gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master e4fde1b: Crop: Correct blank value for reading


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master e4fde1b: Crop: Correct blank value for reading of non-basic FITS integer types
Date: Fri, 22 Feb 2019 11:33:37 -0500 (EST)

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

    Crop: Correct blank value for reading of non-basic FITS integer types
    
    Until now, we were using the same allocated space pointer to write the
    BLANK keywords and to use as blank values in the the dataset that CFITSIO
    reads. For all basic types defined in the FITS standard this is
    fine. However, for the non-simple ones (those that are defined with the
    `BZERO' and `BSCALE' keywords), this would cause problems.
    
    This bug was reported by Raúl Infante-Sainz.
    
    This fixes bug #55763.
---
 NEWS               |  1 +
 bin/crop/main.h    |  3 ++-
 bin/crop/onecrop.c |  9 +++++----
 bin/crop/ui.c      |  5 ++++-
 doc/gnuastro.texi  | 22 +++++++++++++++++-----
 5 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/NEWS b/NEWS
index 50bf5bd..92021bd 100644
--- a/NEWS
+++ b/NEWS
@@ -118,6 +118,7 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
   bug #55491: NoiseChisel crash when no tiles good for quantile thresholding.
   bug #55544: Arithmetic's output WCS with where operator is not as expected.
   bug #55740: Diamond shapes in nearst-ngb interpolation affecting NoiseChisel.
+  bug #55763: Crop not keeping Blank pixels on unsigned types.
 
 
 
diff --git a/bin/crop/main.h b/bin/crop/main.h
index 6675571..7b83426 100644
--- a/bin/crop/main.h
+++ b/bin/crop/main.h
@@ -112,7 +112,8 @@ struct cropparams
   time_t               rawtime;  /* Starting time of the program.         */
   int            outnameisfile;  /* Output filename is a directory.       */
   int                     type;  /* Type of output(s).                    */
-  void                 *bitnul;  /* Null value for this data-type.        */
+  void           *blankptrread;  /* Null value for reading of output type.*/
+  void          *blankptrwrite;  /* Null value for writing of output type.*/
   struct inputimgs       *imgs;  /* WCS and size information for inputs.  */
   gal_data_t              *log;  /* Log file contents.                    */
 };
diff --git a/bin/crop/onecrop.c b/bin/crop/onecrop.c
index 91b0492..bc5b30e 100644
--- a/bin/crop/onecrop.c
+++ b/bin/crop/onecrop.c
@@ -639,7 +639,7 @@ onecrop_make_array(struct onecropparams *crp, long 
*fpixel_i,
 
   /* When CFITSIO creates a FITS extension it adds two comments linking to
      the FITS paper. Since we are mentioning the version of CFITSIO and
-     only use its ruitines to read/write from/to FITS files, this is
+     only use its routines to read/write from/to FITS files, this is
      redundant. If `status!=0', then `gal_fits_io_error' will abort, but in
      case CFITSIO doesn't write the comments, status will become
      non-zero. So we are resetting it to zero after these (because not
@@ -668,7 +668,8 @@ onecrop_make_array(struct onecropparams *crp, long 
*fpixel_i,
   /* Write the blank value as a FITS keyword if necessary. */
   if( type!=GAL_TYPE_FLOAT32 && type!=GAL_TYPE_FLOAT64 )
     if(fits_write_key(ofp, gal_fits_type_to_datatype(crp->p->type), "BLANK",
-                      crp->p->bitnul, "pixels with no data", &status) )
+                      crp->p->blankptrwrite, "Pixels with no data.",
+                      &status) )
       gal_fits_io_error(status, "adding Blank");
   if(fits_write_null_img(ofp, 1, naxes[0]*naxes[1], &status))
     gal_fits_io_error(status, "writing null array");
