Skip to content

Commit

Permalink
improving context definition
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume W. Bres <[email protected]>
  • Loading branch information
gwbres committed Mar 10, 2024
1 parent 844fbd0 commit 5d9e3c6
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 86 deletions.
10 changes: 3 additions & 7 deletions rinex-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::{

use clap::{value_parser, Arg, ArgAction, ArgMatches, ColorChoice, Command};
use rinex::prelude::*;
use walkdir::WalkDir;

use crate::{fops::open_with_web_browser, Error};

Expand Down Expand Up @@ -44,13 +43,10 @@ impl Default for Cli {
}
}

use std::cell::RefCell;
use std::rc::Rc;

/// Context defined by User.
pub struct Context<'a> {
pub struct Context {
/// Data context defined by user
pub data: RnxContext<'a>,
pub data: RnxContext,
/// Quiet option
pub quiet: bool,
/// Workspace is the place where this session will generate data.
Expand All @@ -68,7 +64,7 @@ pub struct Context<'a> {
pub rx_ecef: Option<(f64, f64, f64)>,
}

impl<'a> Context<'a> {
impl Context {
/*
* Utility to determine the most major filename stem,
* to be used as the session workspace
Expand Down
2 changes: 1 addition & 1 deletion rinex-cli/src/fops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ pub fn time_binning(ctx: &Context, matches: &ArgMatches) -> Result<(), Error> {
/*
* Substract RINEX[A]-RINEX[B]
*/
pub fn substract<'a>(ctx: &Context<'a>, matches: &ArgMatches) -> Result<(), Error> {
pub fn substract(ctx: &Context, matches: &ArgMatches) -> Result<(), Error> {
let ctx_data = &ctx.data;
let path_a = ctx_data
.files(ProductType::Observation)
Expand Down
129 changes: 83 additions & 46 deletions rinex-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
//mod analysis; // basic analysis
mod cli; // command line interface
mod fops;
//mod graph;
//mod identification; // high level identification/macros
//mod positioning;
//mod qc; // QC report generator // plotting operations // file operation helpers // graphical analysis // positioning + CGGTTS opmode
mod graph;
mod identification; // high level identification/macros
mod positioning;
mod qc; // QC report generator // plotting operations // file operation helpers // graphical analysis // positioning + CGGTTS opmode

mod preprocessing;
use preprocessing::preprocess;
Expand All @@ -17,10 +17,14 @@ use rinex::prelude::RnxContext;

use std::fs::create_dir_all;
use std::path::{Path, PathBuf};
use walkdir::WalkDir;

extern crate gnss_rs as gnss;
extern crate gnss_rtk as rtk;

use rinex::prelude::Rinex;
use sp3::prelude::SP3;

use cli::{Cli, Context};

use map_3d::{ecef2geodetic, rad2deg, Ellipsoid};
Expand All @@ -46,8 +50,8 @@ pub enum Error {
SplitError(#[from] rinex::split::Error),
#[error("failed to create QC report: permission denied!")]
QcReportCreationError,
//#[error("positioning solver error")]
//PositioningSolverError(#[from] positioning::Error),
#[error("positioning solver error")]
PositioningSolverError(#[from] positioning::Error),
}

/*
Expand All @@ -56,8 +60,74 @@ pub enum Error {
fn user_data_parsing(cli: &Cli) -> RnxContext {
let mut ctx = RnxContext::default();

let max_depth = match cli.matches.get_one::<u8>("depth") {
Some(value) => *value as usize,
None => 5usize,
};

/*
* Preprocessing
* Load directories recursively (`-d`)
*/
for dir in cli.input_directories() {
let walkdir = WalkDir::new(dir).max_depth(max_depth);
for entry in walkdir.into_iter().filter_map(|e| e.ok()) {
if !entry.path().is_dir() {
let path = entry.path();
if let Ok(rinex) = Rinex::from_path(path) {
let loading = ctx.load_rinex(path, rinex);
if loading.is_err() {
warn!(
"failed to load RINEX file \"{}\": {}",
path.display(),
loading.err().unwrap()
);
}
} else if let Ok(sp3) = SP3::from_path(path) {
let loading = ctx.load_sp3(path, sp3);
if loading.is_err() {
warn!(
"failed to load SP3 file \"{}\": {}",
path.display(),
loading.err().unwrap()
);
}
} else {
warn!("non supported file format \"{}\"", path.display());
}
}
}
}

/*
* Load each individual file (`-f`)
*/
for fp in cli.input_files() {
let path = Path::new(fp);
if let Ok(rinex) = Rinex::from_path(path) {
let loading = ctx.load_rinex(path, rinex);
if loading.is_err() {
warn!(
"failed to load RINEX file \"{}\": {}",
path.display(),
loading.err().unwrap()
);
}
} else if let Ok(sp3) = SP3::from_path(path) {
let loading = ctx.load_sp3(path, sp3);
if loading.is_err() {
warn!(
"failed to load SP3 file \"{}\": {}",
path.display(),
loading.err().unwrap()
);
}
} else {
warn!("non supported file format \"{}\"", path.display());
}
}

/*
* Preprocess whole context
*/
preprocess(&mut ctx, &cli);
ctx
Expand Down Expand Up @@ -163,39 +233,6 @@ pub fn main() -> Result<(), Error> {
},
};

// let mut data = RnxContext::default();
// let max_depth = match cli.matches.get_one::<u8>("depth") {
// Some(value) => *value as usize,
// None => 5usize,
// };

// /* load all directories recursively, one by one */
// for dir in cli.input_directories() {
// let walkdir = WalkDir::new(dir).max_depth(max_depth);
// for entry in walkdir.into_iter().filter_map(|e| e.ok()) {
// if !entry.path().is_dir() {
// let path = entry.path();
// if let Ok(mut rinex) = Rinex::from_path(path) {
// let ret = data.load_rinex(path, &mut rinex);
// if ret.is_err() {
// warn!(
// "failed to load \"{}\": {}",
// path.display(),
// ret.err().unwrap()
// );
// }
// }
// }
// }
// }
// // // load individual files, if any
// // for filepath in cli.input_files() {
// // let ret = data.load(&Path::new(filepath).to_path_buf());
// // if ret.is_err() {
// // warn!("failed to load \"{}\": {}", filepath, ret.err().unwrap());
// // }
// // }

/*
* Exclusive opmodes
*/
Expand All @@ -204,22 +241,22 @@ pub fn main() -> Result<(), Error> {
fops::filegen(&ctx, submatches)?;
},
Some(("graph", submatches)) => {
//graph::graph_opmode(&ctx, submatches)?;
graph::graph_opmode(&ctx, submatches)?;
},
Some(("identify", submatches)) => {
//identification::dataset_identification(&ctx.data, submatches);
identification::dataset_identification(&ctx.data, submatches);
},
Some(("merge", submatches)) => {
//fops::merge(&ctx, submatches)?;
fops::merge(&ctx, submatches)?;
},
Some(("split", submatches)) => {
//fops::split(&ctx, submatches)?;
fops::split(&ctx, submatches)?;
},
Some(("quality-check", submatches)) => {
//qc::qc_report(&ctx, submatches)?;
qc::qc_report(&ctx, submatches)?;
},
Some(("positioning", submatches)) => {
//positioning::precise_positioning(&ctx, submatches)?;
positioning::precise_positioning(&ctx, submatches)?;
},
Some(("tbin", submatches)) => {
fops::time_binning(&ctx, submatches)?;
Expand Down
7 changes: 2 additions & 5 deletions rinex-cli/src/preprocessing.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use log::error;
use std::str::FromStr;

use crate::{Cli, Context};
use crate::Cli;
use rinex::prelude::RnxContext;
use rinex::preprocessing::*;

use std::cell::RefCell;
use std::rc::Rc;

pub fn preprocess<'a>(ctx: &mut RnxContext<'a>, cli: &Cli) {
pub fn preprocess(ctx: &mut RnxContext, cli: &Cli) {
// GNSS filters
let mut gnss_filters = Vec::<&str>::new();

Expand Down
Loading

0 comments on commit 5d9e3c6

Please sign in to comment.