pub struct ThermalAnomaly {
    pub temperaturek: f64,
    pub durationdays: u32,
    pub altitudem: f64,
}

impl ThermalAnomaly {
    pub fn warmingexcessk(&self) -> f64 {
        (self.temperaturek - crate::ONEBARTEMPK).max(0.0)
    }

    pub fn coldexcessk(&self) -> f64 {
        (crate::ONEBARTEMPK - self.temperaturek).max(0.0)
    }

    pub fn methevaportempk() -> f64 {
        90.7
    }

    pub fn dangerlevel(&self) -> &'static str {
        let excess = self.warmingexcessk();
        if excess >= 30.0 {
            "Extreme anomaly"
        } else if excess >= 15.0 {
            "Strong anomaly"
        } else if excess >= 5.0 {
            "Moderate anomaly"
        } else {
            "Normal"
        }
    }

    pub fn methanecondensationpressurepa(temperaturek: f64) -> f64 {
        let tref = 90.7;
        let pref = 11696.0;
        let lhvap = 8520.0;
        let r = sciforge::hub::prelude::constants::R_GAS / crate::mch4();
        pref * (lhvap / r * (1.0 / tref - 1.0 / temperaturek)).exp()
    }
}

pub fn saturationvaporpressuremethanepa(tempk: f64) -> f64 {
    ThermalAnomaly::methanecondensationpressurepa(tempk)
}

pub fn dewpointmethanek(pressure: f64) -> f64 {
    let pref = 11696.0;
    let tref = 90.7;
    let lhvap = 8520.0;
    let r = sciforge::hub::prelude::constants::R_GAS / crate::mch4();
    1.0 / (1.0 / tref - r / lhvap * (pressure / pref).ln())
}
