1 /*********************************************************************
2  * Copyright 2018, University Corporation for Atmospheric
3  * Research/Unidata.  See \ref copyright file for copying and
4  * redistribution conditionsmore information.
5  *********************************************************************/
6 #ifndef _NCCOMPS_H_
7 #define _NCCOMPS_H_
8 
9 typedef struct {			/* dimension */
10     char name[NC_MAX_NAME];
11     size_t size;
12 } ncdim_t;
13 
14 /* forward declarations */
15 struct nctype_t;
16 struct ncvar_t;
17 struct timeinfo_t;
18 
19 /*
20  * Member function to determine if values for this type are equal,
21  * used to compare with fill value.
22  */
23 typedef bool_t (*val_equals_func)(const struct nctype_t *this,
24 				   const void *v1p, const void *v2p);
25 /*
26  * Member function to convert value of this type to a string. Returns
27  * number of bytes in output string sb (not including trailing null)
28  */
29 typedef int (*typ_tostring_func)(const struct nctype_t *this,
30 				 struct safebuf_t *sb,
31 				 const void *valp);
32 
33 /*
34  * Per-variable member function to convert value of this type to a
35  * string. Returns number of bytes in output string sb (not
36  * including trailing null).  This is needed because a variable
37  * can override its type for output, if a variable-specific format
38  * is specified in an attribute.
39  */
40 typedef int (*val_tostring_func)(const struct ncvar_t *this,
41 				 struct safebuf_t *sb,
42 				 const void *valp);
43 
44 typedef struct nctype_t {	/* type */
45     int ncid;		    /* group in which type is defined */
46     nc_type tid;	    /* type ID */
47     char *name;	       	    /* relative name of type within its group */
48     char *grps;	       	    /* full prefix for type name, eg "grp1/grp2" */
49     int class;	       	    /* > 0 for netCDF-4 user-defined types */
50     size_t size;       	    /* like sizeof, even for user-defined types */
51     nc_type base_tid;  	    /* for netCDF-4 enums, vlens */
52     size_t nfields;    	    /* for netCDF-4 compound types */
53     const char *fmt;   	    /* if non-null, format for printing values */
54     nc_type *fids;  	    /* type id for each field of compound type */
55     size_t *offsets;   	    /* offsets for each field of compound type */
56     int *ranks;		    /* rank for each field of compound type */
57     int **sides;	    /* rank sizes for each field where rank > 0 */
58     int *nvals;		    /* num of values for each field (prod of sides) */
59     /* member functions */
60     val_equals_func val_equals; /* function to compare 2 values for equality */
61     typ_tostring_func typ_tostring; /* default function to convert
62 				     * value to string for output (can
63 				     * be overridden by per-variable
64 				     * function, if fmt attribute
65 				     * is specified for a variable) */
66 } nctype_t;
67 
68 typedef struct ncvar_t {	/* variable */
69     char name[NC_MAX_NAME];
70     nc_type type;
71     struct nctype_t *tinfo;	/* full type information */
72     int ndims;			/* number of dimensions (rank) */
73     int *dims;			/* dimension ids */
74     int natts;			/* number of attributes */
75     bool_t has_fillval;	/* has a fill value defined? */
76     void* fillvalp;	        /* pointer to the fill value, if any */
77     bool_t has_timeval;	/* has date-time values, for -t output option */
78     struct timeinfo_t *timeinfo;/* if time values, units, calendar, and origin */
79     bool_t is_bnds_var;        /* cell bounds variable, inherits timeinfo */
80     const char *fmt;            /* overriding variable-specific format for
81 				   printing values or base values, if any */
82     int locid;			/* group id */
83     /* member functions */
84     val_tostring_func val_tostring; /* function to convert value to string for
85 				       output */
86 } ncvar_t;
87 
88 typedef struct ncatt_t {			/* attribute */
89     int var;
90     char name[NC_MAX_NAME];
91     nc_type type;
92     nctype_t *tinfo;
93     size_t len;
94     char *string;		/* for NcML text attributes (type = NC_CHAR)
95 				 * TODO: eliminate and just use valgp */
96     double *vals;		/* for NcML numeric attributes of all types
97 				 * TODO: eliminate and just use valgp */
98     void *valgp;		/* generic pointer to values of any type */
99 } ncatt_t;
100 
101 #endif	/*_NCCOMPS_H_ */
102