1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
//! CGGTTS is the core structure, it comprises a list of Track.
//! Homepage: <https://github.com/gwbres/cggtts>
use thiserror::Error;
use std::str::FromStr;
use scan_fmt::scan_fmt;
use rinex::constellation::Constellation;

use crate::{Track, Delay, delay::SystemDelay, CalibratedDelay};

/// supported `Cggtts` version,
/// non matching input files will be rejected
const CURRENT_RELEASE: &str = "2E";

/// Latest revision date
const LATEST_REVISION_DATE : &str = "2014-02-20";

/// labels in case we provide Ionospheric parameters estimates
const TRACK_LABELS_WITH_IONOSPHERIC_DATA: &str =
"SAT CL MJD STTIME TRKL ELV AZTH REFSV SRSV REFSYS SRSYS DSG IOE MDTR SMDT MDIO SMDI MSIO SMSI ISG FR HC FRC CK";

const TRACK_LABELS_WITHOUT_IONOSPHERIC_DATA: &str =
"SAT CL  MJD  STTIME TRKL ELV AZTH   REFSV      SRSV     REFSYS    SRSYS  DSG IOE MDTR SMDT MDIO SMDI FR HC FRC CK";

#[derive(Clone, PartialEq, Debug)]
/// `Rcvr` describes a GNSS receiver
/// (hardware). Used to describe the
/// GNSS receiver or hardware used to evaluate IMS parameters
pub struct Rcvr {
    /// Manufacturer of this hardware
    pub manufacturer: String,
    /// Type of receiver
    pub recv_type: String,
    /// Receiver's serial number
    pub serial_number: String,
    /// Receiver manufacturing year
    pub year: u16,
    /// Receiver software revision number
    pub release: String,
}

#[derive(Error, Debug)]
pub enum CrcError {
    #[error("failed to compute CRC over non utf8 data")] 
    NonAsciiData(String),
}

/// computes crc for given str content
pub fn calc_crc (content: &str) -> Result<u8, CrcError> {
    match content.is_ascii() {
        true => {
            let mut ck: u8 = 0;
            let mut ptr = content.encode_utf16();
            for _ in 0..ptr.clone().count() {
                ck = ck.wrapping_add(
                    ptr.next()
                    .unwrap()
                    as u8)
            }
            Ok(ck)
        },
        false => return Err(CrcError::NonAsciiData(String::from(content))),
    }
}

impl std::fmt::Display for Rcvr { 
    fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
        fmt.write_str(&self.manufacturer)?;
        fmt.write_str(" ")?;
        fmt.write_str(&self.recv_type)?;
        fmt.write_str(" ")?;
        fmt.write_str(&self.serial_number)?;
        fmt.write_str(" ")?;
        fmt.write_str(&self.year.to_string())?;
        fmt.write_str(" ")?;
        fmt.write_str(&self.release)?;
        Ok(())
    }
}

/// `Cggtts` structure comprises
/// a measurement system and 
/// and its Common View realizations (`tracks`)
#[derive(Debug, Clone)]
pub struct Cggtts {
    /// file revision release date 
    pub rev_date: chrono::NaiveDate, 
    /// laboratory / agency where measurements were performed (if unknown)
    pub lab: Option<String>, 
    /// possible GNSS receiver infos
    pub rcvr: Option<Rcvr>, 
    /// nb of GNSS receiver channels
    pub nb_channels: u16, 
    /// IMS Ionospheric Measurement System (if any)
    pub ims: Option<Rcvr>, 
    /// Description of Reference time system (if any)
    pub time_reference: Option<String>, 
    /// Reference frame, coordinates system and conversions,
    /// used in `coordinates` field
    pub reference_frame: Option<String>,
    /// Antenna phase center coordinates [m]
    /// in `ITFR`, `ECEF` or other spatial systems
    pub coordinates: rust_3d::Point3D, 
    /// Comments (if any..)
    pub comments: Option<Vec<String>>, 
    /// Describes the measurement systems delay.
    /// Refer to [Delay] enum,
    /// to understand their meaning.
    /// Refer to [SystemDelay] and [CalibratedDelay] to understand
    /// how to specify the measurement systems delay.
    pub delay: SystemDelay, 
    /// Tracks: actual measurements / realizations
    pub tracks: Vec<Track>,
}

