From 5feb09690f8d744f2deb623f224247427e8e7968 Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Wed, 11 Nov 2020 15:26:35 -1000 Subject: [PATCH 1/5] Add -Irefpoint to meca This will simplify adding actual meca symbols to legends. --- src/seis/psmeca.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/seis/psmeca.c b/src/seis/psmeca.c index 840b218cc31..d7e7d86e06f 100644 --- a/src/seis/psmeca.c +++ b/src/seis/psmeca.c @@ -66,6 +66,11 @@ struct PSMECA_CTRL { bool active; struct GMT_FILL fill; } G; + struct PSMECA_I { /* -D[g|j|n|x][+o[/]] */ + bool active; + struct GMT_REFPOINT *refpoint; + double off[2]; + } I; struct PSMECA_L { /* -L */ bool active; struct GMT_PEN pen; @@ -163,6 +168,7 @@ static void *New_Ctrl (struct GMT_CTRL *GMT) { /* Allocate and initialize a new static void Free_Ctrl (struct GMT_CTRL *GMT, struct PSMECA_CTRL *C) { /* Deallocate control structure */ if (!C) return; gmt_M_str_free (C->Z.file); + gmt_free_refpoint (GMT, &C->I.refpoint); gmt_M_free (GMT, C); } @@ -252,7 +258,7 @@ static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPT * returned when registering these sources/destinations with the API. */ - unsigned int n_errors = 0; + unsigned int n_errors = 0, n; char txt[GMT_LEN256] = {""}, txt_b[GMT_LEN256] = {""}, txt_c[GMT_LEN256] = {""}, *p = NULL; struct GMT_OPTION *opt = NULL; @@ -365,6 +371,17 @@ static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPT n_errors++; } break; + case 'I': + if ((Ctrl->I.refpoint = gmt_get_refpoint (GMT, opt->arg, 'I')) == NULL) { + n_errors++; /* Failed basic parsing */ + continue; + } + /* Args are [+o[/]] */ + if (gmt_validate_modifiers (GMT, Ctrl->I.refpoint->args, 'I', "o", GMT_MSG_ERROR)) n_errors++; + if (gmt_get_modifier (Ctrl->I.refpoint->args, 'o', txt)) { + if ((n = gmt_get_pair (GMT, txt, GMT_PAIR_DIM_DUP, Ctrl->I.off)) < 0) n_errors++; + } + break; case 'L': /* Draw outline [set outline attributes] */ Ctrl->L.active = true; if (opt->arg[0] && gmt_getpen (GMT, opt->arg, &Ctrl->L.pen)) { @@ -569,6 +586,9 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { if (gmt_map_setup (GMT, GMT->common.R.wesn)) Return (GMT_PROJECTION_ERROR); + if (Ctrl->I.active) + gmt_set_refpoint (GMT, Ctrl->I.refpoint); /* Finalize reference point plot coordinates, if needed */ + if ((PSL = gmt_plotinit (GMT, options)) == NULL) Return (GMT_RUNTIME_ERROR); gmt_plane_perspective (GMT, GMT->current.proj.z_project.view_plane, GMT->current.proj.z_level); gmt_set_basemap_orders (GMT, Ctrl->N.active ? GMT_BASEMAP_FRAME_BEFORE : GMT_BASEMAP_FRAME_AFTER, GMT_BASEMAP_GRID_BEFORE, GMT_BASEMAP_ANNOT_BEFORE); @@ -610,7 +630,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { n_rec++; /* Immediately skip locations outside of the map area */ - if (!Ctrl->N.active) { + if (!(Ctrl->N.active|| Ctrl->I.active)) { gmt_map_outside (GMT, in[GMT_X], in[GMT_Y]); if (abs (GMT->current.map.this_x_status) > 1 || abs (GMT->current.map.this_y_status) > 1) continue; } @@ -761,7 +781,12 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { /* Common to all input types ... */ - gmt_geo_to_xy (GMT, in[GMT_X], in[GMT_Y], &plot_x, &plot_y); + if (Ctrl->I.active) { + plot_x = Ctrl->I.refpoint->x; + plot_y = Ctrl->I.refpoint->y; + } + else + gmt_geo_to_xy (GMT, in[GMT_X], in[GMT_Y], &plot_x, &plot_y); /* If option -C is used, read the new position */ From 22c00c868882989d16415f779f5e6b4e9b00dd82 Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Wed, 11 Nov 2020 16:50:48 -1000 Subject: [PATCH 2/5] Update psmeca.c --- src/seis/psmeca.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/seis/psmeca.c b/src/seis/psmeca.c index d7e7d86e06f..2d243fefa84 100644 --- a/src/seis/psmeca.c +++ b/src/seis/psmeca.c @@ -179,7 +179,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) { if (level == GMT_MODULE_PURPOSE) return (GMT_NOERROR); GMT_Message (API, GMT_TIME_NONE, "usage: %s [] %s %s\n", name, GMT_J_OPT, GMT_Rgeo_OPT); GMT_Message (API, GMT_TIME_NONE, "\t-S[+a][+f][+j][+o[/]] [%s]\n", GMT_B_OPT); - GMT_Message (API, GMT_TIME_NONE, "\t[-C[][+s]] [-D/] [-E] [-G] %s[-L] [-M]\n", API->K_OPT); + GMT_Message (API, GMT_TIME_NONE, "\t[-C[][+s]] [-D/] [-E] [-G] [-D%s%s %s[-L] [-M]\n", GMT_XYANCHOR, GMT_OFFSET, API->K_OPT); GMT_Message (API, GMT_TIME_NONE, "\t[-Fa[[/[]]] [-Fe] [-Fg] [-Fo] [-Fr] [-Fp[]] [-Ft[]] [-Fz[]]\n"); GMT_Message (API, GMT_TIME_NONE, "\t[-N] %s%s[-T[/]] [%s] [%s] [-W]\n", API->O_OPT, API->P_OPT, GMT_U_OPT, GMT_V_OPT); GMT_Message (API, GMT_TIME_NONE, "\t[%s] [%s] [-Z]\n", GMT_X_OPT, GMT_Y_OPT); @@ -231,6 +231,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) { GMT_Message (API, GMT_TIME_NONE, "\t r Draw box behind labels.\n"); GMT_Message (API, GMT_TIME_NONE, "\t z Overlay zero trace moment tensor using default pen (see -W) or append outline pen.\n"); gmt_fill_syntax (API->GMT, 'G', NULL, "Set filling of compressive quadrants [Default is black]."); + gmt_refpoint_syntax (API->GMT, "I", "Specify position of a single symbol for information only [0/0].", 0, 1); GMT_Option (API, "K"); GMT_Message (API, GMT_TIME_NONE, "\t-L Sets pen attribute for outline other than the default set by -W.\n"); GMT_Message (API, GMT_TIME_NONE, "\t-M Same size for any magnitude. Size is given with -S.\n"); @@ -372,6 +373,7 @@ static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPT } break; case 'I': + Ctrl->I.active = true; if ((Ctrl->I.refpoint = gmt_get_refpoint (GMT, opt->arg, 'I')) == NULL) { n_errors++; /* Failed basic parsing */ continue; @@ -586,8 +588,16 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { if (gmt_map_setup (GMT, GMT->common.R.wesn)) Return (GMT_PROJECTION_ERROR); - if (Ctrl->I.active) + if (Ctrl->I.active) { + int mode = Ctrl->I.refpoint->mode; gmt_set_refpoint (GMT, Ctrl->I.refpoint); /* Finalize reference point plot coordinates, if needed */ + Ctrl->I.refpoint->x += 0.5 * Ctrl->S.scale; plot_y = Ctrl->I.refpoint->y += 0.5 * Ctrl->S.scale; /* First let these refer to BL of symbol BoundingBox */ + if (mode == GMT_REFPOINT_JUST) { /* Must adjust these auto-locations by symbol size and offsets */ + double dim[2] = {Ctrl->S.scale, Ctrl->S.scale}; + gmt_adjust_refpoint (GMT, Ctrl->I.refpoint, dim, Ctrl->I.off, Ctrl->I.refpoint->justify, PSL_BL); + } + plot_x = Ctrl->I.refpoint->x; plot_y = Ctrl->I.refpoint->y; + } if ((PSL = gmt_plotinit (GMT, options)) == NULL) Return (GMT_RUNTIME_ERROR); gmt_plane_perspective (GMT, GMT->current.proj.z_project.view_plane, GMT->current.proj.z_level); @@ -781,11 +791,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { /* Common to all input types ... */ - if (Ctrl->I.active) { - plot_x = Ctrl->I.refpoint->x; - plot_y = Ctrl->I.refpoint->y; - } - else + if (!Ctrl->I.active) gmt_geo_to_xy (GMT, in[GMT_X], in[GMT_Y], &plot_x, &plot_y); /* If option -C is used, read the new position */ @@ -896,8 +902,11 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { PSL_plotsymbol (PSL, T_x, T_y, &Ctrl->A2.size, Ctrl->A2.T_symbol); } event_title[0] = string[0] = '\0'; /* Reset these two in case next record misses "string" */ + if (Ctrl->I.active) goto once_only; } while (true); +once_only: /* When -I is active we only plot the very first entry */ + if (GMT_End_IO (API, GMT_IN, 0) != GMT_NOERROR) { /* Disables further data input */ Return (API->error); } From c4a8efae1875ecd5ac55d23802b2931cc96d9635 Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Wed, 11 Nov 2020 16:59:27 -1000 Subject: [PATCH 3/5] Update psmeca.c --- src/seis/psmeca.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/seis/psmeca.c b/src/seis/psmeca.c index 2d243fefa84..e39f61cbe48 100644 --- a/src/seis/psmeca.c +++ b/src/seis/psmeca.c @@ -590,6 +590,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { if (Ctrl->I.active) { int mode = Ctrl->I.refpoint->mode; + Ctrl->N.active = true; gmt_set_refpoint (GMT, Ctrl->I.refpoint); /* Finalize reference point plot coordinates, if needed */ Ctrl->I.refpoint->x += 0.5 * Ctrl->S.scale; plot_y = Ctrl->I.refpoint->y += 0.5 * Ctrl->S.scale; /* First let these refer to BL of symbol BoundingBox */ if (mode == GMT_REFPOINT_JUST) { /* Must adjust these auto-locations by symbol size and offsets */ From 7668d584c7045c878b5af7974bd859b6ec874232 Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Wed, 11 Nov 2020 17:09:36 -1000 Subject: [PATCH 4/5] Update psmeca.c --- src/seis/psmeca.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/seis/psmeca.c b/src/seis/psmeca.c index e39f61cbe48..2e5c6938539 100644 --- a/src/seis/psmeca.c +++ b/src/seis/psmeca.c @@ -66,7 +66,7 @@ struct PSMECA_CTRL { bool active; struct GMT_FILL fill; } G; - struct PSMECA_I { /* -D[g|j|n|x][+o[/]] */ + struct PSMECA_I { /* -D[g|j|J|n|x][+o[/]] */ bool active; struct GMT_REFPOINT *refpoint; double off[2]; @@ -179,7 +179,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) { if (level == GMT_MODULE_PURPOSE) return (GMT_NOERROR); GMT_Message (API, GMT_TIME_NONE, "usage: %s [
] %s %s\n", name, GMT_J_OPT, GMT_Rgeo_OPT); GMT_Message (API, GMT_TIME_NONE, "\t-S[+a][+f][+j][+o[/]] [%s]\n", GMT_B_OPT); - GMT_Message (API, GMT_TIME_NONE, "\t[-C[][+s]] [-D/] [-E] [-G] [-D%s%s %s[-L] [-M]\n", GMT_XYANCHOR, GMT_OFFSET, API->K_OPT); + GMT_Message (API, GMT_TIME_NONE, "\t[-C[][+s]] [-D/] [-E] [-G] [-I%s%s %s[-L] [-M]\n", GMT_XYANCHOR, GMT_OFFSET, API->K_OPT); GMT_Message (API, GMT_TIME_NONE, "\t[-Fa[[/[]]] [-Fe] [-Fg] [-Fo] [-Fr] [-Fp[]] [-Ft[]] [-Fz[]]\n"); GMT_Message (API, GMT_TIME_NONE, "\t[-N] %s%s[-T[/]] [%s] [%s] [-W]\n", API->O_OPT, API->P_OPT, GMT_U_OPT, GMT_V_OPT); GMT_Message (API, GMT_TIME_NONE, "\t[%s] [%s] [-Z]\n", GMT_X_OPT, GMT_Y_OPT); @@ -588,9 +588,9 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { if (gmt_map_setup (GMT, GMT->common.R.wesn)) Return (GMT_PROJECTION_ERROR); - if (Ctrl->I.active) { + if (Ctrl->I.active) { /* Not plotting into a map but a legend box, so fix the plot location, adjust if needed */ int mode = Ctrl->I.refpoint->mode; - Ctrl->N.active = true; + Ctrl->N.active = true; /* Allow this symbol to be placed anywhere relative to given anchor */ gmt_set_refpoint (GMT, Ctrl->I.refpoint); /* Finalize reference point plot coordinates, if needed */ Ctrl->I.refpoint->x += 0.5 * Ctrl->S.scale; plot_y = Ctrl->I.refpoint->y += 0.5 * Ctrl->S.scale; /* First let these refer to BL of symbol BoundingBox */ if (mode == GMT_REFPOINT_JUST) { /* Must adjust these auto-locations by symbol size and offsets */ @@ -641,7 +641,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { n_rec++; /* Immediately skip locations outside of the map area */ - if (!(Ctrl->N.active|| Ctrl->I.active)) { + if (!Ctrl->N.active) { gmt_map_outside (GMT, in[GMT_X], in[GMT_Y]); if (abs (GMT->current.map.this_x_status) > 1 || abs (GMT->current.map.this_y_status) > 1) continue; } @@ -792,7 +792,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { /* Common to all input types ... */ - if (!Ctrl->I.active) + if (!Ctrl->I.active) /* Update plot location */ gmt_geo_to_xy (GMT, in[GMT_X], in[GMT_Y], &plot_x, &plot_y); /* If option -C is used, read the new position */ @@ -902,11 +902,11 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { gmt_setfill (GMT, &Ctrl->E2.fill, Ctrl->T2.active ? 1 : 0); PSL_plotsymbol (PSL, T_x, T_y, &Ctrl->A2.size, Ctrl->A2.T_symbol); } - event_title[0] = string[0] = '\0'; /* Reset these two in case next record misses "string" */ - if (Ctrl->I.active) goto once_only; + event_title[0] = string[0] = '\0'; /* Reset these two in case next record misses "string" */ + if (Ctrl->I.active) goto once_only; /* When -I is active we only plot the very first entry */ } while (true); -once_only: /* When -I is active we only plot the very first entry */ +once_only: if (GMT_End_IO (API, GMT_IN, 0) != GMT_NOERROR) { /* Disables further data input */ Return (API->error); From 889b4f105ba8977fb35fbb6e97e60fc90b0618cf Mon Sep 17 00:00:00 2001 From: Paul Wessel Date: Tue, 7 Jun 2022 10:47:56 +0100 Subject: [PATCH 5/5] Update psmeca.c --- src/seis/psmeca.c | 50 +++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/src/seis/psmeca.c b/src/seis/psmeca.c index 4769700dc63..6d42b077365 100644 --- a/src/seis/psmeca.c +++ b/src/seis/psmeca.c @@ -183,7 +183,7 @@ static void *New_Ctrl (struct GMT_CTRL *GMT) { /* Allocate and initialize a new static void Free_Ctrl (struct GMT_CTRL *GMT, struct PSMECA_CTRL *C) { /* Deallocate control structure */ if (!C) return; - gmt_free_refpoint (GMT, &C->I2.refpoint); + gmt_free_refpoint (GMT, &C->M.refpoint); gmt_M_str_free (C->C.file); gmt_M_free (GMT, C); } @@ -477,18 +477,6 @@ static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPT n_errors++; } break; - case 'M': - Ctrl->M.active = true; - if ((Ctrl->M.refpoint = gmt_get_refpoint (GMT, opt->arg, 'I')) == NULL) { - n_errors++; /* Failed basic parsing */ - continue; - } - /* Args are [+o[/]] */ - if (gmt_validate_modifiers (GMT, Ctrl->M.refpoint->args, 'I', "o", GMT_MSG_ERROR)) n_errors++; - if (gmt_get_modifier (Ctrl->M.refpoint->args, 'o', txt)) { - if ((n = gmt_get_pair (GMT, txt, GMT_PAIR_DIM_DUP, Ctrl->M.off)) < 0) n_errors++; - } - break; case 'H': /* Overall symbol/pen scale column provided */ n_errors += gmt_M_repeated_module_option (API, Ctrl->H.active); if (opt->arg[0]) { /* Gave a fixed scale - no reading from file */ @@ -510,13 +498,23 @@ static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPT n_errors++; } break; - case 'M': /* Same size for any magnitude [Deprecated 8/14/2021 6.3.0 - use -S+m instead] */ - if (gmt_M_compat_check (GMT, 6)) { + case 'M': + if (opt->arg[0] == '\0' && gmt_M_compat_check (GMT, 6)) { /* Same size for any magnitude [Deprecated 8/14/2021 6.3.0 - use -S+m instead] */ GMT_Report (API, GMT_MSG_COMPAT, "-M is deprecated from 6.3.0; use -S modifier +m instead.\n"); Ctrl->S.fixed = true; } - else - n_errors += gmt_default_option_error (GMT, opt); + else { + n_errors += gmt_M_repeated_module_option (API, Ctrl->M.active); + if ((Ctrl->M.refpoint = gmt_get_refpoint (GMT, opt->arg, 'M')) == NULL) { + n_errors++; /* Failed basic parsing */ + continue; + } + /* Args are [+o[/]] */ + if (gmt_validate_modifiers (GMT, Ctrl->M.refpoint->args, 'I', "o", GMT_MSG_ERROR)) n_errors++; + if (gmt_get_modifier (Ctrl->M.refpoint->args, 'o', txt)) { + if ((n = gmt_get_pair (GMT, txt, GMT_PAIR_DIM_DUP, Ctrl->M.off)) < 0) n_errors++; + } + } break; case 'N': /* Do not skip points outside border */ n_errors += gmt_M_repeated_module_option (API, Ctrl->N.active); @@ -1171,12 +1169,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { PSL_plotsymbol (PSL, T_x, T_y, &Ctrl->A2.size, Ctrl->A2.T_symbol); } event_title[0] = string[0] = '\0'; /* Reset these two in case next record misses "string" */ - } } - else if (n_scanned == 1) /* Only got event title */ - strncpy (event_title, In->text, GMT_BUFSIZ-1); - else /* Got no title */ - event_title[0] = '\0'; } /* Gather and transform the input records, depending on type */ @@ -1231,7 +1224,8 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { Ctrl->T.active = true; Ctrl->T.n_plane = 1; meca.NP1.rake = 1000.; - GMT_Report (API, GMT_MSG_WARNING, "Second plane is not defined for event %s only first plane is plotted.\n", In->text); + event_name = (has_text) ? S->text[row] : no_name; + GMT_Report (API, GMT_MSG_WARNING, "Second plane is not defined for event %s only first plane is plotted.\n", event_name); } else meca.NP1.rake = meca_computed_rake2(meca.NP2.str, meca.NP2.dip, meca.NP1.str, meca.NP1.dip, fault); @@ -1288,17 +1282,17 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { /* Common to all input types ... */ - if (!Ctrl->I.active) /* Update plot location */ + if (!Ctrl->M.active) /* Update plot location */ gmt_geo_to_xy (GMT, in[GMT_X], in[GMT_Y], &plot_x, &plot_y); - /* If option -C is used, read the new position */ + /* If option -A is used, read the new position */ - if (Ctrl->C.active) { + if (Ctrl->A.active) { if (fabs (xynew[GMT_X]) > EPSIL || fabs (xynew[GMT_Y]) > EPSIL) { - gmt_setpen (GMT, &Ctrl->C.pen); + gmt_setpen (GMT, &Ctrl->A.pen); gmt_geo_to_xy (GMT, xynew[GMT_X], xynew[GMT_Y], &plot_xnew, &plot_ynew); gmt_setfill (GMT, &Ctrl->G.fill, 1); - PSL_plotsymbol (PSL, plot_x, plot_y, &Ctrl->C.size, PSL_CIRCLE); + PSL_plotsymbol (PSL, plot_x, plot_y, &Ctrl->A.size, PSL_CIRCLE); PSL_plotsegment (PSL, plot_x, plot_y, plot_xnew, plot_ynew); plot_x = plot_xnew; plot_y = plot_ynew;