Fix github issues #140

1. Added check to libsrc4/nc4var.nc_def_var_extra to
   check that the no specified chunks size is greater than
   the dimension size.

2. Added test to nc_test4/tst_chunks.c
This commit is contained in:
dmh 2015-11-07 20:29:16 -07:00
parent 996ef87cd1
commit 5ad26bb68f
2 changed files with 42 additions and 0 deletions

View File

@ -931,6 +931,10 @@ nc_def_var_extra(int ncid, int varid, int *shuffle, int *deflate,
if ((retval = check_chunksizes(grp, var, chunksizes)))
return retval;
for (d = 0; d < var->ndims; d++) {
if(var->dim[d]->len > 0 && chunksizes[d] > var->dim[d]->len)
return NC_EBADCHUNK;
}
/* Set the chunksizes for this variable. */
for (d = 0; d < var->ndims; d++)

View File

@ -253,6 +253,44 @@ main(int argc, char **argv)
if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("**** testing that too large chunksizes fail...");
{
#define D_SMALL_LEN2 66
int stat = NC_NOERR;
int ncid;
int nvars, ndims, ngatts, unlimdimid;
int contig;
int ndims_in, natts_in, dimids_in;
int small_dimid, medium_dimid, large_dimid;
int small_varid;
char var_name_in[NC_MAX_NAME + 1];
size_t chunks[1], chunksize_in;
nc_type xtype_in;
/* Create a netcdf-4 file with three dimensions. */
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
if (nc_def_dim(ncid, D_SMALL, D_SMALL_LEN2, &small_dimid)) ERR;
/* Add one var. */
if (nc_def_var(ncid, V_SMALL, NC_INT64, NDIMS1, &small_dimid, &small_varid)) ERR;
/* Attempt to set too large chunksizes */
chunks[0] = D_SMALL_LEN2 + 1;
stat = nc_def_var_chunking(ncid, small_varid, NC_CHUNKED, chunks);
if(stat != NC_EBADCHUNK) {
printf("Return code is '%s', expected NC_BADCHUNK",nc_strerror(stat));
ERR;
}
/* try agains with proper chunksize */
chunks[0] = D_SMALL_LEN2;
stat = nc_def_var_chunking(ncid, small_varid, NC_CHUNKED, chunks);
if(stat != NC_NOERR) {
printf("Return code is '%s', expected NC_NOERR",nc_strerror(stat));
ERR;
}
if (nc_abort(ncid)) ERR;
}
SUMMARIZE_ERR;
FINAL_RESULTS;
}