Line data Source code
1 : /*****************************************************************************
2 : * $Id$
3 : *
4 : * This module has a number of additions and improvements over the original
5 : * implementation to be suitable for usage in GDAL HDF driver.
6 : *
7 : * Andrey Kiselev <dron@ak4719.spb.edu> is responsible for all the changes.
8 : ****************************************************************************/
9 :
10 : /*
11 : Copyright (C) 1996 Hughes and Applied Research Corporation
12 :
13 : Permission to use, modify, and distribute this software and its documentation
14 : for any purpose without fee is hereby granted, provided that the above
15 : copyright notice appear in all copies and that both that copyright notice and
16 : this permission notice appear in supporting documentation.
17 : */
18 : /*****************************************************************************
19 : REVISIONS:
20 :
21 : Aug 31, 1999 Abe Taaheri Changed memory allocation for utility strings to
22 : the size of UTLSTR_MAX_SIZE.
23 : Added error check for memory unavailability in
24 : several functions.
25 : Added check for NULL metabuf returned from
26 : EHmeta... functions. NULL pointer returned from
27 : EHmeta... functions indicate that memory could not
28 : be allocated for metabuf.
29 : Jun 27, 2000 Abe Taaheri Added support for EASE grid that uses
30 : Behrmann Cylinderical Equal Area (BCEA) projection
31 : Oct 23, 2000 Abe Taaheri Updated for ISINUS projection, so that both codes
32 : 31 and 99 can be used for this projection.
33 : Jan 15, 2003 Abe Taaheri Modified for generalization of EASE Grid.
34 :
35 : Jun 05, 2003 Bruce Beaumont / Abe Taaheri
36 :
37 : Fixed SQUARE definition.
38 : Added static projection number/name translation
39 : Added projection table lookup in GDdefproj.
40 : Removed projection table from GDdefproj
41 : Added projection table lookup in GDprojinfo
42 : Removed projection table from GDprojinfo
43 : Added cast for compcode in call to SDsetcompress
44 : in GDdeffield to avoid compiler errors
45 : Removed declaration for unused variable endptr
46 : in GDSDfldsrch
47 : Removed initialization code for unused variables
48 : in GDSDfldsrch
49 : Removed declarations for unused variables
50 : BCEA_scale, r0, s0, xMtr0, xMtr1, yMtr0,
51 : and yMtr1 in GDll2ij
52 : Removed initialization code for unused variables
53 : in GDll2ij
54 : Added code in GEO projection handling to allow
55 : map to span dateline in GDll2ij
56 : Changed "for each point" loop in GDll2ij to
57 : return -2147483648.0 for xVal and yVal if
58 : for_trans returned an error instead of
59 : returning an error to the caller
60 : (Note: MAXLONG is defined as 2147483647.0 in
61 : function cproj.c of GCTP)
62 : Added code in GDij2ll to use for_trans to
63 : translate the BCEA corner points from packed
64 : degrees to meters
65 : Removed declarations for unused variables
66 : BCEA_scale, r0, s0, xMtr, yMtr, epsilon,
67 : beta, qp_cea, kz_cea, eccen, eccen_sq,
68 : phi1, sinphi1, cosphi1, lon, lat, xcor,
69 : ycor, and nlatlon from GDij2ll
70 : Removed initialization code for unused variables
71 : in GDij2ll
72 : Added declarations for xMtr0, yMtr0, xMtr1, and
73 : yMtr1 in GDij2ll
74 : Added special-case code for BCEA
75 : Changed "for each point" loop in GDij2ll to
76 : return PGSd_GCT_IN_ERROR (1.0e51) for
77 : longitude and latitude values if inv_trans
78 : returned an error instead of return an error
79 : to the caller
80 : Removed declaration for unused variable ii in
81 : GDgetpixvalues
82 : Removed declaration for unused variable
83 : numTileDims in GDtileinfo
84 : Added error message and error return at the
85 : end of GDll2mm_cea
86 : Added return statement to GDll2mm_cea
87 : ******************************************************************************/
88 : #include "cpl_string.h"
89 : #include "stdio.h"
90 : #include "mfhdf.h"
91 : #include "hcomp.h"
92 : #include <math.h>
93 : #include "HdfEosDef.h"
94 :
95 : #include "hdf4compat.h"
96 :
97 : extern void for_init(int32, int32, float64 *, int32, const char *, const char *, int32 *,
98 : int32 (*for_trans[])(double, double, double*, double*));
99 : extern void inv_init(int32, int32, float64 *, int32, const char *, const char *, int32 *,
100 : int32 (*inv_trans[])(double, double, double*, double*));
101 :
102 : #define GDIDOFFSET 4194304
103 : #define SQUARE(x) ((x) * (x)) /* x**2 */
104 :
105 : static int32 GDXSDcomb[512*5];
106 : static char GDXSDname[HDFE_NAMBUFSIZE];
107 : static char GDXSDdims[HDFE_DIMBUFSIZE];
108 :
109 :
110 : #define NGRID 200
111 : /* Grid Structure External Arrays */
112 : struct gridStructure
113 : {
114 : int32 active;
115 : int32 IDTable;
116 : int32 VIDTable[2];
117 : int32 fid;
118 : int32 nSDS;
119 : int32 *sdsID;
120 : int32 compcode;
121 : intn compparm[5];
122 : int32 tilecode;
123 : int32 tilerank;
124 : int32 tiledims[8];
125 : };
126 : static struct gridStructure GDXGrid[NGRID];
127 :
128 :
129 :
130 : #define NGRIDREGN 256
131 : struct gridRegion
132 : {
133 : int32 fid;
134 : int32 gridID;
135 : int32 xStart;
136 : int32 xCount;
137 : int32 yStart;
138 : int32 yCount;
139 : int32 somStart;
140 : int32 somCount;
141 : float64 upleftpt[2];
142 : float64 lowrightpt[2];
143 : int32 StartVertical[8];
144 : int32 StopVertical[8];
145 : char *DimNamePtr[8];
146 : };
147 : static struct gridRegion *GDXRegion[NGRIDREGN];
148 :
149 : /* define a macro for the string size of the utility strings and some dimension
150 : list strings. The value of 80 in the previous version of this code
151 : may not be enough in some cases. The length now is 512 which seems to
152 : be more than enough to hold larger strings. */
153 :
154 : #define UTLSTR_MAX_SIZE 512
155 :
156 : /* Static projection table */
157 : static const struct {
158 : int32 projcode;
159 : const char *projname;
160 : } Projections[] = {
161 : {GCTP_GEO, "GCTP_GEO"},
162 : {GCTP_UTM, "GCTP_UTM"},
163 : {GCTP_SPCS, "GCTP_SPCS"},
164 : {GCTP_ALBERS, "GCTP_ALBERS"},
165 : {GCTP_LAMCC, "GCTP_LAMCC"},
166 : {GCTP_MERCAT, "GCTP_MERCAT"},
167 : {GCTP_PS, "GCTP_PS"},
168 : {GCTP_POLYC, "GCTP_POLYC"},
169 : {GCTP_EQUIDC, "GCTP_EQUIDC"},
170 : {GCTP_TM, "GCTP_TM"},
171 : {GCTP_STEREO, "GCTP_STEREO"},
172 : {GCTP_LAMAZ, "GCTP_LAMAZ"},
173 : {GCTP_AZMEQD, "GCTP_AZMEQD"},
174 : {GCTP_GNOMON, "GCTP_GNOMON"},
175 : {GCTP_ORTHO, "GCTP_ORTHO"},
176 : {GCTP_GVNSP, "GCTP_GVNSP"},
177 : {GCTP_SNSOID, "GCTP_SNSOID"},
178 : {GCTP_EQRECT, "GCTP_EQRECT"},
179 : {GCTP_MILLER, "GCTP_MILLER"},
180 : {GCTP_VGRINT, "GCTP_VGRINT"},
181 : {GCTP_HOM, "GCTP_HOM"},
182 : {GCTP_ROBIN, "GCTP_ROBIN"},
183 : {GCTP_SOM, "GCTP_SOM"},
184 : {GCTP_ALASKA, "GCTP_ALASKA"},
185 : {GCTP_GOOD, "GCTP_GOOD"},
186 : {GCTP_MOLL, "GCTP_MOLL"},
187 : {GCTP_IMOLL, "GCTP_IMOLL"},
188 : {GCTP_HAMMER, "GCTP_HAMMER"},
189 : {GCTP_WAGIV, "GCTP_WAGIV"},
190 : {GCTP_WAGVII, "GCTP_WAGVII"},
191 : {GCTP_OBLEQA, "GCTP_OBLEQA"},
192 : {GCTP_ISINUS1, "GCTP_ISINUS1"},
193 : {GCTP_CEA, "GCTP_CEA"},
194 : {GCTP_BCEA, "GCTP_BCEA"},
195 : {GCTP_ISINUS, "GCTP_ISINUS"},
196 : {-1, NULL}
197 : };
198 :
199 : /* Compression Codes */
200 : static const char * const HDFcomp[] = {
201 : "HDFE_COMP_NONE",
202 : "HDFE_COMP_RLE",
203 : "HDFE_COMP_NBIT",
204 : "HDFE_COMP_SKPHUFF",
205 : "HDFE_COMP_DEFLATE"
206 : };
207 :
208 : /* Origin Codes */
209 : static const char * const originNames[] = {
210 : "HDFE_GD_UL",
211 : "HDFE_GD_UR",
212 : "HDFE_GD_LL",
213 : "HDFE_GD_LR"
214 : };
215 :
216 : /* Pixel Registration Codes */
217 : static const char * const pixregNames[] = {
218 : "HDFE_CENTER",
219 : "HDFE_CORNER"
220 : };
221 :
222 : /* Grid Function Prototypes (internal routines) */
223 : static intn GDchkgdid(int32, const char *, int32 *, int32 *, int32 *);
224 : static intn GDSDfldsrch(int32, int32, const char *, int32 *, int32 *,
225 : int32 *, int32 *, int32 [], int32 *);
226 : static intn GDwrrdfield(int32, const char *, const char *,
227 : int32 [], int32 [], int32 [], VOIDP datbuf);
228 : static intn GDwrrdattr(int32, const char *, int32, int32, const char *, VOIDP);
229 : static intn GDll2ij(int32, int32, float64 [], int32, int32, int32, float64[],
230 : float64[], int32, float64[], float64[], int32[], int32[],
231 : float64[], float64[]);
232 : static intn GDgetdefaults(int32, int32, float64[], int32,
233 : float64[], float64[]);
234 : static intn GDtangentpnts(int32, float64[], float64[], float64[], float64[],
235 : float64 [], int32 *);
236 : static intn GDwrrdtile(int32, const char *, const char *, int32 [], VOIDP);
237 : static intn GDll2mm_cea(int32,int32, int32, float64[], int32, int32,
238 : float64[], float64[], int32, float64[],float64[],
239 : float64[], float64[], float64 *, float64 *);
240 :
241 : static intn GDmm2ll_cea(int32, int32, int32, float64[], int32, int32,
242 : float64[], float64[], int32, float64[], float64[],
243 : float64[], float64[]);
244 :
245 : /*----------------------------------------------------------------------------|
246 : | BEGIN_PROLOG |
247 : | |
248 : | FUNCTION: GDopen |
249 : | |
250 : | DESCRIPTION: Opens or creates HDF file in order to create, read, or write |
251 : | a grid. |
252 : | |
253 : | |
254 : | Return Value Type Units Description |
255 : | ============ ====== ========= ===================================== |
256 : | fid int32 HDF-EOS file ID |
257 : | |
258 : | INPUTS: |
259 : | filename char Filename |
260 : | l_access intn HDF l_access code |
261 : | |
262 : | |
263 : | OUTPUTS: |
264 : | None |
265 : | |
266 : | NOTES: |
267 : | |
268 : | |
269 : | Date Programmer Description |
270 : | ====== ============ ================================================= |
271 : | Jun 96 Joel Gales Original Programmer |
272 : | |
273 : | END_PROLOG |
274 : -----------------------------------------------------------------------------*/
275 : int32
276 4 : GDopen(const char *filename, intn l_access)
277 :
278 : {
279 : int32 fid /* HDF-EOS file ID */ ;
280 :
281 : /* Call EHopen to perform file l_access */
282 : /* ---------------------------------- */
283 4 : fid = EHopen(filename, l_access);
284 :
285 4 : return (fid);
286 :
287 : }
288 :
289 :
290 :
291 : /*----------------------------------------------------------------------------|
292 : | BEGIN_PROLOG |
293 : | |
294 : | FUNCTION: GDcreate |
295 : | |
296 : | DESCRIPTION: Creates a grid within the file. |
297 : | |
298 : | |
299 : | Return Value Type Units Description |
300 : | ============ ====== ========= ===================================== |
301 : | gridID int32 Grid structure ID |
302 : | |
303 : | INPUTS: |
304 : | fid int32 File ID |
305 : | gridname char Grid structure name |
306 : | xdimsize int32 Number of columns in grid |
307 : | ydimsize int32 Number of rows in grid |
308 : | upleftpt float64 Location (m/deg) of upper left corner |
309 : | lowrightpt float64 Location (m/deg) of lower right corner |
310 : | |
311 : | |
312 : | OUTPUTS: |
313 : | None |
314 : | |
315 : | NOTES: |
316 : | |
317 : | |
318 : | Date Programmer Description |
319 : | ====== ============ ================================================= |
320 : | Jun 96 Joel Gales Original Programmer |
321 : | Aug 96 Joel Gales Make metadata ODL compliant |
322 : | Aug 96 Joel Gales Check grid name for ODL compliance |
323 : | |
324 : | END_PROLOG |
325 : -----------------------------------------------------------------------------*/
326 : int32
327 0 : GDcreate(int32 fid, const char *gridname, int32 xdimsize, int32 ydimsize,
328 : float64 upleftpt[], float64 lowrightpt[])
329 : {
330 : intn i; /* Loop index */
331 0 : intn ngridopen = 0; /* # of grid structures open */
332 0 : intn status = 0; /* routine return status variable */
333 :
334 : uint8 l_access; /* Read/Write file l_access code */
335 :
336 : int32 HDFfid; /* HDF file id */
337 : int32 vgRef; /* Vgroup reference number */
338 : int32 vgid[3]; /* Vgroup ID array */
339 0 : int32 gridID = -1;/* HDF-EOS grid ID */
340 :
341 : int32 sdInterfaceID; /* HDF SDS interface ID */
342 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
343 0 : int32 nGrid = 0; /* Grid counter */
344 :
345 : char name[80]; /* Vgroup name */
346 : char class[80]; /* Vgroup class */
347 : char errbuf[256];/* Buffer for error message */
348 : char utlbuf[1024]; /* Utility buffer */
349 : char header[128];/* Structural metadata header string */
350 : char footer[256];/* Structural metadata footer string */
351 : char refstr1[128]; /* Upper left ref string (metadata) */
352 : char refstr2[128]; /* Lower right ref string (metadata) */
353 :
354 :
355 : /*
356 : * Check HDF-EOS file ID, get back HDF file ID, SD interface ID and
357 : * l_access code
358 : */
359 0 : status = EHchkfid(fid, gridname, &HDFfid, &sdInterfaceID, &l_access);
360 :
361 :
362 : /* Check gridname for length */
363 : /* ------------------------- */
364 0 : if ((intn) strlen(gridname) > VGNAMELENMAX)
365 : {
366 0 : status = -1;
367 0 : HEpush(DFE_GENAPP, "GDcreate", __FILE__, __LINE__);
368 0 : HEreport("Gridname \"%s\" must be less than %d characters.\n",
369 : gridname, VGNAMELENMAX);
370 : }
371 :
372 :
373 :
374 0 : if (status == 0)
375 : {
376 : /* Determine number of grids currently opened */
377 : /* ------------------------------------------- */
378 0 : for (i = 0; i < NGRID; i++)
379 : {
380 0 : ngridopen += GDXGrid[i].active;
381 : }
382 :
383 :
384 : /* Setup file interface */
385 : /* -------------------- */
386 0 : if (ngridopen < NGRID)
387 : {
388 :
389 : /* Check that grid has not been previously opened */
390 : /* ----------------------------------------------- */
391 0 : vgRef = -1;
392 :
393 : while (1)
394 : {
395 0 : vgRef = Vgetid(HDFfid, vgRef);
396 :
397 : /* If no more Vgroups then exist while loop */
398 : /* ---------------------------------------- */
399 0 : if (vgRef == -1)
400 : {
401 0 : break;
402 : }
403 :
404 : /* Get name and class of Vgroup */
405 : /* ---------------------------- */
406 0 : vgid[0] = Vattach(HDFfid, vgRef, "r");
407 0 : Vgetname(vgid[0], name);
408 0 : Vgetclass(vgid[0], class);
409 0 : Vdetach(vgid[0]);
410 :
411 :
412 : /* If GRID then increment # grid counter */
413 : /* ------------------------------------- */
414 0 : if (strcmp(class, "GRID") == 0)
415 : {
416 0 : nGrid++;
417 : }
418 :
419 :
420 : /* If grid already exist, return error */
421 : /* ------------------------------------ */
422 0 : if (strcmp(name, gridname) == 0 &&
423 0 : strcmp(class, "GRID") == 0)
424 : {
425 0 : status = -1;
426 0 : HEpush(DFE_GENAPP, "GDcreate", __FILE__, __LINE__);
427 0 : HEreport("\"%s\" already exists.\n", gridname);
428 0 : break;
429 : }
430 : }
431 :
432 :
433 0 : if (status == 0)
434 : {
435 : /* Create Root Vgroup for Grid */
436 : /* ---------------------------- */
437 0 : vgid[0] = Vattach(HDFfid, -1, "w");
438 :
439 :
440 : /* Set Name and Class (GRID) */
441 : /* -------------------------- */
442 0 : Vsetname(vgid[0], gridname);
443 0 : Vsetclass(vgid[0], "GRID");
444 :
445 :
446 :
447 : /* Create Data Fields Vgroup */
448 : /* ------------------------- */
449 0 : vgid[1] = Vattach(HDFfid, -1, "w");
450 0 : Vsetname(vgid[1], "Data Fields");
451 0 : Vsetclass(vgid[1], "GRID Vgroup");
452 0 : Vinsert(vgid[0], vgid[1]);
453 :
454 :
455 :
456 : /* Create Attributes Vgroup */
457 : /* ------------------------ */
458 0 : vgid[2] = Vattach(HDFfid, -1, "w");
459 0 : Vsetname(vgid[2], "Grid Attributes");
460 0 : Vsetclass(vgid[2], "GRID Vgroup");
461 0 : Vinsert(vgid[0], vgid[2]);
462 :
463 :
464 :
465 : /* Establish Grid in Structural MetaData Block */
466 : /* -------------------------------------------- */
467 0 : snprintf(header, sizeof(header), "%s%d%s%s%s%s%d%s%s%d%s",
468 : "\tGROUP=GRID_", (int)(nGrid + 1),
469 : "\n\t\tGridName=\"", gridname, "\"\n",
470 : "\t\tXDim=", (int)xdimsize, "\n",
471 : "\t\tYDim=", (int)ydimsize, "\n");
472 :
473 :
474 0 : snprintf(footer, sizeof(footer),
475 : "%s%s%s%s%s%s%s%d%s",
476 : "\t\tGROUP=Dimension\n",
477 : "\t\tEND_GROUP=Dimension\n",
478 : "\t\tGROUP=DataField\n",
479 : "\t\tEND_GROUP=DataField\n",
480 : "\t\tGROUP=MergedFields\n",
481 : "\t\tEND_GROUP=MergedFields\n",
482 : "\tEND_GROUP=GRID_", (int)(nGrid + 1), "\n");
483 :
484 :
485 :
486 : /* Build Ref point Col-Row strings */
487 : /* ------------------------------- */
488 0 : if (upleftpt == NULL ||
489 0 : (upleftpt[0] == 0 && upleftpt[1] == 0 &&
490 0 : lowrightpt[0] == 0 && lowrightpt[1] == 0))
491 : {
492 0 : strcpy(refstr1, "DEFAULT");
493 0 : strcpy(refstr2, "DEFAULT");
494 : }
495 : else
496 : {
497 0 : CPLsnprintf(refstr1, sizeof(refstr1), "%s%f%s%f%s",
498 0 : "(", upleftpt[0], ",", upleftpt[1], ")");
499 :
500 0 : CPLsnprintf(refstr2, sizeof(refstr2), "%s%f%s%f%s",
501 0 : "(", lowrightpt[0], ",", lowrightpt[1], ")");
502 : }
503 :
504 0 : snprintf(utlbuf, sizeof(utlbuf),
505 : "%s%s%s%s%s%s%s%s",
506 : header,
507 : "\t\tUpperLeftPointMtrs=", refstr1, "\n",
508 : "\t\tLowerRightMtrs=", refstr2, "\n",
509 : footer);
510 :
511 0 : status = EHinsertmeta(sdInterfaceID, "", "g", 1002L,
512 : utlbuf, NULL);
513 :
514 : }
515 : }
516 : else
517 : {
518 : /* Too many files opened */
519 : /* --------------------- */
520 0 : status = -1;
521 0 : strcpy(errbuf,
522 : "No more than %d grids may be open simultaneously");
523 0 : strcat(errbuf, " (%s)");
524 0 : HEpush(DFE_DENIED, "GDcreate", __FILE__, __LINE__);
525 0 : HEreport(errbuf, NGRID, gridname);
526 : }
527 :
528 :
529 : /* Assign gridID # & Load grid and GDXGrid.fid table entries */
530 : /* --------------------------------------------------------- */
531 0 : if (status == 0)
532 : {
533 :
534 0 : for (i = 0; i < NGRID; i++)
535 : {
536 0 : if (GDXGrid[i].active == 0)
537 : {
538 0 : gridID = i + idOffset;
539 0 : GDXGrid[i].active = 1;
540 0 : GDXGrid[i].IDTable = vgid[0];
541 0 : GDXGrid[i].VIDTable[0] = vgid[1];
542 0 : GDXGrid[i].VIDTable[1] = vgid[2];
543 0 : GDXGrid[i].fid = fid;
544 0 : status = 0;
545 0 : break;
546 : }
547 : }
548 :
549 : }
550 : }
551 0 : return (gridID);
552 : }
553 :
554 :
555 :
556 : /*----------------------------------------------------------------------------|
557 : | BEGIN_PROLOG |
558 : | |
559 : | FUNCTION: GDattach |
560 : | |
561 : | DESCRIPTION: Attaches to an existing grid within the file. |
562 : | |
563 : | |
564 : | Return Value Type Units Description |
565 : | ============ ====== ========= ===================================== |
566 : | gridID int32 grid structure ID |
567 : | |
568 : | INPUTS: |
569 : | fid int32 HDF-EOS file id |
570 : | gridname char grid structure name |
571 : | |
572 : | |
573 : | OUTPUTS: |
574 : | None |
575 : | |
576 : | NOTES: |
577 : | |
578 : | |
579 : | Date Programmer Description |
580 : | ====== ============ ================================================= |
581 : | Jun 96 Joel Gales Original Programmer |
582 : | Sep 99 Abe Taaheri Modified test for memory allocation check when no |
583 : | SDSs are in the grid, NCR24147 |
584 : | |
585 : | END_PROLOG |
586 : -----------------------------------------------------------------------------*/
587 : int32
588 0 : GDattach(int32 fid, const char *gridname)
589 :
590 : {
591 : intn i; /* Loop index */
592 : intn j; /* Loop index */
593 0 : intn ngridopen = 0; /* # of grid structures open */
594 : intn status; /* routine return status variable */
595 :
596 : uint8 acs; /* Read/Write file l_access code */
597 :
598 : int32 HDFfid; /* HDF file id */
599 : int32 vgRef; /* Vgroup reference number */
600 : int32 vgid[3]; /* Vgroup ID array */
601 0 : int32 gridID = -1;/* HDF-EOS grid ID */
602 : int32 *tags; /* Pnt to Vgroup object tags array */
603 : int32 *refs; /* Pnt to Vgroup object refs array */
604 : int32 dum; /* dummy variable */
605 : int32 sdInterfaceID; /* HDF SDS interface ID */
606 : int32 nObjects; /* # of objects in Vgroup */
607 : int32 nSDS; /* SDS counter */
608 : int32 l_index; /* SDS l_index */
609 : int32 sdid; /* SDS object ID */
610 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
611 :
612 : char name[80]; /* Vgroup name */
613 : char class[80]; /* Vgroup class */
614 : char errbuf[256];/* Buffer for error message */
615 : char acsCode[1]; /* Read/Write l_access char: "r/w" */
616 :
617 :
618 : /* Check HDF-EOS file ID, get back HDF file ID and l_access code */
619 : /* ----------------------------------------------------------- */
620 0 : status = EHchkfid(fid, gridname, &HDFfid, &dum, &acs);
621 :
622 :
623 0 : if (status == 0)
624 : {
625 : /* Convert numeric l_access code to character */
626 : /* ---------------------------------------- */
627 :
628 0 : acsCode[0] = (acs == 1) ? 'w' : 'r';
629 :
630 : /* Determine number of grids currently opened */
631 : /* ------------------------------------------- */
632 0 : for (i = 0; i < NGRID; i++)
633 : {
634 0 : ngridopen += GDXGrid[i].active;
635 : }
636 :
637 :
638 : /* If room for more ... */
639 : /* -------------------- */
640 0 : if (ngridopen < NGRID)
641 : {
642 :
643 : /* Search Vgroups for Grid */
644 : /* ------------------------ */
645 0 : vgRef = -1;
646 :
647 : while (1)
648 : {
649 0 : vgRef = Vgetid(HDFfid, vgRef);
650 :
651 : /* If no more Vgroups then exist while loop */
652 : /* ---------------------------------------- */
653 0 : if (vgRef == -1)
654 : {
655 0 : break;
656 : }
657 :
658 : /* Get name and class of Vgroup */
659 : /* ---------------------------- */
660 0 : vgid[0] = Vattach(HDFfid, vgRef, "r");
661 0 : Vgetname(vgid[0], name);
662 0 : Vgetclass(vgid[0], class);
663 :
664 :
665 : /*
666 : * If Vgroup with gridname and class GRID found, load tables
667 : */
668 :
669 0 : if (strcmp(name, gridname) == 0 &&
670 0 : strcmp(class, "GRID") == 0)
671 : {
672 : /* Attach to "Data Fields" and "Grid Attributes" Vgroups */
673 : /* ----------------------------------------------------- */
674 0 : tags = (int32 *) malloc(sizeof(int32) * 2);
675 0 : if(tags == NULL)
676 : {
677 0 : HEpush(DFE_NOSPACE,"GDattach", __FILE__, __LINE__);
678 0 : return(-1);
679 : }
680 0 : refs = (int32 *) malloc(sizeof(int32) * 2);
681 0 : if(refs == NULL)
682 : {
683 0 : HEpush(DFE_NOSPACE,"GDattach", __FILE__, __LINE__);
684 0 : free(tags);
685 0 : return(-1);
686 : }
687 0 : Vgettagrefs(vgid[0], tags, refs, 2);
688 0 : vgid[1] = Vattach(HDFfid, refs[0], acsCode);
689 0 : vgid[2] = Vattach(HDFfid, refs[1], acsCode);
690 0 : free(tags);
691 0 : free(refs);
692 :
693 :
694 : /* Setup External Arrays */
695 : /* --------------------- */
696 0 : for (i = 0; i < NGRID; i++)
697 : {
698 : /* Find empty entry in array */
699 : /* ------------------------- */
700 0 : if (GDXGrid[i].active == 0)
701 : {
702 : /*
703 : * Set gridID, Set grid entry active, Store root
704 : * Vgroup ID, Store sub Vgroup IDs, Store HDF-EOS
705 : * file ID
706 : */
707 0 : gridID = i + idOffset;
708 0 : GDXGrid[i].active = 1;
709 0 : GDXGrid[i].IDTable = vgid[0];
710 0 : GDXGrid[i].VIDTable[0] = vgid[1];
711 0 : GDXGrid[i].VIDTable[1] = vgid[2];
712 0 : GDXGrid[i].fid = fid;
713 0 : break;
714 : }
715 : }
716 :
717 : /* Get SDS interface ID */
718 : /* -------------------- */
719 0 : status = GDchkgdid(gridID, "GDattach", &dum,
720 : &sdInterfaceID, &dum);
721 :
722 :
723 : /* Get # of entries within Data Vgroup & search for SDS */
724 : /* ---------------------------------------------------- */
725 0 : nObjects = Vntagrefs(vgid[1]);
726 :
727 0 : if (nObjects > 0)
728 : {
729 : /* Get tag and ref # for Data Vgroup objects */
730 : /* ----------------------------------------- */
731 0 : tags = (int32 *) malloc(sizeof(int32) * nObjects);
732 0 : if(tags == NULL)
733 : {
734 0 : HEpush(DFE_NOSPACE,"GDattach", __FILE__, __LINE__);
735 0 : return(-1);
736 : }
737 0 : refs = (int32 *) malloc(sizeof(int32) * nObjects);
738 0 : if(refs == NULL)
739 : {
740 0 : HEpush(DFE_NOSPACE,"GDattach", __FILE__, __LINE__);
741 0 : free(tags);
742 0 : return(-1);
743 : }
744 0 : Vgettagrefs(vgid[1], tags, refs, nObjects);
745 :
746 : /* Count number of SDS & allocate SDS ID array */
747 : /* ------------------------------------------- */
748 0 : nSDS = 0;
749 0 : for (j = 0; j < nObjects; j++)
750 : {
751 0 : if (tags[j] == DFTAG_NDG)
752 : {
753 0 : nSDS++;
754 : }
755 : }
756 0 : GDXGrid[i].sdsID = (int32 *) calloc(nSDS, 4);
757 0 : if(GDXGrid[i].sdsID == NULL && nSDS != 0)
758 : {
759 0 : HEpush(DFE_NOSPACE,"GDattach", __FILE__, __LINE__);
760 0 : free(tags);
761 0 : free(refs);
762 0 : return(-1);
763 : }
764 0 : nSDS = 0;
765 :
766 :
767 :
768 : /* Fill SDS ID array */
769 : /* ----------------- */
770 0 : for (j = 0; j < nObjects; j++)
771 : {
772 : /* If object is SDS then get id */
773 : /* ---------------------------- */
774 0 : if (tags[j] == DFTAG_NDG)
775 : {
776 0 : l_index = SDreftoindex(sdInterfaceID, refs[j]);
777 0 : sdid = SDselect(sdInterfaceID, l_index);
778 0 : GDXGrid[i].sdsID[nSDS] = sdid;
779 0 : nSDS++;
780 0 : GDXGrid[i].nSDS++;
781 : }
782 : }
783 0 : free(tags);
784 0 : free(refs);
785 : }
786 0 : break;
787 : }
788 :
789 : /* Detach Vgroup if not desired Grid */
790 : /* --------------------------------- */
791 0 : Vdetach(vgid[0]);
792 : }
793 :
794 : /* If Grid not found then set up error message */
795 : /* ------------------------------------------- */
796 0 : if (gridID == -1)
797 : {
798 0 : HEpush(DFE_RANGE, "GDattach", __FILE__, __LINE__);
799 0 : HEreport("Grid: \"%s\" does not exist within HDF file.\n",
800 : gridname);
801 : }
802 : }
803 : else
804 : {
805 : /* Too many files opened */
806 : /* --------------------- */
807 0 : gridID = -1;
808 0 : strcpy(errbuf,
809 : "No more than %d grids may be open simultaneously");
810 0 : strcat(errbuf, " (%s)");
811 0 : HEpush(DFE_DENIED, "GDattach", __FILE__, __LINE__);
812 0 : HEreport(errbuf, NGRID, gridname);
813 : }
814 :
815 : }
816 0 : return (gridID);
817 : }
818 :
819 :
820 : /*----------------------------------------------------------------------------|
821 : | BEGIN_PROLOG |
822 : | |
823 : | FUNCTION: GDchkgdid |
824 : | |
825 : | DESCRIPTION: |
826 : | |
827 : | |
828 : | Return Value Type Units Description |
829 : | ============ ====== ========= ===================================== |
830 : | status intn return status (0) SUCCEED, (-1) FAIL |
831 : | |
832 : | INPUTS: |
833 : | gridID int32 grid structure ID |
834 : | routname char Name of routine calling GDchkgdid |
835 : | |
836 : | OUTPUTS: |
837 : | fid int32 File ID |
838 : | sdInterfaceID int32 SDS interface ID |
839 : | gdVgrpID int32 grid Vgroup ID |
840 : | |
841 : | |
842 : | OUTPUTS: |
843 : | None |
844 : | |
845 : | NOTES: |
846 : | |
847 : | |
848 : | Date Programmer Description |
849 : | ====== ============ ================================================= |
850 : | Jun 96 Joel Gales Original Programmer |
851 : | |
852 : | END_PROLOG |
853 : -----------------------------------------------------------------------------*/
854 : static intn
855 0 : GDchkgdid(int32 gridID, const char *routname,
856 : int32 * fid, int32 * sdInterfaceID, int32 * gdVgrpID)
857 : {
858 0 : intn status = 0; /* routine return status variable */
859 : uint8 l_access; /* Read/Write l_access code */
860 : int32 gID; /* Grid ID - offset */
861 :
862 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
863 :
864 : static const char message1[] =
865 : "Invalid grid id: %d in routine \"%s\". ID must be >= %d and < %d.\n";
866 : static const char message2[] =
867 : "Grid id %d in routine \"%s\" not active.\n";
868 :
869 :
870 :
871 : /* Check for valid grid id */
872 :
873 0 : if (gridID < idOffset || gridID >= NGRID + idOffset)
874 : {
875 0 : status = -1;
876 0 : HEpush(DFE_RANGE, "GDchkgdid", __FILE__, __LINE__);
877 0 : HEreport(message1, gridID, routname, idOffset, NGRID + idOffset);
878 : }
879 : else
880 : {
881 :
882 : /* Compute "reduced" ID */
883 : /* -------------------- */
884 0 : gID = gridID % idOffset;
885 :
886 :
887 : /* Check for active grid ID */
888 : /* ------------------------ */
889 0 : if (GDXGrid[gID].active == 0)
890 : {
891 0 : status = -1;
892 0 : HEpush(DFE_GENAPP, "GDchkgdid", __FILE__, __LINE__);
893 0 : HEreport(message2, gridID, routname);
894 : }
895 : else
896 : {
897 :
898 : /* Get file & SDS ids and Grid key */
899 : /* -------------------------------- */
900 0 : status = EHchkfid(GDXGrid[gID].fid, " ",
901 : fid, sdInterfaceID, &l_access);
902 0 : *gdVgrpID = GDXGrid[gID].IDTable;
903 : }
904 : }
905 0 : return (status);
906 :
907 : }
908 :
909 :
910 : /*----------------------------------------------------------------------------|
911 : | BEGIN_PROLOG |
912 : | |
913 : | FUNCTION: GDdefdim |
914 : | |
915 : | DESCRIPTION: Defines a new dimension within the grid. |
916 : | |
917 : | |
918 : | Return Value Type Units Description |
919 : | ============ ====== ========= ===================================== |
920 : | status intn return status (0) SUCCEED, (-1) FAIL |
921 : | |
922 : | INPUTS: |
923 : | gridID int32 grid structure ID |
924 : | dimname char Dimension name to define |
925 : | dim int32 Dimension value |
926 : | |
927 : | |
928 : | OUTPUTS: |
929 : | None |
930 : | |
931 : | NOTES: |
932 : | |
933 : | |
934 : | Date Programmer Description |
935 : | ====== ============ ================================================= |
936 : | Jun 96 Joel Gales Original Programmer |
937 : | |
938 : | END_PROLOG |
939 : -----------------------------------------------------------------------------*/
940 : intn
941 0 : GDdefdim(int32 gridID, const char *dimname, int32 dim)
942 :
943 : {
944 : intn status; /* routine return status variable */
945 :
946 : int32 fid; /* HDF-EOS file id */
947 : int32 sdInterfaceID; /* HDF SDS interface ID */
948 : int32 gdVgrpID; /* Grid root Vgroup ID */
949 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
950 :
951 : char gridname[80] /* Grid name */ ;
952 :
953 :
954 : /* Check for valid grid id */
955 0 : status = GDchkgdid(gridID, "GDdefinedim",
956 : &fid, &sdInterfaceID, &gdVgrpID);
957 :
958 :
959 : /* Make sure dimension >= 0 */
960 : /* ------------------------ */
961 0 : if (dim < 0)
962 : {
963 0 : status = -1;
964 0 : HEpush(DFE_GENAPP, "GDdefdim", __FILE__, __LINE__);
965 0 : HEreport("Dimension value for \"%s\" less than zero: %d.\n",
966 : dimname, dim);
967 : }
968 :
969 :
970 : /* Write Dimension to Structural MetaData */
971 : /* -------------------------------------- */
972 0 : if (status == 0)
973 : {
974 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
975 : /* The cast to char* is somehow nasty since EHinsertmeta can modify */
976 : /* dimname, but not in this case since we call with metacode = 0 */
977 0 : status = EHinsertmeta(sdInterfaceID, gridname, "g", 0L,
978 : (char*) dimname, &dim);
979 : }
980 0 : return (status);
981 :
982 : }
983 :
984 : /*----------------------------------------------------------------------------|
985 : | BEGIN_PROLOG |
986 : | |
987 : | FUNCTION: GDdefproj |
988 : | |
989 : | DESCRIPTION: Defines projection of grid. |
990 : | |
991 : | |
992 : | Return Value Type Units Description |
993 : | ============ ====== ========= ===================================== |
994 : | status intn return status (0) SUCCEED, (-1) FAIL |
995 : | |
996 : | INPUTS: |
997 : | gridID int32 Grid structure ID |
998 : | projcode int32 GCTP projection code |
999 : | zonecode int32 UTM zone code |
1000 : | spherecode int32 GCTP spheriod code |
1001 : | projparm float64 Projection parameters |
1002 : | |
1003 : | OUTPUTS: |
1004 : | None |
1005 : | |
1006 : | NOTES: |
1007 : | |
1008 : | |
1009 : | Date Programmer Description |
1010 : | ====== ============ ================================================= |
1011 : | Jun 96 Joel Gales Original Programmer |
1012 : | Jun 00 Abe Taaheri Added support for EASE grid |
1013 : | |
1014 : | END_PROLOG |
1015 : -----------------------------------------------------------------------------*/
1016 : intn
1017 0 : GDdefproj(int32 gridID, int32 projcode, int32 zonecode, int32 spherecode,
1018 : float64 projparm[])
1019 : {
1020 : intn i; /* Loop index */
1021 : intn projx; /* Projection table l_index */
1022 0 : intn status = 0; /* routine return status variable */
1023 :
1024 : int32 fid; /* HDF-EOS file ID */
1025 : int32 sdInterfaceID; /* HDF SDS interface ID */
1026 : int32 gdVgrpID; /* Grid root Vgroup ID */
1027 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
1028 : int32 slen; /* String length */
1029 : char utlbuf[1024]; /* Utility Buffer */
1030 : char projparmbuf[512]; /* Projection parameter metadata
1031 : * string */
1032 : char gridname[80]; /* Grid Name */
1033 :
1034 :
1035 : /* Check for valid grid id */
1036 : /* ----------------------- */
1037 0 : status = GDchkgdid(gridID, "GDdefproj", &fid, &sdInterfaceID, &gdVgrpID);
1038 :
1039 0 : if (status == 0)
1040 : {
1041 : /*
1042 : * If projection not GEO, UTM, or State Code build projection
1043 : * parameter string
1044 : */
1045 0 : if (projcode != GCTP_GEO &&
1046 0 : projcode != GCTP_UTM &&
1047 : projcode != GCTP_SPCS)
1048 : {
1049 :
1050 : /* Begin projection parameter list with "(" */
1051 0 : strcpy(projparmbuf, "(");
1052 :
1053 0 : for (i = 0; i < 13; i++)
1054 : {
1055 : /* If projparm[i] = 0 ... */
1056 0 : if (projparm[i] == 0.0)
1057 : {
1058 0 : strcpy(utlbuf, "0,");
1059 : }
1060 : else
1061 : {
1062 : /* if projparm[i] is integer ... */
1063 0 : if ((int32) projparm[i] == projparm[i])
1064 : {
1065 0 : snprintf(utlbuf, sizeof(utlbuf), "%d%s",
1066 0 : (int) projparm[i], ",");
1067 : }
1068 : /* else projparm[i] is non-zero floating point ... */
1069 : else
1070 : {
1071 0 : CPLsnprintf(utlbuf, sizeof(utlbuf), "%f%s", projparm[i], ",");
1072 : }
1073 : }
1074 0 : strcat(projparmbuf, utlbuf);
1075 : }
1076 0 : slen = (int)strlen(projparmbuf);
1077 :
1078 : /* Add trailing ")" */
1079 0 : projparmbuf[slen - 1] = ')';
1080 : }
1081 :
1082 0 : for (projx = 0; Projections[projx].projcode != -1; projx++)
1083 : {
1084 0 : if (projcode == Projections[projx].projcode)
1085 : {
1086 0 : break;
1087 : }
1088 : }
1089 :
1090 :
1091 : /* Build metadata string */
1092 : /* --------------------- */
1093 0 : if (projcode == GCTP_GEO)
1094 : {
1095 0 : snprintf(utlbuf, sizeof(utlbuf),
1096 : "%s%s%s",
1097 : "\t\tProjection=", Projections[projx].projname, "\n");
1098 : }
1099 0 : else if (projcode == GCTP_UTM || projcode == GCTP_SPCS)
1100 : {
1101 0 : snprintf(utlbuf, sizeof(utlbuf),
1102 : "%s%s%s%s%d%s%s%d%s",
1103 : "\t\tProjection=", Projections[projx].projname, "\n",
1104 : "\t\tZoneCode=", (int)zonecode, "\n",
1105 : "\t\tSphereCode=", (int)spherecode, "\n");
1106 : }
1107 : else
1108 : {
1109 0 : snprintf(utlbuf, sizeof(utlbuf),
1110 : "%s%s%s%s%s%s%s%d%s",
1111 : "\t\tProjection=", Projections[projx].projname, "\n",
1112 : "\t\tProjParams=", projparmbuf, "\n",
1113 : "\t\tSphereCode=", (int)spherecode, "\n");
1114 : }
1115 :
1116 :
1117 : /* Insert in structural metadata */
1118 : /* ----------------------------- */
1119 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
1120 0 : status = EHinsertmeta(sdInterfaceID, gridname, "g", 101L,
1121 : utlbuf, NULL);
1122 : }
1123 :
1124 0 : return (status);
1125 : }
1126 :
1127 :
1128 :
1129 : /*----------------------------------------------------------------------------|
1130 : | BEGIN_PROLOG |
1131 : | |
1132 : | FUNCTION: GDblkSOMoffset |
1133 : | |
1134 : | DESCRIPTION: Writes Block SOM offset values |
1135 : | |
1136 : | |
1137 : | Return Value Type Units Description |
1138 : | ============ ====== ========= ===================================== |
1139 : | status intn return status (0) SUCCEED, (-1) FAIL |
1140 : | |
1141 : | INPUTS: |
1142 : | gridID int32 Grid structure ID |
1143 : | offset float32 Offset values |
1144 : | count int32 Number of offset values |
1145 : | code char w/r code (w/r) |
1146 : | |
1147 : | OUTPUTS: |
1148 : | None |
1149 : | |
1150 : | NOTES: |
1151 : | |
1152 : | |
1153 : | Date Programmer Description |
1154 : | ====== ============ ================================================= |
1155 : | Sep 96 Joel Gales Original Programmer |
1156 : | Mar 99 David Wynne Changed data type of offset array from int32 to |
1157 : | float32, NCR 21197 |
1158 : | |
1159 : | END_PROLOG |
1160 : -----------------------------------------------------------------------------*/
1161 : intn
1162 0 : GDblkSOMoffset(int32 gridID, float32 offset[], int32 count, const char *code)
1163 : {
1164 0 : intn status = 0; /* routine return status variable */
1165 :
1166 : int32 fid; /* HDF-EOS file ID */
1167 : int32 sdInterfaceID; /* HDF SDS interface ID */
1168 : int32 gdVgrpID; /* Grid root Vgroup ID */
1169 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
1170 : int32 projcode; /* GCTP projection code */
1171 :
1172 : float64 projparm[13]; /* Projection parameters */
1173 :
1174 : char utlbuf[128];/* Utility Buffer */
1175 : char gridname[80]; /* Grid Name */
1176 :
1177 : /* Check for valid grid id */
1178 0 : status = GDchkgdid(gridID, "GDblkSOMoffset",
1179 : &fid, &sdInterfaceID, &gdVgrpID);
1180 :
1181 0 : if (status == 0)
1182 : {
1183 : /* Get projection parameters */
1184 0 : status = GDprojinfo(gridID, &projcode, NULL, NULL, projparm);
1185 :
1186 : /* If SOM projection with projparm[11] non-zero ... */
1187 0 : if (projcode == GCTP_SOM && projparm[11] != 0)
1188 : {
1189 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
1190 0 : snprintf(utlbuf, sizeof(utlbuf),"%s%s", "_BLKSOM:", gridname);
1191 :
1192 : /* Write offset values as attribute */
1193 0 : if (strcmp(code, "w") == 0)
1194 : {
1195 0 : status = GDwriteattr(gridID, utlbuf, DFNT_FLOAT32,
1196 : count, offset);
1197 : }
1198 : /* Read offset values from attribute */
1199 0 : else if (strcmp(code, "r") == 0)
1200 : {
1201 0 : status = GDreadattr(gridID, utlbuf, offset);
1202 : }
1203 : }
1204 : }
1205 0 : return (status);
1206 : }
1207 :
1208 :
1209 : /*----------------------------------------------------------------------------|
1210 : | BEGIN_PROLOG |
1211 : | |
1212 : | FUNCTION: GDdefcomp |
1213 : | |
1214 : | DESCRIPTION: Defines compression type and parameters |
1215 : | |
1216 : | |
1217 : | Return Value Type Units Description |
1218 : | ============ ====== ========= ===================================== |
1219 : | status intn return status (0) SUCCEED, (-1) FAIL |
1220 : | |
1221 : | INPUTS: |
1222 : | gridID int32 grid structure ID |
1223 : | compcode int32 compression code |
1224 : | compparm intn compression parameters |
1225 : | |
1226 : | OUTPUTS: |
1227 : | None |
1228 : | |
1229 : | NOTES: |
1230 : | |
1231 : | |
1232 : | Date Programmer Description |
1233 : | ====== ============ ================================================= |
1234 : | Sep 96 Joel Gales Original Programmer |
1235 : | |
1236 : | END_PROLOG |
1237 : -----------------------------------------------------------------------------*/
1238 : intn
1239 0 : GDdefcomp(int32 gridID, int32 compcode, intn compparm[])
1240 : {
1241 0 : intn status = 0; /* routine return status variable */
1242 :
1243 : int32 fid; /* HDF-EOS file id */
1244 : int32 sdInterfaceID; /* HDF SDS interface ID */
1245 : int32 gdVgrpID; /* Grid root Vgroup ID */
1246 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
1247 : int32 gID; /* gridID - offset */
1248 :
1249 : /* Check for valid grid id */
1250 0 : status = GDchkgdid(gridID, "GDdefcomp", &fid, &sdInterfaceID, &gdVgrpID);
1251 :
1252 0 : if (status == 0)
1253 : {
1254 0 : gID = gridID % idOffset;
1255 :
1256 : /* Set compression code in compression external array */
1257 0 : GDXGrid[gID].compcode = compcode;
1258 :
1259 0 : switch (compcode)
1260 : {
1261 : /* Set NBIT compression parameters in compression external array */
1262 0 : case HDFE_COMP_NBIT:
1263 :
1264 0 : GDXGrid[gID].compparm[0] = compparm[0];
1265 0 : GDXGrid[gID].compparm[1] = compparm[1];
1266 0 : GDXGrid[gID].compparm[2] = compparm[2];
1267 0 : GDXGrid[gID].compparm[3] = compparm[3];
1268 :
1269 0 : break;
1270 :
1271 : /* Set GZIP compression parameter in compression external array */
1272 0 : case HDFE_COMP_DEFLATE:
1273 :
1274 0 : GDXGrid[gID].compparm[0] = compparm[0];
1275 :
1276 0 : break;
1277 :
1278 : }
1279 0 : }
1280 :
1281 0 : return (status);
1282 : }
1283 :
1284 :
1285 :
1286 :
1287 : /*----------------------------------------------------------------------------|
1288 : | BEGIN_PROLOG |
1289 : | |
1290 : | FUNCTION: GDdeftile |
1291 : | |
1292 : | DESCRIPTION: Defines tiling parameters |
1293 : | |
1294 : | |
1295 : | Return Value Type Units Description |
1296 : | ============ ====== ========= ===================================== |
1297 : | status intn return status (0) SUCCEED, (-1) FAIL |
1298 : | |
1299 : | INPUTS: |
1300 : | gridID int32 grid structure ID |
1301 : | tilecode int32 tile code |
1302 : | tilerank int32 number of tiling dimensions |
1303 : | tiledims int32 tiling dimensions |
1304 : | |
1305 : | OUTPUTS: |
1306 : | None |
1307 : | |
1308 : | NOTES: |
1309 : | |
1310 : | |
1311 : | Date Programmer Description |
1312 : | ====== ============ ================================================= |
1313 : | Jan 97 Joel Gales Original Programmer |
1314 : | |
1315 : | END_PROLOG |
1316 : -----------------------------------------------------------------------------*/
1317 : intn
1318 0 : GDdeftile(int32 gridID, int32 tilecode, int32 tilerank, int32 tiledims[])
1319 : {
1320 : intn i; /* Loop index */
1321 0 : intn status = 0; /* routine return status variable */
1322 :
1323 : int32 fid; /* HDF-EOS file id */
1324 : int32 sdInterfaceID; /* HDF SDS interface ID */
1325 : int32 gdVgrpID; /* Grid root Vgroup ID */
1326 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
1327 : int32 gID; /* gridID - offset */
1328 :
1329 : /* Check for valid grid id */
1330 : /* ----------------------- */
1331 0 : status = GDchkgdid(gridID, "GDdeftile", &fid, &sdInterfaceID, &gdVgrpID);
1332 :
1333 :
1334 0 : if (status == 0)
1335 : {
1336 0 : gID = gridID % idOffset;
1337 :
1338 0 : for (i = 0; i < 8; i++)
1339 : {
1340 0 : GDXGrid[gID].tiledims[i] = 0;
1341 : }
1342 :
1343 0 : GDXGrid[gID].tilecode = tilecode;
1344 :
1345 0 : switch (tilecode)
1346 : {
1347 0 : case HDFE_NOTILE:
1348 :
1349 0 : GDXGrid[gID].tilerank = 0;
1350 :
1351 0 : break;
1352 :
1353 :
1354 0 : case HDFE_TILE:
1355 :
1356 0 : GDXGrid[gID].tilerank = tilerank;
1357 :
1358 0 : for (i = 0; i < tilerank; i++)
1359 : {
1360 0 : GDXGrid[gID].tiledims[i] = tiledims[i];
1361 :
1362 0 : if (GDXGrid[gID].tiledims[i] == 0)
1363 : {
1364 0 : GDXGrid[gID].tiledims[i] = 1;
1365 : }
1366 : }
1367 :
1368 0 : break;
1369 :
1370 : }
1371 0 : }
1372 :
1373 0 : return (status);
1374 : }
1375 :
1376 :
1377 :
1378 :
1379 : /*----------------------------------------------------------------------------|
1380 : | BEGIN_PROLOG |
1381 : | |
1382 : | FUNCTION: GDdeforigin |
1383 : | |
1384 : | DESCRIPTION: Defines the origin of the grid data. |
1385 : | |
1386 : | |
1387 : | Return Value Type Units Description |
1388 : | ============ ====== ========= ===================================== |
1389 : | status intn return status (0) SUCCEED, (-1) FAIL |
1390 : | |
1391 : | INPUTS: |
1392 : | gridID int32 grid structure ID |
1393 : | origincode int32 origin code |
1394 : | HDFE_GD_UL (0) |
1395 : | HDFE_GD_UR (1) |
1396 : | HDFE_GD_LL (2) |
1397 : | HDFE_GD_LR (3) |
1398 : | |
1399 : | |
1400 : | OUTPUTS: |
1401 : | None |
1402 : | |
1403 : | NOTES: |
1404 : | |
1405 : | |
1406 : | Date Programmer Description |
1407 : | ====== ============ ================================================= |
1408 : | Jun 96 Joel Gales Original Programmer |
1409 : | |
1410 : | END_PROLOG |
1411 : -----------------------------------------------------------------------------*/
1412 : intn
1413 0 : GDdeforigin(int32 gridID, int32 origincode)
1414 : {
1415 0 : intn status = 0; /* routine return status variable */
1416 :
1417 : int32 fid; /* HDF-EOS file ID */
1418 : int32 gdVgrpID; /* Grid root Vgroup ID */
1419 : int32 sdInterfaceID; /* HDF SDS interface ID */
1420 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
1421 :
1422 : char utlbuf[64]; /* Utility buffer */
1423 : char gridname[80]; /* Grid name */
1424 :
1425 :
1426 : /* Check for valid grid id */
1427 0 : status = GDchkgdid(gridID, "GDdeforigin",
1428 : &fid, &sdInterfaceID, &gdVgrpID);
1429 :
1430 0 : if (status == 0)
1431 : {
1432 : /* If proper origin code then write to structural metadata */
1433 : /* ------------------------------------------------------- */
1434 0 : if (origincode >= 0 && origincode < (int32)sizeof(originNames))
1435 : {
1436 0 : snprintf(utlbuf, sizeof(utlbuf),"%s%s%s",
1437 : "\t\tGridOrigin=", originNames[origincode], "\n");
1438 :
1439 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
1440 0 : status = EHinsertmeta(sdInterfaceID, gridname, "g", 101L,
1441 : utlbuf, NULL);
1442 : }
1443 : else
1444 : {
1445 0 : status = -1;
1446 0 : HEpush(DFE_GENAPP, "GDdeforigin", __FILE__, __LINE__);
1447 0 : HEreport("Improper Grid Origin code: %d\n", origincode);
1448 : }
1449 : }
1450 :
1451 0 : return (status);
1452 : }
1453 :
1454 : /*----------------------------------------------------------------------------|
1455 : | BEGIN_PROLOG |
1456 : | |
1457 : | FUNCTION: GDdefpixreg |
1458 : | |
1459 : | DESCRIPTION: Defines pixel registration within grid cell. |
1460 : | |
1461 : | |
1462 : | Return Value Type Units Description |
1463 : | ============ ====== ========= ===================================== |
1464 : | status intn return status (0) SUCCEED, (-1) FAIL |
1465 : | |
1466 : | INPUTS: |
1467 : | gridID int32 grid structure ID |
1468 : | pixregcode int32 Pixel registration code |
1469 : | HDFE_CENTER (0) |
1470 : | HDFE_CORNER (1) |
1471 : | |
1472 : | |
1473 : | OUTPUTS: |
1474 : | None |
1475 : | |
1476 : | NOTES: |
1477 : | |
1478 : | |
1479 : | Date Programmer Description |
1480 : | ====== ============ ================================================= |
1481 : | Jun 96 Joel Gales Original Programmer |
1482 : | |
1483 : | END_PROLOG |
1484 : -----------------------------------------------------------------------------*/
1485 : intn
1486 0 : GDdefpixreg(int32 gridID, int32 pixregcode)
1487 : {
1488 0 : intn status = 0; /* routine return status variable */
1489 :
1490 : int32 fid; /* HDF-EOS file ID */
1491 : int32 gdVgrpID; /* Grid root Vgroup ID */
1492 : int32 sdInterfaceID; /* HDF SDS interface ID */
1493 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
1494 :
1495 : char utlbuf[64]; /* Utility buffer */
1496 : char gridname[80]; /* Grid name */
1497 :
1498 : /* Check for valid grid id */
1499 0 : status = GDchkgdid(gridID, "GDdefpixreg",
1500 : &fid, &sdInterfaceID, &gdVgrpID);
1501 :
1502 0 : if (status == 0)
1503 : {
1504 : /* If proper pix reg code then write to structural metadata */
1505 : /* -------------------------------------------------------- */
1506 0 : if (pixregcode >= 0 && pixregcode < (int32)sizeof(pixregNames))
1507 : {
1508 0 : snprintf(utlbuf, sizeof(utlbuf),"%s%s%s",
1509 : "\t\tPixelRegistration=", pixregNames[pixregcode], "\n");
1510 :
1511 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
1512 0 : status = EHinsertmeta(sdInterfaceID, gridname, "g", 101L,
1513 : utlbuf, NULL);
1514 : }
1515 : else
1516 : {
1517 0 : status = -1;
1518 0 : HEpush(DFE_GENAPP, "GDdefpixreg", __FILE__, __LINE__);
1519 0 : HEreport("Improper Pixel Registration code: %d\n", pixregcode);
1520 : }
1521 : }
1522 :
1523 0 : return (status);
1524 :
1525 : }
1526 :
1527 :
1528 :
1529 :
1530 :
1531 : /*----------------------------------------------------------------------------|
1532 : | BEGIN_PROLOG |
1533 : | |
1534 : | FUNCTION: GDdiminfo |
1535 : | |
1536 : | DESCRIPTION: Retrieve size of specified dimension. |
1537 : | |
1538 : | |
1539 : | Return Value Type Units Description |
1540 : | ============ ====== ========= ===================================== |
1541 : | size int32 Size of dimension |
1542 : | |
1543 : | INPUTS: |
1544 : | gridID int32 grid structure id |
1545 : | dimname char Dimension name |
1546 : | |
1547 : | |
1548 : | OUTPUTS: |
1549 : | None |
1550 : | |
1551 : | NOTES: |
1552 : | |
1553 : | |
1554 : | Date Programmer Description |
1555 : | ====== ============ ================================================= |
1556 : | Jun 96 Joel Gales Original Programmer |
1557 : | Aug 96 Joel Gales Make metadata ODL compliant |
1558 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
1559 : | |
1560 : | END_PROLOG |
1561 : -----------------------------------------------------------------------------*/
1562 : int32
1563 0 : GDdiminfo(int32 gridID, const char *dimname)
1564 :
1565 : {
1566 : intn status; /* routine return status variable */
1567 :
1568 : int32 fid; /* HDF-EOS file ID */
1569 : int32 sdInterfaceID; /* HDF SDS interface ID */
1570 : int32 gdVgrpID; /* Grid root Vgroup ID */
1571 : int32 size; /* Dimension size */
1572 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
1573 :
1574 :
1575 : char *metabuf; /* Pointer to structural metadata (SM) */
1576 : char *metaptrs[2];/* Pointers to begin and end of SM section */
1577 : char gridname[80]; /* Grid Name */
1578 : char *utlstr; /* Utility string */
1579 :
1580 : /* Allocate space for utility string */
1581 : /* --------------------------------- */
1582 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
1583 0 : if(utlstr == NULL)
1584 : {
1585 0 : HEpush(DFE_NOSPACE,"GDdiminfo", __FILE__, __LINE__);
1586 0 : return(-1);
1587 : }
1588 : /* Initialize return value */
1589 : /* ----------------------- */
1590 0 : size = -1;
1591 :
1592 :
1593 : /* Check Grid ID */
1594 : /* ------------- */
1595 0 : status = GDchkgdid(gridID, "GDdiminfo", &fid, &sdInterfaceID, &gdVgrpID);
1596 :
1597 :
1598 0 : if (status == 0)
1599 : {
1600 : /* Get grid name */
1601 : /* ------------- */
1602 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
1603 :
1604 :
1605 : /* Get pointers to "Dimension" section within SM */
1606 : /* --------------------------------------------- */
1607 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
1608 : "Dimension", metaptrs);
1609 :
1610 0 : if(metabuf == NULL)
1611 : {
1612 0 : free(utlstr);
1613 0 : return(-1);
1614 : }
1615 :
1616 : /* Search for dimension name (surrounded by quotes) */
1617 : /* ------------------------------------------------ */
1618 0 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "\"", dimname, "\"\n");
1619 0 : metaptrs[0] = strstr(metaptrs[0], utlstr);
1620 :
1621 : /*
1622 : * If dimension found within grid structure then get dimension value
1623 : */
1624 0 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
1625 : {
1626 : /* Set endptr at end of dimension definition entry */
1627 : /* ----------------------------------------------- */
1628 0 : metaptrs[1] = strstr(metaptrs[0], "\t\t\tEND_OBJECT");
1629 :
1630 0 : status = EHgetmetavalue(metaptrs, "Size", utlstr);
1631 :
1632 0 : if (status == 0)
1633 : {
1634 0 : size = atoi(utlstr);
1635 : }
1636 : else
1637 : {
1638 0 : HEpush(DFE_GENAPP, "GDdiminfo", __FILE__, __LINE__);
1639 0 : HEreport("\"Size\" string not found in metadata.\n");
1640 : }
1641 : }
1642 : else
1643 : {
1644 0 : HEpush(DFE_GENAPP, "GDdiminfo", __FILE__, __LINE__);
1645 0 : HEreport("Dimension \"%s\" not found.\n", dimname);
1646 : }
1647 :
1648 0 : free(metabuf);
1649 : }
1650 0 : free(utlstr);
1651 0 : return (size);
1652 : }
1653 :
1654 :
1655 :
1656 :
1657 :
1658 : /*----------------------------------------------------------------------------|
1659 : | BEGIN_PROLOG |
1660 : | |
1661 : | FUNCTION: GDgridinfo |
1662 : | |
1663 : | DESCRIPTION: Returns xdim, ydim and location of upper left and lower |
1664 : | right corners, in meters. |
1665 : | |
1666 : | |
1667 : | Return Value Type Units Description |
1668 : | ============ ====== ========= ===================================== |
1669 : | status intn return status (0) SUCCEED, (-1) FAIL |
1670 : | |
1671 : | INPUTS: |
1672 : | fid int32 File ID |
1673 : | gridname char Grid structure name |
1674 : | |
1675 : | OUTPUTS: |
1676 : | xdimsize int32 Number of columns in grid |
1677 : | ydimsize int32 Number of rows in grid |
1678 : | upleftpt float64 Location (m/deg) of upper left corner |
1679 : | lowrightpt float64 Location (m/deg) of lower right corner |
1680 : | |
1681 : | NOTES: |
1682 : | |
1683 : | |
1684 : | Date Programmer Description |
1685 : | ====== ============ ================================================= |
1686 : | Jun 96 Joel Gales Original Programmer |
1687 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
1688 : | |
1689 : | END_PROLOG |
1690 : -----------------------------------------------------------------------------*/
1691 : intn
1692 0 : GDgridinfo(int32 gridID, int32 * xdimsize, int32 * ydimsize,
1693 : float64 upleftpt[], float64 lowrightpt[])
1694 :
1695 : {
1696 0 : intn status = 0; /* routine return status variable */
1697 0 : intn statmeta = 0; /* EHgetmetavalue return status */
1698 :
1699 : int32 fid; /* HDF-EOS file ID */
1700 : int32 sdInterfaceID; /* HDF SDS interface ID */
1701 : int32 gdVgrpID; /* Grid root Vgroup ID */
1702 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
1703 :
1704 :
1705 : char *metabuf; /* Pointer to structural metadata (SM) */
1706 : char *metaptrs[2];/* Pointers to begin and end of SM section */
1707 : char gridname[80]; /* Grid Name */
1708 : char *utlstr; /* Utility string */
1709 :
1710 : /* Allocate space for utility string */
1711 : /* --------------------------------- */
1712 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
1713 0 : if(utlstr == NULL)
1714 : {
1715 0 : HEpush(DFE_NOSPACE,"GDgridinfo", __FILE__, __LINE__);
1716 0 : return(-1);
1717 : }
1718 : /* Check Grid ID */
1719 : /* ------------- */
1720 0 : status = GDchkgdid(gridID, "GDgridinfo", &fid, &sdInterfaceID, &gdVgrpID);
1721 :
1722 0 : if (status == 0)
1723 : {
1724 : /* Get grid name */
1725 : /* ------------- */
1726 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
1727 :
1728 :
1729 : /* Get pointers to grid structure section within SM */
1730 : /* ------------------------------------------------ */
1731 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
1732 : NULL, metaptrs);
1733 :
1734 0 : if(metabuf == NULL)
1735 : {
1736 0 : free(utlstr);
1737 0 : return(-1);
1738 : }
1739 :
1740 :
1741 : /* Get xdimsize if requested */
1742 : /* ------------------------- */
1743 0 : if (xdimsize != NULL)
1744 : {
1745 0 : statmeta = EHgetmetavalue(metaptrs, "XDim", utlstr);
1746 0 : if (statmeta == 0)
1747 : {
1748 0 : *xdimsize = atoi(utlstr);
1749 : }
1750 : else
1751 : {
1752 0 : status = -1;
1753 0 : HEpush(DFE_GENAPP, "GDgridinfo", __FILE__, __LINE__);
1754 0 : HEreport("\"XDim\" string not found in metadata.\n");
1755 : }
1756 : }
1757 :
1758 :
1759 : /* Get ydimsize if requested */
1760 : /* ------------------------- */
1761 0 : if (ydimsize != NULL)
1762 : {
1763 0 : statmeta = EHgetmetavalue(metaptrs, "YDim", utlstr);
1764 0 : if (statmeta == 0)
1765 : {
1766 0 : *ydimsize = atoi(utlstr);
1767 : }
1768 : else
1769 : {
1770 0 : status = -1;
1771 0 : HEpush(DFE_GENAPP, "GDgridinfo", __FILE__, __LINE__);
1772 0 : HEreport("\"YDim\" string not found in metadata.\n");
1773 : }
1774 : }
1775 :
1776 :
1777 : /* Get upleftpt if requested */
1778 : /* ------------------------- */
1779 0 : if (upleftpt != NULL)
1780 : {
1781 0 : statmeta = EHgetmetavalue(metaptrs, "UpperLeftPointMtrs", utlstr);
1782 0 : if (statmeta == 0)
1783 : {
1784 : /* If value is "DEFAULT" then return zeros */
1785 : /* --------------------------------------- */
1786 0 : if (strcmp(utlstr, "DEFAULT") == 0)
1787 : {
1788 0 : upleftpt[0] = 0;
1789 0 : upleftpt[1] = 0;
1790 : }
1791 : else
1792 : {
1793 0 : sscanf(utlstr, "(%lf,%lf)",
1794 : &upleftpt[0], &upleftpt[1]);
1795 : }
1796 : }
1797 : else
1798 : {
1799 0 : status = -1;
1800 0 : HEpush(DFE_GENAPP, "GDgridinfo", __FILE__, __LINE__);
1801 0 : HEreport(
1802 : "\"UpperLeftPointMtrs\" string not found in metadata.\n");
1803 : }
1804 :
1805 : }
1806 :
1807 : /* Get lowrightpt if requested */
1808 : /* --------------------------- */
1809 0 : if (lowrightpt != NULL)
1810 : {
1811 0 : statmeta = EHgetmetavalue(metaptrs, "LowerRightMtrs", utlstr);
1812 0 : if (statmeta == 0)
1813 : {
1814 : /* If value is "DEFAULT" then return zeros */
1815 0 : if (strcmp(utlstr, "DEFAULT") == 0)
1816 : {
1817 0 : lowrightpt[0] = 0;
1818 0 : lowrightpt[1] = 0;
1819 : }
1820 : else
1821 : {
1822 0 : sscanf(utlstr, "(%lf,%lf)",
1823 : &lowrightpt[0], &lowrightpt[1]);
1824 : }
1825 : }
1826 : else
1827 : {
1828 0 : status = -1;
1829 0 : HEpush(DFE_GENAPP, "GDgridinfo", __FILE__, __LINE__);
1830 0 : HEreport(
1831 : "\"LowerRightMtrs\" string not found in metadata.\n");
1832 : }
1833 : }
1834 :
1835 0 : free(metabuf);
1836 : }
1837 0 : free(utlstr);
1838 0 : return (status);
1839 : }
1840 :
1841 :
1842 :
1843 :
1844 :
1845 :
1846 :
1847 : /*----------------------------------------------------------------------------|
1848 : | BEGIN_PROLOG |
1849 : | |
1850 : | FUNCTION: GDprojinfo |
1851 : | |
1852 : | DESCRIPTION: Returns GCTP projection code, zone code, spheroid code |
1853 : | and projection parameters. |
1854 : | |
1855 : | |
1856 : | Return Value Type Units Description |
1857 : | ============ ====== ========= ===================================== |
1858 : | status intn return status (0) SUCCEED, (-1) FAIL |
1859 : | |
1860 : | INPUTS: |
1861 : | gridID int32 Grid structure ID |
1862 : | |
1863 : | OUTPUTS: |
1864 : | projcode int32 GCTP projection code |
1865 : | zonecode int32 UTM zone code |
1866 : | spherecode int32 GCTP spheriod code |
1867 : | projparm float64 Projection parameters |
1868 : | |
1869 : | NOTES: |
1870 : | |
1871 : | |
1872 : | Date Programmer Description |
1873 : | ====== ============ ================================================= |
1874 : | Jun 96 Joel Gales Original Programmer |
1875 : | Oct 96 Joel Gales Add check for no projection code |
1876 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
1877 : | Jun 00 Abe Taaheri Added support for EASE grid |
1878 : | |
1879 : | END_PROLOG |
1880 : -----------------------------------------------------------------------------*/
1881 : intn
1882 0 : GDprojinfo(int32 gridID, int32 * projcode, int32 * zonecode,
1883 : int32 * spherecode, float64 projparm[])
1884 :
1885 : {
1886 : intn i; /* Loop index */
1887 : intn projx; /* Loop index */
1888 0 : intn status = 0; /* routine return status variable */
1889 0 : intn statmeta = 0; /* EHgetmetavalue return status */
1890 :
1891 : int32 fid; /* HDF-EOS file ID */
1892 : int32 sdInterfaceID; /* HDF SDS interface ID */
1893 : int32 gdVgrpID; /* Grid root Vgroup ID */
1894 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
1895 :
1896 :
1897 : char *metabuf; /* Pointer to structural metadata (SM) */
1898 : char *metaptrs[2];/* Pointers to begin and end of SM section */
1899 : char gridname[80]; /* Grid Name */
1900 : char *utlstr; /* Utility string */
1901 : char fmt[96]; /* Format String */
1902 :
1903 : /* Allocate space for utility string */
1904 : /* --------------------------------- */
1905 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
1906 0 : if(utlstr == NULL)
1907 : {
1908 0 : HEpush(DFE_NOSPACE,"GDprojinfo", __FILE__, __LINE__);
1909 0 : return(-1);
1910 : }
1911 :
1912 : /* Check Grid ID */
1913 : /* ------------- */
1914 0 : status = GDchkgdid(gridID, "GDprojinfo", &fid, &sdInterfaceID, &gdVgrpID);
1915 :
1916 0 : if (status == 0)
1917 : {
1918 : /* Get grid name */
1919 : /* ------------- */
1920 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
1921 :
1922 :
1923 : /* Get pointers to grid structure section within SM */
1924 : /* ------------------------------------------------ */
1925 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
1926 : NULL, metaptrs);
1927 :
1928 0 : if(metabuf == NULL)
1929 : {
1930 0 : free(utlstr);
1931 0 : return(-1);
1932 : }
1933 :
1934 :
1935 : /* Get projcode if requested */
1936 : /* ------------------------- */
1937 0 : if (projcode != NULL)
1938 : {
1939 0 : *projcode = -1;
1940 :
1941 0 : statmeta = EHgetmetavalue(metaptrs, "Projection", utlstr);
1942 0 : if (statmeta == 0)
1943 : {
1944 : /* Loop through projection codes until found */
1945 : /* ----------------------------------------- */
1946 0 : for (projx = 0; Projections[projx].projcode != -1; projx++)
1947 0 : if (strcmp(utlstr, Projections[projx].projname) == 0)
1948 0 : break;
1949 0 : if (Projections[projx].projname != NULL)
1950 0 : *projcode = Projections[projx].projcode;
1951 : }
1952 : else
1953 : {
1954 0 : status = -1;
1955 0 : HEpush(DFE_GENAPP, "GDprojinfo", __FILE__, __LINE__);
1956 0 : HEreport("Projection Code not defined for \"%s\".\n",
1957 : gridname);
1958 :
1959 0 : if (projparm != NULL)
1960 : {
1961 0 : for (i = 0; i < 13; i++)
1962 : {
1963 0 : projparm[i] = -1;
1964 : }
1965 : }
1966 : }
1967 : }
1968 :
1969 :
1970 : /* Get zonecode if requested */
1971 : /* ------------------------- */
1972 0 : if (zonecode != NULL)
1973 : {
1974 0 : *zonecode = -1;
1975 :
1976 :
1977 : /* Zone code only relevant for UTM and State Code projections */
1978 : /* ---------------------------------------------------------- */
1979 0 : if (*projcode == GCTP_UTM || *projcode == GCTP_SPCS)
1980 : {
1981 0 : statmeta = EHgetmetavalue(metaptrs, "ZoneCode", utlstr);
1982 0 : if (statmeta == 0)
1983 : {
1984 0 : *zonecode = atoi(utlstr);
1985 : }
1986 : else
1987 : {
1988 0 : status = -1;
1989 0 : HEpush(DFE_GENAPP, "GDprojinfo", __FILE__, __LINE__);
1990 0 : HEreport("Zone Code not defined for \"%s\".\n",
1991 : gridname);
1992 : }
1993 : }
1994 : }
1995 :
1996 :
1997 : /* Get projection parameters if requested */
1998 : /* -------------------------------------- */
1999 0 : if (projparm != NULL)
2000 : {
2001 :
2002 : /*
2003 : * Note: No projection parameters for GEO, UTM, and State Code
2004 : * projections
2005 : */
2006 0 : if (*projcode == GCTP_GEO || *projcode == GCTP_UTM ||
2007 0 : *projcode == GCTP_SPCS)
2008 : {
2009 0 : for (i = 0; i < 13; i++)
2010 : {
2011 0 : projparm[i] = 0.0;
2012 : }
2013 :
2014 : }
2015 : else
2016 : {
2017 0 : statmeta = EHgetmetavalue(metaptrs, "ProjParams", utlstr);
2018 :
2019 0 : if (statmeta == 0)
2020 : {
2021 :
2022 : /* Build format string to read projection parameters */
2023 : /* ------------------------------------------------- */
2024 0 : strcpy(fmt, "%lf,");
2025 0 : for (i = 1; i <= 11; i++)
2026 0 : strcat(fmt, "%lf,");
2027 0 : strcat(fmt, "%lf");
2028 :
2029 :
2030 : /* Read parameters from numeric list */
2031 : /* --------------------------------- */
2032 0 : sscanf(&utlstr[1], fmt,
2033 : &projparm[0], &projparm[1],
2034 : &projparm[2], &projparm[3],
2035 : &projparm[4], &projparm[5],
2036 : &projparm[6], &projparm[7],
2037 : &projparm[8], &projparm[9],
2038 : &projparm[10], &projparm[11],
2039 : &projparm[12]);
2040 : }
2041 : else
2042 : {
2043 0 : status = -1;
2044 0 : HEpush(DFE_GENAPP, "GDprojinfo", __FILE__, __LINE__);
2045 0 : HEreport("Projection parameters not defined for \"%s\".\n",
2046 : gridname);
2047 :
2048 : }
2049 : }
2050 : }
2051 :
2052 :
2053 : /* Get spherecode if requested */
2054 : /* --------------------------- */
2055 0 : if (spherecode != NULL)
2056 : {
2057 0 : *spherecode = 0;
2058 :
2059 : /* Note: Spherecode not defined for GEO projection */
2060 : /* ----------------------------------------------- */
2061 0 : if ((*projcode != GCTP_GEO))
2062 : {
2063 0 : EHgetmetavalue(metaptrs, "SphereCode", utlstr);
2064 0 : if (statmeta == 0)
2065 : {
2066 0 : *spherecode = atoi(utlstr);
2067 : }
2068 : }
2069 : }
2070 0 : free(metabuf);
2071 :
2072 : }
2073 0 : free(utlstr);
2074 0 : return (status);
2075 : }
2076 :
2077 :
2078 :
2079 : /*----------------------------------------------------------------------------|
2080 : | BEGIN_PROLOG |
2081 : | |
2082 : | FUNCTION: GDorigininfo |
2083 : | |
2084 : | DESCRIPTION: Returns origin code |
2085 : | |
2086 : | |
2087 : | Return Value Type Units Description |
2088 : | ============ ====== ========= ===================================== |
2089 : | status intn return status (0) SUCCEED, (-1) FAIL |
2090 : | |
2091 : | INPUTS: |
2092 : | gridID int32 Grid structure ID |
2093 : | |
2094 : | |
2095 : | OUTPUTS: |
2096 : | origincode int32 grid origin code |
2097 : | |
2098 : | NOTES: |
2099 : | |
2100 : | |
2101 : | Date Programmer Description |
2102 : | ====== ============ ================================================= |
2103 : | Jun 96 Joel Gales Original Programmer |
2104 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
2105 : | |
2106 : | END_PROLOG |
2107 : -----------------------------------------------------------------------------*/
2108 : intn
2109 0 : GDorigininfo(int32 gridID, int32 * origincode)
2110 : {
2111 : intn i; /* Loop index */
2112 0 : intn status = 0; /* routine return status variable */
2113 0 : intn statmeta = 0; /* EHgetmetavalue return status */
2114 :
2115 : int32 fid; /* HDF-EOS file ID */
2116 : int32 sdInterfaceID; /* HDF SDS interface ID */
2117 : int32 gdVgrpID; /* Grid root Vgroup ID */
2118 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
2119 :
2120 :
2121 : char *metabuf; /* Pointer to structural metadata (SM) */
2122 : char *metaptrs[2];/* Pointers to begin and end of SM section */
2123 : char gridname[80]; /* Grid Name */
2124 : char *utlstr; /* Utility string */
2125 :
2126 : /* Allocate space for utility string */
2127 : /* --------------------------------- */
2128 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
2129 0 : if(utlstr == NULL)
2130 : {
2131 0 : HEpush(DFE_NOSPACE,"GDorigininfo", __FILE__, __LINE__);
2132 0 : return(-1);
2133 : }
2134 : /* Check Grid ID */
2135 : /* ------------- */
2136 0 : status = GDchkgdid(gridID, "GDorigininfo",
2137 : &fid, &sdInterfaceID, &gdVgrpID);
2138 :
2139 :
2140 : /* Initialize pixreg code to -1 (in case of error) */
2141 : /* ----------------------------------------------- */
2142 0 : *origincode = -1;
2143 :
2144 0 : if (status == 0)
2145 : {
2146 : /* Set default origin code */
2147 : /* ----------------------- */
2148 0 : *origincode = 0;
2149 :
2150 :
2151 : /* Get grid name */
2152 : /* ------------- */
2153 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
2154 :
2155 :
2156 : /* Get pointers to grid structure section within SM */
2157 : /* ------------------------------------------------ */
2158 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
2159 : NULL, metaptrs);
2160 :
2161 0 : if(metabuf == NULL)
2162 : {
2163 0 : free(utlstr);
2164 0 : return(-1);
2165 : }
2166 :
2167 :
2168 0 : statmeta = EHgetmetavalue(metaptrs, "GridOrigin", utlstr);
2169 :
2170 0 : if (statmeta == 0)
2171 : {
2172 : /*
2173 : * If "GridOrigin" string found in metadata then convert to
2174 : * numeric origin code (fixed added: Jan 97)
2175 : */
2176 0 : for (i = 0; i < (intn)sizeof(originNames); i++)
2177 : {
2178 0 : if (strcmp(utlstr, originNames[i]) == 0)
2179 : {
2180 0 : *origincode = i;
2181 0 : break;
2182 : }
2183 : }
2184 : }
2185 :
2186 0 : free(metabuf);
2187 : }
2188 0 : free(utlstr);
2189 0 : return (status);
2190 : }
2191 :
2192 :
2193 :
2194 :
2195 :
2196 :
2197 : /*----------------------------------------------------------------------------|
2198 : | BEGIN_PROLOG |
2199 : | |
2200 : | FUNCTION: GDpixreginfo |
2201 : | |
2202 : | DESCRIPTION: |
2203 : | |
2204 : | |
2205 : | Return Value Type Units Description |
2206 : | ============ ====== ========= ===================================== |
2207 : | status intn return status (0) SUCCEED, (-1) FAIL |
2208 : | |
2209 : | INPUTS: |
2210 : | gridID int32 Grid structure ID |
2211 : | |
2212 : | |
2213 : | OUTPUTS: |
2214 : | pixregcode int32 Pixel registration code |
2215 : | |
2216 : | |
2217 : | OUTPUTS: |
2218 : | None |
2219 : | |
2220 : | NOTES: |
2221 : | |
2222 : | |
2223 : | Date Programmer Description |
2224 : | ====== ============ ================================================= |
2225 : | Jun 96 Joel Gales Original Programmer |
2226 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
2227 : | |
2228 : | END_PROLOG |
2229 : -----------------------------------------------------------------------------*/
2230 : intn
2231 0 : GDpixreginfo(int32 gridID, int32 * pixregcode)
2232 : {
2233 : intn i; /* Loop index */
2234 0 : intn status = 0; /* routine return status variable */
2235 0 : intn statmeta = 0; /* EHgetmetavalue return status */
2236 :
2237 : int32 fid; /* HDF-EOS file ID */
2238 : int32 sdInterfaceID; /* HDF SDS interface ID */
2239 : int32 gdVgrpID; /* Grid root Vgroup ID */
2240 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
2241 :
2242 :
2243 : char *metabuf; /* Pointer to structural metadata (SM) */
2244 : char *metaptrs[2];/* Pointers to begin and end of SM section */
2245 : char gridname[80]; /* Grid Name */
2246 : char *utlstr; /* Utility string */
2247 :
2248 : /* Allocate space for utility string */
2249 : /* --------------------------------- */
2250 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
2251 0 : if(utlstr == NULL)
2252 : {
2253 0 : HEpush(DFE_NOSPACE,"GDpixreginfo", __FILE__, __LINE__);
2254 0 : return(-1);
2255 : }
2256 : /* Check Grid ID */
2257 0 : status = GDchkgdid(gridID, "GDpixreginfo",
2258 : &fid, &sdInterfaceID, &gdVgrpID);
2259 :
2260 : /* Initialize pixreg code to -1 (in case of error) */
2261 0 : *pixregcode = -1;
2262 :
2263 0 : if (status == 0)
2264 : {
2265 : /* Set default pixreg code */
2266 0 : *pixregcode = 0;
2267 :
2268 : /* Get grid name */
2269 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
2270 :
2271 : /* Get pointers to grid structure section within SM */
2272 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
2273 : NULL, metaptrs);
2274 :
2275 0 : if(metabuf == NULL)
2276 : {
2277 0 : free(utlstr);
2278 0 : return(-1);
2279 : }
2280 :
2281 :
2282 0 : statmeta = EHgetmetavalue(metaptrs, "PixelRegistration", utlstr);
2283 :
2284 0 : if (statmeta == 0)
2285 : {
2286 : /*
2287 : * If "PixelRegistration" string found in metadata then convert
2288 : * to numeric origin code (fixed added: Jan 97)
2289 : */
2290 :
2291 0 : for (i = 0; i < (intn)sizeof(pixregNames); i++)
2292 : {
2293 0 : if (strcmp(utlstr, pixregNames[i]) == 0)
2294 : {
2295 0 : *pixregcode = i;
2296 0 : break;
2297 : }
2298 : }
2299 : }
2300 0 : free(metabuf);
2301 : }
2302 0 : free(utlstr);
2303 0 : return (status);
2304 : }
2305 :
2306 :
2307 :
2308 : /*----------------------------------------------------------------------------|
2309 : | BEGIN_PROLOG |
2310 : | |
2311 : | FUNCTION: GDcompinfo |
2312 : | |
2313 : | DESCRIPTION: |
2314 : | |
2315 : | |
2316 : | Return Value Type Units Description |
2317 : | ============ ====== ========= ===================================== |
2318 : | status intn |
2319 : | |
2320 : | INPUTS: |
2321 : | gridID int32 |
2322 : | compcode int32 |
2323 : | compparm intn |
2324 : | |
2325 : | |
2326 : | OUTPUTS: |
2327 : | None |
2328 : | |
2329 : | NOTES: |
2330 : | |
2331 : | |
2332 : | Date Programmer Description |
2333 : | ====== ============ ================================================= |
2334 : | Oct 96 Joel Gales Original Programmer |
2335 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
2336 : | |
2337 : | END_PROLOG |
2338 : -----------------------------------------------------------------------------*/
2339 : intn
2340 0 : GDcompinfo(int32 gridID, const char *fieldname, int32 * compcode, intn compparm[])
2341 : {
2342 : intn i; /* Loop index */
2343 0 : intn status = 0; /* routine return status variable */
2344 0 : intn statmeta = 0; /* EHgetmetavalue return status */
2345 :
2346 : int32 fid; /* HDF-EOS file ID */
2347 : int32 sdInterfaceID; /* HDF SDS interface ID */
2348 : int32 gdVgrpID; /* Grid root Vgroup ID */
2349 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
2350 :
2351 :
2352 : char *metabuf; /* Pointer to structural metadata (SM) */
2353 : char *metaptrs[2];/* Pointers to begin and end of SM section */
2354 : char gridname[80]; /* Grid Name */
2355 : char *utlstr;/* Utility string */
2356 :
2357 : /* Allocate space for utility string */
2358 : /* --------------------------------- */
2359 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
2360 0 : if(utlstr == NULL)
2361 : {
2362 0 : HEpush(DFE_NOSPACE,"GDcompinfo", __FILE__, __LINE__);
2363 0 : return(-1);
2364 : }
2365 : /* Check Grid ID */
2366 0 : status = GDchkgdid(gridID, "GDcompinfo", &fid, &sdInterfaceID, &gdVgrpID);
2367 :
2368 :
2369 0 : if (status == 0)
2370 : {
2371 : /* Get grid name */
2372 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
2373 :
2374 : /* Get pointers to "DataField" section within SM */
2375 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
2376 : "DataField", metaptrs);
2377 0 : if(metabuf == NULL)
2378 : {
2379 0 : free(utlstr);
2380 0 : return(-1);
2381 : }
2382 :
2383 :
2384 : /* Search for field */
2385 0 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "\"", fieldname, "\"\n");
2386 0 : metaptrs[0] = strstr(metaptrs[0], utlstr);
2387 :
2388 :
2389 : /* If field found and user wants compression code ... */
2390 0 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
2391 : {
2392 0 : if (compcode != NULL)
2393 : {
2394 : /* Set endptr at end of field's definition entry */
2395 0 : metaptrs[1] = strstr(metaptrs[0], "\t\t\tEND_OBJECT");
2396 :
2397 : /* Get compression type */
2398 0 : statmeta = EHgetmetavalue(metaptrs, "CompressionType", utlstr);
2399 :
2400 : /*
2401 : * Default is no compression if "CompressionType" string not
2402 : * in metadata
2403 : */
2404 0 : *compcode = HDFE_COMP_NONE;
2405 :
2406 : /* If compression code is found ... */
2407 0 : if (statmeta == 0)
2408 : {
2409 : /* Loop through compression types until match */
2410 0 : for (i = 0; i < (intn)sizeof(HDFcomp); i++)
2411 : {
2412 0 : if (strcmp(utlstr, HDFcomp[i]) == 0)
2413 : {
2414 0 : *compcode = i;
2415 0 : break;
2416 : }
2417 : }
2418 : }
2419 : }
2420 :
2421 : /* If user wants compression parameters ... */
2422 0 : if (compparm != NULL && compcode != NULL)
2423 : {
2424 : /* Initialize to zero */
2425 0 : for (i = 0; i < 4; i++)
2426 : {
2427 0 : compparm[i] = 0;
2428 : }
2429 :
2430 : /*
2431 : * Get compression parameters if NBIT or DEFLATE compression
2432 : */
2433 0 : if (*compcode == HDFE_COMP_NBIT)
2434 : {
2435 : statmeta =
2436 0 : EHgetmetavalue(metaptrs, "CompressionParams", utlstr);
2437 0 : if (statmeta == 0)
2438 : {
2439 0 : sscanf(utlstr, "(%d,%d,%d,%d)",
2440 : &compparm[0], &compparm[1],
2441 : &compparm[2], &compparm[3]);
2442 : }
2443 : else
2444 : {
2445 0 : status = -1;
2446 0 : HEpush(DFE_GENAPP, "GDcompinfo", __FILE__, __LINE__);
2447 0 : HEreport(
2448 : "\"CompressionParams\" string not found in metadata.\n");
2449 : }
2450 : }
2451 0 : else if (*compcode == HDFE_COMP_DEFLATE)
2452 : {
2453 : statmeta =
2454 0 : EHgetmetavalue(metaptrs, "DeflateLevel", utlstr);
2455 0 : if (statmeta == 0)
2456 : {
2457 0 : sscanf(utlstr, "%d", &compparm[0]);
2458 : }
2459 : else
2460 : {
2461 0 : status = -1;
2462 0 : HEpush(DFE_GENAPP, "GDcompinfo", __FILE__, __LINE__);
2463 0 : HEreport(
2464 : "\"DeflateLevel\" string not found in metadata.\n");
2465 : }
2466 : }
2467 : }
2468 : }
2469 : else
2470 : {
2471 0 : HEpush(DFE_GENAPP, "GDcompinfo", __FILE__, __LINE__);
2472 0 : HEreport("Fieldname \"%s\" not found.\n", fieldname);
2473 : }
2474 :
2475 0 : free(metabuf);
2476 :
2477 : }
2478 0 : free(utlstr);
2479 0 : return (status);
2480 : }
2481 :
2482 :
2483 :
2484 :
2485 :
2486 :
2487 : /*----------------------------------------------------------------------------|
2488 : | BEGIN_PROLOG |
2489 : | |
2490 : | FUNCTION: GDfieldinfo |
2491 : | |
2492 : | DESCRIPTION: Retrieve information about a specific geolocation or data |
2493 : | field in the grid. |
2494 : | |
2495 : | |
2496 : | Return Value Type Units Description |
2497 : | ============ ====== ========= ===================================== |
2498 : | status intn return status (0) SUCCEED, (-1) FAIL |
2499 : | |
2500 : | INPUTS: |
2501 : | gridID int32 grid structure id |
2502 : | fieldname char name of field |
2503 : | |
2504 : | |
2505 : | OUTPUTS: |
2506 : | rank int32 rank of field (# of dims) |
2507 : | dims int32 field dimensions |
2508 : | numbertype int32 field number type |
2509 : | dimlist char field dimension list |
2510 : | |
2511 : | |
2512 : | OUTPUTS: |
2513 : | None |
2514 : | |
2515 : | NOTES: |
2516 : | |
2517 : | |
2518 : | Date Programmer Description |
2519 : | ====== ============ ================================================= |
2520 : | Jun 96 Joel Gales Original Programmer |
2521 : | Aug 96 Joel Gales Make metadata ODL compliant |
2522 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
2523 : | Feb 99 Abe Taaheri Changed memcpy to memmove to avoid overlapping |
2524 : | problem when copying strings |
2525 : | |
2526 : | END_PROLOG |
2527 : -----------------------------------------------------------------------------*/
2528 : intn
2529 0 : GDfieldinfo(int32 gridID, const char *fieldname, int32 * rank, int32 dims[],
2530 : int32 * numbertype, char *dimlist)
2531 :
2532 : {
2533 : intn i; /* Loop index */
2534 : intn status; /* routine return status variable */
2535 0 : intn statmeta = 0; /* EHgetmetavalue return status */
2536 :
2537 : int32 fid; /* HDF-EOS file ID */
2538 : int32 sdInterfaceID; /* HDF SDS interface ID */
2539 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
2540 0 : int32 ndims = 0; /* Number of dimensions */
2541 : int32 slen[8]; /* Length of each entry in parsed string */
2542 : int32 dum; /* Dummy variable */
2543 : int32 xdim; /* X dim size */
2544 : int32 ydim; /* Y dim size */
2545 : int32 sdid; /* SDS id */
2546 :
2547 : char *metabuf; /* Pointer to structural metadata (SM) */
2548 : char *metaptrs[2]; /* Pointers to begin and end of SM section */
2549 : char gridname[80]; /* Grid Name */
2550 : char *utlstr; /* Utility string */
2551 : char *ptr[8]; /* String pointers for parsed string */
2552 : char dimstr[64]; /* Individual dimension entry string */
2553 :
2554 :
2555 : /* Allocate space for utility string */
2556 : /* --------------------------------- */
2557 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
2558 0 : if(utlstr == NULL)
2559 : {
2560 0 : HEpush(DFE_NOSPACE,"GDfieldinfo", __FILE__, __LINE__);
2561 0 : return(-1);
2562 : }
2563 0 : *rank = -1;
2564 0 : *numbertype = -1;
2565 :
2566 0 : status = GDchkgdid(gridID, "GDfieldinfo", &fid, &sdInterfaceID, &dum);
2567 :
2568 0 : if (status == 0)
2569 : {
2570 :
2571 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
2572 :
2573 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
2574 : "DataField", metaptrs);
2575 0 : if(metabuf == NULL)
2576 : {
2577 0 : free(utlstr);
2578 0 : return(-1);
2579 : }
2580 :
2581 :
2582 : /* Search for field */
2583 0 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "\"", fieldname, "\"\n");
2584 0 : metaptrs[0] = strstr(metaptrs[0], utlstr);
2585 :
2586 : /* If field found ... */
2587 0 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
2588 : {
2589 :
2590 : /* Set endptr at end of dimension definition entry */
2591 0 : metaptrs[1] = strstr(metaptrs[0], "\t\t\tEND_OBJECT");
2592 :
2593 : /* Get DataType string */
2594 0 : statmeta = EHgetmetavalue(metaptrs, "DataType", utlstr);
2595 :
2596 : /* Convert to numbertype code */
2597 0 : if (statmeta == 0)
2598 0 : *numbertype = EHnumstr(utlstr);
2599 : else
2600 : {
2601 0 : status = -1;
2602 0 : HEpush(DFE_GENAPP, "GDfieldinfo", __FILE__, __LINE__);
2603 0 : HEreport("\"DataType\" string not found in metadata.\n");
2604 : }
2605 :
2606 : /*
2607 : * Get DimList string and trim off leading and trailing parens
2608 : * "()"
2609 : */
2610 0 : statmeta = EHgetmetavalue(metaptrs, "DimList", utlstr);
2611 :
2612 0 : if (statmeta == 0)
2613 : {
2614 0 : memmove(utlstr, utlstr + 1, strlen(utlstr) - 2);
2615 0 : utlstr[strlen(utlstr) - 2] = 0;
2616 :
2617 : /* Parse trimmed DimList string and get rank */
2618 0 : ndims = EHparsestr(utlstr, ',', ptr, slen);
2619 0 : *rank = ndims;
2620 : }
2621 : else
2622 : {
2623 0 : status = -1;
2624 0 : HEpush(DFE_GENAPP, "GDfieldinfo", __FILE__, __LINE__);
2625 0 : HEreport("\"DimList\" string not found in metadata.\n");
2626 : }
2627 :
2628 :
2629 0 : if (status == 0)
2630 : {
2631 0 : status = GDgridinfo(gridID, &xdim, &ydim, NULL, NULL);
2632 :
2633 0 : for (i = 0; i < ndims; i++)
2634 : {
2635 0 : memcpy(dimstr, ptr[i] + 1, slen[i] - 2);
2636 0 : dimstr[slen[i] - 2] = 0;
2637 :
2638 0 : if (strcmp(dimstr, "XDim") == 0)
2639 : {
2640 0 : dims[i] = xdim;
2641 : }
2642 0 : else if (strcmp(dimstr, "YDim") == 0)
2643 : {
2644 0 : dims[i] = ydim;
2645 : }
2646 : else
2647 : {
2648 0 : dims[i] = GDdiminfo(gridID, dimstr);
2649 : }
2650 :
2651 :
2652 0 : if (dimlist != NULL)
2653 : {
2654 0 : if (i == 0)
2655 : {
2656 0 : dimlist[0] = 0;
2657 : }
2658 :
2659 0 : if (i > 0)
2660 : {
2661 0 : strcat(dimlist, ",");
2662 : }
2663 0 : strcat(dimlist, dimstr);
2664 : }
2665 : }
2666 :
2667 :
2668 0 : if (dims[0] == 0)
2669 : {
2670 0 : status = GDSDfldsrch(gridID, sdInterfaceID, fieldname,
2671 : &sdid, &dum, &dum, &dum, dims,
2672 : &dum);
2673 : }
2674 : }
2675 : }
2676 :
2677 0 : free(metabuf);
2678 : }
2679 :
2680 0 : if (*rank == -1)
2681 : {
2682 0 : status = -1;
2683 :
2684 0 : HEpush(DFE_GENAPP, "GDfieldinfo", __FILE__, __LINE__);
2685 0 : HEreport("Fieldname \"%s\" not found.\n", fieldname);
2686 : }
2687 0 : free(utlstr);
2688 0 : return (status);
2689 : }
2690 :
2691 :
2692 :
2693 :
2694 :
2695 :
2696 : /*----------------------------------------------------------------------------|
2697 : | BEGIN_PROLOG |
2698 : | |
2699 : | FUNCTION: GDdeffield |
2700 : | |
2701 : | DESCRIPTION: Defines a new data field within the grid. |
2702 : | |
2703 : | |
2704 : | Return Value Type Units Description |
2705 : | ============ ====== ========= ===================================== |
2706 : | status intn return status (0) SUCCEED, (-1) FAIL |
2707 : | |
2708 : | INPUTS: |
2709 : | gridID int32 grid structure ID |
2710 : | fieldname char fieldname |
2711 : | dimlist char Dimension list (comma-separated list) |
2712 : | numbertype int32 field type |
2713 : | merge int32 merge code |
2714 : | |
2715 : | |
2716 : | OUTPUTS: |
2717 : | None |
2718 : | |
2719 : | NOTES: |
2720 : | |
2721 : | |
2722 : | Date Programmer Description |
2723 : | ====== ============ ================================================= |
2724 : | Jun 96 Joel Gales Original Programmer |
2725 : | Aug 96 Joel Gales Check name for ODL compliance |
2726 : | Sep 96 Joel Gales Make string array "dimbuf" dynamic |
2727 : | Sep 96 Joel Gales Add support for Block SOM (MISR) |
2728 : | Jan 97 Joel Gales Add support for tiling |
2729 : | Feb 99 Abe Taaheri Changed strcpy to memmove to avoid overlapping |
2730 : | problem when copying strings |
2731 : | |
2732 : | END_PROLOG |
2733 : -----------------------------------------------------------------------------*/
2734 : intn
2735 0 : GDdeffield(int32 gridID, const char *fieldname, const char *dimlist,
2736 : int32 numbertype, int32 merge)
2737 :
2738 : {
2739 : intn i; /* Loop index */
2740 : intn status; /* routine return status variable */
2741 : intn found; /* utility found flag */
2742 0 : intn foundNT = 0;/* found number type flag */
2743 0 : intn foundAllDim = 1; /* found all dimensions flag */
2744 0 : intn first = 1; /* first entry flag */
2745 :
2746 : int32 fid; /* HDF-EOS file ID */
2747 : int32 vgid; /* Geo/Data field Vgroup ID */
2748 : int32 sdInterfaceID; /* HDF SDS interface ID */
2749 : int32 sdid; /* SDS object ID */
2750 : int32 dimid; /* SDS dimension ID */
2751 : int32 gdVgrpID; /* Grid root Vgroup ID */
2752 : int32 dims[8]; /* Dimension size array */
2753 : int32 dimsize; /* Dimension size */
2754 0 : int32 rank = 0; /* Field rank */
2755 : int32 slen[32]; /* String length array */
2756 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
2757 : int32 compcode; /* Compression code */
2758 : int32 tilecode; /* Tiling code */
2759 : int32 chunkFlag; /* Chunking (Tiling) flag */
2760 : int32 gID; /* GridID - offset */
2761 : int32 xdim; /* Grid X dimension */
2762 : int32 ydim; /* Grid Y dimension */
2763 : int32 projcode; /* Projection Code */
2764 :
2765 : float64 projparm[13]; /* Projection Parameters */
2766 :
2767 : char *dimbuf; /* Dimension buffer */
2768 : char *dimlist0; /* Auxiliary dimension list */
2769 : char *comma; /* Pointer to comma */
2770 : char *dimcheck; /* Dimension check buffer */
2771 : char utlbuf[512];/* Utility buffer */
2772 : char utlbuf2[256]; /* Utility buffer 1 */
2773 : char *ptr[32]; /* String pointer array */
2774 : char gridname[80]; /* Grid name */
2775 : char parmbuf[128]; /* Parameter string buffer */
2776 : char errbuf1[128]; /* Error buffer 1 */
2777 : char errbuf2[128]; /* Error buffer 2 */
2778 : static const char errmsg1[] = "Dimension: %d (size: %d) not divisible by ";
2779 : /* Tiling error message part 1 */
2780 : static const char errmsg2[] = "tile dimension (size: %d).\n";
2781 : /* Tiling error message part 2 */
2782 : char errmsg[128];/* Tiling error message */
2783 :
2784 : /* Valid number types */
2785 : static const uint16 good_number[10] = {
2786 : 3, 4, 5, 6, 20, 21, 22, 23, 24, 25
2787 : };
2788 :
2789 : comp_info c_info; /* Compression parameter structure */
2790 :
2791 : HDF_CHUNK_DEF chunkDef; /* Tiling structure */
2792 :
2793 0 : memset(&c_info, 0, sizeof(c_info));
2794 0 : memset(&chunkDef, 0, sizeof(chunkDef));
2795 :
2796 :
2797 : /* Setup error message strings */
2798 : /* --------------------------- */
2799 0 : strcpy(errbuf1, "GDXSDname array too small.\nPlease increase ");
2800 0 : strcat(errbuf1, "size of HDFE_NAMBUFSIZE in \"HdfEosDef.h\".\n");
2801 0 : strcpy(errbuf2, "GDXSDdims array too small.\nPlease increase ");
2802 0 : strcat(errbuf2, "size of HDFE_DIMBUFSIZE in \"HdfEosDef.h\".\n");
2803 :
2804 :
2805 : /* Build tiling dimension error message */
2806 : /* ------------------------------------ */
2807 0 : strcpy(errmsg, errmsg1);
2808 0 : strcat(errmsg, errmsg2);
2809 :
2810 : /*
2811 : * Check for proper grid ID and return HDF-EOS file ID, SDinterface ID,
2812 : * and grid root Vgroup ID
2813 : */
2814 0 : status = GDchkgdid(gridID, "GDdefinefield",
2815 : &fid, &sdInterfaceID, &gdVgrpID);
2816 :
2817 :
2818 0 : if (status == 0)
2819 : {
2820 : /* Remove offset from grid ID & get gridname */
2821 0 : gID = gridID % idOffset;
2822 0 : Vgetname(GDXGrid[gID].IDTable, gridname);
2823 :
2824 :
2825 : /* Allocate space for dimension buffer and auxiliary dimension list */
2826 : /* ---------------------------------------------------------------- */
2827 0 : dimbuf = (char *) calloc(strlen(dimlist) + 64, 1);
2828 0 : if(dimbuf == NULL)
2829 : {
2830 0 : HEpush(DFE_NOSPACE,"GDdeffield", __FILE__, __LINE__);
2831 0 : return(-1);
2832 : }
2833 0 : dimlist0 = (char *) calloc(strlen(dimlist) + 64, 1);
2834 0 : if(dimlist0 == NULL)
2835 : {
2836 0 : HEpush(DFE_NOSPACE,"GDdeffield", __FILE__, __LINE__);
2837 0 : free(dimbuf);
2838 0 : return(-1);
2839 : }
2840 :
2841 :
2842 : /* Get Grid and Projection info */
2843 : /* ---------------------------- */
2844 0 : status = GDgridinfo(gridID, &xdim, &ydim, NULL, NULL);
2845 0 : status = GDprojinfo(gridID, &projcode, NULL, NULL, projparm);
2846 :
2847 :
2848 : /* Setup Block Dimension if "Blocked" SOM projection */
2849 : /* ------------------------------------------------- */
2850 0 : if (projcode == GCTP_SOM && (int32) projparm[11] != 0)
2851 : {
2852 0 : dimsize = GDdiminfo(gridID, "SOMBlockDim");
2853 :
2854 : /* If "SOMBlockDim" not yet defined then do it */
2855 0 : if (dimsize == -1)
2856 : {
2857 0 : GDdefdim(gridID, "SOMBlockDim", (int32) projparm[11]);
2858 : }
2859 :
2860 : /* If not 1D field then prepend to dimension list */
2861 0 : if (strchr(dimlist, ',') != NULL)
2862 : {
2863 0 : strcpy(dimbuf, "SOMBlockDim,");
2864 0 : strcat(dimbuf, dimlist);
2865 : }
2866 : else
2867 : {
2868 0 : strcpy(dimbuf, dimlist);
2869 : }
2870 : }
2871 : else
2872 : {
2873 : /* If not "Blocked" SOM then just copy dim list to dim buffer */
2874 0 : strcpy(dimbuf, dimlist);
2875 : }
2876 :
2877 : /*
2878 : * Copy dimension buffer to auxiliary dimlist and append a comma to
2879 : * end of dimension list.
2880 : */
2881 0 : strcpy(dimlist0, dimbuf);
2882 0 : strcat(dimbuf, ",");
2883 :
2884 :
2885 : /* Find comma */
2886 : /* ---------- */
2887 0 : comma = strchr(dimbuf, ',');
2888 :
2889 :
2890 : /*
2891 : * Loop through entries in dimension list to make sure they are
2892 : * defined in grid
2893 : */
2894 0 : while (comma != NULL)
2895 : {
2896 : /* Copy dimension list entry to dimcheck */
2897 : /* ------------------------------------- */
2898 0 : dimcheck = (char *) calloc(comma - dimbuf + 1, 1);
2899 0 : if(dimcheck == NULL)
2900 : {
2901 0 : HEpush(DFE_NOSPACE,"GDdeffield", __FILE__, __LINE__);
2902 0 : free(dimbuf);
2903 0 : free(dimlist0);
2904 0 : return(-1);
2905 : }
2906 0 : memcpy(dimcheck, dimbuf, comma - dimbuf);
2907 :
2908 :
2909 : /* Get Dimension Size */
2910 : /* ------------------ */
2911 0 : if (strcmp(dimcheck, "XDim") == 0)
2912 : {
2913 : /* If "XDim" then use xdim value for grid definition */
2914 : /* ------------------------------------------------- */
2915 0 : dimsize = xdim;
2916 0 : found = 1;
2917 0 : dims[rank] = dimsize;
2918 0 : rank++;
2919 : }
2920 0 : else if (strcmp(dimcheck, "YDim") == 0)
2921 : {
2922 : /* If "YDim" then use ydim value for grid definition */
2923 : /* ------------------------------------------------- */
2924 0 : dimsize = ydim;
2925 0 : found = 1;
2926 0 : dims[rank] = dimsize;
2927 0 : rank++;
2928 : }
2929 : else
2930 : {
2931 : /* "Regular" Dimension */
2932 : /* ------------------- */
2933 0 : dimsize = GDdiminfo(gridID, dimcheck);
2934 0 : if (dimsize != -1)
2935 : {
2936 0 : found = 1;
2937 0 : dims[rank] = dimsize;
2938 0 : rank++;
2939 : }
2940 : else
2941 : {
2942 0 : found = 0;
2943 : }
2944 : }
2945 :
2946 :
2947 : /*
2948 : * If dimension list entry not found - set error return status,
2949 : * append name to utility buffer for error report
2950 : */
2951 0 : if (found == 0)
2952 : {
2953 0 : status = -1;
2954 0 : foundAllDim = 0;
2955 0 : if (first == 1)
2956 : {
2957 0 : strcpy(utlbuf, dimcheck);
2958 : }
2959 : else
2960 : {
2961 0 : strcat(utlbuf, ",");
2962 0 : strcat(utlbuf, dimcheck);
2963 : }
2964 0 : first = 0;
2965 : }
2966 :
2967 : /*
2968 : * Go to next dimension entry, find next comma, & free up
2969 : * dimcheck buffer
2970 : */
2971 0 : memmove(dimbuf, comma + 1, strlen(comma)-1);
2972 0 : dimbuf[strlen(comma)-1]= 0;
2973 0 : comma = strchr(dimbuf, ',');
2974 0 : free(dimcheck);
2975 : }
2976 0 : free(dimbuf);
2977 :
2978 : /* Check fieldname length */
2979 : /* ---------------------- */
2980 0 : if (status == 0)
2981 : {
2982 : /* if ((intn) strlen(fieldname) > MAX_NC_NAME - 7)
2983 : ** this was changed because HDF4.1r3 made a change in the
2984 : ** hlimits.h file. We have notified NCSA and asked to have
2985 : ** it made the same as in previous versions of HDF
2986 : ** see ncr 26314. DaW Apr 2000
2987 : */
2988 0 : if((intn) strlen(fieldname) > (256 - 7))
2989 : {
2990 0 : status = -1;
2991 0 : HEpush(DFE_GENAPP, "GDdefinefield", __FILE__, __LINE__);
2992 0 : HEreport("Fieldname \"%s\" too long.\n", fieldname);
2993 : }
2994 : }
2995 :
2996 : /* Check for valid numbertype */
2997 : /* -------------------------- */
2998 0 : if (status == 0)
2999 : {
3000 0 : for (i = 0; i < 10; i++)
3001 : {
3002 0 : if (numbertype == good_number[i])
3003 : {
3004 0 : foundNT = 1;
3005 0 : break;
3006 : }
3007 : }
3008 :
3009 0 : if (foundNT == 0)
3010 : {
3011 0 : HEpush(DFE_BADNUMTYPE, "GDdeffield", __FILE__, __LINE__);
3012 0 : HEreport("Invalid number type: %d (%s).\n",
3013 : numbertype, fieldname);
3014 0 : status = -1;
3015 : }
3016 : }
3017 :
3018 :
3019 : /* Define Field */
3020 : /* ------------ */
3021 0 : if (status == 0)
3022 : {
3023 : /* Get Field Vgroup id, compression code, & tiling code */
3024 : /* -------------------------------------------------- */
3025 0 : vgid = GDXGrid[gID].VIDTable[0];
3026 0 : compcode = GDXGrid[gID].compcode;
3027 0 : tilecode = GDXGrid[gID].tilecode;
3028 :
3029 :
3030 : /* SDS Interface (Multi-dim fields) */
3031 : /* -------------------------------- */
3032 :
3033 :
3034 : /*
3035 : * If rank is less than or equal to 3 (and greater than 1) and
3036 : * AUTOMERGE is set and the first dimension is not appendable and
3037 : * the compression code is set to none then ...
3038 : */
3039 0 : if (rank >= 2 && rank <= 3 && merge == HDFE_AUTOMERGE &&
3040 0 : dims[0] != 0 && compcode == HDFE_COMP_NONE &&
3041 : tilecode == HDFE_NOTILE)
3042 : {
3043 :
3044 : /* Find first empty slot in external combination array */
3045 : /* --------------------------------------------------- */
3046 0 : i = 0;
3047 0 : while (GDXSDcomb[5 * i] != 0)
3048 : {
3049 0 : i++;
3050 : }
3051 :
3052 : /*
3053 : * Store dimensions, grid root Vgroup ID, and number type in
3054 : * external combination array "GDXSDcomb"
3055 : */
3056 0 : if (rank == 2)
3057 : {
3058 : /* If 2-dim field then set lowest dimension to 1 */
3059 : /* --------------------------------------------- */
3060 0 : GDXSDcomb[5 * i] = 1;
3061 0 : GDXSDcomb[5 * i + 1] = dims[0];
3062 0 : GDXSDcomb[5 * i + 2] = dims[1];
3063 : }
3064 : else
3065 : {
3066 0 : GDXSDcomb[5 * i] = dims[0];
3067 0 : GDXSDcomb[5 * i + 1] = dims[1];
3068 0 : GDXSDcomb[5 * i + 2] = dims[2];
3069 : }
3070 :
3071 0 : GDXSDcomb[5 * i + 3] = gdVgrpID;
3072 0 : GDXSDcomb[5 * i + 4] = numbertype;
3073 :
3074 :
3075 : /* Concatenate fieldname with combined name string */
3076 : /* ----------------------------------------------- */
3077 0 : if ((intn) strlen(GDXSDname) +
3078 0 : (intn) strlen(fieldname) + 2 < HDFE_NAMBUFSIZE)
3079 : {
3080 0 : strcat(GDXSDname, fieldname);
3081 0 : strcat(GDXSDname, ",");
3082 : }
3083 : else
3084 : {
3085 : /* GDXSDname array too small! */
3086 : /* -------------------------- */
3087 0 : HEpush(DFE_GENAPP, "GDdefinefield",
3088 : __FILE__, __LINE__);
3089 0 : HEreport(errbuf1);
3090 0 : status = -1;
3091 0 : free(dimlist0);
3092 0 : return (status);
3093 : }
3094 :
3095 :
3096 : /*
3097 : * If 2-dim field then set lowest dimension (in 3-dim array)
3098 : * to "ONE"
3099 : */
3100 0 : if (rank == 2)
3101 : {
3102 0 : if ((intn) strlen(GDXSDdims) + 5 < HDFE_DIMBUFSIZE)
3103 : {
3104 0 : strcat(GDXSDdims, "ONE,");
3105 : }
3106 : else
3107 : {
3108 : /* GDXSDdims array too small! */
3109 : /* -------------------------- */
3110 0 : HEpush(DFE_GENAPP, "GDdefinefield",
3111 : __FILE__, __LINE__);
3112 0 : HEreport(errbuf2);
3113 0 : status = -1;
3114 0 : free(dimlist0);
3115 0 : return (status);
3116 : }
3117 : }
3118 :
3119 :
3120 : /*
3121 : * Concatanate field dimlist to merged dimlist and separate
3122 : * fields with semi-colon.
3123 : */
3124 0 : if ((intn) strlen(GDXSDdims) +
3125 0 : (intn) strlen(dimlist0) + 2 < HDFE_DIMBUFSIZE)
3126 : {
3127 0 : strcat(GDXSDdims, dimlist0);
3128 0 : strcat(GDXSDdims, ";");
3129 : }
3130 : else
3131 : {
3132 : /* GDXSDdims array too small! */
3133 : /* -------------------------- */
3134 0 : HEpush(DFE_GENAPP, "GDdefinefield",
3135 : __FILE__, __LINE__);
3136 0 : HEreport(errbuf2);
3137 0 : status = -1;
3138 0 : free(dimlist0);
3139 0 : return (status);
3140 : }
3141 :
3142 : } /* End Multi-Dim Merge Section */
3143 : else
3144 : {
3145 :
3146 : /* Multi-Dim No Merge Section */
3147 : /* ========================== */
3148 :
3149 :
3150 : /* Check that field dims are divisible by tile dims */
3151 : /* ------------------------------------------------ */
3152 0 : if (tilecode == HDFE_TILE)
3153 : {
3154 0 : for (i = 0; i < GDXGrid[gID].tilerank; i++)
3155 : {
3156 0 : if ((dims[i] % GDXGrid[gID].tiledims[i]) != 0)
3157 : {
3158 0 : HEpush(DFE_GENAPP, "GDdeffield",
3159 : __FILE__, __LINE__);
3160 0 : HEreport(errmsg,
3161 : i, dims[i], GDXGrid[gID].tiledims[0]);
3162 0 : status = -1;
3163 : }
3164 : }
3165 :
3166 0 : if (status == -1)
3167 : {
3168 0 : free(dimlist0);
3169 0 : return (status);
3170 : }
3171 : }
3172 :
3173 :
3174 : /* Create SDS dataset */
3175 : /* ------------------ */
3176 0 : sdid = SDcreate(sdInterfaceID, fieldname,
3177 : numbertype, rank, dims);
3178 :
3179 :
3180 : /* Store Dimension Names in SDS */
3181 : /* ---------------------------- */
3182 0 : rank = EHparsestr(dimlist0, ',', ptr, slen);
3183 0 : for (i = 0; i < rank; i++)
3184 : {
3185 : /* Dimension name = Swathname:Dimname */
3186 : /* ---------------------------------- */
3187 0 : memcpy(utlbuf, ptr[i], slen[i]);
3188 0 : utlbuf[slen[i]] = 0;
3189 0 : strcat(utlbuf, ":");
3190 0 : strcat(utlbuf, gridname);
3191 :
3192 0 : dimid = SDgetdimid(sdid, i);
3193 0 : SDsetdimname(dimid, utlbuf);
3194 : }
3195 :
3196 :
3197 : /* Setup Compression */
3198 : /* ----------------- */
3199 0 : if (compcode == HDFE_COMP_NBIT)
3200 : {
3201 0 : c_info.nbit.nt = numbertype;
3202 0 : c_info.nbit.sign_ext = GDXGrid[gID].compparm[0];
3203 0 : c_info.nbit.fill_one = GDXGrid[gID].compparm[1];
3204 0 : c_info.nbit.start_bit = GDXGrid[gID].compparm[2];
3205 0 : c_info.nbit.bit_len = GDXGrid[gID].compparm[3];
3206 : }
3207 0 : else if (compcode == HDFE_COMP_SKPHUFF)
3208 : {
3209 0 : c_info.skphuff.skp_size = (intn) DFKNTsize(numbertype);
3210 : }
3211 0 : else if (compcode == HDFE_COMP_DEFLATE)
3212 : {
3213 0 : c_info.deflate.level = GDXGrid[gID].compparm[0];
3214 : }
3215 :
3216 :
3217 : /* If field is compressed w/o tiling then call SDsetcompress */
3218 : /* --------------------------------------------------------- */
3219 0 : if (compcode != HDFE_COMP_NONE && tilecode == HDFE_NOTILE)
3220 : {
3221 0 : /* status = */ SDsetcompress(sdid, (comp_coder_t) compcode, &c_info);
3222 : }
3223 :
3224 :
3225 : /* Setup Tiling */
3226 : /* ------------ */
3227 0 : if (tilecode == HDFE_TILE)
3228 : {
3229 : /* Tiling without Compression */
3230 : /* -------------------------- */
3231 0 : if (compcode == HDFE_COMP_NONE)
3232 : {
3233 :
3234 : /* Setup chunk lengths */
3235 : /* ------------------- */
3236 0 : for (i = 0; i < GDXGrid[gID].tilerank; i++)
3237 : {
3238 0 : chunkDef.chunk_lengths[i] =
3239 0 : GDXGrid[gID].tiledims[i];
3240 : }
3241 :
3242 0 : chunkFlag = HDF_CHUNK;
3243 : }
3244 :
3245 : /* Tiling with Compression */
3246 : /* ----------------------- */
3247 : else
3248 : {
3249 : /* Setup chunk lengths */
3250 : /* ------------------- */
3251 0 : for (i = 0; i < GDXGrid[gID].tilerank; i++)
3252 : {
3253 0 : chunkDef.comp.chunk_lengths[i] =
3254 0 : GDXGrid[gID].tiledims[i];
3255 : }
3256 :
3257 :
3258 : /* Setup chunk flag & chunk compression type */
3259 : /* ----------------------------------------- */
3260 0 : chunkFlag = HDF_CHUNK | HDF_COMP;
3261 0 : chunkDef.comp.comp_type = compcode;
3262 :
3263 :
3264 : /* Setup chunk compression parameters */
3265 : /* ---------------------------------- */
3266 0 : if (compcode == HDFE_COMP_SKPHUFF)
3267 : {
3268 0 : chunkDef.comp.cinfo.skphuff.skp_size =
3269 0 : c_info.skphuff.skp_size;
3270 : }
3271 0 : else if (compcode == HDFE_COMP_DEFLATE)
3272 : {
3273 0 : chunkDef.comp.cinfo.deflate.level =
3274 0 : c_info.deflate.level;
3275 : }
3276 : }
3277 :
3278 : /* Call SDsetchunk routine */
3279 : /* ----------------------- */
3280 0 : /* status = */ SDsetchunk(sdid, chunkDef, chunkFlag);
3281 : }
3282 :
3283 :
3284 : /* Attach to Vgroup */
3285 : /* ---------------- */
3286 0 : Vaddtagref(vgid, DFTAG_NDG, SDidtoref(sdid));
3287 :
3288 :
3289 : /* Store SDS dataset IDs */
3290 : /* --------------------- */
3291 :
3292 : /* Allocate space for the SDS ID array */
3293 : /* ----------------------------------- */
3294 0 : if (GDXGrid[gID].nSDS > 0)
3295 : {
3296 : /* Array already exists therefore reallocate */
3297 : /* ----------------------------------------- */
3298 0 : GDXGrid[gID].sdsID = (int32 *)
3299 0 : realloc((void *) GDXGrid[gID].sdsID,
3300 0 : (GDXGrid[gID].nSDS + 1) * 4);
3301 0 : if(GDXGrid[gID].sdsID == NULL)
3302 : {
3303 0 : HEpush(DFE_NOSPACE,"GDdeffield", __FILE__, __LINE__);
3304 0 : free(dimlist0);
3305 0 : return(-1);
3306 : }
3307 : }
3308 : else
3309 : {
3310 : /* Array does not exist */
3311 : /* -------------------- */
3312 0 : GDXGrid[gID].sdsID = (int32 *) calloc(1, 4);
3313 0 : if(GDXGrid[gID].sdsID == NULL)
3314 : {
3315 0 : HEpush(DFE_NOSPACE,"GDdeffield", __FILE__, __LINE__);
3316 0 : free(dimlist0);
3317 0 : return(-1);
3318 : }
3319 : }
3320 :
3321 : /* Store SDS ID in array & increment count */
3322 : /* --------------------------------------- */
3323 0 : GDXGrid[gID].sdsID[GDXGrid[gID].nSDS] = sdid;
3324 0 : GDXGrid[gID].nSDS++;
3325 :
3326 : }
3327 :
3328 :
3329 : /* Setup metadata string */
3330 : /* --------------------- */
3331 0 : snprintf(utlbuf, sizeof(utlbuf), "%s%s%s", fieldname, ":", dimlist0);
3332 :
3333 :
3334 : /* Setup compression metadata */
3335 : /* -------------------------- */
3336 0 : if (compcode != HDFE_COMP_NONE)
3337 : {
3338 0 : snprintf(utlbuf2, sizeof(utlbuf2),
3339 : "%s%s",
3340 : ":\n\t\t\t\tCompressionType=", HDFcomp[compcode]);
3341 :
3342 0 : switch (compcode)
3343 : {
3344 0 : case HDFE_COMP_NBIT:
3345 :
3346 0 : snprintf(parmbuf, sizeof(parmbuf),
3347 : "%s%d,%d,%d,%d%s",
3348 : "\n\t\t\t\tCompressionParams=(",
3349 : GDXGrid[gID].compparm[0],
3350 : GDXGrid[gID].compparm[1],
3351 : GDXGrid[gID].compparm[2],
3352 : GDXGrid[gID].compparm[3], ")");
3353 0 : strcat(utlbuf2, parmbuf);
3354 0 : break;
3355 :
3356 :
3357 0 : case HDFE_COMP_DEFLATE:
3358 :
3359 0 : snprintf(parmbuf, sizeof(parmbuf),
3360 : "%s%d",
3361 : "\n\t\t\t\tDeflateLevel=",
3362 : GDXGrid[gID].compparm[0]);
3363 0 : strcat(utlbuf2, parmbuf);
3364 0 : break;
3365 : }
3366 0 : strcat(utlbuf, utlbuf2);
3367 : }
3368 :
3369 :
3370 :
3371 :
3372 : /* Setup tiling metadata */
3373 : /* --------------------- */
3374 0 : if (tilecode == HDFE_TILE)
3375 : {
3376 0 : if (compcode == HDFE_COMP_NONE)
3377 : {
3378 0 : snprintf(utlbuf2, sizeof(utlbuf2), "%s%d",
3379 : ":\n\t\t\t\tTilingDimensions=(",
3380 0 : (int)GDXGrid[gID].tiledims[0]);
3381 : }
3382 : else
3383 : {
3384 0 : snprintf(utlbuf2, sizeof(utlbuf2), "%s%d",
3385 : "\n\t\t\t\tTilingDimensions=(",
3386 0 : (int)GDXGrid[gID].tiledims[0]);
3387 : }
3388 :
3389 0 : for (i = 1; i < GDXGrid[gID].tilerank; i++)
3390 : {
3391 0 : snprintf(parmbuf, sizeof(parmbuf), ",%d", (int)GDXGrid[gID].tiledims[i]);
3392 0 : strcat(utlbuf2, parmbuf);
3393 : }
3394 0 : strcat(utlbuf2, ")");
3395 0 : strcat(utlbuf, utlbuf2);
3396 : }
3397 :
3398 :
3399 : /* Insert field metadata within File Structural Metadata */
3400 : /* ----------------------------------------------------- */
3401 0 : status = EHinsertmeta(sdInterfaceID, gridname, "g", 4L,
3402 : utlbuf, &numbertype);
3403 :
3404 : }
3405 0 : free(dimlist0);
3406 :
3407 : }
3408 :
3409 : /* If all dimensions not found then report error */
3410 : /* --------------------------------------------- */
3411 0 : if (foundAllDim == 0)
3412 : {
3413 0 : HEpush(DFE_GENAPP, "GDdeffield", __FILE__, __LINE__);
3414 0 : HEreport("Dimension(s): \"%s\" not found (%s).\n",
3415 : utlbuf, fieldname);
3416 0 : status = -1;
3417 : }
3418 :
3419 0 : return (status);
3420 : }
3421 :
3422 :
3423 :
3424 :
3425 : /*----------------------------------------------------------------------------|
3426 : | BEGIN_PROLOG |
3427 : | |
3428 : | FUNCTION: GDwritefieldmeta |
3429 : | |
3430 : | DESCRIPTION: Writes field meta data for an existing grid field not |
3431 : | defined within the grid API routine "GDdeffield". |
3432 : | |
3433 : | Return Value Type Units Description |
3434 : | ============ ====== ========= ===================================== |
3435 : | status intn return status (0) SUCCEED, (-1) FAIL |
3436 : | |
3437 : | INPUTS: |
3438 : | gridID int32 grid structure ID |
3439 : | fieldname char fieldname |
3440 : | dimlist char Dimension list (comma-separated list) |
3441 : | numbertype int32 field type |
3442 : | |
3443 : | |
3444 : | OUTPUTS: |
3445 : | None |
3446 : | |
3447 : | NOTES: |
3448 : | |
3449 : | |
3450 : | Date Programmer Description |
3451 : | ====== ============ ================================================= |
3452 : | Jun 96 Joel Gales Original Programmer |
3453 : | |
3454 : | END_PROLOG |
3455 : -----------------------------------------------------------------------------*/
3456 : intn
3457 0 : GDwritefieldmeta(int32 gridID, const char *fieldname, const char *dimlist,
3458 : int32 numbertype)
3459 : {
3460 0 : intn status = 0; /* routine return status variable */
3461 :
3462 : int32 sdInterfaceID; /* HDF SDS interface ID */
3463 : int32 dum; /* dummy variable */
3464 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
3465 :
3466 : char utlbuf[256];/* Utility buffer */
3467 : char gridname[80]; /* Grid name */
3468 :
3469 :
3470 0 : status = GDchkgdid(gridID, "GDwritefieldmeta", &dum, &sdInterfaceID,
3471 : &dum);
3472 :
3473 0 : if (status == 0)
3474 : {
3475 0 : snprintf(utlbuf, sizeof(utlbuf), "%s%s%s", fieldname, ":", dimlist);
3476 :
3477 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
3478 0 : status = EHinsertmeta(sdInterfaceID, gridname, "g", 4L,
3479 : utlbuf, &numbertype);
3480 : }
3481 0 : return (status);
3482 : }
3483 :
3484 :
3485 :
3486 :
3487 : /*----------------------------------------------------------------------------|
3488 : | BEGIN_PROLOG |
3489 : | |
3490 : | FUNCTION: GDSDfldsrch |
3491 : | |
3492 : | DESCRIPTION: Retrieves information from SDS fields |
3493 : | |
3494 : | |
3495 : | Return Value Type Units Description |
3496 : | ============ ====== ========= ===================================== |
3497 : | status intn return status (0) SUCCEED, (-1) FAIL |
3498 : | |
3499 : | INPUTS: |
3500 : | gridID int32 grid structure ID |
3501 : | sdInterfaceID int32 SD interface ID |
3502 : | fieldname char field name |
3503 : | |
3504 : | |
3505 : | OUTPUTS: |
3506 : | sdid int32 SD element ID |
3507 : | rankSDS int32 Rank of SDS |
3508 : | rankFld int32 True rank of field (merging) |
3509 : | offset int32 Offset of field within merged field |
3510 : | dims int32 Dimensions of field |
3511 : | solo int32 Solo field flag |
3512 : | |
3513 : | NOTES: |
3514 : | |
3515 : | |
3516 : | Date Programmer Description |
3517 : | ====== ============ ================================================= |
3518 : | Jun 96 Joel Gales Original Programmer |
3519 : | Aug 96 Joel Gales Make metadata ODL compliant |
3520 : | |
3521 : | END_PROLOG |
3522 : -----------------------------------------------------------------------------*/
3523 : static intn
3524 0 : GDSDfldsrch(int32 gridID, int32 sdInterfaceID, const char *fieldname,
3525 : int32 * sdid, int32 * rankSDS, int32 * rankFld, int32 * offset,
3526 : int32 dims[], int32 * solo)
3527 : {
3528 : intn i; /* Loop index */
3529 0 : intn status = -1;/* routine return status variable */
3530 :
3531 : int32 gID; /* GridID - offset */
3532 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
3533 : int32 dum; /* Dummy variable */
3534 : int32 dums[128]; /* Dummy array */
3535 : int32 attrIndex; /* Attribute l_index */
3536 :
3537 : char name[2048]; /* Merged-Field Names */
3538 : char gridname[80]; /* Grid Name */
3539 : char *utlstr;/* Utility string */
3540 : char *metabuf; /* Pointer to structural metadata (SM) */
3541 : char *metaptrs[2];/* Pointers to begin and end of SM section */
3542 : #ifdef broken_logic
3543 : char *oldmetaptr; /* Pointer within SM section */
3544 : char *metaptr; /* Pointer within SM section */
3545 : #endif
3546 :
3547 : /* Allocate space for utility string */
3548 : /* --------------------------------- */
3549 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
3550 0 : if(utlstr == NULL)
3551 : {
3552 0 : HEpush(DFE_NOSPACE,"GDSDfldsrch", __FILE__, __LINE__);
3553 0 : return(-1);
3554 : }
3555 : /* Set solo flag to 0 (no) */
3556 : /* ----------------------- */
3557 0 : *solo = 0;
3558 :
3559 :
3560 : /* Compute "reduced" grid ID */
3561 : /* ------------------------- */
3562 0 : gID = gridID % idOffset;
3563 :
3564 :
3565 : /* Loop through all SDSs in grid */
3566 : /* ----------------------------- */
3567 0 : for (i = 0; i < GDXGrid[gID].nSDS; i++)
3568 : {
3569 : /* If active SDS ... */
3570 : /* ----------------- */
3571 0 : if (GDXGrid[gID].sdsID[i] != 0)
3572 : {
3573 : /* Get SDS ID, name, rankSDS, and dimensions */
3574 : /* ----------------------------------------- */
3575 0 : *sdid = GDXGrid[gID].sdsID[i];
3576 0 : SDgetinfo(*sdid, name, rankSDS, dims, &dum, &dum);
3577 0 : *rankFld = *rankSDS;
3578 :
3579 :
3580 : /* If merged field ... */
3581 : /* ------------------- */
3582 0 : if (strstr(name, "MRGFLD_") == &name[0])
3583 : {
3584 : /* Get grid name */
3585 : /* ------------- */
3586 0 : Vgetname(GDXGrid[gID].IDTable, gridname);
3587 :
3588 :
3589 : /* Get pointers to "MergedFields" section within SM */
3590 : /* ------------------------------------------------ */
3591 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
3592 : "MergedFields", metaptrs);
3593 0 : if(metabuf == NULL)
3594 : {
3595 0 : free(utlstr);
3596 0 : return(-1);
3597 : }
3598 :
3599 : #ifdef broken_logic
3600 : /* Initialize metaptr to beg. of section */
3601 : /* ------------------------------------- */
3602 : metaptr = metaptrs[0];
3603 :
3604 :
3605 : /* Store metaptr in order to recover */
3606 : /* --------------------------------- */
3607 : oldmetaptr = metaptr;
3608 :
3609 :
3610 : /* Search for Merged field name */
3611 : /* ---------------------------- */
3612 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "MergedFieldName=\"",
3613 : name, "\"\n");
3614 : metaptr = strstr(metaptr, utlstr);
3615 :
3616 :
3617 : /* If not found check for old metadata */
3618 : /* ----------------------------------- */
3619 : if (metaptr == NULL)
3620 : {
3621 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "OBJECT=\"", name, "\"\n");
3622 : metaptr = strstr(oldmetaptr, utlstr);
3623 : }
3624 : #endif
3625 :
3626 : /* Get field list and strip off leading and trailing quotes */
3627 : /* -------------------------------------------------------- */
3628 0 : EHgetmetavalue(metaptrs, "FieldList", name);
3629 0 : memmove(name, name + 1, strlen(name) - 2);
3630 0 : name[strlen(name) - 2] = 0;
3631 :
3632 :
3633 : /* Search for desired field within merged field list */
3634 : /* ------------------------------------------------- */
3635 0 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "\"", fieldname, "\"");
3636 0 : dum = EHstrwithin(utlstr, name, ',');
3637 :
3638 0 : free(metabuf);
3639 : }
3640 : else
3641 : {
3642 : /* If solo (unmerged) check if SDS name matches fieldname */
3643 : /* ------------------------------------------------------ */
3644 0 : dum = EHstrwithin(fieldname, name, ',');
3645 0 : if (dum != -1)
3646 : {
3647 0 : *solo = 1;
3648 0 : *offset = 0;
3649 : }
3650 : }
3651 :
3652 :
3653 :
3654 : /* If field found ... */
3655 : /* ------------------ */
3656 0 : if (dum != -1)
3657 : {
3658 0 : status = 0;
3659 :
3660 : /* If merged field ... */
3661 : /* ------------------- */
3662 0 : if (*solo == 0)
3663 : {
3664 : /* Get "Field Offsets" SDS attribute l_index */
3665 : /* --------------------------------------- */
3666 0 : attrIndex = SDfindattr(*sdid, "Field Offsets");
3667 :
3668 : /*
3669 : * If attribute exists then get offset of desired field
3670 : * within merged field
3671 : */
3672 0 : if (attrIndex != -1)
3673 : {
3674 0 : SDreadattr(*sdid, attrIndex, (VOIDP) dums);
3675 0 : *offset = dums[dum];
3676 : }
3677 :
3678 :
3679 : /* Get "Field Dims" SDS attribute l_index */
3680 : /* ------------------------------------ */
3681 0 : attrIndex = SDfindattr(*sdid, "Field Dims");
3682 :
3683 : /*
3684 : * If attribute exists then get 0th dimension of desired
3685 : * field within merged field
3686 : */
3687 0 : if (attrIndex != -1)
3688 : {
3689 0 : SDreadattr(*sdid, attrIndex, (VOIDP) dums);
3690 0 : dims[0] = dums[dum];
3691 :
3692 : /* If this dimension = 1 then field is really 2 dim */
3693 : /* ------------------------------------------------ */
3694 0 : if (dums[dum] == 1)
3695 : {
3696 0 : *rankFld = 2;
3697 : }
3698 : }
3699 : }
3700 :
3701 :
3702 : /* Break out of SDS loop */
3703 : /* --------------------- */
3704 0 : break;
3705 : } /* End of found field section */
3706 : }
3707 : else
3708 : {
3709 : /* First non-active SDS signifies no more, break out of SDS loop */
3710 : /* ------------------------------------------------------------- */
3711 0 : break;
3712 : }
3713 : }
3714 0 : free(utlstr);
3715 0 : return (status);
3716 : }
3717 :
3718 :
3719 :
3720 :
3721 : /*----------------------------------------------------------------------------|
3722 : | BEGIN_PROLOG |
3723 : | |
3724 : | FUNCTION: GDwrrdfield |
3725 : | |
3726 : | DESCRIPTION: Writes/Reads fields |
3727 : | |
3728 : | |
3729 : | Return Value Type Units Description |
3730 : | ============ ====== ========= ===================================== |
3731 : | status intn return status (0) SUCCEED, (-1) FAIL |
3732 : | |
3733 : | INPUTS: |
3734 : | gridID int32 grid structure ID |
3735 : | fieldname char fieldname |
3736 : | code char Write/Read code (w/r) |
3737 : | start int32 start array |
3738 : | stride int32 stride array |
3739 : | edge int32 edge array |
3740 : | datbuf void data buffer for read |
3741 : | |
3742 : | |
3743 : | OUTPUTS: |
3744 : | datbuf void data buffer for write |
3745 : | |
3746 : | |
3747 : | NOTES: |
3748 : | |
3749 : | |
3750 : | Date Programmer Description |
3751 : | ====== ============ ================================================= |
3752 : | Jun 96 Joel Gales Original Programmer |
3753 : | Feb 97 Joel Gales Stride = 1 HDF compression workaround |
3754 : | |
3755 : | END_PROLOG |
3756 : -----------------------------------------------------------------------------*/
3757 : static intn
3758 0 : GDwrrdfield(int32 gridID, const char *fieldname, const char *code,
3759 : int32 start[], int32 stride[], int32 edge[], VOIDP datbuf)
3760 :
3761 : {
3762 : intn i; /* Loop index */
3763 0 : intn status = 0; /* routine return status variable */
3764 :
3765 : int32 fid; /* HDF-EOS file ID */
3766 : int32 sdInterfaceID; /* HDF SDS interface ID */
3767 : int32 sdid; /* SDS ID */
3768 : int32 dum; /* Dummy variable */
3769 : int32 rankSDS; /* Rank of SDS */
3770 : int32 rankFld; /* Rank of field */
3771 :
3772 : int32 offset[8]; /* I/O offset (start) */
3773 : int32 incr[8]; /* I/O increment (stride) */
3774 : int32 count[8]; /* I/O count (edge) */
3775 : int32 dims[8]; /* Field/SDS dimensions */
3776 : int32 mrgOffset; /* Merged field offset */
3777 : int32 strideOne; /* Strides = 1 flag */
3778 :
3779 :
3780 : /* Check for valid grid ID */
3781 : /* ----------------------- */
3782 0 : status = GDchkgdid(gridID, "GDwrrdfield", &fid, &sdInterfaceID, &dum);
3783 :
3784 :
3785 0 : if (status == 0)
3786 : {
3787 : /* Check that field exists */
3788 : /* ----------------------- */
3789 0 : status = GDfieldinfo(gridID, fieldname, &rankSDS, dims, &dum, NULL);
3790 :
3791 :
3792 0 : if (status != 0)
3793 : {
3794 0 : HEpush(DFE_GENAPP, "GDwrrdfield", __FILE__, __LINE__);
3795 0 : HEreport("Fieldname \"%s\" does not exist.\n", fieldname);
3796 0 : status = -1;
3797 :
3798 : }
3799 :
3800 :
3801 0 : if (status == 0)
3802 : {
3803 0 : status = GDSDfldsrch(gridID, sdInterfaceID, fieldname, &sdid,
3804 : &rankSDS, &rankFld, &mrgOffset, dims, &dum);
3805 :
3806 :
3807 : /* Set I/O offset Section */
3808 : /* ---------------------- */
3809 :
3810 : /*
3811 : * If start == NULL (default) set I/O offset of 0th field to
3812 : * offset within merged field (if any) and the rest to 0
3813 : */
3814 0 : if (start == NULL)
3815 : {
3816 0 : for (i = 0; i < rankSDS; i++)
3817 : {
3818 0 : offset[i] = 0;
3819 : }
3820 0 : offset[0] = mrgOffset;
3821 : }
3822 : else
3823 : {
3824 : /*
3825 : * ... otherwise set I/O offset to user values, adjusting the
3826 : * 0th field with the merged field offset (if any)
3827 : */
3828 0 : if (rankFld == rankSDS)
3829 : {
3830 0 : for (i = 0; i < rankSDS; i++)
3831 : {
3832 0 : offset[i] = start[i];
3833 : }
3834 0 : offset[0] += mrgOffset;
3835 : }
3836 : else
3837 : {
3838 : /*
3839 : * If field really 2-dim merged in 3-dim field then set
3840 : * 0th field offset to merge offset and then next two to
3841 : * the user values
3842 : */
3843 0 : for (i = 0; i < rankFld; i++)
3844 : {
3845 0 : offset[i + 1] = start[i];
3846 : }
3847 0 : offset[0] = mrgOffset;
3848 : }
3849 : }
3850 :
3851 :
3852 :
3853 : /* Set I/O stride Section */
3854 : /* ---------------------- */
3855 :
3856 : /*
3857 : * If stride == NULL (default) set I/O stride to 1
3858 : */
3859 0 : if (stride == NULL)
3860 : {
3861 0 : for (i = 0; i < rankSDS; i++)
3862 : {
3863 0 : incr[i] = 1;
3864 : }
3865 : }
3866 : else
3867 : {
3868 : /*
3869 : * ... otherwise set I/O stride to user values
3870 : */
3871 0 : if (rankFld == rankSDS)
3872 : {
3873 0 : for (i = 0; i < rankSDS; i++)
3874 : {
3875 0 : incr[i] = stride[i];
3876 : }
3877 : }
3878 : else
3879 : {
3880 : /*
3881 : * If field really 2-dim merged in 3-dim field then set
3882 : * 0th field stride to 1 and then next two to the user
3883 : * values.
3884 : */
3885 0 : for (i = 0; i < rankFld; i++)
3886 : {
3887 0 : incr[i + 1] = stride[i];
3888 : }
3889 0 : incr[0] = 1;
3890 : }
3891 : }
3892 :
3893 :
3894 :
3895 : /* Set I/O count Section */
3896 : /* --------------------- */
3897 :
3898 : /*
3899 : * If edge == NULL (default) set I/O count to number of remaining
3900 : * entries (dims - start) / increment. Note that 0th field
3901 : * offset corrected for merged field offset (if any).
3902 : */
3903 0 : if (edge == NULL)
3904 : {
3905 0 : for (i = 1; i < rankSDS; i++)
3906 : {
3907 0 : count[i] = (dims[i] - offset[i]) / incr[i];
3908 : }
3909 0 : count[0] = (dims[0] - (offset[0] - mrgOffset)) / incr[0];
3910 : }
3911 : else
3912 : {
3913 : /*
3914 : * ... otherwise set I/O count to user values
3915 : */
3916 0 : if (rankFld == rankSDS)
3917 : {
3918 0 : for (i = 0; i < rankSDS; i++)
3919 : {
3920 0 : count[i] = edge[i];
3921 : }
3922 : }
3923 : else
3924 : {
3925 : /*
3926 : * If field really 2-dim merged in 3-dim field then set
3927 : * 0th field count to 1 and then next two to the user
3928 : * values.
3929 : */
3930 0 : for (i = 0; i < rankFld; i++)
3931 : {
3932 0 : count[i + 1] = edge[i];
3933 : }
3934 0 : count[0] = 1;
3935 : }
3936 : }
3937 :
3938 :
3939 : /* Perform I/O with relevant HDF I/O routine */
3940 : /* ----------------------------------------- */
3941 0 : if (strcmp(code, "w") == 0)
3942 : {
3943 : /* Set strideOne to true (1) */
3944 : /* ------------------------- */
3945 0 : strideOne = 1;
3946 :
3947 :
3948 : /* If incr[i] != 1 set strideOne to false (0) */
3949 : /* ------------------------------------------ */
3950 0 : for (i = 0; i < rankSDS; i++)
3951 : {
3952 0 : if (incr[i] != 1)
3953 : {
3954 0 : strideOne = 0;
3955 0 : break;
3956 : }
3957 : }
3958 :
3959 :
3960 : /*
3961 : * If strideOne is true use NULL parameter for stride. This
3962 : * is a work-around to HDF compression problem
3963 : */
3964 0 : if (strideOne == 1)
3965 : {
3966 0 : status = SDwritedata(sdid, offset, NULL, count,
3967 : (VOIDP) datbuf);
3968 : }
3969 : else
3970 : {
3971 0 : status = SDwritedata(sdid, offset, incr, count,
3972 : (VOIDP) datbuf);
3973 : }
3974 : }
3975 : else
3976 : {
3977 0 : status = SDreaddata(sdid, offset, incr, count,
3978 : (VOIDP) datbuf);
3979 : }
3980 : }
3981 : }
3982 :
3983 0 : return (status);
3984 : }
3985 :
3986 :
3987 : /*----------------------------------------------------------------------------|
3988 : | BEGIN_PROLOG |
3989 : | |
3990 : | FUNCTION: GDwritefield |
3991 : | |
3992 : | DESCRIPTION: Writes data to a grid field. |
3993 : | |
3994 : | |
3995 : | Return Value Type Units Description |
3996 : | ============ ====== ========= ===================================== |
3997 : | status intn return status (0) SUCCEED, (-1) FAIL |
3998 : | |
3999 : | INPUTS: |
4000 : | gridID int32 grid structure ID |
4001 : | fieldname char fieldname |
4002 : | start int32 start array |
4003 : | stride int32 stride array |
4004 : | edge int32 edge array |
4005 : | |
4006 : | |
4007 : | OUTPUTS: |
4008 : | data void data buffer for write |
4009 : | |
4010 : | NOTES: |
4011 : | |
4012 : | |
4013 : | Date Programmer Description |
4014 : | ====== ============ ================================================= |
4015 : | Jun 96 Joel Gales Original Programmer |
4016 : | |
4017 : | END_PROLOG |
4018 : -----------------------------------------------------------------------------*/
4019 : intn
4020 0 : GDwritefield(int32 gridID, const char *fieldname,
4021 : int32 start[], int32 stride[], int32 edge[], VOIDP data)
4022 :
4023 : {
4024 0 : intn status = 0; /* routine return status variable */
4025 :
4026 0 : status = GDwrrdfield(gridID, fieldname, "w", start, stride, edge,
4027 : data);
4028 0 : return (status);
4029 : }
4030 :
4031 :
4032 :
4033 :
4034 :
4035 : /*----------------------------------------------------------------------------|
4036 : | BEGIN_PROLOG |
4037 : | |
4038 : | FUNCTION: GDreadfield |
4039 : | |
4040 : | DESCRIPTION: Reads data from a grid field. |
4041 : | |
4042 : | |
4043 : | Return Value Type Units Description |
4044 : | ============ ====== ========= ===================================== |
4045 : | status intn return status (0) SUCCEED, (-1) FAIL |
4046 : | |
4047 : | INPUTS: |
4048 : | gridID int32 grid structure ID |
4049 : | fieldname char fieldname |
4050 : | start int32 start array |
4051 : | stride int32 stride array |
4052 : | edge int32 edge array |
4053 : | buffer void data buffer for read |
4054 : | |
4055 : | |
4056 : | OUTPUTS: |
4057 : | None |
4058 : | |
4059 : | NOTES: |
4060 : | |
4061 : | |
4062 : | Date Programmer Description |
4063 : | ====== ============ ================================================= |
4064 : | Jun 96 Joel Gales Original Programmer |
4065 : | |
4066 : | END_PROLOG |
4067 : -----------------------------------------------------------------------------*/
4068 : intn
4069 0 : GDreadfield(int32 gridID, const char *fieldname,
4070 : int32 start[], int32 stride[], int32 edge[], VOIDP buffer)
4071 :
4072 : {
4073 0 : intn status = 0; /* routine return status variable */
4074 :
4075 0 : status = GDwrrdfield(gridID, fieldname, "r", start, stride, edge,
4076 : buffer);
4077 0 : return (status);
4078 : }
4079 :
4080 :
4081 :
4082 :
4083 : /*----------------------------------------------------------------------------|
4084 : | BEGIN_PROLOG |
4085 : | |
4086 : | FUNCTION: GDwrrdattr |
4087 : | |
4088 : | DESCRIPTION: |
4089 : | |
4090 : | |
4091 : | Return Value Type Units Description |
4092 : | ============ ====== ========= ===================================== |
4093 : | status intn return status (0) SUCCEED, (-1) FAIL |
4094 : | |
4095 : | INPUTS: |
4096 : | gridID int32 grid structure ID |
4097 : | attrname char attribute name |
4098 : | numbertype int32 attribute HDF numbertype |
4099 : | count int32 Number of attribute elements |
4100 : | wrcode char Read/Write Code "w/r" |
4101 : | datbuf void I/O buffer |
4102 : | |
4103 : | OUTPUTS: |
4104 : | datbuf |
4105 : | |
4106 : | NOTES: |
4107 : | |
4108 : | |
4109 : | Date Programmer Description |
4110 : | ====== ============ ================================================= |
4111 : | Jun 96 Joel Gales Original Programmer |
4112 : | Oct 96 Joel Gales Get Attribute Vgroup ID from external array |
4113 : | |
4114 : | END_PROLOG |
4115 : -----------------------------------------------------------------------------*/
4116 : static intn
4117 0 : GDwrrdattr(int32 gridID, const char *attrname, int32 numbertype, int32 count,
4118 : const char *wrcode, VOIDP datbuf)
4119 :
4120 : {
4121 : intn status; /* routine return status variable */
4122 :
4123 : int32 fid; /* HDF-EOS file ID */
4124 : int32 attrVgrpID; /* Grid attribute ID */
4125 : int32 dum; /* dummy variable */
4126 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
4127 :
4128 :
4129 : /* Check Grid id */
4130 0 : status = GDchkgdid(gridID, "GDwrrdattr", &fid, &dum, &dum);
4131 :
4132 0 : if (status == 0)
4133 : {
4134 : /* Perform Attribute I/O */
4135 : /* --------------------- */
4136 0 : attrVgrpID = GDXGrid[gridID % idOffset].VIDTable[1];
4137 0 : status = EHattr(fid, attrVgrpID, attrname, numbertype, count,
4138 : wrcode, datbuf);
4139 : }
4140 0 : return (status);
4141 : }
4142 :
4143 :
4144 :
4145 : /*----------------------------------------------------------------------------|
4146 : | BEGIN_PROLOG |
4147 : | |
4148 : | FUNCTION: GDwriteattr |
4149 : | |
4150 : | DESCRIPTION: Writes/updates attribute in a grid. |
4151 : | |
4152 : | |
4153 : | Return Value Type Units Description |
4154 : | ============ ====== ========= ===================================== |
4155 : | status intn return status (0) SUCCEED, (-1) FAIL |
4156 : | |
4157 : | INPUTS: |
4158 : | gridID int32 grid structure ID |
4159 : | attrname char attribute name |
4160 : | numbertype int32 attribute HDF numbertype |
4161 : | count int32 Number of attribute elements |
4162 : | datbuf void I/O buffer |
4163 : | |
4164 : | OUTPUTS: |
4165 : | None |
4166 : | |
4167 : | NOTES: |
4168 : | |
4169 : | |
4170 : | Date Programmer Description |
4171 : | ====== ============ ================================================= |
4172 : | Jun 96 Joel Gales Original Programmer |
4173 : | |
4174 : | END_PROLOG |
4175 : -----------------------------------------------------------------------------*/
4176 : intn
4177 0 : GDwriteattr(int32 gridID, const char *attrname, int32 numbertype, int32 count,
4178 : VOIDP datbuf)
4179 : {
4180 0 : intn status = 0; /* routine return status variable */
4181 :
4182 : /* Call GDwrrdattr routine to write attribute */
4183 : /* ------------------------------------------ */
4184 0 : status = GDwrrdattr(gridID, attrname, numbertype, count, "w", datbuf);
4185 :
4186 0 : return (status);
4187 : }
4188 :
4189 :
4190 :
4191 : /*----------------------------------------------------------------------------|
4192 : | BEGIN_PROLOG |
4193 : | |
4194 : | FUNCTION: GDreadattr |
4195 : | |
4196 : | DESCRIPTION: Reads attribute from a grid. |
4197 : | |
4198 : | |
4199 : | Return Value Type Units Description |
4200 : | ============ ====== ========= ===================================== |
4201 : | status intn return status (0) SUCCEED, (-1) FAIL |
4202 : | |
4203 : | INPUTS: |
4204 : | gridID int32 grid structure ID |
4205 : | attrname char attribute name |
4206 : | |
4207 : | OUTPUTS: |
4208 : | datbuf void I/O buffer |
4209 : | |
4210 : | NOTES: |
4211 : | |
4212 : | |
4213 : | Date Programmer Description |
4214 : | ====== ============ ================================================= |
4215 : | Jun 96 Joel Gales Original Programmer |
4216 : | |
4217 : | END_PROLOG |
4218 : -----------------------------------------------------------------------------*/
4219 : intn
4220 0 : GDreadattr(int32 gridID, const char *attrname, VOIDP datbuf)
4221 : {
4222 0 : intn status = 0; /* routine return status variable */
4223 0 : int32 dum = 0; /* dummy variable */
4224 :
4225 : /* Call GDwrrdattr routine to read attribute */
4226 : /* ----------------------------------------- */
4227 0 : status = GDwrrdattr(gridID, attrname, dum, dum, "r", datbuf);
4228 :
4229 0 : return (status);
4230 : }
4231 :
4232 :
4233 :
4234 :
4235 :
4236 : /*----------------------------------------------------------------------------|
4237 : | BEGIN_PROLOG |
4238 : | |
4239 : | FUNCTION: GDattrinfo |
4240 : | |
4241 : | DESCRIPTION: |
4242 : | |
4243 : | |
4244 : | Return Value Type Units Description |
4245 : | ============ ====== ========= ===================================== |
4246 : | status intn return status (0) SUCCEED, (-1) FAIL |
4247 : | |
4248 : | INPUTS: |
4249 : | gridID int32 grid structure ID |
4250 : | attrname char attribute name |
4251 : | |
4252 : | OUTPUTS: |
4253 : | numbertype int32 attribute HDF numbertype |
4254 : | count int32 Number of attribute elements |
4255 : | |
4256 : | |
4257 : | OUTPUTS: |
4258 : | None |
4259 : | |
4260 : | NOTES: |
4261 : | |
4262 : | |
4263 : | Date Programmer Description |
4264 : | ====== ============ ================================================= |
4265 : | Jun 96 Joel Gales Original Programmer |
4266 : | Oct 96 Joel Gales Get Attribute Vgroup ID from external array |
4267 : | |
4268 : | END_PROLOG |
4269 : -----------------------------------------------------------------------------*/
4270 : intn
4271 0 : GDattrinfo(int32 gridID, const char *attrname, int32 * numbertype, int32 * count)
4272 : {
4273 0 : intn status = 0; /* routine return status variable */
4274 :
4275 : int32 fid; /* HDF-EOS file ID */
4276 : int32 attrVgrpID; /* Grid attribute ID */
4277 : int32 dum; /* dummy variable */
4278 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
4279 :
4280 0 : status = GDchkgdid(gridID, "GDattrinfo", &fid, &dum, &dum);
4281 :
4282 0 : attrVgrpID = GDXGrid[gridID % idOffset].VIDTable[1];
4283 :
4284 0 : status = EHattrinfo(fid, attrVgrpID, attrname, numbertype,
4285 : count);
4286 :
4287 0 : return (status);
4288 : }
4289 :
4290 :
4291 :
4292 :
4293 :
4294 :
4295 : /*----------------------------------------------------------------------------|
4296 : | BEGIN_PROLOG |
4297 : | |
4298 : | FUNCTION: GDinqattrs |
4299 : | |
4300 : | DESCRIPTION: |
4301 : | |
4302 : | |
4303 : | Return Value Type Units Description |
4304 : | ============ ====== ========= ===================================== |
4305 : | nattr int32 Number of attributes in swath struct |
4306 : | |
4307 : | INPUTS: |
4308 : | grid ID int32 grid structure ID |
4309 : | |
4310 : | OUTPUTS: |
4311 : | attrnames char Attribute names in swath struct |
4312 : | (Comma-separated list) |
4313 : | strbufsize int32 Attributes name list string length |
4314 : | |
4315 : | OUTPUTS: |
4316 : | None |
4317 : | |
4318 : | NOTES: |
4319 : | |
4320 : | |
4321 : | Date Programmer Description |
4322 : | ====== ============ ================================================= |
4323 : | Jun 96 Joel Gales Original Programmer |
4324 : | Oct 96 Joel Gales Initialize nattr |
4325 : | Oct 96 Joel Gales Get Attribute Vgroup ID from external array |
4326 : | |
4327 : | END_PROLOG |
4328 : -----------------------------------------------------------------------------*/
4329 : int32
4330 0 : GDinqattrs(int32 gridID, char *attrnames, int32 * strbufsize)
4331 : {
4332 : intn status; /* routine return status variable */
4333 :
4334 : int32 fid; /* HDF-EOS file ID */
4335 : int32 attrVgrpID; /* Grid attribute ID */
4336 : int32 dum; /* dummy variable */
4337 0 : int32 nattr = 0; /* Number of attributes */
4338 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
4339 :
4340 :
4341 : /* Check Grid id */
4342 0 : status = GDchkgdid(gridID, "GDinqattrs", &fid, &dum, &dum);
4343 :
4344 0 : if (status == 0)
4345 : {
4346 0 : attrVgrpID = GDXGrid[gridID % idOffset].VIDTable[1];
4347 0 : nattr = EHattrcat(fid, attrVgrpID, attrnames, strbufsize);
4348 : }
4349 :
4350 0 : return (nattr);
4351 : }
4352 :
4353 :
4354 :
4355 :
4356 :
4357 :
4358 : #define REMQUOTE \
4359 : \
4360 : memmove(utlstr, utlstr + 1, strlen(utlstr) - 2); \
4361 : utlstr[strlen(utlstr) - 2] = 0;
4362 :
4363 :
4364 : /*----------------------------------------------------------------------------|
4365 : | BEGIN_PROLOG |
4366 : | |
4367 : | FUNCTION: GDinqdims |
4368 : | |
4369 : | DESCRIPTION: Retrieve information about all dimensions defined in a grid. |
4370 : | |
4371 : | |
4372 : | Return Value Type Units Description |
4373 : | ============ ====== ========= ===================================== |
4374 : | nDim int32 Number of defined dimensions |
4375 : | |
4376 : | INPUTS: |
4377 : | gridID int32 grid structure ID |
4378 : | |
4379 : | OUTPUTS: |
4380 : | dimnames char Dimension names (comma-separated) |
4381 : | dims int32 Dimension values |
4382 : | |
4383 : | |
4384 : | OUTPUTS: |
4385 : | None |
4386 : | |
4387 : | NOTES: |
4388 : | |
4389 : | |
4390 : | Date Programmer Description |
4391 : | ====== ============ ================================================= |
4392 : | Jun 96 Joel Gales Original Programmer |
4393 : | Aug 96 Joel Gales Make metadata ODL compliant |
4394 : | Feb 97 Joel Gales Set nDim to -1 if status = -1 |
4395 : | |
4396 : | END_PROLOG |
4397 : -----------------------------------------------------------------------------*/
4398 : int32
4399 0 : GDinqdims(int32 gridID, char *dimnames, int32 dims[])
4400 : {
4401 : intn status; /* routine return status variable */
4402 :
4403 : int32 fid; /* HDF-EOS file ID */
4404 : int32 sdInterfaceID; /* HDF SDS interface ID */
4405 : int32 gdVgrpID; /* Grid root Vgroup ID */
4406 : int32 size; /* Dimension size */
4407 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
4408 0 : int32 nDim = 0; /* Number of dimensions */
4409 :
4410 : char *metabuf; /* Pointer to structural metadata (SM) */
4411 : char *metaptrs[2];/* Pointers to begin and end of SM section */
4412 : char gridname[80]; /* Grid Name */
4413 : char *utlstr;/* Utility string */
4414 :
4415 : /* Allocate space for utility string */
4416 : /* --------------------------------- */
4417 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
4418 0 : if(utlstr == NULL)
4419 : {
4420 0 : HEpush(DFE_NOSPACE,"GDinqdims", __FILE__, __LINE__);
4421 0 : return(-1);
4422 : }
4423 : /* Check for valid grid id */
4424 : /* ----------------------- */
4425 0 : status = GDchkgdid(gridID, "GDinqdims", &fid, &sdInterfaceID, &gdVgrpID);
4426 :
4427 0 : if (status == 0)
4428 : {
4429 : /* If dimension names or sizes are requested */
4430 : /* ----------------------------------------- */
4431 0 : if (dimnames != NULL || dims != NULL)
4432 : {
4433 : /* Get grid name */
4434 : /* ------------- */
4435 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
4436 :
4437 :
4438 : /* Get pointers to "Dimension" section within SM */
4439 : /* --------------------------------------------- */
4440 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
4441 : "Dimension", metaptrs);
4442 0 : if(metabuf == NULL)
4443 : {
4444 0 : free(utlstr);
4445 0 : return(-1);
4446 : }
4447 :
4448 :
4449 : /* If dimension names are requested then "clear" name buffer */
4450 : /* --------------------------------------------------------- */
4451 0 : if (dimnames != NULL)
4452 : {
4453 0 : dimnames[0] = 0;
4454 : }
4455 :
4456 0 : while (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
4457 : {
4458 0 : strcpy(utlstr, "\t\tOBJECT=");
4459 0 : metaptrs[0] = strstr(metaptrs[0], utlstr);
4460 0 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
4461 : {
4462 : /* Get Dimension Name */
4463 : /* ------------------ */
4464 0 : if (dimnames != NULL)
4465 : {
4466 : /* Check 1st for old meta data then new */
4467 : /* ------------------------------------ */
4468 0 : EHgetmetavalue(metaptrs, "OBJECT", utlstr);
4469 0 : if (utlstr[0] != '"')
4470 : {
4471 0 : metaptrs[0] =
4472 0 : strstr(metaptrs[0], "\t\t\t\tDimensionName=");
4473 0 : EHgetmetavalue(metaptrs, "DimensionName", utlstr);
4474 : }
4475 :
4476 : /* Strip off double quotes */
4477 : /* ----------------------- */
4478 0 : memmove(utlstr, utlstr + 1, strlen(utlstr) - 2);
4479 0 : utlstr[strlen(utlstr) - 2] = 0;
4480 :
4481 0 : if (nDim > 0)
4482 : {
4483 0 : strcat(dimnames, ",");
4484 : }
4485 0 : strcat(dimnames, utlstr);
4486 : }
4487 :
4488 : /* Get Dimension Size */
4489 : /* ------------------ */
4490 0 : if (dims != NULL)
4491 : {
4492 0 : EHgetmetavalue(metaptrs, "Size", utlstr);
4493 0 : size = atoi(utlstr);
4494 0 : dims[nDim] = size;
4495 : }
4496 0 : nDim++;
4497 : }
4498 : }
4499 0 : free(metabuf);
4500 :
4501 : }
4502 : }
4503 :
4504 :
4505 : /* Set nDim to -1 if error status exists */
4506 : /* ------------------------------------- */
4507 0 : if (status == -1)
4508 : {
4509 0 : nDim = -1;
4510 : }
4511 0 : free(utlstr);
4512 0 : return (nDim);
4513 : }
4514 :
4515 :
4516 :
4517 :
4518 :
4519 :
4520 : /*----------------------------------------------------------------------------|
4521 : | BEGIN_PROLOG |
4522 : | |
4523 : | FUNCTION: GDinqfields |
4524 : | |
4525 : | DESCRIPTION: Retrieve information about all data fields defined in a grid. |
4526 : | |
4527 : | |
4528 : | Return Value Type Units Description |
4529 : | ============ ====== ========= ===================================== |
4530 : | nFld int32 Number of fields in swath |
4531 : | |
4532 : | INPUTS: |
4533 : | gridID int32 grid structure ID |
4534 : | |
4535 : | |
4536 : | OUTPUTS: |
4537 : | fieldlist char Field names (comma-separated) |
4538 : | rank int32 Array of ranks |
4539 : | numbertype int32 Array of HDF number types |
4540 : | |
4541 : | NOTES: |
4542 : | |
4543 : | |
4544 : | Date Programmer Description |
4545 : | ====== ============ ================================================= |
4546 : | Jun 96 Joel Gales Original Programmer |
4547 : | Aug 96 Joel Gales Make metadata ODL compliant |
4548 : | Feb 97 Joel Gales Set nFld to -1 if status = -1 |
4549 : | |
4550 : | END_PROLOG |
4551 : -----------------------------------------------------------------------------*/
4552 : int32
4553 0 : GDinqfields(int32 gridID, char *fieldlist, int32 rank[],
4554 : int32 numbertype[])
4555 : {
4556 : intn status; /* routine return status variable */
4557 :
4558 : int32 fid; /* HDF-EOS file ID */
4559 : int32 sdInterfaceID; /* HDF SDS interface ID */
4560 : int32 gdVgrpID; /* Grid root Vgroup ID */
4561 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
4562 0 : int32 nFld = 0; /* Number of mappings */
4563 : int32 slen[8]; /* String length array */
4564 :
4565 : char *metabuf; /* Pointer to structural metadata (SM) */
4566 : char *metaptrs[2];/* Pointers to begin and end of SM section */
4567 : char gridname[80]; /* Grid Name */
4568 : char *utlstr;/* Utility string */
4569 : char *ptr[8]; /* String pointer array */
4570 :
4571 : /* Allocate space for utility string */
4572 : /* --------------------------------- */
4573 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
4574 0 : if(utlstr == NULL)
4575 : {
4576 0 : HEpush(DFE_NOSPACE,"GDinqfields", __FILE__, __LINE__);
4577 0 : return(-1);
4578 : }
4579 : /* Check for valid grid id */
4580 : /* ----------------------- */
4581 0 : status = GDchkgdid(gridID, "GDinqfields", &fid, &sdInterfaceID, &gdVgrpID);
4582 0 : if (status == 0)
4583 : {
4584 :
4585 : /* If field names, ranks, or number types desired ... */
4586 : /* --------------------------------------------------- */
4587 0 : if (fieldlist != NULL || rank != NULL || numbertype != NULL)
4588 : {
4589 : /* Get grid name */
4590 : /* ------------- */
4591 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
4592 :
4593 :
4594 : /* Get pointers to "DataField" section within SM */
4595 : /* --------------------------------------------- */
4596 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
4597 : "DataField", metaptrs);
4598 0 : if(metabuf == NULL)
4599 : {
4600 0 : free(utlstr);
4601 0 : return(-1);
4602 : }
4603 :
4604 :
4605 : /* If field names are desired then "clear" name buffer */
4606 : /* --------------------------------------------------- */
4607 0 : if (fieldlist != NULL)
4608 : {
4609 0 : fieldlist[0] = 0;
4610 : }
4611 :
4612 :
4613 : /* Begin loop through mapping entries in metadata */
4614 : /* ---------------------------------------------- */
4615 : while (1)
4616 : {
4617 : /* Search for OBJECT string */
4618 : /* ------------------------ */
4619 0 : metaptrs[0] = strstr(metaptrs[0], "\t\tOBJECT=");
4620 :
4621 :
4622 : /* If found within "Data" Field metadata section .. */
4623 : /* ------------------------------------------------ */
4624 0 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
4625 : {
4626 : /* Get Fieldnames (if desired) */
4627 : /* --------------------------- */
4628 0 : if (fieldlist != NULL)
4629 : {
4630 : /* Check 1st for old meta data then new */
4631 : /* ------------------------------------ */
4632 0 : EHgetmetavalue(metaptrs, "OBJECT", utlstr);
4633 :
4634 : /*
4635 : * If OBJECT value begins with double quote then old
4636 : * metadata, field name is OBJECT value. Otherwise
4637 : * search for "DataFieldName" string
4638 : */
4639 :
4640 0 : if (utlstr[0] != '"')
4641 : {
4642 0 : strcpy(utlstr, "\t\t\t\t");
4643 0 : strcat(utlstr, "DataFieldName");
4644 0 : strcat(utlstr, "=");
4645 0 : metaptrs[0] = strstr(metaptrs[0], utlstr);
4646 0 : EHgetmetavalue(metaptrs, "DataFieldName", utlstr);
4647 : }
4648 :
4649 : /* Strip off double quotes */
4650 : /* ----------------------- */
4651 0 : REMQUOTE
4652 :
4653 :
4654 : /* Add to fieldlist */
4655 : /* ---------------- */
4656 0 : if (nFld > 0)
4657 : {
4658 0 : strcat(fieldlist, ",");
4659 : }
4660 0 : strcat(fieldlist, utlstr);
4661 :
4662 : }
4663 : /* Get Numbertype */
4664 0 : if (numbertype != NULL)
4665 : {
4666 0 : EHgetmetavalue(metaptrs, "DataType", utlstr);
4667 0 : numbertype[nFld] = EHnumstr(utlstr);
4668 : }
4669 : /*
4670 : * Get Rank (if desired) by counting # of dimensions in
4671 : * "DimList" string
4672 : */
4673 0 : if (rank != NULL)
4674 : {
4675 0 : EHgetmetavalue(metaptrs, "DimList", utlstr);
4676 0 : rank[nFld] = EHparsestr(utlstr, ',', ptr, slen);
4677 : }
4678 : /* Increment number of fields */
4679 0 : nFld++;
4680 : }
4681 : else
4682 : /* No more fields found */
4683 : {
4684 : break;
4685 : }
4686 : }
4687 0 : free(metabuf);
4688 : }
4689 : }
4690 :
4691 : /* Set nFld to -1 if error status exists */
4692 : /* ------------------------------------- */
4693 0 : if (status == -1)
4694 : {
4695 0 : nFld = -1;
4696 : }
4697 0 : free(utlstr);
4698 0 : return (nFld);
4699 : }
4700 :
4701 :
4702 :
4703 :
4704 :
4705 : /*----------------------------------------------------------------------------|
4706 : | BEGIN_PROLOG |
4707 : | |
4708 : | FUNCTION: GDnentries |
4709 : | |
4710 : | DESCRIPTION: Returns number of entries and descriptive string buffer |
4711 : | size for a specified entity. |
4712 : | |
4713 : | |
4714 : | Return Value Type Units Description |
4715 : | ============ ====== ========= ===================================== |
4716 : | nEntries int32 Number of entries |
4717 : | |
4718 : | INPUTS: |
4719 : | gridID int32 grid structure ID |
4720 : | entrycode int32 Entry code |
4721 : | HDFE_NENTDIM (0) |
4722 : | HDFE_NENTDFLD (4) |
4723 : | |
4724 : | |
4725 : | OUTPUTS: |
4726 : | strbufsize int32 Length of comma-separated list |
4727 : | (Does not include null-terminator |
4728 : | |
4729 : | NOTES: |
4730 : | |
4731 : | |
4732 : | Date Programmer Description |
4733 : | ====== ============ ================================================= |
4734 : | Jun 96 Joel Gales Original Programmer |
4735 : | Aug 96 Joel Gales Make metadata ODL compliant |
4736 : | Feb 97 Joel Gales Set nEntries to -1 if status = -1 |
4737 : | |
4738 : | END_PROLOG |
4739 : -----------------------------------------------------------------------------*/
4740 : int32
4741 0 : GDnentries(int32 gridID, int32 entrycode, int32 * strbufsize)
4742 :
4743 : {
4744 : intn status; /* routine return status variable */
4745 : intn i; /* Loop index */
4746 :
4747 : int32 fid; /* HDF-EOS file ID */
4748 : int32 sdInterfaceID; /* HDF SDS interface ID */
4749 : int32 gdVgrpID; /* Grid root Vgroup ID */
4750 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
4751 0 : int32 nEntries = 0; /* Number of entries */
4752 : int32 metaflag; /* Old (0), New (1) metadata flag) */
4753 0 : int32 nVal = 0; /* Number of strings to search for */
4754 :
4755 0 : char *metabuf = NULL; /* Pointer to structural metadata (SM) */
4756 : char *metaptrs[2];/* Pointers to begin and end of SM section */
4757 : char gridname[80]; /* Grid Name */
4758 : char *utlstr;/* Utility string */
4759 : char valName[2][32]; /* Strings to search for */
4760 :
4761 : /* Allocate space for utility string */
4762 : /* --------------------------------- */
4763 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
4764 0 : if(utlstr == NULL)
4765 : {
4766 0 : HEpush(DFE_NOSPACE,"GDnentries", __FILE__, __LINE__);
4767 0 : return(-1);
4768 : }
4769 0 : status = GDchkgdid(gridID, "GDnentries", &fid, &sdInterfaceID, &gdVgrpID);
4770 :
4771 0 : if (status == 0)
4772 : {
4773 : /* Get grid name */
4774 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
4775 :
4776 : /* Zero out string buffer size */
4777 0 : *strbufsize = 0;
4778 :
4779 :
4780 : /*
4781 : * Get pointer to relevant section within SM and Get names of
4782 : * metadata strings to inquire about
4783 : */
4784 0 : switch (entrycode)
4785 : {
4786 0 : case HDFE_NENTDIM:
4787 : {
4788 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
4789 : "Dimension", metaptrs);
4790 0 : if(metabuf == NULL)
4791 : {
4792 0 : free(utlstr);
4793 0 : return(-1);
4794 : }
4795 :
4796 0 : nVal = 1;
4797 0 : strcpy(&valName[0][0], "DimensionName");
4798 : }
4799 0 : break;
4800 :
4801 0 : case HDFE_NENTDFLD:
4802 : {
4803 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
4804 : "DataField", metaptrs);
4805 0 : if(metabuf == NULL)
4806 : {
4807 0 : free(utlstr);
4808 0 : return(-1);
4809 : }
4810 :
4811 0 : nVal = 1;
4812 0 : strcpy(&valName[0][0], "DataFieldName");
4813 : }
4814 0 : break;
4815 : }
4816 :
4817 :
4818 : /*
4819 : * Check for presence of 'GROUP="' string If found then old metadata,
4820 : * search on OBJECT string
4821 : */
4822 0 : metaflag = (strstr(metabuf, "GROUP=\"") == NULL) ? 1 : 0;
4823 0 : if (metaflag == 0)
4824 : {
4825 0 : nVal = 1;
4826 0 : strcpy(&valName[0][0], "\t\tOBJECT");
4827 : }
4828 :
4829 :
4830 : /* Begin loop through entries in metadata */
4831 : /* -------------------------------------- */
4832 : while (1)
4833 : {
4834 : /* Search for first string */
4835 0 : strcpy(utlstr, &valName[0][0]);
4836 0 : strcat(utlstr, "=");
4837 0 : metaptrs[0] = strstr(metaptrs[0], utlstr);
4838 :
4839 : /* If found within relevant metadata section ... */
4840 0 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
4841 : {
4842 0 : for (i = 0; i < nVal; i++)
4843 : {
4844 : /*
4845 : * Get all string values Don't count quotes
4846 : */
4847 0 : EHgetmetavalue(metaptrs, &valName[i][0], utlstr);
4848 0 : *strbufsize += (int32)strlen(utlstr) - 2;
4849 : }
4850 : /* Increment number of entries */
4851 0 : nEntries++;
4852 :
4853 : /* Go to end of OBJECT */
4854 0 : metaptrs[0] = strstr(metaptrs[0], "END_OBJECT");
4855 : }
4856 : else
4857 : /* No more entries found */
4858 : {
4859 : break;
4860 : }
4861 : }
4862 0 : free(metabuf);
4863 :
4864 :
4865 : /* Count comma separators & slashes (if mappings) */
4866 : /* ---------------------------------------------- */
4867 0 : if (nEntries > 0)
4868 : {
4869 0 : *strbufsize += nEntries - 1;
4870 0 : *strbufsize += (nVal - 1) * nEntries;
4871 : }
4872 : }
4873 :
4874 :
4875 : /* Set nEntries to -1 if error status exists */
4876 : /* ----------------------------------------- */
4877 0 : if (status == -1)
4878 : {
4879 0 : nEntries = -1;
4880 : }
4881 :
4882 0 : free(utlstr);
4883 0 : return (nEntries);
4884 : }
4885 :
4886 :
4887 :
4888 :
4889 :
4890 : /*----------------------------------------------------------------------------|
4891 : | BEGIN_PROLOG |
4892 : | |
4893 : | FUNCTION: GDinqgrid |
4894 : | |
4895 : | DESCRIPTION: Returns number and names of grid structures in file |
4896 : | |
4897 : | |
4898 : | Return Value Type Units Description |
4899 : | ============ ====== ========= ===================================== |
4900 : | nGrid int32 Number of grid structures in file |
4901 : | |
4902 : | INPUTS: |
4903 : | filename char HDF-EOS filename |
4904 : | |
4905 : | OUTPUTS: |
4906 : | gridlist char List of grid names (comma-separated) |
4907 : | strbufsize int32 Length of gridlist |
4908 : | |
4909 : | NOTES: |
4910 : | |
4911 : | |
4912 : | Date Programmer Description |
4913 : | ====== ============ ================================================= |
4914 : | Jun 96 Joel Gales Original Programmer |
4915 : | |
4916 : | END_PROLOG |
4917 : -----------------------------------------------------------------------------*/
4918 : int32
4919 4 : GDinqgrid(const char *filename, char *gridlist, int32 * strbufsize)
4920 : {
4921 : int32 nGrid; /* Number of grid structures in file */
4922 :
4923 : /* Call "EHinquire" routine */
4924 : /* ------------------------ */
4925 4 : nGrid = EHinquire(filename, "GRID", gridlist, strbufsize);
4926 :
4927 4 : return (nGrid);
4928 : }
4929 :
4930 :
4931 : /*----------------------------------------------------------------------------|
4932 : | BEGIN_PROLOG |
4933 : | |
4934 : | FUNCTION: GDsetfillvalue |
4935 : | |
4936 : | DESCRIPTION: Sets fill value for the specified field. |
4937 : | |
4938 : | |
4939 : | Return Value Type Units Description |
4940 : | ============ ====== ========= ===================================== |
4941 : | status intn return status (0) SUCCEED, (-1) FAIL |
4942 : | |
4943 : | INPUTS: |
4944 : | gridID int32 grid structure ID |
4945 : | fieldname char field name |
4946 : | fillval void fill value |
4947 : | |
4948 : | OUTPUTS: |
4949 : | None |
4950 : | |
4951 : | NOTES: |
4952 : | |
4953 : | |
4954 : | Date Programmer Description |
4955 : | ====== ============ ================================================= |
4956 : | Jun 96 Joel Gales Original Programmer |
4957 : | |
4958 : | END_PROLOG |
4959 : -----------------------------------------------------------------------------*/
4960 : intn
4961 0 : GDsetfillvalue(int32 gridID, const char *fieldname, VOIDP fillval)
4962 : {
4963 : intn status; /* routine return status variable */
4964 :
4965 : int32 fid; /* HDF-EOS file ID */
4966 : int32 sdInterfaceID; /* HDF SDS interface ID */
4967 : int32 gdVgrpID; /* Grid root Vgroup ID */
4968 : int32 sdid; /* SDS id */
4969 : int32 nt; /* Number type */
4970 : int32 dims[8]; /* Dimensions array */
4971 : int32 dum; /* Dummy variable */
4972 : int32 solo; /* "Solo" (non-merged) field flag */
4973 :
4974 : char name[80]; /* Fill value "attribute" name */
4975 :
4976 : /* Check for valid grid ID and get SDS interface ID */
4977 0 : status = GDchkgdid(gridID, "GDsetfillvalue",
4978 : &fid, &sdInterfaceID, &gdVgrpID);
4979 :
4980 0 : if (status == 0)
4981 : {
4982 : /* Get field info */
4983 0 : status = GDfieldinfo(gridID, fieldname, &dum, dims, &nt, NULL);
4984 :
4985 0 : if (status == 0)
4986 : {
4987 : /* Get SDS ID and solo flag */
4988 0 : status = GDSDfldsrch(gridID, sdInterfaceID, fieldname,
4989 : &sdid, &dum, &dum, &dum,
4990 : dims, &solo);
4991 :
4992 : /* If unmerged field then call HDF set field routine */
4993 0 : if (solo == 1)
4994 : {
4995 0 : /* status = */ SDsetfillvalue(sdid, fillval);
4996 : }
4997 :
4998 : /*
4999 : * Store fill value in attribute. Name is given by fieldname
5000 : * prepended with "_FV_"
5001 : */
5002 0 : strcpy(name, "_FV_");
5003 0 : strcat(name, fieldname);
5004 0 : status = GDwriteattr(gridID, name, nt, 1, fillval);
5005 :
5006 :
5007 : }
5008 : else
5009 : {
5010 0 : HEpush(DFE_GENAPP, "GDsetfillvalue", __FILE__, __LINE__);
5011 0 : HEreport("Fieldname \"%s\" does not exist.\n", fieldname);
5012 : }
5013 : }
5014 0 : return (status);
5015 : }
5016 :
5017 :
5018 :
5019 :
5020 :
5021 :
5022 :
5023 : /*----------------------------------------------------------------------------|
5024 : | BEGIN_PROLOG |
5025 : | |
5026 : | FUNCTION: GDgetfillvalue |
5027 : | |
5028 : | DESCRIPTION: Retrieves fill value for a specified field. |
5029 : | |
5030 : | |
5031 : | Return Value Type Units Description |
5032 : | ============ ====== ========= ===================================== |
5033 : | status intn return status (0) SUCCEED, (-1) FAIL |
5034 : | |
5035 : | INPUTS: |
5036 : | gridID int32 grid structure ID |
5037 : | fieldname char field name |
5038 : | |
5039 : | OUTPUTS: |
5040 : | fillval void fill value |
5041 : | |
5042 : | NOTES: |
5043 : | |
5044 : | |
5045 : | Date Programmer Description |
5046 : | ====== ============ ================================================= |
5047 : | Jun 96 Joel Gales Original Programmer |
5048 : | |
5049 : | END_PROLOG |
5050 : -----------------------------------------------------------------------------*/
5051 : intn
5052 0 : GDgetfillvalue(int32 gridID, const char *fieldname, VOIDP fillval)
5053 : {
5054 : intn status; /* routine return status variable */
5055 :
5056 : int32 nt; /* Number type */
5057 : int32 dims[8]; /* Dimensions array */
5058 : int32 dum; /* Dummy variable */
5059 :
5060 : char name[80]; /* Fill value "attribute" name */
5061 :
5062 0 : status = GDchkgdid(gridID, "GDgetfillvalue", &dum, &dum, &dum);
5063 :
5064 : /* Check for valid grid ID */
5065 0 : if (status == 0)
5066 : {
5067 : /* Get field info */
5068 0 : status = GDfieldinfo(gridID, fieldname, &dum, dims, &nt, NULL);
5069 :
5070 0 : if (status == 0)
5071 : {
5072 : /* Read fill value attribute */
5073 0 : strcpy(name, "_FV_");
5074 0 : strcat(name, fieldname);
5075 0 : status = GDreadattr(gridID, name, fillval);
5076 : }
5077 : else
5078 : {
5079 0 : HEpush(DFE_GENAPP, "GDgetfillvalue", __FILE__, __LINE__);
5080 0 : HEreport("Fieldname \"%s\" does not exist.\n", fieldname);
5081 : }
5082 :
5083 : }
5084 0 : return (status);
5085 : }
5086 :
5087 :
5088 :
5089 :
5090 :
5091 : /*----------------------------------------------------------------------------|
5092 : | BEGIN_PROLOG |
5093 : | |
5094 : | FUNCTION: GDdetach |
5095 : | |
5096 : | DESCRIPTION: Detaches from grid interface and performs file housekeeping. |
5097 : | |
5098 : | |
5099 : | Return Value Type Units Description |
5100 : | ============ ====== ========= ===================================== |
5101 : | status intn return status (0) SUCCEED, (-1) FAIL |
5102 : | |
5103 : | INPUTS: |
5104 : | gridID int32 grid structure ID |
5105 : | |
5106 : | |
5107 : | OUTPUTS: |
5108 : | None |
5109 : | |
5110 : | NOTES: |
5111 : | |
5112 : | |
5113 : | Date Programmer Description |
5114 : | ====== ============ ================================================= |
5115 : | Jun 96 Joel Gales Original Programmer |
5116 : | Sep 96 Joel Gales Setup dim names for SDsetdimname in dimbuf1 rather |
5117 : | that utlstr |
5118 : | Oct 96 Joel Gales Detach Grid Vgroups |
5119 : | Oct 96 Joel Gales "Detach" from SDS |
5120 : | Nov 96 Joel Gales Call GDchkgdid to check for proper grid ID |
5121 : | Dec 96 Joel Gales Add multiple vertical subsetting garbage collection |
5122 : | Oct 98 Abe Taaheri Added GDXRegion[k]->DimNamePtr[i] =0; after freeing |
5123 : | memory |
5124 : | Sep 99 Abe Taaheri Changed memcpy to memmove because of overlapping |
5125 : | source and destination for GDXSDcomb, nameptr, and |
5126 : | dimptr. memcpy may cause unexpected results. |
5127 : | |
5128 : | END_PROLOG |
5129 : -----------------------------------------------------------------------------*/
5130 : intn
5131 0 : GDdetach(int32 gridID)
5132 :
5133 : {
5134 : intn i; /* Loop index */
5135 : intn j; /* Loop index */
5136 : intn k; /* Loop index */
5137 0 : intn status = 0; /* routine return status variable */
5138 0 : intn statusFill = 0; /* return status from GDgetfillvalue */
5139 :
5140 : int32 *namelen; /* Pointer to name string length array */
5141 : int32 *dimlen; /* Pointer to dim string length array */
5142 : int32 slen1[3]; /* String length array 1 */
5143 : int32 slen2[3]; /* String length array 2 */
5144 : int32 nflds; /* Number of fields */
5145 : int32 match[5]; /* Merged field match array */
5146 : int32 cmbfldcnt; /* Number of fields combined */
5147 : int32 sdid; /* SDS ID */
5148 : int32 vgid; /* Vgroup ID */
5149 : int32 dims[3]; /* Dimension array */
5150 : int32 *offset; /* Pointer to merged field offset array */
5151 : int32 *indvdims; /* Pointer to merged field size array */
5152 : int32 sdInterfaceID; /* SDS interface ID */
5153 : int32 gID; /* Grid ID - offset */
5154 : int32 nflds0; /* Number of fields */
5155 : int32 *namelen0; /* Pointer to name string length array */
5156 : int32 rank; /* Rank of merged field */
5157 : int32 truerank; /* True rank of merged field */
5158 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
5159 : int32 dum; /* Dummy variable */
5160 :
5161 : char *nambuf; /* Pointer to name buffer */
5162 : char **nameptr; /* Pointer to name string pointer array */
5163 : char **dimptr; /* Pointer to dim string pointer array */
5164 : char **nameptr0; /* Pointer to name string pointer array */
5165 : char *ptr1[3]; /* String pointer array */
5166 : char *ptr2[3]; /* String pointer array */
5167 : char dimbuf1[128]; /* Dimension buffer 1 */
5168 : char dimbuf2[128]; /* Dimension buffer 2 */
5169 : char gridname[VGNAMELENMAX + 1]; /* Grid name */
5170 : char *utlbuf; /* Utility buffer */
5171 : char fillval[32];/* Fill value buffer */
5172 :
5173 :
5174 :
5175 0 : status = GDchkgdid(gridID, "GDdetach", &dum, &sdInterfaceID, &dum);
5176 :
5177 0 : if (status == 0)
5178 : {
5179 0 : gID = gridID % idOffset;
5180 0 : Vgetname(GDXGrid[gID].IDTable, gridname);
5181 :
5182 : /* SDS combined fields */
5183 : /* ------------------- */
5184 0 : if (strlen(GDXSDname) == 0)
5185 : {
5186 0 : nflds = 0;
5187 :
5188 : /* Allocate "dummy" arrays so free() doesn't bomb later */
5189 : /* ---------------------------------------------------- */
5190 0 : nameptr = (char **) calloc(1, sizeof(char *));
5191 0 : if(nameptr == NULL)
5192 : {
5193 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5194 0 : return(-1);
5195 : }
5196 0 : namelen = (int32 *) calloc(1, sizeof(int32));
5197 0 : if(namelen == NULL)
5198 : {
5199 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5200 0 : free(nameptr);
5201 0 : return(-1);
5202 : }
5203 0 : nameptr0 = (char **) calloc(1, sizeof(char *));
5204 0 : if(nameptr0 == NULL)
5205 : {
5206 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5207 0 : free(nameptr);
5208 0 : free(namelen);
5209 0 : return(-1);
5210 : }
5211 0 : namelen0 = (int32 *) calloc(1, sizeof(int32));
5212 0 : if(namelen0 == NULL)
5213 : {
5214 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5215 0 : free(nameptr);
5216 0 : free(namelen);
5217 0 : free(nameptr0);
5218 0 : return(-1);
5219 : }
5220 0 : dimptr = (char **) calloc(1, sizeof(char *));
5221 0 : if(dimptr == NULL)
5222 : {
5223 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5224 0 : free(nameptr);
5225 0 : free(namelen);
5226 0 : free(nameptr0);
5227 0 : free(namelen0);
5228 0 : return(-1);
5229 : }
5230 0 : dimlen = (int32 *) calloc(1, sizeof(int32));
5231 0 : if(dimlen == NULL)
5232 : {
5233 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5234 0 : free(nameptr);
5235 0 : free(namelen);
5236 0 : free(nameptr0);
5237 0 : free(namelen0);
5238 0 : free(dimptr);
5239 0 : return(-1);
5240 : }
5241 0 : offset = (int32 *) calloc(1, sizeof(int32));
5242 0 : if(offset == NULL)
5243 : {
5244 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5245 0 : free(nameptr);
5246 0 : free(namelen);
5247 0 : free(nameptr0);
5248 0 : free(namelen0);
5249 0 : free(dimptr);
5250 0 : free(dimlen);
5251 0 : return(-1);
5252 : }
5253 0 : indvdims = (int32 *) calloc(1, sizeof(int32));
5254 0 : if(indvdims == NULL)
5255 : {
5256 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5257 0 : free(nameptr);
5258 0 : free(namelen);
5259 0 : free(nameptr0);
5260 0 : free(namelen0);
5261 0 : free(dimptr);
5262 0 : free(dimlen);
5263 0 : free(offset);
5264 0 : return(-1);
5265 : }
5266 : }
5267 : else
5268 : {
5269 : /*
5270 : * "Trim Off" trailing "," and ";" in GDXSDname & GDXSDdims
5271 : * respectively
5272 : */
5273 0 : GDXSDname[strlen(GDXSDname) - 1] = 0;
5274 0 : GDXSDdims[strlen(GDXSDdims) - 1] = 0;
5275 :
5276 :
5277 : /* Get number of fields from GDXSDname string */
5278 : /* ------------------------------------------ */
5279 0 : nflds = EHparsestr(GDXSDname, ',', NULL, NULL);
5280 :
5281 : /* Allocate space for various dynamic arrays */
5282 : /* ----------------------------------------- */
5283 0 : nameptr = (char **) calloc(nflds, sizeof(char *));
5284 0 : if(nameptr == NULL)
5285 : {
5286 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5287 0 : return(-1);
5288 : }
5289 0 : namelen = (int32 *) calloc(nflds, sizeof(int32));
5290 0 : if(namelen == NULL)
5291 : {
5292 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5293 0 : free(nameptr);
5294 0 : return(-1);
5295 : }
5296 0 : nameptr0 = (char **) calloc(nflds, sizeof(char *));
5297 0 : if(nameptr0 == NULL)
5298 : {
5299 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5300 0 : free(nameptr);
5301 0 : free(namelen);
5302 0 : return(-1);
5303 : }
5304 0 : namelen0 = (int32 *) calloc(nflds, sizeof(int32));
5305 0 : if(namelen0 == NULL)
5306 : {
5307 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5308 0 : free(nameptr);
5309 0 : free(namelen);
5310 0 : free(nameptr0);
5311 0 : return(-1);
5312 : }
5313 0 : dimptr = (char **) calloc(nflds, sizeof(char *));
5314 0 : if(dimptr == NULL)
5315 : {
5316 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5317 0 : free(nameptr);
5318 0 : free(namelen);
5319 0 : free(nameptr0);
5320 0 : free(namelen0);
5321 0 : return(-1);
5322 : }
5323 0 : dimlen = (int32 *) calloc(nflds, sizeof(int32));
5324 0 : if(dimlen == NULL)
5325 : {
5326 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5327 0 : free(nameptr);
5328 0 : free(namelen);
5329 0 : free(nameptr0);
5330 0 : free(namelen0);
5331 0 : free(dimptr);
5332 0 : return(-1);
5333 : }
5334 0 : offset = (int32 *) calloc(nflds, sizeof(int32));
5335 0 : if(offset == NULL)
5336 : {
5337 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5338 0 : free(nameptr);
5339 0 : free(namelen);
5340 0 : free(nameptr0);
5341 0 : free(namelen0);
5342 0 : free(dimptr);
5343 0 : free(dimlen);
5344 0 : return(-1);
5345 : }
5346 0 : indvdims = (int32 *) calloc(nflds, sizeof(int32));
5347 0 : if(indvdims == NULL)
5348 : {
5349 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5350 0 : free(nameptr);
5351 0 : free(namelen);
5352 0 : free(nameptr0);
5353 0 : free(namelen0);
5354 0 : free(dimptr);
5355 0 : free(dimlen);
5356 0 : free(offset);
5357 0 : return(-1);
5358 : }
5359 :
5360 : /* Parse GDXSDname and GDXSDdims strings */
5361 : /* ------------------------------------- */
5362 0 : nflds = EHparsestr(GDXSDname, ',', nameptr, namelen);
5363 0 : nflds = EHparsestr(GDXSDdims, ';', dimptr, dimlen);
5364 : }
5365 :
5366 :
5367 0 : for (i = 0; i < nflds; i++)
5368 : {
5369 0 : if (GDXSDcomb[5 * i] != 0 &&
5370 0 : GDXSDcomb[5 * i + 3] == GDXGrid[gID].IDTable)
5371 : {
5372 0 : nambuf = (char *) calloc(strlen(GDXSDname) + 1, 1);
5373 0 : if(nambuf == NULL)
5374 : {
5375 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5376 0 : free(nameptr);
5377 0 : free(namelen);
5378 0 : free(nameptr0);
5379 0 : free(namelen0);
5380 0 : free(dimptr);
5381 0 : free(dimlen);
5382 0 : free(offset);
5383 0 : return(-1);
5384 : }
5385 0 : utlbuf = (char *) calloc(strlen(GDXSDname) * 2 + 7, 1);
5386 0 : if(utlbuf == NULL)
5387 : {
5388 0 : HEpush(DFE_NOSPACE,"GDdetach", __FILE__, __LINE__);
5389 0 : free(nambuf);
5390 0 : free(nameptr);
5391 0 : free(namelen);
5392 0 : free(nameptr0);
5393 0 : free(namelen0);
5394 0 : free(dimptr);
5395 0 : free(dimlen);
5396 0 : free(offset);
5397 0 : return(-1);
5398 : }
5399 :
5400 0 : for (k = 0; k < (intn)sizeof(dimbuf1); k++)
5401 0 : dimbuf1[k] = 0;
5402 :
5403 :
5404 : /* Load array to match, name & parse dims */
5405 : /* -------------------------------------- */
5406 0 : memcpy(match, &GDXSDcomb[5 * i], 20);
5407 0 : memcpy(nambuf, nameptr[i], namelen[i]);
5408 :
5409 0 : memcpy(dimbuf1, dimptr[i], dimlen[i]);
5410 0 : dum = EHparsestr(dimbuf1, ',', ptr1, slen1);
5411 :
5412 :
5413 : /* Separate combined dimension from others */
5414 : /* --------------------------------------- */
5415 0 : dimbuf1[slen1[0]] = 0;
5416 :
5417 0 : offset[0] = 0;
5418 0 : indvdims[0] = abs(match[0]);
5419 :
5420 0 : for (j = i + 1, cmbfldcnt = 0; j < nflds; j++)
5421 : {
5422 0 : for (k = 0; k < (intn)sizeof(dimbuf2); k++)
5423 0 : dimbuf2[k] = 0;
5424 0 : memcpy(dimbuf2, dimptr[j], dimlen[j]);
5425 0 : dum = EHparsestr(dimbuf2, ',', ptr2, slen2);
5426 0 : dimbuf2[slen2[0]] = 0;
5427 :
5428 :
5429 0 : if (GDXSDcomb[5 * j] != 0 &&
5430 0 : strcmp(dimbuf1 + slen1[0],
5431 0 : dimbuf2 + slen2[0]) == 0 &&
5432 0 : match[1] == GDXSDcomb[5 * j + 1] &&
5433 0 : match[2] == GDXSDcomb[5 * j + 2] &&
5434 0 : match[3] == GDXSDcomb[5 * j + 3] &&
5435 0 : match[4] == GDXSDcomb[5 * j + 4])
5436 : {
5437 : /* Add to combined dimension size */
5438 0 : match[0] += GDXSDcomb[5 * j];
5439 :
5440 : /* Concatenate name */
5441 0 : strcat(nambuf, ",");
5442 0 : memcpy(nambuf + strlen(nambuf),
5443 0 : nameptr[j], namelen[j]);
5444 :
5445 : /* Store individual dims and dim offsets */
5446 0 : cmbfldcnt++;
5447 0 : indvdims[cmbfldcnt] = abs(GDXSDcomb[5 * j]);
5448 0 : offset[cmbfldcnt] =
5449 0 : offset[cmbfldcnt - 1] + indvdims[cmbfldcnt - 1];
5450 :
5451 0 : GDXSDcomb[5 * j] = 0;
5452 : }
5453 : }
5454 :
5455 :
5456 : /* Create SDS */
5457 : /* ---------- */
5458 0 : nflds0 = EHparsestr(nambuf, ',', nameptr0, namelen0);
5459 :
5460 0 : if (abs(match[0]) == 1)
5461 : {
5462 0 : for (k = 0; k < 2; k++)
5463 0 : dims[k] = abs(match[k + 1]);
5464 :
5465 0 : rank = 2;
5466 :
5467 0 : sdid = SDcreate(sdInterfaceID, nambuf,
5468 0 : GDXSDcomb[5 * i + 4], 2, dims);
5469 : }
5470 : else
5471 : {
5472 0 : for (k = 0; k < 3; k++)
5473 0 : dims[k] = abs(match[k]);
5474 :
5475 0 : rank = 3;
5476 :
5477 0 : if (cmbfldcnt > 0)
5478 : {
5479 0 : strcpy(utlbuf, "MRGFLD_");
5480 0 : memcpy(utlbuf + 7, nameptr0[0], namelen0[0]);
5481 0 : utlbuf[7 + namelen0[0]] = 0;
5482 0 : strcat(utlbuf, ":");
5483 0 : strcat(utlbuf, nambuf);
5484 :
5485 0 : status = EHinsertmeta(sdInterfaceID, gridname, "g",
5486 : 6L, utlbuf, NULL);
5487 : }
5488 : else
5489 : {
5490 0 : strcpy(utlbuf, nambuf);
5491 : }
5492 :
5493 0 : sdid = SDcreate(sdInterfaceID, utlbuf,
5494 0 : GDXSDcomb[5 * i + 4], 3, dims);
5495 :
5496 :
5497 0 : if (cmbfldcnt > 0)
5498 : {
5499 0 : SDsetattr(sdid, "Field Dims", DFNT_INT32,
5500 : cmbfldcnt + 1, (VOIDP) indvdims);
5501 :
5502 0 : SDsetattr(sdid, "Field Offsets", DFNT_INT32,
5503 : cmbfldcnt + 1, (VOIDP) offset);
5504 : }
5505 :
5506 : }
5507 :
5508 :
5509 :
5510 : /* Register Dimensions in SDS */
5511 : /* -------------------------- */
5512 0 : for (k = 0; k < rank; k++)
5513 : {
5514 0 : if (rank == 2)
5515 : {
5516 0 : memcpy(dimbuf2, ptr1[k + 1], slen1[k + 1]);
5517 0 : dimbuf2[slen1[k + 1]] = 0;
5518 : }
5519 : else
5520 : {
5521 0 : memcpy(dimbuf2, ptr1[k], slen1[k]);
5522 0 : dimbuf2[slen1[k]] = 0;
5523 : }
5524 :
5525 :
5526 0 : if (k == 0 && rank > 2 && cmbfldcnt > 0)
5527 : {
5528 0 : snprintf(dimbuf2, sizeof(dimbuf2), "%s%s_%d", "MRGDIM:",
5529 0 : gridname, (int)dims[0]);
5530 : }
5531 : else
5532 : {
5533 0 : strcat(dimbuf2, ":");
5534 0 : strcat(dimbuf2, gridname);
5535 : }
5536 0 : SDsetdimname(SDgetdimid(sdid, k), (char *) dimbuf2);
5537 : }
5538 :
5539 :
5540 :
5541 : /* Write Fill Value */
5542 : /* ---------------- */
5543 0 : for (k = 0; k < nflds0; k++)
5544 : {
5545 0 : memcpy(utlbuf, nameptr0[k], namelen0[k]);
5546 0 : utlbuf[namelen[k]] = 0;
5547 0 : statusFill = GDgetfillvalue(gridID, utlbuf, fillval);
5548 :
5549 0 : if (statusFill == 0)
5550 : {
5551 0 : if (cmbfldcnt > 0)
5552 : {
5553 0 : dims[0] = indvdims[k];
5554 0 : truerank = (dims[0] == 1) ? 2 : 3;
5555 0 : EHfillfld(sdid, rank, truerank,
5556 0 : DFKNTsize(match[4]), offset[k],
5557 : dims, fillval);
5558 : }
5559 : else
5560 : {
5561 0 : status = SDsetfillvalue(sdid, fillval);
5562 : }
5563 : }
5564 : }
5565 :
5566 :
5567 0 : vgid = GDXGrid[gID].VIDTable[0];
5568 0 : Vaddtagref(vgid, DFTAG_NDG, SDidtoref(sdid));
5569 0 : SDendaccess(sdid);
5570 :
5571 0 : free(nambuf);
5572 0 : free(utlbuf);
5573 :
5574 : }
5575 : }
5576 :
5577 :
5578 0 : for (i = 0; i < nflds; i++)
5579 : {
5580 0 : if (GDXSDcomb[5 * i + 3] == GDXGrid[gID].IDTable)
5581 : {
5582 0 : if (i == (nflds - 1))
5583 : {
5584 0 : GDXSDcomb[5 * i] = 0;
5585 0 : *(nameptr[i] - (nflds != 1)) = 0;
5586 0 : *(dimptr[i] - (nflds != 1)) = 0;
5587 : }
5588 : else
5589 : {
5590 : /* memcpy(&GDXSDcomb[5 * i],
5591 : &GDXSDcomb[5 * (i + 1)],
5592 : (512 - i - 1) * 5 * 4);*/
5593 0 : memmove(&GDXSDcomb[5 * i],
5594 0 : &GDXSDcomb[5 * (i + 1)],
5595 0 : (512 - i - 1) * 5 * 4);
5596 : /* memcpy(nameptr[i],
5597 : nameptr[i + 1],
5598 : nameptr[0] + 2048 - nameptr[i + 1] - 1);*/
5599 0 : memmove(nameptr[i],
5600 0 : nameptr[i + 1],
5601 0 : nameptr[0] + 2048 - nameptr[i + 1] - 1);
5602 : /* memcpy(dimptr[i],
5603 : dimptr[i + 1],
5604 : dimptr[0] + 2048 * 2 - dimptr[i + 1] - 1);*/
5605 0 : memmove(dimptr[i],
5606 0 : dimptr[i + 1],
5607 0 : dimptr[0] + 2048 * 2 - dimptr[i + 1] - 1);
5608 : }
5609 :
5610 0 : i--;
5611 0 : nflds = EHparsestr(GDXSDname, ',', nameptr, namelen);
5612 0 : nflds = EHparsestr(GDXSDdims, ';', dimptr, dimlen);
5613 : }
5614 : }
5615 :
5616 0 : if (nflds != 0)
5617 : {
5618 0 : strcat(GDXSDname, ",");
5619 0 : strcat(GDXSDdims, ";");
5620 : }
5621 :
5622 :
5623 :
5624 : /* Free up a bunch of dynamically allocated arrays */
5625 : /* ----------------------------------------------- */
5626 0 : free(nameptr);
5627 0 : free(namelen);
5628 0 : free(nameptr0);
5629 0 : free(namelen0);
5630 0 : free(dimptr);
5631 0 : free(dimlen);
5632 0 : free(offset);
5633 0 : free(indvdims);
5634 :
5635 :
5636 :
5637 : /* "Detach" from previously attached SDSs */
5638 : /* -------------------------------------- */
5639 0 : for (k = 0; k < GDXGrid[gID].nSDS; k++)
5640 : {
5641 0 : SDendaccess(GDXGrid[gID].sdsID[k]);
5642 : }
5643 0 : free(GDXGrid[gID].sdsID);
5644 0 : GDXGrid[gID].sdsID = 0;
5645 0 : GDXGrid[gID].nSDS = 0;
5646 :
5647 :
5648 :
5649 : /* Detach Grid Vgroups */
5650 : /* ------------------- */
5651 0 : Vdetach(GDXGrid[gID].VIDTable[0]);
5652 0 : Vdetach(GDXGrid[gID].VIDTable[1]);
5653 0 : Vdetach(GDXGrid[gID].IDTable);
5654 :
5655 0 : GDXGrid[gID].active = 0;
5656 0 : GDXGrid[gID].VIDTable[0] = 0;
5657 0 : GDXGrid[gID].VIDTable[1] = 0;
5658 0 : GDXGrid[gID].IDTable = 0;
5659 0 : GDXGrid[gID].fid = 0;
5660 :
5661 :
5662 :
5663 :
5664 : /* Free Region Pointers */
5665 : /* -------------------- */
5666 0 : for (k = 0; k < NGRIDREGN; k++)
5667 : {
5668 0 : if (GDXRegion[k] != 0 &&
5669 0 : GDXRegion[k]->gridID == gridID)
5670 : {
5671 0 : for (i = 0; i < 8; i++)
5672 : {
5673 0 : if (GDXRegion[k]->DimNamePtr[i] != 0)
5674 : {
5675 0 : free(GDXRegion[k]->DimNamePtr[i]);
5676 0 : GDXRegion[k]->DimNamePtr[i] = 0;
5677 : }
5678 : }
5679 :
5680 0 : free(GDXRegion[k]);
5681 0 : GDXRegion[k] = 0;
5682 : }
5683 : }
5684 : }
5685 0 : return (status);
5686 : }
5687 :
5688 :
5689 : /*----------------------------------------------------------------------------|
5690 : | BEGIN_PROLOG |
5691 : | |
5692 : | FUNCTION: GDclose |
5693 : | |
5694 : | DESCRIPTION: Closes file. |
5695 : | |
5696 : | |
5697 : | Return Value Type Units Description |
5698 : | ============ ====== ========= ===================================== |
5699 : | status intn return status (0) SUCCEED, (-1) FAIL |
5700 : | |
5701 : | INPUTS: |
5702 : | fid int32 File ID |
5703 : | |
5704 : | |
5705 : | OUTPUTS: |
5706 : | None |
5707 : | |
5708 : | NOTES: |
5709 : | |
5710 : | |
5711 : | Date Programmer Description |
5712 : | ====== ============ ================================================= |
5713 : | Jun 96 Joel Gales Original Programmer |
5714 : | |
5715 : | END_PROLOG |
5716 : -----------------------------------------------------------------------------*/
5717 : intn
5718 4 : GDclose(int32 fid)
5719 :
5720 : {
5721 4 : intn status = 0; /* routine return status variable */
5722 :
5723 : /* Call EHclose to perform file close */
5724 : /* ---------------------------------- */
5725 4 : status = EHclose(fid);
5726 :
5727 4 : return (status);
5728 : }
5729 :
5730 :
5731 : /*----------------------------------------------------------------------------|
5732 : | BEGIN_PROLOG |
5733 : | |
5734 : | FUNCTION: GDgetdefaults |
5735 : | |
5736 : | DESCRIPTION: |
5737 : | |
5738 : | |
5739 : | Return Value Type Units Description |
5740 : | ============ ====== ========= ===================================== |
5741 : | status intn return status (0) SUCCEED, (-1) FAIL |
5742 : | |
5743 : | INPUTS: |
5744 : | projcode int32 GCTP projection code |
5745 : | zonecode int32 UTM zone code |
5746 : | projparm float64 Projection parameters |
5747 : | spherecode int32 GCTP spheriod code |
5748 : | upleftpt float64 upper left corner coordinates |
5749 : | lowrightpt float64 lower right corner coordinates |
5750 : | |
5751 : | |
5752 : | OUTPUTS: |
5753 : | upleftpt float64 upper left corner coordinates |
5754 : | lowrightpt float64 lower right corner coordinates |
5755 : | |
5756 : | NOTES: |
5757 : | |
5758 : | |
5759 : | Date Programmer Description |
5760 : | ====== ============ ================================================= |
5761 : | Aug 96 Joel Gales Original Programmer |
5762 : | Sep 96 Raj Gejjaga Fixed bugs in Polar Stereographic and Goode | | Homolosine default calculations. |
5763 : | Sep 96 Raj Gejjaga Added code to compute default boundary points |
5764 : | for Lambert Azimuthal Polar and Equatorial |
5765 : | projections. |
5766 : | Feb 97 Raj Gejjaga Added code to compute default boundary points |
5767 : | for Integerized Sinusoidal Grid. Added error |
5768 : | handling code. |
5769 : | Jun 00 Abe Taaheri Added support for EASE grid |
5770 : | |
5771 : | END_PROLOG |
5772 : -----------------------------------------------------------------------------*/
5773 : static intn
5774 0 : GDgetdefaults(int32 projcode, int32 zonecode, float64 projparm[],
5775 : int32 spherecode, float64 upleftpt[], float64 lowrightpt[])
5776 : {
5777 0 : int32 errorcode = 0, status = 0;
5778 : int32(*for_trans[100]) (double, double, double*, double*);
5779 :
5780 : float64 lon, lat, plat, x, y;
5781 : float64 plon, tlon, llon, rlon, pplon, LLon, LLat, RLon, RLat;
5782 :
5783 :
5784 : /* invoke GCTP initialization routine */
5785 : /* ---------------------------------- */
5786 0 : for_init(projcode, zonecode, projparm, spherecode, NULL, NULL,
5787 : &errorcode, for_trans);
5788 :
5789 : /* Report error if any */
5790 : /* ------------------- */
5791 0 : if (errorcode != 0)
5792 : {
5793 0 : status = -1;
5794 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
5795 0 : HEreport("GCTP Error: %d\n", errorcode);
5796 0 : return (status);
5797 : }
5798 :
5799 : /* Compute Default Boundary Points for EASE Grid */
5800 : /* Use Global coverage */
5801 : /* ------------------------------------------------------ */
5802 0 : if (projcode == GCTP_BCEA &&
5803 0 : upleftpt[0] == 0 && upleftpt[1] == 0 &&
5804 0 : lowrightpt[0] == 0 && lowrightpt[1] == 0)
5805 : {
5806 0 : upleftpt[0] = EHconvAng(EASE_GRID_DEFAULT_UPLEFT_LON, HDFE_DEG_DMS);
5807 0 : upleftpt[1] = EHconvAng(EASE_GRID_DEFAULT_UPLEFT_LAT, HDFE_DEG_DMS);
5808 0 : lowrightpt[0] = EHconvAng(EASE_GRID_DEFAULT_LOWRGT_LON, HDFE_DEG_DMS);
5809 0 : lowrightpt[1] = EHconvAng(EASE_GRID_DEFAULT_LOWRGT_LAT, HDFE_DEG_DMS);
5810 : }
5811 :
5812 : /* Compute Default Boundary Points for CEA */
5813 : /* --------------------------------------------*/
5814 0 : if (projcode == GCTP_CEA &&
5815 0 : upleftpt[0] == 0 && upleftpt[1] == 0 &&
5816 0 : lowrightpt[0] == 0 && lowrightpt[1] == 0)
5817 : {
5818 0 : LLon = EHconvAng(EASE_GRID_DEFAULT_UPLEFT_LON, HDFE_DEG_RAD);
5819 0 : LLat = EHconvAng(EASE_GRID_DEFAULT_UPLEFT_LAT, HDFE_DEG_RAD);
5820 0 : RLon = EHconvAng(EASE_GRID_DEFAULT_LOWRGT_LON, HDFE_DEG_RAD);
5821 0 : RLat = EHconvAng(EASE_GRID_DEFAULT_LOWRGT_LAT, HDFE_DEG_RAD);
5822 :
5823 0 : errorcode = for_trans[projcode] (LLon, LLat, &x, &y);
5824 0 : if (errorcode != 0)
5825 : {
5826 0 : status = -1;
5827 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
5828 0 : HEreport("GCTP Error: %d\n", errorcode);
5829 0 : return (status);
5830 : }
5831 0 : upleftpt[0] = x;
5832 0 : upleftpt[1] = y;
5833 :
5834 0 : errorcode = for_trans[projcode] (RLon, RLat, &x, &y);
5835 0 : if (errorcode != 0)
5836 : {
5837 0 : status = -1;
5838 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
5839 0 : HEreport("GCTP Error: %d\n", errorcode);
5840 0 : return (status);
5841 : }
5842 0 : lowrightpt[0] = x;
5843 0 : lowrightpt[1] = y;
5844 :
5845 : }
5846 :
5847 :
5848 : /* Compute Default Boundary Points for Polar Sterographic */
5849 : /* ------------------------------------------------------ */
5850 0 : if (projcode == GCTP_PS &&
5851 0 : upleftpt[0] == 0 && upleftpt[1] == 0 &&
5852 0 : lowrightpt[0] == 0 && lowrightpt[1] == 0)
5853 : {
5854 : /*
5855 : * Convert the longitude and latitude from the DMS to decimal degree
5856 : * format.
5857 : */
5858 0 : plon = EHconvAng(projparm[4], HDFE_DMS_DEG);
5859 0 : plat = EHconvAng(projparm[5], HDFE_DMS_DEG);
5860 :
5861 : /*
5862 : * Compute the longitudes at 90, 180 and 270 degrees from the central
5863 : * longitude.
5864 : */
5865 :
5866 0 : if (plon <= 0.0)
5867 : {
5868 0 : tlon = 180.0 + plon;
5869 0 : pplon = plon + 360.0;
5870 : }
5871 : else
5872 : {
5873 0 : tlon = plon - 180.0;
5874 0 : pplon = plon;
5875 : }
5876 :
5877 0 : rlon = pplon + 90.0;
5878 0 : if (rlon > 360.0)
5879 0 : rlon = rlon - 360;
5880 :
5881 0 : if (rlon > 180.0)
5882 0 : rlon = rlon - 360.0;
5883 :
5884 0 : if (rlon <= 0.0)
5885 0 : llon = 180.0 + rlon;
5886 : else
5887 0 : llon = rlon - 180.0;
5888 :
5889 :
5890 : /* Convert all four longitudes from decimal degrees to radians */
5891 0 : plon = EHconvAng(plon, HDFE_DEG_RAD);
5892 0 : tlon = EHconvAng(tlon, HDFE_DEG_RAD);
5893 0 : llon = EHconvAng(llon, HDFE_DEG_RAD);
5894 0 : rlon = EHconvAng(rlon, HDFE_DEG_RAD);
5895 :
5896 0 : errorcode = for_trans[projcode] (llon, 0.0, &x, &y);
5897 0 : if (errorcode != 0)
5898 : {
5899 0 : status = -1;
5900 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
5901 0 : HEreport("GCTP Error: %d\n", errorcode);
5902 0 : return (status);
5903 : }
5904 :
5905 0 : upleftpt[0] = x;
5906 :
5907 0 : errorcode = for_trans[projcode] (rlon, 0.0, &x, &y);
5908 0 : if (errorcode != 0)
5909 : {
5910 0 : status = -1;
5911 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
5912 0 : HEreport("GCTP Error: %d\n", errorcode);
5913 0 : return (status);
5914 : }
5915 :
5916 0 : lowrightpt[0] = x;
5917 :
5918 : /*
5919 : * Compute the upperleft and lowright y values based on the south or
5920 : * north polar projection
5921 : */
5922 :
5923 0 : if (plat < 0.0)
5924 : {
5925 0 : errorcode = for_trans[projcode] (plon, 0.0, &x, &y);
5926 0 : if (errorcode != 0)
5927 : {
5928 0 : status = -1;
5929 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
5930 0 : HEreport("GCTP Error: %d\n", errorcode);
5931 0 : return (status);
5932 : }
5933 :
5934 0 : upleftpt[1] = y;
5935 :
5936 0 : errorcode = for_trans[projcode] (tlon, 0.0, &x, &y);
5937 0 : if (errorcode != 0)
5938 : {
5939 0 : status = -1;
5940 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
5941 0 : HEreport("GCTP Error: %d\n", errorcode);
5942 0 : return (status);
5943 : }
5944 :
5945 0 : lowrightpt[1] = y;
5946 :
5947 : }
5948 : else
5949 : {
5950 0 : errorcode = for_trans[projcode] (tlon, 0.0, &x, &y);
5951 0 : if (errorcode != 0)
5952 : {
5953 0 : status = -1;
5954 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
5955 0 : HEreport("GCTP Error: %d\n", errorcode);
5956 0 : return (status);
5957 : }
5958 :
5959 0 : upleftpt[1] = y;
5960 :
5961 0 : errorcode = for_trans[projcode] (plon, 0.0, &x, &y);
5962 0 : if (errorcode != 0)
5963 : {
5964 0 : status = -1;
5965 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
5966 0 : HEreport("GCTP Error: %d\n", errorcode);
5967 0 : return (status);
5968 : }
5969 :
5970 0 : lowrightpt[1] = y;
5971 :
5972 : }
5973 : }
5974 :
5975 :
5976 : /* Compute Default Boundary Points for Goode Homolosine */
5977 : /* ---------------------------------------------------- */
5978 0 : if (projcode == GCTP_GOOD &&
5979 0 : upleftpt[0] == 0 && upleftpt[1] == 0 &&
5980 0 : lowrightpt[0] == 0 && lowrightpt[1] == 0)
5981 : {
5982 0 : lon = EHconvAng(-180, HDFE_DEG_RAD);
5983 0 : lat = 0.0;
5984 :
5985 0 : errorcode = for_trans[projcode] (lon, lat, &x, &y);
5986 0 : if (errorcode != 0)
5987 : {
5988 0 : status = -1;
5989 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
5990 0 : HEreport("GCTP Error: %d\n", errorcode);
5991 0 : return (status);
5992 : }
5993 :
5994 0 : upleftpt[0] = -fabs(x);
5995 0 : lowrightpt[0] = +fabs(x);
5996 :
5997 0 : lat = EHconvAng(90, HDFE_DEG_RAD);
5998 :
5999 0 : errorcode = for_trans[projcode] (lon, lat, &x, &y);
6000 0 : if (errorcode != 0)
6001 : {
6002 0 : status = -1;
6003 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
6004 0 : HEreport("GCTP Error: %d\n", errorcode);
6005 0 : return (status);
6006 : }
6007 :
6008 0 : upleftpt[1] = +fabs(y);
6009 0 : lowrightpt[1] = -fabs(y);
6010 : }
6011 :
6012 : /* Compute Default Boundary Points for Lambert Azimuthal */
6013 : /* ----------------------------------------------------- */
6014 0 : if (projcode == GCTP_LAMAZ &&
6015 0 : upleftpt[0] == 0 && upleftpt[1] == 0 &&
6016 0 : lowrightpt[0] == 0 && lowrightpt[1] == 0)
6017 : {
6018 : /*
6019 : * Convert the longitude and latitude from the DMS to decimal degree
6020 : * format.
6021 : */
6022 0 : plon = EHconvAng(projparm[4], HDFE_DMS_DEG);
6023 0 : plat = EHconvAng(projparm[5], HDFE_DMS_DEG);
6024 :
6025 : /*
6026 : * Compute the longitudes at 90, 180 and 270 degrees from the central
6027 : * longitude.
6028 : */
6029 :
6030 0 : if (plon <= 0.0)
6031 : {
6032 0 : tlon = 180.0 + plon;
6033 0 : pplon = plon + 360.0;
6034 : }
6035 : else
6036 : {
6037 0 : tlon = plon - 180.0;
6038 0 : pplon = plon;
6039 : }
6040 :
6041 0 : rlon = pplon + 90.0;
6042 0 : if (rlon > 360.0)
6043 0 : rlon = rlon - 360;
6044 :
6045 0 : if (rlon > 180.0)
6046 0 : rlon = rlon - 360.0;
6047 :
6048 0 : if (rlon <= 0.0)
6049 0 : llon = 180.0 + rlon;
6050 : else
6051 0 : llon = rlon - 180.0;
6052 :
6053 : /* Convert all four longitudes from decimal degrees to radians */
6054 0 : plon = EHconvAng(plon, HDFE_DEG_RAD);
6055 0 : tlon = EHconvAng(tlon, HDFE_DEG_RAD);
6056 0 : llon = EHconvAng(llon, HDFE_DEG_RAD);
6057 0 : rlon = EHconvAng(rlon, HDFE_DEG_RAD);
6058 :
6059 0 : errorcode = for_trans[projcode] (llon, 0.0, &x, &y);
6060 0 : if (errorcode != 0)
6061 : {
6062 0 : status = -1;
6063 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
6064 0 : HEreport("GCTP Error: %d\n", errorcode);
6065 0 : return (status);
6066 : }
6067 :
6068 0 : upleftpt[0] = x;
6069 :
6070 0 : errorcode = for_trans[projcode] (rlon, 0.0, &x, &y);
6071 0 : if (errorcode != 0)
6072 : {
6073 0 : status = -1;
6074 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
6075 0 : HEreport("GCTP Error: %d\n", errorcode);
6076 0 : return (status);
6077 : }
6078 :
6079 0 : lowrightpt[0] = x;
6080 :
6081 : /*
6082 : * Compute upperleft and lowerright values based on whether the
6083 : * projection is south polar, north polar or equatorial
6084 : */
6085 :
6086 0 : if (plat == -90.0)
6087 : {
6088 0 : errorcode = for_trans[projcode] (plon, 0.0, &x, &y);
6089 0 : if (errorcode != 0)
6090 : {
6091 0 : status = -1;
6092 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
6093 0 : HEreport("GCTP Error: %d\n", errorcode);
6094 0 : return (status);
6095 : }
6096 :
6097 0 : upleftpt[1] = y;
6098 :
6099 0 : errorcode = for_trans[projcode] (tlon, 0.0, &x, &y);
6100 0 : if (errorcode != 0)
6101 : {
6102 0 : status = -1;
6103 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
6104 0 : HEreport("GCTP Error: %d\n", errorcode);
6105 0 : return (status);
6106 : }
6107 :
6108 0 : lowrightpt[1] = y;
6109 : }
6110 0 : else if (plat == 90.0)
6111 : {
6112 0 : errorcode = for_trans[projcode] (tlon, 0.0, &x, &y);
6113 0 : if (errorcode != 0)
6114 : {
6115 0 : status = -1;
6116 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
6117 0 : HEreport("GCTP Error: %d\n", errorcode);
6118 0 : return (status);
6119 : }
6120 :
6121 0 : upleftpt[1] = y;
6122 :
6123 0 : errorcode = for_trans[projcode] (plon, 0.0, &x, &y);
6124 0 : if (errorcode != 0)
6125 : {
6126 0 : status = -1;
6127 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
6128 0 : HEreport("GCTP Error: %d\n", errorcode);
6129 0 : return (status);
6130 : }
6131 :
6132 0 : lowrightpt[1] = y;
6133 : }
6134 : else
6135 : {
6136 0 : lat = EHconvAng(90, HDFE_DEG_RAD);
6137 0 : errorcode = for_trans[projcode] (plon, lat, &x, &y);
6138 0 : if (errorcode != 0)
6139 : {
6140 0 : status = -1;
6141 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
6142 0 : HEreport("GCTP Error: %d\n", errorcode);
6143 0 : return (status);
6144 : }
6145 :
6146 0 : upleftpt[1] = y;
6147 :
6148 0 : lat = EHconvAng(-90, HDFE_DEG_RAD);
6149 0 : errorcode = for_trans[projcode] (plon, lat, &x, &y);
6150 0 : if (errorcode != 0)
6151 : {
6152 0 : status = -1;
6153 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
6154 0 : HEreport("GCTP Error: %d\n", errorcode);
6155 0 : return (status);
6156 : }
6157 :
6158 0 : lowrightpt[1] = y;
6159 : }
6160 : }
6161 :
6162 : /* Compute Default Boundary Points for Integerized Sinusoidal Grid */
6163 : /* --------------------------------------------------------------- */
6164 0 : if (((projcode == GCTP_ISINUS) || (projcode == GCTP_ISINUS1)) &&
6165 0 : upleftpt[0] == 0 && upleftpt[1] == 0 &&
6166 0 : lowrightpt[0] == 0 && lowrightpt[1] == 0)
6167 : {
6168 : /*
6169 : * Convert the longitude and latitude from the DMS to decimal degree
6170 : * format.
6171 : */
6172 0 : plon = EHconvAng(projparm[4], HDFE_DMS_DEG);
6173 : /*plat = EHconvAng(projparm[5], HDFE_DMS_DEG); */
6174 :
6175 : /*
6176 : * Compute the longitudes at 90, 180 and 270 degrees from the central
6177 : * longitude.
6178 : */
6179 :
6180 0 : if (plon <= 0.0)
6181 : {
6182 0 : tlon = 180.0 + plon;
6183 0 : pplon = plon + 360.0;
6184 : }
6185 : else
6186 : {
6187 0 : tlon = plon - 180.0;
6188 0 : pplon = plon;
6189 : }
6190 :
6191 0 : rlon = pplon + 90.0;
6192 0 : if (rlon > 360.0)
6193 0 : rlon = rlon - 360;
6194 :
6195 0 : if (rlon > 180.0)
6196 0 : rlon = rlon - 360.0;
6197 :
6198 0 : if (rlon <= 0.0)
6199 0 : llon = 180.0 + rlon;
6200 : else
6201 0 : llon = rlon - 180.0;
6202 :
6203 : /* Convert all four longitudes from decimal degrees to radians */
6204 0 : plon = EHconvAng(plon, HDFE_DEG_RAD);
6205 0 : tlon = EHconvAng(tlon, HDFE_DEG_RAD);
6206 0 : llon = EHconvAng(llon, HDFE_DEG_RAD);
6207 0 : rlon = EHconvAng(rlon, HDFE_DEG_RAD);
6208 :
6209 0 : errorcode = for_trans[projcode] (llon, 0.0, &x, &y);
6210 0 : if (errorcode != 0)
6211 : {
6212 0 : status = -1;
6213 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
6214 0 : HEreport("GCTP Error: %d\n", errorcode);
6215 0 : return (status);
6216 : }
6217 :
6218 0 : upleftpt[0] = x;
6219 :
6220 0 : errorcode = for_trans[projcode] (rlon, 0.0, &x, &y);
6221 0 : if (errorcode != 0)
6222 : {
6223 0 : status = -1;
6224 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
6225 0 : HEreport("GCTP Error: %d\n", errorcode);
6226 0 : return (status);
6227 : }
6228 :
6229 0 : lowrightpt[0] = x;
6230 :
6231 0 : lat = EHconvAng(90, HDFE_DEG_RAD);
6232 0 : errorcode = for_trans[projcode] (plon, lat, &x, &y);
6233 0 : if (errorcode != 0)
6234 : {
6235 0 : status = -1;
6236 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
6237 0 : HEreport("GCTP Error: %d\n", errorcode);
6238 0 : return (status);
6239 : }
6240 :
6241 0 : upleftpt[1] = y;
6242 :
6243 0 : lat = EHconvAng(-90, HDFE_DEG_RAD);
6244 0 : errorcode = for_trans[projcode] (plon, lat, &x, &y);
6245 0 : if (errorcode != 0)
6246 : {
6247 0 : status = -1;
6248 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
6249 0 : HEreport("GCTP Error: %d\n", errorcode);
6250 0 : return (status);
6251 : }
6252 :
6253 0 : lowrightpt[1] = y;
6254 : }
6255 0 : return (errorcode);
6256 : }
6257 :
6258 : /*----------------------------------------------------------------------------|
6259 : | BEGIN_PROLOG |
6260 : | |
6261 : | FUNCTION: GDll2ij |
6262 : | |
6263 : | DESCRIPTION: |
6264 : | |
6265 : | |
6266 : | Return Value Type Units Description |
6267 : | ============ ====== ========= ===================================== |
6268 : | status intn return status (0) SUCCEED, (-1) FAIL |
6269 : | |
6270 : | INPUTS: |
6271 : | projcode int32 GCTP projection code |
6272 : | zonecode int32 UTM zone code |
6273 : | projparm float64 Projection parameters |
6274 : | spherecode int32 GCTP spheriod code |
6275 : | xdimsize int32 xdimsize from GDcreate |
6276 : | ydimsize int32 ydimsize from GDcreate |
6277 : | upleftpt float64 upper left corner coordinates |
6278 : | lowrightpt float64 lower right corner coordinates |
6279 : | npnts int32 number of lon-lat points |
6280 : | longitude float64 longitude array (radians) |
6281 : | latitude float64 latitude array (radians) |
6282 : | |
6283 : | OUTPUTS: |
6284 : | row int32 Row array |
6285 : | col int32 Column array |
6286 : | xval float64 X value array |
6287 : | yval float64 Y value array |
6288 : | |
6289 : | |
6290 : | NOTES: |
6291 : | |
6292 : | |
6293 : | Date Programmer Description |
6294 : | ====== ============ ================================================= |
6295 : | Jun 96 Joel Gales Original Programmer |
6296 : | Aug 96 Joel Gales Return x and y values if requested |
6297 : | Jun 00 Abe Taaheri Added support for EASE grid |
6298 : | |
6299 : | END_PROLOG |
6300 : -----------------------------------------------------------------------------*/
6301 : static intn
6302 0 : GDll2ij(int32 projcode, int32 zonecode, float64 projparm[],
6303 : int32 spherecode, int32 xdimsize, int32 ydimsize,
6304 : float64 upleftpt[], float64 lowrightpt[],
6305 : int32 npnts, float64 longitude[], float64 latitude[],
6306 : int32 row[], int32 col[], float64 xval[], float64 yval[])
6307 :
6308 :
6309 : {
6310 : intn i; /* Loop index */
6311 0 : intn status = 0; /* routine return status variable */
6312 :
6313 0 : int32 errorcode = 0; /* GCTP error code */
6314 : int32(*for_trans[100]) (double, double, double*, double*); /* GCTP function pointer */
6315 :
6316 : float64 xVal; /* Scaled x distance */
6317 : float64 yVal; /* Scaled y distance */
6318 : float64 xMtr; /* X value in meters from GCTP */
6319 : float64 yMtr; /* Y value in meters from GCTP */
6320 : float64 lonrad0; /* Longitude in radians of upleft point */
6321 0 : float64 latrad0 = 0; /* Latitude in radians of upleft point */
6322 : float64 lonrad; /* Longitude in radians of point */
6323 : float64 latrad; /* Latitude in radians of point */
6324 : float64 scaleX; /* X scale factor */
6325 : float64 scaleY; /* Y scale factor */
6326 0 : float64 xMtr0 = 0, xMtr1, yMtr0 = 0, yMtr1;
6327 : float64 lonrad1; /* Longitude in radians of lowright point */
6328 :
6329 : /* If projection not GEO call GCTP initialization routine */
6330 : /* ------------------------------------------------------ */
6331 0 : if (projcode != GCTP_GEO)
6332 : {
6333 0 : for_init(projcode, zonecode, projparm, spherecode, NULL, NULL,
6334 : &errorcode, for_trans);
6335 :
6336 : /* Report error if any */
6337 : /* ------------------- */
6338 0 : if (errorcode != 0)
6339 : {
6340 0 : status = -1;
6341 0 : HEpush(DFE_GENAPP, "GDll2ij", __FILE__, __LINE__);
6342 0 : HEreport("GCTP Error: %d\n", errorcode);
6343 : }
6344 : }
6345 :
6346 :
6347 0 : if (status == 0)
6348 : {
6349 : /* GEO projection */
6350 : /* -------------- */
6351 0 : if (projcode == GCTP_GEO)
6352 : {
6353 : /* Convert upleft and lowright X coords from DMS to radians */
6354 : /* -------------------------------------------------------- */
6355 0 : lonrad0 = EHconvAng(upleftpt[0], HDFE_DMS_RAD);
6356 0 : lonrad = EHconvAng(lowrightpt[0], HDFE_DMS_RAD);
6357 :
6358 : /* Compute x scale factor */
6359 : /* ---------------------- */
6360 0 : scaleX = (lonrad - lonrad0) / xdimsize;
6361 :
6362 :
6363 : /* Convert upleft and lowright Y coords from DMS to radians */
6364 : /* -------------------------------------------------------- */
6365 0 : latrad0 = EHconvAng(upleftpt[1], HDFE_DMS_RAD);
6366 0 : latrad = EHconvAng(lowrightpt[1], HDFE_DMS_RAD);
6367 :
6368 :
6369 : /* Compute y scale factor */
6370 : /* ---------------------- */
6371 0 : scaleY = (latrad - latrad0) / ydimsize;
6372 : }
6373 :
6374 : /* BCEA projection */
6375 : /* -------------- */
6376 0 : else if ( projcode == GCTP_BCEA)
6377 : {
6378 : /* Convert upleft and lowright X coords from DMS to radians */
6379 : /* -------------------------------------------------------- */
6380 :
6381 0 : lonrad0 = EHconvAng(upleftpt[0], HDFE_DMS_RAD);
6382 0 : lonrad = EHconvAng(lowrightpt[0], HDFE_DMS_RAD);
6383 :
6384 : /* Convert upleft and lowright Y coords from DMS to radians */
6385 : /* -------------------------------------------------------- */
6386 0 : latrad0 = EHconvAng(upleftpt[1], HDFE_DMS_RAD);
6387 0 : latrad = EHconvAng(lowrightpt[1], HDFE_DMS_RAD);
6388 :
6389 : /* Convert from lon/lat to meters(or whatever unit is, i.e unit
6390 : of r_major and r_minor) using GCTP */
6391 : /* ----------------------------------------- */
6392 0 : errorcode = for_trans[projcode] (lonrad0, latrad0, &xMtr0, &yMtr0);
6393 :
6394 :
6395 : /* Report error if any */
6396 : /* ------------------- */
6397 0 : if (errorcode != 0)
6398 : {
6399 0 : status = -1;
6400 0 : HEpush(DFE_GENAPP, "GDll2ij", __FILE__, __LINE__);
6401 0 : HEreport("GCTP Error: %d\n", errorcode);
6402 0 : return (status);
6403 : }
6404 :
6405 : /* Convert from lon/lat to meters(or whatever unit is, i.e unit
6406 : of r_major and r_minor) using GCTP */
6407 : /* ----------------------------------------- */
6408 0 : errorcode = for_trans[projcode] (lonrad, latrad, &xMtr1, &yMtr1);
6409 :
6410 :
6411 : /* Report error if any */
6412 : /* ------------------- */
6413 0 : if (errorcode != 0)
6414 : {
6415 0 : status = -1;
6416 0 : HEpush(DFE_GENAPP, "GDll2ij", __FILE__, __LINE__);
6417 0 : HEreport("GCTP Error: %d\n", errorcode);
6418 0 : return (status);
6419 : }
6420 :
6421 : /* Compute x scale factor */
6422 : /* ---------------------- */
6423 0 : scaleX = (xMtr1 - xMtr0) / xdimsize;
6424 :
6425 : /* Compute y scale factor */
6426 : /* ---------------------- */
6427 0 : scaleY = (yMtr1 - yMtr0) / ydimsize;
6428 : }
6429 : else
6430 : {
6431 : /* Non-GEO, Non_BCEA projections */
6432 : /* ---------------------------- */
6433 :
6434 : /* Compute x & y scale factors */
6435 : /* --------------------------- */
6436 0 : scaleX = (lowrightpt[0] - upleftpt[0]) / xdimsize;
6437 0 : scaleY = (lowrightpt[1] - upleftpt[1]) / ydimsize;
6438 : }
6439 :
6440 :
6441 :
6442 : /* Loop through all points */
6443 : /* ----------------------- */
6444 0 : for (i = 0; i < npnts; i++)
6445 : {
6446 : /* Convert lon & lat from decimal degrees to radians */
6447 : /* ------------------------------------------------- */
6448 0 : lonrad = EHconvAng(longitude[i], HDFE_DEG_RAD);
6449 0 : latrad = EHconvAng(latitude[i], HDFE_DEG_RAD);
6450 :
6451 :
6452 : /* GEO projection */
6453 : /* -------------- */
6454 0 : if (projcode == GCTP_GEO)
6455 : {
6456 : /* allow map to span dateline */
6457 0 : lonrad0 = EHconvAng(upleftpt[0], HDFE_DMS_RAD);
6458 0 : lonrad1 = EHconvAng(lowrightpt[0], HDFE_DMS_RAD);
6459 : /* if time-line is passed */
6460 0 : if(lonrad < lonrad1)
6461 : {
6462 0 : if (lonrad < lonrad0) lonrad += 2.0 * M_PI;
6463 0 : if (lonrad > lonrad1) lonrad -= 2.0 * M_PI;
6464 : }
6465 :
6466 : /* Compute scaled distance to point from origin */
6467 : /* -------------------------------------------- */
6468 0 : xVal = (lonrad - lonrad0) / scaleX;
6469 0 : yVal = (latrad - latrad0) / scaleY;
6470 : }
6471 : else
6472 : {
6473 : /* Convert from lon/lat to meters using GCTP */
6474 : /* ----------------------------------------- */
6475 0 : errorcode = for_trans[projcode] (lonrad, latrad, &xMtr, &yMtr);
6476 :
6477 :
6478 : /* Report error if any */
6479 : /* ------------------- */
6480 0 : if (errorcode != 0)
6481 : {
6482 : /*status = -1;
6483 : HEpush(DFE_GENAPP, "GDll2ij", __FILE__, __LINE__);
6484 : HEreport("GCTP Error: %d\n", errorcode);
6485 : return (status); */ /* Bruce Beaumont */
6486 0 : xVal = -2147483648.0; /* Bruce Beaumont */
6487 0 : yVal = -2147483648.0; /* Bruce Beaumont */
6488 : }/* (Note: MAXLONG is defined as 2147483647.0 in
6489 : function cproj.c of GCTP) */
6490 : else {
6491 : /* if projection is BCEA normalize x and y by cell size and
6492 : measure it from the upperleft corner of the grid */
6493 :
6494 : /* Compute scaled distance to point from origin */
6495 : /* -------------------------------------------- */
6496 0 : if( projcode == GCTP_BCEA)
6497 : {
6498 0 : xVal = (xMtr - xMtr0) / scaleX;
6499 0 : yVal = (yMtr - yMtr0) / scaleY;
6500 : }
6501 : else
6502 : {
6503 0 : xVal = (xMtr - upleftpt[0]) / scaleX;
6504 0 : yVal = (yMtr - upleftpt[1]) / scaleY;
6505 : }
6506 : }
6507 : }
6508 :
6509 :
6510 : /* Compute row and col from scaled distance */
6511 : /* ---------------------------------------- */
6512 0 : col[i] = (int32) xVal;
6513 0 : row[i] = (int32) yVal;
6514 :
6515 : /* Store scaled distances if requested */
6516 : /* ----------------------------------- */
6517 0 : if (xval != NULL)
6518 : {
6519 0 : xval[i] = xVal;
6520 : }
6521 :
6522 0 : if (yval != NULL)
6523 : {
6524 0 : yval[i] = yVal;
6525 : }
6526 : }
6527 : }
6528 0 : return (status);
6529 : }
6530 :
6531 :
6532 :
6533 :
6534 : /*----------------------------------------------------------------------------|
6535 : | BEGIN_PROLOG |
6536 : | |
6537 : | FUNCTION: GDrs2ll |
6538 : | |
6539 : | DESCRIPTION: Converts EASE grid's (r,s) coordinates to longitude and |
6540 : | latitude (in decimal degrees). |
6541 : | |
6542 : | |
6543 : | Return Value Type Units Description |
6544 : | ============ ====== ========= ===================================== |
6545 : | status intn return status (0) SUCCEED, (-1) FAIL |
6546 : | |
6547 : | INPUTS: |
6548 : | projcode int32 GCTP projection code |
6549 : | projparm float64 Projection parameters |
6550 : | xdimsize int32 xdimsize from GDcreate |
6551 : | ydimsize int32 ydimsize from GDcreate |
6552 : | pixcen int32 pixel center code |
6553 : | npnts int32 number of lon-lat points |
6554 : | s int32 s coordinate |
6555 : | r int32 r coordinate |
6556 : | pixcen int32 Code from GDpixreginfo |
6557 : | pixcnr int32 Code from GDorigininfo |
6558 : | upleft float64 upper left corner coordinates (DMS) |
6559 : | lowright float64 lower right corner coordinates (DMS) |
6560 : | |
6561 : | |
6562 : | OUTPUTS: |
6563 : | longitude float64 longitude array (decimal degrees) |
6564 : | latitude float64 latitude array (decimal degrees) |
6565 : | |
6566 : | NOTES: |
6567 : | |
6568 : | |
6569 : | Date Programmer Description |
6570 : | ====== ============ ================================================= |
6571 : | Jul 00 Abe Taaheri Original Programmer |
6572 : | |
6573 : | END_PROLOG |
6574 : -----------------------------------------------------------------------------*/
6575 : intn
6576 0 : GDrs2ll(int32 projcode, float64 projparm[],
6577 : int32 xdimsize, int32 ydimsize,
6578 : float64 upleft[], float64 lowright[],
6579 : int32 npnts, float64 r[], float64 s[],
6580 : float64 longitude[], float64 latitude[], int32 pixcen, int32 pixcnr)
6581 : {
6582 : intn i; /* Loop index */
6583 0 : intn status = 0; /* routine return status variable */
6584 :
6585 0 : int32 errorcode = 0; /* GCTP error code */
6586 : int32(*inv_trans[100]) (double, double, double*, double*); /* GCTP function pointer */
6587 :
6588 0 : float64 pixadjX = 0.0; /* Pixel adjustment (x) */
6589 0 : float64 pixadjY = 0.0; /* Pixel adjustment (y) */
6590 : float64 lonrad; /* Longitude in radians of point */
6591 : float64 latrad; /* Latitude in radians of point */
6592 : float64 xMtr; /* X value in meters from GCTP */
6593 : float64 yMtr; /* Y value in meters from GCTP */
6594 : float64 epsilon;
6595 : float64 beta;
6596 0 : float64 qp_cea = 0;
6597 0 : float64 kz_cea = 0;
6598 : float64 eccen, eccen_sq;
6599 : float64 phi1, sinphi1, cosphi1;
6600 : float64 scaleX, scaleY;
6601 :
6602 0 : int32 zonecode=0;
6603 :
6604 0 : int32 spherecode=0;
6605 : float64 lon[2],lat[2];
6606 : float64 xcor[2], ycor[2];
6607 : int32 nlatlon;
6608 :
6609 : /* If projection is BCEA define scale, r0 and s0 */
6610 0 : if (projcode == GCTP_BCEA)
6611 : {
6612 0 : eccen_sq = 1.0 - SQUARE(projparm[1]/projparm[0]);
6613 0 : eccen = sqrt(eccen_sq);
6614 0 : if(eccen < 0.00001)
6615 : {
6616 0 : qp_cea = 2.0;
6617 : }
6618 : else
6619 : {
6620 0 : qp_cea =
6621 0 : (1.0 - eccen_sq)*((1.0/(1.0 - eccen_sq))-(1.0/(2.0*eccen))*
6622 0 : log((1.0 - eccen)/(1.0 + eccen)));
6623 : }
6624 0 : phi1 = EHconvAng(projparm[5],HDFE_DMS_RAD);
6625 0 : cosphi1 = cos(phi1);
6626 0 : sinphi1 = sin(phi1);
6627 0 : kz_cea = cosphi1/(sqrt(1.0 - (eccen_sq*sinphi1*sinphi1)));
6628 : }
6629 :
6630 :
6631 :
6632 :
6633 : /* Compute adjustment of position within pixel */
6634 : /* ------------------------------------------- */
6635 0 : if (pixcen == HDFE_CENTER)
6636 : {
6637 : /* Pixel defined at center */
6638 : /* ----------------------- */
6639 0 : pixadjX = 0.5;
6640 0 : pixadjY = 0.5;
6641 : }
6642 : else
6643 : {
6644 0 : switch (pixcnr)
6645 : {
6646 0 : case HDFE_GD_UL:
6647 : {
6648 : /* Pixel defined at upper left corner */
6649 : /* ---------------------------------- */
6650 0 : pixadjX = 0.0;
6651 0 : pixadjY = 0.0;
6652 0 : break;
6653 : }
6654 :
6655 0 : case HDFE_GD_UR:
6656 : {
6657 : /* Pixel defined at upper right corner */
6658 : /* ----------------------------------- */
6659 0 : pixadjX = 1.0;
6660 0 : pixadjY = 0.0;
6661 0 : break;
6662 : }
6663 :
6664 0 : case HDFE_GD_LL:
6665 : {
6666 : /* Pixel defined at lower left corner */
6667 : /* ---------------------------------- */
6668 0 : pixadjX = 0.0;
6669 0 : pixadjY = 1.0;
6670 0 : break;
6671 : }
6672 :
6673 0 : case HDFE_GD_LR:
6674 : {
6675 : /* Pixel defined at lower right corner */
6676 : /* ----------------------------------- */
6677 0 : pixadjX = 1.0;
6678 0 : pixadjY = 1.0;
6679 0 : break;
6680 : }
6681 :
6682 : }
6683 0 : }
6684 :
6685 : /* If projection is BCEA call GCTP initialization routine */
6686 : /* ------------------------------------------------------ */
6687 0 : if (projcode == GCTP_BCEA)
6688 : {
6689 :
6690 0 : inv_init(projcode, 0, projparm, 0, NULL, NULL,
6691 : &errorcode, inv_trans);
6692 :
6693 : /* Report error if any */
6694 : /* ------------------- */
6695 0 : if (errorcode != 0)
6696 : {
6697 0 : status = -1;
6698 0 : HEpush(DFE_GENAPP, "GDrs2ll", __FILE__, __LINE__);
6699 0 : HEreport("GCTP Error: %d\n", errorcode);
6700 : }
6701 : else
6702 : {
6703 : /* For each point ... */
6704 : /* ------------------ */
6705 0 : for (i = 0; i < npnts; i++)
6706 : {
6707 : /* Convert from EASE grid's (r,s) to lon/lat (radians)
6708 : using GCTP */
6709 : /* --------------------------------------------------- */
6710 0 : nlatlon = 2;
6711 0 : lon[0] = upleft[0];
6712 0 : lon[1] = lowright[0];
6713 0 : lat[0] = upleft[1];
6714 0 : lat[1] = lowright[1];
6715 : status =
6716 0 : GDll2mm_cea(projcode,zonecode,spherecode,projparm,
6717 : xdimsize, ydimsize,
6718 : upleft, lowright, nlatlon,
6719 : lon, lat,
6720 : xcor, ycor, &scaleX, &scaleY);
6721 :
6722 0 : if (status == -1)
6723 : {
6724 0 : HEpush(DFE_GENAPP, "GDrs2ll", __FILE__, __LINE__);
6725 0 : return (status);
6726 : }
6727 :
6728 0 : xMtr = (r[i]/ scaleX + pixadjX - 0.5)* scaleX;
6729 0 : yMtr = - (s[i]/fabs(scaleY) + pixadjY - 0.5)* fabs(scaleY);
6730 :
6731 :
6732 : /* allow .5 cell tolerance in arcsin function
6733 : (used in bceainv function) so that grid
6734 : coordinates which are less than .5 cells
6735 : above 90.00N or below 90.00S are given lat of 90.00
6736 : */
6737 :
6738 0 : epsilon = 1 + 0.5 * (fabs(scaleY)/projparm[0]);
6739 0 : beta = 2.0 * (yMtr - projparm[7]) * kz_cea/(projparm[0] * qp_cea);
6740 :
6741 0 : if( fabs (beta) > epsilon)
6742 : {
6743 0 : status = -1;
6744 0 : HEpush(DFE_GENAPP, "GDrs2ll", __FILE__, __LINE__);
6745 0 : HEreport("GCTP Error: %s %s %s\n", "grid coordinates",
6746 : "are more than .5 cells",
6747 : "above 90.00N or below 90.00S. ");
6748 0 : return (status);
6749 : }
6750 0 : else if( beta <= -1)
6751 : {
6752 0 : errorcode = inv_trans[projcode] (xMtr, 0.0,
6753 : &lonrad, &latrad);
6754 0 : latrad = - M_PI/2;
6755 : }
6756 0 : else if( beta >= 1)
6757 : {
6758 0 : errorcode = inv_trans[projcode] (xMtr, 0.0,
6759 : &lonrad, &latrad);
6760 0 : latrad = M_PI/2;
6761 : }
6762 : else
6763 : {
6764 0 : errorcode = inv_trans[projcode] (xMtr, yMtr,
6765 : &lonrad, &latrad);
6766 : }
6767 :
6768 : /* Report error if any */
6769 : /* ------------------- */
6770 0 : if (errorcode != 0)
6771 : {
6772 0 : status = -1;
6773 0 : HEpush(DFE_GENAPP, "GDrs2ll", __FILE__, __LINE__);
6774 0 : HEreport("GCTP Error: %d\n", errorcode);
6775 0 : return (status);
6776 : }
6777 :
6778 : /* Convert from radians to decimal degrees */
6779 : /* --------------------------------------- */
6780 0 : longitude[i] = EHconvAng(lonrad, HDFE_RAD_DEG);
6781 0 : latitude[i] = EHconvAng(latrad, HDFE_RAD_DEG);
6782 : }
6783 : }
6784 : }
6785 :
6786 :
6787 :
6788 :
6789 0 : return (status);
6790 : }
6791 :
6792 :
6793 :
6794 : /*----------------------------------------------------------------------------|
6795 : | BEGIN_PROLOG |
6796 : | |
6797 : | FUNCTION: lamaxDxDtheta |
6798 : | |
6799 : | DESCRIPTION: Partial derivative along longitude line for Lambert Azimuthal |
6800 : | |
6801 : | |
6802 : | Return Value Type Units Description |
6803 : | ============ ====== ========= ===================================== |
6804 : | float64 Dx/D(theta) for LAMAZ projection |
6805 : | |
6806 : | INPUTS: |
6807 : | parms float64 Parameters defining partial derivative |
6808 : | |
6809 : | OUTPUTS: |
6810 : | None |
6811 : | |
6812 : | NOTES: |
6813 : | |
6814 : | |
6815 : | Date Programmer Description |
6816 : | ====== ============ ================================================= |
6817 : | Nov 96 Joel Gales Original Programmer |
6818 : | |
6819 : | END_PROLOG |
6820 : -----------------------------------------------------------------------------*/
6821 : static float64
6822 0 : lamazDxDtheta(float64 parms[])
6823 : {
6824 : float64 snTheta, sn2Theta, snTheta1, csTheta1, csLamda;
6825 :
6826 0 : snTheta = sin(EHconvAng(parms[0], HDFE_DEG_RAD));
6827 0 : sn2Theta = sin(2 * EHconvAng(parms[0], HDFE_DEG_RAD));
6828 0 : snTheta1 = sin(EHconvAng(parms[1], HDFE_DEG_RAD));
6829 0 : csTheta1 = cos(EHconvAng(parms[1], HDFE_DEG_RAD));
6830 0 : csLamda = cos(EHconvAng(parms[2], HDFE_DEG_RAD) -
6831 0 : EHconvAng(parms[3], HDFE_DEG_RAD));
6832 :
6833 0 : return (4 * snTheta +
6834 0 : (csTheta1 * csLamda * sn2Theta) +
6835 0 : (2 * snTheta1 * (1 + (snTheta * snTheta))));
6836 : }
6837 :
6838 :
6839 :
6840 :
6841 : /*----------------------------------------------------------------------------|
6842 : | BEGIN_PROLOG |
6843 : | |
6844 : | FUNCTION: lamaxDxDlamda |
6845 : | |
6846 : | DESCRIPTION: Partial derivative along latitude line for Lambert Azimuthal |
6847 : | |
6848 : | |
6849 : | Return Value Type Units Description |
6850 : | ============ ====== ========= ===================================== |
6851 : | float64 Dx/D(lamda) for LAMAZ projection |
6852 : | |
6853 : | INPUTS: |
6854 : | parms float64 Parameters defining partial derivative |
6855 : | |
6856 : | OUTPUTS: |
6857 : | None |
6858 : | |
6859 : | NOTES: |
6860 : | |
6861 : | |
6862 : | Date Programmer Description |
6863 : | ====== ============ ================================================= |
6864 : | Nov 96 Joel Gales Original Programmer |
6865 : | |
6866 : | END_PROLOG |
6867 : -----------------------------------------------------------------------------*/
6868 : static float64
6869 0 : lamazDxDlamda(float64 parms[])
6870 : {
6871 : float64 snTheta, csTheta, snTheta1, csTheta1, csLamda;
6872 : float64 cs, sn;
6873 :
6874 0 : snTheta = sin(EHconvAng(parms[2], HDFE_DEG_RAD));
6875 0 : csTheta = cos(EHconvAng(parms[2], HDFE_DEG_RAD));
6876 0 : snTheta1 = sin(EHconvAng(parms[1], HDFE_DEG_RAD));
6877 0 : csTheta1 = cos(EHconvAng(parms[1], HDFE_DEG_RAD));
6878 0 : csLamda = cos(EHconvAng(parms[0], HDFE_DEG_RAD) -
6879 0 : EHconvAng(parms[3], HDFE_DEG_RAD));
6880 :
6881 0 : cs = csTheta * csTheta1;
6882 0 : sn = snTheta * snTheta1;
6883 :
6884 0 : return (cs + (2 * (1 + sn) + (cs * csLamda)) * csLamda);
6885 : }
6886 :
6887 :
6888 :
6889 : /*----------------------------------------------------------------------------|
6890 : | BEGIN_PROLOG |
6891 : | |
6892 : | FUNCTION: lamaxDyDtheta |
6893 : | |
6894 : | DESCRIPTION: Partial derivative along longitude line for Lambert Azimuthal |
6895 : | |
6896 : | |
6897 : | Return Value Type Units Description |
6898 : | ============ ====== ========= ===================================== |
6899 : | float64 Dy/D(theta) for LAMAZ projection |
6900 : | |
6901 : | INPUTS: |
6902 : | parms float64 Parameters defining partial derivative |
6903 : | |
6904 : | OUTPUTS: |
6905 : | None |
6906 : | |
6907 : | NOTES: |
6908 : | |
6909 : | |
6910 : | Date Programmer Description |
6911 : | ====== ============ ================================================= |
6912 : | Nov 96 Joel Gales Original Programmer |
6913 : | |
6914 : | END_PROLOG |
6915 : -----------------------------------------------------------------------------*/
6916 : static float64
6917 0 : lamazDyDtheta(float64 parms[])
6918 : {
6919 : float64 snTheta, csTheta, snTheta1, csTheta1, csLamda;
6920 : float64 sn2, cs2, sndiff;
6921 :
6922 0 : snTheta = sin(EHconvAng(parms[0], HDFE_DEG_RAD));
6923 0 : csTheta = cos(EHconvAng(parms[0], HDFE_DEG_RAD));
6924 0 : snTheta1 = sin(EHconvAng(parms[1], HDFE_DEG_RAD));
6925 0 : csTheta1 = cos(EHconvAng(parms[1], HDFE_DEG_RAD));
6926 0 : csLamda = cos(EHconvAng(parms[2], HDFE_DEG_RAD) -
6927 0 : EHconvAng(parms[3], HDFE_DEG_RAD));
6928 :
6929 0 : sn2 = snTheta1 * snTheta;
6930 0 : cs2 = csTheta1 * csTheta;
6931 0 : sndiff = snTheta1 - snTheta;
6932 :
6933 0 : return (cs2 * (sn2 * (1 + (csLamda * csLamda)) + 2) +
6934 0 : csLamda * (2 * (1 + sn2 * sn2) - (sndiff * sndiff)));
6935 : }
6936 :
6937 :
6938 :
6939 : /*----------------------------------------------------------------------------|
6940 : | BEGIN_PROLOG |
6941 : | |
6942 : | FUNCTION: homDyDtheta |
6943 : | |
6944 : | DESCRIPTION: Partial derivative along longitude line for Oblique Mercator |
6945 : | |
6946 : | |
6947 : | Return Value Type Units Description |
6948 : | ============ ====== ========= ===================================== |
6949 : | float64 Dx/D(theta) for HOM projection |
6950 : | |
6951 : | INPUTS: |
6952 : | parms float64 Parameters defining partial derivative |
6953 : | |
6954 : | OUTPUTS: |
6955 : | None |
6956 : | |
6957 : | NOTES: |
6958 : | |
6959 : | |
6960 : | Date Programmer Description |
6961 : | ====== ============ ================================================= |
6962 : | Mar 97 Joel Gales Original Programmer |
6963 : | |
6964 : | END_PROLOG |
6965 : -----------------------------------------------------------------------------*/
6966 : static float64
6967 0 : homDyDtheta(float64 parms[])
6968 : {
6969 : float64 tnTheta, tnTheta1, snLamda;
6970 :
6971 0 : tnTheta = tan(EHconvAng(parms[0], HDFE_DEG_RAD));
6972 0 : tnTheta1 = tan(EHconvAng(parms[1], HDFE_DEG_RAD));
6973 0 : snLamda = cos(EHconvAng(parms[2], HDFE_DEG_RAD) -
6974 0 : EHconvAng(parms[3], HDFE_DEG_RAD));
6975 :
6976 0 : return (tnTheta * snLamda + tnTheta1);
6977 : }
6978 :
6979 :
6980 :
6981 :
6982 : /*----------------------------------------------------------------------------|
6983 : | BEGIN_PROLOG |
6984 : | |
6985 : | FUNCTION: GDtangentpnts |
6986 : | |
6987 : | DESCRIPTION: Finds tangent points along lon/lat lines |
6988 : | |
6989 : | |
6990 : | Return Value Type Units Description |
6991 : | ============ ====== ========= ===================================== |
6992 : | status intn return status (0) SUCCEED, (-1) FAIL |
6993 : | |
6994 : | INPUTS: |
6995 : | projcode int32 Projection code |
6996 : | projparm float64 Projection parameters |
6997 : | cornerlon float64 dec deg Longitude of opposite corners of box |
6998 : | cornerlat float64 dec deg Latitude of opposite corners of box |
6999 : | longitude float64 dec deg Longitude of points to check |
7000 : | latitude float64 dec deg Latitude of points to check |
7001 : | |
7002 : | |
7003 : | OUTPUTS: |
7004 : | npnts int32 Number of points to check in subset |
7005 : | |
7006 : | NOTES: |
7007 : | |
7008 : | |
7009 : | Date Programmer Description |
7010 : | ====== ============ ================================================= |
7011 : | Nov 96 Joel Gales Original Programmer |
7012 : | Mar 97 Joel Gales Add support for LAMCC, POLYC, TM |
7013 : | Aug 99 Abe Taaheri Add support for ALBERS, and MERCAT projections. |
7014 : | Also changed mistyped bisectParm[2] to |
7015 : | bisectParm[3] for HOM projection. |
7016 : | Jun 00 Abe Taaheri Added support for EASE grid |
7017 : | |
7018 : | END_PROLOG |
7019 : -----------------------------------------------------------------------------*/
7020 : static intn
7021 0 : GDtangentpnts(int32 projcode, float64 projparm[], float64 cornerlon[],
7022 : float64 cornerlat[], float64 longitude[], float64 latitude[],
7023 : int32 * npnts)
7024 : {
7025 : intn i; /* Loop index */
7026 0 : intn status = 0; /* routine return status variable */
7027 :
7028 : float64 lonrad; /* Longitude (radians) */
7029 : float64 latrad; /* Latitude (radians) */
7030 : float64 cs[4]; /* Cosine array */
7031 : float64 sn[4]; /* Sine array */
7032 : float64 csTest; /* Cosine test value */
7033 : float64 snTest; /* Sine test value */
7034 : float64 crs01; /* Cross product */
7035 : float64 crsTest[2]; /* Cross product array */
7036 : float64 longPol; /* Longitude beneath pole */
7037 : float64 minLat; /* Minimum latitude */
7038 : float64 bisectParm[4]; /* Bisection parameters */
7039 : float64 tanLat; /* Tangent latitude */
7040 : float64 tanLon; /* Tangent longitude */
7041 : float64 dotPrd; /* Dot product */
7042 : float64 centMerd; /* Central Meridian */
7043 : float64 orgLat; /* Latitude of origin */
7044 : float64 dpi; /* Double precision pi */
7045 :
7046 : #if 0
7047 : float64 lamazDxDtheta(); /* Lambert Azimuthal Dx/Dtheta */
7048 : float64 lamazDxDlamda(); /* Lambert Azimuthal Dx/Dlamda */
7049 : float64 lamazDyDtheta(); /* Lambert Azimuthal Dy/Dtheta */
7050 : float64 homDyDtheta(); /* Oblique Mercator Dy/Dtheta */
7051 : #endif
7052 :
7053 : /* Compute pi (double precision) */
7054 : /* ----------------------------- */
7055 0 : dpi = atan(1.0) * 4;
7056 :
7057 :
7058 0 : switch (projcode)
7059 : {
7060 0 : case GCTP_MERCAT:
7061 : {
7062 : /* No need for tangent points, since MERCAT projection
7063 : is rectangular */
7064 : }
7065 0 : break;
7066 0 : case GCTP_BCEA:
7067 : {
7068 : /* No need for tangent points, since BCEA projection
7069 : is rectangular */
7070 : }
7071 0 : break;
7072 0 : case GCTP_CEA:
7073 : {
7074 : /* No need for tangent points, since CEA projection
7075 : is rectangular */
7076 : }
7077 0 : break;
7078 :
7079 0 : case GCTP_PS:
7080 : {
7081 : /* Add "xy axis" points for Polar Stereographic if necessary */
7082 : /* --------------------------------------------------------- */
7083 :
7084 :
7085 : /* Get minimum of corner latitudes */
7086 : /* ------------------------------- */
7087 0 : minLat = (fabs(cornerlat[0]) <= fabs(cornerlat[1]))
7088 0 : ? cornerlat[0] : cornerlat[1];
7089 :
7090 :
7091 : /* Compute sine and cosine of corner longitudes */
7092 : /* -------------------------------------------- */
7093 0 : for (i = 0; i < 2; i++)
7094 : {
7095 0 : lonrad = EHconvAng(cornerlon[i], HDFE_DEG_RAD);
7096 0 : cs[i] = cos(lonrad);
7097 0 : sn[i] = sin(lonrad);
7098 : }
7099 :
7100 :
7101 : /* Compute cross product */
7102 : /* --------------------- */
7103 0 : crs01 = cs[0] * sn[1] - cs[1] * sn[0];
7104 :
7105 :
7106 : /* Convert longitude beneath pole from DMS to DEG */
7107 : /* ---------------------------------------------- */
7108 0 : longPol = EHconvAng(projparm[4], HDFE_DMS_RAD);
7109 :
7110 :
7111 :
7112 0 : for (i = 0; i < 4; i++)
7113 : {
7114 0 : csTest = cos(longPol);
7115 0 : snTest = sin(longPol);
7116 :
7117 0 : crsTest[0] = cs[0] * snTest - csTest * sn[0];
7118 0 : crsTest[1] = cs[1] * snTest - csTest * sn[1];
7119 :
7120 0 : if ((crs01 > 0 && crsTest[0] > 0 && crsTest[1] < 0) ||
7121 0 : (crs01 < 0 && crsTest[0] < 0 && crsTest[1] < 0) ||
7122 0 : (crs01 < 0 && crsTest[0] > 0 && crsTest[1] < 0) ||
7123 0 : (crs01 < 0 && crsTest[0] > 0 && crsTest[1] > 0))
7124 : {
7125 0 : longitude[*npnts] = EHconvAng(longPol, HDFE_RAD_DEG);
7126 0 : latitude[*npnts] = minLat;
7127 0 : (*npnts)++;
7128 : }
7129 0 : longPol += 0.5 * dpi;
7130 : }
7131 : }
7132 0 : break;
7133 :
7134 :
7135 0 : case GCTP_LAMAZ:
7136 : {
7137 0 : if ((int32) projparm[5] == +90000000 ||
7138 0 : (int32) projparm[5] == -90000000)
7139 : {
7140 : /* Add "xy axis" points for Polar Lambert Azimuthal */
7141 : /* ------------------------------------------------ */
7142 0 : minLat = (fabs(cornerlat[0]) <= fabs(cornerlat[1]))
7143 0 : ? cornerlat[0] : cornerlat[1];
7144 :
7145 0 : for (i = 0; i < 2; i++)
7146 : {
7147 0 : lonrad = EHconvAng(cornerlon[i], HDFE_DEG_RAD);
7148 0 : cs[i] = cos(lonrad);
7149 0 : sn[i] = sin(lonrad);
7150 : }
7151 0 : crs01 = cs[0] * sn[1] - cs[1] * sn[0];
7152 :
7153 0 : longPol = EHconvAng(projparm[4], HDFE_DMS_RAD);
7154 0 : for (i = 0; i < 4; i++)
7155 : {
7156 0 : csTest = cos(longPol);
7157 0 : snTest = sin(longPol);
7158 :
7159 0 : crsTest[0] = cs[0] * snTest - csTest * sn[0];
7160 0 : crsTest[1] = cs[1] * snTest - csTest * sn[1];
7161 :
7162 0 : if ((crs01 > 0 && crsTest[0] > 0 && crsTest[1] < 0) ||
7163 0 : (crs01 < 0 && crsTest[0] < 0 && crsTest[1] < 0) ||
7164 0 : (crs01 < 0 && crsTest[0] > 0 && crsTest[1] < 0) ||
7165 0 : (crs01 < 0 && crsTest[0] > 0 && crsTest[1] > 0))
7166 : {
7167 0 : longitude[*npnts] = EHconvAng(longPol, HDFE_RAD_DEG);
7168 0 : latitude[*npnts] = minLat;
7169 0 : (*npnts)++;
7170 : }
7171 0 : longPol += 0.5 * dpi;
7172 : }
7173 : }
7174 0 : else if ((int32) projparm[5] == 0)
7175 : {
7176 : /* Add "Equator" points for Equatorial Lambert Azimuthal */
7177 : /* ----------------------------------------------------- */
7178 0 : if (cornerlat[0] * cornerlat[1] < 0)
7179 : {
7180 0 : longitude[4] = cornerlon[0];
7181 0 : latitude[4] = 0;
7182 :
7183 0 : longitude[5] = cornerlon[1];
7184 0 : latitude[5] = 0;
7185 :
7186 0 : *npnts = 6;
7187 : }
7188 : }
7189 : else
7190 : {
7191 : /* Add tangent points for Oblique Lambert Azimuthal */
7192 : /* ------------------------------------------------ */
7193 0 : bisectParm[0] = EHconvAng(projparm[5], HDFE_DMS_DEG);
7194 0 : bisectParm[2] = EHconvAng(projparm[4], HDFE_DMS_DEG);
7195 :
7196 :
7197 : /* Tangent to y-axis along longitude */
7198 : /* --------------------------------- */
7199 0 : for (i = 0; i < 2; i++)
7200 : {
7201 0 : bisectParm[1] = cornerlon[i];
7202 :
7203 0 : if (EHbisect(lamazDxDtheta, bisectParm, 3,
7204 0 : cornerlat[0], cornerlat[1],
7205 : 0.0001, &tanLat) == 0)
7206 : {
7207 0 : longitude[*npnts] = cornerlon[i];
7208 0 : latitude[*npnts] = tanLat;
7209 0 : (*npnts)++;
7210 : }
7211 : }
7212 :
7213 : /* Tangent to y-axis along latitude */
7214 : /* -------------------------------- */
7215 0 : for (i = 0; i < 2; i++)
7216 : {
7217 0 : bisectParm[1] = cornerlat[i];
7218 :
7219 0 : if (EHbisect(lamazDxDlamda, bisectParm, 3,
7220 0 : cornerlon[0], cornerlon[1],
7221 : 0.0001, &tanLon) == 0)
7222 : {
7223 0 : longitude[*npnts] = tanLon;
7224 0 : latitude[*npnts] = cornerlat[i];
7225 0 : (*npnts)++;
7226 : }
7227 : }
7228 :
7229 :
7230 : /* Tangent to x-axis along longitude */
7231 : /* --------------------------------- */
7232 0 : for (i = 0; i < 2; i++)
7233 : {
7234 0 : bisectParm[1] = cornerlon[i];
7235 :
7236 0 : if (EHbisect(lamazDyDtheta, bisectParm, 3,
7237 0 : cornerlat[0], cornerlat[1],
7238 : 0.0001, &tanLat) == 0)
7239 : {
7240 0 : longitude[*npnts] = cornerlon[i];
7241 0 : latitude[*npnts] = tanLat;
7242 0 : (*npnts)++;
7243 : }
7244 : }
7245 :
7246 : /* Tangent to x-axis along latitude */
7247 : /* -------------------------------- */
7248 0 : for (i = 0; i < 2; i++)
7249 : {
7250 0 : lonrad = EHconvAng(cornerlon[i], HDFE_DEG_RAD);
7251 0 : cs[i] = cos(lonrad);
7252 0 : sn[i] = sin(lonrad);
7253 : }
7254 0 : crs01 = cs[0] * sn[1] - cs[1] * sn[0];
7255 :
7256 0 : longPol = EHconvAng(projparm[4], HDFE_DMS_RAD);
7257 0 : for (i = 0; i < 2; i++)
7258 : {
7259 0 : csTest = cos(longPol);
7260 0 : snTest = sin(longPol);
7261 :
7262 0 : crsTest[0] = cs[0] * snTest - csTest * sn[0];
7263 0 : crsTest[1] = cs[1] * snTest - csTest * sn[1];
7264 :
7265 0 : if ((crs01 > 0 && crsTest[0] > 0 && crsTest[1] < 0) ||
7266 0 : (crs01 < 0 && crsTest[0] < 0 && crsTest[1] < 0) ||
7267 0 : (crs01 < 0 && crsTest[0] > 0 && crsTest[1] < 0) ||
7268 0 : (crs01 < 0 && crsTest[0] > 0 && crsTest[1] > 0))
7269 : {
7270 0 : longitude[*npnts] = EHconvAng(longPol, HDFE_RAD_DEG);
7271 0 : latitude[*npnts] = cornerlat[0];
7272 0 : (*npnts)++;
7273 0 : longitude[*npnts] = EHconvAng(longPol, HDFE_RAD_DEG);
7274 0 : latitude[*npnts] = cornerlat[1];
7275 0 : (*npnts)++;
7276 : }
7277 0 : longPol += dpi;
7278 : }
7279 : }
7280 : }
7281 0 : break;
7282 :
7283 :
7284 0 : case GCTP_GOOD:
7285 : {
7286 : /* Add "Equator" points for Goode Homolosine if necessary */
7287 : /* ------------------------------------------------------ */
7288 0 : if (cornerlat[0] * cornerlat[1] < 0)
7289 : {
7290 0 : longitude[4] = cornerlon[0];
7291 0 : latitude[4] = 0;
7292 :
7293 0 : longitude[5] = cornerlon[1];
7294 0 : latitude[5] = 0;
7295 :
7296 0 : *npnts = 6;
7297 : }
7298 : }
7299 0 : break;
7300 :
7301 :
7302 0 : case GCTP_LAMCC:
7303 : {
7304 : /* Compute sine and cosine of corner longitudes */
7305 : /* -------------------------------------------- */
7306 0 : for (i = 0; i < 2; i++)
7307 : {
7308 0 : lonrad = EHconvAng(cornerlon[i], HDFE_DEG_RAD);
7309 0 : cs[i] = cos(lonrad);
7310 0 : sn[i] = sin(lonrad);
7311 : }
7312 :
7313 :
7314 : /* Compute dot product */
7315 : /* ------------------- */
7316 0 : dotPrd = cs[0] * cs[1] + sn[0] * sn[1];
7317 :
7318 :
7319 : /* Convert central meridian (DMS to DEG) & compute sin & cos */
7320 : /* --------------------------------------------------------- */
7321 0 : centMerd = EHconvAng(projparm[4], HDFE_DMS_DEG);
7322 0 : lonrad = EHconvAng(centMerd, HDFE_DEG_RAD);
7323 0 : cs[1] = cos(lonrad);
7324 0 : sn[1] = sin(lonrad);
7325 :
7326 :
7327 : /* If box brackets central meridian ... */
7328 : /* ------------------------------------ */
7329 0 : if (cs[0] * cs[1] + sn[0] * sn[1] > dotPrd)
7330 : {
7331 0 : latitude[4] = cornerlat[0];
7332 0 : longitude[4] = centMerd;
7333 :
7334 0 : latitude[5] = cornerlat[1];
7335 0 : longitude[5] = centMerd;
7336 :
7337 0 : *npnts = 6;
7338 : }
7339 : }
7340 0 : break;
7341 :
7342 :
7343 0 : case GCTP_ALBERS:
7344 : {
7345 : /* Compute sine and cosine of corner longitudes */
7346 : /* -------------------------------------------- */
7347 0 : for (i = 0; i < 2; i++)
7348 : {
7349 0 : lonrad = EHconvAng(cornerlon[i], HDFE_DEG_RAD);
7350 0 : cs[i] = cos(lonrad);
7351 0 : sn[i] = sin(lonrad);
7352 : }
7353 :
7354 :
7355 : /* Compute dot product */
7356 : /* ------------------- */
7357 0 : dotPrd = cs[0] * cs[1] + sn[0] * sn[1];
7358 :
7359 :
7360 : /* Convert central meridian (DMS to DEG) & compute sin & cos */
7361 : /* --------------------------------------------------------- */
7362 0 : centMerd = EHconvAng(projparm[4], HDFE_DMS_DEG);
7363 0 : lonrad = EHconvAng(centMerd, HDFE_DEG_RAD);
7364 0 : cs[1] = cos(lonrad);
7365 0 : sn[1] = sin(lonrad);
7366 :
7367 :
7368 : /* If box brackets central meridian ... */
7369 : /* ------------------------------------ */
7370 0 : if (cs[0] * cs[1] + sn[0] * sn[1] > dotPrd)
7371 : {
7372 0 : latitude[4] = cornerlat[0];
7373 0 : longitude[4] = centMerd;
7374 :
7375 0 : latitude[5] = cornerlat[1];
7376 0 : longitude[5] = centMerd;
7377 :
7378 0 : *npnts = 6;
7379 : }
7380 : }
7381 0 : break;
7382 :
7383 :
7384 0 : case GCTP_POLYC:
7385 : {
7386 : /* Compute sine and cosine of corner longitudes */
7387 : /* -------------------------------------------- */
7388 0 : for (i = 0; i < 2; i++)
7389 : {
7390 0 : lonrad = EHconvAng(cornerlon[i], HDFE_DEG_RAD);
7391 0 : cs[i] = cos(lonrad);
7392 0 : sn[i] = sin(lonrad);
7393 : }
7394 :
7395 :
7396 : /* Compute dot product */
7397 : /* ------------------- */
7398 0 : dotPrd = cs[0] * cs[1] + sn[0] * sn[1];
7399 :
7400 :
7401 : /* Convert central meridian (DMS to DEG) & compute sin & cos */
7402 : /* --------------------------------------------------------- */
7403 0 : centMerd = EHconvAng(projparm[4], HDFE_DMS_DEG);
7404 0 : lonrad = EHconvAng(centMerd, HDFE_DEG_RAD);
7405 0 : cs[1] = cos(lonrad);
7406 0 : sn[1] = sin(lonrad);
7407 :
7408 :
7409 : /* If box brackets central meridian ... */
7410 : /* ------------------------------------ */
7411 0 : if (cs[0] * cs[1] + sn[0] * sn[1] > dotPrd)
7412 : {
7413 0 : latitude[4] = cornerlat[0];
7414 0 : longitude[4] = centMerd;
7415 :
7416 0 : latitude[5] = cornerlat[1];
7417 0 : longitude[5] = centMerd;
7418 :
7419 0 : *npnts = 6;
7420 : }
7421 : }
7422 0 : break;
7423 :
7424 :
7425 0 : case GCTP_TM:
7426 : {
7427 : /* Compute sine and cosine of corner longitudes */
7428 : /* -------------------------------------------- */
7429 0 : for (i = 0; i < 2; i++)
7430 : {
7431 0 : lonrad = EHconvAng(cornerlon[i], HDFE_DEG_RAD);
7432 0 : cs[i] = cos(lonrad);
7433 0 : sn[i] = sin(lonrad);
7434 : }
7435 :
7436 :
7437 : /* Compute dot product */
7438 : /* ------------------- */
7439 0 : dotPrd = cs[0] * cs[1] + sn[0] * sn[1];
7440 :
7441 :
7442 0 : for (i = -1; i <= 1; i++)
7443 : {
7444 0 : centMerd = EHconvAng(projparm[4], HDFE_DMS_DEG);
7445 0 : lonrad = EHconvAng(centMerd + 90 * i, HDFE_DEG_RAD);
7446 0 : csTest = cos(lonrad);
7447 0 : snTest = sin(lonrad);
7448 :
7449 :
7450 : /* If box brackets meridian ... */
7451 : /* ---------------------------- */
7452 0 : if (csTest * cs[1] + snTest * sn[1] > dotPrd)
7453 : {
7454 0 : latitude[*npnts] = cornerlat[0];
7455 0 : longitude[*npnts] = centMerd;
7456 0 : (*npnts)++;
7457 :
7458 0 : latitude[*npnts] = cornerlat[1];
7459 0 : longitude[*npnts] = centMerd;
7460 0 : (*npnts)++;
7461 : }
7462 : }
7463 :
7464 :
7465 :
7466 : /* Compute sine and cosine of corner latitudes */
7467 : /* ------------------------------------------- */
7468 0 : for (i = 0; i < 2; i++)
7469 : {
7470 0 : latrad = EHconvAng(cornerlat[i], HDFE_DEG_RAD);
7471 0 : cs[i] = cos(latrad);
7472 0 : sn[i] = sin(latrad);
7473 : }
7474 :
7475 :
7476 : /* Compute dot product */
7477 : /* ------------------- */
7478 0 : dotPrd = cs[0] * cs[1] + sn[0] * sn[1];
7479 :
7480 :
7481 : /* Convert origin latitude (DMS to DEG) & compute sin & cos */
7482 : /* -------------------------------------------------------- */
7483 0 : orgLat = EHconvAng(projparm[5], HDFE_DMS_DEG);
7484 0 : latrad = EHconvAng(orgLat, HDFE_DEG_RAD);
7485 0 : cs[1] = cos(latrad);
7486 0 : sn[1] = sin(latrad);
7487 :
7488 :
7489 : /* If box brackets origin latitude ... */
7490 : /* ----------------------------------- */
7491 0 : if (cs[0] * cs[1] + sn[0] * sn[1] > dotPrd)
7492 : {
7493 0 : latitude[*npnts] = orgLat;
7494 0 : longitude[*npnts] = cornerlon[0];
7495 0 : (*npnts)++;
7496 :
7497 0 : latitude[*npnts] = orgLat;
7498 0 : longitude[*npnts] = cornerlon[1];
7499 0 : (*npnts)++;
7500 : }
7501 : }
7502 0 : break;
7503 :
7504 :
7505 0 : case GCTP_HOM:
7506 : {
7507 : /* Tangent to y-axis along longitude */
7508 : /* --------------------------------- */
7509 0 : if (projparm[12] == 0)
7510 : {
7511 0 : cs[0] = cos(EHconvAng(projparm[8], HDFE_DMS_RAD));
7512 0 : sn[0] = sin(EHconvAng(projparm[8], HDFE_DMS_RAD));
7513 0 : cs[1] = cos(EHconvAng(projparm[9], HDFE_DMS_RAD));
7514 0 : sn[1] = sin(EHconvAng(projparm[9], HDFE_DMS_RAD));
7515 0 : cs[2] = cos(EHconvAng(projparm[10], HDFE_DMS_RAD));
7516 0 : sn[2] = sin(EHconvAng(projparm[10], HDFE_DMS_RAD));
7517 0 : cs[3] = cos(EHconvAng(projparm[11], HDFE_DMS_RAD));
7518 0 : sn[3] = sin(EHconvAng(projparm[11], HDFE_DMS_RAD));
7519 :
7520 0 : bisectParm[3] = atan2(
7521 0 : (cs[1] * sn[3] * cs[0] - sn[1] * cs[3] * cs[2]),
7522 0 : (sn[1] * cs[3] * sn[2] - cs[1] * sn[3] * sn[0]));
7523 0 : bisectParm[0] = atan(
7524 0 : (sin(bisectParm[3]) * sn[0] - cos(bisectParm[3]) * cs[0]) /
7525 0 : (sn[1] / cs[1]));
7526 0 : bisectParm[2] = bisectParm[3] + 0.5 * dpi;
7527 : }
7528 : else
7529 : {
7530 0 : cs[0] = cos(EHconvAng(projparm[3], HDFE_DMS_RAD));
7531 0 : sn[0] = sin(EHconvAng(projparm[3], HDFE_DMS_RAD));
7532 0 : cs[1] = cos(EHconvAng(projparm[4], HDFE_DMS_RAD));
7533 0 : sn[1] = sin(EHconvAng(projparm[4], HDFE_DMS_RAD));
7534 :
7535 0 : bisectParm[0] = asin(cs[1] * sn[0]);
7536 0 : bisectParm[2] = atan2(-cs[0], (-sn[1] * sn[0])) + 0.5 * dpi;
7537 : }
7538 :
7539 0 : for (i = 0; i < 2; i++)
7540 : {
7541 0 : bisectParm[1] = cornerlon[i];
7542 :
7543 0 : if (EHbisect(homDyDtheta, bisectParm, 3,
7544 0 : cornerlat[0], cornerlat[1],
7545 : 0.0001, &tanLat) == 0)
7546 : {
7547 0 : longitude[*npnts] = cornerlon[i];
7548 0 : latitude[*npnts] = tanLat;
7549 0 : (*npnts)++;
7550 : }
7551 : }
7552 :
7553 : }
7554 0 : break;
7555 : }
7556 :
7557 :
7558 0 : return (status);
7559 : }
7560 :
7561 :
7562 :
7563 : /*----------------------------------------------------------------------------|
7564 : | BEGIN_PROLOG |
7565 : | |
7566 : | FUNCTION: GDdefboxregion |
7567 : | |
7568 : | DESCRIPTION: Defines region for subsetting in a grid. |
7569 : | |
7570 : | |
7571 : | Return Value Type Units Description |
7572 : | ============ ====== ========= ===================================== |
7573 : | regionID int32 Region ID |
7574 : | |
7575 : | INPUTS: |
7576 : | gridID int32 Grid structure ID |
7577 : | cornerlon float64 dec deg Longitude of opposite corners of box |
7578 : | cornerlat float64 dec deg Latitude of opposite corners of box |
7579 : | |
7580 : | |
7581 : | OUTPUTS: |
7582 : | None |
7583 : | |
7584 : | NOTES: |
7585 : | |
7586 : | |
7587 : | Date Programmer Description |
7588 : | ====== ============ ================================================= |
7589 : | Jun 96 Joel Gales Original Programmer |
7590 : | Oct 96 Joel Gales "Clamp" subset region around grid |
7591 : | Oct 96 Joel Gales Fix "outside region" check |
7592 : | Nov 96 Joel Gales Add check for "tangent" points (GDtangentpnts) |
7593 : | Dec 96 Joel Gales Trap if no projection code defined |
7594 : | Dec 96 Joel Gales Add multiple vertical subsetting capability |
7595 : | Mar 99 David Wynne Fix for NCR 21195, allow subsetting of MISR SOM |
7596 : | data sets |
7597 : | Jun 00 Abe Taaheri Added support for EASE grid |
7598 : | |
7599 : | END_PROLOG |
7600 : -----------------------------------------------------------------------------*/
7601 : int32
7602 0 : GDdefboxregion(int32 gridID, float64 cornerlon[], float64 cornerlat[])
7603 : {
7604 : intn i; /* Loop index */
7605 : intn j; /* Loop index */
7606 : intn k; /* Loop index */
7607 : intn n; /* Loop index */
7608 0 : intn status = 0; /* routine return status variable */
7609 :
7610 : int32 fid; /* HDF-EOS file ID */
7611 : int32 sdInterfaceID; /* HDF SDS interface ID */
7612 : int32 gdVgrpID; /* Grid root Vgroup ID */
7613 0 : int32 regionID = -1; /* Region ID */
7614 : int32 xdimsize; /* XDim size */
7615 : int32 ydimsize; /* YDim size */
7616 : int32 projcode; /* Projection code */
7617 : int32 zonecode; /* Zone code */
7618 : int32 spherecode; /* Sphere code */
7619 : int32 row[32]; /* Row array */
7620 : int32 col[32]; /* Column array */
7621 0 : int32 minCol = 0; /* Minimum column value */
7622 0 : int32 minRow = 0; /* Minimum row value */
7623 0 : int32 maxCol = 0; /* Maximum column value */
7624 0 : int32 maxRow = 0; /* Maximum row value */
7625 : int32 npnts; /* Number of boundary
7626 : (edge & tangent) pnts */
7627 :
7628 : float64 longitude[32]; /* Longitude array */
7629 : float64 latitude[32]; /* Latitude array */
7630 : float64 upleftpt[2]; /* Upper left pt coordinates */
7631 : float64 lowrightpt[2]; /* Lower right pt coordinates */
7632 : float64 somupleftpt[2]; /* temporary Upper left pt coordinates
7633 : for SOM projection */
7634 : float64 somlowrightpt[2]; /* temporary Lower right pt
7635 : coordinates for SOM projection */
7636 : float64 projparm[16]; /* Projection parameters */
7637 : float64 xscale; /* X scale */
7638 : float64 yscale; /* Y scale */
7639 : float64 lonrad0; /* Longitude of upper left point
7640 : (radians) */
7641 : float64 latrad0; /* Latitude of upper left point (radians) */
7642 : float64 lonrad2; /* Longitude of point (radians) */
7643 : float64 latrad2; /* Latitude of point (radians) */
7644 :
7645 : /* Used for SOM projection */
7646 : char *utlbuf;
7647 : char *gridname;
7648 0 : int32 blockindexstart = -1;
7649 0 : int32 blockindexstop = -1;
7650 : float32 offset[180];
7651 : float64 templeftpt[2];
7652 : float64 temprightpt[2];
7653 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
7654 : float64 xmtr[2], ymtr[2];
7655 : float64 lon[2],lat[2];
7656 : float64 xcor[2], ycor[2];
7657 : int32 nlatlon;
7658 : float64 upleftpt_m[2];
7659 :
7660 :
7661 0 : utlbuf = (char *)calloc(128, sizeof(char));
7662 0 : if(utlbuf == NULL)
7663 : {
7664 0 : HEpush(DFE_NOSPACE,"GDdefboxregion", __FILE__, __LINE__);
7665 0 : return(-1);
7666 : }
7667 0 : gridname = (char *)calloc(128, sizeof(char));
7668 0 : if(gridname == NULL)
7669 : {
7670 0 : HEpush(DFE_NOSPACE,"GDdefboxregion", __FILE__, __LINE__);
7671 0 : free(utlbuf);
7672 0 : return(-1);
7673 : }
7674 :
7675 : /* Check for valid grid ID */
7676 : /* ----------------------- */
7677 0 : status = GDchkgdid(gridID, "GDdefboxregion",
7678 : &fid, &sdInterfaceID, &gdVgrpID);
7679 :
7680 :
7681 0 : if (status == 0)
7682 : {
7683 : /* Get grid info */
7684 : /* ------------- */
7685 0 : status = GDgridinfo(gridID, &xdimsize, &ydimsize,
7686 : upleftpt, lowrightpt);
7687 :
7688 :
7689 : /* If error then bail */
7690 : /* ------------------ */
7691 0 : if (status != 0)
7692 : {
7693 0 : regionID = -1;
7694 0 : free(utlbuf);
7695 0 : free(gridname);
7696 0 : return (regionID);
7697 : }
7698 :
7699 :
7700 : /* Get proj info */
7701 : /* ------------- */
7702 0 : status = GDprojinfo(gridID, &projcode, &zonecode,
7703 : &spherecode, projparm);
7704 :
7705 :
7706 : /* If no projection code defined then bail */
7707 : /* --------------------------------------- */
7708 0 : if (projcode == -1)
7709 : {
7710 0 : regionID = -1;
7711 0 : free(utlbuf);
7712 0 : free(gridname);
7713 0 : return (regionID);
7714 : }
7715 :
7716 :
7717 : /* Get default values for upleft and lowright if necessary */
7718 : /* ------------------------------------------------------- */
7719 0 : if (upleftpt[0] == 0 && upleftpt[1] == 0 &&
7720 0 : lowrightpt[0] == 0 && lowrightpt[1] == 0)
7721 : {
7722 0 : status = GDgetdefaults(projcode, zonecode, projparm, spherecode,
7723 : upleftpt, lowrightpt);
7724 :
7725 : /* If error then bail */
7726 : /* ------------------ */
7727 0 : if (status != 0)
7728 : {
7729 0 : regionID = -1;
7730 0 : free(utlbuf);
7731 0 : free(gridname);
7732 0 : return (regionID);
7733 : }
7734 : }
7735 :
7736 :
7737 :
7738 : /* Fill-up longitude and latitude arrays */
7739 : /* ------------------------------------- */
7740 0 : longitude[0] = cornerlon[0];
7741 0 : latitude[0] = cornerlat[0];
7742 :
7743 0 : longitude[1] = cornerlon[0];
7744 0 : latitude[1] = cornerlat[1];
7745 :
7746 0 : longitude[2] = cornerlon[1];
7747 0 : latitude[2] = cornerlat[0];
7748 :
7749 0 : longitude[3] = cornerlon[1];
7750 0 : latitude[3] = cornerlat[1];
7751 :
7752 0 : npnts = 4;
7753 :
7754 :
7755 : /* Find additional tangent points from GDtangentpnts */
7756 : /* ------------------------------------------------- */
7757 0 : status = GDtangentpnts(projcode, projparm, cornerlon, cornerlat,
7758 : longitude, latitude, &npnts);
7759 :
7760 : /* If SOM projection with projparm[11] non-zero ... */
7761 0 : if (projcode == GCTP_SOM && projparm[11] != 0)
7762 : {
7763 0 : Vgetname(GDXGrid[gridID % idOffset].IDTable, gridname);
7764 0 : snprintf(utlbuf, 128, "%s%s", "_BLKSOM:", gridname);
7765 0 : status = GDreadattr(gridID, utlbuf, offset);
7766 :
7767 0 : somupleftpt[0] = upleftpt[0];
7768 0 : somupleftpt[1] = upleftpt[1];
7769 0 : somlowrightpt[0]= lowrightpt[0];
7770 0 : somlowrightpt[1] = lowrightpt[1];
7771 :
7772 0 : k = 0;
7773 0 : n = 2;
7774 :
7775 0 : for (j = 0; j <= projparm[11] - 1; j++)
7776 : {
7777 :
7778 : /* Convert from lon/lat to row/col */
7779 : /* ------------------------------- */
7780 0 : status = GDll2ij(projcode, zonecode, projparm, spherecode,
7781 : xdimsize, ydimsize, somupleftpt, somlowrightpt,
7782 : npnts, longitude, latitude, row, col, NULL, NULL);
7783 :
7784 :
7785 : /* Find min/max values for row & col */
7786 : /* --------------------------------- */
7787 0 : minCol = col[0];
7788 0 : minRow = row[0];
7789 0 : maxCol = col[0];
7790 0 : maxRow = row[0];
7791 0 : for (i = 1; i < npnts; i++)
7792 : {
7793 0 : if (col[i] < minCol)
7794 : {
7795 0 : minCol = col[i];
7796 : }
7797 :
7798 0 : if (col[i] > maxCol)
7799 : {
7800 0 : maxCol = col[i];
7801 : }
7802 :
7803 0 : if (row[i] < minRow)
7804 : {
7805 0 : minRow = row[i];
7806 : }
7807 :
7808 0 : if (row[i] > maxRow)
7809 : {
7810 0 : maxRow = row[i];
7811 : }
7812 : }
7813 :
7814 :
7815 :
7816 : /* "Clamp" if outside Grid */
7817 : /* ----------------------- */
7818 0 : minCol = (minCol < 0) ? 0 : minCol;
7819 0 : minRow = (minRow < 0) ? 0 : minRow;
7820 :
7821 0 : maxCol = (maxCol >= xdimsize) ? xdimsize - 1 : maxCol;
7822 0 : maxRow = (maxRow >= ydimsize) ? ydimsize - 1 : maxRow;
7823 :
7824 :
7825 : /* Check whether subset region is outside grid region */
7826 : /* -------------------------------------------------- */
7827 0 : if (minCol >= xdimsize || minRow >= ydimsize ||
7828 0 : maxCol < 0 || maxRow < 0)
7829 : {
7830 0 : if ( blockindexstart == -1 && (projparm[11]) == j)
7831 : {
7832 0 : status = -1;
7833 0 : HEpush(DFE_GENAPP, "GDdefboxregion", __FILE__, __LINE__);
7834 0 : HEreport("Subset Region outside of Grid Region\n");
7835 0 : regionID = -1;
7836 : }
7837 : }
7838 : else
7839 : {
7840 0 : if (k == 0)
7841 : {
7842 0 : blockindexstart = j;
7843 0 : blockindexstop = j;
7844 0 : k = 1;
7845 : }
7846 : else
7847 : {
7848 0 : blockindexstop = j;
7849 : }
7850 : }
7851 :
7852 : // E. Rouault: FIXME: was really abs(int) indented here ? Forcing the cast to int to please compilers
7853 0 : templeftpt[0] = upleftpt[0] + ((offset[j]/xdimsize)*abs((int)(upleftpt[0] - lowrightpt[0]))) + abs((int)(upleftpt[0] - lowrightpt[0]))*(n-1);
7854 0 : templeftpt[1] = upleftpt[1] + ((lowrightpt[1] - upleftpt[1]))*(n-1);
7855 :
7856 0 : temprightpt[0] = lowrightpt[0] + ((offset[j]/xdimsize)*abs((int)(lowrightpt[0] - upleftpt[0]))) + abs((int)(lowrightpt[0] - upleftpt[0]))*(n-1);
7857 0 : temprightpt[1] = lowrightpt[1] + ((upleftpt[1] - lowrightpt[1]))*(n-1);
7858 :
7859 0 : somupleftpt[0] = templeftpt[0];
7860 0 : somupleftpt[1] = templeftpt[1];
7861 :
7862 0 : somlowrightpt[0] = temprightpt[0];
7863 0 : somlowrightpt[1] = temprightpt[1];
7864 0 : n++;
7865 : }
7866 : }
7867 : else
7868 : {
7869 :
7870 : /* Convert from lon/lat to row/col */
7871 : /* ------------------------------- */
7872 :
7873 0 : status = GDll2ij(projcode, zonecode, projparm, spherecode,
7874 : xdimsize, ydimsize, upleftpt, lowrightpt,
7875 : npnts, longitude, latitude, row, col, NULL, NULL);
7876 :
7877 : /* Find min/max values for row & col */
7878 : /* --------------------------------- */
7879 0 : minCol = col[0];
7880 0 : minRow = row[0];
7881 0 : maxCol = col[0];
7882 0 : maxRow = row[0];
7883 0 : for (i = 1; i < npnts; i++)
7884 : {
7885 0 : if (col[i] < minCol)
7886 : {
7887 0 : minCol = col[i];
7888 : }
7889 :
7890 0 : if (col[i] > maxCol)
7891 : {
7892 0 : maxCol = col[i];
7893 : }
7894 :
7895 0 : if (row[i] < minRow)
7896 : {
7897 0 : minRow = row[i];
7898 : }
7899 :
7900 0 : if (row[i] > maxRow)
7901 : {
7902 0 : maxRow = row[i];
7903 : }
7904 : }
7905 :
7906 :
7907 :
7908 : /* "Clamp" if outside Grid */
7909 : /* ----------------------- */
7910 0 : minCol = (minCol < 0) ? 0 : minCol;
7911 0 : minRow = (minRow < 0) ? 0 : minRow;
7912 :
7913 0 : maxCol = (maxCol >= xdimsize) ? xdimsize - 1 : maxCol;
7914 0 : maxRow = (maxRow >= ydimsize) ? ydimsize - 1 : maxRow;
7915 :
7916 :
7917 : /* Check whether subset region is outside grid region */
7918 : /* -------------------------------------------------- */
7919 0 : if (minCol >= xdimsize || minRow >= ydimsize || maxCol < 0 || maxRow < 0)
7920 : {
7921 0 : status = -1;
7922 0 : HEpush(DFE_GENAPP, "GDdefboxregion", __FILE__, __LINE__);
7923 0 : HEreport("Subset Region outside of Grid Region\n");
7924 0 : regionID = -1;
7925 :
7926 : }
7927 : }
7928 0 : if (status == 0)
7929 : {
7930 : /* Store grid region info */
7931 : /* ---------------------- */
7932 0 : for (i = 0; i < NGRIDREGN; i++)
7933 : {
7934 : /* Find first empty grid region */
7935 : /* ---------------------------- */
7936 0 : if (GDXRegion[i] == 0)
7937 : {
7938 : /* Allocate space for grid region entry */
7939 : /* ------------------------------------ */
7940 0 : GDXRegion[i] = (struct gridRegion *)
7941 0 : calloc(1, sizeof(struct gridRegion));
7942 0 : if(GDXRegion[i] == NULL)
7943 : {
7944 0 : HEpush(DFE_NOSPACE,"GDdefboxregion", __FILE__, __LINE__);
7945 0 : free(utlbuf);
7946 0 : free(gridname);
7947 0 : return(-1);
7948 : }
7949 :
7950 :
7951 : /* Store file and grid ID */
7952 : /* ---------------------- */
7953 0 : GDXRegion[i]->fid = fid;
7954 0 : GDXRegion[i]->gridID = gridID;
7955 :
7956 :
7957 : /* Initialize vertical subset entries to -1 */
7958 : /* ---------------------------------------- */
7959 0 : for (j = 0; j < 8; j++)
7960 : {
7961 0 : GDXRegion[i]->StartVertical[j] = -1;
7962 0 : GDXRegion[i]->StopVertical[j] = -1;
7963 : }
7964 :
7965 :
7966 : /* Store start & count along x & y */
7967 : /* ------------------------------- */
7968 0 : GDXRegion[i]->xStart = minCol;
7969 0 : GDXRegion[i]->xCount = maxCol - minCol + 1;
7970 0 : GDXRegion[i]->yStart = minRow;
7971 0 : GDXRegion[i]->yCount = maxRow - minRow + 1;
7972 :
7973 :
7974 : /* Store upleft and lowright points of subset region */
7975 : /* ------------------------------------------------- */
7976 0 : if (projcode == GCTP_GEO )
7977 : {
7978 : /* GEO projection */
7979 : /* ------------------------ */
7980 :
7981 : /* Convert upleft & lowright lon from DMS to radians */
7982 : /* ------------------------------------------------- */
7983 0 : lonrad0 = EHconvAng(upleftpt[0], HDFE_DMS_RAD);
7984 0 : lonrad2 = EHconvAng(lowrightpt[0], HDFE_DMS_RAD);
7985 :
7986 : /* Compute X scale */
7987 : /* --------------- */
7988 0 : xscale = (lonrad2 - lonrad0) / xdimsize;
7989 :
7990 : /* Convert upleft & lowright lat from DMS to radians */
7991 : /* ------------------------------------------------- */
7992 0 : latrad0 = EHconvAng(upleftpt[1], HDFE_DMS_RAD);
7993 0 : latrad2 = EHconvAng(lowrightpt[1], HDFE_DMS_RAD);
7994 :
7995 : /* Compute Y scale */
7996 : /* --------------- */
7997 0 : yscale = (latrad2 - latrad0) / ydimsize;
7998 :
7999 :
8000 : /* MinCol -> radians -> DMS -> upleftpt[0] */
8001 : /* --------------------------------------- */
8002 0 : GDXRegion[i]->upleftpt[0] =
8003 0 : EHconvAng(lonrad0 + xscale * minCol,
8004 : HDFE_RAD_DMS);
8005 :
8006 :
8007 : /* MinRow -> radians -> DMS -> upleftpt[1] */
8008 : /* --------------------------------------- */
8009 0 : GDXRegion[i]->upleftpt[1] =
8010 0 : EHconvAng(latrad0 + yscale * minRow,
8011 : HDFE_RAD_DMS);
8012 :
8013 :
8014 : /* MinCol + 1 -> radians -> DMS -> lowrightpt[0] */
8015 : /* --------------------------------------------- */
8016 0 : GDXRegion[i]->lowrightpt[0] =
8017 0 : EHconvAng(lonrad0 + xscale * (maxCol + 1),
8018 : HDFE_RAD_DMS);
8019 :
8020 :
8021 : /* MinRow + 1 -> radians -> DMS -> lowrightpt[1] */
8022 : /* --------------------------------------------- */
8023 0 : GDXRegion[i]->lowrightpt[1] =
8024 0 : EHconvAng(latrad0 + yscale * (maxRow + 1),
8025 : HDFE_RAD_DMS);
8026 : }
8027 0 : else if (projcode == GCTP_BCEA)
8028 : {
8029 : /* BCEA projection */
8030 : /* -------------- */
8031 0 : nlatlon = 2;
8032 0 : lon[0] = upleftpt[0];
8033 0 : lon[1] = lowrightpt[0];
8034 0 : lat[0] = upleftpt[1];
8035 0 : lat[1] = lowrightpt[1];
8036 : status =
8037 0 : GDll2mm_cea(projcode,zonecode,spherecode,projparm,
8038 : xdimsize, ydimsize,
8039 : upleftpt, lowrightpt,nlatlon,
8040 : lon, lat,
8041 : xcor, ycor, &xscale, &yscale);
8042 0 : upleftpt_m[0] = xcor[0];
8043 0 : upleftpt_m[1] = ycor[0];
8044 :
8045 :
8046 0 : if (status == -1)
8047 : {
8048 0 : HEpush(DFE_GENAPP, "GDdefboxregion", __FILE__, __LINE__);
8049 0 : free(utlbuf);
8050 0 : free(gridname);
8051 0 : return (status);
8052 : }
8053 :
8054 : /* MinCol -> meters -> upleftpt[0] */
8055 : /* ------------------------------- */
8056 0 : xmtr[0] = upleftpt_m[0] + xscale * minCol;
8057 :
8058 : /* MinRow -> meters -> upleftpt[1] */
8059 : /* ------------------------------- */
8060 0 : ymtr[0] = upleftpt_m[1] + yscale * minRow;
8061 :
8062 : /* MinCol + 1 -> meters -> lowrightpt[0] */
8063 : /* ------------------------------------- */
8064 0 : xmtr[1] = upleftpt_m[0] + xscale * (maxCol + 1);
8065 :
8066 : /* MinRow + 1 -> meters -> lowrightpt[1] */
8067 : /* ------------------------------------- */
8068 0 : ymtr[1] = upleftpt_m[1] + yscale * (maxRow + 1);
8069 :
8070 : /* Convert upleft & lowright lon from DMS to radians */
8071 : /* ------------------------------------------------- */
8072 0 : npnts = 2;
8073 0 : status = GDmm2ll_cea(projcode, zonecode, spherecode,
8074 : projparm, xdimsize, ydimsize,
8075 : upleftpt, lowrightpt, npnts,
8076 : xmtr, ymtr,
8077 : longitude, latitude);
8078 0 : if (status == -1)
8079 : {
8080 0 : HEpush(DFE_GENAPP, "GDdefboxregion", __FILE__, __LINE__);
8081 0 : free(utlbuf);
8082 0 : free(gridname);
8083 0 : return (status);
8084 : }
8085 0 : GDXRegion[i]->upleftpt[0] = longitude[0];
8086 :
8087 0 : GDXRegion[i]->upleftpt[1] = latitude[0];
8088 :
8089 0 : GDXRegion[i]->lowrightpt[0] = longitude[1];
8090 :
8091 0 : GDXRegion[i]->lowrightpt[1] = latitude[1];
8092 : }
8093 0 : else if (projcode == GCTP_SOM)
8094 : {
8095 : /* Store start & count along x & y */
8096 : /* ------------------------------- */
8097 0 : GDXRegion[i]->xStart = 0;
8098 0 : GDXRegion[i]->xCount = xdimsize;
8099 0 : GDXRegion[i]->yStart = 0;
8100 0 : GDXRegion[i]->yCount = ydimsize;
8101 :
8102 0 : GDXRegion[i]->somStart = blockindexstart;
8103 0 : GDXRegion[i]->somCount = blockindexstop - blockindexstart + 1;
8104 :
8105 : /* Store upleft and lowright points of subset region */
8106 : /* ------------------------------------------------- */
8107 0 : if (blockindexstart == 0)
8108 : {
8109 0 : GDXRegion[i]->upleftpt[0] = upleftpt[0];
8110 0 : GDXRegion[i]->upleftpt[1] = upleftpt[1];
8111 0 : GDXRegion[i]->lowrightpt[0] = lowrightpt[0];
8112 0 : GDXRegion[i]->lowrightpt[1] = lowrightpt[1];
8113 : }
8114 : else
8115 : {
8116 0 : GDXRegion[i]->upleftpt[0] =
8117 0 : (lowrightpt[0] - upleftpt[0])*
8118 0 : (offset[blockindexstart-1]/xdimsize) + upleftpt[0];
8119 0 : GDXRegion[i]->upleftpt[1] =
8120 0 : (lowrightpt[1] - upleftpt[1])*
8121 0 : (blockindexstart+1-1) + upleftpt[1];
8122 :
8123 0 : GDXRegion[i]->lowrightpt[0] =
8124 0 : (lowrightpt[0] - upleftpt[0])*
8125 0 : (offset[blockindexstart-1]/xdimsize) + lowrightpt[0];
8126 0 : GDXRegion[i]->lowrightpt[1] =
8127 0 : (lowrightpt[1] - upleftpt[1])*
8128 0 : (blockindexstart+1-1) + lowrightpt[1];
8129 :
8130 : }
8131 : }
8132 : else
8133 : {
8134 : /* Non-GEO, Non-BCEA projections */
8135 : /* ---------------------------- */
8136 :
8137 : /* Compute X & Y scale */
8138 : /* ------------------- */
8139 0 : xscale = (lowrightpt[0] - upleftpt[0]) / xdimsize;
8140 0 : yscale = (lowrightpt[1] - upleftpt[1]) / ydimsize;
8141 :
8142 :
8143 : /* MinCol -> meters -> upleftpt[0] */
8144 : /* ------------------------------- */
8145 0 : GDXRegion[i]->upleftpt[0] = upleftpt[0] +
8146 0 : xscale * minCol;
8147 :
8148 :
8149 : /* MinRow -> meters -> upleftpt[1] */
8150 : /* ------------------------------- */
8151 0 : GDXRegion[i]->upleftpt[1] = upleftpt[1] +
8152 0 : yscale * minRow;
8153 :
8154 :
8155 : /* MinCol + 1 -> meters -> lowrightpt[0] */
8156 : /* ------------------------------------- */
8157 0 : GDXRegion[i]->lowrightpt[0] = upleftpt[0] +
8158 0 : xscale * (maxCol + 1);
8159 :
8160 :
8161 : /* MinRow + 1 -> meters -> lowrightpt[1] */
8162 : /* ------------------------------------- */
8163 0 : GDXRegion[i]->lowrightpt[1] = upleftpt[1] +
8164 0 : yscale * (maxRow + 1);
8165 : }
8166 :
8167 : /* Store region ID */
8168 : /* --------------- */
8169 0 : regionID = i;
8170 0 : break;
8171 : }
8172 :
8173 : }
8174 : }
8175 :
8176 : }
8177 0 : free(utlbuf);
8178 0 : free(gridname);
8179 0 : return (regionID);
8180 : }
8181 :
8182 :
8183 :
8184 :
8185 :
8186 : /*----------------------------------------------------------------------------|
8187 : | BEGIN_PROLOG |
8188 : | |
8189 : | FUNCTION: GDregioninfo |
8190 : | |
8191 : | DESCRIPTION: Retrieves size of region in bytes. |
8192 : | |
8193 : | |
8194 : | Return Value Type Units Description |
8195 : | ============ ====== ========= ===================================== |
8196 : | status intn return status (0) SUCCEED, (-1) FAIL |
8197 : | |
8198 : | INPUTS: |
8199 : | gridID int32 Grid structure ID |
8200 : | regionID int32 Region ID |
8201 : | fieldname char Fieldname |
8202 : | |
8203 : | |
8204 : | OUTPUTS: |
8205 : | ntype int32 field number type |
8206 : | rank int32 field rank |
8207 : | dims int32 dimensions of field region |
8208 : | size int32 size in bytes of field region |
8209 : | upleftpt float64 Upper left corner coord for region |
8210 : | lowrightpt float64 Lower right corner coord for region |
8211 : | |
8212 : | NOTES: |
8213 : | |
8214 : | |
8215 : | Date Programmer Description |
8216 : | ====== ============ ================================================= |
8217 : | Jun 96 Joel Gales Original Programmer |
8218 : | Aug 96 Joel Gales Add vertical subsetting |
8219 : | Dec 96 Joel Gales Add multiple vertical subsetting capability |
8220 : | Apr 99 David Wynne Added support for MISR SOM projection, NCR 21195 |
8221 : | |
8222 : | END_PROLOG |
8223 : -----------------------------------------------------------------------------*/
8224 : intn
8225 0 : GDregioninfo(int32 gridID, int32 regionID, const char *fieldname,
8226 : int32 * ntype, int32 * rank, int32 dims[], int32 * size,
8227 : float64 upleftpt[], float64 lowrightpt[])
8228 : {
8229 : intn j; /* Loop index */
8230 0 : intn status = 0; /* routine return status variable */
8231 :
8232 : int32 fid; /* HDF-EOS file ID */
8233 : int32 sdInterfaceID; /* HDF SDS interface ID */
8234 : int32 gdVgrpID; /* Grid root Vgroup ID */
8235 : int32 l_index; /* Dimension l_index */
8236 :
8237 : char dimlist[256]; /* Dimension list */
8238 0 : const char *errMesg = "Vertical Dimension Not Found: \"%s\".\n";
8239 0 : const char *errM1 = "Both \"XDim\" and \"YDim\" must be present ";
8240 0 : const char *errM2 = "in the dimension list for \"%s\".\n";
8241 : char errbuf[256];/* Error buffer */
8242 :
8243 :
8244 : /* Check for valid grid ID */
8245 : /* ----------------------- */
8246 0 : status = GDchkgdid(gridID, "GDregioninfo", &fid, &sdInterfaceID,
8247 : &gdVgrpID);
8248 :
8249 :
8250 : /* Check for valid region ID */
8251 : /* ------------------------- */
8252 0 : if (status == 0)
8253 : {
8254 0 : if (regionID < 0 || regionID >= NGRIDREGN)
8255 : {
8256 0 : status = -1;
8257 0 : HEpush(DFE_RANGE, "GDregioninfo", __FILE__, __LINE__);
8258 0 : HEreport("Invalid Region id: %d.\n", regionID);
8259 : }
8260 : }
8261 :
8262 :
8263 : /* Check for active region ID */
8264 : /* -------------------------- */
8265 0 : if (status == 0)
8266 : {
8267 0 : if (GDXRegion[regionID] == 0)
8268 : {
8269 0 : status = -1;
8270 0 : HEpush(DFE_GENAPP, "GDregioninfo", __FILE__, __LINE__);
8271 0 : HEreport("Inactive Region ID: %d.\n", regionID);
8272 : }
8273 : }
8274 :
8275 :
8276 :
8277 : /* Check that region defined for this file */
8278 : /* --------------------------------------- */
8279 0 : if (status == 0)
8280 : {
8281 0 : if (GDXRegion[regionID]->fid != fid)
8282 : {
8283 0 : status = -1;
8284 0 : HEpush(DFE_GENAPP, "GDregioninfo", __FILE__, __LINE__);
8285 0 : HEreport("Region is not defined for this file.\n");
8286 : }
8287 : }
8288 :
8289 :
8290 : /* Check that region defined for this grid */
8291 : /* --------------------------------------- */
8292 0 : if (status == 0)
8293 : {
8294 0 : if (GDXRegion[regionID]->gridID != gridID)
8295 : {
8296 0 : status = -1;
8297 0 : HEpush(DFE_GENAPP, "GDregioninfo", __FILE__, __LINE__);
8298 0 : HEreport("Region is not defined for this Grid.\n");
8299 : }
8300 : }
8301 :
8302 :
8303 :
8304 : /* Check for valid fieldname */
8305 : /* ------------------------- */
8306 0 : if (status == 0)
8307 : {
8308 0 : status = GDfieldinfo(gridID, fieldname, rank, dims, ntype, dimlist);
8309 :
8310 0 : if (status != 0)
8311 : {
8312 : /* Fieldname not found in grid */
8313 : /* --------------------------- */
8314 0 : status = -1;
8315 0 : HEpush(DFE_GENAPP, "GDregioninfo", __FILE__, __LINE__);
8316 0 : HEreport("Fieldname \"%s\" not found.\n",
8317 : fieldname);
8318 : }
8319 0 : else if (*rank == 1)
8320 : {
8321 : /* Field is 1 dimensional */
8322 : /* ---------------------- */
8323 0 : status = -1;
8324 0 : HEpush(DFE_GENAPP, "GDregioninfo", __FILE__, __LINE__);
8325 0 : HEreport(
8326 : "One-Dimesional fields \"%s\" may not be subsetted.\n",
8327 : fieldname);
8328 : }
8329 : else
8330 : {
8331 : /* "XDim" and/or "YDim" not found */
8332 : /* ------------------------------ */
8333 0 : if (EHstrwithin("XDim", dimlist, ',') == -1 ||
8334 0 : EHstrwithin("YDim", dimlist, ',') == -1)
8335 : {
8336 0 : status = -1;
8337 0 : HEpush(DFE_GENAPP, "GDregioninfo", __FILE__, __LINE__);
8338 0 : snprintf(errbuf, sizeof(errbuf), "%s%s", errM1, errM2);
8339 0 : HEreport(errbuf, fieldname);
8340 : }
8341 : }
8342 : }
8343 :
8344 :
8345 :
8346 : /* If no problems ... */
8347 : /* ------------------ */
8348 0 : if (status == 0)
8349 : {
8350 : /* Check if SOM projection */
8351 : /* ----------------------- */
8352 0 : if (EHstrwithin("SOMBlockDim", dimlist, ',') == 0)
8353 : {
8354 0 : dims[EHstrwithin("SOMBlockDim", dimlist, ',')] =
8355 0 : GDXRegion[regionID]->somCount;
8356 : }
8357 :
8358 : /* Load XDim dimension from region entry */
8359 : /* ------------------------------------- */
8360 0 : if (GDXRegion[regionID]->xCount != 0)
8361 : {
8362 0 : dims[EHstrwithin("XDim", dimlist, ',')] =
8363 0 : GDXRegion[regionID]->xCount;
8364 : }
8365 :
8366 : /* Load YDim dimension from region entry */
8367 : /* ------------------------------------- */
8368 0 : if (GDXRegion[regionID]->yCount != 0)
8369 : {
8370 0 : dims[EHstrwithin("YDim", dimlist, ',')] =
8371 0 : GDXRegion[regionID]->yCount;
8372 : }
8373 :
8374 :
8375 : /* Vertical Subset */
8376 : /* --------------- */
8377 0 : for (j = 0; j < 8; j++)
8378 : {
8379 :
8380 : /* If active vertical subset ... */
8381 : /* ----------------------------- */
8382 0 : if (GDXRegion[regionID]->StartVertical[j] != -1)
8383 : {
8384 : /* Find vertical dimension within dimlist */
8385 : /* -------------------------------------- */
8386 0 : l_index = EHstrwithin(GDXRegion[regionID]->DimNamePtr[j],
8387 : dimlist, ',');
8388 :
8389 : /* If dimension found ... */
8390 : /* ---------------------- */
8391 0 : if (l_index != -1)
8392 : {
8393 : /* Compute dimension size */
8394 : /* ---------------------- */
8395 0 : dims[l_index] =
8396 0 : GDXRegion[regionID]->StopVertical[j] -
8397 0 : GDXRegion[regionID]->StartVertical[j] + 1;
8398 : }
8399 : else
8400 : {
8401 : /* Vertical dimension not found */
8402 : /* ---------------------------- */
8403 0 : status = -1;
8404 0 : *size = -1;
8405 0 : HEpush(DFE_GENAPP, "GDregioninfo",
8406 : __FILE__, __LINE__);
8407 0 : HEreport(errMesg,
8408 0 : GDXRegion[regionID]->DimNamePtr[j]);
8409 : }
8410 : }
8411 : }
8412 :
8413 :
8414 0 : if (status == 0)
8415 : {
8416 : /* Compute number of total elements */
8417 : /* -------------------------------- */
8418 0 : *size = dims[0];
8419 0 : for (j = 1; j < *rank; j++)
8420 : {
8421 0 : *size *= dims[j];
8422 : }
8423 :
8424 : /* Multiply by size in bytes of numbertype */
8425 : /* --------------------------------------- */
8426 0 : *size *= DFKNTsize(*ntype);
8427 :
8428 :
8429 : /* Return upper left and lower right subset values */
8430 : /* ----------------------------------------------- */
8431 0 : upleftpt[0] = GDXRegion[regionID]->upleftpt[0];
8432 0 : upleftpt[1] = GDXRegion[regionID]->upleftpt[1];
8433 0 : lowrightpt[0] = GDXRegion[regionID]->lowrightpt[0];
8434 0 : lowrightpt[1] = GDXRegion[regionID]->lowrightpt[1];
8435 : }
8436 : }
8437 0 : return (status);
8438 : }
8439 :
8440 :
8441 :
8442 :
8443 :
8444 : /*----------------------------------------------------------------------------|
8445 : | BEGIN_PROLOG |
8446 : | |
8447 : | FUNCTION: GDextractregion |
8448 : | |
8449 : | DESCRIPTION: Retrieves data from specified region. |
8450 : | |
8451 : | |
8452 : | Return Value Type Units Description |
8453 : | ============ ====== ========= ===================================== |
8454 : | status intn return status (0) SUCCEED, (-1) FAIL |
8455 : | |
8456 : | INPUTS: |
8457 : | gridID int32 Grid structure ID |
8458 : | regionID int32 Region ID |
8459 : | fieldname char Fieldname |
8460 : | |
8461 : | OUTPUTS: |
8462 : | buffer void Data buffer containing subsetted region |
8463 : | |
8464 : | |
8465 : | NOTES: |
8466 : | |
8467 : | |
8468 : | Date Programmer Description |
8469 : | ====== ============ ================================================= |
8470 : | Jun 96 Joel Gales Original Programmer |
8471 : | Aug 96 Joel Gales Add vertical subsetting |
8472 : | Dec 96 Joel Gales Add multiple vertical subsetting capability |
8473 : | Apr 99 David Wynne Add support for MISR SOM projection, NCR 21195 |
8474 : | |
8475 : | END_PROLOG |
8476 : -----------------------------------------------------------------------------*/
8477 : intn
8478 0 : GDextractregion(int32 gridID, int32 regionID, const char *fieldname,
8479 : VOIDP buffer)
8480 : {
8481 : intn i; /* Loop index */
8482 : intn j; /* Loop index */
8483 0 : intn status = 0; /* routine return status variable */
8484 :
8485 : int32 fid; /* HDF-EOS file ID */
8486 : int32 sdInterfaceID; /* HDF SDS interface ID */
8487 : int32 gdVgrpID; /* Grid root Vgroup ID */
8488 : int32 l_index; /* Dimension l_index */
8489 : int32 start[8]; /* Start array for data read */
8490 : int32 edge[8]; /* Edge array for data read */
8491 : int32 dims[8]; /* Dimensions */
8492 0 : int32 rank = 0; /* Field rank */
8493 : int32 ntype; /* Field number type */
8494 : int32 origincode; /* Pixel origin code */
8495 :
8496 : char dimlist[256]; /* Dimension list */
8497 0 : const char *errMesg = "Vertical Dimension Not Found: \"%s\".\n";
8498 0 : const char *errM1 = "Both \"XDim\" and \"YDim\" must be present ";
8499 0 : const char *errM2 = "in the dimension list for \"%s\".\n";
8500 : char errbuf[256];/* Error buffer */
8501 :
8502 :
8503 : /* Check for valid grid ID */
8504 : /* ----------------------- */
8505 0 : status = GDchkgdid(gridID, "GDextractregion", &fid, &sdInterfaceID,
8506 : &gdVgrpID);
8507 :
8508 :
8509 : /* Check for valid region ID */
8510 : /* ------------------------- */
8511 0 : if (status == 0)
8512 : {
8513 0 : if (regionID < 0 || regionID >= NGRIDREGN)
8514 : {
8515 0 : status = -1;
8516 0 : HEpush(DFE_RANGE, "GDextractregion", __FILE__, __LINE__);
8517 0 : HEreport("Invalid Region id: %d.\n", regionID);
8518 : }
8519 : }
8520 :
8521 :
8522 : /* Check for active region ID */
8523 : /* -------------------------- */
8524 0 : if (status == 0)
8525 : {
8526 0 : if (GDXRegion[regionID] == 0)
8527 : {
8528 0 : status = -1;
8529 0 : HEpush(DFE_GENAPP, "GDextractregion", __FILE__, __LINE__);
8530 0 : HEreport("Inactive Region ID: %d.\n", regionID);
8531 : }
8532 : }
8533 :
8534 :
8535 :
8536 : /* Check that region defined for this file */
8537 : /* --------------------------------------- */
8538 0 : if (status == 0)
8539 : {
8540 0 : if (GDXRegion[regionID]->fid != fid)
8541 : {
8542 0 : status = -1;
8543 0 : HEpush(DFE_GENAPP, "GDextractregion", __FILE__, __LINE__);
8544 0 : HEreport("Region is not defined for this file.\n");
8545 : }
8546 : }
8547 :
8548 :
8549 : /* Check that region defined for this grid */
8550 : /* --------------------------------------- */
8551 0 : if (status == 0)
8552 : {
8553 0 : if (GDXRegion[regionID]->gridID != gridID)
8554 : {
8555 0 : status = -1;
8556 0 : HEpush(DFE_GENAPP, "GDextractregion", __FILE__, __LINE__);
8557 0 : HEreport("Region is not defined for this Grid.\n");
8558 : }
8559 : }
8560 :
8561 :
8562 :
8563 : /* Check for valid fieldname */
8564 : /* ------------------------- */
8565 0 : if (status == 0)
8566 : {
8567 0 : status = GDfieldinfo(gridID, fieldname, &rank, dims, &ntype, dimlist);
8568 :
8569 0 : if (status != 0)
8570 : {
8571 : /* Fieldname not found in grid */
8572 : /* --------------------------- */
8573 0 : status = -1;
8574 0 : HEpush(DFE_GENAPP, "GDextractregion", __FILE__, __LINE__);
8575 0 : HEreport("Fieldname \"%s\" not found.\n",
8576 : fieldname);
8577 : }
8578 0 : else if (rank == 1)
8579 : {
8580 : /* Field is 1 dimensional */
8581 : /* ---------------------- */
8582 0 : status = -1;
8583 0 : HEpush(DFE_GENAPP, "GDextractregion", __FILE__, __LINE__);
8584 0 : HEreport(
8585 : "One-Dimesional fields \"%s\" may not be subsetted.\n",
8586 : fieldname);
8587 : }
8588 : else
8589 : {
8590 : /* "XDim" and/or "YDim" not found */
8591 : /* ------------------------------ */
8592 0 : if (EHstrwithin("XDim", dimlist, ',') == -1 ||
8593 0 : EHstrwithin("YDim", dimlist, ',') == -1)
8594 : {
8595 0 : status = -1;
8596 0 : HEpush(DFE_GENAPP, "GDextractregion", __FILE__, __LINE__);
8597 0 : snprintf(errbuf, sizeof(errbuf), "%s%s", errM1, errM2);
8598 0 : HEreport(errbuf, fieldname);
8599 : }
8600 : }
8601 : }
8602 :
8603 :
8604 :
8605 0 : if (status == 0)
8606 : {
8607 :
8608 : /* Get origin order info */
8609 : /* --------------------- */
8610 0 : status = GDorigininfo(gridID, &origincode);
8611 :
8612 :
8613 : /* Initialize start & edge arrays */
8614 : /* ------------------------------ */
8615 0 : for (i = 0; i < rank; i++)
8616 : {
8617 0 : start[i] = 0;
8618 0 : edge[i] = dims[i];
8619 : }
8620 :
8621 :
8622 : /* if MISR SOM projection, set start */
8623 : /* & edge arrays for SOMBlockDim */
8624 : /* --------------------------------- */
8625 0 : if (EHstrwithin("SOMBlockDim", dimlist, ',') == 0)
8626 : {
8627 0 : l_index = EHstrwithin("SOMBlockDim", dimlist, ',');
8628 0 : edge[l_index] = GDXRegion[regionID]->somCount;
8629 0 : start[l_index] = GDXRegion[regionID]->somStart;
8630 : }
8631 :
8632 :
8633 : /* Set start & edge arrays for XDim */
8634 : /* -------------------------------- */
8635 0 : l_index = EHstrwithin("XDim", dimlist, ',');
8636 0 : if (GDXRegion[regionID]->xCount != 0)
8637 : {
8638 0 : edge[l_index] = GDXRegion[regionID]->xCount;
8639 0 : start[l_index] = GDXRegion[regionID]->xStart;
8640 : }
8641 :
8642 : /* Adjust X-dim start if origin on right edge */
8643 : /* ------------------------------------------ */
8644 0 : if ((origincode & 1) == 1)
8645 : {
8646 0 : start[l_index] = dims[l_index] - (start[l_index] + edge[l_index]);
8647 : }
8648 :
8649 :
8650 : /* Set start & edge arrays for YDim */
8651 : /* -------------------------------- */
8652 0 : l_index = EHstrwithin("YDim", dimlist, ',');
8653 0 : if (GDXRegion[regionID]->yCount != 0)
8654 : {
8655 0 : start[l_index] = GDXRegion[regionID]->yStart;
8656 0 : edge[l_index] = GDXRegion[regionID]->yCount;
8657 : }
8658 :
8659 : /* Adjust Y-dim start if origin on lower edge */
8660 : /* ------------------------------------------ */
8661 0 : if ((origincode & 2) == 2)
8662 : {
8663 0 : start[l_index] = dims[l_index] - (start[l_index] + edge[l_index]);
8664 : }
8665 :
8666 :
8667 :
8668 : /* Vertical Subset */
8669 : /* --------------- */
8670 0 : for (j = 0; j < 8; j++)
8671 : {
8672 : /* If active vertical subset ... */
8673 : /* ----------------------------- */
8674 0 : if (GDXRegion[regionID]->StartVertical[j] != -1)
8675 : {
8676 :
8677 : /* Find vertical dimension within dimlist */
8678 : /* -------------------------------------- */
8679 0 : l_index = EHstrwithin(GDXRegion[regionID]->DimNamePtr[j],
8680 : dimlist, ',');
8681 :
8682 : /* If dimension found ... */
8683 : /* ---------------------- */
8684 0 : if (l_index != -1)
8685 : {
8686 : /* Compute start and edge for vertical dimension */
8687 : /* --------------------------------------------- */
8688 0 : start[l_index] = GDXRegion[regionID]->StartVertical[j];
8689 0 : edge[l_index] = GDXRegion[regionID]->StopVertical[j] -
8690 0 : GDXRegion[regionID]->StartVertical[j] + 1;
8691 : }
8692 : else
8693 : {
8694 : /* Vertical dimension not found */
8695 : /* ---------------------------- */
8696 0 : status = -1;
8697 0 : HEpush(DFE_GENAPP, "GDextractregion", __FILE__, __LINE__);
8698 0 : HEreport(errMesg,
8699 0 : GDXRegion[regionID]->DimNamePtr[j]);
8700 : }
8701 : }
8702 : }
8703 :
8704 :
8705 : /* Read into data buffer */
8706 : /* --------------------- */
8707 0 : if (status == 0)
8708 : {
8709 0 : status = GDreadfield(gridID, fieldname, start, NULL, edge, buffer);
8710 : }
8711 : }
8712 0 : return (status);
8713 : }
8714 :
8715 :
8716 :
8717 :
8718 : /*----------------------------------------------------------------------------|
8719 : | BEGIN_PROLOG |
8720 : | |
8721 : | FUNCTION: GDdupregion |
8722 : | |
8723 : | DESCRIPTION: Duplicates a region |
8724 : | |
8725 : | |
8726 : | Return Value Type Units Description |
8727 : | ============ ====== ========= ===================================== |
8728 : | newregionID int32 New region ID |
8729 : | |
8730 : | INPUTS: |
8731 : | oldregionID int32 Old region ID |
8732 : | |
8733 : | OUTPUTS: |
8734 : | None |
8735 : | |
8736 : | NOTES: |
8737 : | |
8738 : | |
8739 : | Date Programmer Description |
8740 : | ====== ============ ================================================= |
8741 : | Jan 97 Joel Gales Original Programmer |
8742 : | Oct 98 Abe Taaheri changed *GDXRegion[i] = *GDXRegion[oldregionID]; |
8743 : | to copy elements of structure one by one to avoid |
8744 : | copying pointer for DimNamePtr to another place that|
8745 : | causes "Freeing Unallocated Memory" in purify when |
8746 : | using GDdetach |
8747 : | |
8748 : | END_PROLOG |
8749 : -----------------------------------------------------------------------------*/
8750 : int32
8751 0 : GDdupregion(int32 oldregionID)
8752 : {
8753 : intn i; /* Loop index */
8754 : intn j; /* Loop index */
8755 : int32 slendupregion;
8756 0 : int32 newregionID = -1; /* New region ID */
8757 :
8758 :
8759 : /* Find first empty (inactive) region */
8760 : /* ---------------------------------- */
8761 0 : for (i = 0; i < NGRIDREGN; i++)
8762 : {
8763 0 : if (GDXRegion[i] == 0)
8764 : {
8765 : /* Allocate space for new grid region entry */
8766 : /* ---------------------------------------- */
8767 0 : GDXRegion[i] = (struct gridRegion *)
8768 0 : calloc(1, sizeof(struct gridRegion));
8769 0 : if(GDXRegion[i] == NULL)
8770 : {
8771 0 : HEpush(DFE_NOSPACE,"GDdupregion", __FILE__, __LINE__);
8772 0 : return(-1);
8773 : }
8774 :
8775 :
8776 : /* Copy old region structure data to new region */
8777 : /* -------------------------------------------- */
8778 :
8779 0 : GDXRegion[i]->fid = GDXRegion[oldregionID]->fid;
8780 0 : GDXRegion[i]->gridID = GDXRegion[oldregionID]->gridID;
8781 0 : GDXRegion[i]->xStart = GDXRegion[oldregionID]->xStart;
8782 0 : GDXRegion[i]->xCount = GDXRegion[oldregionID]->xCount;
8783 0 : GDXRegion[i]->yStart = GDXRegion[oldregionID]->yStart;
8784 0 : GDXRegion[i]->yCount = GDXRegion[oldregionID]->yCount;
8785 0 : GDXRegion[i]->upleftpt[0] = GDXRegion[oldregionID]->upleftpt[0];
8786 0 : GDXRegion[i]->upleftpt[1] = GDXRegion[oldregionID]->upleftpt[1];
8787 0 : GDXRegion[i]->lowrightpt[0] = GDXRegion[oldregionID]->lowrightpt[0];
8788 0 : GDXRegion[i]->lowrightpt[1] = GDXRegion[oldregionID]->lowrightpt[1];
8789 0 : for (j = 0; j < 8; j++)
8790 : {
8791 0 : GDXRegion[i]->StartVertical[j] = GDXRegion[oldregionID]->StartVertical[j];
8792 0 : GDXRegion[i]->StopVertical[j] = GDXRegion[oldregionID]->StopVertical[j];
8793 : }
8794 :
8795 0 : for (j=0; j<8; j++)
8796 : {
8797 0 : if(GDXRegion[oldregionID]->DimNamePtr[j] != NULL)
8798 : {
8799 0 : slendupregion = (int)strlen(GDXRegion[oldregionID]->DimNamePtr[j]);
8800 0 : GDXRegion[i]->DimNamePtr[j] = (char *) malloc(slendupregion + 1);
8801 0 : strcpy(GDXRegion[i]->DimNamePtr[j],GDXRegion[oldregionID]->DimNamePtr[j]);
8802 : }
8803 : }
8804 :
8805 :
8806 : /* Define new region ID */
8807 : /* -------------------- */
8808 0 : newregionID = i;
8809 :
8810 0 : break;
8811 : }
8812 : }
8813 0 : return (newregionID);
8814 : }
8815 :
8816 :
8817 : /*----------------------------------------------------------------------------|
8818 : | BEGIN_PROLOG |
8819 : | |
8820 : | FUNCTION: GDdefvrtregion |
8821 : | |
8822 : | DESCRIPTION: Finds elements of a monotonic field within a vertical subset |
8823 : | region. |
8824 : | |
8825 : | |
8826 : | Return Value Type Units Description |
8827 : | ============ ====== ========= ===================================== |
8828 : | regionID int32 Region ID |
8829 : | |
8830 : | INPUTS: |
8831 : | gridID int32 Grid structure ID |
8832 : | regionID int32 Region ID |
8833 : | vertObj char Vertical object to subset |
8834 : | range float64 Vertical subsetting range |
8835 : | |
8836 : | OUTPUTS: |
8837 : | None |
8838 : | |
8839 : | NOTES: |
8840 : | |
8841 : | |
8842 : | Date Programmer Description |
8843 : | ====== ============ ================================================= |
8844 : | Aug 96 Joel Gales Original Programmer |
8845 : | Dec 96 Joel Gales Add multiple vertical subsetting capability |
8846 : | Feb 97 Joel Gales Store XDim, YDim, upleftpt, lowrightpt in GDXRegion |
8847 : | |
8848 : | END_PROLOG |
8849 : -----------------------------------------------------------------------------*/
8850 : #define SETGRIDREG \
8851 : \
8852 : status = GDgridinfo(gridID, &xdimsize, &ydimsize, upleftpt, lowrightpt); \
8853 : for (k = 0; k < NGRIDREGN; k++) \
8854 : { \
8855 : if (GDXRegion[k] == 0) \
8856 : { \
8857 : GDXRegion[k] = (struct gridRegion *) \
8858 : calloc(1, sizeof(struct gridRegion)); \
8859 : GDXRegion[k]->fid = fid; \
8860 : GDXRegion[k]->gridID = gridID; \
8861 : GDXRegion[k]->xStart = 0; \
8862 : GDXRegion[k]->xCount = xdimsize; \
8863 : GDXRegion[k]->yStart = 0; \
8864 : GDXRegion[k]->yCount = ydimsize; \
8865 : GDXRegion[k]->upleftpt[0] = upleftpt[0]; \
8866 : GDXRegion[k]->upleftpt[1] = upleftpt[1]; \
8867 : GDXRegion[k]->lowrightpt[0] = lowrightpt[0]; \
8868 : GDXRegion[k]->lowrightpt[1] = lowrightpt[1]; \
8869 : regionID = k; \
8870 : for (j=0; j<8; j++) \
8871 : { \
8872 : GDXRegion[k]->StartVertical[j] = -1; \
8873 : GDXRegion[k]->StopVertical[j] = -1; \
8874 : } \
8875 : break; \
8876 : } \
8877 : }
8878 :
8879 : #define FILLVERTREG \
8880 : for (j=0; j<8; j++) \
8881 : { \
8882 : if (GDXRegion[regionID]->StartVertical[j] == -1) \
8883 : { \
8884 : GDXRegion[regionID]->StartVertical[j] = i; \
8885 : GDXRegion[regionID]->DimNamePtr[j] = \
8886 : (char *) malloc(slen + 1); \
8887 : memcpy(GDXRegion[regionID]->DimNamePtr[j], \
8888 : dimlist, slen + 1); \
8889 : break; \
8890 : } \
8891 : } \
8892 :
8893 :
8894 :
8895 : int32
8896 0 : GDdefvrtregion(int32 gridID, int32 regionID, const char *vertObj, float64 range[])
8897 : {
8898 0 : intn i, j = 0, k, status;
8899 0 : uint8 found = 0;
8900 :
8901 : int16 vertINT16;
8902 :
8903 : int32 fid, sdInterfaceID, slen;
8904 : int32 gdVgrpID, rank, nt, dims[8], size;
8905 : int32 vertINT32;
8906 : int32 xdimsize;
8907 : int32 ydimsize;
8908 :
8909 : float32 vertFLT32;
8910 : float64 vertFLT64;
8911 : float64 upleftpt[2];
8912 : float64 lowrightpt[2];
8913 :
8914 : char *vertArr;
8915 : char *dimlist;
8916 :
8917 : /* Allocate space for dimlist */
8918 : /* --------------------------------- */
8919 0 : dimlist = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
8920 0 : if(dimlist == NULL)
8921 : {
8922 0 : HEpush(DFE_NOSPACE,"GDdefvrtregion", __FILE__, __LINE__);
8923 0 : return(-1);
8924 : }
8925 : /* Check for valid grid ID */
8926 : /* ----------------------- */
8927 0 : status = GDchkgdid(gridID, "GDdefvrtregion",
8928 : &fid, &sdInterfaceID, &gdVgrpID);
8929 :
8930 0 : if (status == 0)
8931 : {
8932 0 : memcpy(dimlist, vertObj, 4);
8933 0 : dimlist[4] = 0;
8934 :
8935 0 : if (strcmp(dimlist, "DIM:") == 0)
8936 : {
8937 0 : slen = (int)strlen(vertObj) - 4;
8938 0 : if (regionID == -1)
8939 : {
8940 0 : SETGRIDREG;
8941 : }
8942 0 : for (j = 0; j < 8; j++)
8943 : {
8944 0 : if (GDXRegion[regionID]->StartVertical[j] == -1)
8945 : {
8946 0 : GDXRegion[regionID]->StartVertical[j] = (int32) range[0];
8947 0 : GDXRegion[regionID]->StopVertical[j] = (int32) range[1];
8948 0 : GDXRegion[regionID]->DimNamePtr[j] =
8949 0 : (char *) malloc(slen + 1);
8950 0 : if(GDXRegion[regionID]->DimNamePtr[j] == NULL)
8951 : {
8952 0 : HEpush(DFE_NOSPACE,"GDdefvrtregion", __FILE__, __LINE__);
8953 0 : free(dimlist);
8954 0 : return(-1);
8955 : }
8956 0 : memcpy(GDXRegion[regionID]->DimNamePtr[j],
8957 0 : vertObj + 4, slen + 1);
8958 0 : break;
8959 : }
8960 : }
8961 : }
8962 : else
8963 : {
8964 0 : status = GDfieldinfo(gridID, vertObj, &rank, dims, &nt, dimlist);
8965 0 : if (status != 0)
8966 : {
8967 0 : status = -1;
8968 0 : HEpush(DFE_GENAPP, "GDdefvrtregion", __FILE__, __LINE__);
8969 0 : HEreport("Vertical Field: \"%s\" not found.\n", vertObj);
8970 : }
8971 : else
8972 : {
8973 0 : if (rank != 1)
8974 : {
8975 0 : status = -1;
8976 0 : HEpush(DFE_GENAPP, "GDdefvrtregion", __FILE__, __LINE__);
8977 0 : HEreport("Vertical Field: \"%s\" must be 1-dim.\n",
8978 : vertObj);
8979 : }
8980 : else
8981 : {
8982 0 : slen = (int)strlen(dimlist);
8983 0 : size = DFKNTsize(nt);
8984 0 : vertArr = (char *) calloc(dims[0], size);
8985 0 : if(vertArr == NULL)
8986 : {
8987 0 : HEpush(DFE_NOSPACE,"GDdefvrtregion", __FILE__, __LINE__);
8988 0 : free(dimlist);
8989 0 : return(-1);
8990 : }
8991 :
8992 0 : status = GDreadfield(gridID, vertObj,
8993 : NULL, NULL, NULL, vertArr);
8994 :
8995 0 : switch (nt)
8996 : {
8997 0 : case DFNT_INT16:
8998 :
8999 0 : for (i = 0; i < dims[0]; i++)
9000 : {
9001 0 : memcpy(&vertINT16, vertArr + i * size, size);
9002 :
9003 0 : if (vertINT16 >= range[0] &&
9004 0 : vertINT16 <= range[1])
9005 : {
9006 0 : found = 1;
9007 0 : if (regionID == -1)
9008 : {
9009 0 : SETGRIDREG;
9010 : }
9011 0 : FILLVERTREG;
9012 :
9013 0 : break;
9014 : }
9015 : }
9016 :
9017 0 : if (found == 1)
9018 : {
9019 0 : for (i = dims[0] - 1; i >= 0; i--)
9020 : {
9021 0 : memcpy(&vertINT16, vertArr + i * size, size);
9022 :
9023 0 : if (vertINT16 >= range[0] &&
9024 0 : vertINT16 <= range[1])
9025 : {
9026 0 : GDXRegion[regionID]->StopVertical[j] = i;
9027 0 : break;
9028 : }
9029 : }
9030 : }
9031 : else
9032 : {
9033 0 : status = -1;
9034 : }
9035 0 : break;
9036 :
9037 :
9038 0 : case DFNT_INT32:
9039 :
9040 0 : for (i = 0; i < dims[0]; i++)
9041 : {
9042 0 : memcpy(&vertINT32, vertArr + i * size, size);
9043 :
9044 0 : if (vertINT32 >= range[0] &&
9045 0 : vertINT32 <= range[1])
9046 : {
9047 0 : found = 1;
9048 0 : if (regionID == -1)
9049 : {
9050 0 : SETGRIDREG;
9051 : }
9052 0 : FILLVERTREG;
9053 :
9054 0 : break;
9055 : }
9056 : }
9057 :
9058 0 : if (found == 1)
9059 : {
9060 0 : for (i = dims[0] - 1; i >= 0; i--)
9061 : {
9062 0 : memcpy(&vertINT32, vertArr + i * size, size);
9063 :
9064 0 : if (vertINT32 >= range[0] &&
9065 0 : vertINT32 <= range[1])
9066 : {
9067 0 : GDXRegion[regionID]->StopVertical[j] = i;
9068 0 : break;
9069 : }
9070 : }
9071 : }
9072 : else
9073 : {
9074 0 : status = -1;
9075 : }
9076 0 : break;
9077 :
9078 :
9079 0 : case DFNT_FLOAT32:
9080 :
9081 0 : for (i = 0; i < dims[0]; i++)
9082 : {
9083 0 : memcpy(&vertFLT32, vertArr + i * size, size);
9084 :
9085 0 : if (vertFLT32 >= range[0] &&
9086 0 : vertFLT32 <= range[1])
9087 : {
9088 0 : found = 1;
9089 0 : if (regionID == -1)
9090 : {
9091 0 : SETGRIDREG;
9092 : }
9093 0 : FILLVERTREG;
9094 :
9095 0 : break;
9096 : }
9097 : }
9098 :
9099 0 : if (found == 1)
9100 : {
9101 0 : for (i = dims[0] - 1; i >= 0; i--)
9102 : {
9103 0 : memcpy(&vertFLT32, vertArr + i * size, size);
9104 :
9105 0 : if (vertFLT32 >= range[0] &&
9106 0 : vertFLT32 <= range[1])
9107 : {
9108 0 : GDXRegion[regionID]->StopVertical[j] = i;
9109 0 : break;
9110 : }
9111 : }
9112 : }
9113 : else
9114 : {
9115 0 : status = -1;
9116 : }
9117 0 : break;
9118 :
9119 :
9120 0 : case DFNT_FLOAT64:
9121 :
9122 0 : for (i = 0; i < dims[0]; i++)
9123 : {
9124 0 : memcpy(&vertFLT64, vertArr + i * size, size);
9125 :
9126 0 : if (vertFLT64 >= range[0] &&
9127 0 : vertFLT64 <= range[1])
9128 : {
9129 0 : found = 1;
9130 0 : if (regionID == -1)
9131 : {
9132 0 : SETGRIDREG;
9133 : }
9134 0 : FILLVERTREG;
9135 :
9136 0 : break;
9137 : }
9138 : }
9139 :
9140 0 : if (found == 1)
9141 : {
9142 0 : for (i = dims[0] - 1; i >= 0; i--)
9143 : {
9144 0 : memcpy(&vertFLT64, vertArr + i * size, size);
9145 :
9146 0 : if (vertFLT64 >= range[0] &&
9147 0 : vertFLT64 <= range[1])
9148 : {
9149 0 : GDXRegion[regionID]->StopVertical[j] = i;
9150 0 : break;
9151 : }
9152 : }
9153 : }
9154 : else
9155 : {
9156 0 : status = -1;
9157 : }
9158 0 : break;
9159 :
9160 : }
9161 0 : free(vertArr);
9162 : }
9163 : }
9164 : }
9165 : }
9166 0 : if (status == -1)
9167 : {
9168 0 : regionID = -1;
9169 : }
9170 0 : free(dimlist);
9171 0 : return (regionID);
9172 : }
9173 :
9174 :
9175 :
9176 :
9177 :
9178 : /*----------------------------------------------------------------------------|
9179 : | BEGIN_PROLOG |
9180 : | |
9181 : | FUNCTION: GDdeftimeperiod |
9182 : | |
9183 : | DESCRIPTION: Finds elements of the "Time" field within a given time |
9184 : | period. |
9185 : | |
9186 : | |
9187 : | Return Value Type Units Description |
9188 : | ============ ====== ========= ===================================== |
9189 : | periodID int32 Period ID |
9190 : | |
9191 : | INPUTS: |
9192 : | gridID int32 Grid structure ID |
9193 : | periodID int32 Period ID |
9194 : | starttime float64 TAI sec Start of time period |
9195 : | stoptime float64 TAI sec Stop of time period |
9196 : | |
9197 : | OUTPUTS: |
9198 : | None |
9199 : | |
9200 : | NOTES: |
9201 : | |
9202 : | |
9203 : | Date Programmer Description |
9204 : | ====== ============ ================================================= |
9205 : | Aug 96 Joel Gales Original Programmer |
9206 : | |
9207 : | END_PROLOG |
9208 : -----------------------------------------------------------------------------*/
9209 : int32
9210 0 : GDdeftimeperiod(int32 gridID, int32 periodID, float64 starttime,
9211 : float64 stoptime)
9212 : {
9213 : float64 timerange[2];
9214 :
9215 0 : timerange[0] = starttime;
9216 0 : timerange[1] = stoptime;
9217 :
9218 0 : periodID = GDdefvrtregion(gridID, periodID, "Time", timerange);
9219 :
9220 0 : return (periodID);
9221 : }
9222 :
9223 :
9224 :
9225 : /*----------------------------------------------------------------------------|
9226 : | BEGIN_PROLOG |
9227 : | |
9228 : | FUNCTION: GDgetpixels |
9229 : | |
9230 : | DESCRIPTION: Finds row and columns for specified lon/lat values |
9231 : | |
9232 : | |
9233 : | Return Value Type Units Description |
9234 : | ============ ====== ========= ===================================== |
9235 : | status intn return status (0) SUCCEED, (-1) FAIL |
9236 : | |
9237 : | INPUTS: |
9238 : | gridID int32 Grid structure ID |
9239 : | nLonLat int32 Number of lonlat values |
9240 : | lonVal float64 dec deg Longitude values |
9241 : | latVal float64 dec deg Latitude values |
9242 : | |
9243 : | |
9244 : | OUTPUTS: |
9245 : | pixRow int32 Pixel rows |
9246 : | pixCol int32 Pixel columns |
9247 : | |
9248 : | NOTES: |
9249 : | |
9250 : | |
9251 : | Date Programmer Description |
9252 : | ====== ============ ================================================= |
9253 : | Aug 96 Joel Gales Original Programmer |
9254 : | Oct 96 Joel Gales Set row/col to -1 if outside boundary |
9255 : | Mar 97 Joel Gales Adjust row/col for CORNER pixel registration |
9256 : | |
9257 : | END_PROLOG |
9258 : -----------------------------------------------------------------------------*/
9259 : intn
9260 0 : GDgetpixels(int32 gridID, int32 nLonLat, float64 lonVal[], float64 latVal[],
9261 : int32 pixRow[], int32 pixCol[])
9262 : {
9263 : intn i; /* Loop index */
9264 0 : intn status = 0; /* routine return status variable */
9265 :
9266 : int32 fid; /* HDF-EOS file ID */
9267 : int32 sdInterfaceID; /* HDF SDS interface ID */
9268 : int32 gdVgrpID; /* Grid root Vgroup ID */
9269 :
9270 : int32 xdimsize; /* Size of "XDim" */
9271 : int32 ydimsize; /* Size of "YDim" */
9272 : int32 projcode; /* GCTP projection code */
9273 : int32 zonecode; /* Zone code */
9274 : int32 spherecode; /* Sphere code */
9275 : int32 origincode; /* Origin code */
9276 : int32 pixregcode; /* Pixel registration code */
9277 :
9278 : float64 upleftpt[2];/* Upper left point */
9279 : float64 lowrightpt[2]; /* Lower right point */
9280 : float64 projparm[16]; /* Projection parameters */
9281 : float64 *xVal; /* Pointer to point x location values */
9282 : float64 *yVal; /* Pointer to point y location values */
9283 :
9284 :
9285 : /* Check for valid grid ID */
9286 : /* ----------------------- */
9287 0 : status = GDchkgdid(gridID, "GDgetpixels", &fid, &sdInterfaceID, &gdVgrpID);
9288 :
9289 0 : if (status == 0)
9290 : {
9291 : /* Get grid info */
9292 : /* ------------- */
9293 0 : status = GDgridinfo(gridID, &xdimsize, &ydimsize,
9294 : upleftpt, lowrightpt);
9295 :
9296 :
9297 : /* Get projection info */
9298 : /* ------------------- */
9299 0 : status = GDprojinfo(gridID, &projcode, &zonecode,
9300 : &spherecode, projparm);
9301 :
9302 :
9303 : /* Get explicit upleftpt & lowrightpt if defaults are used */
9304 : /* ------------------------------------------------------- */
9305 0 : status = GDgetdefaults(projcode, zonecode, projparm, spherecode,
9306 : upleftpt, lowrightpt);
9307 :
9308 :
9309 : /* Get pixel registration and origin info */
9310 : /* -------------------------------------- */
9311 0 : status = GDorigininfo(gridID, &origincode);
9312 0 : status = GDpixreginfo(gridID, &pixregcode);
9313 :
9314 :
9315 : /* Allocate space for x & y locations */
9316 : /* ---------------------------------- */
9317 0 : xVal = (float64 *) calloc(nLonLat, sizeof(float64));
9318 0 : if(xVal == NULL)
9319 : {
9320 0 : HEpush(DFE_NOSPACE,"GDgetpixels", __FILE__, __LINE__);
9321 0 : return(-1);
9322 : }
9323 0 : yVal = (float64 *) calloc(nLonLat, sizeof(float64));
9324 0 : if(yVal == NULL)
9325 : {
9326 0 : HEpush(DFE_NOSPACE,"GDgetpixels", __FILE__, __LINE__);
9327 0 : free(xVal);
9328 0 : return(-1);
9329 : }
9330 :
9331 :
9332 : /* Get pixRow, pixCol, xVal, & yVal */
9333 : /* -------------------------------- */
9334 0 : status = GDll2ij(projcode, zonecode, projparm, spherecode,
9335 : xdimsize, ydimsize, upleftpt, lowrightpt,
9336 : nLonLat, lonVal, latVal, pixRow, pixCol,
9337 : xVal, yVal);
9338 :
9339 :
9340 :
9341 : /* Loop through all lon/lat values */
9342 : /* ------------------------------- */
9343 0 : for (i = 0; i < nLonLat; i++)
9344 : {
9345 : /* Adjust columns & rows for "corner" registered grids */
9346 : /* --------------------------------------------------- */
9347 0 : if (pixregcode == HDFE_CORNER)
9348 : {
9349 0 : if (origincode == HDFE_GD_UL)
9350 : {
9351 0 : if (xVal[i] - pixCol[i] > 0.5)
9352 : {
9353 0 : ++pixCol[i];
9354 : }
9355 :
9356 0 : if (yVal[i] - pixRow[i] > 0.5)
9357 : {
9358 0 : ++pixRow[i];
9359 : }
9360 : }
9361 0 : else if (origincode == HDFE_GD_UR)
9362 : {
9363 0 : if (xVal[i] - pixCol[i] <= 0.5)
9364 : {
9365 0 : --pixCol[i];
9366 : }
9367 :
9368 0 : if (yVal[i] - pixRow[i] > 0.5)
9369 : {
9370 0 : ++pixRow[i];
9371 : }
9372 : }
9373 0 : else if (origincode == HDFE_GD_LL)
9374 : {
9375 0 : if (xVal[i] - pixCol[i] > 0.5)
9376 : {
9377 0 : ++pixCol[i];
9378 : }
9379 :
9380 0 : if (yVal[i] - pixRow[i] <= 0.5)
9381 : {
9382 0 : --pixRow[i];
9383 : }
9384 : }
9385 0 : else if (origincode == HDFE_GD_LR)
9386 : {
9387 0 : if (xVal[i] - pixCol[i] <= 0.5)
9388 : {
9389 0 : --pixCol[i];
9390 : }
9391 :
9392 0 : if (yVal[i] - pixRow[i] <= 0.5)
9393 : {
9394 0 : --pixRow[i];
9395 : }
9396 : }
9397 : }
9398 :
9399 :
9400 : /* If outside grid boundaries then set to -1 */
9401 : /* ----------------------------------------- */
9402 0 : if (pixCol[i] < 0 || pixCol[i] >= xdimsize ||
9403 0 : pixRow[i] < 0 || pixRow[i] >= ydimsize)
9404 : {
9405 0 : pixCol[i] = -1;
9406 0 : pixRow[i] = -1;
9407 : }
9408 : }
9409 0 : free(xVal);
9410 0 : free(yVal);
9411 : }
9412 0 : return (status);
9413 : }
9414 :
9415 :
9416 :
9417 :
9418 :
9419 : /*----------------------------------------------------------------------------|
9420 : | BEGIN_PROLOG |
9421 : | |
9422 : | FUNCTION: GDgetpixvalues |
9423 : | |
9424 : | DESCRIPTION: Retrieves data from specified pixels. |
9425 : | |
9426 : | |
9427 : | Return Value Type Units Description |
9428 : | ============ ====== ========= ===================================== |
9429 : | size*nPixels int32 Size of data buffer |
9430 : | |
9431 : | INPUTS: |
9432 : | gridID int32 Grid structure ID |
9433 : | nPixels int32 Number of pixels |
9434 : | pixRow int32 Pixel row numbers |
9435 : | pixCol int32 Pixel column numbers |
9436 : | fieldname char Fieldname |
9437 : | |
9438 : | OUTPUTS: |
9439 : | buffer void Data buffer |
9440 : | |
9441 : | |
9442 : | NOTES: |
9443 : | |
9444 : | |
9445 : | Date Programmer Description |
9446 : | ====== ============ ================================================= |
9447 : | Aug 96 Joel Gales Original Programmer |
9448 : | Oct 96 Joel Gales Check for pixels outside boundaries (-1) |
9449 : | Mar 98 Abe Taaheri revised to reduce overhead for rechecking |
9450 : | for gridid, fieldname, etc in GDreadfield. |
9451 : | June 98 AT fixed bug with 2-dim field merged in 3-dim field |
9452 : | (for offset and count) |
9453 : | END_PROLOG |
9454 : -----------------------------------------------------------------------------*/
9455 : int32
9456 0 : GDgetpixvalues(int32 gridID, int32 nPixels, int32 pixRow[], int32 pixCol[],
9457 : const char *fieldname, VOIDP buffer)
9458 : {
9459 : intn i; /* Loop index */
9460 : intn j; /* Loop index */
9461 0 : intn status = 0; /* routine return status variable */
9462 :
9463 : int32 fid; /* HDF-EOS file ID */
9464 : int32 sdInterfaceID; /* HDF SDS interface ID */
9465 : int32 gdVgrpID; /* Grid root Vgroup ID */
9466 :
9467 : int32 start[8]; /* GDreadfield start array */
9468 : int32 edge[8]; /* GDreadfield edge array */
9469 : int32 dims[8]; /* Field dimensions */
9470 : int32 rank; /* Field rank */
9471 0 : int32 xdum = 0; /* Location of "XDim" within field list */
9472 0 : int32 ydum = 0; /* Location of "YDim" within field list */
9473 : int32 ntype; /* Field number type */
9474 : int32 origincode; /* Origin code */
9475 : int32 bufOffset; /* Data buffer offset */
9476 0 : int32 size = 0; /* Size of returned data buffer for each
9477 : * value in bytes */
9478 : int32 offset[8]; /* I/O offset (start) */
9479 : int32 incr[8]; /* I/O increment (stride) */
9480 : int32 count[8]; /* I/O count (edge) */
9481 : int32 sdid; /* SDS ID */
9482 : int32 rankSDS; /* Rank of SDS */
9483 : int32 rankFld; /* Rank of field */
9484 : int32 dum; /* Dummy variable */
9485 : int32 mrgOffset; /* Merged field offset */
9486 :
9487 : char *dimlist; /* Dimension list */
9488 :
9489 :
9490 :
9491 : /* Allocate space for dimlist */
9492 : /* --------------------------------- */
9493 0 : dimlist = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
9494 0 : if(dimlist == NULL)
9495 : {
9496 0 : HEpush(DFE_NOSPACE,"GDgetpixvalues", __FILE__, __LINE__);
9497 0 : return(-1);
9498 : }
9499 : /* Check for valid grid ID */
9500 : /* ----------------------- */
9501 0 : status = GDchkgdid(gridID, "GDgetpixvalues",
9502 : &fid, &sdInterfaceID, &gdVgrpID);
9503 :
9504 :
9505 0 : if (status == 0)
9506 : {
9507 : /* Get field list */
9508 : /* -------------- */
9509 0 : status = GDfieldinfo(gridID, fieldname, &rank, dims, &ntype, dimlist);
9510 :
9511 :
9512 : /* Check for "XDim" & "YDim" in dimension list */
9513 : /* ------------------------------------------- */
9514 0 : if (status == 0)
9515 : {
9516 0 : xdum = EHstrwithin("XDim", dimlist, ',');
9517 0 : ydum = EHstrwithin("YDim", dimlist, ',');
9518 :
9519 0 : if (xdum == -1)
9520 : {
9521 0 : status = -1;
9522 0 : HEpush(DFE_GENAPP, "GDgetpixvalues", __FILE__, __LINE__);
9523 0 : HEreport(
9524 : "\"XDim\" not present in dimlist for field: \"%s\".\n",
9525 : fieldname);
9526 : }
9527 :
9528 :
9529 0 : if (ydum == -1)
9530 : {
9531 0 : status = -1;
9532 0 : HEpush(DFE_GENAPP, "GDgetpixvalues", __FILE__, __LINE__);
9533 0 : HEreport(
9534 : "\"YDim\" not present in dimlist for field: \"%s\".\n",
9535 : fieldname);
9536 : }
9537 : }
9538 : else
9539 : {
9540 0 : status = -1;
9541 0 : HEpush(DFE_GENAPP, "GDgetpixvalues", __FILE__, __LINE__);
9542 0 : HEreport("Fieldname \"%s\" not found.\n", fieldname);
9543 : }
9544 :
9545 :
9546 0 : if (status == 0)
9547 : {
9548 :
9549 : /* Get origin order info */
9550 : /* --------------------- */
9551 0 : status = GDorigininfo(gridID, &origincode);
9552 :
9553 :
9554 : /* Initialize start & edge arrays */
9555 : /* ------------------------------ */
9556 0 : for (i = 0; i < rank; i++)
9557 : {
9558 0 : start[i] = 0;
9559 0 : edge[i] = dims[i];
9560 : }
9561 :
9562 :
9563 : /* Compute size of data buffer for each pixel */
9564 : /* ------------------------------------------ */
9565 0 : edge[xdum] = 1;
9566 0 : edge[ydum] = 1;
9567 0 : size = edge[0];
9568 0 : for (j = 1; j < rank; j++)
9569 : {
9570 0 : size *= edge[j];
9571 : }
9572 0 : size *= DFKNTsize(ntype);
9573 :
9574 :
9575 :
9576 : /* If data values are requested ... */
9577 : /* -------------------------------- */
9578 0 : if (buffer != NULL)
9579 : {
9580 : /* get sdid */
9581 0 : status = GDSDfldsrch(gridID, sdInterfaceID, fieldname, &sdid,
9582 : &rankSDS, &rankFld, &mrgOffset, dims, &dum);
9583 :
9584 : /* Loop through all pixels */
9585 : /* ----------------------- */
9586 0 : for (i = 0; i < nPixels; i++)
9587 : {
9588 : /* Conmpute offset within returned data buffer */
9589 : /* ------------------------------------------- */
9590 0 : bufOffset = size * i;
9591 :
9592 :
9593 : /* If pixel row & column OK ... */
9594 : /* ---------------------------- */
9595 0 : if (pixCol[i] != -1 && pixRow[i] != -1)
9596 : {
9597 0 : start[xdum] = pixCol[i];
9598 0 : start[ydum] = pixRow[i];
9599 :
9600 :
9601 : /* Adjust X-dim start if origin on right edge */
9602 : /* ------------------------------------------ */
9603 0 : if ((origincode & 1) == 1)
9604 : {
9605 0 : start[xdum] = dims[xdum] - (start[xdum] + 1);
9606 : }
9607 :
9608 :
9609 : /* Adjust Y-dim start if origin on lower edge */
9610 : /* ------------------------------------------ */
9611 0 : if ((origincode & 2) == 2)
9612 : {
9613 0 : start[ydum] = dims[ydum] - (start[ydum] + 1);
9614 : }
9615 :
9616 : /* Set I/O offset and count Section */
9617 : /* ---------------------- */
9618 :
9619 : /*
9620 : * start and edge != NULL, set I/O offset and count to
9621 : * user values, adjusting the
9622 : * 0th field with the merged field offset (if any)
9623 : */
9624 0 : if (rankFld == rankSDS)
9625 : {
9626 0 : for (j = 0; j < rankSDS; j++)
9627 : {
9628 0 : offset[j] = start[j];
9629 0 : count[j] = edge[j];
9630 : }
9631 0 : offset[0] += mrgOffset;
9632 : }
9633 : else
9634 : {
9635 : /*
9636 : * If field really 2-dim merged in 3-dim field then set
9637 : * 0th field offset to merge offset and then next two to
9638 : * the user values
9639 : */
9640 0 : for (j = 0; j < rankFld; j++)
9641 : {
9642 0 : offset[j + 1] = start[j];
9643 0 : count[j + 1] = edge[j];
9644 : }
9645 0 : offset[0] = mrgOffset;
9646 0 : count[0] = 1;
9647 : }
9648 :
9649 :
9650 :
9651 : /* Set I/O stride Section */
9652 : /* ---------------------- */
9653 :
9654 : /* In original code stride entered as NULL.
9655 : Abe Taaheri June 12, 1998 */
9656 : /*
9657 : * If stride == NULL (default) set I/O stride to 1
9658 : */
9659 0 : for (j = 0; j < rankSDS; j++)
9660 : {
9661 0 : incr[j] = 1;
9662 : }
9663 :
9664 :
9665 : /* Read into data buffer */
9666 : /* --------------------- */
9667 0 : status = SDreaddata(sdid,
9668 : offset, incr, count,
9669 : (VOIDP) ((uint8 *) buffer + bufOffset));
9670 : }
9671 : }
9672 : }
9673 : }
9674 : }
9675 :
9676 :
9677 : /* If successful return size of returned data in bytes */
9678 : /* --------------------------------------------------- */
9679 0 : if (status == 0)
9680 : {
9681 0 : free(dimlist);
9682 0 : return (size * nPixels);
9683 : }
9684 : else
9685 : {
9686 0 : free(dimlist);
9687 0 : return ((int32) status);
9688 : }
9689 : }
9690 :
9691 :
9692 : /*----------------------------------------------------------------------------|
9693 : | BEGIN_PROLOG |
9694 : | |
9695 : | FUNCTION: GDinterpolate |
9696 : | |
9697 : | DESCRIPTION: Performs bilinear interpolate on a set of xy values |
9698 : | |
9699 : | |
9700 : | Return Value Type Units Description |
9701 : | ============ ====== ========= ===================================== |
9702 : | nRetn*nValues* int32 Size of data buffer |
9703 : | sizeof(float64) |
9704 : | |
9705 : | INPUTS: |
9706 : | gridID int32 Grid structure ID |
9707 : | nValues int32 Number of lon/lat points to interpolate |
9708 : | xyValues float64 XY values of points to interpolate |
9709 : | fieldname char Fieldname |
9710 : | |
9711 : | OUTPUTS: |
9712 : | interpVal float64 Interpolated Data Values |
9713 : | |
9714 : | |
9715 : | NOTES: |
9716 : | |
9717 : | |
9718 : | Date Programmer Description |
9719 : | ====== ============ ================================================= |
9720 : | Aug 96 Joel Gales Original Programmer |
9721 : | Oct 96 Joel Gales Fix array l_index problem with interpVal write |
9722 : | Apr 97 Joel Gales Trap interpolation boundary out of bounds error |
9723 : | Jun 98 Abe Taaheri changed the return value so that the Return Value |
9724 : | is size in bytes for the data buffer which is |
9725 : | float64.
9726 : | |
9727 : | END_PROLOG |
9728 : -----------------------------------------------------------------------------*/
9729 : int32
9730 0 : GDinterpolate(int32 gridID, int32 nValues, float64 lonVal[], float64 latVal[],
9731 : const char *fieldname, float64 interpVal[])
9732 : {
9733 : intn i; /* Loop index */
9734 : intn j; /* Loop index */
9735 : intn k; /* Loop index */
9736 0 : intn status = 0; /* routine return status variable */
9737 :
9738 : int32 fid; /* HDF-EOS file ID */
9739 : int32 sdInterfaceID; /* HDF SDS interface ID */
9740 : int32 gdVgrpID; /* Grid root Vgroup ID */
9741 : int32 xdimsize; /* XDim size */
9742 : int32 ydimsize; /* YDim size */
9743 : int32 projcode; /* Projection code */
9744 : int32 zonecode; /* Zone code */
9745 : int32 spherecode; /* Sphere code */
9746 : int32 pixregcode; /* Pixel registration code */
9747 : int32 origincode; /* Origin code */
9748 : int32 dims[8]; /* Field dimensions */
9749 : int32 numsize; /* Size in bytes of number type */
9750 : int32 rank; /* Field rank */
9751 0 : int32 xdum = 0; /* Location of "XDim" within field list */
9752 0 : int32 ydum = 0; /* Location of "YDim" within field list */
9753 : int32 ntype; /* Number type */
9754 : int32 dum; /* Dummy variable */
9755 : int32 size; /* Size of returned data buffer for each
9756 : * value in bytes */
9757 : int32 pixCol[4]; /* Pixel columns for 4 nearest neighbors */
9758 : int32 pixRow[4]; /* Pixel rows for 4 nearest neighbors */
9759 : int32 tDen; /* Interpolation denominator value 1 */
9760 : int32 uDen; /* Interpolation denominator value 2 */
9761 0 : int32 nRetn = 0; /* Number of data values returned */
9762 :
9763 : float64 upleftpt[2];/* Upper left pt coordinates */
9764 : float64 lowrightpt[2]; /* Lower right pt coordinates */
9765 : float64 projparm[16]; /* Projection parameters */
9766 0 : float64 xVal = 0.0; /* "Exact" x location of interpolated point */
9767 0 : float64 yVal = 0.0; /* "Exact" y location of interpolated point */
9768 0 : float64 tNum = 0.0; /* Interpolation numerator value 1 */
9769 0 : float64 uNum = 0.0; /* Interpolation numerator value 2 */
9770 :
9771 : int16 i16[4]; /* Working buffer (int16) */
9772 : int32 i32[4]; /* Working buffer (int132) */
9773 : float32 f32[4]; /* Working buffer (float32) */
9774 : float64 f64[4]; /* Working buffer (float64) */
9775 :
9776 : char *pixVal; /* Nearest neighbor values */
9777 : char *dimlist; /* Dimension list */
9778 :
9779 : /* Allocate space for dimlist */
9780 : /* --------------------------------- */
9781 0 : dimlist = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
9782 0 : if(dimlist == NULL)
9783 : {
9784 0 : HEpush(DFE_NOSPACE,"GDinterpolate", __FILE__, __LINE__);
9785 0 : return(-1);
9786 : }
9787 : /* Check for valid grid ID */
9788 : /* ----------------------- */
9789 0 : status = GDchkgdid(gridID, "GDinterpolate",
9790 : &fid, &sdInterfaceID, &gdVgrpID);
9791 :
9792 :
9793 : /* If no problems ... */
9794 : /* ------------------ */
9795 0 : if (status == 0)
9796 : {
9797 : /* Get field information */
9798 : /* --------------------- */
9799 0 : status = GDfieldinfo(gridID, fieldname, &rank, dims, &ntype, dimlist);
9800 :
9801 :
9802 : /* Check for "XDim" & "YDim" in dimension list */
9803 : /* ------------------------------------------- */
9804 0 : if (status == 0)
9805 : {
9806 0 : xdum = EHstrwithin("XDim", dimlist, ',');
9807 0 : ydum = EHstrwithin("YDim", dimlist, ',');
9808 :
9809 0 : if (xdum == -1)
9810 : {
9811 0 : status = -1;
9812 0 : HEpush(DFE_GENAPP, "GDinterpolate", __FILE__, __LINE__);
9813 0 : HEreport(
9814 : "\"XDim\" not present in dimlist for field: \"%s\".\n",
9815 : fieldname);
9816 : }
9817 :
9818 :
9819 0 : if (ydum == -1)
9820 : {
9821 0 : status = -1;
9822 0 : HEpush(DFE_GENAPP, "GDinterpolate", __FILE__, __LINE__);
9823 0 : HEreport(
9824 : "\"YDim\" not present in dimlist for field: \"%s\".\n",
9825 : fieldname);
9826 : }
9827 : }
9828 : else
9829 : {
9830 : /* Fieldname not found in grid */
9831 : /* --------------------------- */
9832 0 : status = -1;
9833 0 : HEpush(DFE_GENAPP, "GDinterpolate", __FILE__, __LINE__);
9834 0 : HEreport("Fieldname \"%s\" not found.\n", fieldname);
9835 : }
9836 :
9837 :
9838 : /* If no problems ... */
9839 : /* ------------------ */
9840 0 : if (status == 0)
9841 : {
9842 : /* Compute size of data buffer for each interpolated value */
9843 : /* ------------------------------------------------------- */
9844 0 : dims[xdum] = 1;
9845 0 : dims[ydum] = 1;
9846 0 : size = dims[0];
9847 0 : for (i = 1; i < rank; i++)
9848 : {
9849 0 : size *= dims[i];
9850 : }
9851 0 : numsize = DFKNTsize(ntype);
9852 0 : size *= numsize;
9853 :
9854 0 : nRetn = size / numsize;
9855 :
9856 :
9857 :
9858 : /* If interpolated values are requested ... */
9859 : /* ---------------------------------------- */
9860 0 : if (interpVal != NULL)
9861 : {
9862 : /* Get grid info */
9863 : /* ------------- */
9864 0 : status = GDgridinfo(gridID, &xdimsize, &ydimsize,
9865 : upleftpt, lowrightpt);
9866 :
9867 :
9868 : /* Get projection info */
9869 : /* ------------------- */
9870 0 : status = GDprojinfo(gridID, &projcode, &zonecode,
9871 : &spherecode, projparm);
9872 :
9873 :
9874 : /* Get explicit upleftpt & lowrightpt if defaults are used */
9875 : /* ------------------------------------------------------- */
9876 0 : status = GDgetdefaults(projcode, zonecode, projparm,
9877 : spherecode, upleftpt, lowrightpt);
9878 :
9879 :
9880 : /* Get pixel registration and origin info */
9881 : /* -------------------------------------- */
9882 0 : status = GDpixreginfo(gridID, &pixregcode);
9883 0 : status = GDorigininfo(gridID, &origincode);
9884 :
9885 :
9886 :
9887 : /* Loop through all interpolated points */
9888 : /* ------------------------------------ */
9889 0 : for (i = 0; i < nValues; i++)
9890 : {
9891 : /* Get row & column of point pixel */
9892 : /* ------------------------------- */
9893 0 : status = GDll2ij(projcode, zonecode, projparm, spherecode,
9894 : xdimsize, ydimsize, upleftpt, lowrightpt,
9895 0 : 1, &lonVal[i], &latVal[i],
9896 : pixRow, pixCol, &xVal, &yVal);
9897 :
9898 :
9899 : /* Get diff of interp. point from pixel location */
9900 : /* --------------------------------------------- */
9901 0 : if (pixregcode == HDFE_CENTER)
9902 : {
9903 0 : tNum = xVal - (pixCol[0] + 0.5);
9904 0 : uNum = yVal - (pixRow[0] + 0.5);
9905 : }
9906 0 : else if (origincode == HDFE_GD_UL)
9907 : {
9908 0 : tNum = xVal - pixCol[0];
9909 0 : uNum = yVal - pixRow[0];
9910 : }
9911 0 : else if (origincode == HDFE_GD_UR)
9912 : {
9913 0 : tNum = xVal - (pixCol[0] + 1);
9914 0 : uNum = yVal - pixRow[0];
9915 : }
9916 0 : else if (origincode == HDFE_GD_LL)
9917 : {
9918 0 : tNum = xVal - pixCol[0];
9919 0 : uNum = yVal - (pixRow[0] + 1);
9920 : }
9921 0 : else if (origincode == HDFE_GD_LR)
9922 : {
9923 0 : tNum = xVal - (pixCol[0] + 1);
9924 0 : uNum = yVal - (pixRow[0] + 1);
9925 : }
9926 :
9927 :
9928 : /* Get rows and columns of other nearest neighbor pixels */
9929 : /* ----------------------------------------------------- */
9930 0 : pixCol[1] = pixCol[0];
9931 0 : pixRow[3] = pixRow[0];
9932 :
9933 0 : if (tNum >= 0)
9934 : {
9935 0 : pixCol[2] = pixCol[0] + 1;
9936 0 : pixCol[3] = pixCol[0] + 1;
9937 : }
9938 :
9939 0 : if (tNum < 0)
9940 : {
9941 0 : pixCol[2] = pixCol[0] - 1;
9942 0 : pixCol[3] = pixCol[0] - 1;
9943 : }
9944 :
9945 0 : if (uNum >= 0)
9946 : {
9947 0 : pixRow[2] = pixRow[0] + 1;
9948 0 : pixRow[1] = pixRow[0] + 1;
9949 : }
9950 :
9951 0 : if (uNum < 0)
9952 : {
9953 0 : pixRow[2] = pixRow[0] - 1;
9954 0 : pixRow[1] = pixRow[0] - 1;
9955 : }
9956 :
9957 :
9958 : /* Get values of nearest neighbors */
9959 : /* -------------------------------- */
9960 0 : pixVal = (char *) malloc(4 * size);
9961 0 : if(pixVal == NULL)
9962 : {
9963 0 : HEpush(DFE_NOSPACE,"GDinterpolate", __FILE__, __LINE__);
9964 0 : free(dimlist);
9965 0 : return(-1);
9966 : }
9967 0 : dum = GDgetpixvalues(gridID, 4, pixRow, pixCol,
9968 : fieldname, pixVal);
9969 :
9970 :
9971 : /* Trap interpolation boundary out of range error */
9972 : /* ---------------------------------------------- */
9973 0 : if (dum == -1)
9974 : {
9975 0 : status = -1;
9976 0 : HEpush(DFE_GENAPP, "GDinterpolate", __FILE__, __LINE__);
9977 0 : HEreport("Interpolation boundary outside of grid.\n");
9978 : }
9979 : else
9980 : {
9981 :
9982 : /*
9983 : * Algorithm taken for Numerical Recipes in C, 2nd
9984 : * edition, Section 3.6
9985 : */
9986 :
9987 : /* Perform bilinear interpolation */
9988 : /* ------------------------------ */
9989 0 : tDen = pixCol[3] - pixCol[0];
9990 0 : uDen = pixRow[1] - pixRow[0];
9991 :
9992 0 : switch (ntype)
9993 : {
9994 0 : case DFNT_INT16:
9995 :
9996 :
9997 : /* Loop through all returned data values */
9998 : /* ------------------------------------- */
9999 0 : for (j = 0; j < nRetn; j++)
10000 : {
10001 : /* Copy 4 NN values into working array */
10002 : /* ----------------------------------- */
10003 0 : for (k = 0; k < 4; k++)
10004 : {
10005 0 : memcpy(&i16[k],
10006 0 : pixVal + j * numsize + k * size,
10007 : sizeof(int16));
10008 : }
10009 :
10010 : /* Compute interpolated value */
10011 : /* -------------------------- */
10012 0 : interpVal[i * nRetn + j] =
10013 0 : (1 - tNum / tDen) * (1 - uNum / uDen) *
10014 0 : i16[0] +
10015 0 : (tNum / tDen) * (1 - uNum / uDen) *
10016 0 : i16[3] +
10017 0 : (tNum / tDen) * (uNum / uDen) *
10018 0 : i16[2] +
10019 0 : (1 - tNum / tDen) * (uNum / uDen) *
10020 0 : i16[1];
10021 : }
10022 0 : break;
10023 :
10024 :
10025 0 : case DFNT_INT32:
10026 :
10027 0 : for (j = 0; j < nRetn; j++)
10028 : {
10029 0 : for (k = 0; k < 4; k++)
10030 : {
10031 0 : memcpy(&i32[k],
10032 0 : pixVal + j * numsize + k * size,
10033 : sizeof(int32));
10034 : }
10035 :
10036 0 : interpVal[i * nRetn + j] =
10037 0 : (1 - tNum / tDen) * (1 - uNum / uDen) *
10038 0 : i32[0] +
10039 0 : (tNum / tDen) * (1 - uNum / uDen) *
10040 0 : i32[3] +
10041 0 : (tNum / tDen) * (uNum / uDen) *
10042 0 : i32[2] +
10043 0 : (1 - tNum / tDen) * (uNum / uDen) *
10044 0 : i32[1];
10045 : }
10046 0 : break;
10047 :
10048 :
10049 0 : case DFNT_FLOAT32:
10050 :
10051 0 : for (j = 0; j < nRetn; j++)
10052 : {
10053 0 : for (k = 0; k < 4; k++)
10054 : {
10055 0 : memcpy(&f32[k],
10056 0 : pixVal + j * numsize + k * size,
10057 : sizeof(float32));
10058 : }
10059 :
10060 0 : interpVal[i * nRetn + j] =
10061 0 : (1 - tNum / tDen) * (1 - uNum / uDen) *
10062 0 : f32[0] +
10063 0 : (tNum / tDen) * (1 - uNum / uDen) *
10064 0 : f32[3] +
10065 0 : (tNum / tDen) * (uNum / uDen) *
10066 0 : f32[2] +
10067 0 : (1 - tNum / tDen) * (uNum / uDen) *
10068 0 : f32[1];
10069 : }
10070 0 : break;
10071 :
10072 :
10073 0 : case DFNT_FLOAT64:
10074 :
10075 0 : for (j = 0; j < nRetn; j++)
10076 : {
10077 0 : for (k = 0; k < 4; k++)
10078 : {
10079 0 : memcpy(&f64[k],
10080 0 : pixVal + j * numsize + k * size,
10081 : sizeof(float64));
10082 : }
10083 :
10084 0 : interpVal[i * nRetn + j] =
10085 0 : (1 - tNum / tDen) * (1 - uNum / uDen) *
10086 0 : f64[0] +
10087 0 : (tNum / tDen) * (1 - uNum / uDen) *
10088 0 : f64[3] +
10089 0 : (tNum / tDen) * (uNum / uDen) *
10090 0 : f64[2] +
10091 0 : (1 - tNum / tDen) * (uNum / uDen) *
10092 0 : f64[1];
10093 : }
10094 0 : break;
10095 : }
10096 0 : }
10097 0 : free(pixVal);
10098 : }
10099 : }
10100 : }
10101 : }
10102 :
10103 :
10104 : /* If successful return size of returned data in bytes */
10105 : /* --------------------------------------------------- */
10106 0 : if (status == 0)
10107 : {
10108 : /*always return size of float64 buffer */
10109 0 : free(dimlist);
10110 0 : return (nRetn * nValues * sizeof(float64));
10111 : }
10112 : else
10113 : {
10114 0 : free(dimlist);
10115 0 : return ((int32) status);
10116 : }
10117 :
10118 : }
10119 : /***********************************************
10120 : GDwrrdtile --
10121 : This function is the underlying function below GDwritetile and
10122 : GDreadtile.
10123 :
10124 :
10125 : Author--
10126 : Alexis Zubrow
10127 :
10128 : ********************************************************/
10129 :
10130 : static intn
10131 0 : GDwrrdtile(int32 gridID, const char *fieldname, const char *code, int32 start[],
10132 : VOIDP datbuf)
10133 : {
10134 : intn i; /* Loop index */
10135 0 : intn status = 0; /* routine return status variable */
10136 :
10137 : int32 fid; /* HDF-EOS file ID */
10138 : int32 sdInterfaceID; /* HDF SDS interface ID */
10139 : int32 sdid; /* SDS ID */
10140 :
10141 : int32 dum; /* Dummy variable */
10142 : int32 rankSDS; /* Rank of SDS/Field */
10143 :
10144 : int32 dims[8]; /* Field/SDS dimensions */
10145 : int32 tileFlags; /* flag to determine if field is tiled */
10146 : int32 numTileDims;/* number of tiles spanning a dimension */
10147 : HDF_CHUNK_DEF tileDef; /* union holding tiling info. */
10148 :
10149 :
10150 : /* Get gridID */
10151 0 : status = GDchkgdid(gridID, "GDwrrdtile", &fid, &sdInterfaceID, &dum);
10152 0 : if (status == 0)
10153 : {
10154 :
10155 : /* Get field info */
10156 0 : status = GDfieldinfo(gridID, fieldname, &rankSDS, dims, &dum, NULL);
10157 :
10158 0 : if (status == 0)
10159 : {
10160 :
10161 : /* Check whether fieldname is in SDS (multi-dim field) */
10162 : /* --------------------------------------------------- */
10163 0 : status = GDSDfldsrch(gridID, sdInterfaceID, fieldname, &sdid,
10164 : &rankSDS, &dum, &dum, dims, &dum);
10165 :
10166 :
10167 :
10168 : /*
10169 : * Check for errors in parameters passed to GDwritetile or
10170 : * GDreadtile
10171 : */
10172 :
10173 : /* Check if untiled field */
10174 0 : status = SDgetchunkinfo(sdid, &tileDef, &tileFlags);
10175 0 : if (tileFlags == HDF_NONE)
10176 : {
10177 0 : HEpush(DFE_GENAPP, "GDwrrdtile", __FILE__, __LINE__);
10178 0 : HEreport("Field \"%s\" is not tiled.\n", fieldname);
10179 0 : status = -1;
10180 0 : return (status);
10181 :
10182 : }
10183 :
10184 : /*
10185 : * Check if rd/wr tilecoords are within the extent of the field
10186 : */
10187 0 : for (i = 0; i < rankSDS; i++)
10188 : {
10189 : /*
10190 : * Calculate the number of tiles which span a dimension of
10191 : * the field
10192 : */
10193 0 : numTileDims = dims[i] / tileDef.chunk_lengths[i];
10194 0 : if ((start[i] >= numTileDims) || (start[i] < 0))
10195 : {
10196 : /*
10197 : * ERROR INDICATING BEYOND EXTENT OF THAT DIMENSION OR
10198 : * NEGATIVE TILECOORDS
10199 : */
10200 0 : HEpush(DFE_GENAPP, "GDwrrdtile", __FILE__, __LINE__);
10201 0 : HEreport("Tilecoords for dimension \"%d\" ...\n", i);
10202 0 : HEreport("is beyond the extent of dimension length\n");
10203 0 : status = -1;
10204 :
10205 : }
10206 : }
10207 :
10208 0 : if (status == -1)
10209 : {
10210 0 : return (status);
10211 : }
10212 :
10213 :
10214 : /* Actually write/read to the field */
10215 :
10216 0 : if (strcmp(code, "w") == 0) /* write tile */
10217 : {
10218 0 : status = SDwritechunk(sdid, start, (VOIDP) datbuf);
10219 : }
10220 0 : else if (strcmp(code, "r") == 0) /* read tile */
10221 : {
10222 0 : status = SDreadchunk(sdid, start, (VOIDP) datbuf);
10223 : }
10224 :
10225 :
10226 : }
10227 :
10228 : /* Non-existent fieldname */
10229 : else
10230 : {
10231 0 : HEpush(DFE_GENAPP, "GDwrrdtile", __FILE__, __LINE__);
10232 0 : HEreport("Fieldname \"%s\" does not exist.\n", fieldname);
10233 0 : status = -1;
10234 : }
10235 :
10236 : }
10237 :
10238 0 : return (status);
10239 : }
10240 :
10241 :
10242 : /***********************************************
10243 : GDtileinfo --
10244 : This function queries the field to determine if it is tiled. If it is
10245 : tile, one can retrieve some of the characteristics of the tiles.
10246 :
10247 : Author-- Alexis Zubrow
10248 :
10249 : ********************************************************/
10250 :
10251 :
10252 : intn
10253 0 : GDtileinfo(int32 gridID, const char *fieldname, int32 * tilecode, int32 * tilerank,
10254 : int32 tiledims[])
10255 :
10256 : {
10257 : intn i; /* Loop index */
10258 0 : intn status = 0; /* routine return status variable */
10259 :
10260 : int32 fid; /* HDF-EOS file ID */
10261 : int32 sdInterfaceID; /* HDF SDS interface ID */
10262 : int32 sdid; /* SDS ID */
10263 :
10264 : int32 dum; /* Dummy variable */
10265 : int32 rankSDS; /* Rank of SDS/Field/tile */
10266 :
10267 : int32 dims[8]; /* Field/SDS dimensions */
10268 : int32 tileFlags; /* flag to determine if field is tiled */
10269 : HDF_CHUNK_DEF tileDef; /* union holding tiling info. */
10270 :
10271 :
10272 : /* Check if improper gridID */
10273 0 : status = GDchkgdid(gridID, "GDtileinfo", &fid, &sdInterfaceID, &dum);
10274 0 : if (status == 0)
10275 : {
10276 :
10277 : /* Get field info */
10278 0 : status = GDfieldinfo(gridID, fieldname, &rankSDS, dims, &dum, NULL);
10279 :
10280 0 : if (status == 0)
10281 : {
10282 :
10283 : /* Check whether fieldname is in SDS (multi-dim field) */
10284 : /* --------------------------------------------------- */
10285 0 : status = GDSDfldsrch(gridID, sdInterfaceID, fieldname, &sdid,
10286 : &rankSDS, &dum, &dum, dims, &dum);
10287 :
10288 :
10289 :
10290 : /* Query field for tiling information */
10291 0 : status = SDgetchunkinfo(sdid, &tileDef, &tileFlags);
10292 :
10293 : /* If field is untiled, return untiled flag */
10294 0 : if (tileFlags == HDF_NONE)
10295 : {
10296 0 : *tilecode = HDFE_NOTILE;
10297 0 : return (status);
10298 : }
10299 :
10300 : /* IF field is tiled or tiled with compression */
10301 0 : else if ((tileFlags == HDF_CHUNK) ||
10302 0 : (tileFlags == (HDF_CHUNK | HDF_COMP)))
10303 : {
10304 0 : if (tilecode != NULL)
10305 : {
10306 0 : *tilecode = HDFE_TILE;
10307 : }
10308 0 : if (tilerank != NULL)
10309 : {
10310 0 : *tilerank = rankSDS;
10311 : }
10312 0 : if (tiledims != NULL)
10313 : {
10314 : /* Assign size of tile dimensions */
10315 0 : for (i = 0; i < rankSDS; i++)
10316 : {
10317 0 : tiledims[i] = tileDef.chunk_lengths[i];
10318 : }
10319 : }
10320 : }
10321 : }
10322 :
10323 : /* Non-existent fieldname */
10324 : else
10325 : {
10326 0 : HEpush(DFE_GENAPP, "GDtileinfo", __FILE__, __LINE__);
10327 0 : HEreport("Fieldname \"%s\" does not exist.\n", fieldname);
10328 0 : status = -1;
10329 : }
10330 :
10331 : }
10332 0 : return (status);
10333 : }
10334 : /***********************************************
10335 : GDwritetile --
10336 : This function writes one tile to a particular field.
10337 :
10338 :
10339 : Author--
10340 : Alexis Zubrow
10341 :
10342 : ********************************************************/
10343 :
10344 : intn
10345 0 : GDwritetile(int32 gridID, const char *fieldname, int32 tilecoords[],
10346 : VOIDP tileData)
10347 : {
10348 0 : char code[] = "w"; /* write tile code */
10349 0 : intn status = 0; /* routine return status variable */
10350 :
10351 0 : status = GDwrrdtile(gridID, fieldname, code, tilecoords, tileData);
10352 :
10353 0 : return (status);
10354 : }
10355 : /***********************************************
10356 : GDreadtile --
10357 : This function reads one tile from a particular field.
10358 :
10359 :
10360 : Author--
10361 : Alexis Zubrow
10362 :
10363 : ********************************************************/
10364 :
10365 : intn
10366 0 : GDreadtile(int32 gridID, const char *fieldname, int32 tilecoords[],
10367 : VOIDP tileData)
10368 : {
10369 0 : char code[] = "r"; /* read tile code */
10370 0 : intn status = 0; /* routine return status variable */
10371 :
10372 0 : status = GDwrrdtile(gridID, fieldname, code, tilecoords, tileData);
10373 :
10374 0 : return (status);
10375 : }
10376 : /***********************************************
10377 : GDsettilecache --
10378 : This function sets the cache size for a tiled field.
10379 :
10380 :
10381 : Author--
10382 : Alexis Zubrow
10383 :
10384 : ********************************************************/
10385 :
10386 : intn
10387 0 : GDsettilecache(int32 gridID, const char *fieldname, int32 maxcache, CPL_UNUSED int32 cachecode)
10388 : {
10389 :
10390 0 : intn status = 0; /* routine return status variable */
10391 :
10392 : int32 fid; /* HDF-EOS file ID */
10393 : int32 sdInterfaceID; /* HDF SDS interface ID */
10394 : int32 sdid; /* SDS ID */
10395 :
10396 : int32 dum; /* Dummy variable */
10397 :
10398 : int32 dims[8]; /* Field/SDS dimensions */
10399 :
10400 :
10401 : /* Check gridID */
10402 0 : status = GDchkgdid(gridID, "GDwrrdtile", &fid, &sdInterfaceID, &dum);
10403 0 : if (status == 0)
10404 : {
10405 :
10406 : /* Get field info */
10407 0 : status = GDfieldinfo(gridID, fieldname, &dum, dims, &dum, NULL);
10408 :
10409 0 : if (status == 0)
10410 : {
10411 :
10412 : /* Check whether fieldname is in SDS (multi-dim field) */
10413 : /* --------------------------------------------------- */
10414 0 : status = GDSDfldsrch(gridID, sdInterfaceID, fieldname, &sdid,
10415 : &dum, &dum, &dum, dims, &dum);
10416 :
10417 :
10418 : /* Check if maxcache is less than or equal to zero */
10419 0 : if (maxcache <= 0)
10420 : {
10421 0 : HEpush(DFE_GENAPP, "GDsettilecache", __FILE__, __LINE__);
10422 0 : HEreport("Improper maxcache \"%d\"... \n", maxcache);
10423 0 : HEreport("maxcache must be greater than zero.\n");
10424 0 : status = -1;
10425 0 : return (status);
10426 : }
10427 :
10428 :
10429 : /* Set the number of tiles to cache */
10430 : /* Presently, the only cache flag allowed is 0 */
10431 0 : status = SDsetchunkcache(sdid, maxcache, 0);
10432 :
10433 :
10434 : }
10435 :
10436 : /* Non-existent fieldname */
10437 : else
10438 : {
10439 0 : HEpush(DFE_GENAPP, "GDwrrdtile", __FILE__, __LINE__);
10440 0 : HEreport("Fieldname \"%s\" does not exist.\n", fieldname);
10441 0 : status = -1;
10442 : }
10443 :
10444 : }
10445 :
10446 0 : return (status);
10447 : }
10448 :
10449 : /*----------------------------------------------------------------------------|
10450 : | BEGIN_PROLOG |
10451 : | |
10452 : | FUNCTION: GDsettilecomp |
10453 : | |
10454 : | DESCRIPTION: Sets the tiling/compression parameters for the specified |
10455 : | field. This can be called after GDsetfillvalue and assumes |
10456 : | that the field was defined with no compression/tiling set |
10457 : | by GDdeftile or GDdefcomp. |
10458 : | |
10459 : | This function replaces the following sequence: |
10460 : | GDdefcomp |
10461 : | GDdeftile |
10462 : | GDdeffield |
10463 : | GDsetfillvalue |
10464 : | with: |
10465 : | GDdeffield |
10466 : | GDsetfillvalue |
10467 : | GDsettilecomp |
10468 : | so that fill values will work correctly. |
10469 : | |
10470 : | Return Value Type Units Description |
10471 : | ============ ====== ========= ===================================== |
10472 : | status intn return status (0) SUCCEED, (-1) FAIL |
10473 : | |
10474 : | INPUTS: |
10475 : | gridID int32 grid structure ID |
10476 : | fieldname char field name |
10477 : | tilerank int32 number of tiling dimensions |
10478 : | tiledims int32 tiling dimensions |
10479 : | compcode int32 compression code |
10480 : | compparm intn compression parameters |
10481 : | |
10482 : | OUTPUTS: |
10483 : | None |
10484 : | |
10485 : | NOTES: |
10486 : | |
10487 : | |
10488 : | Date Programmer Description |
10489 : | ====== ============ ================================================= |
10490 : | Jun 98 MISR Used GDsetfillvalue as a template and copied |
10491 : | tiling/comp portions of GDdeffield.(NCR15866). |
10492 : | |
10493 : | END_PROLOG |
10494 : -----------------------------------------------------------------------------*/
10495 : intn
10496 0 : GDsettilecomp(int32 gridID, const char *fieldname, int32 tilerank, int32*
10497 : tiledims, int32 compcode, intn* compparm)
10498 : {
10499 : intn status; /* routine return status variable */
10500 :
10501 : int32 fid; /* HDF-EOS file ID */
10502 : int32 sdInterfaceID; /* HDF SDS interface ID */
10503 : int32 gdVgrpID; /* Grid root Vgroup ID */
10504 : int i; /* Looping variable. */
10505 : int32 sdid; /* SDS id */
10506 : int32 nt; /* Number type */
10507 : int32 dims[8]; /* Dimensions array */
10508 : int32 dum; /* Dummy variable */
10509 : int32 solo; /* "Solo" (non-merged) field flag */
10510 : comp_info c_info; /* Compression parameter structure */
10511 : HDF_CHUNK_DEF chunkDef; /* Tiling structure */
10512 : int32 chunkFlag; /* Chunking (Tiling) flag */
10513 :
10514 0 : c_info.nbit.nt = 0;
10515 :
10516 : /* Check for valid grid ID and get SDS interface ID */
10517 0 : status = GDchkgdid(gridID, "GDsetfillvalue",
10518 : &fid, &sdInterfaceID, &gdVgrpID);
10519 :
10520 0 : if (status == 0)
10521 : {
10522 : /* Get field info */
10523 0 : status = GDfieldinfo(gridID, fieldname, &dum, dims, &nt, NULL);
10524 :
10525 0 : if (status == 0)
10526 : {
10527 : /* Get SDS ID and solo flag */
10528 0 : status = GDSDfldsrch(gridID, sdInterfaceID, fieldname,
10529 : &sdid, &dum, &dum, &dum,
10530 : dims, &solo);
10531 0 : if (status !=0) {
10532 0 : HEpush(DFE_GENAPP, "GDsettilecomp", __FILE__, __LINE__);
10533 0 : HEreport("GDSDfldsrch failed\n", fieldname);
10534 0 : return FAIL;
10535 : }
10536 : /* Tiling with Compression */
10537 : /* ----------------------- */
10538 :
10539 :
10540 : /* Setup Compression */
10541 : /* ----------------- */
10542 0 : if (compcode == HDFE_COMP_NBIT)
10543 : {
10544 0 : c_info.nbit.nt = nt;
10545 0 : c_info.nbit.sign_ext = compparm[0];
10546 0 : c_info.nbit.fill_one = compparm[1];
10547 0 : c_info.nbit.start_bit = compparm[2];
10548 0 : c_info.nbit.bit_len = compparm[3];
10549 : }
10550 0 : else if (compcode == HDFE_COMP_SKPHUFF)
10551 : {
10552 0 : c_info.skphuff.skp_size = (intn) DFKNTsize(nt);
10553 : }
10554 0 : else if (compcode == HDFE_COMP_DEFLATE)
10555 : {
10556 0 : c_info.deflate.level = compparm[0];
10557 : }
10558 :
10559 : /* Setup chunk lengths */
10560 : /* ------------------- */
10561 0 : for (i = 0; i < tilerank; i++)
10562 : {
10563 0 : chunkDef.comp.chunk_lengths[i] = tiledims[i];
10564 : }
10565 :
10566 : /* Setup chunk flag & chunk compression type */
10567 : /* ----------------------------------------- */
10568 0 : chunkFlag = HDF_CHUNK | HDF_COMP;
10569 0 : chunkDef.comp.comp_type = compcode;
10570 :
10571 : /* Setup chunk compression parameters */
10572 : /* ---------------------------------- */
10573 0 : if (compcode == HDFE_COMP_SKPHUFF)
10574 : {
10575 0 : chunkDef.comp.cinfo.skphuff.skp_size =
10576 0 : c_info.skphuff.skp_size;
10577 : }
10578 0 : else if (compcode == HDFE_COMP_DEFLATE)
10579 : {
10580 0 : chunkDef.comp.cinfo.deflate.level =
10581 0 : c_info.deflate.level;
10582 : }
10583 : /* Call SDsetchunk routine */
10584 : /* ----------------------- */
10585 0 : status = SDsetchunk(sdid, chunkDef, chunkFlag);
10586 0 : if (status ==FAIL) {
10587 0 : HEpush(DFE_GENAPP, "GDsettilecomp", __FILE__, __LINE__);
10588 0 : HEreport("Fieldname \"%s\" does not exist.\n",
10589 : fieldname);
10590 0 : return status;
10591 : }
10592 : }
10593 : else
10594 : {
10595 0 : HEpush(DFE_GENAPP, "GDsettilecomp", __FILE__, __LINE__);
10596 0 : HEreport("Fieldname \"%s\" does not exist.\n", fieldname);
10597 : }
10598 : }
10599 0 : return (status);
10600 : }
10601 :
10602 : /*----------------------------------------------------------------------------|
10603 : | BEGIN_PROLOG |
10604 : | |
10605 : | FUNCTION: GDll2mm_cea |
10606 : | |
10607 : | DESCRIPTION: |
10608 : | |
10609 : | |
10610 : | Return Value Type Units Description |
10611 : | ============ ====== ========= ===================================== |
10612 : | status intn return status (0) SUCCEED, (-1) FAIL |
10613 : | |
10614 : | INPUTS: |
10615 : | projcode int32 GCTP projection code |
10616 : | zonecode int32 UTM zone code |
10617 : | projparm float64 Projection parameters |
10618 : | spherecode int32 GCTP spheriod code |
10619 : | xdimsize int32 xdimsize from GDcreate |
10620 : | ydimsize int32 ydimsize from GDcreate |
10621 : | upleftpt float64 upper left corner coordinates (DMS) |
10622 : | lowrightpt float64 lower right corner coordinates (DMS) |
10623 : | longitude float64 longitude array (DMS) |
10624 : | latitude float64 latitude array (DMS) |
10625 : | npnts int32 number of lon-lat points |
10626 : | |
10627 : | OUTPUTS: |
10628 : | x float64 X value array |
10629 : | y float64 Y value array |
10630 : | scaleX float64 X grid size |
10631 : | scaley float64 Y grid size |
10632 : | |
10633 : | NOTES: |
10634 : | |
10635 : | |
10636 : | Date Programmer Description |
10637 : | ====== ============ ================================================= |
10638 : | Oct 02 Abe Taaheri Added support for EASE grid |
10639 : | |
10640 : | END_PROLOG |
10641 : -----------------------------------------------------------------------------*/
10642 0 : static intn GDll2mm_cea(int32 projcode,int32 zonecode, int32 spherecode,
10643 : float64 projparm[],
10644 : int32 xdimsize, int32 ydimsize,
10645 : float64 upleftpt[], float64 lowrightpt[], int32 npnts,
10646 : CPL_UNUSED float64 lon[],CPL_UNUSED float64 lat[],
10647 : float64 x[],float64 y[], float64 *scaleX,float64 *scaleY)
10648 : {
10649 0 : intn status = 0; /* routine return status variable */
10650 0 : int32 errorcode = 0; /* GCTP error code */
10651 : float64 xMtr0, xMtr1, yMtr0, yMtr1;
10652 : float64 lonrad0; /* Longitude in radians of upleft point */
10653 : float64 latrad0; /* Latitude in radians of upleft point */
10654 : float64 lonrad; /* Longitude in radians of point */
10655 : float64 latrad; /* Latitude in radians of point */
10656 : int32(*for_trans[100]) (double, double, double*, double*); /* GCTP function pointer */
10657 :
10658 0 : if(npnts <= 0)
10659 : {
10660 0 : HEpush(DFE_GENAPP, " GDll2mm_cea", __FILE__, __LINE__);
10661 0 : HEreport("Improper npnts value\"%d\"... \n", npnts);
10662 0 : HEreport("npnts must be greater than zero.\n");
10663 0 : status = -1;
10664 0 : return (status);
10665 : }
10666 0 : if ( projcode == GCTP_BCEA)
10667 : {
10668 0 : for_init(projcode, zonecode, projparm, spherecode, NULL, NULL,
10669 : &errorcode, for_trans);
10670 : /* Convert upleft and lowright X coords from DMS to radians */
10671 : /* -------------------------------------------------------- */
10672 :
10673 0 : lonrad0 = EHconvAng(upleftpt[0], HDFE_DMS_RAD);
10674 0 : lonrad = EHconvAng(lowrightpt[0], HDFE_DMS_RAD);
10675 :
10676 : /* Convert upleft and lowright Y coords from DMS to radians */
10677 : /* -------------------------------------------------------- */
10678 0 : latrad0 = EHconvAng(upleftpt[1], HDFE_DMS_RAD);
10679 0 : latrad = EHconvAng(lowrightpt[1], HDFE_DMS_RAD);
10680 :
10681 : /* Convert from lon/lat to meters(or whatever unit is, i.e unit
10682 : of r_major and r_minor) using GCTP */
10683 : /* ----------------------------------------- */
10684 0 : errorcode = for_trans[projcode] (lonrad0, latrad0, &xMtr0, &yMtr0);
10685 0 : x[0] = xMtr0;
10686 0 : y[0] = yMtr0;
10687 :
10688 : /* Report error if any */
10689 : /* ------------------- */
10690 0 : if (errorcode != 0)
10691 : {
10692 0 : status = -1;
10693 0 : HEpush(DFE_GENAPP, "GDll2mm_cea", __FILE__, __LINE__);
10694 0 : HEreport("GCTP Error: %d\n", errorcode);
10695 0 : return (status);
10696 : }
10697 :
10698 : /* Convert from lon/lat to meters(or whatever unit is, i.e unit
10699 : of r_major and r_minor) using GCTP */
10700 : /* ----------------------------------------- */
10701 0 : errorcode = for_trans[projcode] (lonrad, latrad, &xMtr1, &yMtr1);
10702 0 : x[1] = xMtr1;
10703 0 : y[1] = yMtr1;
10704 :
10705 : /* Report error if any */
10706 : /* ------------------- */
10707 0 : if (errorcode != 0)
10708 : {
10709 0 : status = -1;
10710 0 : HEpush(DFE_GENAPP, "GDll2mm_cea", __FILE__, __LINE__);
10711 0 : HEreport("GCTP Error: %d\n", errorcode);
10712 0 : return (status);
10713 : }
10714 :
10715 : /* Compute x scale factor */
10716 : /* ---------------------- */
10717 0 : *scaleX = (xMtr1 - xMtr0) / xdimsize;
10718 :
10719 : /* Compute y scale factor */
10720 : /* ---------------------- */
10721 0 : *scaleY = (yMtr1 - yMtr0) / ydimsize;
10722 : }
10723 : else
10724 : {
10725 0 : status = -1;
10726 0 : HEpush(DFE_GENAPP, "GDll2mm_cea", __FILE__, __LINE__);
10727 0 : HEreport("Wrong projection code; this function is only for EASE grid");
10728 0 : return (status);
10729 : }
10730 0 : return (0);
10731 : }
10732 :
10733 :
10734 : /*----------------------------------------------------------------------------|
10735 : | BEGIN_PROLOG |
10736 : | |
10737 : | FUNCTION: GDmm2ll_cea |
10738 : | |
10739 : | DESCRIPTION: |
10740 : | |
10741 : | |
10742 : | Return Value Type Units Description |
10743 : | ============ ====== ========= ===================================== |
10744 : | status intn return status (0) SUCCEED, (-1) FAIL |
10745 : | |
10746 : | INPUTS: |
10747 : | projcode int32 GCTP projection code |
10748 : | zonecode int32 UTM zone code |
10749 : | projparm float64 Projection parameters |
10750 : | spherecode int32 GCTP spheriod code |
10751 : | xdimsize int32 xdimsize from GDcreate |
10752 : | ydimsize int32 ydimsize from GDcreate |
10753 : | upleftpt float64 upper left corner coordinates (DMS) |
10754 : | lowrightpt float64 lower right corner coordinates (DMS) |
10755 : | x float64 X value array |
10756 : | y float64 Y value array |
10757 : | npnts int32 number of x-y points |
10758 : | |
10759 : | OUTPUTS: |
10760 : | longitude float64 longitude array (DMS) |
10761 : | latitude float64 latitude array (DMS) |
10762 : | |
10763 : | NOTES: |
10764 : | |
10765 : | |
10766 : | Date Programmer Description |
10767 : | ====== ============ ================================================= |
10768 : | Oct 02 Abe Taaheri Added support for EASE grid |
10769 : | |
10770 : | END_PROLOG |
10771 : -----------------------------------------------------------------------------*/
10772 0 : static intn GDmm2ll_cea(int32 projcode,int32 zonecode, int32 spherecode,
10773 : float64 projparm[],
10774 : CPL_UNUSED int32 xdimsize, CPL_UNUSED int32 ydimsize,
10775 : CPL_UNUSED float64 upleftpt[], CPL_UNUSED float64 lowrightpt[], int32 npnts,
10776 : float64 x[], float64 y[],
10777 : float64 longitude[], float64 latitude[])
10778 : {
10779 0 : intn status = 0; /* routine return status variable */
10780 0 : int32 errorcode = 0; /* GCTP error code */
10781 : int32(*inv_trans[100]) (double, double, double*, double*); /* GCTP function pointer */
10782 : int32 i;
10783 :
10784 0 : if(npnts <= 0)
10785 : {
10786 0 : HEpush(DFE_GENAPP, " GDmm2ll_cea", __FILE__, __LINE__);
10787 0 : HEreport("Improper npnts value\"%d\"... \n", npnts);
10788 0 : HEreport("npnts must be greater than zero.\n");
10789 0 : status = -1;
10790 0 : return (status);
10791 : }
10792 0 : if ( projcode == GCTP_BCEA)
10793 : {
10794 0 : inv_init(projcode, zonecode, projparm, spherecode, NULL, NULL,
10795 : &errorcode, inv_trans);
10796 :
10797 : /* Convert from meters(or whatever unit is, i.e unit
10798 : of r_major and r_minor) to lat/lon using GCTP */
10799 : /* ----------------------------------------- */
10800 0 : for(i=0; i<npnts; i++)
10801 : {
10802 0 : errorcode =
10803 0 : inv_trans[projcode] (x[i], y[i],&longitude[i], &latitude[i]);
10804 : /* Report error if any */
10805 : /* ------------------- */
10806 0 : if (errorcode != 0)
10807 : {
10808 0 : status = -1;
10809 0 : HEpush(DFE_GENAPP, "GDmm2ll_cea", __FILE__, __LINE__);
10810 0 : HEreport("GCTP Error: %d\n", errorcode);
10811 0 : return (status);
10812 : }
10813 0 : longitude[i] = EHconvAng(longitude[i], HDFE_RAD_DMS);
10814 0 : latitude[i] = EHconvAng(latitude[i], HDFE_RAD_DMS);
10815 : }
10816 : }
10817 : else
10818 : {
10819 : /* Wrong projection code; this function is only for EASE grid */
10820 : }
10821 0 : return(status);
10822 : }
10823 :
10824 : /*----------------------------------------------------------------------------|
10825 : | BEGIN_PROLOG |
10826 : | |
10827 : | FUNCTION: GDsdid |
10828 : | |
10829 : | DESCRIPTION: Returns SD element ID for grid field |
10830 : | |
10831 : | |
10832 : | Return Value Type Units Description |
10833 : | ============ ====== ========= ===================================== |
10834 : | status intn return status (0) SUCCEED, (-1) FAIL |
10835 : | |
10836 : | INPUTS: |
10837 : | gridID int32 grid structure ID |
10838 : | fieldname const char field name |
10839 : | |
10840 : | |
10841 : | OUTPUTS: |
10842 : | sdid int32 SD element ID |
10843 : | |
10844 : | NOTES: |
10845 : | |
10846 : | |
10847 : | Date Programmer Description |
10848 : | ====== ============ ================================================= |
10849 : | Oct 07 Andrey Kiselev Original Programmer |
10850 : | |
10851 : | END_PROLOG |
10852 : -----------------------------------------------------------------------------*/
10853 : intn
10854 0 : GDsdid(int32 gridID, const char *fieldname, int32 *sdid)
10855 : {
10856 : intn status; /* routine return status variable */
10857 : int32 fid; /* HDF-EOS file ID */
10858 : int32 sdInterfaceID; /* HDF SDS interface ID */
10859 : int32 dum; /* Dummy variable */
10860 : int32 dims[H4_MAX_VAR_DIMS]; /* Field/SDS dimensions */
10861 :
10862 0 : status = GDchkgdid(gridID, "GDsdid", &fid, &sdInterfaceID, &dum);
10863 0 : if (status != -1)
10864 : {
10865 0 : status = GDSDfldsrch(gridID, sdInterfaceID, fieldname,
10866 : sdid, &dum, &dum, &dum, dims, &dum);
10867 : }
10868 :
10869 0 : return (status);
10870 : }
|