static int reclaim_compound(int ncid, int xtype, size_t size, size_t nfields, void* memory) { int stat = NC_NOERR; size_t fid, offset, i, fieldsize, arraycount; int dimsizes[NC_MAX_VAR_DIMS]; int ndims; nc_type fieldtype; char* p; /* Get info about each field in turn and reclaim it */ for(fid=0;fid<nfields;fid++) { if((stat = nc_inq_compound_field(ncid,xtype,fid,NULL,&offset, &fieldtype, &ndims, dimsizes))) goto done; if((stat = nc_inq_type(ncid,fieldtype,NULL,&fieldsize))) goto done; if(ndims == 0) {ndims=1; dimsizes[0]=1;} /* fake the scalar case */ /* compute the total number of elements in the field array */ arraycount = 1; for(i=0;i<ndims;i++) arraycount *= dimsizes[i]; for(i=0;i<arraycount;i++) { p = ((char*)memory) + offset + (i*fieldsize); if((stat = reclaim_datar(ncid, fieldtype, p))) goto done; } } done: return stat; }
EXTERNL int ncaux_reclaim_data(int ncid, int xtype, void* memory, size_t count) { int stat = NC_NOERR; size_t typesize = 0; size_t i; Position offset; if(ncid < 0 || xtype < 0 || (memory == NULL && count > 0) || xtype == NC_NAT) {stat = NC_EINVAL; goto done;} if(memory == NULL || count == 0) goto done; /* ok, do nothing */ if((stat=nc_inq_type(ncid,xtype,NULL,&typesize))) goto done; offset.memory = (char*)memory; /* use char* so we can do pointer arithmetic */ offset.offset = 0; for(i=0;i<count;i++) { if((stat=reclaim_datar(ncid,xtype,typesize,&offset))) /* reclaim one instance */ break; } done: return stat; }
static int reclaim_vlen(int ncid, int xtype, int basetype, Position* offset) { int stat = NC_NOERR; size_t i, basesize; nc_vlen_t* vl = (nc_vlen_t*)(offset->memory+offset->offset); /* Get size of the basetype */ if((stat=nc_inq_type(ncid,basetype,NULL,&basesize))) goto done; /* Free up each entry in the vlen list */ if(vl->p != NULL) { Position voffset; unsigned int alignment = ncaux_type_alignment(basetype,ncid); voffset.memory = vl->p; voffset.offset = 0; for(i=0;i<vl->len;i++) { voffset.offset = read_align(voffset.offset,alignment); if((stat = reclaim_datar(ncid,basetype,basesize,&voffset))) goto done; } offset->offset += sizeof(nc_vlen_t); free(vl->p); } done: return stat; }
static int reclaim_vlen(int ncid, int xtype, int basetype, void* memory) { int stat = NC_NOERR; nc_vlen_t* vl = (nc_vlen_t*)memory; size_t i, size; /* Get size of the basetype */ if((stat=nc_inq_type(ncid,basetype,NULL,&size))) goto done; /* Free up each entry in the vlen list */ if(vl->p != NULL) { char* p = vl->p; for(i=0;i<vl->len;i++,p+=size) if((stat = reclaim_datar(ncid,basetype,p))) goto done; free(vl->p); } done: return stat; }
int ncaux_reclaim_data(int ncid, int xtype, const void* memory, size_t count) { int stat = NC_NOERR; size_t typesize = 0; char* p; size_t i; if(ncid < 0 || xtype < 0 || (memory == NULL && count > 0) || xtype == NC_NAT) {stat = NC_EINVAL; goto done;} if(memory == NULL || count == 0) goto done; /* ok, do nothing */ if((stat=nc_inq_type(ncid,xtype,NULL,&typesize))) goto done; p = (char*)memory; /* use char* so we can do pointer arithmetic */ for(i=0;i<count;i++,p+=typesize) { if((stat=reclaim_datar(ncid,xtype,p))) /* reclaim one instance */ break; } done: return stat; }
static int reclaim_compound(int ncid, int xtype, size_t cmpdsize, size_t nfields, Position* offset) { int stat = NC_NOERR; size_t fid, fieldoffset, i, fieldsize, arraycount; int dimsizes[NC_MAX_VAR_DIMS]; int ndims; nc_type fieldtype; ptrdiff_t saveoffset; saveoffset = offset->offset; /* Get info about each field in turn and reclaim it */ for(fid=0;fid<nfields;fid++) { unsigned int fieldalignment; /* Get all relevant info about the field */ if((stat = nc_inq_compound_field(ncid,xtype,fid,NULL,&fieldoffset, &fieldtype, &ndims, dimsizes))) goto done; fieldalignment = ncaux_type_alignment(fieldtype,ncid); if((stat = nc_inq_type(ncid,fieldtype,NULL,&fieldsize))) goto done; if(ndims == 0) {ndims=1; dimsizes[0]=1;} /* fake the scalar case */ /* Align to this field */ offset->offset = read_align(offset->offset,fieldalignment); /* compute the total number of elements in the field array */ arraycount = 1; for(i=0;i<ndims;i++) arraycount *= dimsizes[i]; for(i=0;i<arraycount;i++) { if((stat = reclaim_datar(ncid, fieldtype, fieldsize, offset))) goto done; } } /* Return to beginning of the compound and move |compound| */ offset->offset = saveoffset; offset->offset += cmpdsize; done: return stat; }
static int reclaim_enum(int ncid, int xtype, int basetype, size_t basesize, Position* offset) { /* basically same as an instance of the enum's integer basetype */ return reclaim_datar(ncid,basetype,basesize,offset); }