1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! Library to parse FITS file written in pure rust.
//!
//! Uses only one dependency, [byteorder](../byteorder), to deal with endianness.
//!
//! Uses intelligent cache to parse big FITS files. Developed for use in
//! multi-threaded environments.
//!
//! # How to use
//!
//! ## Read FITS
//!
//! ```rust,no_run
//! extern crate fitrs;
//! use fitrs::{Fits, FitsData, FitsDataArray};
//!
//! let fits = Fits::open("path/to/fits/file.fits").expect("Failed to open");
//! // Iterate over HDUs
//! for hdu in fits.iter() {
//!     println!("{:?}", hdu.value("EXTNAME"));
//!     println!("{:?}", hdu.read_data());
//! }
//!
//! // Get HDU by ID
//! let hdu_2 = &fits[2];
//! // Get HDU by EXTNAME
//! let hdu_flux = &fits["FLUX"];
//!
//! match hdu_flux.read_data() {
//!     &FitsData::FloatingPoint32(FitsDataArray { ref shape, ref data }) => {
//!         println!("{:?}", shape);
//!         println!("{:?}", data);
//!     }
//!     _ => { /* ... */ }
//! }
//! ```
//!
//! ## Write FITS
//!
//! The FITS files written by `fitrs` are verified by astropy.io.fits for
//! standard compliance. If `fitrs` outputs a non-compliant FITS file, please
//! file a bug.
//!
//! ```rust
//! extern crate fitrs;
//! use fitrs::{Fits, Hdu};
//!
//! // Make example dummy data array
//! let shape = [20, 20];
//! let data = (0..shape[0])
//!     .map(|i| (0..shape[1]).map(move |j| i + j))
//!     .flatten()
//!     .collect();
//! let mut primary_hdu = Hdu::new(&[20, 20], data);
//! // Insert values in header
//! primary_hdu.insert("KEYSTR", "My string");
//! primary_hdu.insert("KEYSTR2", "Whatever value you want to save in this FITS files. Continued (long) strings are supported, if you happen to care.");
//! primary_hdu.insert("KEYFLOAT", 3.14);
//! primary_hdu.insert("KEYINT", 42);
//!
//! // Save file
//! Fits::create("new_file.fits", primary_hdu).expect("Failed to create");
//! ```
//!
//! A lot of possibly desirable functionalities are still missing.
//! PR are welcome.

extern crate byteorder;

mod fits;
mod header;
mod scifmt;
mod types;
mod wcs;

pub use fits::{Fits, FitsData, FitsDataArray, Hdu, HduIter, HeaderValue};
pub use fits::{FitsIntoIter, FitsIter, FitsIterMut};
pub use types::FitsDataType;
pub use wcs::WCS;