1 #ifndef NC_NCGEN_H 2 #define NC_NCGEN_H 3 /********************************************************************* 4 * Copyright 2018, UCAR/Unidata 5 * See netcdf/COPYRIGHT file for copying and redistribution conditions. 6 * $Header: /upc/share/CVS/netcdf-3/ncgen/ncgen.h,v 1.18 2010/06/01 15:34:53 ed Exp $ 7 *********************************************************************/ 8 9 #ifdef _WIN32 10 #include <float.h> 11 #include "../ncdump/isnan.h" 12 #define strcasecmp _stricmp 13 #endif 14 15 #ifdef USE_NETCDF4 16 #define CLASSICONLY 0 17 #else 18 #define CLASSICONLY 1 19 #endif 20 21 #define MAX_NC_ATTSIZE 20000 /* max size of attribute (for ncgen) */ 22 #define MAXTRST 5000 /* max size of string value (for ncgen) */ 23 24 /* Define the possible classes of objects*/ 25 /* extend the NC_XXX values*/ 26 #define NC_GRP 100 27 #define NC_DIM 101 28 #define NC_VAR 102 29 #define NC_ATT 103 30 #define NC_TYPE 104 31 #define NC_ECONST 105 32 #define NC_FIELD 106 33 #define NC_ARRAY 107 34 #define NC_PRIM 108 /*Including NC_STRING */ 35 #define NC_STRUCT NC_COMPOUND /* alias */ 36 #define NC_LIST NC_COMPOUND /* alias */ 37 38 /* Extend nc types with generic fill value*/ 39 #define NC_FILLVALUE 31 40 /* Extend nc types with NIL value*/ 41 #define NC_NIL 32 42 43 /* Must be a better way to do this */ 44 #ifndef INFINITE 45 #ifdef _MSC_VER 46 #define NC_INFINITE (DBL_MAX+DBL_MAX) 47 #define NC_INFINITEF NC_INFINITE 48 #define NAN (NC_INFINITE-NC_INFINITE) 49 #define NANF NAN 50 #else 51 #define NC_INFINITE (1.0/0.0) 52 #define NC_INFINITEF (1.0f/0.0f) 53 #define NAN (0.0/0.0) 54 #define NANF (0.0f/0.0f) 55 #endif 56 57 #define NEGNC_INFINITEF (-NC_INFINITEF) 58 #define NEGNC_INFINITE (-NC_INFINITEF) 59 #endif 60 61 /* nc_class is one of: 62 NC_GRP NC_DIM NC_VAR NC_ATT NC_TYPE 63 */ 64 typedef nc_type nc_class; 65 66 /* nc_subclass is one of: 67 NC_PRIM NC_OPAQUE NC_ENUM 68 NC_FIELD NC_VLEN NC_COMPOUND 69 NC_ECONST NC_ARRAY NC_FILLVALUE 70 */ 71 typedef nc_type nc_subclass; 72 73 /* 74 Define data structure 75 xto hold special attribute values 76 for a given variable. 77 Global values are kept as 78 various C global variables 79 */ 80 81 /* Define a bit set for indicating which*/ 82 /* specials were explicitly specified*/ 83 /* See also: ncgen.y.tag2name */ 84 #define _STORAGE_FLAG 0x001 85 #define _CHUNKSIZES_FLAG 0x002 86 #define _FLETCHER32_FLAG 0x004 87 #define _DEFLATE_FLAG 0x008 88 #define _SHUFFLE_FLAG 0x010 89 #define _ENDIAN_FLAG 0x020 90 #define _NOFILL_FLAG 0x040 91 #define _FILLVALUE_FLAG 0x080 92 #define _NCPROPS_FLAG 0x100 93 #define _ISNETCDF4_FLAG 0x200 94 #define _SUPERBLOCK_FLAG 0x400 95 #define _FORMAT_FLAG 0x800 96 #define _FILTER_FLAG 0x1000 97 98 extern struct Specialtoken { 99 char* name; 100 int token; 101 int tag; 102 } specials[]; 103 104 /* Define an enumeration of supported languages */ 105 typedef enum Language { 106 L_UNDEFINED=0, 107 L_BINARY=1, 108 L_C=2, 109 L_F77=3, 110 L_JAVA=4 111 } Language; 112 113 struct Kvalues { 114 char* name; 115 int k_flag; 116 }; 117 118 extern struct Kvalues legalkinds[]; 119 120 #define ZIP_ID 0xFFFFFFFF 121 #define SZIP_ID 0xFFFFFFFE 122 #define BZIP2_ID 307U 123 #define ZFP_ID 32013U 124 #define FPZIP_ID 32014U 125 126 /* Note: some non-var specials (i.e. _Format) are not included in this struct*/ 127 typedef struct Specialdata { 128 int flags; 129 Datalist* _Fillvalue; /* This is a per-type ; points to the _FillValue attribute node */ 130 int _Storage; /* NC_CHUNKED | NC_CONTIGUOUS*/ 131 size_t* _ChunkSizes; /* NULL => defaults*/ 132 int nchunks; /* |_Chunksize| ; 0 => not specified*/ 133 int _Fletcher32; /* 1=>fletcher32*/ 134 int _DeflateLevel; /* 0-9 => level*/ 135 int _Shuffle; /* 0 => false, 1 => true*/ 136 int _Endianness; /* 1 =>little, 2 => big*/ 137 int _Fill ; /* 0 => false, 1 => true WATCHOUT: this is inverse of NOFILL*/ 138 NC4_Filterspec** _Filters; 139 size_t nfilters; /* |filters| */ 140 } Specialdata; 141 142 typedef struct GlobalSpecialdata { 143 int _Format ; /* kflag */ 144 const char* _NCProperties ; 145 int _IsNetcdf4 ; /* 0 => false, 1 => true */ 146 int _Superblock ; /* HDF5 file superblock version */ 147 } GlobalSpecialData; 148 149 /* 150 During the generation of binary data, 151 we will generate a number of references 152 to strings and opaques that should 153 be reclaimed to keep the memory 154 checkers happy. 155 */ 156 typedef struct BinBuffer { 157 Bytebuffer* buf; /* top level data */ 158 List* reclaim; /* objects that need to be free'd */ 159 } BinBuffer; 160 161 /* Track a set of dimensions*/ 162 /* (Note: the netcdf type system is deficient here)*/ 163 typedef struct Dimset { 164 int ndims; 165 struct Symbol* dimsyms[NC_MAX_VAR_DIMS]; /* Symbol for dimension*/ 166 } Dimset; 167 168 typedef struct Diminfo { 169 int isconstant; /* separate constant from named dimension*/ 170 int isunlimited; 171 size_t declsize; /* 0 => unlimited/unspecified*/ 172 } Diminfo; 173 174 typedef struct Attrinfo { 175 struct Symbol* var; /* NULL => global*/ 176 } Attrinfo; 177 178 typedef struct Typeinfo { 179 struct Symbol* basetype; 180 int hasvlen; /* 1 => this type contains a vlen*/ 181 nc_type typecode; 182 unsigned long offset; /* fields in struct*/ 183 unsigned long alignment;/* fields in struct*/ 184 NCConstant* econst; /* for enum values*/ 185 Dimset dimset; /* for NC_VAR/NC_FIELD/NC_ATT*/ 186 size_t size; /* for opaque, compound, etc.*/ 187 size_t cmpdalign; /* alignment needed for total size instances */ 188 size_t nelems; /* size in terms of # of datalist constants 189 it takes to represent it */ 190 Datalist* _Fillvalue; /* per-type cached fillvalue 191 (overridden by var fillvalue) */ 192 } Typeinfo; 193 194 typedef struct Varinfo { 195 int nattributes; /* |attributes|*/ 196 List* attributes; /* List<Symbol*>*/ 197 Specialdata* special; 198 } Varinfo; 199 200 typedef struct Groupinfo { 201 int is_root; 202 } Groupinfo; 203 204 typedef struct Fileinfo { 205 char* filename; 206 } Fileinfo; 207 208 /* store info when the symbol 209 is really a reference to another 210 symbol 211 */ 212 typedef struct Reference { 213 int is_ref; /* separate name defs from refs*/ 214 char* unescaped; /* original, unescaped name */ 215 struct Symbol* ref; /* ptr to the symbol if is_ref is true*/ 216 } Reference; 217 218 typedef struct Symbol { /* symbol table entry*/ 219 nc_class objectclass; /* NC_DIM|NC_VLEN|NC_OPAQUE...*/ 220 nc_class subclass; /* NC_STRUCT|...*/ 221 char* name; 222 char* fqn; /* cached fully qualified C or FORTRAN name*/ 223 struct Symbol* container; /* The group containing this symbol.*/ 224 /* for fields or enumids, it is*/ 225 /* the parent type.*/ 226 struct Symbol* location; /* current group when symbol was created*/ 227 List* subnodes; /* sublist for enum or struct or group*/ 228 int is_prefixed; /* prefix was specified (vs computed).*/ 229 List* prefix; /* List<Symbol*>*/ 230 struct Datalist* data; /* shared by variables and attributes*/ 231 /* Note that we cannot union these because some kinds of symbols*/ 232 /* use more than one part*/ 233 Typeinfo typ; /* type info for e.g. var, att, etc.*/ 234 Varinfo var; 235 Attrinfo att; 236 Diminfo dim; 237 Groupinfo grp; 238 Fileinfo file; 239 Reference ref; /* symbol is really a reference to another symbol*/ 240 /* Misc pieces of info*/ 241 int lineno; /* at point of creation*/ 242 int touched; /* for sorting*/ 243 /* for use by -lb */ 244 int nc_id; /* from netcdf API: varid, or dimid, or etc.*/ 245 } Symbol; 246 247 248 #endif /*!NC_NCGEN_H*/ 249