[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master fc276fe: FITS Library: using NaN for non-reada

From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master fc276fe: FITS Library: using NaN for non-readable float number in ASCII tables
Date: Fri, 29 Nov 2019 12:21:50 -0500 (EST)

branch: master
commit fc276fe5389bfb379bbdc25e5aef98b1708ef01a
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    FITS Library: using NaN for non-readable float number in ASCII tables
    Until now, when an un-readable (by the C Library's `strtod' function)
    string was encountered in a floating-point ASCII FITS table's column, the
    running program would abort with a crash exactly giving the row and column
    number. However, different ASCII FITS table writers, use different
    conventions to mark NaNs in ASCII FITS tables and it is hard to include
    With this commit, when such strings are encountered, they are read as NaN
    values and no warning or error is printed. This is the natural expected
    behavior when an un-readable number is present in an ASCII FITS table
 NEWS       | 6 ++++++
 lib/fits.c | 8 +++-----
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index 820f3ad..7e9f472 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,12 @@ See the end of the file for license conditions.
 ** Changed features
+  All programs and libraries:
+   - FITS ASCII tables: When a column has a floating point type, but its
+     ASCII string can't be parsed as a number, it will be read as a
+     NaN. Until now, the corresponding program/library would abort,
+     printing the problematic string and its location.
 ** Bugs fixed
   bug #57300: MakeCatalog memory crash when input dataset has units.
   bug #57301: MakeCatalog using river sum instead of mean times by clump area.
diff --git a/lib/fits.c b/lib/fits.c
index 82af7e0..4463602 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -2706,12 +2706,10 @@ fits_tab_read_ascii_float_special(char *filename, char 
*hdu, fitsfile *fptr,
   /* Convert the strings to float. */
-      /* Parse the string. */
+      /* Parse the string, if its not readable as a special number (like
+         `inf' or `nan', then just read it as a NaN. */
       tmp=strtod(strarr[i], &tailptr);
-      if(tailptr==strarr[i])
-        error(EXIT_FAILURE, 0, "%s (hdu %s): couldn't parse row %zu of "
-              "column %zu (with value `%s') as a floating point number",
-              filename, hdu, i+1, colnum, strarr[i]);
+      if(tailptr==strarr[i]) tmp=NAN;
       /* Write it into the output dataset. */

reply via email to

[Prev in Thread] Current Thread [Next in Thread]