fixed problem with scalar compact

This commit is contained in:
Edward Hartnett 2020-02-26 09:13:12 -07:00
parent 52e3b4659f
commit 418e428a05
2 changed files with 67 additions and 67 deletions

View File

@ -1004,23 +1004,6 @@ var_create_dataset(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, nc_bool_t write_dimid
}
}
/* Set the var storage to contiguous, compact, or chunked. */
if (var->contiguous)
{
if (H5Pset_layout(plistid, H5D_CONTIGUOUS) < 0)
BAIL(NC_EHDFERR);
}
else if (var->compact)
{
if (H5Pset_layout(plistid, H5D_COMPACT) < 0)
BAIL(NC_EHDFERR);
}
else
{
if (H5Pset_chunk(plistid, var->ndims, chunksize) < 0)
BAIL(NC_EHDFERR);
}
/* Create the dataspace. */
if ((spaceid = H5Screate_simple(var->ndims, dimsize, maxdimsize)) < 0)
BAIL(NC_EHDFERR);
@ -1031,6 +1014,25 @@ var_create_dataset(NC_GRP_INFO_T *grp, NC_VAR_INFO_T *var, nc_bool_t write_dimid
BAIL(NC_EHDFERR);
}
/* Set the var storage to contiguous, compact, or chunked. Don't
* try to set chunking for scalar vars, they will default to
* contiguous if not set to compact. */
if (var->contiguous)
{
if (H5Pset_layout(plistid, H5D_CONTIGUOUS) < 0)
BAIL(NC_EHDFERR);
}
else if (var->compact)
{
if (H5Pset_layout(plistid, H5D_COMPACT) < 0)
BAIL(NC_EHDFERR);
}
else if (var->ndims)
{
if (H5Pset_chunk(plistid, var->ndims, chunksize) < 0)
BAIL(NC_EHDFERR);
}
/* Turn on creation order tracking. */
if (H5Pset_attr_creation_order(plistid, H5P_CRT_ORDER_TRACKED|
H5P_CRT_ORDER_INDEXED) < 0)

View File

