Skip to content
Merged
Changes from all 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
Make checking for registrations more robust
THe gmt_set_unspecified_remote_registration function, whose job it is to determine of the pixel or gridline registration was specifically requested in a remote file name, was written before there was @earth_geoid and hence the lame check for _g or _p found _g(eoid) and returned prematurely.
This PR adds the harder work of advancing past the leading dataset name and then look for _g or _p.
In the process I learned I had a typo in the test gmt_data_server.txt where the earth_relief_01d_g.grd had a missing / in front of server.  Just delete your test/server/gmt_data_server.txt to get the fixed file.

Tests pass.
  • Loading branch information
PaulWessel committed Dec 27, 2021
commit 89f780f2d626a80ecf9ff67ecc0c6f0df5d09c2d
12 changes: 10 additions & 2 deletions src/gmt_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,10 @@ void gmt_set_unspecified_remote_registration (struct GMTAPI_CTRL *API, char **fi
* There are a few different scenarios where this can happen:
* 1. Users of GMT <= 6.0.0 are used to say earth_relief_01m. These will now get p.
* 2. Users who do not care about registration. If so, they get p if available. */
char newfile[GMT_LEN256] = {""}, reg[2] = {'p', 'g'}, *file = NULL, *infile = NULL, *ext = NULL, *c = NULL;
char newfile[GMT_LEN256] = {""}, dir[GMT_LEN128] = {""}, reg[2] = {'p', 'g'};
char *file = NULL, *infile = NULL, *ext = NULL, *c = NULL, *p = NULL, *q = NULL;
int k_data, k;
size_t L;
if (file_ptr == NULL || (file = *file_ptr) == NULL || file[0] == '\0') return;
if (gmt_M_file_is_memory (file)) return; /* Not a remote file for sure */
if (file[0] != '@') return;
Expand All @@ -475,7 +477,13 @@ void gmt_set_unspecified_remote_registration (struct GMTAPI_CTRL *API, char **fi
ext = gmt_chop_ext (infile);
/* If the remote file is found then there is nothing to do */
if ((k_data = gmt_remote_dataset_id (API, infile)) == GMT_NOTSET) goto clean_up;
if (strstr (file, "_p") || strstr (file, "_g")) goto clean_up; /* Already have the registration codes */
L = strlen (API->remote_info[k_data].dir) - 1; /* Length of dir minus trailing slash */
strncpy (dir, API->remote_info[k_data].dir, L); dir[L] = '\0'; /* Duplicate dir without slash */
p = strrchr (dir, '/') + 1; /* Start of final subdirectory (skipping over the slash we found) */
q = strstr (file, p); /* Start of the file name (most likely the same as &file[1] but we want to make sure) */
if (q == NULL) return; /* Should never happen but definitively nothing more to do here - just a safety valve */
q += strlen (p); /* Move to the end of family name after which any registration codes would be found */
if (strstr (q, "_p") || strstr (q, "_g")) goto clean_up; /* Already have the registration codes */
for (k = 0; k < 2; k++) {
/* First see if this _<reg> version exists of this dataset */
sprintf (newfile, "%s_%c", infile, reg[k]);
Expand Down