#760 closed defect (fixed)
Can't write NaN or Inf to a FITS header
| Reported by: | Paul Price | Owned by: | Paul Price |
|---|---|---|---|
| Priority: | high | Milestone: | |
| Component: | fits | Version: | unspecified |
| Severity: | normal | Keywords: | |
| Cc: | rhl@… |
Description
Due to a deficiency in cfitsio, writing NaN or Inf to a FITS header (at least as
a floating-point type) is not possible.
Here's the cfitsio error stack from attempting to write an F32 NaN to a header
keyword:
FITSIO status = 402: bad float to string conversion
Error in ffr2e: float value is a NaN or INDEF
Note that cfitsio seems to be explicitly blocking NaN. This is affirmed by
inspection of putkey.c:
/* test if output string is 'NaN', 'INDEF', or 'INF' */
if (strchr(cval, 'N'))
{
ffpmsg("Error in ffr2f: float value is a NaN or INDEF");
*status = BAD_F2C;
}
Note:
See TracTickets
for help on using tickets.

This behaviour of cfitsio is quite annoying, since we'd like to be able to write
NaN and Inf. I choose to write these values as strings, and filter them on the
read. This solution produces FITS files that we can read without problems
(write a NAN, read a NAN). We will likely get problems when trying to read FITS
files with NAN/INF headers with other software packages (since they won't know
to trap the string "NaN" or "Inf" and convert to floating-point). Hence, this
is not the best solution (the best solution would be to fix or replace cfitsio),
but I believe this is the best way to get around the problem for the time being.
Fixed in CVS head.