From 7ae3d7554e8add126784d74d1d7262ea7d840c95 Mon Sep 17 00:00:00 2001 From: "Guillaume W. Bres" Date: Fri, 29 Sep 2023 16:58:02 +0200 Subject: [PATCH] test timescale validity, for both crinex and obsdata Signed-off-by: Guillaume W. Bres --- rinex/src/header.rs | 24 +++++++++++++++++++++-- rinex/src/observation/record.rs | 3 +-- rinex/src/tests/parsing.rs | 34 ++++++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/rinex/src/header.rs b/rinex/src/header.rs index 105a0a84a..218a1e59c 100644 --- a/rinex/src/header.rs +++ b/rinex/src/header.rs @@ -801,10 +801,30 @@ impl Header { // {}, + Some(c) => { + // in case of OLD RINEX : fixed constellation + // use that information, as it may be omitted in the TIME OF OBS header + time_of_first_obs.time_scale = c + .to_timescale() + .ok_or(ParsingError::TimescaleParsing(c.to_string()))?; + }, + } observation = observation.with_time_of_first_obs(time_of_first_obs); } else if marker.contains("TIME OF LAST OBS") { - let time_of_last_obs = Self::parse_time_of_obs(content)?; + let mut time_of_last_obs = Self::parse_time_of_obs(content)?; + match constellation { + Some(Constellation::Mixed) | None => {}, + Some(c) => { + // in case of OLD RINEX : fixed constellation + // use that information, as it may be omitted in the TIME OF OBS header + time_of_last_obs.time_scale = c + .to_timescale() + .ok_or(ParsingError::TimescaleParsing(c.to_string()))?; + }, + } observation = observation.with_time_of_last_obs(time_of_last_obs); } else if marker.contains("TYPES OF OBS") { // these observations can serve both Observation & Meteo RINEX diff --git a/rinex/src/observation/record.rs b/rinex/src/observation/record.rs index 115bead35..a05d3c503 100644 --- a/rinex/src/observation/record.rs +++ b/rinex/src/observation/record.rs @@ -156,8 +156,7 @@ pub(crate) fn is_new_epoch(line: &str, v: Version) -> bool { } } -/// Builds `Record` entry for `ObservationData` -/// from given epoch content +/// Builds `Record` entry for `ObservationData` from given epoch content pub(crate) fn parse_epoch( header: &Header, content: &str, diff --git a/rinex/src/tests/parsing.rs b/rinex/src/tests/parsing.rs index d5760f5d9..d419bccd7 100644 --- a/rinex/src/tests/parsing.rs +++ b/rinex/src/tests/parsing.rs @@ -177,14 +177,39 @@ mod test { } } }, - "OBS" => { + "CRNX" | "OBS" => { assert!(rinex.header.obs.is_some()); + let obs_header = rinex.header.obs.clone().unwrap(); + assert!(rinex.is_observation_rinex()); assert!(rinex.epoch().count() > 0); // all files have content assert!(rinex.observation().count() > 0); // all files have content /* - * test interpreted time scale + * test timescale validity */ + for ((e, _), _) in rinex.observation() { + let ts = e.time_scale; + if let Some(e0) = obs_header.time_of_first_obs { + assert!( + e0.time_scale == ts, + "interpreted wrong timescale: expecting \"{}\", got \"{}\"", + e0.time_scale, + ts + ); + } else { + match rinex.header.constellation { + Some(Constellation::Mixed) | None => {}, // can't test + Some(c) => { + let timescale = c.to_timescale().unwrap(); + assert!(ts == timescale, + "interpreted wrong timescale: expecting \"{}\", got \"{}\"", + timescale, + ts + ); + }, + } + } + } /* let gf = rinex.observation_gf_combinations(); let nl = rinex.observation_nl_combinations(); @@ -211,11 +236,6 @@ mod test { assert_eq!(wl_combinations, mw_combinations); */ }, - "CRNX" => { - assert!(rinex.header.obs.is_some()); - assert!(rinex.is_observation_rinex()); - assert!(rinex.epoch().count() > 0); // all files have content - }, "MET" => { assert!(rinex.is_meteo_rinex()); assert!(rinex.epoch().count() > 0); // all files have content