Skip to content

Commit

Permalink
Merge pull request #102 from richli/add-shuffle-setting
Browse files Browse the repository at this point in the history
Add the shuffle option to the compression method
  • Loading branch information
magnusuMET authored Feb 17, 2023
2 parents e24d4c2 + f8a1486 commit d4034d7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
7 changes: 5 additions & 2 deletions netcdf/src/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,19 @@ impl<'g> VariableMut<'g> {
/// compression (good for CPU bound tasks), and 9 providing the
/// highest compression level (good for memory bound tasks)
///
/// `shuffle` enables a filter to reorder bytes before compressing, which
/// can improve compression ratios
///
/// # Errors
///
/// Not a `netcdf-4` file or `deflate_level` not valid
pub fn compression(&mut self, deflate_level: nc_type) -> error::Result<()> {
pub fn compression(&mut self, deflate_level: nc_type, shuffle: bool) -> error::Result<()> {
unsafe {
error::checked(super::with_lock(|| {
nc_def_var_deflate(
self.ncid,
self.varid,
<_>::from(false),
shuffle.into(),
<_>::from(true),
deflate_level,
)
Expand Down
2 changes: 1 addition & 1 deletion netcdf/tests/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn find_variable() {

for mut var in group.variables_mut() {
if var.dimensions().len() > 0 {
var.compression(3).unwrap();
var.compression(3, false).unwrap();
}
if var.name() == "z" {
var.chunking(&[1]).unwrap();
Expand Down
7 changes: 4 additions & 3 deletions netcdf/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ fn use_compression_chunking() {
file.add_dimension("x", 10).unwrap();

let var = &mut file.add_variable::<i32>("compressed", &["x"]).unwrap();
var.compression(5).unwrap();
var.compression(5, false).unwrap();
var.chunking(&[5]).unwrap();

let v = vec![0i32; 10];
Expand All @@ -863,7 +863,7 @@ fn use_compression_chunking() {
let var = &mut file
.add_variable::<i32>("compressed2", &["x", "x"])
.unwrap();
var.compression(9).unwrap();
var.compression(9, true).unwrap();
var.chunking(&[5, 5]).unwrap();
var.put_values(&[1i32, 2, 3, 4, 5, 6, 7, 8, 9, 10], (..10, ..1))
.unwrap();
Expand Down Expand Up @@ -903,7 +903,8 @@ fn set_compression_all_variables_in_a_group() {
.expect("Could not create variable");

for mut var in file.variables_mut() {
var.compression(9).expect("Could not set compression level");
var.compression(9, false)
.expect("Could not set compression level");
}
}

Expand Down

0 comments on commit d4034d7

Please sign in to comment.