Commit 47ac3c2a authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Added support for szip compression with NetCDF 4.7.4.

parent 39dc1cba
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
* using CGRIBEX library version 1.9.5 * using CGRIBEX library version 1.9.5
* Version 1.9.9 released * Version 1.9.9 released
2020-08-25 Uwe Schulzweida
* Added support for szip compression with NetCDF 4.7.4
2020-08-24 Uwe Schulzweida 2020-08-24 Uwe Schulzweida
* Renamed default MPIMET institute longname to <Max Planck Institute for Meteorology> * Renamed default MPIMET institute longname to <Max Planck Institute for Meteorology>
......
...@@ -21,15 +21,15 @@ void cdfDefVarDeflate(int ncid, int ncvarID, int deflate_level) ...@@ -21,15 +21,15 @@ void cdfDefVarDeflate(int ncid, int ncvarID, int deflate_level)
// Set chunking, shuffle, and deflate. // Set chunking, shuffle, and deflate.
const int shuffle = 1, deflate = 1; const int shuffle = 1, deflate = 1;
if ( deflate_level < 1 || deflate_level > 9 ) deflate_level = 1; if (deflate_level < 1 || deflate_level > 9) deflate_level = 1;
if ( (retval = nc_def_var_deflate(ncid, ncvarID, shuffle, deflate, deflate_level)) ) if ((retval = nc_def_var_deflate(ncid, ncvarID, shuffle, deflate, deflate_level)))
{ {
Error("nc_def_var_deflate failed, status = %d", retval); Error("nc_def_var_deflate failed, status = %d", retval);
} }
#else #else
static bool lwarn = true; static bool lwarn = true;
if ( lwarn ) if (lwarn)
{ {
lwarn = false; lwarn = false;
Warning("Deflate compression failed, NetCDF4 not available!"); Warning("Deflate compression failed, NetCDF4 not available!");
...@@ -37,6 +37,33 @@ void cdfDefVarDeflate(int ncid, int ncvarID, int deflate_level) ...@@ -37,6 +37,33 @@ void cdfDefVarDeflate(int ncid, int ncvarID, int deflate_level)
#endif #endif
} }
void cdfDefVarSzip(int ncid, int ncvarID, int pixels_per_block)
{
#ifdef HAVE_NC4SZLIB
// Set options_mask.
/*
H5_SZIP_ALLOW_K13_OPTION_MASK 1
H5_SZIP_CHIP_OPTION_MASK 2
H5_SZIP_EC_OPTION_MASK 4
H5_SZIP_NN_OPTION_MASK 32
H5_SZIP_ALL_MASKS (H5_SZIP_CHIP_OPTION_MASK|H5_SZIP_EC_OPTION_MASK|H5_SZIP_NN_OPTION_MASK)
*/
int options_mask = 38;
int retval;
if ((retval = nc_def_var_szip(ncid, ncvarID, options_mask, pixels_per_block)))
{
Error("nc_def_var_szip failed, status = %d", retval);
}
#else
static bool lwarn = true;
if (lwarn)
{
lwarn = false;
Warning("Szip compression failed, NetCDF4/szlib not available!");
}
#endif
}
#ifdef HAVE_NETCDF4 #ifdef HAVE_NETCDF4
static static
nc_type cdfTypeComplexFloat(stream_t *streamptr) nc_type cdfTypeComplexFloat(stream_t *streamptr)
...@@ -378,7 +405,22 @@ int nc_grid_index(stream_t *streamptr, int gridID) ...@@ -378,7 +405,22 @@ int nc_grid_index(stream_t *streamptr, int gridID)
} }
static static
void cdfDefVarCompression(const stream_t *streamptr, int ncvarID, bool lchunk) int xtype2ppb(nc_type xtype)
{
int ppb = 32;
if (xtype == NC_BYTE) ppb = 8;
else if (xtype == NC_SHORT) ppb = 16;
#ifdef HAVE_NETCDF4
else if (xtype == NC_UBYTE) ppb = 8;
else if (xtype == NC_USHORT) ppb = 16;
#endif
return ppb;
}
static
void cdfDefVarCompression(const stream_t *streamptr, int ncvarID, bool lchunk, nc_type xtype)
{ {
if ( streamptr->comptype == CDI_COMPRESS_ZIP ) if ( streamptr->comptype == CDI_COMPRESS_ZIP )
{ {
...@@ -399,6 +441,25 @@ void cdfDefVarCompression(const stream_t *streamptr, int ncvarID, bool lchunk) ...@@ -399,6 +441,25 @@ void cdfDefVarCompression(const stream_t *streamptr, int ncvarID, bool lchunk)
} }
} }
} }
else if ( streamptr->comptype == CDI_COMPRESS_SZIP )
{
if ( lchunk && (streamptr->filetype == CDI_FILETYPE_NC4 || streamptr->filetype == CDI_FILETYPE_NC4C) )
{
cdfDefVarSzip(streamptr->fileID, ncvarID, xtype2ppb(xtype));
}
else
{
if ( lchunk )
{
static bool lwarn = true;
if ( lwarn )
{
lwarn = false;
Warning("SZIP compression is only available for NetCDF4!");
}
}
}
}
} }
static static
...@@ -808,11 +869,11 @@ int cdfDefVar(stream_t *streamptr, int varID) ...@@ -808,11 +869,11 @@ int cdfDefVar(stream_t *streamptr, int varID)
cdf_def_var(fileID, name, xtype, ndims, dims, &ncvarID); cdf_def_var(fileID, name, xtype, ndims, dims, &ncvarID);
#ifdef HAVE_NETCDF4 #ifdef HAVE_NETCDF4
if ( lchunk && (streamptr->filetype == CDI_FILETYPE_NC4 || streamptr->filetype == CDI_FILETYPE_NC4C) ) if (lchunk && (streamptr->filetype == CDI_FILETYPE_NC4 || streamptr->filetype == CDI_FILETYPE_NC4C))
cdf_def_var_chunking(fileID, ncvarID, NC_CHUNKED, chunks); cdf_def_var_chunking(fileID, ncvarID, NC_CHUNKED, chunks);
#endif #endif
cdfDefVarCompression(streamptr, ncvarID, lchunk); cdfDefVarCompression(streamptr, ncvarID, lchunk, xtype);
if ( *stdname ) cdf_put_att_text(fileID, ncvarID, "standard_name", strlen(stdname), stdname); if ( *stdname ) cdf_put_att_text(fileID, ncvarID, "standard_name", strlen(stdname), stdname);
if ( *longname ) cdf_put_att_text(fileID, ncvarID, "long_name", strlen(longname), longname); if ( *longname ) cdf_put_att_text(fileID, ncvarID, "long_name", strlen(longname), longname);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment