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