gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 4ca9403: Library (fits.h): quiet option added


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 4ca9403: Library (fits.h): quiet option added to gal_fits_key_write_filename
Date: Thu, 22 Jul 2021 19:47:43 -0400 (EDT)

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

    Library (fits.h): quiet option added to gal_fits_key_write_filename
    
    Many of the programs write the filename of their inputs as keywords in the
    output FITS files. When the filename is longer than 68 characters, they
    would also print a warning that the full name is trunctated. However, this
    warning did not account for the '--quiet' option! So even when the user
    doesn't want any output printed on the command-line, the worning was
    printed!
    
    With this commit, the main function in charge of this operation
    ('gal_fits_key_write_filename') has been given a 'quiet' argument. When it
    isn't zero, no warning will be printed. All the calls to this function
    within all the programs have also been modified to take the value from the
    user's input arguments.
    
    This fixes bug #60958 that was reported by Raúl Infante-Sainz.
---
 NEWS                          |  6 ++++++
 bin/convolve/convolve.c       |  3 ++-
 bin/crop/onecrop.c            |  3 ++-
 bin/match/match.c             |  4 ++--
 bin/mkcatalog/mkcatalog.c     | 40 +++++++++++++++++++++++++++-------------
 bin/mknoise/mknoise.c         |  6 ++++--
 bin/mkprof/mkprof.c           |  3 ++-
 bin/noisechisel/noisechisel.c |  3 ++-
 bin/segment/segment.c         |  3 ++-
 bin/statistics/sky.c          |  3 ++-
 bin/statistics/statistics.c   |  9 ++++++---
 bin/warp/warp.c               |  6 ++++--
 doc/announce-acknowledge.txt  |  1 +
 doc/gnuastro.texi             | 26 +++++++++++++-------------
 lib/fits.c                    | 14 ++++++++------
 lib/gnuastro/fits.h           |  3 ++-
 lib/options.c                 |  3 ++-
 17 files changed, 87 insertions(+), 49 deletions(-)

diff --git a/NEWS b/NEWS
index d537eed..7e6e6c4 100644
--- a/NEWS
+++ b/NEWS
@@ -89,6 +89,10 @@ See the end of the file for license conditions.
      called). Until now, adding columns from other files was done after all
      row selection or re-ordering, but this was not too practically useful.
 
+  Library
+   - gal_fits_key_write_filename: now has 'quiet' argument to avoid
+     printing a warning.
+
 ** Bugs fixed
   bug #60725: MakeCatalog doesn't put comment on --halfsumsb column.
   bug #60776: Radial profile script not using standard deviation image,
@@ -105,6 +109,8 @@ See the end of the file for license conditions.
               fixed with the help of Mark Calabretta.
   bug #60923: Standard deviation calculation giving NaN values due to
               floating point errors, found and fixed by Natáli Anzanello.
+  bug #60958: Warning on long filename not written in FITS keyword printed
+              even when '--quiet' is called, found by Raúl Infante-Sainz.
 
 
 
diff --git a/bin/convolve/convolve.c b/bin/convolve/convolve.c
index 881dcae..6c3872a 100644
--- a/bin/convolve/convolve.c
+++ b/bin/convolve/convolve.c
@@ -823,7 +823,8 @@ convolve(struct convolveparams *p)
      the output. */
   if( gal_fits_name_is_fits(p->cp.output) )
     {
-      gal_fits_key_write_filename("input", p->filename, &cp->okeys, 1);
+      gal_fits_key_write_filename("input", p->filename, &cp->okeys, 1,
+                                  cp->quiet);
       gal_fits_key_write_config(&cp->okeys, "Convolve configuration",
                                 "CONVOLVE-CONFIG", cp->output, "0");
     }
diff --git a/bin/crop/onecrop.c b/bin/crop/onecrop.c
index f1c8bbd..d8a2566 100644
--- a/bin/crop/onecrop.c
+++ b/bin/crop/onecrop.c
@@ -747,7 +747,8 @@ onecrop(struct onecropparams *crp)
       /* A section has been added to the cropped image from this input
          image, so save the information of this image. */
       sprintf(basekeyname, "ICF%zu", crp->numimg);
