nccommon.h 12 KB

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