gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master f83769e: Library table writing functions don't


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master f83769e: Library table writing functions don't delete
Date: Fri, 27 Oct 2017 20:50:54 -0400 (EDT)

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

    Library table writing functions don't delete
    
    Until now the table writing functions had a `dontdelete' argument. This
    argument was in charge of letting the function know what to do with the
    output file if it already existed. But ultimately, this job (deciding what
    to do with the output file) is a choice at another level. It would thus
    make it hard to write multiple FITS tables to separate extensions.
    
    So with this commit, the choice of what to do with the output file is left
    to the caller of the function. If the output is a FITS file and it already
    exits, they will write the output as a new extension and if it is a text
    file, it will abort with an error (it is the caller's responsibility to
    check before calling this function).
    
    With this change, MakeCatalog can now write its two outputs in separate
    extensions of a single FITS file. Also in this commit, the options relating
    to output catalog columns were grouped into related contexts to make it
    easier to find them.
---
 NEWS                             |  19 ++-
 bin/convertt/convertt.c          |   4 +-
 bin/crop/crop.c                  |   3 +-
 bin/fits/fits.c                  |   2 +-
 bin/mkcatalog/args.h             | 247 +++++++++++++++++++++++----------------
 bin/mkcatalog/mkcatalog.c        |   6 +-
 bin/mkcatalog/ui.c               |  71 +++++++----
 bin/mkcatalog/ui.h               |   6 +-
 bin/mkprof/mkprof.c              |   3 +-
 bin/noisechisel/segmentation.c   |   5 +-
 bin/noisechisel/threshold.c      |   4 +-
 bin/statistics/statistics.c      |   4 +-
 bin/statistics/ui.c              |   8 +-
 bin/table/table.c                |   6 +-
 doc/gnuastro.texi                |  60 ++++++----
 lib/checkset.c                   |   4 +-
 lib/fits.c                       |  13 +--
 lib/gnuastro-internal/checkset.h |   2 +-
 lib/gnuastro/fits.h              |   2 +-
 lib/gnuastro/table.h             |   4 +-
 lib/gnuastro/txt.h               |   3 +-
 lib/table.c                      |  18 ++-
 lib/txt.c                        |  17 +--
 tests/mkcatalog/aperturephot.sh  |   2 +-
 24 files changed, 314 insertions(+), 199 deletions(-)

diff --git a/NEWS b/NEWS
index aafd6ea..c804552 100644
--- a/NEWS
+++ b/NEWS
@@ -72,6 +72,9 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
   `gal_fits_key_img_blank': returns the value that must be used in the
   BLANK keyword for the given type as defined by the FITS standard.
 
+  `gal_txt_write' and `gal_fits_tab_write' now accept an extension name as
+  argument to allow a name for the FITS extension they write.
+
 ** Removed features
 
   MakeCatalog: `--zeropoint' option doesn't have a short option name any
@@ -88,20 +91,28 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
   CosmicCalculator: The redshift is no longer mandatory. When no redshift
   is given, it will only print the input parameters (cosmology) and abort.
 
+  MakeCatalog: when the output is a FITS file, the two object and clumps
+  catalogs will no longer
+
   `gal_binary_fill_holes' now accepts a `connectivity' and `maxsize'
   argument to specify the connectivity of the holes and the maximum size of
   acceptable holes to fill.
 
-  `gal_tile_block_write_const_value' and `gal_tile_full_values_write' now
-  accept a new `withblank' option to set all pixels that are blank in the
-  tile's block to be blank in the check image.
-
   `gal_fits_img_read' and `gal_fits_img_read_to_type' now also read the WCS
   structure of the extension/HDU in a FITS file and have two extra
   arguments: `hstartwcs' and `hendwcs'. With these options it is possible
   to limit the range of header keywords to read the WCS, similar to how
   they are used in `gal_wcs_read'.
 
+  `gal_txt_write', `gal_table_write_log', `gal_fits_tab_write' and
+  `gal_txt_write' don't have the `dontdelete' argument any more. The action
+  they take if the file already exists depends on the file: for FITS, a new
+  extension will be added and for text, they will abort with an error.
+
+  `gal_tile_block_write_const_value' and `gal_tile_full_values_write' now
+  accept a new `withblank' option to set all pixels that are blank in the
+  tile's block to be blank in the check image.
+
   `gal_wcs_pixel_area_arcsec2' will return NaN (instead of aborting) when
   input is unreasonable (not two dimensions or not in units of degrees).
 
diff --git a/bin/convertt/convertt.c b/bin/convertt/convertt.c
index 88df4d0..b51b2bc 100644
--- a/bin/convertt/convertt.c
+++ b/bin/convertt/convertt.c
@@ -34,6 +34,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro/arithmetic.h>
 
 #include <gnuastro-internal/timing.h>
+#include <gnuastro-internal/checkset.h>
 
 #include "main.h"
 
@@ -183,7 +184,8 @@ save_with_gnuastro_lib(struct converttparams *p)
 
     /* Plain text: only one channel is acceptable. */
     case OUT_FORMAT_TXT:
-      gal_txt_write(p->chll, NULL, p->cp.output, p->cp.dontdelete);
+      gal_checkset_writable_remove(p->cp.output, 0, p->cp.dontdelete);
+      gal_txt_write(p->chll, NULL, p->cp.output);
       break;
 
 
