gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master a87decb7: astscript-fits-view: print message w


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master a87decb7: astscript-fits-view: print message when input file does not exist
Date: Sat, 27 May 2023 10:50:59 -0400 (EDT)

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

    astscript-fits-view: print message when input file does not exist
    
    Until now, this installed script wouldn't print any message if the input
    file did not exist! The test for the existence was merged with the test for
    being a FITS file (with 'astfits'), therefore when it crashed, the script
    would not continue.
    
    With this commit, to fix the problem we now explicitly check the existence
    of the input before calling 'astfits'.
    
    This bug was reported by Ryan Begley.
    
    This fixes bug #64250.
---
 NEWS                         |   2 +
 THANKS                       |   1 +
 bin/script/fits-view.in      | 212 +++++++++++++++++++++----------------------
 doc/announce-acknowledge.txt |   1 +
 4 files changed, 108 insertions(+), 108 deletions(-)

diff --git a/NEWS b/NEWS
index 8e38dea8..605e3cdd 100644
--- a/NEWS
+++ b/NEWS
@@ -86,6 +86,8 @@ See the end of the file for license conditions.
               problem in Query by Sepideh Eskandarlou.
   bug #64199: info astscript-zeropoint not working. Reported by Zahra
               Sharbaf.
+  bug #64250: astscript-fits-view: no message printed when input file did
+              not exist. Reported by Ryan Begley.
 
 
 
diff --git a/THANKS b/THANKS
index 7c121cd8..91312fc8 100644
--- a/THANKS
+++ b/THANKS
@@ -114,6 +114,7 @@ support in Gnuastro. The list is ordered alphabetically (by 
family name).
     Roberto Baena Gallé                  rbaena@iac.es
     Roland Bacon                         roland.bacon@univ-lyon1.fr
     Rosa Calvi                           rcalvi@iac.es
+    Ryan Begley                          rbeg@roe.ac.uk
     Samane Raji                          samaneraji@gmail.com
     Sara Yousefi Taemeh                  s.yousefi.t@gmail.com
     Sebastián Luna Valero                sluna@iaa.es
diff --git a/bin/script/fits-view.in b/bin/script/fits-view.in
index 346caa52..9ffea1ec 100644
--- a/bin/script/fits-view.in
+++ b/bin/script/fits-view.in
@@ -360,131 +360,127 @@ else
     # Select the first input.
     input1=$(echo $inputs | awk '{print $1}')
 
-    # Make sure we are dealing with a FITS file. We are using shell
-    # redirection here to make sure that nothing is printed in the
-    # terminal (to standard output when we have a FITS file, or to
-    # standard error when we don't). Since we've used redirection,
-    # we'll also have to echo the return value of `astfits'.
-    check=$(astfits $input1 -h0 > /dev/null 2>&1; echo $?)
-
-    # If the first input existed and was a FITS file, then `check' will be
-    # 0 ('astfits' was successful).
-    if [ "$check" = 0 ]; then
-
-        # Input is image or table.
-        type=$(astfits $input1 --hasimagehdu)
-
-        # If the file was a image, then  `check` will be 1.
-        if [ "$type" = 1 ]; then
-
-            # If a HDU is given, add it to all the input file names (within
-            # square brackets for DS9).
-            if [ x"$hdu" = x ]; then
-                inwithhdu="$inputs"
-            else
-                inwithhdu=""
-                for i in $inputs; do inwithhdu="$inwithhdu $i[$hdu]"; done
-            fi
+    # Do the tests only if the given file exists.
+    if [ -f $input1 ]; then
 
-            # Read the number of dimensions.
-            n0=$(astfits $input1 -h0 | awk '$1=="NAXIS"{print $3}')
-
-            # Find the number of dimensions.
-            if [ "$n0" = 0 ]; then
-                ndim=$(astfits $input1 -h1 | awk '$1=="NAXIS"{print $3}')
-            else
-                ndim=$n0
-            fi;
+        # If the first input exists. Continue if it is also a FITS file.
+        if astfits $input1 -h0 > /dev/null 2>&1; then
 
-            # If multiple colorbars should be used.
-            if [ x"$ds9colorbarmulti" = x ]; then multicolorbars=no;
-            else                                  multicolorbars=yes;
-            fi
+            # Input is image or table.
+            type=$(astfits $input1 --hasimagehdu)
 
-            # Open DS9 based on the number of dimension.
-            if [ "$ndim" = 2 ]; then
+            # If the file was a image, then  `check` will be 1.
+            if [ "$type" = 1 ]; then
 
-                # If a HDU is specified, ignore other HDUs (recall that
-                # with '-mecube' we are viewing all the HDUs as a single
-                # cube.
-                if [ x"$hdu" = x ]; then mecube="-mecube";
-                else                     mecube="";
+                # If a HDU is given, add it to all the input file names (within
+                # square brackets for DS9).
+                if [ x"$hdu" = x ]; then
+                    inwithhdu="$inputs"
+                else
+                    inwithhdu=""
+                    for i in $inputs; do inwithhdu="$inwithhdu $i[$hdu]"; done
                 fi
 
-                # 2D multi-extension file: use the "Cube" window to
-                # flip/slide through the extensions.
-                execom="$ds9exec $ds9scaleopt \
-                                 $ds9geoopt \
-                                 $mecube \
-                                 $inwithhdu \
-                                 -zoom to fit \
-                                 -wcs degrees \
-                                 -cmap sls \
-                                 -match frame image \
-                                 -match frame colorbar \
-                                 -frame lock image \
-                                 -colorbar lock yes \
-                                 -view multi $multicolorbars \
-                                 -lock slice image \
-                                 $ds9pan \
-                                 $ds9extra"
-            else
+                # Read the number of dimensions.
+                n0=$(astfits $input1 -h0 | awk '$1=="NAXIS"{print $3}')
+
+                # Find the number of dimensions.
+                if [ "$n0" = 0 ]; then
+                    ndim=$(astfits $input1 -h1 | awk '$1=="NAXIS"{print $3}')
+                else
+                    ndim=$n0
+                fi;
 
