@@ -112,11 +112,12 @@ struct PSSCALE_CTRL {
112
112
struct PSSCALE_Q { /* -Q */
113
113
bool active ;
114
114
} Q ;
115
- struct PSSCALE_S { /* -S[+c|n][+s][+a<angle>] */
115
+ struct PSSCALE_S { /* -S[+c|n][+s][+a<angle>][+x<label>][+y<unit>] */
116
116
bool active ;
117
117
bool skip ;
118
118
double angle ;
119
119
unsigned int mode ;
120
+ char unit [GMT_LEN256 ], label [GMT_LEN256 ];
120
121
} S ;
121
122
struct PSSCALE_W { /* -W<scale> */
122
123
bool active ;
@@ -163,7 +164,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
163
164
GMT_Message (API , GMT_TIME_NONE , "\t[-D%s[+w<length>[/<width>]][+e[b|f][<length>]][+h|v][+j<justify>][+ma|c|l|u][+n[<txt>]]%s]\n" , GMT_XYANCHOR , GMT_OFFSET );
164
165
GMT_Message (API , GMT_TIME_NONE , "\t[-F%s]\n" , GMT_PANEL );
165
166
GMT_Message (API , GMT_TIME_NONE , "\t[-G<zlo>/<zhi>] [-I[<max_intens>|<low_i>/<high_i>] [%s] %s[-L[i][<gap>]] [-M] [-N[p|<dpi>]]\n" , GMT_J_OPT , API -> K_OPT );
166
- GMT_Message (API , GMT_TIME_NONE , "\t%s%s[-Q] [%s] [-S[+a<angle>][+c|n][+s]] [%s] [%s] [-W<scale>]\n" , API -> O_OPT , API -> P_OPT , GMT_Rgeoz_OPT , GMT_U_OPT , GMT_V_OPT );
167
+ GMT_Message (API , GMT_TIME_NONE , "\t%s%s[-Q] [%s] [-S[+a<angle>][+c|n][+s][+x<label>][+y<unit>] ] [%s] [%s] [-W<scale>]\n" , API -> O_OPT , API -> P_OPT , GMT_Rgeoz_OPT , GMT_U_OPT , GMT_V_OPT );
167
168
GMT_Message (API , GMT_TIME_NONE , "\t[%s] [%s] [-Z<zfile>]\n\t%s[%s] [%s] [%s]\n\n" , GMT_X_OPT , GMT_Y_OPT , API -> c_OPT , GMT_p_OPT , GMT_t_OPT , GMT_PAR_OPT );
168
169
169
170
if (level == GMT_SYNOPSIS ) return (GMT_MODULE_SYNOPSIS );
@@ -215,6 +216,8 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
215
216
GMT_Message (API , GMT_TIME_NONE , "\t Append +c to use any custom labels in the CPT for annotations, if available.\n" );
216
217
GMT_Message (API , GMT_TIME_NONE , "\t Append +n to use numerical values for annotations [Default].\n" );
217
218
GMT_Message (API , GMT_TIME_NONE , "\t Append +s to skip drawing gridlines between different color sections [Default draws lines].\n" );
219
+ GMT_Message (API , GMT_TIME_NONE , "\t Append +x<label> to set a colorbar label [No label].\n" );
220
+ GMT_Message (API , GMT_TIME_NONE , "\t Append +y to set a colorbar unit [No unit].\n" );
218
221
GMT_Option (API , "U,V,X" );
219
222
GMT_Message (API , GMT_TIME_NONE , "\t-Z Give file with colorbar-width (in %s) per color entry.\n" ,
220
223
API -> GMT -> session .unit_name [API -> GMT -> current .setting .proj_length_unit ]);
@@ -351,6 +354,7 @@ static int parse (struct GMT_CTRL *GMT, struct PSSCALE_CTRL *Ctrl, struct GMT_OP
351
354
j = 0 ;
352
355
if (opt -> arg [0 ] == 'i' ) Ctrl -> L .interval = true, j = 1 ;
353
356
if (opt -> arg [j ]) Ctrl -> L .spacing = gmt_M_to_inch (GMT , & opt -> arg [j ]);
357
+ if (c ) c [0 ] = '+' ; /* Restore option string */
354
358
break ;
355
359
case 'M' :
356
360
Ctrl -> M .active = true;
@@ -372,16 +376,20 @@ static int parse (struct GMT_CTRL *GMT, struct PSSCALE_CTRL *Ctrl, struct GMT_OP
372
376
Ctrl -> S .active = true;
373
377
Ctrl -> S .mode = PSSCALE_ANNOT_NUMERICAL ; /* The default */
374
378
if (opt -> arg [0 ]) { /* Modern syntax with modifiers */
375
- if ((c = strstr (opt -> arg , "+a" ))) {
376
- Ctrl -> S .mode |= PSSCALE_ANNOT_ANGLED ;
377
- Ctrl -> S .angle = atof (& c [2 ]);
379
+ if ((c = gmt_first_modifier (GMT , opt -> arg , "acnsxy" ))) { /* Process any modifiers */
380
+ unsigned int pos = 0 ; /* Reset to start of new word */
381
+ while (gmt_getmodopt (GMT , 'S' , c , "acnsxy" , & pos , txt_a , & n_errors ) && n_errors == 0 ) {
382
+ switch (txt_a [0 ]) {
383
+ case 'a' : Ctrl -> S .angle = atof (& txt_a [1 ]); Ctrl -> S .mode |= PSSCALE_ANNOT_ANGLED ; break ;
384
+ case 'c' : Ctrl -> S .mode |= PSSCALE_ANNOT_CUSTOM ; break ;
385
+ case 'n' : Ctrl -> S .mode = PSSCALE_ANNOT_NUMERICAL ; break ;
386
+ case 's' : Ctrl -> S .skip = true; break ;
387
+ case 'x' : strncpy (Ctrl -> S .label , & txt_a [1 ], GMT_LEN256 ); break ;
388
+ case 'y' : strncpy (Ctrl -> S .unit , & txt_a [1 ], GMT_LEN256 ); break ;
389
+ default : break ; /* These are caught in gmt_getmodopt so break is just for Coverity */
390
+ }
391
+ }
378
392
}
379
- if (strstr (opt -> arg , "+c" ))
380
- Ctrl -> S .mode |= PSSCALE_ANNOT_CUSTOM ;
381
- if (strstr (opt -> arg , "+n" )) /* Default, but just in case */
382
- Ctrl -> S .mode = PSSCALE_ANNOT_NUMERICAL ;
383
- if (strstr (opt -> arg , "+s" ))
384
- Ctrl -> S .skip = true;
385
393
}
386
394
else /* Backwards compatible -S means -S+s */
387
395
Ctrl -> S .skip = true;
@@ -1026,7 +1034,10 @@ GMT_LOCAL void psscale_draw_colorbar (struct GMT_CTRL *GMT, struct PSSCALE_CTRL
1026
1034
strncpy (label , GMT -> current .map .frame .axis [GMT_X ].label , GMT_LEN256 - 1 );
1027
1035
strncpy (unit , GMT -> current .map .frame .axis [GMT_Y ].label , GMT_LEN256 - 1 );
1028
1036
GMT -> current .map .frame .axis [GMT_X ].label [0 ] = GMT -> current .map .frame .axis [GMT_Y ].label [1 ] = 0 ;
1029
-
1037
+ if (Ctrl -> L .active ) {
1038
+ strncpy (label , Ctrl -> S .label , GMT_LEN256 - 1 );
1039
+ strncpy (unit , Ctrl -> S .unit , GMT_LEN256 - 1 );
1040
+ }
1030
1041
if (flip & PSSCALE_FLIP_ANNOT ) { /* Place annotations on the opposite side */
1031
1042
justify = l_justify = (Ctrl -> D .horizontal ) ? PSL_BC : PSL_MR ;
1032
1043
y_base = width ;
0 commit comments