OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
dfutils.h
Go to the documentation of this file.
1 /*
2  * File: dfutils.h
3  * Author: dshea
4  *
5  * Created on May 11, 2015, 10:44 AM
6  */
7 
8 #ifndef DFUTILS_H
9 #define DFUTILS_H
10 
11 #include <hdf4utils.h>
12 
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 typedef enum {
19  DS_HDF, // use a HDF file
20  DS_NCDF // use a netCDF file
21 } ds_format_t;
22 
23 typedef enum {
24  DS_READ, // open file for reading
25  DS_WRITE // open/create file for writing
26 } ds_access_t;
27 
28 typedef struct {
29  int32_t fid;
30  int32_t sid;
32  int32_t deflate;
33 } idDS;
34 
35 
36 int s2u(const char *in, char *out);
37 int getProdlist(const char *fname, char **prodlist, int32_t *l2_flags_type);
38 
39 idDS startDS(const char *filename, ds_format_t format,
40  ds_access_t accessmode, int32_t deflate);
41 idDS openDS(const char *filename);
42 int endDS(idDS ds_id);
43 
44 #if 0
45 int createDS(
46  idDS ds_id,
47  const char *sname, /* short name */
48  const char *lname, /* long name */
49  const char *standard_name, /* NetCDF standard name (not set if passed NULL or "") */
50  char *reference;
51  const char *units, /* units (not set if passed NULL or "") */
52  double low, /* low end of valid range */
53  double high, /* high end of range (no range set if low >= high) */
54  float slope, /* scale factor (not set if 0) */
55  float offset, /* scaling offset (not set if 0) */
56  int32 nt, /* HDF number type */
57  int32 rank, /* number of dimensions (must be <= 3) */
58  int32 d0, /* size of 1st dimension */
59  int32 d1, /* size of 2nd dimension */
60  int32 d2, /* size of 3rd dimension (1 if rank < 2) */
61  const char *dn0, /* name of 1st dimension */
62  const char *dn1, /* name of 2nd dimension (NULL if rank < 2) */
63  const char *dn2 /* name of 3rd dimension (NULL if rank < 3) */
64  );
65 #endif
66 
67 int createDS(
68  idDS ds_id, int sensorId,
69  const char *sname, /* short name */
70  int32_t dm[3], /* dimension sizes */
71  const char dm_name[3][80] /* dimension names */
72  );
73 
75 int createDS2(idDS ds_id,
76  const char *sname,
77  productInfo_t* pinfo,
78  int32_t dm[3],
79  const char dm_name[3][80]
80  );
81 
82 int32_t selectDS(idDS ds_id, const char *l2_prod_names);
83 int32_t checkDS(idDS ds_id, const char *l2_prod_name);
84 int readDS(idDS ds_id, const char *name, int32_t *start, int32_t *stride,
85  int32_t *count, void* data);
86 int writeDS(idDS ds_id, const char *name, const void* data, int32_t s0, int32_t s1,
87  int32_t s2, int32_t e0, int32_t e1, int32_t e2);
88 int endaccessDS(idDS ds_id);
89 
90 int fileInfo(idDS ds_id, int32_t *n_datasets, int32_t *n_globalattr);
91 int getDimsDS(idDS ds_id, const char sdsname[], int32_t dims[]);
92 int getTypeDS(idDS ds_id, const char sdsname[HDF4_UTILS_MAX_NAME], int32_t *dtype);
93 
94 int setAttr(idDS ds_id, const char *nam, int32_t typ, int32_t cnt, const void* data);
95 int8_t findAttr(idDS ds_id, const char *nam);
96 int readAttr(idDS ds_id, const char *nam, void* data);
97 char* readAttrStr(idDS ds_id, const char *name);
98 int infoAttr(idDS ds_id, const char *nam, int32_t *dtype, int32_t *count);
99 
100 int SetChrGA(idDS ds_id, const char *name, const char *value);
101 int SetF32GA(idDS ds_id, const char *name, float value);
102 int SetF64GA(idDS ds_id, const char *name, double value);
103 int SetI8GA(idDS ds_id, const char *name, uint8_t value);
104 int SetI16GA(idDS ds_id, const char *name, int16_t value);
105 int SetI32GA(idDS ds_id, const char *name, int32_t value);
106 
107 int16_t getDataTypeInt(productInfo_t *p_info);
108 int16_t *float2int16(float fbuf[], int32_t spix, int32_t npix, int32_t incr,
109  float slope, float offset);
110 int8_t *float2int8(float fbuf[], int32_t spix, int32_t npix, int32_t incr,
111  float slope, float offset);
112 uint16_t *float2uint16(float fbuf[], int32_t spix, int32_t npix, int32_t incr,
113  float slope, float offset);
114 uint8_t *float2uint8(float fbuf[], int32_t spix, int32_t npix, int32_t incr,
115  float slope, float offset);
116 void *scale_sds(float *data, productInfo_t *p, int32_t npix);
117 float *unscale_sds(void *data, productInfo_t *p, int32_t spix, int32_t npix,
118  int incr);
119 
120 // netcdf specific routines
121 int CreateNCDF(
122  idDS ds_id,
123  const char *sname, /* short name */
124  const char *lname, /* long name */
125  const char *standard_name, /* NetCDF standard name (not set if passed NULL or "") */
126  const char *reference,
127  const char *comment,
128  const char *units, /* units (not set if passed NULL or "") */
129  double low, /* low end of valid range */
130  double high, /* high end of range (no range set if low >= high) */
131  float scale_factor, /* scale factor (not set if 0) */
132  float add_offset, /* scaling offset (not set if 0) */
133  int32_t fillValue, /* fill value */
134  int32_t nt, /* NCDF number type */
135  int32_t rank, /* number of dimensions (must be <= 3) */
136  int32_t dimids[3]/* dimension ids */
137  );
138 void nc_init_compress(int32_t nc_id, int32_t var_id, int32_t *dimids, int32_t rank,
139  size_t *chunksize, int deflate_level);
140 
141 #ifdef __cplusplus
142 }
143 #endif
144 
145 #endif /* DFUTILS_H */
146 
@ DS_READ
Definition: dfutils.h:24
int SetF32GA(idDS ds_id, const char *name, float value)
int32 value
Definition: Granule.c:1235
int getDimsDS(idDS ds_id, const char sdsname[], int32_t dims[])
int infoAttr(idDS ds_id, const char *nam, int32_t *dtype, int32_t *count)
Definition: wrapper.c:191
idDS openDS(const char *filename)
Definition: wrapper.c:616
int32_t selectDS(idDS ds_id, const char *l2_prod_names)
Definition: wrapper.c:438
void nc_init_compress(int32_t nc_id, int32_t var_id, int32_t *dimids, int32_t rank, size_t *chunksize, int deflate_level)
int CreateNCDF(idDS ds_id, const char *sname, const char *lname, const char *standard_name, const char *reference, const char *comment, const char *units, double low, double high, float scale_factor, float add_offset, int32_t fillValue, int32_t nt, int32_t rank, int32_t dimids[3])
Definition: wrapper.c:848
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 as required for compatibility with version of the SDP toolkit Corrected test output file names to end in out
Definition: HISTORY.txt:422
dictionary pinfo
int getTypeDS(idDS ds_id, const char sdsname[HDF4_UTILS_MAX_NAME], int32_t *dtype)
int32_t deflate
Definition: dfutils.h:32
uint8_t * float2uint8(float fbuf[], int32_t spix, int32_t npix, int32_t incr, float slope, float offset)
ds_format_t fftype
Definition: dfutils.h:31
int createDS(idDS ds_id, int sensorId, const char *sname, int32_t dm[3], const char dm_name[3][80])
Definition: wrapper.c:344
int readAttr(idDS ds_id, const char *nam, void *data)
ds_access_t
Definition: dfutils.h:23
int endaccessDS(idDS ds_id)
Definition: wrapper.c:627
char * readAttrStr(idDS ds_id, const char *name)
Definition: wrapper.c:102
int getProdlist(const char *fname, char **prodlist, int32_t *l2_flags_type)
Definition: wrapper.c:721
idDS startDS(const char *filename, ds_format_t format, ds_access_t accessmode, int32_t deflate)
Definition: wrapper.c:561
int SetI8GA(idDS ds_id, const char *name, uint8_t value)
int16_t getDataTypeInt(productInfo_t *p_info)
Definition: scale_sds.c:16
float32 slope[]
Definition: l2lists.h:30
int8_t findAttr(idDS ds_id, const char *nam)
Definition: wrapper.c:49
int16_t * float2int16(float fbuf[], int32_t spix, int32_t npix, int32_t incr, float slope, float offset)
int32_t checkDS(idDS ds_id, const char *l2_prod_name)
Definition: wrapper.c:455
char filename[FILENAME_MAX]
Definition: atrem_corl1.h:122
int writeDS(idDS ds_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: wrapper.c:475
int setAttr(idDS ds_id, const char *nam, int32_t typ, int32_t cnt, const void *data)
Definition: wrapper.c:219
int SetF64GA(idDS ds_id, const char *name, double value)
int SetI16GA(idDS ds_id, const char *name, int16_t value)
@ DS_NCDF
Definition: dfutils.h:20
int readDS(idDS ds_id, const char *name, int32_t *start, int32_t *stride, int32_t *count, void *data)
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
Definition: HISTORY.txt:356
int32_t sid
Definition: dfutils.h:30
int8_t * float2int8(float fbuf[], int32_t spix, int32_t npix, int32_t incr, float slope, float offset)
int SetI32GA(idDS ds_id, const char *name, int32_t value)
Definition: wrapper.c:326
uint16_t * float2uint16(float fbuf[], int32_t spix, int32_t npix, int32_t incr, float slope, float offset)
float * unscale_sds(void *data, productInfo_t *p, int32_t spix, int32_t npix, int incr)
Definition: scale_sds.c:245
dtype
Definition: DDataset.hpp:31
@ DS_WRITE
Definition: dfutils.h:25
int SetChrGA(idDS ds_id, const char *name, const char *value)
Definition: wrapper.c:236
void * scale_sds(float *data, productInfo_t *p, int32_t npix)
int32_t fid
Definition: dfutils.h:29
Extra metadata that will be written to the HDF4 file l2prod rank
@ DS_HDF
Definition: dfutils.h:19
Definition: dfutils.h:28
#define HDF4_UTILS_MAX_NAME
Definition: hdf4utils.h:11
l2prod offset
ds_format_t
Definition: dfutils.h:18
int fileInfo(idDS ds_id, int32_t *n_datasets, int32_t *n_globalattr)
Definition: wrapper.c:705
int s2u(const char *in, char *out)
Definition: wrapper.c:36
int endDS(idDS ds_id)
Definition: wrapper.c:634
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 npix
Definition: get_cmp.c:27
int createDS2(idDS ds_id, const char *sname, productInfo_t *pinfo, int32_t dm[3], const char dm_name[3][80])
Definition: wrapper.c:360
float p[MODELMAX]
Definition: atrem_corl1.h:131
int count
Definition: decode_rs.h:79