1 /* Copyright (C) 1988-2005 by Brian Doty and the Institute 2 of Global Environment and Society (IGES). 3 4 See file COPYRIGHT for more information. */ 5 6 /* Handling of missing data values. If SETMISS is 0, it is assumed 7 that missing data values will exactly match the value parsed from 8 the data description file (true on many machines). If SETMISS is 1, 9 a test is done for a small range (+-value/EPSILON) and if true the 10 value is set to exactly the missing data value when read. */ 11 12 /* kk 020624 --- change for 64bit seek K.Komine mf */ 13 14 #include <sys/types.h> 15 #include <stdio.h> 16 #include <stdlib.h> 17 #include <gabufr.h> 18 19 #define SETMISS 1 20 #define EPSILON 1e5 21 #define FUZZ_SCALE 1e-5 22 23 /* RPTNUM: Number of garpt blocks to allocate per memory block 24 BLKNUM: Max number of memory requests 25 A max of RPTNUM*BLKNUM stations can be held per request 26 27 Static memory usage is sizeof(pointer) * BLKNUM bytes */ 28 29 #define RPTNUM 200 30 #define BLKNUM 5000 31 32 #if GRADS_CRAY == 1 33 #define CPULIMSIG SIGCPULIM 34 #else 35 #ifdef __hpux 36 #define CPULIMSIG _SIGXCPU 37 #else 38 #define CPULIMSIG SIGXCPU 39 #endif 40 #endif 41 42 /*******************\ 43 * Data Structures * 44 \*******************/ 45 46 /* Pointer to data object */ 47 union gadata { 48 struct gagrid *pgr; 49 struct gastn *stn; 50 }; 51 52 /* Date/time structure. */ 53 struct dt { 54 int yr; 55 int mo; 56 int dy; 57 int hr; 58 int mn; 59 }; 60 61 /* Collection structure */ 62 struct gaclct { 63 struct gaclct *forw; /* Forward Pointer */ 64 struct gastn *stn; /* Pointer to station data */ 65 struct gastn *stn2; /* Pointer to station data */ 66 }; 67 68 /* Structure for info for the gxout "writegds" option, 69 for writing data for the use of the GDS */ 70 struct gawgds { 71 char *fname; /* File name to write */ 72 char *opts; /* User specified options */ 73 }; 74 75 /* info for LATS */ 76 struct galats { 77 78 /*=== lats_parmtab ===*/ 79 char ptname[256]; /* parameter file name */ 80 81 /*=== lats_create ===*/ 82 int convention; /* data convention (enum) */ 83 int frequency; /* data frequency (enum) e.g., hourly */ 84 int calendar; /* calendar of the time model (enum) e.g., standard */ 85 int deltat; /* number of time units between outputs, e.g., 12 for every 12 h */ 86 char model[256]; /* model COMMENT */ 87 char center[32]; /* data source which is the GRIB PROCESS ! NOT the GRIB CENTER */ 88 char comment[256]; /* comment on data set which will go into the title of the .ctl file */ 89 char oname[256]; /* name of the output file (dset) */ 90 91 /*=== lats_basetime ===*/ 92 int lyr; /* lats basetime year */ 93 int lmo; /* lats basetime month */ 94 int lda; /* lats basetime day */ 95 int lhr; /* lats basetime hour */ 96 97 /*=== lats_vertdim ===*/ 98 char vertdimname[32]; /* name of the vertial dimension */ 99 double levels[128]; /* vertical levels MAX IS 128!!!*/ 100 int nlev; /* number of levels */ 101 102 /*=== lats_grid ===*/ 103 int gridtype; /* grid type (enum), calculated in GrADS except when LATS_GAUSSIAN */ 104 char gridname[32]; /* name of the vertial dimension */ 105 int ilinear; /* linearity of the grid in x */ 106 int jlinear; /* linearity of the grid in y */ 107 int nlon; /* # of points in x */ 108 int nlat; /* # of points in y */ 109 float lon_1; /* starting longitide */ 110 float lat_1; /* starting latitude */ 111 float lon_nlon; /* ending longitude */ 112 float lat_nlat; /* ending latitude */ 113 114 /*=== lats_var ===*/ 115 char var[32]; /* variable name */ 116 char var_comment[256]; /* variable name */ 117 int timestat; /* variable time statistic (enum) */ 118 119 /*=== lats_write ===*/ 120 double varlev; /* level value of the variable for lats_write*/ 121 122 /*--- time options ---*/ 123 int time_opt; /* 0 - grid relative ; 1 - dimension environment relative ; 2 - set time using baset time ; 3 - forecast hourly */ 124 int fhour; /* forecast hour if using lats forecast_hourly */ 125 126 /*--- internal id's to pass to the lats routines ---*/ 127 int id_file; 128 int id_lev; 129 int id_grid; 130 int id_var; 131 int id_user_file; 132 int id_user_var; 133 int id_user_grid; 134 int id_user_lev; 135 int id_user_write; 136 }; 137 138 139 /*mf 9612105 Contains global information for Mike Fiorino and Gary Love 980114 mf*/ 140 141 struct gamfcmn { 142 int cal365 ; /* 365 (no leap year) calendar */ 143 int fullyear ; /* 1 - must specify full year 0 old default */ 144 int warnflg; /* warning level flag for messages */ 145 int winid; /* Window ID */ 146 int winx; /* Window X position (upper left) */ 147 int winy; /* Window Y position (upper left) */ 148 unsigned int winw; /* Window width */ 149 unsigned int winh; /* Window height */ 150 unsigned int winb; /* Window border width */ 151 152 }; 153 154 /* Contains information about the user interface and graphics output. */ 155 struct gacmn { 156 157 struct gawgds *wgds; /* Pointer to gds output structure */ 158 int hbufsz; /* Metafile buffer size */ 159 int pass; /* Number of passes since last clear */ 160 int gpass[10]; /* Number of passes for each gx type */ 161 int loopdim; /* Looping dimension */ 162 int loopflg; /* Looping on or off */ 163 float loopincr; /* Looping increment */ 164 165 struct gafile *pfi1; /* Pointer to first gafile in chain */ 166 struct gafile *pfid; /* Pointer to default gafile */ 167 int fnum; /* File count */ 168 int dfnum; /* Default file number */ 169 int fseq; /* Unique sequence num for files opened */ 170 171 struct gadefn *pdf1; /* Pointer to first define block */ 172 173 float dmin[3],dmax[3]; /* Current absolute coordinate limits */ 174 struct dt tmin,tmax; 175 int vdim[4]; /* Which dimensions vary? */ 176 int x1ex,x2ex,y1ex,y2ex; /* For -ex flag on fwrite */ 177 int xexflg,yexflg; /* -ex -- are dims valid? */ 178 179 float pxsize,pysize; /* Physical page size in inches */ 180 int orient; /* Page orientation */ 181 int vpflag; /* If 1, virtual page being used */ 182 float xsiz,xsiz1,xsiz2; /* Physical plotting size in X direction */ 183 float ysiz,ysiz1,ysiz2; /* Physical plotting size in Y direction */ 184 int paflg; /* User has specified plotting area */ 185 float pxmin,pxmax; /* User specified plotting area */ 186 float pymin,pymax; 187 float aspect; /* User specified aspect ratio */ 188 189 int clab; /* control contour labels. */ 190 int clskip; /* Contour label skipping */ 191 char *clstr; /* Contour label template */ 192 float rainmn,rainmx; /* control rainbow colors */ 193 int rbflg; /* User rainbow colors specified */ 194 int rbcols[100]; /* User rainbow colors */ 195 196 float cmin,cmax,cint; /* User specified contour limits */ 197 int cflag; /* If true, user specifies contour levels*/ 198 float clevs[100]; /* User specified contour levels */ 199 int ccflg; /* If true, user specifies contour colors*/ 200 int ccols[100]; /* User specified contour colors */ 201 int shdcls[120]; /* Shade colors after shading */ 202 float shdlvs[120]; /* Shade levels */ 203 int shdcnt; /* Number of shdlvs, shdcls */ 204 int ccolor,cstyle; /* User contour/line appearance */ 205 int cthick; /* User gx display line thickness */ 206 int cmark; /* Line marker type */ 207 int csmth; /* Contour smoothing on or off */ 208 int cterp; /* Spline fit on or off */ 209 float rmin,rmax,rint; /* Axis limits for 1-D plots */ 210 float rmin2,rmax2,rint2; /* Axis limits for 1-D plots */ 211 int aflag,aflag2; /* Keep 1D axis limits fixed */ 212 int grflag,grstyl,grcolr; /* Grid flag, linestyle, color */ 213 int dignum; /* grid value plot control (gxout=grid) */ 214 float digsiz; 215 int arrflg; /* Use already set arrow scaling */ 216 float arrsiz; /* Arrow size in inches */ 217 int arlflg; /* Arrow label flag */ 218 float arrmag; /* Vector magnitude producing arrsiz arrw*/ 219 float ahdsiz; /* Arrow head size. */ 220 int hemflg; /* -1; auto 0; nhem 1; shem */ 221 int miconn; /* Connect line graph accross missing */ 222 int strmden; /* Streamline density indicator */ 223 int mdlblnk,mdldig3; /* Station model plot opts */ 224 225 char *prstr; /* Format string for gxout print */ 226 int prlnum; /* Number of values per record */ 227 int prbnum; /* Number of blanks to add between values */ 228 int prudef; /* Undef printed as "undef" or value */ 229 230 int fgvals[50]; /* Values for grid fill */ 231 int fgcols[50]; 232 int fgcnt; 233 234 int gridln; /* Line attributes for gxout grid */ 235 236 int stidflg; /* Plot station ids with values */ 237 238 float axmin,axmax,axint; /* Overrides for X-axis labels */ 239 float aymin,aymax,ayint; /* Overrides for Y-axis labels */ 240 int axflg, ayflg; /* Is override in effect for the axis? */ 241 int frame; /* Display frame? */ 242 243 int rotate; /* Rotate plot from default orientation */ 244 int xflip, yflip; /* Flip X or Y axes */ 245 int zlog; /* Z coordinate in log scale */ 246 int coslat; /* Lat coordinate scaled as cos lat */ 247 248 int mproj; /* Map projection -- used for X,Y plot */ 249 /* only. 0 = no map. */ 250 int mpdraw; /* Draw map outline - 0=no */ 251 float mpvals[10]; /* Map projection option values. */ 252 int mpflg; /* Map projection option values are set. */ 253 char *mpdset[8]; /* Map data set names. */ 254 int mpcols[256]; /* Map Color array */ 255 int mpstls[256]; /* Map line styles array */ 256 int mpthks[256]; /* Map line widths array */ 257 int mapcol,mapstl,mapthk; /* Default map color, style, thickness */ 258 259 int gout0; /* Graphics output type for stat. */ 260 int gout1; /* Graphics output type for 1-D. */ 261 int gout1a; /* Graphics output type for 1-D. */ 262 int gout2a; /* Graphics output type for 2-D. */ 263 int gout2b; /* Graphics output type for 2-D. */ 264 int goutstn; /* Graphics output type for stns */ 265 266 int blkflg; /* Leave certain values black when shadng*/ 267 float blkmin, blkmax; /* Black range */ 268 269 int reccol,recthk; /* Draw Rectangle color, brdr thickness */ 270 int lincol,linstl,linthk; /* Draw line color, style, thickness */ 271 int mcolor; /* auto color (orange or grey) */ 272 int strcol,strthk,strjst; /* Draw string color, thckns, justifictn */ 273 float strrot; /* Draw string rotation */ 274 float strhsz,strvsz; /* Draw string hor. size, vert. size */ 275 int anncol,annthk; /* Draw title color, thickness */ 276 int grflg; /* Grey Scale flag */ 277 int devbck; /* Device background */ 278 int xlcol,xlthck,ylcol,ylthck,clcol,clthck; /* color, thickness */ 279 int xlside,ylside,ylpflg; 280 float xlsiz,ylsiz,clsiz,xlpos,ylpos,yllow; /* Axis lable size */ 281 float xlevs[50],ylevs[50]; /* User specified x/y axis labels */ 282 int xlflg,ylflg; /* Number of user specified labels */ 283 int xtick,ytick; /* Number of extra tick marks */ 284 float xlint,ylint; /* User specified label increment */ 285 char *xlstr, *ylstr; /* user substitution string for labels */ 286 int xlab,ylab; /* Axis label options */ 287 char *xlabs, *ylabs; /* User specifies all labels */ 288 int ixlabs, iylabs; /* Count of user labels */ 289 int tlsupp; /* Suppress year or month of time labels */ 290 int lfc1,lfc2; /* Linefill colors */ 291 int wxcols[5]; /* wx symbol colors */ 292 int wxopt; /* wx options */ 293 int tser; /* station time series type */ 294 295 int bargap; /* Bar Gap in percent */ 296 int barolin; /* Bar outline flag */ 297 float barbase; /* Bar Base Value */ 298 int barflg; /* Bar flag: 1, use base value */ 299 /* 0, draw from plot base */ 300 /* -1, draw from plot top */ 301 302 int btnfc,btnbc,btnoc,btnoc2; /* Current button attributes */ 303 int btnftc,btnbtc,btnotc,btnotc2; 304 int btnthk; 305 306 int dlgfc,dlgbc,dlgoc; /* Current dialog attributes */ 307 int dlgpc,dlgth,dlgnu; 308 309 int drvals[15]; /* Attributes for drop menus */ 310 311 FILE *ffile; /* grads.fwrite file handle */ 312 char *fwname; /* fwrite file name */ 313 int fwenflg; /* fwrite byte order control */ 314 int fwsqflg; /* fwrite stream vs fortran seq */ 315 int fwappend; /* write mode (1): append */ 316 int fwexflg; /* fwrite exact grid dims */ 317 318 int grdsflg; /* Indicate whether to put grads atrib. */ 319 320 int timelabflg; /* Indicate whether to put cur time atrib. */ 321 322 int stnprintflg; /* Indicate whether to put cur time atrib. */ 323 324 int dbflg; /* Double buffer mode flag */ 325 326 int batflg; /* Batch mode */ 327 328 int numgrd,relnum; /* Number of data objects held */ 329 int type[16]; /* Data type of each data object */ 330 union gadata result[16]; /* Pointers to held data objects */ 331 struct gaclct *clct[32]; /* Anchor for collection */ 332 int clctnm[32]; /* Number of items collected */ 333 int clcttp[32]; /* Varying dimension of collection */ 334 335 int lastgx; /* Last gx plotted */ 336 int xdim, ydim; /* Which dimensions on X and Y axis */ 337 /* Grid-to-world conversion info follows */ 338 339 float (*xgr2ab) (float *, float); 340 float (*ygr2ab) (float *, float); 341 float (*xab2gr) (float *, float); 342 float (*yab2gr) (float *, float); 343 float *xgrval; 344 float *ygrval; 345 float *xabval; 346 float *yabval; 347 int statflg; /* stat txt output on all displays */ 348 int impflg; /* Implied run flag */ 349 char *impnam; /* Implided run script name */ 350 int impcmd; /* Implicit run */ 351 int sig; /* User has signalled */ 352 int ptflg; /* Pattern fill flag */ 353 int ptopt; /* Pattern option: */ 354 /* 0, open */ 355 /* 1, solid */ 356 /* 2, dot */ 357 /* 3, line */ 358 int ptden; /* Dot or line pattern density */ 359 int ptang; /* Line pattern angle */ 360 int dwrnflg; /* Issue, or not, warnings about missing/ 361 constant data */ 362 struct galats glats ; /* LATS option struct */ 363 }; 364 365 /* Sructure for string substitution in templating -- the %ch template. 366 This forms a linked list chained from pchsub1 in gafile */ 367 struct gachsub { 368 struct gachsub *forw; /* Forward pointer */ 369 int t1; /* First time for this substitution */ 370 int t2; /* Last time. -99 indicates open ended */ 371 char *ch; /* Substitution string */ 372 }; 373 374 /* GA status structure. Contains necessary info about the scaling 375 and file structure in force. */ 376 377 struct gastat { 378 struct gafile *pfi1; /* Pointer to first gafile in chain */ 379 struct gafile *pfid; /* Pointer to default gafile */ 380 int fnum; /* Default file number */ 381 struct gadefn *pdf1; /* Pointer to first define block */ 382 struct gaclct **pclct; /* Pointer to the collection pointers */ 383 union gadata result; /* Result goes here */ 384 int type; /* Result type (grid or stn) */ 385 int idim,jdim; /* Varying dimensions */ 386 float dmin[3],dmax[3]; /* Range of absolute dimensions */ 387 struct dt tmin,tmax; 388 }; 389 390 391 /* Description of a data file. */ 392 393 /* This is to define the pointer added at the end of the gafile structure */ 394 /* -hoop, 95/07/10 and 95/11/10 */ 395 #if USESDF == 1 396 #include "gasdf.h" 397 #endif 398 399 struct gafile { 400 401 struct gafile *pforw; /* Forward pointer to next gafile block. 402 List is anchored within gastat. */ 403 int fseq; /* Unique sequence number for cache 404 detection */ 405 char name[4096]; /* File name or DODS URL */ 406 char *tempname; /* File name of open file (different with templates) */ 407 char dnam[4096]; /* Descriptor file name */ 408 char *mnam; /* Map(index) file name */ 409 FILE *infile; /* File pointer. */ 410 int type; /* Type of file: 1 = grid 411 2 = simple station 412 3 = mapped station 413 4 = defined grid */ 414 char title[512]; /* Title -- describes the file. */ 415 float undef; /* Global undefined value for this file */ 416 float ulow,uhi; /* Undefined limits for SETMISS test */ 417 float *rbuf; /* Buffer for file I/O equal in length 418 to one grid row in the file, or equal 419 in length to the size needed to hold 420 the largest station report */ 421 char *pbuf; /* Same as rbuf, for unpacking */ 422 char *bbuf; /* Same as rbuf, for bit map I/O */ 423 int bswap; /* Byte swapping needed */ 424 int dhandle; /* libgadods file handle. this is bad 425 usage but avoids an include 426 problem with gadods.h. */ 427 int dodinf[5]; /* pointer to coordinate variable indices 428 (first four elements are lon,lat,lev,time 429 fifth is station id) 430 for dods station data only */ 431 int mtype; /* Stn map file type */ 432 int *tstrt; /* Pointer to list length dnum[3] of 433 start points of times in the file */ 434 int *tcnt; /* Count of stns for assctd time */ 435 int stcnt; /* Count of mapped stids when stn data 436 and map file is type stidmap. */ 437 int stpos; /* Position in map file of start of 438 stid info for map file type stidmap. */ 439 FILE *mfile; /* File pointer to stidmap file */ 440 int dnum[4]; /* Dimension sizes for this file. */ 441 int tlpflg; /* Circular file flag */ 442 int tlpst; /* Start time offset in circular file */ 443 int vnum; /* Number of variables. */ 444 int ivnum; /* Number of level independent variables 445 for station data file */ 446 int lvnum; /* Number of level dependent variables 447 for station data file */ 448 struct gavar *pvar1; /* Pointer to an array of structures. 449 Each structure in the array has info 450 about the specific variable. */ 451 long gsiz; /* Number of elements in a grid (x*y) */ 452 /* This is for actual grid on disk, 453 not psuedo grid (when pp in force) */ 454 long tsiz; /* Number of elements in an entire time 455 group (all variables at all levels 456 for one time). */ 457 int trecs; /* Number of records (XY grids) per time 458 group. */ 459 long fhdr; /* Number of bytes to ignore at file head*/ 460 int wrap; /* The grid globally 'wraps' in X */ 461 int seqflg, yrflg, zrflg; /* Format flags */ 462 int ppflag; /* Pre-projected data in use */ 463 int ppwrot; /* Pre-projection wind rotation flag */ 464 int ppisiz, ppjsiz; /* Actual size of preprojected grid */ 465 float ppvals[20]; /* Projection constants for pre-projected 466 grids. Values depend on projection. */ 467 int *ppi[9]; /* Pointers to offsets for pre-projected 468 grid interpolation */ 469 float *ppf[9]; /* Pointers to interpolation constants 470 for pre-projected grids */ 471 float *ppw; /* Pointer to wind rotation array */ 472 float (*gr2ab[3]) (float *, float); 473 /* Addresses of routines to do conversion 474 from grid coordinates to absolute 475 coordinates for X, Y, Z. All Date/time 476 conversions handled by gr2t. */ 477 float (*ab2gr[3]) (float *, float); 478 /* Addresses of routines to do conversion 479 from absolute coordinates to grid 480 coordinates for X,Y,Z. All date/time 481 conversions handled by t2gr. */ 482 float *grvals[4]; /* Pointers to conversion information for 483 grid-to-absolute conversion routines. */ 484 float *abvals[4]; /* Pointers to conversion information for 485 absolute-to-grid conversion routines. */ 486 int linear[4]; /* Indicates if a dimension has a linear 487 grid/absolute coord transformation 488 (Time coordinate always linear). */ 489 int dimoff[4]; /* Dimension offsets for defined grids */ 490 int climo; /* Climatological Flag (defined grids) */ 491 int cysiz; /* Cycle size for climo grids */ 492 int idxflg; /* File records are indexed */ 493 int grbgrd; /* GRIB Grid type */ 494 struct gaindx *pindx; /* Index Strucure if indexed file */ 495 int tmplat; /* File name template */ 496 int *fnums; /* File number for each time */ 497 int fnumc; /* Current file number that is open */ 498 struct gachsub *pchsub1; /* Pointer to first %ch substitution */ 499 int errcnt; /* Current error count */ 500 int errflg; /* Current error flag */ 501 int ncflg; /* 1==dtype netcdf 2==dtype hdfsds 3==sdf/xdf dataset */ 502 int ncid; /* netcdf file id */ 503 int sdid; /* hdf-sds file id */ 504 int packflg; /* Data are packed with scale and offset values */ 505 int undefattrflg; /* Undefined values are retrieved individually */ 506 char *scattr; /* scale factor attribute name for unpacking data */ 507 char *ofattr; /* offset attribute name for unpacking data */ 508 char *undefattr; /* undef attribute name */ 509 long xyhdr; /* Number of bytes to ignore at head of xy grids*/ 510 long thdr; /* Number of bytes to ignore at head of time chunk*/ 511 int calendar; /* Support for 365-day calendars */ 512 int cray_ieee; /* Support 32-bit IEEE data on cray */ 513 int bufrflg; /* 1==dtype bufr */ 514 struct bufrinfo *bufrinfo; /* x,y pairs from descriptor file */ 515 gabufr_dset *bufrdset; /* pointer to parsed bufr data */ 516 struct gaattr *attr; /* pointer to link list of attribute metadata */ 517 518 /* Use of this with the ifdef has implications for checkpoint/restart, */ 519 /* as it changes the size of the gafile structure. -hoop 95/07/10 */ 520 #if USESDF == 1 521 IO_STD *sdf_ptr ; /* Pointer to SDF file structure */ 522 int is_a_SDF ; 523 IO_STD *first_sdf_ptr ; /* used for time series templating */ 524 #endif 525 526 }; 527 528 /* Structure that describes a grid (requestor or descriptor block). */ 529 struct gagrid { 530 float *grid; /* Address of the grid. */ 531 struct gafile *pfile; /* Address of the associated gafile 532 structure to get the data from 533 (requestor block only) */ 534 float undef; /* Undefined value for this grid. */ 535 float rmin,rmax; /* Minimum/Maximum grid value 536 (rmin is set to the grid value when 537 isiz=jsiz=1. *grid points to here.) */ 538 int isiz,jsiz; /* isiz = number of elements per row. 539 jsiz = number of rows. */ 540 int idim,jdim; /* Dimension of rows and columns. 541 -1 = This dimension does not vary 542 1 = X dimension (usually longitude) 543 2 = Y dimension (usually lattitude) 544 3 = Z dimension (usually pressure) 545 4 = Time 546 If both dimensions are -1, then the 547 grid has one value, which will be 548 placed in rmin. */ 549 int iwrld, jwrld; /* World coordinates valid? */ 550 int dimmin[4],dimmax[4]; /* Dimension limits for each dimension 551 (X,Y,Z,T) in grid units. */ 552 struct gavar *pvar; /* Pointer to the structure with info 553 on this particular variable. If 554 NULL, this grid is the result of 555 an expression evaluation where the 556 variable type is unkown. */ 557 char *exprsn; /* If grid is a 'final' result, this 558 will point to a character string that 559 contains the original expression. */ 560 int alocf; /* Scaling info allocated for us only */ 561 float (*igrab) (float *, float); 562 float (*jgrab) (float *, float); 563 /* Addresses of routines to perform 564 grid-to-absolute coordinate 565 transforms for this grid's i and j 566 dimensions (unless i or j = 3). */ 567 float (*iabgr) (float *, float); 568 float (*jabgr) (float *, float); 569 /* Absolute to grid conversion routines */ 570 float *ivals, *jvals; /* Pointers to conversion info for the 571 grid to abs conversion routines */ 572 float *iavals, *javals; /* Conversion info for abs to grid */ 573 int ilinr,jlinr; /* Indicates if linear transformation */ 574 }; 575 576 /* Structure that contains attribute metadata */ 577 struct gaattr { 578 struct gaattr *next; /* Address of next attribute */ 579 char *varname; /* Name of variable or 'global' */ 580 char *name; /* Name of attribute -- e.g. "units" */ 581 char *type; /* Type of attribute -- e.g. "String", "Float32", etc. */ 582 char value[512]; /* Attribute value -- strings may contains blanks. */ 583 }; 584 585 /* Structure that contains the x,y pairs for bufr time values */ 586 struct bufrtimeinfo { 587 int yrxy[2]; 588 int moxy[2]; 589 int dyxy[2]; 590 int hrxy[2]; 591 int mnxy[2]; 592 int scxy[2]; 593 }; 594 595 /* Structure that contains the x,y pairs for file-wide bufr variables */ 596 struct bufrinfo { 597 int lonxy[2]; 598 int latxy[2]; 599 int levxy[2]; 600 int stidxy[2]; 601 struct bufrtimeinfo base,offset; /* structures for base and offset time values */ 602 }; 603 604 /* Structure that contains the header (coordinate) info for a gabufr_msg */ 605 struct bufrhdr { 606 double lon; 607 double lat; 608 double lev; 609 double sec,offsec; 610 char stid[8]; 611 struct dt tvals,toffvals; 612 }; 613 614 /* Structure that describes a report header in a stn file */ 615 struct rpthdr { 616 char id[8]; /* Character station id */ 617 float lat; /* Latitude of report */ 618 float lon; /* Longitude of report */ 619 float t; /* Time in relative grid units */ 620 int nlev; /* Number of levels following */ 621 int flag; /* Level independent var set flag */ 622 }; 623 624 /* Structure that describes a stid info block within a stidmap file */ 625 struct stninf { 626 char stid[8]; 627 int offset; 628 int rcnt; 629 }; 630 631 /* Structure that describes a single report */ 632 struct garpt { 633 struct garpt *rpt; /* Address of next report */ 634 char stid[8]; /* Station id */ 635 float lat,lon,lev,tim; /* Location of station */ 636 int work; /* Work area */ 637 float val; /* Value of variable */ 638 }; 639 640 /* Structure that describes a collection of station reports. */ 641 struct gastn { 642 struct garpt *rpt; /* Address of start of link list */ 643 int rnum; /* Number of reports. */ 644 struct garpt *blks[BLKNUM]; /* ptrs to memory holding rpts */ 645 struct gafile *pfi; /* Address of the associated gafile 646 structure to get the data from 647 (requestor block only) */ 648 float undef; /* Undefined value for this data. */ 649 float smin, smax; /* Min and Max values for this data */ 650 int idim,jdim; /* Varying dimensions for this data 651 -1 = This dimension does not vary 652 1 = X dimension (longitude) 653 2 = Y dimension (lattitude) 654 3 = Z dimension (pressure) 655 4 = Time */ 656 float dmin[3],dmax[3]; /* Dimension limits for each dimension 657 (X,Y,Z) in world coords. 658 Non-varying dimensions can have 659 limits in this structure. */ 660 int rflag; /* Get stations within specified radius in 661 degrees of fixed lat and lon */ 662 float radius; /* Radius */ 663 int sflag; /* Get specific station */ 664 char stid[8]; /* Station id to get */ 665 int tmin,tmax; /* Grid limits of time */ 666 float ftmin,ftmax; /* Float-valued grid limits of time, 667 equivalent to dmin[3],dmax[3] */ 668 float *tvals; /* Pointer to conversion info for the 669 time conversion routines. */ 670 struct gavar *pvar; /* Pointer to the structure with info 671 on this particular variable. If 672 NULL, this grid is the result of 673 an expression evaluation where the 674 variable type is unkown. */ 675 struct garpt **prev; /* Used for allocating rpt structures */ 676 struct garpt *crpt; 677 int rptcnt,blkcnt; 678 }; 679 680 /* Structure that describes a variable in a file. These structures 681 are built in arrays that are hung off of gafile structures. */ 682 struct gavar { 683 char varnm[128]; /* Variable name. */ 684 char abbrv[16]; /* Variable abbreviation. */ 685 char *longnm; /* netcdf/hdf var name if different */ 686 int units[16]; /* Units indicator. */ 687 int offset; /* Offset in grid elements of the start 688 of this variable within a time group 689 within this file. */ 690 int recoff; /* Record (XY grid) offset of the start 691 of this variable within a time group */ 692 int ncvid; /* netcdf vid for this variable */ 693 int sdvid; /* netcdf vid for this variable */ 694 int levels; /* Number of levels for this variable. 695 0 is special and indiates one grid is 696 available for the surface only. */ 697 int dfrm; /* format type indicator 698 1 - unsigned char 699 4 - int */ 700 int var_t ; /* variable t transform */ 701 int var_z ; /* variable z transform */ 702 int y_x ; /* x-y transform */ 703 float scale; /* scale factor for unpacking data */ 704 float add; /* offset value for unpacking data */ 705 float undef; /* undefined value */ 706 int vecpair; /* Variable has a vector pair */ 707 int isu; /* Variable is the u-component of a vector pair */ 708 }; 709 710 /* Structure that describes a function call. */ 711 struct gafunc { 712 int argnum; /* Number of arguments found by fncprs */ 713 char *argpnt[20]; /* Pointers to the argument strings */ 714 char buff[1000]; /* Argument string buffer */ 715 }; 716 717 /* Structure that describes a user defined function */ 718 struct gaufb { 719 struct gaufb *ufb; /* Forward pointer */ 720 char name[8]; /* Function name */ 721 int alo,ahi; /* Limits on number of args */ 722 int atype[8]; /* Types of args. 0=expr,1=float,2=int,3=char */ 723 int sflg; /* Sequential or direct */ 724 char *fname; /* Name of user executable */ 725 char *oname; /* File name for data transfer to user */ 726 char *iname; /* File name for data transfer from user */ 727 }; 728 729 /* Structure that describes a defined grid */ 730 struct gadefn { 731 struct gadefn *pforw; /* Linked list pointer */ 732 struct gafile *pfi; /* File Structure containing the data */ 733 char abbrv[20]; /* Abbreviation assigned to this */ 734 }; 735 736 /* Stack to evaluate the expression. The stack consists of an 737 array of structures. */ 738 struct smem { 739 int type; /* Entry type: -2 stn,-1 grid,1=op,2='(',3=')' */ 740 union sobj { 741 int op; /* Operator: 0=*, 1=/, 2=+ */ 742 struct gagrid *pgr; /* Operand (grid or stn) */ 743 struct gastn *stn; 744 } obj; 745 }; 746 747 /* Index structure, for when the records in a data file are indexed. 748 The indexing file will contain this structure at the front, followed 749 by the specified number of header and indexing values. These 750 header and indexing values are file format specific. */ 751 752 struct gaindx { 753 int type; /* Indexing file type */ 754 int hinum; /* Number of ints in header */ 755 int hfnum; /* Number of floats in header */ 756 int intnum; /* Number of index ints (long) */ 757 int fltnum; /* Number of index floats */ 758 int *hipnt; /* Pointer to header int values */ 759 float *hfpnt; /* Pointer to header float values */ 760 int *intpnt; /* Pointer to int index values */ 761 float *fltpnt; /* Pointer to float index values */ 762 } ; 763 764 765 /***********************\ 766 * Function Prototypes * 767 \***********************/ 768 769 /* Functions in GRADS.C */ 770 771 void gasig (int); 772 int gaqsig (void); 773 774 /* Functions in GAUSER: 775 gacmd: Process a user command 776 gacln: Reset variables 777 gaenab: Process an enable command 778 gadraw: Process a draw command 779 gadef: Process a define command 780 gaudef: Process undefine command 781 gamodf: Modify defined grid 782 gaqury: Process a query command 783 gahelp: Process a help command 784 gaset: Process the SET command 785 gadspl: Process a display command 786 gapars: Parse a compound expression for gadspl 787 gagrel: Release all held grids 788 gaopen: Open a data file from a descriptor file 789 cleanup: Clean up an input record 790 gaprnt: Process output messages 791 prntgaattr: Print out a descriptor attribute 792 gagsdo: Execute command for a script 793 getpst: Allocate and initialize a gastat block */ 794 795 void gainit (void); 796 797 int gacmd (char *, struct gacmn *, int); 798 void gacln (struct gacmn *,int); 799 int gaenab (char *, struct gacmn *); 800 int gadraw (char *, struct gacmn *); 801 int gardrw (char *, struct gacmn *); 802 int gaexec (char *, struct gacmn *); 803 char *gagsdo (char *, int *); 804 int gadef (char *, struct gacmn *, int); 805 int gaudef (char *, struct gacmn *); 806 int gamodf (char *, struct gacmn *); 807 int gaqdef (char *, struct gacmn *, int); 808 int gaqury (char *, char *, struct gacmn *); 809 int gahelp (char *, struct gacmn *); 810 int gaset (char *, char *, struct gacmn *); 811 int gacoll (char *, struct gacmn *); 812 int gadspl (char *, struct gacmn *); 813 int gaspcl (char *, struct gacmn *); 814 int gapars (char *, struct gastat *, struct gacmn *) ; 815 void gagrel (struct gacmn *); 816 int gaopen (char *, struct gacmn *); 817 void cleanup (char *); 818 struct gastat *getpst (struct gacmn *); 819 void gaprnt (int, char *); 820 int prntgaattr (struct gafile *, char *, int, int); 821 822 int gaddes (char *, struct gafile *, int); 823 int deflin (char *, struct gafile *, int, int); 824 int deflev (char *, char *, struct gafile *, int); 825 int ddfattr (char *, struct gafile *); 826 struct gafile *getpfi (void); 827 void frepfi (struct gafile *, int); 828 829 /* Functions in GAEXPR: 830 gaexpr: Evaluate an expression by creating a stack 831 eval: Process the expression stack 832 gaoper: Perforam operation between two operands 833 gagrop: Perform a grid operation 834 gastop: Perform a station operation 835 gascop: Perform an op between a constant and stations 836 gagrvl: Put a constant in grid format 837 varprs: Parse a variable in the expression 838 getdfn: Search defined grid chain for a predifined grid 839 gagchk: Check validity of operation between two grids 840 stnvar: Handle specialized parsing of stn variable */ 841 842 int gaexpr (char *, struct gastat *) ; 843 int eval (int, struct smem *, int *); 844 int gaoper (struct smem *, int, int, int, int); 845 struct gagrid *gagrop (struct gagrid *, struct gagrid *, int, int); 846 struct gastn *gastop (struct gastn *, struct gastn *, int, int); 847 struct gastn *gascop (struct gastn *, float, int, int); 848 struct gagrid *gagrvl (float); 849 char *varprs (char *, struct gastat *) ; 850 int gagchk (struct gagrid *, struct gagrid *, int); 851 struct gafile *getdfn (char *, struct gastat *); 852 char *stnvar (char *, char *, struct gafile *, struct gavar *, 853 struct gastat *); 854 855 /* Functions in GAFUNC: 856 rtnprs: Parse and execute a function call 857 gafopr: Perform opration for two-op function call 858 gafdef: Read user function definition table 859 */ 860 861 char *rtnprs (char *, char *, struct gastat *) ; 862 int gafopr (struct gastat *, struct gastat *, int ); 863 void gafdef (void); 864 865 /* Functions in GAIO: 866 gaggrd: Get a grid from a data file 867 gagrow: Get a row of data, possibly wrapped, from the file 868 gafcyx: Calculate file position of an item of data with x-y transposed 869 gafcor: Calculate file position of an item of data 870 garrow: Get an item or items from the data file 871 gagstn: Get a collection of stations 872 garead: 873 gardyx: garead for x-y transposed 874 gaglvs: Get appropriate var and levs from rpt 875 gaarpt: Allocate report block 876 gasstn: Seek to location in station file 877 garstn: Read station data 878 gacstn: Cache a station report 879 gagdef: Get grid from defined variable 880 clicyc: Adjust for cyclic climatological defined variable 881 gagpre: Predefined variable access 882 ganrow: Get an item or items from the netcdf data file 883 ganhow: Get an item or items from the HDF-SDS data file 884 gaopnc: Open a netcdf file 885 gaophdf: Open an HDF-SDS file 886 887 Note: function prototype for garead is now in gaio.c 888 */ 889 890 int gaggrd (struct gagrid *); 891 int gagrow (float *, int *); 892 /* kk 020624 --- s */ 893 /* int gafcor (int, int, int, int); */ 894 long gafcor (int, int, int, int); 895 /* kk 020624 --- e */ 896 /* kk 020624 --- s */ 897 /* int gafcyx (int, int, int, int); */ 898 long gafcyx (int, int, int, int); 899 /* kk 020624 --- e */ 900 int garrow (int, int, int, int, int, float *); 901 /* kk 020624 --- s */ 902 /* int garead (int, int, float *); */ 903 /* int gardyx (int, int, float *); */ 904 int gardyx (off_t, int, float *); 905 /* kk 020624 --- e */ 906 int gagstn (struct gastn *); 907 int gaglvs (int, struct rpthdr *, struct gastn *); 908 struct garpt *gaarpt (struct gastn *); 909 /* kk 020624 --- s */ 910 /* int gasstn (int); */ 911 /* int garstn (int, char *, int); */ 912 int gasstn (off_t); 913 int garstn (int, char *, off_t); 914 /* kk 020624 --- e */ 915 void gacstn (char *, char *, int, int); 916 void gagcst (int, char *); 917 int gagdef (void); 918 void clicyc(int *); 919 int gagpre (void); 920 int gairow (int, int, int, int, int, int, float *); 921 int gaird (off_t, int, int, int, int, int); 922 int gaprow (int, int, int, int, int, int, float *); 923 int gaopfn (int,int *,struct gafile *); 924 int gappcn (struct gafile *, int, int); 925 void w3fb04 (float, float, float, float, float *, float *); 926 void ll2lc (float *, float, float, float *, float *, float *); 927 void gaiomg (void); 928 int ganrow (int, int, int, int, int, float *); 929 int gahrow (int, int, int, int, int, float *); 930 int gaopnc (struct gafile *, int, int); 931 int gaophdf (struct gafile *, int, int); 932 int hdfattr (int, char *, float *); 933 int ncpattrs(int, char *, char *, int, int, char *); 934 int hdfpattrs(int, char *, char *, int, int, char *); 935 void prntwrap(char *, char *, char *); 936 937 /* Functions in GAGX: 938 gagx: Initialize graphics interface 939 gaplot: Generalized graphics output routine 940 gas1d: Set up scaling for a 1-D grid 941 gas2d: Set up scaling for a 2-D grid 942 gagrph: Plot line graph 943 gacntr: Plot contour plot 944 gastrm: Plot streamline plot 945 gafgrd: Fill grid boxes 946 gashad: Plot shaded plot 947 gavect: Plot vector feild 948 gascat: Plot scatter plot from two grids 949 gaarrw: Plot individual arrow 950 gaplvl: Plot grid values 951 gawmap: Plot appropriate map 952 gacsel: Select a contour interval 953 gaaxis: Generate proper axis labels for axes 954 galnch: Convert a longitude value to character form 955 galtch: Convert a latitude value to character form 956 gaconv: Perform grid level scaling 957 gatinc: Get date/time increment for time axis 958 gasfil: Shade fill a grid sqaure 959 trfill: Fill half a grid square (triangle) 960 gagfil: Fill grids with shaded ranges 961 */ 962 void gagx (struct gacmn *); 963 void gaplot (struct gacmn *); 964 void gas1d (struct gacmn *, float, float, int, int, struct gagrid *, 965 struct gastn *); 966 void gas2d (struct gacmn *, struct gagrid *, int); 967 void gagrph (struct gacmn *,int); 968 void gastts (struct gacmn *); 969 void gadprnt (struct gacmn *); 970 void gaoutgds (struct gacmn *); 971 void galfil (struct gacmn *); 972 void lfint (float, float, float, float, float *, float *); 973 void lfout (float *, float *, float *, float *, int, int); 974 void gacntr (struct gacmn *, int); 975 void gastrm (struct gacmn *); 976 void gashad (struct gacmn *); 977 void gavect (struct gacmn *, int); 978 void gascat (struct gacmn *); 979 void gafgrd (struct gacmn *); 980 void gafwrt (struct gacmn *); 981 int galats (struct gacmn *, int, int); /*mf --- GrADS-lats interface mf*/ 982 void gaarrw (float, float, float, float, float); 983 void gaplvl (struct gacmn *); 984 void gamscl (struct gacmn *); 985 void gawmap (struct gacmn *, int); 986 void gacsel (float, float, float *, float *, float *); 987 void gaaxis (int, struct gacmn *, int); 988 int galnch (float, char *); 989 int galtch (float, char *); 990 void gaconv (float, float, float *, float *); 991 void gagexp (float *, int, int, float *, int, int, float); 992 void gaglin (float *, int, int, float *, int, int, float); 993 struct gagrid *gaflip (struct gagrid *, struct gacmn *); 994 int gatinc (struct gacmn *, struct dt *, struct dt *); 995 void gasfil (int, int, float, float, float, float, float, float, float, float); 996 void trfill (float, float, float, float, float, float, float, float, 997 float, int, int); 998 void gafstn (struct gacmn *); 999 void gapstn (struct gacmn *); 1000 void gawsym (struct gacmn *); 1001 void gasmrk (struct gacmn *); 1002 void gabarb (float, float, float, float, float, float, float, int); 1003 void gapmdl (struct gacmn *); 1004 void gasmdl (struct gacmn *, struct garpt *, float *, float *); 1005 float wndexit (float, float, float, float, float, float *, 1006 float *, float *, float *); 1007 void gapprf (struct gacmn *); 1008 void gatser (struct gacmn *); 1009 void gampax (struct gacmn *); 1010 void wxsym (int, float, float, float, int, int *); 1011 void wxprim (int, float, float, float); 1012 void gagsav (int, struct gacmn *, struct gagrid *); 1013 void galnx (float, float, float *, float *); 1014 void galny (float, float, float *, float *); 1015 void gaalnx (float, float, float *, float *); 1016 void gaalny (float, float, float *, float *); 1017 void gaclx (float, float, float *, float *); 1018 void gacly (float, float, float *, float *); 1019 void gaaclx (float, float, float *, float *); 1020 void gaacly (float, float, float *, float *); 1021 void gagfil ( float *, int, int, float *, int *, int, float); 1022 void gafram (struct gacmn *); 1023 void gaaxpl (struct gacmn *, int, int); 1024 void gaselc (struct gacmn *, float, float); 1025 int gashdc (struct gacmn *, float); 1026 1027 /* Functions in GAUTIL: 1028 nxtcmd: Get next command from the user 1029 timadd: Add an increment to a time 1030 timsub: Subtract an increment from a time 1031 t2gr: Convert an absolute time to a grid value 1032 gr2t: Convert a grid value to an absolute time 1033 timdif: Calculate difference between two times 1034 qleap: Determine if a year is a leap year 1035 adtprs: Parse an absolute date/time expression 1036 rdtprs: Parse a relative date/time expression 1037 gaedit: Convert from float to character 1038 cmpwrd: Compare two character strings 1039 nxtwrd: Point to the next blank delimited word in a string 1040 liconv: Linear conversion routine 1041 gr2lev: Discrete level scaling routine 1042 lev2gr: Discrete level scaling routine 1043 intprs: Parse an integer expression 1044 longprs: Parse an long integer expression kk 020624 --- 1045 valprs: Parse a floating number expression 1046 dimprs: Parse a dimension expression 1047 lowcas: Convert a string to lower case 1048 uppcas: Convert a string to upper case 1049 getstr: Move part of a string to another string 1050 getwrd: Get next word in a string as a string 1051 gamnmx: Get minimum and maximum grid value 1052 garemb: Remove blanks from and terminate a string 1053 gagaus: Set up scaling for gaussian grid (R40) 1054 gags30: Set up scaling for gaussian grid (R30) 1055 gags20: Set up scaling for gaussian grid (R20) 1056 gags15: Set up scaling for Ocean Grid (MOM32) 1057 gamo32: Set up scaling for gaussian grid (R15) 1058 gat2ch: Date/Time to character form 1059 cmpch: Compare two strings of specified length 1060 gafree: Free stuff hung off pst block 1061 gagfre: Free gagrid block and associated data 1062 gasfre: Free gastn block and associated data 1063 gagbb: Unpack bit value 1064 gagby: Unpack byte value 1065 gabswp: Byte swap data values 1066 gahswp: Byte swap report header 1067 flt2ibm: convert float to ibm float (ebisuzaki) 1068 ibm2flt: convert ibm float to float (ebisuzaki) 1069 cpscal: Copy grid scaling info 1070 getvnm: Get variable long name and abbrv 1071 */ 1072 1073 int nxtcmd (char *, char *); 1074 void timadd (struct dt *, struct dt *); 1075 void timsub (struct dt *, struct dt *); 1076 float t2gr (float *, struct dt *); 1077 void gr2t (float *, float, struct dt *); 1078 int timdif (struct dt *, struct dt *); 1079 int qleap (int); 1080 char *adtprs (char *, struct dt *, struct dt *); 1081 char *rdtprs (char *, struct dt *); 1082 int gaedit (float, char *, int); 1083 int cmpwrd (char *, char *); 1084 int cmpwrdl (char *, char *); 1085 char *nxtwrd (char *); 1086 float liconv (float *, float); 1087 float gr2lev (float *, float); 1088 float lev2gr (float *, float); 1089 char *intprs (char *, int *); 1090 /* kk 020624 --- s */ 1091 char *longprs (char *, long *); 1092 /* kk 020624 --- e */ 1093 char *valprs (char *, float *); 1094 char *dimprs (char *, struct gastat *, struct gafile *, 1095 int *, float *, int, int *); 1096 void lowcas (char *); 1097 void uppcas (char *); 1098 void getstr (char *, char *, int); 1099 void getwrd (char *, char *, int); 1100 void gamnmx (struct gagrid *); 1101 void gasmnmx (struct gastn *); 1102 int garemb (char *); 1103 float *gagaus(int,int); 1104 float *gags30(int,int); 1105 float *gagst62(int,int); 1106 float *gags20(int,int); 1107 float *gags15(int,int); 1108 float *gamo32(int,int); 1109 int gat2ch (struct dt *, int, char *); 1110 int cmpch (char *, char *, int); 1111 void gafree (struct gastat *); 1112 void gagfre (struct gagrid *); 1113 void gasfre (struct gastn *); 1114 void fnmexp (char *, char *, char *); 1115 int gagbb (char *, int, int); 1116 int gagby (char *, int, int); 1117 char *gafndt (char *, struct dt *, struct dt *, float *, struct gachsub *, int); 1118 void gabswp (void *, int); 1119 void gahswp (struct rpthdr *); 1120 int dayweek (struct dt *); 1121 1122 /*mf -- Wesley Ebisuzaki routines -- mf*/ 1123 1124 int flt2ibm(float x, unsigned char *ibm); 1125 float ibm2flt(unsigned char *ibm); 1126 float ieee2flt(unsigned char *); 1127 int flt2ieee(float , unsigned char *); 1128 int be_int2int(unsigned char *) ; 1129 1130 float *cpscal (float *, int, int, int); 1131 int getvnm (struct gavar *, char *); 1132 1133 1134 /* Functions in GASRCP: 1135 gsfile: run a script file used in gauser.c 1136 */ 1137 1138 char *gsfile (char *, int *, int); 1139 1140 1141 /* Functions in gxX: 1142 gxwdln: use X server for wide lines 1143 */ 1144 1145 void gxwdln(void); 1146 1147 1148 #ifdef USEGADODS 1149 /* Function in dodstn */ 1150 int dodpfi (char *, struct gafile *); 1151 void dodclo (struct gafile *); 1152 int dodget (struct gastn *); 1153 #endif 1154 1155 /* Functions in bufrstn.c */ 1156 void getbufrhdr (gabufr_val *, gabufr_val *, struct bufrinfo *, struct bufrhdr *, int, int *); 1157 int getbufr (struct gastn *); 1158 struct garpt * sortrpt(struct garpt *); 1159