00001
00002
00003
00004
00005
00006 #ifndef _NC_H_
00007 #define _NC_H_
00008
00009
00010
00011
00012 #include <config.h>
00013
00014
00015 #ifdef USE_NETCDF4
00016 #include <netcdf3.h>
00017 #include <nc3convert.h>
00018 #endif
00019
00020 #include <stddef.h>
00021 #include <sys/types.h>
00022 #include "netcdf.h"
00023 #include "ncio.h"
00024 #include "fbits.h"
00025
00026
00027 #ifndef NC_ARRAY_GROWBY
00028 #define NC_ARRAY_GROWBY 4
00029 #endif
00030
00031
00032
00033
00034
00035
00036 #define MIN_NC_XSZ 32
00037
00038 typedef struct NC NC;
00039
00040
00041
00042
00043 typedef enum {
00044 NC_UNSPECIFIED = 0,
00045
00046
00047 NC_DIMENSION = 10,
00048 NC_VARIABLE = 11,
00049 NC_ATTRIBUTE = 12
00050 } NCtype;
00051
00052
00053
00054
00055
00056 typedef struct {
00057
00058 size_t nchars;
00059 char *cp;
00060 } NC_string;
00061
00062
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
00076
00077
00078
00079
00080 typedef struct {
00081
00082 NC_string *name;
00083 size_t size;
00084 } NC_dim;
00085
00086 typedef struct NC_dimarray {
00087 size_t nalloc;
00088
00089
00090 size_t nelems;
00091 NC_dim **value;
00092 } NC_dimarray;
00093
00094
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
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
00120
00121
00122
00123
00124 typedef struct {
00125 size_t xsz;
00126
00127 NC_string *name;
00128 nc_type type;
00129 size_t nelems;
00130 void *xvalue;
00131 } NC_attr;
00132
00133 typedef struct NC_attrarray {
00134 size_t nalloc;
00135
00136
00137 size_t nelems;
00138 NC_attr **value;
00139 } NC_attrarray;
00140
00141
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
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
00170
00171
00172
00173
00174
00175 typedef struct {
00176 size_t xsz;
00177 size_t *shape;
00178 size_t *dsizes;
00179
00180 NC_string *name;
00181
00182 size_t ndims;
00183 int *dimids;
00184 NC_attrarray attrs;
00185 nc_type type;
00186 size_t len;
00187 off_t begin;
00188 } NC_var;
00189
00190 typedef struct NC_vararray {
00191 size_t nalloc;
00192
00193
00194 size_t nelems;
00195 NC_var **value;
00196 } NC_vararray;
00197
00198
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
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
00232
00233 #define IS_RECVAR(vp) \
00234 ((vp)->shape != NULL ? (*(vp)->shape == NC_UNLIMITED) : 0 )
00235
00236 #ifdef LOCKNUMREC
00237
00238
00239
00240
00241 typedef unsigned short int ushmem_t;
00242 typedef short int shmem_t;
00243 #endif
00244
00245 struct NC {
00246
00247 struct NC *next;
00248 struct NC *prev;
00249
00250 struct NC *old;
00251
00252 #define NC_CREAT 2
00253 #define NC_INDEF 8
00254 #define NC_NSYNC 0x10
00255 #define NC_HSYNC 0x20
00256 #define NC_NDIRTY 0x40
00257 #define NC_HDIRTY 0x80
00258
00259 int flags;
00260 ncio *nciop;
00261 size_t chunk;
00262 size_t xsz;
00263 off_t begin_var;
00264 off_t begin_rec;
00265
00266 #if SIZEOF_OFF_T > SIZEOF_SIZE_T
00267 off_t recsize;
00268 #else
00269 size_t recsize;
00270 #endif
00271
00272 size_t numrecs;
00273 NC_dimarray dims;
00274 NC_attrarray attrs;
00275 NC_vararray vars;
00276 #ifdef LOCKNUMREC
00277
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
00284
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
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
00359
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
00371
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
00386
00387 #endif