Skip to content

Commit

Permalink
Usage demo for Context
Browse files Browse the repository at this point in the history
Leads to #94
  • Loading branch information
ChristopherRabotin committed Jun 22, 2023
1 parent c2a377d commit e2a2975
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/bin/anise/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anise::cli::inspect::{BpcRow, SpkRow};
use anise::cli::CliErrors;
use anise::file_mmap;
use anise::naif::daf::{FileRecord, NAIFRecord, NAIFSummaryRecord};
#[cfg(feature = "std")]
use anise::naif::kpl::parser::convert_tpc;
use anise::prelude::*;
use anise::structure::dataset::{DataSet, DataSetType};
Expand Down
14 changes: 13 additions & 1 deletion src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ pub struct Context<'a> {

impl<'a> fmt::Display for Context<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "Context: #SPK = {}", self.num_loaded_spk())
write!(
f,
"Context: #SPK = {}\t#BPC = {}",
self.num_loaded_spk(),
self.num_loaded_bpc()
)?;
if !self.planetary_data.lut.by_id.is_empty() {
write!(f, "\t{}", self.planetary_data)?;
}
if !self.spacecraft_data.lut.by_id.is_empty() {
write!(f, "\t{}", self.spacecraft_data)?;
}
Ok(())
}
}
14 changes: 14 additions & 0 deletions src/naif/kpl/tpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,23 @@ fn test_parse_gm() {

#[test]
fn test_anise_conversion() {
use crate::errors::AniseError;
use crate::naif::kpl::parser::convert_tpc;
use crate::{file_mmap, structure::dataset::DataSet};
use std::fs::File;

let dataset = convert_tpc("data/pck00008.tpc", "data/gm_de431.tpc").unwrap();

assert_eq!(dataset.lut.by_id.len(), 47);

let path = "target/gm_pck_08.anise";

// Test saving
dataset.save_as(path.into(), true).unwrap();

// Test reloading
let bytes = file_mmap!(path).unwrap();
let reloaded = DataSet::from_bytes(&bytes);

assert_eq!(reloaded, dataset);
}
23 changes: 23 additions & 0 deletions tests/context/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#[cfg(feature = "std")]
#[test]
fn test_load_ctx() {
// Start bycreating the ANISE planetary data
use anise::{
naif::kpl::parser::convert_tpc,
prelude::{Context, BPC, SPK},
};

let dataset = convert_tpc("data/pck00008.tpc", "data/gm_de431.tpc").unwrap();

// Load BSP and BPC
let ctx = Context::default();

let spk = SPK::load("data/de440.bsp").unwrap();
let bpc = BPC::load("data/earth_latest_high_prec.bpc").unwrap();

let mut loaded_ctx = ctx.load_spk(&spk).unwrap().load_bpc(&bpc).unwrap();

loaded_ctx.planetary_data = dataset;

println!("{loaded_ctx}");
}
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
#[macro_use]
extern crate approx;
mod astro;
mod context;
mod ephemerides;
mod frames;

0 comments on commit e2a2975

Please sign in to comment.