use hdf5_pure::{File, FileBuilder};
fn main() {
let dir = tempfile::tempdir().expect("temp dir");
let path = dir.path().join("frames.h5");
let rows = 1000usize;
let cols = 4usize;
let data: Vec<f64> = (0..rows * cols).map(|i| i as f64).collect();
let mut builder = FileBuilder::new();
builder
.create_dataset("frames")
.with_f64_data(&data)
.with_shape(&[rows as u64, cols as u64])
.with_chunks(&[64, cols as u64]);
builder.write(&path).expect("write file");
let file = File::open(&path).expect("open");
let ds = file.dataset("frames").expect("open dataset");
let window = ds.read_f64_rows(100, 50).expect("windowed read");
assert_eq!(window.len(), 50 * cols);
println!("read rows 100..150 -> {} elements", window.len());
let n0 = ds.shape().unwrap()[0];
let step = 128u64;
let mut total = 0usize;
for start in (0..n0).step_by(step as usize) {
total += ds.read_f64_rows(start, step).unwrap().len();
}
assert_eq!(total, rows * cols);
let whole = ds.read_f64().unwrap();
let (start, count) = (250usize, 300usize);
let w = ds.read_f64_rows(start as u64, count as u64).unwrap();
assert_eq!(w, whole[start * cols..(start + count) * cols]);
println!("row window matches the whole read sliced to the same rows");
println!("windowed read verified");
}