gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master b947f79 62/62: TAB completion: enabled in Fits


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master b947f79 62/62: TAB completion: enabled in Fits program
Date: Thu, 13 May 2021 22:20:56 -0400 (EDT)

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

    TAB completion: enabled in Fits program
    
    With this commit, TAB completion has been implemented for the Fits
    program. The following corrections have also been made:
    
     - A new step was added in the complete.bash.build file to keep the values
       to the '--wcscoordsys' option.
    
     - Two new options have been added to the FITS program to help in
       extracting the information for TAB completion: '--listallhdus' and
       '--printkeynames'.
    
     - I noticed that generally in all the programs, the TAB completion command
       for '--tableformat' was missing the currently typed string.
    
     - A generic 'fits' mode was added to the respective TAB completion
       functions (until now they would distinguish between image or table and
       not the whole FITS file or any HDU).
    
     - The documentation of the Fits program's '--update' option was improved
       to show that it needs two strings.
---
 Makefile.am                                        |  19 ++
 NEWS                                               |   2 +
 bin/arithmetic/astarithmetic-complete.bash         |   2 +-
 bin/completion.bash.in                             | 201 +++++++++++++++------
 bin/fits/Makefile.am                               |   3 +-
 bin/fits/args.h                                    |  30 ++-
 .../astfits-complete.bash}                         | 100 +++++-----
 bin/fits/fits.c                                    |  37 ++++
 bin/fits/keywords.c                                |  35 +++-
 bin/fits/main.h                                    |   2 +
 bin/fits/ui.c                                      |   8 +-
 bin/fits/ui.h                                      |   2 +
 bin/table/asttable-complete.bash                   |   5 +-
 doc/gnuastro.texi                                  |  17 +-
 14 files changed, 350 insertions(+), 113 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index dd42042..173a239 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -75,6 +75,7 @@ if COND_CROP
 endif
 if COND_FITS
   MAYBE_FITS = bin/fits
+  MAYBE_COMPLETE_FITS = bin/fits/astfits-complete.bash
 endif
 if COND_MATCH
   MAYBE_MATCH = bin/match
@@ -261,6 +262,23 @@ bin/completion.bash: $(top_srcdir)/bin/completion.bash.in
        echo "specline_names=\"$$names\"" >> $@.built; \
        echo "}" >> $@.built
 
+        # Extract the WCS coordinate system strings for Fits.
+       vals=""
+       echo "" >> $@.built
+       for val in $$($(AWK) '/^gal_wcs_coordsys_from_string/{parse=1} \
+                            /^\}/{parse=0} \
+                            parse==1 && /strcmp\(coordsys/{ \
+                                  for(i=1;i<=NF;++i) if($$i ~ /"/) { \
+                                    print $$i; break}  \
+                               }' $(top_srcdir)/lib/wcs.c \
+                           | $(SED) -e's|"||g' -e's|)||' \
+                           | $(AWK) 'BEGIN{FS=","} {print $$NF}'  ); do \
+           vals="$$vals $$val"; \
+       done; \
+       echo "_gnuastro_autocomplete_compreply_wcs_coordsys(){" >> $@.built; \
+       echo "wcs_coordsys=\"$$vals\"" >> $@.built; \
+       echo "}" >> $@.built
+
         # Copy the low-level common functions to all programs, then put the
         # arithmetic functions inside of it. We are keeping the arithmetic
         # operators separate to help in debugging when necessary (they can
@@ -275,6 +293,7 @@ bin/completion.bash: $(top_srcdir)/bin/completion.bash.in
                 $(MAYBE_COMPLETE_CONVOLVE) \
                 $(MAYBE_COMPLETE_COSMICCAL) \
                 $(MAYBE_COMPLETE_CROP) \
+                $(MAYBE_COMPLETE_FITS) \
                 $(MAYBE_COMPLETE_TABLE); do \
          $(SED) -e 's|@PREFIX[@]|$(bindir)|g' $(top_srcdir)/$$f >> $@.tmp; \
        done
diff --git a/NEWS b/NEWS
index 7ee4179..c298dfd 100644
--- a/NEWS
+++ b/NEWS
@@ -84,8 +84,10 @@ See the end of the file for license conditions.
   Fits:
    --hastablehdu: print 1 if at least one table HDU exists in file.
    --hasimagehdu: print 1 if at least one image HDU exists in file.
+   --listallhdus: print all HDU names (or numbers when no name exists).
    --listtablehdus: print table HDU names (or numbers when no name exists).
    --listimagehdus: print image HDU names (or numbers when no name exists).
