Fix ncdump bug identifying coordinate variables in groups. Fix bug in libsrc/posixio.c when providing sizehint larger than default, which then doesn't get used (reported by Harald nlauf).

This commit is contained in:
Russ Rew 2010-07-08 17:17:33 +00:00
commit d62c16ad73
2 changed files with 45 additions and 8 deletions

View File

@ -1422,7 +1422,9 @@ ncio_new(const char *path, int ioflags)
#ifndef NCIO_MINBLOCKSIZE
#define NCIO_MINBLOCKSIZE 256
#endif
#ifndef NCIO_MAXBLOCKSIZE
#define NCIO_MAXBLOCKSIZE 268435456 /* sanity check, about X_SIZE_T_MAX/8 */
#endif
#ifdef S_IRUSR
#define NC_DEFAULT_CREAT_MODE \
@ -1494,11 +1496,16 @@ ncio_create(const char *path, int ioflags,
}
*((int *)&nciop->fd) = fd; /* cast away const */
if(*sizehintp < NCIO_MINBLOCKSIZE || *sizehintp > NCIO_MAXBLOCKSIZE)
if(*sizehintp < NCIO_MINBLOCKSIZE)
{
/* Use default */
*sizehintp = blksize(fd);
}
else if(*sizehintp >= NCIO_MAXBLOCKSIZE)
{
/* Use maximum allowed value */
*sizehintp = NCIO_MAXBLOCKSIZE;
}
else
{
*sizehintp = M_RNDUP(*sizehintp);
@ -1618,11 +1625,16 @@ ncio_open(const char *path,
}
*((int *)&nciop->fd) = fd; /* cast away const */
if(*sizehintp < NCIO_MINBLOCKSIZE || *sizehintp > NCIO_MAXBLOCKSIZE)
if(*sizehintp < NCIO_MINBLOCKSIZE)
{
/* Use default */
*sizehintp = blksize(fd);
}
else if(*sizehintp >= NCIO_MAXBLOCKSIZE)
{
/* Use maximum allowed value */
*sizehintp = NCIO_MAXBLOCKSIZE;
}
else
{
*sizehintp = M_RNDUP(*sizehintp);

View File

@ -1777,17 +1777,39 @@ init_types(int ncid) {
int
iscoordvar(int ncid, int varid)
{
int ndims;
int ndims, ndims1;
int dimid;
ncdim_t *dims;
int* dimids = 0;
ncdim_t *dims = 0;
int include_parents = 1;
int is_coord = 0; /* true if variable is a coordinate variable */
char varname[NC_MAX_NAME];
int varndims;
NC_CHECK( nc_inq_ndims(ncid, &ndims) );
dims = (ncdim_t *) emalloc((ndims + 1) * sizeof(ncdim_t));
do { /* be safe in case someone is currently adding
* dimensions */
NC_CHECK( nc_inq_ndims(ncid, &ndims) );
if (dims)
free(dims);
dims = (ncdim_t *) emalloc((ndims + 1) * sizeof(ncdim_t));
if (dimids)
free(dimids);
dimids = (int *) emalloc((ndims + 1) * sizeof(int));
#ifdef USE_NETCDF4
NC_CHECK( nc_inq_dimids(ncid, &ndims1, dimids, include_parents ) );
#else
{
int i;
for(i = 0; i < ndims; i++) {
dimids[i] = i; /* for netCDF-3, dimids are 0, 1, ..., ndims-1 */
}
NC_CHECK( nc_inq_ndims(ncid, &ndims1) );
}
#endif /* USE_NETCDF4 */
} while (ndims != ndims1);
for (dimid = 0; dimid < ndims; dimid++) {
NC_CHECK( nc_inq_dimname(ncid, dimid, dims[dimid].name) );
NC_CHECK( nc_inq_dimname(ncid, dimids[dimid], dims[dimid].name) );
}
NC_CHECK( nc_inq_varname(ncid, varid, varname) );
NC_CHECK( nc_inq_varndims(ncid, varid, &varndims) );
@ -1798,7 +1820,10 @@ iscoordvar(int ncid, int varid)
break;
}
}
free(dims);
if(dims)
free(dims);
if(dimids)
free(dimids);
return is_coord;
}