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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
use Debug;
use crateImage;
use crateHDU;
pub use crate;
use Deref;
/// Structure storing the content of one HDU (i.e. Header Data Unit)
/// of a fits file
;
use DerefMut;
/*
#[derive(Debug)]
pub struct AsyncPrimaryHDU<'a, R>(pub AsyncHDU<'a, R, Image>)
where
R: DataAsyncBufRead<'a, Image>
+ DataAsyncBufRead<'a, BinTable>
+ DataAsyncBufRead<'a, AsciiTable>
+ 'a;
impl<'a, R> AsyncPrimaryHDU<'a, R>
where
R: DataAsyncBufRead<'a, Image>
+ DataAsyncBufRead<'a, BinTable>
+ DataAsyncBufRead<'a, AsciiTable>
+ 'a,
{
pub async fn new(reader: &'a mut R) -> Result<AsyncPrimaryHDU<'a, R>, Error> {
let mut num_bytes_read = 0;
let mut card_80_bytes_buf = [0; 80];
// SIMPLE
consume_next_card_async(reader, &mut card_80_bytes_buf, &mut num_bytes_read).await?;
let _ = check_card_keyword(&card_80_bytes_buf, b"SIMPLE ")?;
let hdu =
AsyncHDU::<'a, R, Image>::new(reader, &mut num_bytes_read, &mut card_80_bytes_buf)
.await?;
Ok(AsyncPrimaryHDU(hdu))
}
async fn consume(self) -> Result<Option<&'a mut R>, Error> {
self.0.consume().await
}
pub async fn next(self) -> Result<Option<AsyncXtensionHDU<'a, R>>, Error> {
if let Some(reader) = self.consume().await? {
let hdu = AsyncXtensionHDU::new(reader).await?;
Ok(Some(hdu))
} else {
Ok(None)
}
}
}
impl<'a, R> Deref for AsyncPrimaryHDU<'a, R>
where
R: DataAsyncBufRead<'a, Image>
+ DataAsyncBufRead<'a, BinTable>
+ DataAsyncBufRead<'a, AsciiTable>
+ 'a,
{
type Target = AsyncHDU<'a, R, Image>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<'a, R> DerefMut for AsyncPrimaryHDU<'a, R>
where
R: DataAsyncBufRead<'a, Image>
+ DataAsyncBufRead<'a, BinTable>
+ DataAsyncBufRead<'a, AsciiTable>
+ 'a,
{
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}*/
/*
use std::pin::Pin;
use futures::AsyncBufRead;
/// Structure storing the content of one HDU (i.e. Header Data Unit)
/// of a fits file that is opened in an async way
#[derive(Debug)]
pub struct AsyncHDU<'a, R>
where
R: AsyncDataRead<'a>
{
/// The header part that stores all the cards
pub header: PrimaryHeader,
/// The data part
pub data: R::Data,
}
impl<'a, R> AsyncHDU<'a, R>
where
R: AsyncDataRead<'a> + std::marker::Unpin
{
pub async fn new(mut reader: &'a mut R) -> Result<AsyncHDU<'a, R>, Error> {
let mut bytes_read = 0;
/* 1. Parse the header first */
let header = PrimaryHeader::parse_async(reader, &mut bytes_read).await?;
// At this point the header is valid
let num_pixels = (0..header.get_naxis())
.map(|idx| header.get_axis_size(idx + 1).unwrap())
.product();
let bitpix = header.get_bitpix();
/* 2. Skip the next bytes to a new 2880 multiple of bytes
This is where the data block should start */
let off_data_block = 2880 - bytes_read % 2880;
Pin::new(&mut reader).consume(off_data_block);
let data = unsafe { reader.read_data_block(bitpix, num_pixels) };
Ok(Self {
header,
data
})
}
}
*/