@ -234,7 +234,6 @@ main(int argc, char **argv)
int data = TEST_VAL_42;
/* Create a file with one var which is compact scalar. */
nc_set_log_level(3);
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR;
/* Define a scalar. Scalars can also be compact. */
@ -255,67 +254,66 @@ main(int argc, char **argv)
if (nc_inq(ncid, &ndims, &nvars, NULL, NULL)) ERR;
if (ndims != 0 || nvars != 1) ERR;
if (nc_inq_var_chunking(ncid, 0, &storage_in, NULL)) ERR;
/* if (storage_in != NC_COMPACT) ERR; */
if (storage_in != NC_COMPACT) ERR;
if (nc_close(ncid)) ERR;
}
}
SUMMARIZE_ERR;
/* printf("**** testing compact storage..."); */
/* { */
/* int ncid, dimid[NDIM2], varid, varid2, varid3; */
/* int data[XDIM_LEN]; */
/* int storage_in; */
/* int x; */
printf("**** testing compact storage...");
{
int ncid, dimid[NDIM2], varid, varid2, varid3;
int data[XDIM_LEN];
int storage_in;
int x;
/* /\* Create some data. *\/ */
/* for (x = 0; x < XDIM_LEN; x++) */
/* data[x] = x; */
/* Create some data. */
for (x = 0; x < XDIM_LEN; x++)
data[x] = x;
/* /\* Create a file with one var with compact storage. *\/ */
/* if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR; */
/* Create a file with one var with compact storage. */
if (nc_create(FILE_NAME, NC_NETCDF4|NC_CLOBBER, &ncid)) ERR;
/* /\* Define dims. *\/ */
/* if (nc_def_dim(ncid, X_NAME, XDIM_LEN, &dimid[0])) ERR; */
/* if (nc_def_dim(ncid, Z_NAME, ZDIM_LEN, &dimid[1])) ERR; */
/* Define dims. */
if (nc_def_dim(ncid, X_NAME, XDIM_LEN, &dimid[0])) ERR;
if (nc_def_dim(ncid, Z_NAME, ZDIM_LEN, &dimid[1])) ERR;
/* /\* Define vars1 to be compact. *\/ */
/* if (nc_def_var(ncid, Y_NAME, NC_INT, 1, dimid, &varid)) ERR; */
/* if (nc_def_var_chunking(ncid, varid, NC_COMPACT, NULL)) ERR; */
/* if (nc_inq_var_chunking(ncid, varid, &storage_in, NULL)) ERR; */
/* if (storage_in != NC_COMPACT) ERR; */
/* Define vars1 to be compact. */
if (nc_def_var(ncid, Y_NAME, NC_INT, 1, dimid, &varid)) ERR;
if (nc_def_var_chunking(ncid, varid, NC_COMPACT, NULL)) ERR;
if (nc_inq_var_chunking(ncid, varid, &storage_in, NULL)) ERR;
if (storage_in != NC_COMPACT) ERR;
/* /\* Define var2 - it's too big for compact. *\/ */
/* if (nc_def_var(ncid, CLAIR, NC_INT, NDIM2, dimid, &varid2)) ERR; */
/* /\* This won't work, the var is too big for compact! *\/ */
/* if (nc_def_var_chunking(ncid, varid2, NC_COMPACT, NULL) != NC_EVARSIZE) ERR; */
/* Define var2 - it's too big for compact. */
if (nc_def_var(ncid, CLAIR, NC_INT, NDIM2, dimid, &varid2)) ERR;
/* This won't work, the var is too big for compact! */
if (nc_def_var_chunking(ncid, varid2, NC_COMPACT, NULL) != NC_EVARSIZE) ERR;
/* /\* Define var3, a scalar. Scalars can also be compact. *\/ */
/* if (nc_def_var(ncid, JAMIE, NC_INT, 0, NULL, &varid3)) ERR; */
/* if (nc_def_var_chunking(ncid, varid3, NC_COMPACT, NULL)) ERR; */
/* Define var3, a scalar. Scalars can also be compact. */
if (nc_def_var(ncid, JAMIE, NC_INT, 0, NULL, &varid3)) ERR;
if (nc_def_var_chunking(ncid, varid3, NC_COMPACT, NULL)) ERR;
/* /\* Write data. *\/ */
/* if (nc_put_var_int(ncid, varid3, data)) ERR; */
/* Write data. */
if (nc_put_var_int(ncid, varid3, data)) ERR;
/* /\* Close file. *\/ */
/* if (nc_close(ncid)) ERR; */
/* Close file. */
if (nc_close(ncid)) ERR;
/* /\* Open the file and check it. *\/ */
/* { */
/* int ndims, nvars; */
/* int storage_in; */
/* nc_set_log_level(3); */
/* if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; */
/* if (nc_inq(ncid, &ndims, &nvars, NULL, NULL)) ERR; */
/* if (ndims != 2 || nvars != 3) ERR; */
/* if (nc_inq_var_chunking(ncid, varid, &storage_in, NULL)) ERR; */
/* if (storage_in != NC_COMPACT) ERR; */
/* if (nc_inq_var_chunking(ncid, varid2, &storage_in, NULL)) ERR; */
/* if (storage_in != NC_CONTIGUOUS) ERR; */
/* if (nc_inq_var_chunking(ncid, varid3, &storage_in, NULL)) ERR; */
/* /\* if (storage_in != NC_COMPACT) ERR; *\/ */
/* if (nc_close(ncid)) ERR; */
/* } */
/* } */
/* SUMMARIZE_ERR; */
/* Open the file and check it. */
{
int ndims, nvars;
int storage_in;
if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR;
if (nc_inq(ncid, &ndims, &nvars, NULL, NULL)) ERR;
if (ndims != 2 || nvars != 3) ERR;
if (nc_inq_var_chunking(ncid, varid, &storage_in, NULL)) ERR;
if (storage_in != NC_COMPACT) ERR;
if (nc_inq_var_chunking(ncid, varid2, &storage_in, NULL)) ERR;
if (storage_in != NC_CONTIGUOUS) ERR;
if (nc_inq_var_chunking(ncid, varid3, &storage_in, NULL)) ERR;
if (storage_in != NC_COMPACT) ERR;
if (nc_close(ncid)) ERR;
}
}
SUMMARIZE_ERR;
FINAL_RESULTS;
}