Line data Source code
1 : /*****************************************************************************
2 : *
3 : * This module has a number of additions and improvements over the original
4 : * implementation to be suitable for usage in GDAL HDF driver.
5 : *
6 : * Andrey Kiselev <dron@ak4719.spb.edu> is responsible for all the changes.
7 : ****************************************************************************/
8 :
9 : /*
10 : Copyright (C) 1996 Hughes and Applied Research Corporation
11 :
12 : Permission to use, modify, and distribute this software and its documentation
13 : for any purpose without fee is hereby granted, provided that the above
14 : copyright notice appear in all copies and that both that copyright notice and
15 : this permission notice appear in supporting documentation.
16 : */
17 : /*****************************************************************************
18 : REVISIONS:
19 :
20 : Aug 31, 1999 Abe Taaheri Changed memory allocation for utility strings to
21 : the size of UTLSTR_MAX_SIZE.
22 : Added error check for memory unavailability in
23 : several functions.
24 : Added check for NULL metabuf returned from
25 : EHmeta... functions. NULL pointer returned from
26 : EHmeta... functions indicate that memory could not
27 : be allocated for metabuf.
28 : Jun 27, 2000 Abe Taaheri Added support for EASE grid that uses
29 : Behrmann Cylinderical Equal Area (BCEA) projection
30 : Oct 23, 2000 Abe Taaheri Updated for ISINUS projection, so that both codes
31 : 31 and 99 can be used for this projection.
32 : Jan 15, 2003 Abe Taaheri Modified for generalization of EASE Grid.
33 :
34 : Jun 05, 2003 Bruce Beaumont / Abe Taaheri
35 :
36 : Fixed SQUARE definition.
37 : Added static projection number/name translation
38 : Added projection table lookup in GDdefproj.
39 : Removed projection table from GDdefproj
40 : Added projection table lookup in GDprojinfo
41 : Removed projection table from GDprojinfo
42 : Added cast for compcode in call to SDsetcompress
43 : in GDdeffield to avoid compiler errors
44 : Removed declaration for unused variable endptr
45 : in GDSDfldsrch
46 : Removed initialization code for unused variables
47 : in GDSDfldsrch
48 : Removed declarations for unused variables
49 : BCEA_scale, r0, s0, xMtr0, xMtr1, yMtr0,
50 : and yMtr1 in GDll2ij
51 : Removed initialization code for unused variables
52 : in GDll2ij
53 : Added code in GEO projection handling to allow
54 : map to span dateline in GDll2ij
55 : Changed "for each point" loop in GDll2ij to
56 : return -2147483648.0 for xVal and yVal if
57 : for_trans returned an error instead of
58 : returning an error to the caller
59 : (Note: MAXLONG is defined as 2147483647.0 in
60 : function cproj.c of GCTP)
61 : Added code in GDij2ll to use for_trans to
62 : translate the BCEA corner points from packed
63 : degrees to meters
64 : Removed declarations for unused variables
65 : BCEA_scale, r0, s0, xMtr, yMtr, epsilon,
66 : beta, qp_cea, kz_cea, eccen, eccen_sq,
67 : phi1, sinphi1, cosphi1, lon, lat, xcor,
68 : ycor, and nlatlon from GDij2ll
69 : Removed initialization code for unused variables
70 : in GDij2ll
71 : Added declarations for xMtr0, yMtr0, xMtr1, and
72 : yMtr1 in GDij2ll
73 : Added special-case code for BCEA
74 : Changed "for each point" loop in GDij2ll to
75 : return PGSd_GCT_IN_ERROR (1.0e51) for
76 : longitude and latitude values if inv_trans
77 : returned an error instead of return an error
78 : to the caller
79 : Removed declaration for unused variable ii in
80 : GDgetpixvalues
81 : Removed declaration for unused variable
82 : numTileDims in GDtileinfo
83 : Added error message and error return at the
84 : end of GDll2mm_cea
85 : Added return statement to GDll2mm_cea
86 : ******************************************************************************/
87 : #include "cpl_string.h"
88 : #include "stdio.h"
89 : #include "mfhdf.h"
90 : #include "hcomp.h"
91 : #include <math.h>
92 : #include "HdfEosDef.h"
93 :
94 : #include "hdf4compat.h"
95 :
96 : extern void for_init(int32, int32, float64 *, int32, const char *, const char *, int32 *,
97 : int32 (*for_trans[])(double, double, double*, double*));
98 : extern void inv_init(int32, int32, float64 *, int32, const char *, const char *, int32 *,
99 : int32 (*inv_trans[])(double, double, double*, double*));
100 :
101 : #define GDIDOFFSET 4194304
102 : #define SQUARE(x) ((x) * (x)) /* x**2 */
103 :
104 :
105 : #define NGRID 200
106 : /* Grid Structure External Arrays */
107 : struct gridStructure
108 : {
109 : int32 active;
110 : int32 IDTable;
111 : int32 VIDTable[2];
112 : int32 fid;
113 : int32 nSDS;
114 : int32 *sdsID;
115 : int32 compcode;
116 : intn compparm[5];
117 : int32 tilecode;
118 : int32 tilerank;
119 : int32 tiledims[8];
120 : };
121 : static struct gridStructure GDXGrid[NGRID];
122 :
123 :
124 :
125 : #define NGRIDREGN 256
126 : struct gridRegion
127 : {
128 : int32 fid;
129 : int32 gridID;
130 : int32 xStart;
131 : int32 xCount;
132 : int32 yStart;
133 : int32 yCount;
134 : int32 somStart;
135 : int32 somCount;
136 : float64 upleftpt[2];
137 : float64 lowrightpt[2];
138 : int32 StartVertical[8];
139 : int32 StopVertical[8];
140 : char *DimNamePtr[8];
141 : };
142 : static struct gridRegion *GDXRegion[NGRIDREGN];
143 :
144 : /* define a macro for the string size of the utility strings and some dimension
145 : list strings. The value of 80 in the previous version of this code
146 : may not be enough in some cases. The length now is 512 which seems to
147 : be more than enough to hold larger strings. */
148 :
149 : #define UTLSTR_MAX_SIZE 512
150 :
151 : /* Static projection table */
152 : static const struct {
153 : int32 projcode;
154 : const char *projname;
155 : } Projections[] = {
156 : {GCTP_GEO, "GCTP_GEO"},
157 : {GCTP_UTM, "GCTP_UTM"},
158 : {GCTP_SPCS, "GCTP_SPCS"},
159 : {GCTP_ALBERS, "GCTP_ALBERS"},
160 : {GCTP_LAMCC, "GCTP_LAMCC"},
161 : {GCTP_MERCAT, "GCTP_MERCAT"},
162 : {GCTP_PS, "GCTP_PS"},
163 : {GCTP_POLYC, "GCTP_POLYC"},
164 : {GCTP_EQUIDC, "GCTP_EQUIDC"},
165 : {GCTP_TM, "GCTP_TM"},
166 : {GCTP_STEREO, "GCTP_STEREO"},
167 : {GCTP_LAMAZ, "GCTP_LAMAZ"},
168 : {GCTP_AZMEQD, "GCTP_AZMEQD"},
169 : {GCTP_GNOMON, "GCTP_GNOMON"},
170 : {GCTP_ORTHO, "GCTP_ORTHO"},
171 : {GCTP_GVNSP, "GCTP_GVNSP"},
172 : {GCTP_SNSOID, "GCTP_SNSOID"},
173 : {GCTP_EQRECT, "GCTP_EQRECT"},
174 : {GCTP_MILLER, "GCTP_MILLER"},
175 : {GCTP_VGRINT, "GCTP_VGRINT"},
176 : {GCTP_HOM, "GCTP_HOM"},
177 : {GCTP_ROBIN, "GCTP_ROBIN"},
178 : {GCTP_SOM, "GCTP_SOM"},
179 : {GCTP_ALASKA, "GCTP_ALASKA"},
180 : {GCTP_GOOD, "GCTP_GOOD"},
181 : {GCTP_MOLL, "GCTP_MOLL"},
182 : {GCTP_IMOLL, "GCTP_IMOLL"},
183 : {GCTP_HAMMER, "GCTP_HAMMER"},
184 : {GCTP_WAGIV, "GCTP_WAGIV"},
185 : {GCTP_WAGVII, "GCTP_WAGVII"},
186 : {GCTP_OBLEQA, "GCTP_OBLEQA"},
187 : {GCTP_ISINUS1, "GCTP_ISINUS1"},
188 : {GCTP_CEA, "GCTP_CEA"},
189 : {GCTP_BCEA, "GCTP_BCEA"},
190 : {GCTP_ISINUS, "GCTP_ISINUS"},
191 : {-1, NULL}
192 : };
193 :
194 : /* Compression Codes */
195 : static const char * const HDFcomp[] = {
196 : "HDFE_COMP_NONE",
197 : "HDFE_COMP_RLE",
198 : "HDFE_COMP_NBIT",
199 : "HDFE_COMP_SKPHUFF",
200 : "HDFE_COMP_DEFLATE"
201 : };
202 :
203 : /* Origin Codes */
204 : static const char * const originNames[] = {
205 : "HDFE_GD_UL",
206 : "HDFE_GD_UR",
207 : "HDFE_GD_LL",
208 : "HDFE_GD_LR"
209 : };
210 :
211 : /* Pixel Registration Codes */
212 : static const char * const pixregNames[] = {
213 : "HDFE_CENTER",
214 : "HDFE_CORNER"
215 : };
216 :
217 : /* Grid Function Prototypes (internal routines) */
218 : static intn GDchkgdid(int32, const char *, int32 *, int32 *, int32 *);
219 : static intn GDSDfldsrch(int32, int32, const char *, int32 *, int32 *,
220 : int32 *, int32 *, int32 [], int32 *);
221 : static intn GDwrrdfield(int32, const char *, const char *,
222 : int32 [], int32 [], int32 [], VOIDP datbuf);
223 : static intn GDwrrdattr(int32, const char *, int32, int32, const char *, VOIDP);
224 : static intn GDll2ij(int32, int32, float64 [], int32, int32, int32, float64[],
225 : float64[], int32, float64[], float64[], int32[], int32[],
226 : float64[], float64[]);
227 : static intn GDgetdefaults(int32, int32, float64[], int32,
228 : float64[], float64[]);
229 : static intn GDwrrdtile(int32, const char *, const char *, int32 [], VOIDP);
230 :
231 : /*----------------------------------------------------------------------------|
232 : | BEGIN_PROLOG |
233 : | |
234 : | FUNCTION: GDopen |
235 : | |
236 : | DESCRIPTION: Opens or creates HDF file in order to create, read, or write |
237 : | a grid. |
238 : | |
239 : | |
240 : | Return Value Type Units Description |
241 : | ============ ====== ========= ===================================== |
242 : | fid int32 HDF-EOS file ID |
243 : | |
244 : | INPUTS: |
245 : | filename char Filename |
246 : | l_access intn HDF l_access code |
247 : | |
248 : | |
249 : | OUTPUTS: |
250 : | None |
251 : | |
252 : | NOTES: |
253 : | |
254 : | |
255 : | Date Programmer Description |
256 : | ====== ============ ================================================= |
257 : | Jun 96 Joel Gales Original Programmer |
258 : | |
259 : | END_PROLOG |
260 : -----------------------------------------------------------------------------*/
261 : int32
262 11 : GDopen(const char *filename, intn l_access)
263 :
264 : {
265 : int32 fid /* HDF-EOS file ID */ ;
266 :
267 : /* Call EHopen to perform file l_access */
268 : /* ---------------------------------- */
269 11 : fid = EHopen(filename, l_access);
270 :
271 11 : return (fid);
272 :
273 : }
274 :
275 :
276 : /*----------------------------------------------------------------------------|
277 : | BEGIN_PROLOG |
278 : | |
279 : | FUNCTION: GDattach |
280 : | |
281 : | DESCRIPTION: Attaches to an existing grid within the file. |
282 : | |
283 : | |
284 : | Return Value Type Units Description |
285 : | ============ ====== ========= ===================================== |
286 : | gridID int32 grid structure ID |
287 : | |
288 : | INPUTS: |
289 : | fid int32 HDF-EOS file id |
290 : | gridname char grid structure name |
291 : | |
292 : | |
293 : | OUTPUTS: |
294 : | None |
295 : | |
296 : | NOTES: |
297 : | |
298 : | |
299 : | Date Programmer Description |
300 : | ====== ============ ================================================= |
301 : | Jun 96 Joel Gales Original Programmer |
302 : | Sep 99 Abe Taaheri Modified test for memory allocation check when no |
303 : | SDSs are in the grid, NCR24147 |
304 : | |
305 : | END_PROLOG |
306 : -----------------------------------------------------------------------------*/
307 : int32
308 3 : GDattach(int32 fid, const char *gridname)
309 :
310 : {
311 : intn i; /* Loop index */
312 : intn j; /* Loop index */
313 3 : intn ngridopen = 0; /* # of grid structures open */
314 : intn status; /* routine return status variable */
315 :
316 : uint8 acs; /* Read/Write file l_access code */
317 :
318 : int32 HDFfid; /* HDF file id */
319 : int32 vgRef; /* Vgroup reference number */
320 : int32 vgid[3]; /* Vgroup ID array */
321 3 : int32 gridID = -1;/* HDF-EOS grid ID */
322 : int32 *tags; /* Pnt to Vgroup object tags array */
323 : int32 *refs; /* Pnt to Vgroup object refs array */
324 : int32 dum; /* dummy variable */
325 : int32 sdInterfaceID; /* HDF SDS interface ID */
326 : int32 nObjects; /* # of objects in Vgroup */
327 : int32 nSDS; /* SDS counter */
328 : int32 l_index; /* SDS l_index */
329 : int32 sdid; /* SDS object ID */
330 3 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
331 :
332 : char name[80]; /* Vgroup name */
333 : char class[80]; /* Vgroup class */
334 : char errbuf[256];/* Buffer for error message */
335 : char acsCode[1]; /* Read/Write l_access char: "r/w" */
336 :
337 :
338 : /* Check HDF-EOS file ID, get back HDF file ID and l_access code */
339 : /* ----------------------------------------------------------- */
340 3 : status = EHchkfid(fid, gridname, &HDFfid, &dum, &acs);
341 :
342 :
343 3 : if (status == 0)
344 : {
345 : /* Convert numeric l_access code to character */
346 : /* ---------------------------------------- */
347 :
348 3 : acsCode[0] = (acs == 1) ? 'w' : 'r';
349 :
350 : /* Determine number of grids currently opened */
351 : /* ------------------------------------------- */
352 603 : for (i = 0; i < NGRID; i++)
353 : {
354 600 : ngridopen += GDXGrid[i].active;
355 : }
356 :
357 :
358 : /* If room for more ... */
359 : /* -------------------- */
360 3 : if (ngridopen < NGRID)
361 : {
362 :
363 : /* Search Vgroups for Grid */
364 : /* ------------------------ */
365 3 : vgRef = -1;
366 :
367 : while (1)
368 : {
369 12 : vgRef = Vgetid(HDFfid, vgRef);
370 :
371 : /* If no more Vgroups then exist while loop */
372 : /* ---------------------------------------- */
373 12 : if (vgRef == -1)
374 : {
375 0 : break;
376 : }
377 :
378 : /* Get name and class of Vgroup */
379 : /* ---------------------------- */
380 12 : vgid[0] = Vattach(HDFfid, vgRef, "r");
381 12 : Vgetname(vgid[0], name);
382 12 : Vgetclass(vgid[0], class);
383 :
384 :
385 : /*
386 : * If Vgroup with gridname and class GRID found, load tables
387 : */
388 :
389 12 : if (strcmp(name, gridname) == 0 &&
390 3 : strcmp(class, "GRID") == 0)
391 : {
392 : /* Attach to "Data Fields" and "Grid Attributes" Vgroups */
393 : /* ----------------------------------------------------- */
394 3 : tags = (int32 *) malloc(sizeof(int32) * 2);
395 3 : if(tags == NULL)
396 : {
397 0 : HEpush(DFE_NOSPACE,"GDattach", __FILE__, __LINE__);
398 0 : return(-1);
399 : }
400 3 : refs = (int32 *) malloc(sizeof(int32) * 2);
401 3 : if(refs == NULL)
402 : {
403 0 : HEpush(DFE_NOSPACE,"GDattach", __FILE__, __LINE__);
404 0 : free(tags);
405 0 : return(-1);
406 : }
407 3 : Vgettagrefs(vgid[0], tags, refs, 2);
408 3 : vgid[1] = Vattach(HDFfid, refs[0], acsCode);
409 3 : vgid[2] = Vattach(HDFfid, refs[1], acsCode);
410 3 : free(tags);
411 3 : free(refs);
412 :
413 :
414 : /* Setup External Arrays */
415 : /* --------------------- */
416 3 : for (i = 0; i < NGRID; i++)
417 : {
418 : /* Find empty entry in array */
419 : /* ------------------------- */
420 3 : if (GDXGrid[i].active == 0)
421 : {
422 : /*
423 : * Set gridID, Set grid entry active, Store root
424 : * Vgroup ID, Store sub Vgroup IDs, Store HDF-EOS
425 : * file ID
426 : */
427 3 : gridID = i + idOffset;
428 3 : GDXGrid[i].active = 1;
429 3 : GDXGrid[i].IDTable = vgid[0];
430 3 : GDXGrid[i].VIDTable[0] = vgid[1];
431 3 : GDXGrid[i].VIDTable[1] = vgid[2];
432 3 : GDXGrid[i].fid = fid;
433 3 : break;
434 : }
435 : }
436 :
437 : /* Get SDS interface ID */
438 : /* -------------------- */
439 3 : status = GDchkgdid(gridID, "GDattach", &dum,
440 : &sdInterfaceID, &dum);
441 :
442 :
443 : /* Get # of entries within Data Vgroup & search for SDS */
444 : /* ---------------------------------------------------- */
445 3 : nObjects = Vntagrefs(vgid[1]);
446 :
447 3 : if (nObjects > 0)
448 : {
449 : /* Get tag and ref # for Data Vgroup objects */
450 : /* ----------------------------------------- */
451 0 : tags = (int32 *) malloc(sizeof(int32) * nObjects);
452 0 : if(tags == NULL)
453 : {
454 0 : HEpush(DFE_NOSPACE,"GDattach", __FILE__, __LINE__);
455 0 : return(-1);
456 : }
457 0 : refs = (int32 *) malloc(sizeof(int32) * nObjects);
458 0 : if(refs == NULL)
459 : {
460 0 : HEpush(DFE_NOSPACE,"GDattach", __FILE__, __LINE__);
461 0 : free(tags);
462 0 : return(-1);
463 : }
464 0 : Vgettagrefs(vgid[1], tags, refs, nObjects);
465 :
466 : /* Count number of SDS & allocate SDS ID array */
467 : /* ------------------------------------------- */
468 0 : nSDS = 0;
469 0 : for (j = 0; j < nObjects; j++)
470 : {
471 0 : if (tags[j] == DFTAG_NDG)
472 : {
473 0 : nSDS++;
474 : }
475 : }
476 0 : GDXGrid[i].sdsID = (int32 *) calloc(nSDS, 4);
477 0 : if(GDXGrid[i].sdsID == NULL && nSDS != 0)
478 : {
479 0 : HEpush(DFE_NOSPACE,"GDattach", __FILE__, __LINE__);
480 0 : free(tags);
481 0 : free(refs);
482 0 : return(-1);
483 : }
484 0 : nSDS = 0;
485 :
486 :
487 :
488 : /* Fill SDS ID array */
489 : /* ----------------- */
490 0 : for (j = 0; j < nObjects; j++)
491 : {
492 : /* If object is SDS then get id */
493 : /* ---------------------------- */
494 0 : if (tags[j] == DFTAG_NDG)
495 : {
496 0 : l_index = SDreftoindex(sdInterfaceID, refs[j]);
497 0 : sdid = SDselect(sdInterfaceID, l_index);
498 0 : GDXGrid[i].sdsID[nSDS] = sdid;
499 0 : nSDS++;
500 0 : GDXGrid[i].nSDS++;
501 : }
502 : }
503 0 : free(tags);
504 0 : free(refs);
505 : }
506 3 : break;
507 : }
508 :
509 : /* Detach Vgroup if not desired Grid */
510 : /* --------------------------------- */
511 9 : Vdetach(vgid[0]);
512 : }
513 :
514 : /* If Grid not found then set up error message */
515 : /* ------------------------------------------- */
516 3 : if (gridID == -1)
517 : {
518 0 : HEpush(DFE_RANGE, "GDattach", __FILE__, __LINE__);
519 0 : HEreport("Grid: \"%s\" does not exist within HDF file.\n",
520 : gridname);
521 : }
522 : }
523 : else
524 : {
525 : /* Too many files opened */
526 : /* --------------------- */
527 0 : gridID = -1;
528 0 : strcpy(errbuf,
529 : "No more than %d grids may be open simultaneously");
530 0 : strcat(errbuf, " (%s)");
531 0 : HEpush(DFE_DENIED, "GDattach", __FILE__, __LINE__);
532 0 : HEreport(errbuf, NGRID, gridname);
533 : }
534 :
535 : }
536 3 : return (gridID);
537 : }
538 :
539 :
540 : /*----------------------------------------------------------------------------|
541 : | BEGIN_PROLOG |
542 : | |
543 : | FUNCTION: GDchkgdid |
544 : | |
545 : | DESCRIPTION: |
546 : | |
547 : | |
548 : | Return Value Type Units Description |
549 : | ============ ====== ========= ===================================== |
550 : | status intn return status (0) SUCCEED, (-1) FAIL |
551 : | |
552 : | INPUTS: |
553 : | gridID int32 grid structure ID |
554 : | routname char Name of routine calling GDchkgdid |
555 : | |
556 : | OUTPUTS: |
557 : | fid int32 File ID |
558 : | sdInterfaceID int32 SDS interface ID |
559 : | gdVgrpID int32 grid Vgroup ID |
560 : | |
561 : | |
562 : | OUTPUTS: |
563 : | None |
564 : | |
565 : | NOTES: |
566 : | |
567 : | |
568 : | Date Programmer Description |
569 : | ====== ============ ================================================= |
570 : | Jun 96 Joel Gales Original Programmer |
571 : | |
572 : | END_PROLOG |
573 : -----------------------------------------------------------------------------*/
574 : static intn
575 167 : GDchkgdid(int32 gridID, const char *routname,
576 : int32 * fid, int32 * sdInterfaceID, int32 * gdVgrpID)
577 : {
578 167 : intn status = 0; /* routine return status variable */
579 : uint8 l_access; /* Read/Write l_access code */
580 : int32 gID; /* Grid ID - offset */
581 :
582 167 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
583 :
584 : static const char message1[] =
585 : "Invalid grid id: %d in routine \"%s\". ID must be >= %d and < %d.\n";
586 : static const char message2[] =
587 : "Grid id %d in routine \"%s\" not active.\n";
588 :
589 :
590 :
591 : /* Check for valid grid id */
592 :
593 167 : if (gridID < idOffset || gridID >= NGRID + idOffset)
594 : {
595 0 : status = -1;
596 0 : HEpush(DFE_RANGE, "GDchkgdid", __FILE__, __LINE__);
597 0 : HEreport(message1, gridID, routname, idOffset, NGRID + idOffset);
598 : }
599 : else
600 : {
601 :
602 : /* Compute "reduced" ID */
603 : /* -------------------- */
604 167 : gID = gridID % idOffset;
605 :
606 : /* Check for active grid ID */
607 : /* ------------------------ */
608 167 : if (GDXGrid[gID].active == 0)
609 : {
610 0 : status = -1;
611 0 : HEpush(DFE_GENAPP, "GDchkgdid", __FILE__, __LINE__);
612 0 : HEreport(message2, gridID, routname);
613 : }
614 : else
615 : {
616 :
617 : /* Get file & SDS ids and Grid key */
618 : /* -------------------------------- */
619 167 : status = EHchkfid(GDXGrid[gID].fid, " ",
620 : fid, sdInterfaceID, &l_access);
621 167 : *gdVgrpID = GDXGrid[gID].IDTable;
622 : }
623 : }
624 167 : return (status);
625 :
626 : }
627 :
628 :
629 : /*----------------------------------------------------------------------------|
630 : | BEGIN_PROLOG |
631 : | |
632 : | FUNCTION: GDdiminfo |
633 : | |
634 : | DESCRIPTION: Retrieve size of specified dimension. |
635 : | |
636 : | |
637 : | Return Value Type Units Description |
638 : | ============ ====== ========= ===================================== |
639 : | size int32 Size of dimension |
640 : | |
641 : | INPUTS: |
642 : | gridID int32 grid structure id |
643 : | dimname char Dimension name |
644 : | |
645 : | |
646 : | OUTPUTS: |
647 : | None |
648 : | |
649 : | NOTES: |
650 : | |
651 : | |
652 : | Date Programmer Description |
653 : | ====== ============ ================================================= |
654 : | Jun 96 Joel Gales Original Programmer |
655 : | Aug 96 Joel Gales Make metadata ODL compliant |
656 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
657 : | |
658 : | END_PROLOG |
659 : -----------------------------------------------------------------------------*/
660 : int32
661 0 : GDdiminfo(int32 gridID, const char *dimname)
662 :
663 : {
664 : intn status; /* routine return status variable */
665 :
666 : int32 fid; /* HDF-EOS file ID */
667 : int32 sdInterfaceID; /* HDF SDS interface ID */
668 : int32 gdVgrpID; /* Grid root Vgroup ID */
669 : int32 size; /* Dimension size */
670 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
671 :
672 :
673 : char *metabuf; /* Pointer to structural metadata (SM) */
674 : char *metaptrs[2];/* Pointers to begin and end of SM section */
675 : char gridname[80]; /* Grid Name */
676 : char *utlstr; /* Utility string */
677 :
678 : /* Allocate space for utility string */
679 : /* --------------------------------- */
680 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
681 0 : if(utlstr == NULL)
682 : {
683 0 : HEpush(DFE_NOSPACE,"GDdiminfo", __FILE__, __LINE__);
684 0 : return(-1);
685 : }
686 : /* Initialize return value */
687 : /* ----------------------- */
688 0 : size = -1;
689 :
690 :
691 : /* Check Grid ID */
692 : /* ------------- */
693 0 : status = GDchkgdid(gridID, "GDdiminfo", &fid, &sdInterfaceID, &gdVgrpID);
694 :
695 :
696 0 : if (status == 0)
697 : {
698 : /* Get grid name */
699 : /* ------------- */
700 0 : int gID = gridID % idOffset;
701 0 : if (gID >= NGRID)
702 : {
703 0 : free(utlstr);
704 0 : return -1;
705 : }
706 0 : Vgetname(GDXGrid[gID].IDTable, gridname);
707 :
708 :
709 : /* Get pointers to "Dimension" section within SM */
710 : /* --------------------------------------------- */
711 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
712 : "Dimension", metaptrs);
713 :
714 0 : if(metabuf == NULL)
715 : {
716 0 : free(utlstr);
717 0 : return(-1);
718 : }
719 :
720 : /* Search for dimension name (surrounded by quotes) */
721 : /* ------------------------------------------------ */
722 0 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "\"", dimname, "\"\n");
723 0 : metaptrs[0] = strstr(metaptrs[0], utlstr);
724 :
725 : /*
726 : * If dimension found within grid structure then get dimension value
727 : */
728 0 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
729 : {
730 : /* Set endptr at end of dimension definition entry */
731 : /* ----------------------------------------------- */
732 0 : metaptrs[1] = strstr(metaptrs[0], "\t\t\tEND_OBJECT");
733 :
734 0 : status = EHgetmetavalue(metaptrs, "Size", utlstr);
735 :
736 0 : if (status == 0)
737 : {
738 0 : size = atoi(utlstr);
739 : }
740 : else
741 : {
742 0 : HEpush(DFE_GENAPP, "GDdiminfo", __FILE__, __LINE__);
743 0 : HEreport("\"Size\" string not found in metadata.\n");
744 : }
745 : }
746 : else
747 : {
748 0 : HEpush(DFE_GENAPP, "GDdiminfo", __FILE__, __LINE__);
749 0 : HEreport("Dimension \"%s\" not found.\n", dimname);
750 : }
751 :
752 0 : free(metabuf);
753 : }
754 0 : free(utlstr);
755 0 : return (size);
756 : }
757 :
758 :
759 :
760 :
761 :
762 : /*----------------------------------------------------------------------------|
763 : | BEGIN_PROLOG |
764 : | |
765 : | FUNCTION: GDgridinfo |
766 : | |
767 : | DESCRIPTION: Returns xdim, ydim and location of upper left and lower |
768 : | right corners, in meters. |
769 : | |
770 : | |
771 : | Return Value Type Units Description |
772 : | ============ ====== ========= ===================================== |
773 : | status intn return status (0) SUCCEED, (-1) FAIL |
774 : | |
775 : | INPUTS: |
776 : | fid int32 File ID |
777 : | gridname char Grid structure name |
778 : | |
779 : | OUTPUTS: |
780 : | xdimsize int32 Number of columns in grid |
781 : | ydimsize int32 Number of rows in grid |
782 : | upleftpt float64 Location (m/deg) of upper left corner |
783 : | lowrightpt float64 Location (m/deg) of lower right corner |
784 : | |
785 : | NOTES: |
786 : | |
787 : | |
788 : | Date Programmer Description |
789 : | ====== ============ ================================================= |
790 : | Jun 96 Joel Gales Original Programmer |
791 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
792 : | |
793 : | END_PROLOG |
794 : -----------------------------------------------------------------------------*/
795 : intn
796 2 : GDgridinfo(int32 gridID, int32 * xdimsize, int32 * ydimsize,
797 : float64 upleftpt[], float64 lowrightpt[])
798 :
799 : {
800 2 : intn status = 0; /* routine return status variable */
801 2 : intn statmeta = 0; /* EHgetmetavalue return status */
802 :
803 : int32 fid; /* HDF-EOS file ID */
804 : int32 sdInterfaceID; /* HDF SDS interface ID */
805 : int32 gdVgrpID; /* Grid root Vgroup ID */
806 2 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
807 :
808 :
809 : char *metabuf; /* Pointer to structural metadata (SM) */
810 : char *metaptrs[2];/* Pointers to begin and end of SM section */
811 : char gridname[80]; /* Grid Name */
812 : char *utlstr; /* Utility string */
813 :
814 : /* Allocate space for utility string */
815 : /* --------------------------------- */
816 2 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
817 2 : if(utlstr == NULL)
818 : {
819 0 : HEpush(DFE_NOSPACE,"GDgridinfo", __FILE__, __LINE__);
820 0 : return(-1);
821 : }
822 : /* Check Grid ID */
823 : /* ------------- */
824 2 : status = GDchkgdid(gridID, "GDgridinfo", &fid, &sdInterfaceID, &gdVgrpID);
825 :
826 2 : if (status == 0)
827 : {
828 : /* Get grid name */
829 : /* ------------- */
830 2 : int gID = gridID % idOffset;
831 2 : if (gID >= NGRID)
832 : {
833 0 : free(utlstr);
834 0 : return -1;
835 : }
836 2 : Vgetname(GDXGrid[gID].IDTable, gridname);
837 :
838 :
839 : /* Get pointers to grid structure section within SM */
840 : /* ------------------------------------------------ */
841 2 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
842 : NULL, metaptrs);
843 :
844 2 : if(metabuf == NULL)
845 : {
846 0 : free(utlstr);
847 0 : return(-1);
848 : }
849 :
850 :
851 : /* Get xdimsize if requested */
852 : /* ------------------------- */
853 2 : if (xdimsize != NULL)
854 : {
855 2 : statmeta = EHgetmetavalue(metaptrs, "XDim", utlstr);
856 2 : if (statmeta == 0)
857 : {
858 2 : *xdimsize = atoi(utlstr);
859 : }
860 : else
861 : {
862 0 : status = -1;
863 0 : HEpush(DFE_GENAPP, "GDgridinfo", __FILE__, __LINE__);
864 0 : HEreport("\"XDim\" string not found in metadata.\n");
865 : }
866 : }
867 :
868 :
869 : /* Get ydimsize if requested */
870 : /* ------------------------- */
871 2 : if (ydimsize != NULL)
872 : {
873 2 : statmeta = EHgetmetavalue(metaptrs, "YDim", utlstr);
874 2 : if (statmeta == 0)
875 : {
876 2 : *ydimsize = atoi(utlstr);
877 : }
878 : else
879 : {
880 0 : status = -1;
881 0 : HEpush(DFE_GENAPP, "GDgridinfo", __FILE__, __LINE__);
882 0 : HEreport("\"YDim\" string not found in metadata.\n");
883 : }
884 : }
885 :
886 :
887 : /* Get upleftpt if requested */
888 : /* ------------------------- */
889 2 : if (upleftpt != NULL)
890 : {
891 1 : statmeta = EHgetmetavalue(metaptrs, "UpperLeftPointMtrs", utlstr);
892 1 : if (statmeta == 0)
893 : {
894 : /* If value is "DEFAULT" then return zeros */
895 : /* --------------------------------------- */
896 1 : if (strcmp(utlstr, "DEFAULT") == 0)
897 : {
898 0 : upleftpt[0] = 0;
899 0 : upleftpt[1] = 0;
900 : }
901 : else
902 : {
903 1 : sscanf(utlstr, "(%lf,%lf)",
904 : &upleftpt[0], &upleftpt[1]);
905 : }
906 : }
907 : else
908 : {
909 0 : status = -1;
910 0 : HEpush(DFE_GENAPP, "GDgridinfo", __FILE__, __LINE__);
911 0 : HEreport(
912 : "\"UpperLeftPointMtrs\" string not found in metadata.\n");
913 : }
914 :
915 : }
916 :
917 : /* Get lowrightpt if requested */
918 : /* --------------------------- */
919 2 : if (lowrightpt != NULL)
920 : {
921 1 : statmeta = EHgetmetavalue(metaptrs, "LowerRightMtrs", utlstr);
922 1 : if (statmeta == 0)
923 : {
924 : /* If value is "DEFAULT" then return zeros */
925 1 : if (strcmp(utlstr, "DEFAULT") == 0)
926 : {
927 0 : lowrightpt[0] = 0;
928 0 : lowrightpt[1] = 0;
929 : }
930 : else
931 : {
932 1 : sscanf(utlstr, "(%lf,%lf)",
933 : &lowrightpt[0], &lowrightpt[1]);
934 : }
935 : }
936 : else
937 : {
938 0 : status = -1;
939 0 : HEpush(DFE_GENAPP, "GDgridinfo", __FILE__, __LINE__);
940 0 : HEreport(
941 : "\"LowerRightMtrs\" string not found in metadata.\n");
942 : }
943 : }
944 :
945 2 : free(metabuf);
946 : }
947 2 : free(utlstr);
948 2 : return (status);
949 : }
950 :
951 :
952 :
953 :
954 :
955 :
956 :
957 : /*----------------------------------------------------------------------------|
958 : | BEGIN_PROLOG |
959 : | |
960 : | FUNCTION: GDprojinfo |
961 : | |
962 : | DESCRIPTION: Returns GCTP projection code, zone code, spheroid code |
963 : | and projection parameters. |
964 : | |
965 : | |
966 : | Return Value Type Units Description |
967 : | ============ ====== ========= ===================================== |
968 : | status intn return status (0) SUCCEED, (-1) FAIL |
969 : | |
970 : | INPUTS: |
971 : | gridID int32 Grid structure ID |
972 : | |
973 : | OUTPUTS: |
974 : | projcode int32 GCTP projection code |
975 : | zonecode int32 UTM zone code |
976 : | spherecode int32 GCTP spheroid code |
977 : | projparm float64 Projection parameters |
978 : | |
979 : | NOTES: |
980 : | |
981 : | |
982 : | Date Programmer Description |
983 : | ====== ============ ================================================= |
984 : | Jun 96 Joel Gales Original Programmer |
985 : | Oct 96 Joel Gales Add check for no projection code |
986 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
987 : | Jun 00 Abe Taaheri Added support for EASE grid |
988 : | |
989 : | END_PROLOG |
990 : -----------------------------------------------------------------------------*/
991 : intn
992 1 : GDprojinfo(int32 gridID, int32 * projcode, int32 * zonecode,
993 : int32 * spherecode, float64 projparm[])
994 :
995 : {
996 : intn i; /* Loop index */
997 : intn projx; /* Loop index */
998 1 : intn status = 0; /* routine return status variable */
999 1 : intn statmeta = 0; /* EHgetmetavalue return status */
1000 :
1001 : int32 fid; /* HDF-EOS file ID */
1002 : int32 sdInterfaceID; /* HDF SDS interface ID */
1003 : int32 gdVgrpID; /* Grid root Vgroup ID */
1004 1 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
1005 :
1006 :
1007 : char *metabuf; /* Pointer to structural metadata (SM) */
1008 : char *metaptrs[2];/* Pointers to begin and end of SM section */
1009 : char gridname[80]; /* Grid Name */
1010 : char *utlstr; /* Utility string */
1011 : char fmt[96]; /* Format String */
1012 :
1013 : /* Allocate space for utility string */
1014 : /* --------------------------------- */
1015 1 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
1016 1 : if(utlstr == NULL)
1017 : {
1018 0 : HEpush(DFE_NOSPACE,"GDprojinfo", __FILE__, __LINE__);
1019 0 : return(-1);
1020 : }
1021 :
1022 : /* Check Grid ID */
1023 : /* ------------- */
1024 1 : status = GDchkgdid(gridID, "GDprojinfo", &fid, &sdInterfaceID, &gdVgrpID);
1025 :
1026 1 : if (status == 0)
1027 : {
1028 : /* Get grid name */
1029 : /* ------------- */
1030 1 : int gID = gridID % idOffset;
1031 1 : if (gID >= NGRID)
1032 : {
1033 0 : free(utlstr);
1034 0 : return -1;
1035 : }
1036 :
1037 1 : Vgetname(GDXGrid[gID].IDTable, gridname);
1038 :
1039 :
1040 : /* Get pointers to grid structure section within SM */
1041 : /* ------------------------------------------------ */
1042 1 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
1043 : NULL, metaptrs);
1044 :
1045 1 : if(metabuf == NULL)
1046 : {
1047 0 : free(utlstr);
1048 0 : return(-1);
1049 : }
1050 :
1051 :
1052 : /* Get projcode if requested */
1053 : /* ------------------------- */
1054 1 : if (projcode != NULL)
1055 : {
1056 1 : *projcode = -1;
1057 :
1058 1 : statmeta = EHgetmetavalue(metaptrs, "Projection", utlstr);
1059 1 : if (statmeta == 0)
1060 : {
1061 : /* Loop through projection codes until found */
1062 : /* ----------------------------------------- */
1063 1 : for (projx = 0; Projections[projx].projcode != -1; projx++)
1064 1 : if (strcmp(utlstr, Projections[projx].projname) == 0)
1065 1 : break;
1066 1 : if (Projections[projx].projname != NULL)
1067 1 : *projcode = Projections[projx].projcode;
1068 : }
1069 : else
1070 : {
1071 0 : status = -1;
1072 0 : HEpush(DFE_GENAPP, "GDprojinfo", __FILE__, __LINE__);
1073 0 : HEreport("Projection Code not defined for \"%s\".\n",
1074 : gridname);
1075 :
1076 0 : if (projparm != NULL)
1077 : {
1078 0 : for (i = 0; i < 13; i++)
1079 : {
1080 0 : projparm[i] = -1;
1081 : }
1082 : }
1083 : }
1084 : }
1085 :
1086 :
1087 : /* Get zonecode if requested */
1088 : /* ------------------------- */
1089 1 : if (projcode && zonecode != NULL)
1090 : {
1091 1 : *zonecode = -1;
1092 :
1093 :
1094 : /* Zone code only relevant for UTM and State Code projections */
1095 : /* ---------------------------------------------------------- */
1096 1 : if (*projcode == GCTP_UTM || *projcode == GCTP_SPCS)
1097 : {
1098 0 : statmeta = EHgetmetavalue(metaptrs, "ZoneCode", utlstr);
1099 0 : if (statmeta == 0)
1100 : {
1101 0 : *zonecode = atoi(utlstr);
1102 : }
1103 : else
1104 : {
1105 0 : status = -1;
1106 0 : HEpush(DFE_GENAPP, "GDprojinfo", __FILE__, __LINE__);
1107 0 : HEreport("Zone Code not defined for \"%s\".\n",
1108 : gridname);
1109 : }
1110 : }
1111 : }
1112 :
1113 :
1114 : /* Get projection parameters if requested */
1115 : /* -------------------------------------- */
1116 1 : if (projcode && projparm != NULL)
1117 : {
1118 :
1119 : /*
1120 : * Note: No projection parameters for GEO, UTM, and State Code
1121 : * projections
1122 : */
1123 1 : if (*projcode == GCTP_GEO || *projcode == GCTP_UTM ||
1124 0 : *projcode == GCTP_SPCS)
1125 : {
1126 14 : for (i = 0; i < 13; i++)
1127 : {
1128 13 : projparm[i] = 0.0;
1129 : }
1130 :
1131 : }
1132 : else
1133 : {
1134 0 : statmeta = EHgetmetavalue(metaptrs, "ProjParams", utlstr);
1135 :
1136 0 : if (statmeta == 0)
1137 : {
1138 :
1139 : /* Build format string to read projection parameters */
1140 : /* ------------------------------------------------- */
1141 0 : strcpy(fmt, "%lf,");
1142 0 : for (i = 1; i <= 11; i++)
1143 0 : strcat(fmt, "%lf,");
1144 0 : strcat(fmt, "%lf");
1145 :
1146 :
1147 : /* Read parameters from numeric list */
1148 : /* --------------------------------- */
1149 0 : sscanf(&utlstr[1], fmt,
1150 : &projparm[0], &projparm[1],
1151 : &projparm[2], &projparm[3],
1152 : &projparm[4], &projparm[5],
1153 : &projparm[6], &projparm[7],
1154 : &projparm[8], &projparm[9],
1155 : &projparm[10], &projparm[11],
1156 : &projparm[12]);
1157 : }
1158 : else
1159 : {
1160 0 : status = -1;
1161 0 : HEpush(DFE_GENAPP, "GDprojinfo", __FILE__, __LINE__);
1162 0 : HEreport("Projection parameters not defined for \"%s\".\n",
1163 : gridname);
1164 :
1165 : }
1166 : }
1167 : }
1168 :
1169 :
1170 : /* Get spherecode if requested */
1171 : /* --------------------------- */
1172 1 : if (projcode && spherecode != NULL)
1173 : {
1174 1 : *spherecode = 0;
1175 :
1176 : /* Note: Spherecode not defined for GEO projection */
1177 : /* ----------------------------------------------- */
1178 1 : if ((*projcode != GCTP_GEO))
1179 : {
1180 0 : EHgetmetavalue(metaptrs, "SphereCode", utlstr);
1181 0 : if (statmeta == 0)
1182 : {
1183 0 : *spherecode = atoi(utlstr);
1184 : }
1185 : }
1186 : }
1187 1 : free(metabuf);
1188 :
1189 : }
1190 1 : free(utlstr);
1191 1 : return (status);
1192 : }
1193 :
1194 :
1195 :
1196 : /*----------------------------------------------------------------------------|
1197 : | BEGIN_PROLOG |
1198 : | |
1199 : | FUNCTION: GDorigininfo |
1200 : | |
1201 : | DESCRIPTION: Returns origin code |
1202 : | |
1203 : | |
1204 : | Return Value Type Units Description |
1205 : | ============ ====== ========= ===================================== |
1206 : | status intn return status (0) SUCCEED, (-1) FAIL |
1207 : | |
1208 : | INPUTS: |
1209 : | gridID int32 Grid structure ID |
1210 : | |
1211 : | |
1212 : | OUTPUTS: |
1213 : | origincode int32 grid origin code |
1214 : | |
1215 : | NOTES: |
1216 : | |
1217 : | |
1218 : | Date Programmer Description |
1219 : | ====== ============ ================================================= |
1220 : | Jun 96 Joel Gales Original Programmer |
1221 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
1222 : | |
1223 : | END_PROLOG |
1224 : -----------------------------------------------------------------------------*/
1225 : intn
1226 0 : GDorigininfo(int32 gridID, int32 * origincode)
1227 : {
1228 : intn i; /* Loop index */
1229 0 : intn status = 0; /* routine return status variable */
1230 0 : intn statmeta = 0; /* EHgetmetavalue return status */
1231 :
1232 : int32 fid; /* HDF-EOS file ID */
1233 : int32 sdInterfaceID; /* HDF SDS interface ID */
1234 : int32 gdVgrpID; /* Grid root Vgroup ID */
1235 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
1236 :
1237 :
1238 : char *metabuf; /* Pointer to structural metadata (SM) */
1239 : char *metaptrs[2];/* Pointers to begin and end of SM section */
1240 : char gridname[80]; /* Grid Name */
1241 : char *utlstr; /* Utility string */
1242 :
1243 : /* Allocate space for utility string */
1244 : /* --------------------------------- */
1245 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
1246 0 : if(utlstr == NULL)
1247 : {
1248 0 : HEpush(DFE_NOSPACE,"GDorigininfo", __FILE__, __LINE__);
1249 0 : return(-1);
1250 : }
1251 : /* Check Grid ID */
1252 : /* ------------- */
1253 0 : status = GDchkgdid(gridID, "GDorigininfo",
1254 : &fid, &sdInterfaceID, &gdVgrpID);
1255 :
1256 :
1257 : /* Initialize pixreg code to -1 (in case of error) */
1258 : /* ----------------------------------------------- */
1259 0 : *origincode = -1;
1260 :
1261 0 : if (status == 0)
1262 : {
1263 : /* Set default origin code */
1264 : /* ----------------------- */
1265 0 : *origincode = 0;
1266 :
1267 :
1268 : /* Get grid name */
1269 : /* ------------- */
1270 0 : int gID = gridID % idOffset;
1271 0 : if (gID >= NGRID)
1272 : {
1273 0 : free(utlstr);
1274 0 : return -1;
1275 : }
1276 :
1277 0 : Vgetname(GDXGrid[gID].IDTable, gridname);
1278 :
1279 :
1280 : /* Get pointers to grid structure section within SM */
1281 : /* ------------------------------------------------ */
1282 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
1283 : NULL, metaptrs);
1284 :
1285 0 : if(metabuf == NULL)
1286 : {
1287 0 : free(utlstr);
1288 0 : return(-1);
1289 : }
1290 :
1291 :
1292 0 : statmeta = EHgetmetavalue(metaptrs, "GridOrigin", utlstr);
1293 :
1294 0 : if (statmeta == 0)
1295 : {
1296 : /*
1297 : * If "GridOrigin" string found in metadata then convert to
1298 : * numeric origin code (fixed added: Jan 97)
1299 : */
1300 0 : for (i = 0; i < (intn)(sizeof(originNames) / sizeof(originNames[0])); i++)
1301 : {
1302 0 : if (strcmp(utlstr, originNames[i]) == 0)
1303 : {
1304 0 : *origincode = i;
1305 0 : break;
1306 : }
1307 : }
1308 : }
1309 :
1310 0 : free(metabuf);
1311 : }
1312 0 : free(utlstr);
1313 0 : return (status);
1314 : }
1315 :
1316 :
1317 :
1318 :
1319 :
1320 :
1321 : /*----------------------------------------------------------------------------|
1322 : | BEGIN_PROLOG |
1323 : | |
1324 : | FUNCTION: GDpixreginfo |
1325 : | |
1326 : | DESCRIPTION: |
1327 : | |
1328 : | |
1329 : | Return Value Type Units Description |
1330 : | ============ ====== ========= ===================================== |
1331 : | status intn return status (0) SUCCEED, (-1) FAIL |
1332 : | |
1333 : | INPUTS: |
1334 : | gridID int32 Grid structure ID |
1335 : | |
1336 : | |
1337 : | OUTPUTS: |
1338 : | pixregcode int32 Pixel registration code |
1339 : | |
1340 : | |
1341 : | OUTPUTS: |
1342 : | None |
1343 : | |
1344 : | NOTES: |
1345 : | |
1346 : | |
1347 : | Date Programmer Description |
1348 : | ====== ============ ================================================= |
1349 : | Jun 96 Joel Gales Original Programmer |
1350 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
1351 : | |
1352 : | END_PROLOG |
1353 : -----------------------------------------------------------------------------*/
1354 : intn
1355 0 : GDpixreginfo(int32 gridID, int32 * pixregcode)
1356 : {
1357 : intn i; /* Loop index */
1358 0 : intn status = 0; /* routine return status variable */
1359 0 : intn statmeta = 0; /* EHgetmetavalue return status */
1360 :
1361 : int32 fid; /* HDF-EOS file ID */
1362 : int32 sdInterfaceID; /* HDF SDS interface ID */
1363 : int32 gdVgrpID; /* Grid root Vgroup ID */
1364 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
1365 :
1366 :
1367 : char *metabuf; /* Pointer to structural metadata (SM) */
1368 : char *metaptrs[2];/* Pointers to begin and end of SM section */
1369 : char gridname[80]; /* Grid Name */
1370 : char *utlstr; /* Utility string */
1371 :
1372 : /* Allocate space for utility string */
1373 : /* --------------------------------- */
1374 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
1375 0 : if(utlstr == NULL)
1376 : {
1377 0 : HEpush(DFE_NOSPACE,"GDpixreginfo", __FILE__, __LINE__);
1378 0 : return(-1);
1379 : }
1380 : /* Check Grid ID */
1381 0 : status = GDchkgdid(gridID, "GDpixreginfo",
1382 : &fid, &sdInterfaceID, &gdVgrpID);
1383 :
1384 : /* Initialize pixreg code to -1 (in case of error) */
1385 0 : *pixregcode = -1;
1386 :
1387 0 : if (status == 0)
1388 : {
1389 : /* Set default pixreg code */
1390 0 : *pixregcode = 0;
1391 :
1392 : /* Get grid name */
1393 0 : int gID = gridID % idOffset;
1394 0 : if (gID >= NGRID)
1395 : {
1396 0 : free(utlstr);
1397 0 : return -1;
1398 : }
1399 :
1400 0 : Vgetname(GDXGrid[gID].IDTable, gridname);
1401 :
1402 : /* Get pointers to grid structure section within SM */
1403 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
1404 : NULL, metaptrs);
1405 :
1406 0 : if(metabuf == NULL)
1407 : {
1408 0 : free(utlstr);
1409 0 : return(-1);
1410 : }
1411 :
1412 :
1413 0 : statmeta = EHgetmetavalue(metaptrs, "PixelRegistration", utlstr);
1414 :
1415 0 : if (statmeta == 0)
1416 : {
1417 : /*
1418 : * If "PixelRegistration" string found in metadata then convert
1419 : * to numeric origin code (fixed added: Jan 97)
1420 : */
1421 :
1422 0 : for (i = 0; i < (intn)(sizeof(pixregNames) / sizeof(pixregNames[0])); i++)
1423 : {
1424 0 : if (strcmp(utlstr, pixregNames[i]) == 0)
1425 : {
1426 0 : *pixregcode = i;
1427 0 : break;
1428 : }
1429 : }
1430 : }
1431 0 : free(metabuf);
1432 : }
1433 0 : free(utlstr);
1434 0 : return (status);
1435 : }
1436 :
1437 :
1438 :
1439 : /*----------------------------------------------------------------------------|
1440 : | BEGIN_PROLOG |
1441 : | |
1442 : | FUNCTION: GDcompinfo |
1443 : | |
1444 : | DESCRIPTION: |
1445 : | |
1446 : | |
1447 : | Return Value Type Units Description |
1448 : | ============ ====== ========= ===================================== |
1449 : | status intn |
1450 : | |
1451 : | INPUTS: |
1452 : | gridID int32 |
1453 : | compcode int32 |
1454 : | compparm intn |
1455 : | |
1456 : | |
1457 : | OUTPUTS: |
1458 : | None |
1459 : | |
1460 : | NOTES: |
1461 : | |
1462 : | |
1463 : | Date Programmer Description |
1464 : | ====== ============ ================================================= |
1465 : | Oct 96 Joel Gales Original Programmer |
1466 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
1467 : | |
1468 : | END_PROLOG |
1469 : -----------------------------------------------------------------------------*/
1470 : intn
1471 0 : GDcompinfo(int32 gridID, const char *fieldname, int32 * compcode, intn compparm[])
1472 : {
1473 : intn i; /* Loop index */
1474 0 : intn status = 0; /* routine return status variable */
1475 0 : intn statmeta = 0; /* EHgetmetavalue return status */
1476 :
1477 : int32 fid; /* HDF-EOS file ID */
1478 : int32 sdInterfaceID; /* HDF SDS interface ID */
1479 : int32 gdVgrpID; /* Grid root Vgroup ID */
1480 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
1481 :
1482 :
1483 : char *metabuf; /* Pointer to structural metadata (SM) */
1484 : char *metaptrs[2];/* Pointers to begin and end of SM section */
1485 : char gridname[80]; /* Grid Name */
1486 : char *utlstr;/* Utility string */
1487 :
1488 : /* Allocate space for utility string */
1489 : /* --------------------------------- */
1490 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
1491 0 : if(utlstr == NULL)
1492 : {
1493 0 : HEpush(DFE_NOSPACE,"GDcompinfo", __FILE__, __LINE__);
1494 0 : return(-1);
1495 : }
1496 : /* Check Grid ID */
1497 0 : status = GDchkgdid(gridID, "GDcompinfo", &fid, &sdInterfaceID, &gdVgrpID);
1498 :
1499 :
1500 0 : if (status == 0)
1501 : {
1502 : /* Get grid name */
1503 0 : int gID = gridID % idOffset;
1504 0 : if (gID >= NGRID)
1505 : {
1506 0 : free(utlstr);
1507 0 : return -1;
1508 : }
1509 0 : Vgetname(GDXGrid[gID].IDTable, gridname);
1510 :
1511 : /* Get pointers to "DataField" section within SM */
1512 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
1513 : "DataField", metaptrs);
1514 0 : if(metabuf == NULL)
1515 : {
1516 0 : free(utlstr);
1517 0 : return(-1);
1518 : }
1519 :
1520 :
1521 : /* Search for field */
1522 0 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "\"", fieldname, "\"\n");
1523 0 : metaptrs[0] = strstr(metaptrs[0], utlstr);
1524 :
1525 :
1526 : /* If field found and user wants compression code ... */
1527 0 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
1528 : {
1529 0 : if (compcode != NULL)
1530 : {
1531 : /* Set endptr at end of field's definition entry */
1532 0 : metaptrs[1] = strstr(metaptrs[0], "\t\t\tEND_OBJECT");
1533 :
1534 : /* Get compression type */
1535 0 : statmeta = EHgetmetavalue(metaptrs, "CompressionType", utlstr);
1536 :
1537 : /*
1538 : * Default is no compression if "CompressionType" string not
1539 : * in metadata
1540 : */
1541 0 : *compcode = HDFE_COMP_NONE;
1542 :
1543 : /* If compression code is found ... */
1544 0 : if (statmeta == 0)
1545 : {
1546 : /* Loop through compression types until match */
1547 0 : for (i = 0; i < (intn)(sizeof(HDFcomp) / sizeof(HDFcomp[0])); i++)
1548 : {
1549 0 : if (strcmp(utlstr, HDFcomp[i]) == 0)
1550 : {
1551 0 : *compcode = i;
1552 0 : break;
1553 : }
1554 : }
1555 : }
1556 : }
1557 :
1558 : /* If user wants compression parameters ... */
1559 0 : if (compparm != NULL && compcode != NULL)
1560 : {
1561 : /* Initialize to zero */
1562 0 : for (i = 0; i < 4; i++)
1563 : {
1564 0 : compparm[i] = 0;
1565 : }
1566 :
1567 : /*
1568 : * Get compression parameters if NBIT or DEFLATE compression
1569 : */
1570 0 : if (*compcode == HDFE_COMP_NBIT)
1571 : {
1572 : statmeta =
1573 0 : EHgetmetavalue(metaptrs, "CompressionParams", utlstr);
1574 0 : if (statmeta == 0)
1575 : {
1576 0 : sscanf(utlstr, "(%d,%d,%d,%d)",
1577 : &compparm[0], &compparm[1],
1578 : &compparm[2], &compparm[3]);
1579 : }
1580 : else
1581 : {
1582 0 : status = -1;
1583 0 : HEpush(DFE_GENAPP, "GDcompinfo", __FILE__, __LINE__);
1584 0 : HEreport(
1585 : "\"CompressionParams\" string not found in metadata.\n");
1586 : }
1587 : }
1588 0 : else if (*compcode == HDFE_COMP_DEFLATE)
1589 : {
1590 : statmeta =
1591 0 : EHgetmetavalue(metaptrs, "DeflateLevel", utlstr);
1592 0 : if (statmeta == 0)
1593 : {
1594 0 : sscanf(utlstr, "%d", &compparm[0]);
1595 : }
1596 : else
1597 : {
1598 0 : status = -1;
1599 0 : HEpush(DFE_GENAPP, "GDcompinfo", __FILE__, __LINE__);
1600 0 : HEreport(
1601 : "\"DeflateLevel\" string not found in metadata.\n");
1602 : }
1603 : }
1604 : }
1605 : }
1606 : else
1607 : {
1608 0 : HEpush(DFE_GENAPP, "GDcompinfo", __FILE__, __LINE__);
1609 0 : HEreport("Fieldname \"%s\" not found.\n", fieldname);
1610 : }
1611 :
1612 0 : free(metabuf);
1613 :
1614 : }
1615 0 : free(utlstr);
1616 0 : return (status);
1617 : }
1618 :
1619 :
1620 :
1621 :
1622 :
1623 :
1624 : /*----------------------------------------------------------------------------|
1625 : | BEGIN_PROLOG |
1626 : | |
1627 : | FUNCTION: GDfieldinfo |
1628 : | |
1629 : | DESCRIPTION: Retrieve information about a specific geolocation or data |
1630 : | field in the grid. |
1631 : | |
1632 : | |
1633 : | Return Value Type Units Description |
1634 : | ============ ====== ========= ===================================== |
1635 : | status intn return status (0) SUCCEED, (-1) FAIL |
1636 : | |
1637 : | INPUTS: |
1638 : | gridID int32 grid structure id |
1639 : | fieldname char name of field |
1640 : | |
1641 : | |
1642 : | OUTPUTS: |
1643 : | rank int32 rank of field (# of dims) |
1644 : | dims int32 field dimensions |
1645 : | numbertype int32 field number type |
1646 : | dimlist char field dimension list |
1647 : | |
1648 : | |
1649 : | OUTPUTS: |
1650 : | None |
1651 : | |
1652 : | NOTES: |
1653 : | |
1654 : | |
1655 : | Date Programmer Description |
1656 : | ====== ============ ================================================= |
1657 : | Jun 96 Joel Gales Original Programmer |
1658 : | Aug 96 Joel Gales Make metadata ODL compliant |
1659 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
1660 : | Feb 99 Abe Taaheri Changed memcpy to memmove to avoid overlapping |
1661 : | problem when copying strings |
1662 : | |
1663 : | END_PROLOG |
1664 : -----------------------------------------------------------------------------*/
1665 : intn
1666 101 : GDfieldinfo(int32 gridID, const char *fieldname, int32 * rank, int32 dims[],
1667 : int32 * numbertype, char *dimlist)
1668 :
1669 : {
1670 : intn i; /* Loop index */
1671 : intn status; /* routine return status variable */
1672 101 : intn statmeta = 0; /* EHgetmetavalue return status */
1673 :
1674 : int32 fid; /* HDF-EOS file ID */
1675 : int32 sdInterfaceID; /* HDF SDS interface ID */
1676 101 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
1677 101 : int32 ndims = 0; /* Number of dimensions */
1678 : int32 slen[8]; /* Length of each entry in parsed string */
1679 : int32 dum; /* Dummy variable */
1680 : int32 xdim; /* X dim size */
1681 : int32 ydim; /* Y dim size */
1682 : int32 sdid; /* SDS id */
1683 :
1684 : char *metabuf; /* Pointer to structural metadata (SM) */
1685 : char *metaptrs[2]; /* Pointers to begin and end of SM section */
1686 : char gridname[80]; /* Grid Name */
1687 : char *utlstr; /* Utility string */
1688 : char *ptr[8]; /* String pointers for parsed string */
1689 : char dimstr[64]; /* Individual dimension entry string */
1690 :
1691 :
1692 : /* Allocate space for utility string */
1693 : /* --------------------------------- */
1694 101 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
1695 101 : if(utlstr == NULL)
1696 : {
1697 0 : HEpush(DFE_NOSPACE,"GDfieldinfo", __FILE__, __LINE__);
1698 0 : return(-1);
1699 : }
1700 101 : *rank = -1;
1701 101 : *numbertype = -1;
1702 :
1703 101 : status = GDchkgdid(gridID, "GDfieldinfo", &fid, &sdInterfaceID, &dum);
1704 :
1705 101 : if (status == 0)
1706 : {
1707 101 : int gID = gridID % idOffset;
1708 101 : if (gID >= NGRID)
1709 : {
1710 0 : free(utlstr);
1711 0 : return -1;
1712 : }
1713 101 : Vgetname(GDXGrid[gID].IDTable, gridname);
1714 :
1715 101 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
1716 : "DataField", metaptrs);
1717 101 : if(metabuf == NULL)
1718 : {
1719 0 : free(utlstr);
1720 0 : return(-1);
1721 : }
1722 :
1723 :
1724 : /* Search for field */
1725 101 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "\"", fieldname, "\"\n");
1726 101 : metaptrs[0] = strstr(metaptrs[0], utlstr);
1727 :
1728 : /* If field found ... */
1729 101 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
1730 : {
1731 :
1732 : /* Set endptr at end of dimension definition entry */
1733 1 : metaptrs[1] = strstr(metaptrs[0], "\t\t\tEND_OBJECT");
1734 :
1735 : /* Get DataType string */
1736 1 : statmeta = EHgetmetavalue(metaptrs, "DataType", utlstr);
1737 :
1738 : /* Convert to numbertype code */
1739 1 : if (statmeta == 0)
1740 1 : *numbertype = EHnumstr(utlstr);
1741 : else
1742 : {
1743 0 : status = -1;
1744 0 : HEpush(DFE_GENAPP, "GDfieldinfo", __FILE__, __LINE__);
1745 0 : HEreport("\"DataType\" string not found in metadata.\n");
1746 : }
1747 :
1748 : /*
1749 : * Get DimList string and trim off leading and trailing parens
1750 : * "()"
1751 : */
1752 1 : statmeta = EHgetmetavalue(metaptrs, "DimList", utlstr);
1753 :
1754 1 : if (statmeta == 0)
1755 : {
1756 1 : const size_t len = strlen(utlstr);
1757 1 : if (len >= 2 && utlstr[0] == '(' && utlstr[len-1] == ')')
1758 : {
1759 0 : memmove(utlstr, utlstr + 1, len - 2);
1760 0 : utlstr[len - 2] = '\0';
1761 : }
1762 :
1763 : /* Parse trimmed DimList string and get rank */
1764 1 : ndims = EHparsestr(utlstr, ',', ptr, slen);
1765 1 : *rank = ndims;
1766 : }
1767 : else
1768 : {
1769 0 : status = -1;
1770 0 : HEpush(DFE_GENAPP, "GDfieldinfo", __FILE__, __LINE__);
1771 0 : HEreport("\"DimList\" string not found in metadata.\n");
1772 : }
1773 :
1774 :
1775 1 : if (status == 0)
1776 : {
1777 1 : status = GDgridinfo(gridID, &xdim, &ydim, NULL, NULL);
1778 :
1779 1 : for (i = 0; i < ndims; i++)
1780 : {
1781 0 : memcpy(dimstr, ptr[i] + 1, slen[i] - 2);
1782 0 : dimstr[slen[i] - 2] = 0;
1783 :
1784 0 : if (strcmp(dimstr, "XDim") == 0)
1785 : {
1786 0 : dims[i] = xdim;
1787 : }
1788 0 : else if (strcmp(dimstr, "YDim") == 0)
1789 : {
1790 0 : dims[i] = ydim;
1791 : }
1792 : else
1793 : {
1794 0 : dims[i] = GDdiminfo(gridID, dimstr);
1795 : }
1796 :
1797 :
1798 0 : if (dimlist != NULL)
1799 : {
1800 0 : if (i == 0)
1801 : {
1802 0 : dimlist[0] = 0;
1803 : }
1804 :
1805 0 : if (i > 0)
1806 : {
1807 0 : strcat(dimlist, ",");
1808 : }
1809 0 : strcat(dimlist, dimstr);
1810 : }
1811 : }
1812 :
1813 :
1814 1 : if (dims[0] == 0)
1815 : {
1816 1 : status = GDSDfldsrch(gridID, sdInterfaceID, fieldname,
1817 : &sdid, &dum, &dum, &dum, dims,
1818 : &dum);
1819 : }
1820 : }
1821 : }
1822 :
1823 101 : free(metabuf);
1824 : }
1825 :
1826 101 : if (*rank == -1)
1827 : {
1828 100 : status = -1;
1829 :
1830 100 : HEpush(DFE_GENAPP, "GDfieldinfo", __FILE__, __LINE__);
1831 100 : HEreport("Fieldname \"%s\" not found.\n", fieldname);
1832 : }
1833 101 : free(utlstr);
1834 101 : return (status);
1835 : }
1836 :
1837 :
1838 :
1839 : /*----------------------------------------------------------------------------|
1840 : | BEGIN_PROLOG |
1841 : | |
1842 : | FUNCTION: GDSDfldsrch |
1843 : | |
1844 : | DESCRIPTION: Retrieves information from SDS fields |
1845 : | |
1846 : | |
1847 : | Return Value Type Units Description |
1848 : | ============ ====== ========= ===================================== |
1849 : | status intn return status (0) SUCCEED, (-1) FAIL |
1850 : | |
1851 : | INPUTS: |
1852 : | gridID int32 grid structure ID |
1853 : | sdInterfaceID int32 SD interface ID |
1854 : | fieldname char field name |
1855 : | |
1856 : | |
1857 : | OUTPUTS: |
1858 : | sdid int32 SD element ID |
1859 : | rankSDS int32 Rank of SDS |
1860 : | rankFld int32 True rank of field (merging) |
1861 : | offset int32 Offset of field within merged field |
1862 : | dims int32 Dimensions of field |
1863 : | solo int32 Solo field flag |
1864 : | |
1865 : | NOTES: |
1866 : | |
1867 : | |
1868 : | Date Programmer Description |
1869 : | ====== ============ ================================================= |
1870 : | Jun 96 Joel Gales Original Programmer |
1871 : | Aug 96 Joel Gales Make metadata ODL compliant |
1872 : | |
1873 : | END_PROLOG |
1874 : -----------------------------------------------------------------------------*/
1875 : static intn
1876 1 : GDSDfldsrch(int32 gridID, int32 sdInterfaceID, const char *fieldname,
1877 : int32 * sdid, int32 * rankSDS, int32 * rankFld, int32 * offset,
1878 : int32 dims[], int32 * solo)
1879 : {
1880 : intn i; /* Loop index */
1881 1 : intn status = -1;/* routine return status variable */
1882 :
1883 : int32 gID; /* GridID - offset */
1884 1 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
1885 : int32 dum; /* Dummy variable */
1886 : int32 dums[128]; /* Dummy array */
1887 : int32 attrIndex; /* Attribute l_index */
1888 :
1889 : char name[2048]; /* Merged-Field Names */
1890 : char gridname[80]; /* Grid Name */
1891 : char *utlstr;/* Utility string */
1892 : char *metabuf; /* Pointer to structural metadata (SM) */
1893 : char *metaptrs[2];/* Pointers to begin and end of SM section */
1894 : #ifdef broken_logic
1895 : char *oldmetaptr; /* Pointer within SM section */
1896 : char *metaptr; /* Pointer within SM section */
1897 : #endif
1898 :
1899 : /* Allocate space for utility string */
1900 : /* --------------------------------- */
1901 1 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
1902 1 : if(utlstr == NULL)
1903 : {
1904 0 : HEpush(DFE_NOSPACE,"GDSDfldsrch", __FILE__, __LINE__);
1905 0 : return(-1);
1906 : }
1907 : /* Set solo flag to 0 (no) */
1908 : /* ----------------------- */
1909 1 : *solo = 0;
1910 :
1911 :
1912 : /* Compute "reduced" grid ID */
1913 : /* ------------------------- */
1914 1 : gID = gridID % idOffset;
1915 1 : if (gID >= NGRID)
1916 : {
1917 0 : free(utlstr);
1918 0 : return -1;
1919 : }
1920 :
1921 : /* Loop through all SDSs in grid */
1922 : /* ----------------------------- */
1923 1 : for (i = 0; i < GDXGrid[gID].nSDS; i++)
1924 : {
1925 : /* If active SDS ... */
1926 : /* ----------------- */
1927 0 : if (GDXGrid[gID].sdsID[i] != 0)
1928 : {
1929 : /* Get SDS ID, name, rankSDS, and dimensions */
1930 : /* ----------------------------------------- */
1931 0 : *sdid = GDXGrid[gID].sdsID[i];
1932 0 : SDgetinfo(*sdid, name, rankSDS, dims, &dum, &dum);
1933 0 : *rankFld = *rankSDS;
1934 :
1935 :
1936 : /* If merged field ... */
1937 : /* ------------------- */
1938 0 : if (strstr(name, "MRGFLD_") == &name[0])
1939 : {
1940 : /* Get grid name */
1941 : /* ------------- */
1942 0 : Vgetname(GDXGrid[gID].IDTable, gridname);
1943 :
1944 :
1945 : /* Get pointers to "MergedFields" section within SM */
1946 : /* ------------------------------------------------ */
1947 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
1948 : "MergedFields", metaptrs);
1949 0 : if(metabuf == NULL)
1950 : {
1951 0 : free(utlstr);
1952 0 : return(-1);
1953 : }
1954 :
1955 : #ifdef broken_logic
1956 : /* Initialize metaptr to beg. of section */
1957 : /* ------------------------------------- */
1958 : metaptr = metaptrs[0];
1959 :
1960 :
1961 : /* Store metaptr in order to recover */
1962 : /* --------------------------------- */
1963 : oldmetaptr = metaptr;
1964 :
1965 :
1966 : /* Search for Merged field name */
1967 : /* ---------------------------- */
1968 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "MergedFieldName=\"",
1969 : name, "\"\n");
1970 : metaptr = strstr(metaptr, utlstr);
1971 :
1972 :
1973 : /* If not found check for old metadata */
1974 : /* ----------------------------------- */
1975 : if (metaptr == NULL)
1976 : {
1977 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "OBJECT=\"", name, "\"\n");
1978 : metaptr = strstr(oldmetaptr, utlstr);
1979 : }
1980 : #endif
1981 :
1982 : /* Get field list and strip off leading and trailing quotes */
1983 : /* -------------------------------------------------------- */
1984 0 : EHgetmetavalue(metaptrs, "FieldList", name);
1985 0 : memmove(name, name + 1, strlen(name) - 2);
1986 0 : name[strlen(name) - 2] = 0;
1987 :
1988 :
1989 : /* Search for desired field within merged field list */
1990 : /* ------------------------------------------------- */
1991 0 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "\"", fieldname, "\"");
1992 0 : dum = EHstrwithin(utlstr, name, ',');
1993 :
1994 0 : free(metabuf);
1995 : }
1996 : else
1997 : {
1998 : /* If solo (unmerged) check if SDS name matches fieldname */
1999 : /* ------------------------------------------------------ */
2000 0 : dum = EHstrwithin(fieldname, name, ',');
2001 0 : if (dum != -1)
2002 : {
2003 0 : *solo = 1;
2004 0 : *offset = 0;
2005 : }
2006 : }
2007 :
2008 :
2009 :
2010 : /* If field found ... */
2011 : /* ------------------ */
2012 0 : if (dum != -1)
2013 : {
2014 0 : status = 0;
2015 :
2016 : /* If merged field ... */
2017 : /* ------------------- */
2018 0 : if (*solo == 0)
2019 : {
2020 : /* Get "Field Offsets" SDS attribute l_index */
2021 : /* --------------------------------------- */
2022 0 : attrIndex = SDfindattr(*sdid, "Field Offsets");
2023 :
2024 : /*
2025 : * If attribute exists then get offset of desired field
2026 : * within merged field
2027 : */
2028 0 : if (attrIndex != -1)
2029 : {
2030 0 : SDreadattr(*sdid, attrIndex, (VOIDP) dums);
2031 0 : *offset = dums[dum];
2032 : }
2033 :
2034 :
2035 : /* Get "Field Dims" SDS attribute l_index */
2036 : /* ------------------------------------ */
2037 0 : attrIndex = SDfindattr(*sdid, "Field Dims");
2038 :
2039 : /*
2040 : * If attribute exists then get 0th dimension of desired
2041 : * field within merged field
2042 : */
2043 0 : if (attrIndex != -1)
2044 : {
2045 0 : SDreadattr(*sdid, attrIndex, (VOIDP) dums);
2046 0 : dims[0] = dums[dum];
2047 :
2048 : /* If this dimension = 1 then field is really 2 dim */
2049 : /* ------------------------------------------------ */
2050 0 : if (dums[dum] == 1)
2051 : {
2052 0 : *rankFld = 2;
2053 : }
2054 : }
2055 : }
2056 :
2057 :
2058 : /* Break out of SDS loop */
2059 : /* --------------------- */
2060 0 : break;
2061 : } /* End of found field section */
2062 : }
2063 : else
2064 : {
2065 : /* First non-active SDS signifies no more, break out of SDS loop */
2066 : /* ------------------------------------------------------------- */
2067 0 : break;
2068 : }
2069 : }
2070 1 : free(utlstr);
2071 1 : return (status);
2072 : }
2073 :
2074 :
2075 :
2076 :
2077 : /*----------------------------------------------------------------------------|
2078 : | BEGIN_PROLOG |
2079 : | |
2080 : | FUNCTION: GDwrrdfield |
2081 : | |
2082 : | DESCRIPTION: Writes/Reads fields |
2083 : | |
2084 : | |
2085 : | Return Value Type Units Description |
2086 : | ============ ====== ========= ===================================== |
2087 : | status intn return status (0) SUCCEED, (-1) FAIL |
2088 : | |
2089 : | INPUTS: |
2090 : | gridID int32 grid structure ID |
2091 : | fieldname char fieldname |
2092 : | code char Write/Read code (w/r) |
2093 : | start int32 start array |
2094 : | stride int32 stride array |
2095 : | edge int32 edge array |
2096 : | datbuf void data buffer for read |
2097 : | |
2098 : | |
2099 : | OUTPUTS: |
2100 : | datbuf void data buffer for write |
2101 : | |
2102 : | |
2103 : | NOTES: |
2104 : | |
2105 : | |
2106 : | Date Programmer Description |
2107 : | ====== ============ ================================================= |
2108 : | Jun 96 Joel Gales Original Programmer |
2109 : | Feb 97 Joel Gales Stride = 1 HDF compression workaround |
2110 : | |
2111 : | END_PROLOG |
2112 : -----------------------------------------------------------------------------*/
2113 : static intn
2114 0 : GDwrrdfield(int32 gridID, const char *fieldname, const char *code,
2115 : int32 start[], int32 stride[], int32 edge[], VOIDP datbuf)
2116 :
2117 : {
2118 : intn i; /* Loop index */
2119 0 : intn status = 0; /* routine return status variable */
2120 :
2121 : int32 fid; /* HDF-EOS file ID */
2122 : int32 sdInterfaceID; /* HDF SDS interface ID */
2123 : int32 sdid; /* SDS ID */
2124 : int32 dum; /* Dummy variable */
2125 : int32 rankSDS; /* Rank of SDS */
2126 : int32 rankFld; /* Rank of field */
2127 :
2128 : int32 offset[8]; /* I/O offset (start) */
2129 : int32 incr[8]; /* I/O increment (stride) */
2130 : int32 count[8]; /* I/O count (edge) */
2131 : int32 dims[8]; /* Field/SDS dimensions */
2132 : int32 mrgOffset; /* Merged field offset */
2133 : int32 strideOne; /* Strides = 1 flag */
2134 :
2135 :
2136 : /* Check for valid grid ID */
2137 : /* ----------------------- */
2138 0 : status = GDchkgdid(gridID, "GDwrrdfield", &fid, &sdInterfaceID, &dum);
2139 :
2140 :
2141 0 : if (status == 0)
2142 : {
2143 : /* Check that field exists */
2144 : /* ----------------------- */
2145 0 : status = GDfieldinfo(gridID, fieldname, &rankSDS, dims, &dum, NULL);
2146 :
2147 :
2148 0 : if (status != 0)
2149 : {
2150 0 : HEpush(DFE_GENAPP, "GDwrrdfield", __FILE__, __LINE__);
2151 0 : HEreport("Fieldname \"%s\" does not exist.\n", fieldname);
2152 0 : status = -1;
2153 :
2154 : }
2155 :
2156 :
2157 0 : if (status == 0)
2158 : {
2159 0 : status = GDSDfldsrch(gridID, sdInterfaceID, fieldname, &sdid,
2160 : &rankSDS, &rankFld, &mrgOffset, dims, &dum);
2161 :
2162 :
2163 : /* Set I/O offset Section */
2164 : /* ---------------------- */
2165 :
2166 : /*
2167 : * If start == NULL (default) set I/O offset of 0th field to
2168 : * offset within merged field (if any) and the rest to 0
2169 : */
2170 0 : if (start == NULL)
2171 : {
2172 0 : for (i = 0; i < rankSDS; i++)
2173 : {
2174 0 : offset[i] = 0;
2175 : }
2176 0 : offset[0] = mrgOffset;
2177 : }
2178 : else
2179 : {
2180 : /*
2181 : * ... otherwise set I/O offset to user values, adjusting the
2182 : * 0th field with the merged field offset (if any)
2183 : */
2184 0 : if (rankFld == rankSDS)
2185 : {
2186 0 : for (i = 0; i < rankSDS; i++)
2187 : {
2188 0 : offset[i] = start[i];
2189 : }
2190 0 : offset[0] += mrgOffset;
2191 : }
2192 : else
2193 : {
2194 : /*
2195 : * If field really 2-dim merged in 3-dim field then set
2196 : * 0th field offset to merge offset and then next two to
2197 : * the user values
2198 : */
2199 0 : for (i = 0; i < rankFld; i++)
2200 : {
2201 0 : offset[i + 1] = start[i];
2202 : }
2203 0 : offset[0] = mrgOffset;
2204 : }
2205 : }
2206 :
2207 :
2208 :
2209 : /* Set I/O stride Section */
2210 : /* ---------------------- */
2211 :
2212 : /*
2213 : * If stride == NULL (default) set I/O stride to 1
2214 : */
2215 0 : if (stride == NULL)
2216 : {
2217 0 : for (i = 0; i < rankSDS; i++)
2218 : {
2219 0 : incr[i] = 1;
2220 : }
2221 : }
2222 : else
2223 : {
2224 : /*
2225 : * ... otherwise set I/O stride to user values
2226 : */
2227 0 : if (rankFld == rankSDS)
2228 : {
2229 0 : for (i = 0; i < rankSDS; i++)
2230 : {
2231 0 : incr[i] = stride[i];
2232 : }
2233 : }
2234 : else
2235 : {
2236 : /*
2237 : * If field really 2-dim merged in 3-dim field then set
2238 : * 0th field stride to 1 and then next two to the user
2239 : * values.
2240 : */
2241 0 : for (i = 0; i < rankFld; i++)
2242 : {
2243 0 : incr[i + 1] = stride[i];
2244 : }
2245 0 : incr[0] = 1;
2246 : }
2247 : }
2248 :
2249 :
2250 :
2251 : /* Set I/O count Section */
2252 : /* --------------------- */
2253 :
2254 : /*
2255 : * If edge == NULL (default) set I/O count to number of remaining
2256 : * entries (dims - start) / increment. Note that 0th field
2257 : * offset corrected for merged field offset (if any).
2258 : */
2259 0 : if (edge == NULL)
2260 : {
2261 0 : for (i = 1; i < rankSDS; i++)
2262 : {
2263 0 : count[i] = (dims[i] - offset[i]) / incr[i];
2264 : }
2265 0 : count[0] = (dims[0] - (offset[0] - mrgOffset)) / incr[0];
2266 : }
2267 : else
2268 : {
2269 : /*
2270 : * ... otherwise set I/O count to user values
2271 : */
2272 0 : if (rankFld == rankSDS)
2273 : {
2274 0 : for (i = 0; i < rankSDS; i++)
2275 : {
2276 0 : count[i] = edge[i];
2277 : }
2278 : }
2279 : else
2280 : {
2281 : /*
2282 : * If field really 2-dim merged in 3-dim field then set
2283 : * 0th field count to 1 and then next two to the user
2284 : * values.
2285 : */
2286 0 : for (i = 0; i < rankFld; i++)
2287 : {
2288 0 : count[i + 1] = edge[i];
2289 : }
2290 0 : count[0] = 1;
2291 : }
2292 : }
2293 :
2294 :
2295 : /* Perform I/O with relevant HDF I/O routine */
2296 : /* ----------------------------------------- */
2297 0 : if (strcmp(code, "w") == 0)
2298 : {
2299 : /* Set strideOne to true (1) */
2300 : /* ------------------------- */
2301 0 : strideOne = 1;
2302 :
2303 :
2304 : /* If incr[i] != 1 set strideOne to false (0) */
2305 : /* ------------------------------------------ */
2306 0 : for (i = 0; i < rankSDS; i++)
2307 : {
2308 0 : if (incr[i] != 1)
2309 : {
2310 0 : strideOne = 0;
2311 0 : break;
2312 : }
2313 : }
2314 :
2315 :
2316 : /*
2317 : * If strideOne is true use NULL parameter for stride. This
2318 : * is a work-around to HDF compression problem
2319 : */
2320 0 : if (strideOne == 1)
2321 : {
2322 0 : status = SDwritedata(sdid, offset, NULL, count,
2323 : (VOIDP) datbuf);
2324 : }
2325 : else
2326 : {
2327 0 : status = SDwritedata(sdid, offset, incr, count,
2328 : (VOIDP) datbuf);
2329 : }
2330 : }
2331 : else
2332 : {
2333 0 : status = SDreaddata(sdid, offset, incr, count,
2334 : (VOIDP) datbuf);
2335 : }
2336 : }
2337 : }
2338 :
2339 0 : return (status);
2340 : }
2341 :
2342 :
2343 : /*----------------------------------------------------------------------------|
2344 : | BEGIN_PROLOG |
2345 : | |
2346 : | FUNCTION: GDreadfield |
2347 : | |
2348 : | DESCRIPTION: Reads data from a grid field. |
2349 : | |
2350 : | |
2351 : | Return Value Type Units Description |
2352 : | ============ ====== ========= ===================================== |
2353 : | status intn return status (0) SUCCEED, (-1) FAIL |
2354 : | |
2355 : | INPUTS: |
2356 : | gridID int32 grid structure ID |
2357 : | fieldname char fieldname |
2358 : | start int32 start array |
2359 : | stride int32 stride array |
2360 : | edge int32 edge array |
2361 : | buffer void data buffer for read |
2362 : | |
2363 : | |
2364 : | OUTPUTS: |
2365 : | None |
2366 : | |
2367 : | NOTES: |
2368 : | |
2369 : | |
2370 : | Date Programmer Description |
2371 : | ====== ============ ================================================= |
2372 : | Jun 96 Joel Gales Original Programmer |
2373 : | |
2374 : | END_PROLOG |
2375 : -----------------------------------------------------------------------------*/
2376 : intn
2377 0 : GDreadfield(int32 gridID, const char *fieldname,
2378 : int32 start[], int32 stride[], int32 edge[], VOIDP buffer)
2379 :
2380 : {
2381 0 : intn status = 0; /* routine return status variable */
2382 :
2383 0 : status = GDwrrdfield(gridID, fieldname, "r", start, stride, edge,
2384 : buffer);
2385 0 : return (status);
2386 : }
2387 :
2388 :
2389 :
2390 :
2391 : /*----------------------------------------------------------------------------|
2392 : | BEGIN_PROLOG |
2393 : | |
2394 : | FUNCTION: GDwrrdattr |
2395 : | |
2396 : | DESCRIPTION: |
2397 : | |
2398 : | |
2399 : | Return Value Type Units Description |
2400 : | ============ ====== ========= ===================================== |
2401 : | status intn return status (0) SUCCEED, (-1) FAIL |
2402 : | |
2403 : | INPUTS: |
2404 : | gridID int32 grid structure ID |
2405 : | attrname char attribute name |
2406 : | numbertype int32 attribute HDF numbertype |
2407 : | count int32 Number of attribute elements |
2408 : | wrcode char Read/Write Code "w/r" |
2409 : | datbuf void I/O buffer |
2410 : | |
2411 : | OUTPUTS: |
2412 : | datbuf |
2413 : | |
2414 : | NOTES: |
2415 : | |
2416 : | |
2417 : | Date Programmer Description |
2418 : | ====== ============ ================================================= |
2419 : | Jun 96 Joel Gales Original Programmer |
2420 : | Oct 96 Joel Gales Get Attribute Vgroup ID from external array |
2421 : | |
2422 : | END_PROLOG |
2423 : -----------------------------------------------------------------------------*/
2424 : static intn
2425 0 : GDwrrdattr(int32 gridID, const char *attrname, int32 numbertype, int32 count,
2426 : const char *wrcode, VOIDP datbuf)
2427 :
2428 : {
2429 : intn status; /* routine return status variable */
2430 :
2431 : int32 fid; /* HDF-EOS file ID */
2432 : int32 attrVgrpID; /* Grid attribute ID */
2433 : int32 dum; /* dummy variable */
2434 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
2435 :
2436 :
2437 : /* Check Grid id */
2438 0 : status = GDchkgdid(gridID, "GDwrrdattr", &fid, &dum, &dum);
2439 :
2440 0 : if (status == 0)
2441 : {
2442 : /* Perform Attribute I/O */
2443 : /* --------------------- */
2444 0 : int gID = gridID % idOffset;
2445 0 : if (gID >= NGRID)
2446 : {
2447 0 : return -1;
2448 : }
2449 0 : attrVgrpID = GDXGrid[gID].VIDTable[1];
2450 0 : status = EHattr(fid, attrVgrpID, attrname, numbertype, count,
2451 : wrcode, datbuf);
2452 : }
2453 0 : return (status);
2454 : }
2455 :
2456 : /*----------------------------------------------------------------------------|
2457 : | BEGIN_PROLOG |
2458 : | |
2459 : | FUNCTION: GDreadattr |
2460 : | |
2461 : | DESCRIPTION: Reads attribute from a grid. |
2462 : | |
2463 : | |
2464 : | Return Value Type Units Description |
2465 : | ============ ====== ========= ===================================== |
2466 : | status intn return status (0) SUCCEED, (-1) FAIL |
2467 : | |
2468 : | INPUTS: |
2469 : | gridID int32 grid structure ID |
2470 : | attrname char attribute name |
2471 : | |
2472 : | OUTPUTS: |
2473 : | datbuf void I/O buffer |
2474 : | |
2475 : | NOTES: |
2476 : | |
2477 : | |
2478 : | Date Programmer Description |
2479 : | ====== ============ ================================================= |
2480 : | Jun 96 Joel Gales Original Programmer |
2481 : | |
2482 : | END_PROLOG |
2483 : -----------------------------------------------------------------------------*/
2484 : intn
2485 0 : GDreadattr(int32 gridID, const char *attrname, VOIDP datbuf)
2486 : {
2487 0 : intn status = 0; /* routine return status variable */
2488 0 : int32 dum = 0; /* dummy variable */
2489 :
2490 : /* Call GDwrrdattr routine to read attribute */
2491 : /* ----------------------------------------- */
2492 0 : status = GDwrrdattr(gridID, attrname, dum, dum, "r", datbuf);
2493 :
2494 0 : return (status);
2495 : }
2496 :
2497 :
2498 :
2499 :
2500 :
2501 : /*----------------------------------------------------------------------------|
2502 : | BEGIN_PROLOG |
2503 : | |
2504 : | FUNCTION: GDattrinfo |
2505 : | |
2506 : | DESCRIPTION: |
2507 : | |
2508 : | |
2509 : | Return Value Type Units Description |
2510 : | ============ ====== ========= ===================================== |
2511 : | status intn return status (0) SUCCEED, (-1) FAIL |
2512 : | |
2513 : | INPUTS: |
2514 : | gridID int32 grid structure ID |
2515 : | attrname char attribute name |
2516 : | |
2517 : | OUTPUTS: |
2518 : | numbertype int32 attribute HDF numbertype |
2519 : | count int32 Number of attribute elements |
2520 : | |
2521 : | |
2522 : | OUTPUTS: |
2523 : | None |
2524 : | |
2525 : | NOTES: |
2526 : | |
2527 : | |
2528 : | Date Programmer Description |
2529 : | ====== ============ ================================================= |
2530 : | Jun 96 Joel Gales Original Programmer |
2531 : | Oct 96 Joel Gales Get Attribute Vgroup ID from external array |
2532 : | |
2533 : | END_PROLOG |
2534 : -----------------------------------------------------------------------------*/
2535 : intn
2536 0 : GDattrinfo(int32 gridID, const char *attrname, int32 * numbertype, int32 * count)
2537 : {
2538 0 : intn status = 0; /* routine return status variable */
2539 :
2540 : int32 fid; /* HDF-EOS file ID */
2541 : int32 attrVgrpID; /* Grid attribute ID */
2542 : int32 dum; /* dummy variable */
2543 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
2544 :
2545 0 : status = GDchkgdid(gridID, "GDattrinfo", &fid, &dum, &dum);
2546 :
2547 0 : int gID = gridID % idOffset;
2548 0 : if (gID >= NGRID)
2549 : {
2550 0 : return -1;
2551 : }
2552 0 : attrVgrpID = GDXGrid[gID].VIDTable[1];
2553 :
2554 0 : status = EHattrinfo(fid, attrVgrpID, attrname, numbertype,
2555 : count);
2556 :
2557 0 : return (status);
2558 : }
2559 :
2560 :
2561 :
2562 :
2563 :
2564 :
2565 : /*----------------------------------------------------------------------------|
2566 : | BEGIN_PROLOG |
2567 : | |
2568 : | FUNCTION: GDinqattrs |
2569 : | |
2570 : | DESCRIPTION: |
2571 : | |
2572 : | |
2573 : | Return Value Type Units Description |
2574 : | ============ ====== ========= ===================================== |
2575 : | nattr int32 Number of attributes in swath struct |
2576 : | |
2577 : | INPUTS: |
2578 : | grid ID int32 grid structure ID |
2579 : | |
2580 : | OUTPUTS: |
2581 : | attrnames char Attribute names in swath struct |
2582 : | (Comma-separated list) |
2583 : | strbufsize int32 Attributes name list string length |
2584 : | |
2585 : | OUTPUTS: |
2586 : | None |
2587 : | |
2588 : | NOTES: |
2589 : | |
2590 : | |
2591 : | Date Programmer Description |
2592 : | ====== ============ ================================================= |
2593 : | Jun 96 Joel Gales Original Programmer |
2594 : | Oct 96 Joel Gales Initialize nattr |
2595 : | Oct 96 Joel Gales Get Attribute Vgroup ID from external array |
2596 : | |
2597 : | END_PROLOG |
2598 : -----------------------------------------------------------------------------*/
2599 : int32
2600 1 : GDinqattrs(int32 gridID, char *attrnames, int32 * strbufsize)
2601 : {
2602 : intn status; /* routine return status variable */
2603 :
2604 : int32 fid; /* HDF-EOS file ID */
2605 : int32 attrVgrpID; /* Grid attribute ID */
2606 : int32 dum; /* dummy variable */
2607 1 : int32 nattr = 0; /* Number of attributes */
2608 1 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
2609 :
2610 :
2611 : /* Check Grid id */
2612 1 : status = GDchkgdid(gridID, "GDinqattrs", &fid, &dum, &dum);
2613 :
2614 1 : if (status == 0)
2615 : {
2616 1 : int gID = gridID % idOffset;
2617 1 : if (gID >= NGRID)
2618 : {
2619 0 : return -1;
2620 : }
2621 1 : attrVgrpID = GDXGrid[gID].VIDTable[1];
2622 1 : nattr = EHattrcat(fid, attrVgrpID, attrnames, strbufsize);
2623 : }
2624 :
2625 1 : return (nattr);
2626 : }
2627 :
2628 :
2629 :
2630 :
2631 :
2632 :
2633 : #define REMQUOTE(x) do { \
2634 : char* l_x = x; \
2635 : const size_t l_x_len = strlen(l_x); \
2636 : if (l_x_len >= 2 && l_x[0] == '"' && l_x[l_x_len - 1] == '"') {\
2637 : memmove(l_x, l_x + 1, l_x_len - 2); \
2638 : l_x[l_x_len - 2] = 0; \
2639 : } \
2640 : } while(0)
2641 :
2642 :
2643 : /*----------------------------------------------------------------------------|
2644 : | BEGIN_PROLOG |
2645 : | |
2646 : | FUNCTION: GDinqdims |
2647 : | |
2648 : | DESCRIPTION: Retrieve information about all dimensions defined in a grid. |
2649 : | |
2650 : | |
2651 : | Return Value Type Units Description |
2652 : | ============ ====== ========= ===================================== |
2653 : | nDim int32 Number of defined dimensions |
2654 : | |
2655 : | INPUTS: |
2656 : | gridID int32 grid structure ID |
2657 : | |
2658 : | OUTPUTS: |
2659 : | dimnames char Dimension names (comma-separated) |
2660 : | dims int32 Dimension values |
2661 : | |
2662 : | |
2663 : | OUTPUTS: |
2664 : | None |
2665 : | |
2666 : | NOTES: |
2667 : | |
2668 : | |
2669 : | Date Programmer Description |
2670 : | ====== ============ ================================================= |
2671 : | Jun 96 Joel Gales Original Programmer |
2672 : | Aug 96 Joel Gales Make metadata ODL compliant |
2673 : | Feb 97 Joel Gales Set nDim to -1 if status = -1 |
2674 : | |
2675 : | END_PROLOG |
2676 : -----------------------------------------------------------------------------*/
2677 : int32
2678 0 : GDinqdims(int32 gridID, char *dimnames, int32 dims[])
2679 : {
2680 : intn status; /* routine return status variable */
2681 :
2682 : int32 fid; /* HDF-EOS file ID */
2683 : int32 sdInterfaceID; /* HDF SDS interface ID */
2684 : int32 gdVgrpID; /* Grid root Vgroup ID */
2685 : int32 size; /* Dimension size */
2686 0 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
2687 0 : int32 nDim = 0; /* Number of dimensions */
2688 :
2689 : char *metabuf; /* Pointer to structural metadata (SM) */
2690 : char *metaptrs[2];/* Pointers to begin and end of SM section */
2691 : char gridname[80]; /* Grid Name */
2692 : char *utlstr;/* Utility string */
2693 :
2694 : /* Allocate space for utility string */
2695 : /* --------------------------------- */
2696 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
2697 0 : if(utlstr == NULL)
2698 : {
2699 0 : HEpush(DFE_NOSPACE,"GDinqdims", __FILE__, __LINE__);
2700 0 : return(-1);
2701 : }
2702 : /* Check for valid grid id */
2703 : /* ----------------------- */
2704 0 : status = GDchkgdid(gridID, "GDinqdims", &fid, &sdInterfaceID, &gdVgrpID);
2705 :
2706 0 : if (status == 0)
2707 : {
2708 : /* If dimension names or sizes are requested */
2709 : /* ----------------------------------------- */
2710 0 : if (dimnames != NULL || dims != NULL)
2711 : {
2712 : /* Get grid name */
2713 : /* ------------- */
2714 0 : int gID = gridID % idOffset;
2715 0 : if (gID >= NGRID)
2716 : {
2717 0 : free(utlstr);
2718 0 : return -1;
2719 : }
2720 0 : Vgetname(GDXGrid[gID].IDTable, gridname);
2721 :
2722 :
2723 : /* Get pointers to "Dimension" section within SM */
2724 : /* --------------------------------------------- */
2725 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
2726 : "Dimension", metaptrs);
2727 0 : if(metabuf == NULL)
2728 : {
2729 0 : free(utlstr);
2730 0 : return(-1);
2731 : }
2732 :
2733 :
2734 : /* If dimension names are requested then "clear" name buffer */
2735 : /* --------------------------------------------------------- */
2736 0 : if (dimnames != NULL)
2737 : {
2738 0 : dimnames[0] = 0;
2739 : }
2740 :
2741 0 : while (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
2742 : {
2743 0 : strcpy(utlstr, "\t\tOBJECT=");
2744 0 : metaptrs[0] = strstr(metaptrs[0], utlstr);
2745 0 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
2746 : {
2747 : /* Get Dimension Name */
2748 : /* ------------------ */
2749 0 : if (dimnames != NULL)
2750 : {
2751 : /* Check 1st for old meta data then new */
2752 : /* ------------------------------------ */
2753 0 : EHgetmetavalue(metaptrs, "OBJECT", utlstr);
2754 0 : if (utlstr[0] != '"')
2755 : {
2756 0 : metaptrs[0] =
2757 0 : strstr(metaptrs[0], "\t\t\t\tDimensionName=");
2758 0 : EHgetmetavalue(metaptrs, "DimensionName", utlstr);
2759 : }
2760 :
2761 : /* Strip off double quotes */
2762 : /* ----------------------- */
2763 0 : memmove(utlstr, utlstr + 1, strlen(utlstr) - 2);
2764 0 : utlstr[strlen(utlstr) - 2] = 0;
2765 :
2766 0 : if (nDim > 0)
2767 : {
2768 0 : strcat(dimnames, ",");
2769 : }
2770 0 : strcat(dimnames, utlstr);
2771 : }
2772 :
2773 : /* Get Dimension Size */
2774 : /* ------------------ */
2775 0 : if (dims != NULL)
2776 : {
2777 0 : EHgetmetavalue(metaptrs, "Size", utlstr);
2778 0 : size = atoi(utlstr);
2779 0 : dims[nDim] = size;
2780 : }
2781 0 : nDim++;
2782 : }
2783 : }
2784 0 : free(metabuf);
2785 :
2786 : }
2787 : }
2788 :
2789 :
2790 : /* Set nDim to -1 if error status exists */
2791 : /* ------------------------------------- */
2792 0 : if (status == -1)
2793 : {
2794 0 : nDim = -1;
2795 : }
2796 0 : free(utlstr);
2797 0 : return (nDim);
2798 : }
2799 :
2800 :
2801 :
2802 :
2803 :
2804 :
2805 : /*----------------------------------------------------------------------------|
2806 : | BEGIN_PROLOG |
2807 : | |
2808 : | FUNCTION: GDinqfields |
2809 : | |
2810 : | DESCRIPTION: Retrieve information about all data fields defined in a grid. |
2811 : | |
2812 : | |
2813 : | Return Value Type Units Description |
2814 : | ============ ====== ========= ===================================== |
2815 : | nFld int32 Number of fields in swath |
2816 : | |
2817 : | INPUTS: |
2818 : | gridID int32 grid structure ID |
2819 : | |
2820 : | |
2821 : | OUTPUTS: |
2822 : | fieldlist char Field names (comma-separated) |
2823 : | rank int32 Array of ranks |
2824 : | numbertype int32 Array of HDF number types |
2825 : | |
2826 : | NOTES: |
2827 : | |
2828 : | |
2829 : | Date Programmer Description |
2830 : | ====== ============ ================================================= |
2831 : | Jun 96 Joel Gales Original Programmer |
2832 : | Aug 96 Joel Gales Make metadata ODL compliant |
2833 : | Feb 97 Joel Gales Set nFld to -1 if status = -1 |
2834 : | |
2835 : | END_PROLOG |
2836 : -----------------------------------------------------------------------------*/
2837 : int32
2838 3 : GDinqfields(int32 gridID, char *fieldlist, int32 rank[],
2839 : int32 numbertype[])
2840 : {
2841 : intn status; /* routine return status variable */
2842 :
2843 : int32 fid; /* HDF-EOS file ID */
2844 : int32 sdInterfaceID; /* HDF SDS interface ID */
2845 : int32 gdVgrpID; /* Grid root Vgroup ID */
2846 3 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
2847 3 : int32 nFld = 0; /* Number of mappings */
2848 : int32 slen[8]; /* String length array */
2849 :
2850 : char *metabuf; /* Pointer to structural metadata (SM) */
2851 : char *metaptrs[2];/* Pointers to begin and end of SM section */
2852 : char gridname[80]; /* Grid Name */
2853 : char *utlstr;/* Utility string */
2854 : char *ptr[8]; /* String pointer array */
2855 :
2856 : /* Allocate space for utility string */
2857 : /* --------------------------------- */
2858 3 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
2859 3 : if(utlstr == NULL)
2860 : {
2861 0 : HEpush(DFE_NOSPACE,"GDinqfields", __FILE__, __LINE__);
2862 0 : return(-1);
2863 : }
2864 : /* Check for valid grid id */
2865 : /* ----------------------- */
2866 3 : status = GDchkgdid(gridID, "GDinqfields", &fid, &sdInterfaceID, &gdVgrpID);
2867 3 : if (status == 0)
2868 : {
2869 :
2870 : /* If field names, ranks, or number types desired ... */
2871 : /* --------------------------------------------------- */
2872 3 : if (fieldlist != NULL || rank != NULL || numbertype != NULL)
2873 : {
2874 : /* Get grid name */
2875 : /* ------------- */
2876 3 : int gID = gridID % idOffset;
2877 3 : if (gID >= NGRID)
2878 : {
2879 0 : free(utlstr);
2880 0 : return -1;
2881 : }
2882 3 : Vgetname(GDXGrid[gID].IDTable, gridname);
2883 :
2884 :
2885 : /* Get pointers to "DataField" section within SM */
2886 : /* --------------------------------------------- */
2887 3 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
2888 : "DataField", metaptrs);
2889 3 : if(metabuf == NULL)
2890 : {
2891 0 : free(utlstr);
2892 0 : return(-1);
2893 : }
2894 :
2895 :
2896 : /* If field names are desired then "clear" name buffer */
2897 : /* --------------------------------------------------- */
2898 3 : if (fieldlist != NULL)
2899 : {
2900 3 : fieldlist[0] = 0;
2901 : }
2902 :
2903 :
2904 : /* Begin loop through mapping entries in metadata */
2905 : /* ---------------------------------------------- */
2906 : while (1)
2907 : {
2908 : /* Search for OBJECT string */
2909 : /* ------------------------ */
2910 104 : metaptrs[0] = strstr(metaptrs[0], "\t\tOBJECT=");
2911 :
2912 :
2913 : /* If found within "Data" Field metadata section .. */
2914 : /* ------------------------------------------------ */
2915 104 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
2916 : {
2917 : /* Get Fieldnames (if desired) */
2918 : /* --------------------------- */
2919 101 : if (fieldlist != NULL)
2920 : {
2921 : /* Check 1st for old meta data then new */
2922 : /* ------------------------------------ */
2923 101 : EHgetmetavalue(metaptrs, "OBJECT", utlstr);
2924 :
2925 : /*
2926 : * If OBJECT value begins with double quote then old
2927 : * metadata, field name is OBJECT value. Otherwise
2928 : * search for "DataFieldName" string
2929 : */
2930 :
2931 101 : if (utlstr[0] != '"')
2932 : {
2933 101 : strcpy(utlstr, "\t\t\t\t");
2934 101 : strcat(utlstr, "DataFieldName");
2935 101 : strcat(utlstr, "=");
2936 101 : metaptrs[0] = strstr(metaptrs[0], utlstr);
2937 101 : EHgetmetavalue(metaptrs, "DataFieldName", utlstr);
2938 : }
2939 :
2940 : /* Strip off double quotes */
2941 : /* ----------------------- */
2942 101 : REMQUOTE(utlstr);
2943 :
2944 :
2945 : /* Add to fieldlist */
2946 : /* ---------------- */
2947 101 : if (nFld > 0)
2948 : {
2949 98 : strcat(fieldlist, ",");
2950 : }
2951 101 : strcat(fieldlist, utlstr);
2952 :
2953 : }
2954 : /* Get Numbertype */
2955 101 : if (numbertype != NULL)
2956 : {
2957 101 : EHgetmetavalue(metaptrs, "DataType", utlstr);
2958 101 : numbertype[nFld] = EHnumstr(utlstr);
2959 : }
2960 : /*
2961 : * Get Rank (if desired) by counting # of dimensions in
2962 : * "DimList" string
2963 : */
2964 101 : if (rank != NULL)
2965 : {
2966 101 : EHgetmetavalue(metaptrs, "DimList", utlstr);
2967 101 : rank[nFld] = EHparsestr(utlstr, ',', ptr, slen);
2968 : }
2969 : /* Increment number of fields */
2970 101 : nFld++;
2971 : }
2972 : else
2973 : /* No more fields found */
2974 : {
2975 : break;
2976 : }
2977 : }
2978 3 : free(metabuf);
2979 : }
2980 : }
2981 :
2982 : /* Set nFld to -1 if error status exists */
2983 : /* ------------------------------------- */
2984 3 : if (status == -1)
2985 : {
2986 0 : nFld = -1;
2987 : }
2988 3 : free(utlstr);
2989 3 : return (nFld);
2990 : }
2991 :
2992 :
2993 :
2994 :
2995 :
2996 : /*----------------------------------------------------------------------------|
2997 : | BEGIN_PROLOG |
2998 : | |
2999 : | FUNCTION: GDnentries |
3000 : | |
3001 : | DESCRIPTION: Returns number of entries and descriptive string buffer |
3002 : | size for a specified entity. |
3003 : | |
3004 : | |
3005 : | Return Value Type Units Description |
3006 : | ============ ====== ========= ===================================== |
3007 : | nEntries int32 Number of entries |
3008 : | |
3009 : | INPUTS: |
3010 : | gridID int32 grid structure ID |
3011 : | entrycode int32 Entry code |
3012 : | HDFE_NENTDIM (0) |
3013 : | HDFE_NENTDFLD (4) |
3014 : | |
3015 : | |
3016 : | OUTPUTS: |
3017 : | strbufsize int32 Length of comma-separated list |
3018 : | (Does not include null-terminator |
3019 : | |
3020 : | NOTES: |
3021 : | |
3022 : | |
3023 : | Date Programmer Description |
3024 : | ====== ============ ================================================= |
3025 : | Jun 96 Joel Gales Original Programmer |
3026 : | Aug 96 Joel Gales Make metadata ODL compliant |
3027 : | Feb 97 Joel Gales Set nEntries to -1 if status = -1 |
3028 : | |
3029 : | END_PROLOG |
3030 : -----------------------------------------------------------------------------*/
3031 : int32
3032 53 : GDnentries(int32 gridID, int32 entrycode, int32 * strbufsize)
3033 :
3034 : {
3035 : intn status; /* routine return status variable */
3036 : intn i; /* Loop index */
3037 :
3038 : int32 fid; /* HDF-EOS file ID */
3039 : int32 sdInterfaceID; /* HDF SDS interface ID */
3040 : int32 gdVgrpID; /* Grid root Vgroup ID */
3041 53 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
3042 53 : int32 nEntries = 0; /* Number of entries */
3043 : int32 metaflag; /* Old (0), New (1) metadata flag) */
3044 53 : int32 nVal = 0; /* Number of strings to search for */
3045 :
3046 53 : char *metabuf = NULL; /* Pointer to structural metadata (SM) */
3047 53 : char *metaptrs[2] = {NULL, NULL};/* Pointers to begin and end of SM section */
3048 : char gridname[80]; /* Grid Name */
3049 : char *utlstr;/* Utility string */
3050 : char valName[2][32]; /* Strings to search for */
3051 :
3052 53 : memset(valName, 0, sizeof(valName));
3053 :
3054 : /* Allocate space for utility string */
3055 : /* --------------------------------- */
3056 53 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
3057 53 : if(utlstr == NULL)
3058 : {
3059 0 : HEpush(DFE_NOSPACE,"GDnentries", __FILE__, __LINE__);
3060 0 : return(-1);
3061 : }
3062 53 : status = GDchkgdid(gridID, "GDnentries", &fid, &sdInterfaceID, &gdVgrpID);
3063 :
3064 53 : if (status == 0)
3065 : {
3066 : /* Get grid name */
3067 53 : int gID = gridID % idOffset;
3068 53 : if (gID >= NGRID)
3069 : {
3070 0 : free(utlstr);
3071 0 : return -1;
3072 : }
3073 :
3074 53 : Vgetname(GDXGrid[gID].IDTable, gridname);
3075 :
3076 : /* Zero out string buffer size */
3077 53 : *strbufsize = 0;
3078 :
3079 :
3080 : /*
3081 : * Get pointer to relevant section within SM and Get names of
3082 : * metadata strings to inquire about
3083 : */
3084 53 : switch (entrycode)
3085 : {
3086 50 : case HDFE_NENTDIM:
3087 : {
3088 50 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
3089 : "Dimension", metaptrs);
3090 50 : if(metabuf == NULL)
3091 : {
3092 0 : free(utlstr);
3093 0 : return(-1);
3094 : }
3095 :
3096 50 : nVal = 1;
3097 50 : strcpy(&valName[0][0], "DimensionName");
3098 : }
3099 50 : break;
3100 :
3101 3 : case HDFE_NENTDFLD:
3102 : {
3103 3 : metabuf = (char *) EHmetagroup(sdInterfaceID, gridname, "g",
3104 : "DataField", metaptrs);
3105 3 : if(metabuf == NULL)
3106 : {
3107 0 : free(utlstr);
3108 0 : return(-1);
3109 : }
3110 :
3111 3 : nVal = 1;
3112 3 : strcpy(&valName[0][0], "DataFieldName");
3113 : }
3114 3 : break;
3115 : }
3116 :
3117 53 : if (!metabuf || metaptrs[0] == NULL)
3118 : {
3119 0 : free(metabuf);
3120 0 : free(utlstr);
3121 0 : return -1;
3122 : }
3123 :
3124 : /*
3125 : * Check for presence of 'GROUP="' string If found then old metadata,
3126 : * search on OBJECT string
3127 : */
3128 53 : metaflag = (strstr(metabuf, "GROUP=\"") == NULL) ? 1 : 0;
3129 53 : if (metaflag == 0)
3130 : {
3131 0 : nVal = 1;
3132 0 : strcpy(&valName[0][0], "\t\tOBJECT");
3133 : }
3134 :
3135 :
3136 : /* Begin loop through entries in metadata */
3137 : /* -------------------------------------- */
3138 : while (1)
3139 : {
3140 : /* Search for first string */
3141 154 : strcpy(utlstr, &valName[0][0]);
3142 154 : strcat(utlstr, "=");
3143 154 : metaptrs[0] = strstr(metaptrs[0], utlstr);
3144 :
3145 : /* If found within relevant metadata section ... */
3146 154 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
3147 : {
3148 202 : for (i = 0; i < nVal; i++)
3149 : {
3150 : /*
3151 : * Get all string values Don't count quotes
3152 : */
3153 101 : EHgetmetavalue(metaptrs, &valName[i][0], utlstr);
3154 101 : if( utlstr[0] == '"' && utlstr[strlen(utlstr)-1] == '"' )
3155 1 : *strbufsize += (int32)strlen(utlstr) - 2;
3156 : else
3157 100 : *strbufsize += (int32)strlen(utlstr);
3158 : }
3159 : /* Increment number of entries */
3160 101 : nEntries++;
3161 :
3162 : /* Go to end of OBJECT */
3163 101 : metaptrs[0] = strstr(metaptrs[0], "END_OBJECT");
3164 : }
3165 : else
3166 : /* No more entries found */
3167 : {
3168 : break;
3169 : }
3170 : }
3171 53 : free(metabuf);
3172 :
3173 :
3174 : /* Count comma separators & slashes (if mappings) */
3175 : /* ---------------------------------------------- */
3176 53 : if (nEntries > 0)
3177 : {
3178 3 : *strbufsize += nEntries - 1;
3179 3 : *strbufsize += (nVal - 1) * nEntries;
3180 : }
3181 : }
3182 :
3183 :
3184 : /* Set nEntries to -1 if error status exists */
3185 : /* ----------------------------------------- */
3186 53 : if (status == -1)
3187 : {
3188 0 : nEntries = -1;
3189 : }
3190 :
3191 53 : free(utlstr);
3192 53 : return (nEntries);
3193 : }
3194 :
3195 :
3196 :
3197 :
3198 :
3199 : /*----------------------------------------------------------------------------|
3200 : | BEGIN_PROLOG |
3201 : | |
3202 : | FUNCTION: GDinqgrid |
3203 : | |
3204 : | DESCRIPTION: Returns number and names of grid structures in file |
3205 : | |
3206 : | |
3207 : | Return Value Type Units Description |
3208 : | ============ ====== ========= ===================================== |
3209 : | nGrid int32 Number of grid structures in file |
3210 : | |
3211 : | INPUTS: |
3212 : | filename char HDF-EOS filename |
3213 : | |
3214 : | OUTPUTS: |
3215 : | gridlist char List of grid names (comma-separated) |
3216 : | strbufsize int32 Length of gridlist |
3217 : | |
3218 : | NOTES: |
3219 : | |
3220 : | |
3221 : | Date Programmer Description |
3222 : | ====== ============ ================================================= |
3223 : | Jun 96 Joel Gales Original Programmer |
3224 : | |
3225 : | END_PROLOG |
3226 : -----------------------------------------------------------------------------*/
3227 : int32
3228 14 : GDinqgrid(const char *filename, char *gridlist, int32 * strbufsize)
3229 : {
3230 : int32 nGrid; /* Number of grid structures in file */
3231 :
3232 : /* Call "EHinquire" routine */
3233 : /* ------------------------ */
3234 14 : nGrid = EHinquire(filename, "GRID", gridlist, strbufsize);
3235 :
3236 14 : return (nGrid);
3237 : }
3238 :
3239 :
3240 :
3241 : /*----------------------------------------------------------------------------|
3242 : | BEGIN_PROLOG |
3243 : | |
3244 : | FUNCTION: GDgetfillvalue |
3245 : | |
3246 : | DESCRIPTION: Retrieves fill value for a specified field. |
3247 : | |
3248 : | |
3249 : | Return Value Type Units Description |
3250 : | ============ ====== ========= ===================================== |
3251 : | status intn return status (0) SUCCEED, (-1) FAIL |
3252 : | |
3253 : | INPUTS: |
3254 : | gridID int32 grid structure ID |
3255 : | fieldname char field name |
3256 : | |
3257 : | OUTPUTS: |
3258 : | fillval void fill value |
3259 : | |
3260 : | NOTES: |
3261 : | |
3262 : | |
3263 : | Date Programmer Description |
3264 : | ====== ============ ================================================= |
3265 : | Jun 96 Joel Gales Original Programmer |
3266 : | |
3267 : | END_PROLOG |
3268 : -----------------------------------------------------------------------------*/
3269 : intn
3270 0 : GDgetfillvalue(int32 gridID, const char *fieldname, VOIDP fillval)
3271 : {
3272 : intn status; /* routine return status variable */
3273 :
3274 : int32 nt; /* Number type */
3275 : int32 dims[8]; /* Dimensions array */
3276 : int32 dum; /* Dummy variable */
3277 :
3278 : char name[80]; /* Fill value "attribute" name */
3279 :
3280 0 : status = GDchkgdid(gridID, "GDgetfillvalue", &dum, &dum, &dum);
3281 :
3282 : /* Check for valid grid ID */
3283 0 : if (status == 0)
3284 : {
3285 : /* Get field info */
3286 0 : status = GDfieldinfo(gridID, fieldname, &dum, dims, &nt, NULL);
3287 :
3288 0 : if (status == 0)
3289 : {
3290 : /* Read fill value attribute */
3291 0 : strcpy(name, "_FV_");
3292 0 : strcat(name, fieldname);
3293 0 : status = GDreadattr(gridID, name, fillval);
3294 : }
3295 : else
3296 : {
3297 0 : HEpush(DFE_GENAPP, "GDgetfillvalue", __FILE__, __LINE__);
3298 0 : HEreport("Fieldname \"%s\" does not exist.\n", fieldname);
3299 : }
3300 :
3301 : }
3302 0 : return (status);
3303 : }
3304 :
3305 :
3306 :
3307 :
3308 :
3309 : /*----------------------------------------------------------------------------|
3310 : | BEGIN_PROLOG |
3311 : | |
3312 : | FUNCTION: GDdetach |
3313 : | |
3314 : | DESCRIPTION: Detaches from grid interface and performs file housekeeping. |
3315 : | |
3316 : | |
3317 : | Return Value Type Units Description |
3318 : | ============ ====== ========= ===================================== |
3319 : | status intn return status (0) SUCCEED, (-1) FAIL |
3320 : | |
3321 : | INPUTS: |
3322 : | gridID int32 grid structure ID |
3323 : | |
3324 : | |
3325 : | OUTPUTS: |
3326 : | None |
3327 : | |
3328 : | NOTES: |
3329 : | |
3330 : | |
3331 : | Date Programmer Description |
3332 : | ====== ============ ================================================= |
3333 : | Jun 96 Joel Gales Original Programmer |
3334 : | Sep 96 Joel Gales Setup dim names for SDsetdimname in dimbuf1 rather |
3335 : | that utlstr |
3336 : | Oct 96 Joel Gales Detach Grid Vgroups |
3337 : | Oct 96 Joel Gales "Detach" from SDS |
3338 : | Nov 96 Joel Gales Call GDchkgdid to check for proper grid ID |
3339 : | Dec 96 Joel Gales Add multiple vertical subsetting garbage collection |
3340 : | Oct 98 Abe Taaheri Added GDXRegion[k]->DimNamePtr[i] =0; after freeing |
3341 : | memory |
3342 : | Sep 99 Abe Taaheri Changed memcpy to memmove because of overlapping |
3343 : | source and destination for GDXSDcomb, nameptr, and |
3344 : | dimptr. memcpy may cause unexpected results. |
3345 : | |
3346 : | END_PROLOG |
3347 : -----------------------------------------------------------------------------*/
3348 : intn
3349 3 : GDdetach(int32 gridID)
3350 :
3351 : {
3352 : intn i; /* Loop index */
3353 : intn k; /* Loop index */
3354 3 : intn status = 0; /* routine return status variable */
3355 :
3356 : int32 sdInterfaceID; /* SDS interface ID */
3357 : int32 gID; /* Grid ID - offset */
3358 3 : int32 idOffset = GDIDOFFSET; /* Grid ID offset */
3359 : int32 dum; /* Dummy variable */
3360 :
3361 : char gridname[VGNAMELENMAX + 1]; /* Grid name */
3362 :
3363 :
3364 3 : status = GDchkgdid(gridID, "GDdetach", &dum, &sdInterfaceID, &dum);
3365 :
3366 3 : if (status == 0)
3367 : {
3368 3 : gID = gridID % idOffset;
3369 3 : if (gID >= NGRID)
3370 : {
3371 0 : return -1;
3372 : }
3373 3 : Vgetname(GDXGrid[gID].IDTable, gridname);
3374 :
3375 :
3376 : /* "Detach" from previously attached SDSs */
3377 : /* -------------------------------------- */
3378 3 : for (k = 0; k < GDXGrid[gID].nSDS; k++)
3379 : {
3380 0 : SDendaccess(GDXGrid[gID].sdsID[k]);
3381 : }
3382 3 : free(GDXGrid[gID].sdsID);
3383 3 : GDXGrid[gID].sdsID = 0;
3384 3 : GDXGrid[gID].nSDS = 0;
3385 :
3386 :
3387 :
3388 : /* Detach Grid Vgroups */
3389 : /* ------------------- */
3390 3 : Vdetach(GDXGrid[gID].VIDTable[0]);
3391 3 : Vdetach(GDXGrid[gID].VIDTable[1]);
3392 3 : Vdetach(GDXGrid[gID].IDTable);
3393 :
3394 3 : GDXGrid[gID].active = 0;
3395 3 : GDXGrid[gID].VIDTable[0] = 0;
3396 3 : GDXGrid[gID].VIDTable[1] = 0;
3397 3 : GDXGrid[gID].IDTable = 0;
3398 3 : GDXGrid[gID].fid = 0;
3399 :
3400 :
3401 :
3402 :
3403 : /* Free Region Pointers */
3404 : /* -------------------- */
3405 771 : for (k = 0; k < NGRIDREGN; k++)
3406 : {
3407 768 : if (GDXRegion[k] != 0 &&
3408 0 : GDXRegion[k]->gridID == gridID)
3409 : {
3410 0 : for (i = 0; i < 8; i++)
3411 : {
3412 0 : if (GDXRegion[k]->DimNamePtr[i] != 0)
3413 : {
3414 0 : free(GDXRegion[k]->DimNamePtr[i]);
3415 0 : GDXRegion[k]->DimNamePtr[i] = 0;
3416 : }
3417 : }
3418 :
3419 0 : free(GDXRegion[k]);
3420 0 : GDXRegion[k] = 0;
3421 : }
3422 : }
3423 : }
3424 3 : return (status);
3425 : }
3426 :
3427 :
3428 : /*----------------------------------------------------------------------------|
3429 : | BEGIN_PROLOG |
3430 : | |
3431 : | FUNCTION: GDclose |
3432 : | |
3433 : | DESCRIPTION: Closes file. |
3434 : | |
3435 : | |
3436 : | Return Value Type Units Description |
3437 : | ============ ====== ========= ===================================== |
3438 : | status intn return status (0) SUCCEED, (-1) FAIL |
3439 : | |
3440 : | INPUTS: |
3441 : | fid int32 File ID |
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 11 : GDclose(int32 fid)
3458 :
3459 : {
3460 11 : intn status = 0; /* routine return status variable */
3461 :
3462 : /* Call EHclose to perform file close */
3463 : /* ---------------------------------- */
3464 11 : status = EHclose(fid);
3465 :
3466 11 : return (status);
3467 : }
3468 :
3469 :
3470 : /*----------------------------------------------------------------------------|
3471 : | BEGIN_PROLOG |
3472 : | |
3473 : | FUNCTION: GDgetdefaults |
3474 : | |
3475 : | DESCRIPTION: |
3476 : | |
3477 : | |
3478 : | Return Value Type Units Description |
3479 : | ============ ====== ========= ===================================== |
3480 : | status intn return status (0) SUCCEED, (-1) FAIL |
3481 : | |
3482 : | INPUTS: |
3483 : | projcode int32 GCTP projection code |
3484 : | zonecode int32 UTM zone code |
3485 : | projparm float64 Projection parameters |
3486 : | spherecode int32 GCTP spheroid code |
3487 : | upleftpt float64 upper left corner coordinates |
3488 : | lowrightpt float64 lower right corner coordinates |
3489 : | |
3490 : | |
3491 : | OUTPUTS: |
3492 : | upleftpt float64 upper left corner coordinates |
3493 : | lowrightpt float64 lower right corner coordinates |
3494 : | |
3495 : | NOTES: |
3496 : | |
3497 : | |
3498 : | Date Programmer Description |
3499 : | ====== ============ ================================================= |
3500 : | Aug 96 Joel Gales Original Programmer |
3501 : | Sep 96 Raj Gejjaga Fixed bugs in Polar Stereographic and Goode | | Homolosine default calculations. |
3502 : | Sep 96 Raj Gejjaga Added code to compute default boundary points |
3503 : | for Lambert Azimuthal Polar and Equatorial |
3504 : | projections. |
3505 : | Feb 97 Raj Gejjaga Added code to compute default boundary points |
3506 : | for Integerized Sinusoidal Grid. Added error |
3507 : | handling code. |
3508 : | Jun 00 Abe Taaheri Added support for EASE grid |
3509 : | |
3510 : | END_PROLOG |
3511 : -----------------------------------------------------------------------------*/
3512 : static intn
3513 0 : GDgetdefaults(int32 projcode, int32 zonecode, float64 projparm[],
3514 : int32 spherecode, float64 upleftpt[], float64 lowrightpt[])
3515 : {
3516 0 : int32 errorcode = 0, status = 0;
3517 : int32(*for_trans[100]) (double, double, double*, double*);
3518 :
3519 : float64 lon, lat, plat, x, y;
3520 : float64 plon, tlon, llon, rlon, pplon, LLon, LLat, RLon, RLat;
3521 :
3522 :
3523 : /* invoke GCTP initialization routine */
3524 : /* ---------------------------------- */
3525 0 : for_init(projcode, zonecode, projparm, spherecode, NULL, NULL,
3526 : &errorcode, for_trans);
3527 :
3528 : /* Report error if any */
3529 : /* ------------------- */
3530 0 : if (errorcode != 0)
3531 : {
3532 0 : status = -1;
3533 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3534 0 : HEreport("GCTP Error: %d\n", errorcode);
3535 0 : return (status);
3536 : }
3537 :
3538 : /* Compute Default Boundary Points for EASE Grid */
3539 : /* Use Global coverage */
3540 : /* ------------------------------------------------------ */
3541 0 : if (projcode == GCTP_BCEA &&
3542 0 : upleftpt[0] == 0 && upleftpt[1] == 0 &&
3543 0 : lowrightpt[0] == 0 && lowrightpt[1] == 0)
3544 : {
3545 0 : upleftpt[0] = EHconvAng(EASE_GRID_DEFAULT_UPLEFT_LON, HDFE_DEG_DMS);
3546 0 : upleftpt[1] = EHconvAng(EASE_GRID_DEFAULT_UPLEFT_LAT, HDFE_DEG_DMS);
3547 0 : lowrightpt[0] = EHconvAng(EASE_GRID_DEFAULT_LOWRGT_LON, HDFE_DEG_DMS);
3548 0 : lowrightpt[1] = EHconvAng(EASE_GRID_DEFAULT_LOWRGT_LAT, HDFE_DEG_DMS);
3549 : }
3550 :
3551 : /* Compute Default Boundary Points for CEA */
3552 : /* --------------------------------------------*/
3553 0 : if (projcode == GCTP_CEA &&
3554 0 : upleftpt[0] == 0 && upleftpt[1] == 0 &&
3555 0 : lowrightpt[0] == 0 && lowrightpt[1] == 0)
3556 : {
3557 0 : LLon = EHconvAng(EASE_GRID_DEFAULT_UPLEFT_LON, HDFE_DEG_RAD);
3558 0 : LLat = EHconvAng(EASE_GRID_DEFAULT_UPLEFT_LAT, HDFE_DEG_RAD);
3559 0 : RLon = EHconvAng(EASE_GRID_DEFAULT_LOWRGT_LON, HDFE_DEG_RAD);
3560 0 : RLat = EHconvAng(EASE_GRID_DEFAULT_LOWRGT_LAT, HDFE_DEG_RAD);
3561 :
3562 0 : errorcode = for_trans[projcode] (LLon, LLat, &x, &y);
3563 0 : if (errorcode != 0)
3564 : {
3565 0 : status = -1;
3566 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3567 0 : HEreport("GCTP Error: %d\n", errorcode);
3568 0 : return (status);
3569 : }
3570 0 : upleftpt[0] = x;
3571 0 : upleftpt[1] = y;
3572 :
3573 0 : errorcode = for_trans[projcode] (RLon, RLat, &x, &y);
3574 0 : if (errorcode != 0)
3575 : {
3576 0 : status = -1;
3577 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3578 0 : HEreport("GCTP Error: %d\n", errorcode);
3579 0 : return (status);
3580 : }
3581 0 : lowrightpt[0] = x;
3582 0 : lowrightpt[1] = y;
3583 :
3584 : }
3585 :
3586 :
3587 : /* Compute Default Boundary Points for Polar Sterographic */
3588 : /* ------------------------------------------------------ */
3589 0 : if (projcode == GCTP_PS &&
3590 0 : upleftpt[0] == 0 && upleftpt[1] == 0 &&
3591 0 : lowrightpt[0] == 0 && lowrightpt[1] == 0)
3592 : {
3593 : /*
3594 : * Convert the longitude and latitude from the DMS to decimal degree
3595 : * format.
3596 : */
3597 0 : plon = EHconvAng(projparm[4], HDFE_DMS_DEG);
3598 0 : plat = EHconvAng(projparm[5], HDFE_DMS_DEG);
3599 :
3600 : /*
3601 : * Compute the longitudes at 90, 180 and 270 degrees from the central
3602 : * longitude.
3603 : */
3604 :
3605 0 : if (plon <= 0.0)
3606 : {
3607 0 : tlon = 180.0 + plon;
3608 0 : pplon = plon + 360.0;
3609 : }
3610 : else
3611 : {
3612 0 : tlon = plon - 180.0;
3613 0 : pplon = plon;
3614 : }
3615 :
3616 0 : rlon = pplon + 90.0;
3617 0 : if (rlon > 360.0)
3618 0 : rlon = rlon - 360;
3619 :
3620 0 : if (rlon > 180.0)
3621 0 : rlon = rlon - 360.0;
3622 :
3623 0 : if (rlon <= 0.0)
3624 0 : llon = 180.0 + rlon;
3625 : else
3626 0 : llon = rlon - 180.0;
3627 :
3628 :
3629 : /* Convert all four longitudes from decimal degrees to radians */
3630 0 : plon = EHconvAng(plon, HDFE_DEG_RAD);
3631 0 : tlon = EHconvAng(tlon, HDFE_DEG_RAD);
3632 0 : llon = EHconvAng(llon, HDFE_DEG_RAD);
3633 0 : rlon = EHconvAng(rlon, HDFE_DEG_RAD);
3634 :
3635 0 : errorcode = for_trans[projcode] (llon, 0.0, &x, &y);
3636 0 : if (errorcode != 0)
3637 : {
3638 0 : status = -1;
3639 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3640 0 : HEreport("GCTP Error: %d\n", errorcode);
3641 0 : return (status);
3642 : }
3643 :
3644 0 : upleftpt[0] = x;
3645 :
3646 0 : errorcode = for_trans[projcode] (rlon, 0.0, &x, &y);
3647 0 : if (errorcode != 0)
3648 : {
3649 0 : status = -1;
3650 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3651 0 : HEreport("GCTP Error: %d\n", errorcode);
3652 0 : return (status);
3653 : }
3654 :
3655 0 : lowrightpt[0] = x;
3656 :
3657 : /*
3658 : * Compute the upperleft and lowright y values based on the south or
3659 : * north polar projection
3660 : */
3661 :
3662 0 : if (plat < 0.0)
3663 : {
3664 0 : errorcode = for_trans[projcode] (plon, 0.0, &x, &y);
3665 0 : if (errorcode != 0)
3666 : {
3667 0 : status = -1;
3668 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3669 0 : HEreport("GCTP Error: %d\n", errorcode);
3670 0 : return (status);
3671 : }
3672 :
3673 0 : upleftpt[1] = y;
3674 :
3675 0 : errorcode = for_trans[projcode] (tlon, 0.0, &x, &y);
3676 0 : if (errorcode != 0)
3677 : {
3678 0 : status = -1;
3679 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3680 0 : HEreport("GCTP Error: %d\n", errorcode);
3681 0 : return (status);
3682 : }
3683 :
3684 0 : lowrightpt[1] = y;
3685 :
3686 : }
3687 : else
3688 : {
3689 0 : errorcode = for_trans[projcode] (tlon, 0.0, &x, &y);
3690 0 : if (errorcode != 0)
3691 : {
3692 0 : status = -1;
3693 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3694 0 : HEreport("GCTP Error: %d\n", errorcode);
3695 0 : return (status);
3696 : }
3697 :
3698 0 : upleftpt[1] = y;
3699 :
3700 0 : errorcode = for_trans[projcode] (plon, 0.0, &x, &y);
3701 0 : if (errorcode != 0)
3702 : {
3703 0 : status = -1;
3704 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3705 0 : HEreport("GCTP Error: %d\n", errorcode);
3706 0 : return (status);
3707 : }
3708 :
3709 0 : lowrightpt[1] = y;
3710 :
3711 : }
3712 : }
3713 :
3714 :
3715 : /* Compute Default Boundary Points for Goode Homolosine */
3716 : /* ---------------------------------------------------- */
3717 0 : if (projcode == GCTP_GOOD &&
3718 0 : upleftpt[0] == 0 && upleftpt[1] == 0 &&
3719 0 : lowrightpt[0] == 0 && lowrightpt[1] == 0)
3720 : {
3721 0 : lon = EHconvAng(-180, HDFE_DEG_RAD);
3722 0 : lat = 0.0;
3723 :
3724 0 : errorcode = for_trans[projcode] (lon, lat, &x, &y);
3725 0 : if (errorcode != 0)
3726 : {
3727 0 : status = -1;
3728 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3729 0 : HEreport("GCTP Error: %d\n", errorcode);
3730 0 : return (status);
3731 : }
3732 :
3733 0 : upleftpt[0] = -fabs(x);
3734 0 : lowrightpt[0] = +fabs(x);
3735 :
3736 0 : lat = EHconvAng(90, HDFE_DEG_RAD);
3737 :
3738 0 : errorcode = for_trans[projcode] (lon, lat, &x, &y);
3739 0 : if (errorcode != 0)
3740 : {
3741 0 : status = -1;
3742 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3743 0 : HEreport("GCTP Error: %d\n", errorcode);
3744 0 : return (status);
3745 : }
3746 :
3747 0 : upleftpt[1] = +fabs(y);
3748 0 : lowrightpt[1] = -fabs(y);
3749 : }
3750 :
3751 : /* Compute Default Boundary Points for Lambert Azimuthal */
3752 : /* ----------------------------------------------------- */
3753 0 : if (projcode == GCTP_LAMAZ &&
3754 0 : upleftpt[0] == 0 && upleftpt[1] == 0 &&
3755 0 : lowrightpt[0] == 0 && lowrightpt[1] == 0)
3756 : {
3757 : /*
3758 : * Convert the longitude and latitude from the DMS to decimal degree
3759 : * format.
3760 : */
3761 0 : plon = EHconvAng(projparm[4], HDFE_DMS_DEG);
3762 0 : plat = EHconvAng(projparm[5], HDFE_DMS_DEG);
3763 :
3764 : /*
3765 : * Compute the longitudes at 90, 180 and 270 degrees from the central
3766 : * longitude.
3767 : */
3768 :
3769 0 : if (plon <= 0.0)
3770 : {
3771 0 : tlon = 180.0 + plon;
3772 0 : pplon = plon + 360.0;
3773 : }
3774 : else
3775 : {
3776 0 : tlon = plon - 180.0;
3777 0 : pplon = plon;
3778 : }
3779 :
3780 0 : rlon = pplon + 90.0;
3781 0 : if (rlon > 360.0)
3782 0 : rlon = rlon - 360;
3783 :
3784 0 : if (rlon > 180.0)
3785 0 : rlon = rlon - 360.0;
3786 :
3787 0 : if (rlon <= 0.0)
3788 0 : llon = 180.0 + rlon;
3789 : else
3790 0 : llon = rlon - 180.0;
3791 :
3792 : /* Convert all four longitudes from decimal degrees to radians */
3793 0 : plon = EHconvAng(plon, HDFE_DEG_RAD);
3794 0 : tlon = EHconvAng(tlon, HDFE_DEG_RAD);
3795 0 : llon = EHconvAng(llon, HDFE_DEG_RAD);
3796 0 : rlon = EHconvAng(rlon, HDFE_DEG_RAD);
3797 :
3798 0 : errorcode = for_trans[projcode] (llon, 0.0, &x, &y);
3799 0 : if (errorcode != 0)
3800 : {
3801 0 : status = -1;
3802 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3803 0 : HEreport("GCTP Error: %d\n", errorcode);
3804 0 : return (status);
3805 : }
3806 :
3807 0 : upleftpt[0] = x;
3808 :
3809 0 : errorcode = for_trans[projcode] (rlon, 0.0, &x, &y);
3810 0 : if (errorcode != 0)
3811 : {
3812 0 : status = -1;
3813 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3814 0 : HEreport("GCTP Error: %d\n", errorcode);
3815 0 : return (status);
3816 : }
3817 :
3818 0 : lowrightpt[0] = x;
3819 :
3820 : /*
3821 : * Compute upperleft and lowerright values based on whether the
3822 : * projection is south polar, north polar or equatorial
3823 : */
3824 :
3825 0 : if (plat == -90.0)
3826 : {
3827 0 : errorcode = for_trans[projcode] (plon, 0.0, &x, &y);
3828 0 : if (errorcode != 0)
3829 : {
3830 0 : status = -1;
3831 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3832 0 : HEreport("GCTP Error: %d\n", errorcode);
3833 0 : return (status);
3834 : }
3835 :
3836 0 : upleftpt[1] = y;
3837 :
3838 0 : errorcode = for_trans[projcode] (tlon, 0.0, &x, &y);
3839 0 : if (errorcode != 0)
3840 : {
3841 0 : status = -1;
3842 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3843 0 : HEreport("GCTP Error: %d\n", errorcode);
3844 0 : return (status);
3845 : }
3846 :
3847 0 : lowrightpt[1] = y;
3848 : }
3849 0 : else if (plat == 90.0)
3850 : {
3851 0 : errorcode = for_trans[projcode] (tlon, 0.0, &x, &y);
3852 0 : if (errorcode != 0)
3853 : {
3854 0 : status = -1;
3855 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3856 0 : HEreport("GCTP Error: %d\n", errorcode);
3857 0 : return (status);
3858 : }
3859 :
3860 0 : upleftpt[1] = y;
3861 :
3862 0 : errorcode = for_trans[projcode] (plon, 0.0, &x, &y);
3863 0 : if (errorcode != 0)
3864 : {
3865 0 : status = -1;
3866 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3867 0 : HEreport("GCTP Error: %d\n", errorcode);
3868 0 : return (status);
3869 : }
3870 :
3871 0 : lowrightpt[1] = y;
3872 : }
3873 : else
3874 : {
3875 0 : lat = EHconvAng(90, HDFE_DEG_RAD);
3876 0 : errorcode = for_trans[projcode] (plon, lat, &x, &y);
3877 0 : if (errorcode != 0)
3878 : {
3879 0 : status = -1;
3880 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3881 0 : HEreport("GCTP Error: %d\n", errorcode);
3882 0 : return (status);
3883 : }
3884 :
3885 0 : upleftpt[1] = y;
3886 :
3887 0 : lat = EHconvAng(-90, HDFE_DEG_RAD);
3888 0 : errorcode = for_trans[projcode] (plon, lat, &x, &y);
3889 0 : if (errorcode != 0)
3890 : {
3891 0 : status = -1;
3892 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3893 0 : HEreport("GCTP Error: %d\n", errorcode);
3894 0 : return (status);
3895 : }
3896 :
3897 0 : lowrightpt[1] = y;
3898 : }
3899 : }
3900 :
3901 : /* Compute Default Boundary Points for Integerized Sinusoidal Grid */
3902 : /* --------------------------------------------------------------- */
3903 0 : if (((projcode == GCTP_ISINUS) || (projcode == GCTP_ISINUS1)) &&
3904 0 : upleftpt[0] == 0 && upleftpt[1] == 0 &&
3905 0 : lowrightpt[0] == 0 && lowrightpt[1] == 0)
3906 : {
3907 : /*
3908 : * Convert the longitude and latitude from the DMS to decimal degree
3909 : * format.
3910 : */
3911 0 : plon = EHconvAng(projparm[4], HDFE_DMS_DEG);
3912 : /*plat = EHconvAng(projparm[5], HDFE_DMS_DEG); */
3913 :
3914 : /*
3915 : * Compute the longitudes at 90, 180 and 270 degrees from the central
3916 : * longitude.
3917 : */
3918 :
3919 0 : if (plon <= 0.0)
3920 : {
3921 0 : tlon = 180.0 + plon;
3922 0 : pplon = plon + 360.0;
3923 : }
3924 : else
3925 : {
3926 0 : tlon = plon - 180.0;
3927 0 : pplon = plon;
3928 : }
3929 :
3930 0 : rlon = pplon + 90.0;
3931 0 : if (rlon > 360.0)
3932 0 : rlon = rlon - 360;
3933 :
3934 0 : if (rlon > 180.0)
3935 0 : rlon = rlon - 360.0;
3936 :
3937 0 : if (rlon <= 0.0)
3938 0 : llon = 180.0 + rlon;
3939 : else
3940 0 : llon = rlon - 180.0;
3941 :
3942 : /* Convert all four longitudes from decimal degrees to radians */
3943 0 : plon = EHconvAng(plon, HDFE_DEG_RAD);
3944 0 : tlon = EHconvAng(tlon, HDFE_DEG_RAD);
3945 0 : llon = EHconvAng(llon, HDFE_DEG_RAD);
3946 0 : rlon = EHconvAng(rlon, HDFE_DEG_RAD);
3947 :
3948 0 : errorcode = for_trans[projcode] (llon, 0.0, &x, &y);
3949 0 : if (errorcode != 0)
3950 : {
3951 0 : status = -1;
3952 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3953 0 : HEreport("GCTP Error: %d\n", errorcode);
3954 0 : return (status);
3955 : }
3956 :
3957 0 : upleftpt[0] = x;
3958 :
3959 0 : errorcode = for_trans[projcode] (rlon, 0.0, &x, &y);
3960 0 : if (errorcode != 0)
3961 : {
3962 0 : status = -1;
3963 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3964 0 : HEreport("GCTP Error: %d\n", errorcode);
3965 0 : return (status);
3966 : }
3967 :
3968 0 : lowrightpt[0] = x;
3969 :
3970 0 : lat = EHconvAng(90, HDFE_DEG_RAD);
3971 0 : errorcode = for_trans[projcode] (plon, lat, &x, &y);
3972 0 : if (errorcode != 0)
3973 : {
3974 0 : status = -1;
3975 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3976 0 : HEreport("GCTP Error: %d\n", errorcode);
3977 0 : return (status);
3978 : }
3979 :
3980 0 : upleftpt[1] = y;
3981 :
3982 0 : lat = EHconvAng(-90, HDFE_DEG_RAD);
3983 0 : errorcode = for_trans[projcode] (plon, lat, &x, &y);
3984 0 : if (errorcode != 0)
3985 : {
3986 0 : status = -1;
3987 0 : HEpush(DFE_GENAPP, "GDgetdefaults", __FILE__, __LINE__);
3988 0 : HEreport("GCTP Error: %d\n", errorcode);
3989 0 : return (status);
3990 : }
3991 :
3992 0 : lowrightpt[1] = y;
3993 : }
3994 0 : return (errorcode);
3995 : }
3996 :
3997 : /*----------------------------------------------------------------------------|
3998 : | BEGIN_PROLOG |
3999 : | |
4000 : | FUNCTION: GDll2ij |
4001 : | |
4002 : | DESCRIPTION: |
4003 : | |
4004 : | |
4005 : | Return Value Type Units Description |
4006 : | ============ ====== ========= ===================================== |
4007 : | status intn return status (0) SUCCEED, (-1) FAIL |
4008 : | |
4009 : | INPUTS: |
4010 : | projcode int32 GCTP projection code |
4011 : | zonecode int32 UTM zone code |
4012 : | projparm float64 Projection parameters |
4013 : | spherecode int32 GCTP spheroid code |
4014 : | xdimsize int32 xdimsize from GDcreate |
4015 : | ydimsize int32 ydimsize from GDcreate |
4016 : | upleftpt float64 upper left corner coordinates |
4017 : | lowrightpt float64 lower right corner coordinates |
4018 : | npnts int32 number of lon-lat points |
4019 : | longitude float64 longitude array (radians) |
4020 : | latitude float64 latitude array (radians) |
4021 : | |
4022 : | OUTPUTS: |
4023 : | row int32 Row array |
4024 : | col int32 Column array |
4025 : | xval float64 X value array |
4026 : | yval float64 Y value array |
4027 : | |
4028 : | |
4029 : | NOTES: |
4030 : | |
4031 : | |
4032 : | Date Programmer Description |
4033 : | ====== ============ ================================================= |
4034 : | Jun 96 Joel Gales Original Programmer |
4035 : | Aug 96 Joel Gales Return x and y values if requested |
4036 : | Jun 00 Abe Taaheri Added support for EASE grid |
4037 : | |
4038 : | END_PROLOG |
4039 : -----------------------------------------------------------------------------*/
4040 : static intn
4041 0 : GDll2ij(int32 projcode, int32 zonecode, float64 projparm[],
4042 : int32 spherecode, int32 xdimsize, int32 ydimsize,
4043 : float64 upleftpt[], float64 lowrightpt[],
4044 : int32 npnts, float64 longitude[], float64 latitude[],
4045 : int32 row[], int32 col[], float64 xval[], float64 yval[])
4046 :
4047 :
4048 : {
4049 : intn i; /* Loop index */
4050 0 : intn status = 0; /* routine return status variable */
4051 :
4052 0 : int32 errorcode = 0; /* GCTP error code */
4053 : int32(*for_trans[100]) (double, double, double*, double*); /* GCTP function pointer */
4054 :
4055 : float64 xVal; /* Scaled x distance */
4056 : float64 yVal; /* Scaled y distance */
4057 : float64 xMtr; /* X value in meters from GCTP */
4058 : float64 yMtr; /* Y value in meters from GCTP */
4059 : float64 lonrad0; /* Longitude in radians of upleft point */
4060 0 : float64 latrad0 = 0; /* Latitude in radians of upleft point */
4061 : float64 lonrad; /* Longitude in radians of point */
4062 : float64 latrad; /* Latitude in radians of point */
4063 : float64 scaleX; /* X scale factor */
4064 : float64 scaleY; /* Y scale factor */
4065 0 : float64 xMtr0 = 0, xMtr1, yMtr0 = 0, yMtr1;
4066 : float64 lonrad1; /* Longitude in radians of lowright point */
4067 :
4068 : /* If projection not GEO call GCTP initialization routine */
4069 : /* ------------------------------------------------------ */
4070 0 : if (projcode != GCTP_GEO)
4071 : {
4072 0 : for_init(projcode, zonecode, projparm, spherecode, NULL, NULL,
4073 : &errorcode, for_trans);
4074 :
4075 : /* Report error if any */
4076 : /* ------------------- */
4077 0 : if (errorcode != 0)
4078 : {
4079 0 : status = -1;
4080 0 : HEpush(DFE_GENAPP, "GDll2ij", __FILE__, __LINE__);
4081 0 : HEreport("GCTP Error: %d\n", errorcode);
4082 : }
4083 : }
4084 :
4085 :
4086 0 : if (status == 0)
4087 : {
4088 : /* GEO projection */
4089 : /* -------------- */
4090 0 : if (projcode == GCTP_GEO)
4091 : {
4092 : /* Convert upleft and lowright X coords from DMS to radians */
4093 : /* -------------------------------------------------------- */
4094 0 : lonrad0 = EHconvAng(upleftpt[0], HDFE_DMS_RAD);
4095 0 : lonrad = EHconvAng(lowrightpt[0], HDFE_DMS_RAD);
4096 :
4097 : /* Compute x scale factor */
4098 : /* ---------------------- */
4099 0 : scaleX = (lonrad - lonrad0) / xdimsize;
4100 :
4101 :
4102 : /* Convert upleft and lowright Y coords from DMS to radians */
4103 : /* -------------------------------------------------------- */
4104 0 : latrad0 = EHconvAng(upleftpt[1], HDFE_DMS_RAD);
4105 0 : latrad = EHconvAng(lowrightpt[1], HDFE_DMS_RAD);
4106 :
4107 :
4108 : /* Compute y scale factor */
4109 : /* ---------------------- */
4110 0 : scaleY = (latrad - latrad0) / ydimsize;
4111 : }
4112 :
4113 : /* BCEA projection */
4114 : /* -------------- */
4115 0 : else if ( projcode == GCTP_BCEA)
4116 : {
4117 : /* Convert upleft and lowright X coords from DMS to radians */
4118 : /* -------------------------------------------------------- */
4119 :
4120 0 : lonrad0 = EHconvAng(upleftpt[0], HDFE_DMS_RAD);
4121 0 : lonrad = EHconvAng(lowrightpt[0], HDFE_DMS_RAD);
4122 :
4123 : /* Convert upleft and lowright Y coords from DMS to radians */
4124 : /* -------------------------------------------------------- */
4125 0 : latrad0 = EHconvAng(upleftpt[1], HDFE_DMS_RAD);
4126 0 : latrad = EHconvAng(lowrightpt[1], HDFE_DMS_RAD);
4127 :
4128 : /* Convert from lon/lat to meters(or whatever unit is, i.e unit
4129 : of r_major and r_minor) using GCTP */
4130 : /* ----------------------------------------- */
4131 0 : errorcode = for_trans[projcode] (lonrad0, latrad0, &xMtr0, &yMtr0);
4132 :
4133 :
4134 : /* Report error if any */
4135 : /* ------------------- */
4136 0 : if (errorcode != 0)
4137 : {
4138 0 : status = -1;
4139 0 : HEpush(DFE_GENAPP, "GDll2ij", __FILE__, __LINE__);
4140 0 : HEreport("GCTP Error: %d\n", errorcode);
4141 0 : return (status);
4142 : }
4143 :
4144 : /* Convert from lon/lat to meters(or whatever unit is, i.e unit
4145 : of r_major and r_minor) using GCTP */
4146 : /* ----------------------------------------- */
4147 0 : errorcode = for_trans[projcode] (lonrad, latrad, &xMtr1, &yMtr1);
4148 :
4149 :
4150 : /* Report error if any */
4151 : /* ------------------- */
4152 0 : if (errorcode != 0)
4153 : {
4154 0 : status = -1;
4155 0 : HEpush(DFE_GENAPP, "GDll2ij", __FILE__, __LINE__);
4156 0 : HEreport("GCTP Error: %d\n", errorcode);
4157 0 : return (status);
4158 : }
4159 :
4160 : /* Compute x scale factor */
4161 : /* ---------------------- */
4162 0 : scaleX = (xMtr1 - xMtr0) / xdimsize;
4163 :
4164 : /* Compute y scale factor */
4165 : /* ---------------------- */
4166 0 : scaleY = (yMtr1 - yMtr0) / ydimsize;
4167 : }
4168 : else
4169 : {
4170 : /* Non-GEO, Non_BCEA projections */
4171 : /* ---------------------------- */
4172 :
4173 : /* Compute x & y scale factors */
4174 : /* --------------------------- */
4175 0 : scaleX = (lowrightpt[0] - upleftpt[0]) / xdimsize;
4176 0 : scaleY = (lowrightpt[1] - upleftpt[1]) / ydimsize;
4177 : }
4178 :
4179 :
4180 :
4181 : /* Loop through all points */
4182 : /* ----------------------- */
4183 0 : for (i = 0; i < npnts; i++)
4184 : {
4185 : /* Convert lon & lat from decimal degrees to radians */
4186 : /* ------------------------------------------------- */
4187 0 : lonrad = EHconvAng(longitude[i], HDFE_DEG_RAD);
4188 0 : latrad = EHconvAng(latitude[i], HDFE_DEG_RAD);
4189 :
4190 :
4191 : /* GEO projection */
4192 : /* -------------- */
4193 0 : if (projcode == GCTP_GEO)
4194 : {
4195 : /* allow map to span dateline */
4196 0 : lonrad0 = EHconvAng(upleftpt[0], HDFE_DMS_RAD);
4197 0 : lonrad1 = EHconvAng(lowrightpt[0], HDFE_DMS_RAD);
4198 : /* if time-line is passed */
4199 0 : if(lonrad < lonrad1)
4200 : {
4201 0 : if (lonrad < lonrad0) lonrad += 2.0 * M_PI;
4202 0 : if (lonrad > lonrad1) lonrad -= 2.0 * M_PI;
4203 : }
4204 :
4205 : /* Compute scaled distance to point from origin */
4206 : /* -------------------------------------------- */
4207 0 : xVal = (lonrad - lonrad0) / scaleX;
4208 0 : yVal = (latrad - latrad0) / scaleY;
4209 : }
4210 : else
4211 : {
4212 : /* Convert from lon/lat to meters using GCTP */
4213 : /* ----------------------------------------- */
4214 0 : errorcode = for_trans[projcode] (lonrad, latrad, &xMtr, &yMtr);
4215 :
4216 :
4217 : /* Report error if any */
4218 : /* ------------------- */
4219 0 : if (errorcode != 0)
4220 : {
4221 : /*status = -1;
4222 : HEpush(DFE_GENAPP, "GDll2ij", __FILE__, __LINE__);
4223 : HEreport("GCTP Error: %d\n", errorcode);
4224 : return (status); */ /* Bruce Beaumont */
4225 0 : xVal = -2147483648.0; /* Bruce Beaumont */
4226 0 : yVal = -2147483648.0; /* Bruce Beaumont */
4227 : }/* (Note: MAXLONG is defined as 2147483647.0 in
4228 : function cproj.c of GCTP) */
4229 : else {
4230 : /* if projection is BCEA normalize x and y by cell size and
4231 : measure it from the upperleft corner of the grid */
4232 :
4233 : /* Compute scaled distance to point from origin */
4234 : /* -------------------------------------------- */
4235 0 : if( projcode == GCTP_BCEA)
4236 : {
4237 0 : xVal = (xMtr - xMtr0) / scaleX;
4238 0 : yVal = (yMtr - yMtr0) / scaleY;
4239 : }
4240 : else
4241 : {
4242 0 : xVal = (xMtr - upleftpt[0]) / scaleX;
4243 0 : yVal = (yMtr - upleftpt[1]) / scaleY;
4244 : }
4245 : }
4246 : }
4247 :
4248 :
4249 : /* Compute row and col from scaled distance */
4250 : /* ---------------------------------------- */
4251 0 : col[i] = (int32) xVal;
4252 0 : row[i] = (int32) yVal;
4253 :
4254 : /* Store scaled distances if requested */
4255 : /* ----------------------------------- */
4256 0 : if (xval != NULL)
4257 : {
4258 0 : xval[i] = xVal;
4259 : }
4260 :
4261 0 : if (yval != NULL)
4262 : {
4263 0 : yval[i] = yVal;
4264 : }
4265 : }
4266 : }
4267 0 : return (status);
4268 : }
4269 :
4270 : /*----------------------------------------------------------------------------|
4271 : | BEGIN_PROLOG |
4272 : | |
4273 : | FUNCTION: GDgetpixels |
4274 : | |
4275 : | DESCRIPTION: Finds row and columns for specified lon/lat values |
4276 : | |
4277 : | |
4278 : | Return Value Type Units Description |
4279 : | ============ ====== ========= ===================================== |
4280 : | status intn return status (0) SUCCEED, (-1) FAIL |
4281 : | |
4282 : | INPUTS: |
4283 : | gridID int32 Grid structure ID |
4284 : | nLonLat int32 Number of lonlat values |
4285 : | lonVal float64 dec deg Longitude values |
4286 : | latVal float64 dec deg Latitude values |
4287 : | |
4288 : | |
4289 : | OUTPUTS: |
4290 : | pixRow int32 Pixel rows |
4291 : | pixCol int32 Pixel columns |
4292 : | |
4293 : | NOTES: |
4294 : | |
4295 : | |
4296 : | Date Programmer Description |
4297 : | ====== ============ ================================================= |
4298 : | Aug 96 Joel Gales Original Programmer |
4299 : | Oct 96 Joel Gales Set row/col to -1 if outside boundary |
4300 : | Mar 97 Joel Gales Adjust row/col for CORNER pixel registration |
4301 : | |
4302 : | END_PROLOG |
4303 : -----------------------------------------------------------------------------*/
4304 : intn
4305 0 : GDgetpixels(int32 gridID, int32 nLonLat, float64 lonVal[], float64 latVal[],
4306 : int32 pixRow[], int32 pixCol[])
4307 : {
4308 : intn i; /* Loop index */
4309 0 : intn status = 0; /* routine return status variable */
4310 :
4311 : int32 fid; /* HDF-EOS file ID */
4312 : int32 sdInterfaceID; /* HDF SDS interface ID */
4313 : int32 gdVgrpID; /* Grid root Vgroup ID */
4314 :
4315 : int32 xdimsize; /* Size of "XDim" */
4316 : int32 ydimsize; /* Size of "YDim" */
4317 : int32 projcode; /* GCTP projection code */
4318 : int32 zonecode; /* Zone code */
4319 : int32 spherecode; /* Sphere code */
4320 : int32 origincode; /* Origin code */
4321 : int32 pixregcode; /* Pixel registration code */
4322 :
4323 : float64 upleftpt[2];/* Upper left point */
4324 : float64 lowrightpt[2]; /* Lower right point */
4325 : float64 projparm[16]; /* Projection parameters */
4326 : float64 *xVal; /* Pointer to point x location values */
4327 : float64 *yVal; /* Pointer to point y location values */
4328 :
4329 :
4330 : /* Check for valid grid ID */
4331 : /* ----------------------- */
4332 0 : status = GDchkgdid(gridID, "GDgetpixels", &fid, &sdInterfaceID, &gdVgrpID);
4333 :
4334 0 : if (status == 0)
4335 : {
4336 : /* Get grid info */
4337 : /* ------------- */
4338 0 : status = GDgridinfo(gridID, &xdimsize, &ydimsize,
4339 : upleftpt, lowrightpt);
4340 :
4341 :
4342 : /* Get projection info */
4343 : /* ------------------- */
4344 0 : status = GDprojinfo(gridID, &projcode, &zonecode,
4345 : &spherecode, projparm);
4346 :
4347 :
4348 : /* Get explicit upleftpt & lowrightpt if defaults are used */
4349 : /* ------------------------------------------------------- */
4350 0 : status = GDgetdefaults(projcode, zonecode, projparm, spherecode,
4351 : upleftpt, lowrightpt);
4352 :
4353 :
4354 : /* Get pixel registration and origin info */
4355 : /* -------------------------------------- */
4356 0 : status = GDorigininfo(gridID, &origincode);
4357 0 : status = GDpixreginfo(gridID, &pixregcode);
4358 :
4359 :
4360 : /* Allocate space for x & y locations */
4361 : /* ---------------------------------- */
4362 0 : xVal = (float64 *) calloc(nLonLat, sizeof(float64));
4363 0 : if(xVal == NULL)
4364 : {
4365 0 : HEpush(DFE_NOSPACE,"GDgetpixels", __FILE__, __LINE__);
4366 0 : return(-1);
4367 : }
4368 0 : yVal = (float64 *) calloc(nLonLat, sizeof(float64));
4369 0 : if(yVal == NULL)
4370 : {
4371 0 : HEpush(DFE_NOSPACE,"GDgetpixels", __FILE__, __LINE__);
4372 0 : free(xVal);
4373 0 : return(-1);
4374 : }
4375 :
4376 :
4377 : /* Get pixRow, pixCol, xVal, & yVal */
4378 : /* -------------------------------- */
4379 0 : status = GDll2ij(projcode, zonecode, projparm, spherecode,
4380 : xdimsize, ydimsize, upleftpt, lowrightpt,
4381 : nLonLat, lonVal, latVal, pixRow, pixCol,
4382 : xVal, yVal);
4383 :
4384 :
4385 :
4386 : /* Loop through all lon/lat values */
4387 : /* ------------------------------- */
4388 0 : for (i = 0; i < nLonLat; i++)
4389 : {
4390 : /* Adjust columns & rows for "corner" registered grids */
4391 : /* --------------------------------------------------- */
4392 0 : if (pixregcode == HDFE_CORNER)
4393 : {
4394 0 : if (origincode == HDFE_GD_UL)
4395 : {
4396 0 : if (xVal[i] - pixCol[i] > 0.5)
4397 : {
4398 0 : ++pixCol[i];
4399 : }
4400 :
4401 0 : if (yVal[i] - pixRow[i] > 0.5)
4402 : {
4403 0 : ++pixRow[i];
4404 : }
4405 : }
4406 0 : else if (origincode == HDFE_GD_UR)
4407 : {
4408 0 : if (xVal[i] - pixCol[i] <= 0.5)
4409 : {
4410 0 : --pixCol[i];
4411 : }
4412 :
4413 0 : if (yVal[i] - pixRow[i] > 0.5)
4414 : {
4415 0 : ++pixRow[i];
4416 : }
4417 : }
4418 0 : else if (origincode == HDFE_GD_LL)
4419 : {
4420 0 : if (xVal[i] - pixCol[i] > 0.5)
4421 : {
4422 0 : ++pixCol[i];
4423 : }
4424 :
4425 0 : if (yVal[i] - pixRow[i] <= 0.5)
4426 : {
4427 0 : --pixRow[i];
4428 : }
4429 : }
4430 0 : else if (origincode == HDFE_GD_LR)
4431 : {
4432 0 : if (xVal[i] - pixCol[i] <= 0.5)
4433 : {
4434 0 : --pixCol[i];
4435 : }
4436 :
4437 0 : if (yVal[i] - pixRow[i] <= 0.5)
4438 : {
4439 0 : --pixRow[i];
4440 : }
4441 : }
4442 : }
4443 :
4444 :
4445 : /* If outside grid boundaries then set to -1 */
4446 : /* ----------------------------------------- */
4447 0 : if (pixCol[i] < 0 || pixCol[i] >= xdimsize ||
4448 0 : pixRow[i] < 0 || pixRow[i] >= ydimsize)
4449 : {
4450 0 : pixCol[i] = -1;
4451 0 : pixRow[i] = -1;
4452 : }
4453 : }
4454 0 : free(xVal);
4455 0 : free(yVal);
4456 : }
4457 0 : return (status);
4458 : }
4459 :
4460 :
4461 :
4462 :
4463 :
4464 : /*----------------------------------------------------------------------------|
4465 : | BEGIN_PROLOG |
4466 : | |
4467 : | FUNCTION: GDgetpixvalues |
4468 : | |
4469 : | DESCRIPTION: Retrieves data from specified pixels. |
4470 : | |
4471 : | |
4472 : | Return Value Type Units Description |
4473 : | ============ ====== ========= ===================================== |
4474 : | size*nPixels int32 Size of data buffer |
4475 : | |
4476 : | INPUTS: |
4477 : | gridID int32 Grid structure ID |
4478 : | nPixels int32 Number of pixels |
4479 : | pixRow int32 Pixel row numbers |
4480 : | pixCol int32 Pixel column numbers |
4481 : | fieldname char Fieldname |
4482 : | |
4483 : | OUTPUTS: |
4484 : | buffer void Data buffer |
4485 : | |
4486 : | |
4487 : | NOTES: |
4488 : | |
4489 : | |
4490 : | Date Programmer Description |
4491 : | ====== ============ ================================================= |
4492 : | Aug 96 Joel Gales Original Programmer |
4493 : | Oct 96 Joel Gales Check for pixels outside boundaries (-1) |
4494 : | Mar 98 Abe Taaheri revised to reduce overhead for rechecking |
4495 : | for gridid, fieldname, etc in GDreadfield. |
4496 : | June 98 AT fixed bug with 2-dim field merged in 3-dim field |
4497 : | (for offset and count) |
4498 : | END_PROLOG |
4499 : -----------------------------------------------------------------------------*/
4500 : int32
4501 0 : GDgetpixvalues(int32 gridID, int32 nPixels, int32 pixRow[], int32 pixCol[],
4502 : const char *fieldname, VOIDP buffer)
4503 : {
4504 : intn i; /* Loop index */
4505 : intn j; /* Loop index */
4506 0 : intn status = 0; /* routine return status variable */
4507 :
4508 : int32 fid; /* HDF-EOS file ID */
4509 : int32 sdInterfaceID; /* HDF SDS interface ID */
4510 : int32 gdVgrpID; /* Grid root Vgroup ID */
4511 :
4512 : int32 start[8]; /* GDreadfield start array */
4513 : int32 edge[8]; /* GDreadfield edge array */
4514 : int32 dims[8]; /* Field dimensions */
4515 : int32 rank; /* Field rank */
4516 0 : int32 xdum = 0; /* Location of "XDim" within field list */
4517 0 : int32 ydum = 0; /* Location of "YDim" within field list */
4518 : int32 ntype; /* Field number type */
4519 : int32 origincode; /* Origin code */
4520 : int32 bufOffset; /* Data buffer offset */
4521 0 : int32 size = 0; /* Size of returned data buffer for each
4522 : * value in bytes */
4523 : int32 offset[8]; /* I/O offset (start) */
4524 : int32 incr[8]; /* I/O increment (stride) */
4525 : int32 count[8]; /* I/O count (edge) */
4526 : int32 sdid; /* SDS ID */
4527 : int32 rankSDS; /* Rank of SDS */
4528 : int32 rankFld; /* Rank of field */
4529 : int32 dum; /* Dummy variable */
4530 : int32 mrgOffset; /* Merged field offset */
4531 :
4532 : char *dimlist; /* Dimension list */
4533 :
4534 :
4535 :
4536 : /* Allocate space for dimlist */
4537 : /* --------------------------------- */
4538 0 : dimlist = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
4539 0 : if(dimlist == NULL)
4540 : {
4541 0 : HEpush(DFE_NOSPACE,"GDgetpixvalues", __FILE__, __LINE__);
4542 0 : return(-1);
4543 : }
4544 : /* Check for valid grid ID */
4545 : /* ----------------------- */
4546 0 : status = GDchkgdid(gridID, "GDgetpixvalues",
4547 : &fid, &sdInterfaceID, &gdVgrpID);
4548 :
4549 :
4550 0 : if (status == 0)
4551 : {
4552 : /* Get field list */
4553 : /* -------------- */
4554 0 : status = GDfieldinfo(gridID, fieldname, &rank, dims, &ntype, dimlist);
4555 :
4556 :
4557 : /* Check for "XDim" & "YDim" in dimension list */
4558 : /* ------------------------------------------- */
4559 0 : if (status == 0)
4560 : {
4561 0 : xdum = EHstrwithin("XDim", dimlist, ',');
4562 0 : ydum = EHstrwithin("YDim", dimlist, ',');
4563 :
4564 0 : if (xdum == -1)
4565 : {
4566 0 : status = -1;
4567 0 : HEpush(DFE_GENAPP, "GDgetpixvalues", __FILE__, __LINE__);
4568 0 : HEreport(
4569 : "\"XDim\" not present in dimlist for field: \"%s\".\n",
4570 : fieldname);
4571 : }
4572 :
4573 :
4574 0 : if (ydum == -1)
4575 : {
4576 0 : status = -1;
4577 0 : HEpush(DFE_GENAPP, "GDgetpixvalues", __FILE__, __LINE__);
4578 0 : HEreport(
4579 : "\"YDim\" not present in dimlist for field: \"%s\".\n",
4580 : fieldname);
4581 : }
4582 : }
4583 : else
4584 : {
4585 0 : status = -1;
4586 0 : HEpush(DFE_GENAPP, "GDgetpixvalues", __FILE__, __LINE__);
4587 0 : HEreport("Fieldname \"%s\" not found.\n", fieldname);
4588 : }
4589 :
4590 :
4591 0 : if (status == 0)
4592 : {
4593 :
4594 : /* Get origin order info */
4595 : /* --------------------- */
4596 0 : status = GDorigininfo(gridID, &origincode);
4597 :
4598 :
4599 : /* Initialize start & edge arrays */
4600 : /* ------------------------------ */
4601 0 : for (i = 0; i < rank; i++)
4602 : {
4603 0 : start[i] = 0;
4604 0 : edge[i] = dims[i];
4605 : }
4606 :
4607 :
4608 : /* Compute size of data buffer for each pixel */
4609 : /* ------------------------------------------ */
4610 0 : edge[xdum] = 1;
4611 0 : edge[ydum] = 1;
4612 0 : size = edge[0];
4613 0 : for (j = 1; j < rank; j++)
4614 : {
4615 0 : size *= edge[j];
4616 : }
4617 0 : size *= DFKNTsize(ntype);
4618 :
4619 :
4620 :
4621 : /* If data values are requested ... */
4622 : /* -------------------------------- */
4623 0 : if (buffer != NULL)
4624 : {
4625 : /* get sdid */
4626 0 : status = GDSDfldsrch(gridID, sdInterfaceID, fieldname, &sdid,
4627 : &rankSDS, &rankFld, &mrgOffset, dims, &dum);
4628 :
4629 : /* Loop through all pixels */
4630 : /* ----------------------- */
4631 0 : for (i = 0; i < nPixels; i++)
4632 : {
4633 : /* Conmpute offset within returned data buffer */
4634 : /* ------------------------------------------- */
4635 0 : bufOffset = size * i;
4636 :
4637 :
4638 : /* If pixel row & column OK ... */
4639 : /* ---------------------------- */
4640 0 : if (pixCol[i] != -1 && pixRow[i] != -1)
4641 : {
4642 0 : start[xdum] = pixCol[i];
4643 0 : start[ydum] = pixRow[i];
4644 :
4645 :
4646 : /* Adjust X-dim start if origin on right edge */
4647 : /* ------------------------------------------ */
4648 0 : if ((origincode & 1) == 1)
4649 : {
4650 0 : start[xdum] = dims[xdum] - (start[xdum] + 1);
4651 : }
4652 :
4653 :
4654 : /* Adjust Y-dim start if origin on lower edge */
4655 : /* ------------------------------------------ */
4656 0 : if ((origincode & 2) == 2)
4657 : {
4658 0 : start[ydum] = dims[ydum] - (start[ydum] + 1);
4659 : }
4660 :
4661 : /* Set I/O offset and count Section */
4662 : /* ---------------------- */
4663 :
4664 : /*
4665 : * start and edge != NULL, set I/O offset and count to
4666 : * user values, adjusting the
4667 : * 0th field with the merged field offset (if any)
4668 : */
4669 0 : if (rankFld == rankSDS)
4670 : {
4671 0 : for (j = 0; j < rankSDS; j++)
4672 : {
4673 0 : offset[j] = start[j];
4674 0 : count[j] = edge[j];
4675 : }
4676 0 : offset[0] += mrgOffset;
4677 : }
4678 : else
4679 : {
4680 : /*
4681 : * If field really 2-dim merged in 3-dim field then set
4682 : * 0th field offset to merge offset and then next two to
4683 : * the user values
4684 : */
4685 0 : for (j = 0; j < rankFld; j++)
4686 : {
4687 0 : offset[j + 1] = start[j];
4688 0 : count[j + 1] = edge[j];
4689 : }
4690 0 : offset[0] = mrgOffset;
4691 0 : count[0] = 1;
4692 : }
4693 :
4694 :
4695 :
4696 : /* Set I/O stride Section */
4697 : /* ---------------------- */
4698 :
4699 : /* In original code stride entered as NULL.
4700 : Abe Taaheri June 12, 1998 */
4701 : /*
4702 : * If stride == NULL (default) set I/O stride to 1
4703 : */
4704 0 : for (j = 0; j < rankSDS; j++)
4705 : {
4706 0 : incr[j] = 1;
4707 : }
4708 :
4709 :
4710 : /* Read into data buffer */
4711 : /* --------------------- */
4712 0 : status = SDreaddata(sdid,
4713 : offset, incr, count,
4714 : (VOIDP) ((uint8 *) buffer + bufOffset));
4715 : }
4716 : }
4717 : }
4718 : }
4719 : }
4720 :
4721 :
4722 : /* If successful return size of returned data in bytes */
4723 : /* --------------------------------------------------- */
4724 0 : if (status == 0)
4725 : {
4726 0 : free(dimlist);
4727 0 : return (size * nPixels);
4728 : }
4729 : else
4730 : {
4731 0 : free(dimlist);
4732 0 : return ((int32) status);
4733 : }
4734 : }
4735 :
4736 : /***********************************************
4737 : GDwrrdtile --
4738 : This function is the underlying function below GDwritetile and
4739 : GDreadtile.
4740 :
4741 :
4742 : Author--
4743 : Alexis Zubrow
4744 :
4745 : ********************************************************/
4746 :
4747 : static intn
4748 0 : GDwrrdtile(int32 gridID, const char *fieldname, const char *code, int32 start[],
4749 : VOIDP datbuf)
4750 : {
4751 : intn i; /* Loop index */
4752 0 : intn status = 0; /* routine return status variable */
4753 :
4754 : int32 fid; /* HDF-EOS file ID */
4755 : int32 sdInterfaceID; /* HDF SDS interface ID */
4756 : int32 sdid; /* SDS ID */
4757 :
4758 : int32 dum; /* Dummy variable */
4759 : int32 rankSDS; /* Rank of SDS/Field */
4760 :
4761 : int32 dims[8]; /* Field/SDS dimensions */
4762 : int32 tileFlags; /* flag to determine if field is tiled */
4763 : int32 numTileDims;/* number of tiles spanning a dimension */
4764 : HDF_CHUNK_DEF tileDef; /* union holding tiling info. */
4765 :
4766 :
4767 : /* Get gridID */
4768 0 : status = GDchkgdid(gridID, "GDwrrdtile", &fid, &sdInterfaceID, &dum);
4769 0 : if (status == 0)
4770 : {
4771 :
4772 : /* Get field info */
4773 0 : status = GDfieldinfo(gridID, fieldname, &rankSDS, dims, &dum, NULL);
4774 :
4775 0 : if (status == 0)
4776 : {
4777 :
4778 : /* Check whether fieldname is in SDS (multi-dim field) */
4779 : /* --------------------------------------------------- */
4780 0 : status = GDSDfldsrch(gridID, sdInterfaceID, fieldname, &sdid,
4781 : &rankSDS, &dum, &dum, dims, &dum);
4782 :
4783 :
4784 :
4785 : /*
4786 : * Check for errors in parameters passed to GDwritetile or
4787 : * GDreadtile
4788 : */
4789 :
4790 : /* Check if untiled field */
4791 0 : status = SDgetchunkinfo(sdid, &tileDef, &tileFlags);
4792 0 : if (tileFlags == HDF_NONE)
4793 : {
4794 0 : HEpush(DFE_GENAPP, "GDwrrdtile", __FILE__, __LINE__);
4795 0 : HEreport("Field \"%s\" is not tiled.\n", fieldname);
4796 0 : status = -1;
4797 0 : return (status);
4798 :
4799 : }
4800 :
4801 : /*
4802 : * Check if rd/wr tilecoords are within the extent of the field
4803 : */
4804 0 : for (i = 0; i < rankSDS; i++)
4805 : {
4806 : /*
4807 : * Calculate the number of tiles which span a dimension of
4808 : * the field
4809 : */
4810 0 : numTileDims = dims[i] / tileDef.chunk_lengths[i];
4811 0 : if ((start[i] >= numTileDims) || (start[i] < 0))
4812 : {
4813 : /*
4814 : * ERROR INDICATING BEYOND EXTENT OF THAT DIMENSION OR
4815 : * NEGATIVE TILECOORDS
4816 : */
4817 0 : HEpush(DFE_GENAPP, "GDwrrdtile", __FILE__, __LINE__);
4818 0 : HEreport("Tilecoords for dimension \"%d\" ...\n", i);
4819 0 : HEreport("is beyond the extent of dimension length\n");
4820 0 : status = -1;
4821 :
4822 : }
4823 : }
4824 :
4825 0 : if (status == -1)
4826 : {
4827 0 : return (status);
4828 : }
4829 :
4830 :
4831 : /* Actually write/read to the field */
4832 :
4833 0 : if (strcmp(code, "w") == 0) /* write tile */
4834 : {
4835 0 : status = SDwritechunk(sdid, start, (VOIDP) datbuf);
4836 : }
4837 0 : else if (strcmp(code, "r") == 0) /* read tile */
4838 : {
4839 0 : status = SDreadchunk(sdid, start, (VOIDP) datbuf);
4840 : }
4841 :
4842 :
4843 : }
4844 :
4845 : /* Non-existent fieldname */
4846 : else
4847 : {
4848 0 : HEpush(DFE_GENAPP, "GDwrrdtile", __FILE__, __LINE__);
4849 0 : HEreport("Fieldname \"%s\" does not exist.\n", fieldname);
4850 0 : status = -1;
4851 : }
4852 :
4853 : }
4854 :
4855 0 : return (status);
4856 : }
4857 :
4858 : /***********************************************
4859 : GDtileinfo --
4860 : This function queries the field to determine if it is tiled. If it is
4861 : tile, one can retrieve some of the characteristics of the tiles.
4862 :
4863 : Author-- Alexis Zubrow
4864 :
4865 : ********************************************************/
4866 :
4867 :
4868 : intn
4869 0 : GDtileinfo(int32 gridID, const char *fieldname, int32 * tilecode, int32 * tilerank,
4870 : int32 tiledims[])
4871 :
4872 : {
4873 : intn i; /* Loop index */
4874 0 : intn status = 0; /* routine return status variable */
4875 :
4876 : int32 fid; /* HDF-EOS file ID */
4877 : int32 sdInterfaceID; /* HDF SDS interface ID */
4878 : int32 sdid; /* SDS ID */
4879 :
4880 : int32 dum; /* Dummy variable */
4881 : int32 rankSDS; /* Rank of SDS/Field/tile */
4882 :
4883 : int32 dims[8]; /* Field/SDS dimensions */
4884 : int32 tileFlags; /* flag to determine if field is tiled */
4885 : HDF_CHUNK_DEF tileDef; /* union holding tiling info. */
4886 :
4887 :
4888 : /* Check if improper gridID */
4889 0 : status = GDchkgdid(gridID, "GDtileinfo", &fid, &sdInterfaceID, &dum);
4890 0 : if (status == 0)
4891 : {
4892 :
4893 : /* Get field info */
4894 0 : status = GDfieldinfo(gridID, fieldname, &rankSDS, dims, &dum, NULL);
4895 :
4896 0 : if (status == 0)
4897 : {
4898 :
4899 : /* Check whether fieldname is in SDS (multi-dim field) */
4900 : /* --------------------------------------------------- */
4901 0 : status = GDSDfldsrch(gridID, sdInterfaceID, fieldname, &sdid,
4902 : &rankSDS, &dum, &dum, dims, &dum);
4903 :
4904 :
4905 :
4906 : /* Query field for tiling information */
4907 0 : status = SDgetchunkinfo(sdid, &tileDef, &tileFlags);
4908 :
4909 : /* If field is untiled, return untiled flag */
4910 0 : if (tileFlags == HDF_NONE)
4911 : {
4912 0 : *tilecode = HDFE_NOTILE;
4913 0 : return (status);
4914 : }
4915 :
4916 : /* IF field is tiled or tiled with compression */
4917 0 : else if ((tileFlags == HDF_CHUNK) ||
4918 0 : (tileFlags == (HDF_CHUNK | HDF_COMP)))
4919 : {
4920 0 : if (tilecode != NULL)
4921 : {
4922 0 : *tilecode = HDFE_TILE;
4923 : }
4924 0 : if (tilerank != NULL)
4925 : {
4926 0 : *tilerank = rankSDS;
4927 : }
4928 0 : if (tiledims != NULL)
4929 : {
4930 : /* Assign size of tile dimensions */
4931 0 : for (i = 0; i < rankSDS; i++)
4932 : {
4933 0 : tiledims[i] = tileDef.chunk_lengths[i];
4934 : }
4935 : }
4936 : }
4937 : }
4938 :
4939 : /* Non-existent fieldname */
4940 : else
4941 : {
4942 0 : HEpush(DFE_GENAPP, "GDtileinfo", __FILE__, __LINE__);
4943 0 : HEreport("Fieldname \"%s\" does not exist.\n", fieldname);
4944 0 : status = -1;
4945 : }
4946 :
4947 : }
4948 0 : return (status);
4949 : }
4950 :
4951 : /***********************************************
4952 : GDreadtile --
4953 : This function reads one tile from a particular field.
4954 :
4955 :
4956 : Author--
4957 : Alexis Zubrow
4958 :
4959 : ********************************************************/
4960 :
4961 : intn
4962 0 : GDreadtile(int32 gridID, const char *fieldname, int32 tilecoords[],
4963 : VOIDP tileData)
4964 : {
4965 0 : char code[] = "r"; /* read tile code */
4966 0 : intn status = 0; /* routine return status variable */
4967 :
4968 0 : status = GDwrrdtile(gridID, fieldname, code, tilecoords, tileData);
4969 :
4970 0 : return (status);
4971 : }
4972 :
4973 : /*----------------------------------------------------------------------------|
4974 : | BEGIN_PROLOG |
4975 : | |
4976 : | FUNCTION: GDsdid |
4977 : | |
4978 : | DESCRIPTION: Returns SD element ID for grid field |
4979 : | |
4980 : | |
4981 : | Return Value Type Units Description |
4982 : | ============ ====== ========= ===================================== |
4983 : | status intn return status (0) SUCCEED, (-1) FAIL |
4984 : | |
4985 : | INPUTS: |
4986 : | gridID int32 grid structure ID |
4987 : | fieldname const char field name |
4988 : | |
4989 : | |
4990 : | OUTPUTS: |
4991 : | sdid int32 SD element ID |
4992 : | |
4993 : | NOTES: |
4994 : | |
4995 : | |
4996 : | Date Programmer Description |
4997 : | ====== ============ ================================================= |
4998 : | Oct 07 Andrey Kiselev Original Programmer |
4999 : | |
5000 : | END_PROLOG |
5001 : -----------------------------------------------------------------------------*/
5002 : intn
5003 0 : GDsdid(int32 gridID, const char *fieldname, int32 *sdid)
5004 : {
5005 : intn status; /* routine return status variable */
5006 : int32 fid; /* HDF-EOS file ID */
5007 : int32 sdInterfaceID; /* HDF SDS interface ID */
5008 : int32 dum; /* Dummy variable */
5009 : int32 dims[H4_MAX_VAR_DIMS]; /* Field/SDS dimensions */
5010 :
5011 0 : status = GDchkgdid(gridID, "GDsdid", &fid, &sdInterfaceID, &dum);
5012 0 : if (status != -1)
5013 : {
5014 0 : status = GDSDfldsrch(gridID, sdInterfaceID, fieldname,
5015 : sdid, &dum, &dum, &dum, dims, &dum);
5016 : }
5017 :
5018 0 : return (status);
5019 : }
|