MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / GMT_Get_FilePath

Function GMT_Get_FilePath

src/gmt_api.c:15988–16105  ·  view source on GitHub ↗

! . */

Source from the content-addressed store, hash-verified

15986
15987/*! . */
15988int GMT_Get_FilePath (void *V_API, unsigned int family, unsigned int direction, unsigned int mode, char **file_ptr) {
15989 /* Replace file with its full path if that file exists, else return an error.
15990 * If (mode & GMT_FILE_REMOTE) then we try to download any remote files
15991 * given but not yet cached locally), and if the downloaded file is readable then
15992 * we update file_ptr with the local path, otherwise return an error.
15993 * If (mode & GMT_FILE_CHECK) then we only return error code and don't update file_ptr.
15994 * The explicit mode for only examining local files is GMT_FILE_LOCAL [0].
15995 *
15996 * Filename complications: Both grid, image and CPT filenames may have modifiers or
15997 * format identifiers appended to their names. Thus, as given, file may name be a valid
15998 * filename until we have chopped off these strings. Here is a summary of what GMT allows:
15999 *
16000 * imagefile[=gd[+b<band>]]
16001 * grdfile[=<id>][+o<offset>][+n<invalid>][+s<scale>][+u|U<unit>]
16002 * cptfile[+h<hinge>][+u|U<unit>]
16003 * Note: Some modules also allows cptfile[+h<hinge>][+u|U<unit>][i<dz>] but the +d
16004 * modifier is processed and removed in the module (grd-image/view/vector/2kml).
16005 *
16006 * gridfiles may also have strings to select specific layers of nigher-dimension netCDFfiles, using
16007 * grdfile?<variables>[layer]|(value).
16008 *
16009 * URL queries also use ? as in http://<address>?<par1>=<val1>...
16010 * Remote grids may also have format specification and modifiers like local grids:
16011 * https://<address>/grdfile[=<id>][+o<offset>][+n<invalid>][+s<scale>][+u|U<unit>]
16012 */
16013
16014 char remote_path[PATH_MAX] = {""}, local_path[PATH_MAX] = {""}, was = '\0', *file = NULL, *c = NULL, *f = NULL;
16015 struct GMTAPI_CTRL *API = NULL;
16016
16017 if (V_API == NULL) return_error (V_API, GMT_NOT_A_SESSION);
16018 if (!(direction == GMT_IN || direction == GMT_OUT)) return_error (API, GMT_NOT_A_VALID_DIRECTION);
16019 if (!gmtapi_valid_input_family (family)) return_error (API, GMT_NOT_A_VALID_FAMILY);
16020 if (mode > (GMT_FILE_CHECK+GMT_FILE_REMOTE)) return_error (API, GMT_NOT_A_VALID_MODE);
16021 API = gmtapi_get_api_ptr (V_API);
16022 API->error = GMT_NOERROR;
16023
16024 if (file_ptr == NULL || (file = *file_ptr) == NULL || file[0] == '\0') {
16025 GMT_Report (API, GMT_MSG_ERROR, "No filename provided\n");
16026 return_error (V_API, GMT_ARG_IS_NULL);
16027 }
16028
16029 if (direction == GMT_OUT) return GMT_NOERROR;
16030
16031 if (gmt_M_file_is_memory (file)) return GMT_NOERROR; /* Memory files are always fine */
16032
16033 if (gmtlib_found_url_for_gdal (file)) { /* Special URLs for grids to be read via GDAL */
16034 return GMT_NOERROR;
16035 }
16036
16037 if ((mode & GMT_FILE_CHECK) == 0 && gmt_set_unspecified_remote_registration (API, file_ptr)) /* Complete remote filenames without registration information */
16038 GMT_Report (API, GMT_MSG_DEBUG, "Revised remote file name to %s\n", file_ptr);
16039
16040 gmt_filename_get (file); /* Replace any ASCII 29 with spaces (if filename had spaces they may now be ASCII 29) */
16041
16042 switch (family) {
16043 case GMT_IS_GRID:
16044 if (!gmt_file_is_tiled_list (API, file, NULL, NULL, NULL) && (c = strchr (file, '='))) { /* Got filename=id[+modifiers] */
16045 /* Nothing*/

Callers 15

parseFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85
parseFunction · 0.85
GMT_grdfilter_parseFunction · 0.85
parseFunction · 0.85
gmt_get_required_fileFunction · 0.85
parseFunction · 0.85

Calls 11

gmtapi_get_api_ptrFunction · 0.85
GMT_ReportFunction · 0.85
gmt_filename_getFunction · 0.85
gmt_file_is_tiled_listFunction · 0.85
gmt_strrstrFunction · 0.85
gmt_download_fileFunction · 0.85
strdupFunction · 0.85

Tested by 1

parseFunction · 0.68