OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
nc4utils.h
Go to the documentation of this file.
1 #ifndef _NC4UTILS_
2 #define _NC4UTILS_
3 
4 #include <netcdf.h>
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 
11 #include <stddef.h>
12 #include <stdint.h>
13 //#include <sys/types.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 //#include <math.h>
18 //#include <ctype.h>
19 
20 /*----- Utility macros -----*/
21 
22 #define TRYMEM(file,line,memstat) { \
23  if (memstat == NULL) { \
24  fprintf(stderr, "-E- %s:%d: " \
25  "Memory allocation error.\n", \
26  file, line); \
27  fflush(stderr); \
28  exit(1); } \
29  }
30 
31 #define TRY_NC(file,line,ncstat) { \
32  if (ncstat != NC_NOERR) { \
33  fprintf(stderr, "-E- %s:%d: " \
34  "%s\n", \
35  file, line, nc_strerror(ncstat)); \
36  fflush(stderr); \
37  exit(1); } \
38  }
39 
40 /*----- Datatype definitions -----*/
41 
42 typedef struct dim_str_nc {
43  char name[NC_MAX_NAME + 1]; /* dimension name */
44  size_t len; /* dimension length */
45 } dim_str_nc;
46 
47 typedef struct att_str_nc {
48  char name[NC_MAX_NAME + 1]; /* attribute name */
49  nc_type type; /* attribute type */
50  size_t nvals; /* number of attribute values */
51  void *value; /* pointer to untyped attribute value(s) */
52 } att_str_nc;
53 
54 typedef struct var_str_nc {
55  int grpid; /* parent group ID */
56  int id; /* variable index */
57  char name[NC_MAX_NAME + 1]; /* variable name */
58  nc_type type; /* variable type */
59  int ndims; /* number of dimensions */
60  dim_str_nc *dim; /* pointer to dimensions */
61  int natts; /* number of attributes */
62  att_str_nc *att; /* pointer to attributes */
63  int dimids[NC_MAX_VAR_DIMS]; /* array of dimension IDs */
64  void *data; /* pointer to data */
65 } var_str_nc;
66 
67 typedef struct grp_str_nc {
68  int id; /* group ID */
69  char name[NC_MAX_NAME + 1]; /* group name */
70  int ndims; /* number of dimensions */
71  dim_str_nc *dim; /* pointer to dimensions */
72  int natts; /* number of attributes */
73  att_str_nc *att; /* pointer to attributes */
74  int nvars; /* number of variables */
75  var_str_nc *var; /* pointer to variables */
76  int ngrps; /* number of subgroups */
77  struct grp_str_nc *grps; /* pointer to subgroups */
78 } grp_str_nc;
79 
80 /*----- Function Prototypes----- */
81 
82 dim_str_nc *load_dims_nc(int ncid);
83 void print_dims_nc(dim_str_nc *dim, int ndims);
85 int find_dimid_nc(int ncid, int *dimid, const char *dimnames[]);
86 
87 att_str_nc *load_atts_nc(int ncid, int varid);
88 void print_atts_nc(att_str_nc *att, int natts, char *varname);
89 void free_atts_nc(att_str_nc *att, int natts);
90 
91 var_str_nc *load_vars_nc(int ncid);
93  const char* varname, const char* grpname);
95 void print_vars_nc(var_str_nc *var, int nvars);
96 void free_vars_nc(var_str_nc *var, int nvars);
97 int find_varid_nc(int ncid, int *varid, const char *varnames[]);
98 
99 int load_grp_nc(grp_str_nc *grp);
100 void print_grp_nc(grp_str_nc grp);
101 void free_grp_nc(grp_str_nc *grp);
102 void check_err(const int stat, const int line, const char *file);
103 void report_err(const int stat, const int line, const char *file);
104 int createNCDF(int ncid, const char *sname, const char *lname,
105  const char *standard_name, const char *units,
106  void *fill_value,
107  const char *flag_values, const char *flag_meanings,
108  double low, double high, int nt,
109  int rank, int *dimids, size_t *chunksize);
110 void nc_init_compress(int32_t nc_id, int32_t var_id, int32_t *dimids, int32_t rank,
111  size_t *chunksize, int deflate_level);
112 int nc_init_compress2(int32_t nc_id, char *varnam, int32_t var_id, int32_t *dimids, int32_t rank,
113  size_t *chunksize, int type_size, int deflate_level);
114 int check_chunksizes(size_t type_len, int32_t ndims, const size_t *chunksizes);
115 #ifdef __cplusplus
116 }
117 #endif
118 
119 #endif /* _NC_UTILS_ */
size_t len
Definition: nc4utils.h:44
int grpid
Definition: nc4utils.h:55
int ndims
Definition: nc4utils.h:70
void print_grp_nc(grp_str_nc grp)
Definition: nc4utils.c:466
char name[NC_MAX_NAME+1]
Definition: nc4utils.h:69
void free_dims_nc(dim_str_nc *dim)
Definition: nc4utils.c:147
att_str_nc * att
Definition: nc4utils.h:62
void free_atts_nc(att_str_nc *att, int natts)
Definition: nc4utils.c:236
char name[NC_MAX_NAME+1]
Definition: nc4utils.h:57
att_str_nc * load_atts_nc(int ncid, int varid)
Definition: nc4utils.c:177
int nvars
Definition: nc4utils.h:74
dim_str_nc * load_dims_nc(int ncid)
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
int dimids[NC_MAX_VAR_DIMS]
Definition: nc4utils.h:63
nc_type type
Definition: nc4utils.h:58
int load_grp_nc(grp_str_nc *grp)
Definition: nc4utils.c:423
size_t nvals
Definition: nc4utils.h:50
int id
Definition: nc4utils.h:68
int ndims
Definition: nc4utils.h:59
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 id
Definition: nc4utils.h:56
struct grp_str_nc * grps
Definition: nc4utils.h:77
int check_chunksizes(size_t type_len, int32_t ndims, const size_t *chunksizes)
void * data
Definition: nc4utils.h:64
void free_grp_nc(grp_str_nc *grp)
Definition: nc4utils.c:495
var_str_nc * find_var_byname_nc(grp_str_nc nc, const char *varname, const char *grpname)
Definition: nc4utils.c:314
var_str_nc * var
Definition: nc4utils.h:75
int readall_var(var_str_nc *var)
Definition: nc4utils.c:334
var_str_nc * load_vars_nc(int ncid)
Definition: nc4utils.c:254
int ngrps
Definition: nc4utils.h:76
int find_varid_nc(int ncid, int *varid, const char *varnames[])
Definition: nc4utils.c:407
char name[NC_MAX_NAME+1]
Definition: nc4utils.h:48
void print_dims_nc(dim_str_nc *dim, int ndims)
Definition: nc4utils.c:139
dim_str_nc * dim
Definition: nc4utils.h:60
void free_vars_nc(var_str_nc *var, int nvars)
Definition: nc4utils.c:384
nc_type type
Definition: nc4utils.h:49
void * value
Definition: nc4utils.h:51
char name[NC_MAX_NAME+1]
Definition: nc4utils.h:43
Extra metadata that will be written to the HDF4 file l2prod rank
int natts
Definition: nc4utils.h:72
void print_vars_nc(var_str_nc *var, int nvars)
Definition: nc4utils.c:362
att_str_nc * att
Definition: nc4utils.h:73
int nc_init_compress2(int32_t nc_id, char *varnam, int32_t var_id, int32_t *dimids, int32_t rank, size_t *chunksize, int type_size, int deflate_level)
void report_err(const int stat, const int line, const char *file)
Definition: nc4utils.c:28
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 natts
Definition: nc4utils.h:61
void print_atts_nc(att_str_nc *att, int natts, char *varname)
Definition: nc4utils.c:224
int createNCDF(int ncid, const char *sname, const char *lname, const char *standard_name, const char *units, void *fill_value, const char *flag_values, const char *flag_meanings, double low, double high, int nt, int rank, int *dimids, size_t *chunksize)
Definition: createNCDF.c:17
void check_err(const int stat, const int line, const char *file)
Definition: nc4utils.c:35
int find_dimid_nc(int ncid, int *dimid, const char *dimnames[])
Definition: nc4utils.c:161
dim_str_nc * dim
Definition: nc4utils.h:71