Skip to content

Commit

Permalink
merged 760
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Jan 20, 2018
2 parents ef65bdf + 978e83d commit c329298
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
6 changes: 3 additions & 3 deletions libsrc4/nc4var.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,10 +973,8 @@ nc_def_var_extra(int ncid, int varid, int *shuffle, int *deflate,
NC_GRP_INFO_T *grp;
NC_HDF5_FILE_INFO_T *h5;
NC_VAR_INFO_T *var;
NC_DIM_INFO_T *dim;
int d;
int retval;
nc_bool_t ishdf4 = NC_FALSE; /* Use this to avoid so many ifdefs */

/* All or none of these will be provided. */
assert((deflate && deflate_level && shuffle) ||
Expand Down Expand Up @@ -1075,8 +1073,10 @@ nc_def_var_extra(int ncid, int varid, int *shuffle, int *deflate,

if ((retval = check_chunksizes(grp, var, chunksizes)))
return retval;

/* Ensure chunksize is smaller than dimension size */
for (d = 0; d < var->ndims; d++)
if (var->dim[d]->len > 0 && chunksizes[d] > var->dim[d]->len)
if(!var->dim[d]->unlimited && var->dim[d]->len > 0 && chunksizes[d] > var->dim[d]->len)
return NC_EBADCHUNK;

/* Set the chunksizes for this variable. */
Expand Down
41 changes: 41 additions & 0 deletions nc_test4/tst_chunks.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,46 @@ main(int argc, char **argv)
if (nc_abort(ncid)) ERR;
}
SUMMARIZE_ERR;
printf("**** testing different chunksizes on an unlimited dimension with existing data...");
{
#define D_UNLIM "unlimited_dim"
#define V_UNLIM_ONE "unlimited_var_one"
#define V_UNLIM_TWO "unlimited_var_two"
int ncid;
int unlim_dimid;
int first_unlim_varid;
int second_unlim_varid;
size_t first_chunks[1];
size_t second_chunks[1];
size_t start[1], count[1];
unsigned short first_data[2] = {0, 1}, second_data[3] = {2, 3, 4};

/* Create a netcdf4 file with 1 dimension. */
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
if (nc_def_dim(ncid, D_UNLIM, NC_UNLIMITED, &unlim_dimid)) ERR;

/* Add one var with one chunksize */
if (nc_def_var(ncid, V_UNLIM_ONE, NC_USHORT, NDIMS1, &unlim_dimid, &first_unlim_varid)) ERR;
first_chunks[0] = 2;
if (nc_def_var_chunking(ncid, first_unlim_varid, NC_CHUNKED, first_chunks)) ERR;

/* Add a record to the first variable. */
start[0] = 0;
count[0] = 1;
if (nc_put_vara(ncid, first_unlim_varid, start, count, first_data)) ERR;

/* Add second var with second chunksize */
if (nc_def_var(ncid, V_UNLIM_TWO, NC_USHORT, NDIMS1, &unlim_dimid, &second_unlim_varid)) ERR;
second_chunks[0] = 3;
if (nc_def_var_chunking(ncid, second_unlim_varid, NC_CHUNKED, second_chunks)) ERR;

/* Add a record to the second variable. */
start[0] = 0;
count[0] = 2;
if (nc_put_vara(ncid, second_unlim_varid, start, count, second_data)) ERR;

if (nc_close(ncid)) ERR;
}
SUMMARIZE_ERR;
FINAL_RESULTS;
}

0 comments on commit c329298

Please sign in to comment.