12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358 |
- /*! \file
- Functions for writing data to variables.
- Copyright 2010 University Corporation for Atmospheric
- Research/Unidata. See COPYRIGHT file for more info.
- */
- #include "ncdispatch.h"
- /** \internal
- \ingroup variables
- */
- static int
- NC_put_vara(int ncid, int varid, const size_t *start,
- const size_t *edges, const void *value, nc_type memtype)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- if(edges == NULL) {
- size_t shape[NC_MAX_VAR_DIMS];
- int ndims;
- stat = nc_inq_varndims(ncid, varid, &ndims);
- if(stat != NC_NOERR) return stat;
- stat = NC_getshape(ncid, varid, ndims, shape);
- if(stat != NC_NOERR) return stat;
- return ncp->dispatch->put_vara(ncid, varid, start, shape, value, memtype);
- } else
- return ncp->dispatch->put_vara(ncid, varid, start, edges, value, memtype);
- }
- /** \internal
- \ingroup variables
- */
- static int
- NC_put_var(int ncid, int varid, const void *value, nc_type memtype)
- {
- int ndims;
- size_t shape[NC_MAX_VAR_DIMS];
- int stat = nc_inq_varndims(ncid,varid, &ndims);
- if(stat) return stat;
- stat = NC_getshape(ncid,varid, ndims, shape);
- if(stat) return stat;
- return NC_put_vara(ncid, varid, NC_coord_zero, shape, value, memtype);
- }
- /** \internal
- \ingroup variables
- */
- static int
- NC_put_var1(int ncid, int varid, const size_t *coord, const void* value,
- nc_type memtype)
- {
- return NC_put_vara(ncid, varid, coord, NC_coord_one, value, memtype);
- }
- /** \internal
- \ingroup variables
- */
- int
- NCDEFAULT_put_vars(int ncid, int varid, const size_t * start,
- const size_t * edges, const ptrdiff_t * stride,
- const void *value, nc_type memtype)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return ncp->dispatch->put_varm(ncid,varid,start,edges,stride,NULL,value,memtype);
- }
- /** \internal
- \ingroup variables
- */
- int
- NCDEFAULT_put_varm(
- int ncid,
- int varid,
- const size_t * start,
- const size_t * edges,
- const ptrdiff_t * stride,
- const ptrdiff_t * imapp,
- const void *value0,
- nc_type memtype)
- {
- int status = NC_NOERR;
- nc_type vartype = NC_NAT;
- int varndims = 0;
- int maxidim = 0;
- NC* ncp;
- size_t memtypelen;
- ptrdiff_t cvtmap[NC_MAX_VAR_DIMS];
- const char* value = (char*)value0;
- 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;
- */
- /* mid body */
- status = nc_inq_vartype(ncid, varid, &vartype);
- if(status != NC_NOERR) return status;
- /* Check that this is an atomic type */
- if(vartype >= NC_MAX_ATOMIC_TYPE)
- return NC_EMAPTYPE;
- status = nc_inq_varndims(ncid, varid, &varndims);
- if(status != NC_NOERR) return status;
- if(memtype == NC_NAT) {
- if(imapp != NULL && varndims != 0) {
- /*
- * convert map units from bytes to units of sizeof(type)
- */
- size_t ii;
- const ptrdiff_t szof = (ptrdiff_t) nctypelen(vartype);
- for(ii = 0; ii < varndims; ii++) {
- if(imapp[ii] % szof != 0) {
- /*free(cvtmap);*/
- return NC_EINVAL;
- }
- cvtmap[ii] = imapp[ii] / szof;
- }
- imapp = cvtmap;
- }
- memtype = vartype;
- }
- if(memtype == NC_CHAR && vartype != NC_CHAR)
- return NC_ECHAR;
- else if(memtype != NC_CHAR && vartype == NC_CHAR)
- return NC_ECHAR;
- memtypelen = nctypelen(memtype);
- maxidim = (int) varndims - 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?)
- */
- size_t edge1[1] = {1};
- return NC_put_vara(ncid, varid, start, edge1, value, memtype);
- }
- /*
- * 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;
- size_t varshape[NC_MAX_VAR_DIMS];
- int isrecvar;
- size_t numrecs;
- int stride1; /* is stride all ones? */
- /*
- * Verify stride argument.
- */
- stride1 = 1; /* assume ok; */
- if(stride != NULL) {
- for (idim = 0; idim <= maxidim; ++idim) {
- if ((stride[idim] == 0)
- /* cast needed for braindead systems with signed size_t */
- || ((unsigned long) stride[idim] >= X_INT_MAX))
- {
- return NC_ESTRIDE;
- }
- if(stride[idim] != 1) stride1 = 0;
- }
- }
- /* If stride1 is true, and there is no imap, then call get_vara
- directly
- */
- if(stride1 && imapp == NULL) {
- return NC_put_vara(ncid, varid, start, edges, value, memtype);
- }
- /* Compute some dimension related values */
- isrecvar = NC_is_recvar(ncid,varid,&numrecs);
- NC_getshape(ncid,varid,varndims,varshape);
- /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */
- mystart = (size_t *)calloc(varndims * 7, sizeof(ptrdiff_t));
- if(mystart == NULL) return NC_ENOMEM;
- myedges = mystart + varndims;
- iocount = myedges + varndims;
- stop = iocount + varndims;
- length = stop + varndims;
- mystride = (ptrdiff_t *)(length + varndims);
- mymap = mystride + varndims;
- /*
- * Initialize I/O parameters.
- */
- for (idim = maxidim; idim >= 0; --idim)
- {
- mystart[idim] = start != NULL
- ? start[idim]
- : 0;
- if (edges != NULL && edges[idim] == 0)
- {
- status = NC_NOERR; /* read/write no data */
- goto done;
- }
- myedges[idim] = edges != NULL
- ? edges[idim]
- : idim == 0 && isrecvar
- ? numrecs - mystart[idim]
- : varshape[idim] - mystart[idim];
- mystride[idim] = stride != NULL
- ? stride[idim]
- : 1;
- mymap[idim] = imapp != NULL
- ? imapp[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 = isrecvar; idim < maxidim; ++idim)
- {
- if (mystart[idim] > varshape[idim])
- {
- status = NC_EINVALCOORDS;
- goto done;
- }
- if (mystart[idim] + myedges[idim] > varshape[idim])
- {
- status = NC_EEDGE;
- goto done;
- }
- }
- /* Lower body */
- /*
- * 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_put_vara(ncid, varid, mystart, iocount,
- value, memtype);
- if (lstatus != NC_NOERR) {
- if(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] * memtypelen);
- mystart[idim] += mystride[idim];
- if (mystart[idim] == stop[idim])
- {
- mystart[idim] = start[idim];
- value -= (length[idim] * memtypelen);
- if (--idim < 0)
- break; /* normal return */
- goto carry;
- }
- } /* I/O loop */
- done:
- free(mystart);
- } /* variable is array */
- return status;
- }
- /** \internal
- \ingroup variables
- */
- static int
- NC_put_vars(int ncid, int varid, const size_t *start,
- const size_t *edges, const ptrdiff_t *stride,
- const void *value, nc_type memtype)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- #ifdef USE_NETCDF4
- if(memtype >= NC_FIRSTUSERTYPEID) memtype = NC_NAT;
- #endif
- return ncp->dispatch->put_vars(ncid,varid,start,edges,stride,value,memtype);
- }
- /** \internal
- \ingroup variables
- */
- static 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, nc_type memtype)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- #ifdef USE_NETCDF4
- if(memtype >= NC_FIRSTUSERTYPEID) memtype = NC_NAT;
- #endif
- return ncp->dispatch->put_varm(ncid,varid,start,edges,stride,map,value,memtype);
- }
- /** \name Writing Data to Variables
- Functions to write data from variables. */
- /*! \{ */ /* All these functions are part of this named group... */
- /** \ingroup variables
- Write an array of values to a variable.
- The values to be written are associated with the netCDF variable by
- assuming that the last dimension of the netCDF variable varies fastest
- in the C interface. The netCDF dataset must be in data mode. The array
- to be written is specified by giving a corner and a vector of edge
- lengths to \ref specify_hyperslab.
- The functions for types ubyte, ushort, uint, longlong, ulonglong, and
- string are only available for netCDF-4/HDF5 files.
- The nc_put_var() function will write a variable of any type, including
- user defined type. For this function, the type of the data in memory
- must match the type of the variable - no data conversion is done.
- \param ncid NetCDF or group ID, from a previous call to nc_open(),
- nc_create(), nc_def_grp(), or associated inquiry functions such as
- nc_inq_ncid().
- \param varid Variable ID
- \param startp Start vector with one element for each dimension to \ref
- specify_hyperslab.
- \param countp Count vector with one element for each dimension to \ref
- specify_hyperslab.
- \param op Pointer where the data will be copied. Memory must be
- allocated by the user before this function is called.
- \returns ::NC_NOERR No error.
- \returns ::NC_ENOTVAR Variable not found.
- \returns ::NC_EINVALCOORDS Index exceeds dimension bound.
- \returns ::NC_EEDGE Start+count exceeds dimension bound.
- \returns ::NC_ERANGE One or more of the values are out of range.
- \returns ::NC_EINDEFINE Operation not allowed in define mode.
- \returns ::NC_EBADID Bad ncid.
- */
- /**@{*/
- int
- nc_put_vara(int ncid, int varid, const size_t *startp,
- const size_t *countp, const void *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- nc_type xtype;
- if(stat != NC_NOERR) return stat;
- stat = nc_inq_vartype(ncid, varid, &xtype);
- if(stat != NC_NOERR) return stat;
- return NC_put_vara(ncid, varid, startp, countp, op, xtype);
- }
- int
- nc_put_vara_text(int ncid, int varid, const size_t *startp,
- const size_t *countp, const char *op)
- {
- return NC_put_vara(ncid, varid, startp, countp,
- (void*)op, NC_CHAR);
- }
- int
- nc_put_vara_schar(int ncid, int varid, const size_t *startp,
- const size_t *countp, const signed char *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vara(ncid, varid, startp, countp, (void *)op,
- NC_BYTE);
- }
- int
- nc_put_vara_uchar(int ncid, int varid, const size_t *startp,
- const size_t *countp, const unsigned char *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vara(ncid, varid, startp, countp, (void *)op,
- T_uchar);
- }
- int
- nc_put_vara_short(int ncid, int varid, const size_t *startp,
- const size_t *countp, const short *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vara(ncid, varid, startp, countp, (void *)op,
- NC_SHORT);
- }
- int
- nc_put_vara_int(int ncid, int varid, const size_t *startp,
- const size_t *countp, const int *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vara(ncid, varid, startp, countp, (void *)op,
- NC_INT);
- }
- int
- nc_put_vara_long(int ncid, int varid, const size_t *startp,
- const size_t *countp, const long *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vara(ncid, varid, startp, countp, (void *)op,
- T_long);
- }
- int
- nc_put_vara_float(int ncid, int varid, const size_t *startp,
- const size_t *countp, const float *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vara(ncid, varid, startp, countp, (void *)op,
- T_float);
- }
- int
- nc_put_vara_double(int ncid, int varid, const size_t *startp,
- const size_t *countp, const double *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vara(ncid, varid, startp, countp, (void *)op,
- T_double);
- }
- int
- nc_put_vara_ubyte(int ncid, int varid, const size_t *startp,
- const size_t *countp, const unsigned char *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vara(ncid, varid, startp, countp, (void *)op,
- T_ubyte);
- }
- int
- nc_put_vara_ushort(int ncid, int varid, const size_t *startp,
- const size_t *countp, const unsigned short *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vara(ncid, varid, startp, countp, (void *)op,
- T_ushort);
- }
- int
- nc_put_vara_uint(int ncid, int varid, const size_t *startp,
- const size_t *countp, const unsigned int *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vara(ncid, varid, startp, countp, (void *)op,
- T_uint);
- }
- int
- nc_put_vara_longlong(int ncid, int varid, const size_t *startp,
- const size_t *countp, const long long *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vara(ncid, varid, startp, countp, (void *)op,
- T_longlong);
- }
- int
- nc_put_vara_ulonglong(int ncid, int varid, const size_t *startp,
- const size_t *countp, const unsigned long long *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vara(ncid, varid, startp, countp, (void *)op,
- NC_UINT64);
- }
- #ifdef USE_NETCDF4
- int
- nc_put_vara_string(int ncid, int varid, const size_t *startp,
- const size_t *countp, const char* *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vara(ncid, varid, startp, countp, (void *)op,
- NC_STRING);
- }
- #endif /*USE_NETCDF4*/
- /**@}*/
- /** \ingroup variables
- Write one datum.
- \param ncid NetCDF or group ID, from a previous call to nc_open(),
- nc_create(), nc_def_grp(), or associated inquiry functions such as
- nc_inq_ncid().
- \param varid Variable ID
- \param indexp Index vector with one element for each dimension.
- \param op Pointer from where the data will be copied.
- \returns ::NC_NOERR No error.
- \returns ::NC_ENOTVAR Variable not found.
- \returns ::NC_EINVALCOORDS Index exceeds dimension bound.
- \returns ::NC_EEDGE Start+count exceeds dimension bound.
- \returns ::NC_ERANGE One or more of the values are out of range.
- \returns ::NC_EINDEFINE Operation not allowed in define mode.
- \returns ::NC_EBADID Bad ncid.
- */
- /**@{*/
- int
- nc_put_var1(int ncid, int varid, const size_t *indexp, const void *op)
- {
- return NC_put_var1(ncid, varid, indexp, op, NC_NAT);
- }
- int
- nc_put_var1_text(int ncid, int varid, const size_t *indexp, const char *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var1(ncid, varid, indexp, (void *)op, NC_CHAR);
- }
- int
- nc_put_var1_schar(int ncid, int varid, const size_t *indexp, const signed char *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var1(ncid, varid, indexp, (void *)op, NC_BYTE);
- }
- int
- nc_put_var1_uchar(int ncid, int varid, const size_t *indexp, const unsigned char *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var1(ncid, varid, indexp, (void *)op, NC_UBYTE);
- }
- int
- nc_put_var1_short(int ncid, int varid, const size_t *indexp, const short *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var1(ncid, varid, indexp, (void *)op, NC_SHORT);
- }
- int
- nc_put_var1_int(int ncid, int varid, const size_t *indexp, const int *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var1(ncid, varid, indexp, (void *)op, NC_INT);
- }
- int
- nc_put_var1_long(int ncid, int varid, const size_t *indexp, const long *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var1(ncid, varid, indexp, (void*)op, longtype);
- }
- int
- nc_put_var1_float(int ncid, int varid, const size_t *indexp, const float *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var1(ncid, varid, indexp, (void*)op, NC_FLOAT);
- }
- int
- nc_put_var1_double(int ncid, int varid, const size_t *indexp, const double *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var1(ncid, varid, indexp, (void *)op, NC_DOUBLE);
- }
- int
- nc_put_var1_ubyte(int ncid, int varid, const size_t *indexp, const unsigned char *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var1(ncid, varid, indexp, (void *)op, NC_UBYTE);
- }
- int
- nc_put_var1_ushort(int ncid, int varid, const size_t *indexp, const unsigned short *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var1(ncid, varid, indexp, (void *)op, NC_USHORT);
- }
- int
- nc_put_var1_uint(int ncid, int varid, const size_t *indexp, const unsigned int *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var1(ncid, varid, indexp, (void *)op, NC_UINT);
- }
- int
- nc_put_var1_longlong(int ncid, int varid, const size_t *indexp, const long long *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var1(ncid, varid, indexp, (void *)op, NC_INT64);
- }
- int
- nc_put_var1_ulonglong(int ncid, int varid, const size_t *indexp, const unsigned long long *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var1(ncid, varid, indexp, (void *)op, NC_UINT64);
- }
- #ifdef USE_NETCDF4
- int
- nc_put_var1_string(int ncid, int varid, const size_t *indexp, const char* *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var1(ncid, varid, indexp, (void*)op, NC_STRING);
- }
- #endif /*USE_NETCDF4*/
- /**@}*/
- /** \ingroup variables
- Write an entire variable with one call.
- The nc_put_var_ type family of functions write all the values of a
- variable into a netCDF variable of an open netCDF dataset. This is the
- simplest interface to use for writing a value in a scalar variable or
- whenever all the values of a multidimensional variable can all be
- written at once. The values to be written are associated with the
- netCDF variable by assuming that the last dimension of the netCDF
- variable varies fastest in the C interface. The values are converted
- to the external data type of the variable, if necessary.
- Take care when using this function with record variables (variables
- that use the ::NC_UNLIMITED dimension). If you try to write all the
- values of a record variable into a netCDF file that has no record data
- yet (hence has 0 records), nothing will be written. Similarly, if you
- try to write all the values of a record variable but there are more
- records in the file than you assume, more in-memory data will be
- accessed than you supply, which may result in a segmentation
- violation. To avoid such problems, it is better to use the nc_put_vara
- interfaces for variables that use the ::NC_UNLIMITED dimension.
- The functions for types ubyte, ushort, uint, longlong, ulonglong, and
- string are only available for netCDF-4/HDF5 files.
- The nc_put_var() function will write a variable of any type, including
- user defined type. For this function, the type of the data in memory
- must match the type of the variable - no data conversion is done.
- \param ncid NetCDF or group ID, from a previous call to nc_open(),
- nc_create(), nc_def_grp(), or associated inquiry functions such as
- nc_inq_ncid().
- \param varid Variable ID
- \param op Pointer from where the data will be copied.
- \returns ::NC_NOERR No error.
- \returns ::NC_ENOTVAR Variable not found.
- \returns ::NC_EINVALCOORDS Index exceeds dimension bound.
- \returns ::NC_EEDGE Start+count exceeds dimension bound.
- \returns ::NC_ERANGE One or more of the values are out of range.
- \returns ::NC_EINDEFINE Operation not allowed in define mode.
- \returns ::NC_EBADID Bad ncid.
- */
- /**@{*/
- int
- nc_put_var(int ncid, int varid, const void *op)
- {
- return NC_put_var(ncid, varid, op, NC_NAT);
- }
- int
- nc_put_var_text(int ncid, int varid, const char *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var(ncid,varid,(void*)op,NC_CHAR);
- }
- int
- nc_put_var_schar(int ncid, int varid, const signed char *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var(ncid,varid,(void*)op,NC_BYTE);
- }
- int
- nc_put_var_uchar(int ncid, int varid, const unsigned char *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var(ncid,varid,(void*)op,T_uchar);
- }
- int
- nc_put_var_short(int ncid, int varid, const short *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var(ncid,varid,(void*)op,NC_SHORT);
- }
- int
- nc_put_var_int(int ncid, int varid, const int *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var(ncid,varid,(void*)op,NC_INT);
- }
- int
- nc_put_var_long(int ncid, int varid, const long *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var(ncid,varid,(void*)op,T_long);
- }
- int
- nc_put_var_float(int ncid, int varid, const float *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var(ncid,varid,(void*)op,T_float);
- }
- int
- nc_put_var_double(int ncid, int varid, const double *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var(ncid,varid,(void*)op,T_double);
- }
- int
- nc_put_var_ubyte(int ncid, int varid, const unsigned char *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var(ncid,varid,(void*)op,T_ubyte);
- }
- int
- nc_put_var_ushort(int ncid, int varid, const unsigned short *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var(ncid,varid,(void*)op,T_ushort);
- }
- int
- nc_put_var_uint(int ncid, int varid, const unsigned int *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var(ncid,varid,(void*)op,T_uint);
- }
- int
- nc_put_var_longlong(int ncid, int varid, const long long *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var(ncid,varid,(void*)op,T_longlong);
- }
- int
- nc_put_var_ulonglong(int ncid, int varid, const unsigned long long *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var(ncid,varid,(void*)op,NC_UINT64);
- }
- #ifdef USE_NETCDF4
- int
- nc_put_var_string(int ncid, int varid, const char* *op)
- {
- NC* ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_var(ncid,varid,(void*)op,NC_STRING);
- }
- #endif /*USE_NETCDF4*/
- /**\} */
- /** \ingroup variables
- Write a strided array of values to a variable.
- \param ncid NetCDF or group ID, from a previous call to nc_open(),
- nc_create(), nc_def_grp(), or associated inquiry functions such as
- nc_inq_ncid().
- \param varid Variable ID
- \param startp Start vector with one element for each dimension to \ref
- specify_hyperslab.
- \param countp Count vector with one element for each dimension to \ref
- specify_hyperslab.
- \param stridep Stride vector with one element for each dimension to
- \ref specify_hyperslab.
- \param op Pointer where the data will be copied. Memory must be
- allocated by the user before this function is called.
- \returns ::NC_NOERR No error.
- \returns ::NC_ENOTVAR Variable not found.
- \returns ::NC_EINVALCOORDS Index exceeds dimension bound.
- \returns ::NC_EEDGE Start+count exceeds dimension bound.
- \returns ::NC_ERANGE One or more of the values are out of range.
- \returns ::NC_EINDEFINE Operation not allowed in define mode.
- \returns ::NC_EBADID Bad ncid.
- */
- /**@{*/
- int
- nc_put_vars (int ncid, int varid, const size_t *startp,
- const size_t *countp, const ptrdiff_t *stridep,
- const void *op)
- {
- NC *ncp;
- int stat = NC_NOERR;
- if ((stat = NC_check_id(ncid, &ncp)))
- return stat;
- return ncp->dispatch->put_vars(ncid, varid, startp, countp,
- stridep, op, NC_NAT);
- }
- int
- nc_put_vars_text(int ncid, int varid, const size_t *startp,
- const size_t *countp, const ptrdiff_t *stridep,
- const char *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vars(ncid, varid, startp, countp,
- stridep,(void*)op,NC_CHAR);
- }
- int
- nc_put_vars_schar(int ncid, int varid, const size_t *startp,
- const size_t *countp, const ptrdiff_t *stridep,
- const signed char *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vars(ncid, varid, startp, countp,
- stridep,(void*)op,NC_BYTE);
- }
- int
- nc_put_vars_uchar(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep,
- const unsigned char *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vars(ncid, varid, startp, countp,
- stridep, (void *)op, T_uchar);
- }
- int
- nc_put_vars_short(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep,
- const short *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vars(ncid, varid, startp, countp,
- stridep, (void *)op, NC_SHORT);
- }
- int
- nc_put_vars_int(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep,
- const int *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vars(ncid, varid, startp, countp,
- stridep, (void *)op, NC_INT);
- }
- int
- nc_put_vars_long(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep,
- const long *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vars(ncid, varid, startp, countp,
- stridep, (void *)op, T_long);
- }
- int
- nc_put_vars_float(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep,
- const float *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vars(ncid, varid, startp, countp,
- stridep, (void *)op, T_float);
- }
- int
- nc_put_vars_double(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep,
- const double *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vars(ncid, varid, startp, countp,
- stridep, (void *)op, T_double);
- }
- int
- nc_put_vars_ubyte(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep,
- const unsigned char *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vars(ncid, varid, startp, countp,
- stridep, (void *)op, T_ubyte);
- }
- int
- nc_put_vars_ushort(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep,
- const unsigned short *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vars(ncid, varid, startp, countp,
- stridep, (void *)op, T_ushort);
- }
- int
- nc_put_vars_uint(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep,
- const unsigned int *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vars(ncid, varid, startp, countp,
- stridep, (void *)op, T_uint);
- }
- int
- nc_put_vars_longlong(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep,
- const long long *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vars(ncid, varid, startp, countp,
- stridep, (void *)op, T_longlong);
- }
- int
- nc_put_vars_ulonglong(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep,
- const unsigned long long *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vars(ncid, varid, startp, countp,
- stridep, (void *)op, NC_UINT64);
- }
- #ifdef USE_NETCDF4
- int
- nc_put_vars_string(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep,
- const char**op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_vars(ncid, varid, startp, countp, stridep,
- (void *)op, NC_STRING);
- }
- #endif /*USE_NETCDF4*/
- /**\} */
- /** \ingroup variables
- Write a mapped array of values to a variable.
- \param ncid NetCDF or group ID, from a previous call to nc_open(),
- nc_create(), nc_def_grp(), or associated inquiry functions such as
- nc_inq_ncid().
- \param varid Variable ID
- \param startp Start vector with one element for each dimension to \ref
- specify_hyperslab.
- \param countp Count vector with one element for each dimension to \ref
- specify_hyperslab.
- \param stridep Stride vector with one element for each dimension to
- \ref specify_hyperslab.
- \param imapp Mapping vector with one element for each dimension to
- \ref specify_hyperslab.
- \param op Pointer where the data will be copied. Memory must be
- allocated by the user before this function is called.
- \returns ::NC_NOERR No error.
- \returns ::NC_ENOTVAR Variable not found.
- \returns ::NC_EINVALCOORDS Index exceeds dimension bound.
- \returns ::NC_EEDGE Start+count exceeds dimension bound.
- \returns ::NC_ERANGE One or more of the values are out of range.
- \returns ::NC_EINDEFINE Operation not allowed in define mode.
- \returns ::NC_EBADID Bad ncid.
- */
- /**@{*/
- int
- nc_put_varm (int ncid, int varid, const size_t *startp,
- const size_t *countp, const ptrdiff_t *stridep,
- const ptrdiff_t *imapp, const void *op)
- {
- NC *ncp;
- int stat = NC_NOERR;
- if ((stat = NC_check_id(ncid, &ncp)))
- return stat;
- return ncp->dispatch->put_varm(ncid, varid, startp, countp,
- stridep, imapp, op, NC_NAT);
- }
- int
- nc_put_varm_text(int ncid, int varid, const size_t *startp,
- const size_t *countp, const ptrdiff_t *stridep,
- const ptrdiff_t *imapp, const char *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
- (void *)op, NC_CHAR);
- }
- int
- nc_put_varm_schar(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep, const ptrdiff_t *imapp,
- const signed char *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
- (void *)op, NC_BYTE);
- }
- int
- nc_put_varm_uchar(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep, const ptrdiff_t *imapp,
- const unsigned char *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
- (void *)op, T_uchar);
- }
- int
- nc_put_varm_short(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep, const ptrdiff_t *imapp,
- const short *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
- (void *)op, NC_SHORT);
- }
- int
- nc_put_varm_int(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep, const ptrdiff_t *imapp,
- const int *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
- (void *)op, NC_INT);
- }
- int
- nc_put_varm_long(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep, const ptrdiff_t *imapp,
- const long *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
- (void *)op, T_long);
- }
- int
- nc_put_varm_float(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep, const ptrdiff_t *imapp,
- const float *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
- (void *)op, T_float);
- }
- int
- nc_put_varm_double(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep, const ptrdiff_t *imapp,
- const double *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
- (void *)op, T_double);
- }
- int
- nc_put_varm_ubyte(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep, const ptrdiff_t *imapp,
- const unsigned char *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
- (void *)op, T_ubyte);
- }
- int
- nc_put_varm_ushort(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep, const ptrdiff_t *imapp,
- const unsigned short *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
- (void *)op, T_ushort);
- }
- int
- nc_put_varm_uint(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep, const ptrdiff_t *imapp,
- const unsigned int *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
- (void *)op, T_uint);
- }
- int
- nc_put_varm_longlong(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep, const ptrdiff_t *imapp,
- const long long *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
- (void *)op, T_longlong);
- }
- int
- nc_put_varm_ulonglong(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep, const ptrdiff_t *imapp,
- const unsigned long long *op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
- (void *)op, NC_UINT64);
- }
- #ifdef USE_NETCDF4
- int
- nc_put_varm_string(int ncid, int varid,
- const size_t *startp, const size_t *countp,
- const ptrdiff_t *stridep, const ptrdiff_t *imapp,
- const char**op)
- {
- NC *ncp;
- int stat = NC_check_id(ncid, &ncp);
- if(stat != NC_NOERR) return stat;
- return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
- (void *)op, NC_STRING);
- }
- #endif /*USE_NETCDF4*/
- /**\} */
- /*! \} */ /*End of named group... */
|