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