ncdf4a13/libsrc/nc.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright 1996, University Corporation for Atmospheric Research
00003  *      See netcdf/COPYRIGHT file for copying and redistribution conditions.
00004  */
00005 /* $Id: nc.h,v 2.80 2005/10/17 22:09:09 russ Exp $ */
00006 #ifndef _NC_H_
00007 #define _NC_H_
00008 
00009 /*
00010  *      netcdf library 'private' data structures, objects and interfaces
00011  */
00012 #include <config.h>
00013 
00014 /* If netcdf-4 is in use, rename all nc_ functions to nc3_ functions. */
00015 #ifdef USE_NETCDF4
00016 #include <netcdf3.h>
00017 #include <nc3convert.h>
00018 #endif
00019 
00020 #include        <stddef.h>      /* size_t */
00021 #include        <sys/types.h>   /* off_t */
00022 #include        "netcdf.h"
00023 #include        "ncio.h"        /* ncio */
00024 #include        "fbits.h"
00025 
00026 
00027 #ifndef NC_ARRAY_GROWBY
00028 #define NC_ARRAY_GROWBY 4
00029 #endif
00030 
00031 /*
00032  * The extern size of an empty
00033  * netcdf version 1 file.
00034  * The initial value of ncp->xsz.
00035  */
00036 #define MIN_NC_XSZ 32
00037 
00038 typedef struct NC NC; /* forward reference */
00039 
00040 /*
00041  *  The internal data types
00042  */
00043 typedef enum {
00044         NC_UNSPECIFIED = 0,
00045 /* future       NC_BITFIELD = 7, */
00046 /*      NC_STRING =     8,      */
00047         NC_DIMENSION =  10,
00048         NC_VARIABLE =   11,
00049         NC_ATTRIBUTE =  12
00050 } NCtype;
00051 
00052 
00053 /*
00054  * Counted string for names and such
00055  */
00056 typedef struct {
00057         /* all xdr'd */
00058         size_t nchars;
00059         char *cp;
00060 } NC_string;
00061 
00062 /* Begin defined in string.c */
00063 extern void
00064 free_NC_string(NC_string *ncstrp);
00065 
00066 extern int
00067 NC_check_name(const char *name);
00068 
00069 extern NC_string *
00070 new_NC_string(size_t slen, const char *str);
00071 
00072 extern int
00073 set_NC_string(NC_string *ncstrp, const char *str);
00074 
00075 /* End defined in string.c */
00076 
00077 /*
00078  * NC dimension stucture
00079  */
00080 typedef struct {
00081         /* all xdr'd */
00082         NC_string *name;
00083         size_t size;
00084 } NC_dim;
00085 
00086 typedef struct NC_dimarray {
00087         size_t nalloc;          /* number allocated >= nelems */
00088         /* below gets xdr'd */
00089         /* NCtype type = NC_DIMENSION */
00090         size_t nelems;          /* length of the array */
00091         NC_dim **value;
00092 } NC_dimarray;
00093 
00094 /* Begin defined in dim.c */
00095 
00096 extern void
00097 free_NC_dim(NC_dim *dimp);
00098 
00099 extern NC_dim *
00100 new_x_NC_dim(NC_string *name);
00101 
00102 extern int
00103 find_NC_Udim(const NC_dimarray *ncap, NC_dim **dimpp);
00104 
00105 /* dimarray */
00106 
00107 extern void
00108 free_NC_dimarrayV0(NC_dimarray *ncap);
00109 
00110 extern void
00111 free_NC_dimarrayV(NC_dimarray *ncap);
00112 
00113 extern int
00114 dup_NC_dimarrayV(NC_dimarray *ncap, const NC_dimarray *ref);
00115 
00116 extern NC_dim *
00117 elem_NC_dimarray(const NC_dimarray *ncap, size_t elem);
00118 
00119 /* End defined in dim.c */
00120 
00121 /*
00122  * NC attribute
00123  */
00124 typedef struct {
00125         size_t xsz;             /* amount of space at xvalue */
00126         /* below gets xdr'd */
00127         NC_string *name;
00128         nc_type type;           /* the discriminant */
00129         size_t nelems;          /* length of the array */
00130         void *xvalue;           /* the actual data, in external representation */
00131 } NC_attr;
00132 
00133 typedef struct NC_attrarray {
00134         size_t nalloc;          /* number allocated >= nelems */
00135         /* below gets xdr'd */
00136         /* NCtype type = NC_ATTRIBUTE */
00137         size_t nelems;          /* length of the array */
00138         NC_attr **value;
00139 } NC_attrarray;
00140 
00141 /* Begin defined in attr.c */
00142 
00143 extern void
00144 free_NC_attr(NC_attr *attrp);
00145 
00146 extern NC_attr *
00147 new_x_NC_attr(
00148         NC_string *strp,
00149         nc_type type,
00150         size_t nelems);
00151 
00152 extern NC_attr **
00153 NC_findattr(const NC_attrarray *ncap, const char *name);
00154 
00155 /* attrarray */
00156 
00157 extern void
00158 free_NC_attrarrayV0(NC_attrarray *ncap);
00159 
00160 extern void
00161 free_NC_attrarrayV(NC_attrarray *ncap);
00162 
00163 extern int
00164 dup_NC_attrarrayV(NC_attrarray *ncap, const NC_attrarray *ref);
00165 
00166 extern NC_attr *
00167 elem_NC_attrarray(const NC_attrarray *ncap, size_t elem);
00168 
00169 /* End defined in attr.c */
00170 
00171 
00172 /*
00173  * NC variable: description and data
00174  */
00175 typedef struct {
00176         size_t xsz;             /* xszof 1 element */
00177         size_t *shape; /* compiled info: dim->size of each dim */
00178         size_t *dsizes; /* compiled info: the right to left product of shape */
00179         /* below gets xdr'd */
00180         NC_string *name;
00181         /* next two: formerly NC_iarray *assoc */ /* user definition */
00182         size_t ndims;   /* assoc->count */
00183         int *dimids;    /* assoc->value */
00184         NC_attrarray attrs;
00185         nc_type type;           /* the discriminant */
00186         size_t len;             /* the total length originally allocated */
00187         off_t begin;
00188 } NC_var;
00189 
00190 typedef struct NC_vararray {
00191         size_t nalloc;          /* number allocated >= nelems */
00192         /* below gets xdr'd */
00193         /* NCtype type = NC_VARIABLE */
00194         size_t nelems;          /* length of the array */
00195         NC_var **value;
00196 } NC_vararray;
00197 
00198 /* Begin defined in var.c */
00199 
00200 extern void
00201 free_NC_var(NC_var *varp);
00202 
00203 extern NC_var *
00204 new_x_NC_var(
00205         NC_string *strp,
00206         size_t ndims);
00207 
00208 /* vararray */
00209 
00210 extern void
00211 free_NC_vararrayV0(NC_vararray *ncap);
00212 
00213 extern void
00214 free_NC_vararrayV(NC_vararray *ncap);
00215 
00216 extern int
00217 dup_NC_vararrayV(NC_vararray *ncap, const NC_vararray *ref);
00218 
00219 extern int
00220 NC_var_shape(NC_var *varp, const NC_dimarray *dims);
00221 
00222 extern int
00223 NC_findvar(const NC_vararray *ncap, const char *name, NC_var **varpp);
00224 
00225 extern int
00226 NC_check_vlen(NC_var *varp, size_t vlen_max);
00227 
00228 extern NC_var *
00229 NC_lookupvar(NC *ncp, int varid);
00230 
00231 /* End defined in var.c */
00232 
00233 #define IS_RECVAR(vp) \
00234         ((vp)->shape != NULL ? (*(vp)->shape == NC_UNLIMITED) : 0 )
00235 
00236 #ifdef LOCKNUMREC
00237 /*
00238  * typedef SHMEM type
00239  * for whenever the SHMEM functions can handle other than shorts
00240  */
00241 typedef unsigned short int      ushmem_t;
00242 typedef short int                shmem_t;
00243 #endif
00244 
00245 struct NC {
00246         /* links to make list of open netcdf's */
00247         struct NC *next;
00248         struct NC *prev;
00249         /* contains the previous NC during redef. */
00250         struct NC *old;
00251         /* flags */
00252 #define NC_CREAT 2      /* in create phase, cleared by ncendef */
00253 #define NC_INDEF 8      /* in define mode, cleared by ncendef */
00254 #define NC_NSYNC 0x10   /* synchronise numrecs on change */
00255 #define NC_HSYNC 0x20   /* synchronise whole header on change */
00256 #define NC_NDIRTY 0x40  /* numrecs has changed */
00257 #define NC_HDIRTY 0x80  /* header info has changed */
00258 /*      NC_NOFILL in netcdf.h, historical interface */
00259         int flags;
00260         ncio *nciop;
00261         size_t chunk;   /* largest extent this layer will request from ncio->get() */
00262         size_t xsz;     /* external size of this header, == var[0].begin */
00263         off_t begin_var; /* position of the first (non-record) var */
00264         off_t begin_rec; /* position of the first 'record' */
00265         /* don't constrain maximum size of record unnecessarily */
00266 #if SIZEOF_OFF_T > SIZEOF_SIZE_T
00267         off_t recsize;   /* length of 'record' */
00268 #else
00269         size_t recsize;  /* length of 'record' */
00270 #endif
00271         /* below gets xdr'd */
00272         size_t numrecs; /* number of 'records' allocated */
00273         NC_dimarray dims;
00274         NC_attrarray attrs;
00275         NC_vararray vars;
00276 #ifdef LOCKNUMREC
00277 /* size and named indexes for the lock array protecting NC.numrecs */
00278 #  define LOCKNUMREC_DIM        4
00279 #  define LOCKNUMREC_VALUE      0
00280 #  define LOCKNUMREC_LOCK       1
00281 #  define LOCKNUMREC_SERVING    2
00282 #  define LOCKNUMREC_BASEPE     3
00283         /* Used on Cray T3E MPP to maintain the
00284          * integrity of numrecs for an unlimited dimension
00285          */
00286         ushmem_t lock[LOCKNUMREC_DIM];
00287 #endif
00288 };
00289 
00290 #define NC_readonly(ncp) \
00291         (!fIsSet(ncp->nciop->ioflags, NC_WRITE))
00292 
00293 #define NC_IsNew(ncp) \
00294         fIsSet((ncp)->flags, NC_CREAT)
00295 
00296 #define NC_indef(ncp) \
00297         (NC_IsNew(ncp) || fIsSet((ncp)->flags, NC_INDEF)) 
00298 
00299 #define set_NC_ndirty(ncp) \
00300         fSet((ncp)->flags, NC_NDIRTY)
00301 
00302 #define NC_ndirty(ncp) \
00303         fIsSet((ncp)->flags, NC_NDIRTY)
00304 
00305 #define set_NC_hdirty(ncp) \
00306         fSet((ncp)->flags, NC_HDIRTY)
00307 
00308 #define NC_hdirty(ncp) \
00309         fIsSet((ncp)->flags, NC_HDIRTY)
00310 
00311 #define NC_dofill(ncp) \
00312         (!fIsSet((ncp)->flags, NC_NOFILL))
00313 
00314 #define NC_doHsync(ncp) \
00315         fIsSet((ncp)->flags, NC_HSYNC)
00316 
00317 #define NC_doNsync(ncp) \
00318         fIsSet((ncp)->flags, NC_NSYNC)
00319 
00320 #ifndef LOCKNUMREC
00321 #  define NC_get_numrecs(ncp) \
00322         ((ncp)->numrecs)
00323 
00324 #  define NC_set_numrecs(ncp, nrecs) \
00325         {((ncp)->numrecs = (nrecs));}
00326 
00327 #  define NC_increase_numrecs(ncp, nrecs) \
00328         {if((nrecs) > (ncp)->numrecs) ((ncp)->numrecs = (nrecs));}
00329 #else
00330         size_t NC_get_numrecs(const NC *ncp);
00331         void   NC_set_numrecs(NC *ncp, size_t nrecs);
00332         void   NC_increase_numrecs(NC *ncp, size_t nrecs);
00333 #endif
00334 
00335 /* Begin defined in nc.c */
00336 
00337 extern int
00338 NC_check_id(int ncid, NC **ncpp);
00339 
00340 extern int
00341 nc_cktype(nc_type datatype);
00342 
00343 extern size_t
00344 ncx_howmany(nc_type type, size_t xbufsize);
00345 
00346 extern int
00347 read_numrecs(NC *ncp);
00348 
00349 extern int
00350 write_numrecs(NC *ncp);
00351 
00352 extern int
00353 NC_sync(NC *ncp);
00354 
00355 extern int
00356 NC_calcsize(NC *ncp, off_t *filesizep);
00357 
00358 /* End defined in nc.c */
00359 /* Begin defined in v1hpg.c */
00360 
00361 extern size_t
00362 ncx_len_NC(const NC *ncp, size_t sizeof_off_t);
00363 
00364 extern int
00365 ncx_put_NC(const NC *ncp, void **xpp, off_t offset, size_t extent);
00366 
00367 extern int
00368 nc_get_NC( NC *ncp);
00369 
00370 /* End defined in v1hpg.c */
00371 /* Begin defined in putget.c */
00372 
00373 extern int
00374 fill_NC_var(NC *ncp, const NC_var *varp, size_t recno);
00375 
00376 extern int
00377 nc_inq_rec(int ncid, size_t *nrecvars, int *recvarids, size_t *recsizes);
00378 
00379 extern int
00380 nc_get_rec(int ncid, size_t recnum, void **datap);
00381 
00382 extern int
00383 nc_put_rec(int ncid, size_t recnum, void *const *datap);
00384 
00385 /* End defined in putget.c */
00386 
00387 #endif /* _NC_H_ */

Generated on Thu Mar 16 18:10:09 2006 for nco by  doxygen 1.4.4