fitsrs 0.4.1

Implementation of the FITS image parser
Documentation
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
//! Module implementing the header part of a HDU
//!
//! A header consists of a list a of [cards](Card) where each card is a line of
//! 80 ASCII characters.
use futures::{AsyncRead, AsyncReadExt};
use indexmap::map::{IndexMap, Keys};
use log::warn;
use serde::de::{value::MapDeserializer, IntoDeserializer};
use serde::{Deserialize, Serialize};

pub mod extension;

pub use extension::Xtension;

use std::convert::TryFrom;
use std::io::Read;
use std::ops::Deref;

use crate::{
    card::{self, *},
    error::Error,
};
use serde_repr::{Deserialize_repr, Serialize_repr};

pub fn consume_next_card<R: Read>(
    reader: &mut R,
    buf: &mut [u8; 80],
    bytes_read: &mut usize,
) -> Result<(), Error> {
    reader.read_exact(buf)?;
    *bytes_read += 80;

    Ok(())
}

pub async fn consume_next_card_async<R: AsyncRead + std::marker::Unpin>(
    reader: &mut R,
    buf: &mut [u8; 80],
    bytes_read: &mut usize,
) -> Result<(), Error> {
    *bytes_read += 80;
    reader
        .read_exact(buf)
        .await
        .map_err(|_| Error::FailReadingNextBytes)?;
    Ok(())
}

pub fn check_card_keyword(card: &[u8; 80], keyword: &[u8; 8]) -> Result<card::Value, Error> {
    if card[..8] == keyword[..] {
        if let Card::Value { value, .. } = Card::try_from(card)? {
            Ok(value)
        } else {
            Err(Error::FailFindingKeyword(
                std::str::from_utf8(keyword)?.to_owned(),
            ))
        }
    } else {
        Err(Error::FailFindingKeyword(
            std::str::from_utf8(keyword)?.to_owned(),
        ))
    }
}

#[derive(Debug, PartialEq, Serialize_repr, Deserialize_repr, Clone, Copy)]
#[repr(i8)]
pub enum Bitpix {
    U8 = 8,
    I16 = 16,
    I32 = 32,
    I64 = 64,
    F32 = -32,
    F64 = -64,
}

impl Bitpix {
    pub fn byte_size(&self) -> usize {
        ((*self as i8).unsigned_abs() as usize) >> 3
    }
}

#[derive(Debug, PartialEq, Serialize, Clone)]
#[serde(transparent)]
pub struct ValueMap {
    values: IndexMap<String, Value>,
}

impl ValueMap {
    /// Get the value of a card, returns `None` if the card is not
    /// found or is not a value card.
    pub fn get(&self, key: &str) -> Option<&Value> {
        self.values.get(key)
    }

    /// Get the value a specific card and try to parse the value. Returns an
    /// error if the value is not in the map or the asking type does not match
    /// the true inner type of the value.
    ///
    /// # Params
    /// * `key` - The key of a card
    pub fn get_parsed<'de, T>(&'de self, key: &str) -> Result<T, Error>
    where
        T: Deserialize<'de>,
    {
        // We use `Value::Undefined` fallback to handle `T` being an `Option<_>`.
        T::deserialize(self.get(key).unwrap_or(&Value::Undefined))
    }

    /// Return an iterator over all key-[value](Card::Value) pairs in the FITS
    /// header.
    pub fn iter(&self) -> ValueMapIter<'_> {
        ValueMapIter {
            inner: self.values.iter(),
        }
    }

    /// Get the keyword corresponding to a specific value, returns `None` if
    /// no card are found with that value. If multiple cards do have the same value
    /// then the first found card's keyword will be returned.
    ///
    /// # Params
    /// * `value` - The value of a card
    pub fn get_keyword(&self, val: &Value) -> Option<&str> {
        self.iter()
            .find_map(|(name, value)| (value == val).then_some(name))
    }

    /// Return an iterator over all keywords representing a FITS [Card::Value]
    /// in the FITS header.
    pub fn keywords(&self) -> Keys<'_, String, Value> {
        self.values.keys()
    }

    /* Mandatory keywords parsing */

    fn check_for_bitpix(&self) -> Result<Bitpix, Error> {
        self.get_parsed("BITPIX")
    }

    fn check_for_naxis(&self) -> Result<u64, Error> {
        self.get_parsed("NAXIS")
    }

    fn check_for_naxisi(&self, i: usize) -> Result<u64, Error> {
        self.get_parsed(&format!("NAXIS{i}"))
    }

    fn check_for_gcount(&self) -> Result<u64, Error> {
        self.get_parsed("GCOUNT")
    }

    fn check_for_pcount(&self) -> Result<u64, Error> {
        self.get_parsed("PCOUNT")
    }

    fn check_for_tfields(&self) -> Result<usize, Error> {
        self.get_parsed("TFIELDS")
    }
}

