doris_rs/header/
antenna.rs

1use crate::{fmt_doris, prelude::FormattingError};
2
3use std::io::{BufWriter, Write};
4
5#[cfg(feature = "serde")]
6use serde::{Deserialize, Serialize};
7
8/// Antenna description
9#[derive(Default, Clone, Debug, PartialEq)]
10#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11pub struct Antenna {
12    /// Name of this [Antenna] model
13    pub model: String,
14
15    /// Serial number
16    pub serial_number: String,
17
18    /// Approximate coordinates of the anntena base
19    pub approx_coordinates: Option<(f64, f64, f64)>,
20
21    /// Optionnal `h` eccentricity (height component),
22    /// referenced to base/reference point, in meter
23    pub height: Option<f64>,
24
25    /// Optionnal `eastern` eccentricity (eastern component),
26    /// referenced to base/reference point, in meter
27    pub eastern: Option<f64>,
28
29    /// Optionnal `northern` eccentricity (northern component),
30    /// referenced to base/reference point, in meter
31    pub northern: Option<f64>,
32}
33
34impl Antenna {
35    /// Formats [Antenna] into [BufWriter]
36    pub(crate) fn format<W: Write>(&self, w: &mut BufWriter<W>) -> Result<(), FormattingError> {
37        writeln!(
38            w,
39            "{}",
40            fmt_doris(
41                &format!("{:<20}{}", self.serial_number, self.model),
42                "ANT # / TYPE"
43            )
44        )?;
45
46        if let Some(coords) = &self.approx_coordinates {
47            writeln!(
48                w,
49                "{}",
50                fmt_doris(
51                    &format!("{:14.4}{:14.4}{:14.4}", coords.0, coords.1, coords.2),
52                    "APPROX POSITION XYZ"
53                )
54            )?;
55        }
56
57        writeln!(
58            w,
59            "{}",
60            fmt_doris(
61                &format!(
62                    "{:14.4}{:14.4}{:14.4}",
63                    self.height.unwrap_or(0.0),
64                    self.eastern.unwrap_or(0.0),
65                    self.northern.unwrap_or(0.0)
66                ),
67                "ANTENNA: DELTA H/E/N"
68            )
69        )?;
70
71        Ok(())
72    }
73
74    /// Sets desired model
75    pub fn with_model(&self, m: &str) -> Self {
76        let mut s = self.clone();
77        s.model = m.to_string();
78        s
79    }
80
81    /// Sets desired Serial Number
82    pub fn with_serial_number(&self, serial_number: &str) -> Self {
83        let mut s = self.clone();
84        s.serial_number = serial_number.to_string();
85        s
86    }
87
88    /// Sets reference/base coordinates (3D)
89    pub fn with_base_coordinates(&self, coords: (f64, f64, f64)) -> Self {
90        let mut s = self.clone();
91        s.approx_coordinates = Some(coords);
92        s
93    }
94
95    /// Sets antenna `h` eccentricity component
96    pub fn with_height(&self, h: f64) -> Self {
97        let mut s = self.clone();
98        s.height = Some(h);
99        s
100    }
101
102    /// Sets antenna `eastern` coordinates component
103    pub fn with_eastern_component(&self, e: f64) -> Self {
104        let mut s = self.clone();
105        s.eastern = Some(e);
106        s
107    }
108
109    /// Sets antenna `northern` coordiantes component
110    pub fn with_northern_component(&self, n: f64) -> Self {
111        let mut s = self.clone();
112        s.northern = Some(n);
113        s
114    }
115}