gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master c3fc5214 04/39: Zeropoint: add options with va


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master c3fc5214 04/39: Zeropoint: add options with variable
Date: Wed, 19 Apr 2023 12:18:21 -0400 (EDT)

branch: master
commit c3fc52148714217c5f1896309730e4ee721bfc76
Author: Sepideh Eskandarlou <sepideh.eskandarlou@gmail.com>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Zeropoint: add options with variable
    
    Until now, command line arguments from options did not separated.
    
    With this commit, command line arguments are separated from the options and
    put the option values into the respective values.
---
 bin/script/zeropoint.in | 188 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 187 insertions(+), 1 deletion(-)

diff --git a/bin/script/zeropoint.in b/bin/script/zeropoint.in
index 686bfb01..fd0c9481 100644
--- a/bin/script/zeropoint.in
+++ b/bin/script/zeropoint.in
@@ -9,7 +9,6 @@
 #     Sepideh Eskandarlou <sepideh.eskandarlou@gmail.com>
 # Contributing author:
 #     Mohammad Akhlaghi <mohammad@akhlaghi.org>
-#     Samane Raji <samaneraji@gmail.com>
 # Copyright (C) 2020-2022 Free Software Foundation, Inc.
 #
 # Gnuastro is free software: you can redistribute it and/or modify it under
@@ -126,3 +125,190 @@ There is NO WARRANTY, to the extent permitted by law.
 Written/developed by Sepideh Eskandarlou.
 EOF
 }
+
+
+
+
+# Output of `--cite':
+print_citation() {
+    empty="" # needed for the ascii art!
+    cat <<EOF
+
+Thank you for using $scriptname (GNU Astronomy Utilities) $version
+
+Citations and acknowledgement are vital for the continued work on Gnuastro.
+
+Please cite the following record(s) and add the acknowledgement statement 
below in your work to support us. Please note that different Gnuastro programs 
may have different corresponding papers. Hence, please check all the programs 
you used. Don't forget to also include the version as shown above for 
reproducibility.
+
+First paper introducing Gnuastro
+--------------------------------
+  @ARTICLE{gnuastro,
+     author = {{Akhlaghi}, M. and {Ichikawa}, T.},
+      title = "{Noise-based Detection and Segmentation of Nebulous Objects}",
+    journal = {ApJS},
+  archivePrefix = "arXiv",
+     eprint = {1505.01664},
+   primaryClass = "astro-ph.IM",
+       year = 2015,
+      month = sep,
+     volume = 220,
+        eid = {1},
+      pages = {1},
+        doi = {10.1088/0067-0049/220/1/1},
+     adsurl = {https://ui.adsabs.harvard.edu/abs/2015ApJS..220....1A},
+    adsnote = {Provided by the SAO/NASA Astrophysics Data System}
+  }
+
+Acknowledgement
+---------------
+This work was partly done using GNU Astronomy Utilities (Gnuastro,
+ascl.net/1801.009) version $version. Work on Gnuastro has been funded by
+the Japanese Ministry of Education, Culture, Sports, Science, and
+Technology (MEXT) scholarship and its Grant-in-Aid for Scientific Research
+(21244012, 24253003), the European Research Council (ERC) advanced grant
+339659-MUSICOS, the Spanish Ministry of Economy and Competitiveness
+(MINECO, grant number AYA2016-76219-P) and the NextGenerationEU grant
+through the Recovery and Resilience Facility project
+ICTS-MRR-2021-03-CEFCA.
+                                               ,
+                                              {|'--.
+                                             {{\    \ $empty
+      Many thanks from all                   |/\`'--./=.
+      Gnuastro developers!                   \`\.---' \`\\
+                                                  |\  ||
+                                                  | |//
+                                                   \//_/|
+                                                   //\__/
+                                                  //
+                   (http://www.chris.com/ascii/) |/
+
+EOF
+}
+
+
+
+
+# Functions to check option values and complain if necessary.
+on_off_option_error() {
+    if [ x"$2" = x ]; then
+        echo "$scriptname: '$1' doesn't take any values"
+    else
+        echo "$scriptname: '$1' (or '$2') doesn't take any values"
+    fi
+    exit 1
+}
+
+check_v() {
+    if [ x"$2" = x ]; then
+        cat <<EOF
+$scriptname: option '$1' requires an argument. Try '$scriptname --help' for 
more information
+EOF
+        exit 1;
+    fi
+}
+
+
+
+
+# Separate command-line arguments from options and put the option values
+# into the respective variables.
+#
+# OPTIONS WITH A VALUE:
+#
+#   Each option has three lines because we take into account the three common
+#   formats:
+#   For long option names, '--longname value' and '--longname=value'.
+#   For short option names, '-l value', '-l=value' and '-lvalue'
+#   (where '-l' is the short version of the hypothetical '--longname option').
+#
+#   The first case (with a space between the name and value) is two
+#   command-line arguments. So, we'll need to shift it twice. The
+#   latter two cases are a single command-line argument, so we just need to
+#   "shift" the counter by one.
+#
+#   IMPORTANT NOTE: the ORDER OF THE LATTER TWO cases matters: '-h*' should be
+#   checked only when we are sure that its not '-h=*').
+#
+# OPTIONS WITH NO VALUE (ON-OFF OPTIONS)
+#
+#   For these, we just want the forms of '--longname' or '-l'. Nothing
+#   else. So if an equal sign is given we should definitely crash and also,
+#   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=""
+while [ $# -gt 0 ]
+do
+   case "$1" in
+   # Input parameters.
+       -h|--hdu)               hdu="$2";                                     
check_v "$1" "$hdu";  shift;shift;;
+       -h=*|--hdu=*)           hdu="${1#*=}";                                
check_v "$1" "$hdu";  shift;;
+       -h*)                    hdu=$(echo "$1" | sed -e's/-h//');            
check_v "$1" "$hdu";  shift;;
+       -c|--catalog)           catalog="$2";                                 
check_v "$1" "$catalog";  shift;shift;;
+       -c=*|--catalog=*)       catalog="${1#*=}";                            
check_v "$1" "$catalog";  shift;;
+       -c*)                    catalog=$(echo "$1" | sed -e's/-c//');        
check_v "$1" "$catalog";  shift;;
+       -C|--cataloghdu)        cataloghdu="$2";                              
check_v "$1" "$cataloghdu";  shift;shift;;
+       -C=*|--cataloghdu=*)    cataloghdu="${1#*=}";                         
check_v "$1" "$cataloghdu";  shift;;
+       -C*)                    cataloghdu=$(echo "$1" | sed -e's/-C//');     
check_v "$1" "$cataloghdu";  shift;;
+       -r|--reference)         reference="$2";                               
check_v "$1" "$reference";  shift;shift;;
+       -r=*|--reference=*)     reference="${1#*=}";                          
check_v "$1" "$reference";  shift;;
+       -r*)                    reference=$(echo "$1" | sed -e's/-r//');      
check_v "$1" "$reference";  shift;;
+       -z|--referencezp)       referencezp="$2";                             
check_v "$1" "$referencezp";  shift;shift;;
+       -z=*|--referencezp=*)   referencezp="${1#*=}";                        
check_v "$1" "$referencezp";  shift;;
+       -z*)                    referencezp=$(echo "$1" | sed -e's/-z//');    
check_v "$1" "$referencezp";  shift;;
+       -R|--referencehdu)      referencehdu="$2";                            
check_v "$1" "$referencehdu";  shift;shift;;
+       -R=*|--referencehdu=*)   referencehdu="${1#*=}";                       
check_v "$1" "$referencehdu";  shift;;
+       -R*)                    referencehdu=$(echo "$1" | sed -e's/-R//');    
check_v "$1" "$referencehdu";  shift;;
+       -a|--aperarcsec)         aperarcsec="$2";                             
check_v "$1" "$aperarcsec";  shift;shift;;
+       -a=*|--referencehdu=*)   aperarcsec="${1#*=}";                        
check_v "$1" "$aperarcsec";  shift;;
+       -a*)                     aperarcsec=$(echo "$1" | sed -e's/-a//');    
check_v "$1" "$aperarcsec";  shift;;
+
+
+# Output parameters
+       -k|--keeptmp)           keeptmp=1; shift;;
+       -k*|--keeptmp=*)        on_off_option_error --keeptmp -k;;
+       -t|--tmpdir)            tmpdir="$2";                                  
check_v "$1" "$tmpdir";  shift;shift;;
+       -t=*|--tmpdir=*)        tmpdir="${1#*=}";                             
check_v "$1" "$tmpdir";  shift;;
+       -t*)                    tmpdir=$(echo "$1" | sed -e's/-t//');         
check_v "$1" "$tmpdir";  shift;;
+       -o|--output)            output="$2";                                  
check_v "$1" "$output"; shift;shift;;
+       -o=*|--output=*)        output="${1#*=}";                             
check_v "$1" "$output"; shift;;
+       -o*)                    output=$(echo "$1" | sed -e's/-o//');         
check_v "$1" "$output"; shift;;
+
+   # Non-operating options.
+       -q|--quiet)             quiet=" -q"; shift;;
+       -q*|--quiet=*)          on_off_option_error --quiet -q;;
+       -?|--help)              print_help; exit 0;;
+       -'?'*|--help=*)         on_off_option_error --help -?;;
+       -V|--version)           print_version; exit 0;;
+       -V*|--version=*)        on_off_option_error --version -V;;
+       --cite)                 print_citation; exit 0;;
+       --cite=*)               on_off_option_error --cite;;
+
+   # Unrecognized option:
+       -*) echo "$scriptname: unknown option '$1'"; exit 1;;
+
+       # 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;;
+   esac
+done
+
+
+
+
+
+# Basic sanity checks
+# ===================
+
+# If an input image is not given at all.
+if [ x"$inputs" = x ]; then
+    cat <<EOF
+$scriptname: ERROR: no input FITS image files (outer part of the PSF to unite 
with an inner part). Run with '--help' for more information on how to run
+EOF
+    exit 1
+elif [ ! -f $inputs ]; then
+    cat <<EOF
+$scriptname: ERROR: $inputs, no such file or directory
+EOF
+    exit 1
+fi



reply via email to

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