use name of grid in output

This commit is contained in:
Magnus Ulimoen 2020-04-22 20:47:26 +02:00
parent 6fe4e1460f
commit 86f75905d9
2 changed files with 10 additions and 8 deletions

View File

@ -65,13 +65,15 @@ impl Drop for OutputThread {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct File(hdf5::File); pub struct File(hdf5::File, Vec<String>);
impl File { impl File {
pub fn create<P: AsRef<std::path::Path>>( pub fn create<P: AsRef<std::path::Path>>(
path: P, path: P,
grids: &[sbp::grid::Grid], grids: &[sbp::grid::Grid],
names: Vec<String>,
) -> Result<Self, Box<dyn std::error::Error>> { ) -> Result<Self, Box<dyn std::error::Error>> {
assert_eq!(grids.len(), names.len());
let file = hdf5::File::create(path.as_ref())?; let file = hdf5::File::create(path.as_ref())?;
let _tds = file let _tds = file
.new_dataset::<u64>() .new_dataset::<u64>()
@ -79,8 +81,8 @@ impl File {
.chunk((1,)) .chunk((1,))
.create("t", (0,))?; .create("t", (0,))?;
for (i, grid) in grids.iter().enumerate() { for (name, grid) in names.iter().zip(grids.iter()) {
let g = file.create_group(&i.to_string())?; let g = file.create_group(name)?;
g.link_soft("/t", "t").unwrap(); g.link_soft("/t", "t").unwrap();
let add_dim = |name| { let add_dim = |name| {
@ -108,7 +110,7 @@ impl File {
add_var("e")?; add_var("e")?;
} }
Ok(Self(file)) Ok(Self(file, names))
} }
pub fn add_timestep( pub fn add_timestep(
@ -122,8 +124,8 @@ impl File {
tds.resize((tpos + 1,))?; tds.resize((tpos + 1,))?;
tds.write_slice(&[t], ndarray::s![tpos..tpos + 1])?; tds.write_slice(&[t], ndarray::s![tpos..tpos + 1])?;
for (i, fnow) in fields.iter().enumerate() { for (groupname, fnow) in self.1.iter().zip(fields.iter()) {
let g = file.group(&i.to_string())?; let g = file.group(groupname)?;
let (tpos, ny, nx) = { let (tpos, ny, nx) = {
let ds = g.dataset("rho")?; let ds = g.dataset("rho")?;
let shape = ds.shape(); let shape = ds.shape();

View File

@ -156,7 +156,7 @@ fn main() {
let json = json::parse(&filecontents).unwrap(); let json = json::parse(&filecontents).unwrap();
let vortexparams = json_to_vortex(json["vortex"].clone()); 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(); 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 mut output = OutputThread::new(output);
let progressbar = progressbar(opt.no_progressbar, ntime); let progressbar = progressbar(opt.no_progressbar, ntime);