Skip to content

Commit

Permalink
Merge branch 'remove-dimensions'
Browse files Browse the repository at this point in the history
Closes #18
  • Loading branch information
simonrw committed Feb 14, 2017
2 parents 49a2e56 + b73d8b6 commit 6720fc8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
14 changes: 4 additions & 10 deletions fitsio/src/fitsfile.rs
Expand Up @@ -17,10 +17,7 @@ use super::stringutils::status_to_string;
/// Otherwise the variant is `HduInfo::TableInfo`.
#[derive(Debug)]
pub enum HduInfo {
ImageInfo {
dimensions: usize,
shape: Vec<usize>,
},
ImageInfo { shape: Vec<usize> },
TableInfo {
column_descriptions: Vec<ColumnDescription>,
num_rows: usize,
Expand Down Expand Up @@ -59,10 +56,7 @@ unsafe fn fetch_hdu_info(fptr: *mut sys::fitsfile) -> Result<HduInfo> {
let mut shape = vec![0; dimensions as usize];
sys::ffgisz(fptr, dimensions, shape.as_mut_ptr(), &mut status);

HduInfo::ImageInfo {
dimensions: dimensions as usize,
shape: shape.iter().map(|v| *v as usize).collect(),
}
HduInfo::ImageInfo { shape: shape.iter().map(|v| *v as usize).collect() }
}
1 | 2 => {
let mut num_rows = 0;
Expand Down Expand Up @@ -412,8 +406,8 @@ mod test {
fn fetching_hdu_info() {
let f = FitsFile::open("../testdata/full_example.fits").unwrap();
match f.fetch_hdu_info() {
Ok(HduInfo::ImageInfo { dimensions, shape }) => {
assert_eq!(dimensions, 2);
Ok(HduInfo::ImageInfo { shape }) => {
assert_eq!(shape.len(), 2);
assert_eq!(shape, vec![100, 100]);
}
Err(e) => panic!("Error fetching hdu info {:?}", e),
Expand Down
14 changes: 7 additions & 7 deletions fitsio/src/fitshdu.rs
Expand Up @@ -369,9 +369,9 @@ pub trait ReadWriteImage: Sized {
/// This reads an entire image into a one-dimensional vector
fn read_image(fits_file: &FitsFile) -> Result<Vec<Self>> {
match fits_file.fetch_hdu_info() {
Ok(HduInfo::ImageInfo { dimensions, shape }) => {
Ok(HduInfo::ImageInfo { shape }) => {
let mut npixels = 1;
for dim in 0..dimensions {
for dim in 0..shape.len() {
npixels *= shape[dim];
}
Self::read_section(fits_file, 0, npixels)
Expand Down Expand Up @@ -400,7 +400,7 @@ macro_rules! read_write_image_impl {
impl ReadWriteImage for $t {
fn read_section(fits_file: &FitsFile, start: usize, end: usize) -> Result<Vec<Self>> {
match fits_file.fetch_hdu_info() {
Ok(HduInfo::ImageInfo { dimensions: _dimensions, shape: _shape }) => {
Ok(HduInfo::ImageInfo { shape: _shape }) => {
let nelements = end - start;
let mut out = vec![0 as $t; nelements];
let mut status = 0;
Expand Down Expand Up @@ -430,8 +430,8 @@ macro_rules! read_write_image_impl {
fn read_rows(fits_file: &FitsFile, start_row: usize, num_rows: usize)
-> Result<Vec<Self>> {
match fits_file.fetch_hdu_info() {
Ok(HduInfo::ImageInfo { dimensions, shape }) => {
if dimensions != 2 {
Ok(HduInfo::ImageInfo { shape }) => {
if shape.len() != 2 {
unimplemented!();
}

Expand All @@ -456,8 +456,8 @@ macro_rules! read_write_image_impl {
fn read_region( fits_file: &FitsFile, lower_left: &Coordinate, upper_right: &Coordinate)
-> Result<Vec<Self>> {
match fits_file.fetch_hdu_info() {
Ok(HduInfo::ImageInfo { dimensions, .. }) => {
if dimensions != 2 {
Ok(HduInfo::ImageInfo { shape }) => {
if shape.len() != 2 {
unimplemented!();
}

Expand Down
4 changes: 2 additions & 2 deletions fitsio/src/lib.rs
Expand Up @@ -83,8 +83,8 @@
//! # let fptr = FitsFile::open(filename).unwrap();
//! let hdu = fptr.hdu(0).unwrap();
//! // image HDU
//! if let HduInfo::ImageInfo { dimensions, shape } = hdu.info {
//! println!("Image is {}-dimensional", dimensions);
//! if let HduInfo::ImageInfo { shape } = hdu.info {
//! println!("Image is {}-dimensional", shape.len());
//! println!("Found image with shape {:?}", shape);
//! }
//! # let hdu = fptr.hdu("TESTEXT").unwrap();
Expand Down

0 comments on commit 6720fc8

Please sign in to comment.