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