9 #include "ncdispatch.h"
36 odom_init(
struct GETodometer* odom,
int rank,
const size_t* start,
37 const size_t* edges,
const ptrdiff_t* stride)
40 memset(odom,0,
sizeof(
struct GETodometer));
43 for(i=0;i<odom->rank;i++) {
44 odom->start[i] = (start != NULL ? start[i] : 0);
45 odom->edges[i] = (edges != NULL ? edges[i] : 1);
46 odom->stride[i] = (stride != NULL ? stride[i] : 1);
47 odom->stop[i] = odom->start[i] + (odom->edges[i]*((size_t)odom->stride[i]));
48 odom->index[i] = odom->start[i];
60 odom_more(
struct GETodometer* odom)
62 return (odom->index[0] < odom->stop[0]);
73 odom_next(
struct GETodometer* odom)
76 if(odom->rank == 0)
return 0;
77 for(i=odom->rank-1;i>=0;i--) {
78 odom->index[i] += (size_t)odom->stride[i];
79 if(odom->index[i] < odom->stop[i])
break;
81 odom->index[i] = odom->start[i];
91 NC_get_vara(
int ncid,
int varid,
92 const size_t *start,
const size_t *edges,
96 size_t *my_count = (
size_t *)edges;
97 int stat = NC_check_id(ncid, &ncp);
100 if(start == NULL || edges == NULL) {
101 stat = NC_check_nulls(ncid, varid, start, &my_count, NULL);
104 stat = ncp->dispatch->get_vara(ncid,varid,start,my_count,value,memtype);
105 if(edges == NULL) free(my_count);
136 NC_get_var(
int ncid,
int varid,
void *value,
nc_type memtype)
138 return NC_get_vara(ncid, varid, NC_coord_zero, NULL, value, memtype);
146 NCDEFAULT_get_vars(
int ncid,
int varid,
const size_t * start,
147 const size_t * edges,
const ptrdiff_t * stride,
153 int i,simplestride,isrecvar;
155 struct GETodometer odom;
161 char* value = (
char*)value0;
169 status = NC_check_id (ncid, &ncp);
170 if(status !=
NC_NOERR)
return status;
173 if(status !=
NC_NOERR)
return status;
175 if(memtype ==
NC_NAT) memtype = vartype;
178 status =
nc_inq_type(ncid,vartype,NULL,&vartypelen);
179 if(status !=
NC_NOERR)
return status;
181 if(memtype > NC_MAX_ATOMIC_TYPE)
182 memtypelen = (int)vartypelen;
184 memtypelen = nctypelen(memtype);
187 if(vartype != memtype) {
189 if(vartype > NC_MAX_ATOMIC_TYPE
190 || memtype > NC_MAX_ATOMIC_TYPE)
199 if(status !=
NC_NOERR)
return status;
202 if(rank > 0 && start == NULL)
206 isrecvar = NC_is_recvar(ncid,varid,&numrecs);
207 NC_getshape(ncid,varid,rank,varshape);
216 size_t edge1[1] = {1};
217 return NC_get_vara(ncid, varid, start, edge1, value, memtype);
223 for(i=0;i<rank;i++) {
225 mystart[i] = (start == NULL ? 0 : start[i]);
227 dimlen = (i == 0 && isrecvar ? numrecs : varshape[i]);
232 if(i == 0 && isrecvar)
233 myedges[i] = numrecs - start[i];
235 myedges[i] = varshape[i] - mystart[i];
237 myedges[i] = edges[i];
242 if(mystart[i] + myedges[i] > dimlen)
244 mystride[i] = (stride == NULL ? 1 : stride[i]);
247 || ((
unsigned long) mystride[i] >= X_INT_MAX))
249 if(mystride[i] != 1) simplestride = 0;
256 return NC_get_vara(ncid, varid, mystart, myedges, value, memtype);
262 odom_init(&odom,rank,mystart,myedges,mystride);
265 while(odom_more(&odom)) {
268 localstatus = NC_get_vara(ncid,varid,odom.index,NC_coord_one,memptr,memtype);
274 status = localstatus;
276 memptr += memtypelen;
286 NC_get_var1(
int ncid,
int varid,
const size_t *coord,
void* value,
289 return NC_get_vara(ncid, varid, coord, NC_coord_one, value, memtype);
296 NCDEFAULT_get_varm(
int ncid,
int varid,
const size_t *start,
297 const size_t *edges,
const ptrdiff_t *stride,
298 const ptrdiff_t *imapp,
void *value0,
nc_type memtype)
302 int varndims,maxidim;
305 char* value = (
char*)value0;
307 status = NC_check_id (ncid, &ncp);
308 if(status !=
NC_NOERR)
return status;
315 if(status !=
NC_NOERR)
return status;
317 if(vartype > NC_MAX_ATOMIC_TYPE)
321 if(status !=
NC_NOERR)
return status;
332 memtypelen = nctypelen(memtype);
334 maxidim = (int) varndims - 1;
343 size_t edge1[1] = {1};
344 return NC_get_vara(ncid, varid, start, edge1, value, memtype);
353 size_t *mystart = NULL;
365 isrecvar = NC_is_recvar(ncid,varid,&numrecs);
366 NC_getshape(ncid,varid,varndims,varshape);
373 for (idim = 0; idim <= maxidim; ++idim)
375 if (stride[idim] == 0
377 || ((
unsigned long) stride[idim] >= X_INT_MAX))
381 if(stride[idim] != 1) stride1 = 0;
386 if(stride1 && imapp == NULL) {
387 return NC_get_vara(ncid, varid, start, edges, value, memtype);
393 mystart = (
size_t *)calloc((
size_t)(varndims * 7),
sizeof(ptrdiff_t));
395 myedges = mystart + varndims;
396 iocount = myedges + varndims;
397 stop = iocount + varndims;
398 length = stop + varndims;
399 mystride = (ptrdiff_t *)(length + varndims);
400 mymap = mystride + varndims;
405 for (idim = maxidim; idim >= 0; --idim)
408 idim == 0 && isrecvar
412 mystart[idim] = start != NULL
416 if (mystart[idim] > dimlen)
423 myedges[idim] = edges != NULL
425 : idim == 0 && isrecvar
426 ? numrecs - mystart[idim]
427 : varshape[idim] - mystart[idim];
430 myedges[idim] = edges[idim];
431 else if (idim == 0 && isrecvar)
432 myedges[idim] = numrecs - mystart[idim];
434 myedges[idim] = varshape[idim] - mystart[idim];
437 if (mystart[idim] == dimlen && myedges[idim] > 0)
443 if (mystart[idim] + myedges[idim] > dimlen)
454 for (idim = maxidim; idim >= 0; --idim)
456 if (edges != NULL && edges[idim] == 0)
462 mystride[idim] = stride != NULL
469 mymap[idim] = (imapp != NULL
471 : (idim == maxidim ? 1
472 : mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1]));
475 mymap[idim] = imapp[idim];
476 else if (idim == maxidim)
480 mymap[idim + 1] * (ptrdiff_t) myedges[idim + 1];
483 length[idim] = ((size_t)mymap[idim]) * myedges[idim];
484 stop[idim] = (mystart[idim] + myedges[idim] * (size_t)mystride[idim]);
494 if (mystride[maxidim] == 1
495 && mymap[maxidim] == 1)
497 iocount[maxidim] = myedges[maxidim];
498 mystride[maxidim] = (ptrdiff_t) myedges[maxidim];
499 mymap[maxidim] = (ptrdiff_t) length[maxidim];
508 int lstatus = NC_get_vara(ncid, varid, mystart, iocount,
522 value += (((int)mymap[idim]) * memtypelen);
523 mystart[idim] += (size_t)mystride[idim];
524 if (mystart[idim] == stop[idim])
526 size_t l = (length[idim] * (size_t)memtypelen);
528 mystart[idim] = start[idim];
573 NC_get_vars(
int ncid,
int varid,
const size_t *start,
574 const size_t *edges,
const ptrdiff_t *stride,
void *value,
578 size_t *my_count = (
size_t *)edges;
579 ptrdiff_t *my_stride = (ptrdiff_t *)stride;
582 stat = NC_check_id(ncid, &ncp);
586 if(start == NULL || edges == NULL || stride == NULL) {
587 stat = NC_check_nulls(ncid, varid, start, &my_count, &my_stride);
591 stat = ncp->dispatch->get_vars(ncid,varid,start,my_count,my_stride,
593 if(edges == NULL) free(my_count);
594 if(stride == NULL) free(my_stride);
635 NC_get_varm(
int ncid,
int varid,
const size_t *start,
636 const size_t *edges,
const ptrdiff_t *stride,
const ptrdiff_t* map,
640 size_t *my_count = (
size_t *)edges;
641 ptrdiff_t *my_stride = (ptrdiff_t *)stride;
644 stat = NC_check_id(ncid, &ncp);
648 if(start == NULL || edges == NULL || stride == NULL) {
649 stat = NC_check_nulls(ncid, varid, start, &my_count, &my_stride);
653 stat = ncp->dispatch->get_varm(ncid, varid, start, my_count, my_stride,
654 map, value, memtype);
655 if(edges == NULL) free(my_count);
656 if(stride == NULL) free(my_stride);
742 const size_t *countp,
void *ip)
746 int stat = NC_check_id(ncid, &ncp);
750 return NC_get_vara(ncid, varid, startp, countp, ip, xtype);
755 const size_t *countp,
char *ip)
757 return NC_get_vara(ncid, varid, startp, countp, (
void *)ip,
NC_CHAR);
762 const size_t *countp,
signed char *ip)
764 return NC_get_vara(ncid, varid, startp, countp, (
void *)ip,
NC_BYTE);
769 const size_t *countp,
unsigned char *ip)
771 return NC_get_vara(ncid, varid, startp, countp, (
void *)ip, T_uchar);
776 const size_t *countp,
short *ip)
778 return NC_get_vara(ncid, varid, startp, countp, (
void *)ip,
NC_SHORT);
783 const size_t *startp,
const size_t *countp,
int *ip)
785 return NC_get_vara(ncid,varid,startp,countp, (
void *)ip,
NC_INT);
790 const size_t *startp,
const size_t *countp,
long *ip)
792 return NC_get_vara(ncid,varid,startp,countp, (
void *)ip,T_long);
797 const size_t *startp,
const size_t *countp,
float *ip)
799 return NC_get_vara(ncid,varid,startp,countp, (
void *)ip,T_float);
804 const size_t *countp,
double *ip)
806 return NC_get_vara(ncid,varid,startp,countp, (
void *)ip,T_double);
811 const size_t *startp,
const size_t *countp,
unsigned char *ip)
813 return NC_get_vara(ncid,varid,startp,countp, (
void *)ip,T_ubyte);
818 const size_t *startp,
const size_t *countp,
unsigned short *ip)
820 return NC_get_vara(ncid,varid,startp,countp, (
void *)ip,T_ushort);
825 const size_t *startp,
const size_t *countp,
unsigned int *ip)
827 return NC_get_vara(ncid,varid,startp,countp, (
void *)ip,T_uint);
832 const size_t *startp,
const size_t *countp,
long long *ip)
834 return NC_get_vara(ncid,varid,startp,countp, (
void *)ip,T_longlong);
839 const size_t *countp,
unsigned long long *ip)
841 return NC_get_vara(ncid,varid,startp,countp, (
void *)ip,
NC_UINT64);
846 const size_t *countp,
char* *ip)
848 return NC_get_vara(ncid,varid,startp,countp, (
void *)ip,
NC_STRING);
891 return NC_get_var1(ncid, varid, indexp, ip,
NC_NAT);
897 return NC_get_var1(ncid, varid, indexp, (
void *)ip,
NC_CHAR);
903 return NC_get_var1(ncid, varid, indexp, (
void *)ip,
NC_BYTE);
909 return NC_get_var1(ncid, varid, indexp, (
void *)ip,
NC_UBYTE);
915 return NC_get_var1(ncid, varid, indexp, (
void *)ip,
NC_SHORT);
921 return NC_get_var1(ncid, varid, indexp, (
void *)ip,
NC_INT);
928 return NC_get_var1(ncid, varid, indexp, (
void *)ip, longtype);
935 return NC_get_var1(ncid, varid, indexp, (
void *)ip,
NC_FLOAT);
942 return NC_get_var1(ncid, varid, indexp, (
void *)ip,
NC_DOUBLE);
949 return NC_get_var1(ncid, varid, indexp, (
void *)ip,
NC_UBYTE);
956 return NC_get_var1(ncid, varid, indexp, (
void *)ip,
NC_USHORT);
963 return NC_get_var1(ncid, varid, indexp, (
void *)ip,
NC_UINT);
970 return NC_get_var1(ncid, varid, indexp, (
void *)ip,
NC_INT64);
975 unsigned long long *ip)
977 return NC_get_var1(ncid, varid, indexp, (
void *)ip,
NC_UINT64);
983 return NC_get_var1(ncid, varid, indexp, (
void *)ip,
NC_STRING);
1035 return NC_get_var(ncid, varid, ip,
NC_NAT);
1041 return NC_get_var(ncid, varid, (
void *)ip,
NC_CHAR);
1047 return NC_get_var(ncid, varid, (
void *)ip,
NC_BYTE);
1053 return NC_get_var(ncid,varid, (
void *)ip,
NC_UBYTE);
1059 return NC_get_var(ncid, varid, (
void *)ip,
NC_SHORT);
1065 return NC_get_var(ncid,varid, (
void *)ip,
NC_INT);
1071 return NC_get_var(ncid,varid, (
void *)ip, longtype);
1077 return NC_get_var(ncid,varid, (
void *)ip,
NC_FLOAT);
1083 return NC_get_var(ncid,varid, (
void *)ip,
NC_DOUBLE);
1089 return NC_get_var(ncid,varid, (
void *)ip,
NC_UBYTE);
1095 return NC_get_var(ncid,varid, (
void *)ip,
NC_USHORT);
1101 return NC_get_var(ncid,varid, (
void *)ip,
NC_UINT);
1107 return NC_get_var(ncid,varid, (
void *)ip,
NC_INT64);
1113 return NC_get_var(ncid,varid, (
void *)ip,
NC_UINT64);
1119 return NC_get_var(ncid,varid, (
void *)ip,
NC_STRING);
1166 const size_t * countp,
const ptrdiff_t * stridep,
1169 return NC_get_vars(ncid, varid, startp, countp, stridep,
1175 const size_t *countp,
const ptrdiff_t * stridep,
1178 return NC_get_vars(ncid,varid,startp, countp, stridep,
1184 const size_t *countp,
const ptrdiff_t * stridep,
1187 return NC_get_vars(ncid,varid,startp, countp, stridep,
1193 const size_t *countp,
const ptrdiff_t * stridep,
1196 return NC_get_vars(ncid,varid,startp, countp, stridep,
1197 (
void *)ip, T_uchar);
1202 const size_t *countp,
const ptrdiff_t *stridep,
1205 return NC_get_vars(ncid,varid,startp, countp, stridep,
1211 const size_t *countp,
const ptrdiff_t * stridep,
1214 return NC_get_vars(ncid,varid,startp, countp, stridep,
1220 const size_t *countp,
const ptrdiff_t * stridep,
1223 return NC_get_vars(ncid,varid,startp, countp, stridep,
1224 (
void *)ip, T_long);
1229 const size_t *countp,
const ptrdiff_t * stridep,
1232 return NC_get_vars(ncid,varid,startp, countp, stridep,
1233 (
void *)ip, T_float);
1238 const size_t *countp,
const ptrdiff_t * stridep,
1241 return NC_get_vars(ncid,varid,startp, countp, stridep,
1242 (
void *)ip, T_double);
1247 const size_t *countp,
const ptrdiff_t * stridep,
1250 return NC_get_vars(ncid,varid, startp, countp, stridep,
1251 (
void *)ip, T_ubyte);
1256 const size_t *countp,
const ptrdiff_t * stridep,
1259 return NC_get_vars(ncid,varid,startp,countp, stridep,
1260 (
void *)ip, T_ushort);
1265 const size_t *countp,
const ptrdiff_t * stridep,
1268 return NC_get_vars(ncid,varid,startp, countp, stridep,
1269 (
void *)ip, T_uint);
1274 const size_t *countp,
const ptrdiff_t * stridep,
1277 return NC_get_vars(ncid, varid, startp, countp, stridep,
1278 (
void *)ip, T_longlong);
1283 const size_t *countp,
const ptrdiff_t * stridep,
1284 unsigned long long *ip)
1286 return NC_get_vars(ncid, varid, startp, countp, stridep,
1292 const size_t *startp,
const size_t *countp,
1293 const ptrdiff_t * stridep,
1296 return NC_get_vars(ncid, varid, startp, countp, stridep,
1360 const size_t * countp,
const ptrdiff_t * stridep,
1361 const ptrdiff_t * imapp,
void *ip)
1363 return NC_get_varm(ncid, varid, startp, countp, stridep, imapp, ip,
NC_NAT);
1368 const size_t *startp,
const size_t *countp,
1369 const ptrdiff_t *stridep,
1370 const ptrdiff_t *imapp,
signed char *ip)
1372 return NC_get_varm(ncid, varid, startp, countp,
1373 stridep, imapp, (
void *)ip,
NC_BYTE);
1378 const size_t *startp,
const size_t *countp,
1379 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1382 return NC_get_varm(ncid,varid,startp,countp,stridep,imapp, (
void *)ip,T_uchar);
1387 const size_t *countp,
const ptrdiff_t *stridep,
1388 const ptrdiff_t *imapp,
short *ip)
1390 return NC_get_varm(ncid,varid,startp,countp,stridep,imapp, (
void *)ip,
NC_SHORT);
1395 const size_t *startp,
const size_t *countp,
1396 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1399 return NC_get_varm(ncid,varid,startp,countp,stridep,imapp, (
void *)ip,
NC_INT);
1404 const size_t *startp,
const size_t *countp,
1405 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1408 return NC_get_varm(ncid,varid,startp,countp,stridep,imapp, (
void *)ip,T_long);
1413 const size_t *startp,
const size_t *countp,
1414 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1417 return NC_get_varm(ncid,varid,startp,countp,stridep,imapp, (
void *)ip,T_float);
1422 const size_t *startp,
const size_t *countp,
1423 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1426 return NC_get_varm(ncid,varid,startp,countp,stridep,imapp, (
void *)ip,T_double);
1431 const size_t *startp,
const size_t *countp,
1432 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1435 return NC_get_varm(ncid,varid,startp,countp,stridep,
1436 imapp, (
void *)ip, T_ubyte);
1441 const size_t *startp,
const size_t *countp,
1442 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1445 return NC_get_varm(ncid, varid, startp, countp, stridep,
1446 imapp, (
void *)ip, T_ushort);
1451 const size_t *startp,
const size_t *countp,
1452 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1455 return NC_get_varm(ncid, varid, startp, countp,
1456 stridep, imapp, (
void *)ip, T_uint);
1461 const size_t *countp,
const ptrdiff_t *stridep,
1462 const ptrdiff_t *imapp,
long long *ip)
1464 return NC_get_varm(ncid, varid, startp, countp, stridep, imapp,
1465 (
void *)ip, T_longlong);
1470 const size_t *startp,
const size_t *countp,
1471 const ptrdiff_t *stridep,
const ptrdiff_t *imapp,
1472 unsigned long long *ip)
1474 return NC_get_varm(ncid, varid, startp, countp, stridep, imapp,
1480 const size_t *countp,
const ptrdiff_t *stridep,
1481 const ptrdiff_t *imapp,
char *ip)
1483 return NC_get_varm(ncid, varid, startp, countp, stridep, imapp,
1489 const size_t *countp,
const ptrdiff_t *stridep,
1490 const ptrdiff_t *imapp,
char **ip)
1492 return NC_get_varm(ncid, varid, startp, countp, stridep, imapp,