/*-------------------------------------------------------------------- * $Id: grdvector.c,v 1.4.4.2 2002/01/17 17:42:51 pwessel Exp $ * * Copyright (c) 1991-2002 by P. Wessel and W. H. F. Smith * See COPYING 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 General Public License as published by * the Free Software Foundation; version 2 of the License. * * 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 General Public License for more details. * * Contact info: gmt.soest.hawaii.edu *--------------------------------------------------------------------*/ /* grdvector reads 2 grdfiles that contains the 2 components of a vector field (cartesian or polar) and plots vectors at the grid positions. This is basically a short-hand for using grd2xyz | psxy -SV and is more convenient for such plots on a grid. Author: Paul Wessel Date: 12-JUN-1995 Revised: 15-FEB-2000 Version: 3.4.1 */ #include "gmt.h" float *r, *theta; main (int argc, char **argv) { int i, j, n = 0, nm, nx, ny, ij, i0, j0, di, dj, off; BOOLEAN convert_angles = FALSE, get_rgb = FALSE, cartesian = TRUE, shrink = FALSE, set_fill = FALSE; BOOLEAN error = FALSE, center = FALSE, outline = FALSE, azimuth = FALSE, stick_plot = TRUE, inc_set = FALSE; BOOLEAN clip = TRUE, got_fix_length = FALSE; char *file[2], *cpt, txt_a[32], txt_b[32], txt_c[32], unit = 0; double dx2, dy2, v_width = 0.03, h_length = 0.12, h_width = 0.1; double v_w, h_l, h_w, v_shrink, v_norm = 0.0, tmp, x, y, plot_x, plot_y, x_off, y_off; double west, east, south, north, x2, y2, scale = 1.0, fix_length = 0.0; double data_west, data_east, data_south, data_north, value, c, s; struct GRD_HEADER h[2]; struct GMT_FILL fill; struct GMT_PEN pen; GMT_init_pen (&pen, GMT_PENWIDTH); GMT_init_fill (&fill, -1, -1, -1); west = east = south = north = 0.0; di = dj = 1; i0 = j0 = 0; dx2 = dy2 = 0.0; argc = GMT_begin (argc, argv); for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { /* Common parameters */ case 'B': 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 '\0': error += GMT_get_common_args (argv[i], &west, &east, &south, &north); break; /* Supplemental parameters */ case 'A': cartesian = FALSE; break; case 'C': /* Vary symbol color with z */ cpt = &argv[i][2]; get_rgb = TRUE; break; case 'E': center = TRUE; break; case 'G': /* Set Gray shade for polygon */ if (GMT_getfill (&argv[i][2], &fill)) { GMT_fill_syntax ('G'); error++; } set_fill = TRUE; break; case 'I': /* Only use gridnodes dx2,dy2 apart */ GMT_getinc (&argv[i][2], &dx2, &dy2); inc_set = TRUE; break; case 'N': /* Do not clip at border */ clip = FALSE; break; case 'Q': if (argv[i][2] && argv[i][3] != 'n') { if (sscanf (&argv[i][2], "%[^/]/%[^/]/%s", txt_a, txt_b, txt_c) != 3) { fprintf (stderr, "%s: GMT SYNTAX ERROR -Q option: Could not decode arrowwidth/headlength/headwidth\n", GMT_program); error++; } else { 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); } } for (j = 2; argv[i][j] && argv[i][j] != 'n'; j++); if (argv[i][j]) { /* Normalize option used */ v_norm = atof (&argv[i][j+1]); if (v_norm > 0.0) { v_shrink = 1.0 / v_norm; shrink = TRUE; } else { fprintf (stderr, "%s: GMT SYNTAX ERROR -Qn option: No reference length given\n", GMT_program); error++; } } stick_plot = FALSE; break; case 'S': j = strlen (argv[i]) - 1; if (strchr ("cimpCIMP", (int)argv[i][j])) unit = argv[i][j]; if (argv[i][2] == 'l' || argv[i][2] == 'L') { got_fix_length = TRUE; fix_length = atof (&argv[i][3]); } else scale = atof (&argv[i][2]); break; case 'T': convert_angles = TRUE; break; case 'W': /* Set line attributes */ if (argv[i][2] && GMT_getpen (&argv[i][2], &pen)) { GMT_pen_syntax ('W'); error++; } outline = TRUE; break; case 'Z': azimuth = TRUE; break; default: error = TRUE; GMT_default_error (argv[i][1]); break; } } else if (n < 2) file[n++] = argv[i]; else n++; } if (argc == 1 || GMT_quick) { fprintf (stderr, "grdvector %s - Plot vector fields from grdfiles\n\n", GMT_VERSION); fprintf (stderr, "usage: grdvector compx.grd compy.grd -J -R [-A]\n"); fprintf (stderr, "\t[-B] [-C] [-E] [-G] [-I] [-K] [-O] [-P] [-Q] [-N] [-S[l]] [-T]\n"); fprintf (stderr, "\t[-U[