doris_rs/record/
flag.rs

1use crate::error::ParsingError;
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6/// [EpochFlag] is attached to DORIS epochs,
7/// describing sampling conditions and attached data.
8#[derive(Copy, Default, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
9#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10pub enum EpochFlag {
11    /// Epoch is OK (sane)
12    #[default]
13    OK,
14
15    /// Power failure since previous epoch
16    PowerFailure,
17
18    /// Special event: antenna being moved since previous measurement
19    AntennaBeingMoved,
20
21    /// Special event: new site occupation (marks end of kinematic data)
22    NewSiteEndofKinematics,
23
24    /// Header information is to follow (not actual measurements)
25    HeaderDataFollowing,
26
27    /// External event (other)
28    ExternalEvent,
29}
30
31impl std::str::FromStr for EpochFlag {
32    type Err = ParsingError;
33
34    /// Parses [EpochFlag] from standard values.    
35    fn from_str(s: &str) -> Result<Self, Self::Err> {
36        match s {
37            "0" => Ok(Self::OK),
38            "1" => Ok(Self::PowerFailure),
39            "2" => Ok(Self::AntennaBeingMoved),
40            "3" => Ok(Self::NewSiteEndofKinematics),
41            "4" => Ok(Self::HeaderDataFollowing),
42            "5" => Ok(Self::ExternalEvent),
43            _ => Err(ParsingError::EpochFlag),
44        }
45    }
46}
47
48impl std::fmt::Display for EpochFlag {
49    /// Formats [EpochFlag] according to standards.
50    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
51        match self {
52            Self::OK => "0".fmt(f),
53            Self::PowerFailure => "1".fmt(f),
54            Self::AntennaBeingMoved => "2".fmt(f),
55            Self::NewSiteEndofKinematics => "3".fmt(f),
56            Self::HeaderDataFollowing => "4".fmt(f),
57            Self::ExternalEvent => "5".fmt(f),
58        }
59    }
60}