gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 8a30d8e: Crop includes BUNIT in output files i


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 8a30d8e: Crop includes BUNIT in output files if present
Date: Tue, 29 Aug 2017 08:43:46 -0400 (EDT)

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

    Crop includes BUNIT in output files if present
    
    Until now, the Crop program didn't care about the units of the data and
    just copied the dataset and its WCS information. But when `BUNIT' is
    present in the input's keywords, it is something like WCS and will probably
    matter for the user. Also, Crop doesn't change anything about the dataset,
    so the units remain unchanged. Therefore with this commit, when Crop is
    creating the output crop, it also checks for the `BUNIT' keyword and if
    present, it will write it in the output cropped image also.
---
 bin/crop/onecrop.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/bin/crop/onecrop.c b/bin/crop/onecrop.c
index d74526f..93cbba9 100644
--- a/bin/crop/onecrop.c
+++ b/bin/crop/onecrop.c
@@ -572,9 +572,10 @@ onecrop_make_array(struct onecropparams *crp, long 
*fpixel_i,
   fitsfile *ofp;
   long naxes[MAXDIM];
   char *outname=crp->name;
-  char cpname[FLEN_KEYWORD];
   int status=0, type=crp->p->type;
   size_t i, ndim=crp->p->imgs->ndim;
+  char **strarr, cpname[FLEN_KEYWORD];
+  gal_data_t *rkey=gal_data_array_calloc(1);
   char *cp, *cpf, blankrec[80], titlerec[80];
   char startblank[]="                      / ";
   struct inputimgs *img=&crp->p->imgs[crp->in_ind];
@@ -592,11 +593,11 @@ onecrop_make_array(struct onecropparams *crp, long 
*fpixel_i,
     for(i=0;i<ndim;++i)
       {
         fpixel_c[i] = 1;
-        lpixel_c[i] = naxes[i]=lpixel_i[i]-fpixel_i[i]+1;
+        lpixel_c[i] = naxes[i] = lpixel_i[i]-fpixel_i[i]+1;
       }
   else
     for(i=0;i<ndim;++i)
-      naxes[i]=crp->lpixel[i] - crp->fpixel[i] + 1;
+      naxes[i] = crp->lpixel[i]-crp->fpixel[i]+1;
 
 
   /* Create the FITS file with a blank first extension, then close it, so
@@ -630,6 +631,22 @@ onecrop_make_array(struct onecropparams *crp, long 
*fpixel_i,
   status=0;
 
 
+  /* Read the units of the input dataset and store them in the output. */
+  rkey->next=NULL;
+  rkey->name="BUNIT";
+  rkey->type=GAL_TYPE_STRING;
+  gal_fits_key_read_from_ptr(crp->infits, rkey, 1, 1);
+  if(rkey->status==0)           /* The BUNIT keyword was read. */
+    {
+      strarr=rkey->array;
+      fits_update_key(ofp, TSTRING, "BUNIT", strarr[0], "physical units",
+                      &status);
+      gal_fits_io_error(status, "writing BUNIT");
+    }
+  rkey->name=NULL;              /* `name' wasn't allocated. */
+  gal_data_free(rkey);
+
+
   /* 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",
@@ -662,7 +679,6 @@ onecrop_make_array(struct onecropparams *crp, long 
*fpixel_i,
           fits_update_key(ofp, TDOUBLE, cpname, &crpix, NULL, &status);
           gal_fits_io_error(status, NULL);
         }
-
     }
 
 



reply via email to

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