/* * How much space will 'nelems' of 'type' take in * external representation (as the values of an attribute)? */ static size_t ncx_len_NC_attrV(nc_type type, size_t nelems) { switch(type) { case NC_BYTE: case NC_CHAR: return ncx_len_char(nelems); case NC_SHORT: return ncx_len_short(nelems); case NC_INT: return ncx_len_int(nelems); case NC_FLOAT: return ncx_len_float(nelems); case NC_DOUBLE: return ncx_len_double(nelems); case NC_UBYTE: return ncx_len_ubyte(nelems); case NC_USHORT: return ncx_len_ushort(nelems); case NC_UINT: return ncx_len_uint(nelems); case NC_INT64: return ncx_len_int64(nelems); case NC_UINT64: return ncx_len_uint64(nelems); default: assert("ncx_len_NC_attr bad type" == 0); } return 0; }
/* Write a NC_var to the header */ static int v1h_put_NC_var(v1hs *psp, const NC_var *varp) { int status; status = v1h_put_NC_string(psp, varp->name); if(status != ENOERR) return status; status = v1h_put_size_t(psp, &varp->ndims); if(status != ENOERR) return status; if (psp->version == 5) { status = check_v1hs(psp, ncx_len_int64(varp->ndims)); if(status != ENOERR) return status; status = ncx_putn_longlong_int(&psp->pos, varp->ndims, varp->dimids); if(status != ENOERR) return status; } else { status = check_v1hs(psp, ncx_len_int(varp->ndims)); if(status != ENOERR) return status; status = ncx_putn_int_int(&psp->pos, varp->ndims, varp->dimids); if(status != ENOERR) return status; } status = v1h_put_NC_attrarray(psp, &varp->attrs); if(status != ENOERR) return status; status = v1h_put_nc_type(psp, &varp->type); if(status != ENOERR) return status; status = v1h_put_size_t(psp, &varp->len); if(status != ENOERR) return status; status = check_v1hs(psp, psp->version == 1 ? 4 : 8); /*begin*/ if(status != ENOERR) return status; status = ncx_put_off_t(&psp->pos, &varp->begin, psp->version == 1 ? 4 : 8); if(status != ENOERR) return status; return ENOERR; }
/* * How much space will the xdr'd var take. * Formerly NC_xlen_var(vpp) */ static size_t ncx_len_NC_var(const NC_var *varp, size_t sizeof_off_t) { size_t sz; assert(varp != NULL); assert(sizeof_off_t != 0); sz = ncx_len_NC_string(varp->name); sz += X_SIZEOF_SIZE_T; /* ndims */ sz += ncx_len_int(varp->ndims); /* dimids */ sz += ncx_len_NC_attrarray(&varp->attrs); sz += X_SIZEOF_NC_TYPE; /* type */ sz += X_SIZEOF_SIZE_T; /* len */ sz += sizeof_off_t; /* begin */ return(sz); }
/* * How much space will 'nelems' of 'type' take in * external representation (as the values of an attribute)? */ static size_t ncx_len_NC_attrV(nc_type type, size_t nelems) { switch(type) { case NC_BYTE: case NC_CHAR: return ncx_len_char(nelems); case NC_SHORT: return ncx_len_short(nelems); case NC_INT: return ncx_len_int(nelems); case NC_FLOAT: return ncx_len_float(nelems); case NC_DOUBLE: return ncx_len_double(nelems); case NC_NAT: break; /* Some compilers complain if enums are missing from a switch */ } /* default */ assert("ncx_len_NC_attr bad type" == 0); return 0; }
/* * How much space will the xdr'd var take. * Formerly NC_xlen_var(vpp) */ static size_t ncx_len_NC_var(const NC_var *varp, size_t sizeof_off_t, int version) { size_t sz; assert(varp != NULL); assert(sizeof_off_t != 0); sz = ncx_len_NC_string(varp->name, version); if (version == 5) { sz += X_SIZEOF_INT64; /* ndims */ sz += ncx_len_int64(varp->ndims); /* dimids */ } else { sz += X_SIZEOF_SIZE_T; /* ndims */ sz += ncx_len_int(varp->ndims); /* dimids */ } sz += ncx_len_NC_attrarray(&varp->attrs, version); sz += X_SIZEOF_NC_TYPE; /* nc_type */ sz += (version == 5) ? X_SIZEOF_INT64 : X_SIZEOF_SIZE_T; /* vsize */ sz += sizeof_off_t; /* begin */ return(sz); }
/* Read a NC_var from the header */ static int v1h_get_NC_var(v1hs *gsp, NC_var **varpp) { NC_string *strp; int status; size_t ndims; NC_var *varp; status = v1h_get_NC_string(gsp, &strp); if(status != ENOERR) return status; status = v1h_get_size_t(gsp, &ndims); if(status != ENOERR) goto unwind_name; varp = new_x_NC_var(strp, ndims); if(varp == NULL) { status = NC_ENOMEM; goto unwind_name; } if (gsp->version == 5) { status = check_v1hs(gsp, ncx_len_int64(ndims)); if(status != ENOERR) goto unwind_alloc; status = ncx_getn_longlong_int((const void **)(&gsp->pos), ndims, varp->dimids); if(status != ENOERR) goto unwind_alloc; } else { status = check_v1hs(gsp, ncx_len_int(ndims)); if(status != ENOERR) goto unwind_alloc; status = ncx_getn_int_int((const void **)(&gsp->pos), ndims, varp->dimids); if(status != ENOERR) goto unwind_alloc; } status = v1h_get_NC_attrarray(gsp, &varp->attrs); if(status != ENOERR) goto unwind_alloc; status = v1h_get_nc_type(gsp, &varp->type); if(status != ENOERR) goto unwind_alloc; status = v1h_get_size_t(gsp, &varp->len); if(status != ENOERR) goto unwind_alloc; status = check_v1hs(gsp, gsp->version == 1 ? 4 : 8); if(status != ENOERR) goto unwind_alloc; status = ncx_get_off_t((const void **)&gsp->pos, &varp->begin, gsp->version == 1 ? 4 : 8); if(status != ENOERR) goto unwind_alloc; *varpp = varp; return ENOERR; unwind_alloc: free_NC_var(varp); /* frees name */ return status; unwind_name: free_NC_string(strp); return status; }