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 #include<stdlib.h> 7 8 void *galloc(int,char *); 9 void gree(); 10 void glook(); 11 12 /* Installation options for the GX package. */ 13 14 /* HBUFSZ is the size of the metafile output buffer in 15 number of short integers. The metafile buffer should be as 16 large as is convenient for the target system. Frames larger 17 than the buffer will get bufferred into the meta file on disk, 18 when BUFOPT is 1. Otherwise multiple buffers of size HBUFSZ 19 will be allocated as needed. */ 20 21 #define HBUFSZ 10000000L 22 #define BUFOPT 0 23 24 /*------------------------------------------------------------------------------ 25 New projections: Mollweide Projection (mollweide) 26 Orthographic Projection (orthogr) 27 28 Changes in GrADS C source code files: 29 gxwmap.c 30 gagx.c 31 gauser.c 32 gx.h 33 DKRZ 34 10.08.95 Karin Meier (karin.meier@dkrz.de) 35 36 ------------------------------------------------------------------------------*/ 37 38 #define pi 3.14159265358979 39 static float lomin, lomax, lamin, lamax; 40 41 42 /* Default directory containing the stroke and map data sets. 43 User can override this default via setenv GADDIR */ 44 45 static char *datad = "%%DATADIR%%"; 46 47 /* Option flag. If 0, map data set is only read once into a 48 dynamically allocated memory area. The memory is held onto 49 for the next call (about 35K). If 1, the memory is allocated for 50 each call and the map data set is read each time. */ 51 /* Lowres map only */ 52 53 #define MAPOPT 0 54 55 /* Spacing to use for shading to get a 'solid' fill when drawing 56 lines side by side at lineweight 3. */ 57 58 #define SDIFF 0.005 59 60 /* Structure for setting up map projections. Used to call 61 map projection routines. */ 62 63 struct mapprj { 64 float lnmn,lnmx,ltmn,ltmx; /* Lat,lon limits for projections */ 65 float lnref; /* Reference longitude */ 66 float ltref1,ltref2; /* Reference latitudes */ 67 float xmn,xmx,ymn,ymx; /* Put map in this page area */ 68 float axmn,axmx,aymn,aymx; /* Actual page area used by proj. */ 69 }; 70 71 /* Structure for holding info on displayed widgets. */ 72 73 struct gobj { 74 int type; /* Basic type of object. -1 - end of list; 75 0 - none; 1 - btn; 2 - rbb; 3 = popm */ 76 int i1,i2,j1,j2; /* Extent of object */ 77 int mb; /* Mouse button that invokes object */ 78 union tobj { 79 struct gbtn *btn; /* Pointer to button struct */ 80 struct grbb *rbb; /* Pointer to rubber-band struct */ 81 struct gdmu *dmu; /* Pointer to drop menu struct */ 82 } iob; 83 }; 84 85 /* Structure for holding information about GrADS button widgets */ 86 /* Also used for popmenus, which display on the screen the same 87 as buttons */ 88 89 struct gbtn { 90 int num; /* Button number (-1, unset) */ 91 float x,y,w,h; /* Button location, size */ 92 int ilo,ihi,jlo,jhi; 93 int fc,bc,oc1,oc2,ftc,btc,otc1,otc2; /* Colors */ 94 int thk; /* Thickness of outline */ 95 int state; /* Toggled or not? */ 96 int len; /* Length of string */ 97 char *ch; /* String content of btn */ 98 }; 99 100 /* Structure holds info on rubber-band regions */ 101 102 struct grbb { 103 int num; /* Region number (-1, unset) */ 104 int mb; /* Mouse button specific */ 105 float xlo,xhi,ylo,yhi; /* Rubber band region */ 106 int type; /* 0 for box, 1 for line */ 107 }; 108 109 /* Structure for info on drop menus */ 110 111 struct gdmu { 112 int num; /* Menu number */ 113 int casc; /* Anchored? */ 114 float x,y,w,h; /* Header button loc,size */ 115 int ilo,ihi,jlo,jhi; 116 int fc,bc,oc1,oc2; /* Colors of base */ 117 int tfc,tbc,toc1,toc2; /* Colors of selected base */ 118 int bfc,bbc,boc1,boc2; /* Colors of box */ 119 int soc1,soc2; /* Colors of selected item */ 120 int thk; /* Thickness of outlines */ 121 int len; /* Length of string */ 122 char *ch; /* String content of menu */ 123 }; 124 125 /* Structure holds info on dialog */ 126 127 struct gdlg { 128 float x,y,w,h; /* Button location, size */ 129 int pc,fc,bc,oc; /* Colors */ 130 int th; /* Thickness of outline */ 131 int len; /* Length of string */ 132 char *ch; /* String content of btn */ 133 int nu; /* Flag for numeric args */ 134 }; 135 136 137 /* GrADS event queue. This queue is built as the mouse button 138 is clicked, and is cleared by a GrADS clear event. Events 139 are removed from the queue via the 'q pos' command. */ 140 141 struct gevent { 142 struct gevent *forw; /* Forward pointer */ 143 float x, y; /* X and Y position of cursor */ 144 int mbtn; /* Mouse button pressed */ 145 int type; /* Type of event */ 146 int info[10]; /* Integer info about event */ 147 float rinfo[4]; /* Floating point info about event */ 148 }; 149 150 /* Structure for passing information on map plotting 151 options */ 152 153 struct mapopt { 154 int dcol,dstl,dthk; /* Default color, style, thickness */ 155 int *mcol,*mstl,*mthk; /* Arrays of map line attributes */ 156 float lnmin,lnmax,ltmin,ltmax; /* Plot bounds */ 157 char *mpdset; /* Map data set name */ 158 }; 159 160 /* Structure for passing information on the currently open 161 X Window */ 162 163 struct xinfo { 164 int winid; /* Window ID */ 165 int winx; /* Window X position (upper left) */ 166 int winy; /* Window Y position (upper left) */ 167 unsigned int winw; /* Window width */ 168 unsigned int winh; /* Window height */ 169 unsigned int winb; /* Window border width */ 170 }; 171 172 /* Function prototypes for GX library routines */ 173 174 /* Functions in gxdev: 175 gxdbgn: Initialize hardware 176 gxdend: Terminate hardware 177 gxdfrm: New frame 178 gxdcol: New color 179 gxadcl: Assign rgb color 180 gxdwid: New line width 181 gxdmov: Move pen 182 gxddrw: Draw 183 gxdrec: Filled rectangle 184 gxdsgl: Set single buffer mode 185 gxddbl: Set doulbe buffer mode 186 gxdswp: Swap buffers 187 gxqfil: Query availability of hardware polygon fill 188 gxdfil: Hardware Polygon fill 189 gxdxsz: Resize X Window (X only) 190 gxdbtn: Get pointer pos at mouse btn press 191 gxgrey: Set grey scale 192 gxdbck: Set hardware background/foreground 193 gxrswd: Reset Widget Structures 194 gxrs1wd: Reset one widget 195 gxcpwd: Copy widgets on swap in double buffer mode 196 gxevbn: Handle button press event 197 gxevrb: Handle rubber-band event 198 gxdptn: Set fill pattern 199 gxmaskrec: Set mask for a rectangle 200 gxmaskclear: Clear (unset) mask array 201 */ 202 203 void gxdbgn (float, float); 204 void gxdbat (void); 205 void gxdend (void); 206 void gxdfrm (int); 207 void gxdcol (int); 208 int gxdacl (int, int, int, int); 209 void gxdwid (int); 210 void gxdmov (float, float); 211 void gxddrw (float, float); 212 void gxdrec (float, float, float, float); 213 void gxdsgl (void); 214 void gxdbl (void); 215 void gxdswp (void); 216 int gxqfil (void); 217 void gxdfil (float *, int); 218 void gxdfl2 (float *, int); 219 void gxdxsz (int, int); 220 void gxgrey (int); 221 void gxdbck (int); 222 int gxdbkq (void); 223 int gxdeve (int); 224 void gxdbtn (int, float *, float *, int *, int *, int *, float *); 225 void gxdpbn (int, struct gbtn *, int, int, int); 226 void gxdrmu (int, struct gdmu *, int, int); 227 void gxdsfn (void); 228 void gxdtxt (char *, float, float); 229 void gxdcf (void); 230 int gxdfsw (char *, int, int); 231 void gxdrdw (void); 232 void gxrdrw (int); 233 void gxrswd (int); 234 void gxrs1wd (int, int); 235 void gxcpwd (void); 236 void gxevbn (struct gevent *, int); 237 void gxevrb (struct gevent *, int, int, int); 238 int gxevdm (struct gevent *, int, int, int); 239 int gxpopdm(struct gdmu *, int, int, int, int); 240 void gxdrbb (int, int, float, float, float, float,int); 241 char *gxdlg (struct gdlg *); 242 void gxdptn (int, int, int); 243 void gxdssv (int); 244 void gxdssh (int); 245 void gxdsfr (int); 246 int win_data (struct xinfo *); 247 void gxmaskrec (float, float, float, float); 248 void gxmaskclear (void); 249 250 /* Routines in gxsubs: 251 gxstrt: Initialize graphics output 252 gxend: Terminate graphics output 253 gxfrme: Start new frame 254 gxcolr: Set color attribute 255 gxacol: Assign new rgb to color number from 16-99 256 gxbckg: Set background color 257 gxqbck: Query background color 258 gxwide: Set line width attribute 259 gxmove: Move to X, Y 260 gxdraw: Draw solid line to X, Y using current color and linewidth 261 gxstyl: Set linestyle 262 gxplot: Move or draw using linestyles 263 gxclip: Set clipping region 264 gxchin: Initialize stroke font 265 gxchpl: Draw character(s) 266 gxtitl: Draw centered title 267 gxvpag: Set up virtual page 268 gxvcon: Do virtual page scaling 269 gxscal: Set up level 1 (linear) scaling 270 gxproj: Set up level 2 (projection) scaling 271 gxgrid: Set up level 3 (grid) scaling 272 gxback: Set up level 1 to level 2 back transform 273 gxconv: Convert coordinates to level 0 (hardware) 274 gxxy2w: Convert level 0 to level 2 275 gxcord: Convert array of coordinates to level 0 276 gxrset: Reset projection or grid level scaling 277 gxrecf: Draw filled rectangle 278 gxqclr: Query current color value 279 gxqstl: Query current linestyle value 280 gxmark: Draw marker 281 gxfill: Polygon fill 282 bdterp: Clipping Boundry Interpolation 283 gxgsym: Get env var 284 gxgnam: Get full path name 285 gxptrn: Set fill pattern 286 */ 287 288 void gxstrt (float, float, int, int); 289 void gxend (void); 290 void gxfrme (int); 291 void gxsfrm (void); 292 void gxcolr (int); 293 int gxacol (int, int, int, int); 294 void gxbckg (int); 295 int gxqbck (void); 296 void gxwide (int); 297 void gxmove (float, float); 298 void gxdraw (float, float); 299 void gxstyl (int); 300 void gxplot (float, float, int); 301 void gxclip (float, float, float, float); 302 void gxtitl (char *, float, float, float, float, float); 303 void gxvpag (float, float, float, float, float, float); 304 void gxvcon (float, float, float *, float *); 305 void gxppvp (float, float, float *, float *); 306 void gxscal (float, float, float, float, float, float, float, float); 307 void gxproj ( void (*) (float, float, float*, float*) ); 308 void gxgrid ( void (*) (float, float, float*, float*) ); 309 void gxback ( void (*) (float, float, float*, float*) ); 310 void gxconv (float, float, float *, float *, int); 311 void gxxy2w (float, float, float *, float *); 312 void gxgrmp (float, float, float *, float *); 313 void gxcord (float *, int, int); 314 void gxpoly (float *, int, int); 315 void gxrset (int); 316 void gxrecf (float, float, float, float); 317 int gxqclr (void); 318 int gxqstl (void); 319 void gxmark (int, float, float, float); 320 void gxfill (float *, int); 321 void bdterp (float, float, float, float, float *, float *); 322 char *gxgsym(char *); 323 char *gxgnam(char *); 324 void gxptrn (int, int, int); 325 326 /* Gxmeta routines handle graphics buffering and metafile output. 327 Routines in gxmeta: 328 gxhopt: Specify buffering option before open 329 gxhnew: Buffering initialization on startup 330 gxhbgn: Enable hardcopy (metafile) output 331 hout0: Buffer 0 arg metafile command 332 hout1: Buffer one arg metafile command 333 hout2: Buffer two arg metafile command 334 hout4: Buffer four arg metafile command 335 hout2i: Buffer two arg int metafile command 336 hout3i: Buffer three arg int metafile command 337 hout4i: Buffer four arg int metafile command 338 hfull: Deal with full metafile memory buffer 339 gxhprt: Handle print command (output to metafile) 340 gxhwri: Write buffer to metafile 341 gxhend: Close output metafile 342 gxhfrm: Handle new frame action 343 gxhdrw: Handle redraw operation 344 */ 345 346 void gxhopt (int); 347 void gxhnew (float, float, int); 348 int gxhbgn (char *); 349 void hout0 (int); 350 void hout1 (int, int); 351 void hout2 (int, float, float); 352 void hout4 (int, float, float, float, float); 353 void hout2i (int, int, int); 354 void hout3i (int, int, int, int); 355 void hout4i (int, int, int, int, int); 356 void hfull (void); 357 #ifdef PRINT_EPS 358 void gxhprt (char *); 359 #else 360 void gxhprt (void); 361 #endif 362 int gxhwri (void *, int); 363 void gxhend (void); 364 void gxhfrm (int); 365 void gxhdrw (int); 366 367 /* Routines in gxchpl: 368 gxchii: Initialize character plotting 369 gxchdf: Set default font 370 gxchpl: Plot character string 371 gxchln: Determine length (in plotting units) of a string 372 gxchgc: Get character info given character and font 373 gxchrd: Read in a font 374 */ 375 void gxchii (void); 376 void gxchdf (int); 377 void gxchpl (char *, int, float, float, float, float, float); 378 int gxchln (char *, int, float, float *); 379 char *gxchgc (int, int, int *); 380 int gxchrd (int); 381 382 /* Routine in gxcntr: 383 gxclmn: Specify minimum distance between labels 384 gxclev: Plot contour at specified value 385 gxcflw: Follow a contour segment 386 gxcspl: Spline fit a contour segment 387 gxclab: Draw buffered contour labels. 388 pathln: Find shortest col path through grid box 389 gxcrel: Release storage used by the contouring system 390 */ 391 void gxclmn (float); 392 void gxclev (float *, int, int, int, int, int, int, 393 float, float, char *, int, int); 394 void gxcflw (int, int, int, int); 395 void gxcspl (void); 396 void gxclab (float,int,int); 397 int pathln (float, float, float, float); 398 void gxcrel (void); 399 400 /* Routines in gxshad -- color filled contour routine: 401 402 gxshad -- do color filled contours 403 gxsflw -- Follow shade area boundries 404 spathl -- Calculate col path lengths 405 undcol -- Determine undefined-grid-side col characteristics 406 putxy -- Buffer current coordinate 407 shdcmp -- Compress contour line 408 shdmax -- Determine max or min interior 409 */ 410 void gxshad ( float *, int, int, float *, int *, int, float); 411 int gxsflw (int, int, int); 412 int spathl (float, float, float, float); 413 int undcol (int, int); 414 int putxy (float, float); 415 void shdcmp (void); 416 int shdmax (void); 417 418 /* routines in gxstrm: gxstrm (do streamlines) */ 419 420 void gxstrm (float *, float *, float *, int, int, float, float, float, 421 int, float *, int *, int, int); 422 void strmar (float, float, float, float); 423 int gxshdc (float *, int *, int, float); 424 425 /* Routines in gxwmap: 426 gxwmap: Draw world map 427 gxnmap: Draw medium res n.am. map 428 gxmout: Output section of world map 429 gxnste: Set up projection scaling for north polar stereographic 430 gxnpst: Scaling routine for north polar stereographic projection 431 gxaarw: Direction adjustment for map projection 432 gxgmap: Medium and hi res map drawer 433 gxhqpt: Plot quadrant of medium or hi res map 434 gxmpoly: Interpolate polygon sides for drawing in non-linear map space 435 */ 436 437 void gxdmap (struct mapopt *); 438 void gxwmap (float, float, float, float); 439 void gxnmap (float, float, float, float); 440 void gxmout (int, float, float, float, float, float); 441 int gxltln (struct mapprj *); 442 int gxscld (struct mapprj *, int, int); 443 int gxnste (struct mapprj *); 444 void gxnpst (float, float, float *, float *); 445 void gxnrev (float, float, float *, float *); 446 int gxsste (struct mapprj *); 447 void gxspst (float, float, float *, float *); 448 void gxsrev (float, float, float *, float *); 449 float gxaarw (float, float); 450 void gxgmap (int, int, float, float, float, float); 451 void gxhqpt (int, int, int, float, float, float, float, float); 452 int gxrobi (struct mapprj *); 453 void gxrobp (float, float, float *, float *); 454 void gxrobb (float, float, float *, float *); 455 /*---- DKRZ: appending new projections --- 10.08.95 Karin Meier 456 457 gxmoll: Setup scaling Mollweide projection 458 gxortg: Setup scaling Orthographic projection 459 460 ---- DKRZ: end of new projections --- karin.meier@dkrz.de ----*/ 461 462 /*---- Mollweide Projection ----*/ 463 464 int gxmoll (struct mapprj *); 465 void gxmollp (float, float, float *, float *); 466 void gxmollb (float, float, float *, float *); 467 468 /*---- Orthographic Projection ----*/ 469 470 int gxortg (struct mapprj *); 471 void gxortgp (float, float, float *, float *); 472 void gxortgb (float, float, float *, float *); 473 474 /*------- DKRZ appendingd end ------*/ 475 476 /*---- Lambert Conformal Projection ----*/ 477 478 int gxlamc (struct mapprj *); 479 void gxlamcp (float, float, float *, float *); 480 void gxlamcb (float, float, float *, float *); 481 482 /*------- DKRZ appendingd end ------*/ 483 float *gxmpoly(float *xy, int cnt, float llinc, int *newcnt); 484