Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
libcdi
Commits
47ac3c2a
Commit
47ac3c2a
authored
Aug 25, 2020
by
Uwe Schulzweida
Browse files
Added support for szip compression with NetCDF 4.7.4.
parent
39dc1cba
Changes
2
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
47ac3c2a
...
...
@@ -3,6 +3,10 @@
* using CGRIBEX library version 1.9.5
* 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
* Renamed default MPIMET institute longname to <Max Planck Institute for Meteorology>
...
...
src/cdf_write.c
View file @
47ac3c2a
...
...
@@ -21,15 +21,15 @@ void cdfDefVarDeflate(int ncid, int ncvarID, int deflate_level)
// Set chunking, shuffle, and deflate.
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
);
}
#else
static
bool
lwarn
=
true
;
if
(
lwarn
)
if
(
lwarn
)
{
lwarn
=
false
;
Warning
(
"Deflate compression failed, NetCDF4 not available!"
);
...
...
@@ -37,6 +37,33 @@ void cdfDefVarDeflate(int ncid, int ncvarID, int deflate_level)
#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
static
nc_type
cdfTypeComplexFloat
(
stream_t
*
streamptr
)
...
...
@@ -378,7 +405,22 @@ int nc_grid_index(stream_t *streamptr, int gridID)
}
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
)
{
...
...
@@ -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
...
...
@@ -808,11 +869,11 @@ int cdfDefVar(stream_t *streamptr, int varID)
cdf_def_var
(
fileID
,
name
,
xtype
,
ndims
,
dims
,
&
ncvarID
);
#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
);
#endif
cdfDefVarCompression
(
streamptr
,
ncvarID
,
lchunk
);
cdfDefVarCompression
(
streamptr
,
ncvarID
,
lchunk
,
xtype
);
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
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment