MISR Toolkit  1.5.1
MtkFileToOrbit.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkFileToOrbit =
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 *orbit )
37 {
38  MTKt_status status; /* Return status */
39 
40  status = MtkFileToOrbitNC(filename, orbit); // try netCDF
41  if (status != MTK_NETCDF_OPEN_FAILED) return status;
42 
43  return MtkFileToOrbitHDF(filename, orbit); // try HDF
44 }
45 
47  int *orbit )
48 {
49  MTKt_status status_code; /* Return status 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 = MtkFileToOrbitNcid(ncid, orbit);
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 *orbit )
81 {
82  MTKt_status status_code; /* Return status of this function */
83  MTKt_status status; /* Return status */
84  int32 hdf_status; /* HDF-EOS return status */
85  int32 sd_id = FAIL; /* HDF SD file identifier. */
86 
87  if (filename == NULL)
89 
90  /* Open HDF File */
91  hdf_status = sd_id = SDstart(filename, DFACC_READ);
92  if (hdf_status == FAIL)
94 
95  /* Read orbit number. */
96  status = MtkFileToOrbitFid(sd_id, orbit);
97  MTK_ERR_COND_JUMP(status);
98 
99  /* Close HDF File */
100  hdf_status = SDend(sd_id);
101  if (hdf_status == FAIL)
103  sd_id = FAIL;
104 
105  return MTK_SUCCESS;
106 
107 ERROR_HANDLE:
108  if (sd_id != FAIL)
109  SDend(sd_id);
110 
111  return status_code;
112 }
113 
120  int *orbit )
121 {
122  MTKt_status status_code; /* Return status of this function */
123  MTKt_status status; /* Return status */
125  /* Core metadata structure */
126 
127  if (orbit == NULL)
129 
130  status = MtkFileCoreMetaDataGetFid(sd_id, "ORBITNUMBER", &metadata);
131  MTK_ERR_COND_JUMP(status);
132 
133  *orbit = metadata.data.i[0];
134 
135  MtkCoreMetaDataFree(&metadata);
136  return MTK_SUCCESS;
137 
138 ERROR_HANDLE:
139  MtkCoreMetaDataFree(&metadata);
140  return status_code;
141 }
142 
144  int *orbit )
145 {
146  MTKt_status status_code; /* Return status of this function */
147 
148  if (orbit == NULL)
150 
151  {
152  int nc_status = nc_get_att_int(ncid, NC_GLOBAL, "Orbit_number", orbit);
154  }
155 
156  return MTK_SUCCESS;
157 
158 ERROR_HANDLE:
159  return status_code;
160 }
#define DFACC_READ
Definition: hdf.h:44
char * filename
Definition: cdjpeg.h:133
union MtkCoreMetaData::@0 data
MTKt_status MtkFileCoreMetaDataGetFid(int32 sd_id, const char *param, MtkCoreMetaData *metadata)
Version of MtkFileCoreMetaDataGet that takes an HDF SD identifier rather than a filename.
MTKt_status MtkFileToOrbitNC(const char *filename, int *orbit)
MTKt_status MtkCoreMetaDataFree(MtkCoreMetaData *metadata)
Free core metadata.
EXTERNL int nc_get_att_int(int ncid, int varid, const char *name, int *ip)
#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)
MTKt_status MtkFileToOrbitNcid(int ncid, int *orbit)
#define NC_NOERR
Definition: netcdf.h:313
Core Metadata.
Definition: MisrFileQuery.h:57
MTKt_status MtkFileToOrbitFid(int32 sd_id, int *orbit)
Version of MtkFileToOrbit that takes an HDF SD file identifier rather than a filename.
#define MTK_CORE_METADATA_INIT
Definition: MisrFileQuery.h:72
MTKt_status MtkFileToOrbitHDF(const char *filename, int *orbit)
HDFLIBAPI intn SDend(int32 fid)
MTKt_status MtkFileToOrbit(const char *filename, int *orbit)
Read orbit number from file.
#define NC_NOWRITE
Definition: netcdf.h:201
#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