Skip to content

Commit

Permalink
OBS_RINEX formatting: fix tiny issues when formatting header section
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume W. Bres <[email protected]>
  • Loading branch information
gwbres committed Mar 18, 2024
1 parent 754b134 commit acddb91
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
9 changes: 6 additions & 3 deletions rinex/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1610,11 +1610,14 @@ impl Header {
/*
* List of observables
*/
for (constell, observables) in &obs.codes {
for (index, (constell, observables)) in obs.codes.iter().enumerate() {
let mut descriptor = String::new();
descriptor.push_str(&format!("{:x}{:5}", constell, observables.len()));
for observable in observables {
descriptor.push_str(&format!(" {}", observable));
for (i, observable) in observables.iter().enumerate() {
if (i % 13) == 0 && (i > 0) {
descriptor.push_str(&format!(" ")); // TAB
}
descriptor.push_str(&format!(" {}", observable)); // TAB
}
writeln!(f, "{}", fmt_rinex(&descriptor, "SYS / # / OBS TYPES"))?;
}
Expand Down
21 changes: 15 additions & 6 deletions rinex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,9 @@ pub(crate) fn fmt_rinex(content: &str, marker: &str) -> String {
for i in 0..nb_lines {
let start_off = i * 60;
let end_off = std::cmp::min(start_off + 60, content.len());
string.push_str(&format!(
"{:<padding$}{}",
&content[start_off..end_off],
marker,
padding = 60
));
let chunk = &content[start_off..end_off];
let len = chunk.len();
string.push_str(&format!("{:<padding$}{}", chunk, marker, padding = 60));
if i < nb_lines - 1 {
string.push('\n');
}
Expand Down Expand Up @@ -3471,4 +3468,16 @@ mod test {
}
}
}
#[test]
fn fmt_observables_v3() {
for (desc, expected) in [
("R 9 C1C L1C S1C C2C C2P L2C L2P S2C S2P",
"R 9 C1C L1C S1C C2C C2P L2C L2P S2C S2P SYS / # / OBS TYPES"),
("G 18 C1C L1C S1C C2P C2W C2S C2L C2X L2P L2W L2S L2L L2X S2P S2W S2S S2L S2X",
"G 18 C1C L1C S1C C2P C2W C2S C2L C2X L2P L2W L2S L2L L2X SYS / # / OBS TYPES
S2P S2W S2S S2L S2X SYS / # / OBS TYPES"),
] {
assert_eq!(fmt_rinex(desc, "SYS / # / OBS TYPES"), expected);
}
}
}
2 changes: 1 addition & 1 deletion rinex/src/tests/production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod test {
use crate::*;
use std::path::Path;
fn testbench(path: &str) {
// parse this file
println!("running on \"{}\"", path);
let rnx = Rinex::from_file(path).unwrap(); // already tested elsewhere
let tmp_path = format!("test-{}.rnx", random_name(5));
assert!(rnx.to_file(&tmp_path).is_ok()); // test writer
Expand Down

0 comments on commit acddb91

Please sign in to comment.