OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
hdf4utils.h
Go to the documentation of this file.
1 #ifndef HDF4UTILS_H
2 #define HDF4UTILS_H
3 
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <stdint.h>
7 #include <string.h>
8 #include <productInfo.h>
9 #include <passthebuck.h>
10 
11 #define HDF4_UTILS_MAX_NAME 256
12 #define HDF4_UTILS_MAX_DIM 32
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
19 int32_t hdf_sizeof(int32_t dtype);
20 
21 char *GetFileDesc(const char *filename);
22 
23 int CreateSDS(
24  int32_t sd_id,
25  const char *sname, /* short name */
26  const char *lname, /* long name */
27  const char *standard_name, /* NetCDF standard name (not set if passed NULL or "") */
28  const char *units, /* units (not set if passed NULL or "") */
29  double low, /* low end of valid range */
30  double high, /* high end of range (no range set if low >= high) */
31  float slope, /* scale factor (not set if 0) */
32  float offset, /* scaling offset (not set if 0) */
33  int32_t nt, /* HDF number type */
34  int32_t rank, /* number of dimensions (must be <= 3) */
35  int32_t d0, /* size of 1st dimension */
36  int32_t d1, /* size of 2nd dimension */
37  int32_t d2, /* size of 3rd dimension (1 if rank < 2) */
38  const char *dn0, /* name of 1st dimension */
39  const char *dn1, /* name of 2nd dimension (NULL if rank < 2) */
40  const char *dn2 /* name of 3rd dimension (NULL if rank < 3) */
41  );
42 int sd_create(int32_t id, const char *nam, int32_t typ, int32_t rank, int32_t d0,
43  int32_t d1, int32_t d2, int32_t *sds_id);
44 int sd_select(int32_t sd_id, const char *name, int32_t *sds_id);
45 int sd_endaccess(int32_t id);
46 int sd_setdimnames(int32_t id, const char *d0, const char *d1, const char *d2);
47 int sd_setdimname(int32_t sds_id, int32_t dim_number, const char *name);
48 int sd_setattr(int32_t id, const char *nam, int32_t typ, int32_t cnt, const void* data);
49 int sd_readdata(int32_t sd_id, const char *name, void* data, int32_t s0, int32_t s1,
50  int32_t s2, int32_t e0, int32_t e1, int32_t e2);
51 int sd_writedata(int32_t sd_id, const char *name, const void* data, int32_t s0,
52  int32_t s1, int32_t s2, int32_t e0, int32_t e1, int32_t e2);
53 int AddSdsToVgroup(int32_t sd_id, int32_t v_id, const char *name);
54 int v_attach(int32_t h_id, int32_t *v_id);
55 int getDims(int32_t fileID, const char sdsname[], int32_t dims[]);
56 int get_type(int32_t fileID, const char sdsname[], int32_t *dtype);
57 int rdSDS(int32_t fileID, const char sdsname[], int32_t start1, int32_t start2,
58  int32_t edges1, int32_t edges2, void* array_data);
59 int getHDFattr(int32_t fileID, const char attrname[], const char sdsname[],
60  void* data);
61 int32_t read_SDS(int32_t sdfid, const char *sds_name, void *buffer);
62 int attach_vdata(int32_t fid, const char *sname);
63 
64 int rdvdata(int32_t vskey, const char *fields, int32_t start, int32_t nelt,
65  unsigned char *databuf);
66 
67 #define READ_GLBL_ATTR(nam,ptr) { \
68  if(SDreadattr(sd_id,SDfindattr(sd_id,(nam)),(void*)(ptr))){ \
69  fprintf(stderr, \
70  "-E- %s line %d: Could not get global attribute, %s.\n", \
71  __FILE__,__LINE__,(nam)); \
72  } \
73 }
74 
75 #define READ_GLBL_ATTR_E(nam,ptr) { \
76  if(SDreadattr(sd_id,SDfindattr(sd_id,(nam)),(void*)(ptr))){ \
77  fprintf(stderr, \
78  "-E- %s line %d: Could not get global attribute, %s.\n", \
79  __FILE__,__LINE__,(nam)); \
80  exit(1); \
81  } \
82 }
83 
84 #define READ_SDS(nam,ptr,s0,s1,s2,e0,e1,e2) { \
85  int32_t start[3]; \
86  int32_t edge[3]; \
87  edge[0]=(e0); edge[1]=(e1); edge[2]=(e2); \
88  start[0]=(s0); start[1]=(s1); start[2]=(s2); \
89  if(SDreaddata(SDselect(sd_id, SDnametoindex(sd_id, (nam))), \
90  start, NULL, edge, (void*)(ptr)) == FAIL){ \
91  fprintf(stderr,"-E- %s line %d: Could not read SDS, %s.\n", \
92  __FILE__,__LINE__,(nam)); \
93  } \
94 }
95 
96 #define READ_SDS_E(nam,ptr,s0,s1,s2,e0,e1,e2) { \
97  int32_t start[3]; \
98  int32_t edge[3]; \
99  edge[0]=(e0); edge[1]=(e1); edge[2]=(e2); \
100  start[0]=(s0); start[1]=(s1); start[2]=(s2); \
101  if(SDreaddata(SDselect(sd_id, SDnametoindex(sd_id, (nam))), \
102  start, NULL, edge, (void*)(ptr)) == FAIL){ \
103  fprintf(stderr,"-E- %s line %d: Could not read SDS, %s.\n", \
104  __FILE__,__LINE__,(nam)); \
105  exit(1); \
106  } \
107 }
108 
109 #define READ_SDS_ID(sd_id,nam,ptr,s0,s1,s2,s3,e0,e1,e2,e3) { \
110  int32_t start[4]; \
111  int32_t edge[4]; \
112  edge[0]=(e0); edge[1]=(e1); edge[2]=(e2); edge[3]=(e3); \
113  start[0]=(s0); start[1]=(s1); start[2]=(s2); start[3]=(s3); \
114  if(SDreaddata(SDselect((sd_id), SDnametoindex((sd_id), (nam))), \
115  start, NULL, edge, (void*)(ptr)) == FAIL){ \
116  fprintf(stderr,"-E- %s line %d: Could not read SDS, %s.\n", \
117  __FILE__,__LINE__,(nam)); \
118  } \
119 }
120 
121 #define READ_SDS_ID_E(sd_id,nam,ptr,s0,s1,s2,s3,e0,e1,e2,e3) { \
122  int32_t start[4]; \
123  int32_t edge[4]; \
124  edge[0]=(e0); edge[1]=(e1); edge[2]=(e2); edge[3]=(e3); \
125  start[0]=(s0); start[1]=(s1); start[2]=(s2); start[3]=(s3); \
126  if(SDreaddata(SDselect((sd_id), SDnametoindex((sd_id), (nam))), \
127  start, NULL, edge, (void*)(ptr)) == FAIL){ \
128  fprintf(stderr,"-E- %s line %d: Could not read SDS, %s.\n", \
129  __FILE__,__LINE__,(nam)); \
130  exit(1); \
131  } \
132 }
133 
134 /*
135  * below here are the functions that used to be in hdf4_utils.h
136  */
137 
138 typedef struct att_info_struct {
139  int32_t id; /* HDF4 identifier for parent object */
140  int32_t index; /* index of attribute within parent */
141  char name[HDF4_UTILS_MAX_NAME]; /* name of the attribute */
142  int32_t nvals; /* number of values */
143  int32_t ntype; /* number type for stored data (hntdefs.h) */
144  void *data; /* pointer to data */
145 } att_struct;
146 
147 typedef struct sds_info_struct {
148  int32_t id; /* HDF4 Science Data Set identifier */
149  char name[HDF4_UTILS_MAX_NAME]; /* name of the HDF4 data set */
150  int32_t ndims; /* number of dimensions */
151  int32_t dimlen[HDF4_UTILS_MAX_DIM]; /* dimension lengths */
152  int32_t ntype; /* number type for stored data (hntdefs.h) */
153  int32_t nvals; /* number of values in data */
154  void *data; /* pointer to data */
155  int32_t natts; /* number of attributes */
156  att_struct *atts; /* pointer to array of attributes */
157 } sds_struct;
158 
159 const char *hdf_typename(const int32_t ntype);
160 char *fmt_hdf_val(const void *array, const int32_t i, const int32_t ntype);
161 void fopen_warn(const char *filename, const char *file, int32_t const line);
162 void fopen_err(const char *filename, const char *file, int32_t const line);
163 
164 int init_sds_byname(int32_t fileid, const char *sdsname, sds_struct *sds);
165 int readall_sds(sds_struct *sds);
166 void free_sds(sds_struct *sds);
167 void print_sds_info(const sds_struct sds);
168 
169 int load_att_byname(int32_t obj_id, const char *attname, att_struct *att);
170 void print_att_vals(const att_struct att);
171 void print_att_info(const att_struct att);
172 
173 #define EOSMETALEN 32768
174 int parse_odl(const char *odltext, const char *object, char *value);
175 int get_hdfeos_meta(int32_t sd_id, char *attribute, char *name, char *data);
176 
177 #define read_att(obj_id,attname,valptr) \
178  SDreadattr(obj_id, \
179  SDfindattr(obj_id,attname), \
180  (void *) valptr)
181 
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 
187 
188 #endif
int v_attach(int32_t h_id, int32_t *v_id)
Definition: hdf_utils.c:404
int sd_setdimname(int32_t sds_id, int32_t dim_number, const char *name)
Definition: hdf_utils.c:275
int CreateSDS(int32_t sd_id, const char *sname, const char *lname, const char *standard_name, const char *units, double low, double high, float slope, float offset, int32_t nt, int32_t rank, int32_t d0, int32_t d1, int32_t d2, const char *dn0, const char *dn1, const char *dn2)
Definition: hdf_utils.c:77
int32 value
Definition: Granule.c:1235
char * GetFileDesc(const char *filename)
Definition: hdf_utils.c:752
char * fmt_hdf_val(const void *array, const int32_t i, const int32_t ntype)
Definition: hdf4_utils.c:211
void print_att_info(const att_struct att)
Definition: hdf4_utils.c:37
int rdSDS(int32_t fileID, const char sdsname[], int32_t start1, int32_t start2, int32_t edges1, int32_t edges2, void *array_data)
int sd_select(int32_t sd_id, const char *name, int32_t *sds_id)
Definition: hdf_utils.c:355
int16_t fileID
int32_t hdf_sizeof(int32_t dtype)
return the sizeof dtype in bytes
Definition: hdf_utils.c:28
int32_t nvals
Definition: hdf4utils.h:153
int32_t ntype
Definition: hdf4utils.h:143
int32_t ntype
Definition: hdf4utils.h:152
int sd_readdata(int32_t sd_id, const char *name, void *data, int32_t s0, int32_t s1, int32_t s2, int32_t e0, int32_t e1, int32_t e2)
char name[HDF4_UTILS_MAX_NAME]
Definition: hdf4utils.h:149
int attach_vdata(int32_t fid, const char *sname)
char name[HDF4_UTILS_MAX_NAME]
Definition: hdf4utils.h:141
int init_sds_byname(int32_t fileid, const char *sdsname, sds_struct *sds)
Definition: hdf4_utils.c:92
void fopen_warn(const char *filename, const char *file, int32_t const line)
Definition: hdf4_utils.c:261
int32_t dimlen[HDF4_UTILS_MAX_DIM]
Definition: hdf4utils.h:151
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed file
Definition: HISTORY.txt:413
void fopen_err(const char *filename, const char *file, int32_t const line)
Definition: hdf4_utils.c:266
const char * hdf_typename(const int32_t ntype)
Definition: hdf4_utils.c:189
int sd_setattr(int32_t id, const char *nam, int32_t typ, int32_t cnt, const void *data)
Definition: hdf_utils.c:216
int32_t ndims
Definition: hdf4utils.h:150
int getDims(int32_t fileID, const char sdsname[], int32_t dims[])
void print_att_vals(const att_struct att)
Definition: hdf4_utils.c:50
int get_hdfeos_meta(int32_t sd_id, char *attribute, char *name, char *data)
Definition: hdf4_utils.c:326
float32 slope[]
Definition: l2lists.h:30
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE fields
Definition: HISTORY.txt:400
int getHDFattr(int32_t fileID, const char attrname[], const char sdsname[], void *data)
int sd_setdimnames(int32_t id, const char *d0, const char *d1, const char *d2)
Definition: hdf_utils.c:264
char filename[FILENAME_MAX]
Definition: atrem_corl1.h:122
void free_sds(sds_struct *sds)
Definition: hdf4_utils.c:161
int sd_create(int32_t id, const char *nam, int32_t typ, int32_t rank, int32_t d0, int32_t d1, int32_t d2, int32_t *sds_id)
Definition: hdf_utils.c:227
int get_type(int32_t fileID, const char sdsname[], int32_t *dtype)
int readall_sds(sds_struct *sds)
Definition: hdf4_utils.c:138
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
Definition: HISTORY.txt:356
int rdvdata(int32_t vskey, const char *fields, int32_t start, int32_t nelt, unsigned char *databuf)
int32_t read_SDS(int32_t sdfid, const char *sds_name, void *buffer)
#define HDF4_UTILS_MAX_DIM
Definition: hdf4utils.h:12
int parse_odl(const char *odltext, const char *object, char *value)
Definition: hdf4_utils.c:274
int32_t nvals
Definition: hdf4utils.h:142
dtype
Definition: DDataset.hpp:31
Extra metadata that will be written to the HDF4 file l2prod rank
int32_t natts
Definition: hdf4utils.h:155
int AddSdsToVgroup(int32_t sd_id, int32_t v_id, const char *name)
Definition: hdf_utils.c:383
int sd_writedata(int32_t sd_id, const char *name, const void *data, int32_t s0, int32_t s1, int32_t s2, int32_t e0, int32_t e1, int32_t e2)
Definition: hdf_utils.c:293
#define HDF4_UTILS_MAX_NAME
Definition: hdf4utils.h:11
l2prod offset
These two strings are used for the product XML output If product_id is not set then prefix is used If the last char of the name_prefix is _ then it is removed If algorithm_id is not set then name_suffix is used If the first char is _ then it is removed l2prod standard_name[0]
int load_att_byname(int32_t obj_id, const char *attname, att_struct *att)
Definition: hdf4_utils.c:31
int i
Definition: decode_rs.h:71
int32_t index
Definition: hdf4utils.h:140
void print_sds_info(const sds_struct sds)
Definition: hdf4_utils.c:103
int sd_endaccess(int32_t id)
Definition: hdf_utils.c:255
att_struct * atts
Definition: hdf4utils.h:156