From 133d0e21f69e61d59580f480027c9e3c1bb8afa2 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 2 Jan 2019 04:04:00 -0700 Subject: [PATCH] fixed some tests --- nc_test4/tst_h_refs.c | 1 - nc_test4/tst_vars4.c | 270 +++++++++++++++++++++--------------------- 2 files changed, 135 insertions(+), 136 deletions(-) diff --git a/nc_test4/tst_h_refs.c b/nc_test4/tst_h_refs.c index d2bf0663d..7610e42f8 100644 --- a/nc_test4/tst_h_refs.c +++ b/nc_test4/tst_h_refs.c @@ -82,7 +82,6 @@ main() int natts = 0; nc_type type; - nc_set_log_level(4); if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; /* Check the root group's attributes are OK */ diff --git a/nc_test4/tst_vars4.c b/nc_test4/tst_vars4.c index 7786bb017..acc2d0b3c 100644 --- a/nc_test4/tst_vars4.c +++ b/nc_test4/tst_vars4.c @@ -24,147 +24,147 @@ int main(int argc, char **argv) { printf("\n*** Testing netcdf-4 variable functions, even more.\n"); -/* printf("**** testing Jeff's dimension problem..."); */ -/* { */ -/* int varid, ncid, dims[NDIMS2], dims_in[NDIMS2]; */ -/* int ndims, nvars, ngatts, unlimdimid, natts; */ -/* char name_in[NC_MAX_NAME + 1]; */ -/* nc_type type_in; */ -/* size_t len_in; */ + printf("**** testing Jeff's dimension problem..."); + { + int varid, ncid, dims[NDIMS2], dims_in[NDIMS2]; + int ndims, nvars, ngatts, unlimdimid, natts; + char name_in[NC_MAX_NAME + 1]; + nc_type type_in; + size_t len_in; -/* if (nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid)) ERR; */ -/* if (nc_def_dim(ncid, X_NAME, XDIM_LEN, &dims[0])) ERR; */ -/* if (nc_def_dim(ncid, Y_NAME, YDIM_LEN, &dims[1])) ERR; */ -/* if (nc_def_var(ncid, VAR_NAME, NC_FLOAT, 2, dims, &varid)) ERR; */ -/* if (nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)) ERR; */ -/* if (nvars != NUM_VARS || ndims != NDIMS2 || ngatts != 0 || unlimdimid != -1) ERR; */ -/* if (nc_inq_var(ncid, 0, name_in, &type_in, &ndims, dims_in, &natts)) ERR; */ -/* if (strcmp(name_in, VAR_NAME) || type_in != NC_FLOAT || ndims != NDIMS2 || */ -/* dims_in[0] != dims[0] || dims_in[1] != dims[1] || natts != 0) ERR; */ -/* if (nc_inq_dim(ncid, 0, name_in, &len_in)) ERR; */ -/* if (strcmp(name_in, X_NAME) || len_in != XDIM_LEN) ERR; */ -/* if (nc_inq_dim(ncid, 1, name_in, &len_in)) ERR; */ -/* if (strcmp(name_in, Y_NAME)) ERR; */ -/* if (len_in != YDIM_LEN) ERR; */ -/* if (nc_close(ncid)) ERR; */ + if (nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid)) ERR; + if (nc_def_dim(ncid, X_NAME, XDIM_LEN, &dims[0])) ERR; + if (nc_def_dim(ncid, Y_NAME, YDIM_LEN, &dims[1])) ERR; + if (nc_def_var(ncid, VAR_NAME, NC_FLOAT, 2, dims, &varid)) ERR; + if (nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)) ERR; + if (nvars != NUM_VARS || ndims != NDIMS2 || ngatts != 0 || unlimdimid != -1) ERR; + if (nc_inq_var(ncid, 0, name_in, &type_in, &ndims, dims_in, &natts)) ERR; + if (strcmp(name_in, VAR_NAME) || type_in != NC_FLOAT || ndims != NDIMS2 || + dims_in[0] != dims[0] || dims_in[1] != dims[1] || natts != 0) ERR; + if (nc_inq_dim(ncid, 0, name_in, &len_in)) ERR; + if (strcmp(name_in, X_NAME) || len_in != XDIM_LEN) ERR; + if (nc_inq_dim(ncid, 1, name_in, &len_in)) ERR; + if (strcmp(name_in, Y_NAME)) ERR; + if (len_in != YDIM_LEN) ERR; + if (nc_close(ncid)) ERR; -/* /\* Open the file and check. *\/ */ -/* if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; */ -/* if (nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)) ERR; */ -/* if (nvars != NUM_VARS || ndims != NDIMS2 || ngatts != 0 || unlimdimid != -1) ERR; */ -/* if (nc_inq_var(ncid, 0, name_in, &type_in, &ndims, dims_in, &natts)) ERR; */ -/* if (strcmp(name_in, VAR_NAME) || type_in != NC_FLOAT || ndims != NDIMS2 || */ -/* dims_in[0] != dims[0] || dims_in[1] != dims[1] || natts != 0) ERR; */ -/* if (nc_inq_dim(ncid, 0, name_in, &len_in)) ERR; */ -/* if (strcmp(name_in, X_NAME) || len_in != XDIM_LEN) ERR; */ -/* if (nc_inq_dim(ncid, 1, name_in, &len_in)) ERR; */ -/* if (strcmp(name_in, Y_NAME)) ERR; */ -/* if (len_in != YDIM_LEN) ERR; */ -/* if (nc_close(ncid)) ERR; */ -/* } */ -/* SUMMARIZE_ERR; */ -/* printf("**** testing chunking turned on by fletcher..."); */ -/* { */ -/* int varid, ncid, dims[NDIMS2]; */ -/* int storage_in; */ -/* size_t chunksizes_in[NDIMS2]; */ + /* Open the file and check. */ + if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; + if (nc_inq(ncid, &ndims, &nvars, &ngatts, &unlimdimid)) ERR; + if (nvars != NUM_VARS || ndims != NDIMS2 || ngatts != 0 || unlimdimid != -1) ERR; + if (nc_inq_var(ncid, 0, name_in, &type_in, &ndims, dims_in, &natts)) ERR; + if (strcmp(name_in, VAR_NAME) || type_in != NC_FLOAT || ndims != NDIMS2 || + dims_in[0] != dims[0] || dims_in[1] != dims[1] || natts != 0) ERR; + if (nc_inq_dim(ncid, 0, name_in, &len_in)) ERR; + if (strcmp(name_in, X_NAME) || len_in != XDIM_LEN) ERR; + if (nc_inq_dim(ncid, 1, name_in, &len_in)) ERR; + if (strcmp(name_in, Y_NAME)) ERR; + if (len_in != YDIM_LEN) ERR; + if (nc_close(ncid)) ERR; + } + SUMMARIZE_ERR; + printf("**** testing chunking turned on by fletcher..."); + { + int varid, ncid, dims[NDIMS2]; + int storage_in; + size_t chunksizes_in[NDIMS2]; -/* if (nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid)) ERR; */ -/* if (nc_def_dim(ncid, X_NAME, XDIM_LEN, &dims[0])) ERR; */ -/* if (nc_def_dim(ncid, Y_NAME, YDIM_LEN, &dims[1])) ERR; */ -/* if (nc_def_var(ncid, VAR_NAME, NC_FLOAT, 2, dims, &varid)) ERR; */ -/* if (nc_def_var_fletcher32(ncid, varid, NC_FLETCHER32)) ERR; */ -/* if (nc_inq_var_chunking(ncid, varid, &storage_in, chunksizes_in)) ERR; */ -/* if (chunksizes_in[0] != XDIM_LEN || chunksizes_in[1] != YDIM_LEN) ERR; */ -/* if (nc_close(ncid)) ERR; */ + if (nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid)) ERR; + if (nc_def_dim(ncid, X_NAME, XDIM_LEN, &dims[0])) ERR; + if (nc_def_dim(ncid, Y_NAME, YDIM_LEN, &dims[1])) ERR; + if (nc_def_var(ncid, VAR_NAME, NC_FLOAT, 2, dims, &varid)) ERR; + if (nc_def_var_fletcher32(ncid, varid, NC_FLETCHER32)) ERR; + if (nc_inq_var_chunking(ncid, varid, &storage_in, chunksizes_in)) ERR; + if (chunksizes_in[0] != XDIM_LEN || chunksizes_in[1] != YDIM_LEN) ERR; + if (nc_close(ncid)) ERR; -/* /\* Open the file and check. *\/ */ -/* if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; */ -/* if (nc_inq_var_chunking(ncid, varid, &storage_in, chunksizes_in)) ERR; */ -/* if (chunksizes_in[0] != XDIM_LEN || chunksizes_in[1] != YDIM_LEN) ERR; */ -/* if (nc_close(ncid)) ERR; */ -/* } */ -/* SUMMARIZE_ERR; */ -/* printf("**** testing chunking turned on by shuffle..."); */ -/* { */ -/* int varid, ncid, dims[NDIMS2]; */ -/* int storage_in; */ -/* size_t chunksizes_in[NDIMS2]; */ + /* Open the file and check. */ + if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; + if (nc_inq_var_chunking(ncid, varid, &storage_in, chunksizes_in)) ERR; + if (chunksizes_in[0] != XDIM_LEN || chunksizes_in[1] != YDIM_LEN) ERR; + if (nc_close(ncid)) ERR; + } + SUMMARIZE_ERR; + printf("**** testing chunking turned on by shuffle..."); + { + int varid, ncid, dims[NDIMS2]; + int storage_in; + size_t chunksizes_in[NDIMS2]; -/* if (nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid)) ERR; */ -/* if (nc_def_dim(ncid, X_NAME, XDIM_LEN, &dims[0])) ERR; */ -/* if (nc_def_dim(ncid, Y_NAME, YDIM_LEN, &dims[1])) ERR; */ -/* if (nc_def_var(ncid, VAR_NAME, NC_FLOAT, 2, dims, &varid)) ERR; */ -/* if (nc_def_var_deflate(ncid, varid, NC_SHUFFLE, 0, 0)) ERR; */ -/* if (nc_inq_var_chunking(ncid, varid, &storage_in, chunksizes_in)) ERR; */ -/* if (chunksizes_in[0] != XDIM_LEN || chunksizes_in[1] != YDIM_LEN) ERR; */ -/* if (nc_close(ncid)) ERR; */ + if (nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid)) ERR; + if (nc_def_dim(ncid, X_NAME, XDIM_LEN, &dims[0])) ERR; + if (nc_def_dim(ncid, Y_NAME, YDIM_LEN, &dims[1])) ERR; + if (nc_def_var(ncid, VAR_NAME, NC_FLOAT, 2, dims, &varid)) ERR; + if (nc_def_var_deflate(ncid, varid, NC_SHUFFLE, 0, 0)) ERR; + if (nc_inq_var_chunking(ncid, varid, &storage_in, chunksizes_in)) ERR; + if (chunksizes_in[0] != XDIM_LEN || chunksizes_in[1] != YDIM_LEN) ERR; + if (nc_close(ncid)) ERR; -/* /\* Open the file and check. *\/ */ -/* if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; */ -/* if (nc_inq_var_chunking(ncid, varid, &storage_in, chunksizes_in)) ERR; */ -/* if (chunksizes_in[0] != XDIM_LEN || chunksizes_in[1] != YDIM_LEN) ERR; */ -/* if (nc_close(ncid)) ERR; */ -/* } */ -/* SUMMARIZE_ERR; */ -/* #define DIM_NAME "Distance_from_Mayo" */ -/* #define VAR_NAME_2 "Rocky_Road_to_Dublin" */ -/* #define NDIMS1 1 */ -/* #define NUM_RECORDS 3 */ -/* printf("**** testing extending var along unlimited dim with no coord var..."); */ -/* { */ -/* int varid, ncid, dimid; */ -/* int ndims, nvars, natts, unlimdimid; */ -/* size_t dim_len_in, index; */ -/* int data = TEST_VAL_42; */ + /* Open the file and check. */ + if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; + if (nc_inq_var_chunking(ncid, varid, &storage_in, chunksizes_in)) ERR; + if (chunksizes_in[0] != XDIM_LEN || chunksizes_in[1] != YDIM_LEN) ERR; + if (nc_close(ncid)) ERR; + } + SUMMARIZE_ERR; +#define DIM_NAME "Distance_from_Mayo" +#define VAR_NAME_2 "Rocky_Road_to_Dublin" +#define NDIMS1 1 +#define NUM_RECORDS 3 + printf("**** testing extending var along unlimited dim with no coord var..."); + { + int varid, ncid, dimid; + int ndims, nvars, natts, unlimdimid; + size_t dim_len_in, index; + int data = TEST_VAL_42; -/* /\* Create the test file with one var, one unlimited dim. *\/ */ -/* if (nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid)) ERR; */ -/* if (nc_def_dim(ncid, DIM_NAME, NC_UNLIMITED, &dimid)) ERR; */ -/* if (nc_def_var(ncid, VAR_NAME_2, NC_INT, NDIMS1, &dimid, &varid)) ERR; */ + /* Create the test file with one var, one unlimited dim. */ + if (nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid)) ERR; + if (nc_def_dim(ncid, DIM_NAME, NC_UNLIMITED, &dimid)) ERR; + if (nc_def_var(ncid, VAR_NAME_2, NC_INT, NDIMS1, &dimid, &varid)) ERR; -/* /\* Write some records. *\/ */ -/* for (index = 0; index < NUM_RECORDS; index++) */ -/* if (nc_put_var1_int(ncid, varid, &index, &data)) ERR; */ -/* if (nc_close(ncid)) ERR; */ + /* Write some records. */ + for (index = 0; index < NUM_RECORDS; index++) + if (nc_put_var1_int(ncid, varid, &index, &data)) ERR; + if (nc_close(ncid)) ERR; -/* /\* Open the file and check. *\/ */ -/* if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; */ -/* if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; */ -/* if (ndims != 1 || nvars != 1 || natts != 0 || unlimdimid != 0) ERR; */ -/* if (nc_inq_dim(ncid, dimid, NULL, &dim_len_in)) ERR; */ -/* if (dim_len_in != NUM_RECORDS) ERR; */ + /* Open the file and check. */ + if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; + if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; + if (ndims != 1 || nvars != 1 || natts != 0 || unlimdimid != 0) ERR; + if (nc_inq_dim(ncid, dimid, NULL, &dim_len_in)) ERR; + if (dim_len_in != NUM_RECORDS) ERR; -/* /\* Now add more records. *\/ */ -/* for (index = 3; index < NUM_RECORDS * 2; index++) */ -/* if (nc_put_var1_int(ncid, varid, &index, &data)) ERR; */ -/* if (nc_inq_dim(ncid, dimid, NULL, &dim_len_in)) ERR; */ + /* Now add more records. */ + for (index = 3; index < NUM_RECORDS * 2; index++) + if (nc_put_var1_int(ncid, varid, &index, &data)) ERR; + if (nc_inq_dim(ncid, dimid, NULL, &dim_len_in)) ERR; -/* if (dim_len_in != NUM_RECORDS * 2) ERR; */ + if (dim_len_in != NUM_RECORDS * 2) ERR; -/* /\* Close the file. *\/ */ -/* if (nc_close(ncid)) ERR; */ -/* } */ -/* SUMMARIZE_ERR; */ -/* printf("**** testing type creation and destruction for atomic types..."); */ -/* { */ -/* int varid1, varid2, ncid; */ -/* int ndims, nvars, natts, unlimdimid; */ + /* Close the file. */ + if (nc_close(ncid)) ERR; + } + SUMMARIZE_ERR; + printf("**** testing type creation and destruction for atomic types..."); + { + int varid1, varid2, ncid; + int ndims, nvars, natts, unlimdimid; -/* /\* Create the test file with two scalar vars. *\/ */ -/* /\* nc_set_log_level(4); *\/ */ -/* if (nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid)) ERR; */ -/* if (nc_def_var(ncid, CLAIR, NC_INT, 0, NULL, &varid1)) ERR; */ -/* if (nc_def_var(ncid, JAMIE, NC_INT, 0, NULL, &varid2)) ERR; */ -/* if (nc_close(ncid)) ERR; */ + /* Create the test file with two scalar vars. */ + /* nc_set_log_level(4); */ + if (nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid)) ERR; + if (nc_def_var(ncid, CLAIR, NC_INT, 0, NULL, &varid1)) ERR; + if (nc_def_var(ncid, JAMIE, NC_INT, 0, NULL, &varid2)) ERR; + if (nc_close(ncid)) ERR; -/* /\* Open the file and check. *\/ */ -/* if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; */ -/* if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; */ -/* if (ndims != 0 || nvars != 2 || natts != 0 || unlimdimid != -1) ERR; */ -/* if (nc_close(ncid)) ERR; */ -/* } */ -/* SUMMARIZE_ERR; */ + /* Open the file and check. */ + if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; + if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; + if (ndims != 0 || nvars != 2 || natts != 0 || unlimdimid != -1) ERR; + if (nc_close(ncid)) ERR; + } + SUMMARIZE_ERR; printf("**** testing scalar big endian vars..."); { int varid1, varid2, ncid; @@ -186,14 +186,14 @@ main(int argc, char **argv) if (nc_close(ncid)) ERR; /* Open the file and check. */ - /* if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; */ - /* if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; */ - /* if (ndims != 0 || nvars != 2 || natts != 0 || unlimdimid != -1) ERR; */ - /* if (nc_get_var(ncid, varid1, &data_in)) ERR; */ - /* if (data_in != TEST_VAL_42) ERR; */ - /* if (nc_get_var(ncid, varid2, &data_in)) ERR; */ - /* if (data_in != TEST_VAL_42 * 2) ERR; */ - /* if (nc_close(ncid)) ERR; */ + if (nc_open(FILE_NAME, NC_WRITE, &ncid)) ERR; + if (nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid)) ERR; + if (ndims != 0 || nvars != 2 || natts != 0 || unlimdimid != -1) ERR; + if (nc_get_var(ncid, varid1, &data_in)) ERR; + if (data_in != TEST_VAL_42) ERR; + if (nc_get_var(ncid, varid2, &data_in)) ERR; + if (data_in != TEST_VAL_42 * 2) ERR; + if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; FINAL_RESULTS;