Repository: Unidata/netcdf-c (c)

Issue:
nc_inq_var_deflate() no longer returns 0 for deflate_level when deflate is not in use
Although there was no test for this in the C library, netcdf-fortran tests depend on 0 being returned for deflate_level when deflate is not in use. This used to be the case, but is no longer happening. 

I will submit a PR shortly.

Pull request:
now pass 0 for deflate_level if deflate not in use
Fixes #1673 

Patch:
diff --git a/libdispatch/dvarinq.c b/libdispatch/dvarinq.c
index 50db02a86..caad7e7b8 100644
--- a/libdispatch/dvarinq.c
+++ b/libdispatch/dvarinq.c
@@ -258,8 +258,6 @@ nc_inq_varnatts(int ncid, int varid, int *nattsp)
 /** \ingroup variables
 Learn the storage and deflate settings for a variable.
 
-This is a wrapper for nc_inq_var_all().
-
 \param ncid NetCDF or group ID, from a previous call to nc_open(),
 nc_create(), nc_def_grp(), or associated inquiry functions such as
 nc_inq_ncid().
@@ -274,12 +272,15 @@ function will write a 1 if the deflate filter is turned on for this
 variable, and a 0 otherwise. \ref ignored_if_null.
 
 \param deflate_levelp If the deflate filter is in use for this
-variable, the deflate_level will be written here. \ref ignored_if_null.
+variable, the deflate_level will be written here. If deflate is not in
+use, and deflate_levelp is provided, it will get a zero. (This
+behavior is expected by the Fortran APIs). \ref ignored_if_null.
 
 \returns ::NC_NOERR No error.
 \returns ::NC_ENOTNC4 Not a netCDF-4 file.
 \returns ::NC_EBADID Bad ncid.
 \returns ::NC_ENOTVAR Invalid variable ID.
+\author Ed Hartnett, Dennis Heimbigner
 */
 int
 nc_inq_var_deflate(int ncid, int varid, int *shufflep, int *deflatep, int *deflate_levelp)
@@ -306,10 +307,11 @@ nc_inq_var_deflate(int ncid, int varid, int *shufflep, int *deflatep, int *defla
 	    return NC_EFILTER; /* bad # params */
 	/* Param[0] should be level */
 	if(deflate_levelp) *deflate_levelp = (int)params[0];
-    }
-    /* also get the shuffle state */
-    if(!shufflep)
-	return NC_NOERR;
+   } else if (deflate_levelp)
+       *deflate_levelp = 0;
+   /* also get the shuffle state */
+   if(!shufflep)
+       return NC_NOERR;
    return ncp->dispatch->inq_var_all(
       ncid, varid,
       NULL, /*name*/


Test patch:
diff --git a/nc_test4/tst_vars2.c b/nc_test4/tst_vars2.c
index 2b4b1bc67..d9ef63e38 100644
--- a/nc_test4/tst_vars2.c
+++ b/nc_test4/tst_vars2.c
@@ -1578,5 +1578,31 @@ main(int argc, char **argv)
 
     }
     SUMMARIZE_ERR;
+#define DIM10_NAME "num_monkeys"
+#define DIM11_NAME "num_hats"
+#define VAR_NAME11 "Silly_Sally"
+#define NDIM2 2
+    printf("**** testing deflate_level value when deflate is not in use...");
+    {
+        int ncid;
+        int dimid[NDIM2];
+        int varid;
+	int deflate_in, deflate_level_in = 99;
+
+        /* Create a netcdf-4 file. */
+        if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
+        if (nc_def_dim(ncid, DIM10_NAME, NC_UNLIMITED, &dimid[0])) ERR;
+        if (nc_def_dim(ncid, DIM11_NAME, NC_UNLIMITED, &dimid[1])) ERR;
+        if (nc_def_var(ncid, VAR_NAME11, NC_BYTE, NDIM2, dimid, &varid)) ERR;
+
+	/* Check the deflate_level. */
+        if (nc_inq_var_deflate(ncid, varid, NULL, &deflate_in, &deflate_level_in)) ERR;
+        if (deflate_in || deflate_level_in) ERR;
+
+        /* Close the file. */
+        if (nc_close(ncid)) ERR;
+
+    }
+    SUMMARIZE_ERR;
     FINAL_RESULTS;
 }