From 7c85dacd763da1ac8e082832c5dba110c107cfdc Mon Sep 17 00:00:00 2001 From: "Guillaume W. Bres" Date: Sun, 27 Mar 2022 21:15:12 +0200 Subject: [PATCH] M to control maximal compression order --- README.md | 41 +++++++++++++++++++++-------------------- src/cli.yml | 4 ++++ src/main.rs | 14 +++++++++++--- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 90fff38..350215e 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,8 @@ refer to the `hatanaka` section of the library ## Supported revisions -* [ ] CRINEX1 -* [ ] CRINEX3 +* [ ] CRINEX1 +* [x] CRINEX3 CRINEX2 does not technically exist @@ -32,7 +32,7 @@ CRINEX2 does not technically exist Decompress a `CRINEX` file with `-d` ```bash -cargo run -- --filepath /tmp/data.22d -d +cargo run -- -d --filepath /tmp/data.22d ``` This produces an "output.rnx" RINEX file. @@ -40,23 +40,15 @@ This produces an "output.rnx" RINEX file. Use `-o` to set the output file name: ```bash -cargo run -- -fp /tmp/data.22d -o /tmp/data.22o -d -cargo run -- -fp /tmp/data.22d --output /tmp/data.22o -d +cargo run -- -d --filepath /tmp/data.22d -o /tmp/myfile +cargo run -- -d --filepath /tmp/data.22d --output /tmp/custom ``` ## Modern Observation Data and `--strict` flag `CRX2RNX` violates RINEX standard when decompressing V > 2 (modern) RINEX Observation data, -because decompressed epochs are not wrapped and are larger than 80 characters. - -This tool behaves like `CRX2RNX` by default, -but you can change that behavior -to follow `RINEX` definitnios strictly, by passing the `--strict` flag: - -```bash -cargo run -- -fp data.22d -d -s -``` +because decompressed epochs are not contrainted to 80 characters. ## Epoch events @@ -65,10 +57,19 @@ Just like `CRX2RNX`, epochs with weird events are left untouched. Therefore, explanations on these epochs events, usually described in the form of `COMMENTS` are preserved. -## Compression algorithm +## Compression behavior & limitations + +This tool uses an M=8 maximal compression order, +which should be fine for all CRINEX ever produced, +considering they were probably produced with `CRX2RNX` +which hardcodes an M=5 limitation. + +Unlike `CRX2RNX`, this tool is not limited to M, +you can increase the default value if you think "higher" +compression will be encountered in a given file: +```bash +cargo run -- -d -m 8 --filepath /tmp/data.22d +``` -Unlike `CRX2RNX`, this tool is not limited to -an M=5 compression / decompression order -in the core algorithm. -It actually dynamically adapts and will never fail, as long -as the input content is a valid CRINEX. +Best compression performances seem to be obtained for m=4 +which is handled by default. diff --git a/src/cli.yml b/src/cli.yml index 291c701..2ebab97 100644 --- a/src/cli.yml +++ b/src/cli.yml @@ -22,3 +22,7 @@ args: long: output takes_value: true help: Set output file name + - max-compression-order: + short: M + takes_value: true + help: control maximal compression order (default is M=8) diff --git a/src/main.rs b/src/main.rs index 7e0b48c..742067e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,6 +34,8 @@ fn main() -> Result<(), Error> { let crx2rnx = matches.is_present("crx2rnx"); let rnx2crx = matches.is_present("rnx2crx"); + let m = u16::from_str_radix(matches.value_of("m") + .unwrap_or("8"),10).unwrap(); let strict_flag = matches.is_present("strict"); let outpath : String = match crx2rnx { @@ -55,19 +57,25 @@ fn main() -> Result<(), Error> { let mut output = std::fs::File::create(outpath)?; if crx2rnx { - decompress(filepath, output) + decompress(filepath, m, output)?; + println!("RINEX file extracted"); + Ok(()) } else { Ok(()) } } -fn decompress (fp: &str, mut writer: std::fs::File) -> Result<(), Error> { +/// Decompresses given file, +/// fp : filepath +/// m : maximal compression order for core algorithm +/// writer: stream +fn decompress (fp: &str, m: u16, mut writer: std::fs::File) -> Result<(), Error> { let mut content = String::new(); let mut hd_content = String::new(); let input = std::fs::File::open(fp)?; let reader = BufReader::new(input); let mut header : header::Header = header::Header::default(); - let mut decompressor = hatanaka::Decompressor::new(8); // TODO maximal order + let mut decompressor = hatanaka::Decompressor::new(m.into()); let mut first_epoch = true; let mut epoch_len : usize = 0;