Skip to content

Commit a1e72e6

Browse files
authored
grdinfo -C now also includes registration (#3359)
* grdinfo -C now also includes registration For whatever reason, wihle grdinfo t.grd reports a line about the node registration, there was no such item when we asked for a numerical record -C. So no way of easily determining if a grid is pixel or gridline in a script, other than grepping on the text output. Because the order of outputs were set a long time ago, this PR just adds registration as the very last item of the record. * Update grdinfo.rst
1 parent f89d13b commit a1e72e6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

doc/rst/source/grdinfo.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ Optional Arguments
5555
**-C**\ [**n**\|\ **t**\]
5656
Formats the report using tab-separated fields on a single line. The
5757
output is *name w e s n z0 z1 dx dy nx ny*\ [ *x0 y0 x1 y1* ] [ *med
58-
scale* ] [*mean std rms*] [*n\_nan*]. The data in brackets are
58+
scale* ] [*mean std rms*] [*n\_nan*] *registration*. The data in brackets are
5959
output only if the corresponding options **-M**, **-L1**, **-L2**,
6060
and **-M** are used, respectively. Use **-Ct** to place file *name*
6161
at the end of the output record or **-Cn** to only output numerical
62-
columns. If the **-I** option is used, the
62+
columns. The *registration* is either 0 (gridline) or 1 (pixel).
63+
If the **-I** option is used, the
6364
output format is instead *NF w e s n z0 z1*, where *NF* is the total
6465
number of grids read and *w e s n* are rounded off (see **-I**).
6566

src/grdinfo.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
114114
GMT_Message (API, GMT_TIME_NONE, "\t<grid> may be one or more grid files.\n");
115115
GMT_Message (API, GMT_TIME_NONE, "\n\tOPTIONS:\n");
116116
GMT_Message (API, GMT_TIME_NONE, "\t-C Format report in fields on a single line using the format\n");
117-
GMT_Message (API, GMT_TIME_NONE, "\t <file w e s n z0 z1 dx dy n_columns n_rows [x0 y0 x1 y1] [med L1scale] [mean std rms] [n_nan] [mode LMSscale]>,\n");
117+
GMT_Message (API, GMT_TIME_NONE, "\t <file w e s n z0 z1 dx dy n_columns n_rows [x0 y0 x1 y1] [med L1scale] [mean std rms] [n_nan] [mode LMSscale] registration>,\n");
118118
GMT_Message (API, GMT_TIME_NONE, "\t where -M adds [x0 y0 x1 y1] and [n_nan], -L1 adds [median L1scale], -L2 adds [mean std rms],\n");
119119
GMT_Message (API, GMT_TIME_NONE, "\t and -Lp adds [mode LMSscale]).\n");
120120
GMT_Message (API, GMT_TIME_NONE, "\t Use -Ct to place <file> at the end of the output record, or -Cn to write only numerical columns.\n");
@@ -478,7 +478,7 @@ EXTERN_MSC int GMT_grdinfo (void *V_API, int mode, void *args) {
478478

479479
double x_min = 0.0, y_min = 0.0, z_min = 0.0, x_max = 0.0, y_max = 0.0, z_max = 0.0, wesn[4];
480480
double global_xmin, global_xmax, global_ymin, global_ymax, global_zmin, global_zmax;
481-
double z_mean = 0.0, z_median = 0.0, z_mode = 0.0, z_stdev = 0.0, z_scale = 0.0, z_lmsscl = 0.0, z_rms = 0.0, out[22];
481+
double z_mean = 0.0, z_median = 0.0, z_mode = 0.0, z_stdev = 0.0, z_scale = 0.0, z_lmsscl = 0.0, z_rms = 0.0, out[23];
482482

483483
char format[GMT_BUFSIZ] = {""}, text[GMT_LEN512] = {""}, record[GMT_BUFSIZ] = {""}, grdfile[PATH_MAX] = {""};
484484
char *type[2] = { "Gridline", "Pixel"}, *sep = NULL, *projStr = NULL, *answer[2] = {"", " no"};
@@ -533,6 +533,7 @@ EXTERN_MSC int GMT_grdinfo (void *V_API, int mode, void *args) {
533533
if (Ctrl->L.norm & 1) n_cols += 2; /* Add median scale */
534534
if (Ctrl->L.norm & 2) n_cols += 3; /* Add mean stdev rms */
535535
if (Ctrl->L.norm & 4) n_cols += 2; /* Add mode lmsscale */
536+
n_cols ++; /* Add registration */
536537
}
537538
if (Ctrl->C.mode == GRDINFO_NUMERICAL) cmode = GMT_COL_FIX_NO_TEXT;
538539
geometry = GMT_IS_NONE;
@@ -789,6 +790,7 @@ EXTERN_MSC int GMT_grdinfo (void *V_API, int mode, void *args) {
789790
if (Ctrl->L.norm & 4) {
790791
out[col++] = z_mode; out[col++] = z_lmsscl;
791792
}
793+
out[col++] = G->header->registration;
792794
if (Ctrl->C.mode == GRDINFO_TRAILING)
793795
sprintf (record, "%s", HH->name);
794796
GMT_Put_Record (API, GMT_WRITE_DATA, Out);
@@ -840,6 +842,7 @@ EXTERN_MSC int GMT_grdinfo (void *V_API, int mode, void *args) {
840842
strcat (record, sep); gmt_ascii_format_col (GMT, text, z_mode, GMT_OUT, GMT_Z); strcat (record, text);
841843
strcat (record, sep); gmt_ascii_format_col (GMT, text, z_lmsscl, GMT_OUT, GMT_Z); strcat (record, text);
842844
}
845+
strcat (record, sep); gmt_ascii_format_col (GMT, text, (double)G->header->registration, GMT_OUT, GMT_Z); strcat (record, text);
843846
if (Ctrl->C.mode == GRDINFO_TRAILING) { sprintf (text, "%s%s", sep, HH->name); strcat (record, text); }
844847
GMT_Put_Record (API, GMT_WRITE_DATA, Out);
845848
}

0 commit comments

Comments
 (0)