gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 293d7e40: Crop: returns successfully when prin


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 293d7e40: Crop: returns successfully when printing a single number
Date: Fri, 12 Apr 2024 21:17:39 -0400 (EDT)

branch: master
commit 293d7e40a626a60d544d72abd973780506111583
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Crop: returns successfully when printing a single number
    
    Until now, when the '--oneelemstdout' option was passed to crop, it would
    print the value successfully, but return with a non-zero integer. This
    happened because of the recent change in Commit 0ba08c1c27 (where we
    checked for the existence of an output file to return successfully or not).
    This issue was found while investigating the 'astscript-psf-stamp' script,
    and I noticed that when it is not given the '--mode' option, it crashes.
    
    With this commit, a new variable has been defined to keep track of such
    cases (where the output is not a FITS file) and return successfully. The
    problem with 'astscript-psf-stamp' was fixed by checking the calling of
    '--mode' and by correcting the double quotations (in case the user
    mistakenly gives a multi-word value).
---
 bin/crop/crop.c         | 11 ++++++-----
 bin/crop/onecrop.c      |  2 ++
 bin/crop/onecrop.h      |  1 +
 bin/script/psf-stamp.sh |  8 +++++++-
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/bin/crop/crop.c b/bin/crop/crop.c
index 2be219e1..d4438eda 100644
--- a/bin/crop/crop.c
+++ b/bin/crop/crop.c
@@ -255,8 +255,8 @@ crop_mode_img(void *inparam)
         }
       else crp->centerfilled=0;
 
-      /* Status update (for return value and standard output or log.*/
-      p->outmade[crp->out_ind] = crp->outfits!=NULL;
+      /* Status update (for return value and standard output or log).*/
+      p->outmade[crp->out_ind] = crp->outfits || crp->outinstdout;
       if(!p->cp.quiet) crop_verbose_info(crp);
       if(p->cp.log)    crop_write_to_log(crp);
     }
@@ -362,8 +362,8 @@ crop_mode_wcs(void *inparam)
         }
 
 
-      /* Status update (for return value and standard output or log.*/
-      p->outmade[crp->out_ind] = crp->outfits!=NULL;
+      /* Status update (for return value and standard output or log).*/
+      p->outmade[crp->out_ind] = crp->outfits || crp->outinstdout;
       if(!p->cp.quiet) crop_verbose_info(crp);
       if(p->cp.log)    crop_write_to_log(crp);
     }
@@ -417,7 +417,8 @@ crop(struct cropparams *p)
 
 
   /* Set the function to run: */
-  modefunction = p->mode==IMGCROP_MODE_IMG ? &crop_mode_img : &crop_mode_wcs;
+  modefunction = ( p->mode==IMGCROP_MODE_IMG
+                   ? &crop_mode_img : &crop_mode_wcs );
 
 
   /* Necessary allocations: the array of structures to keep the thread and
diff --git a/bin/crop/onecrop.c b/bin/crop/onecrop.c
index cc3de79c..00ce0ac9 100644
--- a/bin/crop/onecrop.c
+++ b/bin/crop/onecrop.c
@@ -728,8 +728,10 @@ onecrop(struct onecropparams *crp)
       /* Make the output FITS image and initialize it with an array of NaN
          or BLANK values. But only when '--oneelemstdout' isn't called and
          the output is single-element. */
+      crp->outinstdout=0;
       if(crp->outfits==NULL && !( p->oneelemstdout && hasoneelem) )
         onecrop_make_array(crp, fpixel_i, lpixel_i, fpixel_o, lpixel_o);
+      else crp->outinstdout=1;
       ofp=crp->outfits;
 
 
diff --git a/bin/crop/onecrop.h b/bin/crop/onecrop.h
index 704861ae..f3d12ff1 100644
--- a/bin/crop/onecrop.h
+++ b/bin/crop/onecrop.h
@@ -48,6 +48,7 @@ struct onecropparams
   double         corners[24];  /* RA and Dec of this crop's corners.       */
   double      equatorcorr[2];  /* Crop crosses the equator, see wcsmode.c. */
   fitsfile          *outfits;  /* Pointer to the output FITS image.        */
+  uint8_t        outinstdout;  /* The output is not a file.                */
 
   /* For log or return value */
   char                 *name;  /* Filename of crop.                        */
diff --git a/bin/script/psf-stamp.sh b/bin/script/psf-stamp.sh
index bba0c662..b1138326 100644
--- a/bin/script/psf-stamp.sh
+++ b/bin/script/psf-stamp.sh
@@ -485,7 +485,13 @@ fi
 # Make sure the value to '--mode' is either 'wcs' or 'img'. Note: '-o'
 # means "or" and is preferred to '[ ] || [ ]' because only a single
 # invocation of 'test' is done. Run 'man test' for more.
-if [ "$mode" = wcs     -o      $mode = "img" ]; then
+if [ x"$mode"  = x ]; then
+    cat <<EOF
+$scriptname: '--mode' (or '-O') is mandatory. It takes one of the following 
two values: 'img' (for pixel coordinates) or 'wcs' (for celestial coordinates)
+EOF
+    exit 1
+fi
+if [ "$mode" = wcs -o "$mode" = img ]; then
     junk=1
 else
     cat <<EOF



reply via email to

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