/* Read a NC_dimarray from the header */ static int v1h_get_NC_dimarray(v1hs *gsp, NC_dimarray *ncap) { int status; NCtype type = NC_UNSPECIFIED; assert(gsp != NULL && gsp->pos != NULL); assert(ncap != NULL); assert(ncap->value == NULL); status = v1h_get_NCtype(gsp, &type); if(status != NC_NOERR) return status; status = v1h_get_size_t(gsp, &ncap->nelems); if(status != NC_NOERR) return status; if(ncap->nelems == 0) return NC_NOERR; /* else */ if(type != NC_DIMENSION) return EINVAL; ncap->value = (NC_dim **) malloc(ncap->nelems * sizeof(NC_dim *)); if(ncap->value == NULL) return NC_ENOMEM; ncap->nalloc = ncap->nelems; ncap->hashmap = NC_hashmapCreate(ncap->nelems); { NC_dim **dpp = ncap->value; NC_dim *const *const end = &dpp[ncap->nelems]; for( /*NADA*/; dpp < end; dpp++) { status = v1h_get_NC_dim(gsp, dpp); if(status) { ncap->nelems = (size_t)(dpp - ncap->value); free_NC_dimarrayV(ncap); return status; } { int dimid = (size_t)(dpp - ncap->value); NC_hashmapAddDim(ncap, dimid, (*dpp)->name->cp); } } } return NC_NOERR; }
static void free_NC(NC *ncp) { if(ncp == NULL) return; free_NC_dimarrayV(&ncp->dims); free_NC_attrarrayV(&ncp->attrs); free_NC_vararrayV(&ncp->vars); #if _CRAYMPP && defined(LOCKNUMREC) shfree(ncp); #else free(ncp); #endif /* _CRAYMPP && LOCKNUMREC */ }
/* * Read in the header * It is expensive. */ static int read_NC(NC *ncp) { int status = NC_NOERR; free_NC_dimarrayV(&ncp->dims); free_NC_attrarrayV(&ncp->attrs); free_NC_vararrayV(&ncp->vars); status = nc_get_NC(ncp); if(status == NC_NOERR) fClr(ncp->flags, NC_NDIRTY | NC_HDIRTY); return status; }
int dup_NC_dimarrayV(NC_dimarray *ncap, const NC_dimarray *ref) { int status = NC_NOERR; assert(ref != NULL); assert(ncap != NULL); if(ref->nelems != 0) { const size_t sz = ref->nelems * sizeof(NC_dim *); ncap->value = (NC_dim **) malloc(sz); if(ncap->value == NULL) return NC_ENOMEM; (void) memset(ncap->value, 0, sz); ncap->nalloc = ref->nelems; } ncap->nelems = 0; { NC_dim **dpp = ncap->value; const NC_dim **drpp = (const NC_dim **)ref->value; NC_dim *const *const end = &dpp[ref->nelems]; for( /*NADA*/; dpp < end; drpp++, dpp++, ncap->nelems++) { *dpp = dup_NC_dim(*drpp); if(*dpp == NULL) { status = NC_ENOMEM; break; } } } if(status != NC_NOERR) { free_NC_dimarrayV(ncap); return status; } assert(ncap->nelems == ref->nelems); return NC_NOERR; }