1 | /********************************************************************* |
---|
2 | * Copyright 1993, UCAR/Unidata |
---|
3 | * See netcdf/COPYRIGHT file for copying and redistribution conditions. |
---|
4 | * $Header: /upc/share/CVS/netcdf-3/libnccommon/nccommon.h,v 1.40 2010/05/30 19:45:52 dmh Exp $ |
---|
5 | *********************************************************************/ |
---|
6 | #ifndef NCCOMMON_H |
---|
7 | #define NCCOMMON_H 1 |
---|
8 | |
---|
9 | /* Mnemonics */ |
---|
10 | #ifndef BOOL |
---|
11 | #define BOOL int |
---|
12 | #endif |
---|
13 | #ifndef TRUE |
---|
14 | #define TRUE 1 |
---|
15 | #define FALSE 0 |
---|
16 | #endif |
---|
17 | |
---|
18 | #ifndef nullfree |
---|
19 | #define nullfree(m) {if((m)!=NULL) {free(m);} else {}} |
---|
20 | #endif |
---|
21 | |
---|
22 | |
---|
23 | #define FILLCONSTRAINT TRUE |
---|
24 | |
---|
25 | |
---|
26 | /* Use an extended version of the netCDF-4 type system */ |
---|
27 | #define NC_URL 50 |
---|
28 | #define NC_SET 51 |
---|
29 | /* Merge relevant translations of OC types */ |
---|
30 | #define NC_Dataset 52 |
---|
31 | #define NC_Sequence 53 |
---|
32 | #define NC_Structure 54 |
---|
33 | #define NC_Grid 55 |
---|
34 | #define NC_Dimension 56 |
---|
35 | #define NC_Primitive 57 |
---|
36 | |
---|
37 | #undef OCCOMPILEBYDEFAULT |
---|
38 | |
---|
39 | #define DEFAULTSTRINGLENGTH 64 |
---|
40 | /* The sequence limit default is zero because |
---|
41 | most servers do not implement projections |
---|
42 | on sequences. |
---|
43 | */ |
---|
44 | #define DEFAULTSEQLIMIT 0 |
---|
45 | |
---|
46 | /**************************************************/ |
---|
47 | /* sigh, do the forwards */ |
---|
48 | struct NCDAPCOMMON; |
---|
49 | struct NCprojection; |
---|
50 | struct NCselection; |
---|
51 | struct Getvara; |
---|
52 | struct NCcachenode; |
---|
53 | struct NCcache; |
---|
54 | struct NCslice; |
---|
55 | struct NCsegment; |
---|
56 | struct OClist; |
---|
57 | /**************************************************/ |
---|
58 | /* |
---|
59 | Collect single bit flags that |
---|
60 | affect the operation of the system. |
---|
61 | */ |
---|
62 | |
---|
63 | typedef unsigned int NCFLAGS; |
---|
64 | # define SETFLAG(controls,flag) ((controls.flags) |= (flag)) |
---|
65 | # define CLRFLAG(controls,flag) ((controls.flags) &= ~(flag)) |
---|
66 | # define FLAGSET(controls,flag) (((controls.flags) & (flag)) != 0) |
---|
67 | |
---|
68 | /* Defined flags */ |
---|
69 | #define NCF_NC3 (0x0001) /* DAP->netcdf-3 */ |
---|
70 | #define NCF_NC4 (0x0002) /* DAP->netcdf-4 */ |
---|
71 | #define NCF_NCDAP (0x0004) /* Do libnc-dap mimic */ |
---|
72 | #define NCF_CACHE (0x0008) /* Cache enabled/disabled */ |
---|
73 | #define NCF_PREFETCH (0x0010) /* Cache prefetch enabled/disabled */ |
---|
74 | #define NCF_UPGRADE (0x0020) /* Do proper type upgrades */ |
---|
75 | #define NCF_UNCONSTRAINABLE (0x0040) /* Not a constrainable URL */ |
---|
76 | #define NCF_SHOWFETCH (0x0080) /* show fetch calls */ |
---|
77 | #define NCF_ONDISK (0x0100) /* cause oc to store data on disk */ |
---|
78 | #define NCF_WHOLEVAR (0x0200) /* retrieve only whole variables (as opposed to partial variable) |
---|
79 | into cache */ |
---|
80 | |
---|
81 | /* Define all the default on flags */ |
---|
82 | #define DFALT_ON_FLAGS (NCF_PREFETCH) |
---|
83 | |
---|
84 | typedef struct NCCONTROLS { |
---|
85 | NCFLAGS flags; |
---|
86 | } NCCONTROLS; |
---|
87 | |
---|
88 | struct NCTMODEL { |
---|
89 | int translation; |
---|
90 | char* model; |
---|
91 | unsigned int flags; |
---|
92 | }; |
---|
93 | |
---|
94 | /* Detail information about each cache item */ |
---|
95 | typedef struct NCcachenode { |
---|
96 | int wholevariable; /* does this node only have wholevariables? */ |
---|
97 | int prefetch; /* is this the prefetch cache entry? */ |
---|
98 | size_t xdrsize; |
---|
99 | DCEconstraint* constraint; /* as used to create this node */ |
---|
100 | NClist* vars; /* vars potentially covered by this cache node */ |
---|
101 | struct CDFnode* datadds; |
---|
102 | OCobject ocroot; |
---|
103 | OCdata content; |
---|
104 | } NCcachenode; |
---|
105 | |
---|
106 | /* All cache info */ |
---|
107 | typedef struct NCcache { |
---|
108 | size_t cachelimit; /* max total size for all cached entries */ |
---|
109 | size_t cachesize; /* current size */ |
---|
110 | size_t cachecount; /* max # nodes in cache */ |
---|
111 | NCcachenode* prefetch; |
---|
112 | NClist* nodes; /* cache nodes other than prefetch */ |
---|
113 | } NCcache; |
---|
114 | |
---|
115 | /**************************************************/ |
---|
116 | /* The DAP packet info from OC */ |
---|
117 | typedef struct NCOC { |
---|
118 | OCconnection conn; |
---|
119 | char* rawurltext; /* as given to nc3d_open */ |
---|
120 | char* urltext; /* as modified by nc3d_open */ |
---|
121 | NC_URI* url; /* parse of rawuritext */ |
---|
122 | OCobject ocdasroot; |
---|
123 | DCEconstraint* dapconstraint; /* from url */ |
---|
124 | int inmemory; /* store fetched data in memory? */ |
---|
125 | } NCOC; |
---|
126 | |
---|
127 | typedef struct NCCDF { |
---|
128 | struct CDFnode* ddsroot; /* constrained dds */ |
---|
129 | struct CDFnode* fullddsroot; /* unconstrained dds */ |
---|
130 | /* Collected sets of useful nodes (in ddsroot tree space) */ |
---|
131 | NClist* varnodes; /* nodes which can represent netcdf variables */ |
---|
132 | NClist* seqnodes; /* sequence nodes; */ |
---|
133 | NClist* gridnodes; /* grid nodes */ |
---|
134 | NClist* dimnodes; /* (base) dimension nodes */ |
---|
135 | unsigned int defaultstringlength; |
---|
136 | unsigned int defaultsequencelimit; /* global sequence limit;0=>no limit */ |
---|
137 | struct NCcache* cache; |
---|
138 | size_t fetchlimit; |
---|
139 | size_t smallsizelimit; /* what constitutes a small object? */ |
---|
140 | size_t totalestimatedsize; |
---|
141 | const char* separator; /* constant; do not free */ |
---|
142 | /* global string dimension */ |
---|
143 | struct CDFnode* globalstringdim; |
---|
144 | char* recorddimname; /* From DODS_EXTRA */ |
---|
145 | struct CDFnode* recorddim; |
---|
146 | /* libncdap4 only */ |
---|
147 | NClist* usertypes; /* nodes which will represent netcdf types */ |
---|
148 | } NCCDF; |
---|
149 | |
---|
150 | /* Define a structure holding common info for NCDAP{3,4} */ |
---|
151 | |
---|
152 | typedef struct NCDAPCOMMON { |
---|
153 | NC* controller; /* Parent instance of NCDAPCOMMON */ |
---|
154 | NCCDF cdf; |
---|
155 | NCOC oc; |
---|
156 | NCCONTROLS controls; /* Control flags and parameters */ |
---|
157 | } NCDAPCOMMON; |
---|
158 | |
---|
159 | /**************************************************/ |
---|
160 | /* Create our own node tree to mimic ocnode trees*/ |
---|
161 | |
---|
162 | /* Each root CDFnode contains info about the whole tree */ |
---|
163 | typedef struct CDFtree { |
---|
164 | OCobject ocroot; |
---|
165 | OCdxd occlass; |
---|
166 | NClist* nodes; /* all nodes in tree*/ |
---|
167 | struct CDFnode* root; /* cross link */ |
---|
168 | struct NCDAPCOMMON* owner; |
---|
169 | /* Classification flags */ |
---|
170 | int regridded; /* Was this tree passed thru regrid3? */ |
---|
171 | } CDFtree; |
---|
172 | |
---|
173 | /* Track the kinds of dimensions */ |
---|
174 | typedef int CDFdimflags; |
---|
175 | #define CDFDIMNORMAL 0x0 |
---|
176 | #define CDFDIMSEQ 0x1 |
---|
177 | #define CDFDIMSTRING 0x2 |
---|
178 | #define CDFDIMCLONE 0x4 |
---|
179 | #define CDFDIMRECORD 0x20 |
---|
180 | |
---|
181 | #define DIMFLAG(d,flag) ((d)->dim.dimflags & (flag)) |
---|
182 | #define DIMFLAGSET(d,flag) ((d)->dim.dimflags |= (flag)) |
---|
183 | #define DIMFLAGCLR(d,flag) ((d)->dim.dimflags &= ~(flag)) |
---|
184 | |
---|
185 | typedef struct CDFdim { |
---|
186 | CDFdimflags dimflags; |
---|
187 | struct CDFnode* basedim; /* for duplicate dimensions*/ |
---|
188 | struct CDFnode* array; /* parent array node */ |
---|
189 | size_t declsize; /* from constrained DDS*/ |
---|
190 | size_t declsize0; /* from unconstrained DDS*/ |
---|
191 | int index1; /* dimension name index +1; 0=>no index */ |
---|
192 | } CDFdim; |
---|
193 | |
---|
194 | typedef struct CDFarray { |
---|
195 | NClist* dimsetall; /* inherited+originals+pseudo */ |
---|
196 | NClist* dimsetplus; /* originals+pseudo */ |
---|
197 | NClist* dimset0; /* original dims from the dds */ |
---|
198 | struct CDFnode* stringdim; |
---|
199 | /* Track sequence related information */ |
---|
200 | struct CDFnode* seqdim; /* if this node is a sequence */ |
---|
201 | /* note: unlike string dim; seqdim is also stored in dimensions vector */ |
---|
202 | struct CDFnode* sequence; /* containing usable sequence, if any */ |
---|
203 | struct CDFnode* basevar; /* for duplicate grid variables*/ |
---|
204 | } CDFarray; |
---|
205 | |
---|
206 | typedef struct NCattribute { |
---|
207 | char* name; |
---|
208 | nc_type etype; /* dap type of the attribute */ |
---|
209 | NClist* values; /* strings come from the oc values */ |
---|
210 | int invisible; /* Do not materialize to the user */ |
---|
211 | } NCattribute; |
---|
212 | |
---|
213 | /* Extend as additional DODS attribute values are defined */ |
---|
214 | typedef struct NCDODS { |
---|
215 | size_t maxstrlen; |
---|
216 | char* dimname; |
---|
217 | } NCDODS; |
---|
218 | |
---|
219 | typedef struct NCalignment { |
---|
220 | unsigned long size; /* size of single instance of this type*/ |
---|
221 | unsigned long alignment; /* alignment of this field */ |
---|
222 | unsigned long offset; /* offset of this field in parent */ |
---|
223 | } NCalignment; |
---|
224 | |
---|
225 | typedef struct NCtypesize { |
---|
226 | BOOL aligned; /* have instance and field been defined? */ |
---|
227 | NCalignment instance; /* Alignment, etc for instance data */ |
---|
228 | NCalignment field; /* Alignment, etc WRT to parent */ |
---|
229 | } NCtypesize; |
---|
230 | |
---|
231 | /* Closely mimics struct OCnode*/ |
---|
232 | typedef struct CDFnode { |
---|
233 | nc_type nctype; /* e.g. var, dimension */ |
---|
234 | nc_type etype; /* e.g. NC_INT, NC_FLOAT if applicable,*/ |
---|
235 | char* ocname; /* oc base name */ |
---|
236 | char* ncbasename; /* generally cdflegalname(ocname) */ |
---|
237 | char* ncfullname; /* complete path name from root to this node*/ |
---|
238 | OCobject ocnode; /* oc mirror node*/ |
---|
239 | struct CDFnode* group; /* null => in root group */ |
---|
240 | struct CDFnode* container; /* e.g. struct or sequence, but not group */ |
---|
241 | struct CDFnode* root; |
---|
242 | CDFtree* tree; /* root level metadata;only defined if root*/ |
---|
243 | CDFdim dim; /* nctype == dimension */ |
---|
244 | CDFarray array; /* nctype == grid,var,etc. with dimensions */ |
---|
245 | NClist* subnodes; /* if nctype == grid, sequence, etc. */ |
---|
246 | NClist* attributes; /*NClist<NCattribute*>*/ |
---|
247 | NCDODS dodsspecial; /* special attributes like maxStrlen */ |
---|
248 | nc_type externaltype; /* the type as represented to nc_inq*/ |
---|
249 | int ncid; /* relevant NC id for this object*/ |
---|
250 | unsigned long maxstringlength; |
---|
251 | unsigned long sequencelimit; /* 0=>unlimited */ |
---|
252 | BOOL usesequence; /* If this sequence is usable */ |
---|
253 | BOOL elided; /* 1 => node does not partipate in naming*/ |
---|
254 | struct CDFnode* basenode; /* derived tree map to template tree */ |
---|
255 | BOOL visible; /* 1 => node is present in derived tree; independent of elided flag */ |
---|
256 | BOOL zerodim; /* 1 => node has a zero dimension */ |
---|
257 | /* These two flags track the effects on grids of constraints */ |
---|
258 | BOOL virtual; /* node added by regrid */ |
---|
259 | #ifdef PROJECTED |
---|
260 | BOOL projected; /* node referenced by projection */ |
---|
261 | #endif |
---|
262 | struct CDFnode* attachment; /* DDS<->DATADDS cross link*/ |
---|
263 | struct CDFnode* template; /* temporary field for regridding */ |
---|
264 | /* Fields for use by libncdap4 */ |
---|
265 | NCtypesize typesize; |
---|
266 | int typeid; /* when treating field as type */ |
---|
267 | int basetypeid; /* when typeid is vlen */ |
---|
268 | char* typename; |
---|
269 | char* vlenname; /* for sequence types */ |
---|
270 | int singleton; /* for singleton sequences */ |
---|
271 | unsigned long estimatedsize; /* > 0 Only for var nodes */ |
---|
272 | } CDFnode; |
---|
273 | |
---|
274 | /**************************************************/ |
---|
275 | /* Shared procedures */ |
---|
276 | |
---|
277 | /* From ncdap3.c*/ |
---|
278 | extern NCerror freeNCDAPCOMMON(struct NCDAPCOMMON*); |
---|
279 | extern NCerror fetchtemplatemetadata3(NCDAPCOMMON*); |
---|
280 | |
---|
281 | /* From error.c*/ |
---|
282 | extern NCerror ocerrtoncerr(OCerror); |
---|
283 | |
---|
284 | /* From: common34.c */ |
---|
285 | extern NCerror fixgrid34(struct NCDAPCOMMON* drno, CDFnode* grid); |
---|
286 | extern NCerror computecdfinfo34(struct NCDAPCOMMON*, NClist*); |
---|
287 | extern char* cdfname34(char* basename); |
---|
288 | extern NCerror augmentddstree34(struct NCDAPCOMMON*, NClist*); |
---|
289 | extern NCerror computecdfdimnames34(struct NCDAPCOMMON*); |
---|
290 | extern NCerror buildcdftree34(struct NCDAPCOMMON*, OCobject, OCdxd, CDFnode**); |
---|
291 | extern CDFnode* makecdfnode34(struct NCDAPCOMMON*, char* nm, OCtype, |
---|
292 | /*optional*/ OCobject ocnode, CDFnode* container); |
---|
293 | extern void freecdfroot34(CDFnode*); |
---|
294 | |
---|
295 | extern NCerror findnodedds34(struct NCDAPCOMMON* drno, CDFnode* ddssrc); |
---|
296 | extern NCerror makegetvar34(struct NCDAPCOMMON*, struct CDFnode*, void*, nc_type, struct Getvara**); |
---|
297 | extern NCerror applyclientparams34(struct NCDAPCOMMON* drno); |
---|
298 | extern NCerror attach34(CDFnode* xroot, CDFnode* ddstarget); |
---|
299 | extern NCerror attachall34(CDFnode* xroot, CDFnode* ddsroot); |
---|
300 | extern NCerror attachsubset34(CDFnode*, CDFnode*); |
---|
301 | extern void unattach34(CDFnode*); |
---|
302 | extern int nodematch34(CDFnode* node1, CDFnode* node2); |
---|
303 | extern int simplenodematch34(CDFnode* node1, CDFnode* node2); |
---|
304 | extern CDFnode* findxnode34(CDFnode* target, CDFnode* xroot); |
---|
305 | extern int constrainable34(NC_URI*); |
---|
306 | extern char* makeconstraintstring34(DCEconstraint*); |
---|
307 | extern size_t estimatedataddssize34(CDFnode* datadds); |
---|
308 | extern void canonicalprojection34(NClist*, NClist*); |
---|
309 | extern NClist* getalldims34(NCDAPCOMMON* nccomm, int visibleonly); |
---|
310 | |
---|
311 | /* From cdf3.c */ |
---|
312 | extern NCerror dimimprint3(NCDAPCOMMON*); |
---|
313 | extern NCerror definedimsets3(struct NCDAPCOMMON*); |
---|
314 | |
---|
315 | /* From cache.c */ |
---|
316 | extern int iscached(NCDAPCOMMON*, CDFnode* target, NCcachenode** cachenodep); |
---|
317 | extern NCerror prefetchdata3(NCDAPCOMMON*); |
---|
318 | extern NCerror buildcachenode34(NCDAPCOMMON*, |
---|
319 | DCEconstraint* constraint, |
---|
320 | NClist* varlist, |
---|
321 | NCcachenode** cachep, |
---|
322 | int isprefetch); |
---|
323 | extern NCcachenode* createnccachenode(void); |
---|
324 | extern void freenccachenode(NCDAPCOMMON*, NCcachenode* node); |
---|
325 | extern NCcache* createnccache(void); |
---|
326 | extern void freenccache(NCDAPCOMMON*, NCcache* cache); |
---|
327 | |
---|
328 | /* Add an extra function whose sole purpose is to allow |
---|
329 | configure(.ac) to test for the presence of thiscode. |
---|
330 | */ |
---|
331 | extern int nc__opendap(void); |
---|
332 | |
---|
333 | #endif /*NCCOMMON_H*/ |
---|