Posted by
Torsten Roehl on
Oct 29, 2019; 6:34am
URL: http://astroimagej.170.s1.nabble.com/No-valid-Fits-header-tp177p1234.html
Bug in FITS format!
Dear Karin Collins,
i wrote a little Plugin to create 1D-Spectrumfiles in fits-format from a 2D-Image, just for me as a hobby.
For this purpose i studied the FITS_WRITER code, implemented in ij and aij.
I detected a bug in the way the fits header in ij/aij are generated.
==================================
Problem
==================================
Fits files generated by ij/aij producing header error, because the NAXISX value
field are not in integer fixed format.
I checked my 1d-spectrum fits file with the
Nasa FITS File Verifier: https://fits.gsfc.nasa.gov/fits_verify.html
Then i checked arbitary ij/aij generated fits images e.g. the
output of an image of size 76x22 will result in this message from the NASA verifier:
----------------------HDU 1: Primary Array -------------------
*** Error: NAXIS1 mandatory keyword is not in integer fixed format:
NAXIS1 = 76 / length of data axis 1
-------------------^
*** Error: NAXIS2 mandatory keyword is not in integer fixed format:
NAXIS2 = 22 / length of data axis 2
==================================
Fix
==================================
plugin: ij.plugin
class: FITS_Writer
method: createHeader
---------------------------
orginal file:
appendFile(writeCard("NAXIS1", " "+ip.getWidth(), "length of data axis 1"), path);
appendFile(writeCard("NAXIS2", " "+ip.getHeight(), "length of data axis 2"), path);
possible bugfix:
appendFile(writeCard("NAXIS1", naxis(ip.getWidth()), "length of data axis 1"), path);
appendFile(writeCard("NAXIS2", naxis(ip.getHeight()), "length of data axis 2"), path);
private String naxis(int value) {
int length = 20 - String.valueOf(value).length();
String spaces = String.format("%" + length + "s", "");
return spaces + value;
}
--------------------------
The currently implemented method will create invalide header length, depending on the size of the image. This could be
a problem wenn using third party software with very restriced fits-header handling.
kind regards torsten roehl
(because this is my first post i hope everthing is readable

)
ps: should i report this mail also to ij?