-      gal_fits_key_write_filename(basekeyname, img->name, &headers, 0);
+      gal_fits_key_write_filename(basekeyname, img->name, &headers, 0,
+                                  p->cp.quiet);
       sprintf(regionkey, "%sPIX", basekeyname);
       gal_fits_key_list_add_end(&headers, GAL_TYPE_STRING, regionkey,
                                 0, region, 0, "Range of pixels used for "
diff --git a/bin/match/match.c b/bin/match/match.c
index 71850a3..c31f322 100644
--- a/bin/match/match.c
+++ b/bin/match/match.c
@@ -600,10 +600,10 @@ match(struct matchparams *p)
       gal_fits_key_write_filename("input1", ( p->input1name
                                               ? p->input1name
                                               : "Standard input" ),
-                                  &p->cp.okeys, 1);
+                                  &p->cp.okeys, 1, p->cp.quiet);
       gal_fits_key_write_filename("input2",
                                   p->input2name?p->input2name:"--coord",
-                                  &p->cp.okeys, 1);
+                                  &p->cp.okeys, 1, p->cp.quiet);
       gal_fits_key_write_config(&p->cp.okeys, "Match configuration",
                                 "MATCH-CONFIG", p->out1name, "0");
     }
diff --git a/bin/mkcatalog/mkcatalog.c b/bin/mkcatalog/mkcatalog.c
index 18f5a2d..6ec3ca2 100644
--- a/bin/mkcatalog/mkcatalog.c
+++ b/bin/mkcatalog/mkcatalog.c
@@ -358,27 +358,34 @@ void
 mkcatalog_outputs_keys_infiles(struct mkcatalogparams *p,
                                gal_fits_list_key_t **keylist)
 {
+  int quiet=p->cp.quiet;
   char *stdname, *stdhdu, *stdvalcom;
 
   gal_fits_key_list_title_add_end(keylist,
                                   "Input files and/or configuration", 0);
 
   /* Object labels. */
-  gal_fits_key_write_filename("INLAB", p->objectsfile, keylist, 0);
-  gal_fits_key_write_filename("INLABHDU", p->cp.hdu, keylist, 0);
+  gal_fits_key_write_filename("INLAB", p->objectsfile, keylist, 0,
+                              quiet);
+  gal_fits_key_write_filename("INLABHDU", p->cp.hdu, keylist, 0,
+                              quiet);
 
   /* Clump labels. */
   if(p->clumps)
     {
-      gal_fits_key_write_filename("INCLU", p->usedclumpsfile, keylist, 0);
-      gal_fits_key_write_filename("INCLUHDU", p->clumpshdu, keylist, 0);
+      gal_fits_key_write_filename("INCLU", p->usedclumpsfile, keylist, 0,
+                                  quiet);
+      gal_fits_key_write_filename("INCLUHDU", p->clumpshdu, keylist, 0,
+                                  quiet);
     }
 
   /* Values image. */
   if(p->values)
     {
-      gal_fits_key_write_filename("INVAL", p->usedvaluesfile, keylist, 0);
-      gal_fits_key_write_filename("INVALHDU", p->valueshdu, keylist, 0);
+      gal_fits_key_write_filename("INVAL", p->usedvaluesfile, keylist, 0,
+                                  quiet);
+      gal_fits_key_write_filename("INVALHDU", p->valueshdu, keylist, 0,
+                                  quiet);
     }
 
   /* Sky image/value. */
@@ -391,8 +398,10 @@ mkcatalog_outputs_keys_infiles(struct mkcatalogparams *p,
                                        NULL);
       else
         {
-          gal_fits_key_write_filename("INSKY", p->usedskyfile, keylist, 0);
-          gal_fits_key_write_filename("INSKYHDU", p->skyhdu, keylist, 0);
+          gal_fits_key_write_filename("INSKY", p->usedskyfile, keylist, 0,
+                                      quiet);
+          gal_fits_key_write_filename("INSKYHDU", p->skyhdu, keylist, 0,
+                                      quiet);
         }
     }
 
@@ -414,16 +423,20 @@ mkcatalog_outputs_keys_infiles(struct mkcatalogparams *p,
                                        stdname, stdvalcom, NULL);
       else
         {
-          gal_fits_key_write_filename(stdname, p->usedstdfile, keylist, 0);
-          gal_fits_key_write_filename(stdhdu, p->stdhdu, keylist, 0);
+          gal_fits_key_write_filename(stdname, p->usedstdfile, keylist, 0,
+                                      quiet);
+          gal_fits_key_write_filename(stdhdu, p->stdhdu, keylist, 0,
+                                      quiet);
         }
     }
 
   /* Upper limit mask. */
   if(p->upmaskfile)
     {
-      gal_fits_key_write_filename("INUPM", p->upmaskfile, keylist, 0);
-      gal_fits_key_write_filename("INUPMHDU", p->upmaskhdu, keylist, 0);
+      gal_fits_key_write_filename("INUPM", p->upmaskfile, keylist, 0,
+                                  quiet);
+      gal_fits_key_write_filename("INUPMHDU", p->upmaskhdu, keylist, 0,
+                                  quiet);
     }
 }
 
@@ -714,7 +727,8 @@ mkcatalog_write_outputs(struct mkcatalogparams *p)
   /* Configuration information. */
   if(outisfits)
     {
-      gal_fits_key_write_filename("input", p->objectsfile, &p->cp.okeys, 1);
+      gal_fits_key_write_filename("input", p->objectsfile, &p->cp.okeys,
+                                  1, p->cp.quiet);
       gal_fits_key_write_config(&p->cp.okeys, "MakeCatalog configuration",
                                 "MKCATALOG-CONFIG", p->objectsout, "0");
     }
diff --git a/bin/mknoise/mknoise.c b/bin/mknoise/mknoise.c
index 5320d5c..415d50f 100644
--- a/bin/mknoise/mknoise.c
+++ b/bin/mknoise/mknoise.c
@@ -61,7 +61,8 @@ convertsaveoutput(struct mknoiseparams *p)
   gal_fits_list_key_t *headers=NULL;
 
   /* Add the proper information to the header of the output: */
-  gal_fits_key_write_filename("INF", p->inputname, &headers, 0);
+  gal_fits_key_write_filename("INF", p->inputname, &headers, 0,
+                              p->cp.quiet);
   if( !isnan(p->background) )
     {
       gal_checkset_allocate_copy("BCKGRND", &keyname);
@@ -118,7 +119,8 @@ convertsaveoutput(struct mknoiseparams *p)
   p->input->name=NULL; /* because we didn't allocate it. */
 
   /* Write the configuration keywords. */
-  gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1);
+  gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1,
+                              p->cp.quiet);
   gal_fits_key_write_config(&p->cp.okeys, "MakeNoise configuration",
                             "MKNOISE-CONFIG", p->cp.output, "0");
 }
diff --git a/bin/mkprof/mkprof.c b/bin/mkprof/mkprof.c
index afcfaf1..c585249 100644
--- a/bin/mkprof/mkprof.c
+++ b/bin/mkprof/mkprof.c
@@ -708,7 +708,8 @@ mkprof_write(struct mkprofparams *p)
       gal_data_free(out);
 
       /* Write the configuration keywords. */
-      gal_fits_key_write_filename("input", p->catname, &p->cp.okeys, 1);
+      gal_fits_key_write_filename("input", p->catname, &p->cp.okeys, 1,
+                                  p->cp.quiet);
       gal_fits_key_write_config(&p->cp.okeys, "MakeProfiles configuration",
                                 "MKPROF-CONFIG", p->mergedimgname, "0");
 
diff --git a/bin/noisechisel/noisechisel.c b/bin/noisechisel/noisechisel.c
index 1d347b2..a2ebc68 100644
--- a/bin/noisechisel/noisechisel.c
+++ b/bin/noisechisel/noisechisel.c
@@ -206,7 +206,8 @@ noisechisel_output(struct noisechiselparams *p)
 
 
   /* Write the configuration keywords. */
-  gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1);
+  gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1,
+                              p->cp.quiet);
   gal_fits_key_write_config(&p->cp.okeys, "NoiseChisel configuration",
                             "NOISECHISEL-CONFIG", p->cp.output, "0");
 
diff --git a/bin/segment/segment.c b/bin/segment/segment.c
index 2cbcfcd..98a7426 100644
--- a/bin/segment/segment.c
+++ b/bin/segment/segment.c
@@ -1450,7 +1450,8 @@ segment_output(struct segmentparams *p)
     }
 
   /* Write the configuration keywords. */
-  gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1);
+  gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1,
+                              p->cp.quiet);
   gal_fits_key_write_config(&p->cp.okeys, "Segment configuration",
                             "SEGMENT-CONFIG", p->cp.output, "0");
 
