24 #include <HdfEosDef.h> 40 const char *fieldname,
57 status =
MtkReadConvFid(fid, gridname, fieldname, region, databuf, mapinfo);
79 const char *fieldname,
117 int32 start_copy[10];
125 char *basefield = NULL;
127 int *extradims = NULL;
128 int dims_reversed = 0;
142 hdfstatus =
EHidinfo(fid, &HDFfid, &sid);
143 if (hdfstatus ==
FAIL)
159 gid =
GDattach(fid, (
char*)gridname);
163 hdfstatus =
GDgridinfo(gid, &xdimsize, &ydimsize, ulc, lrc);
171 hdfstatus =
GDfieldinfo(gid, basefield, &rank, dims, &hdf_datatype, dimlist);
176 if (dimlist[0] !=
'X') {
178 dims_copy[0] = dims[rank - 2];
180 dims_copy[1] = dims[rank - 1];
182 for (i = 2; i <
rank; i++) {
183 dims_copy[i] = dims[i - 2];
185 for (i = 0; i <
rank; i++) {
186 dims[i] = dims_copy[i];
202 mapfile.
nline = dims[0];
223 if (line < 0.0) ulc_line = 0;
224 else ulc_line = (int)line;
226 if (sample < 0.0) ulc_sample = 0;
227 else ulc_sample = (int)sample;
230 status =
MtkLSToSomXY(mapfile, (
float)(ulc_line + 0.5), (
float)(ulc_sample + 0.5), &ulc_som.
x, &ulc_som.
y);
243 if (line < 0.0) lrc_line = dims[0] - 1;
244 else lrc_line = (int)line;
246 if (sample < 0.0) lrc_sample = dims[1] - 1;
247 else lrc_sample = (int)sample;
250 status =
MtkLSToSomXY(mapfile, (
float)(lrc_line + 0.5), (
float)(lrc_sample + 0.5), &lrc_som.
x, &lrc_som.
y);
254 nline = lrc_line - ulc_line + 1;
255 nsample = lrc_sample - ulc_sample + 1;
258 start[1] = ulc_sample;
263 for (i = 2; i <
rank; i++) {
264 start[i] = extradims[i-2];
271 start_copy[rank - 2] = start[0];
272 edge_copy[rank - 2] = edge[0];
274 start_copy[rank - 1] = start[1];
275 edge_copy[rank - 1] = edge[1];
277 for (i = 0; i < rank - 2; i++) {
278 start_copy[i] = start[i + 2];
279 edge_copy[i] = edge[i + 2];
281 for (i = 0; i <
rank; i++) {
282 start[i] = start_copy[i];
283 edge[i] = edge_copy[i];
292 hdfstatus =
GDreadfield(gid, basefield, start, NULL, edge,
308 for (l = 0; l < map.
nline; l++) {
309 for (s = 0; s < map.
nsample; s++) {
319 for (x = ulc_som.
x; x <= lrc_som.
x; x += map.
resolution) {
321 memcpy((
void *)&(buf.
data.
u8[(
int)line][(
int)sample]),
322 (
void *)&(filebuf_tmp.
data.
u8[i++][0]),
336 if (basefield != NULL) free(basefield);
337 if (extradims != NULL) free(extradims);
MTKt_status MtkReadConv(const char *filename, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Reads any grid/field from a MISR conventional product file.
MTKt_status MtkDataBufferAllocate(int nline, int nsample, MTKt_DataType datatype, MTKt_DataBuffer *databuf)
Allocate Data Buffer.
HDFFCLIBAPI _fcd _fcd intf intf * datatype
int32 GDattach(int32, char *)
#define MTKT_MAPINFO_INIT
MTKt_status MtkLSToSomXY(MTKt_MapInfo mapinfo, float line, float sample, double *som_x, double *som_y)
Convert line, sample to SOM X, SOM Y.
HDFFCLIBAPI void intf dims[]
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 MtkReadConvFid(int32 fid, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Version of MtkReadConv that takes an HDF-EOS file identifier rather than a filename.
MTKt_status MtkHdfToMtkDataTypeConvert(int32 hdf_datatype, MTKt_DataType *datatype)
Convert HDF data type to MISR Toolkit data type.
#define MTKT_DATABUFFER_INIT
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.
MTKt_status MtkSomXYToLS(MTKt_MapInfo mapinfo, double som_x, double som_y, float *line, float *sample)
Convert SOM X, SOM Y to line, sample.
intn GDgridinfo(int32, int32 *, int32 *, float64 [], float64 [])
intn GDfieldinfo(int32, char *, int32 *, int32 [], int32 *, char *)
MTKt_status MtkFileToPathFid(int32 sid, int *path)
Version of MtkFileToPath that takes an HDF SD identifier rather than a filename.
#define MTKT_SOMCOORD_INIT
intn EHidinfo(int32, int32 *, int32 *)
HDFFCLIBAPI intf intf start[]
MTKt_status MtkSnapToGrid(int path, int resolution, MTKt_Region region, MTKt_MapInfo *mapinfo)
Snap a region to a MISR grid based on path number and resolution.
intn GDreadfield(int32, char *, int32 [], int32 [], int32 [], VOIDP)
#define MTK_ERR_COND_JUMP(code)
int32 GDopen(char *, intn)
int const JOCTET * dataptr
MTKt_status MtkFileGridToResolutionFid(int32 fid, const char *gridname, int *resolution)
Version of MtkFileGridToResolution that takes an HDF-EOS file id rather than a filename.