From 8f4d5e6a5b51842e7d55715c0dd0eb16e6c46db5 Mon Sep 17 00:00:00 2001 From: edwardhartnett Date: Sun, 17 Nov 2019 15:41:24 -0700 Subject: [PATCH 1/3] turned off cmake build in travis --- nc_test4/tst_dims3.c | 122 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/nc_test4/tst_dims3.c b/nc_test4/tst_dims3.c index c98ec5e20..23ce2e77a 100644 --- a/nc_test4/tst_dims3.c +++ b/nc_test4/tst_dims3.c @@ -235,5 +235,127 @@ main(int argc, char **argv) if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; +#define NDIM2 2 +#define NY 3 +#define NX 3 +#define DIM_LEN 2 +#define VAR_NAME "var" +#define DIM_NAME1 "y" +#define DIM_NAME2 "x" + printf("*** testing simple case writing data with 2 unlim dims..."); + { + /* This test code based on test code from Jeff Whitaker. See + * https://github.com/Unidata/netcdf4-python/issues/1413. */ + int varid1, varid, ncid; + int dimids[NDIM2]; + size_t start[1] = {0}; + size_t count[1] = {NY}; + size_t start2[NDIM2] = {0, 1}; + size_t count2[NDIM2] = {1, 1}; + int ydata[NY]; + int data = TEST_VAL_42; + int x, y, i; + + /* Fill Y data array. */ + for (i = 0; i < NY; ++i) + ydata[i] = i; + + nc_set_log_level(4); + /* Create a file. */ + if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; + + /* Define two unlimited dims. */ + if (nc_def_dim(ncid, DIM_NAME1, NC_UNLIMITED, &dimids[0])) ERR; + if (nc_def_dim(ncid, DIM_NAME2, NC_UNLIMITED, &dimids[1])) ERR; + + /* Define coord var for first dim Y. */ + if (nc_def_var(ncid, DIM_NAME1, NC_INT, 1, &dimids[0], &varid1)) ERR; + + /* Define a data var with dims Y,X. */ + if (nc_def_var(ncid, VAR_NAME, NC_INT, NDIM2, dimids, &varid)) ERR; + + /* Write data to coordinate var to extend Y. */ + if (nc_put_vara_int(ncid, varid1, start, count, ydata)) ERR; + if (nc_sync(ncid)) ERR; + + /* write a single data point to the 2d variable */ + if (nc_put_vara_int(ncid, varid, start2, count2, &data)) ERR; + if (nc_close(ncid)) ERR; + + /* Reopen the file and check. */ + if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; + + /* Read and check each value. */ + for (x = 0; x < NX; x++) + { + for (y = 0; y < NY; y++) + { + size_t index[NDIM2] = {y, x}; + int data_in; + + printf("y %d x %d\n", y, x); + if (nc_get_var1_int(ncid, varid, index, &data_in)) ERR; + printf("y %d x %d data_in %d\n", y, x, data_in); + } + } + + if (nc_close(ncid)) ERR; + } + SUMMARIZE_ERR; +/* #define NDIM2 2 */ +/* #define NY 10 */ +/* #define NX 5 */ +/* #define DIM_LEN 2 */ +/* #define VAR_NAME "var" */ +/* #define DIM_NAME1 "y" */ +/* #define DIM_NAME2 "x" */ +/* printf("*** testing writing data with 2 unlim dims..."); */ +/* { */ +/* /\* This test code based on test code from Jeff Whitaker. See */ +/* * https://github.com/Unidata/netcdf4-python/issues/1413. *\/ */ +/* int dimids[NDIM2]; */ +/* int ydata[NY]; */ +/* int xdata[NX]; */ +/* int data = TEST_VAL_42; */ +/* int varid1, varid2, varid, i, ncid; */ +/* size_t start[1]; */ +/* size_t count[1]; */ +/* size_t start2[2]; */ +/* size_t count2[2]; */ + +/* /\* Fill two data arrays. *\/ */ +/* for (i = 0; i < NX; ++i) */ +/* xdata[i] = i; */ +/* for (i = 0; i < NY; ++i) */ +/* ydata[i] = i; */ + +/* nc_set_log_level(4); */ +/* /\* Create two 1-D coord vars and a data var two unlimited */ +/* * dimensions. *\/ */ +/* if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; */ +/* if (nc_def_dim(ncid, DIM_NAME1, NC_UNLIMITED, &dimids[0])) ERR; */ +/* if (nc_def_dim(ncid, DIM_NAME2, NC_UNLIMITED, &dimids[1])) ERR; */ +/* if (nc_def_var(ncid, DIM_NAME1, NC_INT, 1, &dimids[0], &varid1)) ERR; */ +/* if (nc_def_var(ncid, DIM_NAME2, NC_INT, 1, &dimids[1], &varid2)) ERR; */ +/* if (nc_def_var(ncid, VAR_NAME, NC_INT, NDIM2, dimids, &varid)) ERR; */ + +/* /\* Write data to coordinate vars to define dimension */ +/* * lengths. *\/ */ +/* start[0]=0; */ +/* count[0]=NY; */ +/* if (nc_put_vara_int(ncid, varid1, start, count, ydata)) ERR; */ +/* count[0]=NX; */ +/* if (nc_put_vara_int(ncid, varid2, start, count, xdata)) ERR; */ +/* if (nc_sync(ncid)) ERR; */ + +/* /\* write a single data point to the 2d variable *\/ */ +/* start2[0]=2; */ +/* start2[1]=3; */ +/* count2[0]=1; */ +/* count2[1]=1; */ +/* if (nc_put_vara_int(ncid, varid, start2, count2, &data)) ERR; */ +/* if (nc_close(ncid)) ERR; */ +/* } */ +/* SUMMARIZE_ERR; */ FINAL_RESULTS; } From e52a74520ecd9562ef90f136f7965727e64cd33f Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sun, 1 Dec 2019 15:05:09 -0700 Subject: [PATCH 2/3] tests and fix for multiple unlimited dim bug --- libhdf5/hdf5var.c | 35 ++++++++++++++++++++------------- nc_test4/tst_dims3.c | 47 -------------------------------------------- 2 files changed, 21 insertions(+), 61 deletions(-) diff --git a/libhdf5/hdf5var.c b/libhdf5/hdf5var.c index 78f0cad89..db9901b7c 100644 --- a/libhdf5/hdf5var.c +++ b/libhdf5/hdf5var.c @@ -1895,7 +1895,8 @@ NC4_get_vars(int ncid, int varid, const size_t *startp, const size_t *countp, #endif /* Check dimension bounds. Remember that unlimited dimensions can - * put data beyond their current length. */ + * get data beyond the length of the dataset, but within the + * lengths of the unlimited dimension(s). */ for (d2 = 0; d2 < var->ndims; d2++) { hsize_t endindex = start[d2] + stride[d2] * (count[d2] - 1); /* last index read */ @@ -1920,20 +1921,26 @@ NC4_get_vars(int ncid, int varid, const size_t *startp, const size_t *countp, if (count[d2] && endindex >= ulen) BAIL_QUIET(NC_EEDGE); - /* Things get a little tricky here. If we're getting - a GET request beyond the end of this var's - current length in an unlimited dimension, we'll - later need to return the fill value for the - variable. */ - if (start[d2] >= (hssize_t)fdims[d2]) - fill_value_size[d2] = count[d2]; - else if (endindex >= fdims[d2]) - fill_value_size[d2] = count[d2] - ((fdims[d2] - start[d2])/stride[d2]); + /* Things get a little tricky here. If we're getting a GET + request beyond the end of this var's current length in + an unlimited dimension, we'll later need to return the + fill value for the variable. */ + if (!no_read) + { + if (start[d2] >= (hssize_t)fdims[d2]) + fill_value_size[d2] = count[d2]; + else if (endindex >= fdims[d2]) + fill_value_size[d2] = count[d2] - ((fdims[d2] - start[d2])/stride[d2]); + else + fill_value_size[d2] = 0; + count[d2] -= fill_value_size[d2]; + if (count[d2] == 0) + no_read++; + if (fill_value_size[d2]) + provide_fill++; + } else - fill_value_size[d2] = 0; - count[d2] -= fill_value_size[d2]; - if (fill_value_size[d2]) - provide_fill++; + fill_value_size[d2] = count[d2]; } else /* Dim is not unlimited. */ { diff --git a/nc_test4/tst_dims3.c b/nc_test4/tst_dims3.c index dbd043b14..3c9f842b2 100644 --- a/nc_test4/tst_dims3.c +++ b/nc_test4/tst_dims3.c @@ -390,52 +390,5 @@ main(int argc, char **argv) if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; - /* printf("*** testing writing data with 2 unlim dims..."); */ - /* { */ - /* /\* This test code based on test code from Jeff Whitaker. See */ - /* * https://github.com/Unidata/netcdf4-python/issues/1413. *\/ */ - /* int dimids[NDIM2]; */ - /* int ydata[NY]; */ - /* int xdata[NX]; */ - /* int data = TEST_VAL_42; */ - /* int varid1, varid2, varid, i, ncid; */ - /* size_t start[1]; */ - /* size_t count[1]; */ - /* size_t start2[2]; */ - /* size_t count2[2]; */ - - /* /\* Fill two data arrays. *\/ */ - /* for (i = 0; i < NX; ++i) */ - /* xdata[i] = i; */ - /* for (i = 0; i < NY; ++i) */ - /* ydata[i] = i; */ - - /* /\* Create two 1-D coord vars and a data var two unlimited */ - /* * dimensions. *\/ */ - /* if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; */ - /* if (nc_def_dim(ncid, DIM_NAME1, NC_UNLIMITED, &dimids[0])) ERR; */ - /* if (nc_def_dim(ncid, DIM_NAME2, NC_UNLIMITED, &dimids[1])) ERR; */ - /* if (nc_def_var(ncid, DIM_NAME1, NC_INT, 1, &dimids[0], &varid1)) ERR; */ - /* if (nc_def_var(ncid, DIM_NAME2, NC_INT, 1, &dimids[1], &varid2)) ERR; */ - /* if (nc_def_var(ncid, VAR_NAME, NC_INT, NDIM2, dimids, &varid)) ERR; */ - - /* /\* Write data to coordinate vars to define dimension */ - /* * lengths. *\/ */ - /* start[0]=0; */ - /* count[0]=NY; */ - /* if (nc_put_vara_int(ncid, varid1, start, count, ydata)) ERR; */ - /* count[0]=NX; */ - /* if (nc_put_vara_int(ncid, varid2, start, count, xdata)) ERR; */ - /* if (nc_sync(ncid)) ERR; */ - - /* /\* write a single data point to the 2d variable *\/ */ - /* start2[0]=2; */ - /* start2[1]=3; */ - /* count2[0]=1; */ - /* count2[1]=1; */ - /* if (nc_put_vara_int(ncid, varid, start2, count2, &data)) ERR; */ - /* if (nc_close(ncid)) ERR; */ - /* } */ - /* SUMMARIZE_ERR; */ FINAL_RESULTS; } From 645b8566cdddf9b00ffac6ad66cb3cf3fc113a02 Mon Sep 17 00:00:00 2001 From: Edward Hartnett Date: Sun, 1 Dec 2019 15:05:43 -0700 Subject: [PATCH 3/3] more tests --- nc_test4/tst_dims3.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/nc_test4/tst_dims3.c b/nc_test4/tst_dims3.c index 3c9f842b2..cb31cc47a 100644 --- a/nc_test4/tst_dims3.c +++ b/nc_test4/tst_dims3.c @@ -342,24 +342,24 @@ main(int argc, char **argv) if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; /* Read and check each value with nc_get_var1_int(). */ - /* for (x = 0; x < NX; x++) */ - /* { */ - /* for (y = 0; y < NY; y++) */ - /* { */ - /* size_t index[NDIM2] = {y, x}; */ - /* int data_in; */ + for (x = 0; x < NX; x++) + { + for (y = 0; y < NY; y++) + { + size_t index[NDIM2] = {y, x}; + int data_in; - /* if (nc_get_var1_int(ncid, varid, index, &data_in)) ERR; */ - /* if (y == start2[0] && x == start2[1]) */ - /* { */ - /* if (data_in != data) ERR; */ - /* } */ - /* else */ - /* { */ - /* if (data_in != NC_FILL_INT) ERR; */ - /* } */ - /* } */ - /* } */ + if (nc_get_var1_int(ncid, varid, index, &data_in)) ERR; + if (y == start2[0] && x == start2[1]) + { + if (data_in != data) ERR; + } + else + { + if (data_in != NC_FILL_INT) ERR; + } + } + } /* Read and check each row with nc_get_vara_int(). */ for (y = 0; y < NY; y++)