Module Fits.Header
Headers.
A header is its records in file order, each the 80 bytes the file held: order, duplicates, blank records and bytes outside ASCII 32–126 are kept, so every record a program does not edit is written back byte for byte. A value is parsed when it is asked for, and fails there alone.
A record is commentary when its keyword is COMMENT, HISTORY or blank, or its bytes 9–10 are not "= ", unless it starts with "HIERARCH " and holds =.
Keywords. A standard keyword is 1 to 8 characters of A–Z 0–9 - _. A hierarchical keyword is the tokens between "HIERARCH " and the first = of a record, joined by single spaces: two or more tokens, or one longer than 8 bytes, each of bytes 33–126 other than =, in the case written, as in "ESO DET DIT". Keywords compare exactly. Header.get, Header.find, Header.set and Header.remove raise Invalid_argument on a name of neither form, such as "naxis", and on COMMENT, HISTORY, blank and CONTINUE, which Header.commentary reads.
Duplicates. A keyword repeated with different values is indeterminate (§4.1.2.3): get returns the value when every card agrees, and is an Error naming two cards that disagree otherwise.
type tThe type for headers: records in file order, without END.
of_string ~name s reads 80-byte records back to back up to END, or, when s holds a newline, lines of at most 80 bytes up to END, as .head files hold them. name starts the header's errors.
to_string h is h's records, END, and spaces to a multiple of 2880 bytes.
pp formats a header one record per line, trailing spaces dropped.
get v k h is the value of keyword k read with v. It is an Error if k is absent or undefined, if a card does not read, or if its cards disagree.
Raises Invalid_argument if k is not a keyword (see above).
find is get with Ok None for an absent or undefined keyword.
set ~comment v k x h is h with one card giving k the value x, at the place of k's first card or appended, its later cards removed. comment replaces the card's comment; without it the comment is kept, cut to fit beside the new value.
A value that fits bytes 11–30 is written in the fixed format of §4.2.2–§4.2.4, others in the free format from byte 11. A string over 68 bytes continues over CONTINUE records. get v k (set v k x h) is Ok x for every finite float and every string without trailing spaces.
Raises Invalid_argument if k is not a keyword, on a non-finite float, on a byte outside ASCII 32–126, on Value.text that is not one FITS value, on a hierarchical keyword that leaves no room for the value, and on a comment that does not fit beside a value other than a string.
remove k h is h without k's cards and their CONTINUE records.
Raises Invalid_argument as get does.
commentary k h is the text of h's commentary records whose keyword is k (bytes 9–80, trailing spaces dropped), in order. k is "COMMENT", "HISTORY", "" for blank, or any other keyword whose records have no value indicator.