use hdf5::{File, Result};
use ndarray::Array2;
fn main() -> Result<()> {
let file = File::create("chunking.h5")?;
let (ny, nx) = (100, 100);
let arr = Array2::from_shape_fn((ny, nx), |(j, i)| (1000 * j + i) as f32);
let ds = file
.new_dataset::<f32>()
.chunk((1, ny, nx)) .shape((1.., ny, nx)) .deflate(3)
.create("variable")?;
ds.write_slice(&arr, (0, .., ..))?;
ds.resize((10, ny, nx))?;
ds.write_slice(&arr, (1, .., ..))?;
let chunksize = ds.chunk().unwrap();
assert_eq!(chunksize, &[1, ny, nx]);
let shape = ds.shape();
assert_eq!(shape, &[10, ny, nx]);
for k in 0..shape[0] {
let _arr: Array2<f32> = ds.read_slice((k, .., ..))?;
}
Ok(())
}