+   --printkeynames: Print all keyword names in current HDU.
    --wcscoordsys: convert the WCS coordinate system of the input into any
      recognized coordinate system. It currently supports: equatorial
      (J2000, B1950), ecliptic (J2000, B1950), Galactic and
diff --git a/bin/arithmetic/astarithmetic-complete.bash 
b/bin/arithmetic/astarithmetic-complete.bash
index 612c0f1..bfb19a0 100644
--- a/bin/arithmetic/astarithmetic-complete.bash
+++ b/bin/arithmetic/astarithmetic-complete.bash
@@ -93,7 +93,7 @@ _gnuastro_autocomplete_astarithmetic_option_value(){
             ;;
 
         --tableformat)
-            _gnuastro_autocomplete_compreply_tableformat
+            _gnuastro_autocomplete_compreply_tableformat "$current"
             ;;
 
         --wcslinearmatrix)
diff --git a/bin/completion.bash.in b/bin/completion.bash.in
index 7d5a66a..da17be2 100644
--- a/bin/completion.bash.in
+++ b/bin/completion.bash.in
@@ -457,22 +457,27 @@ _gnuastro_autocomplete_first_in_arguments(){
             # on the mode.
             else
                 case "$mode" in
-                    table)
-                        if _gnuastro_autocomplete_is_table $word; then
-                            given_file=$word
-                            return 0;
+                    fits)
+                        if _gnuastro_autocomplete_is_fits "$word"; then
+                            given_file="$word"
                         fi
                         ;;
                     image)
-                        if _gnuastro_autocomplete_fits_has_image $word; then
-                            given_file=$word
+                        if _gnuastro_autocomplete_fits_has_image "$word"; then
+                            given_file="$word"
+                            return 0;
+                        fi
+                        ;;
+                    table)
+                        if _gnuastro_autocomplete_is_table "$word"; then
+                            given_file="$word"
                             return 0;
                         fi
                         ;;
                     source_c)
-                        if $(echo $word | grep "\.c$" &> /dev/null) \
-                                && [ -f $word ]; then
-                            given_file=$word
+                        if $(echo "$word" | grep "\.c$" &> /dev/null) \
+                                && [ -f "$word" ]; then
+                            given_file="$word"
                             return 0;
                         fi
                         ;;
@@ -499,7 +504,7 @@ _gnuastro_autocomplete_first_in_arguments(){
 # Find the requested file from the existing tokens on the command-line.
 #
 # INPUT ARGUMENTS:
-#    1) Mode of file ('table' or 'image').
+#    1) Mode of file ('table', 'image', 'fits').
 #    2) Name of option containing file names.
 #
 # WRITTEN VARIABLES (should be defined before this function).
@@ -526,17 +531,25 @@ _gnuastro_autocomplete_given_file(){
 
         # If we are in image-mode, and the found file has an image, then
         # put the name in 'given_file' (final output). Same for tables.
-        if [ x"$mode" = ximage ]; then
-            if _gnuastro_autocomplete_fits_has_image \
-                   "$read_option_value"; then
-                given_file="$read_option_value"
-            fi
-        elif [ x"$mode" = xtable ]; then
-            if _gnuastro_autocomplete_is_table \
-                   "$read_option_value"; then
-                given_file="$read_option_value"
-            fi
-        fi
+        case $mode in
+            fits)
+                if _gnuastro_autocomplete_is_fits "$read_option_value"; then
+                    given_file="$read_option_value"
+                fi
+                ;;
+            image)
+                if _gnuastro_autocomplete_fits_has_image \
+                       "$read_option_value"; then
+                    given_file="$read_option_value"
+                fi
+                ;;
+            table)
+                if _gnuastro_autocomplete_is_table \
+                       "$read_option_value"; then
+                    given_file="$read_option_value"
+                fi
+                ;;
+        esac
     fi
 
 }
