17c17 < /* $Id: putget.c 5196 2009-06-03 05:05:36Z bmribler $ */ --- > /* $Id: putget.c 5955 2013-07-06 15:47:58Z bmribler $ */ 56,60d55 < /* #define VDEBUG < #define DEBUG < #define CDEBUG < */ < 146,150c141,144 < boundary = NULL; /* no boundary check is needed */ < if( IS_RECVAR(vp) ) < { < /* For the variable with unlimited dimension we only need to check < that the size of the first dimension is non-negative, there is no --- > if( IS_RECVAR(vp) ) > { > /* For the variable with unlimited dimension we need to check that > the size of the first dimension is non-negative, there is no 154a149,156 > boundary = coords + 1 ; > if(*coords < 0) > goto bad ; > } else > boundary = coords ; > > up = vp->shape + vp->assoc->count - 1 ; > ip = coords + vp->assoc->count - 1 ; 156,183c158,170 < /* Check that first dimension is non-negative */ < if(*coords < 0) < goto bad ; < < /* Set up boundary to check the rest of the dims if there are more than one dim */ < if (vp->assoc->count > 1) < boundary = coords + 1 ; < } < else < boundary = coords ; /* no unlimited, boundary starts at first dim */ < < if (boundary != NULL) /* no unlimited dim or unlimited dim and more than one dim */ < { < up = vp->shape + vp->assoc->count - 1 ; /* pointer for dimension sizes */ < ip = coords + vp->assoc->count - 1 ; /* pointer for start coords */ < < /* for each dimension, check if starting coord is within dim size */ < for( ; ip >= boundary ; ip--, up--) < { < if( *ip < 0 || *ip >= (long)*up ) < goto bad ; < } < } /* more than one dim */ < < /* Reset ip to coords because, after for loop, ip points to an undefined location < before boundary */ < /* ip = coords; < */ --- > #ifdef CDEBUG > fprintf(stderr," NCcoordck: coords %p, *coords %ld, count %ld, ip %p, boundary %p, *ip %ld\n", > coords, *coords, vp->assoc->count, ip , boundary, *ip) ; > #endif /* CDEBUG */ > for( ; ip >= boundary ; ip--, up--) > { > #ifdef CDEBUG > fprintf(stderr," NCcoordck: ip %p, *ip %ld, up %p, *up %lu\n", > ip, *ip, up, *up ) ; > #endif /* CDEBUG */ > if( *ip < 0 || *ip >= (long)*up ) > goto bad ; > } 201c188 < vp's numrecs is 5, and the accessed index is 8 (*coords), then recs --- > vp's numrecs is 5, and the accessed index is 8 (*ip), then recs 206c193 < if((unfilled = *coords - vp->numrecs) < 0) --- > if((unfilled = *ip - vp->numrecs) < 0) 225c212 < if (*coords >= handle->numrecs) --- > if (*ip >= handle->numrecs) 255c242 < fprintf(stderr, "Going to fill in record %d for variable %s\n", *coords, --- > fprintf(stderr, "Going to fill in record %d for variable %s\n", *ip, 292c279 < count, *coords * count, vp->numrecs); --- > count, *ip * count, vp->numrecs); 298c285 < vp->numrecs = MAX(vp->numrecs, (*coords + 1)); /* if NOFILL */ --- > vp->numrecs = MAX(vp->numrecs, (*ip + 1)); /* if NOFILL */ 302c289 < if((*coords + 1) > (long)(handle->numrecs)) --- > if((*ip + 1) > (long)(handle->numrecs)) 304c291 < handle->numrecs = *coords + 1; --- > handle->numrecs = *ip + 1; 316c303 < if( IS_RECVAR(vp) && (unfilled = *coords - handle->numrecs) >= 0 ) --- > if( IS_RECVAR(vp) && (unfilled = *ip - handle->numrecs) >= 0 ) 327c314 < handle->numrecs = *coords + 1 ; --- > handle->numrecs = *ip + 1 ; 1837c1824 < arrayp("3 coords", vp->assoc->count, coords) ; --- > arrayp("coords", vp->assoc->count, coords) ; 1905,2004d1891 < static bool_t < myxdr_NCvdata(xdrs, where, type, count, values) < XDR *xdrs ; < u_long where ; < nc_type type ; < unsigned count ; < Void *values ; < { < u_long rem = 0 ; < bool_t (*xdr_NC_fnct)() ; < bool_t stat ; < size_t szof ; < < switch(type){ < case NC_BYTE : < case NC_CHAR : < case NC_SHORT : < rem = where%4 ; < where -= rem ; /* round down to nearest word */ < break ; < default: < break; < } < if( !xdr_NCsetpos(xdrs, where) ) < return(FALSE) ; < < switch(type){ < case NC_BYTE : < case NC_CHAR : < if(rem != 0) < { < unsigned vcount = MIN(count, 4 - rem) ; < if(!xdr_NCvbyte(xdrs, (unsigned)rem, vcount, values) ) < return(FALSE) ; < values += vcount ; < count -= vcount ; < } < < rem = count%4 ; /* tail remainder */ < count -= rem ; < if(!xdr_opaque(xdrs, values, count)) < return(FALSE) ; < < if(rem != 0) < { < values += count ; < if( !xdr_NCvbyte(xdrs, (unsigned)0, (unsigned)rem , < values) ) < return(FALSE) ; < return(TRUE) ; < } /* else */ < return(TRUE) ; < case NC_SHORT : < if(rem != 0) < { < if(!xdr_NCvshort(xdrs, (unsigned)1, (short *)values) ) < return(FALSE) ; < values += sizeof(short) ; < count -= 1 ; < } < rem = count%2 ; /* tail remainder */ < count -= rem ; < if(!xdr_shorts(xdrs, (short *)values, count)) < return(FALSE) ; < if(rem != 0) < { < values += (count * sizeof(short)) ; < return( xdr_NCvshort(xdrs, (unsigned)0, < (short *)values) ) ; < } /* else */ < return(TRUE) ; < case NC_LONG : < #if defined _CRAYMPP < xdr_NC_fnct = xdr_short; < #elif defined __alpha || (_MIPS_SZLONG == 64) || defined __ia64 || (defined __sun && defined _LP64) || defined AIX5L64 || defined __x86_64__ || defined __powerpc64__ < xdr_NC_fnct = xdr_int ; < #else < xdr_NC_fnct = xdr_long ; < #endif < szof = sizeof(nclong) ; < break ; < case NC_FLOAT : < xdr_NC_fnct = xdr_float ; < szof = sizeof(float) ; < break ; < case NC_DOUBLE : < xdr_NC_fnct = xdr_double ; < szof = sizeof(double) ; < break ; < default : < return(FALSE) ; < } < for(stat = TRUE ; stat && (count > 0) ; count--) < { < stat = (*xdr_NC_fnct)(xdrs,values) ; < values += szof ; < } < return(stat) ; < } < 2021d1907 < fprintf(stderr, "in xdr_NCvdata...\n"); 2136,2137d2021 < /* boundary point to first dimension in vp->shape */ < 2139,2140c2023,2024 < shp = vp->shape + vp->assoc->count - 1 ; /* points to last dimension */ < edp = edges + vp->assoc->count - 1 ; /* points to last edge */ --- > shp = vp->shape + vp->assoc->count - 1 ; > edp = edges + vp->assoc->count - 1 ; 2142,2144d2025 < < /* Traverse shp back to the begining of boundary while checking that < each edge is within limit between start coord and max of dimension */ 2152,2160c2033,2037 < /* Mark that the writing is partial when any edge is smaller than the < matching dimension */ < if(*edp < *shp ) < { < partial=1; < break ; < /* Why do we want to break here? What if the later edge is out < of limit and we break out as soon as a smaller edge is reached? -BMR */ < } --- > if(*edp < *shp ) > { > partial=1; > break ; > } 2162,2164d2038 < /* When all dimensions have been checked and shp has passed the first element < in boundary and into undefined location, so did edp in edges, move edp < forward once to point to the first element in edges. -BMR, 4/15/2013 */ 2207a2082 > /* After fixing HDFFR-1385, need to reassess this issue. -BMR */ 2261c2136,2137 < exceeds the latter (part of bugzilla 1378) - BMR, 12/30/2008 */ --- > exceeds the latter (part of bugzilla 1378, i.e., JIRA HDFFR-167) > - BMR, 12/30/2008 */ 2375c2251 < arrayp("4 coords", vp->assoc->count, coords) ; --- > arrayp("coords", vp->assoc->count, coords) ; 2480c2356 < arrayp("5 coords", vp->assoc->count, coords) ; --- > arrayp("coords", vp->assoc->count, coords) ; 2496a2373 > * Perhaps it is only true for netCDF files. -BMR (2013-06-24) 2497a2375 > /* HDFFR-1385: the fix for this bug may fix this problem too.-BMR */ 2509,2706d2386 < int myNCvario(handle, varid, start, edges, values, sds_data) < NC *handle ; < int varid ; < const long *start ; < const long *edges ; < void *values ; < void *sds_data ; < { < < NC_var *vp ; < const long *edp0, /* pointer to first element of edges? */ < *edp , /* edges pointer? */ < *edge_p ; /* edges pointer? */ < unsigned long iocount ; < void *sds_datap; < < if(handle->flags & NC_INDEF) < return(-1) ; < < /* find the variable */ < if(handle->vars == NULL) < return(-1) ; < vp = NC_hlookupvar( handle, varid ) ; < if(vp == NULL) < return(-1) ; < < #ifdef VDEBUG < fprintf(stderr, "Entering myNCvario, variable %s\n", vp->name->values ) ; < arrayp("start", vp->assoc->count, start) ; < arrayp("edges", vp->assoc->count, edges) ; < #endif /* VDEBUG */ < < #ifdef HDF < if(handle->file_type != netCDF_FILE) < { < if (FAIL == DFKsetNT(vp->HDFtype)) < return -1; < } < #endif < < if( !NCcoordck(handle, vp, start) ) < return(-1) ; < < if( IS_RECVAR(vp) < && vp->assoc->count == 1 < && handle->recsize <= vp->len) < { < /* one dimensional && the only 'record' variable */ < return(NCsimplerecio(handle, vp, start, edges, values)) ; < } < < /* find max contiguous, check sanity of edges */ < edp0 = NCvcmaxcontig(handle, vp, start, edges) ; < if(edp0 == NULL) < return(-1) ; < #ifdef VDEBUG < fprintf(stderr, "edp0\t%ld\n", (unsigned long)edp0 - (unsigned long)edges) ; < #endif /* VDEBUG */ < < /* now accumulate max count for a single io operation */ < edp = edges + vp->assoc->count - 1 ; /* count is > 0 at this point */ < iocount = 1 ; < for( ; edp >= edp0 ; edp--) < iocount *= *edp ; < /* now edp = edp0 - 1 */ < < { /* inline */ < long fst_coords[H4_MAX_VAR_DIMS], last_coords[H4_MAX_VAR_DIMS]; < /* fst_coords was coords, last_coords was upper */ < long *fst_p ; /* was cc -BMR */ < long *last_p ; /* was cc, re-used cc -BMR */ < const long *startp ; /* was mm -BMR */ < u_long offset ; < size_t szof = nctypelen(vp->type) ; < < /* Copy starting indices from "start" to "fst_coords", using pointers fst_p and startp */ < fst_p = fst_coords ; < startp = start ; < < /* repeat until fst_p gets to fst_coords[number of dimensions] */ < while(fst_p < &fst_coords[vp->assoc->count] ) < { < *fst_p = *startp ; < fst_p++; < startp++; < } < < /* Now, coords has what start has */ < #ifdef VDEBUG < arrayp("1 fst_coords", vp->assoc->count, fst_coords) ; < #endif < < /* Set up maximum indices in "last_coords", i.e., the array describing the location of the */ < /* last item in the slab */ < < /* Pointer last_p points to the array that will describe the location of < the last item in the slab */ < last_p = last_coords ; < fst_p = fst_coords ; < edp = edges ; < while(last_p < &last_coords[vp->assoc->count] ) < *last_p++ = *fst_p++ + *edp++ ; < #ifdef VDEBUG < arrayp("last_coords", vp->assoc->count, last_coords) ; < #endif < < /* ripple counter */ < fst_p = fst_coords ; < last_p = last_coords ; < while(*fst_coords < *last_coords) < { < #ifdef VDEBUG < fprintf(stderr, "Begin of loop\n"); < fprintf(stderr, "\t*last_p %ld, *fst_p %ld\n", < *last_p, *fst_p) ; < #endif /* VDEBUG */ < while( *fst_p < *last_p ) < { < #ifdef VDEBUG < fprintf(stderr, "\t\tedp0 %p, edges %p, fst_p %p, &last_coords[] %p\n", < edp0, edges, fst_p, &last_coords[edp0-edges-1]) ; < #endif /* VDEBUG */ < if(edp0 == edges || last_p == &last_coords[edp0-edges-1]) < { < void *valuesp = values; < /* doit */ < if( !NCcoordck(handle, vp, fst_coords) ) < return(-1) ; < < /* Compute the offset */ < offset = NC_varoffset(handle, vp, fst_coords) ; < #ifdef VDEBUG < fprintf(stderr, "\t\t %s offset %lu, iocount %lu\n", < vp->name->values, offset, iocount ) ; < arrayp("\t\t 6 fst_coords", vp->assoc->count, fst_coords) ; < #endif < /* Advance SDS' data buffer by "offset" */ < sds_datap = sds_data + offset; < < /* Made an attempt to use a switch statement to assign values for < different types, but it was too complicated. Will see if HDmemcpy < will work for all platforms -BMR, 2013/4/17 */ < /* Copy "iocount" values from user's buffer onto SDS' buffer */ < HDmemcpy(sds_datap, valuesp, iocount * szof); < < /* Advancing user's data buffer */ < values = (void *)((const uint8 *)values + iocount * szof); < (*fst_p) += (edp0 == edges ? iocount : 1) ; < < #ifdef VDEBUG < fprintf(stderr, "\t\t *last_p %ld, *fst_p %ld continue\n", < *last_p, *fst_p) ; < #endif /* VDEBUG */ < continue ; < } < fst_p++ ; < last_p++ ; < #ifdef VDEBUG < fprintf(stderr, "\t\t*last_p %ld, *fst_p %ld\n", < *last_p, *fst_p) ; < #endif /* VDEBUG */ < } < #ifdef VDEBUG < fprintf(stderr, "\tlast_p %p, fst_coords %p\n", < last_p, fst_coords) ; < #endif /* VDEBUG */ < if(fst_p == fst_coords) < { < #ifdef VDEBUG < fprintf(stderr, "\t break\n") ; < #endif /* VDEBUG */ < break ; < } < *fst_p = start[ fst_p - fst_coords ] ; < fst_p-- ; < last_p-- ; < (*fst_p)++ ; < #ifdef VDEBUG < fprintf(stderr, "\t*fst_coords %ld, *last_coords %ld\n", < *fst_coords, *last_coords) ; < fprintf(stderr, "End of loop\n"); < #endif < } < #ifdef VDEBUG < arrayp("2 fst_coords", vp->assoc->count, fst_coords) ; < arrayp("last_coords", vp->assoc->count, last_coords) ; < fprintf(stderr,"vp->numrecs=%d\n",vp->numrecs); < fprintf(stderr,"last_coords[0]=%d\n",last_coords[0]); < #endif < } /* end inline */ < < #ifdef VDEBUG < fprintf(stderr, "Exiting myNCvario\n") ; < #endif /* VDEBUG */ < return(0) ; < } < <