Skip to content

Commit

Permalink
Merge branch 'master' into psconvert-no-file-dup
Browse files Browse the repository at this point in the history
  • Loading branch information
joa-quim committed Nov 19, 2024
2 parents 441dd11 + fa3eda0 commit 29f0aa5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions doc/rst/source/mapproject.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ Optional Arguments
**-F**\ [**e**\|\ **f**\|\ **k**\|\ **M**\|\ **n**\|\ **u**\|\ **c**\|\ **i**\|\ **p**]
Force 1:1 scaling, i.e., output (or input, see |-I|) data are in
actual projected meters. To specify other units, append the desired
unit (see `Units`_). Without |-F|, the output (or input, see |-I|)
are in the units specified by :term:`PROJ_LENGTH_UNIT` (but see
|-D|).
unit (see `Units`_). Without |-F|, and when using the classic |-J| syntax, the output (or input, see |-I|)
are in the units specified by :term:`PROJ_LENGTH_UNIT` (but see |-D|). This changes, however, to meters
when PROJ4 syntax or EPSG is used in |-J| and that regardless of |-F| being used or not.

.. _-G:

Expand Down
23 changes: 23 additions & 0 deletions src/mapproject.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,28 @@ static int parse (struct GMT_CTRL *GMT, struct MAPPROJECT_CTRL *Ctrl, struct GMT
return (n_errors ? GMT_PARSE_ERROR : GMT_NOERROR);
}

static void add_J_scale_if_needed(struct GMT_CTRL *GMT, struct GMT_OPTION *options) {
/* Fixes #8624. That is, if -F is used the -J.../size|scale is inutil but it complained that
"No UTM zone given;". The fix requires a function like this because -J is parsed before we even
know if a -F is used. The trick is then to scan the options linked list and patch the -J option
to include a "/1:1" to make the parse_option_J happy. */
char txt_a[GMT_LEN128] = {""};
struct GMT_OPTION *optJ = NULL, *optF = NULL;
if (options == NULL) return; /* No arguments given to begin, done here */
for (optF = options; optF; optF = optF->next) { /* Loop over all options in the linked list */
if (optF->option == 'F') {
for (optJ = options; optJ; optJ = optJ->next) { /* Now search for -J */
if (optJ->option == 'J' && optJ->arg && !strchr(optJ->arg, '/')) {
strcpy(txt_a, optJ->arg); /* Save the -J argument because we need to free it first (was a strdup)*/
free(optJ->arg);
optJ->arg = strdup(strcat(txt_a, "/1:1")); /* Add /1:1 to the -J argument */
return;
}
}
}
}
}

#define bailout(code) {gmt_M_free_options (mode); return (code);}
#define Return(code) {Free_Ctrl (GMT, Ctrl); gmt_end_module (GMT, GMT_cpy); bailout (code);}

Expand Down Expand Up @@ -926,6 +948,7 @@ EXTERN_MSC int GMT_mapproject (void *V_API, int mode, void *args) {
/* Parse the command-line arguments */

if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_CLASSIC_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, module_kw, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
add_J_scale_if_needed(GMT, options);
if (GMT_Parse_Common (API, THIS_MODULE_OPTIONS, options)) Return (API->error);
Ctrl = New_Ctrl (GMT); /* Allocate and initialize a new control structure */
if ((error = parse (GMT, Ctrl, options)) != 0) Return (error);
Expand Down

0 comments on commit 29f0aa5

Please sign in to comment.