MISR Toolkit  1.5.1
MtkFileVersion.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkFileVersion =
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 <string.h>
20 #include <mfhdf.h>
21 
36  const char *filename,
37  char *fileversion )
38 {
39  MTKt_status status; /* Return status */
40 
41  status = MtkFileVersionNC(filename, fileversion); // try netCDF
42  if (status != MTK_NETCDF_OPEN_FAILED) return status;
43 
44  return MtkFileVersionHDF(filename, fileversion); // try HDF
45 }
46 
48  const char *filename,
49  char *fileversion )
50 {
51  MTKt_status status_code; /* Return status of this function */
52  MTKt_status status; /* Return status */
53 
54  if (filename == NULL) return MTK_NULLPTR;
55 
56  /* Open file */
57  int ncid = 0;
58  {
59  int nc_status = nc_open(filename, NC_NOWRITE, &ncid);
61  }
62 
63  /* Read grid attribute */
64  status = MtkFileVersionNcid(ncid,fileversion);
65  MTK_ERR_COND_JUMP(status);
66 
67  /* Close file */
68  {
69  int nc_status = nc_close(ncid);
71  }
72  ncid = 0;
73 
74  return MTK_SUCCESS;
75 
76  ERROR_HANDLE:
77  if (ncid != 0) nc_close(ncid);
78  return status_code;
79 }
80 
82  const char *filename,
83  char *fileversion )
84 {
85  MTKt_status status_code;
86  MTKt_status status;
87  int32 hdf_status; /* HDF-EOS return status */
88  int32 sd_id = FAIL; /* HDF SD file identifier. */
89 
90  if (filename == NULL)
92 
93  /* Open HDF File */
94  hdf_status = sd_id = SDstart(filename, DFACC_READ);
95  if (hdf_status == FAIL)
97 
98  /* Read MISR product file version */
99  status = MtkFileVersionFid(sd_id,fileversion);
100  MTK_ERR_COND_JUMP(status);
101 
102  /* Close HDF File */
103  hdf_status = SDend(sd_id);
104  if (hdf_status == FAIL)
106  sd_id = FAIL;
107 
108  return MTK_SUCCESS;
109 
110 ERROR_HANDLE:
111  if (sd_id != FAIL)
112  SDend(sd_id);
113 
114  return status_code;
115 }
116 
123  int32 sd_id,
124  char *fileversion )
125 {
126  MTKt_status status_code;
127  MTKt_status status;
128  char *lgid;
129  char *fn_end;
130  char *fn_start;
131 
132  if (fileversion == NULL)
134 
135  /* Get Local Granual ID */
136  status = MtkFileLGIDFid(sd_id,&lgid);
137  if (status != MTK_SUCCESS)
138  MTK_ERR_CODE_JUMP(status);
139 
140  fn_end = strchr(lgid,'b'); /* check if file is a subset */
141  if (fn_end != NULL)
142  --fn_end; /* remove . before b */
143  else /* Remove .hdf from end */
144  fn_end = strstr(lgid, ".hdf");
145 
146  fn_start = fn_end;
147  while (*fn_start != 'F')
148  --fn_start;
149 
150 
151  strncpy(fileversion,fn_start,fn_end - fn_start);
152  fileversion[fn_end - fn_start] = '\0';
153 
154  free(lgid);
155 
156  return MTK_SUCCESS;
157 
158 ERROR_HANDLE:
159  return status_code;
160 }
161 
163  int ncid,
164  char *fileversion )
165 {
166  MTKt_status status_code;
167  MTKt_status status;
168  char *lgid;
169  char *fn_end;
170  char *fn_start;
171 
172  if (fileversion == NULL)
174 
175  /* Get Local Granual ID */
176  status = MtkFileLGIDNcid(ncid,&lgid);
177  if (status != MTK_SUCCESS)
178  MTK_ERR_CODE_JUMP(status);
179 
180  fn_end = strstr(lgid,".b"); /* check if file is a subset */
181  if (fn_end == NULL)
182  fn_end = strstr(lgid, ".nc");
183 
184  fn_start = fn_end;
185  while (*fn_start != 'F')
186  --fn_start;
187 
188  strncpy(fileversion,fn_start,fn_end - fn_start);
189  fileversion[fn_end - fn_start] = '\0';
190 
191  free(lgid);
192 
193  return MTK_SUCCESS;
194 
195 ERROR_HANDLE:
196  return status_code;
197 }
MTKt_status MtkFileVersionHDF(const char *filename, char *fileversion)
MTKt_status MtkFileVersionNC(const char *filename, char *fileversion)
#define DFACC_READ
Definition: hdf.h:44
char * filename
Definition: cdjpeg.h:133
MTKt_status MtkFileLGIDNcid(int ncid, char **lgid)
Definition: MtkFileLGID.c:195
MTKt_status MtkFileVersionNcid(int ncid, char *fileversion)
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
HDFLIBAPI int32 SDstart(const char *name, int32 accs)
#define NC_NOERR
Definition: netcdf.h:313
HDFLIBAPI intn SDend(int32 fid)
MTKt_status MtkFileVersion(const char *filename, char *fileversion)
Determine MISR product file version.
#define NC_NOWRITE
Definition: netcdf.h:201
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 MtkFileVersionFid(int32 sd_id, char *fileversion)
Version of MtkFileVersion that takes an HDF SD file identifier rather than a filename.
#define MTK_ERR_COND_JUMP(code)
Definition: MisrError.h:188
MTKt_status
Definition: MisrError.h:11
EXTERNL int nc_close(int 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