📄 ptapi.c
字号:
HEpush(DFE_GENAPP, "PTgetlevelname", __FILE__, __LINE__); HEreport("No Levels Defined for point ID: %d\n", pointID); } else if (nlevels < level) { /* Report error if level # to large */ /* -------------------------------- */ status = -1; HEpush(DFE_GENAPP, "PTgetlevelname", __FILE__, __LINE__); HEreport("Only %d levels Defined for point ID: %d\n", nlevels, pointID); } if (status == 0) { /* Get level name */ /* -------------- */ VSgetname(PTXPoint[pointID % idOffset].vdID[level], name); /* Return name string length */ /* ------------------------- */ *strbufsize = strlen(name); /* Return levelname if requested */ /* ----------------------------- */ if (levelname != NULL) { strcpy(levelname, name); } } } return (status);}/*----------------------------------------------------------------------------|| BEGIN_PROLOG || || FUNCTION: PTattach || || DESCRIPTION: Attaches to an existing point data set. || || || Return Value Type Units Description || ============ ====== ========= ===================================== || pointID int32 point structure ID || || INPUTS: || fid int32 HDF-EOS file ID || pointname char point structure name || || || OUTPUTS: || None || || NOTES: || || || Date Programmer Description || ====== ============ ================================================= || Jun 96 Joel Gales Original Programmer || Aug 96 Joel Gales Initalize pointID to -1 || Sep 96 Joel Gales File ID in EHgetid changed from HDFEOS file id to || HDF file id || || END_PROLOG |-----------------------------------------------------------------------------*/int32PTattach(int32 fid, char *pointname){ intn i; /* Loop index */ intn j; /* Loop index */ intn npointopen = 0; /* # of point structures open */ intn status = -1;/* 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 pointID = -1; /* HDF-EOS point ID */ int32 *tags; /* Pnt to Vgroup object tags array */ int32 *refs; /* Pnt to Vgroup object refs array */ int32 dum; /* dummy varible */ int32 nlevels; /* Number of levels in point */ int32 vgidData; /* Point data Vgroup ID */ int32 tag; /* Point Vdata tag */ int32 ref; /* Point Vdata ref */ int32 idOffset = PTIDOFFSET; /* Point 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, pointname, &HDFfid, &dum, &acs); if (status == 0) { /* Convert numeric access code to character */ /* ---------------------------------------- */ acsCode[0] = (acs == 1) ? 'w' : 'r'; /* Determine number of points currently opened */ /* ------------------------------------------- */ for (i = 0; i < NPOINT; i++) { npointopen += PTXPoint[i].active; } /* If room for more ... */ /* -------------------- */ if (npointopen < NPOINT) { /* Search Vgroups for Point */ /* ------------------------ */ 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, acsCode); Vgetname(vgid[0], name); Vgetclass(vgid[0], class); /* If point found get vgroup & vdata ids */ /* ------------------------------------- */ if (strcmp(name, pointname) == 0 && strcmp(class, "POINT") == 0) { status = 0; /* Attach to Point Vgroups (Skip 1st entry (Vdata)) */ /* ------------------------------------------------ */ tags = (int32 *) malloc(sizeof(int32) * 4); if(tags == NULL) { HEpush(DFE_NOSPACE,"PTattach", __FILE__, __LINE__); return(-1); } refs = (int32 *) malloc(sizeof(int32) * 4); if(refs == NULL) { HEpush(DFE_NOSPACE,"PTattach", __FILE__, __LINE__); free(tags); return(-1); } Vgettagrefs(vgid[0], tags, refs, 4); vgid[1] = Vattach(HDFfid, refs[1], acsCode); vgid[2] = Vattach(HDFfid, refs[2], acsCode); vgid[3] = Vattach(HDFfid, refs[3], acsCode); free(tags); free(refs); /* Setup External Arrays */ /* --------------------- */ for (i = 0; i < NPOINT; i++) { /* Find empty entry in array */ /* ------------------------- */ if (PTXPoint[i].active == 0) { /* * Set pointID, Set point entry active, Store * root Vgroup ID, Store sub Vgroup IDs, Store * HDF-EOS file ID. Get number of levels. */ pointID = i + idOffset; PTXPoint[i].active = 1; PTXPoint[i].IDTable = vgid[0]; PTXPoint[i].VIDTable[0] = vgid[1]; PTXPoint[i].VIDTable[1] = vgid[2]; PTXPoint[i].VIDTable[2] = vgid[3]; PTXPoint[i].fid = fid; vgidData = vgid[1]; nlevels = Vntagrefs(vgidData); /* Attach & Store level Vdata IDs */ /* ------------------------------ */ for (j = 0; j < nlevels; j++) { Vgettagref(vgidData, j, &tag, &ref); PTXPoint[i].vdID[j] = VSattach(HDFfid, ref, acsCode); } break; } } break; } /* Detach Vgroup if not desired Swath */ /* ---------------------------------- */ Vdetach(vgid[0]); } /* If Point not found then set up error message */ /* -------------------------------------------- */ if (status == -1) { pointID = -1; strcpy(errbuf, "Point: \"%s\" does not exist "); strcat(errbuf, "within HDF file.\n"); HEpush(DFE_RANGE, "PTattach", __FILE__, __LINE__); HEreport(errbuf, pointname); } } else { /* Too many files opened */ /* --------------------- */ status = -1; pointID = -1; strcpy(errbuf, "No more than %d points may be open simutaneously"); strcat(errbuf, " (%s)"); HEpush(DFE_DENIED, "PTattach", __FILE__, __LINE__); HEreport(errbuf, NPOINT, pointname); } } return (pointID);}/*----------------------------------------------------------------------------|| BEGIN_PROLOG || || FUNCTION: PTdeflevel || || DESCRIPTION: Defines a level within the point data set. || || || Return Value Type Units Description || ============ ====== ========= ===================================== || status intn return status (0) SUCCEED, (-1) FAIL || || INPUTS: || pointID int32 point structure ID || levelname char name of level || fieldlist char list of level fields (comma-separated) || fieldtype int32 array of field types || fieldorder int32 array of field orders || || || OUTPUTS: || None || || NOTES: || || || Date Programmer Description || ====== ============ ================================================= || Jun 96 Joel Gales Original Programmer || Aug 96 Joel Gales Check level and field names for length || May 00 Abe Taaheri Added few lines to check for errors in HDF functions|| VSfdefine, VSsetfields, and VSsizeof || || END_PROLOG |-----------------------------------------------------------------------------*/intnPTdeflevel(int32 pointID, char *levelname, char *fieldlist, int32 fieldtype[], int32 fieldorder[]){ intn i; /* Loop index */ intn status = 0; /* routine return status variable */ int32 fid; /* HDF-EOS file id */ int32 sdInterfaceID; /* HDF SDS interface ID */ int32 idOffset = PTIDOFFSET; /* Point ID offset */ int32 ptVgrpID; /* Point Vgroup ID */ int32 nlevels; /* Number of levels in point */ int32 pID; /* Point ID - offset */ int32 nfields; /* Number of fields in fieldlist */ int32 vgid; /* Vgroup ID */ int32 vdataID; /* Vdata ID */ int32 order; /* Field order */ int32 slen[VSFIELDMAX]; /* String length array */ int32 size; /* Record size in bytes */ int32 metadata[2];/* Metadata input array */ int32 m1 = -1; /* Minus one (fill value) */ int32 dum; /* Dummy variable */ char pointname[80]; /* Point name */ char utlbuf[256];/* Utility buffer */ char *zerobuf; /* Pointer to zero (initial) Vdata record * buffer */ char *pntr[VSFIELDMAX]; /* String pointer array */ /* Check for valid point ID */ /* ------------------------ */ status = PTchkptid(pointID, "PTdeflevel", &fid, &sdInterfaceID, &ptVgrpID); /* Check levelname for length */ /* -------------------------- */ if ((intn) strlen(levelname) > VSNAMELENMAX) { status = -1; HEpush(DFE_GENAPP, "PTdeflevel", __FILE__, __LINE__); HEreport("Levelname \"%s\" more than %d characters.\n", levelname, VSNAMELENMAX); } if (status == 0) { /* Compute "reduce" point ID */ /* ------------------------- */ pID = pointID % idOffset; /* Parse field list */ /* ---------------- */ nfields = EHparsestr(fieldlist, ',', pntr, slen); /* Loop through all entries in fieldlist */ /* ------------------------------------- */ for (i = 0; i < nfields; i++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -