Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/gmt_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -7515,7 +7515,10 @@ bool gmt_getpen (struct GMT_CTRL *GMT, char *buffer, struct GMT_PEN *P) {

/* Processes pen specifications given as [width[,<color>[,<style>[t<unit>]]][@<transparency>] */

if (gmt_M_is_dnan (P->width)) { /* Worry in case no width is given */
if (gmt_M_is_dnan (P->width) || P->width < 0.0) { /* Worry in case no width is given. Some callers (e.g., psmeca)
use a negative width as a sentinel for "not yet set"; treat
that the same as NaN so a color- or style-only pen string
(e.g., "red") is not mistaken for an explicit (bogus) width. */
strcpy (def_width, "0"); /* To avoid any parsing errors */
set_NaN = true; /* Flag this specific case */
}
Expand Down
1 change: 1 addition & 0 deletions src/seis/meca.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum Seis_scaletype {
struct SEIS_OFFSET_LINE {
bool active;
bool convert_geo; /* True if coupe -D+c, i.e., given geographical coordinates as alternate location */
bool pen_set; /* True if +p<pen> was given (even if <pen> only had a color and/or style) */
unsigned int mode; /* 0-3 as above */
unsigned int symbol; /* Default to PSL_CIRCLE */
unsigned int fill_mode; /* Default to SEIS_EVENT_FILL */
Expand Down
16 changes: 12 additions & 4 deletions src/seis/pscoupe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1438,8 +1438,12 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) {
meca.NP1.dip = in[4];
meca.NP1.rake = in[5];
meca.magms = in[6];
moment.mant = meca.magms;
moment.exponent = 0;
if (Ctrl->S.linear) /* Aki & Richards only gives us the magnitude; derive M0 for +l [#6840] */
moment = meca_computed_moment (meca.magms);
else {
moment.mant = meca.magms;
moment.exponent = 0;
}
meca_define_second_plane (meca.NP1, &meca.NP2);
pscoupe_rot_meca (meca, Ctrl->A.PREF, &mecar);
}
Expand All @@ -1449,8 +1453,12 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) {
meca.NP2.str = in[5];
fault = in[6];
meca.magms = in[7];
moment.exponent = 0;
moment.mant = meca.magms;
if (Ctrl->S.linear) /* Principal planes format only gives us the magnitude; derive M0 for +l [#6840] */
moment = meca_computed_moment (meca.magms);
else {
moment.exponent = 0;
moment.mant = meca.magms;
}
meca.NP2.dip = meca_computed_dip2 (meca.NP1.str, meca.NP1.dip, meca.NP2.str);
if (meca.NP2.dip == 1000.0) {
not_defined = true;
Expand Down
92 changes: 66 additions & 26 deletions src/seis/psmeca.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ struct PSMECA_CTRL {
} I;
struct PSMECA_L { /* -L<pen> */
bool active;
bool pen_set; /* True if a pen (even just color/style) was given */
struct GMT_PEN pen;
} L;
struct PSMECA_N { /* -N */
Expand All @@ -88,6 +89,7 @@ struct PSMECA_CTRL {
} S;
struct PSMECA_T { /* -T[<plane>][+p<pen>] */
bool active;
bool pen_set; /* True if a pen (even just color/style) was given */
unsigned int n_plane;
struct GMT_PEN pen;
} T;
Expand All @@ -110,6 +112,7 @@ struct PSMECA_CTRL {
} G2;
struct PSMECA_P2 { /* -Fp[<pen>] */
bool active;
bool pen_set; /* True if a pen (even just color/style) was given */
struct GMT_PEN pen;
} P2;
struct PSMECA_R2 { /* -Fr[<fill>] */
Expand All @@ -118,13 +121,15 @@ struct PSMECA_CTRL {
} R2;
struct PSMECA_T2 { /* -Ft[<pen>] */
bool active;
bool pen_set; /* True if a pen (even just color/style) was given */
struct GMT_PEN pen;
} T2;
struct PSMECA_O2 { /* -Fo */
bool active;
} O2;
struct PSMECA_Z2 { /* -Fz[<pen>] */
bool active;
bool pen_set; /* True if a pen (even just color/style) was given */
struct GMT_PEN pen;
} Z2;
};
Expand Down Expand Up @@ -352,9 +357,12 @@ static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPT
break;
case 'p': /* Draw outline of P axis symbol [set outline attributes] */
n_errors += gmt_M_repeated_module_option (API, Ctrl->P2.active);
if (opt->arg[1] && gmt_getpen (GMT, &opt->arg[1], &Ctrl->P2.pen)) {
gmt_pen_syntax (GMT, ' ', "Fp", " ", NULL, 0);
n_errors++;
if (opt->arg[1]) {
Ctrl->P2.pen_set = true;
if (gmt_getpen (GMT, &opt->arg[1], &Ctrl->P2.pen)) {
gmt_pen_syntax (GMT, ' ', "Fp", " ", NULL, 0);
n_errors++;
}
}
break;
case 'r': /* draw box around text */
Expand All @@ -366,19 +374,25 @@ static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPT
break;
case 't': /* Draw outline of T axis symbol [set outline attributes] */
n_errors += gmt_M_repeated_module_option (API, Ctrl->T2.active);
if (opt->arg[1] && gmt_getpen (GMT, &opt->arg[1], &Ctrl->T2.pen)) {
gmt_pen_syntax (GMT, ' ', "Ft", " ", NULL, 0);
n_errors++;
if (opt->arg[1]) {
Ctrl->T2.pen_set = true;
if (gmt_getpen (GMT, &opt->arg[1], &Ctrl->T2.pen)) {
gmt_pen_syntax (GMT, ' ', "Ft", " ", NULL, 0);
n_errors++;
}
}
break;
case 'o': /* use psvelomeca format (without depth in 3rd column) */
n_errors += gmt_M_repeated_module_option (API, Ctrl->O2.active);
break;
case 'z': /* overlay zerotrace moment tensor */
n_errors += gmt_M_repeated_module_option (API, Ctrl->Z2.active);
if (opt->arg[1] && gmt_getpen (GMT, &opt->arg[1], &Ctrl->Z2.pen)) { /* Set pen attributes */
gmt_pen_syntax (GMT, ' ', "Fz", " ", NULL, 0);
n_errors++;
if (opt->arg[1]) {
Ctrl->Z2.pen_set = true;
if (gmt_getpen (GMT, &opt->arg[1], &Ctrl->Z2.pen)) { /* Set pen attributes */
gmt_pen_syntax (GMT, ' ', "Fz", " ", NULL, 0);
n_errors++;
}
}
break;
}
Expand Down Expand Up @@ -406,9 +420,12 @@ static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPT
break;
case 'L': /* Draw outline [set outline attributes] */
n_errors += gmt_M_repeated_module_option (API, Ctrl->L.active);
if (opt->arg[0] && gmt_getpen (GMT, opt->arg, &Ctrl->L.pen)) {
gmt_pen_syntax (GMT, 'L', NULL, " ", NULL, 0);
n_errors++;
if (opt->arg[0]) {
Ctrl->L.pen_set = true;
if (gmt_getpen (GMT, opt->arg, &Ctrl->L.pen)) {
gmt_pen_syntax (GMT, 'L', NULL, " ", NULL, 0);
n_errors++;
}
}
break;
case 'M': /* Same size for any magnitude [Deprecated 8/14/2021 6.3.0 - use -S+m instead] */
Expand Down Expand Up @@ -519,13 +536,19 @@ static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPT
case 'T':
n_errors += gmt_M_repeated_module_option (API, Ctrl->T.active);
if (opt->arg[0] == '\0') continue; /* Default plane and pen implied; move on */
if ((p = strstr (opt->arg, "+p")) && gmt_getpen (GMT, &p[2], &Ctrl->T.pen)) { /* Modern modifier for pen but failed parsing the pen */
gmt_pen_syntax (GMT, 'T', NULL, " ", NULL, 0);
n_errors++;
if ((p = strstr (opt->arg, "+p"))) { /* Modern modifier for pen */
Ctrl->T.pen_set = true;
if (gmt_getpen (GMT, &p[2], &Ctrl->T.pen)) { /* Failed parsing the pen */
gmt_pen_syntax (GMT, 'T', NULL, " ", NULL, 0);
n_errors++;
}
}
else if ((p = strchr (opt->arg, '/')) && gmt_getpen (GMT, &p[1], &Ctrl->T.pen)) {
gmt_pen_syntax (GMT, 'T', NULL, " ", NULL, 0);
n_errors++;
else if ((p = strchr (opt->arg, '/'))) {
Ctrl->T.pen_set = true;
if (gmt_getpen (GMT, &p[1], &Ctrl->T.pen)) {
gmt_pen_syntax (GMT, 'T', NULL, " ", NULL, 0);
n_errors++;
}
}
if (strchr ("012", opt->arg[0])) Ctrl->T.n_plane = opt->arg[0] - '0';
break;
Expand Down Expand Up @@ -561,14 +584,27 @@ static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPT
//n_errors += gmt_M_check_condition (GMT, Ctrl->S.active && Ctrl->S.scale <= 0.0, "Option -S: must specify scale\n");
n_errors += gmt_M_check_condition (GMT, Ctrl->C.active && Ctrl->O2.active, "Option -Z cannot be combined with -Fo\n");

/* Set to default pen where needed */

if (Ctrl->A.pen.width < 0.0) Ctrl->A.pen = Ctrl->W.pen;
if (Ctrl->L.pen.width < 0.0) Ctrl->L.pen = Ctrl->W.pen;
if (Ctrl->T.pen.width < 0.0) Ctrl->T.pen = Ctrl->W.pen;
if (Ctrl->T2.pen.width < 0.0) Ctrl->T2.pen = Ctrl->W.pen;
if (Ctrl->P2.pen.width < 0.0) Ctrl->P2.pen = Ctrl->W.pen;
if (Ctrl->Z2.pen.width < 0.0) Ctrl->Z2.pen = Ctrl->W.pen;
/* Set to default pen where needed. If the option was never given a pen at all
* (e.g., plain -T with no plane/pen, or -L with no argument) we fully inherit
* -W's pen. But if a pen was given, even if it only set the color and/or style
* (e.g., -T0/red or -A+pred), we must not discard that; we only need to supply
* a width, since none was given [see #6840]. */
#define SEIS_PEN_UNSET(pen) (gmt_M_is_dnan ((pen).width) || (pen).width < 0.0)

if (Ctrl->A.pen_set) { if (SEIS_PEN_UNSET (Ctrl->A.pen)) Ctrl->A.pen.width = Ctrl->W.pen.width; }
else if (SEIS_PEN_UNSET (Ctrl->A.pen)) Ctrl->A.pen = Ctrl->W.pen;
if (Ctrl->L.pen_set) { if (SEIS_PEN_UNSET (Ctrl->L.pen)) Ctrl->L.pen.width = Ctrl->W.pen.width; }
else if (SEIS_PEN_UNSET (Ctrl->L.pen)) Ctrl->L.pen = Ctrl->W.pen;
if (Ctrl->T.pen_set) { if (SEIS_PEN_UNSET (Ctrl->T.pen)) Ctrl->T.pen.width = Ctrl->W.pen.width; }
else if (SEIS_PEN_UNSET (Ctrl->T.pen)) Ctrl->T.pen = Ctrl->W.pen;
if (Ctrl->T2.pen_set) { if (SEIS_PEN_UNSET (Ctrl->T2.pen)) Ctrl->T2.pen.width = Ctrl->W.pen.width; }
else if (SEIS_PEN_UNSET (Ctrl->T2.pen)) Ctrl->T2.pen = Ctrl->W.pen;
if (Ctrl->P2.pen_set) { if (SEIS_PEN_UNSET (Ctrl->P2.pen)) Ctrl->P2.pen.width = Ctrl->W.pen.width; }
else if (SEIS_PEN_UNSET (Ctrl->P2.pen)) Ctrl->P2.pen = Ctrl->W.pen;
if (Ctrl->Z2.pen_set) { if (SEIS_PEN_UNSET (Ctrl->Z2.pen)) Ctrl->Z2.pen.width = Ctrl->W.pen.width; }
else if (SEIS_PEN_UNSET (Ctrl->Z2.pen)) Ctrl->Z2.pen = Ctrl->W.pen;

#undef SEIS_PEN_UNSET

/* Default -Fe<fill> and -Fg<fill> to -E<fill> and -G<fill> */

Expand Down Expand Up @@ -858,6 +894,8 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) {
if (gmt_M_is_zero (meca.NP1.rake)) meca.NP1.rake = 0.00001; /* Fixing the issue http://gmt.soest.hawaii.edu/issues/894 */
meca.magms = in[5+new_fmt];
meca.moment.exponent = 0;
if (Ctrl->S.linear) /* Aki & Richards only gives us the magnitude; derive M0 for +l [#6840] */
meca.moment = meca_computed_moment (meca.magms);
meca_define_second_plane (meca.NP1, &meca.NP2);
}
else if (Ctrl->S.readmode == SEIS_READ_PLANES) {
Expand All @@ -871,6 +909,8 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) {
fault = in[5+new_fmt];
meca.magms = in[6+new_fmt];
meca.moment.exponent = 0;
if (Ctrl->S.linear) /* Principal planes format only gives us the magnitude; derive M0 for +l [#6840] */
meca.moment = meca_computed_moment (meca.magms);
meca.NP2.dip = meca_computed_dip2(meca.NP1.str, meca.NP1.dip, meca.NP2.str);
if (meca.NP2.dip == 1000.0) {
not_defined = true;
Expand Down
19 changes: 19 additions & 0 deletions src/seis/utilmeca.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,24 @@ double meca_computed_mw (struct SEIS_MOMENT moment, double ms) {
return (mw);
}

/**********************************************************************/
struct SEIS_MOMENT meca_computed_moment (double mw) {
/* Compute the scalar seismic moment M0 (as mantissa * 10^exponent, with the
* mantissa normalized to [1,10)) from a given Mw magnitude. This is simply
* the inverse of meca_computed_mw and is needed for formats such as Aki &
* Richards (-Sa) or principal planes (-Sp) that only carry a magnitude, yet
* still wish to support the -S...+l modifier that scales symbol size by the
* seismic moment instead of the magnitude [see issue #6840]. */

struct SEIS_MOMENT moment;
double log10_M0 = 1.5 * mw + 16.1; /* Kanamori (1977): Mw = (2/3)(log10(M0) - 16.1) */

moment.exponent = (int)floor (log10_M0);
moment.mant = pow (10.0, log10_M0 - moment.exponent);

return (moment);
}

/*********************************************************************/
static double utilmeca_computed_strike1 (struct SEIS_NODAL_PLANE NP1) {
/*
Expand Down Expand Up @@ -1059,6 +1077,7 @@ unsigned int meca_line_parse (struct GMT_CTRL *GMT, struct SEIS_OFFSET_LINE *L,
L->mode |= SEIS_CART_OFFSET_FIX;
break;
case 'p': /* Line and symbol pen */
L->pen_set = true;
if (p[1] == '\0' || gmt_getpen (GMT, &p[1], &L->pen)) {
gmt_pen_syntax (GMT, option, NULL, " ", NULL, 0);
n_errors++;
Expand Down
1 change: 1 addition & 0 deletions src/seis/utilmeca.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void meca_get_trans (struct GMT_CTRL *GMT, double slon, double slat, double *t11
double meca_ps_mechanism (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, double y0, st_me meca, double size, struct GMT_FILL *F, struct GMT_FILL *E, int outline);
double meca_ps_plan (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, double y0, st_me meca, double size, int num_of_plane);
double meca_computed_mw(struct SEIS_MOMENT moment, double ms);
struct SEIS_MOMENT meca_computed_moment(double mw);
double meca_computed_dip2(double str1, double dip1, double str2);
double meca_computed_rake2(double str1, double dip1, double str2, double dip2, double fault);
void meca_define_second_plane(struct SEIS_NODAL_PLANE NP, struct SEIS_NODAL_PLANE *NP2);
Expand Down
Loading