planetsfactory 0.0.3

Planet factory — classify, build and catalogue planets for any star system: Solar System, TRAPPIST-1, Kepler-90, Proxima Centauri, or fully custom worlds.
Documentation
use std::io::Write;

pub fn write_csv<W: Write>(
    writer: &mut W,
    headers: &[&str],
    rows: &[Vec<f64>],
) -> std::io::Result<()> {
    writeln!(writer, "{}", headers.join(","))?;
    for row in rows {
        let line: Vec<String> = row.iter().map(|v| format!("{:.6e}", v)).collect();
        writeln!(writer, "{}", line.join(","))?;
    }
    Ok(())
}

pub fn write_dat<W: Write>(
    writer: &mut W,
    headers: &[&str],
    rows: &[Vec<f64>],
) -> std::io::Result<()> {
    write!(writer, "#")?;
    for (i, h) in headers.iter().enumerate() {
        if i > 0 {
            write!(writer, "\t")?;
        }
        write!(writer, "{}", h)?;
    }
    writeln!(writer)?;
    for row in rows {
        for (i, v) in row.iter().enumerate() {
            if i > 0 {
                write!(writer, "\t")?;
            }
            write!(writer, "{:.6e}", v)?;
        }
        writeln!(writer)?;
    }
    Ok(())
}