create_hdf5_with_structure

Function create_hdf5_with_structure 

Source
pub fn create_hdf5_with_structure<P, F>(path: P, builder: F) -> Result<()>
where P: AsRef<Path>, F: FnOnce(&mut HDF5File) -> Result<()>,
Expand description

Create an HDF5 file with groups and attributes

§Arguments

  • path - Path to the HDF5 file
  • builder - Function to build the file structure

§Example

use scirs2_io::hdf5::{create_hdf5_with_structure, AttributeValue};
use scirs2_core::ndarray::array;

create_hdf5_with_structure("structured.h5", |file| {
    let root = file.root_mut();
     
    // Create groups
    let experiment = root.create_group("experiment");
    experiment.set_attribute("date", AttributeValue::String("2024-01-01".to_string()));
    experiment.set_attribute("temperature", AttributeValue::Float(25.0));
     
    // Add datasets
    let data = array![[1.0, 2.0], [3.0, 4.0]];
    file.create_dataset_from_array("experiment/measurements", &data, None)?;
     
    Ok(())
})?;