mirror of
https://github.com/dnlbauer/WHAM.git
synced 2026-09-11 06:35:30 +00:00
reuse allocated string for timeseries read
This commit is contained in:
12
src/io.rs
12
src/io.rs
@@ -129,7 +129,7 @@ fn read_window_file(window_file: &str, cfg: &Config) -> Option<Histogram> {
|
|||||||
eprintln!("Failed to read sample data from {}. {}", window_file, x);
|
eprintln!("Failed to read sample data from {}. {}", window_file, x);
|
||||||
process::exit(1)
|
process::exit(1)
|
||||||
});
|
});
|
||||||
let buf = BufReader::new(&f);
|
let mut buf = BufReader::new(&f);
|
||||||
|
|
||||||
// total number of bins is the product of all dimensions length
|
// total number of bins is the product of all dimensions length
|
||||||
let total_bins = cfg.num_bins.iter().fold(1, |s, &x| { s*x });
|
let total_bins = cfg.num_bins.iter().fold(1, |s, &x| { s*x });
|
||||||
@@ -141,9 +141,9 @@ fn read_window_file(window_file: &str, cfg: &Config) -> Option<Histogram> {
|
|||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
// read and parse each timeseries line
|
// read and parse each timeseries line
|
||||||
for l in buf.lines() {
|
let mut line = String::new();
|
||||||
let line = l.unwrap();
|
while buf.read_line(&mut line).unwrap() > 0 {
|
||||||
|
{
|
||||||
// skip comments and empty lines
|
// skip comments and empty lines
|
||||||
if line.starts_with("#") || line.starts_with("@") || line.len() == 0 {
|
if line.starts_with("#") || line.starts_with("@") || line.len() == 0 {
|
||||||
continue;
|
continue;
|
||||||
@@ -160,12 +160,14 @@ fn read_window_file(window_file: &str, cfg: &Config) -> Option<Histogram> {
|
|||||||
if is_in_hist_boundaries(&values, cfg) {
|
if is_in_hist_boundaries(&values, cfg) {
|
||||||
let bin_indeces = (0..cfg.dimens).map(|dimen: usize| {
|
let bin_indeces = (0..cfg.dimens).map(|dimen: usize| {
|
||||||
let val = values[dimen];
|
let val = values[dimen];
|
||||||
((val-cfg.hist_min[dimen]) / bin_width[dimen]) as usize
|
((val - cfg.hist_min[dimen]) / bin_width[dimen]) as usize
|
||||||
}).collect();
|
}).collect();
|
||||||
let index = flat_index(&bin_indeces, &cfg.num_bins);
|
let index = flat_index(&bin_indeces, &cfg.num_bins);
|
||||||
hist[index] += 1.0;
|
hist[index] += 1.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
line.clear();
|
||||||
|
}
|
||||||
|
|
||||||
let num_points: f64 = hist.iter().sum();
|
let num_points: f64 = hist.iter().sum();
|
||||||
if num_points == 0.0 {
|
if num_points == 0.0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user