Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterate over all cards in a header #9

Open
chrsoo opened this issue Dec 28, 2024 · 2 comments
Open

Iterate over all cards in a header #9

chrsoo opened this issue Dec 28, 2024 · 2 comments

Comments

@chrsoo
Copy link
Contributor

chrsoo commented Dec 28, 2024

Hi,

From what I can tell the fitsrs library only supports retrieving Cards of a Header by Keyword.

Is this correct or is there a way of iterate over all Cards in Header that does not assume prior knowledge of the possible Keywords?

chrsoo added a commit to chrsoo/fitsrs that referenced this issue Dec 28, 2024
chrsoo added a commit to chrsoo/fitsrs that referenced this issue Dec 28, 2024
@bmatthieu3
Copy link
Collaborator

Hi @chrsoo,

Thank you, I merged the PR with 2,3 unrelated things (git-lfs removal among others).

I added a test retrieving calling cards iter. I realize Keyword may not be very friendly from the user perspective. As a minor future update, would it be better to have a proper Keyword type being just a [u8; 8] that has a method to get its owned String trimmed value (the method you made on Card) ? What do you think ?

@chrsoo
Copy link
Contributor Author

chrsoo commented Jan 7, 2025

Great, thanks!

I just realised that the Card method really should have been a &str like so:

impl Card {
    ...
    /// Return the ASCII trimmed keyword.
    pub fn keyword(&self) -> Result<&str, std::str::Utf8Error> {
        std::str::from_utf8(self.kw.trim_ascii())
    }
}

No point in copying the buffer if an owned value is not needed. If an owned value is needed there is &str.to_owned() or &str.to_string().

Regarding Keyword as a struct wrapping [u8;8], it could make sense, but I am wondering why we are not using strings? Why not parse it up front when reading the keyword from file?

The convenience method I added is only half-way as a keyword should be infallible. Per the FITS standard the whole header must conform to valid ASCII. Should the UTF8 conversion fail all the same, I think the header record should be ignored and a parser error logged or written to stderr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants