mod formatting;
mod parsing;
mod antenna;
mod receiver;
mod version;
use itertools::Itertools;
use std::collections::HashMap;
use crate::{
prelude::{Duration, Epoch, GroundStation, Observable, COSPAR},
Comments,
};
#[cfg(doc)]
use crate::prelude::Record;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
pub use antenna::Antenna;
pub use receiver::Receiver;
pub use version::Version;
#[derive(Clone, Debug, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Header {
pub version: Version,
pub comments: Comments,
pub satellite: String,
pub program: Option<String>,
pub run_by: Option<String>,
pub date: Option<String>,
pub observer: Option<String>,
pub agency: Option<String>,
pub cospar: Option<COSPAR>,
pub receiver: Option<Receiver>,
pub antenna: Option<Antenna>,
pub license: Option<String>,
pub doi: Option<String>,
pub l1_l2_date_offset: Duration,
pub observables: Vec<Observable>,
pub scaling_factors: HashMap<Observable, f64>,
pub ground_stations: Vec<GroundStation>,
pub time_of_first_observation: Option<Epoch>,
pub time_of_last_observation: Option<Epoch>,
}
impl Header {
pub fn ground_station(&self, station_code: u16) -> Option<GroundStation> {
self.ground_stations
.iter()
.filter(|station| station.code == station_code)
.reduce(|k, _| k)
.cloned()
}
pub(crate) fn format_pkg_version(version: &str) -> String {
version
.split('.')
.enumerate()
.filter_map(|(nth, v)| {
if nth < 2 {
Some(v.to_string())
} else if nth == 2 {
Some(
v.split('-')
.filter_map(|v| {
if v == "rc" {
Some("rc".to_string())
} else {
let mut s = String::new();
s.push_str(&v[0..1]);
Some(s)
}
})
.join(""),
)
} else {
None
}
})
.join(".")
}
pub(crate) fn merge_comment(pkg_version: &str, timestamp: Epoch) -> String {
let formatted_version = Self::format_pkg_version(pkg_version);
let (y, m, d, hh, mm, ss, _) = timestamp.to_gregorian_utc();
format!(
"doris-rs v{} {:>width$} {}{:02}{:02} {:02}{:02}{:02} {:x}",
formatted_version,
"FILE MERGE",
y,
m,
d,
hh,
mm,
ss,
timestamp.time_scale,
width = 19 - formatted_version.len(),
)
}
pub fn with_version(&self, version: Version) -> Self {
let mut s = self.clone();
s.version = version;
s
}
pub fn with_run_by(&self, run_by: &str) -> Self {
let mut s = self.clone();
s.run_by = Some(run_by.to_string());
s
}
pub fn with_receiver(&self, receiver: Receiver) -> Self {
let mut s = self.clone();
s.receiver = Some(receiver);
s
}
pub fn push_comment(&mut self, comment: &str) {
self.comments.push(comment.to_string());
}
pub fn with_comment(&self, comment: &str) -> Self {
let mut s = self.clone();
s.comments.push(comment.to_string());
s
}
}