Merge pull request #1674 from NOAA-GSD/ejh_deflate_bug

now pass 0 for deflate_level if deflate not in use
This commit is contained in:
Ward Fisher 2020-03-18 16:47:03 -06:00 committed by GitHub
commit 05c67d9421
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 7 deletions

View File

@ -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*/

View File

@ -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;
}