1 /* Do not edit this file. It is produced from the corresponding .m4 source */
2 /*
3  *	Copyright 2018, University Corporation for Atmospheric Research
4  *      See netcdf/COPYRIGHT file for copying and redistribution conditions.
5  */
6 /* $Id: putget.m4 2783 2014-10-26 05:19:35Z wkliao $ */
7 
8 #if HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11 
12 #include <string.h>
13 #include <stdlib.h>
14 #include <assert.h>
15 
16 #include "netcdf.h"
17 #include "nc3dispatch.h"
18 #include "nc3internal.h"
19 #include "ncx.h"
20 #include "fbits.h"
21 #include "onstack.h"
22 
23 #undef MIN  /* system may define MIN somewhere and complain */
24 #define MIN(mm,nn) (((mm) < (nn)) ? (mm) : (nn))
25 
26 static int
27 readNCv(const NC3_INFO* ncp, const NC_var* varp, const size_t* start,
28         const size_t nelems, void* value, const nc_type memtype);
29 static int
30 writeNCv(NC3_INFO* ncp, const NC_var* varp, const size_t* start,
31          const size_t nelems, const void* value, const nc_type memtype);
32 
33 
34 /* #define ODEBUG 1 */
35 
36 #if ODEBUG
37 #include <stdio.h>
38 /*
39  * Print the values of an array of size_t
40  */
41 void
arrayp(const char * label,size_t count,const size_t * array)42 arrayp(const char *label, size_t count, const size_t *array)
43 {
44 	(void) fprintf(stderr, "%s", label);
45 	(void) fputc('\t',stderr);
46 	for(; count > 0; count--, array++)
47 		(void) fprintf(stderr," %lu", (unsigned long)*array);
48 	(void) fputc('\n',stderr);
49 }
50 #endif /* ODEBUG */
51 
52 
53 /* Begin fill */
54 /*
55  * This is tunable parameter.
56  * It essentially controls the tradeoff between the number of times
57  * memcpy() gets called to copy the external data to fill
58  * a large buffer vs the number of times its called to
59  * prepare the external data.
60  */
61 #if	_SX
62 /* NEC SX specific optimization */
63 #define	NFILL	2048
64 #else
65 #define	NFILL	16
66 #endif
67 
68 
69 
70 /*
71  * Next 6 type specific functions
72  * Fill a some memory with the default special value.
73  * Formerly
74 NC_arrayfill()
75  */
76 static int
NC_fill_schar(void ** xpp,size_t nelems)77 NC_fill_schar(
78 	void **xpp,
79 	size_t nelems)	/* how many */
80 {
81 	schar fillp[NFILL * sizeof(double)/X_SIZEOF_CHAR];
82 
83 	assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
84 
85 	{
86 		schar *vp = fillp;	/* lower bound of area to be filled */
87 		const schar *const end = vp + nelems;
88 		while(vp < end)
89 		{
90 			*vp++ = NC_FILL_BYTE;
91 		}
92 	}
93 	return ncx_putn_schar_schar(xpp, nelems, fillp ,NULL);
94 }
95 
96 static int
NC_fill_char(void ** xpp,size_t nelems)97 NC_fill_char(
98 	void **xpp,
99 	size_t nelems)	/* how many */
100 {
101 	char fillp[NFILL * sizeof(double)/X_SIZEOF_CHAR];
102 
103 	assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
104 
105 	{
106 		char *vp = fillp;	/* lower bound of area to be filled */
107 		const char *const end = vp + nelems;
108 		while(vp < end)
109 		{
110 			*vp++ = NC_FILL_CHAR;
111 		}
112 	}
113 	return ncx_putn_char_char(xpp, nelems, fillp );
114 }
115 
116 static int
NC_fill_short(void ** xpp,size_t nelems)117 NC_fill_short(
118 	void **xpp,
119 	size_t nelems)	/* how many */
120 {
121 	short fillp[NFILL * sizeof(double)/X_SIZEOF_SHORT];
122 
123 	assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
124 
125 	{
126 		short *vp = fillp;	/* lower bound of area to be filled */
127 		const short *const end = vp + nelems;
128 		while(vp < end)
129 		{
130 			*vp++ = NC_FILL_SHORT;
131 		}
132 	}
133 	return ncx_putn_short_short(xpp, nelems, fillp ,NULL);
134 }
135 
136 
137 #if (SIZEOF_INT >= X_SIZEOF_INT)
138 static int
NC_fill_int(void ** xpp,size_t nelems)139 NC_fill_int(
140 	void **xpp,
141 	size_t nelems)	/* how many */
142 {
143 	int fillp[NFILL * sizeof(double)/X_SIZEOF_INT];
144 
145 	assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
146 
147 	{
148 		int *vp = fillp;	/* lower bound of area to be filled */
149 		const int *const end = vp + nelems;
150 		while(vp < end)
151 		{
152 			*vp++ = NC_FILL_INT;
153 		}
154 	}
155 	return ncx_putn_int_int(xpp, nelems, fillp ,NULL);
156 }
157 
158 #elif SIZEOF_LONG == X_SIZEOF_INT
159 static int
NC_fill_int(void ** xpp,size_t nelems)160 NC_fill_int(
161 	void **xpp,
162 	size_t nelems)	/* how many */
163 {
164 	long fillp[NFILL * sizeof(double)/X_SIZEOF_INT];
165 
166 	assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
167 
168 	{
169 		long *vp = fillp;	/* lower bound of area to be filled */
170 		const long *const end = vp + nelems;
171 		while(vp < end)
172 		{
173 			*vp++ = NC_FILL_INT;
174 		}
175 	}
176 	return ncx_putn_int_long(xpp, nelems, fillp ,NULL);
177 }
178 
179 #else
180 #error "NC_fill_int implementation"
181 #endif
182 
183 static int
NC_fill_float(void ** xpp,size_t nelems)184 NC_fill_float(
185 	void **xpp,
186 	size_t nelems)	/* how many */
187 {
188 	float fillp[NFILL * sizeof(double)/X_SIZEOF_FLOAT];
189 
190 	assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
191 
192 	{
193 		float *vp = fillp;	/* lower bound of area to be filled */
194 		const float *const end = vp + nelems;
195 		while(vp < end)
196 		{
197 			*vp++ = NC_FILL_FLOAT;
198 		}
199 	}
200 	return ncx_putn_float_float(xpp, nelems, fillp ,NULL);
201 }
202 
203 static int
NC_fill_double(void ** xpp,size_t nelems)204 NC_fill_double(
205 	void **xpp,
206 	size_t nelems)	/* how many */
207 {
208 	double fillp[NFILL * sizeof(double)/X_SIZEOF_DOUBLE];
209 
210 	assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
211 
212 	{
213 		double *vp = fillp;	/* lower bound of area to be filled */
214 		const double *const end = vp + nelems;
215 		while(vp < end)
216 		{
217 			*vp++ = NC_FILL_DOUBLE;
218 		}
219 	}
220 	return ncx_putn_double_double(xpp, nelems, fillp ,NULL);
221 }
222 
223 
224 static int
NC_fill_uchar(void ** xpp,size_t nelems)225 NC_fill_uchar(
226 	void **xpp,
227 	size_t nelems)	/* how many */
228 {
229 	uchar fillp[NFILL * sizeof(double)/X_SIZEOF_UBYTE];
230 
231 	assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
232 
233 	{
234 		uchar *vp = fillp;	/* lower bound of area to be filled */
235 		const uchar *const end = vp + nelems;
236 		while(vp < end)
237 		{
238 			*vp++ = NC_FILL_UBYTE;
239 		}
240 	}
241 	return ncx_putn_uchar_uchar(xpp, nelems, fillp ,NULL);
242 }
243 
244 static int
NC_fill_ushort(void ** xpp,size_t nelems)245 NC_fill_ushort(
246 	void **xpp,
247 	size_t nelems)	/* how many */
248 {
249 	ushort fillp[NFILL * sizeof(double)/X_SIZEOF_USHORT];
250 
251 	assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
252 
253 	{
254 		ushort *vp = fillp;	/* lower bound of area to be filled */
255 		const ushort *const end = vp + nelems;
256 		while(vp < end)
257 		{
258 			*vp++ = NC_FILL_USHORT;
259 		}
260 	}
261 	return ncx_putn_ushort_ushort(xpp, nelems, fillp ,NULL);
262 }
263 
264 static int
NC_fill_uint(void ** xpp,size_t nelems)265 NC_fill_uint(
266 	void **xpp,
267 	size_t nelems)	/* how many */
268 {
269 	uint fillp[NFILL * sizeof(double)/X_SIZEOF_UINT];
270 
271 	assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
272 
273 	{
274 		uint *vp = fillp;	/* lower bound of area to be filled */
275 		const uint *const end = vp + nelems;
276 		while(vp < end)
277 		{
278 			*vp++ = NC_FILL_UINT;
279 		}
280 	}
281 	return ncx_putn_uint_uint(xpp, nelems, fillp ,NULL);
282 }
283 
284 static int
NC_fill_longlong(void ** xpp,size_t nelems)285 NC_fill_longlong(
286 	void **xpp,
287 	size_t nelems)	/* how many */
288 {
289 	longlong fillp[NFILL * sizeof(double)/X_SIZEOF_LONGLONG];
290 
291 	assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
292 
293 	{
294 		longlong *vp = fillp;	/* lower bound of area to be filled */
295 		const longlong *const end = vp + nelems;
296 		while(vp < end)
297 		{
298 			*vp++ = NC_FILL_INT64;
299 		}
300 	}
301 	return ncx_putn_longlong_longlong(xpp, nelems, fillp ,NULL);
302 }
303 
304 static int
NC_fill_ulonglong(void ** xpp,size_t nelems)305 NC_fill_ulonglong(
306 	void **xpp,
307 	size_t nelems)	/* how many */
308 {
309 	ulonglong fillp[NFILL * sizeof(double)/X_SIZEOF_ULONGLONG];
310 
311 	assert(nelems <= sizeof(fillp)/sizeof(fillp[0]));
312 
313 	{
314 		ulonglong *vp = fillp;	/* lower bound of area to be filled */
315 		const ulonglong *const end = vp + nelems;
316 		while(vp < end)
317 		{
318 			*vp++ = NC_FILL_UINT64;
319 		}
320 	}
321 	return ncx_putn_ulonglong_ulonglong(xpp, nelems, fillp ,NULL);
322 }
323 
324 
325 
326 
327 /*
328  * Fill the external space for variable 'varp' values at 'recno' with
329  * the appropriate value. If 'varp' is not a record variable, fill the
330  * whole thing.  For the special case when 'varp' is the only record
331  * variable and it is of type byte, char, or short, varsize should be
332  * ncp->recsize, otherwise it should be varp->len.
333  * Formerly
334 xdr_NC_fill()
335  */
336 int
fill_NC_var(NC3_INFO * ncp,const NC_var * varp,long long varsize,size_t recno)337 fill_NC_var(NC3_INFO* ncp, const NC_var *varp, long long varsize, size_t recno)
338 {
339 	char xfillp[NFILL * X_SIZEOF_DOUBLE];
340 	const size_t step = varp->xsz;
341 	const size_t nelems = sizeof(xfillp)/step;
342 	const size_t xsz = varp->xsz * nelems;
343 	NC_attr **attrpp = NULL;
344 	off_t offset;
345 	long long remaining = varsize;
346 
347 	void *xp;
348 	int status = NC_NOERR;
349 
350 	/*
351 	 * Set up fill value
352 	 */
353 	attrpp = NC_findattr(&varp->attrs, _FillValue);
354 	if( attrpp != NULL )
355 	{
356 		/* User defined fill value */
357 		if( (*attrpp)->type != varp->type || (*attrpp)->nelems != 1 )
358 		{
359 			return NC_EBADTYPE;
360 		}
361 		else
362 		{
363 			/* Use the user defined value */
364 			char *cp = xfillp;
365 			const char *const end = &xfillp[sizeof(xfillp)];
366 
367 			assert(step <= (*attrpp)->xsz);
368 
369 			for( /*NADA*/; cp < end; cp += step)
370 			{
371 				(void) memcpy(cp, (*attrpp)->xvalue, step);
372 			}
373 		}
374 	}
375 	else
376 	{
377 		/* use the default */
378 
379 		assert(xsz % X_ALIGN == 0);
380 		assert(xsz <= sizeof(xfillp));
381 
382 		xp = xfillp;
383 
384 		switch(varp->type){
385 		case NC_BYTE :
386 			status = NC_fill_schar(&xp, nelems);
387 			break;
388 		case NC_CHAR :
389 			status = NC_fill_char(&xp, nelems);
390 			break;
391 		case NC_SHORT :
392 			status = NC_fill_short(&xp, nelems);
393 			break;
394 		case NC_INT :
395 			status = NC_fill_int(&xp, nelems);
396 			break;
397 		case NC_FLOAT :
398 			status = NC_fill_float(&xp, nelems);
399 			break;
400 		case NC_DOUBLE :
401 			status = NC_fill_double(&xp, nelems);
402 			break;
403                 case NC_UBYTE :
404                         status = NC_fill_uchar(&xp, nelems);
405                         break;
406                 case NC_USHORT :
407                         status = NC_fill_ushort(&xp, nelems);
408                         break;
409                 case NC_UINT :
410                         status = NC_fill_uint(&xp, nelems);
411                         break;
412                 case NC_INT64 :
413                         status = NC_fill_longlong(&xp, nelems);
414                         break;
415                 case NC_UINT64 :
416                         status = NC_fill_ulonglong(&xp, nelems);
417                         break;
418 		default :
419 			assert("fill_NC_var invalid type" == 0);
420 			status = NC_EBADTYPE;
421 			break;
422 		}
423 		if(status != NC_NOERR)
424 			return status;
425 
426 		assert(xp == xfillp + xsz);
427 	}
428 
429 	/*
430 	 * copyout:
431 	 * xfillp now contains 'nelems' elements of the fill value
432 	 * in external representation.
433 	 */
434 
435 	/*
436 	 * Copy it out.
437 	 */
438 
439 	offset = varp->begin;
440 	if(IS_RECVAR(varp))
441 	{
442 		offset += (off_t)ncp->recsize * recno;
443 	}
444 
445 	assert(remaining > 0);
446 	for(;;)
447 	{
448 		const size_t chunksz = MIN(remaining, ncp->chunk);
449 		size_t ii;
450 
451 		status = ncio_get(ncp->nciop, offset, chunksz,
452 				 RGN_WRITE, &xp);
453 		if(status != NC_NOERR)
454 		{
455 			return status;
456 		}
457 
458 		/*
459 		 * fill the chunksz buffer in units  of xsz
460 		 */
461 		for(ii = 0; ii < chunksz/xsz; ii++)
462 		{
463 			(void) memcpy(xp, xfillp, xsz);
464 			xp = (char *)xp + xsz;
465 		}
466 		/*
467 		 * Deal with any remainder
468 		 */
469 		{
470 			const size_t rem = chunksz % xsz;
471 			if(rem != 0)
472 			{
473 				(void) memcpy(xp, xfillp, rem);
474 				/* xp = (char *)xp + xsz; */
475 			}
476 
477 		}
478 
479 		status = ncio_rel(ncp->nciop, offset, RGN_MODIFIED);
480 
481 		if(status != NC_NOERR)
482 		{
483 			break;
484 		}
485 
486 		remaining -= chunksz;
487 		if(remaining == 0)
488 			break;	/* normal loop exit */
489 		offset += chunksz;
490 
491 	}
492 
493 	return status;
494 }
495 /* End fill */
496 
497 
498 /*
499  * Add a record containing the fill values.
500  */
501 static int
NCfillrecord(NC3_INFO * ncp,const NC_var * const * varpp,size_t recno)502 NCfillrecord(NC3_INFO* ncp, const NC_var *const *varpp, size_t recno)
503 {
504 	size_t ii = 0;
505 	for(; ii < ncp->vars.nelems; ii++, varpp++)
506 	{
507 		if( !IS_RECVAR(*varpp) )
508 		{
509 			continue;	/* skip non-record variables */
510 		}
511 		{
512 		const int status = fill_NC_var(ncp, *varpp, (*varpp)->len, recno);
513 		if(status != NC_NOERR)
514 			return status;
515 		}
516 	}
517 	return NC_NOERR;
518 }
519 
520 
521 /*
522  * Add a record containing the fill values in the special case when
523  * there is exactly one record variable, where we don't require each
524  * record to be four-byte aligned (no record padding).
525  */
526 static int
NCfillspecialrecord(NC3_INFO * ncp,const NC_var * varp,size_t recno)527 NCfillspecialrecord(NC3_INFO* ncp, const NC_var *varp, size_t recno)
528 {
529     int status;
530     assert(IS_RECVAR(varp));
531     status = fill_NC_var(ncp, varp, ncp->recsize, recno);
532     if(status != NC_NOERR)
533 	return status;
534     return NC_NOERR;
535 }
536 
537 
538 /*
539  * It is advantageous to
540  * #define TOUCH_LAST
541  * when using memory mapped io.
542  */
543 #if TOUCH_LAST
544 /*
545  * Grow the file to a size which can contain recno
546  */
547 static int
NCtouchlast(NC3_INFO * ncp,const NC_var * const * varpp,size_t recno)548 NCtouchlast(NC3_INFO* ncp, const NC_var *const *varpp, size_t recno)
549 {
550 	int status = NC_NOERR;
551 	const NC_var *varp = NULL;
552 
553 	{
554 	size_t ii = 0;
555 	for(; ii < ncp->vars.nelems; ii++, varpp++)
556 	{
557 		if( !IS_RECVAR(*varpp) )
558 		{
559 			continue;	/* skip non-record variables */
560 		}
561 		varp = *varpp;
562 	}
563 	}
564 	assert(varp != NULL);
565 	assert( IS_RECVAR(varp) );
566 	{
567 		const off_t offset = varp->begin
568 				+ (off_t)(recno-1) * (off_t)ncp->recsize
569 				+ (off_t)(varp->len - varp->xsz);
570 		void *xp;
571 
572 
573 		status = ncio_get(ncp->nciop, offset, varp->xsz,
574 				 RGN_WRITE, &xp);
575 		if(status != NC_NOERR)
576 			return status;
577 		(void)memset(xp, 0, varp->xsz);
578 		status = ncio_rel(ncp->nciop, offset, RGN_MODIFIED);
579 	}
580 	return status;
581 }
582 #endif /* TOUCH_LAST */
583 
584 
585 /*
586  * Ensure that the netcdf file has 'numrecs' records,
587  * add records and fill as necessary.
588  */
589 static int
NCvnrecs(NC3_INFO * ncp,size_t numrecs)590 NCvnrecs(NC3_INFO* ncp, size_t numrecs)
591 {
592 	int status = NC_NOERR;
593 
594 	if(numrecs > NC_get_numrecs(ncp))
595 	{
596 
597 
598 #if TOUCH_LAST
599 		status = NCtouchlast(ncp,
600 			(const NC_var *const*)ncp->vars.value,
601 			numrecs);
602 		if(status != NC_NOERR)
603 			goto common_return;
604 #endif /* TOUCH_LAST */
605 
606 		set_NC_ndirty(ncp);
607 
608 		if(!NC_dofill(ncp))
609 		{
610 			/* Simply set the new numrecs value */
611 			NC_set_numrecs(ncp, numrecs);
612 		}
613 		else
614 		{
615 		    /* Treat two cases differently:
616 		        - exactly one record variable (no padding)
617                         - multiple record variables (each record padded
618                           to 4-byte alignment)
619 		    */
620 		    NC_var **vpp = (NC_var **)ncp->vars.value;
621 		    NC_var *const *const end = &vpp[ncp->vars.nelems];
622 		    NC_var *recvarp = NULL;	/* last record var */
623 		    int numrecvars = 0;
624 		    size_t cur_nrecs;
625 
626 		    /* determine how many record variables */
627 		    for( /*NADA*/; vpp < end; vpp++) {
628 			if(IS_RECVAR(*vpp)) {
629 			    recvarp = *vpp;
630 			    numrecvars++;
631 			}
632 		    }
633 
634 		    if (numrecvars != 1) { /* usual case */
635 			/* Fill each record out to numrecs */
636 			while((cur_nrecs = NC_get_numrecs(ncp)) < numrecs)
637 			    {
638 				status = NCfillrecord(ncp,
639 					(const NC_var *const*)ncp->vars.value,
640 					cur_nrecs);
641 				if(status != NC_NOERR)
642 				{
643 					break;
644 				}
645 				NC_increase_numrecs(ncp, cur_nrecs +1);
646 			}
647 			if(status != NC_NOERR)
648 				goto common_return;
649 		    } else {	/* special case */
650 			/* Fill each record out to numrecs */
651 			while((cur_nrecs = NC_get_numrecs(ncp)) < numrecs)
652 			    {
653 				status = NCfillspecialrecord(ncp,
654 					recvarp,
655 					cur_nrecs);
656 				if(status != NC_NOERR)
657 				{
658 					break;
659 				}
660 				NC_increase_numrecs(ncp, cur_nrecs +1);
661 			}
662 			if(status != NC_NOERR)
663 				goto common_return;
664 
665 		    }
666 		}
667 
668 		if(NC_doNsync(ncp))
669 		{
670 			status = write_numrecs(ncp);
671 		}
672 
673 	}
674 common_return:
675 	return status;
676 }
677 
678 
679 /*
680  * Check whether 'coord' values are valid for the variable.
681  */
682 static int
NCcoordck(NC3_INFO * ncp,const NC_var * varp,const size_t * coord)683 NCcoordck(NC3_INFO* ncp, const NC_var *varp, const size_t *coord)
684 {
685 	const size_t *ip;
686 	size_t *up;
687 
688 	if(varp->ndims == 0)
689 		return NC_NOERR;	/* 'scalar' variable */
690 
691 	if(IS_RECVAR(varp))
692 	{
693 		if(*coord > X_UINT_MAX) /* rkr: bug fix from previous X_INT_MAX */
694 			return NC_EINVALCOORDS; /* sanity check */
695 		if(NC_readonly(ncp) && *coord > NC_get_numrecs(ncp))
696 		{
697 			if(!NC_doNsync(ncp))
698 				return NC_EINVALCOORDS;
699 			/* else */
700 			{
701 				/* Update from disk and check again */
702 				const int status = read_numrecs(ncp);
703 				if(status != NC_NOERR)
704 					return status;
705 				if(*coord > NC_get_numrecs(ncp))
706 					return NC_EINVALCOORDS;
707 			}
708 		}
709 		ip = coord + 1;
710 		up = varp->shape + 1;
711 	}
712 	else
713 	{
714 		ip = coord;
715 		up = varp->shape;
716 	}
717 
718 #ifdef CDEBUG
719 fprintf(stderr,"	NCcoordck: coord %ld, count %d, ip %ld\n",
720 		coord, varp->ndims, ip );
721 #endif /* CDEBUG */
722 
723 	for(; ip < coord + varp->ndims; ip++, up++)
724 	{
725 
726 #ifdef CDEBUG
727 fprintf(stderr,"	NCcoordck: ip %p, *ip %ld, up %p, *up %lu\n",
728 			ip, *ip, up, *up );
729 #endif /* CDEBUG */
730 
731 		/* cast needed for braindead systems with signed size_t */
732 		if((unsigned long) *ip > (unsigned long) *up )
733 			return NC_EINVALCOORDS;
734 	}
735 
736 	return NC_NOERR;
737 }
738 
739 
740 /*
741  * Check whether 'edges' are valid for the variable and 'start'
742  */
743 /*ARGSUSED*/
744 static int
NCedgeck(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,const size_t * edges)745 NCedgeck(const NC3_INFO* ncp, const NC_var *varp,
746 	 const size_t *start, const size_t *edges)
747 {
748 	const size_t *const end = start + varp->ndims;
749 	const size_t *shp = varp->shape;
750 
751 	if(varp->ndims == 0)
752 		return NC_NOERR;	/* 'scalar' variable */
753 
754 	if(IS_RECVAR(varp))
755 	{
756 		if (NC_readonly(ncp) &&
757                     (start[0] == NC_get_numrecs(ncp) && edges[0] > 0))
758 			return(NC_EINVALCOORDS);
759 		start++;
760 		edges++;
761 		shp++;
762 	}
763 
764 	for(; start < end; start++, edges++, shp++)
765 	{
766 		if ((unsigned long) *start == *shp && *edges > 0)
767 			return(NC_EINVALCOORDS);
768 		/* cast needed for braindead systems with signed size_t */
769 		if((unsigned long) *edges > *shp ||
770 			(unsigned long) *start + (unsigned long) *edges > *shp)
771 		{
772 			return(NC_EEDGE);
773 		}
774 	}
775 	return NC_NOERR;
776 }
777 
778 
779 /*
780  * Translate the (variable, coord) pair into a seek index
781  */
782 static off_t
NC_varoffset(const NC3_INFO * ncp,const NC_var * varp,const size_t * coord)783 NC_varoffset(const NC3_INFO* ncp, const NC_var *varp, const size_t *coord)
784 {
785 	if(varp->ndims == 0) /* 'scalar' variable */
786 		return varp->begin;
787 
788 	if(varp->ndims == 1)
789 	{
790 		if(IS_RECVAR(varp))
791 			return varp->begin +
792 				 (off_t)(*coord) * (off_t)ncp->recsize;
793 		/* else */
794 		return varp->begin + (off_t)(*coord) * (off_t)varp->xsz;
795 	}
796 	/* else */
797 	{
798 		off_t lcoord = (off_t)coord[varp->ndims -1];
799 
800 		off_t *up = varp->dsizes +1;
801 		const size_t *ip = coord;
802 		const off_t *const end = varp->dsizes + varp->ndims;
803 
804 		if(IS_RECVAR(varp))
805 			up++, ip++;
806 
807 		for(; up < end; up++, ip++)
808 			lcoord += (off_t)(*up) * (off_t)(*ip);
809 
810 		lcoord *= varp->xsz;
811 
812 		if(IS_RECVAR(varp))
813 			lcoord += (off_t)(*coord) * ncp->recsize;
814 
815 		lcoord += varp->begin;
816 		return lcoord;
817 	}
818 }
819 
820 
821 
822 static int
putNCvx_char_char(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const char * value)823 putNCvx_char_char(NC3_INFO* ncp, const NC_var *varp,
824 		 const size_t *start, size_t nelems, const char *value)
825 {
826 	off_t offset = NC_varoffset(ncp, varp, start);
827 	size_t remaining = varp->xsz * nelems;
828 	int status = NC_NOERR;
829 	void *xp;
830         void *fillp=NULL;
831 
832 	NC_UNUSED(fillp);
833 
834 	if(nelems == 0)
835 		return NC_NOERR;
836 
837 	assert(value != NULL);
838 
839 #ifdef ERANGE_FILL
840         fillp = malloc(varp->xsz);
841         status = NC3_inq_var_fill(varp, fillp);
842 #endif
843 
844 	for(;;)
845 	{
846 		size_t extent = MIN(remaining, ncp->chunk);
847 		size_t nput = ncx_howmany(varp->type, extent);
848 
849 		int lstatus = ncio_get(ncp->nciop, offset, extent,
850 				 RGN_WRITE, &xp);
851 		if(lstatus != NC_NOERR)
852 			return lstatus;
853 
854 		lstatus = ncx_putn_char_char(&xp, nput, value );
855 		if(lstatus != NC_NOERR && status == NC_NOERR)
856 		{
857 			/* not fatal to the loop */
858 			status = lstatus;
859 		}
860 
861 		(void) ncio_rel(ncp->nciop, offset,
862 				 RGN_MODIFIED);
863 
864 		remaining -= extent;
865 		if(remaining == 0)
866 			break; /* normal loop exit */
867 		offset += (off_t)extent;
868 		value += nput;
869 
870 	}
871 #ifdef ERANGE_FILL
872         free(fillp);
873 #endif
874 
875 	return status;
876 }
877 
878 
879 static int
putNCvx_schar_schar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const schar * value)880 putNCvx_schar_schar(NC3_INFO* ncp, const NC_var *varp,
881 		 const size_t *start, size_t nelems, const schar *value)
882 {
883 	off_t offset = NC_varoffset(ncp, varp, start);
884 	size_t remaining = varp->xsz * nelems;
885 	int status = NC_NOERR;
886 	void *xp;
887         void *fillp=NULL;
888 
889 	NC_UNUSED(fillp);
890 
891 	if(nelems == 0)
892 		return NC_NOERR;
893 
894 	assert(value != NULL);
895 
896 #ifdef ERANGE_FILL
897         fillp = malloc(varp->xsz);
898         status = NC3_inq_var_fill(varp, fillp);
899 #endif
900 
901 	for(;;)
902 	{
903 		size_t extent = MIN(remaining, ncp->chunk);
904 		size_t nput = ncx_howmany(varp->type, extent);
905 
906 		int lstatus = ncio_get(ncp->nciop, offset, extent,
907 				 RGN_WRITE, &xp);
908 		if(lstatus != NC_NOERR)
909 			return lstatus;
910 
911 		lstatus = ncx_putn_schar_schar(&xp, nput, value ,fillp);
912 		if(lstatus != NC_NOERR && status == NC_NOERR)
913 		{
914 			/* not fatal to the loop */
915 			status = lstatus;
916 		}
917 
918 		(void) ncio_rel(ncp->nciop, offset,
919 				 RGN_MODIFIED);
920 
921 		remaining -= extent;
922 		if(remaining == 0)
923 			break; /* normal loop exit */
924 		offset += (off_t)extent;
925 		value += nput;
926 
927 	}
928 #ifdef ERANGE_FILL
929         free(fillp);
930 #endif
931 
932 	return status;
933 }
934 
935 static int
putNCvx_schar_uchar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uchar * value)936 putNCvx_schar_uchar(NC3_INFO* ncp, const NC_var *varp,
937 		 const size_t *start, size_t nelems, const uchar *value)
938 {
939 	off_t offset = NC_varoffset(ncp, varp, start);
940 	size_t remaining = varp->xsz * nelems;
941 	int status = NC_NOERR;
942 	void *xp;
943         void *fillp=NULL;
944 
945 	NC_UNUSED(fillp);
946 
947 	if(nelems == 0)
948 		return NC_NOERR;
949 
950 	assert(value != NULL);
951 
952 #ifdef ERANGE_FILL
953         fillp = malloc(varp->xsz);
954         status = NC3_inq_var_fill(varp, fillp);
955 #endif
956 
957 	for(;;)
958 	{
959 		size_t extent = MIN(remaining, ncp->chunk);
960 		size_t nput = ncx_howmany(varp->type, extent);
961 
962 		int lstatus = ncio_get(ncp->nciop, offset, extent,
963 				 RGN_WRITE, &xp);
964 		if(lstatus != NC_NOERR)
965 			return lstatus;
966 
967 		lstatus = ncx_putn_schar_uchar(&xp, nput, value ,fillp);
968 		if(lstatus != NC_NOERR && status == NC_NOERR)
969 		{
970 			/* not fatal to the loop */
971 			status = lstatus;
972 		}
973 
974 		(void) ncio_rel(ncp->nciop, offset,
975 				 RGN_MODIFIED);
976 
977 		remaining -= extent;
978 		if(remaining == 0)
979 			break; /* normal loop exit */
980 		offset += (off_t)extent;
981 		value += nput;
982 
983 	}
984 #ifdef ERANGE_FILL
985         free(fillp);
986 #endif
987 
988 	return status;
989 }
990 
991 static int
putNCvx_schar_short(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const short * value)992 putNCvx_schar_short(NC3_INFO* ncp, const NC_var *varp,
993 		 const size_t *start, size_t nelems, const short *value)
994 {
995 	off_t offset = NC_varoffset(ncp, varp, start);
996 	size_t remaining = varp->xsz * nelems;
997 	int status = NC_NOERR;
998 	void *xp;
999         void *fillp=NULL;
1000 
1001 	NC_UNUSED(fillp);
1002 
1003 	if(nelems == 0)
1004 		return NC_NOERR;
1005 
1006 	assert(value != NULL);
1007 
1008 #ifdef ERANGE_FILL
1009         fillp = malloc(varp->xsz);
1010         status = NC3_inq_var_fill(varp, fillp);
1011 #endif
1012 
1013 	for(;;)
1014 	{
1015 		size_t extent = MIN(remaining, ncp->chunk);
1016 		size_t nput = ncx_howmany(varp->type, extent);
1017 
1018 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1019 				 RGN_WRITE, &xp);
1020 		if(lstatus != NC_NOERR)
1021 			return lstatus;
1022 
1023 		lstatus = ncx_putn_schar_short(&xp, nput, value ,fillp);
1024 		if(lstatus != NC_NOERR && status == NC_NOERR)
1025 		{
1026 			/* not fatal to the loop */
1027 			status = lstatus;
1028 		}
1029 
1030 		(void) ncio_rel(ncp->nciop, offset,
1031 				 RGN_MODIFIED);
1032 
1033 		remaining -= extent;
1034 		if(remaining == 0)
1035 			break; /* normal loop exit */
1036 		offset += (off_t)extent;
1037 		value += nput;
1038 
1039 	}
1040 #ifdef ERANGE_FILL
1041         free(fillp);
1042 #endif
1043 
1044 	return status;
1045 }
1046 
1047 static int
putNCvx_schar_int(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const int * value)1048 putNCvx_schar_int(NC3_INFO* ncp, const NC_var *varp,
1049 		 const size_t *start, size_t nelems, const int *value)
1050 {
1051 	off_t offset = NC_varoffset(ncp, varp, start);
1052 	size_t remaining = varp->xsz * nelems;
1053 	int status = NC_NOERR;
1054 	void *xp;
1055         void *fillp=NULL;
1056 
1057 	NC_UNUSED(fillp);
1058 
1059 	if(nelems == 0)
1060 		return NC_NOERR;
1061 
1062 	assert(value != NULL);
1063 
1064 #ifdef ERANGE_FILL
1065         fillp = malloc(varp->xsz);
1066         status = NC3_inq_var_fill(varp, fillp);
1067 #endif
1068 
1069 	for(;;)
1070 	{
1071 		size_t extent = MIN(remaining, ncp->chunk);
1072 		size_t nput = ncx_howmany(varp->type, extent);
1073 
1074 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1075 				 RGN_WRITE, &xp);
1076 		if(lstatus != NC_NOERR)
1077 			return lstatus;
1078 
1079 		lstatus = ncx_putn_schar_int(&xp, nput, value ,fillp);
1080 		if(lstatus != NC_NOERR && status == NC_NOERR)
1081 		{
1082 			/* not fatal to the loop */
1083 			status = lstatus;
1084 		}
1085 
1086 		(void) ncio_rel(ncp->nciop, offset,
1087 				 RGN_MODIFIED);
1088 
1089 		remaining -= extent;
1090 		if(remaining == 0)
1091 			break; /* normal loop exit */
1092 		offset += (off_t)extent;
1093 		value += nput;
1094 
1095 	}
1096 #ifdef ERANGE_FILL
1097         free(fillp);
1098 #endif
1099 
1100 	return status;
1101 }
1102 
1103 static int
putNCvx_schar_float(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const float * value)1104 putNCvx_schar_float(NC3_INFO* ncp, const NC_var *varp,
1105 		 const size_t *start, size_t nelems, const float *value)
1106 {
1107 	off_t offset = NC_varoffset(ncp, varp, start);
1108 	size_t remaining = varp->xsz * nelems;
1109 	int status = NC_NOERR;
1110 	void *xp;
1111         void *fillp=NULL;
1112 
1113 	NC_UNUSED(fillp);
1114 
1115 	if(nelems == 0)
1116 		return NC_NOERR;
1117 
1118 	assert(value != NULL);
1119 
1120 #ifdef ERANGE_FILL
1121         fillp = malloc(varp->xsz);
1122         status = NC3_inq_var_fill(varp, fillp);
1123 #endif
1124 
1125 	for(;;)
1126 	{
1127 		size_t extent = MIN(remaining, ncp->chunk);
1128 		size_t nput = ncx_howmany(varp->type, extent);
1129 
1130 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1131 				 RGN_WRITE, &xp);
1132 		if(lstatus != NC_NOERR)
1133 			return lstatus;
1134 
1135 		lstatus = ncx_putn_schar_float(&xp, nput, value ,fillp);
1136 		if(lstatus != NC_NOERR && status == NC_NOERR)
1137 		{
1138 			/* not fatal to the loop */
1139 			status = lstatus;
1140 		}
1141 
1142 		(void) ncio_rel(ncp->nciop, offset,
1143 				 RGN_MODIFIED);
1144 
1145 		remaining -= extent;
1146 		if(remaining == 0)
1147 			break; /* normal loop exit */
1148 		offset += (off_t)extent;
1149 		value += nput;
1150 
1151 	}
1152 #ifdef ERANGE_FILL
1153         free(fillp);
1154 #endif
1155 
1156 	return status;
1157 }
1158 
1159 static int
putNCvx_schar_double(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const double * value)1160 putNCvx_schar_double(NC3_INFO* ncp, const NC_var *varp,
1161 		 const size_t *start, size_t nelems, const double *value)
1162 {
1163 	off_t offset = NC_varoffset(ncp, varp, start);
1164 	size_t remaining = varp->xsz * nelems;
1165 	int status = NC_NOERR;
1166 	void *xp;
1167         void *fillp=NULL;
1168 
1169 	NC_UNUSED(fillp);
1170 
1171 	if(nelems == 0)
1172 		return NC_NOERR;
1173 
1174 	assert(value != NULL);
1175 
1176 #ifdef ERANGE_FILL
1177         fillp = malloc(varp->xsz);
1178         status = NC3_inq_var_fill(varp, fillp);
1179 #endif
1180 
1181 	for(;;)
1182 	{
1183 		size_t extent = MIN(remaining, ncp->chunk);
1184 		size_t nput = ncx_howmany(varp->type, extent);
1185 
1186 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1187 				 RGN_WRITE, &xp);
1188 		if(lstatus != NC_NOERR)
1189 			return lstatus;
1190 
1191 		lstatus = ncx_putn_schar_double(&xp, nput, value ,fillp);
1192 		if(lstatus != NC_NOERR && status == NC_NOERR)
1193 		{
1194 			/* not fatal to the loop */
1195 			status = lstatus;
1196 		}
1197 
1198 		(void) ncio_rel(ncp->nciop, offset,
1199 				 RGN_MODIFIED);
1200 
1201 		remaining -= extent;
1202 		if(remaining == 0)
1203 			break; /* normal loop exit */
1204 		offset += (off_t)extent;
1205 		value += nput;
1206 
1207 	}
1208 #ifdef ERANGE_FILL
1209         free(fillp);
1210 #endif
1211 
1212 	return status;
1213 }
1214 
1215 static int
putNCvx_schar_longlong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const longlong * value)1216 putNCvx_schar_longlong(NC3_INFO* ncp, const NC_var *varp,
1217 		 const size_t *start, size_t nelems, const longlong *value)
1218 {
1219 	off_t offset = NC_varoffset(ncp, varp, start);
1220 	size_t remaining = varp->xsz * nelems;
1221 	int status = NC_NOERR;
1222 	void *xp;
1223         void *fillp=NULL;
1224 
1225 	NC_UNUSED(fillp);
1226 
1227 	if(nelems == 0)
1228 		return NC_NOERR;
1229 
1230 	assert(value != NULL);
1231 
1232 #ifdef ERANGE_FILL
1233         fillp = malloc(varp->xsz);
1234         status = NC3_inq_var_fill(varp, fillp);
1235 #endif
1236 
1237 	for(;;)
1238 	{
1239 		size_t extent = MIN(remaining, ncp->chunk);
1240 		size_t nput = ncx_howmany(varp->type, extent);
1241 
1242 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1243 				 RGN_WRITE, &xp);
1244 		if(lstatus != NC_NOERR)
1245 			return lstatus;
1246 
1247 		lstatus = ncx_putn_schar_longlong(&xp, nput, value ,fillp);
1248 		if(lstatus != NC_NOERR && status == NC_NOERR)
1249 		{
1250 			/* not fatal to the loop */
1251 			status = lstatus;
1252 		}
1253 
1254 		(void) ncio_rel(ncp->nciop, offset,
1255 				 RGN_MODIFIED);
1256 
1257 		remaining -= extent;
1258 		if(remaining == 0)
1259 			break; /* normal loop exit */
1260 		offset += (off_t)extent;
1261 		value += nput;
1262 
1263 	}
1264 #ifdef ERANGE_FILL
1265         free(fillp);
1266 #endif
1267 
1268 	return status;
1269 }
1270 
1271 static int
putNCvx_schar_ushort(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ushort * value)1272 putNCvx_schar_ushort(NC3_INFO* ncp, const NC_var *varp,
1273 		 const size_t *start, size_t nelems, const ushort *value)
1274 {
1275 	off_t offset = NC_varoffset(ncp, varp, start);
1276 	size_t remaining = varp->xsz * nelems;
1277 	int status = NC_NOERR;
1278 	void *xp;
1279         void *fillp=NULL;
1280 
1281 	NC_UNUSED(fillp);
1282 
1283 	if(nelems == 0)
1284 		return NC_NOERR;
1285 
1286 	assert(value != NULL);
1287 
1288 #ifdef ERANGE_FILL
1289         fillp = malloc(varp->xsz);
1290         status = NC3_inq_var_fill(varp, fillp);
1291 #endif
1292 
1293 	for(;;)
1294 	{
1295 		size_t extent = MIN(remaining, ncp->chunk);
1296 		size_t nput = ncx_howmany(varp->type, extent);
1297 
1298 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1299 				 RGN_WRITE, &xp);
1300 		if(lstatus != NC_NOERR)
1301 			return lstatus;
1302 
1303 		lstatus = ncx_putn_schar_ushort(&xp, nput, value ,fillp);
1304 		if(lstatus != NC_NOERR && status == NC_NOERR)
1305 		{
1306 			/* not fatal to the loop */
1307 			status = lstatus;
1308 		}
1309 
1310 		(void) ncio_rel(ncp->nciop, offset,
1311 				 RGN_MODIFIED);
1312 
1313 		remaining -= extent;
1314 		if(remaining == 0)
1315 			break; /* normal loop exit */
1316 		offset += (off_t)extent;
1317 		value += nput;
1318 
1319 	}
1320 #ifdef ERANGE_FILL
1321         free(fillp);
1322 #endif
1323 
1324 	return status;
1325 }
1326 
1327 static int
putNCvx_schar_uint(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uint * value)1328 putNCvx_schar_uint(NC3_INFO* ncp, const NC_var *varp,
1329 		 const size_t *start, size_t nelems, const uint *value)
1330 {
1331 	off_t offset = NC_varoffset(ncp, varp, start);
1332 	size_t remaining = varp->xsz * nelems;
1333 	int status = NC_NOERR;
1334 	void *xp;
1335         void *fillp=NULL;
1336 
1337 	NC_UNUSED(fillp);
1338 
1339 	if(nelems == 0)
1340 		return NC_NOERR;
1341 
1342 	assert(value != NULL);
1343 
1344 #ifdef ERANGE_FILL
1345         fillp = malloc(varp->xsz);
1346         status = NC3_inq_var_fill(varp, fillp);
1347 #endif
1348 
1349 	for(;;)
1350 	{
1351 		size_t extent = MIN(remaining, ncp->chunk);
1352 		size_t nput = ncx_howmany(varp->type, extent);
1353 
1354 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1355 				 RGN_WRITE, &xp);
1356 		if(lstatus != NC_NOERR)
1357 			return lstatus;
1358 
1359 		lstatus = ncx_putn_schar_uint(&xp, nput, value ,fillp);
1360 		if(lstatus != NC_NOERR && status == NC_NOERR)
1361 		{
1362 			/* not fatal to the loop */
1363 			status = lstatus;
1364 		}
1365 
1366 		(void) ncio_rel(ncp->nciop, offset,
1367 				 RGN_MODIFIED);
1368 
1369 		remaining -= extent;
1370 		if(remaining == 0)
1371 			break; /* normal loop exit */
1372 		offset += (off_t)extent;
1373 		value += nput;
1374 
1375 	}
1376 #ifdef ERANGE_FILL
1377         free(fillp);
1378 #endif
1379 
1380 	return status;
1381 }
1382 
1383 static int
putNCvx_schar_ulonglong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ulonglong * value)1384 putNCvx_schar_ulonglong(NC3_INFO* ncp, const NC_var *varp,
1385 		 const size_t *start, size_t nelems, const ulonglong *value)
1386 {
1387 	off_t offset = NC_varoffset(ncp, varp, start);
1388 	size_t remaining = varp->xsz * nelems;
1389 	int status = NC_NOERR;
1390 	void *xp;
1391         void *fillp=NULL;
1392 
1393 	NC_UNUSED(fillp);
1394 
1395 	if(nelems == 0)
1396 		return NC_NOERR;
1397 
1398 	assert(value != NULL);
1399 
1400 #ifdef ERANGE_FILL
1401         fillp = malloc(varp->xsz);
1402         status = NC3_inq_var_fill(varp, fillp);
1403 #endif
1404 
1405 	for(;;)
1406 	{
1407 		size_t extent = MIN(remaining, ncp->chunk);
1408 		size_t nput = ncx_howmany(varp->type, extent);
1409 
1410 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1411 				 RGN_WRITE, &xp);
1412 		if(lstatus != NC_NOERR)
1413 			return lstatus;
1414 
1415 		lstatus = ncx_putn_schar_ulonglong(&xp, nput, value ,fillp);
1416 		if(lstatus != NC_NOERR && status == NC_NOERR)
1417 		{
1418 			/* not fatal to the loop */
1419 			status = lstatus;
1420 		}
1421 
1422 		(void) ncio_rel(ncp->nciop, offset,
1423 				 RGN_MODIFIED);
1424 
1425 		remaining -= extent;
1426 		if(remaining == 0)
1427 			break; /* normal loop exit */
1428 		offset += (off_t)extent;
1429 		value += nput;
1430 
1431 	}
1432 #ifdef ERANGE_FILL
1433         free(fillp);
1434 #endif
1435 
1436 	return status;
1437 }
1438 
1439 
1440 static int
putNCvx_short_schar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const schar * value)1441 putNCvx_short_schar(NC3_INFO* ncp, const NC_var *varp,
1442 		 const size_t *start, size_t nelems, const schar *value)
1443 {
1444 	off_t offset = NC_varoffset(ncp, varp, start);
1445 	size_t remaining = varp->xsz * nelems;
1446 	int status = NC_NOERR;
1447 	void *xp;
1448         void *fillp=NULL;
1449 
1450 	NC_UNUSED(fillp);
1451 
1452 	if(nelems == 0)
1453 		return NC_NOERR;
1454 
1455 	assert(value != NULL);
1456 
1457 #ifdef ERANGE_FILL
1458         fillp = malloc(varp->xsz);
1459         status = NC3_inq_var_fill(varp, fillp);
1460 #endif
1461 
1462 	for(;;)
1463 	{
1464 		size_t extent = MIN(remaining, ncp->chunk);
1465 		size_t nput = ncx_howmany(varp->type, extent);
1466 
1467 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1468 				 RGN_WRITE, &xp);
1469 		if(lstatus != NC_NOERR)
1470 			return lstatus;
1471 
1472 		lstatus = ncx_putn_short_schar(&xp, nput, value ,fillp);
1473 		if(lstatus != NC_NOERR && status == NC_NOERR)
1474 		{
1475 			/* not fatal to the loop */
1476 			status = lstatus;
1477 		}
1478 
1479 		(void) ncio_rel(ncp->nciop, offset,
1480 				 RGN_MODIFIED);
1481 
1482 		remaining -= extent;
1483 		if(remaining == 0)
1484 			break; /* normal loop exit */
1485 		offset += (off_t)extent;
1486 		value += nput;
1487 
1488 	}
1489 #ifdef ERANGE_FILL
1490         free(fillp);
1491 #endif
1492 
1493 	return status;
1494 }
1495 
1496 static int
putNCvx_short_uchar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uchar * value)1497 putNCvx_short_uchar(NC3_INFO* ncp, const NC_var *varp,
1498 		 const size_t *start, size_t nelems, const uchar *value)
1499 {
1500 	off_t offset = NC_varoffset(ncp, varp, start);
1501 	size_t remaining = varp->xsz * nelems;
1502 	int status = NC_NOERR;
1503 	void *xp;
1504         void *fillp=NULL;
1505 
1506 	NC_UNUSED(fillp);
1507 
1508 	if(nelems == 0)
1509 		return NC_NOERR;
1510 
1511 	assert(value != NULL);
1512 
1513 #ifdef ERANGE_FILL
1514         fillp = malloc(varp->xsz);
1515         status = NC3_inq_var_fill(varp, fillp);
1516 #endif
1517 
1518 	for(;;)
1519 	{
1520 		size_t extent = MIN(remaining, ncp->chunk);
1521 		size_t nput = ncx_howmany(varp->type, extent);
1522 
1523 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1524 				 RGN_WRITE, &xp);
1525 		if(lstatus != NC_NOERR)
1526 			return lstatus;
1527 
1528 		lstatus = ncx_putn_short_uchar(&xp, nput, value ,fillp);
1529 		if(lstatus != NC_NOERR && status == NC_NOERR)
1530 		{
1531 			/* not fatal to the loop */
1532 			status = lstatus;
1533 		}
1534 
1535 		(void) ncio_rel(ncp->nciop, offset,
1536 				 RGN_MODIFIED);
1537 
1538 		remaining -= extent;
1539 		if(remaining == 0)
1540 			break; /* normal loop exit */
1541 		offset += (off_t)extent;
1542 		value += nput;
1543 
1544 	}
1545 #ifdef ERANGE_FILL
1546         free(fillp);
1547 #endif
1548 
1549 	return status;
1550 }
1551 
1552 static int
putNCvx_short_short(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const short * value)1553 putNCvx_short_short(NC3_INFO* ncp, const NC_var *varp,
1554 		 const size_t *start, size_t nelems, const short *value)
1555 {
1556 	off_t offset = NC_varoffset(ncp, varp, start);
1557 	size_t remaining = varp->xsz * nelems;
1558 	int status = NC_NOERR;
1559 	void *xp;
1560         void *fillp=NULL;
1561 
1562 	NC_UNUSED(fillp);
1563 
1564 	if(nelems == 0)
1565 		return NC_NOERR;
1566 
1567 	assert(value != NULL);
1568 
1569 #ifdef ERANGE_FILL
1570         fillp = malloc(varp->xsz);
1571         status = NC3_inq_var_fill(varp, fillp);
1572 #endif
1573 
1574 	for(;;)
1575 	{
1576 		size_t extent = MIN(remaining, ncp->chunk);
1577 		size_t nput = ncx_howmany(varp->type, extent);
1578 
1579 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1580 				 RGN_WRITE, &xp);
1581 		if(lstatus != NC_NOERR)
1582 			return lstatus;
1583 
1584 		lstatus = ncx_putn_short_short(&xp, nput, value ,fillp);
1585 		if(lstatus != NC_NOERR && status == NC_NOERR)
1586 		{
1587 			/* not fatal to the loop */
1588 			status = lstatus;
1589 		}
1590 
1591 		(void) ncio_rel(ncp->nciop, offset,
1592 				 RGN_MODIFIED);
1593 
1594 		remaining -= extent;
1595 		if(remaining == 0)
1596 			break; /* normal loop exit */
1597 		offset += (off_t)extent;
1598 		value += nput;
1599 
1600 	}
1601 #ifdef ERANGE_FILL
1602         free(fillp);
1603 #endif
1604 
1605 	return status;
1606 }
1607 
1608 static int
putNCvx_short_int(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const int * value)1609 putNCvx_short_int(NC3_INFO* ncp, const NC_var *varp,
1610 		 const size_t *start, size_t nelems, const int *value)
1611 {
1612 	off_t offset = NC_varoffset(ncp, varp, start);
1613 	size_t remaining = varp->xsz * nelems;
1614 	int status = NC_NOERR;
1615 	void *xp;
1616         void *fillp=NULL;
1617 
1618 	NC_UNUSED(fillp);
1619 
1620 	if(nelems == 0)
1621 		return NC_NOERR;
1622 
1623 	assert(value != NULL);
1624 
1625 #ifdef ERANGE_FILL
1626         fillp = malloc(varp->xsz);
1627         status = NC3_inq_var_fill(varp, fillp);
1628 #endif
1629 
1630 	for(;;)
1631 	{
1632 		size_t extent = MIN(remaining, ncp->chunk);
1633 		size_t nput = ncx_howmany(varp->type, extent);
1634 
1635 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1636 				 RGN_WRITE, &xp);
1637 		if(lstatus != NC_NOERR)
1638 			return lstatus;
1639 
1640 		lstatus = ncx_putn_short_int(&xp, nput, value ,fillp);
1641 		if(lstatus != NC_NOERR && status == NC_NOERR)
1642 		{
1643 			/* not fatal to the loop */
1644 			status = lstatus;
1645 		}
1646 
1647 		(void) ncio_rel(ncp->nciop, offset,
1648 				 RGN_MODIFIED);
1649 
1650 		remaining -= extent;
1651 		if(remaining == 0)
1652 			break; /* normal loop exit */
1653 		offset += (off_t)extent;
1654 		value += nput;
1655 
1656 	}
1657 #ifdef ERANGE_FILL
1658         free(fillp);
1659 #endif
1660 
1661 	return status;
1662 }
1663 
1664 static int
putNCvx_short_float(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const float * value)1665 putNCvx_short_float(NC3_INFO* ncp, const NC_var *varp,
1666 		 const size_t *start, size_t nelems, const float *value)
1667 {
1668 	off_t offset = NC_varoffset(ncp, varp, start);
1669 	size_t remaining = varp->xsz * nelems;
1670 	int status = NC_NOERR;
1671 	void *xp;
1672         void *fillp=NULL;
1673 
1674 	NC_UNUSED(fillp);
1675 
1676 	if(nelems == 0)
1677 		return NC_NOERR;
1678 
1679 	assert(value != NULL);
1680 
1681 #ifdef ERANGE_FILL
1682         fillp = malloc(varp->xsz);
1683         status = NC3_inq_var_fill(varp, fillp);
1684 #endif
1685 
1686 	for(;;)
1687 	{
1688 		size_t extent = MIN(remaining, ncp->chunk);
1689 		size_t nput = ncx_howmany(varp->type, extent);
1690 
1691 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1692 				 RGN_WRITE, &xp);
1693 		if(lstatus != NC_NOERR)
1694 			return lstatus;
1695 
1696 		lstatus = ncx_putn_short_float(&xp, nput, value ,fillp);
1697 		if(lstatus != NC_NOERR && status == NC_NOERR)
1698 		{
1699 			/* not fatal to the loop */
1700 			status = lstatus;
1701 		}
1702 
1703 		(void) ncio_rel(ncp->nciop, offset,
1704 				 RGN_MODIFIED);
1705 
1706 		remaining -= extent;
1707 		if(remaining == 0)
1708 			break; /* normal loop exit */
1709 		offset += (off_t)extent;
1710 		value += nput;
1711 
1712 	}
1713 #ifdef ERANGE_FILL
1714         free(fillp);
1715 #endif
1716 
1717 	return status;
1718 }
1719 
1720 static int
putNCvx_short_double(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const double * value)1721 putNCvx_short_double(NC3_INFO* ncp, const NC_var *varp,
1722 		 const size_t *start, size_t nelems, const double *value)
1723 {
1724 	off_t offset = NC_varoffset(ncp, varp, start);
1725 	size_t remaining = varp->xsz * nelems;
1726 	int status = NC_NOERR;
1727 	void *xp;
1728         void *fillp=NULL;
1729 
1730 	NC_UNUSED(fillp);
1731 
1732 	if(nelems == 0)
1733 		return NC_NOERR;
1734 
1735 	assert(value != NULL);
1736 
1737 #ifdef ERANGE_FILL
1738         fillp = malloc(varp->xsz);
1739         status = NC3_inq_var_fill(varp, fillp);
1740 #endif
1741 
1742 	for(;;)
1743 	{
1744 		size_t extent = MIN(remaining, ncp->chunk);
1745 		size_t nput = ncx_howmany(varp->type, extent);
1746 
1747 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1748 				 RGN_WRITE, &xp);
1749 		if(lstatus != NC_NOERR)
1750 			return lstatus;
1751 
1752 		lstatus = ncx_putn_short_double(&xp, nput, value ,fillp);
1753 		if(lstatus != NC_NOERR && status == NC_NOERR)
1754 		{
1755 			/* not fatal to the loop */
1756 			status = lstatus;
1757 		}
1758 
1759 		(void) ncio_rel(ncp->nciop, offset,
1760 				 RGN_MODIFIED);
1761 
1762 		remaining -= extent;
1763 		if(remaining == 0)
1764 			break; /* normal loop exit */
1765 		offset += (off_t)extent;
1766 		value += nput;
1767 
1768 	}
1769 #ifdef ERANGE_FILL
1770         free(fillp);
1771 #endif
1772 
1773 	return status;
1774 }
1775 
1776 static int
putNCvx_short_longlong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const longlong * value)1777 putNCvx_short_longlong(NC3_INFO* ncp, const NC_var *varp,
1778 		 const size_t *start, size_t nelems, const longlong *value)
1779 {
1780 	off_t offset = NC_varoffset(ncp, varp, start);
1781 	size_t remaining = varp->xsz * nelems;
1782 	int status = NC_NOERR;
1783 	void *xp;
1784         void *fillp=NULL;
1785 
1786 	NC_UNUSED(fillp);
1787 
1788 	if(nelems == 0)
1789 		return NC_NOERR;
1790 
1791 	assert(value != NULL);
1792 
1793 #ifdef ERANGE_FILL
1794         fillp = malloc(varp->xsz);
1795         status = NC3_inq_var_fill(varp, fillp);
1796 #endif
1797 
1798 	for(;;)
1799 	{
1800 		size_t extent = MIN(remaining, ncp->chunk);
1801 		size_t nput = ncx_howmany(varp->type, extent);
1802 
1803 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1804 				 RGN_WRITE, &xp);
1805 		if(lstatus != NC_NOERR)
1806 			return lstatus;
1807 
1808 		lstatus = ncx_putn_short_longlong(&xp, nput, value ,fillp);
1809 		if(lstatus != NC_NOERR && status == NC_NOERR)
1810 		{
1811 			/* not fatal to the loop */
1812 			status = lstatus;
1813 		}
1814 
1815 		(void) ncio_rel(ncp->nciop, offset,
1816 				 RGN_MODIFIED);
1817 
1818 		remaining -= extent;
1819 		if(remaining == 0)
1820 			break; /* normal loop exit */
1821 		offset += (off_t)extent;
1822 		value += nput;
1823 
1824 	}
1825 #ifdef ERANGE_FILL
1826         free(fillp);
1827 #endif
1828 
1829 	return status;
1830 }
1831 
1832 static int
putNCvx_short_ushort(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ushort * value)1833 putNCvx_short_ushort(NC3_INFO* ncp, const NC_var *varp,
1834 		 const size_t *start, size_t nelems, const ushort *value)
1835 {
1836 	off_t offset = NC_varoffset(ncp, varp, start);
1837 	size_t remaining = varp->xsz * nelems;
1838 	int status = NC_NOERR;
1839 	void *xp;
1840         void *fillp=NULL;
1841 
1842 	NC_UNUSED(fillp);
1843 
1844 	if(nelems == 0)
1845 		return NC_NOERR;
1846 
1847 	assert(value != NULL);
1848 
1849 #ifdef ERANGE_FILL
1850         fillp = malloc(varp->xsz);
1851         status = NC3_inq_var_fill(varp, fillp);
1852 #endif
1853 
1854 	for(;;)
1855 	{
1856 		size_t extent = MIN(remaining, ncp->chunk);
1857 		size_t nput = ncx_howmany(varp->type, extent);
1858 
1859 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1860 				 RGN_WRITE, &xp);
1861 		if(lstatus != NC_NOERR)
1862 			return lstatus;
1863 
1864 		lstatus = ncx_putn_short_ushort(&xp, nput, value ,fillp);
1865 		if(lstatus != NC_NOERR && status == NC_NOERR)
1866 		{
1867 			/* not fatal to the loop */
1868 			status = lstatus;
1869 		}
1870 
1871 		(void) ncio_rel(ncp->nciop, offset,
1872 				 RGN_MODIFIED);
1873 
1874 		remaining -= extent;
1875 		if(remaining == 0)
1876 			break; /* normal loop exit */
1877 		offset += (off_t)extent;
1878 		value += nput;
1879 
1880 	}
1881 #ifdef ERANGE_FILL
1882         free(fillp);
1883 #endif
1884 
1885 	return status;
1886 }
1887 
1888 static int
putNCvx_short_uint(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uint * value)1889 putNCvx_short_uint(NC3_INFO* ncp, const NC_var *varp,
1890 		 const size_t *start, size_t nelems, const uint *value)
1891 {
1892 	off_t offset = NC_varoffset(ncp, varp, start);
1893 	size_t remaining = varp->xsz * nelems;
1894 	int status = NC_NOERR;
1895 	void *xp;
1896         void *fillp=NULL;
1897 
1898 	NC_UNUSED(fillp);
1899 
1900 	if(nelems == 0)
1901 		return NC_NOERR;
1902 
1903 	assert(value != NULL);
1904 
1905 #ifdef ERANGE_FILL
1906         fillp = malloc(varp->xsz);
1907         status = NC3_inq_var_fill(varp, fillp);
1908 #endif
1909 
1910 	for(;;)
1911 	{
1912 		size_t extent = MIN(remaining, ncp->chunk);
1913 		size_t nput = ncx_howmany(varp->type, extent);
1914 
1915 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1916 				 RGN_WRITE, &xp);
1917 		if(lstatus != NC_NOERR)
1918 			return lstatus;
1919 
1920 		lstatus = ncx_putn_short_uint(&xp, nput, value ,fillp);
1921 		if(lstatus != NC_NOERR && status == NC_NOERR)
1922 		{
1923 			/* not fatal to the loop */
1924 			status = lstatus;
1925 		}
1926 
1927 		(void) ncio_rel(ncp->nciop, offset,
1928 				 RGN_MODIFIED);
1929 
1930 		remaining -= extent;
1931 		if(remaining == 0)
1932 			break; /* normal loop exit */
1933 		offset += (off_t)extent;
1934 		value += nput;
1935 
1936 	}
1937 #ifdef ERANGE_FILL
1938         free(fillp);
1939 #endif
1940 
1941 	return status;
1942 }
1943 
1944 static int
putNCvx_short_ulonglong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ulonglong * value)1945 putNCvx_short_ulonglong(NC3_INFO* ncp, const NC_var *varp,
1946 		 const size_t *start, size_t nelems, const ulonglong *value)
1947 {
1948 	off_t offset = NC_varoffset(ncp, varp, start);
1949 	size_t remaining = varp->xsz * nelems;
1950 	int status = NC_NOERR;
1951 	void *xp;
1952         void *fillp=NULL;
1953 
1954 	NC_UNUSED(fillp);
1955 
1956 	if(nelems == 0)
1957 		return NC_NOERR;
1958 
1959 	assert(value != NULL);
1960 
1961 #ifdef ERANGE_FILL
1962         fillp = malloc(varp->xsz);
1963         status = NC3_inq_var_fill(varp, fillp);
1964 #endif
1965 
1966 	for(;;)
1967 	{
1968 		size_t extent = MIN(remaining, ncp->chunk);
1969 		size_t nput = ncx_howmany(varp->type, extent);
1970 
1971 		int lstatus = ncio_get(ncp->nciop, offset, extent,
1972 				 RGN_WRITE, &xp);
1973 		if(lstatus != NC_NOERR)
1974 			return lstatus;
1975 
1976 		lstatus = ncx_putn_short_ulonglong(&xp, nput, value ,fillp);
1977 		if(lstatus != NC_NOERR && status == NC_NOERR)
1978 		{
1979 			/* not fatal to the loop */
1980 			status = lstatus;
1981 		}
1982 
1983 		(void) ncio_rel(ncp->nciop, offset,
1984 				 RGN_MODIFIED);
1985 
1986 		remaining -= extent;
1987 		if(remaining == 0)
1988 			break; /* normal loop exit */
1989 		offset += (off_t)extent;
1990 		value += nput;
1991 
1992 	}
1993 #ifdef ERANGE_FILL
1994         free(fillp);
1995 #endif
1996 
1997 	return status;
1998 }
1999 
2000 
2001 static int
putNCvx_int_schar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const schar * value)2002 putNCvx_int_schar(NC3_INFO* ncp, const NC_var *varp,
2003 		 const size_t *start, size_t nelems, const schar *value)
2004 {
2005 	off_t offset = NC_varoffset(ncp, varp, start);
2006 	size_t remaining = varp->xsz * nelems;
2007 	int status = NC_NOERR;
2008 	void *xp;
2009         void *fillp=NULL;
2010 
2011 	NC_UNUSED(fillp);
2012 
2013 	if(nelems == 0)
2014 		return NC_NOERR;
2015 
2016 	assert(value != NULL);
2017 
2018 #ifdef ERANGE_FILL
2019         fillp = malloc(varp->xsz);
2020         status = NC3_inq_var_fill(varp, fillp);
2021 #endif
2022 
2023 	for(;;)
2024 	{
2025 		size_t extent = MIN(remaining, ncp->chunk);
2026 		size_t nput = ncx_howmany(varp->type, extent);
2027 
2028 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2029 				 RGN_WRITE, &xp);
2030 		if(lstatus != NC_NOERR)
2031 			return lstatus;
2032 
2033 		lstatus = ncx_putn_int_schar(&xp, nput, value ,fillp);
2034 		if(lstatus != NC_NOERR && status == NC_NOERR)
2035 		{
2036 			/* not fatal to the loop */
2037 			status = lstatus;
2038 		}
2039 
2040 		(void) ncio_rel(ncp->nciop, offset,
2041 				 RGN_MODIFIED);
2042 
2043 		remaining -= extent;
2044 		if(remaining == 0)
2045 			break; /* normal loop exit */
2046 		offset += (off_t)extent;
2047 		value += nput;
2048 
2049 	}
2050 #ifdef ERANGE_FILL
2051         free(fillp);
2052 #endif
2053 
2054 	return status;
2055 }
2056 
2057 static int
putNCvx_int_uchar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uchar * value)2058 putNCvx_int_uchar(NC3_INFO* ncp, const NC_var *varp,
2059 		 const size_t *start, size_t nelems, const uchar *value)
2060 {
2061 	off_t offset = NC_varoffset(ncp, varp, start);
2062 	size_t remaining = varp->xsz * nelems;
2063 	int status = NC_NOERR;
2064 	void *xp;
2065         void *fillp=NULL;
2066 
2067 	NC_UNUSED(fillp);
2068 
2069 	if(nelems == 0)
2070 		return NC_NOERR;
2071 
2072 	assert(value != NULL);
2073 
2074 #ifdef ERANGE_FILL
2075         fillp = malloc(varp->xsz);
2076         status = NC3_inq_var_fill(varp, fillp);
2077 #endif
2078 
2079 	for(;;)
2080 	{
2081 		size_t extent = MIN(remaining, ncp->chunk);
2082 		size_t nput = ncx_howmany(varp->type, extent);
2083 
2084 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2085 				 RGN_WRITE, &xp);
2086 		if(lstatus != NC_NOERR)
2087 			return lstatus;
2088 
2089 		lstatus = ncx_putn_int_uchar(&xp, nput, value ,fillp);
2090 		if(lstatus != NC_NOERR && status == NC_NOERR)
2091 		{
2092 			/* not fatal to the loop */
2093 			status = lstatus;
2094 		}
2095 
2096 		(void) ncio_rel(ncp->nciop, offset,
2097 				 RGN_MODIFIED);
2098 
2099 		remaining -= extent;
2100 		if(remaining == 0)
2101 			break; /* normal loop exit */
2102 		offset += (off_t)extent;
2103 		value += nput;
2104 
2105 	}
2106 #ifdef ERANGE_FILL
2107         free(fillp);
2108 #endif
2109 
2110 	return status;
2111 }
2112 
2113 static int
putNCvx_int_short(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const short * value)2114 putNCvx_int_short(NC3_INFO* ncp, const NC_var *varp,
2115 		 const size_t *start, size_t nelems, const short *value)
2116 {
2117 	off_t offset = NC_varoffset(ncp, varp, start);
2118 	size_t remaining = varp->xsz * nelems;
2119 	int status = NC_NOERR;
2120 	void *xp;
2121         void *fillp=NULL;
2122 
2123 	NC_UNUSED(fillp);
2124 
2125 	if(nelems == 0)
2126 		return NC_NOERR;
2127 
2128 	assert(value != NULL);
2129 
2130 #ifdef ERANGE_FILL
2131         fillp = malloc(varp->xsz);
2132         status = NC3_inq_var_fill(varp, fillp);
2133 #endif
2134 
2135 	for(;;)
2136 	{
2137 		size_t extent = MIN(remaining, ncp->chunk);
2138 		size_t nput = ncx_howmany(varp->type, extent);
2139 
2140 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2141 				 RGN_WRITE, &xp);
2142 		if(lstatus != NC_NOERR)
2143 			return lstatus;
2144 
2145 		lstatus = ncx_putn_int_short(&xp, nput, value ,fillp);
2146 		if(lstatus != NC_NOERR && status == NC_NOERR)
2147 		{
2148 			/* not fatal to the loop */
2149 			status = lstatus;
2150 		}
2151 
2152 		(void) ncio_rel(ncp->nciop, offset,
2153 				 RGN_MODIFIED);
2154 
2155 		remaining -= extent;
2156 		if(remaining == 0)
2157 			break; /* normal loop exit */
2158 		offset += (off_t)extent;
2159 		value += nput;
2160 
2161 	}
2162 #ifdef ERANGE_FILL
2163         free(fillp);
2164 #endif
2165 
2166 	return status;
2167 }
2168 
2169 static int
putNCvx_int_int(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const int * value)2170 putNCvx_int_int(NC3_INFO* ncp, const NC_var *varp,
2171 		 const size_t *start, size_t nelems, const int *value)
2172 {
2173 	off_t offset = NC_varoffset(ncp, varp, start);
2174 	size_t remaining = varp->xsz * nelems;
2175 	int status = NC_NOERR;
2176 	void *xp;
2177         void *fillp=NULL;
2178 
2179 	NC_UNUSED(fillp);
2180 
2181 	if(nelems == 0)
2182 		return NC_NOERR;
2183 
2184 	assert(value != NULL);
2185 
2186 #ifdef ERANGE_FILL
2187         fillp = malloc(varp->xsz);
2188         status = NC3_inq_var_fill(varp, fillp);
2189 #endif
2190 
2191 	for(;;)
2192 	{
2193 		size_t extent = MIN(remaining, ncp->chunk);
2194 		size_t nput = ncx_howmany(varp->type, extent);
2195 
2196 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2197 				 RGN_WRITE, &xp);
2198 		if(lstatus != NC_NOERR)
2199 			return lstatus;
2200 
2201 		lstatus = ncx_putn_int_int(&xp, nput, value ,fillp);
2202 		if(lstatus != NC_NOERR && status == NC_NOERR)
2203 		{
2204 			/* not fatal to the loop */
2205 			status = lstatus;
2206 		}
2207 
2208 		(void) ncio_rel(ncp->nciop, offset,
2209 				 RGN_MODIFIED);
2210 
2211 		remaining -= extent;
2212 		if(remaining == 0)
2213 			break; /* normal loop exit */
2214 		offset += (off_t)extent;
2215 		value += nput;
2216 
2217 	}
2218 #ifdef ERANGE_FILL
2219         free(fillp);
2220 #endif
2221 
2222 	return status;
2223 }
2224 
2225 static int
putNCvx_int_float(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const float * value)2226 putNCvx_int_float(NC3_INFO* ncp, const NC_var *varp,
2227 		 const size_t *start, size_t nelems, const float *value)
2228 {
2229 	off_t offset = NC_varoffset(ncp, varp, start);
2230 	size_t remaining = varp->xsz * nelems;
2231 	int status = NC_NOERR;
2232 	void *xp;
2233         void *fillp=NULL;
2234 
2235 	NC_UNUSED(fillp);
2236 
2237 	if(nelems == 0)
2238 		return NC_NOERR;
2239 
2240 	assert(value != NULL);
2241 
2242 #ifdef ERANGE_FILL
2243         fillp = malloc(varp->xsz);
2244         status = NC3_inq_var_fill(varp, fillp);
2245 #endif
2246 
2247 	for(;;)
2248 	{
2249 		size_t extent = MIN(remaining, ncp->chunk);
2250 		size_t nput = ncx_howmany(varp->type, extent);
2251 
2252 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2253 				 RGN_WRITE, &xp);
2254 		if(lstatus != NC_NOERR)
2255 			return lstatus;
2256 
2257 		lstatus = ncx_putn_int_float(&xp, nput, value ,fillp);
2258 		if(lstatus != NC_NOERR && status == NC_NOERR)
2259 		{
2260 			/* not fatal to the loop */
2261 			status = lstatus;
2262 		}
2263 
2264 		(void) ncio_rel(ncp->nciop, offset,
2265 				 RGN_MODIFIED);
2266 
2267 		remaining -= extent;
2268 		if(remaining == 0)
2269 			break; /* normal loop exit */
2270 		offset += (off_t)extent;
2271 		value += nput;
2272 
2273 	}
2274 #ifdef ERANGE_FILL
2275         free(fillp);
2276 #endif
2277 
2278 	return status;
2279 }
2280 
2281 static int
putNCvx_int_double(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const double * value)2282 putNCvx_int_double(NC3_INFO* ncp, const NC_var *varp,
2283 		 const size_t *start, size_t nelems, const double *value)
2284 {
2285 	off_t offset = NC_varoffset(ncp, varp, start);
2286 	size_t remaining = varp->xsz * nelems;
2287 	int status = NC_NOERR;
2288 	void *xp;
2289         void *fillp=NULL;
2290 
2291 	NC_UNUSED(fillp);
2292 
2293 	if(nelems == 0)
2294 		return NC_NOERR;
2295 
2296 	assert(value != NULL);
2297 
2298 #ifdef ERANGE_FILL
2299         fillp = malloc(varp->xsz);
2300         status = NC3_inq_var_fill(varp, fillp);
2301 #endif
2302 
2303 	for(;;)
2304 	{
2305 		size_t extent = MIN(remaining, ncp->chunk);
2306 		size_t nput = ncx_howmany(varp->type, extent);
2307 
2308 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2309 				 RGN_WRITE, &xp);
2310 		if(lstatus != NC_NOERR)
2311 			return lstatus;
2312 
2313 		lstatus = ncx_putn_int_double(&xp, nput, value ,fillp);
2314 		if(lstatus != NC_NOERR && status == NC_NOERR)
2315 		{
2316 			/* not fatal to the loop */
2317 			status = lstatus;
2318 		}
2319 
2320 		(void) ncio_rel(ncp->nciop, offset,
2321 				 RGN_MODIFIED);
2322 
2323 		remaining -= extent;
2324 		if(remaining == 0)
2325 			break; /* normal loop exit */
2326 		offset += (off_t)extent;
2327 		value += nput;
2328 
2329 	}
2330 #ifdef ERANGE_FILL
2331         free(fillp);
2332 #endif
2333 
2334 	return status;
2335 }
2336 
2337 static int
putNCvx_int_longlong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const longlong * value)2338 putNCvx_int_longlong(NC3_INFO* ncp, const NC_var *varp,
2339 		 const size_t *start, size_t nelems, const longlong *value)
2340 {
2341 	off_t offset = NC_varoffset(ncp, varp, start);
2342 	size_t remaining = varp->xsz * nelems;
2343 	int status = NC_NOERR;
2344 	void *xp;
2345         void *fillp=NULL;
2346 
2347 	NC_UNUSED(fillp);
2348 
2349 	if(nelems == 0)
2350 		return NC_NOERR;
2351 
2352 	assert(value != NULL);
2353 
2354 #ifdef ERANGE_FILL
2355         fillp = malloc(varp->xsz);
2356         status = NC3_inq_var_fill(varp, fillp);
2357 #endif
2358 
2359 	for(;;)
2360 	{
2361 		size_t extent = MIN(remaining, ncp->chunk);
2362 		size_t nput = ncx_howmany(varp->type, extent);
2363 
2364 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2365 				 RGN_WRITE, &xp);
2366 		if(lstatus != NC_NOERR)
2367 			return lstatus;
2368 
2369 		lstatus = ncx_putn_int_longlong(&xp, nput, value ,fillp);
2370 		if(lstatus != NC_NOERR && status == NC_NOERR)
2371 		{
2372 			/* not fatal to the loop */
2373 			status = lstatus;
2374 		}
2375 
2376 		(void) ncio_rel(ncp->nciop, offset,
2377 				 RGN_MODIFIED);
2378 
2379 		remaining -= extent;
2380 		if(remaining == 0)
2381 			break; /* normal loop exit */
2382 		offset += (off_t)extent;
2383 		value += nput;
2384 
2385 	}
2386 #ifdef ERANGE_FILL
2387         free(fillp);
2388 #endif
2389 
2390 	return status;
2391 }
2392 
2393 static int
putNCvx_int_ushort(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ushort * value)2394 putNCvx_int_ushort(NC3_INFO* ncp, const NC_var *varp,
2395 		 const size_t *start, size_t nelems, const ushort *value)
2396 {
2397 	off_t offset = NC_varoffset(ncp, varp, start);
2398 	size_t remaining = varp->xsz * nelems;
2399 	int status = NC_NOERR;
2400 	void *xp;
2401         void *fillp=NULL;
2402 
2403 	NC_UNUSED(fillp);
2404 
2405 	if(nelems == 0)
2406 		return NC_NOERR;
2407 
2408 	assert(value != NULL);
2409 
2410 #ifdef ERANGE_FILL
2411         fillp = malloc(varp->xsz);
2412         status = NC3_inq_var_fill(varp, fillp);
2413 #endif
2414 
2415 	for(;;)
2416 	{
2417 		size_t extent = MIN(remaining, ncp->chunk);
2418 		size_t nput = ncx_howmany(varp->type, extent);
2419 
2420 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2421 				 RGN_WRITE, &xp);
2422 		if(lstatus != NC_NOERR)
2423 			return lstatus;
2424 
2425 		lstatus = ncx_putn_int_ushort(&xp, nput, value ,fillp);
2426 		if(lstatus != NC_NOERR && status == NC_NOERR)
2427 		{
2428 			/* not fatal to the loop */
2429 			status = lstatus;
2430 		}
2431 
2432 		(void) ncio_rel(ncp->nciop, offset,
2433 				 RGN_MODIFIED);
2434 
2435 		remaining -= extent;
2436 		if(remaining == 0)
2437 			break; /* normal loop exit */
2438 		offset += (off_t)extent;
2439 		value += nput;
2440 
2441 	}
2442 #ifdef ERANGE_FILL
2443         free(fillp);
2444 #endif
2445 
2446 	return status;
2447 }
2448 
2449 static int
putNCvx_int_uint(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uint * value)2450 putNCvx_int_uint(NC3_INFO* ncp, const NC_var *varp,
2451 		 const size_t *start, size_t nelems, const uint *value)
2452 {
2453 	off_t offset = NC_varoffset(ncp, varp, start);
2454 	size_t remaining = varp->xsz * nelems;
2455 	int status = NC_NOERR;
2456 	void *xp;
2457         void *fillp=NULL;
2458 
2459 	NC_UNUSED(fillp);
2460 
2461 	if(nelems == 0)
2462 		return NC_NOERR;
2463 
2464 	assert(value != NULL);
2465 
2466 #ifdef ERANGE_FILL
2467         fillp = malloc(varp->xsz);
2468         status = NC3_inq_var_fill(varp, fillp);
2469 #endif
2470 
2471 	for(;;)
2472 	{
2473 		size_t extent = MIN(remaining, ncp->chunk);
2474 		size_t nput = ncx_howmany(varp->type, extent);
2475 
2476 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2477 				 RGN_WRITE, &xp);
2478 		if(lstatus != NC_NOERR)
2479 			return lstatus;
2480 
2481 		lstatus = ncx_putn_int_uint(&xp, nput, value ,fillp);
2482 		if(lstatus != NC_NOERR && status == NC_NOERR)
2483 		{
2484 			/* not fatal to the loop */
2485 			status = lstatus;
2486 		}
2487 
2488 		(void) ncio_rel(ncp->nciop, offset,
2489 				 RGN_MODIFIED);
2490 
2491 		remaining -= extent;
2492 		if(remaining == 0)
2493 			break; /* normal loop exit */
2494 		offset += (off_t)extent;
2495 		value += nput;
2496 
2497 	}
2498 #ifdef ERANGE_FILL
2499         free(fillp);
2500 #endif
2501 
2502 	return status;
2503 }
2504 
2505 static int
putNCvx_int_ulonglong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ulonglong * value)2506 putNCvx_int_ulonglong(NC3_INFO* ncp, const NC_var *varp,
2507 		 const size_t *start, size_t nelems, const ulonglong *value)
2508 {
2509 	off_t offset = NC_varoffset(ncp, varp, start);
2510 	size_t remaining = varp->xsz * nelems;
2511 	int status = NC_NOERR;
2512 	void *xp;
2513         void *fillp=NULL;
2514 
2515 	NC_UNUSED(fillp);
2516 
2517 	if(nelems == 0)
2518 		return NC_NOERR;
2519 
2520 	assert(value != NULL);
2521 
2522 #ifdef ERANGE_FILL
2523         fillp = malloc(varp->xsz);
2524         status = NC3_inq_var_fill(varp, fillp);
2525 #endif
2526 
2527 	for(;;)
2528 	{
2529 		size_t extent = MIN(remaining, ncp->chunk);
2530 		size_t nput = ncx_howmany(varp->type, extent);
2531 
2532 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2533 				 RGN_WRITE, &xp);
2534 		if(lstatus != NC_NOERR)
2535 			return lstatus;
2536 
2537 		lstatus = ncx_putn_int_ulonglong(&xp, nput, value ,fillp);
2538 		if(lstatus != NC_NOERR && status == NC_NOERR)
2539 		{
2540 			/* not fatal to the loop */
2541 			status = lstatus;
2542 		}
2543 
2544 		(void) ncio_rel(ncp->nciop, offset,
2545 				 RGN_MODIFIED);
2546 
2547 		remaining -= extent;
2548 		if(remaining == 0)
2549 			break; /* normal loop exit */
2550 		offset += (off_t)extent;
2551 		value += nput;
2552 
2553 	}
2554 #ifdef ERANGE_FILL
2555         free(fillp);
2556 #endif
2557 
2558 	return status;
2559 }
2560 
2561 
2562 static int
putNCvx_float_schar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const schar * value)2563 putNCvx_float_schar(NC3_INFO* ncp, const NC_var *varp,
2564 		 const size_t *start, size_t nelems, const schar *value)
2565 {
2566 	off_t offset = NC_varoffset(ncp, varp, start);
2567 	size_t remaining = varp->xsz * nelems;
2568 	int status = NC_NOERR;
2569 	void *xp;
2570         void *fillp=NULL;
2571 
2572 	NC_UNUSED(fillp);
2573 
2574 	if(nelems == 0)
2575 		return NC_NOERR;
2576 
2577 	assert(value != NULL);
2578 
2579 #ifdef ERANGE_FILL
2580         fillp = malloc(varp->xsz);
2581         status = NC3_inq_var_fill(varp, fillp);
2582 #endif
2583 
2584 	for(;;)
2585 	{
2586 		size_t extent = MIN(remaining, ncp->chunk);
2587 		size_t nput = ncx_howmany(varp->type, extent);
2588 
2589 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2590 				 RGN_WRITE, &xp);
2591 		if(lstatus != NC_NOERR)
2592 			return lstatus;
2593 
2594 		lstatus = ncx_putn_float_schar(&xp, nput, value ,fillp);
2595 		if(lstatus != NC_NOERR && status == NC_NOERR)
2596 		{
2597 			/* not fatal to the loop */
2598 			status = lstatus;
2599 		}
2600 
2601 		(void) ncio_rel(ncp->nciop, offset,
2602 				 RGN_MODIFIED);
2603 
2604 		remaining -= extent;
2605 		if(remaining == 0)
2606 			break; /* normal loop exit */
2607 		offset += (off_t)extent;
2608 		value += nput;
2609 
2610 	}
2611 #ifdef ERANGE_FILL
2612         free(fillp);
2613 #endif
2614 
2615 	return status;
2616 }
2617 
2618 static int
putNCvx_float_uchar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uchar * value)2619 putNCvx_float_uchar(NC3_INFO* ncp, const NC_var *varp,
2620 		 const size_t *start, size_t nelems, const uchar *value)
2621 {
2622 	off_t offset = NC_varoffset(ncp, varp, start);
2623 	size_t remaining = varp->xsz * nelems;
2624 	int status = NC_NOERR;
2625 	void *xp;
2626         void *fillp=NULL;
2627 
2628 	NC_UNUSED(fillp);
2629 
2630 	if(nelems == 0)
2631 		return NC_NOERR;
2632 
2633 	assert(value != NULL);
2634 
2635 #ifdef ERANGE_FILL
2636         fillp = malloc(varp->xsz);
2637         status = NC3_inq_var_fill(varp, fillp);
2638 #endif
2639 
2640 	for(;;)
2641 	{
2642 		size_t extent = MIN(remaining, ncp->chunk);
2643 		size_t nput = ncx_howmany(varp->type, extent);
2644 
2645 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2646 				 RGN_WRITE, &xp);
2647 		if(lstatus != NC_NOERR)
2648 			return lstatus;
2649 
2650 		lstatus = ncx_putn_float_uchar(&xp, nput, value ,fillp);
2651 		if(lstatus != NC_NOERR && status == NC_NOERR)
2652 		{
2653 			/* not fatal to the loop */
2654 			status = lstatus;
2655 		}
2656 
2657 		(void) ncio_rel(ncp->nciop, offset,
2658 				 RGN_MODIFIED);
2659 
2660 		remaining -= extent;
2661 		if(remaining == 0)
2662 			break; /* normal loop exit */
2663 		offset += (off_t)extent;
2664 		value += nput;
2665 
2666 	}
2667 #ifdef ERANGE_FILL
2668         free(fillp);
2669 #endif
2670 
2671 	return status;
2672 }
2673 
2674 static int
putNCvx_float_short(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const short * value)2675 putNCvx_float_short(NC3_INFO* ncp, const NC_var *varp,
2676 		 const size_t *start, size_t nelems, const short *value)
2677 {
2678 	off_t offset = NC_varoffset(ncp, varp, start);
2679 	size_t remaining = varp->xsz * nelems;
2680 	int status = NC_NOERR;
2681 	void *xp;
2682         void *fillp=NULL;
2683 
2684 	NC_UNUSED(fillp);
2685 
2686 	if(nelems == 0)
2687 		return NC_NOERR;
2688 
2689 	assert(value != NULL);
2690 
2691 #ifdef ERANGE_FILL
2692         fillp = malloc(varp->xsz);
2693         status = NC3_inq_var_fill(varp, fillp);
2694 #endif
2695 
2696 	for(;;)
2697 	{
2698 		size_t extent = MIN(remaining, ncp->chunk);
2699 		size_t nput = ncx_howmany(varp->type, extent);
2700 
2701 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2702 				 RGN_WRITE, &xp);
2703 		if(lstatus != NC_NOERR)
2704 			return lstatus;
2705 
2706 		lstatus = ncx_putn_float_short(&xp, nput, value ,fillp);
2707 		if(lstatus != NC_NOERR && status == NC_NOERR)
2708 		{
2709 			/* not fatal to the loop */
2710 			status = lstatus;
2711 		}
2712 
2713 		(void) ncio_rel(ncp->nciop, offset,
2714 				 RGN_MODIFIED);
2715 
2716 		remaining -= extent;
2717 		if(remaining == 0)
2718 			break; /* normal loop exit */
2719 		offset += (off_t)extent;
2720 		value += nput;
2721 
2722 	}
2723 #ifdef ERANGE_FILL
2724         free(fillp);
2725 #endif
2726 
2727 	return status;
2728 }
2729 
2730 static int
putNCvx_float_int(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const int * value)2731 putNCvx_float_int(NC3_INFO* ncp, const NC_var *varp,
2732 		 const size_t *start, size_t nelems, const int *value)
2733 {
2734 	off_t offset = NC_varoffset(ncp, varp, start);
2735 	size_t remaining = varp->xsz * nelems;
2736 	int status = NC_NOERR;
2737 	void *xp;
2738         void *fillp=NULL;
2739 
2740 	NC_UNUSED(fillp);
2741 
2742 	if(nelems == 0)
2743 		return NC_NOERR;
2744 
2745 	assert(value != NULL);
2746 
2747 #ifdef ERANGE_FILL
2748         fillp = malloc(varp->xsz);
2749         status = NC3_inq_var_fill(varp, fillp);
2750 #endif
2751 
2752 	for(;;)
2753 	{
2754 		size_t extent = MIN(remaining, ncp->chunk);
2755 		size_t nput = ncx_howmany(varp->type, extent);
2756 
2757 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2758 				 RGN_WRITE, &xp);
2759 		if(lstatus != NC_NOERR)
2760 			return lstatus;
2761 
2762 		lstatus = ncx_putn_float_int(&xp, nput, value ,fillp);
2763 		if(lstatus != NC_NOERR && status == NC_NOERR)
2764 		{
2765 			/* not fatal to the loop */
2766 			status = lstatus;
2767 		}
2768 
2769 		(void) ncio_rel(ncp->nciop, offset,
2770 				 RGN_MODIFIED);
2771 
2772 		remaining -= extent;
2773 		if(remaining == 0)
2774 			break; /* normal loop exit */
2775 		offset += (off_t)extent;
2776 		value += nput;
2777 
2778 	}
2779 #ifdef ERANGE_FILL
2780         free(fillp);
2781 #endif
2782 
2783 	return status;
2784 }
2785 
2786 static int
putNCvx_float_float(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const float * value)2787 putNCvx_float_float(NC3_INFO* ncp, const NC_var *varp,
2788 		 const size_t *start, size_t nelems, const float *value)
2789 {
2790 	off_t offset = NC_varoffset(ncp, varp, start);
2791 	size_t remaining = varp->xsz * nelems;
2792 	int status = NC_NOERR;
2793 	void *xp;
2794         void *fillp=NULL;
2795 
2796 	NC_UNUSED(fillp);
2797 
2798 	if(nelems == 0)
2799 		return NC_NOERR;
2800 
2801 	assert(value != NULL);
2802 
2803 #ifdef ERANGE_FILL
2804         fillp = malloc(varp->xsz);
2805         status = NC3_inq_var_fill(varp, fillp);
2806 #endif
2807 
2808 	for(;;)
2809 	{
2810 		size_t extent = MIN(remaining, ncp->chunk);
2811 		size_t nput = ncx_howmany(varp->type, extent);
2812 
2813 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2814 				 RGN_WRITE, &xp);
2815 		if(lstatus != NC_NOERR)
2816 			return lstatus;
2817 
2818 		lstatus = ncx_putn_float_float(&xp, nput, value ,fillp);
2819 		if(lstatus != NC_NOERR && status == NC_NOERR)
2820 		{
2821 			/* not fatal to the loop */
2822 			status = lstatus;
2823 		}
2824 
2825 		(void) ncio_rel(ncp->nciop, offset,
2826 				 RGN_MODIFIED);
2827 
2828 		remaining -= extent;
2829 		if(remaining == 0)
2830 			break; /* normal loop exit */
2831 		offset += (off_t)extent;
2832 		value += nput;
2833 
2834 	}
2835 #ifdef ERANGE_FILL
2836         free(fillp);
2837 #endif
2838 
2839 	return status;
2840 }
2841 
2842 static int
putNCvx_float_double(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const double * value)2843 putNCvx_float_double(NC3_INFO* ncp, const NC_var *varp,
2844 		 const size_t *start, size_t nelems, const double *value)
2845 {
2846 	off_t offset = NC_varoffset(ncp, varp, start);
2847 	size_t remaining = varp->xsz * nelems;
2848 	int status = NC_NOERR;
2849 	void *xp;
2850         void *fillp=NULL;
2851 
2852 	NC_UNUSED(fillp);
2853 
2854 	if(nelems == 0)
2855 		return NC_NOERR;
2856 
2857 	assert(value != NULL);
2858 
2859 #ifdef ERANGE_FILL
2860         fillp = malloc(varp->xsz);
2861         status = NC3_inq_var_fill(varp, fillp);
2862 #endif
2863 
2864 	for(;;)
2865 	{
2866 		size_t extent = MIN(remaining, ncp->chunk);
2867 		size_t nput = ncx_howmany(varp->type, extent);
2868 
2869 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2870 				 RGN_WRITE, &xp);
2871 		if(lstatus != NC_NOERR)
2872 			return lstatus;
2873 
2874 		lstatus = ncx_putn_float_double(&xp, nput, value ,fillp);
2875 		if(lstatus != NC_NOERR && status == NC_NOERR)
2876 		{
2877 			/* not fatal to the loop */
2878 			status = lstatus;
2879 		}
2880 
2881 		(void) ncio_rel(ncp->nciop, offset,
2882 				 RGN_MODIFIED);
2883 
2884 		remaining -= extent;
2885 		if(remaining == 0)
2886 			break; /* normal loop exit */
2887 		offset += (off_t)extent;
2888 		value += nput;
2889 
2890 	}
2891 #ifdef ERANGE_FILL
2892         free(fillp);
2893 #endif
2894 
2895 	return status;
2896 }
2897 
2898 static int
putNCvx_float_longlong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const longlong * value)2899 putNCvx_float_longlong(NC3_INFO* ncp, const NC_var *varp,
2900 		 const size_t *start, size_t nelems, const longlong *value)
2901 {
2902 	off_t offset = NC_varoffset(ncp, varp, start);
2903 	size_t remaining = varp->xsz * nelems;
2904 	int status = NC_NOERR;
2905 	void *xp;
2906         void *fillp=NULL;
2907 
2908 	NC_UNUSED(fillp);
2909 
2910 	if(nelems == 0)
2911 		return NC_NOERR;
2912 
2913 	assert(value != NULL);
2914 
2915 #ifdef ERANGE_FILL
2916         fillp = malloc(varp->xsz);
2917         status = NC3_inq_var_fill(varp, fillp);
2918 #endif
2919 
2920 	for(;;)
2921 	{
2922 		size_t extent = MIN(remaining, ncp->chunk);
2923 		size_t nput = ncx_howmany(varp->type, extent);
2924 
2925 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2926 				 RGN_WRITE, &xp);
2927 		if(lstatus != NC_NOERR)
2928 			return lstatus;
2929 
2930 		lstatus = ncx_putn_float_longlong(&xp, nput, value ,fillp);
2931 		if(lstatus != NC_NOERR && status == NC_NOERR)
2932 		{
2933 			/* not fatal to the loop */
2934 			status = lstatus;
2935 		}
2936 
2937 		(void) ncio_rel(ncp->nciop, offset,
2938 				 RGN_MODIFIED);
2939 
2940 		remaining -= extent;
2941 		if(remaining == 0)
2942 			break; /* normal loop exit */
2943 		offset += (off_t)extent;
2944 		value += nput;
2945 
2946 	}
2947 #ifdef ERANGE_FILL
2948         free(fillp);
2949 #endif
2950 
2951 	return status;
2952 }
2953 
2954 static int
putNCvx_float_ushort(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ushort * value)2955 putNCvx_float_ushort(NC3_INFO* ncp, const NC_var *varp,
2956 		 const size_t *start, size_t nelems, const ushort *value)
2957 {
2958 	off_t offset = NC_varoffset(ncp, varp, start);
2959 	size_t remaining = varp->xsz * nelems;
2960 	int status = NC_NOERR;
2961 	void *xp;
2962         void *fillp=NULL;
2963 
2964 	NC_UNUSED(fillp);
2965 
2966 	if(nelems == 0)
2967 		return NC_NOERR;
2968 
2969 	assert(value != NULL);
2970 
2971 #ifdef ERANGE_FILL
2972         fillp = malloc(varp->xsz);
2973         status = NC3_inq_var_fill(varp, fillp);
2974 #endif
2975 
2976 	for(;;)
2977 	{
2978 		size_t extent = MIN(remaining, ncp->chunk);
2979 		size_t nput = ncx_howmany(varp->type, extent);
2980 
2981 		int lstatus = ncio_get(ncp->nciop, offset, extent,
2982 				 RGN_WRITE, &xp);
2983 		if(lstatus != NC_NOERR)
2984 			return lstatus;
2985 
2986 		lstatus = ncx_putn_float_ushort(&xp, nput, value ,fillp);
2987 		if(lstatus != NC_NOERR && status == NC_NOERR)
2988 		{
2989 			/* not fatal to the loop */
2990 			status = lstatus;
2991 		}
2992 
2993 		(void) ncio_rel(ncp->nciop, offset,
2994 				 RGN_MODIFIED);
2995 
2996 		remaining -= extent;
2997 		if(remaining == 0)
2998 			break; /* normal loop exit */
2999 		offset += (off_t)extent;
3000 		value += nput;
3001 
3002 	}
3003 #ifdef ERANGE_FILL
3004         free(fillp);
3005 #endif
3006 
3007 	return status;
3008 }
3009 
3010 static int
putNCvx_float_uint(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uint * value)3011 putNCvx_float_uint(NC3_INFO* ncp, const NC_var *varp,
3012 		 const size_t *start, size_t nelems, const uint *value)
3013 {
3014 	off_t offset = NC_varoffset(ncp, varp, start);
3015 	size_t remaining = varp->xsz * nelems;
3016 	int status = NC_NOERR;
3017 	void *xp;
3018         void *fillp=NULL;
3019 
3020 	NC_UNUSED(fillp);
3021 
3022 	if(nelems == 0)
3023 		return NC_NOERR;
3024 
3025 	assert(value != NULL);
3026 
3027 #ifdef ERANGE_FILL
3028         fillp = malloc(varp->xsz);
3029         status = NC3_inq_var_fill(varp, fillp);
3030 #endif
3031 
3032 	for(;;)
3033 	{
3034 		size_t extent = MIN(remaining, ncp->chunk);
3035 		size_t nput = ncx_howmany(varp->type, extent);
3036 
3037 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3038 				 RGN_WRITE, &xp);
3039 		if(lstatus != NC_NOERR)
3040 			return lstatus;
3041 
3042 		lstatus = ncx_putn_float_uint(&xp, nput, value ,fillp);
3043 		if(lstatus != NC_NOERR && status == NC_NOERR)
3044 		{
3045 			/* not fatal to the loop */
3046 			status = lstatus;
3047 		}
3048 
3049 		(void) ncio_rel(ncp->nciop, offset,
3050 				 RGN_MODIFIED);
3051 
3052 		remaining -= extent;
3053 		if(remaining == 0)
3054 			break; /* normal loop exit */
3055 		offset += (off_t)extent;
3056 		value += nput;
3057 
3058 	}
3059 #ifdef ERANGE_FILL
3060         free(fillp);
3061 #endif
3062 
3063 	return status;
3064 }
3065 
3066 static int
putNCvx_float_ulonglong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ulonglong * value)3067 putNCvx_float_ulonglong(NC3_INFO* ncp, const NC_var *varp,
3068 		 const size_t *start, size_t nelems, const ulonglong *value)
3069 {
3070 	off_t offset = NC_varoffset(ncp, varp, start);
3071 	size_t remaining = varp->xsz * nelems;
3072 	int status = NC_NOERR;
3073 	void *xp;
3074         void *fillp=NULL;
3075 
3076 	NC_UNUSED(fillp);
3077 
3078 	if(nelems == 0)
3079 		return NC_NOERR;
3080 
3081 	assert(value != NULL);
3082 
3083 #ifdef ERANGE_FILL
3084         fillp = malloc(varp->xsz);
3085         status = NC3_inq_var_fill(varp, fillp);
3086 #endif
3087 
3088 	for(;;)
3089 	{
3090 		size_t extent = MIN(remaining, ncp->chunk);
3091 		size_t nput = ncx_howmany(varp->type, extent);
3092 
3093 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3094 				 RGN_WRITE, &xp);
3095 		if(lstatus != NC_NOERR)
3096 			return lstatus;
3097 
3098 		lstatus = ncx_putn_float_ulonglong(&xp, nput, value ,fillp);
3099 		if(lstatus != NC_NOERR && status == NC_NOERR)
3100 		{
3101 			/* not fatal to the loop */
3102 			status = lstatus;
3103 		}
3104 
3105 		(void) ncio_rel(ncp->nciop, offset,
3106 				 RGN_MODIFIED);
3107 
3108 		remaining -= extent;
3109 		if(remaining == 0)
3110 			break; /* normal loop exit */
3111 		offset += (off_t)extent;
3112 		value += nput;
3113 
3114 	}
3115 #ifdef ERANGE_FILL
3116         free(fillp);
3117 #endif
3118 
3119 	return status;
3120 }
3121 
3122 
3123 static int
putNCvx_double_schar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const schar * value)3124 putNCvx_double_schar(NC3_INFO* ncp, const NC_var *varp,
3125 		 const size_t *start, size_t nelems, const schar *value)
3126 {
3127 	off_t offset = NC_varoffset(ncp, varp, start);
3128 	size_t remaining = varp->xsz * nelems;
3129 	int status = NC_NOERR;
3130 	void *xp;
3131         void *fillp=NULL;
3132 
3133 	NC_UNUSED(fillp);
3134 
3135 	if(nelems == 0)
3136 		return NC_NOERR;
3137 
3138 	assert(value != NULL);
3139 
3140 #ifdef ERANGE_FILL
3141         fillp = malloc(varp->xsz);
3142         status = NC3_inq_var_fill(varp, fillp);
3143 #endif
3144 
3145 	for(;;)
3146 	{
3147 		size_t extent = MIN(remaining, ncp->chunk);
3148 		size_t nput = ncx_howmany(varp->type, extent);
3149 
3150 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3151 				 RGN_WRITE, &xp);
3152 		if(lstatus != NC_NOERR)
3153 			return lstatus;
3154 
3155 		lstatus = ncx_putn_double_schar(&xp, nput, value ,fillp);
3156 		if(lstatus != NC_NOERR && status == NC_NOERR)
3157 		{
3158 			/* not fatal to the loop */
3159 			status = lstatus;
3160 		}
3161 
3162 		(void) ncio_rel(ncp->nciop, offset,
3163 				 RGN_MODIFIED);
3164 
3165 		remaining -= extent;
3166 		if(remaining == 0)
3167 			break; /* normal loop exit */
3168 		offset += (off_t)extent;
3169 		value += nput;
3170 
3171 	}
3172 #ifdef ERANGE_FILL
3173         free(fillp);
3174 #endif
3175 
3176 	return status;
3177 }
3178 
3179 static int
putNCvx_double_uchar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uchar * value)3180 putNCvx_double_uchar(NC3_INFO* ncp, const NC_var *varp,
3181 		 const size_t *start, size_t nelems, const uchar *value)
3182 {
3183 	off_t offset = NC_varoffset(ncp, varp, start);
3184 	size_t remaining = varp->xsz * nelems;
3185 	int status = NC_NOERR;
3186 	void *xp;
3187         void *fillp=NULL;
3188 
3189 	NC_UNUSED(fillp);
3190 
3191 	if(nelems == 0)
3192 		return NC_NOERR;
3193 
3194 	assert(value != NULL);
3195 
3196 #ifdef ERANGE_FILL
3197         fillp = malloc(varp->xsz);
3198         status = NC3_inq_var_fill(varp, fillp);
3199 #endif
3200 
3201 	for(;;)
3202 	{
3203 		size_t extent = MIN(remaining, ncp->chunk);
3204 		size_t nput = ncx_howmany(varp->type, extent);
3205 
3206 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3207 				 RGN_WRITE, &xp);
3208 		if(lstatus != NC_NOERR)
3209 			return lstatus;
3210 
3211 		lstatus = ncx_putn_double_uchar(&xp, nput, value ,fillp);
3212 		if(lstatus != NC_NOERR && status == NC_NOERR)
3213 		{
3214 			/* not fatal to the loop */
3215 			status = lstatus;
3216 		}
3217 
3218 		(void) ncio_rel(ncp->nciop, offset,
3219 				 RGN_MODIFIED);
3220 
3221 		remaining -= extent;
3222 		if(remaining == 0)
3223 			break; /* normal loop exit */
3224 		offset += (off_t)extent;
3225 		value += nput;
3226 
3227 	}
3228 #ifdef ERANGE_FILL
3229         free(fillp);
3230 #endif
3231 
3232 	return status;
3233 }
3234 
3235 static int
putNCvx_double_short(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const short * value)3236 putNCvx_double_short(NC3_INFO* ncp, const NC_var *varp,
3237 		 const size_t *start, size_t nelems, const short *value)
3238 {
3239 	off_t offset = NC_varoffset(ncp, varp, start);
3240 	size_t remaining = varp->xsz * nelems;
3241 	int status = NC_NOERR;
3242 	void *xp;
3243         void *fillp=NULL;
3244 
3245 	NC_UNUSED(fillp);
3246 
3247 	if(nelems == 0)
3248 		return NC_NOERR;
3249 
3250 	assert(value != NULL);
3251 
3252 #ifdef ERANGE_FILL
3253         fillp = malloc(varp->xsz);
3254         status = NC3_inq_var_fill(varp, fillp);
3255 #endif
3256 
3257 	for(;;)
3258 	{
3259 		size_t extent = MIN(remaining, ncp->chunk);
3260 		size_t nput = ncx_howmany(varp->type, extent);
3261 
3262 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3263 				 RGN_WRITE, &xp);
3264 		if(lstatus != NC_NOERR)
3265 			return lstatus;
3266 
3267 		lstatus = ncx_putn_double_short(&xp, nput, value ,fillp);
3268 		if(lstatus != NC_NOERR && status == NC_NOERR)
3269 		{
3270 			/* not fatal to the loop */
3271 			status = lstatus;
3272 		}
3273 
3274 		(void) ncio_rel(ncp->nciop, offset,
3275 				 RGN_MODIFIED);
3276 
3277 		remaining -= extent;
3278 		if(remaining == 0)
3279 			break; /* normal loop exit */
3280 		offset += (off_t)extent;
3281 		value += nput;
3282 
3283 	}
3284 #ifdef ERANGE_FILL
3285         free(fillp);
3286 #endif
3287 
3288 	return status;
3289 }
3290 
3291 static int
putNCvx_double_int(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const int * value)3292 putNCvx_double_int(NC3_INFO* ncp, const NC_var *varp,
3293 		 const size_t *start, size_t nelems, const int *value)
3294 {
3295 	off_t offset = NC_varoffset(ncp, varp, start);
3296 	size_t remaining = varp->xsz * nelems;
3297 	int status = NC_NOERR;
3298 	void *xp;
3299         void *fillp=NULL;
3300 
3301 	NC_UNUSED(fillp);
3302 
3303 	if(nelems == 0)
3304 		return NC_NOERR;
3305 
3306 	assert(value != NULL);
3307 
3308 #ifdef ERANGE_FILL
3309         fillp = malloc(varp->xsz);
3310         status = NC3_inq_var_fill(varp, fillp);
3311 #endif
3312 
3313 	for(;;)
3314 	{
3315 		size_t extent = MIN(remaining, ncp->chunk);
3316 		size_t nput = ncx_howmany(varp->type, extent);
3317 
3318 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3319 				 RGN_WRITE, &xp);
3320 		if(lstatus != NC_NOERR)
3321 			return lstatus;
3322 
3323 		lstatus = ncx_putn_double_int(&xp, nput, value ,fillp);
3324 		if(lstatus != NC_NOERR && status == NC_NOERR)
3325 		{
3326 			/* not fatal to the loop */
3327 			status = lstatus;
3328 		}
3329 
3330 		(void) ncio_rel(ncp->nciop, offset,
3331 				 RGN_MODIFIED);
3332 
3333 		remaining -= extent;
3334 		if(remaining == 0)
3335 			break; /* normal loop exit */
3336 		offset += (off_t)extent;
3337 		value += nput;
3338 
3339 	}
3340 #ifdef ERANGE_FILL
3341         free(fillp);
3342 #endif
3343 
3344 	return status;
3345 }
3346 
3347 static int
putNCvx_double_float(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const float * value)3348 putNCvx_double_float(NC3_INFO* ncp, const NC_var *varp,
3349 		 const size_t *start, size_t nelems, const float *value)
3350 {
3351 	off_t offset = NC_varoffset(ncp, varp, start);
3352 	size_t remaining = varp->xsz * nelems;
3353 	int status = NC_NOERR;
3354 	void *xp;
3355         void *fillp=NULL;
3356 
3357 	NC_UNUSED(fillp);
3358 
3359 	if(nelems == 0)
3360 		return NC_NOERR;
3361 
3362 	assert(value != NULL);
3363 
3364 #ifdef ERANGE_FILL
3365         fillp = malloc(varp->xsz);
3366         status = NC3_inq_var_fill(varp, fillp);
3367 #endif
3368 
3369 	for(;;)
3370 	{
3371 		size_t extent = MIN(remaining, ncp->chunk);
3372 		size_t nput = ncx_howmany(varp->type, extent);
3373 
3374 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3375 				 RGN_WRITE, &xp);
3376 		if(lstatus != NC_NOERR)
3377 			return lstatus;
3378 
3379 		lstatus = ncx_putn_double_float(&xp, nput, value ,fillp);
3380 		if(lstatus != NC_NOERR && status == NC_NOERR)
3381 		{
3382 			/* not fatal to the loop */
3383 			status = lstatus;
3384 		}
3385 
3386 		(void) ncio_rel(ncp->nciop, offset,
3387 				 RGN_MODIFIED);
3388 
3389 		remaining -= extent;
3390 		if(remaining == 0)
3391 			break; /* normal loop exit */
3392 		offset += (off_t)extent;
3393 		value += nput;
3394 
3395 	}
3396 #ifdef ERANGE_FILL
3397         free(fillp);
3398 #endif
3399 
3400 	return status;
3401 }
3402 
3403 static int
putNCvx_double_double(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const double * value)3404 putNCvx_double_double(NC3_INFO* ncp, const NC_var *varp,
3405 		 const size_t *start, size_t nelems, const double *value)
3406 {
3407 	off_t offset = NC_varoffset(ncp, varp, start);
3408 	size_t remaining = varp->xsz * nelems;
3409 	int status = NC_NOERR;
3410 	void *xp;
3411         void *fillp=NULL;
3412 
3413 	NC_UNUSED(fillp);
3414 
3415 	if(nelems == 0)
3416 		return NC_NOERR;
3417 
3418 	assert(value != NULL);
3419 
3420 #ifdef ERANGE_FILL
3421         fillp = malloc(varp->xsz);
3422         status = NC3_inq_var_fill(varp, fillp);
3423 #endif
3424 
3425 	for(;;)
3426 	{
3427 		size_t extent = MIN(remaining, ncp->chunk);
3428 		size_t nput = ncx_howmany(varp->type, extent);
3429 
3430 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3431 				 RGN_WRITE, &xp);
3432 		if(lstatus != NC_NOERR)
3433 			return lstatus;
3434 
3435 		lstatus = ncx_putn_double_double(&xp, nput, value ,fillp);
3436 		if(lstatus != NC_NOERR && status == NC_NOERR)
3437 		{
3438 			/* not fatal to the loop */
3439 			status = lstatus;
3440 		}
3441 
3442 		(void) ncio_rel(ncp->nciop, offset,
3443 				 RGN_MODIFIED);
3444 
3445 		remaining -= extent;
3446 		if(remaining == 0)
3447 			break; /* normal loop exit */
3448 		offset += (off_t)extent;
3449 		value += nput;
3450 
3451 	}
3452 #ifdef ERANGE_FILL
3453         free(fillp);
3454 #endif
3455 
3456 	return status;
3457 }
3458 
3459 static int
putNCvx_double_longlong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const longlong * value)3460 putNCvx_double_longlong(NC3_INFO* ncp, const NC_var *varp,
3461 		 const size_t *start, size_t nelems, const longlong *value)
3462 {
3463 	off_t offset = NC_varoffset(ncp, varp, start);
3464 	size_t remaining = varp->xsz * nelems;
3465 	int status = NC_NOERR;
3466 	void *xp;
3467         void *fillp=NULL;
3468 
3469 	NC_UNUSED(fillp);
3470 
3471 	if(nelems == 0)
3472 		return NC_NOERR;
3473 
3474 	assert(value != NULL);
3475 
3476 #ifdef ERANGE_FILL
3477         fillp = malloc(varp->xsz);
3478         status = NC3_inq_var_fill(varp, fillp);
3479 #endif
3480 
3481 	for(;;)
3482 	{
3483 		size_t extent = MIN(remaining, ncp->chunk);
3484 		size_t nput = ncx_howmany(varp->type, extent);
3485 
3486 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3487 				 RGN_WRITE, &xp);
3488 		if(lstatus != NC_NOERR)
3489 			return lstatus;
3490 
3491 		lstatus = ncx_putn_double_longlong(&xp, nput, value ,fillp);
3492 		if(lstatus != NC_NOERR && status == NC_NOERR)
3493 		{
3494 			/* not fatal to the loop */
3495 			status = lstatus;
3496 		}
3497 
3498 		(void) ncio_rel(ncp->nciop, offset,
3499 				 RGN_MODIFIED);
3500 
3501 		remaining -= extent;
3502 		if(remaining == 0)
3503 			break; /* normal loop exit */
3504 		offset += (off_t)extent;
3505 		value += nput;
3506 
3507 	}
3508 #ifdef ERANGE_FILL
3509         free(fillp);
3510 #endif
3511 
3512 	return status;
3513 }
3514 
3515 static int
putNCvx_double_ushort(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ushort * value)3516 putNCvx_double_ushort(NC3_INFO* ncp, const NC_var *varp,
3517 		 const size_t *start, size_t nelems, const ushort *value)
3518 {
3519 	off_t offset = NC_varoffset(ncp, varp, start);
3520 	size_t remaining = varp->xsz * nelems;
3521 	int status = NC_NOERR;
3522 	void *xp;
3523         void *fillp=NULL;
3524 
3525 	NC_UNUSED(fillp);
3526 
3527 	if(nelems == 0)
3528 		return NC_NOERR;
3529 
3530 	assert(value != NULL);
3531 
3532 #ifdef ERANGE_FILL
3533         fillp = malloc(varp->xsz);
3534         status = NC3_inq_var_fill(varp, fillp);
3535 #endif
3536 
3537 	for(;;)
3538 	{
3539 		size_t extent = MIN(remaining, ncp->chunk);
3540 		size_t nput = ncx_howmany(varp->type, extent);
3541 
3542 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3543 				 RGN_WRITE, &xp);
3544 		if(lstatus != NC_NOERR)
3545 			return lstatus;
3546 
3547 		lstatus = ncx_putn_double_ushort(&xp, nput, value ,fillp);
3548 		if(lstatus != NC_NOERR && status == NC_NOERR)
3549 		{
3550 			/* not fatal to the loop */
3551 			status = lstatus;
3552 		}
3553 
3554 		(void) ncio_rel(ncp->nciop, offset,
3555 				 RGN_MODIFIED);
3556 
3557 		remaining -= extent;
3558 		if(remaining == 0)
3559 			break; /* normal loop exit */
3560 		offset += (off_t)extent;
3561 		value += nput;
3562 
3563 	}
3564 #ifdef ERANGE_FILL
3565         free(fillp);
3566 #endif
3567 
3568 	return status;
3569 }
3570 
3571 static int
putNCvx_double_uint(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uint * value)3572 putNCvx_double_uint(NC3_INFO* ncp, const NC_var *varp,
3573 		 const size_t *start, size_t nelems, const uint *value)
3574 {
3575 	off_t offset = NC_varoffset(ncp, varp, start);
3576 	size_t remaining = varp->xsz * nelems;
3577 	int status = NC_NOERR;
3578 	void *xp;
3579         void *fillp=NULL;
3580 
3581 	NC_UNUSED(fillp);
3582 
3583 	if(nelems == 0)
3584 		return NC_NOERR;
3585 
3586 	assert(value != NULL);
3587 
3588 #ifdef ERANGE_FILL
3589         fillp = malloc(varp->xsz);
3590         status = NC3_inq_var_fill(varp, fillp);
3591 #endif
3592 
3593 	for(;;)
3594 	{
3595 		size_t extent = MIN(remaining, ncp->chunk);
3596 		size_t nput = ncx_howmany(varp->type, extent);
3597 
3598 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3599 				 RGN_WRITE, &xp);
3600 		if(lstatus != NC_NOERR)
3601 			return lstatus;
3602 
3603 		lstatus = ncx_putn_double_uint(&xp, nput, value ,fillp);
3604 		if(lstatus != NC_NOERR && status == NC_NOERR)
3605 		{
3606 			/* not fatal to the loop */
3607 			status = lstatus;
3608 		}
3609 
3610 		(void) ncio_rel(ncp->nciop, offset,
3611 				 RGN_MODIFIED);
3612 
3613 		remaining -= extent;
3614 		if(remaining == 0)
3615 			break; /* normal loop exit */
3616 		offset += (off_t)extent;
3617 		value += nput;
3618 
3619 	}
3620 #ifdef ERANGE_FILL
3621         free(fillp);
3622 #endif
3623 
3624 	return status;
3625 }
3626 
3627 static int
putNCvx_double_ulonglong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ulonglong * value)3628 putNCvx_double_ulonglong(NC3_INFO* ncp, const NC_var *varp,
3629 		 const size_t *start, size_t nelems, const ulonglong *value)
3630 {
3631 	off_t offset = NC_varoffset(ncp, varp, start);
3632 	size_t remaining = varp->xsz * nelems;
3633 	int status = NC_NOERR;
3634 	void *xp;
3635         void *fillp=NULL;
3636 
3637 	NC_UNUSED(fillp);
3638 
3639 	if(nelems == 0)
3640 		return NC_NOERR;
3641 
3642 	assert(value != NULL);
3643 
3644 #ifdef ERANGE_FILL
3645         fillp = malloc(varp->xsz);
3646         status = NC3_inq_var_fill(varp, fillp);
3647 #endif
3648 
3649 	for(;;)
3650 	{
3651 		size_t extent = MIN(remaining, ncp->chunk);
3652 		size_t nput = ncx_howmany(varp->type, extent);
3653 
3654 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3655 				 RGN_WRITE, &xp);
3656 		if(lstatus != NC_NOERR)
3657 			return lstatus;
3658 
3659 		lstatus = ncx_putn_double_ulonglong(&xp, nput, value ,fillp);
3660 		if(lstatus != NC_NOERR && status == NC_NOERR)
3661 		{
3662 			/* not fatal to the loop */
3663 			status = lstatus;
3664 		}
3665 
3666 		(void) ncio_rel(ncp->nciop, offset,
3667 				 RGN_MODIFIED);
3668 
3669 		remaining -= extent;
3670 		if(remaining == 0)
3671 			break; /* normal loop exit */
3672 		offset += (off_t)extent;
3673 		value += nput;
3674 
3675 	}
3676 #ifdef ERANGE_FILL
3677         free(fillp);
3678 #endif
3679 
3680 	return status;
3681 }
3682 
3683 
3684 static int
putNCvx_uchar_schar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const schar * value)3685 putNCvx_uchar_schar(NC3_INFO* ncp, const NC_var *varp,
3686 		 const size_t *start, size_t nelems, const schar *value)
3687 {
3688 	off_t offset = NC_varoffset(ncp, varp, start);
3689 	size_t remaining = varp->xsz * nelems;
3690 	int status = NC_NOERR;
3691 	void *xp;
3692         void *fillp=NULL;
3693 
3694 	NC_UNUSED(fillp);
3695 
3696 	if(nelems == 0)
3697 		return NC_NOERR;
3698 
3699 	assert(value != NULL);
3700 
3701 #ifdef ERANGE_FILL
3702         fillp = malloc(varp->xsz);
3703         status = NC3_inq_var_fill(varp, fillp);
3704 #endif
3705 
3706 	for(;;)
3707 	{
3708 		size_t extent = MIN(remaining, ncp->chunk);
3709 		size_t nput = ncx_howmany(varp->type, extent);
3710 
3711 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3712 				 RGN_WRITE, &xp);
3713 		if(lstatus != NC_NOERR)
3714 			return lstatus;
3715 
3716 		lstatus = ncx_putn_uchar_schar(&xp, nput, value ,fillp);
3717 		if(lstatus != NC_NOERR && status == NC_NOERR)
3718 		{
3719 			/* not fatal to the loop */
3720 			status = lstatus;
3721 		}
3722 
3723 		(void) ncio_rel(ncp->nciop, offset,
3724 				 RGN_MODIFIED);
3725 
3726 		remaining -= extent;
3727 		if(remaining == 0)
3728 			break; /* normal loop exit */
3729 		offset += (off_t)extent;
3730 		value += nput;
3731 
3732 	}
3733 #ifdef ERANGE_FILL
3734         free(fillp);
3735 #endif
3736 
3737 	return status;
3738 }
3739 
3740 static int
putNCvx_uchar_uchar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uchar * value)3741 putNCvx_uchar_uchar(NC3_INFO* ncp, const NC_var *varp,
3742 		 const size_t *start, size_t nelems, const uchar *value)
3743 {
3744 	off_t offset = NC_varoffset(ncp, varp, start);
3745 	size_t remaining = varp->xsz * nelems;
3746 	int status = NC_NOERR;
3747 	void *xp;
3748         void *fillp=NULL;
3749 
3750 	NC_UNUSED(fillp);
3751 
3752 	if(nelems == 0)
3753 		return NC_NOERR;
3754 
3755 	assert(value != NULL);
3756 
3757 #ifdef ERANGE_FILL
3758         fillp = malloc(varp->xsz);
3759         status = NC3_inq_var_fill(varp, fillp);
3760 #endif
3761 
3762 	for(;;)
3763 	{
3764 		size_t extent = MIN(remaining, ncp->chunk);
3765 		size_t nput = ncx_howmany(varp->type, extent);
3766 
3767 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3768 				 RGN_WRITE, &xp);
3769 		if(lstatus != NC_NOERR)
3770 			return lstatus;
3771 
3772 		lstatus = ncx_putn_uchar_uchar(&xp, nput, value ,fillp);
3773 		if(lstatus != NC_NOERR && status == NC_NOERR)
3774 		{
3775 			/* not fatal to the loop */
3776 			status = lstatus;
3777 		}
3778 
3779 		(void) ncio_rel(ncp->nciop, offset,
3780 				 RGN_MODIFIED);
3781 
3782 		remaining -= extent;
3783 		if(remaining == 0)
3784 			break; /* normal loop exit */
3785 		offset += (off_t)extent;
3786 		value += nput;
3787 
3788 	}
3789 #ifdef ERANGE_FILL
3790         free(fillp);
3791 #endif
3792 
3793 	return status;
3794 }
3795 
3796 static int
putNCvx_uchar_short(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const short * value)3797 putNCvx_uchar_short(NC3_INFO* ncp, const NC_var *varp,
3798 		 const size_t *start, size_t nelems, const short *value)
3799 {
3800 	off_t offset = NC_varoffset(ncp, varp, start);
3801 	size_t remaining = varp->xsz * nelems;
3802 	int status = NC_NOERR;
3803 	void *xp;
3804         void *fillp=NULL;
3805 
3806 	NC_UNUSED(fillp);
3807 
3808 	if(nelems == 0)
3809 		return NC_NOERR;
3810 
3811 	assert(value != NULL);
3812 
3813 #ifdef ERANGE_FILL
3814         fillp = malloc(varp->xsz);
3815         status = NC3_inq_var_fill(varp, fillp);
3816 #endif
3817 
3818 	for(;;)
3819 	{
3820 		size_t extent = MIN(remaining, ncp->chunk);
3821 		size_t nput = ncx_howmany(varp->type, extent);
3822 
3823 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3824 				 RGN_WRITE, &xp);
3825 		if(lstatus != NC_NOERR)
3826 			return lstatus;
3827 
3828 		lstatus = ncx_putn_uchar_short(&xp, nput, value ,fillp);
3829 		if(lstatus != NC_NOERR && status == NC_NOERR)
3830 		{
3831 			/* not fatal to the loop */
3832 			status = lstatus;
3833 		}
3834 
3835 		(void) ncio_rel(ncp->nciop, offset,
3836 				 RGN_MODIFIED);
3837 
3838 		remaining -= extent;
3839 		if(remaining == 0)
3840 			break; /* normal loop exit */
3841 		offset += (off_t)extent;
3842 		value += nput;
3843 
3844 	}
3845 #ifdef ERANGE_FILL
3846         free(fillp);
3847 #endif
3848 
3849 	return status;
3850 }
3851 
3852 static int
putNCvx_uchar_int(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const int * value)3853 putNCvx_uchar_int(NC3_INFO* ncp, const NC_var *varp,
3854 		 const size_t *start, size_t nelems, const int *value)
3855 {
3856 	off_t offset = NC_varoffset(ncp, varp, start);
3857 	size_t remaining = varp->xsz * nelems;
3858 	int status = NC_NOERR;
3859 	void *xp;
3860         void *fillp=NULL;
3861 
3862 	NC_UNUSED(fillp);
3863 
3864 	if(nelems == 0)
3865 		return NC_NOERR;
3866 
3867 	assert(value != NULL);
3868 
3869 #ifdef ERANGE_FILL
3870         fillp = malloc(varp->xsz);
3871         status = NC3_inq_var_fill(varp, fillp);
3872 #endif
3873 
3874 	for(;;)
3875 	{
3876 		size_t extent = MIN(remaining, ncp->chunk);
3877 		size_t nput = ncx_howmany(varp->type, extent);
3878 
3879 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3880 				 RGN_WRITE, &xp);
3881 		if(lstatus != NC_NOERR)
3882 			return lstatus;
3883 
3884 		lstatus = ncx_putn_uchar_int(&xp, nput, value ,fillp);
3885 		if(lstatus != NC_NOERR && status == NC_NOERR)
3886 		{
3887 			/* not fatal to the loop */
3888 			status = lstatus;
3889 		}
3890 
3891 		(void) ncio_rel(ncp->nciop, offset,
3892 				 RGN_MODIFIED);
3893 
3894 		remaining -= extent;
3895 		if(remaining == 0)
3896 			break; /* normal loop exit */
3897 		offset += (off_t)extent;
3898 		value += nput;
3899 
3900 	}
3901 #ifdef ERANGE_FILL
3902         free(fillp);
3903 #endif
3904 
3905 	return status;
3906 }
3907 
3908 static int
putNCvx_uchar_float(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const float * value)3909 putNCvx_uchar_float(NC3_INFO* ncp, const NC_var *varp,
3910 		 const size_t *start, size_t nelems, const float *value)
3911 {
3912 	off_t offset = NC_varoffset(ncp, varp, start);
3913 	size_t remaining = varp->xsz * nelems;
3914 	int status = NC_NOERR;
3915 	void *xp;
3916         void *fillp=NULL;
3917 
3918 	NC_UNUSED(fillp);
3919 
3920 	if(nelems == 0)
3921 		return NC_NOERR;
3922 
3923 	assert(value != NULL);
3924 
3925 #ifdef ERANGE_FILL
3926         fillp = malloc(varp->xsz);
3927         status = NC3_inq_var_fill(varp, fillp);
3928 #endif
3929 
3930 	for(;;)
3931 	{
3932 		size_t extent = MIN(remaining, ncp->chunk);
3933 		size_t nput = ncx_howmany(varp->type, extent);
3934 
3935 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3936 				 RGN_WRITE, &xp);
3937 		if(lstatus != NC_NOERR)
3938 			return lstatus;
3939 
3940 		lstatus = ncx_putn_uchar_float(&xp, nput, value ,fillp);
3941 		if(lstatus != NC_NOERR && status == NC_NOERR)
3942 		{
3943 			/* not fatal to the loop */
3944 			status = lstatus;
3945 		}
3946 
3947 		(void) ncio_rel(ncp->nciop, offset,
3948 				 RGN_MODIFIED);
3949 
3950 		remaining -= extent;
3951 		if(remaining == 0)
3952 			break; /* normal loop exit */
3953 		offset += (off_t)extent;
3954 		value += nput;
3955 
3956 	}
3957 #ifdef ERANGE_FILL
3958         free(fillp);
3959 #endif
3960 
3961 	return status;
3962 }
3963 
3964 static int
putNCvx_uchar_double(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const double * value)3965 putNCvx_uchar_double(NC3_INFO* ncp, const NC_var *varp,
3966 		 const size_t *start, size_t nelems, const double *value)
3967 {
3968 	off_t offset = NC_varoffset(ncp, varp, start);
3969 	size_t remaining = varp->xsz * nelems;
3970 	int status = NC_NOERR;
3971 	void *xp;
3972         void *fillp=NULL;
3973 
3974 	NC_UNUSED(fillp);
3975 
3976 	if(nelems == 0)
3977 		return NC_NOERR;
3978 
3979 	assert(value != NULL);
3980 
3981 #ifdef ERANGE_FILL
3982         fillp = malloc(varp->xsz);
3983         status = NC3_inq_var_fill(varp, fillp);
3984 #endif
3985 
3986 	for(;;)
3987 	{
3988 		size_t extent = MIN(remaining, ncp->chunk);
3989 		size_t nput = ncx_howmany(varp->type, extent);
3990 
3991 		int lstatus = ncio_get(ncp->nciop, offset, extent,
3992 				 RGN_WRITE, &xp);
3993 		if(lstatus != NC_NOERR)
3994 			return lstatus;
3995 
3996 		lstatus = ncx_putn_uchar_double(&xp, nput, value ,fillp);
3997 		if(lstatus != NC_NOERR && status == NC_NOERR)
3998 		{
3999 			/* not fatal to the loop */
4000 			status = lstatus;
4001 		}
4002 
4003 		(void) ncio_rel(ncp->nciop, offset,
4004 				 RGN_MODIFIED);
4005 
4006 		remaining -= extent;
4007 		if(remaining == 0)
4008 			break; /* normal loop exit */
4009 		offset += (off_t)extent;
4010 		value += nput;
4011 
4012 	}
4013 #ifdef ERANGE_FILL
4014         free(fillp);
4015 #endif
4016 
4017 	return status;
4018 }
4019 
4020 static int
putNCvx_uchar_longlong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const longlong * value)4021 putNCvx_uchar_longlong(NC3_INFO* ncp, const NC_var *varp,
4022 		 const size_t *start, size_t nelems, const longlong *value)
4023 {
4024 	off_t offset = NC_varoffset(ncp, varp, start);
4025 	size_t remaining = varp->xsz * nelems;
4026 	int status = NC_NOERR;
4027 	void *xp;
4028         void *fillp=NULL;
4029 
4030 	NC_UNUSED(fillp);
4031 
4032 	if(nelems == 0)
4033 		return NC_NOERR;
4034 
4035 	assert(value != NULL);
4036 
4037 #ifdef ERANGE_FILL
4038         fillp = malloc(varp->xsz);
4039         status = NC3_inq_var_fill(varp, fillp);
4040 #endif
4041 
4042 	for(;;)
4043 	{
4044 		size_t extent = MIN(remaining, ncp->chunk);
4045 		size_t nput = ncx_howmany(varp->type, extent);
4046 
4047 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4048 				 RGN_WRITE, &xp);
4049 		if(lstatus != NC_NOERR)
4050 			return lstatus;
4051 
4052 		lstatus = ncx_putn_uchar_longlong(&xp, nput, value ,fillp);
4053 		if(lstatus != NC_NOERR && status == NC_NOERR)
4054 		{
4055 			/* not fatal to the loop */
4056 			status = lstatus;
4057 		}
4058 
4059 		(void) ncio_rel(ncp->nciop, offset,
4060 				 RGN_MODIFIED);
4061 
4062 		remaining -= extent;
4063 		if(remaining == 0)
4064 			break; /* normal loop exit */
4065 		offset += (off_t)extent;
4066 		value += nput;
4067 
4068 	}
4069 #ifdef ERANGE_FILL
4070         free(fillp);
4071 #endif
4072 
4073 	return status;
4074 }
4075 
4076 static int
putNCvx_uchar_ushort(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ushort * value)4077 putNCvx_uchar_ushort(NC3_INFO* ncp, const NC_var *varp,
4078 		 const size_t *start, size_t nelems, const ushort *value)
4079 {
4080 	off_t offset = NC_varoffset(ncp, varp, start);
4081 	size_t remaining = varp->xsz * nelems;
4082 	int status = NC_NOERR;
4083 	void *xp;
4084         void *fillp=NULL;
4085 
4086 	NC_UNUSED(fillp);
4087 
4088 	if(nelems == 0)
4089 		return NC_NOERR;
4090 
4091 	assert(value != NULL);
4092 
4093 #ifdef ERANGE_FILL
4094         fillp = malloc(varp->xsz);
4095         status = NC3_inq_var_fill(varp, fillp);
4096 #endif
4097 
4098 	for(;;)
4099 	{
4100 		size_t extent = MIN(remaining, ncp->chunk);
4101 		size_t nput = ncx_howmany(varp->type, extent);
4102 
4103 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4104 				 RGN_WRITE, &xp);
4105 		if(lstatus != NC_NOERR)
4106 			return lstatus;
4107 
4108 		lstatus = ncx_putn_uchar_ushort(&xp, nput, value ,fillp);
4109 		if(lstatus != NC_NOERR && status == NC_NOERR)
4110 		{
4111 			/* not fatal to the loop */
4112 			status = lstatus;
4113 		}
4114 
4115 		(void) ncio_rel(ncp->nciop, offset,
4116 				 RGN_MODIFIED);
4117 
4118 		remaining -= extent;
4119 		if(remaining == 0)
4120 			break; /* normal loop exit */
4121 		offset += (off_t)extent;
4122 		value += nput;
4123 
4124 	}
4125 #ifdef ERANGE_FILL
4126         free(fillp);
4127 #endif
4128 
4129 	return status;
4130 }
4131 
4132 static int
putNCvx_uchar_uint(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uint * value)4133 putNCvx_uchar_uint(NC3_INFO* ncp, const NC_var *varp,
4134 		 const size_t *start, size_t nelems, const uint *value)
4135 {
4136 	off_t offset = NC_varoffset(ncp, varp, start);
4137 	size_t remaining = varp->xsz * nelems;
4138 	int status = NC_NOERR;
4139 	void *xp;
4140         void *fillp=NULL;
4141 
4142 	NC_UNUSED(fillp);
4143 
4144 	if(nelems == 0)
4145 		return NC_NOERR;
4146 
4147 	assert(value != NULL);
4148 
4149 #ifdef ERANGE_FILL
4150         fillp = malloc(varp->xsz);
4151         status = NC3_inq_var_fill(varp, fillp);
4152 #endif
4153 
4154 	for(;;)
4155 	{
4156 		size_t extent = MIN(remaining, ncp->chunk);
4157 		size_t nput = ncx_howmany(varp->type, extent);
4158 
4159 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4160 				 RGN_WRITE, &xp);
4161 		if(lstatus != NC_NOERR)
4162 			return lstatus;
4163 
4164 		lstatus = ncx_putn_uchar_uint(&xp, nput, value ,fillp);
4165 		if(lstatus != NC_NOERR && status == NC_NOERR)
4166 		{
4167 			/* not fatal to the loop */
4168 			status = lstatus;
4169 		}
4170 
4171 		(void) ncio_rel(ncp->nciop, offset,
4172 				 RGN_MODIFIED);
4173 
4174 		remaining -= extent;
4175 		if(remaining == 0)
4176 			break; /* normal loop exit */
4177 		offset += (off_t)extent;
4178 		value += nput;
4179 
4180 	}
4181 #ifdef ERANGE_FILL
4182         free(fillp);
4183 #endif
4184 
4185 	return status;
4186 }
4187 
4188 static int
putNCvx_uchar_ulonglong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ulonglong * value)4189 putNCvx_uchar_ulonglong(NC3_INFO* ncp, const NC_var *varp,
4190 		 const size_t *start, size_t nelems, const ulonglong *value)
4191 {
4192 	off_t offset = NC_varoffset(ncp, varp, start);
4193 	size_t remaining = varp->xsz * nelems;
4194 	int status = NC_NOERR;
4195 	void *xp;
4196         void *fillp=NULL;
4197 
4198 	NC_UNUSED(fillp);
4199 
4200 	if(nelems == 0)
4201 		return NC_NOERR;
4202 
4203 	assert(value != NULL);
4204 
4205 #ifdef ERANGE_FILL
4206         fillp = malloc(varp->xsz);
4207         status = NC3_inq_var_fill(varp, fillp);
4208 #endif
4209 
4210 	for(;;)
4211 	{
4212 		size_t extent = MIN(remaining, ncp->chunk);
4213 		size_t nput = ncx_howmany(varp->type, extent);
4214 
4215 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4216 				 RGN_WRITE, &xp);
4217 		if(lstatus != NC_NOERR)
4218 			return lstatus;
4219 
4220 		lstatus = ncx_putn_uchar_ulonglong(&xp, nput, value ,fillp);
4221 		if(lstatus != NC_NOERR && status == NC_NOERR)
4222 		{
4223 			/* not fatal to the loop */
4224 			status = lstatus;
4225 		}
4226 
4227 		(void) ncio_rel(ncp->nciop, offset,
4228 				 RGN_MODIFIED);
4229 
4230 		remaining -= extent;
4231 		if(remaining == 0)
4232 			break; /* normal loop exit */
4233 		offset += (off_t)extent;
4234 		value += nput;
4235 
4236 	}
4237 #ifdef ERANGE_FILL
4238         free(fillp);
4239 #endif
4240 
4241 	return status;
4242 }
4243 
4244 
4245 static int
putNCvx_ushort_schar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const schar * value)4246 putNCvx_ushort_schar(NC3_INFO* ncp, const NC_var *varp,
4247 		 const size_t *start, size_t nelems, const schar *value)
4248 {
4249 	off_t offset = NC_varoffset(ncp, varp, start);
4250 	size_t remaining = varp->xsz * nelems;
4251 	int status = NC_NOERR;
4252 	void *xp;
4253         void *fillp=NULL;
4254 
4255 	NC_UNUSED(fillp);
4256 
4257 	if(nelems == 0)
4258 		return NC_NOERR;
4259 
4260 	assert(value != NULL);
4261 
4262 #ifdef ERANGE_FILL
4263         fillp = malloc(varp->xsz);
4264         status = NC3_inq_var_fill(varp, fillp);
4265 #endif
4266 
4267 	for(;;)
4268 	{
4269 		size_t extent = MIN(remaining, ncp->chunk);
4270 		size_t nput = ncx_howmany(varp->type, extent);
4271 
4272 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4273 				 RGN_WRITE, &xp);
4274 		if(lstatus != NC_NOERR)
4275 			return lstatus;
4276 
4277 		lstatus = ncx_putn_ushort_schar(&xp, nput, value ,fillp);
4278 		if(lstatus != NC_NOERR && status == NC_NOERR)
4279 		{
4280 			/* not fatal to the loop */
4281 			status = lstatus;
4282 		}
4283 
4284 		(void) ncio_rel(ncp->nciop, offset,
4285 				 RGN_MODIFIED);
4286 
4287 		remaining -= extent;
4288 		if(remaining == 0)
4289 			break; /* normal loop exit */
4290 		offset += (off_t)extent;
4291 		value += nput;
4292 
4293 	}
4294 #ifdef ERANGE_FILL
4295         free(fillp);
4296 #endif
4297 
4298 	return status;
4299 }
4300 
4301 static int
putNCvx_ushort_uchar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uchar * value)4302 putNCvx_ushort_uchar(NC3_INFO* ncp, const NC_var *varp,
4303 		 const size_t *start, size_t nelems, const uchar *value)
4304 {
4305 	off_t offset = NC_varoffset(ncp, varp, start);
4306 	size_t remaining = varp->xsz * nelems;
4307 	int status = NC_NOERR;
4308 	void *xp;
4309         void *fillp=NULL;
4310 
4311 	NC_UNUSED(fillp);
4312 
4313 	if(nelems == 0)
4314 		return NC_NOERR;
4315 
4316 	assert(value != NULL);
4317 
4318 #ifdef ERANGE_FILL
4319         fillp = malloc(varp->xsz);
4320         status = NC3_inq_var_fill(varp, fillp);
4321 #endif
4322 
4323 	for(;;)
4324 	{
4325 		size_t extent = MIN(remaining, ncp->chunk);
4326 		size_t nput = ncx_howmany(varp->type, extent);
4327 
4328 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4329 				 RGN_WRITE, &xp);
4330 		if(lstatus != NC_NOERR)
4331 			return lstatus;
4332 
4333 		lstatus = ncx_putn_ushort_uchar(&xp, nput, value ,fillp);
4334 		if(lstatus != NC_NOERR && status == NC_NOERR)
4335 		{
4336 			/* not fatal to the loop */
4337 			status = lstatus;
4338 		}
4339 
4340 		(void) ncio_rel(ncp->nciop, offset,
4341 				 RGN_MODIFIED);
4342 
4343 		remaining -= extent;
4344 		if(remaining == 0)
4345 			break; /* normal loop exit */
4346 		offset += (off_t)extent;
4347 		value += nput;
4348 
4349 	}
4350 #ifdef ERANGE_FILL
4351         free(fillp);
4352 #endif
4353 
4354 	return status;
4355 }
4356 
4357 static int
putNCvx_ushort_short(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const short * value)4358 putNCvx_ushort_short(NC3_INFO* ncp, const NC_var *varp,
4359 		 const size_t *start, size_t nelems, const short *value)
4360 {
4361 	off_t offset = NC_varoffset(ncp, varp, start);
4362 	size_t remaining = varp->xsz * nelems;
4363 	int status = NC_NOERR;
4364 	void *xp;
4365         void *fillp=NULL;
4366 
4367 	NC_UNUSED(fillp);
4368 
4369 	if(nelems == 0)
4370 		return NC_NOERR;
4371 
4372 	assert(value != NULL);
4373 
4374 #ifdef ERANGE_FILL
4375         fillp = malloc(varp->xsz);
4376         status = NC3_inq_var_fill(varp, fillp);
4377 #endif
4378 
4379 	for(;;)
4380 	{
4381 		size_t extent = MIN(remaining, ncp->chunk);
4382 		size_t nput = ncx_howmany(varp->type, extent);
4383 
4384 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4385 				 RGN_WRITE, &xp);
4386 		if(lstatus != NC_NOERR)
4387 			return lstatus;
4388 
4389 		lstatus = ncx_putn_ushort_short(&xp, nput, value ,fillp);
4390 		if(lstatus != NC_NOERR && status == NC_NOERR)
4391 		{
4392 			/* not fatal to the loop */
4393 			status = lstatus;
4394 		}
4395 
4396 		(void) ncio_rel(ncp->nciop, offset,
4397 				 RGN_MODIFIED);
4398 
4399 		remaining -= extent;
4400 		if(remaining == 0)
4401 			break; /* normal loop exit */
4402 		offset += (off_t)extent;
4403 		value += nput;
4404 
4405 	}
4406 #ifdef ERANGE_FILL
4407         free(fillp);
4408 #endif
4409 
4410 	return status;
4411 }
4412 
4413 static int
putNCvx_ushort_int(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const int * value)4414 putNCvx_ushort_int(NC3_INFO* ncp, const NC_var *varp,
4415 		 const size_t *start, size_t nelems, const int *value)
4416 {
4417 	off_t offset = NC_varoffset(ncp, varp, start);
4418 	size_t remaining = varp->xsz * nelems;
4419 	int status = NC_NOERR;
4420 	void *xp;
4421         void *fillp=NULL;
4422 
4423 	NC_UNUSED(fillp);
4424 
4425 	if(nelems == 0)
4426 		return NC_NOERR;
4427 
4428 	assert(value != NULL);
4429 
4430 #ifdef ERANGE_FILL
4431         fillp = malloc(varp->xsz);
4432         status = NC3_inq_var_fill(varp, fillp);
4433 #endif
4434 
4435 	for(;;)
4436 	{
4437 		size_t extent = MIN(remaining, ncp->chunk);
4438 		size_t nput = ncx_howmany(varp->type, extent);
4439 
4440 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4441 				 RGN_WRITE, &xp);
4442 		if(lstatus != NC_NOERR)
4443 			return lstatus;
4444 
4445 		lstatus = ncx_putn_ushort_int(&xp, nput, value ,fillp);
4446 		if(lstatus != NC_NOERR && status == NC_NOERR)
4447 		{
4448 			/* not fatal to the loop */
4449 			status = lstatus;
4450 		}
4451 
4452 		(void) ncio_rel(ncp->nciop, offset,
4453 				 RGN_MODIFIED);
4454 
4455 		remaining -= extent;
4456 		if(remaining == 0)
4457 			break; /* normal loop exit */
4458 		offset += (off_t)extent;
4459 		value += nput;
4460 
4461 	}
4462 #ifdef ERANGE_FILL
4463         free(fillp);
4464 #endif
4465 
4466 	return status;
4467 }
4468 
4469 static int
putNCvx_ushort_float(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const float * value)4470 putNCvx_ushort_float(NC3_INFO* ncp, const NC_var *varp,
4471 		 const size_t *start, size_t nelems, const float *value)
4472 {
4473 	off_t offset = NC_varoffset(ncp, varp, start);
4474 	size_t remaining = varp->xsz * nelems;
4475 	int status = NC_NOERR;
4476 	void *xp;
4477         void *fillp=NULL;
4478 
4479 	NC_UNUSED(fillp);
4480 
4481 	if(nelems == 0)
4482 		return NC_NOERR;
4483 
4484 	assert(value != NULL);
4485 
4486 #ifdef ERANGE_FILL
4487         fillp = malloc(varp->xsz);
4488         status = NC3_inq_var_fill(varp, fillp);
4489 #endif
4490 
4491 	for(;;)
4492 	{
4493 		size_t extent = MIN(remaining, ncp->chunk);
4494 		size_t nput = ncx_howmany(varp->type, extent);
4495 
4496 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4497 				 RGN_WRITE, &xp);
4498 		if(lstatus != NC_NOERR)
4499 			return lstatus;
4500 
4501 		lstatus = ncx_putn_ushort_float(&xp, nput, value ,fillp);
4502 		if(lstatus != NC_NOERR && status == NC_NOERR)
4503 		{
4504 			/* not fatal to the loop */
4505 			status = lstatus;
4506 		}
4507 
4508 		(void) ncio_rel(ncp->nciop, offset,
4509 				 RGN_MODIFIED);
4510 
4511 		remaining -= extent;
4512 		if(remaining == 0)
4513 			break; /* normal loop exit */
4514 		offset += (off_t)extent;
4515 		value += nput;
4516 
4517 	}
4518 #ifdef ERANGE_FILL
4519         free(fillp);
4520 #endif
4521 
4522 	return status;
4523 }
4524 
4525 static int
putNCvx_ushort_double(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const double * value)4526 putNCvx_ushort_double(NC3_INFO* ncp, const NC_var *varp,
4527 		 const size_t *start, size_t nelems, const double *value)
4528 {
4529 	off_t offset = NC_varoffset(ncp, varp, start);
4530 	size_t remaining = varp->xsz * nelems;
4531 	int status = NC_NOERR;
4532 	void *xp;
4533         void *fillp=NULL;
4534 
4535 	NC_UNUSED(fillp);
4536 
4537 	if(nelems == 0)
4538 		return NC_NOERR;
4539 
4540 	assert(value != NULL);
4541 
4542 #ifdef ERANGE_FILL
4543         fillp = malloc(varp->xsz);
4544         status = NC3_inq_var_fill(varp, fillp);
4545 #endif
4546 
4547 	for(;;)
4548 	{
4549 		size_t extent = MIN(remaining, ncp->chunk);
4550 		size_t nput = ncx_howmany(varp->type, extent);
4551 
4552 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4553 				 RGN_WRITE, &xp);
4554 		if(lstatus != NC_NOERR)
4555 			return lstatus;
4556 
4557 		lstatus = ncx_putn_ushort_double(&xp, nput, value ,fillp);
4558 		if(lstatus != NC_NOERR && status == NC_NOERR)
4559 		{
4560 			/* not fatal to the loop */
4561 			status = lstatus;
4562 		}
4563 
4564 		(void) ncio_rel(ncp->nciop, offset,
4565 				 RGN_MODIFIED);
4566 
4567 		remaining -= extent;
4568 		if(remaining == 0)
4569 			break; /* normal loop exit */
4570 		offset += (off_t)extent;
4571 		value += nput;
4572 
4573 	}
4574 #ifdef ERANGE_FILL
4575         free(fillp);
4576 #endif
4577 
4578 	return status;
4579 }
4580 
4581 static int
putNCvx_ushort_longlong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const longlong * value)4582 putNCvx_ushort_longlong(NC3_INFO* ncp, const NC_var *varp,
4583 		 const size_t *start, size_t nelems, const longlong *value)
4584 {
4585 	off_t offset = NC_varoffset(ncp, varp, start);
4586 	size_t remaining = varp->xsz * nelems;
4587 	int status = NC_NOERR;
4588 	void *xp;
4589         void *fillp=NULL;
4590 
4591 	NC_UNUSED(fillp);
4592 
4593 	if(nelems == 0)
4594 		return NC_NOERR;
4595 
4596 	assert(value != NULL);
4597 
4598 #ifdef ERANGE_FILL
4599         fillp = malloc(varp->xsz);
4600         status = NC3_inq_var_fill(varp, fillp);
4601 #endif
4602 
4603 	for(;;)
4604 	{
4605 		size_t extent = MIN(remaining, ncp->chunk);
4606 		size_t nput = ncx_howmany(varp->type, extent);
4607 
4608 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4609 				 RGN_WRITE, &xp);
4610 		if(lstatus != NC_NOERR)
4611 			return lstatus;
4612 
4613 		lstatus = ncx_putn_ushort_longlong(&xp, nput, value ,fillp);
4614 		if(lstatus != NC_NOERR && status == NC_NOERR)
4615 		{
4616 			/* not fatal to the loop */
4617 			status = lstatus;
4618 		}
4619 
4620 		(void) ncio_rel(ncp->nciop, offset,
4621 				 RGN_MODIFIED);
4622 
4623 		remaining -= extent;
4624 		if(remaining == 0)
4625 			break; /* normal loop exit */
4626 		offset += (off_t)extent;
4627 		value += nput;
4628 
4629 	}
4630 #ifdef ERANGE_FILL
4631         free(fillp);
4632 #endif
4633 
4634 	return status;
4635 }
4636 
4637 static int
putNCvx_ushort_ushort(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ushort * value)4638 putNCvx_ushort_ushort(NC3_INFO* ncp, const NC_var *varp,
4639 		 const size_t *start, size_t nelems, const ushort *value)
4640 {
4641 	off_t offset = NC_varoffset(ncp, varp, start);
4642 	size_t remaining = varp->xsz * nelems;
4643 	int status = NC_NOERR;
4644 	void *xp;
4645         void *fillp=NULL;
4646 
4647 	NC_UNUSED(fillp);
4648 
4649 	if(nelems == 0)
4650 		return NC_NOERR;
4651 
4652 	assert(value != NULL);
4653 
4654 #ifdef ERANGE_FILL
4655         fillp = malloc(varp->xsz);
4656         status = NC3_inq_var_fill(varp, fillp);
4657 #endif
4658 
4659 	for(;;)
4660 	{
4661 		size_t extent = MIN(remaining, ncp->chunk);
4662 		size_t nput = ncx_howmany(varp->type, extent);
4663 
4664 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4665 				 RGN_WRITE, &xp);
4666 		if(lstatus != NC_NOERR)
4667 			return lstatus;
4668 
4669 		lstatus = ncx_putn_ushort_ushort(&xp, nput, value ,fillp);
4670 		if(lstatus != NC_NOERR && status == NC_NOERR)
4671 		{
4672 			/* not fatal to the loop */
4673 			status = lstatus;
4674 		}
4675 
4676 		(void) ncio_rel(ncp->nciop, offset,
4677 				 RGN_MODIFIED);
4678 
4679 		remaining -= extent;
4680 		if(remaining == 0)
4681 			break; /* normal loop exit */
4682 		offset += (off_t)extent;
4683 		value += nput;
4684 
4685 	}
4686 #ifdef ERANGE_FILL
4687         free(fillp);
4688 #endif
4689 
4690 	return status;
4691 }
4692 
4693 static int
putNCvx_ushort_uint(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uint * value)4694 putNCvx_ushort_uint(NC3_INFO* ncp, const NC_var *varp,
4695 		 const size_t *start, size_t nelems, const uint *value)
4696 {
4697 	off_t offset = NC_varoffset(ncp, varp, start);
4698 	size_t remaining = varp->xsz * nelems;
4699 	int status = NC_NOERR;
4700 	void *xp;
4701         void *fillp=NULL;
4702 
4703 	NC_UNUSED(fillp);
4704 
4705 	if(nelems == 0)
4706 		return NC_NOERR;
4707 
4708 	assert(value != NULL);
4709 
4710 #ifdef ERANGE_FILL
4711         fillp = malloc(varp->xsz);
4712         status = NC3_inq_var_fill(varp, fillp);
4713 #endif
4714 
4715 	for(;;)
4716 	{
4717 		size_t extent = MIN(remaining, ncp->chunk);
4718 		size_t nput = ncx_howmany(varp->type, extent);
4719 
4720 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4721 				 RGN_WRITE, &xp);
4722 		if(lstatus != NC_NOERR)
4723 			return lstatus;
4724 
4725 		lstatus = ncx_putn_ushort_uint(&xp, nput, value ,fillp);
4726 		if(lstatus != NC_NOERR && status == NC_NOERR)
4727 		{
4728 			/* not fatal to the loop */
4729 			status = lstatus;
4730 		}
4731 
4732 		(void) ncio_rel(ncp->nciop, offset,
4733 				 RGN_MODIFIED);
4734 
4735 		remaining -= extent;
4736 		if(remaining == 0)
4737 			break; /* normal loop exit */
4738 		offset += (off_t)extent;
4739 		value += nput;
4740 
4741 	}
4742 #ifdef ERANGE_FILL
4743         free(fillp);
4744 #endif
4745 
4746 	return status;
4747 }
4748 
4749 static int
putNCvx_ushort_ulonglong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ulonglong * value)4750 putNCvx_ushort_ulonglong(NC3_INFO* ncp, const NC_var *varp,
4751 		 const size_t *start, size_t nelems, const ulonglong *value)
4752 {
4753 	off_t offset = NC_varoffset(ncp, varp, start);
4754 	size_t remaining = varp->xsz * nelems;
4755 	int status = NC_NOERR;
4756 	void *xp;
4757         void *fillp=NULL;
4758 
4759 	NC_UNUSED(fillp);
4760 
4761 	if(nelems == 0)
4762 		return NC_NOERR;
4763 
4764 	assert(value != NULL);
4765 
4766 #ifdef ERANGE_FILL
4767         fillp = malloc(varp->xsz);
4768         status = NC3_inq_var_fill(varp, fillp);
4769 #endif
4770 
4771 	for(;;)
4772 	{
4773 		size_t extent = MIN(remaining, ncp->chunk);
4774 		size_t nput = ncx_howmany(varp->type, extent);
4775 
4776 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4777 				 RGN_WRITE, &xp);
4778 		if(lstatus != NC_NOERR)
4779 			return lstatus;
4780 
4781 		lstatus = ncx_putn_ushort_ulonglong(&xp, nput, value ,fillp);
4782 		if(lstatus != NC_NOERR && status == NC_NOERR)
4783 		{
4784 			/* not fatal to the loop */
4785 			status = lstatus;
4786 		}
4787 
4788 		(void) ncio_rel(ncp->nciop, offset,
4789 				 RGN_MODIFIED);
4790 
4791 		remaining -= extent;
4792 		if(remaining == 0)
4793 			break; /* normal loop exit */
4794 		offset += (off_t)extent;
4795 		value += nput;
4796 
4797 	}
4798 #ifdef ERANGE_FILL
4799         free(fillp);
4800 #endif
4801 
4802 	return status;
4803 }
4804 
4805 
4806 static int
putNCvx_uint_schar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const schar * value)4807 putNCvx_uint_schar(NC3_INFO* ncp, const NC_var *varp,
4808 		 const size_t *start, size_t nelems, const schar *value)
4809 {
4810 	off_t offset = NC_varoffset(ncp, varp, start);
4811 	size_t remaining = varp->xsz * nelems;
4812 	int status = NC_NOERR;
4813 	void *xp;
4814         void *fillp=NULL;
4815 
4816 	NC_UNUSED(fillp);
4817 
4818 	if(nelems == 0)
4819 		return NC_NOERR;
4820 
4821 	assert(value != NULL);
4822 
4823 #ifdef ERANGE_FILL
4824         fillp = malloc(varp->xsz);
4825         status = NC3_inq_var_fill(varp, fillp);
4826 #endif
4827 
4828 	for(;;)
4829 	{
4830 		size_t extent = MIN(remaining, ncp->chunk);
4831 		size_t nput = ncx_howmany(varp->type, extent);
4832 
4833 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4834 				 RGN_WRITE, &xp);
4835 		if(lstatus != NC_NOERR)
4836 			return lstatus;
4837 
4838 		lstatus = ncx_putn_uint_schar(&xp, nput, value ,fillp);
4839 		if(lstatus != NC_NOERR && status == NC_NOERR)
4840 		{
4841 			/* not fatal to the loop */
4842 			status = lstatus;
4843 		}
4844 
4845 		(void) ncio_rel(ncp->nciop, offset,
4846 				 RGN_MODIFIED);
4847 
4848 		remaining -= extent;
4849 		if(remaining == 0)
4850 			break; /* normal loop exit */
4851 		offset += (off_t)extent;
4852 		value += nput;
4853 
4854 	}
4855 #ifdef ERANGE_FILL
4856         free(fillp);
4857 #endif
4858 
4859 	return status;
4860 }
4861 
4862 static int
putNCvx_uint_uchar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uchar * value)4863 putNCvx_uint_uchar(NC3_INFO* ncp, const NC_var *varp,
4864 		 const size_t *start, size_t nelems, const uchar *value)
4865 {
4866 	off_t offset = NC_varoffset(ncp, varp, start);
4867 	size_t remaining = varp->xsz * nelems;
4868 	int status = NC_NOERR;
4869 	void *xp;
4870         void *fillp=NULL;
4871 
4872 	NC_UNUSED(fillp);
4873 
4874 	if(nelems == 0)
4875 		return NC_NOERR;
4876 
4877 	assert(value != NULL);
4878 
4879 #ifdef ERANGE_FILL
4880         fillp = malloc(varp->xsz);
4881         status = NC3_inq_var_fill(varp, fillp);
4882 #endif
4883 
4884 	for(;;)
4885 	{
4886 		size_t extent = MIN(remaining, ncp->chunk);
4887 		size_t nput = ncx_howmany(varp->type, extent);
4888 
4889 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4890 				 RGN_WRITE, &xp);
4891 		if(lstatus != NC_NOERR)
4892 			return lstatus;
4893 
4894 		lstatus = ncx_putn_uint_uchar(&xp, nput, value ,fillp);
4895 		if(lstatus != NC_NOERR && status == NC_NOERR)
4896 		{
4897 			/* not fatal to the loop */
4898 			status = lstatus;
4899 		}
4900 
4901 		(void) ncio_rel(ncp->nciop, offset,
4902 				 RGN_MODIFIED);
4903 
4904 		remaining -= extent;
4905 		if(remaining == 0)
4906 			break; /* normal loop exit */
4907 		offset += (off_t)extent;
4908 		value += nput;
4909 
4910 	}
4911 #ifdef ERANGE_FILL
4912         free(fillp);
4913 #endif
4914 
4915 	return status;
4916 }
4917 
4918 static int
putNCvx_uint_short(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const short * value)4919 putNCvx_uint_short(NC3_INFO* ncp, const NC_var *varp,
4920 		 const size_t *start, size_t nelems, const short *value)
4921 {
4922 	off_t offset = NC_varoffset(ncp, varp, start);
4923 	size_t remaining = varp->xsz * nelems;
4924 	int status = NC_NOERR;
4925 	void *xp;
4926         void *fillp=NULL;
4927 
4928 	NC_UNUSED(fillp);
4929 
4930 	if(nelems == 0)
4931 		return NC_NOERR;
4932 
4933 	assert(value != NULL);
4934 
4935 #ifdef ERANGE_FILL
4936         fillp = malloc(varp->xsz);
4937         status = NC3_inq_var_fill(varp, fillp);
4938 #endif
4939 
4940 	for(;;)
4941 	{
4942 		size_t extent = MIN(remaining, ncp->chunk);
4943 		size_t nput = ncx_howmany(varp->type, extent);
4944 
4945 		int lstatus = ncio_get(ncp->nciop, offset, extent,
4946 				 RGN_WRITE, &xp);
4947 		if(lstatus != NC_NOERR)
4948 			return lstatus;
4949 
4950 		lstatus = ncx_putn_uint_short(&xp, nput, value ,fillp);
4951 		if(lstatus != NC_NOERR && status == NC_NOERR)
4952 		{
4953 			/* not fatal to the loop */
4954 			status = lstatus;
4955 		}
4956 
4957 		(void) ncio_rel(ncp->nciop, offset,
4958 				 RGN_MODIFIED);
4959 
4960 		remaining -= extent;
4961 		if(remaining == 0)
4962 			break; /* normal loop exit */
4963 		offset += (off_t)extent;
4964 		value += nput;
4965 
4966 	}
4967 #ifdef ERANGE_FILL
4968         free(fillp);
4969 #endif
4970 
4971 	return status;
4972 }
4973 
4974 static int
putNCvx_uint_int(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const int * value)4975 putNCvx_uint_int(NC3_INFO* ncp, const NC_var *varp,
4976 		 const size_t *start, size_t nelems, const int *value)
4977 {
4978 	off_t offset = NC_varoffset(ncp, varp, start);
4979 	size_t remaining = varp->xsz * nelems;
4980 	int status = NC_NOERR;
4981 	void *xp;
4982         void *fillp=NULL;
4983 
4984 	NC_UNUSED(fillp);
4985 
4986 	if(nelems == 0)
4987 		return NC_NOERR;
4988 
4989 	assert(value != NULL);
4990 
4991 #ifdef ERANGE_FILL
4992         fillp = malloc(varp->xsz);
4993         status = NC3_inq_var_fill(varp, fillp);
4994 #endif
4995 
4996 	for(;;)
4997 	{
4998 		size_t extent = MIN(remaining, ncp->chunk);
4999 		size_t nput = ncx_howmany(varp->type, extent);
5000 
5001 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5002 				 RGN_WRITE, &xp);
5003 		if(lstatus != NC_NOERR)
5004 			return lstatus;
5005 
5006 		lstatus = ncx_putn_uint_int(&xp, nput, value ,fillp);
5007 		if(lstatus != NC_NOERR && status == NC_NOERR)
5008 		{
5009 			/* not fatal to the loop */
5010 			status = lstatus;
5011 		}
5012 
5013 		(void) ncio_rel(ncp->nciop, offset,
5014 				 RGN_MODIFIED);
5015 
5016 		remaining -= extent;
5017 		if(remaining == 0)
5018 			break; /* normal loop exit */
5019 		offset += (off_t)extent;
5020 		value += nput;
5021 
5022 	}
5023 #ifdef ERANGE_FILL
5024         free(fillp);
5025 #endif
5026 
5027 	return status;
5028 }
5029 
5030 static int
putNCvx_uint_float(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const float * value)5031 putNCvx_uint_float(NC3_INFO* ncp, const NC_var *varp,
5032 		 const size_t *start, size_t nelems, const float *value)
5033 {
5034 	off_t offset = NC_varoffset(ncp, varp, start);
5035 	size_t remaining = varp->xsz * nelems;
5036 	int status = NC_NOERR;
5037 	void *xp;
5038         void *fillp=NULL;
5039 
5040 	NC_UNUSED(fillp);
5041 
5042 	if(nelems == 0)
5043 		return NC_NOERR;
5044 
5045 	assert(value != NULL);
5046 
5047 #ifdef ERANGE_FILL
5048         fillp = malloc(varp->xsz);
5049         status = NC3_inq_var_fill(varp, fillp);
5050 #endif
5051 
5052 	for(;;)
5053 	{
5054 		size_t extent = MIN(remaining, ncp->chunk);
5055 		size_t nput = ncx_howmany(varp->type, extent);
5056 
5057 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5058 				 RGN_WRITE, &xp);
5059 		if(lstatus != NC_NOERR)
5060 			return lstatus;
5061 
5062 		lstatus = ncx_putn_uint_float(&xp, nput, value ,fillp);
5063 		if(lstatus != NC_NOERR && status == NC_NOERR)
5064 		{
5065 			/* not fatal to the loop */
5066 			status = lstatus;
5067 		}
5068 
5069 		(void) ncio_rel(ncp->nciop, offset,
5070 				 RGN_MODIFIED);
5071 
5072 		remaining -= extent;
5073 		if(remaining == 0)
5074 			break; /* normal loop exit */
5075 		offset += (off_t)extent;
5076 		value += nput;
5077 
5078 	}
5079 #ifdef ERANGE_FILL
5080         free(fillp);
5081 #endif
5082 
5083 	return status;
5084 }
5085 
5086 static int
putNCvx_uint_double(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const double * value)5087 putNCvx_uint_double(NC3_INFO* ncp, const NC_var *varp,
5088 		 const size_t *start, size_t nelems, const double *value)
5089 {
5090 	off_t offset = NC_varoffset(ncp, varp, start);
5091 	size_t remaining = varp->xsz * nelems;
5092 	int status = NC_NOERR;
5093 	void *xp;
5094         void *fillp=NULL;
5095 
5096 	NC_UNUSED(fillp);
5097 
5098 	if(nelems == 0)
5099 		return NC_NOERR;
5100 
5101 	assert(value != NULL);
5102 
5103 #ifdef ERANGE_FILL
5104         fillp = malloc(varp->xsz);
5105         status = NC3_inq_var_fill(varp, fillp);
5106 #endif
5107 
5108 	for(;;)
5109 	{
5110 		size_t extent = MIN(remaining, ncp->chunk);
5111 		size_t nput = ncx_howmany(varp->type, extent);
5112 
5113 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5114 				 RGN_WRITE, &xp);
5115 		if(lstatus != NC_NOERR)
5116 			return lstatus;
5117 
5118 		lstatus = ncx_putn_uint_double(&xp, nput, value ,fillp);
5119 		if(lstatus != NC_NOERR && status == NC_NOERR)
5120 		{
5121 			/* not fatal to the loop */
5122 			status = lstatus;
5123 		}
5124 
5125 		(void) ncio_rel(ncp->nciop, offset,
5126 				 RGN_MODIFIED);
5127 
5128 		remaining -= extent;
5129 		if(remaining == 0)
5130 			break; /* normal loop exit */
5131 		offset += (off_t)extent;
5132 		value += nput;
5133 
5134 	}
5135 #ifdef ERANGE_FILL
5136         free(fillp);
5137 #endif
5138 
5139 	return status;
5140 }
5141 
5142 static int
putNCvx_uint_longlong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const longlong * value)5143 putNCvx_uint_longlong(NC3_INFO* ncp, const NC_var *varp,
5144 		 const size_t *start, size_t nelems, const longlong *value)
5145 {
5146 	off_t offset = NC_varoffset(ncp, varp, start);
5147 	size_t remaining = varp->xsz * nelems;
5148 	int status = NC_NOERR;
5149 	void *xp;
5150         void *fillp=NULL;
5151 
5152 	NC_UNUSED(fillp);
5153 
5154 	if(nelems == 0)
5155 		return NC_NOERR;
5156 
5157 	assert(value != NULL);
5158 
5159 #ifdef ERANGE_FILL
5160         fillp = malloc(varp->xsz);
5161         status = NC3_inq_var_fill(varp, fillp);
5162 #endif
5163 
5164 	for(;;)
5165 	{
5166 		size_t extent = MIN(remaining, ncp->chunk);
5167 		size_t nput = ncx_howmany(varp->type, extent);
5168 
5169 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5170 				 RGN_WRITE, &xp);
5171 		if(lstatus != NC_NOERR)
5172 			return lstatus;
5173 
5174 		lstatus = ncx_putn_uint_longlong(&xp, nput, value ,fillp);
5175 		if(lstatus != NC_NOERR && status == NC_NOERR)
5176 		{
5177 			/* not fatal to the loop */
5178 			status = lstatus;
5179 		}
5180 
5181 		(void) ncio_rel(ncp->nciop, offset,
5182 				 RGN_MODIFIED);
5183 
5184 		remaining -= extent;
5185 		if(remaining == 0)
5186 			break; /* normal loop exit */
5187 		offset += (off_t)extent;
5188 		value += nput;
5189 
5190 	}
5191 #ifdef ERANGE_FILL
5192         free(fillp);
5193 #endif
5194 
5195 	return status;
5196 }
5197 
5198 static int
putNCvx_uint_ushort(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ushort * value)5199 putNCvx_uint_ushort(NC3_INFO* ncp, const NC_var *varp,
5200 		 const size_t *start, size_t nelems, const ushort *value)
5201 {
5202 	off_t offset = NC_varoffset(ncp, varp, start);
5203 	size_t remaining = varp->xsz * nelems;
5204 	int status = NC_NOERR;
5205 	void *xp;
5206         void *fillp=NULL;
5207 
5208 	NC_UNUSED(fillp);
5209 
5210 	if(nelems == 0)
5211 		return NC_NOERR;
5212 
5213 	assert(value != NULL);
5214 
5215 #ifdef ERANGE_FILL
5216         fillp = malloc(varp->xsz);
5217         status = NC3_inq_var_fill(varp, fillp);
5218 #endif
5219 
5220 	for(;;)
5221 	{
5222 		size_t extent = MIN(remaining, ncp->chunk);
5223 		size_t nput = ncx_howmany(varp->type, extent);
5224 
5225 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5226 				 RGN_WRITE, &xp);
5227 		if(lstatus != NC_NOERR)
5228 			return lstatus;
5229 
5230 		lstatus = ncx_putn_uint_ushort(&xp, nput, value ,fillp);
5231 		if(lstatus != NC_NOERR && status == NC_NOERR)
5232 		{
5233 			/* not fatal to the loop */
5234 			status = lstatus;
5235 		}
5236 
5237 		(void) ncio_rel(ncp->nciop, offset,
5238 				 RGN_MODIFIED);
5239 
5240 		remaining -= extent;
5241 		if(remaining == 0)
5242 			break; /* normal loop exit */
5243 		offset += (off_t)extent;
5244 		value += nput;
5245 
5246 	}
5247 #ifdef ERANGE_FILL
5248         free(fillp);
5249 #endif
5250 
5251 	return status;
5252 }
5253 
5254 static int
putNCvx_uint_uint(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uint * value)5255 putNCvx_uint_uint(NC3_INFO* ncp, const NC_var *varp,
5256 		 const size_t *start, size_t nelems, const uint *value)
5257 {
5258 	off_t offset = NC_varoffset(ncp, varp, start);
5259 	size_t remaining = varp->xsz * nelems;
5260 	int status = NC_NOERR;
5261 	void *xp;
5262         void *fillp=NULL;
5263 
5264 	NC_UNUSED(fillp);
5265 
5266 	if(nelems == 0)
5267 		return NC_NOERR;
5268 
5269 	assert(value != NULL);
5270 
5271 #ifdef ERANGE_FILL
5272         fillp = malloc(varp->xsz);
5273         status = NC3_inq_var_fill(varp, fillp);
5274 #endif
5275 
5276 	for(;;)
5277 	{
5278 		size_t extent = MIN(remaining, ncp->chunk);
5279 		size_t nput = ncx_howmany(varp->type, extent);
5280 
5281 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5282 				 RGN_WRITE, &xp);
5283 		if(lstatus != NC_NOERR)
5284 			return lstatus;
5285 
5286 		lstatus = ncx_putn_uint_uint(&xp, nput, value ,fillp);
5287 		if(lstatus != NC_NOERR && status == NC_NOERR)
5288 		{
5289 			/* not fatal to the loop */
5290 			status = lstatus;
5291 		}
5292 
5293 		(void) ncio_rel(ncp->nciop, offset,
5294 				 RGN_MODIFIED);
5295 
5296 		remaining -= extent;
5297 		if(remaining == 0)
5298 			break; /* normal loop exit */
5299 		offset += (off_t)extent;
5300 		value += nput;
5301 
5302 	}
5303 #ifdef ERANGE_FILL
5304         free(fillp);
5305 #endif
5306 
5307 	return status;
5308 }
5309 
5310 static int
putNCvx_uint_ulonglong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ulonglong * value)5311 putNCvx_uint_ulonglong(NC3_INFO* ncp, const NC_var *varp,
5312 		 const size_t *start, size_t nelems, const ulonglong *value)
5313 {
5314 	off_t offset = NC_varoffset(ncp, varp, start);
5315 	size_t remaining = varp->xsz * nelems;
5316 	int status = NC_NOERR;
5317 	void *xp;
5318         void *fillp=NULL;
5319 
5320 	NC_UNUSED(fillp);
5321 
5322 	if(nelems == 0)
5323 		return NC_NOERR;
5324 
5325 	assert(value != NULL);
5326 
5327 #ifdef ERANGE_FILL
5328         fillp = malloc(varp->xsz);
5329         status = NC3_inq_var_fill(varp, fillp);
5330 #endif
5331 
5332 	for(;;)
5333 	{
5334 		size_t extent = MIN(remaining, ncp->chunk);
5335 		size_t nput = ncx_howmany(varp->type, extent);
5336 
5337 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5338 				 RGN_WRITE, &xp);
5339 		if(lstatus != NC_NOERR)
5340 			return lstatus;
5341 
5342 		lstatus = ncx_putn_uint_ulonglong(&xp, nput, value ,fillp);
5343 		if(lstatus != NC_NOERR && status == NC_NOERR)
5344 		{
5345 			/* not fatal to the loop */
5346 			status = lstatus;
5347 		}
5348 
5349 		(void) ncio_rel(ncp->nciop, offset,
5350 				 RGN_MODIFIED);
5351 
5352 		remaining -= extent;
5353 		if(remaining == 0)
5354 			break; /* normal loop exit */
5355 		offset += (off_t)extent;
5356 		value += nput;
5357 
5358 	}
5359 #ifdef ERANGE_FILL
5360         free(fillp);
5361 #endif
5362 
5363 	return status;
5364 }
5365 
5366 
5367 static int
putNCvx_longlong_schar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const schar * value)5368 putNCvx_longlong_schar(NC3_INFO* ncp, const NC_var *varp,
5369 		 const size_t *start, size_t nelems, const schar *value)
5370 {
5371 	off_t offset = NC_varoffset(ncp, varp, start);
5372 	size_t remaining = varp->xsz * nelems;
5373 	int status = NC_NOERR;
5374 	void *xp;
5375         void *fillp=NULL;
5376 
5377 	NC_UNUSED(fillp);
5378 
5379 	if(nelems == 0)
5380 		return NC_NOERR;
5381 
5382 	assert(value != NULL);
5383 
5384 #ifdef ERANGE_FILL
5385         fillp = malloc(varp->xsz);
5386         status = NC3_inq_var_fill(varp, fillp);
5387 #endif
5388 
5389 	for(;;)
5390 	{
5391 		size_t extent = MIN(remaining, ncp->chunk);
5392 		size_t nput = ncx_howmany(varp->type, extent);
5393 
5394 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5395 				 RGN_WRITE, &xp);
5396 		if(lstatus != NC_NOERR)
5397 			return lstatus;
5398 
5399 		lstatus = ncx_putn_longlong_schar(&xp, nput, value ,fillp);
5400 		if(lstatus != NC_NOERR && status == NC_NOERR)
5401 		{
5402 			/* not fatal to the loop */
5403 			status = lstatus;
5404 		}
5405 
5406 		(void) ncio_rel(ncp->nciop, offset,
5407 				 RGN_MODIFIED);
5408 
5409 		remaining -= extent;
5410 		if(remaining == 0)
5411 			break; /* normal loop exit */
5412 		offset += (off_t)extent;
5413 		value += nput;
5414 
5415 	}
5416 #ifdef ERANGE_FILL
5417         free(fillp);
5418 #endif
5419 
5420 	return status;
5421 }
5422 
5423 static int
putNCvx_longlong_uchar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uchar * value)5424 putNCvx_longlong_uchar(NC3_INFO* ncp, const NC_var *varp,
5425 		 const size_t *start, size_t nelems, const uchar *value)
5426 {
5427 	off_t offset = NC_varoffset(ncp, varp, start);
5428 	size_t remaining = varp->xsz * nelems;
5429 	int status = NC_NOERR;
5430 	void *xp;
5431         void *fillp=NULL;
5432 
5433 	NC_UNUSED(fillp);
5434 
5435 	if(nelems == 0)
5436 		return NC_NOERR;
5437 
5438 	assert(value != NULL);
5439 
5440 #ifdef ERANGE_FILL
5441         fillp = malloc(varp->xsz);
5442         status = NC3_inq_var_fill(varp, fillp);
5443 #endif
5444 
5445 	for(;;)
5446 	{
5447 		size_t extent = MIN(remaining, ncp->chunk);
5448 		size_t nput = ncx_howmany(varp->type, extent);
5449 
5450 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5451 				 RGN_WRITE, &xp);
5452 		if(lstatus != NC_NOERR)
5453 			return lstatus;
5454 
5455 		lstatus = ncx_putn_longlong_uchar(&xp, nput, value ,fillp);
5456 		if(lstatus != NC_NOERR && status == NC_NOERR)
5457 		{
5458 			/* not fatal to the loop */
5459 			status = lstatus;
5460 		}
5461 
5462 		(void) ncio_rel(ncp->nciop, offset,
5463 				 RGN_MODIFIED);
5464 
5465 		remaining -= extent;
5466 		if(remaining == 0)
5467 			break; /* normal loop exit */
5468 		offset += (off_t)extent;
5469 		value += nput;
5470 
5471 	}
5472 #ifdef ERANGE_FILL
5473         free(fillp);
5474 #endif
5475 
5476 	return status;
5477 }
5478 
5479 static int
putNCvx_longlong_short(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const short * value)5480 putNCvx_longlong_short(NC3_INFO* ncp, const NC_var *varp,
5481 		 const size_t *start, size_t nelems, const short *value)
5482 {
5483 	off_t offset = NC_varoffset(ncp, varp, start);
5484 	size_t remaining = varp->xsz * nelems;
5485 	int status = NC_NOERR;
5486 	void *xp;
5487         void *fillp=NULL;
5488 
5489 	NC_UNUSED(fillp);
5490 
5491 	if(nelems == 0)
5492 		return NC_NOERR;
5493 
5494 	assert(value != NULL);
5495 
5496 #ifdef ERANGE_FILL
5497         fillp = malloc(varp->xsz);
5498         status = NC3_inq_var_fill(varp, fillp);
5499 #endif
5500 
5501 	for(;;)
5502 	{
5503 		size_t extent = MIN(remaining, ncp->chunk);
5504 		size_t nput = ncx_howmany(varp->type, extent);
5505 
5506 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5507 				 RGN_WRITE, &xp);
5508 		if(lstatus != NC_NOERR)
5509 			return lstatus;
5510 
5511 		lstatus = ncx_putn_longlong_short(&xp, nput, value ,fillp);
5512 		if(lstatus != NC_NOERR && status == NC_NOERR)
5513 		{
5514 			/* not fatal to the loop */
5515 			status = lstatus;
5516 		}
5517 
5518 		(void) ncio_rel(ncp->nciop, offset,
5519 				 RGN_MODIFIED);
5520 
5521 		remaining -= extent;
5522 		if(remaining == 0)
5523 			break; /* normal loop exit */
5524 		offset += (off_t)extent;
5525 		value += nput;
5526 
5527 	}
5528 #ifdef ERANGE_FILL
5529         free(fillp);
5530 #endif
5531 
5532 	return status;
5533 }
5534 
5535 static int
putNCvx_longlong_int(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const int * value)5536 putNCvx_longlong_int(NC3_INFO* ncp, const NC_var *varp,
5537 		 const size_t *start, size_t nelems, const int *value)
5538 {
5539 	off_t offset = NC_varoffset(ncp, varp, start);
5540 	size_t remaining = varp->xsz * nelems;
5541 	int status = NC_NOERR;
5542 	void *xp;
5543         void *fillp=NULL;
5544 
5545 	NC_UNUSED(fillp);
5546 
5547 	if(nelems == 0)
5548 		return NC_NOERR;
5549 
5550 	assert(value != NULL);
5551 
5552 #ifdef ERANGE_FILL
5553         fillp = malloc(varp->xsz);
5554         status = NC3_inq_var_fill(varp, fillp);
5555 #endif
5556 
5557 	for(;;)
5558 	{
5559 		size_t extent = MIN(remaining, ncp->chunk);
5560 		size_t nput = ncx_howmany(varp->type, extent);
5561 
5562 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5563 				 RGN_WRITE, &xp);
5564 		if(lstatus != NC_NOERR)
5565 			return lstatus;
5566 
5567 		lstatus = ncx_putn_longlong_int(&xp, nput, value ,fillp);
5568 		if(lstatus != NC_NOERR && status == NC_NOERR)
5569 		{
5570 			/* not fatal to the loop */
5571 			status = lstatus;
5572 		}
5573 
5574 		(void) ncio_rel(ncp->nciop, offset,
5575 				 RGN_MODIFIED);
5576 
5577 		remaining -= extent;
5578 		if(remaining == 0)
5579 			break; /* normal loop exit */
5580 		offset += (off_t)extent;
5581 		value += nput;
5582 
5583 	}
5584 #ifdef ERANGE_FILL
5585         free(fillp);
5586 #endif
5587 
5588 	return status;
5589 }
5590 
5591 static int
putNCvx_longlong_float(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const float * value)5592 putNCvx_longlong_float(NC3_INFO* ncp, const NC_var *varp,
5593 		 const size_t *start, size_t nelems, const float *value)
5594 {
5595 	off_t offset = NC_varoffset(ncp, varp, start);
5596 	size_t remaining = varp->xsz * nelems;
5597 	int status = NC_NOERR;
5598 	void *xp;
5599         void *fillp=NULL;
5600 
5601 	NC_UNUSED(fillp);
5602 
5603 	if(nelems == 0)
5604 		return NC_NOERR;
5605 
5606 	assert(value != NULL);
5607 
5608 #ifdef ERANGE_FILL
5609         fillp = malloc(varp->xsz);
5610         status = NC3_inq_var_fill(varp, fillp);
5611 #endif
5612 
5613 	for(;;)
5614 	{
5615 		size_t extent = MIN(remaining, ncp->chunk);
5616 		size_t nput = ncx_howmany(varp->type, extent);
5617 
5618 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5619 				 RGN_WRITE, &xp);
5620 		if(lstatus != NC_NOERR)
5621 			return lstatus;
5622 
5623 		lstatus = ncx_putn_longlong_float(&xp, nput, value ,fillp);
5624 		if(lstatus != NC_NOERR && status == NC_NOERR)
5625 		{
5626 			/* not fatal to the loop */
5627 			status = lstatus;
5628 		}
5629 
5630 		(void) ncio_rel(ncp->nciop, offset,
5631 				 RGN_MODIFIED);
5632 
5633 		remaining -= extent;
5634 		if(remaining == 0)
5635 			break; /* normal loop exit */
5636 		offset += (off_t)extent;
5637 		value += nput;
5638 
5639 	}
5640 #ifdef ERANGE_FILL
5641         free(fillp);
5642 #endif
5643 
5644 	return status;
5645 }
5646 
5647 static int
putNCvx_longlong_double(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const double * value)5648 putNCvx_longlong_double(NC3_INFO* ncp, const NC_var *varp,
5649 		 const size_t *start, size_t nelems, const double *value)
5650 {
5651 	off_t offset = NC_varoffset(ncp, varp, start);
5652 	size_t remaining = varp->xsz * nelems;
5653 	int status = NC_NOERR;
5654 	void *xp;
5655         void *fillp=NULL;
5656 
5657 	NC_UNUSED(fillp);
5658 
5659 	if(nelems == 0)
5660 		return NC_NOERR;
5661 
5662 	assert(value != NULL);
5663 
5664 #ifdef ERANGE_FILL
5665         fillp = malloc(varp->xsz);
5666         status = NC3_inq_var_fill(varp, fillp);
5667 #endif
5668 
5669 	for(;;)
5670 	{
5671 		size_t extent = MIN(remaining, ncp->chunk);
5672 		size_t nput = ncx_howmany(varp->type, extent);
5673 
5674 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5675 				 RGN_WRITE, &xp);
5676 		if(lstatus != NC_NOERR)
5677 			return lstatus;
5678 
5679 		lstatus = ncx_putn_longlong_double(&xp, nput, value ,fillp);
5680 		if(lstatus != NC_NOERR && status == NC_NOERR)
5681 		{
5682 			/* not fatal to the loop */
5683 			status = lstatus;
5684 		}
5685 
5686 		(void) ncio_rel(ncp->nciop, offset,
5687 				 RGN_MODIFIED);
5688 
5689 		remaining -= extent;
5690 		if(remaining == 0)
5691 			break; /* normal loop exit */
5692 		offset += (off_t)extent;
5693 		value += nput;
5694 
5695 	}
5696 #ifdef ERANGE_FILL
5697         free(fillp);
5698 #endif
5699 
5700 	return status;
5701 }
5702 
5703 static int
putNCvx_longlong_longlong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const longlong * value)5704 putNCvx_longlong_longlong(NC3_INFO* ncp, const NC_var *varp,
5705 		 const size_t *start, size_t nelems, const longlong *value)
5706 {
5707 	off_t offset = NC_varoffset(ncp, varp, start);
5708 	size_t remaining = varp->xsz * nelems;
5709 	int status = NC_NOERR;
5710 	void *xp;
5711         void *fillp=NULL;
5712 
5713 	NC_UNUSED(fillp);
5714 
5715 	if(nelems == 0)
5716 		return NC_NOERR;
5717 
5718 	assert(value != NULL);
5719 
5720 #ifdef ERANGE_FILL
5721         fillp = malloc(varp->xsz);
5722         status = NC3_inq_var_fill(varp, fillp);
5723 #endif
5724 
5725 	for(;;)
5726 	{
5727 		size_t extent = MIN(remaining, ncp->chunk);
5728 		size_t nput = ncx_howmany(varp->type, extent);
5729 
5730 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5731 				 RGN_WRITE, &xp);
5732 		if(lstatus != NC_NOERR)
5733 			return lstatus;
5734 
5735 		lstatus = ncx_putn_longlong_longlong(&xp, nput, value ,fillp);
5736 		if(lstatus != NC_NOERR && status == NC_NOERR)
5737 		{
5738 			/* not fatal to the loop */
5739 			status = lstatus;
5740 		}
5741 
5742 		(void) ncio_rel(ncp->nciop, offset,
5743 				 RGN_MODIFIED);
5744 
5745 		remaining -= extent;
5746 		if(remaining == 0)
5747 			break; /* normal loop exit */
5748 		offset += (off_t)extent;
5749 		value += nput;
5750 
5751 	}
5752 #ifdef ERANGE_FILL
5753         free(fillp);
5754 #endif
5755 
5756 	return status;
5757 }
5758 
5759 static int
putNCvx_longlong_ushort(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ushort * value)5760 putNCvx_longlong_ushort(NC3_INFO* ncp, const NC_var *varp,
5761 		 const size_t *start, size_t nelems, const ushort *value)
5762 {
5763 	off_t offset = NC_varoffset(ncp, varp, start);
5764 	size_t remaining = varp->xsz * nelems;
5765 	int status = NC_NOERR;
5766 	void *xp;
5767         void *fillp=NULL;
5768 
5769 	NC_UNUSED(fillp);
5770 
5771 	if(nelems == 0)
5772 		return NC_NOERR;
5773 
5774 	assert(value != NULL);
5775 
5776 #ifdef ERANGE_FILL
5777         fillp = malloc(varp->xsz);
5778         status = NC3_inq_var_fill(varp, fillp);
5779 #endif
5780 
5781 	for(;;)
5782 	{
5783 		size_t extent = MIN(remaining, ncp->chunk);
5784 		size_t nput = ncx_howmany(varp->type, extent);
5785 
5786 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5787 				 RGN_WRITE, &xp);
5788 		if(lstatus != NC_NOERR)
5789 			return lstatus;
5790 
5791 		lstatus = ncx_putn_longlong_ushort(&xp, nput, value ,fillp);
5792 		if(lstatus != NC_NOERR && status == NC_NOERR)
5793 		{
5794 			/* not fatal to the loop */
5795 			status = lstatus;
5796 		}
5797 
5798 		(void) ncio_rel(ncp->nciop, offset,
5799 				 RGN_MODIFIED);
5800 
5801 		remaining -= extent;
5802 		if(remaining == 0)
5803 			break; /* normal loop exit */
5804 		offset += (off_t)extent;
5805 		value += nput;
5806 
5807 	}
5808 #ifdef ERANGE_FILL
5809         free(fillp);
5810 #endif
5811 
5812 	return status;
5813 }
5814 
5815 static int
putNCvx_longlong_uint(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uint * value)5816 putNCvx_longlong_uint(NC3_INFO* ncp, const NC_var *varp,
5817 		 const size_t *start, size_t nelems, const uint *value)
5818 {
5819 	off_t offset = NC_varoffset(ncp, varp, start);
5820 	size_t remaining = varp->xsz * nelems;
5821 	int status = NC_NOERR;
5822 	void *xp;
5823         void *fillp=NULL;
5824 
5825 	NC_UNUSED(fillp);
5826 
5827 	if(nelems == 0)
5828 		return NC_NOERR;
5829 
5830 	assert(value != NULL);
5831 
5832 #ifdef ERANGE_FILL
5833         fillp = malloc(varp->xsz);
5834         status = NC3_inq_var_fill(varp, fillp);
5835 #endif
5836 
5837 	for(;;)
5838 	{
5839 		size_t extent = MIN(remaining, ncp->chunk);
5840 		size_t nput = ncx_howmany(varp->type, extent);
5841 
5842 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5843 				 RGN_WRITE, &xp);
5844 		if(lstatus != NC_NOERR)
5845 			return lstatus;
5846 
5847 		lstatus = ncx_putn_longlong_uint(&xp, nput, value ,fillp);
5848 		if(lstatus != NC_NOERR && status == NC_NOERR)
5849 		{
5850 			/* not fatal to the loop */
5851 			status = lstatus;
5852 		}
5853 
5854 		(void) ncio_rel(ncp->nciop, offset,
5855 				 RGN_MODIFIED);
5856 
5857 		remaining -= extent;
5858 		if(remaining == 0)
5859 			break; /* normal loop exit */
5860 		offset += (off_t)extent;
5861 		value += nput;
5862 
5863 	}
5864 #ifdef ERANGE_FILL
5865         free(fillp);
5866 #endif
5867 
5868 	return status;
5869 }
5870 
5871 static int
putNCvx_longlong_ulonglong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ulonglong * value)5872 putNCvx_longlong_ulonglong(NC3_INFO* ncp, const NC_var *varp,
5873 		 const size_t *start, size_t nelems, const ulonglong *value)
5874 {
5875 	off_t offset = NC_varoffset(ncp, varp, start);
5876 	size_t remaining = varp->xsz * nelems;
5877 	int status = NC_NOERR;
5878 	void *xp;
5879         void *fillp=NULL;
5880 
5881 	NC_UNUSED(fillp);
5882 
5883 	if(nelems == 0)
5884 		return NC_NOERR;
5885 
5886 	assert(value != NULL);
5887 
5888 #ifdef ERANGE_FILL
5889         fillp = malloc(varp->xsz);
5890         status = NC3_inq_var_fill(varp, fillp);
5891 #endif
5892 
5893 	for(;;)
5894 	{
5895 		size_t extent = MIN(remaining, ncp->chunk);
5896 		size_t nput = ncx_howmany(varp->type, extent);
5897 
5898 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5899 				 RGN_WRITE, &xp);
5900 		if(lstatus != NC_NOERR)
5901 			return lstatus;
5902 
5903 		lstatus = ncx_putn_longlong_ulonglong(&xp, nput, value ,fillp);
5904 		if(lstatus != NC_NOERR && status == NC_NOERR)
5905 		{
5906 			/* not fatal to the loop */
5907 			status = lstatus;
5908 		}
5909 
5910 		(void) ncio_rel(ncp->nciop, offset,
5911 				 RGN_MODIFIED);
5912 
5913 		remaining -= extent;
5914 		if(remaining == 0)
5915 			break; /* normal loop exit */
5916 		offset += (off_t)extent;
5917 		value += nput;
5918 
5919 	}
5920 #ifdef ERANGE_FILL
5921         free(fillp);
5922 #endif
5923 
5924 	return status;
5925 }
5926 
5927 
5928 static int
putNCvx_ulonglong_schar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const schar * value)5929 putNCvx_ulonglong_schar(NC3_INFO* ncp, const NC_var *varp,
5930 		 const size_t *start, size_t nelems, const schar *value)
5931 {
5932 	off_t offset = NC_varoffset(ncp, varp, start);
5933 	size_t remaining = varp->xsz * nelems;
5934 	int status = NC_NOERR;
5935 	void *xp;
5936         void *fillp=NULL;
5937 
5938 	NC_UNUSED(fillp);
5939 
5940 	if(nelems == 0)
5941 		return NC_NOERR;
5942 
5943 	assert(value != NULL);
5944 
5945 #ifdef ERANGE_FILL
5946         fillp = malloc(varp->xsz);
5947         status = NC3_inq_var_fill(varp, fillp);
5948 #endif
5949 
5950 	for(;;)
5951 	{
5952 		size_t extent = MIN(remaining, ncp->chunk);
5953 		size_t nput = ncx_howmany(varp->type, extent);
5954 
5955 		int lstatus = ncio_get(ncp->nciop, offset, extent,
5956 				 RGN_WRITE, &xp);
5957 		if(lstatus != NC_NOERR)
5958 			return lstatus;
5959 
5960 		lstatus = ncx_putn_ulonglong_schar(&xp, nput, value ,fillp);
5961 		if(lstatus != NC_NOERR && status == NC_NOERR)
5962 		{
5963 			/* not fatal to the loop */
5964 			status = lstatus;
5965 		}
5966 
5967 		(void) ncio_rel(ncp->nciop, offset,
5968 				 RGN_MODIFIED);
5969 
5970 		remaining -= extent;
5971 		if(remaining == 0)
5972 			break; /* normal loop exit */
5973 		offset += (off_t)extent;
5974 		value += nput;
5975 
5976 	}
5977 #ifdef ERANGE_FILL
5978         free(fillp);
5979 #endif
5980 
5981 	return status;
5982 }
5983 
5984 static int
putNCvx_ulonglong_uchar(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uchar * value)5985 putNCvx_ulonglong_uchar(NC3_INFO* ncp, const NC_var *varp,
5986 		 const size_t *start, size_t nelems, const uchar *value)
5987 {
5988 	off_t offset = NC_varoffset(ncp, varp, start);
5989 	size_t remaining = varp->xsz * nelems;
5990 	int status = NC_NOERR;
5991 	void *xp;
5992         void *fillp=NULL;
5993 
5994 	NC_UNUSED(fillp);
5995 
5996 	if(nelems == 0)
5997 		return NC_NOERR;
5998 
5999 	assert(value != NULL);
6000 
6001 #ifdef ERANGE_FILL
6002         fillp = malloc(varp->xsz);
6003         status = NC3_inq_var_fill(varp, fillp);
6004 #endif
6005 
6006 	for(;;)
6007 	{
6008 		size_t extent = MIN(remaining, ncp->chunk);
6009 		size_t nput = ncx_howmany(varp->type, extent);
6010 
6011 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6012 				 RGN_WRITE, &xp);
6013 		if(lstatus != NC_NOERR)
6014 			return lstatus;
6015 
6016 		lstatus = ncx_putn_ulonglong_uchar(&xp, nput, value ,fillp);
6017 		if(lstatus != NC_NOERR && status == NC_NOERR)
6018 		{
6019 			/* not fatal to the loop */
6020 			status = lstatus;
6021 		}
6022 
6023 		(void) ncio_rel(ncp->nciop, offset,
6024 				 RGN_MODIFIED);
6025 
6026 		remaining -= extent;
6027 		if(remaining == 0)
6028 			break; /* normal loop exit */
6029 		offset += (off_t)extent;
6030 		value += nput;
6031 
6032 	}
6033 #ifdef ERANGE_FILL
6034         free(fillp);
6035 #endif
6036 
6037 	return status;
6038 }
6039 
6040 static int
putNCvx_ulonglong_short(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const short * value)6041 putNCvx_ulonglong_short(NC3_INFO* ncp, const NC_var *varp,
6042 		 const size_t *start, size_t nelems, const short *value)
6043 {
6044 	off_t offset = NC_varoffset(ncp, varp, start);
6045 	size_t remaining = varp->xsz * nelems;
6046 	int status = NC_NOERR;
6047 	void *xp;
6048         void *fillp=NULL;
6049 
6050 	NC_UNUSED(fillp);
6051 
6052 	if(nelems == 0)
6053 		return NC_NOERR;
6054 
6055 	assert(value != NULL);
6056 
6057 #ifdef ERANGE_FILL
6058         fillp = malloc(varp->xsz);
6059         status = NC3_inq_var_fill(varp, fillp);
6060 #endif
6061 
6062 	for(;;)
6063 	{
6064 		size_t extent = MIN(remaining, ncp->chunk);
6065 		size_t nput = ncx_howmany(varp->type, extent);
6066 
6067 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6068 				 RGN_WRITE, &xp);
6069 		if(lstatus != NC_NOERR)
6070 			return lstatus;
6071 
6072 		lstatus = ncx_putn_ulonglong_short(&xp, nput, value ,fillp);
6073 		if(lstatus != NC_NOERR && status == NC_NOERR)
6074 		{
6075 			/* not fatal to the loop */
6076 			status = lstatus;
6077 		}
6078 
6079 		(void) ncio_rel(ncp->nciop, offset,
6080 				 RGN_MODIFIED);
6081 
6082 		remaining -= extent;
6083 		if(remaining == 0)
6084 			break; /* normal loop exit */
6085 		offset += (off_t)extent;
6086 		value += nput;
6087 
6088 	}
6089 #ifdef ERANGE_FILL
6090         free(fillp);
6091 #endif
6092 
6093 	return status;
6094 }
6095 
6096 static int
putNCvx_ulonglong_int(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const int * value)6097 putNCvx_ulonglong_int(NC3_INFO* ncp, const NC_var *varp,
6098 		 const size_t *start, size_t nelems, const int *value)
6099 {
6100 	off_t offset = NC_varoffset(ncp, varp, start);
6101 	size_t remaining = varp->xsz * nelems;
6102 	int status = NC_NOERR;
6103 	void *xp;
6104         void *fillp=NULL;
6105 
6106 	NC_UNUSED(fillp);
6107 
6108 	if(nelems == 0)
6109 		return NC_NOERR;
6110 
6111 	assert(value != NULL);
6112 
6113 #ifdef ERANGE_FILL
6114         fillp = malloc(varp->xsz);
6115         status = NC3_inq_var_fill(varp, fillp);
6116 #endif
6117 
6118 	for(;;)
6119 	{
6120 		size_t extent = MIN(remaining, ncp->chunk);
6121 		size_t nput = ncx_howmany(varp->type, extent);
6122 
6123 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6124 				 RGN_WRITE, &xp);
6125 		if(lstatus != NC_NOERR)
6126 			return lstatus;
6127 
6128 		lstatus = ncx_putn_ulonglong_int(&xp, nput, value ,fillp);
6129 		if(lstatus != NC_NOERR && status == NC_NOERR)
6130 		{
6131 			/* not fatal to the loop */
6132 			status = lstatus;
6133 		}
6134 
6135 		(void) ncio_rel(ncp->nciop, offset,
6136 				 RGN_MODIFIED);
6137 
6138 		remaining -= extent;
6139 		if(remaining == 0)
6140 			break; /* normal loop exit */
6141 		offset += (off_t)extent;
6142 		value += nput;
6143 
6144 	}
6145 #ifdef ERANGE_FILL
6146         free(fillp);
6147 #endif
6148 
6149 	return status;
6150 }
6151 
6152 static int
putNCvx_ulonglong_float(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const float * value)6153 putNCvx_ulonglong_float(NC3_INFO* ncp, const NC_var *varp,
6154 		 const size_t *start, size_t nelems, const float *value)
6155 {
6156 	off_t offset = NC_varoffset(ncp, varp, start);
6157 	size_t remaining = varp->xsz * nelems;
6158 	int status = NC_NOERR;
6159 	void *xp;
6160         void *fillp=NULL;
6161 
6162 	NC_UNUSED(fillp);
6163 
6164 	if(nelems == 0)
6165 		return NC_NOERR;
6166 
6167 	assert(value != NULL);
6168 
6169 #ifdef ERANGE_FILL
6170         fillp = malloc(varp->xsz);
6171         status = NC3_inq_var_fill(varp, fillp);
6172 #endif
6173 
6174 	for(;;)
6175 	{
6176 		size_t extent = MIN(remaining, ncp->chunk);
6177 		size_t nput = ncx_howmany(varp->type, extent);
6178 
6179 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6180 				 RGN_WRITE, &xp);
6181 		if(lstatus != NC_NOERR)
6182 			return lstatus;
6183 
6184 		lstatus = ncx_putn_ulonglong_float(&xp, nput, value ,fillp);
6185 		if(lstatus != NC_NOERR && status == NC_NOERR)
6186 		{
6187 			/* not fatal to the loop */
6188 			status = lstatus;
6189 		}
6190 
6191 		(void) ncio_rel(ncp->nciop, offset,
6192 				 RGN_MODIFIED);
6193 
6194 		remaining -= extent;
6195 		if(remaining == 0)
6196 			break; /* normal loop exit */
6197 		offset += (off_t)extent;
6198 		value += nput;
6199 
6200 	}
6201 #ifdef ERANGE_FILL
6202         free(fillp);
6203 #endif
6204 
6205 	return status;
6206 }
6207 
6208 static int
putNCvx_ulonglong_double(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const double * value)6209 putNCvx_ulonglong_double(NC3_INFO* ncp, const NC_var *varp,
6210 		 const size_t *start, size_t nelems, const double *value)
6211 {
6212 	off_t offset = NC_varoffset(ncp, varp, start);
6213 	size_t remaining = varp->xsz * nelems;
6214 	int status = NC_NOERR;
6215 	void *xp;
6216         void *fillp=NULL;
6217 
6218 	NC_UNUSED(fillp);
6219 
6220 	if(nelems == 0)
6221 		return NC_NOERR;
6222 
6223 	assert(value != NULL);
6224 
6225 #ifdef ERANGE_FILL
6226         fillp = malloc(varp->xsz);
6227         status = NC3_inq_var_fill(varp, fillp);
6228 #endif
6229 
6230 	for(;;)
6231 	{
6232 		size_t extent = MIN(remaining, ncp->chunk);
6233 		size_t nput = ncx_howmany(varp->type, extent);
6234 
6235 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6236 				 RGN_WRITE, &xp);
6237 		if(lstatus != NC_NOERR)
6238 			return lstatus;
6239 
6240 		lstatus = ncx_putn_ulonglong_double(&xp, nput, value ,fillp);
6241 		if(lstatus != NC_NOERR && status == NC_NOERR)
6242 		{
6243 			/* not fatal to the loop */
6244 			status = lstatus;
6245 		}
6246 
6247 		(void) ncio_rel(ncp->nciop, offset,
6248 				 RGN_MODIFIED);
6249 
6250 		remaining -= extent;
6251 		if(remaining == 0)
6252 			break; /* normal loop exit */
6253 		offset += (off_t)extent;
6254 		value += nput;
6255 
6256 	}
6257 #ifdef ERANGE_FILL
6258         free(fillp);
6259 #endif
6260 
6261 	return status;
6262 }
6263 
6264 static int
putNCvx_ulonglong_longlong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const longlong * value)6265 putNCvx_ulonglong_longlong(NC3_INFO* ncp, const NC_var *varp,
6266 		 const size_t *start, size_t nelems, const longlong *value)
6267 {
6268 	off_t offset = NC_varoffset(ncp, varp, start);
6269 	size_t remaining = varp->xsz * nelems;
6270 	int status = NC_NOERR;
6271 	void *xp;
6272         void *fillp=NULL;
6273 
6274 	NC_UNUSED(fillp);
6275 
6276 	if(nelems == 0)
6277 		return NC_NOERR;
6278 
6279 	assert(value != NULL);
6280 
6281 #ifdef ERANGE_FILL
6282         fillp = malloc(varp->xsz);
6283         status = NC3_inq_var_fill(varp, fillp);
6284 #endif
6285 
6286 	for(;;)
6287 	{
6288 		size_t extent = MIN(remaining, ncp->chunk);
6289 		size_t nput = ncx_howmany(varp->type, extent);
6290 
6291 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6292 				 RGN_WRITE, &xp);
6293 		if(lstatus != NC_NOERR)
6294 			return lstatus;
6295 
6296 		lstatus = ncx_putn_ulonglong_longlong(&xp, nput, value ,fillp);
6297 		if(lstatus != NC_NOERR && status == NC_NOERR)
6298 		{
6299 			/* not fatal to the loop */
6300 			status = lstatus;
6301 		}
6302 
6303 		(void) ncio_rel(ncp->nciop, offset,
6304 				 RGN_MODIFIED);
6305 
6306 		remaining -= extent;
6307 		if(remaining == 0)
6308 			break; /* normal loop exit */
6309 		offset += (off_t)extent;
6310 		value += nput;
6311 
6312 	}
6313 #ifdef ERANGE_FILL
6314         free(fillp);
6315 #endif
6316 
6317 	return status;
6318 }
6319 
6320 static int
putNCvx_ulonglong_ushort(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ushort * value)6321 putNCvx_ulonglong_ushort(NC3_INFO* ncp, const NC_var *varp,
6322 		 const size_t *start, size_t nelems, const ushort *value)
6323 {
6324 	off_t offset = NC_varoffset(ncp, varp, start);
6325 	size_t remaining = varp->xsz * nelems;
6326 	int status = NC_NOERR;
6327 	void *xp;
6328         void *fillp=NULL;
6329 
6330 	NC_UNUSED(fillp);
6331 
6332 	if(nelems == 0)
6333 		return NC_NOERR;
6334 
6335 	assert(value != NULL);
6336 
6337 #ifdef ERANGE_FILL
6338         fillp = malloc(varp->xsz);
6339         status = NC3_inq_var_fill(varp, fillp);
6340 #endif
6341 
6342 	for(;;)
6343 	{
6344 		size_t extent = MIN(remaining, ncp->chunk);
6345 		size_t nput = ncx_howmany(varp->type, extent);
6346 
6347 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6348 				 RGN_WRITE, &xp);
6349 		if(lstatus != NC_NOERR)
6350 			return lstatus;
6351 
6352 		lstatus = ncx_putn_ulonglong_ushort(&xp, nput, value ,fillp);
6353 		if(lstatus != NC_NOERR && status == NC_NOERR)
6354 		{
6355 			/* not fatal to the loop */
6356 			status = lstatus;
6357 		}
6358 
6359 		(void) ncio_rel(ncp->nciop, offset,
6360 				 RGN_MODIFIED);
6361 
6362 		remaining -= extent;
6363 		if(remaining == 0)
6364 			break; /* normal loop exit */
6365 		offset += (off_t)extent;
6366 		value += nput;
6367 
6368 	}
6369 #ifdef ERANGE_FILL
6370         free(fillp);
6371 #endif
6372 
6373 	return status;
6374 }
6375 
6376 static int
putNCvx_ulonglong_uint(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const uint * value)6377 putNCvx_ulonglong_uint(NC3_INFO* ncp, const NC_var *varp,
6378 		 const size_t *start, size_t nelems, const uint *value)
6379 {
6380 	off_t offset = NC_varoffset(ncp, varp, start);
6381 	size_t remaining = varp->xsz * nelems;
6382 	int status = NC_NOERR;
6383 	void *xp;
6384         void *fillp=NULL;
6385 
6386 	NC_UNUSED(fillp);
6387 
6388 	if(nelems == 0)
6389 		return NC_NOERR;
6390 
6391 	assert(value != NULL);
6392 
6393 #ifdef ERANGE_FILL
6394         fillp = malloc(varp->xsz);
6395         status = NC3_inq_var_fill(varp, fillp);
6396 #endif
6397 
6398 	for(;;)
6399 	{
6400 		size_t extent = MIN(remaining, ncp->chunk);
6401 		size_t nput = ncx_howmany(varp->type, extent);
6402 
6403 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6404 				 RGN_WRITE, &xp);
6405 		if(lstatus != NC_NOERR)
6406 			return lstatus;
6407 
6408 		lstatus = ncx_putn_ulonglong_uint(&xp, nput, value ,fillp);
6409 		if(lstatus != NC_NOERR && status == NC_NOERR)
6410 		{
6411 			/* not fatal to the loop */
6412 			status = lstatus;
6413 		}
6414 
6415 		(void) ncio_rel(ncp->nciop, offset,
6416 				 RGN_MODIFIED);
6417 
6418 		remaining -= extent;
6419 		if(remaining == 0)
6420 			break; /* normal loop exit */
6421 		offset += (off_t)extent;
6422 		value += nput;
6423 
6424 	}
6425 #ifdef ERANGE_FILL
6426         free(fillp);
6427 #endif
6428 
6429 	return status;
6430 }
6431 
6432 static int
putNCvx_ulonglong_ulonglong(NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,const ulonglong * value)6433 putNCvx_ulonglong_ulonglong(NC3_INFO* ncp, const NC_var *varp,
6434 		 const size_t *start, size_t nelems, const ulonglong *value)
6435 {
6436 	off_t offset = NC_varoffset(ncp, varp, start);
6437 	size_t remaining = varp->xsz * nelems;
6438 	int status = NC_NOERR;
6439 	void *xp;
6440         void *fillp=NULL;
6441 
6442 	NC_UNUSED(fillp);
6443 
6444 	if(nelems == 0)
6445 		return NC_NOERR;
6446 
6447 	assert(value != NULL);
6448 
6449 #ifdef ERANGE_FILL
6450         fillp = malloc(varp->xsz);
6451         status = NC3_inq_var_fill(varp, fillp);
6452 #endif
6453 
6454 	for(;;)
6455 	{
6456 		size_t extent = MIN(remaining, ncp->chunk);
6457 		size_t nput = ncx_howmany(varp->type, extent);
6458 
6459 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6460 				 RGN_WRITE, &xp);
6461 		if(lstatus != NC_NOERR)
6462 			return lstatus;
6463 
6464 		lstatus = ncx_putn_ulonglong_ulonglong(&xp, nput, value ,fillp);
6465 		if(lstatus != NC_NOERR && status == NC_NOERR)
6466 		{
6467 			/* not fatal to the loop */
6468 			status = lstatus;
6469 		}
6470 
6471 		(void) ncio_rel(ncp->nciop, offset,
6472 				 RGN_MODIFIED);
6473 
6474 		remaining -= extent;
6475 		if(remaining == 0)
6476 			break; /* normal loop exit */
6477 		offset += (off_t)extent;
6478 		value += nput;
6479 
6480 	}
6481 #ifdef ERANGE_FILL
6482         free(fillp);
6483 #endif
6484 
6485 	return status;
6486 }
6487 
6488 
6489 
6490 #if 0 /*unused*/
6491 static int
6492 getNCvx_char_char(const NC3_INFO* ncp, const NC_var *varp,
6493 		 const size_t *start, size_t nelems, char *value)
6494 {
6495 	off_t offset = NC_varoffset(ncp, varp, start);
6496 	size_t remaining = varp->xsz * nelems;
6497 	int status = NC_NOERR;
6498 	const void *xp;
6499 
6500 	if(nelems == 0)
6501 		return NC_NOERR;
6502 
6503 	assert(value != NULL);
6504 
6505 	for(;;)
6506 	{
6507 		size_t extent = MIN(remaining, ncp->chunk);
6508 		size_t nget = ncx_howmany(varp->type, extent);
6509 
6510 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6511 				 0, (void **)&xp);	/* cast away const */
6512 		if(lstatus != NC_NOERR)
6513 			return lstatus;
6514 
6515 		lstatus = ncx_getn_char_char(&xp, nget, value);
6516 		if(lstatus != NC_NOERR && status == NC_NOERR)
6517 			status = lstatus;
6518 
6519 		(void) ncio_rel(ncp->nciop, offset, 0);
6520 
6521 		remaining -= extent;
6522 		if(remaining == 0)
6523 			break; /* normal loop exit */
6524 		offset += (off_t)extent;
6525 		value += nget;
6526 	}
6527 
6528 	return status;
6529 }
6530 
6531 #endif
6532 
6533 static int
getNCvx_schar_schar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,schar * value)6534 getNCvx_schar_schar(const NC3_INFO* ncp, const NC_var *varp,
6535 		 const size_t *start, size_t nelems, schar *value)
6536 {
6537 	off_t offset = NC_varoffset(ncp, varp, start);
6538 	size_t remaining = varp->xsz * nelems;
6539 	int status = NC_NOERR;
6540 	const void *xp;
6541 
6542 	if(nelems == 0)
6543 		return NC_NOERR;
6544 
6545 	assert(value != NULL);
6546 
6547 	for(;;)
6548 	{
6549 		size_t extent = MIN(remaining, ncp->chunk);
6550 		size_t nget = ncx_howmany(varp->type, extent);
6551 
6552 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6553 				 0, (void **)&xp);	/* cast away const */
6554 		if(lstatus != NC_NOERR)
6555 			return lstatus;
6556 
6557 		lstatus = ncx_getn_schar_schar(&xp, nget, value);
6558 		if(lstatus != NC_NOERR && status == NC_NOERR)
6559 			status = lstatus;
6560 
6561 		(void) ncio_rel(ncp->nciop, offset, 0);
6562 
6563 		remaining -= extent;
6564 		if(remaining == 0)
6565 			break; /* normal loop exit */
6566 		offset += (off_t)extent;
6567 		value += nget;
6568 	}
6569 
6570 	return status;
6571 }
6572 
6573 static int
getNCvx_schar_short(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,short * value)6574 getNCvx_schar_short(const NC3_INFO* ncp, const NC_var *varp,
6575 		 const size_t *start, size_t nelems, short *value)
6576 {
6577 	off_t offset = NC_varoffset(ncp, varp, start);
6578 	size_t remaining = varp->xsz * nelems;
6579 	int status = NC_NOERR;
6580 	const void *xp;
6581 
6582 	if(nelems == 0)
6583 		return NC_NOERR;
6584 
6585 	assert(value != NULL);
6586 
6587 	for(;;)
6588 	{
6589 		size_t extent = MIN(remaining, ncp->chunk);
6590 		size_t nget = ncx_howmany(varp->type, extent);
6591 
6592 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6593 				 0, (void **)&xp);	/* cast away const */
6594 		if(lstatus != NC_NOERR)
6595 			return lstatus;
6596 
6597 		lstatus = ncx_getn_schar_short(&xp, nget, value);
6598 		if(lstatus != NC_NOERR && status == NC_NOERR)
6599 			status = lstatus;
6600 
6601 		(void) ncio_rel(ncp->nciop, offset, 0);
6602 
6603 		remaining -= extent;
6604 		if(remaining == 0)
6605 			break; /* normal loop exit */
6606 		offset += (off_t)extent;
6607 		value += nget;
6608 	}
6609 
6610 	return status;
6611 }
6612 
6613 static int
getNCvx_schar_int(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,int * value)6614 getNCvx_schar_int(const NC3_INFO* ncp, const NC_var *varp,
6615 		 const size_t *start, size_t nelems, int *value)
6616 {
6617 	off_t offset = NC_varoffset(ncp, varp, start);
6618 	size_t remaining = varp->xsz * nelems;
6619 	int status = NC_NOERR;
6620 	const void *xp;
6621 
6622 	if(nelems == 0)
6623 		return NC_NOERR;
6624 
6625 	assert(value != NULL);
6626 
6627 	for(;;)
6628 	{
6629 		size_t extent = MIN(remaining, ncp->chunk);
6630 		size_t nget = ncx_howmany(varp->type, extent);
6631 
6632 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6633 				 0, (void **)&xp);	/* cast away const */
6634 		if(lstatus != NC_NOERR)
6635 			return lstatus;
6636 
6637 		lstatus = ncx_getn_schar_int(&xp, nget, value);
6638 		if(lstatus != NC_NOERR && status == NC_NOERR)
6639 			status = lstatus;
6640 
6641 		(void) ncio_rel(ncp->nciop, offset, 0);
6642 
6643 		remaining -= extent;
6644 		if(remaining == 0)
6645 			break; /* normal loop exit */
6646 		offset += (off_t)extent;
6647 		value += nget;
6648 	}
6649 
6650 	return status;
6651 }
6652 
6653 static int
getNCvx_schar_float(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,float * value)6654 getNCvx_schar_float(const NC3_INFO* ncp, const NC_var *varp,
6655 		 const size_t *start, size_t nelems, float *value)
6656 {
6657 	off_t offset = NC_varoffset(ncp, varp, start);
6658 	size_t remaining = varp->xsz * nelems;
6659 	int status = NC_NOERR;
6660 	const void *xp;
6661 
6662 	if(nelems == 0)
6663 		return NC_NOERR;
6664 
6665 	assert(value != NULL);
6666 
6667 	for(;;)
6668 	{
6669 		size_t extent = MIN(remaining, ncp->chunk);
6670 		size_t nget = ncx_howmany(varp->type, extent);
6671 
6672 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6673 				 0, (void **)&xp);	/* cast away const */
6674 		if(lstatus != NC_NOERR)
6675 			return lstatus;
6676 
6677 		lstatus = ncx_getn_schar_float(&xp, nget, value);
6678 		if(lstatus != NC_NOERR && status == NC_NOERR)
6679 			status = lstatus;
6680 
6681 		(void) ncio_rel(ncp->nciop, offset, 0);
6682 
6683 		remaining -= extent;
6684 		if(remaining == 0)
6685 			break; /* normal loop exit */
6686 		offset += (off_t)extent;
6687 		value += nget;
6688 	}
6689 
6690 	return status;
6691 }
6692 
6693 static int
getNCvx_schar_double(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,double * value)6694 getNCvx_schar_double(const NC3_INFO* ncp, const NC_var *varp,
6695 		 const size_t *start, size_t nelems, double *value)
6696 {
6697 	off_t offset = NC_varoffset(ncp, varp, start);
6698 	size_t remaining = varp->xsz * nelems;
6699 	int status = NC_NOERR;
6700 	const void *xp;
6701 
6702 	if(nelems == 0)
6703 		return NC_NOERR;
6704 
6705 	assert(value != NULL);
6706 
6707 	for(;;)
6708 	{
6709 		size_t extent = MIN(remaining, ncp->chunk);
6710 		size_t nget = ncx_howmany(varp->type, extent);
6711 
6712 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6713 				 0, (void **)&xp);	/* cast away const */
6714 		if(lstatus != NC_NOERR)
6715 			return lstatus;
6716 
6717 		lstatus = ncx_getn_schar_double(&xp, nget, value);
6718 		if(lstatus != NC_NOERR && status == NC_NOERR)
6719 			status = lstatus;
6720 
6721 		(void) ncio_rel(ncp->nciop, offset, 0);
6722 
6723 		remaining -= extent;
6724 		if(remaining == 0)
6725 			break; /* normal loop exit */
6726 		offset += (off_t)extent;
6727 		value += nget;
6728 	}
6729 
6730 	return status;
6731 }
6732 
6733 static int
getNCvx_schar_longlong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,longlong * value)6734 getNCvx_schar_longlong(const NC3_INFO* ncp, const NC_var *varp,
6735 		 const size_t *start, size_t nelems, longlong *value)
6736 {
6737 	off_t offset = NC_varoffset(ncp, varp, start);
6738 	size_t remaining = varp->xsz * nelems;
6739 	int status = NC_NOERR;
6740 	const void *xp;
6741 
6742 	if(nelems == 0)
6743 		return NC_NOERR;
6744 
6745 	assert(value != NULL);
6746 
6747 	for(;;)
6748 	{
6749 		size_t extent = MIN(remaining, ncp->chunk);
6750 		size_t nget = ncx_howmany(varp->type, extent);
6751 
6752 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6753 				 0, (void **)&xp);	/* cast away const */
6754 		if(lstatus != NC_NOERR)
6755 			return lstatus;
6756 
6757 		lstatus = ncx_getn_schar_longlong(&xp, nget, value);
6758 		if(lstatus != NC_NOERR && status == NC_NOERR)
6759 			status = lstatus;
6760 
6761 		(void) ncio_rel(ncp->nciop, offset, 0);
6762 
6763 		remaining -= extent;
6764 		if(remaining == 0)
6765 			break; /* normal loop exit */
6766 		offset += (off_t)extent;
6767 		value += nget;
6768 	}
6769 
6770 	return status;
6771 }
6772 
6773 static int
getNCvx_schar_uint(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uint * value)6774 getNCvx_schar_uint(const NC3_INFO* ncp, const NC_var *varp,
6775 		 const size_t *start, size_t nelems, uint *value)
6776 {
6777 	off_t offset = NC_varoffset(ncp, varp, start);
6778 	size_t remaining = varp->xsz * nelems;
6779 	int status = NC_NOERR;
6780 	const void *xp;
6781 
6782 	if(nelems == 0)
6783 		return NC_NOERR;
6784 
6785 	assert(value != NULL);
6786 
6787 	for(;;)
6788 	{
6789 		size_t extent = MIN(remaining, ncp->chunk);
6790 		size_t nget = ncx_howmany(varp->type, extent);
6791 
6792 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6793 				 0, (void **)&xp);	/* cast away const */
6794 		if(lstatus != NC_NOERR)
6795 			return lstatus;
6796 
6797 		lstatus = ncx_getn_schar_uint(&xp, nget, value);
6798 		if(lstatus != NC_NOERR && status == NC_NOERR)
6799 			status = lstatus;
6800 
6801 		(void) ncio_rel(ncp->nciop, offset, 0);
6802 
6803 		remaining -= extent;
6804 		if(remaining == 0)
6805 			break; /* normal loop exit */
6806 		offset += (off_t)extent;
6807 		value += nget;
6808 	}
6809 
6810 	return status;
6811 }
6812 
6813 static int
getNCvx_schar_ulonglong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ulonglong * value)6814 getNCvx_schar_ulonglong(const NC3_INFO* ncp, const NC_var *varp,
6815 		 const size_t *start, size_t nelems, ulonglong *value)
6816 {
6817 	off_t offset = NC_varoffset(ncp, varp, start);
6818 	size_t remaining = varp->xsz * nelems;
6819 	int status = NC_NOERR;
6820 	const void *xp;
6821 
6822 	if(nelems == 0)
6823 		return NC_NOERR;
6824 
6825 	assert(value != NULL);
6826 
6827 	for(;;)
6828 	{
6829 		size_t extent = MIN(remaining, ncp->chunk);
6830 		size_t nget = ncx_howmany(varp->type, extent);
6831 
6832 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6833 				 0, (void **)&xp);	/* cast away const */
6834 		if(lstatus != NC_NOERR)
6835 			return lstatus;
6836 
6837 		lstatus = ncx_getn_schar_ulonglong(&xp, nget, value);
6838 		if(lstatus != NC_NOERR && status == NC_NOERR)
6839 			status = lstatus;
6840 
6841 		(void) ncio_rel(ncp->nciop, offset, 0);
6842 
6843 		remaining -= extent;
6844 		if(remaining == 0)
6845 			break; /* normal loop exit */
6846 		offset += (off_t)extent;
6847 		value += nget;
6848 	}
6849 
6850 	return status;
6851 }
6852 
6853 static int
getNCvx_schar_uchar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uchar * value)6854 getNCvx_schar_uchar(const NC3_INFO* ncp, const NC_var *varp,
6855 		 const size_t *start, size_t nelems, uchar *value)
6856 {
6857 	off_t offset = NC_varoffset(ncp, varp, start);
6858 	size_t remaining = varp->xsz * nelems;
6859 	int status = NC_NOERR;
6860 	const void *xp;
6861 
6862 	if(nelems == 0)
6863 		return NC_NOERR;
6864 
6865 	assert(value != NULL);
6866 
6867 	for(;;)
6868 	{
6869 		size_t extent = MIN(remaining, ncp->chunk);
6870 		size_t nget = ncx_howmany(varp->type, extent);
6871 
6872 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6873 				 0, (void **)&xp);	/* cast away const */
6874 		if(lstatus != NC_NOERR)
6875 			return lstatus;
6876 
6877 		lstatus = ncx_getn_schar_uchar(&xp, nget, value);
6878 		if(lstatus != NC_NOERR && status == NC_NOERR)
6879 			status = lstatus;
6880 
6881 		(void) ncio_rel(ncp->nciop, offset, 0);
6882 
6883 		remaining -= extent;
6884 		if(remaining == 0)
6885 			break; /* normal loop exit */
6886 		offset += (off_t)extent;
6887 		value += nget;
6888 	}
6889 
6890 	return status;
6891 }
6892 
6893 static int
getNCvx_schar_ushort(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ushort * value)6894 getNCvx_schar_ushort(const NC3_INFO* ncp, const NC_var *varp,
6895 		 const size_t *start, size_t nelems, ushort *value)
6896 {
6897 	off_t offset = NC_varoffset(ncp, varp, start);
6898 	size_t remaining = varp->xsz * nelems;
6899 	int status = NC_NOERR;
6900 	const void *xp;
6901 
6902 	if(nelems == 0)
6903 		return NC_NOERR;
6904 
6905 	assert(value != NULL);
6906 
6907 	for(;;)
6908 	{
6909 		size_t extent = MIN(remaining, ncp->chunk);
6910 		size_t nget = ncx_howmany(varp->type, extent);
6911 
6912 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6913 				 0, (void **)&xp);	/* cast away const */
6914 		if(lstatus != NC_NOERR)
6915 			return lstatus;
6916 
6917 		lstatus = ncx_getn_schar_ushort(&xp, nget, value);
6918 		if(lstatus != NC_NOERR && status == NC_NOERR)
6919 			status = lstatus;
6920 
6921 		(void) ncio_rel(ncp->nciop, offset, 0);
6922 
6923 		remaining -= extent;
6924 		if(remaining == 0)
6925 			break; /* normal loop exit */
6926 		offset += (off_t)extent;
6927 		value += nget;
6928 	}
6929 
6930 	return status;
6931 }
6932 
6933 
6934 static int
getNCvx_short_schar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,schar * value)6935 getNCvx_short_schar(const NC3_INFO* ncp, const NC_var *varp,
6936 		 const size_t *start, size_t nelems, schar *value)
6937 {
6938 	off_t offset = NC_varoffset(ncp, varp, start);
6939 	size_t remaining = varp->xsz * nelems;
6940 	int status = NC_NOERR;
6941 	const void *xp;
6942 
6943 	if(nelems == 0)
6944 		return NC_NOERR;
6945 
6946 	assert(value != NULL);
6947 
6948 	for(;;)
6949 	{
6950 		size_t extent = MIN(remaining, ncp->chunk);
6951 		size_t nget = ncx_howmany(varp->type, extent);
6952 
6953 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6954 				 0, (void **)&xp);	/* cast away const */
6955 		if(lstatus != NC_NOERR)
6956 			return lstatus;
6957 
6958 		lstatus = ncx_getn_short_schar(&xp, nget, value);
6959 		if(lstatus != NC_NOERR && status == NC_NOERR)
6960 			status = lstatus;
6961 
6962 		(void) ncio_rel(ncp->nciop, offset, 0);
6963 
6964 		remaining -= extent;
6965 		if(remaining == 0)
6966 			break; /* normal loop exit */
6967 		offset += (off_t)extent;
6968 		value += nget;
6969 	}
6970 
6971 	return status;
6972 }
6973 
6974 static int
getNCvx_short_uchar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uchar * value)6975 getNCvx_short_uchar(const NC3_INFO* ncp, const NC_var *varp,
6976 		 const size_t *start, size_t nelems, uchar *value)
6977 {
6978 	off_t offset = NC_varoffset(ncp, varp, start);
6979 	size_t remaining = varp->xsz * nelems;
6980 	int status = NC_NOERR;
6981 	const void *xp;
6982 
6983 	if(nelems == 0)
6984 		return NC_NOERR;
6985 
6986 	assert(value != NULL);
6987 
6988 	for(;;)
6989 	{
6990 		size_t extent = MIN(remaining, ncp->chunk);
6991 		size_t nget = ncx_howmany(varp->type, extent);
6992 
6993 		int lstatus = ncio_get(ncp->nciop, offset, extent,
6994 				 0, (void **)&xp);	/* cast away const */
6995 		if(lstatus != NC_NOERR)
6996 			return lstatus;
6997 
6998 		lstatus = ncx_getn_short_uchar(&xp, nget, value);
6999 		if(lstatus != NC_NOERR && status == NC_NOERR)
7000 			status = lstatus;
7001 
7002 		(void) ncio_rel(ncp->nciop, offset, 0);
7003 
7004 		remaining -= extent;
7005 		if(remaining == 0)
7006 			break; /* normal loop exit */
7007 		offset += (off_t)extent;
7008 		value += nget;
7009 	}
7010 
7011 	return status;
7012 }
7013 
7014 static int
getNCvx_short_short(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,short * value)7015 getNCvx_short_short(const NC3_INFO* ncp, const NC_var *varp,
7016 		 const size_t *start, size_t nelems, short *value)
7017 {
7018 	off_t offset = NC_varoffset(ncp, varp, start);
7019 	size_t remaining = varp->xsz * nelems;
7020 	int status = NC_NOERR;
7021 	const void *xp;
7022 
7023 	if(nelems == 0)
7024 		return NC_NOERR;
7025 
7026 	assert(value != NULL);
7027 
7028 	for(;;)
7029 	{
7030 		size_t extent = MIN(remaining, ncp->chunk);
7031 		size_t nget = ncx_howmany(varp->type, extent);
7032 
7033 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7034 				 0, (void **)&xp);	/* cast away const */
7035 		if(lstatus != NC_NOERR)
7036 			return lstatus;
7037 
7038 		lstatus = ncx_getn_short_short(&xp, nget, value);
7039 		if(lstatus != NC_NOERR && status == NC_NOERR)
7040 			status = lstatus;
7041 
7042 		(void) ncio_rel(ncp->nciop, offset, 0);
7043 
7044 		remaining -= extent;
7045 		if(remaining == 0)
7046 			break; /* normal loop exit */
7047 		offset += (off_t)extent;
7048 		value += nget;
7049 	}
7050 
7051 	return status;
7052 }
7053 
7054 static int
getNCvx_short_int(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,int * value)7055 getNCvx_short_int(const NC3_INFO* ncp, const NC_var *varp,
7056 		 const size_t *start, size_t nelems, int *value)
7057 {
7058 	off_t offset = NC_varoffset(ncp, varp, start);
7059 	size_t remaining = varp->xsz * nelems;
7060 	int status = NC_NOERR;
7061 	const void *xp;
7062 
7063 	if(nelems == 0)
7064 		return NC_NOERR;
7065 
7066 	assert(value != NULL);
7067 
7068 	for(;;)
7069 	{
7070 		size_t extent = MIN(remaining, ncp->chunk);
7071 		size_t nget = ncx_howmany(varp->type, extent);
7072 
7073 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7074 				 0, (void **)&xp);	/* cast away const */
7075 		if(lstatus != NC_NOERR)
7076 			return lstatus;
7077 
7078 		lstatus = ncx_getn_short_int(&xp, nget, value);
7079 		if(lstatus != NC_NOERR && status == NC_NOERR)
7080 			status = lstatus;
7081 
7082 		(void) ncio_rel(ncp->nciop, offset, 0);
7083 
7084 		remaining -= extent;
7085 		if(remaining == 0)
7086 			break; /* normal loop exit */
7087 		offset += (off_t)extent;
7088 		value += nget;
7089 	}
7090 
7091 	return status;
7092 }
7093 
7094 static int
getNCvx_short_float(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,float * value)7095 getNCvx_short_float(const NC3_INFO* ncp, const NC_var *varp,
7096 		 const size_t *start, size_t nelems, float *value)
7097 {
7098 	off_t offset = NC_varoffset(ncp, varp, start);
7099 	size_t remaining = varp->xsz * nelems;
7100 	int status = NC_NOERR;
7101 	const void *xp;
7102 
7103 	if(nelems == 0)
7104 		return NC_NOERR;
7105 
7106 	assert(value != NULL);
7107 
7108 	for(;;)
7109 	{
7110 		size_t extent = MIN(remaining, ncp->chunk);
7111 		size_t nget = ncx_howmany(varp->type, extent);
7112 
7113 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7114 				 0, (void **)&xp);	/* cast away const */
7115 		if(lstatus != NC_NOERR)
7116 			return lstatus;
7117 
7118 		lstatus = ncx_getn_short_float(&xp, nget, value);
7119 		if(lstatus != NC_NOERR && status == NC_NOERR)
7120 			status = lstatus;
7121 
7122 		(void) ncio_rel(ncp->nciop, offset, 0);
7123 
7124 		remaining -= extent;
7125 		if(remaining == 0)
7126 			break; /* normal loop exit */
7127 		offset += (off_t)extent;
7128 		value += nget;
7129 	}
7130 
7131 	return status;
7132 }
7133 
7134 static int
getNCvx_short_double(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,double * value)7135 getNCvx_short_double(const NC3_INFO* ncp, const NC_var *varp,
7136 		 const size_t *start, size_t nelems, double *value)
7137 {
7138 	off_t offset = NC_varoffset(ncp, varp, start);
7139 	size_t remaining = varp->xsz * nelems;
7140 	int status = NC_NOERR;
7141 	const void *xp;
7142 
7143 	if(nelems == 0)
7144 		return NC_NOERR;
7145 
7146 	assert(value != NULL);
7147 
7148 	for(;;)
7149 	{
7150 		size_t extent = MIN(remaining, ncp->chunk);
7151 		size_t nget = ncx_howmany(varp->type, extent);
7152 
7153 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7154 				 0, (void **)&xp);	/* cast away const */
7155 		if(lstatus != NC_NOERR)
7156 			return lstatus;
7157 
7158 		lstatus = ncx_getn_short_double(&xp, nget, value);
7159 		if(lstatus != NC_NOERR && status == NC_NOERR)
7160 			status = lstatus;
7161 
7162 		(void) ncio_rel(ncp->nciop, offset, 0);
7163 
7164 		remaining -= extent;
7165 		if(remaining == 0)
7166 			break; /* normal loop exit */
7167 		offset += (off_t)extent;
7168 		value += nget;
7169 	}
7170 
7171 	return status;
7172 }
7173 
7174 static int
getNCvx_short_longlong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,longlong * value)7175 getNCvx_short_longlong(const NC3_INFO* ncp, const NC_var *varp,
7176 		 const size_t *start, size_t nelems, longlong *value)
7177 {
7178 	off_t offset = NC_varoffset(ncp, varp, start);
7179 	size_t remaining = varp->xsz * nelems;
7180 	int status = NC_NOERR;
7181 	const void *xp;
7182 
7183 	if(nelems == 0)
7184 		return NC_NOERR;
7185 
7186 	assert(value != NULL);
7187 
7188 	for(;;)
7189 	{
7190 		size_t extent = MIN(remaining, ncp->chunk);
7191 		size_t nget = ncx_howmany(varp->type, extent);
7192 
7193 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7194 				 0, (void **)&xp);	/* cast away const */
7195 		if(lstatus != NC_NOERR)
7196 			return lstatus;
7197 
7198 		lstatus = ncx_getn_short_longlong(&xp, nget, value);
7199 		if(lstatus != NC_NOERR && status == NC_NOERR)
7200 			status = lstatus;
7201 
7202 		(void) ncio_rel(ncp->nciop, offset, 0);
7203 
7204 		remaining -= extent;
7205 		if(remaining == 0)
7206 			break; /* normal loop exit */
7207 		offset += (off_t)extent;
7208 		value += nget;
7209 	}
7210 
7211 	return status;
7212 }
7213 
7214 static int
getNCvx_short_uint(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uint * value)7215 getNCvx_short_uint(const NC3_INFO* ncp, const NC_var *varp,
7216 		 const size_t *start, size_t nelems, uint *value)
7217 {
7218 	off_t offset = NC_varoffset(ncp, varp, start);
7219 	size_t remaining = varp->xsz * nelems;
7220 	int status = NC_NOERR;
7221 	const void *xp;
7222 
7223 	if(nelems == 0)
7224 		return NC_NOERR;
7225 
7226 	assert(value != NULL);
7227 
7228 	for(;;)
7229 	{
7230 		size_t extent = MIN(remaining, ncp->chunk);
7231 		size_t nget = ncx_howmany(varp->type, extent);
7232 
7233 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7234 				 0, (void **)&xp);	/* cast away const */
7235 		if(lstatus != NC_NOERR)
7236 			return lstatus;
7237 
7238 		lstatus = ncx_getn_short_uint(&xp, nget, value);
7239 		if(lstatus != NC_NOERR && status == NC_NOERR)
7240 			status = lstatus;
7241 
7242 		(void) ncio_rel(ncp->nciop, offset, 0);
7243 
7244 		remaining -= extent;
7245 		if(remaining == 0)
7246 			break; /* normal loop exit */
7247 		offset += (off_t)extent;
7248 		value += nget;
7249 	}
7250 
7251 	return status;
7252 }
7253 
7254 static int
getNCvx_short_ulonglong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ulonglong * value)7255 getNCvx_short_ulonglong(const NC3_INFO* ncp, const NC_var *varp,
7256 		 const size_t *start, size_t nelems, ulonglong *value)
7257 {
7258 	off_t offset = NC_varoffset(ncp, varp, start);
7259 	size_t remaining = varp->xsz * nelems;
7260 	int status = NC_NOERR;
7261 	const void *xp;
7262 
7263 	if(nelems == 0)
7264 		return NC_NOERR;
7265 
7266 	assert(value != NULL);
7267 
7268 	for(;;)
7269 	{
7270 		size_t extent = MIN(remaining, ncp->chunk);
7271 		size_t nget = ncx_howmany(varp->type, extent);
7272 
7273 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7274 				 0, (void **)&xp);	/* cast away const */
7275 		if(lstatus != NC_NOERR)
7276 			return lstatus;
7277 
7278 		lstatus = ncx_getn_short_ulonglong(&xp, nget, value);
7279 		if(lstatus != NC_NOERR && status == NC_NOERR)
7280 			status = lstatus;
7281 
7282 		(void) ncio_rel(ncp->nciop, offset, 0);
7283 
7284 		remaining -= extent;
7285 		if(remaining == 0)
7286 			break; /* normal loop exit */
7287 		offset += (off_t)extent;
7288 		value += nget;
7289 	}
7290 
7291 	return status;
7292 }
7293 
7294 static int
getNCvx_short_ushort(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ushort * value)7295 getNCvx_short_ushort(const NC3_INFO* ncp, const NC_var *varp,
7296 		 const size_t *start, size_t nelems, ushort *value)
7297 {
7298 	off_t offset = NC_varoffset(ncp, varp, start);
7299 	size_t remaining = varp->xsz * nelems;
7300 	int status = NC_NOERR;
7301 	const void *xp;
7302 
7303 	if(nelems == 0)
7304 		return NC_NOERR;
7305 
7306 	assert(value != NULL);
7307 
7308 	for(;;)
7309 	{
7310 		size_t extent = MIN(remaining, ncp->chunk);
7311 		size_t nget = ncx_howmany(varp->type, extent);
7312 
7313 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7314 				 0, (void **)&xp);	/* cast away const */
7315 		if(lstatus != NC_NOERR)
7316 			return lstatus;
7317 
7318 		lstatus = ncx_getn_short_ushort(&xp, nget, value);
7319 		if(lstatus != NC_NOERR && status == NC_NOERR)
7320 			status = lstatus;
7321 
7322 		(void) ncio_rel(ncp->nciop, offset, 0);
7323 
7324 		remaining -= extent;
7325 		if(remaining == 0)
7326 			break; /* normal loop exit */
7327 		offset += (off_t)extent;
7328 		value += nget;
7329 	}
7330 
7331 	return status;
7332 }
7333 
7334 
7335 static int
getNCvx_int_schar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,schar * value)7336 getNCvx_int_schar(const NC3_INFO* ncp, const NC_var *varp,
7337 		 const size_t *start, size_t nelems, schar *value)
7338 {
7339 	off_t offset = NC_varoffset(ncp, varp, start);
7340 	size_t remaining = varp->xsz * nelems;
7341 	int status = NC_NOERR;
7342 	const void *xp;
7343 
7344 	if(nelems == 0)
7345 		return NC_NOERR;
7346 
7347 	assert(value != NULL);
7348 
7349 	for(;;)
7350 	{
7351 		size_t extent = MIN(remaining, ncp->chunk);
7352 		size_t nget = ncx_howmany(varp->type, extent);
7353 
7354 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7355 				 0, (void **)&xp);	/* cast away const */
7356 		if(lstatus != NC_NOERR)
7357 			return lstatus;
7358 
7359 		lstatus = ncx_getn_int_schar(&xp, nget, value);
7360 		if(lstatus != NC_NOERR && status == NC_NOERR)
7361 			status = lstatus;
7362 
7363 		(void) ncio_rel(ncp->nciop, offset, 0);
7364 
7365 		remaining -= extent;
7366 		if(remaining == 0)
7367 			break; /* normal loop exit */
7368 		offset += (off_t)extent;
7369 		value += nget;
7370 	}
7371 
7372 	return status;
7373 }
7374 
7375 static int
getNCvx_int_uchar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uchar * value)7376 getNCvx_int_uchar(const NC3_INFO* ncp, const NC_var *varp,
7377 		 const size_t *start, size_t nelems, uchar *value)
7378 {
7379 	off_t offset = NC_varoffset(ncp, varp, start);
7380 	size_t remaining = varp->xsz * nelems;
7381 	int status = NC_NOERR;
7382 	const void *xp;
7383 
7384 	if(nelems == 0)
7385 		return NC_NOERR;
7386 
7387 	assert(value != NULL);
7388 
7389 	for(;;)
7390 	{
7391 		size_t extent = MIN(remaining, ncp->chunk);
7392 		size_t nget = ncx_howmany(varp->type, extent);
7393 
7394 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7395 				 0, (void **)&xp);	/* cast away const */
7396 		if(lstatus != NC_NOERR)
7397 			return lstatus;
7398 
7399 		lstatus = ncx_getn_int_uchar(&xp, nget, value);
7400 		if(lstatus != NC_NOERR && status == NC_NOERR)
7401 			status = lstatus;
7402 
7403 		(void) ncio_rel(ncp->nciop, offset, 0);
7404 
7405 		remaining -= extent;
7406 		if(remaining == 0)
7407 			break; /* normal loop exit */
7408 		offset += (off_t)extent;
7409 		value += nget;
7410 	}
7411 
7412 	return status;
7413 }
7414 
7415 static int
getNCvx_int_short(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,short * value)7416 getNCvx_int_short(const NC3_INFO* ncp, const NC_var *varp,
7417 		 const size_t *start, size_t nelems, short *value)
7418 {
7419 	off_t offset = NC_varoffset(ncp, varp, start);
7420 	size_t remaining = varp->xsz * nelems;
7421 	int status = NC_NOERR;
7422 	const void *xp;
7423 
7424 	if(nelems == 0)
7425 		return NC_NOERR;
7426 
7427 	assert(value != NULL);
7428 
7429 	for(;;)
7430 	{
7431 		size_t extent = MIN(remaining, ncp->chunk);
7432 		size_t nget = ncx_howmany(varp->type, extent);
7433 
7434 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7435 				 0, (void **)&xp);	/* cast away const */
7436 		if(lstatus != NC_NOERR)
7437 			return lstatus;
7438 
7439 		lstatus = ncx_getn_int_short(&xp, nget, value);
7440 		if(lstatus != NC_NOERR && status == NC_NOERR)
7441 			status = lstatus;
7442 
7443 		(void) ncio_rel(ncp->nciop, offset, 0);
7444 
7445 		remaining -= extent;
7446 		if(remaining == 0)
7447 			break; /* normal loop exit */
7448 		offset += (off_t)extent;
7449 		value += nget;
7450 	}
7451 
7452 	return status;
7453 }
7454 
7455 static int
getNCvx_int_int(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,int * value)7456 getNCvx_int_int(const NC3_INFO* ncp, const NC_var *varp,
7457 		 const size_t *start, size_t nelems, int *value)
7458 {
7459 	off_t offset = NC_varoffset(ncp, varp, start);
7460 	size_t remaining = varp->xsz * nelems;
7461 	int status = NC_NOERR;
7462 	const void *xp;
7463 
7464 	if(nelems == 0)
7465 		return NC_NOERR;
7466 
7467 	assert(value != NULL);
7468 
7469 	for(;;)
7470 	{
7471 		size_t extent = MIN(remaining, ncp->chunk);
7472 		size_t nget = ncx_howmany(varp->type, extent);
7473 
7474 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7475 				 0, (void **)&xp);	/* cast away const */
7476 		if(lstatus != NC_NOERR)
7477 			return lstatus;
7478 
7479 		lstatus = ncx_getn_int_int(&xp, nget, value);
7480 		if(lstatus != NC_NOERR && status == NC_NOERR)
7481 			status = lstatus;
7482 
7483 		(void) ncio_rel(ncp->nciop, offset, 0);
7484 
7485 		remaining -= extent;
7486 		if(remaining == 0)
7487 			break; /* normal loop exit */
7488 		offset += (off_t)extent;
7489 		value += nget;
7490 	}
7491 
7492 	return status;
7493 }
7494 
7495 static int
getNCvx_int_float(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,float * value)7496 getNCvx_int_float(const NC3_INFO* ncp, const NC_var *varp,
7497 		 const size_t *start, size_t nelems, float *value)
7498 {
7499 	off_t offset = NC_varoffset(ncp, varp, start);
7500 	size_t remaining = varp->xsz * nelems;
7501 	int status = NC_NOERR;
7502 	const void *xp;
7503 
7504 	if(nelems == 0)
7505 		return NC_NOERR;
7506 
7507 	assert(value != NULL);
7508 
7509 	for(;;)
7510 	{
7511 		size_t extent = MIN(remaining, ncp->chunk);
7512 		size_t nget = ncx_howmany(varp->type, extent);
7513 
7514 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7515 				 0, (void **)&xp);	/* cast away const */
7516 		if(lstatus != NC_NOERR)
7517 			return lstatus;
7518 
7519 		lstatus = ncx_getn_int_float(&xp, nget, value);
7520 		if(lstatus != NC_NOERR && status == NC_NOERR)
7521 			status = lstatus;
7522 
7523 		(void) ncio_rel(ncp->nciop, offset, 0);
7524 
7525 		remaining -= extent;
7526 		if(remaining == 0)
7527 			break; /* normal loop exit */
7528 		offset += (off_t)extent;
7529 		value += nget;
7530 	}
7531 
7532 	return status;
7533 }
7534 
7535 static int
getNCvx_int_double(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,double * value)7536 getNCvx_int_double(const NC3_INFO* ncp, const NC_var *varp,
7537 		 const size_t *start, size_t nelems, double *value)
7538 {
7539 	off_t offset = NC_varoffset(ncp, varp, start);
7540 	size_t remaining = varp->xsz * nelems;
7541 	int status = NC_NOERR;
7542 	const void *xp;
7543 
7544 	if(nelems == 0)
7545 		return NC_NOERR;
7546 
7547 	assert(value != NULL);
7548 
7549 	for(;;)
7550 	{
7551 		size_t extent = MIN(remaining, ncp->chunk);
7552 		size_t nget = ncx_howmany(varp->type, extent);
7553 
7554 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7555 				 0, (void **)&xp);	/* cast away const */
7556 		if(lstatus != NC_NOERR)
7557 			return lstatus;
7558 
7559 		lstatus = ncx_getn_int_double(&xp, nget, value);
7560 		if(lstatus != NC_NOERR && status == NC_NOERR)
7561 			status = lstatus;
7562 
7563 		(void) ncio_rel(ncp->nciop, offset, 0);
7564 
7565 		remaining -= extent;
7566 		if(remaining == 0)
7567 			break; /* normal loop exit */
7568 		offset += (off_t)extent;
7569 		value += nget;
7570 	}
7571 
7572 	return status;
7573 }
7574 
7575 static int
getNCvx_int_longlong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,longlong * value)7576 getNCvx_int_longlong(const NC3_INFO* ncp, const NC_var *varp,
7577 		 const size_t *start, size_t nelems, longlong *value)
7578 {
7579 	off_t offset = NC_varoffset(ncp, varp, start);
7580 	size_t remaining = varp->xsz * nelems;
7581 	int status = NC_NOERR;
7582 	const void *xp;
7583 
7584 	if(nelems == 0)
7585 		return NC_NOERR;
7586 
7587 	assert(value != NULL);
7588 
7589 	for(;;)
7590 	{
7591 		size_t extent = MIN(remaining, ncp->chunk);
7592 		size_t nget = ncx_howmany(varp->type, extent);
7593 
7594 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7595 				 0, (void **)&xp);	/* cast away const */
7596 		if(lstatus != NC_NOERR)
7597 			return lstatus;
7598 
7599 		lstatus = ncx_getn_int_longlong(&xp, nget, value);
7600 		if(lstatus != NC_NOERR && status == NC_NOERR)
7601 			status = lstatus;
7602 
7603 		(void) ncio_rel(ncp->nciop, offset, 0);
7604 
7605 		remaining -= extent;
7606 		if(remaining == 0)
7607 			break; /* normal loop exit */
7608 		offset += (off_t)extent;
7609 		value += nget;
7610 	}
7611 
7612 	return status;
7613 }
7614 
7615 static int
getNCvx_int_uint(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uint * value)7616 getNCvx_int_uint(const NC3_INFO* ncp, const NC_var *varp,
7617 		 const size_t *start, size_t nelems, uint *value)
7618 {
7619 	off_t offset = NC_varoffset(ncp, varp, start);
7620 	size_t remaining = varp->xsz * nelems;
7621 	int status = NC_NOERR;
7622 	const void *xp;
7623 
7624 	if(nelems == 0)
7625 		return NC_NOERR;
7626 
7627 	assert(value != NULL);
7628 
7629 	for(;;)
7630 	{
7631 		size_t extent = MIN(remaining, ncp->chunk);
7632 		size_t nget = ncx_howmany(varp->type, extent);
7633 
7634 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7635 				 0, (void **)&xp);	/* cast away const */
7636 		if(lstatus != NC_NOERR)
7637 			return lstatus;
7638 
7639 		lstatus = ncx_getn_int_uint(&xp, nget, value);
7640 		if(lstatus != NC_NOERR && status == NC_NOERR)
7641 			status = lstatus;
7642 
7643 		(void) ncio_rel(ncp->nciop, offset, 0);
7644 
7645 		remaining -= extent;
7646 		if(remaining == 0)
7647 			break; /* normal loop exit */
7648 		offset += (off_t)extent;
7649 		value += nget;
7650 	}
7651 
7652 	return status;
7653 }
7654 
7655 static int
getNCvx_int_ulonglong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ulonglong * value)7656 getNCvx_int_ulonglong(const NC3_INFO* ncp, const NC_var *varp,
7657 		 const size_t *start, size_t nelems, ulonglong *value)
7658 {
7659 	off_t offset = NC_varoffset(ncp, varp, start);
7660 	size_t remaining = varp->xsz * nelems;
7661 	int status = NC_NOERR;
7662 	const void *xp;
7663 
7664 	if(nelems == 0)
7665 		return NC_NOERR;
7666 
7667 	assert(value != NULL);
7668 
7669 	for(;;)
7670 	{
7671 		size_t extent = MIN(remaining, ncp->chunk);
7672 		size_t nget = ncx_howmany(varp->type, extent);
7673 
7674 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7675 				 0, (void **)&xp);	/* cast away const */
7676 		if(lstatus != NC_NOERR)
7677 			return lstatus;
7678 
7679 		lstatus = ncx_getn_int_ulonglong(&xp, nget, value);
7680 		if(lstatus != NC_NOERR && status == NC_NOERR)
7681 			status = lstatus;
7682 
7683 		(void) ncio_rel(ncp->nciop, offset, 0);
7684 
7685 		remaining -= extent;
7686 		if(remaining == 0)
7687 			break; /* normal loop exit */
7688 		offset += (off_t)extent;
7689 		value += nget;
7690 	}
7691 
7692 	return status;
7693 }
7694 
7695 static int
getNCvx_int_ushort(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ushort * value)7696 getNCvx_int_ushort(const NC3_INFO* ncp, const NC_var *varp,
7697 		 const size_t *start, size_t nelems, ushort *value)
7698 {
7699 	off_t offset = NC_varoffset(ncp, varp, start);
7700 	size_t remaining = varp->xsz * nelems;
7701 	int status = NC_NOERR;
7702 	const void *xp;
7703 
7704 	if(nelems == 0)
7705 		return NC_NOERR;
7706 
7707 	assert(value != NULL);
7708 
7709 	for(;;)
7710 	{
7711 		size_t extent = MIN(remaining, ncp->chunk);
7712 		size_t nget = ncx_howmany(varp->type, extent);
7713 
7714 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7715 				 0, (void **)&xp);	/* cast away const */
7716 		if(lstatus != NC_NOERR)
7717 			return lstatus;
7718 
7719 		lstatus = ncx_getn_int_ushort(&xp, nget, value);
7720 		if(lstatus != NC_NOERR && status == NC_NOERR)
7721 			status = lstatus;
7722 
7723 		(void) ncio_rel(ncp->nciop, offset, 0);
7724 
7725 		remaining -= extent;
7726 		if(remaining == 0)
7727 			break; /* normal loop exit */
7728 		offset += (off_t)extent;
7729 		value += nget;
7730 	}
7731 
7732 	return status;
7733 }
7734 
7735 
7736 static int
getNCvx_float_schar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,schar * value)7737 getNCvx_float_schar(const NC3_INFO* ncp, const NC_var *varp,
7738 		 const size_t *start, size_t nelems, schar *value)
7739 {
7740 	off_t offset = NC_varoffset(ncp, varp, start);
7741 	size_t remaining = varp->xsz * nelems;
7742 	int status = NC_NOERR;
7743 	const void *xp;
7744 
7745 	if(nelems == 0)
7746 		return NC_NOERR;
7747 
7748 	assert(value != NULL);
7749 
7750 	for(;;)
7751 	{
7752 		size_t extent = MIN(remaining, ncp->chunk);
7753 		size_t nget = ncx_howmany(varp->type, extent);
7754 
7755 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7756 				 0, (void **)&xp);	/* cast away const */
7757 		if(lstatus != NC_NOERR)
7758 			return lstatus;
7759 
7760 		lstatus = ncx_getn_float_schar(&xp, nget, value);
7761 		if(lstatus != NC_NOERR && status == NC_NOERR)
7762 			status = lstatus;
7763 
7764 		(void) ncio_rel(ncp->nciop, offset, 0);
7765 
7766 		remaining -= extent;
7767 		if(remaining == 0)
7768 			break; /* normal loop exit */
7769 		offset += (off_t)extent;
7770 		value += nget;
7771 	}
7772 
7773 	return status;
7774 }
7775 
7776 static int
getNCvx_float_uchar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uchar * value)7777 getNCvx_float_uchar(const NC3_INFO* ncp, const NC_var *varp,
7778 		 const size_t *start, size_t nelems, uchar *value)
7779 {
7780 	off_t offset = NC_varoffset(ncp, varp, start);
7781 	size_t remaining = varp->xsz * nelems;
7782 	int status = NC_NOERR;
7783 	const void *xp;
7784 
7785 	if(nelems == 0)
7786 		return NC_NOERR;
7787 
7788 	assert(value != NULL);
7789 
7790 	for(;;)
7791 	{
7792 		size_t extent = MIN(remaining, ncp->chunk);
7793 		size_t nget = ncx_howmany(varp->type, extent);
7794 
7795 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7796 				 0, (void **)&xp);	/* cast away const */
7797 		if(lstatus != NC_NOERR)
7798 			return lstatus;
7799 
7800 		lstatus = ncx_getn_float_uchar(&xp, nget, value);
7801 		if(lstatus != NC_NOERR && status == NC_NOERR)
7802 			status = lstatus;
7803 
7804 		(void) ncio_rel(ncp->nciop, offset, 0);
7805 
7806 		remaining -= extent;
7807 		if(remaining == 0)
7808 			break; /* normal loop exit */
7809 		offset += (off_t)extent;
7810 		value += nget;
7811 	}
7812 
7813 	return status;
7814 }
7815 
7816 static int
getNCvx_float_short(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,short * value)7817 getNCvx_float_short(const NC3_INFO* ncp, const NC_var *varp,
7818 		 const size_t *start, size_t nelems, short *value)
7819 {
7820 	off_t offset = NC_varoffset(ncp, varp, start);
7821 	size_t remaining = varp->xsz * nelems;
7822 	int status = NC_NOERR;
7823 	const void *xp;
7824 
7825 	if(nelems == 0)
7826 		return NC_NOERR;
7827 
7828 	assert(value != NULL);
7829 
7830 	for(;;)
7831 	{
7832 		size_t extent = MIN(remaining, ncp->chunk);
7833 		size_t nget = ncx_howmany(varp->type, extent);
7834 
7835 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7836 				 0, (void **)&xp);	/* cast away const */
7837 		if(lstatus != NC_NOERR)
7838 			return lstatus;
7839 
7840 		lstatus = ncx_getn_float_short(&xp, nget, value);
7841 		if(lstatus != NC_NOERR && status == NC_NOERR)
7842 			status = lstatus;
7843 
7844 		(void) ncio_rel(ncp->nciop, offset, 0);
7845 
7846 		remaining -= extent;
7847 		if(remaining == 0)
7848 			break; /* normal loop exit */
7849 		offset += (off_t)extent;
7850 		value += nget;
7851 	}
7852 
7853 	return status;
7854 }
7855 
7856 static int
getNCvx_float_int(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,int * value)7857 getNCvx_float_int(const NC3_INFO* ncp, const NC_var *varp,
7858 		 const size_t *start, size_t nelems, int *value)
7859 {
7860 	off_t offset = NC_varoffset(ncp, varp, start);
7861 	size_t remaining = varp->xsz * nelems;
7862 	int status = NC_NOERR;
7863 	const void *xp;
7864 
7865 	if(nelems == 0)
7866 		return NC_NOERR;
7867 
7868 	assert(value != NULL);
7869 
7870 	for(;;)
7871 	{
7872 		size_t extent = MIN(remaining, ncp->chunk);
7873 		size_t nget = ncx_howmany(varp->type, extent);
7874 
7875 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7876 				 0, (void **)&xp);	/* cast away const */
7877 		if(lstatus != NC_NOERR)
7878 			return lstatus;
7879 
7880 		lstatus = ncx_getn_float_int(&xp, nget, value);
7881 		if(lstatus != NC_NOERR && status == NC_NOERR)
7882 			status = lstatus;
7883 
7884 		(void) ncio_rel(ncp->nciop, offset, 0);
7885 
7886 		remaining -= extent;
7887 		if(remaining == 0)
7888 			break; /* normal loop exit */
7889 		offset += (off_t)extent;
7890 		value += nget;
7891 	}
7892 
7893 	return status;
7894 }
7895 
7896 static int
getNCvx_float_float(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,float * value)7897 getNCvx_float_float(const NC3_INFO* ncp, const NC_var *varp,
7898 		 const size_t *start, size_t nelems, float *value)
7899 {
7900 	off_t offset = NC_varoffset(ncp, varp, start);
7901 	size_t remaining = varp->xsz * nelems;
7902 	int status = NC_NOERR;
7903 	const void *xp;
7904 
7905 	if(nelems == 0)
7906 		return NC_NOERR;
7907 
7908 	assert(value != NULL);
7909 
7910 	for(;;)
7911 	{
7912 		size_t extent = MIN(remaining, ncp->chunk);
7913 		size_t nget = ncx_howmany(varp->type, extent);
7914 
7915 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7916 				 0, (void **)&xp);	/* cast away const */
7917 		if(lstatus != NC_NOERR)
7918 			return lstatus;
7919 
7920 		lstatus = ncx_getn_float_float(&xp, nget, value);
7921 		if(lstatus != NC_NOERR && status == NC_NOERR)
7922 			status = lstatus;
7923 
7924 		(void) ncio_rel(ncp->nciop, offset, 0);
7925 
7926 		remaining -= extent;
7927 		if(remaining == 0)
7928 			break; /* normal loop exit */
7929 		offset += (off_t)extent;
7930 		value += nget;
7931 	}
7932 
7933 	return status;
7934 }
7935 
7936 static int
getNCvx_float_double(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,double * value)7937 getNCvx_float_double(const NC3_INFO* ncp, const NC_var *varp,
7938 		 const size_t *start, size_t nelems, double *value)
7939 {
7940 	off_t offset = NC_varoffset(ncp, varp, start);
7941 	size_t remaining = varp->xsz * nelems;
7942 	int status = NC_NOERR;
7943 	const void *xp;
7944 
7945 	if(nelems == 0)
7946 		return NC_NOERR;
7947 
7948 	assert(value != NULL);
7949 
7950 	for(;;)
7951 	{
7952 		size_t extent = MIN(remaining, ncp->chunk);
7953 		size_t nget = ncx_howmany(varp->type, extent);
7954 
7955 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7956 				 0, (void **)&xp);	/* cast away const */
7957 		if(lstatus != NC_NOERR)
7958 			return lstatus;
7959 
7960 		lstatus = ncx_getn_float_double(&xp, nget, value);
7961 		if(lstatus != NC_NOERR && status == NC_NOERR)
7962 			status = lstatus;
7963 
7964 		(void) ncio_rel(ncp->nciop, offset, 0);
7965 
7966 		remaining -= extent;
7967 		if(remaining == 0)
7968 			break; /* normal loop exit */
7969 		offset += (off_t)extent;
7970 		value += nget;
7971 	}
7972 
7973 	return status;
7974 }
7975 
7976 static int
getNCvx_float_longlong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,longlong * value)7977 getNCvx_float_longlong(const NC3_INFO* ncp, const NC_var *varp,
7978 		 const size_t *start, size_t nelems, longlong *value)
7979 {
7980 	off_t offset = NC_varoffset(ncp, varp, start);
7981 	size_t remaining = varp->xsz * nelems;
7982 	int status = NC_NOERR;
7983 	const void *xp;
7984 
7985 	if(nelems == 0)
7986 		return NC_NOERR;
7987 
7988 	assert(value != NULL);
7989 
7990 	for(;;)
7991 	{
7992 		size_t extent = MIN(remaining, ncp->chunk);
7993 		size_t nget = ncx_howmany(varp->type, extent);
7994 
7995 		int lstatus = ncio_get(ncp->nciop, offset, extent,
7996 				 0, (void **)&xp);	/* cast away const */
7997 		if(lstatus != NC_NOERR)
7998 			return lstatus;
7999 
8000 		lstatus = ncx_getn_float_longlong(&xp, nget, value);
8001 		if(lstatus != NC_NOERR && status == NC_NOERR)
8002 			status = lstatus;
8003 
8004 		(void) ncio_rel(ncp->nciop, offset, 0);
8005 
8006 		remaining -= extent;
8007 		if(remaining == 0)
8008 			break; /* normal loop exit */
8009 		offset += (off_t)extent;
8010 		value += nget;
8011 	}
8012 
8013 	return status;
8014 }
8015 
8016 static int
getNCvx_float_uint(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uint * value)8017 getNCvx_float_uint(const NC3_INFO* ncp, const NC_var *varp,
8018 		 const size_t *start, size_t nelems, uint *value)
8019 {
8020 	off_t offset = NC_varoffset(ncp, varp, start);
8021 	size_t remaining = varp->xsz * nelems;
8022 	int status = NC_NOERR;
8023 	const void *xp;
8024 
8025 	if(nelems == 0)
8026 		return NC_NOERR;
8027 
8028 	assert(value != NULL);
8029 
8030 	for(;;)
8031 	{
8032 		size_t extent = MIN(remaining, ncp->chunk);
8033 		size_t nget = ncx_howmany(varp->type, extent);
8034 
8035 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8036 				 0, (void **)&xp);	/* cast away const */
8037 		if(lstatus != NC_NOERR)
8038 			return lstatus;
8039 
8040 		lstatus = ncx_getn_float_uint(&xp, nget, value);
8041 		if(lstatus != NC_NOERR && status == NC_NOERR)
8042 			status = lstatus;
8043 
8044 		(void) ncio_rel(ncp->nciop, offset, 0);
8045 
8046 		remaining -= extent;
8047 		if(remaining == 0)
8048 			break; /* normal loop exit */
8049 		offset += (off_t)extent;
8050 		value += nget;
8051 	}
8052 
8053 	return status;
8054 }
8055 
8056 static int
getNCvx_float_ulonglong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ulonglong * value)8057 getNCvx_float_ulonglong(const NC3_INFO* ncp, const NC_var *varp,
8058 		 const size_t *start, size_t nelems, ulonglong *value)
8059 {
8060 	off_t offset = NC_varoffset(ncp, varp, start);
8061 	size_t remaining = varp->xsz * nelems;
8062 	int status = NC_NOERR;
8063 	const void *xp;
8064 
8065 	if(nelems == 0)
8066 		return NC_NOERR;
8067 
8068 	assert(value != NULL);
8069 
8070 	for(;;)
8071 	{
8072 		size_t extent = MIN(remaining, ncp->chunk);
8073 		size_t nget = ncx_howmany(varp->type, extent);
8074 
8075 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8076 				 0, (void **)&xp);	/* cast away const */
8077 		if(lstatus != NC_NOERR)
8078 			return lstatus;
8079 
8080 		lstatus = ncx_getn_float_ulonglong(&xp, nget, value);
8081 		if(lstatus != NC_NOERR && status == NC_NOERR)
8082 			status = lstatus;
8083 
8084 		(void) ncio_rel(ncp->nciop, offset, 0);
8085 
8086 		remaining -= extent;
8087 		if(remaining == 0)
8088 			break; /* normal loop exit */
8089 		offset += (off_t)extent;
8090 		value += nget;
8091 	}
8092 
8093 	return status;
8094 }
8095 
8096 static int
getNCvx_float_ushort(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ushort * value)8097 getNCvx_float_ushort(const NC3_INFO* ncp, const NC_var *varp,
8098 		 const size_t *start, size_t nelems, ushort *value)
8099 {
8100 	off_t offset = NC_varoffset(ncp, varp, start);
8101 	size_t remaining = varp->xsz * nelems;
8102 	int status = NC_NOERR;
8103 	const void *xp;
8104 
8105 	if(nelems == 0)
8106 		return NC_NOERR;
8107 
8108 	assert(value != NULL);
8109 
8110 	for(;;)
8111 	{
8112 		size_t extent = MIN(remaining, ncp->chunk);
8113 		size_t nget = ncx_howmany(varp->type, extent);
8114 
8115 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8116 				 0, (void **)&xp);	/* cast away const */
8117 		if(lstatus != NC_NOERR)
8118 			return lstatus;
8119 
8120 		lstatus = ncx_getn_float_ushort(&xp, nget, value);
8121 		if(lstatus != NC_NOERR && status == NC_NOERR)
8122 			status = lstatus;
8123 
8124 		(void) ncio_rel(ncp->nciop, offset, 0);
8125 
8126 		remaining -= extent;
8127 		if(remaining == 0)
8128 			break; /* normal loop exit */
8129 		offset += (off_t)extent;
8130 		value += nget;
8131 	}
8132 
8133 	return status;
8134 }
8135 
8136 
8137 static int
getNCvx_double_schar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,schar * value)8138 getNCvx_double_schar(const NC3_INFO* ncp, const NC_var *varp,
8139 		 const size_t *start, size_t nelems, schar *value)
8140 {
8141 	off_t offset = NC_varoffset(ncp, varp, start);
8142 	size_t remaining = varp->xsz * nelems;
8143 	int status = NC_NOERR;
8144 	const void *xp;
8145 
8146 	if(nelems == 0)
8147 		return NC_NOERR;
8148 
8149 	assert(value != NULL);
8150 
8151 	for(;;)
8152 	{
8153 		size_t extent = MIN(remaining, ncp->chunk);
8154 		size_t nget = ncx_howmany(varp->type, extent);
8155 
8156 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8157 				 0, (void **)&xp);	/* cast away const */
8158 		if(lstatus != NC_NOERR)
8159 			return lstatus;
8160 
8161 		lstatus = ncx_getn_double_schar(&xp, nget, value);
8162 		if(lstatus != NC_NOERR && status == NC_NOERR)
8163 			status = lstatus;
8164 
8165 		(void) ncio_rel(ncp->nciop, offset, 0);
8166 
8167 		remaining -= extent;
8168 		if(remaining == 0)
8169 			break; /* normal loop exit */
8170 		offset += (off_t)extent;
8171 		value += nget;
8172 	}
8173 
8174 	return status;
8175 }
8176 
8177 static int
getNCvx_double_uchar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uchar * value)8178 getNCvx_double_uchar(const NC3_INFO* ncp, const NC_var *varp,
8179 		 const size_t *start, size_t nelems, uchar *value)
8180 {
8181 	off_t offset = NC_varoffset(ncp, varp, start);
8182 	size_t remaining = varp->xsz * nelems;
8183 	int status = NC_NOERR;
8184 	const void *xp;
8185 
8186 	if(nelems == 0)
8187 		return NC_NOERR;
8188 
8189 	assert(value != NULL);
8190 
8191 	for(;;)
8192 	{
8193 		size_t extent = MIN(remaining, ncp->chunk);
8194 		size_t nget = ncx_howmany(varp->type, extent);
8195 
8196 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8197 				 0, (void **)&xp);	/* cast away const */
8198 		if(lstatus != NC_NOERR)
8199 			return lstatus;
8200 
8201 		lstatus = ncx_getn_double_uchar(&xp, nget, value);
8202 		if(lstatus != NC_NOERR && status == NC_NOERR)
8203 			status = lstatus;
8204 
8205 		(void) ncio_rel(ncp->nciop, offset, 0);
8206 
8207 		remaining -= extent;
8208 		if(remaining == 0)
8209 			break; /* normal loop exit */
8210 		offset += (off_t)extent;
8211 		value += nget;
8212 	}
8213 
8214 	return status;
8215 }
8216 
8217 static int
getNCvx_double_short(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,short * value)8218 getNCvx_double_short(const NC3_INFO* ncp, const NC_var *varp,
8219 		 const size_t *start, size_t nelems, short *value)
8220 {
8221 	off_t offset = NC_varoffset(ncp, varp, start);
8222 	size_t remaining = varp->xsz * nelems;
8223 	int status = NC_NOERR;
8224 	const void *xp;
8225 
8226 	if(nelems == 0)
8227 		return NC_NOERR;
8228 
8229 	assert(value != NULL);
8230 
8231 	for(;;)
8232 	{
8233 		size_t extent = MIN(remaining, ncp->chunk);
8234 		size_t nget = ncx_howmany(varp->type, extent);
8235 
8236 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8237 				 0, (void **)&xp);	/* cast away const */
8238 		if(lstatus != NC_NOERR)
8239 			return lstatus;
8240 
8241 		lstatus = ncx_getn_double_short(&xp, nget, value);
8242 		if(lstatus != NC_NOERR && status == NC_NOERR)
8243 			status = lstatus;
8244 
8245 		(void) ncio_rel(ncp->nciop, offset, 0);
8246 
8247 		remaining -= extent;
8248 		if(remaining == 0)
8249 			break; /* normal loop exit */
8250 		offset += (off_t)extent;
8251 		value += nget;
8252 	}
8253 
8254 	return status;
8255 }
8256 
8257 static int
getNCvx_double_int(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,int * value)8258 getNCvx_double_int(const NC3_INFO* ncp, const NC_var *varp,
8259 		 const size_t *start, size_t nelems, int *value)
8260 {
8261 	off_t offset = NC_varoffset(ncp, varp, start);
8262 	size_t remaining = varp->xsz * nelems;
8263 	int status = NC_NOERR;
8264 	const void *xp;
8265 
8266 	if(nelems == 0)
8267 		return NC_NOERR;
8268 
8269 	assert(value != NULL);
8270 
8271 	for(;;)
8272 	{
8273 		size_t extent = MIN(remaining, ncp->chunk);
8274 		size_t nget = ncx_howmany(varp->type, extent);
8275 
8276 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8277 				 0, (void **)&xp);	/* cast away const */
8278 		if(lstatus != NC_NOERR)
8279 			return lstatus;
8280 
8281 		lstatus = ncx_getn_double_int(&xp, nget, value);
8282 		if(lstatus != NC_NOERR && status == NC_NOERR)
8283 			status = lstatus;
8284 
8285 		(void) ncio_rel(ncp->nciop, offset, 0);
8286 
8287 		remaining -= extent;
8288 		if(remaining == 0)
8289 			break; /* normal loop exit */
8290 		offset += (off_t)extent;
8291 		value += nget;
8292 	}
8293 
8294 	return status;
8295 }
8296 
8297 static int
getNCvx_double_float(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,float * value)8298 getNCvx_double_float(const NC3_INFO* ncp, const NC_var *varp,
8299 		 const size_t *start, size_t nelems, float *value)
8300 {
8301 	off_t offset = NC_varoffset(ncp, varp, start);
8302 	size_t remaining = varp->xsz * nelems;
8303 	int status = NC_NOERR;
8304 	const void *xp;
8305 
8306 	if(nelems == 0)
8307 		return NC_NOERR;
8308 
8309 	assert(value != NULL);
8310 
8311 	for(;;)
8312 	{
8313 		size_t extent = MIN(remaining, ncp->chunk);
8314 		size_t nget = ncx_howmany(varp->type, extent);
8315 
8316 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8317 				 0, (void **)&xp);	/* cast away const */
8318 		if(lstatus != NC_NOERR)
8319 			return lstatus;
8320 
8321 		lstatus = ncx_getn_double_float(&xp, nget, value);
8322 		if(lstatus != NC_NOERR && status == NC_NOERR)
8323 			status = lstatus;
8324 
8325 		(void) ncio_rel(ncp->nciop, offset, 0);
8326 
8327 		remaining -= extent;
8328 		if(remaining == 0)
8329 			break; /* normal loop exit */
8330 		offset += (off_t)extent;
8331 		value += nget;
8332 	}
8333 
8334 	return status;
8335 }
8336 
8337 static int
getNCvx_double_double(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,double * value)8338 getNCvx_double_double(const NC3_INFO* ncp, const NC_var *varp,
8339 		 const size_t *start, size_t nelems, double *value)
8340 {
8341 	off_t offset = NC_varoffset(ncp, varp, start);
8342 	size_t remaining = varp->xsz * nelems;
8343 	int status = NC_NOERR;
8344 	const void *xp;
8345 
8346 	if(nelems == 0)
8347 		return NC_NOERR;
8348 
8349 	assert(value != NULL);
8350 
8351 	for(;;)
8352 	{
8353 		size_t extent = MIN(remaining, ncp->chunk);
8354 		size_t nget = ncx_howmany(varp->type, extent);
8355 
8356 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8357 				 0, (void **)&xp);	/* cast away const */
8358 		if(lstatus != NC_NOERR)
8359 			return lstatus;
8360 
8361 		lstatus = ncx_getn_double_double(&xp, nget, value);
8362 		if(lstatus != NC_NOERR && status == NC_NOERR)
8363 			status = lstatus;
8364 
8365 		(void) ncio_rel(ncp->nciop, offset, 0);
8366 
8367 		remaining -= extent;
8368 		if(remaining == 0)
8369 			break; /* normal loop exit */
8370 		offset += (off_t)extent;
8371 		value += nget;
8372 	}
8373 
8374 	return status;
8375 }
8376 
8377 static int
getNCvx_double_longlong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,longlong * value)8378 getNCvx_double_longlong(const NC3_INFO* ncp, const NC_var *varp,
8379 		 const size_t *start, size_t nelems, longlong *value)
8380 {
8381 	off_t offset = NC_varoffset(ncp, varp, start);
8382 	size_t remaining = varp->xsz * nelems;
8383 	int status = NC_NOERR;
8384 	const void *xp;
8385 
8386 	if(nelems == 0)
8387 		return NC_NOERR;
8388 
8389 	assert(value != NULL);
8390 
8391 	for(;;)
8392 	{
8393 		size_t extent = MIN(remaining, ncp->chunk);
8394 		size_t nget = ncx_howmany(varp->type, extent);
8395 
8396 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8397 				 0, (void **)&xp);	/* cast away const */
8398 		if(lstatus != NC_NOERR)
8399 			return lstatus;
8400 
8401 		lstatus = ncx_getn_double_longlong(&xp, nget, value);
8402 		if(lstatus != NC_NOERR && status == NC_NOERR)
8403 			status = lstatus;
8404 
8405 		(void) ncio_rel(ncp->nciop, offset, 0);
8406 
8407 		remaining -= extent;
8408 		if(remaining == 0)
8409 			break; /* normal loop exit */
8410 		offset += (off_t)extent;
8411 		value += nget;
8412 	}
8413 
8414 	return status;
8415 }
8416 
8417 static int
getNCvx_double_uint(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uint * value)8418 getNCvx_double_uint(const NC3_INFO* ncp, const NC_var *varp,
8419 		 const size_t *start, size_t nelems, uint *value)
8420 {
8421 	off_t offset = NC_varoffset(ncp, varp, start);
8422 	size_t remaining = varp->xsz * nelems;
8423 	int status = NC_NOERR;
8424 	const void *xp;
8425 
8426 	if(nelems == 0)
8427 		return NC_NOERR;
8428 
8429 	assert(value != NULL);
8430 
8431 	for(;;)
8432 	{
8433 		size_t extent = MIN(remaining, ncp->chunk);
8434 		size_t nget = ncx_howmany(varp->type, extent);
8435 
8436 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8437 				 0, (void **)&xp);	/* cast away const */
8438 		if(lstatus != NC_NOERR)
8439 			return lstatus;
8440 
8441 		lstatus = ncx_getn_double_uint(&xp, nget, value);
8442 		if(lstatus != NC_NOERR && status == NC_NOERR)
8443 			status = lstatus;
8444 
8445 		(void) ncio_rel(ncp->nciop, offset, 0);
8446 
8447 		remaining -= extent;
8448 		if(remaining == 0)
8449 			break; /* normal loop exit */
8450 		offset += (off_t)extent;
8451 		value += nget;
8452 	}
8453 
8454 	return status;
8455 }
8456 
8457 static int
getNCvx_double_ulonglong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ulonglong * value)8458 getNCvx_double_ulonglong(const NC3_INFO* ncp, const NC_var *varp,
8459 		 const size_t *start, size_t nelems, ulonglong *value)
8460 {
8461 	off_t offset = NC_varoffset(ncp, varp, start);
8462 	size_t remaining = varp->xsz * nelems;
8463 	int status = NC_NOERR;
8464 	const void *xp;
8465 
8466 	if(nelems == 0)
8467 		return NC_NOERR;
8468 
8469 	assert(value != NULL);
8470 
8471 	for(;;)
8472 	{
8473 		size_t extent = MIN(remaining, ncp->chunk);
8474 		size_t nget = ncx_howmany(varp->type, extent);
8475 
8476 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8477 				 0, (void **)&xp);	/* cast away const */
8478 		if(lstatus != NC_NOERR)
8479 			return lstatus;
8480 
8481 		lstatus = ncx_getn_double_ulonglong(&xp, nget, value);
8482 		if(lstatus != NC_NOERR && status == NC_NOERR)
8483 			status = lstatus;
8484 
8485 		(void) ncio_rel(ncp->nciop, offset, 0);
8486 
8487 		remaining -= extent;
8488 		if(remaining == 0)
8489 			break; /* normal loop exit */
8490 		offset += (off_t)extent;
8491 		value += nget;
8492 	}
8493 
8494 	return status;
8495 }
8496 
8497 static int
getNCvx_double_ushort(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ushort * value)8498 getNCvx_double_ushort(const NC3_INFO* ncp, const NC_var *varp,
8499 		 const size_t *start, size_t nelems, ushort *value)
8500 {
8501 	off_t offset = NC_varoffset(ncp, varp, start);
8502 	size_t remaining = varp->xsz * nelems;
8503 	int status = NC_NOERR;
8504 	const void *xp;
8505 
8506 	if(nelems == 0)
8507 		return NC_NOERR;
8508 
8509 	assert(value != NULL);
8510 
8511 	for(;;)
8512 	{
8513 		size_t extent = MIN(remaining, ncp->chunk);
8514 		size_t nget = ncx_howmany(varp->type, extent);
8515 
8516 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8517 				 0, (void **)&xp);	/* cast away const */
8518 		if(lstatus != NC_NOERR)
8519 			return lstatus;
8520 
8521 		lstatus = ncx_getn_double_ushort(&xp, nget, value);
8522 		if(lstatus != NC_NOERR && status == NC_NOERR)
8523 			status = lstatus;
8524 
8525 		(void) ncio_rel(ncp->nciop, offset, 0);
8526 
8527 		remaining -= extent;
8528 		if(remaining == 0)
8529 			break; /* normal loop exit */
8530 		offset += (off_t)extent;
8531 		value += nget;
8532 	}
8533 
8534 	return status;
8535 }
8536 
8537 
8538 static int
getNCvx_uchar_schar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,schar * value)8539 getNCvx_uchar_schar(const NC3_INFO* ncp, const NC_var *varp,
8540 		 const size_t *start, size_t nelems, schar *value)
8541 {
8542 	off_t offset = NC_varoffset(ncp, varp, start);
8543 	size_t remaining = varp->xsz * nelems;
8544 	int status = NC_NOERR;
8545 	const void *xp;
8546 
8547 	if(nelems == 0)
8548 		return NC_NOERR;
8549 
8550 	assert(value != NULL);
8551 
8552 	for(;;)
8553 	{
8554 		size_t extent = MIN(remaining, ncp->chunk);
8555 		size_t nget = ncx_howmany(varp->type, extent);
8556 
8557 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8558 				 0, (void **)&xp);	/* cast away const */
8559 		if(lstatus != NC_NOERR)
8560 			return lstatus;
8561 
8562 		lstatus = ncx_getn_uchar_schar(&xp, nget, value);
8563 		if(lstatus != NC_NOERR && status == NC_NOERR)
8564 			status = lstatus;
8565 
8566 		(void) ncio_rel(ncp->nciop, offset, 0);
8567 
8568 		remaining -= extent;
8569 		if(remaining == 0)
8570 			break; /* normal loop exit */
8571 		offset += (off_t)extent;
8572 		value += nget;
8573 	}
8574 
8575 	return status;
8576 }
8577 
8578 static int
getNCvx_uchar_uchar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uchar * value)8579 getNCvx_uchar_uchar(const NC3_INFO* ncp, const NC_var *varp,
8580 		 const size_t *start, size_t nelems, uchar *value)
8581 {
8582 	off_t offset = NC_varoffset(ncp, varp, start);
8583 	size_t remaining = varp->xsz * nelems;
8584 	int status = NC_NOERR;
8585 	const void *xp;
8586 
8587 	if(nelems == 0)
8588 		return NC_NOERR;
8589 
8590 	assert(value != NULL);
8591 
8592 	for(;;)
8593 	{
8594 		size_t extent = MIN(remaining, ncp->chunk);
8595 		size_t nget = ncx_howmany(varp->type, extent);
8596 
8597 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8598 				 0, (void **)&xp);	/* cast away const */
8599 		if(lstatus != NC_NOERR)
8600 			return lstatus;
8601 
8602 		lstatus = ncx_getn_uchar_uchar(&xp, nget, value);
8603 		if(lstatus != NC_NOERR && status == NC_NOERR)
8604 			status = lstatus;
8605 
8606 		(void) ncio_rel(ncp->nciop, offset, 0);
8607 
8608 		remaining -= extent;
8609 		if(remaining == 0)
8610 			break; /* normal loop exit */
8611 		offset += (off_t)extent;
8612 		value += nget;
8613 	}
8614 
8615 	return status;
8616 }
8617 
8618 static int
getNCvx_uchar_short(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,short * value)8619 getNCvx_uchar_short(const NC3_INFO* ncp, const NC_var *varp,
8620 		 const size_t *start, size_t nelems, short *value)
8621 {
8622 	off_t offset = NC_varoffset(ncp, varp, start);
8623 	size_t remaining = varp->xsz * nelems;
8624 	int status = NC_NOERR;
8625 	const void *xp;
8626 
8627 	if(nelems == 0)
8628 		return NC_NOERR;
8629 
8630 	assert(value != NULL);
8631 
8632 	for(;;)
8633 	{
8634 		size_t extent = MIN(remaining, ncp->chunk);
8635 		size_t nget = ncx_howmany(varp->type, extent);
8636 
8637 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8638 				 0, (void **)&xp);	/* cast away const */
8639 		if(lstatus != NC_NOERR)
8640 			return lstatus;
8641 
8642 		lstatus = ncx_getn_uchar_short(&xp, nget, value);
8643 		if(lstatus != NC_NOERR && status == NC_NOERR)
8644 			status = lstatus;
8645 
8646 		(void) ncio_rel(ncp->nciop, offset, 0);
8647 
8648 		remaining -= extent;
8649 		if(remaining == 0)
8650 			break; /* normal loop exit */
8651 		offset += (off_t)extent;
8652 		value += nget;
8653 	}
8654 
8655 	return status;
8656 }
8657 
8658 static int
getNCvx_uchar_int(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,int * value)8659 getNCvx_uchar_int(const NC3_INFO* ncp, const NC_var *varp,
8660 		 const size_t *start, size_t nelems, int *value)
8661 {
8662 	off_t offset = NC_varoffset(ncp, varp, start);
8663 	size_t remaining = varp->xsz * nelems;
8664 	int status = NC_NOERR;
8665 	const void *xp;
8666 
8667 	if(nelems == 0)
8668 		return NC_NOERR;
8669 
8670 	assert(value != NULL);
8671 
8672 	for(;;)
8673 	{
8674 		size_t extent = MIN(remaining, ncp->chunk);
8675 		size_t nget = ncx_howmany(varp->type, extent);
8676 
8677 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8678 				 0, (void **)&xp);	/* cast away const */
8679 		if(lstatus != NC_NOERR)
8680 			return lstatus;
8681 
8682 		lstatus = ncx_getn_uchar_int(&xp, nget, value);
8683 		if(lstatus != NC_NOERR && status == NC_NOERR)
8684 			status = lstatus;
8685 
8686 		(void) ncio_rel(ncp->nciop, offset, 0);
8687 
8688 		remaining -= extent;
8689 		if(remaining == 0)
8690 			break; /* normal loop exit */
8691 		offset += (off_t)extent;
8692 		value += nget;
8693 	}
8694 
8695 	return status;
8696 }
8697 
8698 static int
getNCvx_uchar_float(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,float * value)8699 getNCvx_uchar_float(const NC3_INFO* ncp, const NC_var *varp,
8700 		 const size_t *start, size_t nelems, float *value)
8701 {
8702 	off_t offset = NC_varoffset(ncp, varp, start);
8703 	size_t remaining = varp->xsz * nelems;
8704 	int status = NC_NOERR;
8705 	const void *xp;
8706 
8707 	if(nelems == 0)
8708 		return NC_NOERR;
8709 
8710 	assert(value != NULL);
8711 
8712 	for(;;)
8713 	{
8714 		size_t extent = MIN(remaining, ncp->chunk);
8715 		size_t nget = ncx_howmany(varp->type, extent);
8716 
8717 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8718 				 0, (void **)&xp);	/* cast away const */
8719 		if(lstatus != NC_NOERR)
8720 			return lstatus;
8721 
8722 		lstatus = ncx_getn_uchar_float(&xp, nget, value);
8723 		if(lstatus != NC_NOERR && status == NC_NOERR)
8724 			status = lstatus;
8725 
8726 		(void) ncio_rel(ncp->nciop, offset, 0);
8727 
8728 		remaining -= extent;
8729 		if(remaining == 0)
8730 			break; /* normal loop exit */
8731 		offset += (off_t)extent;
8732 		value += nget;
8733 	}
8734 
8735 	return status;
8736 }
8737 
8738 static int
getNCvx_uchar_double(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,double * value)8739 getNCvx_uchar_double(const NC3_INFO* ncp, const NC_var *varp,
8740 		 const size_t *start, size_t nelems, double *value)
8741 {
8742 	off_t offset = NC_varoffset(ncp, varp, start);
8743 	size_t remaining = varp->xsz * nelems;
8744 	int status = NC_NOERR;
8745 	const void *xp;
8746 
8747 	if(nelems == 0)
8748 		return NC_NOERR;
8749 
8750 	assert(value != NULL);
8751 
8752 	for(;;)
8753 	{
8754 		size_t extent = MIN(remaining, ncp->chunk);
8755 		size_t nget = ncx_howmany(varp->type, extent);
8756 
8757 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8758 				 0, (void **)&xp);	/* cast away const */
8759 		if(lstatus != NC_NOERR)
8760 			return lstatus;
8761 
8762 		lstatus = ncx_getn_uchar_double(&xp, nget, value);
8763 		if(lstatus != NC_NOERR && status == NC_NOERR)
8764 			status = lstatus;
8765 
8766 		(void) ncio_rel(ncp->nciop, offset, 0);
8767 
8768 		remaining -= extent;
8769 		if(remaining == 0)
8770 			break; /* normal loop exit */
8771 		offset += (off_t)extent;
8772 		value += nget;
8773 	}
8774 
8775 	return status;
8776 }
8777 
8778 static int
getNCvx_uchar_longlong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,longlong * value)8779 getNCvx_uchar_longlong(const NC3_INFO* ncp, const NC_var *varp,
8780 		 const size_t *start, size_t nelems, longlong *value)
8781 {
8782 	off_t offset = NC_varoffset(ncp, varp, start);
8783 	size_t remaining = varp->xsz * nelems;
8784 	int status = NC_NOERR;
8785 	const void *xp;
8786 
8787 	if(nelems == 0)
8788 		return NC_NOERR;
8789 
8790 	assert(value != NULL);
8791 
8792 	for(;;)
8793 	{
8794 		size_t extent = MIN(remaining, ncp->chunk);
8795 		size_t nget = ncx_howmany(varp->type, extent);
8796 
8797 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8798 				 0, (void **)&xp);	/* cast away const */
8799 		if(lstatus != NC_NOERR)
8800 			return lstatus;
8801 
8802 		lstatus = ncx_getn_uchar_longlong(&xp, nget, value);
8803 		if(lstatus != NC_NOERR && status == NC_NOERR)
8804 			status = lstatus;
8805 
8806 		(void) ncio_rel(ncp->nciop, offset, 0);
8807 
8808 		remaining -= extent;
8809 		if(remaining == 0)
8810 			break; /* normal loop exit */
8811 		offset += (off_t)extent;
8812 		value += nget;
8813 	}
8814 
8815 	return status;
8816 }
8817 
8818 static int
getNCvx_uchar_uint(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uint * value)8819 getNCvx_uchar_uint(const NC3_INFO* ncp, const NC_var *varp,
8820 		 const size_t *start, size_t nelems, uint *value)
8821 {
8822 	off_t offset = NC_varoffset(ncp, varp, start);
8823 	size_t remaining = varp->xsz * nelems;
8824 	int status = NC_NOERR;
8825 	const void *xp;
8826 
8827 	if(nelems == 0)
8828 		return NC_NOERR;
8829 
8830 	assert(value != NULL);
8831 
8832 	for(;;)
8833 	{
8834 		size_t extent = MIN(remaining, ncp->chunk);
8835 		size_t nget = ncx_howmany(varp->type, extent);
8836 
8837 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8838 				 0, (void **)&xp);	/* cast away const */
8839 		if(lstatus != NC_NOERR)
8840 			return lstatus;
8841 
8842 		lstatus = ncx_getn_uchar_uint(&xp, nget, value);
8843 		if(lstatus != NC_NOERR && status == NC_NOERR)
8844 			status = lstatus;
8845 
8846 		(void) ncio_rel(ncp->nciop, offset, 0);
8847 
8848 		remaining -= extent;
8849 		if(remaining == 0)
8850 			break; /* normal loop exit */
8851 		offset += (off_t)extent;
8852 		value += nget;
8853 	}
8854 
8855 	return status;
8856 }
8857 
8858 static int
getNCvx_uchar_ulonglong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ulonglong * value)8859 getNCvx_uchar_ulonglong(const NC3_INFO* ncp, const NC_var *varp,
8860 		 const size_t *start, size_t nelems, ulonglong *value)
8861 {
8862 	off_t offset = NC_varoffset(ncp, varp, start);
8863 	size_t remaining = varp->xsz * nelems;
8864 	int status = NC_NOERR;
8865 	const void *xp;
8866 
8867 	if(nelems == 0)
8868 		return NC_NOERR;
8869 
8870 	assert(value != NULL);
8871 
8872 	for(;;)
8873 	{
8874 		size_t extent = MIN(remaining, ncp->chunk);
8875 		size_t nget = ncx_howmany(varp->type, extent);
8876 
8877 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8878 				 0, (void **)&xp);	/* cast away const */
8879 		if(lstatus != NC_NOERR)
8880 			return lstatus;
8881 
8882 		lstatus = ncx_getn_uchar_ulonglong(&xp, nget, value);
8883 		if(lstatus != NC_NOERR && status == NC_NOERR)
8884 			status = lstatus;
8885 
8886 		(void) ncio_rel(ncp->nciop, offset, 0);
8887 
8888 		remaining -= extent;
8889 		if(remaining == 0)
8890 			break; /* normal loop exit */
8891 		offset += (off_t)extent;
8892 		value += nget;
8893 	}
8894 
8895 	return status;
8896 }
8897 
8898 static int
getNCvx_uchar_ushort(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ushort * value)8899 getNCvx_uchar_ushort(const NC3_INFO* ncp, const NC_var *varp,
8900 		 const size_t *start, size_t nelems, ushort *value)
8901 {
8902 	off_t offset = NC_varoffset(ncp, varp, start);
8903 	size_t remaining = varp->xsz * nelems;
8904 	int status = NC_NOERR;
8905 	const void *xp;
8906 
8907 	if(nelems == 0)
8908 		return NC_NOERR;
8909 
8910 	assert(value != NULL);
8911 
8912 	for(;;)
8913 	{
8914 		size_t extent = MIN(remaining, ncp->chunk);
8915 		size_t nget = ncx_howmany(varp->type, extent);
8916 
8917 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8918 				 0, (void **)&xp);	/* cast away const */
8919 		if(lstatus != NC_NOERR)
8920 			return lstatus;
8921 
8922 		lstatus = ncx_getn_uchar_ushort(&xp, nget, value);
8923 		if(lstatus != NC_NOERR && status == NC_NOERR)
8924 			status = lstatus;
8925 
8926 		(void) ncio_rel(ncp->nciop, offset, 0);
8927 
8928 		remaining -= extent;
8929 		if(remaining == 0)
8930 			break; /* normal loop exit */
8931 		offset += (off_t)extent;
8932 		value += nget;
8933 	}
8934 
8935 	return status;
8936 }
8937 
8938 
8939 static int
getNCvx_ushort_schar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,schar * value)8940 getNCvx_ushort_schar(const NC3_INFO* ncp, const NC_var *varp,
8941 		 const size_t *start, size_t nelems, schar *value)
8942 {
8943 	off_t offset = NC_varoffset(ncp, varp, start);
8944 	size_t remaining = varp->xsz * nelems;
8945 	int status = NC_NOERR;
8946 	const void *xp;
8947 
8948 	if(nelems == 0)
8949 		return NC_NOERR;
8950 
8951 	assert(value != NULL);
8952 
8953 	for(;;)
8954 	{
8955 		size_t extent = MIN(remaining, ncp->chunk);
8956 		size_t nget = ncx_howmany(varp->type, extent);
8957 
8958 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8959 				 0, (void **)&xp);	/* cast away const */
8960 		if(lstatus != NC_NOERR)
8961 			return lstatus;
8962 
8963 		lstatus = ncx_getn_ushort_schar(&xp, nget, value);
8964 		if(lstatus != NC_NOERR && status == NC_NOERR)
8965 			status = lstatus;
8966 
8967 		(void) ncio_rel(ncp->nciop, offset, 0);
8968 
8969 		remaining -= extent;
8970 		if(remaining == 0)
8971 			break; /* normal loop exit */
8972 		offset += (off_t)extent;
8973 		value += nget;
8974 	}
8975 
8976 	return status;
8977 }
8978 
8979 static int
getNCvx_ushort_uchar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uchar * value)8980 getNCvx_ushort_uchar(const NC3_INFO* ncp, const NC_var *varp,
8981 		 const size_t *start, size_t nelems, uchar *value)
8982 {
8983 	off_t offset = NC_varoffset(ncp, varp, start);
8984 	size_t remaining = varp->xsz * nelems;
8985 	int status = NC_NOERR;
8986 	const void *xp;
8987 
8988 	if(nelems == 0)
8989 		return NC_NOERR;
8990 
8991 	assert(value != NULL);
8992 
8993 	for(;;)
8994 	{
8995 		size_t extent = MIN(remaining, ncp->chunk);
8996 		size_t nget = ncx_howmany(varp->type, extent);
8997 
8998 		int lstatus = ncio_get(ncp->nciop, offset, extent,
8999 				 0, (void **)&xp);	/* cast away const */
9000 		if(lstatus != NC_NOERR)
9001 			return lstatus;
9002 
9003 		lstatus = ncx_getn_ushort_uchar(&xp, nget, value);
9004 		if(lstatus != NC_NOERR && status == NC_NOERR)
9005 			status = lstatus;
9006 
9007 		(void) ncio_rel(ncp->nciop, offset, 0);
9008 
9009 		remaining -= extent;
9010 		if(remaining == 0)
9011 			break; /* normal loop exit */
9012 		offset += (off_t)extent;
9013 		value += nget;
9014 	}
9015 
9016 	return status;
9017 }
9018 
9019 static int
getNCvx_ushort_short(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,short * value)9020 getNCvx_ushort_short(const NC3_INFO* ncp, const NC_var *varp,
9021 		 const size_t *start, size_t nelems, short *value)
9022 {
9023 	off_t offset = NC_varoffset(ncp, varp, start);
9024 	size_t remaining = varp->xsz * nelems;
9025 	int status = NC_NOERR;
9026 	const void *xp;
9027 
9028 	if(nelems == 0)
9029 		return NC_NOERR;
9030 
9031 	assert(value != NULL);
9032 
9033 	for(;;)
9034 	{
9035 		size_t extent = MIN(remaining, ncp->chunk);
9036 		size_t nget = ncx_howmany(varp->type, extent);
9037 
9038 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9039 				 0, (void **)&xp);	/* cast away const */
9040 		if(lstatus != NC_NOERR)
9041 			return lstatus;
9042 
9043 		lstatus = ncx_getn_ushort_short(&xp, nget, value);
9044 		if(lstatus != NC_NOERR && status == NC_NOERR)
9045 			status = lstatus;
9046 
9047 		(void) ncio_rel(ncp->nciop, offset, 0);
9048 
9049 		remaining -= extent;
9050 		if(remaining == 0)
9051 			break; /* normal loop exit */
9052 		offset += (off_t)extent;
9053 		value += nget;
9054 	}
9055 
9056 	return status;
9057 }
9058 
9059 static int
getNCvx_ushort_int(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,int * value)9060 getNCvx_ushort_int(const NC3_INFO* ncp, const NC_var *varp,
9061 		 const size_t *start, size_t nelems, int *value)
9062 {
9063 	off_t offset = NC_varoffset(ncp, varp, start);
9064 	size_t remaining = varp->xsz * nelems;
9065 	int status = NC_NOERR;
9066 	const void *xp;
9067 
9068 	if(nelems == 0)
9069 		return NC_NOERR;
9070 
9071 	assert(value != NULL);
9072 
9073 	for(;;)
9074 	{
9075 		size_t extent = MIN(remaining, ncp->chunk);
9076 		size_t nget = ncx_howmany(varp->type, extent);
9077 
9078 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9079 				 0, (void **)&xp);	/* cast away const */
9080 		if(lstatus != NC_NOERR)
9081 			return lstatus;
9082 
9083 		lstatus = ncx_getn_ushort_int(&xp, nget, value);
9084 		if(lstatus != NC_NOERR && status == NC_NOERR)
9085 			status = lstatus;
9086 
9087 		(void) ncio_rel(ncp->nciop, offset, 0);
9088 
9089 		remaining -= extent;
9090 		if(remaining == 0)
9091 			break; /* normal loop exit */
9092 		offset += (off_t)extent;
9093 		value += nget;
9094 	}
9095 
9096 	return status;
9097 }
9098 
9099 static int
getNCvx_ushort_float(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,float * value)9100 getNCvx_ushort_float(const NC3_INFO* ncp, const NC_var *varp,
9101 		 const size_t *start, size_t nelems, float *value)
9102 {
9103 	off_t offset = NC_varoffset(ncp, varp, start);
9104 	size_t remaining = varp->xsz * nelems;
9105 	int status = NC_NOERR;
9106 	const void *xp;
9107 
9108 	if(nelems == 0)
9109 		return NC_NOERR;
9110 
9111 	assert(value != NULL);
9112 
9113 	for(;;)
9114 	{
9115 		size_t extent = MIN(remaining, ncp->chunk);
9116 		size_t nget = ncx_howmany(varp->type, extent);
9117 
9118 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9119 				 0, (void **)&xp);	/* cast away const */
9120 		if(lstatus != NC_NOERR)
9121 			return lstatus;
9122 
9123 		lstatus = ncx_getn_ushort_float(&xp, nget, value);
9124 		if(lstatus != NC_NOERR && status == NC_NOERR)
9125 			status = lstatus;
9126 
9127 		(void) ncio_rel(ncp->nciop, offset, 0);
9128 
9129 		remaining -= extent;
9130 		if(remaining == 0)
9131 			break; /* normal loop exit */
9132 		offset += (off_t)extent;
9133 		value += nget;
9134 	}
9135 
9136 	return status;
9137 }
9138 
9139 static int
getNCvx_ushort_double(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,double * value)9140 getNCvx_ushort_double(const NC3_INFO* ncp, const NC_var *varp,
9141 		 const size_t *start, size_t nelems, double *value)
9142 {
9143 	off_t offset = NC_varoffset(ncp, varp, start);
9144 	size_t remaining = varp->xsz * nelems;
9145 	int status = NC_NOERR;
9146 	const void *xp;
9147 
9148 	if(nelems == 0)
9149 		return NC_NOERR;
9150 
9151 	assert(value != NULL);
9152 
9153 	for(;;)
9154 	{
9155 		size_t extent = MIN(remaining, ncp->chunk);
9156 		size_t nget = ncx_howmany(varp->type, extent);
9157 
9158 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9159 				 0, (void **)&xp);	/* cast away const */
9160 		if(lstatus != NC_NOERR)
9161 			return lstatus;
9162 
9163 		lstatus = ncx_getn_ushort_double(&xp, nget, value);
9164 		if(lstatus != NC_NOERR && status == NC_NOERR)
9165 			status = lstatus;
9166 
9167 		(void) ncio_rel(ncp->nciop, offset, 0);
9168 
9169 		remaining -= extent;
9170 		if(remaining == 0)
9171 			break; /* normal loop exit */
9172 		offset += (off_t)extent;
9173 		value += nget;
9174 	}
9175 
9176 	return status;
9177 }
9178 
9179 static int
getNCvx_ushort_longlong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,longlong * value)9180 getNCvx_ushort_longlong(const NC3_INFO* ncp, const NC_var *varp,
9181 		 const size_t *start, size_t nelems, longlong *value)
9182 {
9183 	off_t offset = NC_varoffset(ncp, varp, start);
9184 	size_t remaining = varp->xsz * nelems;
9185 	int status = NC_NOERR;
9186 	const void *xp;
9187 
9188 	if(nelems == 0)
9189 		return NC_NOERR;
9190 
9191 	assert(value != NULL);
9192 
9193 	for(;;)
9194 	{
9195 		size_t extent = MIN(remaining, ncp->chunk);
9196 		size_t nget = ncx_howmany(varp->type, extent);
9197 
9198 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9199 				 0, (void **)&xp);	/* cast away const */
9200 		if(lstatus != NC_NOERR)
9201 			return lstatus;
9202 
9203 		lstatus = ncx_getn_ushort_longlong(&xp, nget, value);
9204 		if(lstatus != NC_NOERR && status == NC_NOERR)
9205 			status = lstatus;
9206 
9207 		(void) ncio_rel(ncp->nciop, offset, 0);
9208 
9209 		remaining -= extent;
9210 		if(remaining == 0)
9211 			break; /* normal loop exit */
9212 		offset += (off_t)extent;
9213 		value += nget;
9214 	}
9215 
9216 	return status;
9217 }
9218 
9219 static int
getNCvx_ushort_uint(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uint * value)9220 getNCvx_ushort_uint(const NC3_INFO* ncp, const NC_var *varp,
9221 		 const size_t *start, size_t nelems, uint *value)
9222 {
9223 	off_t offset = NC_varoffset(ncp, varp, start);
9224 	size_t remaining = varp->xsz * nelems;
9225 	int status = NC_NOERR;
9226 	const void *xp;
9227 
9228 	if(nelems == 0)
9229 		return NC_NOERR;
9230 
9231 	assert(value != NULL);
9232 
9233 	for(;;)
9234 	{
9235 		size_t extent = MIN(remaining, ncp->chunk);
9236 		size_t nget = ncx_howmany(varp->type, extent);
9237 
9238 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9239 				 0, (void **)&xp);	/* cast away const */
9240 		if(lstatus != NC_NOERR)
9241 			return lstatus;
9242 
9243 		lstatus = ncx_getn_ushort_uint(&xp, nget, value);
9244 		if(lstatus != NC_NOERR && status == NC_NOERR)
9245 			status = lstatus;
9246 
9247 		(void) ncio_rel(ncp->nciop, offset, 0);
9248 
9249 		remaining -= extent;
9250 		if(remaining == 0)
9251 			break; /* normal loop exit */
9252 		offset += (off_t)extent;
9253 		value += nget;
9254 	}
9255 
9256 	return status;
9257 }
9258 
9259 static int
getNCvx_ushort_ulonglong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ulonglong * value)9260 getNCvx_ushort_ulonglong(const NC3_INFO* ncp, const NC_var *varp,
9261 		 const size_t *start, size_t nelems, ulonglong *value)
9262 {
9263 	off_t offset = NC_varoffset(ncp, varp, start);
9264 	size_t remaining = varp->xsz * nelems;
9265 	int status = NC_NOERR;
9266 	const void *xp;
9267 
9268 	if(nelems == 0)
9269 		return NC_NOERR;
9270 
9271 	assert(value != NULL);
9272 
9273 	for(;;)
9274 	{
9275 		size_t extent = MIN(remaining, ncp->chunk);
9276 		size_t nget = ncx_howmany(varp->type, extent);
9277 
9278 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9279 				 0, (void **)&xp);	/* cast away const */
9280 		if(lstatus != NC_NOERR)
9281 			return lstatus;
9282 
9283 		lstatus = ncx_getn_ushort_ulonglong(&xp, nget, value);
9284 		if(lstatus != NC_NOERR && status == NC_NOERR)
9285 			status = lstatus;
9286 
9287 		(void) ncio_rel(ncp->nciop, offset, 0);
9288 
9289 		remaining -= extent;
9290 		if(remaining == 0)
9291 			break; /* normal loop exit */
9292 		offset += (off_t)extent;
9293 		value += nget;
9294 	}
9295 
9296 	return status;
9297 }
9298 
9299 static int
getNCvx_ushort_ushort(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ushort * value)9300 getNCvx_ushort_ushort(const NC3_INFO* ncp, const NC_var *varp,
9301 		 const size_t *start, size_t nelems, ushort *value)
9302 {
9303 	off_t offset = NC_varoffset(ncp, varp, start);
9304 	size_t remaining = varp->xsz * nelems;
9305 	int status = NC_NOERR;
9306 	const void *xp;
9307 
9308 	if(nelems == 0)
9309 		return NC_NOERR;
9310 
9311 	assert(value != NULL);
9312 
9313 	for(;;)
9314 	{
9315 		size_t extent = MIN(remaining, ncp->chunk);
9316 		size_t nget = ncx_howmany(varp->type, extent);
9317 
9318 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9319 				 0, (void **)&xp);	/* cast away const */
9320 		if(lstatus != NC_NOERR)
9321 			return lstatus;
9322 
9323 		lstatus = ncx_getn_ushort_ushort(&xp, nget, value);
9324 		if(lstatus != NC_NOERR && status == NC_NOERR)
9325 			status = lstatus;
9326 
9327 		(void) ncio_rel(ncp->nciop, offset, 0);
9328 
9329 		remaining -= extent;
9330 		if(remaining == 0)
9331 			break; /* normal loop exit */
9332 		offset += (off_t)extent;
9333 		value += nget;
9334 	}
9335 
9336 	return status;
9337 }
9338 
9339 
9340 static int
getNCvx_uint_schar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,schar * value)9341 getNCvx_uint_schar(const NC3_INFO* ncp, const NC_var *varp,
9342 		 const size_t *start, size_t nelems, schar *value)
9343 {
9344 	off_t offset = NC_varoffset(ncp, varp, start);
9345 	size_t remaining = varp->xsz * nelems;
9346 	int status = NC_NOERR;
9347 	const void *xp;
9348 
9349 	if(nelems == 0)
9350 		return NC_NOERR;
9351 
9352 	assert(value != NULL);
9353 
9354 	for(;;)
9355 	{
9356 		size_t extent = MIN(remaining, ncp->chunk);
9357 		size_t nget = ncx_howmany(varp->type, extent);
9358 
9359 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9360 				 0, (void **)&xp);	/* cast away const */
9361 		if(lstatus != NC_NOERR)
9362 			return lstatus;
9363 
9364 		lstatus = ncx_getn_uint_schar(&xp, nget, value);
9365 		if(lstatus != NC_NOERR && status == NC_NOERR)
9366 			status = lstatus;
9367 
9368 		(void) ncio_rel(ncp->nciop, offset, 0);
9369 
9370 		remaining -= extent;
9371 		if(remaining == 0)
9372 			break; /* normal loop exit */
9373 		offset += (off_t)extent;
9374 		value += nget;
9375 	}
9376 
9377 	return status;
9378 }
9379 
9380 static int
getNCvx_uint_uchar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uchar * value)9381 getNCvx_uint_uchar(const NC3_INFO* ncp, const NC_var *varp,
9382 		 const size_t *start, size_t nelems, uchar *value)
9383 {
9384 	off_t offset = NC_varoffset(ncp, varp, start);
9385 	size_t remaining = varp->xsz * nelems;
9386 	int status = NC_NOERR;
9387 	const void *xp;
9388 
9389 	if(nelems == 0)
9390 		return NC_NOERR;
9391 
9392 	assert(value != NULL);
9393 
9394 	for(;;)
9395 	{
9396 		size_t extent = MIN(remaining, ncp->chunk);
9397 		size_t nget = ncx_howmany(varp->type, extent);
9398 
9399 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9400 				 0, (void **)&xp);	/* cast away const */
9401 		if(lstatus != NC_NOERR)
9402 			return lstatus;
9403 
9404 		lstatus = ncx_getn_uint_uchar(&xp, nget, value);
9405 		if(lstatus != NC_NOERR && status == NC_NOERR)
9406 			status = lstatus;
9407 
9408 		(void) ncio_rel(ncp->nciop, offset, 0);
9409 
9410 		remaining -= extent;
9411 		if(remaining == 0)
9412 			break; /* normal loop exit */
9413 		offset += (off_t)extent;
9414 		value += nget;
9415 	}
9416 
9417 	return status;
9418 }
9419 
9420 static int
getNCvx_uint_short(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,short * value)9421 getNCvx_uint_short(const NC3_INFO* ncp, const NC_var *varp,
9422 		 const size_t *start, size_t nelems, short *value)
9423 {
9424 	off_t offset = NC_varoffset(ncp, varp, start);
9425 	size_t remaining = varp->xsz * nelems;
9426 	int status = NC_NOERR;
9427 	const void *xp;
9428 
9429 	if(nelems == 0)
9430 		return NC_NOERR;
9431 
9432 	assert(value != NULL);
9433 
9434 	for(;;)
9435 	{
9436 		size_t extent = MIN(remaining, ncp->chunk);
9437 		size_t nget = ncx_howmany(varp->type, extent);
9438 
9439 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9440 				 0, (void **)&xp);	/* cast away const */
9441 		if(lstatus != NC_NOERR)
9442 			return lstatus;
9443 
9444 		lstatus = ncx_getn_uint_short(&xp, nget, value);
9445 		if(lstatus != NC_NOERR && status == NC_NOERR)
9446 			status = lstatus;
9447 
9448 		(void) ncio_rel(ncp->nciop, offset, 0);
9449 
9450 		remaining -= extent;
9451 		if(remaining == 0)
9452 			break; /* normal loop exit */
9453 		offset += (off_t)extent;
9454 		value += nget;
9455 	}
9456 
9457 	return status;
9458 }
9459 
9460 static int
getNCvx_uint_int(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,int * value)9461 getNCvx_uint_int(const NC3_INFO* ncp, const NC_var *varp,
9462 		 const size_t *start, size_t nelems, int *value)
9463 {
9464 	off_t offset = NC_varoffset(ncp, varp, start);
9465 	size_t remaining = varp->xsz * nelems;
9466 	int status = NC_NOERR;
9467 	const void *xp;
9468 
9469 	if(nelems == 0)
9470 		return NC_NOERR;
9471 
9472 	assert(value != NULL);
9473 
9474 	for(;;)
9475 	{
9476 		size_t extent = MIN(remaining, ncp->chunk);
9477 		size_t nget = ncx_howmany(varp->type, extent);
9478 
9479 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9480 				 0, (void **)&xp);	/* cast away const */
9481 		if(lstatus != NC_NOERR)
9482 			return lstatus;
9483 
9484 		lstatus = ncx_getn_uint_int(&xp, nget, value);
9485 		if(lstatus != NC_NOERR && status == NC_NOERR)
9486 			status = lstatus;
9487 
9488 		(void) ncio_rel(ncp->nciop, offset, 0);
9489 
9490 		remaining -= extent;
9491 		if(remaining == 0)
9492 			break; /* normal loop exit */
9493 		offset += (off_t)extent;
9494 		value += nget;
9495 	}
9496 
9497 	return status;
9498 }
9499 
9500 static int
getNCvx_uint_float(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,float * value)9501 getNCvx_uint_float(const NC3_INFO* ncp, const NC_var *varp,
9502 		 const size_t *start, size_t nelems, float *value)
9503 {
9504 	off_t offset = NC_varoffset(ncp, varp, start);
9505 	size_t remaining = varp->xsz * nelems;
9506 	int status = NC_NOERR;
9507 	const void *xp;
9508 
9509 	if(nelems == 0)
9510 		return NC_NOERR;
9511 
9512 	assert(value != NULL);
9513 
9514 	for(;;)
9515 	{
9516 		size_t extent = MIN(remaining, ncp->chunk);
9517 		size_t nget = ncx_howmany(varp->type, extent);
9518 
9519 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9520 				 0, (void **)&xp);	/* cast away const */
9521 		if(lstatus != NC_NOERR)
9522 			return lstatus;
9523 
9524 		lstatus = ncx_getn_uint_float(&xp, nget, value);
9525 		if(lstatus != NC_NOERR && status == NC_NOERR)
9526 			status = lstatus;
9527 
9528 		(void) ncio_rel(ncp->nciop, offset, 0);
9529 
9530 		remaining -= extent;
9531 		if(remaining == 0)
9532 			break; /* normal loop exit */
9533 		offset += (off_t)extent;
9534 		value += nget;
9535 	}
9536 
9537 	return status;
9538 }
9539 
9540 static int
getNCvx_uint_double(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,double * value)9541 getNCvx_uint_double(const NC3_INFO* ncp, const NC_var *varp,
9542 		 const size_t *start, size_t nelems, double *value)
9543 {
9544 	off_t offset = NC_varoffset(ncp, varp, start);
9545 	size_t remaining = varp->xsz * nelems;
9546 	int status = NC_NOERR;
9547 	const void *xp;
9548 
9549 	if(nelems == 0)
9550 		return NC_NOERR;
9551 
9552 	assert(value != NULL);
9553 
9554 	for(;;)
9555 	{
9556 		size_t extent = MIN(remaining, ncp->chunk);
9557 		size_t nget = ncx_howmany(varp->type, extent);
9558 
9559 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9560 				 0, (void **)&xp);	/* cast away const */
9561 		if(lstatus != NC_NOERR)
9562 			return lstatus;
9563 
9564 		lstatus = ncx_getn_uint_double(&xp, nget, value);
9565 		if(lstatus != NC_NOERR && status == NC_NOERR)
9566 			status = lstatus;
9567 
9568 		(void) ncio_rel(ncp->nciop, offset, 0);
9569 
9570 		remaining -= extent;
9571 		if(remaining == 0)
9572 			break; /* normal loop exit */
9573 		offset += (off_t)extent;
9574 		value += nget;
9575 	}
9576 
9577 	return status;
9578 }
9579 
9580 static int
getNCvx_uint_longlong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,longlong * value)9581 getNCvx_uint_longlong(const NC3_INFO* ncp, const NC_var *varp,
9582 		 const size_t *start, size_t nelems, longlong *value)
9583 {
9584 	off_t offset = NC_varoffset(ncp, varp, start);
9585 	size_t remaining = varp->xsz * nelems;
9586 	int status = NC_NOERR;
9587 	const void *xp;
9588 
9589 	if(nelems == 0)
9590 		return NC_NOERR;
9591 
9592 	assert(value != NULL);
9593 
9594 	for(;;)
9595 	{
9596 		size_t extent = MIN(remaining, ncp->chunk);
9597 		size_t nget = ncx_howmany(varp->type, extent);
9598 
9599 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9600 				 0, (void **)&xp);	/* cast away const */
9601 		if(lstatus != NC_NOERR)
9602 			return lstatus;
9603 
9604 		lstatus = ncx_getn_uint_longlong(&xp, nget, value);
9605 		if(lstatus != NC_NOERR && status == NC_NOERR)
9606 			status = lstatus;
9607 
9608 		(void) ncio_rel(ncp->nciop, offset, 0);
9609 
9610 		remaining -= extent;
9611 		if(remaining == 0)
9612 			break; /* normal loop exit */
9613 		offset += (off_t)extent;
9614 		value += nget;
9615 	}
9616 
9617 	return status;
9618 }
9619 
9620 static int
getNCvx_uint_uint(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uint * value)9621 getNCvx_uint_uint(const NC3_INFO* ncp, const NC_var *varp,
9622 		 const size_t *start, size_t nelems, uint *value)
9623 {
9624 	off_t offset = NC_varoffset(ncp, varp, start);
9625 	size_t remaining = varp->xsz * nelems;
9626 	int status = NC_NOERR;
9627 	const void *xp;
9628 
9629 	if(nelems == 0)
9630 		return NC_NOERR;
9631 
9632 	assert(value != NULL);
9633 
9634 	for(;;)
9635 	{
9636 		size_t extent = MIN(remaining, ncp->chunk);
9637 		size_t nget = ncx_howmany(varp->type, extent);
9638 
9639 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9640 				 0, (void **)&xp);	/* cast away const */
9641 		if(lstatus != NC_NOERR)
9642 			return lstatus;
9643 
9644 		lstatus = ncx_getn_uint_uint(&xp, nget, value);
9645 		if(lstatus != NC_NOERR && status == NC_NOERR)
9646 			status = lstatus;
9647 
9648 		(void) ncio_rel(ncp->nciop, offset, 0);
9649 
9650 		remaining -= extent;
9651 		if(remaining == 0)
9652 			break; /* normal loop exit */
9653 		offset += (off_t)extent;
9654 		value += nget;
9655 	}
9656 
9657 	return status;
9658 }
9659 
9660 static int
getNCvx_uint_ulonglong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ulonglong * value)9661 getNCvx_uint_ulonglong(const NC3_INFO* ncp, const NC_var *varp,
9662 		 const size_t *start, size_t nelems, ulonglong *value)
9663 {
9664 	off_t offset = NC_varoffset(ncp, varp, start);
9665 	size_t remaining = varp->xsz * nelems;
9666 	int status = NC_NOERR;
9667 	const void *xp;
9668 
9669 	if(nelems == 0)
9670 		return NC_NOERR;
9671 
9672 	assert(value != NULL);
9673 
9674 	for(;;)
9675 	{
9676 		size_t extent = MIN(remaining, ncp->chunk);
9677 		size_t nget = ncx_howmany(varp->type, extent);
9678 
9679 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9680 				 0, (void **)&xp);	/* cast away const */
9681 		if(lstatus != NC_NOERR)
9682 			return lstatus;
9683 
9684 		lstatus = ncx_getn_uint_ulonglong(&xp, nget, value);
9685 		if(lstatus != NC_NOERR && status == NC_NOERR)
9686 			status = lstatus;
9687 
9688 		(void) ncio_rel(ncp->nciop, offset, 0);
9689 
9690 		remaining -= extent;
9691 		if(remaining == 0)
9692 			break; /* normal loop exit */
9693 		offset += (off_t)extent;
9694 		value += nget;
9695 	}
9696 
9697 	return status;
9698 }
9699 
9700 static int
getNCvx_uint_ushort(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ushort * value)9701 getNCvx_uint_ushort(const NC3_INFO* ncp, const NC_var *varp,
9702 		 const size_t *start, size_t nelems, ushort *value)
9703 {
9704 	off_t offset = NC_varoffset(ncp, varp, start);
9705 	size_t remaining = varp->xsz * nelems;
9706 	int status = NC_NOERR;
9707 	const void *xp;
9708 
9709 	if(nelems == 0)
9710 		return NC_NOERR;
9711 
9712 	assert(value != NULL);
9713 
9714 	for(;;)
9715 	{
9716 		size_t extent = MIN(remaining, ncp->chunk);
9717 		size_t nget = ncx_howmany(varp->type, extent);
9718 
9719 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9720 				 0, (void **)&xp);	/* cast away const */
9721 		if(lstatus != NC_NOERR)
9722 			return lstatus;
9723 
9724 		lstatus = ncx_getn_uint_ushort(&xp, nget, value);
9725 		if(lstatus != NC_NOERR && status == NC_NOERR)
9726 			status = lstatus;
9727 
9728 		(void) ncio_rel(ncp->nciop, offset, 0);
9729 
9730 		remaining -= extent;
9731 		if(remaining == 0)
9732 			break; /* normal loop exit */
9733 		offset += (off_t)extent;
9734 		value += nget;
9735 	}
9736 
9737 	return status;
9738 }
9739 
9740 
9741 static int
getNCvx_longlong_schar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,schar * value)9742 getNCvx_longlong_schar(const NC3_INFO* ncp, const NC_var *varp,
9743 		 const size_t *start, size_t nelems, schar *value)
9744 {
9745 	off_t offset = NC_varoffset(ncp, varp, start);
9746 	size_t remaining = varp->xsz * nelems;
9747 	int status = NC_NOERR;
9748 	const void *xp;
9749 
9750 	if(nelems == 0)
9751 		return NC_NOERR;
9752 
9753 	assert(value != NULL);
9754 
9755 	for(;;)
9756 	{
9757 		size_t extent = MIN(remaining, ncp->chunk);
9758 		size_t nget = ncx_howmany(varp->type, extent);
9759 
9760 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9761 				 0, (void **)&xp);	/* cast away const */
9762 		if(lstatus != NC_NOERR)
9763 			return lstatus;
9764 
9765 		lstatus = ncx_getn_longlong_schar(&xp, nget, value);
9766 		if(lstatus != NC_NOERR && status == NC_NOERR)
9767 			status = lstatus;
9768 
9769 		(void) ncio_rel(ncp->nciop, offset, 0);
9770 
9771 		remaining -= extent;
9772 		if(remaining == 0)
9773 			break; /* normal loop exit */
9774 		offset += (off_t)extent;
9775 		value += nget;
9776 	}
9777 
9778 	return status;
9779 }
9780 
9781 static int
getNCvx_longlong_uchar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uchar * value)9782 getNCvx_longlong_uchar(const NC3_INFO* ncp, const NC_var *varp,
9783 		 const size_t *start, size_t nelems, uchar *value)
9784 {
9785 	off_t offset = NC_varoffset(ncp, varp, start);
9786 	size_t remaining = varp->xsz * nelems;
9787 	int status = NC_NOERR;
9788 	const void *xp;
9789 
9790 	if(nelems == 0)
9791 		return NC_NOERR;
9792 
9793 	assert(value != NULL);
9794 
9795 	for(;;)
9796 	{
9797 		size_t extent = MIN(remaining, ncp->chunk);
9798 		size_t nget = ncx_howmany(varp->type, extent);
9799 
9800 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9801 				 0, (void **)&xp);	/* cast away const */
9802 		if(lstatus != NC_NOERR)
9803 			return lstatus;
9804 
9805 		lstatus = ncx_getn_longlong_uchar(&xp, nget, value);
9806 		if(lstatus != NC_NOERR && status == NC_NOERR)
9807 			status = lstatus;
9808 
9809 		(void) ncio_rel(ncp->nciop, offset, 0);
9810 
9811 		remaining -= extent;
9812 		if(remaining == 0)
9813 			break; /* normal loop exit */
9814 		offset += (off_t)extent;
9815 		value += nget;
9816 	}
9817 
9818 	return status;
9819 }
9820 
9821 static int
getNCvx_longlong_short(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,short * value)9822 getNCvx_longlong_short(const NC3_INFO* ncp, const NC_var *varp,
9823 		 const size_t *start, size_t nelems, short *value)
9824 {
9825 	off_t offset = NC_varoffset(ncp, varp, start);
9826 	size_t remaining = varp->xsz * nelems;
9827 	int status = NC_NOERR;
9828 	const void *xp;
9829 
9830 	if(nelems == 0)
9831 		return NC_NOERR;
9832 
9833 	assert(value != NULL);
9834 
9835 	for(;;)
9836 	{
9837 		size_t extent = MIN(remaining, ncp->chunk);
9838 		size_t nget = ncx_howmany(varp->type, extent);
9839 
9840 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9841 				 0, (void **)&xp);	/* cast away const */
9842 		if(lstatus != NC_NOERR)
9843 			return lstatus;
9844 
9845 		lstatus = ncx_getn_longlong_short(&xp, nget, value);
9846 		if(lstatus != NC_NOERR && status == NC_NOERR)
9847 			status = lstatus;
9848 
9849 		(void) ncio_rel(ncp->nciop, offset, 0);
9850 
9851 		remaining -= extent;
9852 		if(remaining == 0)
9853 			break; /* normal loop exit */
9854 		offset += (off_t)extent;
9855 		value += nget;
9856 	}
9857 
9858 	return status;
9859 }
9860 
9861 static int
getNCvx_longlong_int(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,int * value)9862 getNCvx_longlong_int(const NC3_INFO* ncp, const NC_var *varp,
9863 		 const size_t *start, size_t nelems, int *value)
9864 {
9865 	off_t offset = NC_varoffset(ncp, varp, start);
9866 	size_t remaining = varp->xsz * nelems;
9867 	int status = NC_NOERR;
9868 	const void *xp;
9869 
9870 	if(nelems == 0)
9871 		return NC_NOERR;
9872 
9873 	assert(value != NULL);
9874 
9875 	for(;;)
9876 	{
9877 		size_t extent = MIN(remaining, ncp->chunk);
9878 		size_t nget = ncx_howmany(varp->type, extent);
9879 
9880 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9881 				 0, (void **)&xp);	/* cast away const */
9882 		if(lstatus != NC_NOERR)
9883 			return lstatus;
9884 
9885 		lstatus = ncx_getn_longlong_int(&xp, nget, value);
9886 		if(lstatus != NC_NOERR && status == NC_NOERR)
9887 			status = lstatus;
9888 
9889 		(void) ncio_rel(ncp->nciop, offset, 0);
9890 
9891 		remaining -= extent;
9892 		if(remaining == 0)
9893 			break; /* normal loop exit */
9894 		offset += (off_t)extent;
9895 		value += nget;
9896 	}
9897 
9898 	return status;
9899 }
9900 
9901 static int
getNCvx_longlong_float(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,float * value)9902 getNCvx_longlong_float(const NC3_INFO* ncp, const NC_var *varp,
9903 		 const size_t *start, size_t nelems, float *value)
9904 {
9905 	off_t offset = NC_varoffset(ncp, varp, start);
9906 	size_t remaining = varp->xsz * nelems;
9907 	int status = NC_NOERR;
9908 	const void *xp;
9909 
9910 	if(nelems == 0)
9911 		return NC_NOERR;
9912 
9913 	assert(value != NULL);
9914 
9915 	for(;;)
9916 	{
9917 		size_t extent = MIN(remaining, ncp->chunk);
9918 		size_t nget = ncx_howmany(varp->type, extent);
9919 
9920 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9921 				 0, (void **)&xp);	/* cast away const */
9922 		if(lstatus != NC_NOERR)
9923 			return lstatus;
9924 
9925 		lstatus = ncx_getn_longlong_float(&xp, nget, value);
9926 		if(lstatus != NC_NOERR && status == NC_NOERR)
9927 			status = lstatus;
9928 
9929 		(void) ncio_rel(ncp->nciop, offset, 0);
9930 
9931 		remaining -= extent;
9932 		if(remaining == 0)
9933 			break; /* normal loop exit */
9934 		offset += (off_t)extent;
9935 		value += nget;
9936 	}
9937 
9938 	return status;
9939 }
9940 
9941 static int
getNCvx_longlong_double(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,double * value)9942 getNCvx_longlong_double(const NC3_INFO* ncp, const NC_var *varp,
9943 		 const size_t *start, size_t nelems, double *value)
9944 {
9945 	off_t offset = NC_varoffset(ncp, varp, start);
9946 	size_t remaining = varp->xsz * nelems;
9947 	int status = NC_NOERR;
9948 	const void *xp;
9949 
9950 	if(nelems == 0)
9951 		return NC_NOERR;
9952 
9953 	assert(value != NULL);
9954 
9955 	for(;;)
9956 	{
9957 		size_t extent = MIN(remaining, ncp->chunk);
9958 		size_t nget = ncx_howmany(varp->type, extent);
9959 
9960 		int lstatus = ncio_get(ncp->nciop, offset, extent,
9961 				 0, (void **)&xp);	/* cast away const */
9962 		if(lstatus != NC_NOERR)
9963 			return lstatus;
9964 
9965 		lstatus = ncx_getn_longlong_double(&xp, nget, value);
9966 		if(lstatus != NC_NOERR && status == NC_NOERR)
9967 			status = lstatus;
9968 
9969 		(void) ncio_rel(ncp->nciop, offset, 0);
9970 
9971 		remaining -= extent;
9972 		if(remaining == 0)
9973 			break; /* normal loop exit */
9974 		offset += (off_t)extent;
9975 		value += nget;
9976 	}
9977 
9978 	return status;
9979 }
9980 
9981 static int
getNCvx_longlong_longlong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,longlong * value)9982 getNCvx_longlong_longlong(const NC3_INFO* ncp, const NC_var *varp,
9983 		 const size_t *start, size_t nelems, longlong *value)
9984 {
9985 	off_t offset = NC_varoffset(ncp, varp, start);
9986 	size_t remaining = varp->xsz * nelems;
9987 	int status = NC_NOERR;
9988 	const void *xp;
9989 
9990 	if(nelems == 0)
9991 		return NC_NOERR;
9992 
9993 	assert(value != NULL);
9994 
9995 	for(;;)
9996 	{
9997 		size_t extent = MIN(remaining, ncp->chunk);
9998 		size_t nget = ncx_howmany(varp->type, extent);
9999 
10000 		int lstatus = ncio_get(ncp->nciop, offset, extent,
10001 				 0, (void **)&xp);	/* cast away const */
10002 		if(lstatus != NC_NOERR)
10003 			return lstatus;
10004 
10005 		lstatus = ncx_getn_longlong_longlong(&xp, nget, value);
10006 		if(lstatus != NC_NOERR && status == NC_NOERR)
10007 			status = lstatus;
10008 
10009 		(void) ncio_rel(ncp->nciop, offset, 0);
10010 
10011 		remaining -= extent;
10012 		if(remaining == 0)
10013 			break; /* normal loop exit */
10014 		offset += (off_t)extent;
10015 		value += nget;
10016 	}
10017 
10018 	return status;
10019 }
10020 
10021 static int
getNCvx_longlong_uint(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uint * value)10022 getNCvx_longlong_uint(const NC3_INFO* ncp, const NC_var *varp,
10023 		 const size_t *start, size_t nelems, uint *value)
10024 {
10025 	off_t offset = NC_varoffset(ncp, varp, start);
10026 	size_t remaining = varp->xsz * nelems;
10027 	int status = NC_NOERR;
10028 	const void *xp;
10029 
10030 	if(nelems == 0)
10031 		return NC_NOERR;
10032 
10033 	assert(value != NULL);
10034 
10035 	for(;;)
10036 	{
10037 		size_t extent = MIN(remaining, ncp->chunk);
10038 		size_t nget = ncx_howmany(varp->type, extent);
10039 
10040 		int lstatus = ncio_get(ncp->nciop, offset, extent,
10041 				 0, (void **)&xp);	/* cast away const */
10042 		if(lstatus != NC_NOERR)
10043 			return lstatus;
10044 
10045 		lstatus = ncx_getn_longlong_uint(&xp, nget, value);
10046 		if(lstatus != NC_NOERR && status == NC_NOERR)
10047 			status = lstatus;
10048 
10049 		(void) ncio_rel(ncp->nciop, offset, 0);
10050 
10051 		remaining -= extent;
10052 		if(remaining == 0)
10053 			break; /* normal loop exit */
10054 		offset += (off_t)extent;
10055 		value += nget;
10056 	}
10057 
10058 	return status;
10059 }
10060 
10061 static int
getNCvx_longlong_ulonglong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ulonglong * value)10062 getNCvx_longlong_ulonglong(const NC3_INFO* ncp, const NC_var *varp,
10063 		 const size_t *start, size_t nelems, ulonglong *value)
10064 {
10065 	off_t offset = NC_varoffset(ncp, varp, start);
10066 	size_t remaining = varp->xsz * nelems;
10067 	int status = NC_NOERR;
10068 	const void *xp;
10069 
10070 	if(nelems == 0)
10071 		return NC_NOERR;
10072 
10073 	assert(value != NULL);
10074 
10075 	for(;;)
10076 	{
10077 		size_t extent = MIN(remaining, ncp->chunk);
10078 		size_t nget = ncx_howmany(varp->type, extent);
10079 
10080 		int lstatus = ncio_get(ncp->nciop, offset, extent,
10081 				 0, (void **)&xp);	/* cast away const */
10082 		if(lstatus != NC_NOERR)
10083 			return lstatus;
10084 
10085 		lstatus = ncx_getn_longlong_ulonglong(&xp, nget, value);
10086 		if(lstatus != NC_NOERR && status == NC_NOERR)
10087 			status = lstatus;
10088 
10089 		(void) ncio_rel(ncp->nciop, offset, 0);
10090 
10091 		remaining -= extent;
10092 		if(remaining == 0)
10093 			break; /* normal loop exit */
10094 		offset += (off_t)extent;
10095 		value += nget;
10096 	}
10097 
10098 	return status;
10099 }
10100 
10101 static int
getNCvx_longlong_ushort(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ushort * value)10102 getNCvx_longlong_ushort(const NC3_INFO* ncp, const NC_var *varp,
10103 		 const size_t *start, size_t nelems, ushort *value)
10104 {
10105 	off_t offset = NC_varoffset(ncp, varp, start);
10106 	size_t remaining = varp->xsz * nelems;
10107 	int status = NC_NOERR;
10108 	const void *xp;
10109 
10110 	if(nelems == 0)
10111 		return NC_NOERR;
10112 
10113 	assert(value != NULL);
10114 
10115 	for(;;)
10116 	{
10117 		size_t extent = MIN(remaining, ncp->chunk);
10118 		size_t nget = ncx_howmany(varp->type, extent);
10119 
10120 		int lstatus = ncio_get(ncp->nciop, offset, extent,
10121 				 0, (void **)&xp);	/* cast away const */
10122 		if(lstatus != NC_NOERR)
10123 			return lstatus;
10124 
10125 		lstatus = ncx_getn_longlong_ushort(&xp, nget, value);
10126 		if(lstatus != NC_NOERR && status == NC_NOERR)
10127 			status = lstatus;
10128 
10129 		(void) ncio_rel(ncp->nciop, offset, 0);
10130 
10131 		remaining -= extent;
10132 		if(remaining == 0)
10133 			break; /* normal loop exit */
10134 		offset += (off_t)extent;
10135 		value += nget;
10136 	}
10137 
10138 	return status;
10139 }
10140 
10141 
10142 static int
getNCvx_ulonglong_schar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,schar * value)10143 getNCvx_ulonglong_schar(const NC3_INFO* ncp, const NC_var *varp,
10144 		 const size_t *start, size_t nelems, schar *value)
10145 {
10146 	off_t offset = NC_varoffset(ncp, varp, start);
10147 	size_t remaining = varp->xsz * nelems;
10148 	int status = NC_NOERR;
10149 	const void *xp;
10150 
10151 	if(nelems == 0)
10152 		return NC_NOERR;
10153 
10154 	assert(value != NULL);
10155 
10156 	for(;;)
10157 	{
10158 		size_t extent = MIN(remaining, ncp->chunk);
10159 		size_t nget = ncx_howmany(varp->type, extent);
10160 
10161 		int lstatus = ncio_get(ncp->nciop, offset, extent,
10162 				 0, (void **)&xp);	/* cast away const */
10163 		if(lstatus != NC_NOERR)
10164 			return lstatus;
10165 
10166 		lstatus = ncx_getn_ulonglong_schar(&xp, nget, value);
10167 		if(lstatus != NC_NOERR && status == NC_NOERR)
10168 			status = lstatus;
10169 
10170 		(void) ncio_rel(ncp->nciop, offset, 0);
10171 
10172 		remaining -= extent;
10173 		if(remaining == 0)
10174 			break; /* normal loop exit */
10175 		offset += (off_t)extent;
10176 		value += nget;
10177 	}
10178 
10179 	return status;
10180 }
10181 
10182 static int
getNCvx_ulonglong_uchar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uchar * value)10183 getNCvx_ulonglong_uchar(const NC3_INFO* ncp, const NC_var *varp,
10184 		 const size_t *start, size_t nelems, uchar *value)
10185 {
10186 	off_t offset = NC_varoffset(ncp, varp, start);
10187 	size_t remaining = varp->xsz * nelems;
10188 	int status = NC_NOERR;
10189 	const void *xp;
10190 
10191 	if(nelems == 0)
10192 		return NC_NOERR;
10193 
10194 	assert(value != NULL);
10195 
10196 	for(;;)
10197 	{
10198 		size_t extent = MIN(remaining, ncp->chunk);
10199 		size_t nget = ncx_howmany(varp->type, extent);
10200 
10201 		int lstatus = ncio_get(ncp->nciop, offset, extent,
10202 				 0, (void **)&xp);	/* cast away const */
10203 		if(lstatus != NC_NOERR)
10204 			return lstatus;
10205 
10206 		lstatus = ncx_getn_ulonglong_uchar(&xp, nget, value);
10207 		if(lstatus != NC_NOERR && status == NC_NOERR)
10208 			status = lstatus;
10209 
10210 		(void) ncio_rel(ncp->nciop, offset, 0);
10211 
10212 		remaining -= extent;
10213 		if(remaining == 0)
10214 			break; /* normal loop exit */
10215 		offset += (off_t)extent;
10216 		value += nget;
10217 	}
10218 
10219 	return status;
10220 }
10221 
10222 static int
getNCvx_ulonglong_short(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,short * value)10223 getNCvx_ulonglong_short(const NC3_INFO* ncp, const NC_var *varp,
10224 		 const size_t *start, size_t nelems, short *value)
10225 {
10226 	off_t offset = NC_varoffset(ncp, varp, start);
10227 	size_t remaining = varp->xsz * nelems;
10228 	int status = NC_NOERR;
10229 	const void *xp;
10230 
10231 	if(nelems == 0)
10232 		return NC_NOERR;
10233 
10234 	assert(value != NULL);
10235 
10236 	for(;;)
10237 	{
10238 		size_t extent = MIN(remaining, ncp->chunk);
10239 		size_t nget = ncx_howmany(varp->type, extent);
10240 
10241 		int lstatus = ncio_get(ncp->nciop, offset, extent,
10242 				 0, (void **)&xp);	/* cast away const */
10243 		if(lstatus != NC_NOERR)
10244 			return lstatus;
10245 
10246 		lstatus = ncx_getn_ulonglong_short(&xp, nget, value);
10247 		if(lstatus != NC_NOERR && status == NC_NOERR)
10248 			status = lstatus;
10249 
10250 		(void) ncio_rel(ncp->nciop, offset, 0);
10251 
10252 		remaining -= extent;
10253 		if(remaining == 0)
10254 			break; /* normal loop exit */
10255 		offset += (off_t)extent;
10256 		value += nget;
10257 	}
10258 
10259 	return status;
10260 }
10261 
10262 static int
getNCvx_ulonglong_int(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,int * value)10263 getNCvx_ulonglong_int(const NC3_INFO* ncp, const NC_var *varp,
10264 		 const size_t *start, size_t nelems, int *value)
10265 {
10266 	off_t offset = NC_varoffset(ncp, varp, start);
10267 	size_t remaining = varp->xsz * nelems;
10268 	int status = NC_NOERR;
10269 	const void *xp;
10270 
10271 	if(nelems == 0)
10272 		return NC_NOERR;
10273 
10274 	assert(value != NULL);
10275 
10276 	for(;;)
10277 	{
10278 		size_t extent = MIN(remaining, ncp->chunk);
10279 		size_t nget = ncx_howmany(varp->type, extent);
10280 
10281 		int lstatus = ncio_get(ncp->nciop, offset, extent,
10282 				 0, (void **)&xp);	/* cast away const */
10283 		if(lstatus != NC_NOERR)
10284 			return lstatus;
10285 
10286 		lstatus = ncx_getn_ulonglong_int(&xp, nget, value);
10287 		if(lstatus != NC_NOERR && status == NC_NOERR)
10288 			status = lstatus;
10289 
10290 		(void) ncio_rel(ncp->nciop, offset, 0);
10291 
10292 		remaining -= extent;
10293 		if(remaining == 0)
10294 			break; /* normal loop exit */
10295 		offset += (off_t)extent;
10296 		value += nget;
10297 	}
10298 
10299 	return status;
10300 }
10301 
10302 static int
getNCvx_ulonglong_float(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,float * value)10303 getNCvx_ulonglong_float(const NC3_INFO* ncp, const NC_var *varp,
10304 		 const size_t *start, size_t nelems, float *value)
10305 {
10306 	off_t offset = NC_varoffset(ncp, varp, start);
10307 	size_t remaining = varp->xsz * nelems;
10308 	int status = NC_NOERR;
10309 	const void *xp;
10310 
10311 	if(nelems == 0)
10312 		return NC_NOERR;
10313 
10314 	assert(value != NULL);
10315 
10316 	for(;;)
10317 	{
10318 		size_t extent = MIN(remaining, ncp->chunk);
10319 		size_t nget = ncx_howmany(varp->type, extent);
10320 
10321 		int lstatus = ncio_get(ncp->nciop, offset, extent,
10322 				 0, (void **)&xp);	/* cast away const */
10323 		if(lstatus != NC_NOERR)
10324 			return lstatus;
10325 
10326 		lstatus = ncx_getn_ulonglong_float(&xp, nget, value);
10327 		if(lstatus != NC_NOERR && status == NC_NOERR)
10328 			status = lstatus;
10329 
10330 		(void) ncio_rel(ncp->nciop, offset, 0);
10331 
10332 		remaining -= extent;
10333 		if(remaining == 0)
10334 			break; /* normal loop exit */
10335 		offset += (off_t)extent;
10336 		value += nget;
10337 	}
10338 
10339 	return status;
10340 }
10341 
10342 static int
getNCvx_ulonglong_double(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,double * value)10343 getNCvx_ulonglong_double(const NC3_INFO* ncp, const NC_var *varp,
10344 		 const size_t *start, size_t nelems, double *value)
10345 {
10346 	off_t offset = NC_varoffset(ncp, varp, start);
10347 	size_t remaining = varp->xsz * nelems;
10348 	int status = NC_NOERR;
10349 	const void *xp;
10350 
10351 	if(nelems == 0)
10352 		return NC_NOERR;
10353 
10354 	assert(value != NULL);
10355 
10356 	for(;;)
10357 	{
10358 		size_t extent = MIN(remaining, ncp->chunk);
10359 		size_t nget = ncx_howmany(varp->type, extent);
10360 
10361 		int lstatus = ncio_get(ncp->nciop, offset, extent,
10362 				 0, (void **)&xp);	/* cast away const */
10363 		if(lstatus != NC_NOERR)
10364 			return lstatus;
10365 
10366 		lstatus = ncx_getn_ulonglong_double(&xp, nget, value);
10367 		if(lstatus != NC_NOERR && status == NC_NOERR)
10368 			status = lstatus;
10369 
10370 		(void) ncio_rel(ncp->nciop, offset, 0);
10371 
10372 		remaining -= extent;
10373 		if(remaining == 0)
10374 			break; /* normal loop exit */
10375 		offset += (off_t)extent;
10376 		value += nget;
10377 	}
10378 
10379 	return status;
10380 }
10381 
10382 static int
getNCvx_ulonglong_longlong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,longlong * value)10383 getNCvx_ulonglong_longlong(const NC3_INFO* ncp, const NC_var *varp,
10384 		 const size_t *start, size_t nelems, longlong *value)
10385 {
10386 	off_t offset = NC_varoffset(ncp, varp, start);
10387 	size_t remaining = varp->xsz * nelems;
10388 	int status = NC_NOERR;
10389 	const void *xp;
10390 
10391 	if(nelems == 0)
10392 		return NC_NOERR;
10393 
10394 	assert(value != NULL);
10395 
10396 	for(;;)
10397 	{
10398 		size_t extent = MIN(remaining, ncp->chunk);
10399 		size_t nget = ncx_howmany(varp->type, extent);
10400 
10401 		int lstatus = ncio_get(ncp->nciop, offset, extent,
10402 				 0, (void **)&xp);	/* cast away const */
10403 		if(lstatus != NC_NOERR)
10404 			return lstatus;
10405 
10406 		lstatus = ncx_getn_ulonglong_longlong(&xp, nget, value);
10407 		if(lstatus != NC_NOERR && status == NC_NOERR)
10408 			status = lstatus;
10409 
10410 		(void) ncio_rel(ncp->nciop, offset, 0);
10411 
10412 		remaining -= extent;
10413 		if(remaining == 0)
10414 			break; /* normal loop exit */
10415 		offset += (off_t)extent;
10416 		value += nget;
10417 	}
10418 
10419 	return status;
10420 }
10421 
10422 static int
getNCvx_ulonglong_uint(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uint * value)10423 getNCvx_ulonglong_uint(const NC3_INFO* ncp, const NC_var *varp,
10424 		 const size_t *start, size_t nelems, uint *value)
10425 {
10426 	off_t offset = NC_varoffset(ncp, varp, start);
10427 	size_t remaining = varp->xsz * nelems;
10428 	int status = NC_NOERR;
10429 	const void *xp;
10430 
10431 	if(nelems == 0)
10432 		return NC_NOERR;
10433 
10434 	assert(value != NULL);
10435 
10436 	for(;;)
10437 	{
10438 		size_t extent = MIN(remaining, ncp->chunk);
10439 		size_t nget = ncx_howmany(varp->type, extent);
10440 
10441 		int lstatus = ncio_get(ncp->nciop, offset, extent,
10442 				 0, (void **)&xp);	/* cast away const */
10443 		if(lstatus != NC_NOERR)
10444 			return lstatus;
10445 
10446 		lstatus = ncx_getn_ulonglong_uint(&xp, nget, value);
10447 		if(lstatus != NC_NOERR && status == NC_NOERR)
10448 			status = lstatus;
10449 
10450 		(void) ncio_rel(ncp->nciop, offset, 0);
10451 
10452 		remaining -= extent;
10453 		if(remaining == 0)
10454 			break; /* normal loop exit */
10455 		offset += (off_t)extent;
10456 		value += nget;
10457 	}
10458 
10459 	return status;
10460 }
10461 
10462 static int
getNCvx_ulonglong_ulonglong(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ulonglong * value)10463 getNCvx_ulonglong_ulonglong(const NC3_INFO* ncp, const NC_var *varp,
10464 		 const size_t *start, size_t nelems, ulonglong *value)
10465 {
10466 	off_t offset = NC_varoffset(ncp, varp, start);
10467 	size_t remaining = varp->xsz * nelems;
10468 	int status = NC_NOERR;
10469 	const void *xp;
10470 
10471 	if(nelems == 0)
10472 		return NC_NOERR;
10473 
10474 	assert(value != NULL);
10475 
10476 	for(;;)
10477 	{
10478 		size_t extent = MIN(remaining, ncp->chunk);
10479 		size_t nget = ncx_howmany(varp->type, extent);
10480 
10481 		int lstatus = ncio_get(ncp->nciop, offset, extent,
10482 				 0, (void **)&xp);	/* cast away const */
10483 		if(lstatus != NC_NOERR)
10484 			return lstatus;
10485 
10486 		lstatus = ncx_getn_ulonglong_ulonglong(&xp, nget, value);
10487 		if(lstatus != NC_NOERR && status == NC_NOERR)
10488 			status = lstatus;
10489 
10490 		(void) ncio_rel(ncp->nciop, offset, 0);
10491 
10492 		remaining -= extent;
10493 		if(remaining == 0)
10494 			break; /* normal loop exit */
10495 		offset += (off_t)extent;
10496 		value += nget;
10497 	}
10498 
10499 	return status;
10500 }
10501 
10502 static int
getNCvx_ulonglong_ushort(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,ushort * value)10503 getNCvx_ulonglong_ushort(const NC3_INFO* ncp, const NC_var *varp,
10504 		 const size_t *start, size_t nelems, ushort *value)
10505 {
10506 	off_t offset = NC_varoffset(ncp, varp, start);
10507 	size_t remaining = varp->xsz * nelems;
10508 	int status = NC_NOERR;
10509 	const void *xp;
10510 
10511 	if(nelems == 0)
10512 		return NC_NOERR;
10513 
10514 	assert(value != NULL);
10515 
10516 	for(;;)
10517 	{
10518 		size_t extent = MIN(remaining, ncp->chunk);
10519 		size_t nget = ncx_howmany(varp->type, extent);
10520 
10521 		int lstatus = ncio_get(ncp->nciop, offset, extent,
10522 				 0, (void **)&xp);	/* cast away const */
10523 		if(lstatus != NC_NOERR)
10524 			return lstatus;
10525 
10526 		lstatus = ncx_getn_ulonglong_ushort(&xp, nget, value);
10527 		if(lstatus != NC_NOERR && status == NC_NOERR)
10528 			status = lstatus;
10529 
10530 		(void) ncio_rel(ncp->nciop, offset, 0);
10531 
10532 		remaining -= extent;
10533 		if(remaining == 0)
10534 			break; /* normal loop exit */
10535 		offset += (off_t)extent;
10536 		value += nget;
10537 	}
10538 
10539 	return status;
10540 }
10541 
10542 
10543 #ifdef NOTUSED
10544 static int
getNCvx_schar_uchar(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,size_t nelems,uchar * value)10545 getNCvx_schar_uchar(const NC3_INFO* ncp, const NC_var *varp,
10546 		 const size_t *start, size_t nelems, uchar *value)
10547 {
10548 	off_t offset = NC_varoffset(ncp, varp, start);
10549 	size_t remaining = varp->xsz * nelems;
10550 	int status = NC_NOERR;
10551 	const void *xp;
10552 
10553 	if(nelems == 0)
10554 		return NC_NOERR;
10555 
10556 	assert(value != NULL);
10557 
10558 	for(;;)
10559 	{
10560 		size_t extent = MIN(remaining, ncp->chunk);
10561 		size_t nget = ncx_howmany(varp->type, extent);
10562 
10563 		int lstatus = ncio_get(ncp->nciop, offset, extent,
10564 				 0, (void **)&xp);	/* cast away const */
10565 		if(lstatus != NC_NOERR)
10566 			return lstatus;
10567 
10568 		lstatus = ncx_getn_schar_uchar(&xp, nget, value);
10569 		if(lstatus != NC_NOERR && status == NC_NOERR)
10570 			status = lstatus;
10571 
10572 		(void) ncio_rel(ncp->nciop, offset, 0);
10573 
10574 		remaining -= extent;
10575 		if(remaining == 0)
10576 			break; /* normal loop exit */
10577 		offset += (off_t)extent;
10578 		value += nget;
10579 	}
10580 
10581 	return status;
10582 }
10583 
10584 #endif /*NOTUSED*/
10585 
10586 /*
10587  *  For ncvar{put,get},
10588  *  find the largest contiguous block from within 'edges'.
10589  *  returns the index to the left of this (which may be -1).
10590  *  Compute the number of contiguous elements and return
10591  *  that in *iocountp.
10592  *  The presence of "record" variables makes this routine
10593  *  overly subtle.
10594  */
10595 static int
NCiocount(const NC3_INFO * const ncp,const NC_var * const varp,const size_t * const edges,size_t * const iocountp)10596 NCiocount(const NC3_INFO* const ncp, const NC_var *const varp,
10597 	const size_t *const edges,
10598 	size_t *const iocountp)
10599 {
10600 	const size_t *edp0 = edges;
10601 	const size_t *edp = edges + varp->ndims;
10602 	const size_t *shp = varp->shape + varp->ndims;
10603 
10604 	if(IS_RECVAR(varp))
10605 	{
10606 		if(varp->ndims == 1 && ncp->recsize <= varp->len)
10607 		{
10608 			/* one dimensional && the only 'record' variable */
10609 			*iocountp = *edges;
10610 			return(0);
10611 		}
10612 		/* else */
10613 		edp0++;
10614 	}
10615 
10616 	assert(edges != NULL);
10617 
10618 	/* find max contiguous */
10619 	while(edp > edp0)
10620 	{
10621 		shp--; edp--;
10622 		if(*edp < *shp )
10623 		{
10624 			const size_t *zedp = edp;
10625 			while(zedp >= edp0)
10626 			{
10627 				if(*zedp == 0)
10628 				{
10629 					*iocountp = 0;
10630 					goto done;
10631 				}
10632 				/* Tip of the hat to segmented architectures */
10633 				if(zedp == edp0)
10634 					break;
10635 				zedp--;
10636 			}
10637 			break;
10638 		}
10639 		assert(*edp == *shp);
10640 	}
10641 
10642 	/*
10643 	 * edp, shp reference rightmost index s.t. *(edp +1) == *(shp +1)
10644 	 *
10645 	 * Or there is only one dimension.
10646 	 * If there is only one dimension and it is 'non record' dimension,
10647 	 * 	edp is &edges[0] and we will return -1.
10648 	 * If there is only one dimension and and it is a "record dimension",
10649 	 *	edp is &edges[1] (out of bounds) and we will return 0;
10650 	 */
10651 	assert(shp >= varp->shape + varp->ndims -1
10652 		|| *(edp +1) == *(shp +1));
10653 
10654 	/* now accumulate max count for a single io operation */
10655 	for(*iocountp = 1, edp0 = edp;
10656 		 	edp0 < edges + varp->ndims;
10657 			edp0++)
10658 	{
10659 		*iocountp *= *edp0;
10660 	}
10661 
10662 done:
10663 	return((int)(edp - edges) - 1);
10664 }
10665 
10666 
10667 /*
10668  * Set the elements of the array 'upp' to
10669  * the sum of the corresponding elements of
10670  * 'stp' and 'edp'. 'end' should be &stp[nelems].
10671  */
10672 static void
set_upper(size_t * upp,const size_t * stp,const size_t * edp,const size_t * const end)10673 set_upper(size_t *upp, /* modified on return */
10674 	const size_t *stp,
10675 	const size_t *edp,
10676 	const size_t *const end)
10677 {
10678 	while(upp < end) {
10679 		*upp++ = *stp++ + *edp++;
10680 	}
10681 }
10682 
10683 
10684 /*
10685  * The infamous and oft-discussed odometer code.
10686  *
10687  * 'start[]' is the starting coordinate.
10688  * 'upper[]' is the upper bound s.t. start[ii] < upper[ii].
10689  * 'coord[]' is the register, the current coordinate value.
10690  * For some ii,
10691  * upp == &upper[ii]
10692  * cdp == &coord[ii]
10693  *
10694  * Running this routine increments *cdp.
10695  *
10696  * If after the increment, *cdp is equal to *upp
10697  * (and cdp is not the leftmost dimension),
10698  * *cdp is "zeroed" to the starting value and
10699  * we need to "carry", eg, increment one place to
10700  * the left.
10701  *
10702  * TODO: Some architectures hate recursion?
10703  * 	Reimplement non-recursively.
10704  */
10705 static void
odo1(const size_t * const start,const size_t * const upper,size_t * const coord,const size_t * upp,size_t * cdp)10706 odo1(const size_t *const start, const size_t *const upper,
10707 	size_t *const coord, /* modified on return */
10708 	const size_t *upp,
10709 	size_t *cdp)
10710 {
10711 	assert(coord <= cdp && cdp <= coord + NC_MAX_VAR_DIMS);
10712 	assert(upper <= upp && upp <= upper + NC_MAX_VAR_DIMS);
10713 	assert(upp - upper == cdp - coord);
10714 
10715 	assert(*cdp <= *upp);
10716 
10717 	(*cdp)++;
10718 	if(cdp != coord && *cdp >= *upp)
10719 	{
10720 		*cdp = start[cdp - coord];
10721 		odo1(start, upper, coord, upp -1, cdp -1);
10722 	}
10723 }
10724 #ifdef _CRAYC
10725 #pragma _CRI noinline odo1
10726 #endif
10727 
10728 
10729 
10730 /* Define a macro to allow hash on two type values */
10731 #define CASE(nc1,nc2) (nc1*256+nc2)
10732 
10733 static int
readNCv(const NC3_INFO * ncp,const NC_var * varp,const size_t * start,const size_t nelems,void * value,const nc_type memtype)10734 readNCv(const NC3_INFO* ncp, const NC_var* varp, const size_t* start,
10735         const size_t nelems, void* value, const nc_type memtype)
10736 {
10737     int status = NC_NOERR;
10738     switch (CASE(varp->type,memtype)) {
10739 
10740     case CASE(NC_CHAR,NC_CHAR):
10741     case CASE(NC_CHAR,NC_UBYTE):
10742     return getNCvx_schar_schar(ncp,varp,start,nelems,(signed char*)value);
10743     break;
10744     case CASE(NC_BYTE,NC_BYTE):
10745         return getNCvx_schar_schar(ncp,varp,start,nelems, (schar*)value);
10746 	break;
10747     case CASE(NC_BYTE,NC_UBYTE):
10748         if (fIsSet(ncp->flags,NC_64BIT_DATA))
10749             return getNCvx_schar_uchar(ncp,varp,start,nelems,(unsigned char*)value);
10750         else
10751             /* for CDF-1 and CDF-2, NC_BYTE is treated the same type as uchar memtype */
10752             return getNCvx_uchar_uchar(ncp,varp,start,nelems,(unsigned char*)value);
10753 	break;
10754     case CASE(NC_BYTE,NC_SHORT):
10755         return getNCvx_schar_short(ncp,varp,start,nelems,(short*)value);
10756 	break;
10757     case CASE(NC_BYTE,NC_INT):
10758         return getNCvx_schar_int(ncp,varp,start,nelems,(int*)value);
10759 	break;
10760     case CASE(NC_BYTE,NC_FLOAT):
10761         return getNCvx_schar_float(ncp,varp,start,nelems,(float*)value);
10762 	break;
10763     case CASE(NC_BYTE,NC_DOUBLE):
10764         return getNCvx_schar_double(ncp,varp,start,nelems,(double *)value);
10765 	break;
10766     case CASE(NC_BYTE,NC_INT64):
10767         return getNCvx_schar_longlong(ncp,varp,start,nelems,(long long*)value);
10768 	break;
10769     case CASE(NC_BYTE,NC_UINT):
10770         return getNCvx_schar_uint(ncp,varp,start,nelems,(unsigned int*)value);
10771 	break;
10772     case CASE(NC_BYTE,NC_UINT64):
10773         return getNCvx_schar_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
10774     	break;
10775     case CASE(NC_BYTE,NC_USHORT):
10776         return getNCvx_schar_ushort(ncp,varp,start,nelems,(unsigned short*)value);
10777 	break;
10778     case CASE(NC_SHORT,NC_BYTE):
10779         return getNCvx_short_schar(ncp,varp,start,nelems,(schar*)value);
10780 	break;
10781     case CASE(NC_SHORT,NC_UBYTE):
10782         return getNCvx_short_uchar(ncp,varp,start,nelems,(unsigned char*)value);
10783 	break;
10784     case CASE(NC_SHORT,NC_SHORT):
10785         return getNCvx_short_short(ncp,varp,start,nelems,(short*)value);
10786 	break;
10787     case CASE(NC_SHORT,NC_INT):
10788         return getNCvx_short_int(ncp,varp,start,nelems,(int*)value);
10789 	break;
10790    case CASE(NC_SHORT,NC_FLOAT):
10791         return getNCvx_short_float(ncp,varp,start,nelems,(float*)value);
10792 	break;
10793     case CASE(NC_SHORT,NC_DOUBLE):
10794         return getNCvx_short_double(ncp,varp,start,nelems,(double*)value);
10795 	break;
10796     case CASE(NC_SHORT,NC_INT64):
10797         return getNCvx_short_longlong(ncp,varp,start,nelems,(long long*)value);
10798    	break;
10799     case CASE(NC_SHORT,NC_UINT):
10800         return getNCvx_short_uint(ncp,varp,start,nelems,(unsigned int*)value);
10801     	break;
10802     case CASE(NC_SHORT,NC_UINT64):
10803         return getNCvx_short_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
10804 	break;
10805     case CASE(NC_SHORT,NC_USHORT):
10806         return getNCvx_short_ushort(ncp,varp,start,nelems,(unsigned short*)value);
10807 	break;
10808 
10809     case CASE(NC_INT,NC_BYTE):
10810         return getNCvx_int_schar(ncp,varp,start,nelems,(schar*)value);
10811 	break;
10812     case CASE(NC_INT,NC_UBYTE):
10813         return getNCvx_int_uchar(ncp,varp,start,nelems,(unsigned char*)value);
10814 	break;
10815     case CASE(NC_INT,NC_SHORT):
10816         return getNCvx_int_short(ncp,varp,start,nelems,(short*)value);
10817 	break;
10818     case CASE(NC_INT,NC_INT):
10819         return getNCvx_int_int(ncp,varp,start,nelems,(int*)value);
10820 	break;
10821     case CASE(NC_INT,NC_FLOAT):
10822         return getNCvx_int_float(ncp,varp,start,nelems,(float*)value);
10823 	break;
10824     case CASE(NC_INT,NC_DOUBLE):
10825         return getNCvx_int_double(ncp,varp,start,nelems,(double*)value);
10826 	break;
10827     case CASE(NC_INT,NC_INT64):
10828         return getNCvx_int_longlong(ncp,varp,start,nelems,(long long*)value);
10829 	break;
10830     case CASE(NC_INT,NC_UINT):
10831         return getNCvx_int_uint(ncp,varp,start,nelems,(unsigned int*)value);
10832 	break;
10833     case CASE(NC_INT,NC_UINT64):
10834         return getNCvx_int_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
10835 	break;
10836     case CASE(NC_INT,NC_USHORT):
10837         return getNCvx_int_ushort(ncp,varp,start,nelems,(unsigned short*)value);
10838 	break;
10839 
10840     case CASE(NC_FLOAT,NC_BYTE):
10841         return getNCvx_float_schar(ncp,varp,start,nelems,(schar*)value);
10842 	break;
10843     case CASE(NC_FLOAT,NC_UBYTE):
10844         return getNCvx_float_uchar(ncp,varp,start,nelems,(unsigned char*)value);
10845 	break;
10846     case CASE(NC_FLOAT,NC_SHORT):
10847         return getNCvx_float_short(ncp,varp,start,nelems,(short*)value);
10848 	break;
10849     case CASE(NC_FLOAT,NC_INT):
10850         return getNCvx_float_int(ncp,varp,start,nelems,(int*)value);
10851 	break;
10852     case CASE(NC_FLOAT,NC_FLOAT):
10853         return getNCvx_float_float(ncp,varp,start,nelems,(float*)value);
10854 	break;
10855     case CASE(NC_FLOAT,NC_DOUBLE):
10856         return getNCvx_float_double(ncp,varp,start,nelems,(double*)value);
10857 	break;
10858     case CASE(NC_FLOAT,NC_INT64):
10859         return getNCvx_float_longlong(ncp,varp,start,nelems,(long long*)value);
10860 	break;
10861     case CASE(NC_FLOAT,NC_UINT):
10862         return getNCvx_float_uint(ncp,varp,start,nelems,(unsigned int*)value);
10863 	break;
10864     case CASE(NC_FLOAT,NC_UINT64):
10865         return getNCvx_float_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
10866 	break;
10867     case CASE(NC_FLOAT,NC_USHORT):
10868         return getNCvx_float_ushort(ncp,varp,start,nelems,(unsigned short*)value);
10869 	break;
10870 
10871     case CASE(NC_DOUBLE,NC_BYTE):
10872         return getNCvx_double_schar(ncp,varp,start,nelems,(schar*)value);
10873 	break;
10874     case CASE(NC_DOUBLE,NC_UBYTE):
10875         return getNCvx_double_uchar(ncp,varp,start,nelems,(unsigned char*)value);
10876 	break;
10877     case CASE(NC_DOUBLE,NC_SHORT):
10878         return getNCvx_double_short(ncp,varp,start,nelems,(short*)value);
10879 	break;
10880     case CASE(NC_DOUBLE,NC_INT):
10881         return getNCvx_double_int(ncp,varp,start,nelems,(int*)value);
10882 	break;
10883     case CASE(NC_DOUBLE,NC_FLOAT):
10884         return getNCvx_double_float(ncp,varp,start,nelems,(float*)value);
10885 	break;
10886     case CASE(NC_DOUBLE,NC_DOUBLE):
10887         return getNCvx_double_double(ncp,varp,start,nelems,(double*)value);
10888 	break;
10889     case CASE(NC_DOUBLE,NC_INT64):
10890         return getNCvx_double_longlong(ncp,varp,start,nelems,(long long*)value);
10891 	break;
10892     case CASE(NC_DOUBLE,NC_UINT):
10893         return getNCvx_double_uint(ncp,varp,start,nelems,(unsigned int*)value);
10894 	break;
10895     case CASE(NC_DOUBLE,NC_UINT64):
10896         return getNCvx_double_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
10897 	break;
10898     case CASE(NC_DOUBLE,NC_USHORT):
10899         return getNCvx_double_ushort(ncp,varp,start,nelems,(unsigned short*)value);
10900 	break;
10901 
10902     case CASE(NC_UBYTE,NC_UBYTE):
10903         return getNCvx_uchar_uchar(ncp,varp,start,nelems,(unsigned char*)value);
10904 	break;
10905     case CASE(NC_UBYTE,NC_BYTE):
10906         return getNCvx_uchar_schar(ncp,varp,start,nelems,(schar*)value);
10907 	break;
10908     case CASE(NC_UBYTE,NC_SHORT):
10909         return getNCvx_uchar_short(ncp,varp,start,nelems,(short*)value);
10910 	break;
10911     case CASE(NC_UBYTE,NC_INT):
10912         return getNCvx_uchar_int(ncp,varp,start,nelems,(int*)value);
10913 	break;
10914     case CASE(NC_UBYTE,NC_FLOAT):
10915         return getNCvx_uchar_float(ncp,varp,start,nelems,(float*)value);
10916 	break;
10917     case CASE(NC_UBYTE,NC_DOUBLE):
10918         return getNCvx_uchar_double(ncp,varp,start,nelems,(double *)value);
10919 	break;
10920     case CASE(NC_UBYTE,NC_INT64):
10921         return getNCvx_uchar_longlong(ncp,varp,start,nelems,(long long*)value);
10922 	break;
10923     case CASE(NC_UBYTE,NC_UINT):
10924         return getNCvx_uchar_uint(ncp,varp,start,nelems,(unsigned int*)value);
10925 	break;
10926     case CASE(NC_UBYTE,NC_UINT64):
10927         return getNCvx_uchar_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
10928 	break;
10929     case CASE(NC_UBYTE,NC_USHORT):
10930         return getNCvx_uchar_ushort(ncp,varp,start,nelems,(unsigned short*)value);
10931 	break;
10932 
10933     case CASE(NC_USHORT,NC_BYTE):
10934         return getNCvx_ushort_schar(ncp,varp,start,nelems,(schar*)value);
10935 	break;
10936     case CASE(NC_USHORT,NC_UBYTE):
10937         return getNCvx_ushort_uchar(ncp,varp,start,nelems,(unsigned char*)value);
10938 	break;
10939     case CASE(NC_USHORT,NC_SHORT):
10940         return getNCvx_ushort_short(ncp,varp,start,nelems,(short*)value);
10941 	break;
10942     case CASE(NC_USHORT,NC_INT):
10943         return getNCvx_ushort_int(ncp,varp,start,nelems,(int*)value);
10944 	break;
10945     case CASE(NC_USHORT,NC_FLOAT):
10946         return getNCvx_ushort_float(ncp,varp,start,nelems,(float*)value);
10947 	break;
10948     case CASE(NC_USHORT,NC_DOUBLE):
10949         return getNCvx_ushort_double(ncp,varp,start,nelems,(double*)value);
10950 	break;
10951     case CASE(NC_USHORT,NC_INT64):
10952         return getNCvx_ushort_longlong(ncp,varp,start,nelems,(long long*)value);
10953 	break;
10954     case CASE(NC_USHORT,NC_UINT):
10955         return getNCvx_ushort_uint(ncp,varp,start,nelems,(unsigned int*)value);
10956 	break;
10957     case CASE(NC_USHORT,NC_UINT64):
10958         return getNCvx_ushort_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
10959 	break;
10960     case CASE(NC_USHORT,NC_USHORT):
10961         return getNCvx_ushort_ushort(ncp,varp,start,nelems,(unsigned short*)value);
10962 	break;
10963 
10964     case CASE(NC_UINT,NC_BYTE):
10965         return getNCvx_uint_schar(ncp,varp,start,nelems,(schar*)value);
10966 	break;
10967     case CASE(NC_UINT,NC_UBYTE):
10968         return getNCvx_uint_uchar(ncp,varp,start,nelems,(unsigned char*)value);
10969 	break;
10970     case CASE(NC_UINT,NC_SHORT):
10971         return getNCvx_uint_short(ncp,varp,start,nelems,(short*)value);
10972 	break;
10973     case CASE(NC_UINT,NC_INT):
10974         return getNCvx_uint_int(ncp,varp,start,nelems,(int*)value);
10975 	break;
10976     case CASE(NC_UINT,NC_FLOAT):
10977         return getNCvx_uint_float(ncp,varp,start,nelems,(float*)value);
10978 	break;
10979     case CASE(NC_UINT,NC_DOUBLE):
10980         return getNCvx_uint_double(ncp,varp,start,nelems,(double*)value);
10981 	break;
10982     case CASE(NC_UINT,NC_INT64):
10983         return getNCvx_uint_longlong(ncp,varp,start,nelems,(long long*)value);
10984 	break;
10985     case CASE(NC_UINT,NC_UINT):
10986         return getNCvx_uint_uint(ncp,varp,start,nelems,(unsigned int*)value);
10987 	break;
10988     case CASE(NC_UINT,NC_UINT64):
10989         return getNCvx_uint_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
10990 	break;
10991     case CASE(NC_UINT,NC_USHORT):
10992         return getNCvx_uint_ushort(ncp,varp,start,nelems,(unsigned short*)value);
10993 	break;
10994 
10995     case CASE(NC_INT64,NC_BYTE):
10996         return getNCvx_longlong_schar(ncp,varp,start,nelems,(schar*)value);
10997 	break;
10998     case CASE(NC_INT64,NC_UBYTE):
10999         return getNCvx_longlong_uchar(ncp,varp,start,nelems,(unsigned char*)value);
11000 	break;
11001     case CASE(NC_INT64,NC_SHORT):
11002         return getNCvx_longlong_short(ncp,varp,start,nelems,(short*)value);
11003 	break;
11004     case CASE(NC_INT64,NC_INT):
11005         return getNCvx_longlong_int(ncp,varp,start,nelems,(int*)value);
11006 	break;
11007     case CASE(NC_INT64,NC_FLOAT):
11008         return getNCvx_longlong_float(ncp,varp,start,nelems,(float*)value);
11009 	break;
11010     case CASE(NC_INT64,NC_DOUBLE):
11011         return getNCvx_longlong_double(ncp,varp,start,nelems,(double*)value);
11012 	break;
11013     case CASE(NC_INT64,NC_INT64):
11014         return getNCvx_longlong_longlong(ncp,varp,start,nelems,(long long*)value);
11015 	break;
11016     case CASE(NC_INT64,NC_UINT):
11017         return getNCvx_longlong_uint(ncp,varp,start,nelems,(unsigned int*)value);
11018 	break;
11019     case CASE(NC_INT64,NC_UINT64):
11020         return getNCvx_longlong_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
11021 	break;
11022     case CASE(NC_INT64,NC_USHORT):
11023         return getNCvx_longlong_ushort(ncp,varp,start,nelems,(unsigned short*)value);
11024 	break;
11025 
11026     case CASE(NC_UINT64,NC_BYTE):
11027         return getNCvx_ulonglong_schar(ncp,varp,start,nelems,(schar*)value);
11028 	break;
11029     case CASE(NC_UINT64,NC_UBYTE):
11030         return getNCvx_ulonglong_uchar(ncp,varp,start,nelems,(unsigned char*)value);
11031 	break;
11032     case CASE(NC_UINT64,NC_SHORT):
11033         return getNCvx_ulonglong_short(ncp,varp,start,nelems,(short*)value);
11034 	break;
11035     case CASE(NC_UINT64,NC_INT):
11036         return getNCvx_ulonglong_int(ncp,varp,start,nelems,(int*)value);
11037 	break;
11038     case CASE(NC_UINT64,NC_FLOAT):
11039         return getNCvx_ulonglong_float(ncp,varp,start,nelems,(float*)value);
11040 	break;
11041     case CASE(NC_UINT64,NC_DOUBLE):
11042         return getNCvx_ulonglong_double(ncp,varp,start,nelems,(double*)value);
11043 	break;
11044     case CASE(NC_UINT64,NC_INT64):
11045         return getNCvx_ulonglong_longlong(ncp,varp,start,nelems,(long long*)value);
11046 	break;
11047     case CASE(NC_UINT64,NC_UINT):
11048         return getNCvx_ulonglong_uint(ncp,varp,start,nelems,(unsigned int*)value);
11049 	break;
11050     case CASE(NC_UINT64,NC_UINT64):
11051         return getNCvx_ulonglong_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
11052 	break;
11053     case CASE(NC_UINT64,NC_USHORT):
11054         return getNCvx_ulonglong_ushort(ncp,varp,start,nelems,(unsigned short*)value);
11055 	break;
11056 
11057     default:
11058 	return NC_EBADTYPE;
11059 	break;
11060     }
11061     return status;
11062 }
11063 
11064 
11065 static int
writeNCv(NC3_INFO * ncp,const NC_var * varp,const size_t * start,const size_t nelems,const void * value,const nc_type memtype)11066 writeNCv(NC3_INFO* ncp, const NC_var* varp, const size_t* start,
11067          const size_t nelems, const void* value, const nc_type memtype)
11068 {
11069     int status = NC_NOERR;
11070     switch (CASE(varp->type,memtype)) {
11071 
11072     case CASE(NC_CHAR,NC_CHAR):
11073     case CASE(NC_CHAR,NC_UBYTE):
11074         return putNCvx_char_char(ncp,varp,start,nelems,(char*)value);
11075 	break;
11076     case CASE(NC_BYTE,NC_BYTE):
11077         return putNCvx_schar_schar(ncp,varp,start,nelems,(schar*)value);
11078 	break;
11079     case CASE(NC_BYTE,NC_UBYTE):
11080         if (fIsSet(ncp->flags,NC_64BIT_DATA))
11081             return putNCvx_schar_uchar(ncp,varp,start,nelems,(unsigned char*)value);
11082         else
11083             /* for CDF-1 and CDF-2, NC_BYTE is treated the same type as uchar memtype */
11084             return putNCvx_uchar_uchar(ncp,varp,start,nelems,(unsigned char*)value);
11085 	break;
11086     case CASE(NC_BYTE,NC_SHORT):
11087         return putNCvx_schar_short(ncp,varp,start,nelems,(short*)value);
11088 	break;
11089     case CASE(NC_BYTE,NC_INT):
11090         return putNCvx_schar_int(ncp,varp,start,nelems,(int*)value);
11091 	break;
11092     case CASE(NC_BYTE,NC_FLOAT):
11093         return putNCvx_schar_float(ncp,varp,start,nelems,(float*)value);
11094 	break;
11095     case CASE(NC_BYTE,NC_DOUBLE):
11096         return putNCvx_schar_double(ncp,varp,start,nelems,(double *)value);
11097 	break;
11098     case CASE(NC_BYTE,NC_INT64):
11099         return putNCvx_schar_longlong(ncp,varp,start,nelems,(long long*)value);
11100 	break;
11101     case CASE(NC_BYTE,NC_UINT):
11102         return putNCvx_schar_uint(ncp,varp,start,nelems,(unsigned int*)value);
11103 	break;
11104     case CASE(NC_BYTE,NC_UINT64):
11105         return putNCvx_schar_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
11106 	break;
11107     case CASE(NC_BYTE,NC_USHORT):
11108         return putNCvx_schar_ushort(ncp,varp,start,nelems,(unsigned short*)value);
11109 	break;
11110     case CASE(NC_SHORT,NC_BYTE):
11111         return putNCvx_short_schar(ncp,varp,start,nelems,(schar*)value);
11112 	break;
11113     case CASE(NC_SHORT,NC_UBYTE):
11114         return putNCvx_short_uchar(ncp,varp,start,nelems,(unsigned char*)value);
11115 	break;
11116     case CASE(NC_SHORT,NC_SHORT):
11117         return putNCvx_short_short(ncp,varp,start,nelems,(short*)value);
11118 	break;
11119     case CASE(NC_SHORT,NC_INT):
11120         return putNCvx_short_int(ncp,varp,start,nelems,(int*)value);
11121 	break;
11122     case CASE(NC_SHORT,NC_FLOAT):
11123         return putNCvx_short_float(ncp,varp,start,nelems,(float*)value);
11124 	break;
11125     case CASE(NC_SHORT,NC_DOUBLE):
11126         return putNCvx_short_double(ncp,varp,start,nelems,(double*)value);
11127 	break;
11128     case CASE(NC_SHORT,NC_INT64):
11129         return putNCvx_short_longlong(ncp,varp,start,nelems,(long long*)value);
11130 	break;
11131     case CASE(NC_SHORT,NC_UINT):
11132         return putNCvx_short_uint(ncp,varp,start,nelems,(unsigned int*)value);
11133 	break;
11134     case CASE(NC_SHORT,NC_UINT64):
11135         return putNCvx_short_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
11136 	break;
11137     case CASE(NC_SHORT,NC_USHORT):
11138         return putNCvx_short_ushort(ncp,varp,start,nelems,(unsigned short*)value);
11139 	break;
11140     case CASE(NC_INT,NC_BYTE):
11141         return putNCvx_int_schar(ncp,varp,start,nelems,(schar*)value);
11142 	break;
11143     case CASE(NC_INT,NC_UBYTE):
11144         return putNCvx_int_uchar(ncp,varp,start,nelems,(unsigned char*)value);
11145 	break;
11146     case CASE(NC_INT,NC_SHORT):
11147         return putNCvx_int_short(ncp,varp,start,nelems,(short*)value);
11148 	break;
11149     case CASE(NC_INT,NC_INT):
11150         return putNCvx_int_int(ncp,varp,start,nelems,(int*)value);
11151 	break;
11152     case CASE(NC_INT,NC_FLOAT):
11153         return putNCvx_int_float(ncp,varp,start,nelems,(float*)value);
11154 	break;
11155     case CASE(NC_INT,NC_DOUBLE):
11156         return putNCvx_int_double(ncp,varp,start,nelems,(double*)value);
11157 	break;
11158     case CASE(NC_INT,NC_INT64):
11159         return putNCvx_int_longlong(ncp,varp,start,nelems,(long long*)value);
11160 	break;
11161     case CASE(NC_INT,NC_UINT):
11162         return putNCvx_int_uint(ncp,varp,start,nelems,(unsigned int*)value);
11163 	break;
11164     case CASE(NC_INT,NC_UINT64):
11165         return putNCvx_int_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
11166 	break;
11167     case CASE(NC_INT,NC_USHORT):
11168         return putNCvx_int_ushort(ncp,varp,start,nelems,(unsigned short*)value);
11169 	break;
11170     case CASE(NC_FLOAT,NC_BYTE):
11171         return putNCvx_float_schar(ncp,varp,start,nelems,(schar*)value);
11172 	break;
11173     case CASE(NC_FLOAT,NC_UBYTE):
11174         return putNCvx_float_uchar(ncp,varp,start,nelems,(unsigned char*)value);
11175 	break;
11176     case CASE(NC_FLOAT,NC_SHORT):
11177         return putNCvx_float_short(ncp,varp,start,nelems,(short*)value);
11178 	break;
11179     case CASE(NC_FLOAT,NC_INT):
11180         return putNCvx_float_int(ncp,varp,start,nelems,(int*)value);
11181 	break;
11182     case CASE(NC_FLOAT,NC_FLOAT):
11183         return putNCvx_float_float(ncp,varp,start,nelems,(float*)value);
11184 	break;
11185     case CASE(NC_FLOAT,NC_DOUBLE):
11186         return putNCvx_float_double(ncp,varp,start,nelems,(double*)value);
11187 	break;
11188     case CASE(NC_FLOAT,NC_INT64):
11189         return putNCvx_float_longlong(ncp,varp,start,nelems,(long long*)value);
11190 	break;
11191     case CASE(NC_FLOAT,NC_UINT):
11192         return putNCvx_float_uint(ncp,varp,start,nelems,(unsigned int*)value);
11193 	break;
11194     case CASE(NC_FLOAT,NC_UINT64):
11195         return putNCvx_float_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
11196 	break;
11197     case CASE(NC_FLOAT,NC_USHORT):
11198         return putNCvx_float_ushort(ncp,varp,start,nelems,(unsigned short*)value);
11199 	break;
11200     case CASE(NC_DOUBLE,NC_BYTE):
11201         return putNCvx_double_schar(ncp,varp,start,nelems,(schar*)value);
11202 	break;
11203     case CASE(NC_DOUBLE,NC_UBYTE):
11204         return putNCvx_double_uchar(ncp,varp,start,nelems,(unsigned char*)value);
11205 	break;
11206     case CASE(NC_DOUBLE,NC_SHORT):
11207         return putNCvx_double_short(ncp,varp,start,nelems,(short*)value);
11208 	break;
11209     case CASE(NC_DOUBLE,NC_INT):
11210         return putNCvx_double_int(ncp,varp,start,nelems,(int*)value);
11211 	break;
11212     case CASE(NC_DOUBLE,NC_FLOAT):
11213         return putNCvx_double_float(ncp,varp,start,nelems,(float*)value);
11214 	break;
11215     case CASE(NC_DOUBLE,NC_DOUBLE):
11216         return putNCvx_double_double(ncp,varp,start,nelems,(double*)value);
11217 	break;
11218     case CASE(NC_DOUBLE,NC_INT64):
11219         return putNCvx_double_longlong(ncp,varp,start,nelems,(long long*)value);
11220 	break;
11221     case CASE(NC_DOUBLE,NC_UINT):
11222         return putNCvx_double_uint(ncp,varp,start,nelems,(unsigned int*)value);
11223 	break;
11224     case CASE(NC_DOUBLE,NC_UINT64):
11225         return putNCvx_double_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
11226 	break;
11227     case CASE(NC_DOUBLE,NC_USHORT):
11228         return putNCvx_double_ushort(ncp,varp,start,nelems,(unsigned short*)value);
11229 	break;
11230     case CASE(NC_UBYTE,NC_UBYTE):
11231         return putNCvx_uchar_uchar(ncp,varp,start,nelems,(unsigned char*)value);
11232 	break;
11233     case CASE(NC_UBYTE,NC_BYTE):
11234         return putNCvx_uchar_schar(ncp,varp,start,nelems,(schar*)value);
11235 	break;
11236     case CASE(NC_UBYTE,NC_SHORT):
11237         return putNCvx_uchar_short(ncp,varp,start,nelems,(short*)value);
11238 	break;
11239     case CASE(NC_UBYTE,NC_INT):
11240         return putNCvx_uchar_int(ncp,varp,start,nelems,(int*)value);
11241 	break;
11242     case CASE(NC_UBYTE,NC_FLOAT):
11243         return putNCvx_uchar_float(ncp,varp,start,nelems,(float*)value);
11244 	break;
11245     case CASE(NC_UBYTE,NC_DOUBLE):
11246         return putNCvx_uchar_double(ncp,varp,start,nelems,(double *)value);
11247 	break;
11248     case CASE(NC_UBYTE,NC_INT64):
11249         return putNCvx_uchar_longlong(ncp,varp,start,nelems,(long long*)value);
11250 	break;
11251     case CASE(NC_UBYTE,NC_UINT):
11252         return putNCvx_uchar_uint(ncp,varp,start,nelems,(unsigned int*)value);
11253 	break;
11254     case CASE(NC_UBYTE,NC_UINT64):
11255         return putNCvx_uchar_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
11256 	break;
11257     case CASE(NC_UBYTE,NC_USHORT):
11258         return putNCvx_uchar_ushort(ncp,varp,start,nelems,(unsigned short*)value);
11259 	break;
11260     case CASE(NC_USHORT,NC_BYTE):
11261         return putNCvx_ushort_schar(ncp,varp,start,nelems,(schar*)value);
11262 	break;
11263     case CASE(NC_USHORT,NC_UBYTE):
11264         return putNCvx_ushort_uchar(ncp,varp,start,nelems,(unsigned char*)value);
11265 	break;
11266     case CASE(NC_USHORT,NC_SHORT):
11267         return putNCvx_ushort_short(ncp,varp,start,nelems,(short*)value);
11268 	break;
11269     case CASE(NC_USHORT,NC_INT):
11270         return putNCvx_ushort_int(ncp,varp,start,nelems,(int*)value);
11271 	break;
11272     case CASE(NC_USHORT,NC_FLOAT):
11273         return putNCvx_ushort_float(ncp,varp,start,nelems,(float*)value);
11274 	break;
11275     case CASE(NC_USHORT,NC_DOUBLE):
11276         return putNCvx_ushort_double(ncp,varp,start,nelems,(double*)value);
11277 	break;
11278     case CASE(NC_USHORT,NC_INT64):
11279         return putNCvx_ushort_longlong(ncp,varp,start,nelems,(long long*)value);
11280 	break;
11281     case CASE(NC_USHORT,NC_UINT):
11282         return putNCvx_ushort_uint(ncp,varp,start,nelems,(unsigned int*)value);
11283 	break;
11284     case CASE(NC_USHORT,NC_UINT64):
11285         return putNCvx_ushort_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
11286 	break;
11287     case CASE(NC_USHORT,NC_USHORT):
11288         return putNCvx_ushort_ushort(ncp,varp,start,nelems,(unsigned short*)value);
11289 	break;
11290     case CASE(NC_UINT,NC_BYTE):
11291         return putNCvx_uint_schar(ncp,varp,start,nelems,(schar*)value);
11292 	break;
11293     case CASE(NC_UINT,NC_UBYTE):
11294         return putNCvx_uint_uchar(ncp,varp,start,nelems,(unsigned char*)value);
11295 	break;
11296     case CASE(NC_UINT,NC_SHORT):
11297         return putNCvx_uint_short(ncp,varp,start,nelems,(short*)value);
11298 	break;
11299     case CASE(NC_UINT,NC_INT):
11300         return putNCvx_uint_int(ncp,varp,start,nelems,(int*)value);
11301 	break;
11302     case CASE(NC_UINT,NC_FLOAT):
11303         return putNCvx_uint_float(ncp,varp,start,nelems,(float*)value);
11304 	break;
11305     case CASE(NC_UINT,NC_DOUBLE):
11306         return putNCvx_uint_double(ncp,varp,start,nelems,(double*)value);
11307 	break;
11308     case CASE(NC_UINT,NC_INT64):
11309         return putNCvx_uint_longlong(ncp,varp,start,nelems,(long long*)value);
11310 	break;
11311     case CASE(NC_UINT,NC_UINT):
11312         return putNCvx_uint_uint(ncp,varp,start,nelems,(unsigned int*)value);
11313 	break;
11314     case CASE(NC_UINT,NC_UINT64):
11315         return putNCvx_uint_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
11316 	break;
11317     case CASE(NC_UINT,NC_USHORT):
11318         return putNCvx_uint_ushort(ncp,varp,start,nelems,(unsigned short*)value);
11319 	break;
11320     case CASE(NC_INT64,NC_BYTE):
11321         return putNCvx_longlong_schar(ncp,varp,start,nelems,(schar*)value);
11322 	break;
11323     case CASE(NC_INT64,NC_UBYTE):
11324         return putNCvx_longlong_uchar(ncp,varp,start,nelems,(unsigned char*)value);
11325 	break;
11326     case CASE(NC_INT64,NC_SHORT):
11327         return putNCvx_longlong_short(ncp,varp,start,nelems,(short*)value);
11328 	break;
11329     case CASE(NC_INT64,NC_INT):
11330         return putNCvx_longlong_int(ncp,varp,start,nelems,(int*)value);
11331 	break;
11332     case CASE(NC_INT64,NC_FLOAT):
11333         return putNCvx_longlong_float(ncp,varp,start,nelems,(float*)value);
11334 	break;
11335     case CASE(NC_INT64,NC_DOUBLE):
11336         return putNCvx_longlong_double(ncp,varp,start,nelems,(double*)value);
11337 	break;
11338     case CASE(NC_INT64,NC_INT64):
11339         return putNCvx_longlong_longlong(ncp,varp,start,nelems,(long long*)value);
11340 	break;
11341     case CASE(NC_INT64,NC_UINT):
11342         return putNCvx_longlong_uint(ncp,varp,start,nelems,(unsigned int*)value);
11343 	break;
11344     case CASE(NC_INT64,NC_UINT64):
11345         return putNCvx_longlong_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
11346 	break;
11347     case CASE(NC_INT64,NC_USHORT):
11348         return putNCvx_longlong_ushort(ncp,varp,start,nelems,(unsigned short*)value);
11349 	break;
11350     case CASE(NC_UINT64,NC_BYTE):
11351         return putNCvx_ulonglong_schar(ncp,varp,start,nelems,(schar*)value);
11352 	break;
11353     case CASE(NC_UINT64,NC_UBYTE):
11354         return putNCvx_ulonglong_uchar(ncp,varp,start,nelems,(unsigned char*)value);
11355 	break;
11356     case CASE(NC_UINT64,NC_SHORT):
11357         return putNCvx_ulonglong_short(ncp,varp,start,nelems,(short*)value);
11358 	break;
11359     case CASE(NC_UINT64,NC_INT):
11360         return putNCvx_ulonglong_int(ncp,varp,start,nelems,(int*)value);
11361 	break;
11362     case CASE(NC_UINT64,NC_FLOAT):
11363         return putNCvx_ulonglong_float(ncp,varp,start,nelems,(float*)value);
11364 	break;
11365     case CASE(NC_UINT64,NC_DOUBLE):
11366         return putNCvx_ulonglong_double(ncp,varp,start,nelems,(double*)value);
11367 	break;
11368     case CASE(NC_UINT64,NC_INT64):
11369         return putNCvx_ulonglong_longlong(ncp,varp,start,nelems,(long long*)value);
11370 	break;
11371     case CASE(NC_UINT64,NC_UINT):
11372         return putNCvx_ulonglong_uint(ncp,varp,start,nelems,(unsigned int*)value);
11373 	break;
11374     case CASE(NC_UINT64,NC_UINT64):
11375         return putNCvx_ulonglong_ulonglong(ncp,varp,start,nelems,(unsigned long long*)value);
11376 	break;
11377     case CASE(NC_UINT64,NC_USHORT):
11378         return putNCvx_ulonglong_ushort(ncp,varp,start,nelems,(unsigned short*)value);
11379 	break;
11380 
11381     default:
11382 	return NC_EBADTYPE;
11383 	break;
11384     }
11385     return status;
11386 }
11387 
11388 /**************************************************/
11389 
11390 int
NC3_get_vara(int ncid,int varid,const size_t * start,const size_t * edges0,void * value0,nc_type memtype)11391 NC3_get_vara(int ncid, int varid,
11392 	    const size_t *start, const size_t *edges0,
11393             void *value0,
11394 	    nc_type memtype)
11395 {
11396     int status = NC_NOERR;
11397     NC* nc;
11398     NC3_INFO* nc3;
11399     NC_var *varp;
11400     int ii;
11401     size_t iocount;
11402     size_t memtypelen;
11403     signed char* value = (signed char*) value0; /* legally allow ptr arithmetic */
11404     const size_t* edges = edges0; /* so we can modify for special cases */
11405     size_t modedges[NC_MAX_VAR_DIMS];
11406 
11407     status = NC_check_id(ncid, &nc);
11408     if(status != NC_NOERR)
11409         return status;
11410     nc3 = NC3_DATA(nc);
11411 
11412     if(NC_indef(nc3))
11413         return NC_EINDEFINE;
11414 
11415     status = NC_lookupvar(nc3, varid, &varp);
11416     if(status != NC_NOERR)
11417         return status;
11418 
11419     if(memtype == NC_NAT) memtype=varp->type;
11420 
11421     if(memtype == NC_CHAR && varp->type != NC_CHAR)
11422         return NC_ECHAR;
11423     else if(memtype != NC_CHAR && varp->type == NC_CHAR)
11424         return NC_ECHAR;
11425 
11426     /* If edges is NULL, then this was called from nc_get_var() */
11427     if(edges == NULL && varp->ndims > 0) {
11428 	/* If this is a record variable, then we have to
11429            substitute the number of records into dimension 0. */
11430 	if(varp->shape[0] == 0) {
11431 	    (void)memcpy((void*)modedges,(void*)varp->shape,
11432                           sizeof(size_t)*varp->ndims);
11433 	    modedges[0] = NC_get_numrecs(nc3);
11434 	    edges = modedges;
11435 	} else
11436 	    edges = varp->shape;
11437     }
11438 
11439     status = NCcoordck(nc3, varp, start);
11440     if(status != NC_NOERR)
11441         return status;
11442 
11443     status = NCedgeck(nc3, varp, start, edges);
11444     if(status != NC_NOERR)
11445         return status;
11446 
11447     /* Get the size of the memtype */
11448     memtypelen = nctypelen(memtype);
11449 
11450     if(varp->ndims == 0) /* scalar variable */
11451     {
11452         return( readNCv(nc3, varp, start, 1, (void*)value, memtype) );
11453     }
11454 
11455     if(IS_RECVAR(varp))
11456     {
11457         if(*start + *edges > NC_get_numrecs(nc3))
11458             return NC_EEDGE;
11459         if(varp->ndims == 1 && nc3->recsize <= varp->len)
11460         {
11461             /* one dimensional && the only record variable  */
11462             return( readNCv(nc3, varp, start, *edges, (void*)value, memtype) );
11463         }
11464     }
11465 
11466     /*
11467      * find max contiguous
11468      *   and accumulate max count for a single io operation
11469      */
11470     ii = NCiocount(nc3, varp, edges, &iocount);
11471 
11472     if(ii == -1)
11473     {
11474         return( readNCv(nc3, varp, start, iocount, (void*)value, memtype) );
11475     }
11476 
11477     assert(ii >= 0);
11478 
11479     { /* inline */
11480     ALLOC_ONSTACK(coord, size_t, varp->ndims);
11481     ALLOC_ONSTACK(upper, size_t, varp->ndims);
11482     const size_t index = ii;
11483 
11484     /* copy in starting indices */
11485     (void) memcpy(coord, start, varp->ndims * sizeof(size_t));
11486 
11487     /* set up in maximum indices */
11488     set_upper(upper, start, edges, &upper[varp->ndims]);
11489 
11490     /* ripple counter */
11491     while(*coord < *upper)
11492     {
11493         const int lstatus = readNCv(nc3, varp, coord, iocount, (void*)value, memtype);
11494 	if(lstatus != NC_NOERR)
11495         {
11496             if(lstatus != NC_ERANGE)
11497             {
11498                 status = lstatus;
11499                 /* fatal for the loop */
11500                 break;
11501             }
11502             /* else NC_ERANGE, not fatal for the loop */
11503             if(status == NC_NOERR)
11504                 status = lstatus;
11505         }
11506         value += (iocount * memtypelen);
11507         odo1(start, upper, coord, &upper[index], &coord[index]);
11508     }
11509 
11510     FREE_ONSTACK(upper);
11511     FREE_ONSTACK(coord);
11512     } /* end inline */
11513 
11514     return status;
11515 }
11516 
11517 int
NC3_put_vara(int ncid,int varid,const size_t * start,const size_t * edges0,const void * value0,nc_type memtype)11518 NC3_put_vara(int ncid, int varid,
11519 	    const size_t *start, const size_t *edges0,
11520             const void *value0,
11521 	    nc_type memtype)
11522 {
11523     int status = NC_NOERR;
11524     NC *nc;
11525     NC3_INFO* nc3;
11526     NC_var *varp;
11527     int ii;
11528     size_t iocount;
11529     size_t memtypelen;
11530     signed char* value = (signed char*) value0; /* legally allow ptr arithmetic */
11531     const size_t* edges = edges0; /* so we can modify for special cases */
11532     size_t modedges[NC_MAX_VAR_DIMS];
11533 
11534     status = NC_check_id(ncid, &nc);
11535     if(status != NC_NOERR)
11536         return status;
11537     nc3 = NC3_DATA(nc);
11538 
11539     if(NC_readonly(nc3))
11540         return NC_EPERM;
11541 
11542     if(NC_indef(nc3))
11543         return NC_EINDEFINE;
11544 
11545     status = NC_lookupvar(nc3, varid, &varp);
11546     if(status != NC_NOERR)
11547        return status; /*invalid varid */
11548 
11549 
11550     if(memtype == NC_NAT) memtype=varp->type;
11551 
11552     if(memtype == NC_CHAR && varp->type != NC_CHAR)
11553         return NC_ECHAR;
11554     else if(memtype != NC_CHAR && varp->type == NC_CHAR)
11555         return NC_ECHAR;
11556 
11557     /* Get the size of the memtype */
11558     memtypelen = nctypelen(memtype);
11559 
11560     /* If edges is NULL, then this was called from nc_get_var() */
11561     if(edges == NULL && varp->ndims > 0) {
11562 	/* If this is a record variable, then we have to
11563            substitute the number of records into dimension 0. */
11564 	if(varp->shape[0] == 0) {
11565 	    (void)memcpy((void*)modedges,(void*)varp->shape,
11566                           sizeof(size_t)*varp->ndims);
11567 	    modedges[0] = NC_get_numrecs(nc3);
11568 	    edges = modedges;
11569 	} else
11570 	    edges = varp->shape;
11571     }
11572 
11573     status = NCcoordck(nc3, varp, start);
11574     if(status != NC_NOERR)
11575         return status;
11576     status = NCedgeck(nc3, varp, start, edges);
11577     if(status != NC_NOERR)
11578         return status;
11579 
11580     if(varp->ndims == 0) /* scalar variable */
11581     {
11582         return( writeNCv(nc3, varp, start, 1, (void*)value, memtype) );
11583     }
11584 
11585     if(IS_RECVAR(varp))
11586     {
11587         status = NCvnrecs(nc3, *start + *edges);
11588         if(status != NC_NOERR)
11589             return status;
11590 
11591         if(varp->ndims == 1
11592             && nc3->recsize <= varp->len)
11593         {
11594             /* one dimensional && the only record variable  */
11595             return( writeNCv(nc3, varp, start, *edges, (void*)value, memtype) );
11596         }
11597     }
11598 
11599     /*
11600      * find max contiguous
11601      *   and accumulate max count for a single io operation
11602      */
11603     ii = NCiocount(nc3, varp, edges, &iocount);
11604 
11605     if(ii == -1)
11606     {
11607         return( writeNCv(nc3, varp, start, iocount, (void*)value, memtype) );
11608     }
11609 
11610     assert(ii >= 0);
11611 
11612     { /* inline */
11613     ALLOC_ONSTACK(coord, size_t, varp->ndims);
11614     ALLOC_ONSTACK(upper, size_t, varp->ndims);
11615     const size_t index = ii;
11616 
11617     /* copy in starting indices */
11618     (void) memcpy(coord, start, varp->ndims * sizeof(size_t));
11619 
11620     /* set up in maximum indices */
11621     set_upper(upper, start, edges, &upper[varp->ndims]);
11622 
11623     /* ripple counter */
11624     while(*coord < *upper)
11625     {
11626         const int lstatus = writeNCv(nc3, varp, coord, iocount, (void*)value, memtype);
11627         if(lstatus != NC_NOERR)
11628         {
11629             if(lstatus != NC_ERANGE)
11630             {
11631                 status = lstatus;
11632                 /* fatal for the loop */
11633                 break;
11634             }
11635             /* else NC_ERANGE, not fatal for the loop */
11636             if(status == NC_NOERR)
11637                 status = lstatus;
11638         }
11639         value += (iocount * memtypelen);
11640         odo1(start, upper, coord, &upper[index], &coord[index]);
11641     }
11642 
11643     FREE_ONSTACK(upper);
11644     FREE_ONSTACK(coord);
11645     } /* end inline */
11646 
11647     return status;
11648 }
11649