Commit c5ac6dcf authored by Jakub Klemsa's avatar Jakub Klemsa
Browse files

Load lambda/s_lambda and pi/2^2Delta from YAML.

parent f203db7f
......@@ -42,8 +42,6 @@ fn main() -> Result<(), Box<dyn Error>> {
// load setup
//TODO take setup filename as argument
let stp = Setup::new("setup.yaml")?;
//DBG
println!("(?) ==== SETUP LOAD END ====\n");
// generate all params
#[cfg(feature = "numerical")]
......
......@@ -98,20 +98,16 @@ impl Setup {
// check if setup file exists
if Path::new(setup_filename).is_file() {
println!("(i) Loading setup from '{}' ...", setup_filename);
println!("\n(i) Loading setup from '{}' ...", setup_filename);
// load YAML struct
let yaml_str = fs::read_to_string(setup_filename)?;
let docs = YamlLoader::load_from_str(&yaml_str)?;
let setup_map = &docs[0];
//DBG
println!("(?) setup_map:\n{:?}\n\n", setup_map);
println!("(?) setup_struct:\n{:?}\n\n", stp);
// update setup fields, if they exist in YAML
//WISH it was like this:
// it was like this:
// stp.n_repeat = setup_map["n_repeat"].as_i64().unwrap() as usize;
// but it panics if the output is None
if let Some(n_repeat) = setup_map["n_repeat"].as_i64() {
......@@ -123,18 +119,54 @@ impl Setup {
if let Some(n_top_v_maxes) = setup_map["n_top_v_maxes"].as_i64() {
stp.n_top_v_maxes = n_top_v_maxes as usize;
}
if let Some(v0_corr_yaml) = setup_map["v0_corr"].as_vec() {
if let Some(v0c_vec_yaml) = setup_map["v0_corr"].as_vec() {
let mut v0_corr = vec![];
for v0c_y in v0_corr_yaml {
if let Some(v0c) = v0c_y.as_f64() {
for v0c_yaml in v0c_vec_yaml {
if let Some(v0c) = v0c_yaml.as_f64() {
v0_corr.push(v0c);
}
}
stp.v0_corr = v0_corr;
}
if let Some(lsl_vec_yaml) = setup_map["lambda_s_lambdas"].as_vec() {
let mut lambda_s_lambdas = vec![];
for lsl_ary_yaml in lsl_vec_yaml {
if let Some(lsl_ary_fy) = lsl_ary_yaml.as_vec() {
if lsl_ary_fy.len() == 2 {
if let Some(lambda) = lsl_ary_fy[0].as_i64() {
if let Some(s_lambda) = lsl_ary_fy[1].as_f64() {
lambda_s_lambdas.push((lambda as usize, s_lambda));
}
}
}
}
}
if lambda_s_lambdas.is_empty() {
eprintln!("(!) No valid lambda/s_lambda pairs found under 'lambda_s_lambdas' key in setup YAML file!");
}
stp.lambda_s_lambdas = lambda_s_lambdas;
}
if let Some(pd_vec_yaml) = setup_map["pi_pow_2deltas"].as_vec() {
let mut pi_pow_2deltas = vec![];
for pd_ary_yaml in pd_vec_yaml {
if let Some(pd_ary_fy) = pd_ary_yaml.as_vec() {
if pd_ary_fy.len() == 2 {
if let Some(pi) = pd_ary_fy[0].as_i64() {
if let Some(pow_2delta) = pd_ary_fy[1].as_i64() {
pi_pow_2deltas.push((pi as usize, pow_2delta as usize));
}
}
}
}
}
if pi_pow_2deltas.is_empty() {
eprintln!("(!) No valid pi/pow_2delta pairs found under 'pi_pow_2deltas' key in setup YAML file!");
}
stp.pi_pow_2deltas = pi_pow_2deltas;
}
//DBG
println!("(?) setup_struct:\n{:?}\n\n", stp);
println!(" {:?}", stp);
} else {
eprintln!("(!) Setup file '{}' does not exist.", setup_filename);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment