endf_format 0.0.4

ENDF-6 Format Rust Library
Documentation
//! Module defining currently defined ENDF Library.
//!
//! ENDF libraries are described in section `0.3.1` aand tables `1-2` of ENDF-6
//! Formats Manual.
//!
//! `ENDF-6 Formats Manual` available at
//! <https://www.nndc.bnl.gov/csewg/docs/endf-manual.pdf>
//!
//! > "A library is a collection of material evaluations from a recognized evaluation group.
//! > Each of these collections is identified by an `NLIB` number."

use std::fmt::{Display, Formatter};

/// ENDF library.
///
/// > "A library is a collection of material evaluations from a recognized evaluation group.
/// > Each of these collections is identified by an `NLIB` number."
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[non_exhaustive]
pub enum Library {
    EndfB,
    EndfA,
    Jeff,
    Eff,
    EndfBHe,
    Cendl,
    Jendl,
    Tendl,
    Rosfond,
    SG23,
    IndlV,
    IndlA,
    Fendl,
    Irdf,
    BrondIAEA,
    Ingdb90,
    FendlA,
    BrondOriginal,
}

impl Library {
    /// Returns the library corresponding to specified `NLIB` if available.
    pub fn from_nlib(nlib: u32) -> Option<Self> {
        match nlib {
            0 => Some(Self::EndfB),
            1 => Some(Self::EndfA),
            2 => Some(Self::Jeff),
            3 => Some(Self::Eff),
            4 => Some(Self::EndfBHe),
            5 => Some(Self::Cendl),
            6 => Some(Self::Jendl),
            17 => Some(Self::Tendl),
            18 => Some(Self::Rosfond),
            21 => Some(Self::SG23),
            31 => Some(Self::IndlV),
            32 => Some(Self::IndlA),
            33 => Some(Self::Fendl),
            34 => Some(Self::Irdf),
            35 => Some(Self::BrondIAEA),
            36 => Some(Self::Ingdb90),
            37 => Some(Self::FendlA),
            41 => Some(Self::BrondOriginal),
            _ => None,
        }
    }
    /// Returns the name of the library.
    pub fn name(&self) -> String {
        match self {
            Self::EndfB => "ENDF/B".into(),
            Self::EndfA => "ENDF/A".into(),
            Self::Jeff => "JEFF".into(),
            Self::Eff => "EFF".into(),
            Self::EndfBHe => "ENDF/B".into(),
            Self::Cendl => "CENDL".into(),
            Self::Jendl => "JENDL".into(),
            Self::Tendl => "TENDL".into(),
            Self::Rosfond => "ROSFOND".into(),
            Self::SG23 => "SG-23".into(),
            Self::IndlV => "INDL/V".into(),
            Self::IndlA => "INDL/A".into(),
            Self::Fendl => "FENDL".into(),
            Self::Irdf => "IRDF".into(),
            Self::BrondIAEA => "BROND".into(),
            Self::Ingdb90 => "INGDB-90".into(),
            Self::FendlA => "FENDL/A".into(),
            Self::BrondOriginal => "BROND".into(),
        }
    }

    /// Returbs a short description of the library.
    pub fn description(&self) -> String {
        match self {
            Self::EndfB => "United States Evaluated Nuclear Data File".into(),
            Self::EndfA => "United States Evaluated Nuclear Data File".into(),
            Self::Jeff => "NEA Joint Evaluated Fission and Fusion File (formerly JEF)".into(),
            Self::Eff => "European Fusion File (now part of JEFF)".into(),
            Self::EndfBHe => "High Energy File".into(),
            Self::Cendl => "China Evaluated Nuclear Data Library".into(),
            Self::Jendl => "Japan Evaluated Nuclear Data Library".into(),
            Self::Tendl => "TALYS Evaluated Nuclear Data Library".into(),
            Self::Rosfond => "Russian evaluated neutron data library".into(),
            Self::SG23 => "Fission product library of the Working Party on EvaluationCooperation Subgroup-23 (WPEC-SG23)".into(),
            Self::IndlV => "IAEA Evaluated Neutron Data Library".into(),
            Self::IndlA => "IAEA Nuclear Data Activation Library".into(),
            Self::Fendl => "IAEA Fusion Evaluated Nuclear Data Library".into(),
            Self::Irdf => "IAEA International Reactor Dosimetry File".into(),
            Self::BrondIAEA => "Russian Evaluated Nuclear Data File (IAEA version)".into(),
            Self::Ingdb90 => "Geophysics Data".into(),
            Self::FendlA => "FENDL activation evaluations".into(),
            Self::BrondOriginal => "Russian Evaluated Nuclear Data File (original version)".into(),
        }
    }

    /// Returns the library identifier `NLIB`.
    pub fn nlib(&self) -> u32 {
        match self {
            Self::EndfB => 0,
            Self::EndfA => 1,
            Self::Jeff => 2,
            Self::Eff => 3,
            Self::EndfBHe => 4,
            Self::Cendl => 5,
            Self::Jendl => 6,
            Self::Tendl => 17,
            Self::Rosfond => 18,
            Self::SG23 => 21,
            Self::IndlV => 31,
            Self::IndlA => 32,
            Self::Fendl => 33,
            Self::Irdf => 34,
            Self::BrondIAEA => 35,
            Self::Ingdb90 => 36,
            Self::FendlA => 37,
            Self::BrondOriginal => 41,
        }
    }
}

impl Display for Library {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{}: {} (NLIB = {})",
            self.name(),
            self.description(),
            self.nlib()
        )
    }
}