8 #include "ncdispatch.h"
30 odom_init(
struct PUTodometer* odom,
int rank,
const size_t* start,
31 const size_t* edges,
const ptrdiff_t* stride)
34 memset(odom,0,
sizeof(
struct PUTodometer));
37 for(i=0;i<odom->rank;i++) {
38 odom->start[i] = (start != NULL ? start[i] : 0);
39 odom->edges[i] = (edges != NULL ? edges[i] : 1);
40 odom->stride[i] = (stride != NULL ? stride[i] : 1);
41 odom->stop[i] = odom->start[i] + (odom->edges[i]*(size_t)odom->stride[i]);
42 odom->index[i] = odom->start[i];
54 odom_more(
struct PUTodometer* odom)
56 return (odom->index[0] < odom->stop[0]);
67 odom_next(
struct PUTodometer* odom)
70 if(odom->rank == 0)
return 0;
71 for(i=odom->rank-1;i>=0;i--) {
72 odom->index[i] += (size_t)odom->stride[i];
73 if(odom->index[i] < odom->stop[i])
break;
75 odom->index[i] = odom->start[i];
84 NC_put_vara(
int ncid,
int varid,
const size_t *start,
85 const size_t *edges,
const void *value,
nc_type memtype)
88 size_t *my_count = (
size_t *)edges;
90 int stat = NC_check_id(ncid, &ncp);
93 if(start == NULL || edges == NULL) {
94 stat = NC_check_nulls(ncid, varid, start, &my_count, NULL);
97 stat = ncp->dispatch->put_vara(ncid, varid, start, my_count, value, memtype);
98 if(edges == NULL) free(my_count);
106 NC_put_var(
int ncid,
int varid,
const void *value,
nc_type memtype)
111 if(stat)
return stat;
112 stat = NC_getshape(ncid,varid, ndims, shape);
113 if(stat)
return stat;
114 return NC_put_vara(ncid, varid, NC_coord_zero, shape, value, memtype);
121 NC_put_var1(
int ncid,
int varid,
const size_t *coord,
const void* value,
124 return NC_put_vara(ncid, varid, coord, NC_coord_one, value, memtype);
131 NCDEFAULT_put_vars(
int ncid,
int varid,
const size_t * start,
132 const size_t * edges,
const ptrdiff_t * stride,
133 const void *value0,
nc_type memtype)
138 int i,isstride1,isrecvar;
140 struct PUTodometer odom;
146 const char* value = (
const char*)value0;
153 const char* memptr = value;
155 status = NC_check_id (ncid, &ncp);
156 if(status !=
NC_NOERR)
return status;
159 if(status !=
NC_NOERR)
return status;
161 if(memtype ==
NC_NAT) memtype = vartype;
164 status =
nc_inq_type(ncid,vartype,NULL,&vartypelen);
165 if(status !=
NC_NOERR)
return status;
167 if(memtype > NC_MAX_ATOMIC_TYPE)
168 memtypelen = (int)vartypelen;
170 memtypelen = nctypelen(memtype);
173 if(vartype != memtype) {
175 if(vartype > NC_MAX_ATOMIC_TYPE
176 || memtype > NC_MAX_ATOMIC_TYPE)
185 if(status !=
NC_NOERR)
return status;
188 if(rank > 0 && start == NULL)
192 status = NC_inq_recvar(ncid,varid,&nrecdims,is_recdim);
193 if(status !=
NC_NOERR)
return status;
194 isrecvar = (nrecdims > 0);
195 NC_getshape(ncid,varid,rank,varshape);
204 size_t edge1[1] = {1};
205 return NC_put_vara(ncid, varid, start, edge1, value0, memtype);
211 for(i=0;i<rank;i++) {
213 mystart[i] = (start == NULL ? 0 : start[i]);
215 dimlen = (i == 0 && isrecvar ? numrecs : varshape[i]);
216 if(i == 0 && isrecvar) {}
219 dimlen = varshape[i];
228 if(i == 0 && isrecvar)
229 myedges[i] = numrecs - start[i];
231 if(is_recdim[i] && isrecvar)
232 myedges[i] = varshape[i] - start[i];
235 myedges[i] = varshape[i] - mystart[i];
237 myedges[i] = edges[i];
240 if (mystart[i] == dimlen && myedges[i] > 0)
246 if(mystart[i] + myedges[i] > dimlen)
249 mystride[i] = (stride == NULL ? 1 : stride[i]);
252 || ((
unsigned long) mystride[i] >= X_INT_MAX))
254 if(mystride[i] != 1) isstride1 = 0;
259 return NC_put_vara(ncid, varid, mystart, myedges, value, memtype);
276 odom_init(&odom,rank,mystart,myedges,mystride);
279 while(odom_more(&odom)) {
282 localstatus = NC_put_vara(ncid,varid,odom.index,NC_coord_one,memptr,memtype);
288 status = localstatus;
290 memptr += memtypelen;
303 const size_t * start,
304 const size_t * edges,
305 const ptrdiff_t * stride,
306 const ptrdiff_t * imapp,
316 const char* value = (
char*)value0;
318 status = NC_check_id (ncid, &ncp);
319 if(status !=
NC_NOERR)
return status;
328 if(status !=
NC_NOERR)
return status;
330 if(vartype > NC_MAX_ATOMIC_TYPE)
334 if(status !=
NC_NOERR)
return status;
345 memtypelen = nctypelen(memtype);
347 maxidim = (int) varndims - 1;
356 size_t edge1[1] = {1};
357 return NC_put_vara(ncid, varid, start, edge1, value, memtype);
366 size_t *mystart = NULL;
371 ptrdiff_t *mystride = 0;
383 for (idim = 0; idim <= maxidim; ++idim) {
384 if ((stride[idim] == 0)
386 || ((
unsigned long) stride[idim] >= X_INT_MAX))
390 if(stride[idim] != 1) stride1 = 0;
397 if(stride1 && imapp == NULL) {
398 return NC_put_vara(ncid, varid, start, edges, value, memtype);
402 isrecvar = NC_is_recvar(ncid,varid,&numrecs);
403 NC_getshape(ncid,varid,varndims,varshape);
406 mystart = (
size_t *)calloc((
size_t)(varndims * 7),
sizeof(ptrdiff_t));
408 myedges = mystart + varndims;
409 iocount = myedges + varndims;
410 stop = iocount + varndims;
411 length = stop + varndims;
412 mystride = (ptrdiff_t *)(length + varndims);
413 mymap = mystride + varndims;
418 for (idim = maxidim; idim >= 0; --idim)
420 mystart[idim] = start != NULL
424 myedges[idim] = edges != NULL
426 : idim == 0 && isrecvar
427 ? numrecs - mystart[idim]
428 : varshape[idim] - mystart[idim];
431 for (idim = isrecvar; idim <= maxidim; ++idim)
433 if (mystart[idim] > varshape[idim] ||
434 (mystart[idim] == varshape[idim] && myedges[idim] > 0))
440 if (mystart[idim] + myedges[idim] > varshape[idim])
450 for (idim = maxidim; idim >= 0; --idim)
452 if (edges != NULL && edges[idim] == 0)
458 mystride[idim] = stride != NULL
461 mymap[idim] = imapp != NULL
465 : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1];
468 length[idim] = ((size_t)mymap[idim]) * myedges[idim];
469 stop[idim] = mystart[idim] + myedges[idim] * (size_t)mystride[idim];
479 if (mystride[maxidim] == 1
480 && mymap[maxidim] == 1)
482 iocount[maxidim] = myedges[maxidim];
483 mystride[maxidim] = (ptrdiff_t) myedges[maxidim];
484 mymap[maxidim] = (ptrdiff_t) length[maxidim];
493 int lstatus = NC_put_vara(ncid, varid, mystart, iocount,
508 value += (mymap[idim] * memtypelen);
509 mystart[idim] += (size_t)mystride[idim];
510 if (mystart[idim] == stop[idim])
512 size_t l = (length[idim] * (size_t)memtypelen);
514 mystart[idim] = start[idim];
530 NC_put_vars(
int ncid,
int varid,
const size_t *start,
531 const size_t *edges,
const ptrdiff_t *stride,
532 const void *value,
nc_type memtype)
535 size_t *my_count = (
size_t *)edges;
536 ptrdiff_t *my_stride = (ptrdiff_t *)stride;
539 stat = NC_check_id(ncid, &ncp);
543 if(start == NULL || edges == NULL || stride == NULL) {
544 stat = NC_check_nulls(ncid, varid, start, &my_count, &my_stride);
548 stat = ncp->dispatch->put_vars(ncid, varid, start, my_count, my_stride,
550 if(edges == NULL) free(my_count);
551 if(stride == NULL) free(my_stride);
559 NC_put_varm(
int ncid,
int varid,
const size_t *start,
560 const size_t *edges,
const ptrdiff_t *stride,
const ptrdiff_t* map,
561 const void *value,
nc_type memtype)
564 size_t *my_count = (
size_t *)edges;
565 ptrdiff_t *my_stride = (ptrdiff_t *)stride;
568 stat = NC_check_id(ncid, &ncp);
572 if(start == NULL || edges == NULL || stride == NULL) {
573 stat = NC_check_nulls(ncid, varid, start, &my_count, &my_stride);
577 stat = ncp->dispatch->put_varm(ncid, varid, start, my_count, my_stride,
578 map, value, memtype);
579 if(edges == NULL) free(my_count);
580 if(stride == NULL) free(my_stride);
632 const size_t *countp,
const void *op)
635 int stat = NC_check_id(ncid, &ncp);
640 return NC_put_vara(ncid, varid, startp, countp, op, xtype);
645 const size_t *countp,
const char *op)
647 return NC_put_vara(ncid, varid, startp, countp,
653 const size_t *countp,
const signed char *op)
655 return NC_put_vara(ncid, varid, startp, countp, (
void *)op,
661 const size_t *countp,
const unsigned char *op)
663 return NC_put_vara(ncid, varid, startp, countp, (
void *)op,
669 const size_t *countp,
const short *op)
671 return NC_put_vara(ncid, varid, startp, countp, (
void *)op,
677 const size_t *countp,
const int *op)
679 return NC_put_vara(ncid, varid, startp, countp, (
void *)op,
685 const size_t *countp,
const long *op)
687 return NC_put_vara(ncid, varid, startp, countp, (
void *)op,
693 const size_t *countp,
const float *op)
695 return NC_put_vara(ncid, varid, startp, countp, (
void *)op,
701 const size_t *countp,
const double *op)
703 return NC_put_vara(ncid, varid, startp, countp, (
void *)op,
709 const size_t *countp,
const unsigned char *op)
711 return NC_put_vara(ncid, varid, startp, countp, (
void *)op,
717 const size_t *countp,
const unsigned short *op)
719 return NC_put_vara(ncid, varid, startp, countp, (
void *)op,
725 const size_t *countp,
const unsigned int *op)
727 return NC_put_vara(ncid, varid, startp, countp, (
void *)op,
733 const size_t *countp,
const long long *op)
735 return NC_put_vara(ncid, varid, startp, countp, (
void *)op,
741 const size_t *countp,
const unsigned long long *op)
743 return NC_put_vara(ncid, varid, startp, countp, (
void *)op,
749 const size_t *countp,
const char* *op)
751 return NC_put_vara(ncid, varid, startp, countp, (
void *)op,
781 nc_put_var1(
int ncid,
int varid,
const size_t *indexp,
const void *op)
783 return NC_put_var1(ncid, varid, indexp, op,
NC_NAT);
789 return NC_put_var1(ncid, varid, indexp, (
void *)op,
NC_CHAR);
795 return NC_put_var1(ncid, varid, indexp, (
void *)op,
NC_BYTE);
801 return NC_put_var1(ncid, varid, indexp, (
void *)op,
NC_UBYTE);
807 return NC_put_var1(ncid, varid, indexp, (
void *)op,
NC_SHORT);
813 return NC_put_var1(ncid, varid, indexp, (
void *)op,
NC_INT);
819 return NC_put_var1(ncid, varid, indexp, (
void*)op, longtype);
825 return NC_put_var1(ncid, varid, indexp, (
void*)op,
NC_FLOAT);
831 return NC_put_var1(ncid, varid, indexp, (
void *)op,
NC_DOUBLE);
837 return NC_put_var1(ncid, varid, indexp, (
void *)op,
NC_UBYTE);
843 return NC_put_var1(ncid, varid, indexp, (
void *)op,
NC_USHORT);
849 return NC_put_var1(ncid, varid, indexp, (
void *)op,
NC_UINT);
855 return NC_put_var1(ncid, varid, indexp, (
void *)op,
NC_INT64);
861 return NC_put_var1(ncid, varid, indexp, (
void *)op,
NC_UINT64);
867 return NC_put_var1(ncid, varid, indexp, (
void*)op,
NC_STRING);
922 return NC_put_var(ncid, varid, op,
NC_NAT);
928 return NC_put_var(ncid,varid,(
void*)op,
NC_CHAR);
934 return NC_put_var(ncid,varid,(
void*)op,
NC_BYTE);
940 return NC_put_var(ncid,varid,(
void*)op,T_uchar);
946 return NC_put_var(ncid,varid,(
void*)op,
NC_SHORT);
952 return NC_put_var(ncid,varid,(
void*)op,
NC_INT);
958 return NC_put_var(ncid,varid,(
void*)op,T_long);
964 return NC_put_var(ncid,varid,(
void*)op,T_float);
970 return NC_put_var(ncid,varid,(
void*)op,T_double);
976 return NC_put_var(ncid,varid,(
void*)op,T_ubyte);
982 return NC_put_var(ncid,varid,(
void*)op,T_ushort);
988 return NC_put_var(ncid,varid,(
void*)op,T_uint);
994 return NC_put_var(ncid,varid,(
void*)op,T_longlong);
1000 return NC_put_var(ncid,varid,(
void*)op,
NC_UINT64);
1006 return NC_put_var(ncid,varid,(
void*)op,
NC_STRING);
1044 const size_t *countp,
const ptrdiff_t *stridep,
1047 return NC_put_vars(ncid, varid, startp, countp, stridep, op,
NC_NAT);
1052 const size_t *countp,
const ptrdiff_t *stridep,
1055 return NC_put_vars(ncid, varid, startp, countp,
1061 const size_t *countp,
const ptrdiff_t *stridep,
1062 const signed char *op)
1064 return NC_put_vars(ncid, varid, startp, countp,
1070 const size_t *startp,
const size_t *countp,
1071 const ptrdiff_t *stridep,
1072 const unsigned char *op)
1074 return NC_put_vars(ncid, varid, startp, countp,
1075 stridep, (
void *)op, T_uchar);
1080 const size_t *startp,
const size_t *countp,
1081 const ptrdiff_t *stridep,
1084 return NC_put_vars(ncid, varid, startp, countp,
1090 const size_t *startp,
const size_t *countp,
1091 const ptrdiff_t *stridep,
1094 return NC_put_vars(ncid, varid, startp, countp,
1095 stridep, (
void *)op,
NC_INT);
1100 const size_t *startp,
const size_t *countp,
1101 const ptrdiff_t *stridep,
1104 return NC_put_vars(ncid, varid, startp, countp,
1105 stridep, (
void *)op, T_long);
1110 const size_t *startp,
const size_t *countp,
1111 const ptrdiff_t *stridep,
1114 return NC_put_vars(ncid, varid, startp, countp,
1115 stridep, (
void *)op, T_float);
1120 const size_t *startp,
const size_t *countp,
1121 const ptrdiff_t *stridep,
1124 return NC_put_vars(ncid, varid, startp, countp,
1125 stridep, (
void *)op, T_double);
1130 const size_t *startp,
const size_t *countp,
1131 const ptrdiff_t *stridep,
1132 const unsigned char *op)
1134 return NC_put_vars(ncid, varid, startp, countp,
1135 stridep, (
void *)op, T_ubyte);
1140 const size_t *startp,
const size_t *countp,
1141 const ptrdiff_t *stridep,
1142 const unsigned short *op)
1144 return NC_put_vars(ncid, varid, startp, countp,
1145 stridep, (
void *)op, T_ushort);
1150 const size_t *startp,
const size_t *countp,
1151 const ptrdiff_t *stridep,
1152 const unsigned int *op)
1154 return NC_put_vars(ncid, varid, startp, countp,
1155 stridep, (
void *)op, T_uint);
1160 const size_t *startp,
const size_t *countp,
1161 const ptrdiff_t *stridep,
1162 const long long *op)
1164 return NC_put_vars(ncid, varid, startp, countp,
1165 stridep, (
void *)op, T_longlong);
1170 const size_t *startp,
const size_t *countp,
1171 const ptrdiff_t *stridep,
1172 const unsigned long long *op)
1174 return NC_put_vars(ncid, varid, startp, countp,
1180 const size_t *startp,
const size_t *countp,
1181 const ptrdiff_t *stridep,
1184 return NC_put_vars(ncid, varid, startp, countp, stridep,
1236 const size_t *countp,
const ptrdiff_t *stridep,
1237 const ptrdiff_t *imapp,
const void *op)
1239 return NC_put_varm(ncid, varid, startp, countp, stridep, imapp, op,
NC_NAT);
1244 const size_t *countp,
const ptrdiff_t *stridep,
1245 const ptrdiff_t *imapp,
const char *op)
1247 return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1253 const size_t *startp,
const size_t *countp,
1254 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1255 const signed char *op)
1257 return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1263 const size_t *startp,
const size_t *countp,
1264 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1265 const unsigned char *op)
1267 return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1268 (
void *)op, T_uchar);
1273 const size_t *startp,
const size_t *countp,
1274 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1277 return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1283 const size_t *startp,
const size_t *countp,
1284 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1287 return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1293 const size_t *startp,
const size_t *countp,
1294 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1297 return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1298 (
void *)op, T_long);
1303 const size_t *startp,
const size_t *countp,
1304 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1307 return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1308 (
void *)op, T_float);
1313 const size_t *startp,
const size_t *countp,
1314 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1317 return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1318 (
void *)op, T_double);
1323 const size_t *startp,
const size_t *countp,
1324 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1325 const unsigned char *op)
1327 return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1328 (
void *)op, T_ubyte);
1333 const size_t *startp,
const size_t *countp,
1334 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1335 const unsigned short *op)
1337 return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1338 (
void *)op, T_ushort);
1343 const size_t *startp,
const size_t *countp,
1344 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1345 const unsigned int *op)
1347 return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1348 (
void *)op, T_uint);
1353 const size_t *startp,
const size_t *countp,
1354 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1355 const long long *op)
1357 return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1358 (
void *)op, T_longlong);
1363 const size_t *startp,
const size_t *countp,
1364 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1365 const unsigned long long *op)
1367 return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,
1373 const size_t *startp,
const size_t *countp,
1374 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1377 return NC_put_varm(ncid, varid, startp, countp, stridep, imapp,