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
extern crate bacon_sci;
extern crate crossbeam;
extern crate csv;
extern crate rayon;
use crate::errors::NyxError;
use crate::io::formatter::StateFormatter;
use crate::{Orbit, Spacecraft};
use std::fs::File;
pub mod ui;
pub mod trajectory;
mod events;
pub use events::{Event, EventEvaluator};
pub mod targeter;
pub type ScTraj = trajectory::Traj<Spacecraft>;
pub type Ephemeris = trajectory::Traj<Orbit>;
mod param;
pub use param::StateParameter;
mod target_variable;
pub use target_variable::{Variable, Vary};
pub trait MdHdlr<StateType: Copy>: Send + Sync {
fn handle(&mut self, state: &StateType);
}
pub struct OrbitStateOutput {
csv_out: csv::Writer<File>,
fmtr: StateFormatter,
}
impl OrbitStateOutput {
pub fn new(fmtr: StateFormatter) -> Result<Self, NyxError> {
match csv::Writer::from_path(fmtr.filename.clone()) {
Ok(mut wtr) => {
wtr.serialize(&fmtr.headers)
.expect("could not write headers");
info!("Saving output to {}", fmtr.filename);
Ok(Self { csv_out: wtr, fmtr })
}
Err(e) => Err(NyxError::ExportError(e.to_string())),
}
}
}
impl MdHdlr<Spacecraft> for OrbitStateOutput {
fn handle(&mut self, state: &Spacecraft) {
self.csv_out
.serialize(self.fmtr.fmt(&state.orbit))
.expect("could not format state");
}
}
impl MdHdlr<Orbit> for OrbitStateOutput {
fn handle(&mut self, state: &Orbit) {
self.csv_out
.serialize(self.fmtr.fmt(&state))
.expect("could not format state");
}
}