MISR Toolkit  1.5.1
MtkReadData.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkReadData =
4 = =
5 =============================================================================
6 
7  Jet Propulsion Laboratory
8  MISR
9  MISR Toolkit
10 
11  Copyright 2005, California Institute of Technology.
12  ALL RIGHTS RESERVED.
13  U.S. Government Sponsorship acknowledged.
14 
15 ============================================================================*/
16 
17 #include "MisrReadData.h"
18 #include "MisrFileQuery.h"
19 #include "MisrError.h"
20 #include <stdlib.h>
21 #include <string.h>
22 #include <hdf.h>
23 #include <HdfEosDef.h>
24 #include <netcdf.h>
25 
63  const char *filename,
64  const char *gridname,
65  const char *fieldname,
66  MTKt_Region region,
67  MTKt_DataBuffer *databuf,
68  MTKt_MapInfo *mapinfo )
69 {
70  MTKt_status status; /* Return status */
71 
72  status = MtkReadDataNC(filename, gridname, fieldname, region, databuf, mapinfo); // try netCDF
73  if (status != MTK_NETCDF_OPEN_FAILED) return status;
74 
75  return MtkReadDataHDF(filename, gridname, fieldname, region, databuf, mapinfo); // try HDF
76 }
77 
79  const char *filename,
80  const char *gridname,
81  const char *fieldname,
82  MTKt_Region region,
83  MTKt_DataBuffer *databuf,
84  MTKt_MapInfo *mapinfo )
85 {
86  MTKt_status status_code; /* Return status code for error macros */
87  MTKt_status status; /* Return status */
88  int32 fid = FAIL; /* HDF-EOS File id */
89  intn hdfstatus; /* HDF return status */
90 
91  if (filename == NULL) return MTK_NULLPTR;
92 
93  /* Open file. */
94  fid = GDopen((char*)filename, DFACC_READ);
96 
97  /* Read data. */
98  status = MtkReadDataFid(fid, gridname, fieldname, region, databuf, mapinfo);
99  MTK_ERR_COND_JUMP(status);
100 
101  /* Close file. */
102  hdfstatus = GDclose(fid);
104  fid = FAIL;
105 
106  return MTK_SUCCESS;
107 
108  ERROR_HANDLE:
109  if (fid != FAIL) GDclose(fid);
110  return status_code;
111 }
112 
114  const char *filename,
115  const char *gridname,
116  const char *fieldname,
117  MTKt_Region region,
118  MTKt_DataBuffer *databuf,
119  MTKt_MapInfo *mapinfo )
120 {
121  MTKt_status status_code; /* Return status code for error macros */
122  MTKt_status status; /* Return status */
123 
124  if (filename == NULL) return MTK_NULLPTR;
125 
126  /* Open file. */
127  int ncid = 0;
128  {
129  int nc_status = nc_open(filename, NC_NOWRITE, &ncid);
131  }
132 
133  /* Read data. */
134  status = MtkReadDataNcid(ncid, gridname, fieldname, region, databuf, mapinfo);
135  MTK_ERR_COND_JUMP(status);
136 
137  /* Close file. */
138  {
139  int nc_status = nc_close(ncid);
141  }
142  ncid = 0;
143  /* Close file. */
144 
145  return MTK_SUCCESS;
146 
147  ERROR_HANDLE:
148  if (ncid != 0) nc_close(ncid);
149  return status_code;
150 }
151 
158  int32 fid,
159  const char *gridname,
160  const char *fieldname,
161  MTKt_Region region,
162  MTKt_DataBuffer *databuf,
163  MTKt_MapInfo *mapinfo )
164 {
165  MTKt_status status_code; /* Return status code for error macros */
166  MTKt_status status; /* Return status */
167  MTKt_FileType filetype; /* File type */
168 
169  /* Determine file type */
170  status = MtkFileTypeFid(fid, &filetype);
171  MTK_ERR_COND_JUMP(status);
172 
173  switch (filetype) {
174 
175  case MTK_AGP:
176  case MTK_GP_GMP:
177  case MTK_GRP_RCCM:
178  case MTK_PP:
179  status = MtkReadRawFid(fid, gridname, fieldname, region,
180  databuf, mapinfo);
181  MTK_ERR_COND_JUMP(status);
182  break;
183 
186  case MTK_GRP_TERRAIN_GM:
187  case MTK_GRP_TERRAIN_LM:
188  status = MtkReadL1B2Fid(fid, gridname, fieldname, region,
189  databuf, mapinfo);
190  MTK_ERR_COND_JUMP(status);
191  break;
192 
193  case MTK_AS_AEROSOL:
194  status = MtkReadRawFid(fid, gridname, fieldname, region,
195  databuf, mapinfo);
196  MTK_ERR_COND_JUMP(status);
197  break;
198 
199  case MTK_AS_LAND:
200  status = MtkReadL2LandFid(fid, gridname, fieldname, region,
201  databuf, mapinfo);
202  MTK_ERR_COND_JUMP(status);
203  break;
204 
205  case MTK_TC_ALBEDO:
206  status = MtkReadRawFid(fid, gridname, fieldname, region,
207  databuf, mapinfo);
208  MTK_ERR_COND_JUMP(status);
209  break;
210 
211  case MTK_TC_CLASSIFIERS:
212  status = MtkReadRawFid(fid, gridname, fieldname, region,
213  databuf, mapinfo);
214  MTK_ERR_COND_JUMP(status);
215  break;
216 
217  case MTK_TC_STEREO:
218  status = MtkReadRawFid(fid, gridname, fieldname, region,
219  databuf, mapinfo);
220  MTK_ERR_COND_JUMP(status);
221  break;
222 
223  case MTK_TC_CLOUD:
224  status = MtkReadL2TCCloudFid(fid, gridname, fieldname, region,
225  databuf, mapinfo);
226  MTK_ERR_COND_JUMP(status);
227  break;
228 
229  case MTK_CMV_NRT:
230  status = MtkReadRawFid(fid, gridname, fieldname, region,
231  databuf, mapinfo);
232  MTK_ERR_COND_JUMP(status);
233  break;
234 
235  case MTK_HR_BRF:
236  case MTK_HR_RPV:
237  case MTK_HR_TIP:
238  case MTK_CONVENTIONAL:
239  status = MtkReadConvFid(fid, gridname, fieldname, region,
240  databuf, mapinfo);
241  MTK_ERR_COND_JUMP(status);
242  break;
243 
244  case MTK_UNKNOWN:
245  default:
247  }
248 
249  return MTK_SUCCESS;
250 
251  ERROR_HANDLE:
252 
253  return status_code;
254 }
255 
262  int ncid,
263  const char *gridname,
264  const char *fieldname,
265  MTKt_Region region,
266  MTKt_DataBuffer *databuf,
267  MTKt_MapInfo *mapinfo )
268 {
269  MTKt_status status_code; /* Return status code for error macros */
270  MTKt_status status; /* Return status */
271  MTKt_FileType filetype; /* File type */
272 
273  /* Determine file type */
274  status = MtkFileTypeNcid(ncid, &filetype);
275  MTK_ERR_COND_JUMP(status);
276 
277  switch (filetype) {
278 
279  case MTK_AS_AEROSOL:
280  status = MtkReadRawNcid(ncid, gridname, fieldname, region, databuf, mapinfo);
281  MTK_ERR_COND_JUMP(status);
282  break;
283 
284  case MTK_AS_LAND:
285  status = MtkReadL2LandNcid(ncid, gridname, fieldname, region, databuf, mapinfo);
286  MTK_ERR_COND_JUMP(status);
287  break;
288 
289  case MTK_UNKNOWN:
290  default:
292  }
293 
294  return MTK_SUCCESS;
295 
296  ERROR_HANDLE:
297 
298  return status_code;
299 }
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.
#define DFACC_READ
Definition: hdf.h:44
char * filename
Definition: cdjpeg.h:133
intn GDclose(int32)
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.
Definition: MtkReadConv.c:76
MTKt_status MtkFileTypeNcid(int ncid, MTKt_FileType *filetype)
Definition: MtkFileType.c:266
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
MTKt_FileType
Definition: MisrFileQuery.h:24
MTKt_status MtkReadDataHDF(const char *filename, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Definition: MtkReadData.c:78
Map Information.
Definition: MisrMapQuery.h:65
MTKt_status MtkReadL2TCCloudFid(int32 fid, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Version of MtkReadL2TCCloud that takes and HDF-EOS file identifier rather than a filename.
MTKt_status MtkReadDataNcid(int ncid, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Version of MtkReadData that takes a netCDF file identifier rather than a filename.
Definition: MtkReadData.c:261
2-dimensional Data Buffer
Definition: MisrUtil.h:98
MTKt_status MtkReadL1B2Fid(int32 Fid, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Version of MtkReadL1B2 that takes an HDF-EOS file identifier rather than a filename. MISR L1B2 product file.
Definition: MtkReadL1B2.c:81
MTKt_status MtkReadDataFid(int32 fid, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Version of MtkReadData that takes an HDF-EOS file identifier rather than a filename.
Definition: MtkReadData.c:157
MTKt_status MtkReadL2LandNcid(int ncid, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
#define NC_NOERR
Definition: netcdf.h:313
MTKt_status MtkReadData(const char *filename, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Reads any grid/field from any MISR product file and performs unpacking or unscaling. It also reads any MISR conventional product file.
Definition: MtkReadData.c:62
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.
Definition: MtkReadRaw.c:248
#define NC_NOWRITE
Definition: netcdf.h:201
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.
Definition: MtkReadRaw.c:141
#define MTK_ERR_COND_JUMP(code)
Definition: MisrError.h:188
MTKt_status
Definition: MisrError.h:11
Region of interest.
Definition: MisrSetRegion.h:41
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.
Definition: MtkFileType.c:119
EXTERNL int nc_open(const char *path, int mode, int *ncidp)
MTKt_status MtkReadDataNC(const char *filename, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Definition: MtkReadData.c:113
#define FAIL
Definition: hdf.h:94

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:51