21 #include <HdfEosDef.h> 101 if (filename == NULL)
106 if (hdfstatus ==
FAIL)
115 if (hdfstatus ==
FAIL)
134 const char *gridname,
142 int32 num_fields = 0;
147 int32 str_buffer_size = 0;
150 if (fieldlist == NULL)
156 if (gridname == NULL)
163 hdfstatus = Gid =
GDattach(Fid,(
char*)gridname);
164 if (hdfstatus ==
FAIL)
169 if(hdfstatus ==
FAIL)
172 list = (
char*)malloc((str_buffer_size + 1) *
sizeof(char));
177 hdfstatus = num_fields =
GDinqfields(Gid,list,NULL,NULL);
178 if (hdfstatus ==
FAIL)
181 *nfields = num_fields;
182 *fieldlist = (
char**)calloc(num_fields,
sizeof(
char*));
183 if (*fieldlist == NULL)
186 temp = strtok(list,
",");
190 (*fieldlist)[i] = (
char*)malloc((strlen(temp) + 1) *
sizeof(char));
191 if ((*fieldlist)[i] == NULL)
193 strcpy((*fieldlist)[i],temp);
194 temp = strtok(NULL,
",");
201 if (hdfstatus ==
FAIL)
214 if (strstr(gridname,
"Band") != NULL)
216 char **fieldlist_tmp;
218 char *nf[] = {
"Radiance",
"RDQI",
"DN",
"Equivalent Reflectance",
"Brf" };
219 int nf_size =
sizeof(nf)/
sizeof(*nf);
224 fieldlist_tmp = (
char**)calloc(*nfields,
sizeof(
char*));
225 if (fieldlist_tmp == NULL)
229 for (i = 0; i < num_fields; ++i) {
230 fieldlist_tmp[i] = (*fieldlist)[i];
234 strncpy(band, gridname,
sizeof(band));
235 if ((sp = strstr(band,
"Band")) == NULL)
240 for(i = 0; i < nf_size; i++) {
242 len = (int)(strlen(band) + strlen(nf[i]) + 2);
243 fieldlist_tmp[k] = (
char *)malloc(len *
sizeof(
char));
244 if(fieldlist_tmp[k] == NULL)
246 strcpy(fieldlist_tmp[k], band);
247 strcat(fieldlist_tmp[k],
" ");
248 strcat(fieldlist_tmp[k], nf[i]);
252 *fieldlist = fieldlist_tmp;
257 char **fieldlist_tmp;
263 fieldlist_tmp = (
char**)calloc(num_fields * 2,
sizeof(
char*));
264 if (fieldlist_tmp == NULL)
267 for (i = 0; i < num_fields; ++i) {
268 fieldlist_tmp[j++] = (*fieldlist)[i];
269 strncpy(attrname,
"Scale ",
MAXSTR);
270 strncat(attrname, (*fieldlist)[i],
MAXSTR);
273 len = (int)(strlen(
"Raw ") + strlen((*fieldlist)[i]) + 1);
274 fieldlist_tmp[j] = (
char *)malloc(len *
sizeof(
char));
275 if (fieldlist_tmp[j] == NULL)
277 strncpy(fieldlist_tmp[j],
"Raw ", len);
278 strncat(fieldlist_tmp[j++], (*fieldlist)[i], len);
281 if (((strncmp((*fieldlist)[i],
"LandHDRF",
MAXSTR) == 0) &&
282 (strncmp((*fieldlist)[i],
"LandHDRFUnc",
MAXSTR) != 0)) ||
283 (strncmp((*fieldlist)[i],
"LandBRF",
MAXSTR) == 0) ||
284 (strncmp((*fieldlist)[i],
"LAIDelta1",
MAXSTR) ==0) ||
285 (strncmp((*fieldlist)[i],
"LAIDelta2",
MAXSTR) ==0)) {
286 len = (int)(strlen(
"Flag ") + strlen((*fieldlist)[i]) + 1);
287 fieldlist_tmp[j] = (
char *)malloc(len *
sizeof(
char));
288 if (fieldlist_tmp[j] == NULL)
290 strncpy(fieldlist_tmp[j],
"Flag ", len);
291 strncat(fieldlist_tmp[j++], (*fieldlist)[i], len);
297 *fieldlist = (
char **)realloc((
void *)fieldlist_tmp,
298 *nfields *
sizeof(
char *));
299 if (*fieldlist == NULL)
305 char **fieldlist_tmp;
310 fieldlist_tmp = (
char**)calloc(num_fields * 2,
sizeof(
char*));
311 if (fieldlist_tmp == NULL)
314 for (i = 0; i < num_fields; ++i) {
316 fieldlist_tmp[j++] = (*fieldlist)[i];
319 len = (int)(strlen(
"Raw ") + strlen((*fieldlist)[i]) + 1);
320 fieldlist_tmp[j] = (
char *)malloc(len *
sizeof(
char));
321 if (fieldlist_tmp[j] == NULL)
323 strncpy(fieldlist_tmp[j],
"Raw ", len);
324 strncat(fieldlist_tmp[j++], (*fieldlist)[i], len);
330 *fieldlist = (
char **)realloc((
void *)fieldlist_tmp,
331 *nfields *
sizeof(
char *));
332 if (*fieldlist == NULL)
343 if (fieldlist != NULL)
357 const char *gridname,
MTKt_status MtkStringListFree(int strcnt, char **strlist[])
Free string list.
int32 GDattach(int32, char *)
MTKt_status MtkFileGridToFieldListHDF(const char *filename, const char *gridname, int *nfields, char **fieldlist[])
int32 GDinqfields(int32, char *, int32 [], int32 [])
MTKt_status MtkFieldAttrGetFid(int32 sds_id, const char *fieldname, const char *attrname, MTKt_DataBuffer *attrbuf)
Version of MtkFieldAttrGet that takes an HDF SD file identifier rather than a filename.
#define MTK_ERR_CODE_JUMP(code)
2-dimensional Data Buffer
MTKt_status MtkFileGridToFieldListFid(int32 Fid, const char *gridname, int *nfields, char **fieldlist[])
Version of MtkFileGridToFieldList that takes an HDF-EOS file identifier rather than a filename...
HDFFCLIBAPI intf intf _fcd attrname
#define MTKT_DATABUFFER_INIT
MTKt_status MtkDataBufferFree(MTKt_DataBuffer *databuf)
Free data buffer.
int32 GDnentries(int32, int32, int32 *)
MTKt_status MtkGridAttrGetFid(int32 fid, const char *gridname, const char *attrname, MTKt_DataBuffer *attrbuf)
Version of MtkFileGridAttrGet that takes an HDF-EOS file ID rather than a filename.
MTKt_status MtkFileGridToFieldListNcid(int ncid, const char *gridname, int *nfields, char **fieldlist[])
MTKt_status MtkFileGridToFieldList(const char *filename, const char *gridname, int *nfields, char **fieldlist[])
Read list of fields from file.
HDFFCLIBAPI intf void * scale
MTKt_status MtkFileGridToNativeFieldListNcid(int ncid, const char *gridname, int *nfields, char **fieldlist[])
MTKt_status MtkFileGridToFieldListNC(const char *filename, const char *gridname, int *nfields, char **fieldlist[])
#define MTK_ERR_COND_JUMP(code)
int32 GDopen(char *, intn)
EXTERNL int nc_close(int ncid)
MTKt_status MtkFileTypeFid(int32 Fid, MTKt_FileType *filetype)
Version of MtkFileType that takes an HDF-EOS file identifier rather than a filename.
EXTERNL int nc_open(const char *path, int mode, int *ncidp)