[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 56f24a2 3/3: Reading infinity values from FITS
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 56f24a2 3/3: Reading infinity values from FITS tables |
Date: |
Tue, 6 Mar 2018 09:20:22 -0500 (EST) |
branch: master
commit 56f24a2138716676fac41cdea14573d0425e914f
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
Reading infinity values from FITS tables
Until now, `gal_fits_tab_read' would pass a `blank' pointer to
`fits_read_col' for all types. However, when trying to read infinity
values, CFITSIO will set them to NaN if a blank value is defined. To allow
reading of +/-`inf' in FITS tables, we now only define a blank value for
non floating point types.
---
lib/fits.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/lib/fits.c b/lib/fits.c
index 939d816..aadd92e 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -2396,12 +2396,23 @@ gal_fits_tab_read(char *filename, char *hdu, size_t
numrows,
}
/* Allocate a blank value for the given type and read/store the
- column using CFITSIO. Afterwards, free the blank value. */
- blank=gal_blank_alloc_write(out->type);
+ column using CFITSIO. Afterwards, free the blank value. Note that
+ we only need blank values for integer types. For floating point
+ types, the FITS standard defines blanks as NaN (same as almost any
+ other software like Gnuastro). However if a blank value is
+ specified, CFITSIO will convert other special numbers like `inf'
+ to NaN also. We want to be able to distringuish `inf' and NaN
+ here, so for floating point types, we won't define any blank
+ value. */
+ blank = ( (out->type==GAL_TYPE_FLOAT32 || out->type==GAL_TYPE_FLOAT64)
+ ? NULL
+ : gal_blank_alloc_write(out->type) );
fits_read_col(fptr, gal_fits_type_to_datatype(out->type), ind->v+1,
1, 1, out->size, blank, out->array, &anynul, &status);
gal_fits_io_error(status, NULL);
- free(blank);
+
+ /* Clean up. */
+ if(blank) free(blank);
}
/* Close the FITS file */
@@ -2707,7 +2718,7 @@ gal_fits_tab_write(gal_data_t *cols, gal_list_str_t
*comments,
fptr=gal_fits_open_to_write(filename);
- /* prepare necessary arrays and if integer type columns have blank
+ /* Prepare necessary arrays and if integer type columns have blank
values, write the TNULLn keywords into the FITS file. */
fits_table_prepare_arrays(cols, numcols, tableformat,
&tform, &ttype, &tunit);