gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 1427dfae: Arithmetic: checking/deleting output


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 1427dfae: Arithmetic: checking/deleting output file (if needed) in any case
Date: Tue, 8 Feb 2022 05:14:49 -0500 (EST)

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

    Arithmetic: checking/deleting output file (if needed) in any case
    
    Until now, when the command-line arguments (tokens) to the reverse polish
    notation didn't include a FITS file (for example with the 'makenew'
    operator), Arithmetic wouldn't make sure it is removed (if the user hasn't
    called '--dontdelete') before it starts writing its output. As a result,
    when the output file already existed, the output dataset would be written
    in a new extension of the output file.
    
    But this is not intuitive in Gnuastro: all programs (including Arithmetic;
    when a FITS file exists in the arguments) will check the existance of the
    output and delete it.
    
    With this commit, the source of this bug has been found and fixed! We were
    checking for an output file name's existance only while parsing the tokens
    and when we found a FITS file! This was done because we needed a base-name
    for the output file if no '--output' was given. However, as a result, we
    were implicitly assuming that 'makenew' is either called with another FITS
    file, or without '--output'!
    
    The check has now become generic, so we don't check for the existance of
    the output file while parsing the tokens. We just set the basename and
    unify the checking for the output file afterwards (to be useful in all
    cases).
    
    This fixes bug #62008.
---
 NEWS                |  2 ++
 bin/arithmetic/ui.c | 32 ++++++++++++++++----------------
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/NEWS b/NEWS
index bf46ea6e..ec182c17 100644
--- a/NEWS
+++ b/NEWS
@@ -159,6 +159,8 @@ See the end of the file for license conditions.
   bug #61967: DS9 polygon region files not read when they have width and
               color; reported by Zohreh Ghaffari, fixed by Pedram Ashofteh
               Ardakani.
+  bug #62008: Arithmetic not deleting existing output when the 'makenew' is
+              used (no FITS file exists in the reverse polish notation).
 
 
 
diff --git a/bin/arithmetic/ui.c b/bin/arithmetic/ui.c
index 8ad01970..dab2f435 100644
--- a/bin/arithmetic/ui.c
+++ b/bin/arithmetic/ui.c
@@ -255,9 +255,8 @@ ui_read_check_only_options(struct arithmeticparams *p)
 static void
 ui_check_options_and_arguments(struct arithmeticparams *p)
 {
-  char *filename;
-  int output_checked=0;
   gal_list_str_t *token, *hdu;
+  char *filename, *basename=NULL;
   size_t nummultiext=0, numhdus=0;
   struct gal_options_common_params *cp=&p->cp;
 
@@ -306,17 +305,10 @@ ui_check_options_and_arguments(struct arithmeticparams *p)
               if( gal_array_name_recognized_multiext(token->v)  )
                 ++nummultiext;
 
-              /* If the output filename isn't set yet, then set it. */
-              if(output_checked==0)
-                {
-                  if(cp->output)
-                    gal_checkset_writable_remove(cp->output, cp->keep,
-                                                 cp->dontdelete);
-                  else
-                    p->cp.output=gal_checkset_automatic_output(cp, token->v,
-                                                               "_arith.fits");
-                  output_checked=1;
-                }
+              /* If no output name is given, we need to extract the output
+                 name from the inputs. */
+              if(cp->output==NULL && basename==NULL)
+                basename=token->v;
             }
 
           /* This token is a number. Check if a negative dash was present that
@@ -337,10 +329,18 @@ ui_check_options_and_arguments(struct arithmeticparams *p)
   /* In case no output name has been given (can happen with operators like
      'makenew' when the user doesn't set an output name explicity), use a
      default name. */
-  if(p->cp.output==NULL)
+  if(cp->output)
+    gal_checkset_writable_remove(cp->output, cp->keep, cp->dontdelete);
+  else
     {
-      gal_checkset_allocate_copy("arithmetic.fits", &p->cp.output);
-      gal_checkset_writable_remove(p->cp.output, cp->keep, cp->dontdelete);
+      if(basename)
+        p->cp.output=gal_checkset_automatic_output(cp, basename,
+                                                   "_arith.fits");
+      else
+        {
+          gal_checkset_allocate_copy("arithmetic.fits", &p->cp.output);
+          gal_checkset_writable_remove(p->cp.output, cp->keep, cp->dontdelete);
+        }
     }
 
   /* Count the number of HDU values (if globalhdu isn't given) and check if



reply via email to

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