pub struct ValueMapIter<'map> {
    inner: indexmap::map::Iter<'map, String, Value>,
}

impl<'map> Iterator for ValueMapIter<'map> {
    type Item = (&'map str, &'map Value);

    fn next(&mut self) -> Option<Self::Item> {
        self.inner.next().map(|(k, v)| (k.as_str(), v))
    }

    fn size_hint(&self) -> (usize, Option<usize>) {
        self.inner.size_hint()
    }
}

impl<'de> IntoDeserializer<'de, Error> for &'de ValueMap {
    type Deserializer = MapDeserializer<'de, ValueMapIter<'de>, Error>;

    fn into_deserializer(self) -> Self::Deserializer {
        MapDeserializer::new(self.iter())
    }
}

/// The header part of an [crate::hdu::HDU].
#[derive(Debug, PartialEq, Serialize, Clone)]
pub struct Header<X> {
    /// All cards in the order they appear in the header.
    cards: Vec<Card>,
    /// The value of all cards that represent a [Card::Value] mapped by keyword
    /// `name`.
    ///
    /// * A keyword `name` is a trimmed string and not the eight-byte keyword
    ///   buffer used on the [Card].
    /// * If contrary to the FITS standard, a keyword appears more than once in
    ///   the header, the value of the last [Card::Value] is returned.
    values: ValueMap,
    /// Mandatory keywords for fits ext parsing.
    xtension: X,
}

impl<X> Deref for Header<X> {
    type Target = ValueMap;

    fn deref(&self) -> &Self::Target {
        &self.values
    }
}

impl<X> Header<X>
where
    X: Xtension + std::fmt::Debug,
{
    pub(crate) fn parse(cards: Vec<Card>) -> Result<Self, Error> {
        let values = process_cards(&cards)?;

        let xtension: X = Xtension::parse(&values)?;

        Ok(Self {
            cards,
            values,
            xtension,
        })
    }

    /// Get the gcount value given by the `PCOUNT` card
    pub fn get_xtension(&self) -> &X {
        &self.xtension
    }

    /// Return an iterator over all [cards](Card) in the FITS header.
    pub fn cards(&self) -> impl Iterator<Item = &Card> + '_ {
        self.cards.iter()
    }

    /// Return an iterator over the processing history of the header, i.e. all
    /// [cards](Card) with the `HISTORY` keyword.
    ///
    pub fn history(&self) -> impl Iterator<Item = &String> + '_ {
        self.cards.iter().filter_map(move |c| {
            if let Card::History(string) = c {
                Some(string)
            } else {
                None
            }
        })
    }
}

