📄 swapi.c
字号:
{ compparm[i] = 0.0; } /* * Get compression parameters if NBIT or DEFLATE compression */ if (*compcode == HDFE_COMP_NBIT) { statmeta = EHgetmetavalue(metaptrs, "CompressionParams", utlstr); if (statmeta == 0) { sscanf(utlstr, "(%d,%d,%d,%d)", &compparm[0], &compparm[1], &compparm[2], &compparm[3]); } else { status = -1; HEpush(DFE_GENAPP, "SWcompinfo", __FILE__, __LINE__); HEreport( "\"CompressionParams\" string not found in metadata.\n"); } } else if (*compcode == HDFE_COMP_DEFLATE) { statmeta = EHgetmetavalue(metaptrs, "DeflateLevel", utlstr); if (statmeta == 0) { sscanf(utlstr, "%d", &compparm[0]); } else { status = -1; HEpush(DFE_GENAPP, "SWcompinfo", __FILE__, __LINE__); HEreport( "\"DeflateLevel\" string not found in metadata.\n"); } } } } else { HEpush(DFE_GENAPP, "SWcompinfo", __FILE__, __LINE__); HEreport("Fieldname \"%s\" not found.\n", fieldname); } free(metabuf); } free(utlstr); return (status);}/*----------------------------------------------------------------------------|| BEGIN_PROLOG || || FUNCTION: SWfinfo || || DESCRIPTION: Returns field info || || || Return Value Type Units Description || ============ ====== ========= ===================================== || status intn return status (0) SUCCEED, (-1) FAIL || || INPUTS: || swathID int32 swath structure id || fieldtype char fieldtype (geo or data) || fieldname char name of field || || || OUTPUTS: || rank int32 rank of field (# of dims) || dims int32 field dimensions || numbertype int32 field number type || dimlist char field dimension list || || NOTES: || || || Date Programmer Description || ====== ============ ================================================= || Jun 96 Joel Gales Original Programmer || Aug 96 Joel Gales Make metadata ODL compliant || Jan 97 Joel Gales Check for metadata error status from EHgetmetavalue || || END_PROLOG |-----------------------------------------------------------------------------*/int32SWfinfo(int32 swathID, char *fieldtype, char *fieldname, int32 *rank, int32 dims[], int32 *numbertype, char *dimlist){ intn i; /* Loop index */ intn j; /* Loop index */ intn status; /* routine return status variable */ intn statmeta = 0; /* EHgetmetavalue return status */ int32 fid; /* HDF-EOS file ID */ int32 sdInterfaceID; /* HDF SDS interface ID */ int32 idOffset = SWIDOFFSET; /* Swath ID offset */ int32 fsize; /* field size in bytes */ int32 ndims; /* Number of dimensions */ int32 slen[8]; /* Length of each entry in parsed string */ int32 dum; /* Dummy variable */ int32 vdataID; /* 1d field vdata ID */ uint8 *buf; /* One-Dim field buffer */ char *metabuf; /* Pointer to structural metadata (SM) */ char *metaptrs[2];/* Pointers to begin and end of SM section */ char swathname[80]; /* Swath Name */ char *utlstr; /* Utility string */ char *ptr[8]; /* String pointers for parsed string */ char dimstr[64]; /* Individual dimension entry string */ /* Allocate space for utility string */ /* --------------------------------- */ utlstr = (char *) calloc(UTLSTR_MAX_SIZE, sizeof(char)); if(utlstr == NULL) { HEpush(DFE_NOSPACE,"SWfinfo", __FILE__, __LINE__); return(-1); } /* Initialize rank and numbertype to -1 (error) */ /* -------------------------------------------- */ *rank = -1; *numbertype = -1; /* Get HDF-EOS file ID and SDS interface ID */ status = SWchkswid(swathID, "SWfinfo", &fid, &sdInterfaceID, &dum); /* Get swath name */ Vgetname(SWXSwath[swathID % idOffset].IDTable, swathname); /* Get pointers to appropriate "Field" section within SM */ if (strcmp(fieldtype, "Geolocation Fields") == 0) { metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s", "GeoField", metaptrs); if(metabuf == NULL) { free(utlstr); return(-1); } } else { metabuf = (char *) EHmetagroup(sdInterfaceID, swathname, "s", "DataField", metaptrs); if(metabuf == NULL) { free(utlstr); return(-1); } } /* Search for field */ sprintf(utlstr, "%s%s%s", "\"", fieldname, "\"\n"); metaptrs[0] = strstr(metaptrs[0], utlstr); /* If field found ... */ if (metaptrs[0] < metaptrs[1] && metaptrs[0] != NULL) { /* Get DataType string */ statmeta = EHgetmetavalue(metaptrs, "DataType", utlstr); /* Convert to numbertype code */ if (statmeta == 0) { if (strcmp(utlstr, "DFNT_UCHAR8") == 0) *numbertype = 3; else if (strcmp(utlstr, "DFNT_CHAR8") == 0) *numbertype = 4; else if (strcmp(utlstr, "DFNT_FLOAT32") == 0) *numbertype = 5; else if (strcmp(utlstr, "DFNT_FLOAT64") == 0) *numbertype = 6; else if (strcmp(utlstr, "DFNT_INT8") == 0) *numbertype = 20; else if (strcmp(utlstr, "DFNT_UINT8") == 0) *numbertype = 21; else if (strcmp(utlstr, "DFNT_INT16") == 0) *numbertype = 22; else if (strcmp(utlstr, "DFNT_UINT16") == 0) *numbertype = 23; else if (strcmp(utlstr, "DFNT_INT32") == 0) *numbertype = 24; else if (strcmp(utlstr, "DFNT_UINT32") == 0) *numbertype = 25; } else { status = -1; HEpush(DFE_GENAPP, "SWfieldinfo", __FILE__, __LINE__); HEreport( "\"DataType\" string not found in metadata.\n"); } /* * Get DimList string and trim off leading and trailing parens "()" */ statmeta = EHgetmetavalue(metaptrs, "DimList", utlstr); if (statmeta == 0) { memmove(utlstr, utlstr + 1, strlen(utlstr) - 2); utlstr[strlen(utlstr) - 2] = 0; /* Parse trimmed DimList string and get rank */ ndims = EHparsestr(utlstr, ',', ptr, slen); *rank = ndims; } else { status = -1; HEpush(DFE_GENAPP, "SWfieldinfo", __FILE__, __LINE__); HEreport( "\"DimList\" string not found in metadata.\n"); } /* If dimension list is desired by user then initialize length to 0 */ if (dimlist != NULL) { dimlist[0] = 0; } /* * Copy each entry in DimList and remove leading and trailing quotes, * Get dimension sizes and concatanate dimension names to dimension * list */ for (i = 0; i < ndims; i++) { memcpy(dimstr, ptr[i] + 1, slen[i] - 2); dimstr[slen[i] - 2] = 0; dims[i] = SWdiminfo(swathID, dimstr); if (dimlist != NULL) { if (i > 0) { strcat(dimlist, ","); } strcat(dimlist, dimstr); } } /* Appendable Field Section */ /* ------------------------ */ if (dims[0] == 0) { /* One-Dimensional Field */ if (*rank == 1) { /* Get vdata ID */ status = SW1dfldsrch(fid, swathID, fieldname, "r", &dum, &vdataID, &dum); /* Get actual size of field */ dims[0] = VSelts(vdataID); /* * If size=1 then check where actual record of * "initialization" record */ if (dims[0] == 1) { /* Get record size and read 1st record */ fsize = VSsizeof(vdataID, fieldname); buf = (uint8 *) calloc(fsize, 1); if(buf == NULL) { HEpush(DFE_NOSPACE,"SWfinfo", __FILE__, __LINE__); free(utlstr); return(-1); } VSsetfields(vdataID, fieldname); VSseek(vdataID, 0); VSread(vdataID, (uint8 *) buf, 1, FULL_INTERLACE); /* Sum up "bytes" in record */ for (i = 0, j = 0; i < fsize; i++) { j += buf[i]; } /* * If filled with 255 then "initialization" record, * actual number of records = 0 */ if (j == 255 * fsize) { dims[0] = 0; } free(buf); } /* Detach from 1d field */ VSdetach(vdataID); } else { /* Get actual size of Multi-Dimensional Field */ status = SWSDfldsrch(swathID, sdInterfaceID, fieldname, &dum, &dum, &dum, &dum, dims, &dum); } } } free(metabuf); if (*rank == -1) { status = -1; } free(utlstr); return (status);}/*----------------------------------------------------------------------------|| BEGIN_PROLOG || || FUNCTION: SWfieldinfo || || DESCRIPTION: Wrapper arount SWfinfo || || || Return Value Type Units Description || ============ ====== ========= ===================================== || status intn return status (0) SUCCEED, (-1) FAIL || || INPUTS: || swathID int32 swath structure id || fieldname char name of field ||
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -