gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 2c8709f 2/2: Fits program's comment and histor


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 2c8709f 2/2: Fits program's comment and history may be called multiple times
Date: Fri, 9 Mar 2018 14:11:39 -0500 (EST)

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

    Fits program's comment and history may be called multiple times
    
    Until now, the `--comment' and `--history' keywords would only write one
    string (their last value) into the FITS file. From this commit, they will
    write all values given to them, no matter how many times they are called.
---
 NEWS                |  4 ++++
 bin/fits/args.h     |  4 ++--
 bin/fits/keywords.c | 35 +++++++++++++++++++++++------------
 bin/fits/main.h     |  4 ++--
 doc/gnuastro.texi   | 26 +++++++++++++-------------
 5 files changed, 44 insertions(+), 29 deletions(-)

diff --git a/NEWS b/NEWS
index 6f585be..9757280 100644
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,10 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
   the given value is smaller than the minimum or larger than the maximum of
   the input dataset's range.
 
+  Fits: The `--comment' and `--history' command may be called multiple
+  times to write multiple COMMENT/HISTORY keywords into the input FITS
+  file.
+
 ** Bug fixes
 
   Many unused result warnings for asprintf in some compilers (bug #52979).
diff --git a/bin/fits/args.h b/bin/fits/args.h
index a792d6c..76baf3c 100644
--- a/bin/fits/args.h
+++ b/bin/fits/args.h
@@ -157,7 +157,7 @@ struct argp_option program_options[] =
       "Add HISTORY keyword, any length is ok.",
       UI_GROUP_KEYWORD,
       &p->history,
-      GAL_TYPE_STRING,
+      GAL_TYPE_STRLL,
       GAL_OPTIONS_RANGE_ANY,
       GAL_OPTIONS_NOT_MANDATORY,
       GAL_OPTIONS_NOT_SET
@@ -170,7 +170,7 @@ struct argp_option program_options[] =
       "Add COMMENT keyword, any length is ok.",
       UI_GROUP_KEYWORD,
       &p->comment,
-      GAL_TYPE_STRING,
+      GAL_TYPE_STRLL,
       GAL_OPTIONS_RANGE_ANY,
       GAL_OPTIONS_NOT_MANDATORY,
       GAL_OPTIONS_NOT_SET
diff --git a/bin/fits/keywords.c b/bin/fits/keywords.c
index f36e49f..366a5fc 100644
--- a/bin/fits/keywords.c
+++ b/bin/fits/keywords.c
@@ -316,21 +316,28 @@ keywords(struct fitsparams *p)
 
   /* Put in any full line of keywords as-is. */
   if(p->asis)
-    for(tstll=p->asis; tstll!=NULL; tstll=tstll->next)
-      {
-        fits_write_record(fptr, tstll->v, &status);
-        if(status) r=fits_has_error(p, FITS_ACTION_WRITE, tstll->v, status);
-        status=0;
-      }
+    {
+      keywords_open(p, &fptr, READWRITE);
+      for(tstll=p->asis; tstll!=NULL; tstll=tstll->next)
+        {
+          fits_write_record(fptr, tstll->v, &status);
+          if(status) r=fits_has_error(p, FITS_ACTION_WRITE, tstll->v, status);
+          status=0;
+        }
+    }
 
 
   /* Add the history keyword(s). */
   if(p->history)
     {
       keywords_open(p, &fptr, READWRITE);
-      fits_write_history(fptr, p->history, &status);
-      if(status) r=fits_has_error(p, FITS_ACTION_WRITE, "HISTORY", status);
-      status=0;
+      for(tstll=p->history; tstll!=NULL; tstll=tstll->next)
+        {
+          fits_write_history(fptr, tstll->v, &status);
+          if(status)
+            r=fits_has_error(p, FITS_ACTION_WRITE, "HISTORY", status);
+          status=0;
+        }
     }
 
 
@@ -338,9 +345,13 @@ keywords(struct fitsparams *p)
   if(p->comment)
     {
       keywords_open(p, &fptr, READWRITE);
-      fits_write_comment(fptr, p->comment, &status);
-      if(status) r=fits_has_error(p, FITS_ACTION_WRITE, "COMMENT", status);
-      status=0;
+      for(tstll=p->comment; tstll!=NULL; tstll=tstll->next)
+        {
+          fits_write_comment(fptr, tstll->v, &status);
+          if(status)
+            r=fits_has_error(p, FITS_ACTION_WRITE, "COMMENT", status);
+          status=0;
+        }
     }
 
 
diff --git a/bin/fits/main.h b/bin/fits/main.h
index 3117d72..78681f0 100644
--- a/bin/fits/main.h
+++ b/bin/fits/main.h
@@ -61,13 +61,13 @@ struct fitsparams
   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.    */
+  gal_list_str_t *history;     /* HISTORY value.                    */
+  gal_list_str_t *comment;     /* COMMENT value.                    */
   uint8_t     quitonerror;     /* Quit if an error occurs.          */
 
   /* Internal: */
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index c7c15fd..a477333 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -8261,20 +8261,17 @@ comments and units for the keyword, see the 
@option{--update} option above.
 
 @item -H STR
 @itemx --history STR
-Add a @code{HISTORY} keyword to the header. The string given to this
-keyword will be separated into multiple keyword cards if it is longer than
-70 characters. With each run only one value for the @option{--history}
-option will be read. If there are multiple, it is the last one. If there is
-an error, 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
address@hidden
+Add a @code{HISTORY} keyword to the header with the given value. A new
address@hidden keyword will be created for every instance of this
+option. If the string given to this option is longer than 70 characters, it
+will be separated into multiple keyword cards. If there is an error, 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 -c STR
 @itemx --comment STR
-Add a @code{COMMENT} keyword to the header. Similar to the explanation for
address@hidden above. If there is a writing error, 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}.
+Add a @code{COMMENT} keyword to the header with the given value. Similar to
+the explanation for @option{--history} above.
 
 @item -t
 @itemx --date
@@ -8285,9 +8282,12 @@ not stop. To stop as soon as an error occurs, run with
 @option{--quitonerror}.
 
 @item -p
address@hidden --printall
address@hidden --printallkeys
 Print all the keywords in the specified FITS extension (HDU) on the
-command-line.
+command-line. 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 -Q
 @itemx --quitonerror



reply via email to

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