fn process_cards(cards: &[Card]) -> Result<ValueMap, Error> {
    let mut values = IndexMap::new();
    let mut kw: Option<String> = None;

    for (i, card) in cards.iter().enumerate() {
        match card {
            Card::Value { name, value } | Card::Hierarch { name, value } => {
                if kw.is_some() {
                    // FITS document 4.2.1.2: value ends with a '&' but is not immediately followed
                    // by a CONTINUE record. We thus consider it as part of the previous valued string.
                    kw = None;
                }
                values.insert(name.to_owned(), value.to_owned());
                if value.continued() {
                    kw = Some(name.to_owned());
                }
            }
            Card::Continuation { string, comment } => {
                if let Some(ref name) = kw {
                    if let Some(v) = values.get_mut(name) {
                        v.append(string, comment);
                        if !v.continued() {
                            kw = None
                        }
                    } else {
                        unreachable!("algorithm should have added value for continued keyword")
                    }
                } else {
                    // FITS document 4.2.1.2: Orphaned CONTINUE keyword record case
                    // should be interpreted as containing commentary text (similar to COMMENT keyword)
                    // We then change the card to a comment one, emitting a warning for that
                    // as it may introduce an error with repect to what the author of the file meant
                    warn!("Orphaned CONTINUE found (i.e. which is not preceded by a '&' character).
                          The parser will consider it as a COMMENT record as stated by the FITS document 4.2.1.2.
                          Card is found at index {i}"
                    );
                }
            }
            Card::Xtension { x, .. } => {
                if kw.is_some() {
                    // FITS document 4.2.1.2: value ends with a '&' but is not immediately followed
                    // by a CONTINUE record. We thus consider it as part of the previous valued string.

                    kw = None;
                }

                values.insert(
                    "XTENSION".to_owned(),
                    Value::String {
                        value: x.to_string(),
                        comment: None,
                    },
                );
            }
            Card::End => {
                if i + 1 == cards.len() {
                    return Ok(ValueMap { values });
                } else {
                    unreachable!("cards trailing after the END card")
                }
            }
            // TODO log skipped card at debug level
            _ => ( /* NOOP */),
        }
    }
    Err(Error::StaticError("Missing END card"))
}

#[cfg(test)]
mod tests {
    use crate::card::Card;
    use crate::error::Error;
    use crate::fits::Fits;
    use crate::hdu::HDU;

    use core::panic;
    use std::collections::VecDeque;
    use std::fs::File;

    use std::io::Cursor;

    use super::check_card_keyword;
    // use Iterator;

    use super::CardBuf;
    use std::iter::Iterator;

    use super::Value;

    #[test]
    fn card_keyword() {
        let card =
            b"STRKEY  = 'Some text'                                                           ";
        if let Ok(Value::String { value, .. }) = check_card_keyword(card, b"STRKEY  ") {
            assert_eq!(value, "Some text")
        } else {
            panic!("could not find extension in card")
        }
    }

    #[test]
    fn primary_hdu_without_simple_keyword() -> Result<(), Error> {
        let data = mock_fits_data([
            b"WRONGKW =                    T / this is a fake FITS file                       ",
            b"BITPIX  =                    8 / byte sized numbers                             ",
            b"NAXIS   =                    0 / no data arrays                                 ",
            b"END                                                                             ",
        ]);
        let reader = Cursor::new(data);
        let mut fits = Fits::from_reader(reader);
        let hdu = fits.next().expect("Should contain a primary HDU");
        if let Err(Error::DynamicError(e)) = hdu {
            assert_eq!(
                e,
                "Invalid FITS file: expected `SIMPLE` keyword in first card, found `WRONGKW`"
            );
            Ok(())
        } else {
            panic!("parsing should fail with a keyword error")
        }
    }

