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 :
29 : June 05, 2003 Abe Taaheri / Bruce Beaumont
30 :
31 : Changed MAXNREGIONS to 1024 to support MOPITT data
32 : Supplied cast for compcode in call to
33 : SDsetcompress to avoid compiler error
34 : Removed declaration for unused variable rstatus
35 : in SWwrrdfield
36 : Removed initialization code for unused variables
37 : in SWwrrdfield
38 : Removed declaration for unused variable tmpVal
39 : in SWdefboxregion
40 : Added code in SWdefboxregion to check for l_index k
41 : exceeding NSWATHREGN to avoid overwriting
42 : memory
43 : Removed declaration for unused variable retchar
44 : in SWregionl_index
45 : Removed initialization code for unused variables
46 : in SWregionl_index
47 : Removed declarations for unused variables tstatus,
48 : nfields, nflgs, and swathname in SWextractregion
49 : Removed initialization code for unused variables
50 : in SWextractregion
51 : Removed declaration for unused variable
52 : land_status in SWscan2longlat
53 : Removed initialization code for unused variables
54 : in SWscan2longlat
55 : Added clear (0) of timeflag in SWextractperiod if
56 : return status from SWextractregion is non-zero
57 : Removed declarations for unused variables tstatus,
58 : scandim, ndfields, ndflds, and swathname in
59 : SWregioninfo
60 : Removed initialization code for unused variables
61 : in SWregioninfo
62 : Added clear (0) of timeflag in SWperiodinfo if
63 : return status from SWregioninfo is non-zero
64 : Removed declarations for unused variables size,
65 : nfields, nflds, nswath, idxsz, cornerlon, and
66 : cornerlat in SWdefscanregion
67 : Removed initialization code for unused variables
68 : in SWdefscanregion
69 : Removed declarations for unused variables dims2,
70 : rank, nt, swathname, dimlist, and buffer in
71 : SWupdateidxmap
72 : Removed declaration for unused variable statmeta
73 : in SWgeomapinfo
74 : ******************************************************************************/
75 :
76 : #include "cpl_port.h" /* for M_PI */
77 : #include "cpl_string.h" /* for CPLsnprintf */
78 :
79 : #include "mfhdf.h"
80 : #include "hcomp.h"
81 : #include "HdfEosDef.h"
82 : #include <math.h>
83 :
84 : #include "hdf4compat.h"
85 :
86 : #define SWIDOFFSET 1048576
87 :
88 :
89 : static int32 SWX1dcomb[512*3];
90 :
91 : /* Added for routine that converts scanline to Lat/long
92 : ** for floating scene subsetting
93 : ** Jul 1999 DaW
94 : */
95 : #define RADOE 6371.0 /* Radius of Earth in Km */
96 :
97 : #define NSWATH 200
98 : /* Swath Structure External Arrays */
99 : struct swathStructure
100 : {
101 : int32 active;
102 : int32 IDTable;
103 : int32 VIDTable[3];
104 : int32 fid;
105 : int32 nSDS;
106 : int32 *sdsID;
107 : int32 compcode;
108 : intn compparm[5];
109 : int32 tilecode;
110 : int32 tilerank;
111 : int32 tiledims[8];
112 : };
113 : static struct swathStructure SWXSwath[NSWATH];
114 :
115 :
116 :
117 : #define NSWATHREGN 256
118 : #define MAXNREGIONS 1024
119 : struct swathRegion
120 : {
121 : int32 fid;
122 : int32 swathID;
123 : int32 nRegions;
124 : int32 StartRegion[MAXNREGIONS];
125 : int32 StopRegion[MAXNREGIONS];
126 : int32 StartVertical[8];
127 : int32 StopVertical[8];
128 : int32 StartScan[8];
129 : int32 StopScan[8];
130 : char *DimNamePtr[8];
131 : intn band8flag;
132 : intn scanflag;
133 : };
134 : static struct swathRegion *SWXRegion[NSWATHREGN];
135 :
136 : /* define a macro for the string size of the utility strings. The value
137 : of 80 in previous version of this code was resulting in core dump (Array
138 : Bounds Write and Array Bounds Read problem in SWfinfo function and the
139 : functions called from there) for 7-8 dimensional fields where the
140 : string length for "DimList" can exceed 80 characters, including " and
141 : commas in the string. The length now is 512 which seems to be more
142 : than enough to avoid the problem mentioned above. */
143 :
144 : #define UTLSTR_MAX_SIZE 512
145 :
146 : /* Swath Prototypes (internal routines) */
147 : static intn SWchkswid(int32, const char *, int32 *, int32 *, int32 *);
148 : static int32 SWfinfo(int32, const char *, const char *, int32 *,
149 : int32 [], int32 *, char *, size_t dimlistsize);
150 : static intn SWwrrdattr(int32, const char *, int32, int32, const char *, VOIDP);
151 : static intn SW1dfldsrch(int32, int32, const char *, const char *, int32 *,
152 : int32 *, int32 *);
153 : static intn SWSDfldsrch(int32, int32, const char *, int32 *, int32 *,
154 : int32 *, int32 *, int32 [], int32 *);
155 : static intn SWwrrdfield(int32, const char *, const char *,
156 : int32 [], int32 [], int32 [], VOIDP);
157 : static int32 SWinqfields(int32, const char *, char *, int32 [], int32 []);
158 :
159 : /*----------------------------------------------------------------------------|
160 : | BEGIN_PROLOG |
161 : | |
162 : | FUNCTION: SWopen |
163 : | |
164 : | DESCRIPTION: |
165 : | |
166 : | |
167 : | Return Value Type Units Description |
168 : | ============ ====== ========= ===================================== |
169 : | fid int32 HDF-EOS file ID |
170 : | |
171 : | INPUTS: |
172 : | filename char Filename |
173 : | access intn HDF access code |
174 : | |
175 : | |
176 : | OUTPUTS: |
177 : | None |
178 : | |
179 : | NOTES: |
180 : | |
181 : | |
182 : | Date Programmer Description |
183 : | ====== ============ ================================================= |
184 : | Jun 96 Joel Gales Original Programmer |
185 : | |
186 : | END_PROLOG |
187 : -----------------------------------------------------------------------------*/
188 : int32
189 20 : SWopen(const char *filename, intn i_access)
190 :
191 : {
192 : int32 fid /* HDF-EOS file ID */ ;
193 :
194 : /* Call EHopen to perform file access */
195 : /* ---------------------------------- */
196 20 : fid = EHopen(filename, i_access);
197 :
198 20 : return (fid);
199 : }
200 :
201 : /*----------------------------------------------------------------------------|
202 : | BEGIN_PROLOG |
203 : | |
204 : | FUNCTION: SWattach |
205 : | |
206 : | DESCRIPTION: Attaches to an existing swath within the file. |
207 : | |
208 : | |
209 : | Return Value Type Units Description |
210 : | ============ ====== ========= ===================================== |
211 : | swathID int32 swath structure ID |
212 : | |
213 : | INPUTS: |
214 : | fid int32 HDF-EOS file ID |
215 : | swathname char swath structure name |
216 : | |
217 : | OUTPUTS: |
218 : | None |
219 : | |
220 : | NOTES: |
221 : | |
222 : | |
223 : | Date Programmer Description |
224 : | ====== ============ ================================================= |
225 : | Jun 96 Joel Gales Original Programmer |
226 : | Apr 99 David Wynne Modified test for memory allocation check when no |
227 : | SDSs are in the Swath, NCR22513 |
228 : | |
229 : | END_PROLOG |
230 : -----------------------------------------------------------------------------*/
231 : int32
232 7 : SWattach(int32 fid, const char *swathname)
233 :
234 : {
235 : intn i; /* Loop index */
236 : intn j; /* Loop index */
237 7 : intn nswathopen = 0; /* # of swath structures open */
238 : intn status; /* routine return status variable */
239 :
240 : uint8 acs; /* Read/Write file access code */
241 :
242 : int32 HDFfid; /* HDF file id */
243 : int32 vgRef; /* Vgroup reference number */
244 : int32 vgid[4]; /* Vgroup ID array */
245 7 : int32 swathID = -1; /* HDF-EOS swath ID */
246 : int32 *tags; /* Pnt to Vgroup object tags array */
247 : int32 *refs; /* Pnt to Vgroup object refs array */
248 : int32 dum; /* dummy variable */
249 : int32 sdInterfaceID; /* HDF SDS interface ID */
250 : int32 nObjects; /* # of objects in Vgroup */
251 : int32 nSDS; /* SDS counter */
252 : int32 l_index; /* SDS l_index */
253 : int32 sdid; /* SDS object ID */
254 7 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
255 :
256 : char name[80]; /* Vgroup name */
257 : char class[80]; /* Vgroup class */
258 : char errbuf[256];/* Buffer for error message */
259 : char acsCode[1]; /* Read/Write access char: "r/w" */
260 :
261 :
262 : /* Check HDF-EOS file ID, get back HDF file ID and access code */
263 : /* ----------------------------------------------------------- */
264 7 : status = EHchkfid(fid, swathname, &HDFfid, &dum, &acs);
265 :
266 :
267 7 : if (status == 0)
268 : {
269 : /* Convert numeric access code to character */
270 : /* ---------------------------------------- */
271 7 : acsCode[0] = (acs == 1) ? 'w' : 'r';
272 :
273 : /* Determine number of swaths currently opened */
274 : /* ------------------------------------------- */
275 1407 : for (i = 0; i < NSWATH; i++)
276 : {
277 1400 : nswathopen += SWXSwath[i].active;
278 : }
279 :
280 : /* If room for more ... */
281 : /* -------------------- */
282 7 : if (nswathopen < NSWATH)
283 : {
284 :
285 : /* Search Vgroups for Swath */
286 : /* ------------------------ */
287 7 : vgRef = -1;
288 :
289 : while (1)
290 : {
291 44 : vgRef = Vgetid(HDFfid, vgRef);
292 :
293 :
294 : /* If no more Vgroups then exist while loop */
295 : /* ---------------------------------------- */
296 44 : if (vgRef == -1)
297 : {
298 0 : break;
299 : }
300 :
301 : /* Get name and class of Vgroup */
302 : /* ---------------------------- */
303 44 : vgid[0] = Vattach(HDFfid, vgRef, "r");
304 44 : VgetnameSafe(vgid[0], name, sizeof(name));
305 44 : Vgetclass(vgid[0], class);
306 :
307 :
308 : /*
309 : * If Vgroup with swathname and class SWATH found, load
310 : * tables
311 : */
312 :
313 44 : if (strcmp(name, swathname) == 0 &&
314 7 : strcmp(class, "SWATH") == 0)
315 : {
316 : /* Attach to "Fields" and "Swath Attributes" Vgroups */
317 : /* ------------------------------------------------- */
318 7 : tags = (int32 *) malloc(sizeof(int32) * 3);
319 7 : if(tags == NULL)
320 : {
321 0 : HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__);
322 0 : return(-1);
323 : }
324 7 : refs = (int32 *) malloc(sizeof(int32) * 3);
325 7 : if(refs == NULL)
326 : {
327 0 : HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__);
328 0 : free(tags);
329 0 : return(-1);
330 : }
331 7 : Vgettagrefs(vgid[0], tags, refs, 3);
332 7 : vgid[1] = Vattach(HDFfid, refs[0], acsCode);
333 7 : vgid[2] = Vattach(HDFfid, refs[1], acsCode);
334 7 : vgid[3] = Vattach(HDFfid, refs[2], acsCode);
335 7 : free(tags);
336 7 : free(refs);
337 :
338 : /* Setup External Arrays */
339 : /* --------------------- */
340 10 : for (i = 0; i < NSWATH; i++)
341 : {
342 : /* Find empty entry in array */
343 : /* ------------------------- */
344 10 : if (SWXSwath[i].active == 0)
345 : {
346 : /*
347 : * Set swathID, Set swath entry active, Store
348 : * root Vgroup ID, Store sub Vgroup IDs, Store
349 : * HDF-EOS file ID
350 : */
351 7 : swathID = i + idOffset;
352 7 : SWXSwath[i].active = 1;
353 7 : SWXSwath[i].IDTable = vgid[0];
354 7 : SWXSwath[i].VIDTable[0] = vgid[1];
355 7 : SWXSwath[i].VIDTable[1] = vgid[2];
356 7 : SWXSwath[i].VIDTable[2] = vgid[3];
357 7 : SWXSwath[i].fid = fid;
358 7 : break;
359 : }
360 : }
361 :
362 : /* Get SDS interface ID */
363 : /* -------------------- */
364 7 : status = SWchkswid(swathID, "SWattach", &dum,
365 : &sdInterfaceID, &dum);
366 7 : if (status < 0)
367 0 : return -1;
368 :
369 : /* Access swath "Geolocation" SDS */
370 : /* ------------------------------ */
371 :
372 : /* Get # of entries within this Vgroup & search for SDS */
373 : /* ---------------------------------------------------- */
374 7 : nObjects = Vntagrefs(vgid[1]);
375 :
376 7 : if (nObjects > 0)
377 : {
378 : /* Get tag and ref # for Geolocation Vgroup objects */
379 : /* ------------------------------------------------ */
380 0 : tags = (int32 *) malloc(sizeof(int32) * nObjects);
381 0 : if(tags == NULL)
382 : {
383 0 : HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__);
384 0 : return(-1);
385 : }
386 0 : refs = (int32 *) malloc(sizeof(int32) * nObjects);
387 0 : if(refs == NULL)
388 : {
389 0 : HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__);
390 0 : free(tags);
391 0 : return(-1);
392 : }
393 0 : Vgettagrefs(vgid[1], tags, refs, nObjects);
394 :
395 : /* Count number of SDS & allocate SDS ID array */
396 : /* ------------------------------------------- */
397 0 : nSDS = 0;
398 0 : for (j = 0; j < nObjects; j++)
399 : {
400 0 : if (tags[j] == DFTAG_NDG)
401 : {
402 0 : nSDS++;
403 : }
404 : }
405 0 : SWXSwath[i].sdsID = (int32 *) calloc(nSDS, 4);
406 0 : if(SWXSwath[i].sdsID == NULL && nSDS != 0)
407 : {
408 0 : HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__);
409 0 : free(tags);
410 0 : free(refs);
411 0 : return(-1);
412 : }
413 0 : nSDS = 0;
414 :
415 :
416 : /* Fill SDS ID array */
417 : /* ----------------- */
418 0 : for (j = 0; j < nObjects; j++)
419 : {
420 : /* If object is SDS then get id */
421 : /* ---------------------------- */
422 0 : if (tags[j] == DFTAG_NDG)
423 : {
424 0 : l_index = SDreftoindex(sdInterfaceID, refs[j]);
425 0 : sdid = SDselect(sdInterfaceID, l_index);
426 0 : SWXSwath[i].sdsID[nSDS] = sdid;
427 0 : nSDS++;
428 0 : SWXSwath[i].nSDS++;
429 : }
430 : }
431 0 : free(tags);
432 0 : free(refs);
433 : }
434 :
435 : /* Access swath "Data" SDS */
436 : /* ----------------------- */
437 :
438 : /* Get # of entries within this Vgroup & search for SDS */
439 : /* ---------------------------------------------------- */
440 7 : nObjects = Vntagrefs(vgid[2]);
441 :
442 7 : if (nObjects > 0)
443 : {
444 : /* Get tag and ref # for Data Vgroup objects */
445 : /* ----------------------------------------- */
446 3 : tags = (int32 *) malloc(sizeof(int32) * nObjects);
447 3 : if(tags == NULL)
448 : {
449 0 : HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__);
450 0 : return(-1);
451 : }
452 3 : refs = (int32 *) malloc(sizeof(int32) * nObjects);
453 3 : if(refs == NULL)
454 : {
455 0 : HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__);
456 0 : free(tags);
457 0 : return(-1);
458 : }
459 3 : Vgettagrefs(vgid[2], tags, refs, nObjects);
460 :
461 :
462 : /* Count number of SDS & allocate SDS ID array */
463 : /* ------------------------------------------- */
464 3 : nSDS = 0;
465 6 : for (j = 0; j < nObjects; j++)
466 : {
467 3 : if (tags[j] == DFTAG_NDG)
468 : {
469 3 : nSDS++;
470 : }
471 : }
472 3 : SWXSwath[i].sdsID = (int32 *)
473 3 : realloc((void *) SWXSwath[i].sdsID,
474 3 : (SWXSwath[i].nSDS + nSDS) * 4);
475 3 : if(SWXSwath[i].sdsID == NULL && nSDS != 0)
476 : {
477 0 : HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__);
478 0 : return(-1);
479 : }
480 :
481 : /* Fill SDS ID array */
482 : /* ----------------- */
483 6 : for (j = 0; j < nObjects; j++)
484 : {
485 : /* If object is SDS then get id */
486 : /* ---------------------------- */
487 3 : if (tags[j] == DFTAG_NDG)
488 : {
489 3 : l_index = SDreftoindex(sdInterfaceID, refs[j]);
490 3 : sdid = SDselect(sdInterfaceID, l_index);
491 3 : SWXSwath[i].sdsID[SWXSwath[i].nSDS] = sdid;
492 3 : SWXSwath[i].nSDS++;
493 : }
494 : }
495 3 : free(tags);
496 3 : free(refs);
497 : }
498 7 : break;
499 : }
500 :
501 : /* Detach Vgroup if not desired Swath */
502 : /* ---------------------------------- */
503 37 : Vdetach(vgid[0]);
504 : }
505 :
506 : /* If Swath not found then set up error message */
507 : /* -------------------------------------------- */
508 7 : if (swathID == -1)
509 : {
510 0 : HEpush(DFE_RANGE, "SWattach", __FILE__, __LINE__);
511 0 : HEreport("Swath: \"%s\" does not exist within HDF file.\n",
512 : swathname);
513 : }
514 : }
515 : else
516 : {
517 : /* Too many files opened */
518 : /* --------------------- */
519 0 : swathID = -1;
520 0 : strcpy(errbuf,
521 : "No more than %d swaths may be open simultaneously");
522 0 : strcat(errbuf, " (%s)");
523 0 : HEpush(DFE_DENIED, "SWattach", __FILE__, __LINE__);
524 0 : HEreport(errbuf, NSWATH, swathname);
525 : }
526 :
527 : }
528 7 : return (swathID);
529 : }
530 :
531 : /*----------------------------------------------------------------------------|
532 : | BEGIN_PROLOG |
533 : | |
534 : | FUNCTION: SWchkswid |
535 : | |
536 : | DESCRIPTION: Checks for valid swathID and returns file ID, SDS ID, and |
537 : | swath Vgroup ID |
538 : | |
539 : | |
540 : | Return Value Type Units Description |
541 : | ============ ====== ========= ===================================== |
542 : | status intn return status (0) SUCCEED, (-1) FAIL |
543 : | |
544 : | INPUTS: |
545 : | swathID int32 swath structure ID |
546 : | routname char Name of routine calling SWchkswid |
547 : | |
548 : | OUTPUTS: |
549 : | fid int32 File ID |
550 : | sdInterfaceID int32 SDS interface ID |
551 : | swVgrpID int32 swath Vgroup ID |
552 : | |
553 : | NOTES: |
554 : | |
555 : | |
556 : | Date Programmer Description |
557 : | ====== ============ ================================================= |
558 : | Jun 96 Joel Gales Original Programmer |
559 : | |
560 : | END_PROLOG |
561 : -----------------------------------------------------------------------------*/
562 : static intn
563 67 : SWchkswid(int32 swathID, const char *routname,
564 : int32 * fid, int32 * sdInterfaceID, int32 * swVgrpID)
565 :
566 : {
567 67 : intn status = 0; /* routine return status variable */
568 : uint8 l_access; /* Read/Write access code */
569 :
570 67 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
571 :
572 67 : char message1[] =
573 : "Invalid swath id: %d in routine \"%s\". ID must be >= %d and < %d.\n";
574 67 : char message2[] =
575 : "Swath id %d in routine \"%s\" not active.\n";
576 :
577 :
578 : /* Check for valid swath id */
579 : /* ------------------------ */
580 67 : if (swathID < idOffset || swathID >= NSWATH + idOffset)
581 : {
582 0 : status = -1;
583 0 : HEpush(DFE_RANGE, "SWchkswid", __FILE__, __LINE__);
584 0 : HEreport(message1, swathID, routname, idOffset, NSWATH + idOffset);
585 : }
586 : else
587 : {
588 67 : int sID = swathID % idOffset;
589 : /* Check for active swath ID */
590 : /* ------------------------- */
591 67 : if (SWXSwath[sID].active == 0)
592 : {
593 0 : status = -1;
594 0 : HEpush(DFE_GENAPP, "SWchkswid", __FILE__, __LINE__);
595 0 : HEreport(message2, swathID, routname);
596 : }
597 : else
598 : {
599 :
600 : /* Get file & SDS ids and Swath Vgroup */
601 : /* ----------------------------------- */
602 67 : status = EHchkfid(SWXSwath[sID].fid, " ", fid,
603 : sdInterfaceID, &l_access);
604 67 : *swVgrpID = SWXSwath[sID].IDTable;
605 : }
606 : }
607 67 : return (status);
608 : }
609 :
610 :
611 :
612 : /*----------------------------------------------------------------------------|
613 : | BEGIN_PROLOG |
614 : | |
615 : | FUNCTION: SWdiminfo |
616 : | |
617 : | DESCRIPTION: Returns size in bytes of named dimension |
618 : | |
619 : | |
620 : | Return Value Type Units Description |
621 : | ============ ====== ========= ===================================== |
622 : | size int32 Size of dimension |
623 : | |
624 : | INPUTS: |
625 : | swathID int32 swath structure id |
626 : | dimname char Dimension name |
627 : | |
628 : | |
629 : | OUTPUTS: |
630 : | None |
631 : | |
632 : | NOTES: |
633 : | |
634 : | |
635 : | Date Programmer Description |
636 : | ====== ============ ================================================= |
637 : | Jun 96 Joel Gales Original Programmer |
638 : | Aug 96 Joel Gales Make metadata ODL compliant |
639 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
640 : | |
641 : | END_PROLOG |
642 : -----------------------------------------------------------------------------*/
643 : int32
644 6 : SWdiminfo(int32 swathID, const char *dimname)
645 :
646 : {
647 : intn status; /* routine return status variable */
648 :
649 : int32 fid; /* HDF-EOS file ID */
650 : int32 sdInterfaceID; /* HDF SDS interface ID */
651 : int32 swVgrpID; /* Swath root Vgroup ID */
652 : int32 size; /* Dimension size */
653 6 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
654 :
655 :
656 : char *metabuf; /* Pointer to structural metadata (SM) */
657 : char *metaptrs[2];/* Pointers to begin and end of SM section */
658 : char swathname[80]; /* Swath Name */
659 : char *utlstr; /* Utility string */
660 :
661 :
662 : /* Allocate space for utility string */
663 : /* --------------------------------- */
664 6 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
665 6 : if(utlstr == NULL)
666 : {
667 0 : HEpush(DFE_NOSPACE,"SWdiminfo", __FILE__, __LINE__);
668 0 : return(-1);
669 : }
670 : /* Initialize return value */
671 6 : size = -1;
672 :
673 : /* Check Swath ID */
674 6 : status = SWchkswid(swathID, "SWdiminfo", &fid, &sdInterfaceID, &swVgrpID);
675 :
676 6 : if (status == 0)
677 : {
678 : /* Get swath name */
679 6 : int sID = swathID % idOffset;
680 6 : if (sID >= NSWATH)
681 : {
682 0 : free(utlstr);
683 0 : return -1;
684 : }
685 6 : VgetnameSafe(SWXSwath[sID].IDTable, swathname, sizeof(swathname));
686 :
687 : /* Get pointers to "Dimension" section within SM */
688 6 : metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",
689 : "Dimension", metaptrs);
690 :
691 6 : if(metabuf == NULL)
692 : {
693 0 : free(utlstr);
694 0 : return(-1);
695 : }
696 :
697 : /* Search for dimension name (surrounded by quotes) */
698 6 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "\"", dimname, "\"\n");
699 6 : metaptrs[0] = strstr(metaptrs[0], utlstr);
700 :
701 : /*
702 : * If dimension found within swath structure then get dimension value
703 : */
704 6 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
705 : {
706 : /* Set endptr at end of dimension definition entry */
707 6 : metaptrs[1] = strstr(metaptrs[0], "\t\t\tEND_OBJECT");
708 :
709 6 : status = EHgetmetavalue(metaptrs, "Size", utlstr);
710 :
711 6 : if (status == 0)
712 : {
713 6 : size = atoi(utlstr);
714 : }
715 : else
716 : {
717 0 : HEpush(DFE_GENAPP, "SWdiminfo", __FILE__, __LINE__);
718 0 : HEreport("\"Size\" string not found in metadata.\n");
719 : }
720 : }
721 : else
722 : {
723 0 : HEpush(DFE_GENAPP, "SWdiminfo", __FILE__, __LINE__);
724 0 : HEreport("Dimension \"%s\" not found.\n", dimname);
725 : }
726 :
727 6 : free(metabuf);
728 : }
729 6 : free(utlstr);
730 :
731 6 : return (size);
732 : }
733 :
734 :
735 :
736 :
737 : /*----------------------------------------------------------------------------|
738 : | BEGIN_PROLOG |
739 : | |
740 : | FUNCTION: SWmapinfo |
741 : | |
742 : | DESCRIPTION: Returns dimension mapping information |
743 : | |
744 : | |
745 : | Return Value Type Units Description |
746 : | ============ ====== ========= ===================================== |
747 : | status intn return status (0) SUCCEED, (-1) FAIL |
748 : | |
749 : | INPUTS: |
750 : | swathID int32 swath structure id |
751 : | geodim char geolocation dimension name |
752 : | datadim char data dimension name |
753 : | |
754 : | OUTPUTS: |
755 : | offset int32 mapping offset |
756 : | increment int32 mapping increment |
757 : | |
758 : | NOTES: |
759 : | |
760 : | |
761 : | Date Programmer Description |
762 : | ====== ============ ================================================= |
763 : | Jun 96 Joel Gales Original Programmer |
764 : | Aug 96 Joel Gales Make metadata ODL compliant |
765 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
766 : | |
767 : | END_PROLOG |
768 : -----------------------------------------------------------------------------*/
769 : intn
770 0 : SWmapinfo(int32 swathID, const char *geodim, const char *datadim, int32 * offset,
771 : int32 * increment)
772 :
773 : {
774 : intn status; /* routine return status variable */
775 0 : intn statmeta = 0; /* EHgetmetavalue return status */
776 :
777 : int32 fid; /* HDF-EOS file ID */
778 : int32 sdInterfaceID; /* HDF SDS interface ID */
779 : int32 swVgrpID; /* Swath root Vgroup ID */
780 0 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
781 :
782 : char *metabuf; /* Pointer to structural metadata (SM) */
783 : char *metaptrs[2];/* Pointers to begin and end of SM section */
784 : char swathname[80]; /* Swath Name */
785 : char *utlstr; /* Utility string */
786 :
787 :
788 : /* Allocate space for utility string */
789 : /* --------------------------------- */
790 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
791 0 : if(utlstr == NULL)
792 : {
793 0 : HEpush(DFE_NOSPACE,"SWmapinfo", __FILE__, __LINE__);
794 0 : return(-1);
795 : }
796 : /* Initialize return values */
797 0 : *offset = -1;
798 0 : *increment = -1;
799 :
800 : /* Check Swath ID */
801 0 : status = SWchkswid(swathID, "SWmapinfo", &fid, &sdInterfaceID, &swVgrpID);
802 :
803 0 : if (status == 0)
804 : {
805 : /* Get swath name */
806 0 : int sID = swathID % idOffset;
807 0 : if (sID >= NSWATH)
808 : {
809 0 : free(utlstr);
810 0 : return -1;
811 : }
812 0 : VgetnameSafe(SWXSwath[sID].IDTable, swathname, sizeof(swathname));
813 :
814 : /* Get pointers to "DimensionMap" section within SM */
815 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",
816 : "DimensionMap", metaptrs);
817 0 : if(metabuf == NULL)
818 : {
819 0 : free(utlstr);
820 0 : return(-1);
821 : }
822 :
823 : /* Search for mapping - GeoDim/DataDim (surrounded by quotes) */
824 0 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s%s%s", "\t\t\t\tGeoDimension=\"", geodim,
825 : "\"\n\t\t\t\tDataDimension=\"", datadim, "\"\n");
826 0 : metaptrs[0] = strstr(metaptrs[0], utlstr);
827 :
828 : /*
829 : * If mapping found within swath structure then get offset and
830 : * increment value
831 : */
832 0 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
833 : {
834 : /* Get Offset */
835 0 : statmeta = EHgetmetavalue(metaptrs, "Offset", utlstr);
836 0 : if (statmeta == 0)
837 : {
838 0 : *offset = atoi(utlstr);
839 : }
840 : else
841 : {
842 0 : status = -1;
843 0 : HEpush(DFE_GENAPP, "SWmapinfo", __FILE__, __LINE__);
844 0 : HEreport("\"Offset\" string not found in metadata.\n");
845 : }
846 :
847 :
848 : /* Get Increment */
849 0 : statmeta = EHgetmetavalue(metaptrs, "Increment", utlstr);
850 0 : if (statmeta == 0)
851 : {
852 0 : *increment = atoi(utlstr);
853 : }
854 : else
855 : {
856 0 : status = -1;
857 0 : HEpush(DFE_GENAPP, "SWmapinfo", __FILE__, __LINE__);
858 0 : HEreport("\"Increment\" string not found in metadata.\n");
859 : }
860 : }
861 : else
862 : {
863 0 : status = -1;
864 0 : HEpush(DFE_GENAPP, "SWmapinfo", __FILE__, __LINE__);
865 0 : HEreport("Mapping \"%s/%s\" not found.\n", geodim, datadim);
866 : }
867 :
868 0 : free(metabuf);
869 : }
870 0 : free(utlstr);
871 0 : return (status);
872 : }
873 :
874 :
875 :
876 :
877 : /*----------------------------------------------------------------------------|
878 : | BEGIN_PROLOG |
879 : | |
880 : | FUNCTION: SWidxmapinfo |
881 : | |
882 : | DESCRIPTION: Returns l_indexed mapping information |
883 : | |
884 : | |
885 : | Return Value Type Units Description |
886 : | ============ ====== ========= ===================================== |
887 : | gsize int32 Number of l_index values (sz of geo dim) |
888 : | |
889 : | INPUTS: |
890 : | swathID int32 swath structure id |
891 : | geodim char geolocation dimension name |
892 : | datadim char data dimension name |
893 : | |
894 : | |
895 : | OUTPUTS: |
896 : | l_index int32 array of l_index values |
897 : | |
898 : | NOTES: |
899 : | |
900 : | |
901 : | Date Programmer Description |
902 : | ====== ============ ================================================= |
903 : | Jun 96 Joel Gales Original Programmer |
904 : | |
905 : | END_PROLOG |
906 : -----------------------------------------------------------------------------*/
907 : int32
908 0 : SWidxmapinfo(int32 swathID, const char *geodim, const char *datadim, int32 l_index[])
909 : {
910 : intn status; /* routine return status variable */
911 :
912 : int32 fid; /* HDF-EOS file ID */
913 : int32 sdInterfaceID; /* HDF SDS interface ID */
914 : int32 swVgrpID; /* Swath root Vgroup ID */
915 0 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
916 : int32 vgid; /* Swath Attributes Vgroup ID */
917 : int32 vdataID; /* Index Mapping Vdata ID */
918 0 : int32 gsize = -1; /* Size of geo dim */
919 :
920 : char utlbuf[256];/* Utility buffer */
921 :
922 :
923 : /* Check Swath ID */
924 0 : status = SWchkswid(swathID, "SWidxmapinfo",
925 : &fid, &sdInterfaceID, &swVgrpID);
926 :
927 0 : if (status == 0)
928 : {
929 : /* Find Index Mapping Vdata with Swath Attributes Vgroup */
930 0 : snprintf(utlbuf, sizeof(utlbuf), "%s%s%s%s", "INDXMAP:", geodim, "/", datadim);
931 0 : int sID = swathID % idOffset;
932 0 : if (sID >= NSWATH)
933 : {
934 0 : return -1;
935 : }
936 0 : vgid = SWXSwath[sID].VIDTable[2];
937 0 : vdataID = EHgetid(fid, vgid, utlbuf, 1, "r");
938 :
939 : /* If found then get geodim size & read l_index mapping values */
940 0 : if (vdataID != -1)
941 : {
942 0 : gsize = SWdiminfo(swathID, geodim);
943 :
944 0 : VSsetfields(vdataID, "Index");
945 0 : VSread(vdataID, (uint8 *) l_index, 1, FULL_INTERLACE);
946 0 : VSdetach(vdataID);
947 : }
948 : else
949 : {
950 : /*status = -1;*/
951 0 : HEpush(DFE_GENAPP, "SWidxmapinfo", __FILE__, __LINE__);
952 0 : HEreport("Index Mapping \"%s\" not found.\n", utlbuf);
953 : }
954 : }
955 0 : return (gsize);
956 : }
957 :
958 :
959 :
960 :
961 : /*----------------------------------------------------------------------------|
962 : | BEGIN_PROLOG |
963 : | |
964 : | FUNCTION: SWcompinfo |
965 : | |
966 : | DESCRIPTION: |
967 : | |
968 : | |
969 : | Return Value Type Units Description |
970 : | ============ ====== ========= ===================================== |
971 : | status intn |
972 : | |
973 : | INPUTS: |
974 : | swathID int32 |
975 : | compcode int32 |
976 : | compparm intn |
977 : | |
978 : | |
979 : | OUTPUTS: |
980 : | None |
981 : | |
982 : | NOTES: |
983 : | |
984 : | |
985 : | Date Programmer Description |
986 : | ====== ============ ================================================= |
987 : | Oct 96 Joel Gales Original Programmer |
988 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
989 : | |
990 : | END_PROLOG |
991 : -----------------------------------------------------------------------------*/
992 : intn
993 0 : SWcompinfo(int32 swathID, const char *fieldname, int32 * compcode, intn compparm[])
994 : {
995 : intn i; /* Loop Index */
996 : intn status; /* routine return status variable */
997 0 : intn statmeta = 0; /* EHgetmetavalue return status */
998 :
999 : int32 fid; /* HDF-EOS file ID */
1000 : int32 sdInterfaceID; /* HDF SDS interface ID */
1001 : int32 swVgrpID; /* Swath root Vgroup ID */
1002 0 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
1003 :
1004 : char *metabuf; /* Pointer to structural metadata (SM) */
1005 : char *metaptrs[2];/* Pointers to begin and end of SM section */
1006 : char swathname[80]; /* Swath Name */
1007 : char *utlstr; /* Utility string */
1008 :
1009 0 : const char *HDFcomp[5] = {"HDFE_COMP_NONE", "HDFE_COMP_RLE",
1010 : "HDFE_COMP_NBIT", "HDFE_COMP_SKPHUFF",
1011 : "HDFE_COMP_DEFLATE"}; /* Compression Codes */
1012 :
1013 : /* Allocate space for utility string */
1014 : /* --------------------------------- */
1015 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
1016 0 : if(utlstr == NULL)
1017 : {
1018 0 : HEpush(DFE_NOSPACE,"SWcompinfo", __FILE__, __LINE__);
1019 0 : return(-1);
1020 : }
1021 :
1022 : /* Check Swath ID */
1023 0 : status = SWchkswid(swathID, "SWcompinfo",
1024 : &fid, &sdInterfaceID, &swVgrpID);
1025 :
1026 0 : if (status == 0)
1027 : {
1028 : /* Get swath name */
1029 0 : int sID = swathID % idOffset;
1030 0 : if (sID >= NSWATH)
1031 : {
1032 0 : free(utlstr);
1033 0 : return -1;
1034 : }
1035 0 : VgetnameSafe(SWXSwath[sID].IDTable, swathname, sizeof(swathname));
1036 :
1037 : /* Get pointers to "DataField" section within SM */
1038 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",
1039 : "DataField", metaptrs);
1040 0 : if(metabuf == NULL)
1041 : {
1042 0 : free(utlstr);
1043 0 : return(-1);
1044 : }
1045 : /* Search for field */
1046 0 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "\"", fieldname, "\"\n");
1047 0 : metaptrs[0] = strstr(metaptrs[0], utlstr);
1048 :
1049 : /* If not found then search in "GeoField" section */
1050 0 : if (metaptrs[0] > metaptrs[1] || metaptrs[0] == NULL)
1051 : {
1052 0 : free(metabuf);
1053 :
1054 : /* Get pointers to "GeoField" section within SM */
1055 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",
1056 : "GeoField", metaptrs);
1057 0 : if(metabuf == NULL)
1058 : {
1059 0 : free(utlstr);
1060 0 : return(-1);
1061 : }
1062 : /* Search for field */
1063 0 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "\"", fieldname, "\"\n");
1064 0 : metaptrs[0] = strstr(metaptrs[0], utlstr);
1065 : }
1066 :
1067 :
1068 : /* If field found and user wants compression code ... */
1069 0 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
1070 : {
1071 0 : if (compcode != NULL)
1072 : {
1073 : /* Set endptr at end of field's definition entry */
1074 0 : metaptrs[1] = strstr(metaptrs[0], "\t\t\tEND_OBJECT");
1075 :
1076 : /* Get compression type */
1077 0 : statmeta = EHgetmetavalue(metaptrs, "CompressionType", utlstr);
1078 :
1079 : /*
1080 : * Default is no compression if "CompressionType" string not
1081 : * in metadata
1082 : */
1083 0 : *compcode = HDFE_COMP_NONE;
1084 :
1085 : /* If compression code is found ... */
1086 0 : if (statmeta == 0)
1087 : {
1088 : /* Loop through compression types until match */
1089 0 : for (i = 0; i < 5; i++)
1090 : {
1091 0 : if (strcmp(utlstr, HDFcomp[i]) == 0)
1092 : {
1093 0 : *compcode = i;
1094 0 : break;
1095 : }
1096 : }
1097 : }
1098 : }
1099 :
1100 : /* If user wants compression parameters ... */
1101 0 : if (compparm != NULL && compcode != NULL)
1102 : {
1103 : /* Initialize to zero */
1104 0 : for (i = 0; i < 4; i++)
1105 : {
1106 0 : compparm[i] = 0;
1107 : }
1108 :
1109 : /*
1110 : * Get compression parameters if NBIT or DEFLATE compression
1111 : */
1112 0 : if (*compcode == HDFE_COMP_NBIT)
1113 : {
1114 : statmeta =
1115 0 : EHgetmetavalue(metaptrs, "CompressionParams", utlstr);
1116 0 : if (statmeta == 0)
1117 : {
1118 0 : sscanf(utlstr, "(%d,%d,%d,%d)",
1119 : &compparm[0], &compparm[1],
1120 : &compparm[2], &compparm[3]);
1121 : }
1122 : else
1123 : {
1124 0 : status = -1;
1125 0 : HEpush(DFE_GENAPP, "SWcompinfo", __FILE__, __LINE__);
1126 0 : HEreport(
1127 : "\"CompressionParams\" string not found in metadata.\n");
1128 : }
1129 : }
1130 0 : else if (*compcode == HDFE_COMP_DEFLATE)
1131 : {
1132 : statmeta =
1133 0 : EHgetmetavalue(metaptrs, "DeflateLevel", utlstr);
1134 0 : if (statmeta == 0)
1135 : {
1136 0 : sscanf(utlstr, "%d", &compparm[0]);
1137 : }
1138 : else
1139 : {
1140 0 : status = -1;
1141 0 : HEpush(DFE_GENAPP, "SWcompinfo", __FILE__, __LINE__);
1142 0 : HEreport(
1143 : "\"DeflateLevel\" string not found in metadata.\n");
1144 : }
1145 : }
1146 : }
1147 : }
1148 : else
1149 : {
1150 0 : HEpush(DFE_GENAPP, "SWcompinfo", __FILE__, __LINE__);
1151 0 : HEreport("Fieldname \"%s\" not found.\n", fieldname);
1152 : }
1153 :
1154 0 : free(metabuf);
1155 : }
1156 0 : free(utlstr);
1157 :
1158 0 : return (status);
1159 : }
1160 :
1161 :
1162 :
1163 : /*----------------------------------------------------------------------------|
1164 : | BEGIN_PROLOG |
1165 : | |
1166 : | FUNCTION: SWfinfo |
1167 : | |
1168 : | DESCRIPTION: Returns field info |
1169 : | |
1170 : | |
1171 : | Return Value Type Units Description |
1172 : | ============ ====== ========= ===================================== |
1173 : | status intn return status (0) SUCCEED, (-1) FAIL |
1174 : | |
1175 : | INPUTS: |
1176 : | swathID int32 swath structure id |
1177 : | fieldtype const char fieldtype (geo or data) |
1178 : | fieldname const char name of field |
1179 : | |
1180 : | |
1181 : | OUTPUTS: |
1182 : | rank int32 rank of field (# of dims) |
1183 : | dims int32 field dimensions |
1184 : | numbertype int32 field number type |
1185 : | dimlist char field dimension list |
1186 : | |
1187 : | NOTES: |
1188 : | |
1189 : | |
1190 : | Date Programmer Description |
1191 : | ====== ============ ================================================= |
1192 : | Jun 96 Joel Gales Original Programmer |
1193 : | Aug 96 Joel Gales Make metadata ODL compliant |
1194 : | Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue |
1195 : | |
1196 : | END_PROLOG |
1197 : -----------------------------------------------------------------------------*/
1198 : static int32
1199 10 : SWfinfo(int32 swathID, const char *fieldtype, const char *fieldname,
1200 : int32 *rank, int32 dims[], int32 *numbertype, char *dimlist, size_t dimlistsize)
1201 :
1202 : {
1203 : intn i; /* Loop index */
1204 : intn j; /* Loop index */
1205 : intn status; /* routine return status variable */
1206 10 : intn statmeta = 0; /* EHgetmetavalue return status */
1207 :
1208 10 : int32 fid = 0; /* HDF-EOS file ID */
1209 10 : int32 sdInterfaceID = 0; /* HDF SDS interface ID */
1210 10 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
1211 : int32 fsize; /* field size in bytes */
1212 10 : int32 ndims = 0; /* Number of dimensions */
1213 : int32 slen[8]; /* Length of each entry in parsed string */
1214 : int32 dum; /* Dummy variable */
1215 : int32 vdataID; /* 1d field vdata ID */
1216 :
1217 : uint8 *buf; /* One-Dim field buffer */
1218 :
1219 : char *metabuf; /* Pointer to structural metadata (SM) */
1220 : char *metaptrs[2];/* Pointers to begin and end of SM section */
1221 : char swathname[80]; /* Swath Name */
1222 : char *utlstr; /* Utility string */
1223 : char *ptr[8]; /* String pointers for parsed string */
1224 : char dimstr[64]; /* Individual dimension entry string */
1225 :
1226 :
1227 : /* Allocate space for utility string */
1228 : /* --------------------------------- */
1229 10 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
1230 10 : if(utlstr == NULL)
1231 : {
1232 0 : HEpush(DFE_NOSPACE,"SWfinfo", __FILE__, __LINE__);
1233 0 : return(-1);
1234 : }
1235 :
1236 : /* Initialize rank and numbertype to -1 (error) */
1237 : /* -------------------------------------------- */
1238 10 : *rank = -1;
1239 10 : *numbertype = -1;
1240 :
1241 : /* Get HDF-EOS file ID and SDS interface ID */
1242 10 : status = SWchkswid(swathID, "SWfinfo", &fid, &sdInterfaceID, &dum);
1243 :
1244 : /* Get swath name */
1245 10 : int sID = swathID % idOffset;
1246 10 : if (sID >= NSWATH)
1247 : {
1248 0 : free(utlstr);
1249 0 : return -1;
1250 : }
1251 10 : VgetnameSafe(SWXSwath[sID].IDTable, swathname, sizeof(swathname));
1252 :
1253 : /* Get pointers to appropriate "Field" section within SM */
1254 10 : if (strcmp(fieldtype, "Geolocation Fields") == 0)
1255 : {
1256 5 : metabuf = EHmetagroup(sdInterfaceID, swathname, "s",
1257 : "GeoField", metaptrs);
1258 :
1259 5 : if(metabuf == NULL)
1260 : {
1261 0 : free(utlstr);
1262 0 : return(-1);
1263 : }
1264 : }
1265 : else
1266 : {
1267 5 : metabuf = EHmetagroup(sdInterfaceID, swathname, "s",
1268 : "DataField", metaptrs);
1269 5 : if(metabuf == NULL)
1270 : {
1271 0 : free(utlstr);
1272 0 : return(-1);
1273 : }
1274 : }
1275 :
1276 10 : if (!metaptrs[0])
1277 : {
1278 0 : free(utlstr);
1279 0 : free(metabuf);
1280 0 : return -1;
1281 : }
1282 :
1283 : /* Search for field */
1284 10 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "\"", fieldname, "\"\n");
1285 10 : metaptrs[0] = strstr(metaptrs[0], utlstr);
1286 :
1287 : /* If field found ... */
1288 10 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
1289 : {
1290 : /* Get DataType string */
1291 5 : statmeta = EHgetmetavalue(metaptrs, "DataType", utlstr);
1292 :
1293 : /* Convert to numbertype code */
1294 5 : if (statmeta == 0)
1295 5 : *numbertype = EHnumstr(utlstr);
1296 : else
1297 : {
1298 0 : status = -1;
1299 0 : HEpush(DFE_GENAPP, "SWfinfo", __FILE__, __LINE__);
1300 0 : HEreport("\"DataType\" string not found in metadata.\n");
1301 : }
1302 :
1303 :
1304 : /*
1305 : * Get DimList string and trim off leading and trailing parens "()"
1306 : */
1307 5 : statmeta = EHgetmetavalue(metaptrs, "DimList", utlstr);
1308 :
1309 5 : if (statmeta == 0)
1310 : {
1311 5 : const size_t len = strlen(utlstr);
1312 5 : if (len >= 2 && utlstr[0] == '(' && utlstr[len-1] == ')')
1313 : {
1314 3 : memmove(utlstr, utlstr + 1, len - 2);
1315 3 : utlstr[len - 2] = '\0';
1316 : }
1317 :
1318 : /* Parse trimmed DimList string and get rank */
1319 5 : ndims = EHparsestr(utlstr, ',', ptr, CPL_ARRAYSIZE(ptr), slen, CPL_ARRAYSIZE(slen));
1320 5 : if (ndims < 0)
1321 : {
1322 0 : free(utlstr);
1323 0 : free(metabuf);
1324 0 : HEpush(DFE_NOSPACE, "SWfinfo", __FILE__, __LINE__);
1325 0 : return -1;
1326 : }
1327 5 : *rank = ndims;
1328 : }
1329 : else
1330 : {
1331 0 : status = -1;
1332 0 : HEpush(DFE_GENAPP, "SWfinfo", __FILE__, __LINE__);
1333 0 : HEreport("\"DimList\" string not found in metadata.\n");
1334 : }
1335 :
1336 : /* If dimension list is desired by user then initialize length to 0 */
1337 5 : if (dimlist != NULL)
1338 : {
1339 3 : dimlist[0] = 0;
1340 : }
1341 :
1342 : /*
1343 : * Copy each entry in DimList and remove leading and trailing quotes,
1344 : * Get dimension sizes and concatenate dimension names to dimension
1345 : * list
1346 : */
1347 5 : size_t dimlistlen = 0;
1348 5 : dims[0] = 0;
1349 11 : for (i = 0; i < ndims; i++)
1350 : {
1351 6 : if (slen[i] >= 2)
1352 : {
1353 6 : if ((size_t)(slen[i] - 2) >= sizeof(dimstr))
1354 : {
1355 0 : HEpush(DFE_GENAPP, "SWfinfo", __FILE__, __LINE__);
1356 0 : HEreport("Size of dimstr variable too short.\n");
1357 0 : return -1;
1358 : }
1359 6 : memcpy(dimstr, ptr[i] + 1, slen[i] - 2);
1360 6 : dimstr[slen[i] - 2] = 0;
1361 : }
1362 : else
1363 : {
1364 0 : dimstr[0] = 0;
1365 : }
1366 6 : dims[i] = SWdiminfo(swathID, dimstr);
1367 6 : if (dimlist != NULL)
1368 : {
1369 4 : const int spaceForComma = ((i > 0) ? 1 : 0);
1370 4 : if (dimlistlen + spaceForComma + strlen(dimstr) >= dimlistsize)
1371 : {
1372 0 : HEpush(DFE_GENAPP, "SWfinfo", __FILE__, __LINE__);
1373 0 : HEreport("Size of dimlist variable too short.\n");
1374 0 : return -1;
1375 : }
1376 4 : if (i > 0)
1377 : {
1378 2 : strcpy(dimlist + dimlistlen, ",");
1379 2 : ++dimlistlen;
1380 : }
1381 4 : strcpy(dimlist + dimlistlen, dimstr);
1382 4 : dimlistlen += strlen(dimstr);
1383 : }
1384 : }
1385 :
1386 :
1387 : /* Appendable Field Section */
1388 : /* ------------------------ */
1389 5 : if (dims[0] == 0)
1390 : {
1391 : /* One-Dimensional Field */
1392 5 : if (*rank == 1)
1393 : {
1394 : /* Get vdata ID */
1395 0 : status = SW1dfldsrch(fid, swathID, fieldname, "r",
1396 : &dum, &vdataID, &dum);
1397 :
1398 : /* Get actual size of field */
1399 0 : dims[0] = VSelts(vdataID);
1400 :
1401 : /*
1402 : * If size=1 then check where actual record of
1403 : * "initialization" record
1404 : */
1405 0 : if (dims[0] == 1)
1406 : {
1407 : /* Get record size and read 1st record */
1408 0 : fsize = VSsizeof(vdataID, (char *)fieldname);
1409 0 : buf = (uint8 *) calloc(fsize, 1);
1410 0 : if(buf == NULL)
1411 : {
1412 0 : HEpush(DFE_NOSPACE,"SWfinfo", __FILE__, __LINE__);
1413 0 : free(utlstr);
1414 0 : return(-1);
1415 : }
1416 0 : VSsetfields(vdataID, fieldname);
1417 0 : VSseek(vdataID, 0);
1418 0 : VSread(vdataID, (uint8 *) buf, 1, FULL_INTERLACE);
1419 :
1420 : /* Sum up "bytes" in record */
1421 0 : for (i = 0, j = 0; i < fsize; i++)
1422 : {
1423 0 : j += buf[i];
1424 : }
1425 :
1426 : /*
1427 : * If filled with 255 then "initialization" record,
1428 : * actual number of records = 0
1429 : */
1430 0 : if (j == 255 * fsize)
1431 : {
1432 0 : dims[0] = 0;
1433 : }
1434 :
1435 0 : free(buf);
1436 : }
1437 : /* Detach from 1d field */
1438 0 : VSdetach(vdataID);
1439 : }
1440 : else
1441 : {
1442 : /* Get actual size of Multi-Dimensional Field */
1443 5 : status = SWSDfldsrch(swathID, sdInterfaceID, fieldname,
1444 : &dum, &dum, &dum, &dum, dims,
1445 : &dum);
1446 : }
1447 : }
1448 : }
1449 10 : free(metabuf);
1450 :
1451 10 : if (*rank == -1)
1452 : {
1453 5 : status = -1;
1454 : }
1455 10 : free(utlstr);
1456 :
1457 10 : return (status);
1458 : }
1459 :
1460 :
1461 :
1462 :
1463 :
1464 : /*----------------------------------------------------------------------------|
1465 : | BEGIN_PROLOG |
1466 : | |
1467 : | FUNCTION: SWfieldinfo |
1468 : | |
1469 : | DESCRIPTION: Wrapper around SWfinfo |
1470 : | |
1471 : | |
1472 : | Return Value Type Units Description |
1473 : | ============ ====== ========= ===================================== |
1474 : | status intn return status (0) SUCCEED, (-1) FAIL |
1475 : | |
1476 : | INPUTS: |
1477 : | swathID int32 swath structure id |
1478 : | fieldname const char name of field |
1479 : | |
1480 : | |
1481 : | OUTPUTS: |
1482 : | rank int32 rank of field (# of dims) |
1483 : | dims int32 field dimensions |
1484 : | numbertype int32 field number type |
1485 : | dimlist char field dimension list |
1486 : | |
1487 : | NOTES: |
1488 : | |
1489 : | |
1490 : | Date Programmer Description |
1491 : | ====== ============ ================================================= |
1492 : | Jun 96 Joel Gales Original Programmer |
1493 : | |
1494 : | END_PROLOG |
1495 : -----------------------------------------------------------------------------*/
1496 : intn
1497 5 : SWfieldinfo(int32 swathID, const char *fieldname, int32 * rank, int32 dims[],
1498 : int32 * numbertype, char *dimlist, size_t dimlistsize)
1499 :
1500 : {
1501 : intn status; /* routine return status variable */
1502 :
1503 : int32 fid; /* HDF-EOS file ID */
1504 : int32 sdInterfaceID; /* HDF SDS interface ID */
1505 : int32 swVgrpID; /* Swath root Vgroup ID */
1506 :
1507 :
1508 : /* Check for valid swath id */
1509 5 : status = SWchkswid(swathID, "SWfieldinfo", &fid,
1510 : &sdInterfaceID, &swVgrpID);
1511 5 : if (status == 0)
1512 : {
1513 : /* Check for field within Geolocatation Fields */
1514 5 : status = SWfinfo(swathID, "Geolocation Fields", fieldname,
1515 : rank, dims, numbertype, dimlist, dimlistsize);
1516 :
1517 : /* If not there then check within Data Fields */
1518 5 : if (status == -1)
1519 : {
1520 5 : status = SWfinfo(swathID, "Data Fields", fieldname,
1521 : rank, dims, numbertype, dimlist, dimlistsize);
1522 : }
1523 :
1524 : /* If not there either then can't be found */
1525 5 : if (status == -1)
1526 : {
1527 5 : HEpush(DFE_GENAPP, "SWfieldinfo", __FILE__, __LINE__);
1528 5 : HEreport("Fieldname \"%s\" not found.\n", fieldname);
1529 : }
1530 : }
1531 5 : return (status);
1532 : }
1533 :
1534 :
1535 :
1536 : /*----------------------------------------------------------------------------|
1537 : | BEGIN_PROLOG |
1538 : | |
1539 : | FUNCTION: SWwrrdattr |
1540 : | |
1541 : | DESCRIPTION: |
1542 : | |
1543 : | |
1544 : | Return Value Type Units Description |
1545 : | ============ ====== ========= ===================================== |
1546 : | status intn return status (0) SUCCEED, (-1) FAIL |
1547 : | |
1548 : | INPUTS: |
1549 : | swathID int32 swath structure ID |
1550 : | attrname char attribute name |
1551 : | numbertype int32 attribute HDF numbertype |
1552 : | count int32 Number of attribute elements |
1553 : | wrcode char Read/Write Code "w/r" |
1554 : | datbuf void I/O buffer |
1555 : | |
1556 : | OUTPUTS: |
1557 : | datbuf |
1558 : | |
1559 : | NOTES: |
1560 : | |
1561 : | |
1562 : | Date Programmer Description |
1563 : | ====== ============ ================================================= |
1564 : | Jun 96 Joel Gales Original Programmer |
1565 : | Oct 96 Joel Gales Get Attribute Vgroup ID from external array |
1566 : | |
1567 : | END_PROLOG |
1568 : -----------------------------------------------------------------------------*/
1569 : static intn
1570 0 : SWwrrdattr(int32 swathID, const char *attrname, int32 numbertype, int32 count,
1571 : const char *wrcode, VOIDP datbuf)
1572 :
1573 : {
1574 : intn status; /* routine return status variable */
1575 :
1576 : int32 fid; /* HDF-EOS file ID */
1577 : int32 attrVgrpID; /* Swath attribute ID */
1578 : int32 dum; /* dummy variable */
1579 0 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
1580 :
1581 : /* Check Swath id */
1582 0 : status = SWchkswid(swathID, "SWwrrdattr", &fid, &dum, &dum);
1583 :
1584 0 : if (status == 0)
1585 : {
1586 : /* Get attribute Vgroup ID and call EHattr to perform I/O */
1587 : /* ------------------------------------------------------ */
1588 0 : int sID = swathID % idOffset;
1589 0 : if (sID >= NSWATH)
1590 : {
1591 0 : return -1;
1592 : }
1593 0 : attrVgrpID = SWXSwath[sID].VIDTable[2];
1594 0 : status = EHattr(fid, attrVgrpID, attrname, numbertype, count,
1595 : wrcode, datbuf);
1596 : }
1597 0 : return (status);
1598 : }
1599 :
1600 :
1601 : /*----------------------------------------------------------------------------|
1602 : | BEGIN_PROLOG |
1603 : | |
1604 : | FUNCTION: SWreadattr |
1605 : | |
1606 : | DESCRIPTION: Reads attribute from a swath. |
1607 : | |
1608 : | |
1609 : | Return Value Type Units Description |
1610 : | ============ ====== ========= ===================================== |
1611 : | status intn return status (0) SUCCEED, (-1) FAIL |
1612 : | |
1613 : | INPUTS: |
1614 : | swathID int32 swath structure ID |
1615 : | attrname char attribute name |
1616 : | |
1617 : | OUTPUTS: |
1618 : | datbuf void I/O buffer |
1619 : | |
1620 : | NOTES: |
1621 : | |
1622 : | |
1623 : | Date Programmer Description |
1624 : | ====== ============ ================================================= |
1625 : | Jun 96 Joel Gales Original Programmer |
1626 : | |
1627 : | END_PROLOG |
1628 : -----------------------------------------------------------------------------*/
1629 : intn
1630 0 : SWreadattr(int32 swathID, const char *attrname, VOIDP datbuf)
1631 : {
1632 0 : intn status = 0; /* routine return status variable */
1633 0 : int32 dum = 0; /* dummy variable */
1634 :
1635 : /* Call SWwrrdattr routine to read attribute */
1636 : /* ----------------------------------------- */
1637 0 : status = SWwrrdattr(swathID, attrname, dum, dum, "r", datbuf);
1638 :
1639 0 : return (status);
1640 : }
1641 :
1642 :
1643 :
1644 :
1645 :
1646 : /*----------------------------------------------------------------------------|
1647 : | BEGIN_PROLOG |
1648 : | |
1649 : | FUNCTION: SWattrinfo |
1650 : | |
1651 : | DESCRIPTION: |
1652 : | |
1653 : | |
1654 : | Return Value Type Units Description |
1655 : | ============ ====== ========= ===================================== |
1656 : | status intn return status (0) SUCCEED, (-1) FAIL |
1657 : | |
1658 : | INPUTS: |
1659 : | swathID int32 swath structure ID |
1660 : | attrname char attribute name |
1661 : | |
1662 : | OUTPUTS: |
1663 : | numbertype int32 attribute HDF numbertype |
1664 : | count int32 Number of attribute elements |
1665 : | |
1666 : | |
1667 : | OUTPUTS: |
1668 : | None |
1669 : | |
1670 : | NOTES: |
1671 : | |
1672 : | |
1673 : | Date Programmer Description |
1674 : | ====== ============ ================================================= |
1675 : | Jun 96 Joel Gales Original Programmer |
1676 : | Oct 96 Joel Gales Get Attribute Vgroup ID from external array |
1677 : | |
1678 : | END_PROLOG |
1679 : -----------------------------------------------------------------------------*/
1680 : intn
1681 0 : SWattrinfo(int32 swathID, const char *attrname, int32 * numbertype, int32 * count)
1682 : {
1683 0 : intn status = 0; /* routine return status variable */
1684 :
1685 : int32 fid; /* HDF-EOS file ID */
1686 : int32 attrVgrpID; /* Swath attribute ID */
1687 : int32 dum; /* dummy variable */
1688 0 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
1689 :
1690 : /* Check for valid swath ID */
1691 : /* ------------------------ */
1692 0 : status = SWchkswid(swathID, "SWattrinfo", &fid, &dum, &dum);
1693 :
1694 0 : if (status == 0)
1695 : {
1696 : /* Get attribute Vgroup ID and call EHattrinfo */
1697 : /* ------------------------------------------- */
1698 0 : int sID = swathID % idOffset;
1699 0 : if (sID >= NSWATH)
1700 : {
1701 0 : return -1;
1702 : }
1703 0 : attrVgrpID = SWXSwath[sID].VIDTable[2];
1704 :
1705 0 : status = EHattrinfo(fid, attrVgrpID, attrname, numbertype,
1706 : count);
1707 : }
1708 0 : return (status);
1709 : }
1710 :
1711 :
1712 :
1713 :
1714 :
1715 :
1716 : /*----------------------------------------------------------------------------|
1717 : | BEGIN_PROLOG |
1718 : | |
1719 : | FUNCTION: SWinqattrs |
1720 : | |
1721 : | DESCRIPTION: |
1722 : | |
1723 : | |
1724 : | Return Value Type Units Description |
1725 : | ============ ====== ========= ===================================== |
1726 : | nattr int32 Number of attributes in swath struct |
1727 : | |
1728 : | INPUTS: |
1729 : | swath ID int32 swath structure ID |
1730 : | |
1731 : | OUTPUTS: |
1732 : | attrnames char Attribute names in swath struct |
1733 : | (Comma-separated list) |
1734 : | strbufsize int32 Attributes name list string length |
1735 : | |
1736 : | OUTPUTS: |
1737 : | None |
1738 : | |
1739 : | NOTES: |
1740 : | |
1741 : | |
1742 : | Date Programmer Description |
1743 : | ====== ============ ================================================= |
1744 : | Jun 96 Joel Gales Original Programmer |
1745 : | Oct 96 Joel Gales Initialize nattr |
1746 : | Oct 96 Joel Gales Get Attribute Vgroup ID from external array |
1747 : | |
1748 : | END_PROLOG |
1749 : -----------------------------------------------------------------------------*/
1750 : int32
1751 3 : SWinqattrs(int32 swathID, char *attrnames, int32 * strbufsize)
1752 : {
1753 : intn status; /* routine return status variable */
1754 :
1755 : int32 fid; /* HDF-EOS file ID */
1756 : int32 attrVgrpID; /* Swath attribute ID */
1757 : int32 dum; /* dummy variable */
1758 3 : int32 nattr = 0; /* Number of attributes */
1759 3 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
1760 :
1761 : /* Check Swath id */
1762 3 : status = SWchkswid(swathID, "SWinqattrs", &fid, &dum, &dum);
1763 :
1764 3 : if (status == 0)
1765 : {
1766 : /* Get attribute Vgroup ID and call EHattrcat */
1767 : /* ------------------------------------------ */
1768 3 : int sID = swathID % idOffset;
1769 3 : if (sID >= NSWATH)
1770 : {
1771 0 : return -1;
1772 : }
1773 3 : attrVgrpID = SWXSwath[sID].VIDTable[2];
1774 :
1775 3 : nattr = EHattrcat(fid, attrVgrpID, attrnames, strbufsize);
1776 : }
1777 :
1778 3 : return (nattr);
1779 : }
1780 :
1781 : #define REMQUOTE(x) do { \
1782 : char* l_x = x; \
1783 : const size_t l_x_len = strlen(l_x); \
1784 : if (l_x_len >= 2 && l_x[0] == '"' && l_x[l_x_len - 1] == '"') {\
1785 : memmove(l_x, l_x + 1, l_x_len - 2); \
1786 : l_x[l_x_len - 2] = 0; \
1787 : } \
1788 : } while(0)
1789 :
1790 :
1791 : /*----------------------------------------------------------------------------|
1792 : | BEGIN_PROLOG |
1793 : | |
1794 : | FUNCTION: SWinqdims |
1795 : | |
1796 : | DESCRIPTION: Returns dimension names and values defined in swath structure |
1797 : | |
1798 : | |
1799 : | Return Value Type Units Description |
1800 : | ============ ====== ========= ===================================== |
1801 : | nDim int32 Number of defined dimensions |
1802 : | |
1803 : | INPUTS: |
1804 : | swathID int32 swath structure ID |
1805 : | |
1806 : | OUTPUTS: |
1807 : | dimnames char Dimension names (comma-separated) |
1808 : | dims int32 Dimension values |
1809 : | |
1810 : | NOTES: |
1811 : | |
1812 : | |
1813 : | Date Programmer Description |
1814 : | ====== ============ ================================================= |
1815 : | Jun 96 Joel Gales Original Programmer |
1816 : | Aug 96 Joel Gales Make metadata ODL compliant |
1817 : | Feb 97 Joel Gales Set nDim to -1 if status = -1 |
1818 : | |
1819 : | END_PROLOG |
1820 : -----------------------------------------------------------------------------*/
1821 : int32
1822 6 : SWinqdims(int32 swathID, char *dimnames, int32 dims[])
1823 :
1824 : {
1825 : intn status; /* routine return status variable */
1826 :
1827 : int32 fid; /* HDF-EOS file ID */
1828 : int32 sdInterfaceID; /* HDF SDS interface ID */
1829 : int32 swVgrpID; /* Swath root Vgroup ID */
1830 : int32 size; /* Dimension size */
1831 6 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
1832 6 : int32 nDim = 0; /* Number of dimensions */
1833 :
1834 : char *metabuf; /* Pointer to structural metadata (SM) */
1835 : char *metaptrs[2];/* Pointers to begin and end of SM section */
1836 : char swathname[80]; /* Swath Name */
1837 : char *utlstr; /* Utility string */
1838 :
1839 :
1840 : /* Allocate space for utility string */
1841 : /* --------------------------------- */
1842 6 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
1843 6 : if(utlstr == NULL)
1844 : {
1845 0 : HEpush(DFE_NOSPACE,"SWinqdims", __FILE__, __LINE__);
1846 0 : return(-1);
1847 : }
1848 :
1849 : /* Check for valid swath id */
1850 6 : status = SWchkswid(swathID, "SWinqdims", &fid, &sdInterfaceID, &swVgrpID);
1851 :
1852 6 : if (status == 0)
1853 : {
1854 : /* If dimension names or sizes are desired ... */
1855 : /* ------------------------------------------- */
1856 6 : if (dimnames != NULL || dims != NULL)
1857 : {
1858 : /* Get swath name */
1859 6 : int sID = swathID % idOffset;
1860 6 : if (sID >= NSWATH)
1861 : {
1862 0 : free(utlstr);
1863 0 : return -1;
1864 : }
1865 6 : VgetnameSafe(SWXSwath[sID].IDTable, swathname, sizeof(swathname));
1866 :
1867 : /* Get pointers to "Dimension" section within SM */
1868 6 : metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",
1869 : "Dimension", metaptrs);
1870 6 : if(metabuf == NULL)
1871 : {
1872 0 : free(utlstr);
1873 0 : return(-1);
1874 : }
1875 : /* If dimension names are desired then "clear" name buffer */
1876 6 : if (dimnames != NULL)
1877 : {
1878 6 : dimnames[0] = 0;
1879 : }
1880 :
1881 :
1882 : /* Begin loop through dimension entries in metadata */
1883 : /* ------------------------------------------------ */
1884 : while (1)
1885 : {
1886 : /* Search for OBJECT string */
1887 112 : metaptrs[0] = strstr(metaptrs[0], "\t\tOBJECT=");
1888 :
1889 : /* If found within "Dimension" metadata section ... */
1890 112 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
1891 : {
1892 : /* Get Dimension Name (if desired) */
1893 106 : if (dimnames != NULL)
1894 : {
1895 : /* Check 1st for old meta data then new */
1896 : /* ------------------------------------ */
1897 106 : EHgetmetavalue(metaptrs, "OBJECT", utlstr);
1898 :
1899 : /*
1900 : * If OBJECT value begins with double quote then old
1901 : * metadata, dimension name is OBJECT value.
1902 : * Otherwise search for "DimensionName" string
1903 : */
1904 106 : if (utlstr[0] != '"')
1905 : {
1906 106 : metaptrs[0] =
1907 106 : strstr(metaptrs[0], "\t\t\t\tDimensionName=");
1908 106 : EHgetmetavalue(metaptrs, "DimensionName", utlstr);
1909 : }
1910 :
1911 : /* Strip off double quotes */
1912 : /* ----------------------- */
1913 106 : REMQUOTE(utlstr);
1914 :
1915 : /* If not first name then add comma delimiter */
1916 106 : if (nDim > 0)
1917 : {
1918 100 : strcat(dimnames, ",");
1919 : }
1920 : /* Add dimension name to dimension list */
1921 106 : strcat(dimnames, utlstr);
1922 : }
1923 :
1924 : /* Get Dimension Size (if desired) */
1925 106 : if (dims != NULL)
1926 : {
1927 53 : EHgetmetavalue(metaptrs, "Size", utlstr);
1928 53 : size = atoi(utlstr);
1929 53 : dims[nDim] = size;
1930 : }
1931 : /* Increment number of dimensions */
1932 106 : nDim++;
1933 : }
1934 : else
1935 : /* No more dimensions found */
1936 : {
1937 : break;
1938 : }
1939 : }
1940 6 : free(metabuf);
1941 : }
1942 : }
1943 :
1944 :
1945 : /* Set nDim to -1 if error status exists */
1946 : /* ------------------------------------- */
1947 6 : if (status == -1)
1948 : {
1949 0 : nDim = -1;
1950 : }
1951 6 : free(utlstr);
1952 :
1953 6 : return (nDim);
1954 : }
1955 :
1956 :
1957 :
1958 :
1959 :
1960 : /*----------------------------------------------------------------------------|
1961 : | BEGIN_PROLOG |
1962 : | |
1963 : | FUNCTION: SWinqmaps |
1964 : | |
1965 : | DESCRIPTION: Returns dimension mappings and offsets and increments |
1966 : | |
1967 : | |
1968 : | Return Value Type Units Description |
1969 : | ============ ====== ========= ===================================== |
1970 : | nMap int32 Number of dimension mappings |
1971 : | |
1972 : | INPUTS: |
1973 : | swathID int32 swath structure ID |
1974 : | |
1975 : | OUTPUTS: |
1976 : | dimmaps char dimension mappings (comma-separated) |
1977 : | offset int32 array of offsets |
1978 : | increment int32 array of increments |
1979 : | |
1980 : | NOTES: |
1981 : | |
1982 : | |
1983 : | Date Programmer Description |
1984 : | ====== ============ ================================================= |
1985 : | Jun 96 Joel Gales Original Programmer |
1986 : | Aug 96 Joel Gales Make metadata ODL compliant |
1987 : | Feb 97 Joel Gales Set nMap to -1 if status = -1 |
1988 : | |
1989 : | END_PROLOG |
1990 : -----------------------------------------------------------------------------*/
1991 : int32
1992 0 : SWinqmaps(int32 swathID, char *dimmaps, int32 offset[], int32 increment[])
1993 :
1994 : {
1995 : intn status; /* routine return status variable */
1996 :
1997 : int32 fid; /* HDF-EOS file ID */
1998 : int32 sdInterfaceID; /* HDF SDS interface ID */
1999 : int32 swVgrpID; /* Swath root Vgroup ID */
2000 : int32 off; /* Mapping Offset */
2001 : int32 incr; /* Mapping Increment */
2002 0 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
2003 0 : int32 nMap = 0; /* Number of mappings */
2004 :
2005 : char *metabuf; /* Pointer to structural metadata (SM) */
2006 : char *metaptrs[2];/* Pointers to begin and end of SM section */
2007 : char swathname[80]; /* Swath Name */
2008 : char *utlstr; /* Utility string */
2009 :
2010 :
2011 : /* Allocate space for utility string */
2012 : /* --------------------------------- */
2013 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
2014 0 : if(utlstr == NULL)
2015 : {
2016 0 : HEpush(DFE_NOSPACE,"SWinqmaps", __FILE__, __LINE__);
2017 0 : return(-1);
2018 : }
2019 :
2020 : /* Check for valid swath id */
2021 0 : status = SWchkswid(swathID, "SWinqmaps", &fid, &sdInterfaceID, &swVgrpID);
2022 0 : if (status == 0)
2023 : {
2024 : /* If mapping names or offsets or increments desired ... */
2025 : /* ----------------------------------------------------- */
2026 0 : if (dimmaps != NULL || offset != NULL || increment != NULL)
2027 : {
2028 :
2029 : /* Get swath name */
2030 0 : int sID = swathID % idOffset;
2031 0 : if (sID >= NSWATH)
2032 : {
2033 0 : free(utlstr);
2034 0 : return -1;
2035 : }
2036 0 : VgetnameSafe(SWXSwath[sID].IDTable, swathname, sizeof(swathname));
2037 :
2038 : /* Get pointers to "DimensionMap" section within SM */
2039 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",
2040 : "DimensionMap", metaptrs);
2041 0 : if(metabuf == NULL)
2042 : {
2043 0 : free(utlstr);
2044 0 : return(-1);
2045 : }
2046 : /* If mapping names are desired then "clear" name buffer */
2047 0 : if (dimmaps != NULL)
2048 : {
2049 0 : dimmaps[0] = 0;
2050 : }
2051 :
2052 : /* Begin loop through mapping entries in metadata */
2053 : /* ---------------------------------------------- */
2054 : while (1)
2055 : {
2056 : /* Search for OBJECT string */
2057 0 : metaptrs[0] = strstr(metaptrs[0], "\t\tOBJECT=");
2058 :
2059 : /* If found within "DimensionMap" metadata section ... */
2060 0 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
2061 : {
2062 : /* Get Geo & Data Dimensions (if desired) */
2063 0 : if (dimmaps != NULL)
2064 : {
2065 : /* Get Geo Dim, remove quotes, add "/" */
2066 0 : EHgetmetavalue(metaptrs, "GeoDimension", utlstr);
2067 0 : REMQUOTE(utlstr);
2068 0 : strcat(utlstr, "/");
2069 :
2070 : /* If not first map then add comma delimiter. */
2071 0 : if (nMap > 0)
2072 : {
2073 0 : strcat(dimmaps, ",");
2074 : }
2075 :
2076 : /* Add to map list */
2077 0 : strcat(dimmaps, utlstr);
2078 :
2079 : /* Get Data Dim, remove quotes */
2080 0 : EHgetmetavalue(metaptrs, "DataDimension", utlstr);
2081 0 : REMQUOTE(utlstr);
2082 :
2083 : /* Add to map list */
2084 0 : strcat(dimmaps, utlstr);
2085 : }
2086 :
2087 : /* Get Offset (if desired) */
2088 0 : if (offset != NULL)
2089 : {
2090 0 : EHgetmetavalue(metaptrs, "Offset", utlstr);
2091 0 : off = atoi(utlstr);
2092 0 : offset[nMap] = off;
2093 : }
2094 :
2095 : /* Get Increment (if desired) */
2096 0 : if (increment != NULL)
2097 : {
2098 0 : EHgetmetavalue(metaptrs, "Increment", utlstr);
2099 0 : incr = atoi(utlstr);
2100 0 : increment[nMap] = incr;
2101 : }
2102 :
2103 : /* Increment number of maps */
2104 0 : nMap++;
2105 : }
2106 : else
2107 : /* No more mappings found */
2108 : {
2109 : break;
2110 : }
2111 : }
2112 0 : free(metabuf);
2113 : }
2114 : }
2115 :
2116 :
2117 : /* Set nMap to -1 if error status exists */
2118 : /* ------------------------------------- */
2119 0 : if (status == -1)
2120 : {
2121 0 : nMap = -1;
2122 : }
2123 0 : free(utlstr);
2124 :
2125 0 : return (nMap);
2126 : }
2127 :
2128 :
2129 :
2130 :
2131 :
2132 : /*----------------------------------------------------------------------------|
2133 : | BEGIN_PROLOG |
2134 : | |
2135 : | FUNCTION: SWinqidxmaps |
2136 : | |
2137 : | DESCRIPTION: Returns l_indexed mappings and l_index sizes |
2138 : | |
2139 : | |
2140 : | Return Value Type Units Description |
2141 : | ============ ====== ========= ===================================== |
2142 : | nMap int32 Number of l_indexed dimension mappings |
2143 : | |
2144 : | INPUTS: |
2145 : | swathID int32 swath structure ID |
2146 : | |
2147 : | OUTPUTS: |
2148 : | idxmaps char l_indexed dimension mappings |
2149 : | (comma-separated) |
2150 : | idxsizes int32 Number of elements in each mapping |
2151 : | |
2152 : | |
2153 : | NOTES: |
2154 : | |
2155 : | |
2156 : | Date Programmer Description |
2157 : | ====== ============ ================================================= |
2158 : | Jun 96 Joel Gales Original Programmer |
2159 : | Aug 96 Joel Gales Make metadata ODL compliant |
2160 : | Feb 97 Joel Gales Set nMap to -1 if status = -1 |
2161 : | |
2162 : | END_PROLOG |
2163 : -----------------------------------------------------------------------------*/
2164 : int32
2165 0 : SWinqidxmaps(int32 swathID, char *idxmaps, int32 idxsizes[])
2166 :
2167 : {
2168 : intn status; /* routine return status variable */
2169 :
2170 : int32 fid; /* HDF-EOS file ID */
2171 : int32 sdInterfaceID; /* HDF SDS interface ID */
2172 : int32 swVgrpID; /* Swath root Vgroup ID */
2173 0 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
2174 0 : int32 nMap = 0; /* Number of mappings */
2175 :
2176 : char *metabuf; /* Pointer to structural metadata (SM) */
2177 : char *metaptrs[2];/* Pointers to begin and end of SM section */
2178 : char swathname[80]; /* Swath Name */
2179 : char *utlstr; /* Utility string */
2180 : char *slash; /* Pointer to slash */
2181 :
2182 :
2183 : /* Allocate space for utility string */
2184 : /* --------------------------------- */
2185 0 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
2186 0 : if(utlstr == NULL)
2187 : {
2188 0 : HEpush(DFE_NOSPACE,"SWinqidxmaps", __FILE__, __LINE__);
2189 0 : return(-1);
2190 : }
2191 : /* Check for valid swath id */
2192 0 : status = SWchkswid(swathID, "SWinqidxmaps", &fid,
2193 : &sdInterfaceID, &swVgrpID);
2194 :
2195 0 : if (status == 0)
2196 : {
2197 : /* If mapping names or l_index sizes desired ... */
2198 : /* ------------------------------------------- */
2199 0 : if (idxmaps != NULL || idxsizes != NULL)
2200 : {
2201 : /* Get swath name */
2202 0 : int sID = swathID % idOffset;
2203 0 : if (sID >= NSWATH)
2204 : {
2205 0 : free(utlstr);
2206 0 : return -1;
2207 : }
2208 0 : VgetnameSafe(SWXSwath[sID].IDTable, swathname, sizeof(swathname));
2209 :
2210 : /* Get pointers to "IndexDimensionMap" section within SM */
2211 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",
2212 : "IndexDimensionMap", metaptrs);
2213 0 : if(metabuf == NULL)
2214 : {
2215 0 : free(utlstr);
2216 0 : return(-1);
2217 : }
2218 : /* If mapping names are desired then "clear" name buffer */
2219 0 : if (idxmaps != NULL)
2220 : {
2221 0 : idxmaps[0] = 0;
2222 : }
2223 :
2224 : /* Begin loop through mapping entries in metadata */
2225 : /* ---------------------------------------------- */
2226 : while (1)
2227 : {
2228 : /* Search for OBJECT string */
2229 0 : metaptrs[0] = strstr(metaptrs[0], "\t\tOBJECT=");
2230 :
2231 : /* If found within "IndexDimensionMap" metadata section ... */
2232 0 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
2233 : {
2234 : /* Get Geo & Data Dimensions and # of indices */
2235 0 : if (idxmaps != NULL)
2236 : {
2237 : /* Get Geo Dim, remove quotes, add "/" */
2238 0 : EHgetmetavalue(metaptrs, "GeoDimension", utlstr);
2239 0 : REMQUOTE(utlstr);
2240 0 : strcat(utlstr, "/");
2241 :
2242 : /* If not first map then add comma delimiter. */
2243 0 : if (nMap > 0)
2244 : {
2245 0 : strcat(idxmaps, ",");
2246 : }
2247 :
2248 : /* Add to map list */
2249 0 : strcat(idxmaps, utlstr);
2250 :
2251 :
2252 : /* Get Index size (if desired) */
2253 0 : if (idxsizes != NULL)
2254 : {
2255 : /* Parse off geo dimension and find its size */
2256 0 : slash = strchr(utlstr, '/');
2257 0 : if (slash) *slash = 0;
2258 0 : idxsizes[nMap] = SWdiminfo(swathID, utlstr);
2259 : }
2260 :
2261 :
2262 : /* Get Data Dim, remove quotes */
2263 0 : EHgetmetavalue(metaptrs, "DataDimension", utlstr);
2264 0 : REMQUOTE(utlstr);
2265 :
2266 : /* Add to map list */
2267 0 : strcat(idxmaps, utlstr);
2268 : }
2269 :
2270 : /* Increment number of maps */
2271 0 : nMap++;
2272 : }
2273 : else
2274 : /* No more mappings found */
2275 : {
2276 : break;
2277 : }
2278 : }
2279 0 : free(metabuf);
2280 : }
2281 : }
2282 :
2283 :
2284 : /* Set nMap to -1 if error status exists */
2285 : /* ------------------------------------- */
2286 0 : if (status == -1)
2287 : {
2288 0 : nMap = -1;
2289 : }
2290 0 : free(utlstr);
2291 :
2292 0 : return (nMap);
2293 : }
2294 :
2295 :
2296 :
2297 :
2298 : /*----------------------------------------------------------------------------|
2299 : | BEGIN_PROLOG |
2300 : | |
2301 : | FUNCTION: SWinqfields |
2302 : | |
2303 : | DESCRIPTION: Returns fieldnames, ranks and numbertypes defined in swath. |
2304 : | |
2305 : | |
2306 : | Return Value Type Units Description |
2307 : | ============ ====== ========= ===================================== |
2308 : | nFld int32 Number of (geo/data) fields in swath |
2309 : | |
2310 : | INPUTS: |
2311 : | swathID int32 swath structure ID |
2312 : | fieldtype char field type (geo or data) |
2313 : | |
2314 : | |
2315 : | OUTPUTS: |
2316 : | fieldlist char Field names (comma-separated) |
2317 : | rank int32 Array of ranks |
2318 : | numbertype int32 Array of HDF number types |
2319 : | |
2320 : | NOTES: |
2321 : | |
2322 : | |
2323 : | Date Programmer Description |
2324 : | ====== ============ ================================================= |
2325 : | Jun 96 Joel Gales Original Programmer |
2326 : | Aug 96 Joel Gales Make metadata ODL compliant |
2327 : | Feb 97 Joel Gales Set nFld to -1 if status = -1 |
2328 : | |
2329 : | END_PROLOG |
2330 : -----------------------------------------------------------------------------*/
2331 : static int32
2332 9 : SWinqfields(int32 swathID, const char *fieldtype, char *fieldlist, int32 rank[],
2333 : int32 numbertype[])
2334 :
2335 : {
2336 : intn status; /* routine return status variable */
2337 :
2338 : int32 fid; /* HDF-EOS file ID */
2339 : int32 sdInterfaceID; /* HDF SDS interface ID */
2340 : int32 swVgrpID; /* Swath root Vgroup ID */
2341 9 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
2342 9 : int32 nFld = 0; /* Number of mappings */
2343 : int32 slen[8]; /* String length array */
2344 :
2345 : char *metabuf; /* Pointer to structural metadata (SM) */
2346 : char *metaptrs[2];/* Pointers to begin and end of SM section */
2347 : char swathname[80]; /* Swath Name */
2348 : char *utlstr; /* Utility string */
2349 : char *utlstr2; /* Utility string 2 */
2350 : char *ptr[8]; /* String pointer array */
2351 :
2352 :
2353 : /* Allocate space for utility string */
2354 : /* --------------------------------- */
2355 9 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
2356 9 : if(utlstr == NULL)
2357 : {
2358 0 : HEpush(DFE_NOSPACE,"SWinqfields", __FILE__, __LINE__);
2359 0 : return(-1);
2360 : }
2361 :
2362 9 : utlstr2 = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
2363 9 : if(utlstr2 == NULL)
2364 : {
2365 0 : HEpush(DFE_NOSPACE,"SWinqfields", __FILE__, __LINE__);
2366 0 : free(utlstr);
2367 0 : return(-1);
2368 : }
2369 :
2370 : /* Check for valid swath id */
2371 9 : status = SWchkswid(swathID, "SWinqfields",
2372 : &fid, &sdInterfaceID, &swVgrpID);
2373 :
2374 9 : if (status == 0)
2375 : {
2376 : /* If field names, ranks, or number types desired ... */
2377 : /* --------------------------------------------------- */
2378 9 : if (fieldlist != NULL || rank != NULL || numbertype != NULL)
2379 : {
2380 : /* Get swath name */
2381 9 : int sID = swathID % idOffset;
2382 9 : if (sID >= NSWATH)
2383 : {
2384 0 : free(utlstr);
2385 0 : free(utlstr2);
2386 0 : return -1;
2387 : }
2388 9 : VgetnameSafe(SWXSwath[sID].IDTable, swathname, sizeof(swathname));
2389 :
2390 : /* Get pointers to "GeoField" or "DataField" section within SM */
2391 9 : if (strcmp(fieldtype, "Geolocation Fields") == 0)
2392 : {
2393 3 : metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",
2394 : "GeoField", metaptrs);
2395 3 : if(metabuf == NULL)
2396 : {
2397 0 : free(utlstr);
2398 0 : free(utlstr2);
2399 0 : return(-1);
2400 : }
2401 3 : strcpy(utlstr2, "GeoFieldName");
2402 : }
2403 : else
2404 : {
2405 6 : metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",
2406 : "DataField", metaptrs);
2407 6 : if(metabuf == NULL)
2408 : {
2409 0 : free(utlstr);
2410 0 : free(utlstr2);
2411 0 : return(-1);
2412 : }
2413 6 : strcpy(utlstr2, "DataFieldName");
2414 : }
2415 :
2416 :
2417 : /* If field names are desired then "clear" name buffer */
2418 9 : if (fieldlist != NULL)
2419 : {
2420 9 : fieldlist[0] = 0;
2421 : }
2422 :
2423 :
2424 : /* Begin loop through mapping entries in metadata */
2425 : /* ---------------------------------------------- */
2426 13 : while (metaptrs[0])
2427 : {
2428 : /* Search for OBJECT string */
2429 10 : metaptrs[0] = strstr(metaptrs[0], "\t\tOBJECT=");
2430 :
2431 : /* If found within "Geo" or "Data" Field metadata section .. */
2432 10 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
2433 : {
2434 : /* Get Fieldnames (if desired) */
2435 4 : if (fieldlist != NULL)
2436 : {
2437 : /* Check 1st for old meta data then new */
2438 : /* ------------------------------------ */
2439 4 : EHgetmetavalue(metaptrs, "OBJECT", utlstr);
2440 :
2441 : /*
2442 : * If OBJECT value begins with double quote then old
2443 : * metadata, field name is OBJECT value. Otherwise
2444 : * search for "GeoFieldName" or "DataFieldName"
2445 : * string
2446 : */
2447 :
2448 4 : if (utlstr[0] != '"')
2449 : {
2450 4 : strcpy(utlstr, "\t\t\t\t");
2451 4 : strcat(utlstr, utlstr2);
2452 4 : strcat(utlstr, "=");
2453 4 : metaptrs[0] = strstr(metaptrs[0], utlstr);
2454 4 : EHgetmetavalue(metaptrs, utlstr2, utlstr);
2455 : }
2456 :
2457 : /* Strip off double quotes */
2458 : /* ----------------------- */
2459 4 : REMQUOTE(utlstr);
2460 :
2461 :
2462 : /* Add to fieldlist */
2463 : /* ---------------- */
2464 4 : if (nFld > 0)
2465 : {
2466 0 : strcat(fieldlist, ",");
2467 : }
2468 4 : strcat(fieldlist, utlstr);
2469 :
2470 : }
2471 : /* Get Numbertype */
2472 4 : if (numbertype != NULL)
2473 : {
2474 4 : EHgetmetavalue(metaptrs, "DataType", utlstr);
2475 4 : numbertype[nFld] = EHnumstr(utlstr);
2476 : }
2477 : /*
2478 : * Get Rank (if desired) by counting # of dimensions in
2479 : * "DimList" string
2480 : */
2481 4 : if (rank != NULL)
2482 : {
2483 4 : EHgetmetavalue(metaptrs, "DimList", utlstr);
2484 4 : rank[nFld] = EHparsestr(utlstr, ',', ptr, CPL_ARRAYSIZE(ptr), slen, CPL_ARRAYSIZE(slen));
2485 4 : if (rank[nFld] < 0)
2486 : {
2487 0 : HEpush(DFE_NOSPACE, "SWinqfields", __FILE__, __LINE__);
2488 0 : status = -1;
2489 0 : break;
2490 : }
2491 : }
2492 : /* Increment number of fields */
2493 4 : nFld++;
2494 : }
2495 : else
2496 : /* No more fields found */
2497 : {
2498 : break;
2499 : }
2500 : }
2501 9 : free(metabuf);
2502 : }
2503 : }
2504 :
2505 : /* Set nFld to -1 if error status exists */
2506 : /* ------------------------------------- */
2507 9 : if (status == -1)
2508 : {
2509 0 : nFld = -1;
2510 : }
2511 :
2512 9 : free(utlstr);
2513 9 : free(utlstr2);
2514 :
2515 9 : return (nFld);
2516 : }
2517 :
2518 :
2519 :
2520 :
2521 : /*----------------------------------------------------------------------------|
2522 : | BEGIN_PROLOG |
2523 : | |
2524 : | FUNCTION: SWinqgeofields |
2525 : | |
2526 : | DESCRIPTION: Inquires about geo fields in swath |
2527 : | |
2528 : | |
2529 : | Return Value Type Units Description |
2530 : | ============ ====== ========= ===================================== |
2531 : | nflds int32 Number of geo fields in swath |
2532 : | |
2533 : | INPUTS: |
2534 : | swathID int32 swath structure ID |
2535 : | |
2536 : | OUTPUTS: |
2537 : | fieldlist char Field names (comma-separated) |
2538 : | rank int32 Array of ranks |
2539 : | numbertype int32 Array of HDF number types |
2540 : | |
2541 : | NOTES: |
2542 : | |
2543 : | |
2544 : | Date Programmer Description |
2545 : | ====== ============ ================================================= |
2546 : | Jun 96 Joel Gales Original Programmer |
2547 : | |
2548 : | END_PROLOG |
2549 : -----------------------------------------------------------------------------*/
2550 : int32
2551 3 : SWinqgeofields(int32 swathID, char *fieldlist, int32 rank[],
2552 : int32 numbertype[])
2553 : {
2554 :
2555 : int32 nflds; /* Number of Geolocation fields */
2556 :
2557 : /* Call "SWinqfields" routine */
2558 : /* -------------------------- */
2559 3 : nflds = SWinqfields(swathID, "Geolocation Fields", fieldlist, rank,
2560 : numbertype);
2561 :
2562 3 : return (nflds);
2563 :
2564 : }
2565 :
2566 :
2567 :
2568 :
2569 : /*----------------------------------------------------------------------------|
2570 : | BEGIN_PROLOG |
2571 : | |
2572 : | FUNCTION: SWinqdatafields |
2573 : | |
2574 : | DESCRIPTION: Inquires about data fields in swath |
2575 : | |
2576 : | |
2577 : | Return Value Type Units Description |
2578 : | ============ ====== ========= ===================================== |
2579 : | nflds int32 Number of data fields in swath |
2580 : | |
2581 : | INPUTS: |
2582 : | swathID int32 swath structure ID |
2583 : | |
2584 : | OUTPUTS: |
2585 : | fieldlist char Field names (comma-separated) |
2586 : | rank int32 Array of ranks |
2587 : | numbertype int32 Array of HDF number types |
2588 : | |
2589 : | NOTES: |
2590 : | |
2591 : | |
2592 : | Date Programmer Description |
2593 : | ====== ============ ================================================= |
2594 : | Jun 96 Joel Gales Original Programmer |
2595 : | |
2596 : | END_PROLOG |
2597 : -----------------------------------------------------------------------------*/
2598 : int32
2599 6 : SWinqdatafields(int32 swathID, char *fieldlist, int32 rank[],
2600 : int32 numbertype[])
2601 : {
2602 :
2603 : int32 nflds; /* Number of Data fields */
2604 :
2605 : /* Call "SWinqfields" routine */
2606 : /* -------------------------- */
2607 6 : nflds = SWinqfields(swathID, "Data Fields", fieldlist, rank,
2608 : numbertype);
2609 :
2610 6 : return (nflds);
2611 :
2612 : }
2613 :
2614 :
2615 :
2616 :
2617 : /*----------------------------------------------------------------------------|
2618 : | BEGIN_PROLOG |
2619 : | |
2620 : | FUNCTION: SWnentries |
2621 : | |
2622 : | DESCRIPTION: Returns number of entries and string buffer size |
2623 : | |
2624 : | |
2625 : | Return Value Type Units Description |
2626 : | ============ ====== ========= ===================================== |
2627 : | nEntries int32 Number of entries |
2628 : | |
2629 : | INPUTS: |
2630 : | swathID int32 swath structure ID |
2631 : | entrycode int32 Entry code |
2632 : | HDFE_NENTDIM (0) |
2633 : | HDFE_NENTMAP (1) |
2634 : | HDFE_NENTIMAP (2) |
2635 : | HDFE_NENTGFLD (3) |
2636 : | HDFE_NENTDFLD (4) |
2637 : | |
2638 : | |
2639 : | OUTPUTS: |
2640 : | strbufsize int32 Length of comma-separated list |
2641 : | (Does not include null-terminator |
2642 : | |
2643 : | NOTES: |
2644 : | |
2645 : | |
2646 : | Date Programmer Description |
2647 : | ====== ============ ================================================= |
2648 : | Jun 96 Joel Gales Original Programmer |
2649 : | Aug 96 Joel Gales Make metadata ODL compliant |
2650 : | Feb 97 Joel Gales Set nEntries to -1 if status = -1 |
2651 : | |
2652 : | END_PROLOG |
2653 : -----------------------------------------------------------------------------*/
2654 : int32
2655 15 : SWnentries(int32 swathID, int32 entrycode, int32 * strbufsize)
2656 :
2657 : {
2658 : intn status; /* routine return status variable */
2659 : intn i; /* Loop index */
2660 :
2661 : int32 fid; /* HDF-EOS file ID */
2662 : int32 sdInterfaceID; /* HDF SDS interface ID */
2663 : int32 swVgrpID; /* Swath root Vgroup ID */
2664 15 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
2665 15 : int32 nEntries = 0; /* Number of entries */
2666 : int32 metaflag; /* Old (0), New (1) metadata flag) */
2667 15 : int32 nVal = 0; /* Number of strings to search for */
2668 :
2669 15 : char *metabuf = NULL; /* Pointer to structural metadata (SM) */
2670 : char *metaptrs[2]; /* Pointers to begin and end of SM section */
2671 : char swathname[80]; /* Swath Name */
2672 : char *utlstr; /* Utility string */
2673 : char valName[2][32]; /* Strings to search for */
2674 :
2675 : /* Allocate space for utility string */
2676 : /* --------------------------------- */
2677 15 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
2678 15 : if(utlstr == NULL)
2679 : {
2680 0 : HEpush(DFE_NOSPACE,"SWnemtries", __FILE__, __LINE__);
2681 0 : return(-1);
2682 : }
2683 : /* Check for valid swath id */
2684 : /* ------------------------ */
2685 15 : status = SWchkswid(swathID, "SWnentries", &fid, &sdInterfaceID, &swVgrpID);
2686 :
2687 15 : if (status == 0)
2688 : {
2689 : /* Get swath name */
2690 15 : int sID = swathID % idOffset;
2691 15 : if (sID >= NSWATH)
2692 : {
2693 0 : free(utlstr);
2694 0 : return -1;
2695 : }
2696 15 : VgetnameSafe(SWXSwath[sID].IDTable, swathname, sizeof(swathname));
2697 :
2698 : /* Zero out string buffer size */
2699 15 : *strbufsize = 0;
2700 :
2701 :
2702 : /*
2703 : * Get pointer to relevant section within SM and Get names of
2704 : * metadata strings to inquire about
2705 : */
2706 15 : switch (entrycode)
2707 : {
2708 6 : case HDFE_NENTDIM:
2709 : /* Dimensions */
2710 : {
2711 6 : metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",
2712 : "Dimension", metaptrs);
2713 6 : if(metabuf == NULL)
2714 : {
2715 0 : free(utlstr);
2716 0 : return(-1);
2717 : }
2718 6 : nVal = 1;
2719 6 : strcpy(&valName[0][0], "DimensionName");
2720 : }
2721 6 : break;
2722 :
2723 0 : case HDFE_NENTMAP:
2724 : /* Dimension Maps */
2725 : {
2726 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",
2727 : "DimensionMap", metaptrs);
2728 0 : if(metabuf == NULL)
2729 : {
2730 0 : free(utlstr);
2731 0 : return(-1);
2732 : }
2733 0 : nVal = 2;
2734 0 : strcpy(&valName[0][0], "GeoDimension");
2735 0 : strcpy(&valName[1][0], "DataDimension");
2736 : }
2737 0 : break;
2738 :
2739 0 : case HDFE_NENTIMAP:
2740 : /* Indexed Dimension Maps */
2741 : {
2742 0 : metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",
2743 : "IndexDimensionMap", metaptrs);
2744 0 : if(metabuf == NULL)
2745 : {
2746 0 : free(utlstr);
2747 0 : return(-1);
2748 : }
2749 0 : nVal = 2;
2750 0 : strcpy(&valName[0][0], "GeoDimension");
2751 0 : strcpy(&valName[1][0], "DataDimension");
2752 : }
2753 0 : break;
2754 :
2755 3 : case HDFE_NENTGFLD:
2756 : /* Geolocation Fields */
2757 : {
2758 3 : metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",
2759 : "GeoField", metaptrs);
2760 3 : if(metabuf == NULL)
2761 : {
2762 0 : free(utlstr);
2763 0 : return(-1);
2764 : }
2765 3 : nVal = 1;
2766 3 : strcpy(&valName[0][0], "GeoFieldName");
2767 : }
2768 3 : break;
2769 :
2770 6 : case HDFE_NENTDFLD:
2771 : /* Data Fields */
2772 : {
2773 6 : metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",
2774 : "DataField", metaptrs);
2775 6 : if(metabuf == NULL)
2776 : {
2777 0 : free(utlstr);
2778 0 : return(-1);
2779 : }
2780 6 : nVal = 1;
2781 6 : strcpy(&valName[0][0], "DataFieldName");
2782 : }
2783 6 : break;
2784 : }
2785 :
2786 :
2787 : /*
2788 : * Check for presence of 'GROUP="' string If found then old metadata,
2789 : * search on OBJECT string
2790 : */
2791 15 : if (metabuf)
2792 : {
2793 15 : metaflag = (strstr(metabuf, "GROUP=\"") == NULL) ? 1 : 0;
2794 15 : if (metaflag == 0)
2795 : {
2796 0 : nVal = 1;
2797 0 : strcpy(&valName[0][0], "\t\tOBJECT");
2798 : }
2799 :
2800 :
2801 : /* Begin loop through entries in metadata */
2802 : /* -------------------------------------- */
2803 77 : while (metaptrs[0])
2804 : {
2805 : /* Search for first string */
2806 74 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s=", &valName[0][0]);
2807 74 : metaptrs[0] = strstr(metaptrs[0], utlstr);
2808 :
2809 : /* If found within relevant metadata section ... */
2810 74 : if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL)
2811 : {
2812 124 : for (i = 0; i < nVal; i++)
2813 : {
2814 : /*
2815 : * Get all string values Don't count quotes
2816 : */
2817 62 : EHgetmetavalue(metaptrs, &valName[i][0], utlstr);
2818 62 : const size_t len = strlen(utlstr);
2819 62 : if( len >= 2 && utlstr[0] == '"' && utlstr[len-1] == '"' )
2820 12 : *strbufsize += (int32)len - 2;
2821 : else
2822 50 : *strbufsize += (int32)len;
2823 : }
2824 : /* Increment number of entries */
2825 62 : nEntries++;
2826 :
2827 : /* Go to end of OBJECT */
2828 62 : metaptrs[0] = strstr(metaptrs[0], "END_OBJECT");
2829 : }
2830 : else
2831 : /* No more entries found */
2832 : {
2833 : break;
2834 : }
2835 : }
2836 15 : free(metabuf);
2837 : }
2838 :
2839 :
2840 : /* Count comma separators & slashes (if mappings) */
2841 : /* ---------------------------------------------- */
2842 15 : if (nEntries > 0)
2843 : {
2844 10 : *strbufsize += nEntries - 1;
2845 10 : *strbufsize += (nVal - 1) * nEntries;
2846 : }
2847 : }
2848 :
2849 :
2850 : /* Set nEntries to -1 if error status exists */
2851 : /* ----------------------------------------- */
2852 15 : if (status == -1)
2853 0 : nEntries = -1;
2854 :
2855 15 : free(utlstr);
2856 :
2857 15 : return (nEntries);
2858 : }
2859 :
2860 :
2861 :
2862 :
2863 :
2864 : /*----------------------------------------------------------------------------|
2865 : | BEGIN_PROLOG |
2866 : | |
2867 : | FUNCTION: SWinqswath |
2868 : | |
2869 : | DESCRIPTION: Returns number and names of swath structures in file |
2870 : | |
2871 : | |
2872 : | Return Value Type Units Description |
2873 : | ============ ====== ========= ===================================== |
2874 : | nSwath int32 Number of swath structures in file |
2875 : | |
2876 : | INPUTS: |
2877 : | filename char HDF-EOS filename |
2878 : | |
2879 : | OUTPUTS: |
2880 : | swathlist char List of swath names (comma-separated) |
2881 : | strbufsize int32 Length of swathlist |
2882 : | |
2883 : | NOTES: |
2884 : | |
2885 : | |
2886 : | Date Programmer Description |
2887 : | ====== ============ ================================================= |
2888 : | Jun 96 Joel Gales Original Programmer |
2889 : | |
2890 : | END_PROLOG |
2891 : -----------------------------------------------------------------------------*/
2892 : int32
2893 25 : SWinqswath(const char *filename, char *swathlist, int32 * strbufsize)
2894 : {
2895 : int32 nSwath; /* Number of swath structures in file */
2896 :
2897 : /* Call "EHinquire" routine */
2898 : /* ------------------------ */
2899 25 : nSwath = EHinquire(filename, "SWATH", swathlist, strbufsize);
2900 :
2901 25 : return (nSwath);
2902 : }
2903 :
2904 :
2905 :
2906 : /*----------------------------------------------------------------------------|
2907 : | BEGIN_PROLOG |
2908 : | |
2909 : | FUNCTION: SW1dfldsrch |
2910 : | |
2911 : | DESCRIPTION: Retrieves information about a 1D field |
2912 : | |
2913 : | |
2914 : | Return Value Type Units Description |
2915 : | ============ ====== ========= ===================================== |
2916 : | status intn return status (0) SUCCEED, (-1) FAIL |
2917 : | |
2918 : | INPUTS: |
2919 : | fid int32 HDF-EOS file ID |
2920 : | swathID int32 swath structure ID |
2921 : | fieldname const char field name |
2922 : | access const char Access code (w/r) |
2923 : | |
2924 : | |
2925 : | OUTPUTS: |
2926 : | vgidout int32 Field (geo/data) vgroup ID |
2927 : | vdataIDout int32 Field Vdata ID |
2928 : | fldtype int32 Field type |
2929 : | |
2930 : | NOTES: |
2931 : | |
2932 : | |
2933 : | Date Programmer Description |
2934 : | ====== ============ ================================================= |
2935 : | Jun 96 Joel Gales Original Programmer |
2936 : | |
2937 : | END_PROLOG |
2938 : -----------------------------------------------------------------------------*/
2939 : static intn
2940 0 : SW1dfldsrch(int32 fid, int32 swathID, const char *fieldname, const char *i_access,
2941 : int32 * vgidout, int32 * vdataIDout, int32 * fldtype)
2942 :
2943 : {
2944 0 : intn status = 0; /* routine return status variable */
2945 :
2946 : int32 sID; /* SwathID - offset */
2947 : int32 vgid; /* Swath Geo or Data Vgroup ID */
2948 : int32 vdataID; /* 1d field vdata */
2949 0 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
2950 :
2951 :
2952 : /* Compute "reduced" swath ID */
2953 : /* -------------------------- */
2954 0 : sID = swathID % idOffset;
2955 0 : if (sID >= NSWATH)
2956 : {
2957 0 : return -1;
2958 : }
2959 :
2960 : /* Get Geolocation Vgroup id and 1D field name Vdata id */
2961 : /* ---------------------------------------------------- */
2962 0 : vgid = SWXSwath[sID].VIDTable[0];
2963 0 : vdataID = EHgetid(fid, vgid, fieldname, 1, i_access);
2964 0 : *fldtype = 0;
2965 :
2966 :
2967 : /*
2968 : * If name not found in Geolocation Vgroup then detach Geolocation Vgroup
2969 : * and search in Data Vgroup
2970 : */
2971 0 : if (vdataID == -1)
2972 : {
2973 0 : vgid = SWXSwath[sID].VIDTable[1];;
2974 0 : vdataID = EHgetid(fid, vgid, fieldname, 1, i_access);
2975 0 : *fldtype = 1;
2976 :
2977 : /* If field also not found in Data Vgroup then set error status */
2978 : /* ------------------------------------------------------------ */
2979 0 : if (vdataID == -1)
2980 : {
2981 0 : status = -1;
2982 0 : vgid = -1;
2983 0 : vdataID = -1;
2984 : }
2985 : }
2986 0 : *vgidout = vgid;
2987 0 : *vdataIDout = vdataID;
2988 :
2989 0 : return (status);
2990 : }
2991 :
2992 :
2993 :
2994 :
2995 :
2996 : /*----------------------------------------------------------------------------|
2997 : | BEGIN_PROLOG |
2998 : | |
2999 : | FUNCTION: SWSDfldsrch |
3000 : | |
3001 : | DESCRIPTION: Retrieves information SDS field |
3002 : | |
3003 : | |
3004 : | Return Value Type Units Description |
3005 : | ============ ====== ========= ===================================== |
3006 : | status intn return status (0) SUCCEED, (-1) FAIL |
3007 : | |
3008 : | INPUTS: |
3009 : | swathID int32 swath structure ID |
3010 : | sdInterfaceID int32 SD interface ID |
3011 : | fieldname const char field name |
3012 : | |
3013 : | |
3014 : | OUTPUTS: |
3015 : | sdid int32 SD element ID |
3016 : | rankSDS int32 Rank of SDS |
3017 : | rankFld int32 True rank of field (merging) |
3018 : | offset int32 Offset of field within merged field |
3019 : | dims int32 Dimensions of field |
3020 : | solo int32 Solo field flag |
3021 : | |
3022 : | NOTES: |
3023 : | |
3024 : | |
3025 : | Date Programmer Description |
3026 : | ====== ============ ================================================= |
3027 : | Jun 96 Joel Gales Original Programmer |
3028 : | Aug 96 Joel Gales Make metadata ODL compliant |
3029 : | |
3030 : | END_PROLOG |
3031 : -----------------------------------------------------------------------------*/
3032 : static intn
3033 5 : SWSDfldsrch(int32 swathID, int32 sdInterfaceID, const char *fieldname,
3034 : int32 * sdid, int32 * rankSDS, int32 * rankFld, int32 * offset,
3035 : int32 dims[], int32 * solo)
3036 : {
3037 : intn i; /* Loop index */
3038 5 : intn status = -1;/* routine return status variable */
3039 :
3040 : int32 sID; /* SwathID - offset */
3041 5 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
3042 : int32 dum; /* Dummy variable */
3043 : int32 dums[128]; /* Dummy array */
3044 : int32 attrIndex; /* Attribute l_index */
3045 :
3046 : char name[2048]; /* Merged-Field Names */
3047 : char swathname[80]; /* Swath Name */
3048 : char *utlstr; /* Utility string */
3049 : char *metabuf; /* Pointer to structural metadata (SM) */
3050 : char *metaptrs[2];/* Pointers to begin and end of SM section */
3051 : char *oldmetaptr; /* Pointer within SM section */
3052 :
3053 :
3054 : /* Allocate space for utility string */
3055 : /* --------------------------------- */
3056 5 : utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
3057 5 : if(utlstr == NULL)
3058 : {
3059 0 : HEpush(DFE_NOSPACE,"SWSDfldsrch", __FILE__, __LINE__);
3060 0 : return(-1);
3061 : }
3062 : /* Set solo flag to 0 (no) */
3063 : /* ----------------------- */
3064 5 : *solo = 0;
3065 :
3066 :
3067 : /* Compute "reduced" swath ID */
3068 : /* -------------------------- */
3069 5 : sID = swathID % idOffset;
3070 5 : if (sID >= NSWATH)
3071 : {
3072 0 : free(utlstr);
3073 0 : return -1;
3074 : }
3075 :
3076 : /* Loop through all SDSs in swath */
3077 : /* ------------------------------ */
3078 8 : for (i = 0; i < SWXSwath[sID].nSDS; i++)
3079 : {
3080 : /* If active SDS ... */
3081 : /* ----------------- */
3082 3 : if (SWXSwath[sID].sdsID[i] != 0)
3083 : {
3084 : /* Get SDS ID, name, rankSDS, and dimensions */
3085 : /* ----------------------------------------- */
3086 3 : *sdid = SWXSwath[sID].sdsID[i];
3087 3 : SDgetinfo(*sdid, name, rankSDS, dims, &dum, &dum);
3088 3 : *rankFld = *rankSDS;
3089 :
3090 : /* If merged field ... */
3091 : /* ------------------- */
3092 3 : if (strstr(name, "MRGFLD_") == &name[0])
3093 : {
3094 : /* Get swath name */
3095 : /* -------------- */
3096 3 : VgetnameSafe(SWXSwath[sID].IDTable, swathname, sizeof(swathname));
3097 :
3098 :
3099 : /* Get pointers to "MergedFields" section within SM */
3100 : /* ------------------------------------------------ */
3101 3 : metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s",
3102 : "MergedFields", metaptrs);
3103 3 : if(metabuf == NULL)
3104 : {
3105 0 : free(utlstr);
3106 0 : return(-1);
3107 : }
3108 :
3109 : /* Store metaptr in order to recover */
3110 : /* --------------------------------- */
3111 3 : oldmetaptr = metaptrs[0];
3112 :
3113 :
3114 : /* Search for Merged field name */
3115 : /* ---------------------------- */
3116 3 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%.480s%s", "MergedFieldName=\"",
3117 : name, "\"\n");
3118 3 : metaptrs[0] = strstr(metaptrs[0], utlstr);
3119 :
3120 :
3121 : /* If not found check for old metadata */
3122 : /* ----------------------------------- */
3123 3 : if (metaptrs[0] == NULL)
3124 : {
3125 0 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%.480s%s", "OBJECT=\"", name, "\"\n");
3126 0 : metaptrs[0] = strstr(oldmetaptr, utlstr);
3127 : }
3128 :
3129 : /* Get field list and strip off leading and trailing quotes */
3130 3 : if (EHgetmetavalue(metaptrs, "FieldList", name) == 0)
3131 : {
3132 3 : const size_t len = strlen(name);
3133 3 : if (len >= 2 && name[0] == '"' && name[len-1] == '"')
3134 : {
3135 0 : memmove(name, name + 1, strlen(name) - 2);
3136 0 : name[strlen(name) - 2] = 0;
3137 : }
3138 : }
3139 : else
3140 : {
3141 0 : name[0] = '\0';
3142 : }
3143 :
3144 : /* Search for desired field within merged field list */
3145 3 : snprintf(utlstr, UTLSTR_MAX_SIZE, "%s%s%s", "\"", fieldname, "\"");
3146 3 : dum = EHstrwithin(utlstr, name, ',');
3147 :
3148 3 : free(metabuf);
3149 : }
3150 : else
3151 : {
3152 : /* If solo (unmerged) check if SDS name matches fieldname */
3153 : /* ------------------------------------------------------ */
3154 0 : dum = EHstrwithin(fieldname, name, ',');
3155 0 : if (dum != -1)
3156 : {
3157 0 : *solo = 1;
3158 0 : *offset = 0;
3159 : }
3160 : }
3161 :
3162 :
3163 : /* If field found ... */
3164 : /* ------------------ */
3165 3 : if (dum != -1)
3166 : {
3167 0 : status = 0;
3168 :
3169 : /* If merged field ... */
3170 : /* ------------------- */
3171 0 : if (*solo == 0)
3172 : {
3173 : /* Get "Field Offsets" SDS attribute l_index */
3174 : /* --------------------------------------- */
3175 0 : attrIndex = SDfindattr(*sdid, "Field Offsets");
3176 :
3177 : /*
3178 : * If attribute exists then get offset of desired field
3179 : * within merged field
3180 : */
3181 0 : if (attrIndex != -1)
3182 : {
3183 0 : SDreadattr(*sdid, attrIndex, (VOIDP) dums);
3184 0 : *offset = dums[dum];
3185 : }
3186 :
3187 :
3188 : /* Get "Field Dims" SDS attribute l_index */
3189 : /* ------------------------------------ */
3190 0 : attrIndex = SDfindattr(*sdid, "Field Dims");
3191 :
3192 : /*
3193 : * If attribute exists then get 0th dimension of desired
3194 : * field within merged field
3195 : */
3196 0 : if (attrIndex != -1)
3197 : {
3198 0 : SDreadattr(*sdid, attrIndex, (VOIDP) dums);
3199 0 : dims[0] = dums[dum];
3200 :
3201 : /* If this dimension = 1 then field is really 2 dim */
3202 : /* ------------------------------------------------ */
3203 0 : if (dums[dum] == 1)
3204 : {
3205 0 : *rankFld = 2;
3206 : }
3207 : }
3208 : }
3209 :
3210 :
3211 : /* Break out of SDS loop */
3212 : /* --------------------- */
3213 0 : break;
3214 : } /* End of found field section */
3215 : }
3216 : else
3217 : {
3218 : /* First non-active SDS signifies no more, break out of SDS loop */
3219 : /* ------------------------------------------------------------- */
3220 0 : break;
3221 : }
3222 : }
3223 :
3224 5 : free(utlstr);
3225 :
3226 5 : return (status);
3227 : }
3228 :
3229 :
3230 :
3231 :
3232 :
3233 : /*----------------------------------------------------------------------------|
3234 : | BEGIN_PROLOG |
3235 : | |
3236 : | FUNCTION: SWwrrdfield |
3237 : | |
3238 : | DESCRIPTION: Writes/Reads fields |
3239 : | |
3240 : | |
3241 : | Return Value Type Units Description |
3242 : | ============ ====== ========= ===================================== |
3243 : | status intn return status (0) SUCCEED, (-1) FAIL |
3244 : | |
3245 : | INPUTS: |
3246 : | swathID int32 swath structure ID |
3247 : | fieldname const char fieldname |
3248 : | code const char Write/Read code (w/r) |
3249 : | start int32 start array |
3250 : | stride int32 stride array |
3251 : | edge int32 edge array |
3252 : | datbuf void data buffer for read |
3253 : | |
3254 : | |
3255 : | OUTPUTS: |
3256 : | datbuf void data buffer for write |
3257 : | |
3258 : | NOTES: |
3259 : | |
3260 : | |
3261 : | Date Programmer Description |
3262 : | ====== ============ ================================================= |
3263 : | Jun 96 Joel Gales Original Programmer |
3264 : | Feb 97 Joel Gales Stride = 1 HDF compression workaround |
3265 : | |
3266 : | END_PROLOG |
3267 : -----------------------------------------------------------------------------*/
3268 : static intn
3269 0 : SWwrrdfield(int32 swathID, const char *fieldname, const char *code,
3270 : int32 start[], int32 stride[], int32 edge[], VOIDP datbuf)
3271 :
3272 : {
3273 : intn i; /* Loop index */
3274 0 : intn status = 0; /* routine return status variable */
3275 :
3276 : int32 fid; /* HDF-EOS file ID */
3277 : int32 sdInterfaceID; /* HDF SDS interface ID */
3278 : int32 vgid; /* Swath Geo or Data Vgroup ID */
3279 : int32 sdid; /* SDS ID */
3280 : int32 dum; /* Dummy variable */
3281 : int32 rankSDS; /* Rank of SDS */
3282 : int32 rankFld; /* Rank of field */
3283 :
3284 : int32 vdataID; /* 1d field vdata */
3285 : int32 recsize; /* Vdata record size */
3286 : int32 fldsize; /* Field size */
3287 : int32 nrec; /* Number of records in Vdata */
3288 :
3289 0 : int32 offset[8] = {0}; /* I/O offset (start) */
3290 : int32 incr[8]; /* I/O increment (stride) */
3291 : int32 count[8]; /* I/O count (edge) */
3292 : int32 dims[8]; /* Field/SDS dimensions */
3293 0 : int32 mrgOffset = 0; /* Merged field offset */
3294 : int32 nflds; /* Number of fields in Vdata */
3295 : int32 strideOne; /* Strides = 1 flag */
3296 :
3297 : uint8 *buf; /* I/O (transfer) buffer */
3298 : uint8 *fillbuf; /* Fill value buffer */
3299 :
3300 : char attrName[80]; /* Name of fill value attribute */
3301 : char *ptr[64]; /* String pointer array */
3302 : char fieldlist[256]; /* Vdata field list */
3303 :
3304 0 : for (i = 0; i < 8; ++i)
3305 0 : incr[i] = 1;
3306 :
3307 : /* Check for valid swath ID */
3308 : /* ------------------------ */
3309 0 : status = SWchkswid(swathID, "SWwrrdfield", &fid, &sdInterfaceID, &dum);
3310 :
3311 :
3312 0 : if (status == 0)
3313 : {
3314 :
3315 : /* Check whether fieldname is in SDS (multi-dim field) */
3316 : /* --------------------------------------------------- */
3317 0 : status = SWSDfldsrch(swathID, sdInterfaceID, fieldname, &sdid,
3318 : &rankSDS, &rankFld, &mrgOffset, dims, &dum);
3319 :
3320 : /* Multi-Dimensional Field Section */
3321 : /* ------------------------------- */
3322 0 : if (status != -1)
3323 : {
3324 : /* Set I/O offset Section */
3325 : /* ---------------------- */
3326 :
3327 : /*
3328 : * If start == NULL (default) set I/O offset of 0th field to
3329 : * offset within merged field (if any) and the rest to 0
3330 : */
3331 0 : if (start == NULL)
3332 : {
3333 0 : for (i = 0; i < rankSDS; i++)
3334 : {
3335 0 : offset[i] = 0;
3336 : }
3337 0 : offset[0] = mrgOffset;
3338 : }
3339 : else
3340 : {
3341 : /*
3342 : * ... otherwise set I/O offset to user values, adjusting the
3343 : * 0th field with the merged field offset (if any)
3344 : */
3345 0 : if (rankFld == rankSDS)
3346 : {
3347 0 : for (i = 0; i < rankSDS; i++)
3348 : {
3349 0 : offset[i] = start[i];
3350 : }
3351 0 : offset[0] += mrgOffset;
3352 : }
3353 : else
3354 : {
3355 : /*
3356 : * If field really 2-dim merged in 3-dim field then set
3357 : * 0th field offset to merge offset and then next two to
3358 : * the user values
3359 : */
3360 0 : for (i = 0; i < rankFld; i++)
3361 : {
3362 0 : offset[i + 1] = start[i];
3363 : }
3364 0 : offset[0] = mrgOffset;
3365 : }
3366 : }
3367 :
3368 :
3369 :
3370 : /* Set I/O stride Section */
3371 : /* ---------------------- */
3372 :
3373 : /*
3374 : * If stride == NULL (default) set I/O stride to 1
3375 : */
3376 0 : if (stride == NULL)
3377 : {
3378 0 : for (i = 0; i < rankSDS; i++)
3379 : {
3380 0 : incr[i] = 1;
3381 : }
3382 : }
3383 : else
3384 : {
3385 : /*
3386 : * ... otherwise set I/O stride to user values
3387 : */
3388 0 : if (rankFld == rankSDS)
3389 : {
3390 0 : for (i = 0; i < rankSDS; i++)
3391 : {
3392 0 : incr[i] = stride[i];
3393 : }
3394 : }
3395 : else
3396 : {
3397 : /*
3398 : * If field really 2-dim merged in 3-dim field then set
3399 : * 0th field stride to 1 and then next two to the user
3400 : * values.
3401 : */
3402 0 : for (i = 0; i < rankFld; i++)
3403 : {
3404 0 : incr[i + 1] = stride[i];
3405 : }
3406 0 : incr[0] = 1;
3407 : }
3408 : }
3409 :
3410 :
3411 :
3412 : /* Set I/O count Section */
3413 : /* --------------------- */
3414 :
3415 : /*
3416 : * If edge == NULL (default) set I/O count to number of remaining
3417 : * entries (dims - start) / increment. Note that 0th field
3418 : * offset corrected for merged field offset (if any).
3419 : */
3420 0 : if (edge == NULL)
3421 : {
3422 0 : for (i = 1; i < rankSDS; i++)
3423 : {
3424 0 : count[i] = (dims[i] - offset[i]) / incr[i];
3425 : }
3426 0 : count[0] = (dims[0] - (offset[0] - mrgOffset)) / incr[0];
3427 : }
3428 : else
3429 : {
3430 : /*
3431 : * ... otherwise set I/O count to user values
3432 : */
3433 0 : if (rankFld == rankSDS)
3434 : {
3435 0 : for (i = 0; i < rankSDS; i++)
3436 : {
3437 0 : count[i] = edge[i];
3438 : }
3439 : }
3440 : else
3441 : {
3442 : /*
3443 : * If field really 2-dim merged in 3-dim field then set
3444 : * 0th field count to 1 and then next two to the user
3445 : * values.
3446 : */
3447 0 : for (i = 0; i < rankFld; i++)
3448 : {
3449 0 : count[i + 1] = edge[i];
3450 : }
3451 0 : count[0] = 1;
3452 : }
3453 : }
3454 :
3455 : /* Perform I/O with relevant HDF I/O routine */
3456 : /* ----------------------------------------- */
3457 0 : if (strcmp(code, "w") == 0)
3458 : {
3459 : /* Set strideOne to true (1) */
3460 : /* ------------------------- */
3461 0 : strideOne = 1;
3462 :
3463 :
3464 : /* If incr[i] != 1 set strideOne to false (0) */
3465 : /* ------------------------------------------ */
3466 0 : for (i = 0; i < rankSDS; i++)
3467 : {
3468 0 : if (incr[i] != 1)
3469 : {
3470 0 : strideOne = 0;
3471 0 : break;
3472 : }
3473 : }
3474 :
3475 :
3476 : /*
3477 : * If strideOne is true use NULL parameter for stride. This
3478 : * is a work-around to HDF compression problem
3479 : */
3480 0 : if (strideOne == 1)
3481 : {
3482 0 : status = SDwritedata(sdid, offset, NULL, count,
3483 : (VOIDP) datbuf);
3484 : }
3485 : else
3486 : {
3487 0 : status = SDwritedata(sdid, offset, incr, count,
3488 : (VOIDP) datbuf);
3489 : }
3490 : }
3491 : else
3492 : {
3493 0 : status = SDreaddata(sdid, offset, incr, count,
3494 : (VOIDP) datbuf);
3495 : }
3496 : } /* End of Multi-Dimensional Field Section */
3497 : else
3498 : {
3499 :
3500 : /* One-Dimensional Field Section */
3501 : /* ----------------------------- */
3502 :
3503 : /* Check fieldname within 1d field Vgroups */
3504 : /* --------------------------------------- */
3505 0 : status = SW1dfldsrch(fid, swathID, fieldname, code,
3506 : &vgid, &vdataID, &dum);
3507 :
3508 0 : if (status != -1)
3509 : {
3510 :
3511 : /* Get number of records */
3512 : /* --------------------- */
3513 0 : nrec = VSelts(vdataID);
3514 :
3515 :
3516 : /* Set offset, increment, & count */
3517 : /* ------------------------------ */
3518 0 : offset[0] = (start == NULL) ? 0 : start[0];
3519 0 : incr[0] = (stride == NULL) ? 1 : stride[0];
3520 0 : count[0] = (edge == NULL)
3521 0 : ? (nrec - offset[0]) / incr[0]
3522 0 : : edge[0];
3523 :
3524 :
3525 :
3526 : /* Write Section */
3527 : /* ------------- */
3528 0 : if (strcmp(code, "w") == 0)
3529 : {
3530 : /* Get size of field and setup fill buffer */
3531 : /* --------------------------------------- */
3532 0 : fldsize = VSsizeof(vdataID, (char *)fieldname);
3533 0 : fillbuf = (uint8 *) calloc(fldsize, 1);
3534 0 : if(fillbuf == NULL)
3535 : {
3536 0 : HEpush(DFE_NOSPACE,"SWwrrdfield", __FILE__, __LINE__);
3537 0 : return(-1);
3538 : }
3539 :
3540 : /* Get size of record in Vdata and setup I/O buffer */
3541 : /* ------------------------------------------------ */
3542 0 : VSQueryvsize(vdataID, &recsize);
3543 0 : buf = (uint8 *) calloc(recsize, count[0] * incr[0]);
3544 0 : if(buf == NULL)
3545 : {
3546 0 : HEpush(DFE_NOSPACE,"SWwrrdfield", __FILE__, __LINE__);
3547 0 : free(fillbuf);
3548 0 : return(-1);
3549 : }
3550 :
3551 :
3552 : /* Get names and number of fields in each record */
3553 : /* ---------------------------------------------- */
3554 0 : VSgetfields(vdataID, fieldlist);
3555 0 : dum = EHstrwithin(fieldname, fieldlist, ',');
3556 0 : nflds = EHparsestr(fieldlist, ',', ptr, CPL_ARRAYSIZE(ptr), NULL, 0);
3557 :
3558 :
3559 : /* Get Merged Field Offset (if any) */
3560 : /* -------------------------------- */
3561 0 : if (nflds > 1)
3562 : {
3563 0 : if (dum > 0)
3564 : {
3565 0 : *(ptr[dum] - 1) = 0;
3566 0 : mrgOffset = VSsizeof(vdataID, fieldlist);
3567 0 : *(ptr[dum] - 1) = ',';
3568 : }
3569 : else
3570 : {
3571 0 : mrgOffset = 0;
3572 : }
3573 :
3574 : /* Read records to recover previously written data */
3575 0 : /* status = */ VSsetfields(vdataID, fieldlist);
3576 0 : /* status = */ VSseek(vdataID, offset[0]);
3577 0 : nrec = VSread(vdataID, buf, count[0] * incr[0],
3578 : FULL_INTERLACE);
3579 : }
3580 : else
3581 : {
3582 0 : mrgOffset = 0;
3583 : }
3584 :
3585 :
3586 :
3587 : /* Fill buffer with "Fill" value (if any) */
3588 : /* -------------------------------------- */
3589 0 : snprintf( attrName, sizeof(attrName), "_FV_%s", fieldname);
3590 :
3591 0 : status = SWreadattr(swathID, attrName, (char *) fillbuf);
3592 0 : if (status == 0)
3593 : {
3594 0 : for (i = 0; i < count[0] * incr[0]; i++)
3595 : {
3596 0 : memcpy(buf + i * recsize + mrgOffset,
3597 : fillbuf, fldsize);
3598 : }
3599 : }
3600 :
3601 :
3602 : /* Write new data into buffer */
3603 : /* -------------------------- */
3604 0 : if (incr[0] == 1 && nflds == 1)
3605 : {
3606 0 : memcpy(buf, datbuf, count[0] * recsize);
3607 : }
3608 : else
3609 : {
3610 0 : for (i = 0; i < count[0]; i++)
3611 : {
3612 0 : memcpy(buf + i * recsize * incr[0] + mrgOffset,
3613 0 : (uint8 *) datbuf + i * fldsize, fldsize);
3614 : }
3615 : }
3616 :
3617 :
3618 : /* If append read last record */
3619 : /* -------------------------- */
3620 0 : if (offset[0] == nrec)
3621 : {
3622 : /* abe added "status =" to next line 8/8/97 */
3623 0 : status = VSseek(vdataID, offset[0] - 1);
3624 0 : VSread(vdataID, fillbuf, 1, FULL_INTERLACE);
3625 : }
3626 : else
3627 : {
3628 0 : status = VSseek(vdataID, offset[0]);
3629 : }
3630 :
3631 :
3632 : /* Write data into Vdata */
3633 : /* --------------------- */
3634 0 : nrec = VSwrite(vdataID, buf, count[0] * incr[0],
3635 : FULL_INTERLACE);
3636 : (void)nrec; // FIXME
3637 :
3638 0 : free(fillbuf);
3639 0 : if (status > 0)
3640 0 : status = 0;
3641 :
3642 : } /* End Write Section */
3643 : else
3644 : {
3645 : /* Read Section */
3646 : /* ------------ */
3647 0 : status = VSsetfields(vdataID, fieldname);
3648 0 : fldsize = VSsizeof(vdataID, (char *)fieldname);
3649 0 : buf = (uint8 *) calloc(fldsize, count[0] * incr[0]);
3650 0 : if(buf == NULL)
3651 : {
3652 0 : HEpush(DFE_NOSPACE,"SWwrrdfield", __FILE__, __LINE__);
3653 0 : return(-1);
3654 : }
3655 :
3656 0 : (void) VSseek(vdataID, offset[0]);
3657 0 : (void) VSread(vdataID, buf, count[0] * incr[0],
3658 : FULL_INTERLACE);
3659 :
3660 :
3661 : /* Copy from input buffer to returned data buffer */
3662 : /* ---------------------------------------------- */
3663 0 : if (incr[0] == 1)
3664 : {
3665 0 : memcpy(datbuf, buf, count[0] * fldsize);
3666 : }
3667 : else
3668 : {
3669 0 : for (i = 0; i < count[0]; i++)
3670 : {
3671 0 : memcpy((uint8 *) datbuf + i * fldsize,
3672 0 : buf + i * fldsize * incr[0], fldsize);
3673 : }
3674 : }
3675 :
3676 : } /* End Read Section */
3677 :
3678 0 : free(buf);
3679 0 : VSdetach(vdataID);
3680 : }
3681 : else
3682 : {
3683 0 : HEpush(DFE_GENAPP, "SWwrrdfield", __FILE__, __LINE__);
3684 0 : HEreport("Fieldname \"%s\" does not exist.\n", fieldname);
3685 : }
3686 : } /* End One-D Field Section */
3687 :
3688 : }
3689 0 : return (status);
3690 : }
3691 :
3692 :
3693 :
3694 : /*----------------------------------------------------------------------------|
3695 : | BEGIN_PROLOG |
3696 : | |
3697 : | FUNCTION: SWreadfield |
3698 : | |
3699 : | DESCRIPTION: Reads data from field |
3700 : | |
3701 : | Return Value Type Units Description |
3702 : | ============ ====== ========= ===================================== |
3703 : | status intn return status (0) SUCCEED, (-1) FAIL |
3704 : | |
3705 : | INPUTS: |
3706 : | swathID int32 swath structure ID |
3707 : | fieldname const char fieldname |
3708 : | start int32 start array |
3709 : | stride int32 stride array |
3710 : | edge int32 edge array |
3711 : | buffer void data buffer for read |
3712 : | |
3713 : | |
3714 : | OUTPUTS: |
3715 : | None |
3716 : | |
3717 : | NOTES: |
3718 : | |
3719 : | |
3720 : | Date Programmer Description |
3721 : | ====== ============ ================================================= |
3722 : | Jun 96 Joel Gales Original Programmer |
3723 : | |
3724 : | END_PROLOG |
3725 : -----------------------------------------------------------------------------*/
3726 : intn
3727 0 : SWreadfield(int32 swathID, const char *fieldname,
3728 : int32 start[], int32 stride[], int32 edge[], VOIDP buffer)
3729 :
3730 : {
3731 0 : intn status = 0; /* routine return status variable */
3732 :
3733 0 : status = SWwrrdfield(swathID, fieldname, "r", start, stride, edge,
3734 : buffer);
3735 0 : return (status);
3736 : }
3737 :
3738 : /*----------------------------------------------------------------------------|
3739 : | BEGIN_PROLOG |
3740 : | |
3741 : | FUNCTION: SWgetfillvalue |
3742 : | |
3743 : | DESCRIPTION: Retrieves fill value for a specified field. |
3744 : | |
3745 : | |
3746 : | Return Value Type Units Description |
3747 : | ============ ====== ========= ===================================== |
3748 : | status intn return status (0) SUCCEED, (-1) FAIL |
3749 : | |
3750 : | INPUTS: |
3751 : | swathID int32 swath structure ID |
3752 : | fieldname char field name |
3753 : | |
3754 : | OUTPUTS: |
3755 : | fillval void fill value |
3756 : | |
3757 : | NOTES: |
3758 : | |
3759 : | |
3760 : | Date Programmer Description |
3761 : | ====== ============ ================================================= |
3762 : | Jun 96 Joel Gales Original Programmer |
3763 : | |
3764 : | END_PROLOG |
3765 : -----------------------------------------------------------------------------*/
3766 : intn
3767 0 : SWgetfillvalue(int32 swathID, const char *fieldname, VOIDP fillval)
3768 : {
3769 : intn status; /* routine return status variable */
3770 :
3771 : int32 nt; /* Number type */
3772 : int32 dims[8]; /* Dimensions array */
3773 : int32 dum; /* Dummy variable */
3774 :
3775 : char name[80]; /* Fill value "attribute" name */
3776 :
3777 : /* Check for valid swath ID */
3778 0 : status = SWchkswid(swathID, "SWgetfillvalue", &dum, &dum, &dum);
3779 :
3780 0 : if (status == 0)
3781 : {
3782 : /* Get field info */
3783 0 : status = SWfieldinfo(swathID, fieldname, &dum, dims, &nt, NULL, 0);
3784 :
3785 0 : if (status == 0)
3786 : {
3787 : /* Read fill value attribute */
3788 0 : strcpy(name, "_FV_");
3789 0 : strcat(name, fieldname);
3790 0 : status = SWreadattr(swathID, name, fillval);
3791 : }
3792 : else
3793 : {
3794 0 : HEpush(DFE_GENAPP, "SWgetfillvalue", __FILE__, __LINE__);
3795 0 : HEreport("Fieldname \"%s\" does not exist.\n", fieldname);
3796 : }
3797 :
3798 : }
3799 0 : return (status);
3800 : }
3801 :
3802 :
3803 : /*----------------------------------------------------------------------------|
3804 : | BEGIN_PROLOG |
3805 : | |
3806 : | FUNCTION: SWdetach |
3807 : | |
3808 : | DESCRIPTION: Detaches swath structure and performs housekeeping |
3809 : | |
3810 : | |
3811 : | Return Value Type Units Description |
3812 : | ============ ====== ========= ===================================== |
3813 : | status intn return status (0) SUCCEED, (-1) FAIL |
3814 : | |
3815 : | INPUTS: |
3816 : | swathID int32 swath structure ID |
3817 : | |
3818 : | |
3819 : | OUTPUTS: |
3820 : | None |
3821 : | |
3822 : | NOTES: |
3823 : | |
3824 : | |
3825 : | Date Programmer Description |
3826 : | ====== ============ ================================================= |
3827 : | Jun 96 Joel Gales Original Programmer |
3828 : | Aug 96 Joel Gales Cleanup Region External Structure |
3829 : | Sep 96 Joel Gales Setup dim names for SDsetdimnane in dimbuf1 rather |
3830 : | than utlstr |
3831 : | Nov 96 Joel Gales Call SWchkgdid to check for proper swath ID |
3832 : | Dec 96 Joel Gales Add multiple vertical subsetting garbage collection |
3833 : | |
3834 : | END_PROLOG |
3835 : -----------------------------------------------------------------------------*/
3836 : intn
3837 6 : SWdetach(int32 swathID)
3838 :
3839 : {
3840 : intn i; /* Loop index */
3841 : intn k; /* Loop index */
3842 6 : intn status = 0; /* routine return status variable */
3843 :
3844 : uint8 *buf; /* Buffer for blank (initial) 1D records */
3845 :
3846 : int32 vdataID; /* Vdata ID */
3847 : int32 dims[3]; /* Dimension array */
3848 : int32 sdInterfaceID; /* SDS interface ID */
3849 : int32 sID; /* Swath ID - offset */
3850 6 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
3851 : int32 dum; /* Dummy variable */
3852 :
3853 : char swathname[VGNAMELENMAX + 1]; /* Swath name */
3854 :
3855 : /* Check for proper swath ID and get SD interface ID */
3856 : /* ------------------------------------------------- */
3857 6 : status = SWchkswid(swathID, "SWdetach", &dum, &sdInterfaceID, &dum);
3858 :
3859 6 : if (status == 0)
3860 : {
3861 : /* Subtract off swath ID offset and get swath name */
3862 : /* ----------------------------------------------- */
3863 6 : sID = swathID % idOffset;
3864 6 : if (sID >= NSWATH)
3865 : {
3866 0 : return -1;
3867 : }
3868 6 : VgetnameSafe(SWXSwath[sID].IDTable, swathname, sizeof(swathname));
3869 :
3870 :
3871 : /* Create 1D "orphaned" fields */
3872 : /* --------------------------- */
3873 6 : i = 0;
3874 :
3875 : /* Find "active" entries in 1d combination array */
3876 : /* --------------------------------------------- */
3877 6 : while (SWX1dcomb[3 * i] != 0)
3878 : {
3879 : /* For fields defined within swath... */
3880 : /* ---------------------------------- */
3881 0 : if (SWX1dcomb[3 * i + 1] == SWXSwath[sID].IDTable)
3882 : {
3883 : /* Get dimension size and vdata ID */
3884 : /* ------------------------------- */
3885 0 : dims[0] = abs(SWX1dcomb[3 * i]);
3886 0 : vdataID = SWX1dcomb[3 * i + 2];
3887 :
3888 : /* Get fieldname (= vdata name) */
3889 : /* ---------------------------- */
3890 0 : char* nambuf = (char *) calloc(VSNAMELENMAX + 1, 1);
3891 0 : if(nambuf == NULL)
3892 : {
3893 0 : HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__);
3894 0 : return(-1);
3895 : }
3896 :
3897 0 : VSgetname(vdataID, nambuf);
3898 :
3899 : /* Set field within vdata */
3900 : /* ---------------------- */
3901 0 : VSsetfields(vdataID, nambuf);
3902 :
3903 : /* Write (blank) records */
3904 : /* --------------------- */
3905 0 : buf = (uint8 *) calloc(VSsizeof(vdataID, nambuf), dims[0]);
3906 0 : if(buf == NULL)
3907 : {
3908 0 : HEpush(DFE_NOSPACE,"SWdetach", __FILE__, __LINE__);
3909 0 : free(nambuf);
3910 0 : return(-1);
3911 : }
3912 0 : VSwrite(vdataID, buf, dims[0], FULL_INTERLACE);
3913 :
3914 0 : free(buf);
3915 0 : free(nambuf);
3916 :
3917 : /* Detach Vdata */
3918 : /* ------------ */
3919 0 : VSdetach(vdataID);
3920 : }
3921 0 : i++;
3922 : }
3923 :
3924 : /* "Contract" 1dcomb array */
3925 : /* ----------------------- */
3926 6 : i = 0;
3927 6 : while (SWX1dcomb[3 * i] != 0)
3928 : {
3929 0 : if (SWX1dcomb[3 * i + 1] == SWXSwath[sID].IDTable)
3930 : {
3931 0 : memmove(&SWX1dcomb[3 * i],
3932 0 : &SWX1dcomb[3 * (i + 1)],
3933 0 : (512 - i - 1) * 3 * 4);
3934 : }
3935 : else
3936 0 : i++;
3937 : }
3938 :
3939 : /* "Detach" from previously attached SDSs */
3940 : /* -------------------------------------- */
3941 8 : for (k = 0; k < SWXSwath[sID].nSDS; k++)
3942 : {
3943 2 : SDendaccess(SWXSwath[sID].sdsID[k]);
3944 : }
3945 6 : free(SWXSwath[sID].sdsID);
3946 6 : SWXSwath[sID].sdsID = 0;
3947 6 : SWXSwath[sID].nSDS = 0;
3948 :
3949 :
3950 : /* Detach Swath Vgroups */
3951 : /* -------------------- */
3952 6 : Vdetach(SWXSwath[sID].VIDTable[0]);
3953 6 : Vdetach(SWXSwath[sID].VIDTable[1]);
3954 6 : Vdetach(SWXSwath[sID].VIDTable[2]);
3955 6 : Vdetach(SWXSwath[sID].IDTable);
3956 :
3957 :
3958 : /* Delete entries from External Arrays */
3959 : /* ----------------------------------- */
3960 6 : SWXSwath[sID].active = 0;
3961 6 : SWXSwath[sID].VIDTable[0] = 0;
3962 6 : SWXSwath[sID].VIDTable[1] = 0;
3963 6 : SWXSwath[sID].VIDTable[2] = 0;
3964 6 : SWXSwath[sID].IDTable = 0;
3965 6 : SWXSwath[sID].fid = 0;
3966 :
3967 :
3968 : /* Free Region Pointers */
3969 : /* -------------------- */
3970 1542 : for (k = 0; k < NSWATHREGN; k++)
3971 : {
3972 1536 : if (SWXRegion[k] != 0 &&
3973 0 : SWXRegion[k]->swathID == swathID)
3974 : {
3975 0 : for (i = 0; i < 8; i++)
3976 : {
3977 0 : if (SWXRegion[k]->DimNamePtr[i] != 0)
3978 : {
3979 0 : free(SWXRegion[k]->DimNamePtr[i]);
3980 : }
3981 : }
3982 :
3983 0 : free(SWXRegion[k]);
3984 0 : SWXRegion[k] = 0;
3985 : }
3986 : }
3987 :
3988 : }
3989 6 : return (status);
3990 : }
3991 :
3992 : /*----------------------------------------------------------------------------|
3993 : | BEGIN_PROLOG |
3994 : | |
3995 : | FUNCTION: SWclose |
3996 : | |
3997 : | DESCRIPTION: Closes HDF-EOS file |
3998 : | |
3999 : | |
4000 : | Return Value Type Units Description |
4001 : | ============ ====== ========= ===================================== |
4002 : | status intn return status (0) SUCCEED, (-1) FAIL |
4003 : | |
4004 : | INPUTS: |
4005 : | fid int32 File ID |
4006 : | |
4007 : | OUTPUTS: |
4008 : | None |
4009 : | |
4010 : | NOTES: |
4011 : | |
4012 : | |
4013 : | Date Programmer Description |
4014 : | ====== ============ ================================================= |
4015 : | Jun 96 Joel Gales Original Programmer |
4016 : | |
4017 : | END_PROLOG |
4018 : -----------------------------------------------------------------------------*/
4019 : intn
4020 20 : SWclose(int32 fid)
4021 :
4022 : {
4023 20 : intn status = 0; /* routine return status variable */
4024 :
4025 : /* Call EHclose to perform file close */
4026 : /* ---------------------------------- */
4027 20 : status = EHclose(fid);
4028 :
4029 20 : return (status);
4030 : }
4031 :
4032 : /*----------------------------------------------------------------------------|
4033 : | BEGIN_PROLOG |
4034 : | |
4035 : | FUNCTION: SWgeomapinfo |
4036 : | |
4037 : | DESCRIPTION: Returns mapping information for dimension |
4038 : | |
4039 : | |
4040 : | Return Value Type Units Description |
4041 : | ============ ====== ========= ===================================== |
4042 : | status intn 2 for l_indexed mapping, 1 for regular |
4043 : | mapping, 0 if the dimension is not |
4044 : | and (-1) FAIL |
4045 : | |
4046 : | INPUTS: |
4047 : | swathID int32 swath structure id |
4048 : | geodim char geolocation dimension name |
4049 : | |
4050 : | OUTPUTS: |
4051 : | |
4052 : | NONE |
4053 : | |
4054 : | NOTES: |
4055 : | |
4056 : | |
4057 : | Date Programmer Description |
4058 : | ====== ============ ================================================= |
4059 : | Aug 97 Abe Taaheri Original Programmer |
4060 : | Sept 97 DaW Modified return value so errors can be trapped |
4061 : | |
4062 : | END_PROLOG |
4063 : -----------------------------------------------------------------------------*/
4064 : intn
4065 0 : SWgeomapinfo(int32 swathID, const char *geodim)
4066 :
4067 : {
4068 : intn status; /* routine return status variable */
4069 :
4070 : int32 fid; /* HDF-EOS file ID */
4071 : int32 sdInterfaceID; /* HDF SDS interface ID */
4072 : int32 swVgrpID; /* Swath root Vgroup ID */
4073 0 : int32 idOffset = SWIDOFFSET; /* Swath ID offset */
4074 :
4075 : char *metabufr; /* Pointer to structural metadata (SM) */
4076 : char *metabufi; /* Pointer to structural metadata (SM) */
4077 : char *metaptrsr[2];/* Pointers to begin and end of SM section */
4078 : char *metaptrsi[2];/* Pointers to begin and end of SM section */
4079 : char swathname[80]; /* Swath Name */
4080 : char *utlstrr; /* Utility string */
4081 : char *utlstri; /* Utility string */
4082 :
4083 :
4084 : /* Allocate space for utility string */
4085 : /* --------------------------------- */
4086 0 : utlstrr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
4087 0 : if(utlstrr == NULL)
4088 : {
4089 0 : HEpush(DFE_NOSPACE,"SWgeomapinfo", __FILE__, __LINE__);
4090 0 : return(-1);
4091 : }
4092 0 : utlstri = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char));
4093 0 : if(utlstri == NULL)
4094 : {
4095 0 : HEpush(DFE_NOSPACE,"SWgeomapinfo", __FILE__, __LINE__);
4096 0 : free(utlstrr);
4097 0 : return(-1);
4098 : }
4099 :
4100 : /* Check for valid swath id */
4101 0 : status = SWchkswid(swathID, "SWgeomapinfo", &fid, &sdInterfaceID, &swVgrpID);
4102 0 : if (status == 0)
4103 : {
4104 : /* Get swath name */
4105 0 : int sID = swathID % idOffset;
4106 0 : if (sID >= NSWATH)
4107 : {
4108 0 : free(utlstrr);
4109 0 : free(utlstri);
4110 0 : return -1;
4111 : }
4112 0 : VgetnameSafe(SWXSwath[sID].IDTable, swathname, sizeof(swathname));
4113 :
4114 : /* Get pointers to "DimensionMap" section within SM */
4115 0 : metabufr = EHmetagroup(sdInterfaceID, swathname, "s",
4116 : "DimensionMap", metaptrsr);
4117 :
4118 0 : if(metabufr == NULL)
4119 : {
4120 0 : free(utlstrr);
4121 0 : free(utlstri);
4122 0 : return(-1);
4123 : }
4124 : /* Search for mapping - GeoDim/DataDim (surrounded by quotes) */
4125 0 : snprintf(utlstrr, UTLSTR_MAX_SIZE, "%s%s%s", "\t\t\t\tGeoDimension=\"", geodim,
4126 : "\"\n\t\t\t\tDataDimension=");
4127 0 : metaptrsr[0] = strstr(metaptrsr[0], utlstrr);
4128 :
4129 : /* Get pointers to "IndexDimensionMap" section within SM */
4130 0 : metabufi = EHmetagroup(sdInterfaceID, swathname, "s",
4131 : "IndexDimensionMap", metaptrsi);
4132 0 : if(metabufi == NULL)
4133 : {
4134 0 : free(utlstrr);
4135 0 : free(utlstri);
4136 0 : return(-1);
4137 : }
4138 : /* Search for mapping - GeoDim/DataDim (surrounded by quotes) */
4139 0 : snprintf(utlstri, UTLSTR_MAX_SIZE, "%s%s%s", "\t\t\t\tGeoDimension=\"", geodim,
4140 : "\"\n\t\t\t\tDataDimension=");
4141 0 : metaptrsi[0] = strstr(metaptrsi[0], utlstri);
4142 :
4143 : /*
4144 : ** If regular mapping found add 1 to status
4145 : ** If l_indexed mapping found add 2
4146 : */
4147 0 : if (metaptrsr[0] < metaptrsr[1] && metaptrsr[0] != NULL)
4148 : {
4149 0 : status = status + 1;
4150 : }
4151 :
4152 0 : if (metaptrsi[0] < metaptrsi[1] && metaptrsi[0] != NULL)
4153 : {
4154 0 : status = status + 2;
4155 : }
4156 :
4157 0 : free(metabufr);
4158 0 : free(metabufi);
4159 : }
4160 :
4161 0 : free(utlstrr);
4162 0 : free(utlstri);
4163 :
4164 0 : return (status);
4165 : }
4166 :
4167 : /*----------------------------------------------------------------------------|
4168 : | BEGIN_PROLOG |
4169 : | |
4170 : | FUNCTION: SWsdid |
4171 : | |
4172 : | DESCRIPTION: Returns SD element ID for swath field |
4173 : | |
4174 : | |
4175 : | Return Value Type Units Description |
4176 : | ============ ====== ========= ===================================== |
4177 : | status intn return status (0) SUCCEED, (-1) FAIL |
4178 : | |
4179 : | INPUTS: |
4180 : | swathID int32 swath structure ID |
4181 : | fieldname const char field name |
4182 : | |
4183 : | |
4184 : | OUTPUTS: |
4185 : | sdid int32 SD element ID |
4186 : | |
4187 : | NOTES: |
4188 : | |
4189 : | |
4190 : | Date Programmer Description |
4191 : | ====== ============ ================================================= |
4192 : | Oct 07 Andrey Kiselev Original Programmer |
4193 : | |
4194 : | END_PROLOG |
4195 : -----------------------------------------------------------------------------*/
4196 : intn
4197 0 : SWsdid(int32 swathID, const char *fieldname, int32 *sdid)
4198 : {
4199 : intn status; /* routine return status variable */
4200 : int32 fid; /* HDF-EOS file ID */
4201 : int32 sdInterfaceID; /* HDF SDS interface ID */
4202 : int32 dum; /* Dummy variable */
4203 : int32 dims[H4_MAX_VAR_DIMS]; /* Field/SDS dimensions */
4204 :
4205 0 : status = SWchkswid(swathID, "SWsdid", &fid, &sdInterfaceID, &dum);
4206 0 : if (status != -1)
4207 : {
4208 0 : status = SWSDfldsrch(swathID, sdInterfaceID, fieldname,
4209 : sdid, &dum, &dum, &dum, dims, &dum);
4210 : }
4211 :
4212 0 : return (status);
4213 : }
|