-                # If a HDU is given, don't use multi-frame.
-                if [ x"$hdu" = x ]; then mframe="-multiframe";
-                else                     mframe="";
+                # If multiple colorbars should be used.
+                if [ x"$ds9colorbarmulti" = x ]; then multicolorbars=no;
+                else                                  multicolorbars=yes;
                 fi
 
-                # 3D multi-extension file: The "Cube" window will slide
-                # between the slices of a single extension. To flip through
-                # the extensions (not the slices), press the top row
-                # "frame" button and from the last four buttons of the
-                # bottom row ("first", "previous", "next" and "last") can
-                # be used to switch through the extensions (while keeping
-                # the same slice).
-                execom="$ds9exec $ds9scaleopt \
-                                 $ds9geoopt -wcs degrees \
-                                 $mframe \
-                                 $inwithhdu \
-                                 -lock slice image \
-                                 -lock frame image \
-                                 -zoom to fit \
-                                 -cmap sls \
-                                 -match frame colorbar \
-                                 -colorbar lock yes \
-                                 -view multi $multicolorbars \
-                                 $ds9pan \
-                                 $ds9extra"
-            fi
+                # Open DS9 based on the number of dimension.
+                if [ "$ndim" = 2 ]; then
+
+                    # If a HDU is specified, ignore other HDUs (recall that
+                    # with '-mecube' we are viewing all the HDUs as a single
+                    # cube.
+                    if [ x"$hdu" = x ]; then mecube="-mecube";
+                    else                     mecube="";
+                    fi
+
+                    # 2D multi-extension file: use the "Cube" window to
+                    # flip/slide through the extensions.
+                    execom="$ds9exec $ds9scaleopt \
+                                     $ds9geoopt \
+                                     $mecube \
+                                     $inwithhdu \
+                                     -zoom to fit \
+                                     -wcs degrees \
+                                     -cmap sls \
+                                     -match frame image \
+                                     -match frame colorbar \
+                                     -frame lock image \
+                                     -colorbar lock yes \
+                                     -view multi $multicolorbars \
+                                     -lock slice image \
+                                     $ds9pan \
+                                     $ds9extra"
+                else
+
+                    # If a HDU is given, don't use multi-frame.
+                    if [ x"$hdu" = x ]; then mframe="-multiframe";
+                    else                     mframe="";
+                    fi
+
+                    # 3D multi-extension file: The "Cube" window will slide
+                    # between the slices of a single extension. To flip
+                    # through the extensions (not the slices), press the
+                    # top row "frame" button and from the last four buttons
+                    # of the bottom row ("first", "previous", "next" and
+                    # "last") can be used to switch through the extensions
+                    # (while keeping the same slice).
+                    execom="$ds9exec $ds9scaleopt \
+                                     $ds9geoopt -wcs degrees \
+                                     $mframe \
+                                     $inwithhdu \
+                                     -lock slice image \
+                                     -lock frame image \
+                                     -zoom to fit \
+                                     -cmap sls \
+                                     -match frame colorbar \
+                                     -colorbar lock yes \
+                                     -view multi $multicolorbars \
+                                     $ds9pan \
+                                     $ds9extra"
+                fi
 
-        # When input was table.
-        else
+            # When input was table.
+            else
 
-            # If a HDU is given, add it to all the input file names (with a
-            # '#' between the filename and HDU in TOPCAT).
-            if [ x"$hdu" = x ]; then
+                # If a HDU is given, add it to all the input file names
+                # (with a '#' between the filename and HDU in TOPCAT).
+                if [ x"$hdu" = x ]; then
                 inwithhdu="$inputs"
-            else
-                inwithhdu=""
-                for i in $inputs; do inwithhdu="$inwithhdu $i#$hdu"; done
+                else
+                    inwithhdu=""
+                    for i in $inputs; do inwithhdu="$inwithhdu $i#$hdu"; done
+                fi
+
+                # TOPCAT command.
+                execom="$topcatexec $inwithhdu"
             fi
 
-            # TOPCAT command.
-            execom="$topcatexec $inwithhdu"
-        fi
+            # Run the final command and print it if not in '--quiet' mode.
+            if [ $quiet = 0 ]; then
+                echo "Running: $(echo $execom | sed 's|* | |')";
+            fi
+            $execom
 
-        # Run the final command and print it if not in '--quiet' mode.
-        if [ $quiet = 0 ]; then
-            echo "Running: $(echo $execom | sed 's|* | |')";
+            # 'astfits' couldn't open the file.
+        else
+            echo "$scriptname:$input1: not a FITS file"
         fi
-        $execom
 
-    # 'astfits' couldn't open the file.
+    # File does not exist.
     else
-        if [ -f "$input1" ]; then
-            echo "'$input1' isn't a FITS file."
-        else
-            echo "'$input1' doesn't exist."
-        fi
+        echo "$scriptname:$input1: does not exist"
     fi
 fi
diff --git a/doc/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index ccf907e7..e634624f 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -3,6 +3,7 @@ Alphabetically ordered list to acknowledge in the next release.
 Agata Rożek
 Irene Pintos Castro
 Raul Infante-Sainz
+Ryan Begley
 Sepideh Eskandarlou
 Zahra Sharbaf
 Zohreh Ghaffari



reply via email to

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