diff --git a/bin/crop/crop.c b/bin/crop/crop.c
index ad91458..0137585 100644
--- a/bin/crop/crop.c
+++ b/bin/crop/crop.c
@@ -464,8 +464,9 @@ crop(struct cropparams *p)
                    p->checkcenter);
           gal_list_str_add(&comments, tmp, 0);
         }
+      gal_checkset_writable_remove(LOGFILENAME, 0, p->cp.dontdelete);
       gal_table_write_log(p->log, PROGRAM_STRING, &p->rawtime, comments,
-                          LOGFILENAME, p->cp.dontdelete, p->cp.quiet);
+                          LOGFILENAME, p->cp.quiet);
       gal_list_str_free(comments, 1);
     }
 
diff --git a/bin/fits/fits.c b/bin/fits/fits.c
index e96e45d..d3ca08e 100644
--- a/bin/fits/fits.c
+++ b/bin/fits/fits.c
@@ -232,7 +232,7 @@ fits_print_extension_info(struct fitsparams *p)
       printf(" Column 4: Size of data in HDU.\n");
       printf("-----\n");
     }
-  gal_table_write(cols, NULL, GAL_TABLE_FORMAT_TXT, NULL, 0);
+  gal_table_write(cols, NULL, GAL_TABLE_FORMAT_TXT, NULL, NULL);
   gal_list_data_free(cols);
 }
 
diff --git a/bin/mkcatalog/args.h b/bin/mkcatalog/args.h
index eb3b49b..0f85a83 100644
--- a/bin/mkcatalog/args.h
+++ b/bin/mkcatalog/args.h
@@ -296,13 +296,13 @@ struct argp_option program_options[] =
 
 
 
-    /* Output columns: IMPORTANT: Throughout MakeCatalogs, the order of
-       columns is based on this. So if you make changes/additions, please
-       update all the other places the columns are searched. */
+
+
+    /* ID related columns. */
     {
       0, 0, 0, 0,
-      "Output catalog columns",
-      UI_GROUP_COLUMNS
+      "Identifier columns",
+      UI_GROUP_COLUMNS_IDS
     },
     {  /* `ids' is not a unique column, it is a combination of several
           columns. */
@@ -311,7 +311,7 @@ struct argp_option program_options[] =
       0,
       0,
       "All IDs of objects and clumps.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_IDS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -325,7 +325,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Object label/ID.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_IDS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -339,7 +339,7 @@ struct argp_option program_options[] =
       0,
       0,
       "ID of object hosting this clump.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_IDS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -353,49 +353,7 @@ struct argp_option program_options[] =
       0,
       0,
       "ID of clump in host object.",
-      UI_GROUP_COLUMNS,
-      0,
-      GAL_TYPE_INVALID,
-      GAL_OPTIONS_RANGE_ANY,
-      GAL_OPTIONS_NOT_MANDATORY,
-      GAL_OPTIONS_NOT_SET,
-      ui_column_codes_ll
-    },
-    {
-      "numclumps",
-      UI_KEY_NUMCLUMPS,
-      0,
-      0,
-      "Number of clumps in this object.",
-      UI_GROUP_COLUMNS,
-      0,
-      GAL_TYPE_INVALID,
-      GAL_OPTIONS_RANGE_ANY,
-      GAL_OPTIONS_NOT_MANDATORY,
-      GAL_OPTIONS_NOT_SET,
-      ui_column_codes_ll
-    },
-    {
-      "area",
-      UI_KEY_AREA,
-      0,
-      0,
-      "Number of pixels in clump or object.",
-      UI_GROUP_COLUMNS,
-      0,
-      GAL_TYPE_INVALID,
-      GAL_OPTIONS_RANGE_ANY,
-      GAL_OPTIONS_NOT_MANDATORY,
-      GAL_OPTIONS_NOT_SET,
-      ui_column_codes_ll
-    },
-    {
-      "clumpsarea",
-      UI_KEY_CLUMPSAREA,
-      0,
-      0,
-      "Sum of all clump areas in an object.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_IDS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -403,19 +361,16 @@ struct argp_option program_options[] =
       GAL_OPTIONS_NOT_SET,
       ui_column_codes_ll
     },
+
+
+
+
+
+    /* Position related columns (pixel). */
     {
-      "weightarea",
-      UI_KEY_WEIGHTAREA,
-      0,
-      0,
-      "Area used for flux weighted positions.",
-      UI_GROUP_COLUMNS,
-      0,
-      GAL_TYPE_INVALID,
-      GAL_OPTIONS_RANGE_ANY,
-      GAL_OPTIONS_NOT_MANDATORY,
-      GAL_OPTIONS_NOT_SET,
-      ui_column_codes_ll
+      0, 0, 0, 0,
+      "Positional columns (pixel)",
+      UI_GROUP_COLUMNS_POSITION_PIXEL
     },
     {
       "x",
@@ -423,7 +378,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux weighted center in first FITS axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -437,7 +392,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux weighted center in second FITS axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -451,7 +406,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric center in first FITS axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -465,7 +420,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric center in second FITS axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -479,7 +434,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux.wht center of all clumps in obj. (X).",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -493,7 +448,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux.wht center of all clumps in obj. (Y).",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -507,7 +462,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric center of all clumps in obj. (X).",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -521,7 +476,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric center of all clumps in obj. (Y).",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -529,13 +484,24 @@ struct argp_option program_options[] =
       GAL_OPTIONS_NOT_SET,
       ui_column_codes_ll
     },