    #[test]
    fn primary_hdu_with_no_data() -> Result<(), Error> {
        let data = mock_fits_data([
            b"SIMPLE  =                    T / this is a fake FITS file                       ",
            b"BITPIX  =                    8 / byte sized numbers                             ",
            b"NAXIS   =                    0 / no data arrays                                 ",
            b"COMMENT some contextual comment on the header                                   ",
            b"COMMENT ... over two lines                                                      ",
            b"HISTORY this was processed manually using vscode                                ",
            b"COMMENT comment on the history?                                                 ",
            b"HISTORY did some more processing...                                             ",
            b"END                                                                             ",
        ]);
        let reader = Cursor::new(data);
        let mut fits = Fits::from_reader(reader);
        let hdu = fits.next().expect("Should contain a primary HDU").unwrap();
        assert!(matches!(hdu, HDU::Primary(_)));
        if let HDU::Primary(hdu) = hdu {
            let mut cards = hdu.get_header().cards();
            assert_eq!(
                cards.next(),
                Some(&Card::Value {
                    name: "SIMPLE".to_owned(),
                    value: Value::Logical {
                        value: true,
                        comment: Some(" this is a fake FITS file".to_owned())
                    }
                })
            );
            assert_eq!(
                dbg!(cards.next()),
                Some(&Card::Value {
                    name: "BITPIX".to_owned(),
                    value: Value::Integer {
                        value: 8,
                        comment: Some(" byte sized numbers".to_owned())
                    }
                })
            );
            assert_eq!(
                cards.next(),
                Some(&Card::Value {
                    name: "NAXIS".to_owned(),
                    value: Value::Integer {
                        value: 0,
                        comment: Some(" no data arrays".to_owned())
                    }
                })
            );
            assert_eq!(
                cards.next(),
                Some(&Card::Comment(
                    "some contextual comment on the header".to_owned()
                ))
            );
            assert_eq!(
                cards.next(),
                Some(&Card::Comment("... over two lines".to_owned()))
            );
            assert_eq!(
                cards.next(),
                Some(&Card::History(
                    "this was processed manually using vscode".to_owned()
                ))
            );
            assert_eq!(
                cards.next(),
                Some(&Card::Comment("comment on the history?".to_owned()))
            );
            assert_eq!(
                cards.next(),
                Some(&Card::History("did some more processing...".to_owned()))
            );
            assert_eq!(cards.next(), Some(&Card::End));
            assert_eq!(cards.next(), None);

            let header = hdu.get_header();

            let mut history = header.history();
            assert_eq!(
                history.next(),
                Some(&"this was processed manually using vscode".to_string())
            );
            assert_eq!(
                history.next(),
                Some(&"did some more processing...".to_string())
            );
            assert_eq!(history.next(), None);
        }

        Ok(())
    }

    #[test]
    fn end_card_not_found() {
        let data = mock_fits_data([
            b"SIMPLE  =                    T / Standard FITS Format                           ",
            b"BITPIX  =                    8 / Character data                                 ",
            b"NAXIS   =                    0 / No Image --- just extension(s)                 ",
            b"EXTEND  =                    T / There are standard extensions                  ",
        ]);
        let reader = Cursor::new(data);
        let mut fits = Fits::from_reader(reader);
        let hdu = fits.next().expect("Should contain a primary HDU");

        assert_eq!(Err(Error::Io(std::io::ErrorKind::UnexpectedEof)), hdu);
        // As the primary hdu parsing failed (EOF reached), next call to fits should result in None
        assert_eq!(fits.next(), None);
    }

