MISR Toolkit  1.5.1
MtkFileGridToResolution.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkFileGridToResolution =
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 "MisrError.h"
19 #include <mfhdf.h>
20 #include <HdfEosDef.h>
21 
36  const char *filename,
37  const char *gridname,
38  int *resolution )
39 {
40  MTKt_status status; /* Return status */
41 
42  status = MtkFileGridToResolutionNC(filename, gridname, resolution); // try netCDF
43  if (status != MTK_NETCDF_OPEN_FAILED) return status;
44 
45  return MtkFileGridToResolutionHDF(filename, gridname, resolution); // try HDF
46 }
47 
49  const char *filename,
50  const char *gridname,
51  int *resolution )
52 {
53  MTKt_status status_code; /* Return code of this function */
54  MTKt_status status; /* Return status */
55 
56  if (filename == NULL) return MTK_NULLPTR;
57 
58  /* Open file */
59  int ncid = 0;
60  {
61  int nc_status = nc_open(filename, NC_NOWRITE, &ncid);
63  }
64 
65  /* Get resolution of grid. */
66  status = MtkFileGridToResolutionNcid(ncid, gridname, resolution);
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  const char *gridname,
86  int *resolution )
87 {
88  MTKt_status status_code; /* Return code of this function */
89  MTKt_status status; /* Return status */
90  intn hdfstatus; /* HDF-EOS return status */
91  int32 fid = FAIL; /* HDF-EOS file identifier */
92 
93  if (filename == NULL)
95 
96  fid = GDopen((char *)filename, DFACC_READ);
98 
99  /* Get resolution of grid. */
100  status = MtkFileGridToResolutionFid(fid, gridname, resolution);
101  MTK_ERR_COND_JUMP(status);
102 
103  hdfstatus = GDclose(fid);
105  fid = FAIL;
106 
107  return MTK_SUCCESS;
108  ERROR_HANDLE:
109  if (fid != FAIL) GDclose(fid);
110  return status_code;
111 }
112 
119  int32 fid,
120  const char *gridname,
121  int *resolution )
122 {
123  MTKt_status status_code; /* Return code of this function */
124  intn hdfstatus; /* HDF-EOS return status */
125  int32 gid = FAIL; /* HDF-EOS grid identifier */
126  int32 res_x; /* Resolution in Som X */
127  int32 res_y; /* Resolution in Som Y */
128 
129  if (gridname == NULL || resolution == NULL)
131 
132  gid = GDattach(fid, (char *)gridname);
134 
135  hdfstatus = GDreadattr(gid, "Block_size.resolution_x", (void *)&res_x);
137 
138  hdfstatus = GDreadattr(gid, "Block_size.resolution_y", (void *)&res_y);
140 
141  hdfstatus = GDdetach(gid);
143 
144  if (res_x != res_y) MTK_ERR_CODE_JUMP(MTK_OUTBOUNDS);
145 
146  *resolution = res_x;
147 
148  return MTK_SUCCESS;
149  ERROR_HANDLE:
150  if (gid != FAIL) GDdetach(gid);
151  return status_code;
152 }
153 
155  int ncid,
156  const char *gridname,
157  int *resolution )
158 {
159  MTKt_status status_code; /* Return code of this function */
160 
161  if (gridname == NULL || resolution == NULL)
163 
164  int group_id;
165  {
166  int nc_status = nc_inq_grp_ncid(ncid, gridname, &group_id);
168  }
169 
170  int32 res;
171  {
172  int nc_status = nc_get_att(group_id, NC_GLOBAL, "resolution_in_meters", &res);
174  }
175 
176  *resolution = res;
177 
178  return MTK_SUCCESS;
179  ERROR_HANDLE:
180  return status_code;
181 }
MTKt_status MtkFileGridToResolution(const char *filename, const char *gridname, int *resolution)
Get resolution of a particular grid.
int32 GDattach(int32, char *)
#define DFACC_READ
Definition: hdf.h:44
char * filename
Definition: cdjpeg.h:133
intn GDreadattr(int32, char *, VOIDP)
intn GDclose(int32)
EXTERNL int nc_get_att(int ncid, int varid, const char *name, void *ip)
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
#define NC_GLOBAL
Definition: netcdf.h:214
intn GDdetach(int32)
MTKt_status MtkFileGridToResolutionFid(int32 fid, const char *gridname, int *resolution)
Version of MtkFileGridToResolution that takes an HDF-EOS file id rather than a filename.
#define NC_NOERR
Definition: netcdf.h:313
#define NC_NOWRITE
Definition: netcdf.h:201
MTKt_status MtkFileGridToResolutionHDF(const char *filename, const char *gridname, int *resolution)
MTKt_status MtkFileGridToResolutionNC(const char *filename, const char *gridname, int *resolution)
MTKt_status MtkFileGridToResolutionNcid(int ncid, const char *gridname, int *resolution)
#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)
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)
#define FAIL
Definition: hdf.h:94

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