+
+
+
+
+
+    /* Position related columns (WCS). */
+    {
+      0, 0, 0, 0,
+      "Positional columns (WCS)",
+      UI_GROUP_COLUMNS_POSITION_WCS
+    },
     {
       "ra",
       UI_KEY_RA,
       0,
       0,
       "Flux weighted center right ascension.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_WCS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -549,7 +515,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux weighted center declination.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_WCS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -563,7 +529,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux weighted center in first WCS axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_WCS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -577,7 +543,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux weighted center in second WCS axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_WCS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -591,7 +557,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric center in first WCS axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_WCS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -605,7 +571,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric center in second WCS axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_WCS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -619,7 +585,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux.wht center of all clumps in 1st WCS.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_WCS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -633,7 +599,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux.wht center of all clumps in 2nd WCS.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_WCS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -647,7 +613,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric center of all clumps in 1st WCS.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_WCS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -661,7 +627,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric center of all clumps in 2nd WCS.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_WCS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -669,13 +635,24 @@ struct argp_option program_options[] =
       GAL_OPTIONS_NOT_SET,
       ui_column_codes_ll
     },
+
+
+
+
+
+    /* Brightness/pixel-value related columns. */
+    {
+      0, 0, 0, 0,
+      "Brightness/magnitude related columns",
+      UI_GROUP_COLUMNS_BRIGHTNESS
+    },
     {
       "brightness",
       UI_KEY_BRIGHTNESS,
       0,
       0,
       "Brightness (sum of pixel values).",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_BRIGHTNESS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -689,7 +666,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Brightness of clumps in an object.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_BRIGHTNESS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -703,7 +680,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Sky (not river) subtracted clump brightness.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_BRIGHTNESS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -717,7 +694,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Total magnitude of objects or clumps.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_BRIGHTNESS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -731,7 +708,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Magnitude error of objects or clumps.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_BRIGHTNESS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -745,7 +722,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Magnitude of all clumps in object.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_BRIGHTNESS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -759,7 +736,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Upper-limit value, use other options to config.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_BRIGHTNESS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -773,7 +750,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Upper-limit mag. use other options to config.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_BRIGHTNESS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -787,7 +764,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Average river value surrounding a clump.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_BRIGHTNESS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -801,7 +778,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Number of river pixels around a clump.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_BRIGHTNESS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -815,7 +792,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Signal to noise ratio of objects or clumps.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_BRIGHTNESS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -829,7 +806,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Average Sky value under this clump or object.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_BRIGHTNESS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -843,7 +820,73 @@ struct argp_option program_options[] =
       0,
       0,
       "Average Sky standard deviation.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_BRIGHTNESS,
+      0,
+      GAL_TYPE_INVALID,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET,
+      ui_column_codes_ll
+    },
+
+
+
+
+    /* Morphology/shapre related columns. */
+    {
+      0, 0, 0, 0,
+      "Morphology/shape related columns",
+      UI_GROUP_COLUMNS_MORPHOLOGY
+    },
+    {
+      "numclumps",
+      UI_KEY_NUMCLUMPS,
+      0,
+      0,
+      "Number of clumps in this object.",
+      UI_GROUP_COLUMNS_MORPHOLOGY,
+      0,
+      GAL_TYPE_INVALID,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET,
+      ui_column_codes_ll
+    },
+    {
+      "area",
+      UI_KEY_AREA,
+      0,
+      0,
+      "Number of pixels in clump or object.",
+      UI_GROUP_COLUMNS_MORPHOLOGY,
+      0,
+      GAL_TYPE_INVALID,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET,
+      ui_column_codes_ll
+    },
+    {
+      "clumpsarea",
+      UI_KEY_CLUMPSAREA,
+      0,
+      0,
+      "Sum of all clump areas in an object.",
+      UI_GROUP_COLUMNS_MORPHOLOGY,
+      0,
+      GAL_TYPE_INVALID,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET,
+      ui_column_codes_ll
+    },
+    {
+      "weightarea",
+      UI_KEY_WEIGHTAREA,
+      0,
+      0,
+      "Area used for flux weighted positions.",
+      UI_GROUP_COLUMNS_MORPHOLOGY,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -857,7 +900,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux weighted semi-major axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_MORPHOLOGY,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -871,7 +914,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux weighted semi-minor axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_MORPHOLOGY,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -885,7 +928,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux weighted axis ratio.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_MORPHOLOGY,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -899,7 +942,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux weighted position angle.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_MORPHOLOGY,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -913,7 +956,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric semi-major axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_MORPHOLOGY,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -927,7 +970,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric semi-minor axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_MORPHOLOGY,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -941,7 +984,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric axis ratio.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_MORPHOLOGY,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -955,7 +998,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric position angle.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_MORPHOLOGY,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
diff --git a/bin/mkcatalog/mkcatalog.c b/bin/mkcatalog/mkcatalog.c
index fb167ca..25fcce6 100644
--- a/bin/mkcatalog/mkcatalog.c
+++ b/bin/mkcatalog/mkcatalog.c
@@ -878,7 +878,7 @@ mkcatalog_write_outputs(struct mkcatalogparams *p)
      write the objects catalog and free the comments. */
   gal_list_str_reverse(&comments);
   gal_table_write(p->objectcols, comments, p->cp.tableformat, p->objectsout,
-                  p->cp.dontdelete);
+                  "OBJECTS");
   gal_list_str_free(comments, 1);
 
 