#[derive(Error, Debug)]
pub enum Error {
    #[error("failed to parse file")]
    IoError(#[from] std::io::Error),
    #[error("failed to parse integer number")]
    ParseIntError(#[from] std::num::ParseIntError),
    #[error("failed to parse float number")]
    ParseFloatError(#[from] std::num::ParseFloatError),
    #[error("only revision 2E is supported")]
    VersionMismatch,
    #[error("version format mismatch")]
    VersionFormatError,
    #[error("revision date format mismatch")]
    RevisionDateFormatError,
    #[error("failed to parse revision date")]
    RevisionDateParsingError,
    #[error("failed to parse \"{0}\" coordinates")]
    CoordinatesParsingError(String),
    #[error("failed to identify delay value in line \"{0}\"")]
    DelayIdentificationError(String),
    #[error("failed to parse frequency dependent delay from \"{0}\"")]
    FrequencyDependentDelayParsingError(String),
    #[error("checksum format error")]
    ChecksumFormatError,
    #[error("failed to parse checksum value")]
    ChecksumParsingError,
    #[error("crc calc() failed over non utf8 data: \"{0}\"")]
    NonAsciiData(#[from] CrcError),
    #[error("checksum error, got \"{0}\" but \"{1}\" locally computed")]
    ChecksumError(u8, u8),
}

impl Default for Cggtts {
    /// Buils default `Cggtts` structure,
    fn default() -> Cggtts {
        Cggtts {
            rev_date: chrono::NaiveDate::parse_from_str(
                LATEST_REVISION_DATE,
                "%Y-%m-%d").unwrap(),
            lab: None,
            nb_channels: 0,
            coordinates: rust_3d::Point3D {
                x: 0.0,
                y: 0.0,
                z: 0.0,
            },
            rcvr: None,
            tracks: Vec::new(),
            ims: None, 
            reference_frame: None,
            time_reference: None,
            comments: None,
            delay: SystemDelay::new(), 
        }
    }
}

impl Cggtts {
    /// Builds `Cggtts` object with desired attributes.
    /// Date is set to `now` by default, use
    /// `with_date()` to customize.
    pub fn new (lab: Option<&str>, nb_channels: u16, rcvr: Option<Rcvr>) -> Self { 
        let mut c = Self::default();
        if let Some(lab) = lab {
            c = c.with_lab_agency(lab);
        }
        c = c.with_nb_channels(nb_channels);
        if let Some(rcvr) = rcvr {
            c = c.with_receiver(rcvr);
        }
        c
    }

    /// Returns true if all tracks follow 
    /// BIPM tracking specifications
    pub fn follows_bipm_specs (&self) -> bool {
        for track in self.tracks.iter() {
            if !track.follows_bipm_specs() {
                return false
            }
        }
        true
    }
    
    /// Returns `Cggtts` with same attributes
    /// but desired `Lab` agency
    pub fn with_lab_agency (&self, lab: &str) -> Self { 
        let mut c = self.clone();
        c.lab = Some(lab.to_string());
        c
    }
    
    /// Returns ̀`Cggtts` with desired number of channels
    pub fn with_nb_channels (&self, ch: u16) -> Self { 
        let mut c = self.clone();
        c.nb_channels = ch;
        c
    }

    /// Returns `Cggtts` with desired Receiver infos
    pub fn with_receiver (&self, rcvr: Rcvr) -> Self { 
        let mut c = self.clone();
        c.rcvr = Some(rcvr);
        c
    }

    /// Returns `Cggtts` with desired `IMS` evaluation
    /// hardware infos
    pub fn with_ims_infos (&self, ims: Rcvr) -> Self { 
        let mut c = self.clone();
        c.ims = Some(ims);
        c
    }

    /// Returns `cggtts` but with desired antenna phase center
    /// coordinates, coordinates should be in `IRTF` reference system,
    /// and expressed in meter.
    pub fn with_antenna_coordinates (&self, coords: rust_3d::Point3D) -> Self {
        let mut c = self.clone();
        c.coordinates = coords;
        c
    }
    
    /// Returns `Cggtts` with desired reference time system description 
    pub fn with_time_reference (&self, reference: &str) -> Self { 
        let mut c = self.clone();
        c.time_reference = Some(reference.to_string());
        c
    }

    /// Returns `Cggtts` with desired Reference Frame 
    pub fn with_reference_frame (&self, reference: &str) -> Self {
        let mut c = self.clone();
        c.reference_frame = Some(reference.to_string());
        c
    }

    /// Returns true if Self only contains tracks (measurements)
    /// that have ionospheric parameter estimates
    pub fn has_ionospheric_data (&self) -> bool {
        for track in self.tracks.iter() {
            if !track.has_ionospheric_data() {
                return false
            }
        }
        true
    }

    /// Returns production date (y/m/d) of this file
    /// using MJD field of first track produced
    pub fn date (&self) -> Option<chrono::NaiveDate> {
        if let Some(t) = self.tracks.first() {
            Some(t.date)
        } else {
            None
        }
    }

    /// Returns total set duration,
    /// by cummulating all measurements duration
    pub fn total_duration (&self) -> std::time::Duration {
        let mut s = 0;
        for t in self.tracks.iter() {
            s += t.duration.as_secs()
        }
        std::time::Duration::from_secs(s)
    }

    /// Builds Self from given `Cggtts` file.
    pub fn from_file (fp: &str) -> Result<Self, Error> {
        let file_content = std::fs::read_to_string(fp)
            .unwrap();
        let mut lines = file_content.split("\n")
            .map(|x| x.to_string())
            //.map(|x| x.to_string() +"\n")
            //.map(|x| x.to_string() +"\r"+"\n")
                .into_iter();
        
        // init variables
        let mut line = lines.next()
            .unwrap();
        let mut system_delay = SystemDelay::new();
        
        // VERSION must be first
        let _ = match scan_fmt!(&line, "CGGTTS GENERIC DATA FORMAT VERSION = {}", String) {
            Some(version) => {
                if !version.eq(&CURRENT_RELEASE) {
                    return Err(Error::VersionMismatch)
                }
            },
            _ => return Err(Error::VersionFormatError),
        };
        
        let mut _cksum :u8 = calc_crc(&line)?;
        
        let mut rev_date = chrono::NaiveDate::parse_from_str(LATEST_REVISION_DATE, "%Y-%m-%d")
            .unwrap();
        let mut nb_channels :u16 = 0;
        let mut rcvr : Option<Rcvr> = None;
        let mut ims : Option<Rcvr> = None;
        let mut lab: Option<String> = None;
        let mut comments: Vec<String> = Vec::new();
        let mut reference_frame: Option<String> = None;
        let mut time_reference : Option<String> = None;
        let (mut x, mut y, mut z) : (f64,f64,f64) = (0.0, 0.0, 0.0);

        line = lines.next()
            .unwrap();

        loop {
            if line.starts_with("REV DATE = ") {
                match scan_fmt! (&line, "REV DATE = {d} {d} {d}", i32, u32, u32) {
                    (Some(year),
                    Some(month),
                    Some(day)) => {
                        rev_date = chrono::NaiveDate::from_ymd(year, month, day);
                    },
                    _ => {}
                }
            } else if line.starts_with("RCVR = ") {
                match scan_fmt! (&line, "RCVR = {} {} {} {d} {}", String, String, String, String, String) {
                    (Some(manufacturer),
                    Some(recv_type),
                    Some(serial_number),
                    Some(year),
                    Some(release)) => {
                        rcvr = Some(Rcvr {
                            manufacturer, 
                            recv_type, 
                            serial_number, 
                            year: u16::from_str_radix(&year, 10)?, 
                            release, 
                        })
                    },
                    _ => {}
                }

            } else if line.starts_with("CH = ") {
                match scan_fmt!(&line, "CH = {d}", u16) {
                    Some(n) => nb_channels = n,
                    _ => {} 
                };

            } else if line.starts_with("IMS = ") {
                match scan_fmt!(&line, "IMS = {} {} {} {d} {}", String, String, String, String, String) {
                    (Some(manufacturer),
                    Some(recv_type),
                    Some(serial_number),
                    Some(year),
                    Some(release)) => { 
                        ims = Some(Rcvr {
                            manufacturer, 
                            recv_type, 
                            serial_number, 
                            year: u16::from_str_radix(&year, 10)?, 
                            release,
                        })
                    },
                    _ => {}, 
                }
            
            } else if line.starts_with("LAB = ") {
                match line.strip_prefix("LAB = ") {
                    Some(s) => {
                        lab = Some(String::from(s.trim()))
                    },
                    _ => {},
                }
            } else if line.starts_with("X = ") {
                match scan_fmt!(&line, "X = {f}", f64) {
                    Some(f) => {
                        x = f
                    },
                    _ => {},
                }
            } else if line.starts_with("Y = ") {
                match scan_fmt!(&line, "Y = {f}", f64) {
                    Some(f) => {
                        y = f
                    },
                    _ => {},
                }
            } else if line.starts_with("Z = ") {
                match scan_fmt!(&line, "Z = {f}", f64) {
                    Some(f) => {
                        z = f
                    },
                    _ => {},
                }
            
            } else if line.starts_with("FRAME = ") {
                let frame = line.split_at(7).1.trim();
                if !frame.eq("?") {
                    reference_frame = Some(frame.to_string())
                }

            } else if line.starts_with("COMMENTS = ") {
                let c = line.strip_prefix("COMMENTS =")
                    .unwrap()
                    .trim();
                if !c.eq("NO COMMENTS") {
                    comments.push(c.to_string())
                }

            } else if line.starts_with("REF = ") {
                match scan_fmt!(&line, "REF = {}", String) {
                    Some(s) => {
                        time_reference = Some(s) 
                    },
                    _ => {},
                }

            } else if line.contains("DLY = ") {

                // determine delay denomination
                let label : String = match scan_fmt!(&line, "{} DLY =.*", String) {
                    Some(l) => l,
                    _ => return Err(Error::DelayIdentificationError(String::from(line))),
                };

                // currently we do not support separate values
                // for two carrier and different System delay values.
                // We grab all delay values, treat them as single carrier,
                // and possible second carrier for delays like SYS DLY are left out
                let start_off = line.find("=").unwrap();
                let end_off   = line.find("ns").unwrap();
                let data = &line[start_off+1..end_off];
                let value = f64::from_str(data.trim())?;

                match label.as_str() {
                    "CAB" => {
                        system_delay.rf_cable_delay = value
                    },
                    "REF" => {
                        system_delay.ref_delay = value
                    },
                    "SYS" => {
                        system_delay.calib_delay = CalibratedDelay {
                            info: None, // TODO
                            constellation: Constellation::default(), // TODO
                            delay: Delay::System(value),
                        }
                    },
                    "INT" => {
                        system_delay.calib_delay = CalibratedDelay {
                            info: None, // TODO
                            constellation: Constellation::default(), // TODO
                            delay: Delay::Internal(value),
                        }
                    },
                    "TOT" => {
                        // special case, Total delay is given,
                        // assumes all other delays are not known
                        system_delay.rf_cable_delay = value;
                        break
                    },
                    _ => {}, // non recognized delay type
                };
            
            } else if line.starts_with("CKSUM = ") {

                let _ck :u8 = match scan_fmt!(&line, "CKSUM = {x}", String) {
                    Some(s) => {
                        match u8::from_str_radix(&s, 16) {
                            Ok(hex) => hex,
                            _ => return Err(Error::ChecksumParsingError),
                        }
                    },
                    _ => return Err(Error::ChecksumFormatError),
                };
                
                // check CRC
                let end_pos = line.find("= ")
                    .unwrap();
                _cksum = _cksum.wrapping_add(
                    calc_crc(
                        &line.split_at(end_pos+2).0)?);
        
                //if cksum != ck {
                //    return Err(Error::ChecksumError(ck, cksum))
                //}
                break
            }

            // CRC
            _cksum = _cksum.wrapping_add(
                calc_crc(&line)?);
            
            if let Some(l) = lines.next() {
                line = l 
            } else {
                break
            }
        }
        
        // BLANKS 
        let _ = lines.next().unwrap(); // Blank
        let _ = lines.next().unwrap(); // labels
        let _ = lines.next().unwrap(); // units currently discarded
        // tracks parsing
        let mut tracks: Vec<Track> = Vec::new();
        loop {
            let line = match lines.next() {
                Some(s) => s,
                _ => break // we're done parsing
            };
            if line.len() == 0 { // empty line
                break // we're done parsing
            }
            if let Ok(track) = Track::from_str(&line) {
                tracks.push(track)
            }
        }

        Ok(Cggtts {
            rev_date,
            nb_channels,
            rcvr,
            ims,
            lab,
            reference_frame,
            coordinates: rust_3d::Point3D {
                x,
                y,
                z,
            },
            comments: {
                if comments.len() == 0 {
                    None
                } else {
                    Some(comments)
                }
            },
            delay: system_delay,
            time_reference,
            tracks
        })
    }
}

impl std::fmt::Display for Cggtts {
    /// Writes self into a `Cggtts` file
    fn fmt (&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
        let mut content = String::new();
        let line = format!("CGGTTS GENERIC DATA FORMAT VERSION = {}\n", CURRENT_RELEASE);
        content.push_str(&line);
        let line = format!("REV DATE = {}\n", LATEST_REVISION_DATE);
        content.push_str(&line);

        if let Some(rcvr) = &self.rcvr {
            content.push_str(&format!("RCVR = {}\n", rcvr));
        } else {
            content.push_str("RCVR = RRRRRRRR\n")
        }
        
        let line = format!("CH = {}\n", self.nb_channels); 
        content.push_str(&line);

        if let Some(ims) = &self.ims {
            content.push_str(&format!("RCVR = {}\n", ims));
        } else {
            content.push_str("IMS = 99999\n")
        }
        
        content.push_str(&format!("LAB = {}\n", self.nb_channels)); 
        content.push_str(&format!("X = {}\n", self.coordinates.x)); 
        content.push_str(&format!("Y = {}\n", self.coordinates.y)); 
        content.push_str(&format!("Z = {}\n", self.coordinates.z)); 

        if let Some(r) = &self.reference_frame {
            content.push_str(&format!("FRAME = {}\n", r)); 
        } else {
            content.push_str(&format!("FRAME = ITRF\n"));
        }

        if let Some(comments) = &self.comments {
            content.push_str(&format!("COMMENTS = {}\n", comments[0].to_string()));
        } else {
            content.push_str("COMMENTS = NO COMMENTS\n")
        }

        /*// system delays
        if let Some(delay) = &self.tot_dly {
            // total delay defined
            content.push_str(&format!("TOT DLY = {}\n", delay.to_string()))
        
        } else {
            // total delay not defined
            // => SYS or INT DELAY ?
            // INT DELAY prioritary
            if let Some(delay) = &self.int_dly {
                content.push_str(&format!("INT DLY = {}\n", delay))

            } else if let Some(delay) = &self.sys_dly {
                content.push_str(&format!("SYS DLY = {}\n", delay))
            
            } else {
                // neither SYS / INT delay
                // => specify null SYS DLY
                let null_delay = CalibratedDelay {
                    constellation: track::Constellation::default(),
                    values: vec![0.0_f64],
                    codes: vec![String::from("C1")],
                    report: String::from("NA"),
                };
                content.push_str(&format!("SYS DLY = {}\n", null_delay))
            }
            // other delays always there
            content.push_str(&format!("CAB DLY = {:.1}\n", self.cab_dly * 1E9));
            content.push_str(&format!("REF DLY = {:.1}\n", self.ref_dly * 1E9))
        }*/

        if let Some(r) = &self.time_reference {
            content.push_str(&format!("REF = {}\n", r))
        } else {
            content.push_str(&format!("REF = ?\n"))
        }

        let crc = calc_crc(&content)
            .unwrap();
        content.push_str(&format!("CKSUM = {:2X}\n", crc));
        content.push_str("\n"); // blank

        if self.has_ionospheric_data() {
            content.push_str(TRACK_LABELS_WITH_IONOSPHERIC_DATA);
            content.push_str("\n");
            content.push_str(
"              hhmmss s .1dg .1dg .1ns .1ps/s .1ns .1ps/s .1ns .1ns.1ps/s.1ns.1ps/s.1ns.1ps/s.1ns\n")
        } else {
            content.push_str(TRACK_LABELS_WITHOUT_IONOSPHERIC_DATA);
            content.push_str("\n");
            content.push_str(
"             hhmmss s   .1dg .1dg    .1ns     .1ps/s     .1ns    .1ps/s .1ns     .1ns.1ps/s.1ns.1ps/s\n")
        }

        for i in 0..self.tracks.len() {
            content.push_str(&self.tracks[i].to_string());
            content.push_str("\n")
        }
        fmt.write_str(&content)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_crc() {
        let content = vec![
            "R24 FF 57000 000600  780 347 394 +1186342 +0 163 +0 40 2 141 +22 23 -1 23 -1 29 +2 0 L3P",
            "G99 99 59509 002200 0780 099 0099 +9999999999 +99999 +9999989831   -724    35 999 9999 +999 9999 +999 00 00 L1C"
        ];
        let expected = vec![
            0x0F, 
            0x71,
        ];
        for i in 0..content.len() {
            let ck = calc_crc(content[i])
                .unwrap();
            let expect = expected[i];
            assert_eq!(ck,
                expect,
                "Failed for \"{}\", expect \"{}\" but \"{}\" locally computed",
                content[i],expect,
                ck)
        }
    }
}