Skip to content

Commit 05c67d9

Browse files
authored
Merge pull request #1674 from NOAA-GSD/ejh_deflate_bug
now pass 0 for deflate_level if deflate not in use
2 parents 0251ce7 + 9b62159 commit 05c67d9

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

libdispatch/dvarinq.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,6 @@ nc_inq_varnatts(int ncid, int varid, int *nattsp)
258258
/** \ingroup variables
259259
Learn the storage and deflate settings for a variable.
260260
261-
This is a wrapper for nc_inq_var_all().
262-
263261
\param ncid NetCDF or group ID, from a previous call to nc_open(),
264262
nc_create(), nc_def_grp(), or associated inquiry functions such as
265263
nc_inq_ncid().
@@ -274,12 +272,15 @@ function will write a 1 if the deflate filter is turned on for this
274272
variable, and a 0 otherwise. \ref ignored_if_null.
275273
276274
\param deflate_levelp If the deflate filter is in use for this
277-
variable, the deflate_level will be written here. \ref ignored_if_null.
275+
variable, the deflate_level will be written here. If deflate is not in
276+
use, and deflate_levelp is provided, it will get a zero. (This
277+
behavior is expected by the Fortran APIs). \ref ignored_if_null.
278278
279279
\returns ::NC_NOERR No error.
280280
\returns ::NC_ENOTNC4 Not a netCDF-4 file.
281281
\returns ::NC_EBADID Bad ncid.
282282
\returns ::NC_ENOTVAR Invalid variable ID.
283+
\author Ed Hartnett, Dennis Heimbigner
283284
*/
284285
int
285286
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
306307
return NC_EFILTER; /* bad # params */
307308
/* Param[0] should be level */
308309
if(deflate_levelp) *deflate_levelp = (int)params[0];
309-
}
310-
/* also get the shuffle state */
311-
if(!shufflep)
312-
return NC_NOERR;
310+
} else if (deflate_levelp)
311+
*deflate_levelp = 0;
312+
/* also get the shuffle state */
313+
if(!shufflep)
314+
return NC_NOERR;
313315
return ncp->dispatch->inq_var_all(
314316
ncid, varid,
315317
NULL, /*name*/

nc_test4/tst_vars2.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,5 +1578,31 @@ main(int argc, char **argv)
15781578

15791579
}
15801580
SUMMARIZE_ERR;
1581+
#define DIM10_NAME "num_monkeys"
1582+
#define DIM11_NAME "num_hats"
1583+
#define VAR_NAME11 "Silly_Sally"
1584+
#define NDIM2 2
1585+
printf("**** testing deflate_level value when deflate is not in use...");
1586+
{
1587+
int ncid;
1588+
int dimid[NDIM2];
1589+
int varid;
1590+
int deflate_in, deflate_level_in = 99;
1591+
1592+
/* Create a netcdf-4 file. */
1593+
if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR;
1594+
if (nc_def_dim(ncid, DIM10_NAME, NC_UNLIMITED, &dimid[0])) ERR;
1595+
if (nc_def_dim(ncid, DIM11_NAME, NC_UNLIMITED, &dimid[1])) ERR;
1596+
if (nc_def_var(ncid, VAR_NAME11, NC_BYTE, NDIM2, dimid, &varid)) ERR;
1597+
1598+
/* Check the deflate_level. */
1599+
if (nc_inq_var_deflate(ncid, varid, NULL, &deflate_in, &deflate_level_in)) ERR;
1600+
if (deflate_in || deflate_level_in) ERR;
1601+
1602+
/* Close the file. */
1603+
if (nc_close(ncid)) ERR;
1604+
1605+
}
1606+
SUMMARIZE_ERR;
15811607
FINAL_RESULTS;
15821608
}

0 commit comments

Comments
 (0)