From 86f75905d9b2b938ce153d06674a7a63cfcf8be7 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Wed, 22 Apr 2020 20:47:26 +0200 Subject: [PATCH] use name of grid in output --- multigrid/src/file.rs | 14 ++++++++------ multigrid/src/main.rs | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/multigrid/src/file.rs b/multigrid/src/file.rs index 7aee9e9..1d4f8cd 100644 --- a/multigrid/src/file.rs +++ b/multigrid/src/file.rs @@ -65,13 +65,15 @@ impl Drop for OutputThread { } #[derive(Debug, Clone)] -pub struct File(hdf5::File); +pub struct File(hdf5::File, Vec); impl File { pub fn create>( path: P, grids: &[sbp::grid::Grid], + names: Vec, ) -> Result> { + assert_eq!(grids.len(), names.len()); let file = hdf5::File::create(path.as_ref())?; let _tds = file .new_dataset::() @@ -79,8 +81,8 @@ impl File { .chunk((1,)) .create("t", (0,))?; - for (i, grid) in grids.iter().enumerate() { - let g = file.create_group(&i.to_string())?; + for (name, grid) in names.iter().zip(grids.iter()) { + let g = file.create_group(name)?; g.link_soft("/t", "t").unwrap(); let add_dim = |name| { @@ -108,7 +110,7 @@ impl File { add_var("e")?; } - Ok(Self(file)) + Ok(Self(file, names)) } pub fn add_timestep( @@ -122,8 +124,8 @@ impl File { tds.resize((tpos + 1,))?; tds.write_slice(&[t], ndarray::s![tpos..tpos + 1])?; - for (i, fnow) in fields.iter().enumerate() { - let g = file.group(&i.to_string())?; + for (groupname, fnow) in self.1.iter().zip(fields.iter()) { + let g = file.group(groupname)?; let (tpos, ny, nx) = { let ds = g.dataset("rho")?; let shape = ds.shape(); diff --git a/multigrid/src/main.rs b/multigrid/src/main.rs index e831ad7..eecb2ab 100644 --- a/multigrid/src/main.rs +++ b/multigrid/src/main.rs @@ -156,7 +156,7 @@ fn main() { let json = json::parse(&filecontents).unwrap(); let vortexparams = json_to_vortex(json["vortex"].clone()); - let (_names, grids, bt, operators) = json_to_grids(json["grids"].clone(), vortexparams); + let (names, grids, bt, operators) = json_to_grids(json["grids"].clone(), vortexparams); let integration_time: Float = json["integration_time"].as_number().unwrap().into(); @@ -197,7 +197,7 @@ fn main() { }) }; - let output = File::create(&opt.output, sys.grids.as_slice()).unwrap(); + let output = File::create(&opt.output, sys.grids.as_slice(), names).unwrap(); let mut output = OutputThread::new(output); let progressbar = progressbar(opt.no_progressbar, ntime);