Skip to content

Commit e67d46b

Browse files
PaulWesselremkos
andauthored
Upgrade grd2cpt like makecpt and improve docs (#8138)
* Allow -Fg in makecpt/grd2cpt for gray-scale output No reason not to have -Fg for gray output, via YIQ if needed. ALso updated the docs. * Add helper include files since both modules now need thesame * Update explain_cpt_output.rst_ * Minor text edits in explain_cpt_output.rst_ --------- Co-authored-by: Remko Scharroo <[email protected]>
1 parent a0a8f41 commit e67d46b

File tree

10 files changed

+182
-134
lines changed

10 files changed

+182
-134
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
**-F**\ [**R**\|\ **c**\|\ **g**\|\ **h**\|\ **r**\|\ **x**][**+c**\ [*label*]][**+k**\ *keys*]
2+
Force output CPT to be written in the desired format set by the directives, thus
3+
selecting among color names, single gray-scale values, color names, *r*/*g*/*b* only,
4+
*h*-*s*-*v*, *c*/*m*/*y*/*k*, or *#rrggbb* hex codes. Choose from:
5+
6+
- **R**: Output color names if possible (and use *r*/*g*/*b* otherwise) [Default].
7+
- **c**: Output color using *c*/*m*/*y*/*k* values.
8+
- **g**: Output *gray* singles (will transform any colors to gray via YIQ transformation).
9+
- **h**: Output *h*-*s*-*v* triplets.
10+
- **r**: Output *r*/*g*/*b* codes only (even if a color name applies).
11+
- **x**: Output *#rrggbb* hex codes.
12+
13+
Optionally or alternatively, append these modifiers:
14+
15+
- **+c**: Write discrete palettes in categorical format. If *label* is appended
16+
then we create labels for each category to be used when the CPT is plotted.
17+
The *label* may be a comma-separated list of category names (you can skip a
18+
category by not giving a name), or give *start*\ [-], where we automatically
19+
build monotonically increasing labels from *start* (a single letter or an integer).
20+
Append - to build ranges *start*\ -*start+1* instead.
21+
- **+k**: Categorical CPT should have string keys instead of numerical entries.
22+
Append keys, which is either a file with one key per record or a single letter
23+
(e.g., D), then we build sequential letter keys (e.g., D, E, F, …) starting at that point.
24+
25+
**Notes**: (1) For comma-separated lists of keys, use |-T| instead.
26+
(2) If **+cM** is given and the number of categories is 12, then we automatically create
27+
a list of month names. (3) If **+cD** is given and the number of categories is 7 then we
28+
make a list of weekday names. The format of these labels will depend on the
29+
:term:`FORMAT_TIME_PRIMARY_MAP`, :term:`GMT_LANGUAGE` and possibly
30+
:term:`TIME_WEEK_START` settings.

doc/rst/source/grd2cpt.rst

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Synopsis
1717
[ |-C|\ *cpt* ]
1818
[ |-D|\ [**i**\|\ **o**] ]
1919
[ |-E|\ [*nlevels*][**+c**][**+f**\ *file*] ]
20-
[ |-F|\ [**R**\|\ **r**\|\ **h**\|\ **c**\|\ **x**][**+c**\ [*label*]] ]
20+
[ |-F|\ [**R**\|\ **c**\|\ **g**\|\ **h**\|\ **r**\|\ **x**][**+c**\ [*label*]][**+k**\ *keys*] ]
2121
[ |-G|\ *zlo*\ /\ *zhi* ]
2222
[ |-H| ]
2323
[ |-I|\ [**c**][**z**] ]
@@ -121,23 +121,7 @@ Optional Arguments
121121

122122
.. _-F:
123123

124-
**-F**\ [**R**\|\ **r**\|\ **h**\|\ **c**\|\ **x**][**+c**\ [*label*]]
125-
Force output CPT to written with r/g/b codes, gray-scale values
126-
or color name (**R**, default) or r/g/b codes only (**r**), or h-s-v
127-
codes (**h**), or c/m/y/k codes (**c**), or #rrggbb hex codes (**x**).
128-
Optionally or alternatively,
129-
append **+c** to write discrete palettes in categorical format.
130-
If *label* is appended then we create labels for each category to be used
131-
when the CPT is plotted. The *label* may be a comma-separated list of
132-
category names (you can skip a category by not giving a name), or give
133-
*start*\ [-], where we automatically build monotonically increasing labels
134-
from *start* (a single letter or an integer). Append - to build ranges
135-
*start*-*start+1* instead. **Note**: If **+cM** is given and the number
136-
of categories is 12, then we automatically create a list of month names.
137-
Likewise, if **+cD** is given and the number of categories is 7 then we
138-
make a list of weekday names. The format of these labels will depend on the
139-
:term:`FORMAT_TIME_PRIMARY_MAP`, :term:`GMT_LANGUAGE` and possibly
140-
:term:`TIME_WEEK_START` settings.
124+
.. include:: explain_cpt_output.rst_
141125

142126
.. _-G:
143127

doc/rst/source/makecpt.rst

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Synopsis
1717
[ |-C|\ *cpt* ]
1818
[ |-D|\ [**i**\|\ **o**] ]
1919
[ |-E|\ [*nlevels*] ]
20-
[ |-F|\ [**R**\|\ **r**\|\ **h**\|\ **c**\|\ **x**][**+c**\ [*label*]][**+k**\ *keys*] ]
20+
[ |-F|\ [**R**\|\ **c**\|\ **g**\|\ **h**\|\ **r**\|\ **x**][**+c**\ [*label*]][**+k**\ *keys*]]
2121
[ |-G|\ *zlo*\ /\ *zhi* ]
2222
[ |-H| ]
2323
[ |-I|\ [**c**][**z**] ]
@@ -62,7 +62,7 @@ and :term:`COLOR_NAN` from
6262
the :doc:`gmt.conf` file or the command line will be used. This default
6363
behavior can be overruled using the options |-D|, |-M| or |-N|.
6464

65-
The color model (RGB, HSV or CMYK) of the palette created by **makecpt**
65+
The color model (GRAY, RGB, HSV or CMYK) of the palette created by **makecpt**
6666
will be the same as specified in the header of the master CPT. When
6767
there is no :term:`COLOR_MODEL` entry in the master CPT, the
6868
:term:`COLOR_MODEL` specified in the :doc:`gmt.conf` file or on the command
@@ -110,27 +110,7 @@ Optional Arguments
110110

111111
.. _-F:
112112

113-
**-F**\ [**R**\|\ **r**\|\ **h**\|\ **c**\|\ **x**][**+c**\ [*label*]][**+k**\ *keys*]
114-
Force output CPT to be written with r/g/b codes, gray-scale values
115-
or color name (**R**, default) or r/g/b codes only (**r**), or h-s-v
116-
codes (**h**), or c/m/y/k codes (**c**), or #rrggbb hex codes (**x**).
117-
Optionally or alternatively,
118-
append **+c** to write discrete palettes in categorical format.
119-
If *label* is appended then we create labels for each category to be used
120-
when the CPT is plotted. The *label* may be a comma-separated list of
121-
category names (you can skip a category by not giving a name), or give
122-
*start*\ [-], where we automatically build monotonically increasing labels
123-
from *start* (a single letter or an integer). Append - to build ranges
124-
*start*\ -*start+1* instead. If the categorical CPT should have string
125-
keys instead of numerical entries then append **+k**\ *keys*, where
126-
*keys* is either a file with one key per record or a single letter (e.g., D),
127-
then we build sequential letter keys (e.g., D, E, F, ...) starting at that point.
128-
For comma-separated lists of keys, use |-T| instead. **Note**: If **+cM** is given and the number
129-
of categories is 12, then we automatically create a list of month names.
130-
Likewise, if **+cD** is given and the number of categories is 7 then we
131-
make a list of weekday names. The format of these labels will depend on the
132-
:term:`FORMAT_TIME_PRIMARY_MAP`, :term:`GMT_LANGUAGE` and possibly
133-
:term:`TIME_WEEK_START` settings.
113+
.. include:: explain_cpt_output.rst_
134114

135115
.. _-G:
136116

src/gmt_constants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ enum GMT_time_period {
370370
/* Directives and modifiers for -F interpolant option */
371371
#define GMT_INTERPOLANT_OPT "a|c|e|l|n|s<p>[+d1|2]"
372372

373+
/* Directives and modifiers for -F cpt output option in makecpt/gdr2cpt */
374+
#define GMT_COLORMODES_OPT "[R|c|g|h|r|x]][+c[<label>]][+k<keys>]"
375+
373376
/* Valid modifiers for various input files */
374377

375378
/* Valid modifiers for -Tmin/max/inc array creator */

src/gmt_init.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13977,7 +13977,7 @@ char *gmtlib_putfill (struct GMT_CTRL *GMT, struct GMT_FILL *F) {
1397713977
strcat (text, add_mods);
1397813978
}
1397913979
}
13980-
else if (F->rgb[0] < -0.5)
13980+
else if (F->rgb[0] < -0.5) /* Skip it */
1398113981
strcpy (text, "-");
1398213982
else if ((i = gmtlib_getrgb_index (GMT, F->rgb)) >= 0)
1398313983
snprintf (text, PATH_MAX+GMT_LEN256, "%s", gmt_M_color_name[i]);
@@ -13997,7 +13997,7 @@ char *gmt_putcolor (struct GMT_CTRL *GMT, double *rgb) {
1399713997
static char text[GMT_LEN256] = {""};
1399813998
int i;
1399913999

14000-
if (rgb[0] < -0.5)
14000+
if (rgb[0] < -0.5) /* Skip it */
1400114001
strcpy (text, "-");
1400214002
else if ((i = gmtlib_getrgb_index (GMT, rgb)) >= 0)
1400314003
snprintf (text, GMT_LEN256, "%s", gmt_M_color_name[i]);
@@ -14015,21 +14015,39 @@ char *gmt_putrgb (struct GMT_CTRL *GMT, double *rgb) {
1401514015
static char text[GMT_LEN256] = {""};
1401614016
gmt_M_unused(GMT);
1401714017

14018-
if (rgb[0] < -0.5)
14018+
if (rgb[0] < -0.5) /* Skip it */
1401914019
strcpy (text, "-");
1402014020
else
1402114021
snprintf (text, GMT_LEN256, "%.5g/%.5g/%.5g", gmt_M_t255(rgb,0), gmt_M_t255(rgb,1), gmt_M_t255(rgb,2));
1402214022
gmtinit_append_trans (text, rgb[3]);
1402314023
return (text);
1402414024
}
1402514025

14026+
/*! Creates t the string shade corresponding to the RGB triplet */
14027+
char *gmt_putgray (struct GMT_CTRL *GMT, double *rgb) {
14028+
14029+
static char text[GMT_LEN256] = {""};
14030+
gmt_M_unused(GMT);
14031+
14032+
if (rgb[0] < -0.5) /* Skip it */
14033+
strcpy (text, "-");
14034+
else if (gmt_M_is_gray(rgb))
14035+
snprintf (text, GMT_LEN256, "%.5g", gmt_M_t255(rgb,0));
14036+
else { /* Must convert to gray */
14037+
double gray = gmt_M_yiq (rgb);
14038+
snprintf (text, GMT_LEN256, "%.5g", gray);
14039+
}
14040+
gmtinit_append_trans (text, rgb[3]);
14041+
return (text);
14042+
}
14043+
1402614044
/*! Creates t the string #rrggbb corresponding to the RGB triplet */
1402714045
char *gmt_puthex (struct GMT_CTRL *GMT, double *rgb) {
1402814046

1402914047
static char text[GMT_LEN256] = {""};
1403014048
gmt_M_unused(GMT);
1403114049

14032-
if (rgb[0] < -0.5)
14050+
if (rgb[0] < -0.5) /* Skip it */
1403314051
strcpy (text, "-");
1403414052
else
1403514053
snprintf (text, GMT_LEN256, "#%02x%02x%02x", urint (gmt_M_t255(rgb,0)), urint (gmt_M_t255(rgb,1)), urint (gmt_M_t255(rgb,2)));
@@ -14043,7 +14061,7 @@ char *gmtlib_putcmyk (struct GMT_CTRL *GMT, double *cmyk) {
1404314061
static char text[GMT_LEN256] = {""};
1404414062
gmt_M_unused(GMT);
1404514063

14046-
if (cmyk[0] < -0.5)
14064+
if (cmyk[0] < -0.5) /* Skip it */
1404714065
strcpy (text, "-");
1404814066
else
1404914067
snprintf (text, GMT_LEN256, "%.5g/%.5g/%.5g/%.5g", 100.0*gmt_M_q(cmyk[0]), 100.0*gmt_M_q(cmyk[1]), 100.0*gmt_M_q(cmyk[2]), 100.0*gmt_M_q(cmyk[3]));
@@ -14057,7 +14075,7 @@ char *gmtlib_puthsv (struct GMT_CTRL *GMT, double *hsv) {
1405714075
static char text[GMT_LEN256] = {""};
1405814076
gmt_M_unused(GMT);
1405914077

14060-
if (hsv[0] < -0.5)
14078+
if (hsv[0] < -0.5) /* Skip it */
1406114079
strcpy (text, "-");
1406214080
else
1406314081
snprintf (text, GMT_LEN256, "%.5g-%.5g-%.5g", gmt_M_q(hsv[0]), gmt_M_q(hsv[1]), gmt_M_q(hsv[2]));

src/gmt_prototypes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ EXTERN_MSC int gmt_set_measure_unit (struct GMT_CTRL *GMT, char unit);
114114
EXTERN_MSC char * gmt_putcolor (struct GMT_CTRL *GMT, double *rgb);
115115
EXTERN_MSC char * gmt_putrgb (struct GMT_CTRL *GMT, double *rgb);
116116
EXTERN_MSC char * gmt_puthex (struct GMT_CTRL *GMT, double *rgb);
117+
EXTERN_MSC char * gmt_putgray (struct GMT_CTRL *GMT, double *rgb);
117118
EXTERN_MSC double gmt_convert_units (struct GMT_CTRL *GMT, char *value, unsigned int from_default, unsigned int target_unit);
118119
EXTERN_MSC unsigned int gmt_check_scalingopt (struct GMT_CTRL *GMT, char option, char unit, char *unit_name);
119120
EXTERN_MSC int gmt_parse_common_options (struct GMT_CTRL *GMT, char *list, char option, char *item);
@@ -553,6 +554,8 @@ EXTERN_MSC int gmt_grd_BC_set (struct GMT_CTRL *GMT, struct GMT_GRID *G, unsigne
553554
EXTERN_MSC int gmt_cube_BC_set (struct GMT_CTRL *GMT, struct GMT_CUBE *U, unsigned int direction);
554555
EXTERN_MSC unsigned int gmt_parse_inv_cpt (struct GMT_CTRL *GMT, char *arg);
555556
EXTERN_MSC struct GMT_PALETTE * gmt_truncate_cpt (struct GMT_CTRL *GMT, struct GMT_PALETTE *P, double z_low, double z_high);
557+
EXTERN_MSC void gmt_explain_cpt_output (struct GMTAPI_CTRL *API, char option);
558+
EXTERN_MSC int gmt_prepare_categorical_cpt (struct GMT_CTRL *GMT, char *label, char *key, struct GMT_PALETTE *Pout);
556559
EXTERN_MSC void gmt_free_int_selection (struct GMT_CTRL *GMT, struct GMT_INT_SELECTION **S);
557560
EXTERN_MSC struct GMT_INT_SELECTION * gmt_set_int_selection (struct GMT_CTRL *GMT, char *item);
558561
EXTERN_MSC bool gmt_get_int_selection (struct GMT_CTRL *GMT, struct GMT_INT_SELECTION *S, uint64_t this);

src/gmt_resources.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,8 @@ enum GMT_enum_color {
576576
GMT_HSV = 2,
577577
GMT_COLORINT = 4,
578578
GMT_NO_COLORNAMES = 8,
579-
GMT_HEX_COLOR = 16
579+
GMT_HEX_COLOR = 16,
580+
GMT_GRAY = 32,
580581
};
581582

582583
enum GMT_enum_bfn {
@@ -597,6 +598,7 @@ enum GMT_enum_cptflags {
597598
GMT_CPT_SOFT_HINGE = 8,
598599
GMT_CPT_TIME = 16,
599600
GMT_CPT_COLORLIST = 32,
601+
GMT_CPT_GRAY_SET = 64,
600602
GMT_CPT_HINGED = 4 /* Backwards compatibility with 6.0 API */
601603
};
602604

src/gmt_support.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,68 @@ GMT_LOCAL void gmtsupport_truncate_cpt_slice (struct GMT_LUT *S, bool do_hsv, do
15521552
S->i_dz = 1.0 / (S->z_high - S->z_low);
15531553
}
15541554

1555+
void gmt_explain_cpt_output (struct GMTAPI_CTRL *API, char option) {
1556+
/* Display usage synopsis for -F cpt output/categorical option in makecpt/grd2cpt */
1557+
1558+
GMT_Usage (API, 1, "\n-%c%s", option, GMT_COLORMODES_OPT);
1559+
GMT_Usage (API, -2, "Select the color model for output [Default uses the input model]:");
1560+
GMT_Usage (API, 3, "R: Output r/g/b or colornames.");
1561+
GMT_Usage (API, 3, "c: Output c/m/y/k.");
1562+
GMT_Usage (API, 3, "g: Output gray value (Will apply the YIQ if not a gray value).");
1563+
GMT_Usage (API, 3, "h: Output h-s-v.");
1564+
GMT_Usage (API, 3, "r: Output r/g/b only.");
1565+
GMT_Usage (API, 3, "x: Output hex #rrggbb only.");
1566+
GMT_Usage (API, -2, "Two modifiers control generation of categorical labels:");
1567+
GMT_Usage (API, 3, "+c Output a discrete CPT in categorical CPT format. "
1568+
"The <label>, if appended, sets the labels for each category. It may be a "
1569+
"comma-separated list of category names, or <start>[-] where we automatically build "
1570+
"labels from <start> (a letter or an integer). Append - to build range labels <start>-<start+1>.");
1571+
GMT_Usage (API, 3, "+k Set categorical keys rather than numerical values. "
1572+
"<keys> may be a file with one key per line or a comma-separated list of keys. "
1573+
"If <keys> is a single letter then we build sequential alphabetical keys from that letter. "
1574+
"If number of categories is 12 and label is M then we auto-create month name labels, and "
1575+
"if it is 7 and label is D then we auto-create weekday name labels.");
1576+
}
1577+
1578+
int gmt_prepare_categorical_cpt (struct GMT_CTRL *GMT, char *label, char *key, struct GMT_PALETTE *Pout) {
1579+
bool got_key_file = (key && !gmt_access (GMT, key, R_OK)); /* Want categorical labels read from file */
1580+
unsigned int ns = 0;
1581+
Pout->categorical = GMT_CPT_CATEGORICAL_VAL;
1582+
if (label || (key && !got_key_file)) { /* Want auto-categorical labels appended to each CPT record */
1583+
char **Plabel = gmt_cat_cpt_strings (GMT, (label) ? label : key, Pout->n_colors, &ns);
1584+
for (unsigned int k = 0; k < MIN (Pout->n_colors, ns); k++) {
1585+
if (Pout->data[k].label) gmt_M_str_free (Pout->data[k].label);
1586+
if (Plabel[k]) Pout->data[k].label = Plabel[k]; /* Now the job of the CPT to free these strings */
1587+
}
1588+
gmt_M_free (GMT, Plabel); /* But the master array can go */
1589+
}
1590+
if (key) { /* Want categorical labels */
1591+
char **keys = NULL;
1592+
if (got_key_file) { /* Got a file with category keys */
1593+
ns = gmt_read_list (GMT, key, &keys);
1594+
if (ns < Pout->n_colors) {
1595+
GMT_Report (GMT->parent, GMT_MSG_ERROR, "The categorical keys file %s had %d entries but CPT has %d categories\n", key, ns, Pout->n_colors);
1596+
return (GMT_RUNTIME_ERROR);
1597+
}
1598+
else if (ns > Pout->n_colors)
1599+
GMT_Report (GMT->parent, GMT_MSG_WARNING, "The categorical keys file %s had %d entries but only %d are needed - skipping the extra keys\n", key, ns, Pout->n_colors);
1600+
}
1601+
else /* Got comma-separated keys */
1602+
keys = gmt_cat_cpt_strings (GMT, key, Pout->n_colors, &ns);
1603+
for (unsigned int k = 0; k < MIN (Pout->n_colors, ns); k++) {
1604+
if (Pout->data[k].key) gmt_M_str_free (Pout->data[k].key);
1605+
if (k < ns && keys[k]) {
1606+
Pout->data[k].key = keys[k]; /* Now the job of the CPT to free these strings */
1607+
if (Pout->data[k].label) gmt_M_str_free (Pout->data[k].label);
1608+
Pout->data[k].label = strdup (keys[k]);
1609+
}
1610+
}
1611+
gmt_M_free (GMT, keys); /* But the master array can go */
1612+
Pout->categorical = GMT_CPT_CATEGORICAL_KEY;
1613+
}
1614+
return (GMT_NOERROR);
1615+
}
1616+
15551617
bool gmt_consider_current_cpt (struct GMTAPI_CTRL *API, bool *active, char **arg) {
15561618
/* Modern mode only: Detect if no CPT is given but -C was set.
15571619
* If -C[+u|U<arg>] is given (i.e., no cpt) then we take that to mean
@@ -8330,6 +8392,8 @@ struct GMT_PALETTE * gmtlib_read_cpt (struct GMT_CTRL *GMT, void *source, unsign
83308392
X->model = GMT_RGB | GMT_COLORINT;
83318393
else if (strstr (line, "RGB"))
83328394
X->model = GMT_RGB;
8395+
else if (strstr (line, "+GRAY") || strstr (line, "gray"))
8396+
X->model = GMT_GRAY | GMT_COLORINT;
83338397
else if (strstr (line, "+HSV") || strstr (line, "hsv"))
83348398
X->model = GMT_HSV | GMT_COLORINT;
83358399
else if (strstr (line, "HSV"))
@@ -9473,6 +9537,9 @@ int gmtlib_write_cpt (struct GMT_CTRL *GMT, void *dest, unsigned int dest_type,
94739537
struct CPT_Z_SCALE *Z = NULL; /* For unit manipulations */
94749538
struct GMT_PALETTE_HIDDEN *PH = NULL;
94759539

9540+
if (cpt_flags & GMT_CPT_GRAY_SET && !P->is_gray)
9541+
GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "Colors in the CPT file %s were converted to gray via the YIQ-translation.\n", &cpt_file[append]);
9542+
94769543
/* When writing the CPT to file it is no longer a normalized CPT with a hinge */
94779544
P->has_range = P->has_hinge = 0;
94789545

@@ -9537,6 +9604,8 @@ int gmtlib_write_cpt (struct GMT_CTRL *GMT, void *dest, unsigned int dest_type,
95379604
gmtlib_write_newheaders (GMT, fp, 0); /* Write general header block */
95389605

95399606
if (!(P->model & GMT_COLORINT)) {} /* Write nothing when color interpolation is not forced */
9607+
else if (P->model & GMT_GRAY)
9608+
fprintf (fp, "# COLOR_MODEL = gray\n");
95409609
else if (P->model & GMT_HSV)
95419610
fprintf (fp, "# COLOR_MODEL = hsv\n");
95429611
else if (P->model & GMT_CMYK)
@@ -9562,6 +9631,8 @@ int gmtlib_write_cpt (struct GMT_CTRL *GMT, void *dest, unsigned int dest_type,
95629631

95639632
if (P->categorical) {
95649633
if (P->categorical & GMT_CPT_CATEGORICAL_KEY) strncpy (lo, P->data[i].key, GMT_LEN64-1);
9634+
if (P->model & GMT_GRAY)
9635+
fprintf (fp, format, lo, gmt_putgray (GMT, P->data[i].hsv_low), '\t');
95659636
if (P->model & GMT_HSV)
95669637
fprintf (fp, format, lo, gmtlib_puthsv (GMT, P->data[i].hsv_low), '\t');
95679638
else if (P->model & GMT_CMYK) {
@@ -9575,6 +9646,10 @@ int gmtlib_write_cpt (struct GMT_CTRL *GMT, void *dest, unsigned int dest_type,
95759646
else
95769647
fprintf (fp, format, lo, gmt_putcolor (GMT, P->data[i].rgb_low), '\t');
95779648
}
9649+
else if (P->model & GMT_GRAY) {
9650+
fprintf (fp, format, lo, gmt_putgray (GMT, P->data[i].rgb_low), '\t');
9651+
fprintf (fp, format, hi, gmt_putgray (GMT, P->data[i].rgb_high), '\t');
9652+
}
95789653
else if (P->model & GMT_HSV) {
95799654
fprintf (fp, format, lo, gmtlib_puthsv (GMT, P->data[i].hsv_low), '\t');
95809655
fprintf (fp, format, hi, gmtlib_puthsv (GMT, P->data[i].hsv_high), '\t');
@@ -9615,6 +9690,8 @@ int gmtlib_write_cpt (struct GMT_CTRL *GMT, void *dest, unsigned int dest_type,
96159690
if (!use[i]) continue; /* This BNF entry does not apply to this CPT */
96169691
if (P->bfn[i].skip)
96179692
fprintf (fp, "%c\t-\n", code[i]);
9693+
else if (P->model & GMT_GRAY)
9694+
fprintf (fp, "%c\t%s\n", code[i], gmt_putgray (GMT, P->bfn[i].rgb));
96189695
else if (P->model & GMT_HSV)
96199696
fprintf (fp, "%c\t%s\n", code[i], gmtlib_puthsv (GMT, P->bfn[i].hsv));
96209697
else if (P->model & GMT_CMYK) {

0 commit comments

Comments
 (0)