|
| 1 | +use crate::{ |
| 2 | + observation::{ObsKey, Observations}, |
| 3 | + prelude::{Header, Rinex, TimeScale}, |
| 4 | +}; |
| 5 | + |
| 6 | +use qc_traits::{GnssAbsoluteTime, Timeshift}; |
| 7 | + |
| 8 | +use std::collections::BTreeMap; |
| 9 | + |
| 10 | +impl Timeshift for Header { |
| 11 | + fn timeshift(&self, solver: &GnssAbsoluteTime, target: TimeScale) -> Self |
| 12 | + where |
| 13 | + Self: Sized, |
| 14 | + { |
| 15 | + let mut s = self.clone(); |
| 16 | + s.timeshift_mut(solver, target); |
| 17 | + s |
| 18 | + } |
| 19 | + |
| 20 | + fn timeshift_mut(&mut self, solver: &GnssAbsoluteTime, target: TimeScale) { |
| 21 | + if let Some(obs) = &mut self.obs { |
| 22 | + if let Some(epoch) = &mut obs.timeof_first_obs { |
| 23 | + if let Some(converted) = solver.epoch_time_correction(*epoch, target) { |
| 24 | + *epoch = converted; |
| 25 | + } else { |
| 26 | + obs.timeof_first_obs = None; |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + if let Some(epoch) = &mut obs.timeof_last_obs { |
| 31 | + if let Some(converted) = solver.epoch_time_correction(*epoch, target) { |
| 32 | + *epoch = converted; |
| 33 | + } else { |
| 34 | + obs.timeof_last_obs = None; |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +impl Timeshift for Rinex { |
| 42 | + fn timeshift(&self, solver: &GnssAbsoluteTime, target: TimeScale) -> Self |
| 43 | + where |
| 44 | + Self: Sized, |
| 45 | + { |
| 46 | + let mut s = self.clone(); |
| 47 | + s.timeshift_mut(solver, target); |
| 48 | + s |
| 49 | + } |
| 50 | + |
| 51 | + fn timeshift_mut(&mut self, solver: &GnssAbsoluteTime, target: TimeScale) { |
| 52 | + self.header.timeshift_mut(solver, target); |
| 53 | + |
| 54 | + if let Some(obs_rec) = self.record.as_mut_obs() { |
| 55 | + let mut new_rec = BTreeMap::<ObsKey, Observations>::new(); |
| 56 | + |
| 57 | + for (k, values) in obs_rec.iter() { |
| 58 | + if let Some(converted) = solver.epoch_time_correction(k.epoch, target) { |
| 59 | + let mut key = k.clone(); |
| 60 | + key.epoch = converted; |
| 61 | + |
| 62 | + new_rec.insert(key, values.clone()); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + *obs_rec = new_rec; |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments