1 /*! \file dvarput.c
2 Functions for writing data to variables.
3 
4 Copyright 2010 University Corporation for Atmospheric
5 Research/Unidata. See COPYRIGHT file for more info.
6 */
7 
8 #include "ncdispatch.h"
9 
10 #undef VARS_USES_VARM
11 #ifndef VARS_USES_VARM
12 struct PUTodometer {
13     int            rank;
14     size_t         index[NC_MAX_VAR_DIMS];
15     size_t         start[NC_MAX_VAR_DIMS];
16     size_t         edges[NC_MAX_VAR_DIMS];
17     ptrdiff_t      stride[NC_MAX_VAR_DIMS];
18     size_t         stop[NC_MAX_VAR_DIMS];
19 };
20 
21 static void
odom_init(struct PUTodometer * odom,int rank,const size_t * start,const size_t * edges,const ptrdiff_t * stride)22 odom_init(struct PUTodometer* odom,
23 	    int rank,
24 	    const size_t* start, const size_t* edges, const ptrdiff_t* stride)
25 {
26     int i;
27     memset(odom,0,sizeof(struct PUTodometer));
28     odom->rank = rank;
29     assert(odom->rank <= NC_MAX_VAR_DIMS);
30     for(i=0;i<odom->rank;i++) {
31 	odom->start[i] = (start != NULL ? start[i] : 0);
32 	odom->edges[i] = (edges != NULL ? edges[i] : 1);
33 	odom->stride[i] = (stride != NULL ? stride[i] : 1);
34 	odom->stop[i] = odom->start[i] + (odom->edges[i]*(size_t)odom->stride[i]);
35 	odom->index[i] = odom->start[i];
36     }
37 }
38 
39 static int
odom_more(struct PUTodometer * odom)40 odom_more(struct PUTodometer* odom)
41 {
42     return (odom->index[0] < odom->stop[0]);
43 }
44 
45 static int
odom_next(struct PUTodometer * odom)46 odom_next(struct PUTodometer* odom)
47 {
48     int i;
49     if(odom->rank == 0) return 0;
50     for(i=odom->rank-1;i>=0;i--) {
51         odom->index[i] += (size_t)odom->stride[i];
52         if(odom->index[i] < odom->stop[i]) break;
53 	if(i == 0) return 0; /* leave the 0th entry if it overflows*/
54 	odom->index[i] = odom->start[i]; /* reset this position*/
55     }
56     return 1;
57 }
58 #endif
59 
60 /** \internal
61 \ingroup variables
62 */
63 static int
NC_put_vara(int ncid,int varid,const size_t * start,const size_t * edges,const void * value,nc_type memtype)64 NC_put_vara(int ncid, int varid, const size_t *start,
65 	    const size_t *edges, const void *value, nc_type memtype)
66 {
67    NC* ncp;
68    int stat = NC_check_id(ncid, &ncp);
69    if(stat != NC_NOERR) return stat;
70    if(edges == NULL) {
71       size_t shape[NC_MAX_VAR_DIMS];
72       int ndims;
73       stat = nc_inq_varndims(ncid, varid, &ndims);
74       if(stat != NC_NOERR) return stat;
75       stat = NC_getshape(ncid, varid, ndims, shape);
76       if(stat != NC_NOERR) return stat;
77       return ncp->dispatch->put_vara(ncid, varid, start, shape, value, memtype);
78    } else
79       return ncp->dispatch->put_vara(ncid, varid, start, edges, value, memtype);
80 }
81 
82 /** \internal
83 \ingroup variables
84 */
85 static int
NC_put_var(int ncid,int varid,const void * value,nc_type memtype)86 NC_put_var(int ncid, int varid, const void *value, nc_type memtype)
87 {
88    int ndims;
89    size_t shape[NC_MAX_VAR_DIMS];
90    int stat = nc_inq_varndims(ncid,varid, &ndims);
91    if(stat) return stat;
92    stat = NC_getshape(ncid,varid, ndims, shape);
93    if(stat) return stat;
94    return NC_put_vara(ncid, varid, NC_coord_zero, shape, value, memtype);
95 }
96 
97 /** \internal
98 \ingroup variables
99 */
100 static int
NC_put_var1(int ncid,int varid,const size_t * coord,const void * value,nc_type memtype)101 NC_put_var1(int ncid, int varid, const size_t *coord, const void* value,
102 	    nc_type memtype)
103 {
104    return NC_put_vara(ncid, varid, coord, NC_coord_one, value, memtype);
105 }
106 
107 /** \internal
108 \ingroup variables
109 */
110 int
NCDEFAULT_put_vars(int ncid,int varid,const size_t * start,const size_t * edges,const ptrdiff_t * stride,const void * value0,nc_type memtype)111 NCDEFAULT_put_vars(int ncid, int varid, const size_t * start,
112 	    const size_t * edges, const ptrdiff_t * stride,
113 	    const void *value0, nc_type memtype)
114 {
115 #ifdef VARS_USES_VARM
116    NC* ncp;
117    int stat = NC_check_id(ncid, &ncp);
118 
119    if(stat != NC_NOERR) return stat;
120    return ncp->dispatch->put_varm(ncid,varid,start,edges,stride,NULL,value0,memtype);
121 #else
122   /* Rebuilt put_vars code to simplify and avoid use of put_varm */
123 
124    int status = NC_NOERR;
125    int i,isstride1,isrecvar;
126    int rank;
127    struct PUTodometer odom;
128    nc_type vartype = NC_NAT;
129    NC* ncp;
130    size_t vartypelen;
131    size_t nels;
132    int memtypelen;
133    const char* value = (const char*)value0;
134    int nrecdims;                /* number of record dims for a variable */
135    int is_recdim[NC_MAX_VAR_DIMS]; /* for variable's dimensions */
136    size_t varshape[NC_MAX_VAR_DIMS];
137    size_t mystart[NC_MAX_VAR_DIMS];
138    size_t myedges[NC_MAX_VAR_DIMS];
139    ptrdiff_t mystride[NC_MAX_VAR_DIMS];
140    const char* memptr = value;
141 
142    status = NC_check_id (ncid, &ncp);
143    if(status != NC_NOERR) return status;
144 
145    status = nc_inq_vartype(ncid, varid, &vartype);
146    if(status != NC_NOERR) return status;
147 
148    if(memtype == NC_NAT) memtype = vartype;
149 
150    /* compute the variable type size */
151    status = nc_inq_type(ncid,vartype,NULL,&vartypelen);
152    if(status != NC_NOERR) return status;
153 
154    if(memtype > NC_MAX_ATOMIC_TYPE)
155 	memtypelen = (int)vartypelen;
156     else
157 	memtypelen = nctypelen(memtype);
158 
159    /* Check gross internal/external type compatibility */
160    if(vartype != memtype) {
161       /* If !atomic, the two types must be the same */
162       if(vartype > NC_MAX_ATOMIC_TYPE
163          || memtype > NC_MAX_ATOMIC_TYPE)
164 	 return NC_EBADTYPE;
165       /* ok, the types differ but both are atomic */
166       if(memtype == NC_CHAR || vartype == NC_CHAR)
167 	 return NC_ECHAR;
168    }
169 
170    /* Get the variable rank */
171    status = nc_inq_varndims(ncid, varid, &rank);
172    if(status != NC_NOERR) return status;
173 
174    /* Get variable dimension sizes */
175    status = NC_inq_recvar(ncid,varid,&nrecdims,is_recdim);
176    if(status != NC_NOERR) return status;
177    isrecvar = (nrecdims > 0);
178    NC_getshape(ncid,varid,rank,varshape);
179 
180    /* Optimize out using various checks */
181    if (rank == 0) {
182       /*
183        * The variable is a scalar; consequently,
184        * there is only one thing to get and only one place to put it.
185        * (Why was I called?)
186        */
187       size_t edge1[1] = {1};
188       return NC_put_vara(ncid, varid, start, edge1, value0, memtype);
189    }
190 
191    /* Do various checks and fixups on start/edges/stride */
192    isstride1 = 1; /* assume so */
193    nels = 1;
194    for(i=0;i<rank;i++) {
195 	size_t dimlen;
196 	mystart[i] = (start == NULL ? 0 : start[i]);
197 #if 0
198 	dimlen = (i == 0 && isrecvar ? numrecs : varshape[i]);
199 	if(i == 0 && isrecvar) {/*do nothing*/}
200 #else
201         /* illegal value checks */
202 	dimlen = varshape[i];
203 	if(is_recdim[i]) {/*do nothing*/}
204 #endif
205         else {
206 	  /* mystart is unsigned, will never be < 0 */
207 #ifdef RELAX_COORD_BOUND
208 	  if (mystart[i] > dimlen) return NC_EINVALCOORDS;
209 #else
210           if (mystart[i] >= dimlen) return NC_EINVALCOORDS;
211 #endif
212        }
213 	if(edges == NULL) {
214 #if 0
215 	   if(i == 0 && isrecvar)
216   	      myedges[i] = numrecs - start[i];
217 #else
218 	   if(is_recdim[i] && isrecvar)
219   	      myedges[i] = varshape[i] - start[i];
220 #endif
221 	   else
222 	      myedges[i] = varshape[i] - mystart[i];
223 	} else
224 	    myedges[i] = edges[i];
225 #ifdef RELAX_COORD_BOUND
226 	if(!is_recdim[i]) {
227 	  if (mystart[i] == dimlen && myedges[i] > 0)
228               return NC_EINVALCOORDS;
229         }
230 #endif
231 	if(!is_recdim[i]) {
232           /* myediges is unsigned, will never be < 0 */
233 	  if(mystart[i] + myedges[i] > dimlen)
234 	    return NC_EEDGE;
235         }
236 	mystride[i] = (stride == NULL ? 1 : stride[i]);
237 	if(mystride[i] <= 0
238 	   /* cast needed for braindead systems with signed size_t */
239            || ((unsigned long) mystride[i] >= X_INT_MAX))
240            return NC_ESTRIDE;
241   	if(mystride[i] != 1) isstride1 = 0;
242         nels *= myedges[i];
243    }
244 
245    if(isstride1) {
246       return NC_put_vara(ncid, varid, mystart, myedges, value, memtype);
247    }
248 
249    if(nels == 0) {
250       /* This should be here instead of before NC_put_vara call to
251        * avoid hang in parallel write for single stride.
252        * Still issue with parallel hang if stride > 1
253        */
254       return NC_NOERR; /* cannot write anything */
255    }
256 
257    /* Initial version uses and odometer to walk the variable
258       and read each value one at a time. This can later be optimized
259       to read larger chunks at a time.
260     */
261 
262 
263    odom_init(&odom,rank,mystart,myedges,mystride);
264 
265    /* walk the odometer to extract values */
266    while(odom_more(&odom)) {
267       int localstatus = NC_NOERR;
268       /* Write a single value */
269       localstatus = NC_put_vara(ncid,varid,odom.index,nc_sizevector1,memptr,memtype);
270       /* So it turns out that when get_varm is used, all errors are
271          delayed and ERANGE will be overwritten by more serious errors.
272       */
273       if(localstatus != NC_NOERR) {
274 	    if(status == NC_NOERR || localstatus != NC_ERANGE)
275 	       status = localstatus;
276       }
277       memptr += memtypelen;
278       odom_next(&odom);
279    }
280    return status;
281 #endif
282 }
283 
284 /** \internal
285 \ingroup variables
286 */
287 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)288 NCDEFAULT_put_varm(
289    int ncid,
290    int varid,
291    const size_t * start,
292    const size_t * edges,
293    const ptrdiff_t * stride,
294    const ptrdiff_t * imapp,
295    const void *value0,
296    nc_type memtype)
297 {
298    int status = NC_NOERR;
299    nc_type vartype = NC_NAT;
300    int varndims = 0;
301    int maxidim = 0;
302    NC* ncp;
303    int memtypelen;
304    const char* value = (char*)value0;
305 
306    status = NC_check_id (ncid, &ncp);
307    if(status != NC_NOERR) return status;
308 
309 /*
310   if(NC_indef(ncp)) return NC_EINDEFINE;
311   if(NC_readonly (ncp)) return NC_EPERM;
312 */
313 
314    /* mid body */
315    status = nc_inq_vartype(ncid, varid, &vartype);
316    if(status != NC_NOERR) return status;
317    /* Check that this is an atomic type */
318    if(vartype > NC_MAX_ATOMIC_TYPE)
319 	return NC_EMAPTYPE;
320 
321    status = nc_inq_varndims(ncid, varid, &varndims);
322    if(status != NC_NOERR) return status;
323 
324    if(memtype == NC_NAT) {
325       memtype = vartype;
326    }
327 
328    if(memtype == NC_CHAR && vartype != NC_CHAR)
329       return NC_ECHAR;
330    else if(memtype != NC_CHAR && vartype == NC_CHAR)
331       return NC_ECHAR;
332 
333    memtypelen = nctypelen(memtype);
334 
335    maxidim = (int) varndims - 1;
336 
337    if (maxidim < 0)
338    {
339       /*
340        * The variable is a scalar; consequently,
341        * there s only one thing to get and only one place to put it.
342        * (Why was I called?)
343        */
344       size_t edge1[1] = {1};
345       return NC_put_vara(ncid, varid, start, edge1, value, memtype);
346    }
347 
348    /*
349     * else
350     * The variable is an array.
351     */
352    {
353       int idim;
354       size_t *mystart = NULL;
355       size_t *myedges = 0;
356       size_t *iocount= 0;    /* count vector */
357       size_t *stop = 0;   /* stop indexes */
358       size_t *length = 0; /* edge lengths in bytes */
359       ptrdiff_t *mystride = 0;
360       ptrdiff_t *mymap= 0;
361       size_t varshape[NC_MAX_VAR_DIMS];
362       int isrecvar;
363       size_t numrecs;
364       int stride1; /* is stride all ones? */
365 
366       /*
367        * Verify stride argument.
368        */
369       stride1 = 1;		/*  assume ok; */
370       if(stride != NULL) {
371 	 for (idim = 0; idim <= maxidim; ++idim) {
372             if ((stride[idim] == 0)
373 		/* cast needed for braindead systems with signed size_t */
374                 || ((unsigned long) stride[idim] >= X_INT_MAX))
375 	    {
376 	       return NC_ESTRIDE;
377             }
378 	    if(stride[idim] != 1) stride1 = 0;
379 	 }
380       }
381 
382       /* If stride1 is true, and there is no imap, then call get_vara
383          directly
384       */
385       if(stride1 && imapp == NULL) {
386 	 return NC_put_vara(ncid, varid, start, edges, value, memtype);
387       }
388 
389       /* Compute some dimension related values */
390       isrecvar = NC_is_recvar(ncid,varid,&numrecs);
391       NC_getshape(ncid,varid,varndims,varshape);
392 
393       /* assert(sizeof(ptrdiff_t) >= sizeof(size_t)); */
394       mystart = (size_t *)calloc((size_t)(varndims * 7), sizeof(ptrdiff_t));
395       if(mystart == NULL) return NC_ENOMEM;
396       myedges = mystart + varndims;
397       iocount = myedges + varndims;
398       stop = iocount + varndims;
399       length = stop + varndims;
400       mystride = (ptrdiff_t *)(length + varndims);
401       mymap = mystride + varndims;
402 
403       /*
404        * Check start, edges
405        */
406       for (idim = maxidim; idim >= 0; --idim)
407       {
408 	 mystart[idim] = start != NULL
409 	    ? start[idim]
410 	    : 0;
411 
412 	 myedges[idim] = edges != NULL
413 	    ? edges[idim]
414 	    : idim == 0 && isrecvar
415     	        ? numrecs - mystart[idim]
416 	        : varshape[idim] - mystart[idim];
417       }
418 
419       for (idim = isrecvar; idim <= maxidim; ++idim)
420       {
421 #ifdef RELAX_COORD_BOUND
422 	 if (mystart[idim] > varshape[idim] ||
423 	    (mystart[idim] == varshape[idim] && myedges[idim] > 0))
424 #else
425          if (mystart[idim] >= varshape[idim])
426 #endif
427 	 {
428 	    status = NC_EINVALCOORDS;
429 	    goto done;
430 	 }
431 
432 	 if (mystart[idim] + myedges[idim] > varshape[idim])
433 	 {
434 	    status = NC_EEDGE;
435 	    goto done;
436 	 }
437       }
438 
439       /*
440        * Initialize I/O parameters.
441        */
442       for (idim = maxidim; idim >= 0; --idim)
443       {
444 	 if (edges != NULL && edges[idim] == 0)
445 	 {
446 	    status = NC_NOERR;    /* read/write no data */
447 	    goto done;
448 	 }
449 
450 	 mystride[idim] = stride != NULL
451 	    ? stride[idim]
452 	    : 1;
453 	 mymap[idim] = imapp != NULL
454 	    ? imapp[idim]
455 	    : idim == maxidim
456 	        ? 1
457 	        : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1];
458 
459 	 iocount[idim] = 1;
460 	 length[idim] = ((size_t)mymap[idim]) * myedges[idim];
461 	 stop[idim] = mystart[idim] + myedges[idim] * (size_t)mystride[idim];
462       }
463 
464       /* Lower body */
465       /*
466        * As an optimization, adjust I/O parameters when the fastest
467        * dimension has unity stride both externally and internally.
468        * In this case, the user could have called a simpler routine
469        * (i.e. ncvar$1()
470        */
471       if (mystride[maxidim] == 1
472 	  && mymap[maxidim] == 1)
473       {
474 	 iocount[maxidim] = myedges[maxidim];
475 	 mystride[maxidim] = (ptrdiff_t) myedges[maxidim];
476 	 mymap[maxidim] = (ptrdiff_t) length[maxidim];
477       }
478 
479       /*
480        * Perform I/O.  Exit when done.
481        */
482       for (;;)
483       {
484 	 /* TODO: */
485 	 int lstatus = NC_put_vara(ncid, varid, mystart, iocount,
486 				   value, memtype);
487 	 if (lstatus != NC_NOERR) {
488 	    if(status == NC_NOERR || lstatus != NC_ERANGE)
489 	       status = lstatus;
490 	 }
491 
492 	 /*
493 	  * The following code permutes through the variable s
494 	  * external start-index space and it s internal address
495 	  * space.  At the UPC, this algorithm is commonly
496 	  * called "odometer code".
497 	  */
498 	 idim = maxidim;
499         carry:
500 	 value += (mymap[idim] * memtypelen);
501 	 mystart[idim] += (size_t)mystride[idim];
502 	 if (mystart[idim] == stop[idim])
503 	 {
504 	    size_t l = (length[idim] * (size_t)memtypelen);
505 	    value -= l;
506 	    mystart[idim] = start[idim];
507 	    if (--idim < 0)
508 	       break; /* normal return */
509 	    goto carry;
510 	 }
511       } /* I/O loop */
512      done:
513       free(mystart);
514    } /* variable is array */
515    return status;
516 }
517 
518 /** \internal
519 \ingroup variables
520 */
521 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)522 NC_put_vars(int ncid, int varid, const size_t *start,
523 	    const size_t *edges, const ptrdiff_t *stride,
524 	    const void *value, nc_type memtype)
525 {
526    NC* ncp;
527    int stat = NC_check_id(ncid, &ncp);
528 
529    if(stat != NC_NOERR) return stat;
530 #ifdef USE_NETCDF4
531    if(memtype >= NC_FIRSTUSERTYPEID) memtype = NC_NAT;
532 #endif
533    return ncp->dispatch->put_vars(ncid,varid,start,edges,stride,value,memtype);
534 }
535 
536 /** \internal
537 \ingroup variables
538 */
539 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)540 NC_put_varm(int ncid, int varid, const size_t *start,
541 	    const size_t *edges, const ptrdiff_t *stride, const ptrdiff_t* map,
542 	    const void *value, nc_type memtype)
543 {
544    NC* ncp;
545    int stat = NC_check_id(ncid, &ncp);
546 
547    if(stat != NC_NOERR) return stat;
548 #ifdef USE_NETCDF4
549    if(memtype >= NC_FIRSTUSERTYPEID) memtype = NC_NAT;
550 #endif
551    return ncp->dispatch->put_varm(ncid,varid,start,edges,stride,map,value,memtype);
552 }
553 
554 /** \name Writing Data to Variables
555 
556 Functions to write data from variables. */
557 /*! \{ */ /* All these functions are part of this named group... */
558 
559 /** \ingroup variables
560 Write an array of values to a variable.
561 
562 The values to be written are associated with the netCDF variable by
563 assuming that the last dimension of the netCDF variable varies fastest
564 in the C interface. The netCDF dataset must be in data mode. The array
565 to be written is specified by giving a corner and a vector of edge
566 lengths to \ref specify_hyperslab.
567 
568 The functions for types ubyte, ushort, uint, longlong, ulonglong, and
569 string are only available for netCDF-4/HDF5 files.
570 
571 The nc_put_var() function will write a variable of any type, including
572 user defined type. For this function, the type of the data in memory
573 must match the type of the variable - no data conversion is done.
574 
575 \param ncid NetCDF or group ID, from a previous call to nc_open(),
576 nc_create(), nc_def_grp(), or associated inquiry functions such as
577 nc_inq_ncid().
578 
579 \param varid Variable ID
580 
581 \param startp Start vector with one element for each dimension to \ref
582 specify_hyperslab.
583 
584 \param countp Count vector with one element for each dimension to \ref
585 specify_hyperslab.
586 
587 \param op Pointer where the data will be copied. Memory must be
588 allocated by the user before this function is called.
589 
590 \returns ::NC_NOERR No error.
591 \returns ::NC_ENOTVAR Variable not found.
592 \returns ::NC_EINVALCOORDS Index exceeds dimension bound.
593 \returns ::NC_EEDGE Start+count exceeds dimension bound.
594 \returns ::NC_ERANGE One or more of the values are out of range.
595 \returns ::NC_EINDEFINE Operation not allowed in define mode.
596 \returns ::NC_EBADID Bad ncid.
597  */
598 /**@{*/
599 int
nc_put_vara(int ncid,int varid,const size_t * startp,const size_t * countp,const void * op)600 nc_put_vara(int ncid, int varid, const size_t *startp,
601 	    const size_t *countp, const void *op)
602 {
603    NC* ncp;
604    int stat = NC_check_id(ncid, &ncp);
605    nc_type xtype;
606    if(stat != NC_NOERR) return stat;
607    stat = nc_inq_vartype(ncid, varid, &xtype);
608    if(stat != NC_NOERR) return stat;
609    return NC_put_vara(ncid, varid, startp, countp, op, xtype);
610 }
611 
612 int
nc_put_vara_text(int ncid,int varid,const size_t * startp,const size_t * countp,const char * op)613 nc_put_vara_text(int ncid, int varid, const size_t *startp,
614 		 const size_t *countp, const char *op)
615 {
616    return NC_put_vara(ncid, varid, startp, countp,
617 		      (void*)op, NC_CHAR);
618 }
619 
620 int
nc_put_vara_schar(int ncid,int varid,const size_t * startp,const size_t * countp,const signed char * op)621 nc_put_vara_schar(int ncid, int varid, const size_t *startp,
622 		  const size_t *countp, const signed char *op)
623 {
624    NC* ncp;
625    int stat = NC_check_id(ncid, &ncp);
626    if(stat != NC_NOERR) return stat;
627    return NC_put_vara(ncid, varid, startp, countp, (void *)op,
628 		      NC_BYTE);
629 }
630 
631 int
nc_put_vara_uchar(int ncid,int varid,const size_t * startp,const size_t * countp,const unsigned char * op)632 nc_put_vara_uchar(int ncid, int varid, const size_t *startp,
633 		  const size_t *countp, const unsigned char *op)
634 {
635    NC* ncp;
636    int stat = NC_check_id(ncid, &ncp);
637    if(stat != NC_NOERR) return stat;
638    return NC_put_vara(ncid, varid, startp, countp, (void *)op,
639 		      T_uchar);
640 }
641 
642 int
nc_put_vara_short(int ncid,int varid,const size_t * startp,const size_t * countp,const short * op)643 nc_put_vara_short(int ncid, int varid, const size_t *startp,
644 		  const size_t *countp, const short *op)
645 {
646    NC* ncp;
647    int stat = NC_check_id(ncid, &ncp);
648    if(stat != NC_NOERR) return stat;
649    return NC_put_vara(ncid, varid, startp, countp, (void *)op,
650 		      NC_SHORT);
651 }
652 
653 int
nc_put_vara_int(int ncid,int varid,const size_t * startp,const size_t * countp,const int * op)654 nc_put_vara_int(int ncid, int varid, const size_t *startp,
655 		const size_t *countp, const int *op)
656 {
657    NC* ncp;
658    int stat = NC_check_id(ncid, &ncp);
659    if(stat != NC_NOERR) return stat;
660    return NC_put_vara(ncid, varid, startp, countp, (void *)op,
661 		      NC_INT);
662 }
663 
664 int
nc_put_vara_long(int ncid,int varid,const size_t * startp,const size_t * countp,const long * op)665 nc_put_vara_long(int ncid, int varid, const size_t *startp,
666 		 const size_t *countp, const long *op)
667 {
668    NC* ncp;
669    int stat = NC_check_id(ncid, &ncp);
670    if(stat != NC_NOERR) return stat;
671    return NC_put_vara(ncid, varid, startp, countp, (void *)op,
672 		      T_long);
673 }
674 
675 int
nc_put_vara_float(int ncid,int varid,const size_t * startp,const size_t * countp,const float * op)676 nc_put_vara_float(int ncid, int varid, const size_t *startp,
677 		  const size_t *countp, const float *op)
678 {
679    NC* ncp;
680    int stat = NC_check_id(ncid, &ncp);
681    if(stat != NC_NOERR) return stat;
682    return NC_put_vara(ncid, varid, startp, countp, (void *)op,
683 		      T_float);
684 }
685 
686 int
nc_put_vara_double(int ncid,int varid,const size_t * startp,const size_t * countp,const double * op)687 nc_put_vara_double(int ncid, int varid, const size_t *startp,
688 		   const size_t *countp, const double *op)
689 {
690    NC* ncp;
691    int stat = NC_check_id(ncid, &ncp);
692    if(stat != NC_NOERR) return stat;
693    return NC_put_vara(ncid, varid, startp, countp, (void *)op,
694 		      T_double);
695 }
696 
697 int
nc_put_vara_ubyte(int ncid,int varid,const size_t * startp,const size_t * countp,const unsigned char * op)698 nc_put_vara_ubyte(int ncid, int varid, const size_t *startp,
699 		  const size_t *countp, const unsigned char *op)
700 {
701    NC* ncp;
702    int stat = NC_check_id(ncid, &ncp);
703    if(stat != NC_NOERR) return stat;
704    return NC_put_vara(ncid, varid, startp, countp, (void *)op,
705 		      T_ubyte);
706 }
707 
708 int
nc_put_vara_ushort(int ncid,int varid,const size_t * startp,const size_t * countp,const unsigned short * op)709 nc_put_vara_ushort(int ncid, int varid, const size_t *startp,
710 		   const size_t *countp, const unsigned short *op)
711 {
712    NC* ncp;
713    int stat = NC_check_id(ncid, &ncp);
714    if(stat != NC_NOERR) return stat;
715    return NC_put_vara(ncid, varid, startp, countp, (void *)op,
716 		      T_ushort);
717 }
718 
719 int
nc_put_vara_uint(int ncid,int varid,const size_t * startp,const size_t * countp,const unsigned int * op)720 nc_put_vara_uint(int ncid, int varid, const size_t *startp,
721 		 const size_t *countp, const unsigned int *op)
722 {
723    NC* ncp;
724    int stat = NC_check_id(ncid, &ncp);
725    if(stat != NC_NOERR) return stat;
726    return NC_put_vara(ncid, varid, startp, countp, (void *)op,
727 		      T_uint);
728 }
729 
730 int
nc_put_vara_longlong(int ncid,int varid,const size_t * startp,const size_t * countp,const long long * op)731 nc_put_vara_longlong(int ncid, int varid, const size_t *startp,
732 		     const size_t *countp, const long long *op)
733 {
734    NC* ncp;
735    int stat = NC_check_id(ncid, &ncp);
736    if(stat != NC_NOERR) return stat;
737    return NC_put_vara(ncid, varid, startp, countp, (void *)op,
738 		      T_longlong);
739 }
740 
741 int
nc_put_vara_ulonglong(int ncid,int varid,const size_t * startp,const size_t * countp,const unsigned long long * op)742 nc_put_vara_ulonglong(int ncid, int varid, const size_t *startp,
743 		      const size_t *countp, const unsigned long long *op)
744 {
745    NC* ncp;
746    int stat = NC_check_id(ncid, &ncp);
747    if(stat != NC_NOERR) return stat;
748    return NC_put_vara(ncid, varid, startp, countp, (void *)op,
749 		      NC_UINT64);
750 }
751 
752 #ifdef USE_NETCDF4
753 int
nc_put_vara_string(int ncid,int varid,const size_t * startp,const size_t * countp,const char ** op)754 nc_put_vara_string(int ncid, int varid, const size_t *startp,
755 		   const size_t *countp, const char* *op)
756 {
757    NC* ncp;
758    int stat = NC_check_id(ncid, &ncp);
759    if(stat != NC_NOERR) return stat;
760    return NC_put_vara(ncid, varid, startp, countp, (void *)op,
761 		      NC_STRING);
762 }
763 
764 #endif /*USE_NETCDF4*/
765 /**@}*/
766 
767 /** \ingroup variables
768 Write one datum.
769 
770 \param ncid NetCDF or group ID, from a previous call to nc_open(),
771 nc_create(), nc_def_grp(), or associated inquiry functions such as
772 nc_inq_ncid().
773 
774 \param varid Variable ID
775 
776 \param indexp Index vector with one element for each dimension.
777 
778 \param op Pointer from where the data will be copied.
779 
780 \returns ::NC_NOERR No error.
781 \returns ::NC_ENOTVAR Variable not found.
782 \returns ::NC_EINVALCOORDS Index exceeds dimension bound.
783 \returns ::NC_EEDGE Start+count exceeds dimension bound.
784 \returns ::NC_ERANGE One or more of the values are out of range.
785 \returns ::NC_EINDEFINE Operation not allowed in define mode.
786 \returns ::NC_EBADID Bad ncid.
787  */
788 /**@{*/
789 int
nc_put_var1(int ncid,int varid,const size_t * indexp,const void * op)790 nc_put_var1(int ncid, int varid, const size_t *indexp, const void *op)
791 {
792    return NC_put_var1(ncid, varid, indexp, op, NC_NAT);
793 }
794 
795 int
nc_put_var1_text(int ncid,int varid,const size_t * indexp,const char * op)796 nc_put_var1_text(int ncid, int varid, const size_t *indexp, const char *op)
797 {
798    NC* ncp;
799    int stat = NC_check_id(ncid, &ncp);
800    if(stat != NC_NOERR) return stat;
801    return NC_put_var1(ncid, varid, indexp, (void *)op, NC_CHAR);
802 }
803 
804 int
nc_put_var1_schar(int ncid,int varid,const size_t * indexp,const signed char * op)805 nc_put_var1_schar(int ncid, int varid, const size_t *indexp, const signed char *op)
806 {
807    NC* ncp;
808    int stat = NC_check_id(ncid, &ncp);
809    if(stat != NC_NOERR) return stat;
810    return NC_put_var1(ncid, varid, indexp, (void *)op, NC_BYTE);
811 }
812 
813 int
nc_put_var1_uchar(int ncid,int varid,const size_t * indexp,const unsigned char * op)814 nc_put_var1_uchar(int ncid, int varid, const size_t *indexp, const unsigned char *op)
815 {
816    NC* ncp;
817    int stat = NC_check_id(ncid, &ncp);
818    if(stat != NC_NOERR) return stat;
819    return NC_put_var1(ncid, varid, indexp, (void *)op, NC_UBYTE);
820 }
821 
822 int
nc_put_var1_short(int ncid,int varid,const size_t * indexp,const short * op)823 nc_put_var1_short(int ncid, int varid, const size_t *indexp, const short *op)
824 {
825    NC* ncp;
826    int stat = NC_check_id(ncid, &ncp);
827    if(stat != NC_NOERR) return stat;
828    return NC_put_var1(ncid, varid, indexp, (void *)op, NC_SHORT);
829 }
830 
831 int
nc_put_var1_int(int ncid,int varid,const size_t * indexp,const int * op)832 nc_put_var1_int(int ncid, int varid, const size_t *indexp, const int *op)
833 {
834    NC* ncp;
835    int stat = NC_check_id(ncid, &ncp);
836    if(stat != NC_NOERR) return stat;
837    return NC_put_var1(ncid, varid, indexp, (void *)op, NC_INT);
838 }
839 
840 int
nc_put_var1_long(int ncid,int varid,const size_t * indexp,const long * op)841 nc_put_var1_long(int ncid, int varid, const size_t *indexp, const long *op)
842 {
843    NC* ncp;
844    int stat = NC_check_id(ncid, &ncp);
845    if(stat != NC_NOERR) return stat;
846    return NC_put_var1(ncid, varid, indexp, (void*)op, longtype);
847 }
848 
849 int
nc_put_var1_float(int ncid,int varid,const size_t * indexp,const float * op)850 nc_put_var1_float(int ncid, int varid, const size_t *indexp, const float *op)
851 {
852    NC* ncp;
853    int stat = NC_check_id(ncid, &ncp);
854    if(stat != NC_NOERR) return stat;
855    return NC_put_var1(ncid, varid, indexp, (void*)op, NC_FLOAT);
856 }
857 
858 int
nc_put_var1_double(int ncid,int varid,const size_t * indexp,const double * op)859 nc_put_var1_double(int ncid, int varid, const size_t *indexp, const double *op)
860 {
861    NC* ncp;
862    int stat = NC_check_id(ncid, &ncp);
863    if(stat != NC_NOERR) return stat;
864    return NC_put_var1(ncid, varid, indexp, (void *)op, NC_DOUBLE);
865 }
866 
867 int
nc_put_var1_ubyte(int ncid,int varid,const size_t * indexp,const unsigned char * op)868 nc_put_var1_ubyte(int ncid, int varid, const size_t *indexp, const unsigned char *op)
869 {
870    NC* ncp;
871    int stat = NC_check_id(ncid, &ncp);
872    if(stat != NC_NOERR) return stat;
873    return NC_put_var1(ncid, varid, indexp, (void *)op, NC_UBYTE);
874 }
875 
876 int
nc_put_var1_ushort(int ncid,int varid,const size_t * indexp,const unsigned short * op)877 nc_put_var1_ushort(int ncid, int varid, const size_t *indexp, const unsigned short *op)
878 {
879    NC* ncp;
880    int stat = NC_check_id(ncid, &ncp);
881    if(stat != NC_NOERR) return stat;
882    return NC_put_var1(ncid, varid, indexp, (void *)op, NC_USHORT);
883 }
884 
885 int
nc_put_var1_uint(int ncid,int varid,const size_t * indexp,const unsigned int * op)886 nc_put_var1_uint(int ncid, int varid, const size_t *indexp, const unsigned int *op)
887 {
888    NC* ncp;
889    int stat = NC_check_id(ncid, &ncp);
890    if(stat != NC_NOERR) return stat;
891    return NC_put_var1(ncid, varid, indexp, (void *)op, NC_UINT);
892 }
893 
894 int
nc_put_var1_longlong(int ncid,int varid,const size_t * indexp,const long long * op)895 nc_put_var1_longlong(int ncid, int varid, const size_t *indexp, const long long *op)
896 {
897    NC* ncp;
898    int stat = NC_check_id(ncid, &ncp);
899    if(stat != NC_NOERR) return stat;
900    return NC_put_var1(ncid, varid, indexp, (void *)op, NC_INT64);
901 }
902 
903 int
nc_put_var1_ulonglong(int ncid,int varid,const size_t * indexp,const unsigned long long * op)904 nc_put_var1_ulonglong(int ncid, int varid, const size_t *indexp, const unsigned long long *op)
905 {
906    NC* ncp;
907    int stat = NC_check_id(ncid, &ncp);
908    if(stat != NC_NOERR) return stat;
909    return NC_put_var1(ncid, varid, indexp, (void *)op, NC_UINT64);
910 }
911 
912 #ifdef USE_NETCDF4
913 int
nc_put_var1_string(int ncid,int varid,const size_t * indexp,const char ** op)914 nc_put_var1_string(int ncid, int varid, const size_t *indexp, const char* *op)
915 {
916    NC* ncp;
917    int stat = NC_check_id(ncid, &ncp);
918    if(stat != NC_NOERR) return stat;
919    return NC_put_var1(ncid, varid, indexp, (void*)op, NC_STRING);
920 }
921 #endif /*USE_NETCDF4*/
922 /**@}*/
923 
924 /** \ingroup variables
925 Write an entire variable with one call.
926 
927 The nc_put_var_ type family of functions write all the values of a
928 variable into a netCDF variable of an open netCDF dataset. This is the
929 simplest interface to use for writing a value in a scalar variable or
930 whenever all the values of a multidimensional variable can all be
931 written at once. The values to be written are associated with the
932 netCDF variable by assuming that the last dimension of the netCDF
933 variable varies fastest in the C interface. The values are converted
934 to the external data type of the variable, if necessary.
935 
936 Take care when using this function with record variables (variables
937 that use the ::NC_UNLIMITED dimension). If you try to write all the
938 values of a record variable into a netCDF file that has no record data
939 yet (hence has 0 records), nothing will be written. Similarly, if you
940 try to write all the values of a record variable but there are more
941 records in the file than you assume, more in-memory data will be
942 accessed than you supply, which may result in a segmentation
943 violation. To avoid such problems, it is better to use the nc_put_vara
944 interfaces for variables that use the ::NC_UNLIMITED dimension.
945 
946 The functions for types ubyte, ushort, uint, longlong, ulonglong, and
947 string are only available for netCDF-4/HDF5 files.
948 
949 The nc_put_var() function will write a variable of any type, including
950 user defined type. For this function, the type of the data in memory
951 must match the type of the variable - no data conversion is done.
952 
953 \param ncid NetCDF or group ID, from a previous call to nc_open(),
954 nc_create(), nc_def_grp(), or associated inquiry functions such as
955 nc_inq_ncid().
956 
957 \param varid Variable ID
958 
959 \param op Pointer from where the data will be copied.
960 
961 \returns ::NC_NOERR No error.
962 \returns ::NC_ENOTVAR Variable not found.
963 \returns ::NC_EINVALCOORDS Index exceeds dimension bound.
964 \returns ::NC_EEDGE Start+count exceeds dimension bound.
965 \returns ::NC_ERANGE One or more of the values are out of range.
966 \returns ::NC_EINDEFINE Operation not allowed in define mode.
967 \returns ::NC_EBADID Bad ncid.
968  */
969 /**@{*/
970 int
nc_put_var(int ncid,int varid,const void * op)971 nc_put_var(int ncid, int varid, const void *op)
972 {
973    return NC_put_var(ncid, varid, op, NC_NAT);
974 }
975 
976 int
nc_put_var_text(int ncid,int varid,const char * op)977 nc_put_var_text(int ncid, int varid, const char *op)
978 {
979    NC* ncp;
980    int stat = NC_check_id(ncid, &ncp);
981    if(stat != NC_NOERR) return stat;
982    return NC_put_var(ncid,varid,(void*)op,NC_CHAR);
983 }
984 
985 int
nc_put_var_schar(int ncid,int varid,const signed char * op)986 nc_put_var_schar(int ncid, int varid, const signed char *op)
987 {
988    NC* ncp;
989    int stat = NC_check_id(ncid, &ncp);
990    if(stat != NC_NOERR) return stat;
991    return NC_put_var(ncid,varid,(void*)op,NC_BYTE);
992 }
993 
994 int
nc_put_var_uchar(int ncid,int varid,const unsigned char * op)995 nc_put_var_uchar(int ncid, int varid, const unsigned char *op)
996 {
997    NC* ncp;
998    int stat = NC_check_id(ncid, &ncp);
999    if(stat != NC_NOERR) return stat;
1000    return NC_put_var(ncid,varid,(void*)op,T_uchar);
1001 }
1002 
1003 int
nc_put_var_short(int ncid,int varid,const short * op)1004 nc_put_var_short(int ncid, int varid, const short *op)
1005 {
1006    NC* ncp;
1007    int stat = NC_check_id(ncid, &ncp);
1008    if(stat != NC_NOERR) return stat;
1009    return NC_put_var(ncid,varid,(void*)op,NC_SHORT);
1010 }
1011 
1012 int
nc_put_var_int(int ncid,int varid,const int * op)1013 nc_put_var_int(int ncid, int varid, const int *op)
1014 {
1015    NC* ncp;
1016    int stat = NC_check_id(ncid, &ncp);
1017    if(stat != NC_NOERR) return stat;
1018    return NC_put_var(ncid,varid,(void*)op,NC_INT);
1019 }
1020 
1021 int
nc_put_var_long(int ncid,int varid,const long * op)1022 nc_put_var_long(int ncid, int varid, const long *op)
1023 {
1024    NC* ncp;
1025    int stat = NC_check_id(ncid, &ncp);
1026    if(stat != NC_NOERR) return stat;
1027    return NC_put_var(ncid,varid,(void*)op,T_long);
1028 }
1029 
1030 int
nc_put_var_float(int ncid,int varid,const float * op)1031 nc_put_var_float(int ncid, int varid, const float *op)
1032 {
1033    NC* ncp;
1034    int stat = NC_check_id(ncid, &ncp);
1035    if(stat != NC_NOERR) return stat;
1036    return NC_put_var(ncid,varid,(void*)op,T_float);
1037 }
1038 
1039 int
nc_put_var_double(int ncid,int varid,const double * op)1040 nc_put_var_double(int ncid, int varid, const double *op)
1041 {
1042    NC* ncp;
1043    int stat = NC_check_id(ncid, &ncp);
1044    if(stat != NC_NOERR) return stat;
1045    return NC_put_var(ncid,varid,(void*)op,T_double);
1046 }
1047 
1048 int
nc_put_var_ubyte(int ncid,int varid,const unsigned char * op)1049 nc_put_var_ubyte(int ncid, int varid, const unsigned char *op)
1050 {
1051    NC* ncp;
1052    int stat = NC_check_id(ncid, &ncp);
1053    if(stat != NC_NOERR) return stat;
1054    return NC_put_var(ncid,varid,(void*)op,T_ubyte);
1055 }
1056 
1057 int
nc_put_var_ushort(int ncid,int varid,const unsigned short * op)1058 nc_put_var_ushort(int ncid, int varid, const unsigned short *op)
1059 {
1060    NC* ncp;
1061    int stat = NC_check_id(ncid, &ncp);
1062    if(stat != NC_NOERR) return stat;
1063    return NC_put_var(ncid,varid,(void*)op,T_ushort);
1064 }
1065 
1066 int
nc_put_var_uint(int ncid,int varid,const unsigned int * op)1067 nc_put_var_uint(int ncid, int varid, const unsigned int *op)
1068 {
1069    NC* ncp;
1070    int stat = NC_check_id(ncid, &ncp);
1071    if(stat != NC_NOERR) return stat;
1072    return NC_put_var(ncid,varid,(void*)op,T_uint);
1073 }
1074 
1075 int
nc_put_var_longlong(int ncid,int varid,const long long * op)1076 nc_put_var_longlong(int ncid, int varid, const long long *op)
1077 {
1078    NC* ncp;
1079    int stat = NC_check_id(ncid, &ncp);
1080    if(stat != NC_NOERR) return stat;
1081    return NC_put_var(ncid,varid,(void*)op,T_longlong);
1082 }
1083 
1084 int
nc_put_var_ulonglong(int ncid,int varid,const unsigned long long * op)1085 nc_put_var_ulonglong(int ncid, int varid, const unsigned long long *op)
1086 {
1087    NC* ncp;
1088    int stat = NC_check_id(ncid, &ncp);
1089    if(stat != NC_NOERR) return stat;
1090    return NC_put_var(ncid,varid,(void*)op,NC_UINT64);
1091 }
1092 
1093 #ifdef USE_NETCDF4
1094 int
nc_put_var_string(int ncid,int varid,const char ** op)1095 nc_put_var_string(int ncid, int varid, const char* *op)
1096 {
1097    NC* ncp;
1098    int stat = NC_check_id(ncid, &ncp);
1099    if(stat != NC_NOERR) return stat;
1100    return NC_put_var(ncid,varid,(void*)op,NC_STRING);
1101 }
1102 #endif /*USE_NETCDF4*/
1103 /**\} */
1104 
1105 /** \ingroup variables
1106 Write a strided array of values to a variable.
1107 
1108 \param ncid NetCDF or group ID, from a previous call to nc_open(),
1109 nc_create(), nc_def_grp(), or associated inquiry functions such as
1110 nc_inq_ncid().
1111 
1112 \param varid Variable ID
1113 
1114 \param startp Start vector with one element for each dimension to \ref
1115 specify_hyperslab.
1116 
1117 \param countp Count vector with one element for each dimension to \ref
1118 specify_hyperslab.
1119 
1120 \param stridep Stride vector with one element for each dimension to
1121 \ref specify_hyperslab.
1122 
1123 \param op Pointer where the data will be copied. Memory must be
1124 allocated by the user before this function is called.
1125 
1126 \returns ::NC_NOERR No error.
1127 \returns ::NC_ENOTVAR Variable not found.
1128 \returns ::NC_EINVALCOORDS Index exceeds dimension bound.
1129 \returns ::NC_EEDGE Start+count exceeds dimension bound.
1130 \returns ::NC_ERANGE One or more of the values are out of range.
1131 \returns ::NC_EINDEFINE Operation not allowed in define mode.
1132 \returns ::NC_EBADID Bad ncid.
1133  */
1134 /**@{*/
1135 int
nc_put_vars(int ncid,int varid,const size_t * startp,const size_t * countp,const ptrdiff_t * stridep,const void * op)1136 nc_put_vars (int ncid, int varid, const size_t *startp,
1137 	     const size_t *countp, const ptrdiff_t *stridep,
1138 	     const void *op)
1139 {
1140    NC *ncp;
1141    int stat = NC_NOERR;
1142 
1143    if ((stat = NC_check_id(ncid, &ncp)))
1144        return stat;
1145    return ncp->dispatch->put_vars(ncid, varid, startp, countp,
1146 				  stridep, op, NC_NAT);
1147 }
1148 
1149 int
nc_put_vars_text(int ncid,int varid,const size_t * startp,const size_t * countp,const ptrdiff_t * stridep,const char * op)1150 nc_put_vars_text(int ncid, int varid, const size_t *startp,
1151 		 const size_t *countp, const ptrdiff_t *stridep,
1152 		 const char *op)
1153 {
1154    NC *ncp;
1155    int stat = NC_check_id(ncid, &ncp);
1156    if(stat != NC_NOERR) return stat;
1157    return NC_put_vars(ncid, varid, startp, countp,
1158 		      stridep,(void*)op,NC_CHAR);
1159 }
1160 
1161 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)1162 nc_put_vars_schar(int ncid, int varid, const size_t *startp,
1163 		  const size_t *countp, const ptrdiff_t *stridep,
1164 		  const signed char *op)
1165 {
1166    NC *ncp;
1167    int stat = NC_check_id(ncid, &ncp);
1168    if(stat != NC_NOERR) return stat;
1169    return NC_put_vars(ncid, varid, startp, countp,
1170 		      stridep,(void*)op,NC_BYTE);
1171 }
1172 
1173 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)1174 nc_put_vars_uchar(int ncid, int varid,
1175 		  const size_t *startp, const size_t *countp,
1176 		  const ptrdiff_t *stridep,
1177 		  const unsigned char *op)
1178 {
1179    NC *ncp;
1180    int stat = NC_check_id(ncid, &ncp);
1181    if(stat != NC_NOERR) return stat;
1182    return NC_put_vars(ncid, varid, startp, countp,
1183 		      stridep, (void *)op, T_uchar);
1184 }
1185 
1186 int
nc_put_vars_short(int ncid,int varid,const size_t * startp,const size_t * countp,const ptrdiff_t * stridep,const short * op)1187 nc_put_vars_short(int ncid, int varid,
1188 		  const size_t *startp, const size_t *countp,
1189 		  const ptrdiff_t *stridep,
1190 		  const short *op)
1191 {
1192    NC *ncp;
1193    int stat = NC_check_id(ncid, &ncp);
1194    if(stat != NC_NOERR) return stat;
1195    return NC_put_vars(ncid, varid, startp, countp,
1196 		      stridep, (void *)op, NC_SHORT);
1197 }
1198 
1199 int
nc_put_vars_int(int ncid,int varid,const size_t * startp,const size_t * countp,const ptrdiff_t * stridep,const int * op)1200 nc_put_vars_int(int ncid, int varid,
1201 		const size_t *startp, const size_t *countp,
1202 		const ptrdiff_t *stridep,
1203 		const int *op)
1204 {
1205    NC *ncp;
1206    int stat = NC_check_id(ncid, &ncp);
1207    if(stat != NC_NOERR) return stat;
1208    return NC_put_vars(ncid, varid, startp, countp,
1209 		      stridep, (void *)op, NC_INT);
1210 }
1211 
1212 int
nc_put_vars_long(int ncid,int varid,const size_t * startp,const size_t * countp,const ptrdiff_t * stridep,const long * op)1213 nc_put_vars_long(int ncid, int varid,
1214 		 const size_t *startp, const size_t *countp,
1215 		 const ptrdiff_t *stridep,
1216 		 const long *op)
1217 {
1218    NC *ncp;
1219    int stat = NC_check_id(ncid, &ncp);
1220    if(stat != NC_NOERR) return stat;
1221    return NC_put_vars(ncid, varid, startp, countp,
1222 		      stridep, (void *)op, T_long);
1223 }
1224 
1225 int
nc_put_vars_float(int ncid,int varid,const size_t * startp,const size_t * countp,const ptrdiff_t * stridep,const float * op)1226 nc_put_vars_float(int ncid, int varid,
1227 		  const size_t *startp, const size_t *countp,
1228 		  const ptrdiff_t *stridep,
1229 		  const float *op)
1230 {
1231    NC *ncp;
1232    int stat = NC_check_id(ncid, &ncp);
1233    if(stat != NC_NOERR) return stat;
1234    return NC_put_vars(ncid, varid, startp, countp,
1235 		      stridep, (void *)op, T_float);
1236 }
1237 
1238 int
nc_put_vars_double(int ncid,int varid,const size_t * startp,const size_t * countp,const ptrdiff_t * stridep,const double * op)1239 nc_put_vars_double(int ncid, int varid,
1240 		   const size_t *startp, const size_t *countp,
1241 		   const ptrdiff_t *stridep,
1242 		   const double *op)
1243 {
1244    NC *ncp;
1245    int stat = NC_check_id(ncid, &ncp);
1246    if(stat != NC_NOERR) return stat;
1247    return NC_put_vars(ncid, varid, startp, countp,
1248 		      stridep, (void *)op, T_double);
1249 }
1250 
1251 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)1252 nc_put_vars_ubyte(int ncid, int varid,
1253 		  const size_t *startp, const size_t *countp,
1254 		  const ptrdiff_t *stridep,
1255 		  const unsigned char *op)
1256 {
1257    NC *ncp;
1258    int stat = NC_check_id(ncid, &ncp);
1259    if(stat != NC_NOERR) return stat;
1260    return NC_put_vars(ncid, varid, startp, countp,
1261 		      stridep, (void *)op, T_ubyte);
1262 }
1263 
1264 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)1265 nc_put_vars_ushort(int ncid, int varid,
1266 		   const size_t *startp, const size_t *countp,
1267 		   const ptrdiff_t *stridep,
1268 		   const unsigned short *op)
1269 {
1270    NC *ncp;
1271    int stat = NC_check_id(ncid, &ncp);
1272    if(stat != NC_NOERR) return stat;
1273    return NC_put_vars(ncid, varid, startp, countp,
1274 		      stridep, (void *)op, T_ushort);
1275 }
1276 
1277 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)1278 nc_put_vars_uint(int ncid, int varid,
1279 		 const size_t *startp, const size_t *countp,
1280 		 const ptrdiff_t *stridep,
1281 		 const unsigned int *op)
1282 {
1283    NC *ncp;
1284    int stat = NC_check_id(ncid, &ncp);
1285    if(stat != NC_NOERR) return stat;
1286    return NC_put_vars(ncid, varid, startp, countp,
1287 		      stridep, (void *)op, T_uint);
1288 }
1289 
1290 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)1291 nc_put_vars_longlong(int ncid, int varid,
1292 		     const size_t *startp, const size_t *countp,
1293 		     const ptrdiff_t *stridep,
1294 		     const long long *op)
1295 {
1296    NC *ncp;
1297    int stat = NC_check_id(ncid, &ncp);
1298    if(stat != NC_NOERR) return stat;
1299    return NC_put_vars(ncid, varid, startp, countp,
1300 		      stridep, (void *)op, T_longlong);
1301 }
1302 
1303 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)1304 nc_put_vars_ulonglong(int ncid, int varid,
1305 		      const size_t *startp, const size_t *countp,
1306 		      const ptrdiff_t *stridep,
1307 		      const unsigned long long *op)
1308 {
1309    NC *ncp;
1310    int stat = NC_check_id(ncid, &ncp);
1311    if(stat != NC_NOERR) return stat;
1312    return NC_put_vars(ncid, varid, startp, countp,
1313 		      stridep, (void *)op, NC_UINT64);
1314 }
1315 
1316 #ifdef USE_NETCDF4
1317 int
nc_put_vars_string(int ncid,int varid,const size_t * startp,const size_t * countp,const ptrdiff_t * stridep,const char ** op)1318 nc_put_vars_string(int ncid, int varid,
1319 		   const size_t *startp, const size_t *countp,
1320 		   const ptrdiff_t *stridep,
1321 		   const char**op)
1322 {
1323    NC *ncp;
1324    int stat = NC_check_id(ncid, &ncp);
1325    if(stat != NC_NOERR) return stat;
1326    return NC_put_vars(ncid, varid, startp, countp, stridep,
1327 		      (void *)op, NC_STRING);
1328 }
1329 #endif /*USE_NETCDF4*/
1330 /**\} */
1331 
1332 /** \ingroup variables
1333 Write a mapped array of values to a variable.
1334 
1335 The nc_put_varm() function will only write a variable of an
1336 atomic type; it will not write user defined types. For this
1337 function, the type of the data in memory must match the type
1338 of the variable - no data conversion is done.
1339 
1340 @deprecated Use of this family of functions is discouraged,
1341 although it will continue to be supported.
1342 The reason is the complexity of the
1343 algorithm makes its use difficult for users to properly use.
1344 
1345 \param ncid NetCDF or group ID, from a previous call to nc_open(),
1346 nc_create(), nc_def_grp(), or associated inquiry functions such as
1347 nc_inq_ncid().
1348 
1349 \param varid Variable ID
1350 
1351 \param startp Start vector with one element for each dimension to \ref
1352 specify_hyperslab.
1353 
1354 \param countp Count vector with one element for each dimension to \ref
1355 specify_hyperslab.
1356 
1357 \param stridep Stride vector with one element for each dimension to
1358 \ref specify_hyperslab.
1359 
1360 \param imapp Mapping vector with one element for each dimension to
1361 \ref specify_hyperslab.
1362 
1363 \param op Pointer where the data will be copied. Memory must be
1364 allocated by the user before this function is called.
1365 
1366 \returns ::NC_NOERR No error.
1367 \returns ::NC_ENOTVAR Variable not found.
1368 \returns ::NC_EINVALCOORDS Index exceeds dimension bound.
1369 \returns ::NC_EEDGE Start+count exceeds dimension bound.
1370 \returns ::NC_ERANGE One or more of the values are out of range.
1371 \returns ::NC_EINDEFINE Operation not allowed in define mode.
1372 \returns ::NC_EBADID Bad ncid.
1373  */
1374 /**@{*/
1375 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)1376 nc_put_varm (int ncid, int varid, const size_t *startp,
1377 	     const size_t *countp, const ptrdiff_t *stridep,
1378 	     const ptrdiff_t *imapp, const void *op)
1379 {
1380    NC *ncp;
1381    int stat = NC_NOERR;
1382 
1383    if ((stat = NC_check_id(ncid, &ncp)))
1384        return stat;
1385    return ncp->dispatch->put_varm(ncid, varid, startp, countp,
1386 				  stridep, imapp, op, NC_NAT);
1387 }
1388 
1389 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)1390 nc_put_varm_text(int ncid, int varid, const size_t *startp,
1391 		 const size_t *countp, const ptrdiff_t *stridep,
1392 		 const ptrdiff_t *imapp, const char *op)
1393 {
1394    NC *ncp;
1395    int stat = NC_check_id(ncid, &ncp);
1396    if(stat != NC_NOERR) return stat;
1397    return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1398 		      (void *)op, NC_CHAR);
1399 }
1400 
1401 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)1402 nc_put_varm_schar(int ncid, int varid,
1403 		  const size_t *startp, const size_t *countp,
1404 		  const ptrdiff_t *stridep, const ptrdiff_t *imapp,
1405 		  const signed char *op)
1406 {
1407    NC *ncp;
1408    int stat = NC_check_id(ncid, &ncp);
1409    if(stat != NC_NOERR) return stat;
1410    return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1411 		      (void *)op, NC_BYTE);
1412 }
1413 
1414 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)1415 nc_put_varm_uchar(int ncid, int varid,
1416 		  const size_t *startp, const size_t *countp,
1417 		  const ptrdiff_t *stridep, const ptrdiff_t *imapp,
1418 		  const unsigned char *op)
1419 {
1420    NC *ncp;
1421    int stat = NC_check_id(ncid, &ncp);
1422    if(stat != NC_NOERR) return stat;
1423    return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1424 		      (void *)op, T_uchar);
1425 }
1426 
1427 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)1428 nc_put_varm_short(int ncid, int varid,
1429 		  const size_t *startp, const size_t *countp,
1430 		  const ptrdiff_t *stridep, const ptrdiff_t *imapp,
1431 		  const short *op)
1432 {
1433    NC *ncp;
1434    int stat = NC_check_id(ncid, &ncp);
1435    if(stat != NC_NOERR) return stat;
1436    return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1437 		      (void *)op, NC_SHORT);
1438 }
1439 
1440 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)1441 nc_put_varm_int(int ncid, int varid,
1442 		const size_t *startp, const size_t *countp,
1443 		const ptrdiff_t *stridep, const ptrdiff_t *imapp,
1444 		const int *op)
1445 {
1446    NC *ncp;
1447    int stat = NC_check_id(ncid, &ncp);
1448    if(stat != NC_NOERR) return stat;
1449    return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1450 		      (void *)op, NC_INT);
1451 }
1452 
1453 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)1454 nc_put_varm_long(int ncid, int varid,
1455 		 const size_t *startp, const size_t *countp,
1456 		 const ptrdiff_t *stridep, const ptrdiff_t *imapp,
1457 		 const long *op)
1458 {
1459    NC *ncp;
1460    int stat = NC_check_id(ncid, &ncp);
1461    if(stat != NC_NOERR) return stat;
1462    return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1463 		      (void *)op, T_long);
1464 }
1465 
1466 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)1467 nc_put_varm_float(int ncid, int varid,
1468 		  const size_t *startp, const size_t *countp,
1469 		  const ptrdiff_t *stridep, const ptrdiff_t *imapp,
1470 		  const float *op)
1471 {
1472    NC *ncp;
1473    int stat = NC_check_id(ncid, &ncp);
1474    if(stat != NC_NOERR) return stat;
1475    return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1476 		      (void *)op, T_float);
1477 }
1478 
1479 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)1480 nc_put_varm_double(int ncid, int varid,
1481 		   const size_t *startp, const size_t *countp,
1482 		   const ptrdiff_t *stridep, const ptrdiff_t *imapp,
1483 		   const double *op)
1484 {
1485    NC *ncp;
1486    int stat = NC_check_id(ncid, &ncp);
1487    if(stat != NC_NOERR) return stat;
1488    return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1489 		      (void *)op, T_double);
1490 }
1491 
1492 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)1493 nc_put_varm_ubyte(int ncid, int varid,
1494 		  const size_t *startp, const size_t *countp,
1495 		  const ptrdiff_t *stridep, const ptrdiff_t *imapp,
1496 		  const unsigned char *op)
1497 {
1498    NC *ncp;
1499    int stat = NC_check_id(ncid, &ncp);
1500    if(stat != NC_NOERR) return stat;
1501    return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1502 		      (void *)op, T_ubyte);
1503 }
1504 
1505 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)1506 nc_put_varm_ushort(int ncid, int varid,
1507 		   const size_t *startp, const size_t *countp,
1508 		   const ptrdiff_t *stridep, const ptrdiff_t *imapp,
1509 		   const unsigned short *op)
1510 {
1511    NC *ncp;
1512    int stat = NC_check_id(ncid, &ncp);
1513    if(stat != NC_NOERR) return stat;
1514    return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1515 		      (void *)op, T_ushort);
1516 }
1517 
1518 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)1519 nc_put_varm_uint(int ncid, int varid,
1520 		 const size_t *startp, const size_t *countp,
1521 		 const ptrdiff_t *stridep, const ptrdiff_t *imapp,
1522 		 const unsigned int *op)
1523 {
1524    NC *ncp;
1525    int stat = NC_check_id(ncid, &ncp);
1526    if(stat != NC_NOERR) return stat;
1527    return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1528 		      (void *)op, T_uint);
1529 }
1530 
1531 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)1532 nc_put_varm_longlong(int ncid, int varid,
1533 		     const size_t *startp, const size_t *countp,
1534 		     const ptrdiff_t *stridep, const ptrdiff_t *imapp,
1535 		     const long long *op)
1536 {
1537    NC *ncp;
1538    int stat = NC_check_id(ncid, &ncp);
1539    if(stat != NC_NOERR) return stat;
1540    return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1541 		      (void *)op, T_longlong);
1542 }
1543 
1544 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)1545 nc_put_varm_ulonglong(int ncid, int varid,
1546 		      const size_t *startp, const size_t *countp,
1547 		      const ptrdiff_t *stridep, const ptrdiff_t *imapp,
1548 		      const unsigned long long *op)
1549 {
1550    NC *ncp;
1551    int stat = NC_check_id(ncid, &ncp);
1552    if(stat != NC_NOERR) return stat;
1553    return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1554 		      (void *)op, NC_UINT64);
1555 }
1556 
1557 #ifdef USE_NETCDF4
1558 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)1559 nc_put_varm_string(int ncid, int varid,
1560 		   const size_t *startp, const size_t *countp,
1561 		   const ptrdiff_t *stridep, const ptrdiff_t *imapp,
1562 		   const char**op)
1563 {
1564    NC *ncp;
1565    int stat = NC_check_id(ncid, &ncp);
1566    if(stat != NC_NOERR) return stat;
1567    return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1568 		      (void *)op, NC_STRING);
1569 }
1570 #endif /*USE_NETCDF4*/
1571 /**\} */
1572 
1573 
1574 /*! \} */ /*End of named group... */
1575