    #[test]
    fn blank_interpreted_as_comments() -> Result<(), Error> {
        let data = mock_fits_data([
            b"SIMPLE  =                    T / Standard FITS Format                           ",
            b"BITPIX  =                    8 / Character data                                 ",
            b"NAXIS   =                    0 / No Image --- just extension(s)                 ",
            b"EXTEND  =                    T / There are standard extensions                  ",
            b"ORIGIN  = 'xml2fits_v1.95'     / Converted from XML-Astrores to FITS            ",
            b"                        e-mail: question@simbad.u-strasbg.fr                    ",
            b"LONGSTRN= 'OGIP 1.0'           / Long string convention (&/CONTINUE) may be used",
            b"DATE    = '2018-04-12'         / Written on 2018-04-12:13:25:09 (GMT)           ",
            b"                            by: apache@vizier.u-strasbg.fr                      ",
            b"        **********************************************************              ",
            b"            EXCERPT from catalogues stored in VizieR (CDS)                      ",
            b"                        with the following conditions:                          ",
            b"        **********************************************************              ",
            b"                                                                                ",
            b"        VizieR Astronomical Server vizier.u-strasbg.fr                          ",
            b"        Date: 2018-04-12T13:25:09 [V1.99+ (14-Oct-2013)]                        ",
            b"        In case of problem, please report to: cds-question@unistra.fr           ",
            b"                                                                                ",
            b"INFO    = 'votable-version=1.99+ (14-Oct-2013)' / #                             ",
            b"INFO    = '-ref=VIZ5acf5dfe7d66' / #                                            ",
            b"INFO    = '-out.max=50'        / #                                              ",
            b"END                                                                             ",
        ]);
        let reader = Cursor::new(data);
        let mut fits = Fits::from_reader(reader);
        let hdu = fits.next().expect("Should contain a primary HDU").unwrap();
        assert!(matches!(hdu, HDU::Primary(_)));
        if let HDU::Primary(hdu) = hdu {
            let mut cards = hdu.get_header().cards();
            assert_eq!(
                cards.next(),
                Some(&Card::Value {
                    name: "SIMPLE".to_owned(),
                    value: Value::Logical {
                        value: true,
                        comment: Some(" Standard FITS Format".to_owned())
                    }
                })
            );
            assert_eq!(
                dbg!(cards.next()),
                Some(&Card::Value {
                    name: "BITPIX".to_owned(),
                    value: Value::Integer {
                        value: 8,
                        comment: Some(" Character data".to_owned())
                    }
                })
            );
            assert_eq!(
                cards.next(),
                Some(&Card::Value {
                    name: "NAXIS".to_owned(),
                    value: Value::Integer {
                        value: 0,
                        comment: Some(" No Image --- just extension(s)".to_owned())
                    }
                })
            );
            assert_eq!(
                cards.next(),
                Some(&Card::Value {
                    name: "EXTEND".to_owned(),
                    value: Value::Logical {
                        value: true,
                        comment: Some(" There are standard extensions".to_owned())
                    }
                })
            );
            assert_eq!(
                cards.next(),
                Some(&Card::Value {
                    name: "ORIGIN".to_owned(),
                    value: Value::String {
                        value: "xml2fits_v1.95".to_owned(),
                        comment: Some(" Converted from XML-Astrores to FITS".to_owned())
                    }
                })
            );
            assert_eq!(
                cards.next(),
                Some(&Card::Comment(
                    "                e-mail: question@simbad.u-strasbg.fr".to_string()
                ))
            );
            assert_eq!(
                cards.next(),
                Some(&Card::Value {
                    name: "LONGSTRN".to_owned(),
                    value: Value::String {
                        value: "OGIP 1.0".to_owned(),
                        comment: Some(
                            " Long string convention (&/CONTINUE) may be used".to_owned()
                        )
                    }
                })
            );

            assert_eq!(
                cards.next(),
                Some(&Card::Value {
                    name: "DATE".to_owned(),
                    value: Value::String {
                        value: "2018-04-12".to_owned(),
                        comment: Some(" Written on 2018-04-12:13:25:09 (GMT)".to_owned())
                    }
                })
            );
            /*b"                            by: apache@vizier.u-strasbg.fr                      ",
            b"        **********************************************************              ",
            b"            EXCERPT from catalogues stored in VizieR (CDS)                      ",
            b"                        with the following conditions:                          ",
            b"        **********************************************************              ",
            b"                                                                                ",
            b"        VizieR Astronomical Server vizier.u-strasbg.fr                          ",
            b"        Date: 2018-04-12T13:25:09 [V1.99+ (14-Oct-2013)]                        ",
            b"        In case of problem, please report to: cds-question@unistra.fr           ",
            b"                                                                                ",*/
            assert_eq!(
                cards.next(),
                Some(&Card::Comment(
                    "                    by: apache@vizier.u-strasbg.fr".to_string()
                ))
            );
            assert_eq!(
                cards.next(),
                Some(&Card::Comment(
                    "**********************************************************".to_string()
                ))
            );
            assert_eq!(
                cards.next(),
                Some(&Card::Comment(
                    "    EXCERPT from catalogues stored in VizieR (CDS)".to_string()
                ))
            );
            assert_eq!(
                cards.next(),
                Some(&Card::Comment(
                    "                with the following conditions:".to_string()
                ))
            );
            assert_eq!(
                cards.next(),
                Some(&Card::Comment(
                    "**********************************************************".to_string()
                ))
            );

            assert_eq!(cards.next(), Some(&Card::Space));

            assert_eq!(
                cards.next(),
                Some(&Card::Comment(
                    "VizieR Astronomical Server vizier.u-strasbg.fr".to_string()
                ))
            );
            assert_eq!(
                cards.next(),
                Some(&Card::Comment(
                    "Date: 2018-04-12T13:25:09 [V1.99+ (14-Oct-2013)]".to_string()
                ))
            );
            assert_eq!(
                cards.next(),
                Some(&Card::Comment(
                    "In case of problem, please report to: cds-question@unistra.fr".to_string()
                ))
            );
        }

        Ok(())
    }

