gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master cfea357: Fits prints full list of header keys


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master cfea357: Fits prints full list of header keys when only --hdu given
Date: Thu, 21 Sep 2017 23:05:10 -0400 (EDT)

branch: master
commit cfea3576de27c50e252121400b8add75a494ddc0
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    Fits prints full list of header keys when only --hdu given
    
    When only the `--hdu' option is given on the command-line (not in a
    configuration file) with no other operation (on keywords or HDUs)
    requested, the full list of header keywords is printed (as if you had only
    called `--printallkeys').
    
    This feature was suggested by Leindert Boogaard.
---
 NEWS              |  5 +++++
 bin/fits/main.h   | 31 ++++++++++++++++---------------
 bin/fits/ui.c     | 24 +++++++++++++++++++++---
 doc/gnuastro.texi | 23 +++++++++++++++++++----
 4 files changed, 61 insertions(+), 22 deletions(-)

diff --git a/NEWS b/NEWS
index a5b442b..d065e6a 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,11 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
 
 ** New features
 
+  Fits: when an extension/HDU is identified on the command-line with the
+  `--hdu' option and no operation is requested, the full list of header
+  keywords in that HDU will be printed (as if only `--printallkeys' was
+  called).
+
   NoiseChisel: with the new `--widekernel' option it is now possible to use
   a wider kernel to identify which tiles contain signal. The rest of the
   steps (identifying the quantile threshold on the selected tiles and etc)
diff --git a/bin/fits/main.h b/bin/fits/main.h
index 46bae7d..782850d 100644
--- a/bin/fits/main.h
+++ b/bin/fits/main.h
@@ -53,21 +53,22 @@ enum fits_mode
 struct fitsparams
 {
   /* From the environment. */
-  struct gal_options_common_params cp;  /* Common parameters.     */
-  char          *filename;     /* Name of input file.             */
-  gal_list_str_t  *remove;     /* Remove extensions from a file.  */
-  gal_list_str_t    *copy;     /* Copy extensions to output.      */
-  gal_list_str_t     *cut;     /* Copy ext. to output and remove. */
-  uint8_t    printallkeys;     /* Print all the header keywords.  */
-  uint8_t            date;     /* Set DATE to current time.       */
-  char           *comment;     /* COMMENT value.                  */
-  char           *history;     /* HISTORY value.                  */
-  gal_list_str_t    *asis;     /* Strings to write asis.          */
-  gal_list_str_t  *delete;     /* Keywords to remove.             */
-  gal_list_str_t  *rename;     /* Rename a keyword.               */
-  gal_list_str_t  *update;     /* For keywords to update.         */
-  gal_list_str_t   *write;     /* Full arg. for keywords to add.  */
-  uint8_t     quitonerror;     /* Quit if an error occurs.        */
+  struct gal_options_common_params cp;  /* Common parameters.       */
+  int  hdu_in_commandline;     /* HDU wasn't given in config. file. */
+  char          *filename;     /* Name of input file.               */
+  gal_list_str_t  *remove;     /* Remove extensions from a file.    */
+  gal_list_str_t    *copy;     /* Copy extensions to output.        */
+  gal_list_str_t     *cut;     /* Copy ext. to output and remove.   */
+  uint8_t    printallkeys;     /* Print all the header keywords.    */
+  uint8_t            date;     /* Set DATE to current time.         */
+  char           *comment;     /* COMMENT value.                    */
+  char           *history;     /* HISTORY value.                    */
+  gal_list_str_t    *asis;     /* Strings to write asis.            */
+  gal_list_str_t  *delete;     /* Keywords to remove.               */
+  gal_list_str_t  *rename;     /* Rename a keyword.                 */
+  gal_list_str_t  *update;     /* For keywords to update.           */
+  gal_list_str_t   *write;     /* Full arg. for keywords to add.    */
+  uint8_t     quitonerror;     /* Quit if an error occurs.          */
 
   /* Internal: */
   int                         mode;  /* Operating on HDUs or keywords.  */
diff --git a/bin/fits/ui.c b/bin/fits/ui.c
index 6f1388e..33576d2 100644
--- a/bin/fits/ui.c
+++ b/bin/fits/ui.c
@@ -266,7 +266,15 @@ ui_read_check_only_options(struct fitsparams *p)
   /* If no options are given, go into HDU mode, which will print the HDU
      information when nothing is asked. */
   if(p->mode==FITS_MODE_INVALID)
-    p->mode=FITS_MODE_HDU;
+    {
+      if(p->hdu_in_commandline)
+        {
+          p->printallkeys=1;
+          p->mode = FITS_MODE_KEY;
+        }
+      else
+        p->mode = FITS_MODE_HDU;
+    }
 }
 
 
@@ -408,8 +416,8 @@ ui_fill_fits_headerll(gal_list_str_t *input, 
gal_fits_list_key_t **output)
               errno=0;
               fvalue=dp=malloc(sizeof *dp);
               if(dp==NULL)
-                error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `dp'",
-                      __func__, sizeof *dp);
+                error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for "
+                      "`dp'", __func__, sizeof *dp);
               *dp=d;
             }
           else
@@ -461,6 +469,7 @@ ui_preparations(struct fitsparams *p)
 void
 ui_read_check_inputs_setup(int argc, char *argv[], struct fitsparams *p)
 {
+  size_t i;
   struct gal_options_common_params *cp=&p->cp;
 
 
@@ -485,6 +494,15 @@ ui_read_check_inputs_setup(int argc, char *argv[], struct 
fitsparams *p)
     error(EXIT_FAILURE, errno, "parsing arguments");
 
 
+  /* Check if the HDU is specified on the command-line. If so, then later,
+     if no operation is requested, we will print the header of the given
+     HDU.*/
+  for(i=0; !gal_options_is_last(&cp->coptions[i]); ++i)
+    if(cp->coptions[i].key==GAL_OPTIONS_KEY_HDU
+       && cp->coptions[i].set)
+      p->hdu_in_commandline=1;
+
+
   /* Read the configuration files and set the common values. */
   gal_options_read_config_set(&p->cp);
 
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index cbef6af..a567e7f 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -6678,10 +6678,13 @@ One line examples:
 $ astfits image.fits
 
 ## Print the header keywords in the second HDU (counting from 0):
-$ astfits image.fits -h1 --printallkeys
+$ astfits image.fits -h1
 
 ## Only print header keywords that contain `NAXIS':
-$ astfits image.fits -h1 --printallkeys | grep NAXIS
+$ astfits image.fits -h1 | grep NAXIS
+
+## Only print the WCS standard PC matrix elements
+$ astfits image.fits -h1 | grep 'PC._.'
 
 ## Copy a HDU from input.fits to out.fits:
 $ astfits input.fits --copy=hdu-name --output=out.fits
@@ -6737,6 +6740,18 @@ HDU (extension) information: `image.fits'.
 3      CATALOG         table_binary    12371x5
 @end example
 
+If a specific HDU is identified on the command-line with the @option{--hdu}
+(or @option{-h} option) and no operation requested, then the full list of
+header keywords in that HDU will be printed (as if the
address@hidden was called, see below). It is important to remember
+that this only occurs when @option{--hdu} is given on the command-line. The
address@hidden value given in a configuration file will only be used when a
+specific operation on keywords requested. Therefore as described in the
+paragraphs above, when no explicit call to the @option{--hdu} option is
+made on the command-line and no operation is requested (on the command-line
+or configuration files), the basic information of each HDU/extension is
+printed.
+
 The operating mode and input/output options to Fits are similar to the
 other programs and fully described in @ref{Common options}. The options
 particular to Fits can be divided into two groups: 1) those related to
@@ -6767,8 +6782,8 @@ extensions will be copied from the input FITS file to the 
output FITS file
 in the given order (on the command-line and also in configuration files,
 see @ref{Configuration file precedence}). If the separate classes are
 called together in one run of Fits, then first @option{--copy} is run (on
-all specified HDUs), followed @option{--cut} (again on all specified HDUs),
-and then @option{--remove} (on all specified HDUs).
+all specified HDUs), followed by @option{--cut} (again on all specified
+HDUs), and then @option{--remove} (on all specified HDUs).
 
 The @option{--copy} and @option{--cut} options need an output FITS file
 (specified with the @option{--output} option). If the output file exists,



reply via email to

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