Skip to content

Commit

Permalink
introducing filegen opmode
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume W. Bres <[email protected]>
  • Loading branch information
gwbres committed Feb 19, 2024
1 parent 3e55f24 commit e3b86a9
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
19 changes: 19 additions & 0 deletions rinex-cli/src/cli/filegen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// filegen opmode
use clap::{value_parser, Arg, Command};

pub fn subcommand() -> Command {
Command::new("filegen")
.long_flag("filegen")
.arg_required_else_help(false)
.about(
"RINEX Data formatting. Use this option to preprocess,
modify and dump resulting context in preserved RINEX format.
You can use this for example, to generate a decimated RINEX file from an input Observations file.",
)
.arg(
Arg::new("name")
.value_parser(value_parser!(String))
.value_name("FILENAME")
.help("Set a custom filename, otherwise, the output is named after primary file."),
)
}
3 changes: 3 additions & 0 deletions rinex-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ mod substract;
mod qc;
// positioning mode
mod positioning;
// filegen mode
mod filegen;

pub struct Cli {
/// Arguments passed by user
Expand Down Expand Up @@ -304,6 +306,7 @@ Otherwise it gets automatically picked up."))
.value_name("\"lat,lon,alt\" coordinates in ddeg [°]")
.help("Define the (RX) antenna position manualy, in decimal degrees."))
.next_help_heading("Exclusive Opmodes: you can only run one at a time.")
.subcommand(filegen::subcommand())
.subcommand(graph::subcommand())
.subcommand(identify::subcommand())
.subcommand(merge::subcommand())
Expand Down
43 changes: 43 additions & 0 deletions rinex-cli/src/fops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,49 @@ use std::path::PathBuf;
use std::process::Command;
use std::str::FromStr;

/*
* Dumps current context (usually preprocessed)
* into RINEX format maintaining consistent format
*/
pub fn filegen(ctx: &Context, matches: &ArgMatches) -> Result<(), Error> {
// output name
let filename = if let Some(name) = matches.get_one::<String>("name") {
name.to_string()
} else if let Some(paths) = ctx.data.obs_paths() {
paths
.get(0)
.expect("failed to determine output filename")
.to_string_lossy()
.to_string()
} else if let Some(paths) = ctx.data.meteo_paths() {
paths
.get(0)
.expect("failed to determine output filename")
.to_string_lossy()
.to_string()
} else if let Some(paths) = ctx.data.nav_paths() {
paths
.get(0)
.expect("failed to determine output filename")
.to_string_lossy()
.to_string()
} else {
panic!("filegen not supported for this type of RINEX");
};
let output_path = ctx.workspace.join(filename).to_string_lossy().to_string();

let rinex = ctx.data.obs_data().unwrap_or(
ctx.data.meteo_data().unwrap_or(
ctx.data
.nav_data()
.unwrap_or_else(|| panic!("filegen not supported for this type of RINEX")),
),
);

rinex.to_file(&output_path)?;
Ok(())
}

/*
* Merges proposed (single) file and generates resulting output, into the workspace
*/
Expand Down
3 changes: 3 additions & 0 deletions rinex-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ pub fn main() -> Result<(), Error> {
* Exclusive opmodes
*/
match cli.matches.subcommand() {
Some(("filegen", submatches)) => {
fops::filegen(&ctx, submatches)?;
},
Some(("graph", submatches)) => {
graph::graph_opmode(&ctx, submatches)?;
},
Expand Down

0 comments on commit e3b86a9

Please sign in to comment.