    /// panics if N > 36
    fn mock_fits_data<const N: usize>(cards: [&CardBuf; N]) -> [u8; 2880] {
        let mut data = [b' '; 2880];
        let mut cursor = 0;
        for card in cards {
            data[cursor..cursor + 80].copy_from_slice(card);
            cursor += 80;
        }
        data
    }

    #[test]
    fn test_fits_keywords_iter() {
        let f = File::open("samples/misc/SN2923fxjA.fits").unwrap();

        let reader = std::io::BufReader::new(f);
        let mut hdu_list = Fits::from_reader(reader);

        let hdu = hdu_list.next().unwrap().unwrap();
        match hdu {
            HDU::Primary(hdu) => {
                let mut actuals = hdu.get_header().keywords().collect::<Vec<_>>();
                actuals.sort_unstable();

                /* COMMENT and HISTORY are not part of the cards having values which is what returns keywords */
                let mut expected = VecDeque::from(vec![
                    "BAYERIND", "BITCAMPX", "BITPIX", "CALPHOT", "CCD-TEMP", "CD1_1", "CD1_2",
                    "CD2_1", "CD2_2", "CDELT1", "CDELT2", "CDELTM1",
                    "CDELTM2", /*,  "COMMENT" */
                    "COMPRESS", "CRPIX1", "CRPIX2", "CRVAL1", "CRVAL2", "CTYPE1", "CTYPE2",
                    "CUNIT1", "CUNIT2", "CVF", "DATAMAX", "DATAMIN", "DATE", "DATE-OBS", "DEC",
                    "DEWPOINT", "DIAMETER", "ERRFLUX", "EXPOSURE", "FILTERS", "FOCAL", "FOCUSPOS",
                    "FOCUSTMP", "GAIN_ELE", /*"HISTORY", */ "HUMIDITY", "IMGTYPE", "INSTRUME",
                    "MAGREF", "MIRORX", "NAXIS", "NAXIS1", "NAXIS2", "OBJCTDEC", "OBJCTRA",
                    "OBSERVER", "OFFSET_E", "ORIGIN", "P3DSPHER", "PCXASTRO", "PCYASTRO",
                    "PDEC_REF", "PDIMPOL", "PIERSIDE", "PPLATESD", "PPXC", "PPYC", "PRADIUSX",
                    "PRADIUSY", "PRA_REF", "PRESSURE", "PSOLDC1", "PSOLDC10", "PSOLDC11",
                    "PSOLDC12", "PSOLDC13", "PSOLDC14", "PSOLDC15", "PSOLDC16", "PSOLDC17",
                    "PSOLDC18", "PSOLDC19", "PSOLDC2", "PSOLDC20", "PSOLDC21", "PSOLDC22",
                    "PSOLDC23", "PSOLDC24", "PSOLDC25", "PSOLDC26", "PSOLDC27", "PSOLDC28",
                    "PSOLDC29", "PSOLDC3", "PSOLDC30", "PSOLDC31", "PSOLDC32", "PSOLDC33",
                    "PSOLDC34", "PSOLDC35", "PSOLDC36", "PSOLDC4", "PSOLDC5", "PSOLDC6", "PSOLDC7",
                    "PSOLDC8", "PSOLDC9", "PSOLRA1", "PSOLRA10", "PSOLRA11", "PSOLRA12",
                    "PSOLRA13", "PSOLRA14", "PSOLRA15", "PSOLRA16", "PSOLRA17", "PSOLRA18",
                    "PSOLRA19", "PSOLRA2", "PSOLRA20", "PSOLRA21", "PSOLRA22", "PSOLRA23",
                    "PSOLRA24", "PSOLRA25", "PSOLRA26", "PSOLRA27", "PSOLRA28", "PSOLRA29",
                    "PSOLRA3", "PSOLRA30", "PSOLRA31", "PSOLRA32", "PSOLRA33", "PSOLRA34",
                    "PSOLRA35", "PSOLRA36", "PSOLRA4", "PSOLRA5", "PSOLRA6", "PSOLRA7", "PSOLRA8",
                    "PSOLRA9", "PSOLX1", "PSOLX10", "PSOLX11", "PSOLX12", "PSOLX13", "PSOLX14",
                    "PSOLX15", "PSOLX16", "PSOLX17", "PSOLX18", "PSOLX19", "PSOLX2", "PSOLX20",
                    "PSOLX21", "PSOLX22", "PSOLX23", "PSOLX24", "PSOLX25", "PSOLX26", "PSOLX27",
                    "PSOLX28", "PSOLX29", "PSOLX3", "PSOLX30", "PSOLX31", "PSOLX32", "PSOLX33",
                    "PSOLX34", "PSOLX35", "PSOLX36", "PSOLX4", "PSOLX5", "PSOLX6", "PSOLX7",
                    "PSOLX8", "PSOLX9", "PSOLY1", "PSOLY10", "PSOLY11", "PSOLY12", "PSOLY13",
                    "PSOLY14", "PSOLY15", "PSOLY16", "PSOLY17", "PSOLY18", "PSOLY19", "PSOLY2",
                    "PSOLY20", "PSOLY21", "PSOLY22", "PSOLY23", "PSOLY24", "PSOLY25", "PSOLY26",
                    "PSOLY27", "PSOLY28", "PSOLY29", "PSOLY3", "PSOLY30", "PSOLY31", "PSOLY32",
                    "PSOLY33", "PSOLY34", "PSOLY35", "PSOLY36", "PSOLY4", "PSOLY5", "PSOLY6",
                    "PSOLY7", "PSOLY8", "PSOLY9", "PSSX", "PSSY", "RA", "READOUTT", "REFFLUX",
                    "SIMPLE", "SITELAT", "SITELONG", "STACKNB", "STARCNT", "SWCREATE", "TELESCOP",
                    "TEMPEXT", "UT", "WINDIR", "WINSPEED", "X1", "X2", "XPIXELSZ", "XPIXSZ", "Y1",
                    "Y2", "YPIXELSZ", "YPIXSZ",
                ]);

                for actual in actuals {
                    assert_eq!(actual, expected.pop_front().unwrap())
                }
            }
            _ => unreachable!(),
        }
    }
}