@@ -897,8 +897,8 @@ mkcatalog_write_outputs(struct mkcatalogparams *p)
          Reverse the comments list (so it is printed in the same order here),
          write the objects catalog and free the comments. */
       gal_list_str_reverse(&comments);
-      gal_table_write(p->clumpcols, comments, p->cp.tableformat,
-                      p->clumpsout, p->cp.dontdelete);
+      gal_table_write(p->clumpcols, comments, p->cp.tableformat, p->clumpsout,
+                      "CLUMPS");
       gal_list_str_free(comments, 1);
     }
 }
diff --git a/bin/mkcatalog/ui.c b/bin/mkcatalog/ui.c
index c780516..197b455 100644
--- a/bin/mkcatalog/ui.c
+++ b/bin/mkcatalog/ui.c
@@ -707,41 +707,63 @@ ui_one_tile_per_object(struct mkcatalogparams *p)
 static void
 ui_preparations_both_names(struct mkcatalogparams *p)
 {
-  char *basename;
-  char *end, *tend, suffix[50];
+  char *basename, *suffix=".fits";
   uint8_t keepinputdir=p->cp.keepinputdir;  /* See below. */
 
   /* Set the type ending. */
   if(p->cp.output)
     {
       /* When the user has specified a name, any possible directories in
-         that name must be respected. So we will keep the actual
-         `keepinputdir' value in a temporary variable, set it to 1 only for
-         this operation, then set it back to what it was. */
+         that name must be respected. So we have kept the actual
+         `keepinputdir' value in a temporary variable above and set it to 1
+         only for this operation. Later we set it back to what it was. */
       p->cp.keepinputdir=1;
 
-      /* Set the basic strings. */
+      /* Set the base name (if necessary). */
       basename = p->cp.output;
-      tend = gal_fits_name_is_fits(p->cp.output)     ? "fits" : "txt";
+
+      /* FITS speicifc preparations. */
+      if( gal_fits_name_is_fits(p->cp.output) )
+        {
+          /* The output file name that the user has given supersedes the
+             `tableformat' argument. In this case, the filename is a FITS
+             file, so if `tableformat' is a text file, we will change it to
+             a default binary FITS table. */
+          if( p->cp.tableformat==GAL_TABLE_FORMAT_TXT )
+            p->cp.tableformat=GAL_TABLE_FORMAT_BFITS;
+        }
     }
   else
     {
+      /* Note that suffix is not used in the text table outputs, so it
+         doesn't matter if the output table is not FITS. */
+      suffix="_catalog.fits";
       basename = p->inputname;
-      tend = p->cp.tableformat==GAL_TABLE_FORMAT_TXT ? "txt"  : "fits";
     }
 
-  /* Set the objects name */
-  end="_o";
-  sprintf(suffix, "%s.%s", end, tend);
-  p->objectsout=gal_checkset_automatic_output(&p->cp, basename, suffix);
 
-  /* Set the clumps name */
-  end="_c";
-  sprintf(suffix, "%s.%s", end, tend);
-  p->clumpsout=gal_checkset_automatic_output(&p->cp, basename, suffix);
+  /* Set the final filename. If the output is a text file, we need two
+     files. But when its a FITS file we want to make a multi-extension FITS
+     file. */
+  if(p->cp.tableformat==GAL_TABLE_FORMAT_TXT)
+    {
+      p->objectsout=gal_checkset_automatic_output(&p->cp, basename, "_o.txt");
+      p->clumpsout=gal_checkset_automatic_output(&p->cp, basename, "_c.txt");
+    }
+  else
+    {
+      p->objectsout=gal_checkset_automatic_output(&p->cp, basename, suffix);
+      p->clumpsout=p->objectsout;
+    }
 
-  /* Revert `keepinputdir' to what it was. */
-  if(p->cp.output) p->cp.keepinputdir=keepinputdir;
+  /* Revert `keepinputdir' to what it was and free `p->cp.output', we will
+     be using `p->objectsout' and `p->clumpsout' from now on. */
+  if(p->cp.output)
+    {
+      p->cp.keepinputdir=keepinputdir;
+      free(p->cp.output);
+      p->cp.output=NULL;
+    }
 }
 
 
@@ -770,7 +792,12 @@ ui_preparations_outnames(struct mkcatalogparams *p)
 
       /* If a clumps image has been read, then we have two outputs. */
       if(p->clumps) ui_preparations_both_names(p);
-      else          p->objectsout=p->cp.output;
+      else
+        {
+          gal_checkset_writable_remove(p->cp.output, 0, p->cp.dontdelete);
+          p->objectsout=p->cp.output;
+          p->cp.output=NULL;
+        }
     }
   else
     {
@@ -1025,6 +1052,11 @@ ui_free_report(struct mkcatalogparams *p, struct timeval 
*t1)
   /* If a random number generator was allocated, free it. */
   if(p->rng) gsl_rng_free(p->rng);
 
+  /* Free output names. */
+  if(p->clumpsout && p->clumpsout!=p->objectsout)
+    free(p->clumpsout);
+  free(p->objectsout);
+
   /* Free the allocated arrays: */
   free(p->skyhdu);
   free(p->stdhdu);
@@ -1033,7 +1065,6 @@ ui_free_report(struct mkcatalogparams *p, struct timeval 
*t1)
   free(p->ciflag);
   free(p->skyfile);
   free(p->stdfile);
-  free(p->cp.output);
   free(p->clumpshdu);
   free(p->objectshdu);
   free(p->clumpsfile);
diff --git a/bin/mkcatalog/ui.h b/bin/mkcatalog/ui.h
index cc0cdaf..51e9a52 100644
--- a/bin/mkcatalog/ui.h
+++ b/bin/mkcatalog/ui.h
@@ -34,7 +34,11 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 enum program_args_groups
 {
   UI_GROUP_UPPERLIMIT = GAL_OPTIONS_GROUP_AFTER_COMMON,
-  UI_GROUP_COLUMNS,
+  UI_GROUP_COLUMNS_IDS,
+  UI_GROUP_COLUMNS_POSITION_PIXEL,
+  UI_GROUP_COLUMNS_POSITION_WCS,
+  UI_GROUP_COLUMNS_BRIGHTNESS,
+  UI_GROUP_COLUMNS_MORPHOLOGY,
 };
 
 
diff --git a/bin/mkprof/mkprof.c b/bin/mkprof/mkprof.c
index 3a73cdc..b765486 100644
--- a/bin/mkprof/mkprof.c
+++ b/bin/mkprof/mkprof.c
@@ -703,8 +703,9 @@ mkprof(struct mkprofparams *p)
     {
       asprintf(&tmp, "Zeropoint: %g", p->zeropoint);
       gal_list_str_add(&comments, tmp, 0);
+      gal_checkset_writable_remove(LOGFILENAME, 0, p->cp.dontdelete);
       gal_table_write_log(p->log, PROGRAM_STRING, &p->rawtime, comments,
-                          LOGFILENAME, p->cp.dontdelete, p->cp.quiet);
+                          LOGFILENAME, p->cp.quiet);
       gal_list_str_free(comments, 1);
     }
 
