diff --git a/doc/rst/source/supplements/seis/coupe.rst b/doc/rst/source/supplements/seis/coupe.rst index e80f601ba03..2dffd445718 100644 --- a/doc/rst/source/supplements/seis/coupe.rst +++ b/doc/rst/source/supplements/seis/coupe.rst @@ -20,6 +20,7 @@ Synopsis |-S|\ *format*\ [*scale*][**+a**\ *angle*][**+f**\ *font*][**+j**\ *justify*][**+l**][**+m**][**+o**\ *dx*\ [/*dy*]][**+s**\ *reference*] [ |SYN_OPT-B| ] [ |-C|\ *cpt* ] +[ |-D|\ [**+c**][**+g**\ [*fill*]][**+o**\ *dx*\ [/*dy*]][**+p**\ *pen*][**+s**\ [*symbol*]\ *size*] ] [ |-E|\ *fill* ] [ |-F|\ *mode*\ [*args*] ] [ |-G|\ *fill* ] @@ -136,6 +137,27 @@ Optional Arguments Give a CPT and let compressive part color be determined by the z-value in the third column. +.. _-D: + +**-D**\ [**+c**][**+g**\ [*fill*]][**+o**\ *dx*\ [/*dy*]][**+p**\ *pen*][**+s**\ [*symbol*]\ *size*] ] + Offsets projected focal mechanisms to the alternate distance, depth given + in the last two columns of the input file before the (optional) text + string. Instead, if alternate geographical coordinates are given in the two columns then use **+c** to first + convert them to *distance, depth* coordinates in the crossectional plane, and after projection to + plot locations you can further adjust them via a fixed plot offset **+o**\ *dx/dy* . + Alternatively, use **+o** to interpret the contents of the two + columns as plot offsets instead, or append fixed offset *dx/dy* for all adjusted events plot locations. + We will draw a line connecting the original and relocated + beachball positions and optionally place a small symbol [circle] at the original + location. Use **+s**\ *size* to set the diameter of the symbol [no symbol]. + Change from circle to any of the standard geometric symbols in :doc:`plot `, + i.e., **a**\|\ **c**\|\ **d**\|\ **g**\|\ **h**\|\ **i**\|\ **n**\|\ **p**\|\ **s**\|\ **t**\|\ **x** [**c**]. + The symbol will be filled with the beachball color, but a fixed color (**+g**\ *fill*) + or no fill (**+g**) can be selected. + The line pen defaults to that given via |-W| but can be overridden + by using **+p**\ *pen* [0.25p]. **Note**: If the cross symbol (**x**) is selected there is no fill since it is + just two stroked lines. Use |-W| to set line thickness and append **+c** to color the crosses as other symbols. + .. _-E: **-E**\ *fill* :ref:`(more ...) <-Gfill_attrib>` diff --git a/doc/rst/source/supplements/seis/meca.rst b/doc/rst/source/supplements/seis/meca.rst index ca101882c3e..1bc100adbda 100644 --- a/doc/rst/source/supplements/seis/meca.rst +++ b/doc/rst/source/supplements/seis/meca.rst @@ -16,7 +16,7 @@ Synopsis |-J|\ *parameters* |SYN_OPT-R| |-S|\ *format*\ [*scale*][**+a**\ *angle*][**+f**\ *font*][**+j**\ *justify*][**+l**][**+m**][**+o**\ *dx*\ [/*dy*]][**+s**\ *reference*] -[ |-A|\ [**+p**\ *pen*][**+s**\ *size*] ] +[ |-A|\ [**+g**\ [*fill*]][**+o**\ *dx*\ [/*dy*]][**+p**\ *pen*][**+s**\ [*symbol*]\ *size*] ] [ |SYN_OPT-B| ] [ |-C|\ *cpt* ] [ |-D|\ *depmin*/*depmax* ] @@ -76,12 +76,18 @@ Optional Arguments .. _-A: -**-A**\ [**+p**\ *pen*][**+s**\ *size*] +**-A**\ [**+g**\ [*fill*]][**+o**\ *dx*\ [/*dy*]][**+p**\ *pen*][**+s**\ [*symbol*]\ *size*] ] Offsets focal mechanisms to the alternate longitudes, latitudes given in the last two columns of the input file before the (optional) text - string. We will draw a line connecting the original and relocated - beachball positions and optionally place a small circle at the original - location. Use **+s**\ *size* to set the diameter of the circle [no circle]. + string. Alternatively, use **+o** to interpret the contents of the two + columns as plot offsets instead, or append fixed offset *dx/dy* for all events. + We will draw a line connecting the original and relocated + beachball positions and optionally place a small symbol [circle] at the original + location. Use **+s**\ *size* to set the size of the symbol [no symbol]. + Change from circle to any of the standard geometric symbols in :doc:`plot `, + i.e., **a**\|\ **c**\|\ **d**\|\ **g**\|\ **h**\|\ **i**\|\ **n**\|\ **p**\|\ **s**\|\ **t**\|\ **x** [**c**]. + The symbol will be filled with the beachball color, but a fixed color (**+g**\ *fill*) + or no fill (**+g**) can be selected. The line pen defaults to that given via |-W| but can be overridden by using **+p**\ *pen* [0.25p]. diff --git a/doc/rst/source/supplements/seis/pscoupe.rst b/doc/rst/source/supplements/seis/pscoupe.rst index 8202299036c..db3d324f526 100644 --- a/doc/rst/source/supplements/seis/pscoupe.rst +++ b/doc/rst/source/supplements/seis/pscoupe.rst @@ -20,6 +20,7 @@ Synopsis |-S|\ *format*\ [*scale*][**+a**\ *angle*][**+f**\ *font*][**+j**\ *justify*][**+l**][**+m**][**+o**\ *dx*\ [/*dy*]][**+s**\ *reference*] [ |SYN_OPT-B| ] [ |-C|\ *cpt* ] +[ |-D|\ [**+c**][**+g**\ [*fill*]][**+o**\ *dx*\ [/*dy*]][**+p**\ *pen*][**+s**\ [*symbol*]\ *size*] ] [ |-E|\ *fill* ] [ |-F|\ *mode*\ [*args*] ] [ |-G|\ *fill* ] diff --git a/doc/rst/source/supplements/seis/psmeca.rst b/doc/rst/source/supplements/seis/psmeca.rst index b7e9b085212..3c96e5578b3 100644 --- a/doc/rst/source/supplements/seis/psmeca.rst +++ b/doc/rst/source/supplements/seis/psmeca.rst @@ -16,7 +16,7 @@ Synopsis |-J|\ *parameters* |SYN_OPT-R| |-S|\ *format*\ [*scale*][**+a**\ *angle*][**+f**\ *font*][**+j**\ *justify*][**+l**][**+m**][**+o**\ *dx*\ [/*dy*]][**+s**\ *reference*] -[ |-A|\ [**+p**\ *pen*][**+s**\ *size*] ] +[ |-A|\ [**+g**\ [*fill*]][**+o**\ *dx*\ [/*dy*]][**+p**\ *pen*][**+s**\ [*symbol*]\ *size*] ] [ |SYN_OPT-B| ] [ |-C|\ *cpt* ] [ |-D|\ *depmin*/*depmax* ] diff --git a/src/gmt_init.c b/src/gmt_init.c index d777476f48f..fc3a38ae2f9 100644 --- a/src/gmt_init.c +++ b/src/gmt_init.c @@ -3571,8 +3571,8 @@ GMT_LOCAL int gmtinit_set_env (struct GMT_CTRL *GMT) { else if (err == 0) { /* Path already exists, check why */ if (!S_ISDIR (S.st_mode)) /* Path already exists, but it is not a directory */ GMT_Report (API, GMT_MSG_ERROR, "A file named %s already exist and prevents us creating a session directory by that name\n", API->session_dir); - else if (S_ISDIR (S.st_mode) && (S.st_mode & S_IWUSR) == 0) /* Directory already exists but is not writeable */ - GMT_Report (API, GMT_MSG_ERROR, "Session directory %s already exist but is not writeable\n", API->session_dir); + else if (S_ISDIR (S.st_mode) && (S.st_mode & S_IWUSR) == 0) /* Directory already exists but is not writable */ + GMT_Report (API, GMT_MSG_ERROR, "Session directory %s already exist but is not writable\n", API->session_dir); } } if (GMT->session.USERDIR) GMT_Report (API, GMT_MSG_DEBUG, "GMT->session.USERDIR = %s [%s]\n", GMT->session.USERDIR, how[u]); diff --git a/src/seis/CMakeLists.txt b/src/seis/CMakeLists.txt index 5076d025bfe..ca37fcd2f97 100644 --- a/src/seis/CMakeLists.txt +++ b/src/seis/CMakeLists.txt @@ -25,7 +25,7 @@ # set (SUPPL_NAME seis) -set (SUPPL_HEADERS meca.h meca_symbol.h utilmeca.h sacio.h) +set (SUPPL_HEADERS meca.h meca_symbol.h utilmeca.h seis_defaults.h sacio.h) AUX_SOURCE_DIRECTORY (longopt SUPPL_LONG_OPT_H) set (SUPPL_PROGS_SRCS psmeca.c pspolar.c pscoupe.c pssac.c ${SUPPL_LONG_OPT_H}) set (SUPPL_LIB_SRCS ${SUPPL_PROGS_SRCS} utilmeca.c sacio.c) diff --git a/src/seis/meca.h b/src/seis/meca.h index 9521059eed9..23b13997316 100644 --- a/src/seis/meca.h +++ b/src/seis/meca.h @@ -27,15 +27,51 @@ #include #include -#define EPSIL 0.0001 +#include "seis_defaults.h" -#define SEIS_MAG_REFERENCE 5.0 /* Reference magnitude for -S */ -#define SEIS_MOMENT_MANT_REFERENCE 4.0 /* Mantissa for reference moment for -S */ -#define SEIS_MOMENT_EXP_REFERENCE 23 /* Exponent for reference moment for -S */ +#define SEIS_EPSILON 0.0001 + +/* Reading mode values for different formats */ +#define SEIS_READ_CMT 0 +#define SEIS_READ_AKI 1 +#define SEIS_READ_PLANES 2 +#define SEIS_READ_AXIS 4 +#define SEIS_READ_TENSOR 8 + +#define SEIS_PLOT_DC 1 +#define SEIS_PLOT_AXIS 2 +#define SEIS_PLOT_TRACE 4 +#define SEIS_PLOT_TENSOR 8 + +#define SEIS_CART_OFFSET 1 /* Cartesian plot offset in optional|trailing text */ +#define SEIS_CART_OFFSET_FIX 2 /* Same, but given as fixed offset with +o on option line */ + +#define SEIS_EVENT_FILL 0 /* Default is to fill optional symbol with event color */ +#define SEIS_FIXED_FILL 1 /* Used fixed color set via +g */ +#define SEIS_NO_FILL 2 /* Skip filling the symbol */ #define squared(x) ((x) * (x)) -struct AXIS { +#define SEIS_LINE_SYNTAX "[+g[]][+o[/]][+p][+s[]]" + +enum Seis_scaletype { + SEIS_READ_SCALE = 0, + SEIS_CONST_SCALE = 1 +}; + +struct SEIS_OFFSET_LINE { + bool active; + bool convert_geo; /* True if coupe -D+c, i.e., given geographical coordinates as alternate location */ + unsigned int mode; /* 0-3 as above */ + unsigned int symbol; /* Default to PSL_CIRCLE */ + unsigned int fill_mode; /* Default to SEIS_EVENT_FILL */ + double size; /* Circle size if drawn */ + double off[2]; /* Cartesian offsets from actual location [0/0] */ + struct GMT_PEN pen; /* Pen parameters controlling the line */ + struct GMT_FILL fill; /* Fill parameters controlling the symbol fill */ +}; + +struct SEIS_AXIS { double str; double dip; double val; @@ -43,29 +79,29 @@ struct AXIS { }; /* val in 10**e dynes-cm */ -struct MOMENT { +struct SEIS_MOMENT { double mant; int exponent; }; -struct nodal_plane { +struct SEIS_NODAL_PLANE { double str; double dip; double rake; }; -struct MECHANISM { - struct nodal_plane NP1; - struct nodal_plane NP2; - struct MOMENT moment; +struct SEIS_MECHANISM { + struct SEIS_NODAL_PLANE NP1; + struct SEIS_NODAL_PLANE NP2; + struct SEIS_MOMENT moment; double magms; }; -struct M_TENSOR { +struct SEIS_M_TENSOR { int expo; double f[6]; }; /* mrr mtt mff mrt mrf mtf in 10**expo dynes-cm */ -typedef struct MOMENT st_mo; -typedef struct MECHANISM st_me; +typedef struct SEIS_MOMENT st_mo; +typedef struct SEIS_MECHANISM st_me; diff --git a/src/seis/pscoupe.c b/src/seis/pscoupe.c index 70b4635ef69..a585e1546bc 100644 --- a/src/seis/pscoupe.c +++ b/src/seis/pscoupe.c @@ -45,21 +45,6 @@ PostScript code is written to stdout. #define THIS_MODULE_NEEDS "JR" #define THIS_MODULE_OPTIONS "-:>BJKOPRUVXYdehipqt" GMT_OPT("c") -#define DEFAULT_FONTSIZE 9.0 /* In points */ -#define DEFAULT_OFFSET 3.0 /* In points */ -#define DEFAULT_SYMBOL_SIZE 6.0 /* In points */ - -#define READ_CMT 0 -#define READ_AKI 1 -#define READ_PLANES 2 -#define READ_AXIS 4 -#define READ_TENSOR 8 - -#define PLOT_DC 1 -#define PLOT_AXIS 2 -#define PLOT_TRACE 4 -#define PLOT_TENSOR 8 - /* Control structure for pscoupe */ struct PSCOUPE_CTRL { @@ -72,13 +57,14 @@ struct PSCOUPE_CTRL { double lon1, lat1, lon2, lat2; double xlonref, ylatref; struct GMT_PEN pen; - struct nodal_plane PREF; + struct SEIS_NODAL_PLANE PREF; char newfile[PATH_MAX], extfile[PATH_MAX]; } A; struct PSCOUPE_C { /* -C */ bool active; char *file; } C; + struct SEIS_OFFSET_LINE D; /* -D[+c][+g[]][+o[[/]]][+p][+s] */ struct PSCOUPE_E { /* -E */ bool active; struct GMT_FILL fill; @@ -174,10 +160,10 @@ static void *New_Ctrl (struct GMT_CTRL *GMT) { /* Allocate and initialize a new gmt_init_fill (GMT, &C->E.fill, 1.0, 1.0, 1.0); gmt_init_fill (GMT, &C->G.fill, 0.0, 0.0, 0.0); C->S.font = GMT->current.setting.font_annot[GMT_PRIMARY]; - C->S.font.size = DEFAULT_FONTSIZE; + C->S.font.size = SEIS_DEFAULT_FONTSIZE; C->S.justify = PSL_TC; C->S.reference = SEIS_MAG_REFERENCE; - C->A2.size = DEFAULT_SYMBOL_SIZE * GMT->session.u2u[GMT_PT][GMT_INCH]; + C->A2.size = SEIS_DEFAULT_SYMBOL_SIZE * GMT->session.u2u[GMT_PT][GMT_INCH]; C->A2.P_symbol = C->A2.T_symbol = PSL_CIRCLE; return (C); } @@ -188,7 +174,7 @@ static void Free_Ctrl (struct GMT_CTRL *GMT, struct PSCOUPE_CTRL *C) { /* Deallo gmt_M_free (GMT, C); } -GMT_LOCAL void pscoupe_rot_axis (struct AXIS A, struct nodal_plane PREF, struct AXIS *Ar) { +GMT_LOCAL void pscoupe_rot_axis (struct SEIS_AXIS A, struct SEIS_NODAL_PLANE PREF, struct SEIS_AXIS *Ar) { /* * Change coordinates of axis from * north,east,down @@ -221,7 +207,7 @@ GMT_LOCAL void pscoupe_rot_axis (struct AXIS A, struct nodal_plane PREF, struct } } -GMT_LOCAL void pscoupe_rot_tensor (struct M_TENSOR mt, struct nodal_plane PREF, struct M_TENSOR *mtr) { +GMT_LOCAL void pscoupe_rot_tensor (struct SEIS_M_TENSOR mt, struct SEIS_NODAL_PLANE PREF, struct SEIS_M_TENSOR *mtr) { /* * * Change coordinates from @@ -257,7 +243,7 @@ GMT_LOCAL void pscoupe_rot_tensor (struct M_TENSOR mt, struct nodal_plane PREF, sa*sd*mt.f[4] - c2a*cd*mt.f[5]; } -GMT_LOCAL void pscoupe_rot_nodal_plane (struct nodal_plane PLAN, struct nodal_plane PREF, struct nodal_plane *PLANR) { +GMT_LOCAL void pscoupe_rot_nodal_plane (struct SEIS_NODAL_PLANE PLAN, struct SEIS_NODAL_PLANE PREF, struct SEIS_NODAL_PLANE *PLANR) { /* Calcule l'azimut, le pendage, le glissement relatifs d'un mecanisme par rapport a un plan de reference PREF @@ -294,7 +280,7 @@ GMT_LOCAL void pscoupe_rot_nodal_plane (struct nodal_plane PLAN, struct nodal_pl } } -GMT_LOCAL void pscoupe_rot_meca (st_me meca, struct nodal_plane PREF, st_me *mecar) { +GMT_LOCAL void pscoupe_rot_meca (st_me meca, struct SEIS_NODAL_PLANE PREF, st_me *mecar) { /* Projection d'un mecanisme sur un plan donne PREF. C'est la demi-sphere derriere le plan qui est representee. @@ -303,7 +289,7 @@ GMT_LOCAL void pscoupe_rot_meca (st_me meca, struct nodal_plane PREF, st_me *mec Genevieve Patau, 7 septembre 1992. */ - if (fabs (meca.NP1.str - PREF.str) < EPSIL && fabs (meca.NP1.dip - PREF.dip) < EPSIL) { + if (fabs (meca.NP1.str - PREF.str) < SEIS_EPSILON && fabs (meca.NP1.dip - PREF.dip) < SEIS_EPSILON) { mecar->NP1.str = 0.; mecar->NP1.dip = 0.; mecar->NP1.rake = meca_zero_360 (270. - meca.NP1.rake); @@ -311,7 +297,7 @@ GMT_LOCAL void pscoupe_rot_meca (st_me meca, struct nodal_plane PREF, st_me *mec else pscoupe_rot_nodal_plane (meca.NP1, PREF, &mecar->NP1); - if (fabs (meca.NP2.str - PREF.str) < EPSIL && fabs (meca.NP2.dip - PREF.dip) < EPSIL) { + if (fabs (meca.NP2.str - PREF.str) < SEIS_EPSILON && fabs (meca.NP2.dip - PREF.dip) < SEIS_EPSILON) { mecar->NP2.str = 0.; mecar->NP2.dip = 0.; mecar->NP2.rake = meca_zero_360 (270. - meca.NP2.rake); @@ -319,7 +305,7 @@ GMT_LOCAL void pscoupe_rot_meca (st_me meca, struct nodal_plane PREF, st_me *mec else pscoupe_rot_nodal_plane (meca.NP2, PREF, &mecar->NP2); - if (cosd (mecar->NP2.dip) < EPSIL && fabs (mecar->NP1.rake - mecar->NP2.rake) < 90.0) { + if (cosd (mecar->NP2.dip) < SEIS_EPSILON && fabs (mecar->NP1.rake - mecar->NP2.rake) < 90.0) { mecar->NP1.str += 180.0; mecar->NP1.rake += 180.0; mecar->NP1.str = meca_zero_360 (mecar->NP1.str); @@ -410,8 +396,8 @@ GMT_LOCAL void pscoupe_distaz (double lat1, double lon1, double lat2, double lon lon1 *= D2R; lat2 *= D2R; lon2 *= D2R; - if ((M_PI_2 - fabs(lat1)) > EPSIL) lat1 = atan(CONSTANTE2 * tan(lat1)); - if ((M_PI_2 - fabs(lat2)) > EPSIL) lat2 = atan(CONSTANTE2 * tan(lat2)); + if ((M_PI_2 - fabs(lat1)) > SEIS_EPSILON) lat1 = atan(CONSTANTE2 * tan(lat1)); + if ((M_PI_2 - fabs(lat2)) > SEIS_EPSILON) lat2 = atan(CONSTANTE2 * tan(lat2)); } sincos (lat1, &slat1, &clat1); sincos (lon1, &slon1, &clon1); @@ -452,17 +438,17 @@ static int usage (struct GMTAPI_CTRL *API, int level) { const char *name = gmt_show_name_and_purpose (API, THIS_MODULE_LIB, THIS_MODULE_CLASSIC_NAME, THIS_MODULE_PURPOSE); if (level == GMT_MODULE_PURPOSE) return (GMT_NOERROR); GMT_Usage (API, 0, "usage: %s [] -Aa|b|c|d[+c[n|t]][+d][+r[a|e|]][+w][+z[s]a|e||/] " - "%s %s -S[][+a][+f][+j][+l][+m][+o[/]][+s] " - "[%s] [-C] [-E] [-Fa[[/[]]]] [-Fe] [-Fg] [-Fr] [-Fp[]] [-Ft[]] " + "%s %s %s -S[][+a][+f][+j][+l][+m][+o[/]][+s] " + "[-C] [-D[+c]%s] [-E] [-Fa[[/[]]]] [-Fe] [-Fg] [-Fr] [-Fp[]] [-Ft[]] " "[-Fs] [-G] [-H[]] [-I[]] %s[-L] [-N] %s%s " "[-Q] [-T[/]] [%s] [%s] [-W] [%s] [%s] %s[%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s]\n", - name, GMT_J_OPT, GMT_Rgeo_OPT, GMT_B_OPT, API->K_OPT, API->O_OPT, API->P_OPT, GMT_U_OPT, GMT_V_OPT, GMT_X_OPT, GMT_Y_OPT, + name, GMT_J_OPT, GMT_Rgeo_OPT, GMT_B_OPT, SEIS_LINE_SYNTAX, API->K_OPT, API->O_OPT, API->P_OPT, GMT_U_OPT, GMT_V_OPT, GMT_X_OPT, GMT_Y_OPT, API->c_OPT, GMT_di_OPT, GMT_e_OPT, GMT_h_OPT, GMT_i_OPT, GMT_p_OPT, GMT_qi_OPT, GMT_tv_OPT, GMT_colon_OPT, GMT_PAR_OPT); if (level == GMT_SYNOPSIS) return (GMT_MODULE_SYNOPSIS); font = API->GMT->current.setting.font_annot[GMT_PRIMARY]; - font.size = DEFAULT_FONTSIZE; + font.size = SEIS_DEFAULT_FONTSIZE; GMT_Message (API, GMT_TIME_NONE, " REQUIRED ARGUMENTS:\n"); GMT_Option (API, "<"); @@ -517,6 +503,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) { GMT_Message (API, GMT_TIME_NONE, "\n OPTIONAL ARGUMENTS:\n"); GMT_Option (API, "B-"); GMT_Usage (API, 1, "\n-C"); + meca_line_usage (API, 'D'); gmt_fill_syntax (API->GMT, 'E', NULL, "Set color used for extensive parts [Default is white]."); GMT_Usage (API, 1, "\n-F (repeatable)"); GMT_Usage (API, -2, "Set various attributes of symbols depending on directive:"); @@ -732,6 +719,11 @@ static int parse (struct GMT_CTRL *GMT, struct PSCOUPE_CTRL *Ctrl, struct GMT_OP if (opt->arg[0]) Ctrl->C.file = strdup (opt->arg); break; + case 'D': /* Offset symbol from actual location and optionally draw line between these points */ + n_errors += gmt_M_repeated_module_option (API, Ctrl->D.active); + n_errors += meca_line_parse (GMT, &(Ctrl->D), 'D', opt->arg); + break; + case 'E': /* Set color for extensive parts */ n_errors += gmt_M_repeated_module_option (API, Ctrl->E.active); if (!opt->arg[0] || (opt->arg[0] && gmt_getfill (GMT, opt->arg, &Ctrl->E.fill))) { @@ -812,13 +804,13 @@ static int parse (struct GMT_CTRL *GMT, struct PSCOUPE_CTRL *Ctrl, struct GMT_OP if (gmt_get_pair (GMT, word, GMT_PAIR_DIM_DUP, Ctrl->S.offset) < 0) n_errors++; } else { /* Set default offset */ if (Ctrl->S.justify%4 != 2) /* Not center aligned */ - Ctrl->S.offset[0] = DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; + Ctrl->S.offset[0] = SEIS_DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; if (Ctrl->S.justify/4 != 1) /* Not middle aligned */ - Ctrl->S.offset[1] = DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; + Ctrl->S.offset[1] = SEIS_DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; } if (Ctrl->S.font.size <= 0.0) Ctrl->S.no_label = true; } else { /* Old syntax: -Fs[[/fontsize[/offset[+u]]]] */ - Ctrl->S.offset[1] = DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; /* Set default offset */ + Ctrl->S.offset[1] = SEIS_DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; /* Set default offset */ if ((p = strstr (opt->arg, "+u"))) { /* Plot label under symbol [over] */ Ctrl->S.justify = PSL_BC; p[0] = '\0'; /* Chop off modifier */ @@ -895,42 +887,42 @@ static int parse (struct GMT_CTRL *GMT, struct PSCOUPE_CTRL *Ctrl, struct GMT_OP n_errors += gmt_M_repeated_module_option (API, Ctrl->S.active); switch (opt->arg[0]) { /* parse format */ case 'c': - Ctrl->S.readmode = READ_CMT; Ctrl->S.n_cols = 11; - Ctrl->S.plotmode = PLOT_DC; + Ctrl->S.readmode = SEIS_READ_CMT; Ctrl->S.n_cols = 11; + Ctrl->S.plotmode = SEIS_PLOT_DC; break; case 'a': - Ctrl->S.readmode = READ_AKI; Ctrl->S.n_cols = 7; - Ctrl->S.plotmode = PLOT_DC; + Ctrl->S.readmode = SEIS_READ_AKI; Ctrl->S.n_cols = 7; + Ctrl->S.plotmode = SEIS_PLOT_DC; break; case 'p': - Ctrl->S.readmode = READ_PLANES; Ctrl->S.n_cols = 8; - Ctrl->S.plotmode = PLOT_DC; + Ctrl->S.readmode = SEIS_READ_PLANES; Ctrl->S.n_cols = 8; + Ctrl->S.plotmode = SEIS_PLOT_DC; break; case 'x': - Ctrl->S.readmode = READ_AXIS; Ctrl->S.n_cols = 13; - Ctrl->S.plotmode = PLOT_TENSOR; + Ctrl->S.readmode = SEIS_READ_AXIS; Ctrl->S.n_cols = 13; + Ctrl->S.plotmode = SEIS_PLOT_TENSOR; break; case 'y': - Ctrl->S.readmode = READ_AXIS; Ctrl->S.n_cols = 13; - Ctrl->S.plotmode = PLOT_DC; + Ctrl->S.readmode = SEIS_READ_AXIS; Ctrl->S.n_cols = 13; + Ctrl->S.plotmode = SEIS_PLOT_DC; break; case 't': - Ctrl->S.readmode = READ_AXIS; Ctrl->S.n_cols = 13; - Ctrl->S.plotmode = PLOT_TRACE; + Ctrl->S.readmode = SEIS_READ_AXIS; Ctrl->S.n_cols = 13; + Ctrl->S.plotmode = SEIS_PLOT_TRACE; break; case 'm': - Ctrl->S.readmode = READ_TENSOR; Ctrl->S.n_cols = 10; - Ctrl->S.plotmode = PLOT_TENSOR; + Ctrl->S.readmode = SEIS_READ_TENSOR; Ctrl->S.n_cols = 10; + Ctrl->S.plotmode = SEIS_PLOT_TENSOR; Ctrl->S.zerotrace = true; break; case 'd': - Ctrl->S.readmode = READ_TENSOR; Ctrl->S.n_cols = 10; - Ctrl->S.plotmode = PLOT_DC; + Ctrl->S.readmode = SEIS_READ_TENSOR; Ctrl->S.n_cols = 10; + Ctrl->S.plotmode = SEIS_PLOT_DC; Ctrl->S.zerotrace = true; break; case 'z': - Ctrl->S.readmode = READ_TENSOR; Ctrl->S.n_cols = 10; - Ctrl->S.plotmode = PLOT_TRACE; + Ctrl->S.readmode = SEIS_READ_TENSOR; Ctrl->S.n_cols = 10; + Ctrl->S.plotmode = SEIS_PLOT_TRACE; Ctrl->S.zerotrace = true; break; default: @@ -961,9 +953,9 @@ static int parse (struct GMT_CTRL *GMT, struct PSCOUPE_CTRL *Ctrl, struct GMT_OP if (gmt_get_pair (GMT, word, GMT_PAIR_DIM_DUP, Ctrl->S.offset) < 0) n_errors++; } else { /* Set default offset */ if (Ctrl->S.justify%4 != 2) /* Not center aligned */ - Ctrl->S.offset[0] = DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; + Ctrl->S.offset[0] = SEIS_DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; if (Ctrl->S.justify/4 != 1) /* Not middle aligned */ - Ctrl->S.offset[1] = DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; + Ctrl->S.offset[1] = SEIS_DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; } if (Ctrl->S.font.size <= 0.0) Ctrl->S.no_label = true; if (gmt_get_modifier (opt->arg, 'l', word)) { @@ -975,7 +967,7 @@ static int parse (struct GMT_CTRL *GMT, struct PSCOUPE_CTRL *Ctrl, struct GMT_OP if (gmt_get_modifier (opt->arg, 's', word)) Ctrl->S.reference = atof (word); } else { /* Old syntax: -S[/fontsize[/offset]][+u] */ - Ctrl->S.offset[1] = DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; /* Set default offset */ + Ctrl->S.offset[1] = SEIS_DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; /* Set default offset */ if ((p = strstr (opt->arg, "+u"))) { /* Plot label under symbol [over] */ Ctrl->S.justify = PSL_BC; p[0] = '\0'; /* Chop off modifier */ @@ -1058,15 +1050,15 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) { FILE *pnew = NULL, *pext = NULL; double size, xy[2], xynew[2] = {0.0}, plot_x, plot_y, n_dep, distance, fault, depth; - double scale, P_x, P_y, T_x, T_y, in[GMT_LEN16]; + double scale, P_x, P_y, T_x, T_y, plot_xnew, plot_ynew, in[GMT_LEN16]; char event_title[GMT_BUFSIZ] = {""}, Xstring[GMT_BUFSIZ] = {""}, Ystring[GMT_BUFSIZ] = {""}; char *no_name = "", *event_name = NULL; st_me meca, mecar; - struct MOMENT moment; - struct M_TENSOR mt, mtr; - struct AXIS T, N, P, Tr, Nr, Pr; + struct SEIS_MOMENT moment; + struct SEIS_M_TENSOR mt, mtr; + struct SEIS_AXIS T, N, P, Tr, Nr, Pr; struct GMT_PALETTE *CPT = NULL; struct GMT_PEN current_pen; struct GMT_DATASET *D = NULL; /* Pointer to GMT multisegment input tables */ @@ -1302,7 +1294,11 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) { n_scanned = sscanf (tmp_buffer, "%s %s %[^\n]s\n", Xstring, Ystring, event_title); if (n_scanned >= 2) { /* Got new x,y coordinates and possibly event title */ unsigned int type; - if (GMT->current.setting.io_lonlat_toggle[GMT_IN]) { /* Expect lat lon but watch for junk */ + if (Ctrl->D.mode == SEIS_CART_OFFSET) { /* Cartesian dx and dy in plot units */ + Ctrl->D.off[GMT_X] = gmt_M_to_inch (GMT, Xstring); + Ctrl->D.off[GMT_Y] = gmt_M_to_inch (GMT, Ystring); + } + else if (GMT->current.setting.io_lonlat_toggle[GMT_IN]) { /* Expect lat lon but watch for junk */ if ((type = gmt_scanf_arg (GMT, Ystring, GMT_IS_LON, false, &xynew[GMT_X])) == GMT_IS_NAN) xynew[GMT_X] = GMT->session.d_NaN; if ((type = gmt_scanf_arg (GMT, Xstring, GMT_IS_LAT, false, &xynew[GMT_Y])) == GMT_IS_NAN) xynew[GMT_Y] = GMT->session.d_NaN; } @@ -1366,6 +1362,52 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) { gmt_geo_to_xy (GMT, xy[GMT_X], xy[GMT_Y], &plot_x, &plot_y); + /* If option -D is used, use the alternate position */ + + if (Ctrl->D.active) { + if (Ctrl->D.mode || fabs (xynew[GMT_X]) > SEIS_EPSILON || fabs (xynew[GMT_Y]) > SEIS_EPSILON) { + current_pen = Ctrl->D.pen; + if (Ctrl->H.active) { + double scl = (Ctrl->H.mode == SEIS_READ_SCALE) ? in[xcol] : Ctrl->H.value; + gmt_scale_pen (GMT, ¤t_pen, scl); + } + gmt_setpen (GMT, ¤t_pen); + if (Ctrl->D.convert_geo) { /* Alternate location given as lon lat, must project into our plane (and using epicenter depth) */ + double distance_a, n_dep_a; + if (!pscoupe_dans_coupe (xynew[GMT_X], xynew[GMT_Y], depth, Ctrl->A.xlonref, Ctrl->A.ylatref, Ctrl->A.fuseau, Ctrl->A.PREF.str, + Ctrl->A.PREF.dip, Ctrl->A.p_length, Ctrl->A.p_width, &distance_a, &n_dep_a)) + continue; + gmt_geo_to_xy (GMT, xy[GMT_X], xy[GMT_Y], &plot_xnew, &plot_ynew); /* Now in inches */ + if (Ctrl->D.mode) { /* Adjust Cartesian dx and dy in plot units */ + plot_xnew += Ctrl->D.off[GMT_X]; + plot_ynew += Ctrl->D.off[GMT_Y]; + } + } + else if (Ctrl->D.mode) { /* Alternative location given as offsets relative to projected original point */ + /* Got fixed or variable Cartesian dx and dy in plot units */ + plot_xnew = plot_x + Ctrl->D.off[GMT_X]; + plot_ynew = plot_y + Ctrl->D.off[GMT_Y]; + } + else /* Got alternate distance,depth coordinates */ + gmt_geo_to_xy (GMT, xynew[GMT_X], xynew[GMT_Y], &plot_xnew, &plot_ynew); + + if (Ctrl->D.fill_mode == SEIS_EVENT_FILL) + gmt_setfill (GMT, &Ctrl->G.fill, 1); + else if (Ctrl->D.fill_mode == SEIS_FIXED_FILL) + gmt_setfill (GMT, &Ctrl->D.fill, 1); + else /* SEIS_NO_FILL */ + gmt_setfill (GMT, NULL, 1); + if (Ctrl->D.size > 0.0) /* Plot symbol at actual location */ + PSL_plotsymbol (PSL, plot_x, plot_y, &(Ctrl->D.size), Ctrl->D.symbol); + + /* Draw line between original and alternate location */ + PSL_plotsegment (PSL, plot_x, plot_y, plot_xnew, plot_ynew); + /* Since we will plot beach ball at the alternative location, we swap them */ + plot_x = plot_xnew; + plot_y = plot_ynew; + } + } + if (Ctrl->S.symbol) { if (!Ctrl->Q.active) { fprintf (pnew, "%f %f %f %f\n", distance, n_dep, depth, in[3]); @@ -1374,7 +1416,7 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) { gmt_setfill (GMT, &Ctrl->G.fill, Ctrl->L.active); PSL_plotsymbol (PSL, plot_x, plot_y, &size, Ctrl->S.symbol); } - else if (Ctrl->S.readmode == READ_CMT) { + else if (Ctrl->S.readmode == SEIS_READ_CMT) { meca.NP1.str = in[3]; meca.NP1.dip = in[4]; meca.NP1.rake = in[5]; @@ -1386,7 +1428,7 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) { if (moment.exponent == 0) meca.magms = in[9]; pscoupe_rot_meca (meca, Ctrl->A.PREF, &mecar); } - else if (Ctrl->S.readmode == READ_AKI) { + else if (Ctrl->S.readmode == SEIS_READ_AKI) { meca.NP1.str = in[3]; meca.NP1.dip = in[4]; meca.NP1.rake = in[5]; @@ -1396,7 +1438,7 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) { meca_define_second_plane (meca.NP1, &meca.NP2); pscoupe_rot_meca (meca, Ctrl->A.PREF, &mecar); } - else if (Ctrl->S.readmode == READ_PLANES) { + else if (Ctrl->S.readmode == SEIS_READ_PLANES) { meca.NP1.str = in[3]; meca.NP1.dip = in[4]; meca.NP2.str = in[5]; @@ -1421,7 +1463,7 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) { pscoupe_rot_meca (meca, Ctrl->A.PREF, &mecar); } - else if (Ctrl->S.readmode == READ_AXIS) { + else if (Ctrl->S.readmode == SEIS_READ_AXIS) { T.val = in[3]; T.str = in[4]; T.dip = in[5]; @@ -1460,9 +1502,9 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) { Nr.e = N.e; Pr.e = P.e; - if (Ctrl->S.plotmode == PLOT_DC || Ctrl->T.active) meca_axe2dc (Tr, Pr, &meca.NP1, &meca.NP2); + if (Ctrl->S.plotmode == SEIS_PLOT_DC || Ctrl->T.active) meca_axe2dc (Tr, Pr, &meca.NP1, &meca.NP2); } - else if (Ctrl->S.readmode == READ_TENSOR) { + else if (Ctrl->S.readmode == SEIS_READ_TENSOR) { for (i = 3; i < 9; i++) mt.f[i-3] = in[i]; mt.expo = irint (in[i]); @@ -1480,7 +1522,7 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) { pscoupe_rot_tensor (mt, Ctrl->A.PREF, &mtr); meca_moment2axe (GMT, mtr, &T, &N, &P); - if (Ctrl->S.plotmode == PLOT_DC || Ctrl->T.active) meca_axe2dc (T, P, &meca.NP1, &meca.NP2); + if (Ctrl->S.plotmode == SEIS_PLOT_DC || Ctrl->T.active) meca_axe2dc (T, P, &meca.NP1, &meca.NP2); } if (!Ctrl->S.symbol) { @@ -1497,7 +1539,7 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) { } if (!Ctrl->Q.active) fprintf (pext, "%s\n", S->text ? S->text[row] : ""); - if (Ctrl->S.readmode == READ_AXIS) { + if (Ctrl->S.readmode == SEIS_READ_AXIS) { if (!Ctrl->Q.active) fprintf (pnew, "%f %f %f %f %f %f %f %f %f %f %f %f %d 0 0 %s\n", xy[0], xy[1], depth, Tr.val, Tr.str, Tr.dip, Nr.val, Nr.str, Nr.dip, @@ -1506,7 +1548,7 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) { N = Nr; P = Pr; } - else if (Ctrl->S.readmode == READ_TENSOR) { + else if (Ctrl->S.readmode == SEIS_READ_TENSOR) { if (!Ctrl->Q.active) fprintf (pnew, "%f %f %f %f %f %f %f %f %f %d 0 0 %s\n", xy[0], xy[1], depth, mtr.f[0], mtr.f[1], mtr.f[2], mtr.f[3], mtr.f[4], mtr.f[5], @@ -1522,7 +1564,7 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) { meca = mecar; } - if (Ctrl->S.plotmode == PLOT_TENSOR) { + if (Ctrl->S.plotmode == SEIS_PLOT_TENSOR) { current_pen = Ctrl->L.pen; if (Ctrl->H.active) { double scl = (Ctrl->H.mode == PSCOUPE_READ_SCALE) ? in[xcol] : Ctrl->H.value; @@ -1556,7 +1598,7 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) { Ctrl->T.n_plane = n_plane_old; } } - else if (Ctrl->S.plotmode == PLOT_DC) { + else if (Ctrl->S.plotmode == SEIS_PLOT_DC) { current_pen = Ctrl->L.pen; if (Ctrl->H.active) { double scl = (Ctrl->H.mode == PSCOUPE_READ_SCALE) ? in[xcol] : Ctrl->H.value; @@ -1569,7 +1611,7 @@ EXTERN_MSC int GMT_pscoupe (void *V_API, int mode, void *args) { if (Ctrl->A2.active) { /* Plot axis symbols */ double scl = (Ctrl->H.mode == PSCOUPE_READ_SCALE) ? in[xcol] : Ctrl->H.value; double asize = (Ctrl->H.active) ? Ctrl->A2.size * scl : Ctrl->A2.size; - if (Ctrl->S.readmode != READ_TENSOR && Ctrl->S.readmode != READ_AXIS) meca_dc2axe (meca, &T, &N, &P); + if (Ctrl->S.readmode != SEIS_READ_TENSOR && Ctrl->S.readmode != SEIS_READ_AXIS) meca_dc2axe (meca, &T, &N, &P); meca_axis2xy (plot_x, plot_y, size, P.str, P.dip, T.str, T.dip, &P_x, &P_y, &T_x, &T_y); current_pen = Ctrl->P2.pen; if (Ctrl->H.active) diff --git a/src/seis/psmeca.c b/src/seis/psmeca.c index cd30f824362..1a8f381b46a 100644 --- a/src/seis/psmeca.c +++ b/src/seis/psmeca.c @@ -44,27 +44,9 @@ PostScript code is written to stdout. #define THIS_MODULE_NEEDS "Jd" #define THIS_MODULE_OPTIONS "-:>BJKOPRUVXYdehipqt" GMT_OPT("c") -#define DEFAULT_FONTSIZE 9.0 /* In points */ -#define DEFAULT_OFFSET 3.0 /* In points */ -#define DEFAULT_SYMBOL_SIZE 6.0 /* In points */ - -#define READ_CMT 0 -#define READ_AKI 1 -#define READ_PLANES 2 -#define READ_AXIS 4 -#define READ_TENSOR 8 - -#define PLOT_DC 1 -#define PLOT_AXIS 2 -#define PLOT_TRACE 4 - /* Control structure for psmeca */ struct PSMECA_CTRL { - struct PSMECA_A { /* -A[+p][+s] */ - bool active; - double size; - struct GMT_PEN pen; - } A; + struct SEIS_OFFSET_LINE A; /* -A[+g][+o[[/]]][+p][+s] */ struct PSMECA_C { /* -C */ bool active; char *file; @@ -147,10 +129,6 @@ struct PSMECA_CTRL { } Z2; }; -enum Psmeca_scaletype { - PSMECA_READ_SCALE = 0, - PSMECA_CONST_SCALE = 1}; - static void *New_Ctrl (struct GMT_CTRL *GMT) { /* Allocate and initialize a new control structure */ struct PSMECA_CTRL *C; @@ -169,10 +147,10 @@ static void *New_Ctrl (struct GMT_CTRL *GMT) { /* Allocate and initialize a new gmt_init_fill (GMT, &C->G.fill, 0.0, 0.0, 0.0); gmt_init_fill (GMT, &C->R2.fill, 1.0, 1.0, 1.0); C->S.font = GMT->current.setting.font_annot[GMT_PRIMARY]; - C->S.font.size = DEFAULT_FONTSIZE; + C->S.font.size = SEIS_DEFAULT_FONTSIZE; C->S.justify = PSL_TC; C->S.reference = SEIS_MAG_REFERENCE; - C->A2.size = DEFAULT_SYMBOL_SIZE * GMT->session.u2u[GMT_PT][GMT_INCH]; + C->A2.size = SEIS_DEFAULT_SYMBOL_SIZE * GMT->session.u2u[GMT_PT][GMT_INCH]; C->A2.P_symbol = C->A2.T_symbol = PSL_CIRCLE; return (C); } @@ -190,17 +168,17 @@ static int usage (struct GMTAPI_CTRL *API, int level) { const char *name = gmt_show_name_and_purpose (API, THIS_MODULE_LIB, THIS_MODULE_CLASSIC_NAME, THIS_MODULE_PURPOSE); if (level == GMT_MODULE_PURPOSE) return (GMT_NOERROR); GMT_Usage (API, 0, "usage: %s [
] %s %s " - "-S[][+a][+f][+j][+l][+m][+o[/]][+s] [-A[+p][+s]] [%s] " + "-S[][+a][+f][+j][+l][+m][+o[/]][+s] [-A%s] [%s] " "[-C] [-D/] [-E] [-Fa[[/[]]]] [-Fe] [-Fg] " "[-Fr] [-Fp[]] [-Ft[]] [-Fz[]] [-G] [-H[]] [-I[]] %s[-L] " "[-N] %s%s[-T[/]] [%s] [%s] [-W] [%s] [%s] %s[%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s]\n", - name, GMT_J_OPT, GMT_Rgeo_OPT, GMT_B_OPT, API->K_OPT, API->O_OPT, API->P_OPT, GMT_U_OPT, GMT_V_OPT, GMT_X_OPT, + name, GMT_J_OPT, GMT_Rgeo_OPT, SEIS_LINE_SYNTAX, GMT_B_OPT, API->K_OPT, API->O_OPT, API->P_OPT, GMT_U_OPT, GMT_V_OPT, GMT_X_OPT, GMT_Y_OPT, API->c_OPT, GMT_di_OPT, GMT_e_OPT, GMT_h_OPT, GMT_i_OPT, GMT_p_OPT, GMT_qi_OPT, GMT_tv_OPT, GMT_colon_OPT, GMT_PAR_OPT); if (level == GMT_SYNOPSIS) return (GMT_MODULE_SYNOPSIS); font = API->GMT->current.setting.font_annot[GMT_PRIMARY]; - font.size = DEFAULT_FONTSIZE; + font.size = SEIS_DEFAULT_FONTSIZE; GMT_Message (API, GMT_TIME_NONE, " REQUIRED ARGUMENTS:\n"); GMT_Option (API, "<"); @@ -237,11 +215,8 @@ static int usage (struct GMTAPI_CTRL *API, int level) { GMT_Usage (API, 3, "+s Set reference magnitude [%g] or moment [%ge%d] (if +l) for symbol size.", SEIS_MAG_REFERENCE, SEIS_MOMENT_MANT_REFERENCE, SEIS_MOMENT_EXP_REFERENCE); GMT_Usage (API, -2, "Note: If fontsize < 0 then no label written; offset is from the limit of the beach ball."); GMT_Message (API, GMT_TIME_NONE, "\n OPTIONAL ARGUMENTS:\n"); + meca_line_usage (API, 'A'); GMT_Option (API, "B-"); - GMT_Usage (API, 1, "\n-A[+p][+s]"); - GMT_Usage (API, -2, "Offset focal mechanisms to the alternate positions given in the last two columns of the input file before label. " - "A line is drawn between both positions; see -W for pen used or specify it separately via +p [0.25p]. " - "Optionally, a small circle is plotted at the original location. Append +s to set its diameter [no circle]."); GMT_Usage (API, 1, "\n-C"); GMT_Usage (API, -2, "Use CPT to assign colors based on depth-value in 3rd column."); GMT_Usage (API, 1, "\n-D/"); @@ -292,62 +267,6 @@ GMT_LOCAL bool psmeca_is_old_C_option (struct GMT_CTRL *GMT, char *arg) { return false; /* This assumes nobody would use just -C in modern mode but actually mean the old -C */ } -GMT_LOCAL unsigned int psmeca_A_parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, char *arg) { - unsigned int n_errors = 0; - char txt[GMT_LEN256] = {""}, *c = NULL, *q = NULL; - strncpy (txt, arg, GMT_LEN256-1); - - /* Deal with these possible variations of old -C and new -A options: - * 1. -A[+p][+s] which is the current syntax - * 2. -C[][+s] which was the GMT5-6.1.1 syntax - * 3. -C[][P] which was the GMT4 syntax */ - - if ((c = gmt_first_modifier (GMT, txt, "ps"))) { /* Found at least one valid modifier */ - unsigned int pos = 0; - char p[GMT_LEN256] = {""}; - while (gmt_getmodopt (GMT, 'A', c, "ps", &pos, p, &n_errors) && n_errors == 0) { - switch (p[0]) { - case 'p': /* Line and circle pen */ - if (p[1] == '\0' || gmt_getpen (GMT, &p[1], &Ctrl->A.pen)) { - gmt_pen_syntax (GMT, 'A', NULL, " ", NULL, 0); - n_errors++; - } - break; - case 's': /* Circle diameter */ - if (p[1] == '\0' || (Ctrl->A.size = gmt_M_to_inch (GMT, &p[1])) < 0.0) { - GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -A: Circle diameter cannot be negative or not given!\n"); - n_errors++; - } - break; - default: break; /* These are caught in gmt_getmodopt so break is just for Coverity */ - } - } - c[0] = '\0'; /* Chop off the modifiers */ - } - /* If the user used modern modifiers only as case 1 above then we might be done here */ - if (arg[0] == '\0') return n_errors; - - /* Here we got older syntax: -C[+s] or -C[][P] (but the +s would have been stripped off - * so here we must either have -C or -C[][P] */ - - if ((q = strchr (txt, 'P')) != NULL) { /* Case 3 way of changing the diameter */ - if (q[1] == '\0' || (Ctrl->A.size = gmt_M_to_inch (GMT, &q[1])) < 0.0) { - GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -A: Circle diameter cannot be negative or not given!\n"); - n_errors++; - } - q[0] = '\0'; /* Chop off the Psize setting; if txt is not empty we also have an optional pen */ - if (arg[0] && gmt_getpen (GMT, txt, &Ctrl->A.pen)) { - gmt_pen_syntax (GMT, 'A', NULL, " ", NULL, 0); - n_errors++; - } - } - else if (gmt_getpen (GMT, txt, &Ctrl->A.pen)) { /* Here we just have -C to deal with */ - gmt_pen_syntax (GMT, 'A', NULL, " ", NULL, 0); - n_errors++; - } - return n_errors; -} - static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPTION *options) { /* This parses the options provided to psmeca and sets parameters in Ctrl. * Note Ctrl has already been initialized and non-zero default values set. @@ -371,15 +290,15 @@ static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPT /* Processes program-specific parameters */ - case 'A': + case 'A': /* Offset symbol from actual location and optionally draw line between these points */ n_errors += gmt_M_repeated_module_option (API, Ctrl->A.active); - n_errors += psmeca_A_parse (GMT, Ctrl, opt->arg); + n_errors += meca_line_parse (GMT, &(Ctrl->A), 'A', opt->arg); break; case 'C': /* Either modern -Ccpt option or a deprecated -C now served by -A */ /* Change position [set line attributes] */ if (psmeca_is_old_C_option (GMT, opt->arg)) { /* Need the -A parser for obsolete -C syntax */ Ctrl->A.active = true; - n_errors += psmeca_A_parse (GMT, Ctrl, opt->arg); + n_errors += meca_line_parse (GMT, &(Ctrl->A), 'A', opt->arg); } else { /* Here we have the modern -C parsing */ n_errors += gmt_M_repeated_module_option (API, Ctrl->C.active); @@ -475,7 +394,7 @@ static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPT n_errors += gmt_M_repeated_module_option (API, Ctrl->H.active); if (opt->arg[0]) { /* Gave a fixed scale - no reading from file */ Ctrl->H.value = atof (opt->arg); - Ctrl->H.mode = PSMECA_CONST_SCALE; + Ctrl->H.mode = SEIS_CONST_SCALE; } break; case 'I': /* Adjust symbol color via intensity */ @@ -508,35 +427,35 @@ static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPT n_errors += gmt_M_repeated_module_option (API, Ctrl->S.active); switch (opt->arg[0]) { /* parse format */ case 'c': - Ctrl->S.readmode = READ_CMT; Ctrl->S.n_cols = 11; + Ctrl->S.readmode = SEIS_READ_CMT; Ctrl->S.n_cols = 11; break; case 'a': - Ctrl->S.readmode = READ_AKI; Ctrl->S.n_cols = 7; + Ctrl->S.readmode = SEIS_READ_AKI; Ctrl->S.n_cols = 7; break; case 'p': - Ctrl->S.readmode = READ_PLANES; Ctrl->S.n_cols = 8; + Ctrl->S.readmode = SEIS_READ_PLANES; Ctrl->S.n_cols = 8; break; case 'x': - Ctrl->S.readmode = READ_AXIS; Ctrl->S.n_cols = 13; + Ctrl->S.readmode = SEIS_READ_AXIS; Ctrl->S.n_cols = 13; break; case 'y': - Ctrl->S.readmode = READ_AXIS; Ctrl->S.n_cols = 13; - Ctrl->S.plotmode = PLOT_DC; + Ctrl->S.readmode = SEIS_READ_AXIS; Ctrl->S.n_cols = 13; + Ctrl->S.plotmode = SEIS_PLOT_DC; break; case 't': - Ctrl->S.readmode = READ_AXIS; Ctrl->S.n_cols = 13; - Ctrl->S.plotmode = PLOT_TRACE; + Ctrl->S.readmode = SEIS_READ_AXIS; Ctrl->S.n_cols = 13; + Ctrl->S.plotmode = SEIS_PLOT_TRACE; break; case 'm': - Ctrl->S.readmode = READ_TENSOR; Ctrl->S.n_cols = 10; + Ctrl->S.readmode = SEIS_READ_TENSOR; Ctrl->S.n_cols = 10; break; case 'd': - Ctrl->S.readmode = READ_TENSOR; Ctrl->S.n_cols = 10; - Ctrl->S.plotmode = PLOT_DC; + Ctrl->S.readmode = SEIS_READ_TENSOR; Ctrl->S.n_cols = 10; + Ctrl->S.plotmode = SEIS_PLOT_DC; break; case 'z': - Ctrl->S.readmode = READ_TENSOR; Ctrl->S.n_cols = 10; - Ctrl->S.plotmode = PLOT_TRACE; + Ctrl->S.readmode = SEIS_READ_TENSOR; Ctrl->S.n_cols = 10; + Ctrl->S.plotmode = SEIS_PLOT_TRACE; break; default: n_errors++; @@ -566,9 +485,9 @@ static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPT if (gmt_get_pair (GMT, word, GMT_PAIR_DIM_DUP, Ctrl->S.offset) < 0) n_errors++; } else { /* Set default offset */ if (Ctrl->S.justify%4 != 2) /* Not center aligned */ - Ctrl->S.offset[0] = DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; + Ctrl->S.offset[0] = SEIS_DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; if (Ctrl->S.justify/4 != 1) /* Not middle aligned */ - Ctrl->S.offset[1] = DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; + Ctrl->S.offset[1] = SEIS_DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; } if (gmt_get_modifier (opt->arg, 'l', word)) { Ctrl->S.linear = true; @@ -579,7 +498,7 @@ static int parse (struct GMT_CTRL *GMT, struct PSMECA_CTRL *Ctrl, struct GMT_OPT if (gmt_get_modifier (opt->arg, 's', word)) Ctrl->S.reference = atof (word); } else { /* Old syntax: -S[/fontsize[/offset]][+u] */ - Ctrl->S.offset[1] = DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; /* Set default offset */ + Ctrl->S.offset[1] = SEIS_DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; /* Set default offset */ if ((p = strstr (opt->arg, "+u"))) { Ctrl->S.justify = PSL_BC; p[0] = '\0'; /* Chop off modifier */ @@ -675,9 +594,9 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { char *no_name = "", *event_name = NULL; st_me meca; - struct MOMENT moment; - struct M_TENSOR mt; - struct AXIS T, N, P; + struct SEIS_MOMENT moment; + struct SEIS_M_TENSOR mt; + struct SEIS_AXIS T, N, P; struct GMT_PALETTE *CPT = NULL; struct GMT_DATASET *D = NULL; /* Pointer to GMT multisegment input tables */ @@ -708,9 +627,9 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { gmt_M_memset (event_title, GMT_BUFSIZ, char); gmt_M_memset (&meca, 1, st_me); - gmt_M_memset (&T, 1, struct AXIS); - gmt_M_memset (&N, 1, struct AXIS); - gmt_M_memset (&P, 1, struct AXIS); + gmt_M_memset (&T, 1, struct SEIS_AXIS); + gmt_M_memset (&N, 1, struct SEIS_AXIS); + gmt_M_memset (&P, 1, struct SEIS_AXIS); gmt_M_memset (in, GMT_LEN16, double); if (Ctrl->C.active) { @@ -742,7 +661,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { } else /* Fixed scale */ scale = Ctrl->S.scale; - if (Ctrl->H.active && Ctrl->H.mode == PSMECA_READ_SCALE) { + if (Ctrl->H.active && Ctrl->H.mode == SEIS_READ_SCALE) { xcol = Ctrl->S.n_cols; Ctrl->S.n_cols++; /* Read scaling from data file */ gmt_set_column_type (GMT, GMT_IN, xcol, GMT_IS_FLOAT); @@ -838,12 +757,16 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { unsigned int n_comma = gmt_count_char (GMT, S->text[row], ','); char tmp_buffer[GMT_LEN256] = {""}; /* Local buffer in case S->text is read-only */ strncpy (tmp_buffer, S->text[row], GMT_LEN256); - if (n_comma == 2) /* CSV file so we must handle that */ + if (n_comma == 2) /* CSV file so we must handle that first */ gmt_strrepc (tmp_buffer, ',', ' '); n_scanned = sscanf (tmp_buffer, "%s %s %[^\n]s\n", Xstring, Ystring, event_title); if (n_scanned >= 2) { /* Got new x,y coordinates and possibly event title */ unsigned int type; - if (GMT->current.setting.io_lonlat_toggle[GMT_IN]) { /* Expect lat lon but watch for junk */ + if (Ctrl->A.mode == SEIS_CART_OFFSET) { /* Cartesian dx and dy in plot units */ + Ctrl->A.off[GMT_X] = gmt_M_to_inch (GMT, Xstring); + Ctrl->A.off[GMT_Y] = gmt_M_to_inch (GMT, Ystring); + } + else if (GMT->current.setting.io_lonlat_toggle[GMT_IN]) { /* Expect lat lon but watch for junk */ if ((type = gmt_scanf_arg (GMT, Ystring, GMT_IS_LON, false, &xynew[GMT_X])) == GMT_IS_NAN) xynew[GMT_X] = GMT->session.d_NaN; if ((type = gmt_scanf_arg (GMT, Xstring, GMT_IS_LAT, false, &xynew[GMT_Y])) == GMT_IS_NAN) xynew[GMT_Y] = GMT->session.d_NaN; } @@ -879,7 +802,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { } /* Gather and transform the input records, depending on type */ - if (Ctrl->S.readmode == READ_CMT) { + if (Ctrl->S.readmode == SEIS_READ_CMT) { meca.NP1.str = in[2+new_fmt]; if (meca.NP1.str > 180.0) meca.NP1.str -= 360.0; else if (meca.NP1.str < -180.0) meca.NP1.str += 360.0; /* Strike must be in -180/+180 range*/ @@ -898,7 +821,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { meca.moment.exponent = irint (in[9+new_fmt]); if (meca.moment.exponent == 0) meca.magms = in[8+new_fmt]; } - else if (Ctrl->S.readmode == READ_AKI) { + else if (Ctrl->S.readmode == SEIS_READ_AKI) { meca.NP1.str = in[2+new_fmt]; if (meca.NP1.str > 180.0) meca.NP1.str -= 360.0; else if (meca.NP1.str < -180.0) meca.NP1.str += 360.0; /* Strike must be in -180/+180 range*/ @@ -911,7 +834,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { meca.moment.exponent = 0; meca_define_second_plane (meca.NP1, &meca.NP2); } - else if (Ctrl->S.readmode == READ_PLANES) { + else if (Ctrl->S.readmode == SEIS_READ_PLANES) { meca.NP1.str = in[2+new_fmt]; if (meca.NP1.str > 180.0) meca.NP1.str -= 360.0; else if (meca.NP1.str < -180.0) meca.NP1.str += 360.0; /* Strike must be in -180/+180 range*/ @@ -936,7 +859,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { else meca.NP1.rake = meca_computed_rake2(meca.NP2.str, meca.NP2.dip, meca.NP1.str, meca.NP1.dip, fault); } - else if (Ctrl->S.readmode == READ_AXIS) { + else if (Ctrl->S.readmode == SEIS_READ_AXIS) { T.val = in[2+new_fmt]; T.str = in[3+new_fmt]; T.dip = in[4+new_fmt]; @@ -964,9 +887,9 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { N.val /= meca.moment.mant; P.val /= meca.moment.mant; - if (Ctrl->T.active || Ctrl->S.plotmode == PLOT_DC) meca_axe2dc (T, P, &meca.NP1, &meca.NP2); + if (Ctrl->T.active || Ctrl->S.plotmode == SEIS_PLOT_DC) meca_axe2dc (T, P, &meca.NP1, &meca.NP2); } - else if (Ctrl->S.readmode == READ_TENSOR) { + else if (Ctrl->S.readmode == SEIS_READ_TENSOR) { for (i = 2+new_fmt, n = 0; i < 8+new_fmt; i++, n++) mt.f[n] = in[i]; mt.expo = irint (in[i]); /* @@ -983,7 +906,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { meca_moment2axe (GMT, mt, &T, &N, &P); - if (Ctrl->T.active || Ctrl->S.plotmode == PLOT_DC) meca_axe2dc (T, P, &meca.NP1, &meca.NP2); + if (Ctrl->T.active || Ctrl->S.plotmode == SEIS_PLOT_DC) meca_axe2dc (T, P, &meca.NP1, &meca.NP2); } /* Common to all input types ... */ @@ -991,22 +914,35 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { gmt_geo_to_xy (GMT, in[GMT_X], in[GMT_Y], &plot_x, &plot_y); /* Keep track of whether we have added delaz to avoid double-correcting */ - added_delaz=false; + added_delaz = false; - /* If option -C is used, read the new position */ + /* If option -A is used, use the alternate position */ if (Ctrl->A.active) { - if (fabs (xynew[GMT_X]) > EPSIL || fabs (xynew[GMT_Y]) > EPSIL) { + if (Ctrl->A.mode || fabs (xynew[GMT_X]) > SEIS_EPSILON || fabs (xynew[GMT_Y]) > SEIS_EPSILON) { current_pen = Ctrl->A.pen; if (Ctrl->H.active) { - double scl = (Ctrl->H.mode == PSMECA_READ_SCALE) ? in[xcol] : Ctrl->H.value; + double scl = (Ctrl->H.mode == SEIS_READ_SCALE) ? in[xcol] : Ctrl->H.value; gmt_scale_pen (GMT, ¤t_pen, scl); } gmt_setpen (GMT, ¤t_pen); - gmt_geo_to_xy (GMT, xynew[GMT_X], xynew[GMT_Y], &plot_xnew, &plot_ynew); - gmt_setfill (GMT, &Ctrl->G.fill, 1); - if (Ctrl->A.size > 0.0) PSL_plotsymbol (PSL, plot_x, plot_y, &(Ctrl->A.size), PSL_CIRCLE); + if (Ctrl->A.mode) { /* Got Cartesian dx and dy in plot units */ + plot_xnew = plot_x + Ctrl->A.off[GMT_X]; + plot_ynew = plot_y + Ctrl->A.off[GMT_Y]; + } + else /* Got alternate geographic coordinates */ + gmt_geo_to_xy (GMT, xynew[GMT_X], xynew[GMT_Y], &plot_xnew, &plot_ynew); + if (Ctrl->A.fill_mode == SEIS_EVENT_FILL) + gmt_setfill (GMT, &Ctrl->G.fill, 1); + else if (Ctrl->A.fill_mode == SEIS_FIXED_FILL) + gmt_setfill (GMT, &Ctrl->A.fill, 1); + else /* SEIS_NO_FILL */ + gmt_setfill (GMT, NULL, 1); + if (Ctrl->A.size > 0.0) /* Plot symbol at actual location */ + PSL_plotsymbol (PSL, plot_x, plot_y, &(Ctrl->A.size), Ctrl->A.symbol); + /* Draw line between original and alternate location */ PSL_plotsegment (PSL, plot_x, plot_y, plot_xnew, plot_ynew); + /* Since we will plot beach ball at the alternative location, we swap them */ plot_x = plot_xnew; plot_y = plot_ynew; } @@ -1024,7 +960,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { size = (scale / Ctrl->S.reference) * ((Ctrl->S.linear) ? moment.mant * pow (10.0, moment.exponent) : meca_computed_mw (moment, meca.magms)); if (Ctrl->H.active) { /* Variable scaling of symbol size and pen width */ - double scl = (Ctrl->H.mode == PSMECA_READ_SCALE) ? in[xcol] : Ctrl->H.value; + double scl = (Ctrl->H.mode == SEIS_READ_SCALE) ? in[xcol] : Ctrl->H.value; size *= scl; } @@ -1041,7 +977,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { meca_get_trans (GMT, in[GMT_X], in[GMT_Y], &t11, &t12, &t21, &t22); delaz = atan2d(t12,t11); - if ((Ctrl->S.readmode == READ_AXIS || Ctrl->S.readmode == READ_TENSOR) && Ctrl->S.plotmode != PLOT_DC) { + if ((Ctrl->S.readmode == SEIS_READ_AXIS || Ctrl->S.readmode == SEIS_READ_TENSOR) && Ctrl->S.plotmode != SEIS_PLOT_DC) { T.str = meca_zero_360(T.str + delaz); N.str = meca_zero_360(N.str + delaz); @@ -1049,23 +985,23 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { current_pen = Ctrl->L.pen; if (Ctrl->H.active) { - double scl = (Ctrl->H.mode == PSMECA_READ_SCALE) ? in[xcol] : Ctrl->H.value; + double scl = (Ctrl->H.mode == SEIS_READ_SCALE) ? in[xcol] : Ctrl->H.value; gmt_scale_pen (GMT, ¤t_pen, scl); } gmt_setpen (GMT, ¤t_pen); - if (fabs (N.val) < EPSIL && fabs (T.val + P.val) < EPSIL) { + if (fabs (N.val) < SEIS_EPSILON && fabs (T.val + P.val) < SEIS_EPSILON) { meca_axe2dc (T, P, &meca.NP1, &meca.NP2); added_delaz = true; meca_ps_mechanism (GMT, PSL, plot_x, plot_y, meca, size, &Ctrl->G.fill, &Ctrl->E.fill, Ctrl->L.active); } else - meca_ps_tensor (GMT, PSL, plot_x, plot_y, size, T, N, P, &Ctrl->G.fill, &Ctrl->E.fill, Ctrl->L.active, Ctrl->S.plotmode == PLOT_TRACE, n_rec); + meca_ps_tensor (GMT, PSL, plot_x, plot_y, size, T, N, P, &Ctrl->G.fill, &Ctrl->E.fill, Ctrl->L.active, Ctrl->S.plotmode == SEIS_PLOT_TRACE, n_rec); } if (Ctrl->Z2.active) { current_pen = Ctrl->Z2.pen; if (Ctrl->H.active) { - double scl = (Ctrl->H.mode == PSMECA_READ_SCALE) ? in[xcol] : Ctrl->H.value; + double scl = (Ctrl->H.mode == SEIS_READ_SCALE) ? in[xcol] : Ctrl->H.value; gmt_scale_pen (GMT, ¤t_pen, scl); } gmt_setpen (GMT, ¤t_pen); @@ -1079,7 +1015,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { } current_pen = Ctrl->T.pen; if (Ctrl->H.active) { - double scl = (Ctrl->H.mode == PSMECA_READ_SCALE) ? in[xcol] : Ctrl->H.value; + double scl = (Ctrl->H.mode == SEIS_READ_SCALE) ? in[xcol] : Ctrl->H.value; gmt_scale_pen (GMT, ¤t_pen, scl); } gmt_setpen (GMT, ¤t_pen); @@ -1090,14 +1026,14 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { Ctrl->T.n_plane = n_plane_old; } } - else if (Ctrl->S.readmode == READ_AKI || Ctrl->S.readmode == READ_CMT || Ctrl->S.readmode == READ_PLANES || Ctrl->S.plotmode == PLOT_DC) { + else if (Ctrl->S.readmode == SEIS_READ_AKI || Ctrl->S.readmode == SEIS_READ_CMT || Ctrl->S.readmode == SEIS_READ_PLANES || Ctrl->S.plotmode == SEIS_PLOT_DC) { if (! added_delaz) { meca.NP1.str = meca_zero_360(meca.NP1.str + delaz); meca.NP2.str = meca_zero_360(meca.NP2.str + delaz); } current_pen = Ctrl->L.pen; if (Ctrl->H.active) { - double scl = (Ctrl->H.mode == PSMECA_READ_SCALE) ? in[xcol] : Ctrl->H.value; + double scl = (Ctrl->H.mode == SEIS_READ_SCALE) ? in[xcol] : Ctrl->H.value; gmt_scale_pen (GMT, ¤t_pen, scl); } gmt_setpen (GMT, ¤t_pen); @@ -1127,7 +1063,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { current_pen = Ctrl->W.pen; if (Ctrl->H.active) { - double scl = (Ctrl->H.mode == PSMECA_READ_SCALE) ? in[xcol] : Ctrl->H.value; + double scl = (Ctrl->H.mode == SEIS_READ_SCALE) ? in[xcol] : Ctrl->H.value; gmt_scale_pen (GMT, ¤t_pen, scl); } gmt_setpen (GMT, ¤t_pen); @@ -1138,11 +1074,11 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { } if (Ctrl->A2.active) { - if (Ctrl->S.readmode != READ_TENSOR && Ctrl->S.readmode != READ_AXIS) meca_dc2axe (meca, &T, &N, &P); + if (Ctrl->S.readmode != SEIS_READ_TENSOR && Ctrl->S.readmode != SEIS_READ_AXIS) meca_dc2axe (meca, &T, &N, &P); meca_axis2xy (plot_x, plot_y, size, P.str, P.dip, T.str, T.dip, &P_x, &P_y, &T_x, &T_y); current_pen = Ctrl->P2.pen; if (Ctrl->H.active) { - double scl = (Ctrl->H.mode == PSMECA_READ_SCALE) ? in[xcol] : Ctrl->H.value; + double scl = (Ctrl->H.mode == SEIS_READ_SCALE) ? in[xcol] : Ctrl->H.value; gmt_scale_pen (GMT, ¤t_pen, scl); } gmt_setpen (GMT, ¤t_pen); @@ -1150,7 +1086,7 @@ EXTERN_MSC int GMT_psmeca (void *V_API, int mode, void *args) { PSL_plotsymbol (PSL, P_x, P_y, &Ctrl->A2.size, Ctrl->A2.P_symbol); current_pen = Ctrl->T2.pen; if (Ctrl->H.active) { - double scl = (Ctrl->H.mode == PSMECA_READ_SCALE) ? in[xcol] : Ctrl->H.value; + double scl = (Ctrl->H.mode == SEIS_READ_SCALE) ? in[xcol] : Ctrl->H.value; gmt_scale_pen (GMT, ¤t_pen, scl); } gmt_setpen (GMT, ¤t_pen); diff --git a/src/seis/pspolar.c b/src/seis/pspolar.c index 84eab30406e..1d77231b99d 100644 --- a/src/seis/pspolar.c +++ b/src/seis/pspolar.c @@ -38,6 +38,7 @@ */ #include "gmt_dev.h" +#include "seis_defaults.h" #include "longopt/pspolar_inc.h" #define THIS_MODULE_CLASSIC_NAME "pspolar" @@ -48,9 +49,6 @@ #define THIS_MODULE_NEEDS "Jd" #define THIS_MODULE_OPTIONS "-:>BHJKOPRUVXYdehiqt" GMT_OPT("c") -#define DEFAULT_FONTSIZE 12.0 /* In points */ -#define DEFAULT_OFFSET 3.0 /* In points */ - /* Control structure for pspolar */ struct PSPOLAR_CTRL { @@ -143,7 +141,7 @@ static void *New_Ctrl (struct GMT_CTRL *GMT) { /* Allocate and initialize a new gmt_init_fill (GMT, &C->G.fill, 0.0, 0.0, 0.0); gmt_init_fill (GMT, &C->S2.fill, -1.0, -1.0, -1.0); C->T.justify = PSL_TC; - C->T.font.size = DEFAULT_FONTSIZE; + C->T.font.size = SEIS_DEFAULT_FONTSIZE; return (C); } @@ -168,7 +166,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) { if (level == GMT_SYNOPSIS) return (GMT_MODULE_SYNOPSIS); font = API->GMT->current.setting.font_annot[GMT_PRIMARY]; - font.size = DEFAULT_FONTSIZE; + font.size = SEIS_DEFAULT_FONTSIZE; GMT_Message (API, GMT_TIME_NONE, " REQUIRED ARGUMENTS:\n"); GMT_Option (API, "<"); GMT_Usage (API, 1, "\n-D/"); @@ -479,9 +477,9 @@ static int parse (struct GMT_CTRL *GMT, struct PSPOLAR_CTRL *Ctrl, struct GMT_OP if (gmt_get_pair (GMT, word, GMT_PAIR_DIM_DUP, Ctrl->T.offset) < 0) n_errors++; } else { /* Set default offset */ if (Ctrl->T.justify%4 != 2) /* Not center aligned */ - Ctrl->T.offset[0] = DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; + Ctrl->T.offset[0] = SEIS_DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; if (Ctrl->T.justify/4 != 1) /* Not middle aligned */ - Ctrl->T.offset[1] = DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; + Ctrl->T.offset[1] = SEIS_DEFAULT_OFFSET * GMT->session.u2u[GMT_PT][GMT_INCH]; } } else { /* Old syntax: -T/
// */ diff --git a/src/seis/seis_defaults.h b/src/seis/seis_defaults.h new file mode 100644 index 00000000000..11b93ddc532 --- /dev/null +++ b/src/seis/seis_defaults.h @@ -0,0 +1,35 @@ +/*-------------------------------------------------------------------- + * + * Copyright (c) 2013-2023 by the GMT Team (https://www.generic-mapping-tools.org/team.html) + * See LICENSE.TXT file for copying and redistribution conditions. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; version 3 or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * Contact info: www.generic-mapping-tools.org + *--------------------------------------------------------------------*/ + +/*! + * \file seis_defaults.h + * \brief + */ + +#ifndef SEIS_DEFAULTS_H +#define SEIS_DEFAULTS_H + +#define SEIS_MAG_REFERENCE 5.0 /* Reference magnitude for -S */ +#define SEIS_MOMENT_MANT_REFERENCE 4.0 /* Mantissa for reference moment for -S */ +#define SEIS_MOMENT_EXP_REFERENCE 23 /* Exponent for reference moment for -S */ + +/* Default font, offset, and symbol sizes */ +#define SEIS_DEFAULT_FONTSIZE 9.0 /* In points */ +#define SEIS_DEFAULT_OFFSET 3.0 /* In points */ +#define SEIS_DEFAULT_SYMBOL_SIZE 6.0 /* In points */ + +#endif /* SEIS_DEFAULTS_H */ diff --git a/src/seis/utilmeca.c b/src/seis/utilmeca.c index 3ca88df4330..b31a4893935 100644 --- a/src/seis/utilmeca.c +++ b/src/seis/utilmeca.c @@ -150,7 +150,7 @@ double meca_ps_mechanism (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, int i; - struct AXIS N_axis; + struct SEIS_AXIS N_axis; /* compute null axis strike and dip */ N_axis.dip = utilmeca_null_axis_dip (meca.NP1.str, meca.NP1.dip, meca.NP2.str, meca.NP2.dip); @@ -166,14 +166,14 @@ double meca_ps_mechanism (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, PSL_plotsymbol (PSL, x0, y0, ssize, PSL_CIRCLE); gmt_setfill (GMT, F, outline); - if (fabs (pos_NP1_NP2) < EPSIL) { + if (fabs (pos_NP1_NP2) < SEIS_EPSILON) { /* pure normal or inverse fault (null axis strike is determined with + or - 180 degrees. */ /* first nodal plane part */ i = 0; increment = 1.0; str = meca.NP1.str; - while (str <= meca.NP1.str + 180. + EPSIL) { + while (str <= meca.NP1.str + 180. + SEIS_EPSILON) { radius = utilmeca_proj_radius (meca.NP1.str, meca.NP1.dip, str) * radius_size; sincosd (str, &si, &co); x[i] = x0 + radius * si; @@ -184,7 +184,7 @@ double meca_ps_mechanism (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, if (fault == -1) { /* normal fault, close first compressing part */ str = meca.NP1.str + 180.; - while (str >= meca.NP1.str - EPSIL) { + while (str >= meca.NP1.str - SEIS_EPSILON) { sincosd (str, &si, &co); x[i] = x0 + si * radius_size; y[i] = y0 + co * radius_size; @@ -196,7 +196,7 @@ double meca_ps_mechanism (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, } /* second nodal plane part */ str = meca.NP2.str; - while (str <= meca.NP2.str + 180. + EPSIL) { + while (str <= meca.NP2.str + 180. + SEIS_EPSILON) { radius = utilmeca_proj_radius (meca.NP2.str, meca.NP2.dip, str) * radius_size; sincosd (str, &si, &co); x[i] = x0 + radius * si; @@ -207,7 +207,7 @@ double meca_ps_mechanism (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, if (fault == -1) { /* normal fault, close second compressing part */ str = meca.NP2.str + 180.; - while (str >= meca.NP2.str - EPSIL) { + while (str >= meca.NP2.str - SEIS_EPSILON) { sincosd (str, &si, &co); x[i] = x0 + si * radius_size; y[i] = y0 + co * radius_size; @@ -218,9 +218,9 @@ double meca_ps_mechanism (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, PSL_plotpolygon (PSL, x, y, i); } /* pure strike-slip */ - else if (fabs (90. - N_axis.dip) < EPSIL) { + else if (fabs (90. - N_axis.dip) < SEIS_EPSILON) { - increment = (fabs(meca.NP1.rake) < EPSIL) ? -1.0 : 1.0; + increment = (fabs(meca.NP1.rake) < SEIS_EPSILON) ? -1.0 : 1.0; /* first compressing part */ for (i = 0; i <= 90; i++) { str = meca.NP1.str - 90.0 + i * increment; @@ -251,7 +251,7 @@ double meca_ps_mechanism (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, increment = 1.; if (meca.NP1.str > N_axis.str) meca.NP1.str -= 360.; str = meca.NP1.str; - while (fabs (90. - meca.NP1.dip) < EPSIL ? str <= meca.NP1.str + EPSIL : str <= N_axis.str + EPSIL) { + while (fabs (90. - meca.NP1.dip) < SEIS_EPSILON ? str <= meca.NP1.str + SEIS_EPSILON : str <= N_axis.str + SEIS_EPSILON) { radius = utilmeca_proj_radius (meca.NP1.str, meca.NP1.dip, str) * radius_size; sincosd (str, &si, &co); x[i] = x0 + radius * si; @@ -264,9 +264,9 @@ double meca_ps_mechanism (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, meca.NP2.str += (1 + fault) * 90.; if (meca.NP2.str >= 360.) meca.NP2.str -= 360.; increment = fault; - if (fault * (meca.NP2.str - N_axis.str) < -EPSIL) meca.NP2.str += fault * 360.; - str = fabs (90. - meca.NP2.dip) < EPSIL ? meca.NP2.str : N_axis.str; - while (increment > 0. ? str <= meca.NP2.str + EPSIL : str >= meca.NP2.str - EPSIL) { + if (fault * (meca.NP2.str - N_axis.str) < -SEIS_EPSILON) meca.NP2.str += fault * 360.; + str = fabs (90. - meca.NP2.dip) < SEIS_EPSILON ? meca.NP2.str : N_axis.str; + while (increment > 0. ? str <= meca.NP2.str + SEIS_EPSILON : str >= meca.NP2.str - SEIS_EPSILON) { radius = utilmeca_proj_radius (meca.NP2.str - (1 + fault) * 90., meca.NP2.dip, str) * radius_size; sincosd (str, &si, &co); x[i] = x0 + radius * si; @@ -279,9 +279,9 @@ double meca_ps_mechanism (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, meca.NP1.str = meca_zero_360(meca.NP1.str); meca.NP2.str = meca_zero_360(meca.NP2.str); increment = pos_NP1_NP2 >= 0. ? -fault : fault; - if (increment * (meca.NP1.str - meca.NP2.str) < - EPSIL) meca.NP1.str += increment * 360.; + if (increment * (meca.NP1.str - meca.NP2.str) < - SEIS_EPSILON) meca.NP1.str += increment * 360.; str = meca.NP2.str; - while (increment > 0. ? str <= meca.NP1.str + EPSIL : str >= meca.NP1.str - EPSIL) { + while (increment > 0. ? str <= meca.NP1.str + SEIS_EPSILON : str >= meca.NP1.str - SEIS_EPSILON) { sincosd (str, &si, &co); x[i] = x0 + si * radius_size; y[i] = y0 + co * radius_size; @@ -294,10 +294,10 @@ double meca_ps_mechanism (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, /* first nodal plane till null axis */ i = 0; meca.NP1.str = meca_zero_360 (meca.NP1.str + 180.); - if (meca.NP1.str - N_axis.str < - EPSIL) meca.NP1.str += 360.; + if (meca.NP1.str - N_axis.str < - SEIS_EPSILON) meca.NP1.str += 360.; increment = -1.; str = meca.NP1.str; - while (fabs (90. - meca.NP1.dip) < EPSIL ? str >= meca.NP1.str -EPSIL : str >= N_axis.str - EPSIL) { + while (fabs (90. - meca.NP1.dip) < SEIS_EPSILON ? str >= meca.NP1.str -SEIS_EPSILON : str >= N_axis.str - SEIS_EPSILON) { radius = utilmeca_proj_radius (meca.NP1.str - 180., meca.NP1.dip, str) * radius_size; sincosd (str, &si, &co); x[i] = x0 + radius * si; @@ -309,9 +309,9 @@ double meca_ps_mechanism (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, /* second nodal plane from null axis */ meca.NP2.str = meca_zero_360(meca.NP2.str + 180.); increment = -fault; - if (fault * (N_axis.str - meca.NP2.str) < - EPSIL) meca.NP2.str -= fault * 360.; - str = fabs (90. - meca.NP2.dip) < EPSIL ? meca.NP2.str : N_axis.str; - while (increment > 0. ? str <= meca.NP2.str + EPSIL : str >= meca.NP2.str - EPSIL) { + if (fault * (N_axis.str - meca.NP2.str) < - SEIS_EPSILON) meca.NP2.str -= fault * 360.; + str = fabs (90. - meca.NP2.dip) < SEIS_EPSILON ? meca.NP2.str : N_axis.str; + while (increment > 0. ? str <= meca.NP2.str + SEIS_EPSILON : str >= meca.NP2.str - SEIS_EPSILON) { radius = utilmeca_proj_radius (meca.NP2.str - (1 - fault) * 90., meca.NP2.dip, str) * radius_size; sincosd (str, &si, &co); x[i] = x0 + radius * si; @@ -324,9 +324,9 @@ double meca_ps_mechanism (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, meca.NP1.str = meca_zero_360(meca.NP1.str); meca.NP2.str = meca_zero_360(meca.NP2.str); increment = pos_NP1_NP2 >= 0. ? -fault : fault; - if (increment * (meca.NP1.str - meca.NP2.str) < - EPSIL) meca.NP1.str += increment * 360.; + if (increment * (meca.NP1.str - meca.NP2.str) < - SEIS_EPSILON) meca.NP1.str += increment * 360.; str = meca.NP2.str; - while (increment > 0. ? str <= meca.NP1.str + EPSIL : str >= meca.NP1.str - EPSIL) { + while (increment > 0. ? str <= meca.NP1.str + SEIS_EPSILON : str >= meca.NP1.str - SEIS_EPSILON) { sincosd (str, &si, &co); x[i] = x0 + si * radius_size; y[i] = y0 + co * radius_size; @@ -394,7 +394,7 @@ double meca_zero_360 (double str) { } /**********************************************************************/ -double meca_computed_mw (struct MOMENT moment, double ms) { +double meca_computed_mw (struct SEIS_MOMENT moment, double ms) { /* Compute mw-magnitude from seismic moment or MS magnitude. */ /* Genevieve Patau from @@ -414,7 +414,7 @@ double meca_computed_mw (struct MOMENT moment, double ms) { } /*********************************************************************/ -static double utilmeca_computed_strike1 (struct nodal_plane NP1) { +static double utilmeca_computed_strike1 (struct SEIS_NODAL_PLANE NP1) { /* Compute the strike of the second nodal plane when are given strike, dip and rake for the first nodal plane with AKI & RICHARD's @@ -428,7 +428,7 @@ static double utilmeca_computed_strike1 (struct nodal_plane NP1) { sincosd (NP1.rake, &sr, &cr); sincosd (NP1.str, &ss, &cs); - if (cd1 < EPSIL && fabs (cr) < EPSIL) { + if (cd1 < SEIS_EPSILON && fabs (cr) < SEIS_EPSILON) { #if 0 GMT_Report (API, GMT_MSG_DEBUG, "\nThe second plane is horizontal;"); GMT_Report (API, GMT_MSG_DEBUG, "\nStrike is undetermined."); @@ -451,7 +451,7 @@ static double utilmeca_computed_strike1 (struct nodal_plane NP1) { } /*********************************************************************/ -static double utilmeca_computed_dip1 (struct nodal_plane NP1) { +static double utilmeca_computed_dip1 (struct SEIS_NODAL_PLANE NP1) { /* Compute second nodal plane dip when are given strike, dip and rake for the first nodal plane with AKI & RICHARD's @@ -468,7 +468,7 @@ static double utilmeca_computed_dip1 (struct nodal_plane NP1) { } /*********************************************************************/ -static double utilmeca_computed_rake1 (struct nodal_plane NP1) { +static double utilmeca_computed_rake1 (struct SEIS_NODAL_PLANE NP1) { /* Compute rake in the second nodal plane when strike ,dip and rake are given for the first nodal plane with AKI & @@ -485,7 +485,7 @@ static double utilmeca_computed_rake1 (struct nodal_plane NP1) { sincosd (NP1.dip, &sd, &cd); sincosd (NP1.str - str2, &ss, &cs); - if (fabs (dip2 - 90.0) < EPSIL) + if (fabs (dip2 - 90.0) < SEIS_EPSILON) sinrake2 = am * cd; else sinrake2 = -am * sd * cs / cd; @@ -509,7 +509,7 @@ double meca_computed_dip2 (double str1, double dip1, double str2) { double dip2, cosdp12 = cosd(str1 - str2); - if (fabs (dip1 - 90.) < EPSIL && fabs (cosdp12) < EPSIL) + if (fabs (dip1 - 90.) < SEIS_EPSILON && fabs (cosdp12) < SEIS_EPSILON) dip2 = 1000.0; /* (only first plane will be plotted) */ else dip2 = d_atan2d (cosd (dip1), -sind (dip1) * cosdp12); @@ -534,7 +534,7 @@ double meca_computed_rake2 (double str1, double dip1, double str2, double dip2, sincosd (str1 - str2, &ss, &cs); sd = sind(dip1); cd = cosd(dip2); - if (fabs (dip2 - 90.0) < EPSIL) + if (fabs (dip2 - 90.0) < SEIS_EPSILON) sinrake2 = fault * cd; else sinrake2 = -fault * sd * cs / cd; @@ -545,7 +545,7 @@ double meca_computed_rake2 (double str1, double dip1, double str2, double dip2, } /*********************************************************************/ -void meca_define_second_plane (struct nodal_plane NP1, struct nodal_plane *NP2) { +void meca_define_second_plane (struct SEIS_NODAL_PLANE NP1, struct SEIS_NODAL_PLANE *NP2) { /* Compute strike, dip, slip for the second nodal plane when are given strike, dip and rake for the first one. @@ -558,7 +558,7 @@ void meca_define_second_plane (struct nodal_plane NP1, struct nodal_plane *NP2) } /***************************************************************************************/ -void meca_moment2axe (struct GMT_CTRL *GMT, struct M_TENSOR mt, struct AXIS *T, struct AXIS *N, struct AXIS *P) { +void meca_moment2axe (struct GMT_CTRL *GMT, struct SEIS_M_TENSOR mt, struct SEIS_AXIS *T, struct SEIS_AXIS *N, struct SEIS_AXIS *P) { /* This version uses gmt_jacobi and does not suffer from the convert_matrix bug */ unsigned int j, nrots, np = 3; double *a, *d, *b, *z, *v; @@ -601,7 +601,7 @@ void meca_moment2axe (struct GMT_CTRL *GMT, struct M_TENSOR mt, struct AXIS *T, } /***************************************************************************************/ -double meca_ps_tensor (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, double y0, double size, struct AXIS T, struct AXIS N, struct AXIS P, struct GMT_FILL *C, struct GMT_FILL *E, int outline, int plot_zerotrace, int recno) { +double meca_ps_tensor (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, double y0, double size, struct SEIS_AXIS T, struct SEIS_AXIS N, struct SEIS_AXIS P, struct GMT_FILL *C, struct GMT_FILL *E, int outline, int plot_zerotrace, int recno) { /* Plot beachball for full moment tensors */ int d, b = 1, m, i, ii, n = 0, j1 = 1, j2 = 0, j3 = 0; int bigisotestv0, bigisotestv2; @@ -629,7 +629,7 @@ double meca_ps_tensor (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, do radius_size = size * 0.5; /* pure implosion or explosion */ - if (fabs (squared(v[0]) + squared(v[1]) + squared(v[2])) < EPSIL) { + if (fabs (squared(v[0]) + squared(v[1]) + squared(v[2])) < SEIS_EPSILON) { if (vi > 0.) { gmt_setfill (GMT, C, 1); PSL_plotsymbol (PSL, x0, y0, ssize, PSL_CIRCLE); @@ -698,7 +698,7 @@ double meca_ps_tensor (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, do xn = can * cpd * cad + san * sfi * cpb * cab + san * cfi * cpm * cam; xe = can * cpd * sad + san * sfi * cpb * sab + san * cfi * cpm * sam; - if (fabs (xn) < EPSIL && fabs (xe) < EPSIL) { + if (fabs (xn) < SEIS_EPSILON && fabs (xe) < SEIS_EPSILON) { takeoff = 0.; az = 0.; } @@ -872,7 +872,7 @@ double meca_ps_tensor (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, do return (size); } -void meca_axe2dc (struct AXIS T, struct AXIS P, struct nodal_plane *NP1, struct nodal_plane *NP2) { +void meca_axe2dc (struct SEIS_AXIS T, struct SEIS_AXIS P, struct SEIS_NODAL_PLANE *NP1, struct SEIS_NODAL_PLANE *NP2) { /* Calculate double couple from principal axes. Angles are in degrees. @@ -919,7 +919,7 @@ void meca_axe2dc (struct AXIS T, struct AXIS P, struct nodal_plane *NP1, struct NP2->rake = meca_computed_rake2 (NP1->str, NP1->dip, NP2->str, NP2->dip, im); } -void meca_dc2axe (st_me meca, struct AXIS *T, struct AXIS *N, struct AXIS *P) { +void meca_dc2axe (st_me meca, struct SEIS_AXIS *T, struct SEIS_AXIS *N, struct SEIS_AXIS *P) { /* From FORTRAN routines of Anne Deschamps : compute azimuth and plungement of P-T axis @@ -944,7 +944,7 @@ void meca_dc2axe (st_me meca, struct AXIS *T, struct AXIS *N, struct AXIS *P) { dx = atan2d (hypot(amx, amy), amz) - 90.0; px = atan2d (amy, -amx); if (px < 0.0) px += 360.0; - if (dx < EPSIL) { + if (dx < SEIS_EPSILON) { if (px > 90.0 && px < 180.0) px += 180.0; if (px >= 180.0 && px < 270.0) px -= 180.0; } @@ -956,7 +956,7 @@ void meca_dc2axe (st_me meca, struct AXIS *T, struct AXIS *N, struct AXIS *P) { py = atan2d (amy, -amx); if (amz > 0.0) py -= 180.0; if (py < 0.0) py += 360.0; - if (dy < EPSIL) { + if (dy < SEIS_EPSILON) { if (py > 90.0 && py < 180.0) py += 180.0; if (py >= 180.0 && py < 270.0) py -= 180.0; } @@ -1003,3 +1003,131 @@ GMT_LOCAL int utilmeca_dump_meca (st_me meca) { } #endif #endif + +/* Parsing of meca -A and coupe -D options for offsetting symbols */ + +unsigned int meca_line_parse (struct GMT_CTRL *GMT, struct SEIS_OFFSET_LINE *L, char option, char *arg) { + unsigned int n_errors = 0, k; + int n; + char txt[GMT_LEN256] = {""}, *c = NULL, *q = NULL; + char *modifiers = (option == 'D') ? "cgops" : "gops"; /* Coupe also as +c */ + strncpy (txt, arg, GMT_LEN256-1); + + /* Deal with these possible variations of old -C and new -A options in meca: + * 1. -A[+p][+s] which is the current syntax + * 2. -C[][+s] which was the GMT5-6.1.1 syntax + * 3. -C[][P] which was the GMT4 syntax */ + + if ((c = gmt_first_modifier (GMT, txt, modifiers))) { /* Found at least one valid modifier */ + unsigned int pos = 0; + char p[GMT_LEN256] = {""}; + while (gmt_getmodopt (GMT, option, c, modifiers, &pos, p, &n_errors) && n_errors == 0) { + switch (p[0]) { + case 'c': /* Geo->cart conversion in coupe: +c */ + if (p[1] == '\0') + L->convert_geo = true; /* ALternate location given geographically, must convert to dist/depth */ + else { + GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: +c takes no argument %s\n", option, &p[1]); + n_errors++; + } + break; + case 'g': /* Symbol fill +g or no fill +g */ + if (p[1] == '\0') + L->fill_mode = SEIS_NO_FILL; /* No fill */ + else if (gmt_getfill (GMT, &p[1], &L->fill)) { + GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: Bad +g argument %s\n", option, &p[1]); + n_errors++; + } + else + L->fill_mode = SEIS_FIXED_FILL; /* Default is to fill, with -G unless overwritten */ + break; + case 'o': /* Variable or fixed plot offsets */ + if (p[1] == '\0') /* No args means we read dx and dy as the "alternate coordinates". Implies +c */ + L->mode |= SEIS_CART_OFFSET; + else if ((n = gmt_get_pair (GMT, &p[1], GMT_PAIR_DIM_DUP, L->off)) < 0) { + GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: Failed to parse offset arguments for +o modifier\n", option); + n_errors++; + } + else + L->mode |= SEIS_CART_OFFSET_FIX; + break; + case 'p': /* Line and symbol pen */ + if (p[1] == '\0' || gmt_getpen (GMT, &p[1], &L->pen)) { + gmt_pen_syntax (GMT, option, NULL, " ", NULL, 0); + n_errors++; + } + break; + case 's': /* Symbol diameter */ + k = 2; /* Start of size if symbol type was explicitly given */ + switch (p[1]) { /* Check all standard geometric symbols */ + case 'a': L->symbol = PSL_STAR; break; + case 'c': L->symbol = PSL_CIRCLE; break; + case 'd': L->symbol = PSL_DIAMOND; break; + case 'g': L->symbol = PSL_OCTAGON; break; + case 'h': L->symbol = PSL_HEXAGON; break; + case 'i': L->symbol = PSL_INVTRIANGLE; break; + case 'n': L->symbol = PSL_PENTAGON; break; + case 'r': L->symbol = PSL_RECT; break; + case 's': L->symbol = PSL_SQUARE; break; + case 't': L->symbol = PSL_TRIANGLE; break; + case 'x': L->symbol = PSL_CROSS; break; + default: /* Presumably just size and default to circle, but check for errors */ + if (isalpha (p[1])) { /* Bad symbol code */ + GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: Symbol code %s not supported\n", option, &p[1]); + n_errors++; + } + else { /* No symbol type given, default to circle */ + L->symbol = PSL_CIRCLE; + k = 1; + } + break; + } + if (p[1] == '\0' || (L->size = gmt_M_to_inch (GMT, &p[k])) < 0.0) { + GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: Circle diameter cannot be negative or not given!\n", option); + n_errors++; + } + break; + default: break; /* These are caught in gmt_getmodopt so break is just for Coverity */ + } + } + c[0] = '\0'; /* Chop off the modifiers */ + } + /* If the user used modern modifiers only as case 1 above then we might be done here */ + if (txt[0] == '\0') return n_errors; + + /* Here we got older syntax: -C[+s] or -C[][P] (but the +s would have been stripped off + * so here we must either have -C or -C[][P] */ + + L->symbol = PSL_CIRCLE; /* Only option with this syntax */ + if ((q = strchr (txt, 'P')) != NULL) { /* Case 3 way of changing the diameter */ + if (q[1] == '\0' || (L->size = gmt_M_to_inch (GMT, &q[1])) < 0.0) { + GMT_Report (GMT->parent, GMT_MSG_ERROR, "Option -%c: Circle diameter cannot be negative or not given!\n", option); + n_errors++; + } + q[0] = '\0'; /* Chop off the Psize setting; if txt is not empty we also have an optional pen */ + if (txt[0] && gmt_getpen (GMT, txt, &L->pen)) { + gmt_pen_syntax (GMT, option, NULL, " ", NULL, 0); + n_errors++; + } + } + else if (gmt_getpen (GMT, txt, &L->pen)) { /* Here we just have -C to deal with */ + gmt_pen_syntax (GMT, option, NULL, " ", NULL, 0); + n_errors++; + } + return n_errors; +} + +void meca_line_usage (struct GMTAPI_CTRL *API, char option) { + /* Print the usage message for coupe -D and meca -A */ + char *insert = (option == 'D') ? "[+c]" : ""; /* Coupe also as +c */ + GMT_Usage (API, 1, "\n-%c%s%s", option, insert, SEIS_LINE_SYNTAX); + GMT_Usage (API, -2, "Offset focal mechanisms to alternate positions given in the last two columns of the input file (before the optional label). " + "A line is drawn between both positions:"); + if (option == 'D') + GMT_Usage (API, 3, "+c Alternate coupe locations given as lon, lat; convert to (distance, depth() in crossectional plane [Read Cartesian locations]."); + GMT_Usage (API, 3, "+g Append fill for optional symbol, or chose no fill with +g [Default uses the beachball fill]."); + GMT_Usage (API, 3, "+o Offset the plot positions by /. If none given then we expect the alternative position columns to hold the offsets."); + GMT_Usage (API, 3, "+p Specify the pen used to draw the line between original and adjusted position [0.25p]."); + GMT_Usage (API, 3, "+s Draw a small symbol of indicated size at the original location. Default symbol is a circle " + "but optionally any standard symbol code from a|c|d|g|h|i|n|p|s|t|x is accepted [no symbol]."); +} diff --git a/src/seis/utilmeca.h b/src/seis/utilmeca.h index 25469d46734..2eb90430ed1 100644 --- a/src/seis/utilmeca.h +++ b/src/seis/utilmeca.h @@ -23,17 +23,19 @@ * \file utilmeca.h */ +unsigned int meca_line_parse (struct GMT_CTRL *GMT, struct SEIS_OFFSET_LINE *L, char option, char *arg); +void meca_line_usage (struct GMTAPI_CTRL *API, char option); void meca_get_trans (struct GMT_CTRL *GMT, double slon, double slat, double *t11, double *t12, double *t21, double *t22); 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 MOMENT moment, double ms); +double meca_computed_mw(struct SEIS_MOMENT moment, double ms); 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 nodal_plane NP, struct nodal_plane *NP2); -double meca_ps_tensor (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, double y0, double size, struct AXIS T, struct AXIS N, struct AXIS P, struct GMT_FILL *C, struct GMT_FILL *E, int outline, int plot_zerotrace, int recno); -void meca_axe2dc(struct AXIS T, struct AXIS P, struct nodal_plane *NP1, struct nodal_plane *NP2); -void meca_dc2axe (st_me meca, struct AXIS *T, struct AXIS *N, struct AXIS *P); +void meca_define_second_plane(struct SEIS_NODAL_PLANE NP, struct SEIS_NODAL_PLANE *NP2); +double meca_ps_tensor (struct GMT_CTRL *GMT, struct PSL_CTRL *PSL, double x0, double y0, double size, struct SEIS_AXIS T, struct SEIS_AXIS N, struct SEIS_AXIS P, struct GMT_FILL *C, struct GMT_FILL *E, int outline, int plot_zerotrace, int recno); +void meca_axe2dc(struct SEIS_AXIS T, struct SEIS_AXIS P, struct SEIS_NODAL_PLANE *NP1, struct SEIS_NODAL_PLANE *NP2); +void meca_dc2axe (st_me meca, struct SEIS_AXIS *T, struct SEIS_AXIS *N, struct SEIS_AXIS *P); void ps_pt_axis(double x0, double y0, st_me meca, double size, double *pp, double *dp, double *pt, double *dt, double *xp, double *yp, double *xt, double *yt); -void meca_moment2axe(struct GMT_CTRL *GMT, struct M_TENSOR mt, struct AXIS *T, struct AXIS *N, struct AXIS *P); +void meca_moment2axe(struct GMT_CTRL *GMT, struct SEIS_M_TENSOR mt, struct SEIS_AXIS *T, struct SEIS_AXIS *N, struct SEIS_AXIS *P); void meca_axis2xy(double x0, double y0, double size, double pp, double dp, double pt, double dt, double *xp, double *yp, double *xt, double *yt); double meca_zero_360 (double str); diff --git a/test/baseline/seis.dvc b/test/baseline/seis.dvc index 894a17995aa..d126bbec7fa 100644 --- a/test/baseline/seis.dvc +++ b/test/baseline/seis.dvc @@ -1,5 +1,5 @@ outs: -- md5: 90371beb37da2d936b6c8f0ea34cb65d.dir - size: 931886 +- md5: 732b3570f6a3f9291e2f6f138cdc8d0a.dir + size: 931715 nfiles: 15 path: seis diff --git a/test/seis/seis_12.sh b/test/seis/seis_12.sh index 142e201fbdf..5f13734f969 100755 --- a/test/seis/seis_12.sh +++ b/test/seis/seis_12.sh @@ -21,7 +21,7 @@ gmt math -T2020-01-31T/2020-02-06T/2 --TIME_UNIT=h -o0 T = time.txt cat << EOF > main.sh gmt begin gmt basemap -R0/250/0/100 -Jx0.02i/-0.02i -B -Y0.5i -X0.5i - gmt events labels.txt -L1 -Et -T\${MOVIE_COL0} -F+f12p,Helvetica-Bold,red+jBL -Dj0.1c --TIME_UNIT=d + gmt events labels.txt -L0.5 -Et -T\${MOVIE_COL0} -F+f12p,Helvetica-Bold,red+jBL -Dj0.1c --TIME_UNIT=d gmt events -Z"coupe -Q -L -Sc3c -Ab128/11/120/250/90/400/0/100+f -Fa0.1i/cc" -Ct.cpt -N data.txt -T\${MOVIE_COL0} -Es+r1+p1+d1+f1 -Mi1+c-0.5 -Ms2+c0.5 -Mt+c0 -L3 --TIME_UNIT=d gmt end EOF