doris_rs/header/
formatting.rs1use crate::{fmt_comment, fmt_doris, header::Header, prelude::FormattingError};
4
5use std::io::{BufWriter, Write};
6
7impl Header {
8 pub fn format<W: Write>(&self, w: &mut BufWriter<W>) -> Result<(), FormattingError> {
10 writeln!(w, "{:10}.{:02} O D RINEX VERSION / TYPE", self.version.major, self.version.minor)?;
11
12 writeln!(w, "{}", fmt_doris(&self.satellite, "SATELLITE NAME"))?;
13
14 self.format_prog_runby(w)?;
15 self.format_observer_agency(w)?;
16
17 let mut string = format!("D {:10}", self.observables.len());
18
19 for observable in self.observables.iter() {
20 string.push_str(&format!(" {:x}", observable));
21 }
22
23 writeln!(w, "{}", fmt_doris(&string, "SYS / # / OBS TYPES"))?;
24
25 if let Some(time_of_first_obs) = self.time_of_first_observation {
26 writeln!(w, "{}", fmt_doris("", "TIME OF FIRST OBS"))?;
27 }
28
29 if let Some(time_of_last_obs) = self.time_of_last_observation {
30 writeln!(w, "{}", fmt_doris("", "TIME OF LAST OBS"))?;
31 }
32
33 writeln!(
34 w,
35 "{}",
36 fmt_doris(
37 &format!("{:10}", self.ground_stations.len()),
38 "# OF STATIONS"
39 )
40 )?;
41
42 for station in self.ground_stations.iter() {
43 writeln!(
44 w,
45 "{}",
46 fmt_doris(
47 &format!(
48 "D{:02} {} {} {} 3 0",
49 station.code, station.label, station.site, station.domes
50 ),
51 "STATION REFERENCE"
52 )
53 )?;
54 }
55
56 writeln!(w, "{}", fmt_doris("", "END OF HEADER"))?;
57 Ok(())
58 }
59
60 fn format_prog_runby<W: Write>(&self, w: &mut BufWriter<W>) -> Result<(), FormattingError> {
62 let mut string = if let Some(program) = &self.program {
63 format!("{:<20}", program)
64 } else {
65 " ".to_string()
66 };
67
68 if let Some(runby) = &self.run_by {
69 let formatted = format!("{:<20}", runby);
70 string.push_str(&formatted);
71 } else {
72 string.push_str(" ");
73 };
74
75 if let Some(date) = &self.date {
76 string.push_str(date);
77 } else {
78 string.push_str(" ");
79 };
80
81 writeln!(w, "{}", fmt_doris(&string, "PGM / RUN BY / DATE"),)?;
83
84 Ok(())
85 }
86
87 fn format_observer_agency<W: Write>(
89 &self,
90 w: &mut BufWriter<W>,
91 ) -> Result<(), FormattingError> {
92 let mut string = if let Some(observer) = &self.observer {
93 format!("{:<20}", observer)
94 } else {
95 " ".to_string()
96 };
97
98 if let Some(agency) = &self.agency {
99 string.push_str(agency);
100 } else {
101 string.push_str(" ");
102 };
103
104 writeln!(w, "{}", fmt_doris(&string, "OBSERVER / AGENCY"),)?;
105
106 Ok(())
107 }
108
109 fn format_comments<W: Write>(&self, w: &mut BufWriter<W>) -> Result<(), FormattingError> {
111 for comment in self.comments.iter() {
112 writeln!(w, "{}", fmt_comment(comment))?;
113 }
114 Ok(())
115 }
116}