@@ -545,8 +558,8 @@ _gnuastro_autocomplete_given_file(){
 
 
 
-# Find the requested table within the already entered command-line. This
-# option needs two arguments:
+# Find the requested filename and HDU within the already entered
+# command-line. This option needs three arguments:
 #
 # INPUT ARGUMENTS
 #    1) Mode of file ('table' or 'image').
@@ -631,6 +644,57 @@ _gnuastro_autocomplete_compreply_from_string(){
 
 
 
+# Some options take multiple values, separated by a comma (for example
+# '--option=A,B,C'). Once the possible solutions have been found by the
+# caller function, this function will decide how to print the suggestions:
+# add a comma or not.
+_gnuastro_autocomplete_compreply_comma_when_matched(){
+
+    # Input arguments:
+    local replies="$1"
+    local tomatch="$2"
+    local fullmatch="$3"
+    local continuematch="$4"
+
+    # Add the completion replies.
+    if [ x"$continuematch" = x ]; then
+        for c in $replies; do COMPREPLY+=("$c"); done
+    else
+        # If there is only one match, include the previously specified
+        # replies in the final filled value and append an ',' to let the
+        # user specify more values to the option.
+        if [ $(echo $replies | wc -w) = 1 ]; then
+
+            # In the continue-mode we don't want the final value to be
+            # appended with a space.
+            compopt -o nospace
+
+            # When 'fullmatch' and 'tomatch' are the same, this was the
+            # first requested reply, so we can safely just print it with a
+            # comma.
+            if [ x"$fullmatch" = x"$tomatch" ]; then
+                COMPREPLY+=("$replies,")
+
+            # This was not the first reply, so we need to add the old ones
+            # as a prefix. But we first need to remove any possible start
+            # of the current reply.
+            else
+                local oldreps=$(echo "$fullmatch" | sed -e's|'$tomatch'$||')
+                COMPREPLY+=("$oldreps$replies,")
+            fi
+
+        # There was more than one matching reply, so continue suggesting
+        # with only the column names.
+        else
+            local oldreps=$(echo "$fullmatch" | sed -e's|'$tomatch'$||')
+            for c in $replies; do COMPREPLY+=("$oldreps$c"); done
+        fi
+    fi
+}
+
+
+
+
 
 # Add completion replies for the values to '--searchin'.
 _gnuastro_autocomplete_compreply_searchin(){
@@ -756,7 +820,7 @@ _gnuastro_autocomplete_compreply_file(){
 # file) into the completion replies.
 #
 # INPUT ARGUMENTS
-#    1) Mode of file ('table' or 'image').
+#    1) Mode of file ('table', 'image', or 'all').
 #    2) Name of file.
 #    3) Existing argument.
 _gnuastro_autocomplete_compreply_hdus(){
@@ -782,6 +846,50 @@ _gnuastro_autocomplete_compreply_hdus(){
 
 
 
+# Add all the keywords in current HDU to the replies.
+#
+# INPUT ARGUMENTS:
+#    1) FITS file name.
+#    2) HDU within the FITS file.
+#    3) Existing argument (to match).
+#    4) If a comma should be appended in case of match.
+_gnuastro_autocomplete_compreply_keys(){
+
+    # Input arguments.
+    local given_file="$1"
+    local given_hdu="$2"
+    local fullmatch="$3"
+    local continuematch="$4"
+
+    # Local variables.
+    local keys=""
+    local tomatch=""
+
+    # Keywords can sometimes be given in series (for example
+    # '--keyvalue=A,B,C'). In this case, the caller will give a non-empty
+    # value to the fourth argument ('continuematch'). We therefore need to
+    # will take the last component of the comma-separated list for the
+    # matching of the next element.
+    if [ x"$continuematch" = x ]; then
+        tomatch="$fullmatch"
+    else
+        tomatch=$(echo $fullmatch | awk 'BEGIN{FS=","} {print $NF}')
+    fi
+
+    # Get list of keywords.
+    keys=$("$gnuastro_prefix"/astfits "$given_file" \
+                             --hdu="$given_hdu" \
+                             --printkeynames \
+               | grep ^$tomatch)
+
+    _gnuastro_autocomplete_compreply_comma_when_matched \
+        "$keys" "$tomatch" "$fullmatch" "$continuematch"
+}
+
+
+
+
+
 # Fill the replies with certain files.
 _gnuastro_autocomplete_compreply_directories(){
 
@@ -893,6 +1001,11 @@ _gnuastro_autocomplete_compreply_files_certain(){
             compopt -o nospace
         else
             case "$mode" in
+                fits)
+                    if _gnuastro_autocomplete_is_fits "$f"; then
+                        _gnuastro_autocomplete_compreply_file "$arg" "$f"
+                    fi
+                    ;;
                 image)
                     if _gnuastro_autocomplete_fits_has_image "$f"; then
                         _gnuastro_autocomplete_compreply_file "$arg" "$f"
@@ -945,8 +1058,9 @@ _gnuastro_autocomplete_compreply_table_columns(){
 
     # Columns can usually be given in series (for example
     # '--column=A,B,C'). In this case, the caller will give a non-empty
-    # value to the fourth argument ('continuematch'). To deal with it, we
-    # will take the last component of the comma-separated list.
+    # value to the fourth argument ('continuematch'). We therefore need to
+    # will take the last component of the comma-separated list for the
+    # matching of the next element.
     if [ x"$continuematch" = x ]; then
         tomatch="$fullmatch"
     else
@@ -969,36 +1083,7 @@ _gnuastro_autocomplete_compreply_table_columns(){
                          }' \
                   | grep ^$tomatch)
 
-    # Add the columns into the completion replies.
-    if [ x"$continuematch" = x ]; then
-        for c in $columns; do COMPREPLY+=("$c"); done
-    else
-        # If there is only one match, include the previously specified
-        # columns in the final filled value and append an ',' to let the
-        # user specify more columns.
-        if [ $(echo $columns | wc -w) = 1 ]; then
-
-            # In the continue-mode we don't want the final value to be
-            # appended with a space.
-            compopt -o nospace
-
-            # When 'fullmatch' and 'tomatch' are the same, this was the
-            # first requested column, so we can safely just print it.
-            if [ x"$fullmatch" = x"$tomatch" ]; then
-                COMPREPLY+=("$columns,")
-
-            # This was not the first column, so we need to add the old ones
-            # as a prefix. But we first need to remove any possible start
-            # of the current column.
-            else
-                local oldcols=$(echo "$fullmatch" | sed -e's|'$tomatch'$||')
-                COMPREPLY+=("$oldcols$columns,")
-            fi
-
-        # There was more than one matching column, so continue suggesting
-        # with only the column names.
-        else
-            for c in $columns; do COMPREPLY+=("$c"); done
-        fi
-    fi
+    # Add the necessary columns in a comma-separated manner.
+    _gnuastro_autocomplete_compreply_comma_when_matched \
+        "$columns" "$tomatch" "$fullmatch" "$continuematch"
 }
diff --git a/bin/fits/Makefile.am b/bin/fits/Makefile.am
index 869cbc1..5d6abe9 100644
--- a/bin/fits/Makefile.am
+++ b/bin/fits/Makefile.am
@@ -36,7 +36,8 @@ astfits_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la \
 
 astfits_SOURCES = main.c ui.c extension.c fits.c keywords.c
 
-EXTRA_DIST = main.h authors-cite.h args.h ui.h extension.c fits.h keywords.h
+EXTRA_DIST = main.h authors-cite.h args.h ui.h extension.c fits.h \
+             keywords.h astfits-complete.bash
 
 
 
diff --git a/bin/fits/args.h b/bin/fits/args.h
index 1a2777f..1cb63f2 100644
--- a/bin/fits/args.h
+++ b/bin/fits/args.h
@@ -140,6 +140,19 @@ struct argp_option program_options[] =
       GAL_OPTIONS_NOT_MANDATORY,
       GAL_OPTIONS_NOT_SET
     },
+    {
+      "listallhdus",
+      UI_KEY_LISTALLHDUS,
+      0,
+      0,
+      "List all HDUs within the file.",
+      UI_GROUP_EXTENSION_INFORMATION,
+      &p->listallhdus,
+      GAL_OPTIONS_NO_ARG_TYPE,
+      GAL_OPTIONS_RANGE_0_OR_1,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
 
 
 
@@ -254,7 +267,7 @@ struct argp_option program_options[] =
     {
       "rename",
       UI_KEY_RENAME,
-      "STR",
+      "STR,STR",
       0,
       "Rename keyword, keeping value and comments.",
       UI_GROUP_KEYWORD,
@@ -267,7 +280,7 @@ struct argp_option program_options[] =
     {
       "update",
       UI_KEY_UPDATE,
-      "STR",
+      "STR,STR",
       0,
       "Update a keyword value or comments.",
       UI_GROUP_KEYWORD,
@@ -356,6 +369,19 @@ struct argp_option program_options[] =
       GAL_OPTIONS_NOT_SET
     },
     {
+      "printkeynames",
+      UI_KEY_PRINTKEYNAMES,
+      0,
+      0,
+      "Print all keyword names.",
+      UI_GROUP_KEYWORD,
+      &p->printkeynames,
+      GAL_OPTIONS_NO_ARG_TYPE,
+      GAL_OPTIONS_RANGE_0_OR_1,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
+    {
       "copykeys",
       UI_KEY_COPYKEYS,
       "INT:INT",
diff --git a/bin/arithmetic/astarithmetic-complete.bash 
b/bin/fits/astfits-complete.bash
similarity index 57%
copy from bin/arithmetic/astarithmetic-complete.bash
copy to bin/fits/astfits-complete.bash
index 612c0f1..10edf87 100644
--- a/bin/arithmetic/astarithmetic-complete.bash
+++ b/bin/fits/astfits-complete.bash
@@ -1,5 +1,5 @@
-# Bash autocompletion to Gnuastro's Arithmetic program. See the comments
-# above 'bin/completion.bash.in' for more.
+# Bash autocompletion to Gnuastro's Fits program. See the comments above
+# 'bin/completion.bash.in' for more.
 #
 # Original author:
 #     Mohammad Akhlaghi <mohammad@akhlaghi.org>
@@ -34,32 +34,13 @@
 
 
 #######################################################################
-############       Only for Arithmetic (this program)      ############
+############          Only for Fits (this program)         ############
 #######################################################################
 
-# Dealing with arguments: Arithmetic only takes array/image files.
-_gnuastro_autocomplete_astarithmetic_arguments(){
-
-    # Local variables to be filled by functions.
-    local arithmetic_lib_operators=""
-    local arithmetic_prog_operators=""
-
-    # Print all accessible images.
-    _gnuastro_autocomplete_compreply_files_certain image "$argument"
-
-    # If atleast one image has already been given, also print the
-    # arithmetic operators with the file names.
-    if _gnuastro_autocomplete_first_in_arguments image; then
-
-        # Fill the variables.
-        _gnuastro_autocomplete_compreply_arithmetic_lib
-        _gnuastro_autocomplete_compreply_arithmetic_prog
-
-        # Add them to COMPREPLY
-        _gnuastro_autocomplete_compreply_from_string \
-            "$arithmetic_lib_operators $arithmetic_prog_operators" \
-            "$argument"
-    fi
+# Dealing with arguments: Fits can take any number of images, so don't
+# suggest options
+_gnuastro_autocomplete_astfits_arguments(){
+    _gnuastro_autocomplete_compreply_files_certain fits "$argument"
 }
 
 
@@ -67,43 +48,76 @@ _gnuastro_autocomplete_astarithmetic_arguments(){
 
 
 # Fill option value (depends on option).
-_gnuastro_autocomplete_astarithmetic_option_value(){
+_gnuastro_autocomplete_astfits_option_value(){
 
     # Internal variables.
     local fits_file=""
     local given_hdu=""
     local given_file=""
+    local wcs_coordsys=""
 
     # Keep this in the same order as the output of '--help', for options
     # with similar operations, keep the order within the '|'s.
     case "$option_name" in
 
-        -h|--hdu|-g|--globalhdu|-w|--wcshdu)
-            _gnuastro_autocomplete_given_file image ""
+        --hdu|--copy|--cut|--remove)
+            _gnuastro_autocomplete_given_file fits ""
             _gnuastro_autocomplete_compreply_hdus \
-                image "$given_file" "$current"
+                all "$given_file" "$current"
             ;;
 
-        -w|--wcsfile)
-            _gnuastro_autocomplete_compreply_files_certain image "$current"
+        --outhdu)
+            _gnuastro_autocomplete_given_file fits "--output"
+            _gnuastro_autocomplete_compreply_hdus \
+                all "$given_file" "$current"
             ;;
 
-        --interpmetric)
-            for v in radial manhattan; do COMPREPLY+=("$v"); done
+        --output)
+            _gnuastro_autocomplete_compreply_files_certain fits "$current"
             ;;
 
         --tableformat)
-            _gnuastro_autocomplete_compreply_tableformat
+            _gnuastro_autocomplete_compreply_tableformat "$current"
+            ;;
+
+        --delete|--datetosec)
+            _gnuastro_autocomplete_given_file_and_hdu fits "" "--hdu"
+            _gnuastro_autocomplete_compreply_keys "$given_file" \
+                                                  "$given_hdu" "$current"
             ;;
 
-        --wcslinearmatrix)
-            _gnuastro_autocomplete_compreply_wcslinearmatrix "$current"
+        --keyvalue)
+            _gnuastro_autocomplete_given_file_and_hdu fits "" "--hdu"
+            _gnuastro_autocomplete_compreply_keys "$given_file" \
+                                                  "$given_hdu" "$current" \
+                                                  "yes"
             ;;
 
-        --numthreads)
-            _gnuastro_autocomplete_compreply_numthreads "$current"
+        --rename|--update)
+            # Find the match.
+            _gnuastro_autocomplete_given_file_and_hdu fits "" "--hdu"
+            _gnuastro_autocomplete_compreply_keys "$given_file" \
+                                                  "$given_hdu" "$current"
+
+            # If there is the only one suggestion, then add a ',' (to let
+            # the user easily type-in the new name.
+            if [        x"${COMPREPLY[0]}" != x ] \
+                   && [ x"${COMPREPLY[1]}"  = x ]; then
+                COMPREPLY[0]="${COMPREPLY[0]},";
+                compopt -o nospace
+            fi
             ;;
 
+        --wcscoordsys)
+            _gnuastro_autocomplete_compreply_wcs_coordsys
+            _gnuastro_autocomplete_compreply_from_string \
+                "$wcs_coordsys" "$current"
+            ;;
+
+        --wcsdistortion)
+            _gnuastro_autocomplete_compreply_from_string \
+                "SIP TPV" "$current"
+            ;;
     esac
 }
 
@@ -111,7 +125,7 @@ _gnuastro_autocomplete_astarithmetic_option_value(){
 
 
 
-_gnuastro_autocomplete_astarithmetic(){
+_gnuastro_autocomplete_astfits(){
 
     # The installation directory of Gnuastro. The '@PREFIX@' part will be
     # replaced automatically during 'make install', with the user's given
@@ -154,7 +168,7 @@ _gnuastro_autocomplete_astarithmetic(){
     # If 'option_name_complete==1', then we are busy filling in the option
     # value.
     if [ $option_name_complete = 1 ]; then
-        _gnuastro_autocomplete_astarithmetic_option_value
+        _gnuastro_autocomplete_astfits_option_value
 
     # When 'option_name' is not empty (and not yet complete), we are busy
     # filling in the option name.
@@ -163,7 +177,7 @@ _gnuastro_autocomplete_astarithmetic(){
 
     # In the case of "none-of-the-above", it is an argument.
     else
-        _gnuastro_autocomplete_astarithmetic_arguments
+        _gnuastro_autocomplete_astfits_arguments
     fi
 }
 
@@ -174,4 +188,4 @@ _gnuastro_autocomplete_astarithmetic(){
 # Define the completion specification, or COMPSPEC: -o bashdefault: Use
 # Bash default completions if nothing is found.  -F function: Use this
 # 'function' to generate the given program's completion.
-complete -o bashdefault -F _gnuastro_autocomplete_astarithmetic astarithmetic
+complete -o bashdefault -F _gnuastro_autocomplete_astfits astfits
diff --git a/bin/fits/fits.c b/bin/fits/fits.c
index b3de42a..9512105 100644
--- a/bin/fits/fits.c
+++ b/bin/fits/fits.c
@@ -612,6 +612,42 @@ fits_certain_hdu(struct fitsparams *p, int list1has0,
 
 
 static void
+fits_list_all_hdus(struct fitsparams *p)
+{
+  fitsfile *fptr;
+  gal_list_str_t *names=NULL;
+  int hducounter=1, hdutype, status=0;
+
+  /* Open the FITS file. */
+  fits_open_file(&fptr, p->input->v, READONLY, &status);
+  gal_fits_io_error(status, NULL);
+
+  /* Start by moving to the first HDU (counting from 1) and then parsing
+     through them. */
+  fits_movabs_hdu(fptr, hducounter, &hdutype, &status);
+  while(status==0)
+    {
+      gal_list_str_add(&names,
+                       fits_list_certain_hdu_string(fptr,
+                                                    hducounter-1),
+                       0);
+      fits_movabs_hdu(fptr, ++hducounter, &hdutype, &status);
+    }
+
+  /* Close the file. */
+  status=0;
+  fits_close_file(fptr, &status);
+
+  /* Print the result. */
+  gal_list_str_print(names);
+  gal_list_str_free(names, 1);
+}
+
+
+
+
+
+static void
 fits_hdu_remove(struct fitsparams *p, int *r)
 {
   char *hdu;
@@ -746,6 +782,7 @@ fits(struct fitsparams *p)
       else if(p->hastablehdu)   fits_certain_hdu(p, 0, 1);
       else if(p->listimagehdus) fits_certain_hdu(p, 1, 0);
       else if(p->listtablehdus) fits_certain_hdu(p, 1, 1);
+      else if(p->listallhdus)   fits_list_all_hdus(p);
 
       /* Options that can be called together. */
       else
diff --git a/bin/fits/keywords.c b/bin/fits/keywords.c
index a869966..aa53e51 100644
--- a/bin/fits/keywords.c
+++ b/bin/fits/keywords.c
@@ -273,7 +273,7 @@ keywords_print_all_keys(struct fitsparams *p, fitsfile 
**fptr)
   int nkeys, status=0;
   char *fullheader, *c, *cf;
 
-  /* Conver the header into a contiguous string. */
+  /* Convert the header into a contiguous string. */
   if( fits_hdr2str(*fptr, 0, NULL, 0, &fullheader, &nkeys, &status) )
     gal_fits_io_error(status, NULL);
 
@@ -301,6 +301,33 @@ keywords_print_all_keys(struct fitsparams *p, fitsfile 
**fptr)
 
 
 
+static void
+keywords_list_key_names(struct fitsparams *p, fitsfile *fptr)
+{
+  size_t i=0;
+  int status=0;
+  char keyname[FLEN_CARD], value[FLEN_CARD], *comment=NULL;
+
+  /* Initialize 'keyname' so the first one (that is blank) isn't
+     printed. */
+  keyname[0]='\0';
+
+  /* Go through all the keywords until you reach 'END'. */
+  while( strcmp(keyname, "END") )
+      {
+        /* Print the most recent keyword: this is placed before reading the
+           keyword because we want to stop upon reading 'END'. */
+        if( strlen(keyname) ) printf("%s\n", keyname);
+
+        /* Read the next keyword. */
+        fits_read_keyn(fptr, i++, keyname, value, comment, &status);
+      }
+}
+
+
+
+
+
 static int
 keywords_verify(struct fitsparams *p, fitsfile **fptr)
 {
@@ -1029,6 +1056,12 @@ keywords(struct fitsparams *p)
       keywords_date_to_seconds(p, fptr);
     }
 
+  /* List all keyword names. */
+  if(p->printkeynames)
+    {
+      keywords_open(p, &fptr, READONLY);
+      keywords_list_key_names(p, fptr);
+    }
 
   /* Close the FITS file */
   if(fptr && fits_close_file(fptr, &status))
diff --git a/bin/fits/main.h b/bin/fits/main.h
index 87c7ec6..59dd7c3 100644
--- a/bin/fits/main.h
+++ b/bin/fits/main.h
@@ -68,8 +68,10 @@ struct fitsparams
   uint8_t       hasimagehdu;   /* File has atleast one image HDU.       */
   uint8_t     listtablehdus;   /* List all table HDUs within the file.  */
   uint8_t     listimagehdus;   /* List all image HDUs within the file.  */
+  uint8_t       listallhdus;   /* List all HDUs within the file.        */
   uint8_t     primaryimghdu;   /* Copy/cut HDU into primary HDU.        */
   uint8_t      printallkeys;   /* Print all the header keywords.        */
+  uint8_t     printkeynames;   /* List all keyword names.               */
   uint8_t              date;   /* Set DATE to current time.             */
   gal_list_str_t      *asis;   /* Strings to write asis.                */
   gal_list_str_t  *keyvalue;   /* Strings to write asis.                */
diff --git a/bin/fits/ui.c b/bin/fits/ui.c
index d63a0dd..a6ba964 100644
--- a/bin/fits/ui.c
+++ b/bin/fits/ui.c
@@ -324,7 +324,7 @@ ui_read_check_only_options(struct fitsparams *p)
      mode flag to keyword-mode. */
   if( p->date || p->comment || p->history || p->asis || p->keyvalue
       || p->delete || p->rename || p->update || p->write || p->verify
-      || p->printallkeys || p->copykeys || p->datetosec
+      || p->printallkeys || p->printkeynames || p->copykeys || p->datetosec
       || p->wcscoordsys || p->wcsdistortion )
     {
       /* Check if a HDU is given. */
@@ -340,6 +340,7 @@ ui_read_check_only_options(struct fitsparams *p)
       /* Keyword-related options that must be called alone. */
       checkkeys = ( (p->keyvalue!=NULL)
                     + (p->datetosec!=NULL)
+                    + (p->printkeynames!=0)
                     + (p->wcscoordsys!=NULL)
                     + (p->wcsdistortion!=NULL) );
       if( ( checkkeys
@@ -361,6 +362,11 @@ ui_read_check_only_options(struct fitsparams *p)
       if(p->wcsdistortion)
         p->distortionid=gal_wcs_distortion_from_string(p->wcsdistortion);
 
+      /* Make sure the value of '--keyvalue' is actually present. */
+      if(p->keyvalue && p->keyvalue->v[0]=='\0')
+        error(EXIT_FAILURE, 0, "the '--keyvalue' option requires a value: "
+              "the name(s) of keywords you want the value of");
+
       /* Set the operating mode. */
       p->mode=FITS_MODE_KEY;
     }
diff --git a/bin/fits/ui.h b/bin/fits/ui.h
index cb400c5..293411c 100644
--- a/bin/fits/ui.h
+++ b/bin/fits/ui.h
@@ -79,8 +79,10 @@ enum option_keys_enum
   UI_KEY_HASIMAGEHDU,
   UI_KEY_LISTTABLEHDUS,
   UI_KEY_LISTIMAGEHDUS,
+  UI_KEY_LISTALLHDUS,
   UI_KEY_OUTHDU,
   UI_KEY_COPYKEYS,
+  UI_KEY_PRINTKEYNAMES,
   UI_KEY_WCSCOORDSYS,
   UI_KEY_PRIMARYIMGHDU,
   UI_KEY_WCSDISTORTION,
diff --git a/bin/table/asttable-complete.bash b/bin/table/asttable-complete.bash
index 878e281..920166b 100644
--- a/bin/table/asttable-complete.bash
+++ b/bin/table/asttable-complete.bash
@@ -128,7 +128,10 @@ _gnuastro_autocomplete_asttable_option_value(){
             ;;
 
         --tableformat)
-            _gnuastro_autocomplete_compreply_tableformat
+            _gnuastro_autocomplete_compreply_tableformat "$current"
+            ;;
+
+        --copy)
             ;;
     esac
 }
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index f3f446f..c0bc223 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -9130,6 +9130,9 @@ Otherwise (when no image HDU exists in the file) nothing 
will be printed.
 In the FITS standard, any array with any dimensions is called an ``image'', 
therefore this option includes 1, 3 and 4 dimensional arrays too.
 However, an image HDU with zero dimensions (which is usually the first 
extension and only contains metadata) is not counted here.
 
+@item --listallhdus
+Print the names or numbers (when a name doesn't exist, counting from zero) of 
all HDUs within the input file on the standard output, one per line.
+
 @item --pixelscale
 Print the HDU's pixel-scale (change in world coordinate for one pixel along 
each dimension) and pixel area or voxel volume.
 Without the @option{--quiet} option, the output of @option{--pixelscale} has 
multiple lines and explanations, thus being more human-friendly.
@@ -9395,9 +9398,9 @@ All keywords given will be removed from the headers in 
the same given order.
 If the keyword doesn't exist, Fits will give a warning and return with a 
non-zero value, but will not stop.
 To stop as soon as an error occurs, run with @option{--quitonerror}.
 
-@item -r STR
-@itemx --rename=STR
-Rename a keyword to a new value.
+@item -r STR,STR
+@itemx --rename=STR,STR
+Rename a keyword to a new value (for example @option{--rename=OLDNAME,NEWNAME}.
 @option{STR} contains both the existing and new names, which should be 
separated by either a comma (@key{,}) or a space character.
 Note that if you use a space character, you have to put the value to this 
option within double quotation marks (@key{"}) so the space character is not 
interpreted as an option separator.
 Multiple instances of @option{--rename} can be given in one command.
@@ -9571,10 +9574,14 @@ To stop as soon as an error occurs, run with 
@option{--quitonerror}.
 
 @item -p
 @itemx --printallkeys
-Print all the keywords in the specified FITS extension (HDU) on the 
command-line.
+Print the full meta data (keywords, values, units and comments) in the 
specified FITS extension (HDU).
 If this option is called along with any of the other keyword editing commands, 
as described above, all other editing commands take precedence to this.
 Therefore, it will print the final keywords after all the editing has been 
done.
 
+@item --printkeynames
+Print only the keyword names of the specified FITS extension (HDU), one line 
per name.
+This option must be called alone.
+
 @item -v
 @itemx --verify
 Verify the @code{DATASUM} and @code{CHECKSUM} data integrity keywords of the 
FITS standard.
@@ -17846,7 +17853,7 @@ Therefore if the input standard deviation (or variance) 
image also contains the
 The HDU of the Sky value standard deviation image.
 
 @item --variance
-The dataset given to @option{--stdfile} (and @option{--stdhdu} has the Sky 
variance of every pixel, not the Sky standard deviation.
+The dataset given to @option{--instd} (and @option{--stdhdu} has the Sky 
variance of every pixel, not the Sky standard deviation.
 
 @item --forcereadstd
 Read the input STD image even if it is not required by any of the requested 
columns.



reply via email to

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