From 0e454a75c2fbeb4e4b21068a45955d1c1e09cc99 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 30 Mar 2018 10:20:33 -0600 Subject: [PATCH 1/4] added fill mode test --- nc_test4/tst_fills.c | 238 ++++++++++++++++++++++++------------------- 1 file changed, 136 insertions(+), 102 deletions(-) diff --git a/nc_test4/tst_fills.c b/nc_test4/tst_fills.c index c8cf164eee..808eb3c105 100644 --- a/nc_test4/tst_fills.c +++ b/nc_test4/tst_fills.c @@ -2,9 +2,10 @@ Corporation for Atmospheric Research/Unidata See COPYRIGHT file for conditions of use. See www.unidata.ucar.edu for more info. - Create a test file with default fill values for variables of each type. + Create a test file with default fill values for variables of each + type. - $Id: tst_fills.c,v 1.12 2009/03/17 01:22:42 ed Exp $ + Ed Hartnett */ #include @@ -205,56 +206,56 @@ main(int argc, char **argv) if (nc_inq_varid(ncid, fnames[fixvar], &varid)) ERR; if (nc_inq_vartype(ncid, varid, &type)) ERR; switch(type) { - case NC_CHAR: - { - char vals[NVALS]; - if (nc_get_var_text(ncid, varid, vals)) ERR; - for (i = 0; i < NVALS; i++) - if(vals[i] != NC_FILL_CHAR) ERR; - } - break; - case NC_BYTE: - { - signed char vals[NVALS]; - if (nc_get_var_schar(ncid, varid, vals)) ERR; - for (i = 0; i < NVALS; i++) - if(vals[i] != NC_FILL_BYTE) ERR; - } - break; - case NC_SHORT: - { - short vals[NVALS]; - if (nc_get_var_short(ncid, varid, vals)) ERR; - for (i = 0; i < NVALS; i++) - if(vals[i] != NC_FILL_SHORT) ERR; - } - break; - case NC_INT: - { - int vals[NVALS]; - if (nc_get_var_int(ncid, varid, vals)) ERR; - for (i = 0; i < NVALS; i++) - if(vals[i] != NC_FILL_INT) ERR; - } - break; - case NC_FLOAT: - { - float vals[NVALS]; - if (nc_get_var_float(ncid, varid, vals)) ERR; - for (i = 0; i < NVALS; i++) - if(vals[i] != NC_FILL_FLOAT) ERR; - } - break; - case NC_DOUBLE: - { - double vals[NVALS]; - if (nc_get_var_double(ncid, varid, vals)) ERR; - for (i = 0; i < NVALS; i++) - if (vals[i] != NC_FILL_DOUBLE) ERR; - } - break; - default: - ERR; + case NC_CHAR: + { + char vals[NVALS]; + if (nc_get_var_text(ncid, varid, vals)) ERR; + for (i = 0; i < NVALS; i++) + if(vals[i] != NC_FILL_CHAR) ERR; + } + break; + case NC_BYTE: + { + signed char vals[NVALS]; + if (nc_get_var_schar(ncid, varid, vals)) ERR; + for (i = 0; i < NVALS; i++) + if(vals[i] != NC_FILL_BYTE) ERR; + } + break; + case NC_SHORT: + { + short vals[NVALS]; + if (nc_get_var_short(ncid, varid, vals)) ERR; + for (i = 0; i < NVALS; i++) + if(vals[i] != NC_FILL_SHORT) ERR; + } + break; + case NC_INT: + { + int vals[NVALS]; + if (nc_get_var_int(ncid, varid, vals)) ERR; + for (i = 0; i < NVALS; i++) + if(vals[i] != NC_FILL_INT) ERR; + } + break; + case NC_FLOAT: + { + float vals[NVALS]; + if (nc_get_var_float(ncid, varid, vals)) ERR; + for (i = 0; i < NVALS; i++) + if(vals[i] != NC_FILL_FLOAT) ERR; + } + break; + case NC_DOUBLE: + { + double vals[NVALS]; + if (nc_get_var_double(ncid, varid, vals)) ERR; + for (i = 0; i < NVALS; i++) + if (vals[i] != NC_FILL_DOUBLE) ERR; + } + break; + default: + ERR; } } @@ -268,61 +269,94 @@ main(int argc, char **argv) if (nc_inq_varid(ncid, rnames[recvar], &varid)) ERR; if (nc_inq_vartype(ncid, varid, &type)) ERR; switch(type) { - case NC_CHAR: - { - char vals[NVALS]; - if (nc_get_vara_text(ncid, varid, start, count, vals)) ERR; - for (i = 0; i < NVALS; i++) - if(vals[i] != NC_FILL_CHAR) ERR; - } - break; - case NC_BYTE: - { - signed char vals[NVALS]; - if (nc_get_vara_schar(ncid, varid, start, count, vals)) ERR; - for (i = 0; i < NVALS; i++) - if(vals[i] != NC_FILL_BYTE) ERR; - } - break; - case NC_SHORT: - { - short vals[NVALS]; - if (nc_get_vara_short(ncid, varid, start, count, vals)) ERR; - for (i = 0; i < NVALS; i++) - if(vals[i] != NC_FILL_SHORT) ERR; - } - break; - case NC_INT: - { - int vals[NVALS]; - if (nc_get_vara_int(ncid, varid, start, count, vals)) ERR; - for (i = 0; i < NVALS; i++) - if(vals[i] != NC_FILL_INT) ERR; - } - break; - case NC_FLOAT: - { - float vals[NVALS]; - if (nc_get_vara_float(ncid, varid, start, count, vals)) ERR; - for (i = 0; i < NVALS; i++) - if(vals[i] != NC_FILL_FLOAT) ERR; - } - break; - case NC_DOUBLE: - { - double vals[NVALS]; - if (nc_get_vara_double(ncid, varid, start, count, vals)) ERR; - for (i = 0; i < NVALS; i++) - if(vals[i] != NC_FILL_DOUBLE) ERR; - } - break; - default: - ERR; + case NC_CHAR: + { + char vals[NVALS]; + if (nc_get_vara_text(ncid, varid, start, count, vals)) ERR; + for (i = 0; i < NVALS; i++) + if(vals[i] != NC_FILL_CHAR) ERR; + } + break; + case NC_BYTE: + { + signed char vals[NVALS]; + if (nc_get_vara_schar(ncid, varid, start, count, vals)) ERR; + for (i = 0; i < NVALS; i++) + if(vals[i] != NC_FILL_BYTE) ERR; + } + break; + case NC_SHORT: + { + short vals[NVALS]; + if (nc_get_vara_short(ncid, varid, start, count, vals)) ERR; + for (i = 0; i < NVALS; i++) + if(vals[i] != NC_FILL_SHORT) ERR; + } + break; + case NC_INT: + { + int vals[NVALS]; + if (nc_get_vara_int(ncid, varid, start, count, vals)) ERR; + for (i = 0; i < NVALS; i++) + if(vals[i] != NC_FILL_INT) ERR; + } + break; + case NC_FLOAT: + { + float vals[NVALS]; + if (nc_get_vara_float(ncid, varid, start, count, vals)) ERR; + for (i = 0; i < NVALS; i++) + if(vals[i] != NC_FILL_FLOAT) ERR; + } + break; + case NC_DOUBLE: + { + double vals[NVALS]; + if (nc_get_vara_double(ncid, varid, start, count, vals)) ERR; + for (i = 0; i < NVALS; i++) + if(vals[i] != NC_FILL_DOUBLE) ERR; + } + break; + default: + ERR; } } if (nc_close(ncid)) ERR; } SUMMARIZE_ERR; + printf("*** testing fill mode..."); +#define NDIM1 1 +#define DIM_LEN 4 +#define DIM_NAME "my_dim" +#define VAR_NAME "my_var" + { + int ncid; + int dimid; + int varid; + int cmode = 0; + char testfile[] = "test.nc"; + size_t index = 2; + int test_val = 42; + int no_fill; + int ret; + + if ((ret = nc_create(testfile, cmode, &ncid))) + return ret; + if ((ret = nc_def_dim(ncid, DIM_NAME, DIM_LEN, &dimid))) + return ret; + if ((ret = nc_def_var(ncid, VAR_NAME, NC_INT, NDIM1, &dimid, &varid))) + return ret; + if ((ret = nc_enddef(ncid))) + return ret; + if ((ret = nc_put_var1_int(ncid, varid, &index, &test_val))) + return ret; + if ((ret = nc_inq_var_fill(ncid, varid, &no_fill, NULL))) + return ret; + if (no_fill) ERR; + if ((ret = nc_close(ncid))) + return ret; + } + SUMMARIZE_ERR; FINAL_RESULTS; } From 168340a8b6ce38e4e3378bac9f69744bd99211dc Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 30 Mar 2018 11:26:47 -0600 Subject: [PATCH 2/4] added test for utf8 normalization for variable rename --- nc_test4/tst_utf8.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/nc_test4/tst_utf8.c b/nc_test4/tst_utf8.c index 6d2bb45625..68f7732bc8 100644 --- a/nc_test4/tst_utf8.c +++ b/nc_test4/tst_utf8.c @@ -6,7 +6,7 @@ Unicode names encoded with UTF-8. It is the NETCDF3 equivalent of tst_unicode.c - $Id: tst_utf8.c,v 1.14 2008/10/20 01:48:09 ed Exp $ + Russ Rew, Ed Hartnett */ #include @@ -21,6 +21,7 @@ #define NDIMS 1 #define NX 18 #define ENUM_VALUE 2 +#define BORING_NAME "boring" /* (unnormalized) UTF-8 encoding for Unicode 8-character "Hello" in Greek */ char name_utf8[] = "\xCE\x9A\xCE\xB1\xCE\xBB\xCE\xB7\xCE\xBC\xE1\xBD\xB3\xCF\x81\xCE\xB1"; @@ -283,7 +284,25 @@ main(int argc, char **argv) check_nc4_file(ncid); if (nc_close(ncid)) ERR; } + SUMMARIZE_ERR; + printf("*** ensuring UTF-8 normaization is applied in rename..."); + { + int ncid, varid; + char name_in[NC_MAX_NAME + 1]; + + if (nc_create(FILE_NAME, NC_NETCDF4 | NC_CLOBBER, &ncid)) ERR; + if (nc_def_var(ncid, BORING_NAME, NC_CHAR, 0, NULL, &varid)) ERR; + if (nc_rename_var(ncid, varid, name_utf8)) ERR; + if (nc_inq_varname(ncid, 0, name_in)); + if (!strcmp(name_in, norm_utf8)) ERR; + if (nc_close(ncid)) ERR; + /* Reopen the file and check again. */ + if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; + if (nc_inq_varname(ncid, 0, name_in)); + if (!strcmp(name_in, norm_utf8)) ERR; + if (nc_close(ncid)) ERR; + } SUMMARIZE_ERR; FINAL_RESULTS; } From 1546b4a91fa8db7c035b11a47cdd8be27cc90dbc Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 30 Mar 2018 11:57:26 -0600 Subject: [PATCH 3/4] added documentation of attribute reserved names to user guide --- docs/guide.dox | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/guide.dox b/docs/guide.dox index 613055aad4..41f26da0fa 100644 --- a/docs/guide.dox +++ b/docs/guide.dox @@ -633,6 +633,17 @@ scalar values are treated as single-element vectors. Conventional attribute names should be used where applicable. New names should be as meaningful as possible. +Some attribute names are reserved by netCDF and cannot be created by the +user. Attepts to create attributes with any of these names will return +a ::NC_ENAMEINUSE error. + +The reserved names are: +- _Format +- _nc3_strict +- _NCProperties +- _IsNetcdf4 +- _SuperblockVersion + The external type of an attribute is specified when it is created. The types permitted for attributes are the same as the netCDF external data types for variables. Attributes with the same name for different From 9b16ec96c1c4ed24b2434f7990164607119512eb Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Fri, 30 Mar 2018 14:13:42 -0600 Subject: [PATCH 4/4] removed duplicate docs --- docs/guide.dox | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/docs/guide.dox b/docs/guide.dox index 41f26da0fa..613055aad4 100644 --- a/docs/guide.dox +++ b/docs/guide.dox @@ -633,17 +633,6 @@ scalar values are treated as single-element vectors. Conventional attribute names should be used where applicable. New names should be as meaningful as possible. -Some attribute names are reserved by netCDF and cannot be created by the -user. Attepts to create attributes with any of these names will return -a ::NC_ENAMEINUSE error. - -The reserved names are: -- _Format -- _nc3_strict -- _NCProperties -- _IsNetcdf4 -- _SuperblockVersion - The external type of an attribute is specified when it is created. The types permitted for attributes are the same as the netCDF external data types for variables. Attributes with the same name for different