MISR Toolkit  1.5.1
MtkFileType.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkFileType =
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 "MisrFileQuery.h"
18 #include "MisrUtil.h"
19 #include "MisrError.h"
20 #include <hdf.h>
21 #include <HdfEosDef.h>
22 #include <string.h>
23 
38  const char *filename,
39  MTKt_FileType *filetype )
40 {
41  MTKt_status status; /* Return status */
42 
43  status = MtkFileTypeNC(filename, filetype); // try netCDF
44  if (status != MTK_NETCDF_OPEN_FAILED) return status;
45 
46  return MtkFileTypeHDF(filename, filetype); // try HDF
47 }
48 
50  const char *filename,
51  MTKt_FileType *filetype )
52 {
53  MTKt_status status;
54  MTKt_status status_code;
55  int ncid = 0;
56 
57  if (filename == NULL) MTK_ERR_CODE_JUMP(MTK_NULLPTR);
58 
59  /* Open file */
60  {
61  int nc_status = nc_open(filename, NC_NOWRITE, &ncid);
63  }
64 
65  /* Determine MISR product file type */
66  status = MtkFileTypeNcid(ncid, filetype);
67  MTK_ERR_COND_JUMP(status);
68 
69  /* Close file */
70  {
71  int nc_status = nc_close(ncid);
73  }
74  ncid = 0;
75 
76  return MTK_SUCCESS;
77 
78  ERROR_HANDLE:
79  if (ncid != 0) nc_close(ncid);
80  return status_code;
81 }
82 
84  const char *filename,
85  MTKt_FileType *filetype )
86 {
87  MTKt_status status;
88  MTKt_status status_code;
89  intn hdf_status;
90  int32 fid = FAIL;
91 
92  if (filename == NULL)
94 
95  fid = GDopen((char *)filename, DFACC_READ);
97 
98  /* Determine MISR product file type */
99  status = MtkFileTypeFid(fid, filetype);
100  MTK_ERR_COND_JUMP(status);
101 
102  hdf_status = GDclose(fid);
103  if (hdf_status == FAIL)
105  fid = FAIL;
106 
107  return MTK_SUCCESS;
108 
109 ERROR_HANDLE:
110  if (fid != FAIL) GDclose(fid);
111  return status_code;
112 }
113 
120  int32 Fid,
121  MTKt_FileType *filetype )
122 {
123  MTKt_status status;
124  MTKt_status status_code;
125  intn hdf_status;
126  char *lgid;
127  char *fn_start;
128  int num_grids;
129  char **gridlist = NULL;
130  int32 gridID;
131  int32 projcode;
132  int32 zonecode;
133  int32 spherecode;
134  float64 projparm[13];
135  int32 sid; /* HDF SD identifier (required by MtkFileLGID) */
136  int32 HDFfid; /* HDF file identifier (not used) */
137 
138  if (filetype == NULL)
140 
141  /* It's possible for a file to have both conventional and stacked-block
142  format in the same file but this is not used for MISR so only the
143  first grid in the file is checked. */
144 
145  status = MtkFileToGridListFid(Fid,&num_grids,&gridlist);
146  if (status != MTK_SUCCESS)
147  MTK_ERR_CODE_JUMP(status);
148 
149  hdf_status = gridID = GDattach(Fid,gridlist[0]);
150  if (hdf_status == FAIL)
152 
153  hdf_status = GDprojinfo(gridID,&projcode,&zonecode,&spherecode,projparm);
154  if (hdf_status == FAIL)
156 
157  hdf_status = GDdetach(gridID);
158  if (hdf_status == FAIL)
160 
161  MtkStringListFree(num_grids, &gridlist);
162 
163  if (projparm[11] == 0)
164  {
165  *filetype = MTK_CONVENTIONAL;
166 
167  /* Check if MISR_HR product */
168  hdf_status = EHidinfo(Fid, &HDFfid, &sid);
169  if (hdf_status == FAIL)
170  return MTK_SUCCESS;
171 
172  /* Get Local Granual ID */
173  status = MtkFileLGIDFid(sid,&lgid);
174  if (status != MTK_SUCCESS)
175  return MTK_SUCCESS;
176 
177  fn_start = strstr(lgid, "MISR_HR_");
178  if (fn_start == NULL)
179  return MTK_SUCCESS;
180 
181  fn_start += 8; /* Skip MISR_HR_ */
182 
183  /* Determine file type */
184  if (strncmp(fn_start,"BRF",3) == 0)
185  *filetype = MTK_HR_BRF;
186  else if (strncmp(fn_start,"RPV",3) == 0)
187  *filetype = MTK_HR_RPV;
188  else if (strncmp(fn_start,"TIP",3) == 0)
189  *filetype = MTK_HR_TIP;
190  else
191  *filetype = MTK_UNKNOWN;
192 
193  free(lgid);
194 
195  return MTK_SUCCESS;
196  }
197 
198  /* Determine type of stacked-block product */
199 
200  /* Get the HDF SD identifier. */
201  hdf_status = EHidinfo(Fid, &HDFfid, &sid);
202  if (hdf_status == FAIL)
204 
205  /* Get Local Granual ID */
206  status = MtkFileLGIDFid(sid,&lgid);
207  if (status != MTK_SUCCESS)
208  MTK_ERR_CODE_JUMP(status);
209 
210  fn_start = strstr(lgid, "MISR_AM1_");
211  if (fn_start == NULL)
213 
214  fn_start += 9; /* Skip MISR_AM1_ */
215 
216  /* Determine file type */
217  if (strncmp(fn_start,"AGP",3) == 0)
218  *filetype = MTK_AGP;
219  else if (strncmp(fn_start,"GP_GMP",6) == 0)
220  *filetype = MTK_GP_GMP;
221  else if (strncmp(fn_start,"GRP_RCCM",8) == 0)
222  *filetype = MTK_GRP_RCCM;
223  else if (strncmp(fn_start,"GRP_ELLIPSOID_GM",16) == 0)
224  *filetype = MTK_GRP_ELLIPSOID_GM;
225  else if (strncmp(fn_start,"GRP_TERRAIN_GM",14) == 0)
226  *filetype = MTK_GRP_TERRAIN_GM;
227  else if (strncmp(fn_start,"GRP_ELLIPSOID_LM",16) == 0)
228  *filetype = MTK_GRP_ELLIPSOID_LM;
229  else if (strncmp(fn_start,"GRP_TERRAIN_LM",14) == 0)
230  *filetype = MTK_GRP_TERRAIN_LM;
231  else if (strncmp(fn_start,"AS_AEROSOL",10) == 0)
232  *filetype = MTK_AS_AEROSOL;
233  else if (strncmp(fn_start,"AS_LAND",7) == 0)
234  *filetype = MTK_AS_LAND;
235  else if (strncmp(fn_start,"TC_ALBEDO",9) == 0)
236  *filetype = MTK_TC_ALBEDO;
237  else if (strncmp(fn_start,"TC_CLASSIFIERS",14) == 0)
238  *filetype = MTK_TC_CLASSIFIERS;
239  else if (strncmp(fn_start,"TC_STEREO",9) == 0)
240  *filetype = MTK_TC_STEREO;
241  else if (strncmp(fn_start,"PGRP_ELLIPSOID_GM",17) == 0)
242  *filetype = MTK_GRP_ELLIPSOID_GM;
243  else if (strncmp(fn_start,"PGRP_TERRAIN_GM",15) == 0)
244  *filetype = MTK_GRP_TERRAIN_GM;
245  else if (strncmp(fn_start,"PP",2) == 0)
246  *filetype = MTK_PP;
247  else if (strncmp(fn_start,"TC_CLOUD",8) == 0)
248  *filetype = MTK_TC_CLOUD;
249  else if (strncmp(fn_start,"CMV_T",5) == 0)
250  *filetype = MTK_CMV_NRT;
251  else
252  *filetype = MTK_UNKNOWN;
253 
254  free(lgid);
255 
256  return MTK_SUCCESS;
257 
258 ERROR_HANDLE:
259  if (gridlist != NULL)
260  MtkStringListFree(num_grids, &gridlist);
261 
262  return status_code;
263 
264 }
265 
267  int ncid,
268  MTKt_FileType *filetype )
269 {
270  MTKt_status status;
271  MTKt_status status_code;
272 
273  if (filetype == NULL)
275 
276  /* Get Local Granual ID */
277 
278  char *lgid;
279  status = MtkFileLGIDNcid(ncid,&lgid);
280  if (status != MTK_SUCCESS) MTK_ERR_CODE_JUMP(status);
281 
282  char *fn_start = strstr(lgid, "MISR_AM1_");
283  if (fn_start == NULL)
285 
286  fn_start += 9; /* Skip MISR_AM1_ */
287 
288  /* Determine file type */
289  if (strncmp(fn_start,"AS_AEROSOL",10) == 0)
290  *filetype = MTK_AS_AEROSOL;
291  else if (strncmp(fn_start,"AS_LAND",7) == 0)
292  *filetype = MTK_AS_LAND;
293  else
294  *filetype = MTK_UNKNOWN;
295 
296  free(lgid);
297 
298  return MTK_SUCCESS;
299 
300 ERROR_HANDLE:
301  return status_code;
302 
303 }
MTKt_status MtkStringListFree(int strcnt, char **strlist[])
Free string list.
int32 GDattach(int32, char *)
#define DFACC_READ
Definition: hdf.h:44
char * filename
Definition: cdjpeg.h:133
MTKt_status MtkFileTypeHDF(const char *filename, MTKt_FileType *filetype)
Definition: MtkFileType.c:83
intn GDclose(int32)
MTKt_status MtkFileType(const char *filename, MTKt_FileType *filetype)
Determine MISR product file type.
Definition: MtkFileType.c:37
MTKt_status MtkFileLGIDNcid(int ncid, char **lgid)
Definition: MtkFileLGID.c:195
intn GDprojinfo(int32, int32 *, int32 *, int32 *, float64 [])
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
MTKt_FileType
Definition: MisrFileQuery.h:24
intn GDdetach(int32)
#define NC_NOERR
Definition: netcdf.h:313
MTKt_status MtkFileTypeNC(const char *filename, MTKt_FileType *filetype)
Definition: MtkFileType.c:49
#define NC_NOWRITE
Definition: netcdf.h:201
intn EHidinfo(int32, int32 *, int32 *)
MTKt_status MtkFileLGIDFid(int32 sds_id, char **lgid)
Version of MtkFileLGID that takes an HDF SDS ID rather than a filename.
Definition: MtkFileLGID.c:129
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
MTKt_status MtkFileTypeNcid(int ncid, MTKt_FileType *filetype)
Definition: MtkFileType.c:266
#define MTK_ERR_COND_JUMP(code)
Definition: MisrError.h:188
MTKt_status
Definition: MisrError.h:11
int32 GDopen(char *, intn)
EXTERNL int nc_close(int ncid)
MTKt_status MtkFileToGridListFid(int32 fid, int *ngrids, char **gridlist[])
Version of MtkFileToGridList that takes an HDF-EOS file identifier rather than a filename.
EXTERNL int nc_open(const char *path, int mode, int *ncidp)
#define FAIL
Definition: hdf.h:94

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