Skip to content

Commit

Permalink
Fix unused variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Frits Sweijen committed Jan 11, 2024
1 parent abd1a95 commit 4f52b66
Showing 1 changed file with 112 additions and 24 deletions.
136 changes: 112 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// H5parm interface.

use hdf5::file;
use ndarray::{Array1,ArrayD};

use ndarray::{Array1, ArrayD};

pub struct H5parm {
pub name: String,
Expand All @@ -18,7 +17,9 @@ impl H5parm {
} else {
file::File::open_rw(&h5parm_in).expect("Failed to read H5parm.")
};
let solsets = infile.groups().expect("Failed to read SolSets from H5parm.");
let solsets = infile
.groups()
.expect("Failed to read SolSets from H5parm.");

let mut solsetlist: Vec<SolSet> = vec![];
for ss in solsets.iter() {
Expand Down Expand Up @@ -47,6 +48,15 @@ impl H5parm {
pub fn getSolSets(&self) -> &Vec<SolSet> {
&self.solsets
}

pub fn has_solset(&self, ssname: &str) -> bool {
let result = &self.solsets.iter()
.find(|s| s.name == ssname);
return match result {
None => false,
_ => true,
};
}
}

#[derive(Debug)]
Expand All @@ -56,19 +66,31 @@ pub struct SolSet {
}

impl SolSet {
fn init(h5parm: &hdf5::File, name: String) -> SolSet{
let _sts = h5parm.group("sol000").expect("Failed to read SolTabs.").groups().unwrap();
fn init(h5parm: &hdf5::File, name: String) -> SolSet {
let _sts = h5parm
.group("sol000")
.expect("Failed to read SolTabs.")
.groups()
.unwrap();
let mut soltablist: Vec<SolTab> = vec![];
for ss in _sts.iter() {
// VarLenAscii doesn't work, so we just read a long fixed-length string...
// There's also some ASCII vs Unicode stuff, so try both.
let st_type = match ss.attr("TITLE").expect("SolTab does not appear to have a type.").read_scalar::<hdf5::types::FixedAscii<32>>() {
Ok(f) => f.as_str().to_owned(),
Err(_f) => "".to_string(),
};

let st_type = match ss
.attr("TITLE")
.expect("SolTab does not appear to have a type.")
.read_scalar::<hdf5::types::FixedAscii<32>>()
{
Ok(f) => f.as_str().to_owned(),
Err(_f) => "".to_string(),
};

let st_type = if st_type.is_empty() {
match ss.attr("TITLE").expect("SolTab does not appear to have a type.").read_scalar::<hdf5::types::FixedUnicode<32>>() {
match ss
.attr("TITLE")
.expect("SolTab does not appear to have a type.")
.read_scalar::<hdf5::types::FixedUnicode<32>>()
{
Ok(f) => f.as_str().to_owned(),
Err(_f) => "".to_string(),
}
Expand Down Expand Up @@ -113,16 +135,21 @@ pub struct SolTab {
_h5parm: hdf5::File,
}


impl SolTab {
pub fn get_axes(&self) -> Vec<String> {
let full_st_name = self.get_full_name();
let _axes_string = self._h5parm.group(&full_st_name).unwrap()
.dataset("val").unwrap()
.attr("AXES").expect("SolTab is missing AXES attribute!")
let _axes_string = self
._h5parm
.group(&full_st_name)
.unwrap()
.dataset("val")
.unwrap()
.attr("AXES")
.expect("SolTab is missing AXES attribute!")
// Axes are time, ant, freq and optionally dir or pol.
// This is a single comma-separated string, so max length 22 including commas.
.read_scalar::<hdf5::types::FixedAscii<22>>().unwrap();
.read_scalar::<hdf5::types::FixedAscii<22>>()
.unwrap();
_axes_string.split(",").map(str::to_string).collect()
}

Expand All @@ -140,41 +167,102 @@ impl SolTab {

pub fn get_times(&self) -> Array1<f64> {
let full_st_name = self.get_full_name();
let st = self._h5parm.group(&full_st_name).unwrap().dataset("time").unwrap_or_else(|_err| panic!("Failed to read times for SolTab {}", stringify!(full_st_name)));
let st = self
._h5parm
.group(&full_st_name)
.unwrap()
.dataset("time")
.unwrap_or_else(|_err| {
panic!(
"Failed to read times for SolTab {}",
stringify!(full_st_name)
)
});
st.read_1d::<f64>().unwrap()
}

pub fn get_frequencies(&self) -> Array1<f64> {
let full_st_name = self.get_full_name();
let st = self._h5parm.group(&full_st_name).unwrap().dataset("freq").unwrap_or_else(|_err| panic!("Failed to read frequencies for SolTab {}", stringify!(full_st_name)));
let st = self
._h5parm
.group(&full_st_name)
.unwrap()
.dataset("freq")
.unwrap_or_else(|_err| {
panic!(
"Failed to read frequencies for SolTab {}",
stringify!(full_st_name)
)
});
st.read_1d::<f64>().unwrap()
}

pub fn get_antennas(&self) -> Array1<hdf5::types::FixedAscii<9>> {
let full_st_name = self.get_full_name();
let st = self._h5parm.group(&full_st_name).unwrap().dataset("ant").unwrap_or_else(|_err| panic!("Failed to read antennas for SolTab {}", stringify!(full_st_name)));
let st = self
._h5parm
.group(&full_st_name)
.unwrap()
.dataset("ant")
.unwrap_or_else(|_err| {
panic!(
"Failed to read antennas for SolTab {}",
stringify!(full_st_name)
)
});
// Station names are at most 9 characters long, e.g. CS003HBA0, IE613HBA.
st.read_1d::<hdf5::types::FixedAscii<9>>().unwrap()
}

pub fn get_directions(&self) -> Array1<hdf5::types::FixedAscii<128>> {
let full_st_name = self.get_full_name();
let st = self._h5parm.group(&full_st_name).unwrap().dataset("dir").unwrap_or_else(|_err| panic!("Failed to read polarisations for SolTab {}", stringify!(full_st_name)));
let st = self
._h5parm
.group(&full_st_name)
.unwrap()
.dataset("dir")
.unwrap_or_else(|_err| {
panic!(
"Failed to read polarisations for SolTab {}",
stringify!(full_st_name)
)
});
// Not sure what to do here. Surely 128 characters is fine?
st.read_1d::<hdf5::types::FixedAscii<128>>().unwrap()
}

pub fn get_polarisations(&self) -> Array1<hdf5::types::FixedAscii<2>> {
let full_st_name = self.get_full_name();
let st = self._h5parm.group(&full_st_name).unwrap().dataset("pol").unwrap_or_else(|_err| panic!("Failed to read polarisations for SolTab {}", stringify!(full_st_name)));
let st = self
._h5parm
.group(&full_st_name)
.unwrap()
.dataset("pol")
.unwrap_or_else(|_err| {
panic!(
"Failed to read polarisations for SolTab {}",
stringify!(full_st_name)
)
});
// Polarisations have at most 2 letters (usually), e.g. I, Q, U, V, XX, YY, RL, LR etc.
st.read_1d::<hdf5::types::FixedAscii<2>>().unwrap()
}

pub fn get_values(&self) -> ArrayD<f64>{
pub fn get_values(&self) -> ArrayD<f64> {
let full_st_name = self.get_full_name();
let st = self._h5parm.group(&full_st_name).unwrap().dataset("val").unwrap_or_else(|_err| panic!("Failed to read values for SolTab {}", stringify!(full_st_name)));
st.read_dyn::<f64>().expect("Reading SolTab into array failed!")
let st = self
._h5parm
.group(&full_st_name)
.unwrap()
.dataset("val")
.unwrap_or_else(|_err| {
panic!(
"Failed to read values for SolTab {}",
stringify!(full_st_name)
)
});
st.read_dyn::<f64>()
.expect("Reading SolTab into array failed!")
}
}

Expand Down

0 comments on commit 4f52b66

Please sign in to comment.