Skip to content

Commit

Permalink
M to control maximal compression order
Browse files Browse the repository at this point in the history
  • Loading branch information
gwbres committed Mar 27, 2022
1 parent 9c7c7c7 commit 7c85dac
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ refer to the `hatanaka` section of the library

## Supported revisions

* [ ] CRINEX1
* [ ] CRINEX3
* [ ] CRINEX1
* [x] CRINEX3

CRINEX2 does not technically exist

Expand All @@ -32,31 +32,23 @@ 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.

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

Expand All @@ -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.
4 changes: 4 additions & 0 deletions src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
14 changes: 11 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down

0 comments on commit 7c85dac

Please sign in to comment.