@@ -771,7 +772,7 @@ onecrop(struct onecropparams *crp)
       for(i=0;i<ndim;++i) cropsize *= ( lpixel_i[i] - fpixel_i[i] + 1 );
       array=gal_pointer_allocate(p->type, cropsize, 0, __func__, "array");
       if(fits_read_subset(ifp, gal_fits_type_to_datatype(p->type),
-                          fpixel_i, lpixel_i, inc, p->bitnul, array,
+                          fpixel_i, lpixel_i, inc, p->blankptrread, array,
                           &anynul, &status))
         gal_fits_io_error(status, NULL);
 
@@ -898,7 +899,7 @@ onecrop_center_filled(struct onecropparams *crp)
   /* Allocate the array and read in the pixels. */
   array=gal_pointer_allocate(type, size, 0, __func__, "array");
   if( fits_read_subset(ofp, gal_fits_type_to_datatype(type), fpixel, lpixel,
-                       inc, p->bitnul, array, &anynul, &status) )
+                       inc, p->blankptrread, array, &anynul, &status) )
     gal_fits_io_error(status, NULL);
   free(array);
 
diff --git a/bin/crop/ui.c b/bin/crop/ui.c
index 5386018..429d17a 100644
--- a/bin/crop/ui.c
+++ b/bin/crop/ui.c
@@ -896,7 +896,8 @@ ui_preparations(struct cropparams *p)
           /* Set the basic information. */
           firsttype = p->type;
           firstndim = img->ndim;
-          p->bitnul = gal_fits_key_img_blank(p->type);
+          p->blankptrread  = gal_blank_alloc_write(p->type);
+          p->blankptrwrite = gal_fits_key_img_blank(p->type);
 
           /* Make sure the number of dimensions is supported. */
           if(firstndim>MAXDIM)
@@ -1085,6 +1086,8 @@ ui_free_report(struct cropparams *p, struct timeval *t1)
   size_t i;
 
   /* Free the simple arrays (if they were set). */
+  free(p->blankptrread);
+  free(p->blankptrwrite);
   gal_data_free(p->center);
   if(p->cp.hdu) free(p->cp.hdu);
   if(p->cathdu) free(p->cathdu);
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 7b18c00..1469ede 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -25901,17 +25901,29 @@ typedef struct gal_fits_list_key_t
 @end deftp
 
 @deftypefun {void *} gal_fits_key_img_blank (uint8_t @code{type})
-Returns a pointer to an allocated space for the FITS @code{BLANK} header
-keyword when the input array has a type of @code{type}.
+Returns a pointer to an allocated space containing the value to the FITS
address@hidden header keyword, when the input array has a type of
address@hidden This is useful when you want to write the @code{BLANK} keyword
+using CFITSIO's @code{fits_write_key} function.
 
 According to the FITS standard: ``If the @code{BSCALE} and @code{BZERO}
 keywords do not have the default values of 1.0 and 0.0, respectively, then
 the value of the @code{BLANK} keyword must equal the actual value in the
 FITS data array that is used to represent an undefined pixel and not the
 corresponding physical value''. Therefore a special @code{BLANK} value is
-needed for datasets containing signed 8-bit integers and unsigned 16-bit,
-32-bit and 64-bit integers (types that are defined with @code{BSCALE} and
address@hidden in the FITS standard).
+needed for datasets containing signed 8-bit, unsigned 16-bit, unsigned
+32-bit, and unsigned 64-bit integers (types that are defined with
address@hidden and @code{BZERO} in the FITS standard).
+
address@hidden
address@hidden
address@hidden usable when reading a dataset:} As quoted from the FITS
+standard above, the value returned by this function can only be generically
+used for the writing of the @code{BLANK} keyword header. It @emph{must not}
+be used as the blank pointer when when reading a FITS array using
+CFITSIO. When reading an array with CFITSIO, you can use
address@hidden to generate the necessary pointer.
address@hidden cartouche
 @end deftypefun
 
 @deftypefun void gal_fits_key_clean_str_value (char @code{*string})



reply via email to

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