celestial_pointing/commands/
outmod.rs1use super::{Command, CommandOutput};
2use crate::error::Result;
3use crate::session::Session;
4
5pub struct Outmod;
6
7impl Command for Outmod {
8 fn name(&self) -> &str {
9 "OUTMOD"
10 }
11 fn description(&self) -> &str {
12 "Save model to file"
13 }
14
15 fn execute(&self, session: &mut Session, args: &[&str]) -> Result<CommandOutput> {
16 if args.is_empty() {
17 return Err(crate::error::Error::Parse(
18 "OUTMOD requires a filename".into(),
19 ));
20 }
21 let mut output = String::new();
22 for (name, &coeff) in session
23 .model
24 .term_names()
25 .iter()
26 .zip(session.model.coefficients().iter())
27 {
28 output += &format!("{} {:.6}\n", name, coeff);
29 }
30 output += "END\n";
31 std::fs::write(args[0], &output).map_err(crate::error::Error::Io)?;
32 Ok(CommandOutput::Text(format!("Model saved to {}", args[0])))
33 }
34}