mirror of
https://github.com/dnlbauer/WHAM.git
synced 2026-09-10 22:25:31 +00:00
window files are now relative to metadata.dat
This commit is contained in:
23
src/io.rs
23
src/io.rs
@@ -7,6 +7,16 @@ use std::io::BufReader;
|
|||||||
use k_B;
|
use k_B;
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::option::Option;
|
use std::option::Option;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
// Returns the path to path2 relative to path1
|
||||||
|
// path1: "path/to/file.dat"
|
||||||
|
// path2: "another_file.dat"
|
||||||
|
// => result = path/to/another_file.dat
|
||||||
|
fn get_relative_path(path1: &str, path2: &str) -> String {
|
||||||
|
let path1 = Path::new(path1);
|
||||||
|
path1.parent().unwrap().join(path2).to_str().unwrap().to_string()
|
||||||
|
}
|
||||||
|
|
||||||
// Read input data into a histogram set by iterating over input files
|
// Read input data into a histogram set by iterating over input files
|
||||||
// given in the metadata file
|
// given in the metadata file
|
||||||
@@ -29,7 +39,7 @@ pub fn read_data(cfg: &Config) -> Option<HistogramSet> {
|
|||||||
}
|
}
|
||||||
let (path, x0, k) = scan_fmt!(&line, "{} {} {}", String, f32, f32);
|
let (path, x0, k) = scan_fmt!(&line, "{} {} {}", String, f32, f32);
|
||||||
|
|
||||||
let path = path.unwrap();
|
let path = get_relative_path(&cfg.metadata_file, &path.unwrap());
|
||||||
match read_window_file(&path, cfg) {
|
match read_window_file(&path, cfg) {
|
||||||
Some(h) => {
|
Some(h) => {
|
||||||
histograms.push(h);
|
histograms.push(h);
|
||||||
@@ -166,4 +176,15 @@ mod tests {
|
|||||||
assert_eq!(cfg.temperature * k_B, hs.kT);
|
assert_eq!(cfg.temperature * k_B, hs.kT);
|
||||||
assert_eq!(2, hs.histograms.len())
|
assert_eq!(2, hs.histograms.len())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn get_relative_path() {
|
||||||
|
let path1 = "path/to/some_file.dat";
|
||||||
|
let path2 = "another_file.dat";
|
||||||
|
let path3 = "subfolder/another_file.dat";
|
||||||
|
let relative2 = super::get_relative_path(&path1, &path2);
|
||||||
|
assert_eq!("path/to/another_file.dat" ,relative2);
|
||||||
|
let relative3 = super::get_relative_path(&path1, &path3);
|
||||||
|
assert_eq!("path/to/subfolder/another_file.dat" ,relative3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user