1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use std::path::PathBuf;
pub mod cli;
pub mod orbit;
use orbit::calc::models::MODELS;
use orbit::Orbit;
pub type F = f64;
pub const PI: F = std::f64::consts::PI;
pub type I = usize;
const PADDING: usize = 5;
fn main() {
    
    let matches = cli::get_matches();
    
    let model = MODELS[matches.value_of("model").unwrap().parse::<I>().unwrap() - 1];
    
    let n = matches.value_of("n").unwrap().parse::<I>().unwrap();
    
    let h = matches.value_of("h").unwrap().parse::<F>().unwrap();
    
    let output = PathBuf::from(matches.value_of("output").unwrap());
    
    let fields: Vec<&str> = matches.values_of("fields").unwrap().collect();
    
    let files: Vec<&str> = matches.values_of("file(s)").unwrap().collect();
    
    let rev = matches.occurrences_of("rev") != 0;
    
    let sim = matches.occurrences_of("sim") != 0;
    
    let s = if sim {
        matches.value_of("s").unwrap().parse::<I>().unwrap()
    } else {
        0
    };
    println!("\n{:1$}> Parsing the files...", "", PADDING);
    
    let (orbits, log) = Orbit::load(files);
    
    println!("{}", log.format(PADDING + 2));
    
    macro_rules! info {
        () => {
            if rev {
                println!("{:1$}Reverse mode enabled.\n", "", PADDING + 2);
            } else if sim {
                println!("{:1$}Simulation mode enabled.\n", "", PADDING + 2);
            }
        };
    }
    
    if orbits.is_empty() {
        println!("{:1$}> No orbits were parsed. Exiting.", "", PADDING);
    } else if orbits.len() == 1 {
        println!("{:1$}> One orbit was parsed.\n", "", PADDING);
        info!();
    } else {
        println!(
            "{:1$}> {2} orbits were parsed.\n",
            "",
            PADDING,
            orbits.len()
        );
        info!();
    }
    
    for ref mut orbit in orbits {
        if sim {
            println!(
                "{:1$}> Integrating the simulated orbits of {2}...",
                "",
                PADDING,
                orbit.id()
            );
            orbit.simulate(model, &output, &fields, s, n, h);
        } else {
            println!(
                "{:1$}> Integrating the orbit of {2}...",
                "",
                PADDING,
                orbit.id()
            );
            orbit.integrate(model, n, h, rev);
            orbit.write(&output, &fields, false);
        }
    }
    println!();
}