diff --git a/bin/statistics/sky.c b/bin/statistics/sky.c
index 951f915..a1d0d97 100644
--- a/bin/statistics/sky.c
+++ b/bin/statistics/sky.c
@@ -285,7 +285,8 @@ sky(struct statisticsparams *p)
   gal_tile_full_values_write(p->std_t, tl, !p->ignoreblankintiles, outname,
                              NULL, PROGRAM_NAME);
   p->sky_t->name = p->std_t->name = NULL;
-  gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1);
+  gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1,
+                              p->cp.quiet);
   gal_fits_key_write_config(&p->cp.okeys, "Statistics configuration",
                             "STATISTICS-CONFIG", outname, "0");
   if(!cp->quiet)
diff --git a/bin/statistics/statistics.c b/bin/statistics/statistics.c
index afacdc0..437928b 100644
--- a/bin/statistics/statistics.c
+++ b/bin/statistics/statistics.c
@@ -285,7 +285,8 @@ statistics_interpolate_and_write(struct statisticsparams *p,
   /* Write the values. */
   gal_tile_full_values_write(values, &cp->tl, !p->ignoreblankintiles,
                              output, NULL, PROGRAM_NAME);
-  gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1);
+  gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1,
+                              p->cp.quiet);
   gal_fits_key_write_config(&p->cp.okeys, "Statistics configuration",
                             "STATISTICS-CONFIG", output, "0");
 }
@@ -664,7 +665,8 @@ write_output_table(struct statisticsparams *p, gal_data_t 
*table,
   /* Write the configuration information if we have a FITS output. */
   if(isfits)
     {
-      gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1);
+      gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1,
+                                  p->cp.quiet);
       gal_fits_key_write_config(&p->cp.okeys, "Statistics configuration",
                                 "STATISTICS-CONFIG", output, "0");
     }
@@ -838,7 +840,8 @@ histogram_2d(struct statisticsparams *p)
       /* Write the output. */
       output=statistics_output_name(p, suf, &isfits);
       gal_fits_img_write(img, output, NULL, PROGRAM_STRING);
-      gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1);
+      gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1,
+                                  p->cp.quiet);
       gal_fits_key_write_config(&p->cp.okeys, "Statistics configuration",
                                 "STATISTICS-CONFIG", output, "0");
 
diff --git a/bin/warp/warp.c b/bin/warp/warp.c
index e895d63..eca744d 100644
--- a/bin/warp/warp.c
+++ b/bin/warp/warp.c
@@ -474,7 +474,8 @@ correct_wcs_save_output(struct warpparams *p)
     }
 
   /* Add the appropriate headers: */
-  gal_fits_key_write_filename("INF", p->inputname, &headers, 0);
+  gal_fits_key_write_filename("INF", p->inputname, &headers,
+                              0, p->cp.quiet);
   for(i=0;i<9;++i)
     {
       sprintf(&keyword[i*FLEN_KEYWORD], "WMTX%zu_%zu", i/3+1, i%3+1);
@@ -489,7 +490,8 @@ correct_wcs_save_output(struct warpparams *p)
   gal_fits_img_write(p->output, p->cp.output, headers, PROGRAM_NAME);
 
   /* Write the configuration keywords. */
-  gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1);
+  gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys,
+                              1, p->cp.quiet);
   gal_fits_key_write_config(&p->cp.okeys, "Warp configuration",
                             "WARP-CONFIG", p->cp.output, "0");
 }
diff --git a/doc/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index 566334e..aead2c7 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -3,6 +3,7 @@ Alphabetically ordered list to acknowledge in the next release.
 Fernando Buitrago
 Mark Calabretta
 Leslie Hunt
+Raúl Infante-Sainz
 Matthias Kluge
 Juan Miro
 Juan Molina Tobar
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 354fa72..50b4958 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -26294,19 +26294,19 @@ A title in the list of keywords helps in classifying 
the keywords into groups an
 If @code{title==NULL}, this function won't do anything.
 @end deftypefun
 
