Skip to content

Commit

Permalink
Several fixes to let gmtgravmag3d pass in memory data via modified -T…
Browse files Browse the repository at this point in the history
… option. (#8680)

* Modify option -T to use modifiers.

Let both input xyz file and vertices (new -T+v<file>) be readable by externals.

* Save number of columns read when requesrec reading a file with unknown n cols.

* Change KEYs to allow -F from externals.

Change syntax of -T option

* Update the -T docs.
  • Loading branch information
joa-quim authored Jan 22, 2025
1 parent a2cdd44 commit 504e6d2
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 108 deletions.
10 changes: 5 additions & 5 deletions doc/rst/source/supplements/potential/gmtgravmag3d.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Synopsis

.. include:: ../../common_SYN_OPTs.rst_

**gmt gravmag3d** *xyz_file* |-T|\ **v**\ *vert_file* OR |-T|\ **r\|s**\ *raw_file* OR |-M|\ **+s**\ *body,params*
**gmt gravmag3d** *xyz_file* |-T|\ **+v**\ *vert_file* OR |-T|\ **+r\|+s**\ *raw_file* OR |-M|\ **+s**\ *body,params*
[ |-C|\ *density* ]
[ |-E|\ *thickness* ]
[ |-F|\ *xy_file* ]
Expand Down Expand Up @@ -97,15 +97,15 @@ Required Arguments (not all)

.. _-T:

**-Tv**\ *vert_file* (must have when passing a *xyz_file*) OR **-Tr\|s**\ *raw_file*
Gives names of a xyz and vertex (**-Tv**\ *vert_file*) files defining a close surface.
**-T+v**\ *vert_file* (must have when passing a *xyz_file*) OR **-T+r\|+s**\ *raw_file*
Gives names of a xyz and vertex (**-T+v**\ *vert_file*) files defining a closed surface.
The file formats correspond to the output of the :doc:`triangulate </triangulate>` program.
The *xyz* file can have 3, 4, 5, 6 or 8 columns. In first case (3 columns) the magnetization (or density) are
assumed constant (controlled by |-C| or |-H|). Following cases are: 4 columns -> 4rth col magnetization intensity;
5 columns: mag, mag dip; 6 columns: mag, mag dec, mag dip; 8 columns: field dec, field dip, mag, mag dec, mag dip.
When n columns > 3 the third argument of the |-H| option is ignored. A *raw* format (selected by the **-Tr** option)
When n columns > 3 the third argument of the |-H| option is ignored. A *raw* format (selected with the **-T+r** option)
is a file with N rows (one per triangle) and 9 columns corresponding to the *x, y, z* coordinates of each of the three
vertex of each triangle. Alternatively, the **-Ts** option indicates that the surface file is in the ASCII STL
vertex of each triangle. Alternatively, the **-T+s** option indicates that the surface file is in the ASCII STL
(Stereo Lithographic) format. These two type of files are used to provide a closed surface.

Optional Arguments
Expand Down
11 changes: 9 additions & 2 deletions src/gmt_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -10315,7 +10315,7 @@ GMT_LOCAL void gmtapi_get_record_init (struct GMTAPI_CTRL *API) {
}
}

void * GMT_Get_Record (void *V_API, unsigned int mode, int *retval) {
void *GMT_Get_Record(void *V_API, unsigned int mode, int *retval) {
/* Retrieves the next data record from the virtual input source and
* returns the number of columns found via *retval (unless retval == NULL).
* If current record is a segment header then we return 0.
Expand Down Expand Up @@ -10348,7 +10348,10 @@ void * GMT_Get_Record (void *V_API, unsigned int mode, int *retval) {
record = API->api_get_record (API, mode, &n_fields);
} while (API->get_next_record);

if (!(n_fields == EOF || n_fields == GMT_IO_NEXT_FILE)) API->current_rec[GMT_IN]++; /* Increase record count, unless EOF */
if (!(n_fields == EOF || n_fields == GMT_IO_NEXT_FILE)) { /* Increase record count, unless EOF */
API->current_rec[GMT_IN]++;
if (GMT->current.io.variable_in_columns) GMT->current.io.n_numerical_cols = (unsigned int)n_fields; /* Keep track of this */
}

if (retval) *retval = n_fields; /* Requested we return the number of fields found */
return (record); /* Return pointer to current record */
Expand Down Expand Up @@ -13461,6 +13464,10 @@ struct GMT_RESOURCE * GMT_Encode_Options (void *V_API, const char *module_name,
else if (!strncmp (module, "gravprisms", 10U) && (opt = GMT_Find_Option (API, 'C', *head))) {
deactivate_input = true; /* Turn off implicit input since none is in effect */
}
/* 1z. Check if gmtgravmag3d is producing grids or datasets */
else if (!strncmp (module, "gmtgravmag3d", 12U)) {
//type = (opt = GMT_Find_Option (API, 'F', *head)) ? 'D' : 'G'; /* Giving -F<file> means compute over a line, else grid */
}

/* 2a. Get the option key array for this module */
key = gmtapi_process_keys (API, keys, type, *head, n_per_family, &n_keys); /* This is the array of keys for this module, e.g., "<D{,GG},..." */
Expand Down
Loading

0 comments on commit 504e6d2

Please sign in to comment.