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

Standard header comment duplicated on re-save #126

Open
bensetterholm opened this issue Jan 3, 2020 · 1 comment
Open

Standard header comment duplicated on re-save #126

bensetterholm opened this issue Jan 3, 2020 · 1 comment

Comments

@bensetterholm
Copy link

When I write to a new FITS file using a FITSHeader object extracted from a previously opened FITS file, the comment block

COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H

is duplicated. For example:

julia> using FITSIO

julia> # Create a dummy file

julia> hdr = FITSHeader(["HELLO"], ["World"], [""]); data = rand(10,10);

julia> FITS("helloworld.fits", "w") do file
           write(file, data, header=hdr)
       end

shell> dfits helloworld.fits
====> file helloworld.fits (main) <====
SIMPLE  =                    T / file does conform to FITS standard
BITPIX  =                  -64 / number of bits per data pixel
NAXIS   =                    2 / number of data axes
NAXIS1  =                   10 / length of data axis 1
NAXIS2  =                   10 / length of data axis 2
EXTEND  =                    T / FITS dataset may contain extensions
COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H
HELLO   = 'World   '
END

julia> # Read in the header of the dummy file

julia> hdr2 = FITS("helloworld.fits", "r") do file
           read_header(file[1])
       end
SIMPLE  =                    T / file does conform to FITS standard
BITPIX  =                  -64 / number of bits per data pixel
NAXIS   =                    2 / number of data axes
NAXIS1  =                   10 / length of data axis 1
NAXIS2  =                   10 / length of data axis 2
EXTEND  =                    T / FITS dataset may contain extensions
COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronom
COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H
HELLO   =              'World'

julia> # Write a new file with the old header

julia> FITS("helloagain.fits", "w") do file
           write(file, data, header=hdr2)
       end

shell> dfits helloagain.fits
====> file helloagain.fits (main) <====
SIMPLE  =                    T / file does conform to FITS standard
BITPIX  =                  -64 / number of bits per data pixel
NAXIS   =                    2 / number of data axes
NAXIS1  =                   10 / length of data axis 1
NAXIS2  =                   10 / length of data axis 2
EXTEND  =                    T / FITS dataset may contain extensions
COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H
COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H
HELLO   = 'World   '
END

I also note that the string representation of the FITSHeader object cuts off the final "y" in the first COMMENT card.

@giordano
Copy link
Member

giordano commented Jan 3, 2020

Wow, thanks for the great reproducible example!

My understanding is that the problem is that the comment extends over multiple keywords. Libcfitsio.fits_write_comment calls ffpcom from CFITSIO, which, according to the documentation,

If the comment string is too long to fit on a single keyword (72 chars) then it will automatically be continued on multiple CONTINUE keywords.

When fits_write_header iterates over all keywords, it writes the multi-keyword comment multiple lines.

@kbarbary any idea how to best deal with this?

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