diff --git a/bin/noisechisel/segmentation.c b/bin/noisechisel/segmentation.c
index 53be9a7..1c4bc15 100644
--- a/bin/noisechisel/segmentation.c
+++ b/bin/noisechisel/segmentation.c
@@ -35,6 +35,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro/dimension.h>
 
 #include <gnuastro-internal/timing.h>
+#include <gnuastro-internal/checkset.h>
 
 #include "main.h"
 
@@ -593,7 +594,9 @@ segmentation_save_sn_table(struct clumps_params *clprm)
   /* Set the column pointers and write them into a table.. */
   clumpinobj->next=sn;
   objind->next=clumpinobj;
-  gal_table_write(objind, comments, p->cp.tableformat, p->clumpsn_d_name, 1);
+  gal_checkset_writable_remove(p->clumpsn_d_name, 0, 1);
+  gal_table_write(objind, comments, p->cp.tableformat, p->clumpsn_d_name,
+                  "CLUMPS_SN");
 
 
   /* Clean up. */
diff --git a/bin/noisechisel/threshold.c b/bin/noisechisel/threshold.c
index 9ab5dd5..19e06d2 100644
--- a/bin/noisechisel/threshold.c
+++ b/bin/noisechisel/threshold.c
@@ -35,6 +35,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro/interpolate.h>
 
 #include <gnuastro-internal/timing.h>
+#include <gnuastro-internal/checkset.h>
 
 #include "main.h"
 
@@ -216,7 +217,8 @@ threshold_write_sn_table(struct noisechiselparams *p, 
gal_data_t *insn,
 
 
   /* write the table. */
-  gal_table_write(cols, comments, p->cp.tableformat, filename, 1);
+  gal_checkset_writable_remove(filename, 0, 1);
+  gal_table_write(cols, comments, p->cp.tableformat, filename, "SN");
 
 
   /* Clean up (if necessary). */
diff --git a/bin/statistics/statistics.c b/bin/statistics/statistics.c
index e4a2e2b..c5e05d1 100644
--- a/bin/statistics/statistics.c
+++ b/bin/statistics/statistics.c
@@ -561,8 +561,8 @@ write_output_table(struct statisticsparams *p, gal_data_t 
*table,
 
 
   /* Write the table. */
-  gal_table_write(table, comments, p->cp.tableformat, output,
-                  p->cp.dontdelete);
+  gal_checkset_writable_remove(output, 0, p->cp.dontdelete);
+  gal_table_write(table, comments, p->cp.tableformat, output, "TABLE");
 
 
   /* Let the user know, if we aren't in quiet mode. */
diff --git a/bin/statistics/ui.c b/bin/statistics/ui.c
index cc6f0b6..4626f54 100644
--- a/bin/statistics/ui.c
+++ b/bin/statistics/ui.c
@@ -812,8 +812,12 @@ ui_preparations(struct statisticsparams *p)
           if(p->inputformat==INPUT_FORMAT_IMAGE)
             gal_fits_img_write(check, tl->tilecheckname, NULL, PROGRAM_NAME);
           else
-            gal_table_write(check, NULL, cp->tableformat, tl->tilecheckname,
-                            cp->dontdelete);
+            {
+              gal_checkset_writable_remove(tl->tilecheckname, 0,
+                                           cp->dontdelete);
+              gal_table_write(check, NULL, cp->tableformat, tl->tilecheckname,
+                              "TABLE");
+            }
           gal_data_free(check);
         }
 
diff --git a/bin/table/table.c b/bin/table/table.c
index 17fbba6..7326ce3 100644
--- a/bin/table/table.c
+++ b/bin/table/table.c
@@ -32,6 +32,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro/fits.h>
 #include <gnuastro/table.h>
 
+#include <gnuastro-internal/checkset.h>
+
 #include "main.h"
 
 
@@ -44,6 +46,6 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 void
 table(struct tableparams *p)
 {
-  gal_table_write(p->table, NULL, p->cp.tableformat, p->cp.output,
-                  p->cp.dontdelete);
+  gal_checkset_writable_remove(p->cp.output, 0, p->cp.dontdelete);
+  gal_table_write(p->table, NULL, p->cp.tableformat, p->cp.output, "TABLE");
 }
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index b2a0f3e..2b277d6 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -20181,19 +20181,30 @@ the inverse of the input indexs linked list. It is 
recommended to use
 output}.
 @end deftypefun
 
