Skip to content

Commit db194fe

Browse files
joa-quimEsteban82
andauthored
psmeca: let it recognize master CPTs in -C (#8966)
* psmeca: let it recognize master CPTs in -C * Add execute permission to gmt_functions.sh * Add execute permission to var_offset.sh --------- Co-authored-by: Esteban82 <federico.esteban@gmail.com>
1 parent 7e40e67 commit db194fe

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

share/tools/gmt_functions.sh

100644100755
File mode changed.

src/seis/psmeca.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,11 @@ static int usage (struct GMTAPI_CTRL *API, int level) {
259259
}
260260

261261
GMT_LOCAL bool psmeca_is_old_C_option (struct GMT_CTRL *GMT, char *arg) {
262-
if (strstr (arg, ".cpt")) return false; /* Clearly a CPT file given */
263-
if (strstr (arg, "+s") || strchr (arg, 'P')) return true; /* Clearly setting the circle diameter in old -C */
262+
if (strstr(arg, ".cpt")) return false; /* Clearly a CPT file given */
263+
if (strstr(arg, "+s") || strchr(arg, 'P')) return true; /* Clearly setting the circle diameter in old -C */
264264
if (GMT->current.setting.run_mode == GMT_CLASSIC && arg[0] == '\0') return true; /* A blank -C in classic mode is clearly the old -C with no settings */
265-
if (arg[0]) return true; /* Whatever this is, it is for -A to deal with */
266-
GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "Option -C: Must assume under modern mode that -C here means use current CPT\n");
265+
if (arg[0] && !gmt_is_cpt_master(GMT, arg)) return true; /* Whatever this is, it is for -A to deal with */
266+
GMT_Report(GMT->parent, GMT_MSG_INFORMATION, "Option -C: Must assume under modern mode that -C here means use current CPT\n");
267267
return false; /* This assumes nobody would use just -C in modern mode but actually mean the old -C */
268268
}
269269

@@ -708,6 +708,27 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) {
708708
if (D->n_records == 0)
709709
GMT_Report (API, GMT_MSG_WARNING, "No data records provided\n");
710710

711+
if (Ctrl->C.active && !Ctrl->O2.active && CPT) {
712+
/* Resample the CPT to span the actual depth range of the events to be plotted */
713+
double dep_min = DBL_MAX, dep_max = -DBL_MAX, d;
714+
for (tbl = 0; tbl < D->n_tables; tbl++)
715+
for (seg = 0; seg < D->table[tbl]->n_segments; seg++)
716+
for (row = 0; row < D->table[tbl]->segment[seg]->n_rows; row++) {
717+
d = D->table[tbl]->segment[seg]->data[GMT_Z][row];
718+
if (gmt_M_is_dnan(d) || d < Ctrl->D.depmin || d > Ctrl->D.depmax) continue;
719+
if (d < dep_min) dep_min = d;
720+
if (d > dep_max) dep_max = d;
721+
}
722+
if (dep_min < dep_max) {
723+
unsigned int k;
724+
double *z_new = gmt_M_memory(GMT, NULL, CPT->n_colors + 1, double);
725+
for (k = 0; k <= CPT->n_colors; k++)
726+
z_new[k] = dep_min + k * (dep_max - dep_min) / CPT->n_colors;
727+
CPT = gmt_sample_cpt(GMT, CPT, z_new, (int)(CPT->n_colors + 1), CPT->is_continuous, false, false, false);
728+
gmt_M_free(GMT, z_new);
729+
}
730+
}
731+
711732
for (tbl = 0; tbl < D->n_tables; tbl++) {
712733
for (seg = 0; seg < D->table[tbl]->n_segments; seg++) {
713734
S = D->table[tbl]->segment[seg]; /* Shorthand */

test/pstext/var_offset.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)