28 #include <HdfEosDef.h> 42 const char *fieldname,
49 status =
MtkReadL2LandNC(filename, gridname, fieldname, region, databuf, mapinfo);
52 return MtkReadL2LandHDF(filename, gridname, fieldname, region, databuf, mapinfo);
58 const char *fieldname,
96 const char *fieldname,
113 status =
MtkReadL2LandFid(fid, gridname, fieldname, region, databuf, mapinfo);
134 const char *gridname,
135 const char *fieldname,
172 char *basefield = NULL;
174 int *extradims = NULL;
184 strncpy(fieldstr, fieldname,
MAXSTR);
185 fieldarr[0] = fieldstr;
188 if ((sp = strchr(fieldstr,
' ')) != NULL) {
191 }
else if ((sp = strchr(fieldstr,
'\0')) != NULL) {
201 if ((sp = strcasestr(fieldname,
"raw")) != NULL ||
202 (sp = strcasestr(fieldname,
"native")) != NULL) {
206 }
else if ((sp = strcasestr(fieldname,
"flag")) != NULL) {
224 strncpy(attr,
"Min ",
MAXSTR);
225 strncat(attr, basefield, strlen(basefield));
229 strncpy(attr,
"Max ",
MAXSTR);
230 strncat(attr, basefield, strlen(basefield));
234 strncpy(attr,
"Scale ",
MAXSTR);
235 strncat(attr, basefield, strlen(basefield));
239 strncpy(attr,
"Offset ",
MAXSTR);
240 strncat(attr, basefield, strlen(basefield));
244 strncpy(attr,
"Fill ",
MAXSTR);
245 strncat(attr, basefield, strlen(basefield));
249 strncpy(attr,
"Underflow ",
MAXSTR);
250 strncat(attr, basefield, strlen(basefield));
254 strncpy(attr,
"Overflow ",
MAXSTR);
255 strncat(attr, basefield, strlen(basefield));
272 ((strncmp(basefield,
"LandHDRF",
MAXSTR) == 0 &&
273 strncmp(basefield,
"LandHDRFUnc",
MAXSTR) != 0) ||
274 strncmp(basefield,
"LandBRF",
MAXSTR) == 0)) {
276 status =
MtkReadRawFid(fid, gridname, field, region, &rawbuf, &map);
283 for (l = 0; l < buf.
nline; l++) {
284 for (s = 0; s < buf.
nsample; s++) {
293 scale.
data.
f[0][0]) +
306 status =
MtkReadRawFid(fid, gridname, field, region, &rawbuf, &map);
315 for (l = 0; l < buf.
nline; l++) {
316 for (s = 0; s < buf.
nsample; s++) {
319 }
else if (rawbuf.
data.
u8[l][s] == underflow.
data.
u8[0][0]) {
321 }
else if (rawbuf.
data.
u8[l][s] == overflow.
data.
u8[0][0]) {
331 for (l = 0; l < buf.
nline; l++) {
332 for (s = 0; s < buf.
nsample; s++) {
358 (strncmp(basefield,
"LAIDelta1",
MAXSTR) == 0 ||
359 strncmp(basefield,
"LAIDelta2",
MAXSTR) == 0)) {
361 status =
MtkReadRawFid(fid, gridname, field, region, &buf, &map);
367 for (l = 0; l < buf.
nline; l++) {
368 for (s = 0; s < buf.
nsample; s++) {
383 ((strncmp(basefield,
"LandHDRF",
MAXSTR) == 0 &&
384 strncmp(basefield,
"LandHDRFUnc",
MAXSTR) != 0) ||
385 strncmp(basefield,
"LandBRF",
MAXSTR) == 0)) {
387 status =
MtkReadRawFid(fid, gridname, field, region, &rawbuf, &map);
394 for (l = 0; l < buf.
nline; l++) {
395 for (s = 0; s < buf.
nsample; s++) {
412 (strncmp(basefield,
"LAIDelta1",
MAXSTR) == 0 ||
413 strncmp(basefield,
"LAIDelta2",
MAXSTR) == 0)) {
415 status =
MtkReadRawFid(fid, gridname, field, region, &buf, &map);
421 for (l = 0; l < buf.
nline; l++) {
422 for (s = 0; s < buf.
nsample; s++) {
424 buf.
data.
f[l][s] = buf.
data.
f[l][s] < 0.0f ? -1.0f : 1.0f;
437 status =
MtkReadRawFid(fid, gridname, field, region, &buf, &map);
460 if (basefield != NULL) free(basefield);
461 if (extradims != NULL) free(extradims);
476 const char *gridname,
477 const char *fieldname,
487 char *basefield = NULL;
489 int *extradims = NULL;
511 status =
MtkNCVarId(group_id, basefield, &var);
515 if (nc_status ==
NC_NOERR) scaled = 1;
524 if ( scaled == 1 && nc_datatype ==
NC_USHORT ) {
525 unsigned short valid_range[2];
536 status =
MtkReadRawNcid(ncid, gridname, fieldname, region, &rawbuf, &map);
542 float float_fill = -9999.0;
544 unsigned short valid_min = valid_range[0];
545 unsigned short valid_max = valid_range[1];
546 for (
int i = 0; i < buf.
nline; i++) {
547 for (
int j = 0; j < buf.
nsample; j++) {
548 unsigned short raw = rawbuf.
data.
u16[i][j];
549 if (raw < valid_min || raw > valid_max) {
550 buf.
data.
f[i][j] = float_fill;
561 }
else if (scaled == 1 && nc_datatype ==
NC_UBYTE) {
562 unsigned char valid_range[2];
573 status =
MtkReadRawNcid(ncid, gridname, fieldname, region, &rawbuf, &map);
579 float float_fill = -9999.0;
581 unsigned char valid_min = valid_range[0];
582 unsigned char valid_max = valid_range[1];
583 for (
int i = 0; i < buf.
nline; i++) {
584 for (
int j = 0; j < buf.
nsample; j++) {
585 unsigned char raw = rawbuf.
data.
u8[i][j];
586 if (raw < valid_min || raw > valid_max) {
587 buf.
data.
f[i][j] = float_fill;
600 status =
MtkReadRawNcid(ncid, gridname, fieldname, region, &buf, &map);
614 if (basefield != NULL) free(basefield);
615 if (extradims != NULL) free(extradims);
MTKt_status MtkDataBufferAllocate(int nline, int nsample, MTKt_DataType datatype, MTKt_DataBuffer *databuf)
Allocate Data Buffer.
MTKt_status MtkReadL2Land(const char *filename, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Reads, unpacks and unscales any L2 Land grid/field from a MISR L2 AS Land product file...
#define MTKT_MAPINFO_INIT
EXTERNL int nc_get_att(int ncid, int varid, const char *name, void *ip)
MTKt_status MtkParseFieldname(const char *fieldname, char **basefieldname, int *ndim, int **dimlist)
Parses extra dimensions from fieldnames.
#define MTK_ERR_CODE_JUMP(code)
2-dimensional Data Buffer
MTKt_status MtkReadL2LandNC(const char *filename, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
MTKt_status MtkReadL2LandNcid(int ncid, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
#define MTKT_DATABUFFER_INIT
MTKt_status MtkReadL2LandHDF(const char *filename, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
EXTERNL int nc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep, size_t *lenp)
MTKt_status MtkFillValueGetFid(int32 fid, const char *gridname, const char *fieldname, MTKt_DataBuffer *fillbuf)
Version of MtkFillValueGet that takes an HDF-EOS file ID rather than a filename.
MTKt_status MtkDataBufferFree(MTKt_DataBuffer *databuf)
Free data buffer.
EXTERNL int nc_inq_vartype(int ncid, int varid, nc_type *xtypep)
MTKt_status MtkReadL2LandFid(int32 fid, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Version of MtkReadL2Land that takes and HDF-EOS file identifier rather than a filename.
HDFFCLIBAPI int32 float32 * max
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 MtkReadRawNcid(int ncid, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Version of MtkReadRaw that takes an HDF-EOS file identifier rather than a filename.
HDFFCLIBAPI intf void * scale
MTKt_status MtkReadRawFid(int32 fid, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Version of MtkReadRaw that takes an HDF-EOS file identifier rather than a filename.
#define MTK_ERR_COND_JUMP(code)
HDFFCLIBAPI intf * offset
int32 GDopen(char *, intn)
EXTERNL int nc_close(int ncid)
MTKt_status MtkNCVarId(int Ncid, const char *Name, MTKt_ncvarid *Var)
EXTERNL int nc_inq_grp_ncid(int ncid, const char *grp_name, int *grp_ncid)
EXTERNL int nc_open(const char *path, int mode, int *ncidp)