[409] | 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 */ |
---|
| 45 | typedef struct NC NC; /* forward reference */ |
---|
| 46 | struct ncio; |
---|
| 47 | |
---|
| 48 | /* |
---|
| 49 | * The internal data types |
---|
| 50 | */ |
---|
| 51 | typedef 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 | */ |
---|
| 64 | typedef struct { |
---|
| 65 | /* all xdr'd */ |
---|
| 66 | size_t nchars; |
---|
| 67 | char *cp; |
---|
| 68 | } NC_string; |
---|
| 69 | |
---|
| 70 | /* Begin defined in string.c */ |
---|
| 71 | extern void |
---|
| 72 | free_NC_string(NC_string *ncstrp); |
---|
| 73 | |
---|
| 74 | extern int |
---|
| 75 | NC_check_name(const char *name); |
---|
| 76 | |
---|
| 77 | extern NC_string * |
---|
| 78 | new_NC_string(size_t slen, const char *str); |
---|
| 79 | |
---|
| 80 | extern int |
---|
| 81 | set_NC_string(NC_string *ncstrp, const char *str); |
---|
| 82 | |
---|
| 83 | /* End defined in string.c */ |
---|
| 84 | |
---|
| 85 | /* |
---|
| 86 | * NC dimension stucture |
---|
| 87 | */ |
---|
| 88 | typedef struct { |
---|
| 89 | /* all xdr'd */ |
---|
| 90 | NC_string *name; |
---|
| 91 | uint32_t hash; |
---|
| 92 | size_t size; |
---|
| 93 | } NC_dim; |
---|
| 94 | |
---|
| 95 | typedef 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 | |
---|
| 105 | extern void |
---|
| 106 | free_NC_dim(NC_dim *dimp); |
---|
| 107 | |
---|
| 108 | extern NC_dim * |
---|
| 109 | new_x_NC_dim(NC_string *name); |
---|
| 110 | |
---|
| 111 | extern int |
---|
| 112 | find_NC_Udim(const NC_dimarray *ncap, NC_dim **dimpp); |
---|
| 113 | |
---|
| 114 | /* dimarray */ |
---|
| 115 | |
---|
| 116 | extern void |
---|
| 117 | free_NC_dimarrayV0(NC_dimarray *ncap); |
---|
| 118 | |
---|
| 119 | extern void |
---|
| 120 | free_NC_dimarrayV(NC_dimarray *ncap); |
---|
| 121 | |
---|
| 122 | extern int |
---|
| 123 | dup_NC_dimarrayV(NC_dimarray *ncap, const NC_dimarray *ref); |
---|
| 124 | |
---|
| 125 | extern NC_dim * |
---|
| 126 | elem_NC_dimarray(const NC_dimarray *ncap, size_t elem); |
---|
| 127 | |
---|
| 128 | /* End defined in dim.c */ |
---|
| 129 | |
---|
| 130 | /* |
---|
| 131 | * NC attribute |
---|
| 132 | */ |
---|
| 133 | typedef 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 | |
---|
| 142 | typedef 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 | |
---|
| 152 | extern void |
---|
| 153 | free_NC_attr(NC_attr *attrp); |
---|
| 154 | |
---|
| 155 | extern NC_attr * |
---|
| 156 | new_x_NC_attr( |
---|
| 157 | NC_string *strp, |
---|
| 158 | nc_type type, |
---|
| 159 | size_t nelems); |
---|
| 160 | |
---|
| 161 | extern NC_attr ** |
---|
| 162 | NC_findattr(const NC_attrarray *ncap, const char *name); |
---|
| 163 | |
---|
| 164 | /* attrarray */ |
---|
| 165 | |
---|
| 166 | extern void |
---|
| 167 | free_NC_attrarrayV0(NC_attrarray *ncap); |
---|
| 168 | |
---|
| 169 | extern void |
---|
| 170 | free_NC_attrarrayV(NC_attrarray *ncap); |
---|
| 171 | |
---|
| 172 | extern int |
---|
| 173 | dup_NC_attrarrayV(NC_attrarray *ncap, const NC_attrarray *ref); |
---|
| 174 | |
---|
| 175 | extern NC_attr * |
---|
| 176 | elem_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 | */ |
---|
| 184 | typedef 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 | |
---|
| 200 | typedef 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 | |
---|
| 210 | extern uint32_t |
---|
| 211 | hash_fast(const void *key, size_t length); |
---|
| 212 | |
---|
| 213 | /* End defined in lookup3.c */ |
---|
| 214 | |
---|
| 215 | /* Begin defined in var.c */ |
---|
| 216 | |
---|
| 217 | extern void |
---|
| 218 | free_NC_var(NC_var *varp); |
---|
| 219 | |
---|
| 220 | extern NC_var * |
---|
| 221 | new_x_NC_var( |
---|
| 222 | NC_string *strp, |
---|
| 223 | size_t ndims); |
---|
| 224 | |
---|
| 225 | /* vararray */ |
---|
| 226 | |
---|
| 227 | extern void |
---|
| 228 | free_NC_vararrayV0(NC_vararray *ncap); |
---|
| 229 | |
---|
| 230 | extern void |
---|
| 231 | free_NC_vararrayV(NC_vararray *ncap); |
---|
| 232 | |
---|
| 233 | extern int |
---|
| 234 | dup_NC_vararrayV(NC_vararray *ncap, const NC_vararray *ref); |
---|
| 235 | |
---|
| 236 | extern int |
---|
| 237 | NC_var_shape(NC_var *varp, const NC_dimarray *dims); |
---|
| 238 | |
---|
| 239 | extern int |
---|
| 240 | NC_findvar(const NC_vararray *ncap, const char *name, NC_var **varpp); |
---|
| 241 | |
---|
| 242 | extern int |
---|
| 243 | NC_check_vlen(NC_var *varp, size_t vlen_max); |
---|
| 244 | |
---|
| 245 | extern NC_var * |
---|
| 246 | NC_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 | */ |
---|
| 258 | typedef unsigned short int ushmem_t; |
---|
| 259 | typedef 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 | */ |
---|
| 268 | struct 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 | |
---|
| 368 | extern int |
---|
| 369 | NC_check_id(int ncid, NC **ncpp); |
---|
| 370 | |
---|
| 371 | extern int |
---|
| 372 | nc_cktype(nc_type datatype); |
---|
| 373 | |
---|
| 374 | extern size_t |
---|
| 375 | ncx_howmany(nc_type type, size_t xbufsize); |
---|
| 376 | |
---|
| 377 | extern int |
---|
| 378 | read_numrecs(NC *ncp); |
---|
| 379 | |
---|
| 380 | extern int |
---|
| 381 | write_numrecs(NC *ncp); |
---|
| 382 | |
---|
| 383 | extern int |
---|
| 384 | NC_sync(NC *ncp); |
---|
| 385 | |
---|
| 386 | extern int |
---|
| 387 | NC_calcsize(const NC *ncp, off_t *filesizep); |
---|
| 388 | |
---|
| 389 | /* End defined in nc.c */ |
---|
| 390 | /* Begin defined in v1hpg.c */ |
---|
| 391 | |
---|
| 392 | extern size_t |
---|
| 393 | ncx_len_NC(const NC *ncp, size_t sizeof_off_t); |
---|
| 394 | |
---|
| 395 | extern int |
---|
| 396 | ncx_put_NC(const NC *ncp, void **xpp, off_t offset, size_t extent); |
---|
| 397 | |
---|
| 398 | extern int |
---|
| 399 | nc_get_NC( NC *ncp); |
---|
| 400 | |
---|
| 401 | /* End defined in v1hpg.c */ |
---|
| 402 | /* Begin defined in putget.c */ |
---|
| 403 | |
---|
| 404 | extern int |
---|
| 405 | fill_NC_var(NC *ncp, const NC_var *varp, size_t varsize, size_t recno); |
---|
| 406 | |
---|
| 407 | extern int |
---|
| 408 | nc_inq_rec(int ncid, size_t *nrecvars, int *recvarids, size_t *recsizes); |
---|
| 409 | |
---|
| 410 | extern int |
---|
| 411 | nc_get_rec(int ncid, size_t recnum, void **datap); |
---|
| 412 | |
---|
| 413 | extern int |
---|
| 414 | nc_put_rec(int ncid, size_t recnum, void *const *datap); |
---|
| 415 | |
---|
| 416 | /* End defined in putget.c */ |
---|
| 417 | |
---|
| 418 | extern int add_to_NCList(NC*); |
---|
| 419 | extern void del_from_NCList(NC*);/* does not free object */ |
---|
| 420 | extern NC* find_in_NCList(int ext_ncid); |
---|
| 421 | extern void free_NCList(void);/* reclaim whole list */ |
---|
| 422 | extern 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 | */ |
---|
| 427 | extern int nc__pseudofd(void); |
---|
| 428 | |
---|
| 429 | #endif /* _NC_H_ */ |
---|