source: XIOS/dev/dev_olga/extern/src_netcdf4/nc.h @ 1174

Last change on this file since 1174 was 409, checked in by ymipsl, 12 years ago

Add improved nectdf internal library src

YM

  • Property svn:eol-style set to native
File size: 9.4 KB
Line 
1/*
2 *      Copyright 1996, University Corporation for Atmospheric Research
3 *      See netcdf/COPYRIGHT file for copying and redistribution conditions.
4 */
5#ifndef _NC_H_
6#define _NC_H_
7
8/*
9 *      netcdf library 'private' data structures, objects and interfaces
10 */
11#include <config.h>
12#include <stddef.h>     /* size_t */
13#ifndef HAVE_STDINT_H
14#  include "pstdint.h"  /* attempts to define uint32_t etc portably */
15#else
16#  include <stdint.h>
17#endif /* HAVE_STDINT_H */
18#include <sys/types.h>  /* off_t */
19#ifdef USE_PARALLEL
20#include <netcdf_par.h>
21#else
22#include <netcdf.h>
23#endif /* USE_PARALLEL */
24#if 0
25#include "ncio.h"       
26#include "fbits.h"
27#endif
28
29/*#ifndef HAVE_SSIZE_T
30#define ssize_t int
31#endif*/
32
33#ifndef NC_ARRAY_GROWBY
34#define NC_ARRAY_GROWBY 4
35#endif
36
37/*
38 * The extern size of an empty
39 * netcdf version 1 file.
40 * The initial value of ncp->xsz.
41 */
42#define MIN_NC_XSZ 32
43
44/* Forward */
45typedef struct NC NC; /* forward reference */
46struct ncio;
47
48/*
49 *  The internal data types
50 */
51typedef enum {
52        NC_UNSPECIFIED = 0,
53/* future       NC_BITFIELD = 7, */
54/*      NC_STRING =     8,      */
55        NC_DIMENSION =  10,
56        NC_VARIABLE =   11,
57        NC_ATTRIBUTE =  12
58} NCtype;
59
60
61/*
62 * Counted string for names and such
63 */
64typedef struct {
65        /* all xdr'd */
66        size_t nchars;
67        char *cp;
68} NC_string;
69
70/* Begin defined in string.c */
71extern void
72free_NC_string(NC_string *ncstrp);
73
74extern int
75NC_check_name(const char *name);
76
77extern NC_string *
78new_NC_string(size_t slen, const char *str);
79
80extern int
81set_NC_string(NC_string *ncstrp, const char *str);
82
83/* End defined in string.c */
84
85/*
86 * NC dimension stucture
87 */
88typedef struct {
89        /* all xdr'd */
90        NC_string *name;
91        uint32_t hash;
92        size_t size;
93} NC_dim;
94
95typedef struct NC_dimarray {
96        size_t nalloc;          /* number allocated >= nelems */
97        /* below gets xdr'd */
98        /* NCtype type = NC_DIMENSION */
99        size_t nelems;          /* length of the array */
100        NC_dim **value;
101} NC_dimarray;
102
103/* Begin defined in dim.c */
104
105extern void
106free_NC_dim(NC_dim *dimp);
107
108extern NC_dim *
109new_x_NC_dim(NC_string *name);
110
111extern int
112find_NC_Udim(const NC_dimarray *ncap, NC_dim **dimpp);
113
114/* dimarray */
115
116extern void
117free_NC_dimarrayV0(NC_dimarray *ncap);
118
119extern void
120free_NC_dimarrayV(NC_dimarray *ncap);
121
122extern int
123dup_NC_dimarrayV(NC_dimarray *ncap, const NC_dimarray *ref);
124
125extern NC_dim *
126elem_NC_dimarray(const NC_dimarray *ncap, size_t elem);
127
128/* End defined in dim.c */
129
130/*
131 * NC attribute
132 */
133typedef struct {
134        size_t xsz;             /* amount of space at xvalue */
135        /* below gets xdr'd */
136        NC_string *name;
137        nc_type type;           /* the discriminant */
138        size_t nelems;          /* length of the array */
139        void *xvalue;           /* the actual data, in external representation */
140} NC_attr;
141
142typedef struct NC_attrarray {
143        size_t nalloc;          /* number allocated >= nelems */
144        /* below gets xdr'd */
145        /* NCtype type = NC_ATTRIBUTE */
146        size_t nelems;          /* length of the array */
147        NC_attr **value;
148} NC_attrarray;
149
150/* Begin defined in attr.c */
151
152extern void
153free_NC_attr(NC_attr *attrp);
154
155extern NC_attr *
156new_x_NC_attr(
157        NC_string *strp,
158        nc_type type,
159        size_t nelems);
160
161extern NC_attr **
162NC_findattr(const NC_attrarray *ncap, const char *name);
163
164/* attrarray */
165
166extern void
167free_NC_attrarrayV0(NC_attrarray *ncap);
168
169extern void
170free_NC_attrarrayV(NC_attrarray *ncap);
171
172extern int
173dup_NC_attrarrayV(NC_attrarray *ncap, const NC_attrarray *ref);
174
175extern NC_attr *
176elem_NC_attrarray(const NC_attrarray *ncap, size_t elem);
177
178/* End defined in attr.c */
179
180
181/*
182 * NC variable: description and data
183 */
184typedef struct NC_var {
185        size_t xsz;             /* xszof 1 element */
186        size_t *shape; /* compiled info: dim->size of each dim */
187        off_t *dsizes; /* compiled info: the right to left product of shape */
188        /* below gets xdr'd */
189        NC_string *name;
190        uint32_t hash;
191        /* next two: formerly NC_iarray *assoc */ /* user definition */
192        size_t ndims;   /* assoc->count */
193        int *dimids;    /* assoc->value */
194        NC_attrarray attrs;
195        nc_type type;           /* the discriminant */
196        size_t len;             /* the total length originally allocated */
197        off_t begin;
198} NC_var;
199
200typedef struct NC_vararray {
201        size_t nalloc;          /* number allocated >= nelems */
202        /* below gets xdr'd */
203        /* NCtype type = NC_VARIABLE */
204        size_t nelems;          /* length of the array */
205        NC_var **value;
206} NC_vararray;
207
208/* Begin defined in lookup3.c */
209
210extern uint32_t
211hash_fast(const void *key, size_t length);
212
213/* End defined in lookup3.c */
214
215/* Begin defined in var.c */
216
217extern void
218free_NC_var(NC_var *varp);
219
220extern NC_var *
221new_x_NC_var(
222        NC_string *strp,
223        size_t ndims);
224
225/* vararray */
226
227extern void
228free_NC_vararrayV0(NC_vararray *ncap);
229
230extern void
231free_NC_vararrayV(NC_vararray *ncap);
232
233extern int
234dup_NC_vararrayV(NC_vararray *ncap, const NC_vararray *ref);
235
236extern int
237NC_var_shape(NC_var *varp, const NC_dimarray *dims);
238
239extern int
240NC_findvar(const NC_vararray *ncap, const char *name, NC_var **varpp);
241
242extern int
243NC_check_vlen(NC_var *varp, size_t vlen_max);
244
245extern NC_var *
246NC_lookupvar(NC *ncp, int varid);
247
248/* End defined in var.c */
249
250#define IS_RECVAR(vp) \
251        ((vp)->shape != NULL ? (*(vp)->shape == NC_UNLIMITED) : 0 )
252
253#ifdef LOCKNUMREC
254/*
255 * typedef SHMEM type
256 * for whenever the SHMEM functions can handle other than shorts
257 */
258typedef unsigned short int      ushmem_t;
259typedef short int                shmem_t;
260#endif
261
262/* Warning: fields from BEGIN COMMON to END COMMON must be same for:
263        1. NCcommon (include/ncdispatch.h)
264        2. NC (libsrc/nc.h)
265        3. NC_FILE_INFO (libsrc4/nc4internal.h)
266        4. whatever libdiskless uses
267*/
268struct NC {
269/*BEGIN COMMON (see include/ncdispatch.h: struct NCcommon) */
270        int ext_ncid;
271        int int_ncid;
272        struct NC_Dispatch* dispatch;   
273        void* dispatchdata;
274        char* path;
275        int substrate;
276        void* instance; /* per-instance data specific to netcdf3,4,dap,etc.
277                           Currently only used by librpc, will retrofit other
278                           dispatch kinds over time. */
279/*END COMMON*/
280        /* contains the previous NC during redef. */
281        struct NC *old;
282        /* flags */
283#define NC_CREAT 2      /* in create phase, cleared by ncendef */
284#define NC_INDEF 8      /* in define mode, cleared by ncendef */
285#define NC_NSYNC 0x10   /* synchronise numrecs on change */
286#define NC_HSYNC 0x20   /* synchronise whole header on change */
287#define NC_NDIRTY 0x40  /* numrecs has changed */
288#define NC_HDIRTY 0x80  /* header info has changed */
289/*      NC_NOFILL in netcdf.h, historical interface */
290        int flags;
291        struct ncio* nciop;
292        size_t chunk;   /* largest extent this layer will request from ncio->get() */
293        size_t xsz;     /* external size of this header, == var[0].begin */
294        off_t begin_var; /* position of the first (non-record) var */
295        off_t begin_rec; /* position of the first 'record' */
296        /* Don't constrain maximum size of record unnecessarily */
297#if SIZEOF_OFF_T > SIZEOF_SIZE_T
298        off_t recsize;   /* length of 'record' */
299#else
300        size_t recsize;  /* length of 'record' */
301#endif
302        /* below gets xdr'd */
303        size_t numrecs; /* number of 'records' allocated */
304        NC_dimarray dims;
305        NC_attrarray attrs;
306        NC_vararray vars;
307#ifdef LOCKNUMREC
308/* size and named indexes for the lock array protecting NC.numrecs */
309#  define LOCKNUMREC_DIM        4
310#  define LOCKNUMREC_VALUE      0
311#  define LOCKNUMREC_LOCK       1
312#  define LOCKNUMREC_SERVING    2
313#  define LOCKNUMREC_BASEPE     3
314        /* Used on Cray T3E MPP to maintain the
315         * integrity of numrecs for an unlimited dimension
316         */
317        ushmem_t lock[LOCKNUMREC_DIM];
318#endif
319};
320
321#define NC_readonly(ncp) \
322        (!fIsSet(ncp->nciop->ioflags, NC_WRITE))
323
324#define NC_IsNew(ncp) \
325        fIsSet((ncp)->flags, NC_CREAT)
326
327#define NC_indef(ncp) \
328        (NC_IsNew(ncp) || fIsSet((ncp)->flags, NC_INDEF))
329
330#define set_NC_ndirty(ncp) \
331        fSet((ncp)->flags, NC_NDIRTY)
332
333#define NC_ndirty(ncp) \
334        fIsSet((ncp)->flags, NC_NDIRTY)
335
336#define set_NC_hdirty(ncp) \
337        fSet((ncp)->flags, NC_HDIRTY)
338
339#define NC_hdirty(ncp) \
340        fIsSet((ncp)->flags, NC_HDIRTY)
341
342#define NC_dofill(ncp) \
343        (!fIsSet((ncp)->flags, NC_NOFILL))
344
345#define NC_doHsync(ncp) \
346        fIsSet((ncp)->flags, NC_HSYNC)
347
348#define NC_doNsync(ncp) \
349        fIsSet((ncp)->flags, NC_NSYNC)
350
351#ifndef LOCKNUMREC
352#  define NC_get_numrecs(ncp) \
353        ((ncp)->numrecs)
354
355#  define NC_set_numrecs(ncp, nrecs) \
356        {((ncp)->numrecs = (nrecs));}
357
358#  define NC_increase_numrecs(ncp, nrecs) \
359        {if((nrecs) > (ncp)->numrecs) ((ncp)->numrecs = (nrecs));}
360#else
361        size_t NC_get_numrecs(const NC *ncp);
362        void   NC_set_numrecs(NC *ncp, size_t nrecs);
363        void   NC_increase_numrecs(NC *ncp, size_t nrecs);
364#endif
365
366/* Begin defined in nc.c */
367
368extern int
369NC_check_id(int ncid, NC **ncpp);
370
371extern int
372nc_cktype(nc_type datatype);
373
374extern size_t
375ncx_howmany(nc_type type, size_t xbufsize);
376
377extern int
378read_numrecs(NC *ncp);
379
380extern int
381write_numrecs(NC *ncp);
382
383extern int
384NC_sync(NC *ncp);
385
386extern int
387NC_calcsize(const NC *ncp, off_t *filesizep);
388
389/* End defined in nc.c */
390/* Begin defined in v1hpg.c */
391
392extern size_t
393ncx_len_NC(const NC *ncp, size_t sizeof_off_t);
394
395extern int
396ncx_put_NC(const NC *ncp, void **xpp, off_t offset, size_t extent);
397
398extern int
399nc_get_NC( NC *ncp);
400
401/* End defined in v1hpg.c */
402/* Begin defined in putget.c */
403
404extern int
405fill_NC_var(NC *ncp, const NC_var *varp, size_t varsize, size_t recno);
406
407extern int
408nc_inq_rec(int ncid, size_t *nrecvars, int *recvarids, size_t *recsizes);
409
410extern int
411nc_get_rec(int ncid, size_t recnum, void **datap);
412
413extern int
414nc_put_rec(int ncid, size_t recnum, void *const *datap);
415
416/* End defined in putget.c */
417
418extern int add_to_NCList(NC*);
419extern void del_from_NCList(NC*);/* does not free object */
420extern NC* find_in_NCList(int ext_ncid);
421extern void free_NCList(void);/* reclaim whole list */
422extern int count_NCList(void); /* return # of entries in NClist */
423
424/* Create a pseudo file descriptor that does not
425   overlap real file descriptors
426*/
427extern int nc__pseudofd(void);
428
429#endif /* _NC_H_ */
Note: See TracBrowser for help on using the repository browser.