Index: env-vars =================================================================== --- env-vars (.../trunk) (revision 0) +++ env-vars (.../branches/fileinf_improvement) (revision 531) @@ -0,0 +1,2 @@ +# to incorporate SXP (NC_FILEINF) support: +setenv CPPFLAGS "-DNDEBUG -DUSE_SXP" Index: README-fileinf =================================================================== --- README-fileinf (.../trunk) (revision 0) +++ README-fileinf (.../branches/fileinf_improvement) (revision 531) @@ -0,0 +1,20 @@ + NetCDF performance metrics + -------------------------- + + This version of netCDF uses profiling hooks within netCDF calls +to monitor I/O performance. To activate these hooks, set the environment +variable NC_FILEINF to: + + BASIC minimal information, just file details and a summary of + performance for "access" (file open, define, close etc), + "info" (file/data enquiry), "put" and "get" operations + + YES or NORMAL the above plus summaries of buffer use and data + type conversion performance + + DETAIL all of the above but with detailed info about _which_ + "put" and "get" netcdf calls had what performance + (grouped by call, that is, nc_put_vara and nc_put_varm + are reported separately) + + Index: libsrc/putget.c =================================================================== --- libsrc/putget.c (.../trunk) (revision 531) +++ libsrc/putget.c (.../branches/fileinf_improvement) (revision 531) @@ -1,11556 +0,0 @@ -/* Do not edit this file. It is produced from the corresponding .m4 source */ -/* - * Copyright 1996, University Corporation for Atmospheric Research - * See netcdf/COPYRIGHT file for copying and redistribution conditions. - */ -/* $Id: putget.m4,v 2.60 2006/01/03 20:20:07 russ Exp $ */ - -#include "nc.h" -#include -#include -#include -#include "ncx.h" -#include "fbits.h" -#include "onstack.h" -#ifdef LOCKNUMREC -# include /* for SGI/Cray SHMEM routines */ -# ifdef LN_TEST -# include -# endif -#endif - -#undef MIN /* system may define MIN somewhere and complain */ -#define MIN(mm,nn) (((mm) < (nn)) ? (mm) : (nn)) - -/* #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 */ - -/* - * This is how much space is required by the user, as in - * - * vals = malloc(nel * nctypelen(var.type)); - * ncvarget(cdfid, varid, cor, edg, vals); - */ -int -nctypelen(nc_type type) -{ - switch(type){ - case NC_BYTE : - case NC_CHAR : - return((int)sizeof(char)); - case NC_SHORT : - return(int)(sizeof(short)); - case NC_INT : - return((int)sizeof(int)); - case NC_FLOAT : - return((int)sizeof(float)); - case NC_DOUBLE : - return((int)sizeof(double)); - } - - return -1; -} - - -/* 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 - - - -/* - * Next 6 type specific functions - * Fill a some memory with the default special value. - * Formerly -NC_arrayfill() - */ -static int -NC_fill_schar( - void **xpp, - size_t nelems) /* how many */ -{ - schar fillp[NFILL * sizeof(double)/X_SIZEOF_CHAR]; - - assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); - - { - schar *vp = fillp; /* lower bound of area to be filled */ - const schar *const end = vp + nelems; - while(vp < end) - { - *vp++ = NC_FILL_BYTE; - } - } - return ncx_putn_schar_schar(xpp, nelems, fillp); -} - -static int -NC_fill_char( - void **xpp, - size_t nelems) /* how many */ -{ - char fillp[NFILL * sizeof(double)/X_SIZEOF_CHAR]; - - assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); - - { - char *vp = fillp; /* lower bound of area to be filled */ - const char *const end = vp + nelems; - while(vp < end) - { - *vp++ = NC_FILL_CHAR; - } - } - return ncx_putn_char_char(xpp, nelems, fillp); -} - -static int -NC_fill_short( - void **xpp, - size_t nelems) /* how many */ -{ - short fillp[NFILL * sizeof(double)/X_SIZEOF_SHORT]; - - assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); - - { - short *vp = fillp; /* lower bound of area to be filled */ - const short *const end = vp + nelems; - while(vp < end) - { - *vp++ = NC_FILL_SHORT; - } - } - return ncx_putn_short_short(xpp, nelems, fillp); -} - - -#if (SIZEOF_INT >= X_SIZEOF_INT) -static int -NC_fill_int( - void **xpp, - size_t nelems) /* how many */ -{ - int fillp[NFILL * sizeof(double)/X_SIZEOF_INT]; - - assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); - - { - int *vp = fillp; /* lower bound of area to be filled */ - const int *const end = vp + nelems; - while(vp < end) - { - *vp++ = NC_FILL_INT; - } - } - return ncx_putn_int_int(xpp, nelems, fillp); -} - -#elif SIZEOF_LONG == X_SIZEOF_INT -static int -NC_fill_int( - void **xpp, - size_t nelems) /* how many */ -{ - long fillp[NFILL * sizeof(double)/X_SIZEOF_INT]; - - assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); - - { - long *vp = fillp; /* lower bound of area to be filled */ - const long *const end = vp + nelems; - while(vp < end) - { - *vp++ = NC_FILL_INT; - } - } - return ncx_putn_int_long(xpp, nelems, fillp); -} - -#else -#error "NC_fill_int implementation" -#endif - -static int -NC_fill_float( - void **xpp, - size_t nelems) /* how many */ -{ - float fillp[NFILL * sizeof(double)/X_SIZEOF_FLOAT]; - - assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); - - { - float *vp = fillp; /* lower bound of area to be filled */ - const float *const end = vp + nelems; - while(vp < end) - { - *vp++ = NC_FILL_FLOAT; - } - } - return ncx_putn_float_float(xpp, nelems, fillp); -} - -static int -NC_fill_double( - void **xpp, - size_t nelems) /* how many */ -{ - double fillp[NFILL * sizeof(double)/X_SIZEOF_DOUBLE]; - - assert(nelems <= sizeof(fillp)/sizeof(fillp[0])); - - { - double *vp = fillp; /* lower bound of area to be filled */ - const double *const end = vp + nelems; - while(vp < end) - { - *vp++ = NC_FILL_DOUBLE; - } - } - return ncx_putn_double_double(xpp, nelems, fillp); -} - - - -/* - * 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. - * Formerly -xdr_NC_fill() - */ -int -fill_NC_var(NC *ncp, const NC_var *varp, 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; - size_t remaining = varp->len; - - 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; - 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; - assert(chunksz % X_ALIGN == 0); - - status = ncp->nciop->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 = ncp->nciop->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(NC *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, 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(NC *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 = ncp->nciop->get(ncp->nciop, offset, varp->xsz, - RGN_WRITE, &xp); - if(status != NC_NOERR) - return status; - (void)memset(xp, 0, varp->xsz); - status = ncp->nciop->rel(ncp->nciop, offset, RGN_MODIFIED); - } - return status; -} -#endif /* TOUCH_LAST */ - - -/* - * Ensure that the netcdf file has 'numrecs' records, - * add records and fill as neccessary. - */ -static int -NCvnrecs(NC *ncp, size_t numrecs) -{ - int status = NC_NOERR; -#ifdef LOCKNUMREC - ushmem_t myticket = 0, nowserving = 0; - ushmem_t numpe = (ushmem_t) _num_pes(); - - /* get ticket and wait */ - myticket = shmem_short_finc((shmem_t *) ncp->lock + LOCKNUMREC_LOCK, - ncp->lock[LOCKNUMREC_BASEPE]); -#ifdef LN_TEST - fprintf(stderr,"%d of %d : ticket = %hu\n", - _my_pe(), _num_pes(), myticket); -#endif - do { - shmem_short_get((shmem_t *) &nowserving, - (shmem_t *) ncp->lock + LOCKNUMREC_SERVING, 1, - ncp->lock[LOCKNUMREC_BASEPE]); -#ifdef LN_TEST - fprintf(stderr,"%d of %d : serving = %hu\n", - _my_pe(), _num_pes(), nowserving); -#endif - /* work-around for non-unique tickets */ - if (nowserving > myticket && nowserving < myticket + numpe ) { - /* get a new ticket ... you've been bypassed */ - /* and handle the unlikely wrap-around effect */ - myticket = shmem_short_finc( - (shmem_t *) ncp->lock + LOCKNUMREC_LOCK, - ncp->lock[LOCKNUMREC_BASEPE]); -#ifdef LN_TEST - fprintf(stderr,"%d of %d : new ticket = %hu\n", - _my_pe(), _num_pes(), myticket); -#endif - } - } while(nowserving != myticket); - /* now our turn to check & update value */ -#endif - - 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 - { - /* Fill each record out to numrecs */ - size_t cur_nrecs; - 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; - } - - if(NC_doNsync(ncp)) - { - status = write_numrecs(ncp); - } - - } -common_return: -#ifdef LOCKNUMREC - /* finished with our lock - increment serving number */ - (void) shmem_short_finc((shmem_t *) ncp->lock + LOCKNUMREC_SERVING, - ncp->lock[LOCKNUMREC_BASEPE]); -#endif - return status; -} - - -/* - * Check whether 'coord' values are valid for the variable. - */ -static int -NCcoordck(NC *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_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 NC *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)) - { - start++; - edges++; - shp++; - } - - for(; start < end; start++, edges++, shp++) - { - /* 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 NC *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]; - - size_t *up = varp->dsizes +1; - const size_t *ip = coord; - const size_t *const end = varp->dsizes + varp->ndims; - - if(IS_RECVAR(varp)) - up++, ip++; - - for(; up < end; up++, ip++) - lcoord += *up * *ip; - - lcoord *= varp->xsz; - - if(IS_RECVAR(varp)) - lcoord += (off_t)(*coord) * ncp->recsize; - - lcoord += varp->begin; - return lcoord; - } -} - - - -static int -putNCvx_char_char(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const char *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_char_char(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - - -static int -putNCvx_schar_schar(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const schar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_schar_schar(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_schar_uchar(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const uchar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_schar_uchar(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_schar_short(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const short *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_schar_short(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_schar_int(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const int *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_schar_int(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_schar_long(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const long *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_schar_long(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_schar_float(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const float *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_schar_float(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_schar_double(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const double *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_schar_double(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - - -static int -putNCvx_short_schar(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const schar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_short_schar(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_short_uchar(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const uchar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_short_uchar(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_short_short(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const short *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_short_short(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_short_int(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const int *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_short_int(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_short_long(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const long *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_short_long(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_short_float(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const float *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_short_float(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_short_double(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const double *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_short_double(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - - -static int -putNCvx_int_schar(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const schar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_int_schar(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_int_uchar(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const uchar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_int_uchar(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_int_short(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const short *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_int_short(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_int_int(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const int *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_int_int(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_int_long(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const long *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_int_long(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_int_float(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const float *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_int_float(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_int_double(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const double *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_int_double(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - - -static int -putNCvx_float_schar(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const schar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_float_schar(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_float_uchar(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const uchar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_float_uchar(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_float_short(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const short *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_float_short(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_float_int(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const int *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_float_int(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_float_long(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const long *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_float_long(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_float_float(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const float *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_float_float(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_float_double(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const double *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_float_double(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - - -static int -putNCvx_double_schar(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const schar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_double_schar(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_double_uchar(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const uchar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_double_uchar(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_double_short(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const short *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_double_short(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_double_int(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const int *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_double_int(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_double_long(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const long *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_double_long(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_double_float(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const float *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_double_float(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - -static int -putNCvx_double_double(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const double *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nput = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_putn_double_double(&xp, nput, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - { - /* not fatal to the loop */ - status = lstatus; - } - - (void) ncp->nciop->rel(ncp->nciop, offset, - RGN_MODIFIED); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nput; - - } - - return status; -} - - - - -static int -putNCv_text(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const char *value) -{ - if(varp->type != NC_CHAR) - return NC_ECHAR; - return putNCvx_char_char(ncp, varp, start, nelems, value); -} - -static int -putNCv_schar(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const schar *value) -{ - switch(varp->type){ - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return putNCvx_schar_schar(ncp, varp, start, nelems, - value); - case NC_SHORT: - return putNCvx_short_schar(ncp, varp, start, nelems, - value); - case NC_INT: - return putNCvx_int_schar(ncp, varp, start, nelems, - value); - case NC_FLOAT: - return putNCvx_float_schar(ncp, varp, start, nelems, - value); - case NC_DOUBLE: - return putNCvx_double_schar(ncp, varp, start, nelems, - value); - } - return NC_EBADTYPE; -} - -static int -putNCv_uchar(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const uchar *value) -{ - switch(varp->type){ - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return putNCvx_schar_uchar(ncp, varp, start, nelems, - value); - case NC_SHORT: - return putNCvx_short_uchar(ncp, varp, start, nelems, - value); - case NC_INT: - return putNCvx_int_uchar(ncp, varp, start, nelems, - value); - case NC_FLOAT: - return putNCvx_float_uchar(ncp, varp, start, nelems, - value); - case NC_DOUBLE: - return putNCvx_double_uchar(ncp, varp, start, nelems, - value); - } - return NC_EBADTYPE; -} - -static int -putNCv_short(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const short *value) -{ - switch(varp->type){ - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return putNCvx_schar_short(ncp, varp, start, nelems, - value); - case NC_SHORT: - return putNCvx_short_short(ncp, varp, start, nelems, - value); - case NC_INT: - return putNCvx_int_short(ncp, varp, start, nelems, - value); - case NC_FLOAT: - return putNCvx_float_short(ncp, varp, start, nelems, - value); - case NC_DOUBLE: - return putNCvx_double_short(ncp, varp, start, nelems, - value); - } - return NC_EBADTYPE; -} - -static int -putNCv_int(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const int *value) -{ - switch(varp->type){ - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return putNCvx_schar_int(ncp, varp, start, nelems, - value); - case NC_SHORT: - return putNCvx_short_int(ncp, varp, start, nelems, - value); - case NC_INT: - return putNCvx_int_int(ncp, varp, start, nelems, - value); - case NC_FLOAT: - return putNCvx_float_int(ncp, varp, start, nelems, - value); - case NC_DOUBLE: - return putNCvx_double_int(ncp, varp, start, nelems, - value); - } - return NC_EBADTYPE; -} - -static int -putNCv_long(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const long *value) -{ - switch(varp->type){ - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return putNCvx_schar_long(ncp, varp, start, nelems, - value); - case NC_SHORT: - return putNCvx_short_long(ncp, varp, start, nelems, - value); - case NC_INT: - return putNCvx_int_long(ncp, varp, start, nelems, - value); - case NC_FLOAT: - return putNCvx_float_long(ncp, varp, start, nelems, - value); - case NC_DOUBLE: - return putNCvx_double_long(ncp, varp, start, nelems, - value); - } - return NC_EBADTYPE; -} - -static int -putNCv_float(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const float *value) -{ - switch(varp->type){ - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return putNCvx_schar_float(ncp, varp, start, nelems, - value); - case NC_SHORT: - return putNCvx_short_float(ncp, varp, start, nelems, - value); - case NC_INT: - return putNCvx_int_float(ncp, varp, start, nelems, - value); - case NC_FLOAT: - return putNCvx_float_float(ncp, varp, start, nelems, - value); - case NC_DOUBLE: - return putNCvx_double_float(ncp, varp, start, nelems, - value); - } - return NC_EBADTYPE; -} - -static int -putNCv_double(NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, const double *value) -{ - switch(varp->type){ - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return putNCvx_schar_double(ncp, varp, start, nelems, - value); - case NC_SHORT: - return putNCvx_short_double(ncp, varp, start, nelems, - value); - case NC_INT: - return putNCvx_int_double(ncp, varp, start, nelems, - value); - case NC_FLOAT: - return putNCvx_float_double(ncp, varp, start, nelems, - value); - case NC_DOUBLE: - return putNCvx_double_double(ncp, varp, start, nelems, - value); - } - return NC_EBADTYPE; -} - - - - -static int -getNCvx_char_char(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, char *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_char_char(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - - -static int -getNCvx_schar_schar(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, schar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_schar_schar(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_schar_uchar(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, uchar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_schar_uchar(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_schar_short(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, short *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_schar_short(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_schar_int(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, int *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_schar_int(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_schar_long(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, long *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_schar_long(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_schar_float(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, float *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_schar_float(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_schar_double(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, double *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_schar_double(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - - -static int -getNCvx_short_schar(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, schar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_short_schar(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_short_uchar(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, uchar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_short_uchar(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_short_short(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, short *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_short_short(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_short_int(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, int *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_short_int(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_short_long(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, long *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_short_long(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_short_float(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, float *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_short_float(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_short_double(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, double *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_short_double(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - - -static int -getNCvx_int_schar(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, schar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_int_schar(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_int_uchar(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, uchar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_int_uchar(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_int_short(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, short *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_int_short(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_int_int(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, int *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_int_int(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_int_long(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, long *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_int_long(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_int_float(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, float *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_int_float(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_int_double(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, double *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_int_double(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - - -static int -getNCvx_float_schar(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, schar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_float_schar(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_float_uchar(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, uchar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_float_uchar(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_float_short(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, short *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_float_short(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_float_int(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, int *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_float_int(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_float_long(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, long *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_float_long(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_float_float(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, float *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_float_float(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_float_double(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, double *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_float_double(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - - -static int -getNCvx_double_schar(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, schar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_double_schar(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_double_uchar(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, uchar *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_double_uchar(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_double_short(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, short *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_double_short(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_double_int(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, int *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_double_int(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_double_long(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, long *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_double_long(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_double_float(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, float *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_double_float(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - -static int -getNCvx_double_double(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, double *value) -{ - off_t offset = NC_varoffset(ncp, varp, start); - size_t remaining = varp->xsz * nelems; - int status = NC_NOERR; - const void *xp; - - if(nelems == 0) - return NC_NOERR; - - assert(value != NULL); - - for(;;) - { - size_t extent = MIN(remaining, ncp->chunk); - size_t nget = ncx_howmany(varp->type, extent); - - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - 0, (void **)&xp); /* cast away const */ - if(lstatus != NC_NOERR) - return lstatus; - - lstatus = ncx_getn_double_double(&xp, nget, value); - if(lstatus != NC_NOERR && status == NC_NOERR) - status = lstatus; - - (void) ncp->nciop->rel(ncp->nciop, offset, 0); - - remaining -= extent; - if(remaining == 0) - break; /* normal loop exit */ - offset += extent; - value += nget; - } - - return status; -} - - - - -static int -getNCv_schar(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, schar *value) -{ - switch(varp->type){ - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return getNCvx_schar_schar(ncp, varp, start, nelems, - value); - case NC_SHORT: - return getNCvx_short_schar(ncp, varp, start, nelems, - value); - case NC_INT: - return getNCvx_int_schar(ncp, varp, start, nelems, - value); - case NC_FLOAT: - return getNCvx_float_schar(ncp, varp, start, nelems, - value); - case NC_DOUBLE: - return getNCvx_double_schar(ncp, varp, start, nelems, - value); - } - return NC_EBADTYPE; -} - -static int -getNCv_uchar(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, uchar *value) -{ - switch(varp->type){ - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return getNCvx_schar_uchar(ncp, varp, start, nelems, - value); - case NC_SHORT: - return getNCvx_short_uchar(ncp, varp, start, nelems, - value); - case NC_INT: - return getNCvx_int_uchar(ncp, varp, start, nelems, - value); - case NC_FLOAT: - return getNCvx_float_uchar(ncp, varp, start, nelems, - value); - case NC_DOUBLE: - return getNCvx_double_uchar(ncp, varp, start, nelems, - value); - } - return NC_EBADTYPE; -} - -static int -getNCv_short(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, short *value) -{ - switch(varp->type){ - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return getNCvx_schar_short(ncp, varp, start, nelems, - value); - case NC_SHORT: - return getNCvx_short_short(ncp, varp, start, nelems, - value); - case NC_INT: - return getNCvx_int_short(ncp, varp, start, nelems, - value); - case NC_FLOAT: - return getNCvx_float_short(ncp, varp, start, nelems, - value); - case NC_DOUBLE: - return getNCvx_double_short(ncp, varp, start, nelems, - value); - } - return NC_EBADTYPE; -} - -static int -getNCv_int(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, int *value) -{ - switch(varp->type){ - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return getNCvx_schar_int(ncp, varp, start, nelems, - value); - case NC_SHORT: - return getNCvx_short_int(ncp, varp, start, nelems, - value); - case NC_INT: - return getNCvx_int_int(ncp, varp, start, nelems, - value); - case NC_FLOAT: - return getNCvx_float_int(ncp, varp, start, nelems, - value); - case NC_DOUBLE: - return getNCvx_double_int(ncp, varp, start, nelems, - value); - } - return NC_EBADTYPE; -} - -static int -getNCv_long(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, long *value) -{ - switch(varp->type){ - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return getNCvx_schar_long(ncp, varp, start, nelems, - value); - case NC_SHORT: - return getNCvx_short_long(ncp, varp, start, nelems, - value); - case NC_INT: - return getNCvx_int_long(ncp, varp, start, nelems, - value); - case NC_FLOAT: - return getNCvx_float_long(ncp, varp, start, nelems, - value); - case NC_DOUBLE: - return getNCvx_double_long(ncp, varp, start, nelems, - value); - } - return NC_EBADTYPE; -} - -static int -getNCv_float(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, float *value) -{ - switch(varp->type){ - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return getNCvx_schar_float(ncp, varp, start, nelems, - value); - case NC_SHORT: - return getNCvx_short_float(ncp, varp, start, nelems, - value); - case NC_INT: - return getNCvx_int_float(ncp, varp, start, nelems, - value); - case NC_FLOAT: - return getNCvx_float_float(ncp, varp, start, nelems, - value); - case NC_DOUBLE: - return getNCvx_double_float(ncp, varp, start, nelems, - value); - } - return NC_EBADTYPE; -} - -static int -getNCv_double(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, double *value) -{ - switch(varp->type){ - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return getNCvx_schar_double(ncp, varp, start, nelems, - value); - case NC_SHORT: - return getNCvx_short_double(ncp, varp, start, nelems, - value); - case NC_INT: - return getNCvx_int_double(ncp, varp, start, nelems, - value); - case NC_FLOAT: - return getNCvx_float_double(ncp, varp, start, nelems, - value); - case NC_DOUBLE: - return getNCvx_double_double(ncp, varp, start, nelems, - value); - } - return NC_EBADTYPE; -} - - - -static int -getNCv_text(const NC *ncp, const NC_var *varp, - const size_t *start, size_t nelems, char *value) -{ - if(varp->type != NC_CHAR) - return NC_ECHAR; - return getNCvx_char_char(ncp, varp, start, nelems, value); -} - - -/* - * Copy 'nbytes' contiguous external values - * from ('inncp', invp', inncoord') - * to ('outncp', 'outvp', 'outcoord') - * 'inncp' shouldn't be the same as 'outncp'. - * Used only by ncvarcopy() - */ -static int -NCxvarcpy(NC *inncp, NC_var *invp, size_t *incoord, - NC *outncp, NC_var *outvp, size_t *outcoord, size_t nbytes) -{ - int status; - off_t inoffset = NC_varoffset(inncp, invp, incoord); - off_t outoffset = NC_varoffset(outncp, outvp, outcoord); - void *inxp; - void *outxp; - const size_t chunk = MIN(inncp->chunk, outncp->chunk); - - do { - const size_t extent = MIN(nbytes, chunk); - - status = inncp->nciop->get(inncp->nciop, inoffset, extent, - 0, &inxp); - if(status != NC_NOERR) - return status; - - status = outncp->nciop->get(outncp->nciop, outoffset, extent, - RGN_WRITE, &outxp); - if(status != NC_NOERR) - { - (void) inncp->nciop->rel(inncp->nciop, inoffset, 0); - break; - } - - (void) memcpy(outxp, inxp, extent); - - status = outncp->nciop->rel(outncp->nciop, outoffset, - RGN_MODIFIED); - (void) inncp->nciop->rel(inncp->nciop, inoffset, 0); - - nbytes -= extent; - if(nbytes == 0) - break; /* normal loop exit */ - inoffset += extent; - outoffset += extent; - - } while (status == NC_NOERR); - - return status; -} - - -/* - * 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 NC *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 - - - - -/* Public */ - - -int -nc_put_var1_text(int ncid, int varid, const size_t *coord, - const char *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type != NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *coord +1); - if(status != NC_NOERR) - return status; - } - - return putNCv_text(ncp, varp, coord, 1, value); -} - - -int -nc_put_var1_uchar(int ncid, int varid, const size_t *coord, - const uchar *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *coord +1); - if(status != NC_NOERR) - return status; - } - - return putNCv_uchar(ncp, varp, coord, 1, value); -} - -int -nc_put_var1_schar(int ncid, int varid, const size_t *coord, - const schar *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *coord +1); - if(status != NC_NOERR) - return status; - } - - return putNCv_schar(ncp, varp, coord, 1, value); -} - -int -nc_put_var1_short(int ncid, int varid, const size_t *coord, - const short *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *coord +1); - if(status != NC_NOERR) - return status; - } - - return putNCv_short(ncp, varp, coord, 1, value); -} - -int -nc_put_var1_int(int ncid, int varid, const size_t *coord, - const int *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *coord +1); - if(status != NC_NOERR) - return status; - } - - return putNCv_int(ncp, varp, coord, 1, value); -} - -int -nc_put_var1_long(int ncid, int varid, const size_t *coord, - const long *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *coord +1); - if(status != NC_NOERR) - return status; - } - - return putNCv_long(ncp, varp, coord, 1, value); -} - -int -nc_put_var1_float(int ncid, int varid, const size_t *coord, - const float *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *coord +1); - if(status != NC_NOERR) - return status; - } - - return putNCv_float(ncp, varp, coord, 1, value); -} - -int -nc_put_var1_double(int ncid, int varid, const size_t *coord, - const double *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *coord +1); - if(status != NC_NOERR) - return status; - } - - return putNCv_double(ncp, varp, coord, 1, value); -} - - - -int -nc_get_var1_text(int ncid, int varid, const size_t *coord, char *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type != NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - return getNCv_text(ncp, varp, coord, 1, value); -} - - -int -nc_get_var1_uchar(int ncid, int varid, const size_t *coord, uchar *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - return getNCv_uchar(ncp, varp, coord, 1, value); -} - -int -nc_get_var1_schar(int ncid, int varid, const size_t *coord, schar *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - return getNCv_schar(ncp, varp, coord, 1, value); -} - -int -nc_get_var1_short(int ncid, int varid, const size_t *coord, short *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - return getNCv_short(ncp, varp, coord, 1, value); -} - -int -nc_get_var1_int(int ncid, int varid, const size_t *coord, int *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - return getNCv_int(ncp, varp, coord, 1, value); -} - -int -nc_get_var1_long(int ncid, int varid, const size_t *coord, long *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - return getNCv_long(ncp, varp, coord, 1, value); -} - -int -nc_get_var1_float(int ncid, int varid, const size_t *coord, float *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - return getNCv_float(ncp, varp, coord, 1, value); -} - -int -nc_get_var1_double(int ncid, int varid, const size_t *coord, double *value) -{ - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - return getNCv_double(ncp, varp, coord, 1, value); -} - - - -int -nc_put_vara_text(int ncid, int varid, - const size_t *start, const size_t *edges, const char *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type != NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( putNCv_text(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *start + *edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( putNCv_text(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( putNCv_text(ncp, varp, start, iocount, value) ); - } - - 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 = putNCv_text(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - - -int -nc_put_vara_uchar(int ncid, int varid, - const size_t *start, const size_t *edges, const uchar *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( putNCv_uchar(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *start + *edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( putNCv_uchar(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( putNCv_uchar(ncp, varp, start, iocount, value) ); - } - - 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 = putNCv_uchar(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - -int -nc_put_vara_schar(int ncid, int varid, - const size_t *start, const size_t *edges, const schar *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( putNCv_schar(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *start + *edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( putNCv_schar(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( putNCv_schar(ncp, varp, start, iocount, value) ); - } - - 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 = putNCv_schar(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - -int -nc_put_vara_short(int ncid, int varid, - const size_t *start, const size_t *edges, const short *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( putNCv_short(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *start + *edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( putNCv_short(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( putNCv_short(ncp, varp, start, iocount, value) ); - } - - 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 = putNCv_short(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - -int -nc_put_vara_int(int ncid, int varid, - const size_t *start, const size_t *edges, const int *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( putNCv_int(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *start + *edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( putNCv_int(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( putNCv_int(ncp, varp, start, iocount, value) ); - } - - 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 = putNCv_int(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - -int -nc_put_vara_long(int ncid, int varid, - const size_t *start, const size_t *edges, const long *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( putNCv_long(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *start + *edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( putNCv_long(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( putNCv_long(ncp, varp, start, iocount, value) ); - } - - 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 = putNCv_long(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - -int -nc_put_vara_float(int ncid, int varid, - const size_t *start, const size_t *edges, const float *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( putNCv_float(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *start + *edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( putNCv_float(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( putNCv_float(ncp, varp, start, iocount, value) ); - } - - 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 = putNCv_float(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - -int -nc_put_vara_double(int ncid, int varid, - const size_t *start, const size_t *edges, const double *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( putNCv_double(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *start + *edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( putNCv_double(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( putNCv_double(ncp, varp, start, iocount, value) ); - } - - 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 = putNCv_double(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - - - - -int -nc_get_vara_text(int ncid, int varid, - const size_t *start, const size_t *edges, char *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type != NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( getNCv_text(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - if(*start + *edges > NC_get_numrecs(ncp)) - return NC_EEDGE; - if(varp->ndims == 1 && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( getNCv_text(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( getNCv_text(ncp, varp, start, iocount, value) ); - } - - 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 = getNCv_text(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - - -int -nc_get_vara_uchar(int ncid, int varid, - const size_t *start, const size_t *edges, uchar *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( getNCv_uchar(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - if(*start + *edges > NC_get_numrecs(ncp)) - return NC_EEDGE; - if(varp->ndims == 1 && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( getNCv_uchar(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( getNCv_uchar(ncp, varp, start, iocount, value) ); - } - - 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 = getNCv_uchar(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - -int -nc_get_vara_schar(int ncid, int varid, - const size_t *start, const size_t *edges, schar *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( getNCv_schar(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - if(*start + *edges > NC_get_numrecs(ncp)) - return NC_EEDGE; - if(varp->ndims == 1 && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( getNCv_schar(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( getNCv_schar(ncp, varp, start, iocount, value) ); - } - - 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 = getNCv_schar(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - -int -nc_get_vara_short(int ncid, int varid, - const size_t *start, const size_t *edges, short *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( getNCv_short(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - if(*start + *edges > NC_get_numrecs(ncp)) - return NC_EEDGE; - if(varp->ndims == 1 && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( getNCv_short(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( getNCv_short(ncp, varp, start, iocount, value) ); - } - - 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 = getNCv_short(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - -int -nc_get_vara_int(int ncid, int varid, - const size_t *start, const size_t *edges, int *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( getNCv_int(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - if(*start + *edges > NC_get_numrecs(ncp)) - return NC_EEDGE; - if(varp->ndims == 1 && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( getNCv_int(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( getNCv_int(ncp, varp, start, iocount, value) ); - } - - 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 = getNCv_int(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - -int -nc_get_vara_long(int ncid, int varid, - const size_t *start, const size_t *edges, long *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( getNCv_long(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - if(*start + *edges > NC_get_numrecs(ncp)) - return NC_EEDGE; - if(varp->ndims == 1 && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( getNCv_long(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( getNCv_long(ncp, varp, start, iocount, value) ); - } - - 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 = getNCv_long(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - -int -nc_get_vara_float(int ncid, int varid, - const size_t *start, const size_t *edges, float *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( getNCv_float(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - if(*start + *edges > NC_get_numrecs(ncp)) - return NC_EEDGE; - if(varp->ndims == 1 && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( getNCv_float(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( getNCv_float(ncp, varp, start, iocount, value) ); - } - - 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 = getNCv_float(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - -int -nc_get_vara_double(int ncid, int varid, - const size_t *start, const size_t *edges, double *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( getNCv_double(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - if(*start + *edges > NC_get_numrecs(ncp)) - return NC_EEDGE; - if(varp->ndims == 1 && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( getNCv_double(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( getNCv_double(ncp, varp, start, iocount, value) ); - } - - 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 = getNCv_double(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; -} - - - -#if defined(__cplusplus) -/* C++ consts default to internal linkage and must be initialized */ -const size_t coord_zero[NC_MAX_VAR_DIMS] = {0}; -#else -static const size_t coord_zero[NC_MAX_VAR_DIMS]; -#endif - - -int -nc_put_var_text(int ncid, int varid, const char *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type != NC_CHAR) - return NC_ECHAR; - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( putNCv_text(ncp, varp, &zed, 1, value) ); - } - - if(!IS_RECVAR(varp)) - { - return(putNCv_text(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(putNCv_text(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = putNCv_text(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - - -int -nc_put_var_uchar(int ncid, int varid, const uchar *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( putNCv_uchar(ncp, varp, &zed, 1, value) ); - } - - if(!IS_RECVAR(varp)) - { - return(putNCv_uchar(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(putNCv_uchar(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = putNCv_uchar(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - -int -nc_put_var_schar(int ncid, int varid, const schar *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( putNCv_schar(ncp, varp, &zed, 1, value) ); - } - - if(!IS_RECVAR(varp)) - { - return(putNCv_schar(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(putNCv_schar(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = putNCv_schar(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - -int -nc_put_var_short(int ncid, int varid, const short *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( putNCv_short(ncp, varp, &zed, 1, value) ); - } - - if(!IS_RECVAR(varp)) - { - return(putNCv_short(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(putNCv_short(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = putNCv_short(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - -int -nc_put_var_int(int ncid, int varid, const int *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( putNCv_int(ncp, varp, &zed, 1, value) ); - } - - if(!IS_RECVAR(varp)) - { - return(putNCv_int(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(putNCv_int(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = putNCv_int(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - -int -nc_put_var_long(int ncid, int varid, const long *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( putNCv_long(ncp, varp, &zed, 1, value) ); - } - - if(!IS_RECVAR(varp)) - { - return(putNCv_long(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(putNCv_long(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = putNCv_long(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - -int -nc_put_var_float(int ncid, int varid, const float *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( putNCv_float(ncp, varp, &zed, 1, value) ); - } - - if(!IS_RECVAR(varp)) - { - return(putNCv_float(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(putNCv_float(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = putNCv_float(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - -int -nc_put_var_double(int ncid, int varid, const double *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( putNCv_double(ncp, varp, &zed, 1, value) ); - } - - if(!IS_RECVAR(varp)) - { - return(putNCv_double(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(putNCv_double(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = putNCv_double(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - - - - -int -nc_get_var_text(int ncid, int varid, char *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( getNCv_text(ncp, varp, &zed, 1, value) ); - } - - if(varp->type != NC_CHAR) - return NC_ECHAR; - - - if(!IS_RECVAR(varp)) - { - return(getNCv_text(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(getNCv_text(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = getNCv_text(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - - -int -nc_get_var_uchar(int ncid, int varid, uchar *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( getNCv_uchar(ncp, varp, &zed, 1, value) ); - } - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - - if(!IS_RECVAR(varp)) - { - return(getNCv_uchar(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(getNCv_uchar(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = getNCv_uchar(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - -int -nc_get_var_schar(int ncid, int varid, schar *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( getNCv_schar(ncp, varp, &zed, 1, value) ); - } - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - - if(!IS_RECVAR(varp)) - { - return(getNCv_schar(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(getNCv_schar(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = getNCv_schar(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - -int -nc_get_var_short(int ncid, int varid, short *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( getNCv_short(ncp, varp, &zed, 1, value) ); - } - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - - if(!IS_RECVAR(varp)) - { - return(getNCv_short(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(getNCv_short(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = getNCv_short(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - -int -nc_get_var_int(int ncid, int varid, int *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( getNCv_int(ncp, varp, &zed, 1, value) ); - } - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - - if(!IS_RECVAR(varp)) - { - return(getNCv_int(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(getNCv_int(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = getNCv_int(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - -int -nc_get_var_long(int ncid, int varid, long *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( getNCv_long(ncp, varp, &zed, 1, value) ); - } - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - - if(!IS_RECVAR(varp)) - { - return(getNCv_long(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(getNCv_long(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = getNCv_long(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - -int -nc_get_var_float(int ncid, int varid, float *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( getNCv_float(ncp, varp, &zed, 1, value) ); - } - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - - if(!IS_RECVAR(varp)) - { - return(getNCv_float(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(getNCv_float(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = getNCv_float(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - -int -nc_get_var_double(int ncid, int varid, double *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->ndims == 0) /* scalar variable */ - { - const size_t zed = 0; - return( getNCv_double(ncp, varp, &zed, 1, value) ); - } - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - - if(!IS_RECVAR(varp)) - { - return(getNCv_double(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(getNCv_double(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = getNCv_double(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} - - - -/* Begin putgetg.c */ - - - -int -nc_get_vars_text ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - char *value) -{ - return nc_get_varm_text (ncid, varid, start, edges, - stride, 0, value); -} - - -int -nc_get_vars_uchar ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - uchar *value) -{ - return nc_get_varm_uchar (ncid, varid, start, edges, - stride, 0, value); -} - -int -nc_get_vars_schar ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - schar *value) -{ - return nc_get_varm_schar (ncid, varid, start, edges, - stride, 0, value); -} - -int -nc_get_vars_short ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - short *value) -{ - return nc_get_varm_short (ncid, varid, start, edges, - stride, 0, value); -} - -int -nc_get_vars_int ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - int *value) -{ - return nc_get_varm_int (ncid, varid, start, edges, - stride, 0, value); -} - -int -nc_get_vars_long ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - long *value) -{ - return nc_get_varm_long (ncid, varid, start, edges, - stride, 0, value); -} - -int -nc_get_vars_float ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - float *value) -{ - return nc_get_varm_float (ncid, varid, start, edges, - stride, 0, value); -} - -int -nc_get_vars_double ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - double *value) -{ - return nc_get_varm_double (ncid, varid, start, edges, - stride, 0, value); -} - - - - -int -nc_put_vars_text ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - const char *value) -{ - return nc_put_varm_text (ncid, varid, start, edges, - stride, 0, value); -} - - -int -nc_put_vars_uchar ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - const uchar *value) -{ - return nc_put_varm_uchar (ncid, varid, start, edges, - stride, 0, value); -} - -int -nc_put_vars_schar ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - const schar *value) -{ - return nc_put_varm_schar (ncid, varid, start, edges, - stride, 0, value); -} - -int -nc_put_vars_short ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - const short *value) -{ - return nc_put_varm_short (ncid, varid, start, edges, - stride, 0, value); -} - -int -nc_put_vars_int ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - const int *value) -{ - return nc_put_varm_int (ncid, varid, start, edges, - stride, 0, value); -} - -int -nc_put_vars_long ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - const long *value) -{ - return nc_put_varm_long (ncid, varid, start, edges, - stride, 0, value); -} - -int -nc_put_vars_float ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - const float *value) -{ - return nc_put_varm_float (ncid, varid, start, edges, - stride, 0, value); -} - -int -nc_put_vars_double ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - const double *value) -{ - return nc_put_varm_double (ncid, varid, start, edges, - stride, 0, value); -} - - - -/* - * Generalized hyperslab input. - */ - -int -nc_get_varm_text(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, - const ptrdiff_t *map, - char *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type != NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return getNCv_text (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = maxidim; idim >= 0; --idim) - { - size_t dimlen = - idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - : varp->shape[idim]; - if (mystart[idim] >= dimlen) - { - status = NC_EINVALCOORDS; - goto done; - } - - if (mystart[idim] + myedges[idim] > dimlen) - { - status = NC_EEDGE; - goto done; - } - - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_get_vara_text() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_get_vara_text (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - - -int -nc_get_varm_uchar(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, - const ptrdiff_t *map, - uchar *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return getNCv_uchar (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = maxidim; idim >= 0; --idim) - { - size_t dimlen = - idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - : varp->shape[idim]; - if (mystart[idim] >= dimlen) - { - status = NC_EINVALCOORDS; - goto done; - } - - if (mystart[idim] + myedges[idim] > dimlen) - { - status = NC_EEDGE; - goto done; - } - - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_get_vara_uchar() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_get_vara_uchar (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - -int -nc_get_varm_schar(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, - const ptrdiff_t *map, - schar *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return getNCv_schar (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = maxidim; idim >= 0; --idim) - { - size_t dimlen = - idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - : varp->shape[idim]; - if (mystart[idim] >= dimlen) - { - status = NC_EINVALCOORDS; - goto done; - } - - if (mystart[idim] + myedges[idim] > dimlen) - { - status = NC_EEDGE; - goto done; - } - - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_get_vara_schar() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_get_vara_schar (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - -int -nc_get_varm_short(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, - const ptrdiff_t *map, - short *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return getNCv_short (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = maxidim; idim >= 0; --idim) - { - size_t dimlen = - idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - : varp->shape[idim]; - if (mystart[idim] >= dimlen) - { - status = NC_EINVALCOORDS; - goto done; - } - - if (mystart[idim] + myedges[idim] > dimlen) - { - status = NC_EEDGE; - goto done; - } - - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_get_vara_short() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_get_vara_short (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - -int -nc_get_varm_int(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, - const ptrdiff_t *map, - int *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return getNCv_int (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = maxidim; idim >= 0; --idim) - { - size_t dimlen = - idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - : varp->shape[idim]; - if (mystart[idim] >= dimlen) - { - status = NC_EINVALCOORDS; - goto done; - } - - if (mystart[idim] + myedges[idim] > dimlen) - { - status = NC_EEDGE; - goto done; - } - - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_get_vara_int() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_get_vara_int (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - -int -nc_get_varm_long(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, - const ptrdiff_t *map, - long *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return getNCv_long (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = maxidim; idim >= 0; --idim) - { - size_t dimlen = - idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - : varp->shape[idim]; - if (mystart[idim] >= dimlen) - { - status = NC_EINVALCOORDS; - goto done; - } - - if (mystart[idim] + myedges[idim] > dimlen) - { - status = NC_EEDGE; - goto done; - } - - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_get_vara_long() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_get_vara_long (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - -int -nc_get_varm_float(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, - const ptrdiff_t *map, - float *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return getNCv_float (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = maxidim; idim >= 0; --idim) - { - size_t dimlen = - idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - : varp->shape[idim]; - if (mystart[idim] >= dimlen) - { - status = NC_EINVALCOORDS; - goto done; - } - - if (mystart[idim] + myedges[idim] > dimlen) - { - status = NC_EEDGE; - goto done; - } - - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_get_vara_float() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_get_vara_float (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - -int -nc_get_varm_double(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, - const ptrdiff_t *map, - double *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return getNCv_double (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = maxidim; idim >= 0; --idim) - { - size_t dimlen = - idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - : varp->shape[idim]; - if (mystart[idim] >= dimlen) - { - status = NC_EINVALCOORDS; - goto done; - } - - if (mystart[idim] + myedges[idim] > dimlen) - { - status = NC_EEDGE; - goto done; - } - - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_get_vara_double() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_get_vara_double (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - - -#ifdef NO_NETCDF_2 -extern int -nctypelen(nc_type datatype); -#endif - - -/* - * Generalized hyperslab output. - */ - -int -nc_put_varm_text(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, const ptrdiff_t *map, - const char *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - if (NC_readonly (ncp)) - return NC_EPERM; - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type != NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return putNCv_text (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = IS_RECVAR (varp); idim < maxidim; ++idim) - { - if (mystart[idim] > varp->shape[idim]) - { - status = NC_EINVALCOORDS; - goto done; - } - if (mystart[idim] + myedges[idim] > varp->shape[idim]) - { - status = NC_EEDGE; - goto done; - } - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_put_vara_text() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_put_vara_text (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - - -int -nc_put_varm_uchar(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, const ptrdiff_t *map, - const uchar *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - if (NC_readonly (ncp)) - return NC_EPERM; - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return putNCv_uchar (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = IS_RECVAR (varp); idim < maxidim; ++idim) - { - if (mystart[idim] > varp->shape[idim]) - { - status = NC_EINVALCOORDS; - goto done; - } - if (mystart[idim] + myedges[idim] > varp->shape[idim]) - { - status = NC_EEDGE; - goto done; - } - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_put_vara_uchar() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_put_vara_uchar (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - -int -nc_put_varm_schar(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, const ptrdiff_t *map, - const schar *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - if (NC_readonly (ncp)) - return NC_EPERM; - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return putNCv_schar (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = IS_RECVAR (varp); idim < maxidim; ++idim) - { - if (mystart[idim] > varp->shape[idim]) - { - status = NC_EINVALCOORDS; - goto done; - } - if (mystart[idim] + myedges[idim] > varp->shape[idim]) - { - status = NC_EEDGE; - goto done; - } - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_put_vara_schar() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_put_vara_schar (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - -int -nc_put_varm_short(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, const ptrdiff_t *map, - const short *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - if (NC_readonly (ncp)) - return NC_EPERM; - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return putNCv_short (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = IS_RECVAR (varp); idim < maxidim; ++idim) - { - if (mystart[idim] > varp->shape[idim]) - { - status = NC_EINVALCOORDS; - goto done; - } - if (mystart[idim] + myedges[idim] > varp->shape[idim]) - { - status = NC_EEDGE; - goto done; - } - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_put_vara_short() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_put_vara_short (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - -int -nc_put_varm_int(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, const ptrdiff_t *map, - const int *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - if (NC_readonly (ncp)) - return NC_EPERM; - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return putNCv_int (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = IS_RECVAR (varp); idim < maxidim; ++idim) - { - if (mystart[idim] > varp->shape[idim]) - { - status = NC_EINVALCOORDS; - goto done; - } - if (mystart[idim] + myedges[idim] > varp->shape[idim]) - { - status = NC_EEDGE; - goto done; - } - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_put_vara_int() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_put_vara_int (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - -int -nc_put_varm_long(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, const ptrdiff_t *map, - const long *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - if (NC_readonly (ncp)) - return NC_EPERM; - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return putNCv_long (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = IS_RECVAR (varp); idim < maxidim; ++idim) - { - if (mystart[idim] > varp->shape[idim]) - { - status = NC_EINVALCOORDS; - goto done; - } - if (mystart[idim] + myedges[idim] > varp->shape[idim]) - { - status = NC_EEDGE; - goto done; - } - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_put_vara_long() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_put_vara_long (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - -int -nc_put_varm_float(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, const ptrdiff_t *map, - const float *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - if (NC_readonly (ncp)) - return NC_EPERM; - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return putNCv_float (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = IS_RECVAR (varp); idim < maxidim; ++idim) - { - if (mystart[idim] > varp->shape[idim]) - { - status = NC_EINVALCOORDS; - goto done; - } - if (mystart[idim] + myedges[idim] > varp->shape[idim]) - { - status = NC_EEDGE; - goto done; - } - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_put_vara_float() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_put_vara_float (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - -int -nc_put_varm_double(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, const ptrdiff_t *map, - const double *value) -{ - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } - - if (NC_readonly (ncp)) - return NC_EPERM; - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - - if(varp->type == NC_CHAR) - return NC_ECHAR; - - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return putNCv_double (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } - - /* - * Check start, edges - */ - for (idim = IS_RECVAR (varp); idim < maxidim; ++idim) - { - if (mystart[idim] > varp->shape[idim]) - { - status = NC_EINVALCOORDS; - goto done; - } - if (mystart[idim] + myedges[idim] > varp->shape[idim]) - { - status = NC_EEDGE; - goto done; - } - } - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvarnc_put_vara_double() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = nc_put_vara_double (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; - -} - - - -/* - * Copy the values of a variable from an input netCDF to an output netCDF. - * Input and output var assummed to have the same shape. - * return -1 on error. - */ -int -nc_copy_var(int ncid_in, int varid, int ncid_out) -{ - int status = NC_NOERR; - NC *inncp, *outncp; - NC_var *invp, *outvp; - - status = NC_check_id(ncid_in, &inncp); - if(status != NC_NOERR) - return status; - - - if(NC_indef(inncp)) - { - return NC_EINDEFINE; - } - - status = NC_check_id(ncid_out, &outncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(outncp)) - { - /* output file isn't writable */ - return NC_EPERM; - } - - if(NC_indef(outncp)) - { - return NC_EINDEFINE; - } - - /* find the variable in the input cdf */ - invp = NC_lookupvar(inncp, varid); - if(invp == NULL) - { - return NC_ENOTVAR; - } - - /* find the variable in the output cdf */ - if(NC_findvar(&outncp->vars, invp->name->cp, &outvp) == -1) - { - return NC_ENOTVAR; - } - - /* can we even attempt to copy without conversion? */ - if(outvp->type != invp->type) - { - return NC_EINVAL; - } - - if( (invp->ndims == 0 && outvp->ndims != 0) - || (invp->ndims != 0 && outvp->ndims == 0) - || (IS_RECVAR(invp) && !IS_RECVAR(outvp)) - || (!IS_RECVAR(invp) && IS_RECVAR(outvp)) - || (invp->len != outvp->len) - ) - { - return NC_EINVAL; - } - - /* - * Check coordinates - */ - { - ALLOC_ONSTACK(coord, size_t, invp->ndims); - const size_t nrecs = NC_get_numrecs(inncp); - (void) memcpy(coord, invp->shape, invp->ndims * sizeof(size_t)); - if(IS_RECVAR(invp)) - *coord = nrecs; - - { - size_t ii = 0; - for(; ii < invp->ndims; ii++) - coord[ii] --; - } - /* at this point, coord is the largest valid coord of invp */ - - if(NCcoordck(outncp, outvp, coord) != NC_NOERR) - { - return NC_EINVAL; - } - /* else */ - - (void) memset(coord, 0, invp->ndims * sizeof(size_t)); - - if(!IS_RECVAR(invp)) - { - status = NCxvarcpy(inncp, invp, coord, - outncp, outvp, coord, - invp->len); - goto done; - } - /* else */ - - status = NCvnrecs(outncp, nrecs); - if(status != NC_NOERR) - goto done; - - for( /*NADA*/; *coord < nrecs; (*coord)++) - { - status = NCxvarcpy(inncp, invp, coord, - outncp, outvp, coord, - invp->len); - if(status != NC_NOERR) - break; - } -done: - FREE_ONSTACK(coord); - } - return status; -} - -/* no longer deprecated, used to support the 2.x interface and also the netcdf-4 api. */ -int -nc_get_att(int ncid, int varid, const char *name, void *value) -{ - int status; - nc_type atttype; - - status = nc_inq_atttype(ncid, varid, name, &atttype); - if(status != NC_NOERR) - return status; - - switch (atttype) { - case NC_BYTE: - return nc_get_att_schar(ncid, varid, name, - (schar *)value); - case NC_CHAR: - return nc_get_att_text(ncid, varid, name, - (char *)value); - case NC_SHORT: - return nc_get_att_short(ncid, varid, name, - (short *)value); - case NC_INT: -#if (SIZEOF_INT >= X_SIZEOF_INT) - return nc_get_att_int(ncid, varid, name, - (int *)value); -#elif SIZEOF_LONG == X_SIZEOF_INT - return nc_get_att_long(ncid, varid, name, - (long *)value); -#endif - case NC_FLOAT: - return nc_get_att_float(ncid, varid, name, - (float *)value); - case NC_DOUBLE: - return nc_get_att_double(ncid, varid, name, - (double *)value); - } - return NC_EBADTYPE; -} - - -int -nc_put_att( - int ncid, - int varid, - const char *name, - nc_type type, - size_t nelems, - const void *value) -{ - switch (type) { - case NC_BYTE: - return nc_put_att_schar(ncid, varid, name, type, nelems, - (schar *)value); - case NC_CHAR: - return nc_put_att_text(ncid, varid, name, nelems, - (char *)value); - case NC_SHORT: - return nc_put_att_short(ncid, varid, name, type, nelems, - (short *)value); - case NC_INT: -#if (SIZEOF_INT >= X_SIZEOF_INT) - return nc_put_att_int(ncid, varid, name, type, nelems, - (int *)value); -#elif SIZEOF_LONG == X_SIZEOF_INT - return nc_put_att_long(ncid, varid, name, type, nelems, - (long *)value); -#endif - case NC_FLOAT: - return nc_put_att_float(ncid, varid, name, type, nelems, - (float *)value); - case NC_DOUBLE: - return nc_put_att_double(ncid, varid, name, type, nelems, - (double *)value); - } - return NC_EBADTYPE; -} - - -int -nc_get_var1(int ncid, int varid, const size_t *coord, void *value) -{ - int status; - nc_type vartype; - - status = nc_inq_vartype(ncid, varid, &vartype); - if(status != NC_NOERR) - return status; - - switch(vartype){ - case NC_CHAR: - return nc_get_var1_text(ncid, varid, coord, - (char *) value); - case NC_BYTE: - return nc_get_var1_schar(ncid, varid, coord, - (schar *) value); - case NC_SHORT: - return nc_get_var1_short(ncid, varid, coord, - (short *) value); - case NC_INT: - return nc_get_var1_int(ncid, varid, coord, - (int *) value); - case NC_FLOAT: - return nc_get_var1_float(ncid, varid, coord, - (float *) value); - case NC_DOUBLE: - return nc_get_var1_double(ncid, varid, coord, - (double *) value); - } - return NC_EBADTYPE; -} - - -int -nc_put_var1(int ncid, int varid, const size_t *coord, const void *value) -{ - int status; - nc_type vartype; - - status = nc_inq_vartype(ncid, varid, &vartype); - if(status != NC_NOERR) - return status; - - switch(vartype){ - case NC_CHAR: - return nc_put_var1_text(ncid, varid, coord, - (const char *) value); - case NC_BYTE: - return nc_put_var1_schar(ncid, varid, coord, - (const schar *) value); - case NC_SHORT: - return nc_put_var1_short(ncid, varid, coord, - (const short *) value); - case NC_INT: - return nc_put_var1_int(ncid, varid, coord, - (const int *) value); - case NC_FLOAT: - return nc_put_var1_float(ncid, varid, coord, - (const float *) value); - case NC_DOUBLE: - return nc_put_var1_double(ncid, varid, coord, - (const double *) value); - } - return NC_EBADTYPE; -} - - -int -nc_get_vara(int ncid, int varid, - const size_t *start, const size_t *edges, void *value) -{ - int status; - nc_type vartype; - - status = nc_inq_vartype(ncid, varid, &vartype); - if(status != NC_NOERR) - return status; - - switch(vartype){ - case NC_CHAR: - return nc_get_vara_text(ncid, varid, start, edges, - (char *) value); - case NC_BYTE: - return nc_get_vara_schar(ncid, varid, start, edges, - (schar *) value); - case NC_SHORT: - return nc_get_vara_short(ncid, varid, start, edges, - (short *) value); - case NC_INT: -#if (SIZEOF_INT >= X_SIZEOF_INT) - return nc_get_vara_int(ncid, varid, start, edges, - (int *) value); -#elif SIZEOF_LONG == X_SIZEOF_INT - return nc_get_vara_long(ncid, varid, start, edges, - (long *) value); -#else -#error "nc_get_vara implementation" -#endif - case NC_FLOAT: - return nc_get_vara_float(ncid, varid, start, edges, - (float *) value); - case NC_DOUBLE: - return nc_get_vara_double(ncid, varid, start, edges, - (double *) value); - } - return NC_EBADTYPE; -} - -int -nc_put_vara(int ncid, int varid, - const size_t *start, const size_t *edges, const void *value) -{ - int status; - nc_type vartype; - - status = nc_inq_vartype(ncid, varid, &vartype); - if(status != NC_NOERR) - return status; - - switch(vartype){ - case NC_CHAR: - return nc_put_vara_text(ncid, varid, start, edges, - (const char *) value); - case NC_BYTE: - return nc_put_vara_schar(ncid, varid, start, edges, - (const schar *) value); - case NC_SHORT: - return nc_put_vara_short(ncid, varid, start, edges, - (const short *) value); - case NC_INT: - return nc_put_vara_int(ncid, varid, start, edges, - (const int *) value); - case NC_FLOAT: - return nc_put_vara_float(ncid, varid, start, edges, - (const float *) value); - case NC_DOUBLE: - return nc_put_vara_double(ncid, varid, start, edges, - (const double *) value); - } - return NC_EBADTYPE; -} - -int -nc_get_varm ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - const ptrdiff_t * map, - void *value) -{ - int status; - nc_type vartype; - int varndims; - ptrdiff_t *cvtmap = NULL; - - status = nc_inq_vartype(ncid, varid, &vartype); - if(status != NC_NOERR) - return status; - - status = nc_inq_varndims(ncid, varid, &varndims); - if(status != NC_NOERR) - return status; - - if(map != NULL && varndims != 0) - { - /* - * convert map units from bytes to units of sizeof(type) - */ - size_t ii; - const ptrdiff_t szof = (ptrdiff_t) nctypelen(vartype); - cvtmap = (ptrdiff_t *)calloc(varndims, sizeof(ptrdiff_t)); - if(cvtmap == NULL) - return NC_ENOMEM; - for(ii = 0; ii < varndims; ii++) - { - if(map[ii] % szof != 0) - { - free(cvtmap); - return NC_EINVAL; - } - cvtmap[ii] = map[ii] / szof; - } - map = cvtmap; - } - - switch(vartype){ - case NC_CHAR: - status = nc_get_varm_text(ncid, varid, start, edges, - stride, map, - (char *) value); - break; - case NC_BYTE: - status = nc_get_varm_schar(ncid, varid, start, edges, - stride, map, - (schar *) value); - break; - case NC_SHORT: - status = nc_get_varm_short(ncid, varid, start, edges, - stride, map, - (short *) value); - break; - case NC_INT: -#if (SIZEOF_INT >= X_SIZEOF_INT) - status = nc_get_varm_int(ncid, varid, start, edges, - stride, map, - (int *) value); -#elif SIZEOF_LONG == X_SIZEOF_INT - status = nc_get_varm_long(ncid, varid, start, edges, - stride, map, - (long *) value); -#else -#error "nc_get_varm implementation" -#endif - break; - case NC_FLOAT: - status = nc_get_varm_float(ncid, varid, start, edges, - stride, map, - (float *) value); - break; - case NC_DOUBLE: - status = nc_get_varm_double(ncid, varid, start, edges, - stride, map, - (double *) value); - break; - default: - status = NC_EBADTYPE; - break; - } - - if(cvtmap != NULL) - { - free(cvtmap); - } - return status; -} - - -int -nc_put_varm ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - const ptrdiff_t * map, - const void *value) -{ - int status; - nc_type vartype; - int varndims; - ptrdiff_t *cvtmap = NULL; - - status = nc_inq_vartype(ncid, varid, &vartype); - if(status != NC_NOERR) - return status; - - status = nc_inq_varndims(ncid, varid, &varndims); - if(status != NC_NOERR) - return status; - - if(map != NULL && varndims != 0) - { - /* - * convert map units from bytes to units of sizeof(type) - */ - size_t ii; - const ptrdiff_t szof = (ptrdiff_t) nctypelen(vartype); - cvtmap = (ptrdiff_t *)calloc(varndims, sizeof(ptrdiff_t)); - if(cvtmap == NULL) - return NC_ENOMEM; - for(ii = 0; ii < varndims; ii++) - { - if(map[ii] % szof != 0) - { - free(cvtmap); - return NC_EINVAL; - } - cvtmap[ii] = map[ii] / szof; - } - map = cvtmap; - } - - switch(vartype){ - case NC_CHAR: - status = nc_put_varm_text(ncid, varid, start, edges, - stride, map, - (const char *) value); - break; - case NC_BYTE: - status = nc_put_varm_schar(ncid, varid, start, edges, - stride, map, - (const schar *) value); - break; - case NC_SHORT: - status = nc_put_varm_short(ncid, varid, start, edges, - stride, map, - (const short *) value); - break; - case NC_INT: -#if (SIZEOF_INT >= X_SIZEOF_INT) - status = nc_put_varm_int(ncid, varid, start, edges, - stride, map, - (const int *) value); -#elif SIZEOF_LONG == X_SIZEOF_INT - status = nc_put_varm_long(ncid, varid, start, edges, - stride, map, - (const long *) value); -#else -#error "nc_put_varm implementation" -#endif - break; - case NC_FLOAT: - status = nc_put_varm_float(ncid, varid, start, edges, - stride, map, - (const float *) value); - break; - case NC_DOUBLE: - status = nc_put_varm_double(ncid, varid, start, edges, - stride, map, - (const double *) value); - break; - default: - status = NC_EBADTYPE; - break; - } - - if(cvtmap != NULL) - { - free(cvtmap); - } - return status; -} - -int -nc_get_vars ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - void *value) -{ - return nc_get_varm (ncid, varid, start, edges, - stride, 0, value); -} - -int -nc_put_vars ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - const void *value) -{ - return nc_put_varm (ncid, varid, start, edges, - stride, 0, value); -} - Index: libsrc/attr.c =================================================================== --- libsrc/attr.c (.../trunk) (revision 531) +++ libsrc/attr.c (.../branches/fileinf_improvement) (revision 531) @@ -1,2171 +0,0 @@ -/* Do not edit this file. It is produced from the corresponding .m4 source */ -/* - * Copyright 1996, University Corporation for Atmospheric Research - * See netcdf/COPYRIGHT file for copying and redistribution conditions. - */ -/* $Id: attr.m4,v 2.25 2005/06/23 15:54:26 russ Exp $ */ - -#include "nc.h" -#include -#include -#include -#include "ncx.h" -#include "fbits.h" -#include "rnd.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); - } - /* 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 *name, - nc_type type, - size_t nelems) -{ - NC_string *strp; - NC_attr *attrp; - - assert(name != NULL && *name != 0); - - strp = new_NC_string(strlen(name), name); - if(strp == NULL) - return NULL; - - attrp = new_x_NC_attr(strp, type, nelems); - if(attrp == NULL) - { - free_NC_string(strp); - return NULL; - } - - 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; - (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( NC *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. - */ -NC_attr ** -NC_findattr(const NC_attrarray *ncap, const char *name) -{ - NC_attr **attrpp; - size_t attrid; - size_t slen; - - assert(ncap != NULL); - - if(ncap->nelems == 0) - return NULL; - - attrpp = (NC_attr **) ncap->value; - - slen = strlen(name); - - for(attrid = 0; attrid < ncap->nelems; attrid++, attrpp++) - { - if(strlen((*attrpp)->name->cp) == slen && - strncmp((*attrpp)->name->cp, name, slen) == 0) - { - return(attrpp); /* Normal return */ - } - } - return(NULL); -} - - -/* - * 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 *ncp; - NC_attrarray *ncap; - NC_attr **tmp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - ncap = NC_attrarray0(ncp, varid); - if(ncap == NULL) - return NC_ENOTVAR; - - tmp = NC_findattr(ncap, name); - if(tmp == NULL) - return NC_ENOTATT; - - if(attrpp != NULL) - *attrpp = *tmp; - - return ENOERR; -} - -/* Public */ - -int -nc_inq_attname(int ncid, int varid, int attnum, char *name) -{ - int status; - NC *ncp; - NC_attrarray *ncap; - NC_attr *attrp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - 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 -nc_inq_attid(int ncid, int varid, const char *name, int *attnump) -{ - int status; - NC *ncp; - NC_attrarray *ncap; - NC_attr **attrpp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - 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 -nc_inq_atttype(int ncid, int varid, const char *name, nc_type *datatypep) -{ - int status; - NC_attr *attrp; - - status = NC_lookupattr(ncid, varid, name, &attrp); - if(status != NC_NOERR) - return status; - - if(datatypep != NULL) - *datatypep = attrp->type; - - return NC_NOERR; -} - -int -nc_inq_attlen(int ncid, int varid, const char *name, size_t *lenp) -{ - int status; - NC_attr *attrp; - - status = NC_lookupattr(ncid, varid, name, &attrp); - if(status != NC_NOERR) - return status; - - if(lenp != NULL) - *lenp = attrp->nelems; - - return NC_NOERR; -} - -int -nc_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 -nc_rename_att( int ncid, int varid, const char *name, const char *newname) -{ - int status; - NC *ncp; - NC_attrarray *ncap; - NC_attr **tmp; - NC_attr *attrp; - NC_string *newStr, *old; - - /* sortof inline clone of NC_lookupattr() */ - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - ncap = NC_attrarray0(ncp, varid); - if(ncap == NULL) - return NC_ENOTVAR; - - status = NC_check_name(newname); - if(status != NC_NOERR) - return status; - - tmp = NC_findattr(ncap, name); - if(tmp == NULL) - return NC_ENOTATT; - attrp = *tmp; - /* end inline clone NC_lookupattr() */ - - if(NC_findattr(ncap, newname) != NULL) - { - /* name in use */ - return NC_ENAMEINUSE; - } - - old = attrp->name; - if(NC_indef(ncp)) - { - newStr = new_NC_string(strlen(newname), newname); - if( newStr == NULL) - return NC_ENOMEM; - attrp->name = newStr; - free_NC_string(old); - return NC_NOERR; - } - /* else */ - status = set_NC_string(old, newname); - if( status != NC_NOERR) - return status; - - set_NC_hdirty(ncp); - - if(NC_doHsync(ncp)) - { - status = NC_sync(ncp); - if(status != NC_NOERR) - return status; - } - - return NC_NOERR; -} - - -int -nc_copy_att(int ncid_in, int varid_in, const char *name, int ncid_out, int ovarid) -{ - int status; - NC_attr *iattrp; - NC *ncp; - NC_attrarray *ncap; - NC_attr **attrpp; - NC_attr *old = NULL; - NC_attr *attrp; - - status = NC_lookupattr(ncid_in, varid_in, name, &iattrp); - if(status != NC_NOERR) - return status; - - status = NC_check_id(ncid_out, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - ncap = NC_attrarray0(ncp, ovarid); - if(ncap == NULL) - return NC_ENOTVAR; - - attrpp = NC_findattr(ncap, name); - if(attrpp != NULL) /* name in use */ - { - if(!NC_indef(ncp) ) - { - attrp = *attrpp; /* convenience */ - - if(iattrp->xsz > attrp->xsz) - return NC_ENOTINDEFINE; - /* else, we can reuse existing without redef */ - - attrp->xsz = iattrp->xsz; - attrp->type = iattrp->type; - attrp->nelems = iattrp->nelems; - - (void) memcpy(attrp->xvalue, iattrp->xvalue, - iattrp->xsz); - - set_NC_hdirty(ncp); - - if(NC_doHsync(ncp)) - { - status = NC_sync(ncp); - if(status != NC_NOERR) - return status; - } - - return NC_NOERR; - } - /* else, redefine using existing array slot */ - old = *attrpp; - } - else - { - if(!NC_indef(ncp)) - return NC_ENOTINDEFINE; - - if(ncap->nelems >= NC_MAX_ATTRS) - return NC_EMAXATTS; - } - - attrp = new_NC_attr(name, iattrp->type, iattrp->nelems); - if(attrp == NULL) - return NC_ENOMEM; - - (void) memcpy(attrp->xvalue, iattrp->xvalue, - iattrp->xsz); - - if(attrpp != NULL) - { - assert(old != NULL); - *attrpp = attrp; - free_NC_attr(old); - } - else - { - status = incr_NC_attrarray(ncap, attrp); - if(status != NC_NOERR) - { - free_NC_attr(attrp); - return status; - } - } - - return NC_NOERR; -} - - -int -nc_del_att(int ncid, int varid, const char *name) -{ - int status; - NC *ncp; - NC_attrarray *ncap; - NC_attr **attrpp; - NC_attr *old = NULL; - int attrid; - size_t slen; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(!NC_indef(ncp)) - return NC_ENOTINDEFINE; - - ncap = NC_attrarray0(ncp, varid); - if(ncap == NULL) - return NC_ENOTVAR; - - /* 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 ) - return NC_ENOTATT; - /* 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); - - return NC_NOERR; -} - - -static int -ncx_pad_putn_Iuchar(void **xpp, size_t nelems, const uchar *tp, nc_type type) -{ - switch(type) { - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return ncx_pad_putn_schar_uchar(xpp, nelems, tp); - case NC_SHORT: - return ncx_pad_putn_short_uchar(xpp, nelems, tp); - case NC_INT: - return ncx_putn_int_uchar(xpp, nelems, tp); - case NC_FLOAT: - return ncx_putn_float_uchar(xpp, nelems, tp); - case NC_DOUBLE: - return ncx_putn_double_uchar(xpp, nelems, tp); - } - assert("ncx_pad_putn_Iuchar invalid type" == 0); - return NC_EBADTYPE; -} - -static int -ncx_pad_getn_Iuchar(const void **xpp, size_t nelems, uchar *tp, nc_type type) -{ - switch(type) { - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return ncx_pad_getn_schar_uchar(xpp, nelems, tp); - case NC_SHORT: - return ncx_pad_getn_short_uchar(xpp, nelems, tp); - case NC_INT: - return ncx_getn_int_uchar(xpp, nelems, tp); - case NC_FLOAT: - return ncx_getn_float_uchar(xpp, nelems, tp); - case NC_DOUBLE: - return ncx_getn_double_uchar(xpp, nelems, tp); - } - assert("ncx_pad_getn_Iuchar invalid type" == 0); - return NC_EBADTYPE; -} - - -static int -ncx_pad_putn_Ischar(void **xpp, size_t nelems, const schar *tp, nc_type type) -{ - switch(type) { - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return ncx_pad_putn_schar_schar(xpp, nelems, tp); - case NC_SHORT: - return ncx_pad_putn_short_schar(xpp, nelems, tp); - case NC_INT: - return ncx_putn_int_schar(xpp, nelems, tp); - case NC_FLOAT: - return ncx_putn_float_schar(xpp, nelems, tp); - case NC_DOUBLE: - return ncx_putn_double_schar(xpp, nelems, tp); - } - assert("ncx_pad_putn_Ischar invalid type" == 0); - return NC_EBADTYPE; -} - -static int -ncx_pad_getn_Ischar(const void **xpp, size_t nelems, schar *tp, nc_type type) -{ - switch(type) { - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return ncx_pad_getn_schar_schar(xpp, nelems, tp); - case NC_SHORT: - return ncx_pad_getn_short_schar(xpp, nelems, tp); - case NC_INT: - return ncx_getn_int_schar(xpp, nelems, tp); - case NC_FLOAT: - return ncx_getn_float_schar(xpp, nelems, tp); - case NC_DOUBLE: - return ncx_getn_double_schar(xpp, nelems, tp); - } - assert("ncx_pad_getn_Ischar invalid type" == 0); - return NC_EBADTYPE; -} - - -static int -ncx_pad_putn_Ishort(void **xpp, size_t nelems, const short *tp, nc_type type) -{ - switch(type) { - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return ncx_pad_putn_schar_short(xpp, nelems, tp); - case NC_SHORT: - return ncx_pad_putn_short_short(xpp, nelems, tp); - case NC_INT: - return ncx_putn_int_short(xpp, nelems, tp); - case NC_FLOAT: - return ncx_putn_float_short(xpp, nelems, tp); - case NC_DOUBLE: - return ncx_putn_double_short(xpp, nelems, tp); - } - assert("ncx_pad_putn_Ishort invalid type" == 0); - return NC_EBADTYPE; -} - -static int -ncx_pad_getn_Ishort(const void **xpp, size_t nelems, short *tp, nc_type type) -{ - switch(type) { - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return ncx_pad_getn_schar_short(xpp, nelems, tp); - case NC_SHORT: - return ncx_pad_getn_short_short(xpp, nelems, tp); - case NC_INT: - return ncx_getn_int_short(xpp, nelems, tp); - case NC_FLOAT: - return ncx_getn_float_short(xpp, nelems, tp); - case NC_DOUBLE: - return ncx_getn_double_short(xpp, nelems, tp); - } - assert("ncx_pad_getn_Ishort invalid type" == 0); - return NC_EBADTYPE; -} - - -static int -ncx_pad_putn_Iint(void **xpp, size_t nelems, const int *tp, nc_type type) -{ - switch(type) { - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return ncx_pad_putn_schar_int(xpp, nelems, tp); - case NC_SHORT: - return ncx_pad_putn_short_int(xpp, nelems, tp); - case NC_INT: - return ncx_putn_int_int(xpp, nelems, tp); - case NC_FLOAT: - return ncx_putn_float_int(xpp, nelems, tp); - case NC_DOUBLE: - return ncx_putn_double_int(xpp, nelems, tp); - } - assert("ncx_pad_putn_Iint invalid type" == 0); - return NC_EBADTYPE; -} - -static int -ncx_pad_getn_Iint(const void **xpp, size_t nelems, int *tp, nc_type type) -{ - switch(type) { - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return ncx_pad_getn_schar_int(xpp, nelems, tp); - case NC_SHORT: - return ncx_pad_getn_short_int(xpp, nelems, tp); - case NC_INT: - return ncx_getn_int_int(xpp, nelems, tp); - case NC_FLOAT: - return ncx_getn_float_int(xpp, nelems, tp); - case NC_DOUBLE: - return ncx_getn_double_int(xpp, nelems, tp); - } - assert("ncx_pad_getn_Iint invalid type" == 0); - return NC_EBADTYPE; -} - - -static int -ncx_pad_putn_Ilong(void **xpp, size_t nelems, const long *tp, nc_type type) -{ - switch(type) { - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return ncx_pad_putn_schar_long(xpp, nelems, tp); - case NC_SHORT: - return ncx_pad_putn_short_long(xpp, nelems, tp); - case NC_INT: - return ncx_putn_int_long(xpp, nelems, tp); - case NC_FLOAT: - return ncx_putn_float_long(xpp, nelems, tp); - case NC_DOUBLE: - return ncx_putn_double_long(xpp, nelems, tp); - } - assert("ncx_pad_putn_Ilong invalid type" == 0); - return NC_EBADTYPE; -} - -static int -ncx_pad_getn_Ilong(const void **xpp, size_t nelems, long *tp, nc_type type) -{ - switch(type) { - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return ncx_pad_getn_schar_long(xpp, nelems, tp); - case NC_SHORT: - return ncx_pad_getn_short_long(xpp, nelems, tp); - case NC_INT: - return ncx_getn_int_long(xpp, nelems, tp); - case NC_FLOAT: - return ncx_getn_float_long(xpp, nelems, tp); - case NC_DOUBLE: - return ncx_getn_double_long(xpp, nelems, tp); - } - assert("ncx_pad_getn_Ilong invalid type" == 0); - return NC_EBADTYPE; -} - - -static int -ncx_pad_putn_Ifloat(void **xpp, size_t nelems, const float *tp, nc_type type) -{ - switch(type) { - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return ncx_pad_putn_schar_float(xpp, nelems, tp); - case NC_SHORT: - return ncx_pad_putn_short_float(xpp, nelems, tp); - case NC_INT: - return ncx_putn_int_float(xpp, nelems, tp); - case NC_FLOAT: - return ncx_putn_float_float(xpp, nelems, tp); - case NC_DOUBLE: - return ncx_putn_double_float(xpp, nelems, tp); - } - assert("ncx_pad_putn_Ifloat invalid type" == 0); - return NC_EBADTYPE; -} - -static int -ncx_pad_getn_Ifloat(const void **xpp, size_t nelems, float *tp, nc_type type) -{ - switch(type) { - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return ncx_pad_getn_schar_float(xpp, nelems, tp); - case NC_SHORT: - return ncx_pad_getn_short_float(xpp, nelems, tp); - case NC_INT: - return ncx_getn_int_float(xpp, nelems, tp); - case NC_FLOAT: - return ncx_getn_float_float(xpp, nelems, tp); - case NC_DOUBLE: - return ncx_getn_double_float(xpp, nelems, tp); - } - assert("ncx_pad_getn_Ifloat invalid type" == 0); - return NC_EBADTYPE; -} - - -static int -ncx_pad_putn_Idouble(void **xpp, size_t nelems, const double *tp, nc_type type) -{ - switch(type) { - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return ncx_pad_putn_schar_double(xpp, nelems, tp); - case NC_SHORT: - return ncx_pad_putn_short_double(xpp, nelems, tp); - case NC_INT: - return ncx_putn_int_double(xpp, nelems, tp); - case NC_FLOAT: - return ncx_putn_float_double(xpp, nelems, tp); - case NC_DOUBLE: - return ncx_putn_double_double(xpp, nelems, tp); - } - assert("ncx_pad_putn_Idouble invalid type" == 0); - return NC_EBADTYPE; -} - -static int -ncx_pad_getn_Idouble(const void **xpp, size_t nelems, double *tp, nc_type type) -{ - switch(type) { - case NC_CHAR: - return NC_ECHAR; - case NC_BYTE: - return ncx_pad_getn_schar_double(xpp, nelems, tp); - case NC_SHORT: - return ncx_pad_getn_short_double(xpp, nelems, tp); - case NC_INT: - return ncx_getn_int_double(xpp, nelems, tp); - case NC_FLOAT: - return ncx_getn_float_double(xpp, nelems, tp); - case NC_DOUBLE: - return ncx_getn_double_double(xpp, nelems, tp); - } - assert("ncx_pad_getn_Idouble invalid type" == 0); - return NC_EBADTYPE; -} - - - -int -nc_put_att_text(int ncid, int varid, const char *name, - size_t nelems, const char *value) -{ - int status; - NC *ncp; - NC_attrarray *ncap; - NC_attr **attrpp; - NC_attr *old = NULL; - NC_attr *attrp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - ncap = NC_attrarray0(ncp, varid); - if(ncap == NULL) - return NC_ENOTVAR; - - status = NC_check_name(name); - if(status != NC_NOERR) - return status; - - /* 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 */ - - attrpp = NC_findattr(ncap, name); - if(attrpp != NULL) /* name in use */ - { - if(!NC_indef(ncp) ) - { - const size_t xsz = ncx_len_NC_attrV(NC_CHAR, nelems); - attrp = *attrpp; /* convenience */ - - if(xsz > attrp->xsz) - return NC_ENOTINDEFINE; - /* else, we can reuse existing without redef */ - - attrp->xsz = xsz; - attrp->type = NC_CHAR; - attrp->nelems = nelems; - - if(nelems != 0) - { - void *xp = attrp->xvalue; - status = ncx_pad_putn_text(&xp, nelems, value); - if(status != NC_NOERR) - return status; - } - - set_NC_hdirty(ncp); - - if(NC_doHsync(ncp)) - { - status = NC_sync(ncp); - if(status != NC_NOERR) - return status; - } - - return NC_NOERR; - } - /* else, redefine using existing array slot */ - old = *attrpp; - } - else - { - if(!NC_indef(ncp)) - return NC_ENOTINDEFINE; - - if(ncap->nelems >= NC_MAX_ATTRS) - return NC_EMAXATTS; - } - - attrp = new_NC_attr(name, NC_CHAR, nelems); - if(attrp == NULL) - return NC_ENOMEM; - - if(nelems != 0) - { - void *xp = attrp->xvalue; - status = ncx_pad_putn_text(&xp, nelems, value); - if(status != NC_NOERR) - return status; - } - - if(attrpp != NULL) - { - assert(old != NULL); - *attrpp = attrp; - free_NC_attr(old); - } - else - { - status = incr_NC_attrarray(ncap, attrp); - if(status != NC_NOERR) - { - free_NC_attr(attrp); - return status; - } - } - - return NC_NOERR; -} - - -int -nc_get_att_text(int ncid, int varid, const char *name, char *str) -{ - int status; - NC_attr *attrp; - - status = NC_lookupattr(ncid, varid, name, &attrp); - if(status != NC_NOERR) - return status; - - if(attrp->nelems == 0) - return NC_NOERR; - - if(attrp->type != NC_CHAR) - return NC_ECHAR; - - /* else */ - { - const void *xp = attrp->xvalue; - return ncx_pad_getn_text(&xp, attrp->nelems, str); - } -} - - - - -int -nc_put_att_schar(int ncid, int varid, const char *name, - nc_type type, size_t nelems, const signed char *value) -{ - int status; - NC *ncp; - NC_attrarray *ncap; - NC_attr **attrpp; - NC_attr *old = NULL; - NC_attr *attrp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - ncap = NC_attrarray0(ncp, varid); - if(ncap == NULL) - return NC_ENOTVAR; - - status = nc_cktype(type); - if(status != NC_NOERR) - return status; - - if(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 */ - - attrpp = NC_findattr(ncap, name); - 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; - status = ncx_pad_putn_Ischar(&xp, nelems, - value, type); - } - - 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_Ischar - */ - if(lstatus != ENOERR) - return lstatus; - } - - return status; - } - /* else, redefine using existing array slot */ - old = *attrpp; - } - else - { - if(!NC_indef(ncp)) - return NC_ENOTINDEFINE; - - if(ncap->nelems >= NC_MAX_ATTRS) - return NC_EMAXATTS; - } - - 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; - status = ncx_pad_putn_Ischar(&xp, nelems, - value, type); - } - - if(attrpp != NULL) - { - assert(old != NULL); - *attrpp = attrp; - free_NC_attr(old); - } - else - { - const int lstatus = incr_NC_attrarray(ncap, attrp); - /* - * N.B.: potentially overrides NC_ERANGE - * set by ncx_pad_putn_Ischar - */ - if(lstatus != NC_NOERR) - { - free_NC_attr(attrp); - return lstatus; - } - } - - return status; -} - -int -nc_get_att_schar(int ncid, int varid, const char *name, signed char *tp) -{ - int status; - NC_attr *attrp; - - status = NC_lookupattr(ncid, varid, name, &attrp); - if(status != NC_NOERR) - return status; - - if(attrp->nelems == 0) - return NC_NOERR; - - if(attrp->type == NC_CHAR) - return NC_ECHAR; - - { - const void *xp = attrp->xvalue; - return ncx_pad_getn_Ischar(&xp, attrp->nelems, tp, attrp->type); - } -} - - -int -nc_put_att_uchar(int ncid, int varid, const char *name, - nc_type type, size_t nelems, const unsigned char *value) -{ - int status; - NC *ncp; - NC_attrarray *ncap; - NC_attr **attrpp; - NC_attr *old = NULL; - NC_attr *attrp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - ncap = NC_attrarray0(ncp, varid); - if(ncap == NULL) - return NC_ENOTVAR; - - status = nc_cktype(type); - if(status != NC_NOERR) - return status; - - if(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 */ - - attrpp = NC_findattr(ncap, name); - 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; - status = ncx_pad_putn_Iuchar(&xp, nelems, - value, type); - } - - 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_Iuchar - */ - if(lstatus != ENOERR) - return lstatus; - } - - return status; - } - /* else, redefine using existing array slot */ - old = *attrpp; - } - else - { - if(!NC_indef(ncp)) - return NC_ENOTINDEFINE; - - if(ncap->nelems >= NC_MAX_ATTRS) - return NC_EMAXATTS; - } - - 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; - status = ncx_pad_putn_Iuchar(&xp, nelems, - value, type); - } - - if(attrpp != NULL) - { - assert(old != NULL); - *attrpp = attrp; - free_NC_attr(old); - } - else - { - const int lstatus = incr_NC_attrarray(ncap, attrp); - /* - * N.B.: potentially overrides NC_ERANGE - * set by ncx_pad_putn_Iuchar - */ - if(lstatus != NC_NOERR) - { - free_NC_attr(attrp); - return lstatus; - } - } - - return status; -} - -int -nc_get_att_uchar(int ncid, int varid, const char *name, unsigned char *tp) -{ - int status; - NC_attr *attrp; - - status = NC_lookupattr(ncid, varid, name, &attrp); - if(status != NC_NOERR) - return status; - - if(attrp->nelems == 0) - return NC_NOERR; - - if(attrp->type == NC_CHAR) - return NC_ECHAR; - - { - const void *xp = attrp->xvalue; - return ncx_pad_getn_Iuchar(&xp, attrp->nelems, tp, attrp->type); - } -} - - -int -nc_put_att_short(int ncid, int varid, const char *name, - nc_type type, size_t nelems, const short *value) -{ - int status; - NC *ncp; - NC_attrarray *ncap; - NC_attr **attrpp; - NC_attr *old = NULL; - NC_attr *attrp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - ncap = NC_attrarray0(ncp, varid); - if(ncap == NULL) - return NC_ENOTVAR; - - status = nc_cktype(type); - if(status != NC_NOERR) - return status; - - if(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 */ - - attrpp = NC_findattr(ncap, name); - 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; - status = ncx_pad_putn_Ishort(&xp, nelems, - value, type); - } - - 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_Ishort - */ - if(lstatus != ENOERR) - return lstatus; - } - - return status; - } - /* else, redefine using existing array slot */ - old = *attrpp; - } - else - { - if(!NC_indef(ncp)) - return NC_ENOTINDEFINE; - - if(ncap->nelems >= NC_MAX_ATTRS) - return NC_EMAXATTS; - } - - 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; - status = ncx_pad_putn_Ishort(&xp, nelems, - value, type); - } - - if(attrpp != NULL) - { - assert(old != NULL); - *attrpp = attrp; - free_NC_attr(old); - } - else - { - const int lstatus = incr_NC_attrarray(ncap, attrp); - /* - * N.B.: potentially overrides NC_ERANGE - * set by ncx_pad_putn_Ishort - */ - if(lstatus != NC_NOERR) - { - free_NC_attr(attrp); - return lstatus; - } - } - - return status; -} - -int -nc_get_att_short(int ncid, int varid, const char *name, short *tp) -{ - int status; - NC_attr *attrp; - - status = NC_lookupattr(ncid, varid, name, &attrp); - if(status != NC_NOERR) - return status; - - if(attrp->nelems == 0) - return NC_NOERR; - - if(attrp->type == NC_CHAR) - return NC_ECHAR; - - { - const void *xp = attrp->xvalue; - return ncx_pad_getn_Ishort(&xp, attrp->nelems, tp, attrp->type); - } -} - - -int -nc_put_att_int(int ncid, int varid, const char *name, - nc_type type, size_t nelems, const int *value) -{ - int status; - NC *ncp; - NC_attrarray *ncap; - NC_attr **attrpp; - NC_attr *old = NULL; - NC_attr *attrp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - ncap = NC_attrarray0(ncp, varid); - if(ncap == NULL) - return NC_ENOTVAR; - - status = nc_cktype(type); - if(status != NC_NOERR) - return status; - - if(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 */ - - attrpp = NC_findattr(ncap, name); - 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; - status = ncx_pad_putn_Iint(&xp, nelems, - value, type); - } - - 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_Iint - */ - if(lstatus != ENOERR) - return lstatus; - } - - return status; - } - /* else, redefine using existing array slot */ - old = *attrpp; - } - else - { - if(!NC_indef(ncp)) - return NC_ENOTINDEFINE; - - if(ncap->nelems >= NC_MAX_ATTRS) - return NC_EMAXATTS; - } - - 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; - status = ncx_pad_putn_Iint(&xp, nelems, - value, type); - } - - if(attrpp != NULL) - { - assert(old != NULL); - *attrpp = attrp; - free_NC_attr(old); - } - else - { - const int lstatus = incr_NC_attrarray(ncap, attrp); - /* - * N.B.: potentially overrides NC_ERANGE - * set by ncx_pad_putn_Iint - */ - if(lstatus != NC_NOERR) - { - free_NC_attr(attrp); - return lstatus; - } - } - - return status; -} - -int -nc_get_att_int(int ncid, int varid, const char *name, int *tp) -{ - int status; - NC_attr *attrp; - - status = NC_lookupattr(ncid, varid, name, &attrp); - if(status != NC_NOERR) - return status; - - if(attrp->nelems == 0) - return NC_NOERR; - - if(attrp->type == NC_CHAR) - return NC_ECHAR; - - { - const void *xp = attrp->xvalue; - return ncx_pad_getn_Iint(&xp, attrp->nelems, tp, attrp->type); - } -} - - -int -nc_put_att_long(int ncid, int varid, const char *name, - nc_type type, size_t nelems, const long *value) -{ - int status; - NC *ncp; - NC_attrarray *ncap; - NC_attr **attrpp; - NC_attr *old = NULL; - NC_attr *attrp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - ncap = NC_attrarray0(ncp, varid); - if(ncap == NULL) - return NC_ENOTVAR; - - status = nc_cktype(type); - if(status != NC_NOERR) - return status; - - if(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 */ - - attrpp = NC_findattr(ncap, name); - 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; - status = ncx_pad_putn_Ilong(&xp, nelems, - value, type); - } - - 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_Ilong - */ - if(lstatus != ENOERR) - return lstatus; - } - - return status; - } - /* else, redefine using existing array slot */ - old = *attrpp; - } - else - { - if(!NC_indef(ncp)) - return NC_ENOTINDEFINE; - - if(ncap->nelems >= NC_MAX_ATTRS) - return NC_EMAXATTS; - } - - 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; - status = ncx_pad_putn_Ilong(&xp, nelems, - value, type); - } - - if(attrpp != NULL) - { - assert(old != NULL); - *attrpp = attrp; - free_NC_attr(old); - } - else - { - const int lstatus = incr_NC_attrarray(ncap, attrp); - /* - * N.B.: potentially overrides NC_ERANGE - * set by ncx_pad_putn_Ilong - */ - if(lstatus != NC_NOERR) - { - free_NC_attr(attrp); - return lstatus; - } - } - - return status; -} - -int -nc_get_att_long(int ncid, int varid, const char *name, long *tp) -{ - int status; - NC_attr *attrp; - - status = NC_lookupattr(ncid, varid, name, &attrp); - if(status != NC_NOERR) - return status; - - if(attrp->nelems == 0) - return NC_NOERR; - - if(attrp->type == NC_CHAR) - return NC_ECHAR; - - { - const void *xp = attrp->xvalue; - return ncx_pad_getn_Ilong(&xp, attrp->nelems, tp, attrp->type); - } -} - - -int -nc_put_att_float(int ncid, int varid, const char *name, - nc_type type, size_t nelems, const float *value) -{ - int status; - NC *ncp; - NC_attrarray *ncap; - NC_attr **attrpp; - NC_attr *old = NULL; - NC_attr *attrp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - ncap = NC_attrarray0(ncp, varid); - if(ncap == NULL) - return NC_ENOTVAR; - - status = nc_cktype(type); - if(status != NC_NOERR) - return status; - - if(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 */ - - attrpp = NC_findattr(ncap, name); - 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; - status = ncx_pad_putn_Ifloat(&xp, nelems, - value, type); - } - - 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_Ifloat - */ - if(lstatus != ENOERR) - return lstatus; - } - - return status; - } - /* else, redefine using existing array slot */ - old = *attrpp; - } - else - { - if(!NC_indef(ncp)) - return NC_ENOTINDEFINE; - - if(ncap->nelems >= NC_MAX_ATTRS) - return NC_EMAXATTS; - } - - 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; - status = ncx_pad_putn_Ifloat(&xp, nelems, - value, type); - } - - if(attrpp != NULL) - { - assert(old != NULL); - *attrpp = attrp; - free_NC_attr(old); - } - else - { - const int lstatus = incr_NC_attrarray(ncap, attrp); - /* - * N.B.: potentially overrides NC_ERANGE - * set by ncx_pad_putn_Ifloat - */ - if(lstatus != NC_NOERR) - { - free_NC_attr(attrp); - return lstatus; - } - } - - return status; -} - -int -nc_get_att_float(int ncid, int varid, const char *name, float *tp) -{ - int status; - NC_attr *attrp; - - status = NC_lookupattr(ncid, varid, name, &attrp); - if(status != NC_NOERR) - return status; - - if(attrp->nelems == 0) - return NC_NOERR; - - if(attrp->type == NC_CHAR) - return NC_ECHAR; - - { - const void *xp = attrp->xvalue; - return ncx_pad_getn_Ifloat(&xp, attrp->nelems, tp, attrp->type); - } -} - - -int -nc_put_att_double(int ncid, int varid, const char *name, - nc_type type, size_t nelems, const double *value) -{ - int status; - NC *ncp; - NC_attrarray *ncap; - NC_attr **attrpp; - NC_attr *old = NULL; - NC_attr *attrp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - ncap = NC_attrarray0(ncp, varid); - if(ncap == NULL) - return NC_ENOTVAR; - - status = nc_cktype(type); - if(status != NC_NOERR) - return status; - - if(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 */ - - attrpp = NC_findattr(ncap, name); - 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; - status = ncx_pad_putn_Idouble(&xp, nelems, - value, type); - } - - 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_Idouble - */ - if(lstatus != ENOERR) - return lstatus; - } - - return status; - } - /* else, redefine using existing array slot */ - old = *attrpp; - } - else - { - if(!NC_indef(ncp)) - return NC_ENOTINDEFINE; - - if(ncap->nelems >= NC_MAX_ATTRS) - return NC_EMAXATTS; - } - - 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; - status = ncx_pad_putn_Idouble(&xp, nelems, - value, type); - } - - if(attrpp != NULL) - { - assert(old != NULL); - *attrpp = attrp; - free_NC_attr(old); - } - else - { - const int lstatus = incr_NC_attrarray(ncap, attrp); - /* - * N.B.: potentially overrides NC_ERANGE - * set by ncx_pad_putn_Idouble - */ - if(lstatus != NC_NOERR) - { - free_NC_attr(attrp); - return lstatus; - } - } - - return status; -} - -int -nc_get_att_double(int ncid, int varid, const char *name, double *tp) -{ - int status; - NC_attr *attrp; - - status = NC_lookupattr(ncid, varid, name, &attrp); - if(status != NC_NOERR) - return status; - - if(attrp->nelems == 0) - return NC_NOERR; - - if(attrp->type == NC_CHAR) - return NC_ECHAR; - - { - const void *xp = attrp->xvalue; - return ncx_pad_getn_Idouble(&xp, attrp->nelems, tp, attrp->type); - } -} - Index: libsrc/ncx.c =================================================================== --- libsrc/ncx.c (.../trunk) (revision 531) +++ libsrc/ncx.c (.../branches/fileinf_improvement) (revision 531) @@ -1,4215 +0,0 @@ -/* Do not edit this file. It is produced from the corresponding .m4 source */ -/* - * Copyright 1996, University Corporation for Atmospheric Research - * See netcdf/COPYRIGHT file for copying and redistribution conditions. - * - * This file contains some routines derived from code - * which is copyrighted by Sun Microsystems, Inc. - * The "#ifdef vax" versions of - * ncx_put_float_float() - * ncx_get_float_float() - * ncx_put_double_double() - * ncx_get_double_double() - * ncx_putn_float_float() - * ncx_getn_float_float() - * ncx_putn_double_double() - * ncx_getn_double_double() - * are derived from xdr_float() and xdr_double() routines - * in the freely available, copyrighted Sun RPCSRC 3.9 - * distribution, xdr_float.c. - * Our "value added" is that these are always memory to memory, - * they handle IEEE subnormals properly, and their "n" versions - * operate speedily on arrays. - */ -/* $Id: ncx.m4,v 2.47 2004/09/30 18:47:12 russ Exp $ */ - -/* - * An external data representation interface. - */ - -#include "ncx.h" -#include -#include -/* alias poorly named limits.h macros */ -#define SHORT_MAX SHRT_MAX -#define SHORT_MIN SHRT_MIN -#define USHORT_MAX USHRT_MAX -#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 -#include - -/* - * 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 _SX /* NEC SUPER UX */ -#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 -#endif /* _SX */ - -static const char nada[X_ALIGN] = {0, 0, 0, 0}; - -#ifndef WORDS_BIGENDIAN -/* LITTLE_ENDIAN: DEC and intel */ -/* - * Routines to convert to BIGENDIAN. - * Optimize the swapn?b() and swap?b() routines aggressivly. - */ - -#define SWAP2(a) ( (((a) & 0xff) << 8) | \ - (((a) >> 8) & 0xff) ) - -#define SWAP4(a) ( ((a) << 24) | \ - (((a) << 8) & 0x00ff0000) | \ - (((a) >> 8) & 0x0000ff00) | \ - (((a) >> 24) & 0x000000ff) ) - -static void -swapn2b(void *dst, const void *src, size_t nn) -{ - char *op = dst; - const char *ip = src; - while(nn-- != 0) - { - *op++ = *(++ip); - *op++ = *(ip++ -1); - } -} - -# ifndef vax -static void -swap4b(void *dst, const void *src) -{ - 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 */ - -static void -swapn4b(void *dst, const void *src, size_t nn) -{ - char *op = dst; - const char *ip = src; - while(nn-- != 0) - { - op[0] = ip[3]; - op[1] = ip[2]; - op[2] = ip[1]; - op[3] = ip[0]; - op += 4; - ip += 4; - } -} - -# ifndef vax -static void -swap8b(void *dst, const void *src) -{ - char *op = dst; - const char *ip = src; - 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]; -} -# endif /* !vax */ - -# ifndef vax -static void -swapn8b(void *dst, const void *src, size_t nn) -{ - char *op = dst; - const char *ip = src; - 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; - } -} -# endif /* !vax */ - -#endif /* LITTLE_ENDIAN */ - - -/* - * Primitive numeric conversion functions. - */ - -/* x_schar */ - - /* We don't implement and x_schar primitives. */ - - -/* x_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 -#else -#error "ix_short implementation" -#endif - -static void -get_ix_short(const void *xp, ix_short *ip) -{ - const uchar *cp = (const uchar *) xp; - *ip = *cp++ << 8; -#if SIZEOF_IX_SHORT > X_SIZEOF_SHORT - if(*ip & 0x8000) - { - /* extern is negative */ - *ip |= (~(0xffff)); /* N.B. Assumes "twos complement" */ - } -#endif - *ip |= *cp; -} - -static void -put_ix_short(void *xp, const ix_short *ip) -{ - uchar *cp = (uchar *) xp; - *cp++ = (*ip) >> 8; - *cp = (*ip) & 0xff; -} - - -int -ncx_get_short_schar(const void *xp, schar *ip) -{ - ix_short xx; - get_ix_short(xp, &xx); - *ip = xx; - if(xx > SCHAR_MAX || xx < SCHAR_MIN) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_get_short_uchar(const void *xp, uchar *ip) -{ - ix_short xx; - get_ix_short(xp, &xx); - *ip = xx; - if(xx > UCHAR_MAX || xx < 0) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_get_short_short(const void *xp, short *ip) -{ -#if SIZEOF_IX_SHORT == SIZEOF_SHORT && IX_SHORT_MAX == SHORT_MAX - get_ix_short(xp, (ix_short *)ip); - return ENOERR; -#else - ix_short xx; - get_ix_short(xp, &xx); - *ip = xx; -# if IX_SHORT_MAX > SHORT_MAX - if(xx > SHORT_MAX || xx < SHORT_MIN) - return NC_ERANGE; -# endif - return ENOERR; -#endif -} - -int -ncx_get_short_int(const void *xp, int *ip) -{ -#if SIZEOF_IX_SHORT == SIZEOF_INT && IX_SHORT_MAX == INT_MAX - get_ix_short(xp, (ix_short *)ip); - return ENOERR; -#else - ix_short xx; - get_ix_short(xp, &xx); - *ip = xx; -# if IX_SHORT_MAX > INT_MAX - if(xx > INT_MAX || xx < INT_MIN) - return NC_ERANGE; -# endif - return ENOERR; -#endif -} - -int -ncx_get_short_long(const void *xp, long *ip) -{ -#if SIZEOF_IX_SHORT == SIZEOF_LONG && IX_SHORT_MAX == LONG_MAX - get_ix_short(xp, (ix_short *)ip); - return ENOERR; -#else - /* assert(LONG_MAX >= X_SHORT_MAX); */ - ix_short xx; - get_ix_short(xp, &xx); - *ip = xx; - return ENOERR; -#endif -} - -int -ncx_get_short_float(const void *xp, float *ip) -{ - ix_short xx; - get_ix_short(xp, &xx); - *ip = xx; -#if 0 /* TODO: determine when necessary */ - if(xx > FLT_MAX || xx < (-FLT_MAX)) - return NC_ERANGE; -#endif - return ENOERR; -} - -int -ncx_get_short_double(const void *xp, double *ip) -{ - /* assert(DBL_MAX >= X_SHORT_MAX); */ - ix_short xx; - get_ix_short(xp, &xx); - *ip = xx; - return ENOERR; -} - -int -ncx_put_short_schar(void *xp, const schar *ip) -{ - uchar *cp = (uchar *) xp; - if(*ip & 0x80) - *cp++ = 0xff; - else - *cp++ = 0; - *cp = (uchar)*ip; - return ENOERR; -} - -int -ncx_put_short_uchar(void *xp, const uchar *ip) -{ - uchar *cp = (uchar *) xp; - *cp++ = 0; - *cp = *ip; - return ENOERR; -} - -int -ncx_put_short_short(void *xp, const short *ip) -{ -#if SIZEOF_IX_SHORT == SIZEOF_SHORT && X_SHORT_MAX == SHORT_MAX - put_ix_short(xp, (const ix_short *)ip); - return ENOERR; -#else - ix_short xx = (ix_short)*ip; - put_ix_short(xp, &xx); -# if X_SHORT_MAX < SHORT_MAX - if(*ip > X_SHORT_MAX || *ip < X_SHORT_MIN) - return NC_ERANGE; -# endif - return ENOERR; -#endif -} - -int -ncx_put_short_int(void *xp, const int *ip) -{ -#if SIZEOF_IX_SHORT == SIZEOF_INT && X_SHORT_MAX == INT_MAX - put_ix_short(xp, (const ix_short *)ip); - return ENOERR; -#else - ix_short xx = (ix_short)*ip; - put_ix_short(xp, &xx); -# if X_SHORT_MAX < INT_MAX - if(*ip > X_SHORT_MAX || *ip < X_SHORT_MIN) - return NC_ERANGE; -# endif - return ENOERR; -#endif -} - -int -ncx_put_short_long(void *xp, const long *ip) -{ -#if SIZEOF_IX_SHORT == SIZEOF_LONG && X_SHORT_MAX == LONG_MAX - put_ix_short(xp, (const ix_short *)ip); - return ENOERR; -#else - ix_short xx = (ix_short)*ip; - put_ix_short(xp, &xx); -# if X_SHORT_MAX < LONG_MAX - if(*ip > X_SHORT_MAX || *ip < X_SHORT_MIN) - return NC_ERANGE; -# endif - return ENOERR; -#endif -} - -int -ncx_put_short_float(void *xp, const float *ip) -{ - ix_short xx = *ip; - put_ix_short(xp, &xx); - if(*ip > X_SHORT_MAX || *ip < X_SHORT_MIN) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_put_short_double(void *xp, const double *ip) -{ - ix_short xx = *ip; - put_ix_short(xp, &xx); - if(*ip > X_SHORT_MAX || *ip < X_SHORT_MIN) - return NC_ERANGE; - return ENOERR; -} - -/* x_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; - - *ip = *cp++ << 24; -#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++ = (*ip) >> 24; - *cp++ = ((*ip) & 0x00ff0000) >> 16; - *cp++ = ((*ip) & 0x0000ff00) >> 8; - *cp = ((*ip) & 0x000000ff); -} - - -int -ncx_get_int_schar(const void *xp, schar *ip) -{ - ix_int xx; - get_ix_int(xp, &xx); - *ip = xx; - if(xx > SCHAR_MAX || xx < SCHAR_MIN) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_get_int_uchar(const void *xp, uchar *ip) -{ - ix_int xx; - get_ix_int(xp, &xx); - *ip = xx; - if(xx > UCHAR_MAX || xx < 0) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_get_int_short(const void *xp, short *ip) -{ -#if SIZEOF_IX_INT == SIZEOF_SHORT && IX_INT_MAX == SHORT_MAX - get_ix_int(xp, (ix_int *)ip); - return ENOERR; -#else - ix_int xx; - get_ix_int(xp, &xx); - *ip = xx; -# if IX_INT_MAX > SHORT_MAX - if(xx > SHORT_MAX || xx < SHORT_MIN) - return NC_ERANGE; -# endif - return ENOERR; -#endif -} - -int -ncx_get_int_int(const void *xp, int *ip) -{ -#if SIZEOF_IX_INT == SIZEOF_INT && IX_INT_MAX == INT_MAX - get_ix_int(xp, (ix_int *)ip); - return ENOERR; -#else - ix_int xx; - get_ix_int(xp, &xx); - *ip = xx; -# if IX_INT_MAX > INT_MAX - if(xx > INT_MAX || xx < INT_MIN) - return NC_ERANGE; -# endif - return ENOERR; -#endif -} - -int -ncx_get_int_long(const void *xp, long *ip) -{ -#if SIZEOF_IX_INT == SIZEOF_LONG && IX_INT_MAX == LONG_MAX - get_ix_int(xp, (ix_int *)ip); - return ENOERR; -#else - ix_int xx; - get_ix_int(xp, &xx); - *ip = xx; -# if IX_INT_MAX > LONG_MAX /* unlikely */ - if(xx > LONG_MAX || xx < LONG_MIN) - return NC_ERANGE; -# endif - return ENOERR; -#endif -} - -int -ncx_get_int_float(const void *xp, float *ip) -{ - ix_int xx; - get_ix_int(xp, &xx); - *ip = xx; -#if 0 /* TODO: determine when necessary */ - if(xx > FLT_MAX || xx < (-FLT_MAX)) - return NC_ERANGE; -#endif - return ENOERR; -} - -int -ncx_get_int_double(const void *xp, double *ip) -{ - /* assert((DBL_MAX >= X_INT_MAX); */ - ix_int xx; - get_ix_int(xp, &xx); - *ip = xx; - return ENOERR; -} - -int -ncx_put_int_schar(void *xp, const schar *ip) -{ - uchar *cp = (uchar *) xp; - if(*ip & 0x80) - { - *cp++ = 0xff; - *cp++ = 0xff; - *cp++ = 0xff; - } - else - { - *cp++ = 0x00; - *cp++ = 0x00; - *cp++ = 0x00; - } - *cp = (uchar)*ip; - return ENOERR; -} - -int -ncx_put_int_uchar(void *xp, const uchar *ip) -{ - uchar *cp = (uchar *) xp; - *cp++ = 0x00; - *cp++ = 0x00; - *cp++ = 0x00; - *cp = *ip; - return ENOERR; -} - -int -ncx_put_int_short(void *xp, const short *ip) -{ -#if SIZEOF_IX_INT == SIZEOF_SHORT && IX_INT_MAX == SHORT_MAX - put_ix_int(xp, (ix_int *)ip); - return ENOERR; -#else - ix_int xx = (ix_int)(*ip); - put_ix_int(xp, &xx); -# if IX_INT_MAX < SHORT_MAX - if(*ip > X_INT_MAX || *ip < X_INT_MIN) - return NC_ERANGE; -# endif - return ENOERR; -#endif -} - -int -ncx_put_int_int(void *xp, const int *ip) -{ -#if SIZEOF_IX_INT == SIZEOF_INT && IX_INT_MAX == INT_MAX - put_ix_int(xp, (ix_int *)ip); - return ENOERR; -#else - ix_int xx = (ix_int)(*ip); - put_ix_int(xp, &xx); -# if IX_INT_MAX < INT_MAX - if(*ip > X_INT_MAX || *ip < X_INT_MIN) - return NC_ERANGE; -# endif - return ENOERR; -#endif -} - -int -ncx_put_int_long(void *xp, const long *ip) -{ -#if SIZEOF_IX_INT == SIZEOF_LONG && IX_INT_MAX == LONG_MAX - put_ix_int(xp, (ix_int *)ip); - return ENOERR; -#else - ix_int xx = (ix_int)(*ip); - put_ix_int(xp, &xx); -# if IX_INT_MAX < LONG_MAX - if(*ip > X_INT_MAX || *ip < X_INT_MIN) - return NC_ERANGE; -# endif - return ENOERR; -#endif -} - -int -ncx_put_int_float(void *xp, const float *ip) -{ - ix_int xx = (ix_int)(*ip); - put_ix_int(xp, &xx); - if(*ip > (double)X_INT_MAX || *ip < (double)X_INT_MIN) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_put_int_double(void *xp, const double *ip) -{ - ix_int xx = (ix_int)(*ip); - put_ix_int(xp, &xx); - if(*ip > X_INT_MAX || *ip < X_INT_MIN) - return NC_ERANGE; - return ENOERR; -} - - -/* x_float */ - -#if X_SIZEOF_FLOAT == SIZEOF_FLOAT && !defined(NO_IEEE_FLOAT) - -static void -get_ix_float(const void *xp, float *ip) -{ -#ifdef WORDS_BIGENDIAN - (void) memcpy(ip, xp, sizeof(float)); -#else - swap4b(ip, xp); -#endif -} - -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 vax - -/* 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 */ -}; - -static void -get_ix_float(const void *xp, float *ip) -{ - struct vax_single *const vsp = (struct vax_single *) ip; - const struct ieee_single *const isp = - (const struct ieee_single *) xp; - unsigned exp = isp->exp_hi << 1 | isp->exp_lo; - - switch(exp) { - case 0 : - /* ieee subnormal */ - if(isp->mant_hi == min.ieee.mant_hi - && isp->mant_lo_hi == min.ieee.mant_lo_hi - && isp->mant_lo_lo == min.ieee.mant_lo_lo) - { - *vsp = min.s; - } - else - { - unsigned mantissa = (isp->mant_hi << 16) - | isp->mant_lo_hi << 8 - | isp->mant_lo_lo; - unsigned tmp = mantissa >> 20; - if(tmp >= 4) { - vsp->exp = 2; - } else if (tmp >= 2) { - vsp->exp = 1; - } else { - *vsp = min.s; - break; - } /* else */ - tmp = mantissa - (1 << (20 + vsp->exp )); - tmp <<= 3 - vsp->exp; - vsp->mantissa2 = tmp; - vsp->mantissa1 = (tmp >> 16); - } - break; - case 0xfe : - case 0xff : - *vsp = max.s; - break; - default : - vsp->exp = exp - IEEE_SNG_BIAS + VAX_SNG_BIAS; - vsp->mantissa2 = isp->mant_lo_hi << 8 | isp->mant_lo_lo; - vsp->mantissa1 = isp->mant_hi; - } - - vsp->sign = isp->sign; - -} - - -static void -put_ix_float(void *xp, const float *ip) -{ - const struct vax_single *const vsp = - (const struct vax_single *)ip; - struct ieee_single *const isp = (struct ieee_single *) xp; - - switch(vsp->exp){ - case 0 : - /* all vax float with zero exponent map to zero */ - *isp = min.ieee; - break; - case 2 : - case 1 : - { - /* These will map to subnormals */ - unsigned mantissa = (vsp->mantissa1 << 16) - | vsp->mantissa2; - mantissa >>= 3 - vsp->exp; - mantissa += (1 << (20 + vsp->exp)); - isp->mant_lo_lo = mantissa; - isp->mant_lo_hi = mantissa >> 8; - isp->mant_hi = mantissa >> 16; - isp->exp_lo = 0; - isp->exp_hi = 0; - } - break; - case 0xff : /* max.s.exp */ - if( vsp->mantissa2 == max.s.mantissa2 - && vsp->mantissa1 == max.s.mantissa1) - { - /* map largest vax float to ieee infinity */ - *isp = max.ieee; - break; - } /* else, fall thru */ - default : - { - unsigned exp = vsp->exp - VAX_SNG_BIAS + IEEE_SNG_BIAS; - isp->exp_hi = exp >> 1; - isp->exp_lo = exp; - isp->mant_lo_lo = vsp->mantissa2; - isp->mant_lo_hi = vsp->mantissa2 >> 8; - isp->mant_hi = vsp->mantissa1; - } - } - - isp->sign = vsp->sign; - -} - - /* vax */ -#elif defined(_CRAY) - -/* - * Return the number of bytes until the next "word" boundary - * N.B. This is based on the very wierd 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; - - -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; - - if(isp->exp == 0) - { - /* ieee subnormal */ - *ip = (double)isp->mant; - if(isp->mant != 0) - { - csp->exp -= (ieee_single_bias + 22); - } - } - else - { - csp->exp = isp->exp + cs_ieis_bias + 1; - csp->mant = isp->mant << (48 - 1 - 23); - csp->mant |= (1 << (48 - 1)); - } - csp->sign = isp->sign; - - - } - else - { - const ieee_single_lo *isp = (const ieee_single_lo *) xp; - cray_single *csp = (cray_single *) ip; - - if(isp->exp == 0) - { - /* ieee subnormal */ - *ip = (double)isp->mant; - if(isp->mant != 0) - { - csp->exp -= (ieee_single_bias + 22); - } - } - else - { - csp->exp = isp->exp + cs_ieis_bias + 1; - csp->mant = isp->mant << (48 - 1 - 23); - csp->mant |= (1 << (48 - 1)); - } - csp->sign = isp->sign; - - - } -} - -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; - int ieee_exp = csp->exp - cs_ieis_bias -1; - - isp->sign = csp->sign; - - if(ieee_exp >= 0xff) - { - /* NC_ERANGE => ieee Inf */ - isp->exp = 0xff; - isp->mant = 0x0; - } - else if(ieee_exp > 0) - { - /* normal ieee representation */ - isp->exp = ieee_exp; - /* assumes cray rep is in normal form */ - assert(csp->mant & 0x800000000000); - isp->mant = (((csp->mant << 1) & - 0xffffffffffff) >> (48 - 23)); - } - else if(ieee_exp > -23) - { - /* ieee subnormal, right */ - const int rshift = (48 - 23 - ieee_exp); - - isp->mant = csp->mant >> rshift; - -#if 0 - if(csp->mant & (1 << (rshift -1))) - { - /* round up */ - isp->mant++; - } -#endif - - isp->exp = 0; - } - else - { - /* smaller than ieee can represent */ - isp->exp = 0; - isp->mant = 0; - } - - } - else - { - ieee_single_lo *isp = (ieee_single_lo*)xp; - const cray_single *csp = (const cray_single *) ip; - int ieee_exp = csp->exp - cs_ieis_bias -1; - - isp->sign = csp->sign; - - if(ieee_exp >= 0xff) - { - /* NC_ERANGE => ieee Inf */ - isp->exp = 0xff; - isp->mant = 0x0; - } - else if(ieee_exp > 0) - { - /* normal ieee representation */ - isp->exp = ieee_exp; - /* assumes cray rep is in normal form */ - assert(csp->mant & 0x800000000000); - isp->mant = (((csp->mant << 1) & - 0xffffffffffff) >> (48 - 23)); - } - else if(ieee_exp > -23) - { - /* ieee subnormal, right */ - const int rshift = (48 - 23 - ieee_exp); - - isp->mant = csp->mant >> rshift; - -#if 0 - if(csp->mant & (1 << (rshift -1))) - { - /* round up */ - isp->mant++; - } -#endif - - isp->exp = 0; - } - else - { - /* smaller than ieee can represent */ - isp->exp = 0; - isp->mant = 0; - } - - } -} - -#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 - -#elif _SX && _FLOAT2 -static void -get_ix_float(const void *xp, float *ip) -{ - const int ncnv = ie3_fl2(xp, ip, 4, 8, 1); -} - -static void -put_ix_float(void *xp, const float *ip) -{ - const int ncnv = fl2_ie3(ip, xp, 8, 4, 1); -} -#else -#error "ix_float implementation" -#endif - - -int -ncx_get_float_schar(const void *xp, schar *ip) -{ - float xx; - get_ix_float(xp, &xx); - *ip = (schar) xx; - if(xx > SCHAR_MAX || xx < SCHAR_MIN) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_get_float_uchar(const void *xp, uchar *ip) -{ - float xx; - get_ix_float(xp, &xx); - *ip = (uchar) xx; - if(xx > UCHAR_MAX || xx < 0) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_get_float_short(const void *xp, short *ip) -{ - float xx; - get_ix_float(xp, &xx); - *ip = (short) xx; - if(xx > SHORT_MAX || xx < SHORT_MIN) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_get_float_int(const void *xp, int *ip) -{ - float xx; - get_ix_float(xp, &xx); - *ip = (int) xx; - if(xx > (double)INT_MAX || xx < (double)INT_MIN) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_get_float_long(const void *xp, long *ip) -{ - float xx; - get_ix_float(xp, &xx); - *ip = (long) xx; - if(xx > LONG_MAX || xx < LONG_MIN) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_get_float_float(const void *xp, float *ip) -{ - /* TODO */ - get_ix_float(xp, ip); - return ENOERR; -} - -int -ncx_get_float_double(const void *xp, double *ip) -{ - /* TODO */ - float xx; - get_ix_float(xp, &xx); - *ip = xx; - return ENOERR; -} - - -int -ncx_put_float_schar(void *xp, const schar *ip) -{ - float xx = (float) *ip; - put_ix_float(xp, &xx); - return ENOERR; -} - -int -ncx_put_float_uchar(void *xp, const uchar *ip) -{ - float xx = (float) *ip; - put_ix_float(xp, &xx); - return ENOERR; -} - -int -ncx_put_float_short(void *xp, const short *ip) -{ - float xx = (float) *ip; - put_ix_float(xp, &xx); -#if 0 /* TODO: figure this out */ - if((float)(*ip) > X_FLOAT_MAX || (float)(*ip) < X_FLOAT_MIN) - return NC_ERANGE; -#endif - return ENOERR; -} - -int -ncx_put_float_int(void *xp, const int *ip) -{ - float xx = (float) *ip; - put_ix_float(xp, &xx); -#if 1 /* TODO: figure this out */ - if((float)(*ip) > X_FLOAT_MAX || (float)(*ip) < X_FLOAT_MIN) - return NC_ERANGE; -#endif - return ENOERR; -} - -int -ncx_put_float_long(void *xp, const long *ip) -{ - float xx = (float) *ip; - put_ix_float(xp, &xx); -#if 1 /* TODO: figure this out */ - if((float)(*ip) > X_FLOAT_MAX || (float)(*ip) < X_FLOAT_MIN) - return NC_ERANGE; -#endif - return ENOERR; -} - -int -ncx_put_float_float(void *xp, const float *ip) -{ - put_ix_float(xp, ip); -#ifdef NO_IEEE_FLOAT - if(*ip > X_FLOAT_MAX || *ip < X_FLOAT_MIN) - return NC_ERANGE; -#endif - return ENOERR; -} - -int -ncx_put_float_double(void *xp, const double *ip) -{ - float xx = (float) *ip; - put_ix_float(xp, &xx); - if(*ip > X_FLOAT_MAX || *ip < X_FLOAT_MIN) - return NC_ERANGE; - return ENOERR; -} - -/* x_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 vax - -/* 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 */ -}; - - -static void -get_ix_double(const void *xp, double *ip) -{ - struct vax_double *const vdp = - (struct vax_double *)ip; - const struct ieee_double *const idp = - (const struct ieee_double *) xp; - { - const struct dbl_limits *lim; - int ii; - for (ii = 0, lim = dbl_limits; - ii < sizeof(dbl_limits)/sizeof(struct dbl_limits); - ii++, lim++) - { - if ((idp->mant_lo == lim->ieee.mant_lo) - && (idp->mant_4 == lim->ieee.mant_4) - && (idp->mant_5 == lim->ieee.mant_5) - && (idp->mant_6 == lim->ieee.mant_6) - && (idp->exp_lo == lim->ieee.exp_lo) - && (idp->exp_hi == lim->ieee.exp_hi) - ) - { - *vdp = lim->d; - goto doneit; - } - } - } - { - unsigned exp = idp->exp_hi << 4 | idp->exp_lo; - vdp->exp = exp - IEEE_DBL_BIAS + VAX_DBL_BIAS; - } - { - unsigned mant_hi = ((idp->mant_6 << 16) - | (idp->mant_5 << 8) - | idp->mant_4); - unsigned mant_lo = SWAP4(idp->mant_lo); - vdp->mantissa1 = (mant_hi >> 13); - vdp->mantissa2 = ((mant_hi & MASK(13)) << 3) - | (mant_lo >> 29); - vdp->mantissa3 = (mant_lo >> 13); - vdp->mantissa4 = (mant_lo << 3); - } - doneit: - vdp->sign = idp->sign; - -} - - -static void -put_ix_double(void *xp, const double *ip) -{ - const struct vax_double *const vdp = - (const struct vax_double *)ip; - struct ieee_double *const idp = - (struct ieee_double *) xp; - - if ((vdp->mantissa4 > (dbl_limits[0].d.mantissa4 - 3)) && - (vdp->mantissa3 == dbl_limits[0].d.mantissa3) && - (vdp->mantissa2 == dbl_limits[0].d.mantissa2) && - (vdp->mantissa1 == dbl_limits[0].d.mantissa1) && - (vdp->exp == dbl_limits[0].d.exp)) - { - *idp = dbl_limits[0].ieee; - goto shipit; - } - if ((vdp->mantissa4 == dbl_limits[1].d.mantissa4) && - (vdp->mantissa3 == dbl_limits[1].d.mantissa3) && - (vdp->mantissa2 == dbl_limits[1].d.mantissa2) && - (vdp->mantissa1 == dbl_limits[1].d.mantissa1) && - (vdp->exp == dbl_limits[1].d.exp)) - { - *idp = dbl_limits[1].ieee; - goto shipit; - } - - { - unsigned exp = vdp->exp - VAX_DBL_BIAS + IEEE_DBL_BIAS; - - unsigned mant_lo = ((vdp->mantissa2 & MASK(3)) << 29) | - (vdp->mantissa3 << 13) | - ((vdp->mantissa4 >> 3) & MASK(13)); - - unsigned mant_hi = (vdp->mantissa1 << 13) - | (vdp->mantissa2 >> 3); - - if((vdp->mantissa4 & 7) > 4) - { - /* round up */ - mant_lo++; - if(mant_lo == 0) - { - mant_hi++; - if(mant_hi > 0xffffff) - { - mant_hi = 0; - exp++; - } - } - } - - idp->mant_lo = SWAP4(mant_lo); - idp->mant_6 = mant_hi >> 16; - idp->mant_5 = (mant_hi & 0xff00) >> 8; - idp->mant_4 = mant_hi; - idp->exp_hi = exp >> 4; - idp->exp_lo = exp; - } - - shipit: - idp->sign = vdp->sign; - -} - - /* vax */ -#elif defined(_CRAY) - -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 */ - const int lshift = (52 - 48) + ieee_exp; - idp->mant = csp->mant << lshift; - idp->exp = 0; - } - else if(ieee_exp >= -52) - { - /* ieee subnormal, right */ - 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; - } -} -#elif _SX && _FLOAT2 -static void -get_ix_double(const void *xp, double *ip) -{ - const int ncnv = ie3_fl2(xp, ip, 8, 8, 1); -} - -static void -put_ix_double(void *xp, const double *ip) -{ - const int ncnv = fl2_ie3(ip, xp, 8, 8, 1); -} -#else -#error "ix_double implementation" -#endif - -int -ncx_get_double_schar(const void *xp, schar *ip) -{ - double xx; - get_ix_double(xp, &xx); - *ip = (schar) xx; - if(xx > SCHAR_MAX || xx < SCHAR_MIN) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_get_double_uchar(const void *xp, uchar *ip) -{ - double xx; - get_ix_double(xp, &xx); - *ip = (uchar) xx; - if(xx > UCHAR_MAX || xx < 0) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_get_double_short(const void *xp, short *ip) -{ - double xx; - get_ix_double(xp, &xx); - *ip = (short) xx; - if(xx > SHORT_MAX || xx < SHORT_MIN) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_get_double_int(const void *xp, int *ip) -{ - double xx; - get_ix_double(xp, &xx); - *ip = (int) xx; - if(xx > INT_MAX || xx < INT_MIN) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_get_double_long(const void *xp, long *ip) -{ - double xx; - get_ix_double(xp, &xx); - *ip = (long) xx; - if(xx > LONG_MAX || xx < LONG_MIN) - return NC_ERANGE; - return ENOERR; -} - -int -ncx_get_double_float(const void *xp, float *ip) -{ - double xx; - get_ix_double(xp, &xx); - if(xx > FLT_MAX || xx < (-FLT_MAX)) - { - *ip = FLT_MAX; - return NC_ERANGE; - } - if(xx < (-FLT_MAX)) - { - *ip = (-FLT_MAX); - return NC_ERANGE; - } - *ip = (float) xx; - return ENOERR; -} - -int -ncx_get_double_double(const void *xp, double *ip) -{ - /* TODO */ - get_ix_double(xp, ip); - return ENOERR; -} - - -int -ncx_put_double_schar(void *xp, const schar *ip) -{ - double xx = (double) *ip; - put_ix_double(xp, &xx); - return ENOERR; -} - -int -ncx_put_double_uchar(void *xp, const uchar *ip) -{ - double xx = (double) *ip; - put_ix_double(xp, &xx); - return ENOERR; -} - -int -ncx_put_double_short(void *xp, const short *ip) -{ - double xx = (double) *ip; - put_ix_double(xp, &xx); -#if 0 /* TODO: figure this out */ - if((double)(*ip) > X_DOUBLE_MAX || (double)(*ip) < X_DOUBLE_MIN) - return NC_ERANGE; -#endif - return ENOERR; -} - -int -ncx_put_double_int(void *xp, const int *ip) -{ - double xx = (double) *ip; - put_ix_double(xp, &xx); -#if 0 /* TODO: figure this out */ - if((double)(*ip) > X_DOUBLE_MAX || (double)(*ip) < X_DOUBLE_MIN) - return NC_ERANGE; -#endif - return ENOERR; -} - -int -ncx_put_double_long(void *xp, const long *ip) -{ - double xx = (double) *ip; - put_ix_double(xp, &xx); -#if 1 /* TODO: figure this out */ - if((double)(*ip) > X_DOUBLE_MAX || (double)(*ip) < X_DOUBLE_MIN) - return NC_ERANGE; -#endif - return ENOERR; -} - -int -ncx_put_double_float(void *xp, const float *ip) -{ - double xx = (double) *ip; - put_ix_double(xp, &xx); -#if 1 /* TODO: figure this out */ - if((double)(*ip) > X_DOUBLE_MAX || (double)(*ip) < X_DOUBLE_MIN) - return NC_ERANGE; -#endif - return ENOERR; -} - -int -ncx_put_double_double(void *xp, const double *ip) -{ - put_ix_double(xp, ip); -#ifdef NO_IEEE_FLOAT - if(*ip > X_DOUBLE_MAX || *ip < X_DOUBLE_MIN) - return NC_ERANGE; -#endif - return ENOERR; -} - - -/* 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 ENOERR; -} - -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 ENOERR; -} - -/* 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 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) & 0x00ff000000000000ULL) >> 48); - *cp++ = (uchar)(((*lp) & 0x0000ff0000000000ULL) >> 40); - *cp++ = (uchar)(((*lp) & 0x000000ff00000000ULL) >> 32); - *cp++ = (uchar)(((*lp) & 0x00000000ff000000ULL) >> 24); - *cp++ = (uchar)(((*lp) & 0x0000000000ff0000ULL) >> 16); - *cp++ = (uchar)(((*lp) & 0x000000000000ff00ULL) >> 8); - *cp = (uchar)( (*lp) & 0x00000000000000ffULL); -#endif - } - *xpp = (void *)((char *)(*xpp) + sizeof_off_t); - return ENOERR; -} - -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 = *cp++ << 24; - *lp |= (*cp++ << 16); - *lp |= (*cp++ << 8); - *lp |= *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 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 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 ENOERR; -} - - -/* - * Aggregate numeric conversion functions. - */ - - - -/* schar */ - -int -ncx_getn_schar_schar(const void **xpp, size_t nelems, schar *tp) -{ - (void) memcpy(tp, *xpp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems); - return ENOERR; - -} -int -ncx_getn_schar_uchar(const void **xpp, size_t nelems, uchar *tp) -{ - (void) memcpy(tp, *xpp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems); - return ENOERR; - -} -int -ncx_getn_schar_short(const void **xpp, size_t nelems, short *tp) -{ - schar *xp = (schar *)(*xpp); - - while(nelems-- != 0) - { - *tp++ = *xp++; - } - - *xpp = (const void *)xp; - return ENOERR; -} - -int -ncx_getn_schar_int(const void **xpp, size_t nelems, int *tp) -{ - schar *xp = (schar *)(*xpp); - - while(nelems-- != 0) - { - *tp++ = *xp++; - } - - *xpp = (const void *)xp; - return ENOERR; -} - -int -ncx_getn_schar_long(const void **xpp, size_t nelems, long *tp) -{ - schar *xp = (schar *)(*xpp); - - while(nelems-- != 0) - { - *tp++ = *xp++; - } - - *xpp = (const void *)xp; - return ENOERR; -} - -int -ncx_getn_schar_float(const void **xpp, size_t nelems, float *tp) -{ - schar *xp = (schar *)(*xpp); - - while(nelems-- != 0) - { - *tp++ = *xp++; - } - - *xpp = (const void *)xp; - return ENOERR; -} - -int -ncx_getn_schar_double(const void **xpp, size_t nelems, double *tp) -{ - schar *xp = (schar *)(*xpp); - - while(nelems-- != 0) - { - *tp++ = *xp++; - } - - *xpp = (const void *)xp; - return ENOERR; -} - - -int -ncx_pad_getn_schar_schar(const void **xpp, size_t nelems, schar *tp) -{ - size_t rndup = nelems % X_ALIGN; - - if(rndup) - rndup = X_ALIGN - rndup; - - (void) memcpy(tp, *xpp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems + rndup); - - return ENOERR; - -} -int -ncx_pad_getn_schar_uchar(const void **xpp, size_t nelems, uchar *tp) -{ - size_t rndup = nelems % X_ALIGN; - - if(rndup) - rndup = X_ALIGN - rndup; - - (void) memcpy(tp, *xpp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems + rndup); - - return ENOERR; - -} -int -ncx_pad_getn_schar_short(const void **xpp, size_t nelems, short *tp) -{ - size_t rndup = nelems % X_ALIGN; - schar *xp = (schar *) *xpp; - - if(rndup) - rndup = X_ALIGN - rndup; - - while(nelems-- != 0) - { - *tp++ = *xp++; - } - - *xpp = (void *)(xp + rndup); - return ENOERR; -} - -int -ncx_pad_getn_schar_int(const void **xpp, size_t nelems, int *tp) -{ - size_t rndup = nelems % X_ALIGN; - schar *xp = (schar *) *xpp; - - if(rndup) - rndup = X_ALIGN - rndup; - - while(nelems-- != 0) - { - *tp++ = *xp++; - } - - *xpp = (void *)(xp + rndup); - return ENOERR; -} - -int -ncx_pad_getn_schar_long(const void **xpp, size_t nelems, long *tp) -{ - size_t rndup = nelems % X_ALIGN; - schar *xp = (schar *) *xpp; - - if(rndup) - rndup = X_ALIGN - rndup; - - while(nelems-- != 0) - { - *tp++ = *xp++; - } - - *xpp = (void *)(xp + rndup); - return ENOERR; -} - -int -ncx_pad_getn_schar_float(const void **xpp, size_t nelems, float *tp) -{ - size_t rndup = nelems % X_ALIGN; - schar *xp = (schar *) *xpp; - - if(rndup) - rndup = X_ALIGN - rndup; - - while(nelems-- != 0) - { - *tp++ = *xp++; - } - - *xpp = (void *)(xp + rndup); - return ENOERR; -} - -int -ncx_pad_getn_schar_double(const void **xpp, size_t nelems, double *tp) -{ - size_t rndup = nelems % X_ALIGN; - schar *xp = (schar *) *xpp; - - if(rndup) - rndup = X_ALIGN - rndup; - - while(nelems-- != 0) - { - *tp++ = *xp++; - } - - *xpp = (void *)(xp + rndup); - return ENOERR; -} - - -int -ncx_putn_schar_schar(void **xpp, size_t nelems, const schar *tp) -{ - (void) memcpy(*xpp, tp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems); - - return ENOERR; - -} -int -ncx_putn_schar_uchar(void **xpp, size_t nelems, const uchar *tp) -{ - (void) memcpy(*xpp, tp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems); - - return ENOERR; - -} -int -ncx_putn_schar_short(void **xpp, size_t nelems, const short *tp) -{ - int status = ENOERR; - schar *xp = (schar *) *xpp; - - while(nelems-- != 0) - { - if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN) - status = NC_ERANGE; - *xp++ = (schar) *tp++; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_schar_int(void **xpp, size_t nelems, const int *tp) -{ - int status = ENOERR; - schar *xp = (schar *) *xpp; - - while(nelems-- != 0) - { - if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN) - status = NC_ERANGE; - *xp++ = (schar) *tp++; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_schar_long(void **xpp, size_t nelems, const long *tp) -{ - int status = ENOERR; - schar *xp = (schar *) *xpp; - - while(nelems-- != 0) - { - if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN) - status = NC_ERANGE; - *xp++ = (schar) *tp++; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_schar_float(void **xpp, size_t nelems, const float *tp) -{ - int status = ENOERR; - schar *xp = (schar *) *xpp; - - while(nelems-- != 0) - { - if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN) - status = NC_ERANGE; - *xp++ = (schar) *tp++; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_schar_double(void **xpp, size_t nelems, const double *tp) -{ - int status = ENOERR; - schar *xp = (schar *) *xpp; - - while(nelems-- != 0) - { - if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN) - status = NC_ERANGE; - *xp++ = (schar) *tp++; - } - - *xpp = (void *)xp; - return status; -} - - -int -ncx_pad_putn_schar_schar(void **xpp, size_t nelems, const schar *tp) -{ - size_t rndup = nelems % X_ALIGN; - - if(rndup) - rndup = X_ALIGN - rndup; - - (void) memcpy(*xpp, tp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems); - - if(rndup) - { - (void) memcpy(*xpp, nada, rndup); - *xpp = (void *)((char *)(*xpp) + rndup); - } - - return ENOERR; - -} -int -ncx_pad_putn_schar_uchar(void **xpp, size_t nelems, const uchar *tp) -{ - size_t rndup = nelems % X_ALIGN; - - if(rndup) - rndup = X_ALIGN - rndup; - - (void) memcpy(*xpp, tp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems); - - if(rndup) - { - (void) memcpy(*xpp, nada, rndup); - *xpp = (void *)((char *)(*xpp) + rndup); - } - - return ENOERR; - -} -int -ncx_pad_putn_schar_short(void **xpp, size_t nelems, const short *tp) -{ - int status = ENOERR; - size_t rndup = nelems % X_ALIGN; - schar *xp = (schar *) *xpp; - - if(rndup) - rndup = X_ALIGN - rndup; - - while(nelems-- != 0) - { - /* N.B. schar as signed */ - if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN) - status = NC_ERANGE; - *xp++ = (schar) *tp++; - } - - - if(rndup) - { - (void) memcpy(xp, nada, rndup); - xp += rndup; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_putn_schar_int(void **xpp, size_t nelems, const int *tp) -{ - int status = ENOERR; - size_t rndup = nelems % X_ALIGN; - schar *xp = (schar *) *xpp; - - if(rndup) - rndup = X_ALIGN - rndup; - - while(nelems-- != 0) - { - /* N.B. schar as signed */ - if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN) - status = NC_ERANGE; - *xp++ = (schar) *tp++; - } - - - if(rndup) - { - (void) memcpy(xp, nada, rndup); - xp += rndup; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_putn_schar_long(void **xpp, size_t nelems, const long *tp) -{ - int status = ENOERR; - size_t rndup = nelems % X_ALIGN; - schar *xp = (schar *) *xpp; - - if(rndup) - rndup = X_ALIGN - rndup; - - while(nelems-- != 0) - { - /* N.B. schar as signed */ - if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN) - status = NC_ERANGE; - *xp++ = (schar) *tp++; - } - - - if(rndup) - { - (void) memcpy(xp, nada, rndup); - xp += rndup; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_putn_schar_float(void **xpp, size_t nelems, const float *tp) -{ - int status = ENOERR; - size_t rndup = nelems % X_ALIGN; - schar *xp = (schar *) *xpp; - - if(rndup) - rndup = X_ALIGN - rndup; - - while(nelems-- != 0) - { - /* N.B. schar as signed */ - if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN) - status = NC_ERANGE; - *xp++ = (schar) *tp++; - } - - - if(rndup) - { - (void) memcpy(xp, nada, rndup); - xp += rndup; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_putn_schar_double(void **xpp, size_t nelems, const double *tp) -{ - int status = ENOERR; - size_t rndup = nelems % X_ALIGN; - schar *xp = (schar *) *xpp; - - if(rndup) - rndup = X_ALIGN - rndup; - - while(nelems-- != 0) - { - /* N.B. schar as signed */ - if(*tp > X_SCHAR_MAX || *tp < X_SCHAR_MIN) - status = NC_ERANGE; - *xp++ = (schar) *tp++; - } - - - if(rndup) - { - (void) memcpy(xp, nada, rndup); - xp += rndup; - } - - *xpp = (void *)xp; - return status; -} - - - -/* short */ - -int -ncx_getn_short_schar(const void **xpp, size_t nelems, schar *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - const int lstatus = ncx_get_short_schar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_short_uchar(const void **xpp, size_t nelems, uchar *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - const int lstatus = ncx_get_short_uchar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -#if X_SIZEOF_SHORT == SIZEOF_SHORT -/* optimized version */ -int -ncx_getn_short_short(const void **xpp, size_t nelems, short *tp) -{ -# if WORDS_BIGENDIAN - (void) memcpy(tp, *xpp, nelems * sizeof(short)); -# else - swapn2b(tp, *xpp, nelems); -# endif - *xpp = (const void *)((const char *)(*xpp) + nelems * X_SIZEOF_SHORT); - return ENOERR; -} -#else -int -ncx_getn_short_short(const void **xpp, size_t nelems, short *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - const int lstatus = ncx_get_short_short(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -#endif -int -ncx_getn_short_int(const void **xpp, size_t nelems, int *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - const int lstatus = ncx_get_short_int(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_short_long(const void **xpp, size_t nelems, long *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - const int lstatus = ncx_get_short_long(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_short_float(const void **xpp, size_t nelems, float *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - const int lstatus = ncx_get_short_float(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_short_double(const void **xpp, size_t nelems, double *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - const int lstatus = ncx_get_short_double(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - - -int -ncx_pad_getn_short_schar(const void **xpp, size_t nelems, schar *tp) -{ - const size_t rndup = nelems % 2; - - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - const int lstatus = ncx_get_short_schar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - if(rndup != 0) - xp += X_SIZEOF_SHORT; - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_getn_short_uchar(const void **xpp, size_t nelems, uchar *tp) -{ - const size_t rndup = nelems % 2; - - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - const int lstatus = ncx_get_short_uchar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - if(rndup != 0) - xp += X_SIZEOF_SHORT; - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_getn_short_short(const void **xpp, size_t nelems, short *tp) -{ - const size_t rndup = nelems % 2; - - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - const int lstatus = ncx_get_short_short(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - if(rndup != 0) - xp += X_SIZEOF_SHORT; - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_getn_short_int(const void **xpp, size_t nelems, int *tp) -{ - const size_t rndup = nelems % 2; - - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - const int lstatus = ncx_get_short_int(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - if(rndup != 0) - xp += X_SIZEOF_SHORT; - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_getn_short_long(const void **xpp, size_t nelems, long *tp) -{ - const size_t rndup = nelems % 2; - - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - const int lstatus = ncx_get_short_long(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - if(rndup != 0) - xp += X_SIZEOF_SHORT; - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_getn_short_float(const void **xpp, size_t nelems, float *tp) -{ - const size_t rndup = nelems % 2; - - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - const int lstatus = ncx_get_short_float(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - if(rndup != 0) - xp += X_SIZEOF_SHORT; - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_getn_short_double(const void **xpp, size_t nelems, double *tp) -{ - const size_t rndup = nelems % 2; - - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - const int lstatus = ncx_get_short_double(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - if(rndup != 0) - xp += X_SIZEOF_SHORT; - - *xpp = (void *)xp; - return status; -} - - -int -ncx_putn_short_schar(void **xpp, size_t nelems, const schar *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - int lstatus = ncx_put_short_schar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_short_uchar(void **xpp, size_t nelems, const uchar *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - int lstatus = ncx_put_short_uchar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -#if X_SIZEOF_SHORT == SIZEOF_SHORT -/* optimized version */ -int -ncx_putn_short_short(void **xpp, size_t nelems, const short *tp) -{ -# if WORDS_BIGENDIAN - (void) memcpy(*xpp, tp, nelems * X_SIZEOF_SHORT); -# else - swapn2b(*xpp, tp, nelems); -# endif - *xpp = (void *)((char *)(*xpp) + nelems * X_SIZEOF_SHORT); - return ENOERR; -} -#else -int -ncx_putn_short_short(void **xpp, size_t nelems, const short *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - int lstatus = ncx_put_short_short(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -#endif -int -ncx_putn_short_int(void **xpp, size_t nelems, const int *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - int lstatus = ncx_put_short_int(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_short_long(void **xpp, size_t nelems, const long *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - int lstatus = ncx_put_short_long(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_short_float(void **xpp, size_t nelems, const float *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - int lstatus = ncx_put_short_float(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_short_double(void **xpp, size_t nelems, const double *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - int lstatus = ncx_put_short_double(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - - -int -ncx_pad_putn_short_schar(void **xpp, size_t nelems, const schar *tp) -{ - const size_t rndup = nelems % 2; - - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - int lstatus = ncx_put_short_schar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - if(rndup != 0) - { - (void) memcpy(xp, nada, X_SIZEOF_SHORT); - xp += X_SIZEOF_SHORT; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_putn_short_uchar(void **xpp, size_t nelems, const uchar *tp) -{ - const size_t rndup = nelems % 2; - - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - int lstatus = ncx_put_short_uchar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - if(rndup != 0) - { - (void) memcpy(xp, nada, X_SIZEOF_SHORT); - xp += X_SIZEOF_SHORT; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_putn_short_short(void **xpp, size_t nelems, const short *tp) -{ - const size_t rndup = nelems % 2; - - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - int lstatus = ncx_put_short_short(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - if(rndup != 0) - { - (void) memcpy(xp, nada, X_SIZEOF_SHORT); - xp += X_SIZEOF_SHORT; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_putn_short_int(void **xpp, size_t nelems, const int *tp) -{ - const size_t rndup = nelems % 2; - - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - int lstatus = ncx_put_short_int(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - if(rndup != 0) - { - (void) memcpy(xp, nada, X_SIZEOF_SHORT); - xp += X_SIZEOF_SHORT; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_putn_short_long(void **xpp, size_t nelems, const long *tp) -{ - const size_t rndup = nelems % 2; - - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - int lstatus = ncx_put_short_long(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - if(rndup != 0) - { - (void) memcpy(xp, nada, X_SIZEOF_SHORT); - xp += X_SIZEOF_SHORT; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_putn_short_float(void **xpp, size_t nelems, const float *tp) -{ - const size_t rndup = nelems % 2; - - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - int lstatus = ncx_put_short_float(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - if(rndup != 0) - { - (void) memcpy(xp, nada, X_SIZEOF_SHORT); - xp += X_SIZEOF_SHORT; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_pad_putn_short_double(void **xpp, size_t nelems, const double *tp) -{ - const size_t rndup = nelems % 2; - - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_SHORT, tp++) - { - int lstatus = ncx_put_short_double(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - if(rndup != 0) - { - (void) memcpy(xp, nada, X_SIZEOF_SHORT); - xp += X_SIZEOF_SHORT; - } - - *xpp = (void *)xp; - return status; -} - - - -/* int */ - -int -ncx_getn_int_schar(const void **xpp, size_t nelems, schar *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) - { - const int lstatus = ncx_get_int_schar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_int_uchar(const void **xpp, size_t nelems, uchar *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) - { - const int lstatus = ncx_get_int_uchar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_int_short(const void **xpp, size_t nelems, short *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) - { - const int lstatus = ncx_get_int_short(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -#if X_SIZEOF_INT == SIZEOF_INT -/* optimized version */ -int -ncx_getn_int_int(const void **xpp, size_t nelems, int *tp) -{ -# if WORDS_BIGENDIAN - (void) memcpy(tp, *xpp, nelems * sizeof(int)); -# else - swapn4b(tp, *xpp, nelems); -# endif - *xpp = (const void *)((const char *)(*xpp) + nelems * X_SIZEOF_INT); - return ENOERR; -} -#else -int -ncx_getn_int_int(const void **xpp, size_t nelems, int *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) - { - const int lstatus = ncx_get_int_int(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -#endif -#if X_SIZEOF_INT == SIZEOF_LONG -/* optimized version */ -int -ncx_getn_int_long(const void **xpp, size_t nelems, long *tp) -{ -# if WORDS_BIGENDIAN - (void) memcpy(tp, *xpp, nelems * sizeof(long)); -# else - swapn4b(tp, *xpp, nelems); -# endif - *xpp = (const void *)((const char *)(*xpp) + nelems * X_SIZEOF_INT); - return ENOERR; -} -#else -int -ncx_getn_int_long(const void **xpp, size_t nelems, long *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) - { - const int lstatus = ncx_get_int_long(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -#endif -int -ncx_getn_int_float(const void **xpp, size_t nelems, float *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) - { - const int lstatus = ncx_get_int_float(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_int_double(const void **xpp, size_t nelems, double *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) - { - const int lstatus = ncx_get_int_double(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - - -int -ncx_putn_int_schar(void **xpp, size_t nelems, const schar *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) - { - int lstatus = ncx_put_int_schar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_int_uchar(void **xpp, size_t nelems, const uchar *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) - { - int lstatus = ncx_put_int_uchar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_int_short(void **xpp, size_t nelems, const short *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) - { - int lstatus = ncx_put_int_short(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -#if X_SIZEOF_INT == SIZEOF_INT -/* optimized version */ -int -ncx_putn_int_int(void **xpp, size_t nelems, const int *tp) -{ -# if WORDS_BIGENDIAN - (void) memcpy(*xpp, tp, nelems * X_SIZEOF_INT); -# else - swapn4b(*xpp, tp, nelems); -# endif - *xpp = (void *)((char *)(*xpp) + nelems * X_SIZEOF_INT); - return ENOERR; -} -#else -int -ncx_putn_int_int(void **xpp, size_t nelems, const int *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) - { - int lstatus = ncx_put_int_int(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -#endif -#if X_SIZEOF_INT == SIZEOF_LONG -/* optimized version */ -int -ncx_putn_int_long(void **xpp, size_t nelems, const long *tp) -{ -# if WORDS_BIGENDIAN - (void) memcpy(*xpp, tp, nelems * X_SIZEOF_INT); -# else - swapn4b(*xpp, tp, nelems); -# endif - *xpp = (void *)((char *)(*xpp) + nelems * X_SIZEOF_INT); - return ENOERR; -} -#else -int -ncx_putn_int_long(void **xpp, size_t nelems, const long *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) - { - int lstatus = ncx_put_int_long(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -#endif -int -ncx_putn_int_float(void **xpp, size_t nelems, const float *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) - { - int lstatus = ncx_put_int_float(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_int_double(void **xpp, size_t nelems, const double *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_INT, tp++) - { - int lstatus = ncx_put_int_double(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - - - -/* float */ - -int -ncx_getn_float_schar(const void **xpp, size_t nelems, schar *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) - { - const int lstatus = ncx_get_float_schar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_float_uchar(const void **xpp, size_t nelems, uchar *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) - { - const int lstatus = ncx_get_float_uchar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_float_short(const void **xpp, size_t nelems, short *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) - { - const int lstatus = ncx_get_float_short(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_float_int(const void **xpp, size_t nelems, int *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) - { - const int lstatus = ncx_get_float_int(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_float_long(const void **xpp, size_t nelems, long *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) - { - const int lstatus = ncx_get_float_long(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -#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) -{ -# if WORDS_BIGENDIAN - (void) memcpy(tp, *xpp, nelems * sizeof(float)); -# else - swapn4b(tp, *xpp, nelems); -# endif - *xpp = (const void *)((const char *)(*xpp) + nelems * X_SIZEOF_FLOAT); - return ENOERR; -} -#elif vax -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; - const struct ieee_single *const isp = - (const struct ieee_single *) (*xpp); - unsigned exp = isp->exp_hi << 1 | isp->exp_lo; - - switch(exp) { - case 0 : - /* ieee subnormal */ - if(isp->mant_hi == min.ieee.mant_hi - && isp->mant_lo_hi == min.ieee.mant_lo_hi - && isp->mant_lo_lo == min.ieee.mant_lo_lo) - { - *vsp = min.s; - } - else - { - unsigned mantissa = (isp->mant_hi << 16) - | isp->mant_lo_hi << 8 - | isp->mant_lo_lo; - unsigned tmp = mantissa >> 20; - if(tmp >= 4) { - vsp->exp = 2; - } else if (tmp >= 2) { - vsp->exp = 1; - } else { - *vsp = min.s; - break; - } /* else */ - tmp = mantissa - (1 << (20 + vsp->exp )); - tmp <<= 3 - vsp->exp; - vsp->mantissa2 = tmp; - vsp->mantissa1 = (tmp >> 16); - } - break; - case 0xfe : - case 0xff : - *vsp = max.s; - break; - default : - vsp->exp = exp - IEEE_SNG_BIAS + VAX_SNG_BIAS; - vsp->mantissa2 = isp->mant_lo_hi << 8 | isp->mant_lo_lo; - vsp->mantissa1 = isp->mant_hi; - } - - vsp->sign = isp->sign; - - - ip++; - *xpp = (char *)(*xpp) + X_SIZEOF_FLOAT; - } - return ENOERR; -} -#elif _SX && _FLOAT2 -int -ncx_getn_float_float(const void **xpp, size_t nelems, float *tp) -{ - const char *const xp = *xpp; - - const int ncnv = ie3_fl2(xp, tp, 4, 8, nelems); - - *xpp = xp + nelems * X_SIZEOF_FLOAT; - return (nelems == ncnv ? ENOERR : NC_ERANGE); -} -#else -int -ncx_getn_float_float(const void **xpp, size_t nelems, float *tp) -{ - const char *xp = *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) - { - const int lstatus = ncx_get_float_float(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -#endif -int -ncx_getn_float_double(const void **xpp, size_t nelems, double *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) - { - const int lstatus = ncx_get_float_double(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - - -int -ncx_putn_float_schar(void **xpp, size_t nelems, const schar *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) - { - int lstatus = ncx_put_float_schar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_float_uchar(void **xpp, size_t nelems, const uchar *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) - { - int lstatus = ncx_put_float_uchar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_float_short(void **xpp, size_t nelems, const short *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) - { - int lstatus = ncx_put_float_short(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_float_int(void **xpp, size_t nelems, const int *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) - { - int lstatus = ncx_put_float_int(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_float_long(void **xpp, size_t nelems, const long *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) - { - int lstatus = ncx_put_float_long(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -#if X_SIZEOF_FLOAT == SIZEOF_FLOAT && !defined(NO_IEEE_FLOAT) -/* optimized version */ -int -ncx_putn_float_float(void **xpp, size_t nelems, const float *tp) -{ -# if WORDS_BIGENDIAN - (void) memcpy(*xpp, tp, nelems * X_SIZEOF_FLOAT); -# else - swapn4b(*xpp, tp, nelems); -# endif - *xpp = (void *)((char *)(*xpp) + nelems * X_SIZEOF_FLOAT); - return ENOERR; -} -#elif vax -int -ncx_putn_float_float(void **xpp, size_t nfloats, const float *ip) -{ - const float *const end = ip + nfloats; - - while(ip < end) - { - const struct vax_single *const vsp = - (const struct vax_single *)ip; - struct ieee_single *const isp = (struct ieee_single *) (*xpp); - - switch(vsp->exp){ - case 0 : - /* all vax float with zero exponent map to zero */ - *isp = min.ieee; - break; - case 2 : - case 1 : - { - /* These will map to subnormals */ - unsigned mantissa = (vsp->mantissa1 << 16) - | vsp->mantissa2; - mantissa >>= 3 - vsp->exp; - mantissa += (1 << (20 + vsp->exp)); - isp->mant_lo_lo = mantissa; - isp->mant_lo_hi = mantissa >> 8; - isp->mant_hi = mantissa >> 16; - isp->exp_lo = 0; - isp->exp_hi = 0; - } - break; - case 0xff : /* max.s.exp */ - if( vsp->mantissa2 == max.s.mantissa2 - && vsp->mantissa1 == max.s.mantissa1) - { - /* map largest vax float to ieee infinity */ - *isp = max.ieee; - break; - } /* else, fall thru */ - default : - { - unsigned exp = vsp->exp - VAX_SNG_BIAS + IEEE_SNG_BIAS; - isp->exp_hi = exp >> 1; - isp->exp_lo = exp; - isp->mant_lo_lo = vsp->mantissa2; - isp->mant_lo_hi = vsp->mantissa2 >> 8; - isp->mant_hi = vsp->mantissa1; - } - } - - isp->sign = vsp->sign; - - - ip++; - *xpp = (char *)(*xpp) + X_SIZEOF_FLOAT; - } - return ENOERR; -} -#elif _SX && _FLOAT2 -int -ncx_putn_float_float(void **xpp, size_t nelems, const float *tp) -{ - char *const xp = *xpp; - - const int ncnv = fl2_ie3(tp, xp, 8, 4, nelems); - - *xpp = xp + nelems * X_SIZEOF_FLOAT; - return (nelems == ncnv ? ENOERR : NC_ERANGE); -} -#else -int -ncx_putn_float_float(void **xpp, size_t nelems, const float *tp) -{ - char *xp = *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) - { - int lstatus = ncx_put_float_float(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -#endif -int -ncx_putn_float_double(void **xpp, size_t nelems, const double *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_FLOAT, tp++) - { - int lstatus = ncx_put_float_double(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - - - -/* double */ - -int -ncx_getn_double_schar(const void **xpp, size_t nelems, schar *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) - { - const int lstatus = ncx_get_double_schar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_double_uchar(const void **xpp, size_t nelems, uchar *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) - { - const int lstatus = ncx_get_double_uchar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_double_short(const void **xpp, size_t nelems, short *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) - { - const int lstatus = ncx_get_double_short(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_double_int(const void **xpp, size_t nelems, int *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) - { - const int lstatus = ncx_get_double_int(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_double_long(const void **xpp, size_t nelems, long *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) - { - const int lstatus = ncx_get_double_long(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -int -ncx_getn_double_float(const void **xpp, size_t nelems, float *tp) -{ - const char *xp = (const char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) - { - const int lstatus = ncx_get_double_float(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -#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) -{ -# if WORDS_BIGENDIAN - (void) memcpy(tp, *xpp, nelems * sizeof(double)); -# else - swapn8b(tp, *xpp, nelems); -# endif - *xpp = (const void *)((const char *)(*xpp) + nelems * X_SIZEOF_DOUBLE); - return ENOERR; -} -#elif vax -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 = - (struct vax_double *)ip; - const struct ieee_double *const idp = - (const struct ieee_double *) (*xpp); - { - const struct dbl_limits *lim; - int ii; - for (ii = 0, lim = dbl_limits; - ii < sizeof(dbl_limits)/sizeof(struct dbl_limits); - ii++, lim++) - { - if ((idp->mant_lo == lim->ieee.mant_lo) - && (idp->mant_4 == lim->ieee.mant_4) - && (idp->mant_5 == lim->ieee.mant_5) - && (idp->mant_6 == lim->ieee.mant_6) - && (idp->exp_lo == lim->ieee.exp_lo) - && (idp->exp_hi == lim->ieee.exp_hi) - ) - { - *vdp = lim->d; - goto doneit; - } - } - } - { - unsigned exp = idp->exp_hi << 4 | idp->exp_lo; - vdp->exp = exp - IEEE_DBL_BIAS + VAX_DBL_BIAS; - } - { - unsigned mant_hi = ((idp->mant_6 << 16) - | (idp->mant_5 << 8) - | idp->mant_4); - unsigned mant_lo = SWAP4(idp->mant_lo); - vdp->mantissa1 = (mant_hi >> 13); - vdp->mantissa2 = ((mant_hi & MASK(13)) << 3) - | (mant_lo >> 29); - vdp->mantissa3 = (mant_lo >> 13); - vdp->mantissa4 = (mant_lo << 3); - } - doneit: - vdp->sign = idp->sign; - - ip++; - *xpp = (char *)(*xpp) + X_SIZEOF_DOUBLE; - } - return ENOERR; -} - /* vax */ -#elif _SX && _FLOAT2 -int -ncx_getn_double_double(const void **xpp, size_t nelems, double *tp) -{ - const char *const xp = *xpp; - - const int ncnv = ie3_fl2(xp, tp, 8, 8, nelems); - - *xpp = xp + nelems * X_SIZEOF_DOUBLE; - return (nelems == ncnv ? ENOERR : NC_ERANGE); -} -#else -int -ncx_getn_double_double(const void **xpp, size_t nelems, double *tp) -{ - const char *xp = *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) - { - const int lstatus = ncx_get_double_double(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (const void *)xp; - return status; -} - -#endif - -int -ncx_putn_double_schar(void **xpp, size_t nelems, const schar *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) - { - int lstatus = ncx_put_double_schar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_double_uchar(void **xpp, size_t nelems, const uchar *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) - { - int lstatus = ncx_put_double_uchar(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_double_short(void **xpp, size_t nelems, const short *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) - { - int lstatus = ncx_put_double_short(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_double_int(void **xpp, size_t nelems, const int *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) - { - int lstatus = ncx_put_double_int(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_double_long(void **xpp, size_t nelems, const long *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) - { - int lstatus = ncx_put_double_long(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -int -ncx_putn_double_float(void **xpp, size_t nelems, const float *tp) -{ - char *xp = (char *) *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) - { - int lstatus = ncx_put_double_float(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -#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) -{ -# if WORDS_BIGENDIAN - (void) memcpy(*xpp, tp, nelems * X_SIZEOF_DOUBLE); -# else - swapn8b(*xpp, tp, nelems); -# endif - *xpp = (void *)((char *)(*xpp) + nelems * X_SIZEOF_DOUBLE); - return ENOERR; -} -#elif vax -int -ncx_putn_double_double(void **xpp, size_t ndoubles, const double *ip) -{ - const double *const end = ip + ndoubles; - - while(ip < end) - { - const struct vax_double *const vdp = - (const struct vax_double *)ip; - struct ieee_double *const idp = - (struct ieee_double *) (*xpp); - - if ((vdp->mantissa4 > (dbl_limits[0].d.mantissa4 - 3)) && - (vdp->mantissa3 == dbl_limits[0].d.mantissa3) && - (vdp->mantissa2 == dbl_limits[0].d.mantissa2) && - (vdp->mantissa1 == dbl_limits[0].d.mantissa1) && - (vdp->exp == dbl_limits[0].d.exp)) - { - *idp = dbl_limits[0].ieee; - goto shipit; - } - if ((vdp->mantissa4 == dbl_limits[1].d.mantissa4) && - (vdp->mantissa3 == dbl_limits[1].d.mantissa3) && - (vdp->mantissa2 == dbl_limits[1].d.mantissa2) && - (vdp->mantissa1 == dbl_limits[1].d.mantissa1) && - (vdp->exp == dbl_limits[1].d.exp)) - { - *idp = dbl_limits[1].ieee; - goto shipit; - } - - { - unsigned exp = vdp->exp - VAX_DBL_BIAS + IEEE_DBL_BIAS; - - unsigned mant_lo = ((vdp->mantissa2 & MASK(3)) << 29) | - (vdp->mantissa3 << 13) | - ((vdp->mantissa4 >> 3) & MASK(13)); - - unsigned mant_hi = (vdp->mantissa1 << 13) - | (vdp->mantissa2 >> 3); - - if((vdp->mantissa4 & 7) > 4) - { - /* round up */ - mant_lo++; - if(mant_lo == 0) - { - mant_hi++; - if(mant_hi > 0xffffff) - { - mant_hi = 0; - exp++; - } - } - } - - idp->mant_lo = SWAP4(mant_lo); - idp->mant_6 = mant_hi >> 16; - idp->mant_5 = (mant_hi & 0xff00) >> 8; - idp->mant_4 = mant_hi; - idp->exp_hi = exp >> 4; - idp->exp_lo = exp; - } - - shipit: - idp->sign = vdp->sign; - - ip++; - *xpp = (char *)(*xpp) + X_SIZEOF_DOUBLE; - } - return ENOERR; -} - /* vax */ -#elif _SX && _FLOAT2 -int -ncx_putn_double_double(void **xpp, size_t nelems, const double *tp) -{ - char *const xp = *xpp; - - const int ncnv = fl2_ie3(tp, xp, 8, 8, nelems); - - *xpp = xp + nelems * X_SIZEOF_DOUBLE; - return (nelems == ncnv ? ENOERR : NC_ERANGE); -} -#else -int -ncx_putn_double_double(void **xpp, size_t nelems, const double *tp) -{ - char *xp = *xpp; - int status = ENOERR; - - for( ; nelems != 0; nelems--, xp += X_SIZEOF_DOUBLE, tp++) - { - int lstatus = ncx_put_double_double(xp, tp); - if(lstatus != ENOERR) - status = lstatus; - } - - *xpp = (void *)xp; - return status; -} - -#endif - - -/* - * Other aggregate conversion functions. - */ - -/* text */ - -int -ncx_getn_text(const void **xpp, size_t nelems, char *tp) -{ - (void) memcpy(tp, *xpp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems); - return ENOERR; - -} - -int -ncx_pad_getn_text(const void **xpp, size_t nelems, char *tp) -{ - size_t rndup = nelems % X_ALIGN; - - if(rndup) - rndup = X_ALIGN - rndup; - - (void) memcpy(tp, *xpp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems + rndup); - - return ENOERR; - -} - -int -ncx_putn_text(void **xpp, size_t nelems, const char *tp) -{ - (void) memcpy(*xpp, tp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems); - - return ENOERR; - -} - -int -ncx_pad_putn_text(void **xpp, size_t nelems, const char *tp) -{ - size_t rndup = nelems % X_ALIGN; - - if(rndup) - rndup = X_ALIGN - rndup; - - (void) memcpy(*xpp, tp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems); - - if(rndup) - { - (void) memcpy(*xpp, nada, rndup); - *xpp = (void *)((char *)(*xpp) + rndup); - } - - return ENOERR; - -} - - -/* opaque */ - -int -ncx_getn_void(const void **xpp, size_t nelems, void *tp) -{ - (void) memcpy(tp, *xpp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems); - return ENOERR; - -} - -int -ncx_pad_getn_void(const void **xpp, size_t nelems, void *tp) -{ - size_t rndup = nelems % X_ALIGN; - - if(rndup) - rndup = X_ALIGN - rndup; - - (void) memcpy(tp, *xpp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems + rndup); - - return ENOERR; - -} - -int -ncx_putn_void(void **xpp, size_t nelems, const void *tp) -{ - (void) memcpy(*xpp, tp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems); - - return ENOERR; - -} - -int -ncx_pad_putn_void(void **xpp, size_t nelems, const void *tp) -{ - size_t rndup = nelems % X_ALIGN; - - if(rndup) - rndup = X_ALIGN - rndup; - - (void) memcpy(*xpp, tp, nelems); - *xpp = (void *)((char *)(*xpp) + nelems); - - if(rndup) - { - (void) memcpy(*xpp, nada, rndup); - *xpp = (void *)((char *)(*xpp) + rndup); - } - - return ENOERR; - -} Index: libsrc/putget.m4 =================================================================== --- libsrc/putget.m4 (.../trunk) (revision 531) +++ libsrc/putget.m4 (.../branches/fileinf_improvement) (revision 531) @@ -12,7 +12,7 @@ * Copyright 1996, University Corporation for Atmospheric Research * See netcdf/COPYRIGHT file for copying and redistribution conditions. */ -/* $Id: putget.m4,v 2.60 2006/01/03 20:20:07 russ Exp $ */ +/* $Id: putget.m4,v 2.52 2004/11/09 20:05:27 russ Exp $ */ #include "nc.h" #include @@ -27,7 +27,9 @@ # include # endif #endif - +#if defined(USE_SXP) +# include "SXP.h" /* sjl: SX profiling hooks */ +#endif #undef MIN /* system may define MIN somewhere and complain */ #define MIN(mm,nn) (((mm) < (nn)) ? (mm) : (nn)) @@ -56,23 +58,23 @@ * ncvarget(cdfid, varid, cor, edg, vals); */ int -nctypelen(nc_type type) +nctypelen(nc_type type) { - switch(type){ - case NC_BYTE : - case NC_CHAR : - return((int)sizeof(char)); - case NC_SHORT : - return(int)(sizeof(short)); - case NC_INT : - return((int)sizeof(int)); - case NC_FLOAT : - return((int)sizeof(float)); - case NC_DOUBLE : - return((int)sizeof(double)); - } + switch(type){ + case NC_BYTE : + case NC_CHAR : + return((int)sizeof(char)); + case NC_SHORT : + return(int)(sizeof(short)); + case NC_INT : + return((int)sizeof(int)); + case NC_FLOAT : + return((int)sizeof(float)); + case NC_DOUBLE : + return((int)sizeof(double)); + } - return -1; + return -1; } @@ -195,6 +197,9 @@ xp = xfillp; +#if defined(USE_SXP) + SXP_START_DC(ncp->nciop->sxp,nelems,varp->type); +#endif switch(varp->type){ case NC_BYTE : status = NC_fill_schar(&xp, nelems); @@ -219,6 +224,9 @@ status = NC_EBADTYPE; break; } +#if defined(USE_SXP) + SXP_STOP_DC(ncp->nciop->sxp); +#endif if(status != NC_NOERR) return status; @@ -616,6 +624,7 @@ size_t remaining = varp->xsz * nelems; int status = NC_NOERR; void *xp; + int lstatus; if(nelems == 0) return NC_NOERR; @@ -626,13 +635,25 @@ { size_t extent = MIN(remaining, ncp->chunk); size_t nput = ncx_howmany(varp->type, extent); + /* sjl: there might be a subtle bug here: if extent + * is not a multiple of howmany, it is possible for + * alignment to go haywire. Because chunksize is + * always a multiple of a power of two, I dont think + * it will ever happen, but to be safe: */ + extent = varp->xsz * nput; - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, - RGN_WRITE, &xp); + lstatus = ncp->nciop->get(ncp->nciop, offset, extent, + RGN_WRITE, &xp); if(lstatus != NC_NOERR) return lstatus; +#if defined(USE_SXP) + SXP_START_DC(ncp->nciop->sxp,nput,varp->type); +#endif lstatus = ncx_putn_$1_$2(&xp, nput, value); +#if defined(USE_SXP) + SXP_STOP_DC(ncp->nciop->sxp); +#endif if(lstatus != NC_NOERR && status == NC_NOERR) { /* not fatal to the loop */ @@ -706,6 +727,9 @@ putNCv_$1(NC *ncp, const NC_var *varp, const size_t *start, size_t nelems, const $1 *value) { +#if defined(USE_SXP) + SXP_ADD_ELEMS(ncp->nciop->sxp,nelems); +#endif switch(varp->type){ case NC_CHAR: return NC_ECHAR; @@ -735,6 +759,9 @@ { if(varp->type != NC_CHAR) return NC_ECHAR; +#if defined(USE_SXP) + SXP_ADD_ELEMS(ncp->nciop->sxp,nelems); +#endif return putNCvx_char_char(ncp, varp, start, nelems, value); } @@ -760,6 +787,7 @@ size_t remaining = varp->xsz * nelems; int status = NC_NOERR; const void *xp; + int lstatus; if(nelems == 0) return NC_NOERR; @@ -770,13 +798,21 @@ { size_t extent = MIN(remaining, ncp->chunk); size_t nget = ncx_howmany(varp->type, extent); + /* sjl: potential minor bug fix, see putNCvx_$1_$2 for comments: */ + extent = varp->xsz * nget; - int lstatus = ncp->nciop->get(ncp->nciop, offset, extent, + lstatus = ncp->nciop->get(ncp->nciop, offset, extent, 0, (void **)&xp); /* cast away const */ if(lstatus != NC_NOERR) return lstatus; +#if defined(USE_SXP) + SXP_START_DC(ncp->nciop->sxp,nget,varp->type); +#endif lstatus = ncx_getn_$1_$2(&xp, nget, value); +#if defined(USE_SXP) + SXP_STOP_DC(ncp->nciop->sxp); +#endif if(lstatus != NC_NOERR && status == NC_NOERR) status = lstatus; @@ -845,6 +881,9 @@ getNCv_$1(const NC *ncp, const NC_var *varp, const size_t *start, size_t nelems, $1 *value) { +#if defined(USE_SXP) + SXP_ADD_ELEMS(ncp->nciop->sxp,nelems); +#endif switch(varp->type){ case NC_CHAR: return NC_ECHAR; @@ -883,6 +922,9 @@ { if(varp->type != NC_CHAR) return NC_ECHAR; +#if defined(USE_SXP) + SXP_ADD_ELEMS(ncp->nciop->sxp,nelems); +#endif return getNCvx_char_char(ncp, varp, start, nelems, value); } @@ -1064,8 +1106,8 @@ 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(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); @@ -1081,890 +1123,195 @@ #pragma _CRI noinline odo1 #endif +dnl ---- sjl: the external interface is now in pg_interface.m4. This is +dnl ---- mostly to simplify diffing and patching, since the interface +dnl ---- part has been refactored rather a bit to facilitate adding +dnl ---- profiling hooks -dnl -dnl NCTEXTCOND(Abbrv) -dnl This is used inside the NC{PUT,GET} macros below -dnl -define(`NCTEXTCOND',dnl -`dnl -ifelse($1, text,dnl -`dnl - if(varp->type != NC_CHAR) - return NC_ECHAR; -',dnl -`dnl - if(varp->type == NC_CHAR) - return NC_ECHAR; -')dnl -')dnl +include(pg_interface.m4) +dnl ---- sjl: end of interface part +/* Begin recio, deprecated */ -/* Public */ - -dnl -dnl NCPUTVAR1(Abbrev, Type) -dnl -define(`NCPUTVAR1',dnl -`dnl -int -nc_put_var1_$1(int ncid, int varid, const size_t *coord, - const $2 *value) +/* + * input 'nelems' items of contiguous data of 'varp' at 'start' + * N.B. this function deprecated. + */ +static int +getNCvdata(const NC *ncp, const NC_var *varp, + const size_t *start, size_t nelems, void *value) { - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - -NCTEXTCOND($1) - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *coord +1); - if(status != NC_NOERR) - return status; + switch(varp->type){ + case NC_CHAR: + return getNCvx_char_char(ncp, varp, start, nelems, + (char *) value); + case NC_BYTE: + return getNCvx_schar_schar(ncp, varp, start, nelems, + (schar *) value); + case NC_SHORT: + return getNCvx_short_short(ncp, varp, start, nelems, + (short *) value); + case NC_INT: +#if (SIZEOF_INT >= X_SIZEOF_INT) + return getNCvx_int_int(ncp, varp, start, nelems, + (int *) value); +#elif SIZEOF_LONG == X_SIZEOF_INT + return getNCvx_int_long(ncp, varp, start, nelems, + (long *) value); +#else +#error "getNCvdata implementation" +#endif + case NC_FLOAT: + return getNCvx_float_float(ncp, varp, start, nelems, + (float *) value); + case NC_DOUBLE: + return getNCvx_double_double(ncp, varp, start, nelems, + (double *) value); } - - return putNCv_$1(ncp, varp, coord, 1, value); + return NC_EBADTYPE; } -')dnl -NCPUTVAR1(text, char) -NCPUTVAR1(uchar, uchar) -NCPUTVAR1(schar, schar) -NCPUTVAR1(short, short) -NCPUTVAR1(int, int) -NCPUTVAR1(long, long) -NCPUTVAR1(float, float) -NCPUTVAR1(double, double) - -dnl -dnl NCGETVAR1(Abbrv, Type) -dnl -define(`NCGETVAR1',dnl -`dnl -int -nc_get_var1_$1(int ncid, int varid, const size_t *coord, $2 *value) +/* + * output 'nelems' items of contiguous data of 'varp' at 'start' + * N.B. this function deprecated. + */ +static int +putNCvdata(NC *ncp, const NC_var *varp, + const size_t *start, size_t nelems, const void *value) { - int status; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - -NCTEXTCOND($1) - status = NCcoordck(ncp, varp, coord); - if(status != NC_NOERR) - return status; - - return getNCv_$1(ncp, varp, coord, 1, value); + switch(varp->type){ + case NC_CHAR: + return putNCvx_char_char(ncp, varp, start, nelems, + (const char *) value); + case NC_BYTE: + return putNCvx_schar_schar(ncp, varp, start, nelems, + (const schar *) value); + case NC_SHORT: + return putNCvx_short_short(ncp, varp, start, nelems, + (const short *) value); + case NC_INT: +#if (SIZEOF_INT >= X_SIZEOF_INT) + return putNCvx_int_int(ncp, varp, start, nelems, + (const int *) value); +#elif SIZEOF_LONG == X_SIZEOF_INT + return putNCvx_long_int(ncp, varp, start, nelems, + (const long *) value); +#else +#error "putNCvdata implementation" +#endif + case NC_FLOAT: + return putNCvx_float_float(ncp, varp, start, nelems, + (const float *) value); + case NC_DOUBLE: + return putNCvx_double_double(ncp, varp, start, nelems, + (const double *) value); + } + return NC_EBADTYPE; } -')dnl -NCGETVAR1(text, char) -NCGETVAR1(uchar, uchar) -NCGETVAR1(schar, schar) -NCGETVAR1(short, short) -NCGETVAR1(int, int) -NCGETVAR1(long, long) -NCGETVAR1(float, float) -NCGETVAR1(double, double) - -dnl -dnl NCPUTVARA(Abbrv, Type) -dnl -define(`NCPUTVARA',dnl -`dnl -int -nc_put_vara_$1(int ncid, int varid, - const size_t *start, const size_t *edges, const $2 *value) +static size_t +NCelemsPerRec( + const NC_var *varp) { - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; - size_t iocount; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - -NCTEXTCOND($1) - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ - { - return( putNCv_$1(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - status = NCvnrecs(ncp, *start + *edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return( putNCv_$1(ncp, varp, start, *edges, value) ); - } - } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) - { - return( putNCv_$1(ncp, varp, start, iocount, value) ); - } - - 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 = putNCv_$1(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); - FREE_ONSTACK(coord); - } /* end inline */ - - return status; + size_t nelems = 1; + size_t jj; + for(jj = 1; jj < varp->ndims; jj++) + nelems *= varp->shape[jj]; + return nelems; } -')dnl -NCPUTVARA(text, char) - -NCPUTVARA(uchar, uchar) -NCPUTVARA(schar, schar) -NCPUTVARA(short, short) -NCPUTVARA(int, int) -NCPUTVARA(long, long) -NCPUTVARA(float, float) -NCPUTVARA(double, double) - - -dnl -dnl NCGETVARA(Abbrv, Type) -dnl -define(`NCGETVARA',dnl -`dnl -int -nc_get_vara_$1(int ncid, int varid, - const size_t *start, const size_t *edges, $2 *value) +static int +NCrecput( + NC *ncp, + size_t recnum, + void *const *datap) { int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - int ii; + size_t nrvars = 0; + NC_var *varp; + size_t ii; size_t iocount; + ALLOC_ONSTACK(coord, size_t, ncp->dims.nelems); - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; + assert(ncp->dims.nelems != 0); - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - -NCTEXTCOND($1) - status = NCcoordck(ncp, varp, start); - if(status != NC_NOERR) - return status; - status = NCedgeck(ncp, varp, start, edges); - if(status != NC_NOERR) - return status; - - if(varp->ndims == 0) /* scalar variable */ + (void) memset(coord, 0, ncp->dims.nelems * sizeof(size_t)); + coord[0] = recnum; + for(ii = 0; ii < ncp->vars.nelems; ii++) { - return( getNCv_$1(ncp, varp, start, 1, value) ); - } - - if(IS_RECVAR(varp)) - { - if(*start + *edges > NC_get_numrecs(ncp)) - return NC_EEDGE; - if(varp->ndims == 1 && ncp->recsize <= varp->len) + varp = ncp->vars.value[ii]; + if(!IS_RECVAR(varp)) + continue; + /* else */ + nrvars++; + if(*datap == NULL) { - /* one dimensional && the only record variable */ - return( getNCv_$1(ncp, varp, start, *edges, value) ); + datap++; + continue; } + /* else */ + iocount = NCelemsPerRec(varp); + status = putNCvdata(ncp, varp, coord, iocount, *datap++); + if(status != NC_NOERR) + break; } - - /* - * find max contiguous - * and accumulate max count for a single io operation - */ - ii = NCiocount(ncp, varp, edges, &iocount); - - if(ii == -1) + if(nrvars == 0 && status == NC_NOERR) { - return( getNCv_$1(ncp, varp, start, iocount, value) ); + status = NC_ENORECVARS; } - - 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 = getNCv_$1(ncp, varp, coord, iocount, - value); - 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; - odo1(start, upper, coord, &upper[index], &coord[index]); - } - - FREE_ONSTACK(upper); + FREE_ONSTACK(coord); - } /* end inline */ - return status; } -')dnl -NCGETVARA(text, char) -NCGETVARA(uchar, uchar) -NCGETVARA(schar, schar) -NCGETVARA(short, short) -NCGETVARA(int, int) -NCGETVARA(long, long) -NCGETVARA(float, float) -NCGETVARA(double, double) - - -#if defined(__cplusplus) -/* C++ consts default to internal linkage and must be initialized */ -const size_t coord_zero[NC_MAX_VAR_DIMS] = {0}; -#else -static const size_t coord_zero[NC_MAX_VAR_DIMS]; -#endif - -dnl -dnl NCPUTVAR(Abbrev, Type) -dnl -define(`NCPUTVAR',dnl -`dnl -int -nc_put_var_$1(int ncid, int varid, const $2 *value) +static int +NCrecget( + NC *ncp, + size_t recnum, + void **datap) { int status = NC_NOERR; - NC *ncp; - const NC_var *varp; + size_t nrvars = 0; + NC_var *varp; + size_t ii; + size_t iocount; + ALLOC_ONSTACK(coord, size_t, ncp->dims.nelems); - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; + assert(ncp->dims.nelems != 0); - if(NC_readonly(ncp)) - return NC_EPERM; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - -NCTEXTCOND($1) - if(varp->ndims == 0) /* scalar variable */ + (void) memset(coord, 0, ncp->dims.nelems * sizeof(size_t)); + coord[0] = recnum; + for(ii = 0; ii < ncp->vars.nelems; ii++) { - const size_t zed = 0; - return( putNCv_$1(ncp, varp, &zed, 1, value) ); - } - - if(!IS_RECVAR(varp)) - { - return(putNCv_$1(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(putNCv_$1(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = putNCv_$1(ncp, varp, coord, elemsPerRec, - value); - if(lstatus != NC_NOERR) + varp = ncp->vars.value[ii]; + if(!IS_RECVAR(varp)) + continue; + /* else */ + nrvars++; + if(*datap == NULL) { - 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; + datap++; + continue; } - value += elemsPerRec; - (*coord)++; + /* else */ + iocount = NCelemsPerRec(varp); + status = getNCvdata(ncp, varp, coord, iocount, *datap++); + if(status != NC_NOERR) + break; } - FREE_ONSTACK(coord); - } /* elemsPerRec */ - - return status; -} -')dnl - -NCPUTVAR(text, char) - -NCPUTVAR(uchar, uchar) -NCPUTVAR(schar, schar) -NCPUTVAR(short, short) -NCPUTVAR(int, int) -NCPUTVAR(long, long) -NCPUTVAR(float, float) -NCPUTVAR(double, double) - - -dnl -dnl NCGETVAR(Abbrv, Type) -dnl -define(`NCGETVAR',dnl -`dnl -int -nc_get_var_$1(int ncid, int varid, $2 *value) -{ - int status = NC_NOERR; - NC *ncp; - const NC_var *varp; - - status = NC_check_id(ncid, &ncp); - if(status != NC_NOERR) - return status; - - if(NC_indef(ncp)) - return NC_EINDEFINE; - - varp = NC_lookupvar(ncp, varid); - if(varp == NULL) - return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ - - if(varp->ndims == 0) /* scalar variable */ + if(nrvars == 0 && status == NC_NOERR) { - const size_t zed = 0; - return( getNCv_$1(ncp, varp, &zed, 1, value) ); + status = NC_ENORECVARS; } -NCTEXTCOND($1) - - if(!IS_RECVAR(varp)) - { - return(getNCv_$1(ncp, varp, coord_zero, *varp->dsizes, value)); - } - /* else */ - - if(varp->ndims == 1 - && ncp->recsize <= varp->len) - { - /* one dimensional && the only record variable */ - return(getNCv_$1(ncp, varp, coord_zero, NC_get_numrecs(ncp), - value)); - } - /* else */ - - { - ALLOC_ONSTACK(coord, size_t, varp->ndims); - size_t elemsPerRec = 1; - const size_t nrecs = NC_get_numrecs(ncp); - (void) memset(coord, 0, varp->ndims * sizeof(size_t)); - /* TODO: fix dsizes to avoid this nonsense */ - if(varp->ndims > 1) - elemsPerRec = varp->dsizes[1]; - while(*coord < nrecs) - { - const int lstatus = getNCv_$1(ncp, varp, coord, elemsPerRec, - value); - 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 += elemsPerRec; - (*coord)++; - } FREE_ONSTACK(coord); - } /* elemsPerRec */ - return status; } -')dnl -NCGETVAR(text, char) - -NCGETVAR(uchar, uchar) -NCGETVAR(schar, schar) -NCGETVAR(short, short) -NCGETVAR(int, int) -NCGETVAR(long, long) -NCGETVAR(float, float) -NCGETVAR(double, double) - - -/* Begin putgetg.c */ - -dnl -dnl NC_VARM_Upper_Body(void) -dnl -define(`NC_VARM_Upper_Body',dnl -`dnl - int status = ENOERR; - NC *ncp; - NC_var *varp; - int maxidim; /* maximum dimensional index */ - - status = NC_check_id (ncid, &ncp); - if (status != NC_NOERR) - return status; - - if (NC_indef (ncp)) - { - return NC_EINDEFINE; - } -')dnl -dnl -dnl NC_VARM_Mid_Body(put_or_get, Abbrv) -dnl -define(`NC_VARM_Mid_Body',dnl -`dnl - varp = NC_lookupvar (ncp, varid); - if (varp == NULL) - return NC_ENOTVAR; - -NCTEXTCOND($2) - maxidim = (int) varp->ndims - 1; - - if (maxidim < 0) - { - /* - * The variable is a scalar; consequently, - * there s only one thing to get and only one place to put it. - * (Why was I called?) - */ - return $1 (ncp, varp, start, 1, value); - } - - /* - * else - * The variable is an array. - */ - { - int idim; - size_t *mystart = NULL; - size_t *myedges; - size_t *iocount; /* count vector */ - size_t *stop; /* stop indexes */ - size_t *length; /* edge lengths in bytes */ - ptrdiff_t *mystride; - ptrdiff_t *mymap; - - /* - * Verify stride argument. - */ - for (idim = 0; idim <= maxidim; ++idim) - { - if (stride != NULL - && (stride[idim] == 0 - /* cast needed for braindead systems with signed size_t */ - || (unsigned long) stride[idim] >= X_INT_MAX)) - { - return NC_ESTRIDE; - } - } - - /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ - mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); - if(mystart == NULL) - return NC_ENOMEM; - myedges = mystart + varp->ndims; - iocount = myedges + varp->ndims; - stop = iocount + varp->ndims; - length = stop + varp->ndims; - mystride = (ptrdiff_t *)(length + varp->ndims); - mymap = mystride + varp->ndims; - - /* - * Initialize I/O parameters. - */ - for (idim = maxidim; idim >= 0; --idim) - { - mystart[idim] = start != NULL - ? start[idim] - : 0; - - if (edges[idim] == 0) - { - status = NC_NOERR; /* read/write no data */ - goto done; - } - - myedges[idim] = edges != NULL - ? edges[idim] - : idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - mystart[idim] - : varp->shape[idim] - mystart[idim]; - mystride[idim] = stride != NULL - ? stride[idim] - : 1; - mymap[idim] = map != NULL - ? map[idim] - : idim == maxidim - ? 1 - : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; - - iocount[idim] = 1; - length[idim] = mymap[idim] * myedges[idim]; - stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; - } -')dnl -dnl -dnl NC_VARM_Lower_Body(put_or_get) -dnl -define(`NC_VARM_Lower_Body',dnl -`dnl - /* - * As an optimization, adjust I/O parameters when the fastest - * dimension has unity stride both externally and internally. - * In this case, the user could have called a simpler routine - * (i.e. ncvar$1() - */ - if (mystride[maxidim] == 1 - && mymap[maxidim] == 1) - { - iocount[maxidim] = myedges[maxidim]; - mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; - mymap[maxidim] = (ptrdiff_t) length[maxidim]; - } - - /* - * Perform I/O. Exit when done. - */ - for (;;) - { - /* TODO: */ - int lstatus = $1 (ncid, varid, mystart, iocount, - value); - if (lstatus != NC_NOERR - && (status == NC_NOERR || lstatus != NC_ERANGE)) - status = lstatus; - - /* - * The following code permutes through the variable s - * external start-index space and it s internal address - * space. At the UPC, this algorithm is commonly - * called "odometer code". - */ - idim = maxidim; - carry: - value += mymap[idim]; - mystart[idim] += mystride[idim]; - if (mystart[idim] == stop[idim]) - { - mystart[idim] = start[idim]; - value -= length[idim]; - if (--idim < 0) - break; /* normal return */ - goto carry; - } - } /* I/O loop */ - done: - free(mystart); - } /* variable is array */ - return status; -')dnl - -dnl -dnl NCGETVARS(Abbrv, Type) -dnl -define(`NCGETVARS',dnl -`dnl -int -nc_get_vars_$1 ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - $2 *value) -{ - return nc_get_varm_$1 (ncid, varid, start, edges, - stride, 0, value); -} -')dnl - -NCGETVARS(text, char) - -NCGETVARS(uchar, uchar) -NCGETVARS(schar, schar) -NCGETVARS(short, short) -NCGETVARS(int, int) -NCGETVARS(long, long) -NCGETVARS(float, float) -NCGETVARS(double, double) - - -dnl -dnl NCPUTVARS(Abbrv, Type) -dnl -define(`NCPUTVARS',dnl -`dnl -int -nc_put_vars_$1 ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - const $2 *value) -{ - return nc_put_varm_$1 (ncid, varid, start, edges, - stride, 0, value); -} -')dnl - -NCPUTVARS(text, char) - -NCPUTVARS(uchar, uchar) -NCPUTVARS(schar, schar) -NCPUTVARS(short, short) -NCPUTVARS(int, int) -NCPUTVARS(long, long) -NCPUTVARS(float, float) -NCPUTVARS(double, double) - - /* - * Generalized hyperslab input. - */ -dnl -dnl NCGETVARM(Abbrv, Type) -dnl -define(`NCGETVARM',dnl -`dnl -int -nc_get_varm_$1(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, - const ptrdiff_t *map, - $2 *value) -{ -NC_VARM_Upper_Body() -NC_VARM_Mid_Body(getNCv_$1, $1) - /* - * Check start, edges - */ - for (idim = maxidim; idim >= 0; --idim) - { - size_t dimlen = - idim == 0 && IS_RECVAR (varp) - ? NC_get_numrecs(ncp) - : varp->shape[idim]; - if (mystart[idim] >= dimlen) - { - status = NC_EINVALCOORDS; - goto done; - } - - if (mystart[idim] + myedges[idim] > dimlen) - { - status = NC_EEDGE; - goto done; - } - - } -NC_VARM_Lower_Body(nc_get_vara_$1) -} -')dnl - -NCGETVARM(text, char) - -NCGETVARM(uchar, uchar) -NCGETVARM(schar, schar) -NCGETVARM(short, short) -NCGETVARM(int, int) -NCGETVARM(long, long) -NCGETVARM(float, float) -NCGETVARM(double, double) - -#ifdef NO_NETCDF_2 -extern int -nctypelen(nc_type datatype); -#endif - - -/* - * Generalized hyperslab output. - */ -dnl -dnl NCPUTVARM(Abbrv, Type) -dnl -define(`NCPUTVARM',dnl -`dnl -int -nc_put_varm_$1(int ncid, int varid, - const size_t *start, const size_t *edges, - const ptrdiff_t *stride, const ptrdiff_t *map, - const $2 *value) -{ -NC_VARM_Upper_Body() - if (NC_readonly (ncp)) - return NC_EPERM; -NC_VARM_Mid_Body(putNCv_$1, $1) - /* - * Check start, edges - */ - for (idim = IS_RECVAR (varp); idim < maxidim; ++idim) - { - if (mystart[idim] > varp->shape[idim]) - { - status = NC_EINVALCOORDS; - goto done; - } - if (mystart[idim] + myedges[idim] > varp->shape[idim]) - { - status = NC_EEDGE; - goto done; - } - } -NC_VARM_Lower_Body(nc_put_vara_$1) -} -')dnl - -NCPUTVARM(text, char) - -NCPUTVARM(uchar, uchar) -NCPUTVARM(schar, schar) -NCPUTVARM(short, short) -NCPUTVARM(int, int) -NCPUTVARM(long, long) -NCPUTVARM(float, float) -NCPUTVARM(double, double) - - -/* * Copy the values of a variable from an input netCDF to an output netCDF. * Input and output var assummed to have the same shape. * return -1 on error. @@ -2081,444 +1428,3 @@ } return status; } - -/* no longer deprecated, used to support the 2.x interface and also the netcdf-4 api. */ -int -nc_get_att(int ncid, int varid, const char *name, void *value) -{ - int status; - nc_type atttype; - - status = nc_inq_atttype(ncid, varid, name, &atttype); - if(status != NC_NOERR) - return status; - - switch (atttype) { - case NC_BYTE: - return nc_get_att_schar(ncid, varid, name, - (schar *)value); - case NC_CHAR: - return nc_get_att_text(ncid, varid, name, - (char *)value); - case NC_SHORT: - return nc_get_att_short(ncid, varid, name, - (short *)value); - case NC_INT: -#if (SIZEOF_INT >= X_SIZEOF_INT) - return nc_get_att_int(ncid, varid, name, - (int *)value); -#elif SIZEOF_LONG == X_SIZEOF_INT - return nc_get_att_long(ncid, varid, name, - (long *)value); -#endif - case NC_FLOAT: - return nc_get_att_float(ncid, varid, name, - (float *)value); - case NC_DOUBLE: - return nc_get_att_double(ncid, varid, name, - (double *)value); - } - return NC_EBADTYPE; -} - - -int -nc_put_att( - int ncid, - int varid, - const char *name, - nc_type type, - size_t nelems, - const void *value) -{ - switch (type) { - case NC_BYTE: - return nc_put_att_schar(ncid, varid, name, type, nelems, - (schar *)value); - case NC_CHAR: - return nc_put_att_text(ncid, varid, name, nelems, - (char *)value); - case NC_SHORT: - return nc_put_att_short(ncid, varid, name, type, nelems, - (short *)value); - case NC_INT: -#if (SIZEOF_INT >= X_SIZEOF_INT) - return nc_put_att_int(ncid, varid, name, type, nelems, - (int *)value); -#elif SIZEOF_LONG == X_SIZEOF_INT - return nc_put_att_long(ncid, varid, name, type, nelems, - (long *)value); -#endif - case NC_FLOAT: - return nc_put_att_float(ncid, varid, name, type, nelems, - (float *)value); - case NC_DOUBLE: - return nc_put_att_double(ncid, varid, name, type, nelems, - (double *)value); - } - return NC_EBADTYPE; -} - - -int -nc_get_var1(int ncid, int varid, const size_t *coord, void *value) -{ - int status; - nc_type vartype; - - status = nc_inq_vartype(ncid, varid, &vartype); - if(status != NC_NOERR) - return status; - - switch(vartype){ - case NC_CHAR: - return nc_get_var1_text(ncid, varid, coord, - (char *) value); - case NC_BYTE: - return nc_get_var1_schar(ncid, varid, coord, - (schar *) value); - case NC_SHORT: - return nc_get_var1_short(ncid, varid, coord, - (short *) value); - case NC_INT: - return nc_get_var1_int(ncid, varid, coord, - (int *) value); - case NC_FLOAT: - return nc_get_var1_float(ncid, varid, coord, - (float *) value); - case NC_DOUBLE: - return nc_get_var1_double(ncid, varid, coord, - (double *) value); - } - return NC_EBADTYPE; -} - - -int -nc_put_var1(int ncid, int varid, const size_t *coord, const void *value) -{ - int status; - nc_type vartype; - - status = nc_inq_vartype(ncid, varid, &vartype); - if(status != NC_NOERR) - return status; - - switch(vartype){ - case NC_CHAR: - return nc_put_var1_text(ncid, varid, coord, - (const char *) value); - case NC_BYTE: - return nc_put_var1_schar(ncid, varid, coord, - (const schar *) value); - case NC_SHORT: - return nc_put_var1_short(ncid, varid, coord, - (const short *) value); - case NC_INT: - return nc_put_var1_int(ncid, varid, coord, - (const int *) value); - case NC_FLOAT: - return nc_put_var1_float(ncid, varid, coord, - (const float *) value); - case NC_DOUBLE: - return nc_put_var1_double(ncid, varid, coord, - (const double *) value); - } - return NC_EBADTYPE; -} - - -int -nc_get_vara(int ncid, int varid, - const size_t *start, const size_t *edges, void *value) -{ - int status; - nc_type vartype; - - status = nc_inq_vartype(ncid, varid, &vartype); - if(status != NC_NOERR) - return status; - - switch(vartype){ - case NC_CHAR: - return nc_get_vara_text(ncid, varid, start, edges, - (char *) value); - case NC_BYTE: - return nc_get_vara_schar(ncid, varid, start, edges, - (schar *) value); - case NC_SHORT: - return nc_get_vara_short(ncid, varid, start, edges, - (short *) value); - case NC_INT: -#if (SIZEOF_INT >= X_SIZEOF_INT) - return nc_get_vara_int(ncid, varid, start, edges, - (int *) value); -#elif SIZEOF_LONG == X_SIZEOF_INT - return nc_get_vara_long(ncid, varid, start, edges, - (long *) value); -#else -#error "nc_get_vara implementation" -#endif - case NC_FLOAT: - return nc_get_vara_float(ncid, varid, start, edges, - (float *) value); - case NC_DOUBLE: - return nc_get_vara_double(ncid, varid, start, edges, - (double *) value); - } - return NC_EBADTYPE; -} - -int -nc_put_vara(int ncid, int varid, - const size_t *start, const size_t *edges, const void *value) -{ - int status; - nc_type vartype; - - status = nc_inq_vartype(ncid, varid, &vartype); - if(status != NC_NOERR) - return status; - - switch(vartype){ - case NC_CHAR: - return nc_put_vara_text(ncid, varid, start, edges, - (const char *) value); - case NC_BYTE: - return nc_put_vara_schar(ncid, varid, start, edges, - (const schar *) value); - case NC_SHORT: - return nc_put_vara_short(ncid, varid, start, edges, - (const short *) value); - case NC_INT: - return nc_put_vara_int(ncid, varid, start, edges, - (const int *) value); - case NC_FLOAT: - return nc_put_vara_float(ncid, varid, start, edges, - (const float *) value); - case NC_DOUBLE: - return nc_put_vara_double(ncid, varid, start, edges, - (const double *) value); - } - return NC_EBADTYPE; -} - -int -nc_get_varm ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - const ptrdiff_t * map, - void *value) -{ - int status; - nc_type vartype; - int varndims; - ptrdiff_t *cvtmap = NULL; - - status = nc_inq_vartype(ncid, varid, &vartype); - if(status != NC_NOERR) - return status; - - status = nc_inq_varndims(ncid, varid, &varndims); - if(status != NC_NOERR) - return status; - - if(map != NULL && varndims != 0) - { - /* - * convert map units from bytes to units of sizeof(type) - */ - size_t ii; - const ptrdiff_t szof = (ptrdiff_t) nctypelen(vartype); - cvtmap = (ptrdiff_t *)calloc(varndims, sizeof(ptrdiff_t)); - if(cvtmap == NULL) - return NC_ENOMEM; - for(ii = 0; ii < varndims; ii++) - { - if(map[ii] % szof != 0) - { - free(cvtmap); - return NC_EINVAL; - } - cvtmap[ii] = map[ii] / szof; - } - map = cvtmap; - } - - switch(vartype){ - case NC_CHAR: - status = nc_get_varm_text(ncid, varid, start, edges, - stride, map, - (char *) value); - break; - case NC_BYTE: - status = nc_get_varm_schar(ncid, varid, start, edges, - stride, map, - (schar *) value); - break; - case NC_SHORT: - status = nc_get_varm_short(ncid, varid, start, edges, - stride, map, - (short *) value); - break; - case NC_INT: -#if (SIZEOF_INT >= X_SIZEOF_INT) - status = nc_get_varm_int(ncid, varid, start, edges, - stride, map, - (int *) value); -#elif SIZEOF_LONG == X_SIZEOF_INT - status = nc_get_varm_long(ncid, varid, start, edges, - stride, map, - (long *) value); -#else -#error "nc_get_varm implementation" -#endif - break; - case NC_FLOAT: - status = nc_get_varm_float(ncid, varid, start, edges, - stride, map, - (float *) value); - break; - case NC_DOUBLE: - status = nc_get_varm_double(ncid, varid, start, edges, - stride, map, - (double *) value); - break; - default: - status = NC_EBADTYPE; - break; - } - - if(cvtmap != NULL) - { - free(cvtmap); - } - return status; -} - - -int -nc_put_varm ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - const ptrdiff_t * map, - const void *value) -{ - int status; - nc_type vartype; - int varndims; - ptrdiff_t *cvtmap = NULL; - - status = nc_inq_vartype(ncid, varid, &vartype); - if(status != NC_NOERR) - return status; - - status = nc_inq_varndims(ncid, varid, &varndims); - if(status != NC_NOERR) - return status; - - if(map != NULL && varndims != 0) - { - /* - * convert map units from bytes to units of sizeof(type) - */ - size_t ii; - const ptrdiff_t szof = (ptrdiff_t) nctypelen(vartype); - cvtmap = (ptrdiff_t *)calloc(varndims, sizeof(ptrdiff_t)); - if(cvtmap == NULL) - return NC_ENOMEM; - for(ii = 0; ii < varndims; ii++) - { - if(map[ii] % szof != 0) - { - free(cvtmap); - return NC_EINVAL; - } - cvtmap[ii] = map[ii] / szof; - } - map = cvtmap; - } - - switch(vartype){ - case NC_CHAR: - status = nc_put_varm_text(ncid, varid, start, edges, - stride, map, - (const char *) value); - break; - case NC_BYTE: - status = nc_put_varm_schar(ncid, varid, start, edges, - stride, map, - (const schar *) value); - break; - case NC_SHORT: - status = nc_put_varm_short(ncid, varid, start, edges, - stride, map, - (const short *) value); - break; - case NC_INT: -#if (SIZEOF_INT >= X_SIZEOF_INT) - status = nc_put_varm_int(ncid, varid, start, edges, - stride, map, - (const int *) value); -#elif SIZEOF_LONG == X_SIZEOF_INT - status = nc_put_varm_long(ncid, varid, start, edges, - stride, map, - (const long *) value); -#else -#error "nc_put_varm implementation" -#endif - break; - case NC_FLOAT: - status = nc_put_varm_float(ncid, varid, start, edges, - stride, map, - (const float *) value); - break; - case NC_DOUBLE: - status = nc_put_varm_double(ncid, varid, start, edges, - stride, map, - (const double *) value); - break; - default: - status = NC_EBADTYPE; - break; - } - - if(cvtmap != NULL) - { - free(cvtmap); - } - return status; -} - -int -nc_get_vars ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - void *value) -{ - return nc_get_varm (ncid, varid, start, edges, - stride, 0, value); -} - -int -nc_put_vars ( - int ncid, - int varid, - const size_t * start, - const size_t * edges, - const ptrdiff_t * stride, - const void *value) -{ - return nc_put_varm (ncid, varid, start, edges, - stride, 0, value); -} - Index: libsrc/SXP.c =================================================================== --- libsrc/SXP.c (.../trunk) (revision 0) +++ libsrc/SXP.c (.../branches/fileinf_improvement) (revision 531) @@ -0,0 +1,573 @@ +#if defined(USE_SXP) + +#include "SXP.h" +#include "netcdf.h" +#include +#include +#include +#include +#include +#if defined(_SX) +# include +# define TMS htms +# define U_TIME hutime +# define S_TIME hstime +#else +# include +# include +# define TMS tms +# define U_TIME tms_utime +# define S_TIME tms_stime +#endif +#define SXP_CLKSPEED_KHZ 500000 /* 500 MHz */ + + /* I expect MAX/MIN are defined elsewhere but can't be bothered looking */ +#define SXP_MAX(a,b) ((a>b) ? (a) : (b)) +#define SXP_MIN(a,b) ((apath = malloc(sizeof(char)*(strlen(path)+1)); + strcpy((*sxp)->path, path); + (*sxp)->op = -1; /* not currently performing any op */ + return 0; +} + +int sxp_start_op(SXP *sxp, const int op, const int nelems, const int type) { + int ierr = 0; + struct TMS h; + +#ifdef DEBUG + fprintf(stderr,"called start_op with %d\n", op); +#endif + if (NC_FILEINF==SXP_NONE) return 0; /* should not happen in any case */ + if (sxp->op != -1) return -1; /* nesting error: op already set */ + if (op < 0) return -1; /* invalid op */ + if (op > SXP_GET_VARS) return -1; /* invalid op */ + if (type > NC_DOUBLE) return -1; /* non-sane type */ + + sxp->op = op; + sxp->nelems = nelems; + sxp->dir = 0; + if (SXP_PUT_ATTR <= op && op <= SXP_PUT_VARS) sxp->dir=1; + sxp->type = type; + sxp->c[op][SXP_CALL_COUNT]++; /* call count */ +#if defined(_SX) + ierr += syssx(HGTIME, &sxp->rstart); /* real time */ + ierr += syssx(HTIMES, &h); +#else + sxp->rstart = (long long) times(&h); +#endif + sxp->ustart = (long long) h.U_TIME; /* user time */ + sxp->sstart = (long long) h.S_TIME; /* system time */ + +#ifdef DEBUG + fprintf(stderr,"starting op %d at time %ld (%d)\n", op, sxp->rstart, sxp->fd); +#endif + + return ierr; +} + +int sxp_start_dc(SXP *sxp, const int nelems, const int type) { + long long sxcnt[7] = {0}; + int op; + int ierr = 0; +#if defined(_SX) +#else + clock_t dummy; +#endif + struct TMS h; + +#ifdef DEBUG + fprintf(stderr,"called start_dc with %d\n", op); +#endif + if (NC_FILEINF==SXP_NONE) return 0; /* should not happen in any case */ + op = sxp->op; + if (op < 0) return -1; /* no current op */ + if (op > SXP_GET_VARS) return -1; /* or invalid op */ + +#if defined(_SX) + ierr += syssx(HTIMES, &h); + ierr+=syssx(SXCNT, &sxcnt); + sxp->ex = sxcnt[0]; /* instruction count */ + sxp->vx = sxcnt[1]; /* vector instr. count */ + sxp->ve = sxcnt[2]; /* vector element count */ + sxp->cmcc = sxcnt[5]; /* cache miss counter */ + sxp->bccc = sxcnt[6]; /* bank conflict counter */ +#else + dummy = times(&h); +#endif + sxp->dcstart = (long long) h.U_TIME; /* user time */ + sxp->c[op][SXP_CONV_COUNT] ++; /* call count */ + sxp->c[op][SXP_CONV_BYTES] += nelems*sxp_types[type]; + +#ifdef DEBUG + fprintf(stderr,"starting dc at user time %ld (%d)\n", op, sxp->dcstart, sxp->fd); +#endif + + return ierr; +} + +int sxp_stop_dc(SXP *sxp) { + long long sxcnt[7] = {0}; + int op; + int ierr = 0; + long long t; +#if defined(_SX) +#else + clock_t dummy; +#endif + struct TMS h; + +#ifdef DEBUG + fprintf(stderr,"called stop_dc\n"); +#endif + if (NC_FILEINF==SXP_NONE) return 0; /* should not happen in any case */ + op = sxp->op; + if (op < 0) return -1; /* no current op */ + if (op > SXP_GET_VARS) return -1; /* or invalid op */ + +#if defined(_SX) + ierr += syssx(HTIMES, &h); + ierr+=syssx(SXCNT, &sxcnt); + sxp->c[op][SXP_CONV_EX] += sxcnt[0]-sxp->ex; /* instruction count */ + sxp->c[op][SXP_CONV_VX] += sxcnt[1]-sxp->vx; /* vector instr. count */ + sxp->c[op][SXP_CONV_VE] += sxcnt[2]-sxp->ve; /* vector element count */ + sxp->c[op][SXP_CONV_CMCC] += sxcnt[5]-sxp->cmcc; /* cache miss */ + sxp->c[op][SXP_CONV_BCCC] += sxcnt[6]-sxp->bccc; /* bank conflict */ +#else + dummy = times(&h); +#endif + t = (long long) h.U_TIME; + sxp->c[op][SXP_CONV_TIME] += t-sxp->dcstart; /* user time */ + +#ifdef DEBUG + fprintf(stderr,"stopped dc at user time %ld (%d)\n", op, h.hutime, sxp->fd); +#endif + + return ierr; +} + +int sxp_stop_op(SXP *sxp) { + int op; + int ierr = 0; + long long rend, uend, send; + struct TMS h; + +#ifdef DEBUG + fprintf(stderr,"called stop_op\n"); +#endif + if (NC_FILEINF==SXP_NONE) return 0; /* should not happen in any case */ + op = sxp->op; + if (op < 0) return -1; /* no current op */ + if (op > SXP_GET_VARS) return -1; /* or invalid op */ + +#if defined(_SX) + ierr += syssx(HGTIME, &rend); + ierr += syssx(HTIMES, &h); +#else + rend = (long long)times(&h); +#endif + uend = h.U_TIME; + send = h.S_TIME; + sxp->c[op][SXP_REAL_TIME] += rend-sxp->rstart; /* real time */ + sxp->c[op][SXP_USER_TIME] += uend-sxp->ustart; /* user time */ + sxp->c[op][SXP_SYS_TIME] += send-sxp->sstart; /* system time */ + if (sxp->dir == 0) { /* count */ + sxp->c[op][SXP_GET_BYTES]+= sxp->nelems*sxp_types[sxp->type]; + } else { + sxp->c[op][SXP_PUT_BYTES]+= sxp->nelems*sxp_types[sxp->type]; + } + sxp->op = -1; + sxp->nelems = 0; + sxp->type = 0; + +#ifdef DEBUG + fprintf(stderr,"stopped op %d at time %ld (%d)\n", op, rend, sxp->fd); +#endif + + return ierr; +} + +int sxp_add_elems(SXP *sxp, const int nelems) { + /* see SXP.h for explanation */ + if (NC_FILEINF==SXP_NONE) return 0; /* should not happen in any case */ + sxp->nelems += nelems; +#ifdef DEBUG + fprintf(stderr,"adding %d elems (%d)\n", nelems, sxp->fd); +#endif + return 0; +} + +int sxp_set_type(SXP *sxp, const int type) { + /* see SXP.h for explanation */ + if (NC_FILEINF==SXP_NONE) return 0; /* should not happen in any case */ + if (type > NC_DOUBLE) return -1; /* non-sane type */ + sxp->type = type; +#ifdef DEBUG + fprintf(stderr,"setting type to %d (%d)\n", type, sxp->fd); +#endif + return 0; +} + +int sxp_add_time(SXP *sxp, const int op, const long long r, + const long long u, const long long s) { + /* see SXP.h for explanation */ + if (NC_FILEINF==SXP_NONE) return 0; /* should not happen in any case */ + if (op < 0) return -1; /* invalid op */ + if (op > SXP_GET_VARS) return -1; /* invalid op */ + + sxp->c[op][SXP_REAL_TIME] += r; /* real time */ + sxp->c[op][SXP_USER_TIME] += u; /* user time */ + sxp->c[op][SXP_SYS_TIME] += s; /* system time */ + +#ifdef DEBUG + fprintf(stderr,"adding %d/%d/%d us to %d (%d)\n", r,u,s, op, sxp->fd); +#endif + return 0; +} + +int sxp_set_info(SXP *sxp, int fd, size_t bufsize) { + if (NC_FILEINF==SXP_NONE) return 0; /* should not happen in any case */ +#if 0 /* debug */ + fprintf(stderr, "setting bufsize for %s to %d\n", sxp->path, bufsize); +#endif + sxp->bufsize = bufsize; + sxp->fd = fd; + return 0; +} + +/* move byte counts into end, because the fill might return */ +/* less than was requested */ +int sxp_start_fill(SXP *sxp) { + int ierr=0; +#if defined(_SX) +#else + struct TMS h; +#endif + if (NC_FILEINF==SXP_NONE) return 0; /* should not happen in any case */ + + sxp->b[SXP_FILL_COUNT]++; +#if defined(_SX) + ierr += syssx(HGTIME, &sxp->bstart); /* real time */ +#else + sxp->bstart = (long long) times(&h); +#endif + +#ifdef DEBUG + fprintf(stderr,"starting fill at time %ld (%d)\n", sxp->bstart, sxp->fd); +#endif + return ierr; +} + +int sxp_stop_fill(SXP *sxp, const size_t bytes) { + int ierr=0; +#if defined(_SX) +#else + struct TMS h; +#endif + long long bend; + if (NC_FILEINF==SXP_NONE) return 0; /* should not happen in any case */ + + sxp->b[SXP_FILL_SIZE] += bytes; + if (sxp->b[SXP_FILL_MIN] == 0) + sxp->b[SXP_FILL_MIN] = bytes; + else + sxp->b[SXP_FILL_MIN] = SXP_MIN(sxp->b[SXP_FILL_MIN],bytes); + sxp->b[SXP_FILL_MAX] = SXP_MAX(sxp->b[SXP_FILL_MAX],bytes); +#if defined(_SX) + ierr += syssx(HGTIME, &bend); +#else + bend = (long long) times(&h); +#endif + sxp->b[SXP_FILL_TIME] += bend-sxp->bstart; /* real time */ +#ifdef DEBUG + fprintf(stderr,"stopped fill after %d bytes at time %ld (%d)\n", bytes, bend, sxp->fd); +#endif + return ierr; +} + +int sxp_start_flush(SXP *sxp) { + int ierr=0; +#if defined(_SX) +#else + struct TMS h; +#endif + if (NC_FILEINF==SXP_NONE) return 0; /* should not happen in any case */ + + sxp->b[SXP_FLUSH_COUNT]++; +#if defined(_SX) + ierr += syssx(HGTIME, &sxp->bstart); /* real time */ +#else + sxp->bstart = (long long) times(&h); +#endif + +#ifdef DEBUG + fprintf(stderr,"starting flush at time %ld (%d)\n", sxp->bstart, sxp->fd); +#endif + return ierr; +} + +int sxp_stop_flush(SXP *sxp, const size_t bytes) { + int ierr=0; +#if defined(_SX) +#else + struct TMS h; +#endif + long long bend; + if (NC_FILEINF==SXP_NONE) return 0; /* should not happen in any case */ + + sxp->b[SXP_FLUSH_SIZE] += bytes; + if (sxp->b[SXP_FLUSH_MIN] == 0) + sxp->b[SXP_FLUSH_MIN] = bytes; + else + sxp->b[SXP_FLUSH_MIN] = SXP_MIN(sxp->b[SXP_FLUSH_MIN],bytes); + sxp->b[SXP_FLUSH_MAX] = SXP_MAX(sxp->b[SXP_FLUSH_MAX],bytes); +#if defined(_SX) + ierr += syssx(HGTIME, &bend); +#else + bend = (long long) times(&h); +#endif + sxp->b[SXP_FLUSH_TIME] += bend-sxp->bstart; /* real time */ +#ifdef DEBUG + fprintf(stderr,"stopped flush of %d bytes at time %ld (%d)\n", bytes, bend, sxp->fd); +#endif + return ierr; +} + +/* sjl: HP-UX prinf doesnt handle long long gracefully, so cast to long */ +int sxp_finalise(SXP *sxp,int print) { + /* print statistics to stderr, free mem used by sxp */ + char *h; + int op; + long long io; + float time_unit; + long tu; + + if (NC_FILEINF==SXP_NONE) return 0; /* was never allocated */ + + /* if there was an op in progress, stop it. (else ignore error) */ + sxp_stop_op(sxp); + +#if defined(_SX) + time_unit = 1000000.0; +#else + tu = sysconf(_SC_CLK_TCK); + time_unit = (float) tu; +#endif + + if (print) { + fprintf(stderr,"\n\nNetCDF File (fd %d): %s (blocksize %d kb)\n", + sxp->fd, sxp->path, sxp->bufsize/1024); + /* first block: real/user/sys time, bytes, and MB/sec */ + h="---NetCDF--- Count Size(KB) Real(sec) User(sec) Sys(sec) MB/sec\n"; + sxp_print_stat_block(sxp,h,time_unit,sxp_print_basic_line); + + if (NC_FILEINF>SXP_BASIC) { + /* buffer use stats */ + h="---Buffers--- Count Time(sec) Min(KB) Max(KB) Avg(KB) Tot(KB) %%Used\n"; + fprintf(stderr,h); + for (io=0, op=SXP_ACCESS; op<=SXP_GET_VARS; op++) + /* io += sxp->c[op][SXP_GET_BYTES]+sxp->c[op][SXP_PUT_BYTES]; */ + io += sxp->c[op][SXP_GET_BYTES]; + fprintf(stderr, "%s %10ld %8.3f %8.0f %8.0f %8.0f %8.0f %6.2f\n", + " Fill :", (long) sxp->b[SXP_FILL_COUNT], + (float) sxp->b[SXP_FILL_TIME] / time_unit, + (float) sxp->b[SXP_FILL_MIN] / 1024.0, + (float) sxp->b[SXP_FILL_MAX] / 1024.0, + (float) sxp->b[SXP_FILL_SIZE] / (float) SXP_MAX(sxp->b[SXP_FILL_COUNT]*1024,1), + (float) sxp->b[SXP_FILL_SIZE] / 1024.0, + 100.0 * (float)io / (float)(SXP_MAX(sxp->b[SXP_FILL_SIZE],1))); + + for (io=0, op=SXP_ACCESS; op<=SXP_GET_VARS; op++) + io += sxp->c[op][SXP_PUT_BYTES]; + fprintf(stderr, "%s %10ld %8.3f %8.0f %8.0f %8.0f %8.0f %6.2f\n", + " Flush :", (long) sxp->b[SXP_FLUSH_COUNT], + (float) sxp->b[SXP_FLUSH_TIME] / time_unit, + (float) sxp->b[SXP_FLUSH_MIN] / 1024.0, + (float) sxp->b[SXP_FLUSH_MAX] / 1024.0, + (float) sxp->b[SXP_FLUSH_SIZE] / (float) SXP_MAX(sxp->b[SXP_FLUSH_COUNT]*1024,1), + (float) sxp->b[SXP_FLUSH_SIZE] / 1024.0, + 100.0 * (float)io / (float)(SXP_MAX(sxp->b[SXP_FLUSH_SIZE],1))); + fprintf(stderr,"\n"); + + /* finally: data copy/conv. performance (count,time,vlen,v.op,cache,bank) */ +#if defined(_SX) + h="--Data Copy/Conv-- Count Size(KB) Time(sec) VLEN V.Op.%% Cache(ms) Bank(ms)\n"; +#else + h="--Data Copy/Conv-- Count Size(KB) Time(sec)\n"; +#endif + sxp_print_stat_block(sxp,h,time_unit,sxp_print_conv_line); + } + } + + /* free resources */ + free(sxp->path); + free(sxp); + return 0; +} + +/* internal routines: */ +int sxp_print_stat_block(SXP *sxp, char *heading, float time_unit, +int print_line(char *, long long *, int, float)) { + long long total[SXP_NCNT]; + int c, op; + char *pname[6] = {" put_attr:"," put_var :"," put_var1:", + " put_vara:"," put_varm:"," put_vars:"}; + char *gname[6] = {" get_attr:"," get_var :"," get_var1:", + " get_vara:"," get_varm:"," get_vars:"}; + + fprintf(stderr,heading); + print_line("access :", sxp->c[SXP_ACCESS],1,time_unit); + print_line("info :", sxp->c[SXP_INFO],1,time_unit); + if (NC_FILEINF==SXP_DETAIL) { + for (c=0; cc[op][c]; + + print_line("total put :", total,1,time_unit); + for (op=SXP_PUT_ATTR; op<=SXP_PUT_VARS; op++) + print_line(pname[op-SXP_PUT_ATTR], sxp->c[op],0,time_unit); + + for (c=0; cc[op][c]; + print_line("total get :", total,1,time_unit); + + for (op=SXP_GET_ATTR; op<=SXP_GET_VARS; op++) + print_line(gname[op-SXP_GET_ATTR], sxp->c[op],0,time_unit); + + } else { + print_line("put :", sxp->c[SXP_PUT],1,time_unit); + print_line("get :", sxp->c[SXP_GET],1,time_unit); + } + for (c=0; cc[op][c]; + print_line("Total :", total,1,time_unit); + fprintf(stderr,"\n"); + return 0; +} + +int sxp_print_basic_line(char *name, long long c[SXP_NCNT], int force, float time_unit) { + /* op_name: Count Size(KB) Real(sec) User(sec) Sys(sec) MB/sec */ + float t = time_unit/(1024*1024); /* convert bytes/time_unit to MB/s */ + long long b = c[SXP_GET_BYTES]+c[SXP_PUT_BYTES]; + if (c[SXP_CALL_COUNT] == 0 && !force) return 0; /* empty line, dont print it */ + fprintf(stderr, "%s %10ld %11.3f %8.3f %8.3f %8.3f %8.3f\n", + name, + (long) c[SXP_CALL_COUNT], + (float)b / 1024.0, + (float) c[SXP_REAL_TIME] / time_unit, + (float) c[SXP_USER_TIME] / time_unit, + (float) c[SXP_SYS_TIME] / time_unit, + t*(float)b / (float)SXP_MAX(c[SXP_REAL_TIME],1) ); + return 0; +} + +int sxp_print_conv_line(char *name, long long c[SXP_NCNT], int force, float time_unit) { + /* Copy/Convert: Count Time(sec) VLEN V.Op.% Cache Miss(ms) Bank(ms) */ + long long ve,vx,ex; /*shorthand */ + if (c[SXP_CONV_COUNT] == 0 && !force) return 0; /*empty line, dont print it */ + /* first (common) half */ + fprintf(stderr, "%s %10ld %8.0f %8.3f", + name, + (long) c[SXP_CONV_COUNT], + (float) c[SXP_CONV_BYTES] / 1024.0, + (float) c[SXP_CONV_TIME] / time_unit); +#if defined(_SX) + ve = c[SXP_CONV_VE]; + vx = c[SXP_CONV_VX]; + ex = c[SXP_CONV_EX]; + fprintf(stderr, " %6.2f %6.2f %8.3f %8.3f", + (float) ve / (float)SXP_MAX(vx,1), + 100.0*(float)ve / (float) SXP_MAX((ex-vx)+ve,1), + (float) c[SXP_CONV_CMCC] / (float)SXP_CLKSPEED_KHZ, + (float) c[SXP_CONV_BCCC] / (float)SXP_CLKSPEED_KHZ); +#endif + fprintf(stderr, "\n"); + return 0; +} + +#else /* not USE_SXP */ +int NC_FILEINF, SXP_ACCESS, SXP_INFO, SXP_PUT_ATTR, SXP_PUT_VAR, + SXP_PUT_VAR1, SXP_PUT_VARA, SXP_PUT_VARM, SXP_PUT_VARS, + SXP_GET_ATTR, SXP_GET_VAR, SXP_GET_VAR1, SXP_GET_VARA, + SXP_GET_VARM, SXP_GET_VARS, SXP_PUT, SXP_GET; +#endif Index: libsrc/SXP.h =================================================================== --- libsrc/SXP.h (.../trunk) (revision 0) +++ libsrc/SXP.h (.../branches/fileinf_improvement) (revision 531) @@ -0,0 +1,147 @@ +#ifndef SXP_H +#define SXP_H + +#include + +typedef struct SXP SXP; /* SX performance counter set. One per operation */ + +/* the counters: */ +#define SXP_NCNT 14 /* number of counters */ +#define SXP_CALL_COUNT 0 +#define SXP_REAL_TIME 1 +#define SXP_USER_TIME 2 +#define SXP_SYS_TIME 3 +#define SXP_GET_BYTES 4 +#define SXP_PUT_BYTES 5 +#define SXP_CONV_COUNT 6 +#define SXP_CONV_BYTES 7 +#define SXP_CONV_TIME 8 +#define SXP_CONV_EX 9 +#define SXP_CONV_VX 10 +#define SXP_CONV_VE 11 +#define SXP_CONV_CMCC 12 +#define SXP_CONV_BCCC 13 + +/* buffer stats affect file, not operations (lower level) */ +#define SXP_BCNT 11 /* number of buffer counters */ +#define SXP_FILL_COUNT 1 +#define SXP_FILL_SIZE 2 +#define SXP_FILL_MIN 3 +#define SXP_FILL_MAX 4 +#define SXP_FILL_TIME 5 +#define SXP_FLUSH_COUNT 6 +#define SXP_FLUSH_SIZE 7 +#define SXP_FLUSH_MIN 8 +#define SXP_FLUSH_MAX 9 +#define SXP_FLUSH_TIME 10 + +struct SXP { + int fd; /* file descriptor */ + char *path; /* path & name */ + size_t bufsize; /* buffer size used (0=unknown) */ + /* there are 14 operation types. If not counting in detail, only + 4 are actually used. The wasted memory is small enough not to + care about. */ + long long c[14][SXP_NCNT]; /* the counters */ + long long b[SXP_BCNT]; /* buffer counters */ + int op; /* the current op. -1 means "none" */ + int nelems; /* number of elements read or written */ + int dir; /* direction of i/o: 0=get 1=put */ + int type; /* element type (from NC_var *varp->type) */ + /* temp space to hold certain counters */ + long long rstart; /* real time start for current op invocation */ + long long ustart; /* user time ... */ + long long sstart; /* system time ... */ + long long dcstart; /* data conv start time (user) */ + long long bstart; /* buffer fill/flush start time (real) */ + long long ex,vx,ve,cmcc,bccc; /* other data conv counters. only used for SX */ +}; + + /* various psuedo-constants: */ + /* flags: */ +#define SXP_NONE 0 +#define SXP_BASIC 1 +#define SXP_NORMAL 2 +#define SXP_DETAIL 3 +extern int NC_FILEINF; + + /* operations: */ +extern int SXP_ACCESS; +extern int SXP_INFO; +extern int SXP_PUT_ATTR; +extern int SXP_PUT_VAR; +extern int SXP_PUT_VAR1; +extern int SXP_PUT_VARA; +extern int SXP_PUT_VARM; +extern int SXP_PUT_VARS; +extern int SXP_GET_ATTR; +extern int SXP_GET_VAR; +extern int SXP_GET_VAR1; +extern int SXP_GET_VARA; +extern int SXP_GET_VARM; +extern int SXP_GET_VARS; + + /* calls */ +int sxp_init(SXP **sxp, const char *path); +int sxp_finalise(SXP *sxp, int print); /* if print==1, print stats */ + /* operations */ +int sxp_start_op(SXP *sxp, const int op, const int nelems, const int type); +int sxp_stop_op(SXP *sxp); + /* data conversion and copying */ +int sxp_start_dc(SXP *sxp, const int nelems, const int type); +int sxp_stop_dc(SXP *sxp); + /* buffer fill/flush */ +int sxp_start_fill(SXP *sxp); +int sxp_stop_fill(SXP *sxp, const size_t bytes); +int sxp_start_flush(SXP *sxp); +int sxp_stop_flush(SXP *sxp, const size_t bytes); + /* other support: in many cases the element count is difficult + to determine (eg when using put_vara), so make it possible + to accumulate the element count during an operaiton */ +int sxp_add_elems(SXP *sxp, const int nelems); + /* other times (varm/vars) you can't tell the type right off. + make it possible to set the type later: */ +int sxp_set_type(SXP *sxp, const int type); + /* on open and create, cant measure time in the usual way because + * SXP is not create till partway through. Make it possible to + * add time to an op group manually (us is microseconds) */ +int sxp_add_time(SXP *sxp, const int op, const long long r, + const long long u, const long long s); + /* other useful info for printing at the end. So far the + * buffer size used is all i can think of */ +int sxp_set_info(SXP *sxp, int fd, size_t bufsize); + + /* call patterns */ +#ifdef USE_SXP +#define SXP_INIT(sxp,path) sxp_init(sxp,path) +#define SXP_FINALISE(sxp,p) sxp_finalise(sxp,p) +#define SXP_START_OP(sxp,op,n,t) if (NC_FILEINF) sxp_start_op(sxp,op,n,t) +#define SXP_STOP_OP(sxp) if (NC_FILEINF) sxp_stop_op(sxp) +#define SXP_START_DC(sxp,n,t) if (NC_FILEINF>=SXP_NORMAL) sxp_start_dc(sxp,n,t) +#define SXP_STOP_DC(sxp) if (NC_FILEINF>=SXP_NORMAL) sxp_stop_dc(sxp) +#define SXP_START_FILL(sxp) if (NC_FILEINF>=SXP_NORMAL) sxp_start_fill(sxp) +#define SXP_STOP_FILL(sxp,b) if (NC_FILEINF>=SXP_NORMAL) sxp_stop_fill(sxp,b) +#define SXP_START_FLUSH(sxp) if (NC_FILEINF>=SXP_NORMAL) sxp_start_flush(sxp) +#define SXP_STOP_FLUSH(sxp,b) if (NC_FILEINF>=SXP_NORMAL) sxp_stop_flush(sxp,b) +#define SXP_ADD_ELEMS(sxp,n) if (NC_FILEINF) sxp_add_elems(sxp,n) +#define SXP_SET_TYPE(sxp,t) if (NC_FILEINF) sxp_set_type(sxp,t) +#define SXP_ADD_TIME(sxp,op,r,u,s) if (NC_FILEINF) sxp_add_time(sxp,op,r,u,s) +#define SXP_SET_INFO(sxp,fd,bs) if (NC_FILEINF) sxp_set_info(sxp,fd,bs) +#else +#define SXP_INIT(sxp,path) ; +#define SXP_FINALISE(sxp,p) ; +#define SXP_START_OP(sxp,op,n,t) ; +#define SXP_STOP_OP(sxp) ; +#define SXP_START_DC(sxp,n,t) ; +#define SXP_STOP_DC(sxp) ; +#define SXP_START_FILL(sxp) ; +#define SXP_STOP_FILL(sxp,b) ; +#define SXP_START_FLUSH(sxp) ; +#define SXP_STOP_FLUSH(sxp,b) ; +#define SXP_ADD_ELEMS(sxp,n) ; +#define SXP_SET_TYPE(sxp,t) ; +#define SXP_ADD_TIME(sxp,op,r,u,s) ; +#define SXP_SET_INFO(sxp,fd,bs) ; +#endif /* USE_SXP */ + +#endif /* SXP_H */ Index: libsrc/pg_interface.m4 =================================================================== --- libsrc/pg_interface.m4 (.../trunk) (revision 0) +++ libsrc/pg_interface.m4 (.../branches/fileinf_improvement) (revision 531) @@ -0,0 +1,1082 @@ + +dnl ---- sjl: the external interface is now in pg_interface.m4. This is +dnl ---- mostly to simplify diffing and patching, since the interface +dnl ---- part has been refactored rather a bit to facilitate adding +dnl ---- profiling hooks + +dnl ----------------------------------------------------------- +dnl +dnl NCGETNCP +dnl declare important variables and get the ncp and type (so that +dnl SXP_START_OP works ..) +dnl +define(`NCGETNCP',dnl +`dnl + int status; + NC *ncp; + const NC_var *varp; + + status = NC_check_id(ncid, &ncp); + if(status != NC_NOERR) return status; + + varp = NC_lookupvar(ncp, varid); + if(varp == NULL) return NC_ENOTVAR; /* TODO: lost NC_EGLOBAL */ +')dnl + + +dnl ----------------------------------------------------------- +dnl +dnl NCBASICTESTS(put|get, abbrev) +dnl sjl: basic sanity tests of arguments, getting type name (abbrev) +dnl etc. We really want to meanure the whole operation, so instead +dnl of returning with an error, jump down to "done", where SXP_STOP_OP +dnl is called and the status returned +dnl +define(`NCBASICTESTS',dnl +`dnl + +ifelse($1, put,dnl +`dnl + if(NC_readonly(ncp)) + { status=NC_EPERM; goto done; } +')dnl + + if(NC_indef(ncp)) + { status=NC_EINDEFINE; goto done; } + +ifelse($2, text,dnl +`dnl + if(varp->type != NC_CHAR) + { status=NC_ECHAR; goto done; } +',dnl +`dnl + if(varp->type == NC_CHAR) + { status=NC_ECHAR; goto done; } +')dnl +')dnl + +dnl ----------------------------------------------------------- + +/* Public */ + +dnl +dnl NCPUTVAR1(Abbrev, Type) +dnl NCGETVAR1(Abbrv, Type) +dnl +dnl NCPUTGETVAR1(put|get, PUT|GET, abbrev, type) +dnl sjl: generalised put/get var1 routine. The second PUT/GET is +dnl just an uppercase of the first, easier to call SXP routine +dnl that way +dnl +define(`NCPUTGETVAR1',dnl +`dnl +int +nc_$1_var1_$3(int ncid, int varid, const size_t *coord, $4 *value) +{ +NCGETNCP +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_$2_VAR1,0,varp->type); +#endif +NCBASICTESTS($1,$3) + status = NCcoordck(ncp, varp, coord); + if(status != NC_NOERR) goto done; + + if(IS_RECVAR(varp)) + { + status = NCvnrecs(ncp, *coord +1); + if(status != NC_NOERR) goto done; + } + + status = $1NCv_$3(ncp, varp, coord, 1, value); + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; +} +')dnl + + +NCPUTGETVAR1(put, PUT, text, const char) +NCPUTGETVAR1(put, PUT, uchar, const uchar) +NCPUTGETVAR1(put, PUT, schar, const schar) +NCPUTGETVAR1(put, PUT, short, const short) +NCPUTGETVAR1(put, PUT, int, const int) +NCPUTGETVAR1(put, PUT, long, const long) +NCPUTGETVAR1(put, PUT, float, const float) +NCPUTGETVAR1(put, PUT, double, const double) + +NCPUTGETVAR1(get, GET, text, char) +NCPUTGETVAR1(get, GET, uchar, uchar) +NCPUTGETVAR1(get, GET, schar, schar) +NCPUTGETVAR1(get, GET, short, short) +NCPUTGETVAR1(get, GET, int, int) +NCPUTGETVAR1(get, GET, long, long) +NCPUTGETVAR1(get, GET, float, float) +NCPUTGETVAR1(get, GET, double, double) + +dnl +dnl NCPUTVARA(Abbrv, Type) +dnl NCGETVARA(Abbrv, Type) +dnl +dnl NCPUTGETVARA(put|get, PUT|GET, abbrev, type) +dnl sjl: generalised put/get vara routine. The second PUT/GET is +dnl just an uppercase of the first, easier to call SXP routine +dnl that way +dnl +define(`NCPUTGETVARA',dnl +`dnl +int +nc_$1_vara_$3(int ncid, int varid, + const size_t *start, const size_t *edges, $4 *value) +{ + int ii; + size_t iocount; +NCGETNCP +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_$2_VARA,0,varp->type); +#endif +NCBASICTESTS($1,$3) + + status = NCcoordck(ncp, varp, start); + if(status != NC_NOERR) goto done; + status = NCedgeck(ncp, varp, start, edges); + if(status != NC_NOERR) goto done; + + if(varp->ndims == 0) /* scalar variable */ + { + status = $1NCv_$3(ncp, varp, start, 1, value); + goto done; + } + + if(IS_RECVAR(varp)) + { +ifelse($1, put,dnl +`dnl + status = NCvnrecs(ncp, *start + *edges); + if(status != NC_NOERR) goto done; +',dnl +`dnl + if(*start + *edges > NC_get_numrecs(ncp)) + { status = NC_EEDGE; goto done; } +')dnl + + if(varp->ndims == 1 && ncp->recsize <= varp->len) + { + /* one dimensional && the only record variable */ + status =$1NCv_$3(ncp, varp, start, *edges, value); + goto done; + } + } + + /* + * find max contiguous + * and accumulate max count for a single io operation + */ + ii = NCiocount(ncp, varp, edges, &iocount); + + if(ii == -1) + { + status = $1NCv_$3(ncp, varp, start, iocount, value); + goto done; + } + + 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 = $1NCv_$3(ncp, varp, coord, iocount, + value); + 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; + odo1(start, upper, coord, &upper[index], &coord[index]); + } + + FREE_ONSTACK(upper); + FREE_ONSTACK(coord); + } /* end inline */ + + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; +} +')dnl + +NCPUTGETVARA(put, PUT, text, const char) +NCPUTGETVARA(put, PUT, uchar, const uchar) +NCPUTGETVARA(put, PUT, schar, const schar) +NCPUTGETVARA(put, PUT, short, const short) +NCPUTGETVARA(put, PUT, int, const int) +NCPUTGETVARA(put, PUT, long, const long) +NCPUTGETVARA(put, PUT, float, const float) +NCPUTGETVARA(put, PUT, double, const double) + +NCPUTGETVARA(get, GET, text, char) +NCPUTGETVARA(get, GET, uchar, uchar) +NCPUTGETVARA(get, GET, schar, schar) +NCPUTGETVARA(get, GET, short, short) +NCPUTGETVARA(get, GET, int, int) +NCPUTGETVARA(get, GET, long, long) +NCPUTGETVARA(get, GET, float, float) +NCPUTGETVARA(get, GET, double, double) + +#if defined(__cplusplus) +/* C++ consts default to internal linkage and must be initialized */ +const size_t coord_zero[NC_MAX_VAR_DIMS] = {0}; +#else +static const size_t coord_zero[NC_MAX_VAR_DIMS]; +#endif + +dnl +dnl NCPUTVAR(Abbrev, Type) +dnl NCGETVAR(Abbrv, Type) +dnl +dnl NCPUTGETVAR(put|get, PUT|GET, abbrev, type) +dnl sjl: generalised put/get var routine. The second PUT/GET is +dnl just an uppercase of the first, easier to call SXP routine +dnl that way +dnl +define(`NCPUTGETVAR',dnl +`dnl +int +nc_$1_var_$3(int ncid, int varid, $4 *value) +{ +NCGETNCP +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_$2_VAR,0,varp->type); +#endif +NCBASICTESTS($1,$3) + + if(varp->ndims == 0) /* scalar variable */ + { + const size_t zed = 0; + status = $1NCv_$3(ncp, varp, &zed, 1, value); + goto done; + } + + if(!IS_RECVAR(varp)) + { + status = $1NCv_$3(ncp, varp, coord_zero, *varp->dsizes, value); + goto done; + } + /* else */ + + if(varp->ndims == 1 && ncp->recsize <= varp->len) + { + /* one dimensional && the only record variable */ + status = $1NCv_$3(ncp, varp, coord_zero, NC_get_numrecs(ncp), + value); + goto done; + } + /* else */ + + { + ALLOC_ONSTACK(coord, size_t, varp->ndims); + size_t elemsPerRec = 1; + const size_t nrecs = NC_get_numrecs(ncp); + (void) memset(coord, 0, varp->ndims * sizeof(size_t)); + /* TODO: fix dsizes to avoid this nonsense */ + if(varp->ndims > 1) + elemsPerRec = varp->dsizes[1]; + while(*coord < nrecs) + { + const int lstatus = $1NCv_$3(ncp, varp, coord, elemsPerRec, + value); + 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 += elemsPerRec; + (*coord)++; + } + FREE_ONSTACK(coord); + } /* elemsPerRec */ + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; +} +')dnl + +NCPUTGETVAR(put, PUT, text, const char) +NCPUTGETVAR(put, PUT, uchar, const uchar) +NCPUTGETVAR(put, PUT, schar, const schar) +NCPUTGETVAR(put, PUT, short, const short) +NCPUTGETVAR(put, PUT, int, const int) +NCPUTGETVAR(put, PUT, long, const long) +NCPUTGETVAR(put, PUT, float, const float) +NCPUTGETVAR(put, PUT, double, const double) + +NCPUTGETVAR(get, GET, text, char) +NCPUTGETVAR(get, GET, uchar, uchar) +NCPUTGETVAR(get, GET, schar, schar) +NCPUTGETVAR(get, GET, short, short) +NCPUTGETVAR(get, GET, int, int) +NCPUTGETVAR(get, GET, long, long) +NCPUTGETVAR(get, GET, float, float) +NCPUTGETVAR(get, GET, double, double) + +dnl +dnl NCGETVAR(Abbrv, Type) +dnl + +/* Begin putgetg.c */ +dnl + +/* sjl: ok, this is a bit ugly! the call to SXP_START_OP in nc_get/put_vars + * routines will start the op, then when it is called again in the varm + * routines it will exit quickly with a nesting error. Since we are not checking + * errors, the program will continue and the SXP_STOP_OP in the varm routine + * will actually stop the current op, which is still the vars one. + * The SXP_STOP_OP in the vars routines will return a "no current op" error + * (which we dont check) in most cases, and if the varm routines return an + * error without first calling SXP_STOP_OP (eg args are wrong), then the + * SXP_STOP_OP in the vars routine will catch it and sane nesting will be + * restored. + * In other words, it all works out in the wash, so long as we dont check + * for errors! + * (my heartfelt apologies to anyone attempting to maintain this ..) + */ + +dnl +dnl NCGETVARS(Abbrv, Type) +dnl NCPUTVARS(Abbrv, Type) +dnl +dnl NCPUTGETVARS(put|get, PUT|GET, abbrev, type) +dnl sjl: generalised put/get vars routine. The second PUT/GET is +dnl just an uppercase of the first, easier to call SXP routine +dnl that way +dnl +define(`NCPUTGETVARS',dnl +`dnl +int +nc_$1_vars_$3 ( + int ncid, + int varid, + const size_t * start, + const size_t * edges, + const ptrdiff_t * stride, + $4 *value) +{ +NCGETNCP +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_$2_VARS,0,varp->type); +#endif + status = nc_$1_varm_$3 (ncid, varid, start, edges, + stride, 0, value); +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; +} +')dnl + +NCPUTGETVARS(put, PUT, text, const char) +NCPUTGETVARS(put, PUT, uchar, const uchar) +NCPUTGETVARS(put, PUT, schar, const schar) +NCPUTGETVARS(put, PUT, short, const short) +NCPUTGETVARS(put, PUT, int, const int) +NCPUTGETVARS(put, PUT, long, const long) +NCPUTGETVARS(put, PUT, float, const float) +NCPUTGETVARS(put, PUT, double, const double) + +NCPUTGETVARS(get, GET, text, char) +NCPUTGETVARS(get, GET, uchar, uchar) +NCPUTGETVARS(get, GET, schar, schar) +NCPUTGETVARS(get, GET, short, short) +NCPUTGETVARS(get, GET, int, int) +NCPUTGETVARS(get, GET, long, long) +NCPUTGETVARS(get, GET, float, float) +NCPUTGETVARS(get, GET, double, double) + +/* + * Generalized hyperslab input. + */ + +dnl +dnl NCPUTGETVARM(put|get, PUT|GET, abbrev, type) +dnl sjl: generalised put/get varm routine. The second PUT/GET is +dnl just an uppercase of the first, easier to call SXP routine +dnl that way +dnl +define(`NCPUTGETVARM',dnl +`dnl +int +nc_$1_varm_$3(int ncid, int varid, + const size_t *start, const size_t *edges, + const ptrdiff_t *stride, + const ptrdiff_t *map, + $4 *value) +{ + int maxidim; /* maximum dimensional index */ + +NCGETNCP +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_$2_VARM,0,varp->type); +#endif +NCBASICTESTS($1,$3) + + maxidim = (int) varp->ndims - 1; + if (maxidim < 0) + { + /* + * The variable is a scalar; consequently, + * there s only one thing to get and only one place to put it. + * (Why was I called?) + */ + status = $1NCv_$3(ncp, varp, start, 1, value); + goto done; + } + + /* + * else + * The variable is an array. + */ + { + int idim; + size_t *mystart = NULL; + size_t *myedges; + size_t *iocount; /* count vector */ + size_t *stop; /* stop indexes */ + size_t *length; /* edge lengths in bytes */ + ptrdiff_t *mystride; + ptrdiff_t *mymap; + + /* + * Verify stride argument. + */ + for (idim = 0; idim <= maxidim; ++idim) + { + if (stride != NULL + && (stride[idim] == 0 + /* cast needed for braindead systems with signed size_t */ + || (unsigned long) stride[idim] >= X_INT_MAX)) + { status = NC_ESTRIDE; goto done; } + } + + /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */ + mystart = (size_t *)calloc(varp->ndims * 7, sizeof(ptrdiff_t)); + if(mystart == NULL) + { status = NC_ENOMEM; goto done; } + myedges = mystart + varp->ndims; + iocount = myedges + varp->ndims; + stop = iocount + varp->ndims; + length = stop + varp->ndims; + mystride = (ptrdiff_t *)(length + varp->ndims); + mymap = mystride + varp->ndims; + + /* + * Initialize I/O parameters. + */ + for (idim = maxidim; idim >= 0; --idim) + { + mystart[idim] = start != NULL + ? start[idim] + : 0; + + if (edges[idim] == 0) + { + status = NC_NOERR; /* read/write no data */ + goto free_mem; + } + + myedges[idim] = edges != NULL + ? edges[idim] + : idim == 0 && IS_RECVAR (varp) + ? NC_get_numrecs(ncp) - mystart[idim] + : varp->shape[idim] - mystart[idim]; + mystride[idim] = stride != NULL + ? stride[idim] + : 1; + mymap[idim] = map != NULL + ? map[idim] + : idim == maxidim + ? 1 + : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]; + + iocount[idim] = 1; + length[idim] = mymap[idim] * myedges[idim]; + stop[idim] = mystart[idim] + myedges[idim] * mystride[idim]; + } + + /* + * Check start, edges + */ +ifelse($1, put,dnl +`dnl + for (idim = IS_RECVAR (varp); idim < maxidim; ++idim) + { + if (mystart[idim] > varp->shape[idim]) + { status = NC_EINVALCOORDS; goto free_mem; } + if (mystart[idim] + myedges[idim] > varp->shape[idim]) + { status = NC_EEDGE; goto free_mem; } + } +',dnl +`dnl + for (idim = maxidim; idim >= 0; --idim) + { + size_t dimlen = + idim == 0 && IS_RECVAR (varp) + ? NC_get_numrecs(ncp) + : varp->shape[idim]; + if (mystart[idim] >= dimlen) + { status = NC_EINVALCOORDS; goto free_mem; } + if (mystart[idim] + myedges[idim] > dimlen) + { status = NC_EEDGE; goto free_mem; } + } +')dnl + /* + * As an optimization, adjust I/O parameters when the fastest + * dimension has unity stride both externally and internally. + * In this case, the user could have called a simpler routine + * (i.e. ncvar$1() + */ + if (mystride[maxidim] == 1 + && mymap[maxidim] == 1) + { + iocount[maxidim] = myedges[maxidim]; + mystride[maxidim] = (ptrdiff_t) myedges[maxidim]; + mymap[maxidim] = (ptrdiff_t) length[maxidim]; + } + + /* + * Perform I/O. Exit when done. + */ + for (;;) + { + /* TODO: */ + int lstatus = nc_$1_vara_$3 (ncid, varid, mystart, iocount, + value); + if (lstatus != NC_NOERR + && (status == NC_NOERR || lstatus != NC_ERANGE)) + status = lstatus; + + /* + * The following code permutes through the variable s + * external start-index space and it s internal address + * space. At the UPC, this algorithm is commonly + * called "odometer code". + */ + idim = maxidim; + carry: + value += mymap[idim]; + mystart[idim] += mystride[idim]; + if (mystart[idim] == stop[idim]) + { + mystart[idim] = start[idim]; + value -= length[idim]; + if (--idim < 0) + break; /* normal return */ + goto carry; + } + } /* I/O loop */ + free_mem: + free(mystart); + } /* variable is array */ + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; +} +')dnl + +NCPUTGETVARM(put, PUT, text, const char) +NCPUTGETVARM(put, PUT, uchar, const uchar) +NCPUTGETVARM(put, PUT, schar, const schar) +NCPUTGETVARM(put, PUT, short, const short) +NCPUTGETVARM(put, PUT, int, const int) +NCPUTGETVARM(put, PUT, long, const long) +NCPUTGETVARM(put, PUT, float, const float) +NCPUTGETVARM(put, PUT, double, const double) + +NCPUTGETVARM(get, GET, text, char) +NCPUTGETVARM(get, GET, uchar, uchar) +NCPUTGETVARM(get, GET, schar, schar) +NCPUTGETVARM(get, GET, short, short) +NCPUTGETVARM(get, GET, int, int) +NCPUTGETVARM(get, GET, long, long) +NCPUTGETVARM(get, GET, float, float) +NCPUTGETVARM(get, GET, double, double) + +#ifdef NO_NETCDF_2 +extern int +nctypelen(nc_type datatype); +#endif + +/* no longer deprecated, used to support the 2.x interface and also the netcdf-4 api. */ +int +nc_get_att(int ncid, int varid, const char *name, void *value) +{ + int status; + nc_type atttype; + + status = nc_inq_atttype(ncid, varid, name, &atttype); + if(status != NC_NOERR) + return status; + + switch (atttype) { + case NC_BYTE: + return nc_get_att_schar(ncid, varid, name, + (schar *)value); + case NC_CHAR: + return nc_get_att_text(ncid, varid, name, + (char *)value); + case NC_SHORT: + return nc_get_att_short(ncid, varid, name, + (short *)value); + case NC_INT: +#if (SIZEOF_INT >= X_SIZEOF_INT) + return nc_get_att_int(ncid, varid, name, + (int *)value); +#elif SIZEOF_LONG == X_SIZEOF_INT + return nc_get_att_long(ncid, varid, name, + (long *)value); +#endif + case NC_FLOAT: + return nc_get_att_float(ncid, varid, name, + (float *)value); + case NC_DOUBLE: + return nc_get_att_double(ncid, varid, name, + (double *)value); + } + return NC_EBADTYPE; +} + +int +nc_put_att( + int ncid, + int varid, + const char *name, + nc_type type, + size_t nelems, + const void *value) +{ + switch (type) { + case NC_BYTE: + return nc_put_att_schar(ncid, varid, name, type, nelems, + (schar *)value); + case NC_CHAR: + return nc_put_att_text(ncid, varid, name, nelems, + (char *)value); + case NC_SHORT: + return nc_put_att_short(ncid, varid, name, type, nelems, + (short *)value); + case NC_INT: +#if (SIZEOF_INT >= X_SIZEOF_INT) + return nc_put_att_int(ncid, varid, name, type, nelems, + (int *)value); +#elif SIZEOF_LONG == X_SIZEOF_INT + return nc_put_att_long(ncid, varid, name, type, nelems, + (long *)value); +#endif + case NC_FLOAT: + return nc_put_att_float(ncid, varid, name, type, nelems, + (float *)value); + case NC_DOUBLE: + return nc_put_att_double(ncid, varid, name, type, nelems, + (double *)value); + } + return NC_EBADTYPE; +} + +int +nc_get_var1(int ncid, int varid, const size_t *coord, void *value) +{ + int status; + nc_type vartype; + + status = nc_inq_vartype(ncid, varid, &vartype); + if(status != NC_NOERR) + return status; + + switch(vartype){ + case NC_CHAR: + return nc_get_var1_text(ncid, varid, coord, + (char *) value); + case NC_BYTE: + return nc_get_var1_schar(ncid, varid, coord, + (schar *) value); + case NC_SHORT: + return nc_get_var1_short(ncid, varid, coord, + (short *) value); + case NC_INT: + return nc_get_var1_int(ncid, varid, coord, + (int *) value); + case NC_FLOAT: + return nc_get_var1_float(ncid, varid, coord, + (float *) value); + case NC_DOUBLE: + return nc_get_var1_double(ncid, varid, coord, + (double *) value); + } + return NC_EBADTYPE; +} + + +int +nc_put_var1(int ncid, int varid, const size_t *coord, const void *value) +{ + int status; + nc_type vartype; + + status = nc_inq_vartype(ncid, varid, &vartype); + if(status != NC_NOERR) + return status; + + switch(vartype){ + case NC_CHAR: + return nc_put_var1_text(ncid, varid, coord, + (const char *) value); + case NC_BYTE: + return nc_put_var1_schar(ncid, varid, coord, + (const schar *) value); + case NC_SHORT: + return nc_put_var1_short(ncid, varid, coord, + (const short *) value); + case NC_INT: + return nc_put_var1_int(ncid, varid, coord, + (const int *) value); + case NC_FLOAT: + return nc_put_var1_float(ncid, varid, coord, + (const float *) value); + case NC_DOUBLE: + return nc_put_var1_double(ncid, varid, coord, + (const double *) value); + } + return NC_EBADTYPE; +} + +int +nc_get_vara(int ncid, int varid, + const size_t *start, const size_t *edges, void *value) +{ + int status; + nc_type vartype; + + status = nc_inq_vartype(ncid, varid, &vartype); + if(status != NC_NOERR) + return status; + + switch(vartype){ + case NC_CHAR: + return nc_get_vara_text(ncid, varid, start, edges, + (char *) value); + case NC_BYTE: + return nc_get_vara_schar(ncid, varid, start, edges, + (schar *) value); + case NC_SHORT: + return nc_get_vara_short(ncid, varid, start, edges, + (short *) value); + case NC_INT: +#if (SIZEOF_INT >= X_SIZEOF_INT) + return nc_get_vara_int(ncid, varid, start, edges, + (int *) value); +#elif SIZEOF_LONG == X_SIZEOF_INT + return nc_get_vara_long(ncid, varid, start, edges, + (long *) value); +#else +#error "nc_get_vara implementation" +#endif + case NC_FLOAT: + return nc_get_vara_float(ncid, varid, start, edges, + (float *) value); + case NC_DOUBLE: + return nc_get_vara_double(ncid, varid, start, edges, + (double *) value); + } + return NC_EBADTYPE; +} + +int +nc_put_vara(int ncid, int varid, + const size_t *start, const size_t *edges, const void *value) +{ + int status; + nc_type vartype; + + status = nc_inq_vartype(ncid, varid, &vartype); + if(status != NC_NOERR) + return status; + + switch(vartype){ + case NC_CHAR: + return nc_put_vara_text(ncid, varid, start, edges, + (const char *) value); + case NC_BYTE: + return nc_put_vara_schar(ncid, varid, start, edges, + (const schar *) value); + case NC_SHORT: + return nc_put_vara_short(ncid, varid, start, edges, + (const short *) value); + case NC_INT: + return nc_put_vara_int(ncid, varid, start, edges, + (const int *) value); + case NC_FLOAT: + return nc_put_vara_float(ncid, varid, start, edges, + (const float *) value); + case NC_DOUBLE: + return nc_put_vara_double(ncid, varid, start, edges, + (const double *) value); + } + return NC_EBADTYPE; +} + +int +nc_get_varm ( + int ncid, + int varid, + const size_t * start, + const size_t * edges, + const ptrdiff_t * stride, + const ptrdiff_t * map, + void *value) +{ + int status; + nc_type vartype; + int varndims; + ptrdiff_t *cvtmap = NULL; + + status = nc_inq_vartype(ncid, varid, &vartype); + if(status != NC_NOERR) + return status; + + status = nc_inq_varndims(ncid, varid, &varndims); + if(status != NC_NOERR) + return status; + + if(map != NULL && varndims != 0) + { + /* + * convert map units from bytes to units of sizeof(type) + */ + size_t ii; + const ptrdiff_t szof = (ptrdiff_t) nctypelen(vartype); + cvtmap = (ptrdiff_t *)calloc(varndims, sizeof(ptrdiff_t)); + if(cvtmap == NULL) + return NC_ENOMEM; + for(ii = 0; ii < varndims; ii++) + { + if(map[ii] % szof != 0) + { + free(cvtmap); + return NC_EINVAL; + } + cvtmap[ii] = map[ii] / szof; + } + map = cvtmap; + } + + switch(vartype){ + case NC_CHAR: + status = nc_get_varm_text(ncid, varid, start, edges, + stride, map, + (char *) value); + break; + case NC_BYTE: + status = nc_get_varm_schar(ncid, varid, start, edges, + stride, map, + (schar *) value); + break; + case NC_SHORT: + status = nc_get_varm_short(ncid, varid, start, edges, + stride, map, + (short *) value); + break; + case NC_INT: +#if (SIZEOF_INT >= X_SIZEOF_INT) + status = nc_get_varm_int(ncid, varid, start, edges, + stride, map, + (int *) value); +#elif SIZEOF_LONG == X_SIZEOF_INT + status = nc_get_varm_long(ncid, varid, start, edges, + stride, map, + (long *) value); +#else +#error "nc_get_varm implementation" +#endif + break; + case NC_FLOAT: + status = nc_get_varm_float(ncid, varid, start, edges, + stride, map, + (float *) value); + break; + case NC_DOUBLE: + status = nc_get_varm_double(ncid, varid, start, edges, + stride, map, + (double *) value); + break; + default: + status = NC_EBADTYPE; + break; + } + + if(cvtmap != NULL) + { + free(cvtmap); + } + return status; +} + + +int +nc_put_varm ( + int ncid, + int varid, + const size_t * start, + const size_t * edges, + const ptrdiff_t * stride, + const ptrdiff_t * map, + const void *value) +{ + int status; + nc_type vartype; + int varndims; + ptrdiff_t *cvtmap = NULL; + + status = nc_inq_vartype(ncid, varid, &vartype); + if(status != NC_NOERR) + return status; + + status = nc_inq_varndims(ncid, varid, &varndims); + if(status != NC_NOERR) + return status; + + if(map != NULL && varndims != 0) + { + /* + * convert map units from bytes to units of sizeof(type) + */ + size_t ii; + const ptrdiff_t szof = (ptrdiff_t) nctypelen(vartype); + cvtmap = (ptrdiff_t *)calloc(varndims, sizeof(ptrdiff_t)); + if(cvtmap == NULL) + return NC_ENOMEM; + for(ii = 0; ii < varndims; ii++) + { + if(map[ii] % szof != 0) + { + free(cvtmap); + return NC_EINVAL; + } + cvtmap[ii] = map[ii] / szof; + } + map = cvtmap; + } + + switch(vartype){ + case NC_CHAR: + status = nc_put_varm_text(ncid, varid, start, edges, + stride, map, + (const char *) value); + break; + case NC_BYTE: + status = nc_put_varm_schar(ncid, varid, start, edges, + stride, map, + (const schar *) value); + break; + case NC_SHORT: + status = nc_put_varm_short(ncid, varid, start, edges, + stride, map, + (const short *) value); + break; + case NC_INT: +#if (SIZEOF_INT >= X_SIZEOF_INT) + status = nc_put_varm_int(ncid, varid, start, edges, + stride, map, + (const int *) value); +#elif SIZEOF_LONG == X_SIZEOF_INT + status = nc_put_varm_long(ncid, varid, start, edges, + stride, map, + (const long *) value); +#else +#error "nc_put_varm implementation" +#endif + break; + case NC_FLOAT: + status = nc_put_varm_float(ncid, varid, start, edges, + stride, map, + (const float *) value); + break; + case NC_DOUBLE: + status = nc_put_varm_double(ncid, varid, start, edges, + stride, map, + (const double *) value); + break; + default: + status = NC_EBADTYPE; + break; + } + + if(cvtmap != NULL) + { + free(cvtmap); + } + return status; +} + +int +nc_get_vars ( + int ncid, + int varid, + const size_t * start, + const size_t * edges, + const ptrdiff_t * stride, + void *value) +{ + return nc_get_varm (ncid, varid, start, edges, + stride, 0, value); +} + +int +nc_put_vars ( + int ncid, + int varid, + const size_t * start, + const size_t * edges, + const ptrdiff_t * stride, + const void *value) +{ + return nc_put_varm (ncid, varid, start, edges, + stride, 0, value); +} + + + + +dnl ---- sjl: end of interface part Index: libsrc/v1hpg.c =================================================================== --- libsrc/v1hpg.c (.../trunk) (revision 531) +++ libsrc/v1hpg.c (.../branches/fileinf_improvement) (revision 531) @@ -844,8 +844,14 @@ status = check_v1hs(psp, ncx_len_int(varp->ndims)); if(status != ENOERR) return status; +#if defined(USE_SXP) + SXP_START_DC(psp->nciop->sxp,varp->ndims,NC_INT); +#endif status = ncx_putn_int_int(&psp->pos, varp->ndims, varp->dimids); +#if defined(USE_SXP) + SXP_STOP_DC(psp->nciop->sxp); +#endif if(status != ENOERR) return status; @@ -898,8 +904,14 @@ status = check_v1hs(gsp, ncx_len_int(ndims)); if(status != ENOERR) goto unwind_alloc; +#if defined(USE_SXP) + SXP_START_DC(gsp->nciop->sxp,ndims,NC_INT); +#endif status = ncx_getn_int_int((const void **)(&gsp->pos), ndims, varp->dimids); +#if defined(USE_SXP) + SXP_STOP_DC(gsp->nciop->sxp); +#endif if(status != ENOERR) goto unwind_alloc; @@ -1233,10 +1245,21 @@ ps.end = (char *)ps.base + ps.extent; } - if (ps.version == 2) + if (ps.version == 2) { +#if defined(USE_SXP) + SXP_START_DC(ncp->nciop->sxp,sizeof(ncmagic),NC_BYTE); +#endif status = ncx_putn_schar_schar(&ps.pos, sizeof(ncmagic), ncmagic); - else + } + else { +#if defined(USE_SXP) + SXP_START_DC(ncp->nciop->sxp,sizeof(ncmagic1),NC_BYTE); +#endif status = ncx_putn_schar_schar(&ps.pos, sizeof(ncmagic1), ncmagic1); +#if defined(USE_SXP) + SXP_STOP_DC(ncp->nciop->sxp); +#endif + } if(status != ENOERR) goto release; @@ -1333,8 +1356,14 @@ schar magic[sizeof(ncmagic)]; (void) memset(magic, 0, sizeof(magic)); +#if defined(USE_SXP) + SXP_START_DC(ncp->nciop->sxp,sizeof(magic),NC_BYTE); +#endif status = ncx_getn_schar_schar( (const void **)(&gs.pos), sizeof(magic), magic); +#if defined(USE_SXP) + SXP_STOP_DC(ncp->nciop->sxp); +#endif if(status != ENOERR) goto unwind_get; @@ -1348,7 +1377,7 @@ gs.version = 1; } else if (magic[sizeof(ncmagic)-1] == 0x2) { gs.version = 2; - fSet(ncp->flags, NC_64BIT_OFFSET); + fSet(ncp->flags, NC_64BIT_OFFSET); /* Now we support version 2 file access on non-LFS systems -- rkr */ #if 0 if (sizeof(off_t) != 8) { Index: libsrc/error.c =================================================================== --- libsrc/error.c (.../trunk) (revision 531) +++ libsrc/error.c (.../branches/fileinf_improvement) (revision 531) @@ -17,6 +17,7 @@ #include #else #include "netcdf.h" + #endif #ifndef NO_STRERROR Index: libsrc/Makefile =================================================================== --- libsrc/Makefile (.../trunk) (revision 531) +++ libsrc/Makefile (.../branches/fileinf_improvement) (revision 531) @@ -26,7 +26,8 @@ string.c \ v1hpg.c \ v2i.c \ - var.c + var.c \ + SXP.c PACKING_LIST = \ $(LIB_CSRCS) \ @@ -56,7 +57,7 @@ LIB_OBJS = $(LIB_CSRCS:.c=.o) GARBAGE = t_ncio.o t_ncio t_ncx.o t_ncx t_ncxx.o t_ncxx \ - t_nc.o t_nc test.nc *.so + t_nc.o t_nc test.nc *.so putget.c ncx.c attr.c DIST_GARBAGE = ncconfig.h @@ -146,7 +147,7 @@ attr.c: attr.m4 ncx.c: ncx.m4 -putget.c: putget.m4 +putget.c: putget.m4 pg_interface.m4 t_ncxx.c: t_ncxx.m4 # Ensure that the I/O module depends on ALL implementation files. ncio.o: ffio.c posixio.c Index: libsrc/ncio.h =================================================================== --- libsrc/ncio.h (.../trunk) (revision 531) +++ libsrc/ncio.h (.../branches/fileinf_improvement) (revision 531) @@ -11,6 +11,10 @@ #include /* off_t */ #include "netcdf.h" +#if defined(USE_SXP) +# include "SXP.h" /* for profiling */ +#endif + typedef struct ncio ncio; /* forward reference */ /* @@ -117,6 +121,10 @@ */ const char *path; +#if defined (USE_SXP) + SXP *sxp; /* sjl: profiling hook */ +#endif + /* implementation private stuff */ void *NCIO_CONST pvt; }; Index: libsrc/nc.c =================================================================== --- libsrc/nc.c (.../trunk) (revision 531) +++ libsrc/nc.c (.../branches/fileinf_improvement) (revision 531) @@ -14,6 +14,22 @@ # include # include #endif +#if defined(USE_SXP) +# include "SXP.h" /* NEC SX Profiling */ +# if defined(_SX) +# include +# include +# define TMS htms +# define U_TIME hutime +# define S_TIME hstime +# else +# include +# include +# define TMS tms +# define U_TIME tms_utime +# define S_TIME tms_stime +# endif +#endif /* list of open netcdf's */ static NC *NClist = NULL; @@ -39,9 +55,10 @@ NClist = ncp; } -static void +static int del_from_NCList(NC *ncp) { + if (ncp==NULL) return NC_EINVAL; /* sjl: gracefully handle multiple file closures */ assert(ncp != NULL); if(NClist == ncp) @@ -60,6 +77,7 @@ ncp->next = NULL; ncp->prev = NULL; + return NC_NOERR; } @@ -912,6 +930,16 @@ int status; void *xp = NULL; int sizeof_off_t = 0; +#if defined(USE_SXP) + long long rs, re; /* real time start, end (for SXP) */ + struct TMS hs, he; +# if defined(_SX) + syssx(HGTIME, &rs); + syssx(HTIMES, &hs); +# else + rs = (long long) times(&hs); +# endif +#endif #if ALWAYS_NC_SHARE /* DEBUG */ fSet(ioflags, NC_SHARE); @@ -983,6 +1011,20 @@ if(chunksizehintp != NULL) *chunksizehintp = ncp->chunk; *ncid_ptr = ncp->nciop->fd; + +#if defined(USE_SXP) +# if defined(_SX) + syssx(HGTIME, &re); + syssx(HTIMES, &he); +# else + re = (long long) times(&he); +# endif + SXP_ADD_TIME(ncp->nciop->sxp,SXP_ACCESS, re-rs, + he.U_TIME-hs.U_TIME, he.S_TIME-hs.S_TIME); + SXP_START_OP(ncp->nciop->sxp,SXP_ACCESS,0,0); + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return NC_NOERR; unwind_ioc: @@ -1039,6 +1081,16 @@ { NC *ncp; int status; +#if defined(USE_SXP) + long long rs, re; /* real time start, end (for SXP) */ + struct TMS hs, he; +# if defined(_SX) + syssx(HGTIME, &rs); + syssx(HTIMES, &hs); +# else + rs = (long long) times(&hs); +# endif +#endif #if ALWAYS_NC_SHARE /* DEBUG */ fSet(ioflags, NC_SHARE); @@ -1089,6 +1141,20 @@ if(chunksizehintp != NULL) *chunksizehintp = ncp->chunk; *ncid_ptr = ncp->nciop->fd; + +#if defined(USE_SXP) +# if defined(_SX) + syssx(HGTIME, &re); + syssx(HTIMES, &he); +# else + re = (long long) times(&he); +# endif + SXP_ADD_TIME(ncp->nciop->sxp,SXP_ACCESS, re-rs, + he.U_TIME-hs.U_TIME, he.S_TIME-hs.S_TIME); + SXP_START_OP(ncp->nciop->sxp,SXP_ACCESS,0,0); + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return NC_NOERR; unwind_ioc: @@ -1119,10 +1185,19 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(!NC_indef(ncp)) - return(NC_ENOTINDEFINE); + { status = NC_ENOTINDEFINE; goto done; } - return (NC_endef(ncp, h_minfree, v_align, v_minfree, r_align)); + status = NC_endef(ncp, h_minfree, v_align, v_minfree, r_align); + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } int @@ -1135,11 +1210,20 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(!NC_indef(ncp)) - return(NC_ENOTINDEFINE); + { status = NC_ENOTINDEFINE; goto done; } /* return(NC_endef(ncp, 0, 4096, 0, 4096)); */ - return (NC_endef(ncp, 0, 1, 0, 1)); + status = NC_endef(ncp, 0, 1, 0, 1); + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -1153,11 +1237,19 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + /* final stop op is caught by sxp_finalise */ + SXP_START_OP(ncp->nciop->sxp,SXP_ACCESS,0,0); +#endif + if(NC_indef(ncp)) { status = NC_endef(ncp, 0, 1, 0, 1); /* TODO: defaults */ if(status != NC_NOERR ) { +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); /* stop before abort! */ +#endif (void) nc_abort(ncid); return status; } @@ -1192,7 +1284,7 @@ (void) ncio_close(ncp->nciop, 0); ncp->nciop = NULL; - del_from_NCList(ncp); + (void) del_from_NCList(ncp); free_NC(ncp); @@ -1272,6 +1364,11 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + /* final stop op is caught by sxp_finalise */ + SXP_START_OP(ncp->nciop->sxp,SXP_ACCESS,0,0); +#endif + doUnlink = NC_IsNew(ncp); if(ncp->old != NULL) @@ -1286,15 +1383,21 @@ else if(!NC_readonly(ncp)) { status = NC_sync(ncp); - if(status != NC_NOERR) + if(status != NC_NOERR) + { +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); /* stop before abort! */ +#endif return status; + } } (void) ncio_close(ncp->nciop, doUnlink); ncp->nciop = NULL; - del_from_NCList(ncp); + status = del_from_NCList(ncp); + if(status != NC_NOERR) return status; free_NC(ncp); @@ -1312,28 +1415,36 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(NC_readonly(ncp)) - return NC_EPERM; + { status = NC_EPERM; goto done; } if(NC_indef(ncp)) - return NC_EINDEFINE; - + { status = NC_EINDEFINE; goto done; } if(fIsSet(ncp->nciop->ioflags, NC_SHARE)) { /* read in from disk */ status = read_NC(ncp); if(status != NC_NOERR) - return status; + goto done; } ncp->old = dup_NC(ncp); if(ncp->old == NULL) - return NC_ENOMEM; + { status = NC_ENOMEM; goto done; } fSet(ncp->flags, NC_INDEF); - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -1351,6 +1462,10 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(ndimsp != NULL) *ndimsp = (int) ncp->dims.nelems; if(nvarsp != NULL) @@ -1360,6 +1475,9 @@ if(xtendimp != NULL) *xtendimp = find_NC_Udim(&ncp->dims, NULL); +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif return NC_NOERR; } @@ -1373,9 +1491,16 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(ndimsp != NULL) *ndimsp = (int) ncp->dims.nelems; +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif return NC_NOERR; } @@ -1389,9 +1514,16 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(nvarsp != NULL) *nvarsp = (int) ncp->vars.nelems; +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif return NC_NOERR; } @@ -1405,9 +1537,16 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(nattsp != NULL) *nattsp = (int) ncp->attrs.nelems; +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif return NC_NOERR; } @@ -1421,9 +1560,16 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(xtendimp != NULL) *xtendimp = find_NC_Udim(&ncp->dims, NULL); +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif return NC_NOERR; } @@ -1438,20 +1584,29 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(NC_indef(ncp)) - return NC_EINDEFINE; + { status = NC_EINDEFINE; goto done; } if(NC_readonly(ncp)) { - return read_NC(ncp); + status = read_NC(ncp); goto done; } /* else, read/write */ status = NC_sync(ncp); if(status != NC_NOERR) - return status; + goto done; - return ncp->nciop->sync(ncp->nciop); + status = ncp->nciop->sync(ncp->nciop); + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -1465,10 +1620,14 @@ status = NC_check_id(ncid, &ncp); if(status != NC_NOERR) - return status; + goto done; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(NC_readonly(ncp)) - return NC_EPERM; + { status = NC_EPERM; goto done; } oldmode = fIsSet(ncp->flags, NC_NOFILL) ? NC_NOFILL : NC_FILL; @@ -1486,19 +1645,25 @@ */ status = NC_sync(ncp); if(status != NC_NOERR) - return status; + goto done; } fClr(ncp->flags, NC_NOFILL); } else { - return NC_EINVAL; /* Invalid fillmode */ + status = NC_EINVAL; goto done; /* Invalid fillmode */ } if(old_mode_ptr != NULL) *old_mode_ptr = oldmode; - return NC_NOERR; + status = NC_NOERR; + + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } #ifdef LOCKNUMREC Index: libsrc/attr.m4 =================================================================== --- libsrc/attr.m4 (.../trunk) (revision 531) +++ libsrc/attr.m4 (.../branches/fileinf_improvement) (revision 531) @@ -17,8 +17,10 @@ #include "ncx.h" #include "fbits.h" #include "rnd.h" +#if defined(USE_SXP) +# include "SXP.h" /* NEC SX Profiling */ +#endif - /* * Free attr * Formerly @@ -394,18 +396,28 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + ncap = NC_attrarray0(ncp, varid); if(ncap == NULL) - return NC_ENOTVAR; + { status = NC_ENOTVAR; goto done; } attrp = elem_NC_attrarray(ncap, (size_t)attnum); if(attrp == NULL) - return NC_ENOTATT; + { status = NC_ENOTATT; goto done; } (void) strncpy(name, attrp->name->cp, attrp->name->nchars); name[attrp->name->nchars] = 0; - return NC_NOERR; + status = NC_NOERR; + + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -421,19 +433,28 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + ncap = NC_attrarray0(ncp, varid); if(ncap == NULL) - return NC_ENOTVAR; - + { status = NC_ENOTVAR; goto done; } attrpp = NC_findattr(ncap, name); if(attrpp == NULL) - return NC_ENOTATT; + { status = NC_ENOTATT; goto done; } if(attnump != NULL) *attnump = (int)(attrpp - ncap->value); - return NC_NOERR; + status = NC_NOERR; + + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } int @@ -441,15 +462,30 @@ { int status; NC_attr *attrp; + NC *ncp; - status = NC_lookupattr(ncid, varid, name, &attrp); + /* for SXP */ + status = NC_check_id(ncid, &ncp); if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + + status = NC_lookupattr(ncid, varid, name, &attrp); + if(status != NC_NOERR) + goto done; + if(datatypep != NULL) *datatypep = attrp->type; - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } int @@ -457,15 +493,30 @@ { int status; NC_attr *attrp; + NC *ncp; - status = NC_lookupattr(ncid, varid, name, &attrp); + /* for SXP */ + status = NC_check_id(ncid, &ncp); if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + + status = NC_lookupattr(ncid, varid, name, &attrp); + if(status != NC_NOERR) + goto done; + if(lenp != NULL) *lenp = attrp->nelems; - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } int @@ -477,17 +528,32 @@ { int status; NC_attr *attrp; + NC *ncp; - status = NC_lookupattr(ncid, varid, name, &attrp); + /* for SXP */ + status = NC_check_id(ncid, &ncp); if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + + status = NC_lookupattr(ncid, varid, name, &attrp); + if(status != NC_NOERR) + goto done; + if(datatypep != NULL) *datatypep = attrp->type; if(lenp != NULL) *lenp = attrp->nelems; - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -506,43 +572,45 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(NC_readonly(ncp)) - return NC_EPERM; + { status = NC_EPERM; goto done; } ncap = NC_attrarray0(ncp, varid); if(ncap == NULL) - return NC_ENOTVAR; + { status = NC_ENOTVAR; goto done; } status = NC_check_name(newname); if(status != NC_NOERR) - return status; + goto done; /* return status; */ tmp = NC_findattr(ncap, name); if(tmp == NULL) - return NC_ENOTATT; + { status = NC_ENOTATT; goto done; } attrp = *tmp; /* end inline clone NC_lookupattr() */ if(NC_findattr(ncap, newname) != NULL) - { /* name in use */ - return NC_ENAMEINUSE; - } + { status = NC_ENAMEINUSE; goto done; } old = attrp->name; if(NC_indef(ncp)) { newStr = new_NC_string(strlen(newname), newname); if( newStr == NULL) - return NC_ENOMEM; + { status = NC_ENOMEM; goto done; } attrp->name = newStr; free_NC_string(old); - return NC_NOERR; + status = NC_NOERR; goto done; } /* else */ status = set_NC_string(old, newname); if( status != NC_NOERR) - return status; + goto done; set_NC_hdirty(ncp); @@ -550,10 +618,16 @@ { status = NC_sync(ncp); if(status != NC_NOERR) - return status; + goto done; } - return NC_NOERR; + status = NC_NOERR; + + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -576,12 +650,16 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(NC_readonly(ncp)) - return NC_EPERM; + { status = NC_EPERM; goto done; } ncap = NC_attrarray0(ncp, ovarid); if(ncap == NULL) - return NC_ENOTVAR; + { status = NC_ENOTVAR; goto done; } attrpp = NC_findattr(ncap, name); if(attrpp != NULL) /* name in use */ @@ -591,7 +669,7 @@ attrp = *attrpp; /* convenience */ if(iattrp->xsz > attrp->xsz) - return NC_ENOTINDEFINE; + { status = NC_ENOTINDEFINE; goto done; } /* else, we can reuse existing without redef */ attrp->xsz = iattrp->xsz; @@ -607,10 +685,10 @@ { status = NC_sync(ncp); if(status != NC_NOERR) - return status; + goto done; } - return NC_NOERR; + status = NC_NOERR; goto done; } /* else, redefine using existing array slot */ old = *attrpp; @@ -618,15 +696,15 @@ else { if(!NC_indef(ncp)) - return NC_ENOTINDEFINE; + { status = NC_ENOTINDEFINE; goto done; } if(ncap->nelems >= NC_MAX_ATTRS) - return NC_EMAXATTS; + { status = NC_EMAXATTS; goto done; } } attrp = new_NC_attr(name, iattrp->type, iattrp->nelems); if(attrp == NULL) - return NC_ENOMEM; + { status = NC_ENOMEM; goto done; } (void) memcpy(attrp->xvalue, iattrp->xvalue, iattrp->xsz); @@ -643,11 +721,17 @@ if(status != NC_NOERR) { free_NC_attr(attrp); - return status; + goto done; } } - return NC_NOERR; + status = NC_NOERR; + + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -666,12 +750,16 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(!NC_indef(ncp)) - return NC_ENOTINDEFINE; + { status = NC_ENOTINDEFINE; goto done; } ncap = NC_attrarray0(ncp, varid); if(ncap == NULL) - return NC_ENOTVAR; + { status = NC_ENOTVAR; goto done; } /* sortof inline NC_findattr() */ slen = strlen(name); @@ -687,7 +775,7 @@ } } if( (size_t) attrid == ncap->nelems ) - return NC_ENOTATT; + { status = NC_ENOTATT; goto done; } /* end inline NC_findattr() */ /* shuffle down */ @@ -702,7 +790,13 @@ free_NC_attr(old); - return NC_NOERR; + status = NC_NOERR; + + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } dnl @@ -796,23 +890,27 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_PUT_ATTR,nelems,NC_CHAR); +#endif + if(NC_readonly(ncp)) - return NC_EPERM; + { status = NC_EPERM; goto done; } ncap = NC_attrarray0(ncp, varid); if(ncap == NULL) - return NC_ENOTVAR; + { status = NC_ENOTVAR; goto done; } status = NC_check_name(name); if(status != NC_NOERR) - return status; + goto done; /* cast needed for braindead systems with signed size_t */ if((unsigned long) nelems > X_INT_MAX) /* backward compat */ - return NC_EINVAL; /* Invalid nelems */ + { status = NC_EINVAL; goto done; } /* Invalid nelems */ if(nelems != 0 && value == NULL) - return NC_EINVAL; /* Null arg */ + { status = NC_EINVAL; goto done; } /* Null arg */ attrpp = NC_findattr(ncap, name); if(attrpp != NULL) /* name in use */ @@ -823,7 +921,7 @@ attrp = *attrpp; /* convenience */ if(xsz > attrp->xsz) - return NC_ENOTINDEFINE; + { status = NC_ENOTINDEFINE; goto done; } /* else, we can reuse existing without redef */ attrp->xsz = xsz; @@ -835,7 +933,7 @@ void *xp = attrp->xvalue; status = ncx_pad_putn_text(&xp, nelems, value); if(status != NC_NOERR) - return status; + goto done; } set_NC_hdirty(ncp); @@ -844,10 +942,10 @@ { status = NC_sync(ncp); if(status != NC_NOERR) - return status; + goto done; } - return NC_NOERR; + status = NC_NOERR; goto done; } /* else, redefine using existing array slot */ old = *attrpp; @@ -855,22 +953,22 @@ else { if(!NC_indef(ncp)) - return NC_ENOTINDEFINE; + { status = NC_ENOTINDEFINE; goto done; } if(ncap->nelems >= NC_MAX_ATTRS) - return NC_EMAXATTS; + { status = NC_EMAXATTS; goto done; } } attrp = new_NC_attr(name, NC_CHAR, nelems); if(attrp == NULL) - return NC_ENOMEM; + { status = NC_ENOMEM; goto done; } if(nelems != 0) { void *xp = attrp->xvalue; status = ncx_pad_putn_text(&xp, nelems, value); if(status != NC_NOERR) - return status; + goto done; } if(attrpp != NULL) @@ -885,11 +983,17 @@ if(status != NC_NOERR) { free_NC_attr(attrp); - return status; + goto done; } } - return NC_NOERR; + status = NC_NOERR; + + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -898,22 +1002,42 @@ { int status; NC_attr *attrp; + NC *ncp; - status = NC_lookupattr(ncid, varid, name, &attrp); + /* for SXP */ + status = NC_check_id(ncid, &ncp); if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_GET_ATTR,0,NC_CHAR); +#endif + + status = NC_lookupattr(ncid, varid, name, &attrp); + if(status != NC_NOERR) + goto done; + +#if defined(USE_SXP) + SXP_ADD_ELEMS(ncp->nciop->sxp,attrp->nelems); +#endif + if(attrp->nelems == 0) - return NC_NOERR; + { status = NC_NOERR; goto done; } if(attrp->type != NC_CHAR) - return NC_ECHAR; + { status = NC_ECHAR; goto done; } /* else */ { const void *xp = attrp->xvalue; - return ncx_pad_getn_text(&xp, attrp->nelems, str); + status = ncx_pad_getn_text(&xp, attrp->nelems, str); + goto done; } + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -937,26 +1061,30 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_PUT_ATTR,nelems,type); +#endif + if(NC_readonly(ncp)) - return NC_EPERM; + { status = NC_EPERM; goto done; } ncap = NC_attrarray0(ncp, varid); if(ncap == NULL) - return NC_ENOTVAR; + { status = NC_ENOTVAR; goto done; } status = nc_cktype(type); if(status != NC_NOERR) - return status; + goto done; if(type == NC_CHAR) - return NC_ECHAR; + { status = NC_ECHAR; goto done; } /* cast needed for braindead systems with signed size_t */ if((unsigned long) nelems > X_INT_MAX) /* backward compat */ - return NC_EINVAL; /* Invalid nelems */ + { status = NC_EINVAL; goto done; } /* Invalid nelems */ if(nelems != 0 && value == NULL) - return NC_EINVAL; /* Null arg */ + { status = NC_EINVAL; goto done; } /* Null arg */ attrpp = NC_findattr(ncap, name); if(attrpp != NULL) /* name in use */ @@ -967,7 +1095,7 @@ attrp = *attrpp; /* convenience */ if(xsz > attrp->xsz) - return NC_ENOTINDEFINE; + { status = NC_ENOTINDEFINE; goto done; } /* else, we can reuse existing without redef */ attrp->xsz = xsz; @@ -977,8 +1105,14 @@ if(nelems != 0) { void *xp = attrp->xvalue; +#if defined(USE_SXP) + SXP_START_DC(ncp->nciop->sxp,nelems,type); +#endif status = ncx_pad_putn_I$1(&xp, nelems, value, type); +#if defined(USE_SXP) + SXP_STOP_DC(ncp->nciop->sxp); +#endif } set_NC_hdirty(ncp); @@ -991,10 +1125,10 @@ * set by ncx_pad_putn_I$1 */ if(lstatus != ENOERR) - return lstatus; + { status = lstatus; goto done; } } - return status; + goto done; /*return status;*/ } /* else, redefine using existing array slot */ old = *attrpp; @@ -1002,25 +1136,31 @@ else { if(!NC_indef(ncp)) - return NC_ENOTINDEFINE; + { status = NC_ENOTINDEFINE; goto done; } if(ncap->nelems >= NC_MAX_ATTRS) - return NC_EMAXATTS; + { status = NC_EMAXATTS; goto done; } } status = NC_check_name(name); if(status != NC_NOERR) - return status; + goto done; /* return status; */ attrp = new_NC_attr(name, type, nelems); if(attrp == NULL) - return NC_ENOMEM; + { status = NC_ENOMEM; goto done; } if(nelems != 0) { void *xp = attrp->xvalue; +#if defined(USE_SXP) + SXP_START_DC(ncp->nciop->sxp,nelems,type); +#endif status = ncx_pad_putn_I$1(&xp, nelems, value, type); +#if defined(USE_SXP) + SXP_STOP_DC(ncp->nciop->sxp); +#endif } if(attrpp != NULL) @@ -1039,10 +1179,14 @@ if(lstatus != NC_NOERR) { free_NC_attr(attrp); - return lstatus; + status = lstatus; goto done; } } + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif return status; } ')dnl @@ -1056,21 +1200,49 @@ { int status; NC_attr *attrp; + NC *ncp; - status = NC_lookupattr(ncid, varid, name, &attrp); + /* for SXP */ + status = NC_check_id(ncid, &ncp); if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_GET_ATTR,0,0); +#endif + + status = NC_lookupattr(ncid, varid, name, &attrp); + if(status != NC_NOERR) + goto done; + +#if defined(USE_SXP) + SXP_SET_TYPE(ncp->nciop->sxp,attrp->type); + SXP_ADD_ELEMS(ncp->nciop->sxp,attrp->nelems); +#endif + if(attrp->nelems == 0) - return NC_NOERR; + { status = NC_NOERR; goto done; } if(attrp->type == NC_CHAR) - return NC_ECHAR; + { status = NC_ECHAR; goto done; } + /* else */ { - const void *xp = attrp->xvalue; - return ncx_pad_getn_I$1(&xp, attrp->nelems, tp, attrp->type); + const void *xp = attrp->xvalue; +#if defined(USE_SXP) + SXP_START_DC(ncp->nciop->sxp,attrp->nelems,attrp->type); +#endif + status = ncx_pad_getn_I$1(&xp, attrp->nelems, tp, attrp->type); +#if defined(USE_SXP) + SXP_STOP_DC(ncp->nciop->sxp); +#endif + goto done; } + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } ')dnl Index: libsrc/dim.c =================================================================== --- libsrc/dim.c (.../trunk) (revision 531) +++ libsrc/dim.c (.../branches/fileinf_improvement) (revision 531) @@ -2,7 +2,7 @@ * Copyright 1996, University Corporation for Atmospheric Research * See netcdf/COPYRIGHT file for copying and redistribution conditions. */ -/* $Id: dim.c,v 1.74 2004/07/29 05:25:00 russ Exp $ */ +/* $Id: dim.c,v 1.73 1998/10/02 17:13:05 davis Exp $ */ #include "nc.h" #include @@ -10,7 +10,11 @@ #include #include "ncx.h" #include "fbits.h" +#if defined(USE_SXP) +# include "SXP.h" /* NEC SX Profiling */ +#endif + /* * Free dim * Formerly @@ -314,21 +318,25 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(!NC_indef(ncp)) - return NC_ENOTINDEFINE; + { status = NC_ENOTINDEFINE; goto done; } status = NC_check_name(name); if(status != NC_NOERR) - return status; + goto done; if ((ncp->flags & NC_64BIT_OFFSET) && sizeof(off_t) > 4) { /* CDF2 format and LFS */ if(size > X_UINT_MAX - 3) /* "- 3" handles rounded-up size */ - return NC_EDIMSIZE; + { status = NC_EDIMSIZE; goto done; } } else { /* CDF1 format */ if(size > X_INT_MAX - 3) - return NC_EDIMSIZE; + { status = NC_EDIMSIZE; goto done; } } if(size == NC_UNLIMITED) @@ -337,30 +345,36 @@ if(dimid != -1) { assert(dimid != -1); - return NC_EUNLIMIT; + status = NC_EUNLIMIT; goto done; } } if(ncp->dims.nelems >= NC_MAX_DIMS) - return NC_EMAXDIMS; + { status = NC_EMAXDIMS; goto done; } dimid = NC_finddim(&ncp->dims, name, &dimp); if(dimid != -1) - return NC_ENAMEINUSE; + { status = NC_ENAMEINUSE; goto done; } dimp = new_NC_dim(name, size); if(dimp == NULL) - return NC_ENOMEM; + { status = NC_ENOMEM; goto done; } status = incr_NC_dimarray(&ncp->dims, dimp); if(status != NC_NOERR) { free_NC_dim(dimp); - return status; + goto done;; } if(dimidp != NULL) *dimidp = (int)ncp->dims.nelems -1; - return NC_NOERR; + + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -375,13 +389,22 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + dimid = NC_finddim(&ncp->dims, name, NULL); if(dimid == -1) - return NC_EBADDIM; + { status = NC_EBADDIM; goto done; } *dimid_ptr = dimid; - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -396,9 +419,13 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + dimp = elem_NC_dimarray(&ncp->dims, (size_t)dimid); if(dimp == NULL) - return NC_EBADDIM; + { status = NC_EBADDIM; goto done; } if(name != NULL) { @@ -413,7 +440,12 @@ else *sizep = dimp->size; } - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -428,9 +460,13 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + dimp = elem_NC_dimarray(&ncp->dims, (size_t)dimid); if(dimp == NULL) - return NC_EBADDIM; + { status = NC_EBADDIM; goto done; } if(name != NULL) { @@ -439,7 +475,12 @@ name[dimp->name->nchars] = 0; } - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -454,9 +495,13 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + dimp = elem_NC_dimarray(&ncp->dims, (size_t)dimid); if(dimp == NULL) - return NC_EBADDIM; + { status = NC_EBADDIM; goto done; } if(lenp != 0) { @@ -465,7 +510,12 @@ else *lenp = dimp->size; } - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -481,37 +531,41 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(NC_readonly(ncp)) - return NC_EPERM; + { status = NC_EPERM; goto done; } status = NC_check_name(newname); if(status != NC_NOERR) - return status; + goto done; existid = NC_finddim(&ncp->dims, newname, &dimp); if(existid != -1) - return NC_ENAMEINUSE; + { status = NC_ENAMEINUSE; goto done; } dimp = elem_NC_dimarray(&ncp->dims, (size_t)dimid); if(dimp == NULL) - return NC_EBADDIM; + { status = NC_EBADDIM; goto done; } if(NC_indef(ncp)) { NC_string *old = dimp->name; NC_string *newStr = new_NC_string(strlen(newname), newname); if(newStr == NULL) - return NC_ENOMEM; + { status = NC_ENOMEM; goto done; } dimp->name = newStr; free_NC_string(old); - return NC_NOERR; + status = NC_NOERR; goto done; } /* else, not in define mode */ status = set_NC_string(dimp->name, newname); if(status != NC_NOERR) - return status; + goto done; set_NC_hdirty(ncp); @@ -519,8 +573,13 @@ { status = NC_sync(ncp); if(status != NC_NOERR) - return status; + goto done; } - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } Index: libsrc/var.c =================================================================== --- libsrc/var.c (.../trunk) (revision 531) +++ libsrc/var.c (.../branches/fileinf_improvement) (revision 531) @@ -10,6 +10,9 @@ #include #include "ncx.h" #include "rnd.h" +#if defined(USE_SXP) +# include "SXP.h" /* NEC SX Profiling */ +#endif /* @@ -498,57 +501,59 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(!NC_indef(ncp)) - { - return NC_ENOTINDEFINE; - } + { status = NC_ENOTINDEFINE; goto done; } status = NC_check_name(name); if(status != NC_NOERR) - return status; + goto done; status = nc_cktype(type); if(status != NC_NOERR) - return status; + goto done; /* cast needed for braindead systems with signed size_t */ if((unsigned long) ndims > X_INT_MAX) /* Backward compat */ - { - return NC_EINVAL; - } + { status = NC_EINVAL; goto done; } if(ncp->vars.nelems >= NC_MAX_VARS) - { - return NC_EMAXVARS; - } + { status = NC_EMAXVARS; goto done; } varid = NC_findvar(&ncp->vars, name, &varp); if(varid != -1) - { - return NC_ENAMEINUSE; - } + { status = NC_ENAMEINUSE; goto done; } varp = new_NC_var(name, type, ndims, dimids); if(varp == NULL) - return NC_ENOMEM; + { status = NC_ENOMEM; goto done; } status = NC_var_shape(varp, &ncp->dims); if(status != NC_NOERR) { free_NC_var(varp); - return status; + goto done; } status = incr_NC_vararray(&ncp->vars, varp); if(status != NC_NOERR) { free_NC_var(varp); - return status; + goto done; } if(varidp != NULL) *varidp = (int)ncp->vars.nelems -1; /* varid */ - return NC_NOERR; + status = NC_NOERR; + + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -564,14 +569,22 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + varid = NC_findvar(&ncp->vars, name, &varp); if(varid == -1) - { - return NC_ENOTVAR; - } + { status = NC_ENOTVAR; goto done; } *varid_ptr = varid; - return NC_NOERR; + status = NC_NOERR; + + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -593,9 +606,13 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + varp = elem_NC_vararray(&ncp->vars, (size_t)varid); if(varp == NULL) - return NC_ENOTVAR; + { status = NC_ENOTVAR; goto done; } if(name != NULL) { @@ -621,7 +638,12 @@ *nattsp = (int) varp->attrs.nelems; } - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -636,9 +658,13 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + varp = elem_NC_vararray(&ncp->vars, (size_t)varid); if(varp == NULL) - return NC_ENOTVAR; + { status = NC_ENOTVAR; goto done; } if(name != NULL) { @@ -646,7 +672,12 @@ name[varp->name->nchars] = 0; } - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } int @@ -660,14 +691,23 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + varp = elem_NC_vararray(&ncp->vars, (size_t)varid); if(varp == NULL) - return NC_ENOTVAR; + { status = NC_ENOTVAR; goto done; } if(typep != 0) *typep = varp->type; - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } int @@ -681,16 +721,26 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + varp = elem_NC_vararray(&ncp->vars, (size_t)varid); if(varp == NULL) - return NC_ENOTVAR; /* TODO: is this the right error code? */ + /* TODO: is this the right error code? */ + { status = NC_ENOTVAR; goto done; } if(ndimsp != 0) { *ndimsp = (int) varp->ndims; } - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -706,9 +756,14 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + varp = elem_NC_vararray(&ncp->vars, (size_t)varid); if(varp == NULL) - return NC_ENOTVAR; /* TODO: is this the right error code? */ + /* TODO: is this the right error code? */ + { status = NC_ENOTVAR; goto done; } if(dimids != 0) { @@ -718,7 +773,12 @@ } } - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } @@ -736,16 +796,26 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + varp = elem_NC_vararray(&ncp->vars, (size_t)varid); if(varp == NULL) - return NC_ENOTVAR; /* TODO: is this the right error code? */ + /* TODO: is this the right error code? */ + { status = NC_ENOTVAR; goto done; } if(nattsp != 0) { *nattsp = (int) varp->attrs.nelems; } - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } int @@ -761,44 +831,43 @@ if(status != NC_NOERR) return status; +#if defined(USE_SXP) + SXP_START_OP(ncp->nciop->sxp,SXP_INFO,0,0); +#endif + if(NC_readonly(ncp)) - { - return NC_EPERM; - } + { status = NC_EPERM; goto done; } status = NC_check_name(newname); if(status != NC_NOERR) - return status; + goto done; /* check for name in use */ other = NC_findvar(&ncp->vars, newname, &varp); if(other != -1) - { - return NC_ENAMEINUSE; - } + { status = NC_ENAMEINUSE; goto done; } varp = NC_lookupvar(ncp, varid); if(varp == NULL) - { /* invalid varid */ - return NC_ENOTVAR; /* TODO: is this the right error code? */ - } + /* TODO: is this the right error code? */ + { status = NC_ENOTVAR; goto done; } old = varp->name; if(NC_indef(ncp)) { newStr = new_NC_string(strlen(newname),newname); if(newStr == NULL) - return(-1); + { status = -1; goto done; } varp->name = newStr; free_NC_string(old); - return NC_NOERR; + status = NC_NOERR; goto done; } /* else, not in define mode */ status = set_NC_string(varp->name, newname); if(status != NC_NOERR) - return status; + goto done; set_NC_hdirty(ncp); @@ -806,8 +875,13 @@ { status = NC_sync(ncp); if(status != NC_NOERR) - return status; + goto done; } - return NC_NOERR; + status = NC_NOERR; + done: +#if defined(USE_SXP) + SXP_STOP_OP(ncp->nciop->sxp); +#endif + return status; } Index: libsrc/posixio.c =================================================================== --- libsrc/posixio.c (.../trunk) (revision 531) +++ libsrc/posixio.c (.../branches/fileinf_improvement) (revision 531) @@ -21,6 +21,10 @@ #include #endif +#if defined(USE_SXP) +#include "SXP.h" /* for profiling */ +#endif + #ifndef SEEK_SET #define SEEK_SET 0 #define SEEK_CUR 1 @@ -184,27 +188,40 @@ off_t const offset, const size_t extent, void *const vp, off_t *posp) { + int status; + ssize_t nwrit=0; #ifdef X_ALIGN assert(offset % X_ALIGN == 0); #endif - +#if defined(USE_SXP) + SXP_START_FLUSH(nciop->sxp); +#endif assert(*posp == OFF_NONE || *posp == lseek(nciop->fd, 0, SEEK_CUR)); if(*posp != offset) { if(lseek(nciop->fd, offset, SEEK_SET) != offset) { - return errno; + status = errno; + goto done; } *posp = offset; } - if(write(nciop->fd, vp, extent) != (ssize_t) extent) + nwrit=write(nciop->fd, vp, extent); + if(nwrit != (ssize_t) extent) { - return errno; + nwrit=0; + status = errno; + goto done; } *posp += extent; - return ENOERR; + status = ENOERR; + done: +#if defined(USE_SXP) + SXP_STOP_FLUSH(nciop->sxp, nwrit); +#endif + return status; } /* Read in a page of data. @@ -222,12 +239,15 @@ void *const vp, size_t *nreadp, off_t *posp) { int status; - ssize_t nread; + ssize_t nread=0; #ifdef X_ALIGN assert(offset % X_ALIGN == 0); assert(extent % X_ALIGN == 0); #endif +#if defined(USE_SXP) + SXP_START_FILL(nciop->sxp); +#endif assert(*posp == OFF_NONE || *posp == lseek(nciop->fd, 0, SEEK_CUR)); @@ -236,7 +256,7 @@ if(lseek(nciop->fd, offset, SEEK_SET) != offset) { status = errno; - return status; + goto done; /* return status; */ } *posp = offset; } @@ -246,15 +266,22 @@ if(nread != (ssize_t) extent) { status = errno; - if(nread == -1 || status != ENOERR) - return status; + if(nread == -1 || status != ENOERR) { + nread=0; + goto done; /* return status; */ + } /* else it's okay we read less than asked for */ (void) memset((char *)vp + nread, 0, (ssize_t)extent - nread); } *nreadp = nread; *posp += nread; - return ENOERR; + status = ENOERR; + done: +#if defined(USE_SXP) + SXP_STOP_FILL(nciop->sxp,nread); +#endif + return status; } /* This struct is for POSIX systems, with NC_SHARE not in effect. If @@ -1436,6 +1463,10 @@ if(nciop == NULL) return ENOMEM; +#if defined(USE_SXP) + SXP_INIT(&nciop->sxp,path); +#endif + if(fIsSet(ioflags, NC_NOCLOBBER)) fSet(oflags, O_EXCL); else @@ -1469,6 +1500,9 @@ { *sizehintp = M_RNDUP(*sizehintp); } +#if defined(USE_SXP) + SXP_SET_INFO(nciop->sxp,fd,*sizehintp); +#endif if(fIsSet(nciop->ioflags, NC_SHARE)) status = ncio_spx_init2(nciop, sizehintp); @@ -1503,6 +1537,9 @@ /* ?? unlink */ /*FALLTHRU*/ unwind_new: +#if defined(USE_SXP) + SXP_FINALISE(nciop->sxp,0); +#endif ncio_free(nciop); return status; } @@ -1569,6 +1606,10 @@ if(nciop == NULL) return ENOMEM; +#if defined(USE_SXP) + SXP_INIT(&nciop->sxp,path); +#endif + #ifdef O_BINARY fSet(oflags, O_BINARY); #endif @@ -1593,6 +1634,9 @@ { *sizehintp = M_RNDUP(*sizehintp); } +#if defined(USE_SXP) + SXP_SET_INFO(nciop->sxp,fd,*sizehintp); +#endif if(fIsSet(nciop->ioflags, NC_SHARE)) status = ncio_spx_init2(nciop, sizehintp); @@ -1619,6 +1663,9 @@ (void) close(fd); /*FALLTHRU*/ unwind_new: +#if defined(USE_SXP) + SXP_FINALISE(nciop->sxp,0); +#endif ncio_free(nciop); return status; } @@ -1692,6 +1739,9 @@ if(doUnlink) (void) unlink(nciop->path); +#if defined(USE_SXP) + SXP_FINALISE(nciop->sxp,1); +#endif ncio_free(nciop); return status;