[Top][All Lists]

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

[gnuastro-commits] master 43ad287: Library (fits.h): no blanks in writin

From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 43ad287: Library (fits.h): no blanks in writing standard FITS numeric tables
Date: Wed, 5 Aug 2020 19:44:33 -0400 (EDT)

branch: master
commit 43ad2870fefba4eb191b48d3b8b7f2fe8dfcbe6f
Author: Mohammad Akhlaghi <>
Commit: Mohammad Akhlaghi <>

    Library (fits.h): no blanks in writing standard FITS numeric tables
    Until now, when writing FITS tables we would simply write Gnuastro's blank
    value into the 'blank' pointer that is passed to CFITSIO. But this would
    cause an error (which is not expected as far as I understand from the
    definition of TNULL in the FITS standard).
    With this commit, for these types, we now remove the blank value (and its
    pointer) because they are ultimately redundant for these types. This fixed
    the problem in cases that we tested.
 lib/fits.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/lib/fits.c b/lib/fits.c
index 95ccd3f..ce89c09 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -1434,7 +1434,7 @@ gal_fits_key_write_filename(char *keynamebase, char 
       /* Set the keyword value: */
-      value=malloc(maxlength);
+      value=malloc(maxlength+1);
         error(EXIT_FAILURE, errno, "%s: allocating %zu bytes", __func__,
@@ -3277,12 +3277,30 @@ gal_fits_tab_write(gal_data_t *cols, gal_list_str_t 
       fits_write_tnull_tcomm(fptr, col, tableformat, i+1, tform[i]);
       /* Set the blank pointer if its necessary, note that strings don't
-         need a blank pointer in a FITS ASCII table.*/
+         need a blank pointer in a FITS ASCII table. */
       blank = ( gal_blank_present(col, 0)
                 ? fits_blank_for_tnull(col->type) : NULL );
       if(tableformat==GAL_TABLE_FORMAT_AFITS && col->type==GAL_TYPE_STRING)
         { if(blank) free(blank); blank=NULL; }
+      /* Manually remove the 'blank' pointer for standard FITS table
+         numeric types (types below). We are doing this because as of
+         CFITSIO 3.48, CFITSIO crashes for these types when we define our
+         own blank values within this pointer, and such values actually
+         exist in the column. This is the error message: "Null value for
+         integer table column is not defined (FTPCLU)". Generally, for
+         these native FITS table types 'blank' is redundant because our
+         blank values are actually within their numerical data range. */
+      switch(col->type)
+        {
+        case GAL_TYPE_UINT8:
+        case GAL_TYPE_INT16:
+        case GAL_TYPE_INT32:
+        case GAL_TYPE_INT64:
+          free(blank); blank=NULL;
+          break;
+        }
       /* Write the full column into the table. */
       fits_write_colnull(fptr, gal_fits_type_to_datatype(col->type),
                          i+1, 1, 1, col->size, col->array, blank, &status);

reply via email to

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