1use crate::data::data::Precision;
2
3#[derive(Debug, Clone, PartialEq)]
4pub struct Primary {
5 pub fitsblocks: Vec<[u8; 2880]>,
6 bitpix: i8,
7 naxis: u8,
8 naxisn: Vec<u32>,
9}
10
11impl Primary {
12 pub fn new() -> Primary {
13 Primary {
14 fitsblocks: Vec::new(),
15 bitpix: 0,
16 naxis: 0,
17 naxisn: Vec::new(),
18 }
19 }
20
21 pub fn n_bits(&self) -> u32 {
22 (self.bitpix.abs() as u32)*(self.naxisn.iter().product::<u32>())
23 }
24
25 pub fn convert_fitsblocks(&self) -> Precision {
26 let fitsblocks: Vec<[u8; 2880]> = self.fitsblocks.to_vec();
27 let mut precision: Precision = match self.bitpix {
28 8 => Precision::U8(Vec::new()),
29 16 => Precision::I16(Vec::new()),
30 32 => Precision::I32(Vec::new()),
31 64 => Precision::I64(Vec::new()),
32 -32 => Precision::F32(Vec::new()),
33 -64 => Precision::F64(Vec::new()),
34 _ => Precision::U8(Vec::new()),
35 };
36 precision = Precision::convert_fitsblocks(fitsblocks, precision);
37 precision
38 }
39}