-@deftypefun void gal_fits_key_write_filename (char @code{*keynamebase}, char 
@code{*filename}, gal_fits_list_key_t @code{**list}, int @code{top1end0})
-Put @file{filename} into the @code{gal_fits_list_key_t} list (possibly
-broken up into multiple keywords) to later write into a HDU header. The
-@code{keynamebase} string will be appended with a @code{_N} (N>0) and used
-as the keyword name. If @code{top1end0!=0}, then the keywords containing
-the filename will be added to the top of the list.
-
-The FITS standard sets a maximum length for the value of a keyword. This
-creates problems with file names (which include directories). Because file
-names/addresses can become very long. Therefore, when @code{filename} is
-longer than the maximum length of a FITS keyword value, this function will
-break it into several keywords (breaking up the string on directory
-separators).
+@deftypefun void gal_fits_key_write_filename (char @code{*keynamebase}, char 
@code{*filename}, gal_fits_list_key_t @code{**list}, int @code{top1end0}, int 
@code{quiet})
+Put @file{filename} into the @code{gal_fits_list_key_t} list (possibly broken 
up into multiple keywords) to later write into a HDU header.
+The @code{keynamebase} string will be appended with a @code{_N} (N>0) and used 
as the keyword name.
+If @code{top1end0!=0}, then the keywords containing the filename will be added 
to the top of the list.
+
+The FITS standard sets a maximum length of 69 characters for the string values 
of a keyword@footnote{The limit is actually 71 characters (which is the full 80 
character length, subtracted by 8 for the keyword name and one character for 
the @key{=}).
+However, for strings, FITS also requires two single quotes.}.
+This creates problems with file names (which include directories) because file 
names/addresses can become longer than .
+Therefore, when @code{filename} is longer than the maximum length of a FITS 
keyword value, this function will break it into several keywords (breaking up 
the string on directory separators).
+So the full file/directory address (including directories) can be longer than 
69 characters.
+However, if a single file or directory name (within a larger address) is 
longer than 69 characters, this function will truncate the name and print a 
warning.
+If @code{quiet!=0}, then the warning won't be printed.
+
 @end deftypefun
 
 @deftypefun void gal_fits_key_write_wcsstr (fitsfile @code{*fptr}, struct 
wcsprm @code{wcs}, char @code{*wcsstr}, int @code{nkeyrec})
diff --git a/lib/fits.c b/lib/fits.c
index 839671a..ef55975 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -1708,7 +1708,8 @@ gal_fits_key_write_title_in_ptr(char *title, fitsfile 
*fptr)
 /* Write a filename into keyword values. */
 void
 gal_fits_key_write_filename(char *keynamebase, char *filename,
-                            gal_fits_list_key_t **list, int top1end0)
+                            gal_fits_list_key_t **list, int top1end0,
+                            int quiet)
 {
   char *keyname, *value;
   size_t numkey=1, maxlength;
@@ -1778,11 +1779,12 @@ gal_fits_key_write_filename(char *keynamebase, char 
*filename,
                  basename. */
               strcpy(keyname, keynamebase);
 
-              /* Let the user know that  */
-              error(0,0, "%s: WARNING: '%s' is too long to fit "
-                    "into a FITS keyword value (max of %zu characters), "
-                    "it will be truncated", __func__, filename,
-                    maxlength);
+              /* Let the user know that the name will be truncated. */
+              if(quiet==0)
+                error(0,0, "%s: WARNING: '%s' is too long to fit "
+                      "into a FITS keyword value (max of %zu characters), "
+                      "it will be truncated", __func__, filename,
+                      maxlength);
             }
 
           /* Convert the last useful character and save the file name.*/
diff --git a/lib/gnuastro/fits.h b/lib/gnuastro/fits.h
index 7827fac..3ca2536 100644
--- a/lib/gnuastro/fits.h
+++ b/lib/gnuastro/fits.h
@@ -238,7 +238,8 @@ gal_fits_key_write_title_in_ptr(char *title, fitsfile 
*fptr);
 
 void
 gal_fits_key_write_filename(char *keynamebase, char *filename,
-                            gal_fits_list_key_t **list, int top1end0);
+                            gal_fits_list_key_t **list, int top1end0,
+                            int quiet);
 
 void
 gal_fits_key_write_wcsstr(fitsfile *fptr, struct wcsprm *wcs,
diff --git a/lib/options.c b/lib/options.c
index 82c89ce..5cdb50a 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -2977,7 +2977,8 @@ options_as_fits_keywords_write(gal_fits_list_key_t **keys,
                qualifier. */
             gal_checkset_allocate_copy(options[i].name, &name);
             if(vtype==GAL_TYPE_STRING && strlen(vptr)>FLEN_KEYWORD)
-              gal_fits_key_write_filename(name, vptr, keys, 1);
+              gal_fits_key_write_filename(name, vptr, keys, 1,
+                                          cp->quiet);
             else
               {
                 gal_checkset_allocate_copy(options[i].doc,  &doc);



reply via email to

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