[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 9e3c4f94: astscript-ds9-region: check for exis
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 9e3c4f94: astscript-ds9-region: check for existence of input file |
Date: |
Thu, 1 Feb 2024 17:57:07 -0500 (EST) |
branch: master
commit 9e3c4f94ae7c27a0d797627d6a85a1501e9a8fae
Author: Thorsten Alteholz <thorsten@alteholz.dev>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
astscript-ds9-region: check for existence of input file
Until now, when the input file given to this script did not exist, it would
still take it and prepare the output (before checking if it actually
exists!). As a result, even when it crashed and made an empty output, the
users would see an output, confusing users.
With this commit, before registering the input file name as an input, this
script will check if it actually exists and abort if it does not.
Also, if more than one input is given, the script will abort (informing the
user that only one input should be given). To avoid confussion within the
script, the variable name 'inputs' was changed to 'input'. This component
was added by Mohammad while reviewing Thorsten's commit.
This bug was reported by Sepideh Eskdandarlou.
This fixes bug #61476.
---
NEWS | 6 +++++-
bin/script/ds9-region.sh | 22 ++++++++++++++--------
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/NEWS b/NEWS
index 5e527e34..9035163e 100644
--- a/NEWS
+++ b/NEWS
@@ -248,7 +248,9 @@ See the end of the file for license conditions.
** Bugs fixed
- bug #52674: Correcting Clang warnings on macOS during compilation;
- fixed with help of Thorsten Alteholz and Raul Infante-Sainz
+ fixed with help of Thorsten Alteholz and Raul Infante-Sainz.
+ - bug #61476: astscript-ds9-region: output created when input file does
+ not exist; reported by Sepideh Eskandarlou, fixed by Thorsten Alteholz.
- bug #64825: astscript-fits-view only takes the last HDU provided;
reported by Teet Kuumta and fixed by Raul Infante-Sainz.
- bug #64852: astscript-zeropoint: crash when input is in 0-th HDU;
@@ -277,6 +279,8 @@ See the end of the file for license conditions.
+
+
* Noteworthy changes in release 0.21 (library 19.0.0) (2023-10-20)
** New features
*** New program
diff --git a/bin/script/ds9-region.sh b/bin/script/ds9-region.sh
index 9869d2f6..2b5af635 100644
--- a/bin/script/ds9-region.sh
+++ b/bin/script/ds9-region.sh
@@ -180,7 +180,7 @@ EOF
# if a value is appended to the short format it should crash. So in the
# second test for these ('-l*') will account for both the case where we
# have an equal sign and where we don't.
-inputs=""
+input=""
while [ $# -gt 0 ]
do
# Initialize 'tcol':
@@ -233,7 +233,13 @@ do
# Not an option (not starting with a '-'): assumed to be input FITS
# file name.
- *) if [ x"$inputs" = x ]; then inputs="$1"; else inputs="$inputs $1";
fi; shift;;
+ *) if [ x"$input" = x ]; then
+ if [ -f "$1" ]; then
+ input="$1";
+ else echo "$scriptname: $1: no such file"; exit 1;
+ fi;
+ else echo "$scriptname: only one input should be given"; exit 1
+ fi; shift;;
esac
# If a column was given, add it to possibly existing previous columns
@@ -313,8 +319,8 @@ if [ x"$mode" = xwcs ]; then unit="\""; else unit=""; fi
# Write the metadata in the output.
printf "# Region file format: DS9 version 4.1\n" > $out
printf "# Created by $scriptname (GNU Astronomy Utilities) $version\n" >> $out
-if [ x"$inputs" = x ]; then printf "# Input from stdin\n" >> $out
-else printf "# Input file: $inputs (hdu $hdu)\n" >> $out
+if [ x"$input" = x ]; then printf "# Input from stdin\n" >> $out
+else printf "# Input file: $input (hdu $hdu)\n" >> $out
fi
printf "# Columns: $col\n" >> $out
if [ x"$namecol" != x ]; then
@@ -334,7 +340,7 @@ else printf "image\n" >> $out; fi
# 'printf' will not see anything and use the next variable where the unit
# should be printed! See https://savannah.gnu.org/bugs/index.php?64153
if [ x"$namecol" = x ]; then
- if [ x"$inputs" = x ]; then
+ if [ x"$input" = x ]; then
cat /dev/stdin \
| asttable --column=$col \
| while read a b; do \
@@ -342,14 +348,14 @@ if [ x"$namecol" = x ]; then
$a $b $radius "$unit" >> $out; \
done
else
- asttable $inputs --hdu=$hdu --column=$col \
+ asttable $input --hdu=$hdu --column=$col \
| while read a b; do \
printf "circle(%f,%f,%f%s)\n" \
$a $b $radius "$unit" >> $out; \
done
fi
else
- if [ x"$inputs" = x ]; then
+ if [ x"$input" = x ]; then
cat /dev/stdin \
| asttable --column=$col --column=$namecol \
| while read a b c; do \
@@ -357,7 +363,7 @@ else
$a $b $radius "$unit" $c >> $out; \
done
else
- asttable $inputs --hdu=$hdu --column=$col --column=$namecol \
+ asttable $input --hdu=$hdu --column=$col --column=$namecol \
| while read a b c; do \
printf "circle(%f,%f,%f%s) # text={%g}\n" \
$a $b $radius "$unit" $c >> $out; \
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master 9e3c4f94: astscript-ds9-region: check for existence of input file,
Mohammad Akhlaghi <=