MISR Toolkit  1.5.1
MtkFileToPath.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkFileToPath =
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 <hdf.h>
20 #include <mfhdf.h>
21 
36  int *path )
37 {
38  MTKt_status status; /* Return status */
39 
40  status = MtkFileToPathNC(filename, path); // try netCDF
41  if (status != MTK_NETCDF_OPEN_FAILED) return status;
42 
43  return MtkFileToPathHDF(filename, path); // try HDF
44 }
45 
47  int *path )
48 {
49  MTKt_status status_code; /* Return code of this function */
50  MTKt_status status; /* Return status */
51 
52  if (filename == NULL) return MTK_NULLPTR;
53 
54  /* Open file */
55  int ncid = 0;
56  {
57  int nc_status = nc_open(filename, NC_NOWRITE, &ncid);
59  }
60 
61  /* Read grid attribute */
62  status = MtkFileToPathNcid(ncid, path);
63  MTK_ERR_COND_JUMP(status);
64 
65  /* Close file */
66  {
67  int nc_status = nc_close(ncid);
69  }
70  ncid = 0;
71 
72  return MTK_SUCCESS;
73 
74  ERROR_HANDLE:
75  if (ncid != 0) nc_close(ncid);
76  return status_code;
77 }
78 
80  int *path )
81 {
82  MTKt_status status_code; /* Return status of this function */
83  int32 sid = FAIL; /* HDF SD file identifier */
84  MTKt_status status; /* Return status */
85  intn hdfstatus; /* HDF return status */
86 
87  if (filename == NULL)
89 
90  sid = SDstart(filename, DFACC_READ);
91  if (sid == FAIL)
93 
94  /* Read path number. */
95  status = MtkFileToPathFid(sid, path);
96  MTK_ERR_COND_JUMP(status);
97 
98  hdfstatus = SDend(sid);
99  if (hdfstatus == FAIL)
101  sid = FAIL;
102 
103  return MTK_SUCCESS;
104 
105 ERROR_HANDLE:
106  if (sid != FAIL) {
107  hdfstatus = SDend(sid);
108  }
109  return status_code;
110 }
111 
118  int *path )
119 {
120  MTKt_status status_code; /* Return status of this function */
121  intn status; /* HDF return status */
122  int32 attr_index; /* HDF attribute index */
123  int32 path_tmp; /* Temp path number */
124 
125  if (path == NULL)
127 
128  attr_index = SDfindattr(sid, "Path_number");
129  if (attr_index == FAIL)
131 
132  status = SDreadattr(sid, attr_index, &path_tmp);
133  if (status == FAIL)
135 
136  *path = path_tmp;
137 
138  return MTK_SUCCESS;
139 
140 ERROR_HANDLE:
141  return status_code;
142 }
143 
145  int *path )
146 {
147  MTKt_status status_code; /* Return status of this function */
148 
149  if (path == NULL)
151 
152  int path_tmp;
153  {
154  int nc_status = nc_get_att(ncid, NC_GLOBAL, "Path_number", &path_tmp);
156  }
157 
158  *path = path_tmp;
159 
160  return MTK_SUCCESS;
161 
162 ERROR_HANDLE:
163  return status_code;
164 }
MTKt_status MtkFileToPathFid(int32 sid, int *path)
Version of MtkFileToPath that takes an HDF SD identifier rather than a filename.
MTKt_status MtkFileToPath(const char *filename, int *path)
Read path number from file.
Definition: MtkFileToPath.c:35
#define DFACC_READ
Definition: hdf.h:44
char * filename
Definition: cdjpeg.h:133
EXTERNL int nc_get_att(int ncid, int varid, const char *name, void *ip)
MTKt_status MtkFileToPathNcid(int ncid, int *path)
MTKt_status MtkFileToPathHDF(const char *filename, int *path)
Definition: MtkFileToPath.c:79
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
#define NC_GLOBAL
Definition: netcdf.h:214
HDFLIBAPI int32 SDstart(const char *name, int32 accs)
#define NC_NOERR
Definition: netcdf.h:313
HDFLIBAPI intn SDreadattr(int32 id, int32 idx, void *buf)
HDFLIBAPI intn SDend(int32 fid)
#define NC_NOWRITE
Definition: netcdf.h:201
HDFLIBAPI int32 SDfindattr(int32 id, const char *attrname)
#define MTK_ERR_COND_JUMP(code)
Definition: MisrError.h:188
MTKt_status
Definition: MisrError.h:11
EXTERNL int nc_close(int ncid)
MTKt_status MtkFileToPathNC(const char *filename, int *path)
Definition: MtkFileToPath.c:46
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