From 9328ba17cb53f13a63707547c94f4715243dafdf Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Tue, 14 Mar 2023 14:34:25 -0600 Subject: [PATCH] Added generated test files for a stand-alone release. --- libsrc/attr.c | 2297 +++ libsrc/ncx.c | 39535 +++++++++++++++++++++++++++++++++++++++++ libsrc/netcdf.3 | 1387 ++ libsrc/putget.c | 21416 ++++++++++++++++++++++ nc_test/test_get.c | 12262 +++++++++++++ nc_test/test_put.c | 13910 +++++++++++++++ nc_test/test_read.c | 1970 ++ nc_test/test_write.c | 2413 +++ 8 files changed, 95190 insertions(+) create mode 100644 libsrc/attr.c create mode 100644 libsrc/ncx.c create mode 100644 libsrc/netcdf.3 create mode 100644 libsrc/putget.c create mode 100644 nc_test/test_get.c create mode 100644 nc_test/test_put.c create mode 100644 nc_test/test_read.c create mode 100644 nc_test/test_write.c diff --git a/libsrc/attr.c b/libsrc/attr.c new file mode 100644 index 0000000000..59caf8c3f1 --- /dev/null +++ b/libsrc/attr.c @@ -0,0 +1,2297 @@ +#line 5 "attr.m4" +/* Do not edit this file. It is produced from the corresponding .m4 source */ +#line 7 +/* + * Copyright 2018, University Corporation for Atmospheric Research + * See netcdf/COPYRIGHT file for copying and redistribution conditions. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#include "nc3internal.h" +#include "ncdispatch.h" +#include "nc3dispatch.h" +#include +#include +#include +#include "ncx.h" +#include "fbits.h" +#include "rnd.h" +#include "ncutf8.h" + +/* + * Free attr + * Formerly +NC_free_attr() + */ +void +free_NC_attr(NC_attr *attrp) +{ + + if(attrp == NULL) + return; + free_NC_string(attrp->name); + free(attrp); +} + + +/* + * 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; +} + + +NC_attr * +new_x_NC_attr( + NC_string *strp, + nc_type type, + size_t nelems) +{ + NC_attr *attrp; + const size_t xsz = ncx_len_NC_attrV(type, nelems); + size_t sz = M_RNDUP(sizeof(NC_attr)); + + assert(!(xsz == 0 && nelems != 0)); + + sz += xsz; + + attrp = (NC_attr *) malloc(sz); + if(attrp == NULL ) + return NULL; + + attrp->xsz = xsz; + + attrp->name = strp; + attrp->type = type; + attrp->nelems = nelems; + if(xsz != 0) + attrp->xvalue = (char *)attrp + M_RNDUP(sizeof(NC_attr)); + else + attrp->xvalue = NULL; + + return(attrp); +} + + +/* + * Formerly +NC_new_attr(name,type,count,value) + */ +static NC_attr * +new_NC_attr( + const char *uname, + nc_type type, + size_t nelems) +{ + NC_string *strp = NULL; + NC_attr *attrp = NULL; + char *name = NULL; + int stat = NC_NOERR; + + stat = nc_utf8_normalize((const unsigned char *)uname,(unsigned char**)&name); + if(stat != NC_NOERR) + goto done; + assert(name != NULL && *name != 0); + + strp = new_NC_string(strlen(name), name); + if(strp == NULL) + goto done; + + attrp = new_x_NC_attr(strp, type, nelems); + if(attrp == NULL) + { + free_NC_string(strp); + goto done; + } +done: + if(name) free(name); + return (attrp); +} + + +static NC_attr * +dup_NC_attr(const NC_attr *rattrp) +{ + NC_attr *attrp = new_NC_attr(rattrp->name->cp, + rattrp->type, rattrp->nelems); + if(attrp == NULL) + return NULL; + if(attrp->xvalue != NULL && rattrp->xvalue != NULL) + (void) memcpy(attrp->xvalue, rattrp->xvalue, rattrp->xsz); + return attrp; +} + +/* attrarray */ + +/* + * Free the stuff "in" (referred to by) an NC_attrarray. + * Leaves the array itself allocated. + */ +void +free_NC_attrarrayV0(NC_attrarray *ncap) +{ + assert(ncap != NULL); + + if(ncap->nelems == 0) + return; + + assert(ncap->value != NULL); + + { + NC_attr **app = ncap->value; + NC_attr *const *const end = &app[ncap->nelems]; + for( /*NADA*/; app < end; app++) + { + free_NC_attr(*app); + *app = NULL; + } + } + ncap->nelems = 0; +} + + +/* + * Free NC_attrarray values. + * formerly +NC_free_array() + */ +void +free_NC_attrarrayV(NC_attrarray *ncap) +{ + assert(ncap != NULL); + + if(ncap->nalloc == 0) + return; + + assert(ncap->value != NULL); + + free_NC_attrarrayV0(ncap); + + free(ncap->value); + ncap->value = NULL; + ncap->nalloc = 0; +} + + +int +dup_NC_attrarrayV(NC_attrarray *ncap, const NC_attrarray *ref) +{ + int status = NC_NOERR; + + assert(ref != NULL); + assert(ncap != NULL); + + if(ref->nelems != 0) + { + const size_t sz = ref->nelems * sizeof(NC_attr *); + ncap->value = (NC_attr **) malloc(sz); + if(ncap->value == NULL) + return NC_ENOMEM; + + (void) memset(ncap->value, 0, sz); + ncap->nalloc = ref->nelems; + } + + ncap->nelems = 0; + { + NC_attr **app = ncap->value; + const NC_attr **drpp = (const NC_attr **)ref->value; + NC_attr *const *const end = &app[ref->nelems]; + for( /*NADA*/; app < end; drpp++, app++, ncap->nelems++) + { + *app = dup_NC_attr(*drpp); + if(*app == NULL) + { + status = NC_ENOMEM; + break; + } + } + } + + if(status != NC_NOERR) + { + free_NC_attrarrayV(ncap); + return status; + } + + assert(ncap->nelems == ref->nelems); + + return NC_NOERR; +} + + +/* + * Add a new handle on the end of an array of handles + * Formerly +NC_incr_array(array, tail) + */ +static int +incr_NC_attrarray(NC_attrarray *ncap, NC_attr *newelemp) +{ + NC_attr **vp; + + assert(ncap != NULL); + + if(ncap->nalloc == 0) + { + assert(ncap->nelems == 0); + vp = (NC_attr **) malloc(NC_ARRAY_GROWBY * sizeof(NC_attr *)); + if(vp == NULL) + return NC_ENOMEM; + + ncap->value = vp; + ncap->nalloc = NC_ARRAY_GROWBY; + } + else if(ncap->nelems +1 > ncap->nalloc) + { + vp = (NC_attr **) realloc(ncap->value, + (ncap->nalloc + NC_ARRAY_GROWBY) * sizeof(NC_attr *)); + if(vp == NULL) + return NC_ENOMEM; + + ncap->value = vp; + ncap->nalloc += NC_ARRAY_GROWBY; + } + + if(newelemp != NULL) + { + ncap->value[ncap->nelems] = newelemp; + ncap->nelems++; + } + return NC_NOERR; +} + + +NC_attr * +elem_NC_attrarray(const NC_attrarray *ncap, size_t elem) +{ + assert(ncap != NULL); + /* cast needed for braindead systems with signed size_t */ + if(ncap->nelems == 0 || (unsigned long) elem >= ncap->nelems) + return NULL; + + assert(ncap->value != NULL); + + return ncap->value[elem]; +} + +/* End attarray per se */ + +/* + * Given ncp and varid, return ptr to array of attributes + * else NULL on error + */ +static NC_attrarray * +NC_attrarray0(NC3_INFO* ncp, int varid) +{ + NC_attrarray *ap; + + if(varid == NC_GLOBAL) /* Global attribute, attach to cdf */ + { + ap = &ncp->attrs; + } + else if(varid >= 0 && (size_t) varid < ncp->vars.nelems) + { + NC_var **vpp; + vpp = (NC_var **)ncp->vars.value; + vpp += varid; + ap = &(*vpp)->attrs; + } else { + ap = NULL; + } + return(ap); +} + + +/* + * Step thru NC_ATTRIBUTE array, seeking match on name. + * return match or NULL if Not Found or out of memory. + */ +NC_attr ** +NC_findattr(const NC_attrarray *ncap, const char *uname) +{ + NC_attr **attrpp = NULL; + size_t attrid; + size_t slen; + char *name = NULL; + int stat = NC_NOERR; + + assert(ncap != NULL); + + if(ncap->nelems == 0) + goto done; + + /* normalized version of uname */ + stat = nc_utf8_normalize((const unsigned char *)uname,(unsigned char**)&name); + if(stat != NC_NOERR) + goto done; /* TODO: need better way to indicate no memory */ + slen = strlen(name); + + attrpp = (NC_attr **) ncap->value; + for(attrid = 0; attrid < ncap->nelems; attrid++, attrpp++) + { + if(strlen((*attrpp)->name->cp) == slen && + strncmp((*attrpp)->name->cp, name, slen) == 0) + goto done; + } + attrpp = NULL; /* not found */ +done: + if(name) free(name); + return (attrpp); /* Normal return */ +} + + +/* + * Look up by ncid, varid and name, return NULL if not found + */ +static int +NC_lookupattr(int ncid, + int varid, + const char *name, /* attribute name */ + NC_attr **attrpp) /* modified on return */ +{ + int status; + NC* nc; + NC3_INFO *ncp; + NC_attrarray *ncap; + NC_attr **tmp; + + status = NC_check_id(ncid, &nc); + if(status != NC_NOERR) + return status; + ncp = NC3_DATA(nc); + + ncap = NC_attrarray0(ncp, varid); + if(ncap == NULL) + return NC_ENOTVAR; + + if(name == NULL) + return NC_EBADNAME; + + tmp = NC_findattr(ncap, name); + if(tmp == NULL) + return NC_ENOTATT; + + if(attrpp != NULL) + *attrpp = *tmp; + + return NC_NOERR; +} + +/* Public */ + +int +NC3_inq_attname(int ncid, int varid, int attnum, char *name) +{ + int status; + NC* nc; + NC3_INFO *ncp; + NC_attrarray *ncap; + NC_attr *attrp; + + status = NC_check_id(ncid, &nc); + if(status != NC_NOERR) + return status; + ncp = NC3_DATA(nc); + + ncap = NC_attrarray0(ncp, varid); + if(ncap == NULL) + return NC_ENOTVAR; + + attrp = elem_NC_attrarray(ncap, (size_t)attnum); + if(attrp == NULL) + return NC_ENOTATT; + + (void) strncpy(name, attrp->name->cp, attrp->name->nchars); + name[attrp->name->nchars] = 0; + + return NC_NOERR; +} + + +int +NC3_inq_attid(int ncid, int varid, const char *name, int *attnump) +{ + int status; + NC *nc; + NC3_INFO* ncp; + NC_attrarray *ncap; + NC_attr **attrpp; + + status = NC_check_id(ncid, &nc); + if(status != NC_NOERR) + return status; + ncp = NC3_DATA(nc); + + ncap = NC_attrarray0(ncp, varid); + if(ncap == NULL) + return NC_ENOTVAR; + + + attrpp = NC_findattr(ncap, name); + if(attrpp == NULL) + return NC_ENOTATT; + + if(attnump != NULL) + *attnump = (int)(attrpp - ncap->value); + + return NC_NOERR; +} + +int +NC3_inq_att(int ncid, + int varid, + const char *name, /* input, attribute name */ + nc_type *datatypep, + size_t *lenp) +{ + int status; + NC_attr *attrp; + + status = NC_lookupattr(ncid, varid, name, &attrp); + if(status != NC_NOERR) + return status; + + if(datatypep != NULL) + *datatypep = attrp->type; + if(lenp != NULL) + *lenp = attrp->nelems; + + return NC_NOERR; +} + + +int +NC3_rename_att( int ncid, int varid, const char *name, const char *unewname) +{ + int status = NC_NOERR; + NC *nc = NULL; + NC3_INFO* ncp = NULL; + NC_attrarray *ncap = NULL; + NC_attr **tmp = NULL; + NC_attr *attrp = NULL; + NC_string *newStr, *old; + char *newname = NULL; /* normalized version */ + +/* start sortof inline clone of NC_lookupattr() */ + + status = NC_check_id(ncid, &nc); + if(status != NC_NOERR) + goto done; + ncp = NC3_DATA(nc); + + if(NC_readonly(ncp)) + {status = NC_EPERM; goto done;} + + ncap = NC_attrarray0(ncp, varid); + if(ncap == NULL) + {status = NC_ENOTVAR; goto done;} + + status = NC_check_name(unewname); + if(status != NC_NOERR) + goto done; + + tmp = NC_findattr(ncap, name); + if(tmp == NULL) + {status = NC_ENOTATT; goto done;} + attrp = *tmp; +/* end inline clone NC_lookupattr() */ + + if(NC_findattr(ncap, unewname) != NULL) + {status = NC_ENAMEINUSE; goto done;} /* name in use */ + + old = attrp->name; + status = nc_utf8_normalize((const unsigned char *)unewname,(unsigned char**)&newname); + if(status != NC_NOERR) + goto done; + if(NC_indef(ncp)) + { + newStr = new_NC_string(strlen(newname), newname); + if( newStr == NULL) + {status = NC_ENOMEM; goto done;} + attrp->name = newStr; + free_NC_string(old); + goto done; + } + /* else not in define mode */ + + /* If new name is longer than old, then complain, + but otherwise, no change (test is same as set_NC_string)*/ + if(old->nchars < strlen(newname)) + {status = NC_ENOTINDEFINE; goto done;} + + status = set_NC_string(old, newname); + if( status != NC_NOERR) + goto done; + + set_NC_hdirty(ncp); + + if(NC_doHsync(ncp)) + { + status = NC_sync(ncp); + if(status != NC_NOERR) + goto done; + } +done: + if(newname) free(newname); + return status; +} + +int +NC3_del_att(int ncid, int varid, const char *uname) +{ + int status = NC_NOERR; + NC *nc = NULL; + NC3_INFO* ncp = NULL; + NC_attrarray *ncap = NULL; + NC_attr **attrpp = NULL; + NC_attr *old = NULL; + int attrid; + size_t slen; + char* name = NULL; + + status = NC_check_id(ncid, &nc); + if(status != NC_NOERR) + goto done; + ncp = NC3_DATA(nc); + + if(!NC_indef(ncp)) + {status = NC_ENOTINDEFINE; goto done;} + + ncap = NC_attrarray0(ncp, varid); + if(ncap == NULL) + {status = NC_ENOTVAR; goto done;} + + status = nc_utf8_normalize((const unsigned char *)uname,(unsigned char**)&name); + if(status != NC_NOERR) + goto done; + +/* start sortof inline NC_findattr() */ + slen = strlen(name); + + attrpp = (NC_attr **) ncap->value; + for(attrid = 0; (size_t) attrid < ncap->nelems; attrid++, attrpp++) + { + if( slen == (*attrpp)->name->nchars && + strncmp(name, (*attrpp)->name->cp, slen) == 0) + { + old = *attrpp; + break; + } + } + if( (size_t) attrid == ncap->nelems ) + {status = NC_ENOTATT; goto done;} +/* end inline NC_findattr() */ + + /* shuffle down */ + for(attrid++; (size_t) attrid < ncap->nelems; attrid++) + { + *attrpp = *(attrpp + 1); + attrpp++; + } + *attrpp = NULL; + /* decrement count */ + ncap->nelems--; + + free_NC_attr(old); + +done: + if(name) free(name); + return status; +} + +#line 713 + +static int +#line 714 +ncx_pad_putn_Iuchar(void **xpp, size_t nelems, const uchar *tp, nc_type type, void *fillp) +#line 714 +{ +#line 714 + switch(type) { +#line 714 + case NC_CHAR: +#line 714 + return NC_ECHAR; +#line 714 + case NC_BYTE: +#line 714 + return ncx_pad_putn_schar_uchar(xpp, nelems, tp, fillp); +#line 714 + case NC_SHORT: +#line 714 + return ncx_pad_putn_short_uchar(xpp, nelems, tp, fillp); +#line 714 + case NC_INT: +#line 714 + return ncx_putn_int_uchar(xpp, nelems, tp, fillp); +#line 714 + case NC_FLOAT: +#line 714 + return ncx_putn_float_uchar(xpp, nelems, tp, fillp); +#line 714 + case NC_DOUBLE: +#line 714 + return ncx_putn_double_uchar(xpp, nelems, tp, fillp); +#line 714 + case NC_UBYTE: +#line 714 + return ncx_pad_putn_uchar_uchar(xpp, nelems, tp, fillp); +#line 714 + case NC_USHORT: +#line 714 + return ncx_putn_ushort_uchar(xpp, nelems, tp, fillp); +#line 714 + case NC_UINT: +#line 714 + return ncx_putn_uint_uchar(xpp, nelems, tp, fillp); +#line 714 + case NC_INT64: +#line 714 + return ncx_putn_longlong_uchar(xpp, nelems, tp, fillp); +#line 714 + case NC_UINT64: +#line 714 + return ncx_putn_ulonglong_uchar(xpp, nelems, tp, fillp); +#line 714 + default: +#line 714 + assert("ncx_pad_putn_Iuchar invalid type" == 0); +#line 714 + } +#line 714 + return NC_EBADTYPE; +#line 714 +} +#line 714 + +static int +#line 715 +ncx_pad_getn_Iuchar(const void **xpp, size_t nelems, uchar *tp, nc_type type) +#line 715 +{ +#line 715 + switch(type) { +#line 715 + case NC_CHAR: +#line 715 + return NC_ECHAR; +#line 715 + case NC_BYTE: +#line 715 + return ncx_pad_getn_schar_uchar(xpp, nelems, tp); +#line 715 + case NC_SHORT: +#line 715 + return ncx_pad_getn_short_uchar(xpp, nelems, tp); +#line 715 + case NC_INT: +#line 715 + return ncx_getn_int_uchar(xpp, nelems, tp); +#line 715 + case NC_FLOAT: +#line 715 + return ncx_getn_float_uchar(xpp, nelems, tp); +#line 715 + case NC_DOUBLE: +#line 715 + return ncx_getn_double_uchar(xpp, nelems, tp); +#line 715 + case NC_UBYTE: +#line 715 + return ncx_pad_getn_uchar_uchar(xpp, nelems, tp); +#line 715 + case NC_USHORT: +#line 715 + return ncx_getn_ushort_uchar(xpp, nelems, tp); +#line 715 + case NC_UINT: +#line 715 + return ncx_getn_uint_uchar(xpp, nelems, tp); +#line 715 + case NC_INT64: +#line 715 + return ncx_getn_longlong_uchar(xpp, nelems, tp); +#line 715 + case NC_UINT64: +#line 715 + return ncx_getn_ulonglong_uchar(xpp, nelems, tp); +#line 715 + default: +#line 715 + assert("ncx_pad_getn_Iuchar invalid type" == 0); +#line 715 + } +#line 715 + return NC_EBADTYPE; +#line 715 +} +#line 715 + + +static int +#line 717 +ncx_pad_putn_Ischar(void **xpp, size_t nelems, const schar *tp, nc_type type, void *fillp) +#line 717 +{ +#line 717 + switch(type) { +#line 717 + case NC_CHAR: +#line 717 + return NC_ECHAR; +#line 717 + case NC_BYTE: +#line 717 + return ncx_pad_putn_schar_schar(xpp, nelems, tp, fillp); +#line 717 + case NC_SHORT: +#line 717 + return ncx_pad_putn_short_schar(xpp, nelems, tp, fillp); +#line 717 + case NC_INT: +#line 717 + return ncx_putn_int_schar(xpp, nelems, tp, fillp); +#line 717 + case NC_FLOAT: +#line 717 + return ncx_putn_float_schar(xpp, nelems, tp, fillp); +#line 717 + case NC_DOUBLE: +#line 717 + return ncx_putn_double_schar(xpp, nelems, tp, fillp); +#line 717 + case NC_UBYTE: +#line 717 + return ncx_pad_putn_uchar_schar(xpp, nelems, tp, fillp); +#line 717 + case NC_USHORT: +#line 717 + return ncx_putn_ushort_schar(xpp, nelems, tp, fillp); +#line 717 + case NC_UINT: +#line 717 + return ncx_putn_uint_schar(xpp, nelems, tp, fillp); +#line 717 + case NC_INT64: +#line 717 + return ncx_putn_longlong_schar(xpp, nelems, tp, fillp); +#line 717 + case NC_UINT64: +#line 717 + return ncx_putn_ulonglong_schar(xpp, nelems, tp, fillp); +#line 717 + default: +#line 717 + assert("ncx_pad_putn_Ischar invalid type" == 0); +#line 717 + } +#line 717 + return NC_EBADTYPE; +#line 717 +} +#line 717 + +static int +#line 718 +ncx_pad_getn_Ischar(const void **xpp, size_t nelems, schar *tp, nc_type type) +#line 718 +{ +#line 718 + switch(type) { +#line 718 + case NC_CHAR: +#line 718 + return NC_ECHAR; +#line 718 + case NC_BYTE: +#line 718 + return ncx_pad_getn_schar_schar(xpp, nelems, tp); +#line 718 + case NC_SHORT: +#line 718 + return ncx_pad_getn_short_schar(xpp, nelems, tp); +#line 718 + case NC_INT: +#line 718 + return ncx_getn_int_schar(xpp, nelems, tp); +#line 718 + case NC_FLOAT: +#line 718 + return ncx_getn_float_schar(xpp, nelems, tp); +#line 718 + case NC_DOUBLE: +#line 718 + return ncx_getn_double_schar(xpp, nelems, tp); +#line 718 + case NC_UBYTE: +#line 718 + return ncx_pad_getn_uchar_schar(xpp, nelems, tp); +#line 718 + case NC_USHORT: +#line 718 + return ncx_getn_ushort_schar(xpp, nelems, tp); +#line 718 + case NC_UINT: +#line 718 + return ncx_getn_uint_schar(xpp, nelems, tp); +#line 718 + case NC_INT64: +#line 718 + return ncx_getn_longlong_schar(xpp, nelems, tp); +#line 718 + case NC_UINT64: +#line 718 + return ncx_getn_ulonglong_schar(xpp, nelems, tp); +#line 718 + default: +#line 718 + assert("ncx_pad_getn_Ischar invalid type" == 0); +#line 718 + } +#line 718 + return NC_EBADTYPE; +#line 718 +} +#line 718 + + +static int +#line 720 +ncx_pad_putn_Ishort(void **xpp, size_t nelems, const short *tp, nc_type type, void *fillp) +#line 720 +{ +#line 720 + switch(type) { +#line 720 + case NC_CHAR: +#line 720 + return NC_ECHAR; +#line 720 + case NC_BYTE: +#line 720 + return ncx_pad_putn_schar_short(xpp, nelems, tp, fillp); +#line 720 + case NC_SHORT: +#line 720 + return ncx_pad_putn_short_short(xpp, nelems, tp, fillp); +#line 720 + case NC_INT: +#line 720 + return ncx_putn_int_short(xpp, nelems, tp, fillp); +#line 720 + case NC_FLOAT: +#line 720 + return ncx_putn_float_short(xpp, nelems, tp, fillp); +#line 720 + case NC_DOUBLE: +#line 720 + return ncx_putn_double_short(xpp, nelems, tp, fillp); +#line 720 + case NC_UBYTE: +#line 720 + return ncx_pad_putn_uchar_short(xpp, nelems, tp, fillp); +#line 720 + case NC_USHORT: +#line 720 + return ncx_putn_ushort_short(xpp, nelems, tp, fillp); +#line 720 + case NC_UINT: +#line 720 + return ncx_putn_uint_short(xpp, nelems, tp, fillp); +#line 720 + case NC_INT64: +#line 720 + return ncx_putn_longlong_short(xpp, nelems, tp, fillp); +#line 720 + case NC_UINT64: +#line 720 + return ncx_putn_ulonglong_short(xpp, nelems, tp, fillp); +#line 720 + default: +#line 720 + assert("ncx_pad_putn_Ishort invalid type" == 0); +#line 720 + } +#line 720 + return NC_EBADTYPE; +#line 720 +} +#line 720 + +static int +#line 721 +ncx_pad_getn_Ishort(const void **xpp, size_t nelems, short *tp, nc_type type) +#line 721 +{ +#line 721 + switch(type) { +#line 721 + case NC_CHAR: +#line 721 + return NC_ECHAR; +#line 721 + case NC_BYTE: +#line 721 + return ncx_pad_getn_schar_short(xpp, nelems, tp); +#line 721 + case NC_SHORT: +#line 721 + return ncx_pad_getn_short_short(xpp, nelems, tp); +#line 721 + case NC_INT: +#line 721 + return ncx_getn_int_short(xpp, nelems, tp); +#line 721 + case NC_FLOAT: +#line 721 + return ncx_getn_float_short(xpp, nelems, tp); +#line 721 + case NC_DOUBLE: +#line 721 + return ncx_getn_double_short(xpp, nelems, tp); +#line 721 + case NC_UBYTE: +#line 721 + return ncx_pad_getn_uchar_short(xpp, nelems, tp); +#line 721 + case NC_USHORT: +#line 721 + return ncx_getn_ushort_short(xpp, nelems, tp); +#line 721 + case NC_UINT: +#line 721 + return ncx_getn_uint_short(xpp, nelems, tp); +#line 721 + case NC_INT64: +#line 721 + return ncx_getn_longlong_short(xpp, nelems, tp); +#line 721 + case NC_UINT64: +#line 721 + return ncx_getn_ulonglong_short(xpp, nelems, tp); +#line 721 + default: +#line 721 + assert("ncx_pad_getn_Ishort invalid type" == 0); +#line 721 + } +#line 721 + return NC_EBADTYPE; +#line 721 +} +#line 721 + + +static int +#line 723 +ncx_pad_putn_Iint(void **xpp, size_t nelems, const int *tp, nc_type type, void *fillp) +#line 723 +{ +#line 723 + switch(type) { +#line 723 + case NC_CHAR: +#line 723 + return NC_ECHAR; +#line 723 + case NC_BYTE: +#line 723 + return ncx_pad_putn_schar_int(xpp, nelems, tp, fillp); +#line 723 + case NC_SHORT: +#line 723 + return ncx_pad_putn_short_int(xpp, nelems, tp, fillp); +#line 723 + case NC_INT: +#line 723 + return ncx_putn_int_int(xpp, nelems, tp, fillp); +#line 723 + case NC_FLOAT: +#line 723 + return ncx_putn_float_int(xpp, nelems, tp, fillp); +#line 723 + case NC_DOUBLE: +#line 723 + return ncx_putn_double_int(xpp, nelems, tp, fillp); +#line 723 + case NC_UBYTE: +#line 723 + return ncx_pad_putn_uchar_int(xpp, nelems, tp, fillp); +#line 723 + case NC_USHORT: +#line 723 + return ncx_putn_ushort_int(xpp, nelems, tp, fillp); +#line 723 + case NC_UINT: +#line 723 + return ncx_putn_uint_int(xpp, nelems, tp, fillp); +#line 723 + case NC_INT64: +#line 723 + return ncx_putn_longlong_int(xpp, nelems, tp, fillp); +#line 723 + case NC_UINT64: +#line 723 + return ncx_putn_ulonglong_int(xpp, nelems, tp, fillp); +#line 723 + default: +#line 723 + assert("ncx_pad_putn_Iint invalid type" == 0); +#line 723 + } +#line 723 + return NC_EBADTYPE; +#line 723 +} +#line 723 + +static int +#line 724 +ncx_pad_getn_Iint(const void **xpp, size_t nelems, int *tp, nc_type type) +#line 724 +{ +#line 724 + switch(type) { +#line 724 + case NC_CHAR: +#line 724 + return NC_ECHAR; +#line 724 + case NC_BYTE: +#line 724 + return ncx_pad_getn_schar_int(xpp, nelems, tp); +#line 724 + case NC_SHORT: +#line 724 + return ncx_pad_getn_short_int(xpp, nelems, tp); +#line 724 + case NC_INT: +#line 724 + return ncx_getn_int_int(xpp, nelems, tp); +#line 724 + case NC_FLOAT: +#line 724 + return ncx_getn_float_int(xpp, nelems, tp); +#line 724 + case NC_DOUBLE: +#line 724 + return ncx_getn_double_int(xpp, nelems, tp); +#line 724 + case NC_UBYTE: +#line 724 + return ncx_pad_getn_uchar_int(xpp, nelems, tp); +#line 724 + case NC_USHORT: +#line 724 + return ncx_getn_ushort_int(xpp, nelems, tp); +#line 724 + case NC_UINT: +#line 724 + return ncx_getn_uint_int(xpp, nelems, tp); +#line 724 + case NC_INT64: +#line 724 + return ncx_getn_longlong_int(xpp, nelems, tp); +#line 724 + case NC_UINT64: +#line 724 + return ncx_getn_ulonglong_int(xpp, nelems, tp); +#line 724 + default: +#line 724 + assert("ncx_pad_getn_Iint invalid type" == 0); +#line 724 + } +#line 724 + return NC_EBADTYPE; +#line 724 +} +#line 724 + + +static int +#line 726 +ncx_pad_putn_Ifloat(void **xpp, size_t nelems, const float *tp, nc_type type, void *fillp) +#line 726 +{ +#line 726 + switch(type) { +#line 726 + case NC_CHAR: +#line 726 + return NC_ECHAR; +#line 726 + case NC_BYTE: +#line 726 + return ncx_pad_putn_schar_float(xpp, nelems, tp, fillp); +#line 726 + case NC_SHORT: +#line 726 + return ncx_pad_putn_short_float(xpp, nelems, tp, fillp); +#line 726 + case NC_INT: +#line 726 + return ncx_putn_int_float(xpp, nelems, tp, fillp); +#line 726 + case NC_FLOAT: +#line 726 + return ncx_putn_float_float(xpp, nelems, tp, fillp); +#line 726 + case NC_DOUBLE: +#line 726 + return ncx_putn_double_float(xpp, nelems, tp, fillp); +#line 726 + case NC_UBYTE: +#line 726 + return ncx_pad_putn_uchar_float(xpp, nelems, tp, fillp); +#line 726 + case NC_USHORT: +#line 726 + return ncx_putn_ushort_float(xpp, nelems, tp, fillp); +#line 726 + case NC_UINT: +#line 726 + return ncx_putn_uint_float(xpp, nelems, tp, fillp); +#line 726 + case NC_INT64: +#line 726 + return ncx_putn_longlong_float(xpp, nelems, tp, fillp); +#line 726 + case NC_UINT64: +#line 726 + return ncx_putn_ulonglong_float(xpp, nelems, tp, fillp); +#line 726 + default: +#line 726 + assert("ncx_pad_putn_Ifloat invalid type" == 0); +#line 726 + } +#line 726 + return NC_EBADTYPE; +#line 726 +} +#line 726 + +static int +#line 727 +ncx_pad_getn_Ifloat(const void **xpp, size_t nelems, float *tp, nc_type type) +#line 727 +{ +#line 727 + switch(type) { +#line 727 + case NC_CHAR: +#line 727 + return NC_ECHAR; +#line 727 + case NC_BYTE: +#line 727 + return ncx_pad_getn_schar_float(xpp, nelems, tp); +#line 727 + case NC_SHORT: +#line 727 + return ncx_pad_getn_short_float(xpp, nelems, tp); +#line 727 + case NC_INT: +#line 727 + return ncx_getn_int_float(xpp, nelems, tp); +#line 727 + case NC_FLOAT: +#line 727 + return ncx_getn_float_float(xpp, nelems, tp); +#line 727 + case NC_DOUBLE: +#line 727 + return ncx_getn_double_float(xpp, nelems, tp); +#line 727 + case NC_UBYTE: +#line 727 + return ncx_pad_getn_uchar_float(xpp, nelems, tp); +#line 727 + case NC_USHORT: +#line 727 + return ncx_getn_ushort_float(xpp, nelems, tp); +#line 727 + case NC_UINT: +#line 727 + return ncx_getn_uint_float(xpp, nelems, tp); +#line 727 + case NC_INT64: +#line 727 + return ncx_getn_longlong_float(xpp, nelems, tp); +#line 727 + case NC_UINT64: +#line 727 + return ncx_getn_ulonglong_float(xpp, nelems, tp); +#line 727 + default: +#line 727 + assert("ncx_pad_getn_Ifloat invalid type" == 0); +#line 727 + } +#line 727 + return NC_EBADTYPE; +#line 727 +} +#line 727 + + +static int +#line 729 +ncx_pad_putn_Idouble(void **xpp, size_t nelems, const double *tp, nc_type type, void *fillp) +#line 729 +{ +#line 729 + switch(type) { +#line 729 + case NC_CHAR: +#line 729 + return NC_ECHAR; +#line 729 + case NC_BYTE: +#line 729 + return ncx_pad_putn_schar_double(xpp, nelems, tp, fillp); +#line 729 + case NC_SHORT: +#line 729 + return ncx_pad_putn_short_double(xpp, nelems, tp, fillp); +#line 729 + case NC_INT: +#line 729 + return ncx_putn_int_double(xpp, nelems, tp, fillp); +#line 729 + case NC_FLOAT: +#line 729 + return ncx_putn_float_double(xpp, nelems, tp, fillp); +#line 729 + case NC_DOUBLE: +#line 729 + return ncx_putn_double_double(xpp, nelems, tp, fillp); +#line 729 + case NC_UBYTE: +#line 729 + return ncx_pad_putn_uchar_double(xpp, nelems, tp, fillp); +#line 729 + case NC_USHORT: +#line 729 + return ncx_putn_ushort_double(xpp, nelems, tp, fillp); +#line 729 + case NC_UINT: +#line 729 + return ncx_putn_uint_double(xpp, nelems, tp, fillp); +#line 729 + case NC_INT64: +#line 729 + return ncx_putn_longlong_double(xpp, nelems, tp, fillp); +#line 729 + case NC_UINT64: +#line 729 + return ncx_putn_ulonglong_double(xpp, nelems, tp, fillp); +#line 729 + default: +#line 729 + assert("ncx_pad_putn_Idouble invalid type" == 0); +#line 729 + } +#line 729 + return NC_EBADTYPE; +#line 729 +} +#line 729 + +static int +#line 730 +ncx_pad_getn_Idouble(const void **xpp, size_t nelems, double *tp, nc_type type) +#line 730 +{ +#line 730 + switch(type) { +#line 730 + case NC_CHAR: +#line 730 + return NC_ECHAR; +#line 730 + case NC_BYTE: +#line 730 + return ncx_pad_getn_schar_double(xpp, nelems, tp); +#line 730 + case NC_SHORT: +#line 730 + return ncx_pad_getn_short_double(xpp, nelems, tp); +#line 730 + case NC_INT: +#line 730 + return ncx_getn_int_double(xpp, nelems, tp); +#line 730 + case NC_FLOAT: +#line 730 + return ncx_getn_float_double(xpp, nelems, tp); +#line 730 + case NC_DOUBLE: +#line 730 + return ncx_getn_double_double(xpp, nelems, tp); +#line 730 + case NC_UBYTE: +#line 730 + return ncx_pad_getn_uchar_double(xpp, nelems, tp); +#line 730 + case NC_USHORT: +#line 730 + return ncx_getn_ushort_double(xpp, nelems, tp); +#line 730 + case NC_UINT: +#line 730 + return ncx_getn_uint_double(xpp, nelems, tp); +#line 730 + case NC_INT64: +#line 730 + return ncx_getn_longlong_double(xpp, nelems, tp); +#line 730 + case NC_UINT64: +#line 730 + return ncx_getn_ulonglong_double(xpp, nelems, tp); +#line 730 + default: +#line 730 + assert("ncx_pad_getn_Idouble invalid type" == 0); +#line 730 + } +#line 730 + return NC_EBADTYPE; +#line 730 +} +#line 730 + + +#ifdef IGNORE +static int +#line 733 +ncx_pad_putn_Ilong(void **xpp, size_t nelems, const long *tp, nc_type type, void *fillp) +#line 733 +{ +#line 733 + switch(type) { +#line 733 + case NC_CHAR: +#line 733 + return NC_ECHAR; +#line 733 + case NC_BYTE: +#line 733 + return ncx_pad_putn_schar_long(xpp, nelems, tp, fillp); +#line 733 + case NC_SHORT: +#line 733 + return ncx_pad_putn_short_long(xpp, nelems, tp, fillp); +#line 733 + case NC_INT: +#line 733 + return ncx_putn_int_long(xpp, nelems, tp, fillp); +#line 733 + case NC_FLOAT: +#line 733 + return ncx_putn_float_long(xpp, nelems, tp, fillp); +#line 733 + case NC_DOUBLE: +#line 733 + return ncx_putn_double_long(xpp, nelems, tp, fillp); +#line 733 + case NC_UBYTE: +#line 733 + return ncx_pad_putn_uchar_long(xpp, nelems, tp, fillp); +#line 733 + case NC_USHORT: +#line 733 + return ncx_putn_ushort_long(xpp, nelems, tp, fillp); +#line 733 + case NC_UINT: +#line 733 + return ncx_putn_uint_long(xpp, nelems, tp, fillp); +#line 733 + case NC_INT64: +#line 733 + return ncx_putn_longlong_long(xpp, nelems, tp, fillp); +#line 733 + case NC_UINT64: +#line 733 + return ncx_putn_ulonglong_long(xpp, nelems, tp, fillp); +#line 733 + default: +#line 733 + assert("ncx_pad_putn_Ilong invalid type" == 0); +#line 733 + } +#line 733 + return NC_EBADTYPE; +#line 733 +} +#line 733 + +static int +#line 734 +ncx_pad_getn_Ilong(const void **xpp, size_t nelems, long *tp, nc_type type) +#line 734 +{ +#line 734 + switch(type) { +#line 734 + case NC_CHAR: +#line 734 + return NC_ECHAR; +#line 734 + case NC_BYTE: +#line 734 + return ncx_pad_getn_schar_long(xpp, nelems, tp); +#line 734 + case NC_SHORT: +#line 734 + return ncx_pad_getn_short_long(xpp, nelems, tp); +#line 734 + case NC_INT: +#line 734 + return ncx_getn_int_long(xpp, nelems, tp); +#line 734 + case NC_FLOAT: +#line 734 + return ncx_getn_float_long(xpp, nelems, tp); +#line 734 + case NC_DOUBLE: +#line 734 + return ncx_getn_double_long(xpp, nelems, tp); +#line 734 + case NC_UBYTE: +#line 734 + return ncx_pad_getn_uchar_long(xpp, nelems, tp); +#line 734 + case NC_USHORT: +#line 734 + return ncx_getn_ushort_long(xpp, nelems, tp); +#line 734 + case NC_UINT: +#line 734 + return ncx_getn_uint_long(xpp, nelems, tp); +#line 734 + case NC_INT64: +#line 734 + return ncx_getn_longlong_long(xpp, nelems, tp); +#line 734 + case NC_UINT64: +#line 734 + return ncx_getn_ulonglong_long(xpp, nelems, tp); +#line 734 + default: +#line 734 + assert("ncx_pad_getn_Ilong invalid type" == 0); +#line 734 + } +#line 734 + return NC_EBADTYPE; +#line 734 +} +#line 734 + +#endif + +static int +#line 737 +ncx_pad_putn_Ilonglong(void **xpp, size_t nelems, const longlong *tp, nc_type type, void *fillp) +#line 737 +{ +#line 737 + switch(type) { +#line 737 + case NC_CHAR: +#line 737 + return NC_ECHAR; +#line 737 + case NC_BYTE: +#line 737 + return ncx_pad_putn_schar_longlong(xpp, nelems, tp, fillp); +#line 737 + case NC_SHORT: +#line 737 + return ncx_pad_putn_short_longlong(xpp, nelems, tp, fillp); +#line 737 + case NC_INT: +#line 737 + return ncx_putn_int_longlong(xpp, nelems, tp, fillp); +#line 737 + case NC_FLOAT: +#line 737 + return ncx_putn_float_longlong(xpp, nelems, tp, fillp); +#line 737 + case NC_DOUBLE: +#line 737 + return ncx_putn_double_longlong(xpp, nelems, tp, fillp); +#line 737 + case NC_UBYTE: +#line 737 + return ncx_pad_putn_uchar_longlong(xpp, nelems, tp, fillp); +#line 737 + case NC_USHORT: +#line 737 + return ncx_putn_ushort_longlong(xpp, nelems, tp, fillp); +#line 737 + case NC_UINT: +#line 737 + return ncx_putn_uint_longlong(xpp, nelems, tp, fillp); +#line 737 + case NC_INT64: +#line 737 + return ncx_putn_longlong_longlong(xpp, nelems, tp, fillp); +#line 737 + case NC_UINT64: +#line 737 + return ncx_putn_ulonglong_longlong(xpp, nelems, tp, fillp); +#line 737 + default: +#line 737 + assert("ncx_pad_putn_Ilonglong invalid type" == 0); +#line 737 + } +#line 737 + return NC_EBADTYPE; +#line 737 +} +#line 737 + +static int +#line 738 +ncx_pad_getn_Ilonglong(const void **xpp, size_t nelems, longlong *tp, nc_type type) +#line 738 +{ +#line 738 + switch(type) { +#line 738 + case NC_CHAR: +#line 738 + return NC_ECHAR; +#line 738 + case NC_BYTE: +#line 738 + return ncx_pad_getn_schar_longlong(xpp, nelems, tp); +#line 738 + case NC_SHORT: +#line 738 + return ncx_pad_getn_short_longlong(xpp, nelems, tp); +#line 738 + case NC_INT: +#line 738 + return ncx_getn_int_longlong(xpp, nelems, tp); +#line 738 + case NC_FLOAT: +#line 738 + return ncx_getn_float_longlong(xpp, nelems, tp); +#line 738 + case NC_DOUBLE: +#line 738 + return ncx_getn_double_longlong(xpp, nelems, tp); +#line 738 + case NC_UBYTE: +#line 738 + return ncx_pad_getn_uchar_longlong(xpp, nelems, tp); +#line 738 + case NC_USHORT: +#line 738 + return ncx_getn_ushort_longlong(xpp, nelems, tp); +#line 738 + case NC_UINT: +#line 738 + return ncx_getn_uint_longlong(xpp, nelems, tp); +#line 738 + case NC_INT64: +#line 738 + return ncx_getn_longlong_longlong(xpp, nelems, tp); +#line 738 + case NC_UINT64: +#line 738 + return ncx_getn_ulonglong_longlong(xpp, nelems, tp); +#line 738 + default: +#line 738 + assert("ncx_pad_getn_Ilonglong invalid type" == 0); +#line 738 + } +#line 738 + return NC_EBADTYPE; +#line 738 +} +#line 738 + + +static int +#line 740 +ncx_pad_putn_Iushort(void **xpp, size_t nelems, const ushort *tp, nc_type type, void *fillp) +#line 740 +{ +#line 740 + switch(type) { +#line 740 + case NC_CHAR: +#line 740 + return NC_ECHAR; +#line 740 + case NC_BYTE: +#line 740 + return ncx_pad_putn_schar_ushort(xpp, nelems, tp, fillp); +#line 740 + case NC_SHORT: +#line 740 + return ncx_pad_putn_short_ushort(xpp, nelems, tp, fillp); +#line 740 + case NC_INT: +#line 740 + return ncx_putn_int_ushort(xpp, nelems, tp, fillp); +#line 740 + case NC_FLOAT: +#line 740 + return ncx_putn_float_ushort(xpp, nelems, tp, fillp); +#line 740 + case NC_DOUBLE: +#line 740 + return ncx_putn_double_ushort(xpp, nelems, tp, fillp); +#line 740 + case NC_UBYTE: +#line 740 + return ncx_pad_putn_uchar_ushort(xpp, nelems, tp, fillp); +#line 740 + case NC_USHORT: +#line 740 + return ncx_putn_ushort_ushort(xpp, nelems, tp, fillp); +#line 740 + case NC_UINT: +#line 740 + return ncx_putn_uint_ushort(xpp, nelems, tp, fillp); +#line 740 + case NC_INT64: +#line 740 + return ncx_putn_longlong_ushort(xpp, nelems, tp, fillp); +#line 740 + case NC_UINT64: +#line 740 + return ncx_putn_ulonglong_ushort(xpp, nelems, tp, fillp); +#line 740 + default: +#line 740 + assert("ncx_pad_putn_Iushort invalid type" == 0); +#line 740 + } +#line 740 + return NC_EBADTYPE; +#line 740 +} +#line 740 + +static int +#line 741 +ncx_pad_getn_Iushort(const void **xpp, size_t nelems, ushort *tp, nc_type type) +#line 741 +{ +#line 741 + switch(type) { +#line 741 + case NC_CHAR: +#line 741 + return NC_ECHAR; +#line 741 + case NC_BYTE: +#line 741 + return ncx_pad_getn_schar_ushort(xpp, nelems, tp); +#line 741 + case NC_SHORT: +#line 741 + return ncx_pad_getn_short_ushort(xpp, nelems, tp); +#line 741 + case NC_INT: +#line 741 + return ncx_getn_int_ushort(xpp, nelems, tp); +#line 741 + case NC_FLOAT: +#line 741 + return ncx_getn_float_ushort(xpp, nelems, tp); +#line 741 + case NC_DOUBLE: +#line 741 + return ncx_getn_double_ushort(xpp, nelems, tp); +#line 741 + case NC_UBYTE: +#line 741 + return ncx_pad_getn_uchar_ushort(xpp, nelems, tp); +#line 741 + case NC_USHORT: +#line 741 + return ncx_getn_ushort_ushort(xpp, nelems, tp); +#line 741 + case NC_UINT: +#line 741 + return ncx_getn_uint_ushort(xpp, nelems, tp); +#line 741 + case NC_INT64: +#line 741 + return ncx_getn_longlong_ushort(xpp, nelems, tp); +#line 741 + case NC_UINT64: +#line 741 + return ncx_getn_ulonglong_ushort(xpp, nelems, tp); +#line 741 + default: +#line 741 + assert("ncx_pad_getn_Iushort invalid type" == 0); +#line 741 + } +#line 741 + return NC_EBADTYPE; +#line 741 +} +#line 741 + + +static int +#line 743 +ncx_pad_putn_Iuint(void **xpp, size_t nelems, const uint *tp, nc_type type, void *fillp) +#line 743 +{ +#line 743 + switch(type) { +#line 743 + case NC_CHAR: +#line 743 + return NC_ECHAR; +#line 743 + case NC_BYTE: +#line 743 + return ncx_pad_putn_schar_uint(xpp, nelems, tp, fillp); +#line 743 + case NC_SHORT: +#line 743 + return ncx_pad_putn_short_uint(xpp, nelems, tp, fillp); +#line 743 + case NC_INT: +#line 743 + return ncx_putn_int_uint(xpp, nelems, tp, fillp); +#line 743 + case NC_FLOAT: +#line 743 + return ncx_putn_float_uint(xpp, nelems, tp, fillp); +#line 743 + case NC_DOUBLE: +#line 743 + return ncx_putn_double_uint(xpp, nelems, tp, fillp); +#line 743 + case NC_UBYTE: +#line 743 + return ncx_pad_putn_uchar_uint(xpp, nelems, tp, fillp); +#line 743 + case NC_USHORT: +#line 743 + return ncx_putn_ushort_uint(xpp, nelems, tp, fillp); +#line 743 + case NC_UINT: +#line 743 + return ncx_putn_uint_uint(xpp, nelems, tp, fillp); +#line 743 + case NC_INT64: +#line 743 + return ncx_putn_longlong_uint(xpp, nelems, tp, fillp); +#line 743 + case NC_UINT64: +#line 743 + return ncx_putn_ulonglong_uint(xpp, nelems, tp, fillp); +#line 743 + default: +#line 743 + assert("ncx_pad_putn_Iuint invalid type" == 0); +#line 743 + } +#line 743 + return NC_EBADTYPE; +#line 743 +} +#line 743 + +static int +#line 744 +ncx_pad_getn_Iuint(const void **xpp, size_t nelems, uint *tp, nc_type type) +#line 744 +{ +#line 744 + switch(type) { +#line 744 + case NC_CHAR: +#line 744 + return NC_ECHAR; +#line 744 + case NC_BYTE: +#line 744 + return ncx_pad_getn_schar_uint(xpp, nelems, tp); +#line 744 + case NC_SHORT: +#line 744 + return ncx_pad_getn_short_uint(xpp, nelems, tp); +#line 744 + case NC_INT: +#line 744 + return ncx_getn_int_uint(xpp, nelems, tp); +#line 744 + case NC_FLOAT: +#line 744 + return ncx_getn_float_uint(xpp, nelems, tp); +#line 744 + case NC_DOUBLE: +#line 744 + return ncx_getn_double_uint(xpp, nelems, tp); +#line 744 + case NC_UBYTE: +#line 744 + return ncx_pad_getn_uchar_uint(xpp, nelems, tp); +#line 744 + case NC_USHORT: +#line 744 + return ncx_getn_ushort_uint(xpp, nelems, tp); +#line 744 + case NC_UINT: +#line 744 + return ncx_getn_uint_uint(xpp, nelems, tp); +#line 744 + case NC_INT64: +#line 744 + return ncx_getn_longlong_uint(xpp, nelems, tp); +#line 744 + case NC_UINT64: +#line 744 + return ncx_getn_ulonglong_uint(xpp, nelems, tp); +#line 744 + default: +#line 744 + assert("ncx_pad_getn_Iuint invalid type" == 0); +#line 744 + } +#line 744 + return NC_EBADTYPE; +#line 744 +} +#line 744 + + +static int +#line 746 +ncx_pad_putn_Iulonglong(void **xpp, size_t nelems, const ulonglong *tp, nc_type type, void *fillp) +#line 746 +{ +#line 746 + switch(type) { +#line 746 + case NC_CHAR: +#line 746 + return NC_ECHAR; +#line 746 + case NC_BYTE: +#line 746 + return ncx_pad_putn_schar_ulonglong(xpp, nelems, tp, fillp); +#line 746 + case NC_SHORT: +#line 746 + return ncx_pad_putn_short_ulonglong(xpp, nelems, tp, fillp); +#line 746 + case NC_INT: +#line 746 + return ncx_putn_int_ulonglong(xpp, nelems, tp, fillp); +#line 746 + case NC_FLOAT: +#line 746 + return ncx_putn_float_ulonglong(xpp, nelems, tp, fillp); +#line 746 + case NC_DOUBLE: +#line 746 + return ncx_putn_double_ulonglong(xpp, nelems, tp, fillp); +#line 746 + case NC_UBYTE: +#line 746 + return ncx_pad_putn_uchar_ulonglong(xpp, nelems, tp, fillp); +#line 746 + case NC_USHORT: +#line 746 + return ncx_putn_ushort_ulonglong(xpp, nelems, tp, fillp); +#line 746 + case NC_UINT: +#line 746 + return ncx_putn_uint_ulonglong(xpp, nelems, tp, fillp); +#line 746 + case NC_INT64: +#line 746 + return ncx_putn_longlong_ulonglong(xpp, nelems, tp, fillp); +#line 746 + case NC_UINT64: +#line 746 + return ncx_putn_ulonglong_ulonglong(xpp, nelems, tp, fillp); +#line 746 + default: +#line 746 + assert("ncx_pad_putn_Iulonglong invalid type" == 0); +#line 746 + } +#line 746 + return NC_EBADTYPE; +#line 746 +} +#line 746 + +static int +#line 747 +ncx_pad_getn_Iulonglong(const void **xpp, size_t nelems, ulonglong *tp, nc_type type) +#line 747 +{ +#line 747 + switch(type) { +#line 747 + case NC_CHAR: +#line 747 + return NC_ECHAR; +#line 747 + case NC_BYTE: +#line 747 + return ncx_pad_getn_schar_ulonglong(xpp, nelems, tp); +#line 747 + case NC_SHORT: +#line 747 + return ncx_pad_getn_short_ulonglong(xpp, nelems, tp); +#line 747 + case NC_INT: +#line 747 + return ncx_getn_int_ulonglong(xpp, nelems, tp); +#line 747 + case NC_FLOAT: +#line 747 + return ncx_getn_float_ulonglong(xpp, nelems, tp); +#line 747 + case NC_DOUBLE: +#line 747 + return ncx_getn_double_ulonglong(xpp, nelems, tp); +#line 747 + case NC_UBYTE: +#line 747 + return ncx_pad_getn_uchar_ulonglong(xpp, nelems, tp); +#line 747 + case NC_USHORT: +#line 747 + return ncx_getn_ushort_ulonglong(xpp, nelems, tp); +#line 747 + case NC_UINT: +#line 747 + return ncx_getn_uint_ulonglong(xpp, nelems, tp); +#line 747 + case NC_INT64: +#line 747 + return ncx_getn_longlong_ulonglong(xpp, nelems, tp); +#line 747 + case NC_UINT64: +#line 747 + return ncx_getn_ulonglong_ulonglong(xpp, nelems, tp); +#line 747 + default: +#line 747 + assert("ncx_pad_getn_Iulonglong invalid type" == 0); +#line 747 + } +#line 747 + return NC_EBADTYPE; +#line 747 +} +#line 747 + + + +/* Common dispatcher for put cases */ +static int +dispatchput(void **xpp, size_t nelems, const void* tp, + nc_type atype, nc_type memtype, void *fillp) +{ + switch (memtype) { + case NC_CHAR: + return ncx_pad_putn_text(xpp,nelems, (char *)tp); + case NC_BYTE: + return ncx_pad_putn_Ischar(xpp, nelems, (schar*)tp, atype, fillp); + case NC_SHORT: + return ncx_pad_putn_Ishort(xpp, nelems, (short*)tp, atype, fillp); + case NC_INT: + return ncx_pad_putn_Iint(xpp, nelems, (int*)tp, atype, fillp); + case NC_FLOAT: + return ncx_pad_putn_Ifloat(xpp, nelems, (float*)tp, atype, fillp); + case NC_DOUBLE: + return ncx_pad_putn_Idouble(xpp, nelems, (double*)tp, atype, fillp); + case NC_UBYTE: /*Synthetic*/ + return ncx_pad_putn_Iuchar(xpp,nelems, (uchar *)tp, atype, fillp); + case NC_INT64: + return ncx_pad_putn_Ilonglong(xpp, nelems, (longlong*)tp, atype, fillp); + case NC_USHORT: + return ncx_pad_putn_Iushort(xpp, nelems, (ushort*)tp, atype, fillp); + case NC_UINT: + return ncx_pad_putn_Iuint(xpp, nelems, (uint*)tp, atype, fillp); + case NC_UINT64: + return ncx_pad_putn_Iulonglong(xpp, nelems, (ulonglong*)tp, atype, fillp); + case NC_NAT: + return NC_EBADTYPE; + default: + break; + } + return NC_EBADTYPE; +} + +int +NC3_put_att( + int ncid, + int varid, + const char *name, + nc_type type, + size_t nelems, + const void *value, + nc_type memtype) +{ + int status; + NC *nc; + NC3_INFO* ncp; + NC_attrarray *ncap; + NC_attr **attrpp; + NC_attr *old = NULL; + NC_attr *attrp; + unsigned char fill[8]; /* fill value in internal representation */ + + status = NC_check_id(ncid, &nc); + if(status != NC_NOERR) + return status; + ncp = NC3_DATA(nc); + + if(NC_readonly(ncp)) + return NC_EPERM; + + ncap = NC_attrarray0(ncp, varid); + if(ncap == NULL) + return NC_ENOTVAR; + + if (name == NULL) + return NC_EBADNAME; + + /* check NC_EBADTYPE */ + status = nc3_cktype(nc->mode, type); + if(status != NC_NOERR) + return status; + + if(memtype == NC_NAT) memtype = type; + + if(memtype != NC_CHAR && type == NC_CHAR) + return NC_ECHAR; + if(memtype == NC_CHAR && type != NC_CHAR) + return NC_ECHAR; + + /* cast needed for braindead systems with signed size_t */ + if((unsigned long) nelems > X_INT_MAX) /* backward compat */ + return NC_EINVAL; /* Invalid nelems */ + + if(nelems != 0 && value == NULL) + return NC_EINVAL; /* Null arg */ + + /* Temporarily removed to preserve extant + workflows (NCO based and others). See + + https://github.com/Unidata/netcdf-c/issues/843 + + for more information. */ + +#if 0 + if (varid != NC_GLOBAL && !strcmp(name, _FillValue)) { + /* Fill value must be of the same data type */ + if (type != ncp->vars.value[varid]->type) return NC_EBADTYPE; + + /* Fill value must have exactly one value */ + if (nelems != 1) return NC_EINVAL; + + /* Only allow for variables defined in initial define mode */ + if (ncp->old != NULL && varid < ncp->old->vars.nelems) + return NC_ELATEFILL; /* try put attribute for an old variable */ + } +#endif + + attrpp = NC_findattr(ncap, name); + + /* 4 cases: exists X indef */ + + status = NC3_inq_default_fill_value(type, &fill); + if (status != NC_NOERR) return status; + + if(attrpp != NULL) { /* name in use */ + if(!NC_indef(ncp)) { + const size_t xsz = ncx_len_NC_attrV(type, nelems); + attrp = *attrpp; /* convenience */ + + if(xsz > attrp->xsz) return NC_ENOTINDEFINE; + /* else, we can reuse existing without redef */ + + attrp->xsz = xsz; + attrp->type = type; + attrp->nelems = nelems; + + if(nelems != 0) { + void *xp = attrp->xvalue; + /* for CDF-1 and CDF-2, NC_BYTE is treated the same type as uchar memtype */ + if (!fIsSet(ncp->flags,NC_64BIT_DATA) && type == NC_BYTE && memtype == NC_UBYTE) { + status = NC3_inq_default_fill_value(NC_UBYTE, &fill); + if (status != NC_NOERR) return status; + status = dispatchput(&xp, nelems, value, memtype, memtype, &fill); + } else + status = dispatchput(&xp, nelems, value, type, memtype, &fill); + } + + set_NC_hdirty(ncp); + + if(NC_doHsync(ncp)) { + const int lstatus = NC_sync(ncp); + /* + * N.B.: potentially overrides NC_ERANGE + * set by ncx_pad_putn_I$1 + */ + if(lstatus != NC_NOERR) return lstatus; + } + + return status; + } + /* else, redefine using existing array slot */ + old = *attrpp; + } else { + if(!NC_indef(ncp)) return NC_ENOTINDEFINE; + } + + status = NC_check_name(name); + if(status != NC_NOERR) return status; + + attrp = new_NC_attr(name, type, nelems); + if(attrp == NULL) return NC_ENOMEM; + + if(nelems != 0) { + void *xp = attrp->xvalue; + /* for CDF-1 and CDF-2, NC_BYTE is treated the same type as uchar memtype */ + if (!fIsSet(ncp->flags,NC_64BIT_DATA) && type == NC_BYTE && memtype == NC_UBYTE) { + status = NC3_inq_default_fill_value(NC_UBYTE, &fill); + if (status != NC_NOERR) return status; + status = dispatchput(&xp, nelems, (const void*)value, memtype, memtype, &fill); + } else + status = dispatchput(&xp, nelems, (const void*)value, type, memtype, &fill); + } + + if(attrpp != NULL) { + *attrpp = attrp; + if(old != NULL) + free_NC_attr(old); + } else { + const int lstatus = incr_NC_attrarray(ncap, attrp); + /* + * N.B.: potentially overrides NC_ERANGE + * set by ncx_pad_putn_I$1 + */ + if(lstatus != NC_NOERR) { + free_NC_attr(attrp); + return lstatus; + } + } + return status; +} + +int +NC3_get_att( + int ncid, + int varid, + const char *name, + void *value, + nc_type memtype) +{ + int status; + NC *nc; + NC3_INFO* ncp; + NC_attr *attrp; + const void *xp; + + status = NC_check_id(ncid, &nc); + if(status != NC_NOERR) + return status; + ncp = NC3_DATA(nc); + + status = NC_lookupattr(ncid, varid, name, &attrp); + if(status != NC_NOERR) return status; + + if(attrp->nelems == 0) return NC_NOERR; + + if(memtype == NC_NAT) memtype = attrp->type; + + if(memtype != NC_CHAR && attrp->type == NC_CHAR) + return NC_ECHAR; + if(memtype == NC_CHAR && attrp->type != NC_CHAR) + return NC_ECHAR; + + xp = attrp->xvalue; + switch (memtype) { + case NC_CHAR: + return ncx_pad_getn_text(&xp, attrp->nelems, (char *)value); + case NC_BYTE: + return ncx_pad_getn_Ischar(&xp,attrp->nelems,(schar*)value,attrp->type); + case NC_SHORT: + return ncx_pad_getn_Ishort(&xp,attrp->nelems,(short*)value,attrp->type); + case NC_INT: + return ncx_pad_getn_Iint(&xp,attrp->nelems,(int*)value,attrp->type); + case NC_FLOAT: + return ncx_pad_getn_Ifloat(&xp,attrp->nelems,(float*)value,attrp->type); + case NC_DOUBLE: + return ncx_pad_getn_Idouble(&xp,attrp->nelems,(double*)value,attrp->type); + case NC_INT64: + return ncx_pad_getn_Ilonglong(&xp,attrp->nelems,(longlong*)value,attrp->type); + case NC_UBYTE: /* Synthetic */ + /* for CDF-1 and CDF-2, NC_BYTE is treated the same type as uchar memtype */ + if (!fIsSet(ncp->flags,NC_64BIT_DATA) && attrp->type == NC_BYTE) + return ncx_pad_getn_Iuchar(&xp, attrp->nelems, (uchar *)value, NC_UBYTE); + else + return ncx_pad_getn_Iuchar(&xp, attrp->nelems, (uchar *)value, attrp->type); + case NC_USHORT: + return ncx_pad_getn_Iushort(&xp,attrp->nelems,(ushort*)value,attrp->type); + case NC_UINT: + return ncx_pad_getn_Iuint(&xp,attrp->nelems,(uint*)value,attrp->type); + case NC_UINT64: + return ncx_pad_getn_Iulonglong(&xp,attrp->nelems,(ulonglong*)value,attrp->type); + case NC_NAT: + return NC_EBADTYPE; + default: + break; + } + status = NC_EBADTYPE; + return status; +} diff --git a/libsrc/ncx.c b/libsrc/ncx.c new file mode 100644 index 0000000000..f4461b7fda --- /dev/null +++ b/libsrc/ncx.c @@ -0,0 +1,39535 @@ +#line 6 "ncx.m4" +/* Do not edit this file. It is produced from the corresponding .m4 source */ +#line 8 +/* + * Copyright (C) 2014, Northwestern University and Argonne National Laboratory + * See COPYRIGHT notice in top-level directory. + */ +/* $Id: ncx.m4 2601 2016-11-07 04:54:42Z wkliao $ */ + +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wunused-parameter" +#endif + +#line 22 + +#line 26 + + +#line 34 + +#line 41 + +#line 41 +#if HAVE_CONFIG_H +#line 41 +#include +#line 41 +#endif + +#include +#include +#include +#include + +#line 53 + +#line 53 +#pragma GCC diagnostic ignored "-Wdeprecated" +#line 53 +#include "ncx.h" +#line 53 +#include "nc3dispatch.h" + +#line 72 + + + + +#ifdef HAVE_INTTYPES_H +#include /* uint16_t, uint32_t, uint64_t */ +#elif defined(HAVE_STDINT_H) +#include /* uint16_t, uint32_t, uint64_t */ +#endif + +#line 103 + +#line 121 + +/* + * The only error code returned from subroutines in this file is NC_ERANGE, + * if errors are detected. + */ + +/* + * An external data representation interface. + */ + +/* alias poorly named limits.h macros */ +#define SHORT_MAX SHRT_MAX +#define SHORT_MIN SHRT_MIN +#define USHORT_MAX USHRT_MAX +#ifndef LLONG_MAX +# define LLONG_MAX 9223372036854775807LL +# define LLONG_MIN (-LLONG_MAX - 1LL) +# define ULLONG_MAX 18446744073709551615ULL +#endif +#ifndef LONG_LONG_MAX +#define LONG_LONG_MAX LLONG_MAX +#endif +#ifndef LONGLONG_MAX +#define LONGLONG_MAX LONG_LONG_MAX +#endif +#ifndef LONG_LONG_MIN +#define LONG_LONG_MIN LLONG_MIN +#endif +#ifndef LONGLONG_MIN +#define LONGLONG_MIN LONG_LONG_MIN +#endif +#ifndef ULONG_LONG_MAX +#define ULONG_LONG_MAX ULLONG_MAX +#endif +#ifndef ULONGLONG_MAX +#define ULONGLONG_MAX ULONG_LONG_MAX +#endif +#include +#ifndef FLT_MAX /* This POSIX macro missing on some systems */ +# ifndef NO_IEEE_FLOAT +# define FLT_MAX 3.40282347e+38f +# else +# error "You will need to define FLT_MAX" +# endif +#endif +/* alias poorly named float.h macros */ +#define FLOAT_MAX FLT_MAX +#define FLOAT_MIN (-FLT_MAX) +#define DOUBLE_MAX DBL_MAX +#define DOUBLE_MIN (-DBL_MAX) +#define FLOAT_MAX_EXP FLT_MAX_EXP +#define DOUBLE_MAX_EXP DBL_MAX_EXP +#include +#define UCHAR_MIN 0 +#define Min(a,b) ((a) < (b) ? (a) : (b)) +#define Max(a,b) ((a) > (b) ? (a) : (b)) + +#ifndef SIZEOF_UCHAR +#ifdef SIZEOF_UNSIGNED_CHAR +#define SIZEOF_UCHAR SIZEOF_UNSIGNED_CHAR +#else +#error "unknown SIZEOF_UCHAR" +#endif +#endif + +#ifndef SIZEOF_USHORT +#ifdef SIZEOF_UNSIGNED_SHORT_INT +#define SIZEOF_USHORT SIZEOF_UNSIGNED_SHORT_INT +#elif defined(SIZEOF_UNSIGNED_SHORT) +#define SIZEOF_USHORT SIZEOF_UNSIGNED_SHORT +#else +#error "unknown SIZEOF_USHORT" +#endif +#endif + +#ifndef SIZEOF_UINT +#ifdef SIZEOF_UNSIGNED_INT +#define SIZEOF_UINT SIZEOF_UNSIGNED_INT +#else +#error "unknown SIZEOF_UINT" +#endif +#endif + +#ifndef SIZEOF_LONGLONG +#ifdef SIZEOF_LONG_LONG +#define SIZEOF_LONGLONG SIZEOF_LONG_LONG +#else +#error "unknown SIZEOF_LONGLONG" +#endif +#endif + +#ifndef SIZEOF_INT64 +#ifdef SIZEOF_LONG_LONG +#define SIZEOF_INT64 SIZEOF_LONG_LONG +#elif defined(SIZEOF_LONGLONG) +#define SIZEOF_INT64 SIZEOF_LONGLONG +#else +#error "unknown SIZEOF_INT64" +#endif +#endif + +#ifndef SIZEOF_ULONGLONG +#ifdef SIZEOF_UNSIGNED_LONG_LONG +#define SIZEOF_ULONGLONG SIZEOF_UNSIGNED_LONG_LONG +#else +#error "unknown SIZEOF_ULONGLONG" +#endif +#endif + +#ifndef SIZEOF_UINT64 +#ifdef SIZEOF_UNSIGNED_LONG_LONG +#define SIZEOF_UINT64 SIZEOF_UNSIGNED_LONG_LONG +#elif defined(SIZEOF_ULONGLONG) +#define SIZEOF_UINT64 SIZEOF_ULONGLONG +#else +#error "unknown SIZEOF_UINT64" +#endif +#endif + +/* + * If the machine's float domain is "smaller" than the external one + * use the machine domain + */ +#if defined(FLT_MAX_EXP) && FLT_MAX_EXP < 128 /* 128 is X_FLT_MAX_EXP */ +#undef X_FLOAT_MAX +# define X_FLOAT_MAX FLT_MAX +#undef X_FLOAT_MIN +# define X_FLOAT_MIN (-X_FLOAT_MAX) +#endif + +#if defined(_SX) && _SX != 0 /* NEC SUPER UX */ +#define LOOPCNT 256 /* must be no longer than hardware vector length */ +#if _INT64 +#undef INT_MAX /* workaround cpp bug */ +#define INT_MAX X_INT_MAX +#undef INT_MIN /* workaround cpp bug */ +#define INT_MIN X_INT_MIN +#undef LONG_MAX /* workaround cpp bug */ +#define LONG_MAX X_INT_MAX +#undef LONG_MIN /* workaround cpp bug */ +#define LONG_MIN X_INT_MIN +#elif _LONG64 +#undef LONG_MAX /* workaround cpp bug */ +#define LONG_MAX 4294967295L +#undef LONG_MIN /* workaround cpp bug */ +#define LONG_MIN -4294967295L +#endif +#if !_FLOAT0 +#error "FLOAT1 and FLOAT2 not supported" +#endif +#endif /* _SX */ + +static const char nada[X_ALIGN] = {0, 0, 0, 0}; + +#ifndef WORDS_BIGENDIAN +/* LITTLE_ENDIAN: DEC and intel */ +/* + * Routines to convert to BIG ENDIAN. + * Optimize the swapn?b() and swap?b() routines aggressively. + */ + +#define SWAP2(a) ( (((a) & 0xff) << 8) | \ + (((a) >> 8) & 0xff) ) + +#define SWAP4(a) ( ((a) << 24) | \ + (((a) << 8) & 0x00ff0000) | \ + (((a) >> 8) & 0x0000ff00) | \ + (((a) >> 24) & 0x000000ff) ) + +#define SWAP8(a) ( (((a) & 0x00000000000000FFULL) << 56) | \ + (((a) & 0x000000000000FF00ULL) << 40) | \ + (((a) & 0x0000000000FF0000ULL) << 24) | \ + (((a) & 0x00000000FF000000ULL) << 8) | \ + (((a) & 0x000000FF00000000ULL) >> 8) | \ + (((a) & 0x0000FF0000000000ULL) >> 24) | \ + (((a) & 0x00FF000000000000ULL) >> 40) | \ + (((a) & 0xFF00000000000000ULL) >> 56) ) + +#if defined(_MSC_VER) && _MSC_VER < 1900 +#define inline __inline +#endif + +inline static void +swapn2b(void *dst, const void *src, size_t nn) +{ + /* it is OK if dst == src */ + size_t i; + uint16_t *op = (uint16_t*) dst; + uint16_t *ip = (uint16_t*) src; + for (i=0; i 0) + * { + * *op++ = *(++ip); + * *op++ = *(ip++ -1); + * } + */ + while (nn > 3) + { + *op++ = *(++ip); + *op++ = *(ip++ -1); + *op++ = *(++ip); + *op++ = *(ip++ -1); + *op++ = *(++ip); + *op++ = *(ip++ -1); + *op++ = *(++ip); + *op++ = *(ip++ -1); + nn -= 4; + } + while (nn-- > 0) + { + *op++ = *(++ip); + *op++ = *(ip++ -1); + } +#endif +} + +# ifndef vax +inline static void +swap4b(void *dst, const void *src) +{ + /* copy over, make the below swap in-place */ + uint32_t tmp; + /* use memcpy to avoid type punning */ + memcpy(&tmp, src, sizeof(tmp)); + tmp = SWAP4(tmp); + memcpy(dst, &tmp, 4); + + /* Codes below will cause "break strict-aliasing rules" in gcc + uint32_t *op = (uint32_t*)dst; + *op = *(uint32_t*)src; + *op = SWAP4(*op); + */ + + /* Below are copied from netCDF-4. + * See https://bugtracking.unidata.ucar.edu/browse/NCF-338 + * Quote "One issue we are wrestling with is how compilers optimize this + * code. For some reason, we are actually needing to add an artificial + * move to a 4 byte space to get it to work. I think what is happening is + * that the optimizer is bit shifting within a double, which is incorrect. + * The following code actually does work correctly. + * This is in Linux land, gcc. + * + * However, the above in-place byte-swap does not appear affected by this. + */ +#if 0 + uint32_t *ip = (uint32_t*)src; + uint32_t tempOut; /* cannot use pointer when gcc O2 optimizer is used */ + tempOut = SWAP4(*ip); + + *(float *)dst = *(float *)(&tempOut); +#endif + + /* OLD implementation that results in four load and four store CPU + instructions + char *op = dst; + const char *ip = src; + op[0] = ip[3]; + op[1] = ip[2]; + op[2] = ip[1]; + op[3] = ip[0]; + */ + +} +# endif /* !vax */ + +inline static void +swapn4b(void *dst, const void *src, size_t nn) +{ + size_t i; + uint32_t *op = (uint32_t*) dst; + uint32_t *ip = (uint32_t*) src; + for (i=0; i 0) + * { + * op[0] = ip[3]; + * op[1] = ip[2]; + * op[2] = ip[1]; + * op[3] = ip[0]; + * op += 4; + * ip += 4; + * } + */ + while (nn > 3) + { + op[0] = ip[3]; + op[1] = ip[2]; + op[2] = ip[1]; + op[3] = ip[0]; + op[4] = ip[7]; + op[5] = ip[6]; + op[6] = ip[5]; + op[7] = ip[4]; + op[8] = ip[11]; + op[9] = ip[10]; + op[10] = ip[9]; + op[11] = ip[8]; + op[12] = ip[15]; + op[13] = ip[14]; + op[14] = ip[13]; + op[15] = ip[12]; + op += 16; + ip += 16; + nn -= 4; + } + while (nn-- > 0) + { + op[0] = ip[3]; + op[1] = ip[2]; + op[2] = ip[1]; + op[3] = ip[0]; + op += 4; + ip += 4; + } +#endif +} + +# ifndef vax +inline static void +swap8b(void *dst, const void *src) +{ +#ifdef FLOAT_WORDS_BIGENDIAN + /* copy over, make the below swap in-place */ + *(uint64_t*)dst = *(uint64_t*)src; + + uint32_t *op = (uint32_t*)dst; + *op = SWAP4(*op); + op = (uint32_t*)((char*)dst+4); + *op = SWAP4(*op); +#else + uint64_t tmp; + /* use memcpy to avoid type punning */ + memcpy(&tmp, src, sizeof(tmp)); + tmp = SWAP8(tmp); + memcpy(dst, &tmp, 8); + + /* Codes below will cause "break strict-aliasing rules" in gcc + uint64_t *op = (uint64_t*)dst; + *op = *(uint64_t*)src; + *op = SWAP8(*op); + */ +#endif + +#if 0 + char *op = dst; + const char *ip = src; +# ifndef FLOAT_WORDS_BIGENDIAN + op[0] = ip[7]; + op[1] = ip[6]; + op[2] = ip[5]; + op[3] = ip[4]; + op[4] = ip[3]; + op[5] = ip[2]; + op[6] = ip[1]; + op[7] = ip[0]; +# else + op[0] = ip[3]; + op[1] = ip[2]; + op[2] = ip[1]; + op[3] = ip[0]; + op[4] = ip[7]; + op[5] = ip[6]; + op[6] = ip[5]; + op[7] = ip[4]; +#endif +#endif +} +# endif /* !vax */ + +# ifndef vax +inline static void +swapn8b(void *dst, const void *src, size_t nn) +{ +#ifdef FLOAT_WORDS_BIGENDIAN + size_t i; + uint64_t *dst_p = (uint64_t*) dst; + uint64_t *src_p = (uint64_t*) src; + for (i=0; i 0) + * { + * op[0] = ip[7]; + * op[1] = ip[6]; + * op[2] = ip[5]; + * op[3] = ip[4]; + * op[4] = ip[3]; + * op[5] = ip[2]; + * op[6] = ip[1]; + * op[7] = ip[0]; + * op += 8; + * ip += 8; + * } + */ +# ifndef FLOAT_WORDS_BIGENDIAN + while (nn > 1) + { + op[0] = ip[7]; + op[1] = ip[6]; + op[2] = ip[5]; + op[3] = ip[4]; + op[4] = ip[3]; + op[5] = ip[2]; + op[6] = ip[1]; + op[7] = ip[0]; + op[8] = ip[15]; + op[9] = ip[14]; + op[10] = ip[13]; + op[11] = ip[12]; + op[12] = ip[11]; + op[13] = ip[10]; + op[14] = ip[9]; + op[15] = ip[8]; + op += 16; + ip += 16; + nn -= 2; + } + while (nn-- > 0) + { + op[0] = ip[7]; + op[1] = ip[6]; + op[2] = ip[5]; + op[3] = ip[4]; + op[4] = ip[3]; + op[5] = ip[2]; + op[6] = ip[1]; + op[7] = ip[0]; + op += 8; + ip += 8; + } +# else + while (nn-- > 0) + { + op[0] = ip[3]; + op[1] = ip[2]; + op[2] = ip[1]; + op[3] = ip[0]; + op[4] = ip[7]; + op[5] = ip[6]; + op[6] = ip[5]; + op[7] = ip[4]; + op += 8; + ip += 8; + } +#endif +#endif +} +# endif /* !vax */ + +#endif /* LITTLE_ENDIAN */ + +#line 634 + +#line 638 + +#line 650 + +#line 665 + + +/* + * Primitive numeric conversion functions. + */ + +#line 693 + +#line 741 + +#line 774 + +#line 820 + +/* x_schar */ +/* x_uchar */ + +/* We don't implement any x_schar and x_uchar primitives. */ + + +/* external NC_SHORT --------------------------------------------------------*/ + +#if SHORT_MAX == X_SHORT_MAX +typedef short ix_short; +#define SIZEOF_IX_SHORT SIZEOF_SHORT +#define IX_SHORT_MAX SHORT_MAX +#elif INT_MAX >= X_SHORT_MAX +typedef int ix_short; +#define SIZEOF_IX_SHORT SIZEOF_INT +#define IX_SHORT_MAX INT_MAX +#elif LONG_MAX >= X_SHORT_MAX +typedef long ix_short; +#define SIZEOF_IX_SHORT SIZEOF_LONG +#define IX_SHORT_MAX LONG_MAX +#elif LLONG_MAX >= X_SHORT_MAX +typedef long long ix_short; +#define SIZEOF_IX_SHORT SIZEOF_LONGLONG +#define IX_SHORT_MAX LLONG_MAX +#else +#error "ix_short implementation" +#endif + +static void +get_ix_short(const void *xp, ix_short *ip) +{ + const uchar *cp = (const uchar *) xp; + *ip = (ix_short)(*cp++ << 8); +#if SIZEOF_IX_SHORT > X_SIZEOF_SHORT + if (*ip & 0x8000) + { + /* extern is negative */ + *ip |= (~(0xffff)); /* N.B. Assumes "twos complement" */ + } +#endif + *ip = (ix_short)(*ip | *cp); +} + +static void +put_ix_short(void *xp, const ix_short *ip) +{ + uchar *cp = (uchar *) xp; + *cp++ = (uchar)((*ip) >> 8); + *cp = (uchar)((*ip) & 0xff); +} + +static int +#line 872 +ncx_get_short_schar(const void *xp, schar *ip) +#line 872 +{ +#line 872 + int err=NC_NOERR; +#line 872 + ix_short xx = 0; +#line 872 + get_ix_short(xp, &xx); +#line 872 + +#line 872 +#if IX_SHORT_MAX > SCHAR_MAX +#line 872 + if (xx > SCHAR_MAX || xx < SCHAR_MIN) { +#line 872 +#ifdef ERANGE_FILL +#line 872 + *ip = NC_FILL_BYTE; +#line 872 + return NC_ERANGE; +#line 872 +#else +#line 872 + err = NC_ERANGE; +#line 872 +#endif +#line 872 + } +#line 872 +#endif +#line 872 + +#line 872 + +#line 872 + *ip = (schar) xx; +#line 872 + return err; +#line 872 +} +#line 872 + +static int +#line 873 +ncx_get_short_short(const void *xp, short *ip) +#line 873 +{ +#line 873 + int err=NC_NOERR; +#line 873 +#if SIZEOF_IX_SHORT == SIZEOF_SHORT && IX_SHORT_MAX == SHORT_MAX +#line 873 + get_ix_short(xp, (ix_short *)ip); +#line 873 +#else +#line 873 + ix_short xx = 0; +#line 873 + get_ix_short(xp, &xx); +#line 873 + +#line 873 +#if IX_SHORT_MAX > SHORT_MAX +#line 873 + if (xx > SHORT_MAX || xx < SHORT_MIN) { +#line 873 +#ifdef ERANGE_FILL +#line 873 + *ip = NC_FILL_SHORT; +#line 873 + return NC_ERANGE; +#line 873 +#else +#line 873 + err = NC_ERANGE; +#line 873 +#endif +#line 873 + } +#line 873 +#endif +#line 873 + +#line 873 + +#line 873 + *ip = (short) xx; +#line 873 +#endif +#line 873 + return err; +#line 873 +} +#line 873 + +static int +#line 874 +ncx_get_short_int(const void *xp, int *ip) +#line 874 +{ +#line 874 + int err=NC_NOERR; +#line 874 +#if SIZEOF_IX_SHORT == SIZEOF_INT && IX_SHORT_MAX == INT_MAX +#line 874 + get_ix_short(xp, (ix_short *)ip); +#line 874 +#else +#line 874 + ix_short xx = 0; +#line 874 + get_ix_short(xp, &xx); +#line 874 + +#line 874 +#if IX_SHORT_MAX > INT_MAX +#line 874 + if (xx > INT_MAX || xx < INT_MIN) { +#line 874 +#ifdef ERANGE_FILL +#line 874 + *ip = NC_FILL_INT; +#line 874 + return NC_ERANGE; +#line 874 +#else +#line 874 + err = NC_ERANGE; +#line 874 +#endif +#line 874 + } +#line 874 +#endif +#line 874 + +#line 874 + +#line 874 + *ip = (int) xx; +#line 874 +#endif +#line 874 + return err; +#line 874 +} +#line 874 + +static int +#line 875 +ncx_get_short_long(const void *xp, long *ip) +#line 875 +{ +#line 875 + int err=NC_NOERR; +#line 875 +#if SIZEOF_IX_SHORT == SIZEOF_LONG && IX_SHORT_MAX == LONG_MAX +#line 875 + get_ix_short(xp, (ix_short *)ip); +#line 875 +#else +#line 875 + ix_short xx = 0; +#line 875 + get_ix_short(xp, &xx); +#line 875 + +#line 875 +#if IX_SHORT_MAX > LONG_MAX +#line 875 + if (xx > LONG_MAX || xx < LONG_MIN) { +#line 875 +#ifdef ERANGE_FILL +#line 875 + *ip = NC_FILL_INT; +#line 875 + return NC_ERANGE; +#line 875 +#else +#line 875 + err = NC_ERANGE; +#line 875 +#endif +#line 875 + } +#line 875 +#endif +#line 875 + +#line 875 + +#line 875 + *ip = (long) xx; +#line 875 +#endif +#line 875 + return err; +#line 875 +} +#line 875 + +static int +#line 876 +ncx_get_short_longlong(const void *xp, longlong *ip) +#line 876 +{ +#line 876 + int err=NC_NOERR; +#line 876 +#if SIZEOF_IX_SHORT == SIZEOF_LONGLONG && IX_SHORT_MAX == LONGLONG_MAX +#line 876 + get_ix_short(xp, (ix_short *)ip); +#line 876 +#else +#line 876 + ix_short xx = 0; +#line 876 + get_ix_short(xp, &xx); +#line 876 + +#line 876 +#if IX_SHORT_MAX > LONGLONG_MAX +#line 876 + if (xx > LONGLONG_MAX || xx < LONGLONG_MIN) { +#line 876 +#ifdef ERANGE_FILL +#line 876 + *ip = NC_FILL_INT64; +#line 876 + return NC_ERANGE; +#line 876 +#else +#line 876 + err = NC_ERANGE; +#line 876 +#endif +#line 876 + } +#line 876 +#endif +#line 876 + +#line 876 + +#line 876 + *ip = (longlong) xx; +#line 876 +#endif +#line 876 + return err; +#line 876 +} +#line 876 + +static int +#line 877 +ncx_get_short_ushort(const void *xp, ushort *ip) +#line 877 +{ +#line 877 + int err=NC_NOERR; +#line 877 + ix_short xx = 0; +#line 877 + get_ix_short(xp, &xx); +#line 877 + +#line 877 +#if IX_SHORT_MAX > USHORT_MAX +#line 877 + if (xx > USHORT_MAX) { +#line 877 +#ifdef ERANGE_FILL +#line 877 + *ip = NC_FILL_USHORT; +#line 877 + return NC_ERANGE; +#line 877 +#else +#line 877 + err = NC_ERANGE; +#line 877 +#endif +#line 877 + } +#line 877 +#endif +#line 877 + +#line 877 + if (xx < 0) { +#line 877 +#ifdef ERANGE_FILL +#line 877 + *ip = NC_FILL_USHORT; +#line 877 + return NC_ERANGE; +#line 877 +#else +#line 877 + err = NC_ERANGE; /* because ip is unsigned */ +#line 877 +#endif +#line 877 + } +#line 877 + *ip = (ushort) xx; +#line 877 + return err; +#line 877 +} +#line 877 + +static int +#line 878 +ncx_get_short_uchar(const void *xp, uchar *ip) +#line 878 +{ +#line 878 + int err=NC_NOERR; +#line 878 + ix_short xx = 0; +#line 878 + get_ix_short(xp, &xx); +#line 878 + +#line 878 +#if IX_SHORT_MAX > UCHAR_MAX +#line 878 + if (xx > UCHAR_MAX) { +#line 878 +#ifdef ERANGE_FILL +#line 878 + *ip = NC_FILL_UBYTE; +#line 878 + return NC_ERANGE; +#line 878 +#else +#line 878 + err = NC_ERANGE; +#line 878 +#endif +#line 878 + } +#line 878 +#endif +#line 878 + +#line 878 + if (xx < 0) { +#line 878 +#ifdef ERANGE_FILL +#line 878 + *ip = NC_FILL_UBYTE; +#line 878 + return NC_ERANGE; +#line 878 +#else +#line 878 + err = NC_ERANGE; /* because ip is unsigned */ +#line 878 +#endif +#line 878 + } +#line 878 + *ip = (uchar) xx; +#line 878 + return err; +#line 878 +} +#line 878 + +static int +#line 879 +ncx_get_short_uint(const void *xp, uint *ip) +#line 879 +{ +#line 879 + int err=NC_NOERR; +#line 879 + ix_short xx = 0; +#line 879 + get_ix_short(xp, &xx); +#line 879 + +#line 879 +#if IX_SHORT_MAX > UINT_MAX +#line 879 + if (xx > UINT_MAX) { +#line 879 +#ifdef ERANGE_FILL +#line 879 + *ip = NC_FILL_UINT; +#line 879 + return NC_ERANGE; +#line 879 +#else +#line 879 + err = NC_ERANGE; +#line 879 +#endif +#line 879 + } +#line 879 +#endif +#line 879 + +#line 879 + if (xx < 0) { +#line 879 +#ifdef ERANGE_FILL +#line 879 + *ip = NC_FILL_UINT; +#line 879 + return NC_ERANGE; +#line 879 +#else +#line 879 + err = NC_ERANGE; /* because ip is unsigned */ +#line 879 +#endif +#line 879 + } +#line 879 + *ip = (uint) xx; +#line 879 + return err; +#line 879 +} +#line 879 + +static int +#line 880 +ncx_get_short_ulonglong(const void *xp, ulonglong *ip) +#line 880 +{ +#line 880 + int err=NC_NOERR; +#line 880 + ix_short xx = 0; +#line 880 + get_ix_short(xp, &xx); +#line 880 + +#line 880 +#if IX_SHORT_MAX > ULONGLONG_MAX +#line 880 + if (xx > ULONGLONG_MAX) { +#line 880 +#ifdef ERANGE_FILL +#line 880 + *ip = NC_FILL_UINT64; +#line 880 + return NC_ERANGE; +#line 880 +#else +#line 880 + err = NC_ERANGE; +#line 880 +#endif +#line 880 + } +#line 880 +#endif +#line 880 + +#line 880 + if (xx < 0) { +#line 880 +#ifdef ERANGE_FILL +#line 880 + *ip = NC_FILL_UINT64; +#line 880 + return NC_ERANGE; +#line 880 +#else +#line 880 + err = NC_ERANGE; /* because ip is unsigned */ +#line 880 +#endif +#line 880 + } +#line 880 + *ip = (ulonglong) xx; +#line 880 + return err; +#line 880 +} +#line 880 + +static int +#line 881 +ncx_get_short_float(const void *xp, float *ip) +#line 881 +{ +#line 881 + ix_short xx = 0; +#line 881 + get_ix_short(xp, &xx); +#line 881 + *ip = (float)xx; +#line 881 + return NC_NOERR; +#line 881 +} +#line 881 + +static int +#line 882 +ncx_get_short_double(const void *xp, double *ip) +#line 882 +{ +#line 882 + ix_short xx = 0; +#line 882 + get_ix_short(xp, &xx); +#line 882 + *ip = (double)xx; +#line 882 + return NC_NOERR; +#line 882 +} +#line 882 + + +static int +ncx_put_short_schar(void *xp, const schar *ip, void *fillp) +{ + uchar *cp = (uchar *) xp; + if (*ip & 0x80) + *cp++ = 0xff; + else + *cp++ = 0; + *cp = (uchar)*ip; + return NC_NOERR; +} + +static int +ncx_put_short_uchar(void *xp, const uchar *ip, void *fillp) +{ + uchar *cp = (uchar *) xp; + *cp++ = 0; + *cp = *ip; + return NC_NOERR; +} + +static int +#line 905 +ncx_put_short_short(void *xp, const short *ip, void *fillp) +#line 905 +{ +#line 905 + int err=NC_NOERR; +#line 905 +#if SIZEOF_IX_SHORT == SIZEOF_SHORT && IX_SHORT_MAX == SHORT_MAX +#line 905 + put_ix_short(xp, (const ix_short *)ip); +#line 905 +#else +#line 905 + ix_short xx = NC_FILL_SHORT; +#line 905 + +#line 905 +#if IX_SHORT_MAX < SHORT_MAX +#line 905 + if (*ip > IX_SHORT_MAX || *ip < X_SHORT_MIN) { +#line 905 + +#line 905 +#ifdef ERANGE_FILL +#line 905 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 905 +#endif +#line 905 + err = NC_ERANGE; +#line 905 + } +#line 905 +#ifdef ERANGE_FILL +#line 905 + else +#line 905 +#endif +#line 905 +#endif +#line 905 + xx = (ix_short)*ip; +#line 905 + +#line 905 + put_ix_short(xp, &xx); +#line 905 +#endif +#line 905 + return err; +#line 905 +} +#line 905 + +static int +#line 906 +ncx_put_short_int(void *xp, const int *ip, void *fillp) +#line 906 +{ +#line 906 + int err=NC_NOERR; +#line 906 +#if SIZEOF_IX_SHORT == SIZEOF_INT && IX_SHORT_MAX == INT_MAX +#line 906 + put_ix_short(xp, (const ix_short *)ip); +#line 906 +#else +#line 906 + ix_short xx = NC_FILL_SHORT; +#line 906 + +#line 906 +#if IX_SHORT_MAX < INT_MAX +#line 906 + if (*ip > IX_SHORT_MAX || *ip < X_SHORT_MIN) { +#line 906 + +#line 906 +#ifdef ERANGE_FILL +#line 906 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 906 +#endif +#line 906 + err = NC_ERANGE; +#line 906 + } +#line 906 +#ifdef ERANGE_FILL +#line 906 + else +#line 906 +#endif +#line 906 +#endif +#line 906 + xx = (ix_short)*ip; +#line 906 + +#line 906 + put_ix_short(xp, &xx); +#line 906 +#endif +#line 906 + return err; +#line 906 +} +#line 906 + +static int +#line 907 +ncx_put_short_long(void *xp, const long *ip, void *fillp) +#line 907 +{ +#line 907 + int err=NC_NOERR; +#line 907 +#if SIZEOF_IX_SHORT == SIZEOF_LONG && IX_SHORT_MAX == LONG_MAX +#line 907 + put_ix_short(xp, (const ix_short *)ip); +#line 907 +#else +#line 907 + ix_short xx = NC_FILL_SHORT; +#line 907 + +#line 907 +#if IX_SHORT_MAX < LONG_MAX +#line 907 + if (*ip > IX_SHORT_MAX || *ip < X_SHORT_MIN) { +#line 907 + +#line 907 +#ifdef ERANGE_FILL +#line 907 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 907 +#endif +#line 907 + err = NC_ERANGE; +#line 907 + } +#line 907 +#ifdef ERANGE_FILL +#line 907 + else +#line 907 +#endif +#line 907 +#endif +#line 907 + xx = (ix_short)*ip; +#line 907 + +#line 907 + put_ix_short(xp, &xx); +#line 907 +#endif +#line 907 + return err; +#line 907 +} +#line 907 + +static int +#line 908 +ncx_put_short_longlong(void *xp, const longlong *ip, void *fillp) +#line 908 +{ +#line 908 + int err=NC_NOERR; +#line 908 +#if SIZEOF_IX_SHORT == SIZEOF_LONGLONG && IX_SHORT_MAX == LONGLONG_MAX +#line 908 + put_ix_short(xp, (const ix_short *)ip); +#line 908 +#else +#line 908 + ix_short xx = NC_FILL_SHORT; +#line 908 + +#line 908 +#if IX_SHORT_MAX < LONGLONG_MAX +#line 908 + if (*ip > IX_SHORT_MAX || *ip < X_SHORT_MIN) { +#line 908 + +#line 908 +#ifdef ERANGE_FILL +#line 908 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 908 +#endif +#line 908 + err = NC_ERANGE; +#line 908 + } +#line 908 +#ifdef ERANGE_FILL +#line 908 + else +#line 908 +#endif +#line 908 +#endif +#line 908 + xx = (ix_short)*ip; +#line 908 + +#line 908 + put_ix_short(xp, &xx); +#line 908 +#endif +#line 908 + return err; +#line 908 +} +#line 908 + +static int +#line 909 +ncx_put_short_ushort(void *xp, const ushort *ip, void *fillp) +#line 909 +{ +#line 909 + int err=NC_NOERR; +#line 909 + ix_short xx = NC_FILL_SHORT; +#line 909 + +#line 909 +#if IX_SHORT_MAX < USHORT_MAX +#line 909 + if (*ip > IX_SHORT_MAX) { +#line 909 + +#line 909 +#ifdef ERANGE_FILL +#line 909 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 909 +#endif +#line 909 + err = NC_ERANGE; +#line 909 + } +#line 909 +#ifdef ERANGE_FILL +#line 909 + else +#line 909 +#endif +#line 909 +#endif +#line 909 + xx = (ix_short)*ip; +#line 909 + +#line 909 + put_ix_short(xp, &xx); +#line 909 + return err; +#line 909 +} +#line 909 + +static int +#line 910 +ncx_put_short_uint(void *xp, const uint *ip, void *fillp) +#line 910 +{ +#line 910 + int err=NC_NOERR; +#line 910 + ix_short xx = NC_FILL_SHORT; +#line 910 + +#line 910 +#if IX_SHORT_MAX < UINT_MAX +#line 910 + if (*ip > IX_SHORT_MAX) { +#line 910 + +#line 910 +#ifdef ERANGE_FILL +#line 910 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 910 +#endif +#line 910 + err = NC_ERANGE; +#line 910 + } +#line 910 +#ifdef ERANGE_FILL +#line 910 + else +#line 910 +#endif +#line 910 +#endif +#line 910 + xx = (ix_short)*ip; +#line 910 + +#line 910 + put_ix_short(xp, &xx); +#line 910 + return err; +#line 910 +} +#line 910 + +static int +#line 911 +ncx_put_short_ulonglong(void *xp, const ulonglong *ip, void *fillp) +#line 911 +{ +#line 911 + int err=NC_NOERR; +#line 911 + ix_short xx = NC_FILL_SHORT; +#line 911 + +#line 911 +#if IX_SHORT_MAX < ULONGLONG_MAX +#line 911 + if (*ip > IX_SHORT_MAX) { +#line 911 + +#line 911 +#ifdef ERANGE_FILL +#line 911 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 911 +#endif +#line 911 + err = NC_ERANGE; +#line 911 + } +#line 911 +#ifdef ERANGE_FILL +#line 911 + else +#line 911 +#endif +#line 911 +#endif +#line 911 + xx = (ix_short)*ip; +#line 911 + +#line 911 + put_ix_short(xp, &xx); +#line 911 + return err; +#line 911 +} +#line 911 + +static int +#line 912 +ncx_put_short_float(void *xp, const float *ip, void *fillp) +#line 912 +{ +#line 912 + int err=NC_NOERR; +#line 912 + ix_short xx = NC_FILL_SHORT; +#line 912 + +#line 912 + if (*ip > (double)X_SHORT_MAX || *ip < (double)X_SHORT_MIN) { +#line 912 + +#line 912 +#ifdef ERANGE_FILL +#line 912 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 912 +#endif +#line 912 + err = NC_ERANGE; +#line 912 + } +#line 912 +#ifdef ERANGE_FILL +#line 912 + else +#line 912 +#endif +#line 912 + xx = (ix_short)*ip; +#line 912 + +#line 912 + put_ix_short(xp, &xx); +#line 912 + return err; +#line 912 +} +#line 912 + +static int +#line 913 +ncx_put_short_double(void *xp, const double *ip, void *fillp) +#line 913 +{ +#line 913 + int err=NC_NOERR; +#line 913 + ix_short xx = NC_FILL_SHORT; +#line 913 + +#line 913 + if (*ip > X_SHORT_MAX || *ip < X_SHORT_MIN) { +#line 913 + +#line 913 +#ifdef ERANGE_FILL +#line 913 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 913 +#endif +#line 913 + err = NC_ERANGE; +#line 913 + } +#line 913 +#ifdef ERANGE_FILL +#line 913 + else +#line 913 +#endif +#line 913 + xx = (ix_short)*ip; +#line 913 + +#line 913 + put_ix_short(xp, &xx); +#line 913 + return err; +#line 913 +} +#line 913 + + +/* external NC_USHORT -------------------------------------------------------*/ + +#if USHORT_MAX == X_USHORT_MAX +typedef unsigned short ix_ushort; +#define SIZEOF_IX_USHORT SIZEOF_USHORT +#define IX_USHORT_MAX USHORT_MAX +#elif UINT_MAX >= X_USHORT_MAX +typedef unsigned int ix_ushort; +#define SIZEOF_IX_USHORT SIZEOF_UINT +#define IX_USHORT_MAX UINT_MAX +#elif ULONG_MAX >= X_USHORT_MAX +typedef unsigned long ix_ushort; +#define SIZEOF_IX_USHORT SIZEOF_ULONG +#define IX_USHORT_MAX ULONG_MAX +#elif ULLONG_MAX >= X_USHORT_MAX +typedef unsigned long long ix_ushort; +#define SIZEOF_IX_USHORT SIZEOF_ULONGLONG +#define IX_USHORT_MAX ULLONG_MAX +#else +#error "ix_ushort implementation" +#endif + +static void +get_ix_ushort(const void *xp, ix_ushort *ip) +{ + const uchar *cp = (const uchar *) xp; + *ip = (ix_ushort)(*cp++ << 8); +#if SIZEOF_IX_SHORT > X_SIZEOF_SHORT + if (*ip & 0x8000) + { + /* extern is negative */ + *ip |= (~(0xffff)); /* N.B. Assumes "twos complement" */ + } +#endif + *ip = (ix_ushort)(*ip | *cp); +} + +static void +put_ix_ushort(void *xp, const ix_ushort *ip) +{ + uchar *cp = (uchar *) xp; + *cp++ = (uchar)((*ip) >> 8); + *cp = (uchar)((*ip) & 0xff); +} + +static int +#line 960 +ncx_get_ushort_schar(const void *xp, schar *ip) +#line 960 +{ +#line 960 + int err=NC_NOERR; +#line 960 + ix_ushort xx = 0; +#line 960 + get_ix_ushort(xp, &xx); +#line 960 + +#line 960 +#if IX_USHORT_MAX > SCHAR_MAX +#line 960 + if (xx > SCHAR_MAX) { +#line 960 +#ifdef ERANGE_FILL +#line 960 + *ip = NC_FILL_BYTE; +#line 960 + return NC_ERANGE; +#line 960 +#else +#line 960 + err = NC_ERANGE; +#line 960 +#endif +#line 960 + } +#line 960 +#endif +#line 960 + +#line 960 + +#line 960 + *ip = (schar) xx; +#line 960 + return err; +#line 960 +} +#line 960 + +static int +#line 961 +ncx_get_ushort_short(const void *xp, short *ip) +#line 961 +{ +#line 961 + int err=NC_NOERR; +#line 961 + ix_ushort xx = 0; +#line 961 + get_ix_ushort(xp, &xx); +#line 961 + +#line 961 +#if IX_USHORT_MAX > SHORT_MAX +#line 961 + if (xx > SHORT_MAX) { +#line 961 +#ifdef ERANGE_FILL +#line 961 + *ip = NC_FILL_SHORT; +#line 961 + return NC_ERANGE; +#line 961 +#else +#line 961 + err = NC_ERANGE; +#line 961 +#endif +#line 961 + } +#line 961 +#endif +#line 961 + +#line 961 + +#line 961 + *ip = (short) xx; +#line 961 + return err; +#line 961 +} +#line 961 + +static int +#line 962 +ncx_get_ushort_int(const void *xp, int *ip) +#line 962 +{ +#line 962 + int err=NC_NOERR; +#line 962 + ix_ushort xx = 0; +#line 962 + get_ix_ushort(xp, &xx); +#line 962 + +#line 962 +#if IX_USHORT_MAX > INT_MAX +#line 962 + if (xx > INT_MAX) { +#line 962 +#ifdef ERANGE_FILL +#line 962 + *ip = NC_FILL_INT; +#line 962 + return NC_ERANGE; +#line 962 +#else +#line 962 + err = NC_ERANGE; +#line 962 +#endif +#line 962 + } +#line 962 +#endif +#line 962 + +#line 962 + +#line 962 + *ip = (int) xx; +#line 962 + return err; +#line 962 +} +#line 962 + +static int +#line 963 +ncx_get_ushort_long(const void *xp, long *ip) +#line 963 +{ +#line 963 + int err=NC_NOERR; +#line 963 + ix_ushort xx = 0; +#line 963 + get_ix_ushort(xp, &xx); +#line 963 + +#line 963 +#if IX_USHORT_MAX > LONG_MAX +#line 963 + if (xx > LONG_MAX) { +#line 963 +#ifdef ERANGE_FILL +#line 963 + *ip = NC_FILL_INT; +#line 963 + return NC_ERANGE; +#line 963 +#else +#line 963 + err = NC_ERANGE; +#line 963 +#endif +#line 963 + } +#line 963 +#endif +#line 963 + +#line 963 + +#line 963 + *ip = (long) xx; +#line 963 + return err; +#line 963 +} +#line 963 + +static int +#line 964 +ncx_get_ushort_longlong(const void *xp, longlong *ip) +#line 964 +{ +#line 964 + int err=NC_NOERR; +#line 964 + ix_ushort xx = 0; +#line 964 + get_ix_ushort(xp, &xx); +#line 964 + +#line 964 +#if IX_USHORT_MAX > LONGLONG_MAX +#line 964 + if (xx > LONGLONG_MAX) { +#line 964 +#ifdef ERANGE_FILL +#line 964 + *ip = NC_FILL_INT64; +#line 964 + return NC_ERANGE; +#line 964 +#else +#line 964 + err = NC_ERANGE; +#line 964 +#endif +#line 964 + } +#line 964 +#endif +#line 964 + +#line 964 + +#line 964 + *ip = (longlong) xx; +#line 964 + return err; +#line 964 +} +#line 964 + +static int +#line 965 +ncx_get_ushort_ushort(const void *xp, ushort *ip) +#line 965 +{ +#line 965 + int err=NC_NOERR; +#line 965 +#if SIZEOF_IX_USHORT == SIZEOF_USHORT && IX_USHORT_MAX == USHORT_MAX +#line 965 + get_ix_ushort(xp, (ix_ushort *)ip); +#line 965 +#else +#line 965 + ix_ushort xx = 0; +#line 965 + get_ix_ushort(xp, &xx); +#line 965 + +#line 965 +#if IX_USHORT_MAX > USHORT_MAX +#line 965 + if (xx > USHORT_MAX) { +#line 965 +#ifdef ERANGE_FILL +#line 965 + *ip = NC_FILL_USHORT; +#line 965 + return NC_ERANGE; +#line 965 +#else +#line 965 + err = NC_ERANGE; +#line 965 +#endif +#line 965 + } +#line 965 +#endif +#line 965 + +#line 965 + +#line 965 + *ip = (ushort) xx; +#line 965 +#endif +#line 965 + return err; +#line 965 +} +#line 965 + +static int +#line 966 +ncx_get_ushort_uchar(const void *xp, uchar *ip) +#line 966 +{ +#line 966 + int err=NC_NOERR; +#line 966 +#if SIZEOF_IX_USHORT == SIZEOF_UCHAR && IX_USHORT_MAX == UCHAR_MAX +#line 966 + get_ix_ushort(xp, (ix_ushort *)ip); +#line 966 +#else +#line 966 + ix_ushort xx = 0; +#line 966 + get_ix_ushort(xp, &xx); +#line 966 + +#line 966 +#if IX_USHORT_MAX > UCHAR_MAX +#line 966 + if (xx > UCHAR_MAX) { +#line 966 +#ifdef ERANGE_FILL +#line 966 + *ip = NC_FILL_UBYTE; +#line 966 + return NC_ERANGE; +#line 966 +#else +#line 966 + err = NC_ERANGE; +#line 966 +#endif +#line 966 + } +#line 966 +#endif +#line 966 + +#line 966 + +#line 966 + *ip = (uchar) xx; +#line 966 +#endif +#line 966 + return err; +#line 966 +} +#line 966 + +static int +#line 967 +ncx_get_ushort_uint(const void *xp, uint *ip) +#line 967 +{ +#line 967 + int err=NC_NOERR; +#line 967 +#if SIZEOF_IX_USHORT == SIZEOF_UINT && IX_USHORT_MAX == UINT_MAX +#line 967 + get_ix_ushort(xp, (ix_ushort *)ip); +#line 967 +#else +#line 967 + ix_ushort xx = 0; +#line 967 + get_ix_ushort(xp, &xx); +#line 967 + +#line 967 +#if IX_USHORT_MAX > UINT_MAX +#line 967 + if (xx > UINT_MAX) { +#line 967 +#ifdef ERANGE_FILL +#line 967 + *ip = NC_FILL_UINT; +#line 967 + return NC_ERANGE; +#line 967 +#else +#line 967 + err = NC_ERANGE; +#line 967 +#endif +#line 967 + } +#line 967 +#endif +#line 967 + +#line 967 + +#line 967 + *ip = (uint) xx; +#line 967 +#endif +#line 967 + return err; +#line 967 +} +#line 967 + +static int +#line 968 +ncx_get_ushort_ulonglong(const void *xp, ulonglong *ip) +#line 968 +{ +#line 968 + int err=NC_NOERR; +#line 968 +#if SIZEOF_IX_USHORT == SIZEOF_ULONGLONG && IX_USHORT_MAX == ULONGLONG_MAX +#line 968 + get_ix_ushort(xp, (ix_ushort *)ip); +#line 968 +#else +#line 968 + ix_ushort xx = 0; +#line 968 + get_ix_ushort(xp, &xx); +#line 968 + +#line 968 +#if IX_USHORT_MAX > ULONGLONG_MAX +#line 968 + if (xx > ULONGLONG_MAX) { +#line 968 +#ifdef ERANGE_FILL +#line 968 + *ip = NC_FILL_UINT64; +#line 968 + return NC_ERANGE; +#line 968 +#else +#line 968 + err = NC_ERANGE; +#line 968 +#endif +#line 968 + } +#line 968 +#endif +#line 968 + +#line 968 + +#line 968 + *ip = (ulonglong) xx; +#line 968 +#endif +#line 968 + return err; +#line 968 +} +#line 968 + +static int +#line 969 +ncx_get_ushort_float(const void *xp, float *ip) +#line 969 +{ +#line 969 + ix_ushort xx = 0; +#line 969 + get_ix_ushort(xp, &xx); +#line 969 + *ip = (float)xx; +#line 969 + return NC_NOERR; +#line 969 +} +#line 969 + +static int +#line 970 +ncx_get_ushort_double(const void *xp, double *ip) +#line 970 +{ +#line 970 + ix_ushort xx = 0; +#line 970 + get_ix_ushort(xp, &xx); +#line 970 + *ip = (double)xx; +#line 970 + return NC_NOERR; +#line 970 +} +#line 970 + + +static int +ncx_put_ushort_schar(void *xp, const schar *ip, void *fillp) +{ + int err=NC_NOERR; + uchar *cp; + if (*ip < 0) { +#ifdef ERANGE_FILL + if (fillp != NULL) memcpy(xp, fillp, 2); +#ifndef WORDS_BIGENDIAN + swapn2b(xp, xp, 1); +#endif + return NC_ERANGE; +#else + err = NC_ERANGE; +#endif + } + + cp = (uchar *) xp; + if (*ip & 0x80) + *cp++ = 0xff; + else + *cp++ = 0; + *cp = (uchar)*ip; + + return err; +} + +static int +ncx_put_ushort_uchar(void *xp, const uchar *ip, void *fillp) +{ + uchar *cp = (uchar *) xp; + *cp++ = 0; + *cp = *ip; + return NC_NOERR; +} + +static int +#line 1008 +ncx_put_ushort_short(void *xp, const short *ip, void *fillp) +#line 1008 +{ +#line 1008 + int err=NC_NOERR; +#line 1008 + ix_ushort xx = NC_FILL_USHORT; +#line 1008 + +#line 1008 +#if IX_USHORT_MAX < SHORT_MAX +#line 1008 + if (*ip > IX_USHORT_MAX) { +#line 1008 + +#line 1008 +#ifdef ERANGE_FILL +#line 1008 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 1008 +#endif +#line 1008 + err = NC_ERANGE; +#line 1008 + } +#line 1008 +#ifdef ERANGE_FILL +#line 1008 + else +#line 1008 +#endif +#line 1008 +#endif +#line 1008 + if (*ip < 0) { +#line 1008 + +#line 1008 +#ifdef ERANGE_FILL +#line 1008 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 1008 +#endif +#line 1008 + err = NC_ERANGE; /* because xp is unsigned */ +#line 1008 + } +#line 1008 +#ifdef ERANGE_FILL +#line 1008 + else +#line 1008 +#endif +#line 1008 + xx = (ix_ushort)*ip; +#line 1008 + +#line 1008 + put_ix_ushort(xp, &xx); +#line 1008 + return err; +#line 1008 +} +#line 1008 + +static int +#line 1009 +ncx_put_ushort_int(void *xp, const int *ip, void *fillp) +#line 1009 +{ +#line 1009 + int err=NC_NOERR; +#line 1009 + ix_ushort xx = NC_FILL_USHORT; +#line 1009 + +#line 1009 +#if IX_USHORT_MAX < INT_MAX +#line 1009 + if (*ip > IX_USHORT_MAX) { +#line 1009 + +#line 1009 +#ifdef ERANGE_FILL +#line 1009 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 1009 +#endif +#line 1009 + err = NC_ERANGE; +#line 1009 + } +#line 1009 +#ifdef ERANGE_FILL +#line 1009 + else +#line 1009 +#endif +#line 1009 +#endif +#line 1009 + if (*ip < 0) { +#line 1009 + +#line 1009 +#ifdef ERANGE_FILL +#line 1009 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 1009 +#endif +#line 1009 + err = NC_ERANGE; /* because xp is unsigned */ +#line 1009 + } +#line 1009 +#ifdef ERANGE_FILL +#line 1009 + else +#line 1009 +#endif +#line 1009 + xx = (ix_ushort)*ip; +#line 1009 + +#line 1009 + put_ix_ushort(xp, &xx); +#line 1009 + return err; +#line 1009 +} +#line 1009 + +static int +#line 1010 +ncx_put_ushort_long(void *xp, const long *ip, void *fillp) +#line 1010 +{ +#line 1010 + int err=NC_NOERR; +#line 1010 + ix_ushort xx = NC_FILL_USHORT; +#line 1010 + +#line 1010 +#if IX_USHORT_MAX < LONG_MAX +#line 1010 + if (*ip > IX_USHORT_MAX) { +#line 1010 + +#line 1010 +#ifdef ERANGE_FILL +#line 1010 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 1010 +#endif +#line 1010 + err = NC_ERANGE; +#line 1010 + } +#line 1010 +#ifdef ERANGE_FILL +#line 1010 + else +#line 1010 +#endif +#line 1010 +#endif +#line 1010 + if (*ip < 0) { +#line 1010 + +#line 1010 +#ifdef ERANGE_FILL +#line 1010 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 1010 +#endif +#line 1010 + err = NC_ERANGE; /* because xp is unsigned */ +#line 1010 + } +#line 1010 +#ifdef ERANGE_FILL +#line 1010 + else +#line 1010 +#endif +#line 1010 + xx = (ix_ushort)*ip; +#line 1010 + +#line 1010 + put_ix_ushort(xp, &xx); +#line 1010 + return err; +#line 1010 +} +#line 1010 + +static int +#line 1011 +ncx_put_ushort_longlong(void *xp, const longlong *ip, void *fillp) +#line 1011 +{ +#line 1011 + int err=NC_NOERR; +#line 1011 + ix_ushort xx = NC_FILL_USHORT; +#line 1011 + +#line 1011 +#if IX_USHORT_MAX < LONGLONG_MAX +#line 1011 + if (*ip > IX_USHORT_MAX) { +#line 1011 + +#line 1011 +#ifdef ERANGE_FILL +#line 1011 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 1011 +#endif +#line 1011 + err = NC_ERANGE; +#line 1011 + } +#line 1011 +#ifdef ERANGE_FILL +#line 1011 + else +#line 1011 +#endif +#line 1011 +#endif +#line 1011 + if (*ip < 0) { +#line 1011 + +#line 1011 +#ifdef ERANGE_FILL +#line 1011 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 1011 +#endif +#line 1011 + err = NC_ERANGE; /* because xp is unsigned */ +#line 1011 + } +#line 1011 +#ifdef ERANGE_FILL +#line 1011 + else +#line 1011 +#endif +#line 1011 + xx = (ix_ushort)*ip; +#line 1011 + +#line 1011 + put_ix_ushort(xp, &xx); +#line 1011 + return err; +#line 1011 +} +#line 1011 + +static int +#line 1012 +ncx_put_ushort_ushort(void *xp, const ushort *ip, void *fillp) +#line 1012 +{ +#line 1012 + int err=NC_NOERR; +#line 1012 +#if SIZEOF_IX_USHORT == SIZEOF_USHORT && IX_USHORT_MAX == USHORT_MAX +#line 1012 + put_ix_ushort(xp, (const ix_ushort *)ip); +#line 1012 +#else +#line 1012 + ix_ushort xx = NC_FILL_USHORT; +#line 1012 + +#line 1012 +#if IX_USHORT_MAX < USHORT_MAX +#line 1012 + if (*ip > IX_USHORT_MAX) { +#line 1012 + +#line 1012 +#ifdef ERANGE_FILL +#line 1012 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 1012 +#endif +#line 1012 + err = NC_ERANGE; +#line 1012 + } +#line 1012 +#ifdef ERANGE_FILL +#line 1012 + else +#line 1012 +#endif +#line 1012 +#endif +#line 1012 + xx = (ix_ushort)*ip; +#line 1012 + +#line 1012 + put_ix_ushort(xp, &xx); +#line 1012 +#endif +#line 1012 + return err; +#line 1012 +} +#line 1012 + +static int +#line 1013 +ncx_put_ushort_uint(void *xp, const uint *ip, void *fillp) +#line 1013 +{ +#line 1013 + int err=NC_NOERR; +#line 1013 +#if SIZEOF_IX_USHORT == SIZEOF_UINT && IX_USHORT_MAX == UINT_MAX +#line 1013 + put_ix_ushort(xp, (const ix_ushort *)ip); +#line 1013 +#else +#line 1013 + ix_ushort xx = NC_FILL_USHORT; +#line 1013 + +#line 1013 +#if IX_USHORT_MAX < UINT_MAX +#line 1013 + if (*ip > IX_USHORT_MAX) { +#line 1013 + +#line 1013 +#ifdef ERANGE_FILL +#line 1013 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 1013 +#endif +#line 1013 + err = NC_ERANGE; +#line 1013 + } +#line 1013 +#ifdef ERANGE_FILL +#line 1013 + else +#line 1013 +#endif +#line 1013 +#endif +#line 1013 + xx = (ix_ushort)*ip; +#line 1013 + +#line 1013 + put_ix_ushort(xp, &xx); +#line 1013 +#endif +#line 1013 + return err; +#line 1013 +} +#line 1013 + +static int +#line 1014 +ncx_put_ushort_ulonglong(void *xp, const ulonglong *ip, void *fillp) +#line 1014 +{ +#line 1014 + int err=NC_NOERR; +#line 1014 +#if SIZEOF_IX_USHORT == SIZEOF_ULONGLONG && IX_USHORT_MAX == ULONGLONG_MAX +#line 1014 + put_ix_ushort(xp, (const ix_ushort *)ip); +#line 1014 +#else +#line 1014 + ix_ushort xx = NC_FILL_USHORT; +#line 1014 + +#line 1014 +#if IX_USHORT_MAX < ULONGLONG_MAX +#line 1014 + if (*ip > IX_USHORT_MAX) { +#line 1014 + +#line 1014 +#ifdef ERANGE_FILL +#line 1014 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 1014 +#endif +#line 1014 + err = NC_ERANGE; +#line 1014 + } +#line 1014 +#ifdef ERANGE_FILL +#line 1014 + else +#line 1014 +#endif +#line 1014 +#endif +#line 1014 + xx = (ix_ushort)*ip; +#line 1014 + +#line 1014 + put_ix_ushort(xp, &xx); +#line 1014 +#endif +#line 1014 + return err; +#line 1014 +} +#line 1014 + +static int +#line 1015 +ncx_put_ushort_float(void *xp, const float *ip, void *fillp) +#line 1015 +{ +#line 1015 + int err=NC_NOERR; +#line 1015 + ix_ushort xx = NC_FILL_USHORT; +#line 1015 + +#line 1015 + if (*ip > (double)X_USHORT_MAX || *ip < 0) { +#line 1015 + +#line 1015 +#ifdef ERANGE_FILL +#line 1015 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 1015 +#endif +#line 1015 + err = NC_ERANGE; +#line 1015 + } +#line 1015 +#ifdef ERANGE_FILL +#line 1015 + else +#line 1015 +#endif +#line 1015 + xx = (ix_ushort)*ip; +#line 1015 + +#line 1015 + put_ix_ushort(xp, &xx); +#line 1015 + return err; +#line 1015 +} +#line 1015 + +static int +#line 1016 +ncx_put_ushort_double(void *xp, const double *ip, void *fillp) +#line 1016 +{ +#line 1016 + int err=NC_NOERR; +#line 1016 + ix_ushort xx = NC_FILL_USHORT; +#line 1016 + +#line 1016 + if (*ip > X_USHORT_MAX || *ip < 0) { +#line 1016 + +#line 1016 +#ifdef ERANGE_FILL +#line 1016 + if (fillp != NULL) memcpy(&xx, fillp, 2); +#line 1016 +#endif +#line 1016 + err = NC_ERANGE; +#line 1016 + } +#line 1016 +#ifdef ERANGE_FILL +#line 1016 + else +#line 1016 +#endif +#line 1016 + xx = (ix_ushort)*ip; +#line 1016 + +#line 1016 + put_ix_ushort(xp, &xx); +#line 1016 + return err; +#line 1016 +} +#line 1016 + + +/* external NC_INT ----------------------------------------------------------*/ + +#if SHORT_MAX == X_INT_MAX +typedef short ix_int; +#define SIZEOF_IX_INT SIZEOF_SHORT +#define IX_INT_MAX SHORT_MAX +#elif INT_MAX >= X_INT_MAX +typedef int ix_int; +#define SIZEOF_IX_INT SIZEOF_INT +#define IX_INT_MAX INT_MAX +#elif LONG_MAX >= X_INT_MAX +typedef long ix_int; +#define SIZEOF_IX_INT SIZEOF_LONG +#define IX_INT_MAX LONG_MAX +#else +#error "ix_int implementation" +#endif + + +static void +get_ix_int(const void *xp, ix_int *ip) +{ + const uchar *cp = (const uchar *) xp; + +#if INT_MAX >= X_INT_MAX + *ip = (ix_int)((unsigned)(*cp++) << 24); +#else + *ip = *cp++ << 24; +#endif +#if SIZEOF_IX_INT > X_SIZEOF_INT + if (*ip & 0x80000000) + { + /* extern is negative */ + *ip |= (~(0xffffffff)); /* N.B. Assumes "twos complement" */ + } +#endif + *ip |= (*cp++ << 16); + *ip |= (*cp++ << 8); + *ip |= *cp; +} + +static void +put_ix_int(void *xp, const ix_int *ip) +{ + uchar *cp = (uchar *) xp; + + *cp++ = (uchar)( (*ip) >> 24); + *cp++ = (uchar)(((*ip) & 0x00ff0000) >> 16); + *cp++ = (uchar)(((*ip) & 0x0000ff00) >> 8); + *cp = (uchar)( (*ip) & 0x000000ff); +} + +#if X_SIZEOF_INT != SIZEOF_INT +static int +#line 1071 +ncx_get_int_int(const void *xp, int *ip) +#line 1071 +{ +#line 1071 + int err=NC_NOERR; +#line 1071 +#if SIZEOF_IX_INT == SIZEOF_INT && IX_INT_MAX == INT_MAX +#line 1071 + get_ix_int(xp, (ix_int *)ip); +#line 1071 +#else +#line 1071 + ix_int xx = 0; +#line 1071 + get_ix_int(xp, &xx); +#line 1071 + +#line 1071 +#if IX_INT_MAX > INT_MAX +#line 1071 + if (xx > INT_MAX || xx < INT_MIN) { +#line 1071 +#ifdef ERANGE_FILL +#line 1071 + *ip = NC_FILL_INT; +#line 1071 + return NC_ERANGE; +#line 1071 +#else +#line 1071 + err = NC_ERANGE; +#line 1071 +#endif +#line 1071 + } +#line 1071 +#endif +#line 1071 + +#line 1071 + +#line 1071 + *ip = (int) xx; +#line 1071 +#endif +#line 1071 + return err; +#line 1071 +} +#line 1071 + +#endif +static int +#line 1073 +ncx_get_int_schar(const void *xp, schar *ip) +#line 1073 +{ +#line 1073 + int err=NC_NOERR; +#line 1073 + ix_int xx = 0; +#line 1073 + get_ix_int(xp, &xx); +#line 1073 + +#line 1073 +#if IX_INT_MAX > SCHAR_MAX +#line 1073 + if (xx > SCHAR_MAX || xx < SCHAR_MIN) { +#line 1073 +#ifdef ERANGE_FILL +#line 1073 + *ip = NC_FILL_BYTE; +#line 1073 + return NC_ERANGE; +#line 1073 +#else +#line 1073 + err = NC_ERANGE; +#line 1073 +#endif +#line 1073 + } +#line 1073 +#endif +#line 1073 + +#line 1073 + +#line 1073 + *ip = (schar) xx; +#line 1073 + return err; +#line 1073 +} +#line 1073 + +static int +#line 1074 +ncx_get_int_short(const void *xp, short *ip) +#line 1074 +{ +#line 1074 + int err=NC_NOERR; +#line 1074 +#if SIZEOF_IX_INT == SIZEOF_SHORT && IX_INT_MAX == SHORT_MAX +#line 1074 + get_ix_int(xp, (ix_int *)ip); +#line 1074 +#else +#line 1074 + ix_int xx = 0; +#line 1074 + get_ix_int(xp, &xx); +#line 1074 + +#line 1074 +#if IX_INT_MAX > SHORT_MAX +#line 1074 + if (xx > SHORT_MAX || xx < SHORT_MIN) { +#line 1074 +#ifdef ERANGE_FILL +#line 1074 + *ip = NC_FILL_SHORT; +#line 1074 + return NC_ERANGE; +#line 1074 +#else +#line 1074 + err = NC_ERANGE; +#line 1074 +#endif +#line 1074 + } +#line 1074 +#endif +#line 1074 + +#line 1074 + +#line 1074 + *ip = (short) xx; +#line 1074 +#endif +#line 1074 + return err; +#line 1074 +} +#line 1074 + +static int +#line 1075 +ncx_get_int_long(const void *xp, long *ip) +#line 1075 +{ +#line 1075 + int err=NC_NOERR; +#line 1075 +#if SIZEOF_IX_INT == SIZEOF_LONG && IX_INT_MAX == LONG_MAX +#line 1075 + get_ix_int(xp, (ix_int *)ip); +#line 1075 +#else +#line 1075 + ix_int xx = 0; +#line 1075 + get_ix_int(xp, &xx); +#line 1075 + +#line 1075 +#if IX_INT_MAX > LONG_MAX +#line 1075 + if (xx > LONG_MAX || xx < LONG_MIN) { +#line 1075 +#ifdef ERANGE_FILL +#line 1075 + *ip = NC_FILL_INT; +#line 1075 + return NC_ERANGE; +#line 1075 +#else +#line 1075 + err = NC_ERANGE; +#line 1075 +#endif +#line 1075 + } +#line 1075 +#endif +#line 1075 + +#line 1075 + +#line 1075 + *ip = (long) xx; +#line 1075 +#endif +#line 1075 + return err; +#line 1075 +} +#line 1075 + +static int +#line 1076 +ncx_get_int_longlong(const void *xp, longlong *ip) +#line 1076 +{ +#line 1076 + int err=NC_NOERR; +#line 1076 +#if SIZEOF_IX_INT == SIZEOF_LONGLONG && IX_INT_MAX == LONGLONG_MAX +#line 1076 + get_ix_int(xp, (ix_int *)ip); +#line 1076 +#else +#line 1076 + ix_int xx = 0; +#line 1076 + get_ix_int(xp, &xx); +#line 1076 + +#line 1076 +#if IX_INT_MAX > LONGLONG_MAX +#line 1076 + if (xx > LONGLONG_MAX || xx < LONGLONG_MIN) { +#line 1076 +#ifdef ERANGE_FILL +#line 1076 + *ip = NC_FILL_INT64; +#line 1076 + return NC_ERANGE; +#line 1076 +#else +#line 1076 + err = NC_ERANGE; +#line 1076 +#endif +#line 1076 + } +#line 1076 +#endif +#line 1076 + +#line 1076 + +#line 1076 + *ip = (longlong) xx; +#line 1076 +#endif +#line 1076 + return err; +#line 1076 +} +#line 1076 + +static int +#line 1077 +ncx_get_int_ushort(const void *xp, ushort *ip) +#line 1077 +{ +#line 1077 + int err=NC_NOERR; +#line 1077 + ix_int xx = 0; +#line 1077 + get_ix_int(xp, &xx); +#line 1077 + +#line 1077 +#if IX_INT_MAX > USHORT_MAX +#line 1077 + if (xx > USHORT_MAX) { +#line 1077 +#ifdef ERANGE_FILL +#line 1077 + *ip = NC_FILL_USHORT; +#line 1077 + return NC_ERANGE; +#line 1077 +#else +#line 1077 + err = NC_ERANGE; +#line 1077 +#endif +#line 1077 + } +#line 1077 +#endif +#line 1077 + +#line 1077 + if (xx < 0) { +#line 1077 +#ifdef ERANGE_FILL +#line 1077 + *ip = NC_FILL_USHORT; +#line 1077 + return NC_ERANGE; +#line 1077 +#else +#line 1077 + err = NC_ERANGE; /* because ip is unsigned */ +#line 1077 +#endif +#line 1077 + } +#line 1077 + *ip = (ushort) xx; +#line 1077 + return err; +#line 1077 +} +#line 1077 + +static int +#line 1078 +ncx_get_int_uchar(const void *xp, uchar *ip) +#line 1078 +{ +#line 1078 + int err=NC_NOERR; +#line 1078 + ix_int xx = 0; +#line 1078 + get_ix_int(xp, &xx); +#line 1078 + +#line 1078 +#if IX_INT_MAX > UCHAR_MAX +#line 1078 + if (xx > UCHAR_MAX) { +#line 1078 +#ifdef ERANGE_FILL +#line 1078 + *ip = NC_FILL_UBYTE; +#line 1078 + return NC_ERANGE; +#line 1078 +#else +#line 1078 + err = NC_ERANGE; +#line 1078 +#endif +#line 1078 + } +#line 1078 +#endif +#line 1078 + +#line 1078 + if (xx < 0) { +#line 1078 +#ifdef ERANGE_FILL +#line 1078 + *ip = NC_FILL_UBYTE; +#line 1078 + return NC_ERANGE; +#line 1078 +#else +#line 1078 + err = NC_ERANGE; /* because ip is unsigned */ +#line 1078 +#endif +#line 1078 + } +#line 1078 + *ip = (uchar) xx; +#line 1078 + return err; +#line 1078 +} +#line 1078 + +static int +#line 1079 +ncx_get_int_uint(const void *xp, uint *ip) +#line 1079 +{ +#line 1079 + int err=NC_NOERR; +#line 1079 + ix_int xx = 0; +#line 1079 + get_ix_int(xp, &xx); +#line 1079 + +#line 1079 +#if IX_INT_MAX > UINT_MAX +#line 1079 + if (xx > UINT_MAX) { +#line 1079 +#ifdef ERANGE_FILL +#line 1079 + *ip = NC_FILL_UINT; +#line 1079 + return NC_ERANGE; +#line 1079 +#else +#line 1079 + err = NC_ERANGE; +#line 1079 +#endif +#line 1079 + } +#line 1079 +#endif +#line 1079 + +#line 1079 + if (xx < 0) { +#line 1079 +#ifdef ERANGE_FILL +#line 1079 + *ip = NC_FILL_UINT; +#line 1079 + return NC_ERANGE; +#line 1079 +#else +#line 1079 + err = NC_ERANGE; /* because ip is unsigned */ +#line 1079 +#endif +#line 1079 + } +#line 1079 + *ip = (uint) xx; +#line 1079 + return err; +#line 1079 +} +#line 1079 + +static int +#line 1080 +ncx_get_int_ulonglong(const void *xp, ulonglong *ip) +#line 1080 +{ +#line 1080 + int err=NC_NOERR; +#line 1080 + ix_int xx = 0; +#line 1080 + get_ix_int(xp, &xx); +#line 1080 + +#line 1080 +#if IX_INT_MAX > ULONGLONG_MAX +#line 1080 + if (xx > ULONGLONG_MAX) { +#line 1080 +#ifdef ERANGE_FILL +#line 1080 + *ip = NC_FILL_UINT64; +#line 1080 + return NC_ERANGE; +#line 1080 +#else +#line 1080 + err = NC_ERANGE; +#line 1080 +#endif +#line 1080 + } +#line 1080 +#endif +#line 1080 + +#line 1080 + if (xx < 0) { +#line 1080 +#ifdef ERANGE_FILL +#line 1080 + *ip = NC_FILL_UINT64; +#line 1080 + return NC_ERANGE; +#line 1080 +#else +#line 1080 + err = NC_ERANGE; /* because ip is unsigned */ +#line 1080 +#endif +#line 1080 + } +#line 1080 + *ip = (ulonglong) xx; +#line 1080 + return err; +#line 1080 +} +#line 1080 + +static int +#line 1081 +ncx_get_int_float(const void *xp, float *ip) +#line 1081 +{ +#line 1081 + ix_int xx = 0; +#line 1081 + get_ix_int(xp, &xx); +#line 1081 + *ip = (float)xx; +#line 1081 + return NC_NOERR; +#line 1081 +} +#line 1081 + +static int +#line 1082 +ncx_get_int_double(const void *xp, double *ip) +#line 1082 +{ +#line 1082 + ix_int xx = 0; +#line 1082 + get_ix_int(xp, &xx); +#line 1082 + *ip = (double)xx; +#line 1082 + return NC_NOERR; +#line 1082 +} +#line 1082 + + +static int +ncx_put_int_schar(void *xp, const schar *ip, void *fillp) +{ + uchar *cp = (uchar *) xp; + if (*ip & 0x80) + { + *cp++ = 0xff; + *cp++ = 0xff; + *cp++ = 0xff; + } + else + { + *cp++ = 0x00; + *cp++ = 0x00; + *cp++ = 0x00; + } + *cp = (uchar)*ip; + return NC_NOERR; +} + +static int +ncx_put_int_uchar(void *xp, const uchar *ip, void *fillp) +{ + uchar *cp = (uchar *) xp; + *cp++ = 0x00; + *cp++ = 0x00; + *cp++ = 0x00; + *cp = *ip; + return NC_NOERR; +} + +#if X_SIZEOF_INT != SIZEOF_INT +static int +#line 1116 +ncx_put_int_int(void *xp, const int *ip, void *fillp) +#line 1116 +{ +#line 1116 + int err=NC_NOERR; +#line 1116 +#if SIZEOF_IX_INT == SIZEOF_INT && IX_INT_MAX == INT_MAX +#line 1116 + put_ix_int(xp, (const ix_int *)ip); +#line 1116 +#else +#line 1116 + ix_int xx = NC_FILL_INT; +#line 1116 + +#line 1116 +#if IX_INT_MAX < INT_MAX +#line 1116 + if (*ip > IX_INT_MAX || *ip < X_INT_MIN) { +#line 1116 + +#line 1116 +#ifdef ERANGE_FILL +#line 1116 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1116 +#endif +#line 1116 + err = NC_ERANGE; +#line 1116 + } +#line 1116 +#ifdef ERANGE_FILL +#line 1116 + else +#line 1116 +#endif +#line 1116 +#endif +#line 1116 + xx = (ix_int)*ip; +#line 1116 + +#line 1116 + put_ix_int(xp, &xx); +#line 1116 +#endif +#line 1116 + return err; +#line 1116 +} +#line 1116 + +#endif +static int +#line 1118 +ncx_put_int_short(void *xp, const short *ip, void *fillp) +#line 1118 +{ +#line 1118 + int err=NC_NOERR; +#line 1118 +#if SIZEOF_IX_INT == SIZEOF_SHORT && IX_INT_MAX == SHORT_MAX +#line 1118 + put_ix_int(xp, (const ix_int *)ip); +#line 1118 +#else +#line 1118 + ix_int xx = NC_FILL_INT; +#line 1118 + +#line 1118 +#if IX_INT_MAX < SHORT_MAX +#line 1118 + if (*ip > IX_INT_MAX || *ip < X_INT_MIN) { +#line 1118 + +#line 1118 +#ifdef ERANGE_FILL +#line 1118 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1118 +#endif +#line 1118 + err = NC_ERANGE; +#line 1118 + } +#line 1118 +#ifdef ERANGE_FILL +#line 1118 + else +#line 1118 +#endif +#line 1118 +#endif +#line 1118 + xx = (ix_int)*ip; +#line 1118 + +#line 1118 + put_ix_int(xp, &xx); +#line 1118 +#endif +#line 1118 + return err; +#line 1118 +} +#line 1118 + +static int +#line 1119 +ncx_put_int_long(void *xp, const long *ip, void *fillp) +#line 1119 +{ +#line 1119 + int err=NC_NOERR; +#line 1119 +#if SIZEOF_IX_INT == SIZEOF_LONG && IX_INT_MAX == LONG_MAX +#line 1119 + put_ix_int(xp, (const ix_int *)ip); +#line 1119 +#else +#line 1119 + ix_int xx = NC_FILL_INT; +#line 1119 + +#line 1119 +#if IX_INT_MAX < LONG_MAX +#line 1119 + if (*ip > IX_INT_MAX || *ip < X_INT_MIN) { +#line 1119 + +#line 1119 +#ifdef ERANGE_FILL +#line 1119 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1119 +#endif +#line 1119 + err = NC_ERANGE; +#line 1119 + } +#line 1119 +#ifdef ERANGE_FILL +#line 1119 + else +#line 1119 +#endif +#line 1119 +#endif +#line 1119 + xx = (ix_int)*ip; +#line 1119 + +#line 1119 + put_ix_int(xp, &xx); +#line 1119 +#endif +#line 1119 + return err; +#line 1119 +} +#line 1119 + +static int +#line 1120 +ncx_put_int_longlong(void *xp, const longlong *ip, void *fillp) +#line 1120 +{ +#line 1120 + int err=NC_NOERR; +#line 1120 +#if SIZEOF_IX_INT == SIZEOF_LONGLONG && IX_INT_MAX == LONGLONG_MAX +#line 1120 + put_ix_int(xp, (const ix_int *)ip); +#line 1120 +#else +#line 1120 + ix_int xx = NC_FILL_INT; +#line 1120 + +#line 1120 +#if IX_INT_MAX < LONGLONG_MAX +#line 1120 + if (*ip > IX_INT_MAX || *ip < X_INT_MIN) { +#line 1120 + +#line 1120 +#ifdef ERANGE_FILL +#line 1120 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1120 +#endif +#line 1120 + err = NC_ERANGE; +#line 1120 + } +#line 1120 +#ifdef ERANGE_FILL +#line 1120 + else +#line 1120 +#endif +#line 1120 +#endif +#line 1120 + xx = (ix_int)*ip; +#line 1120 + +#line 1120 + put_ix_int(xp, &xx); +#line 1120 +#endif +#line 1120 + return err; +#line 1120 +} +#line 1120 + +static int +#line 1121 +ncx_put_int_ushort(void *xp, const ushort *ip, void *fillp) +#line 1121 +{ +#line 1121 + int err=NC_NOERR; +#line 1121 + ix_int xx = NC_FILL_INT; +#line 1121 + +#line 1121 +#if IX_INT_MAX < USHORT_MAX +#line 1121 + if (*ip > IX_INT_MAX) { +#line 1121 + +#line 1121 +#ifdef ERANGE_FILL +#line 1121 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1121 +#endif +#line 1121 + err = NC_ERANGE; +#line 1121 + } +#line 1121 +#ifdef ERANGE_FILL +#line 1121 + else +#line 1121 +#endif +#line 1121 +#endif +#line 1121 + xx = (ix_int)*ip; +#line 1121 + +#line 1121 + put_ix_int(xp, &xx); +#line 1121 + return err; +#line 1121 +} +#line 1121 + +static int +#line 1122 +ncx_put_int_uint(void *xp, const uint *ip, void *fillp) +#line 1122 +{ +#line 1122 + int err=NC_NOERR; +#line 1122 + ix_int xx = NC_FILL_INT; +#line 1122 + +#line 1122 +#if IX_INT_MAX < UINT_MAX +#line 1122 + if (*ip > IX_INT_MAX) { +#line 1122 + +#line 1122 +#ifdef ERANGE_FILL +#line 1122 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1122 +#endif +#line 1122 + err = NC_ERANGE; +#line 1122 + } +#line 1122 +#ifdef ERANGE_FILL +#line 1122 + else +#line 1122 +#endif +#line 1122 +#endif +#line 1122 + xx = (ix_int)*ip; +#line 1122 + +#line 1122 + put_ix_int(xp, &xx); +#line 1122 + return err; +#line 1122 +} +#line 1122 + +static int +#line 1123 +ncx_put_int_ulonglong(void *xp, const ulonglong *ip, void *fillp) +#line 1123 +{ +#line 1123 + int err=NC_NOERR; +#line 1123 + ix_int xx = NC_FILL_INT; +#line 1123 + +#line 1123 +#if IX_INT_MAX < ULONGLONG_MAX +#line 1123 + if (*ip > IX_INT_MAX) { +#line 1123 + +#line 1123 +#ifdef ERANGE_FILL +#line 1123 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1123 +#endif +#line 1123 + err = NC_ERANGE; +#line 1123 + } +#line 1123 +#ifdef ERANGE_FILL +#line 1123 + else +#line 1123 +#endif +#line 1123 +#endif +#line 1123 + xx = (ix_int)*ip; +#line 1123 + +#line 1123 + put_ix_int(xp, &xx); +#line 1123 + return err; +#line 1123 +} +#line 1123 + +static int +#line 1124 +ncx_put_int_float(void *xp, const float *ip, void *fillp) +#line 1124 +{ +#line 1124 + int err=NC_NOERR; +#line 1124 + ix_int xx = NC_FILL_INT; +#line 1124 + +#line 1124 + if (*ip > (double)X_INT_MAX || *ip < (double)X_INT_MIN) { +#line 1124 + +#line 1124 +#ifdef ERANGE_FILL +#line 1124 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1124 +#endif +#line 1124 + err = NC_ERANGE; +#line 1124 + } +#line 1124 +#ifdef ERANGE_FILL +#line 1124 + else +#line 1124 +#endif +#line 1124 + xx = (ix_int)*ip; +#line 1124 + +#line 1124 + put_ix_int(xp, &xx); +#line 1124 + return err; +#line 1124 +} +#line 1124 + +static int +#line 1125 +ncx_put_int_double(void *xp, const double *ip, void *fillp) +#line 1125 +{ +#line 1125 + int err=NC_NOERR; +#line 1125 + ix_int xx = NC_FILL_INT; +#line 1125 + +#line 1125 + if (*ip > X_INT_MAX || *ip < X_INT_MIN) { +#line 1125 + +#line 1125 +#ifdef ERANGE_FILL +#line 1125 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1125 +#endif +#line 1125 + err = NC_ERANGE; +#line 1125 + } +#line 1125 +#ifdef ERANGE_FILL +#line 1125 + else +#line 1125 +#endif +#line 1125 + xx = (ix_int)*ip; +#line 1125 + +#line 1125 + put_ix_int(xp, &xx); +#line 1125 + return err; +#line 1125 +} +#line 1125 + + + +/* external NC_UINT ---------------------------------------------------------*/ + +#if USHORT_MAX == X_UINT_MAX +typedef ushort ix_uint; +#define SIZEOF_IX_UINT SIZEOF_USHORT +#define IX_UINT_MAX USHORT_MAX +#elif UINT_MAX >= X_UINT_MAX +typedef uint ix_uint; +#define SIZEOF_IX_UINT SIZEOF_UINT +#define IX_UINT_MAX UINT_MAX +#elif ULONG_MAX >= X_UINT_MAX +typedef ulong ix_uint; +#define SIZEOF_IX_UINT SIZEOF_ULONG +#define IX_UINT_MAX ULONG_MAX +#else +#error "ix_uint implementation" +#endif + + +static void +get_ix_uint(const void *xp, ix_uint *ip) +{ + const uchar *cp = (const uchar *) xp; + + *ip = (ix_uint)(*cp++ << 24); + *ip = (ix_uint)(*ip | (ix_uint)(*cp++ << 16)); + *ip = (ix_uint)(*ip | (ix_uint)(*cp++ << 8)); + *ip = (ix_uint)(*ip | *cp); +} + +static void +put_ix_uint(void *xp, const ix_uint *ip) +{ + uchar *cp = (uchar *) xp; + + *cp++ = (uchar)((*ip) >> 24); + *cp++ = (uchar)(((*ip) & 0x00ff0000) >> 16); + *cp++ = (uchar)(((*ip) & 0x0000ff00) >> 8); + *cp = (uchar)( (*ip) & 0x000000ff); +} + +#if X_SIZEOF_UINT != SIZEOF_UINT +static int +#line 1170 +ncx_get_uint_uint(const void *xp, uint *ip) +#line 1170 +{ +#line 1170 + int err=NC_NOERR; +#line 1170 +#if SIZEOF_IX_UINT == SIZEOF_UINT && IX_UINT_MAX == UINT_MAX +#line 1170 + get_ix_uint(xp, (ix_uint *)ip); +#line 1170 +#else +#line 1170 + ix_uint xx = 0; +#line 1170 + get_ix_uint(xp, &xx); +#line 1170 + +#line 1170 +#if IX_UINT_MAX > UINT_MAX +#line 1170 + if (xx > UINT_MAX) { +#line 1170 +#ifdef ERANGE_FILL +#line 1170 + *ip = NC_FILL_UINT; +#line 1170 + return NC_ERANGE; +#line 1170 +#else +#line 1170 + err = NC_ERANGE; +#line 1170 +#endif +#line 1170 + } +#line 1170 +#endif +#line 1170 + +#line 1170 + +#line 1170 + *ip = (uint) xx; +#line 1170 +#endif +#line 1170 + return err; +#line 1170 +} +#line 1170 + +#endif + +static int +#line 1173 +ncx_get_uint_schar(const void *xp, schar *ip) +#line 1173 +{ +#line 1173 + int err=NC_NOERR; +#line 1173 + ix_uint xx = 0; +#line 1173 + get_ix_uint(xp, &xx); +#line 1173 + +#line 1173 +#if IX_UINT_MAX > SCHAR_MAX +#line 1173 + if (xx > SCHAR_MAX) { +#line 1173 +#ifdef ERANGE_FILL +#line 1173 + *ip = NC_FILL_BYTE; +#line 1173 + return NC_ERANGE; +#line 1173 +#else +#line 1173 + err = NC_ERANGE; +#line 1173 +#endif +#line 1173 + } +#line 1173 +#endif +#line 1173 + +#line 1173 + +#line 1173 + *ip = (schar) xx; +#line 1173 + return err; +#line 1173 +} +#line 1173 + +static int +#line 1174 +ncx_get_uint_short(const void *xp, short *ip) +#line 1174 +{ +#line 1174 + int err=NC_NOERR; +#line 1174 + ix_uint xx = 0; +#line 1174 + get_ix_uint(xp, &xx); +#line 1174 + +#line 1174 +#if IX_UINT_MAX > SHORT_MAX +#line 1174 + if (xx > SHORT_MAX) { +#line 1174 +#ifdef ERANGE_FILL +#line 1174 + *ip = NC_FILL_SHORT; +#line 1174 + return NC_ERANGE; +#line 1174 +#else +#line 1174 + err = NC_ERANGE; +#line 1174 +#endif +#line 1174 + } +#line 1174 +#endif +#line 1174 + +#line 1174 + +#line 1174 + *ip = (short) xx; +#line 1174 + return err; +#line 1174 +} +#line 1174 + +static int +#line 1175 +ncx_get_uint_int(const void *xp, int *ip) +#line 1175 +{ +#line 1175 + int err=NC_NOERR; +#line 1175 + ix_uint xx = 0; +#line 1175 + get_ix_uint(xp, &xx); +#line 1175 + +#line 1175 +#if IX_UINT_MAX > INT_MAX +#line 1175 + if (xx > INT_MAX) { +#line 1175 +#ifdef ERANGE_FILL +#line 1175 + *ip = NC_FILL_INT; +#line 1175 + return NC_ERANGE; +#line 1175 +#else +#line 1175 + err = NC_ERANGE; +#line 1175 +#endif +#line 1175 + } +#line 1175 +#endif +#line 1175 + +#line 1175 + +#line 1175 + *ip = (int) xx; +#line 1175 + return err; +#line 1175 +} +#line 1175 + +static int +#line 1176 +ncx_get_uint_long(const void *xp, long *ip) +#line 1176 +{ +#line 1176 + int err=NC_NOERR; +#line 1176 + ix_uint xx = 0; +#line 1176 + get_ix_uint(xp, &xx); +#line 1176 + +#line 1176 +#if IX_UINT_MAX > LONG_MAX +#line 1176 + if (xx > LONG_MAX) { +#line 1176 +#ifdef ERANGE_FILL +#line 1176 + *ip = NC_FILL_INT; +#line 1176 + return NC_ERANGE; +#line 1176 +#else +#line 1176 + err = NC_ERANGE; +#line 1176 +#endif +#line 1176 + } +#line 1176 +#endif +#line 1176 + +#line 1176 + +#line 1176 + *ip = (long) xx; +#line 1176 + return err; +#line 1176 +} +#line 1176 + +static int +#line 1177 +ncx_get_uint_longlong(const void *xp, longlong *ip) +#line 1177 +{ +#line 1177 + int err=NC_NOERR; +#line 1177 + ix_uint xx = 0; +#line 1177 + get_ix_uint(xp, &xx); +#line 1177 + +#line 1177 +#if IX_UINT_MAX > LONGLONG_MAX +#line 1177 + if (xx > LONGLONG_MAX) { +#line 1177 +#ifdef ERANGE_FILL +#line 1177 + *ip = NC_FILL_INT64; +#line 1177 + return NC_ERANGE; +#line 1177 +#else +#line 1177 + err = NC_ERANGE; +#line 1177 +#endif +#line 1177 + } +#line 1177 +#endif +#line 1177 + +#line 1177 + +#line 1177 + *ip = (longlong) xx; +#line 1177 + return err; +#line 1177 +} +#line 1177 + +static int +#line 1178 +ncx_get_uint_ushort(const void *xp, ushort *ip) +#line 1178 +{ +#line 1178 + int err=NC_NOERR; +#line 1178 +#if SIZEOF_IX_UINT == SIZEOF_USHORT && IX_UINT_MAX == USHORT_MAX +#line 1178 + get_ix_uint(xp, (ix_uint *)ip); +#line 1178 +#else +#line 1178 + ix_uint xx = 0; +#line 1178 + get_ix_uint(xp, &xx); +#line 1178 + +#line 1178 +#if IX_UINT_MAX > USHORT_MAX +#line 1178 + if (xx > USHORT_MAX) { +#line 1178 +#ifdef ERANGE_FILL +#line 1178 + *ip = NC_FILL_USHORT; +#line 1178 + return NC_ERANGE; +#line 1178 +#else +#line 1178 + err = NC_ERANGE; +#line 1178 +#endif +#line 1178 + } +#line 1178 +#endif +#line 1178 + +#line 1178 + +#line 1178 + *ip = (ushort) xx; +#line 1178 +#endif +#line 1178 + return err; +#line 1178 +} +#line 1178 + +static int +#line 1179 +ncx_get_uint_uchar(const void *xp, uchar *ip) +#line 1179 +{ +#line 1179 + int err=NC_NOERR; +#line 1179 +#if SIZEOF_IX_UINT == SIZEOF_UCHAR && IX_UINT_MAX == UCHAR_MAX +#line 1179 + get_ix_uint(xp, (ix_uint *)ip); +#line 1179 +#else +#line 1179 + ix_uint xx = 0; +#line 1179 + get_ix_uint(xp, &xx); +#line 1179 + +#line 1179 +#if IX_UINT_MAX > UCHAR_MAX +#line 1179 + if (xx > UCHAR_MAX) { +#line 1179 +#ifdef ERANGE_FILL +#line 1179 + *ip = NC_FILL_UBYTE; +#line 1179 + return NC_ERANGE; +#line 1179 +#else +#line 1179 + err = NC_ERANGE; +#line 1179 +#endif +#line 1179 + } +#line 1179 +#endif +#line 1179 + +#line 1179 + +#line 1179 + *ip = (uchar) xx; +#line 1179 +#endif +#line 1179 + return err; +#line 1179 +} +#line 1179 + +static int +#line 1180 +ncx_get_uint_ulonglong(const void *xp, ulonglong *ip) +#line 1180 +{ +#line 1180 + int err=NC_NOERR; +#line 1180 +#if SIZEOF_IX_UINT == SIZEOF_ULONGLONG && IX_UINT_MAX == ULONGLONG_MAX +#line 1180 + get_ix_uint(xp, (ix_uint *)ip); +#line 1180 +#else +#line 1180 + ix_uint xx = 0; +#line 1180 + get_ix_uint(xp, &xx); +#line 1180 + +#line 1180 +#if IX_UINT_MAX > ULONGLONG_MAX +#line 1180 + if (xx > ULONGLONG_MAX) { +#line 1180 +#ifdef ERANGE_FILL +#line 1180 + *ip = NC_FILL_UINT64; +#line 1180 + return NC_ERANGE; +#line 1180 +#else +#line 1180 + err = NC_ERANGE; +#line 1180 +#endif +#line 1180 + } +#line 1180 +#endif +#line 1180 + +#line 1180 + +#line 1180 + *ip = (ulonglong) xx; +#line 1180 +#endif +#line 1180 + return err; +#line 1180 +} +#line 1180 + +static int +#line 1181 +ncx_get_uint_float(const void *xp, float *ip) +#line 1181 +{ +#line 1181 + ix_uint xx = 0; +#line 1181 + get_ix_uint(xp, &xx); +#line 1181 + *ip = (float)xx; +#line 1181 + return NC_NOERR; +#line 1181 +} +#line 1181 + +static int +#line 1182 +ncx_get_uint_double(const void *xp, double *ip) +#line 1182 +{ +#line 1182 + ix_uint xx = 0; +#line 1182 + get_ix_uint(xp, &xx); +#line 1182 + *ip = (double)xx; +#line 1182 + return NC_NOERR; +#line 1182 +} +#line 1182 + + +static int +ncx_put_uint_schar(void *xp, const schar *ip, void *fillp) +{ + uchar *cp; + if (*ip < 0) { +#ifdef ERANGE_FILL + if (fillp != NULL) memcpy(xp, fillp, 4); +#ifndef WORDS_BIGENDIAN + swapn4b(xp, xp, 1); +#endif +#endif + return NC_ERANGE; + } + + cp = (uchar *) xp; + *cp++ = 0x00; + *cp++ = 0x00; + *cp++ = 0x00; + *cp = (uchar)*ip; + + return NC_NOERR; +} + +static int +ncx_put_uint_uchar(void *xp, const uchar *ip, void *fillp) +{ + uchar *cp = (uchar *) xp; + *cp++ = 0x00; + *cp++ = 0x00; + *cp++ = 0x00; + *cp = *ip; + return NC_NOERR; +} + +#if X_SIZEOF_UINT != SIZEOF_UINT +static int +#line 1219 +ncx_put_uint_uint(void *xp, const uint *ip, void *fillp) +#line 1219 +{ +#line 1219 + int err=NC_NOERR; +#line 1219 +#if SIZEOF_IX_UINT == SIZEOF_UINT && IX_UINT_MAX == UINT_MAX +#line 1219 + put_ix_uint(xp, (const ix_uint *)ip); +#line 1219 +#else +#line 1219 + ix_uint xx = NC_FILL_UINT; +#line 1219 + +#line 1219 +#if IX_UINT_MAX < UINT_MAX +#line 1219 + if (*ip > IX_UINT_MAX) { +#line 1219 + +#line 1219 +#ifdef ERANGE_FILL +#line 1219 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1219 +#endif +#line 1219 + err = NC_ERANGE; +#line 1219 + } +#line 1219 +#ifdef ERANGE_FILL +#line 1219 + else +#line 1219 +#endif +#line 1219 +#endif +#line 1219 + xx = (ix_uint)*ip; +#line 1219 + +#line 1219 + put_ix_uint(xp, &xx); +#line 1219 +#endif +#line 1219 + return err; +#line 1219 +} +#line 1219 + +#endif + +static int +#line 1222 +ncx_put_uint_short(void *xp, const short *ip, void *fillp) +#line 1222 +{ +#line 1222 + int err=NC_NOERR; +#line 1222 + ix_uint xx = NC_FILL_UINT; +#line 1222 + +#line 1222 +#if IX_UINT_MAX < SHORT_MAX +#line 1222 + if (*ip > IX_UINT_MAX) { +#line 1222 + +#line 1222 +#ifdef ERANGE_FILL +#line 1222 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1222 +#endif +#line 1222 + err = NC_ERANGE; +#line 1222 + } +#line 1222 +#ifdef ERANGE_FILL +#line 1222 + else +#line 1222 +#endif +#line 1222 +#endif +#line 1222 + if (*ip < 0) { +#line 1222 + +#line 1222 +#ifdef ERANGE_FILL +#line 1222 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1222 +#endif +#line 1222 + err = NC_ERANGE; /* because xp is unsigned */ +#line 1222 + } +#line 1222 +#ifdef ERANGE_FILL +#line 1222 + else +#line 1222 +#endif +#line 1222 + xx = (ix_uint)*ip; +#line 1222 + +#line 1222 + put_ix_uint(xp, &xx); +#line 1222 + return err; +#line 1222 +} +#line 1222 + +static int +#line 1223 +ncx_put_uint_int(void *xp, const int *ip, void *fillp) +#line 1223 +{ +#line 1223 + int err=NC_NOERR; +#line 1223 + ix_uint xx = NC_FILL_UINT; +#line 1223 + +#line 1223 +#if IX_UINT_MAX < INT_MAX +#line 1223 + if (*ip > IX_UINT_MAX) { +#line 1223 + +#line 1223 +#ifdef ERANGE_FILL +#line 1223 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1223 +#endif +#line 1223 + err = NC_ERANGE; +#line 1223 + } +#line 1223 +#ifdef ERANGE_FILL +#line 1223 + else +#line 1223 +#endif +#line 1223 +#endif +#line 1223 + if (*ip < 0) { +#line 1223 + +#line 1223 +#ifdef ERANGE_FILL +#line 1223 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1223 +#endif +#line 1223 + err = NC_ERANGE; /* because xp is unsigned */ +#line 1223 + } +#line 1223 +#ifdef ERANGE_FILL +#line 1223 + else +#line 1223 +#endif +#line 1223 + xx = (ix_uint)*ip; +#line 1223 + +#line 1223 + put_ix_uint(xp, &xx); +#line 1223 + return err; +#line 1223 +} +#line 1223 + +static int +#line 1224 +ncx_put_uint_long(void *xp, const long *ip, void *fillp) +#line 1224 +{ +#line 1224 + int err=NC_NOERR; +#line 1224 + ix_uint xx = NC_FILL_UINT; +#line 1224 + +#line 1224 +#if IX_UINT_MAX < LONG_MAX +#line 1224 + if (*ip > IX_UINT_MAX) { +#line 1224 + +#line 1224 +#ifdef ERANGE_FILL +#line 1224 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1224 +#endif +#line 1224 + err = NC_ERANGE; +#line 1224 + } +#line 1224 +#ifdef ERANGE_FILL +#line 1224 + else +#line 1224 +#endif +#line 1224 +#endif +#line 1224 + if (*ip < 0) { +#line 1224 + +#line 1224 +#ifdef ERANGE_FILL +#line 1224 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1224 +#endif +#line 1224 + err = NC_ERANGE; /* because xp is unsigned */ +#line 1224 + } +#line 1224 +#ifdef ERANGE_FILL +#line 1224 + else +#line 1224 +#endif +#line 1224 + xx = (ix_uint)*ip; +#line 1224 + +#line 1224 + put_ix_uint(xp, &xx); +#line 1224 + return err; +#line 1224 +} +#line 1224 + +static int +#line 1225 +ncx_put_uint_longlong(void *xp, const longlong *ip, void *fillp) +#line 1225 +{ +#line 1225 + int err=NC_NOERR; +#line 1225 + ix_uint xx = NC_FILL_UINT; +#line 1225 + +#line 1225 +#if IX_UINT_MAX < LONGLONG_MAX +#line 1225 + if (*ip > IX_UINT_MAX) { +#line 1225 + +#line 1225 +#ifdef ERANGE_FILL +#line 1225 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1225 +#endif +#line 1225 + err = NC_ERANGE; +#line 1225 + } +#line 1225 +#ifdef ERANGE_FILL +#line 1225 + else +#line 1225 +#endif +#line 1225 +#endif +#line 1225 + if (*ip < 0) { +#line 1225 + +#line 1225 +#ifdef ERANGE_FILL +#line 1225 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1225 +#endif +#line 1225 + err = NC_ERANGE; /* because xp is unsigned */ +#line 1225 + } +#line 1225 +#ifdef ERANGE_FILL +#line 1225 + else +#line 1225 +#endif +#line 1225 + xx = (ix_uint)*ip; +#line 1225 + +#line 1225 + put_ix_uint(xp, &xx); +#line 1225 + return err; +#line 1225 +} +#line 1225 + +static int +#line 1226 +ncx_put_uint_ushort(void *xp, const ushort *ip, void *fillp) +#line 1226 +{ +#line 1226 + int err=NC_NOERR; +#line 1226 +#if SIZEOF_IX_UINT == SIZEOF_USHORT && IX_UINT_MAX == USHORT_MAX +#line 1226 + put_ix_uint(xp, (const ix_uint *)ip); +#line 1226 +#else +#line 1226 + ix_uint xx = NC_FILL_UINT; +#line 1226 + +#line 1226 +#if IX_UINT_MAX < USHORT_MAX +#line 1226 + if (*ip > IX_UINT_MAX) { +#line 1226 + +#line 1226 +#ifdef ERANGE_FILL +#line 1226 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1226 +#endif +#line 1226 + err = NC_ERANGE; +#line 1226 + } +#line 1226 +#ifdef ERANGE_FILL +#line 1226 + else +#line 1226 +#endif +#line 1226 +#endif +#line 1226 + xx = (ix_uint)*ip; +#line 1226 + +#line 1226 + put_ix_uint(xp, &xx); +#line 1226 +#endif +#line 1226 + return err; +#line 1226 +} +#line 1226 + +static int +#line 1227 +ncx_put_uint_ulonglong(void *xp, const ulonglong *ip, void *fillp) +#line 1227 +{ +#line 1227 + int err=NC_NOERR; +#line 1227 +#if SIZEOF_IX_UINT == SIZEOF_ULONGLONG && IX_UINT_MAX == ULONGLONG_MAX +#line 1227 + put_ix_uint(xp, (const ix_uint *)ip); +#line 1227 +#else +#line 1227 + ix_uint xx = NC_FILL_UINT; +#line 1227 + +#line 1227 +#if IX_UINT_MAX < ULONGLONG_MAX +#line 1227 + if (*ip > IX_UINT_MAX) { +#line 1227 + +#line 1227 +#ifdef ERANGE_FILL +#line 1227 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1227 +#endif +#line 1227 + err = NC_ERANGE; +#line 1227 + } +#line 1227 +#ifdef ERANGE_FILL +#line 1227 + else +#line 1227 +#endif +#line 1227 +#endif +#line 1227 + xx = (ix_uint)*ip; +#line 1227 + +#line 1227 + put_ix_uint(xp, &xx); +#line 1227 +#endif +#line 1227 + return err; +#line 1227 +} +#line 1227 + +static int +#line 1228 +ncx_put_uint_float(void *xp, const float *ip, void *fillp) +#line 1228 +{ +#line 1228 + int err=NC_NOERR; +#line 1228 + ix_uint xx = NC_FILL_UINT; +#line 1228 + +#line 1228 + if (*ip > (double)X_UINT_MAX || *ip < 0) { +#line 1228 + +#line 1228 +#ifdef ERANGE_FILL +#line 1228 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1228 +#endif +#line 1228 + err = NC_ERANGE; +#line 1228 + } +#line 1228 +#ifdef ERANGE_FILL +#line 1228 + else +#line 1228 +#endif +#line 1228 + xx = (ix_uint)*ip; +#line 1228 + +#line 1228 + put_ix_uint(xp, &xx); +#line 1228 + return err; +#line 1228 +} +#line 1228 + +static int +#line 1229 +ncx_put_uint_double(void *xp, const double *ip, void *fillp) +#line 1229 +{ +#line 1229 + int err=NC_NOERR; +#line 1229 + ix_uint xx = NC_FILL_UINT; +#line 1229 + +#line 1229 + if (*ip > X_UINT_MAX || *ip < 0) { +#line 1229 + +#line 1229 +#ifdef ERANGE_FILL +#line 1229 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1229 +#endif +#line 1229 + err = NC_ERANGE; +#line 1229 + } +#line 1229 +#ifdef ERANGE_FILL +#line 1229 + else +#line 1229 +#endif +#line 1229 + xx = (ix_uint)*ip; +#line 1229 + +#line 1229 + put_ix_uint(xp, &xx); +#line 1229 + return err; +#line 1229 +} +#line 1229 + + + +/* external NC_FLOAT --------------------------------------------------------*/ + +#if X_SIZEOF_FLOAT == SIZEOF_FLOAT && !defined(NO_IEEE_FLOAT) + +inline static void +get_ix_float(const void *xp, float *ip) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(ip, xp, SIZEOF_FLOAT); +#else + swap4b(ip, xp); +#endif +} + +inline static void +put_ix_float(void *xp, const float *ip) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(xp, ip, X_SIZEOF_FLOAT); +#else + swap4b(xp, ip); +#endif +} + +#elif defined(vax) && vax != 0 + +/* What IEEE single precision floating point looks like on a Vax */ +struct ieee_single { + unsigned int exp_hi : 7; + unsigned int sign : 1; + unsigned int mant_hi : 7; + unsigned int exp_lo : 1; + unsigned int mant_lo_hi : 8; + unsigned int mant_lo_lo : 8; +}; + +/* Vax single precision floating point */ +struct vax_single { + unsigned int mantissa1 : 7; + unsigned int exp : 8; + unsigned int sign : 1; + unsigned int mantissa2 : 16; +}; + +#define VAX_SNG_BIAS 0x81 +#define IEEE_SNG_BIAS 0x7f + +static struct sgl_limits { + struct vax_single s; + struct ieee_single ieee; +} max = { + { 0x7f, 0xff, 0x0, 0xffff }, /* Max Vax */ + { 0x7f, 0x0, 0x0, 0x1, 0x0, 0x0 } /* Max IEEE */ +}; +static struct sgl_limits min = { + { 0x0, 0x0, 0x0, 0x0 }, /* Min Vax */ + { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } /* Min IEEE */ +}; + +#line 1343 +static void +get_ix_float(const void *xp, float *ip) +{ + struct vax_single *const vsp = (struct vax_single *) ip; +#line 1346 + const struct ieee_single *const isp = +#line 1346 + (const struct ieee_single *) xp; +#line 1346 + unsigned exp = isp->exp_hi << 1 | isp->exp_lo; +#line 1346 + +#line 1346 + switch(exp) { +#line 1346 + case 0 : +#line 1346 + /* ieee subnormal */ +#line 1346 + if (isp->mant_hi == min.ieee.mant_hi +#line 1346 + && isp->mant_lo_hi == min.ieee.mant_lo_hi +#line 1346 + && isp->mant_lo_lo == min.ieee.mant_lo_lo) +#line 1346 + { +#line 1346 + *vsp = min.s; +#line 1346 + } +#line 1346 + else +#line 1346 + { +#line 1346 + unsigned mantissa = (isp->mant_hi << 16) +#line 1346 + | isp->mant_lo_hi << 8 +#line 1346 + | isp->mant_lo_lo; +#line 1346 + unsigned tmp = mantissa >> 20; +#line 1346 + if (tmp >= 4) { +#line 1346 + vsp->exp = 2; +#line 1346 + } else if (tmp >= 2) { +#line 1346 + vsp->exp = 1; +#line 1346 + } else { +#line 1346 + *vsp = min.s; +#line 1346 + break; +#line 1346 + } /* else */ +#line 1346 + tmp = mantissa - (1 << (20 + vsp->exp )); +#line 1346 + tmp <<= 3 - vsp->exp; +#line 1346 + vsp->mantissa2 = tmp; +#line 1346 + vsp->mantissa1 = (tmp >> 16); +#line 1346 + } +#line 1346 + break; +#line 1346 + case 0xfe : +#line 1346 + case 0xff : +#line 1346 + *vsp = max.s; +#line 1346 + break; +#line 1346 + default : +#line 1346 + vsp->exp = exp - IEEE_SNG_BIAS + VAX_SNG_BIAS; +#line 1346 + vsp->mantissa2 = isp->mant_lo_hi << 8 | isp->mant_lo_lo; +#line 1346 + vsp->mantissa1 = isp->mant_hi; +#line 1346 + } +#line 1346 + +#line 1346 + vsp->sign = isp->sign; +#line 1346 + +} + +#line 1400 + +static void +put_ix_float(void *xp, const float *ip) +{ + const struct vax_single *const vsp = +#line 1404 + (const struct vax_single *)ip; +#line 1404 + struct ieee_single *const isp = (struct ieee_single *) xp; +#line 1404 + +#line 1404 + switch(vsp->exp){ +#line 1404 + case 0 : +#line 1404 + /* all vax float with zero exponent map to zero */ +#line 1404 + *isp = min.ieee; +#line 1404 + break; +#line 1404 + case 2 : +#line 1404 + case 1 : +#line 1404 + { +#line 1404 + /* These will map to subnormals */ +#line 1404 + unsigned mantissa = (vsp->mantissa1 << 16) +#line 1404 + | vsp->mantissa2; +#line 1404 + mantissa >>= 3 - vsp->exp; +#line 1404 + mantissa += (1 << (20 + vsp->exp)); +#line 1404 + isp->mant_lo_lo = mantissa; +#line 1404 + isp->mant_lo_hi = mantissa >> 8; +#line 1404 + isp->mant_hi = mantissa >> 16; +#line 1404 + isp->exp_lo = 0; +#line 1404 + isp->exp_hi = 0; +#line 1404 + } +#line 1404 + break; +#line 1404 + case 0xff : /* max.s.exp */ +#line 1404 + if (vsp->mantissa2 == max.s.mantissa2 && +#line 1404 + vsp->mantissa1 == max.s.mantissa1) +#line 1404 + { +#line 1404 + /* map largest vax float to ieee infinity */ +#line 1404 + *isp = max.ieee; +#line 1404 + break; +#line 1404 + } /* else, fall thru */ +#line 1404 + default : +#line 1404 + { +#line 1404 + unsigned exp = vsp->exp - VAX_SNG_BIAS + IEEE_SNG_BIAS; +#line 1404 + isp->exp_hi = exp >> 1; +#line 1404 + isp->exp_lo = exp; +#line 1404 + isp->mant_lo_lo = vsp->mantissa2; +#line 1404 + isp->mant_lo_hi = vsp->mantissa2 >> 8; +#line 1404 + isp->mant_hi = vsp->mantissa1; +#line 1404 + } +#line 1404 + } +#line 1404 + +#line 1404 + isp->sign = vsp->sign; +#line 1404 + +} + + /* vax */ +#elif defined(_CRAY) && !defined(__crayx1) + +/* + * Return the number of bytes until the next "word" boundary + * N.B. This is based on the very weird YMP address structure, + * which puts the address within a word in the leftmost 3 bits + * of the address. + */ +static size_t +word_align(const void *vp) +{ + const size_t rem = ((size_t)vp >> (64 - 3)) & 0x7; + return (rem != 0); +} + +struct ieee_single_hi { + unsigned int sign : 1; + unsigned int exp : 8; + unsigned int mant :23; + unsigned int pad :32; +}; +typedef struct ieee_single_hi ieee_single_hi; + +struct ieee_single_lo { + unsigned int pad :32; + unsigned int sign : 1; + unsigned int exp : 8; + unsigned int mant :23; +}; +typedef struct ieee_single_lo ieee_single_lo; + +static const int ieee_single_bias = 0x7f; + +struct ieee_double { + unsigned int sign : 1; + unsigned int exp :11; + unsigned int mant :52; +}; +typedef struct ieee_double ieee_double; + +static const int ieee_double_bias = 0x3ff; + +#if defined(NO_IEEE_FLOAT) + +struct cray_single { + unsigned int sign : 1; + unsigned int exp :15; + unsigned int mant :48; +}; +typedef struct cray_single cray_single; + +static const int cs_ieis_bias = 0x4000 - 0x7f; + +static const int cs_id_bias = 0x4000 - 0x3ff; + +#line 1539 + +static void +get_ix_float(const void *xp, float *ip) +{ + + if (word_align(xp) == 0) + { + const ieee_single_hi *isp = (const ieee_single_hi *) xp; + cray_single *csp = (cray_single *) ip; +#line 1547 + +#line 1547 + if (isp->exp == 0) +#line 1547 + { +#line 1547 + /* ieee subnormal */ +#line 1547 + *ip = (double)isp->mant; +#line 1547 + if (isp->mant != 0) +#line 1547 + { +#line 1547 + csp->exp -= (ieee_single_bias + 22); +#line 1547 + } +#line 1547 + } +#line 1547 + else +#line 1547 + { +#line 1547 + csp->exp = isp->exp + cs_ieis_bias + 1; +#line 1547 + csp->mant = isp->mant << (48 - 1 - 23); +#line 1547 + csp->mant |= (1 << (48 - 1)); +#line 1547 + } +#line 1547 + csp->sign = isp->sign; +#line 1547 + +#line 1547 + + } + else + { + const ieee_single_lo *isp = (const ieee_single_lo *) xp; + cray_single *csp = (cray_single *) ip; +#line 1552 + +#line 1552 + if (isp->exp == 0) +#line 1552 + { +#line 1552 + /* ieee subnormal */ +#line 1552 + *ip = (double)isp->mant; +#line 1552 + if (isp->mant != 0) +#line 1552 + { +#line 1552 + csp->exp -= (ieee_single_bias + 22); +#line 1552 + } +#line 1552 + } +#line 1552 + else +#line 1552 + { +#line 1552 + csp->exp = isp->exp + cs_ieis_bias + 1; +#line 1552 + csp->mant = isp->mant << (48 - 1 - 23); +#line 1552 + csp->mant |= (1 << (48 - 1)); +#line 1552 + } +#line 1552 + csp->sign = isp->sign; +#line 1552 + +#line 1552 + + } +} + +static void +put_ix_float(void *xp, const float *ip) +{ + if (word_align(xp) == 0) + { + ieee_single_hi *isp = (ieee_single_hi*)xp; + const cray_single *csp = (const cray_single *) ip; +#line 1562 + int ieee_exp = csp->exp - cs_ieis_bias -1; +#line 1562 + +#line 1562 + isp->sign = csp->sign; +#line 1562 + +#line 1562 + if (ieee_exp >= 0xff) +#line 1562 + { +#line 1562 + /* NC_ERANGE => ieee Inf */ +#line 1562 + isp->exp = 0xff; +#line 1562 + isp->mant = 0x0; +#line 1562 + } +#line 1562 + else if (ieee_exp > 0) +#line 1562 + { +#line 1562 + /* normal ieee representation */ +#line 1562 + isp->exp = ieee_exp; +#line 1562 + /* assumes cray rep is in normal form */ +#line 1562 + assert(csp->mant & 0x800000000000); +#line 1562 + isp->mant = (((csp->mant << 1) & +#line 1562 + 0xffffffffffff) >> (48 - 23)); +#line 1562 + } +#line 1562 + else if (ieee_exp > -23) +#line 1562 + { +#line 1562 + /* ieee subnormal, right shift */ +#line 1562 + const int rshift = (48 - 23 - ieee_exp); +#line 1562 + +#line 1562 + isp->mant = csp->mant >> rshift; +#line 1562 + +#line 1562 +#if 0 +#line 1562 + if (csp->mant & (1 << (rshift -1))) +#line 1562 + { +#line 1562 + /* round up */ +#line 1562 + isp->mant++; +#line 1562 + } +#line 1562 +#endif +#line 1562 + +#line 1562 + isp->exp = 0; +#line 1562 + } +#line 1562 + else +#line 1562 + { +#line 1562 + /* smaller than ieee can represent */ +#line 1562 + isp->exp = 0; +#line 1562 + isp->mant = 0; +#line 1562 + } +#line 1562 + + } + else + { + ieee_single_lo *isp = (ieee_single_lo*)xp; + const cray_single *csp = (const cray_single *) ip; +#line 1567 + int ieee_exp = csp->exp - cs_ieis_bias -1; +#line 1567 + +#line 1567 + isp->sign = csp->sign; +#line 1567 + +#line 1567 + if (ieee_exp >= 0xff) +#line 1567 + { +#line 1567 + /* NC_ERANGE => ieee Inf */ +#line 1567 + isp->exp = 0xff; +#line 1567 + isp->mant = 0x0; +#line 1567 + } +#line 1567 + else if (ieee_exp > 0) +#line 1567 + { +#line 1567 + /* normal ieee representation */ +#line 1567 + isp->exp = ieee_exp; +#line 1567 + /* assumes cray rep is in normal form */ +#line 1567 + assert(csp->mant & 0x800000000000); +#line 1567 + isp->mant = (((csp->mant << 1) & +#line 1567 + 0xffffffffffff) >> (48 - 23)); +#line 1567 + } +#line 1567 + else if (ieee_exp > -23) +#line 1567 + { +#line 1567 + /* ieee subnormal, right shift */ +#line 1567 + const int rshift = (48 - 23 - ieee_exp); +#line 1567 + +#line 1567 + isp->mant = csp->mant >> rshift; +#line 1567 + +#line 1567 +#if 0 +#line 1567 + if (csp->mant & (1 << (rshift -1))) +#line 1567 + { +#line 1567 + /* round up */ +#line 1567 + isp->mant++; +#line 1567 + } +#line 1567 +#endif +#line 1567 + +#line 1567 + isp->exp = 0; +#line 1567 + } +#line 1567 + else +#line 1567 + { +#line 1567 + /* smaller than ieee can represent */ +#line 1567 + isp->exp = 0; +#line 1567 + isp->mant = 0; +#line 1567 + } +#line 1567 + + } +} + +#else + /* IEEE Cray with only doubles */ +static void +get_ix_float(const void *xp, float *ip) +{ + + ieee_double *idp = (ieee_double *) ip; + + if (word_align(xp) == 0) + { + const ieee_single_hi *isp = (const ieee_single_hi *) xp; + if (isp->exp == 0 && isp->mant == 0) + { + idp->exp = 0; + idp->mant = 0; + } + else + { + idp->exp = isp->exp + (ieee_double_bias - ieee_single_bias); + idp->mant = isp->mant << (52 - 23); + } + idp->sign = isp->sign; + } + else + { + const ieee_single_lo *isp = (const ieee_single_lo *) xp; + if (isp->exp == 0 && isp->mant == 0) + { + idp->exp = 0; + idp->mant = 0; + } + else + { + idp->exp = isp->exp + (ieee_double_bias - ieee_single_bias); + idp->mant = isp->mant << (52 - 23); + } + idp->sign = isp->sign; + } +} + +static void +put_ix_float(void *xp, const float *ip) +{ + const ieee_double *idp = (const ieee_double *) ip; + if (word_align(xp) == 0) + { + ieee_single_hi *isp = (ieee_single_hi*)xp; + if (idp->exp > (ieee_double_bias - ieee_single_bias)) + isp->exp = idp->exp - (ieee_double_bias - ieee_single_bias); + else + isp->exp = 0; + isp->mant = idp->mant >> (52 - 23); + isp->sign = idp->sign; + } + else + { + ieee_single_lo *isp = (ieee_single_lo*)xp; + if (idp->exp > (ieee_double_bias - ieee_single_bias)) + isp->exp = idp->exp - (ieee_double_bias - ieee_single_bias); + else + isp->exp = 0; + isp->mant = idp->mant >> (52 - 23); + isp->sign = idp->sign; + } +} +#endif + +#else +#error "ix_float implementation" +#endif + +#if X_SIZEOF_FLOAT != SIZEOF_FLOAT || defined(NO_IEEE_FLOAT) +static int +ncx_get_float_float(const void *xp, float *ip, void *fillp) +{ + /* TODO */ + get_ix_float(xp, ip); + return NC_NOERR; +} +#endif + +#define ix_float float + +static int +#line 1654 +ncx_get_float_schar(const void *xp, schar *ip) +#line 1654 +{ +#line 1654 + ix_float xx = 0; +#line 1654 + get_ix_float(xp, &xx); +#line 1654 + if (xx > (double)SCHAR_MAX || xx < (double)SCHAR_MIN) { +#line 1654 +#ifdef ERANGE_FILL +#line 1654 + *ip = NC_FILL_BYTE; +#line 1654 +#endif +#line 1654 + return NC_ERANGE; +#line 1654 + } +#line 1654 + *ip = (schar)xx; +#line 1654 + return NC_NOERR; +#line 1654 +} +#line 1654 + +static int +#line 1655 +ncx_get_float_short(const void *xp, short *ip) +#line 1655 +{ +#line 1655 + ix_float xx = 0; +#line 1655 + get_ix_float(xp, &xx); +#line 1655 + if (xx > (double)SHORT_MAX || xx < (double)SHORT_MIN) { +#line 1655 +#ifdef ERANGE_FILL +#line 1655 + *ip = NC_FILL_SHORT; +#line 1655 +#endif +#line 1655 + return NC_ERANGE; +#line 1655 + } +#line 1655 + *ip = (short)xx; +#line 1655 + return NC_NOERR; +#line 1655 +} +#line 1655 + +static int +#line 1656 +ncx_get_float_int(const void *xp, int *ip) +#line 1656 +{ +#line 1656 + ix_float xx = 0; +#line 1656 + get_ix_float(xp, &xx); +#line 1656 + if (xx > (double)INT_MAX || xx < (double)INT_MIN) { +#line 1656 +#ifdef ERANGE_FILL +#line 1656 + *ip = NC_FILL_INT; +#line 1656 +#endif +#line 1656 + return NC_ERANGE; +#line 1656 + } +#line 1656 + *ip = (int)xx; +#line 1656 + return NC_NOERR; +#line 1656 +} +#line 1656 + +static int +#line 1657 +ncx_get_float_long(const void *xp, long *ip) +#line 1657 +{ +#line 1657 + ix_float xx = 0; +#line 1657 + get_ix_float(xp, &xx); +#line 1657 + if (xx > (double)LONG_MAX || xx < (double)LONG_MIN) { +#line 1657 +#ifdef ERANGE_FILL +#line 1657 + *ip = NC_FILL_INT; +#line 1657 +#endif +#line 1657 + return NC_ERANGE; +#line 1657 + } +#line 1657 + *ip = (long)xx; +#line 1657 + return NC_NOERR; +#line 1657 +} +#line 1657 + +static int +#line 1658 +ncx_get_float_double(const void *xp, double *ip) +#line 1658 +{ +#line 1658 + ix_float xx = 0; +#line 1658 + get_ix_float(xp, &xx); +#line 1658 + *ip = (double)xx; +#line 1658 + return NC_NOERR; +#line 1658 +} +#line 1658 + +static int +#line 1659 +ncx_get_float_longlong(const void *xp, longlong *ip) +#line 1659 +{ +#line 1659 + ix_float xx = 0; +#line 1659 + get_ix_float(xp, &xx); +#line 1659 + if (xx == LONGLONG_MAX) *ip = LONGLONG_MAX; +#line 1659 + else if (xx == LONGLONG_MIN) *ip = LONGLONG_MIN; +#line 1659 + else if (xx > (double)LONGLONG_MAX || xx < (double)LONGLONG_MIN) { +#line 1659 +#ifdef ERANGE_FILL +#line 1659 + *ip = NC_FILL_INT64; +#line 1659 +#endif +#line 1659 + return NC_ERANGE; +#line 1659 + } +#line 1659 + else *ip = (longlong)xx; +#line 1659 + return NC_NOERR; +#line 1659 +} +#line 1659 + +static int +#line 1660 +ncx_get_float_uchar(const void *xp, uchar *ip) +#line 1660 +{ +#line 1660 + ix_float xx = 0; +#line 1660 + get_ix_float(xp, &xx); +#line 1660 + if (xx > (double)UCHAR_MAX || xx < 0) { +#line 1660 +#ifdef ERANGE_FILL +#line 1660 + *ip = NC_FILL_UBYTE; +#line 1660 +#endif +#line 1660 + return NC_ERANGE; +#line 1660 + } +#line 1660 + *ip = (uchar)xx; +#line 1660 + return NC_NOERR; +#line 1660 +} +#line 1660 + +static int +#line 1661 +ncx_get_float_ushort(const void *xp, ushort *ip) +#line 1661 +{ +#line 1661 + ix_float xx = 0; +#line 1661 + get_ix_float(xp, &xx); +#line 1661 + if (xx > (double)USHORT_MAX || xx < 0) { +#line 1661 +#ifdef ERANGE_FILL +#line 1661 + *ip = NC_FILL_USHORT; +#line 1661 +#endif +#line 1661 + return NC_ERANGE; +#line 1661 + } +#line 1661 + *ip = (ushort)xx; +#line 1661 + return NC_NOERR; +#line 1661 +} +#line 1661 + +static int +#line 1662 +ncx_get_float_uint(const void *xp, uint *ip) +#line 1662 +{ +#line 1662 + ix_float xx = 0; +#line 1662 + get_ix_float(xp, &xx); +#line 1662 + if (xx > (double)UINT_MAX || xx < 0) { +#line 1662 +#ifdef ERANGE_FILL +#line 1662 + *ip = NC_FILL_UINT; +#line 1662 +#endif +#line 1662 + return NC_ERANGE; +#line 1662 + } +#line 1662 + *ip = (uint)xx; +#line 1662 + return NC_NOERR; +#line 1662 +} +#line 1662 + +static int +#line 1663 +ncx_get_float_ulonglong(const void *xp, ulonglong *ip) +#line 1663 +{ +#line 1663 + ix_float xx = 0; +#line 1663 + get_ix_float(xp, &xx); +#line 1663 + if (xx == ULONGLONG_MAX) *ip = ULONGLONG_MAX; +#line 1663 + else if (xx > (double)ULONGLONG_MAX || xx < 0) { +#line 1663 +#ifdef ERANGE_FILL +#line 1663 + *ip = NC_FILL_UINT64; +#line 1663 +#endif +#line 1663 + return NC_ERANGE; +#line 1663 + } +#line 1663 + else *ip = (ulonglong)xx; +#line 1663 + return NC_NOERR; +#line 1663 +} +#line 1663 + + +#if X_SIZEOF_FLOAT != SIZEOF_FLOAT || defined(NO_IEEE_FLOAT) +static int +ncx_put_float_float(void *xp, const float *ip, void *fillp) +{ + int err=NC_NOERR; + float *_ip=ip; +#ifdef NO_IEEE_FLOAT +#ifdef ERANGE_FILL + float tmp; +#endif + if (*ip > X_FLOAT_MAX || *ip < X_FLOAT_MIN) { + +#line 1676 +#ifdef ERANGE_FILL +#line 1676 + if (fillp != NULL) memcpy(&tmp, fillp, 4); +#line 1676 +#endif +#ifdef ERANGE_FILL + _ip = &tmp; +#endif + err = NC_ERANGE; + } +#endif + put_ix_float(xp, _ip); + return err; +} +#endif + +static int +#line 1688 +ncx_put_float_schar(void *xp, const schar *ip, void *fillp) +#line 1688 +{ +#line 1688 + int err=NC_NOERR; +#line 1688 + ix_float xx = NC_FILL_FLOAT; +#line 1688 + +#line 1688 + +#line 1688 + xx = (ix_float)*ip; +#line 1688 + +#line 1688 + put_ix_float(xp, &xx); +#line 1688 + return err; +#line 1688 +} +#line 1688 + +static int +#line 1689 +ncx_put_float_short(void *xp, const short *ip, void *fillp) +#line 1689 +{ +#line 1689 + int err=NC_NOERR; +#line 1689 + ix_float xx = NC_FILL_FLOAT; +#line 1689 + +#line 1689 + +#line 1689 + xx = (ix_float)*ip; +#line 1689 + +#line 1689 + put_ix_float(xp, &xx); +#line 1689 + return err; +#line 1689 +} +#line 1689 + +static int +#line 1690 +ncx_put_float_int(void *xp, const int *ip, void *fillp) +#line 1690 +{ +#line 1690 + int err=NC_NOERR; +#line 1690 + ix_float xx = NC_FILL_FLOAT; +#line 1690 + +#line 1690 + +#line 1690 + xx = (ix_float)*ip; +#line 1690 + +#line 1690 + put_ix_float(xp, &xx); +#line 1690 + return err; +#line 1690 +} +#line 1690 + +static int +#line 1691 +ncx_put_float_long(void *xp, const long *ip, void *fillp) +#line 1691 +{ +#line 1691 + int err=NC_NOERR; +#line 1691 + ix_float xx = NC_FILL_FLOAT; +#line 1691 + +#line 1691 + +#line 1691 + xx = (ix_float)*ip; +#line 1691 + +#line 1691 + put_ix_float(xp, &xx); +#line 1691 + return err; +#line 1691 +} +#line 1691 + +static int +#line 1692 +ncx_put_float_double(void *xp, const double *ip, void *fillp) +#line 1692 +{ +#line 1692 + int err=NC_NOERR; +#line 1692 + ix_float xx = NC_FILL_FLOAT; +#line 1692 + +#line 1692 + if (*ip > X_FLOAT_MAX || *ip < X_FLOAT_MIN) { +#line 1692 + +#line 1692 +#ifdef ERANGE_FILL +#line 1692 + if (fillp != NULL) memcpy(&xx, fillp, 4); +#line 1692 +#endif +#line 1692 + err = NC_ERANGE; +#line 1692 + } +#line 1692 +#ifdef ERANGE_FILL +#line 1692 + else +#line 1692 +#endif +#line 1692 + xx = (ix_float)*ip; +#line 1692 + +#line 1692 + put_ix_float(xp, &xx); +#line 1692 + return err; +#line 1692 +} +#line 1692 + +static int +#line 1693 +ncx_put_float_longlong(void *xp, const longlong *ip, void *fillp) +#line 1693 +{ +#line 1693 + int err=NC_NOERR; +#line 1693 + ix_float xx = NC_FILL_FLOAT; +#line 1693 + +#line 1693 + +#line 1693 + xx = (ix_float)*ip; +#line 1693 + +#line 1693 + put_ix_float(xp, &xx); +#line 1693 + return err; +#line 1693 +} +#line 1693 + +static int +#line 1694 +ncx_put_float_uchar(void *xp, const uchar *ip, void *fillp) +#line 1694 +{ +#line 1694 + int err=NC_NOERR; +#line 1694 + ix_float xx = NC_FILL_FLOAT; +#line 1694 + +#line 1694 + +#line 1694 + xx = (ix_float)*ip; +#line 1694 + +#line 1694 + put_ix_float(xp, &xx); +#line 1694 + return err; +#line 1694 +} +#line 1694 + +static int +#line 1695 +ncx_put_float_ushort(void *xp, const ushort *ip, void *fillp) +#line 1695 +{ +#line 1695 + int err=NC_NOERR; +#line 1695 + ix_float xx = NC_FILL_FLOAT; +#line 1695 + +#line 1695 + +#line 1695 + xx = (ix_float)*ip; +#line 1695 + +#line 1695 + put_ix_float(xp, &xx); +#line 1695 + return err; +#line 1695 +} +#line 1695 + +static int +#line 1696 +ncx_put_float_uint(void *xp, const uint *ip, void *fillp) +#line 1696 +{ +#line 1696 + int err=NC_NOERR; +#line 1696 + ix_float xx = NC_FILL_FLOAT; +#line 1696 + +#line 1696 + +#line 1696 + xx = (ix_float)*ip; +#line 1696 + +#line 1696 + put_ix_float(xp, &xx); +#line 1696 + return err; +#line 1696 +} +#line 1696 + +static int +#line 1697 +ncx_put_float_ulonglong(void *xp, const ulonglong *ip, void *fillp) +#line 1697 +{ +#line 1697 + int err=NC_NOERR; +#line 1697 + ix_float xx = NC_FILL_FLOAT; +#line 1697 + +#line 1697 + +#line 1697 + xx = (ix_float)*ip; +#line 1697 + +#line 1697 + put_ix_float(xp, &xx); +#line 1697 + return err; +#line 1697 +} +#line 1697 + + + +/* external NC_DOUBLE -------------------------------------------------------*/ + +#if X_SIZEOF_DOUBLE == SIZEOF_DOUBLE && !defined(NO_IEEE_FLOAT) + +static void +get_ix_double(const void *xp, double *ip) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(ip, xp, SIZEOF_DOUBLE); +#else + swap8b(ip, xp); +#endif +} + +static void +put_ix_double(void *xp, const double *ip) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(xp, ip, X_SIZEOF_DOUBLE); +#else + swap8b(xp, ip); +#endif +} + +#elif defined(vax) && vax != 0 + +/* What IEEE double precision floating point looks like on a Vax */ +struct ieee_double { + unsigned int exp_hi : 7; + unsigned int sign : 1; + unsigned int mant_6 : 4; + unsigned int exp_lo : 4; + unsigned int mant_5 : 8; + unsigned int mant_4 : 8; + + unsigned int mant_lo : 32; +}; + +/* Vax double precision floating point */ +struct vax_double { + unsigned int mantissa1 : 7; + unsigned int exp : 8; + unsigned int sign : 1; + unsigned int mantissa2 : 16; + unsigned int mantissa3 : 16; + unsigned int mantissa4 : 16; +}; + +#define VAX_DBL_BIAS 0x81 +#define IEEE_DBL_BIAS 0x3ff +#define MASK(nbits) ((1 << nbits) - 1) + +static const struct dbl_limits { + struct vax_double d; + struct ieee_double ieee; +} dbl_limits[2] = { + {{ 0x7f, 0xff, 0x0, 0xffff, 0xffff, 0xffff }, /* Max Vax */ + { 0x7f, 0x0, 0x0, 0xf, 0x0, 0x0, 0x0}}, /* Max IEEE */ + {{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, /* Min Vax */ + { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}, /* Min IEEE */ +}; + + +#line 1811 +static void +get_ix_double(const void *xp, double *ip) +{ + struct vax_double *const vdp = +#line 1814 + (struct vax_double *)ip; +#line 1814 + const struct ieee_double *const idp = +#line 1814 + (const struct ieee_double *) xp; +#line 1814 + { +#line 1814 + const struct dbl_limits *lim; +#line 1814 + int ii; +#line 1814 + for (ii = 0, lim = dbl_limits; +#line 1814 + ii < sizeof(dbl_limits)/sizeof(struct dbl_limits); +#line 1814 + ii++, lim++) +#line 1814 + { +#line 1814 + if ((idp->mant_lo == lim->ieee.mant_lo) +#line 1814 + && (idp->mant_4 == lim->ieee.mant_4) +#line 1814 + && (idp->mant_5 == lim->ieee.mant_5) +#line 1814 + && (idp->mant_6 == lim->ieee.mant_6) +#line 1814 + && (idp->exp_lo == lim->ieee.exp_lo) +#line 1814 + && (idp->exp_hi == lim->ieee.exp_hi) +#line 1814 + ) +#line 1814 + { +#line 1814 + *vdp = lim->d; +#line 1814 + goto doneit; +#line 1814 + } +#line 1814 + } +#line 1814 + } +#line 1814 + { +#line 1814 + unsigned exp = idp->exp_hi << 4 | idp->exp_lo; +#line 1814 + vdp->exp = exp - IEEE_DBL_BIAS + VAX_DBL_BIAS; +#line 1814 + } +#line 1814 + { +#line 1814 + unsigned mant_hi = ((idp->mant_6 << 16) +#line 1814 + | (idp->mant_5 << 8) +#line 1814 + | idp->mant_4); +#line 1814 + unsigned mant_lo = SWAP4(idp->mant_lo); +#line 1814 + vdp->mantissa1 = (mant_hi >> 13); +#line 1814 + vdp->mantissa2 = ((mant_hi & MASK(13)) << 3) +#line 1814 + | (mant_lo >> 29); +#line 1814 + vdp->mantissa3 = (mant_lo >> 13); +#line 1814 + vdp->mantissa4 = (mant_lo << 3); +#line 1814 + } +#line 1814 + doneit: +#line 1814 + vdp->sign = idp->sign; +#line 1814 + +} + + +#line 1884 +static void +put_ix_double(void *xp, const double *ip) +{ + const struct vax_double *const vdp = +#line 1887 + (const struct vax_double *)ip; +#line 1887 + struct ieee_double *const idp = +#line 1887 + (struct ieee_double *) xp; +#line 1887 + +#line 1887 + if ((vdp->mantissa4 > (dbl_limits[0].d.mantissa4 - 3)) && +#line 1887 + (vdp->mantissa3 == dbl_limits[0].d.mantissa3) && +#line 1887 + (vdp->mantissa2 == dbl_limits[0].d.mantissa2) && +#line 1887 + (vdp->mantissa1 == dbl_limits[0].d.mantissa1) && +#line 1887 + (vdp->exp == dbl_limits[0].d.exp)) +#line 1887 + { +#line 1887 + *idp = dbl_limits[0].ieee; +#line 1887 + goto shipit; +#line 1887 + } +#line 1887 + if ((vdp->mantissa4 == dbl_limits[1].d.mantissa4) && +#line 1887 + (vdp->mantissa3 == dbl_limits[1].d.mantissa3) && +#line 1887 + (vdp->mantissa2 == dbl_limits[1].d.mantissa2) && +#line 1887 + (vdp->mantissa1 == dbl_limits[1].d.mantissa1) && +#line 1887 + (vdp->exp == dbl_limits[1].d.exp)) +#line 1887 + { +#line 1887 + *idp = dbl_limits[1].ieee; +#line 1887 + goto shipit; +#line 1887 + } +#line 1887 + +#line 1887 + { +#line 1887 + unsigned exp = vdp->exp - VAX_DBL_BIAS + IEEE_DBL_BIAS; +#line 1887 + +#line 1887 + unsigned mant_lo = ((vdp->mantissa2 & MASK(3)) << 29) | +#line 1887 + (vdp->mantissa3 << 13) | +#line 1887 + ((vdp->mantissa4 >> 3) & MASK(13)); +#line 1887 + +#line 1887 + unsigned mant_hi = (vdp->mantissa1 << 13) +#line 1887 + | (vdp->mantissa2 >> 3); +#line 1887 + +#line 1887 + if ((vdp->mantissa4 & 7) > 4) +#line 1887 + { +#line 1887 + /* round up */ +#line 1887 + mant_lo++; +#line 1887 + if (mant_lo == 0) +#line 1887 + { +#line 1887 + mant_hi++; +#line 1887 + if (mant_hi > 0xffffff) +#line 1887 + { +#line 1887 + mant_hi = 0; +#line 1887 + exp++; +#line 1887 + } +#line 1887 + } +#line 1887 + } +#line 1887 + +#line 1887 + idp->mant_lo = SWAP4(mant_lo); +#line 1887 + idp->mant_6 = mant_hi >> 16; +#line 1887 + idp->mant_5 = (mant_hi & 0xff00) >> 8; +#line 1887 + idp->mant_4 = mant_hi; +#line 1887 + idp->exp_hi = exp >> 4; +#line 1887 + idp->exp_lo = exp; +#line 1887 + } +#line 1887 + +#line 1887 + shipit: +#line 1887 + idp->sign = vdp->sign; +#line 1887 + +} + + /* vax */ +#elif defined(_CRAY) && !defined(__crayx1) + +static void +get_ix_double(const void *xp, double *ip) +{ + const ieee_double *idp = (const ieee_double *) xp; + cray_single *csp = (cray_single *) ip; + + if (idp->exp == 0) + { + /* ieee subnormal */ + *ip = (double)idp->mant; + if (idp->mant != 0) + { + csp->exp -= (ieee_double_bias + 51); + } + } + else + { + csp->exp = idp->exp + cs_id_bias + 1; + csp->mant = idp->mant >> (52 - 48 + 1); + csp->mant |= (1 << (48 - 1)); + } + csp->sign = idp->sign; +} + +static void +put_ix_double(void *xp, const double *ip) +{ + ieee_double *idp = (ieee_double *) xp; + const cray_single *csp = (const cray_single *) ip; + + int ieee_exp = csp->exp - cs_id_bias -1; + + idp->sign = csp->sign; + + if (ieee_exp >= 0x7ff) + { + /* NC_ERANGE => ieee Inf */ + idp->exp = 0x7ff; + idp->mant = 0x0; + } + else if (ieee_exp > 0) + { + /* normal ieee representation */ + idp->exp = ieee_exp; + /* assumes cray rep is in normal form */ + assert(csp->mant & 0x800000000000); + idp->mant = (((csp->mant << 1) & + 0xffffffffffff) << (52 - 48)); + } + else if (ieee_exp >= (-(52 -48))) + { + /* ieee subnormal, left shift */ + const int lshift = (52 - 48) + ieee_exp; + idp->mant = csp->mant << lshift; + idp->exp = 0; + } + else if (ieee_exp >= -52) + { + /* ieee subnormal, right shift */ + const int rshift = (- (52 - 48) - ieee_exp); + + idp->mant = csp->mant >> rshift; + +#if 0 + if (csp->mant & (1 << (rshift -1))) + { + /* round up */ + idp->mant++; + } +#endif + + idp->exp = 0; + } + else + { + /* smaller than ieee can represent */ + idp->exp = 0; + idp->mant = 0; + } +} +#else +#error "ix_double implementation" +#endif + +#define ix_double double + +static int +#line 1979 +ncx_get_double_schar(const void *xp, schar *ip) +#line 1979 +{ +#line 1979 + ix_double xx = 0; +#line 1979 + get_ix_double(xp, &xx); +#line 1979 + if (xx > (double)SCHAR_MAX || xx < (double)SCHAR_MIN) { +#line 1979 +#ifdef ERANGE_FILL +#line 1979 + *ip = NC_FILL_BYTE; +#line 1979 +#endif +#line 1979 + return NC_ERANGE; +#line 1979 + } +#line 1979 + *ip = (schar)xx; +#line 1979 + return NC_NOERR; +#line 1979 +} +#line 1979 + +static int +#line 1980 +ncx_get_double_short(const void *xp, short *ip) +#line 1980 +{ +#line 1980 + ix_double xx = 0; +#line 1980 + get_ix_double(xp, &xx); +#line 1980 + if (xx > (double)SHORT_MAX || xx < (double)SHORT_MIN) { +#line 1980 +#ifdef ERANGE_FILL +#line 1980 + *ip = NC_FILL_SHORT; +#line 1980 +#endif +#line 1980 + return NC_ERANGE; +#line 1980 + } +#line 1980 + *ip = (short)xx; +#line 1980 + return NC_NOERR; +#line 1980 +} +#line 1980 + +static int +#line 1981 +ncx_get_double_int(const void *xp, int *ip) +#line 1981 +{ +#line 1981 + ix_double xx = 0; +#line 1981 + get_ix_double(xp, &xx); +#line 1981 + if (xx > (double)INT_MAX || xx < (double)INT_MIN) { +#line 1981 +#ifdef ERANGE_FILL +#line 1981 + *ip = NC_FILL_INT; +#line 1981 +#endif +#line 1981 + return NC_ERANGE; +#line 1981 + } +#line 1981 + *ip = (int)xx; +#line 1981 + return NC_NOERR; +#line 1981 +} +#line 1981 + +static int +#line 1982 +ncx_get_double_long(const void *xp, long *ip) +#line 1982 +{ +#line 1982 + ix_double xx = 0; +#line 1982 + get_ix_double(xp, &xx); +#line 1982 + if (xx > (double)LONG_MAX || xx < (double)LONG_MIN) { +#line 1982 +#ifdef ERANGE_FILL +#line 1982 + *ip = NC_FILL_INT; +#line 1982 +#endif +#line 1982 + return NC_ERANGE; +#line 1982 + } +#line 1982 + *ip = (long)xx; +#line 1982 + return NC_NOERR; +#line 1982 +} +#line 1982 + +static int +#line 1983 +ncx_get_double_longlong(const void *xp, longlong *ip) +#line 1983 +{ +#line 1983 + ix_double xx = 0; +#line 1983 + get_ix_double(xp, &xx); +#line 1983 + if (xx == LONGLONG_MAX) *ip = LONGLONG_MAX; +#line 1983 + else if (xx == LONGLONG_MIN) *ip = LONGLONG_MIN; +#line 1983 + else if (xx > (double)LONGLONG_MAX || xx < (double)LONGLONG_MIN) { +#line 1983 +#ifdef ERANGE_FILL +#line 1983 + *ip = NC_FILL_INT64; +#line 1983 +#endif +#line 1983 + return NC_ERANGE; +#line 1983 + } +#line 1983 + else *ip = (longlong)xx; +#line 1983 + return NC_NOERR; +#line 1983 +} +#line 1983 + +static int +#line 1984 +ncx_get_double_uchar(const void *xp, uchar *ip) +#line 1984 +{ +#line 1984 + ix_double xx = 0; +#line 1984 + get_ix_double(xp, &xx); +#line 1984 + if (xx > (double)UCHAR_MAX || xx < 0) { +#line 1984 +#ifdef ERANGE_FILL +#line 1984 + *ip = NC_FILL_UBYTE; +#line 1984 +#endif +#line 1984 + return NC_ERANGE; +#line 1984 + } +#line 1984 + *ip = (uchar)xx; +#line 1984 + return NC_NOERR; +#line 1984 +} +#line 1984 + +static int +#line 1985 +ncx_get_double_ushort(const void *xp, ushort *ip) +#line 1985 +{ +#line 1985 + ix_double xx = 0; +#line 1985 + get_ix_double(xp, &xx); +#line 1985 + if (xx > (double)USHORT_MAX || xx < 0) { +#line 1985 +#ifdef ERANGE_FILL +#line 1985 + *ip = NC_FILL_USHORT; +#line 1985 +#endif +#line 1985 + return NC_ERANGE; +#line 1985 + } +#line 1985 + *ip = (ushort)xx; +#line 1985 + return NC_NOERR; +#line 1985 +} +#line 1985 + +static int +#line 1986 +ncx_get_double_uint(const void *xp, uint *ip) +#line 1986 +{ +#line 1986 + ix_double xx = 0; +#line 1986 + get_ix_double(xp, &xx); +#line 1986 + if (xx > (double)UINT_MAX || xx < 0) { +#line 1986 +#ifdef ERANGE_FILL +#line 1986 + *ip = NC_FILL_UINT; +#line 1986 +#endif +#line 1986 + return NC_ERANGE; +#line 1986 + } +#line 1986 + *ip = (uint)xx; +#line 1986 + return NC_NOERR; +#line 1986 +} +#line 1986 + +static int +#line 1987 +ncx_get_double_ulonglong(const void *xp, ulonglong *ip) +#line 1987 +{ +#line 1987 + ix_double xx = 0; +#line 1987 + get_ix_double(xp, &xx); +#line 1987 + if (xx == ULONGLONG_MAX) *ip = ULONGLONG_MAX; +#line 1987 + else if (xx > (double)ULONGLONG_MAX || xx < 0) { +#line 1987 +#ifdef ERANGE_FILL +#line 1987 + *ip = NC_FILL_UINT64; +#line 1987 +#endif +#line 1987 + return NC_ERANGE; +#line 1987 + } +#line 1987 + else *ip = (ulonglong)xx; +#line 1987 + return NC_NOERR; +#line 1987 +} +#line 1987 + + +static int +ncx_get_double_float(const void *xp, float *ip) +{ + double xx = 0.0; + get_ix_double(xp, &xx); + if (xx > FLT_MAX) { +#ifdef ERANGE_FILL + *ip = NC_FILL_FLOAT; +#else + *ip = FLT_MAX; +#endif + return NC_ERANGE; + } + if (xx < (-FLT_MAX)) { +#ifdef ERANGE_FILL + *ip = NC_FILL_FLOAT; +#else + *ip = (-FLT_MAX); +#endif + return NC_ERANGE; + } + *ip = (float) xx; + return NC_NOERR; +} + +#if X_SIZEOF_DOUBLE != SIZEOF_DOUBLE || defined(NO_IEEE_FLOAT) +static int +ncx_get_double_double(const void *xp, double *ip, void *fillp) +{ + /* TODO */ + get_ix_double(xp, ip); + return NC_NOERR; +} +#endif + +static int +#line 2024 +ncx_put_double_schar(void *xp, const schar *ip, void *fillp) +#line 2024 +{ +#line 2024 + int err=NC_NOERR; +#line 2024 + ix_double xx = NC_FILL_DOUBLE; +#line 2024 + +#line 2024 + +#line 2024 + xx = (ix_double)*ip; +#line 2024 + +#line 2024 + put_ix_double(xp, &xx); +#line 2024 + return err; +#line 2024 +} +#line 2024 + +static int +#line 2025 +ncx_put_double_uchar(void *xp, const uchar *ip, void *fillp) +#line 2025 +{ +#line 2025 + int err=NC_NOERR; +#line 2025 + ix_double xx = NC_FILL_DOUBLE; +#line 2025 + +#line 2025 + +#line 2025 + xx = (ix_double)*ip; +#line 2025 + +#line 2025 + put_ix_double(xp, &xx); +#line 2025 + return err; +#line 2025 +} +#line 2025 + +static int +#line 2026 +ncx_put_double_short(void *xp, const short *ip, void *fillp) +#line 2026 +{ +#line 2026 + int err=NC_NOERR; +#line 2026 + ix_double xx = NC_FILL_DOUBLE; +#line 2026 + +#line 2026 + +#line 2026 + xx = (ix_double)*ip; +#line 2026 + +#line 2026 + put_ix_double(xp, &xx); +#line 2026 + return err; +#line 2026 +} +#line 2026 + +static int +#line 2027 +ncx_put_double_ushort(void *xp, const ushort *ip, void *fillp) +#line 2027 +{ +#line 2027 + int err=NC_NOERR; +#line 2027 + ix_double xx = NC_FILL_DOUBLE; +#line 2027 + +#line 2027 + +#line 2027 + xx = (ix_double)*ip; +#line 2027 + +#line 2027 + put_ix_double(xp, &xx); +#line 2027 + return err; +#line 2027 +} +#line 2027 + +static int +#line 2028 +ncx_put_double_int(void *xp, const int *ip, void *fillp) +#line 2028 +{ +#line 2028 + int err=NC_NOERR; +#line 2028 + ix_double xx = NC_FILL_DOUBLE; +#line 2028 + +#line 2028 + +#line 2028 + xx = (ix_double)*ip; +#line 2028 + +#line 2028 + put_ix_double(xp, &xx); +#line 2028 + return err; +#line 2028 +} +#line 2028 + +static int +#line 2029 +ncx_put_double_long(void *xp, const long *ip, void *fillp) +#line 2029 +{ +#line 2029 + int err=NC_NOERR; +#line 2029 + ix_double xx = NC_FILL_DOUBLE; +#line 2029 + +#line 2029 + +#line 2029 + xx = (ix_double)*ip; +#line 2029 + +#line 2029 + put_ix_double(xp, &xx); +#line 2029 + return err; +#line 2029 +} +#line 2029 + +static int +#line 2030 +ncx_put_double_uint(void *xp, const uint *ip, void *fillp) +#line 2030 +{ +#line 2030 + int err=NC_NOERR; +#line 2030 + ix_double xx = NC_FILL_DOUBLE; +#line 2030 + +#line 2030 + +#line 2030 + xx = (ix_double)*ip; +#line 2030 + +#line 2030 + put_ix_double(xp, &xx); +#line 2030 + return err; +#line 2030 +} +#line 2030 + +static int +#line 2031 +ncx_put_double_longlong(void *xp, const longlong *ip, void *fillp) +#line 2031 +{ +#line 2031 + int err=NC_NOERR; +#line 2031 + ix_double xx = NC_FILL_DOUBLE; +#line 2031 + +#line 2031 + +#line 2031 + xx = (ix_double)*ip; +#line 2031 + +#line 2031 + put_ix_double(xp, &xx); +#line 2031 + return err; +#line 2031 +} +#line 2031 + +static int +#line 2032 +ncx_put_double_ulonglong(void *xp, const ulonglong *ip, void *fillp) +#line 2032 +{ +#line 2032 + int err=NC_NOERR; +#line 2032 + ix_double xx = NC_FILL_DOUBLE; +#line 2032 + +#line 2032 + +#line 2032 + xx = (ix_double)*ip; +#line 2032 + +#line 2032 + put_ix_double(xp, &xx); +#line 2032 + return err; +#line 2032 +} +#line 2032 + + +static int +ncx_put_double_float(void *xp, const float *ip, void *fillp) +{ + int err=NC_NOERR; + double xx = NC_FILL_DOUBLE; +#if 1 /* TODO: figure this out (if condition below will never be true)*/ + if ((double)(*ip) > X_DOUBLE_MAX || (double)(*ip) < X_DOUBLE_MIN) { + +#line 2041 +#ifdef ERANGE_FILL +#line 2041 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2041 +#endif + err = NC_ERANGE; + } +#ifdef ERANGE_FILL + else +#endif +#endif + xx = (double) *ip; + + put_ix_double(xp, &xx); + return err; +} + +#if X_SIZEOF_DOUBLE != SIZEOF_DOUBLE || defined(NO_IEEE_FLOAT) +static int +ncx_put_double_double(void *xp, const double *ip, void *fillp) +{ + int err=NC_NOERR; + double *_ip = ip; +#ifdef NO_IEEE_FLOAT +#ifdef ERANGE_FILL + double tmp=NC_FILL_DOUBLE; +#endif + if (*ip > X_DOUBLE_MAX || *ip < X_DOUBLE_MIN) { + +#line 2065 +#ifdef ERANGE_FILL +#line 2065 + if (fillp != NULL) memcpy(&tmp, fillp, 8); +#line 2065 +#endif +#ifdef ERANGE_FILL + _ip = &tmp; +#endif + err = NC_ERANGE; + } +#endif + put_ix_double(xp, _ip); + return err; +} +#endif + + +/* external NC_INT64 --------------------------------------------------------*/ + +#if SHORT_MAX == X_INT64_MAX +typedef short ix_int64; +#define SIZEOF_IX_INT64 SIZEOF_SHORT +#define IX_INT64_MAX SHORT_MAX +#elif LONG_LONG_MAX >= X_INT64_MAX +typedef longlong ix_int64; +#define SIZEOF_IX_INT64 SIZEOF_LONGLONG +#define IX_INT64_MAX LONG_LONG_MAX +#elif LONG_MAX >= X_INT64_MAX +typedef long ix_int64; +#define SIZEOF_IX_INT64 SIZEOF_LONG +#define IX_INT64_MAX LONG_MAX +#else +#error "ix_int64 implementation" +#endif + + +static void +get_ix_int64(const void *xp, ix_int64 *ip) +{ + const uchar *cp = (const uchar *) xp; + + *ip = ((ix_int64)(*cp++) << 56); + *ip |= ((ix_int64)(*cp++) << 48); + *ip |= ((ix_int64)(*cp++) << 40); + *ip |= ((ix_int64)(*cp++) << 32); + *ip |= ((ix_int64)(*cp++) << 24); + *ip |= ((ix_int64)(*cp++) << 16); + *ip |= ((ix_int64)(*cp++) << 8); + *ip |= (ix_int64)*cp; +} + +static void +put_ix_int64(void *xp, const ix_int64 *ip) +{ + uchar *cp = (uchar *) xp; + + *cp++ = (uchar)((*ip) >> 56); + *cp++ = (uchar)(((*ip) & 0x00ff000000000000LL) >> 48); + *cp++ = (uchar)(((*ip) & 0x0000ff0000000000LL) >> 40); + *cp++ = (uchar)(((*ip) & 0x000000ff00000000LL) >> 32); + *cp++ = (uchar)(((*ip) & 0x00000000ff000000LL) >> 24); + *cp++ = (uchar)(((*ip) & 0x0000000000ff0000LL) >> 16); + *cp++ = (uchar)(((*ip) & 0x000000000000ff00LL) >> 8); + *cp = (uchar)( (*ip) & 0x00000000000000ffLL); +} + +#if X_SIZEOF_INT64 != SIZEOF_LONGLONG +static int +#line 2128 +ncx_get_longlong_longlong(const void *xp, longlong *ip) +#line 2128 +{ +#line 2128 + int err=NC_NOERR; +#line 2128 +#if SIZEOF_IX_INT64 == SIZEOF_LONGLONG && IX_INT64_MAX == LONGLONG_MAX +#line 2128 + get_ix_int64(xp, (ix_int64 *)ip); +#line 2128 +#else +#line 2128 + ix_int64 xx = 0; +#line 2128 + get_ix_int64(xp, &xx); +#line 2128 + +#line 2128 +#if IX_INT64_MAX > LONGLONG_MAX +#line 2128 + if (xx > LONGLONG_MAX || xx < LONGLONG_MIN) { +#line 2128 +#ifdef ERANGE_FILL +#line 2128 + *ip = NC_FILL_INT64; +#line 2128 + return NC_ERANGE; +#line 2128 +#else +#line 2128 + err = NC_ERANGE; +#line 2128 +#endif +#line 2128 + } +#line 2128 +#endif +#line 2128 + +#line 2128 + +#line 2128 + *ip = (longlong) xx; +#line 2128 +#endif +#line 2128 + return err; +#line 2128 +} +#line 2128 + +#endif +static int +#line 2130 +ncx_get_longlong_schar(const void *xp, schar *ip) +#line 2130 +{ +#line 2130 + int err=NC_NOERR; +#line 2130 + ix_int64 xx = 0; +#line 2130 + get_ix_int64(xp, &xx); +#line 2130 + +#line 2130 +#if IX_INT64_MAX > SCHAR_MAX +#line 2130 + if (xx > SCHAR_MAX || xx < SCHAR_MIN) { +#line 2130 +#ifdef ERANGE_FILL +#line 2130 + *ip = NC_FILL_BYTE; +#line 2130 + return NC_ERANGE; +#line 2130 +#else +#line 2130 + err = NC_ERANGE; +#line 2130 +#endif +#line 2130 + } +#line 2130 +#endif +#line 2130 + +#line 2130 + +#line 2130 + *ip = (schar) xx; +#line 2130 + return err; +#line 2130 +} +#line 2130 + +static int +#line 2131 +ncx_get_longlong_short(const void *xp, short *ip) +#line 2131 +{ +#line 2131 + int err=NC_NOERR; +#line 2131 +#if SIZEOF_IX_INT64 == SIZEOF_SHORT && IX_INT64_MAX == SHORT_MAX +#line 2131 + get_ix_int64(xp, (ix_int64 *)ip); +#line 2131 +#else +#line 2131 + ix_int64 xx = 0; +#line 2131 + get_ix_int64(xp, &xx); +#line 2131 + +#line 2131 +#if IX_INT64_MAX > SHORT_MAX +#line 2131 + if (xx > SHORT_MAX || xx < SHORT_MIN) { +#line 2131 +#ifdef ERANGE_FILL +#line 2131 + *ip = NC_FILL_SHORT; +#line 2131 + return NC_ERANGE; +#line 2131 +#else +#line 2131 + err = NC_ERANGE; +#line 2131 +#endif +#line 2131 + } +#line 2131 +#endif +#line 2131 + +#line 2131 + +#line 2131 + *ip = (short) xx; +#line 2131 +#endif +#line 2131 + return err; +#line 2131 +} +#line 2131 + +static int +#line 2132 +ncx_get_longlong_int(const void *xp, int *ip) +#line 2132 +{ +#line 2132 + int err=NC_NOERR; +#line 2132 +#if SIZEOF_IX_INT64 == SIZEOF_INT && IX_INT64_MAX == INT_MAX +#line 2132 + get_ix_int64(xp, (ix_int64 *)ip); +#line 2132 +#else +#line 2132 + ix_int64 xx = 0; +#line 2132 + get_ix_int64(xp, &xx); +#line 2132 + +#line 2132 +#if IX_INT64_MAX > INT_MAX +#line 2132 + if (xx > INT_MAX || xx < INT_MIN) { +#line 2132 +#ifdef ERANGE_FILL +#line 2132 + *ip = NC_FILL_INT; +#line 2132 + return NC_ERANGE; +#line 2132 +#else +#line 2132 + err = NC_ERANGE; +#line 2132 +#endif +#line 2132 + } +#line 2132 +#endif +#line 2132 + +#line 2132 + +#line 2132 + *ip = (int) xx; +#line 2132 +#endif +#line 2132 + return err; +#line 2132 +} +#line 2132 + +static int +#line 2133 +ncx_get_longlong_long(const void *xp, long *ip) +#line 2133 +{ +#line 2133 + int err=NC_NOERR; +#line 2133 +#if SIZEOF_IX_INT64 == SIZEOF_LONG && IX_INT64_MAX == LONG_MAX +#line 2133 + get_ix_int64(xp, (ix_int64 *)ip); +#line 2133 +#else +#line 2133 + ix_int64 xx = 0; +#line 2133 + get_ix_int64(xp, &xx); +#line 2133 + +#line 2133 +#if IX_INT64_MAX > LONG_MAX +#line 2133 + if (xx > LONG_MAX || xx < LONG_MIN) { +#line 2133 +#ifdef ERANGE_FILL +#line 2133 + *ip = NC_FILL_INT; +#line 2133 + return NC_ERANGE; +#line 2133 +#else +#line 2133 + err = NC_ERANGE; +#line 2133 +#endif +#line 2133 + } +#line 2133 +#endif +#line 2133 + +#line 2133 + +#line 2133 + *ip = (long) xx; +#line 2133 +#endif +#line 2133 + return err; +#line 2133 +} +#line 2133 + +static int +#line 2134 +ncx_get_longlong_ushort(const void *xp, ushort *ip) +#line 2134 +{ +#line 2134 + int err=NC_NOERR; +#line 2134 + ix_int64 xx = 0; +#line 2134 + get_ix_int64(xp, &xx); +#line 2134 + +#line 2134 +#if IX_INT64_MAX > USHORT_MAX +#line 2134 + if (xx > USHORT_MAX) { +#line 2134 +#ifdef ERANGE_FILL +#line 2134 + *ip = NC_FILL_USHORT; +#line 2134 + return NC_ERANGE; +#line 2134 +#else +#line 2134 + err = NC_ERANGE; +#line 2134 +#endif +#line 2134 + } +#line 2134 +#endif +#line 2134 + +#line 2134 + if (xx < 0) { +#line 2134 +#ifdef ERANGE_FILL +#line 2134 + *ip = NC_FILL_USHORT; +#line 2134 + return NC_ERANGE; +#line 2134 +#else +#line 2134 + err = NC_ERANGE; /* because ip is unsigned */ +#line 2134 +#endif +#line 2134 + } +#line 2134 + *ip = (ushort) xx; +#line 2134 + return err; +#line 2134 +} +#line 2134 + +static int +#line 2135 +ncx_get_longlong_uchar(const void *xp, uchar *ip) +#line 2135 +{ +#line 2135 + int err=NC_NOERR; +#line 2135 + ix_int64 xx = 0; +#line 2135 + get_ix_int64(xp, &xx); +#line 2135 + +#line 2135 +#if IX_INT64_MAX > UCHAR_MAX +#line 2135 + if (xx > UCHAR_MAX) { +#line 2135 +#ifdef ERANGE_FILL +#line 2135 + *ip = NC_FILL_UBYTE; +#line 2135 + return NC_ERANGE; +#line 2135 +#else +#line 2135 + err = NC_ERANGE; +#line 2135 +#endif +#line 2135 + } +#line 2135 +#endif +#line 2135 + +#line 2135 + if (xx < 0) { +#line 2135 +#ifdef ERANGE_FILL +#line 2135 + *ip = NC_FILL_UBYTE; +#line 2135 + return NC_ERANGE; +#line 2135 +#else +#line 2135 + err = NC_ERANGE; /* because ip is unsigned */ +#line 2135 +#endif +#line 2135 + } +#line 2135 + *ip = (uchar) xx; +#line 2135 + return err; +#line 2135 +} +#line 2135 + +static int +#line 2136 +ncx_get_longlong_uint(const void *xp, uint *ip) +#line 2136 +{ +#line 2136 + int err=NC_NOERR; +#line 2136 + ix_int64 xx = 0; +#line 2136 + get_ix_int64(xp, &xx); +#line 2136 + +#line 2136 +#if IX_INT64_MAX > UINT_MAX +#line 2136 + if (xx > UINT_MAX) { +#line 2136 +#ifdef ERANGE_FILL +#line 2136 + *ip = NC_FILL_UINT; +#line 2136 + return NC_ERANGE; +#line 2136 +#else +#line 2136 + err = NC_ERANGE; +#line 2136 +#endif +#line 2136 + } +#line 2136 +#endif +#line 2136 + +#line 2136 + if (xx < 0) { +#line 2136 +#ifdef ERANGE_FILL +#line 2136 + *ip = NC_FILL_UINT; +#line 2136 + return NC_ERANGE; +#line 2136 +#else +#line 2136 + err = NC_ERANGE; /* because ip is unsigned */ +#line 2136 +#endif +#line 2136 + } +#line 2136 + *ip = (uint) xx; +#line 2136 + return err; +#line 2136 +} +#line 2136 + +static int +#line 2137 +ncx_get_longlong_ulonglong(const void *xp, ulonglong *ip) +#line 2137 +{ +#line 2137 + int err=NC_NOERR; +#line 2137 + ix_int64 xx = 0; +#line 2137 + get_ix_int64(xp, &xx); +#line 2137 + +#line 2137 +#if IX_INT64_MAX > ULONGLONG_MAX +#line 2137 + if (xx > ULONGLONG_MAX) { +#line 2137 +#ifdef ERANGE_FILL +#line 2137 + *ip = NC_FILL_UINT64; +#line 2137 + return NC_ERANGE; +#line 2137 +#else +#line 2137 + err = NC_ERANGE; +#line 2137 +#endif +#line 2137 + } +#line 2137 +#endif +#line 2137 + +#line 2137 + if (xx < 0) { +#line 2137 +#ifdef ERANGE_FILL +#line 2137 + *ip = NC_FILL_UINT64; +#line 2137 + return NC_ERANGE; +#line 2137 +#else +#line 2137 + err = NC_ERANGE; /* because ip is unsigned */ +#line 2137 +#endif +#line 2137 + } +#line 2137 + *ip = (ulonglong) xx; +#line 2137 + return err; +#line 2137 +} +#line 2137 + +static int +#line 2138 +ncx_get_longlong_float(const void *xp, float *ip) +#line 2138 +{ +#line 2138 + ix_int64 xx = 0; +#line 2138 + get_ix_int64(xp, &xx); +#line 2138 + *ip = (float)xx; +#line 2138 + return NC_NOERR; +#line 2138 +} +#line 2138 + +static int +#line 2139 +ncx_get_longlong_double(const void *xp, double *ip) +#line 2139 +{ +#line 2139 + ix_int64 xx = 0; +#line 2139 + get_ix_int64(xp, &xx); +#line 2139 + *ip = (double)xx; +#line 2139 + return NC_NOERR; +#line 2139 +} +#line 2139 + + +#if X_SIZEOF_INT64 != SIZEOF_LONGLONG +static int +#line 2142 +ncx_put_longlong_longlong(void *xp, const longlong *ip, void *fillp) +#line 2142 +{ +#line 2142 + int err=NC_NOERR; +#line 2142 +#if SIZEOF_IX_INT64 == SIZEOF_LONGLONG && IX_INT64_MAX == LONGLONG_MAX +#line 2142 + put_ix_int64(xp, (const ix_int64 *)ip); +#line 2142 +#else +#line 2142 + ix_int64 xx = NC_FILL_INT64; +#line 2142 + +#line 2142 +#if IX_INT64_MAX < LONGLONG_MAX +#line 2142 + if (*ip > IX_INT64_MAX || *ip < X_INT64_MIN) { +#line 2142 + +#line 2142 +#ifdef ERANGE_FILL +#line 2142 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2142 +#endif +#line 2142 + err = NC_ERANGE; +#line 2142 + } +#line 2142 +#ifdef ERANGE_FILL +#line 2142 + else +#line 2142 +#endif +#line 2142 +#endif +#line 2142 + xx = (ix_int64)*ip; +#line 2142 + +#line 2142 + put_ix_int64(xp, &xx); +#line 2142 +#endif +#line 2142 + return err; +#line 2142 +} +#line 2142 + +#endif +static int +#line 2144 +ncx_put_longlong_schar(void *xp, const schar *ip, void *fillp) +#line 2144 +{ +#line 2144 + int err=NC_NOERR; +#line 2144 + ix_int64 xx = NC_FILL_INT64; +#line 2144 + +#line 2144 +#if IX_INT64_MAX < SCHAR_MAX +#line 2144 + if (*ip > IX_INT64_MAX || *ip < X_INT64_MIN) { +#line 2144 + +#line 2144 +#ifdef ERANGE_FILL +#line 2144 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2144 +#endif +#line 2144 + err = NC_ERANGE; +#line 2144 + } +#line 2144 +#ifdef ERANGE_FILL +#line 2144 + else +#line 2144 +#endif +#line 2144 +#endif +#line 2144 + xx = (ix_int64)*ip; +#line 2144 + +#line 2144 + put_ix_int64(xp, &xx); +#line 2144 + return err; +#line 2144 +} +#line 2144 + +static int +#line 2145 +ncx_put_longlong_short(void *xp, const short *ip, void *fillp) +#line 2145 +{ +#line 2145 + int err=NC_NOERR; +#line 2145 +#if SIZEOF_IX_INT64 == SIZEOF_SHORT && IX_INT64_MAX == SHORT_MAX +#line 2145 + put_ix_int64(xp, (const ix_int64 *)ip); +#line 2145 +#else +#line 2145 + ix_int64 xx = NC_FILL_INT64; +#line 2145 + +#line 2145 +#if IX_INT64_MAX < SHORT_MAX +#line 2145 + if (*ip > IX_INT64_MAX || *ip < X_INT64_MIN) { +#line 2145 + +#line 2145 +#ifdef ERANGE_FILL +#line 2145 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2145 +#endif +#line 2145 + err = NC_ERANGE; +#line 2145 + } +#line 2145 +#ifdef ERANGE_FILL +#line 2145 + else +#line 2145 +#endif +#line 2145 +#endif +#line 2145 + xx = (ix_int64)*ip; +#line 2145 + +#line 2145 + put_ix_int64(xp, &xx); +#line 2145 +#endif +#line 2145 + return err; +#line 2145 +} +#line 2145 + +static int +#line 2146 +ncx_put_longlong_int(void *xp, const int *ip, void *fillp) +#line 2146 +{ +#line 2146 + int err=NC_NOERR; +#line 2146 +#if SIZEOF_IX_INT64 == SIZEOF_INT && IX_INT64_MAX == INT_MAX +#line 2146 + put_ix_int64(xp, (const ix_int64 *)ip); +#line 2146 +#else +#line 2146 + ix_int64 xx = NC_FILL_INT64; +#line 2146 + +#line 2146 +#if IX_INT64_MAX < INT_MAX +#line 2146 + if (*ip > IX_INT64_MAX || *ip < X_INT64_MIN) { +#line 2146 + +#line 2146 +#ifdef ERANGE_FILL +#line 2146 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2146 +#endif +#line 2146 + err = NC_ERANGE; +#line 2146 + } +#line 2146 +#ifdef ERANGE_FILL +#line 2146 + else +#line 2146 +#endif +#line 2146 +#endif +#line 2146 + xx = (ix_int64)*ip; +#line 2146 + +#line 2146 + put_ix_int64(xp, &xx); +#line 2146 +#endif +#line 2146 + return err; +#line 2146 +} +#line 2146 + +static int +#line 2147 +ncx_put_longlong_long(void *xp, const long *ip, void *fillp) +#line 2147 +{ +#line 2147 + int err=NC_NOERR; +#line 2147 +#if SIZEOF_IX_INT64 == SIZEOF_LONG && IX_INT64_MAX == LONG_MAX +#line 2147 + put_ix_int64(xp, (const ix_int64 *)ip); +#line 2147 +#else +#line 2147 + ix_int64 xx = NC_FILL_INT64; +#line 2147 + +#line 2147 +#if IX_INT64_MAX < LONG_MAX +#line 2147 + if (*ip > IX_INT64_MAX || *ip < X_INT64_MIN) { +#line 2147 + +#line 2147 +#ifdef ERANGE_FILL +#line 2147 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2147 +#endif +#line 2147 + err = NC_ERANGE; +#line 2147 + } +#line 2147 +#ifdef ERANGE_FILL +#line 2147 + else +#line 2147 +#endif +#line 2147 +#endif +#line 2147 + xx = (ix_int64)*ip; +#line 2147 + +#line 2147 + put_ix_int64(xp, &xx); +#line 2147 +#endif +#line 2147 + return err; +#line 2147 +} +#line 2147 + +static int +#line 2148 +ncx_put_longlong_ushort(void *xp, const ushort *ip, void *fillp) +#line 2148 +{ +#line 2148 + int err=NC_NOERR; +#line 2148 + ix_int64 xx = NC_FILL_INT64; +#line 2148 + +#line 2148 +#if IX_INT64_MAX < USHORT_MAX +#line 2148 + if (*ip > IX_INT64_MAX) { +#line 2148 + +#line 2148 +#ifdef ERANGE_FILL +#line 2148 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2148 +#endif +#line 2148 + err = NC_ERANGE; +#line 2148 + } +#line 2148 +#ifdef ERANGE_FILL +#line 2148 + else +#line 2148 +#endif +#line 2148 +#endif +#line 2148 + xx = (ix_int64)*ip; +#line 2148 + +#line 2148 + put_ix_int64(xp, &xx); +#line 2148 + return err; +#line 2148 +} +#line 2148 + +static int +#line 2149 +ncx_put_longlong_uchar(void *xp, const uchar *ip, void *fillp) +#line 2149 +{ +#line 2149 + int err=NC_NOERR; +#line 2149 + ix_int64 xx = NC_FILL_INT64; +#line 2149 + +#line 2149 +#if IX_INT64_MAX < UCHAR_MAX +#line 2149 + if (*ip > IX_INT64_MAX) { +#line 2149 + +#line 2149 +#ifdef ERANGE_FILL +#line 2149 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2149 +#endif +#line 2149 + err = NC_ERANGE; +#line 2149 + } +#line 2149 +#ifdef ERANGE_FILL +#line 2149 + else +#line 2149 +#endif +#line 2149 +#endif +#line 2149 + xx = (ix_int64)*ip; +#line 2149 + +#line 2149 + put_ix_int64(xp, &xx); +#line 2149 + return err; +#line 2149 +} +#line 2149 + +static int +#line 2150 +ncx_put_longlong_uint(void *xp, const uint *ip, void *fillp) +#line 2150 +{ +#line 2150 + int err=NC_NOERR; +#line 2150 + ix_int64 xx = NC_FILL_INT64; +#line 2150 + +#line 2150 +#if IX_INT64_MAX < UINT_MAX +#line 2150 + if (*ip > IX_INT64_MAX) { +#line 2150 + +#line 2150 +#ifdef ERANGE_FILL +#line 2150 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2150 +#endif +#line 2150 + err = NC_ERANGE; +#line 2150 + } +#line 2150 +#ifdef ERANGE_FILL +#line 2150 + else +#line 2150 +#endif +#line 2150 +#endif +#line 2150 + xx = (ix_int64)*ip; +#line 2150 + +#line 2150 + put_ix_int64(xp, &xx); +#line 2150 + return err; +#line 2150 +} +#line 2150 + +static int +#line 2151 +ncx_put_longlong_ulonglong(void *xp, const ulonglong *ip, void *fillp) +#line 2151 +{ +#line 2151 + int err=NC_NOERR; +#line 2151 + ix_int64 xx = NC_FILL_INT64; +#line 2151 + +#line 2151 +#if IX_INT64_MAX < ULONGLONG_MAX +#line 2151 + if (*ip > IX_INT64_MAX) { +#line 2151 + +#line 2151 +#ifdef ERANGE_FILL +#line 2151 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2151 +#endif +#line 2151 + err = NC_ERANGE; +#line 2151 + } +#line 2151 +#ifdef ERANGE_FILL +#line 2151 + else +#line 2151 +#endif +#line 2151 +#endif +#line 2151 + xx = (ix_int64)*ip; +#line 2151 + +#line 2151 + put_ix_int64(xp, &xx); +#line 2151 + return err; +#line 2151 +} +#line 2151 + +static int +#line 2152 +ncx_put_longlong_float(void *xp, const float *ip, void *fillp) +#line 2152 +{ +#line 2152 + int err=NC_NOERR; +#line 2152 + ix_int64 xx = NC_FILL_INT64; +#line 2152 + +#line 2152 + if (*ip > (double)X_INT64_MAX || *ip < (double)X_INT64_MIN) { +#line 2152 + +#line 2152 +#ifdef ERANGE_FILL +#line 2152 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2152 +#endif +#line 2152 + err = NC_ERANGE; +#line 2152 + } +#line 2152 +#ifdef ERANGE_FILL +#line 2152 + else +#line 2152 +#endif +#line 2152 + xx = (ix_int64)*ip; +#line 2152 + +#line 2152 + put_ix_int64(xp, &xx); +#line 2152 + return err; +#line 2152 +} +#line 2152 + +static int +#line 2153 +ncx_put_longlong_double(void *xp, const double *ip, void *fillp) +#line 2153 +{ +#line 2153 + int err=NC_NOERR; +#line 2153 + ix_int64 xx = NC_FILL_INT64; +#line 2153 + +#line 2153 + if (*ip > X_INT64_MAX || *ip < X_INT64_MIN) { +#line 2153 + +#line 2153 +#ifdef ERANGE_FILL +#line 2153 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2153 +#endif +#line 2153 + err = NC_ERANGE; +#line 2153 + } +#line 2153 +#ifdef ERANGE_FILL +#line 2153 + else +#line 2153 +#endif +#line 2153 + xx = (ix_int64)*ip; +#line 2153 + +#line 2153 + put_ix_int64(xp, &xx); +#line 2153 + return err; +#line 2153 +} +#line 2153 + + + +/* external NC_UINT64 -------------------------------------------------------*/ + +#if USHORT_MAX == X_UINT64_MAX +typedef ushort ix_uint64; +#define SIZEOF_IX_UINT64 SIZEOF_USHORT +#define IX_UINT64_MAX USHORT_MAX +#elif ULONG_LONG_MAX >= X_UINT64_MAX +typedef ulonglong ix_uint64; +#define SIZEOF_IX_UINT64 SIZEOF_ULONGLONG +#define IX_UINT64_MAX ULONG_LONG_MAX +#elif ULONG_MAX >= X_UINT64_MAX +typedef ulong ix_uint64; +#define SIZEOF_IX_UINT64 SIZEOF_ULONG +#define IX_UINT64_MAX ULONG_MAX +#else +#error "ix_uint64 implementation" +#endif + + +static void +get_ix_uint64(const void *xp, ix_uint64 *ip) +{ + const uchar *cp = (const uchar *) xp; + + *ip = ((ix_uint64)(*cp++) << 56); + *ip |= ((ix_uint64)(*cp++) << 48); + *ip |= ((ix_uint64)(*cp++) << 40); + *ip |= ((ix_uint64)(*cp++) << 32); + *ip |= ((ix_uint64)(*cp++) << 24); + *ip |= ((ix_uint64)(*cp++) << 16); + *ip |= ((ix_uint64)(*cp++) << 8); + *ip |= (ix_uint64)*cp; +} + +static void +put_ix_uint64(void *xp, const ix_uint64 *ip) +{ + uchar *cp = (uchar *) xp; + + *cp++ = (uchar)((*ip) >> 56); + *cp++ = (uchar)(((*ip) & 0x00ff000000000000ULL) >> 48); + *cp++ = (uchar)(((*ip) & 0x0000ff0000000000ULL) >> 40); + *cp++ = (uchar)(((*ip) & 0x000000ff00000000ULL) >> 32); + *cp++ = (uchar)(((*ip) & 0x00000000ff000000ULL) >> 24); + *cp++ = (uchar)(((*ip) & 0x0000000000ff0000ULL) >> 16); + *cp++ = (uchar)(((*ip) & 0x000000000000ff00ULL) >> 8); + *cp = (uchar)( (*ip) & 0x00000000000000ffULL); +} + +#if X_SIZEOF_UINT64 != SIZEOF_ULONGLONG +static int +#line 2206 +ncx_get_ulonglong_ulonglong(const void *xp, ulonglong *ip) +#line 2206 +{ +#line 2206 + int err=NC_NOERR; +#line 2206 +#if SIZEOF_IX_UINT64 == SIZEOF_ULONGLONG && IX_UINT64_MAX == ULONGLONG_MAX +#line 2206 + get_ix_uint64(xp, (ix_uint64 *)ip); +#line 2206 +#else +#line 2206 + ix_uint64 xx = 0; +#line 2206 + get_ix_uint64(xp, &xx); +#line 2206 + +#line 2206 +#if IX_UINT64_MAX > ULONGLONG_MAX +#line 2206 + if (xx > ULONGLONG_MAX) { +#line 2206 +#ifdef ERANGE_FILL +#line 2206 + *ip = NC_FILL_UINT64; +#line 2206 + return NC_ERANGE; +#line 2206 +#else +#line 2206 + err = NC_ERANGE; +#line 2206 +#endif +#line 2206 + } +#line 2206 +#endif +#line 2206 + +#line 2206 + +#line 2206 + *ip = (ulonglong) xx; +#line 2206 +#endif +#line 2206 + return err; +#line 2206 +} +#line 2206 + +#endif +static int +#line 2208 +ncx_get_ulonglong_schar(const void *xp, schar *ip) +#line 2208 +{ +#line 2208 + int err=NC_NOERR; +#line 2208 + ix_uint64 xx = 0; +#line 2208 + get_ix_uint64(xp, &xx); +#line 2208 + +#line 2208 +#if IX_UINT64_MAX > SCHAR_MAX +#line 2208 + if (xx > SCHAR_MAX) { +#line 2208 +#ifdef ERANGE_FILL +#line 2208 + *ip = NC_FILL_BYTE; +#line 2208 + return NC_ERANGE; +#line 2208 +#else +#line 2208 + err = NC_ERANGE; +#line 2208 +#endif +#line 2208 + } +#line 2208 +#endif +#line 2208 + +#line 2208 + +#line 2208 + *ip = (schar) xx; +#line 2208 + return err; +#line 2208 +} +#line 2208 + +static int +#line 2209 +ncx_get_ulonglong_short(const void *xp, short *ip) +#line 2209 +{ +#line 2209 + int err=NC_NOERR; +#line 2209 + ix_uint64 xx = 0; +#line 2209 + get_ix_uint64(xp, &xx); +#line 2209 + +#line 2209 +#if IX_UINT64_MAX > SHORT_MAX +#line 2209 + if (xx > SHORT_MAX) { +#line 2209 +#ifdef ERANGE_FILL +#line 2209 + *ip = NC_FILL_SHORT; +#line 2209 + return NC_ERANGE; +#line 2209 +#else +#line 2209 + err = NC_ERANGE; +#line 2209 +#endif +#line 2209 + } +#line 2209 +#endif +#line 2209 + +#line 2209 + +#line 2209 + *ip = (short) xx; +#line 2209 + return err; +#line 2209 +} +#line 2209 + +static int +#line 2210 +ncx_get_ulonglong_int(const void *xp, int *ip) +#line 2210 +{ +#line 2210 + int err=NC_NOERR; +#line 2210 + ix_uint64 xx = 0; +#line 2210 + get_ix_uint64(xp, &xx); +#line 2210 + +#line 2210 +#if IX_UINT64_MAX > INT_MAX +#line 2210 + if (xx > INT_MAX) { +#line 2210 +#ifdef ERANGE_FILL +#line 2210 + *ip = NC_FILL_INT; +#line 2210 + return NC_ERANGE; +#line 2210 +#else +#line 2210 + err = NC_ERANGE; +#line 2210 +#endif +#line 2210 + } +#line 2210 +#endif +#line 2210 + +#line 2210 + +#line 2210 + *ip = (int) xx; +#line 2210 + return err; +#line 2210 +} +#line 2210 + +static int +#line 2211 +ncx_get_ulonglong_long(const void *xp, long *ip) +#line 2211 +{ +#line 2211 + int err=NC_NOERR; +#line 2211 + ix_uint64 xx = 0; +#line 2211 + get_ix_uint64(xp, &xx); +#line 2211 + +#line 2211 +#if IX_UINT64_MAX > LONG_MAX +#line 2211 + if (xx > LONG_MAX) { +#line 2211 +#ifdef ERANGE_FILL +#line 2211 + *ip = NC_FILL_INT; +#line 2211 + return NC_ERANGE; +#line 2211 +#else +#line 2211 + err = NC_ERANGE; +#line 2211 +#endif +#line 2211 + } +#line 2211 +#endif +#line 2211 + +#line 2211 + +#line 2211 + *ip = (long) xx; +#line 2211 + return err; +#line 2211 +} +#line 2211 + +static int +#line 2212 +ncx_get_ulonglong_longlong(const void *xp, longlong *ip) +#line 2212 +{ +#line 2212 + int err=NC_NOERR; +#line 2212 + ix_uint64 xx = 0; +#line 2212 + get_ix_uint64(xp, &xx); +#line 2212 + +#line 2212 +#if IX_UINT64_MAX > LONGLONG_MAX +#line 2212 + if (xx > LONGLONG_MAX) { +#line 2212 +#ifdef ERANGE_FILL +#line 2212 + *ip = NC_FILL_INT64; +#line 2212 + return NC_ERANGE; +#line 2212 +#else +#line 2212 + err = NC_ERANGE; +#line 2212 +#endif +#line 2212 + } +#line 2212 +#endif +#line 2212 + +#line 2212 + +#line 2212 + *ip = (longlong) xx; +#line 2212 + return err; +#line 2212 +} +#line 2212 + +static int +#line 2213 +ncx_get_ulonglong_ushort(const void *xp, ushort *ip) +#line 2213 +{ +#line 2213 + int err=NC_NOERR; +#line 2213 +#if SIZEOF_IX_UINT64 == SIZEOF_USHORT && IX_UINT64_MAX == USHORT_MAX +#line 2213 + get_ix_uint64(xp, (ix_uint64 *)ip); +#line 2213 +#else +#line 2213 + ix_uint64 xx = 0; +#line 2213 + get_ix_uint64(xp, &xx); +#line 2213 + +#line 2213 +#if IX_UINT64_MAX > USHORT_MAX +#line 2213 + if (xx > USHORT_MAX) { +#line 2213 +#ifdef ERANGE_FILL +#line 2213 + *ip = NC_FILL_USHORT; +#line 2213 + return NC_ERANGE; +#line 2213 +#else +#line 2213 + err = NC_ERANGE; +#line 2213 +#endif +#line 2213 + } +#line 2213 +#endif +#line 2213 + +#line 2213 + +#line 2213 + *ip = (ushort) xx; +#line 2213 +#endif +#line 2213 + return err; +#line 2213 +} +#line 2213 + +static int +#line 2214 +ncx_get_ulonglong_uchar(const void *xp, uchar *ip) +#line 2214 +{ +#line 2214 + int err=NC_NOERR; +#line 2214 +#if SIZEOF_IX_UINT64 == SIZEOF_UCHAR && IX_UINT64_MAX == UCHAR_MAX +#line 2214 + get_ix_uint64(xp, (ix_uint64 *)ip); +#line 2214 +#else +#line 2214 + ix_uint64 xx = 0; +#line 2214 + get_ix_uint64(xp, &xx); +#line 2214 + +#line 2214 +#if IX_UINT64_MAX > UCHAR_MAX +#line 2214 + if (xx > UCHAR_MAX) { +#line 2214 +#ifdef ERANGE_FILL +#line 2214 + *ip = NC_FILL_UBYTE; +#line 2214 + return NC_ERANGE; +#line 2214 +#else +#line 2214 + err = NC_ERANGE; +#line 2214 +#endif +#line 2214 + } +#line 2214 +#endif +#line 2214 + +#line 2214 + +#line 2214 + *ip = (uchar) xx; +#line 2214 +#endif +#line 2214 + return err; +#line 2214 +} +#line 2214 + +static int +#line 2215 +ncx_get_ulonglong_uint(const void *xp, uint *ip) +#line 2215 +{ +#line 2215 + int err=NC_NOERR; +#line 2215 +#if SIZEOF_IX_UINT64 == SIZEOF_UINT && IX_UINT64_MAX == UINT_MAX +#line 2215 + get_ix_uint64(xp, (ix_uint64 *)ip); +#line 2215 +#else +#line 2215 + ix_uint64 xx = 0; +#line 2215 + get_ix_uint64(xp, &xx); +#line 2215 + +#line 2215 +#if IX_UINT64_MAX > UINT_MAX +#line 2215 + if (xx > UINT_MAX) { +#line 2215 +#ifdef ERANGE_FILL +#line 2215 + *ip = NC_FILL_UINT; +#line 2215 + return NC_ERANGE; +#line 2215 +#else +#line 2215 + err = NC_ERANGE; +#line 2215 +#endif +#line 2215 + } +#line 2215 +#endif +#line 2215 + +#line 2215 + +#line 2215 + *ip = (uint) xx; +#line 2215 +#endif +#line 2215 + return err; +#line 2215 +} +#line 2215 + +static int +#line 2216 +ncx_get_ulonglong_float(const void *xp, float *ip) +#line 2216 +{ +#line 2216 + ix_uint64 xx = 0; +#line 2216 + get_ix_uint64(xp, &xx); +#line 2216 + *ip = (float)xx; +#line 2216 + return NC_NOERR; +#line 2216 +} +#line 2216 + +static int +#line 2217 +ncx_get_ulonglong_double(const void *xp, double *ip) +#line 2217 +{ +#line 2217 + ix_uint64 xx = 0; +#line 2217 + get_ix_uint64(xp, &xx); +#line 2217 + *ip = (double)xx; +#line 2217 + return NC_NOERR; +#line 2217 +} +#line 2217 + + +#if X_SIZEOF_UINT64 != SIZEOF_ULONGLONG +static int +#line 2220 +ncx_put_ulonglong_ulonglong(void *xp, const ulonglong *ip, void *fillp) +#line 2220 +{ +#line 2220 + int err=NC_NOERR; +#line 2220 +#if SIZEOF_IX_UINT64 == SIZEOF_ULONGLONG && IX_UINT64_MAX == ULONGLONG_MAX +#line 2220 + put_ix_uint64(xp, (const ix_uint64 *)ip); +#line 2220 +#else +#line 2220 + ix_uint64 xx = NC_FILL_UINT64; +#line 2220 + +#line 2220 +#if IX_UINT64_MAX < ULONGLONG_MAX +#line 2220 + if (*ip > IX_UINT64_MAX) { +#line 2220 + +#line 2220 +#ifdef ERANGE_FILL +#line 2220 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2220 +#endif +#line 2220 + err = NC_ERANGE; +#line 2220 + } +#line 2220 +#ifdef ERANGE_FILL +#line 2220 + else +#line 2220 +#endif +#line 2220 +#endif +#line 2220 + xx = (ix_uint64)*ip; +#line 2220 + +#line 2220 + put_ix_uint64(xp, &xx); +#line 2220 +#endif +#line 2220 + return err; +#line 2220 +} +#line 2220 + +#endif +static int +#line 2222 +ncx_put_ulonglong_schar(void *xp, const schar *ip, void *fillp) +#line 2222 +{ +#line 2222 + int err=NC_NOERR; +#line 2222 + ix_uint64 xx = NC_FILL_UINT64; +#line 2222 + +#line 2222 +#if IX_UINT64_MAX < SCHAR_MAX +#line 2222 + if (*ip > IX_UINT64_MAX) { +#line 2222 + +#line 2222 +#ifdef ERANGE_FILL +#line 2222 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2222 +#endif +#line 2222 + err = NC_ERANGE; +#line 2222 + } +#line 2222 +#ifdef ERANGE_FILL +#line 2222 + else +#line 2222 +#endif +#line 2222 +#endif +#line 2222 + if (*ip < 0) { +#line 2222 + +#line 2222 +#ifdef ERANGE_FILL +#line 2222 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2222 +#endif +#line 2222 + err = NC_ERANGE; /* because xp is unsigned */ +#line 2222 + } +#line 2222 +#ifdef ERANGE_FILL +#line 2222 + else +#line 2222 +#endif +#line 2222 + xx = (ix_uint64)*ip; +#line 2222 + +#line 2222 + put_ix_uint64(xp, &xx); +#line 2222 + return err; +#line 2222 +} +#line 2222 + +static int +#line 2223 +ncx_put_ulonglong_short(void *xp, const short *ip, void *fillp) +#line 2223 +{ +#line 2223 + int err=NC_NOERR; +#line 2223 + ix_uint64 xx = NC_FILL_UINT64; +#line 2223 + +#line 2223 +#if IX_UINT64_MAX < SHORT_MAX +#line 2223 + if (*ip > IX_UINT64_MAX) { +#line 2223 + +#line 2223 +#ifdef ERANGE_FILL +#line 2223 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2223 +#endif +#line 2223 + err = NC_ERANGE; +#line 2223 + } +#line 2223 +#ifdef ERANGE_FILL +#line 2223 + else +#line 2223 +#endif +#line 2223 +#endif +#line 2223 + if (*ip < 0) { +#line 2223 + +#line 2223 +#ifdef ERANGE_FILL +#line 2223 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2223 +#endif +#line 2223 + err = NC_ERANGE; /* because xp is unsigned */ +#line 2223 + } +#line 2223 +#ifdef ERANGE_FILL +#line 2223 + else +#line 2223 +#endif +#line 2223 + xx = (ix_uint64)*ip; +#line 2223 + +#line 2223 + put_ix_uint64(xp, &xx); +#line 2223 + return err; +#line 2223 +} +#line 2223 + +static int +#line 2224 +ncx_put_ulonglong_int(void *xp, const int *ip, void *fillp) +#line 2224 +{ +#line 2224 + int err=NC_NOERR; +#line 2224 + ix_uint64 xx = NC_FILL_UINT64; +#line 2224 + +#line 2224 +#if IX_UINT64_MAX < INT_MAX +#line 2224 + if (*ip > IX_UINT64_MAX) { +#line 2224 + +#line 2224 +#ifdef ERANGE_FILL +#line 2224 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2224 +#endif +#line 2224 + err = NC_ERANGE; +#line 2224 + } +#line 2224 +#ifdef ERANGE_FILL +#line 2224 + else +#line 2224 +#endif +#line 2224 +#endif +#line 2224 + if (*ip < 0) { +#line 2224 + +#line 2224 +#ifdef ERANGE_FILL +#line 2224 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2224 +#endif +#line 2224 + err = NC_ERANGE; /* because xp is unsigned */ +#line 2224 + } +#line 2224 +#ifdef ERANGE_FILL +#line 2224 + else +#line 2224 +#endif +#line 2224 + xx = (ix_uint64)*ip; +#line 2224 + +#line 2224 + put_ix_uint64(xp, &xx); +#line 2224 + return err; +#line 2224 +} +#line 2224 + +static int +#line 2225 +ncx_put_ulonglong_long(void *xp, const long *ip, void *fillp) +#line 2225 +{ +#line 2225 + int err=NC_NOERR; +#line 2225 + ix_uint64 xx = NC_FILL_UINT64; +#line 2225 + +#line 2225 +#if IX_UINT64_MAX < LONG_MAX +#line 2225 + if (*ip > IX_UINT64_MAX) { +#line 2225 + +#line 2225 +#ifdef ERANGE_FILL +#line 2225 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2225 +#endif +#line 2225 + err = NC_ERANGE; +#line 2225 + } +#line 2225 +#ifdef ERANGE_FILL +#line 2225 + else +#line 2225 +#endif +#line 2225 +#endif +#line 2225 + if (*ip < 0) { +#line 2225 + +#line 2225 +#ifdef ERANGE_FILL +#line 2225 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2225 +#endif +#line 2225 + err = NC_ERANGE; /* because xp is unsigned */ +#line 2225 + } +#line 2225 +#ifdef ERANGE_FILL +#line 2225 + else +#line 2225 +#endif +#line 2225 + xx = (ix_uint64)*ip; +#line 2225 + +#line 2225 + put_ix_uint64(xp, &xx); +#line 2225 + return err; +#line 2225 +} +#line 2225 + +static int +#line 2226 +ncx_put_ulonglong_longlong(void *xp, const longlong *ip, void *fillp) +#line 2226 +{ +#line 2226 + int err=NC_NOERR; +#line 2226 + ix_uint64 xx = NC_FILL_UINT64; +#line 2226 + +#line 2226 +#if IX_UINT64_MAX < LONGLONG_MAX +#line 2226 + if (*ip > IX_UINT64_MAX) { +#line 2226 + +#line 2226 +#ifdef ERANGE_FILL +#line 2226 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2226 +#endif +#line 2226 + err = NC_ERANGE; +#line 2226 + } +#line 2226 +#ifdef ERANGE_FILL +#line 2226 + else +#line 2226 +#endif +#line 2226 +#endif +#line 2226 + if (*ip < 0) { +#line 2226 + +#line 2226 +#ifdef ERANGE_FILL +#line 2226 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2226 +#endif +#line 2226 + err = NC_ERANGE; /* because xp is unsigned */ +#line 2226 + } +#line 2226 +#ifdef ERANGE_FILL +#line 2226 + else +#line 2226 +#endif +#line 2226 + xx = (ix_uint64)*ip; +#line 2226 + +#line 2226 + put_ix_uint64(xp, &xx); +#line 2226 + return err; +#line 2226 +} +#line 2226 + +static int +#line 2227 +ncx_put_ulonglong_uchar(void *xp, const uchar *ip, void *fillp) +#line 2227 +{ +#line 2227 + int err=NC_NOERR; +#line 2227 +#if SIZEOF_IX_UINT64 == SIZEOF_UCHAR && IX_UINT64_MAX == UCHAR_MAX +#line 2227 + put_ix_uint64(xp, (const ix_uint64 *)ip); +#line 2227 +#else +#line 2227 + ix_uint64 xx = NC_FILL_UINT64; +#line 2227 + +#line 2227 +#if IX_UINT64_MAX < UCHAR_MAX +#line 2227 + if (*ip > IX_UINT64_MAX) { +#line 2227 + +#line 2227 +#ifdef ERANGE_FILL +#line 2227 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2227 +#endif +#line 2227 + err = NC_ERANGE; +#line 2227 + } +#line 2227 +#ifdef ERANGE_FILL +#line 2227 + else +#line 2227 +#endif +#line 2227 +#endif +#line 2227 + xx = (ix_uint64)*ip; +#line 2227 + +#line 2227 + put_ix_uint64(xp, &xx); +#line 2227 +#endif +#line 2227 + return err; +#line 2227 +} +#line 2227 + +static int +#line 2228 +ncx_put_ulonglong_ushort(void *xp, const ushort *ip, void *fillp) +#line 2228 +{ +#line 2228 + int err=NC_NOERR; +#line 2228 +#if SIZEOF_IX_UINT64 == SIZEOF_USHORT && IX_UINT64_MAX == USHORT_MAX +#line 2228 + put_ix_uint64(xp, (const ix_uint64 *)ip); +#line 2228 +#else +#line 2228 + ix_uint64 xx = NC_FILL_UINT64; +#line 2228 + +#line 2228 +#if IX_UINT64_MAX < USHORT_MAX +#line 2228 + if (*ip > IX_UINT64_MAX) { +#line 2228 + +#line 2228 +#ifdef ERANGE_FILL +#line 2228 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2228 +#endif +#line 2228 + err = NC_ERANGE; +#line 2228 + } +#line 2228 +#ifdef ERANGE_FILL +#line 2228 + else +#line 2228 +#endif +#line 2228 +#endif +#line 2228 + xx = (ix_uint64)*ip; +#line 2228 + +#line 2228 + put_ix_uint64(xp, &xx); +#line 2228 +#endif +#line 2228 + return err; +#line 2228 +} +#line 2228 + +static int +#line 2229 +ncx_put_ulonglong_uint(void *xp, const uint *ip, void *fillp) +#line 2229 +{ +#line 2229 + int err=NC_NOERR; +#line 2229 +#if SIZEOF_IX_UINT64 == SIZEOF_UINT && IX_UINT64_MAX == UINT_MAX +#line 2229 + put_ix_uint64(xp, (const ix_uint64 *)ip); +#line 2229 +#else +#line 2229 + ix_uint64 xx = NC_FILL_UINT64; +#line 2229 + +#line 2229 +#if IX_UINT64_MAX < UINT_MAX +#line 2229 + if (*ip > IX_UINT64_MAX) { +#line 2229 + +#line 2229 +#ifdef ERANGE_FILL +#line 2229 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2229 +#endif +#line 2229 + err = NC_ERANGE; +#line 2229 + } +#line 2229 +#ifdef ERANGE_FILL +#line 2229 + else +#line 2229 +#endif +#line 2229 +#endif +#line 2229 + xx = (ix_uint64)*ip; +#line 2229 + +#line 2229 + put_ix_uint64(xp, &xx); +#line 2229 +#endif +#line 2229 + return err; +#line 2229 +} +#line 2229 + +static int +#line 2230 +ncx_put_ulonglong_float(void *xp, const float *ip, void *fillp) +#line 2230 +{ +#line 2230 + int err=NC_NOERR; +#line 2230 + ix_uint64 xx = NC_FILL_UINT64; +#line 2230 + +#line 2230 + if (*ip > (double)X_UINT64_MAX || *ip < 0) { +#line 2230 + +#line 2230 +#ifdef ERANGE_FILL +#line 2230 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2230 +#endif +#line 2230 + err = NC_ERANGE; +#line 2230 + } +#line 2230 +#ifdef ERANGE_FILL +#line 2230 + else +#line 2230 +#endif +#line 2230 + xx = (ix_uint64)*ip; +#line 2230 + +#line 2230 + put_ix_uint64(xp, &xx); +#line 2230 + return err; +#line 2230 +} +#line 2230 + +static int +#line 2231 +ncx_put_ulonglong_double(void *xp, const double *ip, void *fillp) +#line 2231 +{ +#line 2231 + int err=NC_NOERR; +#line 2231 + ix_uint64 xx = NC_FILL_UINT64; +#line 2231 + +#line 2231 + if (*ip > X_UINT64_MAX || *ip < 0) { +#line 2231 + +#line 2231 +#ifdef ERANGE_FILL +#line 2231 + if (fillp != NULL) memcpy(&xx, fillp, 8); +#line 2231 +#endif +#line 2231 + err = NC_ERANGE; +#line 2231 + } +#line 2231 +#ifdef ERANGE_FILL +#line 2231 + else +#line 2231 +#endif +#line 2231 + xx = (ix_uint64)*ip; +#line 2231 + +#line 2231 + put_ix_uint64(xp, &xx); +#line 2231 + return err; +#line 2231 +} +#line 2231 + + + +/* x_size_t */ + +#if SIZEOF_SIZE_T < X_SIZEOF_SIZE_T +#error "x_size_t implementation" +/* netcdf requires size_t which can hold a values from 0 to 2^32 -1 */ +#endif + +int +ncx_put_size_t(void **xpp, const size_t *ulp) +{ + /* similar to put_ix_int() */ + uchar *cp = (uchar *) *xpp; + assert(*ulp <= X_SIZE_MAX); + + *cp++ = (uchar)((*ulp) >> 24); + *cp++ = (uchar)(((*ulp) & 0x00ff0000) >> 16); + *cp++ = (uchar)(((*ulp) & 0x0000ff00) >> 8); + *cp = (uchar)((*ulp) & 0x000000ff); + + *xpp = (void *)((char *)(*xpp) + X_SIZEOF_SIZE_T); + return NC_NOERR; +} + +int +ncx_get_size_t(const void **xpp, size_t *ulp) +{ + /* similar to get_ix_int */ + const uchar *cp = (const uchar *) *xpp; + + *ulp = (unsigned)(*cp++) << 24; + *ulp |= (*cp++ << 16); + *ulp |= (*cp++ << 8); + *ulp |= *cp; + + *xpp = (const void *)((const char *)(*xpp) + X_SIZEOF_SIZE_T); + return NC_NOERR; +} + +/* x_off_t */ + +int +ncx_put_off_t(void **xpp, const off_t *lp, size_t sizeof_off_t) +{ + /* similar to put_ix_int() */ + uchar *cp = (uchar *) *xpp; + + /* No negative offsets stored in netcdf */ + if (*lp < 0) { + /* Assume this is an overflow of a 32-bit int... */ + return NC_ERANGE; + } + + assert(sizeof_off_t == 4 || sizeof_off_t == 8); + + if (sizeof_off_t == 4) { + *cp++ = (uchar) ((*lp) >> 24); + *cp++ = (uchar)(((*lp) & 0x00ff0000) >> 16); + *cp++ = (uchar)(((*lp) & 0x0000ff00) >> 8); + *cp = (uchar)( (*lp) & 0x000000ff); + } else { +#if SIZEOF_OFF_T == 4 +/* Write a 64-bit offset on a system with only a 32-bit offset */ + *cp++ = (uchar)0; + *cp++ = (uchar)0; + *cp++ = (uchar)0; + *cp++ = (uchar)0; + + *cp++ = (uchar)(((*lp) & 0xff000000) >> 24); + *cp++ = (uchar)(((*lp) & 0x00ff0000) >> 16); + *cp++ = (uchar)(((*lp) & 0x0000ff00) >> 8); + *cp = (uchar)( (*lp) & 0x000000ff); +#else + *cp++ = (uchar) ((*lp) >> 56); + *cp++ = (uchar)(((*lp) & 0x00ff000000000000LL) >> 48); + *cp++ = (uchar)(((*lp) & 0x0000ff0000000000LL) >> 40); + *cp++ = (uchar)(((*lp) & 0x000000ff00000000LL) >> 32); + *cp++ = (uchar)(((*lp) & 0x00000000ff000000LL) >> 24); + *cp++ = (uchar)(((*lp) & 0x0000000000ff0000LL) >> 16); + *cp++ = (uchar)(((*lp) & 0x000000000000ff00LL) >> 8); + *cp = (uchar)( (*lp) & 0x00000000000000ffLL); +#endif + } + *xpp = (void *)((char *)(*xpp) + sizeof_off_t); + return NC_NOERR; +} + +int +ncx_get_off_t(const void **xpp, off_t *lp, size_t sizeof_off_t) +{ + /* similar to get_ix_int() */ + const uchar *cp = (const uchar *) *xpp; + assert(sizeof_off_t == 4 || sizeof_off_t == 8); + + if (sizeof_off_t == 4) { + *lp = (off_t)(*cp++ << 24); + *lp |= (off_t)(*cp++ << 16); + *lp |= (off_t)(*cp++ << 8); + *lp |= (off_t)*cp; + } else { +#if SIZEOF_OFF_T == 4 +/* Read a 64-bit offset on a system with only a 32-bit offset */ +/* If the offset overflows, set an error code and return */ + *lp = ((off_t)(*cp++) << 24); + *lp |= ((off_t)(*cp++) << 16); + *lp |= ((off_t)(*cp++) << 8); + *lp |= ((off_t)(*cp++)); +/* + * lp now contains the upper 32-bits of the 64-bit offset. if lp is + * not zero, then the dataset is larger than can be represented + * on this system. Set an error code and return. + */ + if (*lp != 0) { + return NC_ERANGE; + } + + *lp = ((off_t)(*cp++) << 24); + *lp |= ((off_t)(*cp++) << 16); + *lp |= ((off_t)(*cp++) << 8); + *lp |= (off_t)*cp; + + if (*lp < 0) { + /* + * If this fails, then the offset is >2^31, but less + * than 2^32 which is not allowed, but is not caught + * by the previous check + */ + return NC_ERANGE; + } +#else + *lp = ((off_t)(*cp++) << 56); + *lp |= ((off_t)(*cp++) << 48); + *lp |= ((off_t)(*cp++) << 40); + *lp |= ((off_t)(*cp++) << 32); + *lp |= ((off_t)(*cp++) << 24); + *lp |= ((off_t)(*cp++) << 16); + *lp |= ((off_t)(*cp++) << 8); + *lp |= (off_t)*cp; +#endif + } + *xpp = (const void *)((const char *)(*xpp) + sizeof_off_t); + return NC_NOERR; +} + +/*----< ncx_get_uint32() >------------------------------------------*/ +int +ncx_get_uint32(const void **xpp, uint *ip) +{ +#ifdef WORDS_BIGENDIAN + /* use memcpy instead of assignment to avoid BUS_ADRALN alignment error on + * some system, such as HPUX */ + (void) memcpy(ip, *xpp, SIZEOF_UINT); +#else + const uchar *cp = (const uchar *) *xpp; + + *ip = (uint)(*cp++ << 24); + *ip = (uint)(*ip | (uint)(*cp++ << 16)); + *ip = (uint)(*ip | (uint)(*cp++ << 8)); + *ip = (uint)(*ip | *cp); +#endif + /* advance *xpp 4 bytes */ + *xpp = (void *)((const char *)(*xpp) + 4); + + return NC_NOERR; +} + +/*----< ncx_get_uint64() >------------------------------------------*/ +int +ncx_get_uint64(const void **xpp, unsigned long long *ullp) +{ +#ifdef WORDS_BIGENDIAN + /* use memcpy instead of assignment to avoid BUS_ADRALN alignment error on + * some system, such as HPUX */ + (void) memcpy(ullp, *xpp, SIZEOF_UINT64); +#else + const uchar *cp = (const uchar *) *xpp; + + /* below is the same as calling swap8b(ullp, *xpp) */ + *ullp = (unsigned long long)(*cp++) << 56; + *ullp = (unsigned long long)(*ullp | (unsigned long long)(*cp++) << 48); + *ullp = (unsigned long long)(*ullp | (unsigned long long)(*cp++) << 40); + *ullp = (unsigned long long)(*ullp | (unsigned long long)(*cp++) << 32); + *ullp = (unsigned long long)(*ullp | (unsigned long long)(*cp++) << 24); + *ullp = (unsigned long long)(*ullp | (unsigned long long)(*cp++) << 16); + *ullp = (unsigned long long)(*ullp | (unsigned long long)(*cp++) << 8); + *ullp = (unsigned long long)(*ullp | (unsigned long long)(*cp)); +#endif + /* advance *xpp 8 bytes */ + *xpp = (void *)((const char *)(*xpp) + 8); + + return NC_NOERR; +} + +/*---< ncx_put_uint32() >-------------------------------------------*/ +/* copy the contents of ip (an unsigned 32-bit integer) to xpp in Big Endian + * form and advance *xpp 4 bytes + */ +int +ncx_put_uint32(void **xpp, const unsigned int ip) +{ +#ifdef WORDS_BIGENDIAN + /* use memcpy instead of assignment to avoid BUS_ADRALN alignment error on + * some system, such as HPUX */ + (void) memcpy(*xpp, &ip, X_SIZEOF_UINT); +#else + /* bitwise shifts below are to produce an integer in Big Endian */ + uchar *cp = (uchar *) *xpp; + *cp++ = (uchar)((ip & 0xff000000) >> 24); + *cp++ = (uchar)((ip & 0x00ff0000) >> 16); + *cp++ = (uchar)((ip & 0x0000ff00) >> 8); + *cp = (uchar)( ip & 0x000000ff); +#endif + /* advance *xpp 4 bytes */ + *xpp = (void *)((char *)(*xpp) + 4); + + return NC_NOERR; +} + +/*---< ncx_put_uint64() >-------------------------------------------*/ +/* copy the contents of ip (an unsigned 64-bit integer) to xpp in Big Endian + * form and advance *xpp 8 bytes + */ +int +ncx_put_uint64(void **xpp, const unsigned long long ip) +{ +#ifdef WORDS_BIGENDIAN + /* use memcpy instead of assignment to avoid BUS_ADRALN alignment error on + * some system, such as HPUX */ + (void) memcpy(*xpp, &ip, X_SIZEOF_UINT64); +#else + uchar *cp = (uchar *) *xpp; + /* below is the same as calling swap8b(*xpp, &ip) */ + *cp++ = (uchar) (ip >> 56); + *cp++ = (uchar)((ip & 0x00ff000000000000LL) >> 48); + *cp++ = (uchar)((ip & 0x0000ff0000000000LL) >> 40); + *cp++ = (uchar)((ip & 0x000000ff00000000LL) >> 32); + *cp++ = (uchar)((ip & 0x00000000ff000000LL) >> 24); + *cp++ = (uchar)((ip & 0x0000000000ff0000LL) >> 16); + *cp++ = (uchar)((ip & 0x000000000000ff00LL) >> 8); + *cp = (uchar) (ip & 0x00000000000000ffLL); +#endif + /* advance *xpp 8 bytes */ + *xpp = (void *)((char *)(*xpp) + 8); + + return NC_NOERR; +} + + +/* + * Aggregate numeric conversion functions. + */ +#line 2487 + +#line 2890 + +#line 2896 + +/* schar ---------------------------------------------------------------------*/ + +#line 2900 +int +ncx_getn_schar_schar(const void **xpp, size_t nelems, schar *tp) +{ + (void) memcpy(tp, *xpp, (size_t)nelems); +#line 2903 + *xpp = (void *)((char *)(*xpp) + nelems); +#line 2903 + return NC_NOERR; +#line 2903 + +} +int +#line 2905 +ncx_getn_schar_uchar(const void **xpp, size_t nelems, uchar *tp) +#line 2905 +{ +#line 2905 + int status = NC_NOERR; +#line 2905 + schar *xp = (schar *)(*xpp); +#line 2905 + +#line 2905 + while (nelems-- != 0) { +#line 2905 + +#line 2905 + if (*xp < 0) { +#line 2905 +#ifdef ERANGE_FILL +#line 2905 + *tp = NC_FILL_UBYTE; +#line 2905 +#endif +#line 2905 + status = NC_ERANGE; /* because tp is unsigned */ +#line 2905 + +#line 2905 +#ifdef ERANGE_FILL +#line 2905 + xp++; tp++; continue; +#line 2905 +#endif +#line 2905 + } +#line 2905 + *tp++ = (uchar) (signed) (*xp++); /* type cast from schar to uchar */ +#line 2905 + } +#line 2905 + +#line 2905 + *xpp = (const void *)xp; +#line 2905 + return status; +#line 2905 +} +#line 2905 + +int +#line 2906 +ncx_getn_schar_short(const void **xpp, size_t nelems, short *tp) +#line 2906 +{ +#line 2906 + int status = NC_NOERR; +#line 2906 + schar *xp = (schar *)(*xpp); +#line 2906 + +#line 2906 + while (nelems-- != 0) { +#line 2906 + +#line 2906 + *tp++ = (short) (*xp++); /* type cast from schar to short */ +#line 2906 + } +#line 2906 + +#line 2906 + *xpp = (const void *)xp; +#line 2906 + return status; +#line 2906 +} +#line 2906 + +int +#line 2907 +ncx_getn_schar_int(const void **xpp, size_t nelems, int *tp) +#line 2907 +{ +#line 2907 + int status = NC_NOERR; +#line 2907 + schar *xp = (schar *)(*xpp); +#line 2907 + +#line 2907 + while (nelems-- != 0) { +#line 2907 + +#line 2907 + *tp++ = (int) (*xp++); /* type cast from schar to int */ +#line 2907 + } +#line 2907 + +#line 2907 + *xpp = (const void *)xp; +#line 2907 + return status; +#line 2907 +} +#line 2907 + +int +#line 2908 +ncx_getn_schar_long(const void **xpp, size_t nelems, long *tp) +#line 2908 +{ +#line 2908 + int status = NC_NOERR; +#line 2908 + schar *xp = (schar *)(*xpp); +#line 2908 + +#line 2908 + while (nelems-- != 0) { +#line 2908 + +#line 2908 + *tp++ = (long) (*xp++); /* type cast from schar to long */ +#line 2908 + } +#line 2908 + +#line 2908 + *xpp = (const void *)xp; +#line 2908 + return status; +#line 2908 +} +#line 2908 + +int +#line 2909 +ncx_getn_schar_float(const void **xpp, size_t nelems, float *tp) +#line 2909 +{ +#line 2909 + int status = NC_NOERR; +#line 2909 + schar *xp = (schar *)(*xpp); +#line 2909 + +#line 2909 + while (nelems-- != 0) { +#line 2909 + +#line 2909 + *tp++ = (float) (*xp++); /* type cast from schar to float */ +#line 2909 + } +#line 2909 + +#line 2909 + *xpp = (const void *)xp; +#line 2909 + return status; +#line 2909 +} +#line 2909 + +int +#line 2910 +ncx_getn_schar_double(const void **xpp, size_t nelems, double *tp) +#line 2910 +{ +#line 2910 + int status = NC_NOERR; +#line 2910 + schar *xp = (schar *)(*xpp); +#line 2910 + +#line 2910 + while (nelems-- != 0) { +#line 2910 + +#line 2910 + *tp++ = (double) (*xp++); /* type cast from schar to double */ +#line 2910 + } +#line 2910 + +#line 2910 + *xpp = (const void *)xp; +#line 2910 + return status; +#line 2910 +} +#line 2910 + +int +#line 2911 +ncx_getn_schar_longlong(const void **xpp, size_t nelems, longlong *tp) +#line 2911 +{ +#line 2911 + int status = NC_NOERR; +#line 2911 + schar *xp = (schar *)(*xpp); +#line 2911 + +#line 2911 + while (nelems-- != 0) { +#line 2911 + +#line 2911 + *tp++ = (longlong) (*xp++); /* type cast from schar to longlong */ +#line 2911 + } +#line 2911 + +#line 2911 + *xpp = (const void *)xp; +#line 2911 + return status; +#line 2911 +} +#line 2911 + +int +#line 2912 +ncx_getn_schar_ushort(const void **xpp, size_t nelems, ushort *tp) +#line 2912 +{ +#line 2912 + int status = NC_NOERR; +#line 2912 + schar *xp = (schar *)(*xpp); +#line 2912 + +#line 2912 + while (nelems-- != 0) { +#line 2912 + +#line 2912 + if (*xp < 0) { +#line 2912 +#ifdef ERANGE_FILL +#line 2912 + *tp = NC_FILL_USHORT; +#line 2912 +#endif +#line 2912 + status = NC_ERANGE; /* because tp is unsigned */ +#line 2912 + +#line 2912 +#ifdef ERANGE_FILL +#line 2912 + xp++; tp++; continue; +#line 2912 +#endif +#line 2912 + } +#line 2912 + *tp++ = (ushort) (signed) (*xp++); /* type cast from schar to ushort */ +#line 2912 + } +#line 2912 + +#line 2912 + *xpp = (const void *)xp; +#line 2912 + return status; +#line 2912 +} +#line 2912 + +int +#line 2913 +ncx_getn_schar_uint(const void **xpp, size_t nelems, uint *tp) +#line 2913 +{ +#line 2913 + int status = NC_NOERR; +#line 2913 + schar *xp = (schar *)(*xpp); +#line 2913 + +#line 2913 + while (nelems-- != 0) { +#line 2913 + +#line 2913 + if (*xp < 0) { +#line 2913 +#ifdef ERANGE_FILL +#line 2913 + *tp = NC_FILL_UINT; +#line 2913 +#endif +#line 2913 + status = NC_ERANGE; /* because tp is unsigned */ +#line 2913 + +#line 2913 +#ifdef ERANGE_FILL +#line 2913 + xp++; tp++; continue; +#line 2913 +#endif +#line 2913 + } +#line 2913 + *tp++ = (uint) (signed) (*xp++); /* type cast from schar to uint */ +#line 2913 + } +#line 2913 + +#line 2913 + *xpp = (const void *)xp; +#line 2913 + return status; +#line 2913 +} +#line 2913 + +int +#line 2914 +ncx_getn_schar_ulonglong(const void **xpp, size_t nelems, ulonglong *tp) +#line 2914 +{ +#line 2914 + int status = NC_NOERR; +#line 2914 + schar *xp = (schar *)(*xpp); +#line 2914 + +#line 2914 + while (nelems-- != 0) { +#line 2914 + +#line 2914 + if (*xp < 0) { +#line 2914 +#ifdef ERANGE_FILL +#line 2914 + *tp = NC_FILL_UINT64; +#line 2914 +#endif +#line 2914 + status = NC_ERANGE; /* because tp is unsigned */ +#line 2914 + +#line 2914 +#ifdef ERANGE_FILL +#line 2914 + xp++; tp++; continue; +#line 2914 +#endif +#line 2914 + } +#line 2914 + *tp++ = (ulonglong) (signed) (*xp++); /* type cast from schar to ulonglong */ +#line 2914 + } +#line 2914 + +#line 2914 + *xpp = (const void *)xp; +#line 2914 + return status; +#line 2914 +} +#line 2914 + + +#line 2917 +int +ncx_pad_getn_schar_schar(const void **xpp, size_t nelems, schar *tp) +{ + size_t rndup = nelems % X_ALIGN; +#line 2920 + +#line 2920 + if (rndup) +#line 2920 + rndup = X_ALIGN - rndup; +#line 2920 + +#line 2920 + (void) memcpy(tp, *xpp, (size_t)nelems); +#line 2920 + *xpp = (void *)((char *)(*xpp) + nelems + rndup); +#line 2920 + +#line 2920 + return NC_NOERR; +#line 2920 + +} +int +#line 2922 +ncx_pad_getn_schar_uchar(const void **xpp, size_t nelems, uchar *tp) +#line 2922 +{ +#line 2922 + int status = NC_NOERR; +#line 2922 + size_t rndup = nelems % X_ALIGN; +#line 2922 + schar *xp = (schar *) *xpp; +#line 2922 + +#line 2922 + if (rndup) +#line 2922 + rndup = X_ALIGN - rndup; +#line 2922 + +#line 2922 + while (nelems-- != 0) { +#line 2922 + +#line 2922 + if (*xp < 0) { +#line 2922 +#ifdef ERANGE_FILL +#line 2922 + *tp = NC_FILL_UBYTE; +#line 2922 +#endif +#line 2922 + status = NC_ERANGE; /* because tp is unsigned */ +#line 2922 + +#line 2922 +#ifdef ERANGE_FILL +#line 2922 + xp++; tp++; continue; +#line 2922 +#endif +#line 2922 + } +#line 2922 + *tp++ = (uchar) (signed) (*xp++); /* type cast from schar to uchar */ +#line 2922 + } +#line 2922 + +#line 2922 + *xpp = (void *)(xp + rndup); +#line 2922 + return status; +#line 2922 +} +#line 2922 + +int +#line 2923 +ncx_pad_getn_schar_short(const void **xpp, size_t nelems, short *tp) +#line 2923 +{ +#line 2923 + int status = NC_NOERR; +#line 2923 + size_t rndup = nelems % X_ALIGN; +#line 2923 + schar *xp = (schar *) *xpp; +#line 2923 + +#line 2923 + if (rndup) +#line 2923 + rndup = X_ALIGN - rndup; +#line 2923 + +#line 2923 + while (nelems-- != 0) { +#line 2923 + +#line 2923 + *tp++ = (short) (*xp++); /* type cast from schar to short */ +#line 2923 + } +#line 2923 + +#line 2923 + *xpp = (void *)(xp + rndup); +#line 2923 + return status; +#line 2923 +} +#line 2923 + +int +#line 2924 +ncx_pad_getn_schar_int(const void **xpp, size_t nelems, int *tp) +#line 2924 +{ +#line 2924 + int status = NC_NOERR; +#line 2924 + size_t rndup = nelems % X_ALIGN; +#line 2924 + schar *xp = (schar *) *xpp; +#line 2924 + +#line 2924 + if (rndup) +#line 2924 + rndup = X_ALIGN - rndup; +#line 2924 + +#line 2924 + while (nelems-- != 0) { +#line 2924 + +#line 2924 + *tp++ = (int) (*xp++); /* type cast from schar to int */ +#line 2924 + } +#line 2924 + +#line 2924 + *xpp = (void *)(xp + rndup); +#line 2924 + return status; +#line 2924 +} +#line 2924 + +int +#line 2925 +ncx_pad_getn_schar_long(const void **xpp, size_t nelems, long *tp) +#line 2925 +{ +#line 2925 + int status = NC_NOERR; +#line 2925 + size_t rndup = nelems % X_ALIGN; +#line 2925 + schar *xp = (schar *) *xpp; +#line 2925 + +#line 2925 + if (rndup) +#line 2925 + rndup = X_ALIGN - rndup; +#line 2925 + +#line 2925 + while (nelems-- != 0) { +#line 2925 + +#line 2925 + *tp++ = (long) (*xp++); /* type cast from schar to long */ +#line 2925 + } +#line 2925 + +#line 2925 + *xpp = (void *)(xp + rndup); +#line 2925 + return status; +#line 2925 +} +#line 2925 + +int +#line 2926 +ncx_pad_getn_schar_float(const void **xpp, size_t nelems, float *tp) +#line 2926 +{ +#line 2926 + int status = NC_NOERR; +#line 2926 + size_t rndup = nelems % X_ALIGN; +#line 2926 + schar *xp = (schar *) *xpp; +#line 2926 + +#line 2926 + if (rndup) +#line 2926 + rndup = X_ALIGN - rndup; +#line 2926 + +#line 2926 + while (nelems-- != 0) { +#line 2926 + +#line 2926 + *tp++ = (float) (*xp++); /* type cast from schar to float */ +#line 2926 + } +#line 2926 + +#line 2926 + *xpp = (void *)(xp + rndup); +#line 2926 + return status; +#line 2926 +} +#line 2926 + +int +#line 2927 +ncx_pad_getn_schar_double(const void **xpp, size_t nelems, double *tp) +#line 2927 +{ +#line 2927 + int status = NC_NOERR; +#line 2927 + size_t rndup = nelems % X_ALIGN; +#line 2927 + schar *xp = (schar *) *xpp; +#line 2927 + +#line 2927 + if (rndup) +#line 2927 + rndup = X_ALIGN - rndup; +#line 2927 + +#line 2927 + while (nelems-- != 0) { +#line 2927 + +#line 2927 + *tp++ = (double) (*xp++); /* type cast from schar to double */ +#line 2927 + } +#line 2927 + +#line 2927 + *xpp = (void *)(xp + rndup); +#line 2927 + return status; +#line 2927 +} +#line 2927 + +int +#line 2928 +ncx_pad_getn_schar_longlong(const void **xpp, size_t nelems, longlong *tp) +#line 2928 +{ +#line 2928 + int status = NC_NOERR; +#line 2928 + size_t rndup = nelems % X_ALIGN; +#line 2928 + schar *xp = (schar *) *xpp; +#line 2928 + +#line 2928 + if (rndup) +#line 2928 + rndup = X_ALIGN - rndup; +#line 2928 + +#line 2928 + while (nelems-- != 0) { +#line 2928 + +#line 2928 + *tp++ = (longlong) (*xp++); /* type cast from schar to longlong */ +#line 2928 + } +#line 2928 + +#line 2928 + *xpp = (void *)(xp + rndup); +#line 2928 + return status; +#line 2928 +} +#line 2928 + +int +#line 2929 +ncx_pad_getn_schar_ushort(const void **xpp, size_t nelems, ushort *tp) +#line 2929 +{ +#line 2929 + int status = NC_NOERR; +#line 2929 + size_t rndup = nelems % X_ALIGN; +#line 2929 + schar *xp = (schar *) *xpp; +#line 2929 + +#line 2929 + if (rndup) +#line 2929 + rndup = X_ALIGN - rndup; +#line 2929 + +#line 2929 + while (nelems-- != 0) { +#line 2929 + +#line 2929 + if (*xp < 0) { +#line 2929 +#ifdef ERANGE_FILL +#line 2929 + *tp = NC_FILL_USHORT; +#line 2929 +#endif +#line 2929 + status = NC_ERANGE; /* because tp is unsigned */ +#line 2929 + +#line 2929 +#ifdef ERANGE_FILL +#line 2929 + xp++; tp++; continue; +#line 2929 +#endif +#line 2929 + } +#line 2929 + *tp++ = (ushort) (signed) (*xp++); /* type cast from schar to ushort */ +#line 2929 + } +#line 2929 + +#line 2929 + *xpp = (void *)(xp + rndup); +#line 2929 + return status; +#line 2929 +} +#line 2929 + +int +#line 2930 +ncx_pad_getn_schar_uint(const void **xpp, size_t nelems, uint *tp) +#line 2930 +{ +#line 2930 + int status = NC_NOERR; +#line 2930 + size_t rndup = nelems % X_ALIGN; +#line 2930 + schar *xp = (schar *) *xpp; +#line 2930 + +#line 2930 + if (rndup) +#line 2930 + rndup = X_ALIGN - rndup; +#line 2930 + +#line 2930 + while (nelems-- != 0) { +#line 2930 + +#line 2930 + if (*xp < 0) { +#line 2930 +#ifdef ERANGE_FILL +#line 2930 + *tp = NC_FILL_UINT; +#line 2930 +#endif +#line 2930 + status = NC_ERANGE; /* because tp is unsigned */ +#line 2930 + +#line 2930 +#ifdef ERANGE_FILL +#line 2930 + xp++; tp++; continue; +#line 2930 +#endif +#line 2930 + } +#line 2930 + *tp++ = (uint) (signed) (*xp++); /* type cast from schar to uint */ +#line 2930 + } +#line 2930 + +#line 2930 + *xpp = (void *)(xp + rndup); +#line 2930 + return status; +#line 2930 +} +#line 2930 + +int +#line 2931 +ncx_pad_getn_schar_ulonglong(const void **xpp, size_t nelems, ulonglong *tp) +#line 2931 +{ +#line 2931 + int status = NC_NOERR; +#line 2931 + size_t rndup = nelems % X_ALIGN; +#line 2931 + schar *xp = (schar *) *xpp; +#line 2931 + +#line 2931 + if (rndup) +#line 2931 + rndup = X_ALIGN - rndup; +#line 2931 + +#line 2931 + while (nelems-- != 0) { +#line 2931 + +#line 2931 + if (*xp < 0) { +#line 2931 +#ifdef ERANGE_FILL +#line 2931 + *tp = NC_FILL_UINT64; +#line 2931 +#endif +#line 2931 + status = NC_ERANGE; /* because tp is unsigned */ +#line 2931 + +#line 2931 +#ifdef ERANGE_FILL +#line 2931 + xp++; tp++; continue; +#line 2931 +#endif +#line 2931 + } +#line 2931 + *tp++ = (ulonglong) (signed) (*xp++); /* type cast from schar to ulonglong */ +#line 2931 + } +#line 2931 + +#line 2931 + *xpp = (void *)(xp + rndup); +#line 2931 + return status; +#line 2931 +} +#line 2931 + + +#line 2934 +int +ncx_putn_schar_schar(void **xpp, size_t nelems, const schar *tp, void *fillp) +{ + (void) memcpy(*xpp, tp, (size_t)nelems); +#line 2937 + *xpp = (void *)((char *)(*xpp) + nelems); +#line 2937 + +#line 2937 + return NC_NOERR; +#line 2937 + +} +int +#line 2939 +ncx_putn_schar_uchar(void **xpp, size_t nelems, const uchar *tp, void *fillp) +#line 2939 +{ +#line 2939 + int status = NC_NOERR; +#line 2939 + schar *xp = (schar *) *xpp; +#line 2939 + +#line 2939 + while (nelems-- != 0) { +#line 2939 + if (*tp > (uchar)X_SCHAR_MAX ) { +#line 2939 + +#line 2939 +#ifdef ERANGE_FILL +#line 2939 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2939 +#endif +#line 2939 + status = NC_ERANGE; +#line 2939 + +#line 2939 +#ifdef ERANGE_FILL +#line 2939 + xp++; tp++; continue; +#line 2939 +#endif +#line 2939 + } +#line 2939 + *xp++ = (schar) *tp++; /* type cast from uchar to schar */ +#line 2939 + } +#line 2939 + +#line 2939 + *xpp = (void *)xp; +#line 2939 + return status; +#line 2939 +} +#line 2939 + +int +#line 2940 +ncx_putn_schar_short(void **xpp, size_t nelems, const short *tp, void *fillp) +#line 2940 +{ +#line 2940 + int status = NC_NOERR; +#line 2940 + schar *xp = (schar *) *xpp; +#line 2940 + +#line 2940 + while (nelems-- != 0) { +#line 2940 + if (*tp > (short)X_SCHAR_MAX || *tp < X_SCHAR_MIN) { +#line 2940 + +#line 2940 +#ifdef ERANGE_FILL +#line 2940 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2940 +#endif +#line 2940 + status = NC_ERANGE; +#line 2940 + +#line 2940 +#ifdef ERANGE_FILL +#line 2940 + xp++; tp++; continue; +#line 2940 +#endif +#line 2940 + } +#line 2940 + *xp++ = (schar) *tp++; /* type cast from short to schar */ +#line 2940 + } +#line 2940 + +#line 2940 + *xpp = (void *)xp; +#line 2940 + return status; +#line 2940 +} +#line 2940 + +int +#line 2941 +ncx_putn_schar_int(void **xpp, size_t nelems, const int *tp, void *fillp) +#line 2941 +{ +#line 2941 + int status = NC_NOERR; +#line 2941 + schar *xp = (schar *) *xpp; +#line 2941 + +#line 2941 + while (nelems-- != 0) { +#line 2941 + if (*tp > (int)X_SCHAR_MAX || *tp < X_SCHAR_MIN) { +#line 2941 + +#line 2941 +#ifdef ERANGE_FILL +#line 2941 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2941 +#endif +#line 2941 + status = NC_ERANGE; +#line 2941 + +#line 2941 +#ifdef ERANGE_FILL +#line 2941 + xp++; tp++; continue; +#line 2941 +#endif +#line 2941 + } +#line 2941 + *xp++ = (schar) *tp++; /* type cast from int to schar */ +#line 2941 + } +#line 2941 + +#line 2941 + *xpp = (void *)xp; +#line 2941 + return status; +#line 2941 +} +#line 2941 + +int +#line 2942 +ncx_putn_schar_long(void **xpp, size_t nelems, const long *tp, void *fillp) +#line 2942 +{ +#line 2942 + int status = NC_NOERR; +#line 2942 + schar *xp = (schar *) *xpp; +#line 2942 + +#line 2942 + while (nelems-- != 0) { +#line 2942 + if (*tp > (long)X_SCHAR_MAX || *tp < X_SCHAR_MIN) { +#line 2942 + +#line 2942 +#ifdef ERANGE_FILL +#line 2942 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2942 +#endif +#line 2942 + status = NC_ERANGE; +#line 2942 + +#line 2942 +#ifdef ERANGE_FILL +#line 2942 + xp++; tp++; continue; +#line 2942 +#endif +#line 2942 + } +#line 2942 + *xp++ = (schar) *tp++; /* type cast from long to schar */ +#line 2942 + } +#line 2942 + +#line 2942 + *xpp = (void *)xp; +#line 2942 + return status; +#line 2942 +} +#line 2942 + +int +#line 2943 +ncx_putn_schar_float(void **xpp, size_t nelems, const float *tp, void *fillp) +#line 2943 +{ +#line 2943 + int status = NC_NOERR; +#line 2943 + schar *xp = (schar *) *xpp; +#line 2943 + +#line 2943 + while (nelems-- != 0) { +#line 2943 + if (*tp > (float)X_SCHAR_MAX || *tp < X_SCHAR_MIN) { +#line 2943 + +#line 2943 +#ifdef ERANGE_FILL +#line 2943 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2943 +#endif +#line 2943 + status = NC_ERANGE; +#line 2943 + +#line 2943 +#ifdef ERANGE_FILL +#line 2943 + xp++; tp++; continue; +#line 2943 +#endif +#line 2943 + } +#line 2943 + *xp++ = (schar) *tp++; /* type cast from float to schar */ +#line 2943 + } +#line 2943 + +#line 2943 + *xpp = (void *)xp; +#line 2943 + return status; +#line 2943 +} +#line 2943 + +int +#line 2944 +ncx_putn_schar_double(void **xpp, size_t nelems, const double *tp, void *fillp) +#line 2944 +{ +#line 2944 + int status = NC_NOERR; +#line 2944 + schar *xp = (schar *) *xpp; +#line 2944 + +#line 2944 + while (nelems-- != 0) { +#line 2944 + if (*tp > (double)X_SCHAR_MAX || *tp < X_SCHAR_MIN) { +#line 2944 + +#line 2944 +#ifdef ERANGE_FILL +#line 2944 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2944 +#endif +#line 2944 + status = NC_ERANGE; +#line 2944 + +#line 2944 +#ifdef ERANGE_FILL +#line 2944 + xp++; tp++; continue; +#line 2944 +#endif +#line 2944 + } +#line 2944 + *xp++ = (schar) *tp++; /* type cast from double to schar */ +#line 2944 + } +#line 2944 + +#line 2944 + *xpp = (void *)xp; +#line 2944 + return status; +#line 2944 +} +#line 2944 + +int +#line 2945 +ncx_putn_schar_longlong(void **xpp, size_t nelems, const longlong *tp, void *fillp) +#line 2945 +{ +#line 2945 + int status = NC_NOERR; +#line 2945 + schar *xp = (schar *) *xpp; +#line 2945 + +#line 2945 + while (nelems-- != 0) { +#line 2945 + if (*tp > (longlong)X_SCHAR_MAX || *tp < X_SCHAR_MIN) { +#line 2945 + +#line 2945 +#ifdef ERANGE_FILL +#line 2945 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2945 +#endif +#line 2945 + status = NC_ERANGE; +#line 2945 + +#line 2945 +#ifdef ERANGE_FILL +#line 2945 + xp++; tp++; continue; +#line 2945 +#endif +#line 2945 + } +#line 2945 + *xp++ = (schar) *tp++; /* type cast from longlong to schar */ +#line 2945 + } +#line 2945 + +#line 2945 + *xpp = (void *)xp; +#line 2945 + return status; +#line 2945 +} +#line 2945 + +int +#line 2946 +ncx_putn_schar_ushort(void **xpp, size_t nelems, const ushort *tp, void *fillp) +#line 2946 +{ +#line 2946 + int status = NC_NOERR; +#line 2946 + schar *xp = (schar *) *xpp; +#line 2946 + +#line 2946 + while (nelems-- != 0) { +#line 2946 + if (*tp > (ushort)X_SCHAR_MAX ) { +#line 2946 + +#line 2946 +#ifdef ERANGE_FILL +#line 2946 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2946 +#endif +#line 2946 + status = NC_ERANGE; +#line 2946 + +#line 2946 +#ifdef ERANGE_FILL +#line 2946 + xp++; tp++; continue; +#line 2946 +#endif +#line 2946 + } +#line 2946 + *xp++ = (schar) *tp++; /* type cast from ushort to schar */ +#line 2946 + } +#line 2946 + +#line 2946 + *xpp = (void *)xp; +#line 2946 + return status; +#line 2946 +} +#line 2946 + +int +#line 2947 +ncx_putn_schar_uint(void **xpp, size_t nelems, const uint *tp, void *fillp) +#line 2947 +{ +#line 2947 + int status = NC_NOERR; +#line 2947 + schar *xp = (schar *) *xpp; +#line 2947 + +#line 2947 + while (nelems-- != 0) { +#line 2947 + if (*tp > (uint)X_SCHAR_MAX ) { +#line 2947 + +#line 2947 +#ifdef ERANGE_FILL +#line 2947 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2947 +#endif +#line 2947 + status = NC_ERANGE; +#line 2947 + +#line 2947 +#ifdef ERANGE_FILL +#line 2947 + xp++; tp++; continue; +#line 2947 +#endif +#line 2947 + } +#line 2947 + *xp++ = (schar) *tp++; /* type cast from uint to schar */ +#line 2947 + } +#line 2947 + +#line 2947 + *xpp = (void *)xp; +#line 2947 + return status; +#line 2947 +} +#line 2947 + +int +#line 2948 +ncx_putn_schar_ulonglong(void **xpp, size_t nelems, const ulonglong *tp, void *fillp) +#line 2948 +{ +#line 2948 + int status = NC_NOERR; +#line 2948 + schar *xp = (schar *) *xpp; +#line 2948 + +#line 2948 + while (nelems-- != 0) { +#line 2948 + if (*tp > (ulonglong)X_SCHAR_MAX ) { +#line 2948 + +#line 2948 +#ifdef ERANGE_FILL +#line 2948 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2948 +#endif +#line 2948 + status = NC_ERANGE; +#line 2948 + +#line 2948 +#ifdef ERANGE_FILL +#line 2948 + xp++; tp++; continue; +#line 2948 +#endif +#line 2948 + } +#line 2948 + *xp++ = (schar) *tp++; /* type cast from ulonglong to schar */ +#line 2948 + } +#line 2948 + +#line 2948 + *xpp = (void *)xp; +#line 2948 + return status; +#line 2948 +} +#line 2948 + + +#line 2951 +int +ncx_pad_putn_schar_schar(void **xpp, size_t nelems, const schar *tp, void *fillp) +{ + size_t rndup = nelems % X_ALIGN; +#line 2954 + +#line 2954 + if (rndup) +#line 2954 + rndup = X_ALIGN - rndup; +#line 2954 + +#line 2954 + (void) memcpy(*xpp, tp, (size_t)nelems); +#line 2954 + *xpp = (void *)((char *)(*xpp) + nelems); +#line 2954 + +#line 2954 + if (rndup) +#line 2954 + { +#line 2954 + (void) memcpy(*xpp, nada, (size_t)rndup); +#line 2954 + *xpp = (void *)((char *)(*xpp) + rndup); +#line 2954 + } +#line 2954 + +#line 2954 + return NC_NOERR; +#line 2954 + +} +int +#line 2956 +ncx_pad_putn_schar_uchar(void **xpp, size_t nelems, const uchar *tp, void *fillp) +#line 2956 +{ +#line 2956 + int status = NC_NOERR; +#line 2956 + size_t rndup = nelems % X_ALIGN; +#line 2956 + schar *xp = (schar *) *xpp; +#line 2956 + +#line 2956 + if (rndup) rndup = X_ALIGN - rndup; +#line 2956 + +#line 2956 + while (nelems-- != 0) { +#line 2956 + if (*tp > (uchar)X_SCHAR_MAX ) { +#line 2956 + +#line 2956 +#ifdef ERANGE_FILL +#line 2956 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2956 +#endif +#line 2956 + status = NC_ERANGE; +#line 2956 + +#line 2956 +#ifdef ERANGE_FILL +#line 2956 + xp++; tp++; continue; +#line 2956 +#endif +#line 2956 + } +#line 2956 + *xp++ = (schar) *tp++; /* type cast from uchar to schar */ +#line 2956 + } +#line 2956 + +#line 2956 + +#line 2956 + if (rndup) { +#line 2956 + (void) memcpy(xp, nada, (size_t)rndup); +#line 2956 + xp += rndup; +#line 2956 + } +#line 2956 + +#line 2956 + *xpp = (void *)xp; +#line 2956 + return status; +#line 2956 +} +#line 2956 + +int +#line 2957 +ncx_pad_putn_schar_short(void **xpp, size_t nelems, const short *tp, void *fillp) +#line 2957 +{ +#line 2957 + int status = NC_NOERR; +#line 2957 + size_t rndup = nelems % X_ALIGN; +#line 2957 + schar *xp = (schar *) *xpp; +#line 2957 + +#line 2957 + if (rndup) rndup = X_ALIGN - rndup; +#line 2957 + +#line 2957 + while (nelems-- != 0) { +#line 2957 + if (*tp > (short)X_SCHAR_MAX || *tp < X_SCHAR_MIN) { +#line 2957 + +#line 2957 +#ifdef ERANGE_FILL +#line 2957 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2957 +#endif +#line 2957 + status = NC_ERANGE; +#line 2957 + +#line 2957 +#ifdef ERANGE_FILL +#line 2957 + xp++; tp++; continue; +#line 2957 +#endif +#line 2957 + } +#line 2957 + *xp++ = (schar) *tp++; /* type cast from short to schar */ +#line 2957 + } +#line 2957 + +#line 2957 + +#line 2957 + if (rndup) { +#line 2957 + (void) memcpy(xp, nada, (size_t)rndup); +#line 2957 + xp += rndup; +#line 2957 + } +#line 2957 + +#line 2957 + *xpp = (void *)xp; +#line 2957 + return status; +#line 2957 +} +#line 2957 + +int +#line 2958 +ncx_pad_putn_schar_int(void **xpp, size_t nelems, const int *tp, void *fillp) +#line 2958 +{ +#line 2958 + int status = NC_NOERR; +#line 2958 + size_t rndup = nelems % X_ALIGN; +#line 2958 + schar *xp = (schar *) *xpp; +#line 2958 + +#line 2958 + if (rndup) rndup = X_ALIGN - rndup; +#line 2958 + +#line 2958 + while (nelems-- != 0) { +#line 2958 + if (*tp > (int)X_SCHAR_MAX || *tp < X_SCHAR_MIN) { +#line 2958 + +#line 2958 +#ifdef ERANGE_FILL +#line 2958 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2958 +#endif +#line 2958 + status = NC_ERANGE; +#line 2958 + +#line 2958 +#ifdef ERANGE_FILL +#line 2958 + xp++; tp++; continue; +#line 2958 +#endif +#line 2958 + } +#line 2958 + *xp++ = (schar) *tp++; /* type cast from int to schar */ +#line 2958 + } +#line 2958 + +#line 2958 + +#line 2958 + if (rndup) { +#line 2958 + (void) memcpy(xp, nada, (size_t)rndup); +#line 2958 + xp += rndup; +#line 2958 + } +#line 2958 + +#line 2958 + *xpp = (void *)xp; +#line 2958 + return status; +#line 2958 +} +#line 2958 + +int +#line 2959 +ncx_pad_putn_schar_long(void **xpp, size_t nelems, const long *tp, void *fillp) +#line 2959 +{ +#line 2959 + int status = NC_NOERR; +#line 2959 + size_t rndup = nelems % X_ALIGN; +#line 2959 + schar *xp = (schar *) *xpp; +#line 2959 + +#line 2959 + if (rndup) rndup = X_ALIGN - rndup; +#line 2959 + +#line 2959 + while (nelems-- != 0) { +#line 2959 + if (*tp > (long)X_SCHAR_MAX || *tp < X_SCHAR_MIN) { +#line 2959 + +#line 2959 +#ifdef ERANGE_FILL +#line 2959 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2959 +#endif +#line 2959 + status = NC_ERANGE; +#line 2959 + +#line 2959 +#ifdef ERANGE_FILL +#line 2959 + xp++; tp++; continue; +#line 2959 +#endif +#line 2959 + } +#line 2959 + *xp++ = (schar) *tp++; /* type cast from long to schar */ +#line 2959 + } +#line 2959 + +#line 2959 + +#line 2959 + if (rndup) { +#line 2959 + (void) memcpy(xp, nada, (size_t)rndup); +#line 2959 + xp += rndup; +#line 2959 + } +#line 2959 + +#line 2959 + *xpp = (void *)xp; +#line 2959 + return status; +#line 2959 +} +#line 2959 + +int +#line 2960 +ncx_pad_putn_schar_float(void **xpp, size_t nelems, const float *tp, void *fillp) +#line 2960 +{ +#line 2960 + int status = NC_NOERR; +#line 2960 + size_t rndup = nelems % X_ALIGN; +#line 2960 + schar *xp = (schar *) *xpp; +#line 2960 + +#line 2960 + if (rndup) rndup = X_ALIGN - rndup; +#line 2960 + +#line 2960 + while (nelems-- != 0) { +#line 2960 + if (*tp > (float)X_SCHAR_MAX || *tp < X_SCHAR_MIN) { +#line 2960 + +#line 2960 +#ifdef ERANGE_FILL +#line 2960 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2960 +#endif +#line 2960 + status = NC_ERANGE; +#line 2960 + +#line 2960 +#ifdef ERANGE_FILL +#line 2960 + xp++; tp++; continue; +#line 2960 +#endif +#line 2960 + } +#line 2960 + *xp++ = (schar) *tp++; /* type cast from float to schar */ +#line 2960 + } +#line 2960 + +#line 2960 + +#line 2960 + if (rndup) { +#line 2960 + (void) memcpy(xp, nada, (size_t)rndup); +#line 2960 + xp += rndup; +#line 2960 + } +#line 2960 + +#line 2960 + *xpp = (void *)xp; +#line 2960 + return status; +#line 2960 +} +#line 2960 + +int +#line 2961 +ncx_pad_putn_schar_double(void **xpp, size_t nelems, const double *tp, void *fillp) +#line 2961 +{ +#line 2961 + int status = NC_NOERR; +#line 2961 + size_t rndup = nelems % X_ALIGN; +#line 2961 + schar *xp = (schar *) *xpp; +#line 2961 + +#line 2961 + if (rndup) rndup = X_ALIGN - rndup; +#line 2961 + +#line 2961 + while (nelems-- != 0) { +#line 2961 + if (*tp > (double)X_SCHAR_MAX || *tp < X_SCHAR_MIN) { +#line 2961 + +#line 2961 +#ifdef ERANGE_FILL +#line 2961 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2961 +#endif +#line 2961 + status = NC_ERANGE; +#line 2961 + +#line 2961 +#ifdef ERANGE_FILL +#line 2961 + xp++; tp++; continue; +#line 2961 +#endif +#line 2961 + } +#line 2961 + *xp++ = (schar) *tp++; /* type cast from double to schar */ +#line 2961 + } +#line 2961 + +#line 2961 + +#line 2961 + if (rndup) { +#line 2961 + (void) memcpy(xp, nada, (size_t)rndup); +#line 2961 + xp += rndup; +#line 2961 + } +#line 2961 + +#line 2961 + *xpp = (void *)xp; +#line 2961 + return status; +#line 2961 +} +#line 2961 + +int +#line 2962 +ncx_pad_putn_schar_longlong(void **xpp, size_t nelems, const longlong *tp, void *fillp) +#line 2962 +{ +#line 2962 + int status = NC_NOERR; +#line 2962 + size_t rndup = nelems % X_ALIGN; +#line 2962 + schar *xp = (schar *) *xpp; +#line 2962 + +#line 2962 + if (rndup) rndup = X_ALIGN - rndup; +#line 2962 + +#line 2962 + while (nelems-- != 0) { +#line 2962 + if (*tp > (longlong)X_SCHAR_MAX || *tp < X_SCHAR_MIN) { +#line 2962 + +#line 2962 +#ifdef ERANGE_FILL +#line 2962 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2962 +#endif +#line 2962 + status = NC_ERANGE; +#line 2962 + +#line 2962 +#ifdef ERANGE_FILL +#line 2962 + xp++; tp++; continue; +#line 2962 +#endif +#line 2962 + } +#line 2962 + *xp++ = (schar) *tp++; /* type cast from longlong to schar */ +#line 2962 + } +#line 2962 + +#line 2962 + +#line 2962 + if (rndup) { +#line 2962 + (void) memcpy(xp, nada, (size_t)rndup); +#line 2962 + xp += rndup; +#line 2962 + } +#line 2962 + +#line 2962 + *xpp = (void *)xp; +#line 2962 + return status; +#line 2962 +} +#line 2962 + +int +#line 2963 +ncx_pad_putn_schar_ushort(void **xpp, size_t nelems, const ushort *tp, void *fillp) +#line 2963 +{ +#line 2963 + int status = NC_NOERR; +#line 2963 + size_t rndup = nelems % X_ALIGN; +#line 2963 + schar *xp = (schar *) *xpp; +#line 2963 + +#line 2963 + if (rndup) rndup = X_ALIGN - rndup; +#line 2963 + +#line 2963 + while (nelems-- != 0) { +#line 2963 + if (*tp > (ushort)X_SCHAR_MAX ) { +#line 2963 + +#line 2963 +#ifdef ERANGE_FILL +#line 2963 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2963 +#endif +#line 2963 + status = NC_ERANGE; +#line 2963 + +#line 2963 +#ifdef ERANGE_FILL +#line 2963 + xp++; tp++; continue; +#line 2963 +#endif +#line 2963 + } +#line 2963 + *xp++ = (schar) *tp++; /* type cast from ushort to schar */ +#line 2963 + } +#line 2963 + +#line 2963 + +#line 2963 + if (rndup) { +#line 2963 + (void) memcpy(xp, nada, (size_t)rndup); +#line 2963 + xp += rndup; +#line 2963 + } +#line 2963 + +#line 2963 + *xpp = (void *)xp; +#line 2963 + return status; +#line 2963 +} +#line 2963 + +int +#line 2964 +ncx_pad_putn_schar_uint(void **xpp, size_t nelems, const uint *tp, void *fillp) +#line 2964 +{ +#line 2964 + int status = NC_NOERR; +#line 2964 + size_t rndup = nelems % X_ALIGN; +#line 2964 + schar *xp = (schar *) *xpp; +#line 2964 + +#line 2964 + if (rndup) rndup = X_ALIGN - rndup; +#line 2964 + +#line 2964 + while (nelems-- != 0) { +#line 2964 + if (*tp > (uint)X_SCHAR_MAX ) { +#line 2964 + +#line 2964 +#ifdef ERANGE_FILL +#line 2964 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2964 +#endif +#line 2964 + status = NC_ERANGE; +#line 2964 + +#line 2964 +#ifdef ERANGE_FILL +#line 2964 + xp++; tp++; continue; +#line 2964 +#endif +#line 2964 + } +#line 2964 + *xp++ = (schar) *tp++; /* type cast from uint to schar */ +#line 2964 + } +#line 2964 + +#line 2964 + +#line 2964 + if (rndup) { +#line 2964 + (void) memcpy(xp, nada, (size_t)rndup); +#line 2964 + xp += rndup; +#line 2964 + } +#line 2964 + +#line 2964 + *xpp = (void *)xp; +#line 2964 + return status; +#line 2964 +} +#line 2964 + +int +#line 2965 +ncx_pad_putn_schar_ulonglong(void **xpp, size_t nelems, const ulonglong *tp, void *fillp) +#line 2965 +{ +#line 2965 + int status = NC_NOERR; +#line 2965 + size_t rndup = nelems % X_ALIGN; +#line 2965 + schar *xp = (schar *) *xpp; +#line 2965 + +#line 2965 + if (rndup) rndup = X_ALIGN - rndup; +#line 2965 + +#line 2965 + while (nelems-- != 0) { +#line 2965 + if (*tp > (ulonglong)X_SCHAR_MAX ) { +#line 2965 + +#line 2965 +#ifdef ERANGE_FILL +#line 2965 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 2965 +#endif +#line 2965 + status = NC_ERANGE; +#line 2965 + +#line 2965 +#ifdef ERANGE_FILL +#line 2965 + xp++; tp++; continue; +#line 2965 +#endif +#line 2965 + } +#line 2965 + *xp++ = (schar) *tp++; /* type cast from ulonglong to schar */ +#line 2965 + } +#line 2965 + +#line 2965 + +#line 2965 + if (rndup) { +#line 2965 + (void) memcpy(xp, nada, (size_t)rndup); +#line 2965 + xp += rndup; +#line 2965 + } +#line 2965 + +#line 2965 + *xpp = (void *)xp; +#line 2965 + return status; +#line 2965 +} +#line 2965 + + + +/* uchar ---------------------------------------------------------------------*/ +#line 2971 +int +ncx_getn_uchar_schar(const void **xpp, size_t nelems, schar *tp) +{ + int status = NC_NOERR; + uchar *xp = (uchar *)(*xpp); + + while (nelems-- != 0) { + if (*xp > SCHAR_MAX) { + *tp = NC_FILL_BYTE; + status = NC_ERANGE; + +#line 2981 +#ifdef ERANGE_FILL +#line 2981 + xp++; tp++; continue; +#line 2981 +#endif + } + *tp++ = (schar) *xp++; /* type cast from uchar to schar */ + } + + *xpp = (const void *)xp; + return status; +} +#line 2990 +int +ncx_getn_uchar_uchar(const void **xpp, size_t nelems, uchar *tp) +{ + (void) memcpy(tp, *xpp, (size_t)nelems); +#line 2993 + *xpp = (void *)((char *)(*xpp) + nelems); +#line 2993 + return NC_NOERR; +#line 2993 + +} +int +#line 2995 +ncx_getn_uchar_short(const void **xpp, size_t nelems, short *tp) +#line 2995 +{ +#line 2995 + int status = NC_NOERR; +#line 2995 + uchar *xp = (uchar *)(*xpp); +#line 2995 + +#line 2995 + while (nelems-- != 0) { +#line 2995 + +#line 2995 + *tp++ = (short) (*xp++); /* type cast from uchar to short */ +#line 2995 + } +#line 2995 + +#line 2995 + *xpp = (const void *)xp; +#line 2995 + return status; +#line 2995 +} +#line 2995 + +int +#line 2996 +ncx_getn_uchar_int(const void **xpp, size_t nelems, int *tp) +#line 2996 +{ +#line 2996 + int status = NC_NOERR; +#line 2996 + uchar *xp = (uchar *)(*xpp); +#line 2996 + +#line 2996 + while (nelems-- != 0) { +#line 2996 + +#line 2996 + *tp++ = (int) (*xp++); /* type cast from uchar to int */ +#line 2996 + } +#line 2996 + +#line 2996 + *xpp = (const void *)xp; +#line 2996 + return status; +#line 2996 +} +#line 2996 + +int +#line 2997 +ncx_getn_uchar_long(const void **xpp, size_t nelems, long *tp) +#line 2997 +{ +#line 2997 + int status = NC_NOERR; +#line 2997 + uchar *xp = (uchar *)(*xpp); +#line 2997 + +#line 2997 + while (nelems-- != 0) { +#line 2997 + +#line 2997 + *tp++ = (long) (*xp++); /* type cast from uchar to long */ +#line 2997 + } +#line 2997 + +#line 2997 + *xpp = (const void *)xp; +#line 2997 + return status; +#line 2997 +} +#line 2997 + +int +#line 2998 +ncx_getn_uchar_float(const void **xpp, size_t nelems, float *tp) +#line 2998 +{ +#line 2998 + int status = NC_NOERR; +#line 2998 + uchar *xp = (uchar *)(*xpp); +#line 2998 + +#line 2998 + while (nelems-- != 0) { +#line 2998 + +#line 2998 + *tp++ = (float) (*xp++); /* type cast from uchar to float */ +#line 2998 + } +#line 2998 + +#line 2998 + *xpp = (const void *)xp; +#line 2998 + return status; +#line 2998 +} +#line 2998 + +int +#line 2999 +ncx_getn_uchar_double(const void **xpp, size_t nelems, double *tp) +#line 2999 +{ +#line 2999 + int status = NC_NOERR; +#line 2999 + uchar *xp = (uchar *)(*xpp); +#line 2999 + +#line 2999 + while (nelems-- != 0) { +#line 2999 + +#line 2999 + *tp++ = (double) (*xp++); /* type cast from uchar to double */ +#line 2999 + } +#line 2999 + +#line 2999 + *xpp = (const void *)xp; +#line 2999 + return status; +#line 2999 +} +#line 2999 + +int +#line 3000 +ncx_getn_uchar_longlong(const void **xpp, size_t nelems, longlong *tp) +#line 3000 +{ +#line 3000 + int status = NC_NOERR; +#line 3000 + uchar *xp = (uchar *)(*xpp); +#line 3000 + +#line 3000 + while (nelems-- != 0) { +#line 3000 + +#line 3000 + *tp++ = (longlong) (*xp++); /* type cast from uchar to longlong */ +#line 3000 + } +#line 3000 + +#line 3000 + *xpp = (const void *)xp; +#line 3000 + return status; +#line 3000 +} +#line 3000 + +int +#line 3001 +ncx_getn_uchar_ushort(const void **xpp, size_t nelems, ushort *tp) +#line 3001 +{ +#line 3001 + int status = NC_NOERR; +#line 3001 + uchar *xp = (uchar *)(*xpp); +#line 3001 + +#line 3001 + while (nelems-- != 0) { +#line 3001 + +#line 3001 + *tp++ = (ushort) (*xp++); /* type cast from uchar to ushort */ +#line 3001 + } +#line 3001 + +#line 3001 + *xpp = (const void *)xp; +#line 3001 + return status; +#line 3001 +} +#line 3001 + +int +#line 3002 +ncx_getn_uchar_uint(const void **xpp, size_t nelems, uint *tp) +#line 3002 +{ +#line 3002 + int status = NC_NOERR; +#line 3002 + uchar *xp = (uchar *)(*xpp); +#line 3002 + +#line 3002 + while (nelems-- != 0) { +#line 3002 + +#line 3002 + *tp++ = (uint) (*xp++); /* type cast from uchar to uint */ +#line 3002 + } +#line 3002 + +#line 3002 + *xpp = (const void *)xp; +#line 3002 + return status; +#line 3002 +} +#line 3002 + +int +#line 3003 +ncx_getn_uchar_ulonglong(const void **xpp, size_t nelems, ulonglong *tp) +#line 3003 +{ +#line 3003 + int status = NC_NOERR; +#line 3003 + uchar *xp = (uchar *)(*xpp); +#line 3003 + +#line 3003 + while (nelems-- != 0) { +#line 3003 + +#line 3003 + *tp++ = (ulonglong) (*xp++); /* type cast from uchar to ulonglong */ +#line 3003 + } +#line 3003 + +#line 3003 + *xpp = (const void *)xp; +#line 3003 + return status; +#line 3003 +} +#line 3003 + + +#line 3006 +int +ncx_pad_getn_uchar_schar(const void **xpp, size_t nelems, schar *tp) +{ + int status = NC_NOERR; + size_t rndup = nelems % X_ALIGN; + uchar *xp = (uchar *) *xpp; + + if (rndup) rndup = X_ALIGN - rndup; + + while (nelems-- != 0) { + if (*xp > SCHAR_MAX) { + *tp = NC_FILL_BYTE; + status = NC_ERANGE; + +#line 3019 +#ifdef ERANGE_FILL +#line 3019 + xp++; tp++; continue; +#line 3019 +#endif + } + *tp++ = (schar) *xp++; /* type cast from uchar to schar */ + } + + *xpp = (void *)(xp + rndup); + return status; +} +#line 3028 +int +ncx_pad_getn_uchar_uchar(const void **xpp, size_t nelems, uchar *tp) +{ + size_t rndup = nelems % X_ALIGN; +#line 3031 + +#line 3031 + if (rndup) +#line 3031 + rndup = X_ALIGN - rndup; +#line 3031 + +#line 3031 + (void) memcpy(tp, *xpp, (size_t)nelems); +#line 3031 + *xpp = (void *)((char *)(*xpp) + nelems + rndup); +#line 3031 + +#line 3031 + return NC_NOERR; +#line 3031 + +} +int +#line 3033 +ncx_pad_getn_uchar_short(const void **xpp, size_t nelems, short *tp) +#line 3033 +{ +#line 3033 + int status = NC_NOERR; +#line 3033 + size_t rndup = nelems % X_ALIGN; +#line 3033 + uchar *xp = (uchar *) *xpp; +#line 3033 + +#line 3033 + if (rndup) +#line 3033 + rndup = X_ALIGN - rndup; +#line 3033 + +#line 3033 + while (nelems-- != 0) { +#line 3033 + +#line 3033 + *tp++ = (short) (*xp++); /* type cast from uchar to short */ +#line 3033 + } +#line 3033 + +#line 3033 + *xpp = (void *)(xp + rndup); +#line 3033 + return status; +#line 3033 +} +#line 3033 + +int +#line 3034 +ncx_pad_getn_uchar_int(const void **xpp, size_t nelems, int *tp) +#line 3034 +{ +#line 3034 + int status = NC_NOERR; +#line 3034 + size_t rndup = nelems % X_ALIGN; +#line 3034 + uchar *xp = (uchar *) *xpp; +#line 3034 + +#line 3034 + if (rndup) +#line 3034 + rndup = X_ALIGN - rndup; +#line 3034 + +#line 3034 + while (nelems-- != 0) { +#line 3034 + +#line 3034 + *tp++ = (int) (*xp++); /* type cast from uchar to int */ +#line 3034 + } +#line 3034 + +#line 3034 + *xpp = (void *)(xp + rndup); +#line 3034 + return status; +#line 3034 +} +#line 3034 + +int +#line 3035 +ncx_pad_getn_uchar_long(const void **xpp, size_t nelems, long *tp) +#line 3035 +{ +#line 3035 + int status = NC_NOERR; +#line 3035 + size_t rndup = nelems % X_ALIGN; +#line 3035 + uchar *xp = (uchar *) *xpp; +#line 3035 + +#line 3035 + if (rndup) +#line 3035 + rndup = X_ALIGN - rndup; +#line 3035 + +#line 3035 + while (nelems-- != 0) { +#line 3035 + +#line 3035 + *tp++ = (long) (*xp++); /* type cast from uchar to long */ +#line 3035 + } +#line 3035 + +#line 3035 + *xpp = (void *)(xp + rndup); +#line 3035 + return status; +#line 3035 +} +#line 3035 + +int +#line 3036 +ncx_pad_getn_uchar_float(const void **xpp, size_t nelems, float *tp) +#line 3036 +{ +#line 3036 + int status = NC_NOERR; +#line 3036 + size_t rndup = nelems % X_ALIGN; +#line 3036 + uchar *xp = (uchar *) *xpp; +#line 3036 + +#line 3036 + if (rndup) +#line 3036 + rndup = X_ALIGN - rndup; +#line 3036 + +#line 3036 + while (nelems-- != 0) { +#line 3036 + +#line 3036 + *tp++ = (float) (*xp++); /* type cast from uchar to float */ +#line 3036 + } +#line 3036 + +#line 3036 + *xpp = (void *)(xp + rndup); +#line 3036 + return status; +#line 3036 +} +#line 3036 + +int +#line 3037 +ncx_pad_getn_uchar_double(const void **xpp, size_t nelems, double *tp) +#line 3037 +{ +#line 3037 + int status = NC_NOERR; +#line 3037 + size_t rndup = nelems % X_ALIGN; +#line 3037 + uchar *xp = (uchar *) *xpp; +#line 3037 + +#line 3037 + if (rndup) +#line 3037 + rndup = X_ALIGN - rndup; +#line 3037 + +#line 3037 + while (nelems-- != 0) { +#line 3037 + +#line 3037 + *tp++ = (double) (*xp++); /* type cast from uchar to double */ +#line 3037 + } +#line 3037 + +#line 3037 + *xpp = (void *)(xp + rndup); +#line 3037 + return status; +#line 3037 +} +#line 3037 + +int +#line 3038 +ncx_pad_getn_uchar_longlong(const void **xpp, size_t nelems, longlong *tp) +#line 3038 +{ +#line 3038 + int status = NC_NOERR; +#line 3038 + size_t rndup = nelems % X_ALIGN; +#line 3038 + uchar *xp = (uchar *) *xpp; +#line 3038 + +#line 3038 + if (rndup) +#line 3038 + rndup = X_ALIGN - rndup; +#line 3038 + +#line 3038 + while (nelems-- != 0) { +#line 3038 + +#line 3038 + *tp++ = (longlong) (*xp++); /* type cast from uchar to longlong */ +#line 3038 + } +#line 3038 + +#line 3038 + *xpp = (void *)(xp + rndup); +#line 3038 + return status; +#line 3038 +} +#line 3038 + +int +#line 3039 +ncx_pad_getn_uchar_ushort(const void **xpp, size_t nelems, ushort *tp) +#line 3039 +{ +#line 3039 + int status = NC_NOERR; +#line 3039 + size_t rndup = nelems % X_ALIGN; +#line 3039 + uchar *xp = (uchar *) *xpp; +#line 3039 + +#line 3039 + if (rndup) +#line 3039 + rndup = X_ALIGN - rndup; +#line 3039 + +#line 3039 + while (nelems-- != 0) { +#line 3039 + +#line 3039 + *tp++ = (ushort) (*xp++); /* type cast from uchar to ushort */ +#line 3039 + } +#line 3039 + +#line 3039 + *xpp = (void *)(xp + rndup); +#line 3039 + return status; +#line 3039 +} +#line 3039 + +int +#line 3040 +ncx_pad_getn_uchar_uint(const void **xpp, size_t nelems, uint *tp) +#line 3040 +{ +#line 3040 + int status = NC_NOERR; +#line 3040 + size_t rndup = nelems % X_ALIGN; +#line 3040 + uchar *xp = (uchar *) *xpp; +#line 3040 + +#line 3040 + if (rndup) +#line 3040 + rndup = X_ALIGN - rndup; +#line 3040 + +#line 3040 + while (nelems-- != 0) { +#line 3040 + +#line 3040 + *tp++ = (uint) (*xp++); /* type cast from uchar to uint */ +#line 3040 + } +#line 3040 + +#line 3040 + *xpp = (void *)(xp + rndup); +#line 3040 + return status; +#line 3040 +} +#line 3040 + +int +#line 3041 +ncx_pad_getn_uchar_ulonglong(const void **xpp, size_t nelems, ulonglong *tp) +#line 3041 +{ +#line 3041 + int status = NC_NOERR; +#line 3041 + size_t rndup = nelems % X_ALIGN; +#line 3041 + uchar *xp = (uchar *) *xpp; +#line 3041 + +#line 3041 + if (rndup) +#line 3041 + rndup = X_ALIGN - rndup; +#line 3041 + +#line 3041 + while (nelems-- != 0) { +#line 3041 + +#line 3041 + *tp++ = (ulonglong) (*xp++); /* type cast from uchar to ulonglong */ +#line 3041 + } +#line 3041 + +#line 3041 + *xpp = (void *)(xp + rndup); +#line 3041 + return status; +#line 3041 +} +#line 3041 + + +#line 3044 +int +ncx_putn_uchar_schar(void **xpp, size_t nelems, const schar *tp, void *fillp) +{ + int status = NC_NOERR; + uchar *xp = (uchar *) *xpp; + + while (nelems-- != 0) { + if (*tp < 0) { + +#line 3052 +#ifdef ERANGE_FILL +#line 3052 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3052 +#endif + status = NC_ERANGE; + +#line 3054 +#ifdef ERANGE_FILL +#line 3054 + xp++; tp++; continue; +#line 3054 +#endif + } + *xp++ = (uchar) (signed) *tp++; /* type cast from schar to uchar */ + } + + *xpp = (void *)xp; + return status; +} +#line 3063 +int +ncx_putn_uchar_uchar(void **xpp, size_t nelems, const uchar *tp, void *fillp) +{ + (void) memcpy(*xpp, tp, (size_t)nelems); +#line 3066 + *xpp = (void *)((char *)(*xpp) + nelems); +#line 3066 + +#line 3066 + return NC_NOERR; +#line 3066 + +} +int +#line 3068 +ncx_putn_uchar_short(void **xpp, size_t nelems, const short *tp, void *fillp) +#line 3068 +{ +#line 3068 + int status = NC_NOERR; +#line 3068 + uchar *xp = (uchar *) *xpp; +#line 3068 + +#line 3068 + while (nelems-- != 0) { +#line 3068 + if (*tp > (short)X_UCHAR_MAX || *tp < 0) { +#line 3068 + +#line 3068 +#ifdef ERANGE_FILL +#line 3068 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3068 +#endif +#line 3068 + status = NC_ERANGE; +#line 3068 + +#line 3068 +#ifdef ERANGE_FILL +#line 3068 + xp++; tp++; continue; +#line 3068 +#endif +#line 3068 + } +#line 3068 + *xp++ = (uchar) (signed) *tp++; /* type cast from short to uchar */ +#line 3068 + } +#line 3068 + +#line 3068 + *xpp = (void *)xp; +#line 3068 + return status; +#line 3068 +} +#line 3068 + +int +#line 3069 +ncx_putn_uchar_int(void **xpp, size_t nelems, const int *tp, void *fillp) +#line 3069 +{ +#line 3069 + int status = NC_NOERR; +#line 3069 + uchar *xp = (uchar *) *xpp; +#line 3069 + +#line 3069 + while (nelems-- != 0) { +#line 3069 + if (*tp > (int)X_UCHAR_MAX || *tp < 0) { +#line 3069 + +#line 3069 +#ifdef ERANGE_FILL +#line 3069 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3069 +#endif +#line 3069 + status = NC_ERANGE; +#line 3069 + +#line 3069 +#ifdef ERANGE_FILL +#line 3069 + xp++; tp++; continue; +#line 3069 +#endif +#line 3069 + } +#line 3069 + *xp++ = (uchar) (signed) *tp++; /* type cast from int to uchar */ +#line 3069 + } +#line 3069 + +#line 3069 + *xpp = (void *)xp; +#line 3069 + return status; +#line 3069 +} +#line 3069 + +int +#line 3070 +ncx_putn_uchar_long(void **xpp, size_t nelems, const long *tp, void *fillp) +#line 3070 +{ +#line 3070 + int status = NC_NOERR; +#line 3070 + uchar *xp = (uchar *) *xpp; +#line 3070 + +#line 3070 + while (nelems-- != 0) { +#line 3070 + if (*tp > (long)X_UCHAR_MAX || *tp < 0) { +#line 3070 + +#line 3070 +#ifdef ERANGE_FILL +#line 3070 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3070 +#endif +#line 3070 + status = NC_ERANGE; +#line 3070 + +#line 3070 +#ifdef ERANGE_FILL +#line 3070 + xp++; tp++; continue; +#line 3070 +#endif +#line 3070 + } +#line 3070 + *xp++ = (uchar) (signed) *tp++; /* type cast from long to uchar */ +#line 3070 + } +#line 3070 + +#line 3070 + *xpp = (void *)xp; +#line 3070 + return status; +#line 3070 +} +#line 3070 + +int +#line 3071 +ncx_putn_uchar_float(void **xpp, size_t nelems, const float *tp, void *fillp) +#line 3071 +{ +#line 3071 + int status = NC_NOERR; +#line 3071 + uchar *xp = (uchar *) *xpp; +#line 3071 + +#line 3071 + while (nelems-- != 0) { +#line 3071 + if (*tp > (float)X_UCHAR_MAX || *tp < 0) { +#line 3071 + +#line 3071 +#ifdef ERANGE_FILL +#line 3071 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3071 +#endif +#line 3071 + status = NC_ERANGE; +#line 3071 + +#line 3071 +#ifdef ERANGE_FILL +#line 3071 + xp++; tp++; continue; +#line 3071 +#endif +#line 3071 + } +#line 3071 + *xp++ = (uchar) (signed) *tp++; /* type cast from float to uchar */ +#line 3071 + } +#line 3071 + +#line 3071 + *xpp = (void *)xp; +#line 3071 + return status; +#line 3071 +} +#line 3071 + +int +#line 3072 +ncx_putn_uchar_double(void **xpp, size_t nelems, const double *tp, void *fillp) +#line 3072 +{ +#line 3072 + int status = NC_NOERR; +#line 3072 + uchar *xp = (uchar *) *xpp; +#line 3072 + +#line 3072 + while (nelems-- != 0) { +#line 3072 + if (*tp > (double)X_UCHAR_MAX || *tp < 0) { +#line 3072 + +#line 3072 +#ifdef ERANGE_FILL +#line 3072 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3072 +#endif +#line 3072 + status = NC_ERANGE; +#line 3072 + +#line 3072 +#ifdef ERANGE_FILL +#line 3072 + xp++; tp++; continue; +#line 3072 +#endif +#line 3072 + } +#line 3072 + *xp++ = (uchar) (signed) *tp++; /* type cast from double to uchar */ +#line 3072 + } +#line 3072 + +#line 3072 + *xpp = (void *)xp; +#line 3072 + return status; +#line 3072 +} +#line 3072 + +int +#line 3073 +ncx_putn_uchar_longlong(void **xpp, size_t nelems, const longlong *tp, void *fillp) +#line 3073 +{ +#line 3073 + int status = NC_NOERR; +#line 3073 + uchar *xp = (uchar *) *xpp; +#line 3073 + +#line 3073 + while (nelems-- != 0) { +#line 3073 + if (*tp > (longlong)X_UCHAR_MAX || *tp < 0) { +#line 3073 + +#line 3073 +#ifdef ERANGE_FILL +#line 3073 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3073 +#endif +#line 3073 + status = NC_ERANGE; +#line 3073 + +#line 3073 +#ifdef ERANGE_FILL +#line 3073 + xp++; tp++; continue; +#line 3073 +#endif +#line 3073 + } +#line 3073 + *xp++ = (uchar) (signed) *tp++; /* type cast from longlong to uchar */ +#line 3073 + } +#line 3073 + +#line 3073 + *xpp = (void *)xp; +#line 3073 + return status; +#line 3073 +} +#line 3073 + +int +#line 3074 +ncx_putn_uchar_ushort(void **xpp, size_t nelems, const ushort *tp, void *fillp) +#line 3074 +{ +#line 3074 + int status = NC_NOERR; +#line 3074 + uchar *xp = (uchar *) *xpp; +#line 3074 + +#line 3074 + while (nelems-- != 0) { +#line 3074 + if (*tp > (ushort)X_UCHAR_MAX ) { +#line 3074 + +#line 3074 +#ifdef ERANGE_FILL +#line 3074 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3074 +#endif +#line 3074 + status = NC_ERANGE; +#line 3074 + +#line 3074 +#ifdef ERANGE_FILL +#line 3074 + xp++; tp++; continue; +#line 3074 +#endif +#line 3074 + } +#line 3074 + *xp++ = (uchar) *tp++; /* type cast from ushort to uchar */ +#line 3074 + } +#line 3074 + +#line 3074 + *xpp = (void *)xp; +#line 3074 + return status; +#line 3074 +} +#line 3074 + +int +#line 3075 +ncx_putn_uchar_uint(void **xpp, size_t nelems, const uint *tp, void *fillp) +#line 3075 +{ +#line 3075 + int status = NC_NOERR; +#line 3075 + uchar *xp = (uchar *) *xpp; +#line 3075 + +#line 3075 + while (nelems-- != 0) { +#line 3075 + if (*tp > (uint)X_UCHAR_MAX ) { +#line 3075 + +#line 3075 +#ifdef ERANGE_FILL +#line 3075 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3075 +#endif +#line 3075 + status = NC_ERANGE; +#line 3075 + +#line 3075 +#ifdef ERANGE_FILL +#line 3075 + xp++; tp++; continue; +#line 3075 +#endif +#line 3075 + } +#line 3075 + *xp++ = (uchar) *tp++; /* type cast from uint to uchar */ +#line 3075 + } +#line 3075 + +#line 3075 + *xpp = (void *)xp; +#line 3075 + return status; +#line 3075 +} +#line 3075 + +int +#line 3076 +ncx_putn_uchar_ulonglong(void **xpp, size_t nelems, const ulonglong *tp, void *fillp) +#line 3076 +{ +#line 3076 + int status = NC_NOERR; +#line 3076 + uchar *xp = (uchar *) *xpp; +#line 3076 + +#line 3076 + while (nelems-- != 0) { +#line 3076 + if (*tp > (ulonglong)X_UCHAR_MAX ) { +#line 3076 + +#line 3076 +#ifdef ERANGE_FILL +#line 3076 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3076 +#endif +#line 3076 + status = NC_ERANGE; +#line 3076 + +#line 3076 +#ifdef ERANGE_FILL +#line 3076 + xp++; tp++; continue; +#line 3076 +#endif +#line 3076 + } +#line 3076 + *xp++ = (uchar) *tp++; /* type cast from ulonglong to uchar */ +#line 3076 + } +#line 3076 + +#line 3076 + *xpp = (void *)xp; +#line 3076 + return status; +#line 3076 +} +#line 3076 + + +#line 3079 +int +ncx_pad_putn_uchar_schar(void **xpp, size_t nelems, const schar *tp, void *fillp) +{ + int status = NC_NOERR; + size_t rndup = nelems % X_ALIGN; + uchar *xp = (uchar *) *xpp; + + if (rndup) rndup = X_ALIGN - rndup; + + while (nelems-- != 0) { + if (*tp < 0) { + +#line 3090 +#ifdef ERANGE_FILL +#line 3090 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3090 +#endif + status = NC_ERANGE; + +#line 3092 +#ifdef ERANGE_FILL +#line 3092 + xp++; tp++; continue; +#line 3092 +#endif + } + *xp++ = (uchar) (signed) *tp++; /* type cast from schar to uchar */ + } + + if (rndup) { + (void) memcpy(xp, nada, (size_t)rndup); + xp += rndup; + } + + *xpp = (void *)xp; + return status; +} +#line 3106 +int +ncx_pad_putn_uchar_uchar(void **xpp, size_t nelems, const uchar *tp, void *fillp) +{ + size_t rndup = nelems % X_ALIGN; +#line 3109 + +#line 3109 + if (rndup) +#line 3109 + rndup = X_ALIGN - rndup; +#line 3109 + +#line 3109 + (void) memcpy(*xpp, tp, (size_t)nelems); +#line 3109 + *xpp = (void *)((char *)(*xpp) + nelems); +#line 3109 + +#line 3109 + if (rndup) +#line 3109 + { +#line 3109 + (void) memcpy(*xpp, nada, (size_t)rndup); +#line 3109 + *xpp = (void *)((char *)(*xpp) + rndup); +#line 3109 + } +#line 3109 + +#line 3109 + return NC_NOERR; +#line 3109 + +} +int +#line 3111 +ncx_pad_putn_uchar_short(void **xpp, size_t nelems, const short *tp, void *fillp) +#line 3111 +{ +#line 3111 + int status = NC_NOERR; +#line 3111 + size_t rndup = nelems % X_ALIGN; +#line 3111 + uchar *xp = (uchar *) *xpp; +#line 3111 + +#line 3111 + if (rndup) rndup = X_ALIGN - rndup; +#line 3111 + +#line 3111 + while (nelems-- != 0) { +#line 3111 + if (*tp > (short)X_UCHAR_MAX || *tp < 0) { +#line 3111 + +#line 3111 +#ifdef ERANGE_FILL +#line 3111 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3111 +#endif +#line 3111 + status = NC_ERANGE; +#line 3111 + +#line 3111 +#ifdef ERANGE_FILL +#line 3111 + xp++; tp++; continue; +#line 3111 +#endif +#line 3111 + } +#line 3111 + *xp++ = (uchar) (signed) *tp++; /* type cast from short to uchar */ +#line 3111 + } +#line 3111 + +#line 3111 + +#line 3111 + if (rndup) { +#line 3111 + (void) memcpy(xp, nada, (size_t)rndup); +#line 3111 + xp += rndup; +#line 3111 + } +#line 3111 + +#line 3111 + *xpp = (void *)xp; +#line 3111 + return status; +#line 3111 +} +#line 3111 + +int +#line 3112 +ncx_pad_putn_uchar_int(void **xpp, size_t nelems, const int *tp, void *fillp) +#line 3112 +{ +#line 3112 + int status = NC_NOERR; +#line 3112 + size_t rndup = nelems % X_ALIGN; +#line 3112 + uchar *xp = (uchar *) *xpp; +#line 3112 + +#line 3112 + if (rndup) rndup = X_ALIGN - rndup; +#line 3112 + +#line 3112 + while (nelems-- != 0) { +#line 3112 + if (*tp > (int)X_UCHAR_MAX || *tp < 0) { +#line 3112 + +#line 3112 +#ifdef ERANGE_FILL +#line 3112 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3112 +#endif +#line 3112 + status = NC_ERANGE; +#line 3112 + +#line 3112 +#ifdef ERANGE_FILL +#line 3112 + xp++; tp++; continue; +#line 3112 +#endif +#line 3112 + } +#line 3112 + *xp++ = (uchar) (signed) *tp++; /* type cast from int to uchar */ +#line 3112 + } +#line 3112 + +#line 3112 + +#line 3112 + if (rndup) { +#line 3112 + (void) memcpy(xp, nada, (size_t)rndup); +#line 3112 + xp += rndup; +#line 3112 + } +#line 3112 + +#line 3112 + *xpp = (void *)xp; +#line 3112 + return status; +#line 3112 +} +#line 3112 + +int +#line 3113 +ncx_pad_putn_uchar_long(void **xpp, size_t nelems, const long *tp, void *fillp) +#line 3113 +{ +#line 3113 + int status = NC_NOERR; +#line 3113 + size_t rndup = nelems % X_ALIGN; +#line 3113 + uchar *xp = (uchar *) *xpp; +#line 3113 + +#line 3113 + if (rndup) rndup = X_ALIGN - rndup; +#line 3113 + +#line 3113 + while (nelems-- != 0) { +#line 3113 + if (*tp > (long)X_UCHAR_MAX || *tp < 0) { +#line 3113 + +#line 3113 +#ifdef ERANGE_FILL +#line 3113 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3113 +#endif +#line 3113 + status = NC_ERANGE; +#line 3113 + +#line 3113 +#ifdef ERANGE_FILL +#line 3113 + xp++; tp++; continue; +#line 3113 +#endif +#line 3113 + } +#line 3113 + *xp++ = (uchar) (signed) *tp++; /* type cast from long to uchar */ +#line 3113 + } +#line 3113 + +#line 3113 + +#line 3113 + if (rndup) { +#line 3113 + (void) memcpy(xp, nada, (size_t)rndup); +#line 3113 + xp += rndup; +#line 3113 + } +#line 3113 + +#line 3113 + *xpp = (void *)xp; +#line 3113 + return status; +#line 3113 +} +#line 3113 + +int +#line 3114 +ncx_pad_putn_uchar_float(void **xpp, size_t nelems, const float *tp, void *fillp) +#line 3114 +{ +#line 3114 + int status = NC_NOERR; +#line 3114 + size_t rndup = nelems % X_ALIGN; +#line 3114 + uchar *xp = (uchar *) *xpp; +#line 3114 + +#line 3114 + if (rndup) rndup = X_ALIGN - rndup; +#line 3114 + +#line 3114 + while (nelems-- != 0) { +#line 3114 + if (*tp > (float)X_UCHAR_MAX || *tp < 0) { +#line 3114 + +#line 3114 +#ifdef ERANGE_FILL +#line 3114 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3114 +#endif +#line 3114 + status = NC_ERANGE; +#line 3114 + +#line 3114 +#ifdef ERANGE_FILL +#line 3114 + xp++; tp++; continue; +#line 3114 +#endif +#line 3114 + } +#line 3114 + *xp++ = (uchar) (signed) *tp++; /* type cast from float to uchar */ +#line 3114 + } +#line 3114 + +#line 3114 + +#line 3114 + if (rndup) { +#line 3114 + (void) memcpy(xp, nada, (size_t)rndup); +#line 3114 + xp += rndup; +#line 3114 + } +#line 3114 + +#line 3114 + *xpp = (void *)xp; +#line 3114 + return status; +#line 3114 +} +#line 3114 + +int +#line 3115 +ncx_pad_putn_uchar_double(void **xpp, size_t nelems, const double *tp, void *fillp) +#line 3115 +{ +#line 3115 + int status = NC_NOERR; +#line 3115 + size_t rndup = nelems % X_ALIGN; +#line 3115 + uchar *xp = (uchar *) *xpp; +#line 3115 + +#line 3115 + if (rndup) rndup = X_ALIGN - rndup; +#line 3115 + +#line 3115 + while (nelems-- != 0) { +#line 3115 + if (*tp > (double)X_UCHAR_MAX || *tp < 0) { +#line 3115 + +#line 3115 +#ifdef ERANGE_FILL +#line 3115 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3115 +#endif +#line 3115 + status = NC_ERANGE; +#line 3115 + +#line 3115 +#ifdef ERANGE_FILL +#line 3115 + xp++; tp++; continue; +#line 3115 +#endif +#line 3115 + } +#line 3115 + *xp++ = (uchar) (signed) *tp++; /* type cast from double to uchar */ +#line 3115 + } +#line 3115 + +#line 3115 + +#line 3115 + if (rndup) { +#line 3115 + (void) memcpy(xp, nada, (size_t)rndup); +#line 3115 + xp += rndup; +#line 3115 + } +#line 3115 + +#line 3115 + *xpp = (void *)xp; +#line 3115 + return status; +#line 3115 +} +#line 3115 + +int +#line 3116 +ncx_pad_putn_uchar_longlong(void **xpp, size_t nelems, const longlong *tp, void *fillp) +#line 3116 +{ +#line 3116 + int status = NC_NOERR; +#line 3116 + size_t rndup = nelems % X_ALIGN; +#line 3116 + uchar *xp = (uchar *) *xpp; +#line 3116 + +#line 3116 + if (rndup) rndup = X_ALIGN - rndup; +#line 3116 + +#line 3116 + while (nelems-- != 0) { +#line 3116 + if (*tp > (longlong)X_UCHAR_MAX || *tp < 0) { +#line 3116 + +#line 3116 +#ifdef ERANGE_FILL +#line 3116 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3116 +#endif +#line 3116 + status = NC_ERANGE; +#line 3116 + +#line 3116 +#ifdef ERANGE_FILL +#line 3116 + xp++; tp++; continue; +#line 3116 +#endif +#line 3116 + } +#line 3116 + *xp++ = (uchar) (signed) *tp++; /* type cast from longlong to uchar */ +#line 3116 + } +#line 3116 + +#line 3116 + +#line 3116 + if (rndup) { +#line 3116 + (void) memcpy(xp, nada, (size_t)rndup); +#line 3116 + xp += rndup; +#line 3116 + } +#line 3116 + +#line 3116 + *xpp = (void *)xp; +#line 3116 + return status; +#line 3116 +} +#line 3116 + +int +#line 3117 +ncx_pad_putn_uchar_ushort(void **xpp, size_t nelems, const ushort *tp, void *fillp) +#line 3117 +{ +#line 3117 + int status = NC_NOERR; +#line 3117 + size_t rndup = nelems % X_ALIGN; +#line 3117 + uchar *xp = (uchar *) *xpp; +#line 3117 + +#line 3117 + if (rndup) rndup = X_ALIGN - rndup; +#line 3117 + +#line 3117 + while (nelems-- != 0) { +#line 3117 + if (*tp > (ushort)X_UCHAR_MAX ) { +#line 3117 + +#line 3117 +#ifdef ERANGE_FILL +#line 3117 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3117 +#endif +#line 3117 + status = NC_ERANGE; +#line 3117 + +#line 3117 +#ifdef ERANGE_FILL +#line 3117 + xp++; tp++; continue; +#line 3117 +#endif +#line 3117 + } +#line 3117 + *xp++ = (uchar) *tp++; /* type cast from ushort to uchar */ +#line 3117 + } +#line 3117 + +#line 3117 + +#line 3117 + if (rndup) { +#line 3117 + (void) memcpy(xp, nada, (size_t)rndup); +#line 3117 + xp += rndup; +#line 3117 + } +#line 3117 + +#line 3117 + *xpp = (void *)xp; +#line 3117 + return status; +#line 3117 +} +#line 3117 + +int +#line 3118 +ncx_pad_putn_uchar_uint(void **xpp, size_t nelems, const uint *tp, void *fillp) +#line 3118 +{ +#line 3118 + int status = NC_NOERR; +#line 3118 + size_t rndup = nelems % X_ALIGN; +#line 3118 + uchar *xp = (uchar *) *xpp; +#line 3118 + +#line 3118 + if (rndup) rndup = X_ALIGN - rndup; +#line 3118 + +#line 3118 + while (nelems-- != 0) { +#line 3118 + if (*tp > (uint)X_UCHAR_MAX ) { +#line 3118 + +#line 3118 +#ifdef ERANGE_FILL +#line 3118 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3118 +#endif +#line 3118 + status = NC_ERANGE; +#line 3118 + +#line 3118 +#ifdef ERANGE_FILL +#line 3118 + xp++; tp++; continue; +#line 3118 +#endif +#line 3118 + } +#line 3118 + *xp++ = (uchar) *tp++; /* type cast from uint to uchar */ +#line 3118 + } +#line 3118 + +#line 3118 + +#line 3118 + if (rndup) { +#line 3118 + (void) memcpy(xp, nada, (size_t)rndup); +#line 3118 + xp += rndup; +#line 3118 + } +#line 3118 + +#line 3118 + *xpp = (void *)xp; +#line 3118 + return status; +#line 3118 +} +#line 3118 + +int +#line 3119 +ncx_pad_putn_uchar_ulonglong(void **xpp, size_t nelems, const ulonglong *tp, void *fillp) +#line 3119 +{ +#line 3119 + int status = NC_NOERR; +#line 3119 + size_t rndup = nelems % X_ALIGN; +#line 3119 + uchar *xp = (uchar *) *xpp; +#line 3119 + +#line 3119 + if (rndup) rndup = X_ALIGN - rndup; +#line 3119 + +#line 3119 + while (nelems-- != 0) { +#line 3119 + if (*tp > (ulonglong)X_UCHAR_MAX ) { +#line 3119 + +#line 3119 +#ifdef ERANGE_FILL +#line 3119 + if (fillp != NULL) memcpy(xp, fillp, 1); +#line 3119 +#endif +#line 3119 + status = NC_ERANGE; +#line 3119 + +#line 3119 +#ifdef ERANGE_FILL +#line 3119 + xp++; tp++; continue; +#line 3119 +#endif +#line 3119 + } +#line 3119 + *xp++ = (uchar) *tp++; /* type cast from ulonglong to uchar */ +#line 3119 + } +#line 3119 + +#line 3119 + +#line 3119 + if (rndup) { +#line 3119 + (void) memcpy(xp, nada, (size_t)rndup); +#line 3119 + xp += rndup; +#line 3119 + } +#line 3119 + +#line 3119 + *xpp = (void *)xp; +#line 3119 + return status; +#line 3119 +} +#line 3119 + + +/* short ---------------------------------------------------------------------*/ + +#if X_SIZEOF_SHORT == SIZEOF_SHORT +/* optimized version */ +int +ncx_getn_short_short(const void **xpp, size_t nelems, short *tp) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(tp, *xpp, (size_t)nelems * SIZEOF_SHORT); +# else + swapn2b(tp, *xpp, nelems); +# endif + *xpp = (const void *)((const char *)(*xpp) + nelems * X_SIZEOF_SHORT); + return NC_NOERR; +} +#else +int +#line 3137 +ncx_getn_short_short(const void **xpp, size_t nelems, short *tp) +#line 3137 +{ +#line 3137 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3137 + +#line 3137 + /* basic algorithm is: +#line 3137 + * - ensure sane alignment of input data +#line 3137 + * - copy (conversion happens automatically) input data +#line 3137 + * to output +#line 3137 + * - update xpp to point at next unconverted input, and tp to point +#line 3137 + * at next location for converted output +#line 3137 + */ +#line 3137 + long i, j, ni; +#line 3137 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3137 + short *xp; +#line 3137 + int nrange = 0; /* number of range errors */ +#line 3137 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3137 + long cxp = (long) *((char**)xpp); +#line 3137 + +#line 3137 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3137 + /* sjl: manually stripmine so we can limit amount of +#line 3137 + * vector work space reserved to LOOPCNT elements. Also +#line 3137 + * makes vectorisation easy */ +#line 3137 + for (j=0; j= 0 */ +#line 3137 + nrange += xp[i] > SHORT_MAX || xp[i] < SHORT_MIN; +#line 3137 + } +#line 3137 + /* update xpp and tp */ +#line 3137 + if (realign) xp = (short *) *xpp; +#line 3137 + xp += ni; +#line 3137 + tp += ni; +#line 3137 + *xpp = (void*)xp; +#line 3137 + } +#line 3137 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3137 + +#line 3137 +#else /* not SX */ +#line 3137 + const char *xp = (const char *) *xpp; +#line 3137 + int status = NC_NOERR; +#line 3137 + +#line 3137 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3137 + { +#line 3137 + const int lstatus = ncx_get_short_short(xp, tp); +#line 3137 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3137 + status = lstatus; +#line 3137 + } +#line 3137 + +#line 3137 + *xpp = (const void *)xp; +#line 3137 + return status; +#line 3137 +#endif +#line 3137 +} +#line 3137 + +#endif +int +#line 3139 +ncx_getn_short_schar(const void **xpp, size_t nelems, schar *tp) +#line 3139 +{ +#line 3139 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3139 + +#line 3139 + /* basic algorithm is: +#line 3139 + * - ensure sane alignment of input data +#line 3139 + * - copy (conversion happens automatically) input data +#line 3139 + * to output +#line 3139 + * - update xpp to point at next unconverted input, and tp to point +#line 3139 + * at next location for converted output +#line 3139 + */ +#line 3139 + long i, j, ni; +#line 3139 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3139 + short *xp; +#line 3139 + int nrange = 0; /* number of range errors */ +#line 3139 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3139 + long cxp = (long) *((char**)xpp); +#line 3139 + +#line 3139 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3139 + /* sjl: manually stripmine so we can limit amount of +#line 3139 + * vector work space reserved to LOOPCNT elements. Also +#line 3139 + * makes vectorisation easy */ +#line 3139 + for (j=0; j= 0 */ +#line 3139 + nrange += xp[i] > SCHAR_MAX || xp[i] < SCHAR_MIN; +#line 3139 + } +#line 3139 + /* update xpp and tp */ +#line 3139 + if (realign) xp = (short *) *xpp; +#line 3139 + xp += ni; +#line 3139 + tp += ni; +#line 3139 + *xpp = (void*)xp; +#line 3139 + } +#line 3139 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3139 + +#line 3139 +#else /* not SX */ +#line 3139 + const char *xp = (const char *) *xpp; +#line 3139 + int status = NC_NOERR; +#line 3139 + +#line 3139 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3139 + { +#line 3139 + const int lstatus = ncx_get_short_schar(xp, tp); +#line 3139 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3139 + status = lstatus; +#line 3139 + } +#line 3139 + +#line 3139 + *xpp = (const void *)xp; +#line 3139 + return status; +#line 3139 +#endif +#line 3139 +} +#line 3139 + +int +#line 3140 +ncx_getn_short_int(const void **xpp, size_t nelems, int *tp) +#line 3140 +{ +#line 3140 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3140 + +#line 3140 + /* basic algorithm is: +#line 3140 + * - ensure sane alignment of input data +#line 3140 + * - copy (conversion happens automatically) input data +#line 3140 + * to output +#line 3140 + * - update xpp to point at next unconverted input, and tp to point +#line 3140 + * at next location for converted output +#line 3140 + */ +#line 3140 + long i, j, ni; +#line 3140 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3140 + short *xp; +#line 3140 + int nrange = 0; /* number of range errors */ +#line 3140 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3140 + long cxp = (long) *((char**)xpp); +#line 3140 + +#line 3140 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3140 + /* sjl: manually stripmine so we can limit amount of +#line 3140 + * vector work space reserved to LOOPCNT elements. Also +#line 3140 + * makes vectorisation easy */ +#line 3140 + for (j=0; j= 0 */ +#line 3140 + nrange += xp[i] > INT_MAX || xp[i] < INT_MIN; +#line 3140 + } +#line 3140 + /* update xpp and tp */ +#line 3140 + if (realign) xp = (short *) *xpp; +#line 3140 + xp += ni; +#line 3140 + tp += ni; +#line 3140 + *xpp = (void*)xp; +#line 3140 + } +#line 3140 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3140 + +#line 3140 +#else /* not SX */ +#line 3140 + const char *xp = (const char *) *xpp; +#line 3140 + int status = NC_NOERR; +#line 3140 + +#line 3140 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3140 + { +#line 3140 + const int lstatus = ncx_get_short_int(xp, tp); +#line 3140 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3140 + status = lstatus; +#line 3140 + } +#line 3140 + +#line 3140 + *xpp = (const void *)xp; +#line 3140 + return status; +#line 3140 +#endif +#line 3140 +} +#line 3140 + +int +#line 3141 +ncx_getn_short_long(const void **xpp, size_t nelems, long *tp) +#line 3141 +{ +#line 3141 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3141 + +#line 3141 + /* basic algorithm is: +#line 3141 + * - ensure sane alignment of input data +#line 3141 + * - copy (conversion happens automatically) input data +#line 3141 + * to output +#line 3141 + * - update xpp to point at next unconverted input, and tp to point +#line 3141 + * at next location for converted output +#line 3141 + */ +#line 3141 + long i, j, ni; +#line 3141 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3141 + short *xp; +#line 3141 + int nrange = 0; /* number of range errors */ +#line 3141 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3141 + long cxp = (long) *((char**)xpp); +#line 3141 + +#line 3141 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3141 + /* sjl: manually stripmine so we can limit amount of +#line 3141 + * vector work space reserved to LOOPCNT elements. Also +#line 3141 + * makes vectorisation easy */ +#line 3141 + for (j=0; j= 0 */ +#line 3141 + nrange += xp[i] > LONG_MAX || xp[i] < LONG_MIN; +#line 3141 + } +#line 3141 + /* update xpp and tp */ +#line 3141 + if (realign) xp = (short *) *xpp; +#line 3141 + xp += ni; +#line 3141 + tp += ni; +#line 3141 + *xpp = (void*)xp; +#line 3141 + } +#line 3141 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3141 + +#line 3141 +#else /* not SX */ +#line 3141 + const char *xp = (const char *) *xpp; +#line 3141 + int status = NC_NOERR; +#line 3141 + +#line 3141 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3141 + { +#line 3141 + const int lstatus = ncx_get_short_long(xp, tp); +#line 3141 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3141 + status = lstatus; +#line 3141 + } +#line 3141 + +#line 3141 + *xpp = (const void *)xp; +#line 3141 + return status; +#line 3141 +#endif +#line 3141 +} +#line 3141 + +int +#line 3142 +ncx_getn_short_float(const void **xpp, size_t nelems, float *tp) +#line 3142 +{ +#line 3142 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3142 + +#line 3142 + /* basic algorithm is: +#line 3142 + * - ensure sane alignment of input data +#line 3142 + * - copy (conversion happens automatically) input data +#line 3142 + * to output +#line 3142 + * - update xpp to point at next unconverted input, and tp to point +#line 3142 + * at next location for converted output +#line 3142 + */ +#line 3142 + long i, j, ni; +#line 3142 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3142 + short *xp; +#line 3142 + int nrange = 0; /* number of range errors */ +#line 3142 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3142 + long cxp = (long) *((char**)xpp); +#line 3142 + +#line 3142 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3142 + /* sjl: manually stripmine so we can limit amount of +#line 3142 + * vector work space reserved to LOOPCNT elements. Also +#line 3142 + * makes vectorisation easy */ +#line 3142 + for (j=0; j= 0 */ +#line 3142 + nrange += xp[i] > FLOAT_MAX || xp[i] < FLOAT_MIN; +#line 3142 + } +#line 3142 + /* update xpp and tp */ +#line 3142 + if (realign) xp = (short *) *xpp; +#line 3142 + xp += ni; +#line 3142 + tp += ni; +#line 3142 + *xpp = (void*)xp; +#line 3142 + } +#line 3142 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3142 + +#line 3142 +#else /* not SX */ +#line 3142 + const char *xp = (const char *) *xpp; +#line 3142 + int status = NC_NOERR; +#line 3142 + +#line 3142 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3142 + { +#line 3142 + const int lstatus = ncx_get_short_float(xp, tp); +#line 3142 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3142 + status = lstatus; +#line 3142 + } +#line 3142 + +#line 3142 + *xpp = (const void *)xp; +#line 3142 + return status; +#line 3142 +#endif +#line 3142 +} +#line 3142 + +int +#line 3143 +ncx_getn_short_double(const void **xpp, size_t nelems, double *tp) +#line 3143 +{ +#line 3143 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3143 + +#line 3143 + /* basic algorithm is: +#line 3143 + * - ensure sane alignment of input data +#line 3143 + * - copy (conversion happens automatically) input data +#line 3143 + * to output +#line 3143 + * - update xpp to point at next unconverted input, and tp to point +#line 3143 + * at next location for converted output +#line 3143 + */ +#line 3143 + long i, j, ni; +#line 3143 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3143 + short *xp; +#line 3143 + int nrange = 0; /* number of range errors */ +#line 3143 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3143 + long cxp = (long) *((char**)xpp); +#line 3143 + +#line 3143 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3143 + /* sjl: manually stripmine so we can limit amount of +#line 3143 + * vector work space reserved to LOOPCNT elements. Also +#line 3143 + * makes vectorisation easy */ +#line 3143 + for (j=0; j= 0 */ +#line 3143 + nrange += xp[i] > DOUBLE_MAX || xp[i] < DOUBLE_MIN; +#line 3143 + } +#line 3143 + /* update xpp and tp */ +#line 3143 + if (realign) xp = (short *) *xpp; +#line 3143 + xp += ni; +#line 3143 + tp += ni; +#line 3143 + *xpp = (void*)xp; +#line 3143 + } +#line 3143 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3143 + +#line 3143 +#else /* not SX */ +#line 3143 + const char *xp = (const char *) *xpp; +#line 3143 + int status = NC_NOERR; +#line 3143 + +#line 3143 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3143 + { +#line 3143 + const int lstatus = ncx_get_short_double(xp, tp); +#line 3143 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3143 + status = lstatus; +#line 3143 + } +#line 3143 + +#line 3143 + *xpp = (const void *)xp; +#line 3143 + return status; +#line 3143 +#endif +#line 3143 +} +#line 3143 + +int +#line 3144 +ncx_getn_short_longlong(const void **xpp, size_t nelems, longlong *tp) +#line 3144 +{ +#line 3144 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3144 + +#line 3144 + /* basic algorithm is: +#line 3144 + * - ensure sane alignment of input data +#line 3144 + * - copy (conversion happens automatically) input data +#line 3144 + * to output +#line 3144 + * - update xpp to point at next unconverted input, and tp to point +#line 3144 + * at next location for converted output +#line 3144 + */ +#line 3144 + long i, j, ni; +#line 3144 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3144 + short *xp; +#line 3144 + int nrange = 0; /* number of range errors */ +#line 3144 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3144 + long cxp = (long) *((char**)xpp); +#line 3144 + +#line 3144 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3144 + /* sjl: manually stripmine so we can limit amount of +#line 3144 + * vector work space reserved to LOOPCNT elements. Also +#line 3144 + * makes vectorisation easy */ +#line 3144 + for (j=0; j= 0 */ +#line 3144 + nrange += xp[i] > LONGLONG_MAX || xp[i] < LONGLONG_MIN; +#line 3144 + } +#line 3144 + /* update xpp and tp */ +#line 3144 + if (realign) xp = (short *) *xpp; +#line 3144 + xp += ni; +#line 3144 + tp += ni; +#line 3144 + *xpp = (void*)xp; +#line 3144 + } +#line 3144 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3144 + +#line 3144 +#else /* not SX */ +#line 3144 + const char *xp = (const char *) *xpp; +#line 3144 + int status = NC_NOERR; +#line 3144 + +#line 3144 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3144 + { +#line 3144 + const int lstatus = ncx_get_short_longlong(xp, tp); +#line 3144 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3144 + status = lstatus; +#line 3144 + } +#line 3144 + +#line 3144 + *xpp = (const void *)xp; +#line 3144 + return status; +#line 3144 +#endif +#line 3144 +} +#line 3144 + +int +#line 3145 +ncx_getn_short_uchar(const void **xpp, size_t nelems, uchar *tp) +#line 3145 +{ +#line 3145 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3145 + +#line 3145 + /* basic algorithm is: +#line 3145 + * - ensure sane alignment of input data +#line 3145 + * - copy (conversion happens automatically) input data +#line 3145 + * to output +#line 3145 + * - update xpp to point at next unconverted input, and tp to point +#line 3145 + * at next location for converted output +#line 3145 + */ +#line 3145 + long i, j, ni; +#line 3145 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3145 + short *xp; +#line 3145 + int nrange = 0; /* number of range errors */ +#line 3145 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3145 + long cxp = (long) *((char**)xpp); +#line 3145 + +#line 3145 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3145 + /* sjl: manually stripmine so we can limit amount of +#line 3145 + * vector work space reserved to LOOPCNT elements. Also +#line 3145 + * makes vectorisation easy */ +#line 3145 + for (j=0; j= 0 */ +#line 3145 + nrange += xp[i] > UCHAR_MAX || xp[i] < 0; +#line 3145 + } +#line 3145 + /* update xpp and tp */ +#line 3145 + if (realign) xp = (short *) *xpp; +#line 3145 + xp += ni; +#line 3145 + tp += ni; +#line 3145 + *xpp = (void*)xp; +#line 3145 + } +#line 3145 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3145 + +#line 3145 +#else /* not SX */ +#line 3145 + const char *xp = (const char *) *xpp; +#line 3145 + int status = NC_NOERR; +#line 3145 + +#line 3145 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3145 + { +#line 3145 + const int lstatus = ncx_get_short_uchar(xp, tp); +#line 3145 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3145 + status = lstatus; +#line 3145 + } +#line 3145 + +#line 3145 + *xpp = (const void *)xp; +#line 3145 + return status; +#line 3145 +#endif +#line 3145 +} +#line 3145 + +int +#line 3146 +ncx_getn_short_ushort(const void **xpp, size_t nelems, ushort *tp) +#line 3146 +{ +#line 3146 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3146 + +#line 3146 + /* basic algorithm is: +#line 3146 + * - ensure sane alignment of input data +#line 3146 + * - copy (conversion happens automatically) input data +#line 3146 + * to output +#line 3146 + * - update xpp to point at next unconverted input, and tp to point +#line 3146 + * at next location for converted output +#line 3146 + */ +#line 3146 + long i, j, ni; +#line 3146 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3146 + short *xp; +#line 3146 + int nrange = 0; /* number of range errors */ +#line 3146 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3146 + long cxp = (long) *((char**)xpp); +#line 3146 + +#line 3146 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3146 + /* sjl: manually stripmine so we can limit amount of +#line 3146 + * vector work space reserved to LOOPCNT elements. Also +#line 3146 + * makes vectorisation easy */ +#line 3146 + for (j=0; j= 0 */ +#line 3146 + nrange += xp[i] > USHORT_MAX || xp[i] < 0; +#line 3146 + } +#line 3146 + /* update xpp and tp */ +#line 3146 + if (realign) xp = (short *) *xpp; +#line 3146 + xp += ni; +#line 3146 + tp += ni; +#line 3146 + *xpp = (void*)xp; +#line 3146 + } +#line 3146 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3146 + +#line 3146 +#else /* not SX */ +#line 3146 + const char *xp = (const char *) *xpp; +#line 3146 + int status = NC_NOERR; +#line 3146 + +#line 3146 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3146 + { +#line 3146 + const int lstatus = ncx_get_short_ushort(xp, tp); +#line 3146 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3146 + status = lstatus; +#line 3146 + } +#line 3146 + +#line 3146 + *xpp = (const void *)xp; +#line 3146 + return status; +#line 3146 +#endif +#line 3146 +} +#line 3146 + +int +#line 3147 +ncx_getn_short_uint(const void **xpp, size_t nelems, uint *tp) +#line 3147 +{ +#line 3147 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3147 + +#line 3147 + /* basic algorithm is: +#line 3147 + * - ensure sane alignment of input data +#line 3147 + * - copy (conversion happens automatically) input data +#line 3147 + * to output +#line 3147 + * - update xpp to point at next unconverted input, and tp to point +#line 3147 + * at next location for converted output +#line 3147 + */ +#line 3147 + long i, j, ni; +#line 3147 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3147 + short *xp; +#line 3147 + int nrange = 0; /* number of range errors */ +#line 3147 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3147 + long cxp = (long) *((char**)xpp); +#line 3147 + +#line 3147 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3147 + /* sjl: manually stripmine so we can limit amount of +#line 3147 + * vector work space reserved to LOOPCNT elements. Also +#line 3147 + * makes vectorisation easy */ +#line 3147 + for (j=0; j= 0 */ +#line 3147 + nrange += xp[i] > UINT_MAX || xp[i] < 0; +#line 3147 + } +#line 3147 + /* update xpp and tp */ +#line 3147 + if (realign) xp = (short *) *xpp; +#line 3147 + xp += ni; +#line 3147 + tp += ni; +#line 3147 + *xpp = (void*)xp; +#line 3147 + } +#line 3147 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3147 + +#line 3147 +#else /* not SX */ +#line 3147 + const char *xp = (const char *) *xpp; +#line 3147 + int status = NC_NOERR; +#line 3147 + +#line 3147 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3147 + { +#line 3147 + const int lstatus = ncx_get_short_uint(xp, tp); +#line 3147 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3147 + status = lstatus; +#line 3147 + } +#line 3147 + +#line 3147 + *xpp = (const void *)xp; +#line 3147 + return status; +#line 3147 +#endif +#line 3147 +} +#line 3147 + +int +#line 3148 +ncx_getn_short_ulonglong(const void **xpp, size_t nelems, ulonglong *tp) +#line 3148 +{ +#line 3148 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3148 + +#line 3148 + /* basic algorithm is: +#line 3148 + * - ensure sane alignment of input data +#line 3148 + * - copy (conversion happens automatically) input data +#line 3148 + * to output +#line 3148 + * - update xpp to point at next unconverted input, and tp to point +#line 3148 + * at next location for converted output +#line 3148 + */ +#line 3148 + long i, j, ni; +#line 3148 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3148 + short *xp; +#line 3148 + int nrange = 0; /* number of range errors */ +#line 3148 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3148 + long cxp = (long) *((char**)xpp); +#line 3148 + +#line 3148 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3148 + /* sjl: manually stripmine so we can limit amount of +#line 3148 + * vector work space reserved to LOOPCNT elements. Also +#line 3148 + * makes vectorisation easy */ +#line 3148 + for (j=0; j= 0 */ +#line 3148 + nrange += xp[i] > ULONGLONG_MAX || xp[i] < 0; +#line 3148 + } +#line 3148 + /* update xpp and tp */ +#line 3148 + if (realign) xp = (short *) *xpp; +#line 3148 + xp += ni; +#line 3148 + tp += ni; +#line 3148 + *xpp = (void*)xp; +#line 3148 + } +#line 3148 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3148 + +#line 3148 +#else /* not SX */ +#line 3148 + const char *xp = (const char *) *xpp; +#line 3148 + int status = NC_NOERR; +#line 3148 + +#line 3148 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3148 + { +#line 3148 + const int lstatus = ncx_get_short_ulonglong(xp, tp); +#line 3148 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3148 + status = lstatus; +#line 3148 + } +#line 3148 + +#line 3148 + *xpp = (const void *)xp; +#line 3148 + return status; +#line 3148 +#endif +#line 3148 +} +#line 3148 + + +int +#line 3150 +ncx_pad_getn_short_schar(const void **xpp, size_t nelems, schar *tp) +#line 3150 +{ +#line 3150 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3150 + +#line 3150 + const char *xp = (const char *) *xpp; +#line 3150 + int status = NC_NOERR; +#line 3150 + +#line 3150 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3150 + { +#line 3150 + const int lstatus = ncx_get_short_schar(xp, tp); +#line 3150 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3150 + status = lstatus; +#line 3150 + } +#line 3150 + +#line 3150 + if (rndup != 0) +#line 3150 + xp += X_SIZEOF_SHORT; +#line 3150 + +#line 3150 + *xpp = (void *)xp; +#line 3150 + return status; +#line 3150 +} +#line 3150 + +int +#line 3151 +ncx_pad_getn_short_uchar(const void **xpp, size_t nelems, uchar *tp) +#line 3151 +{ +#line 3151 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3151 + +#line 3151 + const char *xp = (const char *) *xpp; +#line 3151 + int status = NC_NOERR; +#line 3151 + +#line 3151 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3151 + { +#line 3151 + const int lstatus = ncx_get_short_uchar(xp, tp); +#line 3151 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3151 + status = lstatus; +#line 3151 + } +#line 3151 + +#line 3151 + if (rndup != 0) +#line 3151 + xp += X_SIZEOF_SHORT; +#line 3151 + +#line 3151 + *xpp = (void *)xp; +#line 3151 + return status; +#line 3151 +} +#line 3151 + +int +#line 3152 +ncx_pad_getn_short_short(const void **xpp, size_t nelems, short *tp) +#line 3152 +{ +#line 3152 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3152 + +#line 3152 + const char *xp = (const char *) *xpp; +#line 3152 + int status = NC_NOERR; +#line 3152 + +#line 3152 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3152 + { +#line 3152 + const int lstatus = ncx_get_short_short(xp, tp); +#line 3152 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3152 + status = lstatus; +#line 3152 + } +#line 3152 + +#line 3152 + if (rndup != 0) +#line 3152 + xp += X_SIZEOF_SHORT; +#line 3152 + +#line 3152 + *xpp = (void *)xp; +#line 3152 + return status; +#line 3152 +} +#line 3152 + +int +#line 3153 +ncx_pad_getn_short_int(const void **xpp, size_t nelems, int *tp) +#line 3153 +{ +#line 3153 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3153 + +#line 3153 + const char *xp = (const char *) *xpp; +#line 3153 + int status = NC_NOERR; +#line 3153 + +#line 3153 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3153 + { +#line 3153 + const int lstatus = ncx_get_short_int(xp, tp); +#line 3153 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3153 + status = lstatus; +#line 3153 + } +#line 3153 + +#line 3153 + if (rndup != 0) +#line 3153 + xp += X_SIZEOF_SHORT; +#line 3153 + +#line 3153 + *xpp = (void *)xp; +#line 3153 + return status; +#line 3153 +} +#line 3153 + +int +#line 3154 +ncx_pad_getn_short_long(const void **xpp, size_t nelems, long *tp) +#line 3154 +{ +#line 3154 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3154 + +#line 3154 + const char *xp = (const char *) *xpp; +#line 3154 + int status = NC_NOERR; +#line 3154 + +#line 3154 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3154 + { +#line 3154 + const int lstatus = ncx_get_short_long(xp, tp); +#line 3154 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3154 + status = lstatus; +#line 3154 + } +#line 3154 + +#line 3154 + if (rndup != 0) +#line 3154 + xp += X_SIZEOF_SHORT; +#line 3154 + +#line 3154 + *xpp = (void *)xp; +#line 3154 + return status; +#line 3154 +} +#line 3154 + +int +#line 3155 +ncx_pad_getn_short_float(const void **xpp, size_t nelems, float *tp) +#line 3155 +{ +#line 3155 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3155 + +#line 3155 + const char *xp = (const char *) *xpp; +#line 3155 + int status = NC_NOERR; +#line 3155 + +#line 3155 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3155 + { +#line 3155 + const int lstatus = ncx_get_short_float(xp, tp); +#line 3155 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3155 + status = lstatus; +#line 3155 + } +#line 3155 + +#line 3155 + if (rndup != 0) +#line 3155 + xp += X_SIZEOF_SHORT; +#line 3155 + +#line 3155 + *xpp = (void *)xp; +#line 3155 + return status; +#line 3155 +} +#line 3155 + +int +#line 3156 +ncx_pad_getn_short_double(const void **xpp, size_t nelems, double *tp) +#line 3156 +{ +#line 3156 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3156 + +#line 3156 + const char *xp = (const char *) *xpp; +#line 3156 + int status = NC_NOERR; +#line 3156 + +#line 3156 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3156 + { +#line 3156 + const int lstatus = ncx_get_short_double(xp, tp); +#line 3156 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3156 + status = lstatus; +#line 3156 + } +#line 3156 + +#line 3156 + if (rndup != 0) +#line 3156 + xp += X_SIZEOF_SHORT; +#line 3156 + +#line 3156 + *xpp = (void *)xp; +#line 3156 + return status; +#line 3156 +} +#line 3156 + +int +#line 3157 +ncx_pad_getn_short_uint(const void **xpp, size_t nelems, uint *tp) +#line 3157 +{ +#line 3157 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3157 + +#line 3157 + const char *xp = (const char *) *xpp; +#line 3157 + int status = NC_NOERR; +#line 3157 + +#line 3157 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3157 + { +#line 3157 + const int lstatus = ncx_get_short_uint(xp, tp); +#line 3157 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3157 + status = lstatus; +#line 3157 + } +#line 3157 + +#line 3157 + if (rndup != 0) +#line 3157 + xp += X_SIZEOF_SHORT; +#line 3157 + +#line 3157 + *xpp = (void *)xp; +#line 3157 + return status; +#line 3157 +} +#line 3157 + +int +#line 3158 +ncx_pad_getn_short_longlong(const void **xpp, size_t nelems, longlong *tp) +#line 3158 +{ +#line 3158 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3158 + +#line 3158 + const char *xp = (const char *) *xpp; +#line 3158 + int status = NC_NOERR; +#line 3158 + +#line 3158 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3158 + { +#line 3158 + const int lstatus = ncx_get_short_longlong(xp, tp); +#line 3158 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3158 + status = lstatus; +#line 3158 + } +#line 3158 + +#line 3158 + if (rndup != 0) +#line 3158 + xp += X_SIZEOF_SHORT; +#line 3158 + +#line 3158 + *xpp = (void *)xp; +#line 3158 + return status; +#line 3158 +} +#line 3158 + +int +#line 3159 +ncx_pad_getn_short_ulonglong(const void **xpp, size_t nelems, ulonglong *tp) +#line 3159 +{ +#line 3159 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3159 + +#line 3159 + const char *xp = (const char *) *xpp; +#line 3159 + int status = NC_NOERR; +#line 3159 + +#line 3159 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3159 + { +#line 3159 + const int lstatus = ncx_get_short_ulonglong(xp, tp); +#line 3159 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3159 + status = lstatus; +#line 3159 + } +#line 3159 + +#line 3159 + if (rndup != 0) +#line 3159 + xp += X_SIZEOF_SHORT; +#line 3159 + +#line 3159 + *xpp = (void *)xp; +#line 3159 + return status; +#line 3159 +} +#line 3159 + +int +#line 3160 +ncx_pad_getn_short_ushort(const void **xpp, size_t nelems, ushort *tp) +#line 3160 +{ +#line 3160 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3160 + +#line 3160 + const char *xp = (const char *) *xpp; +#line 3160 + int status = NC_NOERR; +#line 3160 + +#line 3160 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3160 + { +#line 3160 + const int lstatus = ncx_get_short_ushort(xp, tp); +#line 3160 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3160 + status = lstatus; +#line 3160 + } +#line 3160 + +#line 3160 + if (rndup != 0) +#line 3160 + xp += X_SIZEOF_SHORT; +#line 3160 + +#line 3160 + *xpp = (void *)xp; +#line 3160 + return status; +#line 3160 +} +#line 3160 + + +#if X_SIZEOF_SHORT == SIZEOF_SHORT +/* optimized version */ +int +ncx_putn_short_short(void **xpp, size_t nelems, const short *tp, void *fillp) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(*xpp, tp, (size_t)nelems * X_SIZEOF_SHORT); +# else + swapn2b(*xpp, tp, nelems); +# endif + *xpp = (void *)((char *)(*xpp) + nelems * X_SIZEOF_SHORT); + return NC_NOERR; +} +#else +int +#line 3176 +ncx_putn_short_short(void **xpp, size_t nelems, const short *tp, void *fillp) +#line 3176 +{ +#line 3176 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3176 + +#line 3176 + /* basic algorithm is: +#line 3176 + * - ensure sane alignment of output data +#line 3176 + * - copy (conversion happens automatically) input data +#line 3176 + * to output +#line 3176 + * - update tp to point at next unconverted input, and xpp to point +#line 3176 + * at next location for converted output +#line 3176 + */ +#line 3176 + long i, j, ni; +#line 3176 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3176 + short *xp; +#line 3176 + int nrange = 0; /* number of range errors */ +#line 3176 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3176 + long cxp = (long) *((char**)xpp); +#line 3176 + +#line 3176 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3176 + /* sjl: manually stripmine so we can limit amount of +#line 3176 + * vector work space reserved to LOOPCNT elements. Also +#line 3176 + * makes vectorisation easy */ +#line 3176 + for (j=0; j= 0 */ +#line 3176 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3176 + nrange += tp[i] > X_SHORT_MAX || tp[i] < X_SHORT_MIN; +#line 3176 + } +#line 3176 + /* copy workspace back if necessary */ +#line 3176 + if (realign) { +#line 3176 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_SHORT); +#line 3176 + xp = (short *) *xpp; +#line 3176 + } +#line 3176 + /* update xpp and tp */ +#line 3176 + xp += ni; +#line 3176 + tp += ni; +#line 3176 + *xpp = (void*)xp; +#line 3176 + } +#line 3176 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3176 + +#line 3176 +#else /* not SX */ +#line 3176 + +#line 3176 + char *xp = (char *) *xpp; +#line 3176 + int status = NC_NOERR; +#line 3176 + +#line 3176 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3176 + { +#line 3176 + int lstatus = ncx_put_short_short(xp, tp, fillp); +#line 3176 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3176 + status = lstatus; +#line 3176 + } +#line 3176 + +#line 3176 + *xpp = (void *)xp; +#line 3176 + return status; +#line 3176 +#endif +#line 3176 +} +#line 3176 + +#endif +int +#line 3178 +ncx_putn_short_schar(void **xpp, size_t nelems, const schar *tp, void *fillp) +#line 3178 +{ +#line 3178 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3178 + +#line 3178 + /* basic algorithm is: +#line 3178 + * - ensure sane alignment of output data +#line 3178 + * - copy (conversion happens automatically) input data +#line 3178 + * to output +#line 3178 + * - update tp to point at next unconverted input, and xpp to point +#line 3178 + * at next location for converted output +#line 3178 + */ +#line 3178 + long i, j, ni; +#line 3178 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3178 + short *xp; +#line 3178 + int nrange = 0; /* number of range errors */ +#line 3178 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3178 + long cxp = (long) *((char**)xpp); +#line 3178 + +#line 3178 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3178 + /* sjl: manually stripmine so we can limit amount of +#line 3178 + * vector work space reserved to LOOPCNT elements. Also +#line 3178 + * makes vectorisation easy */ +#line 3178 + for (j=0; j= 0 */ +#line 3178 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3178 + nrange += tp[i] > X_SHORT_MAX || tp[i] < X_SHORT_MIN; +#line 3178 + } +#line 3178 + /* copy workspace back if necessary */ +#line 3178 + if (realign) { +#line 3178 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_SHORT); +#line 3178 + xp = (short *) *xpp; +#line 3178 + } +#line 3178 + /* update xpp and tp */ +#line 3178 + xp += ni; +#line 3178 + tp += ni; +#line 3178 + *xpp = (void*)xp; +#line 3178 + } +#line 3178 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3178 + +#line 3178 +#else /* not SX */ +#line 3178 + +#line 3178 + char *xp = (char *) *xpp; +#line 3178 + int status = NC_NOERR; +#line 3178 + +#line 3178 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3178 + { +#line 3178 + int lstatus = ncx_put_short_schar(xp, tp, fillp); +#line 3178 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3178 + status = lstatus; +#line 3178 + } +#line 3178 + +#line 3178 + *xpp = (void *)xp; +#line 3178 + return status; +#line 3178 +#endif +#line 3178 +} +#line 3178 + +int +#line 3179 +ncx_putn_short_int(void **xpp, size_t nelems, const int *tp, void *fillp) +#line 3179 +{ +#line 3179 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3179 + +#line 3179 + /* basic algorithm is: +#line 3179 + * - ensure sane alignment of output data +#line 3179 + * - copy (conversion happens automatically) input data +#line 3179 + * to output +#line 3179 + * - update tp to point at next unconverted input, and xpp to point +#line 3179 + * at next location for converted output +#line 3179 + */ +#line 3179 + long i, j, ni; +#line 3179 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3179 + short *xp; +#line 3179 + int nrange = 0; /* number of range errors */ +#line 3179 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3179 + long cxp = (long) *((char**)xpp); +#line 3179 + +#line 3179 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3179 + /* sjl: manually stripmine so we can limit amount of +#line 3179 + * vector work space reserved to LOOPCNT elements. Also +#line 3179 + * makes vectorisation easy */ +#line 3179 + for (j=0; j= 0 */ +#line 3179 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3179 + nrange += tp[i] > X_SHORT_MAX || tp[i] < X_SHORT_MIN; +#line 3179 + } +#line 3179 + /* copy workspace back if necessary */ +#line 3179 + if (realign) { +#line 3179 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_SHORT); +#line 3179 + xp = (short *) *xpp; +#line 3179 + } +#line 3179 + /* update xpp and tp */ +#line 3179 + xp += ni; +#line 3179 + tp += ni; +#line 3179 + *xpp = (void*)xp; +#line 3179 + } +#line 3179 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3179 + +#line 3179 +#else /* not SX */ +#line 3179 + +#line 3179 + char *xp = (char *) *xpp; +#line 3179 + int status = NC_NOERR; +#line 3179 + +#line 3179 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3179 + { +#line 3179 + int lstatus = ncx_put_short_int(xp, tp, fillp); +#line 3179 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3179 + status = lstatus; +#line 3179 + } +#line 3179 + +#line 3179 + *xpp = (void *)xp; +#line 3179 + return status; +#line 3179 +#endif +#line 3179 +} +#line 3179 + +int +#line 3180 +ncx_putn_short_long(void **xpp, size_t nelems, const long *tp, void *fillp) +#line 3180 +{ +#line 3180 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3180 + +#line 3180 + /* basic algorithm is: +#line 3180 + * - ensure sane alignment of output data +#line 3180 + * - copy (conversion happens automatically) input data +#line 3180 + * to output +#line 3180 + * - update tp to point at next unconverted input, and xpp to point +#line 3180 + * at next location for converted output +#line 3180 + */ +#line 3180 + long i, j, ni; +#line 3180 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3180 + short *xp; +#line 3180 + int nrange = 0; /* number of range errors */ +#line 3180 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3180 + long cxp = (long) *((char**)xpp); +#line 3180 + +#line 3180 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3180 + /* sjl: manually stripmine so we can limit amount of +#line 3180 + * vector work space reserved to LOOPCNT elements. Also +#line 3180 + * makes vectorisation easy */ +#line 3180 + for (j=0; j= 0 */ +#line 3180 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3180 + nrange += tp[i] > X_SHORT_MAX || tp[i] < X_SHORT_MIN; +#line 3180 + } +#line 3180 + /* copy workspace back if necessary */ +#line 3180 + if (realign) { +#line 3180 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_SHORT); +#line 3180 + xp = (short *) *xpp; +#line 3180 + } +#line 3180 + /* update xpp and tp */ +#line 3180 + xp += ni; +#line 3180 + tp += ni; +#line 3180 + *xpp = (void*)xp; +#line 3180 + } +#line 3180 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3180 + +#line 3180 +#else /* not SX */ +#line 3180 + +#line 3180 + char *xp = (char *) *xpp; +#line 3180 + int status = NC_NOERR; +#line 3180 + +#line 3180 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3180 + { +#line 3180 + int lstatus = ncx_put_short_long(xp, tp, fillp); +#line 3180 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3180 + status = lstatus; +#line 3180 + } +#line 3180 + +#line 3180 + *xpp = (void *)xp; +#line 3180 + return status; +#line 3180 +#endif +#line 3180 +} +#line 3180 + +int +#line 3181 +ncx_putn_short_float(void **xpp, size_t nelems, const float *tp, void *fillp) +#line 3181 +{ +#line 3181 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3181 + +#line 3181 + /* basic algorithm is: +#line 3181 + * - ensure sane alignment of output data +#line 3181 + * - copy (conversion happens automatically) input data +#line 3181 + * to output +#line 3181 + * - update tp to point at next unconverted input, and xpp to point +#line 3181 + * at next location for converted output +#line 3181 + */ +#line 3181 + long i, j, ni; +#line 3181 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3181 + short *xp; +#line 3181 + int nrange = 0; /* number of range errors */ +#line 3181 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3181 + long cxp = (long) *((char**)xpp); +#line 3181 + +#line 3181 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3181 + /* sjl: manually stripmine so we can limit amount of +#line 3181 + * vector work space reserved to LOOPCNT elements. Also +#line 3181 + * makes vectorisation easy */ +#line 3181 + for (j=0; j= 0 */ +#line 3181 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3181 + nrange += tp[i] > X_SHORT_MAX || tp[i] < X_SHORT_MIN; +#line 3181 + } +#line 3181 + /* copy workspace back if necessary */ +#line 3181 + if (realign) { +#line 3181 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_SHORT); +#line 3181 + xp = (short *) *xpp; +#line 3181 + } +#line 3181 + /* update xpp and tp */ +#line 3181 + xp += ni; +#line 3181 + tp += ni; +#line 3181 + *xpp = (void*)xp; +#line 3181 + } +#line 3181 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3181 + +#line 3181 +#else /* not SX */ +#line 3181 + +#line 3181 + char *xp = (char *) *xpp; +#line 3181 + int status = NC_NOERR; +#line 3181 + +#line 3181 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3181 + { +#line 3181 + int lstatus = ncx_put_short_float(xp, tp, fillp); +#line 3181 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3181 + status = lstatus; +#line 3181 + } +#line 3181 + +#line 3181 + *xpp = (void *)xp; +#line 3181 + return status; +#line 3181 +#endif +#line 3181 +} +#line 3181 + +int +#line 3182 +ncx_putn_short_double(void **xpp, size_t nelems, const double *tp, void *fillp) +#line 3182 +{ +#line 3182 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3182 + +#line 3182 + /* basic algorithm is: +#line 3182 + * - ensure sane alignment of output data +#line 3182 + * - copy (conversion happens automatically) input data +#line 3182 + * to output +#line 3182 + * - update tp to point at next unconverted input, and xpp to point +#line 3182 + * at next location for converted output +#line 3182 + */ +#line 3182 + long i, j, ni; +#line 3182 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3182 + short *xp; +#line 3182 + int nrange = 0; /* number of range errors */ +#line 3182 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3182 + long cxp = (long) *((char**)xpp); +#line 3182 + +#line 3182 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3182 + /* sjl: manually stripmine so we can limit amount of +#line 3182 + * vector work space reserved to LOOPCNT elements. Also +#line 3182 + * makes vectorisation easy */ +#line 3182 + for (j=0; j= 0 */ +#line 3182 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3182 + nrange += tp[i] > X_SHORT_MAX || tp[i] < X_SHORT_MIN; +#line 3182 + } +#line 3182 + /* copy workspace back if necessary */ +#line 3182 + if (realign) { +#line 3182 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_SHORT); +#line 3182 + xp = (short *) *xpp; +#line 3182 + } +#line 3182 + /* update xpp and tp */ +#line 3182 + xp += ni; +#line 3182 + tp += ni; +#line 3182 + *xpp = (void*)xp; +#line 3182 + } +#line 3182 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3182 + +#line 3182 +#else /* not SX */ +#line 3182 + +#line 3182 + char *xp = (char *) *xpp; +#line 3182 + int status = NC_NOERR; +#line 3182 + +#line 3182 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3182 + { +#line 3182 + int lstatus = ncx_put_short_double(xp, tp, fillp); +#line 3182 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3182 + status = lstatus; +#line 3182 + } +#line 3182 + +#line 3182 + *xpp = (void *)xp; +#line 3182 + return status; +#line 3182 +#endif +#line 3182 +} +#line 3182 + +int +#line 3183 +ncx_putn_short_longlong(void **xpp, size_t nelems, const longlong *tp, void *fillp) +#line 3183 +{ +#line 3183 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3183 + +#line 3183 + /* basic algorithm is: +#line 3183 + * - ensure sane alignment of output data +#line 3183 + * - copy (conversion happens automatically) input data +#line 3183 + * to output +#line 3183 + * - update tp to point at next unconverted input, and xpp to point +#line 3183 + * at next location for converted output +#line 3183 + */ +#line 3183 + long i, j, ni; +#line 3183 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3183 + short *xp; +#line 3183 + int nrange = 0; /* number of range errors */ +#line 3183 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3183 + long cxp = (long) *((char**)xpp); +#line 3183 + +#line 3183 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3183 + /* sjl: manually stripmine so we can limit amount of +#line 3183 + * vector work space reserved to LOOPCNT elements. Also +#line 3183 + * makes vectorisation easy */ +#line 3183 + for (j=0; j= 0 */ +#line 3183 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3183 + nrange += tp[i] > X_SHORT_MAX || tp[i] < X_SHORT_MIN; +#line 3183 + } +#line 3183 + /* copy workspace back if necessary */ +#line 3183 + if (realign) { +#line 3183 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_SHORT); +#line 3183 + xp = (short *) *xpp; +#line 3183 + } +#line 3183 + /* update xpp and tp */ +#line 3183 + xp += ni; +#line 3183 + tp += ni; +#line 3183 + *xpp = (void*)xp; +#line 3183 + } +#line 3183 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3183 + +#line 3183 +#else /* not SX */ +#line 3183 + +#line 3183 + char *xp = (char *) *xpp; +#line 3183 + int status = NC_NOERR; +#line 3183 + +#line 3183 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3183 + { +#line 3183 + int lstatus = ncx_put_short_longlong(xp, tp, fillp); +#line 3183 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3183 + status = lstatus; +#line 3183 + } +#line 3183 + +#line 3183 + *xpp = (void *)xp; +#line 3183 + return status; +#line 3183 +#endif +#line 3183 +} +#line 3183 + +int +#line 3184 +ncx_putn_short_uchar(void **xpp, size_t nelems, const uchar *tp, void *fillp) +#line 3184 +{ +#line 3184 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3184 + +#line 3184 + /* basic algorithm is: +#line 3184 + * - ensure sane alignment of output data +#line 3184 + * - copy (conversion happens automatically) input data +#line 3184 + * to output +#line 3184 + * - update tp to point at next unconverted input, and xpp to point +#line 3184 + * at next location for converted output +#line 3184 + */ +#line 3184 + long i, j, ni; +#line 3184 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3184 + short *xp; +#line 3184 + int nrange = 0; /* number of range errors */ +#line 3184 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3184 + long cxp = (long) *((char**)xpp); +#line 3184 + +#line 3184 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3184 + /* sjl: manually stripmine so we can limit amount of +#line 3184 + * vector work space reserved to LOOPCNT elements. Also +#line 3184 + * makes vectorisation easy */ +#line 3184 + for (j=0; j= 0 */ +#line 3184 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3184 + nrange += tp[i] > X_SHORT_MAX ; +#line 3184 + } +#line 3184 + /* copy workspace back if necessary */ +#line 3184 + if (realign) { +#line 3184 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_SHORT); +#line 3184 + xp = (short *) *xpp; +#line 3184 + } +#line 3184 + /* update xpp and tp */ +#line 3184 + xp += ni; +#line 3184 + tp += ni; +#line 3184 + *xpp = (void*)xp; +#line 3184 + } +#line 3184 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3184 + +#line 3184 +#else /* not SX */ +#line 3184 + +#line 3184 + char *xp = (char *) *xpp; +#line 3184 + int status = NC_NOERR; +#line 3184 + +#line 3184 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3184 + { +#line 3184 + int lstatus = ncx_put_short_uchar(xp, tp, fillp); +#line 3184 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3184 + status = lstatus; +#line 3184 + } +#line 3184 + +#line 3184 + *xpp = (void *)xp; +#line 3184 + return status; +#line 3184 +#endif +#line 3184 +} +#line 3184 + +int +#line 3185 +ncx_putn_short_uint(void **xpp, size_t nelems, const uint *tp, void *fillp) +#line 3185 +{ +#line 3185 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3185 + +#line 3185 + /* basic algorithm is: +#line 3185 + * - ensure sane alignment of output data +#line 3185 + * - copy (conversion happens automatically) input data +#line 3185 + * to output +#line 3185 + * - update tp to point at next unconverted input, and xpp to point +#line 3185 + * at next location for converted output +#line 3185 + */ +#line 3185 + long i, j, ni; +#line 3185 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3185 + short *xp; +#line 3185 + int nrange = 0; /* number of range errors */ +#line 3185 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3185 + long cxp = (long) *((char**)xpp); +#line 3185 + +#line 3185 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3185 + /* sjl: manually stripmine so we can limit amount of +#line 3185 + * vector work space reserved to LOOPCNT elements. Also +#line 3185 + * makes vectorisation easy */ +#line 3185 + for (j=0; j= 0 */ +#line 3185 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3185 + nrange += tp[i] > X_SHORT_MAX ; +#line 3185 + } +#line 3185 + /* copy workspace back if necessary */ +#line 3185 + if (realign) { +#line 3185 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_SHORT); +#line 3185 + xp = (short *) *xpp; +#line 3185 + } +#line 3185 + /* update xpp and tp */ +#line 3185 + xp += ni; +#line 3185 + tp += ni; +#line 3185 + *xpp = (void*)xp; +#line 3185 + } +#line 3185 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3185 + +#line 3185 +#else /* not SX */ +#line 3185 + +#line 3185 + char *xp = (char *) *xpp; +#line 3185 + int status = NC_NOERR; +#line 3185 + +#line 3185 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3185 + { +#line 3185 + int lstatus = ncx_put_short_uint(xp, tp, fillp); +#line 3185 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3185 + status = lstatus; +#line 3185 + } +#line 3185 + +#line 3185 + *xpp = (void *)xp; +#line 3185 + return status; +#line 3185 +#endif +#line 3185 +} +#line 3185 + +int +#line 3186 +ncx_putn_short_ulonglong(void **xpp, size_t nelems, const ulonglong *tp, void *fillp) +#line 3186 +{ +#line 3186 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3186 + +#line 3186 + /* basic algorithm is: +#line 3186 + * - ensure sane alignment of output data +#line 3186 + * - copy (conversion happens automatically) input data +#line 3186 + * to output +#line 3186 + * - update tp to point at next unconverted input, and xpp to point +#line 3186 + * at next location for converted output +#line 3186 + */ +#line 3186 + long i, j, ni; +#line 3186 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3186 + short *xp; +#line 3186 + int nrange = 0; /* number of range errors */ +#line 3186 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3186 + long cxp = (long) *((char**)xpp); +#line 3186 + +#line 3186 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3186 + /* sjl: manually stripmine so we can limit amount of +#line 3186 + * vector work space reserved to LOOPCNT elements. Also +#line 3186 + * makes vectorisation easy */ +#line 3186 + for (j=0; j= 0 */ +#line 3186 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3186 + nrange += tp[i] > X_SHORT_MAX ; +#line 3186 + } +#line 3186 + /* copy workspace back if necessary */ +#line 3186 + if (realign) { +#line 3186 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_SHORT); +#line 3186 + xp = (short *) *xpp; +#line 3186 + } +#line 3186 + /* update xpp and tp */ +#line 3186 + xp += ni; +#line 3186 + tp += ni; +#line 3186 + *xpp = (void*)xp; +#line 3186 + } +#line 3186 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3186 + +#line 3186 +#else /* not SX */ +#line 3186 + +#line 3186 + char *xp = (char *) *xpp; +#line 3186 + int status = NC_NOERR; +#line 3186 + +#line 3186 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3186 + { +#line 3186 + int lstatus = ncx_put_short_ulonglong(xp, tp, fillp); +#line 3186 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3186 + status = lstatus; +#line 3186 + } +#line 3186 + +#line 3186 + *xpp = (void *)xp; +#line 3186 + return status; +#line 3186 +#endif +#line 3186 +} +#line 3186 + +int +#line 3187 +ncx_putn_short_ushort(void **xpp, size_t nelems, const ushort *tp, void *fillp) +#line 3187 +{ +#line 3187 +#if defined(_SX) && _SX != 0 && X_SIZEOF_SHORT == SIZEOF_SHORT +#line 3187 + +#line 3187 + /* basic algorithm is: +#line 3187 + * - ensure sane alignment of output data +#line 3187 + * - copy (conversion happens automatically) input data +#line 3187 + * to output +#line 3187 + * - update tp to point at next unconverted input, and xpp to point +#line 3187 + * at next location for converted output +#line 3187 + */ +#line 3187 + long i, j, ni; +#line 3187 + short tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3187 + short *xp; +#line 3187 + int nrange = 0; /* number of range errors */ +#line 3187 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3187 + long cxp = (long) *((char**)xpp); +#line 3187 + +#line 3187 + realign = (cxp & 7) % SIZEOF_SHORT; +#line 3187 + /* sjl: manually stripmine so we can limit amount of +#line 3187 + * vector work space reserved to LOOPCNT elements. Also +#line 3187 + * makes vectorisation easy */ +#line 3187 + for (j=0; j= 0 */ +#line 3187 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3187 + nrange += tp[i] > X_SHORT_MAX ; +#line 3187 + } +#line 3187 + /* copy workspace back if necessary */ +#line 3187 + if (realign) { +#line 3187 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_SHORT); +#line 3187 + xp = (short *) *xpp; +#line 3187 + } +#line 3187 + /* update xpp and tp */ +#line 3187 + xp += ni; +#line 3187 + tp += ni; +#line 3187 + *xpp = (void*)xp; +#line 3187 + } +#line 3187 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3187 + +#line 3187 +#else /* not SX */ +#line 3187 + +#line 3187 + char *xp = (char *) *xpp; +#line 3187 + int status = NC_NOERR; +#line 3187 + +#line 3187 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3187 + { +#line 3187 + int lstatus = ncx_put_short_ushort(xp, tp, fillp); +#line 3187 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3187 + status = lstatus; +#line 3187 + } +#line 3187 + +#line 3187 + *xpp = (void *)xp; +#line 3187 + return status; +#line 3187 +#endif +#line 3187 +} +#line 3187 + + +int +#line 3189 +ncx_pad_putn_short_schar(void **xpp, size_t nelems, const schar *tp, void *fillp) +#line 3189 +{ +#line 3189 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3189 + +#line 3189 + char *xp = (char *) *xpp; +#line 3189 + int status = NC_NOERR; +#line 3189 + +#line 3189 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3189 + { +#line 3189 + int lstatus = ncx_put_short_schar(xp, tp, fillp); +#line 3189 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3189 + status = lstatus; +#line 3189 + } +#line 3189 + +#line 3189 + if (rndup != 0) +#line 3189 + { +#line 3189 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_SHORT)); +#line 3189 + xp += X_SIZEOF_SHORT; +#line 3189 + } +#line 3189 + +#line 3189 + *xpp = (void *)xp; +#line 3189 + return status; +#line 3189 +} +#line 3189 + +int +#line 3190 +ncx_pad_putn_short_uchar(void **xpp, size_t nelems, const uchar *tp, void *fillp) +#line 3190 +{ +#line 3190 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3190 + +#line 3190 + char *xp = (char *) *xpp; +#line 3190 + int status = NC_NOERR; +#line 3190 + +#line 3190 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3190 + { +#line 3190 + int lstatus = ncx_put_short_uchar(xp, tp, fillp); +#line 3190 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3190 + status = lstatus; +#line 3190 + } +#line 3190 + +#line 3190 + if (rndup != 0) +#line 3190 + { +#line 3190 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_SHORT)); +#line 3190 + xp += X_SIZEOF_SHORT; +#line 3190 + } +#line 3190 + +#line 3190 + *xpp = (void *)xp; +#line 3190 + return status; +#line 3190 +} +#line 3190 + +int +#line 3191 +ncx_pad_putn_short_short(void **xpp, size_t nelems, const short *tp, void *fillp) +#line 3191 +{ +#line 3191 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3191 + +#line 3191 + char *xp = (char *) *xpp; +#line 3191 + int status = NC_NOERR; +#line 3191 + +#line 3191 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3191 + { +#line 3191 + int lstatus = ncx_put_short_short(xp, tp, fillp); +#line 3191 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3191 + status = lstatus; +#line 3191 + } +#line 3191 + +#line 3191 + if (rndup != 0) +#line 3191 + { +#line 3191 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_SHORT)); +#line 3191 + xp += X_SIZEOF_SHORT; +#line 3191 + } +#line 3191 + +#line 3191 + *xpp = (void *)xp; +#line 3191 + return status; +#line 3191 +} +#line 3191 + +int +#line 3192 +ncx_pad_putn_short_int(void **xpp, size_t nelems, const int *tp, void *fillp) +#line 3192 +{ +#line 3192 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3192 + +#line 3192 + char *xp = (char *) *xpp; +#line 3192 + int status = NC_NOERR; +#line 3192 + +#line 3192 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3192 + { +#line 3192 + int lstatus = ncx_put_short_int(xp, tp, fillp); +#line 3192 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3192 + status = lstatus; +#line 3192 + } +#line 3192 + +#line 3192 + if (rndup != 0) +#line 3192 + { +#line 3192 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_SHORT)); +#line 3192 + xp += X_SIZEOF_SHORT; +#line 3192 + } +#line 3192 + +#line 3192 + *xpp = (void *)xp; +#line 3192 + return status; +#line 3192 +} +#line 3192 + +int +#line 3193 +ncx_pad_putn_short_long(void **xpp, size_t nelems, const long *tp, void *fillp) +#line 3193 +{ +#line 3193 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3193 + +#line 3193 + char *xp = (char *) *xpp; +#line 3193 + int status = NC_NOERR; +#line 3193 + +#line 3193 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3193 + { +#line 3193 + int lstatus = ncx_put_short_long(xp, tp, fillp); +#line 3193 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3193 + status = lstatus; +#line 3193 + } +#line 3193 + +#line 3193 + if (rndup != 0) +#line 3193 + { +#line 3193 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_SHORT)); +#line 3193 + xp += X_SIZEOF_SHORT; +#line 3193 + } +#line 3193 + +#line 3193 + *xpp = (void *)xp; +#line 3193 + return status; +#line 3193 +} +#line 3193 + +int +#line 3194 +ncx_pad_putn_short_float(void **xpp, size_t nelems, const float *tp, void *fillp) +#line 3194 +{ +#line 3194 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3194 + +#line 3194 + char *xp = (char *) *xpp; +#line 3194 + int status = NC_NOERR; +#line 3194 + +#line 3194 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3194 + { +#line 3194 + int lstatus = ncx_put_short_float(xp, tp, fillp); +#line 3194 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3194 + status = lstatus; +#line 3194 + } +#line 3194 + +#line 3194 + if (rndup != 0) +#line 3194 + { +#line 3194 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_SHORT)); +#line 3194 + xp += X_SIZEOF_SHORT; +#line 3194 + } +#line 3194 + +#line 3194 + *xpp = (void *)xp; +#line 3194 + return status; +#line 3194 +} +#line 3194 + +int +#line 3195 +ncx_pad_putn_short_double(void **xpp, size_t nelems, const double *tp, void *fillp) +#line 3195 +{ +#line 3195 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3195 + +#line 3195 + char *xp = (char *) *xpp; +#line 3195 + int status = NC_NOERR; +#line 3195 + +#line 3195 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3195 + { +#line 3195 + int lstatus = ncx_put_short_double(xp, tp, fillp); +#line 3195 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3195 + status = lstatus; +#line 3195 + } +#line 3195 + +#line 3195 + if (rndup != 0) +#line 3195 + { +#line 3195 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_SHORT)); +#line 3195 + xp += X_SIZEOF_SHORT; +#line 3195 + } +#line 3195 + +#line 3195 + *xpp = (void *)xp; +#line 3195 + return status; +#line 3195 +} +#line 3195 + +int +#line 3196 +ncx_pad_putn_short_uint(void **xpp, size_t nelems, const uint *tp, void *fillp) +#line 3196 +{ +#line 3196 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3196 + +#line 3196 + char *xp = (char *) *xpp; +#line 3196 + int status = NC_NOERR; +#line 3196 + +#line 3196 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3196 + { +#line 3196 + int lstatus = ncx_put_short_uint(xp, tp, fillp); +#line 3196 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3196 + status = lstatus; +#line 3196 + } +#line 3196 + +#line 3196 + if (rndup != 0) +#line 3196 + { +#line 3196 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_SHORT)); +#line 3196 + xp += X_SIZEOF_SHORT; +#line 3196 + } +#line 3196 + +#line 3196 + *xpp = (void *)xp; +#line 3196 + return status; +#line 3196 +} +#line 3196 + +int +#line 3197 +ncx_pad_putn_short_longlong(void **xpp, size_t nelems, const longlong *tp, void *fillp) +#line 3197 +{ +#line 3197 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3197 + +#line 3197 + char *xp = (char *) *xpp; +#line 3197 + int status = NC_NOERR; +#line 3197 + +#line 3197 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3197 + { +#line 3197 + int lstatus = ncx_put_short_longlong(xp, tp, fillp); +#line 3197 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3197 + status = lstatus; +#line 3197 + } +#line 3197 + +#line 3197 + if (rndup != 0) +#line 3197 + { +#line 3197 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_SHORT)); +#line 3197 + xp += X_SIZEOF_SHORT; +#line 3197 + } +#line 3197 + +#line 3197 + *xpp = (void *)xp; +#line 3197 + return status; +#line 3197 +} +#line 3197 + +int +#line 3198 +ncx_pad_putn_short_ulonglong(void **xpp, size_t nelems, const ulonglong *tp, void *fillp) +#line 3198 +{ +#line 3198 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3198 + +#line 3198 + char *xp = (char *) *xpp; +#line 3198 + int status = NC_NOERR; +#line 3198 + +#line 3198 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3198 + { +#line 3198 + int lstatus = ncx_put_short_ulonglong(xp, tp, fillp); +#line 3198 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3198 + status = lstatus; +#line 3198 + } +#line 3198 + +#line 3198 + if (rndup != 0) +#line 3198 + { +#line 3198 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_SHORT)); +#line 3198 + xp += X_SIZEOF_SHORT; +#line 3198 + } +#line 3198 + +#line 3198 + *xpp = (void *)xp; +#line 3198 + return status; +#line 3198 +} +#line 3198 + +int +#line 3199 +ncx_pad_putn_short_ushort(void **xpp, size_t nelems, const ushort *tp, void *fillp) +#line 3199 +{ +#line 3199 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3199 + +#line 3199 + char *xp = (char *) *xpp; +#line 3199 + int status = NC_NOERR; +#line 3199 + +#line 3199 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) +#line 3199 + { +#line 3199 + int lstatus = ncx_put_short_ushort(xp, tp, fillp); +#line 3199 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3199 + status = lstatus; +#line 3199 + } +#line 3199 + +#line 3199 + if (rndup != 0) +#line 3199 + { +#line 3199 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_SHORT)); +#line 3199 + xp += X_SIZEOF_SHORT; +#line 3199 + } +#line 3199 + +#line 3199 + *xpp = (void *)xp; +#line 3199 + return status; +#line 3199 +} +#line 3199 + + + +/* ushort --------------------------------------------------------------------*/ + +#if X_SIZEOF_USHORT == SIZEOF_USHORT +/* optimized version */ +int +ncx_getn_ushort_ushort(const void **xpp, size_t nelems, unsigned short *tp) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(tp, *xpp, (size_t)nelems * SIZEOF_USHORT); +# else + swapn2b(tp, *xpp, nelems); +# endif + *xpp = (const void *)((const char *)(*xpp) + nelems * X_SIZEOF_USHORT); + return NC_NOERR; +} +#else +int +#line 3218 +ncx_getn_ushort_ushort(const void **xpp, size_t nelems, ushort *tp) +#line 3218 +{ +#line 3218 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3218 + +#line 3218 + /* basic algorithm is: +#line 3218 + * - ensure sane alignment of input data +#line 3218 + * - copy (conversion happens automatically) input data +#line 3218 + * to output +#line 3218 + * - update xpp to point at next unconverted input, and tp to point +#line 3218 + * at next location for converted output +#line 3218 + */ +#line 3218 + long i, j, ni; +#line 3218 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3218 + ushort *xp; +#line 3218 + int nrange = 0; /* number of range errors */ +#line 3218 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3218 + long cxp = (long) *((char**)xpp); +#line 3218 + +#line 3218 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3218 + /* sjl: manually stripmine so we can limit amount of +#line 3218 + * vector work space reserved to LOOPCNT elements. Also +#line 3218 + * makes vectorisation easy */ +#line 3218 + for (j=0; j= 0 */ +#line 3218 + nrange += xp[i] > USHORT_MAX ; +#line 3218 + } +#line 3218 + /* update xpp and tp */ +#line 3218 + if (realign) xp = (ushort *) *xpp; +#line 3218 + xp += ni; +#line 3218 + tp += ni; +#line 3218 + *xpp = (void*)xp; +#line 3218 + } +#line 3218 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3218 + +#line 3218 +#else /* not SX */ +#line 3218 + const char *xp = (const char *) *xpp; +#line 3218 + int status = NC_NOERR; +#line 3218 + +#line 3218 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3218 + { +#line 3218 + const int lstatus = ncx_get_ushort_ushort(xp, tp); +#line 3218 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3218 + status = lstatus; +#line 3218 + } +#line 3218 + +#line 3218 + *xpp = (const void *)xp; +#line 3218 + return status; +#line 3218 +#endif +#line 3218 +} +#line 3218 + +#endif +int +#line 3220 +ncx_getn_ushort_schar(const void **xpp, size_t nelems, schar *tp) +#line 3220 +{ +#line 3220 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3220 + +#line 3220 + /* basic algorithm is: +#line 3220 + * - ensure sane alignment of input data +#line 3220 + * - copy (conversion happens automatically) input data +#line 3220 + * to output +#line 3220 + * - update xpp to point at next unconverted input, and tp to point +#line 3220 + * at next location for converted output +#line 3220 + */ +#line 3220 + long i, j, ni; +#line 3220 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3220 + ushort *xp; +#line 3220 + int nrange = 0; /* number of range errors */ +#line 3220 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3220 + long cxp = (long) *((char**)xpp); +#line 3220 + +#line 3220 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3220 + /* sjl: manually stripmine so we can limit amount of +#line 3220 + * vector work space reserved to LOOPCNT elements. Also +#line 3220 + * makes vectorisation easy */ +#line 3220 + for (j=0; j= 0 */ +#line 3220 + nrange += xp[i] > SCHAR_MAX ; +#line 3220 + } +#line 3220 + /* update xpp and tp */ +#line 3220 + if (realign) xp = (ushort *) *xpp; +#line 3220 + xp += ni; +#line 3220 + tp += ni; +#line 3220 + *xpp = (void*)xp; +#line 3220 + } +#line 3220 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3220 + +#line 3220 +#else /* not SX */ +#line 3220 + const char *xp = (const char *) *xpp; +#line 3220 + int status = NC_NOERR; +#line 3220 + +#line 3220 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3220 + { +#line 3220 + const int lstatus = ncx_get_ushort_schar(xp, tp); +#line 3220 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3220 + status = lstatus; +#line 3220 + } +#line 3220 + +#line 3220 + *xpp = (const void *)xp; +#line 3220 + return status; +#line 3220 +#endif +#line 3220 +} +#line 3220 + +int +#line 3221 +ncx_getn_ushort_short(const void **xpp, size_t nelems, short *tp) +#line 3221 +{ +#line 3221 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3221 + +#line 3221 + /* basic algorithm is: +#line 3221 + * - ensure sane alignment of input data +#line 3221 + * - copy (conversion happens automatically) input data +#line 3221 + * to output +#line 3221 + * - update xpp to point at next unconverted input, and tp to point +#line 3221 + * at next location for converted output +#line 3221 + */ +#line 3221 + long i, j, ni; +#line 3221 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3221 + ushort *xp; +#line 3221 + int nrange = 0; /* number of range errors */ +#line 3221 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3221 + long cxp = (long) *((char**)xpp); +#line 3221 + +#line 3221 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3221 + /* sjl: manually stripmine so we can limit amount of +#line 3221 + * vector work space reserved to LOOPCNT elements. Also +#line 3221 + * makes vectorisation easy */ +#line 3221 + for (j=0; j= 0 */ +#line 3221 + nrange += xp[i] > SHORT_MAX ; +#line 3221 + } +#line 3221 + /* update xpp and tp */ +#line 3221 + if (realign) xp = (ushort *) *xpp; +#line 3221 + xp += ni; +#line 3221 + tp += ni; +#line 3221 + *xpp = (void*)xp; +#line 3221 + } +#line 3221 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3221 + +#line 3221 +#else /* not SX */ +#line 3221 + const char *xp = (const char *) *xpp; +#line 3221 + int status = NC_NOERR; +#line 3221 + +#line 3221 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3221 + { +#line 3221 + const int lstatus = ncx_get_ushort_short(xp, tp); +#line 3221 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3221 + status = lstatus; +#line 3221 + } +#line 3221 + +#line 3221 + *xpp = (const void *)xp; +#line 3221 + return status; +#line 3221 +#endif +#line 3221 +} +#line 3221 + +int +#line 3222 +ncx_getn_ushort_int(const void **xpp, size_t nelems, int *tp) +#line 3222 +{ +#line 3222 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3222 + +#line 3222 + /* basic algorithm is: +#line 3222 + * - ensure sane alignment of input data +#line 3222 + * - copy (conversion happens automatically) input data +#line 3222 + * to output +#line 3222 + * - update xpp to point at next unconverted input, and tp to point +#line 3222 + * at next location for converted output +#line 3222 + */ +#line 3222 + long i, j, ni; +#line 3222 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3222 + ushort *xp; +#line 3222 + int nrange = 0; /* number of range errors */ +#line 3222 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3222 + long cxp = (long) *((char**)xpp); +#line 3222 + +#line 3222 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3222 + /* sjl: manually stripmine so we can limit amount of +#line 3222 + * vector work space reserved to LOOPCNT elements. Also +#line 3222 + * makes vectorisation easy */ +#line 3222 + for (j=0; j= 0 */ +#line 3222 + nrange += xp[i] > INT_MAX ; +#line 3222 + } +#line 3222 + /* update xpp and tp */ +#line 3222 + if (realign) xp = (ushort *) *xpp; +#line 3222 + xp += ni; +#line 3222 + tp += ni; +#line 3222 + *xpp = (void*)xp; +#line 3222 + } +#line 3222 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3222 + +#line 3222 +#else /* not SX */ +#line 3222 + const char *xp = (const char *) *xpp; +#line 3222 + int status = NC_NOERR; +#line 3222 + +#line 3222 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3222 + { +#line 3222 + const int lstatus = ncx_get_ushort_int(xp, tp); +#line 3222 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3222 + status = lstatus; +#line 3222 + } +#line 3222 + +#line 3222 + *xpp = (const void *)xp; +#line 3222 + return status; +#line 3222 +#endif +#line 3222 +} +#line 3222 + +int +#line 3223 +ncx_getn_ushort_long(const void **xpp, size_t nelems, long *tp) +#line 3223 +{ +#line 3223 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3223 + +#line 3223 + /* basic algorithm is: +#line 3223 + * - ensure sane alignment of input data +#line 3223 + * - copy (conversion happens automatically) input data +#line 3223 + * to output +#line 3223 + * - update xpp to point at next unconverted input, and tp to point +#line 3223 + * at next location for converted output +#line 3223 + */ +#line 3223 + long i, j, ni; +#line 3223 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3223 + ushort *xp; +#line 3223 + int nrange = 0; /* number of range errors */ +#line 3223 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3223 + long cxp = (long) *((char**)xpp); +#line 3223 + +#line 3223 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3223 + /* sjl: manually stripmine so we can limit amount of +#line 3223 + * vector work space reserved to LOOPCNT elements. Also +#line 3223 + * makes vectorisation easy */ +#line 3223 + for (j=0; j= 0 */ +#line 3223 + nrange += xp[i] > LONG_MAX ; +#line 3223 + } +#line 3223 + /* update xpp and tp */ +#line 3223 + if (realign) xp = (ushort *) *xpp; +#line 3223 + xp += ni; +#line 3223 + tp += ni; +#line 3223 + *xpp = (void*)xp; +#line 3223 + } +#line 3223 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3223 + +#line 3223 +#else /* not SX */ +#line 3223 + const char *xp = (const char *) *xpp; +#line 3223 + int status = NC_NOERR; +#line 3223 + +#line 3223 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3223 + { +#line 3223 + const int lstatus = ncx_get_ushort_long(xp, tp); +#line 3223 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3223 + status = lstatus; +#line 3223 + } +#line 3223 + +#line 3223 + *xpp = (const void *)xp; +#line 3223 + return status; +#line 3223 +#endif +#line 3223 +} +#line 3223 + +int +#line 3224 +ncx_getn_ushort_float(const void **xpp, size_t nelems, float *tp) +#line 3224 +{ +#line 3224 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3224 + +#line 3224 + /* basic algorithm is: +#line 3224 + * - ensure sane alignment of input data +#line 3224 + * - copy (conversion happens automatically) input data +#line 3224 + * to output +#line 3224 + * - update xpp to point at next unconverted input, and tp to point +#line 3224 + * at next location for converted output +#line 3224 + */ +#line 3224 + long i, j, ni; +#line 3224 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3224 + ushort *xp; +#line 3224 + int nrange = 0; /* number of range errors */ +#line 3224 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3224 + long cxp = (long) *((char**)xpp); +#line 3224 + +#line 3224 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3224 + /* sjl: manually stripmine so we can limit amount of +#line 3224 + * vector work space reserved to LOOPCNT elements. Also +#line 3224 + * makes vectorisation easy */ +#line 3224 + for (j=0; j= 0 */ +#line 3224 + nrange += xp[i] > FLOAT_MAX ; +#line 3224 + } +#line 3224 + /* update xpp and tp */ +#line 3224 + if (realign) xp = (ushort *) *xpp; +#line 3224 + xp += ni; +#line 3224 + tp += ni; +#line 3224 + *xpp = (void*)xp; +#line 3224 + } +#line 3224 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3224 + +#line 3224 +#else /* not SX */ +#line 3224 + const char *xp = (const char *) *xpp; +#line 3224 + int status = NC_NOERR; +#line 3224 + +#line 3224 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3224 + { +#line 3224 + const int lstatus = ncx_get_ushort_float(xp, tp); +#line 3224 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3224 + status = lstatus; +#line 3224 + } +#line 3224 + +#line 3224 + *xpp = (const void *)xp; +#line 3224 + return status; +#line 3224 +#endif +#line 3224 +} +#line 3224 + +int +#line 3225 +ncx_getn_ushort_double(const void **xpp, size_t nelems, double *tp) +#line 3225 +{ +#line 3225 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3225 + +#line 3225 + /* basic algorithm is: +#line 3225 + * - ensure sane alignment of input data +#line 3225 + * - copy (conversion happens automatically) input data +#line 3225 + * to output +#line 3225 + * - update xpp to point at next unconverted input, and tp to point +#line 3225 + * at next location for converted output +#line 3225 + */ +#line 3225 + long i, j, ni; +#line 3225 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3225 + ushort *xp; +#line 3225 + int nrange = 0; /* number of range errors */ +#line 3225 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3225 + long cxp = (long) *((char**)xpp); +#line 3225 + +#line 3225 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3225 + /* sjl: manually stripmine so we can limit amount of +#line 3225 + * vector work space reserved to LOOPCNT elements. Also +#line 3225 + * makes vectorisation easy */ +#line 3225 + for (j=0; j= 0 */ +#line 3225 + nrange += xp[i] > DOUBLE_MAX ; +#line 3225 + } +#line 3225 + /* update xpp and tp */ +#line 3225 + if (realign) xp = (ushort *) *xpp; +#line 3225 + xp += ni; +#line 3225 + tp += ni; +#line 3225 + *xpp = (void*)xp; +#line 3225 + } +#line 3225 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3225 + +#line 3225 +#else /* not SX */ +#line 3225 + const char *xp = (const char *) *xpp; +#line 3225 + int status = NC_NOERR; +#line 3225 + +#line 3225 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3225 + { +#line 3225 + const int lstatus = ncx_get_ushort_double(xp, tp); +#line 3225 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3225 + status = lstatus; +#line 3225 + } +#line 3225 + +#line 3225 + *xpp = (const void *)xp; +#line 3225 + return status; +#line 3225 +#endif +#line 3225 +} +#line 3225 + +int +#line 3226 +ncx_getn_ushort_longlong(const void **xpp, size_t nelems, longlong *tp) +#line 3226 +{ +#line 3226 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3226 + +#line 3226 + /* basic algorithm is: +#line 3226 + * - ensure sane alignment of input data +#line 3226 + * - copy (conversion happens automatically) input data +#line 3226 + * to output +#line 3226 + * - update xpp to point at next unconverted input, and tp to point +#line 3226 + * at next location for converted output +#line 3226 + */ +#line 3226 + long i, j, ni; +#line 3226 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3226 + ushort *xp; +#line 3226 + int nrange = 0; /* number of range errors */ +#line 3226 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3226 + long cxp = (long) *((char**)xpp); +#line 3226 + +#line 3226 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3226 + /* sjl: manually stripmine so we can limit amount of +#line 3226 + * vector work space reserved to LOOPCNT elements. Also +#line 3226 + * makes vectorisation easy */ +#line 3226 + for (j=0; j= 0 */ +#line 3226 + nrange += xp[i] > LONGLONG_MAX ; +#line 3226 + } +#line 3226 + /* update xpp and tp */ +#line 3226 + if (realign) xp = (ushort *) *xpp; +#line 3226 + xp += ni; +#line 3226 + tp += ni; +#line 3226 + *xpp = (void*)xp; +#line 3226 + } +#line 3226 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3226 + +#line 3226 +#else /* not SX */ +#line 3226 + const char *xp = (const char *) *xpp; +#line 3226 + int status = NC_NOERR; +#line 3226 + +#line 3226 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3226 + { +#line 3226 + const int lstatus = ncx_get_ushort_longlong(xp, tp); +#line 3226 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3226 + status = lstatus; +#line 3226 + } +#line 3226 + +#line 3226 + *xpp = (const void *)xp; +#line 3226 + return status; +#line 3226 +#endif +#line 3226 +} +#line 3226 + +int +#line 3227 +ncx_getn_ushort_uchar(const void **xpp, size_t nelems, uchar *tp) +#line 3227 +{ +#line 3227 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3227 + +#line 3227 + /* basic algorithm is: +#line 3227 + * - ensure sane alignment of input data +#line 3227 + * - copy (conversion happens automatically) input data +#line 3227 + * to output +#line 3227 + * - update xpp to point at next unconverted input, and tp to point +#line 3227 + * at next location for converted output +#line 3227 + */ +#line 3227 + long i, j, ni; +#line 3227 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3227 + ushort *xp; +#line 3227 + int nrange = 0; /* number of range errors */ +#line 3227 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3227 + long cxp = (long) *((char**)xpp); +#line 3227 + +#line 3227 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3227 + /* sjl: manually stripmine so we can limit amount of +#line 3227 + * vector work space reserved to LOOPCNT elements. Also +#line 3227 + * makes vectorisation easy */ +#line 3227 + for (j=0; j= 0 */ +#line 3227 + nrange += xp[i] > UCHAR_MAX ; +#line 3227 + } +#line 3227 + /* update xpp and tp */ +#line 3227 + if (realign) xp = (ushort *) *xpp; +#line 3227 + xp += ni; +#line 3227 + tp += ni; +#line 3227 + *xpp = (void*)xp; +#line 3227 + } +#line 3227 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3227 + +#line 3227 +#else /* not SX */ +#line 3227 + const char *xp = (const char *) *xpp; +#line 3227 + int status = NC_NOERR; +#line 3227 + +#line 3227 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3227 + { +#line 3227 + const int lstatus = ncx_get_ushort_uchar(xp, tp); +#line 3227 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3227 + status = lstatus; +#line 3227 + } +#line 3227 + +#line 3227 + *xpp = (const void *)xp; +#line 3227 + return status; +#line 3227 +#endif +#line 3227 +} +#line 3227 + +int +#line 3228 +ncx_getn_ushort_uint(const void **xpp, size_t nelems, uint *tp) +#line 3228 +{ +#line 3228 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3228 + +#line 3228 + /* basic algorithm is: +#line 3228 + * - ensure sane alignment of input data +#line 3228 + * - copy (conversion happens automatically) input data +#line 3228 + * to output +#line 3228 + * - update xpp to point at next unconverted input, and tp to point +#line 3228 + * at next location for converted output +#line 3228 + */ +#line 3228 + long i, j, ni; +#line 3228 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3228 + ushort *xp; +#line 3228 + int nrange = 0; /* number of range errors */ +#line 3228 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3228 + long cxp = (long) *((char**)xpp); +#line 3228 + +#line 3228 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3228 + /* sjl: manually stripmine so we can limit amount of +#line 3228 + * vector work space reserved to LOOPCNT elements. Also +#line 3228 + * makes vectorisation easy */ +#line 3228 + for (j=0; j= 0 */ +#line 3228 + nrange += xp[i] > UINT_MAX ; +#line 3228 + } +#line 3228 + /* update xpp and tp */ +#line 3228 + if (realign) xp = (ushort *) *xpp; +#line 3228 + xp += ni; +#line 3228 + tp += ni; +#line 3228 + *xpp = (void*)xp; +#line 3228 + } +#line 3228 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3228 + +#line 3228 +#else /* not SX */ +#line 3228 + const char *xp = (const char *) *xpp; +#line 3228 + int status = NC_NOERR; +#line 3228 + +#line 3228 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3228 + { +#line 3228 + const int lstatus = ncx_get_ushort_uint(xp, tp); +#line 3228 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3228 + status = lstatus; +#line 3228 + } +#line 3228 + +#line 3228 + *xpp = (const void *)xp; +#line 3228 + return status; +#line 3228 +#endif +#line 3228 +} +#line 3228 + +int +#line 3229 +ncx_getn_ushort_ulonglong(const void **xpp, size_t nelems, ulonglong *tp) +#line 3229 +{ +#line 3229 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3229 + +#line 3229 + /* basic algorithm is: +#line 3229 + * - ensure sane alignment of input data +#line 3229 + * - copy (conversion happens automatically) input data +#line 3229 + * to output +#line 3229 + * - update xpp to point at next unconverted input, and tp to point +#line 3229 + * at next location for converted output +#line 3229 + */ +#line 3229 + long i, j, ni; +#line 3229 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3229 + ushort *xp; +#line 3229 + int nrange = 0; /* number of range errors */ +#line 3229 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3229 + long cxp = (long) *((char**)xpp); +#line 3229 + +#line 3229 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3229 + /* sjl: manually stripmine so we can limit amount of +#line 3229 + * vector work space reserved to LOOPCNT elements. Also +#line 3229 + * makes vectorisation easy */ +#line 3229 + for (j=0; j= 0 */ +#line 3229 + nrange += xp[i] > ULONGLONG_MAX ; +#line 3229 + } +#line 3229 + /* update xpp and tp */ +#line 3229 + if (realign) xp = (ushort *) *xpp; +#line 3229 + xp += ni; +#line 3229 + tp += ni; +#line 3229 + *xpp = (void*)xp; +#line 3229 + } +#line 3229 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3229 + +#line 3229 +#else /* not SX */ +#line 3229 + const char *xp = (const char *) *xpp; +#line 3229 + int status = NC_NOERR; +#line 3229 + +#line 3229 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3229 + { +#line 3229 + const int lstatus = ncx_get_ushort_ulonglong(xp, tp); +#line 3229 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3229 + status = lstatus; +#line 3229 + } +#line 3229 + +#line 3229 + *xpp = (const void *)xp; +#line 3229 + return status; +#line 3229 +#endif +#line 3229 +} +#line 3229 + + +int +#line 3231 +ncx_pad_getn_ushort_schar(const void **xpp, size_t nelems, schar *tp) +#line 3231 +{ +#line 3231 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3231 + +#line 3231 + const char *xp = (const char *) *xpp; +#line 3231 + int status = NC_NOERR; +#line 3231 + +#line 3231 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3231 + { +#line 3231 + const int lstatus = ncx_get_ushort_schar(xp, tp); +#line 3231 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3231 + status = lstatus; +#line 3231 + } +#line 3231 + +#line 3231 + if (rndup != 0) +#line 3231 + xp += X_SIZEOF_USHORT; +#line 3231 + +#line 3231 + *xpp = (void *)xp; +#line 3231 + return status; +#line 3231 +} +#line 3231 + +int +#line 3232 +ncx_pad_getn_ushort_short(const void **xpp, size_t nelems, short *tp) +#line 3232 +{ +#line 3232 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3232 + +#line 3232 + const char *xp = (const char *) *xpp; +#line 3232 + int status = NC_NOERR; +#line 3232 + +#line 3232 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3232 + { +#line 3232 + const int lstatus = ncx_get_ushort_short(xp, tp); +#line 3232 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3232 + status = lstatus; +#line 3232 + } +#line 3232 + +#line 3232 + if (rndup != 0) +#line 3232 + xp += X_SIZEOF_USHORT; +#line 3232 + +#line 3232 + *xpp = (void *)xp; +#line 3232 + return status; +#line 3232 +} +#line 3232 + +int +#line 3233 +ncx_pad_getn_ushort_int(const void **xpp, size_t nelems, int *tp) +#line 3233 +{ +#line 3233 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3233 + +#line 3233 + const char *xp = (const char *) *xpp; +#line 3233 + int status = NC_NOERR; +#line 3233 + +#line 3233 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3233 + { +#line 3233 + const int lstatus = ncx_get_ushort_int(xp, tp); +#line 3233 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3233 + status = lstatus; +#line 3233 + } +#line 3233 + +#line 3233 + if (rndup != 0) +#line 3233 + xp += X_SIZEOF_USHORT; +#line 3233 + +#line 3233 + *xpp = (void *)xp; +#line 3233 + return status; +#line 3233 +} +#line 3233 + +int +#line 3234 +ncx_pad_getn_ushort_long(const void **xpp, size_t nelems, long *tp) +#line 3234 +{ +#line 3234 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3234 + +#line 3234 + const char *xp = (const char *) *xpp; +#line 3234 + int status = NC_NOERR; +#line 3234 + +#line 3234 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3234 + { +#line 3234 + const int lstatus = ncx_get_ushort_long(xp, tp); +#line 3234 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3234 + status = lstatus; +#line 3234 + } +#line 3234 + +#line 3234 + if (rndup != 0) +#line 3234 + xp += X_SIZEOF_USHORT; +#line 3234 + +#line 3234 + *xpp = (void *)xp; +#line 3234 + return status; +#line 3234 +} +#line 3234 + +int +#line 3235 +ncx_pad_getn_ushort_float(const void **xpp, size_t nelems, float *tp) +#line 3235 +{ +#line 3235 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3235 + +#line 3235 + const char *xp = (const char *) *xpp; +#line 3235 + int status = NC_NOERR; +#line 3235 + +#line 3235 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3235 + { +#line 3235 + const int lstatus = ncx_get_ushort_float(xp, tp); +#line 3235 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3235 + status = lstatus; +#line 3235 + } +#line 3235 + +#line 3235 + if (rndup != 0) +#line 3235 + xp += X_SIZEOF_USHORT; +#line 3235 + +#line 3235 + *xpp = (void *)xp; +#line 3235 + return status; +#line 3235 +} +#line 3235 + +int +#line 3236 +ncx_pad_getn_ushort_double(const void **xpp, size_t nelems, double *tp) +#line 3236 +{ +#line 3236 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3236 + +#line 3236 + const char *xp = (const char *) *xpp; +#line 3236 + int status = NC_NOERR; +#line 3236 + +#line 3236 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3236 + { +#line 3236 + const int lstatus = ncx_get_ushort_double(xp, tp); +#line 3236 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3236 + status = lstatus; +#line 3236 + } +#line 3236 + +#line 3236 + if (rndup != 0) +#line 3236 + xp += X_SIZEOF_USHORT; +#line 3236 + +#line 3236 + *xpp = (void *)xp; +#line 3236 + return status; +#line 3236 +} +#line 3236 + +int +#line 3237 +ncx_pad_getn_ushort_uchar(const void **xpp, size_t nelems, uchar *tp) +#line 3237 +{ +#line 3237 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3237 + +#line 3237 + const char *xp = (const char *) *xpp; +#line 3237 + int status = NC_NOERR; +#line 3237 + +#line 3237 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3237 + { +#line 3237 + const int lstatus = ncx_get_ushort_uchar(xp, tp); +#line 3237 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3237 + status = lstatus; +#line 3237 + } +#line 3237 + +#line 3237 + if (rndup != 0) +#line 3237 + xp += X_SIZEOF_USHORT; +#line 3237 + +#line 3237 + *xpp = (void *)xp; +#line 3237 + return status; +#line 3237 +} +#line 3237 + +int +#line 3238 +ncx_pad_getn_ushort_ushort(const void **xpp, size_t nelems, ushort *tp) +#line 3238 +{ +#line 3238 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3238 + +#line 3238 + const char *xp = (const char *) *xpp; +#line 3238 + int status = NC_NOERR; +#line 3238 + +#line 3238 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3238 + { +#line 3238 + const int lstatus = ncx_get_ushort_ushort(xp, tp); +#line 3238 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3238 + status = lstatus; +#line 3238 + } +#line 3238 + +#line 3238 + if (rndup != 0) +#line 3238 + xp += X_SIZEOF_USHORT; +#line 3238 + +#line 3238 + *xpp = (void *)xp; +#line 3238 + return status; +#line 3238 +} +#line 3238 + +int +#line 3239 +ncx_pad_getn_ushort_uint(const void **xpp, size_t nelems, uint *tp) +#line 3239 +{ +#line 3239 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3239 + +#line 3239 + const char *xp = (const char *) *xpp; +#line 3239 + int status = NC_NOERR; +#line 3239 + +#line 3239 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3239 + { +#line 3239 + const int lstatus = ncx_get_ushort_uint(xp, tp); +#line 3239 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3239 + status = lstatus; +#line 3239 + } +#line 3239 + +#line 3239 + if (rndup != 0) +#line 3239 + xp += X_SIZEOF_USHORT; +#line 3239 + +#line 3239 + *xpp = (void *)xp; +#line 3239 + return status; +#line 3239 +} +#line 3239 + +int +#line 3240 +ncx_pad_getn_ushort_longlong(const void **xpp, size_t nelems, longlong *tp) +#line 3240 +{ +#line 3240 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3240 + +#line 3240 + const char *xp = (const char *) *xpp; +#line 3240 + int status = NC_NOERR; +#line 3240 + +#line 3240 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3240 + { +#line 3240 + const int lstatus = ncx_get_ushort_longlong(xp, tp); +#line 3240 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3240 + status = lstatus; +#line 3240 + } +#line 3240 + +#line 3240 + if (rndup != 0) +#line 3240 + xp += X_SIZEOF_USHORT; +#line 3240 + +#line 3240 + *xpp = (void *)xp; +#line 3240 + return status; +#line 3240 +} +#line 3240 + +int +#line 3241 +ncx_pad_getn_ushort_ulonglong(const void **xpp, size_t nelems, ulonglong *tp) +#line 3241 +{ +#line 3241 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3241 + +#line 3241 + const char *xp = (const char *) *xpp; +#line 3241 + int status = NC_NOERR; +#line 3241 + +#line 3241 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3241 + { +#line 3241 + const int lstatus = ncx_get_ushort_ulonglong(xp, tp); +#line 3241 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3241 + status = lstatus; +#line 3241 + } +#line 3241 + +#line 3241 + if (rndup != 0) +#line 3241 + xp += X_SIZEOF_USHORT; +#line 3241 + +#line 3241 + *xpp = (void *)xp; +#line 3241 + return status; +#line 3241 +} +#line 3241 + + +#if X_SIZEOF_USHORT == SIZEOF_USHORT +/* optimized version */ +int +ncx_putn_ushort_ushort(void **xpp, size_t nelems, const unsigned short *tp, void *fillp) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(*xpp, tp, (size_t)nelems * X_SIZEOF_USHORT); +# else + swapn2b(*xpp, tp, nelems); +# endif + *xpp = (void *)((char *)(*xpp) + nelems * X_SIZEOF_USHORT); + return NC_NOERR; +} +#else +int +#line 3257 +ncx_putn_ushort_ushort(void **xpp, size_t nelems, const ushort *tp, void *fillp) +#line 3257 +{ +#line 3257 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3257 + +#line 3257 + /* basic algorithm is: +#line 3257 + * - ensure sane alignment of output data +#line 3257 + * - copy (conversion happens automatically) input data +#line 3257 + * to output +#line 3257 + * - update tp to point at next unconverted input, and xpp to point +#line 3257 + * at next location for converted output +#line 3257 + */ +#line 3257 + long i, j, ni; +#line 3257 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3257 + ushort *xp; +#line 3257 + int nrange = 0; /* number of range errors */ +#line 3257 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3257 + long cxp = (long) *((char**)xpp); +#line 3257 + +#line 3257 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3257 + /* sjl: manually stripmine so we can limit amount of +#line 3257 + * vector work space reserved to LOOPCNT elements. Also +#line 3257 + * makes vectorisation easy */ +#line 3257 + for (j=0; j= 0 */ +#line 3257 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3257 + nrange += tp[i] > X_USHORT_MAX ; +#line 3257 + } +#line 3257 + /* copy workspace back if necessary */ +#line 3257 + if (realign) { +#line 3257 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_USHORT); +#line 3257 + xp = (ushort *) *xpp; +#line 3257 + } +#line 3257 + /* update xpp and tp */ +#line 3257 + xp += ni; +#line 3257 + tp += ni; +#line 3257 + *xpp = (void*)xp; +#line 3257 + } +#line 3257 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3257 + +#line 3257 +#else /* not SX */ +#line 3257 + +#line 3257 + char *xp = (char *) *xpp; +#line 3257 + int status = NC_NOERR; +#line 3257 + +#line 3257 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3257 + { +#line 3257 + int lstatus = ncx_put_ushort_ushort(xp, tp, fillp); +#line 3257 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3257 + status = lstatus; +#line 3257 + } +#line 3257 + +#line 3257 + *xpp = (void *)xp; +#line 3257 + return status; +#line 3257 +#endif +#line 3257 +} +#line 3257 + +#endif +int +#line 3259 +ncx_putn_ushort_schar(void **xpp, size_t nelems, const schar *tp, void *fillp) +#line 3259 +{ +#line 3259 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3259 + +#line 3259 + /* basic algorithm is: +#line 3259 + * - ensure sane alignment of output data +#line 3259 + * - copy (conversion happens automatically) input data +#line 3259 + * to output +#line 3259 + * - update tp to point at next unconverted input, and xpp to point +#line 3259 + * at next location for converted output +#line 3259 + */ +#line 3259 + long i, j, ni; +#line 3259 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3259 + ushort *xp; +#line 3259 + int nrange = 0; /* number of range errors */ +#line 3259 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3259 + long cxp = (long) *((char**)xpp); +#line 3259 + +#line 3259 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3259 + /* sjl: manually stripmine so we can limit amount of +#line 3259 + * vector work space reserved to LOOPCNT elements. Also +#line 3259 + * makes vectorisation easy */ +#line 3259 + for (j=0; j= 0 */ +#line 3259 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3259 + nrange += tp[i] > X_USHORT_MAX || tp[i] < 0; +#line 3259 + } +#line 3259 + /* copy workspace back if necessary */ +#line 3259 + if (realign) { +#line 3259 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_USHORT); +#line 3259 + xp = (ushort *) *xpp; +#line 3259 + } +#line 3259 + /* update xpp and tp */ +#line 3259 + xp += ni; +#line 3259 + tp += ni; +#line 3259 + *xpp = (void*)xp; +#line 3259 + } +#line 3259 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3259 + +#line 3259 +#else /* not SX */ +#line 3259 + +#line 3259 + char *xp = (char *) *xpp; +#line 3259 + int status = NC_NOERR; +#line 3259 + +#line 3259 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3259 + { +#line 3259 + int lstatus = ncx_put_ushort_schar(xp, tp, fillp); +#line 3259 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3259 + status = lstatus; +#line 3259 + } +#line 3259 + +#line 3259 + *xpp = (void *)xp; +#line 3259 + return status; +#line 3259 +#endif +#line 3259 +} +#line 3259 + +int +#line 3260 +ncx_putn_ushort_short(void **xpp, size_t nelems, const short *tp, void *fillp) +#line 3260 +{ +#line 3260 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3260 + +#line 3260 + /* basic algorithm is: +#line 3260 + * - ensure sane alignment of output data +#line 3260 + * - copy (conversion happens automatically) input data +#line 3260 + * to output +#line 3260 + * - update tp to point at next unconverted input, and xpp to point +#line 3260 + * at next location for converted output +#line 3260 + */ +#line 3260 + long i, j, ni; +#line 3260 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3260 + ushort *xp; +#line 3260 + int nrange = 0; /* number of range errors */ +#line 3260 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3260 + long cxp = (long) *((char**)xpp); +#line 3260 + +#line 3260 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3260 + /* sjl: manually stripmine so we can limit amount of +#line 3260 + * vector work space reserved to LOOPCNT elements. Also +#line 3260 + * makes vectorisation easy */ +#line 3260 + for (j=0; j= 0 */ +#line 3260 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3260 + nrange += tp[i] > X_USHORT_MAX || tp[i] < 0; +#line 3260 + } +#line 3260 + /* copy workspace back if necessary */ +#line 3260 + if (realign) { +#line 3260 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_USHORT); +#line 3260 + xp = (ushort *) *xpp; +#line 3260 + } +#line 3260 + /* update xpp and tp */ +#line 3260 + xp += ni; +#line 3260 + tp += ni; +#line 3260 + *xpp = (void*)xp; +#line 3260 + } +#line 3260 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3260 + +#line 3260 +#else /* not SX */ +#line 3260 + +#line 3260 + char *xp = (char *) *xpp; +#line 3260 + int status = NC_NOERR; +#line 3260 + +#line 3260 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3260 + { +#line 3260 + int lstatus = ncx_put_ushort_short(xp, tp, fillp); +#line 3260 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3260 + status = lstatus; +#line 3260 + } +#line 3260 + +#line 3260 + *xpp = (void *)xp; +#line 3260 + return status; +#line 3260 +#endif +#line 3260 +} +#line 3260 + +int +#line 3261 +ncx_putn_ushort_int(void **xpp, size_t nelems, const int *tp, void *fillp) +#line 3261 +{ +#line 3261 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3261 + +#line 3261 + /* basic algorithm is: +#line 3261 + * - ensure sane alignment of output data +#line 3261 + * - copy (conversion happens automatically) input data +#line 3261 + * to output +#line 3261 + * - update tp to point at next unconverted input, and xpp to point +#line 3261 + * at next location for converted output +#line 3261 + */ +#line 3261 + long i, j, ni; +#line 3261 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3261 + ushort *xp; +#line 3261 + int nrange = 0; /* number of range errors */ +#line 3261 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3261 + long cxp = (long) *((char**)xpp); +#line 3261 + +#line 3261 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3261 + /* sjl: manually stripmine so we can limit amount of +#line 3261 + * vector work space reserved to LOOPCNT elements. Also +#line 3261 + * makes vectorisation easy */ +#line 3261 + for (j=0; j= 0 */ +#line 3261 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3261 + nrange += tp[i] > X_USHORT_MAX || tp[i] < 0; +#line 3261 + } +#line 3261 + /* copy workspace back if necessary */ +#line 3261 + if (realign) { +#line 3261 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_USHORT); +#line 3261 + xp = (ushort *) *xpp; +#line 3261 + } +#line 3261 + /* update xpp and tp */ +#line 3261 + xp += ni; +#line 3261 + tp += ni; +#line 3261 + *xpp = (void*)xp; +#line 3261 + } +#line 3261 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3261 + +#line 3261 +#else /* not SX */ +#line 3261 + +#line 3261 + char *xp = (char *) *xpp; +#line 3261 + int status = NC_NOERR; +#line 3261 + +#line 3261 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3261 + { +#line 3261 + int lstatus = ncx_put_ushort_int(xp, tp, fillp); +#line 3261 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3261 + status = lstatus; +#line 3261 + } +#line 3261 + +#line 3261 + *xpp = (void *)xp; +#line 3261 + return status; +#line 3261 +#endif +#line 3261 +} +#line 3261 + +int +#line 3262 +ncx_putn_ushort_long(void **xpp, size_t nelems, const long *tp, void *fillp) +#line 3262 +{ +#line 3262 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3262 + +#line 3262 + /* basic algorithm is: +#line 3262 + * - ensure sane alignment of output data +#line 3262 + * - copy (conversion happens automatically) input data +#line 3262 + * to output +#line 3262 + * - update tp to point at next unconverted input, and xpp to point +#line 3262 + * at next location for converted output +#line 3262 + */ +#line 3262 + long i, j, ni; +#line 3262 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3262 + ushort *xp; +#line 3262 + int nrange = 0; /* number of range errors */ +#line 3262 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3262 + long cxp = (long) *((char**)xpp); +#line 3262 + +#line 3262 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3262 + /* sjl: manually stripmine so we can limit amount of +#line 3262 + * vector work space reserved to LOOPCNT elements. Also +#line 3262 + * makes vectorisation easy */ +#line 3262 + for (j=0; j= 0 */ +#line 3262 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3262 + nrange += tp[i] > X_USHORT_MAX || tp[i] < 0; +#line 3262 + } +#line 3262 + /* copy workspace back if necessary */ +#line 3262 + if (realign) { +#line 3262 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_USHORT); +#line 3262 + xp = (ushort *) *xpp; +#line 3262 + } +#line 3262 + /* update xpp and tp */ +#line 3262 + xp += ni; +#line 3262 + tp += ni; +#line 3262 + *xpp = (void*)xp; +#line 3262 + } +#line 3262 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3262 + +#line 3262 +#else /* not SX */ +#line 3262 + +#line 3262 + char *xp = (char *) *xpp; +#line 3262 + int status = NC_NOERR; +#line 3262 + +#line 3262 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3262 + { +#line 3262 + int lstatus = ncx_put_ushort_long(xp, tp, fillp); +#line 3262 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3262 + status = lstatus; +#line 3262 + } +#line 3262 + +#line 3262 + *xpp = (void *)xp; +#line 3262 + return status; +#line 3262 +#endif +#line 3262 +} +#line 3262 + +int +#line 3263 +ncx_putn_ushort_float(void **xpp, size_t nelems, const float *tp, void *fillp) +#line 3263 +{ +#line 3263 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3263 + +#line 3263 + /* basic algorithm is: +#line 3263 + * - ensure sane alignment of output data +#line 3263 + * - copy (conversion happens automatically) input data +#line 3263 + * to output +#line 3263 + * - update tp to point at next unconverted input, and xpp to point +#line 3263 + * at next location for converted output +#line 3263 + */ +#line 3263 + long i, j, ni; +#line 3263 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3263 + ushort *xp; +#line 3263 + int nrange = 0; /* number of range errors */ +#line 3263 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3263 + long cxp = (long) *((char**)xpp); +#line 3263 + +#line 3263 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3263 + /* sjl: manually stripmine so we can limit amount of +#line 3263 + * vector work space reserved to LOOPCNT elements. Also +#line 3263 + * makes vectorisation easy */ +#line 3263 + for (j=0; j= 0 */ +#line 3263 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3263 + nrange += tp[i] > X_USHORT_MAX || tp[i] < 0; +#line 3263 + } +#line 3263 + /* copy workspace back if necessary */ +#line 3263 + if (realign) { +#line 3263 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_USHORT); +#line 3263 + xp = (ushort *) *xpp; +#line 3263 + } +#line 3263 + /* update xpp and tp */ +#line 3263 + xp += ni; +#line 3263 + tp += ni; +#line 3263 + *xpp = (void*)xp; +#line 3263 + } +#line 3263 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3263 + +#line 3263 +#else /* not SX */ +#line 3263 + +#line 3263 + char *xp = (char *) *xpp; +#line 3263 + int status = NC_NOERR; +#line 3263 + +#line 3263 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3263 + { +#line 3263 + int lstatus = ncx_put_ushort_float(xp, tp, fillp); +#line 3263 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3263 + status = lstatus; +#line 3263 + } +#line 3263 + +#line 3263 + *xpp = (void *)xp; +#line 3263 + return status; +#line 3263 +#endif +#line 3263 +} +#line 3263 + +int +#line 3264 +ncx_putn_ushort_double(void **xpp, size_t nelems, const double *tp, void *fillp) +#line 3264 +{ +#line 3264 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3264 + +#line 3264 + /* basic algorithm is: +#line 3264 + * - ensure sane alignment of output data +#line 3264 + * - copy (conversion happens automatically) input data +#line 3264 + * to output +#line 3264 + * - update tp to point at next unconverted input, and xpp to point +#line 3264 + * at next location for converted output +#line 3264 + */ +#line 3264 + long i, j, ni; +#line 3264 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3264 + ushort *xp; +#line 3264 + int nrange = 0; /* number of range errors */ +#line 3264 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3264 + long cxp = (long) *((char**)xpp); +#line 3264 + +#line 3264 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3264 + /* sjl: manually stripmine so we can limit amount of +#line 3264 + * vector work space reserved to LOOPCNT elements. Also +#line 3264 + * makes vectorisation easy */ +#line 3264 + for (j=0; j= 0 */ +#line 3264 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3264 + nrange += tp[i] > X_USHORT_MAX || tp[i] < 0; +#line 3264 + } +#line 3264 + /* copy workspace back if necessary */ +#line 3264 + if (realign) { +#line 3264 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_USHORT); +#line 3264 + xp = (ushort *) *xpp; +#line 3264 + } +#line 3264 + /* update xpp and tp */ +#line 3264 + xp += ni; +#line 3264 + tp += ni; +#line 3264 + *xpp = (void*)xp; +#line 3264 + } +#line 3264 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3264 + +#line 3264 +#else /* not SX */ +#line 3264 + +#line 3264 + char *xp = (char *) *xpp; +#line 3264 + int status = NC_NOERR; +#line 3264 + +#line 3264 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3264 + { +#line 3264 + int lstatus = ncx_put_ushort_double(xp, tp, fillp); +#line 3264 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3264 + status = lstatus; +#line 3264 + } +#line 3264 + +#line 3264 + *xpp = (void *)xp; +#line 3264 + return status; +#line 3264 +#endif +#line 3264 +} +#line 3264 + +int +#line 3265 +ncx_putn_ushort_longlong(void **xpp, size_t nelems, const longlong *tp, void *fillp) +#line 3265 +{ +#line 3265 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3265 + +#line 3265 + /* basic algorithm is: +#line 3265 + * - ensure sane alignment of output data +#line 3265 + * - copy (conversion happens automatically) input data +#line 3265 + * to output +#line 3265 + * - update tp to point at next unconverted input, and xpp to point +#line 3265 + * at next location for converted output +#line 3265 + */ +#line 3265 + long i, j, ni; +#line 3265 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3265 + ushort *xp; +#line 3265 + int nrange = 0; /* number of range errors */ +#line 3265 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3265 + long cxp = (long) *((char**)xpp); +#line 3265 + +#line 3265 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3265 + /* sjl: manually stripmine so we can limit amount of +#line 3265 + * vector work space reserved to LOOPCNT elements. Also +#line 3265 + * makes vectorisation easy */ +#line 3265 + for (j=0; j= 0 */ +#line 3265 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3265 + nrange += tp[i] > X_USHORT_MAX || tp[i] < 0; +#line 3265 + } +#line 3265 + /* copy workspace back if necessary */ +#line 3265 + if (realign) { +#line 3265 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_USHORT); +#line 3265 + xp = (ushort *) *xpp; +#line 3265 + } +#line 3265 + /* update xpp and tp */ +#line 3265 + xp += ni; +#line 3265 + tp += ni; +#line 3265 + *xpp = (void*)xp; +#line 3265 + } +#line 3265 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3265 + +#line 3265 +#else /* not SX */ +#line 3265 + +#line 3265 + char *xp = (char *) *xpp; +#line 3265 + int status = NC_NOERR; +#line 3265 + +#line 3265 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3265 + { +#line 3265 + int lstatus = ncx_put_ushort_longlong(xp, tp, fillp); +#line 3265 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3265 + status = lstatus; +#line 3265 + } +#line 3265 + +#line 3265 + *xpp = (void *)xp; +#line 3265 + return status; +#line 3265 +#endif +#line 3265 +} +#line 3265 + +int +#line 3266 +ncx_putn_ushort_uchar(void **xpp, size_t nelems, const uchar *tp, void *fillp) +#line 3266 +{ +#line 3266 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3266 + +#line 3266 + /* basic algorithm is: +#line 3266 + * - ensure sane alignment of output data +#line 3266 + * - copy (conversion happens automatically) input data +#line 3266 + * to output +#line 3266 + * - update tp to point at next unconverted input, and xpp to point +#line 3266 + * at next location for converted output +#line 3266 + */ +#line 3266 + long i, j, ni; +#line 3266 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3266 + ushort *xp; +#line 3266 + int nrange = 0; /* number of range errors */ +#line 3266 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3266 + long cxp = (long) *((char**)xpp); +#line 3266 + +#line 3266 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3266 + /* sjl: manually stripmine so we can limit amount of +#line 3266 + * vector work space reserved to LOOPCNT elements. Also +#line 3266 + * makes vectorisation easy */ +#line 3266 + for (j=0; j= 0 */ +#line 3266 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3266 + nrange += tp[i] > X_USHORT_MAX ; +#line 3266 + } +#line 3266 + /* copy workspace back if necessary */ +#line 3266 + if (realign) { +#line 3266 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_USHORT); +#line 3266 + xp = (ushort *) *xpp; +#line 3266 + } +#line 3266 + /* update xpp and tp */ +#line 3266 + xp += ni; +#line 3266 + tp += ni; +#line 3266 + *xpp = (void*)xp; +#line 3266 + } +#line 3266 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3266 + +#line 3266 +#else /* not SX */ +#line 3266 + +#line 3266 + char *xp = (char *) *xpp; +#line 3266 + int status = NC_NOERR; +#line 3266 + +#line 3266 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3266 + { +#line 3266 + int lstatus = ncx_put_ushort_uchar(xp, tp, fillp); +#line 3266 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3266 + status = lstatus; +#line 3266 + } +#line 3266 + +#line 3266 + *xpp = (void *)xp; +#line 3266 + return status; +#line 3266 +#endif +#line 3266 +} +#line 3266 + +int +#line 3267 +ncx_putn_ushort_uint(void **xpp, size_t nelems, const uint *tp, void *fillp) +#line 3267 +{ +#line 3267 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3267 + +#line 3267 + /* basic algorithm is: +#line 3267 + * - ensure sane alignment of output data +#line 3267 + * - copy (conversion happens automatically) input data +#line 3267 + * to output +#line 3267 + * - update tp to point at next unconverted input, and xpp to point +#line 3267 + * at next location for converted output +#line 3267 + */ +#line 3267 + long i, j, ni; +#line 3267 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3267 + ushort *xp; +#line 3267 + int nrange = 0; /* number of range errors */ +#line 3267 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3267 + long cxp = (long) *((char**)xpp); +#line 3267 + +#line 3267 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3267 + /* sjl: manually stripmine so we can limit amount of +#line 3267 + * vector work space reserved to LOOPCNT elements. Also +#line 3267 + * makes vectorisation easy */ +#line 3267 + for (j=0; j= 0 */ +#line 3267 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3267 + nrange += tp[i] > X_USHORT_MAX ; +#line 3267 + } +#line 3267 + /* copy workspace back if necessary */ +#line 3267 + if (realign) { +#line 3267 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_USHORT); +#line 3267 + xp = (ushort *) *xpp; +#line 3267 + } +#line 3267 + /* update xpp and tp */ +#line 3267 + xp += ni; +#line 3267 + tp += ni; +#line 3267 + *xpp = (void*)xp; +#line 3267 + } +#line 3267 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3267 + +#line 3267 +#else /* not SX */ +#line 3267 + +#line 3267 + char *xp = (char *) *xpp; +#line 3267 + int status = NC_NOERR; +#line 3267 + +#line 3267 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3267 + { +#line 3267 + int lstatus = ncx_put_ushort_uint(xp, tp, fillp); +#line 3267 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3267 + status = lstatus; +#line 3267 + } +#line 3267 + +#line 3267 + *xpp = (void *)xp; +#line 3267 + return status; +#line 3267 +#endif +#line 3267 +} +#line 3267 + +int +#line 3268 +ncx_putn_ushort_ulonglong(void **xpp, size_t nelems, const ulonglong *tp, void *fillp) +#line 3268 +{ +#line 3268 +#if defined(_SX) && _SX != 0 && X_SIZEOF_USHORT == SIZEOF_USHORT +#line 3268 + +#line 3268 + /* basic algorithm is: +#line 3268 + * - ensure sane alignment of output data +#line 3268 + * - copy (conversion happens automatically) input data +#line 3268 + * to output +#line 3268 + * - update tp to point at next unconverted input, and xpp to point +#line 3268 + * at next location for converted output +#line 3268 + */ +#line 3268 + long i, j, ni; +#line 3268 + ushort tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3268 + ushort *xp; +#line 3268 + int nrange = 0; /* number of range errors */ +#line 3268 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3268 + long cxp = (long) *((char**)xpp); +#line 3268 + +#line 3268 + realign = (cxp & 7) % SIZEOF_USHORT; +#line 3268 + /* sjl: manually stripmine so we can limit amount of +#line 3268 + * vector work space reserved to LOOPCNT elements. Also +#line 3268 + * makes vectorisation easy */ +#line 3268 + for (j=0; j= 0 */ +#line 3268 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3268 + nrange += tp[i] > X_USHORT_MAX ; +#line 3268 + } +#line 3268 + /* copy workspace back if necessary */ +#line 3268 + if (realign) { +#line 3268 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_USHORT); +#line 3268 + xp = (ushort *) *xpp; +#line 3268 + } +#line 3268 + /* update xpp and tp */ +#line 3268 + xp += ni; +#line 3268 + tp += ni; +#line 3268 + *xpp = (void*)xp; +#line 3268 + } +#line 3268 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3268 + +#line 3268 +#else /* not SX */ +#line 3268 + +#line 3268 + char *xp = (char *) *xpp; +#line 3268 + int status = NC_NOERR; +#line 3268 + +#line 3268 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3268 + { +#line 3268 + int lstatus = ncx_put_ushort_ulonglong(xp, tp, fillp); +#line 3268 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3268 + status = lstatus; +#line 3268 + } +#line 3268 + +#line 3268 + *xpp = (void *)xp; +#line 3268 + return status; +#line 3268 +#endif +#line 3268 +} +#line 3268 + + +int +#line 3270 +ncx_pad_putn_ushort_schar(void **xpp, size_t nelems, const schar *tp, void *fillp) +#line 3270 +{ +#line 3270 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3270 + +#line 3270 + char *xp = (char *) *xpp; +#line 3270 + int status = NC_NOERR; +#line 3270 + +#line 3270 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3270 + { +#line 3270 + int lstatus = ncx_put_ushort_schar(xp, tp, fillp); +#line 3270 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3270 + status = lstatus; +#line 3270 + } +#line 3270 + +#line 3270 + if (rndup != 0) +#line 3270 + { +#line 3270 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_USHORT)); +#line 3270 + xp += X_SIZEOF_USHORT; +#line 3270 + } +#line 3270 + +#line 3270 + *xpp = (void *)xp; +#line 3270 + return status; +#line 3270 +} +#line 3270 + +int +#line 3271 +ncx_pad_putn_ushort_uchar(void **xpp, size_t nelems, const uchar *tp, void *fillp) +#line 3271 +{ +#line 3271 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3271 + +#line 3271 + char *xp = (char *) *xpp; +#line 3271 + int status = NC_NOERR; +#line 3271 + +#line 3271 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3271 + { +#line 3271 + int lstatus = ncx_put_ushort_uchar(xp, tp, fillp); +#line 3271 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3271 + status = lstatus; +#line 3271 + } +#line 3271 + +#line 3271 + if (rndup != 0) +#line 3271 + { +#line 3271 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_USHORT)); +#line 3271 + xp += X_SIZEOF_USHORT; +#line 3271 + } +#line 3271 + +#line 3271 + *xpp = (void *)xp; +#line 3271 + return status; +#line 3271 +} +#line 3271 + +int +#line 3272 +ncx_pad_putn_ushort_short(void **xpp, size_t nelems, const short *tp, void *fillp) +#line 3272 +{ +#line 3272 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3272 + +#line 3272 + char *xp = (char *) *xpp; +#line 3272 + int status = NC_NOERR; +#line 3272 + +#line 3272 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3272 + { +#line 3272 + int lstatus = ncx_put_ushort_short(xp, tp, fillp); +#line 3272 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3272 + status = lstatus; +#line 3272 + } +#line 3272 + +#line 3272 + if (rndup != 0) +#line 3272 + { +#line 3272 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_USHORT)); +#line 3272 + xp += X_SIZEOF_USHORT; +#line 3272 + } +#line 3272 + +#line 3272 + *xpp = (void *)xp; +#line 3272 + return status; +#line 3272 +} +#line 3272 + +int +#line 3273 +ncx_pad_putn_ushort_int(void **xpp, size_t nelems, const int *tp, void *fillp) +#line 3273 +{ +#line 3273 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3273 + +#line 3273 + char *xp = (char *) *xpp; +#line 3273 + int status = NC_NOERR; +#line 3273 + +#line 3273 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3273 + { +#line 3273 + int lstatus = ncx_put_ushort_int(xp, tp, fillp); +#line 3273 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3273 + status = lstatus; +#line 3273 + } +#line 3273 + +#line 3273 + if (rndup != 0) +#line 3273 + { +#line 3273 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_USHORT)); +#line 3273 + xp += X_SIZEOF_USHORT; +#line 3273 + } +#line 3273 + +#line 3273 + *xpp = (void *)xp; +#line 3273 + return status; +#line 3273 +} +#line 3273 + +int +#line 3274 +ncx_pad_putn_ushort_long(void **xpp, size_t nelems, const long *tp, void *fillp) +#line 3274 +{ +#line 3274 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3274 + +#line 3274 + char *xp = (char *) *xpp; +#line 3274 + int status = NC_NOERR; +#line 3274 + +#line 3274 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3274 + { +#line 3274 + int lstatus = ncx_put_ushort_long(xp, tp, fillp); +#line 3274 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3274 + status = lstatus; +#line 3274 + } +#line 3274 + +#line 3274 + if (rndup != 0) +#line 3274 + { +#line 3274 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_USHORT)); +#line 3274 + xp += X_SIZEOF_USHORT; +#line 3274 + } +#line 3274 + +#line 3274 + *xpp = (void *)xp; +#line 3274 + return status; +#line 3274 +} +#line 3274 + +int +#line 3275 +ncx_pad_putn_ushort_float(void **xpp, size_t nelems, const float *tp, void *fillp) +#line 3275 +{ +#line 3275 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3275 + +#line 3275 + char *xp = (char *) *xpp; +#line 3275 + int status = NC_NOERR; +#line 3275 + +#line 3275 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3275 + { +#line 3275 + int lstatus = ncx_put_ushort_float(xp, tp, fillp); +#line 3275 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3275 + status = lstatus; +#line 3275 + } +#line 3275 + +#line 3275 + if (rndup != 0) +#line 3275 + { +#line 3275 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_USHORT)); +#line 3275 + xp += X_SIZEOF_USHORT; +#line 3275 + } +#line 3275 + +#line 3275 + *xpp = (void *)xp; +#line 3275 + return status; +#line 3275 +} +#line 3275 + +int +#line 3276 +ncx_pad_putn_ushort_double(void **xpp, size_t nelems, const double *tp, void *fillp) +#line 3276 +{ +#line 3276 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3276 + +#line 3276 + char *xp = (char *) *xpp; +#line 3276 + int status = NC_NOERR; +#line 3276 + +#line 3276 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3276 + { +#line 3276 + int lstatus = ncx_put_ushort_double(xp, tp, fillp); +#line 3276 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3276 + status = lstatus; +#line 3276 + } +#line 3276 + +#line 3276 + if (rndup != 0) +#line 3276 + { +#line 3276 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_USHORT)); +#line 3276 + xp += X_SIZEOF_USHORT; +#line 3276 + } +#line 3276 + +#line 3276 + *xpp = (void *)xp; +#line 3276 + return status; +#line 3276 +} +#line 3276 + +int +#line 3277 +ncx_pad_putn_ushort_uint(void **xpp, size_t nelems, const uint *tp, void *fillp) +#line 3277 +{ +#line 3277 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3277 + +#line 3277 + char *xp = (char *) *xpp; +#line 3277 + int status = NC_NOERR; +#line 3277 + +#line 3277 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3277 + { +#line 3277 + int lstatus = ncx_put_ushort_uint(xp, tp, fillp); +#line 3277 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3277 + status = lstatus; +#line 3277 + } +#line 3277 + +#line 3277 + if (rndup != 0) +#line 3277 + { +#line 3277 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_USHORT)); +#line 3277 + xp += X_SIZEOF_USHORT; +#line 3277 + } +#line 3277 + +#line 3277 + *xpp = (void *)xp; +#line 3277 + return status; +#line 3277 +} +#line 3277 + +int +#line 3278 +ncx_pad_putn_ushort_longlong(void **xpp, size_t nelems, const longlong *tp, void *fillp) +#line 3278 +{ +#line 3278 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3278 + +#line 3278 + char *xp = (char *) *xpp; +#line 3278 + int status = NC_NOERR; +#line 3278 + +#line 3278 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3278 + { +#line 3278 + int lstatus = ncx_put_ushort_longlong(xp, tp, fillp); +#line 3278 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3278 + status = lstatus; +#line 3278 + } +#line 3278 + +#line 3278 + if (rndup != 0) +#line 3278 + { +#line 3278 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_USHORT)); +#line 3278 + xp += X_SIZEOF_USHORT; +#line 3278 + } +#line 3278 + +#line 3278 + *xpp = (void *)xp; +#line 3278 + return status; +#line 3278 +} +#line 3278 + +int +#line 3279 +ncx_pad_putn_ushort_ulonglong(void **xpp, size_t nelems, const ulonglong *tp, void *fillp) +#line 3279 +{ +#line 3279 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3279 + +#line 3279 + char *xp = (char *) *xpp; +#line 3279 + int status = NC_NOERR; +#line 3279 + +#line 3279 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3279 + { +#line 3279 + int lstatus = ncx_put_ushort_ulonglong(xp, tp, fillp); +#line 3279 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3279 + status = lstatus; +#line 3279 + } +#line 3279 + +#line 3279 + if (rndup != 0) +#line 3279 + { +#line 3279 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_USHORT)); +#line 3279 + xp += X_SIZEOF_USHORT; +#line 3279 + } +#line 3279 + +#line 3279 + *xpp = (void *)xp; +#line 3279 + return status; +#line 3279 +} +#line 3279 + +int +#line 3280 +ncx_pad_putn_ushort_ushort(void **xpp, size_t nelems, const ushort *tp, void *fillp) +#line 3280 +{ +#line 3280 + const size_t rndup = nelems % X_SIZEOF_SHORT; +#line 3280 + +#line 3280 + char *xp = (char *) *xpp; +#line 3280 + int status = NC_NOERR; +#line 3280 + +#line 3280 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_USHORT, tp++) +#line 3280 + { +#line 3280 + int lstatus = ncx_put_ushort_ushort(xp, tp, fillp); +#line 3280 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3280 + status = lstatus; +#line 3280 + } +#line 3280 + +#line 3280 + if (rndup != 0) +#line 3280 + { +#line 3280 + (void) memcpy(xp, nada, (size_t)(X_SIZEOF_USHORT)); +#line 3280 + xp += X_SIZEOF_USHORT; +#line 3280 + } +#line 3280 + +#line 3280 + *xpp = (void *)xp; +#line 3280 + return status; +#line 3280 +} +#line 3280 + + + +/* int -----------------------------------------------------------------------*/ + +#if X_SIZEOF_INT == SIZEOF_INT +/* optimized version */ +int +ncx_getn_int_int(const void **xpp, size_t nelems, int *tp) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(tp, *xpp, (size_t)nelems * SIZEOF_INT); +# else + swapn4b(tp, *xpp, nelems); +# endif + *xpp = (const void *)((const char *)(*xpp) + nelems * X_SIZEOF_INT); + return NC_NOERR; +} +#else +int +#line 3299 +ncx_getn_int_int(const void **xpp, size_t nelems, int *tp) +#line 3299 +{ +#line 3299 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3299 + +#line 3299 + /* basic algorithm is: +#line 3299 + * - ensure sane alignment of input data +#line 3299 + * - copy (conversion happens automatically) input data +#line 3299 + * to output +#line 3299 + * - update xpp to point at next unconverted input, and tp to point +#line 3299 + * at next location for converted output +#line 3299 + */ +#line 3299 + long i, j, ni; +#line 3299 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3299 + int *xp; +#line 3299 + int nrange = 0; /* number of range errors */ +#line 3299 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3299 + long cxp = (long) *((char**)xpp); +#line 3299 + +#line 3299 + realign = (cxp & 7) % SIZEOF_INT; +#line 3299 + /* sjl: manually stripmine so we can limit amount of +#line 3299 + * vector work space reserved to LOOPCNT elements. Also +#line 3299 + * makes vectorisation easy */ +#line 3299 + for (j=0; j= 0 */ +#line 3299 + nrange += xp[i] > INT_MAX || xp[i] < INT_MIN; +#line 3299 + } +#line 3299 + /* update xpp and tp */ +#line 3299 + if (realign) xp = (int *) *xpp; +#line 3299 + xp += ni; +#line 3299 + tp += ni; +#line 3299 + *xpp = (void*)xp; +#line 3299 + } +#line 3299 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3299 + +#line 3299 +#else /* not SX */ +#line 3299 + const char *xp = (const char *) *xpp; +#line 3299 + int status = NC_NOERR; +#line 3299 + +#line 3299 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3299 + { +#line 3299 + const int lstatus = ncx_get_int_int(xp, tp); +#line 3299 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3299 + status = lstatus; +#line 3299 + } +#line 3299 + +#line 3299 + *xpp = (const void *)xp; +#line 3299 + return status; +#line 3299 +#endif +#line 3299 +} +#line 3299 + +#endif +int +#line 3301 +ncx_getn_int_schar(const void **xpp, size_t nelems, schar *tp) +#line 3301 +{ +#line 3301 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3301 + +#line 3301 + /* basic algorithm is: +#line 3301 + * - ensure sane alignment of input data +#line 3301 + * - copy (conversion happens automatically) input data +#line 3301 + * to output +#line 3301 + * - update xpp to point at next unconverted input, and tp to point +#line 3301 + * at next location for converted output +#line 3301 + */ +#line 3301 + long i, j, ni; +#line 3301 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3301 + int *xp; +#line 3301 + int nrange = 0; /* number of range errors */ +#line 3301 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3301 + long cxp = (long) *((char**)xpp); +#line 3301 + +#line 3301 + realign = (cxp & 7) % SIZEOF_INT; +#line 3301 + /* sjl: manually stripmine so we can limit amount of +#line 3301 + * vector work space reserved to LOOPCNT elements. Also +#line 3301 + * makes vectorisation easy */ +#line 3301 + for (j=0; j= 0 */ +#line 3301 + nrange += xp[i] > SCHAR_MAX || xp[i] < SCHAR_MIN; +#line 3301 + } +#line 3301 + /* update xpp and tp */ +#line 3301 + if (realign) xp = (int *) *xpp; +#line 3301 + xp += ni; +#line 3301 + tp += ni; +#line 3301 + *xpp = (void*)xp; +#line 3301 + } +#line 3301 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3301 + +#line 3301 +#else /* not SX */ +#line 3301 + const char *xp = (const char *) *xpp; +#line 3301 + int status = NC_NOERR; +#line 3301 + +#line 3301 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3301 + { +#line 3301 + const int lstatus = ncx_get_int_schar(xp, tp); +#line 3301 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3301 + status = lstatus; +#line 3301 + } +#line 3301 + +#line 3301 + *xpp = (const void *)xp; +#line 3301 + return status; +#line 3301 +#endif +#line 3301 +} +#line 3301 + +int +#line 3302 +ncx_getn_int_short(const void **xpp, size_t nelems, short *tp) +#line 3302 +{ +#line 3302 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3302 + +#line 3302 + /* basic algorithm is: +#line 3302 + * - ensure sane alignment of input data +#line 3302 + * - copy (conversion happens automatically) input data +#line 3302 + * to output +#line 3302 + * - update xpp to point at next unconverted input, and tp to point +#line 3302 + * at next location for converted output +#line 3302 + */ +#line 3302 + long i, j, ni; +#line 3302 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3302 + int *xp; +#line 3302 + int nrange = 0; /* number of range errors */ +#line 3302 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3302 + long cxp = (long) *((char**)xpp); +#line 3302 + +#line 3302 + realign = (cxp & 7) % SIZEOF_INT; +#line 3302 + /* sjl: manually stripmine so we can limit amount of +#line 3302 + * vector work space reserved to LOOPCNT elements. Also +#line 3302 + * makes vectorisation easy */ +#line 3302 + for (j=0; j= 0 */ +#line 3302 + nrange += xp[i] > SHORT_MAX || xp[i] < SHORT_MIN; +#line 3302 + } +#line 3302 + /* update xpp and tp */ +#line 3302 + if (realign) xp = (int *) *xpp; +#line 3302 + xp += ni; +#line 3302 + tp += ni; +#line 3302 + *xpp = (void*)xp; +#line 3302 + } +#line 3302 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3302 + +#line 3302 +#else /* not SX */ +#line 3302 + const char *xp = (const char *) *xpp; +#line 3302 + int status = NC_NOERR; +#line 3302 + +#line 3302 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3302 + { +#line 3302 + const int lstatus = ncx_get_int_short(xp, tp); +#line 3302 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3302 + status = lstatus; +#line 3302 + } +#line 3302 + +#line 3302 + *xpp = (const void *)xp; +#line 3302 + return status; +#line 3302 +#endif +#line 3302 +} +#line 3302 + +int +#line 3303 +ncx_getn_int_long(const void **xpp, size_t nelems, long *tp) +#line 3303 +{ +#line 3303 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3303 + +#line 3303 + /* basic algorithm is: +#line 3303 + * - ensure sane alignment of input data +#line 3303 + * - copy (conversion happens automatically) input data +#line 3303 + * to output +#line 3303 + * - update xpp to point at next unconverted input, and tp to point +#line 3303 + * at next location for converted output +#line 3303 + */ +#line 3303 + long i, j, ni; +#line 3303 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3303 + int *xp; +#line 3303 + int nrange = 0; /* number of range errors */ +#line 3303 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3303 + long cxp = (long) *((char**)xpp); +#line 3303 + +#line 3303 + realign = (cxp & 7) % SIZEOF_INT; +#line 3303 + /* sjl: manually stripmine so we can limit amount of +#line 3303 + * vector work space reserved to LOOPCNT elements. Also +#line 3303 + * makes vectorisation easy */ +#line 3303 + for (j=0; j= 0 */ +#line 3303 + nrange += xp[i] > LONG_MAX || xp[i] < LONG_MIN; +#line 3303 + } +#line 3303 + /* update xpp and tp */ +#line 3303 + if (realign) xp = (int *) *xpp; +#line 3303 + xp += ni; +#line 3303 + tp += ni; +#line 3303 + *xpp = (void*)xp; +#line 3303 + } +#line 3303 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3303 + +#line 3303 +#else /* not SX */ +#line 3303 + const char *xp = (const char *) *xpp; +#line 3303 + int status = NC_NOERR; +#line 3303 + +#line 3303 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3303 + { +#line 3303 + const int lstatus = ncx_get_int_long(xp, tp); +#line 3303 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3303 + status = lstatus; +#line 3303 + } +#line 3303 + +#line 3303 + *xpp = (const void *)xp; +#line 3303 + return status; +#line 3303 +#endif +#line 3303 +} +#line 3303 + +int +#line 3304 +ncx_getn_int_float(const void **xpp, size_t nelems, float *tp) +#line 3304 +{ +#line 3304 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3304 + +#line 3304 + /* basic algorithm is: +#line 3304 + * - ensure sane alignment of input data +#line 3304 + * - copy (conversion happens automatically) input data +#line 3304 + * to output +#line 3304 + * - update xpp to point at next unconverted input, and tp to point +#line 3304 + * at next location for converted output +#line 3304 + */ +#line 3304 + long i, j, ni; +#line 3304 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3304 + int *xp; +#line 3304 + int nrange = 0; /* number of range errors */ +#line 3304 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3304 + long cxp = (long) *((char**)xpp); +#line 3304 + +#line 3304 + realign = (cxp & 7) % SIZEOF_INT; +#line 3304 + /* sjl: manually stripmine so we can limit amount of +#line 3304 + * vector work space reserved to LOOPCNT elements. Also +#line 3304 + * makes vectorisation easy */ +#line 3304 + for (j=0; j= 0 */ +#line 3304 + nrange += xp[i] > FLOAT_MAX || xp[i] < FLOAT_MIN; +#line 3304 + } +#line 3304 + /* update xpp and tp */ +#line 3304 + if (realign) xp = (int *) *xpp; +#line 3304 + xp += ni; +#line 3304 + tp += ni; +#line 3304 + *xpp = (void*)xp; +#line 3304 + } +#line 3304 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3304 + +#line 3304 +#else /* not SX */ +#line 3304 + const char *xp = (const char *) *xpp; +#line 3304 + int status = NC_NOERR; +#line 3304 + +#line 3304 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3304 + { +#line 3304 + const int lstatus = ncx_get_int_float(xp, tp); +#line 3304 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3304 + status = lstatus; +#line 3304 + } +#line 3304 + +#line 3304 + *xpp = (const void *)xp; +#line 3304 + return status; +#line 3304 +#endif +#line 3304 +} +#line 3304 + +int +#line 3305 +ncx_getn_int_double(const void **xpp, size_t nelems, double *tp) +#line 3305 +{ +#line 3305 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3305 + +#line 3305 + /* basic algorithm is: +#line 3305 + * - ensure sane alignment of input data +#line 3305 + * - copy (conversion happens automatically) input data +#line 3305 + * to output +#line 3305 + * - update xpp to point at next unconverted input, and tp to point +#line 3305 + * at next location for converted output +#line 3305 + */ +#line 3305 + long i, j, ni; +#line 3305 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3305 + int *xp; +#line 3305 + int nrange = 0; /* number of range errors */ +#line 3305 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3305 + long cxp = (long) *((char**)xpp); +#line 3305 + +#line 3305 + realign = (cxp & 7) % SIZEOF_INT; +#line 3305 + /* sjl: manually stripmine so we can limit amount of +#line 3305 + * vector work space reserved to LOOPCNT elements. Also +#line 3305 + * makes vectorisation easy */ +#line 3305 + for (j=0; j= 0 */ +#line 3305 + nrange += xp[i] > DOUBLE_MAX || xp[i] < DOUBLE_MIN; +#line 3305 + } +#line 3305 + /* update xpp and tp */ +#line 3305 + if (realign) xp = (int *) *xpp; +#line 3305 + xp += ni; +#line 3305 + tp += ni; +#line 3305 + *xpp = (void*)xp; +#line 3305 + } +#line 3305 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3305 + +#line 3305 +#else /* not SX */ +#line 3305 + const char *xp = (const char *) *xpp; +#line 3305 + int status = NC_NOERR; +#line 3305 + +#line 3305 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3305 + { +#line 3305 + const int lstatus = ncx_get_int_double(xp, tp); +#line 3305 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3305 + status = lstatus; +#line 3305 + } +#line 3305 + +#line 3305 + *xpp = (const void *)xp; +#line 3305 + return status; +#line 3305 +#endif +#line 3305 +} +#line 3305 + +int +#line 3306 +ncx_getn_int_longlong(const void **xpp, size_t nelems, longlong *tp) +#line 3306 +{ +#line 3306 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3306 + +#line 3306 + /* basic algorithm is: +#line 3306 + * - ensure sane alignment of input data +#line 3306 + * - copy (conversion happens automatically) input data +#line 3306 + * to output +#line 3306 + * - update xpp to point at next unconverted input, and tp to point +#line 3306 + * at next location for converted output +#line 3306 + */ +#line 3306 + long i, j, ni; +#line 3306 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3306 + int *xp; +#line 3306 + int nrange = 0; /* number of range errors */ +#line 3306 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3306 + long cxp = (long) *((char**)xpp); +#line 3306 + +#line 3306 + realign = (cxp & 7) % SIZEOF_INT; +#line 3306 + /* sjl: manually stripmine so we can limit amount of +#line 3306 + * vector work space reserved to LOOPCNT elements. Also +#line 3306 + * makes vectorisation easy */ +#line 3306 + for (j=0; j= 0 */ +#line 3306 + nrange += xp[i] > LONGLONG_MAX || xp[i] < LONGLONG_MIN; +#line 3306 + } +#line 3306 + /* update xpp and tp */ +#line 3306 + if (realign) xp = (int *) *xpp; +#line 3306 + xp += ni; +#line 3306 + tp += ni; +#line 3306 + *xpp = (void*)xp; +#line 3306 + } +#line 3306 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3306 + +#line 3306 +#else /* not SX */ +#line 3306 + const char *xp = (const char *) *xpp; +#line 3306 + int status = NC_NOERR; +#line 3306 + +#line 3306 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3306 + { +#line 3306 + const int lstatus = ncx_get_int_longlong(xp, tp); +#line 3306 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3306 + status = lstatus; +#line 3306 + } +#line 3306 + +#line 3306 + *xpp = (const void *)xp; +#line 3306 + return status; +#line 3306 +#endif +#line 3306 +} +#line 3306 + +int +#line 3307 +ncx_getn_int_uchar(const void **xpp, size_t nelems, uchar *tp) +#line 3307 +{ +#line 3307 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3307 + +#line 3307 + /* basic algorithm is: +#line 3307 + * - ensure sane alignment of input data +#line 3307 + * - copy (conversion happens automatically) input data +#line 3307 + * to output +#line 3307 + * - update xpp to point at next unconverted input, and tp to point +#line 3307 + * at next location for converted output +#line 3307 + */ +#line 3307 + long i, j, ni; +#line 3307 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3307 + int *xp; +#line 3307 + int nrange = 0; /* number of range errors */ +#line 3307 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3307 + long cxp = (long) *((char**)xpp); +#line 3307 + +#line 3307 + realign = (cxp & 7) % SIZEOF_INT; +#line 3307 + /* sjl: manually stripmine so we can limit amount of +#line 3307 + * vector work space reserved to LOOPCNT elements. Also +#line 3307 + * makes vectorisation easy */ +#line 3307 + for (j=0; j= 0 */ +#line 3307 + nrange += xp[i] > UCHAR_MAX || xp[i] < 0; +#line 3307 + } +#line 3307 + /* update xpp and tp */ +#line 3307 + if (realign) xp = (int *) *xpp; +#line 3307 + xp += ni; +#line 3307 + tp += ni; +#line 3307 + *xpp = (void*)xp; +#line 3307 + } +#line 3307 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3307 + +#line 3307 +#else /* not SX */ +#line 3307 + const char *xp = (const char *) *xpp; +#line 3307 + int status = NC_NOERR; +#line 3307 + +#line 3307 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3307 + { +#line 3307 + const int lstatus = ncx_get_int_uchar(xp, tp); +#line 3307 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3307 + status = lstatus; +#line 3307 + } +#line 3307 + +#line 3307 + *xpp = (const void *)xp; +#line 3307 + return status; +#line 3307 +#endif +#line 3307 +} +#line 3307 + +int +#line 3308 +ncx_getn_int_ushort(const void **xpp, size_t nelems, ushort *tp) +#line 3308 +{ +#line 3308 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3308 + +#line 3308 + /* basic algorithm is: +#line 3308 + * - ensure sane alignment of input data +#line 3308 + * - copy (conversion happens automatically) input data +#line 3308 + * to output +#line 3308 + * - update xpp to point at next unconverted input, and tp to point +#line 3308 + * at next location for converted output +#line 3308 + */ +#line 3308 + long i, j, ni; +#line 3308 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3308 + int *xp; +#line 3308 + int nrange = 0; /* number of range errors */ +#line 3308 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3308 + long cxp = (long) *((char**)xpp); +#line 3308 + +#line 3308 + realign = (cxp & 7) % SIZEOF_INT; +#line 3308 + /* sjl: manually stripmine so we can limit amount of +#line 3308 + * vector work space reserved to LOOPCNT elements. Also +#line 3308 + * makes vectorisation easy */ +#line 3308 + for (j=0; j= 0 */ +#line 3308 + nrange += xp[i] > USHORT_MAX || xp[i] < 0; +#line 3308 + } +#line 3308 + /* update xpp and tp */ +#line 3308 + if (realign) xp = (int *) *xpp; +#line 3308 + xp += ni; +#line 3308 + tp += ni; +#line 3308 + *xpp = (void*)xp; +#line 3308 + } +#line 3308 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3308 + +#line 3308 +#else /* not SX */ +#line 3308 + const char *xp = (const char *) *xpp; +#line 3308 + int status = NC_NOERR; +#line 3308 + +#line 3308 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3308 + { +#line 3308 + const int lstatus = ncx_get_int_ushort(xp, tp); +#line 3308 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3308 + status = lstatus; +#line 3308 + } +#line 3308 + +#line 3308 + *xpp = (const void *)xp; +#line 3308 + return status; +#line 3308 +#endif +#line 3308 +} +#line 3308 + +int +#line 3309 +ncx_getn_int_uint(const void **xpp, size_t nelems, uint *tp) +#line 3309 +{ +#line 3309 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3309 + +#line 3309 + /* basic algorithm is: +#line 3309 + * - ensure sane alignment of input data +#line 3309 + * - copy (conversion happens automatically) input data +#line 3309 + * to output +#line 3309 + * - update xpp to point at next unconverted input, and tp to point +#line 3309 + * at next location for converted output +#line 3309 + */ +#line 3309 + long i, j, ni; +#line 3309 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3309 + int *xp; +#line 3309 + int nrange = 0; /* number of range errors */ +#line 3309 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3309 + long cxp = (long) *((char**)xpp); +#line 3309 + +#line 3309 + realign = (cxp & 7) % SIZEOF_INT; +#line 3309 + /* sjl: manually stripmine so we can limit amount of +#line 3309 + * vector work space reserved to LOOPCNT elements. Also +#line 3309 + * makes vectorisation easy */ +#line 3309 + for (j=0; j= 0 */ +#line 3309 + nrange += xp[i] > UINT_MAX || xp[i] < 0; +#line 3309 + } +#line 3309 + /* update xpp and tp */ +#line 3309 + if (realign) xp = (int *) *xpp; +#line 3309 + xp += ni; +#line 3309 + tp += ni; +#line 3309 + *xpp = (void*)xp; +#line 3309 + } +#line 3309 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3309 + +#line 3309 +#else /* not SX */ +#line 3309 + const char *xp = (const char *) *xpp; +#line 3309 + int status = NC_NOERR; +#line 3309 + +#line 3309 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3309 + { +#line 3309 + const int lstatus = ncx_get_int_uint(xp, tp); +#line 3309 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3309 + status = lstatus; +#line 3309 + } +#line 3309 + +#line 3309 + *xpp = (const void *)xp; +#line 3309 + return status; +#line 3309 +#endif +#line 3309 +} +#line 3309 + +int +#line 3310 +ncx_getn_int_ulonglong(const void **xpp, size_t nelems, ulonglong *tp) +#line 3310 +{ +#line 3310 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3310 + +#line 3310 + /* basic algorithm is: +#line 3310 + * - ensure sane alignment of input data +#line 3310 + * - copy (conversion happens automatically) input data +#line 3310 + * to output +#line 3310 + * - update xpp to point at next unconverted input, and tp to point +#line 3310 + * at next location for converted output +#line 3310 + */ +#line 3310 + long i, j, ni; +#line 3310 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3310 + int *xp; +#line 3310 + int nrange = 0; /* number of range errors */ +#line 3310 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3310 + long cxp = (long) *((char**)xpp); +#line 3310 + +#line 3310 + realign = (cxp & 7) % SIZEOF_INT; +#line 3310 + /* sjl: manually stripmine so we can limit amount of +#line 3310 + * vector work space reserved to LOOPCNT elements. Also +#line 3310 + * makes vectorisation easy */ +#line 3310 + for (j=0; j= 0 */ +#line 3310 + nrange += xp[i] > ULONGLONG_MAX || xp[i] < 0; +#line 3310 + } +#line 3310 + /* update xpp and tp */ +#line 3310 + if (realign) xp = (int *) *xpp; +#line 3310 + xp += ni; +#line 3310 + tp += ni; +#line 3310 + *xpp = (void*)xp; +#line 3310 + } +#line 3310 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3310 + +#line 3310 +#else /* not SX */ +#line 3310 + const char *xp = (const char *) *xpp; +#line 3310 + int status = NC_NOERR; +#line 3310 + +#line 3310 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3310 + { +#line 3310 + const int lstatus = ncx_get_int_ulonglong(xp, tp); +#line 3310 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3310 + status = lstatus; +#line 3310 + } +#line 3310 + +#line 3310 + *xpp = (const void *)xp; +#line 3310 + return status; +#line 3310 +#endif +#line 3310 +} +#line 3310 + + +#if X_SIZEOF_INT == SIZEOF_INT +/* optimized version */ +int +ncx_putn_int_int(void **xpp, size_t nelems, const int *tp, void *fillp) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(*xpp, tp, (size_t)nelems * X_SIZEOF_INT); +# else + swapn4b(*xpp, tp, nelems); +# endif + *xpp = (void *)((char *)(*xpp) + nelems * X_SIZEOF_INT); + return NC_NOERR; +} +#else +int +#line 3326 +ncx_putn_int_int(void **xpp, size_t nelems, const int *tp, void *fillp) +#line 3326 +{ +#line 3326 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3326 + +#line 3326 + /* basic algorithm is: +#line 3326 + * - ensure sane alignment of output data +#line 3326 + * - copy (conversion happens automatically) input data +#line 3326 + * to output +#line 3326 + * - update tp to point at next unconverted input, and xpp to point +#line 3326 + * at next location for converted output +#line 3326 + */ +#line 3326 + long i, j, ni; +#line 3326 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3326 + int *xp; +#line 3326 + int nrange = 0; /* number of range errors */ +#line 3326 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3326 + long cxp = (long) *((char**)xpp); +#line 3326 + +#line 3326 + realign = (cxp & 7) % SIZEOF_INT; +#line 3326 + /* sjl: manually stripmine so we can limit amount of +#line 3326 + * vector work space reserved to LOOPCNT elements. Also +#line 3326 + * makes vectorisation easy */ +#line 3326 + for (j=0; j= 0 */ +#line 3326 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3326 + nrange += tp[i] > X_INT_MAX || tp[i] < X_INT_MIN; +#line 3326 + } +#line 3326 + /* copy workspace back if necessary */ +#line 3326 + if (realign) { +#line 3326 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT); +#line 3326 + xp = (int *) *xpp; +#line 3326 + } +#line 3326 + /* update xpp and tp */ +#line 3326 + xp += ni; +#line 3326 + tp += ni; +#line 3326 + *xpp = (void*)xp; +#line 3326 + } +#line 3326 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3326 + +#line 3326 +#else /* not SX */ +#line 3326 + +#line 3326 + char *xp = (char *) *xpp; +#line 3326 + int status = NC_NOERR; +#line 3326 + +#line 3326 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3326 + { +#line 3326 + int lstatus = ncx_put_int_int(xp, tp, fillp); +#line 3326 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3326 + status = lstatus; +#line 3326 + } +#line 3326 + +#line 3326 + *xpp = (void *)xp; +#line 3326 + return status; +#line 3326 +#endif +#line 3326 +} +#line 3326 + +#endif +int +#line 3328 +ncx_putn_int_schar(void **xpp, size_t nelems, const schar *tp, void *fillp) +#line 3328 +{ +#line 3328 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3328 + +#line 3328 + /* basic algorithm is: +#line 3328 + * - ensure sane alignment of output data +#line 3328 + * - copy (conversion happens automatically) input data +#line 3328 + * to output +#line 3328 + * - update tp to point at next unconverted input, and xpp to point +#line 3328 + * at next location for converted output +#line 3328 + */ +#line 3328 + long i, j, ni; +#line 3328 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3328 + int *xp; +#line 3328 + int nrange = 0; /* number of range errors */ +#line 3328 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3328 + long cxp = (long) *((char**)xpp); +#line 3328 + +#line 3328 + realign = (cxp & 7) % SIZEOF_INT; +#line 3328 + /* sjl: manually stripmine so we can limit amount of +#line 3328 + * vector work space reserved to LOOPCNT elements. Also +#line 3328 + * makes vectorisation easy */ +#line 3328 + for (j=0; j= 0 */ +#line 3328 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3328 + nrange += tp[i] > X_INT_MAX || tp[i] < X_INT_MIN; +#line 3328 + } +#line 3328 + /* copy workspace back if necessary */ +#line 3328 + if (realign) { +#line 3328 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT); +#line 3328 + xp = (int *) *xpp; +#line 3328 + } +#line 3328 + /* update xpp and tp */ +#line 3328 + xp += ni; +#line 3328 + tp += ni; +#line 3328 + *xpp = (void*)xp; +#line 3328 + } +#line 3328 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3328 + +#line 3328 +#else /* not SX */ +#line 3328 + +#line 3328 + char *xp = (char *) *xpp; +#line 3328 + int status = NC_NOERR; +#line 3328 + +#line 3328 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3328 + { +#line 3328 + int lstatus = ncx_put_int_schar(xp, tp, fillp); +#line 3328 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3328 + status = lstatus; +#line 3328 + } +#line 3328 + +#line 3328 + *xpp = (void *)xp; +#line 3328 + return status; +#line 3328 +#endif +#line 3328 +} +#line 3328 + +int +#line 3329 +ncx_putn_int_short(void **xpp, size_t nelems, const short *tp, void *fillp) +#line 3329 +{ +#line 3329 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3329 + +#line 3329 + /* basic algorithm is: +#line 3329 + * - ensure sane alignment of output data +#line 3329 + * - copy (conversion happens automatically) input data +#line 3329 + * to output +#line 3329 + * - update tp to point at next unconverted input, and xpp to point +#line 3329 + * at next location for converted output +#line 3329 + */ +#line 3329 + long i, j, ni; +#line 3329 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3329 + int *xp; +#line 3329 + int nrange = 0; /* number of range errors */ +#line 3329 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3329 + long cxp = (long) *((char**)xpp); +#line 3329 + +#line 3329 + realign = (cxp & 7) % SIZEOF_INT; +#line 3329 + /* sjl: manually stripmine so we can limit amount of +#line 3329 + * vector work space reserved to LOOPCNT elements. Also +#line 3329 + * makes vectorisation easy */ +#line 3329 + for (j=0; j= 0 */ +#line 3329 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3329 + nrange += tp[i] > X_INT_MAX || tp[i] < X_INT_MIN; +#line 3329 + } +#line 3329 + /* copy workspace back if necessary */ +#line 3329 + if (realign) { +#line 3329 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT); +#line 3329 + xp = (int *) *xpp; +#line 3329 + } +#line 3329 + /* update xpp and tp */ +#line 3329 + xp += ni; +#line 3329 + tp += ni; +#line 3329 + *xpp = (void*)xp; +#line 3329 + } +#line 3329 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3329 + +#line 3329 +#else /* not SX */ +#line 3329 + +#line 3329 + char *xp = (char *) *xpp; +#line 3329 + int status = NC_NOERR; +#line 3329 + +#line 3329 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3329 + { +#line 3329 + int lstatus = ncx_put_int_short(xp, tp, fillp); +#line 3329 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3329 + status = lstatus; +#line 3329 + } +#line 3329 + +#line 3329 + *xpp = (void *)xp; +#line 3329 + return status; +#line 3329 +#endif +#line 3329 +} +#line 3329 + +int +#line 3330 +ncx_putn_int_long(void **xpp, size_t nelems, const long *tp, void *fillp) +#line 3330 +{ +#line 3330 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3330 + +#line 3330 + /* basic algorithm is: +#line 3330 + * - ensure sane alignment of output data +#line 3330 + * - copy (conversion happens automatically) input data +#line 3330 + * to output +#line 3330 + * - update tp to point at next unconverted input, and xpp to point +#line 3330 + * at next location for converted output +#line 3330 + */ +#line 3330 + long i, j, ni; +#line 3330 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3330 + int *xp; +#line 3330 + int nrange = 0; /* number of range errors */ +#line 3330 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3330 + long cxp = (long) *((char**)xpp); +#line 3330 + +#line 3330 + realign = (cxp & 7) % SIZEOF_INT; +#line 3330 + /* sjl: manually stripmine so we can limit amount of +#line 3330 + * vector work space reserved to LOOPCNT elements. Also +#line 3330 + * makes vectorisation easy */ +#line 3330 + for (j=0; j= 0 */ +#line 3330 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3330 + nrange += tp[i] > X_INT_MAX || tp[i] < X_INT_MIN; +#line 3330 + } +#line 3330 + /* copy workspace back if necessary */ +#line 3330 + if (realign) { +#line 3330 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT); +#line 3330 + xp = (int *) *xpp; +#line 3330 + } +#line 3330 + /* update xpp and tp */ +#line 3330 + xp += ni; +#line 3330 + tp += ni; +#line 3330 + *xpp = (void*)xp; +#line 3330 + } +#line 3330 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3330 + +#line 3330 +#else /* not SX */ +#line 3330 + +#line 3330 + char *xp = (char *) *xpp; +#line 3330 + int status = NC_NOERR; +#line 3330 + +#line 3330 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3330 + { +#line 3330 + int lstatus = ncx_put_int_long(xp, tp, fillp); +#line 3330 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3330 + status = lstatus; +#line 3330 + } +#line 3330 + +#line 3330 + *xpp = (void *)xp; +#line 3330 + return status; +#line 3330 +#endif +#line 3330 +} +#line 3330 + +int +#line 3331 +ncx_putn_int_float(void **xpp, size_t nelems, const float *tp, void *fillp) +#line 3331 +{ +#line 3331 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3331 + +#line 3331 + /* basic algorithm is: +#line 3331 + * - ensure sane alignment of output data +#line 3331 + * - copy (conversion happens automatically) input data +#line 3331 + * to output +#line 3331 + * - update tp to point at next unconverted input, and xpp to point +#line 3331 + * at next location for converted output +#line 3331 + */ +#line 3331 + long i, j, ni; +#line 3331 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3331 + int *xp; +#line 3331 + double d; /* special case for ncx_putn_int_float */ +#line 3331 + int nrange = 0; /* number of range errors */ +#line 3331 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3331 + long cxp = (long) *((char**)xpp); +#line 3331 + +#line 3331 + realign = (cxp & 7) % SIZEOF_INT; +#line 3331 + /* sjl: manually stripmine so we can limit amount of +#line 3331 + * vector work space reserved to LOOPCNT elements. Also +#line 3331 + * makes vectorisation easy */ +#line 3331 + for (j=0; j X_INT_MAX || tp[i] < X_INT_MIN; +#line 3331 + } +#line 3331 + /* copy workspace back if necessary */ +#line 3331 + if (realign) { +#line 3331 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT); +#line 3331 + xp = (int *) *xpp; +#line 3331 + } +#line 3331 + /* update xpp and tp */ +#line 3331 + xp += ni; +#line 3331 + tp += ni; +#line 3331 + *xpp = (void*)xp; +#line 3331 + } +#line 3331 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3331 + +#line 3331 +#else /* not SX */ +#line 3331 + +#line 3331 + char *xp = (char *) *xpp; +#line 3331 + int status = NC_NOERR; +#line 3331 + +#line 3331 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3331 + { +#line 3331 + int lstatus = ncx_put_int_float(xp, tp, fillp); +#line 3331 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3331 + status = lstatus; +#line 3331 + } +#line 3331 + +#line 3331 + *xpp = (void *)xp; +#line 3331 + return status; +#line 3331 +#endif +#line 3331 +} +#line 3331 + +int +#line 3332 +ncx_putn_int_double(void **xpp, size_t nelems, const double *tp, void *fillp) +#line 3332 +{ +#line 3332 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3332 + +#line 3332 + /* basic algorithm is: +#line 3332 + * - ensure sane alignment of output data +#line 3332 + * - copy (conversion happens automatically) input data +#line 3332 + * to output +#line 3332 + * - update tp to point at next unconverted input, and xpp to point +#line 3332 + * at next location for converted output +#line 3332 + */ +#line 3332 + long i, j, ni; +#line 3332 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3332 + int *xp; +#line 3332 + int nrange = 0; /* number of range errors */ +#line 3332 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3332 + long cxp = (long) *((char**)xpp); +#line 3332 + +#line 3332 + realign = (cxp & 7) % SIZEOF_INT; +#line 3332 + /* sjl: manually stripmine so we can limit amount of +#line 3332 + * vector work space reserved to LOOPCNT elements. Also +#line 3332 + * makes vectorisation easy */ +#line 3332 + for (j=0; j= 0 */ +#line 3332 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3332 + nrange += tp[i] > X_INT_MAX || tp[i] < X_INT_MIN; +#line 3332 + } +#line 3332 + /* copy workspace back if necessary */ +#line 3332 + if (realign) { +#line 3332 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT); +#line 3332 + xp = (int *) *xpp; +#line 3332 + } +#line 3332 + /* update xpp and tp */ +#line 3332 + xp += ni; +#line 3332 + tp += ni; +#line 3332 + *xpp = (void*)xp; +#line 3332 + } +#line 3332 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3332 + +#line 3332 +#else /* not SX */ +#line 3332 + +#line 3332 + char *xp = (char *) *xpp; +#line 3332 + int status = NC_NOERR; +#line 3332 + +#line 3332 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3332 + { +#line 3332 + int lstatus = ncx_put_int_double(xp, tp, fillp); +#line 3332 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3332 + status = lstatus; +#line 3332 + } +#line 3332 + +#line 3332 + *xpp = (void *)xp; +#line 3332 + return status; +#line 3332 +#endif +#line 3332 +} +#line 3332 + +int +#line 3333 +ncx_putn_int_longlong(void **xpp, size_t nelems, const longlong *tp, void *fillp) +#line 3333 +{ +#line 3333 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3333 + +#line 3333 + /* basic algorithm is: +#line 3333 + * - ensure sane alignment of output data +#line 3333 + * - copy (conversion happens automatically) input data +#line 3333 + * to output +#line 3333 + * - update tp to point at next unconverted input, and xpp to point +#line 3333 + * at next location for converted output +#line 3333 + */ +#line 3333 + long i, j, ni; +#line 3333 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3333 + int *xp; +#line 3333 + int nrange = 0; /* number of range errors */ +#line 3333 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3333 + long cxp = (long) *((char**)xpp); +#line 3333 + +#line 3333 + realign = (cxp & 7) % SIZEOF_INT; +#line 3333 + /* sjl: manually stripmine so we can limit amount of +#line 3333 + * vector work space reserved to LOOPCNT elements. Also +#line 3333 + * makes vectorisation easy */ +#line 3333 + for (j=0; j= 0 */ +#line 3333 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3333 + nrange += tp[i] > X_INT_MAX || tp[i] < X_INT_MIN; +#line 3333 + } +#line 3333 + /* copy workspace back if necessary */ +#line 3333 + if (realign) { +#line 3333 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT); +#line 3333 + xp = (int *) *xpp; +#line 3333 + } +#line 3333 + /* update xpp and tp */ +#line 3333 + xp += ni; +#line 3333 + tp += ni; +#line 3333 + *xpp = (void*)xp; +#line 3333 + } +#line 3333 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3333 + +#line 3333 +#else /* not SX */ +#line 3333 + +#line 3333 + char *xp = (char *) *xpp; +#line 3333 + int status = NC_NOERR; +#line 3333 + +#line 3333 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3333 + { +#line 3333 + int lstatus = ncx_put_int_longlong(xp, tp, fillp); +#line 3333 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3333 + status = lstatus; +#line 3333 + } +#line 3333 + +#line 3333 + *xpp = (void *)xp; +#line 3333 + return status; +#line 3333 +#endif +#line 3333 +} +#line 3333 + +int +#line 3334 +ncx_putn_int_uchar(void **xpp, size_t nelems, const uchar *tp, void *fillp) +#line 3334 +{ +#line 3334 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3334 + +#line 3334 + /* basic algorithm is: +#line 3334 + * - ensure sane alignment of output data +#line 3334 + * - copy (conversion happens automatically) input data +#line 3334 + * to output +#line 3334 + * - update tp to point at next unconverted input, and xpp to point +#line 3334 + * at next location for converted output +#line 3334 + */ +#line 3334 + long i, j, ni; +#line 3334 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3334 + int *xp; +#line 3334 + int nrange = 0; /* number of range errors */ +#line 3334 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3334 + long cxp = (long) *((char**)xpp); +#line 3334 + +#line 3334 + realign = (cxp & 7) % SIZEOF_INT; +#line 3334 + /* sjl: manually stripmine so we can limit amount of +#line 3334 + * vector work space reserved to LOOPCNT elements. Also +#line 3334 + * makes vectorisation easy */ +#line 3334 + for (j=0; j= 0 */ +#line 3334 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3334 + nrange += tp[i] > X_INT_MAX ; +#line 3334 + } +#line 3334 + /* copy workspace back if necessary */ +#line 3334 + if (realign) { +#line 3334 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT); +#line 3334 + xp = (int *) *xpp; +#line 3334 + } +#line 3334 + /* update xpp and tp */ +#line 3334 + xp += ni; +#line 3334 + tp += ni; +#line 3334 + *xpp = (void*)xp; +#line 3334 + } +#line 3334 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3334 + +#line 3334 +#else /* not SX */ +#line 3334 + +#line 3334 + char *xp = (char *) *xpp; +#line 3334 + int status = NC_NOERR; +#line 3334 + +#line 3334 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3334 + { +#line 3334 + int lstatus = ncx_put_int_uchar(xp, tp, fillp); +#line 3334 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3334 + status = lstatus; +#line 3334 + } +#line 3334 + +#line 3334 + *xpp = (void *)xp; +#line 3334 + return status; +#line 3334 +#endif +#line 3334 +} +#line 3334 + +int +#line 3335 +ncx_putn_int_ushort(void **xpp, size_t nelems, const ushort *tp, void *fillp) +#line 3335 +{ +#line 3335 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3335 + +#line 3335 + /* basic algorithm is: +#line 3335 + * - ensure sane alignment of output data +#line 3335 + * - copy (conversion happens automatically) input data +#line 3335 + * to output +#line 3335 + * - update tp to point at next unconverted input, and xpp to point +#line 3335 + * at next location for converted output +#line 3335 + */ +#line 3335 + long i, j, ni; +#line 3335 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3335 + int *xp; +#line 3335 + int nrange = 0; /* number of range errors */ +#line 3335 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3335 + long cxp = (long) *((char**)xpp); +#line 3335 + +#line 3335 + realign = (cxp & 7) % SIZEOF_INT; +#line 3335 + /* sjl: manually stripmine so we can limit amount of +#line 3335 + * vector work space reserved to LOOPCNT elements. Also +#line 3335 + * makes vectorisation easy */ +#line 3335 + for (j=0; j= 0 */ +#line 3335 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3335 + nrange += tp[i] > X_INT_MAX ; +#line 3335 + } +#line 3335 + /* copy workspace back if necessary */ +#line 3335 + if (realign) { +#line 3335 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT); +#line 3335 + xp = (int *) *xpp; +#line 3335 + } +#line 3335 + /* update xpp and tp */ +#line 3335 + xp += ni; +#line 3335 + tp += ni; +#line 3335 + *xpp = (void*)xp; +#line 3335 + } +#line 3335 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3335 + +#line 3335 +#else /* not SX */ +#line 3335 + +#line 3335 + char *xp = (char *) *xpp; +#line 3335 + int status = NC_NOERR; +#line 3335 + +#line 3335 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3335 + { +#line 3335 + int lstatus = ncx_put_int_ushort(xp, tp, fillp); +#line 3335 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3335 + status = lstatus; +#line 3335 + } +#line 3335 + +#line 3335 + *xpp = (void *)xp; +#line 3335 + return status; +#line 3335 +#endif +#line 3335 +} +#line 3335 + +int +#line 3336 +ncx_putn_int_uint(void **xpp, size_t nelems, const uint *tp, void *fillp) +#line 3336 +{ +#line 3336 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3336 + +#line 3336 + /* basic algorithm is: +#line 3336 + * - ensure sane alignment of output data +#line 3336 + * - copy (conversion happens automatically) input data +#line 3336 + * to output +#line 3336 + * - update tp to point at next unconverted input, and xpp to point +#line 3336 + * at next location for converted output +#line 3336 + */ +#line 3336 + long i, j, ni; +#line 3336 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3336 + int *xp; +#line 3336 + int nrange = 0; /* number of range errors */ +#line 3336 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3336 + long cxp = (long) *((char**)xpp); +#line 3336 + +#line 3336 + realign = (cxp & 7) % SIZEOF_INT; +#line 3336 + /* sjl: manually stripmine so we can limit amount of +#line 3336 + * vector work space reserved to LOOPCNT elements. Also +#line 3336 + * makes vectorisation easy */ +#line 3336 + for (j=0; j= 0 */ +#line 3336 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3336 + nrange += tp[i] > X_INT_MAX ; +#line 3336 + } +#line 3336 + /* copy workspace back if necessary */ +#line 3336 + if (realign) { +#line 3336 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT); +#line 3336 + xp = (int *) *xpp; +#line 3336 + } +#line 3336 + /* update xpp and tp */ +#line 3336 + xp += ni; +#line 3336 + tp += ni; +#line 3336 + *xpp = (void*)xp; +#line 3336 + } +#line 3336 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3336 + +#line 3336 +#else /* not SX */ +#line 3336 + +#line 3336 + char *xp = (char *) *xpp; +#line 3336 + int status = NC_NOERR; +#line 3336 + +#line 3336 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3336 + { +#line 3336 + int lstatus = ncx_put_int_uint(xp, tp, fillp); +#line 3336 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3336 + status = lstatus; +#line 3336 + } +#line 3336 + +#line 3336 + *xpp = (void *)xp; +#line 3336 + return status; +#line 3336 +#endif +#line 3336 +} +#line 3336 + +int +#line 3337 +ncx_putn_int_ulonglong(void **xpp, size_t nelems, const ulonglong *tp, void *fillp) +#line 3337 +{ +#line 3337 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT == SIZEOF_INT +#line 3337 + +#line 3337 + /* basic algorithm is: +#line 3337 + * - ensure sane alignment of output data +#line 3337 + * - copy (conversion happens automatically) input data +#line 3337 + * to output +#line 3337 + * - update tp to point at next unconverted input, and xpp to point +#line 3337 + * at next location for converted output +#line 3337 + */ +#line 3337 + long i, j, ni; +#line 3337 + int tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3337 + int *xp; +#line 3337 + int nrange = 0; /* number of range errors */ +#line 3337 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3337 + long cxp = (long) *((char**)xpp); +#line 3337 + +#line 3337 + realign = (cxp & 7) % SIZEOF_INT; +#line 3337 + /* sjl: manually stripmine so we can limit amount of +#line 3337 + * vector work space reserved to LOOPCNT elements. Also +#line 3337 + * makes vectorisation easy */ +#line 3337 + for (j=0; j= 0 */ +#line 3337 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3337 + nrange += tp[i] > X_INT_MAX ; +#line 3337 + } +#line 3337 + /* copy workspace back if necessary */ +#line 3337 + if (realign) { +#line 3337 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT); +#line 3337 + xp = (int *) *xpp; +#line 3337 + } +#line 3337 + /* update xpp and tp */ +#line 3337 + xp += ni; +#line 3337 + tp += ni; +#line 3337 + *xpp = (void*)xp; +#line 3337 + } +#line 3337 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3337 + +#line 3337 +#else /* not SX */ +#line 3337 + +#line 3337 + char *xp = (char *) *xpp; +#line 3337 + int status = NC_NOERR; +#line 3337 + +#line 3337 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) +#line 3337 + { +#line 3337 + int lstatus = ncx_put_int_ulonglong(xp, tp, fillp); +#line 3337 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3337 + status = lstatus; +#line 3337 + } +#line 3337 + +#line 3337 + *xpp = (void *)xp; +#line 3337 + return status; +#line 3337 +#endif +#line 3337 +} +#line 3337 + + +/* uint ----------------------------------------------------------------------*/ + +#if X_SIZEOF_UINT == SIZEOF_UINT +/* optimized version */ +int +ncx_getn_uint_uint(const void **xpp, size_t nelems, unsigned int *tp) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(tp, *xpp, (size_t)nelems * SIZEOF_UINT); +# else + swapn4b(tp, *xpp, nelems); +# endif + *xpp = (const void *)((const char *)(*xpp) + nelems * X_SIZEOF_UINT); + return NC_NOERR; +} +#else +int +#line 3355 +ncx_getn_uint_uint(const void **xpp, size_t nelems, uint *tp) +#line 3355 +{ +#line 3355 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3355 + +#line 3355 + /* basic algorithm is: +#line 3355 + * - ensure sane alignment of input data +#line 3355 + * - copy (conversion happens automatically) input data +#line 3355 + * to output +#line 3355 + * - update xpp to point at next unconverted input, and tp to point +#line 3355 + * at next location for converted output +#line 3355 + */ +#line 3355 + long i, j, ni; +#line 3355 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3355 + uint *xp; +#line 3355 + int nrange = 0; /* number of range errors */ +#line 3355 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3355 + long cxp = (long) *((char**)xpp); +#line 3355 + +#line 3355 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3355 + /* sjl: manually stripmine so we can limit amount of +#line 3355 + * vector work space reserved to LOOPCNT elements. Also +#line 3355 + * makes vectorisation easy */ +#line 3355 + for (j=0; j= 0 */ +#line 3355 + nrange += xp[i] > UINT_MAX ; +#line 3355 + } +#line 3355 + /* update xpp and tp */ +#line 3355 + if (realign) xp = (uint *) *xpp; +#line 3355 + xp += ni; +#line 3355 + tp += ni; +#line 3355 + *xpp = (void*)xp; +#line 3355 + } +#line 3355 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3355 + +#line 3355 +#else /* not SX */ +#line 3355 + const char *xp = (const char *) *xpp; +#line 3355 + int status = NC_NOERR; +#line 3355 + +#line 3355 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3355 + { +#line 3355 + const int lstatus = ncx_get_uint_uint(xp, tp); +#line 3355 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3355 + status = lstatus; +#line 3355 + } +#line 3355 + +#line 3355 + *xpp = (const void *)xp; +#line 3355 + return status; +#line 3355 +#endif +#line 3355 +} +#line 3355 + +#endif +int +#line 3357 +ncx_getn_uint_schar(const void **xpp, size_t nelems, schar *tp) +#line 3357 +{ +#line 3357 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3357 + +#line 3357 + /* basic algorithm is: +#line 3357 + * - ensure sane alignment of input data +#line 3357 + * - copy (conversion happens automatically) input data +#line 3357 + * to output +#line 3357 + * - update xpp to point at next unconverted input, and tp to point +#line 3357 + * at next location for converted output +#line 3357 + */ +#line 3357 + long i, j, ni; +#line 3357 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3357 + uint *xp; +#line 3357 + int nrange = 0; /* number of range errors */ +#line 3357 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3357 + long cxp = (long) *((char**)xpp); +#line 3357 + +#line 3357 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3357 + /* sjl: manually stripmine so we can limit amount of +#line 3357 + * vector work space reserved to LOOPCNT elements. Also +#line 3357 + * makes vectorisation easy */ +#line 3357 + for (j=0; j= 0 */ +#line 3357 + nrange += xp[i] > SCHAR_MAX ; +#line 3357 + } +#line 3357 + /* update xpp and tp */ +#line 3357 + if (realign) xp = (uint *) *xpp; +#line 3357 + xp += ni; +#line 3357 + tp += ni; +#line 3357 + *xpp = (void*)xp; +#line 3357 + } +#line 3357 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3357 + +#line 3357 +#else /* not SX */ +#line 3357 + const char *xp = (const char *) *xpp; +#line 3357 + int status = NC_NOERR; +#line 3357 + +#line 3357 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3357 + { +#line 3357 + const int lstatus = ncx_get_uint_schar(xp, tp); +#line 3357 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3357 + status = lstatus; +#line 3357 + } +#line 3357 + +#line 3357 + *xpp = (const void *)xp; +#line 3357 + return status; +#line 3357 +#endif +#line 3357 +} +#line 3357 + +int +#line 3358 +ncx_getn_uint_short(const void **xpp, size_t nelems, short *tp) +#line 3358 +{ +#line 3358 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3358 + +#line 3358 + /* basic algorithm is: +#line 3358 + * - ensure sane alignment of input data +#line 3358 + * - copy (conversion happens automatically) input data +#line 3358 + * to output +#line 3358 + * - update xpp to point at next unconverted input, and tp to point +#line 3358 + * at next location for converted output +#line 3358 + */ +#line 3358 + long i, j, ni; +#line 3358 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3358 + uint *xp; +#line 3358 + int nrange = 0; /* number of range errors */ +#line 3358 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3358 + long cxp = (long) *((char**)xpp); +#line 3358 + +#line 3358 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3358 + /* sjl: manually stripmine so we can limit amount of +#line 3358 + * vector work space reserved to LOOPCNT elements. Also +#line 3358 + * makes vectorisation easy */ +#line 3358 + for (j=0; j= 0 */ +#line 3358 + nrange += xp[i] > SHORT_MAX ; +#line 3358 + } +#line 3358 + /* update xpp and tp */ +#line 3358 + if (realign) xp = (uint *) *xpp; +#line 3358 + xp += ni; +#line 3358 + tp += ni; +#line 3358 + *xpp = (void*)xp; +#line 3358 + } +#line 3358 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3358 + +#line 3358 +#else /* not SX */ +#line 3358 + const char *xp = (const char *) *xpp; +#line 3358 + int status = NC_NOERR; +#line 3358 + +#line 3358 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3358 + { +#line 3358 + const int lstatus = ncx_get_uint_short(xp, tp); +#line 3358 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3358 + status = lstatus; +#line 3358 + } +#line 3358 + +#line 3358 + *xpp = (const void *)xp; +#line 3358 + return status; +#line 3358 +#endif +#line 3358 +} +#line 3358 + +int +#line 3359 +ncx_getn_uint_int(const void **xpp, size_t nelems, int *tp) +#line 3359 +{ +#line 3359 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3359 + +#line 3359 + /* basic algorithm is: +#line 3359 + * - ensure sane alignment of input data +#line 3359 + * - copy (conversion happens automatically) input data +#line 3359 + * to output +#line 3359 + * - update xpp to point at next unconverted input, and tp to point +#line 3359 + * at next location for converted output +#line 3359 + */ +#line 3359 + long i, j, ni; +#line 3359 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3359 + uint *xp; +#line 3359 + int nrange = 0; /* number of range errors */ +#line 3359 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3359 + long cxp = (long) *((char**)xpp); +#line 3359 + +#line 3359 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3359 + /* sjl: manually stripmine so we can limit amount of +#line 3359 + * vector work space reserved to LOOPCNT elements. Also +#line 3359 + * makes vectorisation easy */ +#line 3359 + for (j=0; j= 0 */ +#line 3359 + nrange += xp[i] > INT_MAX ; +#line 3359 + } +#line 3359 + /* update xpp and tp */ +#line 3359 + if (realign) xp = (uint *) *xpp; +#line 3359 + xp += ni; +#line 3359 + tp += ni; +#line 3359 + *xpp = (void*)xp; +#line 3359 + } +#line 3359 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3359 + +#line 3359 +#else /* not SX */ +#line 3359 + const char *xp = (const char *) *xpp; +#line 3359 + int status = NC_NOERR; +#line 3359 + +#line 3359 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3359 + { +#line 3359 + const int lstatus = ncx_get_uint_int(xp, tp); +#line 3359 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3359 + status = lstatus; +#line 3359 + } +#line 3359 + +#line 3359 + *xpp = (const void *)xp; +#line 3359 + return status; +#line 3359 +#endif +#line 3359 +} +#line 3359 + +int +#line 3360 +ncx_getn_uint_long(const void **xpp, size_t nelems, long *tp) +#line 3360 +{ +#line 3360 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3360 + +#line 3360 + /* basic algorithm is: +#line 3360 + * - ensure sane alignment of input data +#line 3360 + * - copy (conversion happens automatically) input data +#line 3360 + * to output +#line 3360 + * - update xpp to point at next unconverted input, and tp to point +#line 3360 + * at next location for converted output +#line 3360 + */ +#line 3360 + long i, j, ni; +#line 3360 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3360 + uint *xp; +#line 3360 + int nrange = 0; /* number of range errors */ +#line 3360 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3360 + long cxp = (long) *((char**)xpp); +#line 3360 + +#line 3360 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3360 + /* sjl: manually stripmine so we can limit amount of +#line 3360 + * vector work space reserved to LOOPCNT elements. Also +#line 3360 + * makes vectorisation easy */ +#line 3360 + for (j=0; j= 0 */ +#line 3360 + nrange += xp[i] > LONG_MAX ; +#line 3360 + } +#line 3360 + /* update xpp and tp */ +#line 3360 + if (realign) xp = (uint *) *xpp; +#line 3360 + xp += ni; +#line 3360 + tp += ni; +#line 3360 + *xpp = (void*)xp; +#line 3360 + } +#line 3360 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3360 + +#line 3360 +#else /* not SX */ +#line 3360 + const char *xp = (const char *) *xpp; +#line 3360 + int status = NC_NOERR; +#line 3360 + +#line 3360 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3360 + { +#line 3360 + const int lstatus = ncx_get_uint_long(xp, tp); +#line 3360 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3360 + status = lstatus; +#line 3360 + } +#line 3360 + +#line 3360 + *xpp = (const void *)xp; +#line 3360 + return status; +#line 3360 +#endif +#line 3360 +} +#line 3360 + +int +#line 3361 +ncx_getn_uint_float(const void **xpp, size_t nelems, float *tp) +#line 3361 +{ +#line 3361 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3361 + +#line 3361 + /* basic algorithm is: +#line 3361 + * - ensure sane alignment of input data +#line 3361 + * - copy (conversion happens automatically) input data +#line 3361 + * to output +#line 3361 + * - update xpp to point at next unconverted input, and tp to point +#line 3361 + * at next location for converted output +#line 3361 + */ +#line 3361 + long i, j, ni; +#line 3361 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3361 + uint *xp; +#line 3361 + int nrange = 0; /* number of range errors */ +#line 3361 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3361 + long cxp = (long) *((char**)xpp); +#line 3361 + +#line 3361 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3361 + /* sjl: manually stripmine so we can limit amount of +#line 3361 + * vector work space reserved to LOOPCNT elements. Also +#line 3361 + * makes vectorisation easy */ +#line 3361 + for (j=0; j= 0 */ +#line 3361 + nrange += xp[i] > FLOAT_MAX ; +#line 3361 + } +#line 3361 + /* update xpp and tp */ +#line 3361 + if (realign) xp = (uint *) *xpp; +#line 3361 + xp += ni; +#line 3361 + tp += ni; +#line 3361 + *xpp = (void*)xp; +#line 3361 + } +#line 3361 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3361 + +#line 3361 +#else /* not SX */ +#line 3361 + const char *xp = (const char *) *xpp; +#line 3361 + int status = NC_NOERR; +#line 3361 + +#line 3361 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3361 + { +#line 3361 + const int lstatus = ncx_get_uint_float(xp, tp); +#line 3361 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3361 + status = lstatus; +#line 3361 + } +#line 3361 + +#line 3361 + *xpp = (const void *)xp; +#line 3361 + return status; +#line 3361 +#endif +#line 3361 +} +#line 3361 + +int +#line 3362 +ncx_getn_uint_double(const void **xpp, size_t nelems, double *tp) +#line 3362 +{ +#line 3362 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3362 + +#line 3362 + /* basic algorithm is: +#line 3362 + * - ensure sane alignment of input data +#line 3362 + * - copy (conversion happens automatically) input data +#line 3362 + * to output +#line 3362 + * - update xpp to point at next unconverted input, and tp to point +#line 3362 + * at next location for converted output +#line 3362 + */ +#line 3362 + long i, j, ni; +#line 3362 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3362 + uint *xp; +#line 3362 + int nrange = 0; /* number of range errors */ +#line 3362 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3362 + long cxp = (long) *((char**)xpp); +#line 3362 + +#line 3362 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3362 + /* sjl: manually stripmine so we can limit amount of +#line 3362 + * vector work space reserved to LOOPCNT elements. Also +#line 3362 + * makes vectorisation easy */ +#line 3362 + for (j=0; j= 0 */ +#line 3362 + nrange += xp[i] > DOUBLE_MAX ; +#line 3362 + } +#line 3362 + /* update xpp and tp */ +#line 3362 + if (realign) xp = (uint *) *xpp; +#line 3362 + xp += ni; +#line 3362 + tp += ni; +#line 3362 + *xpp = (void*)xp; +#line 3362 + } +#line 3362 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3362 + +#line 3362 +#else /* not SX */ +#line 3362 + const char *xp = (const char *) *xpp; +#line 3362 + int status = NC_NOERR; +#line 3362 + +#line 3362 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3362 + { +#line 3362 + const int lstatus = ncx_get_uint_double(xp, tp); +#line 3362 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3362 + status = lstatus; +#line 3362 + } +#line 3362 + +#line 3362 + *xpp = (const void *)xp; +#line 3362 + return status; +#line 3362 +#endif +#line 3362 +} +#line 3362 + +int +#line 3363 +ncx_getn_uint_longlong(const void **xpp, size_t nelems, longlong *tp) +#line 3363 +{ +#line 3363 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3363 + +#line 3363 + /* basic algorithm is: +#line 3363 + * - ensure sane alignment of input data +#line 3363 + * - copy (conversion happens automatically) input data +#line 3363 + * to output +#line 3363 + * - update xpp to point at next unconverted input, and tp to point +#line 3363 + * at next location for converted output +#line 3363 + */ +#line 3363 + long i, j, ni; +#line 3363 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3363 + uint *xp; +#line 3363 + int nrange = 0; /* number of range errors */ +#line 3363 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3363 + long cxp = (long) *((char**)xpp); +#line 3363 + +#line 3363 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3363 + /* sjl: manually stripmine so we can limit amount of +#line 3363 + * vector work space reserved to LOOPCNT elements. Also +#line 3363 + * makes vectorisation easy */ +#line 3363 + for (j=0; j= 0 */ +#line 3363 + nrange += xp[i] > LONGLONG_MAX ; +#line 3363 + } +#line 3363 + /* update xpp and tp */ +#line 3363 + if (realign) xp = (uint *) *xpp; +#line 3363 + xp += ni; +#line 3363 + tp += ni; +#line 3363 + *xpp = (void*)xp; +#line 3363 + } +#line 3363 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3363 + +#line 3363 +#else /* not SX */ +#line 3363 + const char *xp = (const char *) *xpp; +#line 3363 + int status = NC_NOERR; +#line 3363 + +#line 3363 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3363 + { +#line 3363 + const int lstatus = ncx_get_uint_longlong(xp, tp); +#line 3363 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3363 + status = lstatus; +#line 3363 + } +#line 3363 + +#line 3363 + *xpp = (const void *)xp; +#line 3363 + return status; +#line 3363 +#endif +#line 3363 +} +#line 3363 + +int +#line 3364 +ncx_getn_uint_uchar(const void **xpp, size_t nelems, uchar *tp) +#line 3364 +{ +#line 3364 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3364 + +#line 3364 + /* basic algorithm is: +#line 3364 + * - ensure sane alignment of input data +#line 3364 + * - copy (conversion happens automatically) input data +#line 3364 + * to output +#line 3364 + * - update xpp to point at next unconverted input, and tp to point +#line 3364 + * at next location for converted output +#line 3364 + */ +#line 3364 + long i, j, ni; +#line 3364 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3364 + uint *xp; +#line 3364 + int nrange = 0; /* number of range errors */ +#line 3364 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3364 + long cxp = (long) *((char**)xpp); +#line 3364 + +#line 3364 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3364 + /* sjl: manually stripmine so we can limit amount of +#line 3364 + * vector work space reserved to LOOPCNT elements. Also +#line 3364 + * makes vectorisation easy */ +#line 3364 + for (j=0; j= 0 */ +#line 3364 + nrange += xp[i] > UCHAR_MAX ; +#line 3364 + } +#line 3364 + /* update xpp and tp */ +#line 3364 + if (realign) xp = (uint *) *xpp; +#line 3364 + xp += ni; +#line 3364 + tp += ni; +#line 3364 + *xpp = (void*)xp; +#line 3364 + } +#line 3364 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3364 + +#line 3364 +#else /* not SX */ +#line 3364 + const char *xp = (const char *) *xpp; +#line 3364 + int status = NC_NOERR; +#line 3364 + +#line 3364 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3364 + { +#line 3364 + const int lstatus = ncx_get_uint_uchar(xp, tp); +#line 3364 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3364 + status = lstatus; +#line 3364 + } +#line 3364 + +#line 3364 + *xpp = (const void *)xp; +#line 3364 + return status; +#line 3364 +#endif +#line 3364 +} +#line 3364 + +int +#line 3365 +ncx_getn_uint_ushort(const void **xpp, size_t nelems, ushort *tp) +#line 3365 +{ +#line 3365 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3365 + +#line 3365 + /* basic algorithm is: +#line 3365 + * - ensure sane alignment of input data +#line 3365 + * - copy (conversion happens automatically) input data +#line 3365 + * to output +#line 3365 + * - update xpp to point at next unconverted input, and tp to point +#line 3365 + * at next location for converted output +#line 3365 + */ +#line 3365 + long i, j, ni; +#line 3365 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3365 + uint *xp; +#line 3365 + int nrange = 0; /* number of range errors */ +#line 3365 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3365 + long cxp = (long) *((char**)xpp); +#line 3365 + +#line 3365 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3365 + /* sjl: manually stripmine so we can limit amount of +#line 3365 + * vector work space reserved to LOOPCNT elements. Also +#line 3365 + * makes vectorisation easy */ +#line 3365 + for (j=0; j= 0 */ +#line 3365 + nrange += xp[i] > USHORT_MAX ; +#line 3365 + } +#line 3365 + /* update xpp and tp */ +#line 3365 + if (realign) xp = (uint *) *xpp; +#line 3365 + xp += ni; +#line 3365 + tp += ni; +#line 3365 + *xpp = (void*)xp; +#line 3365 + } +#line 3365 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3365 + +#line 3365 +#else /* not SX */ +#line 3365 + const char *xp = (const char *) *xpp; +#line 3365 + int status = NC_NOERR; +#line 3365 + +#line 3365 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3365 + { +#line 3365 + const int lstatus = ncx_get_uint_ushort(xp, tp); +#line 3365 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3365 + status = lstatus; +#line 3365 + } +#line 3365 + +#line 3365 + *xpp = (const void *)xp; +#line 3365 + return status; +#line 3365 +#endif +#line 3365 +} +#line 3365 + +int +#line 3366 +ncx_getn_uint_ulonglong(const void **xpp, size_t nelems, ulonglong *tp) +#line 3366 +{ +#line 3366 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3366 + +#line 3366 + /* basic algorithm is: +#line 3366 + * - ensure sane alignment of input data +#line 3366 + * - copy (conversion happens automatically) input data +#line 3366 + * to output +#line 3366 + * - update xpp to point at next unconverted input, and tp to point +#line 3366 + * at next location for converted output +#line 3366 + */ +#line 3366 + long i, j, ni; +#line 3366 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3366 + uint *xp; +#line 3366 + int nrange = 0; /* number of range errors */ +#line 3366 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3366 + long cxp = (long) *((char**)xpp); +#line 3366 + +#line 3366 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3366 + /* sjl: manually stripmine so we can limit amount of +#line 3366 + * vector work space reserved to LOOPCNT elements. Also +#line 3366 + * makes vectorisation easy */ +#line 3366 + for (j=0; j= 0 */ +#line 3366 + nrange += xp[i] > ULONGLONG_MAX ; +#line 3366 + } +#line 3366 + /* update xpp and tp */ +#line 3366 + if (realign) xp = (uint *) *xpp; +#line 3366 + xp += ni; +#line 3366 + tp += ni; +#line 3366 + *xpp = (void*)xp; +#line 3366 + } +#line 3366 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3366 + +#line 3366 +#else /* not SX */ +#line 3366 + const char *xp = (const char *) *xpp; +#line 3366 + int status = NC_NOERR; +#line 3366 + +#line 3366 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3366 + { +#line 3366 + const int lstatus = ncx_get_uint_ulonglong(xp, tp); +#line 3366 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3366 + status = lstatus; +#line 3366 + } +#line 3366 + +#line 3366 + *xpp = (const void *)xp; +#line 3366 + return status; +#line 3366 +#endif +#line 3366 +} +#line 3366 + + +#if X_SIZEOF_UINT == SIZEOF_UINT +/* optimized version */ +int +ncx_putn_uint_uint(void **xpp, size_t nelems, const unsigned int *tp, void *fillp) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(*xpp, tp, (size_t)nelems * X_SIZEOF_UINT); +# else + swapn4b(*xpp, tp, nelems); +# endif + *xpp = (void *)((char *)(*xpp) + nelems * X_SIZEOF_UINT); + return NC_NOERR; +} +#else +int +#line 3382 +ncx_putn_uint_uint(void **xpp, size_t nelems, const uint *tp, void *fillp) +#line 3382 +{ +#line 3382 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3382 + +#line 3382 + /* basic algorithm is: +#line 3382 + * - ensure sane alignment of output data +#line 3382 + * - copy (conversion happens automatically) input data +#line 3382 + * to output +#line 3382 + * - update tp to point at next unconverted input, and xpp to point +#line 3382 + * at next location for converted output +#line 3382 + */ +#line 3382 + long i, j, ni; +#line 3382 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3382 + uint *xp; +#line 3382 + int nrange = 0; /* number of range errors */ +#line 3382 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3382 + long cxp = (long) *((char**)xpp); +#line 3382 + +#line 3382 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3382 + /* sjl: manually stripmine so we can limit amount of +#line 3382 + * vector work space reserved to LOOPCNT elements. Also +#line 3382 + * makes vectorisation easy */ +#line 3382 + for (j=0; j= 0 */ +#line 3382 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3382 + nrange += tp[i] > X_UINT_MAX ; +#line 3382 + } +#line 3382 + /* copy workspace back if necessary */ +#line 3382 + if (realign) { +#line 3382 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT); +#line 3382 + xp = (uint *) *xpp; +#line 3382 + } +#line 3382 + /* update xpp and tp */ +#line 3382 + xp += ni; +#line 3382 + tp += ni; +#line 3382 + *xpp = (void*)xp; +#line 3382 + } +#line 3382 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3382 + +#line 3382 +#else /* not SX */ +#line 3382 + +#line 3382 + char *xp = (char *) *xpp; +#line 3382 + int status = NC_NOERR; +#line 3382 + +#line 3382 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3382 + { +#line 3382 + int lstatus = ncx_put_uint_uint(xp, tp, fillp); +#line 3382 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3382 + status = lstatus; +#line 3382 + } +#line 3382 + +#line 3382 + *xpp = (void *)xp; +#line 3382 + return status; +#line 3382 +#endif +#line 3382 +} +#line 3382 + +#endif +int +#line 3384 +ncx_putn_uint_schar(void **xpp, size_t nelems, const schar *tp, void *fillp) +#line 3384 +{ +#line 3384 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3384 + +#line 3384 + /* basic algorithm is: +#line 3384 + * - ensure sane alignment of output data +#line 3384 + * - copy (conversion happens automatically) input data +#line 3384 + * to output +#line 3384 + * - update tp to point at next unconverted input, and xpp to point +#line 3384 + * at next location for converted output +#line 3384 + */ +#line 3384 + long i, j, ni; +#line 3384 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3384 + uint *xp; +#line 3384 + int nrange = 0; /* number of range errors */ +#line 3384 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3384 + long cxp = (long) *((char**)xpp); +#line 3384 + +#line 3384 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3384 + /* sjl: manually stripmine so we can limit amount of +#line 3384 + * vector work space reserved to LOOPCNT elements. Also +#line 3384 + * makes vectorisation easy */ +#line 3384 + for (j=0; j= 0 */ +#line 3384 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3384 + nrange += tp[i] > X_UINT_MAX || tp[i] < 0; +#line 3384 + } +#line 3384 + /* copy workspace back if necessary */ +#line 3384 + if (realign) { +#line 3384 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT); +#line 3384 + xp = (uint *) *xpp; +#line 3384 + } +#line 3384 + /* update xpp and tp */ +#line 3384 + xp += ni; +#line 3384 + tp += ni; +#line 3384 + *xpp = (void*)xp; +#line 3384 + } +#line 3384 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3384 + +#line 3384 +#else /* not SX */ +#line 3384 + +#line 3384 + char *xp = (char *) *xpp; +#line 3384 + int status = NC_NOERR; +#line 3384 + +#line 3384 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3384 + { +#line 3384 + int lstatus = ncx_put_uint_schar(xp, tp, fillp); +#line 3384 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3384 + status = lstatus; +#line 3384 + } +#line 3384 + +#line 3384 + *xpp = (void *)xp; +#line 3384 + return status; +#line 3384 +#endif +#line 3384 +} +#line 3384 + +int +#line 3385 +ncx_putn_uint_short(void **xpp, size_t nelems, const short *tp, void *fillp) +#line 3385 +{ +#line 3385 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3385 + +#line 3385 + /* basic algorithm is: +#line 3385 + * - ensure sane alignment of output data +#line 3385 + * - copy (conversion happens automatically) input data +#line 3385 + * to output +#line 3385 + * - update tp to point at next unconverted input, and xpp to point +#line 3385 + * at next location for converted output +#line 3385 + */ +#line 3385 + long i, j, ni; +#line 3385 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3385 + uint *xp; +#line 3385 + int nrange = 0; /* number of range errors */ +#line 3385 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3385 + long cxp = (long) *((char**)xpp); +#line 3385 + +#line 3385 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3385 + /* sjl: manually stripmine so we can limit amount of +#line 3385 + * vector work space reserved to LOOPCNT elements. Also +#line 3385 + * makes vectorisation easy */ +#line 3385 + for (j=0; j= 0 */ +#line 3385 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3385 + nrange += tp[i] > X_UINT_MAX || tp[i] < 0; +#line 3385 + } +#line 3385 + /* copy workspace back if necessary */ +#line 3385 + if (realign) { +#line 3385 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT); +#line 3385 + xp = (uint *) *xpp; +#line 3385 + } +#line 3385 + /* update xpp and tp */ +#line 3385 + xp += ni; +#line 3385 + tp += ni; +#line 3385 + *xpp = (void*)xp; +#line 3385 + } +#line 3385 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3385 + +#line 3385 +#else /* not SX */ +#line 3385 + +#line 3385 + char *xp = (char *) *xpp; +#line 3385 + int status = NC_NOERR; +#line 3385 + +#line 3385 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3385 + { +#line 3385 + int lstatus = ncx_put_uint_short(xp, tp, fillp); +#line 3385 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3385 + status = lstatus; +#line 3385 + } +#line 3385 + +#line 3385 + *xpp = (void *)xp; +#line 3385 + return status; +#line 3385 +#endif +#line 3385 +} +#line 3385 + +int +#line 3386 +ncx_putn_uint_int(void **xpp, size_t nelems, const int *tp, void *fillp) +#line 3386 +{ +#line 3386 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3386 + +#line 3386 + /* basic algorithm is: +#line 3386 + * - ensure sane alignment of output data +#line 3386 + * - copy (conversion happens automatically) input data +#line 3386 + * to output +#line 3386 + * - update tp to point at next unconverted input, and xpp to point +#line 3386 + * at next location for converted output +#line 3386 + */ +#line 3386 + long i, j, ni; +#line 3386 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3386 + uint *xp; +#line 3386 + int nrange = 0; /* number of range errors */ +#line 3386 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3386 + long cxp = (long) *((char**)xpp); +#line 3386 + +#line 3386 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3386 + /* sjl: manually stripmine so we can limit amount of +#line 3386 + * vector work space reserved to LOOPCNT elements. Also +#line 3386 + * makes vectorisation easy */ +#line 3386 + for (j=0; j= 0 */ +#line 3386 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3386 + nrange += tp[i] > X_UINT_MAX || tp[i] < 0; +#line 3386 + } +#line 3386 + /* copy workspace back if necessary */ +#line 3386 + if (realign) { +#line 3386 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT); +#line 3386 + xp = (uint *) *xpp; +#line 3386 + } +#line 3386 + /* update xpp and tp */ +#line 3386 + xp += ni; +#line 3386 + tp += ni; +#line 3386 + *xpp = (void*)xp; +#line 3386 + } +#line 3386 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3386 + +#line 3386 +#else /* not SX */ +#line 3386 + +#line 3386 + char *xp = (char *) *xpp; +#line 3386 + int status = NC_NOERR; +#line 3386 + +#line 3386 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3386 + { +#line 3386 + int lstatus = ncx_put_uint_int(xp, tp, fillp); +#line 3386 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3386 + status = lstatus; +#line 3386 + } +#line 3386 + +#line 3386 + *xpp = (void *)xp; +#line 3386 + return status; +#line 3386 +#endif +#line 3386 +} +#line 3386 + +int +#line 3387 +ncx_putn_uint_long(void **xpp, size_t nelems, const long *tp, void *fillp) +#line 3387 +{ +#line 3387 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3387 + +#line 3387 + /* basic algorithm is: +#line 3387 + * - ensure sane alignment of output data +#line 3387 + * - copy (conversion happens automatically) input data +#line 3387 + * to output +#line 3387 + * - update tp to point at next unconverted input, and xpp to point +#line 3387 + * at next location for converted output +#line 3387 + */ +#line 3387 + long i, j, ni; +#line 3387 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3387 + uint *xp; +#line 3387 + int nrange = 0; /* number of range errors */ +#line 3387 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3387 + long cxp = (long) *((char**)xpp); +#line 3387 + +#line 3387 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3387 + /* sjl: manually stripmine so we can limit amount of +#line 3387 + * vector work space reserved to LOOPCNT elements. Also +#line 3387 + * makes vectorisation easy */ +#line 3387 + for (j=0; j= 0 */ +#line 3387 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3387 + nrange += tp[i] > X_UINT_MAX || tp[i] < 0; +#line 3387 + } +#line 3387 + /* copy workspace back if necessary */ +#line 3387 + if (realign) { +#line 3387 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT); +#line 3387 + xp = (uint *) *xpp; +#line 3387 + } +#line 3387 + /* update xpp and tp */ +#line 3387 + xp += ni; +#line 3387 + tp += ni; +#line 3387 + *xpp = (void*)xp; +#line 3387 + } +#line 3387 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3387 + +#line 3387 +#else /* not SX */ +#line 3387 + +#line 3387 + char *xp = (char *) *xpp; +#line 3387 + int status = NC_NOERR; +#line 3387 + +#line 3387 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3387 + { +#line 3387 + int lstatus = ncx_put_uint_long(xp, tp, fillp); +#line 3387 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3387 + status = lstatus; +#line 3387 + } +#line 3387 + +#line 3387 + *xpp = (void *)xp; +#line 3387 + return status; +#line 3387 +#endif +#line 3387 +} +#line 3387 + +int +#line 3388 +ncx_putn_uint_float(void **xpp, size_t nelems, const float *tp, void *fillp) +#line 3388 +{ +#line 3388 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3388 + +#line 3388 + /* basic algorithm is: +#line 3388 + * - ensure sane alignment of output data +#line 3388 + * - copy (conversion happens automatically) input data +#line 3388 + * to output +#line 3388 + * - update tp to point at next unconverted input, and xpp to point +#line 3388 + * at next location for converted output +#line 3388 + */ +#line 3388 + long i, j, ni; +#line 3388 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3388 + uint *xp; +#line 3388 + int nrange = 0; /* number of range errors */ +#line 3388 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3388 + long cxp = (long) *((char**)xpp); +#line 3388 + +#line 3388 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3388 + /* sjl: manually stripmine so we can limit amount of +#line 3388 + * vector work space reserved to LOOPCNT elements. Also +#line 3388 + * makes vectorisation easy */ +#line 3388 + for (j=0; j= 0 */ +#line 3388 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3388 + nrange += tp[i] > X_UINT_MAX || tp[i] < 0; +#line 3388 + } +#line 3388 + /* copy workspace back if necessary */ +#line 3388 + if (realign) { +#line 3388 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT); +#line 3388 + xp = (uint *) *xpp; +#line 3388 + } +#line 3388 + /* update xpp and tp */ +#line 3388 + xp += ni; +#line 3388 + tp += ni; +#line 3388 + *xpp = (void*)xp; +#line 3388 + } +#line 3388 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3388 + +#line 3388 +#else /* not SX */ +#line 3388 + +#line 3388 + char *xp = (char *) *xpp; +#line 3388 + int status = NC_NOERR; +#line 3388 + +#line 3388 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3388 + { +#line 3388 + int lstatus = ncx_put_uint_float(xp, tp, fillp); +#line 3388 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3388 + status = lstatus; +#line 3388 + } +#line 3388 + +#line 3388 + *xpp = (void *)xp; +#line 3388 + return status; +#line 3388 +#endif +#line 3388 +} +#line 3388 + +int +#line 3389 +ncx_putn_uint_double(void **xpp, size_t nelems, const double *tp, void *fillp) +#line 3389 +{ +#line 3389 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3389 + +#line 3389 + /* basic algorithm is: +#line 3389 + * - ensure sane alignment of output data +#line 3389 + * - copy (conversion happens automatically) input data +#line 3389 + * to output +#line 3389 + * - update tp to point at next unconverted input, and xpp to point +#line 3389 + * at next location for converted output +#line 3389 + */ +#line 3389 + long i, j, ni; +#line 3389 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3389 + uint *xp; +#line 3389 + int nrange = 0; /* number of range errors */ +#line 3389 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3389 + long cxp = (long) *((char**)xpp); +#line 3389 + +#line 3389 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3389 + /* sjl: manually stripmine so we can limit amount of +#line 3389 + * vector work space reserved to LOOPCNT elements. Also +#line 3389 + * makes vectorisation easy */ +#line 3389 + for (j=0; j= 0 */ +#line 3389 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3389 + nrange += tp[i] > X_UINT_MAX || tp[i] < 0; +#line 3389 + } +#line 3389 + /* copy workspace back if necessary */ +#line 3389 + if (realign) { +#line 3389 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT); +#line 3389 + xp = (uint *) *xpp; +#line 3389 + } +#line 3389 + /* update xpp and tp */ +#line 3389 + xp += ni; +#line 3389 + tp += ni; +#line 3389 + *xpp = (void*)xp; +#line 3389 + } +#line 3389 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3389 + +#line 3389 +#else /* not SX */ +#line 3389 + +#line 3389 + char *xp = (char *) *xpp; +#line 3389 + int status = NC_NOERR; +#line 3389 + +#line 3389 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3389 + { +#line 3389 + int lstatus = ncx_put_uint_double(xp, tp, fillp); +#line 3389 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3389 + status = lstatus; +#line 3389 + } +#line 3389 + +#line 3389 + *xpp = (void *)xp; +#line 3389 + return status; +#line 3389 +#endif +#line 3389 +} +#line 3389 + +int +#line 3390 +ncx_putn_uint_longlong(void **xpp, size_t nelems, const longlong *tp, void *fillp) +#line 3390 +{ +#line 3390 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3390 + +#line 3390 + /* basic algorithm is: +#line 3390 + * - ensure sane alignment of output data +#line 3390 + * - copy (conversion happens automatically) input data +#line 3390 + * to output +#line 3390 + * - update tp to point at next unconverted input, and xpp to point +#line 3390 + * at next location for converted output +#line 3390 + */ +#line 3390 + long i, j, ni; +#line 3390 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3390 + uint *xp; +#line 3390 + int nrange = 0; /* number of range errors */ +#line 3390 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3390 + long cxp = (long) *((char**)xpp); +#line 3390 + +#line 3390 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3390 + /* sjl: manually stripmine so we can limit amount of +#line 3390 + * vector work space reserved to LOOPCNT elements. Also +#line 3390 + * makes vectorisation easy */ +#line 3390 + for (j=0; j= 0 */ +#line 3390 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3390 + nrange += tp[i] > X_UINT_MAX || tp[i] < 0; +#line 3390 + } +#line 3390 + /* copy workspace back if necessary */ +#line 3390 + if (realign) { +#line 3390 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT); +#line 3390 + xp = (uint *) *xpp; +#line 3390 + } +#line 3390 + /* update xpp and tp */ +#line 3390 + xp += ni; +#line 3390 + tp += ni; +#line 3390 + *xpp = (void*)xp; +#line 3390 + } +#line 3390 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3390 + +#line 3390 +#else /* not SX */ +#line 3390 + +#line 3390 + char *xp = (char *) *xpp; +#line 3390 + int status = NC_NOERR; +#line 3390 + +#line 3390 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3390 + { +#line 3390 + int lstatus = ncx_put_uint_longlong(xp, tp, fillp); +#line 3390 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3390 + status = lstatus; +#line 3390 + } +#line 3390 + +#line 3390 + *xpp = (void *)xp; +#line 3390 + return status; +#line 3390 +#endif +#line 3390 +} +#line 3390 + +int +#line 3391 +ncx_putn_uint_uchar(void **xpp, size_t nelems, const uchar *tp, void *fillp) +#line 3391 +{ +#line 3391 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3391 + +#line 3391 + /* basic algorithm is: +#line 3391 + * - ensure sane alignment of output data +#line 3391 + * - copy (conversion happens automatically) input data +#line 3391 + * to output +#line 3391 + * - update tp to point at next unconverted input, and xpp to point +#line 3391 + * at next location for converted output +#line 3391 + */ +#line 3391 + long i, j, ni; +#line 3391 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3391 + uint *xp; +#line 3391 + int nrange = 0; /* number of range errors */ +#line 3391 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3391 + long cxp = (long) *((char**)xpp); +#line 3391 + +#line 3391 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3391 + /* sjl: manually stripmine so we can limit amount of +#line 3391 + * vector work space reserved to LOOPCNT elements. Also +#line 3391 + * makes vectorisation easy */ +#line 3391 + for (j=0; j= 0 */ +#line 3391 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3391 + nrange += tp[i] > X_UINT_MAX ; +#line 3391 + } +#line 3391 + /* copy workspace back if necessary */ +#line 3391 + if (realign) { +#line 3391 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT); +#line 3391 + xp = (uint *) *xpp; +#line 3391 + } +#line 3391 + /* update xpp and tp */ +#line 3391 + xp += ni; +#line 3391 + tp += ni; +#line 3391 + *xpp = (void*)xp; +#line 3391 + } +#line 3391 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3391 + +#line 3391 +#else /* not SX */ +#line 3391 + +#line 3391 + char *xp = (char *) *xpp; +#line 3391 + int status = NC_NOERR; +#line 3391 + +#line 3391 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3391 + { +#line 3391 + int lstatus = ncx_put_uint_uchar(xp, tp, fillp); +#line 3391 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3391 + status = lstatus; +#line 3391 + } +#line 3391 + +#line 3391 + *xpp = (void *)xp; +#line 3391 + return status; +#line 3391 +#endif +#line 3391 +} +#line 3391 + +int +#line 3392 +ncx_putn_uint_ushort(void **xpp, size_t nelems, const ushort *tp, void *fillp) +#line 3392 +{ +#line 3392 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3392 + +#line 3392 + /* basic algorithm is: +#line 3392 + * - ensure sane alignment of output data +#line 3392 + * - copy (conversion happens automatically) input data +#line 3392 + * to output +#line 3392 + * - update tp to point at next unconverted input, and xpp to point +#line 3392 + * at next location for converted output +#line 3392 + */ +#line 3392 + long i, j, ni; +#line 3392 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3392 + uint *xp; +#line 3392 + int nrange = 0; /* number of range errors */ +#line 3392 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3392 + long cxp = (long) *((char**)xpp); +#line 3392 + +#line 3392 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3392 + /* sjl: manually stripmine so we can limit amount of +#line 3392 + * vector work space reserved to LOOPCNT elements. Also +#line 3392 + * makes vectorisation easy */ +#line 3392 + for (j=0; j= 0 */ +#line 3392 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3392 + nrange += tp[i] > X_UINT_MAX ; +#line 3392 + } +#line 3392 + /* copy workspace back if necessary */ +#line 3392 + if (realign) { +#line 3392 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT); +#line 3392 + xp = (uint *) *xpp; +#line 3392 + } +#line 3392 + /* update xpp and tp */ +#line 3392 + xp += ni; +#line 3392 + tp += ni; +#line 3392 + *xpp = (void*)xp; +#line 3392 + } +#line 3392 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3392 + +#line 3392 +#else /* not SX */ +#line 3392 + +#line 3392 + char *xp = (char *) *xpp; +#line 3392 + int status = NC_NOERR; +#line 3392 + +#line 3392 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3392 + { +#line 3392 + int lstatus = ncx_put_uint_ushort(xp, tp, fillp); +#line 3392 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3392 + status = lstatus; +#line 3392 + } +#line 3392 + +#line 3392 + *xpp = (void *)xp; +#line 3392 + return status; +#line 3392 +#endif +#line 3392 +} +#line 3392 + +int +#line 3393 +ncx_putn_uint_ulonglong(void **xpp, size_t nelems, const ulonglong *tp, void *fillp) +#line 3393 +{ +#line 3393 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT == SIZEOF_UINT +#line 3393 + +#line 3393 + /* basic algorithm is: +#line 3393 + * - ensure sane alignment of output data +#line 3393 + * - copy (conversion happens automatically) input data +#line 3393 + * to output +#line 3393 + * - update tp to point at next unconverted input, and xpp to point +#line 3393 + * at next location for converted output +#line 3393 + */ +#line 3393 + long i, j, ni; +#line 3393 + uint tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3393 + uint *xp; +#line 3393 + int nrange = 0; /* number of range errors */ +#line 3393 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3393 + long cxp = (long) *((char**)xpp); +#line 3393 + +#line 3393 + realign = (cxp & 7) % SIZEOF_UINT; +#line 3393 + /* sjl: manually stripmine so we can limit amount of +#line 3393 + * vector work space reserved to LOOPCNT elements. Also +#line 3393 + * makes vectorisation easy */ +#line 3393 + for (j=0; j= 0 */ +#line 3393 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3393 + nrange += tp[i] > X_UINT_MAX ; +#line 3393 + } +#line 3393 + /* copy workspace back if necessary */ +#line 3393 + if (realign) { +#line 3393 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT); +#line 3393 + xp = (uint *) *xpp; +#line 3393 + } +#line 3393 + /* update xpp and tp */ +#line 3393 + xp += ni; +#line 3393 + tp += ni; +#line 3393 + *xpp = (void*)xp; +#line 3393 + } +#line 3393 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3393 + +#line 3393 +#else /* not SX */ +#line 3393 + +#line 3393 + char *xp = (char *) *xpp; +#line 3393 + int status = NC_NOERR; +#line 3393 + +#line 3393 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT, tp++) +#line 3393 + { +#line 3393 + int lstatus = ncx_put_uint_ulonglong(xp, tp, fillp); +#line 3393 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3393 + status = lstatus; +#line 3393 + } +#line 3393 + +#line 3393 + *xpp = (void *)xp; +#line 3393 + return status; +#line 3393 +#endif +#line 3393 +} +#line 3393 + + + +/* float ---------------------------------------------------------------------*/ + +#if X_SIZEOF_FLOAT == SIZEOF_FLOAT && !defined(NO_IEEE_FLOAT) +/* optimized version */ +int +ncx_getn_float_float(const void **xpp, size_t nelems, float *tp) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(tp, *xpp, (size_t)nelems * SIZEOF_FLOAT); +# else + swapn4b(tp, *xpp, nelems); +# endif + *xpp = (const void *)((const char *)(*xpp) + nelems * X_SIZEOF_FLOAT); + return NC_NOERR; +} +#elif defined(vax) && vax != 0 +int +ncx_getn_float_float(const void **xpp, size_t nfloats, float *ip) +{ + float *const end = ip + nfloats; + + while (ip < end) + { + struct vax_single *const vsp = (struct vax_single *) ip; +#line 3419 + const struct ieee_single *const isp = +#line 3419 + (const struct ieee_single *) (*xpp); +#line 3419 + unsigned exp = isp->exp_hi << 1 | isp->exp_lo; +#line 3419 + +#line 3419 + switch(exp) { +#line 3419 + case 0 : +#line 3419 + /* ieee subnormal */ +#line 3419 + if (isp->mant_hi == min.ieee.mant_hi +#line 3419 + && isp->mant_lo_hi == min.ieee.mant_lo_hi +#line 3419 + && isp->mant_lo_lo == min.ieee.mant_lo_lo) +#line 3419 + { +#line 3419 + *vsp = min.s; +#line 3419 + } +#line 3419 + else +#line 3419 + { +#line 3419 + unsigned mantissa = (isp->mant_hi << 16) +#line 3419 + | isp->mant_lo_hi << 8 +#line 3419 + | isp->mant_lo_lo; +#line 3419 + unsigned tmp = mantissa >> 20; +#line 3419 + if (tmp >= 4) { +#line 3419 + vsp->exp = 2; +#line 3419 + } else if (tmp >= 2) { +#line 3419 + vsp->exp = 1; +#line 3419 + } else { +#line 3419 + *vsp = min.s; +#line 3419 + break; +#line 3419 + } /* else */ +#line 3419 + tmp = mantissa - (1 << (20 + vsp->exp )); +#line 3419 + tmp <<= 3 - vsp->exp; +#line 3419 + vsp->mantissa2 = tmp; +#line 3419 + vsp->mantissa1 = (tmp >> 16); +#line 3419 + } +#line 3419 + break; +#line 3419 + case 0xfe : +#line 3419 + case 0xff : +#line 3419 + *vsp = max.s; +#line 3419 + break; +#line 3419 + default : +#line 3419 + vsp->exp = exp - IEEE_SNG_BIAS + VAX_SNG_BIAS; +#line 3419 + vsp->mantissa2 = isp->mant_lo_hi << 8 | isp->mant_lo_lo; +#line 3419 + vsp->mantissa1 = isp->mant_hi; +#line 3419 + } +#line 3419 + +#line 3419 + vsp->sign = isp->sign; +#line 3419 + + + ip++; + *xpp = (char *)(*xpp) + X_SIZEOF_FLOAT; + } + return NC_NOERR; +} +#else +int +ncx_getn_float_float(const void **xpp, size_t nelems, float *tp) +{ + const char *xp = *xpp; + int status = NC_NOERR; + + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) + { + const int lstatus = ncx_get_float_float(xp, tp, fillp); + if (status == NC_NOERR) /* report the first encountered error */ + status = lstatus; + } + + *xpp = (const void *)xp; + return status; +} + +#endif +int +#line 3445 +ncx_getn_float_schar(const void **xpp, size_t nelems, schar *tp) +#line 3445 +{ +#line 3445 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3445 + +#line 3445 + /* basic algorithm is: +#line 3445 + * - ensure sane alignment of input data +#line 3445 + * - copy (conversion happens automatically) input data +#line 3445 + * to output +#line 3445 + * - update xpp to point at next unconverted input, and tp to point +#line 3445 + * at next location for converted output +#line 3445 + */ +#line 3445 + long i, j, ni; +#line 3445 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3445 + float *xp; +#line 3445 + int nrange = 0; /* number of range errors */ +#line 3445 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3445 + long cxp = (long) *((char**)xpp); +#line 3445 + +#line 3445 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3445 + /* sjl: manually stripmine so we can limit amount of +#line 3445 + * vector work space reserved to LOOPCNT elements. Also +#line 3445 + * makes vectorisation easy */ +#line 3445 + for (j=0; j= 0 */ +#line 3445 + nrange += xp[i] > SCHAR_MAX || xp[i] < SCHAR_MIN; +#line 3445 + } +#line 3445 + /* update xpp and tp */ +#line 3445 + if (realign) xp = (float *) *xpp; +#line 3445 + xp += ni; +#line 3445 + tp += ni; +#line 3445 + *xpp = (void*)xp; +#line 3445 + } +#line 3445 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3445 + +#line 3445 +#else /* not SX */ +#line 3445 + const char *xp = (const char *) *xpp; +#line 3445 + int status = NC_NOERR; +#line 3445 + +#line 3445 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3445 + { +#line 3445 + const int lstatus = ncx_get_float_schar(xp, tp); +#line 3445 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3445 + status = lstatus; +#line 3445 + } +#line 3445 + +#line 3445 + *xpp = (const void *)xp; +#line 3445 + return status; +#line 3445 +#endif +#line 3445 +} +#line 3445 + +int +#line 3446 +ncx_getn_float_short(const void **xpp, size_t nelems, short *tp) +#line 3446 +{ +#line 3446 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3446 + +#line 3446 + /* basic algorithm is: +#line 3446 + * - ensure sane alignment of input data +#line 3446 + * - copy (conversion happens automatically) input data +#line 3446 + * to output +#line 3446 + * - update xpp to point at next unconverted input, and tp to point +#line 3446 + * at next location for converted output +#line 3446 + */ +#line 3446 + long i, j, ni; +#line 3446 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3446 + float *xp; +#line 3446 + int nrange = 0; /* number of range errors */ +#line 3446 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3446 + long cxp = (long) *((char**)xpp); +#line 3446 + +#line 3446 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3446 + /* sjl: manually stripmine so we can limit amount of +#line 3446 + * vector work space reserved to LOOPCNT elements. Also +#line 3446 + * makes vectorisation easy */ +#line 3446 + for (j=0; j= 0 */ +#line 3446 + nrange += xp[i] > SHORT_MAX || xp[i] < SHORT_MIN; +#line 3446 + } +#line 3446 + /* update xpp and tp */ +#line 3446 + if (realign) xp = (float *) *xpp; +#line 3446 + xp += ni; +#line 3446 + tp += ni; +#line 3446 + *xpp = (void*)xp; +#line 3446 + } +#line 3446 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3446 + +#line 3446 +#else /* not SX */ +#line 3446 + const char *xp = (const char *) *xpp; +#line 3446 + int status = NC_NOERR; +#line 3446 + +#line 3446 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3446 + { +#line 3446 + const int lstatus = ncx_get_float_short(xp, tp); +#line 3446 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3446 + status = lstatus; +#line 3446 + } +#line 3446 + +#line 3446 + *xpp = (const void *)xp; +#line 3446 + return status; +#line 3446 +#endif +#line 3446 +} +#line 3446 + +int +#line 3447 +ncx_getn_float_int(const void **xpp, size_t nelems, int *tp) +#line 3447 +{ +#line 3447 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3447 + +#line 3447 + /* basic algorithm is: +#line 3447 + * - ensure sane alignment of input data +#line 3447 + * - copy (conversion happens automatically) input data +#line 3447 + * to output +#line 3447 + * - update xpp to point at next unconverted input, and tp to point +#line 3447 + * at next location for converted output +#line 3447 + */ +#line 3447 + long i, j, ni; +#line 3447 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3447 + float *xp; +#line 3447 + int nrange = 0; /* number of range errors */ +#line 3447 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3447 + long cxp = (long) *((char**)xpp); +#line 3447 + +#line 3447 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3447 + /* sjl: manually stripmine so we can limit amount of +#line 3447 + * vector work space reserved to LOOPCNT elements. Also +#line 3447 + * makes vectorisation easy */ +#line 3447 + for (j=0; j= 0 */ +#line 3447 + nrange += xp[i] > INT_MAX || xp[i] < INT_MIN; +#line 3447 + } +#line 3447 + /* update xpp and tp */ +#line 3447 + if (realign) xp = (float *) *xpp; +#line 3447 + xp += ni; +#line 3447 + tp += ni; +#line 3447 + *xpp = (void*)xp; +#line 3447 + } +#line 3447 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3447 + +#line 3447 +#else /* not SX */ +#line 3447 + const char *xp = (const char *) *xpp; +#line 3447 + int status = NC_NOERR; +#line 3447 + +#line 3447 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3447 + { +#line 3447 + const int lstatus = ncx_get_float_int(xp, tp); +#line 3447 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3447 + status = lstatus; +#line 3447 + } +#line 3447 + +#line 3447 + *xpp = (const void *)xp; +#line 3447 + return status; +#line 3447 +#endif +#line 3447 +} +#line 3447 + +int +#line 3448 +ncx_getn_float_long(const void **xpp, size_t nelems, long *tp) +#line 3448 +{ +#line 3448 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3448 + +#line 3448 + /* basic algorithm is: +#line 3448 + * - ensure sane alignment of input data +#line 3448 + * - copy (conversion happens automatically) input data +#line 3448 + * to output +#line 3448 + * - update xpp to point at next unconverted input, and tp to point +#line 3448 + * at next location for converted output +#line 3448 + */ +#line 3448 + long i, j, ni; +#line 3448 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3448 + float *xp; +#line 3448 + int nrange = 0; /* number of range errors */ +#line 3448 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3448 + long cxp = (long) *((char**)xpp); +#line 3448 + +#line 3448 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3448 + /* sjl: manually stripmine so we can limit amount of +#line 3448 + * vector work space reserved to LOOPCNT elements. Also +#line 3448 + * makes vectorisation easy */ +#line 3448 + for (j=0; j= 0 */ +#line 3448 + nrange += xp[i] > LONG_MAX || xp[i] < LONG_MIN; +#line 3448 + } +#line 3448 + /* update xpp and tp */ +#line 3448 + if (realign) xp = (float *) *xpp; +#line 3448 + xp += ni; +#line 3448 + tp += ni; +#line 3448 + *xpp = (void*)xp; +#line 3448 + } +#line 3448 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3448 + +#line 3448 +#else /* not SX */ +#line 3448 + const char *xp = (const char *) *xpp; +#line 3448 + int status = NC_NOERR; +#line 3448 + +#line 3448 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3448 + { +#line 3448 + const int lstatus = ncx_get_float_long(xp, tp); +#line 3448 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3448 + status = lstatus; +#line 3448 + } +#line 3448 + +#line 3448 + *xpp = (const void *)xp; +#line 3448 + return status; +#line 3448 +#endif +#line 3448 +} +#line 3448 + +int +#line 3449 +ncx_getn_float_double(const void **xpp, size_t nelems, double *tp) +#line 3449 +{ +#line 3449 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3449 + +#line 3449 + /* basic algorithm is: +#line 3449 + * - ensure sane alignment of input data +#line 3449 + * - copy (conversion happens automatically) input data +#line 3449 + * to output +#line 3449 + * - update xpp to point at next unconverted input, and tp to point +#line 3449 + * at next location for converted output +#line 3449 + */ +#line 3449 + long i, j, ni; +#line 3449 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3449 + float *xp; +#line 3449 + int nrange = 0; /* number of range errors */ +#line 3449 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3449 + long cxp = (long) *((char**)xpp); +#line 3449 + +#line 3449 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3449 + /* sjl: manually stripmine so we can limit amount of +#line 3449 + * vector work space reserved to LOOPCNT elements. Also +#line 3449 + * makes vectorisation easy */ +#line 3449 + for (j=0; j= 0 */ +#line 3449 + nrange += xp[i] > DOUBLE_MAX || xp[i] < DOUBLE_MIN; +#line 3449 + } +#line 3449 + /* update xpp and tp */ +#line 3449 + if (realign) xp = (float *) *xpp; +#line 3449 + xp += ni; +#line 3449 + tp += ni; +#line 3449 + *xpp = (void*)xp; +#line 3449 + } +#line 3449 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3449 + +#line 3449 +#else /* not SX */ +#line 3449 + const char *xp = (const char *) *xpp; +#line 3449 + int status = NC_NOERR; +#line 3449 + +#line 3449 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3449 + { +#line 3449 + const int lstatus = ncx_get_float_double(xp, tp); +#line 3449 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3449 + status = lstatus; +#line 3449 + } +#line 3449 + +#line 3449 + *xpp = (const void *)xp; +#line 3449 + return status; +#line 3449 +#endif +#line 3449 +} +#line 3449 + +int +#line 3450 +ncx_getn_float_longlong(const void **xpp, size_t nelems, longlong *tp) +#line 3450 +{ +#line 3450 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3450 + +#line 3450 + /* basic algorithm is: +#line 3450 + * - ensure sane alignment of input data +#line 3450 + * - copy (conversion happens automatically) input data +#line 3450 + * to output +#line 3450 + * - update xpp to point at next unconverted input, and tp to point +#line 3450 + * at next location for converted output +#line 3450 + */ +#line 3450 + long i, j, ni; +#line 3450 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3450 + float *xp; +#line 3450 + int nrange = 0; /* number of range errors */ +#line 3450 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3450 + long cxp = (long) *((char**)xpp); +#line 3450 + +#line 3450 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3450 + /* sjl: manually stripmine so we can limit amount of +#line 3450 + * vector work space reserved to LOOPCNT elements. Also +#line 3450 + * makes vectorisation easy */ +#line 3450 + for (j=0; j= 0 */ +#line 3450 + nrange += xp[i] > LONGLONG_MAX || xp[i] < LONGLONG_MIN; +#line 3450 + } +#line 3450 + /* update xpp and tp */ +#line 3450 + if (realign) xp = (float *) *xpp; +#line 3450 + xp += ni; +#line 3450 + tp += ni; +#line 3450 + *xpp = (void*)xp; +#line 3450 + } +#line 3450 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3450 + +#line 3450 +#else /* not SX */ +#line 3450 + const char *xp = (const char *) *xpp; +#line 3450 + int status = NC_NOERR; +#line 3450 + +#line 3450 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3450 + { +#line 3450 + const int lstatus = ncx_get_float_longlong(xp, tp); +#line 3450 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3450 + status = lstatus; +#line 3450 + } +#line 3450 + +#line 3450 + *xpp = (const void *)xp; +#line 3450 + return status; +#line 3450 +#endif +#line 3450 +} +#line 3450 + +int +#line 3451 +ncx_getn_float_ushort(const void **xpp, size_t nelems, ushort *tp) +#line 3451 +{ +#line 3451 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3451 + +#line 3451 + /* basic algorithm is: +#line 3451 + * - ensure sane alignment of input data +#line 3451 + * - copy (conversion happens automatically) input data +#line 3451 + * to output +#line 3451 + * - update xpp to point at next unconverted input, and tp to point +#line 3451 + * at next location for converted output +#line 3451 + */ +#line 3451 + long i, j, ni; +#line 3451 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3451 + float *xp; +#line 3451 + int nrange = 0; /* number of range errors */ +#line 3451 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3451 + long cxp = (long) *((char**)xpp); +#line 3451 + +#line 3451 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3451 + /* sjl: manually stripmine so we can limit amount of +#line 3451 + * vector work space reserved to LOOPCNT elements. Also +#line 3451 + * makes vectorisation easy */ +#line 3451 + for (j=0; j= 0 */ +#line 3451 + nrange += xp[i] > USHORT_MAX || xp[i] < 0; +#line 3451 + } +#line 3451 + /* update xpp and tp */ +#line 3451 + if (realign) xp = (float *) *xpp; +#line 3451 + xp += ni; +#line 3451 + tp += ni; +#line 3451 + *xpp = (void*)xp; +#line 3451 + } +#line 3451 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3451 + +#line 3451 +#else /* not SX */ +#line 3451 + const char *xp = (const char *) *xpp; +#line 3451 + int status = NC_NOERR; +#line 3451 + +#line 3451 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3451 + { +#line 3451 + const int lstatus = ncx_get_float_ushort(xp, tp); +#line 3451 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3451 + status = lstatus; +#line 3451 + } +#line 3451 + +#line 3451 + *xpp = (const void *)xp; +#line 3451 + return status; +#line 3451 +#endif +#line 3451 +} +#line 3451 + +int +#line 3452 +ncx_getn_float_uchar(const void **xpp, size_t nelems, uchar *tp) +#line 3452 +{ +#line 3452 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3452 + +#line 3452 + /* basic algorithm is: +#line 3452 + * - ensure sane alignment of input data +#line 3452 + * - copy (conversion happens automatically) input data +#line 3452 + * to output +#line 3452 + * - update xpp to point at next unconverted input, and tp to point +#line 3452 + * at next location for converted output +#line 3452 + */ +#line 3452 + long i, j, ni; +#line 3452 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3452 + float *xp; +#line 3452 + int nrange = 0; /* number of range errors */ +#line 3452 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3452 + long cxp = (long) *((char**)xpp); +#line 3452 + +#line 3452 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3452 + /* sjl: manually stripmine so we can limit amount of +#line 3452 + * vector work space reserved to LOOPCNT elements. Also +#line 3452 + * makes vectorisation easy */ +#line 3452 + for (j=0; j= 0 */ +#line 3452 + nrange += xp[i] > UCHAR_MAX || xp[i] < 0; +#line 3452 + } +#line 3452 + /* update xpp and tp */ +#line 3452 + if (realign) xp = (float *) *xpp; +#line 3452 + xp += ni; +#line 3452 + tp += ni; +#line 3452 + *xpp = (void*)xp; +#line 3452 + } +#line 3452 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3452 + +#line 3452 +#else /* not SX */ +#line 3452 + const char *xp = (const char *) *xpp; +#line 3452 + int status = NC_NOERR; +#line 3452 + +#line 3452 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3452 + { +#line 3452 + const int lstatus = ncx_get_float_uchar(xp, tp); +#line 3452 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3452 + status = lstatus; +#line 3452 + } +#line 3452 + +#line 3452 + *xpp = (const void *)xp; +#line 3452 + return status; +#line 3452 +#endif +#line 3452 +} +#line 3452 + +int +#line 3453 +ncx_getn_float_uint(const void **xpp, size_t nelems, uint *tp) +#line 3453 +{ +#line 3453 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3453 + +#line 3453 + /* basic algorithm is: +#line 3453 + * - ensure sane alignment of input data +#line 3453 + * - copy (conversion happens automatically) input data +#line 3453 + * to output +#line 3453 + * - update xpp to point at next unconverted input, and tp to point +#line 3453 + * at next location for converted output +#line 3453 + */ +#line 3453 + long i, j, ni; +#line 3453 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3453 + float *xp; +#line 3453 + int nrange = 0; /* number of range errors */ +#line 3453 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3453 + long cxp = (long) *((char**)xpp); +#line 3453 + +#line 3453 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3453 + /* sjl: manually stripmine so we can limit amount of +#line 3453 + * vector work space reserved to LOOPCNT elements. Also +#line 3453 + * makes vectorisation easy */ +#line 3453 + for (j=0; j= 0 */ +#line 3453 + nrange += xp[i] > UINT_MAX || xp[i] < 0; +#line 3453 + } +#line 3453 + /* update xpp and tp */ +#line 3453 + if (realign) xp = (float *) *xpp; +#line 3453 + xp += ni; +#line 3453 + tp += ni; +#line 3453 + *xpp = (void*)xp; +#line 3453 + } +#line 3453 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3453 + +#line 3453 +#else /* not SX */ +#line 3453 + const char *xp = (const char *) *xpp; +#line 3453 + int status = NC_NOERR; +#line 3453 + +#line 3453 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3453 + { +#line 3453 + const int lstatus = ncx_get_float_uint(xp, tp); +#line 3453 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3453 + status = lstatus; +#line 3453 + } +#line 3453 + +#line 3453 + *xpp = (const void *)xp; +#line 3453 + return status; +#line 3453 +#endif +#line 3453 +} +#line 3453 + +int +#line 3454 +ncx_getn_float_ulonglong(const void **xpp, size_t nelems, ulonglong *tp) +#line 3454 +{ +#line 3454 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3454 + +#line 3454 + /* basic algorithm is: +#line 3454 + * - ensure sane alignment of input data +#line 3454 + * - copy (conversion happens automatically) input data +#line 3454 + * to output +#line 3454 + * - update xpp to point at next unconverted input, and tp to point +#line 3454 + * at next location for converted output +#line 3454 + */ +#line 3454 + long i, j, ni; +#line 3454 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3454 + float *xp; +#line 3454 + int nrange = 0; /* number of range errors */ +#line 3454 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3454 + long cxp = (long) *((char**)xpp); +#line 3454 + +#line 3454 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3454 + /* sjl: manually stripmine so we can limit amount of +#line 3454 + * vector work space reserved to LOOPCNT elements. Also +#line 3454 + * makes vectorisation easy */ +#line 3454 + for (j=0; j= 0 */ +#line 3454 + nrange += xp[i] > ULONGLONG_MAX || xp[i] < 0; +#line 3454 + } +#line 3454 + /* update xpp and tp */ +#line 3454 + if (realign) xp = (float *) *xpp; +#line 3454 + xp += ni; +#line 3454 + tp += ni; +#line 3454 + *xpp = (void*)xp; +#line 3454 + } +#line 3454 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3454 + +#line 3454 +#else /* not SX */ +#line 3454 + const char *xp = (const char *) *xpp; +#line 3454 + int status = NC_NOERR; +#line 3454 + +#line 3454 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3454 + { +#line 3454 + const int lstatus = ncx_get_float_ulonglong(xp, tp); +#line 3454 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3454 + status = lstatus; +#line 3454 + } +#line 3454 + +#line 3454 + *xpp = (const void *)xp; +#line 3454 + return status; +#line 3454 +#endif +#line 3454 +} +#line 3454 + + +int +ncx_putn_float_float(void **xpp, size_t nelems, const float *tp, void *fillp) +#if X_SIZEOF_FLOAT == SIZEOF_FLOAT && !defined(NO_IEEE_FLOAT) +/* optimized version */ +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(*xpp, tp, (size_t)nelems * X_SIZEOF_FLOAT); +# else + swapn4b(*xpp, tp, nelems); +# endif + *xpp = (void *)((char *)(*xpp) + nelems * X_SIZEOF_FLOAT); + return NC_NOERR; +} +#elif defined(vax) && vax != 0 +{ + const float *const end = tp + nelems; + + while (tp < end) { + const struct vax_single *const vsp = +#line 3474 + (const struct vax_single *)ip; +#line 3474 + struct ieee_single *const isp = (struct ieee_single *) (*xpp); +#line 3474 + +#line 3474 + switch(vsp->exp){ +#line 3474 + case 0 : +#line 3474 + /* all vax float with zero exponent map to zero */ +#line 3474 + *isp = min.ieee; +#line 3474 + break; +#line 3474 + case 2 : +#line 3474 + case 1 : +#line 3474 + { +#line 3474 + /* These will map to subnormals */ +#line 3474 + unsigned mantissa = (vsp->mantissa1 << 16) +#line 3474 + | vsp->mantissa2; +#line 3474 + mantissa >>= 3 - vsp->exp; +#line 3474 + mantissa += (1 << (20 + vsp->exp)); +#line 3474 + isp->mant_lo_lo = mantissa; +#line 3474 + isp->mant_lo_hi = mantissa >> 8; +#line 3474 + isp->mant_hi = mantissa >> 16; +#line 3474 + isp->exp_lo = 0; +#line 3474 + isp->exp_hi = 0; +#line 3474 + } +#line 3474 + break; +#line 3474 + case 0xff : /* max.s.exp */ +#line 3474 + if (vsp->mantissa2 == max.s.mantissa2 && +#line 3474 + vsp->mantissa1 == max.s.mantissa1) +#line 3474 + { +#line 3474 + /* map largest vax float to ieee infinity */ +#line 3474 + *isp = max.ieee; +#line 3474 + break; +#line 3474 + } /* else, fall thru */ +#line 3474 + default : +#line 3474 + { +#line 3474 + unsigned exp = vsp->exp - VAX_SNG_BIAS + IEEE_SNG_BIAS; +#line 3474 + isp->exp_hi = exp >> 1; +#line 3474 + isp->exp_lo = exp; +#line 3474 + isp->mant_lo_lo = vsp->mantissa2; +#line 3474 + isp->mant_lo_hi = vsp->mantissa2 >> 8; +#line 3474 + isp->mant_hi = vsp->mantissa1; +#line 3474 + } +#line 3474 + } +#line 3474 + +#line 3474 + isp->sign = vsp->sign; +#line 3474 + + tp++; + *xpp = (char *)(*xpp) + X_SIZEOF_FLOAT; + } + return NC_NOERR; +} +#else +{ + char *xp = *xpp; + int status = NC_NOERR; + + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) { + int lstatus = ncx_put_float_float(xp, tp, fillp); + if (status == NC_NOERR) /* report the first encountered error */ + status = lstatus; + } + + *xpp = (void *)xp; + return status; +} +#endif +int +#line 3495 +ncx_putn_float_schar(void **xpp, size_t nelems, const schar *tp, void *fillp) +#line 3495 +{ +#line 3495 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3495 + +#line 3495 + /* basic algorithm is: +#line 3495 + * - ensure sane alignment of output data +#line 3495 + * - copy (conversion happens automatically) input data +#line 3495 + * to output +#line 3495 + * - update tp to point at next unconverted input, and xpp to point +#line 3495 + * at next location for converted output +#line 3495 + */ +#line 3495 + long i, j, ni; +#line 3495 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3495 + float *xp; +#line 3495 + int nrange = 0; /* number of range errors */ +#line 3495 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3495 + long cxp = (long) *((char**)xpp); +#line 3495 + +#line 3495 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3495 + /* sjl: manually stripmine so we can limit amount of +#line 3495 + * vector work space reserved to LOOPCNT elements. Also +#line 3495 + * makes vectorisation easy */ +#line 3495 + for (j=0; j= 0 */ +#line 3495 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3495 + nrange += tp[i] > X_FLOAT_MAX || tp[i] < X_FLOAT_MIN; +#line 3495 + } +#line 3495 + /* copy workspace back if necessary */ +#line 3495 + if (realign) { +#line 3495 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_FLOAT); +#line 3495 + xp = (float *) *xpp; +#line 3495 + } +#line 3495 + /* update xpp and tp */ +#line 3495 + xp += ni; +#line 3495 + tp += ni; +#line 3495 + *xpp = (void*)xp; +#line 3495 + } +#line 3495 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3495 + +#line 3495 +#else /* not SX */ +#line 3495 + +#line 3495 + char *xp = (char *) *xpp; +#line 3495 + int status = NC_NOERR; +#line 3495 + +#line 3495 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3495 + { +#line 3495 + int lstatus = ncx_put_float_schar(xp, tp, fillp); +#line 3495 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3495 + status = lstatus; +#line 3495 + } +#line 3495 + +#line 3495 + *xpp = (void *)xp; +#line 3495 + return status; +#line 3495 +#endif +#line 3495 +} +#line 3495 + +int +#line 3496 +ncx_putn_float_short(void **xpp, size_t nelems, const short *tp, void *fillp) +#line 3496 +{ +#line 3496 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3496 + +#line 3496 + /* basic algorithm is: +#line 3496 + * - ensure sane alignment of output data +#line 3496 + * - copy (conversion happens automatically) input data +#line 3496 + * to output +#line 3496 + * - update tp to point at next unconverted input, and xpp to point +#line 3496 + * at next location for converted output +#line 3496 + */ +#line 3496 + long i, j, ni; +#line 3496 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3496 + float *xp; +#line 3496 + int nrange = 0; /* number of range errors */ +#line 3496 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3496 + long cxp = (long) *((char**)xpp); +#line 3496 + +#line 3496 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3496 + /* sjl: manually stripmine so we can limit amount of +#line 3496 + * vector work space reserved to LOOPCNT elements. Also +#line 3496 + * makes vectorisation easy */ +#line 3496 + for (j=0; j= 0 */ +#line 3496 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3496 + nrange += tp[i] > X_FLOAT_MAX || tp[i] < X_FLOAT_MIN; +#line 3496 + } +#line 3496 + /* copy workspace back if necessary */ +#line 3496 + if (realign) { +#line 3496 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_FLOAT); +#line 3496 + xp = (float *) *xpp; +#line 3496 + } +#line 3496 + /* update xpp and tp */ +#line 3496 + xp += ni; +#line 3496 + tp += ni; +#line 3496 + *xpp = (void*)xp; +#line 3496 + } +#line 3496 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3496 + +#line 3496 +#else /* not SX */ +#line 3496 + +#line 3496 + char *xp = (char *) *xpp; +#line 3496 + int status = NC_NOERR; +#line 3496 + +#line 3496 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3496 + { +#line 3496 + int lstatus = ncx_put_float_short(xp, tp, fillp); +#line 3496 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3496 + status = lstatus; +#line 3496 + } +#line 3496 + +#line 3496 + *xpp = (void *)xp; +#line 3496 + return status; +#line 3496 +#endif +#line 3496 +} +#line 3496 + +int +#line 3497 +ncx_putn_float_int(void **xpp, size_t nelems, const int *tp, void *fillp) +#line 3497 +{ +#line 3497 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3497 + +#line 3497 + /* basic algorithm is: +#line 3497 + * - ensure sane alignment of output data +#line 3497 + * - copy (conversion happens automatically) input data +#line 3497 + * to output +#line 3497 + * - update tp to point at next unconverted input, and xpp to point +#line 3497 + * at next location for converted output +#line 3497 + */ +#line 3497 + long i, j, ni; +#line 3497 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3497 + float *xp; +#line 3497 + int nrange = 0; /* number of range errors */ +#line 3497 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3497 + long cxp = (long) *((char**)xpp); +#line 3497 + +#line 3497 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3497 + /* sjl: manually stripmine so we can limit amount of +#line 3497 + * vector work space reserved to LOOPCNT elements. Also +#line 3497 + * makes vectorisation easy */ +#line 3497 + for (j=0; j= 0 */ +#line 3497 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3497 + nrange += tp[i] > X_FLOAT_MAX || tp[i] < X_FLOAT_MIN; +#line 3497 + } +#line 3497 + /* copy workspace back if necessary */ +#line 3497 + if (realign) { +#line 3497 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_FLOAT); +#line 3497 + xp = (float *) *xpp; +#line 3497 + } +#line 3497 + /* update xpp and tp */ +#line 3497 + xp += ni; +#line 3497 + tp += ni; +#line 3497 + *xpp = (void*)xp; +#line 3497 + } +#line 3497 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3497 + +#line 3497 +#else /* not SX */ +#line 3497 + +#line 3497 + char *xp = (char *) *xpp; +#line 3497 + int status = NC_NOERR; +#line 3497 + +#line 3497 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3497 + { +#line 3497 + int lstatus = ncx_put_float_int(xp, tp, fillp); +#line 3497 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3497 + status = lstatus; +#line 3497 + } +#line 3497 + +#line 3497 + *xpp = (void *)xp; +#line 3497 + return status; +#line 3497 +#endif +#line 3497 +} +#line 3497 + +int +#line 3498 +ncx_putn_float_long(void **xpp, size_t nelems, const long *tp, void *fillp) +#line 3498 +{ +#line 3498 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3498 + +#line 3498 + /* basic algorithm is: +#line 3498 + * - ensure sane alignment of output data +#line 3498 + * - copy (conversion happens automatically) input data +#line 3498 + * to output +#line 3498 + * - update tp to point at next unconverted input, and xpp to point +#line 3498 + * at next location for converted output +#line 3498 + */ +#line 3498 + long i, j, ni; +#line 3498 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3498 + float *xp; +#line 3498 + int nrange = 0; /* number of range errors */ +#line 3498 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3498 + long cxp = (long) *((char**)xpp); +#line 3498 + +#line 3498 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3498 + /* sjl: manually stripmine so we can limit amount of +#line 3498 + * vector work space reserved to LOOPCNT elements. Also +#line 3498 + * makes vectorisation easy */ +#line 3498 + for (j=0; j= 0 */ +#line 3498 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3498 + nrange += tp[i] > X_FLOAT_MAX || tp[i] < X_FLOAT_MIN; +#line 3498 + } +#line 3498 + /* copy workspace back if necessary */ +#line 3498 + if (realign) { +#line 3498 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_FLOAT); +#line 3498 + xp = (float *) *xpp; +#line 3498 + } +#line 3498 + /* update xpp and tp */ +#line 3498 + xp += ni; +#line 3498 + tp += ni; +#line 3498 + *xpp = (void*)xp; +#line 3498 + } +#line 3498 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3498 + +#line 3498 +#else /* not SX */ +#line 3498 + +#line 3498 + char *xp = (char *) *xpp; +#line 3498 + int status = NC_NOERR; +#line 3498 + +#line 3498 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3498 + { +#line 3498 + int lstatus = ncx_put_float_long(xp, tp, fillp); +#line 3498 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3498 + status = lstatus; +#line 3498 + } +#line 3498 + +#line 3498 + *xpp = (void *)xp; +#line 3498 + return status; +#line 3498 +#endif +#line 3498 +} +#line 3498 + +int +#line 3499 +ncx_putn_float_double(void **xpp, size_t nelems, const double *tp, void *fillp) +#line 3499 +{ +#line 3499 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3499 + +#line 3499 + /* basic algorithm is: +#line 3499 + * - ensure sane alignment of output data +#line 3499 + * - copy (conversion happens automatically) input data +#line 3499 + * to output +#line 3499 + * - update tp to point at next unconverted input, and xpp to point +#line 3499 + * at next location for converted output +#line 3499 + */ +#line 3499 + long i, j, ni; +#line 3499 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3499 + float *xp; +#line 3499 + int nrange = 0; /* number of range errors */ +#line 3499 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3499 + long cxp = (long) *((char**)xpp); +#line 3499 + +#line 3499 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3499 + /* sjl: manually stripmine so we can limit amount of +#line 3499 + * vector work space reserved to LOOPCNT elements. Also +#line 3499 + * makes vectorisation easy */ +#line 3499 + for (j=0; j= 0 */ +#line 3499 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3499 + nrange += tp[i] > X_FLOAT_MAX || tp[i] < X_FLOAT_MIN; +#line 3499 + } +#line 3499 + /* copy workspace back if necessary */ +#line 3499 + if (realign) { +#line 3499 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_FLOAT); +#line 3499 + xp = (float *) *xpp; +#line 3499 + } +#line 3499 + /* update xpp and tp */ +#line 3499 + xp += ni; +#line 3499 + tp += ni; +#line 3499 + *xpp = (void*)xp; +#line 3499 + } +#line 3499 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3499 + +#line 3499 +#else /* not SX */ +#line 3499 + +#line 3499 + char *xp = (char *) *xpp; +#line 3499 + int status = NC_NOERR; +#line 3499 + +#line 3499 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3499 + { +#line 3499 + int lstatus = ncx_put_float_double(xp, tp, fillp); +#line 3499 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3499 + status = lstatus; +#line 3499 + } +#line 3499 + +#line 3499 + *xpp = (void *)xp; +#line 3499 + return status; +#line 3499 +#endif +#line 3499 +} +#line 3499 + +int +#line 3500 +ncx_putn_float_longlong(void **xpp, size_t nelems, const longlong *tp, void *fillp) +#line 3500 +{ +#line 3500 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3500 + +#line 3500 + /* basic algorithm is: +#line 3500 + * - ensure sane alignment of output data +#line 3500 + * - copy (conversion happens automatically) input data +#line 3500 + * to output +#line 3500 + * - update tp to point at next unconverted input, and xpp to point +#line 3500 + * at next location for converted output +#line 3500 + */ +#line 3500 + long i, j, ni; +#line 3500 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3500 + float *xp; +#line 3500 + int nrange = 0; /* number of range errors */ +#line 3500 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3500 + long cxp = (long) *((char**)xpp); +#line 3500 + +#line 3500 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3500 + /* sjl: manually stripmine so we can limit amount of +#line 3500 + * vector work space reserved to LOOPCNT elements. Also +#line 3500 + * makes vectorisation easy */ +#line 3500 + for (j=0; j= 0 */ +#line 3500 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3500 + nrange += tp[i] > X_FLOAT_MAX || tp[i] < X_FLOAT_MIN; +#line 3500 + } +#line 3500 + /* copy workspace back if necessary */ +#line 3500 + if (realign) { +#line 3500 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_FLOAT); +#line 3500 + xp = (float *) *xpp; +#line 3500 + } +#line 3500 + /* update xpp and tp */ +#line 3500 + xp += ni; +#line 3500 + tp += ni; +#line 3500 + *xpp = (void*)xp; +#line 3500 + } +#line 3500 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3500 + +#line 3500 +#else /* not SX */ +#line 3500 + +#line 3500 + char *xp = (char *) *xpp; +#line 3500 + int status = NC_NOERR; +#line 3500 + +#line 3500 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3500 + { +#line 3500 + int lstatus = ncx_put_float_longlong(xp, tp, fillp); +#line 3500 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3500 + status = lstatus; +#line 3500 + } +#line 3500 + +#line 3500 + *xpp = (void *)xp; +#line 3500 + return status; +#line 3500 +#endif +#line 3500 +} +#line 3500 + +int +#line 3501 +ncx_putn_float_uchar(void **xpp, size_t nelems, const uchar *tp, void *fillp) +#line 3501 +{ +#line 3501 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3501 + +#line 3501 + /* basic algorithm is: +#line 3501 + * - ensure sane alignment of output data +#line 3501 + * - copy (conversion happens automatically) input data +#line 3501 + * to output +#line 3501 + * - update tp to point at next unconverted input, and xpp to point +#line 3501 + * at next location for converted output +#line 3501 + */ +#line 3501 + long i, j, ni; +#line 3501 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3501 + float *xp; +#line 3501 + int nrange = 0; /* number of range errors */ +#line 3501 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3501 + long cxp = (long) *((char**)xpp); +#line 3501 + +#line 3501 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3501 + /* sjl: manually stripmine so we can limit amount of +#line 3501 + * vector work space reserved to LOOPCNT elements. Also +#line 3501 + * makes vectorisation easy */ +#line 3501 + for (j=0; j= 0 */ +#line 3501 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3501 + nrange += tp[i] > X_FLOAT_MAX ; +#line 3501 + } +#line 3501 + /* copy workspace back if necessary */ +#line 3501 + if (realign) { +#line 3501 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_FLOAT); +#line 3501 + xp = (float *) *xpp; +#line 3501 + } +#line 3501 + /* update xpp and tp */ +#line 3501 + xp += ni; +#line 3501 + tp += ni; +#line 3501 + *xpp = (void*)xp; +#line 3501 + } +#line 3501 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3501 + +#line 3501 +#else /* not SX */ +#line 3501 + +#line 3501 + char *xp = (char *) *xpp; +#line 3501 + int status = NC_NOERR; +#line 3501 + +#line 3501 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3501 + { +#line 3501 + int lstatus = ncx_put_float_uchar(xp, tp, fillp); +#line 3501 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3501 + status = lstatus; +#line 3501 + } +#line 3501 + +#line 3501 + *xpp = (void *)xp; +#line 3501 + return status; +#line 3501 +#endif +#line 3501 +} +#line 3501 + +int +#line 3502 +ncx_putn_float_ushort(void **xpp, size_t nelems, const ushort *tp, void *fillp) +#line 3502 +{ +#line 3502 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3502 + +#line 3502 + /* basic algorithm is: +#line 3502 + * - ensure sane alignment of output data +#line 3502 + * - copy (conversion happens automatically) input data +#line 3502 + * to output +#line 3502 + * - update tp to point at next unconverted input, and xpp to point +#line 3502 + * at next location for converted output +#line 3502 + */ +#line 3502 + long i, j, ni; +#line 3502 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3502 + float *xp; +#line 3502 + int nrange = 0; /* number of range errors */ +#line 3502 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3502 + long cxp = (long) *((char**)xpp); +#line 3502 + +#line 3502 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3502 + /* sjl: manually stripmine so we can limit amount of +#line 3502 + * vector work space reserved to LOOPCNT elements. Also +#line 3502 + * makes vectorisation easy */ +#line 3502 + for (j=0; j= 0 */ +#line 3502 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3502 + nrange += tp[i] > X_FLOAT_MAX ; +#line 3502 + } +#line 3502 + /* copy workspace back if necessary */ +#line 3502 + if (realign) { +#line 3502 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_FLOAT); +#line 3502 + xp = (float *) *xpp; +#line 3502 + } +#line 3502 + /* update xpp and tp */ +#line 3502 + xp += ni; +#line 3502 + tp += ni; +#line 3502 + *xpp = (void*)xp; +#line 3502 + } +#line 3502 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3502 + +#line 3502 +#else /* not SX */ +#line 3502 + +#line 3502 + char *xp = (char *) *xpp; +#line 3502 + int status = NC_NOERR; +#line 3502 + +#line 3502 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3502 + { +#line 3502 + int lstatus = ncx_put_float_ushort(xp, tp, fillp); +#line 3502 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3502 + status = lstatus; +#line 3502 + } +#line 3502 + +#line 3502 + *xpp = (void *)xp; +#line 3502 + return status; +#line 3502 +#endif +#line 3502 +} +#line 3502 + +int +#line 3503 +ncx_putn_float_uint(void **xpp, size_t nelems, const uint *tp, void *fillp) +#line 3503 +{ +#line 3503 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3503 + +#line 3503 + /* basic algorithm is: +#line 3503 + * - ensure sane alignment of output data +#line 3503 + * - copy (conversion happens automatically) input data +#line 3503 + * to output +#line 3503 + * - update tp to point at next unconverted input, and xpp to point +#line 3503 + * at next location for converted output +#line 3503 + */ +#line 3503 + long i, j, ni; +#line 3503 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3503 + float *xp; +#line 3503 + int nrange = 0; /* number of range errors */ +#line 3503 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3503 + long cxp = (long) *((char**)xpp); +#line 3503 + +#line 3503 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3503 + /* sjl: manually stripmine so we can limit amount of +#line 3503 + * vector work space reserved to LOOPCNT elements. Also +#line 3503 + * makes vectorisation easy */ +#line 3503 + for (j=0; j= 0 */ +#line 3503 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3503 + nrange += tp[i] > X_FLOAT_MAX ; +#line 3503 + } +#line 3503 + /* copy workspace back if necessary */ +#line 3503 + if (realign) { +#line 3503 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_FLOAT); +#line 3503 + xp = (float *) *xpp; +#line 3503 + } +#line 3503 + /* update xpp and tp */ +#line 3503 + xp += ni; +#line 3503 + tp += ni; +#line 3503 + *xpp = (void*)xp; +#line 3503 + } +#line 3503 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3503 + +#line 3503 +#else /* not SX */ +#line 3503 + +#line 3503 + char *xp = (char *) *xpp; +#line 3503 + int status = NC_NOERR; +#line 3503 + +#line 3503 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3503 + { +#line 3503 + int lstatus = ncx_put_float_uint(xp, tp, fillp); +#line 3503 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3503 + status = lstatus; +#line 3503 + } +#line 3503 + +#line 3503 + *xpp = (void *)xp; +#line 3503 + return status; +#line 3503 +#endif +#line 3503 +} +#line 3503 + +int +#line 3504 +ncx_putn_float_ulonglong(void **xpp, size_t nelems, const ulonglong *tp, void *fillp) +#line 3504 +{ +#line 3504 +#if defined(_SX) && _SX != 0 && X_SIZEOF_FLOAT == SIZEOF_FLOAT +#line 3504 + +#line 3504 + /* basic algorithm is: +#line 3504 + * - ensure sane alignment of output data +#line 3504 + * - copy (conversion happens automatically) input data +#line 3504 + * to output +#line 3504 + * - update tp to point at next unconverted input, and xpp to point +#line 3504 + * at next location for converted output +#line 3504 + */ +#line 3504 + long i, j, ni; +#line 3504 + float tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3504 + float *xp; +#line 3504 + int nrange = 0; /* number of range errors */ +#line 3504 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3504 + long cxp = (long) *((char**)xpp); +#line 3504 + +#line 3504 + realign = (cxp & 7) % SIZEOF_FLOAT; +#line 3504 + /* sjl: manually stripmine so we can limit amount of +#line 3504 + * vector work space reserved to LOOPCNT elements. Also +#line 3504 + * makes vectorisation easy */ +#line 3504 + for (j=0; j= 0 */ +#line 3504 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3504 + nrange += tp[i] > X_FLOAT_MAX ; +#line 3504 + } +#line 3504 + /* copy workspace back if necessary */ +#line 3504 + if (realign) { +#line 3504 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_FLOAT); +#line 3504 + xp = (float *) *xpp; +#line 3504 + } +#line 3504 + /* update xpp and tp */ +#line 3504 + xp += ni; +#line 3504 + tp += ni; +#line 3504 + *xpp = (void*)xp; +#line 3504 + } +#line 3504 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3504 + +#line 3504 +#else /* not SX */ +#line 3504 + +#line 3504 + char *xp = (char *) *xpp; +#line 3504 + int status = NC_NOERR; +#line 3504 + +#line 3504 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) +#line 3504 + { +#line 3504 + int lstatus = ncx_put_float_ulonglong(xp, tp, fillp); +#line 3504 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3504 + status = lstatus; +#line 3504 + } +#line 3504 + +#line 3504 + *xpp = (void *)xp; +#line 3504 + return status; +#line 3504 +#endif +#line 3504 +} +#line 3504 + + +/* double --------------------------------------------------------------------*/ + +#if X_SIZEOF_DOUBLE == SIZEOF_DOUBLE && !defined(NO_IEEE_FLOAT) +/* optimized version */ +int +ncx_getn_double_double(const void **xpp, size_t nelems, double *tp) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(tp, *xpp, (size_t)nelems * SIZEOF_DOUBLE); +# else + swapn8b(tp, *xpp, nelems); +# endif + *xpp = (const void *)((const char *)(*xpp) + nelems * X_SIZEOF_DOUBLE); + return NC_NOERR; +} +#elif defined(vax) && vax != 0 +int +ncx_getn_double_double(const void **xpp, size_t ndoubles, double *ip) +{ + double *const end = ip + ndoubles; + + while (ip < end) + { + struct vax_double *const vdp = +#line 3529 + (struct vax_double *)ip; +#line 3529 + const struct ieee_double *const idp = +#line 3529 + (const struct ieee_double *) (*xpp); +#line 3529 + { +#line 3529 + const struct dbl_limits *lim; +#line 3529 + int ii; +#line 3529 + for (ii = 0, lim = dbl_limits; +#line 3529 + ii < sizeof(dbl_limits)/sizeof(struct dbl_limits); +#line 3529 + ii++, lim++) +#line 3529 + { +#line 3529 + if ((idp->mant_lo == lim->ieee.mant_lo) +#line 3529 + && (idp->mant_4 == lim->ieee.mant_4) +#line 3529 + && (idp->mant_5 == lim->ieee.mant_5) +#line 3529 + && (idp->mant_6 == lim->ieee.mant_6) +#line 3529 + && (idp->exp_lo == lim->ieee.exp_lo) +#line 3529 + && (idp->exp_hi == lim->ieee.exp_hi) +#line 3529 + ) +#line 3529 + { +#line 3529 + *vdp = lim->d; +#line 3529 + goto doneit; +#line 3529 + } +#line 3529 + } +#line 3529 + } +#line 3529 + { +#line 3529 + unsigned exp = idp->exp_hi << 4 | idp->exp_lo; +#line 3529 + vdp->exp = exp - IEEE_DBL_BIAS + VAX_DBL_BIAS; +#line 3529 + } +#line 3529 + { +#line 3529 + unsigned mant_hi = ((idp->mant_6 << 16) +#line 3529 + | (idp->mant_5 << 8) +#line 3529 + | idp->mant_4); +#line 3529 + unsigned mant_lo = SWAP4(idp->mant_lo); +#line 3529 + vdp->mantissa1 = (mant_hi >> 13); +#line 3529 + vdp->mantissa2 = ((mant_hi & MASK(13)) << 3) +#line 3529 + | (mant_lo >> 29); +#line 3529 + vdp->mantissa3 = (mant_lo >> 13); +#line 3529 + vdp->mantissa4 = (mant_lo << 3); +#line 3529 + } +#line 3529 + doneit: +#line 3529 + vdp->sign = idp->sign; +#line 3529 + + ip++; + *xpp = (char *)(*xpp) + X_SIZEOF_DOUBLE; + } + return NC_NOERR; +} + /* vax */ +#else +int +ncx_getn_double_double(const void **xpp, size_t nelems, double *tp) +{ + const char *xp = *xpp; + int status = NC_NOERR; + + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) + { + const int lstatus = ncx_get_double_double(xp, tp, fillp); + if (status == NC_NOERR) /* report the first encountered error */ + status = lstatus; + } + + *xpp = (const void *)xp; + return status; +} +#endif +int +#line 3554 +ncx_getn_double_schar(const void **xpp, size_t nelems, schar *tp) +#line 3554 +{ +#line 3554 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3554 + +#line 3554 + /* basic algorithm is: +#line 3554 + * - ensure sane alignment of input data +#line 3554 + * - copy (conversion happens automatically) input data +#line 3554 + * to output +#line 3554 + * - update xpp to point at next unconverted input, and tp to point +#line 3554 + * at next location for converted output +#line 3554 + */ +#line 3554 + long i, j, ni; +#line 3554 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3554 + double *xp; +#line 3554 + int nrange = 0; /* number of range errors */ +#line 3554 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3554 + long cxp = (long) *((char**)xpp); +#line 3554 + +#line 3554 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3554 + /* sjl: manually stripmine so we can limit amount of +#line 3554 + * vector work space reserved to LOOPCNT elements. Also +#line 3554 + * makes vectorisation easy */ +#line 3554 + for (j=0; j= 0 */ +#line 3554 + nrange += xp[i] > SCHAR_MAX || xp[i] < SCHAR_MIN; +#line 3554 + } +#line 3554 + /* update xpp and tp */ +#line 3554 + if (realign) xp = (double *) *xpp; +#line 3554 + xp += ni; +#line 3554 + tp += ni; +#line 3554 + *xpp = (void*)xp; +#line 3554 + } +#line 3554 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3554 + +#line 3554 +#else /* not SX */ +#line 3554 + const char *xp = (const char *) *xpp; +#line 3554 + int status = NC_NOERR; +#line 3554 + +#line 3554 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3554 + { +#line 3554 + const int lstatus = ncx_get_double_schar(xp, tp); +#line 3554 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3554 + status = lstatus; +#line 3554 + } +#line 3554 + +#line 3554 + *xpp = (const void *)xp; +#line 3554 + return status; +#line 3554 +#endif +#line 3554 +} +#line 3554 + +int +#line 3555 +ncx_getn_double_short(const void **xpp, size_t nelems, short *tp) +#line 3555 +{ +#line 3555 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3555 + +#line 3555 + /* basic algorithm is: +#line 3555 + * - ensure sane alignment of input data +#line 3555 + * - copy (conversion happens automatically) input data +#line 3555 + * to output +#line 3555 + * - update xpp to point at next unconverted input, and tp to point +#line 3555 + * at next location for converted output +#line 3555 + */ +#line 3555 + long i, j, ni; +#line 3555 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3555 + double *xp; +#line 3555 + int nrange = 0; /* number of range errors */ +#line 3555 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3555 + long cxp = (long) *((char**)xpp); +#line 3555 + +#line 3555 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3555 + /* sjl: manually stripmine so we can limit amount of +#line 3555 + * vector work space reserved to LOOPCNT elements. Also +#line 3555 + * makes vectorisation easy */ +#line 3555 + for (j=0; j= 0 */ +#line 3555 + nrange += xp[i] > SHORT_MAX || xp[i] < SHORT_MIN; +#line 3555 + } +#line 3555 + /* update xpp and tp */ +#line 3555 + if (realign) xp = (double *) *xpp; +#line 3555 + xp += ni; +#line 3555 + tp += ni; +#line 3555 + *xpp = (void*)xp; +#line 3555 + } +#line 3555 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3555 + +#line 3555 +#else /* not SX */ +#line 3555 + const char *xp = (const char *) *xpp; +#line 3555 + int status = NC_NOERR; +#line 3555 + +#line 3555 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3555 + { +#line 3555 + const int lstatus = ncx_get_double_short(xp, tp); +#line 3555 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3555 + status = lstatus; +#line 3555 + } +#line 3555 + +#line 3555 + *xpp = (const void *)xp; +#line 3555 + return status; +#line 3555 +#endif +#line 3555 +} +#line 3555 + +int +#line 3556 +ncx_getn_double_int(const void **xpp, size_t nelems, int *tp) +#line 3556 +{ +#line 3556 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3556 + +#line 3556 + /* basic algorithm is: +#line 3556 + * - ensure sane alignment of input data +#line 3556 + * - copy (conversion happens automatically) input data +#line 3556 + * to output +#line 3556 + * - update xpp to point at next unconverted input, and tp to point +#line 3556 + * at next location for converted output +#line 3556 + */ +#line 3556 + long i, j, ni; +#line 3556 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3556 + double *xp; +#line 3556 + int nrange = 0; /* number of range errors */ +#line 3556 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3556 + long cxp = (long) *((char**)xpp); +#line 3556 + +#line 3556 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3556 + /* sjl: manually stripmine so we can limit amount of +#line 3556 + * vector work space reserved to LOOPCNT elements. Also +#line 3556 + * makes vectorisation easy */ +#line 3556 + for (j=0; j= 0 */ +#line 3556 + nrange += xp[i] > INT_MAX || xp[i] < INT_MIN; +#line 3556 + } +#line 3556 + /* update xpp and tp */ +#line 3556 + if (realign) xp = (double *) *xpp; +#line 3556 + xp += ni; +#line 3556 + tp += ni; +#line 3556 + *xpp = (void*)xp; +#line 3556 + } +#line 3556 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3556 + +#line 3556 +#else /* not SX */ +#line 3556 + const char *xp = (const char *) *xpp; +#line 3556 + int status = NC_NOERR; +#line 3556 + +#line 3556 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3556 + { +#line 3556 + const int lstatus = ncx_get_double_int(xp, tp); +#line 3556 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3556 + status = lstatus; +#line 3556 + } +#line 3556 + +#line 3556 + *xpp = (const void *)xp; +#line 3556 + return status; +#line 3556 +#endif +#line 3556 +} +#line 3556 + +int +#line 3557 +ncx_getn_double_long(const void **xpp, size_t nelems, long *tp) +#line 3557 +{ +#line 3557 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3557 + +#line 3557 + /* basic algorithm is: +#line 3557 + * - ensure sane alignment of input data +#line 3557 + * - copy (conversion happens automatically) input data +#line 3557 + * to output +#line 3557 + * - update xpp to point at next unconverted input, and tp to point +#line 3557 + * at next location for converted output +#line 3557 + */ +#line 3557 + long i, j, ni; +#line 3557 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3557 + double *xp; +#line 3557 + int nrange = 0; /* number of range errors */ +#line 3557 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3557 + long cxp = (long) *((char**)xpp); +#line 3557 + +#line 3557 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3557 + /* sjl: manually stripmine so we can limit amount of +#line 3557 + * vector work space reserved to LOOPCNT elements. Also +#line 3557 + * makes vectorisation easy */ +#line 3557 + for (j=0; j= 0 */ +#line 3557 + nrange += xp[i] > LONG_MAX || xp[i] < LONG_MIN; +#line 3557 + } +#line 3557 + /* update xpp and tp */ +#line 3557 + if (realign) xp = (double *) *xpp; +#line 3557 + xp += ni; +#line 3557 + tp += ni; +#line 3557 + *xpp = (void*)xp; +#line 3557 + } +#line 3557 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3557 + +#line 3557 +#else /* not SX */ +#line 3557 + const char *xp = (const char *) *xpp; +#line 3557 + int status = NC_NOERR; +#line 3557 + +#line 3557 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3557 + { +#line 3557 + const int lstatus = ncx_get_double_long(xp, tp); +#line 3557 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3557 + status = lstatus; +#line 3557 + } +#line 3557 + +#line 3557 + *xpp = (const void *)xp; +#line 3557 + return status; +#line 3557 +#endif +#line 3557 +} +#line 3557 + +int +#line 3558 +ncx_getn_double_float(const void **xpp, size_t nelems, float *tp) +#line 3558 +{ +#line 3558 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3558 + +#line 3558 + /* basic algorithm is: +#line 3558 + * - ensure sane alignment of input data +#line 3558 + * - copy (conversion happens automatically) input data +#line 3558 + * to output +#line 3558 + * - update xpp to point at next unconverted input, and tp to point +#line 3558 + * at next location for converted output +#line 3558 + */ +#line 3558 + long i, j, ni; +#line 3558 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3558 + double *xp; +#line 3558 + int nrange = 0; /* number of range errors */ +#line 3558 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3558 + long cxp = (long) *((char**)xpp); +#line 3558 + +#line 3558 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3558 + /* sjl: manually stripmine so we can limit amount of +#line 3558 + * vector work space reserved to LOOPCNT elements. Also +#line 3558 + * makes vectorisation easy */ +#line 3558 + for (j=0; j= 0 */ +#line 3558 + nrange += xp[i] > FLOAT_MAX || xp[i] < FLOAT_MIN; +#line 3558 + } +#line 3558 + /* update xpp and tp */ +#line 3558 + if (realign) xp = (double *) *xpp; +#line 3558 + xp += ni; +#line 3558 + tp += ni; +#line 3558 + *xpp = (void*)xp; +#line 3558 + } +#line 3558 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3558 + +#line 3558 +#else /* not SX */ +#line 3558 + const char *xp = (const char *) *xpp; +#line 3558 + int status = NC_NOERR; +#line 3558 + +#line 3558 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3558 + { +#line 3558 + const int lstatus = ncx_get_double_float(xp, tp); +#line 3558 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3558 + status = lstatus; +#line 3558 + } +#line 3558 + +#line 3558 + *xpp = (const void *)xp; +#line 3558 + return status; +#line 3558 +#endif +#line 3558 +} +#line 3558 + +int +#line 3559 +ncx_getn_double_longlong(const void **xpp, size_t nelems, longlong *tp) +#line 3559 +{ +#line 3559 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3559 + +#line 3559 + /* basic algorithm is: +#line 3559 + * - ensure sane alignment of input data +#line 3559 + * - copy (conversion happens automatically) input data +#line 3559 + * to output +#line 3559 + * - update xpp to point at next unconverted input, and tp to point +#line 3559 + * at next location for converted output +#line 3559 + */ +#line 3559 + long i, j, ni; +#line 3559 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3559 + double *xp; +#line 3559 + int nrange = 0; /* number of range errors */ +#line 3559 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3559 + long cxp = (long) *((char**)xpp); +#line 3559 + +#line 3559 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3559 + /* sjl: manually stripmine so we can limit amount of +#line 3559 + * vector work space reserved to LOOPCNT elements. Also +#line 3559 + * makes vectorisation easy */ +#line 3559 + for (j=0; j= 0 */ +#line 3559 + nrange += xp[i] > LONGLONG_MAX || xp[i] < LONGLONG_MIN; +#line 3559 + } +#line 3559 + /* update xpp and tp */ +#line 3559 + if (realign) xp = (double *) *xpp; +#line 3559 + xp += ni; +#line 3559 + tp += ni; +#line 3559 + *xpp = (void*)xp; +#line 3559 + } +#line 3559 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3559 + +#line 3559 +#else /* not SX */ +#line 3559 + const char *xp = (const char *) *xpp; +#line 3559 + int status = NC_NOERR; +#line 3559 + +#line 3559 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3559 + { +#line 3559 + const int lstatus = ncx_get_double_longlong(xp, tp); +#line 3559 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3559 + status = lstatus; +#line 3559 + } +#line 3559 + +#line 3559 + *xpp = (const void *)xp; +#line 3559 + return status; +#line 3559 +#endif +#line 3559 +} +#line 3559 + +int +#line 3560 +ncx_getn_double_uchar(const void **xpp, size_t nelems, uchar *tp) +#line 3560 +{ +#line 3560 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3560 + +#line 3560 + /* basic algorithm is: +#line 3560 + * - ensure sane alignment of input data +#line 3560 + * - copy (conversion happens automatically) input data +#line 3560 + * to output +#line 3560 + * - update xpp to point at next unconverted input, and tp to point +#line 3560 + * at next location for converted output +#line 3560 + */ +#line 3560 + long i, j, ni; +#line 3560 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3560 + double *xp; +#line 3560 + int nrange = 0; /* number of range errors */ +#line 3560 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3560 + long cxp = (long) *((char**)xpp); +#line 3560 + +#line 3560 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3560 + /* sjl: manually stripmine so we can limit amount of +#line 3560 + * vector work space reserved to LOOPCNT elements. Also +#line 3560 + * makes vectorisation easy */ +#line 3560 + for (j=0; j= 0 */ +#line 3560 + nrange += xp[i] > UCHAR_MAX || xp[i] < 0; +#line 3560 + } +#line 3560 + /* update xpp and tp */ +#line 3560 + if (realign) xp = (double *) *xpp; +#line 3560 + xp += ni; +#line 3560 + tp += ni; +#line 3560 + *xpp = (void*)xp; +#line 3560 + } +#line 3560 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3560 + +#line 3560 +#else /* not SX */ +#line 3560 + const char *xp = (const char *) *xpp; +#line 3560 + int status = NC_NOERR; +#line 3560 + +#line 3560 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3560 + { +#line 3560 + const int lstatus = ncx_get_double_uchar(xp, tp); +#line 3560 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3560 + status = lstatus; +#line 3560 + } +#line 3560 + +#line 3560 + *xpp = (const void *)xp; +#line 3560 + return status; +#line 3560 +#endif +#line 3560 +} +#line 3560 + +int +#line 3561 +ncx_getn_double_ushort(const void **xpp, size_t nelems, ushort *tp) +#line 3561 +{ +#line 3561 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3561 + +#line 3561 + /* basic algorithm is: +#line 3561 + * - ensure sane alignment of input data +#line 3561 + * - copy (conversion happens automatically) input data +#line 3561 + * to output +#line 3561 + * - update xpp to point at next unconverted input, and tp to point +#line 3561 + * at next location for converted output +#line 3561 + */ +#line 3561 + long i, j, ni; +#line 3561 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3561 + double *xp; +#line 3561 + int nrange = 0; /* number of range errors */ +#line 3561 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3561 + long cxp = (long) *((char**)xpp); +#line 3561 + +#line 3561 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3561 + /* sjl: manually stripmine so we can limit amount of +#line 3561 + * vector work space reserved to LOOPCNT elements. Also +#line 3561 + * makes vectorisation easy */ +#line 3561 + for (j=0; j= 0 */ +#line 3561 + nrange += xp[i] > USHORT_MAX || xp[i] < 0; +#line 3561 + } +#line 3561 + /* update xpp and tp */ +#line 3561 + if (realign) xp = (double *) *xpp; +#line 3561 + xp += ni; +#line 3561 + tp += ni; +#line 3561 + *xpp = (void*)xp; +#line 3561 + } +#line 3561 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3561 + +#line 3561 +#else /* not SX */ +#line 3561 + const char *xp = (const char *) *xpp; +#line 3561 + int status = NC_NOERR; +#line 3561 + +#line 3561 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3561 + { +#line 3561 + const int lstatus = ncx_get_double_ushort(xp, tp); +#line 3561 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3561 + status = lstatus; +#line 3561 + } +#line 3561 + +#line 3561 + *xpp = (const void *)xp; +#line 3561 + return status; +#line 3561 +#endif +#line 3561 +} +#line 3561 + +int +#line 3562 +ncx_getn_double_uint(const void **xpp, size_t nelems, uint *tp) +#line 3562 +{ +#line 3562 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3562 + +#line 3562 + /* basic algorithm is: +#line 3562 + * - ensure sane alignment of input data +#line 3562 + * - copy (conversion happens automatically) input data +#line 3562 + * to output +#line 3562 + * - update xpp to point at next unconverted input, and tp to point +#line 3562 + * at next location for converted output +#line 3562 + */ +#line 3562 + long i, j, ni; +#line 3562 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3562 + double *xp; +#line 3562 + int nrange = 0; /* number of range errors */ +#line 3562 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3562 + long cxp = (long) *((char**)xpp); +#line 3562 + +#line 3562 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3562 + /* sjl: manually stripmine so we can limit amount of +#line 3562 + * vector work space reserved to LOOPCNT elements. Also +#line 3562 + * makes vectorisation easy */ +#line 3562 + for (j=0; j= 0 */ +#line 3562 + nrange += xp[i] > UINT_MAX || xp[i] < 0; +#line 3562 + } +#line 3562 + /* update xpp and tp */ +#line 3562 + if (realign) xp = (double *) *xpp; +#line 3562 + xp += ni; +#line 3562 + tp += ni; +#line 3562 + *xpp = (void*)xp; +#line 3562 + } +#line 3562 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3562 + +#line 3562 +#else /* not SX */ +#line 3562 + const char *xp = (const char *) *xpp; +#line 3562 + int status = NC_NOERR; +#line 3562 + +#line 3562 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3562 + { +#line 3562 + const int lstatus = ncx_get_double_uint(xp, tp); +#line 3562 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3562 + status = lstatus; +#line 3562 + } +#line 3562 + +#line 3562 + *xpp = (const void *)xp; +#line 3562 + return status; +#line 3562 +#endif +#line 3562 +} +#line 3562 + +int +#line 3563 +ncx_getn_double_ulonglong(const void **xpp, size_t nelems, ulonglong *tp) +#line 3563 +{ +#line 3563 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3563 + +#line 3563 + /* basic algorithm is: +#line 3563 + * - ensure sane alignment of input data +#line 3563 + * - copy (conversion happens automatically) input data +#line 3563 + * to output +#line 3563 + * - update xpp to point at next unconverted input, and tp to point +#line 3563 + * at next location for converted output +#line 3563 + */ +#line 3563 + long i, j, ni; +#line 3563 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3563 + double *xp; +#line 3563 + int nrange = 0; /* number of range errors */ +#line 3563 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3563 + long cxp = (long) *((char**)xpp); +#line 3563 + +#line 3563 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3563 + /* sjl: manually stripmine so we can limit amount of +#line 3563 + * vector work space reserved to LOOPCNT elements. Also +#line 3563 + * makes vectorisation easy */ +#line 3563 + for (j=0; j= 0 */ +#line 3563 + nrange += xp[i] > ULONGLONG_MAX || xp[i] < 0; +#line 3563 + } +#line 3563 + /* update xpp and tp */ +#line 3563 + if (realign) xp = (double *) *xpp; +#line 3563 + xp += ni; +#line 3563 + tp += ni; +#line 3563 + *xpp = (void*)xp; +#line 3563 + } +#line 3563 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3563 + +#line 3563 +#else /* not SX */ +#line 3563 + const char *xp = (const char *) *xpp; +#line 3563 + int status = NC_NOERR; +#line 3563 + +#line 3563 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3563 + { +#line 3563 + const int lstatus = ncx_get_double_ulonglong(xp, tp); +#line 3563 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3563 + status = lstatus; +#line 3563 + } +#line 3563 + +#line 3563 + *xpp = (const void *)xp; +#line 3563 + return status; +#line 3563 +#endif +#line 3563 +} +#line 3563 + + +#if X_SIZEOF_DOUBLE == SIZEOF_DOUBLE && !defined(NO_IEEE_FLOAT) +/* optimized version */ +int +ncx_putn_double_double(void **xpp, size_t nelems, const double *tp, void *fillp) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(*xpp, tp, (size_t)nelems * X_SIZEOF_DOUBLE); +# else + swapn8b(*xpp, tp, nelems); +# endif + *xpp = (void *)((char *)(*xpp) + nelems * X_SIZEOF_DOUBLE); + return NC_NOERR; +} +#elif defined(vax) && vax != 0 +int +ncx_putn_double_double(void **xpp, size_t ndoubles, const double *ip, void *fillp) +{ + const double *const end = ip + ndoubles; + + while (ip < end) + { + const struct vax_double *const vdp = +#line 3586 + (const struct vax_double *)ip; +#line 3586 + struct ieee_double *const idp = +#line 3586 + (struct ieee_double *) (*xpp); +#line 3586 + +#line 3586 + if ((vdp->mantissa4 > (dbl_limits[0].d.mantissa4 - 3)) && +#line 3586 + (vdp->mantissa3 == dbl_limits[0].d.mantissa3) && +#line 3586 + (vdp->mantissa2 == dbl_limits[0].d.mantissa2) && +#line 3586 + (vdp->mantissa1 == dbl_limits[0].d.mantissa1) && +#line 3586 + (vdp->exp == dbl_limits[0].d.exp)) +#line 3586 + { +#line 3586 + *idp = dbl_limits[0].ieee; +#line 3586 + goto shipit; +#line 3586 + } +#line 3586 + if ((vdp->mantissa4 == dbl_limits[1].d.mantissa4) && +#line 3586 + (vdp->mantissa3 == dbl_limits[1].d.mantissa3) && +#line 3586 + (vdp->mantissa2 == dbl_limits[1].d.mantissa2) && +#line 3586 + (vdp->mantissa1 == dbl_limits[1].d.mantissa1) && +#line 3586 + (vdp->exp == dbl_limits[1].d.exp)) +#line 3586 + { +#line 3586 + *idp = dbl_limits[1].ieee; +#line 3586 + goto shipit; +#line 3586 + } +#line 3586 + +#line 3586 + { +#line 3586 + unsigned exp = vdp->exp - VAX_DBL_BIAS + IEEE_DBL_BIAS; +#line 3586 + +#line 3586 + unsigned mant_lo = ((vdp->mantissa2 & MASK(3)) << 29) | +#line 3586 + (vdp->mantissa3 << 13) | +#line 3586 + ((vdp->mantissa4 >> 3) & MASK(13)); +#line 3586 + +#line 3586 + unsigned mant_hi = (vdp->mantissa1 << 13) +#line 3586 + | (vdp->mantissa2 >> 3); +#line 3586 + +#line 3586 + if ((vdp->mantissa4 & 7) > 4) +#line 3586 + { +#line 3586 + /* round up */ +#line 3586 + mant_lo++; +#line 3586 + if (mant_lo == 0) +#line 3586 + { +#line 3586 + mant_hi++; +#line 3586 + if (mant_hi > 0xffffff) +#line 3586 + { +#line 3586 + mant_hi = 0; +#line 3586 + exp++; +#line 3586 + } +#line 3586 + } +#line 3586 + } +#line 3586 + +#line 3586 + idp->mant_lo = SWAP4(mant_lo); +#line 3586 + idp->mant_6 = mant_hi >> 16; +#line 3586 + idp->mant_5 = (mant_hi & 0xff00) >> 8; +#line 3586 + idp->mant_4 = mant_hi; +#line 3586 + idp->exp_hi = exp >> 4; +#line 3586 + idp->exp_lo = exp; +#line 3586 + } +#line 3586 + +#line 3586 + shipit: +#line 3586 + idp->sign = vdp->sign; +#line 3586 + + ip++; + *xpp = (char *)(*xpp) + X_SIZEOF_DOUBLE; + } + return NC_NOERR; +} + /* vax */ +#else +int +ncx_putn_double_double(void **xpp, size_t nelems, const double *tp, void *fillp) +{ + char *xp = *xpp; + int status = NC_NOERR; + + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) + { + int lstatus = ncx_put_double_double(xp, tp, fillp); + if (status == NC_NOERR) /* report the first encountered error */ + status = lstatus; + } + + *xpp = (void *)xp; + return status; +} +#endif +int +#line 3611 +ncx_putn_double_schar(void **xpp, size_t nelems, const schar *tp, void *fillp) +#line 3611 +{ +#line 3611 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3611 + +#line 3611 + /* basic algorithm is: +#line 3611 + * - ensure sane alignment of output data +#line 3611 + * - copy (conversion happens automatically) input data +#line 3611 + * to output +#line 3611 + * - update tp to point at next unconverted input, and xpp to point +#line 3611 + * at next location for converted output +#line 3611 + */ +#line 3611 + long i, j, ni; +#line 3611 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3611 + double *xp; +#line 3611 + int nrange = 0; /* number of range errors */ +#line 3611 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3611 + long cxp = (long) *((char**)xpp); +#line 3611 + +#line 3611 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3611 + /* sjl: manually stripmine so we can limit amount of +#line 3611 + * vector work space reserved to LOOPCNT elements. Also +#line 3611 + * makes vectorisation easy */ +#line 3611 + for (j=0; j= 0 */ +#line 3611 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3611 + nrange += tp[i] > X_DOUBLE_MAX || tp[i] < X_DOUBLE_MIN; +#line 3611 + } +#line 3611 + /* copy workspace back if necessary */ +#line 3611 + if (realign) { +#line 3611 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_DOUBLE); +#line 3611 + xp = (double *) *xpp; +#line 3611 + } +#line 3611 + /* update xpp and tp */ +#line 3611 + xp += ni; +#line 3611 + tp += ni; +#line 3611 + *xpp = (void*)xp; +#line 3611 + } +#line 3611 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3611 + +#line 3611 +#else /* not SX */ +#line 3611 + +#line 3611 + char *xp = (char *) *xpp; +#line 3611 + int status = NC_NOERR; +#line 3611 + +#line 3611 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3611 + { +#line 3611 + int lstatus = ncx_put_double_schar(xp, tp, fillp); +#line 3611 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3611 + status = lstatus; +#line 3611 + } +#line 3611 + +#line 3611 + *xpp = (void *)xp; +#line 3611 + return status; +#line 3611 +#endif +#line 3611 +} +#line 3611 + +int +#line 3612 +ncx_putn_double_short(void **xpp, size_t nelems, const short *tp, void *fillp) +#line 3612 +{ +#line 3612 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3612 + +#line 3612 + /* basic algorithm is: +#line 3612 + * - ensure sane alignment of output data +#line 3612 + * - copy (conversion happens automatically) input data +#line 3612 + * to output +#line 3612 + * - update tp to point at next unconverted input, and xpp to point +#line 3612 + * at next location for converted output +#line 3612 + */ +#line 3612 + long i, j, ni; +#line 3612 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3612 + double *xp; +#line 3612 + int nrange = 0; /* number of range errors */ +#line 3612 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3612 + long cxp = (long) *((char**)xpp); +#line 3612 + +#line 3612 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3612 + /* sjl: manually stripmine so we can limit amount of +#line 3612 + * vector work space reserved to LOOPCNT elements. Also +#line 3612 + * makes vectorisation easy */ +#line 3612 + for (j=0; j= 0 */ +#line 3612 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3612 + nrange += tp[i] > X_DOUBLE_MAX || tp[i] < X_DOUBLE_MIN; +#line 3612 + } +#line 3612 + /* copy workspace back if necessary */ +#line 3612 + if (realign) { +#line 3612 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_DOUBLE); +#line 3612 + xp = (double *) *xpp; +#line 3612 + } +#line 3612 + /* update xpp and tp */ +#line 3612 + xp += ni; +#line 3612 + tp += ni; +#line 3612 + *xpp = (void*)xp; +#line 3612 + } +#line 3612 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3612 + +#line 3612 +#else /* not SX */ +#line 3612 + +#line 3612 + char *xp = (char *) *xpp; +#line 3612 + int status = NC_NOERR; +#line 3612 + +#line 3612 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3612 + { +#line 3612 + int lstatus = ncx_put_double_short(xp, tp, fillp); +#line 3612 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3612 + status = lstatus; +#line 3612 + } +#line 3612 + +#line 3612 + *xpp = (void *)xp; +#line 3612 + return status; +#line 3612 +#endif +#line 3612 +} +#line 3612 + +int +#line 3613 +ncx_putn_double_int(void **xpp, size_t nelems, const int *tp, void *fillp) +#line 3613 +{ +#line 3613 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3613 + +#line 3613 + /* basic algorithm is: +#line 3613 + * - ensure sane alignment of output data +#line 3613 + * - copy (conversion happens automatically) input data +#line 3613 + * to output +#line 3613 + * - update tp to point at next unconverted input, and xpp to point +#line 3613 + * at next location for converted output +#line 3613 + */ +#line 3613 + long i, j, ni; +#line 3613 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3613 + double *xp; +#line 3613 + int nrange = 0; /* number of range errors */ +#line 3613 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3613 + long cxp = (long) *((char**)xpp); +#line 3613 + +#line 3613 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3613 + /* sjl: manually stripmine so we can limit amount of +#line 3613 + * vector work space reserved to LOOPCNT elements. Also +#line 3613 + * makes vectorisation easy */ +#line 3613 + for (j=0; j= 0 */ +#line 3613 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3613 + nrange += tp[i] > X_DOUBLE_MAX || tp[i] < X_DOUBLE_MIN; +#line 3613 + } +#line 3613 + /* copy workspace back if necessary */ +#line 3613 + if (realign) { +#line 3613 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_DOUBLE); +#line 3613 + xp = (double *) *xpp; +#line 3613 + } +#line 3613 + /* update xpp and tp */ +#line 3613 + xp += ni; +#line 3613 + tp += ni; +#line 3613 + *xpp = (void*)xp; +#line 3613 + } +#line 3613 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3613 + +#line 3613 +#else /* not SX */ +#line 3613 + +#line 3613 + char *xp = (char *) *xpp; +#line 3613 + int status = NC_NOERR; +#line 3613 + +#line 3613 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3613 + { +#line 3613 + int lstatus = ncx_put_double_int(xp, tp, fillp); +#line 3613 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3613 + status = lstatus; +#line 3613 + } +#line 3613 + +#line 3613 + *xpp = (void *)xp; +#line 3613 + return status; +#line 3613 +#endif +#line 3613 +} +#line 3613 + +int +#line 3614 +ncx_putn_double_long(void **xpp, size_t nelems, const long *tp, void *fillp) +#line 3614 +{ +#line 3614 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3614 + +#line 3614 + /* basic algorithm is: +#line 3614 + * - ensure sane alignment of output data +#line 3614 + * - copy (conversion happens automatically) input data +#line 3614 + * to output +#line 3614 + * - update tp to point at next unconverted input, and xpp to point +#line 3614 + * at next location for converted output +#line 3614 + */ +#line 3614 + long i, j, ni; +#line 3614 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3614 + double *xp; +#line 3614 + int nrange = 0; /* number of range errors */ +#line 3614 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3614 + long cxp = (long) *((char**)xpp); +#line 3614 + +#line 3614 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3614 + /* sjl: manually stripmine so we can limit amount of +#line 3614 + * vector work space reserved to LOOPCNT elements. Also +#line 3614 + * makes vectorisation easy */ +#line 3614 + for (j=0; j= 0 */ +#line 3614 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3614 + nrange += tp[i] > X_DOUBLE_MAX || tp[i] < X_DOUBLE_MIN; +#line 3614 + } +#line 3614 + /* copy workspace back if necessary */ +#line 3614 + if (realign) { +#line 3614 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_DOUBLE); +#line 3614 + xp = (double *) *xpp; +#line 3614 + } +#line 3614 + /* update xpp and tp */ +#line 3614 + xp += ni; +#line 3614 + tp += ni; +#line 3614 + *xpp = (void*)xp; +#line 3614 + } +#line 3614 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3614 + +#line 3614 +#else /* not SX */ +#line 3614 + +#line 3614 + char *xp = (char *) *xpp; +#line 3614 + int status = NC_NOERR; +#line 3614 + +#line 3614 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3614 + { +#line 3614 + int lstatus = ncx_put_double_long(xp, tp, fillp); +#line 3614 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3614 + status = lstatus; +#line 3614 + } +#line 3614 + +#line 3614 + *xpp = (void *)xp; +#line 3614 + return status; +#line 3614 +#endif +#line 3614 +} +#line 3614 + +int +#line 3615 +ncx_putn_double_float(void **xpp, size_t nelems, const float *tp, void *fillp) +#line 3615 +{ +#line 3615 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3615 + +#line 3615 + /* basic algorithm is: +#line 3615 + * - ensure sane alignment of output data +#line 3615 + * - copy (conversion happens automatically) input data +#line 3615 + * to output +#line 3615 + * - update tp to point at next unconverted input, and xpp to point +#line 3615 + * at next location for converted output +#line 3615 + */ +#line 3615 + long i, j, ni; +#line 3615 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3615 + double *xp; +#line 3615 + int nrange = 0; /* number of range errors */ +#line 3615 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3615 + long cxp = (long) *((char**)xpp); +#line 3615 + +#line 3615 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3615 + /* sjl: manually stripmine so we can limit amount of +#line 3615 + * vector work space reserved to LOOPCNT elements. Also +#line 3615 + * makes vectorisation easy */ +#line 3615 + for (j=0; j= 0 */ +#line 3615 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3615 + nrange += tp[i] > X_DOUBLE_MAX || tp[i] < X_DOUBLE_MIN; +#line 3615 + } +#line 3615 + /* copy workspace back if necessary */ +#line 3615 + if (realign) { +#line 3615 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_DOUBLE); +#line 3615 + xp = (double *) *xpp; +#line 3615 + } +#line 3615 + /* update xpp and tp */ +#line 3615 + xp += ni; +#line 3615 + tp += ni; +#line 3615 + *xpp = (void*)xp; +#line 3615 + } +#line 3615 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3615 + +#line 3615 +#else /* not SX */ +#line 3615 + +#line 3615 + char *xp = (char *) *xpp; +#line 3615 + int status = NC_NOERR; +#line 3615 + +#line 3615 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3615 + { +#line 3615 + int lstatus = ncx_put_double_float(xp, tp, fillp); +#line 3615 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3615 + status = lstatus; +#line 3615 + } +#line 3615 + +#line 3615 + *xpp = (void *)xp; +#line 3615 + return status; +#line 3615 +#endif +#line 3615 +} +#line 3615 + +int +#line 3616 +ncx_putn_double_longlong(void **xpp, size_t nelems, const longlong *tp, void *fillp) +#line 3616 +{ +#line 3616 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3616 + +#line 3616 + /* basic algorithm is: +#line 3616 + * - ensure sane alignment of output data +#line 3616 + * - copy (conversion happens automatically) input data +#line 3616 + * to output +#line 3616 + * - update tp to point at next unconverted input, and xpp to point +#line 3616 + * at next location for converted output +#line 3616 + */ +#line 3616 + long i, j, ni; +#line 3616 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3616 + double *xp; +#line 3616 + int nrange = 0; /* number of range errors */ +#line 3616 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3616 + long cxp = (long) *((char**)xpp); +#line 3616 + +#line 3616 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3616 + /* sjl: manually stripmine so we can limit amount of +#line 3616 + * vector work space reserved to LOOPCNT elements. Also +#line 3616 + * makes vectorisation easy */ +#line 3616 + for (j=0; j= 0 */ +#line 3616 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3616 + nrange += tp[i] > X_DOUBLE_MAX || tp[i] < X_DOUBLE_MIN; +#line 3616 + } +#line 3616 + /* copy workspace back if necessary */ +#line 3616 + if (realign) { +#line 3616 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_DOUBLE); +#line 3616 + xp = (double *) *xpp; +#line 3616 + } +#line 3616 + /* update xpp and tp */ +#line 3616 + xp += ni; +#line 3616 + tp += ni; +#line 3616 + *xpp = (void*)xp; +#line 3616 + } +#line 3616 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3616 + +#line 3616 +#else /* not SX */ +#line 3616 + +#line 3616 + char *xp = (char *) *xpp; +#line 3616 + int status = NC_NOERR; +#line 3616 + +#line 3616 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3616 + { +#line 3616 + int lstatus = ncx_put_double_longlong(xp, tp, fillp); +#line 3616 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3616 + status = lstatus; +#line 3616 + } +#line 3616 + +#line 3616 + *xpp = (void *)xp; +#line 3616 + return status; +#line 3616 +#endif +#line 3616 +} +#line 3616 + +int +#line 3617 +ncx_putn_double_uchar(void **xpp, size_t nelems, const uchar *tp, void *fillp) +#line 3617 +{ +#line 3617 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3617 + +#line 3617 + /* basic algorithm is: +#line 3617 + * - ensure sane alignment of output data +#line 3617 + * - copy (conversion happens automatically) input data +#line 3617 + * to output +#line 3617 + * - update tp to point at next unconverted input, and xpp to point +#line 3617 + * at next location for converted output +#line 3617 + */ +#line 3617 + long i, j, ni; +#line 3617 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3617 + double *xp; +#line 3617 + int nrange = 0; /* number of range errors */ +#line 3617 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3617 + long cxp = (long) *((char**)xpp); +#line 3617 + +#line 3617 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3617 + /* sjl: manually stripmine so we can limit amount of +#line 3617 + * vector work space reserved to LOOPCNT elements. Also +#line 3617 + * makes vectorisation easy */ +#line 3617 + for (j=0; j= 0 */ +#line 3617 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3617 + nrange += tp[i] > X_DOUBLE_MAX ; +#line 3617 + } +#line 3617 + /* copy workspace back if necessary */ +#line 3617 + if (realign) { +#line 3617 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_DOUBLE); +#line 3617 + xp = (double *) *xpp; +#line 3617 + } +#line 3617 + /* update xpp and tp */ +#line 3617 + xp += ni; +#line 3617 + tp += ni; +#line 3617 + *xpp = (void*)xp; +#line 3617 + } +#line 3617 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3617 + +#line 3617 +#else /* not SX */ +#line 3617 + +#line 3617 + char *xp = (char *) *xpp; +#line 3617 + int status = NC_NOERR; +#line 3617 + +#line 3617 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3617 + { +#line 3617 + int lstatus = ncx_put_double_uchar(xp, tp, fillp); +#line 3617 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3617 + status = lstatus; +#line 3617 + } +#line 3617 + +#line 3617 + *xpp = (void *)xp; +#line 3617 + return status; +#line 3617 +#endif +#line 3617 +} +#line 3617 + +int +#line 3618 +ncx_putn_double_ushort(void **xpp, size_t nelems, const ushort *tp, void *fillp) +#line 3618 +{ +#line 3618 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3618 + +#line 3618 + /* basic algorithm is: +#line 3618 + * - ensure sane alignment of output data +#line 3618 + * - copy (conversion happens automatically) input data +#line 3618 + * to output +#line 3618 + * - update tp to point at next unconverted input, and xpp to point +#line 3618 + * at next location for converted output +#line 3618 + */ +#line 3618 + long i, j, ni; +#line 3618 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3618 + double *xp; +#line 3618 + int nrange = 0; /* number of range errors */ +#line 3618 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3618 + long cxp = (long) *((char**)xpp); +#line 3618 + +#line 3618 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3618 + /* sjl: manually stripmine so we can limit amount of +#line 3618 + * vector work space reserved to LOOPCNT elements. Also +#line 3618 + * makes vectorisation easy */ +#line 3618 + for (j=0; j= 0 */ +#line 3618 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3618 + nrange += tp[i] > X_DOUBLE_MAX ; +#line 3618 + } +#line 3618 + /* copy workspace back if necessary */ +#line 3618 + if (realign) { +#line 3618 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_DOUBLE); +#line 3618 + xp = (double *) *xpp; +#line 3618 + } +#line 3618 + /* update xpp and tp */ +#line 3618 + xp += ni; +#line 3618 + tp += ni; +#line 3618 + *xpp = (void*)xp; +#line 3618 + } +#line 3618 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3618 + +#line 3618 +#else /* not SX */ +#line 3618 + +#line 3618 + char *xp = (char *) *xpp; +#line 3618 + int status = NC_NOERR; +#line 3618 + +#line 3618 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3618 + { +#line 3618 + int lstatus = ncx_put_double_ushort(xp, tp, fillp); +#line 3618 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3618 + status = lstatus; +#line 3618 + } +#line 3618 + +#line 3618 + *xpp = (void *)xp; +#line 3618 + return status; +#line 3618 +#endif +#line 3618 +} +#line 3618 + +int +#line 3619 +ncx_putn_double_uint(void **xpp, size_t nelems, const uint *tp, void *fillp) +#line 3619 +{ +#line 3619 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3619 + +#line 3619 + /* basic algorithm is: +#line 3619 + * - ensure sane alignment of output data +#line 3619 + * - copy (conversion happens automatically) input data +#line 3619 + * to output +#line 3619 + * - update tp to point at next unconverted input, and xpp to point +#line 3619 + * at next location for converted output +#line 3619 + */ +#line 3619 + long i, j, ni; +#line 3619 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3619 + double *xp; +#line 3619 + int nrange = 0; /* number of range errors */ +#line 3619 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3619 + long cxp = (long) *((char**)xpp); +#line 3619 + +#line 3619 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3619 + /* sjl: manually stripmine so we can limit amount of +#line 3619 + * vector work space reserved to LOOPCNT elements. Also +#line 3619 + * makes vectorisation easy */ +#line 3619 + for (j=0; j= 0 */ +#line 3619 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3619 + nrange += tp[i] > X_DOUBLE_MAX ; +#line 3619 + } +#line 3619 + /* copy workspace back if necessary */ +#line 3619 + if (realign) { +#line 3619 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_DOUBLE); +#line 3619 + xp = (double *) *xpp; +#line 3619 + } +#line 3619 + /* update xpp and tp */ +#line 3619 + xp += ni; +#line 3619 + tp += ni; +#line 3619 + *xpp = (void*)xp; +#line 3619 + } +#line 3619 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3619 + +#line 3619 +#else /* not SX */ +#line 3619 + +#line 3619 + char *xp = (char *) *xpp; +#line 3619 + int status = NC_NOERR; +#line 3619 + +#line 3619 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3619 + { +#line 3619 + int lstatus = ncx_put_double_uint(xp, tp, fillp); +#line 3619 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3619 + status = lstatus; +#line 3619 + } +#line 3619 + +#line 3619 + *xpp = (void *)xp; +#line 3619 + return status; +#line 3619 +#endif +#line 3619 +} +#line 3619 + +int +#line 3620 +ncx_putn_double_ulonglong(void **xpp, size_t nelems, const ulonglong *tp, void *fillp) +#line 3620 +{ +#line 3620 +#if defined(_SX) && _SX != 0 && X_SIZEOF_DOUBLE == SIZEOF_DOUBLE +#line 3620 + +#line 3620 + /* basic algorithm is: +#line 3620 + * - ensure sane alignment of output data +#line 3620 + * - copy (conversion happens automatically) input data +#line 3620 + * to output +#line 3620 + * - update tp to point at next unconverted input, and xpp to point +#line 3620 + * at next location for converted output +#line 3620 + */ +#line 3620 + long i, j, ni; +#line 3620 + double tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3620 + double *xp; +#line 3620 + int nrange = 0; /* number of range errors */ +#line 3620 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3620 + long cxp = (long) *((char**)xpp); +#line 3620 + +#line 3620 + realign = (cxp & 7) % SIZEOF_DOUBLE; +#line 3620 + /* sjl: manually stripmine so we can limit amount of +#line 3620 + * vector work space reserved to LOOPCNT elements. Also +#line 3620 + * makes vectorisation easy */ +#line 3620 + for (j=0; j= 0 */ +#line 3620 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3620 + nrange += tp[i] > X_DOUBLE_MAX ; +#line 3620 + } +#line 3620 + /* copy workspace back if necessary */ +#line 3620 + if (realign) { +#line 3620 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_DOUBLE); +#line 3620 + xp = (double *) *xpp; +#line 3620 + } +#line 3620 + /* update xpp and tp */ +#line 3620 + xp += ni; +#line 3620 + tp += ni; +#line 3620 + *xpp = (void*)xp; +#line 3620 + } +#line 3620 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3620 + +#line 3620 +#else /* not SX */ +#line 3620 + +#line 3620 + char *xp = (char *) *xpp; +#line 3620 + int status = NC_NOERR; +#line 3620 + +#line 3620 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) +#line 3620 + { +#line 3620 + int lstatus = ncx_put_double_ulonglong(xp, tp, fillp); +#line 3620 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3620 + status = lstatus; +#line 3620 + } +#line 3620 + +#line 3620 + *xpp = (void *)xp; +#line 3620 + return status; +#line 3620 +#endif +#line 3620 +} +#line 3620 + + + +/* longlong ------------------------------------------------------------------*/ + +#if X_SIZEOF_INT64 == SIZEOF_LONGLONG +/* optimized version */ +int +ncx_getn_longlong_longlong(const void **xpp, size_t nelems, long long *tp) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(tp, *xpp, (size_t)nelems * SIZEOF_LONG_LONG); +# else + swapn8b(tp, *xpp, nelems); +# endif + *xpp = (const void *)((const char *)(*xpp) + nelems * X_SIZEOF_INT64); + return NC_NOERR; +} +#else +int +#line 3639 +ncx_getn_longlong_longlong(const void **xpp, size_t nelems, longlong *tp) +#line 3639 +{ +#line 3639 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3639 + +#line 3639 + /* basic algorithm is: +#line 3639 + * - ensure sane alignment of input data +#line 3639 + * - copy (conversion happens automatically) input data +#line 3639 + * to output +#line 3639 + * - update xpp to point at next unconverted input, and tp to point +#line 3639 + * at next location for converted output +#line 3639 + */ +#line 3639 + long i, j, ni; +#line 3639 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3639 + int64 *xp; +#line 3639 + int nrange = 0; /* number of range errors */ +#line 3639 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3639 + long cxp = (long) *((char**)xpp); +#line 3639 + +#line 3639 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3639 + /* sjl: manually stripmine so we can limit amount of +#line 3639 + * vector work space reserved to LOOPCNT elements. Also +#line 3639 + * makes vectorisation easy */ +#line 3639 + for (j=0; j= 0 */ +#line 3639 + nrange += xp[i] > LONGLONG_MAX || xp[i] < LONGLONG_MIN; +#line 3639 + } +#line 3639 + /* update xpp and tp */ +#line 3639 + if (realign) xp = (int64 *) *xpp; +#line 3639 + xp += ni; +#line 3639 + tp += ni; +#line 3639 + *xpp = (void*)xp; +#line 3639 + } +#line 3639 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3639 + +#line 3639 +#else /* not SX */ +#line 3639 + const char *xp = (const char *) *xpp; +#line 3639 + int status = NC_NOERR; +#line 3639 + +#line 3639 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3639 + { +#line 3639 + const int lstatus = ncx_get_longlong_longlong(xp, tp); +#line 3639 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3639 + status = lstatus; +#line 3639 + } +#line 3639 + +#line 3639 + *xpp = (const void *)xp; +#line 3639 + return status; +#line 3639 +#endif +#line 3639 +} +#line 3639 + +#endif +int +#line 3641 +ncx_getn_longlong_schar(const void **xpp, size_t nelems, schar *tp) +#line 3641 +{ +#line 3641 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3641 + +#line 3641 + /* basic algorithm is: +#line 3641 + * - ensure sane alignment of input data +#line 3641 + * - copy (conversion happens automatically) input data +#line 3641 + * to output +#line 3641 + * - update xpp to point at next unconverted input, and tp to point +#line 3641 + * at next location for converted output +#line 3641 + */ +#line 3641 + long i, j, ni; +#line 3641 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3641 + int64 *xp; +#line 3641 + int nrange = 0; /* number of range errors */ +#line 3641 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3641 + long cxp = (long) *((char**)xpp); +#line 3641 + +#line 3641 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3641 + /* sjl: manually stripmine so we can limit amount of +#line 3641 + * vector work space reserved to LOOPCNT elements. Also +#line 3641 + * makes vectorisation easy */ +#line 3641 + for (j=0; j= 0 */ +#line 3641 + nrange += xp[i] > SCHAR_MAX || xp[i] < SCHAR_MIN; +#line 3641 + } +#line 3641 + /* update xpp and tp */ +#line 3641 + if (realign) xp = (int64 *) *xpp; +#line 3641 + xp += ni; +#line 3641 + tp += ni; +#line 3641 + *xpp = (void*)xp; +#line 3641 + } +#line 3641 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3641 + +#line 3641 +#else /* not SX */ +#line 3641 + const char *xp = (const char *) *xpp; +#line 3641 + int status = NC_NOERR; +#line 3641 + +#line 3641 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3641 + { +#line 3641 + const int lstatus = ncx_get_longlong_schar(xp, tp); +#line 3641 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3641 + status = lstatus; +#line 3641 + } +#line 3641 + +#line 3641 + *xpp = (const void *)xp; +#line 3641 + return status; +#line 3641 +#endif +#line 3641 +} +#line 3641 + +int +#line 3642 +ncx_getn_longlong_short(const void **xpp, size_t nelems, short *tp) +#line 3642 +{ +#line 3642 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3642 + +#line 3642 + /* basic algorithm is: +#line 3642 + * - ensure sane alignment of input data +#line 3642 + * - copy (conversion happens automatically) input data +#line 3642 + * to output +#line 3642 + * - update xpp to point at next unconverted input, and tp to point +#line 3642 + * at next location for converted output +#line 3642 + */ +#line 3642 + long i, j, ni; +#line 3642 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3642 + int64 *xp; +#line 3642 + int nrange = 0; /* number of range errors */ +#line 3642 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3642 + long cxp = (long) *((char**)xpp); +#line 3642 + +#line 3642 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3642 + /* sjl: manually stripmine so we can limit amount of +#line 3642 + * vector work space reserved to LOOPCNT elements. Also +#line 3642 + * makes vectorisation easy */ +#line 3642 + for (j=0; j= 0 */ +#line 3642 + nrange += xp[i] > SHORT_MAX || xp[i] < SHORT_MIN; +#line 3642 + } +#line 3642 + /* update xpp and tp */ +#line 3642 + if (realign) xp = (int64 *) *xpp; +#line 3642 + xp += ni; +#line 3642 + tp += ni; +#line 3642 + *xpp = (void*)xp; +#line 3642 + } +#line 3642 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3642 + +#line 3642 +#else /* not SX */ +#line 3642 + const char *xp = (const char *) *xpp; +#line 3642 + int status = NC_NOERR; +#line 3642 + +#line 3642 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3642 + { +#line 3642 + const int lstatus = ncx_get_longlong_short(xp, tp); +#line 3642 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3642 + status = lstatus; +#line 3642 + } +#line 3642 + +#line 3642 + *xpp = (const void *)xp; +#line 3642 + return status; +#line 3642 +#endif +#line 3642 +} +#line 3642 + +int +#line 3643 +ncx_getn_longlong_int(const void **xpp, size_t nelems, int *tp) +#line 3643 +{ +#line 3643 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3643 + +#line 3643 + /* basic algorithm is: +#line 3643 + * - ensure sane alignment of input data +#line 3643 + * - copy (conversion happens automatically) input data +#line 3643 + * to output +#line 3643 + * - update xpp to point at next unconverted input, and tp to point +#line 3643 + * at next location for converted output +#line 3643 + */ +#line 3643 + long i, j, ni; +#line 3643 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3643 + int64 *xp; +#line 3643 + int nrange = 0; /* number of range errors */ +#line 3643 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3643 + long cxp = (long) *((char**)xpp); +#line 3643 + +#line 3643 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3643 + /* sjl: manually stripmine so we can limit amount of +#line 3643 + * vector work space reserved to LOOPCNT elements. Also +#line 3643 + * makes vectorisation easy */ +#line 3643 + for (j=0; j= 0 */ +#line 3643 + nrange += xp[i] > INT_MAX || xp[i] < INT_MIN; +#line 3643 + } +#line 3643 + /* update xpp and tp */ +#line 3643 + if (realign) xp = (int64 *) *xpp; +#line 3643 + xp += ni; +#line 3643 + tp += ni; +#line 3643 + *xpp = (void*)xp; +#line 3643 + } +#line 3643 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3643 + +#line 3643 +#else /* not SX */ +#line 3643 + const char *xp = (const char *) *xpp; +#line 3643 + int status = NC_NOERR; +#line 3643 + +#line 3643 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3643 + { +#line 3643 + const int lstatus = ncx_get_longlong_int(xp, tp); +#line 3643 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3643 + status = lstatus; +#line 3643 + } +#line 3643 + +#line 3643 + *xpp = (const void *)xp; +#line 3643 + return status; +#line 3643 +#endif +#line 3643 +} +#line 3643 + +int +#line 3644 +ncx_getn_longlong_long(const void **xpp, size_t nelems, long *tp) +#line 3644 +{ +#line 3644 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3644 + +#line 3644 + /* basic algorithm is: +#line 3644 + * - ensure sane alignment of input data +#line 3644 + * - copy (conversion happens automatically) input data +#line 3644 + * to output +#line 3644 + * - update xpp to point at next unconverted input, and tp to point +#line 3644 + * at next location for converted output +#line 3644 + */ +#line 3644 + long i, j, ni; +#line 3644 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3644 + int64 *xp; +#line 3644 + int nrange = 0; /* number of range errors */ +#line 3644 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3644 + long cxp = (long) *((char**)xpp); +#line 3644 + +#line 3644 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3644 + /* sjl: manually stripmine so we can limit amount of +#line 3644 + * vector work space reserved to LOOPCNT elements. Also +#line 3644 + * makes vectorisation easy */ +#line 3644 + for (j=0; j= 0 */ +#line 3644 + nrange += xp[i] > LONG_MAX || xp[i] < LONG_MIN; +#line 3644 + } +#line 3644 + /* update xpp and tp */ +#line 3644 + if (realign) xp = (int64 *) *xpp; +#line 3644 + xp += ni; +#line 3644 + tp += ni; +#line 3644 + *xpp = (void*)xp; +#line 3644 + } +#line 3644 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3644 + +#line 3644 +#else /* not SX */ +#line 3644 + const char *xp = (const char *) *xpp; +#line 3644 + int status = NC_NOERR; +#line 3644 + +#line 3644 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3644 + { +#line 3644 + const int lstatus = ncx_get_longlong_long(xp, tp); +#line 3644 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3644 + status = lstatus; +#line 3644 + } +#line 3644 + +#line 3644 + *xpp = (const void *)xp; +#line 3644 + return status; +#line 3644 +#endif +#line 3644 +} +#line 3644 + +int +#line 3645 +ncx_getn_longlong_float(const void **xpp, size_t nelems, float *tp) +#line 3645 +{ +#line 3645 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3645 + +#line 3645 + /* basic algorithm is: +#line 3645 + * - ensure sane alignment of input data +#line 3645 + * - copy (conversion happens automatically) input data +#line 3645 + * to output +#line 3645 + * - update xpp to point at next unconverted input, and tp to point +#line 3645 + * at next location for converted output +#line 3645 + */ +#line 3645 + long i, j, ni; +#line 3645 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3645 + int64 *xp; +#line 3645 + int nrange = 0; /* number of range errors */ +#line 3645 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3645 + long cxp = (long) *((char**)xpp); +#line 3645 + +#line 3645 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3645 + /* sjl: manually stripmine so we can limit amount of +#line 3645 + * vector work space reserved to LOOPCNT elements. Also +#line 3645 + * makes vectorisation easy */ +#line 3645 + for (j=0; j= 0 */ +#line 3645 + nrange += xp[i] > FLOAT_MAX || xp[i] < FLOAT_MIN; +#line 3645 + } +#line 3645 + /* update xpp and tp */ +#line 3645 + if (realign) xp = (int64 *) *xpp; +#line 3645 + xp += ni; +#line 3645 + tp += ni; +#line 3645 + *xpp = (void*)xp; +#line 3645 + } +#line 3645 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3645 + +#line 3645 +#else /* not SX */ +#line 3645 + const char *xp = (const char *) *xpp; +#line 3645 + int status = NC_NOERR; +#line 3645 + +#line 3645 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3645 + { +#line 3645 + const int lstatus = ncx_get_longlong_float(xp, tp); +#line 3645 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3645 + status = lstatus; +#line 3645 + } +#line 3645 + +#line 3645 + *xpp = (const void *)xp; +#line 3645 + return status; +#line 3645 +#endif +#line 3645 +} +#line 3645 + +int +#line 3646 +ncx_getn_longlong_double(const void **xpp, size_t nelems, double *tp) +#line 3646 +{ +#line 3646 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3646 + +#line 3646 + /* basic algorithm is: +#line 3646 + * - ensure sane alignment of input data +#line 3646 + * - copy (conversion happens automatically) input data +#line 3646 + * to output +#line 3646 + * - update xpp to point at next unconverted input, and tp to point +#line 3646 + * at next location for converted output +#line 3646 + */ +#line 3646 + long i, j, ni; +#line 3646 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3646 + int64 *xp; +#line 3646 + int nrange = 0; /* number of range errors */ +#line 3646 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3646 + long cxp = (long) *((char**)xpp); +#line 3646 + +#line 3646 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3646 + /* sjl: manually stripmine so we can limit amount of +#line 3646 + * vector work space reserved to LOOPCNT elements. Also +#line 3646 + * makes vectorisation easy */ +#line 3646 + for (j=0; j= 0 */ +#line 3646 + nrange += xp[i] > DOUBLE_MAX || xp[i] < DOUBLE_MIN; +#line 3646 + } +#line 3646 + /* update xpp and tp */ +#line 3646 + if (realign) xp = (int64 *) *xpp; +#line 3646 + xp += ni; +#line 3646 + tp += ni; +#line 3646 + *xpp = (void*)xp; +#line 3646 + } +#line 3646 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3646 + +#line 3646 +#else /* not SX */ +#line 3646 + const char *xp = (const char *) *xpp; +#line 3646 + int status = NC_NOERR; +#line 3646 + +#line 3646 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3646 + { +#line 3646 + const int lstatus = ncx_get_longlong_double(xp, tp); +#line 3646 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3646 + status = lstatus; +#line 3646 + } +#line 3646 + +#line 3646 + *xpp = (const void *)xp; +#line 3646 + return status; +#line 3646 +#endif +#line 3646 +} +#line 3646 + +int +#line 3647 +ncx_getn_longlong_uchar(const void **xpp, size_t nelems, uchar *tp) +#line 3647 +{ +#line 3647 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3647 + +#line 3647 + /* basic algorithm is: +#line 3647 + * - ensure sane alignment of input data +#line 3647 + * - copy (conversion happens automatically) input data +#line 3647 + * to output +#line 3647 + * - update xpp to point at next unconverted input, and tp to point +#line 3647 + * at next location for converted output +#line 3647 + */ +#line 3647 + long i, j, ni; +#line 3647 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3647 + int64 *xp; +#line 3647 + int nrange = 0; /* number of range errors */ +#line 3647 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3647 + long cxp = (long) *((char**)xpp); +#line 3647 + +#line 3647 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3647 + /* sjl: manually stripmine so we can limit amount of +#line 3647 + * vector work space reserved to LOOPCNT elements. Also +#line 3647 + * makes vectorisation easy */ +#line 3647 + for (j=0; j= 0 */ +#line 3647 + nrange += xp[i] > UCHAR_MAX || xp[i] < 0; +#line 3647 + } +#line 3647 + /* update xpp and tp */ +#line 3647 + if (realign) xp = (int64 *) *xpp; +#line 3647 + xp += ni; +#line 3647 + tp += ni; +#line 3647 + *xpp = (void*)xp; +#line 3647 + } +#line 3647 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3647 + +#line 3647 +#else /* not SX */ +#line 3647 + const char *xp = (const char *) *xpp; +#line 3647 + int status = NC_NOERR; +#line 3647 + +#line 3647 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3647 + { +#line 3647 + const int lstatus = ncx_get_longlong_uchar(xp, tp); +#line 3647 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3647 + status = lstatus; +#line 3647 + } +#line 3647 + +#line 3647 + *xpp = (const void *)xp; +#line 3647 + return status; +#line 3647 +#endif +#line 3647 +} +#line 3647 + +int +#line 3648 +ncx_getn_longlong_ushort(const void **xpp, size_t nelems, ushort *tp) +#line 3648 +{ +#line 3648 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3648 + +#line 3648 + /* basic algorithm is: +#line 3648 + * - ensure sane alignment of input data +#line 3648 + * - copy (conversion happens automatically) input data +#line 3648 + * to output +#line 3648 + * - update xpp to point at next unconverted input, and tp to point +#line 3648 + * at next location for converted output +#line 3648 + */ +#line 3648 + long i, j, ni; +#line 3648 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3648 + int64 *xp; +#line 3648 + int nrange = 0; /* number of range errors */ +#line 3648 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3648 + long cxp = (long) *((char**)xpp); +#line 3648 + +#line 3648 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3648 + /* sjl: manually stripmine so we can limit amount of +#line 3648 + * vector work space reserved to LOOPCNT elements. Also +#line 3648 + * makes vectorisation easy */ +#line 3648 + for (j=0; j= 0 */ +#line 3648 + nrange += xp[i] > USHORT_MAX || xp[i] < 0; +#line 3648 + } +#line 3648 + /* update xpp and tp */ +#line 3648 + if (realign) xp = (int64 *) *xpp; +#line 3648 + xp += ni; +#line 3648 + tp += ni; +#line 3648 + *xpp = (void*)xp; +#line 3648 + } +#line 3648 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3648 + +#line 3648 +#else /* not SX */ +#line 3648 + const char *xp = (const char *) *xpp; +#line 3648 + int status = NC_NOERR; +#line 3648 + +#line 3648 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3648 + { +#line 3648 + const int lstatus = ncx_get_longlong_ushort(xp, tp); +#line 3648 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3648 + status = lstatus; +#line 3648 + } +#line 3648 + +#line 3648 + *xpp = (const void *)xp; +#line 3648 + return status; +#line 3648 +#endif +#line 3648 +} +#line 3648 + +int +#line 3649 +ncx_getn_longlong_uint(const void **xpp, size_t nelems, uint *tp) +#line 3649 +{ +#line 3649 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3649 + +#line 3649 + /* basic algorithm is: +#line 3649 + * - ensure sane alignment of input data +#line 3649 + * - copy (conversion happens automatically) input data +#line 3649 + * to output +#line 3649 + * - update xpp to point at next unconverted input, and tp to point +#line 3649 + * at next location for converted output +#line 3649 + */ +#line 3649 + long i, j, ni; +#line 3649 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3649 + int64 *xp; +#line 3649 + int nrange = 0; /* number of range errors */ +#line 3649 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3649 + long cxp = (long) *((char**)xpp); +#line 3649 + +#line 3649 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3649 + /* sjl: manually stripmine so we can limit amount of +#line 3649 + * vector work space reserved to LOOPCNT elements. Also +#line 3649 + * makes vectorisation easy */ +#line 3649 + for (j=0; j= 0 */ +#line 3649 + nrange += xp[i] > UINT_MAX || xp[i] < 0; +#line 3649 + } +#line 3649 + /* update xpp and tp */ +#line 3649 + if (realign) xp = (int64 *) *xpp; +#line 3649 + xp += ni; +#line 3649 + tp += ni; +#line 3649 + *xpp = (void*)xp; +#line 3649 + } +#line 3649 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3649 + +#line 3649 +#else /* not SX */ +#line 3649 + const char *xp = (const char *) *xpp; +#line 3649 + int status = NC_NOERR; +#line 3649 + +#line 3649 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3649 + { +#line 3649 + const int lstatus = ncx_get_longlong_uint(xp, tp); +#line 3649 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3649 + status = lstatus; +#line 3649 + } +#line 3649 + +#line 3649 + *xpp = (const void *)xp; +#line 3649 + return status; +#line 3649 +#endif +#line 3649 +} +#line 3649 + +int +#line 3650 +ncx_getn_longlong_ulonglong(const void **xpp, size_t nelems, ulonglong *tp) +#line 3650 +{ +#line 3650 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3650 + +#line 3650 + /* basic algorithm is: +#line 3650 + * - ensure sane alignment of input data +#line 3650 + * - copy (conversion happens automatically) input data +#line 3650 + * to output +#line 3650 + * - update xpp to point at next unconverted input, and tp to point +#line 3650 + * at next location for converted output +#line 3650 + */ +#line 3650 + long i, j, ni; +#line 3650 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3650 + int64 *xp; +#line 3650 + int nrange = 0; /* number of range errors */ +#line 3650 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3650 + long cxp = (long) *((char**)xpp); +#line 3650 + +#line 3650 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3650 + /* sjl: manually stripmine so we can limit amount of +#line 3650 + * vector work space reserved to LOOPCNT elements. Also +#line 3650 + * makes vectorisation easy */ +#line 3650 + for (j=0; j= 0 */ +#line 3650 + nrange += xp[i] > ULONGLONG_MAX || xp[i] < 0; +#line 3650 + } +#line 3650 + /* update xpp and tp */ +#line 3650 + if (realign) xp = (int64 *) *xpp; +#line 3650 + xp += ni; +#line 3650 + tp += ni; +#line 3650 + *xpp = (void*)xp; +#line 3650 + } +#line 3650 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3650 + +#line 3650 +#else /* not SX */ +#line 3650 + const char *xp = (const char *) *xpp; +#line 3650 + int status = NC_NOERR; +#line 3650 + +#line 3650 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3650 + { +#line 3650 + const int lstatus = ncx_get_longlong_ulonglong(xp, tp); +#line 3650 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3650 + status = lstatus; +#line 3650 + } +#line 3650 + +#line 3650 + *xpp = (const void *)xp; +#line 3650 + return status; +#line 3650 +#endif +#line 3650 +} +#line 3650 + + +#if X_SIZEOF_INT64 == SIZEOF_LONGLONG +/* optimized version */ +int +ncx_putn_longlong_longlong(void **xpp, size_t nelems, const long long *tp, void *fillp) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(*xpp, tp, (size_t)nelems * X_SIZEOF_INT64); +# else + swapn8b(*xpp, tp, nelems); +# endif + *xpp = (void *)((char *)(*xpp) + nelems * X_SIZEOF_INT64); + return NC_NOERR; +} +#else +int +#line 3666 +ncx_putn_longlong_longlong(void **xpp, size_t nelems, const longlong *tp, void *fillp) +#line 3666 +{ +#line 3666 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3666 + +#line 3666 + /* basic algorithm is: +#line 3666 + * - ensure sane alignment of output data +#line 3666 + * - copy (conversion happens automatically) input data +#line 3666 + * to output +#line 3666 + * - update tp to point at next unconverted input, and xpp to point +#line 3666 + * at next location for converted output +#line 3666 + */ +#line 3666 + long i, j, ni; +#line 3666 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3666 + int64 *xp; +#line 3666 + int nrange = 0; /* number of range errors */ +#line 3666 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3666 + long cxp = (long) *((char**)xpp); +#line 3666 + +#line 3666 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3666 + /* sjl: manually stripmine so we can limit amount of +#line 3666 + * vector work space reserved to LOOPCNT elements. Also +#line 3666 + * makes vectorisation easy */ +#line 3666 + for (j=0; j= 0 */ +#line 3666 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3666 + nrange += tp[i] > X_INT64_MAX || tp[i] < X_INT64_MIN; +#line 3666 + } +#line 3666 + /* copy workspace back if necessary */ +#line 3666 + if (realign) { +#line 3666 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT64); +#line 3666 + xp = (int64 *) *xpp; +#line 3666 + } +#line 3666 + /* update xpp and tp */ +#line 3666 + xp += ni; +#line 3666 + tp += ni; +#line 3666 + *xpp = (void*)xp; +#line 3666 + } +#line 3666 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3666 + +#line 3666 +#else /* not SX */ +#line 3666 + +#line 3666 + char *xp = (char *) *xpp; +#line 3666 + int status = NC_NOERR; +#line 3666 + +#line 3666 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3666 + { +#line 3666 + int lstatus = ncx_put_longlong_longlong(xp, tp, fillp); +#line 3666 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3666 + status = lstatus; +#line 3666 + } +#line 3666 + +#line 3666 + *xpp = (void *)xp; +#line 3666 + return status; +#line 3666 +#endif +#line 3666 +} +#line 3666 + +#endif +int +#line 3668 +ncx_putn_longlong_schar(void **xpp, size_t nelems, const schar *tp, void *fillp) +#line 3668 +{ +#line 3668 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3668 + +#line 3668 + /* basic algorithm is: +#line 3668 + * - ensure sane alignment of output data +#line 3668 + * - copy (conversion happens automatically) input data +#line 3668 + * to output +#line 3668 + * - update tp to point at next unconverted input, and xpp to point +#line 3668 + * at next location for converted output +#line 3668 + */ +#line 3668 + long i, j, ni; +#line 3668 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3668 + int64 *xp; +#line 3668 + int nrange = 0; /* number of range errors */ +#line 3668 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3668 + long cxp = (long) *((char**)xpp); +#line 3668 + +#line 3668 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3668 + /* sjl: manually stripmine so we can limit amount of +#line 3668 + * vector work space reserved to LOOPCNT elements. Also +#line 3668 + * makes vectorisation easy */ +#line 3668 + for (j=0; j= 0 */ +#line 3668 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3668 + nrange += tp[i] > X_INT64_MAX || tp[i] < X_INT64_MIN; +#line 3668 + } +#line 3668 + /* copy workspace back if necessary */ +#line 3668 + if (realign) { +#line 3668 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT64); +#line 3668 + xp = (int64 *) *xpp; +#line 3668 + } +#line 3668 + /* update xpp and tp */ +#line 3668 + xp += ni; +#line 3668 + tp += ni; +#line 3668 + *xpp = (void*)xp; +#line 3668 + } +#line 3668 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3668 + +#line 3668 +#else /* not SX */ +#line 3668 + +#line 3668 + char *xp = (char *) *xpp; +#line 3668 + int status = NC_NOERR; +#line 3668 + +#line 3668 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3668 + { +#line 3668 + int lstatus = ncx_put_longlong_schar(xp, tp, fillp); +#line 3668 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3668 + status = lstatus; +#line 3668 + } +#line 3668 + +#line 3668 + *xpp = (void *)xp; +#line 3668 + return status; +#line 3668 +#endif +#line 3668 +} +#line 3668 + +int +#line 3669 +ncx_putn_longlong_short(void **xpp, size_t nelems, const short *tp, void *fillp) +#line 3669 +{ +#line 3669 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3669 + +#line 3669 + /* basic algorithm is: +#line 3669 + * - ensure sane alignment of output data +#line 3669 + * - copy (conversion happens automatically) input data +#line 3669 + * to output +#line 3669 + * - update tp to point at next unconverted input, and xpp to point +#line 3669 + * at next location for converted output +#line 3669 + */ +#line 3669 + long i, j, ni; +#line 3669 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3669 + int64 *xp; +#line 3669 + int nrange = 0; /* number of range errors */ +#line 3669 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3669 + long cxp = (long) *((char**)xpp); +#line 3669 + +#line 3669 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3669 + /* sjl: manually stripmine so we can limit amount of +#line 3669 + * vector work space reserved to LOOPCNT elements. Also +#line 3669 + * makes vectorisation easy */ +#line 3669 + for (j=0; j= 0 */ +#line 3669 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3669 + nrange += tp[i] > X_INT64_MAX || tp[i] < X_INT64_MIN; +#line 3669 + } +#line 3669 + /* copy workspace back if necessary */ +#line 3669 + if (realign) { +#line 3669 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT64); +#line 3669 + xp = (int64 *) *xpp; +#line 3669 + } +#line 3669 + /* update xpp and tp */ +#line 3669 + xp += ni; +#line 3669 + tp += ni; +#line 3669 + *xpp = (void*)xp; +#line 3669 + } +#line 3669 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3669 + +#line 3669 +#else /* not SX */ +#line 3669 + +#line 3669 + char *xp = (char *) *xpp; +#line 3669 + int status = NC_NOERR; +#line 3669 + +#line 3669 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3669 + { +#line 3669 + int lstatus = ncx_put_longlong_short(xp, tp, fillp); +#line 3669 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3669 + status = lstatus; +#line 3669 + } +#line 3669 + +#line 3669 + *xpp = (void *)xp; +#line 3669 + return status; +#line 3669 +#endif +#line 3669 +} +#line 3669 + +int +#line 3670 +ncx_putn_longlong_int(void **xpp, size_t nelems, const int *tp, void *fillp) +#line 3670 +{ +#line 3670 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3670 + +#line 3670 + /* basic algorithm is: +#line 3670 + * - ensure sane alignment of output data +#line 3670 + * - copy (conversion happens automatically) input data +#line 3670 + * to output +#line 3670 + * - update tp to point at next unconverted input, and xpp to point +#line 3670 + * at next location for converted output +#line 3670 + */ +#line 3670 + long i, j, ni; +#line 3670 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3670 + int64 *xp; +#line 3670 + int nrange = 0; /* number of range errors */ +#line 3670 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3670 + long cxp = (long) *((char**)xpp); +#line 3670 + +#line 3670 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3670 + /* sjl: manually stripmine so we can limit amount of +#line 3670 + * vector work space reserved to LOOPCNT elements. Also +#line 3670 + * makes vectorisation easy */ +#line 3670 + for (j=0; j= 0 */ +#line 3670 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3670 + nrange += tp[i] > X_INT64_MAX || tp[i] < X_INT64_MIN; +#line 3670 + } +#line 3670 + /* copy workspace back if necessary */ +#line 3670 + if (realign) { +#line 3670 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT64); +#line 3670 + xp = (int64 *) *xpp; +#line 3670 + } +#line 3670 + /* update xpp and tp */ +#line 3670 + xp += ni; +#line 3670 + tp += ni; +#line 3670 + *xpp = (void*)xp; +#line 3670 + } +#line 3670 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3670 + +#line 3670 +#else /* not SX */ +#line 3670 + +#line 3670 + char *xp = (char *) *xpp; +#line 3670 + int status = NC_NOERR; +#line 3670 + +#line 3670 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3670 + { +#line 3670 + int lstatus = ncx_put_longlong_int(xp, tp, fillp); +#line 3670 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3670 + status = lstatus; +#line 3670 + } +#line 3670 + +#line 3670 + *xpp = (void *)xp; +#line 3670 + return status; +#line 3670 +#endif +#line 3670 +} +#line 3670 + +int +#line 3671 +ncx_putn_longlong_long(void **xpp, size_t nelems, const long *tp, void *fillp) +#line 3671 +{ +#line 3671 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3671 + +#line 3671 + /* basic algorithm is: +#line 3671 + * - ensure sane alignment of output data +#line 3671 + * - copy (conversion happens automatically) input data +#line 3671 + * to output +#line 3671 + * - update tp to point at next unconverted input, and xpp to point +#line 3671 + * at next location for converted output +#line 3671 + */ +#line 3671 + long i, j, ni; +#line 3671 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3671 + int64 *xp; +#line 3671 + int nrange = 0; /* number of range errors */ +#line 3671 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3671 + long cxp = (long) *((char**)xpp); +#line 3671 + +#line 3671 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3671 + /* sjl: manually stripmine so we can limit amount of +#line 3671 + * vector work space reserved to LOOPCNT elements. Also +#line 3671 + * makes vectorisation easy */ +#line 3671 + for (j=0; j= 0 */ +#line 3671 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3671 + nrange += tp[i] > X_INT64_MAX || tp[i] < X_INT64_MIN; +#line 3671 + } +#line 3671 + /* copy workspace back if necessary */ +#line 3671 + if (realign) { +#line 3671 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT64); +#line 3671 + xp = (int64 *) *xpp; +#line 3671 + } +#line 3671 + /* update xpp and tp */ +#line 3671 + xp += ni; +#line 3671 + tp += ni; +#line 3671 + *xpp = (void*)xp; +#line 3671 + } +#line 3671 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3671 + +#line 3671 +#else /* not SX */ +#line 3671 + +#line 3671 + char *xp = (char *) *xpp; +#line 3671 + int status = NC_NOERR; +#line 3671 + +#line 3671 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3671 + { +#line 3671 + int lstatus = ncx_put_longlong_long(xp, tp, fillp); +#line 3671 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3671 + status = lstatus; +#line 3671 + } +#line 3671 + +#line 3671 + *xpp = (void *)xp; +#line 3671 + return status; +#line 3671 +#endif +#line 3671 +} +#line 3671 + +int +#line 3672 +ncx_putn_longlong_float(void **xpp, size_t nelems, const float *tp, void *fillp) +#line 3672 +{ +#line 3672 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3672 + +#line 3672 + /* basic algorithm is: +#line 3672 + * - ensure sane alignment of output data +#line 3672 + * - copy (conversion happens automatically) input data +#line 3672 + * to output +#line 3672 + * - update tp to point at next unconverted input, and xpp to point +#line 3672 + * at next location for converted output +#line 3672 + */ +#line 3672 + long i, j, ni; +#line 3672 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3672 + int64 *xp; +#line 3672 + int nrange = 0; /* number of range errors */ +#line 3672 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3672 + long cxp = (long) *((char**)xpp); +#line 3672 + +#line 3672 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3672 + /* sjl: manually stripmine so we can limit amount of +#line 3672 + * vector work space reserved to LOOPCNT elements. Also +#line 3672 + * makes vectorisation easy */ +#line 3672 + for (j=0; j= 0 */ +#line 3672 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3672 + nrange += tp[i] > X_INT64_MAX || tp[i] < X_INT64_MIN; +#line 3672 + } +#line 3672 + /* copy workspace back if necessary */ +#line 3672 + if (realign) { +#line 3672 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT64); +#line 3672 + xp = (int64 *) *xpp; +#line 3672 + } +#line 3672 + /* update xpp and tp */ +#line 3672 + xp += ni; +#line 3672 + tp += ni; +#line 3672 + *xpp = (void*)xp; +#line 3672 + } +#line 3672 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3672 + +#line 3672 +#else /* not SX */ +#line 3672 + +#line 3672 + char *xp = (char *) *xpp; +#line 3672 + int status = NC_NOERR; +#line 3672 + +#line 3672 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3672 + { +#line 3672 + int lstatus = ncx_put_longlong_float(xp, tp, fillp); +#line 3672 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3672 + status = lstatus; +#line 3672 + } +#line 3672 + +#line 3672 + *xpp = (void *)xp; +#line 3672 + return status; +#line 3672 +#endif +#line 3672 +} +#line 3672 + +int +#line 3673 +ncx_putn_longlong_double(void **xpp, size_t nelems, const double *tp, void *fillp) +#line 3673 +{ +#line 3673 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3673 + +#line 3673 + /* basic algorithm is: +#line 3673 + * - ensure sane alignment of output data +#line 3673 + * - copy (conversion happens automatically) input data +#line 3673 + * to output +#line 3673 + * - update tp to point at next unconverted input, and xpp to point +#line 3673 + * at next location for converted output +#line 3673 + */ +#line 3673 + long i, j, ni; +#line 3673 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3673 + int64 *xp; +#line 3673 + int nrange = 0; /* number of range errors */ +#line 3673 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3673 + long cxp = (long) *((char**)xpp); +#line 3673 + +#line 3673 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3673 + /* sjl: manually stripmine so we can limit amount of +#line 3673 + * vector work space reserved to LOOPCNT elements. Also +#line 3673 + * makes vectorisation easy */ +#line 3673 + for (j=0; j= 0 */ +#line 3673 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3673 + nrange += tp[i] > X_INT64_MAX || tp[i] < X_INT64_MIN; +#line 3673 + } +#line 3673 + /* copy workspace back if necessary */ +#line 3673 + if (realign) { +#line 3673 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT64); +#line 3673 + xp = (int64 *) *xpp; +#line 3673 + } +#line 3673 + /* update xpp and tp */ +#line 3673 + xp += ni; +#line 3673 + tp += ni; +#line 3673 + *xpp = (void*)xp; +#line 3673 + } +#line 3673 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3673 + +#line 3673 +#else /* not SX */ +#line 3673 + +#line 3673 + char *xp = (char *) *xpp; +#line 3673 + int status = NC_NOERR; +#line 3673 + +#line 3673 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3673 + { +#line 3673 + int lstatus = ncx_put_longlong_double(xp, tp, fillp); +#line 3673 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3673 + status = lstatus; +#line 3673 + } +#line 3673 + +#line 3673 + *xpp = (void *)xp; +#line 3673 + return status; +#line 3673 +#endif +#line 3673 +} +#line 3673 + +int +#line 3674 +ncx_putn_longlong_uchar(void **xpp, size_t nelems, const uchar *tp, void *fillp) +#line 3674 +{ +#line 3674 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3674 + +#line 3674 + /* basic algorithm is: +#line 3674 + * - ensure sane alignment of output data +#line 3674 + * - copy (conversion happens automatically) input data +#line 3674 + * to output +#line 3674 + * - update tp to point at next unconverted input, and xpp to point +#line 3674 + * at next location for converted output +#line 3674 + */ +#line 3674 + long i, j, ni; +#line 3674 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3674 + int64 *xp; +#line 3674 + int nrange = 0; /* number of range errors */ +#line 3674 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3674 + long cxp = (long) *((char**)xpp); +#line 3674 + +#line 3674 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3674 + /* sjl: manually stripmine so we can limit amount of +#line 3674 + * vector work space reserved to LOOPCNT elements. Also +#line 3674 + * makes vectorisation easy */ +#line 3674 + for (j=0; j= 0 */ +#line 3674 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3674 + nrange += tp[i] > X_INT64_MAX ; +#line 3674 + } +#line 3674 + /* copy workspace back if necessary */ +#line 3674 + if (realign) { +#line 3674 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT64); +#line 3674 + xp = (int64 *) *xpp; +#line 3674 + } +#line 3674 + /* update xpp and tp */ +#line 3674 + xp += ni; +#line 3674 + tp += ni; +#line 3674 + *xpp = (void*)xp; +#line 3674 + } +#line 3674 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3674 + +#line 3674 +#else /* not SX */ +#line 3674 + +#line 3674 + char *xp = (char *) *xpp; +#line 3674 + int status = NC_NOERR; +#line 3674 + +#line 3674 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3674 + { +#line 3674 + int lstatus = ncx_put_longlong_uchar(xp, tp, fillp); +#line 3674 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3674 + status = lstatus; +#line 3674 + } +#line 3674 + +#line 3674 + *xpp = (void *)xp; +#line 3674 + return status; +#line 3674 +#endif +#line 3674 +} +#line 3674 + +int +#line 3675 +ncx_putn_longlong_ushort(void **xpp, size_t nelems, const ushort *tp, void *fillp) +#line 3675 +{ +#line 3675 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3675 + +#line 3675 + /* basic algorithm is: +#line 3675 + * - ensure sane alignment of output data +#line 3675 + * - copy (conversion happens automatically) input data +#line 3675 + * to output +#line 3675 + * - update tp to point at next unconverted input, and xpp to point +#line 3675 + * at next location for converted output +#line 3675 + */ +#line 3675 + long i, j, ni; +#line 3675 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3675 + int64 *xp; +#line 3675 + int nrange = 0; /* number of range errors */ +#line 3675 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3675 + long cxp = (long) *((char**)xpp); +#line 3675 + +#line 3675 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3675 + /* sjl: manually stripmine so we can limit amount of +#line 3675 + * vector work space reserved to LOOPCNT elements. Also +#line 3675 + * makes vectorisation easy */ +#line 3675 + for (j=0; j= 0 */ +#line 3675 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3675 + nrange += tp[i] > X_INT64_MAX ; +#line 3675 + } +#line 3675 + /* copy workspace back if necessary */ +#line 3675 + if (realign) { +#line 3675 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT64); +#line 3675 + xp = (int64 *) *xpp; +#line 3675 + } +#line 3675 + /* update xpp and tp */ +#line 3675 + xp += ni; +#line 3675 + tp += ni; +#line 3675 + *xpp = (void*)xp; +#line 3675 + } +#line 3675 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3675 + +#line 3675 +#else /* not SX */ +#line 3675 + +#line 3675 + char *xp = (char *) *xpp; +#line 3675 + int status = NC_NOERR; +#line 3675 + +#line 3675 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3675 + { +#line 3675 + int lstatus = ncx_put_longlong_ushort(xp, tp, fillp); +#line 3675 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3675 + status = lstatus; +#line 3675 + } +#line 3675 + +#line 3675 + *xpp = (void *)xp; +#line 3675 + return status; +#line 3675 +#endif +#line 3675 +} +#line 3675 + +int +#line 3676 +ncx_putn_longlong_uint(void **xpp, size_t nelems, const uint *tp, void *fillp) +#line 3676 +{ +#line 3676 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3676 + +#line 3676 + /* basic algorithm is: +#line 3676 + * - ensure sane alignment of output data +#line 3676 + * - copy (conversion happens automatically) input data +#line 3676 + * to output +#line 3676 + * - update tp to point at next unconverted input, and xpp to point +#line 3676 + * at next location for converted output +#line 3676 + */ +#line 3676 + long i, j, ni; +#line 3676 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3676 + int64 *xp; +#line 3676 + int nrange = 0; /* number of range errors */ +#line 3676 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3676 + long cxp = (long) *((char**)xpp); +#line 3676 + +#line 3676 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3676 + /* sjl: manually stripmine so we can limit amount of +#line 3676 + * vector work space reserved to LOOPCNT elements. Also +#line 3676 + * makes vectorisation easy */ +#line 3676 + for (j=0; j= 0 */ +#line 3676 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3676 + nrange += tp[i] > X_INT64_MAX ; +#line 3676 + } +#line 3676 + /* copy workspace back if necessary */ +#line 3676 + if (realign) { +#line 3676 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT64); +#line 3676 + xp = (int64 *) *xpp; +#line 3676 + } +#line 3676 + /* update xpp and tp */ +#line 3676 + xp += ni; +#line 3676 + tp += ni; +#line 3676 + *xpp = (void*)xp; +#line 3676 + } +#line 3676 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3676 + +#line 3676 +#else /* not SX */ +#line 3676 + +#line 3676 + char *xp = (char *) *xpp; +#line 3676 + int status = NC_NOERR; +#line 3676 + +#line 3676 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3676 + { +#line 3676 + int lstatus = ncx_put_longlong_uint(xp, tp, fillp); +#line 3676 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3676 + status = lstatus; +#line 3676 + } +#line 3676 + +#line 3676 + *xpp = (void *)xp; +#line 3676 + return status; +#line 3676 +#endif +#line 3676 +} +#line 3676 + +int +#line 3677 +ncx_putn_longlong_ulonglong(void **xpp, size_t nelems, const ulonglong *tp, void *fillp) +#line 3677 +{ +#line 3677 +#if defined(_SX) && _SX != 0 && X_SIZEOF_INT64 == SIZEOF_INT64 +#line 3677 + +#line 3677 + /* basic algorithm is: +#line 3677 + * - ensure sane alignment of output data +#line 3677 + * - copy (conversion happens automatically) input data +#line 3677 + * to output +#line 3677 + * - update tp to point at next unconverted input, and xpp to point +#line 3677 + * at next location for converted output +#line 3677 + */ +#line 3677 + long i, j, ni; +#line 3677 + int64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3677 + int64 *xp; +#line 3677 + int nrange = 0; /* number of range errors */ +#line 3677 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3677 + long cxp = (long) *((char**)xpp); +#line 3677 + +#line 3677 + realign = (cxp & 7) % SIZEOF_INT64; +#line 3677 + /* sjl: manually stripmine so we can limit amount of +#line 3677 + * vector work space reserved to LOOPCNT elements. Also +#line 3677 + * makes vectorisation easy */ +#line 3677 + for (j=0; j= 0 */ +#line 3677 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3677 + nrange += tp[i] > X_INT64_MAX ; +#line 3677 + } +#line 3677 + /* copy workspace back if necessary */ +#line 3677 + if (realign) { +#line 3677 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_INT64); +#line 3677 + xp = (int64 *) *xpp; +#line 3677 + } +#line 3677 + /* update xpp and tp */ +#line 3677 + xp += ni; +#line 3677 + tp += ni; +#line 3677 + *xpp = (void*)xp; +#line 3677 + } +#line 3677 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3677 + +#line 3677 +#else /* not SX */ +#line 3677 + +#line 3677 + char *xp = (char *) *xpp; +#line 3677 + int status = NC_NOERR; +#line 3677 + +#line 3677 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT64, tp++) +#line 3677 + { +#line 3677 + int lstatus = ncx_put_longlong_ulonglong(xp, tp, fillp); +#line 3677 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3677 + status = lstatus; +#line 3677 + } +#line 3677 + +#line 3677 + *xpp = (void *)xp; +#line 3677 + return status; +#line 3677 +#endif +#line 3677 +} +#line 3677 + + +/* uint64 --------------------------------------------------------------------*/ + +#if X_SIZEOF_UINT64 == SIZEOF_ULONGLONG +/* optimized version */ +int +ncx_getn_ulonglong_ulonglong(const void **xpp, size_t nelems, unsigned long long *tp) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(tp, *xpp, (size_t)nelems * SIZEOF_UNSIGNED_LONG_LONG); +# else + swapn8b(tp, *xpp, nelems); +# endif + *xpp = (const void *)((const char *)(*xpp) + nelems * X_SIZEOF_UINT64); + return NC_NOERR; +} +#else +int +#line 3695 +ncx_getn_ulonglong_ulonglong(const void **xpp, size_t nelems, ulonglong *tp) +#line 3695 +{ +#line 3695 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3695 + +#line 3695 + /* basic algorithm is: +#line 3695 + * - ensure sane alignment of input data +#line 3695 + * - copy (conversion happens automatically) input data +#line 3695 + * to output +#line 3695 + * - update xpp to point at next unconverted input, and tp to point +#line 3695 + * at next location for converted output +#line 3695 + */ +#line 3695 + long i, j, ni; +#line 3695 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3695 + uint64 *xp; +#line 3695 + int nrange = 0; /* number of range errors */ +#line 3695 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3695 + long cxp = (long) *((char**)xpp); +#line 3695 + +#line 3695 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3695 + /* sjl: manually stripmine so we can limit amount of +#line 3695 + * vector work space reserved to LOOPCNT elements. Also +#line 3695 + * makes vectorisation easy */ +#line 3695 + for (j=0; j= 0 */ +#line 3695 + nrange += xp[i] > ULONGLONG_MAX ; +#line 3695 + } +#line 3695 + /* update xpp and tp */ +#line 3695 + if (realign) xp = (uint64 *) *xpp; +#line 3695 + xp += ni; +#line 3695 + tp += ni; +#line 3695 + *xpp = (void*)xp; +#line 3695 + } +#line 3695 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3695 + +#line 3695 +#else /* not SX */ +#line 3695 + const char *xp = (const char *) *xpp; +#line 3695 + int status = NC_NOERR; +#line 3695 + +#line 3695 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3695 + { +#line 3695 + const int lstatus = ncx_get_ulonglong_ulonglong(xp, tp); +#line 3695 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3695 + status = lstatus; +#line 3695 + } +#line 3695 + +#line 3695 + *xpp = (const void *)xp; +#line 3695 + return status; +#line 3695 +#endif +#line 3695 +} +#line 3695 + +#endif +int +#line 3697 +ncx_getn_ulonglong_schar(const void **xpp, size_t nelems, schar *tp) +#line 3697 +{ +#line 3697 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3697 + +#line 3697 + /* basic algorithm is: +#line 3697 + * - ensure sane alignment of input data +#line 3697 + * - copy (conversion happens automatically) input data +#line 3697 + * to output +#line 3697 + * - update xpp to point at next unconverted input, and tp to point +#line 3697 + * at next location for converted output +#line 3697 + */ +#line 3697 + long i, j, ni; +#line 3697 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3697 + uint64 *xp; +#line 3697 + int nrange = 0; /* number of range errors */ +#line 3697 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3697 + long cxp = (long) *((char**)xpp); +#line 3697 + +#line 3697 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3697 + /* sjl: manually stripmine so we can limit amount of +#line 3697 + * vector work space reserved to LOOPCNT elements. Also +#line 3697 + * makes vectorisation easy */ +#line 3697 + for (j=0; j= 0 */ +#line 3697 + nrange += xp[i] > SCHAR_MAX ; +#line 3697 + } +#line 3697 + /* update xpp and tp */ +#line 3697 + if (realign) xp = (uint64 *) *xpp; +#line 3697 + xp += ni; +#line 3697 + tp += ni; +#line 3697 + *xpp = (void*)xp; +#line 3697 + } +#line 3697 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3697 + +#line 3697 +#else /* not SX */ +#line 3697 + const char *xp = (const char *) *xpp; +#line 3697 + int status = NC_NOERR; +#line 3697 + +#line 3697 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3697 + { +#line 3697 + const int lstatus = ncx_get_ulonglong_schar(xp, tp); +#line 3697 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3697 + status = lstatus; +#line 3697 + } +#line 3697 + +#line 3697 + *xpp = (const void *)xp; +#line 3697 + return status; +#line 3697 +#endif +#line 3697 +} +#line 3697 + +int +#line 3698 +ncx_getn_ulonglong_short(const void **xpp, size_t nelems, short *tp) +#line 3698 +{ +#line 3698 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3698 + +#line 3698 + /* basic algorithm is: +#line 3698 + * - ensure sane alignment of input data +#line 3698 + * - copy (conversion happens automatically) input data +#line 3698 + * to output +#line 3698 + * - update xpp to point at next unconverted input, and tp to point +#line 3698 + * at next location for converted output +#line 3698 + */ +#line 3698 + long i, j, ni; +#line 3698 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3698 + uint64 *xp; +#line 3698 + int nrange = 0; /* number of range errors */ +#line 3698 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3698 + long cxp = (long) *((char**)xpp); +#line 3698 + +#line 3698 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3698 + /* sjl: manually stripmine so we can limit amount of +#line 3698 + * vector work space reserved to LOOPCNT elements. Also +#line 3698 + * makes vectorisation easy */ +#line 3698 + for (j=0; j= 0 */ +#line 3698 + nrange += xp[i] > SHORT_MAX ; +#line 3698 + } +#line 3698 + /* update xpp and tp */ +#line 3698 + if (realign) xp = (uint64 *) *xpp; +#line 3698 + xp += ni; +#line 3698 + tp += ni; +#line 3698 + *xpp = (void*)xp; +#line 3698 + } +#line 3698 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3698 + +#line 3698 +#else /* not SX */ +#line 3698 + const char *xp = (const char *) *xpp; +#line 3698 + int status = NC_NOERR; +#line 3698 + +#line 3698 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3698 + { +#line 3698 + const int lstatus = ncx_get_ulonglong_short(xp, tp); +#line 3698 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3698 + status = lstatus; +#line 3698 + } +#line 3698 + +#line 3698 + *xpp = (const void *)xp; +#line 3698 + return status; +#line 3698 +#endif +#line 3698 +} +#line 3698 + +int +#line 3699 +ncx_getn_ulonglong_int(const void **xpp, size_t nelems, int *tp) +#line 3699 +{ +#line 3699 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3699 + +#line 3699 + /* basic algorithm is: +#line 3699 + * - ensure sane alignment of input data +#line 3699 + * - copy (conversion happens automatically) input data +#line 3699 + * to output +#line 3699 + * - update xpp to point at next unconverted input, and tp to point +#line 3699 + * at next location for converted output +#line 3699 + */ +#line 3699 + long i, j, ni; +#line 3699 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3699 + uint64 *xp; +#line 3699 + int nrange = 0; /* number of range errors */ +#line 3699 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3699 + long cxp = (long) *((char**)xpp); +#line 3699 + +#line 3699 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3699 + /* sjl: manually stripmine so we can limit amount of +#line 3699 + * vector work space reserved to LOOPCNT elements. Also +#line 3699 + * makes vectorisation easy */ +#line 3699 + for (j=0; j= 0 */ +#line 3699 + nrange += xp[i] > INT_MAX ; +#line 3699 + } +#line 3699 + /* update xpp and tp */ +#line 3699 + if (realign) xp = (uint64 *) *xpp; +#line 3699 + xp += ni; +#line 3699 + tp += ni; +#line 3699 + *xpp = (void*)xp; +#line 3699 + } +#line 3699 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3699 + +#line 3699 +#else /* not SX */ +#line 3699 + const char *xp = (const char *) *xpp; +#line 3699 + int status = NC_NOERR; +#line 3699 + +#line 3699 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3699 + { +#line 3699 + const int lstatus = ncx_get_ulonglong_int(xp, tp); +#line 3699 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3699 + status = lstatus; +#line 3699 + } +#line 3699 + +#line 3699 + *xpp = (const void *)xp; +#line 3699 + return status; +#line 3699 +#endif +#line 3699 +} +#line 3699 + +int +#line 3700 +ncx_getn_ulonglong_long(const void **xpp, size_t nelems, long *tp) +#line 3700 +{ +#line 3700 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3700 + +#line 3700 + /* basic algorithm is: +#line 3700 + * - ensure sane alignment of input data +#line 3700 + * - copy (conversion happens automatically) input data +#line 3700 + * to output +#line 3700 + * - update xpp to point at next unconverted input, and tp to point +#line 3700 + * at next location for converted output +#line 3700 + */ +#line 3700 + long i, j, ni; +#line 3700 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3700 + uint64 *xp; +#line 3700 + int nrange = 0; /* number of range errors */ +#line 3700 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3700 + long cxp = (long) *((char**)xpp); +#line 3700 + +#line 3700 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3700 + /* sjl: manually stripmine so we can limit amount of +#line 3700 + * vector work space reserved to LOOPCNT elements. Also +#line 3700 + * makes vectorisation easy */ +#line 3700 + for (j=0; j= 0 */ +#line 3700 + nrange += xp[i] > LONG_MAX ; +#line 3700 + } +#line 3700 + /* update xpp and tp */ +#line 3700 + if (realign) xp = (uint64 *) *xpp; +#line 3700 + xp += ni; +#line 3700 + tp += ni; +#line 3700 + *xpp = (void*)xp; +#line 3700 + } +#line 3700 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3700 + +#line 3700 +#else /* not SX */ +#line 3700 + const char *xp = (const char *) *xpp; +#line 3700 + int status = NC_NOERR; +#line 3700 + +#line 3700 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3700 + { +#line 3700 + const int lstatus = ncx_get_ulonglong_long(xp, tp); +#line 3700 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3700 + status = lstatus; +#line 3700 + } +#line 3700 + +#line 3700 + *xpp = (const void *)xp; +#line 3700 + return status; +#line 3700 +#endif +#line 3700 +} +#line 3700 + +int +#line 3701 +ncx_getn_ulonglong_float(const void **xpp, size_t nelems, float *tp) +#line 3701 +{ +#line 3701 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3701 + +#line 3701 + /* basic algorithm is: +#line 3701 + * - ensure sane alignment of input data +#line 3701 + * - copy (conversion happens automatically) input data +#line 3701 + * to output +#line 3701 + * - update xpp to point at next unconverted input, and tp to point +#line 3701 + * at next location for converted output +#line 3701 + */ +#line 3701 + long i, j, ni; +#line 3701 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3701 + uint64 *xp; +#line 3701 + int nrange = 0; /* number of range errors */ +#line 3701 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3701 + long cxp = (long) *((char**)xpp); +#line 3701 + +#line 3701 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3701 + /* sjl: manually stripmine so we can limit amount of +#line 3701 + * vector work space reserved to LOOPCNT elements. Also +#line 3701 + * makes vectorisation easy */ +#line 3701 + for (j=0; j= 0 */ +#line 3701 + nrange += xp[i] > FLOAT_MAX ; +#line 3701 + } +#line 3701 + /* update xpp and tp */ +#line 3701 + if (realign) xp = (uint64 *) *xpp; +#line 3701 + xp += ni; +#line 3701 + tp += ni; +#line 3701 + *xpp = (void*)xp; +#line 3701 + } +#line 3701 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3701 + +#line 3701 +#else /* not SX */ +#line 3701 + const char *xp = (const char *) *xpp; +#line 3701 + int status = NC_NOERR; +#line 3701 + +#line 3701 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3701 + { +#line 3701 + const int lstatus = ncx_get_ulonglong_float(xp, tp); +#line 3701 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3701 + status = lstatus; +#line 3701 + } +#line 3701 + +#line 3701 + *xpp = (const void *)xp; +#line 3701 + return status; +#line 3701 +#endif +#line 3701 +} +#line 3701 + +int +#line 3702 +ncx_getn_ulonglong_double(const void **xpp, size_t nelems, double *tp) +#line 3702 +{ +#line 3702 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3702 + +#line 3702 + /* basic algorithm is: +#line 3702 + * - ensure sane alignment of input data +#line 3702 + * - copy (conversion happens automatically) input data +#line 3702 + * to output +#line 3702 + * - update xpp to point at next unconverted input, and tp to point +#line 3702 + * at next location for converted output +#line 3702 + */ +#line 3702 + long i, j, ni; +#line 3702 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3702 + uint64 *xp; +#line 3702 + int nrange = 0; /* number of range errors */ +#line 3702 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3702 + long cxp = (long) *((char**)xpp); +#line 3702 + +#line 3702 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3702 + /* sjl: manually stripmine so we can limit amount of +#line 3702 + * vector work space reserved to LOOPCNT elements. Also +#line 3702 + * makes vectorisation easy */ +#line 3702 + for (j=0; j= 0 */ +#line 3702 + nrange += xp[i] > DOUBLE_MAX ; +#line 3702 + } +#line 3702 + /* update xpp and tp */ +#line 3702 + if (realign) xp = (uint64 *) *xpp; +#line 3702 + xp += ni; +#line 3702 + tp += ni; +#line 3702 + *xpp = (void*)xp; +#line 3702 + } +#line 3702 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3702 + +#line 3702 +#else /* not SX */ +#line 3702 + const char *xp = (const char *) *xpp; +#line 3702 + int status = NC_NOERR; +#line 3702 + +#line 3702 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3702 + { +#line 3702 + const int lstatus = ncx_get_ulonglong_double(xp, tp); +#line 3702 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3702 + status = lstatus; +#line 3702 + } +#line 3702 + +#line 3702 + *xpp = (const void *)xp; +#line 3702 + return status; +#line 3702 +#endif +#line 3702 +} +#line 3702 + +int +#line 3703 +ncx_getn_ulonglong_longlong(const void **xpp, size_t nelems, longlong *tp) +#line 3703 +{ +#line 3703 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3703 + +#line 3703 + /* basic algorithm is: +#line 3703 + * - ensure sane alignment of input data +#line 3703 + * - copy (conversion happens automatically) input data +#line 3703 + * to output +#line 3703 + * - update xpp to point at next unconverted input, and tp to point +#line 3703 + * at next location for converted output +#line 3703 + */ +#line 3703 + long i, j, ni; +#line 3703 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3703 + uint64 *xp; +#line 3703 + int nrange = 0; /* number of range errors */ +#line 3703 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3703 + long cxp = (long) *((char**)xpp); +#line 3703 + +#line 3703 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3703 + /* sjl: manually stripmine so we can limit amount of +#line 3703 + * vector work space reserved to LOOPCNT elements. Also +#line 3703 + * makes vectorisation easy */ +#line 3703 + for (j=0; j= 0 */ +#line 3703 + nrange += xp[i] > LONGLONG_MAX ; +#line 3703 + } +#line 3703 + /* update xpp and tp */ +#line 3703 + if (realign) xp = (uint64 *) *xpp; +#line 3703 + xp += ni; +#line 3703 + tp += ni; +#line 3703 + *xpp = (void*)xp; +#line 3703 + } +#line 3703 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3703 + +#line 3703 +#else /* not SX */ +#line 3703 + const char *xp = (const char *) *xpp; +#line 3703 + int status = NC_NOERR; +#line 3703 + +#line 3703 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3703 + { +#line 3703 + const int lstatus = ncx_get_ulonglong_longlong(xp, tp); +#line 3703 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3703 + status = lstatus; +#line 3703 + } +#line 3703 + +#line 3703 + *xpp = (const void *)xp; +#line 3703 + return status; +#line 3703 +#endif +#line 3703 +} +#line 3703 + +int +#line 3704 +ncx_getn_ulonglong_uchar(const void **xpp, size_t nelems, uchar *tp) +#line 3704 +{ +#line 3704 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3704 + +#line 3704 + /* basic algorithm is: +#line 3704 + * - ensure sane alignment of input data +#line 3704 + * - copy (conversion happens automatically) input data +#line 3704 + * to output +#line 3704 + * - update xpp to point at next unconverted input, and tp to point +#line 3704 + * at next location for converted output +#line 3704 + */ +#line 3704 + long i, j, ni; +#line 3704 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3704 + uint64 *xp; +#line 3704 + int nrange = 0; /* number of range errors */ +#line 3704 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3704 + long cxp = (long) *((char**)xpp); +#line 3704 + +#line 3704 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3704 + /* sjl: manually stripmine so we can limit amount of +#line 3704 + * vector work space reserved to LOOPCNT elements. Also +#line 3704 + * makes vectorisation easy */ +#line 3704 + for (j=0; j= 0 */ +#line 3704 + nrange += xp[i] > UCHAR_MAX ; +#line 3704 + } +#line 3704 + /* update xpp and tp */ +#line 3704 + if (realign) xp = (uint64 *) *xpp; +#line 3704 + xp += ni; +#line 3704 + tp += ni; +#line 3704 + *xpp = (void*)xp; +#line 3704 + } +#line 3704 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3704 + +#line 3704 +#else /* not SX */ +#line 3704 + const char *xp = (const char *) *xpp; +#line 3704 + int status = NC_NOERR; +#line 3704 + +#line 3704 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3704 + { +#line 3704 + const int lstatus = ncx_get_ulonglong_uchar(xp, tp); +#line 3704 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3704 + status = lstatus; +#line 3704 + } +#line 3704 + +#line 3704 + *xpp = (const void *)xp; +#line 3704 + return status; +#line 3704 +#endif +#line 3704 +} +#line 3704 + +int +#line 3705 +ncx_getn_ulonglong_ushort(const void **xpp, size_t nelems, ushort *tp) +#line 3705 +{ +#line 3705 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3705 + +#line 3705 + /* basic algorithm is: +#line 3705 + * - ensure sane alignment of input data +#line 3705 + * - copy (conversion happens automatically) input data +#line 3705 + * to output +#line 3705 + * - update xpp to point at next unconverted input, and tp to point +#line 3705 + * at next location for converted output +#line 3705 + */ +#line 3705 + long i, j, ni; +#line 3705 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3705 + uint64 *xp; +#line 3705 + int nrange = 0; /* number of range errors */ +#line 3705 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3705 + long cxp = (long) *((char**)xpp); +#line 3705 + +#line 3705 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3705 + /* sjl: manually stripmine so we can limit amount of +#line 3705 + * vector work space reserved to LOOPCNT elements. Also +#line 3705 + * makes vectorisation easy */ +#line 3705 + for (j=0; j= 0 */ +#line 3705 + nrange += xp[i] > USHORT_MAX ; +#line 3705 + } +#line 3705 + /* update xpp and tp */ +#line 3705 + if (realign) xp = (uint64 *) *xpp; +#line 3705 + xp += ni; +#line 3705 + tp += ni; +#line 3705 + *xpp = (void*)xp; +#line 3705 + } +#line 3705 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3705 + +#line 3705 +#else /* not SX */ +#line 3705 + const char *xp = (const char *) *xpp; +#line 3705 + int status = NC_NOERR; +#line 3705 + +#line 3705 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3705 + { +#line 3705 + const int lstatus = ncx_get_ulonglong_ushort(xp, tp); +#line 3705 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3705 + status = lstatus; +#line 3705 + } +#line 3705 + +#line 3705 + *xpp = (const void *)xp; +#line 3705 + return status; +#line 3705 +#endif +#line 3705 +} +#line 3705 + +int +#line 3706 +ncx_getn_ulonglong_uint(const void **xpp, size_t nelems, uint *tp) +#line 3706 +{ +#line 3706 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3706 + +#line 3706 + /* basic algorithm is: +#line 3706 + * - ensure sane alignment of input data +#line 3706 + * - copy (conversion happens automatically) input data +#line 3706 + * to output +#line 3706 + * - update xpp to point at next unconverted input, and tp to point +#line 3706 + * at next location for converted output +#line 3706 + */ +#line 3706 + long i, j, ni; +#line 3706 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3706 + uint64 *xp; +#line 3706 + int nrange = 0; /* number of range errors */ +#line 3706 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3706 + long cxp = (long) *((char**)xpp); +#line 3706 + +#line 3706 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3706 + /* sjl: manually stripmine so we can limit amount of +#line 3706 + * vector work space reserved to LOOPCNT elements. Also +#line 3706 + * makes vectorisation easy */ +#line 3706 + for (j=0; j= 0 */ +#line 3706 + nrange += xp[i] > UINT_MAX ; +#line 3706 + } +#line 3706 + /* update xpp and tp */ +#line 3706 + if (realign) xp = (uint64 *) *xpp; +#line 3706 + xp += ni; +#line 3706 + tp += ni; +#line 3706 + *xpp = (void*)xp; +#line 3706 + } +#line 3706 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3706 + +#line 3706 +#else /* not SX */ +#line 3706 + const char *xp = (const char *) *xpp; +#line 3706 + int status = NC_NOERR; +#line 3706 + +#line 3706 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3706 + { +#line 3706 + const int lstatus = ncx_get_ulonglong_uint(xp, tp); +#line 3706 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3706 + status = lstatus; +#line 3706 + } +#line 3706 + +#line 3706 + *xpp = (const void *)xp; +#line 3706 + return status; +#line 3706 +#endif +#line 3706 +} +#line 3706 + + +#if X_SIZEOF_UINT64 == SIZEOF_ULONGLONG +/* optimized version */ +int +ncx_putn_ulonglong_ulonglong(void **xpp, size_t nelems, const unsigned long long *tp, void *fillp) +{ +#ifdef WORDS_BIGENDIAN + (void) memcpy(*xpp, tp, (size_t)nelems * X_SIZEOF_UINT64); +# else + swapn8b(*xpp, tp, nelems); +# endif + *xpp = (void *)((char *)(*xpp) + nelems * X_SIZEOF_UINT64); + return NC_NOERR; +} +#else +int +#line 3722 +ncx_putn_ulonglong_ulonglong(void **xpp, size_t nelems, const ulonglong *tp, void *fillp) +#line 3722 +{ +#line 3722 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3722 + +#line 3722 + /* basic algorithm is: +#line 3722 + * - ensure sane alignment of output data +#line 3722 + * - copy (conversion happens automatically) input data +#line 3722 + * to output +#line 3722 + * - update tp to point at next unconverted input, and xpp to point +#line 3722 + * at next location for converted output +#line 3722 + */ +#line 3722 + long i, j, ni; +#line 3722 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3722 + uint64 *xp; +#line 3722 + int nrange = 0; /* number of range errors */ +#line 3722 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3722 + long cxp = (long) *((char**)xpp); +#line 3722 + +#line 3722 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3722 + /* sjl: manually stripmine so we can limit amount of +#line 3722 + * vector work space reserved to LOOPCNT elements. Also +#line 3722 + * makes vectorisation easy */ +#line 3722 + for (j=0; j= 0 */ +#line 3722 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3722 + nrange += tp[i] > X_UINT64_MAX ; +#line 3722 + } +#line 3722 + /* copy workspace back if necessary */ +#line 3722 + if (realign) { +#line 3722 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT64); +#line 3722 + xp = (uint64 *) *xpp; +#line 3722 + } +#line 3722 + /* update xpp and tp */ +#line 3722 + xp += ni; +#line 3722 + tp += ni; +#line 3722 + *xpp = (void*)xp; +#line 3722 + } +#line 3722 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3722 + +#line 3722 +#else /* not SX */ +#line 3722 + +#line 3722 + char *xp = (char *) *xpp; +#line 3722 + int status = NC_NOERR; +#line 3722 + +#line 3722 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3722 + { +#line 3722 + int lstatus = ncx_put_ulonglong_ulonglong(xp, tp, fillp); +#line 3722 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3722 + status = lstatus; +#line 3722 + } +#line 3722 + +#line 3722 + *xpp = (void *)xp; +#line 3722 + return status; +#line 3722 +#endif +#line 3722 +} +#line 3722 + +#endif +int +#line 3724 +ncx_putn_ulonglong_schar(void **xpp, size_t nelems, const schar *tp, void *fillp) +#line 3724 +{ +#line 3724 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3724 + +#line 3724 + /* basic algorithm is: +#line 3724 + * - ensure sane alignment of output data +#line 3724 + * - copy (conversion happens automatically) input data +#line 3724 + * to output +#line 3724 + * - update tp to point at next unconverted input, and xpp to point +#line 3724 + * at next location for converted output +#line 3724 + */ +#line 3724 + long i, j, ni; +#line 3724 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3724 + uint64 *xp; +#line 3724 + int nrange = 0; /* number of range errors */ +#line 3724 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3724 + long cxp = (long) *((char**)xpp); +#line 3724 + +#line 3724 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3724 + /* sjl: manually stripmine so we can limit amount of +#line 3724 + * vector work space reserved to LOOPCNT elements. Also +#line 3724 + * makes vectorisation easy */ +#line 3724 + for (j=0; j= 0 */ +#line 3724 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3724 + nrange += tp[i] > X_UINT64_MAX || tp[i] < 0; +#line 3724 + } +#line 3724 + /* copy workspace back if necessary */ +#line 3724 + if (realign) { +#line 3724 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT64); +#line 3724 + xp = (uint64 *) *xpp; +#line 3724 + } +#line 3724 + /* update xpp and tp */ +#line 3724 + xp += ni; +#line 3724 + tp += ni; +#line 3724 + *xpp = (void*)xp; +#line 3724 + } +#line 3724 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3724 + +#line 3724 +#else /* not SX */ +#line 3724 + +#line 3724 + char *xp = (char *) *xpp; +#line 3724 + int status = NC_NOERR; +#line 3724 + +#line 3724 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3724 + { +#line 3724 + int lstatus = ncx_put_ulonglong_schar(xp, tp, fillp); +#line 3724 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3724 + status = lstatus; +#line 3724 + } +#line 3724 + +#line 3724 + *xpp = (void *)xp; +#line 3724 + return status; +#line 3724 +#endif +#line 3724 +} +#line 3724 + +int +#line 3725 +ncx_putn_ulonglong_short(void **xpp, size_t nelems, const short *tp, void *fillp) +#line 3725 +{ +#line 3725 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3725 + +#line 3725 + /* basic algorithm is: +#line 3725 + * - ensure sane alignment of output data +#line 3725 + * - copy (conversion happens automatically) input data +#line 3725 + * to output +#line 3725 + * - update tp to point at next unconverted input, and xpp to point +#line 3725 + * at next location for converted output +#line 3725 + */ +#line 3725 + long i, j, ni; +#line 3725 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3725 + uint64 *xp; +#line 3725 + int nrange = 0; /* number of range errors */ +#line 3725 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3725 + long cxp = (long) *((char**)xpp); +#line 3725 + +#line 3725 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3725 + /* sjl: manually stripmine so we can limit amount of +#line 3725 + * vector work space reserved to LOOPCNT elements. Also +#line 3725 + * makes vectorisation easy */ +#line 3725 + for (j=0; j= 0 */ +#line 3725 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3725 + nrange += tp[i] > X_UINT64_MAX || tp[i] < 0; +#line 3725 + } +#line 3725 + /* copy workspace back if necessary */ +#line 3725 + if (realign) { +#line 3725 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT64); +#line 3725 + xp = (uint64 *) *xpp; +#line 3725 + } +#line 3725 + /* update xpp and tp */ +#line 3725 + xp += ni; +#line 3725 + tp += ni; +#line 3725 + *xpp = (void*)xp; +#line 3725 + } +#line 3725 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3725 + +#line 3725 +#else /* not SX */ +#line 3725 + +#line 3725 + char *xp = (char *) *xpp; +#line 3725 + int status = NC_NOERR; +#line 3725 + +#line 3725 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3725 + { +#line 3725 + int lstatus = ncx_put_ulonglong_short(xp, tp, fillp); +#line 3725 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3725 + status = lstatus; +#line 3725 + } +#line 3725 + +#line 3725 + *xpp = (void *)xp; +#line 3725 + return status; +#line 3725 +#endif +#line 3725 +} +#line 3725 + +int +#line 3726 +ncx_putn_ulonglong_int(void **xpp, size_t nelems, const int *tp, void *fillp) +#line 3726 +{ +#line 3726 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3726 + +#line 3726 + /* basic algorithm is: +#line 3726 + * - ensure sane alignment of output data +#line 3726 + * - copy (conversion happens automatically) input data +#line 3726 + * to output +#line 3726 + * - update tp to point at next unconverted input, and xpp to point +#line 3726 + * at next location for converted output +#line 3726 + */ +#line 3726 + long i, j, ni; +#line 3726 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3726 + uint64 *xp; +#line 3726 + int nrange = 0; /* number of range errors */ +#line 3726 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3726 + long cxp = (long) *((char**)xpp); +#line 3726 + +#line 3726 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3726 + /* sjl: manually stripmine so we can limit amount of +#line 3726 + * vector work space reserved to LOOPCNT elements. Also +#line 3726 + * makes vectorisation easy */ +#line 3726 + for (j=0; j= 0 */ +#line 3726 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3726 + nrange += tp[i] > X_UINT64_MAX || tp[i] < 0; +#line 3726 + } +#line 3726 + /* copy workspace back if necessary */ +#line 3726 + if (realign) { +#line 3726 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT64); +#line 3726 + xp = (uint64 *) *xpp; +#line 3726 + } +#line 3726 + /* update xpp and tp */ +#line 3726 + xp += ni; +#line 3726 + tp += ni; +#line 3726 + *xpp = (void*)xp; +#line 3726 + } +#line 3726 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3726 + +#line 3726 +#else /* not SX */ +#line 3726 + +#line 3726 + char *xp = (char *) *xpp; +#line 3726 + int status = NC_NOERR; +#line 3726 + +#line 3726 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3726 + { +#line 3726 + int lstatus = ncx_put_ulonglong_int(xp, tp, fillp); +#line 3726 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3726 + status = lstatus; +#line 3726 + } +#line 3726 + +#line 3726 + *xpp = (void *)xp; +#line 3726 + return status; +#line 3726 +#endif +#line 3726 +} +#line 3726 + +int +#line 3727 +ncx_putn_ulonglong_long(void **xpp, size_t nelems, const long *tp, void *fillp) +#line 3727 +{ +#line 3727 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3727 + +#line 3727 + /* basic algorithm is: +#line 3727 + * - ensure sane alignment of output data +#line 3727 + * - copy (conversion happens automatically) input data +#line 3727 + * to output +#line 3727 + * - update tp to point at next unconverted input, and xpp to point +#line 3727 + * at next location for converted output +#line 3727 + */ +#line 3727 + long i, j, ni; +#line 3727 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3727 + uint64 *xp; +#line 3727 + int nrange = 0; /* number of range errors */ +#line 3727 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3727 + long cxp = (long) *((char**)xpp); +#line 3727 + +#line 3727 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3727 + /* sjl: manually stripmine so we can limit amount of +#line 3727 + * vector work space reserved to LOOPCNT elements. Also +#line 3727 + * makes vectorisation easy */ +#line 3727 + for (j=0; j= 0 */ +#line 3727 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3727 + nrange += tp[i] > X_UINT64_MAX || tp[i] < 0; +#line 3727 + } +#line 3727 + /* copy workspace back if necessary */ +#line 3727 + if (realign) { +#line 3727 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT64); +#line 3727 + xp = (uint64 *) *xpp; +#line 3727 + } +#line 3727 + /* update xpp and tp */ +#line 3727 + xp += ni; +#line 3727 + tp += ni; +#line 3727 + *xpp = (void*)xp; +#line 3727 + } +#line 3727 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3727 + +#line 3727 +#else /* not SX */ +#line 3727 + +#line 3727 + char *xp = (char *) *xpp; +#line 3727 + int status = NC_NOERR; +#line 3727 + +#line 3727 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3727 + { +#line 3727 + int lstatus = ncx_put_ulonglong_long(xp, tp, fillp); +#line 3727 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3727 + status = lstatus; +#line 3727 + } +#line 3727 + +#line 3727 + *xpp = (void *)xp; +#line 3727 + return status; +#line 3727 +#endif +#line 3727 +} +#line 3727 + +int +#line 3728 +ncx_putn_ulonglong_float(void **xpp, size_t nelems, const float *tp, void *fillp) +#line 3728 +{ +#line 3728 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3728 + +#line 3728 + /* basic algorithm is: +#line 3728 + * - ensure sane alignment of output data +#line 3728 + * - copy (conversion happens automatically) input data +#line 3728 + * to output +#line 3728 + * - update tp to point at next unconverted input, and xpp to point +#line 3728 + * at next location for converted output +#line 3728 + */ +#line 3728 + long i, j, ni; +#line 3728 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3728 + uint64 *xp; +#line 3728 + int nrange = 0; /* number of range errors */ +#line 3728 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3728 + long cxp = (long) *((char**)xpp); +#line 3728 + +#line 3728 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3728 + /* sjl: manually stripmine so we can limit amount of +#line 3728 + * vector work space reserved to LOOPCNT elements. Also +#line 3728 + * makes vectorisation easy */ +#line 3728 + for (j=0; j= 0 */ +#line 3728 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3728 + nrange += tp[i] > X_UINT64_MAX || tp[i] < 0; +#line 3728 + } +#line 3728 + /* copy workspace back if necessary */ +#line 3728 + if (realign) { +#line 3728 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT64); +#line 3728 + xp = (uint64 *) *xpp; +#line 3728 + } +#line 3728 + /* update xpp and tp */ +#line 3728 + xp += ni; +#line 3728 + tp += ni; +#line 3728 + *xpp = (void*)xp; +#line 3728 + } +#line 3728 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3728 + +#line 3728 +#else /* not SX */ +#line 3728 + +#line 3728 + char *xp = (char *) *xpp; +#line 3728 + int status = NC_NOERR; +#line 3728 + +#line 3728 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3728 + { +#line 3728 + int lstatus = ncx_put_ulonglong_float(xp, tp, fillp); +#line 3728 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3728 + status = lstatus; +#line 3728 + } +#line 3728 + +#line 3728 + *xpp = (void *)xp; +#line 3728 + return status; +#line 3728 +#endif +#line 3728 +} +#line 3728 + +int +#line 3729 +ncx_putn_ulonglong_double(void **xpp, size_t nelems, const double *tp, void *fillp) +#line 3729 +{ +#line 3729 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3729 + +#line 3729 + /* basic algorithm is: +#line 3729 + * - ensure sane alignment of output data +#line 3729 + * - copy (conversion happens automatically) input data +#line 3729 + * to output +#line 3729 + * - update tp to point at next unconverted input, and xpp to point +#line 3729 + * at next location for converted output +#line 3729 + */ +#line 3729 + long i, j, ni; +#line 3729 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3729 + uint64 *xp; +#line 3729 + int nrange = 0; /* number of range errors */ +#line 3729 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3729 + long cxp = (long) *((char**)xpp); +#line 3729 + +#line 3729 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3729 + /* sjl: manually stripmine so we can limit amount of +#line 3729 + * vector work space reserved to LOOPCNT elements. Also +#line 3729 + * makes vectorisation easy */ +#line 3729 + for (j=0; j= 0 */ +#line 3729 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3729 + nrange += tp[i] > X_UINT64_MAX || tp[i] < 0; +#line 3729 + } +#line 3729 + /* copy workspace back if necessary */ +#line 3729 + if (realign) { +#line 3729 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT64); +#line 3729 + xp = (uint64 *) *xpp; +#line 3729 + } +#line 3729 + /* update xpp and tp */ +#line 3729 + xp += ni; +#line 3729 + tp += ni; +#line 3729 + *xpp = (void*)xp; +#line 3729 + } +#line 3729 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3729 + +#line 3729 +#else /* not SX */ +#line 3729 + +#line 3729 + char *xp = (char *) *xpp; +#line 3729 + int status = NC_NOERR; +#line 3729 + +#line 3729 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3729 + { +#line 3729 + int lstatus = ncx_put_ulonglong_double(xp, tp, fillp); +#line 3729 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3729 + status = lstatus; +#line 3729 + } +#line 3729 + +#line 3729 + *xpp = (void *)xp; +#line 3729 + return status; +#line 3729 +#endif +#line 3729 +} +#line 3729 + +int +#line 3730 +ncx_putn_ulonglong_longlong(void **xpp, size_t nelems, const longlong *tp, void *fillp) +#line 3730 +{ +#line 3730 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3730 + +#line 3730 + /* basic algorithm is: +#line 3730 + * - ensure sane alignment of output data +#line 3730 + * - copy (conversion happens automatically) input data +#line 3730 + * to output +#line 3730 + * - update tp to point at next unconverted input, and xpp to point +#line 3730 + * at next location for converted output +#line 3730 + */ +#line 3730 + long i, j, ni; +#line 3730 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3730 + uint64 *xp; +#line 3730 + int nrange = 0; /* number of range errors */ +#line 3730 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3730 + long cxp = (long) *((char**)xpp); +#line 3730 + +#line 3730 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3730 + /* sjl: manually stripmine so we can limit amount of +#line 3730 + * vector work space reserved to LOOPCNT elements. Also +#line 3730 + * makes vectorisation easy */ +#line 3730 + for (j=0; j= 0 */ +#line 3730 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3730 + nrange += tp[i] > X_UINT64_MAX || tp[i] < 0; +#line 3730 + } +#line 3730 + /* copy workspace back if necessary */ +#line 3730 + if (realign) { +#line 3730 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT64); +#line 3730 + xp = (uint64 *) *xpp; +#line 3730 + } +#line 3730 + /* update xpp and tp */ +#line 3730 + xp += ni; +#line 3730 + tp += ni; +#line 3730 + *xpp = (void*)xp; +#line 3730 + } +#line 3730 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3730 + +#line 3730 +#else /* not SX */ +#line 3730 + +#line 3730 + char *xp = (char *) *xpp; +#line 3730 + int status = NC_NOERR; +#line 3730 + +#line 3730 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3730 + { +#line 3730 + int lstatus = ncx_put_ulonglong_longlong(xp, tp, fillp); +#line 3730 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3730 + status = lstatus; +#line 3730 + } +#line 3730 + +#line 3730 + *xpp = (void *)xp; +#line 3730 + return status; +#line 3730 +#endif +#line 3730 +} +#line 3730 + +int +#line 3731 +ncx_putn_ulonglong_uchar(void **xpp, size_t nelems, const uchar *tp, void *fillp) +#line 3731 +{ +#line 3731 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3731 + +#line 3731 + /* basic algorithm is: +#line 3731 + * - ensure sane alignment of output data +#line 3731 + * - copy (conversion happens automatically) input data +#line 3731 + * to output +#line 3731 + * - update tp to point at next unconverted input, and xpp to point +#line 3731 + * at next location for converted output +#line 3731 + */ +#line 3731 + long i, j, ni; +#line 3731 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3731 + uint64 *xp; +#line 3731 + int nrange = 0; /* number of range errors */ +#line 3731 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3731 + long cxp = (long) *((char**)xpp); +#line 3731 + +#line 3731 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3731 + /* sjl: manually stripmine so we can limit amount of +#line 3731 + * vector work space reserved to LOOPCNT elements. Also +#line 3731 + * makes vectorisation easy */ +#line 3731 + for (j=0; j= 0 */ +#line 3731 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3731 + nrange += tp[i] > X_UINT64_MAX ; +#line 3731 + } +#line 3731 + /* copy workspace back if necessary */ +#line 3731 + if (realign) { +#line 3731 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT64); +#line 3731 + xp = (uint64 *) *xpp; +#line 3731 + } +#line 3731 + /* update xpp and tp */ +#line 3731 + xp += ni; +#line 3731 + tp += ni; +#line 3731 + *xpp = (void*)xp; +#line 3731 + } +#line 3731 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3731 + +#line 3731 +#else /* not SX */ +#line 3731 + +#line 3731 + char *xp = (char *) *xpp; +#line 3731 + int status = NC_NOERR; +#line 3731 + +#line 3731 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3731 + { +#line 3731 + int lstatus = ncx_put_ulonglong_uchar(xp, tp, fillp); +#line 3731 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3731 + status = lstatus; +#line 3731 + } +#line 3731 + +#line 3731 + *xpp = (void *)xp; +#line 3731 + return status; +#line 3731 +#endif +#line 3731 +} +#line 3731 + +int +#line 3732 +ncx_putn_ulonglong_ushort(void **xpp, size_t nelems, const ushort *tp, void *fillp) +#line 3732 +{ +#line 3732 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3732 + +#line 3732 + /* basic algorithm is: +#line 3732 + * - ensure sane alignment of output data +#line 3732 + * - copy (conversion happens automatically) input data +#line 3732 + * to output +#line 3732 + * - update tp to point at next unconverted input, and xpp to point +#line 3732 + * at next location for converted output +#line 3732 + */ +#line 3732 + long i, j, ni; +#line 3732 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3732 + uint64 *xp; +#line 3732 + int nrange = 0; /* number of range errors */ +#line 3732 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3732 + long cxp = (long) *((char**)xpp); +#line 3732 + +#line 3732 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3732 + /* sjl: manually stripmine so we can limit amount of +#line 3732 + * vector work space reserved to LOOPCNT elements. Also +#line 3732 + * makes vectorisation easy */ +#line 3732 + for (j=0; j= 0 */ +#line 3732 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3732 + nrange += tp[i] > X_UINT64_MAX ; +#line 3732 + } +#line 3732 + /* copy workspace back if necessary */ +#line 3732 + if (realign) { +#line 3732 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT64); +#line 3732 + xp = (uint64 *) *xpp; +#line 3732 + } +#line 3732 + /* update xpp and tp */ +#line 3732 + xp += ni; +#line 3732 + tp += ni; +#line 3732 + *xpp = (void*)xp; +#line 3732 + } +#line 3732 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3732 + +#line 3732 +#else /* not SX */ +#line 3732 + +#line 3732 + char *xp = (char *) *xpp; +#line 3732 + int status = NC_NOERR; +#line 3732 + +#line 3732 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3732 + { +#line 3732 + int lstatus = ncx_put_ulonglong_ushort(xp, tp, fillp); +#line 3732 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3732 + status = lstatus; +#line 3732 + } +#line 3732 + +#line 3732 + *xpp = (void *)xp; +#line 3732 + return status; +#line 3732 +#endif +#line 3732 +} +#line 3732 + +int +#line 3733 +ncx_putn_ulonglong_uint(void **xpp, size_t nelems, const uint *tp, void *fillp) +#line 3733 +{ +#line 3733 +#if defined(_SX) && _SX != 0 && X_SIZEOF_UINT64 == SIZEOF_UINT64 +#line 3733 + +#line 3733 + /* basic algorithm is: +#line 3733 + * - ensure sane alignment of output data +#line 3733 + * - copy (conversion happens automatically) input data +#line 3733 + * to output +#line 3733 + * - update tp to point at next unconverted input, and xpp to point +#line 3733 + * at next location for converted output +#line 3733 + */ +#line 3733 + long i, j, ni; +#line 3733 + uint64 tmp[LOOPCNT]; /* in case input is misaligned */ +#line 3733 + uint64 *xp; +#line 3733 + int nrange = 0; /* number of range errors */ +#line 3733 + int realign = 0; /* "do we need to fix input data alignment?" */ +#line 3733 + long cxp = (long) *((char**)xpp); +#line 3733 + +#line 3733 + realign = (cxp & 7) % SIZEOF_UINT64; +#line 3733 + /* sjl: manually stripmine so we can limit amount of +#line 3733 + * vector work space reserved to LOOPCNT elements. Also +#line 3733 + * makes vectorisation easy */ +#line 3733 + for (j=0; j= 0 */ +#line 3733 + /* if tp is unsigned, we need not check if tp[i] < X__MIN */ +#line 3733 + nrange += tp[i] > X_UINT64_MAX ; +#line 3733 + } +#line 3733 + /* copy workspace back if necessary */ +#line 3733 + if (realign) { +#line 3733 + memcpy(*xpp, tmp, (size_t)*ni*X_SIZEOF_UINT64); +#line 3733 + xp = (uint64 *) *xpp; +#line 3733 + } +#line 3733 + /* update xpp and tp */ +#line 3733 + xp += ni; +#line 3733 + tp += ni; +#line 3733 + *xpp = (void*)xp; +#line 3733 + } +#line 3733 + return nrange == 0 ? NC_NOERR : NC_ERANGE; +#line 3733 + +#line 3733 +#else /* not SX */ +#line 3733 + +#line 3733 + char *xp = (char *) *xpp; +#line 3733 + int status = NC_NOERR; +#line 3733 + +#line 3733 + for( ; nelems != 0; nelems--, xp += X_SIZEOF_UINT64, tp++) +#line 3733 + { +#line 3733 + int lstatus = ncx_put_ulonglong_uint(xp, tp, fillp); +#line 3733 + if (status == NC_NOERR) /* report the first encountered error */ +#line 3733 + status = lstatus; +#line 3733 + } +#line 3733 + +#line 3733 + *xpp = (void *)xp; +#line 3733 + return status; +#line 3733 +#endif +#line 3733 +} +#line 3733 + + + +/* + * Other aggregate conversion functions. + */ + +/* text */ + +int +ncx_getn_text(const void **xpp, size_t nelems, char *tp) +{ + (void) memcpy(tp, *xpp, (size_t)nelems); +#line 3745 + *xpp = (void *)((char *)(*xpp) + nelems); +#line 3745 + return NC_NOERR; +#line 3745 + +} + +int +ncx_pad_getn_text(const void **xpp, size_t nelems, char *tp) +{ + size_t rndup = nelems % X_ALIGN; +#line 3751 + +#line 3751 + if (rndup) +#line 3751 + rndup = X_ALIGN - rndup; +#line 3751 + +#line 3751 + (void) memcpy(tp, *xpp, (size_t)nelems); +#line 3751 + *xpp = (void *)((char *)(*xpp) + nelems + rndup); +#line 3751 + +#line 3751 + return NC_NOERR; +#line 3751 + +} + +int +ncx_putn_text(void **xpp, size_t nelems, const char *tp) +{ + (void) memcpy(*xpp, tp, (size_t)nelems); +#line 3757 + *xpp = (void *)((char *)(*xpp) + nelems); +#line 3757 + +#line 3757 + return NC_NOERR; +#line 3757 + +} + +int +ncx_pad_putn_text(void **xpp, size_t nelems, const char *tp) +{ + size_t rndup = nelems % X_ALIGN; +#line 3763 + +#line 3763 + if (rndup) +#line 3763 + rndup = X_ALIGN - rndup; +#line 3763 + +#line 3763 + (void) memcpy(*xpp, tp, (size_t)nelems); +#line 3763 + *xpp = (void *)((char *)(*xpp) + nelems); +#line 3763 + +#line 3763 + if (rndup) +#line 3763 + { +#line 3763 + (void) memcpy(*xpp, nada, (size_t)rndup); +#line 3763 + *xpp = (void *)((char *)(*xpp) + rndup); +#line 3763 + } +#line 3763 + +#line 3763 + return NC_NOERR; +#line 3763 + +} + + +/* opaque */ + +int +ncx_getn_void(const void **xpp, size_t nelems, void *tp) +{ + (void) memcpy(tp, *xpp, (size_t)nelems); +#line 3772 + *xpp = (void *)((char *)(*xpp) + nelems); +#line 3772 + return NC_NOERR; +#line 3772 + +} + +int +ncx_pad_getn_void(const void **xpp, size_t nelems, void *tp) +{ + size_t rndup = nelems % X_ALIGN; +#line 3778 + +#line 3778 + if (rndup) +#line 3778 + rndup = X_ALIGN - rndup; +#line 3778 + +#line 3778 + (void) memcpy(tp, *xpp, (size_t)nelems); +#line 3778 + *xpp = (void *)((char *)(*xpp) + nelems + rndup); +#line 3778 + +#line 3778 + return NC_NOERR; +#line 3778 + +} + +int +ncx_putn_void(void **xpp, size_t nelems, const void *tp) +{ + (void) memcpy(*xpp, tp, (size_t)nelems); +#line 3784 + *xpp = (void *)((char *)(*xpp) + nelems); +#line 3784 + +#line 3784 + return NC_NOERR; +#line 3784 + +} + +int +ncx_pad_putn_void(void **xpp, size_t nelems, const void *tp) +{ + size_t rndup = nelems % X_ALIGN; +#line 3790 + +#line 3790 + if (rndup) +#line 3790 + rndup = X_ALIGN - rndup; +#line 3790 + +#line 3790 + (void) memcpy(*xpp, tp, (size_t)nelems); +#line 3790 + *xpp = (void *)((char *)(*xpp) + nelems); +#line 3790 + +#line 3790 + if (rndup) +#line 3790 + { +#line 3790 + (void) memcpy(*xpp, nada, (size_t)rndup); +#line 3790 + *xpp = (void *)((char *)(*xpp) + rndup); +#line 3790 + } +#line 3790 + +#line 3790 + return NC_NOERR; +#line 3790 + +} diff --git a/libsrc/netcdf.3 b/libsrc/netcdf.3 new file mode 100644 index 0000000000..8b217f409a --- /dev/null +++ b/libsrc/netcdf.3 @@ -0,0 +1,1387 @@ +.nr yr \n(yr+1900 +.af mo 01 +.af dy 01 +.TH NETCDF 3 "1997-04-18" "Printed: \n(yr-\n(mo-\n(dy" "UNIDATA LIBRARY FUNCTIONS" +.SH NAME +netcdf \- Unidata's Network Common Data Form (netCDF) library interface +.SH SYNOPSIS +.ft B +.na +.nh +#include "netcdf.h" +.sp + +cc ... \-lnetcdf \-lhdf5_hl \-lhdf5 \-lz \-lm + +.ad +.hy +Complete documentation for the netCDF libraries can be found at the netCDF website: https://www.unidata.ucar.edu/software/netcdf/. +.sp +.SH "LIBRARY VERSION" +.LP +This document describes versions 3 and 4 +of Unidata netCDF data-access interface +for the C programming language. +.HP +\fBconst char* nc_inq_libvers()\fR +.sp +Returns a string identifying the version of the netCDF library, and +when it was built, like: "3.1a of Aug 22 1996 12:57:47 $". +.LP +The RCS \fBident(1)\fP command will find a string like +"$\|Id: @\|(#) netcdf library version 3.1a of Sep 6 1996 15:56:26 $" +in the library. The SCCS \fBwhat(1)\fP command will find a string like +"netcdf library version 3.1a of Aug 23 1996 16:07:40 $". +.SH "RETURN VALUES" +.LP +All netCDF functions (except +\fBnc_inq_libvers(\|)\fR and \fBnc_strerror(\|)\fR) return an integer status. + +If this returned status value is not equal to +\fBNC_NOERR\fR (zero), it +indicates that an error occurred. The possible status values are defined in +system include file and in "netcdf.h". +.HP +\fBconst char* nc_strerror(int \fIstatus\fP)\fR +.sp +Returns a string textual translation of the \fIstatus\fP +value, like "Attribute or variable name contains illegal characters" +or "No such file or directory". +.sp +.SH "FILE OPERATIONS" +.LP +.HP +\fBint nc_create(const char \fIpath\fP[], int \fIcmode\fP, int* \fIncid\fP)\fR +.sp +Creates a new netCDF dataset at \fIpath\fP, +returning a netCDF ID in \fIncid\fP. +The argument \fIcmode\fP may include the bitwise-or +of the following flags: +\fBNC_NOCLOBBER\fR +to protect existing datasets (default +silently blows them away), +\fBNC_SHARE\fR +for synchronous dataset updates for classic format files +(default is to buffer accesses), +.sp +When a netCDF dataset is created, is is opened +\fBNC_WRITE\fR. +The new netCDF dataset is in define mode. +\fBNC_64BIT_OFFSET\fR. +to create a file in the 64-bit offset format +(as opposed to classic format, the default). +\fBNC_TRUE\fR to create a netCDF-4/HDF5 file, +and \fBNC_CLASSIC_MODEL\fR to guarantee that netCDF-4/HDF5 files maintain compatibility +with the netCDF classic data model. +.HP +\fBint nc__create(const char \fIpath\fP[], int \fIcmode\fP, size_t \fIinitialsize\fP, size_t* \fIchunksize\fP, int* \fIncid\fP)\fR +.sp +Like \fBnc_create(\|)\fR but has additional performance tuning parameters. +.sp +The argument \fIinitialsize\fP sets the initial size of the file at +creation time. +.sp +See \fBnc__open(\|)\fR below for an explanation of the \fIchunksize\fP +parameter. +.HP +\fBint nc_open(const char \fIpath\fP[], int \fImode\fP, int* \fIncid\fP)\fR +.sp +(Corresponds to \fBncopen(\|)\fR in version 2) +.sp +Opens a existing netCDF dataset at \fIpath\fP +returning a netCDF ID +in \fIncid\fP. +The type of access is described by the \fImode\fP parameter, +which may include the bitwise-or +of the following flags: +\fBNC_WRITE\fR +for read-write access (default +read-only), +\fBNC_SHARE\fR +for synchronous dataset updates (default is +to buffer accesses), and +\fBNC_LOCK\fR +(not yet implemented). +.sp +As of NetCDF version 4.1, and if TRUE support was enabled +when the NetCDF library was built, the path parameter +may specify a TRUE URL. In this case, the access mode is +forced to be read-only. +.HP +\fBint nc__open(const char \fIpath\fP[], int \fImode\fP, size_t* \fIchunksize\fP, int* \fIncid\fP)\fR +.sp +Like \fBnc_open(\|)\fR but has an additional performance tuning parameter. +.sp +The argument referenced by \fIchunksize\fP controls a space versus time +tradeoff, memory allocated in the netcdf library versus number of system +calls. +Because of internal requirements, the value may not be set to exactly +the value requested. +The actual value chosen is returned by reference. +Using the value \fBNC_SIZEHINT_DEFAULT\fR causes the library to choose a +default. +How the system choses the default depends on the system. +On many systems, the "preferred I/O block size" is available from the +\fBstat()\fR system call, \fBstruct stat\fR member \fBst_blksize\fR. +If this is available it is used. Lacking that, twice the system pagesize +is used. +Lacking a call to discover the system pagesize, we just set default +chunksize to 8192. +.sp +The chunksize is a property of a given open netcdf descriptor +\fIncid\fP, it is not a persistent property of the netcdf dataset. +.sp +As with \fBnc__open(\|)\fR, the path parameter +may specify a TRUE URL, but the tuning parameters are ignored. +.HP +\fBint nc_redef(int \fIncid\fP)\fR +.sp +(Corresponds to \fBncredef(\|)\fR in version 2) +.sp +Puts an open netCDF dataset into define mode, +so dimensions, variables, and attributes can be added or renamed and +attributes can be deleted. +.HP +\fBint nc_enddef(int \fIncid\fP)\fR +.sp +(Corresponds to \fBncendef(\|)\fR in version 2) +.sp +Takes an open netCDF dataset out of define mode. +The changes made to the netCDF dataset +while it was in define mode are checked and committed to disk if no +problems occurred. Some data values may be written as well, +see "VARIABLE PREFILLING" below. +After a successful call, variable data can be read or written to the dataset. +.HP +\fBint nc__enddef(int \fIncid\fP, size_t \fIh_minfree\fP, size_t \fIv_align\fP, size_t \fIv_minfree\fP, size_t \fIr_align\fP)\fR +.sp +Like \fBnc_enddef(\|)\fR but has additional performance tuning parameters. +.sp +Caution: this function exposes internals of the netcdf version 1 file +format. +It may not be available on future netcdf implementations. +.sp +The current netcdf file format has three sections, +the "header" section, the data section for fixed size variables, and +the data section for variables which have an unlimited dimension (record +variables). +The header begins at the beginning of the file. The index +(offset) of the beginning of the other two sections is contained in the +header. Typically, there is no space between the sections. This causes +copying overhead to accrue if one wishes to change the size of the +sections, +as may happen when changing names of things, text attribute values, +adding +attributes or adding variables. Also, for buffered i/o, there may be +advantages +to aligning sections in certain ways. +.sp +The minfree parameters allow one to control costs of future calls +to \fBnc_redef(\|)\fR, \fBnc_enddef(\|)\fR by requesting that \fIminfree\fP bytes be +available at the end of the section. +The \fIh_minfree\fP parameter sets the pad +at the end of the "header" section. The \fIv_minfree\fP parameter sets +the pad at the end of the data section for fixed size variables. +.sp +The align parameters allow one to set the alignment of the beginning of +the corresponding sections. The beginning of the section is rounded up +to an index which is a multiple of the align parameter. The flag value +\fBNC_ALIGN_CHUNK\fR tells the library to use the chunksize (see above) +as the align parameter. +The \fIv_align\fP parameter controls the alignment of the beginning of +the data section for fixed size variables. +The \fIr_align\fP parameter controls the alignment of the beginning of +the data section for variables which have an unlimited dimension (record +variables). +.sp +The file format requires mod 4 alignment, so the align parameters +are silently rounded up to multiples of 4. The usual call, +\fBnc_enddef(\fIncid\fP)\fR +is equivalent to +\fBnc__enddef(\fIncid\fP, 0, 4, 0, 4)\fR. +.sp +The file format does not contain a "record size" value, this is +calculated from the sizes of the record variables. This unfortunate fact +prevents us from providing minfree and alignment control of the +"records" +in a netcdf file. If you add a variable which has an unlimited +dimension, +the third section will always be copied with the new variable added. +.HP +\fBint nc_sync(int \fIncid\fP)\fR +.sp +(Corresponds to \fBncsync(\|)\fR in version 2) +.sp +Unless the +\fBNC_SHARE\fR +bit is set in +\fBnc_open(\|)\fR or \fBnc_create(\|)\fR, +accesses to the underlying netCDF dataset are +buffered by the library. This function synchronizes the state of +the underlying dataset and the library. +This is done automatically by +\fBnc_close(\|)\fR and \fBnc_enddef(\|)\fR. +.HP +\fBint nc_abort(int \fIncid\fP)\fR +.sp +(Corresponds to \fBncabort(\|)\fR in version 2) +.sp +You don't need to call this function. +This function is called automatically by +\fBnc_close(\|)\fR +if the netCDF was in define mode and something goes wrong with the commit. +If the netCDF dataset isn't in define mode, then this function is equivalent to +\fBnc_close(\|)\fR. +If it is called after +\fBnc_redef(\|)\fR, +but before +\fBnc_enddef(\|)\fR, +the new definitions are not committed and the dataset is closed. +If it is called after +\fBnc_create(\|)\fR +but before +\fBnc_enddef(\|)\fR, +the dataset disappears. +.HP +\fBint nc_close(int \fIncid\fP)\fR +.sp +(Corresponds to +\fBncclose(\|)\fR in version 2) +.sp +Closes an open netCDF dataset. +If the dataset is in define mode, +\fBnc_enddef(\|)\fR +will be called before closing. +After a dataset is closed, its ID may be reassigned to another dataset. +.HP +\fBint nc_inq(int \fIncid\fP, int* \fIndims\fP, int* \fInvars\fP, +int* \fInatts\fP, int* \fIunlimdimid\fP)\fR +.HP +\fBint nc_inq_ndims(int \fIncid\fP, int* \fIndims\fP)\fR +.HP +\fBint nc_inq_nvars(int \fIncid\fP, int* \fInvars\fP)\fR +.HP +\fBint nc_inq_natts(int \fIncid\fP, int* \fInatts\fP)\fR +.HP +\fBint nc_inq_unlimdim(int \fIncid\fP, int* \fIunlimdimid\fP)\fR +.HP +\fBint nc_inq_format(int \fIncid\fP, int* \fIformatn\fP)\fR +.sp +Use these functions to find out what is in a netCDF dataset. +Upon successful return, +\fIndims\fP will contain the +number of dimensions defined for this netCDF dataset, +\fInvars\fP will contain the number of variables, +\fInatts\fP will contain the number of attributes, and +\fIunlimdimid\fP will contain the +dimension ID of the unlimited dimension if one exists, or +\-1 otherwise. +\fIformatn\fP will contain the version number of the dataset , one of +\fBNC_FORMAT_CLASSIC\fR, \fBNC_FORMAT_64BIT_OFFSET\fR, \fBNC_FORMAT_NETCDF4\fR, or +\fBNC_FORMAT_NETCDF4_CLASSIC\fR. +If any of the +return parameters is a \fBNULL\fR pointer, then the corresponding information +will not be returned; hence, no space need be allocated for it. +.HP +\fBint nc_def_dim(int \fIncid\fP, const char \fIname\fP[], size_t \fIlen\fP, int* \fIdimid\fP)\fR +.sp +(Corresponds to \fBncdimdef(\|)\fR in version 2) +.sp +Adds a new dimension to an open netCDF dataset, which must be +in define mode. +\fIname\fP is the dimension name. +If \fIdimid\fP is not a \fBNULL\fR pointer then upon successful completion \fIdimid\fP will contain the dimension ID of the newly created dimension. + +.SH "USER DEFINED TYPES" +.LP +Users many define types for a netCDF-4/HDF5 file (unless the +\fBNC_CLASSIC_MODEL\fR was used when the file was creates). Users may +define compound types, variable length arrays, enumeration types, and +opaque types. +.sp + +.HP +\fBint nc_def_compound(int \fIncid\fP, size_t \fIsize\fP, const char \fIname\fP[], int* \fItypeidp\fP)\fR +.sp +Define a compound type. +.HP +\fBint nc_insert_compound(int \fIncid\fP, nc_type \fI\fP, const char \fIname\fP[], size_t \fIoffset\fP, nc_type \fIfield_typeid\fP)\fR +.sp +Insert an element into a compound type. May not be done after type has been used, or after the type has been written by an enddef. +.HP +\fBint nc_insert_array_compound(int \fIncid\fP, nc_type \fI\fP, const char \fIname\fP[], size_t \fIoffset\fP, nc_type \fIfield_typeid\fP, int \fIndims\fP, const int \fIdim_sizes\fP[])\fR +.sp +Insert an array into a compound type. +.HP +\fBint nc_inq_type(int \fIncid\fP, nc_type \fI\fP, char \fIname\fP[], size_t* \fIsizep\fP)\fR +.sp +Learn about a type. +.HP +\fBint nc_inq_compound(int \fIncid\fP, nc_type \fI\fP, char \fIname\fP[], size_t* \fIsizep\fP, size_t* \fInfieldsp\fP)\fR +.HP +\fBint nc_inq_compound_name(int \fIncid\fP, nc_type \fI\fP, char \fIname\fP[])\fR +.HP +\fBint nc_inq_compound_size(int \fIncid\fP, nc_type \fI\fP, size_t* \fIsizep\fP)\fR +.HP +\fBint nc_inq_compound_nfields(int \fIncid\fP, nc_type \fI\fP, size_t* \fInfieldsp\fP)\fR +.HP +\fBint nc_inq_compound_fieldname(int \fIncid\fP, nc_type \fI\fP, int \fIfieldid\fP, char \fIname\fP[])\fR +.HP +\fBint nc_inq_compound_fieldindex(int \fIncid\fP, nc_type \fI\fP, const char \fIname\fP[], int* \fIfieldidp\fP)\fR +.HP +\fBint nc_inq_compound_fieldoffset(int \fIncid\fP, nc_type \fI\fP, int \fIfieldid\fP, size_t* \fIoffsetp\fP)\fR +.HP +\fBint nc_inq_compound_fieldtype(int \fIncid\fP, nc_type \fI\fP, int \fIfieldid\fP, nc_type* \fIfield_typeid\fP)\fR +.HP +\fBint nc_inq_compound_fieldndims(int \fIncid\fP, nc_type \fI\fP, int \fIfieldid\fP, int* \fIndims\fP)\fR +.HP +\fBint nc_inq_compound_fielddim_sizes(int \fIncid\fP, nc_type \fI\fP, int \fIfieldid\fP, int \fIdim_sizes\fP[])\fR +.sp +Learn about a compound type. +.HP +\fBint nc_def_vlen(int \fIncid\fP, const char \fIname\fP[], nc_type \fIbase_typeid\fP, nc_type* \fIxtypep\fP)\fR +.sp +Create a variable length array type. +.HP +\fBint nc_inq_vlen(int \fIncid\fP, nc_type \fI\fP, char \fIname\fP[], size_t* \fIdatum_sizep\fP, nc_type* \fIbase_nc_typep\fP)\fR +.sp +Learn about a variable length array type. +.HP +\fBint nc_free_vlen(nc_vlen_t *vl)\fR +.sp +Free memory consumed by reading data of a variable length array type. +.HP +\fBint nc_put_vlen_element(int \fIncid\fP, nc_type \fI\fP, void * \fIvlen_element\fP, size_t \fIlen\fP, void * \fIdata\fP)\fR +.sp +Write one VLEN. +.HP +\fBint nc_get_vlen_element(int \fIncid\fP, nc_type \fI\fP, void ** \fIvlen_element\fP, size_t \fIlen\fP, void ** \fIdata\fP)\fR +.sp +Read one VLEN. +.HP +\fBint nc_free_string(size_t \fIlen\fP, char **data)\fR +.sp +Free memory consumed by reading data of a string type. +.HP +\fBint nc_inq_user_type(int \fIncid\fP, nc_type \fI\fP, char \fIname\fP[], size_t* \fI\fP, nc_type* \fI\fP, size_t* \fI\fP, int* \fI\fP)\fR +.sp +Learn about a user define type. +.HP +\fBint nc_def_enum(int \fIncid\fP, nc_type \fIbase_typeid\fP, const char \fIname\fP[], nc_type* \fItypeidp\fP)\fR +.sp +Define an enumeration type. +.HP +\fBint nc_insert_enum(int \fIncid\fP, nc_type \fIbase_typeid\fP, const char \fIname\fP[], const void *value)\fR +.sp +Insert a name-value pair into enumeration type. +.HP +\fBint nc_inq_enum_member(int \fIncid\fP, nc_type \fIxtype\fP, int \fIidx\fP, char \fIname\fP[], void *value)\fR +.HP +\fBint nc_inq_enum_ident(int \fIncid\fP, nc_type \fIxtype\fP, int \fIidx\fP, long long \fIvalue\fP, char \fIidentifier\fP[])\fR +.sp +Learn about a name-value pair into enumeration type. +.HP +\fBint nc_def_opaque(int \fIncid\fP, size_t \fIsize\fP, const char \fIname\fP[], nc_type* \fIxtypep\fP)\fR +.sp +Create an opaque type. +.HP +\fBint nc_inq_opaque(int \fIncid\fP, nc_type \fIxtype\fP, char \fIname\fP[], size_t* \fIsizep\fP)\fR +.sp +Learn about opaque type. +.HP +.SH "GROUPS" +.sp +Users may organize data into hierarchical groups in netCDF-4/HDF5 files (unless \fBNC_CLASSIC_MODEL\fR was used when creating the file). +.HP +\fBint nc_inq_grps(int \fIncid\fP, int* \fInumgrps\fP, int \fIncids\fP[])\fR +.sp +Learn how many groups (and their ncids) are available from the group represented by ncid. +.HP +\fBint nc_inq_grpname(int \fIncid\fP, char \fIname\fP[])\fR +.HP +\fBint nc_inq_grpname_full(int \fIncid\fP, size_t* \fIlen\fP, char \fIname\fP[])\fR +.HP +\fBint nc_inq_grpname_len(int \fIncid\fP, size_t* \fIlen\fP)\fR +.HP +\fBint nc_inq_grp_parent(int \fIncid\fP, int* \fIncid\fP)\fR +.HP +\fBint nc_inq_grp_ncid(int \fIncid\fP, char \fIname\fP[], int* \fIncid\fP)\fR +.HP +\fBint nc_inq_full_ncid(int \fIncid\fP, char \fIname\fP[], int* \fIncid\fP)\fR +.sp +Learn about a group. +.HP +\fBint nc_inq_varids(int \fIncid\fP, int* \fInvars\fP, int* \fI\fP)\fR +.sp +Get the varids in a group. +.HP +\fBint nc_inq_dimids(int \fIncid\fP, int* \fIndims\fP, int* \fIdimids\fP, int \fIinclude_parents\fP)\fR +.sp +Get the dimids in a group and (potentially) its parents. +.HP +\fBint nc_inq_typeids(int \fIncid\fP, int* \fIntypes\fP, int \fItypeids\fP[])\fR +.sp +Get the typeids of user-defined types in a group. +.HP +\fBint nc_def_grp(int \fIncid\fP, char \fIname\fP[], int* \fIncid\fP)\fR +.sp +Create a group. +.LP + +.SH "DIMENSIONS" +.LP +.HP +\fBint nc_inq_dimid(int \fIncid\fP, const char \fIname\fP[], int* \fIdimid\fP)\fR +.sp +(Corresponds to \fBncdimid(\|)\fR in version 2) +.sp +Given a dimension name, returns the ID of a netCDF dimension in \fIdimid\fP. +.HP +\fBint nc_inq_dim(int \fIncid\fP, int \fIdimid\fP, char \fIname\fP[], size_t* \fIlen\fP)\fR +.HP +\fBint nc_inq_dimname(int \fIncid\fP, int \fIdimid\fP, char \fIname\fP[])\fR +.HP +\fBint nc_inq_dimlen(int \fIncid\fP, int \fIdimid\fP, size_t* \fIlen\fP)\fR +.sp +Use these functions to find out about a dimension. +If either the \fIname\fP +argument or \fIlen\fP argument is a \fBNULL\fR pointer, then +the associated information will not be returned. Otherwise, +\fIname\fP should be big enough (\fBNC_MAX_NAME\fR) +to hold the dimension name as the name will be copied into your storage. +The length return parameter, \fIlen\fP +will contain the size of the dimension. +For the unlimited dimension, the returned length is the current +maximum value used for writing into any of the variables which use +the dimension. +.HP +\fBint nc_rename_dim(int \fIncid\fP, int \fIdimid\fP, const char \fIname\fP[])\fR +.sp +(Corresponds to \fBncdimrename(\|)\fR in version 2) +.sp +Renames an existing dimension in an open netCDF dataset. +If the new name is longer than the old name, the netCDF dataset must be in +define mode. +You cannot rename a dimension to have the same name as another dimension. +.SH "VARIABLES" +.LP +.HP +\fBint nc_def_var(int \fIncid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, int \fIndims\fP, const int \fIdimids\fP[], int* \fIvarid\fP)\fR +.sp +(Corresponds to \fBncvardef(\|)\fR in version 2) +.sp +Adds a new variable to a netCDF dataset. The netCDF must be in define mode. +If not \fBNULL\fR, then \fIvarid\fP will be set to the netCDF variable ID. +.HP +\fBint nc_inq_varid(int \fIncid\fP, const char \fIname\fP[], int* \fIvarid\fP)\fR +.sp +(Corresponds to \fBncvarid(\|)\fR in version 2) +.sp +Returns the ID of a netCDF variable in \fIvarid\fP given its name. +.HP +\fBint nc_inq_var(int \fIncid\fP, int \fIvarid\fP, char \fIname\fP[], nc_type* \fIxtype\fP, int* \fIndims\fP, int \fIdimids\fP[], +int* \fInatts\fP)\fR +.HP +\fBint nc_inq_varname(int \fIncid\fP, int \fIvarid\fP, char \fIname\fP[])\fR +.HP +\fBint nc_inq_vartype(int \fIncid\fP, int \fIvarid\fP, nc_type* \fIxtype\fP)\fR +.HP +\fBint nc_inq_varndims(int \fIncid\fP, int \fIvarid\fP, int* \fIndims\fP)\fR +.HP +\fBint nc_inq_vardimid(int \fIncid\fP, int \fIvarid\fP, int \fIdimids\fP[])\fR +.HP +\fBint nc_inq_varnatts(int \fIncid\fP, int \fIvarid\fP, int* \fInatts\fP)\fR +.sp +Returns information about a netCDF variable, given its ID. +If any of the +return parameters (\fIname\fP, \fIxtype\fP, \fIndims\fP, \fIdimids\fP, or +\fInatts\fP) is a \fBNULL\fR pointer, then the corresponding information +will not be returned; hence, no space need be allocated for it. +.HP +\fBint nc_rename_var(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[])\fR +.sp +(Corresponds to \fBncvarrename(\|)\fR in version 2) +.sp +Changes the name of a netCDF variable. +If the new name is longer than the old name, the netCDF must be in define mode. +You cannot rename a variable to have the name of any existing variable. + +.SH "VARIABLES \fIin\fP NETCDF-4 FILES" +.LP +The following functions may only be used on variables in a +netCDF-4/HDF5 data file. These functions must be called after the +variable is defined, but before an enddef call. +.sp +\fBint nc_def_var_deflate(int \fIncid\fP, int \fIvarid\fP, int \fIshuffle\fP, int \fIdeflate\fP, int \fIdeflate_level\fP)\fR +.sp +Turn on compression and/or shuffle filter. (Shuffle filter is only useful for integer data.) +.HP +\fBint nc_inq_var_deflate(int \fIncid\fP, int \fIvarid\fP, int* \fIshufflep\fP, int* \fIdeflatep\fP, int* \fIdeflate_levelp\fP)\fR +.sp +Learn about a variable's deflate settings. +.HP +\fBint nc_def_var_fletcher32(int \fIncid\fP, int \fIvarid\fP, int \fIfletcher32\fP)\fR +.sp +Turn on checksumming for a variable. +.HP +\fBint nc_inq_var_fletcher32(int \fIncid\fP, int \fIvarid\fP, int* \fIfletcher32\fP)\fR +.sp +Learn about checksumming for a variable. +.HP +\fBint nc_def_var_chunking(int \fIncid\fP, int \fIvarid\fP, int \fIstorage\fP, const size_t \fIchunksizesp\fP[])\fR +.sp +Set chunksizes for a variable. +.HP +\fBint nc_inq_var_chunking(int \fIncid\fP, int \fIvarid\fP, int* \fIstoragep\fP, size_t \fIchunksizesp\fP[])\fR +.sp +Learn about chunksizes for a variable. +.HP +\fBint nc_def_var_fill(int \fIncid\fP, int \fIvarid\fP, int \fIno_fill\fP, const size_t \fIchunksizesp\fP[])\fR +.sp +Set a fill value for a variable. +.HP +\fBint nc_inq_var_fill(int \fIncid\fP, int \fIvarid\fP, int* \fIstoragep\fP, size_t \fIchunksizesp\fP[])\fR +.sp +Learn the fill value for a variable. +.HP +\fBint nc_def_var_endian(int \fIncid\fP, int \fIvarid\fP, int \fIendian\fP)\fR +.sp +Set endianness of variable. +.HP +\fBint nc_inq_var_endian(int \fIncid\fP, int \fIvarid\fP, int* \fIendianp\fP)\fR +.sp +Learn the endianness of a variable. +.HP + +.SH "WRITING AND READING WHOLE VARIABLES" +.LP +.HP +\fBint nc_put_var_text(int \fIncid\fP, int \fIvarid\fP, const char \fIout\fP[])\fR +.HP +\fBint nc_put_var_uchar(int \fIncid\fP, int \fIvarid\fP, const unsigned char \fIout\fP[])\fR +.HP +\fBint nc_put_var_schar(int \fIncid\fP, int \fIvarid\fP, const signed char \fIout\fP[])\fR +.HP +\fBint nc_put_var_short(int \fIncid\fP, int \fIvarid\fP, const short \fIout\fP[])\fR +.HP +\fBint nc_put_var_int(int \fIncid\fP, int \fIvarid\fP, const int \fIout\fP[])\fR +.HP +\fBint nc_put_var_long(int \fIncid\fP, int \fIvarid\fP, const long \fIout\fP[])\fR +.HP +\fBint nc_put_var_float(int \fIncid\fP, int \fIvarid\fP, const float \fIout\fP[])\fR +.HP +\fBint nc_put_var_double(int \fIncid\fP, int \fIvarid\fP, const double \fIout\fP[])\fR +.HP +\fBint nc_put_var_ubyte(int \fIncid\fP, int \fIvarid\fP, const unsigned char \fIout\fP[])\fR +.HP +\fBint nc_put_var_ushort(int \fIncid\fP, int \fIvarid\fP, const unsigned short \fIout\fP[])\fR +.HP +\fBint nc_put_var_uint(int \fIncid\fP, int \fIvarid\fP, const unsigned int \fIout\fP[])\fR +.HP +\fBint nc_put_var_int64(int \fIncid\fP, int \fIvarid\fP, const long long \fIout\fP[])\fR +.HP +\fBint nc_put_var_uint64(int \fIncid\fP, int \fIvarid\fP, const unsigned long long \fIout\fP[])\fR +.HP +\fBint nc_put_var_string(int \fIncid\fP, int \fIvarid\fP, const char * \fIout\fP[])\fR + + +.sp +Writes an entire netCDF variable (i.e. all the values). The netCDF +dataset must be open and in data mode. The type of the data is +specified in the function name, and it is converted to the external +type of the specified variable, if possible, otherwise an +\fBNC_ERANGE\fR error is returned. Note that rounding is not performed +during the conversion. Floating point numbers are truncated when +converted to integers. +.HP +\fBint nc_get_var_text(int \fIncid\fP, int \fIvarid\fP, char \fIin\fP[])\fR +.HP +\fBint nc_get_var_uchar(int \fIncid\fP, int \fIvarid\fP, unsigned char \fIin\fP[])\fR +.HP +\fBint nc_get_var_schar(int \fIncid\fP, int \fIvarid\fP, signed char \fIin\fP[])\fR +.HP +\fBint nc_get_var_short(int \fIncid\fP, int \fIvarid\fP, short \fIin\fP[])\fR +.HP +\fBint nc_get_var_int(int \fIncid\fP, int \fIvarid\fP, int \fIin\fP[])\fR +.HP +\fBint nc_get_var_long(int \fIncid\fP, int \fIvarid\fP, long \fIin\fP[])\fR +.HP +\fBint nc_get_var_float(int \fIncid\fP, int \fIvarid\fP, float \fIin\fP[])\fR +.HP +\fBint nc_get_var_double(int \fIncid\fP, int \fIvarid\fP, double \fIin\fP[])\fR +.HP +\fBint nc_get_var_ubyte(int \fIncid\fP, int \fIvarid\fP, unsigned char \fIin\fP[])\fR +.HP +\fBint nc_get_var_ushort(int \fIncid\fP, int \fIvarid\fP, unsigned short \fIin\fP[])\fR +.HP +\fBint nc_get_var_uint(int \fIncid\fP, int \fIvarid\fP, unsigned int \fIin\fP[])\fR +.HP +\fBint nc_get_var_int64(int \fIncid\fP, int \fIvarid\fP, long long \fIin\fP[])\fR +.HP +\fBint nc_get_var_uint64(int \fIncid\fP, int \fIvarid\fP, unsigned long long \fIin\fP[])\fR +.HP +\fBint nc_get_var_string(int \fIncid\fP, int \fIvarid\fP, char * \fIin\fP[])\fR + + +.sp +Reads an entire netCDF variable (i.e. all the values). +The netCDF dataset must be open and in data mode. +The data is converted from the external type of the specified variable, +if necessary, to the type specified in the function name. If conversion is +not possible, an \fBNC_ERANGE\fR error is returned. +.SH "WRITING AND READING ONE DATUM" +.LP +.HP +\fBint nc_put_var1_text(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], char \fI*out\fP)\fR +.HP +\fBint nc_put_var1_uchar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], unsigned char \fI*out\fP)\fR +.HP +\fBint nc_put_var1_schar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], signed char \fI*out\fP)\fR +.HP +\fBint nc_put_var1_short(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], short \fI*out\fP)\fR +.HP +\fBint nc_put_var1_int(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], int \fI*out\fP)\fR +.HP +\fBint nc_put_var1_long(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], long \fI*out\fP)\fR +.HP +\fBint nc_put_var1_float(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], float \fI*out\fP)\fR +.HP +\fBint nc_put_var1_double(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], double \fI*out\fP)\fR +.HP +\fBint nc_put_var1_ubyte(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], unsigned char \fI*out\fP)\fR +.HP +\fBint nc_put_var1_ushort(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], unsigned short \fI*out\fP)\fR +.HP +\fBint nc_put_var1_uint(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], unsigned int \fI*out\fP)\fR +.HP +\fBint nc_put_var1_int64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], long long \fI*out\fP)\fR +.HP +\fBint nc_put_var1_uint64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], unsigned long long \fI*out\fP)\fR +.HP +\fBint nc_put_var1_string(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], char * \fI*out\fP)\fR + + +.sp +Puts a single data value into a variable at the position \fIindex\fP of an +open netCDF dataset that is in data mode. The type of the data is +specified in the function name, and it is converted to the external type +of the specified variable, if possible, otherwise an \fBNC_ERANGE\fR +error is returned. +.HP +\fBint nc_get_var1_text(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], char* \fIin\fP)\fR +.HP +\fBint nc_get_var1_uchar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], unsigned char* \fIin\fP)\fR +.HP +\fBint nc_get_var1_schar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], signed char* \fIin\fP)\fR +.HP +\fBint nc_get_var1_short(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], short* \fIin\fP)\fR +.HP +\fBint nc_get_var1_int(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], int* \fIin\fP)\fR +.HP +\fBint nc_get_var1_long(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], long* \fIin\fP)\fR +.HP +\fBint nc_get_var1_float(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], float* \fIin\fP)\fR +.HP +\fBint nc_get_var1_double(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], double* \fIin\fP)\fR +.HP +\fBint nc_get_var1_ubyte(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], unsigned char* \fIin\fP)\fR +.HP +\fBint nc_get_var1_ushort(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], unsigned short* \fIin\fP)\fR +.HP +\fBint nc_get_var1_uint(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], unsigned int* \fIin\fP)\fR +.HP +\fBint nc_get_var1_int64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], long long* \fIin\fP)\fR +.HP +\fBint nc_get_var1_uint64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], unsigned long long* \fIin\fP)\fR +.HP +\fBint nc_get_var1_string(int \fIncid\fP, int \fIvarid\fP, const size_t \fIindex\fP[], char ** \fIin\fP)\fR + + +.sp +Gets a single data value from a variable at the position \fIindex\fP +of an open netCDF dataset that is in data mode. +The data is converted from the external type of the specified variable, +if necessary, to the type specified in the function name. If conversion is +not possible, an \fBNC_ERANGE\fR error is returned. +.SH "WRITING AND READING AN ARRAY" +.LP +.HP +\fBint nc_put_vara_text(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const char \fIout\fP[])\fR +.HP +\fBint nc_put_vara_uchar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const unsigned char \fIout\fP[])\fR +.HP +\fBint nc_put_vara_schar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const signed char \fIout\fP[])\fR +.HP +\fBint nc_put_vara_short(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const short \fIout\fP[])\fR +.HP +\fBint nc_put_vara_int(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const int \fIout\fP[])\fR +.HP +\fBint nc_put_vara_long(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const long \fIout\fP[])\fR +.HP +\fBint nc_put_vara_float(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const float \fIout\fP[])\fR +.HP +\fBint nc_put_vara_double(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const double \fIout\fP[])\fR +.HP +\fBint nc_put_vara_ubyte(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const unsigned char \fIout\fP[])\fR +.HP +\fBint nc_put_vara_ushort(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const unsigned short \fIout\fP[])\fR +.HP +\fBint nc_put_vara_uint(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const unsigned int \fIout\fP[])\fR +.HP +\fBint nc_put_vara_int64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const long long \fIout\fP[])\fR +.HP +\fBint nc_put_vara_uint64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const unsigned long long \fIout\fP[])\fR +.HP +\fBint nc_put_vara_string(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const char * \fIout\fP[])\fR + + +.sp +Writes an array section of values into a netCDF variable of an open +netCDF dataset, which must be in data mode. The array section is specified +by the \fIstart\fP and \fIcount\fP vectors, which give the starting index +and count of values along each dimension of the specified variable. +The type of the data is +specified in the function name and is converted to the external type +of the specified variable, if possible, otherwise an \fBNC_ERANGE\fR +error is returned. +.HP +\fBint nc_get_vara_text(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], char \fIin\fP[])\fR +.HP +\fBint nc_get_vara_uchar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], unsigned char \fIin\fP[])\fR +.HP +\fBint nc_get_vara_schar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], signed char \fIin\fP[])\fR +.HP +\fBint nc_get_vara_short(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], short \fIin\fP[])\fR +.HP +\fBint nc_get_vara_int(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], int \fIin\fP[])\fR +.HP +\fBint nc_get_vara_long(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], long \fIin\fP[])\fR +.HP +\fBint nc_get_vara_float(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], float \fIin\fP[])\fR +.HP +\fBint nc_get_vara_double(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], double \fIin\fP[])\fR +.HP +\fBint nc_get_vara_ubyte(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], unsigned char \fIin\fP[])\fR +.HP +\fBint nc_get_vara_ushort(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], unsigned short \fIin\fP[])\fR +.HP +\fBint nc_get_vara_uint(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], unsigned int \fIin\fP[])\fR +.HP +\fBint nc_get_vara_int64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], long long \fIin\fP[])\fR +.HP +\fBint nc_get_vara_uint64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], unsigned long long \fIin\fP[])\fR +.HP +\fBint nc_get_vara_string(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], char * \fIin\fP[])\fR + + +.sp +Reads an array section of values from a netCDF variable of an open +netCDF dataset, which must be in data mode. The array section is specified +by the \fIstart\fP and \fIcount\fP vectors, which give the starting index +and count of values along each dimension of the specified variable. +The data is converted from the external type of the specified variable, +if necessary, to the type specified in the function name. If conversion is +not possible, an \fBNC_ERANGE\fR error is returned. +.SH "WRITING AND READING A SLICED ARRAY" +.LP +.HP +\fBint nc_put_vars_text(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], const char \fIout\fP[])\fR +.HP +\fBint nc_put_vars_uchar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], const unsigned char \fIout\fP[])\fR +.HP +\fBint nc_put_vars_schar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], const signed char \fIout\fP[])\fR +.HP +\fBint nc_put_vars_short(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], const short \fIout\fP[])\fR +.HP +\fBint nc_put_vars_int(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], const int \fIout\fP[])\fR +.HP +\fBint nc_put_vars_long(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], const long \fIout\fP[])\fR +.HP +\fBint nc_put_vars_float(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], const float \fIout\fP[])\fR +.HP +\fBint nc_put_vars_double(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], const double \fIout\fP[])\fR +.HP +\fBint nc_put_vars_ubyte(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], const unsigned char \fIout\fP[])\fR +.HP +\fBint nc_put_vars_ushort(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], const unsigned short \fIout\fP[])\fR +.HP +\fBint nc_put_vars_uint(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], const unsigned int \fIout\fP[])\fR +.HP +\fBint nc_put_vars_int64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], const long long \fIout\fP[])\fR +.HP +\fBint nc_put_vars_uint64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], const unsigned long long \fIout\fP[])\fR +.HP +\fBint nc_put_vars_string(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], const char * \fIout\fP[])\fR + + +.sp +These functions are used for \fIstrided output\fP, which is like the +array section output described above, except that +the sampling stride (the interval between accessed values) is +specified for each dimension. +For an explanation of the sampling stride +vector, see COMMON ARGUMENTS DESCRIPTIONS below. +.HP +\fBint nc_get_vars_text(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], char \fIin\fP[])\fR +.HP +\fBint nc_get_vars_uchar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], unsigned char \fIin\fP[])\fR +.HP +\fBint nc_get_vars_schar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], signed char \fIin\fP[])\fR +.HP +\fBint nc_get_vars_short(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], short \fIin\fP[])\fR +.HP +\fBint nc_get_vars_int(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], int \fIin\fP[])\fR +.HP +\fBint nc_get_vars_long(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], long \fIin\fP[])\fR +.HP +\fBint nc_get_vars_float(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], float \fIin\fP[])\fR +.HP +\fBint nc_get_vars_double(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], double \fIin\fP[])\fR +.HP +\fBint nc_get_vars_ubyte(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], unsigned char \fIin\fP[])\fR +.HP +\fBint nc_get_vars_ushort(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], unsigned short \fIin\fP[])\fR +.HP +\fBint nc_get_vars_uint(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], unsigned int \fIin\fP[])\fR +.HP +\fBint nc_get_vars_int64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], long long \fIin\fP[])\fR +.HP +\fBint nc_get_vars_uint64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], unsigned long long \fIin\fP[])\fR +.HP +\fBint nc_get_vars_string(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], char * \fIin\fP[])\fR + + +.sp +These functions are used for \fIstrided input\fP, which is like the +array section input described above, except that +the sampling stride (the interval between accessed values) is +specified for each dimension. +For an explanation of the sampling stride +vector, see COMMON ARGUMENTS DESCRIPTIONS below. +.SH "WRITING AND READING A MAPPED ARRAY" +.LP +.HP +\fBint nc_put_varm_text(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, const char \fIout\fP[])\fR +.HP +\fBint nc_put_varm_uchar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, const unsigned char \fIout\fP[])\fR +.HP +\fBint nc_put_varm_schar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, const signed char \fIout\fP[])\fR +.HP +\fBint nc_put_varm_short(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, const short \fIout\fP[])\fR +.HP +\fBint nc_put_varm_int(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, const int \fIout\fP[])\fR +.HP +\fBint nc_put_varm_long(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, const long \fIout\fP[])\fR +.HP +\fBint nc_put_varm_float(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, const float \fIout\fP[])\fR +.HP +\fBint nc_put_varm_double(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, const double \fIout\fP[])\fR +.HP +\fBint nc_put_varm_ubyte(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, const unsigned char \fIout\fP[])\fR +.HP +\fBint nc_put_varm_ushort(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, const unsigned short \fIout\fP[])\fR +.HP +\fBint nc_put_varm_uint(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, const unsigned int \fIout\fP[])\fR +.HP +\fBint nc_put_varm_int64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, const long long \fIout\fP[])\fR +.HP +\fBint nc_put_varm_uint64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, const unsigned long long \fIout\fP[])\fR +.HP +\fBint nc_put_varm_string(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, const char * \fIout\fP[])\fR + + +.sp +These functions are used for \fImapped output\fP, which is like +strided output described above, except that an additional index mapping +vector is provided to specify the in-memory arrangement of the data +values. +For an explanation of the index +mapping vector, see COMMON ARGUMENTS DESCRIPTIONS below. +.HP +\fBint nc_get_varm_text(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, char \fIin\fP[])\fR +.HP +\fBint nc_get_varm_uchar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, unsigned char \fIin\fP[])\fR +.HP +\fBint nc_get_varm_schar(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, signed char \fIin\fP[])\fR +.HP +\fBint nc_get_varm_short(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, short \fIin\fP[])\fR +.HP +\fBint nc_get_varm_int(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, int \fIin\fP[])\fR +.HP +\fBint nc_get_varm_long(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, long \fIin\fP[])\fR +.HP +\fBint nc_get_varm_float(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, float \fIin\fP[])\fR +.HP +\fBint nc_get_varm_double(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, double \fIin\fP[])\fR +.HP +\fBint nc_get_varm_ubyte(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, unsigned char \fIin\fP[])\fR +.HP +\fBint nc_get_varm_ushort(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, unsigned short \fIin\fP[])\fR +.HP +\fBint nc_get_varm_uint(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, unsigned int \fIin\fP[])\fR +.HP +\fBint nc_get_varm_int64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, long long \fIin\fP[])\fR +.HP +\fBint nc_get_varm_uint64(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, unsigned long long \fIin\fP[])\fR +.HP +\fBint nc_get_varm_string(int \fIncid\fP, int \fIvarid\fP, const size_t \fIstart\fP[], const size_t \fIcount\fP[], const size_t \fIstride\fP[], \fIimap\fP, char * \fIin\fP[])\fR + + +.sp +These functions are used for \fImapped input\fP, which is like +strided input described above, except that an additional index mapping +vector is provided to specify the in-memory arrangement of the data +values. +For an explanation of the index +mapping vector, see COMMON ARGUMENTS DESCRIPTIONS below. +.SH "ATTRIBUTES" +.LP +.HP +\fBint nc_put_att_text(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, size_t \fIlen\fP, const char \fIout\fP[])\fR +.HP +\fBint nc_put_att_uchar(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, size_t \fIlen\fP, const unsigned char \fIout\fP[])\fR +.HP +\fBint nc_put_att_schar(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, size_t \fIlen\fP, const signed char \fIout\fP[])\fR +.HP +\fBint nc_put_att_short(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, size_t \fIlen\fP, const short \fIout\fP[])\fR +.HP +\fBint nc_put_att_int(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, size_t \fIlen\fP, const int \fIout\fP[])\fR +.HP +\fBint nc_put_att_long(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, size_t \fIlen\fP, const long \fIout\fP[])\fR +.HP +\fBint nc_put_att_float(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, size_t \fIlen\fP, const float \fIout\fP[])\fR +.HP +\fBint nc_put_att_double(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, size_t \fIlen\fP, const double \fIout\fP[])\fR +.HP +\fBint nc_put_att_ubyte(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, size_t \fIlen\fP, const unsigned char \fIout\fP[])\fR +.HP +\fBint nc_put_att_ushort(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, size_t \fIlen\fP, const unsigned short \fIout\fP[])\fR +.HP +\fBint nc_put_att_uint(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, size_t \fIlen\fP, const unsigned int \fIout\fP[])\fR +.HP +\fBint nc_put_att_int64(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, size_t \fIlen\fP, const long long \fIout\fP[])\fR +.HP +\fBint nc_put_att_uint64(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, size_t \fIlen\fP, const unsigned long long \fIout\fP[])\fR +.HP +\fBint nc_put_att_string(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, size_t \fIlen\fP, const char * \fIout\fP[])\fR + + +.HP +\fBint nc_put_att(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type \fIxtype\fP, size_t \fIlen\fP, void * \fIip\fP)\fR +.HP +\fBint nc_get_att(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], void ** \fIip\fP)\fR +.sp +Unlike variables, attributes do not have +separate functions for defining and writing values. +This family of functions defines a new attribute with a value or changes +the value of an existing attribute. +If the attribute is new, or if the space required to +store the attribute value is greater than before, +the netCDF dataset must be in define mode. +The parameter \fIlen\fP is the number of values from \fIout\fP to transfer. +It is often one, except that for +\fBnc_put_att_text(\|)\fR it will usually be +\fBstrlen(\fIout\fP)\fR. +.sp +For these functions, the type component of the function name refers to +the in-memory type of the value, whereas the \fIxtype\fP argument refers to the +external type for storing the value. An \fBNC_ERANGE\fR +error results if +a conversion between these types is not possible. In this case the value +is represented with the appropriate fill-value for the associated +external type. +.HP +\fBint nc_inq_attname(int \fIncid\fP, int \fIvarid\fP, int \fIattnum\fP, char \fIname\fP[])\fR +.sp +Gets the +name of an attribute, given its variable ID and attribute number. +This function is useful in generic applications that +need to get the names of all the attributes associated with a variable, +since attributes are accessed by name rather than number in all other +attribute functions. The number of an attribute is more volatile than +the name, since it can change when other attributes of the same variable +are deleted. The attributes for each variable are numbered +from 0 (the first attribute) to +\fInvatts\fP-1, +where \fInvatts\fP is +the number of attributes for the variable, as returned from a call to +\fBnc_inq_varnatts(\|)\fR. +If the \fIname\fP parameter is a \fBNULL\fR pointer, no name will be +returned and no space need be allocated. +.HP +\fBint nc_inq_att(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type* \fIxtype\fP, size_t* \fIlen\fP)\fR +.HP +\fBint nc_inq_attid(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], int* \fIattnum\fP)\fR +.HP +\fBint nc_inq_atttype(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], nc_type* \fIxtype\fP)\fR +.HP +\fBint nc_inq_attlen(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], size_t* \fIlen\fP)\fR +.sp +These functions return information about a netCDF attribute, +given its variable ID and name. The information returned is the +external type in \fIxtype\fP +and the number of elements in the attribute as \fIlen\fP. +If any of the return arguments is a \fBNULL\fR pointer, +the specified information will not be returned. +.HP +\fBint nc_copy_att(int \fIncid\fP, int \fIvarid_in\fP, const char \fIname\fP[], int \fIncid_out\fP, int \fIvarid_out\fP)\fR +.sp +Copies an +attribute from one netCDF dataset to another. It can also be used to +copy an attribute from one variable to another within the same netCDF. +\fIncid_in\fP is the netCDF ID of an input netCDF dataset from which the +attribute will be copied. +\fIvarid_in\fP +is the ID of the variable in the input netCDF dataset from which the +attribute will be copied, or \fBNC_GLOBAL\fR +for a global attribute. +\fIname\fP +is the name of the attribute in the input netCDF dataset to be copied. +\fIncid_out\fP +is the netCDF ID of the output netCDF dataset to which the attribute will be +copied. +It is permissible for the input and output netCDF ID's to be the same. The +output netCDF dataset should be in define mode if the attribute to be +copied does not already exist for the target variable, or if it would +cause an existing target attribute to grow. +\fIvarid_out\fP +is the ID of the variable in the output netCDF dataset to which the attribute will +be copied, or \fBNC_GLOBAL\fR to copy to a global attribute. +.HP +\fBint nc_rename_att(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], const char \fInewname\fP[])\fR +.sp +Changes the +name of an attribute. If the new name is longer than the original name, +the netCDF must be in define mode. You cannot rename an attribute to +have the same name as another attribute of the same variable. +\fIname\fP is the original attribute name. +\fInewname\fP +is the new name to be assigned to the specified attribute. If the new name +is longer than the old name, the netCDF dataset must be in define mode. +.HP +\fBint nc_del_att(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[])\fR +.sp +Deletes an attribute from a netCDF dataset. The dataset must be in +define mode. +.HP +\fBint nc_get_att_text(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], char \fIin\fP[])\fR +.HP +\fBint nc_get_att_uchar(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], unsigned char \fIin\fP[])\fR +.HP +\fBint nc_get_att_schar(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], signed char \fIin\fP[])\fR +.HP +\fBint nc_get_att_short(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], short \fIin\fP[])\fR +.HP +\fBint nc_get_att_int(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], int \fIin\fP[])\fR +.HP +\fBint nc_get_att_long(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], long \fIin\fP[])\fR +.HP +\fBint nc_get_att_float(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], float \fIin\fP[])\fR +.HP +\fBint nc_get_att_double(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], double \fIin\fP[])\fR +.HP +\fBint nc_get_att_ubyte(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], unsigned char \fIin\fP[])\fR +.HP +\fBint nc_get_att_ushort(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], unsigned short \fIin\fP[])\fR +.HP +\fBint nc_get_att_uint(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], unsigned int \fIin\fP[])\fR +.HP +\fBint nc_get_att_int64(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], long long \fIin\fP[])\fR +.HP +\fBint nc_get_att_uint64(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], unsigned long long \fIin\fP[])\fR +.HP +\fBint nc_get_att_string(int \fIncid\fP, int \fIvarid\fP, const char \fIname\fP[], char * \fIin\fP[])\fR + + +.sp +Gets the value(s) of a netCDF attribute, given its +variable ID and name. Converts from the external type to the type +specified in +the function name, if possible, otherwise returns an \fBNC_ERANGE\fR +error. +All elements of the vector of attribute +values are returned, so you must allocate enough space to hold +them. If you don't know how much space to reserve, call +\fBnc_inq_attlen(\|)\fR +first to find out the length of the attribute. +.SH "COMMON ARGUMENT DESCRIPTIONS" +.LP +In this section we define some common arguments which are used in the +"FUNCTION DESCRIPTIONS" section. +.TP +int \fIncid\fP +is the netCDF ID returned from a previous, successful call to +\fBnc_open(\|)\fR or \fBnc_create(\|)\fR +.TP +char \fIname\fP[] +is the name of a dimension, variable, or attribute. The names of +dimensions, variables and attributes consist of arbitrary +sequences of alphanumeric characters (as well as underscore '_', +period '.' and hyphen '-'), beginning with a letter or +underscore. (However names commencing with underscore are reserved for +system use.) Case is significant in netCDF names. A zero-length name +is not allowed. +As an input argument, +it shall be a pointer to a 0-terminated string; as an output argument, it +shall be the address of a buffer in which to hold such a string. +The maximum allowable number of characters +(excluding the terminating 0) is \fBNC_MAX_NAME\fR. +.TP +nc_type \fIxtype\fP +specifies the external data type of a netCDF variable or attribute and +is one of the following: +\fBNC_BYTE\fR, \fBNC_CHAR\fR, \fBNC_SHORT\fR, \fBNC_INT\fR, +\fBNC_FLOAT\fR, or \fBNC_DOUBLE\fR. +These are used to specify 8-bit integers, +characters, 16-bit integers, 32-bit integers, 32-bit IEEE floating point +numbers, and 64-bit IEEE floating-point numbers, respectively. +(\fBNC_INT\fR corresponds to \fBNC_LONG\fR in version 2, to specify a +32-bit integer). +.TP +int \fIdimids\fP[] +is a vector of dimension ID's and defines the shape of a netCDF variable. +The size of the vector shall be greater than or equal to the +rank (i.e. the number of dimensions) of the variable (\fIndims\fP). +The vector shall be ordered by the speed with which a dimension varies: +\fIdimids\fP[\fIndims\fP-1] +shall be the dimension ID of the most rapidly +varying dimension and +\fIdimids\fP[0] +shall be the dimension ID of the most slowly +varying dimension. +The maximum possible number of +dimensions for a variable is given by the symbolic constant +\fBNC_MAX_VAR_DIMS\fR. +.TP +int \fIdimid\fP +is the ID of a netCDF dimension. +netCDF dimension ID's are allocated sequentially from the +non-negative +integers beginning with 0. +.TP +int \fIndims\fP +is either the total number of dimensions in a netCDF dataset or the rank +(i.e. the number of dimensions) of a netCDF variable. +The value shall not be negative or greater than the symbolic constant +\fBNC_MAX_VAR_DIMS\fR. +.TP +int \fIvarid\fP +is the ID of a netCDF variable or (for the attribute-access functions) +the symbolic constant +\fBNC_GLOBAL\fR, +which is used to reference global attributes. +netCDF variable ID's are allocated sequentially from the +non-negative +integers beginning with 0. +.TP +int* \fInatts\fP +is the number of global attributes in a netCDF dataset for the +\fBnc_inquire(\|)\fR +function or the number +of attributes associated with a netCDF variable for the +\fBnc_varinq(\|)\fR +function. +.TP +const size_t \fIindex\fP[] +specifies the indicial coordinates of the netCDF data value to be accessed. +The indices start at 0; +thus, for example, the first data value of a +two-dimensional variable is (0,0). +The size of the vector shall be at least the rank of the associated +netCDF variable and its elements shall correspond, in order, to the +variable's dimensions. +.TP +const size_t \fIstart\fP[] +specifies the starting point +for accessing a netCDF variable's data values +in terms of the indicial coordinates of +the corner of the array section. +The indices start at 0; +thus, the first data +value of a variable is (0, 0, ..., 0). +The size of the vector shall be at least the rank of the associated +netCDF variable and its elements shall correspond, in order, to the +variable's dimensions. +.TP +const size_t \fIcount\fP[] +specifies the number of indices selected along each dimension of the +array section. +Thus, to access a single value, for example, specify \fIcount\fP as +(1, 1, ..., 1). +Note that, for strided I/O, this argument must be adjusted +to be compatible with the \fIstride\fP and \fIstart\fP arguments so that +the interaction of the +three does not attempt to access an invalid data co-ordinate. +The elements of the +\fIcount\fP vector correspond, in order, to the variable's dimensions. +.TP +const size_t \fIstride\fP[] +specifies the sampling interval along each dimension of the netCDF +variable. The elements of the stride vector correspond, in order, +to the netCDF variable's dimensions (\fIstride\fP[0]) +gives the sampling interval along the most slowly +varying dimension of the netCDF variable). Sampling intervals are +specified in type-independent units of elements (a value of 1 selects +consecutive elements of the netCDF variable along the corresponding +dimension, a value of 2 selects every other element, etc.). +A \fBNULL\fR stride argument is treated as (1, 1, ... , 1). +.TP +\fIimap\fP +specifies the mapping between the dimensions of a netCDF variable and +the in-memory structure of the internal data array. The elements of +the index mapping vector correspond, in order, to the netCDF variable's +dimensions (\fIimap\fP[0] gives the distance +between elements of the internal array corresponding to the most +slowly varying dimension of the netCDF variable). +Distances between elements are specified in type-independent units of +elements (the distance between internal elements that occupy adjacent +memory locations is 1 and not the element's byte-length as in netCDF 2). +A \fBNULL\fR pointer means the memory-resident values have +the same structure as the associated netCDF variable. +.SH "VARIABLE PREFILLING" +.LP +By default, the netCDF interface sets the values of +all newly-defined variables of finite length (i.e. those that do not have +an unlimited, dimension) to the type-dependent fill-value associated with each +variable. This is done when \fBnc_enddef(\|)\fR +is called. The +fill-value for a variable may be changed from the default value by +defining the attribute `\fB_FillValue\fR' for the variable. This +attribute must have the same type as the variable and be of length one. +.LP +Variables with an unlimited dimension are also prefilled, but on +an `as needed' basis. For example, if the first write of such a +variable is to position 5, then +positions +0 through 4 +(and no others) +would be set to the fill-value at the same time. +.LP +This default prefilling of data values may be disabled by +or'ing the +\fBNC_NOFILL\fR +flag into the mode parameter of \fBnc_open(\|)\fR or \fBnc_create(\|)\fR, +or, by calling the function \fBnc_set_fill(\|)\fR +with the argument \fBNC_NOFILL\fR. +For variables that do not use the unlimited dimension, +this call must +be made before +\fBnc_enddef(\|)\fR. +For variables that +use the unlimited dimension, this call +may be made at any time. +.LP +One can obtain increased performance of the netCDF interface by using +this feature, but only at the expense of requiring the application to set +every single data value. The performance +enhancing behavior of this function is dependent on the particulars of +the implementation and dataset format. +The flag value controlled by \fBnc_set_fill(\|)\fR +is per netCDF ID, +not per variable or per write. +Allowing this to change affects the degree to which +a program can be effectively parallelized. +Given all of this, we state that the use +of this feature may not be available (or even needed) in future +releases. Programmers are cautioned against heavy reliance upon this +feature. +.HP +\fBint nc_setfill(int \fIncid\fP, int \fIfillmode\fP, int* \fIold_fillemode\fP)\fR +.sp +(Corresponds to \fBncsetfill(\|)\fR in version 2) +.sp +Determines whether or not variable prefilling will be done (see +above). +The netCDF dataset shall be writable. +\fIfillmode\fP is either \fBNC_FILL\fR +to enable prefilling (the +default) or \fBNC_NOFILL\fR +to disable prefilling. +This function returns the previous setting in \fIold_fillmode\fP. + +.HP +.SH "MPP FUNCTION DESCRIPTIONS" +.LP +These functions were used on archaic SGI/Cray MPP machines. These +functions are retained for backward compatibility; the PE arguments +must all be set to zero. +.LP +.HP +\fBint nc__create_mp(const char \fIpath\fP[], int \fIcmode\fP, size_t \fIinitialsize\fP, int \fIpe\fP, size_t* \fIchunksize\fP, int* \fIncid\fP)\fR +.sp +Like \fBnc__create(\|)\fR. +.sp +The argument \fIpe\fP must be zero. +.HP +\fBint nc__open_mp(const char \fIpath\fP[], int \fImode\fP, int \fIpe\fP, size_t* \fIchunksize\fP, int* \fIncid\fP)\fR +.sp +Like \fBnc__open(\|)\fR. +The argument \fIpe\fP must be zero. +.HP +\fBint nc_inq_base_pe(int \fIncid\fP, int* \fIpe\fP)\fR +.sp +Always returns pe of zero. +.HP +\fBint nc_set_base_pe(int \fIncid\fP, int \fIpe\fP)\fR +.sp +This function does nothing. +.SH "ENVIRONMENT VARIABLES" +.TP 4 +.B NETCDF_FFIOSPEC +Specifies the Flexible File I/O buffers for netCDF I/O when executing +under the UNICOS operating system (the variable is ignored on other +operating systems). +An appropriate specification can greatly increase the efficiency of +netCDF I/O -- to the extent that it can actually surpass FORTRAN binary +I/O. +This environment variable has been made a little more generalized, +such that other FFIO option specifications can now be added. +The default specification is \fBbufa:336:2\fP, +unless a current FFIO specification is in operation, +which will be honored. +See UNICOS Flexible File I/O for more information. +.SH "MAILING-LISTS" +.LP +Both a mailing list and a digest are available for +discussion of the netCDF interface and announcements about netCDF bugs, +fixes, and enhancements. +To begin or change your subscription to either the mailing-list or the +digest, send one of the following in the body (not +the subject line) of an email message to "majordomo@unidata.ucar.edu". +Use your email address in place of \fIjdoe@host.inst.domain\fP. +.sp +To subscribe to the netCDF mailing list: +.RS +\fBsubscribe netcdfgroup \fIjdoe@host.inst.domain\fR +.RE +To unsubscribe from the netCDF mailing list: +.RS +\fBunsubscribe netcdfgroup \fIjdoe@host.inst.domain\fR +.RE +To subscribe to the netCDF digest: +.RS +\fBsubscribe netcdfdigest \fIjdoe@host.inst.domain\fR +.RE +To unsubscribe from the netCDF digest: +.RS +\fBunsubscribe netcdfdigest \fIjdoe@host.inst.domain\fR +.RE +To retrieve the general introductory information for the mailing list: +.RS +\fBinfo netcdfgroup\fR +.RE +To get a synopsis of other majordomo commands: +.RS +\fBhelp\fR +.RE +.SH "SEE ALSO" +.LP +.BR ncdump (1), +.BR ncgen (1), +.BR netcdf (3). +.LP +\fInetCDF User's Guide\fP, published +by the Unidata Program Center, University Corporation for Atmospheric +Research, located in Boulder, Colorado. + +NetCDF home page at http:/www.unidata.ucar.edu/netcdf. diff --git a/libsrc/putget.c b/libsrc/putget.c new file mode 100644 index 0000000000..4426c517d9 --- /dev/null +++ b/libsrc/putget.c @@ -0,0 +1,21416 @@ +#line 9 "putget.m4" +/* Do not edit this file. It is produced from the corresponding .m4 source */ +#line 11 +/* + * Copyright 2018, University Corporation for Atmospheric Research + * See netcdf/COPYRIGHT file for copying and redistribution conditions. + */ +/* $Id: putget.m4 2783 2014-10-26 05:19:35Z wkliao $ */ + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include "netcdf.h" +#include "nc3dispatch.h" +#include "nc3internal.h" +#include "ncx.h" +#include "fbits.h" +#include "onstack.h" + +#undef MIN /* system may define MIN somewhere and complain */ +#define MIN(mm,nn) (((mm) < (nn)) ? (mm) : (nn)) + +static int +readNCv(const NC3_INFO* ncp, const NC_var* varp, const size_t* start, + const size_t nelems, void* value, const nc_type memtype); +static int +writeNCv(NC3_INFO* ncp, const NC_var* varp, const size_t* start, + const size_t nelems, const void* value, const nc_type memtype); + + +/* #define ODEBUG 1 */ + +#if ODEBUG +#include +/* + * Print the values of an array of size_t + */ +void +arrayp(const char *label, size_t count, const size_t *array) +{ + (void) fprintf(stderr, "%s", label); + (void) fputc('\t',stderr); + for(; count > 0; count--, array++) + (void) fprintf(stderr," %lu", (unsigned long)*array); + (void) fputc('\n',stderr); +} +#endif /* ODEBUG */ + + +/* Begin fill */ +/* + * This is tunable parameter. + * It essentially controls the tradeoff between the number of times + * memcpy() gets called to copy the external data to fill + * a large buffer vs the number of times its called to + * prepare the external data. + */ +#if _SX +/* NEC SX specific optimization */ +#define NFILL 2048 +#else +#define NFILL 16 +#endif + + +#line 103 + +/* + * Next 6 type specific functions + * Fill a some memory with the default special value. + * Formerly +NC_arrayfill() + */ +static int +#line 110 +NC_fill_schar( +#line 110 + void **xpp, +#line 110 + size_t nelems) /* how many */ +#line 110 +{ +#line 110 + schar fillp[NFILL * sizeof(double)/X_SIZEOF_CHAR]; +#line 110 + +#line 110 + assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); +#line 110 + +#line 110 + { +#line 110 + schar *vp = fillp; /* lower bound of area to be filled */ +#line 110 + const schar *const end = vp + nelems; +#line 110 + while(vp < end) +#line 110 + { +#line 110 + *vp++ = NC_FILL_BYTE; +#line 110 + } +#line 110 + } +#line 110 + return ncx_putn_schar_schar(xpp, nelems, fillp ,NULL); +#line 110 +} +#line 110 + +static int +#line 111 +NC_fill_char( +#line 111 + void **xpp, +#line 111 + size_t nelems) /* how many */ +#line 111 +{ +#line 111 + char fillp[NFILL * sizeof(double)/X_SIZEOF_CHAR]; +#line 111 + +#line 111 + assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); +#line 111 + +#line 111 + { +#line 111 + char *vp = fillp; /* lower bound of area to be filled */ +#line 111 + const char *const end = vp + nelems; +#line 111 + while(vp < end) +#line 111 + { +#line 111 + *vp++ = NC_FILL_CHAR; +#line 111 + } +#line 111 + } +#line 111 + return ncx_putn_char_char(xpp, nelems, fillp ); +#line 111 +} +#line 111 + +static int +#line 112 +NC_fill_short( +#line 112 + void **xpp, +#line 112 + size_t nelems) /* how many */ +#line 112 +{ +#line 112 + short fillp[NFILL * sizeof(double)/X_SIZEOF_SHORT]; +#line 112 + +#line 112 + assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); +#line 112 + +#line 112 + { +#line 112 + short *vp = fillp; /* lower bound of area to be filled */ +#line 112 + const short *const end = vp + nelems; +#line 112 + while(vp < end) +#line 112 + { +#line 112 + *vp++ = NC_FILL_SHORT; +#line 112 + } +#line 112 + } +#line 112 + return ncx_putn_short_short(xpp, nelems, fillp ,NULL); +#line 112 +} +#line 112 + + +#if (SIZEOF_INT >= X_SIZEOF_INT) +static int +#line 115 +NC_fill_int( +#line 115 + void **xpp, +#line 115 + size_t nelems) /* how many */ +#line 115 +{ +#line 115 + int fillp[NFILL * sizeof(double)/X_SIZEOF_INT]; +#line 115 + +#line 115 + assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); +#line 115 + +#line 115 + { +#line 115 + int *vp = fillp; /* lower bound of area to be filled */ +#line 115 + const int *const end = vp + nelems; +#line 115 + while(vp < end) +#line 115 + { +#line 115 + *vp++ = NC_FILL_INT; +#line 115 + } +#line 115 + } +#line 115 + return ncx_putn_int_int(xpp, nelems, fillp ,NULL); +#line 115 +} +#line 115 + +#elif SIZEOF_LONG == X_SIZEOF_INT +static int +#line 117 +NC_fill_int( +#line 117 + void **xpp, +#line 117 + size_t nelems) /* how many */ +#line 117 +{ +#line 117 + long fillp[NFILL * sizeof(double)/X_SIZEOF_INT]; +#line 117 + +#line 117 + assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); +#line 117 + +#line 117 + { +#line 117 + long *vp = fillp; /* lower bound of area to be filled */ +#line 117 + const long *const end = vp + nelems; +#line 117 + while(vp < end) +#line 117 + { +#line 117 + *vp++ = NC_FILL_INT; +#line 117 + } +#line 117 + } +#line 117 + return ncx_putn_int_long(xpp, nelems, fillp ,NULL); +#line 117 +} +#line 117 + +#else +#error "NC_fill_int implementation" +#endif + +static int +#line 122 +NC_fill_float( +#line 122 + void **xpp, +#line 122 + size_t nelems) /* how many */ +#line 122 +{ +#line 122 + float fillp[NFILL * sizeof(double)/X_SIZEOF_FLOAT]; +#line 122 + +#line 122 + assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); +#line 122 + +#line 122 + { +#line 122 + float *vp = fillp; /* lower bound of area to be filled */ +#line 122 + const float *const end = vp + nelems; +#line 122 + while(vp < end) +#line 122 + { +#line 122 + *vp++ = NC_FILL_FLOAT; +#line 122 + } +#line 122 + } +#line 122 + return ncx_putn_float_float(xpp, nelems, fillp ,NULL); +#line 122 +} +#line 122 + +static int +#line 123 +NC_fill_double( +#line 123 + void **xpp, +#line 123 + size_t nelems) /* how many */ +#line 123 +{ +#line 123 + double fillp[NFILL * sizeof(double)/X_SIZEOF_DOUBLE]; +#line 123 + +#line 123 + assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); +#line 123 + +#line 123 + { +#line 123 + double *vp = fillp; /* lower bound of area to be filled */ +#line 123 + const double *const end = vp + nelems; +#line 123 + while(vp < end) +#line 123 + { +#line 123 + *vp++ = NC_FILL_DOUBLE; +#line 123 + } +#line 123 + } +#line 123 + return ncx_putn_double_double(xpp, nelems, fillp ,NULL); +#line 123 +} +#line 123 + + +static int +#line 125 +NC_fill_uchar( +#line 125 + void **xpp, +#line 125 + size_t nelems) /* how many */ +#line 125 +{ +#line 125 + uchar fillp[NFILL * sizeof(double)/X_SIZEOF_UBYTE]; +#line 125 + +#line 125 + assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); +#line 125 + +#line 125 + { +#line 125 + uchar *vp = fillp; /* lower bound of area to be filled */ +#line 125 + const uchar *const end = vp + nelems; +#line 125 + while(vp < end) +#line 125 + { +#line 125 + *vp++ = NC_FILL_UBYTE; +#line 125 + } +#line 125 + } +#line 125 + return ncx_putn_uchar_uchar(xpp, nelems, fillp ,NULL); +#line 125 +} +#line 125 + +static int +#line 126 +NC_fill_ushort( +#line 126 + void **xpp, +#line 126 + size_t nelems) /* how many */ +#line 126 +{ +#line 126 + ushort fillp[NFILL * sizeof(double)/X_SIZEOF_USHORT]; +#line 126 + +#line 126 + assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); +#line 126 + +#line 126 + { +#line 126 + ushort *vp = fillp; /* lower bound of area to be filled */ +#line 126 + const ushort *const end = vp + nelems; +#line 126 + while(vp < end) +#line 126 + { +#line 126 + *vp++ = NC_FILL_USHORT; +#line 126 + } +#line 126 + } +#line 126 + return ncx_putn_ushort_ushort(xpp, nelems, fillp ,NULL); +#line 126 +} +#line 126 + +static int +#line 127 +NC_fill_uint( +#line 127 + void **xpp, +#line 127 + size_t nelems) /* how many */ +#line 127 +{ +#line 127 + uint fillp[NFILL * sizeof(double)/X_SIZEOF_UINT]; +#line 127 + +#line 127 + assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); +#line 127 + +#line 127 + { +#line 127 + uint *vp = fillp; /* lower bound of area to be filled */ +#line 127 + const uint *const end = vp + nelems; +#line 127 + while(vp < end) +#line 127 + { +#line 127 + *vp++ = NC_FILL_UINT; +#line 127 + } +#line 127 + } +#line 127 + return ncx_putn_uint_uint(xpp, nelems, fillp ,NULL); +#line 127 +} +#line 127 + +static int +#line 128 +NC_fill_longlong( +#line 128 + void **xpp, +#line 128 + size_t nelems) /* how many */ +#line 128 +{ +#line 128 + longlong fillp[NFILL * sizeof(double)/X_SIZEOF_LONGLONG]; +#line 128 + +#line 128 + assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); +#line 128 + +#line 128 + { +#line 128 + longlong *vp = fillp; /* lower bound of area to be filled */ +#line 128 + const longlong *const end = vp + nelems; +#line 128 + while(vp < end) +#line 128 + { +#line 128 + *vp++ = NC_FILL_INT64; +#line 128 + } +#line 128 + } +#line 128 + return ncx_putn_longlong_longlong(xpp, nelems, fillp ,NULL); +#line 128 +} +#line 128 + +static int +#line 129 +NC_fill_ulonglong( +#line 129 + void **xpp, +#line 129 + size_t nelems) /* how many */ +#line 129 +{ +#line 129 + ulonglong fillp[NFILL * sizeof(double)/X_SIZEOF_ULONGLONG]; +#line 129 + +#line 129 + assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); +#line 129 + +#line 129 + { +#line 129 + ulonglong *vp = fillp; /* lower bound of area to be filled */ +#line 129 + const ulonglong *const end = vp + nelems; +#line 129 + while(vp < end) +#line 129 + { +#line 129 + *vp++ = NC_FILL_UINT64; +#line 129 + } +#line 129 + } +#line 129 + return ncx_putn_ulonglong_ulonglong(xpp, nelems, fillp ,NULL); +#line 129 +} +#line 129 + + + + +/* + * Fill the external space for variable 'varp' values at 'recno' with + * the appropriate value. If 'varp' is not a record variable, fill the + * whole thing. For the special case when 'varp' is the only record + * variable and it is of type byte, char, or short, varsize should be + * ncp->recsize, otherwise it should be varp->len. + * Formerly +xdr_NC_fill() + */ +int +fill_NC_var(NC3_INFO* ncp, const NC_var *varp, long long varsize, size_t recno) +{ + char xfillp[NFILL * X_SIZEOF_DOUBLE]; + const size_t step = varp->xsz; + const size_t nelems = sizeof(xfillp)/step; + const size_t xsz = varp->xsz * nelems; + NC_attr **attrpp = NULL; + off_t offset; + long long remaining = varsize; + + void *xp; + int status = NC_NOERR; + + /* + * Set up fill value + */ + attrpp = NC_findattr(&varp->attrs, _FillValue); + if( attrpp != NULL ) + { + /* User defined fill value */ + if( (*attrpp)->type != varp->type || (*attrpp)->nelems != 1 ) + { + return NC_EBADTYPE; + } + else + { + /* Use the user defined value */ + char *cp = xfillp; + const char *const end = &xfillp[sizeof(xfillp)]; + + assert(step <= (*attrpp)->xsz); + + for( /*NADA*/; cp < end; cp += step) + { + (void) memcpy(cp, (*attrpp)->xvalue, step); + } + } + } + else + { + /* use the default */ + + assert(xsz % X_ALIGN == 0); + assert(xsz <= sizeof(xfillp)); + + xp = xfillp; + + switch(varp->type){ + case NC_BYTE : + status = NC_fill_schar(&xp, nelems); + break; + case NC_CHAR : + status = NC_fill_char(&xp, nelems); + break; + case NC_SHORT : + status = NC_fill_short(&xp, nelems); + break; + case NC_INT : + status = NC_fill_int(&xp, nelems); + break; + case NC_FLOAT : + status = NC_fill_float(&xp, nelems); + break; + case NC_DOUBLE : + status = NC_fill_double(&xp, nelems); + break; + case NC_UBYTE : + status = NC_fill_uchar(&xp, nelems); + break; + case NC_USHORT : + status = NC_fill_ushort(&xp, nelems); + break; + case NC_UINT : + status = NC_fill_uint(&xp, nelems); + break; + case NC_INT64 : + status = NC_fill_longlong(&xp, nelems); + break; + case NC_UINT64 : + status = NC_fill_ulonglong(&xp, nelems); + break; + default : + assert("fill_NC_var invalid type" == 0); + status = NC_EBADTYPE; + break; + } + if(status != NC_NOERR) + return status; + + assert(xp == xfillp + xsz); + } + + /* + * copyout: + * xfillp now contains 'nelems' elements of the fill value + * in external representation. + */ + + /* + * Copy it out. + */ + + offset = varp->begin; + if(IS_RECVAR(varp)) + { + offset += (off_t)ncp->recsize * recno; + } + + assert(remaining > 0); + for(;;) + { + const size_t chunksz = MIN(remaining, ncp->chunk); + size_t ii; + + status = ncio_get(ncp->nciop, offset, chunksz, + RGN_WRITE, &xp); + if(status != NC_NOERR) + { + return status; + } + + /* + * fill the chunksz buffer in units of xsz + */ + for(ii = 0; ii < chunksz/xsz; ii++) + { + (void) memcpy(xp, xfillp, xsz); + xp = (char *)xp + xsz; + } + /* + * Deal with any remainder + */ + { + const size_t rem = chunksz % xsz; + if(rem != 0) + { + (void) memcpy(xp, xfillp, rem); + /* xp = (char *)xp + xsz; */ + } + + } + + status = ncio_rel(ncp->nciop, offset, RGN_MODIFIED); + + if(status != NC_NOERR) + { + break; + } + + remaining -= chunksz; + if(remaining == 0) + break; /* normal loop exit */ + offset += chunksz; + + } + + return status; +} +/* End fill */ + + +/* + * Add a record containing the fill values. + */ +static int +NCfillrecord(NC3_INFO* ncp, const NC_var *const *varpp, size_t recno) +{ + size_t ii = 0; + for(; ii < ncp->vars.nelems; ii++, varpp++) + { + if( !IS_RECVAR(*varpp) ) + { + continue; /* skip non-record variables */ + } + { + const int status = fill_NC_var(ncp, *varpp, (*varpp)->len, recno); + if(status != NC_NOERR) + return status; + } + } + return NC_NOERR; +} + + +/* + * Add a record containing the fill values in the special case when + * there is exactly one record variable, where we don't require each + * record to be four-byte aligned (no record padding). + */ +static int +NCfillspecialrecord(NC3_INFO* ncp, const NC_var *varp, size_t recno) +{ + int status; + assert(IS_RECVAR(varp)); + status = fill_NC_var(ncp, varp, ncp->recsize, recno); + if(status != NC_NOERR) + return status; + return NC_NOERR; +} + + +/* + * It is advantageous to + * #define TOUCH_LAST + * when using memory mapped io. + */ +#if TOUCH_LAST +/* + * Grow the file to a size which can contain recno + */ +static int +NCtouchlast(NC3_INFO* ncp, const NC_var *const *varpp, size_t recno) +{ + int status = NC_NOERR; + const NC_var *varp = NULL; + + { + size_t ii = 0; + for(; ii < ncp->vars.nelems; ii++, varpp++) + { + if( !IS_RECVAR(*varpp) ) + { + continue; /* skip non-record variables */ + } + varp = *varpp; + } + } + assert(varp != NULL); + assert( IS_RECVAR(varp) ); + { + const off_t offset = varp->begin + + (off_t)(recno-1) * (off_t)ncp->recsize + + (off_t)(varp->len - varp->xsz); + void *xp; + + + status = ncio_get(ncp->nciop, offset, varp->xsz, + RGN_WRITE, &xp); + if(status != NC_NOERR) + return status; + (void)memset(xp, 0, varp->xsz); + status = ncio_rel(ncp->nciop, offset, RGN_MODIFIED); + } + return status; +} +#endif /* TOUCH_LAST */ + + +/* + * Ensure that the netcdf file has 'numrecs' records, + * add records and fill as necessary. + */ +static int +NCvnrecs(NC3_INFO* ncp, size_t numrecs) +{ + int status = NC_NOERR; + + if(numrecs > NC_get_numrecs(ncp)) + { + + +#if TOUCH_LAST + status = NCtouchlast(ncp, + (const NC_var *const*)ncp->vars.value, + numrecs); + if(status != NC_NOERR) + goto common_return; +#endif /* TOUCH_LAST */ + + set_NC_ndirty(ncp); + + if(!NC_dofill(ncp)) + { + /* Simply set the new numrecs value */ + NC_set_numrecs(ncp, numrecs); + } + else + { + /* Treat two cases differently: + - exactly one record variable (no padding) + - multiple record variables (each record padded + to 4-byte alignment) + */ + NC_var **vpp = (NC_var **)ncp->vars.value; + NC_var *const *const end = &vpp[ncp->vars.nelems]; + NC_var *recvarp = NULL; /* last record var */ + int numrecvars = 0; + size_t cur_nrecs; + + /* determine how many record variables */ + for( /*NADA*/; vpp < end; vpp++) { + if(IS_RECVAR(*vpp)) { + recvarp = *vpp; + numrecvars++; + } + } + + if (numrecvars != 1) { /* usual case */ + /* Fill each record out to numrecs */ + while((cur_nrecs = NC_get_numrecs(ncp)) < numrecs) + { + status = NCfillrecord(ncp, + (const NC_var *const*)ncp->vars.value, + cur_nrecs); + if(status != NC_NOERR) + { + break; + } + NC_increase_numrecs(ncp, cur_nrecs +1); + } + if(status != NC_NOERR) + goto common_return; + } else { /* special case */ + /* Fill each record out to numrecs */ + while((cur_nrecs = NC_get_numrecs(ncp)) < numrecs) + { + status = NCfillspecialrecord(ncp, + recvarp, + cur_nrecs); + if(status != NC_NOERR) + { + break; + } + NC_increase_numrecs(ncp, cur_nrecs +1); + } + if(status != NC_NOERR) + goto common_return; + + } + } + + if(NC_doNsync(ncp)) + { + status = write_numrecs(ncp); + } + + } +common_return: + return status; +} + + +/* + * Check whether 'coord' values are valid for the variable. + */ +static int +NCcoordck(NC3_INFO* ncp, const NC_var *varp, const size_t *coord) +{ + const size_t *ip; + size_t *up; + + if(varp->ndims == 0) + return NC_NOERR; /* 'scalar' variable */ + + if(IS_RECVAR(varp)) + { + if(*coord > X_UINT_MAX) /* rkr: bug fix from previous X_INT_MAX */ + return NC_EINVALCOORDS; /* sanity check */ + if(NC_readonly(ncp) && *coord > NC_get_numrecs(ncp)) + { + if(!NC_doNsync(ncp)) + return NC_EINVALCOORDS; + /* else */ + { + /* Update from disk and check again */ + const int status = read_numrecs(ncp); + if(status != NC_NOERR) + return status; + if(*coord > NC_get_numrecs(ncp)) + return NC_EINVALCOORDS; + } + } + ip = coord + 1; + up = varp->shape + 1; + } + else + { + ip = coord; + up = varp->shape; + } + +#ifdef CDEBUG +fprintf(stderr," NCcoordck: coord %ld, count %d, ip %ld\n", + coord, varp->ndims, ip ); +#endif /* CDEBUG */ + + for(; ip < coord + varp->ndims; ip++, up++) + { + +#ifdef CDEBUG +fprintf(stderr," NCcoordck: ip %p, *ip %ld, up %p, *up %lu\n", + ip, *ip, up, *up ); +#endif /* CDEBUG */ + + /* cast needed for braindead systems with signed size_t */ + if((unsigned long) *ip > (unsigned long) *up ) + return NC_EINVALCOORDS; + } + + return NC_NOERR; +} + + +/* + * Check whether 'edges' are valid for the variable and 'start' + */ +/*ARGSUSED*/ +static int +NCedgeck(const NC3_INFO* ncp, const NC_var *varp, + const size_t *start, const size_t *edges) +{ + const size_t *const end = start + varp->ndims; + const size_t *shp = varp->shape; + + if(varp->ndims == 0) + return NC_NOERR; /* 'scalar' variable */ + + if(IS_RECVAR(varp)) + { + if (NC_readonly(ncp) && + (start[0] == NC_get_numrecs(ncp) && edges[0] > 0)) + return(NC_EINVALCOORDS); + start++; + edges++; + shp++; + } + + for(; start < end; start++, edges++, shp++) + { + if ((unsigned long) *start == *shp && *edges > 0) + return(NC_EINVALCOORDS); + /* cast needed for braindead systems with signed size_t */ + if((unsigned long) *edges > *shp || + (unsigned long) *start + (unsigned long) *edges > *shp) + { + return(NC_EEDGE); + } + } + return NC_NOERR; +} + + +/* + * Translate the (variable, coord) pair into a seek index + */ +static off_t +NC_varoffset(const NC3_INFO* ncp, const NC_var *varp, const size_t *coord) +{ + if(varp->ndims == 0) /* 'scalar' variable */ + return varp->begin; + + if(varp->ndims == 1) + { + if(IS_RECVAR(varp)) + return varp->begin + + (off_t)(*coord) * (off_t)ncp->recsize; + /* else */ + return varp->begin + (off_t)(*coord) * (off_t)varp->xsz; + } + /* else */ + { + off_t lcoord = (off_t)coord[varp->ndims -1]; + + off_t *up = varp->dsizes +1; + const size_t *ip = coord; + const off_t *const end = varp->dsizes + varp->ndims; + + if(IS_RECVAR(varp)) + up++, ip++; + + for(; up < end; up++, ip++) + lcoord += (off_t)(*up) * (off_t)(*ip); + + lcoord *= varp->xsz; + + if(IS_RECVAR(varp)) + lcoord += (off_t)(*coord) * ncp->recsize; + + lcoord += varp->begin; + return lcoord; + } +} + + +#line 693 + +static int +#line 694 +putNCvx_char_char(NC3_INFO* ncp, const NC_var *varp, +#line 694 + const size_t *start, size_t nelems, const char *value) +#line 694 +{ +#line 694 + off_t offset = NC_varoffset(ncp, varp, start); +#line 694 + size_t remaining = varp->xsz * nelems; +#line 694 + int status = NC_NOERR; +#line 694 + void *xp; +#line 694 + void *fillp=NULL; +#line 694 + +#line 694 + NC_UNUSED(fillp); +#line 694 + +#line 694 + if(nelems == 0) +#line 694 + return NC_NOERR; +#line 694 + +#line 694 + assert(value != NULL); +#line 694 + +#line 694 +#ifdef ERANGE_FILL +#line 694 + fillp = malloc(varp->xsz); +#line 694 + status = NC3_inq_var_fill(varp, fillp); +#line 694 +#endif +#line 694 + +#line 694 + for(;;) +#line 694 + { +#line 694 + size_t extent = MIN(remaining, ncp->chunk); +#line 694 + size_t nput = ncx_howmany(varp->type, extent); +#line 694 + +#line 694 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 694 + RGN_WRITE, &xp); +#line 694 + if(lstatus != NC_NOERR) +#line 694 + return lstatus; +#line 694 + +#line 694 + lstatus = ncx_putn_char_char(&xp, nput, value ); +#line 694 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 694 + { +#line 694 + /* not fatal to the loop */ +#line 694 + status = lstatus; +#line 694 + } +#line 694 + +#line 694 + (void) ncio_rel(ncp->nciop, offset, +#line 694 + RGN_MODIFIED); +#line 694 + +#line 694 + remaining -= extent; +#line 694 + if(remaining == 0) +#line 694 + break; /* normal loop exit */ +#line 694 + offset += (off_t)extent; +#line 694 + value += nput; +#line 694 + +#line 694 + } +#line 694 +#ifdef ERANGE_FILL +#line 694 + free(fillp); +#line 694 +#endif +#line 694 + +#line 694 + return status; +#line 694 +} +#line 694 + + +static int +#line 696 +putNCvx_schar_schar(NC3_INFO* ncp, const NC_var *varp, +#line 696 + const size_t *start, size_t nelems, const schar *value) +#line 696 +{ +#line 696 + off_t offset = NC_varoffset(ncp, varp, start); +#line 696 + size_t remaining = varp->xsz * nelems; +#line 696 + int status = NC_NOERR; +#line 696 + void *xp; +#line 696 + void *fillp=NULL; +#line 696 + +#line 696 + NC_UNUSED(fillp); +#line 696 + +#line 696 + if(nelems == 0) +#line 696 + return NC_NOERR; +#line 696 + +#line 696 + assert(value != NULL); +#line 696 + +#line 696 +#ifdef ERANGE_FILL +#line 696 + fillp = malloc(varp->xsz); +#line 696 + status = NC3_inq_var_fill(varp, fillp); +#line 696 +#endif +#line 696 + +#line 696 + for(;;) +#line 696 + { +#line 696 + size_t extent = MIN(remaining, ncp->chunk); +#line 696 + size_t nput = ncx_howmany(varp->type, extent); +#line 696 + +#line 696 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 696 + RGN_WRITE, &xp); +#line 696 + if(lstatus != NC_NOERR) +#line 696 + return lstatus; +#line 696 + +#line 696 + lstatus = ncx_putn_schar_schar(&xp, nput, value ,fillp); +#line 696 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 696 + { +#line 696 + /* not fatal to the loop */ +#line 696 + status = lstatus; +#line 696 + } +#line 696 + +#line 696 + (void) ncio_rel(ncp->nciop, offset, +#line 696 + RGN_MODIFIED); +#line 696 + +#line 696 + remaining -= extent; +#line 696 + if(remaining == 0) +#line 696 + break; /* normal loop exit */ +#line 696 + offset += (off_t)extent; +#line 696 + value += nput; +#line 696 + +#line 696 + } +#line 696 +#ifdef ERANGE_FILL +#line 696 + free(fillp); +#line 696 +#endif +#line 696 + +#line 696 + return status; +#line 696 +} +#line 696 + +static int +#line 697 +putNCvx_schar_uchar(NC3_INFO* ncp, const NC_var *varp, +#line 697 + const size_t *start, size_t nelems, const uchar *value) +#line 697 +{ +#line 697 + off_t offset = NC_varoffset(ncp, varp, start); +#line 697 + size_t remaining = varp->xsz * nelems; +#line 697 + int status = NC_NOERR; +#line 697 + void *xp; +#line 697 + void *fillp=NULL; +#line 697 + +#line 697 + NC_UNUSED(fillp); +#line 697 + +#line 697 + if(nelems == 0) +#line 697 + return NC_NOERR; +#line 697 + +#line 697 + assert(value != NULL); +#line 697 + +#line 697 +#ifdef ERANGE_FILL +#line 697 + fillp = malloc(varp->xsz); +#line 697 + status = NC3_inq_var_fill(varp, fillp); +#line 697 +#endif +#line 697 + +#line 697 + for(;;) +#line 697 + { +#line 697 + size_t extent = MIN(remaining, ncp->chunk); +#line 697 + size_t nput = ncx_howmany(varp->type, extent); +#line 697 + +#line 697 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 697 + RGN_WRITE, &xp); +#line 697 + if(lstatus != NC_NOERR) +#line 697 + return lstatus; +#line 697 + +#line 697 + lstatus = ncx_putn_schar_uchar(&xp, nput, value ,fillp); +#line 697 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 697 + { +#line 697 + /* not fatal to the loop */ +#line 697 + status = lstatus; +#line 697 + } +#line 697 + +#line 697 + (void) ncio_rel(ncp->nciop, offset, +#line 697 + RGN_MODIFIED); +#line 697 + +#line 697 + remaining -= extent; +#line 697 + if(remaining == 0) +#line 697 + break; /* normal loop exit */ +#line 697 + offset += (off_t)extent; +#line 697 + value += nput; +#line 697 + +#line 697 + } +#line 697 +#ifdef ERANGE_FILL +#line 697 + free(fillp); +#line 697 +#endif +#line 697 + +#line 697 + return status; +#line 697 +} +#line 697 + +static int +#line 698 +putNCvx_schar_short(NC3_INFO* ncp, const NC_var *varp, +#line 698 + const size_t *start, size_t nelems, const short *value) +#line 698 +{ +#line 698 + off_t offset = NC_varoffset(ncp, varp, start); +#line 698 + size_t remaining = varp->xsz * nelems; +#line 698 + int status = NC_NOERR; +#line 698 + void *xp; +#line 698 + void *fillp=NULL; +#line 698 + +#line 698 + NC_UNUSED(fillp); +#line 698 + +#line 698 + if(nelems == 0) +#line 698 + return NC_NOERR; +#line 698 + +#line 698 + assert(value != NULL); +#line 698 + +#line 698 +#ifdef ERANGE_FILL +#line 698 + fillp = malloc(varp->xsz); +#line 698 + status = NC3_inq_var_fill(varp, fillp); +#line 698 +#endif +#line 698 + +#line 698 + for(;;) +#line 698 + { +#line 698 + size_t extent = MIN(remaining, ncp->chunk); +#line 698 + size_t nput = ncx_howmany(varp->type, extent); +#line 698 + +#line 698 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 698 + RGN_WRITE, &xp); +#line 698 + if(lstatus != NC_NOERR) +#line 698 + return lstatus; +#line 698 + +#line 698 + lstatus = ncx_putn_schar_short(&xp, nput, value ,fillp); +#line 698 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 698 + { +#line 698 + /* not fatal to the loop */ +#line 698 + status = lstatus; +#line 698 + } +#line 698 + +#line 698 + (void) ncio_rel(ncp->nciop, offset, +#line 698 + RGN_MODIFIED); +#line 698 + +#line 698 + remaining -= extent; +#line 698 + if(remaining == 0) +#line 698 + break; /* normal loop exit */ +#line 698 + offset += (off_t)extent; +#line 698 + value += nput; +#line 698 + +#line 698 + } +#line 698 +#ifdef ERANGE_FILL +#line 698 + free(fillp); +#line 698 +#endif +#line 698 + +#line 698 + return status; +#line 698 +} +#line 698 + +static int +#line 699 +putNCvx_schar_int(NC3_INFO* ncp, const NC_var *varp, +#line 699 + const size_t *start, size_t nelems, const int *value) +#line 699 +{ +#line 699 + off_t offset = NC_varoffset(ncp, varp, start); +#line 699 + size_t remaining = varp->xsz * nelems; +#line 699 + int status = NC_NOERR; +#line 699 + void *xp; +#line 699 + void *fillp=NULL; +#line 699 + +#line 699 + NC_UNUSED(fillp); +#line 699 + +#line 699 + if(nelems == 0) +#line 699 + return NC_NOERR; +#line 699 + +#line 699 + assert(value != NULL); +#line 699 + +#line 699 +#ifdef ERANGE_FILL +#line 699 + fillp = malloc(varp->xsz); +#line 699 + status = NC3_inq_var_fill(varp, fillp); +#line 699 +#endif +#line 699 + +#line 699 + for(;;) +#line 699 + { +#line 699 + size_t extent = MIN(remaining, ncp->chunk); +#line 699 + size_t nput = ncx_howmany(varp->type, extent); +#line 699 + +#line 699 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 699 + RGN_WRITE, &xp); +#line 699 + if(lstatus != NC_NOERR) +#line 699 + return lstatus; +#line 699 + +#line 699 + lstatus = ncx_putn_schar_int(&xp, nput, value ,fillp); +#line 699 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 699 + { +#line 699 + /* not fatal to the loop */ +#line 699 + status = lstatus; +#line 699 + } +#line 699 + +#line 699 + (void) ncio_rel(ncp->nciop, offset, +#line 699 + RGN_MODIFIED); +#line 699 + +#line 699 + remaining -= extent; +#line 699 + if(remaining == 0) +#line 699 + break; /* normal loop exit */ +#line 699 + offset += (off_t)extent; +#line 699 + value += nput; +#line 699 + +#line 699 + } +#line 699 +#ifdef ERANGE_FILL +#line 699 + free(fillp); +#line 699 +#endif +#line 699 + +#line 699 + return status; +#line 699 +} +#line 699 + +static int +#line 700 +putNCvx_schar_float(NC3_INFO* ncp, const NC_var *varp, +#line 700 + const size_t *start, size_t nelems, const float *value) +#line 700 +{ +#line 700 + off_t offset = NC_varoffset(ncp, varp, start); +#line 700 + size_t remaining = varp->xsz * nelems; +#line 700 + int status = NC_NOERR; +#line 700 + void *xp; +#line 700 + void *fillp=NULL; +#line 700 + +#line 700 + NC_UNUSED(fillp); +#line 700 + +#line 700 + if(nelems == 0) +#line 700 + return NC_NOERR; +#line 700 + +#line 700 + assert(value != NULL); +#line 700 + +#line 700 +#ifdef ERANGE_FILL +#line 700 + fillp = malloc(varp->xsz); +#line 700 + status = NC3_inq_var_fill(varp, fillp); +#line 700 +#endif +#line 700 + +#line 700 + for(;;) +#line 700 + { +#line 700 + size_t extent = MIN(remaining, ncp->chunk); +#line 700 + size_t nput = ncx_howmany(varp->type, extent); +#line 700 + +#line 700 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 700 + RGN_WRITE, &xp); +#line 700 + if(lstatus != NC_NOERR) +#line 700 + return lstatus; +#line 700 + +#line 700 + lstatus = ncx_putn_schar_float(&xp, nput, value ,fillp); +#line 700 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 700 + { +#line 700 + /* not fatal to the loop */ +#line 700 + status = lstatus; +#line 700 + } +#line 700 + +#line 700 + (void) ncio_rel(ncp->nciop, offset, +#line 700 + RGN_MODIFIED); +#line 700 + +#line 700 + remaining -= extent; +#line 700 + if(remaining == 0) +#line 700 + break; /* normal loop exit */ +#line 700 + offset += (off_t)extent; +#line 700 + value += nput; +#line 700 + +#line 700 + } +#line 700 +#ifdef ERANGE_FILL +#line 700 + free(fillp); +#line 700 +#endif +#line 700 + +#line 700 + return status; +#line 700 +} +#line 700 + +static int +#line 701 +putNCvx_schar_double(NC3_INFO* ncp, const NC_var *varp, +#line 701 + const size_t *start, size_t nelems, const double *value) +#line 701 +{ +#line 701 + off_t offset = NC_varoffset(ncp, varp, start); +#line 701 + size_t remaining = varp->xsz * nelems; +#line 701 + int status = NC_NOERR; +#line 701 + void *xp; +#line 701 + void *fillp=NULL; +#line 701 + +#line 701 + NC_UNUSED(fillp); +#line 701 + +#line 701 + if(nelems == 0) +#line 701 + return NC_NOERR; +#line 701 + +#line 701 + assert(value != NULL); +#line 701 + +#line 701 +#ifdef ERANGE_FILL +#line 701 + fillp = malloc(varp->xsz); +#line 701 + status = NC3_inq_var_fill(varp, fillp); +#line 701 +#endif +#line 701 + +#line 701 + for(;;) +#line 701 + { +#line 701 + size_t extent = MIN(remaining, ncp->chunk); +#line 701 + size_t nput = ncx_howmany(varp->type, extent); +#line 701 + +#line 701 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 701 + RGN_WRITE, &xp); +#line 701 + if(lstatus != NC_NOERR) +#line 701 + return lstatus; +#line 701 + +#line 701 + lstatus = ncx_putn_schar_double(&xp, nput, value ,fillp); +#line 701 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 701 + { +#line 701 + /* not fatal to the loop */ +#line 701 + status = lstatus; +#line 701 + } +#line 701 + +#line 701 + (void) ncio_rel(ncp->nciop, offset, +#line 701 + RGN_MODIFIED); +#line 701 + +#line 701 + remaining -= extent; +#line 701 + if(remaining == 0) +#line 701 + break; /* normal loop exit */ +#line 701 + offset += (off_t)extent; +#line 701 + value += nput; +#line 701 + +#line 701 + } +#line 701 +#ifdef ERANGE_FILL +#line 701 + free(fillp); +#line 701 +#endif +#line 701 + +#line 701 + return status; +#line 701 +} +#line 701 + +static int +#line 702 +putNCvx_schar_longlong(NC3_INFO* ncp, const NC_var *varp, +#line 702 + const size_t *start, size_t nelems, const longlong *value) +#line 702 +{ +#line 702 + off_t offset = NC_varoffset(ncp, varp, start); +#line 702 + size_t remaining = varp->xsz * nelems; +#line 702 + int status = NC_NOERR; +#line 702 + void *xp; +#line 702 + void *fillp=NULL; +#line 702 + +#line 702 + NC_UNUSED(fillp); +#line 702 + +#line 702 + if(nelems == 0) +#line 702 + return NC_NOERR; +#line 702 + +#line 702 + assert(value != NULL); +#line 702 + +#line 702 +#ifdef ERANGE_FILL +#line 702 + fillp = malloc(varp->xsz); +#line 702 + status = NC3_inq_var_fill(varp, fillp); +#line 702 +#endif +#line 702 + +#line 702 + for(;;) +#line 702 + { +#line 702 + size_t extent = MIN(remaining, ncp->chunk); +#line 702 + size_t nput = ncx_howmany(varp->type, extent); +#line 702 + +#line 702 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 702 + RGN_WRITE, &xp); +#line 702 + if(lstatus != NC_NOERR) +#line 702 + return lstatus; +#line 702 + +#line 702 + lstatus = ncx_putn_schar_longlong(&xp, nput, value ,fillp); +#line 702 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 702 + { +#line 702 + /* not fatal to the loop */ +#line 702 + status = lstatus; +#line 702 + } +#line 702 + +#line 702 + (void) ncio_rel(ncp->nciop, offset, +#line 702 + RGN_MODIFIED); +#line 702 + +#line 702 + remaining -= extent; +#line 702 + if(remaining == 0) +#line 702 + break; /* normal loop exit */ +#line 702 + offset += (off_t)extent; +#line 702 + value += nput; +#line 702 + +#line 702 + } +#line 702 +#ifdef ERANGE_FILL +#line 702 + free(fillp); +#line 702 +#endif +#line 702 + +#line 702 + return status; +#line 702 +} +#line 702 + +static int +#line 703 +putNCvx_schar_ushort(NC3_INFO* ncp, const NC_var *varp, +#line 703 + const size_t *start, size_t nelems, const ushort *value) +#line 703 +{ +#line 703 + off_t offset = NC_varoffset(ncp, varp, start); +#line 703 + size_t remaining = varp->xsz * nelems; +#line 703 + int status = NC_NOERR; +#line 703 + void *xp; +#line 703 + void *fillp=NULL; +#line 703 + +#line 703 + NC_UNUSED(fillp); +#line 703 + +#line 703 + if(nelems == 0) +#line 703 + return NC_NOERR; +#line 703 + +#line 703 + assert(value != NULL); +#line 703 + +#line 703 +#ifdef ERANGE_FILL +#line 703 + fillp = malloc(varp->xsz); +#line 703 + status = NC3_inq_var_fill(varp, fillp); +#line 703 +#endif +#line 703 + +#line 703 + for(;;) +#line 703 + { +#line 703 + size_t extent = MIN(remaining, ncp->chunk); +#line 703 + size_t nput = ncx_howmany(varp->type, extent); +#line 703 + +#line 703 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 703 + RGN_WRITE, &xp); +#line 703 + if(lstatus != NC_NOERR) +#line 703 + return lstatus; +#line 703 + +#line 703 + lstatus = ncx_putn_schar_ushort(&xp, nput, value ,fillp); +#line 703 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 703 + { +#line 703 + /* not fatal to the loop */ +#line 703 + status = lstatus; +#line 703 + } +#line 703 + +#line 703 + (void) ncio_rel(ncp->nciop, offset, +#line 703 + RGN_MODIFIED); +#line 703 + +#line 703 + remaining -= extent; +#line 703 + if(remaining == 0) +#line 703 + break; /* normal loop exit */ +#line 703 + offset += (off_t)extent; +#line 703 + value += nput; +#line 703 + +#line 703 + } +#line 703 +#ifdef ERANGE_FILL +#line 703 + free(fillp); +#line 703 +#endif +#line 703 + +#line 703 + return status; +#line 703 +} +#line 703 + +static int +#line 704 +putNCvx_schar_uint(NC3_INFO* ncp, const NC_var *varp, +#line 704 + const size_t *start, size_t nelems, const uint *value) +#line 704 +{ +#line 704 + off_t offset = NC_varoffset(ncp, varp, start); +#line 704 + size_t remaining = varp->xsz * nelems; +#line 704 + int status = NC_NOERR; +#line 704 + void *xp; +#line 704 + void *fillp=NULL; +#line 704 + +#line 704 + NC_UNUSED(fillp); +#line 704 + +#line 704 + if(nelems == 0) +#line 704 + return NC_NOERR; +#line 704 + +#line 704 + assert(value != NULL); +#line 704 + +#line 704 +#ifdef ERANGE_FILL +#line 704 + fillp = malloc(varp->xsz); +#line 704 + status = NC3_inq_var_fill(varp, fillp); +#line 704 +#endif +#line 704 + +#line 704 + for(;;) +#line 704 + { +#line 704 + size_t extent = MIN(remaining, ncp->chunk); +#line 704 + size_t nput = ncx_howmany(varp->type, extent); +#line 704 + +#line 704 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 704 + RGN_WRITE, &xp); +#line 704 + if(lstatus != NC_NOERR) +#line 704 + return lstatus; +#line 704 + +#line 704 + lstatus = ncx_putn_schar_uint(&xp, nput, value ,fillp); +#line 704 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 704 + { +#line 704 + /* not fatal to the loop */ +#line 704 + status = lstatus; +#line 704 + } +#line 704 + +#line 704 + (void) ncio_rel(ncp->nciop, offset, +#line 704 + RGN_MODIFIED); +#line 704 + +#line 704 + remaining -= extent; +#line 704 + if(remaining == 0) +#line 704 + break; /* normal loop exit */ +#line 704 + offset += (off_t)extent; +#line 704 + value += nput; +#line 704 + +#line 704 + } +#line 704 +#ifdef ERANGE_FILL +#line 704 + free(fillp); +#line 704 +#endif +#line 704 + +#line 704 + return status; +#line 704 +} +#line 704 + +static int +#line 705 +putNCvx_schar_ulonglong(NC3_INFO* ncp, const NC_var *varp, +#line 705 + const size_t *start, size_t nelems, const ulonglong *value) +#line 705 +{ +#line 705 + off_t offset = NC_varoffset(ncp, varp, start); +#line 705 + size_t remaining = varp->xsz * nelems; +#line 705 + int status = NC_NOERR; +#line 705 + void *xp; +#line 705 + void *fillp=NULL; +#line 705 + +#line 705 + NC_UNUSED(fillp); +#line 705 + +#line 705 + if(nelems == 0) +#line 705 + return NC_NOERR; +#line 705 + +#line 705 + assert(value != NULL); +#line 705 + +#line 705 +#ifdef ERANGE_FILL +#line 705 + fillp = malloc(varp->xsz); +#line 705 + status = NC3_inq_var_fill(varp, fillp); +#line 705 +#endif +#line 705 + +#line 705 + for(;;) +#line 705 + { +#line 705 + size_t extent = MIN(remaining, ncp->chunk); +#line 705 + size_t nput = ncx_howmany(varp->type, extent); +#line 705 + +#line 705 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 705 + RGN_WRITE, &xp); +#line 705 + if(lstatus != NC_NOERR) +#line 705 + return lstatus; +#line 705 + +#line 705 + lstatus = ncx_putn_schar_ulonglong(&xp, nput, value ,fillp); +#line 705 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 705 + { +#line 705 + /* not fatal to the loop */ +#line 705 + status = lstatus; +#line 705 + } +#line 705 + +#line 705 + (void) ncio_rel(ncp->nciop, offset, +#line 705 + RGN_MODIFIED); +#line 705 + +#line 705 + remaining -= extent; +#line 705 + if(remaining == 0) +#line 705 + break; /* normal loop exit */ +#line 705 + offset += (off_t)extent; +#line 705 + value += nput; +#line 705 + +#line 705 + } +#line 705 +#ifdef ERANGE_FILL +#line 705 + free(fillp); +#line 705 +#endif +#line 705 + +#line 705 + return status; +#line 705 +} +#line 705 + + +static int +#line 707 +putNCvx_short_schar(NC3_INFO* ncp, const NC_var *varp, +#line 707 + const size_t *start, size_t nelems, const schar *value) +#line 707 +{ +#line 707 + off_t offset = NC_varoffset(ncp, varp, start); +#line 707 + size_t remaining = varp->xsz * nelems; +#line 707 + int status = NC_NOERR; +#line 707 + void *xp; +#line 707 + void *fillp=NULL; +#line 707 + +#line 707 + NC_UNUSED(fillp); +#line 707 + +#line 707 + if(nelems == 0) +#line 707 + return NC_NOERR; +#line 707 + +#line 707 + assert(value != NULL); +#line 707 + +#line 707 +#ifdef ERANGE_FILL +#line 707 + fillp = malloc(varp->xsz); +#line 707 + status = NC3_inq_var_fill(varp, fillp); +#line 707 +#endif +#line 707 + +#line 707 + for(;;) +#line 707 + { +#line 707 + size_t extent = MIN(remaining, ncp->chunk); +#line 707 + size_t nput = ncx_howmany(varp->type, extent); +#line 707 + +#line 707 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 707 + RGN_WRITE, &xp); +#line 707 + if(lstatus != NC_NOERR) +#line 707 + return lstatus; +#line 707 + +#line 707 + lstatus = ncx_putn_short_schar(&xp, nput, value ,fillp); +#line 707 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 707 + { +#line 707 + /* not fatal to the loop */ +#line 707 + status = lstatus; +#line 707 + } +#line 707 + +#line 707 + (void) ncio_rel(ncp->nciop, offset, +#line 707 + RGN_MODIFIED); +#line 707 + +#line 707 + remaining -= extent; +#line 707 + if(remaining == 0) +#line 707 + break; /* normal loop exit */ +#line 707 + offset += (off_t)extent; +#line 707 + value += nput; +#line 707 + +#line 707 + } +#line 707 +#ifdef ERANGE_FILL +#line 707 + free(fillp); +#line 707 +#endif +#line 707 + +#line 707 + return status; +#line 707 +} +#line 707 + +static int +#line 708 +putNCvx_short_uchar(NC3_INFO* ncp, const NC_var *varp, +#line 708 + const size_t *start, size_t nelems, const uchar *value) +#line 708 +{ +#line 708 + off_t offset = NC_varoffset(ncp, varp, start); +#line 708 + size_t remaining = varp->xsz * nelems; +#line 708 + int status = NC_NOERR; +#line 708 + void *xp; +#line 708 + void *fillp=NULL; +#line 708 + +#line 708 + NC_UNUSED(fillp); +#line 708 + +#line 708 + if(nelems == 0) +#line 708 + return NC_NOERR; +#line 708 + +#line 708 + assert(value != NULL); +#line 708 + +#line 708 +#ifdef ERANGE_FILL +#line 708 + fillp = malloc(varp->xsz); +#line 708 + status = NC3_inq_var_fill(varp, fillp); +#line 708 +#endif +#line 708 + +#line 708 + for(;;) +#line 708 + { +#line 708 + size_t extent = MIN(remaining, ncp->chunk); +#line 708 + size_t nput = ncx_howmany(varp->type, extent); +#line 708 + +#line 708 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 708 + RGN_WRITE, &xp); +#line 708 + if(lstatus != NC_NOERR) +#line 708 + return lstatus; +#line 708 + +#line 708 + lstatus = ncx_putn_short_uchar(&xp, nput, value ,fillp); +#line 708 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 708 + { +#line 708 + /* not fatal to the loop */ +#line 708 + status = lstatus; +#line 708 + } +#line 708 + +#line 708 + (void) ncio_rel(ncp->nciop, offset, +#line 708 + RGN_MODIFIED); +#line 708 + +#line 708 + remaining -= extent; +#line 708 + if(remaining == 0) +#line 708 + break; /* normal loop exit */ +#line 708 + offset += (off_t)extent; +#line 708 + value += nput; +#line 708 + +#line 708 + } +#line 708 +#ifdef ERANGE_FILL +#line 708 + free(fillp); +#line 708 +#endif +#line 708 + +#line 708 + return status; +#line 708 +} +#line 708 + +static int +#line 709 +putNCvx_short_short(NC3_INFO* ncp, const NC_var *varp, +#line 709 + const size_t *start, size_t nelems, const short *value) +#line 709 +{ +#line 709 + off_t offset = NC_varoffset(ncp, varp, start); +#line 709 + size_t remaining = varp->xsz * nelems; +#line 709 + int status = NC_NOERR; +#line 709 + void *xp; +#line 709 + void *fillp=NULL; +#line 709 + +#line 709 + NC_UNUSED(fillp); +#line 709 + +#line 709 + if(nelems == 0) +#line 709 + return NC_NOERR; +#line 709 + +#line 709 + assert(value != NULL); +#line 709 + +#line 709 +#ifdef ERANGE_FILL +#line 709 + fillp = malloc(varp->xsz); +#line 709 + status = NC3_inq_var_fill(varp, fillp); +#line 709 +#endif +#line 709 + +#line 709 + for(;;) +#line 709 + { +#line 709 + size_t extent = MIN(remaining, ncp->chunk); +#line 709 + size_t nput = ncx_howmany(varp->type, extent); +#line 709 + +#line 709 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 709 + RGN_WRITE, &xp); +#line 709 + if(lstatus != NC_NOERR) +#line 709 + return lstatus; +#line 709 + +#line 709 + lstatus = ncx_putn_short_short(&xp, nput, value ,fillp); +#line 709 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 709 + { +#line 709 + /* not fatal to the loop */ +#line 709 + status = lstatus; +#line 709 + } +#line 709 + +#line 709 + (void) ncio_rel(ncp->nciop, offset, +#line 709 + RGN_MODIFIED); +#line 709 + +#line 709 + remaining -= extent; +#line 709 + if(remaining == 0) +#line 709 + break; /* normal loop exit */ +#line 709 + offset += (off_t)extent; +#line 709 + value += nput; +#line 709 + +#line 709 + } +#line 709 +#ifdef ERANGE_FILL +#line 709 + free(fillp); +#line 709 +#endif +#line 709 + +#line 709 + return status; +#line 709 +} +#line 709 + +static int +#line 710 +putNCvx_short_int(NC3_INFO* ncp, const NC_var *varp, +#line 710 + const size_t *start, size_t nelems, const int *value) +#line 710 +{ +#line 710 + off_t offset = NC_varoffset(ncp, varp, start); +#line 710 + size_t remaining = varp->xsz * nelems; +#line 710 + int status = NC_NOERR; +#line 710 + void *xp; +#line 710 + void *fillp=NULL; +#line 710 + +#line 710 + NC_UNUSED(fillp); +#line 710 + +#line 710 + if(nelems == 0) +#line 710 + return NC_NOERR; +#line 710 + +#line 710 + assert(value != NULL); +#line 710 + +#line 710 +#ifdef ERANGE_FILL +#line 710 + fillp = malloc(varp->xsz); +#line 710 + status = NC3_inq_var_fill(varp, fillp); +#line 710 +#endif +#line 710 + +#line 710 + for(;;) +#line 710 + { +#line 710 + size_t extent = MIN(remaining, ncp->chunk); +#line 710 + size_t nput = ncx_howmany(varp->type, extent); +#line 710 + +#line 710 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 710 + RGN_WRITE, &xp); +#line 710 + if(lstatus != NC_NOERR) +#line 710 + return lstatus; +#line 710 + +#line 710 + lstatus = ncx_putn_short_int(&xp, nput, value ,fillp); +#line 710 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 710 + { +#line 710 + /* not fatal to the loop */ +#line 710 + status = lstatus; +#line 710 + } +#line 710 + +#line 710 + (void) ncio_rel(ncp->nciop, offset, +#line 710 + RGN_MODIFIED); +#line 710 + +#line 710 + remaining -= extent; +#line 710 + if(remaining == 0) +#line 710 + break; /* normal loop exit */ +#line 710 + offset += (off_t)extent; +#line 710 + value += nput; +#line 710 + +#line 710 + } +#line 710 +#ifdef ERANGE_FILL +#line 710 + free(fillp); +#line 710 +#endif +#line 710 + +#line 710 + return status; +#line 710 +} +#line 710 + +static int +#line 711 +putNCvx_short_float(NC3_INFO* ncp, const NC_var *varp, +#line 711 + const size_t *start, size_t nelems, const float *value) +#line 711 +{ +#line 711 + off_t offset = NC_varoffset(ncp, varp, start); +#line 711 + size_t remaining = varp->xsz * nelems; +#line 711 + int status = NC_NOERR; +#line 711 + void *xp; +#line 711 + void *fillp=NULL; +#line 711 + +#line 711 + NC_UNUSED(fillp); +#line 711 + +#line 711 + if(nelems == 0) +#line 711 + return NC_NOERR; +#line 711 + +#line 711 + assert(value != NULL); +#line 711 + +#line 711 +#ifdef ERANGE_FILL +#line 711 + fillp = malloc(varp->xsz); +#line 711 + status = NC3_inq_var_fill(varp, fillp); +#line 711 +#endif +#line 711 + +#line 711 + for(;;) +#line 711 + { +#line 711 + size_t extent = MIN(remaining, ncp->chunk); +#line 711 + size_t nput = ncx_howmany(varp->type, extent); +#line 711 + +#line 711 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 711 + RGN_WRITE, &xp); +#line 711 + if(lstatus != NC_NOERR) +#line 711 + return lstatus; +#line 711 + +#line 711 + lstatus = ncx_putn_short_float(&xp, nput, value ,fillp); +#line 711 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 711 + { +#line 711 + /* not fatal to the loop */ +#line 711 + status = lstatus; +#line 711 + } +#line 711 + +#line 711 + (void) ncio_rel(ncp->nciop, offset, +#line 711 + RGN_MODIFIED); +#line 711 + +#line 711 + remaining -= extent; +#line 711 + if(remaining == 0) +#line 711 + break; /* normal loop exit */ +#line 711 + offset += (off_t)extent; +#line 711 + value += nput; +#line 711 + +#line 711 + } +#line 711 +#ifdef ERANGE_FILL +#line 711 + free(fillp); +#line 711 +#endif +#line 711 + +#line 711 + return status; +#line 711 +} +#line 711 + +static int +#line 712 +putNCvx_short_double(NC3_INFO* ncp, const NC_var *varp, +#line 712 + const size_t *start, size_t nelems, const double *value) +#line 712 +{ +#line 712 + off_t offset = NC_varoffset(ncp, varp, start); +#line 712 + size_t remaining = varp->xsz * nelems; +#line 712 + int status = NC_NOERR; +#line 712 + void *xp; +#line 712 + void *fillp=NULL; +#line 712 + +#line 712 + NC_UNUSED(fillp); +#line 712 + +#line 712 + if(nelems == 0) +#line 712 + return NC_NOERR; +#line 712 + +#line 712 + assert(value != NULL); +#line 712 + +#line 712 +#ifdef ERANGE_FILL +#line 712 + fillp = malloc(varp->xsz); +#line 712 + status = NC3_inq_var_fill(varp, fillp); +#line 712 +#endif +#line 712 + +#line 712 + for(;;) +#line 712 + { +#line 712 + size_t extent = MIN(remaining, ncp->chunk); +#line 712 + size_t nput = ncx_howmany(varp->type, extent); +#line 712 + +#line 712 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 712 + RGN_WRITE, &xp); +#line 712 + if(lstatus != NC_NOERR) +#line 712 + return lstatus; +#line 712 + +#line 712 + lstatus = ncx_putn_short_double(&xp, nput, value ,fillp); +#line 712 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 712 + { +#line 712 + /* not fatal to the loop */ +#line 712 + status = lstatus; +#line 712 + } +#line 712 + +#line 712 + (void) ncio_rel(ncp->nciop, offset, +#line 712 + RGN_MODIFIED); +#line 712 + +#line 712 + remaining -= extent; +#line 712 + if(remaining == 0) +#line 712 + break; /* normal loop exit */ +#line 712 + offset += (off_t)extent; +#line 712 + value += nput; +#line 712 + +#line 712 + } +#line 712 +#ifdef ERANGE_FILL +#line 712 + free(fillp); +#line 712 +#endif +#line 712 + +#line 712 + return status; +#line 712 +} +#line 712 + +static int +#line 713 +putNCvx_short_longlong(NC3_INFO* ncp, const NC_var *varp, +#line 713 + const size_t *start, size_t nelems, const longlong *value) +#line 713 +{ +#line 713 + off_t offset = NC_varoffset(ncp, varp, start); +#line 713 + size_t remaining = varp->xsz * nelems; +#line 713 + int status = NC_NOERR; +#line 713 + void *xp; +#line 713 + void *fillp=NULL; +#line 713 + +#line 713 + NC_UNUSED(fillp); +#line 713 + +#line 713 + if(nelems == 0) +#line 713 + return NC_NOERR; +#line 713 + +#line 713 + assert(value != NULL); +#line 713 + +#line 713 +#ifdef ERANGE_FILL +#line 713 + fillp = malloc(varp->xsz); +#line 713 + status = NC3_inq_var_fill(varp, fillp); +#line 713 +#endif +#line 713 + +#line 713 + for(;;) +#line 713 + { +#line 713 + size_t extent = MIN(remaining, ncp->chunk); +#line 713 + size_t nput = ncx_howmany(varp->type, extent); +#line 713 + +#line 713 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 713 + RGN_WRITE, &xp); +#line 713 + if(lstatus != NC_NOERR) +#line 713 + return lstatus; +#line 713 + +#line 713 + lstatus = ncx_putn_short_longlong(&xp, nput, value ,fillp); +#line 713 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 713 + { +#line 713 + /* not fatal to the loop */ +#line 713 + status = lstatus; +#line 713 + } +#line 713 + +#line 713 + (void) ncio_rel(ncp->nciop, offset, +#line 713 + RGN_MODIFIED); +#line 713 + +#line 713 + remaining -= extent; +#line 713 + if(remaining == 0) +#line 713 + break; /* normal loop exit */ +#line 713 + offset += (off_t)extent; +#line 713 + value += nput; +#line 713 + +#line 713 + } +#line 713 +#ifdef ERANGE_FILL +#line 713 + free(fillp); +#line 713 +#endif +#line 713 + +#line 713 + return status; +#line 713 +} +#line 713 + +static int +#line 714 +putNCvx_short_ushort(NC3_INFO* ncp, const NC_var *varp, +#line 714 + const size_t *start, size_t nelems, const ushort *value) +#line 714 +{ +#line 714 + off_t offset = NC_varoffset(ncp, varp, start); +#line 714 + size_t remaining = varp->xsz * nelems; +#line 714 + int status = NC_NOERR; +#line 714 + void *xp; +#line 714 + void *fillp=NULL; +#line 714 + +#line 714 + NC_UNUSED(fillp); +#line 714 + +#line 714 + if(nelems == 0) +#line 714 + return NC_NOERR; +#line 714 + +#line 714 + assert(value != NULL); +#line 714 + +#line 714 +#ifdef ERANGE_FILL +#line 714 + fillp = malloc(varp->xsz); +#line 714 + status = NC3_inq_var_fill(varp, fillp); +#line 714 +#endif +#line 714 + +#line 714 + for(;;) +#line 714 + { +#line 714 + size_t extent = MIN(remaining, ncp->chunk); +#line 714 + size_t nput = ncx_howmany(varp->type, extent); +#line 714 + +#line 714 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 714 + RGN_WRITE, &xp); +#line 714 + if(lstatus != NC_NOERR) +#line 714 + return lstatus; +#line 714 + +#line 714 + lstatus = ncx_putn_short_ushort(&xp, nput, value ,fillp); +#line 714 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 714 + { +#line 714 + /* not fatal to the loop */ +#line 714 + status = lstatus; +#line 714 + } +#line 714 + +#line 714 + (void) ncio_rel(ncp->nciop, offset, +#line 714 + RGN_MODIFIED); +#line 714 + +#line 714 + remaining -= extent; +#line 714 + if(remaining == 0) +#line 714 + break; /* normal loop exit */ +#line 714 + offset += (off_t)extent; +#line 714 + value += nput; +#line 714 + +#line 714 + } +#line 714 +#ifdef ERANGE_FILL +#line 714 + free(fillp); +#line 714 +#endif +#line 714 + +#line 714 + return status; +#line 714 +} +#line 714 + +static int +#line 715 +putNCvx_short_uint(NC3_INFO* ncp, const NC_var *varp, +#line 715 + const size_t *start, size_t nelems, const uint *value) +#line 715 +{ +#line 715 + off_t offset = NC_varoffset(ncp, varp, start); +#line 715 + size_t remaining = varp->xsz * nelems; +#line 715 + int status = NC_NOERR; +#line 715 + void *xp; +#line 715 + void *fillp=NULL; +#line 715 + +#line 715 + NC_UNUSED(fillp); +#line 715 + +#line 715 + if(nelems == 0) +#line 715 + return NC_NOERR; +#line 715 + +#line 715 + assert(value != NULL); +#line 715 + +#line 715 +#ifdef ERANGE_FILL +#line 715 + fillp = malloc(varp->xsz); +#line 715 + status = NC3_inq_var_fill(varp, fillp); +#line 715 +#endif +#line 715 + +#line 715 + for(;;) +#line 715 + { +#line 715 + size_t extent = MIN(remaining, ncp->chunk); +#line 715 + size_t nput = ncx_howmany(varp->type, extent); +#line 715 + +#line 715 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 715 + RGN_WRITE, &xp); +#line 715 + if(lstatus != NC_NOERR) +#line 715 + return lstatus; +#line 715 + +#line 715 + lstatus = ncx_putn_short_uint(&xp, nput, value ,fillp); +#line 715 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 715 + { +#line 715 + /* not fatal to the loop */ +#line 715 + status = lstatus; +#line 715 + } +#line 715 + +#line 715 + (void) ncio_rel(ncp->nciop, offset, +#line 715 + RGN_MODIFIED); +#line 715 + +#line 715 + remaining -= extent; +#line 715 + if(remaining == 0) +#line 715 + break; /* normal loop exit */ +#line 715 + offset += (off_t)extent; +#line 715 + value += nput; +#line 715 + +#line 715 + } +#line 715 +#ifdef ERANGE_FILL +#line 715 + free(fillp); +#line 715 +#endif +#line 715 + +#line 715 + return status; +#line 715 +} +#line 715 + +static int +#line 716 +putNCvx_short_ulonglong(NC3_INFO* ncp, const NC_var *varp, +#line 716 + const size_t *start, size_t nelems, const ulonglong *value) +#line 716 +{ +#line 716 + off_t offset = NC_varoffset(ncp, varp, start); +#line 716 + size_t remaining = varp->xsz * nelems; +#line 716 + int status = NC_NOERR; +#line 716 + void *xp; +#line 716 + void *fillp=NULL; +#line 716 + +#line 716 + NC_UNUSED(fillp); +#line 716 + +#line 716 + if(nelems == 0) +#line 716 + return NC_NOERR; +#line 716 + +#line 716 + assert(value != NULL); +#line 716 + +#line 716 +#ifdef ERANGE_FILL +#line 716 + fillp = malloc(varp->xsz); +#line 716 + status = NC3_inq_var_fill(varp, fillp); +#line 716 +#endif +#line 716 + +#line 716 + for(;;) +#line 716 + { +#line 716 + size_t extent = MIN(remaining, ncp->chunk); +#line 716 + size_t nput = ncx_howmany(varp->type, extent); +#line 716 + +#line 716 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 716 + RGN_WRITE, &xp); +#line 716 + if(lstatus != NC_NOERR) +#line 716 + return lstatus; +#line 716 + +#line 716 + lstatus = ncx_putn_short_ulonglong(&xp, nput, value ,fillp); +#line 716 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 716 + { +#line 716 + /* not fatal to the loop */ +#line 716 + status = lstatus; +#line 716 + } +#line 716 + +#line 716 + (void) ncio_rel(ncp->nciop, offset, +#line 716 + RGN_MODIFIED); +#line 716 + +#line 716 + remaining -= extent; +#line 716 + if(remaining == 0) +#line 716 + break; /* normal loop exit */ +#line 716 + offset += (off_t)extent; +#line 716 + value += nput; +#line 716 + +#line 716 + } +#line 716 +#ifdef ERANGE_FILL +#line 716 + free(fillp); +#line 716 +#endif +#line 716 + +#line 716 + return status; +#line 716 +} +#line 716 + + +static int +#line 718 +putNCvx_int_schar(NC3_INFO* ncp, const NC_var *varp, +#line 718 + const size_t *start, size_t nelems, const schar *value) +#line 718 +{ +#line 718 + off_t offset = NC_varoffset(ncp, varp, start); +#line 718 + size_t remaining = varp->xsz * nelems; +#line 718 + int status = NC_NOERR; +#line 718 + void *xp; +#line 718 + void *fillp=NULL; +#line 718 + +#line 718 + NC_UNUSED(fillp); +#line 718 + +#line 718 + if(nelems == 0) +#line 718 + return NC_NOERR; +#line 718 + +#line 718 + assert(value != NULL); +#line 718 + +#line 718 +#ifdef ERANGE_FILL +#line 718 + fillp = malloc(varp->xsz); +#line 718 + status = NC3_inq_var_fill(varp, fillp); +#line 718 +#endif +#line 718 + +#line 718 + for(;;) +#line 718 + { +#line 718 + size_t extent = MIN(remaining, ncp->chunk); +#line 718 + size_t nput = ncx_howmany(varp->type, extent); +#line 718 + +#line 718 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 718 + RGN_WRITE, &xp); +#line 718 + if(lstatus != NC_NOERR) +#line 718 + return lstatus; +#line 718 + +#line 718 + lstatus = ncx_putn_int_schar(&xp, nput, value ,fillp); +#line 718 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 718 + { +#line 718 + /* not fatal to the loop */ +#line 718 + status = lstatus; +#line 718 + } +#line 718 + +#line 718 + (void) ncio_rel(ncp->nciop, offset, +#line 718 + RGN_MODIFIED); +#line 718 + +#line 718 + remaining -= extent; +#line 718 + if(remaining == 0) +#line 718 + break; /* normal loop exit */ +#line 718 + offset += (off_t)extent; +#line 718 + value += nput; +#line 718 + +#line 718 + } +#line 718 +#ifdef ERANGE_FILL +#line 718 + free(fillp); +#line 718 +#endif +#line 718 + +#line 718 + return status; +#line 718 +} +#line 718 + +static int +#line 719 +putNCvx_int_uchar(NC3_INFO* ncp, const NC_var *varp, +#line 719 + const size_t *start, size_t nelems, const uchar *value) +#line 719 +{ +#line 719 + off_t offset = NC_varoffset(ncp, varp, start); +#line 719 + size_t remaining = varp->xsz * nelems; +#line 719 + int status = NC_NOERR; +#line 719 + void *xp; +#line 719 + void *fillp=NULL; +#line 719 + +#line 719 + NC_UNUSED(fillp); +#line 719 + +#line 719 + if(nelems == 0) +#line 719 + return NC_NOERR; +#line 719 + +#line 719 + assert(value != NULL); +#line 719 + +#line 719 +#ifdef ERANGE_FILL +#line 719 + fillp = malloc(varp->xsz); +#line 719 + status = NC3_inq_var_fill(varp, fillp); +#line 719 +#endif +#line 719 + +#line 719 + for(;;) +#line 719 + { +#line 719 + size_t extent = MIN(remaining, ncp->chunk); +#line 719 + size_t nput = ncx_howmany(varp->type, extent); +#line 719 + +#line 719 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 719 + RGN_WRITE, &xp); +#line 719 + if(lstatus != NC_NOERR) +#line 719 + return lstatus; +#line 719 + +#line 719 + lstatus = ncx_putn_int_uchar(&xp, nput, value ,fillp); +#line 719 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 719 + { +#line 719 + /* not fatal to the loop */ +#line 719 + status = lstatus; +#line 719 + } +#line 719 + +#line 719 + (void) ncio_rel(ncp->nciop, offset, +#line 719 + RGN_MODIFIED); +#line 719 + +#line 719 + remaining -= extent; +#line 719 + if(remaining == 0) +#line 719 + break; /* normal loop exit */ +#line 719 + offset += (off_t)extent; +#line 719 + value += nput; +#line 719 + +#line 719 + } +#line 719 +#ifdef ERANGE_FILL +#line 719 + free(fillp); +#line 719 +#endif +#line 719 + +#line 719 + return status; +#line 719 +} +#line 719 + +static int +#line 720 +putNCvx_int_short(NC3_INFO* ncp, const NC_var *varp, +#line 720 + const size_t *start, size_t nelems, const short *value) +#line 720 +{ +#line 720 + off_t offset = NC_varoffset(ncp, varp, start); +#line 720 + size_t remaining = varp->xsz * nelems; +#line 720 + int status = NC_NOERR; +#line 720 + void *xp; +#line 720 + void *fillp=NULL; +#line 720 + +#line 720 + NC_UNUSED(fillp); +#line 720 + +#line 720 + if(nelems == 0) +#line 720 + return NC_NOERR; +#line 720 + +#line 720 + assert(value != NULL); +#line 720 + +#line 720 +#ifdef ERANGE_FILL +#line 720 + fillp = malloc(varp->xsz); +#line 720 + status = NC3_inq_var_fill(varp, fillp); +#line 720 +#endif +#line 720 + +#line 720 + for(;;) +#line 720 + { +#line 720 + size_t extent = MIN(remaining, ncp->chunk); +#line 720 + size_t nput = ncx_howmany(varp->type, extent); +#line 720 + +#line 720 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 720 + RGN_WRITE, &xp); +#line 720 + if(lstatus != NC_NOERR) +#line 720 + return lstatus; +#line 720 + +#line 720 + lstatus = ncx_putn_int_short(&xp, nput, value ,fillp); +#line 720 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 720 + { +#line 720 + /* not fatal to the loop */ +#line 720 + status = lstatus; +#line 720 + } +#line 720 + +#line 720 + (void) ncio_rel(ncp->nciop, offset, +#line 720 + RGN_MODIFIED); +#line 720 + +#line 720 + remaining -= extent; +#line 720 + if(remaining == 0) +#line 720 + break; /* normal loop exit */ +#line 720 + offset += (off_t)extent; +#line 720 + value += nput; +#line 720 + +#line 720 + } +#line 720 +#ifdef ERANGE_FILL +#line 720 + free(fillp); +#line 720 +#endif +#line 720 + +#line 720 + return status; +#line 720 +} +#line 720 + +static int +#line 721 +putNCvx_int_int(NC3_INFO* ncp, const NC_var *varp, +#line 721 + const size_t *start, size_t nelems, const int *value) +#line 721 +{ +#line 721 + off_t offset = NC_varoffset(ncp, varp, start); +#line 721 + size_t remaining = varp->xsz * nelems; +#line 721 + int status = NC_NOERR; +#line 721 + void *xp; +#line 721 + void *fillp=NULL; +#line 721 + +#line 721 + NC_UNUSED(fillp); +#line 721 + +#line 721 + if(nelems == 0) +#line 721 + return NC_NOERR; +#line 721 + +#line 721 + assert(value != NULL); +#line 721 + +#line 721 +#ifdef ERANGE_FILL +#line 721 + fillp = malloc(varp->xsz); +#line 721 + status = NC3_inq_var_fill(varp, fillp); +#line 721 +#endif +#line 721 + +#line 721 + for(;;) +#line 721 + { +#line 721 + size_t extent = MIN(remaining, ncp->chunk); +#line 721 + size_t nput = ncx_howmany(varp->type, extent); +#line 721 + +#line 721 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 721 + RGN_WRITE, &xp); +#line 721 + if(lstatus != NC_NOERR) +#line 721 + return lstatus; +#line 721 + +#line 721 + lstatus = ncx_putn_int_int(&xp, nput, value ,fillp); +#line 721 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 721 + { +#line 721 + /* not fatal to the loop */ +#line 721 + status = lstatus; +#line 721 + } +#line 721 + +#line 721 + (void) ncio_rel(ncp->nciop, offset, +#line 721 + RGN_MODIFIED); +#line 721 + +#line 721 + remaining -= extent; +#line 721 + if(remaining == 0) +#line 721 + break; /* normal loop exit */ +#line 721 + offset += (off_t)extent; +#line 721 + value += nput; +#line 721 + +#line 721 + } +#line 721 +#ifdef ERANGE_FILL +#line 721 + free(fillp); +#line 721 +#endif +#line 721 + +#line 721 + return status; +#line 721 +} +#line 721 + +static int +#line 722 +putNCvx_int_float(NC3_INFO* ncp, const NC_var *varp, +#line 722 + const size_t *start, size_t nelems, const float *value) +#line 722 +{ +#line 722 + off_t offset = NC_varoffset(ncp, varp, start); +#line 722 + size_t remaining = varp->xsz * nelems; +#line 722 + int status = NC_NOERR; +#line 722 + void *xp; +#line 722 + void *fillp=NULL; +#line 722 + +#line 722 + NC_UNUSED(fillp); +#line 722 + +#line 722 + if(nelems == 0) +#line 722 + return NC_NOERR; +#line 722 + +#line 722 + assert(value != NULL); +#line 722 + +#line 722 +#ifdef ERANGE_FILL +#line 722 + fillp = malloc(varp->xsz); +#line 722 + status = NC3_inq_var_fill(varp, fillp); +#line 722 +#endif +#line 722 + +#line 722 + for(;;) +#line 722 + { +#line 722 + size_t extent = MIN(remaining, ncp->chunk); +#line 722 + size_t nput = ncx_howmany(varp->type, extent); +#line 722 + +#line 722 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 722 + RGN_WRITE, &xp); +#line 722 + if(lstatus != NC_NOERR) +#line 722 + return lstatus; +#line 722 + +#line 722 + lstatus = ncx_putn_int_float(&xp, nput, value ,fillp); +#line 722 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 722 + { +#line 722 + /* not fatal to the loop */ +#line 722 + status = lstatus; +#line 722 + } +#line 722 + +#line 722 + (void) ncio_rel(ncp->nciop, offset, +#line 722 + RGN_MODIFIED); +#line 722 + +#line 722 + remaining -= extent; +#line 722 + if(remaining == 0) +#line 722 + break; /* normal loop exit */ +#line 722 + offset += (off_t)extent; +#line 722 + value += nput; +#line 722 + +#line 722 + } +#line 722 +#ifdef ERANGE_FILL +#line 722 + free(fillp); +#line 722 +#endif +#line 722 + +#line 722 + return status; +#line 722 +} +#line 722 + +static int +#line 723 +putNCvx_int_double(NC3_INFO* ncp, const NC_var *varp, +#line 723 + const size_t *start, size_t nelems, const double *value) +#line 723 +{ +#line 723 + off_t offset = NC_varoffset(ncp, varp, start); +#line 723 + size_t remaining = varp->xsz * nelems; +#line 723 + int status = NC_NOERR; +#line 723 + void *xp; +#line 723 + void *fillp=NULL; +#line 723 + +#line 723 + NC_UNUSED(fillp); +#line 723 + +#line 723 + if(nelems == 0) +#line 723 + return NC_NOERR; +#line 723 + +#line 723 + assert(value != NULL); +#line 723 + +#line 723 +#ifdef ERANGE_FILL +#line 723 + fillp = malloc(varp->xsz); +#line 723 + status = NC3_inq_var_fill(varp, fillp); +#line 723 +#endif +#line 723 + +#line 723 + for(;;) +#line 723 + { +#line 723 + size_t extent = MIN(remaining, ncp->chunk); +#line 723 + size_t nput = ncx_howmany(varp->type, extent); +#line 723 + +#line 723 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 723 + RGN_WRITE, &xp); +#line 723 + if(lstatus != NC_NOERR) +#line 723 + return lstatus; +#line 723 + +#line 723 + lstatus = ncx_putn_int_double(&xp, nput, value ,fillp); +#line 723 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 723 + { +#line 723 + /* not fatal to the loop */ +#line 723 + status = lstatus; +#line 723 + } +#line 723 + +#line 723 + (void) ncio_rel(ncp->nciop, offset, +#line 723 + RGN_MODIFIED); +#line 723 + +#line 723 + remaining -= extent; +#line 723 + if(remaining == 0) +#line 723 + break; /* normal loop exit */ +#line 723 + offset += (off_t)extent; +#line 723 + value += nput; +#line 723 + +#line 723 + } +#line 723 +#ifdef ERANGE_FILL +#line 723 + free(fillp); +#line 723 +#endif +#line 723 + +#line 723 + return status; +#line 723 +} +#line 723 + +static int +#line 724 +putNCvx_int_longlong(NC3_INFO* ncp, const NC_var *varp, +#line 724 + const size_t *start, size_t nelems, const longlong *value) +#line 724 +{ +#line 724 + off_t offset = NC_varoffset(ncp, varp, start); +#line 724 + size_t remaining = varp->xsz * nelems; +#line 724 + int status = NC_NOERR; +#line 724 + void *xp; +#line 724 + void *fillp=NULL; +#line 724 + +#line 724 + NC_UNUSED(fillp); +#line 724 + +#line 724 + if(nelems == 0) +#line 724 + return NC_NOERR; +#line 724 + +#line 724 + assert(value != NULL); +#line 724 + +#line 724 +#ifdef ERANGE_FILL +#line 724 + fillp = malloc(varp->xsz); +#line 724 + status = NC3_inq_var_fill(varp, fillp); +#line 724 +#endif +#line 724 + +#line 724 + for(;;) +#line 724 + { +#line 724 + size_t extent = MIN(remaining, ncp->chunk); +#line 724 + size_t nput = ncx_howmany(varp->type, extent); +#line 724 + +#line 724 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 724 + RGN_WRITE, &xp); +#line 724 + if(lstatus != NC_NOERR) +#line 724 + return lstatus; +#line 724 + +#line 724 + lstatus = ncx_putn_int_longlong(&xp, nput, value ,fillp); +#line 724 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 724 + { +#line 724 + /* not fatal to the loop */ +#line 724 + status = lstatus; +#line 724 + } +#line 724 + +#line 724 + (void) ncio_rel(ncp->nciop, offset, +#line 724 + RGN_MODIFIED); +#line 724 + +#line 724 + remaining -= extent; +#line 724 + if(remaining == 0) +#line 724 + break; /* normal loop exit */ +#line 724 + offset += (off_t)extent; +#line 724 + value += nput; +#line 724 + +#line 724 + } +#line 724 +#ifdef ERANGE_FILL +#line 724 + free(fillp); +#line 724 +#endif +#line 724 + +#line 724 + return status; +#line 724 +} +#line 724 + +static int +#line 725 +putNCvx_int_ushort(NC3_INFO* ncp, const NC_var *varp, +#line 725 + const size_t *start, size_t nelems, const ushort *value) +#line 725 +{ +#line 725 + off_t offset = NC_varoffset(ncp, varp, start); +#line 725 + size_t remaining = varp->xsz * nelems; +#line 725 + int status = NC_NOERR; +#line 725 + void *xp; +#line 725 + void *fillp=NULL; +#line 725 + +#line 725 + NC_UNUSED(fillp); +#line 725 + +#line 725 + if(nelems == 0) +#line 725 + return NC_NOERR; +#line 725 + +#line 725 + assert(value != NULL); +#line 725 + +#line 725 +#ifdef ERANGE_FILL +#line 725 + fillp = malloc(varp->xsz); +#line 725 + status = NC3_inq_var_fill(varp, fillp); +#line 725 +#endif +#line 725 + +#line 725 + for(;;) +#line 725 + { +#line 725 + size_t extent = MIN(remaining, ncp->chunk); +#line 725 + size_t nput = ncx_howmany(varp->type, extent); +#line 725 + +#line 725 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 725 + RGN_WRITE, &xp); +#line 725 + if(lstatus != NC_NOERR) +#line 725 + return lstatus; +#line 725 + +#line 725 + lstatus = ncx_putn_int_ushort(&xp, nput, value ,fillp); +#line 725 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 725 + { +#line 725 + /* not fatal to the loop */ +#line 725 + status = lstatus; +#line 725 + } +#line 725 + +#line 725 + (void) ncio_rel(ncp->nciop, offset, +#line 725 + RGN_MODIFIED); +#line 725 + +#line 725 + remaining -= extent; +#line 725 + if(remaining == 0) +#line 725 + break; /* normal loop exit */ +#line 725 + offset += (off_t)extent; +#line 725 + value += nput; +#line 725 + +#line 725 + } +#line 725 +#ifdef ERANGE_FILL +#line 725 + free(fillp); +#line 725 +#endif +#line 725 + +#line 725 + return status; +#line 725 +} +#line 725 + +static int +#line 726 +putNCvx_int_uint(NC3_INFO* ncp, const NC_var *varp, +#line 726 + const size_t *start, size_t nelems, const uint *value) +#line 726 +{ +#line 726 + off_t offset = NC_varoffset(ncp, varp, start); +#line 726 + size_t remaining = varp->xsz * nelems; +#line 726 + int status = NC_NOERR; +#line 726 + void *xp; +#line 726 + void *fillp=NULL; +#line 726 + +#line 726 + NC_UNUSED(fillp); +#line 726 + +#line 726 + if(nelems == 0) +#line 726 + return NC_NOERR; +#line 726 + +#line 726 + assert(value != NULL); +#line 726 + +#line 726 +#ifdef ERANGE_FILL +#line 726 + fillp = malloc(varp->xsz); +#line 726 + status = NC3_inq_var_fill(varp, fillp); +#line 726 +#endif +#line 726 + +#line 726 + for(;;) +#line 726 + { +#line 726 + size_t extent = MIN(remaining, ncp->chunk); +#line 726 + size_t nput = ncx_howmany(varp->type, extent); +#line 726 + +#line 726 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 726 + RGN_WRITE, &xp); +#line 726 + if(lstatus != NC_NOERR) +#line 726 + return lstatus; +#line 726 + +#line 726 + lstatus = ncx_putn_int_uint(&xp, nput, value ,fillp); +#line 726 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 726 + { +#line 726 + /* not fatal to the loop */ +#line 726 + status = lstatus; +#line 726 + } +#line 726 + +#line 726 + (void) ncio_rel(ncp->nciop, offset, +#line 726 + RGN_MODIFIED); +#line 726 + +#line 726 + remaining -= extent; +#line 726 + if(remaining == 0) +#line 726 + break; /* normal loop exit */ +#line 726 + offset += (off_t)extent; +#line 726 + value += nput; +#line 726 + +#line 726 + } +#line 726 +#ifdef ERANGE_FILL +#line 726 + free(fillp); +#line 726 +#endif +#line 726 + +#line 726 + return status; +#line 726 +} +#line 726 + +static int +#line 727 +putNCvx_int_ulonglong(NC3_INFO* ncp, const NC_var *varp, +#line 727 + const size_t *start, size_t nelems, const ulonglong *value) +#line 727 +{ +#line 727 + off_t offset = NC_varoffset(ncp, varp, start); +#line 727 + size_t remaining = varp->xsz * nelems; +#line 727 + int status = NC_NOERR; +#line 727 + void *xp; +#line 727 + void *fillp=NULL; +#line 727 + +#line 727 + NC_UNUSED(fillp); +#line 727 + +#line 727 + if(nelems == 0) +#line 727 + return NC_NOERR; +#line 727 + +#line 727 + assert(value != NULL); +#line 727 + +#line 727 +#ifdef ERANGE_FILL +#line 727 + fillp = malloc(varp->xsz); +#line 727 + status = NC3_inq_var_fill(varp, fillp); +#line 727 +#endif +#line 727 + +#line 727 + for(;;) +#line 727 + { +#line 727 + size_t extent = MIN(remaining, ncp->chunk); +#line 727 + size_t nput = ncx_howmany(varp->type, extent); +#line 727 + +#line 727 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 727 + RGN_WRITE, &xp); +#line 727 + if(lstatus != NC_NOERR) +#line 727 + return lstatus; +#line 727 + +#line 727 + lstatus = ncx_putn_int_ulonglong(&xp, nput, value ,fillp); +#line 727 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 727 + { +#line 727 + /* not fatal to the loop */ +#line 727 + status = lstatus; +#line 727 + } +#line 727 + +#line 727 + (void) ncio_rel(ncp->nciop, offset, +#line 727 + RGN_MODIFIED); +#line 727 + +#line 727 + remaining -= extent; +#line 727 + if(remaining == 0) +#line 727 + break; /* normal loop exit */ +#line 727 + offset += (off_t)extent; +#line 727 + value += nput; +#line 727 + +#line 727 + } +#line 727 +#ifdef ERANGE_FILL +#line 727 + free(fillp); +#line 727 +#endif +#line 727 + +#line 727 + return status; +#line 727 +} +#line 727 + + +static int +#line 729 +putNCvx_float_schar(NC3_INFO* ncp, const NC_var *varp, +#line 729 + const size_t *start, size_t nelems, const schar *value) +#line 729 +{ +#line 729 + off_t offset = NC_varoffset(ncp, varp, start); +#line 729 + size_t remaining = varp->xsz * nelems; +#line 729 + int status = NC_NOERR; +#line 729 + void *xp; +#line 729 + void *fillp=NULL; +#line 729 + +#line 729 + NC_UNUSED(fillp); +#line 729 + +#line 729 + if(nelems == 0) +#line 729 + return NC_NOERR; +#line 729 + +#line 729 + assert(value != NULL); +#line 729 + +#line 729 +#ifdef ERANGE_FILL +#line 729 + fillp = malloc(varp->xsz); +#line 729 + status = NC3_inq_var_fill(varp, fillp); +#line 729 +#endif +#line 729 + +#line 729 + for(;;) +#line 729 + { +#line 729 + size_t extent = MIN(remaining, ncp->chunk); +#line 729 + size_t nput = ncx_howmany(varp->type, extent); +#line 729 + +#line 729 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 729 + RGN_WRITE, &xp); +#line 729 + if(lstatus != NC_NOERR) +#line 729 + return lstatus; +#line 729 + +#line 729 + lstatus = ncx_putn_float_schar(&xp, nput, value ,fillp); +#line 729 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 729 + { +#line 729 + /* not fatal to the loop */ +#line 729 + status = lstatus; +#line 729 + } +#line 729 + +#line 729 + (void) ncio_rel(ncp->nciop, offset, +#line 729 + RGN_MODIFIED); +#line 729 + +#line 729 + remaining -= extent; +#line 729 + if(remaining == 0) +#line 729 + break; /* normal loop exit */ +#line 729 + offset += (off_t)extent; +#line 729 + value += nput; +#line 729 + +#line 729 + } +#line 729 +#ifdef ERANGE_FILL +#line 729 + free(fillp); +#line 729 +#endif +#line 729 + +#line 729 + return status; +#line 729 +} +#line 729 + +static int +#line 730 +putNCvx_float_uchar(NC3_INFO* ncp, const NC_var *varp, +#line 730 + const size_t *start, size_t nelems, const uchar *value) +#line 730 +{ +#line 730 + off_t offset = NC_varoffset(ncp, varp, start); +#line 730 + size_t remaining = varp->xsz * nelems; +#line 730 + int status = NC_NOERR; +#line 730 + void *xp; +#line 730 + void *fillp=NULL; +#line 730 + +#line 730 + NC_UNUSED(fillp); +#line 730 + +#line 730 + if(nelems == 0) +#line 730 + return NC_NOERR; +#line 730 + +#line 730 + assert(value != NULL); +#line 730 + +#line 730 +#ifdef ERANGE_FILL +#line 730 + fillp = malloc(varp->xsz); +#line 730 + status = NC3_inq_var_fill(varp, fillp); +#line 730 +#endif +#line 730 + +#line 730 + for(;;) +#line 730 + { +#line 730 + size_t extent = MIN(remaining, ncp->chunk); +#line 730 + size_t nput = ncx_howmany(varp->type, extent); +#line 730 + +#line 730 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 730 + RGN_WRITE, &xp); +#line 730 + if(lstatus != NC_NOERR) +#line 730 + return lstatus; +#line 730 + +#line 730 + lstatus = ncx_putn_float_uchar(&xp, nput, value ,fillp); +#line 730 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 730 + { +#line 730 + /* not fatal to the loop */ +#line 730 + status = lstatus; +#line 730 + } +#line 730 + +#line 730 + (void) ncio_rel(ncp->nciop, offset, +#line 730 + RGN_MODIFIED); +#line 730 + +#line 730 + remaining -= extent; +#line 730 + if(remaining == 0) +#line 730 + break; /* normal loop exit */ +#line 730 + offset += (off_t)extent; +#line 730 + value += nput; +#line 730 + +#line 730 + } +#line 730 +#ifdef ERANGE_FILL +#line 730 + free(fillp); +#line 730 +#endif +#line 730 + +#line 730 + return status; +#line 730 +} +#line 730 + +static int +#line 731 +putNCvx_float_short(NC3_INFO* ncp, const NC_var *varp, +#line 731 + const size_t *start, size_t nelems, const short *value) +#line 731 +{ +#line 731 + off_t offset = NC_varoffset(ncp, varp, start); +#line 731 + size_t remaining = varp->xsz * nelems; +#line 731 + int status = NC_NOERR; +#line 731 + void *xp; +#line 731 + void *fillp=NULL; +#line 731 + +#line 731 + NC_UNUSED(fillp); +#line 731 + +#line 731 + if(nelems == 0) +#line 731 + return NC_NOERR; +#line 731 + +#line 731 + assert(value != NULL); +#line 731 + +#line 731 +#ifdef ERANGE_FILL +#line 731 + fillp = malloc(varp->xsz); +#line 731 + status = NC3_inq_var_fill(varp, fillp); +#line 731 +#endif +#line 731 + +#line 731 + for(;;) +#line 731 + { +#line 731 + size_t extent = MIN(remaining, ncp->chunk); +#line 731 + size_t nput = ncx_howmany(varp->type, extent); +#line 731 + +#line 731 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 731 + RGN_WRITE, &xp); +#line 731 + if(lstatus != NC_NOERR) +#line 731 + return lstatus; +#line 731 + +#line 731 + lstatus = ncx_putn_float_short(&xp, nput, value ,fillp); +#line 731 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 731 + { +#line 731 + /* not fatal to the loop */ +#line 731 + status = lstatus; +#line 731 + } +#line 731 + +#line 731 + (void) ncio_rel(ncp->nciop, offset, +#line 731 + RGN_MODIFIED); +#line 731 + +#line 731 + remaining -= extent; +#line 731 + if(remaining == 0) +#line 731 + break; /* normal loop exit */ +#line 731 + offset += (off_t)extent; +#line 731 + value += nput; +#line 731 + +#line 731 + } +#line 731 +#ifdef ERANGE_FILL +#line 731 + free(fillp); +#line 731 +#endif +#line 731 + +#line 731 + return status; +#line 731 +} +#line 731 + +static int +#line 732 +putNCvx_float_int(NC3_INFO* ncp, const NC_var *varp, +#line 732 + const size_t *start, size_t nelems, const int *value) +#line 732 +{ +#line 732 + off_t offset = NC_varoffset(ncp, varp, start); +#line 732 + size_t remaining = varp->xsz * nelems; +#line 732 + int status = NC_NOERR; +#line 732 + void *xp; +#line 732 + void *fillp=NULL; +#line 732 + +#line 732 + NC_UNUSED(fillp); +#line 732 + +#line 732 + if(nelems == 0) +#line 732 + return NC_NOERR; +#line 732 + +#line 732 + assert(value != NULL); +#line 732 + +#line 732 +#ifdef ERANGE_FILL +#line 732 + fillp = malloc(varp->xsz); +#line 732 + status = NC3_inq_var_fill(varp, fillp); +#line 732 +#endif +#line 732 + +#line 732 + for(;;) +#line 732 + { +#line 732 + size_t extent = MIN(remaining, ncp->chunk); +#line 732 + size_t nput = ncx_howmany(varp->type, extent); +#line 732 + +#line 732 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 732 + RGN_WRITE, &xp); +#line 732 + if(lstatus != NC_NOERR) +#line 732 + return lstatus; +#line 732 + +#line 732 + lstatus = ncx_putn_float_int(&xp, nput, value ,fillp); +#line 732 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 732 + { +#line 732 + /* not fatal to the loop */ +#line 732 + status = lstatus; +#line 732 + } +#line 732 + +#line 732 + (void) ncio_rel(ncp->nciop, offset, +#line 732 + RGN_MODIFIED); +#line 732 + +#line 732 + remaining -= extent; +#line 732 + if(remaining == 0) +#line 732 + break; /* normal loop exit */ +#line 732 + offset += (off_t)extent; +#line 732 + value += nput; +#line 732 + +#line 732 + } +#line 732 +#ifdef ERANGE_FILL +#line 732 + free(fillp); +#line 732 +#endif +#line 732 + +#line 732 + return status; +#line 732 +} +#line 732 + +static int +#line 733 +putNCvx_float_float(NC3_INFO* ncp, const NC_var *varp, +#line 733 + const size_t *start, size_t nelems, const float *value) +#line 733 +{ +#line 733 + off_t offset = NC_varoffset(ncp, varp, start); +#line 733 + size_t remaining = varp->xsz * nelems; +#line 733 + int status = NC_NOERR; +#line 733 + void *xp; +#line 733 + void *fillp=NULL; +#line 733 + +#line 733 + NC_UNUSED(fillp); +#line 733 + +#line 733 + if(nelems == 0) +#line 733 + return NC_NOERR; +#line 733 + +#line 733 + assert(value != NULL); +#line 733 + +#line 733 +#ifdef ERANGE_FILL +#line 733 + fillp = malloc(varp->xsz); +#line 733 + status = NC3_inq_var_fill(varp, fillp); +#line 733 +#endif +#line 733 + +#line 733 + for(;;) +#line 733 + { +#line 733 + size_t extent = MIN(remaining, ncp->chunk); +#line 733 + size_t nput = ncx_howmany(varp->type, extent); +#line 733 + +#line 733 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 733 + RGN_WRITE, &xp); +#line 733 + if(lstatus != NC_NOERR) +#line 733 + return lstatus; +#line 733 + +#line 733 + lstatus = ncx_putn_float_float(&xp, nput, value ,fillp); +#line 733 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 733 + { +#line 733 + /* not fatal to the loop */ +#line 733 + status = lstatus; +#line 733 + } +#line 733 + +#line 733 + (void) ncio_rel(ncp->nciop, offset, +#line 733 + RGN_MODIFIED); +#line 733 + +#line 733 + remaining -= extent; +#line 733 + if(remaining == 0) +#line 733 + break; /* normal loop exit */ +#line 733 + offset += (off_t)extent; +#line 733 + value += nput; +#line 733 + +#line 733 + } +#line 733 +#ifdef ERANGE_FILL +#line 733 + free(fillp); +#line 733 +#endif +#line 733 + +#line 733 + return status; +#line 733 +} +#line 733 + +static int +#line 734 +putNCvx_float_double(NC3_INFO* ncp, const NC_var *varp, +#line 734 + const size_t *start, size_t nelems, const double *value) +#line 734 +{ +#line 734 + off_t offset = NC_varoffset(ncp, varp, start); +#line 734 + size_t remaining = varp->xsz * nelems; +#line 734 + int status = NC_NOERR; +#line 734 + void *xp; +#line 734 + void *fillp=NULL; +#line 734 + +#line 734 + NC_UNUSED(fillp); +#line 734 + +#line 734 + if(nelems == 0) +#line 734 + return NC_NOERR; +#line 734 + +#line 734 + assert(value != NULL); +#line 734 + +#line 734 +#ifdef ERANGE_FILL +#line 734 + fillp = malloc(varp->xsz); +#line 734 + status = NC3_inq_var_fill(varp, fillp); +#line 734 +#endif +#line 734 + +#line 734 + for(;;) +#line 734 + { +#line 734 + size_t extent = MIN(remaining, ncp->chunk); +#line 734 + size_t nput = ncx_howmany(varp->type, extent); +#line 734 + +#line 734 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 734 + RGN_WRITE, &xp); +#line 734 + if(lstatus != NC_NOERR) +#line 734 + return lstatus; +#line 734 + +#line 734 + lstatus = ncx_putn_float_double(&xp, nput, value ,fillp); +#line 734 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 734 + { +#line 734 + /* not fatal to the loop */ +#line 734 + status = lstatus; +#line 734 + } +#line 734 + +#line 734 + (void) ncio_rel(ncp->nciop, offset, +#line 734 + RGN_MODIFIED); +#line 734 + +#line 734 + remaining -= extent; +#line 734 + if(remaining == 0) +#line 734 + break; /* normal loop exit */ +#line 734 + offset += (off_t)extent; +#line 734 + value += nput; +#line 734 + +#line 734 + } +#line 734 +#ifdef ERANGE_FILL +#line 734 + free(fillp); +#line 734 +#endif +#line 734 + +#line 734 + return status; +#line 734 +} +#line 734 + +static int +#line 735 +putNCvx_float_longlong(NC3_INFO* ncp, const NC_var *varp, +#line 735 + const size_t *start, size_t nelems, const longlong *value) +#line 735 +{ +#line 735 + off_t offset = NC_varoffset(ncp, varp, start); +#line 735 + size_t remaining = varp->xsz * nelems; +#line 735 + int status = NC_NOERR; +#line 735 + void *xp; +#line 735 + void *fillp=NULL; +#line 735 + +#line 735 + NC_UNUSED(fillp); +#line 735 + +#line 735 + if(nelems == 0) +#line 735 + return NC_NOERR; +#line 735 + +#line 735 + assert(value != NULL); +#line 735 + +#line 735 +#ifdef ERANGE_FILL +#line 735 + fillp = malloc(varp->xsz); +#line 735 + status = NC3_inq_var_fill(varp, fillp); +#line 735 +#endif +#line 735 + +#line 735 + for(;;) +#line 735 + { +#line 735 + size_t extent = MIN(remaining, ncp->chunk); +#line 735 + size_t nput = ncx_howmany(varp->type, extent); +#line 735 + +#line 735 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 735 + RGN_WRITE, &xp); +#line 735 + if(lstatus != NC_NOERR) +#line 735 + return lstatus; +#line 735 + +#line 735 + lstatus = ncx_putn_float_longlong(&xp, nput, value ,fillp); +#line 735 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 735 + { +#line 735 + /* not fatal to the loop */ +#line 735 + status = lstatus; +#line 735 + } +#line 735 + +#line 735 + (void) ncio_rel(ncp->nciop, offset, +#line 735 + RGN_MODIFIED); +#line 735 + +#line 735 + remaining -= extent; +#line 735 + if(remaining == 0) +#line 735 + break; /* normal loop exit */ +#line 735 + offset += (off_t)extent; +#line 735 + value += nput; +#line 735 + +#line 735 + } +#line 735 +#ifdef ERANGE_FILL +#line 735 + free(fillp); +#line 735 +#endif +#line 735 + +#line 735 + return status; +#line 735 +} +#line 735 + +static int +#line 736 +putNCvx_float_ushort(NC3_INFO* ncp, const NC_var *varp, +#line 736 + const size_t *start, size_t nelems, const ushort *value) +#line 736 +{ +#line 736 + off_t offset = NC_varoffset(ncp, varp, start); +#line 736 + size_t remaining = varp->xsz * nelems; +#line 736 + int status = NC_NOERR; +#line 736 + void *xp; +#line 736 + void *fillp=NULL; +#line 736 + +#line 736 + NC_UNUSED(fillp); +#line 736 + +#line 736 + if(nelems == 0) +#line 736 + return NC_NOERR; +#line 736 + +#line 736 + assert(value != NULL); +#line 736 + +#line 736 +#ifdef ERANGE_FILL +#line 736 + fillp = malloc(varp->xsz); +#line 736 + status = NC3_inq_var_fill(varp, fillp); +#line 736 +#endif +#line 736 + +#line 736 + for(;;) +#line 736 + { +#line 736 + size_t extent = MIN(remaining, ncp->chunk); +#line 736 + size_t nput = ncx_howmany(varp->type, extent); +#line 736 + +#line 736 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 736 + RGN_WRITE, &xp); +#line 736 + if(lstatus != NC_NOERR) +#line 736 + return lstatus; +#line 736 + +#line 736 + lstatus = ncx_putn_float_ushort(&xp, nput, value ,fillp); +#line 736 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 736 + { +#line 736 + /* not fatal to the loop */ +#line 736 + status = lstatus; +#line 736 + } +#line 736 + +#line 736 + (void) ncio_rel(ncp->nciop, offset, +#line 736 + RGN_MODIFIED); +#line 736 + +#line 736 + remaining -= extent; +#line 736 + if(remaining == 0) +#line 736 + break; /* normal loop exit */ +#line 736 + offset += (off_t)extent; +#line 736 + value += nput; +#line 736 + +#line 736 + } +#line 736 +#ifdef ERANGE_FILL +#line 736 + free(fillp); +#line 736 +#endif +#line 736 + +#line 736 + return status; +#line 736 +} +#line 736 + +static int +#line 737 +putNCvx_float_uint(NC3_INFO* ncp, const NC_var *varp, +#line 737 + const size_t *start, size_t nelems, const uint *value) +#line 737 +{ +#line 737 + off_t offset = NC_varoffset(ncp, varp, start); +#line 737 + size_t remaining = varp->xsz * nelems; +#line 737 + int status = NC_NOERR; +#line 737 + void *xp; +#line 737 + void *fillp=NULL; +#line 737 + +#line 737 + NC_UNUSED(fillp); +#line 737 + +#line 737 + if(nelems == 0) +#line 737 + return NC_NOERR; +#line 737 + +#line 737 + assert(value != NULL); +#line 737 + +#line 737 +#ifdef ERANGE_FILL +#line 737 + fillp = malloc(varp->xsz); +#line 737 + status = NC3_inq_var_fill(varp, fillp); +#line 737 +#endif +#line 737 + +#line 737 + for(;;) +#line 737 + { +#line 737 + size_t extent = MIN(remaining, ncp->chunk); +#line 737 + size_t nput = ncx_howmany(varp->type, extent); +#line 737 + +#line 737 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 737 + RGN_WRITE, &xp); +#line 737 + if(lstatus != NC_NOERR) +#line 737 + return lstatus; +#line 737 + +#line 737 + lstatus = ncx_putn_float_uint(&xp, nput, value ,fillp); +#line 737 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 737 + { +#line 737 + /* not fatal to the loop */ +#line 737 + status = lstatus; +#line 737 + } +#line 737 + +#line 737 + (void) ncio_rel(ncp->nciop, offset, +#line 737 + RGN_MODIFIED); +#line 737 + +#line 737 + remaining -= extent; +#line 737 + if(remaining == 0) +#line 737 + break; /* normal loop exit */ +#line 737 + offset += (off_t)extent; +#line 737 + value += nput; +#line 737 + +#line 737 + } +#line 737 +#ifdef ERANGE_FILL +#line 737 + free(fillp); +#line 737 +#endif +#line 737 + +#line 737 + return status; +#line 737 +} +#line 737 + +static int +#line 738 +putNCvx_float_ulonglong(NC3_INFO* ncp, const NC_var *varp, +#line 738 + const size_t *start, size_t nelems, const ulonglong *value) +#line 738 +{ +#line 738 + off_t offset = NC_varoffset(ncp, varp, start); +#line 738 + size_t remaining = varp->xsz * nelems; +#line 738 + int status = NC_NOERR; +#line 738 + void *xp; +#line 738 + void *fillp=NULL; +#line 738 + +#line 738 + NC_UNUSED(fillp); +#line 738 + +#line 738 + if(nelems == 0) +#line 738 + return NC_NOERR; +#line 738 + +#line 738 + assert(value != NULL); +#line 738 + +#line 738 +#ifdef ERANGE_FILL +#line 738 + fillp = malloc(varp->xsz); +#line 738 + status = NC3_inq_var_fill(varp, fillp); +#line 738 +#endif +#line 738 + +#line 738 + for(;;) +#line 738 + { +#line 738 + size_t extent = MIN(remaining, ncp->chunk); +#line 738 + size_t nput = ncx_howmany(varp->type, extent); +#line 738 + +#line 738 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 738 + RGN_WRITE, &xp); +#line 738 + if(lstatus != NC_NOERR) +#line 738 + return lstatus; +#line 738 + +#line 738 + lstatus = ncx_putn_float_ulonglong(&xp, nput, value ,fillp); +#line 738 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 738 + { +#line 738 + /* not fatal to the loop */ +#line 738 + status = lstatus; +#line 738 + } +#line 738 + +#line 738 + (void) ncio_rel(ncp->nciop, offset, +#line 738 + RGN_MODIFIED); +#line 738 + +#line 738 + remaining -= extent; +#line 738 + if(remaining == 0) +#line 738 + break; /* normal loop exit */ +#line 738 + offset += (off_t)extent; +#line 738 + value += nput; +#line 738 + +#line 738 + } +#line 738 +#ifdef ERANGE_FILL +#line 738 + free(fillp); +#line 738 +#endif +#line 738 + +#line 738 + return status; +#line 738 +} +#line 738 + + +static int +#line 740 +putNCvx_double_schar(NC3_INFO* ncp, const NC_var *varp, +#line 740 + const size_t *start, size_t nelems, const schar *value) +#line 740 +{ +#line 740 + off_t offset = NC_varoffset(ncp, varp, start); +#line 740 + size_t remaining = varp->xsz * nelems; +#line 740 + int status = NC_NOERR; +#line 740 + void *xp; +#line 740 + void *fillp=NULL; +#line 740 + +#line 740 + NC_UNUSED(fillp); +#line 740 + +#line 740 + if(nelems == 0) +#line 740 + return NC_NOERR; +#line 740 + +#line 740 + assert(value != NULL); +#line 740 + +#line 740 +#ifdef ERANGE_FILL +#line 740 + fillp = malloc(varp->xsz); +#line 740 + status = NC3_inq_var_fill(varp, fillp); +#line 740 +#endif +#line 740 + +#line 740 + for(;;) +#line 740 + { +#line 740 + size_t extent = MIN(remaining, ncp->chunk); +#line 740 + size_t nput = ncx_howmany(varp->type, extent); +#line 740 + +#line 740 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 740 + RGN_WRITE, &xp); +#line 740 + if(lstatus != NC_NOERR) +#line 740 + return lstatus; +#line 740 + +#line 740 + lstatus = ncx_putn_double_schar(&xp, nput, value ,fillp); +#line 740 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 740 + { +#line 740 + /* not fatal to the loop */ +#line 740 + status = lstatus; +#line 740 + } +#line 740 + +#line 740 + (void) ncio_rel(ncp->nciop, offset, +#line 740 + RGN_MODIFIED); +#line 740 + +#line 740 + remaining -= extent; +#line 740 + if(remaining == 0) +#line 740 + break; /* normal loop exit */ +#line 740 + offset += (off_t)extent; +#line 740 + value += nput; +#line 740 + +#line 740 + } +#line 740 +#ifdef ERANGE_FILL +#line 740 + free(fillp); +#line 740 +#endif +#line 740 + +#line 740 + return status; +#line 740 +} +#line 740 + +static int +#line 741 +putNCvx_double_uchar(NC3_INFO* ncp, const NC_var *varp, +#line 741 + const size_t *start, size_t nelems, const uchar *value) +#line 741 +{ +#line 741 + off_t offset = NC_varoffset(ncp, varp, start); +#line 741 + size_t remaining = varp->xsz * nelems; +#line 741 + int status = NC_NOERR; +#line 741 + void *xp; +#line 741 + void *fillp=NULL; +#line 741 + +#line 741 + NC_UNUSED(fillp); +#line 741 + +#line 741 + if(nelems == 0) +#line 741 + return NC_NOERR; +#line 741 + +#line 741 + assert(value != NULL); +#line 741 + +#line 741 +#ifdef ERANGE_FILL +#line 741 + fillp = malloc(varp->xsz); +#line 741 + status = NC3_inq_var_fill(varp, fillp); +#line 741 +#endif +#line 741 + +#line 741 + for(;;) +#line 741 + { +#line 741 + size_t extent = MIN(remaining, ncp->chunk); +#line 741 + size_t nput = ncx_howmany(varp->type, extent); +#line 741 + +#line 741 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 741 + RGN_WRITE, &xp); +#line 741 + if(lstatus != NC_NOERR) +#line 741 + return lstatus; +#line 741 + +#line 741 + lstatus = ncx_putn_double_uchar(&xp, nput, value ,fillp); +#line 741 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 741 + { +#line 741 + /* not fatal to the loop */ +#line 741 + status = lstatus; +#line 741 + } +#line 741 + +#line 741 + (void) ncio_rel(ncp->nciop, offset, +#line 741 + RGN_MODIFIED); +#line 741 + +#line 741 + remaining -= extent; +#line 741 + if(remaining == 0) +#line 741 + break; /* normal loop exit */ +#line 741 + offset += (off_t)extent; +#line 741 + value += nput; +#line 741 + +#line 741 + } +#line 741 +#ifdef ERANGE_FILL +#line 741 + free(fillp); +#line 741 +#endif +#line 741 + +#line 741 + return status; +#line 741 +} +#line 741 + +static int +#line 742 +putNCvx_double_short(NC3_INFO* ncp, const NC_var *varp, +#line 742 + const size_t *start, size_t nelems, const short *value) +#line 742 +{ +#line 742 + off_t offset = NC_varoffset(ncp, varp, start); +#line 742 + size_t remaining = varp->xsz * nelems; +#line 742 + int status = NC_NOERR; +#line 742 + void *xp; +#line 742 + void *fillp=NULL; +#line 742 + +#line 742 + NC_UNUSED(fillp); +#line 742 + +#line 742 + if(nelems == 0) +#line 742 + return NC_NOERR; +#line 742 + +#line 742 + assert(value != NULL); +#line 742 + +#line 742 +#ifdef ERANGE_FILL +#line 742 + fillp = malloc(varp->xsz); +#line 742 + status = NC3_inq_var_fill(varp, fillp); +#line 742 +#endif +#line 742 + +#line 742 + for(;;) +#line 742 + { +#line 742 + size_t extent = MIN(remaining, ncp->chunk); +#line 742 + size_t nput = ncx_howmany(varp->type, extent); +#line 742 + +#line 742 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 742 + RGN_WRITE, &xp); +#line 742 + if(lstatus != NC_NOERR) +#line 742 + return lstatus; +#line 742 + +#line 742 + lstatus = ncx_putn_double_short(&xp, nput, value ,fillp); +#line 742 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 742 + { +#line 742 + /* not fatal to the loop */ +#line 742 + status = lstatus; +#line 742 + } +#line 742 + +#line 742 + (void) ncio_rel(ncp->nciop, offset, +#line 742 + RGN_MODIFIED); +#line 742 + +#line 742 + remaining -= extent; +#line 742 + if(remaining == 0) +#line 742 + break; /* normal loop exit */ +#line 742 + offset += (off_t)extent; +#line 742 + value += nput; +#line 742 + +#line 742 + } +#line 742 +#ifdef ERANGE_FILL +#line 742 + free(fillp); +#line 742 +#endif +#line 742 + +#line 742 + return status; +#line 742 +} +#line 742 + +static int +#line 743 +putNCvx_double_int(NC3_INFO* ncp, const NC_var *varp, +#line 743 + const size_t *start, size_t nelems, const int *value) +#line 743 +{ +#line 743 + off_t offset = NC_varoffset(ncp, varp, start); +#line 743 + size_t remaining = varp->xsz * nelems; +#line 743 + int status = NC_NOERR; +#line 743 + void *xp; +#line 743 + void *fillp=NULL; +#line 743 + +#line 743 + NC_UNUSED(fillp); +#line 743 + +#line 743 + if(nelems == 0) +#line 743 + return NC_NOERR; +#line 743 + +#line 743 + assert(value != NULL); +#line 743 + +#line 743 +#ifdef ERANGE_FILL +#line 743 + fillp = malloc(varp->xsz); +#line 743 + status = NC3_inq_var_fill(varp, fillp); +#line 743 +#endif +#line 743 + +#line 743 + for(;;) +#line 743 + { +#line 743 + size_t extent = MIN(remaining, ncp->chunk); +#line 743 + size_t nput = ncx_howmany(varp->type, extent); +#line 743 + +#line 743 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 743 + RGN_WRITE, &xp); +#line 743 + if(lstatus != NC_NOERR) +#line 743 + return lstatus; +#line 743 + +#line 743 + lstatus = ncx_putn_double_int(&xp, nput, value ,fillp); +#line 743 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 743 + { +#line 743 + /* not fatal to the loop */ +#line 743 + status = lstatus; +#line 743 + } +#line 743 + +#line 743 + (void) ncio_rel(ncp->nciop, offset, +#line 743 + RGN_MODIFIED); +#line 743 + +#line 743 + remaining -= extent; +#line 743 + if(remaining == 0) +#line 743 + break; /* normal loop exit */ +#line 743 + offset += (off_t)extent; +#line 743 + value += nput; +#line 743 + +#line 743 + } +#line 743 +#ifdef ERANGE_FILL +#line 743 + free(fillp); +#line 743 +#endif +#line 743 + +#line 743 + return status; +#line 743 +} +#line 743 + +static int +#line 744 +putNCvx_double_float(NC3_INFO* ncp, const NC_var *varp, +#line 744 + const size_t *start, size_t nelems, const float *value) +#line 744 +{ +#line 744 + off_t offset = NC_varoffset(ncp, varp, start); +#line 744 + size_t remaining = varp->xsz * nelems; +#line 744 + int status = NC_NOERR; +#line 744 + void *xp; +#line 744 + void *fillp=NULL; +#line 744 + +#line 744 + NC_UNUSED(fillp); +#line 744 + +#line 744 + if(nelems == 0) +#line 744 + return NC_NOERR; +#line 744 + +#line 744 + assert(value != NULL); +#line 744 + +#line 744 +#ifdef ERANGE_FILL +#line 744 + fillp = malloc(varp->xsz); +#line 744 + status = NC3_inq_var_fill(varp, fillp); +#line 744 +#endif +#line 744 + +#line 744 + for(;;) +#line 744 + { +#line 744 + size_t extent = MIN(remaining, ncp->chunk); +#line 744 + size_t nput = ncx_howmany(varp->type, extent); +#line 744 + +#line 744 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 744 + RGN_WRITE, &xp); +#line 744 + if(lstatus != NC_NOERR) +#line 744 + return lstatus; +#line 744 + +#line 744 + lstatus = ncx_putn_double_float(&xp, nput, value ,fillp); +#line 744 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 744 + { +#line 744 + /* not fatal to the loop */ +#line 744 + status = lstatus; +#line 744 + } +#line 744 + +#line 744 + (void) ncio_rel(ncp->nciop, offset, +#line 744 + RGN_MODIFIED); +#line 744 + +#line 744 + remaining -= extent; +#line 744 + if(remaining == 0) +#line 744 + break; /* normal loop exit */ +#line 744 + offset += (off_t)extent; +#line 744 + value += nput; +#line 744 + +#line 744 + } +#line 744 +#ifdef ERANGE_FILL +#line 744 + free(fillp); +#line 744 +#endif +#line 744 + +#line 744 + return status; +#line 744 +} +#line 744 + +static int +#line 745 +putNCvx_double_double(NC3_INFO* ncp, const NC_var *varp, +#line 745 + const size_t *start, size_t nelems, const double *value) +#line 745 +{ +#line 745 + off_t offset = NC_varoffset(ncp, varp, start); +#line 745 + size_t remaining = varp->xsz * nelems; +#line 745 + int status = NC_NOERR; +#line 745 + void *xp; +#line 745 + void *fillp=NULL; +#line 745 + +#line 745 + NC_UNUSED(fillp); +#line 745 + +#line 745 + if(nelems == 0) +#line 745 + return NC_NOERR; +#line 745 + +#line 745 + assert(value != NULL); +#line 745 + +#line 745 +#ifdef ERANGE_FILL +#line 745 + fillp = malloc(varp->xsz); +#line 745 + status = NC3_inq_var_fill(varp, fillp); +#line 745 +#endif +#line 745 + +#line 745 + for(;;) +#line 745 + { +#line 745 + size_t extent = MIN(remaining, ncp->chunk); +#line 745 + size_t nput = ncx_howmany(varp->type, extent); +#line 745 + +#line 745 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 745 + RGN_WRITE, &xp); +#line 745 + if(lstatus != NC_NOERR) +#line 745 + return lstatus; +#line 745 + +#line 745 + lstatus = ncx_putn_double_double(&xp, nput, value ,fillp); +#line 745 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 745 + { +#line 745 + /* not fatal to the loop */ +#line 745 + status = lstatus; +#line 745 + } +#line 745 + +#line 745 + (void) ncio_rel(ncp->nciop, offset, +#line 745 + RGN_MODIFIED); +#line 745 + +#line 745 + remaining -= extent; +#line 745 + if(remaining == 0) +#line 745 + break; /* normal loop exit */ +#line 745 + offset += (off_t)extent; +#line 745 + value += nput; +#line 745 + +#line 745 + } +#line 745 +#ifdef ERANGE_FILL +#line 745 + free(fillp); +#line 745 +#endif +#line 745 + +#line 745 + return status; +#line 745 +} +#line 745 + +static int +#line 746 +putNCvx_double_longlong(NC3_INFO* ncp, const NC_var *varp, +#line 746 + const size_t *start, size_t nelems, const longlong *value) +#line 746 +{ +#line 746 + off_t offset = NC_varoffset(ncp, varp, start); +#line 746 + size_t remaining = varp->xsz * nelems; +#line 746 + int status = NC_NOERR; +#line 746 + void *xp; +#line 746 + void *fillp=NULL; +#line 746 + +#line 746 + NC_UNUSED(fillp); +#line 746 + +#line 746 + if(nelems == 0) +#line 746 + return NC_NOERR; +#line 746 + +#line 746 + assert(value != NULL); +#line 746 + +#line 746 +#ifdef ERANGE_FILL +#line 746 + fillp = malloc(varp->xsz); +#line 746 + status = NC3_inq_var_fill(varp, fillp); +#line 746 +#endif +#line 746 + +#line 746 + for(;;) +#line 746 + { +#line 746 + size_t extent = MIN(remaining, ncp->chunk); +#line 746 + size_t nput = ncx_howmany(varp->type, extent); +#line 746 + +#line 746 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 746 + RGN_WRITE, &xp); +#line 746 + if(lstatus != NC_NOERR) +#line 746 + return lstatus; +#line 746 + +#line 746 + lstatus = ncx_putn_double_longlong(&xp, nput, value ,fillp); +#line 746 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 746 + { +#line 746 + /* not fatal to the loop */ +#line 746 + status = lstatus; +#line 746 + } +#line 746 + +#line 746 + (void) ncio_rel(ncp->nciop, offset, +#line 746 + RGN_MODIFIED); +#line 746 + +#line 746 + remaining -= extent; +#line 746 + if(remaining == 0) +#line 746 + break; /* normal loop exit */ +#line 746 + offset += (off_t)extent; +#line 746 + value += nput; +#line 746 + +#line 746 + } +#line 746 +#ifdef ERANGE_FILL +#line 746 + free(fillp); +#line 746 +#endif +#line 746 + +#line 746 + return status; +#line 746 +} +#line 746 + +static int +#line 747 +putNCvx_double_ushort(NC3_INFO* ncp, const NC_var *varp, +#line 747 + const size_t *start, size_t nelems, const ushort *value) +#line 747 +{ +#line 747 + off_t offset = NC_varoffset(ncp, varp, start); +#line 747 + size_t remaining = varp->xsz * nelems; +#line 747 + int status = NC_NOERR; +#line 747 + void *xp; +#line 747 + void *fillp=NULL; +#line 747 + +#line 747 + NC_UNUSED(fillp); +#line 747 + +#line 747 + if(nelems == 0) +#line 747 + return NC_NOERR; +#line 747 + +#line 747 + assert(value != NULL); +#line 747 + +#line 747 +#ifdef ERANGE_FILL +#line 747 + fillp = malloc(varp->xsz); +#line 747 + status = NC3_inq_var_fill(varp, fillp); +#line 747 +#endif +#line 747 + +#line 747 + for(;;) +#line 747 + { +#line 747 + size_t extent = MIN(remaining, ncp->chunk); +#line 747 + size_t nput = ncx_howmany(varp->type, extent); +#line 747 + +#line 747 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 747 + RGN_WRITE, &xp); +#line 747 + if(lstatus != NC_NOERR) +#line 747 + return lstatus; +#line 747 + +#line 747 + lstatus = ncx_putn_double_ushort(&xp, nput, value ,fillp); +#line 747 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 747 + { +#line 747 + /* not fatal to the loop */ +#line 747 + status = lstatus; +#line 747 + } +#line 747 + +#line 747 + (void) ncio_rel(ncp->nciop, offset, +#line 747 + RGN_MODIFIED); +#line 747 + +#line 747 + remaining -= extent; +#line 747 + if(remaining == 0) +#line 747 + break; /* normal loop exit */ +#line 747 + offset += (off_t)extent; +#line 747 + value += nput; +#line 747 + +#line 747 + } +#line 747 +#ifdef ERANGE_FILL +#line 747 + free(fillp); +#line 747 +#endif +#line 747 + +#line 747 + return status; +#line 747 +} +#line 747 + +static int +#line 748 +putNCvx_double_uint(NC3_INFO* ncp, const NC_var *varp, +#line 748 + const size_t *start, size_t nelems, const uint *value) +#line 748 +{ +#line 748 + off_t offset = NC_varoffset(ncp, varp, start); +#line 748 + size_t remaining = varp->xsz * nelems; +#line 748 + int status = NC_NOERR; +#line 748 + void *xp; +#line 748 + void *fillp=NULL; +#line 748 + +#line 748 + NC_UNUSED(fillp); +#line 748 + +#line 748 + if(nelems == 0) +#line 748 + return NC_NOERR; +#line 748 + +#line 748 + assert(value != NULL); +#line 748 + +#line 748 +#ifdef ERANGE_FILL +#line 748 + fillp = malloc(varp->xsz); +#line 748 + status = NC3_inq_var_fill(varp, fillp); +#line 748 +#endif +#line 748 + +#line 748 + for(;;) +#line 748 + { +#line 748 + size_t extent = MIN(remaining, ncp->chunk); +#line 748 + size_t nput = ncx_howmany(varp->type, extent); +#line 748 + +#line 748 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 748 + RGN_WRITE, &xp); +#line 748 + if(lstatus != NC_NOERR) +#line 748 + return lstatus; +#line 748 + +#line 748 + lstatus = ncx_putn_double_uint(&xp, nput, value ,fillp); +#line 748 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 748 + { +#line 748 + /* not fatal to the loop */ +#line 748 + status = lstatus; +#line 748 + } +#line 748 + +#line 748 + (void) ncio_rel(ncp->nciop, offset, +#line 748 + RGN_MODIFIED); +#line 748 + +#line 748 + remaining -= extent; +#line 748 + if(remaining == 0) +#line 748 + break; /* normal loop exit */ +#line 748 + offset += (off_t)extent; +#line 748 + value += nput; +#line 748 + +#line 748 + } +#line 748 +#ifdef ERANGE_FILL +#line 748 + free(fillp); +#line 748 +#endif +#line 748 + +#line 748 + return status; +#line 748 +} +#line 748 + +static int +#line 749 +putNCvx_double_ulonglong(NC3_INFO* ncp, const NC_var *varp, +#line 749 + const size_t *start, size_t nelems, const ulonglong *value) +#line 749 +{ +#line 749 + off_t offset = NC_varoffset(ncp, varp, start); +#line 749 + size_t remaining = varp->xsz * nelems; +#line 749 + int status = NC_NOERR; +#line 749 + void *xp; +#line 749 + void *fillp=NULL; +#line 749 + +#line 749 + NC_UNUSED(fillp); +#line 749 + +#line 749 + if(nelems == 0) +#line 749 + return NC_NOERR; +#line 749 + +#line 749 + assert(value != NULL); +#line 749 + +#line 749 +#ifdef ERANGE_FILL +#line 749 + fillp = malloc(varp->xsz); +#line 749 + status = NC3_inq_var_fill(varp, fillp); +#line 749 +#endif +#line 749 + +#line 749 + for(;;) +#line 749 + { +#line 749 + size_t extent = MIN(remaining, ncp->chunk); +#line 749 + size_t nput = ncx_howmany(varp->type, extent); +#line 749 + +#line 749 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 749 + RGN_WRITE, &xp); +#line 749 + if(lstatus != NC_NOERR) +#line 749 + return lstatus; +#line 749 + +#line 749 + lstatus = ncx_putn_double_ulonglong(&xp, nput, value ,fillp); +#line 749 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 749 + { +#line 749 + /* not fatal to the loop */ +#line 749 + status = lstatus; +#line 749 + } +#line 749 + +#line 749 + (void) ncio_rel(ncp->nciop, offset, +#line 749 + RGN_MODIFIED); +#line 749 + +#line 749 + remaining -= extent; +#line 749 + if(remaining == 0) +#line 749 + break; /* normal loop exit */ +#line 749 + offset += (off_t)extent; +#line 749 + value += nput; +#line 749 + +#line 749 + } +#line 749 +#ifdef ERANGE_FILL +#line 749 + free(fillp); +#line 749 +#endif +#line 749 + +#line 749 + return status; +#line 749 +} +#line 749 + + +static int +#line 751 +putNCvx_uchar_schar(NC3_INFO* ncp, const NC_var *varp, +#line 751 + const size_t *start, size_t nelems, const schar *value) +#line 751 +{ +#line 751 + off_t offset = NC_varoffset(ncp, varp, start); +#line 751 + size_t remaining = varp->xsz * nelems; +#line 751 + int status = NC_NOERR; +#line 751 + void *xp; +#line 751 + void *fillp=NULL; +#line 751 + +#line 751 + NC_UNUSED(fillp); +#line 751 + +#line 751 + if(nelems == 0) +#line 751 + return NC_NOERR; +#line 751 + +#line 751 + assert(value != NULL); +#line 751 + +#line 751 +#ifdef ERANGE_FILL +#line 751 + fillp = malloc(varp->xsz); +#line 751 + status = NC3_inq_var_fill(varp, fillp); +#line 751 +#endif +#line 751 + +#line 751 + for(;;) +#line 751 + { +#line 751 + size_t extent = MIN(remaining, ncp->chunk); +#line 751 + size_t nput = ncx_howmany(varp->type, extent); +#line 751 + +#line 751 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 751 + RGN_WRITE, &xp); +#line 751 + if(lstatus != NC_NOERR) +#line 751 + return lstatus; +#line 751 + +#line 751 + lstatus = ncx_putn_uchar_schar(&xp, nput, value ,fillp); +#line 751 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 751 + { +#line 751 + /* not fatal to the loop */ +#line 751 + status = lstatus; +#line 751 + } +#line 751 + +#line 751 + (void) ncio_rel(ncp->nciop, offset, +#line 751 + RGN_MODIFIED); +#line 751 + +#line 751 + remaining -= extent; +#line 751 + if(remaining == 0) +#line 751 + break; /* normal loop exit */ +#line 751 + offset += (off_t)extent; +#line 751 + value += nput; +#line 751 + +#line 751 + } +#line 751 +#ifdef ERANGE_FILL +#line 751 + free(fillp); +#line 751 +#endif +#line 751 + +#line 751 + return status; +#line 751 +} +#line 751 + +static int +#line 752 +putNCvx_uchar_uchar(NC3_INFO* ncp, const NC_var *varp, +#line 752 + const size_t *start, size_t nelems, const uchar *value) +#line 752 +{ +#line 752 + off_t offset = NC_varoffset(ncp, varp, start); +#line 752 + size_t remaining = varp->xsz * nelems; +#line 752 + int status = NC_NOERR; +#line 752 + void *xp; +#line 752 + void *fillp=NULL; +#line 752 + +#line 752 + NC_UNUSED(fillp); +#line 752 + +#line 752 + if(nelems == 0) +#line 752 + return NC_NOERR; +#line 752 + +#line 752 + assert(value != NULL); +#line 752 + +#line 752 +#ifdef ERANGE_FILL +#line 752 + fillp = malloc(varp->xsz); +#line 752 + status = NC3_inq_var_fill(varp, fillp); +#line 752 +#endif +#line 752 + +#line 752 + for(;;) +#line 752 + { +#line 752 + size_t extent = MIN(remaining, ncp->chunk); +#line 752 + size_t nput = ncx_howmany(varp->type, extent); +#line 752 + +#line 752 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 752 + RGN_WRITE, &xp); +#line 752 + if(lstatus != NC_NOERR) +#line 752 + return lstatus; +#line 752 + +#line 752 + lstatus = ncx_putn_uchar_uchar(&xp, nput, value ,fillp); +#line 752 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 752 + { +#line 752 + /* not fatal to the loop */ +#line 752 + status = lstatus; +#line 752 + } +#line 752 + +#line 752 + (void) ncio_rel(ncp->nciop, offset, +#line 752 + RGN_MODIFIED); +#line 752 + +#line 752 + remaining -= extent; +#line 752 + if(remaining == 0) +#line 752 + break; /* normal loop exit */ +#line 752 + offset += (off_t)extent; +#line 752 + value += nput; +#line 752 + +#line 752 + } +#line 752 +#ifdef ERANGE_FILL +#line 752 + free(fillp); +#line 752 +#endif +#line 752 + +#line 752 + return status; +#line 752 +} +#line 752 + +static int +#line 753 +putNCvx_uchar_short(NC3_INFO* ncp, const NC_var *varp, +#line 753 + const size_t *start, size_t nelems, const short *value) +#line 753 +{ +#line 753 + off_t offset = NC_varoffset(ncp, varp, start); +#line 753 + size_t remaining = varp->xsz * nelems; +#line 753 + int status = NC_NOERR; +#line 753 + void *xp; +#line 753 + void *fillp=NULL; +#line 753 + +#line 753 + NC_UNUSED(fillp); +#line 753 + +#line 753 + if(nelems == 0) +#line 753 + return NC_NOERR; +#line 753 + +#line 753 + assert(value != NULL); +#line 753 + +#line 753 +#ifdef ERANGE_FILL +#line 753 + fillp = malloc(varp->xsz); +#line 753 + status = NC3_inq_var_fill(varp, fillp); +#line 753 +#endif +#line 753 + +#line 753 + for(;;) +#line 753 + { +#line 753 + size_t extent = MIN(remaining, ncp->chunk); +#line 753 + size_t nput = ncx_howmany(varp->type, extent); +#line 753 + +#line 753 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 753 + RGN_WRITE, &xp); +#line 753 + if(lstatus != NC_NOERR) +#line 753 + return lstatus; +#line 753 + +#line 753 + lstatus = ncx_putn_uchar_short(&xp, nput, value ,fillp); +#line 753 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 753 + { +#line 753 + /* not fatal to the loop */ +#line 753 + status = lstatus; +#line 753 + } +#line 753 + +#line 753 + (void) ncio_rel(ncp->nciop, offset, +#line 753 + RGN_MODIFIED); +#line 753 + +#line 753 + remaining -= extent; +#line 753 + if(remaining == 0) +#line 753 + break; /* normal loop exit */ +#line 753 + offset += (off_t)extent; +#line 753 + value += nput; +#line 753 + +#line 753 + } +#line 753 +#ifdef ERANGE_FILL +#line 753 + free(fillp); +#line 753 +#endif +#line 753 + +#line 753 + return status; +#line 753 +} +#line 753 + +static int +#line 754 +putNCvx_uchar_int(NC3_INFO* ncp, const NC_var *varp, +#line 754 + const size_t *start, size_t nelems, const int *value) +#line 754 +{ +#line 754 + off_t offset = NC_varoffset(ncp, varp, start); +#line 754 + size_t remaining = varp->xsz * nelems; +#line 754 + int status = NC_NOERR; +#line 754 + void *xp; +#line 754 + void *fillp=NULL; +#line 754 + +#line 754 + NC_UNUSED(fillp); +#line 754 + +#line 754 + if(nelems == 0) +#line 754 + return NC_NOERR; +#line 754 + +#line 754 + assert(value != NULL); +#line 754 + +#line 754 +#ifdef ERANGE_FILL +#line 754 + fillp = malloc(varp->xsz); +#line 754 + status = NC3_inq_var_fill(varp, fillp); +#line 754 +#endif +#line 754 + +#line 754 + for(;;) +#line 754 + { +#line 754 + size_t extent = MIN(remaining, ncp->chunk); +#line 754 + size_t nput = ncx_howmany(varp->type, extent); +#line 754 + +#line 754 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 754 + RGN_WRITE, &xp); +#line 754 + if(lstatus != NC_NOERR) +#line 754 + return lstatus; +#line 754 + +#line 754 + lstatus = ncx_putn_uchar_int(&xp, nput, value ,fillp); +#line 754 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 754 + { +#line 754 + /* not fatal to the loop */ +#line 754 + status = lstatus; +#line 754 + } +#line 754 + +#line 754 + (void) ncio_rel(ncp->nciop, offset, +#line 754 + RGN_MODIFIED); +#line 754 + +#line 754 + remaining -= extent; +#line 754 + if(remaining == 0) +#line 754 + break; /* normal loop exit */ +#line 754 + offset += (off_t)extent; +#line 754 + value += nput; +#line 754 + +#line 754 + } +#line 754 +#ifdef ERANGE_FILL +#line 754 + free(fillp); +#line 754 +#endif +#line 754 + +#line 754 + return status; +#line 754 +} +#line 754 + +static int +#line 755 +putNCvx_uchar_float(NC3_INFO* ncp, const NC_var *varp, +#line 755 + const size_t *start, size_t nelems, const float *value) +#line 755 +{ +#line 755 + off_t offset = NC_varoffset(ncp, varp, start); +#line 755 + size_t remaining = varp->xsz * nelems; +#line 755 + int status = NC_NOERR; +#line 755 + void *xp; +#line 755 + void *fillp=NULL; +#line 755 + +#line 755 + NC_UNUSED(fillp); +#line 755 + +#line 755 + if(nelems == 0) +#line 755 + return NC_NOERR; +#line 755 + +#line 755 + assert(value != NULL); +#line 755 + +#line 755 +#ifdef ERANGE_FILL +#line 755 + fillp = malloc(varp->xsz); +#line 755 + status = NC3_inq_var_fill(varp, fillp); +#line 755 +#endif +#line 755 + +#line 755 + for(;;) +#line 755 + { +#line 755 + size_t extent = MIN(remaining, ncp->chunk); +#line 755 + size_t nput = ncx_howmany(varp->type, extent); +#line 755 + +#line 755 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 755 + RGN_WRITE, &xp); +#line 755 + if(lstatus != NC_NOERR) +#line 755 + return lstatus; +#line 755 + +#line 755 + lstatus = ncx_putn_uchar_float(&xp, nput, value ,fillp); +#line 755 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 755 + { +#line 755 + /* not fatal to the loop */ +#line 755 + status = lstatus; +#line 755 + } +#line 755 + +#line 755 + (void) ncio_rel(ncp->nciop, offset, +#line 755 + RGN_MODIFIED); +#line 755 + +#line 755 + remaining -= extent; +#line 755 + if(remaining == 0) +#line 755 + break; /* normal loop exit */ +#line 755 + offset += (off_t)extent; +#line 755 + value += nput; +#line 755 + +#line 755 + } +#line 755 +#ifdef ERANGE_FILL +#line 755 + free(fillp); +#line 755 +#endif +#line 755 + +#line 755 + return status; +#line 755 +} +#line 755 + +static int +#line 756 +putNCvx_uchar_double(NC3_INFO* ncp, const NC_var *varp, +#line 756 + const size_t *start, size_t nelems, const double *value) +#line 756 +{ +#line 756 + off_t offset = NC_varoffset(ncp, varp, start); +#line 756 + size_t remaining = varp->xsz * nelems; +#line 756 + int status = NC_NOERR; +#line 756 + void *xp; +#line 756 + void *fillp=NULL; +#line 756 + +#line 756 + NC_UNUSED(fillp); +#line 756 + +#line 756 + if(nelems == 0) +#line 756 + return NC_NOERR; +#line 756 + +#line 756 + assert(value != NULL); +#line 756 + +#line 756 +#ifdef ERANGE_FILL +#line 756 + fillp = malloc(varp->xsz); +#line 756 + status = NC3_inq_var_fill(varp, fillp); +#line 756 +#endif +#line 756 + +#line 756 + for(;;) +#line 756 + { +#line 756 + size_t extent = MIN(remaining, ncp->chunk); +#line 756 + size_t nput = ncx_howmany(varp->type, extent); +#line 756 + +#line 756 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 756 + RGN_WRITE, &xp); +#line 756 + if(lstatus != NC_NOERR) +#line 756 + return lstatus; +#line 756 + +#line 756 + lstatus = ncx_putn_uchar_double(&xp, nput, value ,fillp); +#line 756 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 756 + { +#line 756 + /* not fatal to the loop */ +#line 756 + status = lstatus; +#line 756 + } +#line 756 + +#line 756 + (void) ncio_rel(ncp->nciop, offset, +#line 756 + RGN_MODIFIED); +#line 756 + +#line 756 + remaining -= extent; +#line 756 + if(remaining == 0) +#line 756 + break; /* normal loop exit */ +#line 756 + offset += (off_t)extent; +#line 756 + value += nput; +#line 756 + +#line 756 + } +#line 756 +#ifdef ERANGE_FILL +#line 756 + free(fillp); +#line 756 +#endif +#line 756 + +#line 756 + return status; +#line 756 +} +#line 756 + +static int +#line 757 +putNCvx_uchar_longlong(NC3_INFO* ncp, const NC_var *varp, +#line 757 + const size_t *start, size_t nelems, const longlong *value) +#line 757 +{ +#line 757 + off_t offset = NC_varoffset(ncp, varp, start); +#line 757 + size_t remaining = varp->xsz * nelems; +#line 757 + int status = NC_NOERR; +#line 757 + void *xp; +#line 757 + void *fillp=NULL; +#line 757 + +#line 757 + NC_UNUSED(fillp); +#line 757 + +#line 757 + if(nelems == 0) +#line 757 + return NC_NOERR; +#line 757 + +#line 757 + assert(value != NULL); +#line 757 + +#line 757 +#ifdef ERANGE_FILL +#line 757 + fillp = malloc(varp->xsz); +#line 757 + status = NC3_inq_var_fill(varp, fillp); +#line 757 +#endif +#line 757 + +#line 757 + for(;;) +#line 757 + { +#line 757 + size_t extent = MIN(remaining, ncp->chunk); +#line 757 + size_t nput = ncx_howmany(varp->type, extent); +#line 757 + +#line 757 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 757 + RGN_WRITE, &xp); +#line 757 + if(lstatus != NC_NOERR) +#line 757 + return lstatus; +#line 757 + +#line 757 + lstatus = ncx_putn_uchar_longlong(&xp, nput, value ,fillp); +#line 757 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 757 + { +#line 757 + /* not fatal to the loop */ +#line 757 + status = lstatus; +#line 757 + } +#line 757 + +#line 757 + (void) ncio_rel(ncp->nciop, offset, +#line 757 + RGN_MODIFIED); +#line 757 + +#line 757 + remaining -= extent; +#line 757 + if(remaining == 0) +#line 757 + break; /* normal loop exit */ +#line 757 + offset += (off_t)extent; +#line 757 + value += nput; +#line 757 + +#line 757 + } +#line 757 +#ifdef ERANGE_FILL +#line 757 + free(fillp); +#line 757 +#endif +#line 757 + +#line 757 + return status; +#line 757 +} +#line 757 + +static int +#line 758 +putNCvx_uchar_ushort(NC3_INFO* ncp, const NC_var *varp, +#line 758 + const size_t *start, size_t nelems, const ushort *value) +#line 758 +{ +#line 758 + off_t offset = NC_varoffset(ncp, varp, start); +#line 758 + size_t remaining = varp->xsz * nelems; +#line 758 + int status = NC_NOERR; +#line 758 + void *xp; +#line 758 + void *fillp=NULL; +#line 758 + +#line 758 + NC_UNUSED(fillp); +#line 758 + +#line 758 + if(nelems == 0) +#line 758 + return NC_NOERR; +#line 758 + +#line 758 + assert(value != NULL); +#line 758 + +#line 758 +#ifdef ERANGE_FILL +#line 758 + fillp = malloc(varp->xsz); +#line 758 + status = NC3_inq_var_fill(varp, fillp); +#line 758 +#endif +#line 758 + +#line 758 + for(;;) +#line 758 + { +#line 758 + size_t extent = MIN(remaining, ncp->chunk); +#line 758 + size_t nput = ncx_howmany(varp->type, extent); +#line 758 + +#line 758 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 758 + RGN_WRITE, &xp); +#line 758 + if(lstatus != NC_NOERR) +#line 758 + return lstatus; +#line 758 + +#line 758 + lstatus = ncx_putn_uchar_ushort(&xp, nput, value ,fillp); +#line 758 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 758 + { +#line 758 + /* not fatal to the loop */ +#line 758 + status = lstatus; +#line 758 + } +#line 758 + +#line 758 + (void) ncio_rel(ncp->nciop, offset, +#line 758 + RGN_MODIFIED); +#line 758 + +#line 758 + remaining -= extent; +#line 758 + if(remaining == 0) +#line 758 + break; /* normal loop exit */ +#line 758 + offset += (off_t)extent; +#line 758 + value += nput; +#line 758 + +#line 758 + } +#line 758 +#ifdef ERANGE_FILL +#line 758 + free(fillp); +#line 758 +#endif +#line 758 + +#line 758 + return status; +#line 758 +} +#line 758 + +static int +#line 759 +putNCvx_uchar_uint(NC3_INFO* ncp, const NC_var *varp, +#line 759 + const size_t *start, size_t nelems, const uint *value) +#line 759 +{ +#line 759 + off_t offset = NC_varoffset(ncp, varp, start); +#line 759 + size_t remaining = varp->xsz * nelems; +#line 759 + int status = NC_NOERR; +#line 759 + void *xp; +#line 759 + void *fillp=NULL; +#line 759 + +#line 759 + NC_UNUSED(fillp); +#line 759 + +#line 759 + if(nelems == 0) +#line 759 + return NC_NOERR; +#line 759 + +#line 759 + assert(value != NULL); +#line 759 + +#line 759 +#ifdef ERANGE_FILL +#line 759 + fillp = malloc(varp->xsz); +#line 759 + status = NC3_inq_var_fill(varp, fillp); +#line 759 +#endif +#line 759 + +#line 759 + for(;;) +#line 759 + { +#line 759 + size_t extent = MIN(remaining, ncp->chunk); +#line 759 + size_t nput = ncx_howmany(varp->type, extent); +#line 759 + +#line 759 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 759 + RGN_WRITE, &xp); +#line 759 + if(lstatus != NC_NOERR) +#line 759 + return lstatus; +#line 759 + +#line 759 + lstatus = ncx_putn_uchar_uint(&xp, nput, value ,fillp); +#line 759 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 759 + { +#line 759 + /* not fatal to the loop */ +#line 759 + status = lstatus; +#line 759 + } +#line 759 + +#line 759 + (void) ncio_rel(ncp->nciop, offset, +#line 759 + RGN_MODIFIED); +#line 759 + +#line 759 + remaining -= extent; +#line 759 + if(remaining == 0) +#line 759 + break; /* normal loop exit */ +#line 759 + offset += (off_t)extent; +#line 759 + value += nput; +#line 759 + +#line 759 + } +#line 759 +#ifdef ERANGE_FILL +#line 759 + free(fillp); +#line 759 +#endif +#line 759 + +#line 759 + return status; +#line 759 +} +#line 759 + +static int +#line 760 +putNCvx_uchar_ulonglong(NC3_INFO* ncp, const NC_var *varp, +#line 760 + const size_t *start, size_t nelems, const ulonglong *value) +#line 760 +{ +#line 760 + off_t offset = NC_varoffset(ncp, varp, start); +#line 760 + size_t remaining = varp->xsz * nelems; +#line 760 + int status = NC_NOERR; +#line 760 + void *xp; +#line 760 + void *fillp=NULL; +#line 760 + +#line 760 + NC_UNUSED(fillp); +#line 760 + +#line 760 + if(nelems == 0) +#line 760 + return NC_NOERR; +#line 760 + +#line 760 + assert(value != NULL); +#line 760 + +#line 760 +#ifdef ERANGE_FILL +#line 760 + fillp = malloc(varp->xsz); +#line 760 + status = NC3_inq_var_fill(varp, fillp); +#line 760 +#endif +#line 760 + +#line 760 + for(;;) +#line 760 + { +#line 760 + size_t extent = MIN(remaining, ncp->chunk); +#line 760 + size_t nput = ncx_howmany(varp->type, extent); +#line 760 + +#line 760 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 760 + RGN_WRITE, &xp); +#line 760 + if(lstatus != NC_NOERR) +#line 760 + return lstatus; +#line 760 + +#line 760 + lstatus = ncx_putn_uchar_ulonglong(&xp, nput, value ,fillp); +#line 760 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 760 + { +#line 760 + /* not fatal to the loop */ +#line 760 + status = lstatus; +#line 760 + } +#line 760 + +#line 760 + (void) ncio_rel(ncp->nciop, offset, +#line 760 + RGN_MODIFIED); +#line 760 + +#line 760 + remaining -= extent; +#line 760 + if(remaining == 0) +#line 760 + break; /* normal loop exit */ +#line 760 + offset += (off_t)extent; +#line 760 + value += nput; +#line 760 + +#line 760 + } +#line 760 +#ifdef ERANGE_FILL +#line 760 + free(fillp); +#line 760 +#endif +#line 760 + +#line 760 + return status; +#line 760 +} +#line 760 + + +static int +#line 762 +putNCvx_ushort_schar(NC3_INFO* ncp, const NC_var *varp, +#line 762 + const size_t *start, size_t nelems, const schar *value) +#line 762 +{ +#line 762 + off_t offset = NC_varoffset(ncp, varp, start); +#line 762 + size_t remaining = varp->xsz * nelems; +#line 762 + int status = NC_NOERR; +#line 762 + void *xp; +#line 762 + void *fillp=NULL; +#line 762 + +#line 762 + NC_UNUSED(fillp); +#line 762 + +#line 762 + if(nelems == 0) +#line 762 + return NC_NOERR; +#line 762 + +#line 762 + assert(value != NULL); +#line 762 + +#line 762 +#ifdef ERANGE_FILL +#line 762 + fillp = malloc(varp->xsz); +#line 762 + status = NC3_inq_var_fill(varp, fillp); +#line 762 +#endif +#line 762 + +#line 762 + for(;;) +#line 762 + { +#line 762 + size_t extent = MIN(remaining, ncp->chunk); +#line 762 + size_t nput = ncx_howmany(varp->type, extent); +#line 762 + +#line 762 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 762 + RGN_WRITE, &xp); +#line 762 + if(lstatus != NC_NOERR) +#line 762 + return lstatus; +#line 762 + +#line 762 + lstatus = ncx_putn_ushort_schar(&xp, nput, value ,fillp); +#line 762 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 762 + { +#line 762 + /* not fatal to the loop */ +#line 762 + status = lstatus; +#line 762 + } +#line 762 + +#line 762 + (void) ncio_rel(ncp->nciop, offset, +#line 762 + RGN_MODIFIED); +#line 762 + +#line 762 + remaining -= extent; +#line 762 + if(remaining == 0) +#line 762 + break; /* normal loop exit */ +#line 762 + offset += (off_t)extent; +#line 762 + value += nput; +#line 762 + +#line 762 + } +#line 762 +#ifdef ERANGE_FILL +#line 762 + free(fillp); +#line 762 +#endif +#line 762 + +#line 762 + return status; +#line 762 +} +#line 762 + +static int +#line 763 +putNCvx_ushort_uchar(NC3_INFO* ncp, const NC_var *varp, +#line 763 + const size_t *start, size_t nelems, const uchar *value) +#line 763 +{ +#line 763 + off_t offset = NC_varoffset(ncp, varp, start); +#line 763 + size_t remaining = varp->xsz * nelems; +#line 763 + int status = NC_NOERR; +#line 763 + void *xp; +#line 763 + void *fillp=NULL; +#line 763 + +#line 763 + NC_UNUSED(fillp); +#line 763 + +#line 763 + if(nelems == 0) +#line 763 + return NC_NOERR; +#line 763 + +#line 763 + assert(value != NULL); +#line 763 + +#line 763 +#ifdef ERANGE_FILL +#line 763 + fillp = malloc(varp->xsz); +#line 763 + status = NC3_inq_var_fill(varp, fillp); +#line 763 +#endif +#line 763 + +#line 763 + for(;;) +#line 763 + { +#line 763 + size_t extent = MIN(remaining, ncp->chunk); +#line 763 + size_t nput = ncx_howmany(varp->type, extent); +#line 763 + +#line 763 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 763 + RGN_WRITE, &xp); +#line 763 + if(lstatus != NC_NOERR) +#line 763 + return lstatus; +#line 763 + +#line 763 + lstatus = ncx_putn_ushort_uchar(&xp, nput, value ,fillp); +#line 763 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 763 + { +#line 763 + /* not fatal to the loop */ +#line 763 + status = lstatus; +#line 763 + } +#line 763 + +#line 763 + (void) ncio_rel(ncp->nciop, offset, +#line 763 + RGN_MODIFIED); +#line 763 + +#line 763 + remaining -= extent; +#line 763 + if(remaining == 0) +#line 763 + break; /* normal loop exit */ +#line 763 + offset += (off_t)extent; +#line 763 + value += nput; +#line 763 + +#line 763 + } +#line 763 +#ifdef ERANGE_FILL +#line 763 + free(fillp); +#line 763 +#endif +#line 763 + +#line 763 + return status; +#line 763 +} +#line 763 + +static int +#line 764 +putNCvx_ushort_short(NC3_INFO* ncp, const NC_var *varp, +#line 764 + const size_t *start, size_t nelems, const short *value) +#line 764 +{ +#line 764 + off_t offset = NC_varoffset(ncp, varp, start); +#line 764 + size_t remaining = varp->xsz * nelems; +#line 764 + int status = NC_NOERR; +#line 764 + void *xp; +#line 764 + void *fillp=NULL; +#line 764 + +#line 764 + NC_UNUSED(fillp); +#line 764 + +#line 764 + if(nelems == 0) +#line 764 + return NC_NOERR; +#line 764 + +#line 764 + assert(value != NULL); +#line 764 + +#line 764 +#ifdef ERANGE_FILL +#line 764 + fillp = malloc(varp->xsz); +#line 764 + status = NC3_inq_var_fill(varp, fillp); +#line 764 +#endif +#line 764 + +#line 764 + for(;;) +#line 764 + { +#line 764 + size_t extent = MIN(remaining, ncp->chunk); +#line 764 + size_t nput = ncx_howmany(varp->type, extent); +#line 764 + +#line 764 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 764 + RGN_WRITE, &xp); +#line 764 + if(lstatus != NC_NOERR) +#line 764 + return lstatus; +#line 764 + +#line 764 + lstatus = ncx_putn_ushort_short(&xp, nput, value ,fillp); +#line 764 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 764 + { +#line 764 + /* not fatal to the loop */ +#line 764 + status = lstatus; +#line 764 + } +#line 764 + +#line 764 + (void) ncio_rel(ncp->nciop, offset, +#line 764 + RGN_MODIFIED); +#line 764 + +#line 764 + remaining -= extent; +#line 764 + if(remaining == 0) +#line 764 + break; /* normal loop exit */ +#line 764 + offset += (off_t)extent; +#line 764 + value += nput; +#line 764 + +#line 764 + } +#line 764 +#ifdef ERANGE_FILL +#line 764 + free(fillp); +#line 764 +#endif +#line 764 + +#line 764 + return status; +#line 764 +} +#line 764 + +static int +#line 765 +putNCvx_ushort_int(NC3_INFO* ncp, const NC_var *varp, +#line 765 + const size_t *start, size_t nelems, const int *value) +#line 765 +{ +#line 765 + off_t offset = NC_varoffset(ncp, varp, start); +#line 765 + size_t remaining = varp->xsz * nelems; +#line 765 + int status = NC_NOERR; +#line 765 + void *xp; +#line 765 + void *fillp=NULL; +#line 765 + +#line 765 + NC_UNUSED(fillp); +#line 765 + +#line 765 + if(nelems == 0) +#line 765 + return NC_NOERR; +#line 765 + +#line 765 + assert(value != NULL); +#line 765 + +#line 765 +#ifdef ERANGE_FILL +#line 765 + fillp = malloc(varp->xsz); +#line 765 + status = NC3_inq_var_fill(varp, fillp); +#line 765 +#endif +#line 765 + +#line 765 + for(;;) +#line 765 + { +#line 765 + size_t extent = MIN(remaining, ncp->chunk); +#line 765 + size_t nput = ncx_howmany(varp->type, extent); +#line 765 + +#line 765 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 765 + RGN_WRITE, &xp); +#line 765 + if(lstatus != NC_NOERR) +#line 765 + return lstatus; +#line 765 + +#line 765 + lstatus = ncx_putn_ushort_int(&xp, nput, value ,fillp); +#line 765 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 765 + { +#line 765 + /* not fatal to the loop */ +#line 765 + status = lstatus; +#line 765 + } +#line 765 + +#line 765 + (void) ncio_rel(ncp->nciop, offset, +#line 765 + RGN_MODIFIED); +#line 765 + +#line 765 + remaining -= extent; +#line 765 + if(remaining == 0) +#line 765 + break; /* normal loop exit */ +#line 765 + offset += (off_t)extent; +#line 765 + value += nput; +#line 765 + +#line 765 + } +#line 765 +#ifdef ERANGE_FILL +#line 765 + free(fillp); +#line 765 +#endif +#line 765 + +#line 765 + return status; +#line 765 +} +#line 765 + +static int +#line 766 +putNCvx_ushort_float(NC3_INFO* ncp, const NC_var *varp, +#line 766 + const size_t *start, size_t nelems, const float *value) +#line 766 +{ +#line 766 + off_t offset = NC_varoffset(ncp, varp, start); +#line 766 + size_t remaining = varp->xsz * nelems; +#line 766 + int status = NC_NOERR; +#line 766 + void *xp; +#line 766 + void *fillp=NULL; +#line 766 + +#line 766 + NC_UNUSED(fillp); +#line 766 + +#line 766 + if(nelems == 0) +#line 766 + return NC_NOERR; +#line 766 + +#line 766 + assert(value != NULL); +#line 766 + +#line 766 +#ifdef ERANGE_FILL +#line 766 + fillp = malloc(varp->xsz); +#line 766 + status = NC3_inq_var_fill(varp, fillp); +#line 766 +#endif +#line 766 + +#line 766 + for(;;) +#line 766 + { +#line 766 + size_t extent = MIN(remaining, ncp->chunk); +#line 766 + size_t nput = ncx_howmany(varp->type, extent); +#line 766 + +#line 766 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 766 + RGN_WRITE, &xp); +#line 766 + if(lstatus != NC_NOERR) +#line 766 + return lstatus; +#line 766 + +#line 766 + lstatus = ncx_putn_ushort_float(&xp, nput, value ,fillp); +#line 766 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 766 + { +#line 766 + /* not fatal to the loop */ +#line 766 + status = lstatus; +#line 766 + } +#line 766 + +#line 766 + (void) ncio_rel(ncp->nciop, offset, +#line 766 + RGN_MODIFIED); +#line 766 + +#line 766 + remaining -= extent; +#line 766 + if(remaining == 0) +#line 766 + break; /* normal loop exit */ +#line 766 + offset += (off_t)extent; +#line 766 + value += nput; +#line 766 + +#line 766 + } +#line 766 +#ifdef ERANGE_FILL +#line 766 + free(fillp); +#line 766 +#endif +#line 766 + +#line 766 + return status; +#line 766 +} +#line 766 + +static int +#line 767 +putNCvx_ushort_double(NC3_INFO* ncp, const NC_var *varp, +#line 767 + const size_t *start, size_t nelems, const double *value) +#line 767 +{ +#line 767 + off_t offset = NC_varoffset(ncp, varp, start); +#line 767 + size_t remaining = varp->xsz * nelems; +#line 767 + int status = NC_NOERR; +#line 767 + void *xp; +#line 767 + void *fillp=NULL; +#line 767 + +#line 767 + NC_UNUSED(fillp); +#line 767 + +#line 767 + if(nelems == 0) +#line 767 + return NC_NOERR; +#line 767 + +#line 767 + assert(value != NULL); +#line 767 + +#line 767 +#ifdef ERANGE_FILL +#line 767 + fillp = malloc(varp->xsz); +#line 767 + status = NC3_inq_var_fill(varp, fillp); +#line 767 +#endif +#line 767 + +#line 767 + for(;;) +#line 767 + { +#line 767 + size_t extent = MIN(remaining, ncp->chunk); +#line 767 + size_t nput = ncx_howmany(varp->type, extent); +#line 767 + +#line 767 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 767 + RGN_WRITE, &xp); +#line 767 + if(lstatus != NC_NOERR) +#line 767 + return lstatus; +#line 767 + +#line 767 + lstatus = ncx_putn_ushort_double(&xp, nput, value ,fillp); +#line 767 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 767 + { +#line 767 + /* not fatal to the loop */ +#line 767 + status = lstatus; +#line 767 + } +#line 767 + +#line 767 + (void) ncio_rel(ncp->nciop, offset, +#line 767 + RGN_MODIFIED); +#line 767 + +#line 767 + remaining -= extent; +#line 767 + if(remaining == 0) +#line 767 + break; /* normal loop exit */ +#line 767 + offset += (off_t)extent; +#line 767 + value += nput; +#line 767 + +#line 767 + } +#line 767 +#ifdef ERANGE_FILL +#line 767 + free(fillp); +#line 767 +#endif +#line 767 + +#line 767 + return status; +#line 767 +} +#line 767 + +static int +#line 768 +putNCvx_ushort_longlong(NC3_INFO* ncp, const NC_var *varp, +#line 768 + const size_t *start, size_t nelems, const longlong *value) +#line 768 +{ +#line 768 + off_t offset = NC_varoffset(ncp, varp, start); +#line 768 + size_t remaining = varp->xsz * nelems; +#line 768 + int status = NC_NOERR; +#line 768 + void *xp; +#line 768 + void *fillp=NULL; +#line 768 + +#line 768 + NC_UNUSED(fillp); +#line 768 + +#line 768 + if(nelems == 0) +#line 768 + return NC_NOERR; +#line 768 + +#line 768 + assert(value != NULL); +#line 768 + +#line 768 +#ifdef ERANGE_FILL +#line 768 + fillp = malloc(varp->xsz); +#line 768 + status = NC3_inq_var_fill(varp, fillp); +#line 768 +#endif +#line 768 + +#line 768 + for(;;) +#line 768 + { +#line 768 + size_t extent = MIN(remaining, ncp->chunk); +#line 768 + size_t nput = ncx_howmany(varp->type, extent); +#line 768 + +#line 768 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 768 + RGN_WRITE, &xp); +#line 768 + if(lstatus != NC_NOERR) +#line 768 + return lstatus; +#line 768 + +#line 768 + lstatus = ncx_putn_ushort_longlong(&xp, nput, value ,fillp); +#line 768 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 768 + { +#line 768 + /* not fatal to the loop */ +#line 768 + status = lstatus; +#line 768 + } +#line 768 + +#line 768 + (void) ncio_rel(ncp->nciop, offset, +#line 768 + RGN_MODIFIED); +#line 768 + +#line 768 + remaining -= extent; +#line 768 + if(remaining == 0) +#line 768 + break; /* normal loop exit */ +#line 768 + offset += (off_t)extent; +#line 768 + value += nput; +#line 768 + +#line 768 + } +#line 768 +#ifdef ERANGE_FILL +#line 768 + free(fillp); +#line 768 +#endif +#line 768 + +#line 768 + return status; +#line 768 +} +#line 768 + +static int +#line 769 +putNCvx_ushort_ushort(NC3_INFO* ncp, const NC_var *varp, +#line 769 + const size_t *start, size_t nelems, const ushort *value) +#line 769 +{ +#line 769 + off_t offset = NC_varoffset(ncp, varp, start); +#line 769 + size_t remaining = varp->xsz * nelems; +#line 769 + int status = NC_NOERR; +#line 769 + void *xp; +#line 769 + void *fillp=NULL; +#line 769 + +#line 769 + NC_UNUSED(fillp); +#line 769 + +#line 769 + if(nelems == 0) +#line 769 + return NC_NOERR; +#line 769 + +#line 769 + assert(value != NULL); +#line 769 + +#line 769 +#ifdef ERANGE_FILL +#line 769 + fillp = malloc(varp->xsz); +#line 769 + status = NC3_inq_var_fill(varp, fillp); +#line 769 +#endif +#line 769 + +#line 769 + for(;;) +#line 769 + { +#line 769 + size_t extent = MIN(remaining, ncp->chunk); +#line 769 + size_t nput = ncx_howmany(varp->type, extent); +#line 769 + +#line 769 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 769 + RGN_WRITE, &xp); +#line 769 + if(lstatus != NC_NOERR) +#line 769 + return lstatus; +#line 769 + +#line 769 + lstatus = ncx_putn_ushort_ushort(&xp, nput, value ,fillp); +#line 769 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 769 + { +#line 769 + /* not fatal to the loop */ +#line 769 + status = lstatus; +#line 769 + } +#line 769 + +#line 769 + (void) ncio_rel(ncp->nciop, offset, +#line 769 + RGN_MODIFIED); +#line 769 + +#line 769 + remaining -= extent; +#line 769 + if(remaining == 0) +#line 769 + break; /* normal loop exit */ +#line 769 + offset += (off_t)extent; +#line 769 + value += nput; +#line 769 + +#line 769 + } +#line 769 +#ifdef ERANGE_FILL +#line 769 + free(fillp); +#line 769 +#endif +#line 769 + +#line 769 + return status; +#line 769 +} +#line 769 + +static int +#line 770 +putNCvx_ushort_uint(NC3_INFO* ncp, const NC_var *varp, +#line 770 + const size_t *start, size_t nelems, const uint *value) +#line 770 +{ +#line 770 + off_t offset = NC_varoffset(ncp, varp, start); +#line 770 + size_t remaining = varp->xsz * nelems; +#line 770 + int status = NC_NOERR; +#line 770 + void *xp; +#line 770 + void *fillp=NULL; +#line 770 + +#line 770 + NC_UNUSED(fillp); +#line 770 + +#line 770 + if(nelems == 0) +#line 770 + return NC_NOERR; +#line 770 + +#line 770 + assert(value != NULL); +#line 770 + +#line 770 +#ifdef ERANGE_FILL +#line 770 + fillp = malloc(varp->xsz); +#line 770 + status = NC3_inq_var_fill(varp, fillp); +#line 770 +#endif +#line 770 + +#line 770 + for(;;) +#line 770 + { +#line 770 + size_t extent = MIN(remaining, ncp->chunk); +#line 770 + size_t nput = ncx_howmany(varp->type, extent); +#line 770 + +#line 770 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 770 + RGN_WRITE, &xp); +#line 770 + if(lstatus != NC_NOERR) +#line 770 + return lstatus; +#line 770 + +#line 770 + lstatus = ncx_putn_ushort_uint(&xp, nput, value ,fillp); +#line 770 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 770 + { +#line 770 + /* not fatal to the loop */ +#line 770 + status = lstatus; +#line 770 + } +#line 770 + +#line 770 + (void) ncio_rel(ncp->nciop, offset, +#line 770 + RGN_MODIFIED); +#line 770 + +#line 770 + remaining -= extent; +#line 770 + if(remaining == 0) +#line 770 + break; /* normal loop exit */ +#line 770 + offset += (off_t)extent; +#line 770 + value += nput; +#line 770 + +#line 770 + } +#line 770 +#ifdef ERANGE_FILL +#line 770 + free(fillp); +#line 770 +#endif +#line 770 + +#line 770 + return status; +#line 770 +} +#line 770 + +static int +#line 771 +putNCvx_ushort_ulonglong(NC3_INFO* ncp, const NC_var *varp, +#line 771 + const size_t *start, size_t nelems, const ulonglong *value) +#line 771 +{ +#line 771 + off_t offset = NC_varoffset(ncp, varp, start); +#line 771 + size_t remaining = varp->xsz * nelems; +#line 771 + int status = NC_NOERR; +#line 771 + void *xp; +#line 771 + void *fillp=NULL; +#line 771 + +#line 771 + NC_UNUSED(fillp); +#line 771 + +#line 771 + if(nelems == 0) +#line 771 + return NC_NOERR; +#line 771 + +#line 771 + assert(value != NULL); +#line 771 + +#line 771 +#ifdef ERANGE_FILL +#line 771 + fillp = malloc(varp->xsz); +#line 771 + status = NC3_inq_var_fill(varp, fillp); +#line 771 +#endif +#line 771 + +#line 771 + for(;;) +#line 771 + { +#line 771 + size_t extent = MIN(remaining, ncp->chunk); +#line 771 + size_t nput = ncx_howmany(varp->type, extent); +#line 771 + +#line 771 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 771 + RGN_WRITE, &xp); +#line 771 + if(lstatus != NC_NOERR) +#line 771 + return lstatus; +#line 771 + +#line 771 + lstatus = ncx_putn_ushort_ulonglong(&xp, nput, value ,fillp); +#line 771 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 771 + { +#line 771 + /* not fatal to the loop */ +#line 771 + status = lstatus; +#line 771 + } +#line 771 + +#line 771 + (void) ncio_rel(ncp->nciop, offset, +#line 771 + RGN_MODIFIED); +#line 771 + +#line 771 + remaining -= extent; +#line 771 + if(remaining == 0) +#line 771 + break; /* normal loop exit */ +#line 771 + offset += (off_t)extent; +#line 771 + value += nput; +#line 771 + +#line 771 + } +#line 771 +#ifdef ERANGE_FILL +#line 771 + free(fillp); +#line 771 +#endif +#line 771 + +#line 771 + return status; +#line 771 +} +#line 771 + + +static int +#line 773 +putNCvx_uint_schar(NC3_INFO* ncp, const NC_var *varp, +#line 773 + const size_t *start, size_t nelems, const schar *value) +#line 773 +{ +#line 773 + off_t offset = NC_varoffset(ncp, varp, start); +#line 773 + size_t remaining = varp->xsz * nelems; +#line 773 + int status = NC_NOERR; +#line 773 + void *xp; +#line 773 + void *fillp=NULL; +#line 773 + +#line 773 + NC_UNUSED(fillp); +#line 773 + +#line 773 + if(nelems == 0) +#line 773 + return NC_NOERR; +#line 773 + +#line 773 + assert(value != NULL); +#line 773 + +#line 773 +#ifdef ERANGE_FILL +#line 773 + fillp = malloc(varp->xsz); +#line 773 + status = NC3_inq_var_fill(varp, fillp); +#line 773 +#endif +#line 773 + +#line 773 + for(;;) +#line 773 + { +#line 773 + size_t extent = MIN(remaining, ncp->chunk); +#line 773 + size_t nput = ncx_howmany(varp->type, extent); +#line 773 + +#line 773 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 773 + RGN_WRITE, &xp); +#line 773 + if(lstatus != NC_NOERR) +#line 773 + return lstatus; +#line 773 + +#line 773 + lstatus = ncx_putn_uint_schar(&xp, nput, value ,fillp); +#line 773 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 773 + { +#line 773 + /* not fatal to the loop */ +#line 773 + status = lstatus; +#line 773 + } +#line 773 + +#line 773 + (void) ncio_rel(ncp->nciop, offset, +#line 773 + RGN_MODIFIED); +#line 773 + +#line 773 + remaining -= extent; +#line 773 + if(remaining == 0) +#line 773 + break; /* normal loop exit */ +#line 773 + offset += (off_t)extent; +#line 773 + value += nput; +#line 773 + +#line 773 + } +#line 773 +#ifdef ERANGE_FILL +#line 773 + free(fillp); +#line 773 +#endif +#line 773 + +#line 773 + return status; +#line 773 +} +#line 773 + +static int +#line 774 +putNCvx_uint_uchar(NC3_INFO* ncp, const NC_var *varp, +#line 774 + const size_t *start, size_t nelems, const uchar *value) +#line 774 +{ +#line 774 + off_t offset = NC_varoffset(ncp, varp, start); +#line 774 + size_t remaining = varp->xsz * nelems; +#line 774 + int status = NC_NOERR; +#line 774 + void *xp; +#line 774 + void *fillp=NULL; +#line 774 + +#line 774 + NC_UNUSED(fillp); +#line 774 + +#line 774 + if(nelems == 0) +#line 774 + return NC_NOERR; +#line 774 + +#line 774 + assert(value != NULL); +#line 774 + +#line 774 +#ifdef ERANGE_FILL +#line 774 + fillp = malloc(varp->xsz); +#line 774 + status = NC3_inq_var_fill(varp, fillp); +#line 774 +#endif +#line 774 + +#line 774 + for(;;) +#line 774 + { +#line 774 + size_t extent = MIN(remaining, ncp->chunk); +#line 774 + size_t nput = ncx_howmany(varp->type, extent); +#line 774 + +#line 774 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 774 + RGN_WRITE, &xp); +#line 774 + if(lstatus != NC_NOERR) +#line 774 + return lstatus; +#line 774 + +#line 774 + lstatus = ncx_putn_uint_uchar(&xp, nput, value ,fillp); +#line 774 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 774 + { +#line 774 + /* not fatal to the loop */ +#line 774 + status = lstatus; +#line 774 + } +#line 774 + +#line 774 + (void) ncio_rel(ncp->nciop, offset, +#line 774 + RGN_MODIFIED); +#line 774 + +#line 774 + remaining -= extent; +#line 774 + if(remaining == 0) +#line 774 + break; /* normal loop exit */ +#line 774 + offset += (off_t)extent; +#line 774 + value += nput; +#line 774 + +#line 774 + } +#line 774 +#ifdef ERANGE_FILL +#line 774 + free(fillp); +#line 774 +#endif +#line 774 + +#line 774 + return status; +#line 774 +} +#line 774 + +static int +#line 775 +putNCvx_uint_short(NC3_INFO* ncp, const NC_var *varp, +#line 775 + const size_t *start, size_t nelems, const short *value) +#line 775 +{ +#line 775 + off_t offset = NC_varoffset(ncp, varp, start); +#line 775 + size_t remaining = varp->xsz * nelems; +#line 775 + int status = NC_NOERR; +#line 775 + void *xp; +#line 775 + void *fillp=NULL; +#line 775 + +#line 775 + NC_UNUSED(fillp); +#line 775 + +#line 775 + if(nelems == 0) +#line 775 + return NC_NOERR; +#line 775 + +#line 775 + assert(value != NULL); +#line 775 + +#line 775 +#ifdef ERANGE_FILL +#line 775 + fillp = malloc(varp->xsz); +#line 775 + status = NC3_inq_var_fill(varp, fillp); +#line 775 +#endif +#line 775 + +#line 775 + for(;;) +#line 775 + { +#line 775 + size_t extent = MIN(remaining, ncp->chunk); +#line 775 + size_t nput = ncx_howmany(varp->type, extent); +#line 775 + +#line 775 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 775 + RGN_WRITE, &xp); +#line 775 + if(lstatus != NC_NOERR) +#line 775 + return lstatus; +#line 775 + +#line 775 + lstatus = ncx_putn_uint_short(&xp, nput, value ,fillp); +#line 775 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 775 + { +#line 775 + /* not fatal to the loop */ +#line 775 + status = lstatus; +#line 775 + } +#line 775 + +#line 775 + (void) ncio_rel(ncp->nciop, offset, +#line 775 + RGN_MODIFIED); +#line 775 + +#line 775 + remaining -= extent; +#line 775 + if(remaining == 0) +#line 775 + break; /* normal loop exit */ +#line 775 + offset += (off_t)extent; +#line 775 + value += nput; +#line 775 + +#line 775 + } +#line 775 +#ifdef ERANGE_FILL +#line 775 + free(fillp); +#line 775 +#endif +#line 775 + +#line 775 + return status; +#line 775 +} +#line 775 + +static int +#line 776 +putNCvx_uint_int(NC3_INFO* ncp, const NC_var *varp, +#line 776 + const size_t *start, size_t nelems, const int *value) +#line 776 +{ +#line 776 + off_t offset = NC_varoffset(ncp, varp, start); +#line 776 + size_t remaining = varp->xsz * nelems; +#line 776 + int status = NC_NOERR; +#line 776 + void *xp; +#line 776 + void *fillp=NULL; +#line 776 + +#line 776 + NC_UNUSED(fillp); +#line 776 + +#line 776 + if(nelems == 0) +#line 776 + return NC_NOERR; +#line 776 + +#line 776 + assert(value != NULL); +#line 776 + +#line 776 +#ifdef ERANGE_FILL +#line 776 + fillp = malloc(varp->xsz); +#line 776 + status = NC3_inq_var_fill(varp, fillp); +#line 776 +#endif +#line 776 + +#line 776 + for(;;) +#line 776 + { +#line 776 + size_t extent = MIN(remaining, ncp->chunk); +#line 776 + size_t nput = ncx_howmany(varp->type, extent); +#line 776 + +#line 776 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 776 + RGN_WRITE, &xp); +#line 776 + if(lstatus != NC_NOERR) +#line 776 + return lstatus; +#line 776 + +#line 776 + lstatus = ncx_putn_uint_int(&xp, nput, value ,fillp); +#line 776 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 776 + { +#line 776 + /* not fatal to the loop */ +#line 776 + status = lstatus; +#line 776 + } +#line 776 + +#line 776 + (void) ncio_rel(ncp->nciop, offset, +#line 776 + RGN_MODIFIED); +#line 776 + +#line 776 + remaining -= extent; +#line 776 + if(remaining == 0) +#line 776 + break; /* normal loop exit */ +#line 776 + offset += (off_t)extent; +#line 776 + value += nput; +#line 776 + +#line 776 + } +#line 776 +#ifdef ERANGE_FILL +#line 776 + free(fillp); +#line 776 +#endif +#line 776 + +#line 776 + return status; +#line 776 +} +#line 776 + +static int +#line 777 +putNCvx_uint_float(NC3_INFO* ncp, const NC_var *varp, +#line 777 + const size_t *start, size_t nelems, const float *value) +#line 777 +{ +#line 777 + off_t offset = NC_varoffset(ncp, varp, start); +#line 777 + size_t remaining = varp->xsz * nelems; +#line 777 + int status = NC_NOERR; +#line 777 + void *xp; +#line 777 + void *fillp=NULL; +#line 777 + +#line 777 + NC_UNUSED(fillp); +#line 777 + +#line 777 + if(nelems == 0) +#line 777 + return NC_NOERR; +#line 777 + +#line 777 + assert(value != NULL); +#line 777 + +#line 777 +#ifdef ERANGE_FILL +#line 777 + fillp = malloc(varp->xsz); +#line 777 + status = NC3_inq_var_fill(varp, fillp); +#line 777 +#endif +#line 777 + +#line 777 + for(;;) +#line 777 + { +#line 777 + size_t extent = MIN(remaining, ncp->chunk); +#line 777 + size_t nput = ncx_howmany(varp->type, extent); +#line 777 + +#line 777 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 777 + RGN_WRITE, &xp); +#line 777 + if(lstatus != NC_NOERR) +#line 777 + return lstatus; +#line 777 + +#line 777 + lstatus = ncx_putn_uint_float(&xp, nput, value ,fillp); +#line 777 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 777 + { +#line 777 + /* not fatal to the loop */ +#line 777 + status = lstatus; +#line 777 + } +#line 777 + +#line 777 + (void) ncio_rel(ncp->nciop, offset, +#line 777 + RGN_MODIFIED); +#line 777 + +#line 777 + remaining -= extent; +#line 777 + if(remaining == 0) +#line 777 + break; /* normal loop exit */ +#line 777 + offset += (off_t)extent; +#line 777 + value += nput; +#line 777 + +#line 777 + } +#line 777 +#ifdef ERANGE_FILL +#line 777 + free(fillp); +#line 777 +#endif +#line 777 + +#line 777 + return status; +#line 777 +} +#line 777 + +static int +#line 778 +putNCvx_uint_double(NC3_INFO* ncp, const NC_var *varp, +#line 778 + const size_t *start, size_t nelems, const double *value) +#line 778 +{ +#line 778 + off_t offset = NC_varoffset(ncp, varp, start); +#line 778 + size_t remaining = varp->xsz * nelems; +#line 778 + int status = NC_NOERR; +#line 778 + void *xp; +#line 778 + void *fillp=NULL; +#line 778 + +#line 778 + NC_UNUSED(fillp); +#line 778 + +#line 778 + if(nelems == 0) +#line 778 + return NC_NOERR; +#line 778 + +#line 778 + assert(value != NULL); +#line 778 + +#line 778 +#ifdef ERANGE_FILL +#line 778 + fillp = malloc(varp->xsz); +#line 778 + status = NC3_inq_var_fill(varp, fillp); +#line 778 +#endif +#line 778 + +#line 778 + for(;;) +#line 778 + { +#line 778 + size_t extent = MIN(remaining, ncp->chunk); +#line 778 + size_t nput = ncx_howmany(varp->type, extent); +#line 778 + +#line 778 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 778 + RGN_WRITE, &xp); +#line 778 + if(lstatus != NC_NOERR) +#line 778 + return lstatus; +#line 778 + +#line 778 + lstatus = ncx_putn_uint_double(&xp, nput, value ,fillp); +#line 778 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 778 + { +#line 778 + /* not fatal to the loop */ +#line 778 + status = lstatus; +#line 778 + } +#line 778 + +#line 778 + (void) ncio_rel(ncp->nciop, offset, +#line 778 + RGN_MODIFIED); +#line 778 + +#line 778 + remaining -= extent; +#line 778 + if(remaining == 0) +#line 778 + break; /* normal loop exit */ +#line 778 + offset += (off_t)extent; +#line 778 + value += nput; +#line 778 + +#line 778 + } +#line 778 +#ifdef ERANGE_FILL +#line 778 + free(fillp); +#line 778 +#endif +#line 778 + +#line 778 + return status; +#line 778 +} +#line 778 + +static int +#line 779 +putNCvx_uint_longlong(NC3_INFO* ncp, const NC_var *varp, +#line 779 + const size_t *start, size_t nelems, const longlong *value) +#line 779 +{ +#line 779 + off_t offset = NC_varoffset(ncp, varp, start); +#line 779 + size_t remaining = varp->xsz * nelems; +#line 779 + int status = NC_NOERR; +#line 779 + void *xp; +#line 779 + void *fillp=NULL; +#line 779 + +#line 779 + NC_UNUSED(fillp); +#line 779 + +#line 779 + if(nelems == 0) +#line 779 + return NC_NOERR; +#line 779 + +#line 779 + assert(value != NULL); +#line 779 + +#line 779 +#ifdef ERANGE_FILL +#line 779 + fillp = malloc(varp->xsz); +#line 779 + status = NC3_inq_var_fill(varp, fillp); +#line 779 +#endif +#line 779 + +#line 779 + for(;;) +#line 779 + { +#line 779 + size_t extent = MIN(remaining, ncp->chunk); +#line 779 + size_t nput = ncx_howmany(varp->type, extent); +#line 779 + +#line 779 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 779 + RGN_WRITE, &xp); +#line 779 + if(lstatus != NC_NOERR) +#line 779 + return lstatus; +#line 779 + +#line 779 + lstatus = ncx_putn_uint_longlong(&xp, nput, value ,fillp); +#line 779 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 779 + { +#line 779 + /* not fatal to the loop */ +#line 779 + status = lstatus; +#line 779 + } +#line 779 + +#line 779 + (void) ncio_rel(ncp->nciop, offset, +#line 779 + RGN_MODIFIED); +#line 779 + +#line 779 + remaining -= extent; +#line 779 + if(remaining == 0) +#line 779 + break; /* normal loop exit */ +#line 779 + offset += (off_t)extent; +#line 779 + value += nput; +#line 779 + +#line 779 + } +#line 779 +#ifdef ERANGE_FILL +#line 779 + free(fillp); +#line 779 +#endif +#line 779 + +#line 779 + return status; +#line 779 +} +#line 779 + +static int +#line 780 +putNCvx_uint_ushort(NC3_INFO* ncp, const NC_var *varp, +#line 780 + const size_t *start, size_t nelems, const ushort *value) +#line 780 +{ +#line 780 + off_t offset = NC_varoffset(ncp, varp, start); +#line 780 + size_t remaining = varp->xsz * nelems; +#line 780 + int status = NC_NOERR; +#line 780 + void *xp; +#line 780 + void *fillp=NULL; +#line 780 + +#line 780 + NC_UNUSED(fillp); +#line 780 + +#line 780 + if(nelems == 0) +#line 780 + return NC_NOERR; +#line 780 + +#line 780 + assert(value != NULL); +#line 780 + +#line 780 +#ifdef ERANGE_FILL +#line 780 + fillp = malloc(varp->xsz); +#line 780 + status = NC3_inq_var_fill(varp, fillp); +#line 780 +#endif +#line 780 + +#line 780 + for(;;) +#line 780 + { +#line 780 + size_t extent = MIN(remaining, ncp->chunk); +#line 780 + size_t nput = ncx_howmany(varp->type, extent); +#line 780 + +#line 780 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 780 + RGN_WRITE, &xp); +#line 780 + if(lstatus != NC_NOERR) +#line 780 + return lstatus; +#line 780 + +#line 780 + lstatus = ncx_putn_uint_ushort(&xp, nput, value ,fillp); +#line 780 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 780 + { +#line 780 + /* not fatal to the loop */ +#line 780 + status = lstatus; +#line 780 + } +#line 780 + +#line 780 + (void) ncio_rel(ncp->nciop, offset, +#line 780 + RGN_MODIFIED); +#line 780 + +#line 780 + remaining -= extent; +#line 780 + if(remaining == 0) +#line 780 + break; /* normal loop exit */ +#line 780 + offset += (off_t)extent; +#line 780 + value += nput; +#line 780 + +#line 780 + } +#line 780 +#ifdef ERANGE_FILL +#line 780 + free(fillp); +#line 780 +#endif +#line 780 + +#line 780 + return status; +#line 780 +} +#line 780 + +static int +#line 781 +putNCvx_uint_uint(NC3_INFO* ncp, const NC_var *varp, +#line 781 + const size_t *start, size_t nelems, const uint *value) +#line 781 +{ +#line 781 + off_t offset = NC_varoffset(ncp, varp, start); +#line 781 + size_t remaining = varp->xsz * nelems; +#line 781 + int status = NC_NOERR; +#line 781 + void *xp; +#line 781 + void *fillp=NULL; +#line 781 + +#line 781 + NC_UNUSED(fillp); +#line 781 + +#line 781 + if(nelems == 0) +#line 781 + return NC_NOERR; +#line 781 + +#line 781 + assert(value != NULL); +#line 781 + +#line 781 +#ifdef ERANGE_FILL +#line 781 + fillp = malloc(varp->xsz); +#line 781 + status = NC3_inq_var_fill(varp, fillp); +#line 781 +#endif +#line 781 + +#line 781 + for(;;) +#line 781 + { +#line 781 + size_t extent = MIN(remaining, ncp->chunk); +#line 781 + size_t nput = ncx_howmany(varp->type, extent); +#line 781 + +#line 781 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 781 + RGN_WRITE, &xp); +#line 781 + if(lstatus != NC_NOERR) +#line 781 + return lstatus; +#line 781 + +#line 781 + lstatus = ncx_putn_uint_uint(&xp, nput, value ,fillp); +#line 781 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 781 + { +#line 781 + /* not fatal to the loop */ +#line 781 + status = lstatus; +#line 781 + } +#line 781 + +#line 781 + (void) ncio_rel(ncp->nciop, offset, +#line 781 + RGN_MODIFIED); +#line 781 + +#line 781 + remaining -= extent; +#line 781 + if(remaining == 0) +#line 781 + break; /* normal loop exit */ +#line 781 + offset += (off_t)extent; +#line 781 + value += nput; +#line 781 + +#line 781 + } +#line 781 +#ifdef ERANGE_FILL +#line 781 + free(fillp); +#line 781 +#endif +#line 781 + +#line 781 + return status; +#line 781 +} +#line 781 + +static int +#line 782 +putNCvx_uint_ulonglong(NC3_INFO* ncp, const NC_var *varp, +#line 782 + const size_t *start, size_t nelems, const ulonglong *value) +#line 782 +{ +#line 782 + off_t offset = NC_varoffset(ncp, varp, start); +#line 782 + size_t remaining = varp->xsz * nelems; +#line 782 + int status = NC_NOERR; +#line 782 + void *xp; +#line 782 + void *fillp=NULL; +#line 782 + +#line 782 + NC_UNUSED(fillp); +#line 782 + +#line 782 + if(nelems == 0) +#line 782 + return NC_NOERR; +#line 782 + +#line 782 + assert(value != NULL); +#line 782 + +#line 782 +#ifdef ERANGE_FILL +#line 782 + fillp = malloc(varp->xsz); +#line 782 + status = NC3_inq_var_fill(varp, fillp); +#line 782 +#endif +#line 782 + +#line 782 + for(;;) +#line 782 + { +#line 782 + size_t extent = MIN(remaining, ncp->chunk); +#line 782 + size_t nput = ncx_howmany(varp->type, extent); +#line 782 + +#line 782 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 782 + RGN_WRITE, &xp); +#line 782 + if(lstatus != NC_NOERR) +#line 782 + return lstatus; +#line 782 + +#line 782 + lstatus = ncx_putn_uint_ulonglong(&xp, nput, value ,fillp); +#line 782 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 782 + { +#line 782 + /* not fatal to the loop */ +#line 782 + status = lstatus; +#line 782 + } +#line 782 + +#line 782 + (void) ncio_rel(ncp->nciop, offset, +#line 782 + RGN_MODIFIED); +#line 782 + +#line 782 + remaining -= extent; +#line 782 + if(remaining == 0) +#line 782 + break; /* normal loop exit */ +#line 782 + offset += (off_t)extent; +#line 782 + value += nput; +#line 782 + +#line 782 + } +#line 782 +#ifdef ERANGE_FILL +#line 782 + free(fillp); +#line 782 +#endif +#line 782 + +#line 782 + return status; +#line 782 +} +#line 782 + + +static int +#line 784 +putNCvx_longlong_schar(NC3_INFO* ncp, const NC_var *varp, +#line 784 + const size_t *start, size_t nelems, const schar *value) +#line 784 +{ +#line 784 + off_t offset = NC_varoffset(ncp, varp, start); +#line 784 + size_t remaining = varp->xsz * nelems; +#line 784 + int status = NC_NOERR; +#line 784 + void *xp; +#line 784 + void *fillp=NULL; +#line 784 + +#line 784 + NC_UNUSED(fillp); +#line 784 + +#line 784 + if(nelems == 0) +#line 784 + return NC_NOERR; +#line 784 + +#line 784 + assert(value != NULL); +#line 784 + +#line 784 +#ifdef ERANGE_FILL +#line 784 + fillp = malloc(varp->xsz); +#line 784 + status = NC3_inq_var_fill(varp, fillp); +#line 784 +#endif +#line 784 + +#line 784 + for(;;) +#line 784 + { +#line 784 + size_t extent = MIN(remaining, ncp->chunk); +#line 784 + size_t nput = ncx_howmany(varp->type, extent); +#line 784 + +#line 784 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 784 + RGN_WRITE, &xp); +#line 784 + if(lstatus != NC_NOERR) +#line 784 + return lstatus; +#line 784 + +#line 784 + lstatus = ncx_putn_longlong_schar(&xp, nput, value ,fillp); +#line 784 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 784 + { +#line 784 + /* not fatal to the loop */ +#line 784 + status = lstatus; +#line 784 + } +#line 784 + +#line 784 + (void) ncio_rel(ncp->nciop, offset, +#line 784 + RGN_MODIFIED); +#line 784 + +#line 784 + remaining -= extent; +#line 784 + if(remaining == 0) +#line 784 + break; /* normal loop exit */ +#line 784 + offset += (off_t)extent; +#line 784 + value += nput; +#line 784 + +#line 784 + } +#line 784 +#ifdef ERANGE_FILL +#line 784 + free(fillp); +#line 784 +#endif +#line 784 + +#line 784 + return status; +#line 784 +} +#line 784 + +static int +#line 785 +putNCvx_longlong_uchar(NC3_INFO* ncp, const NC_var *varp, +#line 785 + const size_t *start, size_t nelems, const uchar *value) +#line 785 +{ +#line 785 + off_t offset = NC_varoffset(ncp, varp, start); +#line 785 + size_t remaining = varp->xsz * nelems; +#line 785 + int status = NC_NOERR; +#line 785 + void *xp; +#line 785 + void *fillp=NULL; +#line 785 + +#line 785 + NC_UNUSED(fillp); +#line 785 + +#line 785 + if(nelems == 0) +#line 785 + return NC_NOERR; +#line 785 + +#line 785 + assert(value != NULL); +#line 785 + +#line 785 +#ifdef ERANGE_FILL +#line 785 + fillp = malloc(varp->xsz); +#line 785 + status = NC3_inq_var_fill(varp, fillp); +#line 785 +#endif +#line 785 + +#line 785 + for(;;) +#line 785 + { +#line 785 + size_t extent = MIN(remaining, ncp->chunk); +#line 785 + size_t nput = ncx_howmany(varp->type, extent); +#line 785 + +#line 785 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 785 + RGN_WRITE, &xp); +#line 785 + if(lstatus != NC_NOERR) +#line 785 + return lstatus; +#line 785 + +#line 785 + lstatus = ncx_putn_longlong_uchar(&xp, nput, value ,fillp); +#line 785 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 785 + { +#line 785 + /* not fatal to the loop */ +#line 785 + status = lstatus; +#line 785 + } +#line 785 + +#line 785 + (void) ncio_rel(ncp->nciop, offset, +#line 785 + RGN_MODIFIED); +#line 785 + +#line 785 + remaining -= extent; +#line 785 + if(remaining == 0) +#line 785 + break; /* normal loop exit */ +#line 785 + offset += (off_t)extent; +#line 785 + value += nput; +#line 785 + +#line 785 + } +#line 785 +#ifdef ERANGE_FILL +#line 785 + free(fillp); +#line 785 +#endif +#line 785 + +#line 785 + return status; +#line 785 +} +#line 785 + +static int +#line 786 +putNCvx_longlong_short(NC3_INFO* ncp, const NC_var *varp, +#line 786 + const size_t *start, size_t nelems, const short *value) +#line 786 +{ +#line 786 + off_t offset = NC_varoffset(ncp, varp, start); +#line 786 + size_t remaining = varp->xsz * nelems; +#line 786 + int status = NC_NOERR; +#line 786 + void *xp; +#line 786 + void *fillp=NULL; +#line 786 + +#line 786 + NC_UNUSED(fillp); +#line 786 + +#line 786 + if(nelems == 0) +#line 786 + return NC_NOERR; +#line 786 + +#line 786 + assert(value != NULL); +#line 786 + +#line 786 +#ifdef ERANGE_FILL +#line 786 + fillp = malloc(varp->xsz); +#line 786 + status = NC3_inq_var_fill(varp, fillp); +#line 786 +#endif +#line 786 + +#line 786 + for(;;) +#line 786 + { +#line 786 + size_t extent = MIN(remaining, ncp->chunk); +#line 786 + size_t nput = ncx_howmany(varp->type, extent); +#line 786 + +#line 786 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 786 + RGN_WRITE, &xp); +#line 786 + if(lstatus != NC_NOERR) +#line 786 + return lstatus; +#line 786 + +#line 786 + lstatus = ncx_putn_longlong_short(&xp, nput, value ,fillp); +#line 786 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 786 + { +#line 786 + /* not fatal to the loop */ +#line 786 + status = lstatus; +#line 786 + } +#line 786 + +#line 786 + (void) ncio_rel(ncp->nciop, offset, +#line 786 + RGN_MODIFIED); +#line 786 + +#line 786 + remaining -= extent; +#line 786 + if(remaining == 0) +#line 786 + break; /* normal loop exit */ +#line 786 + offset += (off_t)extent; +#line 786 + value += nput; +#line 786 + +#line 786 + } +#line 786 +#ifdef ERANGE_FILL +#line 786 + free(fillp); +#line 786 +#endif +#line 786 + +#line 786 + return status; +#line 786 +} +#line 786 + +static int +#line 787 +putNCvx_longlong_int(NC3_INFO* ncp, const NC_var *varp, +#line 787 + const size_t *start, size_t nelems, const int *value) +#line 787 +{ +#line 787 + off_t offset = NC_varoffset(ncp, varp, start); +#line 787 + size_t remaining = varp->xsz * nelems; +#line 787 + int status = NC_NOERR; +#line 787 + void *xp; +#line 787 + void *fillp=NULL; +#line 787 + +#line 787 + NC_UNUSED(fillp); +#line 787 + +#line 787 + if(nelems == 0) +#line 787 + return NC_NOERR; +#line 787 + +#line 787 + assert(value != NULL); +#line 787 + +#line 787 +#ifdef ERANGE_FILL +#line 787 + fillp = malloc(varp->xsz); +#line 787 + status = NC3_inq_var_fill(varp, fillp); +#line 787 +#endif +#line 787 + +#line 787 + for(;;) +#line 787 + { +#line 787 + size_t extent = MIN(remaining, ncp->chunk); +#line 787 + size_t nput = ncx_howmany(varp->type, extent); +#line 787 + +#line 787 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 787 + RGN_WRITE, &xp); +#line 787 + if(lstatus != NC_NOERR) +#line 787 + return lstatus; +#line 787 + +#line 787 + lstatus = ncx_putn_longlong_int(&xp, nput, value ,fillp); +#line 787 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 787 + { +#line 787 + /* not fatal to the loop */ +#line 787 + status = lstatus; +#line 787 + } +#line 787 + +#line 787 + (void) ncio_rel(ncp->nciop, offset, +#line 787 + RGN_MODIFIED); +#line 787 + +#line 787 + remaining -= extent; +#line 787 + if(remaining == 0) +#line 787 + break; /* normal loop exit */ +#line 787 + offset += (off_t)extent; +#line 787 + value += nput; +#line 787 + +#line 787 + } +#line 787 +#ifdef ERANGE_FILL +#line 787 + free(fillp); +#line 787 +#endif +#line 787 + +#line 787 + return status; +#line 787 +} +#line 787 + +static int +#line 788 +putNCvx_longlong_float(NC3_INFO* ncp, const NC_var *varp, +#line 788 + const size_t *start, size_t nelems, const float *value) +#line 788 +{ +#line 788 + off_t offset = NC_varoffset(ncp, varp, start); +#line 788 + size_t remaining = varp->xsz * nelems; +#line 788 + int status = NC_NOERR; +#line 788 + void *xp; +#line 788 + void *fillp=NULL; +#line 788 + +#line 788 + NC_UNUSED(fillp); +#line 788 + +#line 788 + if(nelems == 0) +#line 788 + return NC_NOERR; +#line 788 + +#line 788 + assert(value != NULL); +#line 788 + +#line 788 +#ifdef ERANGE_FILL +#line 788 + fillp = malloc(varp->xsz); +#line 788 + status = NC3_inq_var_fill(varp, fillp); +#line 788 +#endif +#line 788 + +#line 788 + for(;;) +#line 788 + { +#line 788 + size_t extent = MIN(remaining, ncp->chunk); +#line 788 + size_t nput = ncx_howmany(varp->type, extent); +#line 788 + +#line 788 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 788 + RGN_WRITE, &xp); +#line 788 + if(lstatus != NC_NOERR) +#line 788 + return lstatus; +#line 788 + +#line 788 + lstatus = ncx_putn_longlong_float(&xp, nput, value ,fillp); +#line 788 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 788 + { +#line 788 + /* not fatal to the loop */ +#line 788 + status = lstatus; +#line 788 + } +#line 788 + +#line 788 + (void) ncio_rel(ncp->nciop, offset, +#line 788 + RGN_MODIFIED); +#line 788 + +#line 788 + remaining -= extent; +#line 788 + if(remaining == 0) +#line 788 + break; /* normal loop exit */ +#line 788 + offset += (off_t)extent; +#line 788 + value += nput; +#line 788 + +#line 788 + } +#line 788 +#ifdef ERANGE_FILL +#line 788 + free(fillp); +#line 788 +#endif +#line 788 + +#line 788 + return status; +#line 788 +} +#line 788 + +static int +#line 789 +putNCvx_longlong_double(NC3_INFO* ncp, const NC_var *varp, +#line 789 + const size_t *start, size_t nelems, const double *value) +#line 789 +{ +#line 789 + off_t offset = NC_varoffset(ncp, varp, start); +#line 789 + size_t remaining = varp->xsz * nelems; +#line 789 + int status = NC_NOERR; +#line 789 + void *xp; +#line 789 + void *fillp=NULL; +#line 789 + +#line 789 + NC_UNUSED(fillp); +#line 789 + +#line 789 + if(nelems == 0) +#line 789 + return NC_NOERR; +#line 789 + +#line 789 + assert(value != NULL); +#line 789 + +#line 789 +#ifdef ERANGE_FILL +#line 789 + fillp = malloc(varp->xsz); +#line 789 + status = NC3_inq_var_fill(varp, fillp); +#line 789 +#endif +#line 789 + +#line 789 + for(;;) +#line 789 + { +#line 789 + size_t extent = MIN(remaining, ncp->chunk); +#line 789 + size_t nput = ncx_howmany(varp->type, extent); +#line 789 + +#line 789 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 789 + RGN_WRITE, &xp); +#line 789 + if(lstatus != NC_NOERR) +#line 789 + return lstatus; +#line 789 + +#line 789 + lstatus = ncx_putn_longlong_double(&xp, nput, value ,fillp); +#line 789 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 789 + { +#line 789 + /* not fatal to the loop */ +#line 789 + status = lstatus; +#line 789 + } +#line 789 + +#line 789 + (void) ncio_rel(ncp->nciop, offset, +#line 789 + RGN_MODIFIED); +#line 789 + +#line 789 + remaining -= extent; +#line 789 + if(remaining == 0) +#line 789 + break; /* normal loop exit */ +#line 789 + offset += (off_t)extent; +#line 789 + value += nput; +#line 789 + +#line 789 + } +#line 789 +#ifdef ERANGE_FILL +#line 789 + free(fillp); +#line 789 +#endif +#line 789 + +#line 789 + return status; +#line 789 +} +#line 789 + +static int +#line 790 +putNCvx_longlong_longlong(NC3_INFO* ncp, const NC_var *varp, +#line 790 + const size_t *start, size_t nelems, const longlong *value) +#line 790 +{ +#line 790 + off_t offset = NC_varoffset(ncp, varp, start); +#line 790 + size_t remaining = varp->xsz * nelems; +#line 790 + int status = NC_NOERR; +#line 790 + void *xp; +#line 790 + void *fillp=NULL; +#line 790 + +#line 790 + NC_UNUSED(fillp); +#line 790 + +#line 790 + if(nelems == 0) +#line 790 + return NC_NOERR; +#line 790 + +#line 790 + assert(value != NULL); +#line 790 + +#line 790 +#ifdef ERANGE_FILL +#line 790 + fillp = malloc(varp->xsz); +#line 790 + status = NC3_inq_var_fill(varp, fillp); +#line 790 +#endif +#line 790 + +#line 790 + for(;;) +#line 790 + { +#line 790 + size_t extent = MIN(remaining, ncp->chunk); +#line 790 + size_t nput = ncx_howmany(varp->type, extent); +#line 790 + +#line 790 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 790 + RGN_WRITE, &xp); +#line 790 + if(lstatus != NC_NOERR) +#line 790 + return lstatus; +#line 790 + +#line 790 + lstatus = ncx_putn_longlong_longlong(&xp, nput, value ,fillp); +#line 790 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 790 + { +#line 790 + /* not fatal to the loop */ +#line 790 + status = lstatus; +#line 790 + } +#line 790 + +#line 790 + (void) ncio_rel(ncp->nciop, offset, +#line 790 + RGN_MODIFIED); +#line 790 + +#line 790 + remaining -= extent; +#line 790 + if(remaining == 0) +#line 790 + break; /* normal loop exit */ +#line 790 + offset += (off_t)extent; +#line 790 + value += nput; +#line 790 + +#line 790 + } +#line 790 +#ifdef ERANGE_FILL +#line 790 + free(fillp); +#line 790 +#endif +#line 790 + +#line 790 + return status; +#line 790 +} +#line 790 + +static int +#line 791 +putNCvx_longlong_ushort(NC3_INFO* ncp, const NC_var *varp, +#line 791 + const size_t *start, size_t nelems, const ushort *value) +#line 791 +{ +#line 791 + off_t offset = NC_varoffset(ncp, varp, start); +#line 791 + size_t remaining = varp->xsz * nelems; +#line 791 + int status = NC_NOERR; +#line 791 + void *xp; +#line 791 + void *fillp=NULL; +#line 791 + +#line 791 + NC_UNUSED(fillp); +#line 791 + +#line 791 + if(nelems == 0) +#line 791 + return NC_NOERR; +#line 791 + +#line 791 + assert(value != NULL); +#line 791 + +#line 791 +#ifdef ERANGE_FILL +#line 791 + fillp = malloc(varp->xsz); +#line 791 + status = NC3_inq_var_fill(varp, fillp); +#line 791 +#endif +#line 791 + +#line 791 + for(;;) +#line 791 + { +#line 791 + size_t extent = MIN(remaining, ncp->chunk); +#line 791 + size_t nput = ncx_howmany(varp->type, extent); +#line 791 + +#line 791 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 791 + RGN_WRITE, &xp); +#line 791 + if(lstatus != NC_NOERR) +#line 791 + return lstatus; +#line 791 + +#line 791 + lstatus = ncx_putn_longlong_ushort(&xp, nput, value ,fillp); +#line 791 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 791 + { +#line 791 + /* not fatal to the loop */ +#line 791 + status = lstatus; +#line 791 + } +#line 791 + +#line 791 + (void) ncio_rel(ncp->nciop, offset, +#line 791 + RGN_MODIFIED); +#line 791 + +#line 791 + remaining -= extent; +#line 791 + if(remaining == 0) +#line 791 + break; /* normal loop exit */ +#line 791 + offset += (off_t)extent; +#line 791 + value += nput; +#line 791 + +#line 791 + } +#line 791 +#ifdef ERANGE_FILL +#line 791 + free(fillp); +#line 791 +#endif +#line 791 + +#line 791 + return status; +#line 791 +} +#line 791 + +static int +#line 792 +putNCvx_longlong_uint(NC3_INFO* ncp, const NC_var *varp, +#line 792 + const size_t *start, size_t nelems, const uint *value) +#line 792 +{ +#line 792 + off_t offset = NC_varoffset(ncp, varp, start); +#line 792 + size_t remaining = varp->xsz * nelems; +#line 792 + int status = NC_NOERR; +#line 792 + void *xp; +#line 792 + void *fillp=NULL; +#line 792 + +#line 792 + NC_UNUSED(fillp); +#line 792 + +#line 792 + if(nelems == 0) +#line 792 + return NC_NOERR; +#line 792 + +#line 792 + assert(value != NULL); +#line 792 + +#line 792 +#ifdef ERANGE_FILL +#line 792 + fillp = malloc(varp->xsz); +#line 792 + status = NC3_inq_var_fill(varp, fillp); +#line 792 +#endif +#line 792 + +#line 792 + for(;;) +#line 792 + { +#line 792 + size_t extent = MIN(remaining, ncp->chunk); +#line 792 + size_t nput = ncx_howmany(varp->type, extent); +#line 792 + +#line 792 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 792 + RGN_WRITE, &xp); +#line 792 + if(lstatus != NC_NOERR) +#line 792 + return lstatus; +#line 792 + +#line 792 + lstatus = ncx_putn_longlong_uint(&xp, nput, value ,fillp); +#line 792 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 792 + { +#line 792 + /* not fatal to the loop */ +#line 792 + status = lstatus; +#line 792 + } +#line 792 + +#line 792 + (void) ncio_rel(ncp->nciop, offset, +#line 792 + RGN_MODIFIED); +#line 792 + +#line 792 + remaining -= extent; +#line 792 + if(remaining == 0) +#line 792 + break; /* normal loop exit */ +#line 792 + offset += (off_t)extent; +#line 792 + value += nput; +#line 792 + +#line 792 + } +#line 792 +#ifdef ERANGE_FILL +#line 792 + free(fillp); +#line 792 +#endif +#line 792 + +#line 792 + return status; +#line 792 +} +#line 792 + +static int +#line 793 +putNCvx_longlong_ulonglong(NC3_INFO* ncp, const NC_var *varp, +#line 793 + const size_t *start, size_t nelems, const ulonglong *value) +#line 793 +{ +#line 793 + off_t offset = NC_varoffset(ncp, varp, start); +#line 793 + size_t remaining = varp->xsz * nelems; +#line 793 + int status = NC_NOERR; +#line 793 + void *xp; +#line 793 + void *fillp=NULL; +#line 793 + +#line 793 + NC_UNUSED(fillp); +#line 793 + +#line 793 + if(nelems == 0) +#line 793 + return NC_NOERR; +#line 793 + +#line 793 + assert(value != NULL); +#line 793 + +#line 793 +#ifdef ERANGE_FILL +#line 793 + fillp = malloc(varp->xsz); +#line 793 + status = NC3_inq_var_fill(varp, fillp); +#line 793 +#endif +#line 793 + +#line 793 + for(;;) +#line 793 + { +#line 793 + size_t extent = MIN(remaining, ncp->chunk); +#line 793 + size_t nput = ncx_howmany(varp->type, extent); +#line 793 + +#line 793 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 793 + RGN_WRITE, &xp); +#line 793 + if(lstatus != NC_NOERR) +#line 793 + return lstatus; +#line 793 + +#line 793 + lstatus = ncx_putn_longlong_ulonglong(&xp, nput, value ,fillp); +#line 793 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 793 + { +#line 793 + /* not fatal to the loop */ +#line 793 + status = lstatus; +#line 793 + } +#line 793 + +#line 793 + (void) ncio_rel(ncp->nciop, offset, +#line 793 + RGN_MODIFIED); +#line 793 + +#line 793 + remaining -= extent; +#line 793 + if(remaining == 0) +#line 793 + break; /* normal loop exit */ +#line 793 + offset += (off_t)extent; +#line 793 + value += nput; +#line 793 + +#line 793 + } +#line 793 +#ifdef ERANGE_FILL +#line 793 + free(fillp); +#line 793 +#endif +#line 793 + +#line 793 + return status; +#line 793 +} +#line 793 + + +static int +#line 795 +putNCvx_ulonglong_schar(NC3_INFO* ncp, const NC_var *varp, +#line 795 + const size_t *start, size_t nelems, const schar *value) +#line 795 +{ +#line 795 + off_t offset = NC_varoffset(ncp, varp, start); +#line 795 + size_t remaining = varp->xsz * nelems; +#line 795 + int status = NC_NOERR; +#line 795 + void *xp; +#line 795 + void *fillp=NULL; +#line 795 + +#line 795 + NC_UNUSED(fillp); +#line 795 + +#line 795 + if(nelems == 0) +#line 795 + return NC_NOERR; +#line 795 + +#line 795 + assert(value != NULL); +#line 795 + +#line 795 +#ifdef ERANGE_FILL +#line 795 + fillp = malloc(varp->xsz); +#line 795 + status = NC3_inq_var_fill(varp, fillp); +#line 795 +#endif +#line 795 + +#line 795 + for(;;) +#line 795 + { +#line 795 + size_t extent = MIN(remaining, ncp->chunk); +#line 795 + size_t nput = ncx_howmany(varp->type, extent); +#line 795 + +#line 795 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 795 + RGN_WRITE, &xp); +#line 795 + if(lstatus != NC_NOERR) +#line 795 + return lstatus; +#line 795 + +#line 795 + lstatus = ncx_putn_ulonglong_schar(&xp, nput, value ,fillp); +#line 795 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 795 + { +#line 795 + /* not fatal to the loop */ +#line 795 + status = lstatus; +#line 795 + } +#line 795 + +#line 795 + (void) ncio_rel(ncp->nciop, offset, +#line 795 + RGN_MODIFIED); +#line 795 + +#line 795 + remaining -= extent; +#line 795 + if(remaining == 0) +#line 795 + break; /* normal loop exit */ +#line 795 + offset += (off_t)extent; +#line 795 + value += nput; +#line 795 + +#line 795 + } +#line 795 +#ifdef ERANGE_FILL +#line 795 + free(fillp); +#line 795 +#endif +#line 795 + +#line 795 + return status; +#line 795 +} +#line 795 + +static int +#line 796 +putNCvx_ulonglong_uchar(NC3_INFO* ncp, const NC_var *varp, +#line 796 + const size_t *start, size_t nelems, const uchar *value) +#line 796 +{ +#line 796 + off_t offset = NC_varoffset(ncp, varp, start); +#line 796 + size_t remaining = varp->xsz * nelems; +#line 796 + int status = NC_NOERR; +#line 796 + void *xp; +#line 796 + void *fillp=NULL; +#line 796 + +#line 796 + NC_UNUSED(fillp); +#line 796 + +#line 796 + if(nelems == 0) +#line 796 + return NC_NOERR; +#line 796 + +#line 796 + assert(value != NULL); +#line 796 + +#line 796 +#ifdef ERANGE_FILL +#line 796 + fillp = malloc(varp->xsz); +#line 796 + status = NC3_inq_var_fill(varp, fillp); +#line 796 +#endif +#line 796 + +#line 796 + for(;;) +#line 796 + { +#line 796 + size_t extent = MIN(remaining, ncp->chunk); +#line 796 + size_t nput = ncx_howmany(varp->type, extent); +#line 796 + +#line 796 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 796 + RGN_WRITE, &xp); +#line 796 + if(lstatus != NC_NOERR) +#line 796 + return lstatus; +#line 796 + +#line 796 + lstatus = ncx_putn_ulonglong_uchar(&xp, nput, value ,fillp); +#line 796 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 796 + { +#line 796 + /* not fatal to the loop */ +#line 796 + status = lstatus; +#line 796 + } +#line 796 + +#line 796 + (void) ncio_rel(ncp->nciop, offset, +#line 796 + RGN_MODIFIED); +#line 796 + +#line 796 + remaining -= extent; +#line 796 + if(remaining == 0) +#line 796 + break; /* normal loop exit */ +#line 796 + offset += (off_t)extent; +#line 796 + value += nput; +#line 796 + +#line 796 + } +#line 796 +#ifdef ERANGE_FILL +#line 796 + free(fillp); +#line 796 +#endif +#line 796 + +#line 796 + return status; +#line 796 +} +#line 796 + +static int +#line 797 +putNCvx_ulonglong_short(NC3_INFO* ncp, const NC_var *varp, +#line 797 + const size_t *start, size_t nelems, const short *value) +#line 797 +{ +#line 797 + off_t offset = NC_varoffset(ncp, varp, start); +#line 797 + size_t remaining = varp->xsz * nelems; +#line 797 + int status = NC_NOERR; +#line 797 + void *xp; +#line 797 + void *fillp=NULL; +#line 797 + +#line 797 + NC_UNUSED(fillp); +#line 797 + +#line 797 + if(nelems == 0) +#line 797 + return NC_NOERR; +#line 797 + +#line 797 + assert(value != NULL); +#line 797 + +#line 797 +#ifdef ERANGE_FILL +#line 797 + fillp = malloc(varp->xsz); +#line 797 + status = NC3_inq_var_fill(varp, fillp); +#line 797 +#endif +#line 797 + +#line 797 + for(;;) +#line 797 + { +#line 797 + size_t extent = MIN(remaining, ncp->chunk); +#line 797 + size_t nput = ncx_howmany(varp->type, extent); +#line 797 + +#line 797 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 797 + RGN_WRITE, &xp); +#line 797 + if(lstatus != NC_NOERR) +#line 797 + return lstatus; +#line 797 + +#line 797 + lstatus = ncx_putn_ulonglong_short(&xp, nput, value ,fillp); +#line 797 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 797 + { +#line 797 + /* not fatal to the loop */ +#line 797 + status = lstatus; +#line 797 + } +#line 797 + +#line 797 + (void) ncio_rel(ncp->nciop, offset, +#line 797 + RGN_MODIFIED); +#line 797 + +#line 797 + remaining -= extent; +#line 797 + if(remaining == 0) +#line 797 + break; /* normal loop exit */ +#line 797 + offset += (off_t)extent; +#line 797 + value += nput; +#line 797 + +#line 797 + } +#line 797 +#ifdef ERANGE_FILL +#line 797 + free(fillp); +#line 797 +#endif +#line 797 + +#line 797 + return status; +#line 797 +} +#line 797 + +static int +#line 798 +putNCvx_ulonglong_int(NC3_INFO* ncp, const NC_var *varp, +#line 798 + const size_t *start, size_t nelems, const int *value) +#line 798 +{ +#line 798 + off_t offset = NC_varoffset(ncp, varp, start); +#line 798 + size_t remaining = varp->xsz * nelems; +#line 798 + int status = NC_NOERR; +#line 798 + void *xp; +#line 798 + void *fillp=NULL; +#line 798 + +#line 798 + NC_UNUSED(fillp); +#line 798 + +#line 798 + if(nelems == 0) +#line 798 + return NC_NOERR; +#line 798 + +#line 798 + assert(value != NULL); +#line 798 + +#line 798 +#ifdef ERANGE_FILL +#line 798 + fillp = malloc(varp->xsz); +#line 798 + status = NC3_inq_var_fill(varp, fillp); +#line 798 +#endif +#line 798 + +#line 798 + for(;;) +#line 798 + { +#line 798 + size_t extent = MIN(remaining, ncp->chunk); +#line 798 + size_t nput = ncx_howmany(varp->type, extent); +#line 798 + +#line 798 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 798 + RGN_WRITE, &xp); +#line 798 + if(lstatus != NC_NOERR) +#line 798 + return lstatus; +#line 798 + +#line 798 + lstatus = ncx_putn_ulonglong_int(&xp, nput, value ,fillp); +#line 798 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 798 + { +#line 798 + /* not fatal to the loop */ +#line 798 + status = lstatus; +#line 798 + } +#line 798 + +#line 798 + (void) ncio_rel(ncp->nciop, offset, +#line 798 + RGN_MODIFIED); +#line 798 + +#line 798 + remaining -= extent; +#line 798 + if(remaining == 0) +#line 798 + break; /* normal loop exit */ +#line 798 + offset += (off_t)extent; +#line 798 + value += nput; +#line 798 + +#line 798 + } +#line 798 +#ifdef ERANGE_FILL +#line 798 + free(fillp); +#line 798 +#endif +#line 798 + +#line 798 + return status; +#line 798 +} +#line 798 + +static int +#line 799 +putNCvx_ulonglong_float(NC3_INFO* ncp, const NC_var *varp, +#line 799 + const size_t *start, size_t nelems, const float *value) +#line 799 +{ +#line 799 + off_t offset = NC_varoffset(ncp, varp, start); +#line 799 + size_t remaining = varp->xsz * nelems; +#line 799 + int status = NC_NOERR; +#line 799 + void *xp; +#line 799 + void *fillp=NULL; +#line 799 + +#line 799 + NC_UNUSED(fillp); +#line 799 + +#line 799 + if(nelems == 0) +#line 799 + return NC_NOERR; +#line 799 + +#line 799 + assert(value != NULL); +#line 799 + +#line 799 +#ifdef ERANGE_FILL +#line 799 + fillp = malloc(varp->xsz); +#line 799 + status = NC3_inq_var_fill(varp, fillp); +#line 799 +#endif +#line 799 + +#line 799 + for(;;) +#line 799 + { +#line 799 + size_t extent = MIN(remaining, ncp->chunk); +#line 799 + size_t nput = ncx_howmany(varp->type, extent); +#line 799 + +#line 799 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 799 + RGN_WRITE, &xp); +#line 799 + if(lstatus != NC_NOERR) +#line 799 + return lstatus; +#line 799 + +#line 799 + lstatus = ncx_putn_ulonglong_float(&xp, nput, value ,fillp); +#line 799 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 799 + { +#line 799 + /* not fatal to the loop */ +#line 799 + status = lstatus; +#line 799 + } +#line 799 + +#line 799 + (void) ncio_rel(ncp->nciop, offset, +#line 799 + RGN_MODIFIED); +#line 799 + +#line 799 + remaining -= extent; +#line 799 + if(remaining == 0) +#line 799 + break; /* normal loop exit */ +#line 799 + offset += (off_t)extent; +#line 799 + value += nput; +#line 799 + +#line 799 + } +#line 799 +#ifdef ERANGE_FILL +#line 799 + free(fillp); +#line 799 +#endif +#line 799 + +#line 799 + return status; +#line 799 +} +#line 799 + +static int +#line 800 +putNCvx_ulonglong_double(NC3_INFO* ncp, const NC_var *varp, +#line 800 + const size_t *start, size_t nelems, const double *value) +#line 800 +{ +#line 800 + off_t offset = NC_varoffset(ncp, varp, start); +#line 800 + size_t remaining = varp->xsz * nelems; +#line 800 + int status = NC_NOERR; +#line 800 + void *xp; +#line 800 + void *fillp=NULL; +#line 800 + +#line 800 + NC_UNUSED(fillp); +#line 800 + +#line 800 + if(nelems == 0) +#line 800 + return NC_NOERR; +#line 800 + +#line 800 + assert(value != NULL); +#line 800 + +#line 800 +#ifdef ERANGE_FILL +#line 800 + fillp = malloc(varp->xsz); +#line 800 + status = NC3_inq_var_fill(varp, fillp); +#line 800 +#endif +#line 800 + +#line 800 + for(;;) +#line 800 + { +#line 800 + size_t extent = MIN(remaining, ncp->chunk); +#line 800 + size_t nput = ncx_howmany(varp->type, extent); +#line 800 + +#line 800 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 800 + RGN_WRITE, &xp); +#line 800 + if(lstatus != NC_NOERR) +#line 800 + return lstatus; +#line 800 + +#line 800 + lstatus = ncx_putn_ulonglong_double(&xp, nput, value ,fillp); +#line 800 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 800 + { +#line 800 + /* not fatal to the loop */ +#line 800 + status = lstatus; +#line 800 + } +#line 800 + +#line 800 + (void) ncio_rel(ncp->nciop, offset, +#line 800 + RGN_MODIFIED); +#line 800 + +#line 800 + remaining -= extent; +#line 800 + if(remaining == 0) +#line 800 + break; /* normal loop exit */ +#line 800 + offset += (off_t)extent; +#line 800 + value += nput; +#line 800 + +#line 800 + } +#line 800 +#ifdef ERANGE_FILL +#line 800 + free(fillp); +#line 800 +#endif +#line 800 + +#line 800 + return status; +#line 800 +} +#line 800 + +static int +#line 801 +putNCvx_ulonglong_longlong(NC3_INFO* ncp, const NC_var *varp, +#line 801 + const size_t *start, size_t nelems, const longlong *value) +#line 801 +{ +#line 801 + off_t offset = NC_varoffset(ncp, varp, start); +#line 801 + size_t remaining = varp->xsz * nelems; +#line 801 + int status = NC_NOERR; +#line 801 + void *xp; +#line 801 + void *fillp=NULL; +#line 801 + +#line 801 + NC_UNUSED(fillp); +#line 801 + +#line 801 + if(nelems == 0) +#line 801 + return NC_NOERR; +#line 801 + +#line 801 + assert(value != NULL); +#line 801 + +#line 801 +#ifdef ERANGE_FILL +#line 801 + fillp = malloc(varp->xsz); +#line 801 + status = NC3_inq_var_fill(varp, fillp); +#line 801 +#endif +#line 801 + +#line 801 + for(;;) +#line 801 + { +#line 801 + size_t extent = MIN(remaining, ncp->chunk); +#line 801 + size_t nput = ncx_howmany(varp->type, extent); +#line 801 + +#line 801 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 801 + RGN_WRITE, &xp); +#line 801 + if(lstatus != NC_NOERR) +#line 801 + return lstatus; +#line 801 + +#line 801 + lstatus = ncx_putn_ulonglong_longlong(&xp, nput, value ,fillp); +#line 801 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 801 + { +#line 801 + /* not fatal to the loop */ +#line 801 + status = lstatus; +#line 801 + } +#line 801 + +#line 801 + (void) ncio_rel(ncp->nciop, offset, +#line 801 + RGN_MODIFIED); +#line 801 + +#line 801 + remaining -= extent; +#line 801 + if(remaining == 0) +#line 801 + break; /* normal loop exit */ +#line 801 + offset += (off_t)extent; +#line 801 + value += nput; +#line 801 + +#line 801 + } +#line 801 +#ifdef ERANGE_FILL +#line 801 + free(fillp); +#line 801 +#endif +#line 801 + +#line 801 + return status; +#line 801 +} +#line 801 + +static int +#line 802 +putNCvx_ulonglong_ushort(NC3_INFO* ncp, const NC_var *varp, +#line 802 + const size_t *start, size_t nelems, const ushort *value) +#line 802 +{ +#line 802 + off_t offset = NC_varoffset(ncp, varp, start); +#line 802 + size_t remaining = varp->xsz * nelems; +#line 802 + int status = NC_NOERR; +#line 802 + void *xp; +#line 802 + void *fillp=NULL; +#line 802 + +#line 802 + NC_UNUSED(fillp); +#line 802 + +#line 802 + if(nelems == 0) +#line 802 + return NC_NOERR; +#line 802 + +#line 802 + assert(value != NULL); +#line 802 + +#line 802 +#ifdef ERANGE_FILL +#line 802 + fillp = malloc(varp->xsz); +#line 802 + status = NC3_inq_var_fill(varp, fillp); +#line 802 +#endif +#line 802 + +#line 802 + for(;;) +#line 802 + { +#line 802 + size_t extent = MIN(remaining, ncp->chunk); +#line 802 + size_t nput = ncx_howmany(varp->type, extent); +#line 802 + +#line 802 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 802 + RGN_WRITE, &xp); +#line 802 + if(lstatus != NC_NOERR) +#line 802 + return lstatus; +#line 802 + +#line 802 + lstatus = ncx_putn_ulonglong_ushort(&xp, nput, value ,fillp); +#line 802 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 802 + { +#line 802 + /* not fatal to the loop */ +#line 802 + status = lstatus; +#line 802 + } +#line 802 + +#line 802 + (void) ncio_rel(ncp->nciop, offset, +#line 802 + RGN_MODIFIED); +#line 802 + +#line 802 + remaining -= extent; +#line 802 + if(remaining == 0) +#line 802 + break; /* normal loop exit */ +#line 802 + offset += (off_t)extent; +#line 802 + value += nput; +#line 802 + +#line 802 + } +#line 802 +#ifdef ERANGE_FILL +#line 802 + free(fillp); +#line 802 +#endif +#line 802 + +#line 802 + return status; +#line 802 +} +#line 802 + +static int +#line 803 +putNCvx_ulonglong_uint(NC3_INFO* ncp, const NC_var *varp, +#line 803 + const size_t *start, size_t nelems, const uint *value) +#line 803 +{ +#line 803 + off_t offset = NC_varoffset(ncp, varp, start); +#line 803 + size_t remaining = varp->xsz * nelems; +#line 803 + int status = NC_NOERR; +#line 803 + void *xp; +#line 803 + void *fillp=NULL; +#line 803 + +#line 803 + NC_UNUSED(fillp); +#line 803 + +#line 803 + if(nelems == 0) +#line 803 + return NC_NOERR; +#line 803 + +#line 803 + assert(value != NULL); +#line 803 + +#line 803 +#ifdef ERANGE_FILL +#line 803 + fillp = malloc(varp->xsz); +#line 803 + status = NC3_inq_var_fill(varp, fillp); +#line 803 +#endif +#line 803 + +#line 803 + for(;;) +#line 803 + { +#line 803 + size_t extent = MIN(remaining, ncp->chunk); +#line 803 + size_t nput = ncx_howmany(varp->type, extent); +#line 803 + +#line 803 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 803 + RGN_WRITE, &xp); +#line 803 + if(lstatus != NC_NOERR) +#line 803 + return lstatus; +#line 803 + +#line 803 + lstatus = ncx_putn_ulonglong_uint(&xp, nput, value ,fillp); +#line 803 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 803 + { +#line 803 + /* not fatal to the loop */ +#line 803 + status = lstatus; +#line 803 + } +#line 803 + +#line 803 + (void) ncio_rel(ncp->nciop, offset, +#line 803 + RGN_MODIFIED); +#line 803 + +#line 803 + remaining -= extent; +#line 803 + if(remaining == 0) +#line 803 + break; /* normal loop exit */ +#line 803 + offset += (off_t)extent; +#line 803 + value += nput; +#line 803 + +#line 803 + } +#line 803 +#ifdef ERANGE_FILL +#line 803 + free(fillp); +#line 803 +#endif +#line 803 + +#line 803 + return status; +#line 803 +} +#line 803 + +static int +#line 804 +putNCvx_ulonglong_ulonglong(NC3_INFO* ncp, const NC_var *varp, +#line 804 + const size_t *start, size_t nelems, const ulonglong *value) +#line 804 +{ +#line 804 + off_t offset = NC_varoffset(ncp, varp, start); +#line 804 + size_t remaining = varp->xsz * nelems; +#line 804 + int status = NC_NOERR; +#line 804 + void *xp; +#line 804 + void *fillp=NULL; +#line 804 + +#line 804 + NC_UNUSED(fillp); +#line 804 + +#line 804 + if(nelems == 0) +#line 804 + return NC_NOERR; +#line 804 + +#line 804 + assert(value != NULL); +#line 804 + +#line 804 +#ifdef ERANGE_FILL +#line 804 + fillp = malloc(varp->xsz); +#line 804 + status = NC3_inq_var_fill(varp, fillp); +#line 804 +#endif +#line 804 + +#line 804 + for(;;) +#line 804 + { +#line 804 + size_t extent = MIN(remaining, ncp->chunk); +#line 804 + size_t nput = ncx_howmany(varp->type, extent); +#line 804 + +#line 804 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 804 + RGN_WRITE, &xp); +#line 804 + if(lstatus != NC_NOERR) +#line 804 + return lstatus; +#line 804 + +#line 804 + lstatus = ncx_putn_ulonglong_ulonglong(&xp, nput, value ,fillp); +#line 804 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 804 + { +#line 804 + /* not fatal to the loop */ +#line 804 + status = lstatus; +#line 804 + } +#line 804 + +#line 804 + (void) ncio_rel(ncp->nciop, offset, +#line 804 + RGN_MODIFIED); +#line 804 + +#line 804 + remaining -= extent; +#line 804 + if(remaining == 0) +#line 804 + break; /* normal loop exit */ +#line 804 + offset += (off_t)extent; +#line 804 + value += nput; +#line 804 + +#line 804 + } +#line 804 +#ifdef ERANGE_FILL +#line 804 + free(fillp); +#line 804 +#endif +#line 804 + +#line 804 + return status; +#line 804 +} +#line 804 + + +#line 851 + +#if 0 /*unused*/ +static int +#line 853 +getNCvx_char_char(const NC3_INFO* ncp, const NC_var *varp, +#line 853 + const size_t *start, size_t nelems, char *value) +#line 853 +{ +#line 853 + off_t offset = NC_varoffset(ncp, varp, start); +#line 853 + size_t remaining = varp->xsz * nelems; +#line 853 + int status = NC_NOERR; +#line 853 + const void *xp; +#line 853 + +#line 853 + if(nelems == 0) +#line 853 + return NC_NOERR; +#line 853 + +#line 853 + assert(value != NULL); +#line 853 + +#line 853 + for(;;) +#line 853 + { +#line 853 + size_t extent = MIN(remaining, ncp->chunk); +#line 853 + size_t nget = ncx_howmany(varp->type, extent); +#line 853 + +#line 853 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 853 + 0, (void **)&xp); /* cast away const */ +#line 853 + if(lstatus != NC_NOERR) +#line 853 + return lstatus; +#line 853 + +#line 853 + lstatus = ncx_getn_char_char(&xp, nget, value); +#line 853 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 853 + status = lstatus; +#line 853 + +#line 853 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 853 + +#line 853 + remaining -= extent; +#line 853 + if(remaining == 0) +#line 853 + break; /* normal loop exit */ +#line 853 + offset += (off_t)extent; +#line 853 + value += nget; +#line 853 + } +#line 853 + +#line 853 + return status; +#line 853 +} +#line 853 + +#endif + +static int +#line 856 +getNCvx_schar_schar(const NC3_INFO* ncp, const NC_var *varp, +#line 856 + const size_t *start, size_t nelems, schar *value) +#line 856 +{ +#line 856 + off_t offset = NC_varoffset(ncp, varp, start); +#line 856 + size_t remaining = varp->xsz * nelems; +#line 856 + int status = NC_NOERR; +#line 856 + const void *xp; +#line 856 + +#line 856 + if(nelems == 0) +#line 856 + return NC_NOERR; +#line 856 + +#line 856 + assert(value != NULL); +#line 856 + +#line 856 + for(;;) +#line 856 + { +#line 856 + size_t extent = MIN(remaining, ncp->chunk); +#line 856 + size_t nget = ncx_howmany(varp->type, extent); +#line 856 + +#line 856 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 856 + 0, (void **)&xp); /* cast away const */ +#line 856 + if(lstatus != NC_NOERR) +#line 856 + return lstatus; +#line 856 + +#line 856 + lstatus = ncx_getn_schar_schar(&xp, nget, value); +#line 856 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 856 + status = lstatus; +#line 856 + +#line 856 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 856 + +#line 856 + remaining -= extent; +#line 856 + if(remaining == 0) +#line 856 + break; /* normal loop exit */ +#line 856 + offset += (off_t)extent; +#line 856 + value += nget; +#line 856 + } +#line 856 + +#line 856 + return status; +#line 856 +} +#line 856 + +static int +#line 857 +getNCvx_schar_short(const NC3_INFO* ncp, const NC_var *varp, +#line 857 + const size_t *start, size_t nelems, short *value) +#line 857 +{ +#line 857 + off_t offset = NC_varoffset(ncp, varp, start); +#line 857 + size_t remaining = varp->xsz * nelems; +#line 857 + int status = NC_NOERR; +#line 857 + const void *xp; +#line 857 + +#line 857 + if(nelems == 0) +#line 857 + return NC_NOERR; +#line 857 + +#line 857 + assert(value != NULL); +#line 857 + +#line 857 + for(;;) +#line 857 + { +#line 857 + size_t extent = MIN(remaining, ncp->chunk); +#line 857 + size_t nget = ncx_howmany(varp->type, extent); +#line 857 + +#line 857 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 857 + 0, (void **)&xp); /* cast away const */ +#line 857 + if(lstatus != NC_NOERR) +#line 857 + return lstatus; +#line 857 + +#line 857 + lstatus = ncx_getn_schar_short(&xp, nget, value); +#line 857 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 857 + status = lstatus; +#line 857 + +#line 857 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 857 + +#line 857 + remaining -= extent; +#line 857 + if(remaining == 0) +#line 857 + break; /* normal loop exit */ +#line 857 + offset += (off_t)extent; +#line 857 + value += nget; +#line 857 + } +#line 857 + +#line 857 + return status; +#line 857 +} +#line 857 + +static int +#line 858 +getNCvx_schar_int(const NC3_INFO* ncp, const NC_var *varp, +#line 858 + const size_t *start, size_t nelems, int *value) +#line 858 +{ +#line 858 + off_t offset = NC_varoffset(ncp, varp, start); +#line 858 + size_t remaining = varp->xsz * nelems; +#line 858 + int status = NC_NOERR; +#line 858 + const void *xp; +#line 858 + +#line 858 + if(nelems == 0) +#line 858 + return NC_NOERR; +#line 858 + +#line 858 + assert(value != NULL); +#line 858 + +#line 858 + for(;;) +#line 858 + { +#line 858 + size_t extent = MIN(remaining, ncp->chunk); +#line 858 + size_t nget = ncx_howmany(varp->type, extent); +#line 858 + +#line 858 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 858 + 0, (void **)&xp); /* cast away const */ +#line 858 + if(lstatus != NC_NOERR) +#line 858 + return lstatus; +#line 858 + +#line 858 + lstatus = ncx_getn_schar_int(&xp, nget, value); +#line 858 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 858 + status = lstatus; +#line 858 + +#line 858 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 858 + +#line 858 + remaining -= extent; +#line 858 + if(remaining == 0) +#line 858 + break; /* normal loop exit */ +#line 858 + offset += (off_t)extent; +#line 858 + value += nget; +#line 858 + } +#line 858 + +#line 858 + return status; +#line 858 +} +#line 858 + +static int +#line 859 +getNCvx_schar_float(const NC3_INFO* ncp, const NC_var *varp, +#line 859 + const size_t *start, size_t nelems, float *value) +#line 859 +{ +#line 859 + off_t offset = NC_varoffset(ncp, varp, start); +#line 859 + size_t remaining = varp->xsz * nelems; +#line 859 + int status = NC_NOERR; +#line 859 + const void *xp; +#line 859 + +#line 859 + if(nelems == 0) +#line 859 + return NC_NOERR; +#line 859 + +#line 859 + assert(value != NULL); +#line 859 + +#line 859 + for(;;) +#line 859 + { +#line 859 + size_t extent = MIN(remaining, ncp->chunk); +#line 859 + size_t nget = ncx_howmany(varp->type, extent); +#line 859 + +#line 859 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 859 + 0, (void **)&xp); /* cast away const */ +#line 859 + if(lstatus != NC_NOERR) +#line 859 + return lstatus; +#line 859 + +#line 859 + lstatus = ncx_getn_schar_float(&xp, nget, value); +#line 859 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 859 + status = lstatus; +#line 859 + +#line 859 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 859 + +#line 859 + remaining -= extent; +#line 859 + if(remaining == 0) +#line 859 + break; /* normal loop exit */ +#line 859 + offset += (off_t)extent; +#line 859 + value += nget; +#line 859 + } +#line 859 + +#line 859 + return status; +#line 859 +} +#line 859 + +static int +#line 860 +getNCvx_schar_double(const NC3_INFO* ncp, const NC_var *varp, +#line 860 + const size_t *start, size_t nelems, double *value) +#line 860 +{ +#line 860 + off_t offset = NC_varoffset(ncp, varp, start); +#line 860 + size_t remaining = varp->xsz * nelems; +#line 860 + int status = NC_NOERR; +#line 860 + const void *xp; +#line 860 + +#line 860 + if(nelems == 0) +#line 860 + return NC_NOERR; +#line 860 + +#line 860 + assert(value != NULL); +#line 860 + +#line 860 + for(;;) +#line 860 + { +#line 860 + size_t extent = MIN(remaining, ncp->chunk); +#line 860 + size_t nget = ncx_howmany(varp->type, extent); +#line 860 + +#line 860 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 860 + 0, (void **)&xp); /* cast away const */ +#line 860 + if(lstatus != NC_NOERR) +#line 860 + return lstatus; +#line 860 + +#line 860 + lstatus = ncx_getn_schar_double(&xp, nget, value); +#line 860 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 860 + status = lstatus; +#line 860 + +#line 860 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 860 + +#line 860 + remaining -= extent; +#line 860 + if(remaining == 0) +#line 860 + break; /* normal loop exit */ +#line 860 + offset += (off_t)extent; +#line 860 + value += nget; +#line 860 + } +#line 860 + +#line 860 + return status; +#line 860 +} +#line 860 + +static int +#line 861 +getNCvx_schar_longlong(const NC3_INFO* ncp, const NC_var *varp, +#line 861 + const size_t *start, size_t nelems, longlong *value) +#line 861 +{ +#line 861 + off_t offset = NC_varoffset(ncp, varp, start); +#line 861 + size_t remaining = varp->xsz * nelems; +#line 861 + int status = NC_NOERR; +#line 861 + const void *xp; +#line 861 + +#line 861 + if(nelems == 0) +#line 861 + return NC_NOERR; +#line 861 + +#line 861 + assert(value != NULL); +#line 861 + +#line 861 + for(;;) +#line 861 + { +#line 861 + size_t extent = MIN(remaining, ncp->chunk); +#line 861 + size_t nget = ncx_howmany(varp->type, extent); +#line 861 + +#line 861 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 861 + 0, (void **)&xp); /* cast away const */ +#line 861 + if(lstatus != NC_NOERR) +#line 861 + return lstatus; +#line 861 + +#line 861 + lstatus = ncx_getn_schar_longlong(&xp, nget, value); +#line 861 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 861 + status = lstatus; +#line 861 + +#line 861 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 861 + +#line 861 + remaining -= extent; +#line 861 + if(remaining == 0) +#line 861 + break; /* normal loop exit */ +#line 861 + offset += (off_t)extent; +#line 861 + value += nget; +#line 861 + } +#line 861 + +#line 861 + return status; +#line 861 +} +#line 861 + +static int +#line 862 +getNCvx_schar_uint(const NC3_INFO* ncp, const NC_var *varp, +#line 862 + const size_t *start, size_t nelems, uint *value) +#line 862 +{ +#line 862 + off_t offset = NC_varoffset(ncp, varp, start); +#line 862 + size_t remaining = varp->xsz * nelems; +#line 862 + int status = NC_NOERR; +#line 862 + const void *xp; +#line 862 + +#line 862 + if(nelems == 0) +#line 862 + return NC_NOERR; +#line 862 + +#line 862 + assert(value != NULL); +#line 862 + +#line 862 + for(;;) +#line 862 + { +#line 862 + size_t extent = MIN(remaining, ncp->chunk); +#line 862 + size_t nget = ncx_howmany(varp->type, extent); +#line 862 + +#line 862 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 862 + 0, (void **)&xp); /* cast away const */ +#line 862 + if(lstatus != NC_NOERR) +#line 862 + return lstatus; +#line 862 + +#line 862 + lstatus = ncx_getn_schar_uint(&xp, nget, value); +#line 862 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 862 + status = lstatus; +#line 862 + +#line 862 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 862 + +#line 862 + remaining -= extent; +#line 862 + if(remaining == 0) +#line 862 + break; /* normal loop exit */ +#line 862 + offset += (off_t)extent; +#line 862 + value += nget; +#line 862 + } +#line 862 + +#line 862 + return status; +#line 862 +} +#line 862 + +static int +#line 863 +getNCvx_schar_ulonglong(const NC3_INFO* ncp, const NC_var *varp, +#line 863 + const size_t *start, size_t nelems, ulonglong *value) +#line 863 +{ +#line 863 + off_t offset = NC_varoffset(ncp, varp, start); +#line 863 + size_t remaining = varp->xsz * nelems; +#line 863 + int status = NC_NOERR; +#line 863 + const void *xp; +#line 863 + +#line 863 + if(nelems == 0) +#line 863 + return NC_NOERR; +#line 863 + +#line 863 + assert(value != NULL); +#line 863 + +#line 863 + for(;;) +#line 863 + { +#line 863 + size_t extent = MIN(remaining, ncp->chunk); +#line 863 + size_t nget = ncx_howmany(varp->type, extent); +#line 863 + +#line 863 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 863 + 0, (void **)&xp); /* cast away const */ +#line 863 + if(lstatus != NC_NOERR) +#line 863 + return lstatus; +#line 863 + +#line 863 + lstatus = ncx_getn_schar_ulonglong(&xp, nget, value); +#line 863 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 863 + status = lstatus; +#line 863 + +#line 863 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 863 + +#line 863 + remaining -= extent; +#line 863 + if(remaining == 0) +#line 863 + break; /* normal loop exit */ +#line 863 + offset += (off_t)extent; +#line 863 + value += nget; +#line 863 + } +#line 863 + +#line 863 + return status; +#line 863 +} +#line 863 + +static int +#line 864 +getNCvx_schar_uchar(const NC3_INFO* ncp, const NC_var *varp, +#line 864 + const size_t *start, size_t nelems, uchar *value) +#line 864 +{ +#line 864 + off_t offset = NC_varoffset(ncp, varp, start); +#line 864 + size_t remaining = varp->xsz * nelems; +#line 864 + int status = NC_NOERR; +#line 864 + const void *xp; +#line 864 + +#line 864 + if(nelems == 0) +#line 864 + return NC_NOERR; +#line 864 + +#line 864 + assert(value != NULL); +#line 864 + +#line 864 + for(;;) +#line 864 + { +#line 864 + size_t extent = MIN(remaining, ncp->chunk); +#line 864 + size_t nget = ncx_howmany(varp->type, extent); +#line 864 + +#line 864 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 864 + 0, (void **)&xp); /* cast away const */ +#line 864 + if(lstatus != NC_NOERR) +#line 864 + return lstatus; +#line 864 + +#line 864 + lstatus = ncx_getn_schar_uchar(&xp, nget, value); +#line 864 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 864 + status = lstatus; +#line 864 + +#line 864 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 864 + +#line 864 + remaining -= extent; +#line 864 + if(remaining == 0) +#line 864 + break; /* normal loop exit */ +#line 864 + offset += (off_t)extent; +#line 864 + value += nget; +#line 864 + } +#line 864 + +#line 864 + return status; +#line 864 +} +#line 864 + +static int +#line 865 +getNCvx_schar_ushort(const NC3_INFO* ncp, const NC_var *varp, +#line 865 + const size_t *start, size_t nelems, ushort *value) +#line 865 +{ +#line 865 + off_t offset = NC_varoffset(ncp, varp, start); +#line 865 + size_t remaining = varp->xsz * nelems; +#line 865 + int status = NC_NOERR; +#line 865 + const void *xp; +#line 865 + +#line 865 + if(nelems == 0) +#line 865 + return NC_NOERR; +#line 865 + +#line 865 + assert(value != NULL); +#line 865 + +#line 865 + for(;;) +#line 865 + { +#line 865 + size_t extent = MIN(remaining, ncp->chunk); +#line 865 + size_t nget = ncx_howmany(varp->type, extent); +#line 865 + +#line 865 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 865 + 0, (void **)&xp); /* cast away const */ +#line 865 + if(lstatus != NC_NOERR) +#line 865 + return lstatus; +#line 865 + +#line 865 + lstatus = ncx_getn_schar_ushort(&xp, nget, value); +#line 865 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 865 + status = lstatus; +#line 865 + +#line 865 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 865 + +#line 865 + remaining -= extent; +#line 865 + if(remaining == 0) +#line 865 + break; /* normal loop exit */ +#line 865 + offset += (off_t)extent; +#line 865 + value += nget; +#line 865 + } +#line 865 + +#line 865 + return status; +#line 865 +} +#line 865 + + +static int +#line 867 +getNCvx_short_schar(const NC3_INFO* ncp, const NC_var *varp, +#line 867 + const size_t *start, size_t nelems, schar *value) +#line 867 +{ +#line 867 + off_t offset = NC_varoffset(ncp, varp, start); +#line 867 + size_t remaining = varp->xsz * nelems; +#line 867 + int status = NC_NOERR; +#line 867 + const void *xp; +#line 867 + +#line 867 + if(nelems == 0) +#line 867 + return NC_NOERR; +#line 867 + +#line 867 + assert(value != NULL); +#line 867 + +#line 867 + for(;;) +#line 867 + { +#line 867 + size_t extent = MIN(remaining, ncp->chunk); +#line 867 + size_t nget = ncx_howmany(varp->type, extent); +#line 867 + +#line 867 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 867 + 0, (void **)&xp); /* cast away const */ +#line 867 + if(lstatus != NC_NOERR) +#line 867 + return lstatus; +#line 867 + +#line 867 + lstatus = ncx_getn_short_schar(&xp, nget, value); +#line 867 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 867 + status = lstatus; +#line 867 + +#line 867 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 867 + +#line 867 + remaining -= extent; +#line 867 + if(remaining == 0) +#line 867 + break; /* normal loop exit */ +#line 867 + offset += (off_t)extent; +#line 867 + value += nget; +#line 867 + } +#line 867 + +#line 867 + return status; +#line 867 +} +#line 867 + +static int +#line 868 +getNCvx_short_uchar(const NC3_INFO* ncp, const NC_var *varp, +#line 868 + const size_t *start, size_t nelems, uchar *value) +#line 868 +{ +#line 868 + off_t offset = NC_varoffset(ncp, varp, start); +#line 868 + size_t remaining = varp->xsz * nelems; +#line 868 + int status = NC_NOERR; +#line 868 + const void *xp; +#line 868 + +#line 868 + if(nelems == 0) +#line 868 + return NC_NOERR; +#line 868 + +#line 868 + assert(value != NULL); +#line 868 + +#line 868 + for(;;) +#line 868 + { +#line 868 + size_t extent = MIN(remaining, ncp->chunk); +#line 868 + size_t nget = ncx_howmany(varp->type, extent); +#line 868 + +#line 868 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 868 + 0, (void **)&xp); /* cast away const */ +#line 868 + if(lstatus != NC_NOERR) +#line 868 + return lstatus; +#line 868 + +#line 868 + lstatus = ncx_getn_short_uchar(&xp, nget, value); +#line 868 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 868 + status = lstatus; +#line 868 + +#line 868 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 868 + +#line 868 + remaining -= extent; +#line 868 + if(remaining == 0) +#line 868 + break; /* normal loop exit */ +#line 868 + offset += (off_t)extent; +#line 868 + value += nget; +#line 868 + } +#line 868 + +#line 868 + return status; +#line 868 +} +#line 868 + +static int +#line 869 +getNCvx_short_short(const NC3_INFO* ncp, const NC_var *varp, +#line 869 + const size_t *start, size_t nelems, short *value) +#line 869 +{ +#line 869 + off_t offset = NC_varoffset(ncp, varp, start); +#line 869 + size_t remaining = varp->xsz * nelems; +#line 869 + int status = NC_NOERR; +#line 869 + const void *xp; +#line 869 + +#line 869 + if(nelems == 0) +#line 869 + return NC_NOERR; +#line 869 + +#line 869 + assert(value != NULL); +#line 869 + +#line 869 + for(;;) +#line 869 + { +#line 869 + size_t extent = MIN(remaining, ncp->chunk); +#line 869 + size_t nget = ncx_howmany(varp->type, extent); +#line 869 + +#line 869 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 869 + 0, (void **)&xp); /* cast away const */ +#line 869 + if(lstatus != NC_NOERR) +#line 869 + return lstatus; +#line 869 + +#line 869 + lstatus = ncx_getn_short_short(&xp, nget, value); +#line 869 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 869 + status = lstatus; +#line 869 + +#line 869 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 869 + +#line 869 + remaining -= extent; +#line 869 + if(remaining == 0) +#line 869 + break; /* normal loop exit */ +#line 869 + offset += (off_t)extent; +#line 869 + value += nget; +#line 869 + } +#line 869 + +#line 869 + return status; +#line 869 +} +#line 869 + +static int +#line 870 +getNCvx_short_int(const NC3_INFO* ncp, const NC_var *varp, +#line 870 + const size_t *start, size_t nelems, int *value) +#line 870 +{ +#line 870 + off_t offset = NC_varoffset(ncp, varp, start); +#line 870 + size_t remaining = varp->xsz * nelems; +#line 870 + int status = NC_NOERR; +#line 870 + const void *xp; +#line 870 + +#line 870 + if(nelems == 0) +#line 870 + return NC_NOERR; +#line 870 + +#line 870 + assert(value != NULL); +#line 870 + +#line 870 + for(;;) +#line 870 + { +#line 870 + size_t extent = MIN(remaining, ncp->chunk); +#line 870 + size_t nget = ncx_howmany(varp->type, extent); +#line 870 + +#line 870 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 870 + 0, (void **)&xp); /* cast away const */ +#line 870 + if(lstatus != NC_NOERR) +#line 870 + return lstatus; +#line 870 + +#line 870 + lstatus = ncx_getn_short_int(&xp, nget, value); +#line 870 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 870 + status = lstatus; +#line 870 + +#line 870 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 870 + +#line 870 + remaining -= extent; +#line 870 + if(remaining == 0) +#line 870 + break; /* normal loop exit */ +#line 870 + offset += (off_t)extent; +#line 870 + value += nget; +#line 870 + } +#line 870 + +#line 870 + return status; +#line 870 +} +#line 870 + +static int +#line 871 +getNCvx_short_float(const NC3_INFO* ncp, const NC_var *varp, +#line 871 + const size_t *start, size_t nelems, float *value) +#line 871 +{ +#line 871 + off_t offset = NC_varoffset(ncp, varp, start); +#line 871 + size_t remaining = varp->xsz * nelems; +#line 871 + int status = NC_NOERR; +#line 871 + const void *xp; +#line 871 + +#line 871 + if(nelems == 0) +#line 871 + return NC_NOERR; +#line 871 + +#line 871 + assert(value != NULL); +#line 871 + +#line 871 + for(;;) +#line 871 + { +#line 871 + size_t extent = MIN(remaining, ncp->chunk); +#line 871 + size_t nget = ncx_howmany(varp->type, extent); +#line 871 + +#line 871 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 871 + 0, (void **)&xp); /* cast away const */ +#line 871 + if(lstatus != NC_NOERR) +#line 871 + return lstatus; +#line 871 + +#line 871 + lstatus = ncx_getn_short_float(&xp, nget, value); +#line 871 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 871 + status = lstatus; +#line 871 + +#line 871 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 871 + +#line 871 + remaining -= extent; +#line 871 + if(remaining == 0) +#line 871 + break; /* normal loop exit */ +#line 871 + offset += (off_t)extent; +#line 871 + value += nget; +#line 871 + } +#line 871 + +#line 871 + return status; +#line 871 +} +#line 871 + +static int +#line 872 +getNCvx_short_double(const NC3_INFO* ncp, const NC_var *varp, +#line 872 + const size_t *start, size_t nelems, double *value) +#line 872 +{ +#line 872 + off_t offset = NC_varoffset(ncp, varp, start); +#line 872 + size_t remaining = varp->xsz * nelems; +#line 872 + int status = NC_NOERR; +#line 872 + const void *xp; +#line 872 + +#line 872 + if(nelems == 0) +#line 872 + return NC_NOERR; +#line 872 + +#line 872 + assert(value != NULL); +#line 872 + +#line 872 + for(;;) +#line 872 + { +#line 872 + size_t extent = MIN(remaining, ncp->chunk); +#line 872 + size_t nget = ncx_howmany(varp->type, extent); +#line 872 + +#line 872 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 872 + 0, (void **)&xp); /* cast away const */ +#line 872 + if(lstatus != NC_NOERR) +#line 872 + return lstatus; +#line 872 + +#line 872 + lstatus = ncx_getn_short_double(&xp, nget, value); +#line 872 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 872 + status = lstatus; +#line 872 + +#line 872 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 872 + +#line 872 + remaining -= extent; +#line 872 + if(remaining == 0) +#line 872 + break; /* normal loop exit */ +#line 872 + offset += (off_t)extent; +#line 872 + value += nget; +#line 872 + } +#line 872 + +#line 872 + return status; +#line 872 +} +#line 872 + +static int +#line 873 +getNCvx_short_longlong(const NC3_INFO* ncp, const NC_var *varp, +#line 873 + const size_t *start, size_t nelems, longlong *value) +#line 873 +{ +#line 873 + off_t offset = NC_varoffset(ncp, varp, start); +#line 873 + size_t remaining = varp->xsz * nelems; +#line 873 + int status = NC_NOERR; +#line 873 + const void *xp; +#line 873 + +#line 873 + if(nelems == 0) +#line 873 + return NC_NOERR; +#line 873 + +#line 873 + assert(value != NULL); +#line 873 + +#line 873 + for(;;) +#line 873 + { +#line 873 + size_t extent = MIN(remaining, ncp->chunk); +#line 873 + size_t nget = ncx_howmany(varp->type, extent); +#line 873 + +#line 873 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 873 + 0, (void **)&xp); /* cast away const */ +#line 873 + if(lstatus != NC_NOERR) +#line 873 + return lstatus; +#line 873 + +#line 873 + lstatus = ncx_getn_short_longlong(&xp, nget, value); +#line 873 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 873 + status = lstatus; +#line 873 + +#line 873 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 873 + +#line 873 + remaining -= extent; +#line 873 + if(remaining == 0) +#line 873 + break; /* normal loop exit */ +#line 873 + offset += (off_t)extent; +#line 873 + value += nget; +#line 873 + } +#line 873 + +#line 873 + return status; +#line 873 +} +#line 873 + +static int +#line 874 +getNCvx_short_uint(const NC3_INFO* ncp, const NC_var *varp, +#line 874 + const size_t *start, size_t nelems, uint *value) +#line 874 +{ +#line 874 + off_t offset = NC_varoffset(ncp, varp, start); +#line 874 + size_t remaining = varp->xsz * nelems; +#line 874 + int status = NC_NOERR; +#line 874 + const void *xp; +#line 874 + +#line 874 + if(nelems == 0) +#line 874 + return NC_NOERR; +#line 874 + +#line 874 + assert(value != NULL); +#line 874 + +#line 874 + for(;;) +#line 874 + { +#line 874 + size_t extent = MIN(remaining, ncp->chunk); +#line 874 + size_t nget = ncx_howmany(varp->type, extent); +#line 874 + +#line 874 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 874 + 0, (void **)&xp); /* cast away const */ +#line 874 + if(lstatus != NC_NOERR) +#line 874 + return lstatus; +#line 874 + +#line 874 + lstatus = ncx_getn_short_uint(&xp, nget, value); +#line 874 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 874 + status = lstatus; +#line 874 + +#line 874 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 874 + +#line 874 + remaining -= extent; +#line 874 + if(remaining == 0) +#line 874 + break; /* normal loop exit */ +#line 874 + offset += (off_t)extent; +#line 874 + value += nget; +#line 874 + } +#line 874 + +#line 874 + return status; +#line 874 +} +#line 874 + +static int +#line 875 +getNCvx_short_ulonglong(const NC3_INFO* ncp, const NC_var *varp, +#line 875 + const size_t *start, size_t nelems, ulonglong *value) +#line 875 +{ +#line 875 + off_t offset = NC_varoffset(ncp, varp, start); +#line 875 + size_t remaining = varp->xsz * nelems; +#line 875 + int status = NC_NOERR; +#line 875 + const void *xp; +#line 875 + +#line 875 + if(nelems == 0) +#line 875 + return NC_NOERR; +#line 875 + +#line 875 + assert(value != NULL); +#line 875 + +#line 875 + for(;;) +#line 875 + { +#line 875 + size_t extent = MIN(remaining, ncp->chunk); +#line 875 + size_t nget = ncx_howmany(varp->type, extent); +#line 875 + +#line 875 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 875 + 0, (void **)&xp); /* cast away const */ +#line 875 + if(lstatus != NC_NOERR) +#line 875 + return lstatus; +#line 875 + +#line 875 + lstatus = ncx_getn_short_ulonglong(&xp, nget, value); +#line 875 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 875 + status = lstatus; +#line 875 + +#line 875 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 875 + +#line 875 + remaining -= extent; +#line 875 + if(remaining == 0) +#line 875 + break; /* normal loop exit */ +#line 875 + offset += (off_t)extent; +#line 875 + value += nget; +#line 875 + } +#line 875 + +#line 875 + return status; +#line 875 +} +#line 875 + +static int +#line 876 +getNCvx_short_ushort(const NC3_INFO* ncp, const NC_var *varp, +#line 876 + const size_t *start, size_t nelems, ushort *value) +#line 876 +{ +#line 876 + off_t offset = NC_varoffset(ncp, varp, start); +#line 876 + size_t remaining = varp->xsz * nelems; +#line 876 + int status = NC_NOERR; +#line 876 + const void *xp; +#line 876 + +#line 876 + if(nelems == 0) +#line 876 + return NC_NOERR; +#line 876 + +#line 876 + assert(value != NULL); +#line 876 + +#line 876 + for(;;) +#line 876 + { +#line 876 + size_t extent = MIN(remaining, ncp->chunk); +#line 876 + size_t nget = ncx_howmany(varp->type, extent); +#line 876 + +#line 876 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 876 + 0, (void **)&xp); /* cast away const */ +#line 876 + if(lstatus != NC_NOERR) +#line 876 + return lstatus; +#line 876 + +#line 876 + lstatus = ncx_getn_short_ushort(&xp, nget, value); +#line 876 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 876 + status = lstatus; +#line 876 + +#line 876 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 876 + +#line 876 + remaining -= extent; +#line 876 + if(remaining == 0) +#line 876 + break; /* normal loop exit */ +#line 876 + offset += (off_t)extent; +#line 876 + value += nget; +#line 876 + } +#line 876 + +#line 876 + return status; +#line 876 +} +#line 876 + + +static int +#line 878 +getNCvx_int_schar(const NC3_INFO* ncp, const NC_var *varp, +#line 878 + const size_t *start, size_t nelems, schar *value) +#line 878 +{ +#line 878 + off_t offset = NC_varoffset(ncp, varp, start); +#line 878 + size_t remaining = varp->xsz * nelems; +#line 878 + int status = NC_NOERR; +#line 878 + const void *xp; +#line 878 + +#line 878 + if(nelems == 0) +#line 878 + return NC_NOERR; +#line 878 + +#line 878 + assert(value != NULL); +#line 878 + +#line 878 + for(;;) +#line 878 + { +#line 878 + size_t extent = MIN(remaining, ncp->chunk); +#line 878 + size_t nget = ncx_howmany(varp->type, extent); +#line 878 + +#line 878 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 878 + 0, (void **)&xp); /* cast away const */ +#line 878 + if(lstatus != NC_NOERR) +#line 878 + return lstatus; +#line 878 + +#line 878 + lstatus = ncx_getn_int_schar(&xp, nget, value); +#line 878 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 878 + status = lstatus; +#line 878 + +#line 878 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 878 + +#line 878 + remaining -= extent; +#line 878 + if(remaining == 0) +#line 878 + break; /* normal loop exit */ +#line 878 + offset += (off_t)extent; +#line 878 + value += nget; +#line 878 + } +#line 878 + +#line 878 + return status; +#line 878 +} +#line 878 + +static int +#line 879 +getNCvx_int_uchar(const NC3_INFO* ncp, const NC_var *varp, +#line 879 + const size_t *start, size_t nelems, uchar *value) +#line 879 +{ +#line 879 + off_t offset = NC_varoffset(ncp, varp, start); +#line 879 + size_t remaining = varp->xsz * nelems; +#line 879 + int status = NC_NOERR; +#line 879 + const void *xp; +#line 879 + +#line 879 + if(nelems == 0) +#line 879 + return NC_NOERR; +#line 879 + +#line 879 + assert(value != NULL); +#line 879 + +#line 879 + for(;;) +#line 879 + { +#line 879 + size_t extent = MIN(remaining, ncp->chunk); +#line 879 + size_t nget = ncx_howmany(varp->type, extent); +#line 879 + +#line 879 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 879 + 0, (void **)&xp); /* cast away const */ +#line 879 + if(lstatus != NC_NOERR) +#line 879 + return lstatus; +#line 879 + +#line 879 + lstatus = ncx_getn_int_uchar(&xp, nget, value); +#line 879 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 879 + status = lstatus; +#line 879 + +#line 879 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 879 + +#line 879 + remaining -= extent; +#line 879 + if(remaining == 0) +#line 879 + break; /* normal loop exit */ +#line 879 + offset += (off_t)extent; +#line 879 + value += nget; +#line 879 + } +#line 879 + +#line 879 + return status; +#line 879 +} +#line 879 + +static int +#line 880 +getNCvx_int_short(const NC3_INFO* ncp, const NC_var *varp, +#line 880 + const size_t *start, size_t nelems, short *value) +#line 880 +{ +#line 880 + off_t offset = NC_varoffset(ncp, varp, start); +#line 880 + size_t remaining = varp->xsz * nelems; +#line 880 + int status = NC_NOERR; +#line 880 + const void *xp; +#line 880 + +#line 880 + if(nelems == 0) +#line 880 + return NC_NOERR; +#line 880 + +#line 880 + assert(value != NULL); +#line 880 + +#line 880 + for(;;) +#line 880 + { +#line 880 + size_t extent = MIN(remaining, ncp->chunk); +#line 880 + size_t nget = ncx_howmany(varp->type, extent); +#line 880 + +#line 880 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 880 + 0, (void **)&xp); /* cast away const */ +#line 880 + if(lstatus != NC_NOERR) +#line 880 + return lstatus; +#line 880 + +#line 880 + lstatus = ncx_getn_int_short(&xp, nget, value); +#line 880 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 880 + status = lstatus; +#line 880 + +#line 880 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 880 + +#line 880 + remaining -= extent; +#line 880 + if(remaining == 0) +#line 880 + break; /* normal loop exit */ +#line 880 + offset += (off_t)extent; +#line 880 + value += nget; +#line 880 + } +#line 880 + +#line 880 + return status; +#line 880 +} +#line 880 + +static int +#line 881 +getNCvx_int_int(const NC3_INFO* ncp, const NC_var *varp, +#line 881 + const size_t *start, size_t nelems, int *value) +#line 881 +{ +#line 881 + off_t offset = NC_varoffset(ncp, varp, start); +#line 881 + size_t remaining = varp->xsz * nelems; +#line 881 + int status = NC_NOERR; +#line 881 + const void *xp; +#line 881 + +#line 881 + if(nelems == 0) +#line 881 + return NC_NOERR; +#line 881 + +#line 881 + assert(value != NULL); +#line 881 + +#line 881 + for(;;) +#line 881 + { +#line 881 + size_t extent = MIN(remaining, ncp->chunk); +#line 881 + size_t nget = ncx_howmany(varp->type, extent); +#line 881 + +#line 881 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 881 + 0, (void **)&xp); /* cast away const */ +#line 881 + if(lstatus != NC_NOERR) +#line 881 + return lstatus; +#line 881 + +#line 881 + lstatus = ncx_getn_int_int(&xp, nget, value); +#line 881 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 881 + status = lstatus; +#line 881 + +#line 881 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 881 + +#line 881 + remaining -= extent; +#line 881 + if(remaining == 0) +#line 881 + break; /* normal loop exit */ +#line 881 + offset += (off_t)extent; +#line 881 + value += nget; +#line 881 + } +#line 881 + +#line 881 + return status; +#line 881 +} +#line 881 + +static int +#line 882 +getNCvx_int_float(const NC3_INFO* ncp, const NC_var *varp, +#line 882 + const size_t *start, size_t nelems, float *value) +#line 882 +{ +#line 882 + off_t offset = NC_varoffset(ncp, varp, start); +#line 882 + size_t remaining = varp->xsz * nelems; +#line 882 + int status = NC_NOERR; +#line 882 + const void *xp; +#line 882 + +#line 882 + if(nelems == 0) +#line 882 + return NC_NOERR; +#line 882 + +#line 882 + assert(value != NULL); +#line 882 + +#line 882 + for(;;) +#line 882 + { +#line 882 + size_t extent = MIN(remaining, ncp->chunk); +#line 882 + size_t nget = ncx_howmany(varp->type, extent); +#line 882 + +#line 882 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 882 + 0, (void **)&xp); /* cast away const */ +#line 882 + if(lstatus != NC_NOERR) +#line 882 + return lstatus; +#line 882 + +#line 882 + lstatus = ncx_getn_int_float(&xp, nget, value); +#line 882 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 882 + status = lstatus; +#line 882 + +#line 882 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 882 + +#line 882 + remaining -= extent; +#line 882 + if(remaining == 0) +#line 882 + break; /* normal loop exit */ +#line 882 + offset += (off_t)extent; +#line 882 + value += nget; +#line 882 + } +#line 882 + +#line 882 + return status; +#line 882 +} +#line 882 + +static int +#line 883 +getNCvx_int_double(const NC3_INFO* ncp, const NC_var *varp, +#line 883 + const size_t *start, size_t nelems, double *value) +#line 883 +{ +#line 883 + off_t offset = NC_varoffset(ncp, varp, start); +#line 883 + size_t remaining = varp->xsz * nelems; +#line 883 + int status = NC_NOERR; +#line 883 + const void *xp; +#line 883 + +#line 883 + if(nelems == 0) +#line 883 + return NC_NOERR; +#line 883 + +#line 883 + assert(value != NULL); +#line 883 + +#line 883 + for(;;) +#line 883 + { +#line 883 + size_t extent = MIN(remaining, ncp->chunk); +#line 883 + size_t nget = ncx_howmany(varp->type, extent); +#line 883 + +#line 883 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 883 + 0, (void **)&xp); /* cast away const */ +#line 883 + if(lstatus != NC_NOERR) +#line 883 + return lstatus; +#line 883 + +#line 883 + lstatus = ncx_getn_int_double(&xp, nget, value); +#line 883 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 883 + status = lstatus; +#line 883 + +#line 883 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 883 + +#line 883 + remaining -= extent; +#line 883 + if(remaining == 0) +#line 883 + break; /* normal loop exit */ +#line 883 + offset += (off_t)extent; +#line 883 + value += nget; +#line 883 + } +#line 883 + +#line 883 + return status; +#line 883 +} +#line 883 + +static int +#line 884 +getNCvx_int_longlong(const NC3_INFO* ncp, const NC_var *varp, +#line 884 + const size_t *start, size_t nelems, longlong *value) +#line 884 +{ +#line 884 + off_t offset = NC_varoffset(ncp, varp, start); +#line 884 + size_t remaining = varp->xsz * nelems; +#line 884 + int status = NC_NOERR; +#line 884 + const void *xp; +#line 884 + +#line 884 + if(nelems == 0) +#line 884 + return NC_NOERR; +#line 884 + +#line 884 + assert(value != NULL); +#line 884 + +#line 884 + for(;;) +#line 884 + { +#line 884 + size_t extent = MIN(remaining, ncp->chunk); +#line 884 + size_t nget = ncx_howmany(varp->type, extent); +#line 884 + +#line 884 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 884 + 0, (void **)&xp); /* cast away const */ +#line 884 + if(lstatus != NC_NOERR) +#line 884 + return lstatus; +#line 884 + +#line 884 + lstatus = ncx_getn_int_longlong(&xp, nget, value); +#line 884 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 884 + status = lstatus; +#line 884 + +#line 884 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 884 + +#line 884 + remaining -= extent; +#line 884 + if(remaining == 0) +#line 884 + break; /* normal loop exit */ +#line 884 + offset += (off_t)extent; +#line 884 + value += nget; +#line 884 + } +#line 884 + +#line 884 + return status; +#line 884 +} +#line 884 + +static int +#line 885 +getNCvx_int_uint(const NC3_INFO* ncp, const NC_var *varp, +#line 885 + const size_t *start, size_t nelems, uint *value) +#line 885 +{ +#line 885 + off_t offset = NC_varoffset(ncp, varp, start); +#line 885 + size_t remaining = varp->xsz * nelems; +#line 885 + int status = NC_NOERR; +#line 885 + const void *xp; +#line 885 + +#line 885 + if(nelems == 0) +#line 885 + return NC_NOERR; +#line 885 + +#line 885 + assert(value != NULL); +#line 885 + +#line 885 + for(;;) +#line 885 + { +#line 885 + size_t extent = MIN(remaining, ncp->chunk); +#line 885 + size_t nget = ncx_howmany(varp->type, extent); +#line 885 + +#line 885 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 885 + 0, (void **)&xp); /* cast away const */ +#line 885 + if(lstatus != NC_NOERR) +#line 885 + return lstatus; +#line 885 + +#line 885 + lstatus = ncx_getn_int_uint(&xp, nget, value); +#line 885 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 885 + status = lstatus; +#line 885 + +#line 885 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 885 + +#line 885 + remaining -= extent; +#line 885 + if(remaining == 0) +#line 885 + break; /* normal loop exit */ +#line 885 + offset += (off_t)extent; +#line 885 + value += nget; +#line 885 + } +#line 885 + +#line 885 + return status; +#line 885 +} +#line 885 + +static int +#line 886 +getNCvx_int_ulonglong(const NC3_INFO* ncp, const NC_var *varp, +#line 886 + const size_t *start, size_t nelems, ulonglong *value) +#line 886 +{ +#line 886 + off_t offset = NC_varoffset(ncp, varp, start); +#line 886 + size_t remaining = varp->xsz * nelems; +#line 886 + int status = NC_NOERR; +#line 886 + const void *xp; +#line 886 + +#line 886 + if(nelems == 0) +#line 886 + return NC_NOERR; +#line 886 + +#line 886 + assert(value != NULL); +#line 886 + +#line 886 + for(;;) +#line 886 + { +#line 886 + size_t extent = MIN(remaining, ncp->chunk); +#line 886 + size_t nget = ncx_howmany(varp->type, extent); +#line 886 + +#line 886 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 886 + 0, (void **)&xp); /* cast away const */ +#line 886 + if(lstatus != NC_NOERR) +#line 886 + return lstatus; +#line 886 + +#line 886 + lstatus = ncx_getn_int_ulonglong(&xp, nget, value); +#line 886 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 886 + status = lstatus; +#line 886 + +#line 886 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 886 + +#line 886 + remaining -= extent; +#line 886 + if(remaining == 0) +#line 886 + break; /* normal loop exit */ +#line 886 + offset += (off_t)extent; +#line 886 + value += nget; +#line 886 + } +#line 886 + +#line 886 + return status; +#line 886 +} +#line 886 + +static int +#line 887 +getNCvx_int_ushort(const NC3_INFO* ncp, const NC_var *varp, +#line 887 + const size_t *start, size_t nelems, ushort *value) +#line 887 +{ +#line 887 + off_t offset = NC_varoffset(ncp, varp, start); +#line 887 + size_t remaining = varp->xsz * nelems; +#line 887 + int status = NC_NOERR; +#line 887 + const void *xp; +#line 887 + +#line 887 + if(nelems == 0) +#line 887 + return NC_NOERR; +#line 887 + +#line 887 + assert(value != NULL); +#line 887 + +#line 887 + for(;;) +#line 887 + { +#line 887 + size_t extent = MIN(remaining, ncp->chunk); +#line 887 + size_t nget = ncx_howmany(varp->type, extent); +#line 887 + +#line 887 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 887 + 0, (void **)&xp); /* cast away const */ +#line 887 + if(lstatus != NC_NOERR) +#line 887 + return lstatus; +#line 887 + +#line 887 + lstatus = ncx_getn_int_ushort(&xp, nget, value); +#line 887 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 887 + status = lstatus; +#line 887 + +#line 887 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 887 + +#line 887 + remaining -= extent; +#line 887 + if(remaining == 0) +#line 887 + break; /* normal loop exit */ +#line 887 + offset += (off_t)extent; +#line 887 + value += nget; +#line 887 + } +#line 887 + +#line 887 + return status; +#line 887 +} +#line 887 + + +static int +#line 889 +getNCvx_float_schar(const NC3_INFO* ncp, const NC_var *varp, +#line 889 + const size_t *start, size_t nelems, schar *value) +#line 889 +{ +#line 889 + off_t offset = NC_varoffset(ncp, varp, start); +#line 889 + size_t remaining = varp->xsz * nelems; +#line 889 + int status = NC_NOERR; +#line 889 + const void *xp; +#line 889 + +#line 889 + if(nelems == 0) +#line 889 + return NC_NOERR; +#line 889 + +#line 889 + assert(value != NULL); +#line 889 + +#line 889 + for(;;) +#line 889 + { +#line 889 + size_t extent = MIN(remaining, ncp->chunk); +#line 889 + size_t nget = ncx_howmany(varp->type, extent); +#line 889 + +#line 889 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 889 + 0, (void **)&xp); /* cast away const */ +#line 889 + if(lstatus != NC_NOERR) +#line 889 + return lstatus; +#line 889 + +#line 889 + lstatus = ncx_getn_float_schar(&xp, nget, value); +#line 889 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 889 + status = lstatus; +#line 889 + +#line 889 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 889 + +#line 889 + remaining -= extent; +#line 889 + if(remaining == 0) +#line 889 + break; /* normal loop exit */ +#line 889 + offset += (off_t)extent; +#line 889 + value += nget; +#line 889 + } +#line 889 + +#line 889 + return status; +#line 889 +} +#line 889 + +static int +#line 890 +getNCvx_float_uchar(const NC3_INFO* ncp, const NC_var *varp, +#line 890 + const size_t *start, size_t nelems, uchar *value) +#line 890 +{ +#line 890 + off_t offset = NC_varoffset(ncp, varp, start); +#line 890 + size_t remaining = varp->xsz * nelems; +#line 890 + int status = NC_NOERR; +#line 890 + const void *xp; +#line 890 + +#line 890 + if(nelems == 0) +#line 890 + return NC_NOERR; +#line 890 + +#line 890 + assert(value != NULL); +#line 890 + +#line 890 + for(;;) +#line 890 + { +#line 890 + size_t extent = MIN(remaining, ncp->chunk); +#line 890 + size_t nget = ncx_howmany(varp->type, extent); +#line 890 + +#line 890 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 890 + 0, (void **)&xp); /* cast away const */ +#line 890 + if(lstatus != NC_NOERR) +#line 890 + return lstatus; +#line 890 + +#line 890 + lstatus = ncx_getn_float_uchar(&xp, nget, value); +#line 890 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 890 + status = lstatus; +#line 890 + +#line 890 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 890 + +#line 890 + remaining -= extent; +#line 890 + if(remaining == 0) +#line 890 + break; /* normal loop exit */ +#line 890 + offset += (off_t)extent; +#line 890 + value += nget; +#line 890 + } +#line 890 + +#line 890 + return status; +#line 890 +} +#line 890 + +static int +#line 891 +getNCvx_float_short(const NC3_INFO* ncp, const NC_var *varp, +#line 891 + const size_t *start, size_t nelems, short *value) +#line 891 +{ +#line 891 + off_t offset = NC_varoffset(ncp, varp, start); +#line 891 + size_t remaining = varp->xsz * nelems; +#line 891 + int status = NC_NOERR; +#line 891 + const void *xp; +#line 891 + +#line 891 + if(nelems == 0) +#line 891 + return NC_NOERR; +#line 891 + +#line 891 + assert(value != NULL); +#line 891 + +#line 891 + for(;;) +#line 891 + { +#line 891 + size_t extent = MIN(remaining, ncp->chunk); +#line 891 + size_t nget = ncx_howmany(varp->type, extent); +#line 891 + +#line 891 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 891 + 0, (void **)&xp); /* cast away const */ +#line 891 + if(lstatus != NC_NOERR) +#line 891 + return lstatus; +#line 891 + +#line 891 + lstatus = ncx_getn_float_short(&xp, nget, value); +#line 891 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 891 + status = lstatus; +#line 891 + +#line 891 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 891 + +#line 891 + remaining -= extent; +#line 891 + if(remaining == 0) +#line 891 + break; /* normal loop exit */ +#line 891 + offset += (off_t)extent; +#line 891 + value += nget; +#line 891 + } +#line 891 + +#line 891 + return status; +#line 891 +} +#line 891 + +static int +#line 892 +getNCvx_float_int(const NC3_INFO* ncp, const NC_var *varp, +#line 892 + const size_t *start, size_t nelems, int *value) +#line 892 +{ +#line 892 + off_t offset = NC_varoffset(ncp, varp, start); +#line 892 + size_t remaining = varp->xsz * nelems; +#line 892 + int status = NC_NOERR; +#line 892 + const void *xp; +#line 892 + +#line 892 + if(nelems == 0) +#line 892 + return NC_NOERR; +#line 892 + +#line 892 + assert(value != NULL); +#line 892 + +#line 892 + for(;;) +#line 892 + { +#line 892 + size_t extent = MIN(remaining, ncp->chunk); +#line 892 + size_t nget = ncx_howmany(varp->type, extent); +#line 892 + +#line 892 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 892 + 0, (void **)&xp); /* cast away const */ +#line 892 + if(lstatus != NC_NOERR) +#line 892 + return lstatus; +#line 892 + +#line 892 + lstatus = ncx_getn_float_int(&xp, nget, value); +#line 892 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 892 + status = lstatus; +#line 892 + +#line 892 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 892 + +#line 892 + remaining -= extent; +#line 892 + if(remaining == 0) +#line 892 + break; /* normal loop exit */ +#line 892 + offset += (off_t)extent; +#line 892 + value += nget; +#line 892 + } +#line 892 + +#line 892 + return status; +#line 892 +} +#line 892 + +static int +#line 893 +getNCvx_float_float(const NC3_INFO* ncp, const NC_var *varp, +#line 893 + const size_t *start, size_t nelems, float *value) +#line 893 +{ +#line 893 + off_t offset = NC_varoffset(ncp, varp, start); +#line 893 + size_t remaining = varp->xsz * nelems; +#line 893 + int status = NC_NOERR; +#line 893 + const void *xp; +#line 893 + +#line 893 + if(nelems == 0) +#line 893 + return NC_NOERR; +#line 893 + +#line 893 + assert(value != NULL); +#line 893 + +#line 893 + for(;;) +#line 893 + { +#line 893 + size_t extent = MIN(remaining, ncp->chunk); +#line 893 + size_t nget = ncx_howmany(varp->type, extent); +#line 893 + +#line 893 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 893 + 0, (void **)&xp); /* cast away const */ +#line 893 + if(lstatus != NC_NOERR) +#line 893 + return lstatus; +#line 893 + +#line 893 + lstatus = ncx_getn_float_float(&xp, nget, value); +#line 893 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 893 + status = lstatus; +#line 893 + +#line 893 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 893 + +#line 893 + remaining -= extent; +#line 893 + if(remaining == 0) +#line 893 + break; /* normal loop exit */ +#line 893 + offset += (off_t)extent; +#line 893 + value += nget; +#line 893 + } +#line 893 + +#line 893 + return status; +#line 893 +} +#line 893 + +static int +#line 894 +getNCvx_float_double(const NC3_INFO* ncp, const NC_var *varp, +#line 894 + const size_t *start, size_t nelems, double *value) +#line 894 +{ +#line 894 + off_t offset = NC_varoffset(ncp, varp, start); +#line 894 + size_t remaining = varp->xsz * nelems; +#line 894 + int status = NC_NOERR; +#line 894 + const void *xp; +#line 894 + +#line 894 + if(nelems == 0) +#line 894 + return NC_NOERR; +#line 894 + +#line 894 + assert(value != NULL); +#line 894 + +#line 894 + for(;;) +#line 894 + { +#line 894 + size_t extent = MIN(remaining, ncp->chunk); +#line 894 + size_t nget = ncx_howmany(varp->type, extent); +#line 894 + +#line 894 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 894 + 0, (void **)&xp); /* cast away const */ +#line 894 + if(lstatus != NC_NOERR) +#line 894 + return lstatus; +#line 894 + +#line 894 + lstatus = ncx_getn_float_double(&xp, nget, value); +#line 894 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 894 + status = lstatus; +#line 894 + +#line 894 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 894 + +#line 894 + remaining -= extent; +#line 894 + if(remaining == 0) +#line 894 + break; /* normal loop exit */ +#line 894 + offset += (off_t)extent; +#line 894 + value += nget; +#line 894 + } +#line 894 + +#line 894 + return status; +#line 894 +} +#line 894 + +static int +#line 895 +getNCvx_float_longlong(const NC3_INFO* ncp, const NC_var *varp, +#line 895 + const size_t *start, size_t nelems, longlong *value) +#line 895 +{ +#line 895 + off_t offset = NC_varoffset(ncp, varp, start); +#line 895 + size_t remaining = varp->xsz * nelems; +#line 895 + int status = NC_NOERR; +#line 895 + const void *xp; +#line 895 + +#line 895 + if(nelems == 0) +#line 895 + return NC_NOERR; +#line 895 + +#line 895 + assert(value != NULL); +#line 895 + +#line 895 + for(;;) +#line 895 + { +#line 895 + size_t extent = MIN(remaining, ncp->chunk); +#line 895 + size_t nget = ncx_howmany(varp->type, extent); +#line 895 + +#line 895 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 895 + 0, (void **)&xp); /* cast away const */ +#line 895 + if(lstatus != NC_NOERR) +#line 895 + return lstatus; +#line 895 + +#line 895 + lstatus = ncx_getn_float_longlong(&xp, nget, value); +#line 895 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 895 + status = lstatus; +#line 895 + +#line 895 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 895 + +#line 895 + remaining -= extent; +#line 895 + if(remaining == 0) +#line 895 + break; /* normal loop exit */ +#line 895 + offset += (off_t)extent; +#line 895 + value += nget; +#line 895 + } +#line 895 + +#line 895 + return status; +#line 895 +} +#line 895 + +static int +#line 896 +getNCvx_float_uint(const NC3_INFO* ncp, const NC_var *varp, +#line 896 + const size_t *start, size_t nelems, uint *value) +#line 896 +{ +#line 896 + off_t offset = NC_varoffset(ncp, varp, start); +#line 896 + size_t remaining = varp->xsz * nelems; +#line 896 + int status = NC_NOERR; +#line 896 + const void *xp; +#line 896 + +#line 896 + if(nelems == 0) +#line 896 + return NC_NOERR; +#line 896 + +#line 896 + assert(value != NULL); +#line 896 + +#line 896 + for(;;) +#line 896 + { +#line 896 + size_t extent = MIN(remaining, ncp->chunk); +#line 896 + size_t nget = ncx_howmany(varp->type, extent); +#line 896 + +#line 896 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 896 + 0, (void **)&xp); /* cast away const */ +#line 896 + if(lstatus != NC_NOERR) +#line 896 + return lstatus; +#line 896 + +#line 896 + lstatus = ncx_getn_float_uint(&xp, nget, value); +#line 896 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 896 + status = lstatus; +#line 896 + +#line 896 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 896 + +#line 896 + remaining -= extent; +#line 896 + if(remaining == 0) +#line 896 + break; /* normal loop exit */ +#line 896 + offset += (off_t)extent; +#line 896 + value += nget; +#line 896 + } +#line 896 + +#line 896 + return status; +#line 896 +} +#line 896 + +static int +#line 897 +getNCvx_float_ulonglong(const NC3_INFO* ncp, const NC_var *varp, +#line 897 + const size_t *start, size_t nelems, ulonglong *value) +#line 897 +{ +#line 897 + off_t offset = NC_varoffset(ncp, varp, start); +#line 897 + size_t remaining = varp->xsz * nelems; +#line 897 + int status = NC_NOERR; +#line 897 + const void *xp; +#line 897 + +#line 897 + if(nelems == 0) +#line 897 + return NC_NOERR; +#line 897 + +#line 897 + assert(value != NULL); +#line 897 + +#line 897 + for(;;) +#line 897 + { +#line 897 + size_t extent = MIN(remaining, ncp->chunk); +#line 897 + size_t nget = ncx_howmany(varp->type, extent); +#line 897 + +#line 897 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 897 + 0, (void **)&xp); /* cast away const */ +#line 897 + if(lstatus != NC_NOERR) +#line 897 + return lstatus; +#line 897 + +#line 897 + lstatus = ncx_getn_float_ulonglong(&xp, nget, value); +#line 897 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 897 + status = lstatus; +#line 897 + +#line 897 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 897 + +#line 897 + remaining -= extent; +#line 897 + if(remaining == 0) +#line 897 + break; /* normal loop exit */ +#line 897 + offset += (off_t)extent; +#line 897 + value += nget; +#line 897 + } +#line 897 + +#line 897 + return status; +#line 897 +} +#line 897 + +static int +#line 898 +getNCvx_float_ushort(const NC3_INFO* ncp, const NC_var *varp, +#line 898 + const size_t *start, size_t nelems, ushort *value) +#line 898 +{ +#line 898 + off_t offset = NC_varoffset(ncp, varp, start); +#line 898 + size_t remaining = varp->xsz * nelems; +#line 898 + int status = NC_NOERR; +#line 898 + const void *xp; +#line 898 + +#line 898 + if(nelems == 0) +#line 898 + return NC_NOERR; +#line 898 + +#line 898 + assert(value != NULL); +#line 898 + +#line 898 + for(;;) +#line 898 + { +#line 898 + size_t extent = MIN(remaining, ncp->chunk); +#line 898 + size_t nget = ncx_howmany(varp->type, extent); +#line 898 + +#line 898 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 898 + 0, (void **)&xp); /* cast away const */ +#line 898 + if(lstatus != NC_NOERR) +#line 898 + return lstatus; +#line 898 + +#line 898 + lstatus = ncx_getn_float_ushort(&xp, nget, value); +#line 898 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 898 + status = lstatus; +#line 898 + +#line 898 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 898 + +#line 898 + remaining -= extent; +#line 898 + if(remaining == 0) +#line 898 + break; /* normal loop exit */ +#line 898 + offset += (off_t)extent; +#line 898 + value += nget; +#line 898 + } +#line 898 + +#line 898 + return status; +#line 898 +} +#line 898 + + +static int +#line 900 +getNCvx_double_schar(const NC3_INFO* ncp, const NC_var *varp, +#line 900 + const size_t *start, size_t nelems, schar *value) +#line 900 +{ +#line 900 + off_t offset = NC_varoffset(ncp, varp, start); +#line 900 + size_t remaining = varp->xsz * nelems; +#line 900 + int status = NC_NOERR; +#line 900 + const void *xp; +#line 900 + +#line 900 + if(nelems == 0) +#line 900 + return NC_NOERR; +#line 900 + +#line 900 + assert(value != NULL); +#line 900 + +#line 900 + for(;;) +#line 900 + { +#line 900 + size_t extent = MIN(remaining, ncp->chunk); +#line 900 + size_t nget = ncx_howmany(varp->type, extent); +#line 900 + +#line 900 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 900 + 0, (void **)&xp); /* cast away const */ +#line 900 + if(lstatus != NC_NOERR) +#line 900 + return lstatus; +#line 900 + +#line 900 + lstatus = ncx_getn_double_schar(&xp, nget, value); +#line 900 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 900 + status = lstatus; +#line 900 + +#line 900 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 900 + +#line 900 + remaining -= extent; +#line 900 + if(remaining == 0) +#line 900 + break; /* normal loop exit */ +#line 900 + offset += (off_t)extent; +#line 900 + value += nget; +#line 900 + } +#line 900 + +#line 900 + return status; +#line 900 +} +#line 900 + +static int +#line 901 +getNCvx_double_uchar(const NC3_INFO* ncp, const NC_var *varp, +#line 901 + const size_t *start, size_t nelems, uchar *value) +#line 901 +{ +#line 901 + off_t offset = NC_varoffset(ncp, varp, start); +#line 901 + size_t remaining = varp->xsz * nelems; +#line 901 + int status = NC_NOERR; +#line 901 + const void *xp; +#line 901 + +#line 901 + if(nelems == 0) +#line 901 + return NC_NOERR; +#line 901 + +#line 901 + assert(value != NULL); +#line 901 + +#line 901 + for(;;) +#line 901 + { +#line 901 + size_t extent = MIN(remaining, ncp->chunk); +#line 901 + size_t nget = ncx_howmany(varp->type, extent); +#line 901 + +#line 901 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 901 + 0, (void **)&xp); /* cast away const */ +#line 901 + if(lstatus != NC_NOERR) +#line 901 + return lstatus; +#line 901 + +#line 901 + lstatus = ncx_getn_double_uchar(&xp, nget, value); +#line 901 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 901 + status = lstatus; +#line 901 + +#line 901 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 901 + +#line 901 + remaining -= extent; +#line 901 + if(remaining == 0) +#line 901 + break; /* normal loop exit */ +#line 901 + offset += (off_t)extent; +#line 901 + value += nget; +#line 901 + } +#line 901 + +#line 901 + return status; +#line 901 +} +#line 901 + +static int +#line 902 +getNCvx_double_short(const NC3_INFO* ncp, const NC_var *varp, +#line 902 + const size_t *start, size_t nelems, short *value) +#line 902 +{ +#line 902 + off_t offset = NC_varoffset(ncp, varp, start); +#line 902 + size_t remaining = varp->xsz * nelems; +#line 902 + int status = NC_NOERR; +#line 902 + const void *xp; +#line 902 + +#line 902 + if(nelems == 0) +#line 902 + return NC_NOERR; +#line 902 + +#line 902 + assert(value != NULL); +#line 902 + +#line 902 + for(;;) +#line 902 + { +#line 902 + size_t extent = MIN(remaining, ncp->chunk); +#line 902 + size_t nget = ncx_howmany(varp->type, extent); +#line 902 + +#line 902 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 902 + 0, (void **)&xp); /* cast away const */ +#line 902 + if(lstatus != NC_NOERR) +#line 902 + return lstatus; +#line 902 + +#line 902 + lstatus = ncx_getn_double_short(&xp, nget, value); +#line 902 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 902 + status = lstatus; +#line 902 + +#line 902 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 902 + +#line 902 + remaining -= extent; +#line 902 + if(remaining == 0) +#line 902 + break; /* normal loop exit */ +#line 902 + offset += (off_t)extent; +#line 902 + value += nget; +#line 902 + } +#line 902 + +#line 902 + return status; +#line 902 +} +#line 902 + +static int +#line 903 +getNCvx_double_int(const NC3_INFO* ncp, const NC_var *varp, +#line 903 + const size_t *start, size_t nelems, int *value) +#line 903 +{ +#line 903 + off_t offset = NC_varoffset(ncp, varp, start); +#line 903 + size_t remaining = varp->xsz * nelems; +#line 903 + int status = NC_NOERR; +#line 903 + const void *xp; +#line 903 + +#line 903 + if(nelems == 0) +#line 903 + return NC_NOERR; +#line 903 + +#line 903 + assert(value != NULL); +#line 903 + +#line 903 + for(;;) +#line 903 + { +#line 903 + size_t extent = MIN(remaining, ncp->chunk); +#line 903 + size_t nget = ncx_howmany(varp->type, extent); +#line 903 + +#line 903 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 903 + 0, (void **)&xp); /* cast away const */ +#line 903 + if(lstatus != NC_NOERR) +#line 903 + return lstatus; +#line 903 + +#line 903 + lstatus = ncx_getn_double_int(&xp, nget, value); +#line 903 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 903 + status = lstatus; +#line 903 + +#line 903 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 903 + +#line 903 + remaining -= extent; +#line 903 + if(remaining == 0) +#line 903 + break; /* normal loop exit */ +#line 903 + offset += (off_t)extent; +#line 903 + value += nget; +#line 903 + } +#line 903 + +#line 903 + return status; +#line 903 +} +#line 903 + +static int +#line 904 +getNCvx_double_float(const NC3_INFO* ncp, const NC_var *varp, +#line 904 + const size_t *start, size_t nelems, float *value) +#line 904 +{ +#line 904 + off_t offset = NC_varoffset(ncp, varp, start); +#line 904 + size_t remaining = varp->xsz * nelems; +#line 904 + int status = NC_NOERR; +#line 904 + const void *xp; +#line 904 + +#line 904 + if(nelems == 0) +#line 904 + return NC_NOERR; +#line 904 + +#line 904 + assert(value != NULL); +#line 904 + +#line 904 + for(;;) +#line 904 + { +#line 904 + size_t extent = MIN(remaining, ncp->chunk); +#line 904 + size_t nget = ncx_howmany(varp->type, extent); +#line 904 + +#line 904 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 904 + 0, (void **)&xp); /* cast away const */ +#line 904 + if(lstatus != NC_NOERR) +#line 904 + return lstatus; +#line 904 + +#line 904 + lstatus = ncx_getn_double_float(&xp, nget, value); +#line 904 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 904 + status = lstatus; +#line 904 + +#line 904 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 904 + +#line 904 + remaining -= extent; +#line 904 + if(remaining == 0) +#line 904 + break; /* normal loop exit */ +#line 904 + offset += (off_t)extent; +#line 904 + value += nget; +#line 904 + } +#line 904 + +#line 904 + return status; +#line 904 +} +#line 904 + +static int +#line 905 +getNCvx_double_double(const NC3_INFO* ncp, const NC_var *varp, +#line 905 + const size_t *start, size_t nelems, double *value) +#line 905 +{ +#line 905 + off_t offset = NC_varoffset(ncp, varp, start); +#line 905 + size_t remaining = varp->xsz * nelems; +#line 905 + int status = NC_NOERR; +#line 905 + const void *xp; +#line 905 + +#line 905 + if(nelems == 0) +#line 905 + return NC_NOERR; +#line 905 + +#line 905 + assert(value != NULL); +#line 905 + +#line 905 + for(;;) +#line 905 + { +#line 905 + size_t extent = MIN(remaining, ncp->chunk); +#line 905 + size_t nget = ncx_howmany(varp->type, extent); +#line 905 + +#line 905 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 905 + 0, (void **)&xp); /* cast away const */ +#line 905 + if(lstatus != NC_NOERR) +#line 905 + return lstatus; +#line 905 + +#line 905 + lstatus = ncx_getn_double_double(&xp, nget, value); +#line 905 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 905 + status = lstatus; +#line 905 + +#line 905 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 905 + +#line 905 + remaining -= extent; +#line 905 + if(remaining == 0) +#line 905 + break; /* normal loop exit */ +#line 905 + offset += (off_t)extent; +#line 905 + value += nget; +#line 905 + } +#line 905 + +#line 905 + return status; +#line 905 +} +#line 905 + +static int +#line 906 +getNCvx_double_longlong(const NC3_INFO* ncp, const NC_var *varp, +#line 906 + const size_t *start, size_t nelems, longlong *value) +#line 906 +{ +#line 906 + off_t offset = NC_varoffset(ncp, varp, start); +#line 906 + size_t remaining = varp->xsz * nelems; +#line 906 + int status = NC_NOERR; +#line 906 + const void *xp; +#line 906 + +#line 906 + if(nelems == 0) +#line 906 + return NC_NOERR; +#line 906 + +#line 906 + assert(value != NULL); +#line 906 + +#line 906 + for(;;) +#line 906 + { +#line 906 + size_t extent = MIN(remaining, ncp->chunk); +#line 906 + size_t nget = ncx_howmany(varp->type, extent); +#line 906 + +#line 906 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 906 + 0, (void **)&xp); /* cast away const */ +#line 906 + if(lstatus != NC_NOERR) +#line 906 + return lstatus; +#line 906 + +#line 906 + lstatus = ncx_getn_double_longlong(&xp, nget, value); +#line 906 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 906 + status = lstatus; +#line 906 + +#line 906 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 906 + +#line 906 + remaining -= extent; +#line 906 + if(remaining == 0) +#line 906 + break; /* normal loop exit */ +#line 906 + offset += (off_t)extent; +#line 906 + value += nget; +#line 906 + } +#line 906 + +#line 906 + return status; +#line 906 +} +#line 906 + +static int +#line 907 +getNCvx_double_uint(const NC3_INFO* ncp, const NC_var *varp, +#line 907 + const size_t *start, size_t nelems, uint *value) +#line 907 +{ +#line 907 + off_t offset = NC_varoffset(ncp, varp, start); +#line 907 + size_t remaining = varp->xsz * nelems; +#line 907 + int status = NC_NOERR; +#line 907 + const void *xp; +#line 907 + +#line 907 + if(nelems == 0) +#line 907 + return NC_NOERR; +#line 907 + +#line 907 + assert(value != NULL); +#line 907 + +#line 907 + for(;;) +#line 907 + { +#line 907 + size_t extent = MIN(remaining, ncp->chunk); +#line 907 + size_t nget = ncx_howmany(varp->type, extent); +#line 907 + +#line 907 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 907 + 0, (void **)&xp); /* cast away const */ +#line 907 + if(lstatus != NC_NOERR) +#line 907 + return lstatus; +#line 907 + +#line 907 + lstatus = ncx_getn_double_uint(&xp, nget, value); +#line 907 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 907 + status = lstatus; +#line 907 + +#line 907 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 907 + +#line 907 + remaining -= extent; +#line 907 + if(remaining == 0) +#line 907 + break; /* normal loop exit */ +#line 907 + offset += (off_t)extent; +#line 907 + value += nget; +#line 907 + } +#line 907 + +#line 907 + return status; +#line 907 +} +#line 907 + +static int +#line 908 +getNCvx_double_ulonglong(const NC3_INFO* ncp, const NC_var *varp, +#line 908 + const size_t *start, size_t nelems, ulonglong *value) +#line 908 +{ +#line 908 + off_t offset = NC_varoffset(ncp, varp, start); +#line 908 + size_t remaining = varp->xsz * nelems; +#line 908 + int status = NC_NOERR; +#line 908 + const void *xp; +#line 908 + +#line 908 + if(nelems == 0) +#line 908 + return NC_NOERR; +#line 908 + +#line 908 + assert(value != NULL); +#line 908 + +#line 908 + for(;;) +#line 908 + { +#line 908 + size_t extent = MIN(remaining, ncp->chunk); +#line 908 + size_t nget = ncx_howmany(varp->type, extent); +#line 908 + +#line 908 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 908 + 0, (void **)&xp); /* cast away const */ +#line 908 + if(lstatus != NC_NOERR) +#line 908 + return lstatus; +#line 908 + +#line 908 + lstatus = ncx_getn_double_ulonglong(&xp, nget, value); +#line 908 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 908 + status = lstatus; +#line 908 + +#line 908 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 908 + +#line 908 + remaining -= extent; +#line 908 + if(remaining == 0) +#line 908 + break; /* normal loop exit */ +#line 908 + offset += (off_t)extent; +#line 908 + value += nget; +#line 908 + } +#line 908 + +#line 908 + return status; +#line 908 +} +#line 908 + +static int +#line 909 +getNCvx_double_ushort(const NC3_INFO* ncp, const NC_var *varp, +#line 909 + const size_t *start, size_t nelems, ushort *value) +#line 909 +{ +#line 909 + off_t offset = NC_varoffset(ncp, varp, start); +#line 909 + size_t remaining = varp->xsz * nelems; +#line 909 + int status = NC_NOERR; +#line 909 + const void *xp; +#line 909 + +#line 909 + if(nelems == 0) +#line 909 + return NC_NOERR; +#line 909 + +#line 909 + assert(value != NULL); +#line 909 + +#line 909 + for(;;) +#line 909 + { +#line 909 + size_t extent = MIN(remaining, ncp->chunk); +#line 909 + size_t nget = ncx_howmany(varp->type, extent); +#line 909 + +#line 909 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 909 + 0, (void **)&xp); /* cast away const */ +#line 909 + if(lstatus != NC_NOERR) +#line 909 + return lstatus; +#line 909 + +#line 909 + lstatus = ncx_getn_double_ushort(&xp, nget, value); +#line 909 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 909 + status = lstatus; +#line 909 + +#line 909 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 909 + +#line 909 + remaining -= extent; +#line 909 + if(remaining == 0) +#line 909 + break; /* normal loop exit */ +#line 909 + offset += (off_t)extent; +#line 909 + value += nget; +#line 909 + } +#line 909 + +#line 909 + return status; +#line 909 +} +#line 909 + + +static int +#line 911 +getNCvx_uchar_schar(const NC3_INFO* ncp, const NC_var *varp, +#line 911 + const size_t *start, size_t nelems, schar *value) +#line 911 +{ +#line 911 + off_t offset = NC_varoffset(ncp, varp, start); +#line 911 + size_t remaining = varp->xsz * nelems; +#line 911 + int status = NC_NOERR; +#line 911 + const void *xp; +#line 911 + +#line 911 + if(nelems == 0) +#line 911 + return NC_NOERR; +#line 911 + +#line 911 + assert(value != NULL); +#line 911 + +#line 911 + for(;;) +#line 911 + { +#line 911 + size_t extent = MIN(remaining, ncp->chunk); +#line 911 + size_t nget = ncx_howmany(varp->type, extent); +#line 911 + +#line 911 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 911 + 0, (void **)&xp); /* cast away const */ +#line 911 + if(lstatus != NC_NOERR) +#line 911 + return lstatus; +#line 911 + +#line 911 + lstatus = ncx_getn_uchar_schar(&xp, nget, value); +#line 911 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 911 + status = lstatus; +#line 911 + +#line 911 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 911 + +#line 911 + remaining -= extent; +#line 911 + if(remaining == 0) +#line 911 + break; /* normal loop exit */ +#line 911 + offset += (off_t)extent; +#line 911 + value += nget; +#line 911 + } +#line 911 + +#line 911 + return status; +#line 911 +} +#line 911 + +static int +#line 912 +getNCvx_uchar_uchar(const NC3_INFO* ncp, const NC_var *varp, +#line 912 + const size_t *start, size_t nelems, uchar *value) +#line 912 +{ +#line 912 + off_t offset = NC_varoffset(ncp, varp, start); +#line 912 + size_t remaining = varp->xsz * nelems; +#line 912 + int status = NC_NOERR; +#line 912 + const void *xp; +#line 912 + +#line 912 + if(nelems == 0) +#line 912 + return NC_NOERR; +#line 912 + +#line 912 + assert(value != NULL); +#line 912 + +#line 912 + for(;;) +#line 912 + { +#line 912 + size_t extent = MIN(remaining, ncp->chunk); +#line 912 + size_t nget = ncx_howmany(varp->type, extent); +#line 912 + +#line 912 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 912 + 0, (void **)&xp); /* cast away const */ +#line 912 + if(lstatus != NC_NOERR) +#line 912 + return lstatus; +#line 912 + +#line 912 + lstatus = ncx_getn_uchar_uchar(&xp, nget, value); +#line 912 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 912 + status = lstatus; +#line 912 + +#line 912 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 912 + +#line 912 + remaining -= extent; +#line 912 + if(remaining == 0) +#line 912 + break; /* normal loop exit */ +#line 912 + offset += (off_t)extent; +#line 912 + value += nget; +#line 912 + } +#line 912 + +#line 912 + return status; +#line 912 +} +#line 912 + +static int +#line 913 +getNCvx_uchar_short(const NC3_INFO* ncp, const NC_var *varp, +#line 913 + const size_t *start, size_t nelems, short *value) +#line 913 +{ +#line 913 + off_t offset = NC_varoffset(ncp, varp, start); +#line 913 + size_t remaining = varp->xsz * nelems; +#line 913 + int status = NC_NOERR; +#line 913 + const void *xp; +#line 913 + +#line 913 + if(nelems == 0) +#line 913 + return NC_NOERR; +#line 913 + +#line 913 + assert(value != NULL); +#line 913 + +#line 913 + for(;;) +#line 913 + { +#line 913 + size_t extent = MIN(remaining, ncp->chunk); +#line 913 + size_t nget = ncx_howmany(varp->type, extent); +#line 913 + +#line 913 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 913 + 0, (void **)&xp); /* cast away const */ +#line 913 + if(lstatus != NC_NOERR) +#line 913 + return lstatus; +#line 913 + +#line 913 + lstatus = ncx_getn_uchar_short(&xp, nget, value); +#line 913 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 913 + status = lstatus; +#line 913 + +#line 913 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 913 + +#line 913 + remaining -= extent; +#line 913 + if(remaining == 0) +#line 913 + break; /* normal loop exit */ +#line 913 + offset += (off_t)extent; +#line 913 + value += nget; +#line 913 + } +#line 913 + +#line 913 + return status; +#line 913 +} +#line 913 + +static int +#line 914 +getNCvx_uchar_int(const NC3_INFO* ncp, const NC_var *varp, +#line 914 + const size_t *start, size_t nelems, int *value) +#line 914 +{ +#line 914 + off_t offset = NC_varoffset(ncp, varp, start); +#line 914 + size_t remaining = varp->xsz * nelems; +#line 914 + int status = NC_NOERR; +#line 914 + const void *xp; +#line 914 + +#line 914 + if(nelems == 0) +#line 914 + return NC_NOERR; +#line 914 + +#line 914 + assert(value != NULL); +#line 914 + +#line 914 + for(;;) +#line 914 + { +#line 914 + size_t extent = MIN(remaining, ncp->chunk); +#line 914 + size_t nget = ncx_howmany(varp->type, extent); +#line 914 + +#line 914 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 914 + 0, (void **)&xp); /* cast away const */ +#line 914 + if(lstatus != NC_NOERR) +#line 914 + return lstatus; +#line 914 + +#line 914 + lstatus = ncx_getn_uchar_int(&xp, nget, value); +#line 914 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 914 + status = lstatus; +#line 914 + +#line 914 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 914 + +#line 914 + remaining -= extent; +#line 914 + if(remaining == 0) +#line 914 + break; /* normal loop exit */ +#line 914 + offset += (off_t)extent; +#line 914 + value += nget; +#line 914 + } +#line 914 + +#line 914 + return status; +#line 914 +} +#line 914 + +static int +#line 915 +getNCvx_uchar_float(const NC3_INFO* ncp, const NC_var *varp, +#line 915 + const size_t *start, size_t nelems, float *value) +#line 915 +{ +#line 915 + off_t offset = NC_varoffset(ncp, varp, start); +#line 915 + size_t remaining = varp->xsz * nelems; +#line 915 + int status = NC_NOERR; +#line 915 + const void *xp; +#line 915 + +#line 915 + if(nelems == 0) +#line 915 + return NC_NOERR; +#line 915 + +#line 915 + assert(value != NULL); +#line 915 + +#line 915 + for(;;) +#line 915 + { +#line 915 + size_t extent = MIN(remaining, ncp->chunk); +#line 915 + size_t nget = ncx_howmany(varp->type, extent); +#line 915 + +#line 915 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 915 + 0, (void **)&xp); /* cast away const */ +#line 915 + if(lstatus != NC_NOERR) +#line 915 + return lstatus; +#line 915 + +#line 915 + lstatus = ncx_getn_uchar_float(&xp, nget, value); +#line 915 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 915 + status = lstatus; +#line 915 + +#line 915 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 915 + +#line 915 + remaining -= extent; +#line 915 + if(remaining == 0) +#line 915 + break; /* normal loop exit */ +#line 915 + offset += (off_t)extent; +#line 915 + value += nget; +#line 915 + } +#line 915 + +#line 915 + return status; +#line 915 +} +#line 915 + +static int +#line 916 +getNCvx_uchar_double(const NC3_INFO* ncp, const NC_var *varp, +#line 916 + const size_t *start, size_t nelems, double *value) +#line 916 +{ +#line 916 + off_t offset = NC_varoffset(ncp, varp, start); +#line 916 + size_t remaining = varp->xsz * nelems; +#line 916 + int status = NC_NOERR; +#line 916 + const void *xp; +#line 916 + +#line 916 + if(nelems == 0) +#line 916 + return NC_NOERR; +#line 916 + +#line 916 + assert(value != NULL); +#line 916 + +#line 916 + for(;;) +#line 916 + { +#line 916 + size_t extent = MIN(remaining, ncp->chunk); +#line 916 + size_t nget = ncx_howmany(varp->type, extent); +#line 916 + +#line 916 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 916 + 0, (void **)&xp); /* cast away const */ +#line 916 + if(lstatus != NC_NOERR) +#line 916 + return lstatus; +#line 916 + +#line 916 + lstatus = ncx_getn_uchar_double(&xp, nget, value); +#line 916 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 916 + status = lstatus; +#line 916 + +#line 916 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 916 + +#line 916 + remaining -= extent; +#line 916 + if(remaining == 0) +#line 916 + break; /* normal loop exit */ +#line 916 + offset += (off_t)extent; +#line 916 + value += nget; +#line 916 + } +#line 916 + +#line 916 + return status; +#line 916 +} +#line 916 + +static int +#line 917 +getNCvx_uchar_longlong(const NC3_INFO* ncp, const NC_var *varp, +#line 917 + const size_t *start, size_t nelems, longlong *value) +#line 917 +{ +#line 917 + off_t offset = NC_varoffset(ncp, varp, start); +#line 917 + size_t remaining = varp->xsz * nelems; +#line 917 + int status = NC_NOERR; +#line 917 + const void *xp; +#line 917 + +#line 917 + if(nelems == 0) +#line 917 + return NC_NOERR; +#line 917 + +#line 917 + assert(value != NULL); +#line 917 + +#line 917 + for(;;) +#line 917 + { +#line 917 + size_t extent = MIN(remaining, ncp->chunk); +#line 917 + size_t nget = ncx_howmany(varp->type, extent); +#line 917 + +#line 917 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 917 + 0, (void **)&xp); /* cast away const */ +#line 917 + if(lstatus != NC_NOERR) +#line 917 + return lstatus; +#line 917 + +#line 917 + lstatus = ncx_getn_uchar_longlong(&xp, nget, value); +#line 917 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 917 + status = lstatus; +#line 917 + +#line 917 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 917 + +#line 917 + remaining -= extent; +#line 917 + if(remaining == 0) +#line 917 + break; /* normal loop exit */ +#line 917 + offset += (off_t)extent; +#line 917 + value += nget; +#line 917 + } +#line 917 + +#line 917 + return status; +#line 917 +} +#line 917 + +static int +#line 918 +getNCvx_uchar_uint(const NC3_INFO* ncp, const NC_var *varp, +#line 918 + const size_t *start, size_t nelems, uint *value) +#line 918 +{ +#line 918 + off_t offset = NC_varoffset(ncp, varp, start); +#line 918 + size_t remaining = varp->xsz * nelems; +#line 918 + int status = NC_NOERR; +#line 918 + const void *xp; +#line 918 + +#line 918 + if(nelems == 0) +#line 918 + return NC_NOERR; +#line 918 + +#line 918 + assert(value != NULL); +#line 918 + +#line 918 + for(;;) +#line 918 + { +#line 918 + size_t extent = MIN(remaining, ncp->chunk); +#line 918 + size_t nget = ncx_howmany(varp->type, extent); +#line 918 + +#line 918 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 918 + 0, (void **)&xp); /* cast away const */ +#line 918 + if(lstatus != NC_NOERR) +#line 918 + return lstatus; +#line 918 + +#line 918 + lstatus = ncx_getn_uchar_uint(&xp, nget, value); +#line 918 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 918 + status = lstatus; +#line 918 + +#line 918 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 918 + +#line 918 + remaining -= extent; +#line 918 + if(remaining == 0) +#line 918 + break; /* normal loop exit */ +#line 918 + offset += (off_t)extent; +#line 918 + value += nget; +#line 918 + } +#line 918 + +#line 918 + return status; +#line 918 +} +#line 918 + +static int +#line 919 +getNCvx_uchar_ulonglong(const NC3_INFO* ncp, const NC_var *varp, +#line 919 + const size_t *start, size_t nelems, ulonglong *value) +#line 919 +{ +#line 919 + off_t offset = NC_varoffset(ncp, varp, start); +#line 919 + size_t remaining = varp->xsz * nelems; +#line 919 + int status = NC_NOERR; +#line 919 + const void *xp; +#line 919 + +#line 919 + if(nelems == 0) +#line 919 + return NC_NOERR; +#line 919 + +#line 919 + assert(value != NULL); +#line 919 + +#line 919 + for(;;) +#line 919 + { +#line 919 + size_t extent = MIN(remaining, ncp->chunk); +#line 919 + size_t nget = ncx_howmany(varp->type, extent); +#line 919 + +#line 919 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 919 + 0, (void **)&xp); /* cast away const */ +#line 919 + if(lstatus != NC_NOERR) +#line 919 + return lstatus; +#line 919 + +#line 919 + lstatus = ncx_getn_uchar_ulonglong(&xp, nget, value); +#line 919 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 919 + status = lstatus; +#line 919 + +#line 919 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 919 + +#line 919 + remaining -= extent; +#line 919 + if(remaining == 0) +#line 919 + break; /* normal loop exit */ +#line 919 + offset += (off_t)extent; +#line 919 + value += nget; +#line 919 + } +#line 919 + +#line 919 + return status; +#line 919 +} +#line 919 + +static int +#line 920 +getNCvx_uchar_ushort(const NC3_INFO* ncp, const NC_var *varp, +#line 920 + const size_t *start, size_t nelems, ushort *value) +#line 920 +{ +#line 920 + off_t offset = NC_varoffset(ncp, varp, start); +#line 920 + size_t remaining = varp->xsz * nelems; +#line 920 + int status = NC_NOERR; +#line 920 + const void *xp; +#line 920 + +#line 920 + if(nelems == 0) +#line 920 + return NC_NOERR; +#line 920 + +#line 920 + assert(value != NULL); +#line 920 + +#line 920 + for(;;) +#line 920 + { +#line 920 + size_t extent = MIN(remaining, ncp->chunk); +#line 920 + size_t nget = ncx_howmany(varp->type, extent); +#line 920 + +#line 920 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 920 + 0, (void **)&xp); /* cast away const */ +#line 920 + if(lstatus != NC_NOERR) +#line 920 + return lstatus; +#line 920 + +#line 920 + lstatus = ncx_getn_uchar_ushort(&xp, nget, value); +#line 920 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 920 + status = lstatus; +#line 920 + +#line 920 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 920 + +#line 920 + remaining -= extent; +#line 920 + if(remaining == 0) +#line 920 + break; /* normal loop exit */ +#line 920 + offset += (off_t)extent; +#line 920 + value += nget; +#line 920 + } +#line 920 + +#line 920 + return status; +#line 920 +} +#line 920 + + +static int +#line 922 +getNCvx_ushort_schar(const NC3_INFO* ncp, const NC_var *varp, +#line 922 + const size_t *start, size_t nelems, schar *value) +#line 922 +{ +#line 922 + off_t offset = NC_varoffset(ncp, varp, start); +#line 922 + size_t remaining = varp->xsz * nelems; +#line 922 + int status = NC_NOERR; +#line 922 + const void *xp; +#line 922 + +#line 922 + if(nelems == 0) +#line 922 + return NC_NOERR; +#line 922 + +#line 922 + assert(value != NULL); +#line 922 + +#line 922 + for(;;) +#line 922 + { +#line 922 + size_t extent = MIN(remaining, ncp->chunk); +#line 922 + size_t nget = ncx_howmany(varp->type, extent); +#line 922 + +#line 922 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 922 + 0, (void **)&xp); /* cast away const */ +#line 922 + if(lstatus != NC_NOERR) +#line 922 + return lstatus; +#line 922 + +#line 922 + lstatus = ncx_getn_ushort_schar(&xp, nget, value); +#line 922 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 922 + status = lstatus; +#line 922 + +#line 922 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 922 + +#line 922 + remaining -= extent; +#line 922 + if(remaining == 0) +#line 922 + break; /* normal loop exit */ +#line 922 + offset += (off_t)extent; +#line 922 + value += nget; +#line 922 + } +#line 922 + +#line 922 + return status; +#line 922 +} +#line 922 + +static int +#line 923 +getNCvx_ushort_uchar(const NC3_INFO* ncp, const NC_var *varp, +#line 923 + const size_t *start, size_t nelems, uchar *value) +#line 923 +{ +#line 923 + off_t offset = NC_varoffset(ncp, varp, start); +#line 923 + size_t remaining = varp->xsz * nelems; +#line 923 + int status = NC_NOERR; +#line 923 + const void *xp; +#line 923 + +#line 923 + if(nelems == 0) +#line 923 + return NC_NOERR; +#line 923 + +#line 923 + assert(value != NULL); +#line 923 + +#line 923 + for(;;) +#line 923 + { +#line 923 + size_t extent = MIN(remaining, ncp->chunk); +#line 923 + size_t nget = ncx_howmany(varp->type, extent); +#line 923 + +#line 923 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 923 + 0, (void **)&xp); /* cast away const */ +#line 923 + if(lstatus != NC_NOERR) +#line 923 + return lstatus; +#line 923 + +#line 923 + lstatus = ncx_getn_ushort_uchar(&xp, nget, value); +#line 923 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 923 + status = lstatus; +#line 923 + +#line 923 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 923 + +#line 923 + remaining -= extent; +#line 923 + if(remaining == 0) +#line 923 + break; /* normal loop exit */ +#line 923 + offset += (off_t)extent; +#line 923 + value += nget; +#line 923 + } +#line 923 + +#line 923 + return status; +#line 923 +} +#line 923 + +static int +#line 924 +getNCvx_ushort_short(const NC3_INFO* ncp, const NC_var *varp, +#line 924 + const size_t *start, size_t nelems, short *value) +#line 924 +{ +#line 924 + off_t offset = NC_varoffset(ncp, varp, start); +#line 924 + size_t remaining = varp->xsz * nelems; +#line 924 + int status = NC_NOERR; +#line 924 + const void *xp; +#line 924 + +#line 924 + if(nelems == 0) +#line 924 + return NC_NOERR; +#line 924 + +#line 924 + assert(value != NULL); +#line 924 + +#line 924 + for(;;) +#line 924 + { +#line 924 + size_t extent = MIN(remaining, ncp->chunk); +#line 924 + size_t nget = ncx_howmany(varp->type, extent); +#line 924 + +#line 924 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 924 + 0, (void **)&xp); /* cast away const */ +#line 924 + if(lstatus != NC_NOERR) +#line 924 + return lstatus; +#line 924 + +#line 924 + lstatus = ncx_getn_ushort_short(&xp, nget, value); +#line 924 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 924 + status = lstatus; +#line 924 + +#line 924 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 924 + +#line 924 + remaining -= extent; +#line 924 + if(remaining == 0) +#line 924 + break; /* normal loop exit */ +#line 924 + offset += (off_t)extent; +#line 924 + value += nget; +#line 924 + } +#line 924 + +#line 924 + return status; +#line 924 +} +#line 924 + +static int +#line 925 +getNCvx_ushort_int(const NC3_INFO* ncp, const NC_var *varp, +#line 925 + const size_t *start, size_t nelems, int *value) +#line 925 +{ +#line 925 + off_t offset = NC_varoffset(ncp, varp, start); +#line 925 + size_t remaining = varp->xsz * nelems; +#line 925 + int status = NC_NOERR; +#line 925 + const void *xp; +#line 925 + +#line 925 + if(nelems == 0) +#line 925 + return NC_NOERR; +#line 925 + +#line 925 + assert(value != NULL); +#line 925 + +#line 925 + for(;;) +#line 925 + { +#line 925 + size_t extent = MIN(remaining, ncp->chunk); +#line 925 + size_t nget = ncx_howmany(varp->type, extent); +#line 925 + +#line 925 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 925 + 0, (void **)&xp); /* cast away const */ +#line 925 + if(lstatus != NC_NOERR) +#line 925 + return lstatus; +#line 925 + +#line 925 + lstatus = ncx_getn_ushort_int(&xp, nget, value); +#line 925 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 925 + status = lstatus; +#line 925 + +#line 925 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 925 + +#line 925 + remaining -= extent; +#line 925 + if(remaining == 0) +#line 925 + break; /* normal loop exit */ +#line 925 + offset += (off_t)extent; +#line 925 + value += nget; +#line 925 + } +#line 925 + +#line 925 + return status; +#line 925 +} +#line 925 + +static int +#line 926 +getNCvx_ushort_float(const NC3_INFO* ncp, const NC_var *varp, +#line 926 + const size_t *start, size_t nelems, float *value) +#line 926 +{ +#line 926 + off_t offset = NC_varoffset(ncp, varp, start); +#line 926 + size_t remaining = varp->xsz * nelems; +#line 926 + int status = NC_NOERR; +#line 926 + const void *xp; +#line 926 + +#line 926 + if(nelems == 0) +#line 926 + return NC_NOERR; +#line 926 + +#line 926 + assert(value != NULL); +#line 926 + +#line 926 + for(;;) +#line 926 + { +#line 926 + size_t extent = MIN(remaining, ncp->chunk); +#line 926 + size_t nget = ncx_howmany(varp->type, extent); +#line 926 + +#line 926 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 926 + 0, (void **)&xp); /* cast away const */ +#line 926 + if(lstatus != NC_NOERR) +#line 926 + return lstatus; +#line 926 + +#line 926 + lstatus = ncx_getn_ushort_float(&xp, nget, value); +#line 926 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 926 + status = lstatus; +#line 926 + +#line 926 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 926 + +#line 926 + remaining -= extent; +#line 926 + if(remaining == 0) +#line 926 + break; /* normal loop exit */ +#line 926 + offset += (off_t)extent; +#line 926 + value += nget; +#line 926 + } +#line 926 + +#line 926 + return status; +#line 926 +} +#line 926 + +static int +#line 927 +getNCvx_ushort_double(const NC3_INFO* ncp, const NC_var *varp, +#line 927 + const size_t *start, size_t nelems, double *value) +#line 927 +{ +#line 927 + off_t offset = NC_varoffset(ncp, varp, start); +#line 927 + size_t remaining = varp->xsz * nelems; +#line 927 + int status = NC_NOERR; +#line 927 + const void *xp; +#line 927 + +#line 927 + if(nelems == 0) +#line 927 + return NC_NOERR; +#line 927 + +#line 927 + assert(value != NULL); +#line 927 + +#line 927 + for(;;) +#line 927 + { +#line 927 + size_t extent = MIN(remaining, ncp->chunk); +#line 927 + size_t nget = ncx_howmany(varp->type, extent); +#line 927 + +#line 927 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 927 + 0, (void **)&xp); /* cast away const */ +#line 927 + if(lstatus != NC_NOERR) +#line 927 + return lstatus; +#line 927 + +#line 927 + lstatus = ncx_getn_ushort_double(&xp, nget, value); +#line 927 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 927 + status = lstatus; +#line 927 + +#line 927 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 927 + +#line 927 + remaining -= extent; +#line 927 + if(remaining == 0) +#line 927 + break; /* normal loop exit */ +#line 927 + offset += (off_t)extent; +#line 927 + value += nget; +#line 927 + } +#line 927 + +#line 927 + return status; +#line 927 +} +#line 927 + +static int +#line 928 +getNCvx_ushort_longlong(const NC3_INFO* ncp, const NC_var *varp, +#line 928 + const size_t *start, size_t nelems, longlong *value) +#line 928 +{ +#line 928 + off_t offset = NC_varoffset(ncp, varp, start); +#line 928 + size_t remaining = varp->xsz * nelems; +#line 928 + int status = NC_NOERR; +#line 928 + const void *xp; +#line 928 + +#line 928 + if(nelems == 0) +#line 928 + return NC_NOERR; +#line 928 + +#line 928 + assert(value != NULL); +#line 928 + +#line 928 + for(;;) +#line 928 + { +#line 928 + size_t extent = MIN(remaining, ncp->chunk); +#line 928 + size_t nget = ncx_howmany(varp->type, extent); +#line 928 + +#line 928 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 928 + 0, (void **)&xp); /* cast away const */ +#line 928 + if(lstatus != NC_NOERR) +#line 928 + return lstatus; +#line 928 + +#line 928 + lstatus = ncx_getn_ushort_longlong(&xp, nget, value); +#line 928 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 928 + status = lstatus; +#line 928 + +#line 928 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 928 + +#line 928 + remaining -= extent; +#line 928 + if(remaining == 0) +#line 928 + break; /* normal loop exit */ +#line 928 + offset += (off_t)extent; +#line 928 + value += nget; +#line 928 + } +#line 928 + +#line 928 + return status; +#line 928 +} +#line 928 + +static int +#line 929 +getNCvx_ushort_uint(const NC3_INFO* ncp, const NC_var *varp, +#line 929 + const size_t *start, size_t nelems, uint *value) +#line 929 +{ +#line 929 + off_t offset = NC_varoffset(ncp, varp, start); +#line 929 + size_t remaining = varp->xsz * nelems; +#line 929 + int status = NC_NOERR; +#line 929 + const void *xp; +#line 929 + +#line 929 + if(nelems == 0) +#line 929 + return NC_NOERR; +#line 929 + +#line 929 + assert(value != NULL); +#line 929 + +#line 929 + for(;;) +#line 929 + { +#line 929 + size_t extent = MIN(remaining, ncp->chunk); +#line 929 + size_t nget = ncx_howmany(varp->type, extent); +#line 929 + +#line 929 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 929 + 0, (void **)&xp); /* cast away const */ +#line 929 + if(lstatus != NC_NOERR) +#line 929 + return lstatus; +#line 929 + +#line 929 + lstatus = ncx_getn_ushort_uint(&xp, nget, value); +#line 929 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 929 + status = lstatus; +#line 929 + +#line 929 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 929 + +#line 929 + remaining -= extent; +#line 929 + if(remaining == 0) +#line 929 + break; /* normal loop exit */ +#line 929 + offset += (off_t)extent; +#line 929 + value += nget; +#line 929 + } +#line 929 + +#line 929 + return status; +#line 929 +} +#line 929 + +static int +#line 930 +getNCvx_ushort_ulonglong(const NC3_INFO* ncp, const NC_var *varp, +#line 930 + const size_t *start, size_t nelems, ulonglong *value) +#line 930 +{ +#line 930 + off_t offset = NC_varoffset(ncp, varp, start); +#line 930 + size_t remaining = varp->xsz * nelems; +#line 930 + int status = NC_NOERR; +#line 930 + const void *xp; +#line 930 + +#line 930 + if(nelems == 0) +#line 930 + return NC_NOERR; +#line 930 + +#line 930 + assert(value != NULL); +#line 930 + +#line 930 + for(;;) +#line 930 + { +#line 930 + size_t extent = MIN(remaining, ncp->chunk); +#line 930 + size_t nget = ncx_howmany(varp->type, extent); +#line 930 + +#line 930 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 930 + 0, (void **)&xp); /* cast away const */ +#line 930 + if(lstatus != NC_NOERR) +#line 930 + return lstatus; +#line 930 + +#line 930 + lstatus = ncx_getn_ushort_ulonglong(&xp, nget, value); +#line 930 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 930 + status = lstatus; +#line 930 + +#line 930 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 930 + +#line 930 + remaining -= extent; +#line 930 + if(remaining == 0) +#line 930 + break; /* normal loop exit */ +#line 930 + offset += (off_t)extent; +#line 930 + value += nget; +#line 930 + } +#line 930 + +#line 930 + return status; +#line 930 +} +#line 930 + +static int +#line 931 +getNCvx_ushort_ushort(const NC3_INFO* ncp, const NC_var *varp, +#line 931 + const size_t *start, size_t nelems, ushort *value) +#line 931 +{ +#line 931 + off_t offset = NC_varoffset(ncp, varp, start); +#line 931 + size_t remaining = varp->xsz * nelems; +#line 931 + int status = NC_NOERR; +#line 931 + const void *xp; +#line 931 + +#line 931 + if(nelems == 0) +#line 931 + return NC_NOERR; +#line 931 + +#line 931 + assert(value != NULL); +#line 931 + +#line 931 + for(;;) +#line 931 + { +#line 931 + size_t extent = MIN(remaining, ncp->chunk); +#line 931 + size_t nget = ncx_howmany(varp->type, extent); +#line 931 + +#line 931 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 931 + 0, (void **)&xp); /* cast away const */ +#line 931 + if(lstatus != NC_NOERR) +#line 931 + return lstatus; +#line 931 + +#line 931 + lstatus = ncx_getn_ushort_ushort(&xp, nget, value); +#line 931 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 931 + status = lstatus; +#line 931 + +#line 931 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 931 + +#line 931 + remaining -= extent; +#line 931 + if(remaining == 0) +#line 931 + break; /* normal loop exit */ +#line 931 + offset += (off_t)extent; +#line 931 + value += nget; +#line 931 + } +#line 931 + +#line 931 + return status; +#line 931 +} +#line 931 + + +static int +#line 933 +getNCvx_uint_schar(const NC3_INFO* ncp, const NC_var *varp, +#line 933 + const size_t *start, size_t nelems, schar *value) +#line 933 +{ +#line 933 + off_t offset = NC_varoffset(ncp, varp, start); +#line 933 + size_t remaining = varp->xsz * nelems; +#line 933 + int status = NC_NOERR; +#line 933 + const void *xp; +#line 933 + +#line 933 + if(nelems == 0) +#line 933 + return NC_NOERR; +#line 933 + +#line 933 + assert(value != NULL); +#line 933 + +#line 933 + for(;;) +#line 933 + { +#line 933 + size_t extent = MIN(remaining, ncp->chunk); +#line 933 + size_t nget = ncx_howmany(varp->type, extent); +#line 933 + +#line 933 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 933 + 0, (void **)&xp); /* cast away const */ +#line 933 + if(lstatus != NC_NOERR) +#line 933 + return lstatus; +#line 933 + +#line 933 + lstatus = ncx_getn_uint_schar(&xp, nget, value); +#line 933 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 933 + status = lstatus; +#line 933 + +#line 933 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 933 + +#line 933 + remaining -= extent; +#line 933 + if(remaining == 0) +#line 933 + break; /* normal loop exit */ +#line 933 + offset += (off_t)extent; +#line 933 + value += nget; +#line 933 + } +#line 933 + +#line 933 + return status; +#line 933 +} +#line 933 + +static int +#line 934 +getNCvx_uint_uchar(const NC3_INFO* ncp, const NC_var *varp, +#line 934 + const size_t *start, size_t nelems, uchar *value) +#line 934 +{ +#line 934 + off_t offset = NC_varoffset(ncp, varp, start); +#line 934 + size_t remaining = varp->xsz * nelems; +#line 934 + int status = NC_NOERR; +#line 934 + const void *xp; +#line 934 + +#line 934 + if(nelems == 0) +#line 934 + return NC_NOERR; +#line 934 + +#line 934 + assert(value != NULL); +#line 934 + +#line 934 + for(;;) +#line 934 + { +#line 934 + size_t extent = MIN(remaining, ncp->chunk); +#line 934 + size_t nget = ncx_howmany(varp->type, extent); +#line 934 + +#line 934 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 934 + 0, (void **)&xp); /* cast away const */ +#line 934 + if(lstatus != NC_NOERR) +#line 934 + return lstatus; +#line 934 + +#line 934 + lstatus = ncx_getn_uint_uchar(&xp, nget, value); +#line 934 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 934 + status = lstatus; +#line 934 + +#line 934 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 934 + +#line 934 + remaining -= extent; +#line 934 + if(remaining == 0) +#line 934 + break; /* normal loop exit */ +#line 934 + offset += (off_t)extent; +#line 934 + value += nget; +#line 934 + } +#line 934 + +#line 934 + return status; +#line 934 +} +#line 934 + +static int +#line 935 +getNCvx_uint_short(const NC3_INFO* ncp, const NC_var *varp, +#line 935 + const size_t *start, size_t nelems, short *value) +#line 935 +{ +#line 935 + off_t offset = NC_varoffset(ncp, varp, start); +#line 935 + size_t remaining = varp->xsz * nelems; +#line 935 + int status = NC_NOERR; +#line 935 + const void *xp; +#line 935 + +#line 935 + if(nelems == 0) +#line 935 + return NC_NOERR; +#line 935 + +#line 935 + assert(value != NULL); +#line 935 + +#line 935 + for(;;) +#line 935 + { +#line 935 + size_t extent = MIN(remaining, ncp->chunk); +#line 935 + size_t nget = ncx_howmany(varp->type, extent); +#line 935 + +#line 935 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 935 + 0, (void **)&xp); /* cast away const */ +#line 935 + if(lstatus != NC_NOERR) +#line 935 + return lstatus; +#line 935 + +#line 935 + lstatus = ncx_getn_uint_short(&xp, nget, value); +#line 935 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 935 + status = lstatus; +#line 935 + +#line 935 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 935 + +#line 935 + remaining -= extent; +#line 935 + if(remaining == 0) +#line 935 + break; /* normal loop exit */ +#line 935 + offset += (off_t)extent; +#line 935 + value += nget; +#line 935 + } +#line 935 + +#line 935 + return status; +#line 935 +} +#line 935 + +static int +#line 936 +getNCvx_uint_int(const NC3_INFO* ncp, const NC_var *varp, +#line 936 + const size_t *start, size_t nelems, int *value) +#line 936 +{ +#line 936 + off_t offset = NC_varoffset(ncp, varp, start); +#line 936 + size_t remaining = varp->xsz * nelems; +#line 936 + int status = NC_NOERR; +#line 936 + const void *xp; +#line 936 + +#line 936 + if(nelems == 0) +#line 936 + return NC_NOERR; +#line 936 + +#line 936 + assert(value != NULL); +#line 936 + +#line 936 + for(;;) +#line 936 + { +#line 936 + size_t extent = MIN(remaining, ncp->chunk); +#line 936 + size_t nget = ncx_howmany(varp->type, extent); +#line 936 + +#line 936 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 936 + 0, (void **)&xp); /* cast away const */ +#line 936 + if(lstatus != NC_NOERR) +#line 936 + return lstatus; +#line 936 + +#line 936 + lstatus = ncx_getn_uint_int(&xp, nget, value); +#line 936 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 936 + status = lstatus; +#line 936 + +#line 936 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 936 + +#line 936 + remaining -= extent; +#line 936 + if(remaining == 0) +#line 936 + break; /* normal loop exit */ +#line 936 + offset += (off_t)extent; +#line 936 + value += nget; +#line 936 + } +#line 936 + +#line 936 + return status; +#line 936 +} +#line 936 + +static int +#line 937 +getNCvx_uint_float(const NC3_INFO* ncp, const NC_var *varp, +#line 937 + const size_t *start, size_t nelems, float *value) +#line 937 +{ +#line 937 + off_t offset = NC_varoffset(ncp, varp, start); +#line 937 + size_t remaining = varp->xsz * nelems; +#line 937 + int status = NC_NOERR; +#line 937 + const void *xp; +#line 937 + +#line 937 + if(nelems == 0) +#line 937 + return NC_NOERR; +#line 937 + +#line 937 + assert(value != NULL); +#line 937 + +#line 937 + for(;;) +#line 937 + { +#line 937 + size_t extent = MIN(remaining, ncp->chunk); +#line 937 + size_t nget = ncx_howmany(varp->type, extent); +#line 937 + +#line 937 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 937 + 0, (void **)&xp); /* cast away const */ +#line 937 + if(lstatus != NC_NOERR) +#line 937 + return lstatus; +#line 937 + +#line 937 + lstatus = ncx_getn_uint_float(&xp, nget, value); +#line 937 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 937 + status = lstatus; +#line 937 + +#line 937 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 937 + +#line 937 + remaining -= extent; +#line 937 + if(remaining == 0) +#line 937 + break; /* normal loop exit */ +#line 937 + offset += (off_t)extent; +#line 937 + value += nget; +#line 937 + } +#line 937 + +#line 937 + return status; +#line 937 +} +#line 937 + +static int +#line 938 +getNCvx_uint_double(const NC3_INFO* ncp, const NC_var *varp, +#line 938 + const size_t *start, size_t nelems, double *value) +#line 938 +{ +#line 938 + off_t offset = NC_varoffset(ncp, varp, start); +#line 938 + size_t remaining = varp->xsz * nelems; +#line 938 + int status = NC_NOERR; +#line 938 + const void *xp; +#line 938 + +#line 938 + if(nelems == 0) +#line 938 + return NC_NOERR; +#line 938 + +#line 938 + assert(value != NULL); +#line 938 + +#line 938 + for(;;) +#line 938 + { +#line 938 + size_t extent = MIN(remaining, ncp->chunk); +#line 938 + size_t nget = ncx_howmany(varp->type, extent); +#line 938 + +#line 938 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 938 + 0, (void **)&xp); /* cast away const */ +#line 938 + if(lstatus != NC_NOERR) +#line 938 + return lstatus; +#line 938 + +#line 938 + lstatus = ncx_getn_uint_double(&xp, nget, value); +#line 938 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 938 + status = lstatus; +#line 938 + +#line 938 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 938 + +#line 938 + remaining -= extent; +#line 938 + if(remaining == 0) +#line 938 + break; /* normal loop exit */ +#line 938 + offset += (off_t)extent; +#line 938 + value += nget; +#line 938 + } +#line 938 + +#line 938 + return status; +#line 938 +} +#line 938 + +static int +#line 939 +getNCvx_uint_longlong(const NC3_INFO* ncp, const NC_var *varp, +#line 939 + const size_t *start, size_t nelems, longlong *value) +#line 939 +{ +#line 939 + off_t offset = NC_varoffset(ncp, varp, start); +#line 939 + size_t remaining = varp->xsz * nelems; +#line 939 + int status = NC_NOERR; +#line 939 + const void *xp; +#line 939 + +#line 939 + if(nelems == 0) +#line 939 + return NC_NOERR; +#line 939 + +#line 939 + assert(value != NULL); +#line 939 + +#line 939 + for(;;) +#line 939 + { +#line 939 + size_t extent = MIN(remaining, ncp->chunk); +#line 939 + size_t nget = ncx_howmany(varp->type, extent); +#line 939 + +#line 939 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 939 + 0, (void **)&xp); /* cast away const */ +#line 939 + if(lstatus != NC_NOERR) +#line 939 + return lstatus; +#line 939 + +#line 939 + lstatus = ncx_getn_uint_longlong(&xp, nget, value); +#line 939 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 939 + status = lstatus; +#line 939 + +#line 939 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 939 + +#line 939 + remaining -= extent; +#line 939 + if(remaining == 0) +#line 939 + break; /* normal loop exit */ +#line 939 + offset += (off_t)extent; +#line 939 + value += nget; +#line 939 + } +#line 939 + +#line 939 + return status; +#line 939 +} +#line 939 + +static int +#line 940 +getNCvx_uint_uint(const NC3_INFO* ncp, const NC_var *varp, +#line 940 + const size_t *start, size_t nelems, uint *value) +#line 940 +{ +#line 940 + off_t offset = NC_varoffset(ncp, varp, start); +#line 940 + size_t remaining = varp->xsz * nelems; +#line 940 + int status = NC_NOERR; +#line 940 + const void *xp; +#line 940 + +#line 940 + if(nelems == 0) +#line 940 + return NC_NOERR; +#line 940 + +#line 940 + assert(value != NULL); +#line 940 + +#line 940 + for(;;) +#line 940 + { +#line 940 + size_t extent = MIN(remaining, ncp->chunk); +#line 940 + size_t nget = ncx_howmany(varp->type, extent); +#line 940 + +#line 940 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 940 + 0, (void **)&xp); /* cast away const */ +#line 940 + if(lstatus != NC_NOERR) +#line 940 + return lstatus; +#line 940 + +#line 940 + lstatus = ncx_getn_uint_uint(&xp, nget, value); +#line 940 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 940 + status = lstatus; +#line 940 + +#line 940 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 940 + +#line 940 + remaining -= extent; +#line 940 + if(remaining == 0) +#line 940 + break; /* normal loop exit */ +#line 940 + offset += (off_t)extent; +#line 940 + value += nget; +#line 940 + } +#line 940 + +#line 940 + return status; +#line 940 +} +#line 940 + +static int +#line 941 +getNCvx_uint_ulonglong(const NC3_INFO* ncp, const NC_var *varp, +#line 941 + const size_t *start, size_t nelems, ulonglong *value) +#line 941 +{ +#line 941 + off_t offset = NC_varoffset(ncp, varp, start); +#line 941 + size_t remaining = varp->xsz * nelems; +#line 941 + int status = NC_NOERR; +#line 941 + const void *xp; +#line 941 + +#line 941 + if(nelems == 0) +#line 941 + return NC_NOERR; +#line 941 + +#line 941 + assert(value != NULL); +#line 941 + +#line 941 + for(;;) +#line 941 + { +#line 941 + size_t extent = MIN(remaining, ncp->chunk); +#line 941 + size_t nget = ncx_howmany(varp->type, extent); +#line 941 + +#line 941 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 941 + 0, (void **)&xp); /* cast away const */ +#line 941 + if(lstatus != NC_NOERR) +#line 941 + return lstatus; +#line 941 + +#line 941 + lstatus = ncx_getn_uint_ulonglong(&xp, nget, value); +#line 941 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 941 + status = lstatus; +#line 941 + +#line 941 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 941 + +#line 941 + remaining -= extent; +#line 941 + if(remaining == 0) +#line 941 + break; /* normal loop exit */ +#line 941 + offset += (off_t)extent; +#line 941 + value += nget; +#line 941 + } +#line 941 + +#line 941 + return status; +#line 941 +} +#line 941 + +static int +#line 942 +getNCvx_uint_ushort(const NC3_INFO* ncp, const NC_var *varp, +#line 942 + const size_t *start, size_t nelems, ushort *value) +#line 942 +{ +#line 942 + off_t offset = NC_varoffset(ncp, varp, start); +#line 942 + size_t remaining = varp->xsz * nelems; +#line 942 + int status = NC_NOERR; +#line 942 + const void *xp; +#line 942 + +#line 942 + if(nelems == 0) +#line 942 + return NC_NOERR; +#line 942 + +#line 942 + assert(value != NULL); +#line 942 + +#line 942 + for(;;) +#line 942 + { +#line 942 + size_t extent = MIN(remaining, ncp->chunk); +#line 942 + size_t nget = ncx_howmany(varp->type, extent); +#line 942 + +#line 942 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 942 + 0, (void **)&xp); /* cast away const */ +#line 942 + if(lstatus != NC_NOERR) +#line 942 + return lstatus; +#line 942 + +#line 942 + lstatus = ncx_getn_uint_ushort(&xp, nget, value); +#line 942 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 942 + status = lstatus; +#line 942 + +#line 942 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 942 + +#line 942 + remaining -= extent; +#line 942 + if(remaining == 0) +#line 942 + break; /* normal loop exit */ +#line 942 + offset += (off_t)extent; +#line 942 + value += nget; +#line 942 + } +#line 942 + +#line 942 + return status; +#line 942 +} +#line 942 + + +static int +#line 944 +getNCvx_longlong_schar(const NC3_INFO* ncp, const NC_var *varp, +#line 944 + const size_t *start, size_t nelems, schar *value) +#line 944 +{ +#line 944 + off_t offset = NC_varoffset(ncp, varp, start); +#line 944 + size_t remaining = varp->xsz * nelems; +#line 944 + int status = NC_NOERR; +#line 944 + const void *xp; +#line 944 + +#line 944 + if(nelems == 0) +#line 944 + return NC_NOERR; +#line 944 + +#line 944 + assert(value != NULL); +#line 944 + +#line 944 + for(;;) +#line 944 + { +#line 944 + size_t extent = MIN(remaining, ncp->chunk); +#line 944 + size_t nget = ncx_howmany(varp->type, extent); +#line 944 + +#line 944 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 944 + 0, (void **)&xp); /* cast away const */ +#line 944 + if(lstatus != NC_NOERR) +#line 944 + return lstatus; +#line 944 + +#line 944 + lstatus = ncx_getn_longlong_schar(&xp, nget, value); +#line 944 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 944 + status = lstatus; +#line 944 + +#line 944 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 944 + +#line 944 + remaining -= extent; +#line 944 + if(remaining == 0) +#line 944 + break; /* normal loop exit */ +#line 944 + offset += (off_t)extent; +#line 944 + value += nget; +#line 944 + } +#line 944 + +#line 944 + return status; +#line 944 +} +#line 944 + +static int +#line 945 +getNCvx_longlong_uchar(const NC3_INFO* ncp, const NC_var *varp, +#line 945 + const size_t *start, size_t nelems, uchar *value) +#line 945 +{ +#line 945 + off_t offset = NC_varoffset(ncp, varp, start); +#line 945 + size_t remaining = varp->xsz * nelems; +#line 945 + int status = NC_NOERR; +#line 945 + const void *xp; +#line 945 + +#line 945 + if(nelems == 0) +#line 945 + return NC_NOERR; +#line 945 + +#line 945 + assert(value != NULL); +#line 945 + +#line 945 + for(;;) +#line 945 + { +#line 945 + size_t extent = MIN(remaining, ncp->chunk); +#line 945 + size_t nget = ncx_howmany(varp->type, extent); +#line 945 + +#line 945 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 945 + 0, (void **)&xp); /* cast away const */ +#line 945 + if(lstatus != NC_NOERR) +#line 945 + return lstatus; +#line 945 + +#line 945 + lstatus = ncx_getn_longlong_uchar(&xp, nget, value); +#line 945 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 945 + status = lstatus; +#line 945 + +#line 945 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 945 + +#line 945 + remaining -= extent; +#line 945 + if(remaining == 0) +#line 945 + break; /* normal loop exit */ +#line 945 + offset += (off_t)extent; +#line 945 + value += nget; +#line 945 + } +#line 945 + +#line 945 + return status; +#line 945 +} +#line 945 + +static int +#line 946 +getNCvx_longlong_short(const NC3_INFO* ncp, const NC_var *varp, +#line 946 + const size_t *start, size_t nelems, short *value) +#line 946 +{ +#line 946 + off_t offset = NC_varoffset(ncp, varp, start); +#line 946 + size_t remaining = varp->xsz * nelems; +#line 946 + int status = NC_NOERR; +#line 946 + const void *xp; +#line 946 + +#line 946 + if(nelems == 0) +#line 946 + return NC_NOERR; +#line 946 + +#line 946 + assert(value != NULL); +#line 946 + +#line 946 + for(;;) +#line 946 + { +#line 946 + size_t extent = MIN(remaining, ncp->chunk); +#line 946 + size_t nget = ncx_howmany(varp->type, extent); +#line 946 + +#line 946 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 946 + 0, (void **)&xp); /* cast away const */ +#line 946 + if(lstatus != NC_NOERR) +#line 946 + return lstatus; +#line 946 + +#line 946 + lstatus = ncx_getn_longlong_short(&xp, nget, value); +#line 946 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 946 + status = lstatus; +#line 946 + +#line 946 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 946 + +#line 946 + remaining -= extent; +#line 946 + if(remaining == 0) +#line 946 + break; /* normal loop exit */ +#line 946 + offset += (off_t)extent; +#line 946 + value += nget; +#line 946 + } +#line 946 + +#line 946 + return status; +#line 946 +} +#line 946 + +static int +#line 947 +getNCvx_longlong_int(const NC3_INFO* ncp, const NC_var *varp, +#line 947 + const size_t *start, size_t nelems, int *value) +#line 947 +{ +#line 947 + off_t offset = NC_varoffset(ncp, varp, start); +#line 947 + size_t remaining = varp->xsz * nelems; +#line 947 + int status = NC_NOERR; +#line 947 + const void *xp; +#line 947 + +#line 947 + if(nelems == 0) +#line 947 + return NC_NOERR; +#line 947 + +#line 947 + assert(value != NULL); +#line 947 + +#line 947 + for(;;) +#line 947 + { +#line 947 + size_t extent = MIN(remaining, ncp->chunk); +#line 947 + size_t nget = ncx_howmany(varp->type, extent); +#line 947 + +#line 947 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 947 + 0, (void **)&xp); /* cast away const */ +#line 947 + if(lstatus != NC_NOERR) +#line 947 + return lstatus; +#line 947 + +#line 947 + lstatus = ncx_getn_longlong_int(&xp, nget, value); +#line 947 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 947 + status = lstatus; +#line 947 + +#line 947 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 947 + +#line 947 + remaining -= extent; +#line 947 + if(remaining == 0) +#line 947 + break; /* normal loop exit */ +#line 947 + offset += (off_t)extent; +#line 947 + value += nget; +#line 947 + } +#line 947 + +#line 947 + return status; +#line 947 +} +#line 947 + +static int +#line 948 +getNCvx_longlong_float(const NC3_INFO* ncp, const NC_var *varp, +#line 948 + const size_t *start, size_t nelems, float *value) +#line 948 +{ +#line 948 + off_t offset = NC_varoffset(ncp, varp, start); +#line 948 + size_t remaining = varp->xsz * nelems; +#line 948 + int status = NC_NOERR; +#line 948 + const void *xp; +#line 948 + +#line 948 + if(nelems == 0) +#line 948 + return NC_NOERR; +#line 948 + +#line 948 + assert(value != NULL); +#line 948 + +#line 948 + for(;;) +#line 948 + { +#line 948 + size_t extent = MIN(remaining, ncp->chunk); +#line 948 + size_t nget = ncx_howmany(varp->type, extent); +#line 948 + +#line 948 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 948 + 0, (void **)&xp); /* cast away const */ +#line 948 + if(lstatus != NC_NOERR) +#line 948 + return lstatus; +#line 948 + +#line 948 + lstatus = ncx_getn_longlong_float(&xp, nget, value); +#line 948 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 948 + status = lstatus; +#line 948 + +#line 948 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 948 + +#line 948 + remaining -= extent; +#line 948 + if(remaining == 0) +#line 948 + break; /* normal loop exit */ +#line 948 + offset += (off_t)extent; +#line 948 + value += nget; +#line 948 + } +#line 948 + +#line 948 + return status; +#line 948 +} +#line 948 + +static int +#line 949 +getNCvx_longlong_double(const NC3_INFO* ncp, const NC_var *varp, +#line 949 + const size_t *start, size_t nelems, double *value) +#line 949 +{ +#line 949 + off_t offset = NC_varoffset(ncp, varp, start); +#line 949 + size_t remaining = varp->xsz * nelems; +#line 949 + int status = NC_NOERR; +#line 949 + const void *xp; +#line 949 + +#line 949 + if(nelems == 0) +#line 949 + return NC_NOERR; +#line 949 + +#line 949 + assert(value != NULL); +#line 949 + +#line 949 + for(;;) +#line 949 + { +#line 949 + size_t extent = MIN(remaining, ncp->chunk); +#line 949 + size_t nget = ncx_howmany(varp->type, extent); +#line 949 + +#line 949 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 949 + 0, (void **)&xp); /* cast away const */ +#line 949 + if(lstatus != NC_NOERR) +#line 949 + return lstatus; +#line 949 + +#line 949 + lstatus = ncx_getn_longlong_double(&xp, nget, value); +#line 949 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 949 + status = lstatus; +#line 949 + +#line 949 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 949 + +#line 949 + remaining -= extent; +#line 949 + if(remaining == 0) +#line 949 + break; /* normal loop exit */ +#line 949 + offset += (off_t)extent; +#line 949 + value += nget; +#line 949 + } +#line 949 + +#line 949 + return status; +#line 949 +} +#line 949 + +static int +#line 950 +getNCvx_longlong_longlong(const NC3_INFO* ncp, const NC_var *varp, +#line 950 + const size_t *start, size_t nelems, longlong *value) +#line 950 +{ +#line 950 + off_t offset = NC_varoffset(ncp, varp, start); +#line 950 + size_t remaining = varp->xsz * nelems; +#line 950 + int status = NC_NOERR; +#line 950 + const void *xp; +#line 950 + +#line 950 + if(nelems == 0) +#line 950 + return NC_NOERR; +#line 950 + +#line 950 + assert(value != NULL); +#line 950 + +#line 950 + for(;;) +#line 950 + { +#line 950 + size_t extent = MIN(remaining, ncp->chunk); +#line 950 + size_t nget = ncx_howmany(varp->type, extent); +#line 950 + +#line 950 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 950 + 0, (void **)&xp); /* cast away const */ +#line 950 + if(lstatus != NC_NOERR) +#line 950 + return lstatus; +#line 950 + +#line 950 + lstatus = ncx_getn_longlong_longlong(&xp, nget, value); +#line 950 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 950 + status = lstatus; +#line 950 + +#line 950 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 950 + +#line 950 + remaining -= extent; +#line 950 + if(remaining == 0) +#line 950 + break; /* normal loop exit */ +#line 950 + offset += (off_t)extent; +#line 950 + value += nget; +#line 950 + } +#line 950 + +#line 950 + return status; +#line 950 +} +#line 950 + +static int +#line 951 +getNCvx_longlong_uint(const NC3_INFO* ncp, const NC_var *varp, +#line 951 + const size_t *start, size_t nelems, uint *value) +#line 951 +{ +#line 951 + off_t offset = NC_varoffset(ncp, varp, start); +#line 951 + size_t remaining = varp->xsz * nelems; +#line 951 + int status = NC_NOERR; +#line 951 + const void *xp; +#line 951 + +#line 951 + if(nelems == 0) +#line 951 + return NC_NOERR; +#line 951 + +#line 951 + assert(value != NULL); +#line 951 + +#line 951 + for(;;) +#line 951 + { +#line 951 + size_t extent = MIN(remaining, ncp->chunk); +#line 951 + size_t nget = ncx_howmany(varp->type, extent); +#line 951 + +#line 951 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 951 + 0, (void **)&xp); /* cast away const */ +#line 951 + if(lstatus != NC_NOERR) +#line 951 + return lstatus; +#line 951 + +#line 951 + lstatus = ncx_getn_longlong_uint(&xp, nget, value); +#line 951 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 951 + status = lstatus; +#line 951 + +#line 951 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 951 + +#line 951 + remaining -= extent; +#line 951 + if(remaining == 0) +#line 951 + break; /* normal loop exit */ +#line 951 + offset += (off_t)extent; +#line 951 + value += nget; +#line 951 + } +#line 951 + +#line 951 + return status; +#line 951 +} +#line 951 + +static int +#line 952 +getNCvx_longlong_ulonglong(const NC3_INFO* ncp, const NC_var *varp, +#line 952 + const size_t *start, size_t nelems, ulonglong *value) +#line 952 +{ +#line 952 + off_t offset = NC_varoffset(ncp, varp, start); +#line 952 + size_t remaining = varp->xsz * nelems; +#line 952 + int status = NC_NOERR; +#line 952 + const void *xp; +#line 952 + +#line 952 + if(nelems == 0) +#line 952 + return NC_NOERR; +#line 952 + +#line 952 + assert(value != NULL); +#line 952 + +#line 952 + for(;;) +#line 952 + { +#line 952 + size_t extent = MIN(remaining, ncp->chunk); +#line 952 + size_t nget = ncx_howmany(varp->type, extent); +#line 952 + +#line 952 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 952 + 0, (void **)&xp); /* cast away const */ +#line 952 + if(lstatus != NC_NOERR) +#line 952 + return lstatus; +#line 952 + +#line 952 + lstatus = ncx_getn_longlong_ulonglong(&xp, nget, value); +#line 952 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 952 + status = lstatus; +#line 952 + +#line 952 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 952 + +#line 952 + remaining -= extent; +#line 952 + if(remaining == 0) +#line 952 + break; /* normal loop exit */ +#line 952 + offset += (off_t)extent; +#line 952 + value += nget; +#line 952 + } +#line 952 + +#line 952 + return status; +#line 952 +} +#line 952 + +static int +#line 953 +getNCvx_longlong_ushort(const NC3_INFO* ncp, const NC_var *varp, +#line 953 + const size_t *start, size_t nelems, ushort *value) +#line 953 +{ +#line 953 + off_t offset = NC_varoffset(ncp, varp, start); +#line 953 + size_t remaining = varp->xsz * nelems; +#line 953 + int status = NC_NOERR; +#line 953 + const void *xp; +#line 953 + +#line 953 + if(nelems == 0) +#line 953 + return NC_NOERR; +#line 953 + +#line 953 + assert(value != NULL); +#line 953 + +#line 953 + for(;;) +#line 953 + { +#line 953 + size_t extent = MIN(remaining, ncp->chunk); +#line 953 + size_t nget = ncx_howmany(varp->type, extent); +#line 953 + +#line 953 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 953 + 0, (void **)&xp); /* cast away const */ +#line 953 + if(lstatus != NC_NOERR) +#line 953 + return lstatus; +#line 953 + +#line 953 + lstatus = ncx_getn_longlong_ushort(&xp, nget, value); +#line 953 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 953 + status = lstatus; +#line 953 + +#line 953 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 953 + +#line 953 + remaining -= extent; +#line 953 + if(remaining == 0) +#line 953 + break; /* normal loop exit */ +#line 953 + offset += (off_t)extent; +#line 953 + value += nget; +#line 953 + } +#line 953 + +#line 953 + return status; +#line 953 +} +#line 953 + + +static int +#line 955 +getNCvx_ulonglong_schar(const NC3_INFO* ncp, const NC_var *varp, +#line 955 + const size_t *start, size_t nelems, schar *value) +#line 955 +{ +#line 955 + off_t offset = NC_varoffset(ncp, varp, start); +#line 955 + size_t remaining = varp->xsz * nelems; +#line 955 + int status = NC_NOERR; +#line 955 + const void *xp; +#line 955 + +#line 955 + if(nelems == 0) +#line 955 + return NC_NOERR; +#line 955 + +#line 955 + assert(value != NULL); +#line 955 + +#line 955 + for(;;) +#line 955 + { +#line 955 + size_t extent = MIN(remaining, ncp->chunk); +#line 955 + size_t nget = ncx_howmany(varp->type, extent); +#line 955 + +#line 955 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 955 + 0, (void **)&xp); /* cast away const */ +#line 955 + if(lstatus != NC_NOERR) +#line 955 + return lstatus; +#line 955 + +#line 955 + lstatus = ncx_getn_ulonglong_schar(&xp, nget, value); +#line 955 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 955 + status = lstatus; +#line 955 + +#line 955 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 955 + +#line 955 + remaining -= extent; +#line 955 + if(remaining == 0) +#line 955 + break; /* normal loop exit */ +#line 955 + offset += (off_t)extent; +#line 955 + value += nget; +#line 955 + } +#line 955 + +#line 955 + return status; +#line 955 +} +#line 955 + +static int +#line 956 +getNCvx_ulonglong_uchar(const NC3_INFO* ncp, const NC_var *varp, +#line 956 + const size_t *start, size_t nelems, uchar *value) +#line 956 +{ +#line 956 + off_t offset = NC_varoffset(ncp, varp, start); +#line 956 + size_t remaining = varp->xsz * nelems; +#line 956 + int status = NC_NOERR; +#line 956 + const void *xp; +#line 956 + +#line 956 + if(nelems == 0) +#line 956 + return NC_NOERR; +#line 956 + +#line 956 + assert(value != NULL); +#line 956 + +#line 956 + for(;;) +#line 956 + { +#line 956 + size_t extent = MIN(remaining, ncp->chunk); +#line 956 + size_t nget = ncx_howmany(varp->type, extent); +#line 956 + +#line 956 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 956 + 0, (void **)&xp); /* cast away const */ +#line 956 + if(lstatus != NC_NOERR) +#line 956 + return lstatus; +#line 956 + +#line 956 + lstatus = ncx_getn_ulonglong_uchar(&xp, nget, value); +#line 956 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 956 + status = lstatus; +#line 956 + +#line 956 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 956 + +#line 956 + remaining -= extent; +#line 956 + if(remaining == 0) +#line 956 + break; /* normal loop exit */ +#line 956 + offset += (off_t)extent; +#line 956 + value += nget; +#line 956 + } +#line 956 + +#line 956 + return status; +#line 956 +} +#line 956 + +static int +#line 957 +getNCvx_ulonglong_short(const NC3_INFO* ncp, const NC_var *varp, +#line 957 + const size_t *start, size_t nelems, short *value) +#line 957 +{ +#line 957 + off_t offset = NC_varoffset(ncp, varp, start); +#line 957 + size_t remaining = varp->xsz * nelems; +#line 957 + int status = NC_NOERR; +#line 957 + const void *xp; +#line 957 + +#line 957 + if(nelems == 0) +#line 957 + return NC_NOERR; +#line 957 + +#line 957 + assert(value != NULL); +#line 957 + +#line 957 + for(;;) +#line 957 + { +#line 957 + size_t extent = MIN(remaining, ncp->chunk); +#line 957 + size_t nget = ncx_howmany(varp->type, extent); +#line 957 + +#line 957 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 957 + 0, (void **)&xp); /* cast away const */ +#line 957 + if(lstatus != NC_NOERR) +#line 957 + return lstatus; +#line 957 + +#line 957 + lstatus = ncx_getn_ulonglong_short(&xp, nget, value); +#line 957 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 957 + status = lstatus; +#line 957 + +#line 957 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 957 + +#line 957 + remaining -= extent; +#line 957 + if(remaining == 0) +#line 957 + break; /* normal loop exit */ +#line 957 + offset += (off_t)extent; +#line 957 + value += nget; +#line 957 + } +#line 957 + +#line 957 + return status; +#line 957 +} +#line 957 + +static int +#line 958 +getNCvx_ulonglong_int(const NC3_INFO* ncp, const NC_var *varp, +#line 958 + const size_t *start, size_t nelems, int *value) +#line 958 +{ +#line 958 + off_t offset = NC_varoffset(ncp, varp, start); +#line 958 + size_t remaining = varp->xsz * nelems; +#line 958 + int status = NC_NOERR; +#line 958 + const void *xp; +#line 958 + +#line 958 + if(nelems == 0) +#line 958 + return NC_NOERR; +#line 958 + +#line 958 + assert(value != NULL); +#line 958 + +#line 958 + for(;;) +#line 958 + { +#line 958 + size_t extent = MIN(remaining, ncp->chunk); +#line 958 + size_t nget = ncx_howmany(varp->type, extent); +#line 958 + +#line 958 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 958 + 0, (void **)&xp); /* cast away const */ +#line 958 + if(lstatus != NC_NOERR) +#line 958 + return lstatus; +#line 958 + +#line 958 + lstatus = ncx_getn_ulonglong_int(&xp, nget, value); +#line 958 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 958 + status = lstatus; +#line 958 + +#line 958 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 958 + +#line 958 + remaining -= extent; +#line 958 + if(remaining == 0) +#line 958 + break; /* normal loop exit */ +#line 958 + offset += (off_t)extent; +#line 958 + value += nget; +#line 958 + } +#line 958 + +#line 958 + return status; +#line 958 +} +#line 958 + +static int +#line 959 +getNCvx_ulonglong_float(const NC3_INFO* ncp, const NC_var *varp, +#line 959 + const size_t *start, size_t nelems, float *value) +#line 959 +{ +#line 959 + off_t offset = NC_varoffset(ncp, varp, start); +#line 959 + size_t remaining = varp->xsz * nelems; +#line 959 + int status = NC_NOERR; +#line 959 + const void *xp; +#line 959 + +#line 959 + if(nelems == 0) +#line 959 + return NC_NOERR; +#line 959 + +#line 959 + assert(value != NULL); +#line 959 + +#line 959 + for(;;) +#line 959 + { +#line 959 + size_t extent = MIN(remaining, ncp->chunk); +#line 959 + size_t nget = ncx_howmany(varp->type, extent); +#line 959 + +#line 959 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 959 + 0, (void **)&xp); /* cast away const */ +#line 959 + if(lstatus != NC_NOERR) +#line 959 + return lstatus; +#line 959 + +#line 959 + lstatus = ncx_getn_ulonglong_float(&xp, nget, value); +#line 959 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 959 + status = lstatus; +#line 959 + +#line 959 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 959 + +#line 959 + remaining -= extent; +#line 959 + if(remaining == 0) +#line 959 + break; /* normal loop exit */ +#line 959 + offset += (off_t)extent; +#line 959 + value += nget; +#line 959 + } +#line 959 + +#line 959 + return status; +#line 959 +} +#line 959 + +static int +#line 960 +getNCvx_ulonglong_double(const NC3_INFO* ncp, const NC_var *varp, +#line 960 + const size_t *start, size_t nelems, double *value) +#line 960 +{ +#line 960 + off_t offset = NC_varoffset(ncp, varp, start); +#line 960 + size_t remaining = varp->xsz * nelems; +#line 960 + int status = NC_NOERR; +#line 960 + const void *xp; +#line 960 + +#line 960 + if(nelems == 0) +#line 960 + return NC_NOERR; +#line 960 + +#line 960 + assert(value != NULL); +#line 960 + +#line 960 + for(;;) +#line 960 + { +#line 960 + size_t extent = MIN(remaining, ncp->chunk); +#line 960 + size_t nget = ncx_howmany(varp->type, extent); +#line 960 + +#line 960 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 960 + 0, (void **)&xp); /* cast away const */ +#line 960 + if(lstatus != NC_NOERR) +#line 960 + return lstatus; +#line 960 + +#line 960 + lstatus = ncx_getn_ulonglong_double(&xp, nget, value); +#line 960 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 960 + status = lstatus; +#line 960 + +#line 960 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 960 + +#line 960 + remaining -= extent; +#line 960 + if(remaining == 0) +#line 960 + break; /* normal loop exit */ +#line 960 + offset += (off_t)extent; +#line 960 + value += nget; +#line 960 + } +#line 960 + +#line 960 + return status; +#line 960 +} +#line 960 + +static int +#line 961 +getNCvx_ulonglong_longlong(const NC3_INFO* ncp, const NC_var *varp, +#line 961 + const size_t *start, size_t nelems, longlong *value) +#line 961 +{ +#line 961 + off_t offset = NC_varoffset(ncp, varp, start); +#line 961 + size_t remaining = varp->xsz * nelems; +#line 961 + int status = NC_NOERR; +#line 961 + const void *xp; +#line 961 + +#line 961 + if(nelems == 0) +#line 961 + return NC_NOERR; +#line 961 + +#line 961 + assert(value != NULL); +#line 961 + +#line 961 + for(;;) +#line 961 + { +#line 961 + size_t extent = MIN(remaining, ncp->chunk); +#line 961 + size_t nget = ncx_howmany(varp->type, extent); +#line 961 + +#line 961 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 961 + 0, (void **)&xp); /* cast away const */ +#line 961 + if(lstatus != NC_NOERR) +#line 961 + return lstatus; +#line 961 + +#line 961 + lstatus = ncx_getn_ulonglong_longlong(&xp, nget, value); +#line 961 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 961 + status = lstatus; +#line 961 + +#line 961 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 961 + +#line 961 + remaining -= extent; +#line 961 + if(remaining == 0) +#line 961 + break; /* normal loop exit */ +#line 961 + offset += (off_t)extent; +#line 961 + value += nget; +#line 961 + } +#line 961 + +#line 961 + return status; +#line 961 +} +#line 961 + +static int +#line 962 +getNCvx_ulonglong_uint(const NC3_INFO* ncp, const NC_var *varp, +#line 962 + const size_t *start, size_t nelems, uint *value) +#line 962 +{ +#line 962 + off_t offset = NC_varoffset(ncp, varp, start); +#line 962 + size_t remaining = varp->xsz * nelems; +#line 962 + int status = NC_NOERR; +#line 962 + const void *xp; +#line 962 + +#line 962 + if(nelems == 0) +#line 962 + return NC_NOERR; +#line 962 + +#line 962 + assert(value != NULL); +#line 962 + +#line 962 + for(;;) +#line 962 + { +#line 962 + size_t extent = MIN(remaining, ncp->chunk); +#line 962 + size_t nget = ncx_howmany(varp->type, extent); +#line 962 + +#line 962 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 962 + 0, (void **)&xp); /* cast away const */ +#line 962 + if(lstatus != NC_NOERR) +#line 962 + return lstatus; +#line 962 + +#line 962 + lstatus = ncx_getn_ulonglong_uint(&xp, nget, value); +#line 962 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 962 + status = lstatus; +#line 962 + +#line 962 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 962 + +#line 962 + remaining -= extent; +#line 962 + if(remaining == 0) +#line 962 + break; /* normal loop exit */ +#line 962 + offset += (off_t)extent; +#line 962 + value += nget; +#line 962 + } +#line 962 + +#line 962 + return status; +#line 962 +} +#line 962 + +static int +#line 963 +getNCvx_ulonglong_ulonglong(const NC3_INFO* ncp, const NC_var *varp, +#line 963 + const size_t *start, size_t nelems, ulonglong *value) +#line 963 +{ +#line 963 + off_t offset = NC_varoffset(ncp, varp, start); +#line 963 + size_t remaining = varp->xsz * nelems; +#line 963 + int status = NC_NOERR; +#line 963 + const void *xp; +#line 963 + +#line 963 + if(nelems == 0) +#line 963 + return NC_NOERR; +#line 963 + +#line 963 + assert(value != NULL); +#line 963 + +#line 963 + for(;;) +#line 963 + { +#line 963 + size_t extent = MIN(remaining, ncp->chunk); +#line 963 + size_t nget = ncx_howmany(varp->type, extent); +#line 963 + +#line 963 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 963 + 0, (void **)&xp); /* cast away const */ +#line 963 + if(lstatus != NC_NOERR) +#line 963 + return lstatus; +#line 963 + +#line 963 + lstatus = ncx_getn_ulonglong_ulonglong(&xp, nget, value); +#line 963 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 963 + status = lstatus; +#line 963 + +#line 963 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 963 + +#line 963 + remaining -= extent; +#line 963 + if(remaining == 0) +#line 963 + break; /* normal loop exit */ +#line 963 + offset += (off_t)extent; +#line 963 + value += nget; +#line 963 + } +#line 963 + +#line 963 + return status; +#line 963 +} +#line 963 + +static int +#line 964 +getNCvx_ulonglong_ushort(const NC3_INFO* ncp, const NC_var *varp, +#line 964 + const size_t *start, size_t nelems, ushort *value) +#line 964 +{ +#line 964 + off_t offset = NC_varoffset(ncp, varp, start); +#line 964 + size_t remaining = varp->xsz * nelems; +#line 964 + int status = NC_NOERR; +#line 964 + const void *xp; +#line 964 + +#line 964 + if(nelems == 0) +#line 964 + return NC_NOERR; +#line 964 + +#line 964 + assert(value != NULL); +#line 964 + +#line 964 + for(;;) +#line 964 + { +#line 964 + size_t extent = MIN(remaining, ncp->chunk); +#line 964 + size_t nget = ncx_howmany(varp->type, extent); +#line 964 + +#line 964 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 964 + 0, (void **)&xp); /* cast away const */ +#line 964 + if(lstatus != NC_NOERR) +#line 964 + return lstatus; +#line 964 + +#line 964 + lstatus = ncx_getn_ulonglong_ushort(&xp, nget, value); +#line 964 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 964 + status = lstatus; +#line 964 + +#line 964 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 964 + +#line 964 + remaining -= extent; +#line 964 + if(remaining == 0) +#line 964 + break; /* normal loop exit */ +#line 964 + offset += (off_t)extent; +#line 964 + value += nget; +#line 964 + } +#line 964 + +#line 964 + return status; +#line 964 +} +#line 964 + + +#line 967 +#ifdef NOTUSED +static int +#line 968 +getNCvx_schar_uchar(const NC3_INFO* ncp, const NC_var *varp, +#line 968 + const size_t *start, size_t nelems, uchar *value) +#line 968 +{ +#line 968 + off_t offset = NC_varoffset(ncp, varp, start); +#line 968 + size_t remaining = varp->xsz * nelems; +#line 968 + int status = NC_NOERR; +#line 968 + const void *xp; +#line 968 + +#line 968 + if(nelems == 0) +#line 968 + return NC_NOERR; +#line 968 + +#line 968 + assert(value != NULL); +#line 968 + +#line 968 + for(;;) +#line 968 + { +#line 968 + size_t extent = MIN(remaining, ncp->chunk); +#line 968 + size_t nget = ncx_howmany(varp->type, extent); +#line 968 + +#line 968 + int lstatus = ncio_get(ncp->nciop, offset, extent, +#line 968 + 0, (void **)&xp); /* cast away const */ +#line 968 + if(lstatus != NC_NOERR) +#line 968 + return lstatus; +#line 968 + +#line 968 + lstatus = ncx_getn_schar_uchar(&xp, nget, value); +#line 968 + if(lstatus != NC_NOERR && status == NC_NOERR) +#line 968 + status = lstatus; +#line 968 + +#line 968 + (void) ncio_rel(ncp->nciop, offset, 0); +#line 968 + +#line 968 + remaining -= extent; +#line 968 + if(remaining == 0) +#line 968 + break; /* normal loop exit */ +#line 968 + offset += (off_t)extent; +#line 968 + value += nget; +#line 968 + } +#line 968 + +#line 968 + return status; +#line 968 +} +#line 968 + +#endif /*NOTUSED*/ + +/* + * For ncvar{put,get}, + * find the largest contiguous block from within 'edges'. + * returns the index to the left of this (which may be -1). + * Compute the number of contiguous elements and return + * that in *iocountp. + * The presence of "record" variables makes this routine + * overly subtle. + */ +static int +NCiocount(const NC3_INFO* const ncp, const NC_var *const varp, + const size_t *const edges, + size_t *const iocountp) +{ + const size_t *edp0 = edges; + const size_t *edp = edges + varp->ndims; + const size_t *shp = varp->shape + varp->ndims; + + if(IS_RECVAR(varp)) + { + if(varp->ndims == 1 && ncp->recsize <= varp->len) + { + /* one dimensional && the only 'record' variable */ + *iocountp = *edges; + return(0); + } + /* else */ + edp0++; + } + + assert(edges != NULL); + + /* find max contiguous */ + while(edp > edp0) + { + shp--; edp--; + if(*edp < *shp ) + { + const size_t *zedp = edp; + while(zedp >= edp0) + { + if(*zedp == 0) + { + *iocountp = 0; + goto done; + } + /* Tip of the hat to segmented architectures */ + if(zedp == edp0) + break; + zedp--; + } + break; + } + assert(*edp == *shp); + } + + /* + * edp, shp reference rightmost index s.t. *(edp +1) == *(shp +1) + * + * Or there is only one dimension. + * If there is only one dimension and it is 'non record' dimension, + * edp is &edges[0] and we will return -1. + * If there is only one dimension and and it is a "record dimension", + * edp is &edges[1] (out of bounds) and we will return 0; + */ + assert(shp >= varp->shape + varp->ndims -1 + || *(edp +1) == *(shp +1)); + + /* now accumulate max count for a single io operation */ + for(*iocountp = 1, edp0 = edp; + edp0 < edges + varp->ndims; + edp0++) + { + *iocountp *= *edp0; + } + +done: + return((int)(edp - edges) - 1); +} + + +/* + * Set the elements of the array 'upp' to + * the sum of the corresponding elements of + * 'stp' and 'edp'. 'end' should be &stp[nelems]. + */ +static void +set_upper(size_t *upp, /* modified on return */ + const size_t *stp, + const size_t *edp, + const size_t *const end) +{ + while(upp < end) { + *upp++ = *stp++ + *edp++; + } +} + + +/* + * The infamous and oft-discussed odometer code. + * + * 'start[]' is the starting coordinate. + * 'upper[]' is the upper bound s.t. start[ii] < upper[ii]. + * 'coord[]' is the register, the current coordinate value. + * For some ii, + * upp == &upper[ii] + * cdp == &coord[ii] + * + * Running this routine increments *cdp. + * + * If after the increment, *cdp is equal to *upp + * (and cdp is not the leftmost dimension), + * *cdp is "zeroed" to the starting value and + * we need to "carry", eg, increment one place to + * the left. + * + * TODO: Some architectures hate recursion? + * Reimplement non-recursively. + */ +static void +odo1(const size_t *const start, const size_t *const upper, + size_t *const coord, /* modified on return */ + const size_t *upp, + size_t *cdp) +{ + assert(coord <= cdp && cdp <= coord + NC_MAX_VAR_DIMS); + assert(upper <= upp && upp <= upper + NC_MAX_VAR_DIMS); + assert(upp - upper == cdp - coord); + + assert(*cdp <= *upp); + + (*cdp)++; + if(cdp != coord && *cdp >= *upp) + { + *cdp = start[cdp - coord]; + odo1(start, upper, coord, upp -1, cdp -1); + } +} +#ifdef _CRAYC +#pragma _CRI noinline odo1 +#endif + + +#line 1130 + +/* Define a macro to allow hash on two type values */ +#define CASE(nc1,nc2) (nc1*256+nc2) + +static int +readNCv(const NC3_INFO* ncp, const NC_var* varp, const size_t* start, + const size_t nelems, void* value, const nc_type memtype) +{ + int status = NC_NOERR; + switch (CASE(varp->type,memtype)) { + + case CASE(NC_CHAR,NC_CHAR): + case CASE(NC_CHAR,NC_UBYTE): + return getNCvx_schar_schar(ncp,varp,start,nelems,(signed char*)value); + break; + case CASE(NC_BYTE,NC_BYTE): + return getNCvx_schar_schar(ncp,varp,start,nelems, (schar*)value); + break; + case CASE(NC_BYTE,NC_UBYTE): + if (fIsSet(ncp->flags,NC_64BIT_DATA)) + return getNCvx_schar_uchar(ncp,varp,start,nelems,(unsigned char*)value); + else + /* for CDF-1 and CDF-2, NC_BYTE is treated the same type as uchar memtype */ + return getNCvx_uchar_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_BYTE,NC_SHORT): + return getNCvx_schar_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_BYTE,NC_INT): + return getNCvx_schar_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_BYTE,NC_FLOAT): + return getNCvx_schar_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_BYTE,NC_DOUBLE): + return getNCvx_schar_double(ncp,varp,start,nelems,(double *)value); + break; + case CASE(NC_BYTE,NC_INT64): + return getNCvx_schar_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_BYTE,NC_UINT): + return getNCvx_schar_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_BYTE,NC_UINT64): + return getNCvx_schar_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_BYTE,NC_USHORT): + return getNCvx_schar_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + case CASE(NC_SHORT,NC_BYTE): + return getNCvx_short_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_SHORT,NC_UBYTE): + return getNCvx_short_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_SHORT,NC_SHORT): + return getNCvx_short_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_SHORT,NC_INT): + return getNCvx_short_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_SHORT,NC_FLOAT): + return getNCvx_short_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_SHORT,NC_DOUBLE): + return getNCvx_short_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_SHORT,NC_INT64): + return getNCvx_short_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_SHORT,NC_UINT): + return getNCvx_short_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_SHORT,NC_UINT64): + return getNCvx_short_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_SHORT,NC_USHORT): + return getNCvx_short_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + + case CASE(NC_INT,NC_BYTE): + return getNCvx_int_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_INT,NC_UBYTE): + return getNCvx_int_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_INT,NC_SHORT): + return getNCvx_int_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_INT,NC_INT): + return getNCvx_int_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_INT,NC_FLOAT): + return getNCvx_int_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_INT,NC_DOUBLE): + return getNCvx_int_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_INT,NC_INT64): + return getNCvx_int_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_INT,NC_UINT): + return getNCvx_int_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_INT,NC_UINT64): + return getNCvx_int_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_INT,NC_USHORT): + return getNCvx_int_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + + case CASE(NC_FLOAT,NC_BYTE): + return getNCvx_float_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_FLOAT,NC_UBYTE): + return getNCvx_float_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_FLOAT,NC_SHORT): + return getNCvx_float_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_FLOAT,NC_INT): + return getNCvx_float_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_FLOAT,NC_FLOAT): + return getNCvx_float_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_FLOAT,NC_DOUBLE): + return getNCvx_float_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_FLOAT,NC_INT64): + return getNCvx_float_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_FLOAT,NC_UINT): + return getNCvx_float_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_FLOAT,NC_UINT64): + return getNCvx_float_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_FLOAT,NC_USHORT): + return getNCvx_float_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + + case CASE(NC_DOUBLE,NC_BYTE): + return getNCvx_double_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_DOUBLE,NC_UBYTE): + return getNCvx_double_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_DOUBLE,NC_SHORT): + return getNCvx_double_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_DOUBLE,NC_INT): + return getNCvx_double_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_DOUBLE,NC_FLOAT): + return getNCvx_double_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_DOUBLE,NC_DOUBLE): + return getNCvx_double_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_DOUBLE,NC_INT64): + return getNCvx_double_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_DOUBLE,NC_UINT): + return getNCvx_double_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_DOUBLE,NC_UINT64): + return getNCvx_double_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_DOUBLE,NC_USHORT): + return getNCvx_double_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + + case CASE(NC_UBYTE,NC_UBYTE): + return getNCvx_uchar_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_UBYTE,NC_BYTE): + return getNCvx_uchar_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_UBYTE,NC_SHORT): + return getNCvx_uchar_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_UBYTE,NC_INT): + return getNCvx_uchar_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_UBYTE,NC_FLOAT): + return getNCvx_uchar_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_UBYTE,NC_DOUBLE): + return getNCvx_uchar_double(ncp,varp,start,nelems,(double *)value); + break; + case CASE(NC_UBYTE,NC_INT64): + return getNCvx_uchar_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_UBYTE,NC_UINT): + return getNCvx_uchar_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_UBYTE,NC_UINT64): + return getNCvx_uchar_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_UBYTE,NC_USHORT): + return getNCvx_uchar_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + + case CASE(NC_USHORT,NC_BYTE): + return getNCvx_ushort_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_USHORT,NC_UBYTE): + return getNCvx_ushort_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_USHORT,NC_SHORT): + return getNCvx_ushort_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_USHORT,NC_INT): + return getNCvx_ushort_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_USHORT,NC_FLOAT): + return getNCvx_ushort_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_USHORT,NC_DOUBLE): + return getNCvx_ushort_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_USHORT,NC_INT64): + return getNCvx_ushort_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_USHORT,NC_UINT): + return getNCvx_ushort_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_USHORT,NC_UINT64): + return getNCvx_ushort_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_USHORT,NC_USHORT): + return getNCvx_ushort_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + + case CASE(NC_UINT,NC_BYTE): + return getNCvx_uint_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_UINT,NC_UBYTE): + return getNCvx_uint_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_UINT,NC_SHORT): + return getNCvx_uint_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_UINT,NC_INT): + return getNCvx_uint_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_UINT,NC_FLOAT): + return getNCvx_uint_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_UINT,NC_DOUBLE): + return getNCvx_uint_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_UINT,NC_INT64): + return getNCvx_uint_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_UINT,NC_UINT): + return getNCvx_uint_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_UINT,NC_UINT64): + return getNCvx_uint_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_UINT,NC_USHORT): + return getNCvx_uint_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + + case CASE(NC_INT64,NC_BYTE): + return getNCvx_longlong_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_INT64,NC_UBYTE): + return getNCvx_longlong_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_INT64,NC_SHORT): + return getNCvx_longlong_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_INT64,NC_INT): + return getNCvx_longlong_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_INT64,NC_FLOAT): + return getNCvx_longlong_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_INT64,NC_DOUBLE): + return getNCvx_longlong_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_INT64,NC_INT64): + return getNCvx_longlong_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_INT64,NC_UINT): + return getNCvx_longlong_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_INT64,NC_UINT64): + return getNCvx_longlong_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_INT64,NC_USHORT): + return getNCvx_longlong_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + + case CASE(NC_UINT64,NC_BYTE): + return getNCvx_ulonglong_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_UINT64,NC_UBYTE): + return getNCvx_ulonglong_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_UINT64,NC_SHORT): + return getNCvx_ulonglong_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_UINT64,NC_INT): + return getNCvx_ulonglong_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_UINT64,NC_FLOAT): + return getNCvx_ulonglong_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_UINT64,NC_DOUBLE): + return getNCvx_ulonglong_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_UINT64,NC_INT64): + return getNCvx_ulonglong_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_UINT64,NC_UINT): + return getNCvx_ulonglong_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_UINT64,NC_UINT64): + return getNCvx_ulonglong_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_UINT64,NC_USHORT): + return getNCvx_ulonglong_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + + default: + return NC_EBADTYPE; + break; + } + return status; +} + + +static int +writeNCv(NC3_INFO* ncp, const NC_var* varp, const size_t* start, + const size_t nelems, const void* value, const nc_type memtype) +{ + int status = NC_NOERR; + switch (CASE(varp->type,memtype)) { + + case CASE(NC_CHAR,NC_CHAR): + case CASE(NC_CHAR,NC_UBYTE): + return putNCvx_char_char(ncp,varp,start,nelems,(char*)value); + break; + case CASE(NC_BYTE,NC_BYTE): + return putNCvx_schar_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_BYTE,NC_UBYTE): + if (fIsSet(ncp->flags,NC_64BIT_DATA)) + return putNCvx_schar_uchar(ncp,varp,start,nelems,(unsigned char*)value); + else + /* for CDF-1 and CDF-2, NC_BYTE is treated the same type as uchar memtype */ + return putNCvx_uchar_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_BYTE,NC_SHORT): + return putNCvx_schar_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_BYTE,NC_INT): + return putNCvx_schar_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_BYTE,NC_FLOAT): + return putNCvx_schar_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_BYTE,NC_DOUBLE): + return putNCvx_schar_double(ncp,varp,start,nelems,(double *)value); + break; + case CASE(NC_BYTE,NC_INT64): + return putNCvx_schar_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_BYTE,NC_UINT): + return putNCvx_schar_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_BYTE,NC_UINT64): + return putNCvx_schar_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_BYTE,NC_USHORT): + return putNCvx_schar_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + case CASE(NC_SHORT,NC_BYTE): + return putNCvx_short_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_SHORT,NC_UBYTE): + return putNCvx_short_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_SHORT,NC_SHORT): + return putNCvx_short_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_SHORT,NC_INT): + return putNCvx_short_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_SHORT,NC_FLOAT): + return putNCvx_short_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_SHORT,NC_DOUBLE): + return putNCvx_short_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_SHORT,NC_INT64): + return putNCvx_short_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_SHORT,NC_UINT): + return putNCvx_short_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_SHORT,NC_UINT64): + return putNCvx_short_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_SHORT,NC_USHORT): + return putNCvx_short_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + case CASE(NC_INT,NC_BYTE): + return putNCvx_int_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_INT,NC_UBYTE): + return putNCvx_int_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_INT,NC_SHORT): + return putNCvx_int_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_INT,NC_INT): + return putNCvx_int_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_INT,NC_FLOAT): + return putNCvx_int_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_INT,NC_DOUBLE): + return putNCvx_int_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_INT,NC_INT64): + return putNCvx_int_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_INT,NC_UINT): + return putNCvx_int_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_INT,NC_UINT64): + return putNCvx_int_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_INT,NC_USHORT): + return putNCvx_int_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + case CASE(NC_FLOAT,NC_BYTE): + return putNCvx_float_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_FLOAT,NC_UBYTE): + return putNCvx_float_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_FLOAT,NC_SHORT): + return putNCvx_float_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_FLOAT,NC_INT): + return putNCvx_float_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_FLOAT,NC_FLOAT): + return putNCvx_float_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_FLOAT,NC_DOUBLE): + return putNCvx_float_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_FLOAT,NC_INT64): + return putNCvx_float_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_FLOAT,NC_UINT): + return putNCvx_float_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_FLOAT,NC_UINT64): + return putNCvx_float_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_FLOAT,NC_USHORT): + return putNCvx_float_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + case CASE(NC_DOUBLE,NC_BYTE): + return putNCvx_double_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_DOUBLE,NC_UBYTE): + return putNCvx_double_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_DOUBLE,NC_SHORT): + return putNCvx_double_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_DOUBLE,NC_INT): + return putNCvx_double_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_DOUBLE,NC_FLOAT): + return putNCvx_double_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_DOUBLE,NC_DOUBLE): + return putNCvx_double_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_DOUBLE,NC_INT64): + return putNCvx_double_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_DOUBLE,NC_UINT): + return putNCvx_double_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_DOUBLE,NC_UINT64): + return putNCvx_double_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_DOUBLE,NC_USHORT): + return putNCvx_double_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + case CASE(NC_UBYTE,NC_UBYTE): + return putNCvx_uchar_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_UBYTE,NC_BYTE): + return putNCvx_uchar_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_UBYTE,NC_SHORT): + return putNCvx_uchar_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_UBYTE,NC_INT): + return putNCvx_uchar_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_UBYTE,NC_FLOAT): + return putNCvx_uchar_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_UBYTE,NC_DOUBLE): + return putNCvx_uchar_double(ncp,varp,start,nelems,(double *)value); + break; + case CASE(NC_UBYTE,NC_INT64): + return putNCvx_uchar_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_UBYTE,NC_UINT): + return putNCvx_uchar_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_UBYTE,NC_UINT64): + return putNCvx_uchar_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_UBYTE,NC_USHORT): + return putNCvx_uchar_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + case CASE(NC_USHORT,NC_BYTE): + return putNCvx_ushort_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_USHORT,NC_UBYTE): + return putNCvx_ushort_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_USHORT,NC_SHORT): + return putNCvx_ushort_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_USHORT,NC_INT): + return putNCvx_ushort_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_USHORT,NC_FLOAT): + return putNCvx_ushort_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_USHORT,NC_DOUBLE): + return putNCvx_ushort_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_USHORT,NC_INT64): + return putNCvx_ushort_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_USHORT,NC_UINT): + return putNCvx_ushort_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_USHORT,NC_UINT64): + return putNCvx_ushort_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_USHORT,NC_USHORT): + return putNCvx_ushort_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + case CASE(NC_UINT,NC_BYTE): + return putNCvx_uint_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_UINT,NC_UBYTE): + return putNCvx_uint_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_UINT,NC_SHORT): + return putNCvx_uint_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_UINT,NC_INT): + return putNCvx_uint_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_UINT,NC_FLOAT): + return putNCvx_uint_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_UINT,NC_DOUBLE): + return putNCvx_uint_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_UINT,NC_INT64): + return putNCvx_uint_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_UINT,NC_UINT): + return putNCvx_uint_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_UINT,NC_UINT64): + return putNCvx_uint_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_UINT,NC_USHORT): + return putNCvx_uint_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + case CASE(NC_INT64,NC_BYTE): + return putNCvx_longlong_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_INT64,NC_UBYTE): + return putNCvx_longlong_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_INT64,NC_SHORT): + return putNCvx_longlong_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_INT64,NC_INT): + return putNCvx_longlong_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_INT64,NC_FLOAT): + return putNCvx_longlong_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_INT64,NC_DOUBLE): + return putNCvx_longlong_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_INT64,NC_INT64): + return putNCvx_longlong_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_INT64,NC_UINT): + return putNCvx_longlong_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_INT64,NC_UINT64): + return putNCvx_longlong_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_INT64,NC_USHORT): + return putNCvx_longlong_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + case CASE(NC_UINT64,NC_BYTE): + return putNCvx_ulonglong_schar(ncp,varp,start,nelems,(schar*)value); + break; + case CASE(NC_UINT64,NC_UBYTE): + return putNCvx_ulonglong_uchar(ncp,varp,start,nelems,(unsigned char*)value); + break; + case CASE(NC_UINT64,NC_SHORT): + return putNCvx_ulonglong_short(ncp,varp,start,nelems,(short*)value); + break; + case CASE(NC_UINT64,NC_INT): + return putNCvx_ulonglong_int(ncp,varp,start,nelems,(int*)value); + break; + case CASE(NC_UINT64,NC_FLOAT): + return putNCvx_ulonglong_float(ncp,varp,start,nelems,(float*)value); + break; + case CASE(NC_UINT64,NC_DOUBLE): + return putNCvx_ulonglong_double(ncp,varp,start,nelems,(double*)value); + break; + case CASE(NC_UINT64,NC_INT64): + return putNCvx_ulonglong_longlong(ncp,varp,start,nelems,(long long*)value); + break; + case CASE(NC_UINT64,NC_UINT): + return putNCvx_ulonglong_uint(ncp,varp,start,nelems,(unsigned int*)value); + break; + case CASE(NC_UINT64,NC_UINT64): + return putNCvx_ulonglong_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value); + break; + case CASE(NC_UINT64,NC_USHORT): + return putNCvx_ulonglong_ushort(ncp,varp,start,nelems,(unsigned short*)value); + break; + + default: + return NC_EBADTYPE; + break; + } + return status; +} + +/**************************************************/ + +int +NC3_get_vara(int ncid, int varid, + const size_t *start, const size_t *edges0, + void *value0, + nc_type memtype) +{ + int status = NC_NOERR; + NC* nc; + NC3_INFO* nc3; + NC_var *varp; + int ii; + size_t iocount; + size_t memtypelen; + signed char* value = (signed char*) value0; /* legally allow ptr arithmetic */ + const size_t* edges = edges0; /* so we can modify for special cases */ + size_t modedges[NC_MAX_VAR_DIMS]; + + status = NC_check_id(ncid, &nc); + if(status != NC_NOERR) + return status; + nc3 = NC3_DATA(nc); + + if(NC_indef(nc3)) + return NC_EINDEFINE; + + status = NC_lookupvar(nc3, varid, &varp); + if(status != NC_NOERR) + return status; + + if(memtype == NC_NAT) memtype=varp->type; + + if(memtype == NC_CHAR && varp->type != NC_CHAR) + return NC_ECHAR; + else if(memtype != NC_CHAR && varp->type == NC_CHAR) + return NC_ECHAR; + + /* If edges is NULL, then this was called from nc_get_var() */ + if(edges == NULL && varp->ndims > 0) { + /* If this is a record variable, then we have to + substitute the number of records into dimension 0. */ + if(varp->shape[0] == 0) { + (void)memcpy((void*)modedges,(void*)varp->shape, + sizeof(size_t)*varp->ndims); + modedges[0] = NC_get_numrecs(nc3); + edges = modedges; + } else + edges = varp->shape; + } + + status = NCcoordck(nc3, varp, start); + if(status != NC_NOERR) + return status; + + status = NCedgeck(nc3, varp, start, edges); + if(status != NC_NOERR) + return status; + + /* Get the size of the memtype */ + memtypelen = nctypelen(memtype); + + if(varp->ndims == 0) /* scalar variable */ + { + return( readNCv(nc3, varp, start, 1, (void*)value, memtype) ); + } + + if(IS_RECVAR(varp)) + { + if(*start + *edges > NC_get_numrecs(nc3)) + return NC_EEDGE; + if(varp->ndims == 1 && nc3->recsize <= varp->len) + { + /* one dimensional && the only record variable */ + return( readNCv(nc3, varp, start, *edges, (void*)value, memtype) ); + } + } + + /* + * find max contiguous + * and accumulate max count for a single io operation + */ + ii = NCiocount(nc3, varp, edges, &iocount); + + if(ii == -1) + { + return( readNCv(nc3, varp, start, iocount, (void*)value, memtype) ); + } + + assert(ii >= 0); + + { /* inline */ + ALLOC_ONSTACK(coord, size_t, varp->ndims); + ALLOC_ONSTACK(upper, size_t, varp->ndims); + const size_t index = ii; + + /* copy in starting indices */ + (void) memcpy(coord, start, varp->ndims * sizeof(size_t)); + + /* set up in maximum indices */ + set_upper(upper, start, edges, &upper[varp->ndims]); + + /* ripple counter */ + while(*coord < *upper) + { + const int lstatus = readNCv(nc3, varp, coord, iocount, (void*)value, memtype); + if(lstatus != NC_NOERR) + { + if(lstatus != NC_ERANGE) + { + status = lstatus; + /* fatal for the loop */ + break; + } + /* else NC_ERANGE, not fatal for the loop */ + if(status == NC_NOERR) + status = lstatus; + } + value += (iocount * memtypelen); + odo1(start, upper, coord, &upper[index], &coord[index]); + } + + FREE_ONSTACK(upper); + FREE_ONSTACK(coord); + } /* end inline */ + + return status; +} + +int +NC3_put_vara(int ncid, int varid, + const size_t *start, const size_t *edges0, + const void *value0, + nc_type memtype) +{ + int status = NC_NOERR; + NC *nc; + NC3_INFO* nc3; + NC_var *varp; + int ii; + size_t iocount; + size_t memtypelen; + signed char* value = (signed char*) value0; /* legally allow ptr arithmetic */ + const size_t* edges = edges0; /* so we can modify for special cases */ + size_t modedges[NC_MAX_VAR_DIMS]; + + status = NC_check_id(ncid, &nc); + if(status != NC_NOERR) + return status; + nc3 = NC3_DATA(nc); + + if(NC_readonly(nc3)) + return NC_EPERM; + + if(NC_indef(nc3)) + return NC_EINDEFINE; + + status = NC_lookupvar(nc3, varid, &varp); + if(status != NC_NOERR) + return status; /*invalid varid */ + + + if(memtype == NC_NAT) memtype=varp->type; + + if(memtype == NC_CHAR && varp->type != NC_CHAR) + return NC_ECHAR; + else if(memtype != NC_CHAR && varp->type == NC_CHAR) + return NC_ECHAR; + + /* Get the size of the memtype */ + memtypelen = nctypelen(memtype); + + /* If edges is NULL, then this was called from nc_get_var() */ + if(edges == NULL && varp->ndims > 0) { + /* If this is a record variable, then we have to + substitute the number of records into dimension 0. */ + if(varp->shape[0] == 0) { + (void)memcpy((void*)modedges,(void*)varp->shape, + sizeof(size_t)*varp->ndims); + modedges[0] = NC_get_numrecs(nc3); + edges = modedges; + } else + edges = varp->shape; + } + + status = NCcoordck(nc3, varp, start); + if(status != NC_NOERR) + return status; + status = NCedgeck(nc3, varp, start, edges); + if(status != NC_NOERR) + return status; + + if(varp->ndims == 0) /* scalar variable */ + { + return( writeNCv(nc3, varp, start, 1, (void*)value, memtype) ); + } + + if(IS_RECVAR(varp)) + { + status = NCvnrecs(nc3, *start + *edges); + if(status != NC_NOERR) + return status; + + if(varp->ndims == 1 + && nc3->recsize <= varp->len) + { + /* one dimensional && the only record variable */ + return( writeNCv(nc3, varp, start, *edges, (void*)value, memtype) ); + } + } + + /* + * find max contiguous + * and accumulate max count for a single io operation + */ + ii = NCiocount(nc3, varp, edges, &iocount); + + if(ii == -1) + { + return( writeNCv(nc3, varp, start, iocount, (void*)value, memtype) ); + } + + assert(ii >= 0); + + { /* inline */ + ALLOC_ONSTACK(coord, size_t, varp->ndims); + ALLOC_ONSTACK(upper, size_t, varp->ndims); + const size_t index = ii; + + /* copy in starting indices */ + (void) memcpy(coord, start, varp->ndims * sizeof(size_t)); + + /* set up in maximum indices */ + set_upper(upper, start, edges, &upper[varp->ndims]); + + /* ripple counter */ + while(*coord < *upper) + { + const int lstatus = writeNCv(nc3, varp, coord, iocount, (void*)value, memtype); + if(lstatus != NC_NOERR) + { + if(lstatus != NC_ERANGE) + { + status = lstatus; + /* fatal for the loop */ + break; + } + /* else NC_ERANGE, not fatal for the loop */ + if(status == NC_NOERR) + status = lstatus; + } + value += (iocount * memtypelen); + odo1(start, upper, coord, &upper[index], &coord[index]); + } + + FREE_ONSTACK(upper); + FREE_ONSTACK(coord); + } /* end inline */ + + return status; +} diff --git a/nc_test/test_get.c b/nc_test/test_get.c new file mode 100644 index 0000000000..a5f6a9b3b5 --- /dev/null +++ b/nc_test/test_get.c @@ -0,0 +1,12262 @@ +/* Do not edit this file. It is produced from the corresponding .m4 source */ +/* + * Copyright (C) 2003, Northwestern University and Argonne National Laboratory + * See COPYRIGHT notice in top-level directory. + */ +/* $Id: test_get.m4 2672 2016-12-03 19:23:53Z wkliao $ */ + + +#include "tests.h" + +#ifdef USE_PNETCDF +#include +#ifndef PNETCDF_VERSION_MAJOR +#error("PNETCDF_VERSION_MAJOR is not defined in pnetcdf.h") +#endif +#ifndef PNETCDF_VERSION_MINOR +#error("PNETCDF_VERSION_MAJOR is not defined in pnetcdf.h") +#endif +#endif + + + + + + + + + + +int +test_nc_get_var1_text(void) +{ + int i=0, err=0, ncid=0, cdf_format=0; + int nok = 0; /* count of valid comparisons */ + int canConvert=0; /* Both text or both numeric */ + size_t j=0, index[MAX_RANK]; + double expect=0; + text value[1]; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var1_text(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var1_text(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var1_text(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) ; + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i]; j++) index[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_get_var1_text(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + /* check if the contents are supposed to be */ + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + /* when file is created the variable contents are generated by + * hash functions */ + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_TEXT); + err = nc_get_var1_text(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, expect,var_type[i], NCT_TEXT)) { + if (1) { + IF (err != NC_NOERR) { + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + + IF (!equal((double)value[0], expect, var_type[i], NCT_TEXT)) { + error("expected: %G, got: %G", expect, (double)value[0]); + } + ELSE_NOK + } + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var1_schar(void) +{ + int i=0, err=0, ncid=0, cdf_format=0; + int nok = 0; /* count of valid comparisons */ + int canConvert=0; /* Both text or both numeric */ + size_t j=0, index[MAX_RANK]; + double expect=0; + schar value[1]; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var1_schar(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var1_schar(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var1_schar(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SCHAR == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i]; j++) index[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_get_var1_schar(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + /* check if the contents are supposed to be */ + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + /* when file is created the variable contents are generated by + * hash functions */ + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_SCHAR); + err = nc_get_var1_schar(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, expect,var_type[i], NCT_SCHAR)) { + if ((expect >= schar_min && expect <= schar_max)) { + IF (err != NC_NOERR) { + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + + IF (!equal((double)value[0], expect, var_type[i], NCT_SCHAR)) { + error("expected: %G, got: %G", expect, (double)value[0]); + } + ELSE_NOK + } + } + +#if defined(USE_PNETCDF) && PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR<7 + else if (cdf_format < NC_FORMAT_CDF5) { +#else + else { +#endif + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var1_uchar(void) +{ + int i=0, err=0, ncid=0, cdf_format=0; + int nok = 0; /* count of valid comparisons */ + int canConvert=0; /* Both text or both numeric */ + size_t j=0, index[MAX_RANK]; + double expect=0; + uchar value[1]; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var1_uchar(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var1_uchar(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var1_uchar(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UCHAR == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i]; j++) index[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_get_var1_uchar(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + /* check if the contents are supposed to be */ + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + /* when file is created the variable contents are generated by + * hash functions */ + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_UCHAR); + err = nc_get_var1_uchar(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, expect,var_type[i], NCT_UCHAR)) { + if ((expect >= uchar_min && expect <= uchar_max)) { + IF (err != NC_NOERR) { + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + + /* in put_vars(), API _put_vara_double() is used to + * write the NC_BYTE variables to files. In this + * case, NC_BYTE variables are treated as signed + * for CDF-1 and 2 formats. Thus, we must skip the + * equal test below for uchar. + */ + if (cdf_format < NC_FORMAT_CDF5 && var_type[i] == NC_BYTE && expect > schar_max) continue; + IF (!equal((double)value[0], expect, var_type[i], NCT_UCHAR)) { + error("expected: %G, got: %G", expect, (double)value[0]); + } + ELSE_NOK + } + } + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=8) + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } +#endif + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var1_short(void) +{ + int i=0, err=0, ncid=0, cdf_format=0; + int nok = 0; /* count of valid comparisons */ + int canConvert=0; /* Both text or both numeric */ + size_t j=0, index[MAX_RANK]; + double expect=0; + short value[1]; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var1_short(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var1_short(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var1_short(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SHORT == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i]; j++) index[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_get_var1_short(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + /* check if the contents are supposed to be */ + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + /* when file is created the variable contents are generated by + * hash functions */ + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_SHORT); + err = nc_get_var1_short(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, expect,var_type[i], NCT_SHORT)) { + if ((expect >= short_min && expect <= short_max)) { + IF (err != NC_NOERR) { + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + + IF (!equal((double)value[0], expect, var_type[i], NCT_SHORT)) { + error("expected: %G, got: %G", expect, (double)value[0]); + } + ELSE_NOK + } + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var1_int(void) +{ + int i=0, err=0, ncid=0, cdf_format=0; + int nok = 0; /* count of valid comparisons */ + int canConvert=0; /* Both text or both numeric */ + size_t j=0, index[MAX_RANK]; + double expect=0; + int value[1]; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var1_int(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var1_int(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var1_int(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_INT == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i]; j++) index[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_get_var1_int(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + /* check if the contents are supposed to be */ + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + /* when file is created the variable contents are generated by + * hash functions */ + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_INT); + err = nc_get_var1_int(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, expect,var_type[i], NCT_INT)) { + if ((expect >= int_min && expect <= int_max)) { + IF (err != NC_NOERR) { + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + + IF (!equal((double)value[0], expect, var_type[i], NCT_INT)) { + error("expected: %G, got: %G", expect, (double)value[0]); + } + ELSE_NOK + } + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var1_long(void) +{ + int i=0, err=0, ncid=0, cdf_format=0; + int nok = 0; /* count of valid comparisons */ + int canConvert=0; /* Both text or both numeric */ + size_t j=0, index[MAX_RANK]; + double expect=0; + long value[1]; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var1_long(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var1_long(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var1_long(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONG == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i]; j++) index[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_get_var1_long(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + /* check if the contents are supposed to be */ + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + /* when file is created the variable contents are generated by + * hash functions */ + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_LONG); + err = nc_get_var1_long(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, expect,var_type[i], NCT_LONG)) { + if ((expect >= long_min && expect <= long_max)) { + IF (err != NC_NOERR) { + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + + IF (!equal((double)value[0], expect, var_type[i], NCT_LONG)) { + error("expected: %G, got: %G", expect, (double)value[0]); + } + ELSE_NOK + } + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var1_float(void) +{ + int i=0, err=0, ncid=0, cdf_format=0; + int nok = 0; /* count of valid comparisons */ + int canConvert=0; /* Both text or both numeric */ + size_t j=0, index[MAX_RANK]; + double expect=0; + float value[1]; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var1_float(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var1_float(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var1_float(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_FLOAT == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i]; j++) index[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_get_var1_float(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + /* check if the contents are supposed to be */ + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + /* when file is created the variable contents are generated by + * hash functions */ + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_FLOAT); + err = nc_get_var1_float(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, expect,var_type[i], NCT_FLOAT)) { + if ((expect >= float_min && expect <= float_max)) { + IF (err != NC_NOERR) { + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + + IF (!equal((double)value[0], expect, var_type[i], NCT_FLOAT)) { + error("expected: %G, got: %G", expect, (double)value[0]); + } + ELSE_NOK + } + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var1_double(void) +{ + int i=0, err=0, ncid=0, cdf_format=0; + int nok = 0; /* count of valid comparisons */ + int canConvert=0; /* Both text or both numeric */ + size_t j=0, index[MAX_RANK]; + double expect=0; + double value[1]; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var1_double(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var1_double(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var1_double(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i]; j++) index[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_get_var1_double(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + /* check if the contents are supposed to be */ + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + /* when file is created the variable contents are generated by + * hash functions */ + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_DOUBLE); + err = nc_get_var1_double(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, expect,var_type[i], NCT_DOUBLE)) { + if ((expect >= double_min && expect <= double_max)) { + IF (err != NC_NOERR) { + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + + IF (!equal((double)value[0], expect, var_type[i], NCT_DOUBLE)) { + error("expected: %G, got: %G", expect, (double)value[0]); + } + ELSE_NOK + } + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var1_ushort(void) +{ + int i=0, err=0, ncid=0, cdf_format=0; + int nok = 0; /* count of valid comparisons */ + int canConvert=0; /* Both text or both numeric */ + size_t j=0, index[MAX_RANK]; + double expect=0; + ushort value[1]; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var1_ushort(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var1_ushort(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var1_ushort(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_USHORT == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i]; j++) index[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_get_var1_ushort(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + /* check if the contents are supposed to be */ + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + /* when file is created the variable contents are generated by + * hash functions */ + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_USHORT); + err = nc_get_var1_ushort(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, expect,var_type[i], NCT_USHORT)) { + if ((expect >= ushort_min && expect <= ushort_max)) { + IF (err != NC_NOERR) { + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + + IF (!equal((double)value[0], expect, var_type[i], NCT_USHORT)) { + error("expected: %G, got: %G", expect, (double)value[0]); + } + ELSE_NOK + } + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var1_uint(void) +{ + int i=0, err=0, ncid=0, cdf_format=0; + int nok = 0; /* count of valid comparisons */ + int canConvert=0; /* Both text or both numeric */ + size_t j=0, index[MAX_RANK]; + double expect=0; + uint value[1]; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var1_uint(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var1_uint(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var1_uint(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UINT == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i]; j++) index[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_get_var1_uint(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + /* check if the contents are supposed to be */ + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + /* when file is created the variable contents are generated by + * hash functions */ + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_UINT); + err = nc_get_var1_uint(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, expect,var_type[i], NCT_UINT)) { + if ((expect >= uint_min && expect <= uint_max)) { + IF (err != NC_NOERR) { + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + + IF (!equal((double)value[0], expect, var_type[i], NCT_UINT)) { + error("expected: %G, got: %G", expect, (double)value[0]); + } + ELSE_NOK + } + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var1_longlong(void) +{ + int i=0, err=0, ncid=0, cdf_format=0; + int nok = 0; /* count of valid comparisons */ + int canConvert=0; /* Both text or both numeric */ + size_t j=0, index[MAX_RANK]; + double expect=0; + longlong value[1]; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var1_longlong(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var1_longlong(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var1_longlong(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONGLONG == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i]; j++) index[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_get_var1_longlong(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + /* check if the contents are supposed to be */ + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + /* when file is created the variable contents are generated by + * hash functions */ + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_LONGLONG); + err = nc_get_var1_longlong(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, expect,var_type[i], NCT_LONGLONG)) { + if ((expect >= longlong_min && expect <= longlong_max)) { + IF (err != NC_NOERR) { + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + + IF (!equal((double)value[0], expect, var_type[i], NCT_LONGLONG)) { + error("expected: %G, got: %G", expect, (double)value[0]); + } + ELSE_NOK + } + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var1_ulonglong(void) +{ + int i=0, err=0, ncid=0, cdf_format=0; + int nok = 0; /* count of valid comparisons */ + int canConvert=0; /* Both text or both numeric */ + size_t j=0, index[MAX_RANK]; + double expect=0; + ulonglong value[1]; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var1_ulonglong(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var1_ulonglong(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var1_ulonglong(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_ULONGLONG == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i]; j++) index[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_get_var1_ulonglong(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + /* check if the contents are supposed to be */ + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + /* when file is created the variable contents are generated by + * hash functions */ + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_ULONGLONG); + err = nc_get_var1_ulonglong(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, expect,var_type[i], NCT_ULONGLONG)) { + if ((expect >= ulonglong_min && expect <= ulonglong_max)) { + IF (err != NC_NOERR) { + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + + IF (!equal((double)value[0], expect, var_type[i], NCT_ULONGLONG)) { + error("expected: %G, got: %G", expect, (double)value[0]); + } + ELSE_NOK + } + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + + + +int +test_nc_get_var_text(void) +{ + int i, err, ncid, cdf_format; + int allInExtRange; /* all values within range of external data type */ + int allInIntRange; /* all values within range of internal data type */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + double expect[MAX_NELS]; + text value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var_text(BAD_ID, 0, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var_text(ncid, BAD_VARID, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var_text(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) ; + + allInExtRange = allInIntRange = 1; + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_TEXT); + if (inRange3(cdf_format, expect[j],var_type[i], NCT_TEXT)) { + if (var_type[i] != NC_CHAR) + allInIntRange &= 1; + } else + allInExtRange = 0; + } + err = nc_get_var_text(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_nels[i]; j++) { + if (1) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_TEXT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var_uchar(void) +{ + int i, err, ncid, cdf_format; + int allInExtRange; /* all values within range of external data type */ + int allInIntRange; /* all values within range of internal data type */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + double expect[MAX_NELS]; + uchar value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var_uchar(BAD_ID, 0, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var_uchar(ncid, BAD_VARID, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var_uchar(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UCHAR == NCT_TEXT); + + allInExtRange = allInIntRange = 1; + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_UCHAR); + if (inRange3(cdf_format, expect[j],var_type[i], NCT_UCHAR)) { + + allInIntRange &= (expect[j] >= uchar_min && expect[j] <= uchar_max); + } else + allInExtRange = 0; + } + err = nc_get_var_uchar(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=8) + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } +#endif + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_nels[i]; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_UCHAR) && (expect[j] >= uchar_min && expect[j] <= uchar_max)) { + + /* in put_vars(), API _put_vara_double() is used to + * write the NC_BYTE variables to files. In this + * case, NC_BYTE variables are treated as signed + * for CDF-1 and 2 formats. Thus, we must skip the + * equal test below for uchar. + */ + if (cdf_format < NC_FORMAT_CDF5 && var_type[i] == NC_BYTE && expect[j] > schar_max) continue; + IF (!equal((double)value[j],expect[j],var_type[i],NCT_UCHAR)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var_schar(void) +{ + int i, err, ncid, cdf_format; + int allInExtRange; /* all values within range of external data type */ + int allInIntRange; /* all values within range of internal data type */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + double expect[MAX_NELS]; + schar value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var_schar(BAD_ID, 0, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var_schar(ncid, BAD_VARID, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var_schar(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SCHAR == NCT_TEXT); + + allInExtRange = allInIntRange = 1; + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_SCHAR); + if (inRange3(cdf_format, expect[j],var_type[i], NCT_SCHAR)) { + + allInIntRange &= (expect[j] >= schar_min && expect[j] <= schar_max); + } else + allInExtRange = 0; + } + err = nc_get_var_schar(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + +#if defined(USE_PNETCDF) && PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR<7 + else if (cdf_format < NC_FORMAT_CDF5) { +#else + else { +#endif + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_nels[i]; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_SCHAR) && (expect[j] >= schar_min && expect[j] <= schar_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_SCHAR)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var_short(void) +{ + int i, err, ncid, cdf_format; + int allInExtRange; /* all values within range of external data type */ + int allInIntRange; /* all values within range of internal data type */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + double expect[MAX_NELS]; + short value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var_short(BAD_ID, 0, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var_short(ncid, BAD_VARID, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var_short(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SHORT == NCT_TEXT); + + allInExtRange = allInIntRange = 1; + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_SHORT); + if (inRange3(cdf_format, expect[j],var_type[i], NCT_SHORT)) { + + allInIntRange &= (expect[j] >= short_min && expect[j] <= short_max); + } else + allInExtRange = 0; + } + err = nc_get_var_short(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_nels[i]; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_SHORT) && (expect[j] >= short_min && expect[j] <= short_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_SHORT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var_int(void) +{ + int i, err, ncid, cdf_format; + int allInExtRange; /* all values within range of external data type */ + int allInIntRange; /* all values within range of internal data type */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + double expect[MAX_NELS]; + int value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var_int(BAD_ID, 0, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var_int(ncid, BAD_VARID, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var_int(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_INT == NCT_TEXT); + + allInExtRange = allInIntRange = 1; + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_INT); + if (inRange3(cdf_format, expect[j],var_type[i], NCT_INT)) { + + allInIntRange &= (expect[j] >= int_min && expect[j] <= int_max); + } else + allInExtRange = 0; + } + err = nc_get_var_int(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_nels[i]; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_INT) && (expect[j] >= int_min && expect[j] <= int_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_INT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var_long(void) +{ + int i, err, ncid, cdf_format; + int allInExtRange; /* all values within range of external data type */ + int allInIntRange; /* all values within range of internal data type */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + double expect[MAX_NELS]; + long value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var_long(BAD_ID, 0, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var_long(ncid, BAD_VARID, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var_long(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONG == NCT_TEXT); + + allInExtRange = allInIntRange = 1; + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_LONG); + if (inRange3(cdf_format, expect[j],var_type[i], NCT_LONG)) { + + allInIntRange &= (expect[j] >= long_min && expect[j] <= long_max); + } else + allInExtRange = 0; + } + err = nc_get_var_long(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_nels[i]; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_LONG) && (expect[j] >= long_min && expect[j] <= long_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_LONG)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var_float(void) +{ + int i, err, ncid, cdf_format; + int allInExtRange; /* all values within range of external data type */ + int allInIntRange; /* all values within range of internal data type */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + double expect[MAX_NELS]; + float value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var_float(BAD_ID, 0, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var_float(ncid, BAD_VARID, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var_float(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_FLOAT == NCT_TEXT); + + allInExtRange = allInIntRange = 1; + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_FLOAT); + if (inRange3(cdf_format, expect[j],var_type[i], NCT_FLOAT)) { + + allInIntRange &= (expect[j] >= float_min && expect[j] <= float_max); + } else + allInExtRange = 0; + } + err = nc_get_var_float(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_nels[i]; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_FLOAT) && (expect[j] >= float_min && expect[j] <= float_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_FLOAT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var_double(void) +{ + int i, err, ncid, cdf_format; + int allInExtRange; /* all values within range of external data type */ + int allInIntRange; /* all values within range of internal data type */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + double expect[MAX_NELS]; + double value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var_double(BAD_ID, 0, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var_double(ncid, BAD_VARID, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var_double(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT); + + allInExtRange = allInIntRange = 1; + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_DOUBLE); + if (inRange3(cdf_format, expect[j],var_type[i], NCT_DOUBLE)) { + + allInIntRange &= (expect[j] >= double_min && expect[j] <= double_max); + } else + allInExtRange = 0; + } + err = nc_get_var_double(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_nels[i]; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_DOUBLE) && (expect[j] >= double_min && expect[j] <= double_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_DOUBLE)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var_ushort(void) +{ + int i, err, ncid, cdf_format; + int allInExtRange; /* all values within range of external data type */ + int allInIntRange; /* all values within range of internal data type */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + double expect[MAX_NELS]; + ushort value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var_ushort(BAD_ID, 0, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var_ushort(ncid, BAD_VARID, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var_ushort(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_USHORT == NCT_TEXT); + + allInExtRange = allInIntRange = 1; + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_USHORT); + if (inRange3(cdf_format, expect[j],var_type[i], NCT_USHORT)) { + + allInIntRange &= (expect[j] >= ushort_min && expect[j] <= ushort_max); + } else + allInExtRange = 0; + } + err = nc_get_var_ushort(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_nels[i]; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_USHORT) && (expect[j] >= ushort_min && expect[j] <= ushort_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_USHORT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var_uint(void) +{ + int i, err, ncid, cdf_format; + int allInExtRange; /* all values within range of external data type */ + int allInIntRange; /* all values within range of internal data type */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + double expect[MAX_NELS]; + uint value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var_uint(BAD_ID, 0, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var_uint(ncid, BAD_VARID, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var_uint(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UINT == NCT_TEXT); + + allInExtRange = allInIntRange = 1; + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_UINT); + if (inRange3(cdf_format, expect[j],var_type[i], NCT_UINT)) { + + allInIntRange &= (expect[j] >= uint_min && expect[j] <= uint_max); + } else + allInExtRange = 0; + } + err = nc_get_var_uint(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_nels[i]; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_UINT) && (expect[j] >= uint_min && expect[j] <= uint_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_UINT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var_longlong(void) +{ + int i, err, ncid, cdf_format; + int allInExtRange; /* all values within range of external data type */ + int allInIntRange; /* all values within range of internal data type */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + double expect[MAX_NELS]; + longlong value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var_longlong(BAD_ID, 0, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var_longlong(ncid, BAD_VARID, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var_longlong(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONGLONG == NCT_TEXT); + + allInExtRange = allInIntRange = 1; + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_LONGLONG); + if (inRange3(cdf_format, expect[j],var_type[i], NCT_LONGLONG)) { + + allInIntRange &= (expect[j] >= longlong_min && expect[j] <= longlong_max); + } else + allInExtRange = 0; + } + err = nc_get_var_longlong(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_nels[i]; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_LONGLONG) && (expect[j] >= longlong_min && expect[j] <= longlong_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_LONGLONG)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_var_ulonglong(void) +{ + int i, err, ncid, cdf_format; + int allInExtRange; /* all values within range of external data type */ + int allInIntRange; /* all values within range of internal data type */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + double expect[MAX_NELS]; + ulonglong value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var_ulonglong(BAD_ID, 0, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_get_var_ulonglong(ncid, BAD_VARID, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var_ulonglong(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_ULONGLONG == NCT_TEXT); + + allInExtRange = allInIntRange = 1; + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_ULONGLONG); + if (inRange3(cdf_format, expect[j],var_type[i], NCT_ULONGLONG)) { + + allInIntRange &= (expect[j] >= ulonglong_min && expect[j] <= ulonglong_max); + } else + allInExtRange = 0; + } + err = nc_get_var_ulonglong(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_nels[i]; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_ULONGLONG) && (expect[j] >= ulonglong_min && expect[j] <= ulonglong_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_ULONGLONG)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + + + +int +test_nc_get_vara_text(void) +{ + int i, k, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK], mid[MAX_RANK]; + double expect[MAX_NELS]; + text value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vara_text(BAD_ID, 0, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vara_text(ncid, BAD_VARID, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vara_text(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) ; + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; /* causes NC_EINVALCOORDS */ + err = nc_get_vara_text(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; /* causes NC_EEDGE */ + err = nc_get_vara_text(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + } + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[*]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_rank[i] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vara_text(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vara_text(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + } + + err = nc_get_vara_text(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_TEXT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_TEXT) && + 1) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + size_t nels = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + int d; + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index[d] += start[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_TEXT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_TEXT)) { + if (var_type[i] != NC_CHAR) + allInIntRange &= 1; + } else + allInExtRange = 0; + } + err = nc_get_vara_text(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (1) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_TEXT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vara_uchar(void) +{ + int i, k, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK], mid[MAX_RANK]; + double expect[MAX_NELS]; + uchar value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vara_uchar(BAD_ID, 0, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vara_uchar(ncid, BAD_VARID, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vara_uchar(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UCHAR == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; /* causes NC_EINVALCOORDS */ + err = nc_get_vara_uchar(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; /* causes NC_EEDGE */ + err = nc_get_vara_uchar(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + } + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[*]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_rank[i] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vara_uchar(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vara_uchar(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + } + + err = nc_get_vara_uchar(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_UCHAR); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_UCHAR) && + (expect[0] >= uchar_min && expect[0] <= uchar_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); +#endif + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + size_t nels = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + int d; + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index[d] += start[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_UCHAR); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_UCHAR)) { + + allInIntRange &= (expect[j] >= uchar_min && expect[j] <= uchar_max); + } else + allInExtRange = 0; + } + err = nc_get_vara_uchar(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=8) + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } +#endif + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_UCHAR) && (expect[j] >= uchar_min && expect[j] <= uchar_max)) { + + /* in put_vars(), API _put_vara_double() is used to + * write the NC_BYTE variables to files. In this + * case, NC_BYTE variables are treated as signed + * for CDF-1 and 2 formats. Thus, we must skip the + * equal test below for uchar. + */ + if (cdf_format < NC_FORMAT_CDF5 && var_type[i] == NC_BYTE && expect[j] > schar_max) continue; + IF (!equal((double)value[j],expect[j],var_type[i],NCT_UCHAR)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vara_schar(void) +{ + int i, k, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK], mid[MAX_RANK]; + double expect[MAX_NELS]; + schar value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vara_schar(BAD_ID, 0, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vara_schar(ncid, BAD_VARID, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vara_schar(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SCHAR == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; /* causes NC_EINVALCOORDS */ + err = nc_get_vara_schar(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; /* causes NC_EEDGE */ + err = nc_get_vara_schar(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + } + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[*]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_rank[i] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vara_schar(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vara_schar(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + } + + err = nc_get_vara_schar(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_SCHAR); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_SCHAR) && + (expect[0] >= schar_min && expect[0] <= schar_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + size_t nels = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + int d; + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index[d] += start[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_SCHAR); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_SCHAR)) { + + allInIntRange &= (expect[j] >= schar_min && expect[j] <= schar_max); + } else + allInExtRange = 0; + } + err = nc_get_vara_schar(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + +#if defined(USE_PNETCDF) && PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR<7 + else if (cdf_format < NC_FORMAT_CDF5) { +#else + else { +#endif + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_SCHAR) && (expect[j] >= schar_min && expect[j] <= schar_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_SCHAR)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vara_short(void) +{ + int i, k, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK], mid[MAX_RANK]; + double expect[MAX_NELS]; + short value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vara_short(BAD_ID, 0, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vara_short(ncid, BAD_VARID, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vara_short(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SHORT == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; /* causes NC_EINVALCOORDS */ + err = nc_get_vara_short(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; /* causes NC_EEDGE */ + err = nc_get_vara_short(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + } + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[*]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_rank[i] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vara_short(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vara_short(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + } + + err = nc_get_vara_short(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_SHORT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_SHORT) && + (expect[0] >= short_min && expect[0] <= short_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + size_t nels = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + int d; + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index[d] += start[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_SHORT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_SHORT)) { + + allInIntRange &= (expect[j] >= short_min && expect[j] <= short_max); + } else + allInExtRange = 0; + } + err = nc_get_vara_short(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_SHORT) && (expect[j] >= short_min && expect[j] <= short_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_SHORT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vara_int(void) +{ + int i, k, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK], mid[MAX_RANK]; + double expect[MAX_NELS]; + int value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vara_int(BAD_ID, 0, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vara_int(ncid, BAD_VARID, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vara_int(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_INT == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; /* causes NC_EINVALCOORDS */ + err = nc_get_vara_int(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; /* causes NC_EEDGE */ + err = nc_get_vara_int(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + } + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[*]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_rank[i] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vara_int(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vara_int(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + } + + err = nc_get_vara_int(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_INT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_INT) && + (expect[0] >= int_min && expect[0] <= int_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + size_t nels = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + int d; + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index[d] += start[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_INT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_INT)) { + + allInIntRange &= (expect[j] >= int_min && expect[j] <= int_max); + } else + allInExtRange = 0; + } + err = nc_get_vara_int(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_INT) && (expect[j] >= int_min && expect[j] <= int_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_INT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vara_long(void) +{ + int i, k, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK], mid[MAX_RANK]; + double expect[MAX_NELS]; + long value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vara_long(BAD_ID, 0, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vara_long(ncid, BAD_VARID, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vara_long(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONG == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; /* causes NC_EINVALCOORDS */ + err = nc_get_vara_long(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; /* causes NC_EEDGE */ + err = nc_get_vara_long(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + } + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[*]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_rank[i] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vara_long(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vara_long(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + } + + err = nc_get_vara_long(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_LONG); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_LONG) && + (expect[0] >= long_min && expect[0] <= long_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + size_t nels = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + int d; + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index[d] += start[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_LONG); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_LONG)) { + + allInIntRange &= (expect[j] >= long_min && expect[j] <= long_max); + } else + allInExtRange = 0; + } + err = nc_get_vara_long(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_LONG) && (expect[j] >= long_min && expect[j] <= long_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_LONG)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vara_float(void) +{ + int i, k, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK], mid[MAX_RANK]; + double expect[MAX_NELS]; + float value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vara_float(BAD_ID, 0, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vara_float(ncid, BAD_VARID, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vara_float(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_FLOAT == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; /* causes NC_EINVALCOORDS */ + err = nc_get_vara_float(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; /* causes NC_EEDGE */ + err = nc_get_vara_float(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + } + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[*]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_rank[i] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vara_float(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vara_float(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + } + + err = nc_get_vara_float(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_FLOAT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_FLOAT) && + (expect[0] >= float_min && expect[0] <= float_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + size_t nels = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + int d; + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index[d] += start[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_FLOAT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_FLOAT)) { + + allInIntRange &= (expect[j] >= float_min && expect[j] <= float_max); + } else + allInExtRange = 0; + } + err = nc_get_vara_float(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_FLOAT) && (expect[j] >= float_min && expect[j] <= float_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_FLOAT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vara_double(void) +{ + int i, k, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK], mid[MAX_RANK]; + double expect[MAX_NELS]; + double value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vara_double(BAD_ID, 0, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vara_double(ncid, BAD_VARID, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vara_double(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; /* causes NC_EINVALCOORDS */ + err = nc_get_vara_double(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; /* causes NC_EEDGE */ + err = nc_get_vara_double(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + } + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[*]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_rank[i] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vara_double(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vara_double(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + } + + err = nc_get_vara_double(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_DOUBLE); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_DOUBLE) && + (expect[0] >= double_min && expect[0] <= double_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + size_t nels = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + int d; + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index[d] += start[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_DOUBLE); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_DOUBLE)) { + + allInIntRange &= (expect[j] >= double_min && expect[j] <= double_max); + } else + allInExtRange = 0; + } + err = nc_get_vara_double(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_DOUBLE) && (expect[j] >= double_min && expect[j] <= double_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_DOUBLE)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vara_ushort(void) +{ + int i, k, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK], mid[MAX_RANK]; + double expect[MAX_NELS]; + ushort value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vara_ushort(BAD_ID, 0, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vara_ushort(ncid, BAD_VARID, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vara_ushort(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_USHORT == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; /* causes NC_EINVALCOORDS */ + err = nc_get_vara_ushort(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; /* causes NC_EEDGE */ + err = nc_get_vara_ushort(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + } + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[*]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_rank[i] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vara_ushort(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vara_ushort(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + } + + err = nc_get_vara_ushort(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_USHORT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_USHORT) && + (expect[0] >= ushort_min && expect[0] <= ushort_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + size_t nels = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + int d; + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index[d] += start[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_USHORT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_USHORT)) { + + allInIntRange &= (expect[j] >= ushort_min && expect[j] <= ushort_max); + } else + allInExtRange = 0; + } + err = nc_get_vara_ushort(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_USHORT) && (expect[j] >= ushort_min && expect[j] <= ushort_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_USHORT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vara_uint(void) +{ + int i, k, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK], mid[MAX_RANK]; + double expect[MAX_NELS]; + uint value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vara_uint(BAD_ID, 0, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vara_uint(ncid, BAD_VARID, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vara_uint(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UINT == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; /* causes NC_EINVALCOORDS */ + err = nc_get_vara_uint(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; /* causes NC_EEDGE */ + err = nc_get_vara_uint(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + } + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[*]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_rank[i] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vara_uint(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vara_uint(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + } + + err = nc_get_vara_uint(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_UINT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_UINT) && + (expect[0] >= uint_min && expect[0] <= uint_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + size_t nels = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + int d; + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index[d] += start[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_UINT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_UINT)) { + + allInIntRange &= (expect[j] >= uint_min && expect[j] <= uint_max); + } else + allInExtRange = 0; + } + err = nc_get_vara_uint(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_UINT) && (expect[j] >= uint_min && expect[j] <= uint_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_UINT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vara_longlong(void) +{ + int i, k, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK], mid[MAX_RANK]; + double expect[MAX_NELS]; + longlong value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vara_longlong(BAD_ID, 0, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vara_longlong(ncid, BAD_VARID, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vara_longlong(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONGLONG == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; /* causes NC_EINVALCOORDS */ + err = nc_get_vara_longlong(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; /* causes NC_EEDGE */ + err = nc_get_vara_longlong(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + } + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[*]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_rank[i] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vara_longlong(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vara_longlong(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + } + + err = nc_get_vara_longlong(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_LONGLONG); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_LONGLONG) && + (expect[0] >= longlong_min && expect[0] <= longlong_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + size_t nels = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + int d; + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index[d] += start[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_LONGLONG); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_LONGLONG)) { + + allInIntRange &= (expect[j] >= longlong_min && expect[j] <= longlong_max); + } else + allInExtRange = 0; + } + err = nc_get_vara_longlong(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_LONGLONG) && (expect[j] >= longlong_min && expect[j] <= longlong_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_LONGLONG)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vara_ulonglong(void) +{ + int i, k, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK], mid[MAX_RANK]; + double expect[MAX_NELS]; + ulonglong value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vara_ulonglong(BAD_ID, 0, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vara_ulonglong(ncid, BAD_VARID, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vara_ulonglong(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_ULONGLONG == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; /* causes NC_EINVALCOORDS */ + err = nc_get_vara_ulonglong(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; /* causes NC_EEDGE */ + err = nc_get_vara_ulonglong(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + } + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[*]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_rank[i] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vara_ulonglong(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vara_ulonglong(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + } + + err = nc_get_vara_ulonglong(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_ULONGLONG); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_ULONGLONG) && + (expect[0] >= ulonglong_min && expect[0] <= ulonglong_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + size_t nels = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + int d; + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index[d] += start[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_ULONGLONG); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_ULONGLONG)) { + + allInIntRange &= (expect[j] >= ulonglong_min && expect[j] <= ulonglong_max); + } else + allInExtRange = 0; + } + err = nc_get_vara_ulonglong(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_ULONGLONG) && (expect[j] >= ulonglong_min && expect[j] <= ulonglong_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i],NCT_ULONGLONG)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + + + +int +test_nc_get_vars_text(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + double expect[MAX_NELS]; + text value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vars_text(BAD_ID, 0, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vars_text(ncid, BAD_VARID, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_text(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) ; + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_vars_text(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_vars_text(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_vars_text(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vars_text(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vars_text(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_vars_text(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_vars_text(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_TEXT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_TEXT) && + 1) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_TEXT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_TEXT)) { + if (var_type[i] != NC_CHAR) + allInIntRange &= 1; + } else + allInExtRange = 0; + } + err = nc_get_vars_text(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (1) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_TEXT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vars_uchar(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + double expect[MAX_NELS]; + uchar value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vars_uchar(BAD_ID, 0, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vars_uchar(ncid, BAD_VARID, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_uchar(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UCHAR == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_vars_uchar(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_vars_uchar(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_vars_uchar(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vars_uchar(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vars_uchar(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_vars_uchar(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_vars_uchar(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_UCHAR); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_UCHAR) && + (expect[0] >= uchar_min && expect[0] <= uchar_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); +#endif + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_UCHAR); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_UCHAR)) { + + allInIntRange &= (expect[j] >= uchar_min && expect[j] <= uchar_max); + } else + allInExtRange = 0; + } + err = nc_get_vars_uchar(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=8) + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } +#endif + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_UCHAR) && (expect[j] >= uchar_min && expect[j] <= uchar_max)) { + + /* in put_vars(), API _put_vara_double() is used to + * write the NC_BYTE variables to files. In this + * case, NC_BYTE variables are treated as signed + * for CDF-1 and 2 formats. Thus, we must skip the + * equal test below for uchar. + */ + if (cdf_format < NC_FORMAT_CDF5 && var_type[i] == NC_BYTE && expect[j] > schar_max) continue; + IF (!equal((double)value[j],expect[j],var_type[i], NCT_UCHAR)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vars_schar(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + double expect[MAX_NELS]; + schar value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vars_schar(BAD_ID, 0, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vars_schar(ncid, BAD_VARID, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_schar(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SCHAR == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_vars_schar(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_vars_schar(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_vars_schar(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vars_schar(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vars_schar(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_vars_schar(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_vars_schar(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_SCHAR); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_SCHAR) && + (expect[0] >= schar_min && expect[0] <= schar_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_SCHAR); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_SCHAR)) { + + allInIntRange &= (expect[j] >= schar_min && expect[j] <= schar_max); + } else + allInExtRange = 0; + } + err = nc_get_vars_schar(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + +#if defined(USE_PNETCDF) && PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR<7 + else if (cdf_format < NC_FORMAT_CDF5) { +#else + else { +#endif + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_SCHAR) && (expect[j] >= schar_min && expect[j] <= schar_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_SCHAR)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vars_short(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + double expect[MAX_NELS]; + short value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vars_short(BAD_ID, 0, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vars_short(ncid, BAD_VARID, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_short(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SHORT == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_vars_short(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_vars_short(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_vars_short(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vars_short(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vars_short(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_vars_short(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_vars_short(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_SHORT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_SHORT) && + (expect[0] >= short_min && expect[0] <= short_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_SHORT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_SHORT)) { + + allInIntRange &= (expect[j] >= short_min && expect[j] <= short_max); + } else + allInExtRange = 0; + } + err = nc_get_vars_short(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_SHORT) && (expect[j] >= short_min && expect[j] <= short_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_SHORT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vars_int(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + double expect[MAX_NELS]; + int value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vars_int(BAD_ID, 0, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vars_int(ncid, BAD_VARID, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_int(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_INT == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_vars_int(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_vars_int(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_vars_int(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vars_int(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vars_int(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_vars_int(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_vars_int(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_INT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_INT) && + (expect[0] >= int_min && expect[0] <= int_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_INT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_INT)) { + + allInIntRange &= (expect[j] >= int_min && expect[j] <= int_max); + } else + allInExtRange = 0; + } + err = nc_get_vars_int(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_INT) && (expect[j] >= int_min && expect[j] <= int_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_INT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vars_long(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + double expect[MAX_NELS]; + long value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vars_long(BAD_ID, 0, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vars_long(ncid, BAD_VARID, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_long(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONG == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_vars_long(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_vars_long(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_vars_long(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vars_long(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vars_long(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_vars_long(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_vars_long(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_LONG); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_LONG) && + (expect[0] >= long_min && expect[0] <= long_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_LONG); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_LONG)) { + + allInIntRange &= (expect[j] >= long_min && expect[j] <= long_max); + } else + allInExtRange = 0; + } + err = nc_get_vars_long(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_LONG) && (expect[j] >= long_min && expect[j] <= long_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_LONG)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vars_float(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + double expect[MAX_NELS]; + float value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vars_float(BAD_ID, 0, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vars_float(ncid, BAD_VARID, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_float(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_FLOAT == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_vars_float(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_vars_float(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_vars_float(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vars_float(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vars_float(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_vars_float(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_vars_float(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_FLOAT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_FLOAT) && + (expect[0] >= float_min && expect[0] <= float_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_FLOAT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_FLOAT)) { + + allInIntRange &= (expect[j] >= float_min && expect[j] <= float_max); + } else + allInExtRange = 0; + } + err = nc_get_vars_float(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_FLOAT) && (expect[j] >= float_min && expect[j] <= float_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_FLOAT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vars_double(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + double expect[MAX_NELS]; + double value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vars_double(BAD_ID, 0, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vars_double(ncid, BAD_VARID, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_double(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_vars_double(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_vars_double(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_vars_double(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vars_double(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vars_double(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_vars_double(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_vars_double(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_DOUBLE); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_DOUBLE) && + (expect[0] >= double_min && expect[0] <= double_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_DOUBLE); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_DOUBLE)) { + + allInIntRange &= (expect[j] >= double_min && expect[j] <= double_max); + } else + allInExtRange = 0; + } + err = nc_get_vars_double(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_DOUBLE) && (expect[j] >= double_min && expect[j] <= double_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_DOUBLE)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vars_ushort(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + double expect[MAX_NELS]; + ushort value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vars_ushort(BAD_ID, 0, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vars_ushort(ncid, BAD_VARID, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_ushort(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_USHORT == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_vars_ushort(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_vars_ushort(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_vars_ushort(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vars_ushort(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vars_ushort(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_vars_ushort(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_vars_ushort(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_USHORT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_USHORT) && + (expect[0] >= ushort_min && expect[0] <= ushort_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_USHORT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_USHORT)) { + + allInIntRange &= (expect[j] >= ushort_min && expect[j] <= ushort_max); + } else + allInExtRange = 0; + } + err = nc_get_vars_ushort(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_USHORT) && (expect[j] >= ushort_min && expect[j] <= ushort_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_USHORT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vars_uint(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + double expect[MAX_NELS]; + uint value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vars_uint(BAD_ID, 0, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vars_uint(ncid, BAD_VARID, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_uint(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UINT == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_vars_uint(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_vars_uint(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_vars_uint(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vars_uint(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vars_uint(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_vars_uint(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_vars_uint(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_UINT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_UINT) && + (expect[0] >= uint_min && expect[0] <= uint_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_UINT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_UINT)) { + + allInIntRange &= (expect[j] >= uint_min && expect[j] <= uint_max); + } else + allInExtRange = 0; + } + err = nc_get_vars_uint(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_UINT) && (expect[j] >= uint_min && expect[j] <= uint_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_UINT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vars_longlong(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + double expect[MAX_NELS]; + longlong value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vars_longlong(BAD_ID, 0, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vars_longlong(ncid, BAD_VARID, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_longlong(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONGLONG == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_vars_longlong(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_vars_longlong(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_vars_longlong(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vars_longlong(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vars_longlong(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_vars_longlong(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_vars_longlong(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_LONGLONG); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_LONGLONG) && + (expect[0] >= longlong_min && expect[0] <= longlong_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_LONGLONG); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_LONGLONG)) { + + allInIntRange &= (expect[j] >= longlong_min && expect[j] <= longlong_max); + } else + allInExtRange = 0; + } + err = nc_get_vars_longlong(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_LONGLONG) && (expect[j] >= longlong_min && expect[j] <= longlong_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_LONGLONG)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_vars_ulonglong(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + double expect[MAX_NELS]; + ulonglong value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_vars_ulonglong(BAD_ID, 0, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_vars_ulonglong(ncid, BAD_VARID, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_ulonglong(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_ULONGLONG == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_vars_ulonglong(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_vars_ulonglong(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_vars_ulonglong(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vars_ulonglong(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_vars_ulonglong(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_vars_ulonglong(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_vars_ulonglong(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_ULONGLONG); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_ULONGLONG) && + (expect[0] >= ulonglong_min && expect[0] <= ulonglong_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_ULONGLONG); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_ULONGLONG)) { + + allInIntRange &= (expect[j] >= ulonglong_min && expect[j] <= ulonglong_max); + } else + allInExtRange = 0; + } + err = nc_get_vars_ulonglong(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_ULONGLONG) && (expect[j] >= ulonglong_min && expect[j] <= ulonglong_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_ULONGLONG)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + + + +int +test_nc_get_varm_text(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + double expect[MAX_NELS]; + text value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_varm_text(BAD_ID, 0, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_varm_text(ncid, BAD_VARID, NULL, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_text(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) ; + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_varm_text(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_varm_text(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_varm_text(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_varm_text(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_varm_text(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_varm_text(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_varm_text(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_TEXT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_TEXT) && + 1) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_TEXT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_TEXT)) { + if (var_type[i] != NC_CHAR) + allInIntRange &= 1; + } else + allInExtRange = 0; + } + err = nc_get_varm_text(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (1) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_TEXT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_varm_uchar(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + double expect[MAX_NELS]; + uchar value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_varm_uchar(BAD_ID, 0, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_varm_uchar(ncid, BAD_VARID, NULL, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_uchar(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UCHAR == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_varm_uchar(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_varm_uchar(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_varm_uchar(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_varm_uchar(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_varm_uchar(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_varm_uchar(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_varm_uchar(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_UCHAR); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_UCHAR) && + (expect[0] >= uchar_min && expect[0] <= uchar_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); +#endif + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_UCHAR); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_UCHAR)) { + + allInIntRange &= (expect[j] >= uchar_min && expect[j] <= uchar_max); + } else + allInExtRange = 0; + } + err = nc_get_varm_uchar(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=8) + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } +#endif + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_UCHAR) && (expect[j] >= uchar_min && expect[j] <= uchar_max)) { + + /* in put_vars(), API _put_vara_double() is used to + * write the NC_BYTE variables to files. In this + * case, NC_BYTE variables are treated as signed + * for CDF-1 and 2 formats. Thus, we must skip the + * equal test below for uchar. + */ + if (cdf_format < NC_FORMAT_CDF5 && var_type[i] == NC_BYTE && expect[j] > schar_max) continue; + IF (!equal((double)value[j],expect[j],var_type[i], NCT_UCHAR)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_varm_schar(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + double expect[MAX_NELS]; + schar value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_varm_schar(BAD_ID, 0, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_varm_schar(ncid, BAD_VARID, NULL, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_schar(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SCHAR == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_varm_schar(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_varm_schar(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_varm_schar(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_varm_schar(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_varm_schar(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_varm_schar(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_varm_schar(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_SCHAR); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_SCHAR) && + (expect[0] >= schar_min && expect[0] <= schar_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_SCHAR); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_SCHAR)) { + + allInIntRange &= (expect[j] >= schar_min && expect[j] <= schar_max); + } else + allInExtRange = 0; + } + err = nc_get_varm_schar(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + +#if defined(USE_PNETCDF) && PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR<7 + else if (cdf_format < NC_FORMAT_CDF5) { +#else + else { +#endif + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_SCHAR) && (expect[j] >= schar_min && expect[j] <= schar_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_SCHAR)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_varm_short(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + double expect[MAX_NELS]; + short value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_varm_short(BAD_ID, 0, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_varm_short(ncid, BAD_VARID, NULL, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_short(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SHORT == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_varm_short(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_varm_short(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_varm_short(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_varm_short(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_varm_short(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_varm_short(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_varm_short(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_SHORT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_SHORT) && + (expect[0] >= short_min && expect[0] <= short_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_SHORT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_SHORT)) { + + allInIntRange &= (expect[j] >= short_min && expect[j] <= short_max); + } else + allInExtRange = 0; + } + err = nc_get_varm_short(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_SHORT) && (expect[j] >= short_min && expect[j] <= short_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_SHORT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_varm_int(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + double expect[MAX_NELS]; + int value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_varm_int(BAD_ID, 0, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_varm_int(ncid, BAD_VARID, NULL, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_int(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_INT == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_varm_int(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_varm_int(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_varm_int(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_varm_int(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_varm_int(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_varm_int(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_varm_int(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_INT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_INT) && + (expect[0] >= int_min && expect[0] <= int_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_INT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_INT)) { + + allInIntRange &= (expect[j] >= int_min && expect[j] <= int_max); + } else + allInExtRange = 0; + } + err = nc_get_varm_int(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_INT) && (expect[j] >= int_min && expect[j] <= int_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_INT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_varm_long(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + double expect[MAX_NELS]; + long value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_varm_long(BAD_ID, 0, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_varm_long(ncid, BAD_VARID, NULL, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_long(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONG == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_varm_long(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_varm_long(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_varm_long(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_varm_long(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_varm_long(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_varm_long(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_varm_long(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_LONG); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_LONG) && + (expect[0] >= long_min && expect[0] <= long_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_LONG); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_LONG)) { + + allInIntRange &= (expect[j] >= long_min && expect[j] <= long_max); + } else + allInExtRange = 0; + } + err = nc_get_varm_long(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_LONG) && (expect[j] >= long_min && expect[j] <= long_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_LONG)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_varm_float(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + double expect[MAX_NELS]; + float value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_varm_float(BAD_ID, 0, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_varm_float(ncid, BAD_VARID, NULL, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_float(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_FLOAT == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_varm_float(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_varm_float(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_varm_float(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_varm_float(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_varm_float(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_varm_float(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_varm_float(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_FLOAT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_FLOAT) && + (expect[0] >= float_min && expect[0] <= float_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_FLOAT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_FLOAT)) { + + allInIntRange &= (expect[j] >= float_min && expect[j] <= float_max); + } else + allInExtRange = 0; + } + err = nc_get_varm_float(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_FLOAT) && (expect[j] >= float_min && expect[j] <= float_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_FLOAT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_varm_double(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + double expect[MAX_NELS]; + double value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_varm_double(BAD_ID, 0, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_varm_double(ncid, BAD_VARID, NULL, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_double(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_varm_double(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_varm_double(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_varm_double(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_varm_double(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_varm_double(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_varm_double(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_varm_double(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_DOUBLE); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_DOUBLE) && + (expect[0] >= double_min && expect[0] <= double_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_DOUBLE); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_DOUBLE)) { + + allInIntRange &= (expect[j] >= double_min && expect[j] <= double_max); + } else + allInExtRange = 0; + } + err = nc_get_varm_double(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_DOUBLE) && (expect[j] >= double_min && expect[j] <= double_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_DOUBLE)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_varm_ushort(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + double expect[MAX_NELS]; + ushort value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_varm_ushort(BAD_ID, 0, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_varm_ushort(ncid, BAD_VARID, NULL, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_ushort(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_USHORT == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_varm_ushort(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_varm_ushort(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_varm_ushort(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_varm_ushort(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_varm_ushort(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_varm_ushort(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_varm_ushort(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_USHORT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_USHORT) && + (expect[0] >= ushort_min && expect[0] <= ushort_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_USHORT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_USHORT)) { + + allInIntRange &= (expect[j] >= ushort_min && expect[j] <= ushort_max); + } else + allInExtRange = 0; + } + err = nc_get_varm_ushort(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_USHORT) && (expect[j] >= ushort_min && expect[j] <= ushort_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_USHORT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_varm_uint(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + double expect[MAX_NELS]; + uint value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_varm_uint(BAD_ID, 0, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_varm_uint(ncid, BAD_VARID, NULL, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_uint(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UINT == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_varm_uint(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_varm_uint(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_varm_uint(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_varm_uint(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_varm_uint(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_varm_uint(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_varm_uint(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_UINT); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_UINT) && + (expect[0] >= uint_min && expect[0] <= uint_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_UINT); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_UINT)) { + + allInIntRange &= (expect[j] >= uint_min && expect[j] <= uint_max); + } else + allInExtRange = 0; + } + err = nc_get_varm_uint(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_UINT) && (expect[j] >= uint_min && expect[j] <= uint_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_UINT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_varm_longlong(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + double expect[MAX_NELS]; + longlong value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_varm_longlong(BAD_ID, 0, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_varm_longlong(ncid, BAD_VARID, NULL, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_longlong(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONGLONG == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_varm_longlong(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_varm_longlong(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_varm_longlong(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_varm_longlong(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_varm_longlong(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_varm_longlong(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_varm_longlong(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_LONGLONG); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_LONGLONG) && + (expect[0] >= longlong_min && expect[0] <= longlong_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_LONGLONG); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_LONGLONG)) { + + allInIntRange &= (expect[j] >= longlong_min && expect[j] <= longlong_max); + } else + allInExtRange = 0; + } + err = nc_get_varm_longlong(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_LONGLONG) && (expect[j] >= longlong_min && expect[j] <= longlong_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_LONGLONG)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_varm_ulonglong(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format; + int allInExtRange; /* all values within external range? */ + int allInIntRange; /* all values within internal range? */ + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* count of valid comparisons */ + int canConvert; /* Both text or both numeric */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + double expect[MAX_NELS]; + ulonglong value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_varm_ulonglong(BAD_ID, 0, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_varm_ulonglong(ncid, BAD_VARID, NULL, NULL, NULL, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars_ulonglong(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_ULONGLONG == NCT_TEXT); + + for (j = 0; j < var_rank[i]; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i]; j++) { + start[j] = var_shape[i][j]; + err = nc_get_varm_ulonglong(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_varm_ulonglong(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + edge[j] = 1; + stride[j] = 0; + err = nc_get_varm_ulonglong(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i]; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_varm_ulonglong(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + start[j] = var_shape[i][j]+1; /* should cause NC_EINVALCOORDS */ + err = nc_get_varm_ulonglong(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + start[j] = 0; +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=7) + stride[j] = 0; + err = nc_get_varm_ulonglong(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + stride[j] = 1; +#endif + } + + err = nc_get_varm_ulonglong(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } else if (var_rank[i] == 0) { + expect[0] = hash4(cdf_format, var_type[i], 0, index, NCT_ULONGLONG); + if (inRange3(cdf_format, expect[0], var_type[i], NCT_ULONGLONG) && + (expect[0] >= ulonglong_min && expect[0] <= ulonglong_max)) { + IF (err != NC_NOERR) error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else IF (err != NC_ERANGE) error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + for (j = 0; j < var_rank[i]; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i]; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i]; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i]; j++) { + count[j] = 1 + (edge[j]-index[j]-1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i]; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + allInExtRange = allInIntRange = 1; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i]; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect[j] = hash4(cdf_format, var_type[i], var_rank[i], + index2, NCT_ULONGLONG); + if (inRange3(cdf_format, expect[j],var_type[i],NCT_ULONGLONG)) { + + allInIntRange &= (expect[j] >= ulonglong_min && expect[j] <= ulonglong_max); + } else + allInExtRange = 0; + } + err = nc_get_varm_ulonglong(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (j = 0; j < nels; j++) { + if (inRange3(cdf_format, expect[j],var_type[i],NCT_ULONGLONG) && (expect[j] >= ulonglong_min && expect[j] <= ulonglong_max)) { + + IF (!equal((double)value[j],expect[j],var_type[i], NCT_ULONGLONG)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("element number: %d, ", j); + error("expect: %g, ", expect[j]); + error("got: %g", (double) value[j]); + } + } + ELSE_NOK + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + + + +int +test_nc_get_att_text(void) +{ + int i, j, err, ncid, cdf_format; + size_t k, ndx[1]; + int allInExtRange; + int allInIntRange; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + double expect[MAX_NELS]; + text value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_att_text(BAD_ID, 0, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_att_text(ncid, BAD_VARID, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) ; + + err = nc_get_att_text(ncid, BAD_VARID, ATT_NAME(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + /* check if can detect a bad name */ + err = nc_get_att_text(ncid, i, NULL, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK +#endif + + err = nc_get_att_text(ncid, i, "noSuch", value); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s",nc_err_code_name(err)); + ELSE_NOK + + allInExtRange = allInIntRange = 1; + for (k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, ATT_TYPE(i,j), -1, ndx, NCT_TEXT); + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_TEXT)) { + /* netCDF specification make a special case for type + * conversion between uchar and scahr: do not check for + * range error. See + * https://docs.unidata.ucar.edu/netcdf-c/current/data_type.html#type_conversion + */ + if (ATT_TYPE(i,j) != NC_CHAR) + + allInIntRange &= 1; + } else { + allInExtRange = 0; + } + } + err = nc_get_att_text(ncid, i, ATT_NAME(i,j), value); + if (canConvert || ATT_LEN(i,j) == 0) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < ATT_LEN(i,j); k++) { + if (1) { + + IF (!equal((double)value[k],expect[k],ATT_TYPE(i,j), NCT_TEXT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + if (i == -1) + error("var_type: GLOBAL, "); + else + error("var_name: %s var_type: %s, ", var_name[i],s_nc_type(var_type[i])); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d, ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_att_uchar(void) +{ + int i, j, err, ncid, cdf_format; + size_t k, ndx[1]; + int allInExtRange; + int allInIntRange; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + double expect[MAX_NELS]; + uchar value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_att_uchar(BAD_ID, 0, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_att_uchar(ncid, BAD_VARID, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_UCHAR == NCT_TEXT); + + err = nc_get_att_uchar(ncid, BAD_VARID, ATT_NAME(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + /* check if can detect a bad name */ + err = nc_get_att_uchar(ncid, i, NULL, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK +#endif + + err = nc_get_att_uchar(ncid, i, "noSuch", value); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s",nc_err_code_name(err)); + ELSE_NOK + + allInExtRange = allInIntRange = 1; + for (k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, ATT_TYPE(i,j), -1, ndx, NCT_UCHAR); + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_UCHAR)) { + /* netCDF specification make a special case for type + * conversion between uchar and scahr: do not check for + * range error. See + * https://docs.unidata.ucar.edu/netcdf-c/current/data_type.html#type_conversion + */ + + if (cdf_format > NC_FORMAT_64BIT_OFFSET || (cdf_format < NC_FORMAT_CDF5 && ATT_TYPE(i,j) != NC_BYTE)) + allInIntRange &= (expect[k] >= uchar_min && expect[k] <= uchar_max); + } else { + allInExtRange = 0; + } + } + err = nc_get_att_uchar(ncid, i, ATT_NAME(i,j), value); + if (canConvert || ATT_LEN(i,j) == 0) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); +#endif + } + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < ATT_LEN(i,j); k++) { + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_UCHAR) && (expect[k] >= uchar_min && expect[k] <= uchar_max)) { + + /* in put_vars(), API _put_vara_double() is used to + * write the NC_BYTE variables to files. In this + * case, NC_BYTE variables are treated as signed + * for CDF-1 and 2 formats. Thus, we must skip the + * equal test below for uchar. + */ + if (cdf_format < NC_FORMAT_CDF5 && ATT_TYPE(i,j) == NC_BYTE && expect[k] > schar_max) continue; + IF (!equal((double)value[k],expect[k],ATT_TYPE(i,j), NCT_UCHAR)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + if (i == -1) + error("var_type: GLOBAL, "); + else + error("var_name: %s var_type: %s, ", var_name[i],s_nc_type(var_type[i])); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d, ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_att_schar(void) +{ + int i, j, err, ncid, cdf_format; + size_t k, ndx[1]; + int allInExtRange; + int allInIntRange; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + double expect[MAX_NELS]; + schar value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_att_schar(BAD_ID, 0, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_att_schar(ncid, BAD_VARID, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_SCHAR == NCT_TEXT); + + err = nc_get_att_schar(ncid, BAD_VARID, ATT_NAME(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + /* check if can detect a bad name */ + err = nc_get_att_schar(ncid, i, NULL, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK +#endif + + err = nc_get_att_schar(ncid, i, "noSuch", value); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s",nc_err_code_name(err)); + ELSE_NOK + + allInExtRange = allInIntRange = 1; + for (k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, ATT_TYPE(i,j), -1, ndx, NCT_SCHAR); + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_SCHAR)) { + /* netCDF specification make a special case for type + * conversion between uchar and scahr: do not check for + * range error. See + * https://docs.unidata.ucar.edu/netcdf-c/current/data_type.html#type_conversion + */ + + + allInIntRange &= (expect[k] >= schar_min && expect[k] <= schar_max); + } else { + allInExtRange = 0; + } + } + err = nc_get_att_schar(ncid, i, ATT_NAME(i,j), value); + if (canConvert || ATT_LEN(i,j) == 0) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < ATT_LEN(i,j); k++) { + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_SCHAR) && (expect[k] >= schar_min && expect[k] <= schar_max)) { + + IF (!equal((double)value[k],expect[k],ATT_TYPE(i,j), NCT_SCHAR)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + if (i == -1) + error("var_type: GLOBAL, "); + else + error("var_name: %s var_type: %s, ", var_name[i],s_nc_type(var_type[i])); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d, ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_att_short(void) +{ + int i, j, err, ncid, cdf_format; + size_t k, ndx[1]; + int allInExtRange; + int allInIntRange; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + double expect[MAX_NELS]; + short value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_att_short(BAD_ID, 0, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_att_short(ncid, BAD_VARID, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_SHORT == NCT_TEXT); + + err = nc_get_att_short(ncid, BAD_VARID, ATT_NAME(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + /* check if can detect a bad name */ + err = nc_get_att_short(ncid, i, NULL, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK +#endif + + err = nc_get_att_short(ncid, i, "noSuch", value); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s",nc_err_code_name(err)); + ELSE_NOK + + allInExtRange = allInIntRange = 1; + for (k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, ATT_TYPE(i,j), -1, ndx, NCT_SHORT); + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_SHORT)) { + /* netCDF specification make a special case for type + * conversion between uchar and scahr: do not check for + * range error. See + * https://docs.unidata.ucar.edu/netcdf-c/current/data_type.html#type_conversion + */ + + + allInIntRange &= (expect[k] >= short_min && expect[k] <= short_max); + } else { + allInExtRange = 0; + } + } + err = nc_get_att_short(ncid, i, ATT_NAME(i,j), value); + if (canConvert || ATT_LEN(i,j) == 0) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < ATT_LEN(i,j); k++) { + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_SHORT) && (expect[k] >= short_min && expect[k] <= short_max)) { + + IF (!equal((double)value[k],expect[k],ATT_TYPE(i,j), NCT_SHORT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + if (i == -1) + error("var_type: GLOBAL, "); + else + error("var_name: %s var_type: %s, ", var_name[i],s_nc_type(var_type[i])); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d, ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_att_int(void) +{ + int i, j, err, ncid, cdf_format; + size_t k, ndx[1]; + int allInExtRange; + int allInIntRange; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + double expect[MAX_NELS]; + int value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_att_int(BAD_ID, 0, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_att_int(ncid, BAD_VARID, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_INT == NCT_TEXT); + + err = nc_get_att_int(ncid, BAD_VARID, ATT_NAME(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + /* check if can detect a bad name */ + err = nc_get_att_int(ncid, i, NULL, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK +#endif + + err = nc_get_att_int(ncid, i, "noSuch", value); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s",nc_err_code_name(err)); + ELSE_NOK + + allInExtRange = allInIntRange = 1; + for (k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, ATT_TYPE(i,j), -1, ndx, NCT_INT); + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_INT)) { + /* netCDF specification make a special case for type + * conversion between uchar and scahr: do not check for + * range error. See + * https://docs.unidata.ucar.edu/netcdf-c/current/data_type.html#type_conversion + */ + + + allInIntRange &= (expect[k] >= int_min && expect[k] <= int_max); + } else { + allInExtRange = 0; + } + } + err = nc_get_att_int(ncid, i, ATT_NAME(i,j), value); + if (canConvert || ATT_LEN(i,j) == 0) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < ATT_LEN(i,j); k++) { + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_INT) && (expect[k] >= int_min && expect[k] <= int_max)) { + + IF (!equal((double)value[k],expect[k],ATT_TYPE(i,j), NCT_INT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + if (i == -1) + error("var_type: GLOBAL, "); + else + error("var_name: %s var_type: %s, ", var_name[i],s_nc_type(var_type[i])); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d, ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_att_long(void) +{ + int i, j, err, ncid, cdf_format; + size_t k, ndx[1]; + int allInExtRange; + int allInIntRange; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + double expect[MAX_NELS]; + long value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_att_long(BAD_ID, 0, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_att_long(ncid, BAD_VARID, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_LONG == NCT_TEXT); + + err = nc_get_att_long(ncid, BAD_VARID, ATT_NAME(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + /* check if can detect a bad name */ + err = nc_get_att_long(ncid, i, NULL, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK +#endif + + err = nc_get_att_long(ncid, i, "noSuch", value); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s",nc_err_code_name(err)); + ELSE_NOK + + allInExtRange = allInIntRange = 1; + for (k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, ATT_TYPE(i,j), -1, ndx, NCT_LONG); + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_LONG)) { + /* netCDF specification make a special case for type + * conversion between uchar and scahr: do not check for + * range error. See + * https://docs.unidata.ucar.edu/netcdf-c/current/data_type.html#type_conversion + */ + + + allInIntRange &= (expect[k] >= long_min && expect[k] <= long_max); + } else { + allInExtRange = 0; + } + } + err = nc_get_att_long(ncid, i, ATT_NAME(i,j), value); + if (canConvert || ATT_LEN(i,j) == 0) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < ATT_LEN(i,j); k++) { + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_LONG) && (expect[k] >= long_min && expect[k] <= long_max)) { + + IF (!equal((double)value[k],expect[k],ATT_TYPE(i,j), NCT_LONG)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + if (i == -1) + error("var_type: GLOBAL, "); + else + error("var_name: %s var_type: %s, ", var_name[i],s_nc_type(var_type[i])); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d, ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_att_float(void) +{ + int i, j, err, ncid, cdf_format; + size_t k, ndx[1]; + int allInExtRange; + int allInIntRange; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + double expect[MAX_NELS]; + float value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_att_float(BAD_ID, 0, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_att_float(ncid, BAD_VARID, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_FLOAT == NCT_TEXT); + + err = nc_get_att_float(ncid, BAD_VARID, ATT_NAME(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + /* check if can detect a bad name */ + err = nc_get_att_float(ncid, i, NULL, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK +#endif + + err = nc_get_att_float(ncid, i, "noSuch", value); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s",nc_err_code_name(err)); + ELSE_NOK + + allInExtRange = allInIntRange = 1; + for (k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, ATT_TYPE(i,j), -1, ndx, NCT_FLOAT); + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_FLOAT)) { + /* netCDF specification make a special case for type + * conversion between uchar and scahr: do not check for + * range error. See + * https://docs.unidata.ucar.edu/netcdf-c/current/data_type.html#type_conversion + */ + + + allInIntRange &= (expect[k] >= float_min && expect[k] <= float_max); + } else { + allInExtRange = 0; + } + } + err = nc_get_att_float(ncid, i, ATT_NAME(i,j), value); + if (canConvert || ATT_LEN(i,j) == 0) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < ATT_LEN(i,j); k++) { + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_FLOAT) && (expect[k] >= float_min && expect[k] <= float_max)) { + + IF (!equal((double)value[k],expect[k],ATT_TYPE(i,j), NCT_FLOAT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + if (i == -1) + error("var_type: GLOBAL, "); + else + error("var_name: %s var_type: %s, ", var_name[i],s_nc_type(var_type[i])); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d, ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_att_double(void) +{ + int i, j, err, ncid, cdf_format; + size_t k, ndx[1]; + int allInExtRange; + int allInIntRange; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + double expect[MAX_NELS]; + double value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_att_double(BAD_ID, 0, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_att_double(ncid, BAD_VARID, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT); + + err = nc_get_att_double(ncid, BAD_VARID, ATT_NAME(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + /* check if can detect a bad name */ + err = nc_get_att_double(ncid, i, NULL, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK +#endif + + err = nc_get_att_double(ncid, i, "noSuch", value); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s",nc_err_code_name(err)); + ELSE_NOK + + allInExtRange = allInIntRange = 1; + for (k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, ATT_TYPE(i,j), -1, ndx, NCT_DOUBLE); + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_DOUBLE)) { + /* netCDF specification make a special case for type + * conversion between uchar and scahr: do not check for + * range error. See + * https://docs.unidata.ucar.edu/netcdf-c/current/data_type.html#type_conversion + */ + + + allInIntRange &= (expect[k] >= double_min && expect[k] <= double_max); + } else { + allInExtRange = 0; + } + } + err = nc_get_att_double(ncid, i, ATT_NAME(i,j), value); + if (canConvert || ATT_LEN(i,j) == 0) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < ATT_LEN(i,j); k++) { + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_DOUBLE) && (expect[k] >= double_min && expect[k] <= double_max)) { + + IF (!equal((double)value[k],expect[k],ATT_TYPE(i,j), NCT_DOUBLE)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + if (i == -1) + error("var_type: GLOBAL, "); + else + error("var_name: %s var_type: %s, ", var_name[i],s_nc_type(var_type[i])); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d, ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_att_ushort(void) +{ + int i, j, err, ncid, cdf_format; + size_t k, ndx[1]; + int allInExtRange; + int allInIntRange; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + double expect[MAX_NELS]; + ushort value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_att_ushort(BAD_ID, 0, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_att_ushort(ncid, BAD_VARID, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_USHORT == NCT_TEXT); + + err = nc_get_att_ushort(ncid, BAD_VARID, ATT_NAME(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + /* check if can detect a bad name */ + err = nc_get_att_ushort(ncid, i, NULL, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK +#endif + + err = nc_get_att_ushort(ncid, i, "noSuch", value); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s",nc_err_code_name(err)); + ELSE_NOK + + allInExtRange = allInIntRange = 1; + for (k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, ATT_TYPE(i,j), -1, ndx, NCT_USHORT); + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_USHORT)) { + /* netCDF specification make a special case for type + * conversion between uchar and scahr: do not check for + * range error. See + * https://docs.unidata.ucar.edu/netcdf-c/current/data_type.html#type_conversion + */ + + + allInIntRange &= (expect[k] >= ushort_min && expect[k] <= ushort_max); + } else { + allInExtRange = 0; + } + } + err = nc_get_att_ushort(ncid, i, ATT_NAME(i,j), value); + if (canConvert || ATT_LEN(i,j) == 0) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < ATT_LEN(i,j); k++) { + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_USHORT) && (expect[k] >= ushort_min && expect[k] <= ushort_max)) { + + IF (!equal((double)value[k],expect[k],ATT_TYPE(i,j), NCT_USHORT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + if (i == -1) + error("var_type: GLOBAL, "); + else + error("var_name: %s var_type: %s, ", var_name[i],s_nc_type(var_type[i])); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d, ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_att_uint(void) +{ + int i, j, err, ncid, cdf_format; + size_t k, ndx[1]; + int allInExtRange; + int allInIntRange; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + double expect[MAX_NELS]; + uint value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_att_uint(BAD_ID, 0, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_att_uint(ncid, BAD_VARID, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_UINT == NCT_TEXT); + + err = nc_get_att_uint(ncid, BAD_VARID, ATT_NAME(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + /* check if can detect a bad name */ + err = nc_get_att_uint(ncid, i, NULL, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK +#endif + + err = nc_get_att_uint(ncid, i, "noSuch", value); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s",nc_err_code_name(err)); + ELSE_NOK + + allInExtRange = allInIntRange = 1; + for (k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, ATT_TYPE(i,j), -1, ndx, NCT_UINT); + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_UINT)) { + /* netCDF specification make a special case for type + * conversion between uchar and scahr: do not check for + * range error. See + * https://docs.unidata.ucar.edu/netcdf-c/current/data_type.html#type_conversion + */ + + + allInIntRange &= (expect[k] >= uint_min && expect[k] <= uint_max); + } else { + allInExtRange = 0; + } + } + err = nc_get_att_uint(ncid, i, ATT_NAME(i,j), value); + if (canConvert || ATT_LEN(i,j) == 0) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < ATT_LEN(i,j); k++) { + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_UINT) && (expect[k] >= uint_min && expect[k] <= uint_max)) { + + IF (!equal((double)value[k],expect[k],ATT_TYPE(i,j), NCT_UINT)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + if (i == -1) + error("var_type: GLOBAL, "); + else + error("var_name: %s var_type: %s, ", var_name[i],s_nc_type(var_type[i])); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d, ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_att_longlong(void) +{ + int i, j, err, ncid, cdf_format; + size_t k, ndx[1]; + int allInExtRange; + int allInIntRange; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + double expect[MAX_NELS]; + longlong value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_att_longlong(BAD_ID, 0, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_att_longlong(ncid, BAD_VARID, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_LONGLONG == NCT_TEXT); + + err = nc_get_att_longlong(ncid, BAD_VARID, ATT_NAME(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + /* check if can detect a bad name */ + err = nc_get_att_longlong(ncid, i, NULL, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK +#endif + + err = nc_get_att_longlong(ncid, i, "noSuch", value); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s",nc_err_code_name(err)); + ELSE_NOK + + allInExtRange = allInIntRange = 1; + for (k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, ATT_TYPE(i,j), -1, ndx, NCT_LONGLONG); + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_LONGLONG)) { + /* netCDF specification make a special case for type + * conversion between uchar and scahr: do not check for + * range error. See + * https://docs.unidata.ucar.edu/netcdf-c/current/data_type.html#type_conversion + */ + + + allInIntRange &= (expect[k] >= longlong_min && expect[k] <= longlong_max); + } else { + allInExtRange = 0; + } + } + err = nc_get_att_longlong(ncid, i, ATT_NAME(i,j), value); + if (canConvert || ATT_LEN(i,j) == 0) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < ATT_LEN(i,j); k++) { + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_LONGLONG) && (expect[k] >= longlong_min && expect[k] <= longlong_max)) { + + IF (!equal((double)value[k],expect[k],ATT_TYPE(i,j), NCT_LONGLONG)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + if (i == -1) + error("var_type: GLOBAL, "); + else + error("var_name: %s var_type: %s, ", var_name[i],s_nc_type(var_type[i])); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d, ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +int +test_nc_get_att_ulonglong(void) +{ + int i, j, err, ncid, cdf_format; + size_t k, ndx[1]; + int allInExtRange; + int allInIntRange; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + double expect[MAX_NELS]; + ulonglong value[MAX_NELS]; + + for(j = 0; j < MAX_NELS; j++) { + expect[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + err = nc_get_att_ulonglong(BAD_ID, 0, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_get_att_ulonglong(ncid, BAD_VARID, NULL, value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_ULONGLONG == NCT_TEXT); + + err = nc_get_att_ulonglong(ncid, BAD_VARID, ATT_NAME(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>7) + /* check if can detect a bad name */ + err = nc_get_att_ulonglong(ncid, i, NULL, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK +#endif + + err = nc_get_att_ulonglong(ncid, i, "noSuch", value); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s",nc_err_code_name(err)); + ELSE_NOK + + allInExtRange = allInIntRange = 1; + for (k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, ATT_TYPE(i,j), -1, ndx, NCT_ULONGLONG); + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_ULONGLONG)) { + /* netCDF specification make a special case for type + * conversion between uchar and scahr: do not check for + * range error. See + * https://docs.unidata.ucar.edu/netcdf-c/current/data_type.html#type_conversion + */ + + + allInIntRange &= (expect[k] >= ulonglong_min && expect[k] <= ulonglong_max); + } else { + allInExtRange = 0; + } + } + err = nc_get_att_ulonglong(ncid, i, ATT_NAME(i,j), value); + if (canConvert || ATT_LEN(i,j) == 0) { + if (allInExtRange) { + if (allInIntRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + + } + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < ATT_LEN(i,j); k++) { + if (inRange3(cdf_format, expect[k],ATT_TYPE(i,j),NCT_ULONGLONG) && (expect[k] >= ulonglong_min && expect[k] <= ulonglong_max)) { + + IF (!equal((double)value[k],expect[k],ATT_TYPE(i,j), NCT_ULONGLONG)){ + error("value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + if (i == -1) + error("var_type: GLOBAL, "); + else + error("var_name: %s var_type: %s, ", var_name[i],s_nc_type(var_type[i])); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d, ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + diff --git a/nc_test/test_put.c b/nc_test/test_put.c new file mode 100644 index 0000000000..9012e7de61 --- /dev/null +++ b/nc_test/test_put.c @@ -0,0 +1,13910 @@ +/* Do not edit this file. It is produced from the corresponding .m4 source */ +/* + * Copyright (C) 2003, Northwestern University and Argonne National Laboratory + * See COPYRIGHT notice in top-level directory. + */ +/* $Id: test_put.m4 2672 2016-12-03 19:23:53Z wkliao $ */ + + +#include "tests.h" + +#ifdef USE_PNETCDF +#include +#ifndef PNETCDF_VERSION_MAJOR +#error("PNETCDF_VERSION_MAJOR is not defined in pnetcdf.h") +#endif +#ifndef PNETCDF_VERSION_MINOR +#error("PNETCDF_VERSION_MAJOR is not defined in pnetcdf.h") +#endif +#endif + + + + + + + + + + +/* + * ensure hash value within range for internal TYPE + */ +text +hash_text(const int cdf_format, + const nc_type type, + const int rank, + const size_t *index, + const nct_itype itype) +{ + double value; + + value = hash4(cdf_format, type, rank, index, itype); + return (text)value; +} + +/* + * ensure hash value within range for internal TYPE + */ +uchar +hash_uchar(const int cdf_format, + const nc_type type, + const int rank, + const size_t *index, + const nct_itype itype) +{ + double value; + + value = hash4(cdf_format, type, rank, index, itype); + + if (value > uchar_max) return uchar_max; + else if (value < uchar_min) return uchar_min; + else return (uchar)value; +} + +/* + * ensure hash value within range for internal TYPE + */ +schar +hash_schar(const int cdf_format, + const nc_type type, + const int rank, + const size_t *index, + const nct_itype itype) +{ + double value; + + value = hash4(cdf_format, type, rank, index, itype); + + if (value > schar_max) return schar_max; + else if (value < schar_min) return schar_min; + else return (schar)value; +} + +/* + * ensure hash value within range for internal TYPE + */ +short +hash_short(const int cdf_format, + const nc_type type, + const int rank, + const size_t *index, + const nct_itype itype) +{ + double value; + + value = hash4(cdf_format, type, rank, index, itype); + + if (value > short_max) return short_max; + else if (value < short_min) return short_min; + else return (short)value; +} + +/* + * ensure hash value within range for internal TYPE + */ +int +hash_int(const int cdf_format, + const nc_type type, + const int rank, + const size_t *index, + const nct_itype itype) +{ + double value; + + value = hash4(cdf_format, type, rank, index, itype); + + if (value > int_max) return int_max; + else if (value < int_min) return int_min; + else return (int)value; +} + +/* + * ensure hash value within range for internal TYPE + */ +long +hash_long(const int cdf_format, + const nc_type type, + const int rank, + const size_t *index, + const nct_itype itype) +{ + double value; + + value = hash4(cdf_format, type, rank, index, itype); + + if (value > long_max) return long_max; + else if (value < long_min) return long_min; + else return (long)value; +} + +/* + * ensure hash value within range for internal TYPE + */ +float +hash_float(const int cdf_format, + const nc_type type, + const int rank, + const size_t *index, + const nct_itype itype) +{ + double value; + + value = hash4(cdf_format, type, rank, index, itype); + + if (value > float_max) return float_max; + else if (value < float_min) return float_min; + else return (float)value; +} + +/* + * ensure hash value within range for internal TYPE + */ +double +hash_double(const int cdf_format, + const nc_type type, + const int rank, + const size_t *index, + const nct_itype itype) +{ + double value; + + value = hash4(cdf_format, type, rank, index, itype); + + if (value > double_max) return double_max; + else if (value < double_min) return double_min; + else return (double)value; +} + +/* + * ensure hash value within range for internal TYPE + */ +ushort +hash_ushort(const int cdf_format, + const nc_type type, + const int rank, + const size_t *index, + const nct_itype itype) +{ + double value; + + value = hash4(cdf_format, type, rank, index, itype); + + if (value > ushort_max) return ushort_max; + else if (value < ushort_min) return ushort_min; + else return (ushort)value; +} + +/* + * ensure hash value within range for internal TYPE + */ +uint +hash_uint(const int cdf_format, + const nc_type type, + const int rank, + const size_t *index, + const nct_itype itype) +{ + double value; + + value = hash4(cdf_format, type, rank, index, itype); + + if (value > uint_max) return uint_max; + else if (value < uint_min) return uint_min; + else return (uint)value; +} + +/* + * ensure hash value within range for internal TYPE + */ +longlong +hash_longlong(const int cdf_format, + const nc_type type, + const int rank, + const size_t *index, + const nct_itype itype) +{ + double value; + + value = hash4(cdf_format, type, rank, index, itype); + + if (value > longlong_max) return longlong_max; + else if (value < longlong_min) return longlong_min; + else return (longlong)value; +} + +/* + * ensure hash value within range for internal TYPE + */ +ulonglong +hash_ulonglong(const int cdf_format, + const nc_type type, + const int rank, + const size_t *index, + const nct_itype itype) +{ + double value; + + value = hash4(cdf_format, type, rank, index, itype); + + if (value > ulonglong_max) return ulonglong_max; + else if (value < ulonglong_min) return ulonglong_min; + else return (ulonglong)value; +} + + + + +/* + * check all vars in file which are (text/numeric) compatible with TYPE + */ +int +check_vars_text(const char *filename, int numVars) +{ + int i, d, err, ncid, cdf_format, ndims; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + int dimids[MAX_RANK]; + nc_type datatype; + char name[NC_MAX_NAME]; + size_t j, length, index[MAX_RANK]; + double expect; + text value; + + err = file_open(filename, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + canConvert = (var_type[i] == NC_CHAR) ; + if (!canConvert) continue; + + err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + IF (strcmp(name, var_name[i]) != 0) + error("Unexpected var_name"); + IF (datatype != var_type[i]) + error("Unexpected type"); + IF (ndims != var_rank[i]) + error("Unexpected rank"); + for (j = 0; j < ndims; j++) { + err = nc_inq_dim(ncid, dimids[j], 0, &length); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + IF (length != var_shape[i][j]) + error("Unexpected shape"); + } + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_TEXT); + err = nc_get_var1_text(ncid, i, index, &value); + if (1) { + IF (err != NC_NOERR) { + error("nc_get_var1_text: %s", nc_strerror(err)); + } else { + + IF (!equal((double)value,expect,var_type[i],NCT_TEXT)){ + error("Var value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("index:"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + error(" %d", index[d]); + error(", expect: %g, ", expect); + error("got: %g", (double) value); + } + } else { + ++nok; + } + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +/* + * check all vars in file which are (text/numeric) compatible with TYPE + */ +int +check_vars_uchar(const char *filename, int numVars) +{ + int i, d, err, ncid, cdf_format, ndims; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + int dimids[MAX_RANK]; + nc_type datatype; + char name[NC_MAX_NAME]; + size_t j, length, index[MAX_RANK]; + double expect; + uchar value; + + err = file_open(filename, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + canConvert = (var_type[i] == NC_CHAR) == (NCT_UCHAR == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + IF (strcmp(name, var_name[i]) != 0) + error("Unexpected var_name"); + IF (datatype != var_type[i]) + error("Unexpected type"); + IF (ndims != var_rank[i]) + error("Unexpected rank"); + for (j = 0; j < ndims; j++) { + err = nc_inq_dim(ncid, dimids[j], 0, &length); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + IF (length != var_shape[i][j]) + error("Unexpected shape"); + } + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_UCHAR); + err = nc_get_var1_uchar(ncid, i, index, &value); + if (inRange3(cdf_format, (double)expect,datatype,NCT_UCHAR) && (expect >= uchar_min && expect <= uchar_max)) { + IF (err != NC_NOERR) { + error("nc_get_var1_uchar: %s", nc_strerror(err)); + } else { + + /* In put_vars(), nc_put_vara_double() is used to write + * variables of type NC_BYTE to files. For uchar APIs, + * NC_BYTE variables are treated as unsigned for CDF-1 and 2 + * formats. Thus, we skip the equal test for out-of-bound + * values below for uchar APIs. + */ + if (cdf_format < NC_FORMAT_CDF5 && + var_type[i] == NC_BYTE && expect > schar_max) + continue; + IF (!equal((double)value,expect,var_type[i],NCT_UCHAR)){ + error("Var value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("index:"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + error(" %d", index[d]); + error(", expect: %g, ", expect); + error("got: %g", (double) value); + } + } else { + ++nok; + } + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +/* + * check all vars in file which are (text/numeric) compatible with TYPE + */ +int +check_vars_schar(const char *filename, int numVars) +{ + int i, d, err, ncid, cdf_format, ndims; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + int dimids[MAX_RANK]; + nc_type datatype; + char name[NC_MAX_NAME]; + size_t j, length, index[MAX_RANK]; + double expect; + schar value; + + err = file_open(filename, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + canConvert = (var_type[i] == NC_CHAR) == (NCT_SCHAR == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + IF (strcmp(name, var_name[i]) != 0) + error("Unexpected var_name"); + IF (datatype != var_type[i]) + error("Unexpected type"); + IF (ndims != var_rank[i]) + error("Unexpected rank"); + for (j = 0; j < ndims; j++) { + err = nc_inq_dim(ncid, dimids[j], 0, &length); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + IF (length != var_shape[i][j]) + error("Unexpected shape"); + } + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_SCHAR); + err = nc_get_var1_schar(ncid, i, index, &value); + if (inRange3(cdf_format, (double)expect,datatype,NCT_SCHAR) && (expect >= schar_min && expect <= schar_max)) { + IF (err != NC_NOERR) { + error("nc_get_var1_schar: %s", nc_strerror(err)); + } else { + + IF (!equal((double)value,expect,var_type[i],NCT_SCHAR)){ + error("Var value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("index:"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + error(" %d", index[d]); + error(", expect: %g, ", expect); + error("got: %g", (double) value); + } + } else { + ++nok; + } + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +/* + * check all vars in file which are (text/numeric) compatible with TYPE + */ +int +check_vars_short(const char *filename, int numVars) +{ + int i, d, err, ncid, cdf_format, ndims; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + int dimids[MAX_RANK]; + nc_type datatype; + char name[NC_MAX_NAME]; + size_t j, length, index[MAX_RANK]; + double expect; + short value; + + err = file_open(filename, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + canConvert = (var_type[i] == NC_CHAR) == (NCT_SHORT == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + IF (strcmp(name, var_name[i]) != 0) + error("Unexpected var_name"); + IF (datatype != var_type[i]) + error("Unexpected type"); + IF (ndims != var_rank[i]) + error("Unexpected rank"); + for (j = 0; j < ndims; j++) { + err = nc_inq_dim(ncid, dimids[j], 0, &length); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + IF (length != var_shape[i][j]) + error("Unexpected shape"); + } + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_SHORT); + err = nc_get_var1_short(ncid, i, index, &value); + if (inRange3(cdf_format, (double)expect,datatype,NCT_SHORT) && (expect >= short_min && expect <= short_max)) { + IF (err != NC_NOERR) { + error("nc_get_var1_short: %s", nc_strerror(err)); + } else { + + IF (!equal((double)value,expect,var_type[i],NCT_SHORT)){ + error("Var value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("index:"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + error(" %d", index[d]); + error(", expect: %g, ", expect); + error("got: %g", (double) value); + } + } else { + ++nok; + } + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +/* + * check all vars in file which are (text/numeric) compatible with TYPE + */ +int +check_vars_int(const char *filename, int numVars) +{ + int i, d, err, ncid, cdf_format, ndims; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + int dimids[MAX_RANK]; + nc_type datatype; + char name[NC_MAX_NAME]; + size_t j, length, index[MAX_RANK]; + double expect; + int value; + + err = file_open(filename, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + canConvert = (var_type[i] == NC_CHAR) == (NCT_INT == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + IF (strcmp(name, var_name[i]) != 0) + error("Unexpected var_name"); + IF (datatype != var_type[i]) + error("Unexpected type"); + IF (ndims != var_rank[i]) + error("Unexpected rank"); + for (j = 0; j < ndims; j++) { + err = nc_inq_dim(ncid, dimids[j], 0, &length); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + IF (length != var_shape[i][j]) + error("Unexpected shape"); + } + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_INT); + err = nc_get_var1_int(ncid, i, index, &value); + if (inRange3(cdf_format, (double)expect,datatype,NCT_INT) && (expect >= int_min && expect <= int_max)) { + IF (err != NC_NOERR) { + error("nc_get_var1_int: %s", nc_strerror(err)); + } else { + + IF (!equal((double)value,expect,var_type[i],NCT_INT)){ + error("Var value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("index:"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + error(" %d", index[d]); + error(", expect: %g, ", expect); + error("got: %g", (double) value); + } + } else { + ++nok; + } + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +/* + * check all vars in file which are (text/numeric) compatible with TYPE + */ +int +check_vars_long(const char *filename, int numVars) +{ + int i, d, err, ncid, cdf_format, ndims; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + int dimids[MAX_RANK]; + nc_type datatype; + char name[NC_MAX_NAME]; + size_t j, length, index[MAX_RANK]; + double expect; + long value; + + err = file_open(filename, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONG == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + IF (strcmp(name, var_name[i]) != 0) + error("Unexpected var_name"); + IF (datatype != var_type[i]) + error("Unexpected type"); + IF (ndims != var_rank[i]) + error("Unexpected rank"); + for (j = 0; j < ndims; j++) { + err = nc_inq_dim(ncid, dimids[j], 0, &length); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + IF (length != var_shape[i][j]) + error("Unexpected shape"); + } + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_LONG); + err = nc_get_var1_long(ncid, i, index, &value); + if (inRange3(cdf_format, (double)expect,datatype,NCT_LONG) && (expect >= long_min && expect <= long_max)) { + IF (err != NC_NOERR) { + error("nc_get_var1_long: %s", nc_strerror(err)); + } else { + + IF (!equal((double)value,expect,var_type[i],NCT_LONG)){ + error("Var value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("index:"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + error(" %d", index[d]); + error(", expect: %g, ", expect); + error("got: %g", (double) value); + } + } else { + ++nok; + } + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +/* + * check all vars in file which are (text/numeric) compatible with TYPE + */ +int +check_vars_float(const char *filename, int numVars) +{ + int i, d, err, ncid, cdf_format, ndims; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + int dimids[MAX_RANK]; + nc_type datatype; + char name[NC_MAX_NAME]; + size_t j, length, index[MAX_RANK]; + double expect; + float value; + + err = file_open(filename, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + canConvert = (var_type[i] == NC_CHAR) == (NCT_FLOAT == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + IF (strcmp(name, var_name[i]) != 0) + error("Unexpected var_name"); + IF (datatype != var_type[i]) + error("Unexpected type"); + IF (ndims != var_rank[i]) + error("Unexpected rank"); + for (j = 0; j < ndims; j++) { + err = nc_inq_dim(ncid, dimids[j], 0, &length); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + IF (length != var_shape[i][j]) + error("Unexpected shape"); + } + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_FLOAT); + err = nc_get_var1_float(ncid, i, index, &value); + if (inRange3(cdf_format, (double)expect,datatype,NCT_FLOAT) && (expect >= float_min && expect <= float_max)) { + IF (err != NC_NOERR) { + error("nc_get_var1_float: %s", nc_strerror(err)); + } else { + + IF (!equal((double)value,expect,var_type[i],NCT_FLOAT)){ + error("Var value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("index:"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + error(" %d", index[d]); + error(", expect: %g, ", expect); + error("got: %g", (double) value); + } + } else { + ++nok; + } + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +/* + * check all vars in file which are (text/numeric) compatible with TYPE + */ +int +check_vars_double(const char *filename, int numVars) +{ + int i, d, err, ncid, cdf_format, ndims; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + int dimids[MAX_RANK]; + nc_type datatype; + char name[NC_MAX_NAME]; + size_t j, length, index[MAX_RANK]; + double expect; + double value; + + err = file_open(filename, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + canConvert = (var_type[i] == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + IF (strcmp(name, var_name[i]) != 0) + error("Unexpected var_name"); + IF (datatype != var_type[i]) + error("Unexpected type"); + IF (ndims != var_rank[i]) + error("Unexpected rank"); + for (j = 0; j < ndims; j++) { + err = nc_inq_dim(ncid, dimids[j], 0, &length); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + IF (length != var_shape[i][j]) + error("Unexpected shape"); + } + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_DOUBLE); + err = nc_get_var1_double(ncid, i, index, &value); + if (inRange3(cdf_format, (double)expect,datatype,NCT_DOUBLE) && (expect >= double_min && expect <= double_max)) { + IF (err != NC_NOERR) { + error("nc_get_var1_double: %s", nc_strerror(err)); + } else { + + IF (!equal((double)value,expect,var_type[i],NCT_DOUBLE)){ + error("Var value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("index:"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + error(" %d", index[d]); + error(", expect: %g, ", expect); + error("got: %g", (double) value); + } + } else { + ++nok; + } + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +/* + * check all vars in file which are (text/numeric) compatible with TYPE + */ +int +check_vars_ushort(const char *filename, int numVars) +{ + int i, d, err, ncid, cdf_format, ndims; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + int dimids[MAX_RANK]; + nc_type datatype; + char name[NC_MAX_NAME]; + size_t j, length, index[MAX_RANK]; + double expect; + ushort value; + + err = file_open(filename, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + canConvert = (var_type[i] == NC_CHAR) == (NCT_USHORT == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + IF (strcmp(name, var_name[i]) != 0) + error("Unexpected var_name"); + IF (datatype != var_type[i]) + error("Unexpected type"); + IF (ndims != var_rank[i]) + error("Unexpected rank"); + for (j = 0; j < ndims; j++) { + err = nc_inq_dim(ncid, dimids[j], 0, &length); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + IF (length != var_shape[i][j]) + error("Unexpected shape"); + } + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_USHORT); + err = nc_get_var1_ushort(ncid, i, index, &value); + if (inRange3(cdf_format, (double)expect,datatype,NCT_USHORT) && (expect >= ushort_min && expect <= ushort_max)) { + IF (err != NC_NOERR) { + error("nc_get_var1_ushort: %s", nc_strerror(err)); + } else { + + IF (!equal((double)value,expect,var_type[i],NCT_USHORT)){ + error("Var value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("index:"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + error(" %d", index[d]); + error(", expect: %g, ", expect); + error("got: %g", (double) value); + } + } else { + ++nok; + } + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +/* + * check all vars in file which are (text/numeric) compatible with TYPE + */ +int +check_vars_uint(const char *filename, int numVars) +{ + int i, d, err, ncid, cdf_format, ndims; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + int dimids[MAX_RANK]; + nc_type datatype; + char name[NC_MAX_NAME]; + size_t j, length, index[MAX_RANK]; + double expect; + uint value; + + err = file_open(filename, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + canConvert = (var_type[i] == NC_CHAR) == (NCT_UINT == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + IF (strcmp(name, var_name[i]) != 0) + error("Unexpected var_name"); + IF (datatype != var_type[i]) + error("Unexpected type"); + IF (ndims != var_rank[i]) + error("Unexpected rank"); + for (j = 0; j < ndims; j++) { + err = nc_inq_dim(ncid, dimids[j], 0, &length); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + IF (length != var_shape[i][j]) + error("Unexpected shape"); + } + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_UINT); + err = nc_get_var1_uint(ncid, i, index, &value); + if (inRange3(cdf_format, (double)expect,datatype,NCT_UINT) && (expect >= uint_min && expect <= uint_max)) { + IF (err != NC_NOERR) { + error("nc_get_var1_uint: %s", nc_strerror(err)); + } else { + + IF (!equal((double)value,expect,var_type[i],NCT_UINT)){ + error("Var value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("index:"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + error(" %d", index[d]); + error(", expect: %g, ", expect); + error("got: %g", (double) value); + } + } else { + ++nok; + } + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +/* + * check all vars in file which are (text/numeric) compatible with TYPE + */ +int +check_vars_longlong(const char *filename, int numVars) +{ + int i, d, err, ncid, cdf_format, ndims; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + int dimids[MAX_RANK]; + nc_type datatype; + char name[NC_MAX_NAME]; + size_t j, length, index[MAX_RANK]; + double expect; + longlong value; + + err = file_open(filename, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONGLONG == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + IF (strcmp(name, var_name[i]) != 0) + error("Unexpected var_name"); + IF (datatype != var_type[i]) + error("Unexpected type"); + IF (ndims != var_rank[i]) + error("Unexpected rank"); + for (j = 0; j < ndims; j++) { + err = nc_inq_dim(ncid, dimids[j], 0, &length); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + IF (length != var_shape[i][j]) + error("Unexpected shape"); + } + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_LONGLONG); + err = nc_get_var1_longlong(ncid, i, index, &value); + if (inRange3(cdf_format, (double)expect,datatype,NCT_LONGLONG) && (expect >= longlong_min && expect <= longlong_max)) { + IF (err != NC_NOERR) { + error("nc_get_var1_longlong: %s", nc_strerror(err)); + } else { + + IF (!equal((double)value,expect,var_type[i],NCT_LONGLONG)){ + error("Var value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("index:"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + error(" %d", index[d]); + error(", expect: %g, ", expect); + error("got: %g", (double) value); + } + } else { + ++nok; + } + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + +/* + * check all vars in file which are (text/numeric) compatible with TYPE + */ +int +check_vars_ulonglong(const char *filename, int numVars) +{ + int i, d, err, ncid, cdf_format, ndims; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + int dimids[MAX_RANK]; + nc_type datatype; + char name[NC_MAX_NAME]; + size_t j, length, index[MAX_RANK]; + double expect; + ulonglong value; + + err = file_open(filename, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) error("inq_format: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + canConvert = (var_type[i] == NC_CHAR) == (NCT_ULONGLONG == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, NULL); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + IF (strcmp(name, var_name[i]) != 0) + error("Unexpected var_name"); + IF (datatype != var_type[i]) + error("Unexpected type"); + IF (ndims != var_rank[i]) + error("Unexpected rank"); + for (j = 0; j < ndims; j++) { + err = nc_inq_dim(ncid, dimids[j], 0, &length); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + IF (length != var_shape[i][j]) + error("Unexpected shape"); + } + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect = hash4(cdf_format, var_type[i], var_rank[i], index, + NCT_ULONGLONG); + err = nc_get_var1_ulonglong(ncid, i, index, &value); + if (inRange3(cdf_format, (double)expect,datatype,NCT_ULONGLONG) && (expect >= ulonglong_min && expect <= ulonglong_max)) { + IF (err != NC_NOERR) { + error("nc_get_var1_ulonglong: %s", nc_strerror(err)); + } else { + + IF (!equal((double)value,expect,var_type[i],NCT_ULONGLONG)){ + error("Var value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("var_type: %s, ", s_nc_type(var_type[i])); + error("index:"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + error(" %d", index[d]); + error(", expect: %g, ", expect); + error("got: %g", (double) value); + } + } else { + ++nok; + } + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + + + +/* + * for _text tests, check all attributes in file which are of text type + * Note no NC_ERANGE check for text attributes as text is not convertible to + * any other numerical data types (i.e. NC_ECHAR) + * + * for other tests, check all numerical attributes in file against values + * outside range of type text + */ +int +check_atts_text(int ncid, int numGatts, int numVars) +{ + int i, j, cdf_format, err; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + size_t k, length, ndx[1]; + nc_type datatype; + size_t nInExtRange; /* number values within external range */ + size_t nInIntRange; /* number values within internal range */ + double expect[MAX_NELS]; + text value[MAX_NELS]; + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) ; + if (!canConvert) continue; + + err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length); + IF (err != NC_NOERR) + error("inq_att: %s", nc_strerror(err)); + IF (datatype != ATT_TYPE(i,j)) + error("inq_att: unexpected type"); + IF (length != ATT_LEN(i,j)) + error("inq_att: unexpected length"); + assert(length <= MAX_NELS); + nInIntRange = nInExtRange = 0; + for (k = 0; k < length; k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, datatype, -1, ndx, NCT_TEXT); + if (inRange3(cdf_format, expect[k], datatype, NCT_TEXT)) { + ++nInExtRange; + if (0) + ++nInIntRange; + } + } + err = nc_get_att_text(ncid, i, ATT_NAME(i,j), value); + if (nInExtRange == length && nInIntRange == length) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < length; k++) { + if (1) { + + IF (!equal((double)value[k],expect[k],datatype,NCT_TEXT)) { + error("att. value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } + } + return nok; +} + +/* + * for _text tests, check all attributes in file which are of text type + * Note no NC_ERANGE check for text attributes as text is not convertible to + * any other numerical data types (i.e. NC_ECHAR) + * + * for other tests, check all numerical attributes in file against values + * outside range of type uchar + */ +int +check_atts_uchar(int ncid, int numGatts, int numVars) +{ + int i, j, cdf_format, err; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + size_t k, length, ndx[1]; + nc_type datatype; + size_t nInExtRange; /* number values within external range */ + size_t nInIntRange; /* number values within internal range */ + double expect[MAX_NELS]; + uchar value[MAX_NELS]; + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_UCHAR == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length); + IF (err != NC_NOERR) + error("inq_att: %s", nc_strerror(err)); + IF (datatype != ATT_TYPE(i,j)) + error("inq_att: unexpected type"); + IF (length != ATT_LEN(i,j)) + error("inq_att: unexpected length"); + assert(length <= MAX_NELS); + nInIntRange = nInExtRange = 0; + for (k = 0; k < length; k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, datatype, -1, ndx, NCT_UCHAR); + if (inRange3(cdf_format, expect[k], datatype, NCT_UCHAR)) { + ++nInExtRange; + if ((expect[k] >= uchar_min && expect[k] <= uchar_max)) + ++nInIntRange; + } + } + err = nc_get_att_uchar(ncid, i, ATT_NAME(i,j), value); + if (nInExtRange == length && nInIntRange == length) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < length; k++) { + if (inRange3(cdf_format, (double)expect[k],datatype,NCT_UCHAR) && (expect[k] >= uchar_min && expect[k] <= uchar_max)) { + + /* In put_vars(), nc_put_vara_double() is used to write + * variables of type NC_BYTE to files. For uchar APIs, + * NC_BYTE variables are treated as unsigned for CDF-1 and 2 + * formats. Thus, we skip the equal test for out-of-bound + * values below for uchar APIs. + */ + if (cdf_format < NC_FORMAT_CDF5 && + ATT_TYPE(i,j) == NC_BYTE && expect[k] > schar_max) + continue; + IF (!equal((double)value[k],expect[k],datatype,NCT_UCHAR)) { + error("att. value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } + } + return nok; +} + +/* + * for _text tests, check all attributes in file which are of text type + * Note no NC_ERANGE check for text attributes as text is not convertible to + * any other numerical data types (i.e. NC_ECHAR) + * + * for other tests, check all numerical attributes in file against values + * outside range of type schar + */ +int +check_atts_schar(int ncid, int numGatts, int numVars) +{ + int i, j, cdf_format, err; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + size_t k, length, ndx[1]; + nc_type datatype; + size_t nInExtRange; /* number values within external range */ + size_t nInIntRange; /* number values within internal range */ + double expect[MAX_NELS]; + schar value[MAX_NELS]; + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_SCHAR == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length); + IF (err != NC_NOERR) + error("inq_att: %s", nc_strerror(err)); + IF (datatype != ATT_TYPE(i,j)) + error("inq_att: unexpected type"); + IF (length != ATT_LEN(i,j)) + error("inq_att: unexpected length"); + assert(length <= MAX_NELS); + nInIntRange = nInExtRange = 0; + for (k = 0; k < length; k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, datatype, -1, ndx, NCT_SCHAR); + if (inRange3(cdf_format, expect[k], datatype, NCT_SCHAR)) { + ++nInExtRange; + if ((expect[k] >= schar_min && expect[k] <= schar_max)) + ++nInIntRange; + } + } + err = nc_get_att_schar(ncid, i, ATT_NAME(i,j), value); + if (nInExtRange == length && nInIntRange == length) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < length; k++) { + if (inRange3(cdf_format, (double)expect[k],datatype,NCT_SCHAR) && (expect[k] >= schar_min && expect[k] <= schar_max)) { + + IF (!equal((double)value[k],expect[k],datatype,NCT_SCHAR)) { + error("att. value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } + } + return nok; +} + +/* + * for _text tests, check all attributes in file which are of text type + * Note no NC_ERANGE check for text attributes as text is not convertible to + * any other numerical data types (i.e. NC_ECHAR) + * + * for other tests, check all numerical attributes in file against values + * outside range of type short + */ +int +check_atts_short(int ncid, int numGatts, int numVars) +{ + int i, j, cdf_format, err; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + size_t k, length, ndx[1]; + nc_type datatype; + size_t nInExtRange; /* number values within external range */ + size_t nInIntRange; /* number values within internal range */ + double expect[MAX_NELS]; + short value[MAX_NELS]; + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_SHORT == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length); + IF (err != NC_NOERR) + error("inq_att: %s", nc_strerror(err)); + IF (datatype != ATT_TYPE(i,j)) + error("inq_att: unexpected type"); + IF (length != ATT_LEN(i,j)) + error("inq_att: unexpected length"); + assert(length <= MAX_NELS); + nInIntRange = nInExtRange = 0; + for (k = 0; k < length; k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, datatype, -1, ndx, NCT_SHORT); + if (inRange3(cdf_format, expect[k], datatype, NCT_SHORT)) { + ++nInExtRange; + if ((expect[k] >= short_min && expect[k] <= short_max)) + ++nInIntRange; + } + } + err = nc_get_att_short(ncid, i, ATT_NAME(i,j), value); + if (nInExtRange == length && nInIntRange == length) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < length; k++) { + if (inRange3(cdf_format, (double)expect[k],datatype,NCT_SHORT) && (expect[k] >= short_min && expect[k] <= short_max)) { + + IF (!equal((double)value[k],expect[k],datatype,NCT_SHORT)) { + error("att. value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } + } + return nok; +} + +/* + * for _text tests, check all attributes in file which are of text type + * Note no NC_ERANGE check for text attributes as text is not convertible to + * any other numerical data types (i.e. NC_ECHAR) + * + * for other tests, check all numerical attributes in file against values + * outside range of type int + */ +int +check_atts_int(int ncid, int numGatts, int numVars) +{ + int i, j, cdf_format, err; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + size_t k, length, ndx[1]; + nc_type datatype; + size_t nInExtRange; /* number values within external range */ + size_t nInIntRange; /* number values within internal range */ + double expect[MAX_NELS]; + int value[MAX_NELS]; + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_INT == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length); + IF (err != NC_NOERR) + error("inq_att: %s", nc_strerror(err)); + IF (datatype != ATT_TYPE(i,j)) + error("inq_att: unexpected type"); + IF (length != ATT_LEN(i,j)) + error("inq_att: unexpected length"); + assert(length <= MAX_NELS); + nInIntRange = nInExtRange = 0; + for (k = 0; k < length; k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, datatype, -1, ndx, NCT_INT); + if (inRange3(cdf_format, expect[k], datatype, NCT_INT)) { + ++nInExtRange; + if ((expect[k] >= int_min && expect[k] <= int_max)) + ++nInIntRange; + } + } + err = nc_get_att_int(ncid, i, ATT_NAME(i,j), value); + if (nInExtRange == length && nInIntRange == length) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < length; k++) { + if (inRange3(cdf_format, (double)expect[k],datatype,NCT_INT) && (expect[k] >= int_min && expect[k] <= int_max)) { + + IF (!equal((double)value[k],expect[k],datatype,NCT_INT)) { + error("att. value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } + } + return nok; +} + +/* + * for _text tests, check all attributes in file which are of text type + * Note no NC_ERANGE check for text attributes as text is not convertible to + * any other numerical data types (i.e. NC_ECHAR) + * + * for other tests, check all numerical attributes in file against values + * outside range of type long + */ +int +check_atts_long(int ncid, int numGatts, int numVars) +{ + int i, j, cdf_format, err; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + size_t k, length, ndx[1]; + nc_type datatype; + size_t nInExtRange; /* number values within external range */ + size_t nInIntRange; /* number values within internal range */ + double expect[MAX_NELS]; + long value[MAX_NELS]; + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_LONG == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length); + IF (err != NC_NOERR) + error("inq_att: %s", nc_strerror(err)); + IF (datatype != ATT_TYPE(i,j)) + error("inq_att: unexpected type"); + IF (length != ATT_LEN(i,j)) + error("inq_att: unexpected length"); + assert(length <= MAX_NELS); + nInIntRange = nInExtRange = 0; + for (k = 0; k < length; k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, datatype, -1, ndx, NCT_LONG); + if (inRange3(cdf_format, expect[k], datatype, NCT_LONG)) { + ++nInExtRange; + if ((expect[k] >= long_min && expect[k] <= long_max)) + ++nInIntRange; + } + } + err = nc_get_att_long(ncid, i, ATT_NAME(i,j), value); + if (nInExtRange == length && nInIntRange == length) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < length; k++) { + if (inRange3(cdf_format, (double)expect[k],datatype,NCT_LONG) && (expect[k] >= long_min && expect[k] <= long_max)) { + + IF (!equal((double)value[k],expect[k],datatype,NCT_LONG)) { + error("att. value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } + } + return nok; +} + +/* + * for _text tests, check all attributes in file which are of text type + * Note no NC_ERANGE check for text attributes as text is not convertible to + * any other numerical data types (i.e. NC_ECHAR) + * + * for other tests, check all numerical attributes in file against values + * outside range of type float + */ +int +check_atts_float(int ncid, int numGatts, int numVars) +{ + int i, j, cdf_format, err; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + size_t k, length, ndx[1]; + nc_type datatype; + size_t nInExtRange; /* number values within external range */ + size_t nInIntRange; /* number values within internal range */ + double expect[MAX_NELS]; + float value[MAX_NELS]; + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_FLOAT == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length); + IF (err != NC_NOERR) + error("inq_att: %s", nc_strerror(err)); + IF (datatype != ATT_TYPE(i,j)) + error("inq_att: unexpected type"); + IF (length != ATT_LEN(i,j)) + error("inq_att: unexpected length"); + assert(length <= MAX_NELS); + nInIntRange = nInExtRange = 0; + for (k = 0; k < length; k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, datatype, -1, ndx, NCT_FLOAT); + if (inRange3(cdf_format, expect[k], datatype, NCT_FLOAT)) { + ++nInExtRange; + if ((expect[k] >= float_min && expect[k] <= float_max)) + ++nInIntRange; + } + } + err = nc_get_att_float(ncid, i, ATT_NAME(i,j), value); + if (nInExtRange == length && nInIntRange == length) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < length; k++) { + if (inRange3(cdf_format, (double)expect[k],datatype,NCT_FLOAT) && (expect[k] >= float_min && expect[k] <= float_max)) { + + IF (!equal((double)value[k],expect[k],datatype,NCT_FLOAT)) { + error("att. value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } + } + return nok; +} + +/* + * for _text tests, check all attributes in file which are of text type + * Note no NC_ERANGE check for text attributes as text is not convertible to + * any other numerical data types (i.e. NC_ECHAR) + * + * for other tests, check all numerical attributes in file against values + * outside range of type double + */ +int +check_atts_double(int ncid, int numGatts, int numVars) +{ + int i, j, cdf_format, err; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + size_t k, length, ndx[1]; + nc_type datatype; + size_t nInExtRange; /* number values within external range */ + size_t nInIntRange; /* number values within internal range */ + double expect[MAX_NELS]; + double value[MAX_NELS]; + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length); + IF (err != NC_NOERR) + error("inq_att: %s", nc_strerror(err)); + IF (datatype != ATT_TYPE(i,j)) + error("inq_att: unexpected type"); + IF (length != ATT_LEN(i,j)) + error("inq_att: unexpected length"); + assert(length <= MAX_NELS); + nInIntRange = nInExtRange = 0; + for (k = 0; k < length; k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, datatype, -1, ndx, NCT_DOUBLE); + if (inRange3(cdf_format, expect[k], datatype, NCT_DOUBLE)) { + ++nInExtRange; + if ((expect[k] >= double_min && expect[k] <= double_max)) + ++nInIntRange; + } + } + err = nc_get_att_double(ncid, i, ATT_NAME(i,j), value); + if (nInExtRange == length && nInIntRange == length) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < length; k++) { + if (inRange3(cdf_format, (double)expect[k],datatype,NCT_DOUBLE) && (expect[k] >= double_min && expect[k] <= double_max)) { + + IF (!equal((double)value[k],expect[k],datatype,NCT_DOUBLE)) { + error("att. value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } + } + return nok; +} + +/* + * for _text tests, check all attributes in file which are of text type + * Note no NC_ERANGE check for text attributes as text is not convertible to + * any other numerical data types (i.e. NC_ECHAR) + * + * for other tests, check all numerical attributes in file against values + * outside range of type ushort + */ +int +check_atts_ushort(int ncid, int numGatts, int numVars) +{ + int i, j, cdf_format, err; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + size_t k, length, ndx[1]; + nc_type datatype; + size_t nInExtRange; /* number values within external range */ + size_t nInIntRange; /* number values within internal range */ + double expect[MAX_NELS]; + ushort value[MAX_NELS]; + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_USHORT == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length); + IF (err != NC_NOERR) + error("inq_att: %s", nc_strerror(err)); + IF (datatype != ATT_TYPE(i,j)) + error("inq_att: unexpected type"); + IF (length != ATT_LEN(i,j)) + error("inq_att: unexpected length"); + assert(length <= MAX_NELS); + nInIntRange = nInExtRange = 0; + for (k = 0; k < length; k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, datatype, -1, ndx, NCT_USHORT); + if (inRange3(cdf_format, expect[k], datatype, NCT_USHORT)) { + ++nInExtRange; + if ((expect[k] >= ushort_min && expect[k] <= ushort_max)) + ++nInIntRange; + } + } + err = nc_get_att_ushort(ncid, i, ATT_NAME(i,j), value); + if (nInExtRange == length && nInIntRange == length) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < length; k++) { + if (inRange3(cdf_format, (double)expect[k],datatype,NCT_USHORT) && (expect[k] >= ushort_min && expect[k] <= ushort_max)) { + + IF (!equal((double)value[k],expect[k],datatype,NCT_USHORT)) { + error("att. value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } + } + return nok; +} + +/* + * for _text tests, check all attributes in file which are of text type + * Note no NC_ERANGE check for text attributes as text is not convertible to + * any other numerical data types (i.e. NC_ECHAR) + * + * for other tests, check all numerical attributes in file against values + * outside range of type uint + */ +int +check_atts_uint(int ncid, int numGatts, int numVars) +{ + int i, j, cdf_format, err; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + size_t k, length, ndx[1]; + nc_type datatype; + size_t nInExtRange; /* number values within external range */ + size_t nInIntRange; /* number values within internal range */ + double expect[MAX_NELS]; + uint value[MAX_NELS]; + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_UINT == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length); + IF (err != NC_NOERR) + error("inq_att: %s", nc_strerror(err)); + IF (datatype != ATT_TYPE(i,j)) + error("inq_att: unexpected type"); + IF (length != ATT_LEN(i,j)) + error("inq_att: unexpected length"); + assert(length <= MAX_NELS); + nInIntRange = nInExtRange = 0; + for (k = 0; k < length; k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, datatype, -1, ndx, NCT_UINT); + if (inRange3(cdf_format, expect[k], datatype, NCT_UINT)) { + ++nInExtRange; + if ((expect[k] >= uint_min && expect[k] <= uint_max)) + ++nInIntRange; + } + } + err = nc_get_att_uint(ncid, i, ATT_NAME(i,j), value); + if (nInExtRange == length && nInIntRange == length) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < length; k++) { + if (inRange3(cdf_format, (double)expect[k],datatype,NCT_UINT) && (expect[k] >= uint_min && expect[k] <= uint_max)) { + + IF (!equal((double)value[k],expect[k],datatype,NCT_UINT)) { + error("att. value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } + } + return nok; +} + +/* + * for _text tests, check all attributes in file which are of text type + * Note no NC_ERANGE check for text attributes as text is not convertible to + * any other numerical data types (i.e. NC_ECHAR) + * + * for other tests, check all numerical attributes in file against values + * outside range of type longlong + */ +int +check_atts_longlong(int ncid, int numGatts, int numVars) +{ + int i, j, cdf_format, err; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + size_t k, length, ndx[1]; + nc_type datatype; + size_t nInExtRange; /* number values within external range */ + size_t nInIntRange; /* number values within internal range */ + double expect[MAX_NELS]; + longlong value[MAX_NELS]; + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_LONGLONG == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length); + IF (err != NC_NOERR) + error("inq_att: %s", nc_strerror(err)); + IF (datatype != ATT_TYPE(i,j)) + error("inq_att: unexpected type"); + IF (length != ATT_LEN(i,j)) + error("inq_att: unexpected length"); + assert(length <= MAX_NELS); + nInIntRange = nInExtRange = 0; + for (k = 0; k < length; k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, datatype, -1, ndx, NCT_LONGLONG); + if (inRange3(cdf_format, expect[k], datatype, NCT_LONGLONG)) { + ++nInExtRange; + if ((expect[k] >= longlong_min && expect[k] <= longlong_max)) + ++nInIntRange; + } + } + err = nc_get_att_longlong(ncid, i, ATT_NAME(i,j), value); + if (nInExtRange == length && nInIntRange == length) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < length; k++) { + if (inRange3(cdf_format, (double)expect[k],datatype,NCT_LONGLONG) && (expect[k] >= longlong_min && expect[k] <= longlong_max)) { + + IF (!equal((double)value[k],expect[k],datatype,NCT_LONGLONG)) { + error("att. value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } + } + return nok; +} + +/* + * for _text tests, check all attributes in file which are of text type + * Note no NC_ERANGE check for text attributes as text is not convertible to + * any other numerical data types (i.e. NC_ECHAR) + * + * for other tests, check all numerical attributes in file against values + * outside range of type ulonglong + */ +int +check_atts_ulonglong(int ncid, int numGatts, int numVars) +{ + int i, j, cdf_format, err; + int canConvert; /* Both text or both numeric */ + int nok = 0; /* count of valid comparisons */ + size_t k, length, ndx[1]; + nc_type datatype; + size_t nInExtRange; /* number values within external range */ + size_t nInIntRange; /* number values within internal range */ + double expect[MAX_NELS]; + ulonglong value[MAX_NELS]; + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + canConvert = (ATT_TYPE(i,j) == NC_CHAR) == (NCT_ULONGLONG == NCT_TEXT); + if (!canConvert) continue; + + err = nc_inq_att(ncid, i, ATT_NAME(i,j), &datatype, &length); + IF (err != NC_NOERR) + error("inq_att: %s", nc_strerror(err)); + IF (datatype != ATT_TYPE(i,j)) + error("inq_att: unexpected type"); + IF (length != ATT_LEN(i,j)) + error("inq_att: unexpected length"); + assert(length <= MAX_NELS); + nInIntRange = nInExtRange = 0; + for (k = 0; k < length; k++) { + ndx[0] = k; + expect[k] = hash4(cdf_format, datatype, -1, ndx, NCT_ULONGLONG); + if (inRange3(cdf_format, expect[k], datatype, NCT_ULONGLONG)) { + ++nInExtRange; + if ((expect[k] >= ulonglong_min && expect[k] <= ulonglong_max)) + ++nInIntRange; + } + } + err = nc_get_att_ulonglong(ncid, i, ATT_NAME(i,j), value); + if (nInExtRange == length && nInIntRange == length) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + } else { + IF (err != NC_NOERR && err != NC_ERANGE) + error("expecting NC_NOERR or NC_ERANGE but got %s",nc_err_code_name(err)); + } + for (k = 0; k < length; k++) { + if (inRange3(cdf_format, (double)expect[k],datatype,NCT_ULONGLONG) && (expect[k] >= ulonglong_min && expect[k] <= ulonglong_max)) { + + IF (!equal((double)value[k],expect[k],datatype,NCT_ULONGLONG)) { + error("att. value read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("att_name: %s, ", ATT_NAME(i,j)); + error("att_type: %s, ", s_nc_type(ATT_TYPE(i,j))); + error("element number: %d ", k); + error("expect: %g, ", expect[k]); + error("got: %g", (double) value[k]); + } + } else { + nok++; + } + } + } + } + } + return nok; +} + + + + +int +test_nc_put_var1_text(void) +{ + int i, err, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + text value[1]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var1_text(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var1_text(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var1_text(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) ; + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) index[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_var1_text(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[0] = hash_text(cdf_format, var_type[i], var_rank[i], index, + NCT_TEXT); + err = nc_put_var1_text(ncid, i, index, value); + if (canConvert) { + if (1) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_text(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var1_uchar(void) +{ + int i, err, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + uchar value[1]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var1_uchar(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var1_uchar(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var1_uchar(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UCHAR == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) index[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_var1_uchar(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[0] = hash_uchar(cdf_format, var_type[i], var_rank[i], index, + NCT_UCHAR); + err = nc_put_var1_uchar(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, (double)value[0],var_type[i],NCT_UCHAR)) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=8) + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } +#endif + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_uchar(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var1_schar(void) +{ + int i, err, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + schar value[1]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var1_schar(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var1_schar(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var1_schar(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SCHAR == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) index[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_var1_schar(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[0] = hash_schar(cdf_format, var_type[i], var_rank[i], index, + NCT_SCHAR); + err = nc_put_var1_schar(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, (double)value[0],var_type[i],NCT_SCHAR)) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + +#if defined(USE_PNETCDF) && PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR<7 + else if (cdf_format < NC_FORMAT_CDF5) { +#else + else { +#endif + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_schar(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var1_short(void) +{ + int i, err, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + short value[1]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var1_short(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var1_short(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var1_short(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SHORT == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) index[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_var1_short(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[0] = hash_short(cdf_format, var_type[i], var_rank[i], index, + NCT_SHORT); + err = nc_put_var1_short(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, (double)value[0],var_type[i],NCT_SHORT)) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_short(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var1_int(void) +{ + int i, err, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + int value[1]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var1_int(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var1_int(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var1_int(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_INT == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) index[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_var1_int(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[0] = hash_int(cdf_format, var_type[i], var_rank[i], index, + NCT_INT); + err = nc_put_var1_int(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, (double)value[0],var_type[i],NCT_INT)) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_int(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var1_long(void) +{ + int i, err, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + long value[1]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var1_long(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var1_long(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var1_long(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONG == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) index[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_var1_long(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[0] = hash_long(cdf_format, var_type[i], var_rank[i], index, + NCT_LONG); + err = nc_put_var1_long(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, (double)value[0],var_type[i],NCT_LONG)) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_long(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var1_float(void) +{ + int i, err, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + float value[1]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var1_float(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var1_float(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var1_float(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_FLOAT == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) index[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_var1_float(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[0] = hash_float(cdf_format, var_type[i], var_rank[i], index, + NCT_FLOAT); + err = nc_put_var1_float(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, (double)value[0],var_type[i],NCT_FLOAT)) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_float(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var1_double(void) +{ + int i, err, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + double value[1]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var1_double(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var1_double(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var1_double(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) index[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_var1_double(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[0] = hash_double(cdf_format, var_type[i], var_rank[i], index, + NCT_DOUBLE); + err = nc_put_var1_double(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, (double)value[0],var_type[i],NCT_DOUBLE)) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_double(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var1_ushort(void) +{ + int i, err, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + ushort value[1]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var1_ushort(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var1_ushort(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var1_ushort(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_USHORT == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) index[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_var1_ushort(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[0] = hash_ushort(cdf_format, var_type[i], var_rank[i], index, + NCT_USHORT); + err = nc_put_var1_ushort(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, (double)value[0],var_type[i],NCT_USHORT)) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_ushort(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var1_uint(void) +{ + int i, err, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + uint value[1]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var1_uint(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var1_uint(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var1_uint(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UINT == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) index[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_var1_uint(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[0] = hash_uint(cdf_format, var_type[i], var_rank[i], index, + NCT_UINT); + err = nc_put_var1_uint(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, (double)value[0],var_type[i],NCT_UINT)) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_uint(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var1_longlong(void) +{ + int i, err, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + longlong value[1]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var1_longlong(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var1_longlong(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var1_longlong(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONGLONG == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) index[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_var1_longlong(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[0] = hash_longlong(cdf_format, var_type[i], var_rank[i], index, + NCT_LONGLONG); + err = nc_put_var1_longlong(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, (double)value[0],var_type[i],NCT_LONGLONG)) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_longlong(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var1_ulonglong(void) +{ + int i, err, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + size_t j, index[MAX_RANK]; + ulonglong value[1]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var1_ulonglong(BAD_ID, 0, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var1_ulonglong(ncid, BAD_VARID, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var1_ulonglong(BAD_ID, i, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_ULONGLONG == NCT_TEXT); + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) index[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_var1_ulonglong(ncid, i, index, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[0] = hash_ulonglong(cdf_format, var_type[i], var_rank[i], index, + NCT_ULONGLONG); + err = nc_put_var1_ulonglong(ncid, i, index, value); + if (canConvert) { + if (inRange3(cdf_format, (double)value[0],var_type[i],NCT_ULONGLONG)) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_ulonglong(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + + + + +int +test_nc_put_var_text(void) +{ + int i, err, ncid, varid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, index[MAX_RANK]; + text value[MAX_NELS]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var_text(BAD_ID, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var_text(ncid, BAD_VARID, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + if (var_dimid[i][0] == RECDIM) continue; /* fixed-size variables only */ + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var_text(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) ; + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_text(cdf_format,var_type[i], var_rank[i], index, + NCT_TEXT); + if (var_type[i] != NC_CHAR) + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_TEXT); + } + err = nc_put_var_text(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { /* should flag wrong type even if nothing to write */ + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + /* Preceding has written nothing for record variables, now try */ + /* again with more than 0 records */ + + /* Write record number NRECS to force writing of preceding records */ + /* Assumes variable cr is char vector with UNLIMITED dimension */ + err = nc_inq_varid(ncid, "cr", &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + index[0] = NRECS-1; + err = nc_put_var1_text(ncid, varid, index, "x"); + IF (err != NC_NOERR) + error("put_var1_text: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + if (var_dimid[i][0] != RECDIM) continue; /* only record variables here */ + + canConvert = (var_type[i] == NC_CHAR) ; + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_text(cdf_format,var_type[i], var_rank[i], index, + NCT_TEXT); + if (var_type[i] != NC_CHAR) + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_TEXT); + } + err = nc_put_var_text(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_text(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var_uchar(void) +{ + int i, err, ncid, varid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, index[MAX_RANK]; + uchar value[MAX_NELS]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var_uchar(BAD_ID, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var_uchar(ncid, BAD_VARID, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + if (var_dimid[i][0] == RECDIM) continue; /* fixed-size variables only */ + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var_uchar(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UCHAR == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_uchar(cdf_format,var_type[i], var_rank[i], index, + NCT_UCHAR); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_UCHAR); + } + err = nc_put_var_uchar(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=8) + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } +#endif + + } else { /* should flag wrong type even if nothing to write */ + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + /* Preceding has written nothing for record variables, now try */ + /* again with more than 0 records */ + + /* Write record number NRECS to force writing of preceding records */ + /* Assumes variable cr is char vector with UNLIMITED dimension */ + err = nc_inq_varid(ncid, "cr", &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + index[0] = NRECS-1; + err = nc_put_var1_text(ncid, varid, index, "x"); + IF (err != NC_NOERR) + error("put_var1_text: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + if (var_dimid[i][0] != RECDIM) continue; /* only record variables here */ + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UCHAR == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_uchar(cdf_format,var_type[i], var_rank[i], index, + NCT_UCHAR); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_UCHAR); + } + err = nc_put_var_uchar(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_uchar(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var_schar(void) +{ + int i, err, ncid, varid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, index[MAX_RANK]; + schar value[MAX_NELS]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var_schar(BAD_ID, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var_schar(ncid, BAD_VARID, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + if (var_dimid[i][0] == RECDIM) continue; /* fixed-size variables only */ + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var_schar(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SCHAR == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_schar(cdf_format,var_type[i], var_rank[i], index, + NCT_SCHAR); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_SCHAR); + } + err = nc_put_var_schar(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + +#if defined(USE_PNETCDF) && PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR<7 + else if (cdf_format < NC_FORMAT_CDF5) { +#else + else { +#endif + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { /* should flag wrong type even if nothing to write */ + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + /* Preceding has written nothing for record variables, now try */ + /* again with more than 0 records */ + + /* Write record number NRECS to force writing of preceding records */ + /* Assumes variable cr is char vector with UNLIMITED dimension */ + err = nc_inq_varid(ncid, "cr", &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + index[0] = NRECS-1; + err = nc_put_var1_text(ncid, varid, index, "x"); + IF (err != NC_NOERR) + error("put_var1_text: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + if (var_dimid[i][0] != RECDIM) continue; /* only record variables here */ + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SCHAR == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_schar(cdf_format,var_type[i], var_rank[i], index, + NCT_SCHAR); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_SCHAR); + } + err = nc_put_var_schar(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_schar(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var_short(void) +{ + int i, err, ncid, varid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, index[MAX_RANK]; + short value[MAX_NELS]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var_short(BAD_ID, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var_short(ncid, BAD_VARID, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + if (var_dimid[i][0] == RECDIM) continue; /* fixed-size variables only */ + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var_short(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SHORT == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_short(cdf_format,var_type[i], var_rank[i], index, + NCT_SHORT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_SHORT); + } + err = nc_put_var_short(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { /* should flag wrong type even if nothing to write */ + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + /* Preceding has written nothing for record variables, now try */ + /* again with more than 0 records */ + + /* Write record number NRECS to force writing of preceding records */ + /* Assumes variable cr is char vector with UNLIMITED dimension */ + err = nc_inq_varid(ncid, "cr", &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + index[0] = NRECS-1; + err = nc_put_var1_text(ncid, varid, index, "x"); + IF (err != NC_NOERR) + error("put_var1_text: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + if (var_dimid[i][0] != RECDIM) continue; /* only record variables here */ + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SHORT == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_short(cdf_format,var_type[i], var_rank[i], index, + NCT_SHORT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_SHORT); + } + err = nc_put_var_short(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_short(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var_int(void) +{ + int i, err, ncid, varid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, index[MAX_RANK]; + int value[MAX_NELS]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var_int(BAD_ID, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var_int(ncid, BAD_VARID, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + if (var_dimid[i][0] == RECDIM) continue; /* fixed-size variables only */ + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var_int(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_INT == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_int(cdf_format,var_type[i], var_rank[i], index, + NCT_INT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_INT); + } + err = nc_put_var_int(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { /* should flag wrong type even if nothing to write */ + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + /* Preceding has written nothing for record variables, now try */ + /* again with more than 0 records */ + + /* Write record number NRECS to force writing of preceding records */ + /* Assumes variable cr is char vector with UNLIMITED dimension */ + err = nc_inq_varid(ncid, "cr", &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + index[0] = NRECS-1; + err = nc_put_var1_text(ncid, varid, index, "x"); + IF (err != NC_NOERR) + error("put_var1_text: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + if (var_dimid[i][0] != RECDIM) continue; /* only record variables here */ + + canConvert = (var_type[i] == NC_CHAR) == (NCT_INT == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_int(cdf_format,var_type[i], var_rank[i], index, + NCT_INT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_INT); + } + err = nc_put_var_int(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_int(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var_long(void) +{ + int i, err, ncid, varid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, index[MAX_RANK]; + long value[MAX_NELS]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var_long(BAD_ID, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var_long(ncid, BAD_VARID, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + if (var_dimid[i][0] == RECDIM) continue; /* fixed-size variables only */ + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var_long(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONG == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_long(cdf_format,var_type[i], var_rank[i], index, + NCT_LONG); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_LONG); + } + err = nc_put_var_long(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { /* should flag wrong type even if nothing to write */ + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + /* Preceding has written nothing for record variables, now try */ + /* again with more than 0 records */ + + /* Write record number NRECS to force writing of preceding records */ + /* Assumes variable cr is char vector with UNLIMITED dimension */ + err = nc_inq_varid(ncid, "cr", &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + index[0] = NRECS-1; + err = nc_put_var1_text(ncid, varid, index, "x"); + IF (err != NC_NOERR) + error("put_var1_text: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + if (var_dimid[i][0] != RECDIM) continue; /* only record variables here */ + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONG == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_long(cdf_format,var_type[i], var_rank[i], index, + NCT_LONG); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_LONG); + } + err = nc_put_var_long(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_long(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var_float(void) +{ + int i, err, ncid, varid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, index[MAX_RANK]; + float value[MAX_NELS]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var_float(BAD_ID, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var_float(ncid, BAD_VARID, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + if (var_dimid[i][0] == RECDIM) continue; /* fixed-size variables only */ + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var_float(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_FLOAT == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_float(cdf_format,var_type[i], var_rank[i], index, + NCT_FLOAT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_FLOAT); + } + err = nc_put_var_float(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { /* should flag wrong type even if nothing to write */ + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + /* Preceding has written nothing for record variables, now try */ + /* again with more than 0 records */ + + /* Write record number NRECS to force writing of preceding records */ + /* Assumes variable cr is char vector with UNLIMITED dimension */ + err = nc_inq_varid(ncid, "cr", &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + index[0] = NRECS-1; + err = nc_put_var1_text(ncid, varid, index, "x"); + IF (err != NC_NOERR) + error("put_var1_text: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + if (var_dimid[i][0] != RECDIM) continue; /* only record variables here */ + + canConvert = (var_type[i] == NC_CHAR) == (NCT_FLOAT == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_float(cdf_format,var_type[i], var_rank[i], index, + NCT_FLOAT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_FLOAT); + } + err = nc_put_var_float(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_float(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var_double(void) +{ + int i, err, ncid, varid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, index[MAX_RANK]; + double value[MAX_NELS]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var_double(BAD_ID, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var_double(ncid, BAD_VARID, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + if (var_dimid[i][0] == RECDIM) continue; /* fixed-size variables only */ + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var_double(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_double(cdf_format,var_type[i], var_rank[i], index, + NCT_DOUBLE); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_DOUBLE); + } + err = nc_put_var_double(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { /* should flag wrong type even if nothing to write */ + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + /* Preceding has written nothing for record variables, now try */ + /* again with more than 0 records */ + + /* Write record number NRECS to force writing of preceding records */ + /* Assumes variable cr is char vector with UNLIMITED dimension */ + err = nc_inq_varid(ncid, "cr", &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + index[0] = NRECS-1; + err = nc_put_var1_text(ncid, varid, index, "x"); + IF (err != NC_NOERR) + error("put_var1_text: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + if (var_dimid[i][0] != RECDIM) continue; /* only record variables here */ + + canConvert = (var_type[i] == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_double(cdf_format,var_type[i], var_rank[i], index, + NCT_DOUBLE); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_DOUBLE); + } + err = nc_put_var_double(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_double(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var_ushort(void) +{ + int i, err, ncid, varid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, index[MAX_RANK]; + ushort value[MAX_NELS]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var_ushort(BAD_ID, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var_ushort(ncid, BAD_VARID, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + if (var_dimid[i][0] == RECDIM) continue; /* fixed-size variables only */ + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var_ushort(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_USHORT == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_ushort(cdf_format,var_type[i], var_rank[i], index, + NCT_USHORT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_USHORT); + } + err = nc_put_var_ushort(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { /* should flag wrong type even if nothing to write */ + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + /* Preceding has written nothing for record variables, now try */ + /* again with more than 0 records */ + + /* Write record number NRECS to force writing of preceding records */ + /* Assumes variable cr is char vector with UNLIMITED dimension */ + err = nc_inq_varid(ncid, "cr", &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + index[0] = NRECS-1; + err = nc_put_var1_text(ncid, varid, index, "x"); + IF (err != NC_NOERR) + error("put_var1_text: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + if (var_dimid[i][0] != RECDIM) continue; /* only record variables here */ + + canConvert = (var_type[i] == NC_CHAR) == (NCT_USHORT == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_ushort(cdf_format,var_type[i], var_rank[i], index, + NCT_USHORT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_USHORT); + } + err = nc_put_var_ushort(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_ushort(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var_uint(void) +{ + int i, err, ncid, varid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, index[MAX_RANK]; + uint value[MAX_NELS]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var_uint(BAD_ID, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var_uint(ncid, BAD_VARID, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + if (var_dimid[i][0] == RECDIM) continue; /* fixed-size variables only */ + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var_uint(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UINT == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_uint(cdf_format,var_type[i], var_rank[i], index, + NCT_UINT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_UINT); + } + err = nc_put_var_uint(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { /* should flag wrong type even if nothing to write */ + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + /* Preceding has written nothing for record variables, now try */ + /* again with more than 0 records */ + + /* Write record number NRECS to force writing of preceding records */ + /* Assumes variable cr is char vector with UNLIMITED dimension */ + err = nc_inq_varid(ncid, "cr", &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + index[0] = NRECS-1; + err = nc_put_var1_text(ncid, varid, index, "x"); + IF (err != NC_NOERR) + error("put_var1_text: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + if (var_dimid[i][0] != RECDIM) continue; /* only record variables here */ + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UINT == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_uint(cdf_format,var_type[i], var_rank[i], index, + NCT_UINT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_UINT); + } + err = nc_put_var_uint(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_uint(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var_longlong(void) +{ + int i, err, ncid, varid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, index[MAX_RANK]; + longlong value[MAX_NELS]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var_longlong(BAD_ID, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var_longlong(ncid, BAD_VARID, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + if (var_dimid[i][0] == RECDIM) continue; /* fixed-size variables only */ + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var_longlong(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONGLONG == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_longlong(cdf_format,var_type[i], var_rank[i], index, + NCT_LONGLONG); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_LONGLONG); + } + err = nc_put_var_longlong(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { /* should flag wrong type even if nothing to write */ + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + /* Preceding has written nothing for record variables, now try */ + /* again with more than 0 records */ + + /* Write record number NRECS to force writing of preceding records */ + /* Assumes variable cr is char vector with UNLIMITED dimension */ + err = nc_inq_varid(ncid, "cr", &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + index[0] = NRECS-1; + err = nc_put_var1_text(ncid, varid, index, "x"); + IF (err != NC_NOERR) + error("put_var1_text: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + if (var_dimid[i][0] != RECDIM) continue; /* only record variables here */ + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONGLONG == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_longlong(cdf_format,var_type[i], var_rank[i], index, + NCT_LONGLONG); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_LONGLONG); + } + err = nc_put_var_longlong(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_longlong(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_var_ulonglong(void) +{ + int i, err, ncid, varid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, index[MAX_RANK]; + ulonglong value[MAX_NELS]; + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var_ulonglong(BAD_ID, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var_ulonglong(ncid, BAD_VARID, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + if (var_dimid[i][0] == RECDIM) continue; /* fixed-size variables only */ + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_var_ulonglong(BAD_ID, i, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_ULONGLONG == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_ulonglong(cdf_format,var_type[i], var_rank[i], index, + NCT_ULONGLONG); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_ULONGLONG); + } + err = nc_put_var_ulonglong(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { /* should flag wrong type even if nothing to write */ + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + /* Preceding has written nothing for record variables, now try */ + /* again with more than 0 records */ + + /* Write record number NRECS to force writing of preceding records */ + /* Assumes variable cr is char vector with UNLIMITED dimension */ + err = nc_inq_varid(ncid, "cr", &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + index[0] = NRECS-1; + err = nc_put_var1_text(ncid, varid, index, "x"); + IF (err != NC_NOERR) + error("put_var1_text: %s", nc_strerror(err)); + + for (i = 0; i < numVars; i++) { + if (var_dimid[i][0] != RECDIM) continue; /* only record variables here */ + + canConvert = (var_type[i] == NC_CHAR) == (NCT_ULONGLONG == NCT_TEXT); + + for (allInExtRange = 1, j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[j]= hash_ulonglong(cdf_format,var_type[i], var_rank[i], index, + NCT_ULONGLONG); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_ULONGLONG); + } + err = nc_put_var_ulonglong(ncid, i, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } else { + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_ulonglong(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + + + + +int +test_nc_put_vara_text(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, nels; + size_t start[MAX_RANK], edge[MAX_RANK]; + size_t mid[MAX_RANK], index[MAX_RANK]; + text value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vara_text(BAD_ID, 0, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vara_text(ncid, BAD_VARID, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vara_text(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) ; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_text(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vara_text(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDG but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + } + + /* Check correct error returned when nothing to put, when edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_text(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vara_text(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index[d] += start[d]; + value[j]= hash_text(cdf_format,var_type[i], var_rank[i], index, + NCT_TEXT); + if (var_type[i] != NC_CHAR) + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_TEXT); + } + err = nc_put_vara_text(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_text(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vara_uchar(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, nels; + size_t start[MAX_RANK], edge[MAX_RANK]; + size_t mid[MAX_RANK], index[MAX_RANK]; + uchar value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vara_uchar(BAD_ID, 0, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vara_uchar(ncid, BAD_VARID, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vara_uchar(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UCHAR == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_uchar(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vara_uchar(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDG but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + } + + /* Check correct error returned when nothing to put, when edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_uchar(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vara_uchar(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index[d] += start[d]; + value[j]= hash_uchar(cdf_format,var_type[i], var_rank[i], index, + NCT_UCHAR); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_UCHAR); + } + err = nc_put_vara_uchar(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=8) + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } +#endif + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_uchar(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vara_schar(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, nels; + size_t start[MAX_RANK], edge[MAX_RANK]; + size_t mid[MAX_RANK], index[MAX_RANK]; + schar value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vara_schar(BAD_ID, 0, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vara_schar(ncid, BAD_VARID, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vara_schar(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SCHAR == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_schar(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vara_schar(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDG but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + } + + /* Check correct error returned when nothing to put, when edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_schar(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vara_schar(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index[d] += start[d]; + value[j]= hash_schar(cdf_format,var_type[i], var_rank[i], index, + NCT_SCHAR); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_SCHAR); + } + err = nc_put_vara_schar(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + +#if defined(USE_PNETCDF) && PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR<7 + else if (cdf_format < NC_FORMAT_CDF5) { +#else + else { +#endif + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_schar(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vara_short(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, nels; + size_t start[MAX_RANK], edge[MAX_RANK]; + size_t mid[MAX_RANK], index[MAX_RANK]; + short value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vara_short(BAD_ID, 0, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vara_short(ncid, BAD_VARID, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vara_short(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SHORT == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_short(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vara_short(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDG but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + } + + /* Check correct error returned when nothing to put, when edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_short(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vara_short(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index[d] += start[d]; + value[j]= hash_short(cdf_format,var_type[i], var_rank[i], index, + NCT_SHORT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_SHORT); + } + err = nc_put_vara_short(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_short(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vara_int(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, nels; + size_t start[MAX_RANK], edge[MAX_RANK]; + size_t mid[MAX_RANK], index[MAX_RANK]; + int value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vara_int(BAD_ID, 0, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vara_int(ncid, BAD_VARID, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vara_int(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_INT == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_int(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vara_int(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDG but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + } + + /* Check correct error returned when nothing to put, when edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_int(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vara_int(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index[d] += start[d]; + value[j]= hash_int(cdf_format,var_type[i], var_rank[i], index, + NCT_INT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_INT); + } + err = nc_put_vara_int(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_int(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vara_long(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, nels; + size_t start[MAX_RANK], edge[MAX_RANK]; + size_t mid[MAX_RANK], index[MAX_RANK]; + long value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vara_long(BAD_ID, 0, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vara_long(ncid, BAD_VARID, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vara_long(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONG == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_long(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vara_long(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDG but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + } + + /* Check correct error returned when nothing to put, when edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_long(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vara_long(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index[d] += start[d]; + value[j]= hash_long(cdf_format,var_type[i], var_rank[i], index, + NCT_LONG); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_LONG); + } + err = nc_put_vara_long(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_long(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vara_float(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, nels; + size_t start[MAX_RANK], edge[MAX_RANK]; + size_t mid[MAX_RANK], index[MAX_RANK]; + float value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vara_float(BAD_ID, 0, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vara_float(ncid, BAD_VARID, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vara_float(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_FLOAT == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_float(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vara_float(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDG but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + } + + /* Check correct error returned when nothing to put, when edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_float(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vara_float(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index[d] += start[d]; + value[j]= hash_float(cdf_format,var_type[i], var_rank[i], index, + NCT_FLOAT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_FLOAT); + } + err = nc_put_vara_float(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_float(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vara_double(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, nels; + size_t start[MAX_RANK], edge[MAX_RANK]; + size_t mid[MAX_RANK], index[MAX_RANK]; + double value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vara_double(BAD_ID, 0, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vara_double(ncid, BAD_VARID, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vara_double(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_double(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vara_double(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDG but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + } + + /* Check correct error returned when nothing to put, when edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_double(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vara_double(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index[d] += start[d]; + value[j]= hash_double(cdf_format,var_type[i], var_rank[i], index, + NCT_DOUBLE); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_DOUBLE); + } + err = nc_put_vara_double(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_double(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vara_ushort(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, nels; + size_t start[MAX_RANK], edge[MAX_RANK]; + size_t mid[MAX_RANK], index[MAX_RANK]; + ushort value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vara_ushort(BAD_ID, 0, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vara_ushort(ncid, BAD_VARID, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vara_ushort(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_USHORT == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_ushort(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vara_ushort(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDG but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + } + + /* Check correct error returned when nothing to put, when edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_ushort(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vara_ushort(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index[d] += start[d]; + value[j]= hash_ushort(cdf_format,var_type[i], var_rank[i], index, + NCT_USHORT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_USHORT); + } + err = nc_put_vara_ushort(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_ushort(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vara_uint(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, nels; + size_t start[MAX_RANK], edge[MAX_RANK]; + size_t mid[MAX_RANK], index[MAX_RANK]; + uint value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vara_uint(BAD_ID, 0, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vara_uint(ncid, BAD_VARID, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vara_uint(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UINT == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_uint(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vara_uint(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDG but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + } + + /* Check correct error returned when nothing to put, when edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_uint(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vara_uint(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index[d] += start[d]; + value[j]= hash_uint(cdf_format,var_type[i], var_rank[i], index, + NCT_UINT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_UINT); + } + err = nc_put_vara_uint(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_uint(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vara_longlong(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, nels; + size_t start[MAX_RANK], edge[MAX_RANK]; + size_t mid[MAX_RANK], index[MAX_RANK]; + longlong value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vara_longlong(BAD_ID, 0, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vara_longlong(ncid, BAD_VARID, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vara_longlong(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONGLONG == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_longlong(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vara_longlong(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDG but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + } + + /* Check correct error returned when nothing to put, when edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_longlong(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vara_longlong(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index[d] += start[d]; + value[j]= hash_longlong(cdf_format,var_type[i], var_rank[i], index, + NCT_LONGLONG); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_LONGLONG); + } + err = nc_put_vara_longlong(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_longlong(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vara_ulonglong(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, nels; + size_t start[MAX_RANK], edge[MAX_RANK]; + size_t mid[MAX_RANK], index[MAX_RANK]; + ulonglong value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vara_ulonglong(BAD_ID, 0, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vara_ulonglong(ncid, BAD_VARID, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vara_ulonglong(BAD_ID, i, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_ULONGLONG == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_ulonglong(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vara_ulonglong(ncid, i, start, edge, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDG but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + } + + /* Check correct error returned when nothing to put, when edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara_ulonglong(ncid, i, start, edge, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vara_ulonglong(ncid, i, start, edge, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index[d] += start[d]; + value[j]= hash_ulonglong(cdf_format,var_type[i], var_rank[i], index, + NCT_ULONGLONG); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_ULONGLONG); + } + err = nc_put_vara_ulonglong(ncid, i, start, edge, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_ulonglong(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + + + + +int +test_nc_put_vars_text(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK]; + text value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vars_text(BAD_ID, 0, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vars_text(ncid, BAD_VARID, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vars_text(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) ; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_vars_text(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vars_text(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_vars_text(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned even when nothing to put */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vars_text(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vars_text(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_text(cdf_format,var_type[i], var_rank[i], + index2, NCT_TEXT); + if (var_type[i] != NC_CHAR) + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_TEXT); + } + err = nc_put_vars_text(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_text(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vars_uchar(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK]; + uchar value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vars_uchar(BAD_ID, 0, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vars_uchar(ncid, BAD_VARID, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vars_uchar(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UCHAR == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_vars_uchar(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vars_uchar(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_vars_uchar(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned even when nothing to put */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vars_uchar(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vars_uchar(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_uchar(cdf_format,var_type[i], var_rank[i], + index2, NCT_UCHAR); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_UCHAR); + } + err = nc_put_vars_uchar(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=8) + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } +#endif + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_uchar(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vars_schar(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK]; + schar value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vars_schar(BAD_ID, 0, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vars_schar(ncid, BAD_VARID, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vars_schar(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SCHAR == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_vars_schar(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vars_schar(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_vars_schar(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned even when nothing to put */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vars_schar(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vars_schar(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_schar(cdf_format,var_type[i], var_rank[i], + index2, NCT_SCHAR); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_SCHAR); + } + err = nc_put_vars_schar(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + +#if defined(USE_PNETCDF) && PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR<7 + else if (cdf_format < NC_FORMAT_CDF5) { +#else + else { +#endif + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_schar(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vars_short(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK]; + short value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vars_short(BAD_ID, 0, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vars_short(ncid, BAD_VARID, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vars_short(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SHORT == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_vars_short(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vars_short(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_vars_short(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned even when nothing to put */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vars_short(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vars_short(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_short(cdf_format,var_type[i], var_rank[i], + index2, NCT_SHORT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_SHORT); + } + err = nc_put_vars_short(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_short(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vars_int(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK]; + int value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vars_int(BAD_ID, 0, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vars_int(ncid, BAD_VARID, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vars_int(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_INT == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_vars_int(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vars_int(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_vars_int(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned even when nothing to put */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vars_int(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vars_int(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_int(cdf_format,var_type[i], var_rank[i], + index2, NCT_INT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_INT); + } + err = nc_put_vars_int(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_int(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vars_long(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK]; + long value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vars_long(BAD_ID, 0, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vars_long(ncid, BAD_VARID, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vars_long(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONG == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_vars_long(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vars_long(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_vars_long(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned even when nothing to put */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vars_long(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vars_long(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_long(cdf_format,var_type[i], var_rank[i], + index2, NCT_LONG); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_LONG); + } + err = nc_put_vars_long(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_long(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vars_float(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK]; + float value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vars_float(BAD_ID, 0, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vars_float(ncid, BAD_VARID, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vars_float(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_FLOAT == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_vars_float(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vars_float(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_vars_float(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned even when nothing to put */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vars_float(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vars_float(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_float(cdf_format,var_type[i], var_rank[i], + index2, NCT_FLOAT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_FLOAT); + } + err = nc_put_vars_float(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_float(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vars_double(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK]; + double value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vars_double(BAD_ID, 0, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vars_double(ncid, BAD_VARID, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vars_double(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_vars_double(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vars_double(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_vars_double(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned even when nothing to put */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vars_double(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vars_double(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_double(cdf_format,var_type[i], var_rank[i], + index2, NCT_DOUBLE); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_DOUBLE); + } + err = nc_put_vars_double(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_double(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vars_ushort(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK]; + ushort value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vars_ushort(BAD_ID, 0, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vars_ushort(ncid, BAD_VARID, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vars_ushort(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_USHORT == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_vars_ushort(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vars_ushort(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_vars_ushort(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned even when nothing to put */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vars_ushort(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vars_ushort(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_ushort(cdf_format,var_type[i], var_rank[i], + index2, NCT_USHORT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_USHORT); + } + err = nc_put_vars_ushort(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_ushort(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vars_uint(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK]; + uint value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vars_uint(BAD_ID, 0, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vars_uint(ncid, BAD_VARID, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vars_uint(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UINT == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_vars_uint(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vars_uint(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_vars_uint(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned even when nothing to put */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vars_uint(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vars_uint(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_uint(cdf_format,var_type[i], var_rank[i], + index2, NCT_UINT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_UINT); + } + err = nc_put_vars_uint(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_uint(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vars_longlong(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK]; + longlong value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vars_longlong(BAD_ID, 0, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vars_longlong(ncid, BAD_VARID, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vars_longlong(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONGLONG == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_vars_longlong(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vars_longlong(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_vars_longlong(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned even when nothing to put */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vars_longlong(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vars_longlong(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_longlong(cdf_format,var_type[i], var_rank[i], + index2, NCT_LONGLONG); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_LONGLONG); + } + err = nc_put_vars_longlong(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_longlong(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_vars_ulonglong(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK]; + ulonglong value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vars_ulonglong(BAD_ID, 0, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vars_ulonglong(ncid, BAD_VARID, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vars_ulonglong(BAD_ID, i, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_ULONGLONG == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_vars_ulonglong(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vars_ulonglong(ncid, i, start, edge, stride, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_vars_ulonglong(ncid, i, start, edge, stride, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned even when nothing to put */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vars_ulonglong(ncid, i, start, edge, stride, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vars_ulonglong(ncid, i, start, edge, stride, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_ulonglong(cdf_format,var_type[i], var_rank[i], + index2, NCT_ULONGLONG); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_ULONGLONG); + } + err = nc_put_vars_ulonglong(ncid, i, index, count, stride, value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_ulonglong(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + + + + +int +test_nc_put_varm_text(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + text value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_varm_text(BAD_ID, 0, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_varm_text(ncid, BAD_VARID, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_varm_text(BAD_ID, i, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) ; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_varm_text(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_varm_text(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_varm_text(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned when nothing to put, i.e. edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]&& j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_varm_text(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_varm_text(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / (size_t)stride[j]; + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_text(cdf_format,var_type[i], var_rank[i], + index2, NCT_TEXT); + if (var_type[i] != NC_CHAR) + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_TEXT); + } + err = nc_put_varm_text(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_text(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_varm_uchar(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + uchar value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_varm_uchar(BAD_ID, 0, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_varm_uchar(ncid, BAD_VARID, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_varm_uchar(BAD_ID, i, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UCHAR == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_varm_uchar(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_varm_uchar(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_varm_uchar(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned when nothing to put, i.e. edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]&& j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_varm_uchar(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_varm_uchar(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / (size_t)stride[j]; + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_uchar(cdf_format,var_type[i], var_rank[i], + index2, NCT_UCHAR); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_UCHAR); + } + err = nc_put_varm_uchar(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=8) + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } +#endif + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_uchar(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_varm_schar(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + schar value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_varm_schar(BAD_ID, 0, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_varm_schar(ncid, BAD_VARID, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_varm_schar(BAD_ID, i, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SCHAR == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_varm_schar(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_varm_schar(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_varm_schar(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned when nothing to put, i.e. edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]&& j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_varm_schar(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_varm_schar(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / (size_t)stride[j]; + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_schar(cdf_format,var_type[i], var_rank[i], + index2, NCT_SCHAR); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_SCHAR); + } + err = nc_put_varm_schar(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + +#if defined(USE_PNETCDF) && PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR<7 + else if (cdf_format < NC_FORMAT_CDF5) { +#else + else { +#endif + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_schar(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_varm_short(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + short value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_varm_short(BAD_ID, 0, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_varm_short(ncid, BAD_VARID, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_varm_short(BAD_ID, i, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_SHORT == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_varm_short(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_varm_short(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_varm_short(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned when nothing to put, i.e. edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]&& j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_varm_short(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_varm_short(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / (size_t)stride[j]; + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_short(cdf_format,var_type[i], var_rank[i], + index2, NCT_SHORT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_SHORT); + } + err = nc_put_varm_short(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_short(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_varm_int(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + int value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_varm_int(BAD_ID, 0, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_varm_int(ncid, BAD_VARID, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_varm_int(BAD_ID, i, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_INT == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_varm_int(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_varm_int(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_varm_int(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned when nothing to put, i.e. edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]&& j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_varm_int(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_varm_int(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / (size_t)stride[j]; + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_int(cdf_format,var_type[i], var_rank[i], + index2, NCT_INT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_INT); + } + err = nc_put_varm_int(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_int(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_varm_long(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + long value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_varm_long(BAD_ID, 0, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_varm_long(ncid, BAD_VARID, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_varm_long(BAD_ID, i, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONG == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_varm_long(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_varm_long(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_varm_long(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned when nothing to put, i.e. edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]&& j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_varm_long(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_varm_long(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / (size_t)stride[j]; + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_long(cdf_format,var_type[i], var_rank[i], + index2, NCT_LONG); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_LONG); + } + err = nc_put_varm_long(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_long(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_varm_float(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + float value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_varm_float(BAD_ID, 0, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_varm_float(ncid, BAD_VARID, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_varm_float(BAD_ID, i, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_FLOAT == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_varm_float(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_varm_float(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_varm_float(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned when nothing to put, i.e. edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]&& j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_varm_float(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_varm_float(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / (size_t)stride[j]; + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_float(cdf_format,var_type[i], var_rank[i], + index2, NCT_FLOAT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_FLOAT); + } + err = nc_put_varm_float(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_float(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_varm_double(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + double value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_varm_double(BAD_ID, 0, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_varm_double(ncid, BAD_VARID, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_varm_double(BAD_ID, i, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_DOUBLE == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_varm_double(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_varm_double(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_varm_double(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned when nothing to put, i.e. edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]&& j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_varm_double(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_varm_double(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / (size_t)stride[j]; + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_double(cdf_format,var_type[i], var_rank[i], + index2, NCT_DOUBLE); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_DOUBLE); + } + err = nc_put_varm_double(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_double(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_varm_ushort(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + ushort value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_varm_ushort(BAD_ID, 0, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_varm_ushort(ncid, BAD_VARID, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_varm_ushort(BAD_ID, i, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_USHORT == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_varm_ushort(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_varm_ushort(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_varm_ushort(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned when nothing to put, i.e. edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]&& j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_varm_ushort(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_varm_ushort(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / (size_t)stride[j]; + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_ushort(cdf_format,var_type[i], var_rank[i], + index2, NCT_USHORT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_USHORT); + } + err = nc_put_varm_ushort(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_ushort(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_varm_uint(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + uint value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_varm_uint(BAD_ID, 0, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_varm_uint(ncid, BAD_VARID, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_varm_uint(BAD_ID, i, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_UINT == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_varm_uint(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_varm_uint(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_varm_uint(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned when nothing to put, i.e. edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]&& j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_varm_uint(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_varm_uint(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / (size_t)stride[j]; + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_uint(cdf_format,var_type[i], var_rank[i], + index2, NCT_UINT); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_UINT); + } + err = nc_put_varm_uint(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_uint(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_varm_longlong(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + longlong value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_varm_longlong(BAD_ID, 0, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_varm_longlong(ncid, BAD_VARID, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_varm_longlong(BAD_ID, i, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_LONGLONG == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_varm_longlong(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_varm_longlong(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_varm_longlong(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned when nothing to put, i.e. edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]&& j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_varm_longlong(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_varm_longlong(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / (size_t)stride[j]; + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_longlong(cdf_format,var_type[i], var_rank[i], + index2, NCT_LONGLONG); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_LONGLONG); + } + err = nc_put_varm_longlong(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_longlong(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_varm_ulonglong(void) +{ + int i, k, d, err, nslabs, ncid, cdf_format, nok=0; + int canConvert; /* Both text or both numeric */ + int allInExtRange; /* all values within external range? */ + size_t j, m, nels; + size_t start[MAX_RANK], edge[MAX_RANK], index[MAX_RANK]; + size_t index2[MAX_RANK], mid[MAX_RANK], count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t nstarts; /* number of different starts */ + ptrdiff_t stride[MAX_RANK], imap[MAX_RANK]; + ulonglong value[MAX_NELS]; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + mid[j] = 0; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_varm_ulonglong(BAD_ID, 0, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_varm_ulonglong(ncid, BAD_VARID, NULL, NULL, NULL, NULL, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_varm_ulonglong(BAD_ID, i, NULL, NULL, NULL, NULL, value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + canConvert = (var_type[i] == NC_CHAR) == (NCT_ULONGLONG == NCT_TEXT); + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_varm_ulonglong(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_varm_ulonglong(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_put_varm_ulonglong(ncid, i, start, edge, stride, imap, value); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned when nothing to put, i.e. edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i]&& j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_varm_ulonglong(ncid, i, start, edge, stride, imap, value); + if (!canConvert) { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + continue; + } + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_varm_ulonglong(ncid, i, start, edge, stride, imap, value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* Put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + } else { + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / (size_t)stride[j]; + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } +*/ + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = 1; + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)count[jj]; + } + for (allInExtRange = 1, j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value[j] = hash_ulonglong(cdf_format,var_type[i], var_rank[i], + index2, NCT_ULONGLONG); + + allInExtRange &= inRange3(cdf_format, (double)value[j], + var_type[i], NCT_ULONGLONG); + } + err = nc_put_varm_ulonglong(ncid,i,index,count,stride,imap,value); + if (canConvert) { + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } else { + IF (err != NC_ECHAR) + error("expecting NC_ECHAR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + nok += check_vars_ulonglong(scratch, numVars); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + + + +int +test_nc_put_att_text(void) +{ + int i, j, err, ncid, nok=0; + double dtmp; + size_t k, ndx[1]; + text value[MAX_NELS]; + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + def_dims(ncid); + def_vars(ncid); + + /* check if can detect a bad file ID */ + err = nc_put_att_text(BAD_ID, 0, NULL, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_att_text(ncid, BAD_VARID, NULL, 0, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + { + const char *const tval = "value for bad name"; + const size_t tval_len = (size_t)strlen(tval); + + err = nc_put_att_text(ncid, 0, "", tval_len, tval); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK + } + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + if (ATT_TYPE(i,j) == NC_CHAR) { + assert(ATT_LEN(i,j) <= MAX_NELS); + + err = nc_put_att_text(ncid, BAD_VARID, ATT_NAME(i,j), ATT_LEN(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + dtmp = hash(ATT_TYPE(i,j), -1, ndx); + value[k] = (text)dtmp; + } + err = nc_put_att_text(ncid, i, ATT_NAME(i,j), ATT_LEN(i,j), value); + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + nok += check_atts_text(ncid, numGatts, numVars); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + + + +int +test_nc_put_att_uchar(void) +{ + int i, j, err, ncid, cdf_format, nok=0; + int allInExtRange; /* all values within external range? */ + size_t k, ndx[1]; + uchar value[MAX_NELS]; + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + /* check if can detect a bad file ID */ + err = nc_put_att_uchar(BAD_ID, 0, NULL, 0, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_att_uchar(ncid, BAD_VARID, NULL, 0, 0, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + if (!(ATT_TYPE(i,j) == NC_CHAR)) { + assert(ATT_LEN(i,j) <= MAX_NELS); + + err = nc_put_att_uchar(ncid, BAD_VARID, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad name */ + err = nc_put_att_uchar(ncid, i, NULL, 0, 0, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_put_att_uchar(ncid, i, ATT_NAME(i,j), BAD_TYPE, ATT_LEN(i,j), value); + IF (err != NC_EBADTYPE) + error("expecting NC_EBADTYPE but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (allInExtRange = 1, k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + value[k] = hash_uchar(cdf_format,ATT_TYPE(i,j), -1, ndx, NCT_UCHAR); + + allInExtRange &= inRange3(cdf_format, (double)value[k], ATT_TYPE(i,j), NCT_UCHAR); + } + err = nc_put_att_uchar(ncid, i, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + +#if !defined(USE_PNETCDF) || (PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR>=8) + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } +#endif + + } + } + } + + nok += check_atts_uchar(ncid, numGatts, numVars); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_att_schar(void) +{ + int i, j, err, ncid, cdf_format, nok=0; + int allInExtRange; /* all values within external range? */ + size_t k, ndx[1]; + schar value[MAX_NELS]; + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + /* check if can detect a bad file ID */ + err = nc_put_att_schar(BAD_ID, 0, NULL, 0, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_att_schar(ncid, BAD_VARID, NULL, 0, 0, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + if (!(ATT_TYPE(i,j) == NC_CHAR)) { + assert(ATT_LEN(i,j) <= MAX_NELS); + + err = nc_put_att_schar(ncid, BAD_VARID, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad name */ + err = nc_put_att_schar(ncid, i, NULL, 0, 0, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_put_att_schar(ncid, i, ATT_NAME(i,j), BAD_TYPE, ATT_LEN(i,j), value); + IF (err != NC_EBADTYPE) + error("expecting NC_EBADTYPE but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (allInExtRange = 1, k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + value[k] = hash_schar(cdf_format,ATT_TYPE(i,j), -1, ndx, NCT_SCHAR); + + allInExtRange &= inRange3(cdf_format, (double)value[k], ATT_TYPE(i,j), NCT_SCHAR); + } + err = nc_put_att_schar(ncid, i, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + +#if defined(USE_PNETCDF) && PNETCDF_VERSION_MAJOR==1 && PNETCDF_VERSION_MINOR<7 + else if (cdf_format < NC_FORMAT_CDF5) { +#else + else { +#endif + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } + } + } + + nok += check_atts_schar(ncid, numGatts, numVars); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_att_short(void) +{ + int i, j, err, ncid, cdf_format, nok=0; + int allInExtRange; /* all values within external range? */ + size_t k, ndx[1]; + short value[MAX_NELS]; + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + /* check if can detect a bad file ID */ + err = nc_put_att_short(BAD_ID, 0, NULL, 0, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_att_short(ncid, BAD_VARID, NULL, 0, 0, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + if (!(ATT_TYPE(i,j) == NC_CHAR)) { + assert(ATT_LEN(i,j) <= MAX_NELS); + + err = nc_put_att_short(ncid, BAD_VARID, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad name */ + err = nc_put_att_short(ncid, i, NULL, 0, 0, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_put_att_short(ncid, i, ATT_NAME(i,j), BAD_TYPE, ATT_LEN(i,j), value); + IF (err != NC_EBADTYPE) + error("expecting NC_EBADTYPE but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (allInExtRange = 1, k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + value[k] = hash_short(cdf_format,ATT_TYPE(i,j), -1, ndx, NCT_SHORT); + + allInExtRange &= inRange3(cdf_format, (double)value[k], ATT_TYPE(i,j), NCT_SHORT); + } + err = nc_put_att_short(ncid, i, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } + } + } + + nok += check_atts_short(ncid, numGatts, numVars); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_att_int(void) +{ + int i, j, err, ncid, cdf_format, nok=0; + int allInExtRange; /* all values within external range? */ + size_t k, ndx[1]; + int value[MAX_NELS]; + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + /* check if can detect a bad file ID */ + err = nc_put_att_int(BAD_ID, 0, NULL, 0, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_att_int(ncid, BAD_VARID, NULL, 0, 0, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + if (!(ATT_TYPE(i,j) == NC_CHAR)) { + assert(ATT_LEN(i,j) <= MAX_NELS); + + err = nc_put_att_int(ncid, BAD_VARID, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad name */ + err = nc_put_att_int(ncid, i, NULL, 0, 0, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_put_att_int(ncid, i, ATT_NAME(i,j), BAD_TYPE, ATT_LEN(i,j), value); + IF (err != NC_EBADTYPE) + error("expecting NC_EBADTYPE but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (allInExtRange = 1, k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + value[k] = hash_int(cdf_format,ATT_TYPE(i,j), -1, ndx, NCT_INT); + + allInExtRange &= inRange3(cdf_format, (double)value[k], ATT_TYPE(i,j), NCT_INT); + } + err = nc_put_att_int(ncid, i, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } + } + } + + nok += check_atts_int(ncid, numGatts, numVars); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_att_long(void) +{ + int i, j, err, ncid, cdf_format, nok=0; + int allInExtRange; /* all values within external range? */ + size_t k, ndx[1]; + long value[MAX_NELS]; + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + /* check if can detect a bad file ID */ + err = nc_put_att_long(BAD_ID, 0, NULL, 0, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_att_long(ncid, BAD_VARID, NULL, 0, 0, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + if (!(ATT_TYPE(i,j) == NC_CHAR)) { + assert(ATT_LEN(i,j) <= MAX_NELS); + + err = nc_put_att_long(ncid, BAD_VARID, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad name */ + err = nc_put_att_long(ncid, i, NULL, 0, 0, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_put_att_long(ncid, i, ATT_NAME(i,j), BAD_TYPE, ATT_LEN(i,j), value); + IF (err != NC_EBADTYPE) + error("expecting NC_EBADTYPE but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (allInExtRange = 1, k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + value[k] = hash_long(cdf_format,ATT_TYPE(i,j), -1, ndx, NCT_LONG); + + allInExtRange &= inRange3(cdf_format, (double)value[k], ATT_TYPE(i,j), NCT_LONG); + } + err = nc_put_att_long(ncid, i, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } + } + } + + nok += check_atts_long(ncid, numGatts, numVars); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_att_float(void) +{ + int i, j, err, ncid, cdf_format, nok=0; + int allInExtRange; /* all values within external range? */ + size_t k, ndx[1]; + float value[MAX_NELS]; + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + /* check if can detect a bad file ID */ + err = nc_put_att_float(BAD_ID, 0, NULL, 0, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_att_float(ncid, BAD_VARID, NULL, 0, 0, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + if (!(ATT_TYPE(i,j) == NC_CHAR)) { + assert(ATT_LEN(i,j) <= MAX_NELS); + + err = nc_put_att_float(ncid, BAD_VARID, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad name */ + err = nc_put_att_float(ncid, i, NULL, 0, 0, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_put_att_float(ncid, i, ATT_NAME(i,j), BAD_TYPE, ATT_LEN(i,j), value); + IF (err != NC_EBADTYPE) + error("expecting NC_EBADTYPE but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (allInExtRange = 1, k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + value[k] = hash_float(cdf_format,ATT_TYPE(i,j), -1, ndx, NCT_FLOAT); + + allInExtRange &= inRange3(cdf_format, (double)value[k], ATT_TYPE(i,j), NCT_FLOAT); + } + err = nc_put_att_float(ncid, i, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } + } + } + + nok += check_atts_float(ncid, numGatts, numVars); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_att_double(void) +{ + int i, j, err, ncid, cdf_format, nok=0; + int allInExtRange; /* all values within external range? */ + size_t k, ndx[1]; + double value[MAX_NELS]; + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + /* check if can detect a bad file ID */ + err = nc_put_att_double(BAD_ID, 0, NULL, 0, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_att_double(ncid, BAD_VARID, NULL, 0, 0, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + if (!(ATT_TYPE(i,j) == NC_CHAR)) { + assert(ATT_LEN(i,j) <= MAX_NELS); + + err = nc_put_att_double(ncid, BAD_VARID, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad name */ + err = nc_put_att_double(ncid, i, NULL, 0, 0, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_put_att_double(ncid, i, ATT_NAME(i,j), BAD_TYPE, ATT_LEN(i,j), value); + IF (err != NC_EBADTYPE) + error("expecting NC_EBADTYPE but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (allInExtRange = 1, k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + value[k] = hash_double(cdf_format,ATT_TYPE(i,j), -1, ndx, NCT_DOUBLE); + + allInExtRange &= inRange3(cdf_format, (double)value[k], ATT_TYPE(i,j), NCT_DOUBLE); + } + err = nc_put_att_double(ncid, i, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } + } + } + + nok += check_atts_double(ncid, numGatts, numVars); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_att_ushort(void) +{ + int i, j, err, ncid, cdf_format, nok=0; + int allInExtRange; /* all values within external range? */ + size_t k, ndx[1]; + ushort value[MAX_NELS]; + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + /* check if can detect a bad file ID */ + err = nc_put_att_ushort(BAD_ID, 0, NULL, 0, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_att_ushort(ncid, BAD_VARID, NULL, 0, 0, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + if (!(ATT_TYPE(i,j) == NC_CHAR)) { + assert(ATT_LEN(i,j) <= MAX_NELS); + + err = nc_put_att_ushort(ncid, BAD_VARID, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad name */ + err = nc_put_att_ushort(ncid, i, NULL, 0, 0, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_put_att_ushort(ncid, i, ATT_NAME(i,j), BAD_TYPE, ATT_LEN(i,j), value); + IF (err != NC_EBADTYPE) + error("expecting NC_EBADTYPE but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (allInExtRange = 1, k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + value[k] = hash_ushort(cdf_format,ATT_TYPE(i,j), -1, ndx, NCT_USHORT); + + allInExtRange &= inRange3(cdf_format, (double)value[k], ATT_TYPE(i,j), NCT_USHORT); + } + err = nc_put_att_ushort(ncid, i, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } + } + } + + nok += check_atts_ushort(ncid, numGatts, numVars); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_att_uint(void) +{ + int i, j, err, ncid, cdf_format, nok=0; + int allInExtRange; /* all values within external range? */ + size_t k, ndx[1]; + uint value[MAX_NELS]; + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + /* check if can detect a bad file ID */ + err = nc_put_att_uint(BAD_ID, 0, NULL, 0, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_att_uint(ncid, BAD_VARID, NULL, 0, 0, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + if (!(ATT_TYPE(i,j) == NC_CHAR)) { + assert(ATT_LEN(i,j) <= MAX_NELS); + + err = nc_put_att_uint(ncid, BAD_VARID, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad name */ + err = nc_put_att_uint(ncid, i, NULL, 0, 0, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_put_att_uint(ncid, i, ATT_NAME(i,j), BAD_TYPE, ATT_LEN(i,j), value); + IF (err != NC_EBADTYPE) + error("expecting NC_EBADTYPE but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (allInExtRange = 1, k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + value[k] = hash_uint(cdf_format,ATT_TYPE(i,j), -1, ndx, NCT_UINT); + + allInExtRange &= inRange3(cdf_format, (double)value[k], ATT_TYPE(i,j), NCT_UINT); + } + err = nc_put_att_uint(ncid, i, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } + } + } + + nok += check_atts_uint(ncid, numGatts, numVars); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_att_longlong(void) +{ + int i, j, err, ncid, cdf_format, nok=0; + int allInExtRange; /* all values within external range? */ + size_t k, ndx[1]; + longlong value[MAX_NELS]; + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + /* check if can detect a bad file ID */ + err = nc_put_att_longlong(BAD_ID, 0, NULL, 0, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_att_longlong(ncid, BAD_VARID, NULL, 0, 0, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + if (!(ATT_TYPE(i,j) == NC_CHAR)) { + assert(ATT_LEN(i,j) <= MAX_NELS); + + err = nc_put_att_longlong(ncid, BAD_VARID, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad name */ + err = nc_put_att_longlong(ncid, i, NULL, 0, 0, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_put_att_longlong(ncid, i, ATT_NAME(i,j), BAD_TYPE, ATT_LEN(i,j), value); + IF (err != NC_EBADTYPE) + error("expecting NC_EBADTYPE but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (allInExtRange = 1, k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + value[k] = hash_longlong(cdf_format,ATT_TYPE(i,j), -1, ndx, NCT_LONGLONG); + + allInExtRange &= inRange3(cdf_format, (double)value[k], ATT_TYPE(i,j), NCT_LONGLONG); + } + err = nc_put_att_longlong(ncid, i, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } + } + } + + nok += check_atts_longlong(ncid, numGatts, numVars); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + +int +test_nc_put_att_ulonglong(void) +{ + int i, j, err, ncid, cdf_format, nok=0; + int allInExtRange; /* all values within external range? */ + size_t k, ndx[1]; + ulonglong value[MAX_NELS]; + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + err = nc_inq_format(ncid, &cdf_format); + IF (err != NC_NOERR) + error("inq_format: %s", nc_strerror(err)); + + def_dims(ncid); + def_vars(ncid); + + /* check if can detect a bad file ID */ + err = nc_put_att_ulonglong(BAD_ID, 0, NULL, 0, 0, NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_att_ulonglong(ncid, BAD_VARID, NULL, 0, 0, NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + if (!(ATT_TYPE(i,j) == NC_CHAR)) { + assert(ATT_LEN(i,j) <= MAX_NELS); + + err = nc_put_att_ulonglong(ncid, BAD_VARID, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad name */ + err = nc_put_att_ulonglong(ncid, i, NULL, 0, 0, NULL); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s",nc_err_code_name(err)); + ELSE_NOK + + err = nc_put_att_ulonglong(ncid, i, ATT_NAME(i,j), BAD_TYPE, ATT_LEN(i,j), value); + IF (err != NC_EBADTYPE) + error("expecting NC_EBADTYPE but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (allInExtRange = 1, k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + value[k] = hash_ulonglong(cdf_format,ATT_TYPE(i,j), -1, ndx, NCT_ULONGLONG); + + allInExtRange &= inRange3(cdf_format, (double)value[k], ATT_TYPE(i,j), NCT_ULONGLONG); + } + err = nc_put_att_ulonglong(ncid, i, ATT_NAME(i,j), ATT_TYPE(i,j), ATT_LEN(i,j), value); + if (allInExtRange) { + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + else { + + IF (err != NC_ERANGE) + error("expecting NC_ERANGE but got %s",nc_err_code_name(err)); + ELSE_NOK + } + + + } + } + } + + nok += check_atts_ulonglong(ncid, numGatts, numVars); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("delete file %s failed", scratch); + return nok; +} + diff --git a/nc_test/test_read.c b/nc_test/test_read.c new file mode 100644 index 0000000000..ae1c1b60fe --- /dev/null +++ b/nc_test/test_read.c @@ -0,0 +1,1970 @@ +/* Do not edit this file. It is produced from the corresponding .m4 source */ +/* + * Copyright (C) 2003, Northwestern University and Argonne National Laboratory + * See COPYRIGHT notice in top-level directory. + */ +/* $Id: test_read.m4 2861 2017-02-09 19:38:02Z wkliao $ */ + + +#if defined (_WIN32) || defined (_WIN64) +#include +#endif + +#include /* open() */ +#include /* open() */ +#include /* open() */ +#ifdef _MSC_VER +#include +#else +#include /* unlink(), write() */ +#endif +#include /* errno, strerror() */ + +#include "tests.h" + + + + + + +/* + * Test nc_strerror. + * Try on a bad error status. + * Test for each defined error status. + */ +int +test_nc_strerror(void) +{ + int i; + const char *message, *expected_msg; + int nok=0; + + static const struct { + int status; + const char *msg; + } ncerrs[] = { + {NC_NOERR, "No error"}, + {NC_EBADID, "NetCDF: Not a valid ID"}, + {NC_ENFILE, "NetCDF: Too many files open"}, + {NC_EEXIST, "NetCDF: File exists && NC_NOCLOBBER"}, + {NC_EINVAL, "NetCDF: Invalid argument"}, + {NC_EPERM, "NetCDF: Write to read only"}, + {NC_ENOTINDEFINE, "NetCDF: Operation not allowed in data mode"}, + {NC_EINDEFINE, "NetCDF: Operation not allowed in define mode"}, + {NC_EINVALCOORDS, "NetCDF: Index exceeds dimension bound"}, + {NC_EMAXDIMS, "NetCDF: NC_MAX_DIMS exceeded"}, /* not enforced after 4.5.0 */ + {NC_ENAMEINUSE, "NetCDF: String match to name in use"}, + {NC_ENOTATT, "NetCDF: Attribute not found"}, + {NC_EMAXATTS, "NetCDF: NC_MAX_ATTRS exceeded"}, /* not enforced after 4.5.0 */ + {NC_EBADTYPE, "NetCDF: Not a valid data type or _FillValue type mismatch"}, + {NC_EBADDIM, "NetCDF: Invalid dimension ID or name"}, + {NC_EUNLIMPOS, "NetCDF: NC_UNLIMITED in the wrong index"}, + {NC_EMAXVARS, "NetCDF: NC_MAX_VARS exceeded"}, /* not enforced after 4.5.0 */ + {NC_ENOTVAR, "NetCDF: Variable not found"}, + {NC_EGLOBAL, "NetCDF: Action prohibited on NC_GLOBAL varid"}, + {NC_ENOTNC, "NetCDF: Unknown file format"}, + {NC_ESTS, "NetCDF: In Fortran, string too short"}, + {NC_EMAXNAME, "NetCDF: NC_MAX_NAME exceeded"}, + {NC_EUNLIMIT, "NetCDF: NC_UNLIMITED size already in use"}, + {NC_ENORECVARS, "NetCDF: nc_rec op when there are no record vars"}, + {NC_ECHAR, "NetCDF: Attempt to convert between text & numbers"}, + {NC_EEDGE, "NetCDF: Start+count exceeds dimension bound"}, + {NC_ESTRIDE, "NetCDF: Illegal stride"}, + {NC_EBADNAME, "NetCDF: Name contains illegal characters"}, + {NC_ERANGE, "NetCDF: Numeric conversion not representable"}, + {NC_ENOMEM, "NetCDF: Memory allocation (malloc) failure"}, + {NC_EVARSIZE, "NetCDF: One or more variable sizes violate format constraints"}, + {NC_EDIMSIZE, "NetCDF: Invalid dimension size"} + }; + + /* Try on a bad error status */ + message = nc_strerror(-666);/* should fail */ + expected_msg = "Unknown Error"; + IF (strncmp(message, expected_msg, strlen(expected_msg)) != 0) + error(" nc_strerror on bad error status returned: %s", message); + ELSE_NOK + + /* Try on each legitimate error status */ + for (i=0; i= 0); + close(fd); + } + + /* Open a file that is not a netCDF file. */ + err = file_open(NOT_NC_FILE, NC_NOWRITE, &ncid); /* should fail */ + IF (err != NC_ENOTNC) + error("expecting NC_ENOTNC or NC_EFILE but got %s", nc_err_code_name(err)); + ELSE_NOK + + /* delete the not-nc file */ + unlink(NOT_NC_FILE); +#endif + + /* Open a netCDF file in read-only mode, check that write fails */ + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + ELSE_NOK + err = nc_redef(ncid); /* should fail */ + IF (err != NC_EPERM) + error("expecting NC_EPERM but got %s", nc_err_code_name(err)); + /* Opened OK, see if can open again and get a different netCDF ID */ + err = file_open(testfile, NC_NOWRITE, &ncid2); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + else { + nc_close(ncid2); + nok++; + } + IF (ncid2 == ncid) + error("netCDF IDs for first and second open calls should differ"); + + + { /* tests using netCDF scratch file */ + err = file_create(scratch, NC_NOCLOBBER, &ncid2); + IF (err != NC_NOERR) + error("create: %s", nc_strerror(err)); + else + nc_close(ncid2); + err = file_open(scratch, NC_WRITE, &ncid2); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + else { + nc_close(ncid2); + nok++; + } + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +/* + * Test nc_close. + * Try to close a netCDF file twice, check whether second close fails. + * Try on bad handle, check error return. + * Try in define mode and data mode. + */ +int +test_nc_close(void) +{ + int ncid, nok=0; + int err = file_open(testfile, NC_NOWRITE, &ncid); + + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + + /* Close a netCDF file twice, second time should fail */ + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close failed: %s", nc_strerror(err)); + ELSE_NOK + err = nc_close(ncid); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + + /* Try with a bad netCDF ID */ + err = nc_close(BAD_ID);/* should fail */ + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + + /* Close in data mode */ + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close in data mode failed: %s", nc_strerror(err)); + ELSE_NOK + + + { /* tests using netCDF scratch file */ + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) + error("create: %s", nc_strerror(err)); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close in define mode: %s", nc_strerror(err)); + ELSE_NOK + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + } + return nok; +} + + +/* + * Test nc_inq + * Try on bad handle, check error return. + * Try in data mode, check returned values. + * Try asking for subsets of info. + * If in writable section of tests, + * Try in define mode, after adding an unlimited dimension, variable. + * On exit, any open netCDF files are closed. + */ +int +test_nc_inq(void) +{ + int ncid; + int ndims; /* number of dimensions */ + int nvars; /* number of variables */ + int ngatts; /* number of global attributes */ + int recdim; /* id of unlimited dimension */ + int err; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + + /* Try on bad handle */ + err = nc_inq(BAD_ID, 0, 0, 0, 0); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + + err = nc_inq(ncid, &ndims, &nvars, &ngatts, &recdim); + IF (err != NC_NOERR) + error("inq: %s", nc_strerror(err)); + else IF (ndims != NDIMS) + error("inq: wrong number of dimensions returned, %d", ndims); + else IF (nvars != numVars) + error("inq: wrong number of variables returned, %d", nvars); + else IF (ngatts != numGatts) + error("inq: wrong number of global atts returned, %d", ngatts); + else IF (recdim != RECDIM) + error("inq: wrong record dimension ID returned, %d", recdim); + ELSE_NOK + + /* Inguire for no info (useless, but should still work) */ + err = nc_inq(ncid, 0, 0, 0, 0); + IF (err != NC_NOERR) + error("inq for no info failed: %s", nc_strerror(err)); + ELSE_NOK + + /* Inguire for subsets of info */ + ngatts = numGatts - 1; /* wipe out previous correct value */ + err = nc_inq(ncid, 0, 0, &ngatts, 0); + IF (err != NC_NOERR) + error("inq for one item failed: %s", nc_strerror(err)); + else IF (ngatts != numGatts) + error("inq subset: wrong number of global atts returned, %d", ngatts); + ELSE_NOK + ndims = NDIMS - 1; + nvars = numVars - 1; + err = nc_inq(ncid, &ndims, &nvars, 0, 0); + IF (err != NC_NOERR) + error("inq for two items failed: %s", nc_strerror(err)); + else IF (ndims != NDIMS) + error("inq subset: wrong number of dimensions returned, %d", ndims); + else IF (nvars != numVars) + error("inq subset: wrong number of variables returned, %d", nvars); + ELSE_NOK + + + { /* tests using netCDF scratch file */ + int ncid2; /* for scratch netCDF dataset */ + + err = file_create(scratch, NC_NOCLOBBER, &ncid2); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + } else { /* add dim, var, gatt, check inq */ + int ndims0; + int nvars0; + int ngatts0; + int recdim0; + err = nc_enddef(ncid2); /* enter data mode */ + err = nc_inq(ncid2, &ndims0, &nvars0, &ngatts0, &recdim0); + IF (err != NC_NOERR) + error("inq: %s", nc_strerror(err)); + ELSE_NOK + err = nc_redef(ncid2); /* enter define mode */ + /* Check that inquire still works in define mode */ + err = nc_inq(ncid2, &ndims, &nvars, &ngatts, &recdim); + IF (err != NC_NOERR) + error("inq in define mode: %s", nc_strerror(err)); + else IF (ndims != ndims0) + error("inq in define mode: ndims wrong, %d", ndims); + else IF (nvars != nvars0) + error("inq in define mode: nvars wrong, %d", nvars); + else IF (ngatts != ngatts0) + error("inq in define mode: ngatts wrong, %d", ngatts); + else IF (recdim != recdim0) + error("inq in define mode: recdim wrong, %d", recdim); + ELSE_NOK + + { + int did, vid; + /* Add dim, var, global att */ + err = nc_def_dim(ncid2, "inqd", 1L, &did); + IF (err != NC_NOERR) + error("def_dim: %s", nc_strerror(err)); + err = nc_def_var(ncid2, "inqv", NC_FLOAT, 0, 0, &vid); + IF (err != NC_NOERR) + error("def_var: %s", nc_strerror(err)); + } + err = nc_put_att_text(ncid2, NC_GLOBAL, "inqa", 1+strlen("stuff"), + "stuff"); + IF (err != NC_NOERR) + error("put_att_text: %s", nc_strerror(err)); + + /* Make sure nc_inq sees the additions while in define mode */ + err = nc_inq(ncid2, &ndims, &nvars, &ngatts, &recdim); + IF (err != NC_NOERR) + error("inq in define mode: %s", nc_strerror(err)); + else IF (ndims != ndims0 + 1) + error("inq in define mode: ndims wrong, %d", ndims); + else IF (nvars != nvars0 + 1) + error("inq in define mode: nvars wrong, %d", nvars); + else IF (ngatts != ngatts0 + 1) + error("inq in define mode: ngatts wrong, %d", ngatts); + ELSE_NOK + err = nc_enddef(ncid2); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* Make sure nc_inq stills sees additions in data mode */ + err = nc_inq(ncid2, &ndims, &nvars, &ngatts, &recdim); + IF (err != NC_NOERR) + error("inq failed in data mode: %s", nc_strerror(err)); + else IF (ndims != ndims0 + 1) + error("inq in define mode: ndims wrong, %d", ndims); + else IF (nvars != nvars0 + 1) + error("inq in define mode: nvars wrong, %d", nvars); + else IF (ngatts != ngatts0 + 1) + error("inq in define mode: ngatts wrong, %d", ngatts); + ELSE_NOK + nc_close(ncid2); + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_natts(void) +{ + int ncid; + int ngatts; /* number of global attributes */ + int err, nok=0; + + err = nc_inq_natts(BAD_ID, &ngatts); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + err = nc_inq_natts(ncid, &ngatts); + IF (err != NC_NOERR) + error("inq_natts: %s", nc_strerror(err)); + else IF (ngatts != numGatts) + error("inq_natts: wrong number of global atts returned, %d", ngatts); + ELSE_NOK + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_ndims(void) +{ + int ncid; + int ndims; + int err; + int nok=0; + + err = nc_inq_ndims(BAD_ID, &ndims); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + err = nc_inq_ndims(ncid, &ndims); + IF (err != NC_NOERR) + error("inq_ndims: %s", nc_strerror(err)); + else IF (ndims != NDIMS) + error("inq_ndims: wrong number returned, %d", ndims); + ELSE_NOK + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_nvars(void) +{ + int ncid; + int nvars; + int err; + int nok=0; + + err = nc_inq_nvars(BAD_ID, &nvars); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + err = nc_inq_nvars(ncid, &nvars); + IF (err != NC_NOERR) + error("inq_nvars: %s", nc_strerror(err)); + else IF (nvars != numVars) + error("inq_nvars: wrong number returned, %d", nvars); + ELSE_NOK + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_unlimdim(void) +{ + int ncid; + int unlimdim; + int err; + int nok=0; + + err = nc_inq_unlimdim(BAD_ID, &unlimdim); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + err = nc_inq_unlimdim(ncid, &unlimdim); + IF (err != NC_NOERR) + error("inq_unlimdim: %s", nc_strerror(err)); + else IF (unlimdim != RECDIM) + error("inq_unlimdim: wrong number returned, %d", unlimdim); + ELSE_NOK + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_dimid(void) +{ + int ncid; + int dimid; + int i; + int err; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + err = nc_inq_dimid(ncid, "noSuch", &dimid); + IF (err != NC_EBADDIM) + error("expecting NC_EBADDIM but got %s", nc_err_code_name(err)); + ELSE_NOK + for (i = 0; i < NDIMS; i++) { + err = nc_inq_dimid(BAD_ID, dim_name[i], &dimid); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_dimid(ncid, dim_name[i], &dimid); + IF (err != NC_NOERR) + error("inq_dimid: %s", nc_strerror(err)); + else IF (dimid != i) + error("expected %d, got %d", i, dimid); + ELSE_NOK + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_dim(void) +{ + int ncid; + int i; + int err; + char name[NC_MAX_NAME]; + size_t length; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + for (i = 0; i < NDIMS; i++) { + err = nc_inq_dim(BAD_ID, i, name, &length); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_dim(ncid, BAD_DIMID, name, &length); + IF (err != NC_EBADDIM) + error("expecting NC_EBADDIM but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_dim(ncid, i, 0, 0); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + ELSE_NOK + err = nc_inq_dim(ncid, i, name, &length); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + else IF (strcmp(dim_name[i],name)) + error("name expected: %s, got: %s",dim_name[i],name); + else IF (dim_len[i] != length) + error("size expected: %d, got: %d",dim_len[i],length); + ELSE_NOK + err = nc_inq_dim(ncid, i, name, 0); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + else IF (strcmp(dim_name[i],name)) + error("name expected: %s, got: %s",dim_name[i],name); + ELSE_NOK + err = nc_inq_dim(ncid, i, 0, &length); + IF (err != NC_NOERR) + error("inq_dim: %s", nc_strerror(err)); + else IF (dim_len[i] != length) + error("size expected: %d, got: %d",dim_len[i],length); + ELSE_NOK + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_dimlen(void) +{ + int ncid; + int i; + int err; + size_t length; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + for (i = 0; i < NDIMS; i++) { + err = nc_inq_dimlen(BAD_ID, i, &length); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_dimlen(ncid, BAD_DIMID, &length); + IF (err != NC_EBADDIM) + error("expecting NC_EBADDIM but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_dimlen(ncid, i, &length); + IF (err != NC_NOERR) + error("inq_dimlen: %s", nc_strerror(err)); + else IF (dim_len[i] != length) + error("size expected: %d, got: %d",dim_len[i],length); + ELSE_NOK + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_dimname(void) +{ + int ncid; + int i; + int err; + char name[NC_MAX_NAME]; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + for (i = 0; i < NDIMS; i++) { + err = nc_inq_dimname(BAD_ID, i, name); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_dimname(ncid, BAD_DIMID, name); + IF (err != NC_EBADDIM) + error("expecting NC_EBADDIM but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_dimname(ncid, i, name); + IF (err != NC_NOERR) + error("inq_dimname: %s", nc_strerror(err)); + else IF (strcmp(dim_name[i],name)) + error("name expected: %s, got: %s",dim_name[i],name); + ELSE_NOK + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_varid(void) +{ + int ncid; + int varid; + int i; + int err; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + + err = nc_inq_varid(ncid, "noSuch", &varid); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + err = nc_inq_varid(BAD_ID, var_name[i], &varid); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_varid(ncid, var_name[i], &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + else IF (varid != i) + error("expected %d, got %d", i, varid); + ELSE_NOK + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_var(void) +{ + int ncid; + int i; + int err; + char name[NC_MAX_NAME]; + nc_type datatype; + int ndims; + int dimids[MAX_RANK]; + int natts; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + for (i = 0; i < numVars; i++) { + err = nc_inq_var(BAD_ID, i, name, &datatype, &ndims, dimids, &natts); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_var(ncid,BAD_VARID,name,&datatype,&ndims,dimids,&natts); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_var(ncid, i, 0, 0, 0, 0, 0); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + ELSE_NOK + err = nc_inq_var(ncid, i, name, &datatype, &ndims, dimids, &natts); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + else IF (strcmp(var_name[i],name)) + error("name expected: %s, got: %s",var_name[i],name); + else IF (var_type[i] != datatype) + error("type expected: %d, got: %d",var_type[i],datatype); + else IF (var_rank[i] != ndims) + error("ndims expected: %d, got: %d",var_rank[i],ndims); + else IF (!int_vec_eq(var_dimid[i],dimids,ndims)) + error("unexpected dimid"); + else IF (var_natts[i] != natts) + error("natts expected: %d, got: %d",var_natts[i],natts); + ELSE_NOK + err = nc_inq_var(ncid, i, name, 0, 0, 0, 0); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + else IF (strcmp(var_name[i],name)) + error("name expected: %s, got: %s",var_name[i],name); + ELSE_NOK + err = nc_inq_var(ncid, i, 0, &datatype, 0, 0, 0); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + else IF (var_type[i] != datatype) + error("type expected: %d, got: %d",var_type[i],datatype); + ELSE_NOK + err = nc_inq_var(ncid, i, 0, 0, &ndims, 0, 0); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + else IF (var_rank[i] != ndims) + error("ndims expected: %d, got: %d",var_rank[i],ndims); + ELSE_NOK + err = nc_inq_var(ncid, i, 0, 0, 0, dimids, 0); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + else IF (!int_vec_eq(var_dimid[i],dimids,ndims)) + error("unexpected dimid"); + ELSE_NOK + err = nc_inq_var(ncid, i, 0, 0, 0, 0, &natts); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + else IF (var_natts[i] != natts) + error("natts expected: %d, got: %d",var_natts[i],natts); + ELSE_NOK + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_vardimid(void) +{ + int ncid; + int i; + int err; + int dimids[MAX_RANK]; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + for (i = 0; i < numVars; i++) { + err = nc_inq_vardimid(BAD_ID, i, dimids); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_vardimid(ncid, BAD_VARID, dimids); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_vardimid(ncid, i, dimids); + IF (err != NC_NOERR) + error("inq_vardimid: %s", nc_strerror(err)); + else IF (!int_vec_eq(var_dimid[i], dimids, var_rank[i])) + error("unexpected dimid"); + ELSE_NOK + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_varname(void) +{ + int ncid; + int i; + int err; + char name[NC_MAX_NAME]; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + for (i = 0; i < numVars; i++) { + err = nc_inq_varname(BAD_ID, i, name); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + nok++; + err = nc_inq_varname(ncid, BAD_VARID, name); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_varname(ncid, i, name); + IF (err != NC_NOERR) + error("inq_varname: %s", nc_strerror(err)); + else IF (strcmp(var_name[i],name)) + error("name expected: %s, got: %s",var_name[i],name); + ELSE_NOK + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_varnatts(void) +{ + int ncid; + int i; + int err; + int natts; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + for (i = -1; i < numVars; i++) { + err = nc_inq_varnatts(BAD_ID, i, &natts); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_varnatts(ncid, BAD_VARID, &natts); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_varnatts(ncid, VARID(i), &natts); + IF (err != NC_NOERR) + error("inq_varnatts: %s", nc_strerror(err)); + else IF (NATTS(i) != natts) + error("natts expected: %d, got: %d",NATTS(i),natts); + ELSE_NOK + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_varndims(void) +{ + int ncid; + int i; + int err; + int ndims; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + for (i = 0; i < numVars; i++) { + err = nc_inq_varndims(BAD_ID, i, &ndims); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_varndims(ncid, BAD_VARID, &ndims); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_varndims(ncid, i, &ndims); + IF (err != NC_NOERR) + error("inq_varndims: %s", nc_strerror(err)); + else IF (var_rank[i] != ndims) + error("ndims expected: %d, got: %d",var_rank[i],ndims); + ELSE_NOK + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_vartype(void) +{ + int ncid; + int i; + int err; + nc_type datatype; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + for (i = 0; i < numVars; i++) { + err = nc_inq_vartype(BAD_ID, i, &datatype); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_vartype(ncid, BAD_VARID, &datatype); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_vartype(ncid, i, &datatype); + IF (err != NC_NOERR) + error("inq_vartype: %s", nc_strerror(err)); + else IF (var_type[i] != datatype) + error("type expected: %d, got: %d", var_type[i], datatype); + ELSE_NOK + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +/* + * Test nc_get_var1(,,,) + */ +int +test_nc_get_var1(void) +{ + int ncid = 0; + int i = 0; + int err = 0; + double expect = 0; + int nok = 0; /* count of valid comparisons */ + double buf[1] = {0}; /* (void *) buffer */ + double value[1] = {0}; + size_t j = 0, index[MAX_RANK] = {0}; + + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) error("open: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_var1(BAD_ID,0,NULL,NULL); + IF (err != NC_EBADID) error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + + /* check if can detect a bad variable ID */ + err = nc_get_var1(ncid,BAD_VARID,NULL,NULL); + IF (err != NC_ENOTVAR) error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_var1(BAD_ID,i,NULL,value); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] = var_shape[i][j]; + err = nc_get_var1(ncid,i,index,buf); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + err = nc_get_var1(ncid,i,index,value); + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if the contents are supposed to be */ + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect = hash( var_type[i], var_rank[i], index ); + err = nc_get_var1(ncid,i,index,buf); + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + err = nc2dbl( var_type[i], buf, &value[0]); + IF (err) + error("error in nc2dbl"); + if (inRange(expect,var_type[i])) { + IF (!equal2(value[0],expect,var_type[i])) + error("expected: %G, got: %G", expect, value[0]); + ELSE_NOK + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +/* + * Test nc_get_vara(,,,,) + * Choose a random point dividing each dim into 2 parts + * Get 2^rank (nslabs) slabs so defined + * Each get overwrites buffer, so check after each get. + */ +int +test_nc_get_vara(void) +{ + int ncid = 0, d = 0, i = 0, k = 0, err = 0, nslabs = 0; + int nok = 0; /* count of valid comparisons */ + size_t j = 0, nels = 0; + size_t start[MAX_RANK]= {0}; + size_t edge[MAX_RANK] = {0}; + size_t index[MAX_RANK] = {0}; + size_t mid[MAX_RANK] = {0}; + + double buf[MAX_NELS] = {0}; /* (void *) buffer */ + double expect = 0; + + for(j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 0; + index[j] = 0; + mid[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_vara(BAD_ID,0,NULL,NULL,NULL); + IF (err != NC_EBADID) error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + + /* check if can detect a bad variable ID */ + err = nc_get_vara(ncid,BAD_VARID,NULL,NULL,NULL); + IF (err != NC_ENOTVAR) error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vara(BAD_ID,i,NULL,NULL,buf); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* test NC_EINVALCOORDS, first when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] = var_shape[i][j]; + err = nc_get_vara(ncid,i,index,edge,buf); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + edge[j] = var_shape[i][j] + 1; /* edge error check */ + err = nc_get_vara(ncid,i,start,edge,buf); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + } + + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vara(ncid,i,start,edge,buf); + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_get_vara(ncid,i,start,edge,buf); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + err = nc_get_vara(ncid,i,start,edge,buf); + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + }else{ + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + err = nc_get_vara(ncid,i,start,edge,buf); + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (j = 0; j < nels; j++) { + double got; + char *p = (char *) buf; + p += j * (size_t)nctypelen(var_type[i]); + err = nc2dbl( var_type[i], p, & got ); + IF (err) error("error in nc2dbl"); + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index[d] += start[d]; + expect = hash(var_type[i], var_rank[i], index); + if (inRange(expect,var_type[i])) { + IF (!equal2(got,expect,var_type[i])) { + error("buf read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("element number: %d ", j); + error("expect: %g", expect); + error("got: %g", got); + } + } + } + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +/* + * Test nc_get_vars(,,,,,) + * Choose a random point dividing each dim into 2 parts + * Get 2^rank (nslabs) slabs so defined + * Each get overwrites buffer, so check after each get. + */ +int +test_nc_get_vars(void) +{ + int ncid; + int d; + int i; + int k; + int err; + int nslabs; + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* total count of valid comparisons */ + int n; /* count of valid comparisons within var */ + size_t j, m, nels; + size_t start[MAX_RANK]; + size_t edge[MAX_RANK]; + size_t index[MAX_RANK]; + size_t index2[MAX_RANK]; + size_t mid[MAX_RANK]; + size_t count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + + double buf[MAX_NELS]; /* (void *) buffer */ + char *p; /* (void *) pointer */ + double expect; + double got; + + for (j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + mid[j] = 1; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_vars(BAD_ID,0,NULL,NULL,NULL,NULL); + IF (err != NC_EBADID) error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + + /* check if can detect a bad variable ID */ + err = nc_get_vars(ncid,BAD_VARID,NULL,NULL,NULL,NULL); + IF (err != NC_ENOTVAR) error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_vars(BAD_ID,i,NULL,NULL,NULL,buf); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + mid[j] = 1; + index[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + } + + + /* test NC_EINVALCOORDS, first when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = var_shape[i][j]; + err = nc_get_vars(ncid,i,start,edge,stride,buf); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_vars(ncid,i,start,edge,stride,buf); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_get_vars(ncid,i,start,edge,stride,buf); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_vars(ncid,i,start,edge,stride,buf); + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_get_vars(ncid,i,start,edge,stride,buf); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + err = nc_get_vars(ncid,i,start,edge,stride,buf); + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + n = 0; + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + }else{ + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + err = nc_get_vars(ncid,i,index,count,stride,buf); + IF (err != NC_NOERR) + error("%s", nc_strerror(err)); + ELSE_NOK + + for (j = 0; j < nels; j++) { + p = (char *) buf; + p += j * (size_t)nctypelen(var_type[i]); + err = nc2dbl( var_type[i], p, & got ); + IF (err != NC_NOERR) + error("error in nc2dbl"); + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + expect = hash(var_type[i], var_rank[i], index2); + if (inRange(expect,var_type[i])) { + IF (!equal2(got,expect,var_type[i])) { + error("buf read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("element number: %d ", j); + error("expect: %g, ", expect); + error("got: %g ", got); + } + } + ELSE_NOK + } + n++; + } + } + } + IF (n != var_nels[i]) { + error("count != nels"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("count: %d, ", n); + error("nels: %d ", var_nels[i]); + } + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +/* + * Test nc_get_varm(,,,,,,) + * Choose a random point dividing each dim into 2 parts + * Get 2^rank (nslabs) slabs so defined + * Choose random stride from 1 to edge + * Buffer should end up being bit image of external variable. + * So all gets for a variable store in different elements of buffer + */ +int +test_nc_get_varm(void) +{ + int ncid; + int i; + int k; + int err; + int nslabs; + ptrdiff_t nstarts; /* number of different starts */ + int nok = 0; /* total count of valid comparisons */ + size_t j, m, nels; + size_t start[MAX_RANK]; + size_t edge[MAX_RANK]; + size_t index[MAX_RANK]; + size_t mid[MAX_RANK]; + size_t count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + ptrdiff_t imap[MAX_RANK]; + ptrdiff_t imap2[MAX_RANK]; + + double buf[MAX_NELS]; /* (void *) buffer */ + char *p; /* (void *) pointer */ + double expect; + double got; + + for (j = 0; j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + mid[j] = 1; + index[j] = 0; + count[j] = 0; + sstride[j] = 1; + imap[j] = 0; + imap2[j] = 0; + } + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_get_varm(BAD_ID,0,NULL,NULL,NULL,NULL,NULL); + IF (err != NC_EBADID) error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + + /* check if can detect a bad variable ID */ + err = nc_get_varm(ncid,BAD_VARID,NULL,NULL,NULL,NULL,NULL); + IF (err != NC_ENOTVAR) error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + /* check if can detect a bad file ID */ + err = nc_get_varm(BAD_ID,i,NULL,NULL,NULL,NULL,buf); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + } + + + /* test NC_EINVALCOORDS, first when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK ; j++) { + start[j] = var_shape[i][j]; + err = nc_get_varm(ncid,i,start,edge,stride,imap,buf); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_get_varm(ncid,i,start,edge,stride,imap,buf); + IF (err != NC_EEDGE) + error("expecting NC_EEDGE but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; + err = nc_get_varm(ncid,i,start,edge,stride,imap,buf); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check non-scalars for correct error returned even when there is + * nothing to get (edge[j]==0) */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_get_varm(ncid,i,start,edge,stride,imap,buf); + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_get_varm(ncid,i,start,edge,stride,imap,buf); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + err = nc_get_varm(ncid,i,start,edge,stride,imap,buf); + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + /* imap[jj] = nctypelen(var_type[i]); */ + imap[jj] = 1; /* in numbers of elements */ + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)var_shape[i][jj]; + } + + /* Choose a random point dividing each dim into 2 parts */ + /* get 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to get lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + }else{ + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + imap2[j] = imap[j] * stride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + if (var_rank[i] == 0 && i%2 ) { + err = nc_get_varm(ncid,i,NULL,NULL,NULL,NULL,buf); + } else { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + index[j] += start[j]; + nels *= count[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + j = fromMixedBase(var_rank[i], index, var_shape[i]); + p = (char *) buf + j * (size_t)nctypelen(var_type[i]); + err = nc_get_varm(ncid,i,index,count,stride,imap2,p); + } + IF (err != NC_NOERR) + error("%s", nc_strerror(err)); + ELSE_NOK + } + } + p = (char *) buf; + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + expect = hash( var_type[i], var_rank[i], index); + err = nc2dbl( var_type[i], p, & got ); + IF (err != NC_NOERR) + error("error in nc2dbl"); + if (inRange(expect,var_type[i])) { + IF (!equal2(got,expect,var_type[i])) { + error("buf read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", var_name[i]); + error("element number: %d ", j); + error("expect: %g, ", expect); + error("got: %g ", got); + } + } + ELSE_NOK + } + p += nctypelen(var_type[i]); + } + } + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_get_att(void) +{ + int ncid; + int i; + int j; + size_t k, ndx[1]; + int err; + double buf[MAX_NELS]; /* (void *) buffer */ + char *p; /* (void *) pointer */ + double expect; + double got; + int nok = 0; /* count of valid comparisons */ + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + err = nc_get_att(BAD_ID, i, ATT_NAME(i,j), buf); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_get_att(ncid, BAD_VARID, ATT_NAME(i,j), buf); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_get_att(ncid, i, "noSuch", buf); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_get_att(ncid, i, ATT_NAME(i,j), buf); + IF (err != NC_NOERR) { + error("%s", nc_strerror(err)); + } else { + nok++; + for (k = 0; k < ATT_LEN(i,j); k++) { + ndx[0] = k; + expect = hash(ATT_TYPE(i,j), -1, ndx); + p = (char *) buf; + p += k * (size_t)nctypelen(ATT_TYPE(i,j)); + err = nc2dbl( ATT_TYPE(i,j), p, &got ); + IF (err != NC_NOERR) + error("error in nc2dbl"); + if (inRange(expect,ATT_TYPE(i,j))) { + IF (!equal2(got,expect,ATT_TYPE(i,j))) { + error("buf read not that expected"); + if (verbose) { + error("\n"); + error("varid: %d, ", i); + error("var_name: %s, ", + i >= 0 ? var_name[i] : "Global"); + error("att_name: %s, ", ATT_NAME(i,j)); + error("element number: %d\n", k); + error("expect: %-23.16e\n", expect); + error(" got: %-23.16e", got); + } + } + } + } + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_att(void) +{ + int ncid; + int i; + int j; + int err; + nc_type t; + size_t n; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + for (j = 0; j < NATTS(i); j++) { + err = nc_inq_att(BAD_ID, i, ATT_NAME(i,j), &t, &n); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_att(ncid, BAD_VARID, ATT_NAME(i,j), &t, &n); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_att(ncid, i, "noSuch", &t, &n); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_att(ncid, i, ATT_NAME(i,j), &t, &n); + IF (err != NC_NOERR) { + error("%s", nc_strerror(err)); + } else { + IF (t != ATT_TYPE(i,j)) + error("type not that expected"); + ELSE_NOK + IF (n != ATT_LEN(i,j)) + error("length not that expected"); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_attlen(void) +{ + int ncid; + int i; + int j; + int err; + size_t len; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + err = nc_inq_attlen(ncid, i, "noSuch", &len); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s", nc_err_code_name(err)); + ELSE_NOK + for (j = 0; j < NATTS(i); j++) { + err = nc_inq_attlen(BAD_ID, i, ATT_NAME(i,j), &len); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_attlen(ncid, BAD_VARID, ATT_NAME(i,j), &len); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_attlen(ncid, i, ATT_NAME(i,j), &len); + IF (err != NC_NOERR) { + error("%s", nc_strerror(err)); + } else { + IF (len != ATT_LEN(i,j)) + error("len not that expected"); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_atttype(void) +{ + int ncid; + int i; + int j; + int err; + nc_type datatype; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + err = nc_inq_atttype(ncid, i, "noSuch", &datatype); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s", nc_err_code_name(err)); + ELSE_NOK + for (j = 0; j < NATTS(i); j++) { + err = nc_inq_atttype(BAD_ID, i, ATT_NAME(i,j), &datatype); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_atttype(ncid, BAD_VARID, ATT_NAME(i,j), &datatype); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_atttype(ncid, i, ATT_NAME(i,j), &datatype); + IF (err != NC_NOERR) { + error("%s", nc_strerror(err)); + } else { + IF (datatype != ATT_TYPE(i,j)) + error("type not that expected"); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_attname(void) +{ + int ncid; + int i; + int j; + int err; + char name[NC_MAX_NAME]; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + err = nc_inq_attname(ncid, i, BAD_ATTNUM, name); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_attname(ncid, i, NATTS(i), name); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s", nc_err_code_name(err)); + ELSE_NOK + for (j = 0; j < NATTS(i); j++) { + err = nc_inq_attname(BAD_ID, i, j, name); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_attname(ncid, BAD_VARID, j, name); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_attname(ncid, i, j, name); + IF (err != NC_NOERR) { + error("%s", nc_strerror(err)); + } else { + IF (strcmp(ATT_NAME(i,j), name) != 0) + error("name not that expected"); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} + + +int +test_nc_inq_attid(void) +{ + int ncid; + int i; + int j; + int err; + int attnum; + int nok=0; + + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + err = nc_inq_attid(ncid, i, "noSuch", &attnum); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s", nc_err_code_name(err)); + ELSE_NOK + for (j = 0; j < NATTS(i); j++) { + err = nc_inq_attid(BAD_ID, i, ATT_NAME(i,j), &attnum); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_attid(ncid, BAD_VARID, ATT_NAME(i,j), &attnum); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_inq_attid(ncid, i, ATT_NAME(i,j), &attnum); + IF (err != NC_NOERR) { + error("%s", nc_strerror(err)); + } else { + IF (attnum != j) + error("attnum not that expected"); + ELSE_NOK + } + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + return nok; +} diff --git a/nc_test/test_write.c b/nc_test/test_write.c new file mode 100644 index 0000000000..ccf841b9e5 --- /dev/null +++ b/nc_test/test_write.c @@ -0,0 +1,2413 @@ +/* Do not edit this file. It is produced from the corresponding .m4 source */ +/* + * Copyright (C) 2003, Northwestern University and Argonne National Laboratory + * See COPYRIGHT notice in top-level directory. + */ +/* $Id: test_write.m4 2687 2016-12-08 18:32:13Z wkliao $ */ + + +#if defined (_WIN32) || defined (_WIN64) +#include +#endif + +#include /* open() */ +#include /* open() */ +#include /* open() */ +#ifdef _MSC_VER +#include +#else +#include /* read() */ +#endif + +#include "tests.h" +#include "config.h" +#include "math.h" + + + + + + + + +/* + * Test nc_create + * For mode in NC_NOCLOBBER, NC_CLOBBER do: + * create netcdf file 'scratch.nc' with no data, close it + * test that it can be opened, do nc_inq to check nvars = 0, etc. + * Try again in NC_NOCLOBBER mode, check error return + * On exit, delete this file + */ +int +test_nc_create(void) +{ + int clobber; /* 0 for NC_NOCLOBBER, 1 for NC_CLOBBER */ + int err; + int ncid; + int ndims; /* number of dimensions */ + int nvars; /* number of variables */ + int ngatts; /* number of global attributes */ + int recdim; /* id of unlimited dimension */ + int nok=0; + + for (clobber = 0; clobber < 2; clobber++) { + err = file_create(scratch, clobber ? NC_CLOBBER : NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) + error("create: %s", nc_strerror(err)); + ELSE_NOK + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + err = file_open(scratch, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + err = nc_inq(ncid, &ndims, &nvars, &ngatts, &recdim); + IF (err != NC_NOERR) + error("inq: %s", nc_strerror(err)); + else IF (ndims != 0) + error("inq: wrong number of dimensions returned, %d", ndims); + else IF (nvars != 0) + error("inq: wrong number of variables returned, %d", nvars); + else IF (ngatts != 0) + error("inq: wrong number of global atts returned, %d", ngatts); + else IF (recdim != -1) + error("inq: wrong record dimension ID returned, %d", recdim); + ELSE_NOK + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + } + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_EEXIST) + error("expecting NC_EEXIST but got %s", nc_err_code_name(err)); + ELSE_NOK + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + return nok; +} + + +/* + * Test nc_redef + * (In fact also tests nc_enddef - called from test_nc_enddef) + * BAD_ID + * attempt redef (error) & enddef on read-only file + * create file, define dims & vars. + * attempt put var (error) + * attempt redef (error) & enddef. + * put vars + * attempt def new dims (error) + * redef + * def new dims, vars. + * put atts + * enddef + * put vars + * close + * check file: vars & atts + * check reopening with NC_WRITE and adding new dims, atts, vars + */ +int +test_nc_redef(void) +{ + int ncid; /* netcdf id */ + /* used to force effective test of ncio->move() in redef */ + size_t sizehint = 8192; + int dimid; /* dimension id */ + int varid; /* variable id */ + int varid1; /* variable id */ + int nok=0, err; + const char * title = "Not funny"; + double var; + char name[NC_MAX_NAME]; + size_t length; + int fmt_variant1, fmt_variant2; + + /* BAD_ID tests */ + err = nc_redef(BAD_ID); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_enddef(BAD_ID); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + + /* read-only tests */ + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + err = nc_redef(ncid); + IF (err != NC_EPERM) + error("expecting NC_EPERM but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_enddef(ncid); + IF (err != NC_ENOTINDEFINE) + error("expecting NC_ENOTINDEFINE but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + /* tests using scratch file */ + err = file__create(scratch, NC_NOCLOBBER, 0, &sizehint, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + /* limit for ncio implementations which have infinite chunksize */ + if(sizehint > 32768) sizehint = 16384; + def_dims(ncid); + def_vars(ncid); + put_atts(ncid); + err = nc_inq_varid(ncid, "d", &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + var = 1.0; + + + err = nc_put_var1_double(ncid, varid, NULL, &var); + IF (err != NC_EINDEFINE) + error("expecting NC_EINDEFINE but got %s", nc_err_code_name(err)); + + + err = nc_redef(ncid); + IF (err != NC_EINDEFINE) + error("expecting NC_EINDEFINE but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + ELSE_NOK + put_vars(ncid); + err = nc_def_dim(ncid, "abc", sizehint, &dimid); + IF (err != NC_ENOTINDEFINE) + error("expecting NC_ENOTINDEFINE but got %s", nc_err_code_name(err)); + err = nc_redef(ncid); + IF (err != NC_NOERR) + error("redef: %s", nc_strerror(err)); + ELSE_NOK + + err = nc_set_fill(ncid, NC_NOFILL, NULL); + IF (err != NC_NOERR) + error("set_fill: %s", nc_strerror(err)); + + err = nc_def_dim(ncid, "abc", sizehint, &dimid); + IF (err != NC_NOERR) + error("def_dim: %s", nc_strerror(err)); + err = nc_def_var(ncid, "abcScalar", NC_INT, 0, NULL, &varid); + IF (err != NC_NOERR) + error("def_var: %s", nc_strerror(err)); + err = nc_def_var(ncid, "abc", NC_INT, 1, &dimid, &varid1); + IF (err != NC_NOERR) + error("def_var: %s", nc_strerror(err)); + { + int dimids[NDIMS +1]; + int ii = 0; + for(ii = 0; ii < NDIMS; ii++) dimids[ii] = ii; + dimids[NDIMS] = dimid; + err = nc_def_var(ncid, "abcRec", NC_INT, NDIMS, dimids, &varid1); + IF (err != NC_NOERR) + error("def_var: %s", nc_strerror(err)); + } + err = nc_put_att_text(ncid, NC_GLOBAL, "title", 1+strlen(title), title); + IF (err != NC_NOERR) + error("put_att_text: %s", nc_strerror(err)); + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + ELSE_NOK + var = 1.0; + + + err = nc_put_var1_double(ncid, varid, NULL, &var); + IF (err != NC_NOERR) + error("put_var1_double: %s", nc_strerror(err)); + err = nc_inq_format(ncid, &fmt_variant1); + IF (err) + error("inq_format: %s", nc_strerror(err)); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + /* check scratch file written as expected */ + check_file(scratch); /* checks all except "abc" stuff added above */ + + IF ((err = file_open(scratch, NC_NOWRITE, &ncid))) + error("open: %s", nc_strerror(err)); + IF ((err = nc_inq_dim(ncid, dimid, name, &length))) + error("inq_dim: %s", nc_strerror(err)); + IF (strcmp(name, "abc") != 0) + error("Unexpected dim name"); + IF (length != sizehint) + error("Unexpected dim length"); + IF ((err = nc_get_var1_double(ncid, varid, NULL, &var))) + error("get_var1_double: %s", nc_strerror(err)); + IF (var != 1.0) + error("get_var1_double: unexpected value"); + IF ((err = nc_close(ncid))) + error("close: %s", nc_strerror(err)); + + /* open scratch file for writing, add another dim, var, att, then check */ + IF ((err = file_open(scratch, NC_WRITE, &ncid))) + error("open: %s", nc_strerror(err)); + IF ((err = nc_redef(ncid))) + error("redef: %s", nc_strerror(err)); + IF ((err = nc_def_dim(ncid, "def", sizehint, &dimid))) + error("def_dim: %s", nc_strerror(err)); + IF ((err = nc_def_var(ncid, "defScalar", NC_INT, 0, NULL, &varid))) + error("def_var: %s", nc_strerror(err)); + IF ((err = nc_def_var(ncid, "def", NC_INT, 1, &dimid, &varid1))) + error("def_var: %s", nc_strerror(err)); + IF ((err = nc_put_att_text(ncid, NC_GLOBAL, "Credits", 1+strlen("Thanks!"), "Thanks!"))) + error("put_att_text: %s", nc_strerror(err)); + IF ((err = nc_enddef(ncid))) + error("enddef: %s", nc_strerror(err)); + var = 2.0; + IF ((err = nc_put_var1_double(ncid, varid, NULL, &var))) + error("put_var1_double: %s", nc_strerror(err)); + IF ((err = nc_close(ncid))) + error("close: %s", nc_strerror(err)); + + /* check scratch file written as expected */ + check_file(scratch); + + err = file_open(scratch, NC_NOWRITE, &ncid); + IF (err) + error("open: %s", nc_strerror(err)); + err = nc_inq_dim(ncid, dimid, name, &length); + IF (err) + error("inq_dim: %s", nc_strerror(err)); + IF (strcmp(name, "def") != 0) + error("Unexpected dim name"); + IF (length != sizehint) + error("Unexpected dim length"); + err = nc_get_var1_double(ncid, varid, NULL, &var); + IF (err) + error("get_var1_double: %s", nc_strerror(err)); + IF (var != 2.0) + error("get_var1_double: unexpected value"); + /* make sure format variant hasn't changed from when created */ + err = nc_inq_format(ncid, &fmt_variant2); + IF (err) + error("inq_format: %s", nc_strerror(err)); + IF (fmt_variant1 != fmt_variant2) + error("enddef changed format variant"); + err = nc_close(ncid); + IF (err) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + return nok; +} + + +/* + * Test nc_enddef + * Simply calls test_nc_redef which tests both nc_redef & nc_enddef + */ +int +test_nc_enddef(void) +{ + return test_nc_redef(); +} + + +/* + * Test nc_sync + * try with bad handle, check error + * try in define mode, check error + * try writing with one handle, reading with another on same netCDF + */ +int +test_nc_sync(void) +{ + int ncidw; /* netcdf id for writing */ + int ncidr; /* netcdf id for reading */ + int nok=0, err; + + /* BAD_ID test */ + err = nc_sync(BAD_ID); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + + /* create scratch file & try nc_sync in define mode */ + err = file_create(scratch, NC_NOCLOBBER, &ncidw); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + err = nc_sync(ncidw); + IF (err != NC_EINDEFINE) + error("expecting NC_EINDEFINE but got %s", nc_err_code_name(err)); + ELSE_NOK + + /* write using same handle */ + def_dims(ncidw); + def_vars(ncidw); + put_atts(ncidw); + err = nc_enddef(ncidw); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + put_vars(ncidw); + err = nc_sync(ncidw); + IF (err != NC_NOERR) + error("sync of ncidw failed: %s", nc_strerror(err)); + ELSE_NOK + + /* open another handle, nc_sync, read (check) */ + err = file_open(scratch, NC_NOWRITE, &ncidr); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + err = nc_sync(ncidr); + IF (err != NC_NOERR) + error("sync of ncidr failed: %s", nc_strerror(err)); + ELSE_NOK + check_dims(ncidr); + check_atts(ncidr); + check_vars(ncidr); + + /* close both handles */ + err = nc_close(ncidr); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + err = nc_close(ncidw); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + return nok; +} + + +/* + * Test nc_abort + * try with bad handle, check error + * try in define mode before anything written, check that file was deleted + * try after nc_enddef, nc_redef, define new dims, vars, atts + * try after writing variable + */ +int +test_nc_abort(void) +{ + int ncid; /* netcdf id */ + int err; + int ndims; + int nvars; + int ngatts; + int nok=0; + + /* BAD_ID test */ + err = nc_abort(BAD_ID); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + + /* create scratch file & try nc_abort in define mode */ + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + def_dims(ncid); + def_vars(ncid); + put_atts(ncid); + err = nc_abort(ncid); + IF (err != NC_NOERR) + error("abort of ncid failed: %s", nc_strerror(err)); + ELSE_NOK + err = nc_close(ncid); /* should already be closed */ + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + err = nc_delete(scratch); /* should already be deleted */ +IF (err != ENOENT && err != NC_EIO) + error("expecting ENOENT or NC_EIO but got %s", nc_err_code_name(err)); + /* + * create scratch file + * do nc_enddef & nc_redef + * define new dims, vars, atts + * try nc_abort: should restore previous state (no dims, vars, atts) + */ + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + err = nc_redef(ncid); + IF (err != NC_NOERR) + error("redef: %s", nc_strerror(err)); + def_dims(ncid); + def_vars(ncid); + put_atts(ncid); + err = nc_abort(ncid); + IF (err != NC_NOERR) + error("abort of ncid failed: %s", nc_strerror(err)); + ELSE_NOK + err = nc_close(ncid); /* should already be closed */ + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + err = file_open(scratch, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + err = nc_inq(ncid, &ndims, &nvars, &ngatts, NULL); + IF (err != NC_NOERR) + error("inq: %s", nc_strerror(err)); + IF (ndims != 0) + error("ndims should be 0"); + IF (nvars != 0) + error("nvars should be 0"); + IF (ngatts != 0) + error("ngatts should be 0"); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + /* try nc_abort in data mode - should just close */ + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + def_dims(ncid); + def_vars(ncid); + put_atts(ncid); + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + put_vars(ncid); + err = nc_abort(ncid); + IF (err != NC_NOERR) + error("abort of ncid failed: %s", nc_strerror(err)); + ELSE_NOK + err = nc_close(ncid); /* should already be closed */ + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + check_file(scratch); + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + return nok; +} + + +/* + * Test nc_def_dim + * try with bad netCDF handle, check error + * try in data mode, check error + * check that returned id is one more than previous id + * try adding same dimension twice, check error + * try with illegal sizes, check error + * make sure unlimited size works, shows up in nc_inq_unlimdim + * try to define a second unlimited dimension, check error + */ +int +test_nc_def_dim(void) +{ + int ncid; + int err; /* status */ + int i, nok=0; + int dimid; /* dimension id */ + size_t length; + + /* BAD_ID test */ + err = nc_def_dim(BAD_ID, "abc", 8, &dimid); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + + /* data mode test */ + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + err = nc_def_dim(ncid, "abc", 8, &dimid); + IF (err != NC_ENOTINDEFINE) + error("expecting NC_ENOTINDEFINE but got %s", nc_err_code_name(err)); + ELSE_NOK + + /* define-mode tests: unlimited dim */ + err = nc_redef(ncid); + IF (err != NC_NOERR) + error("redef: %s", nc_strerror(err)); + err = nc_def_dim(ncid, dim_name[0], NC_UNLIMITED, &dimid); + IF (err != NC_NOERR) + error("def_dim: %s", nc_strerror(err)); + ELSE_NOK + IF (dimid != 0) + error("Unexpected dimid"); + ELSE_NOK + err = nc_inq_unlimdim(ncid, &dimid); + IF (err != NC_NOERR) + error("inq_unlimdim: %s", nc_strerror(err)); + IF (dimid != 0) + error("Unexpected recdim"); + err = nc_inq_dimlen(ncid, dimid, &length); + IF (length != 0) + error("Unexpected length"); + err = nc_def_dim(ncid, "abc", NC_UNLIMITED, &dimid); + IF (err != NC_EUNLIMIT) + error("expecting NC_EUNLIMIT but got %s", nc_err_code_name(err)); + ELSE_NOK + + /* define-mode tests: remaining dims */ + for (i = 1; i < NDIMS; i++) { + err = nc_def_dim(ncid, dim_name[i-1], dim_len[i], &dimid); + IF (err != NC_ENAMEINUSE) + error("expecting NC_ENAMEINUSE but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_def_dim(ncid, BAD_NAME, dim_len[i], &dimid); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s", nc_err_code_name(err)); + ELSE_NOK +if(sizeof(long) > 4) /* Fix: dmh 11/4/2011: works only if sizeof(long) > 4 */ + { + err = nc_def_dim(ncid, dim_name[i], (size_t)(NC_UNLIMITED-1), &dimid); + IF (err != NC_EDIMSIZE) + error("expecting NC_EDIMSIZE but got %s", nc_err_code_name(err)); + ELSE_NOK + } + err = nc_def_dim(ncid, dim_name[i], dim_len[i], &dimid); + IF (err != NC_NOERR) + error("def_dim: %s", nc_strerror(err)); + ELSE_NOK + IF (dimid != i) + error("Unexpected dimid"); + } + + /* Following just to expand unlimited dim */ + def_vars(ncid); + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + put_vars(ncid); + + /* Check all dims */ + check_dims(ncid); + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + return nok; +} + + +/* + * Test nc_rename_dim + * try with bad netCDF handle, check error + * check that proper rename worked with nc_inq_dim + * try renaming to existing dimension name, check error + * try with bad dimension handle, check error + */ +int +test_nc_rename_dim(void) +{ + int ncid; + int err, nok=0; /* status */ + char name[NC_MAX_NAME]; + + /* BAD_ID test */ + err = nc_rename_dim(BAD_ID, 0, "abc"); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + + /* main tests */ + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + def_dims(ncid); + err = nc_rename_dim(ncid, BAD_DIMID, "abc"); + IF (err != NC_EBADDIM) + error("expecting NC_EBADDIM but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_rename_dim(ncid, 2, "abc"); + IF (err != NC_NOERR) + error("rename_dim: %s", nc_strerror(err)); + ELSE_NOK + err = nc_inq_dimname(ncid, 2, name); + IF (strcmp(name, "abc") != 0) + error("Unexpected name: %s", name); + err = nc_rename_dim(ncid, 0, "abc"); + IF (err != NC_ENAMEINUSE) + error("expecting NC_ENAMEINUSE but got %s", nc_err_code_name(err)); + ELSE_NOK + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + return nok; +} + + +/* + * Test nc_def_var + * try with bad netCDF handle, check error + * try with bad name, check error + * scalar tests: + * check that proper define worked with nc_inq_var + * try redefining an existing variable, check error + * try with bad datatype, check error + * try with bad number of dimensions, check error + * try in data mode, check error + * check that returned id is one more than previous id + * try with bad dimension ids, check error + */ +int +test_nc_def_var(void) +{ + int ncid; + int varid; + int err, nok=0; /* status */ + int i; + int ndims; + int natts; + char name[NC_MAX_NAME]; + int dimids[MAX_RANK]; + nc_type datatype; + + /* BAD_ID test */ + err = nc_def_var(BAD_ID, "abc", NC_SHORT, 0, NULL, &varid); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + + /* scalar tests */ + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + err = nc_def_var(ncid, "abc", NC_SHORT, 0, NULL, &varid); + IF (err != NC_NOERR) + error("def_var: %s", nc_strerror(err)); + ELSE_NOK + err = nc_inq_var(ncid, varid, name, &datatype, &ndims, dimids, &natts); + IF (err != NC_NOERR) + error("inq_var: %s", nc_strerror(err)); + IF (strcmp(name, "abc") != 0) + error("Unexpected name: %s", name); + IF (datatype != NC_SHORT) + error("Unexpected datatype"); + IF (ndims != 0) + error("Unexpected rank"); + err = nc_def_var(ncid, BAD_NAME, NC_SHORT, 0, NULL, &varid); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_def_var(ncid, "abc", NC_SHORT, 0, NULL, &varid); + IF (err != NC_ENAMEINUSE) + error("expecting NC_ENAMEINUSE but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_def_var(ncid, "ABC", BAD_TYPE, -1, dimids, &varid); + IF (err != NC_EBADTYPE) + error("expecting NC_EBADTYPE but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_def_var(ncid, "ABC", NC_SHORT, -1, dimids, &varid); + IF (err != NC_EINVAL) + error("expecting NC_EINVAL but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + err = nc_def_var(ncid, "ABC", NC_SHORT, 0, dimids, &varid); + IF (err != NC_ENOTINDEFINE) + error("expecting NC_ENOTINDEFINE but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + + /* general tests using global vars */ + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + def_dims(ncid); + for (i = 0; i < numVars; i++) { + err = nc_def_var(ncid, var_name[i], var_type[i], var_rank[i], + var_dimid[i], &varid); + IF (err != NC_NOERR) + error("def_var: %s", nc_strerror(err)); + ELSE_NOK + IF (varid != i) + error("Unexpected varid"); + ELSE_NOK + } + + /* try bad dim ids */ + dimids[0] = BAD_DIMID; + err = nc_def_var(ncid, "abc", NC_SHORT, 1, dimids, &varid); + IF (err != NC_EBADDIM) + error("expecting NC_EBADDIM but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + return nok; +} + + +/* + * Test nc_put_var1(,,,) + */ +int +test_nc_put_var1(void) +{ + int i, err, ncid, nok=0; + size_t j, index[MAX_RANK]; + double value[1]; + double buf[1]; /* (void *) buffer */ + + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_var1(BAD_ID,0,NULL,NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_var1(ncid,BAD_VARID,NULL,NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + value[0] = 5; /* reset to a value within bounds */ + + + + + /* test NC_EINVALCOORDS */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) index[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + index[j] = var_shape[i][j]; /* out of boundary check */ + err = nc_put_var1(ncid,i,index,value); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + index[j] = 0; + } + + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value[0] = hash(var_type[i], var_rank[i], index); + if (inRange(value[0], var_type[i])) { + err = dbl2nc(value[0], var_type[i], buf); + IF (err != NC_NOERR) + error("error in dbl2nc var:%s type:%s", + var_name[i],s_nc_type(var_type[i])); + err = nc_put_var1(ncid,i,index,buf); + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + check_vars(ncid); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + return nok; +} + + +/* + * Test nc_put_vara(,,,,) + * Choose a random point dividing each dim into 2 parts + * Put 2^rank (nslabs) slabs so defined + * Redefine buffer for each put. + * At end check all variables using check_vars() + */ +int +test_nc_put_vara(void) +{ + int d, i, k, err, nslabs, ncid, nok=0; + size_t j, nels; + size_t start[MAX_RANK]; + size_t edge[MAX_RANK]; + size_t index[MAX_RANK]; + size_t mid[MAX_RANK]; + double buf[MAX_NELS]; /* (void *) buffer */ + char *p; /* (void *) pointer */ + double value = 0; + + + for(j = 0; j < MAX_RANK; j++ ) { + start[j] = 0; + edge[j] = 0; + index[j] = 0; + mid[j] = 0; + } + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vara(BAD_ID,0,start,edge,buf); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vara(ncid,BAD_VARID,start,edge,buf); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + buf[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vara(BAD_ID,i,start,edge,buf); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara(ncid,i,start,edge,buf); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; + err = nc_put_vara(ncid,i,start,edge,buf); + IF (err != NC_EEDGE) + error("expecting NC_EEDG but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + } + /* Check correct error returned when nothing to put, when edge[*]==0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == RECDIM) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vara(ncid,i,start,edge,buf); + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vara(ncid,i,start,edge,buf); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + for (k = 0; k < nslabs; k++) { + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + }else{ + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + nels *= edge[j]; + } + p = (char *) buf; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], edge, index); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index[d] += start[d]; + value = hash(var_type[i], var_rank[i], index); + if (!inRange(value, var_type[i])) + value = 0; + err = dbl2nc(value, var_type[i], p); + IF (err != NC_NOERR) + error("error in dbl2nc"); + p += nctypelen(var_type[i]); + } + err = nc_put_vara(ncid,i,start,edge,buf); + IF (err != NC_NOERR) + error("%s", nc_strerror(err)); + ELSE_NOK + } + } + + check_vars(ncid); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + return nok; +} + + +/* + * Test nc_put_vars(,,,,,) + * Choose a random point dividing each dim into 2 parts + * Put 2^rank (nslabs) slabs so defined + * Choose random stride from 1 to edge + * Redefine buffer for each put. + * At end check all variables using check_vars() + */ +int +test_nc_put_vars(void) +{ + int ncid, d, i, k, err, nslabs, nok=0; + ptrdiff_t nstarts; /* number of different starts */ + size_t j, m, nels; + size_t start[MAX_RANK]; + size_t edge[MAX_RANK]; + size_t index[MAX_RANK]; + size_t index2[MAX_RANK]; + size_t mid[MAX_RANK]; + size_t count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + double buf[MAX_NELS]; /* (void *) buffer */ + char *p; /* (void *) pointer */ + double value; + + + for(j = 0; j < MAX_RANK; j++ ) { + start[j] = 0; + edge[j] = 0; + index[j] = 0; + mid[j] = 0; + index2[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + } + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_vars(BAD_ID,0,NULL,NULL,NULL,NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_vars(ncid,BAD_VARID,NULL,NULL,NULL,NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + buf[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_vars(BAD_ID,i,NULL,NULL,NULL,buf); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == 0) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vars(ncid,i,start,edge,stride,buf); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; /* edge error check */ + err = nc_put_vars(ncid,i,start,edge,stride,buf); + IF (err != NC_EEDGE) + error("expecting NC_EEDG but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; /* strided edge error check */ + err = nc_put_vars(ncid,i,start,edge,stride,buf); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned even when nothing to put */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == 0) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_vars(ncid,i,start,edge,stride,buf); + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_vars(ncid,i,start,edge,stride,buf); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + /* Choose a random point dividing each dim into 2 parts */ + /* put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + }else{ + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + nels = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + nels *= count[j]; + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + p = (char *) buf; + for (j = 0; j < nels; j++) { + err = toMixedBase(j, var_rank[i], count, index2); + IF (err != 0) error("error in toMixedBase"); + for (d = 0; d < var_rank[i] && d < MAX_RANK; d++) + index2[d] = index[d] + index2[d] * (size_t)stride[d]; + value = hash(var_type[i], var_rank[i], index2); + if (!inRange(value, var_type[i])) + value = 0; + err = dbl2nc(value, var_type[i], p); + IF (err != NC_NOERR) + error("error in dbl2nc"); + p += nctypelen(var_type[i]); + } + err = nc_put_vars(ncid,i,index,count,stride,buf); + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + check_vars(ncid); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + return nok; +} + + +/* + * Test nc_put_varm(,,,,,,) + * Choose a random point dividing each dim into 2 parts + * Put 2^rank (nslabs) slabs so defined + * Choose random stride from 1 to edge + * Buffer is bit image of whole external variable. + * So all puts for a variable put different elements of buffer + * At end check all variables using check_vars() + */ +int +test_nc_put_varm(void) +{ + int ncid, nok=0; + int i; + int k; + int err; + int nslabs; + size_t j, m; + ptrdiff_t nstarts; /* number of different starts */ + size_t start[MAX_RANK]; + size_t edge[MAX_RANK]; + size_t index[MAX_RANK]; + size_t mid[MAX_RANK]; + size_t count[MAX_RANK]; + size_t sstride[MAX_RANK]; + ptrdiff_t stride[MAX_RANK]; + ptrdiff_t imap[MAX_RANK]; + ptrdiff_t imap2[MAX_RANK]; + + double buf[MAX_NELS]; /* (void *) buffer */ + char *p; /* (void *) pointer */ + double value; + + + for(j = 0; j < MAX_RANK; j++ ) { + start[j] = 0; + edge[j] = 0; + index[j] = 0; + mid[j] = 0; + count[j] = 0; + sstride[j] = 1; + stride[j] = 1; + imap[j] = 0; + imap2[j] = 0; + } + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + def_dims(ncid); + def_vars(ncid); + + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + /* check if can detect a bad file ID */ + err = nc_put_varm(NC_EBADID,0,NULL,NULL,NULL,NULL,NULL); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + /* check if can detect a bad variable ID */ + err = nc_put_varm(ncid,BAD_VARID,NULL,NULL,NULL,NULL,NULL); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s",nc_err_code_name(err)); + ELSE_NOK + + for (i = 0; i < numVars; i++) { + assert(var_rank[i] <= MAX_RANK); + assert(var_nels[i] <= MAX_NELS); + + buf[0] = 5; /* reset to a value within bounds */ + + /* check if can detect a bad file ID */ + err = nc_put_varm(BAD_ID,i,NULL,NULL,NULL,NULL,buf); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s",nc_err_code_name(err)); + ELSE_NOK + + + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + start[j] = 0; + edge[j] = 1; + stride[j] = 1; + imap[j] = 1; + mid[j] = 1; + } + + + /* first test when edge[*] > 0 */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == 0) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_varm(ncid,i,start,edge,stride,imap,buf); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + edge[j] = var_shape[i][j] + 1; /* edge error check */ + err = nc_put_varm(ncid,i,start,edge,stride,imap,buf); + IF (err != NC_EEDGE) + error("expecting NC_EEDG but got %s",nc_err_code_name(err)); + ELSE_NOK + edge[j] = 1; + stride[j] = 0; /* strided edge error check */ + err = nc_put_varm(ncid,i,start,edge,stride,imap,buf); + IF (err != NC_ESTRIDE) + error("expecting NC_ESTRIDE but got %s",nc_err_code_name(err)); + ELSE_NOK + stride[j] = 1; + } + /* Check correct error returned even when nothing to put */ + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 0; + + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if (var_dimid[i][j] == 0) continue; /* skip record dim */ + start[j] = var_shape[i][j]; + err = nc_put_varm(ncid,i,start,edge,stride,imap,buf); + IF (err != NC_NOERR) /* allowed when edge[j]==0 */ + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = var_shape[i][j]+1; /* out of boundary check */ + err = nc_put_varm(ncid,i,start,edge,stride,imap,buf); + IF (err != NC_EINVALCOORDS) + error("expecting NC_EINVALCOORDS but got %s",nc_err_code_name(err)); + ELSE_NOK + start[j] = 0; + } + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) edge[j] = 1; + + if (var_rank[i] > 0) { + int jj = var_rank[i] - 1; + imap[jj] = nctypelen(var_type[i]); /* netCDF considers imap in bytes */ + imap[jj] = 1; /* PnetCDF considers imap in elements */ + for (; jj > 0; jj--) + imap[jj-1] = imap[jj] * (ptrdiff_t)var_shape[i][jj]; + } + p = (char *) buf; + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + value = hash(var_type[i], var_rank[i], index); + if (!inRange(value, var_type[i])) + value = 0; + err = dbl2nc(value, var_type[i], p); + IF (err != NC_NOERR) + error("error in dbl2nc"); + p += nctypelen(var_type[i]); + } + + /* Choose a random point dividing each dim into 2 parts */ + /* put 2^rank (nslabs) slabs so defined */ + nslabs = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + mid[j] = roll( var_shape[i][j] ); + nslabs *= 2; + } + /* bits of k determine whether to put lower or upper part of dim */ + /* choose random stride from 1 to edge */ + for (k = 0; k < nslabs; k++) { + nstarts = 1; + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + if ((k >> j) & 1) { + start[j] = 0; + edge[j] = mid[j]; + }else{ + start[j] = mid[j]; + edge[j] = var_shape[i][j] - mid[j]; + } + sstride[j] = edge[j] > 0 ? 1+roll(edge[j]) : 1; + stride[j] = (ptrdiff_t)sstride[j]; + imap2[j] = imap[j] * (ptrdiff_t)sstride[j]; + nstarts *= stride[j]; + } + for (m = 0; m < nstarts; m++) { + if (var_rank[i] == 0 && i%2 == 0) { + err = nc_put_varm(ncid,i,NULL,NULL,NULL,NULL,buf); + } else { + err = toMixedBase(m, var_rank[i], sstride, index); + IF (err != 0) error("error in toMixedBase"); + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + count[j] = 1 + (edge[j] - index[j] - 1) / ( (size_t)stride[j] == 0 ? 1 : (size_t)stride[j]); + index[j] += start[j]; + } + /* Random choice of forward or backward */ +/* TODO + if ( roll(2) ) { + for (j = 0; j < var_rank[i] && j < MAX_RANK; j++) { + index[j] += (count[j] - 1) * (size_t)stride[j]; + stride[j] = -stride[j]; + } + } + */ + j = fromMixedBase(var_rank[i], index, var_shape[i]); + p = (char *) buf + (int)j * nctypelen(var_type[i]); + + err = nc_put_varm(ncid,i,index,count,stride,imap2,p); + } + IF (err != NC_NOERR) + error("expecting NC_NOERR but got %s",nc_err_code_name(err)); + ELSE_NOK + } + } + } + + check_vars(ncid); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + return nok; +} + + +/* + * Test nc_rename_var + * try with bad netCDF handle, check error + * try with bad variable handle, check error + * try renaming to existing variable name, check error + * check that proper rename worked with nc_inq_varid + * try in data mode, check error + */ +int +test_nc_rename_var(void) +{ + int ncid; + int varid; + int err, nok=0; + int i; + char name[NC_MAX_NAME]; + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + err = nc_rename_var(ncid, BAD_VARID, "newName"); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + def_dims(ncid); + def_vars(ncid); + + /* Prefix "new_" to each name */ + for (i = 0; i < numVars; i++) { + err = nc_rename_var(BAD_ID, i, "newName"); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_rename_var(ncid, i, var_name[numVars-1]); + IF (err != NC_ENAMEINUSE) + error("expecting NC_ENAMEINUSE but got %s", nc_err_code_name(err)); + ELSE_NOK + strcpy(name, "new_"); + strcat(name, var_name[i]); + err = nc_rename_var(ncid, i, name); + IF (err != NC_NOERR) + error("rename_var: %s", nc_strerror(err)); + ELSE_NOK + err = nc_inq_varid(ncid, name, &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + IF (varid != i) + error("Unexpected varid"); + } + + /* Change to data mode */ + /* Try making names even longer. Then restore original names */ + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + for (i = 0; i < numVars; i++) { + strcpy(name, "even_longer_"); + strcat(name, var_name[i]); + err = nc_rename_var(ncid, i, name); + IF (err != NC_ENOTINDEFINE) + error("expecting NC_ENOTINDEFINE but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_rename_var(ncid, i, var_name[i]); + IF (err != NC_NOERR) + error("rename_var: %s", nc_strerror(err)); + ELSE_NOK + err = nc_inq_varid(ncid, var_name[i], &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + IF (varid != i) + error("Unexpected varid"); + } + + put_vars(ncid); + check_vars(ncid); + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + return nok; +} + + +int +test_nc_put_att(void) +{ + int ncid, nok=0; + int varid; + int i; + int j; + size_t k, ndx[1]; + int err; + double buf[MAX_NELS]; /* (void *) buffer */ + char *p; /* (void *) pointer */ + char *name; /* of att */ + nc_type datatype; /* of att */ + size_t length; /* of att */ + double value; + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + def_dims(ncid); + def_vars(ncid); + + for (i = -1; i < numVars; i++) { + varid = VARID(i); + for (j = 0; j < NATTS(i); j++) { + name = ATT_NAME(i,j); + datatype = ATT_TYPE(i,j); + length = ATT_LEN(i,j); + err = nc_put_att(BAD_ID, varid, name, datatype, length, buf); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_put_att(ncid, varid, BAD_NAME, datatype, length, buf); + IF (err != NC_EBADNAME) + error("expecting NC_EBADNAME but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_put_att(ncid, BAD_VARID, name, datatype, length, buf); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_put_att(ncid, varid, name, BAD_TYPE, length, buf); + IF (err != NC_EBADTYPE) + error("expecting NC_EBADTYPE but got %s", nc_err_code_name(err)); + ELSE_NOK + p = (char *) buf; + for (k=0; k 0 && ATT_LEN(i,j) > 0) { + err = nc_rename_att(ncid_out, i, att_name[i][0], "a"); + IF (err != NC_NOERR) + error("rename_att: %s", nc_strerror(err)); + err = nc_copy_att(ncid_out, NC_GLOBAL, "a", ncid_out, i); + IF (err != NC_NOERR) + error("copy_att: %s", nc_strerror(err)); + ELSE_NOK + } + } + err = nc_close(ncid_out); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + /* Reopen & check */ + err = file_open(scratch, NC_WRITE, &ncid_out); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + for (i = 0; i < numVars; i++) { + if (NATTS(i) > 0 && ATT_LEN(i,j) > 0) { + err = nc_inq_att(ncid_out, i, "a", &datatype, &length); + IF (err != NC_NOERR) + error("inq_att: %s", nc_strerror(err)); + IF (datatype != NC_CHAR) + error("Unexpected type"); + IF (length != 1) + error("Unexpected length"); + err = nc_get_att_text(ncid_out, i, "a", &value); + IF (err != NC_NOERR) + error("get_att_text: %s", nc_strerror(err)); + IF (value != 'A') + error("Unexpected value"); + } + } + + err = nc_close(ncid_out); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + return nok; +} + + +/* + * Test nc_rename_att + * try with bad netCDF handle, check error + * try with bad variable handle, check error + * try with nonexisting att name, check error + * try renaming to existing att name, check error + * check that proper rename worked with nc_inq_attid + * try in data mode, check error + */ +int +test_nc_rename_att(void) +{ + int ncid; + int varid; + int err; + int i; + int j; + size_t k, ndx[1]; + int attnum; + char *attname; + char name[NC_MAX_NAME]; + char oldname[NC_MAX_NAME]; + char newname[NC_MAX_NAME]; + int nok = 0; /* count of valid comparisons */ + nc_type datatype; + nc_type atttype; + size_t length; + size_t attlength; + char text[MAX_NELS]; + double value[MAX_NELS]; + double expect; + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + err = nc_rename_att(ncid, BAD_VARID, "abc", "newName"); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + def_dims(ncid); + def_vars(ncid); + put_atts(ncid); + + for (i = -1; i < numVars; i++) { + varid = VARID(i); + for (j = 0; j < NATTS(i); j++) { + attname = ATT_NAME(i,j); + err = nc_rename_att(BAD_ID, varid, attname, "newName"); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_rename_att(ncid, varid, "noSuch", "newName"); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s", nc_err_code_name(err)); + ELSE_NOK + strcpy(newname, "new_"); + strcat(newname, attname); + err = nc_rename_att(ncid, varid, attname, newname); + IF (err != NC_NOERR) + error("rename_att: %s", nc_strerror(err)); + ELSE_NOK + err = nc_inq_attid(ncid, varid, newname, &attnum); + IF (err != NC_NOERR) + error("inq_attid: %s", nc_strerror(err)); + IF (attnum != j) + error("Unexpected attnum"); + } + } + + /* Close. Reopen & check */ + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + err = file_open(scratch, NC_WRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + varid = VARID(i); + for (j = 0; j < NATTS(i); j++) { + attname = ATT_NAME(i,j); + atttype = ATT_TYPE(i,j); + attlength = ATT_LEN(i,j); + strcpy(newname, "new_"); + strcat(newname, attname); + err = nc_inq_attname(ncid, varid, j, name); + IF (err != NC_NOERR) + error("inq_attname: %s", nc_strerror(err)); + IF (strcmp(name, newname) != 0) + error("inq_attname: unexpected name"); + err = nc_inq_att(ncid, varid, name, &datatype, &length); + IF (err != NC_NOERR) + error("inq_att: %s", nc_strerror(err)); + IF (datatype != atttype) + error("inq_att: unexpected type"); + IF (length != attlength) + error("inq_att: unexpected length"); + if (datatype == NC_CHAR) { + err = nc_get_att_text(ncid, varid, name, text); + IF (err != NC_NOERR) + error("get_att_text: %s", nc_strerror(err)); + for (k = 0; k < attlength; k++) { + ndx[0] = k; + expect = hash(datatype, -1, ndx); + IF (text[k] != (char)expect) + error("get_att_text: unexpected value"); + } + } else { + err = nc_get_att_double(ncid, varid, name, value); + IF (err != NC_NOERR) + error("get_att_double: %s", nc_strerror(err)); + for (k = 0; k < attlength; k++) { + ndx[0] = k; + expect = hash(datatype, -1, ndx); + if (inRange(expect, datatype)) { + IF (!equal(value[k],expect,datatype,NCT_DOUBLE)) + error("get_att_double: unexpected value"); + } + } + } + } + } + + /* Now in data mode */ + /* Try making names even longer. Then restore original names */ + + for (i = -1; i < numVars; i++) { + varid = VARID(i); + for (j = 0; j < NATTS(i); j++) { + attname = ATT_NAME(i,j); + strcpy(oldname, "new_"); + strcat(oldname, attname); + strcpy(newname, "even_longer_"); + strcat(newname, attname); + err = nc_rename_att(ncid, varid, oldname, newname); + IF (err != NC_ENOTINDEFINE) + error("expecting NC_ENOTINDEFINE but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_rename_att(ncid, varid, oldname, attname); + IF (err != NC_NOERR) + error("rename_att: %s", nc_strerror(err)); + ELSE_NOK + err = nc_inq_attid(ncid, varid, attname, &attnum); + IF (err != NC_NOERR) + error("inq_attid: %s", nc_strerror(err)); + IF (attnum != j) + error("Unexpected attnum"); + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + return nok; +} + + +/* + * Test nc_del_att + * try with bad netCDF handle, check error + * try with bad variable handle, check error + * try with nonexisting att name, check error + * check that proper delete worked using: + * nc_inq_attid, nc_inq_natts, nc_inq_varnatts + */ +int +test_nc_del_att(void) +{ + int ncid; + int err, nok=0; + int i; + int j; + int attnum; + int natts; + int numatts; + int varid; + char *name; /* of att */ + + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + err = nc_del_att(ncid, BAD_VARID, "abc"); + IF (err != NC_ENOTVAR) + error("expecting NC_ENOTVAR but got %s", nc_err_code_name(err)); + ELSE_NOK + def_dims(ncid); + def_vars(ncid); + put_atts(ncid); + + for (i = -1; i < numVars; i++) { + varid = VARID(i); + numatts = NATTS(i); + for (j = 0; j < numatts; j++) { + name = ATT_NAME(i,j); + err = nc_del_att(BAD_ID, varid, name); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_del_att(ncid, varid, "noSuch"); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s", nc_err_code_name(err)); + ELSE_NOK + err = nc_del_att(ncid, varid, name); + IF (err != NC_NOERR) + error("del_att: %s", nc_strerror(err)); + ELSE_NOK + err = nc_inq_attid(ncid, varid, name, &attnum); + IF (err != NC_ENOTATT) + error("expecting NC_ENOTATT but got %s", nc_err_code_name(err)); + if (i < 0) { + err = nc_inq_natts(ncid, &natts); + IF (err != NC_NOERR) + error("inq_natts: %s", nc_strerror(err)); + IF (natts != numatts-j-1) + error("natts: expected %d, got %d", numatts-j-1, natts); + } + err = nc_inq_varnatts(ncid, varid, &natts); + IF (err != NC_NOERR) + error("inq_natts: %s", nc_strerror(err)); + IF (natts != numatts-j-1) + error("natts: expected %d, got %d", numatts-j-1, natts); + } + } + + /* Close. Reopen & check no attributes left */ + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + err = file_open(scratch, NC_WRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + err = nc_inq_natts(ncid, &natts); + IF (err != NC_NOERR) + error("inq_natts: %s", nc_strerror(err)); + IF (natts != 0) + error("natts: expected %d, got %d", 0, natts); + for (i = -1; i < numVars; i++) { + varid = VARID(i); + err = nc_inq_varnatts(ncid, varid, &natts); + IF (err != NC_NOERR) + error("inq_natts: %s", nc_strerror(err)); + IF (natts != 0) + error("natts: expected %d, got %d", 0, natts); + } + + /* restore attributes. change to data mode. try to delete */ + err = nc_redef(ncid); + IF (err != NC_NOERR) + error("redef: %s", nc_strerror(err)); + put_atts(ncid); + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + + for (i = -1; i < numVars; i++) { + varid = VARID(i); + numatts = NATTS(i); + for (j = 0; j < numatts; j++) { + name = ATT_NAME(i,j); + err = nc_del_att(ncid, varid, name); + IF (err != NC_ENOTINDEFINE) + error("expecting NC_ENOTINDEFINE but got %s", nc_err_code_name(err)); + ELSE_NOK + } + } + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + return nok; +} + + +/* + * Test nc_set_fill + * try with bad netCDF handle, check error + * try in read-only mode, check error + * try with bad new_fillmode, check error + * try in data mode, check error + * check that proper set to NC_FILL works for record & non-record variables + * (note that it is not possible to test NC_NOFILL mode!) + * close file & create again for test using attribute _FillValue + */ +int +test_nc_set_fill(void) +{ + int ncid; + int varid; + int err; + int i; + size_t j; + int old_fillmode; + int nok = 0; /* count of valid comparisons */ + char text = 0; + double value = 0; + double fill; + size_t index[MAX_RANK]; + + /* bad ncid */ + err = nc_set_fill(BAD_ID, NC_NOFILL, &old_fillmode); + IF (err != NC_EBADID) + error("expecting NC_EBADID but got %s", nc_err_code_name(err)); + + /* try in read-only mode */ + err = file_open(testfile, NC_NOWRITE, &ncid); + IF (err != NC_NOERR) + error("open: %s", nc_strerror(err)); + err = nc_set_fill(ncid, NC_NOFILL, &old_fillmode); + IF (err != NC_EPERM) + error("expecting NC_EPERM but got %s", nc_err_code_name(err)); + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + + /* create scratch */ + err = file_create(scratch, NC_NOCLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + + /* BAD_FILLMODE */ + err = nc_set_fill(ncid, BAD_FILLMODE, &old_fillmode); + IF (err != NC_EINVAL) + error("expecting NC_EINVAL but got %s", nc_err_code_name(err)); + + /* proper calls */ + err = nc_set_fill(ncid, NC_NOFILL, &old_fillmode); + IF (err != NC_NOERR) + error("set_fill: %s", nc_strerror(err)); + IF (old_fillmode != NC_NOFILL) + error("Unexpected old fill mode: %d", old_fillmode); + err = nc_set_fill(ncid, NC_FILL, &old_fillmode); + IF (err != NC_NOERR) + error("set_fill: %s", nc_strerror(err)); + IF (old_fillmode != NC_NOFILL) + error("Unexpected old fill mode: %d", old_fillmode); + + /* define dims & vars */ + def_dims(ncid); + def_vars(ncid); + + /* Change to data mode. Set fillmode again */ + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + err = nc_set_fill(ncid, NC_FILL, &old_fillmode); +IF (err) + error("nc_set_fill: %s", nc_strerror(err)); + IF (old_fillmode != NC_FILL) + error("Unexpected old fill mode: %d", old_fillmode); + /* Write record number NRECS to force writing of preceding records */ + /* Assumes variable cr is char vector with UNLIMITED dimension */ + err = nc_inq_varid(ncid, "cr", &varid); + IF (err != NC_NOERR) + error("inq_varid: %s", nc_strerror(err)); + index[0] = NRECS; + + + err = nc_put_var1_text(ncid, varid, index, &text); + IF (err != NC_NOERR) + error("put_var1_text_all: %s", nc_strerror(err)); + + /* get all variables & check all values equal default fill */ + for (i = 0; i < numVars; i++) { + + switch (var_type[i]) { + case NC_CHAR: fill = (double)NC_FILL_CHAR; break; + case NC_BYTE: fill = (double)NC_FILL_BYTE; break; + case NC_SHORT: fill = (double)NC_FILL_SHORT; break; + case NC_INT: fill = (double)NC_FILL_INT; break; + case NC_FLOAT: fill = (double)NC_FILL_FLOAT; break; + case NC_DOUBLE: fill = (double)NC_FILL_DOUBLE; break; + case NC_UBYTE: fill = (double)NC_FILL_UBYTE; break; + case NC_USHORT: fill = (double)NC_FILL_USHORT; break; + case NC_UINT: fill = (double)NC_FILL_UINT; break; + case NC_INT64: fill = (double)NC_FILL_INT64; break; + case NC_UINT64: fill = (double)NC_FILL_UINT64; break; + default: assert(0); + } + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + if (var_type[i] == NC_CHAR) { + err = nc_get_var1_text(ncid, i, index, &text); + IF (err != NC_NOERR) + error("get_var1_text_all failed: %s", nc_strerror(err)); + value = text; + } else { + err = nc_get_var1_double(ncid, i, index, &value); + IF (err != NC_NOERR) + error("get_var1_double_all failed: %s", nc_strerror(err)); + } + IF (value != fill && fabs((fill - value)/fill) > DBL_EPSILON) + error("\n\t\t%s Value expected: %-23.17e,\n\t\t read: %-23.17e\n", + var_name[i],fill, value); + ELSE_NOK + } + } + + /* close scratch & create again for test using attribute _FillValue */ + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + err = file_create(scratch, NC_CLOBBER, &ncid); + IF (err != NC_NOERR) { + error("create: %s", nc_strerror(err)); + return nok; + } + def_dims(ncid); + def_vars(ncid); + + /* set _FillValue = 42 for all vars */ + fill = 42; + text = 42; + for (i = 0; i < numVars; i++) { + if (var_type[i] == NC_CHAR) { + err = nc_put_att_text(ncid, i, "_FillValue", 1, &text); + IF (err != NC_NOERR) + error("put_att_text: %s", nc_strerror(err)); + } else { + err = nc_put_att_double(ncid, i, "_FillValue",var_type[i],1,&fill); + IF (err != NC_NOERR) + error("put_att_double: %s", nc_strerror(err)); + } + } + + /* data mode. write records */ + err = nc_enddef(ncid); + IF (err != NC_NOERR) + error("enddef: %s", nc_strerror(err)); + index[0] = NRECS; + + + err = nc_put_var1_text(ncid, varid, index, &text); + IF (err != NC_NOERR) + error("put_var1_text_all: %s", nc_strerror(err)); + + /* get all variables & check all values equal 42 */ + for (i = 0; i < numVars; i++) { + if (var_dimid[i][0] == RECDIM) continue; /* skip record variables */ + for (j = 0; j < var_nels[i]; j++) { + err = toMixedBase(j, var_rank[i], var_shape[i], index); + IF (err != 0) error("error in toMixedBase"); + if (var_type[i] == NC_CHAR) { + err = nc_get_var1_text(ncid, i, index, &text); + IF (err != NC_NOERR) + error("get_var1_text_all failed: %s", nc_strerror(err)); + value = text; + } else { + err = nc_get_var1_double(ncid, i, index, &value); + IF (err != NC_NOERR) + error("get_var1_double_all failed: %s", nc_strerror(err)); + } + IF (value != fill) + error(" %s Value expected: %g, read: %g\n", var_name[i],fill, value); + ELSE_NOK + } + } + + /* enter redef mode and add a new variable, check NC_ELATEFILL */ + err = nc_redef(ncid); + IF (err != NC_NOERR) + error("redef: %s", nc_strerror(err)); + + /* it is not allowed to define fill value when variable already exists */ + err = nc_def_var_fill(ncid, 0, 0, &value); + IF (err != NC_ELATEFILL) + error("redef: expect NC_ELATEFILL but got %s", nc_err_code_name(err)); + err = nc_def_var(ncid, "new_var", NC_INT, 0, NULL, &varid); + IF (err != NC_NOERR) + error("redef: %s", nc_strerror(err)); + err = nc_def_var_fill(ncid, varid, 0, &value); + IF (err != NC_NOERR) + error("def_var_fill: %s", nc_strerror(err)); + + err = nc_close(ncid); + IF (err != NC_NOERR) + error("close: %s", nc_strerror(err)); + err = nc_delete(scratch); + IF (err != NC_NOERR) + error("remove of %s failed", scratch); + + return nok; +} + + +/* This function gets the version of a netCDF file, 1 is for netCDF + classic, 2 for 64-bit offset format, (someday) 3 for HDF5 format, + 5 for 64-bit data format (CDF-5). +*/ +#define MAGIC_NUM_LEN 4 +static +int +nc_get_file_version(char *path, int *version) +{ + int fd; + ssize_t read_len; + char magic[MAGIC_NUM_LEN]; + + /* Need two valid pointers - check for NULL. */ + if (!version || !path) + return NC_EINVAL; + + /* Figure out if this is a netcdf or hdf5 file. */ + fd = open(path, O_RDONLY, 0600); + if (fd == -1) return errno; + + read_len = read(fd, magic, MAGIC_NUM_LEN); + if (-1 == close(fd)) return errno; + + if (read_len == -1) + return errno; + + if (read_len != MAGIC_NUM_LEN) { + printf("Error: reading NC magic string unexpected short read\n"); + return 0; + } + + if (strncmp(magic, "CDF", MAGIC_NUM_LEN-1)==0) { + if (magic[MAGIC_NUM_LEN-1] == NC_FORMAT_CLASSIC || + magic[MAGIC_NUM_LEN-1] == NC_FORMAT_64BIT_OFFSET +#ifdef ENABLE_CDF5 + || magic[MAGIC_NUM_LEN-1] == NC_FORMAT_CDF5 +#endif +) + *version = magic[MAGIC_NUM_LEN-1]; + else + return NC_ENOTNC; + } + /* tomorrow, tomorrow, I love you tomorrow, you're always a day + away! */ + /*if (magic[1] == 'H' && magic[2] == 'D' && magic[3] == 'F') + *version = 3;*/ + return NC_NOERR; +} + +/* + * Test nc_set_default_format + * try with bad default format + * try with NULL old_formatp + * try in data mode, check error + * check that proper set to NC_FILL works for record & non-record variables + * (note that it is not possible to test NC_NOFILL mode!) + * close file & create again for test using attribute _FillValue + */ +int +test_nc_set_default_format(void) +{ + int ncid, nok=0; + int err; + int i; + int version=1; + int old_format; + + /* bad format */ + err = nc_set_default_format(BAD_DEFAULT_FORMAT, &old_format); + IF (err != NC_EINVAL) + error("expecting NC_EINVAL but got %s", nc_err_code_name(err)); + ELSE_NOK + + /* NULL old_formatp */ + err = nc_set_default_format(NC_FORMAT_64BIT_OFFSET, NULL); + IF (err != NC_NOERR) + error("null old_fortmatp: status = %d", err); + ELSE_NOK + + /* Cycle through available formats. */ + + for(i=NC_FORMAT_CLASSIC; i