Skip to content

Commit

Permalink
Need to merge Frame and remove anise from file loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherRabotin committed Sep 15, 2023
1 parent c1fda5e commit 33859d5
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 99 deletions.
11 changes: 5 additions & 6 deletions src/bin/anise/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use snafu::prelude::*;

use anise::cli::args::{Actions, Args};
use anise::cli::inspect::{BpcRow, SpkRow};
use anise::cli::{AniseSnafu, CliDAFSnafu, CliErrors, CliFileRecordSnafu};
use anise::cli::{AniseSnafu, CliDAFSnafu, CliDataSetSnafu, CliErrors, CliFileRecordSnafu};

Check failure on line 8 in src/bin/anise/main.rs

View workflow job for this annotation

GitHub Actions / Check

unresolved import `anise::cli::AniseSnafu`
use anise::file2heap;
use anise::naif::daf::{FileRecord, NAIFRecord, NAIFSummaryRecord};
use anise::naif::kpl::parser::convert_tpc;
Expand Down Expand Up @@ -46,14 +46,14 @@ fn main() -> Result<(), CliErrors> {
DataSetType::SpacecraftData => {
// Decode as spacecraft data
let dataset = DataSet::<SpacecraftData, 64>::try_from_bytes(&bytes)
.map_err(|source| CliErrors::AniseError { source })?;
.with_context(|_| CliDataSetSnafu)?;
println!("{dataset}");
Ok(())
}
DataSetType::PlanetaryData => {
// Decode as planetary data
let dataset = DataSet::<PlanetaryData, 64>::try_from_bytes(&bytes)
.map_err(|source| CliErrors::AniseError { source })?;
.with_context(|_| CliDataSetSnafu)?;
println!("{dataset}");
Ok(())
}
Expand Down Expand Up @@ -178,12 +178,11 @@ fn main() -> Result<(), CliErrors> {
gmfile,
outfile,
} => {
let dataset =
convert_tpc(pckfile, gmfile).map_err(|source| CliErrors::AniseError { source })?;
let dataset = convert_tpc(pckfile, gmfile).with_context(|_| CliDataSetSnafu)?;

dataset
.save_as(outfile, false)
.map_err(|source| CliErrors::AniseError { source })?;
.with_context(|_| CliDataSetSnafu)?;

Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::io;

use crate::{
naif::daf::{file_record::FileRecordError, DAFError},
prelude::AniseError,
structure::dataset::DataSetError,
};

pub mod args;
Expand All @@ -30,7 +30,7 @@ pub enum CliErrors {
ArgumentError {
arg: String,
},
AniseError {
source: AniseError,
CliDataSet {
source: DataSetError,
},
}
7 changes: 7 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::structure::semver::Semver;
use crate::NaifId;
use core::convert::From;
use core::fmt;
use der::Error as DerError;
use std::io::ErrorKind as IOErrorKind;

#[derive(Clone, PartialEq, Debug)]
Expand Down Expand Up @@ -86,8 +87,14 @@ pub enum DecodingError {
#[snafu(backtrace)]
source: IntegrityError,
},
#[snafu(display("decoding DER failed: {err}"))]
DecodingDer { err: DerError },
#[snafu(display("somehow casting the data failed"))]
Casting,
#[snafu(display("could not load ANISE data version {got}, expected {exp}"))]
AniseVersion { got: Semver, exp: Semver },
#[snafu(display("data could not be parsed as {kind} despite ANISE version matching (should be loaded as another type?)"))]
Obscure { kind: &'static str },
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
Expand Down
14 changes: 6 additions & 8 deletions src/naif/kpl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use core::str::FromStr;
use std::fmt::Debug;
use std::{collections::HashMap, hash::Hash};

use crate::prelude::AniseError;
use snafu::{whatever, Whatever};

use self::parser::Assignment;

Expand All @@ -38,10 +38,10 @@ pub enum KPLValue {
}

impl KPLValue {
pub fn to_vec_f64(&self) -> Result<Vec<f64>, AniseError> {
pub fn to_vec_f64(&self) -> Result<Vec<f64>, Whatever> {
match self {
KPLValue::Matrix(data) => Ok(data.clone()),
_ => Err(AniseError::ParameterNotSpecified),
_ => whatever!("can only convert matrices to vec of f64"),
}
}
}
Expand Down Expand Up @@ -90,7 +90,7 @@ pub enum Parameter {
}

impl FromStr for Parameter {
type Err = AniseError;
type Err = Whatever;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
Expand All @@ -115,12 +115,10 @@ impl FromStr for Parameter {
"UNITS" => Ok(Self::Units),
"AXES" => Ok(Self::Axes),
"GMLIST" | "NAME" | "SPEC" => {
// This is a known unsupported parameter
Err(AniseError::ParameterNotSpecified)
whatever!("unsupported parameter `{s}`")
}
_ => {
println!("WHAT IS `{s}` ?");
Err(AniseError::ParameterNotSpecified)
whatever!("unknown parameter `{s}`")
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/naif/kpl/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ use log::{error, info, warn};

use crate::naif::kpl::tpc::TPCItem;
use crate::naif::kpl::Parameter;
use crate::prelude::AniseError;
use crate::structure::dataset::{DataSet, DataSetBuilder, DataSetType};
use crate::structure::dataset::{DataSet, DataSetBuilder, DataSetError, DataSetType};
use crate::structure::metadata::Metadata;
use crate::structure::planetocentric::ellipsoid::Ellipsoid;
use crate::structure::planetocentric::phaseangle::PhaseAngle;
Expand Down Expand Up @@ -78,7 +77,7 @@ impl Assignment {
pub fn parse_file<P: AsRef<Path>, I: KPLItem>(
file_path: P,
show_comments: bool,
) -> Result<HashMap<i32, I>, AniseError> {
) -> Result<HashMap<i32, I>, DataSetError> {
let file = File::open(file_path).expect("Failed to open file");
let reader = BufReader::new(file);

Expand Down Expand Up @@ -135,7 +134,7 @@ pub fn parse_file<P: AsRef<Path>, I: KPLItem>(
pub fn convert_tpc<'a, P: AsRef<Path>>(
pck: P,
gm: P,
) -> Result<DataSet<'a, PlanetaryData, 64>, AniseError> {
) -> Result<DataSet<'a, PlanetaryData, 64>, DataSetError> {
let mut buf = vec![];
let mut dataset_builder = DataSetBuilder::default();

Expand Down
Loading

0 comments on commit 33859d5

Please sign in to comment.