/*-------------------------------------------------------------------- * $Id: psvelo.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. *--------------------------------------------------------------------*/ /* psvelo will read pairs (or ) from inputfile and plot symbols on a map. Velocity ellipses, strain crosses, or strain wedges, may be specified, some of which require additional columns of data. Only one symbol may be plotted at a time. PostScript code is written to stdout. Author: Kurt Feigl Date: 7 July 1998 Version: 3.3.4 Roots: based on psxy.c Adapted to version 3.3 by Genevieve Patau (25 June 1999) Last modified : 18 February 2000 */ #include "gmt.h" /* to have gmt environment */ #include "utilvelo.h" #include "utilstrain.h" #define EPSIL 0.0001 #define CINE 1 #define ANISO 2 #define WEDGE 3 #define CROSS 4 #define veclen(x, y) sqrt((x) * (x) + (y) * (y)) /* parameters for writing text */ #define ANGLE 0.0 #define FORM 0 #define TIRET_WIDTH 3 #define TEXT 14 #define POINTSIZE 0.005 int *plot_pen; main (int argc, char **argv) { int i, symbol = 0, n, ix = 0, iy = 1, n_files = 0, fno; int n_args; int n_rec = 0; BOOLEAN outline = FALSE; BOOLEAN error = FALSE, nofile = TRUE, polygon = FALSE; BOOLEAN shade_uncert = FALSE; BOOLEAN rescale_sigma = FALSE; BOOLEAN done, no_size_needed, greenwich; BOOLEAN read_ellipse = FALSE, read_rotated_ellipse = FALSE; BOOLEAN des_ellipse = TRUE, des_arrow = TRUE; BOOLEAN read_anisotropy = FALSE; BOOLEAN read_wedge = FALSE; BOOLEAN read_cross = FALSE; BOOLEAN old_GMT_world_map, skip_if_outside = TRUE; double xy[2], west = 0.0, east = 0.0, south = 0.0, north = 0.0; double plot_x, plot_y, scale = 0.0; double vxy[2], plot_vx, plot_vy; double eps1,eps2,spin,spinsig,theta; double direction, small_axis, great_axis; double sigma_x, sigma_y, corr_xy; double confidence = 0., sigma_scale = 1.0, conrad = 1.0; double v_width = 0.01, h_length = 0.12, h_width = 0.03, vector_shape = 0.4; double wedge_amp = 1.e7; double t11 = 1.0, t12 = 0.0, t21 = 0.0, t22 = 1.0; double hl,hw,vw; char station_name[20]; char txt_a[32], txt_b[32], txt_c[32]; char line[BUFSIZ], symbol_type, col[12][40]; FILE *fp = NULL; struct GMT_PEN pen; struct GMT_FILL fill, efill; /* efill is for uncertainty wedge */ int justify, fontsize; 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); /* 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': /* Change size of arrow head */ strcpy(txt_a, &argv[i][3]); strcpy(txt_b, strchr(txt_a+1, '/')+1); strcpy(txt_c, strchr(txt_b+1, '/')+1); n=0; while (txt_a[n] && txt_a[n] != '/') n++; txt_a[n]=0; n=0; while (txt_b[n] && txt_b[n] != '/') n++; txt_b[n]=0; v_width = GMT_convert_units (txt_a, GMT_INCH); h_length = GMT_convert_units (txt_b, GMT_INCH); h_width = GMT_convert_units (txt_c, GMT_INCH); break; case 'D': /* Rescale Sigmas */ rescale_sigma = TRUE; sscanf (&argv[i][2], "%lf",&sigma_scale); break; case 'E': /* Set color for error ellipse */ GMT_getfill (&argv[i][2], &efill); shade_uncert = TRUE; break; case 'G': /* Set Gray shade for polygon */ GMT_getfill (&argv[i][2], &fill); polygon = TRUE; break; case 'L': /* Draw the outline */ outline = TRUE; break; case 'N': /* Do not skip points outside border */ skip_if_outside = FALSE; break; case 'S': /* Get symbol [and size] */ symbol_type = argv[i][2]; if(symbol_type == 'e' || symbol_type == 'r') { 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); sscanf(strchr(&argv[i][3],'/')+1, "%lf/%d", &confidence, &fontsize); /* confidence scaling */ conrad = sqrt( -2.0 * log(1.0 - confidence)); } if(symbol_type == 'n' || symbol_type == 'x' ) scale = GMT_convert_units (&argv[i][3], GMT_INCH); if(symbol_type == 'w' && 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); sscanf(strchr(&argv[i][3],'/')+1, "%lf", &wedge_amp); } switch (symbol_type) { case 'e': symbol = CINE; read_ellipse = TRUE; break; case 'r': symbol = CINE; read_rotated_ellipse = TRUE; break; case 'n': symbol = ANISO; read_anisotropy = TRUE; break; case 'w': symbol = WEDGE; read_wedge = TRUE; break; case 'x': symbol = CROSS; read_cross = TRUE; break; default: error = TRUE; break; } break; case 'W': /* Set line attributes */ GMT_getpen (&argv[i][2], &pen); break; /* Illegal options */ default: /* Options not recognized */ error = TRUE; break; } } else n_files++; } /* Check that the options selected are mutually consistant */ no_size_needed = (read_ellipse || read_rotated_ellipse || read_anisotropy || read_cross || read_wedge ); error += GMT_check_rgb (pen.rgb) + GMT_check_rgb (fill.rgb) + GMT_check_rgb (efill.rgb) + GMT_check_rgb (gmtdefs.basemap_frame_rgb); /* Only one allowed */ if ((read_ellipse + read_rotated_ellipse + read_anisotropy + read_cross + read_wedge ) > 1) error = TRUE; if (!no_size_needed && (symbol > 1 && scale <= 0.0)) error = TRUE; if (rescale_sigma && ! (read_ellipse || read_wedge)) error = TRUE; if (argc == 1 || GMT_quick || error) { /* Display usage */ fprintf (stderr,"psvelo %s - Plot symbols on maps\n\n", GMT_VERSION); fprintf (stderr,"usage: psvelo -J -R [-B]\n"); fprintf (stderr, " [-G] [-H] [-K] [-L] [-N] [-O]\n"); fprintf (stderr, " [-P] [-S] [-U[/dx/dy/][