@@ -4,7 +4,7 @@ use crate::{
4
4
epoch:: epoch_decompose as epoch_decomposition,
5
5
error:: FormattingError ,
6
6
hatanaka:: { NumDiff , TextDiff } ,
7
- observation:: { HeaderFields , Record } ,
7
+ observation:: { HeaderFields , LliFlags , Record } ,
8
8
prelude:: { Observable , SV } ,
9
9
BufWriter ,
10
10
} ;
@@ -62,10 +62,10 @@ impl<const M: usize> CompressorExpert<M> {
62
62
header : & HeaderFields ,
63
63
) -> Result < ( ) , FormattingError > {
64
64
for ( k, v) in record. iter ( ) {
65
- // TODO: epoch kernel reset on phase lock loss ?
66
- //if k.flags.intersects(LliFlags::LOCK_LOSS || LliFlags::HALF_CYCLE_SLIP) {
67
- // self.epoch_compression = false;
68
- // }
65
+ if !k . flag . is_ok ( ) {
66
+ // TODO not 100% correct, verify > 1
67
+ self . epoch_compression = false ;
68
+ }
69
69
70
70
let ( y, m, d, hh, mm, ss, ns) = epoch_decomposition ( k. epoch ) ;
71
71
@@ -78,9 +78,23 @@ impl<const M: usize> CompressorExpert<M> {
78
78
. sorted ( )
79
79
. collect :: < Vec < _ > > ( ) ;
80
80
81
+ if !self . epoch_compression {
82
+ if self . v3 {
83
+ write ! ( w, "> " ) ?;
84
+ } else {
85
+ write ! ( w, "&" ) ?;
86
+ }
87
+ } else {
88
+ if self . v3 {
89
+ write ! ( w, " " ) ?;
90
+ } else {
91
+ write ! ( w, " " ) ?;
92
+ }
93
+ }
94
+
81
95
if self . v3 {
82
96
self . epoch_buf . push_str ( & format ! (
83
- "> {:04} {:02} {:02} {:02} {:02} {:02}.{:07} {}{:3} " ,
97
+ "{:04} {:02} {:02} {:02} {:02} {:02}.{:07} {}{:3} " ,
84
98
y,
85
99
m,
86
100
d,
@@ -93,7 +107,7 @@ impl<const M: usize> CompressorExpert<M> {
93
107
) ) ;
94
108
} else {
95
109
self . epoch_buf . push_str ( & format ! (
96
- "&{:04 } {:02} {:02} {:02} {:02} {:02}.{:07} {}{:3} " ,
110
+ "{:02 } {:02} {:02} {:02} {:02} {:02}.{:07} {}{:3} " ,
97
111
y,
98
112
m,
99
113
d,
@@ -112,11 +126,12 @@ impl<const M: usize> CompressorExpert<M> {
112
126
}
113
127
114
128
// Epoch compression
115
- if self . epoch_compression {
116
- let compressed = self . epoch_diff . compress ( & self . epoch_buf ) ;
117
- writeln ! ( w, "{}" , compressed ) ?;
129
+ if ! self . epoch_compression {
130
+ self . epoch_diff . force_init ( & self . epoch_buf ) ;
131
+ writeln ! ( w, "{}" , self . epoch_buf . trim_end ( ) ) ?;
118
132
} else {
119
- writeln ! ( w, "{}" , self . epoch_buf) ?;
133
+ let compressed = self . epoch_diff . compress ( & self . epoch_buf ) ;
134
+ writeln ! ( w, "{}" , compressed. trim_end( ) ) ?;
120
135
}
121
136
122
137
if let Some ( clk) = v. clock {
@@ -192,7 +207,10 @@ impl<const M: usize> CompressorExpert<M> {
192
207
}
193
208
self . flags_buf . clear ( ) ;
194
209
}
210
+
211
+ // prepare for next epoch
195
212
self . epoch_compression = true ;
213
+ self . epoch_buf . clear ( ) ;
196
214
}
197
215
Ok ( ( ) )
198
216
}
0 commit comments