📄 swapi.c
字号:
Vsetname(vgid[0], swathname); Vsetclass(vgid[0], "SWATH"); /* Create Geolocation Fields Vgroup */ /* -------------------------------- */ vgid[1] = Vattach(HDFfid, -1, "w"); Vsetname(vgid[1], "Geolocation Fields"); Vsetclass(vgid[1], "SWATH Vgroup"); Vinsert(vgid[0], vgid[1]); /* Create Data Fields Vgroup */ /* ------------------------- */ vgid[2] = Vattach(HDFfid, -1, "w"); Vsetname(vgid[2], "Data Fields"); Vsetclass(vgid[2], "SWATH Vgroup"); Vinsert(vgid[0], vgid[2]); /* Create Attributes Vgroup */ /* ------------------------ */ vgid[3] = Vattach(HDFfid, -1, "w"); Vsetname(vgid[3], "Swath Attributes"); Vsetclass(vgid[3], "SWATH Vgroup"); Vinsert(vgid[0], vgid[3]); /* Establish Swath in Structural MetaData Block */ /* -------------------------------------------- */ sprintf(utlbuf, "%s%d%s%s%s", "\tGROUP=SWATH_", nSwath + 1, "\n\t\tSwathName=\"", swathname, "\"\n"); strcat(utlbuf, "\t\tGROUP=Dimension\n"); strcat(utlbuf, "\t\tEND_GROUP=Dimension\n"); strcat(utlbuf, "\t\tGROUP=DimensionMap\n"); strcat(utlbuf, "\t\tEND_GROUP=DimensionMap\n"); strcat(utlbuf, "\t\tGROUP=IndexDimensionMap\n"); strcat(utlbuf, "\t\tEND_GROUP=IndexDimensionMap\n"); strcat(utlbuf, "\t\tGROUP=GeoField\n"); strcat(utlbuf, "\t\tEND_GROUP=GeoField\n"); strcat(utlbuf, "\t\tGROUP=DataField\n"); strcat(utlbuf, "\t\tEND_GROUP=DataField\n"); strcat(utlbuf, "\t\tGROUP=MergedFields\n"); strcat(utlbuf, "\t\tEND_GROUP=MergedFields\n"); sprintf(utlbuf2, "%s%d%s", "\tEND_GROUP=SWATH_", nSwath + 1, "\n"); strcat(utlbuf, utlbuf2); status = EHinsertmeta(sdInterfaceID, "", "s", 1001L, utlbuf, NULL); } } else { /* Too many files opened */ /* --------------------- */ status = -1; strcpy(errbuf, "No more than %d swaths may be open simutaneously"); strcat(errbuf, " (%s)"); HEpush(DFE_DENIED, "SWcreate", __FILE__, __LINE__); HEreport(errbuf, NSWATH, swathname); } /* Assign swathID # & Load swath and SWXSwath table entries */ /* -------------------------------------------------------- */ if (status == 0) { for (i = 0; i < NSWATH; i++) { if (SWXSwath[i].active == 0) { /* * Set swathID, Set swath entry active, Store root Vgroup * ID, Store sub Vgroup IDs, Store HDF-EOS file ID */ swathID = i + idOffset; SWXSwath[i].active = 1; SWXSwath[i].IDTable = vgid[0]; SWXSwath[i].VIDTable[0] = vgid[1]; SWXSwath[i].VIDTable[1] = vgid[2]; SWXSwath[i].VIDTable[2] = vgid[3]; SWXSwath[i].fid = fid; status = 0; break; } } } } return (swathID);}/*----------------------------------------------------------------------------|| BEGIN_PROLOG || || FUNCTION: SWattach || || DESCRIPTION: Attaches to an existing swath within the file. || || || Return Value Type Units Description || ============ ====== ========= ===================================== || swathID int32 swath structure ID || || INPUTS: || fid int32 HDF-EOS file ID || swathname char swath structure name || || OUTPUTS: || None || || NOTES: || || || Date Programmer Description || ====== ============ ================================================= || Jun 96 Joel Gales Original Programmer || Apr 99 David Wynne Modified test for memory allocation check when no || SDSs are in the Swath, NCR22513 || || END_PROLOG |-----------------------------------------------------------------------------*/int32SWattach(int32 fid, char *swathname){ intn i; /* Loop index */ intn j; /* Loop index */ intn nswathopen = 0; /* # of swath structures open */ intn status; /* routine return status variable */ uint8 acs; /* Read/Write file access code */ int32 HDFfid; /* HDF file id */ int32 vgRef; /* Vgroup reference number */ int32 vgid[4]; /* Vgroup ID array */ int32 swathID = -1; /* HDF-EOS swath ID */ int32 *tags; /* Pnt to Vgroup object tags array */ int32 *refs; /* Pnt to Vgroup object refs array */ int32 dum; /* dummy varible */ int32 sdInterfaceID; /* HDF SDS interface ID */ int32 nObjects; /* # of objects in Vgroup */ int32 nSDS; /* SDS counter */ int32 index; /* SDS index */ int32 sdid; /* SDS object ID */ int32 idOffset = SWIDOFFSET; /* Swath ID offset */ char name[80]; /* Vgroup name */ char class[80]; /* Vgroup class */ char errbuf[256];/* Buffer for error message */ char acsCode[1]; /* Read/Write access char: "r/w" */ /* Check HDF-EOS file ID, get back HDF file ID and access code */ /* ----------------------------------------------------------- */ status = EHchkfid(fid, swathname, &HDFfid, &dum, &acs); if (status == 0) { /* Convert numeric access code to character */ /* ---------------------------------------- */ acsCode[0] = (acs == 1) ? 'w' : 'r'; /* Determine number of swaths currently opened */ /* ------------------------------------------- */ for (i = 0; i < NSWATH; i++) { nswathopen += SWXSwath[i].active; } /* If room for more ... */ /* -------------------- */ if (nswathopen < NSWATH) { /* Search Vgroups for Swath */ /* ------------------------ */ vgRef = -1; while (1) { vgRef = Vgetid(HDFfid, vgRef); /* If no more Vgroups then exist while loop */ /* ---------------------------------------- */ if (vgRef == -1) { break; } /* Get name and class of Vgroup */ /* ---------------------------- */ vgid[0] = Vattach(HDFfid, vgRef, "r"); Vgetname(vgid[0], name); Vgetclass(vgid[0], class); /* * If Vgroup with swathname and class SWATH found, load * tables */ if (strcmp(name, swathname) == 0 && strcmp(class, "SWATH") == 0) { /* Attach to "Fields" and "Swath Attributes" Vgroups */ /* ------------------------------------------------- */ tags = (int32 *) malloc(sizeof(int32) * 3); if(tags == NULL) { HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__); return(-1); } refs = (int32 *) malloc(sizeof(int32) * 3); if(refs == NULL) { HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__); free(tags); return(-1); } Vgettagrefs(vgid[0], tags, refs, 3); vgid[1] = Vattach(HDFfid, refs[0], acsCode); vgid[2] = Vattach(HDFfid, refs[1], acsCode); vgid[3] = Vattach(HDFfid, refs[2], acsCode); free(tags); free(refs); /* Setup External Arrays */ /* --------------------- */ for (i = 0; i < NSWATH; i++) { /* Find empty entry in array */ /* ------------------------- */ if (SWXSwath[i].active == 0) { /* * Set swathID, Set swath entry active, Store * root Vgroup ID, Store sub Vgroup IDs, Store * HDF-EOS file ID */ swathID = i + idOffset; SWXSwath[i].active = 1; SWXSwath[i].IDTable = vgid[0]; SWXSwath[i].VIDTable[0] = vgid[1]; SWXSwath[i].VIDTable[1] = vgid[2]; SWXSwath[i].VIDTable[2] = vgid[3]; SWXSwath[i].fid = fid; break; } } /* Get SDS interface ID */ /* -------------------- */ status = SWchkswid(swathID, "SWattach", &dum, &sdInterfaceID, &dum); /* Access swath "Geolocation" SDS */ /* ------------------------------ */ /* Get # of entries within this Vgroup & search for SDS */ /* ---------------------------------------------------- */ nObjects = Vntagrefs(vgid[1]); if (nObjects > 0) { /* Get tag and ref # for Geolocation Vgroup objects */ /* ------------------------------------------------ */ tags = (int32 *) malloc(sizeof(int32) * nObjects); if(tags == NULL) { HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__); return(-1); } refs = (int32 *) malloc(sizeof(int32) * nObjects); if(refs == NULL) { HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__); free(tags); return(-1); } Vgettagrefs(vgid[1], tags, refs, nObjects); /* Count number of SDS & allocate SDS ID array */ /* ------------------------------------------- */ nSDS = 0; for (j = 0; j < nObjects; j++) { if (tags[j] == DFTAG_NDG) { nSDS++; } } SWXSwath[i].sdsID = (int32 *) calloc(nSDS, 4); if(SWXSwath[i].sdsID == NULL && nSDS != 0) { HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__); free(tags); free(refs); return(-1); } nSDS = 0; /* Fill SDS ID array */ /* ----------------- */ for (j = 0; j < nObjects; j++) { /* If object is SDS then get id */ /* ---------------------------- */ if (tags[j] == DFTAG_NDG) { index = SDreftoindex(sdInterfaceID, refs[j]); sdid = SDselect(sdInterfaceID, index); SWXSwath[i].sdsID[nSDS] = sdid; nSDS++; SWXSwath[i].nSDS++; } } free(tags); free(refs); } /* Access swath "Data" SDS */ /* ----------------------- */ /* Get # of entries within this Vgroup & search for SDS */ /* ---------------------------------------------------- */ nObjects = Vntagrefs(vgid[2]); if (nObjects > 0) { /* Get tag and ref # for Data Vgroup objects */ /* ----------------------------------------- */ tags = (int32 *) malloc(sizeof(int32) * nObjects); if(tags == NULL) { HEpush(DFE_NOSPACE,"SWattach", __FILE__, __LINE__); return(-1); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -