gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 2dd9b61 2/2: New --globalhdu (-g) option for A


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 2dd9b61 2/2: New --globalhdu (-g) option for Arithmetic
Date: Sun, 25 Jun 2017 18:42:47 -0400 (EDT)

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

    New --globalhdu (-g) option for Arithmetic
    
    When many files are input into Arithmetic, it may be the case that same HDU
    string should be used for all of them. It is thus very inconvenient to call
    something like `--hdu=1' 100 times (for 100 input files) for example, even
    in a configuration file.
    
    With this commit, Arithmetic now has a new `--globalhdu' (`-g')
    option. When this option is called, the `--hdu' option is ignored and for
    any input image, Arithmetic will use the string/number given to this
    option.
    
    This was suggested by David Valls-Gabaud.
---
 bin/arithmetic/args.h     | 14 ++++++++++++++
 bin/arithmetic/main.h     |  5 +++--
 bin/arithmetic/operands.c |  5 ++++-
 bin/arithmetic/ui.c       | 25 +++++++++++++++++--------
 bin/arithmetic/ui.h       | 16 ++++++++++++++++
 doc/gnuastro.texi         |  7 +++++++
 6 files changed, 61 insertions(+), 11 deletions(-)

diff --git a/bin/arithmetic/args.h b/bin/arithmetic/args.h
index f6f73a8..2bf0e25 100644
--- a/bin/arithmetic/args.h
+++ b/bin/arithmetic/args.h
@@ -28,6 +28,20 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 /* Definition of program-specific options. */
 struct argp_option program_options[] =
   {
+    {
+      "globalhdu",
+      UI_KEY_GLOBALHDU,
+      "STR",
+      0,
+      "Use this HDU for all inputs, ignore `--hdu'.",
+      GAL_OPTIONS_GROUP_INPUT,
+      &p->globalhdu,
+      GAL_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
+
     {0}
   };
 
diff --git a/bin/arithmetic/main.h b/bin/arithmetic/main.h
index 78ac2fb..f55451c 100644
--- a/bin/arithmetic/main.h
+++ b/bin/arithmetic/main.h
@@ -68,11 +68,12 @@ struct arithmeticparams
   struct gal_options_common_params cp;  /* Common parameters.           */
 
   /* Input: */
-  gal_list_str_t     *hdus; /* List of all given HDU strings. */
-  gal_list_str_t   *tokens; /* List of all arithmetic tokens. */
+  gal_list_str_t     *hdus;  /* List of all given HDU strings.          */
+  gal_list_str_t   *tokens;  /* List of all arithmetic tokens.          */
   size_t        addcounter;  /* The number of FITS images added.        */
   size_t        popcounter;  /* The number of FITS images popped.       */
   gal_data_t       refdata;  /* Container for information of the data.  */
+  char          *globalhdu;  /* Single HDU for all inputs.              */
 
   /* Operating mode: */
 
diff --git a/bin/arithmetic/operands.c b/bin/arithmetic/operands.c
index 3d6b77a..3062efa 100644
--- a/bin/arithmetic/operands.c
+++ b/bin/arithmetic/operands.c
@@ -79,7 +79,10 @@ operands_add(struct arithmeticparams *p, char *filename, 
gal_data_t *data)
       if(filename != NULL && gal_fits_name_is_fits(filename))
         {
           /* Set the HDU for this filename. */
-          newnode->hdu=gal_list_str_pop(&p->hdus);
+          if(p->globalhdu)
+            gal_checkset_allocate_copy(p->globalhdu, &newnode->hdu);
+          else
+            newnode->hdu=gal_list_str_pop(&p->hdus);
 
           /* Increment the FITS counter. */
           ++p->addcounter;
diff --git a/bin/arithmetic/ui.c b/bin/arithmetic/ui.c
index ce995e6..e3cbac3 100644
--- a/bin/arithmetic/ui.c
+++ b/bin/arithmetic/ui.c
@@ -272,14 +272,21 @@ ui_check_options_and_arguments(struct arithmeticparams *p)
         token->v[0]='-';
     }
 
-  /* Count the number of HDU values and check if its not less than the
-     number of input FITS images. */
-  for(hdu=p->hdus; hdu!=NULL; hdu=hdu->next) ++numhdus;
-  if(numhdus<numfits)
-    error(EXIT_FAILURE, 0, "not enough HDUs. There are %zu input FITS "
-          "files, but only %zu HDUs. You can use the `--hdu' (`-h') option "
-          "to specify the number or name of a HDU for each FITS file",
-          numfits, numhdus);
+  /* Count the number of HDU values (if globalhdu isn't given) and check if
+     its not less than the number of input FITS images. */
+  if(p->globalhdu)
+    { if(p->hdus) { gal_list_str_free(p->hdus, 1); p->hdus=NULL; }; }
+  else
+    {
+      for(hdu=p->hdus; hdu!=NULL; hdu=hdu->next) ++numhdus;
+      if(numhdus<numfits)
+        error(EXIT_FAILURE, 0, "not enough HDUs. There are %zu input FITS "
+              "files, so the `--hdu' (`-h') option must be called %zu "
+              "times (once for each FITS file). If the HDU value is the "
+              "same for all the files, you may use `--globalhdu' (`-g') to "
+              "specify a single HDU to be used for any number of input "
+              "files", numfits, numfits);
+    }
 }
 
 
@@ -382,7 +389,9 @@ ui_read_check_inputs_setup(int argc, char *argv[], struct 
arithmeticparams *p)
 void
 freeandreport(struct arithmeticparams *p, struct timeval *t1)
 {
+  /* Free the simple strings. */
   free(p->cp.output);
+  if(p->globalhdu) free(p->globalhdu);
 
   /* If there are any remaining HDUs in the hdus linked list, then
      free them. */
diff --git a/bin/arithmetic/ui.h b/bin/arithmetic/ui.h
index 7ef7468..63ecc17 100644
--- a/bin/arithmetic/ui.h
+++ b/bin/arithmetic/ui.h
@@ -23,6 +23,22 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #ifndef UI_H
 #define UI_H
 
+
+/* Available letters for short options:
+
+   a b c d e f i j k l m n p r s t u v w x y z
+   A B C E G H J L O Q R W X Y
+*/
+enum option_keys_enum
+{
+  /* With short-option version. */
+  UI_KEY_GLOBALHDU       = 'g',
+
+  /* Only with long version (start with a value 1000, the rest will be set
+     automatically). */
+};
+
+
 void
 ui_read_check_inputs_setup(int argc, char *argv[], struct arithmeticparams *p);
 
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 6de7077..077ebda 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -8934,6 +8934,13 @@ extra HDUs in the configuration files and by default 
several HDUs with
 a value of @option{0} are kept in the system-wide configuration file
 when you install Gnuastro.
 
address@hidden -g INT/STR
address@hidden --globalhdu INT/STR
+Use the value to this option as the HDU of all input FITS files. This
+option is very convenient when you have many input files and the dataset of
+interest is in the same HDU of all the files. When this option is called,
+any values given to the @option{--hdu} option (explained above) are ignored
+and will not be used.
 @end table
 
 Arithmetic accepts two kinds of input: images and numbers. Images are



reply via email to

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