address@hidden void gal_fits_tab_write (gal_data_t @code{*cols}, gal_list_str_t 
@code{*comments}, int @code{tableformat}, char @code{*filename}, int 
@code{dontdelete})
address@hidden void gal_fits_tab_write (gal_data_t @code{*cols}, gal_list_str_t 
@code{*comments}, int @code{tableformat}, char @code{*filename})
 Write the list of datasets in @code{cols} (see @ref{List of gal_data_t}) as
 separate columns in a FITS table in @code{filename}. If @code{filename}
-already exists and @code{dontdelete} is non-zero, then this function will
-abort with an error and will not write over the existing file. The format
-of the table (ASCII or binary) may be specified with the @code{tableformat}
-(see @ref{Table input output}). If @code{comments!=NULL}, each node of the
-list of strings will be written as a @code{COMMENT} keywords in the output
-FITS file (see @ref{List of strings}.
+already exists then this function will write the table as a new extension
+after all existing ones. The format of the table (ASCII or binary) may be
+specified with the @code{tableformat} (see @ref{Table input output}). If
address@hidden, each node of the list of strings will be written as
+a @code{COMMENT} keywords in the output FITS file (see @ref{List of
+strings}.
+
+This is a low-level function for tables. It is recommended to use
address@hidden for generic writing of tables in a variety of
+formats, see @ref{Table input output}.
 @end deftypefun
 
 
 
+
+
+
+
+
+
+
 @node World Coordinate System, Text files, FITS files, Gnuastro library
 @subsection World Coordinate System (@file{wcs.h})
 
@@ -20415,7 +20426,7 @@ the dataset. If the necessary space for the image is 
larger than
 see the description under the same name in @ref{Generic data container}.
 @end deftypefun
 
address@hidden void gal_txt_write (gal_data_t @code{*cols}, gal_list_str_t 
@code{*comment}, char @code{*filename}, int @code{dontdelete})
address@hidden void gal_txt_write (gal_data_t @code{*cols}, gal_list_str_t 
@code{*comment}, char @code{*filename})
 Write @code{cols} in a plain text file @code{filename}. @code{cols} may
 have one or two dimensions which determines the output:
 
@@ -20432,13 +20443,14 @@ table.
 be written.
 @end table
 
-If @code{filename} already exists and @code{dontdelete} is non-zero, then
-this function will abort with an error and will not write over the existing
-file. If @code{comments!=NULL}, a @code{#} will be put at the start of each
-node of the list of strings and will be written in the file before the
+If @code{filename} already exists this function will abort with an error
+and will not write over the existing file. Please make sure if the file
+exists or not and take the appropriate action before calling this
+function. If @code{comments!=NULL}, a @code{#} will be put at the start of
+each node of the list of strings and will be written in the file before the
 column meta-data in @code{filename} (see @ref{List of strings}).
 
-Note that this is a low-level function for tables. It is recommended to use
+This is a low-level function for tables. It is recommended to use
 @code{gal_table_write} for generic writing of tables in a variety of
 formats, see @ref{Table input output}.
 @end deftypefun
@@ -20597,18 +20609,24 @@ this line is ignored.
 @end itemize
 @end deftypefun
 
address@hidden void gal_table_write (gal_data_t @code{*cols}, gal_list_str_t 
@code{*comments}, int @code{tableformat}, char @code{*filename}, int 
@code{dontdelete})
address@hidden void gal_table_write (gal_data_t @code{*cols}, gal_list_str_t 
@code{*comments}, int @code{tableformat}, char @code{*filename}, char 
@code{*extname})
 Write the @code{cols} list of datasets into a table in @code{filename} (see
 @ref{List of gal_data_t}). The format of the table can be determined with
 @code{tableformat} that accepts the macros defined above. If
address@hidden, then the list of comments will also be printed into
-the output table. When the output table is a plain text file, each node's
-string will be printed after a @code{#} (so it can be considered as a
-comment). If @code{filename} already exists and @code{dontdelete} is not
-zero, this function will abort the program with an error.
address@hidden is not @code{NULL}, then the list of comments will also be
+printed into the output table. When the output table is a plain text file,
+each node's string will be printed after a @code{#} (so it can be
+considered as a comment) and in FITS table they will follow a
address@hidden keyword. If @file{filename} is a FITS file, the table
+extension that will be written will have the name @code{extname}.
+
+If a file named @file{filename} already exists, the operation depends on
+the type of output. When @file{filename} is a FITS file, the table will be
+added as a new extension after all existing ones. If @file{filename} is a
+plain text file, this function will abort with an error.
 @end deftypefun
 
address@hidden void gal_table_write_log (gal_data_t @code{*logll}, char 
@code{*program_string}, time_t @code{*rawtime}, gal_list_str_t 
@code{*comments}, char @code{*filename}, int @code{dontdelete}, int 
@code{quiet})
address@hidden void gal_table_write_log (gal_data_t @code{*logll}, char 
@code{*program_string}, time_t @code{*rawtime}, gal_list_str_t 
@code{*comments}, char @code{*filename}, int @code{quiet})
 Write the @code{logll} list of datasets into a table in @code{filename}
 (see @ref{List of gal_data_t}). This function is just a wrapper around
 @code{gal_table_comments_add_intro} and @code{gal_table_write} (see
@@ -22809,7 +22827,7 @@ main(void)
   /* Set names for the columns and write them out. */
   c1->name = "COUNTER";
   c2->name = "VALUE";
-  gal_table_write(c1, NULL, GAL_TABLE_FORMAT_BFITS, outname, 1);
+  gal_table_write(c1, NULL, GAL_TABLE_FORMAT_BFITS, outname);
 
   /* The names weren't allocated, so to avoid cleaning-up problems,
    * we'll set them to NULL. */
diff --git a/lib/checkset.c b/lib/checkset.c
index 4096a07..6a9da0d 100644
--- a/lib/checkset.c
+++ b/lib/checkset.c
@@ -235,7 +235,7 @@ gal_checkset_check_file(char *filename)
 /* Similar to `gal_checkset_check_file', but will report the result instead
    of doing it quietly. */
 int
-gal_checkset_check_file_report(char *filename)
+gal_checkset_check_file_return(char *filename)
 {
   FILE *tmpfile;
   errno=0;
@@ -279,7 +279,7 @@ gal_checkset_writable_remove(char *filename, int keep, int 
dontdelete)
   tmpfile=fopen(filename, "r+");
   if (tmpfile)                        /* The file opened. */
     {
-      /* Close the file and make sure that it should be deleted. */
+      /* Close the file. */
       errno=0;
       if(fclose(tmpfile))
         error(EXIT_FAILURE, errno, "%s", filename);
diff --git a/lib/fits.c b/lib/fits.c
index 33b4f9b..bd1cfed 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -2663,7 +2663,7 @@ fits_write_tnull_tcomm(fitsfile *fptr, gal_data_t *col, 
int tableformat,
    table.*/
 void
 gal_fits_tab_write(gal_data_t *cols, gal_list_str_t *comments,
-                   int tableformat, char *filename, int dontdelete)
+                   int tableformat, char *filename, char *extname)
 {
   void *blank;
   fitsfile *fptr;
@@ -2685,13 +2685,8 @@ gal_fits_tab_write(gal_data_t *cols, gal_list_str_t 
*comments,
     }
 
 
-  /* Remove the output if it already exists. */
-  gal_checkset_writable_remove(filename, 0, dontdelete);
-
-
-  /* Create the FITS file */
-  fits_create_file(&fptr, filename, &status);
-  gal_fits_io_error(status, NULL);
+  /* Open the FITS file for writing. */
+  fptr=gal_fits_open_to_write(filename);
 
 
   /* prepare necessary arrays and if integer type columns have blank
@@ -2704,7 +2699,7 @@ gal_fits_tab_write(gal_data_t *cols, gal_list_str_t 
*comments,
      `fits_table_prepare_arrays'. */
   tbltype = tableformat==GAL_TABLE_FORMAT_AFITS ? ASCII_TBL : BINARY_TBL;
   fits_create_tbl(fptr, tbltype, numrows, numcols, ttype, tform, tunit,
-                  "table", &status);
+                  extname, &status);
   gal_fits_io_error(status, NULL);
 
 
diff --git a/lib/gnuastro-internal/checkset.h b/lib/gnuastro-internal/checkset.h
index 2bf63a3..b9e6775 100644
--- a/lib/gnuastro-internal/checkset.h
+++ b/lib/gnuastro-internal/checkset.h
@@ -95,7 +95,7 @@ void
 gal_checkset_check_file(char *filename);
 
 int
-gal_checkset_check_file_report(char *filename);
+gal_checkset_check_file_return(char *filename);
 
 void
 gal_checkset_writable_remove(char *filename, int keep, int dontdelete);
diff --git a/lib/gnuastro/fits.h b/lib/gnuastro/fits.h
index 906fa63..95dcb86 100644
--- a/lib/gnuastro/fits.h
+++ b/lib/gnuastro/fits.h
@@ -262,7 +262,7 @@ gal_fits_tab_read(char *filename, char *hdu, size_t numrows,
 
 void
 gal_fits_tab_write(gal_data_t *cols, gal_list_str_t *comments,
-                   int tableformat, char *filename, int dontdelete);
+                   int tableformat, char *filename, char *extname);
 
 
 
diff --git a/lib/gnuastro/table.h b/lib/gnuastro/table.h
index ff93d9d..c080d4f 100644
--- a/lib/gnuastro/table.h
+++ b/lib/gnuastro/table.h
@@ -151,12 +151,12 @@ gal_table_comments_add_intro(gal_list_str_t **comments,
 
 void
 gal_table_write(gal_data_t *cols, gal_list_str_t *comments,
-                int tableformat, char *filename, int dontdelete);
+                int tableformat, char *filename, char *extname);
 
 void
 gal_table_write_log(gal_data_t *logll, char *program_string,
                     time_t *rawtime, gal_list_str_t *comments,
-                    char *filename, int dontdelete, int quiet);
+                    char *filename, int quiet);
 
 
 
diff --git a/lib/gnuastro/txt.h b/lib/gnuastro/txt.h
index b8373dd..56816e5 100644
--- a/lib/gnuastro/txt.h
+++ b/lib/gnuastro/txt.h
@@ -89,8 +89,7 @@ gal_data_t *
 gal_txt_image_read(char *filename, size_t minmapsize);
 
 void
-gal_txt_write(gal_data_t *input, gal_list_str_t *comment, char *filename,
-              int dontdelete);
+gal_txt_write(gal_data_t *input, gal_list_str_t *comment, char *filename);
 
 
 
diff --git a/lib/table.c b/lib/table.c
index 61ace3d..332d6d5 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -507,11 +507,10 @@ gal_table_comments_add_intro(gal_list_str_t **comments, 
char *program_string,
 
 /* The input is a linked list of data structures and some comments. The
    table will then be written into `filename' with a format that is
-   specified by `tableformat'. If it already exists, and `dontdelete' has a
-   value of 1, then it won't be deleted and an error will be printed. */
+   specified by `tableformat'. */
 void
 gal_table_write(gal_data_t *cols, gal_list_str_t *comments,
-                int tableformat, char *filename, int dontdelete)
+                int tableformat, char *filename, char *extname)
 {
   /* If a filename was given, then the tableformat is relevant and must be
      used. When the filename is empty, a text table must be printed on the
@@ -519,13 +518,13 @@ gal_table_write(gal_data_t *cols, gal_list_str_t 
*comments,
   if(filename)
     {
       if(gal_fits_name_is_fits(filename))
-        gal_fits_tab_write(cols, comments, tableformat, filename,
-                           dontdelete);
+        gal_fits_tab_write(cols, comments, tableformat, filename, extname);
       else
-        gal_txt_write(cols, comments, filename, dontdelete);
+        gal_txt_write(cols, comments, filename);
     }
   else
-    gal_txt_write(cols, comments, filename, dontdelete);
+    /* Write to standard output. */
+    gal_txt_write(cols, comments, filename);
 }
 
 
@@ -535,7 +534,7 @@ gal_table_write(gal_data_t *cols, gal_list_str_t *comments,
 void
 gal_table_write_log(gal_data_t *logll, char *program_string,
                     time_t *rawtime, gal_list_str_t *comments,
-                    char *filename, int dontdelete, int quiet)
+                    char *filename, int quiet)
 {
   char *msg;
 
@@ -543,8 +542,7 @@ gal_table_write_log(gal_data_t *logll, char *program_string,
   gal_table_comments_add_intro(&comments, program_string, rawtime);
 
   /* Write the log file to disk */
-  gal_table_write(logll, comments, GAL_TABLE_FORMAT_TXT, filename,
-                  dontdelete);
+  gal_table_write(logll, comments, GAL_TABLE_FORMAT_TXT, filename, "LOG");
 
   /* In verbose mode, print the information. */
   if(!quiet)
diff --git a/lib/txt.c b/lib/txt.c
index 5e0ecf0..5fb6eab 100644
--- a/lib/txt.c
+++ b/lib/txt.c
@@ -1143,8 +1143,7 @@ txt_print_value(FILE *fp, void *array, int type, size_t 
ind, char *fmt)
 
 static FILE *
 txt_open_file_write_info(gal_data_t *datall, char **fmts,
-                         gal_list_str_t *comment, char *filename,
-                         int dontdelete)
+                         gal_list_str_t *comment, char *filename)
 {
   FILE *fp;
   gal_data_t *data;
@@ -1153,9 +1152,13 @@ txt_open_file_write_info(gal_data_t *datall, char **fmts,
   gal_list_str_t *strt;
   int nlen, nw=0, uw=0, tw=0, bw=0;
 
+  /* Make sure the file doesn't already eixist. */
+  if( gal_checkset_check_file_return(filename) )
+    error(EXIT_FAILURE, 0, "%s: %s already exists. For safety, this "
+          "function will not over-write an existing file. Please delete "
+          "it before calling this function", __func__, filename);
 
-  /* Check the file and open it. */
-  gal_checkset_writable_remove(filename, 0, dontdelete);
+  /* Open the output file. */
   errno=0;
   fp=fopen(filename, "w");
   if(fp==NULL)
@@ -1235,8 +1238,7 @@ txt_open_file_write_info(gal_data_t *datall, char **fmts,
 
 
 void
-gal_txt_write(gal_data_t *input, gal_list_str_t *comment, char *filename,
-              int dontdelete)
+gal_txt_write(gal_data_t *input, gal_list_str_t *comment, char *filename)
 {
   FILE *fp;
   char **fmts;
@@ -1285,8 +1287,7 @@ gal_txt_write(gal_data_t *input, gal_list_str_t *comment, 
char *filename,
   /* Set the output FILE pointer: if it isn't NULL, its an actual file,
      otherwise, its the standard output. */
   fp = ( filename
-         ? txt_open_file_write_info(input, fmts, comment, filename,
-                                    dontdelete)
+         ? txt_open_file_write_info(input, fmts, comment, filename)
          : stdout );
 
 
diff --git a/tests/mkcatalog/aperturephot.sh b/tests/mkcatalog/aperturephot.sh
index 130be3f..39c8bd7 100755
--- a/tests/mkcatalog/aperturephot.sh
+++ b/tests/mkcatalog/aperturephot.sh
@@ -52,5 +52,5 @@ if [ ! -f $objimg   ]; then echo "$objimg does not exist";  
exit 77; fi
 # Actual test script
 # ==================
 $execname $img --objectsfile=$objimg --objectshdu=1 \
-          --output=aperturephot.txt                 \
+          --output=aperturephot.fits                \
           --objid --x --y --ra --dec --magnitude --sn



reply via email to

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