Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ To build GMT, you have to install:
- [CMake](https://cmake.org/) (>=2.8.12)
- [netCDF](https://www.unidata.ucar.edu/software/netcdf/) (>=4.0, netCDF-4/HDF5 support mandatory)
- [curl](https://curl.haxx.se/)
- [GDAL](https://www.gdal.org/) (Ability to read and write numerous grid and image formats)

### Optional dependencies

Optionally install these for more capabilities within GMT:

- [Ghostscript](https://www.ghostscript.com/) (Ability to convert PostScript plots to PDF and rasters)
- [GDAL](https://www.gdal.org/) (Ability to read and write numerous grid and image formats)
- [GEOS](https://trac.osgeo.org/geos/) (Ability to buffer lines and polygons)
- [PCRE](https://www.pcre.org/) or PCRE2 (Regular expression support)
- [FFTW](http://www.fftw.org/) single-precision (Fast FFTs, >=3.3 [not needed under macOS])
Expand Down
11 changes: 3 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,9 @@ include_directories (${CURL_INCLUDE_DIRS})
list (APPEND GMT_OPTIONAL_LIBRARIES ${CURL_LIBRARIES})
set (CURL_LIBRARY ${CURL_LIBRARIES} CACHE INTERNAL "")

if (NOT DEFINED GMT_EXCLUDE_GDAL)
find_package (GDAL)
endif (NOT DEFINED GMT_EXCLUDE_GDAL)
if (GDAL_FOUND)
set (HAVE_GDAL TRUE CACHE INTERNAL "System has GDAL")
include_directories (${GDAL_INCLUDE_DIR})
list (APPEND GMT_OPTIONAL_LIBRARIES ${GDAL_LIBRARIES})
endif (GDAL_FOUND)
find_package (GDAL REQUIRED)
include_directories (${GDAL_INCLUDE_DIR})
list (APPEND GMT_OPTIONAL_LIBRARIES ${GDAL_LIBRARIES})

if (NOT DEFINED GMT_EXCLUDE_GEOS)
find_package (GEOS)
Expand Down
5 changes: 1 addition & 4 deletions src/gmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,7 @@ int main (int argc, char *argv[]) {
fprintf (stderr, "Shared libraries must be in standard system paths or set via environmental parameter %s.\n\n", LIB_PATH);
}
else {
char libraries[GMT_LEN128] = {"netCDF"}; /* Always linked with netCDF */
#ifdef HAVE_GDAL
strcat (libraries, ", GDAL");
#endif
char libraries[GMT_LEN128] = {"netCDF, GDAL"}; /* Always linked with netCDF and GDAL */
#ifdef HAVE_PCRE
strcat (libraries, ", PCRE");
#endif
Expand Down
28 changes: 2 additions & 26 deletions src/gmt_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -4504,7 +4504,6 @@ GMT_LOCAL int gmtapi_import_ppm (struct GMT_CTRL *GMT, char *fname, struct GMT_I
return GMT_NOERROR;
}

#ifdef HAVE_GDAL
GMT_LOCAL bool gmtapi_expand_index_image (struct GMT_CTRL *GMT, struct GMT_IMAGE *I_in, struct GMT_IMAGE **I_out) {
/* In most situations we can use an input image given to a module as the dataset to
* plot. However, if the image is indexed then we must expand it to rgb since we may
Expand Down Expand Up @@ -4602,7 +4601,6 @@ void gmtlib_GDALDestroyDriverManager (struct GMTAPI_CTRL *API) {
/* Cannot close connection to GDAL if calling environment expect it to be open */
if (API->external < 2) GDALDestroyDriverManager();
}
#endif

/*! . */
GMT_LOCAL struct GMT_IMAGE *gmtapi_import_image (struct GMTAPI_CTRL *API, int object_ID, unsigned int mode, struct GMT_IMAGE *image) {
Expand All @@ -4617,9 +4615,10 @@ GMT_LOCAL struct GMT_IMAGE *gmtapi_import_image (struct GMTAPI_CTRL *API, int ob
*/

int item, new_item, new_ID;
bool done = true, via = false, must_be_image = true, no_index = false, bc_not_set = true;
bool done = true, via = false, must_be_image = true, no_index = false, bc_not_set = true, new = false;
uint64_t i0, i1, j0, j1, ij, ij_orig, row, col;
unsigned int both_set = (GMT_CONTAINER_ONLY | GMT_DATA_ONLY);
size_t size;
double dx, dy, d;
p_func_uint64_t GMT_2D_to_index = NULL;
GMT_getfunction api_get_val = NULL;
Expand All @@ -4630,11 +4629,7 @@ GMT_LOCAL struct GMT_IMAGE *gmtapi_import_image (struct GMTAPI_CTRL *API, int ob
struct GMT_GRID_HEADER_HIDDEN *HH = NULL;
struct GMTAPI_DATA_OBJECT *S_obj = NULL;
struct GMT_CTRL *GMT = API->GMT;
#ifdef HAVE_GDAL
bool new = false;
size_t size;
struct GMT_IMAGE *Irgb = NULL;
#endif

GMT_Report (API, GMT_MSG_DEBUG, "gmtapi_import_image: Passed ID = %d and mode = %d\n", object_ID, mode);

Expand All @@ -4656,7 +4651,6 @@ GMT_LOCAL struct GMT_IMAGE *gmtapi_import_image (struct GMTAPI_CTRL *API, int ob

switch (S_obj->method) {
case GMT_IS_FILE: /* Name of an image file on disk */
#ifdef HAVE_GDAL
if (image == NULL) { /* Only allocate image struct when not already allocated */
if (mode & GMT_DATA_ONLY) return_null (API, GMT_NO_GRDHEADER); /* For mode & GMT_DATA_ONLY image must already be allocated */
I_obj = gmtlib_create_image (GMT);
Expand Down Expand Up @@ -4716,9 +4710,6 @@ GMT_LOCAL struct GMT_IMAGE *gmtapi_import_image (struct GMTAPI_CTRL *API, int ob
}
IH = gmt_get_I_hidden (I_obj);
IH->alloc_mode = GMT_ALLOC_INTERNALLY;
#else
GMT_Report (API, GMT_MSG_ERROR, "GDAL required to read image from file %s\n", S_obj->filename);
#endif
break;

case GMT_IS_DUPLICATE: /* GMT image and header in a GMT_IMAGE container object. */
Expand Down Expand Up @@ -4894,7 +4885,6 @@ GMT_LOCAL struct GMT_IMAGE *gmtapi_import_image (struct GMTAPI_CTRL *API, int ob

if (done) S_obj->status = GMT_IS_USED; /* Mark as read (unless we just got the header) */

#ifdef HAVE_GDAL
if (no_index) { /* true if we have an indexed image and we had to allocate a new one */
if (gmtapi_expand_index_image (API->GMT, I_obj, &Irgb)) { /* true if we have a read-only indexed image and we had to allocate a new one */
if (GMT_Destroy_Data (API, &I_obj) != GMT_NOERROR) {
Expand All @@ -4906,7 +4896,6 @@ GMT_LOCAL struct GMT_IMAGE *gmtapi_import_image (struct GMTAPI_CTRL *API, int ob
if (bc_not_set && gmt_M_err_pass (GMT, gmtlib_image_BC_set (GMT, I_obj), S_obj->filename))
return_null (API, GMT_IMAGE_BC_ERROR); /* Failed to set boundary conditions */
}
#endif

if (!via) S_obj->resource = I_obj; /* Retain pointer to the allocated data so we use garbage collection later */

Expand Down Expand Up @@ -5001,13 +4990,8 @@ GMT_LOCAL int gmtapi_export_image (struct GMTAPI_CTRL *API, int object_ID, unsig
GMT_Report (API, GMT_MSG_ERROR, "Unable to export image\n");
return (gmtlib_report_error (API, GMT_ERROR_ON_FOPEN));
}
#ifdef HAVE_GDAL
else if (gmt_M_err_pass (API->GMT, gmt_export_image (API->GMT, S_obj->filename, I_obj), S_obj->filename))
return (gmtlib_report_error (API, GMT_IMAGE_WRITE_ERROR));
#else
else
GMT_Report (API, GMT_MSG_ERROR, "GDAL required to write image to file %s\n", S_obj->filename);
#endif
break;

case GMT_IS_DUPLICATE: /* Duplicate GMT image to a new GMT_IMAGE container object */
Expand Down Expand Up @@ -13528,13 +13512,7 @@ int GMT_Get_Default (void *V_API, const char *keyword, char *value) {
else if (!strncmp (keyword, "API_CORES", 9U)) /* Report number of cores */
sprintf (value, "%d", API->n_cores);
else if (!strncmp (keyword, "API_IMAGE_LAYOUT", 16U)) { /* Report image/band layout */
#ifdef HAVE_GDAL
gmt_M_memcpy (value, API->GMT->current.gdal_read_in.O.mem_layout, 4, char);
#else
GMT_Report (API, GMT_MSG_ERROR, "API_IMAGE_LAYOUT only available when GMT is linked with GDAL; request ignored");
value[0] = '\0';
error = GMT_NOT_A_VALID_ARG;
#endif
}
else if (!strncmp (keyword, "API_GRID_LAYOUT", 15U)) { /* Report grid layout */
if (API->shape == GMT_IS_COL_FORMAT)
Expand Down Expand Up @@ -13577,7 +13555,6 @@ int GMT_Set_Default (void *V_API, const char *keyword, const char *txt_val) {
API->pad = pad;
}
}
#ifdef HAVE_GDAL
else if (!strncmp (keyword, "API_IMAGE_LAYOUT", 16U)) { /* Change image/band layout */
if (strlen (value) != 4U) {
error = 1;
Expand All @@ -13586,7 +13563,6 @@ int GMT_Set_Default (void *V_API, const char *keyword, const char *txt_val) {
else
gmt_M_memcpy (API->GMT->current.gdal_read_in.O.mem_layout, value, 4, char);
}
#endif
else if (!strncmp (keyword, "API_GRID_LAYOUT", 15U)) { /* Change grid layout */
if (!strncmp (value, "columns", 7U) || (strlen(value) >= 2 && value[1] == 'C')) /* Accept also TC, though ignore 1st and 3-end chars. Accept this to be consistent with the "API_IMAGE_LAYOUT" case */
API->shape = GMT_IS_COL_FORMAT; /* Switch to column-major format */
Expand Down
17 changes: 0 additions & 17 deletions src/gmt_customio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1623,13 +1623,8 @@ int gmt_srf_write_grd (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *header, gmt
struct GMT_GRID_HEADER_HIDDEN *HH = gmt_get_H_hidden (header);

if (GMT->session.grdformat[header->type][1] == 'd') {
#ifdef HAVE_GDAL
GMT_Report(GMT->parent, GMT_MSG_INFORMATION,
"Surfer 7 format in GMT is read-only but you can do it via GDAL by appending '=gd:GS7BG' to the file name\n");
#else
GMT_Report(GMT->parent, GMT_MSG_INFORMATION,
"As mentioned in the manual, Surfer 7 format in GMT is read-only\n");
#endif
return (GMT_NOERROR);
}

Expand Down Expand Up @@ -1719,7 +1714,6 @@ int gmt_srf_write_grd (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *header, gmt
return (GMT_NOERROR);
}

#ifdef HAVE_GDAL
#include "gmt_gdalread.c"
#include "gmt_gdalwrite.c"
#include "gmt_ogrproj.c" /* For coordinate conversions but can "enter" here too */
Expand Down Expand Up @@ -2173,8 +2167,6 @@ int gmt_gdal_write_grd (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *header, gm
return (GMT_NOERROR);
}

#endif

/* Add custom code here */

/* 12: NOAA NGDC MGG Format */
Expand Down Expand Up @@ -2432,21 +2424,12 @@ void gmtlib_grdio_init (struct GMT_CTRL *GMT) {
/* FORMAT: Import via the GDAL interface */

id = GMT_GRID_IS_GD;
#ifdef HAVE_GDAL
GMT->session.grdformat[id] = "gd = Import/export through GDAL";
GMT->session.readinfo[id] = &gmt_gdal_read_grd_info;
GMT->session.updateinfo[id] = &gmt_gdal_write_grd_info;
GMT->session.writeinfo[id] = &gmt_gdal_write_grd_info;
GMT->session.readgrd[id] = &gmt_gdal_read_grd;
GMT->session.writegrd[id] = &gmt_gdal_write_grd;
#else
GMT->session.grdformat[id] = "gd = Import/export through GDAL (not supported)";
GMT->session.readinfo[id] = &gmt_dummy_grd_info;
GMT->session.updateinfo[id] = &gmt_dummy_grd_info;
GMT->session.writeinfo[id] = &gmt_dummy_grd_info;
GMT->session.readgrd[id] = &gmt_dummy_grd_read;
GMT->session.writegrd[id] = &gmt_dummy_grd_read;
#endif

/* ----------------------------------------------
* ADD CUSTOM FORMATS BELOW AS THEY ARE NEEDED */
Expand Down
4 changes: 1 addition & 3 deletions src/gmt_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ struct GMT_CTRL; /* forward declaration of GMT_CTRL */
#include "gmt_psl.h" /* Declarations of structure for GMT PostScript settings */
#include "gmt_hash.h" /* Declarations of structure for GMT hashing */

#ifdef HAVE_GDAL
# include "gmt_gdalread.h" /* GDAL support */
#endif
#include "gmt_gdalread.h" /* GDAL support */

#include "gmt_common.h" /* For holding the GMT common option settings */
#include "gmt_fft.h" /* Structures and enums used by programs needing FFTs */
Expand Down
2 changes: 1 addition & 1 deletion src/gmt_gdalcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "gmt_dev.h"
#include "gmt_internals.h"

#if defined(HAVE_GDAL) && ((GDAL_VERSION_MAJOR >= 2) && (GDAL_VERSION_MINOR >= 1)) || (GDAL_VERSION_MAJOR >= 3)
#if ((GDAL_VERSION_MAJOR >= 2) && (GDAL_VERSION_MINOR >= 1)) || (GDAL_VERSION_MAJOR >= 3)

#include <gdal_utils.h>

Expand Down
6 changes: 0 additions & 6 deletions src/gmt_grdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,14 +1131,12 @@ int gmt_grd_get_format (struct GMT_CTRL *GMT, char *file, struct GMT_GRID_HEADER
else if (magic) { /* Reading: determine file format automatically based on grid content */
int choice = 0;
sscanf (HH->name, "%[^?]?%s", tmp, HH->varname); /* Strip off variable name */
#ifdef HAVE_GDAL
/* Check if file is an URL */
if (gmtlib_found_url_for_gdal(HH->name)) {
/* Then check for GDAL grid */
if (gmtlib_is_gdal_grid (GMT, header) == GMT_NOERROR)
return (GMT_NOERROR);
}
#endif
if (!gmt_getdatapath (GMT, tmp, HH->name, R_OK))
return (GMT_GRDIO_FILE_NOT_FOUND); /* Possibly prepended a path from GMT_[GRID|DATA|IMG]DIR */
/* First check if we have a netCDF grid. This MUST be first, because ?var needs to be stripped off. */
Expand Down Expand Up @@ -1171,11 +1169,9 @@ int gmt_grd_get_format (struct GMT_CTRL *GMT, char *file, struct GMT_GRID_HEADER
ext = gmt_get_ext (file);
if (ext && (!strcmp (ext, "txt") || !strcmp (ext, "lis")))
return (GMT_GRDIO_UNKNOWN_FORMAT);
#ifdef HAVE_GDAL
/* Then check for GDAL grid */
if (gmtlib_is_gdal_grid (GMT, header) == GMT_NOERROR)
return (GMT_NOERROR);
#endif
return (GMT_GRDIO_UNKNOWN_FORMAT); /* No supported format found */
}
else { /* Writing: get format type, scale, offset and missing value from GMT->current.setting.io_gridfile_format */
Expand Down Expand Up @@ -3630,7 +3626,6 @@ uint64_t gmt_get_active_layers (struct GMT_CTRL *GMT, struct GMT_CUBE *U, double
return (n_layers_used);
}

#ifdef HAVE_GDAL
GMT_LOCAL void gmtgrdio_gdal_free_from (struct GMT_CTRL *GMT, struct GMT_GDALREAD_OUT_CTRL *from_gdalread) {
int i;
if (from_gdalread->band_field_names) {
Expand Down Expand Up @@ -3838,4 +3833,3 @@ int gmtlib_read_image (struct GMT_CTRL *GMT, char *file, struct GMT_IMAGE *I, do

return (GMT_NOERROR);
}
#endif
16 changes: 2 additions & 14 deletions src/gmt_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -15741,14 +15741,12 @@ void gmt_end_module (struct GMT_CTRL *GMT, struct GMT_CTRL *Ccopy) {

gmt_M_memcpy (spacing, GMT->current.plot.gridline_spacing, 2U, double); /* Remember these so they can survive the end of the module */

#ifdef HAVE_GDAL
/* If that's the case, clean up anu GDAL CT object */
if (GMT->current.gdal_read_in.hCT_fwd)
OCTDestroyCoordinateTransformation(GMT->current.gdal_read_in.hCT_fwd);
if (GMT->current.gdal_read_in.hCT_inv)
OCTDestroyCoordinateTransformation(GMT->current.gdal_read_in.hCT_inv);
GMT->current.gdal_read_in.hCT_fwd = GMT->current.gdal_read_in.hCT_inv = NULL;
#endif

if (GMT->hidden.func_level == GMT_TOP_MODULE && GMT->current.ps.oneliner && GMT->current.ps.active) {
char *setting = getenv ("GMT_END_SHOW");
Expand Down Expand Up @@ -15893,12 +15891,10 @@ void gmt_end_module (struct GMT_CTRL *GMT, struct GMT_CTRL *Ccopy) {
*/
GMT->current.setting.io_lonlat_toggle[GMT_IN] = GMT->current.setting.io_lonlat_toggle[GMT_OUT] = false;

#ifdef HAVE_GDAL
/* Reset these GDAL in/out stuff */
gmt_M_memset (&GMT->current.gdal_read_in, 1, struct GMT_GDALREAD_IN_CTRL);
gmt_M_memset (&GMT->current.gdal_read_out, 1, struct GMT_GDALREAD_OUT_CTRL);
gmt_M_memset (&GMT->current.gdal_write, 1, struct GMT_GDALWRITE_CTRL);
#endif

GMT->parent->cache = false; /* Otherwise gdalread from externals on Windows would mingle CACHEDIR in fnames */

Expand Down Expand Up @@ -17406,7 +17402,6 @@ unsigned int gmt_parse_inc_option (struct GMT_CTRL *GMT, char option, char *item
return GMT_NOERROR;
}

#ifdef HAVE_GDAL
GMT_LOCAL int gmtinit_parse_proj4 (struct GMT_CTRL *GMT, char *item, char *dest) {
/* Deal with proj.4 or EPSGs passed in -J option */
char *item_t1 = NULL, *item_t2 = NULL, wktext[32] = {""}, *pch;
Expand Down Expand Up @@ -17565,7 +17560,6 @@ GMT_LOCAL int gmtinit_parse_proj4 (struct GMT_CTRL *GMT, char *item, char *dest)

return error;
}
#endif

/*! gmt_parse_common_options interprets the command line for the common, unique options
* -B, -J, -K, -O, -P, -R, -U, -V, -X, -Y, -a, -b, -c, -d, -e, -f, -g, -h, -i, -j, -l, -n, -o, -p, -q, -r, -s, -t, -w, -:, -- and -^.
Expand Down Expand Up @@ -17636,7 +17630,6 @@ int gmt_parse_common_options (struct GMT_CTRL *GMT, char *list, char option, cha
GMT->common.J.zactive = true;
}
else if (item && (item[0] == '+' || isdigit(item[0]) || !strncmp(item, "EPSG:", 5) || !strncmp(item, "epsg:", 5))) {
#ifdef HAVE_GDAL
char source[GMT_LEN1024] = {""}, dest[GMT_LEN1024] = {""}, *pch;
bool two = false;

Expand Down Expand Up @@ -17692,11 +17685,6 @@ int gmt_parse_common_options (struct GMT_CTRL *GMT, char *list, char option, cha
if (GMT->current.gdal_read_in.hCT_fwd == NULL || GMT->current.gdal_read_in.hCT_inv == NULL)
error = 1;
}
#else
GMT_Report (GMT->parent, GMT_MSG_ERROR, "PROJ.4 can only be used with GDAL linked GMT.\n");
error = 1;
}
#endif
else { /* Horizontal map projection */
error += (gmt_M_check_condition (GMT, GMT->common.J.active, "Option -J given more than once\n") ||
gmtinit_parse_J_option (GMT, item));
Expand Down Expand Up @@ -18151,7 +18139,7 @@ struct GMT_CTRL *gmt_begin (struct GMTAPI_CTRL *API, const char *session, unsign

struct GMT_CTRL *GMT = NULL;
char version[GMT_LEN8] = {""};
#if defined(HAVE_GDAL) && (GDAL_VERSION_MAJOR >= 3)
#if (GDAL_VERSION_MAJOR >= 3)
char *path1 = NULL, *path2 = NULL, *paths[2] = {NULL, NULL};
int local_count = 0;
#endif
Expand Down Expand Up @@ -18208,7 +18196,7 @@ struct GMT_CTRL *gmt_begin (struct GMTAPI_CTRL *API, const char *session, unsign

API->GMT = GMT;

#if defined(HAVE_GDAL) && (GDAL_VERSION_MAJOR >= 3)
#if (GDAL_VERSION_MAJOR >= 3)
/* Here we allow users to declare a different location for the GDAL's GDAL_DATA and
PROJ4 PROJ_LIB directories. The later may be particularly useful in these days of
transition to GDAL3.0, which imply PROJ4 V6 but many (different) PROJ_LIB from PROJ4 < 6
Expand Down
2 changes: 0 additions & 2 deletions src/gmt_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,11 @@ EXTERN_MSC const char *gmtlib_module_group (void *API, struct GMT_MODULEINFO M[]

EXTERN_MSC int gmtlib_ind2rgb (struct GMT_CTRL *GMT, struct GMT_IMAGE **I_in);

#ifdef HAVE_GDAL
EXTERN_MSC int gmtlib_read_image (struct GMT_CTRL *GMT, char *file, struct GMT_IMAGE *I, double *wesn,
unsigned int *pad, unsigned int complex_mode); /* Function to read true images via GDAL */
int gmtlib_read_image_info (struct GMT_CTRL *GMT, char *file, bool must_be_image, struct GMT_IMAGE *I);
EXTERN_MSC int gmtlib_is_gdal_grid (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *header);
EXTERN_MSC void gmtlib_GDALDestroyDriverManager (struct GMTAPI_CTRL *API);
#endif

/* LOCAL MACROS USED BY GMT_*.C ONLY - NOT PART OF GMT_DEV.H DISTRIBUTION */

Expand Down
Loading