/*-------------------------------------------------------------------- * $Id: pscoupe.c,v 1.3.4.1 2002/02/27 17:41:10 pwessel Exp $ * * Copyright (c) 1996-2001 by G. Patau * See README file for copying and redistribution conditions. *--------------------------------------------------------------------*/ /* pscoupe will read pairs (or ) from inputfile and plot symbols on a cross-section. Focal mechanisms may be specified (double couple or moment tensor) and require additional columns of data. PostScript code is written to stdout. Author: Genevieve Patau Date: 9 September 1992 Last change : 02 April 2001 Version: 3.4 Roots: based on psxy.c version 3.0 */ #include "gmt.h" /* to have gmt environment */ #include "meca.h" #include "utilmeca.h" #include "submeca.h" void distaz(double lat1,double lon1,double lat2,double lon2,double *distrad,double *distdeg,double *distkm,double *az12rad,double *az12deg,double *az21rad,double *az21deg,int syscoord); /* symbols for plotting seismicity and/or axis */ #define CROSS 1 #define CIRCLE 2 #define SQUARE 3 #define TRIANGLE 4 #define DIAMOND 5 #define STAR 6 #define HEXAGON 7 #define ITRIANGLE 8 int *plot_pen; main (int argc, char **argv) { int i, j, symbol = 0, n, ix = 0, iy = 1, n_files = 0, fno; int n_args; int n_rec = 0; BOOLEAN outline = FALSE, p_outline = FALSE, t_outline = FALSE; BOOLEAN error = FALSE, nofile = TRUE, polygon = FALSE; BOOLEAN done, get_rgb = FALSE, no_size_needed, greenwich; BOOLEAN read_size = FALSE, read_proj = FALSE; BOOLEAN read_cmt = FALSE, read_aki = FALSE, read_planes = FALSE; BOOLEAN read_tensor = FALSE, read_axis = FALSE, read_point = FALSE; BOOLEAN plot_dc = FALSE, plot_tensor = FALSE, plot_axis = FALSE; BOOLEAN plot_zerotrace = FALSE, tr_zerotrace = FALSE; BOOLEAN transparence = FALSE, one_size = FALSE, no_label = FALSE; BOOLEAN frame_coupe = FALSE; BOOLEAN old_GMT_world_map, skip_if_outside = TRUE; BOOLEAN transparence_old, not_defined = FALSE; double xy[2], west = 0.0, east = 0.0, south = 0.0, north = 0.0; double plot_x, plot_y, scale = 0.0; char event_title[BUFSIZ], txt_a[32]; char line[BUFSIZ], symbol_type, col[15][40], *cpt; char newfile[120], extracted_file[120]; FILE *fp = NULL; FILE *pnew, *pextract; struct GMT_PEN pen, lpen, tr_pen, tz_pen; struct GMT_PEN ppen, tpen; struct GMT_FILL fill, efill, nofill; struct GMT_FILL pfill, tfill; struct nodal_plane NP1, NP2, PREF; st_me meca, mecar; struct MOMENT moment; struct M_TENSOR mt, mtr; struct AXIS T, N, P, Tr, Nr, Pr; int n_plane = 0, n_plane_old; int default_fontsize = 9, default_justify = 2; int fontsize = default_fontsize, justify = default_justify, form = 0; double default_offset = gmtdefs.measure_unit == 0 ? 0.1 : 0.04; double offset = default_offset, angle = 0.; double size; double tmp1, tmp2, tmp3, tmp4, tmp5; double n_dep, distance; double xlonref, ylatref; double fault, depth, dmin, dmax; double p_length, p_width, lon1, lat1, lon2, lat2; char project_type; int syscoord, fuseau = 0; double P_x, P_y, T_x, T_y, a_size; char P_sym_type, T_sym_type; int P_sym, T_sym; argc = GMT_begin (argc, argv); GMT_init_pen (&pen, GMT_PENWIDTH); GMT_init_fill (&fill, 0, 0, 0); GMT_init_fill (&efill, 255, 255, 255); GMT_init_fill (&nofill, -1, -1, -1); lpen = pen; ppen = pen; tpen = pen; tr_pen = pen; tz_pen = pen; pfill = fill; tfill = efill; /* Check and interpret the command line arguments */ for (i = 1; !error && i < argc; i++) { if (argv[i][0] == '-') { switch(argv[i][1]) { /* Common parameters */ case 'B': case 'H': case 'J': case 'K': case 'O': case 'P': case 'R': case 'U': case 'V': case 'X': case 'x': case 'Y': case 'y': case 'c': case ':': case '\0': error += GMT_get_common_args (argv[i], &west, &east, &south, &north); break; /* Supplemental parameters */ case 'A': /* Cross-section definition */ read_proj = TRUE; project_type = argv[i][2]; j = strlen(argv[i]) - 1; if(argv[i][j] == 'f') frame_coupe = TRUE; if(project_type == 'a' || project_type == 'c') { sscanf (&argv[i][3], "%lf/%lf/%lf/%lf/%lf/%lf/%lf/%lf", &lon1, &lat1, &lon2, &lat2, &PREF.dip, &p_width, &dmin, &dmax); syscoord = project_type == 'a' ? 0 : 2; distaz(lat1, lon1, lat2, lon2, &tmp1, &tmp2, &p_length, &tmp3, &PREF.str, &tmp4, &tmp5, syscoord); sprintf(newfile, "A%c%.1lf_%.1lf_%.1lf_%.1lf_%.0lf_%.0lf_%.0lf_%.0lf", project_type, lon1, lat1, lon2, lat2, PREF.dip, p_width, dmin, dmax); sprintf(extracted_file,"A%c%.1lf_%.1lf_%.1lf_%.1lf_%.0lf_%.0lf_%.0lf_%.0lf_map", project_type, lon1, lat1, lon2, lat2, PREF.dip, p_width, dmin, dmax); } else if(project_type == 'b' || project_type == 'd') { sscanf (&argv[i][3], "%lf/%lf/%lf/%lf/%lf/%lf/%lf/%lf", &lon1, &lat1, &PREF.str, &p_length, &PREF.dip, &p_width, &dmin, &dmax); sprintf(newfile, "A%c%.1lf_%.1lf_%.0lf_%.0lf_%.0lf_%.0lf_%.0lf_%.0lf", project_type, lon1, lat1, PREF.str, p_length, PREF.dip, p_width, dmin, dmax); sprintf(extracted_file,"A%c%.1lf_%.1lf_%.0lf_%.0lf_%.0lf_%.0lf_%.0lf_%.0lf_map", project_type, lon1, lat1, PREF.str, p_length, PREF.dip, p_width, dmin, dmax); } PREF.rake = 0.; pnew = fopen(newfile, "w"); pextract = fopen(extracted_file, "w"); if(project_type == 'a' || project_type == 'b') fuseau = gutm(lon1, lat1, &xlonref, &ylatref, fuseau); else { fuseau = - 1; xlonref = lon1; ylatref = lat1; } polygon = TRUE; break; case 'E': /* Set color for extensive parts */ if (!argv[i][2] || (argv[i][2] && GMT_getfill (&argv[i][2], &efill))) { GMT_fill_syntax ('G'); error++; } polygon = TRUE; break; case 'G': /* Set color for compressive parts */ if (!argv[i][2] || (argv[i][2] && GMT_getfill (&argv[i][2], &fill))) { GMT_fill_syntax ('G'); error++; } polygon = TRUE; break; case 'L': /* Draw outline [set outline attributes] */ outline = TRUE; if (argv[i][2] && GMT_getpen (&argv[i][2], &lpen)) { GMT_pen_syntax ('L'); error++; } break; case 'M': /* Same size for any magnitude */ one_size = TRUE; break; case 'N': /* Do not skip points outside border */ skip_if_outside = FALSE; break; case 'S': /* Mechanisms : get format [and size] */ symbol_type = argv[i][2]; strcpy(txt_a, &argv[i][3]); n=0; while (txt_a[n] && txt_a[n] != '/') n++; txt_a[n]=0; scale = GMT_convert_units (txt_a, GMT_INCH); if(strstr(argv[i], "/\0") != NULL) { sscanf(strstr(argv[i], "/\0"), "/%d/%lf", &fontsize, &offset); if (fontsize == 0) fontsize = default_fontsize; if (fontsize < 0) no_label = TRUE; if (offset == 0.) offset = default_offset; if (argv[i][strlen(argv[i]) - 1] == 'u') justify = 10; } switch (symbol_type) { case 'c': read_cmt = TRUE; plot_dc = TRUE; break; case 'a': read_aki = TRUE; plot_dc = TRUE; break; case 'p': read_planes = TRUE; plot_dc = TRUE; break; case 'm': read_tensor = TRUE; plot_tensor = TRUE; break; case 'd': read_tensor = TRUE; plot_dc = TRUE; break; case 'z': read_tensor = TRUE; plot_zerotrace = TRUE; break; case 'x': read_axis = TRUE; plot_tensor = TRUE; break; case 'y': read_axis = TRUE; plot_dc = TRUE; break; case 't': read_axis = TRUE; plot_zerotrace = TRUE; break; default: error = TRUE; break; } break; case 's': /* Only points : get symbol [and size] */ read_point = TRUE; symbol_type = argv[i][2]; if(strlen(argv[i]) >3) { strcpy(txt_a, &argv[i][3]); n=0; while (txt_a[n] && txt_a[n] != '/') n++; txt_a[n]=0; scale = GMT_convert_units (txt_a, GMT_INCH); } if(strstr(argv[i], "/\0") != NULL) { sscanf(strstr(argv[i], "/\0"), "/%d/%lf", &fontsize, &offset); if (fontsize == 0) fontsize = default_fontsize; if (fontsize < 0) no_label = TRUE; if (offset == 0.) offset = default_offset; if (argv[i][strlen(argv[i]) - 1] == 'u') justify = 10; } switch (symbol_type) { case 'a': symbol = STAR; break; case 'c': symbol = CIRCLE; break; case 'd': symbol = DIAMOND; break; case 'h': symbol = HEXAGON; break; case 'i': symbol = ITRIANGLE; break; case 's': symbol = SQUARE; break; case 't': symbol = TRIANGLE; break; case 'x': symbol = CROSS; break; default: error = TRUE; fprintf (stderr, "%s: GMT SYNTAX ERROR -s option: Unrecognized symbol type %c\n", argv[0], symbol_type); break; } if (scale == 0.0) { read_size = TRUE; } size = scale; break; case 'T': transparence = TRUE; sscanf (&argv[i][2], "%d",&n_plane); if(strlen(argv[i]) > 3) { /* Set transparent attributes */ if (argv[i][2] && GMT_getpen (&argv[i][2], &tr_pen)) { GMT_pen_syntax ('T'); error++; } } break; case 'W': /* Set line attributes */ if (argv[i][2] && GMT_getpen (&argv[i][2], &pen)) { GMT_pen_syntax ('W'); error++; } break; case 'Z': /* Vary symbol color with z */ cpt = &argv[i][2]; get_rgb = TRUE; break; case 'a': /* plot axis */ plot_axis = TRUE; if(strlen(argv[i]) == 2) { strcpy(txt_a,"0.08i"); a_size = GMT_convert_units (txt_a, GMT_INCH); P_sym_type = 'c'; T_sym_type = 'c'; } else { a_size = GMT_convert_units (txt_a, GMT_INCH); strcpy(txt_a, &argv[i][3]); n=0; while (txt_a[n] && txt_a[n] != '/') n++; txt_a[n]=0; a_size = GMT_convert_units (txt_a, GMT_INCH); if(strstr(argv[i], "/\0") != NULL) { strcpy(txt_a,strstr(argv[i], "/\0")); switch (strlen(txt_a)) { case 1: P_sym_type = 'c'; T_sym_type = 'c'; break; case 2: P_sym_type = txt_a[1]; T_sym_type = txt_a[1]; break; case 3: P_sym_type = txt_a[1]; T_sym_type = txt_a[2]; break; } } } switch (P_sym_type) { case 'a': P_sym = STAR; break; case 'c': P_sym = CIRCLE; break; case 'd': P_sym = DIAMOND; break; case 'h': P_sym = HEXAGON; break; case 'i': P_sym = ITRIANGLE; break; case 's': P_sym = SQUARE; break; case 't': P_sym = TRIANGLE; break; case 'x': P_sym = CROSS; break; } switch (T_sym_type) { case 'a': T_sym = STAR; break; case 'c': T_sym = CIRCLE; break; case 'd': T_sym = DIAMOND; break; case 'h': T_sym = HEXAGON; break; case 'i': T_sym = ITRIANGLE; break; case 's': T_sym = SQUARE; break; case 't': T_sym = TRIANGLE; break; case 'x': T_sym = CROSS; break; } break; case 'e': /* Set color for T axis symbol */ if (!argv[i][2] || (argv[i][2] && GMT_getfill (&argv[i][2], &tfill))) { GMT_fill_syntax ('e'); error++; } polygon = TRUE; break; case 'g': /* Set color for P axis symbol */ if (!argv[i][2] || (argv[i][2] && GMT_getfill (&argv[i][2], &pfill))) { GMT_fill_syntax ('g'); error++; } GMT_getfill (&argv[i][2], &pfill); polygon = TRUE; break; case 'p': /* Draw outline of P axis symbol [set outline attributes] */ p_outline = TRUE; if(strlen(argv[i]) > 2) { if (argv[i][2] && GMT_getpen (&argv[i][2], &ppen)) { GMT_pen_syntax ('p'); error++; } } break; case 't': /* Draw outline of T axis symbol [set outline attributes] */ t_outline = TRUE; if(strlen(argv[i]) > 2){ if (argv[i][2] && GMT_getpen (&argv[i][2], &tpen)) { GMT_pen_syntax ('t'); error++; } } break; /* Illegal options */ default: /* Options not recognized */ error = TRUE; fprintf(stderr, "%s, -%c option not recognized.\n", argv[0], argv[i][1]); break; } } else n_files++; } /* Check that the options selected are mutually consistant */ no_size_needed = (read_cmt || read_planes || read_aki || read_axis || read_tensor); error += GMT_check_rgb (pen.rgb) + GMT_check_rgb (lpen.rgb) + GMT_check_rgb (ppen.rgb) + GMT_check_rgb (tpen.rgb) + GMT_check_rgb (fill.rgb) + GMT_check_rgb (efill.rgb) + GMT_check_rgb (pfill.rgb) + GMT_check_rgb (tfill.rgb) + GMT_check_rgb (gmtdefs.basemap_frame_rgb); /* Only one allowed */ if ((read_cmt + read_aki + read_planes + read_tensor + read_axis + read_point) > 1) error++; if(!read_proj) error++; if(no_size_needed && symbol > 0) error++; if (!no_size_needed && (symbol > 0 && scale < 0.0)) error++; if (argc == 1 || GMT_quick || error) { /* Display usage */ fprintf (stderr,"pscoupe %s - Plot seismological symbols on cross-sections\n\n", GMT_VERSION); fprintf (stderr,"usage: pscoupe -A -J -R \n"); fprintf (stderr, " [-B] [-E] [-G]\n"); fprintf (stderr, " [-H] [-K] [-L] [-M] [-N] [-O] [-P]\n"); fprintf (stderr, " [-S[/fontsize[/justify/offset/angle/form]]]\n"); fprintf (stderr, " [-s[/fontsize[/justify/offset/angle/form]]]\n"); fprintf (stderr, " [-Tnplane[/]] [-U[/dx/dy/][