home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Science / Science.zip / gmt_os2.zip / src / gmt_orig.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-07  |  12.2 KB  |  304 lines

  1. /*--------------------------------------------------------------------
  2.  *    The GMT-system:    @(#)gmt.h    2.48  07 Aug 1995
  3.  *
  4.  *    Copyright (c) 1991-1995 by P. Wessel and W. H. F. Smith
  5.  *    See README file for copying and redistribution conditions.
  6.  *--------------------------------------------------------------------*/
  7. /*
  8.  * gmt.h is the main include file for the GMT-SYSTEM.  It contains definitions
  9.  * for several of the structures and parameters used by the programs
  10.  *
  11.  * Author:    Paul Wessel
  12.  * Date:    1-MAR-1991-1995
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <math.h>
  18. #include <string.h>
  19. #include <ctype.h>
  20. #include <memory.h>
  21. #include <pwd.h>
  22. #include <time.h>
  23. #include <sys/file.h>
  24. #include <sys/types.h>
  25.  
  26. #ifndef NeXT
  27. #include <values.h>
  28. #include <unistd.h>
  29. #endif
  30.  
  31. #ifdef sony
  32. typedef long time_t;
  33. #endif
  34.  
  35. #ifndef TRUE
  36. #define TRUE 1
  37. #endif
  38. #ifndef FALSE
  39. #define FALSE 0
  40. #endif
  41.  
  42. #define SMALL        1.0e-4    /* Needed when results aren't exactly zero but close */
  43. #define GMT_SMALL_CHUNK    50
  44. #define GMT_CHUNK    2000
  45. #define GMT_VERSION    "3.0"
  46. #define CNULL        ((char *)NULL)
  47.  
  48. #ifndef MIN
  49. #define MIN(x, y) (((x) < (y)) ? (x) : (y))    /* min and max value macros */
  50. #endif
  51. #ifndef MAX
  52. #define MAX(x, y) (((x) > (y)) ? (x) : (y))
  53. #endif
  54.  
  55. #ifdef _UNICOS
  56. #define copysign(x,y) ((y) < 0.0 ? -fabs(x) : fabs(x))
  57. #define log1p(x) log (1.0+(x))
  58. #endif
  59. #ifdef hpux
  60. #define copysign(x,y) ((y) < 0.0 ? -fabs(x) : fabs(x))
  61. #define log1p(x) log (1.0+(x))
  62. #endif
  63. #ifdef aux
  64. #define copysign(x,y) ((y) < 0.0 ? -fabs(x) : fabs(x))
  65. #define log1p(x) log (1.0+(x))
  66. #endif
  67. #ifdef ultrix
  68. #define copysign(x,y) ((y) < 0.0 ? -fabs(x) : fabs(x))
  69. #define log1p(x) log (1.0+(x))
  70. #endif
  71. #ifdef dgux
  72. #define log1p(x) log (1.0+(x))
  73. #endif
  74.  
  75. /* Safe math macros that check arguments */
  76.  
  77. #define d_sqrt(x) ((x) < 0.0 ? 0.0 : sqrt (x))
  78. #define d_acos(x) (fabs (x) >= 1.0 ? ((x) < 0.0 ? M_PI : 0.0) : acos (x))
  79. #define d_asin(x) (fabs (x) >= 1.0 ? copysign (M_PI_2, (x)) : asin (x))
  80. #define d_atan2(y,x) ((x) == 0.0 && (y) == 0.0 ? 0.0 : atan2 (y, x))
  81. #define d_log(x) ((x) <= 0.0 ? gmt_NaN : log (x))
  82. #define d_log10(x) ((x) <= 0.0 ? gmt_NaN : log10 (x))
  83. #define d_log1p(x) ((x) <= -1.0 ? gmt_NaN : log1p (x))
  84.  
  85. /* Macros for degree-based trig */
  86.  
  87. #define sind(x) sin ((x) * D2R)
  88. #define cosd(x) cos ((x) * D2R)
  89. #define tand(x) tan ((x) * D2R)
  90.  
  91. /* Macros for rint (nearest integer), ceil (next higher integer), and floor (next lower integer) */
  92.  
  93. #define irint(x) ((int)((x) < 0.0 ? (x) - 0.5 : (x) + 0.5))
  94. #define rint(x) ((double)irint((x)))
  95. #define ceil(x) ((double)(int)((x) < 0.0 || (x) == (int)(x) ? (x) : (x) + 1.0))
  96. #define floor(x) ((double)(int)((x) > 0.0 || (x) == (int)(x) ? (x) : (x) - 1.0))
  97.  
  98. /* Macros for swapping misc data types */
  99.  
  100. #define i_swap(x, y) {int tmp; tmp = x, x = y, y = tmp;}
  101. #define d_swap(x, y) {double tmp; tmp = x, x = y, y = tmp;}
  102. #define f_swap(x, y) {float tmp; tmp = x, x = y, y = tmp;}
  103.  
  104. /* Macro to detect a NaN */
  105.  
  106. #define bad_float(x) ((x) != (x))
  107.  
  108. /* Macro to create a NaN */
  109.  
  110. #ifdef __alpha
  111. #define mknan(x) (((unsigned int *) &x)[0] = 0x7fffffff, ((unsigned int *) &x)[1] = 0xffffffff)
  112. #endif
  113.  
  114. #ifdef sony
  115. #define mknan(x) (((unsigned long *) &x)[0] = 0x7ff7ffff, ((unsigned long *) &x)[1] = 0x7ff7ffff)
  116. #endif
  117.  
  118. #if !defined(mknan)
  119. #define mknan(x) (((unsigned long *) &x)[0] = 0x7fffffff, ((unsigned long *) &x)[1] = 0xffffffff)
  120. #endif
  121.  
  122. typedef int BOOLEAN;        /* BOOLEAN used for logical variables */
  123. typedef int (*PFI) ();        /* PFI declares a pointer to a function returning an int */
  124. typedef double (*PFD) ();    /* PFD declares a pointer to a function returning a double */
  125.  
  126. #include "gmt_project.h"    /* Define project_info and frame_info structures */
  127. #include "gmt_grd.h"        /* Define grd file header structure */
  128. #include "gmt_funcnames.h"    /* List of functions */
  129. #include "gmt_colors.h"        /* Defines color/shading global structure */
  130. #include "gmt_grdio.h"        /* Defines function pointers for grd i/o operations */
  131.  
  132. #define N_UNIQUE 49        /* Number of unique options */
  133. #define N_KEYS 55        /* Number of gmt defaults */
  134. #define N_FONTS 34        /* Number of fonts in the PS_font_names.h include file */
  135. #define HASH_SIZE 61        /* Used in get_gmtdefaults, should be ~> N_KEYS */
  136.  
  137. /* This structure contains default parameters for the GMT system */
  138.  
  139. #define N_ELLIPSOIDS 13
  140.  
  141. #include "pslib.h"
  142.  
  143. struct GMTDEFAULTS {
  144.     double anot_min_angle;        /* If angle between map boundary and anotation is less, no anot is drawn [20] */
  145.     int anot_font;            /* Font for anotations [Helvetica] */
  146.     int anot_font_size;        /* Font size for anotations in points [14] */
  147.     double anot_offset;        /* Distance between anotation and tickmarks [0.075] */
  148.     char basemap_axes[5];        /* Which axes to draw and annotate ["WESN"]  */
  149.     int basemap_frame_rgb[3];    /* Frame color rgb [(0,0,0) = black] */
  150.     int basemap_type;        /* Fancy (0) or plain (1) [0] */
  151.     int background_rgb[3];        /* Color of background [0/0/0] */
  152.     int foreground_rgb[3];        /* Color of foreground [255/255/255] */
  153.     int nan_rgb[3];            /* Color of NaNs [0/0/0] */
  154.     int color_image;        /* 0 = Adobe's colorimage, 1 = Tiles, 2 = RGB-separation */
  155.     int color_model;        /* 0 = RGB, 1 = HSV [0] */
  156.     char d_format[10];        /* Default double output format [%lg] */
  157.     int degree_format;        /* 0 = <0/360/-90/90>, 1 = <-180/180/-90/90>, 2 = <0/180/0/90>
  158.                        3 = 0E/180E/180W/0W/90S/90N> */
  159.     int dpi;            /* Dots pr. inch plotter resolution [300] */
  160.     int ellipsoid;            /* Which ellipsoid to use [0 = GRS 80] */
  161.     int frame_pen;            /* Pen thickness for map boundary [5] */
  162.     double frame_width;        /* Thickness of fancy map frame [0.075] */
  163.     double global_x_scale;        /* Scaling of x just before plotting [1] */
  164.     double global_y_scale;        /* Scaling of y just before plotting [1] */
  165.     double grid_cross_size;        /* Size of gridcrosses.  0 means draw continuous gridlines */
  166.     int grid_pen;            /* Pen thickness for gridlines [1] */
  167.     int header_font;        /* Font for headers [Helvetica] */
  168.     int header_font_size;        /* Font size for headers in points [36] */
  169.     double hsv_min_saturation;    /* For smallest or most negative intensity [1.0] */
  170.     double hsv_max_saturation;    /* For largest or most positive intensity [0.1] */
  171.     double hsv_min_value;        /* For smallest or most negative intensity [0.3] */
  172.     double hsv_max_value;        /* For largest or most positive intensity [1.0] */
  173.     int interpolant;        /* Choose between 0 (Linear), 1 (Akima), or 2 (Cubic spline) */
  174.     BOOLEAN io_header;        /* Input data has header records [FALSE] */
  175.     int n_header_recs;        /* number of header records [0] */
  176.     int label_font;            /* Font for labels [Helvetica] */
  177.     int label_font_size;        /* Font size for labels in points [24] */
  178.     BOOLEAN last_page;        /* If TRUE, terminate plot system when done [TRUE] */
  179.     double line_step;        /* Maximum straight linesegment length for arcuate lines */
  180.     double map_scale_factor;    /* Central mapscale factor, typically 0.9996 */
  181.     int measure_unit;        /* Choose 0 (cm), 1 (inch), or 2 (m) [1] */
  182.     int n_copies;            /* Number of copies pr plot [1] */
  183.     int n_lat_nodes;        /* No of points to use for drawing a latitudal line [50] */
  184.     int n_lon_nodes;        /* No of points to use for drawing a longitudal line [50] */
  185.     double dlon, dlat;        /* Corresponding increment in lon/lat */
  186.     int oblique_anotation;        /* Anotate all lon/lat marks (1),  or only longitudes on top/bottom boundary 
  187.                      * and latitudes on left/right boundary (0) [1] */
  188.     BOOLEAN overlay;        /* Make plot in overlay mode [FALSE] */
  189.     int page_rgb[3];        /* Color of the page [255/255/25 white] */
  190.     int page_orientation;        /* Orientation of page [0 = Landscape, 1 = Portrait] */
  191.     double paper_width;        /* Width of paper to plot on [8.5] */
  192.     double ps_heximage;        /* TRUE gives hex ps output image, FALSE gives binary image [TRUE] */
  193.     double tick_length;        /* Length of tickmarks [0.075] */
  194.     int tick_pen;            /* Pen thickness for tickmarks [2] */
  195.     BOOLEAN unix_time;        /* Plot time and map projection on map [FALSE] */
  196.     char unix_time_label[512];    /* Label to plot after time-stamp instead of command line */
  197.     double unix_time_pos[2];    /* Where to plot timestamp relative to origin */
  198.     double vector_shape;        /* 0.0 = straight vectorhead, 1.0 = arrowshape, with continuous range in between */
  199.     BOOLEAN verbose;        /* Give info during execution [FALSE] */
  200.     BOOLEAN want_euro_font;        /* Include re-encoding for European characters [TRUE] */
  201.     double x_axis_length;        /* Length of x-axis if no scale is given [8] */
  202.     double y_axis_length;        /* Length of y-axis if no scale is given [5] */
  203.     double x_origin;        /* x-origin of plot, i.e. where lower left corner plots on paper [1] */
  204.     double y_origin;        /* y-origin of plot, i.e. where lower left corner plots on paper [1] */
  205.     BOOLEAN xy_toggle;        /* TRUE means read/write I/O as lat/lon instead of lon/lat [FALSE] */
  206.     int y_axis_type;        /* Select y-axis with horizontal (0) or vertical (1) annotations  [0] */
  207.     struct ELLIPSOID {    /* Information about a particular ellipsoid */
  208.         /* Table taken from Snyder "Map projection - a working manual", p 12 Table 1 */
  209.         char name[20];
  210.         int date;
  211.         double eq_radius;
  212.         double pol_radius;
  213.         double flattening;
  214.     } ellipse[N_ELLIPSOIDS];    /* Ellipsoid parameters */
  215.     
  216. };
  217.  
  218. struct HASH {    /* Used to related keywords to gmtdefaults entry */
  219.     struct HASH *next;
  220.     int id;
  221.     char *key;
  222. };
  223.  
  224. struct PEN {    /* Holds pen attributes */
  225.     int width;
  226.     int r, g, b;
  227.     int offset;
  228.     char texture[20];
  229. };
  230.  
  231. struct FILL {    /* Holds fill attributes */
  232.     BOOLEAN use_pattern;
  233.     int r, g, b;
  234.     int pattern_no;
  235.     double icon_size;
  236.     BOOLEAN inverse;
  237.     char pattern[80];
  238. };
  239.  
  240. /* Global variables */
  241.  
  242. char *gmt_program;    /* Name of current GMT program */
  243. extern int oldargc;
  244. extern char *oldargv[];    /* Pointers to old common arguments */
  245.  
  246. /*    Current ellipsoid parameters */
  247.  
  248. extern double EQ_RAD, ECC, ECC2, ECC4, ECC6, M_PR_DEG;
  249.  
  250. extern struct GMTDEFAULTS gmtdefs;
  251. extern struct MAP_PROJECTIONS project_info;
  252. extern struct MAP_FRAME frame_info;
  253. extern struct THREE_D z_project;
  254.  
  255. extern char *gmt_unit_names[];
  256. extern double gmt_units[];
  257. extern double gmt_ppu[];        /* Points per measure unit */
  258. extern char *gmt_choice[];
  259. extern char *font_name[];
  260. extern double font_height[];
  261. extern char *unique_option[];
  262. extern char *gmt_keywords[];
  263. extern int gmt_days_of_month[];
  264.  
  265. /*    For I/O purposes */
  266.  
  267. extern PFI gmt_input, gmt_output;
  268. double gmt_data[BUFSIZ];
  269. double grd_in_nan_value, grd_out_nan_value;
  270.  
  271. /*    For plotting purposes */
  272.  
  273. extern double *gmt_x_plot;        /* Holds the x/y (inches) of a line to be plotted */
  274. extern double *gmt_y_plot;
  275. extern int *gmt_pen;            /* Pen (3 = up, 2 = down) for these points */
  276. extern int gmt_n_plot;            /* Number of such points */
  277. extern int gmt_n_alloc;            /* Current size of allocated arrays */
  278. extern int gmt_x_status_new;        /* Tells us what quadrant old and new points are in */
  279. extern int gmt_y_status_new;
  280. extern int gmt_x_status_old;
  281. extern int gmt_y_status_old;
  282. extern int gmt_corner;
  283. extern BOOLEAN gmt_world_map;        /* TRUE if map has 360 degrees of longitude range */
  284. extern BOOLEAN on_border_is_outside;    /* TRUE if a point exactly on the map border shoud be considered outside the map */
  285. extern double gmt_map_width;        /* Full width of this world map */
  286. extern double gmt_map_height;        /* Full height of this world map */
  287. extern double gmt_half_map_size;    /* Half width of this world map */
  288.  
  289.  
  290. extern PFI forward, inverse;        /*    Pointers to the selected mapping functions */
  291. extern PFI x_forward, x_inverse;    /*    Pointers to the selected linear functions */
  292. extern PFI y_forward, y_inverse;    /*    Pointers to the selected linear functions */
  293. extern PFI z_forward, z_inverse;    /*    Pointers to the selected linear functions */
  294. extern PFI outside;            /*    pointer to function checking if a lon/lat point is outside map */
  295. extern PFI crossing;            /*    pointer to functions returning crossover point at boundary */
  296. extern PFI overlap;            /*    pointer to function checking for overlap between 2 regions */
  297. extern PFI map_clip;            /*    pointer to functions that clip a polygon to fit inside map */
  298. extern PFD left_edge, right_edge;    /*    pointer to functions that returns the left,right edge of map */
  299. extern PFD scan_time_string;        /*    pointer to functions that converts timestring to secs */
  300.  
  301. extern BOOLEAN gmt_quick;        /* TRUE if short usage message is desired (must say program - ) */
  302.  
  303. extern double gmt_NaN;            /*    Holds IEEE not-a-number value    */
  304.