gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master e92fd9c 039/113: Merged recent work in master,


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master e92fd9c 039/113: Merged recent work in master, conflicts fixed
Date: Fri, 16 Apr 2021 10:33:40 -0400 (EDT)

branch: master
commit e92fd9c0206b92408b05277d89ce6a337f5c9649
Merge: 4fedb9d 7a1dc26
Author: Mohammad Akhlaghi <akhlaghi@gnu.org>
Commit: Mohammad Akhlaghi <akhlaghi@gnu.org>

    Merged recent work in master, conflicts fixed
    
    The conflics were the number of dimensions in `min' and `max' in
    MakeCatalog's upper limit calculation and the code of the third dimension
    columns in its `args.h'.
---
 NEWS                             |  31 ++++-
 bin/buildprog/args.h             |  16 +++
 bin/buildprog/buildprog.c        |  12 +-
 bin/buildprog/main.h             |   1 +
 bin/buildprog/ui.c               |   1 +
 bin/buildprog/ui.h               |  17 +--
 bin/convertt/convertt.c          |   4 +-
 bin/cosmiccal/args.h             |   2 +-
 bin/crop/crop.c                  |   3 +-
 bin/fits/fits.c                  |   2 +-
 bin/mkcatalog/args.h             | 277 +++++++++++++++++++++++----------------
 bin/mkcatalog/main.h             |   3 +
 bin/mkcatalog/mkcatalog.c        |   6 +-
 bin/mkcatalog/ui.c               |  87 +++++++++---
 bin/mkcatalog/ui.h               |   7 +-
 bin/mkcatalog/upperlimit.c       | 132 +++++++++++++++++--
 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/announce-acknowledge.txt     |   1 +
 doc/gnuastro.texi                |  88 +++++++++----
 doc/release-checklist.txt        |   4 +-
 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/options.c                    |   2 +-
 lib/table.c                      |  18 ++-
 lib/txt.c                        |  17 +--
 tests/mkcatalog/aperturephot.sh  |   2 +-
 35 files changed, 559 insertions(+), 232 deletions(-)

diff --git a/NEWS b/NEWS
index eb0a522..9dc225b 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,9 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
   BuildProgram: The new `--la' option allows the identification of a
   different Libtool `.la' file for Libtool linking information.
 
+  BuildProgram: The new `--deletecompiled' option will delete the compiled
+  program after running it.
+
   CosmicCalculator: all the various cosmological calculations can now be
   requested individually in one line with a specific option added for each
   calculation (for example `--age' or `--luminositydist' for the age of the
@@ -42,6 +45,11 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
   `--geora', `--geodec', `--clumpsra', `--clumpsdec', `--clumpsgeora',
   `--clumpsgeodec'. No alias is currently defined for the latter group.
 
+  MakeCatalog: The new `--uprange' option allows you to specify a range for
+  the random values around each object. This is useful when the noise
+  properies of the dataset vary gradually and sampling from the whole
+  dataset might produce biased results.
+
   NoiseChisel: with the new `--widekernel' option it is now possible to use
   a wider kernel to identify which tiles contain signal. The rest of the
   steps (identifying the quantile threshold on the selected tiles and etc)
@@ -69,6 +77,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
@@ -85,20 +96,30 @@ 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 be stored as multiple extensions of a single file. Until
+  now, two separate FITS files would be created. Plain text outputs are the
+  same as before (two files will be created).
+
   `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).
 
@@ -124,6 +145,8 @@ GNU Astronomy Utilities NEWS                          -*- 
outline -*-
 
 
 
+
+
 * Noteworthy changes in release 0.4 (library 2.0.0) (2017-09-13) [stable]
 
 ** New features
diff --git a/bin/buildprog/args.h b/bin/buildprog/args.h
index 01a96fc..a64911d 100644
--- a/bin/buildprog/args.h
+++ b/bin/buildprog/args.h
@@ -88,6 +88,9 @@ struct argp_option program_options[] =
     },
 
 
+
+
+
     {
       "debug",
       UI_KEY_DEBUG,
@@ -140,6 +143,19 @@ struct argp_option program_options[] =
       GAL_OPTIONS_NOT_MANDATORY,
       GAL_OPTIONS_NOT_SET
     },
+    {
+      "deletecompiled",
+      UI_KEY_DETELECOMPILED,
+      0,
+      0,
+      "Delete compiled program after running.",
+      GAL_OPTIONS_GROUP_OUTPUT,
+      &p->deletecompiled,
+      GAL_OPTIONS_NO_ARG_TYPE,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
 
     {0}
   };
diff --git a/bin/buildprog/buildprog.c b/bin/buildprog/buildprog.c
index 24fbce1..f35236d 100644
--- a/bin/buildprog/buildprog.c
+++ b/bin/buildprog/buildprog.c
@@ -119,7 +119,7 @@ buildprog(struct buildprogparams *p)
       /* Free the initial command. */
       free(command);
 
-      /* Right the command to run the program. Note that if the output
+      /* Wright the command to run the program. Note that if the output
          value doesn't start with a directory, we'll have to put one for
          it. */
       switch(p->cp.output[0])
@@ -136,11 +136,19 @@ buildprog(struct buildprogparams *p)
       /* Print the executed command if necessary, then run it. */
       if(!p->cp.quiet)
         {
-          printf("Run the compiled program\n");
+          printf("\nRun the compiled program\n");
           printf("------------------------\n");
           printf("%s\n", command);
         }
       retval=system(command);
+
+      /* Delete the compiled program after running it. */
+      if(p->deletecompiled)
+        {
+          errno=0;
+          if( remove(p->cp.output) == -1 )
+            error(EXIT_FAILURE, 0, "unable to delete %s", p->cp.output);
+        }
     }
 
   /* Clean up and return. */
diff --git a/bin/buildprog/main.h b/bin/buildprog/main.h
index 2e3902c..b519f30 100644
--- a/bin/buildprog/main.h
+++ b/bin/buildprog/main.h
@@ -54,6 +54,7 @@ struct buildprogparams
   char                 *debug;    /* Keep debugging information.        */
   char               *warning;    /* Compiler warnings.                 */
   uint8_t           onlybuild;    /* Don't run the compiled program.    */
+  uint8_t      deletecompiled;    /* Delete compiled program after running. */
 
   /* Output: */
   time_t              rawtime;  /* Starting time of the program.        */
diff --git a/bin/buildprog/ui.c b/bin/buildprog/ui.c
index 28c172b..6a4cc8c 100644
--- a/bin/buildprog/ui.c
+++ b/bin/buildprog/ui.c
@@ -122,6 +122,7 @@ ui_initialize_options(struct buildprogparams *p,
         case GAL_OPTIONS_KEY_HDU:
         case GAL_OPTIONS_KEY_TYPE:
         case GAL_OPTIONS_KEY_SEARCHIN:
+        case GAL_OPTIONS_KEY_NUMTHREADS:
         case GAL_OPTIONS_KEY_MINMAPSIZE:
         case GAL_OPTIONS_KEY_TABLEFORMAT:
           cp->coptions[i].flags=OPTION_HIDDEN;
diff --git a/bin/buildprog/ui.h b/bin/buildprog/ui.h
index 712147b..f937df5 100644
--- a/bin/buildprog/ui.h
+++ b/bin/buildprog/ui.h
@@ -38,17 +38,18 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 enum option_keys_enum
 {
   /* With short-option version. */
-  UI_KEY_INCLUDE     = 'I',
-  UI_KEY_LINKDIR     = 'L',
-  UI_KEY_LINKLIB     = 'l',
-  UI_KEY_LA          = 'a',
-  UI_KEY_ONLYBUILD   = 'b',
-  UI_KEY_DEBUG       = 'g',
-  UI_KEY_OPTIMIZE    = 'O',
-  UI_KEY_WARNING     = 'W',
+  UI_KEY_INCLUDE        = 'I',
+  UI_KEY_LINKDIR        = 'L',
+  UI_KEY_LINKLIB        = 'l',
+  UI_KEY_LA             = 'a',
+  UI_KEY_ONLYBUILD      = 'b',
+  UI_KEY_DEBUG          = 'g',
+  UI_KEY_OPTIMIZE       = 'O',
+  UI_KEY_WARNING        = 'W',
 
   /* Only with long version (start with a value 1000, the rest will be set
      automatically). */
+  UI_KEY_DETELECOMPILED = 1000,
 };
 
 
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/cosmiccal/args.h b/bin/cosmiccal/args.h
index 46d4bfd..8def9bc 100644
--- a/bin/cosmiccal/args.h
+++ b/bin/cosmiccal/args.h
@@ -102,7 +102,7 @@ struct argp_option program_options[] =
 
     {
       0, 0, 0, 0,
-      "Single row calculations",
+      "Specific calculations",
       UI_GROUP_SPECIFIC
     },
     {
diff --git a/bin/crop/crop.c b/bin/crop/crop.c
index 2a9b423..16c2bfc 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 71f5562..6dd7501 100644
--- a/bin/mkcatalog/args.h
+++ b/bin/mkcatalog/args.h
@@ -254,6 +254,20 @@ struct argp_option program_options[] =
       GAL_OPTIONS_NOT_SET
     },
     {
+      "uprange",
+      UI_KEY_UPRANGE,
+      "INT,INT",
+      0,
+      "Range of random positions (pix) around target.",
+      UI_GROUP_UPPERLIMIT,
+      &p->uprange,
+      GAL_TYPE_SIZE_T,
+      GAL_OPTIONS_RANGE_GT_0,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET,
+      gal_options_parse_sizes_reverse
+    },
+    {
       "envseed",
       UI_KEY_ENVSEED,
       0,
@@ -296,13 +310,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 +325,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 +339,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 +353,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 +367,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 +375,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 +392,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 +406,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 +420,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux weighted center in third FITS axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -465,7 +434,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,
@@ -479,7 +448,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,
@@ -493,7 +462,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric center in third FITS axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -507,7 +476,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,
@@ -521,7 +490,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,
@@ -535,7 +504,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux.wht center of all clumps in obj. (Z).",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -549,7 +518,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,
@@ -563,7 +532,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,
@@ -577,7 +546,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric center of all clumps in obj. (Z).",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_PIXEL,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -585,13 +554,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,
@@ -605,7 +585,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,
@@ -619,7 +599,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,
@@ -633,7 +613,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,
@@ -647,7 +627,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux weighted center in third WCS axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_WCS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -661,7 +641,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,
@@ -675,7 +655,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,
@@ -689,7 +669,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric center in third WCS axis.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_WCS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -703,7 +683,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,
@@ -717,7 +697,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,
@@ -731,7 +711,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Flux.wht center of all clumps in 3rd WCS.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_WCS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -745,7 +725,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,
@@ -759,7 +739,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,
@@ -773,7 +753,7 @@ struct argp_option program_options[] =
       0,
       0,
       "Geometric center of all clumps in 3rd WCS.",
-      UI_GROUP_COLUMNS,
+      UI_GROUP_COLUMNS_POSITION_WCS,
       0,
       GAL_TYPE_INVALID,
       GAL_OPTIONS_RANGE_ANY,
@@ -781,13 +761,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,
@@ -801,7 +792,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,
@@ -815,7 +806,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,
@@ -829,7 +820,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,
@@ -843,7 +834,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,
@@ -857,7 +848,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,
@@ -871,7 +862,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,
@@ -885,7 +876,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,
@@ -899,7 +890,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,
@@ -913,7 +904,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,
@@ -927,7 +918,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,
@@ -941,7 +932,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,
@@ -955,7 +946,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/shape 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,
@@ -969,7 +1026,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,
@@ -983,7 +1040,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,
@@ -997,7 +1054,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,
@@ -1011,7 +1068,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,
@@ -1025,7 +1082,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,
@@ -1039,7 +1096,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,
@@ -1053,7 +1110,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,
@@ -1067,7 +1124,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/main.h b/bin/mkcatalog/main.h
index 73db98f..9f5804b 100644
--- a/bin/mkcatalog/main.h
+++ b/bin/mkcatalog/main.h
@@ -163,6 +163,7 @@ struct mkcatalogparams
   char            *upmaskfile;  /* Name of upper limit mask file.       */
   char             *upmaskhdu;  /* HDU of upper limit mask file.        */
   size_t                upnum;  /* Number of upper-limit random samples.*/
+  size_t             *uprange;  /* Range of random positions about target. */
   uint8_t             envseed;  /* Use the environment for random seed. */
   double       upsigmaclip[2];  /* Sigma clip to measure upper limit.   */
   float              upnsigma;  /* Multiple of sigma to define up-lim.  */
@@ -194,6 +195,8 @@ struct mkcatalogparams
   gsl_rng                *rng;  /* Main random number generator.        */
   uint64_t               seed;  /* Random number generator seed.        */
   const char         *rngname;  /* Name of random number generator.     */
+  size_t               rngmin;  /* Minimum possible value of RNG.       */
+  size_t              rngdiff;  /* Difference of RNG max and min.       */
 
   gal_data_t          *wcs_vo;  /* Object RA-Dec flux weighted X, Y.    */
   gal_data_t          *wcs_vc;  /* Clump RA-Dec flux weighted X, Y.     */
diff --git a/bin/mkcatalog/mkcatalog.c b/bin/mkcatalog/mkcatalog.c
index 8ce056d..0159e79 100644
--- a/bin/mkcatalog/mkcatalog.c
+++ b/bin/mkcatalog/mkcatalog.c
@@ -896,7 +896,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);
 
 
@@ -915,8 +915,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 9a60d88..597420f 100644
--- a/bin/mkcatalog/ui.c
+++ b/bin/mkcatalog/ui.c
@@ -709,41 +709,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;
+    }
 }
 
 
@@ -772,7 +794,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
     {
@@ -798,6 +825,18 @@ ui_preparations_outnames(struct mkcatalogparams *p)
 static void
 ui_preparations_upperlimit(struct mkcatalogparams *p)
 {
+  size_t i, c=0;
+
+  /* Check if the given range has the same number of elements as dimensions
+     in the input. */
+  if(p->uprange)
+    {
+      for(i=0;p->uprange[i]!=-1;++i) ++c;
+      if(c!=p->input->ndim)
+        error(EXIT_FAILURE, 0, "%zu values given to `--uprange', but input "
+              "has %zu dimensions", c, p->input->ndim);
+    }
+
   /* Check the number of random samples. */
   if( p->upnum < MKCATALOG_UPPERLIMIT_MINIMUM_NUM )
     error(EXIT_FAILURE, 0, "%zu not acceptable as `--upnum'. The minimum "
@@ -826,6 +865,10 @@ ui_preparations_upperlimit(struct mkcatalogparams *p)
               : gal_timing_time_based_rng_seed() );
   if(p->envseed) gsl_rng_set(p->rng, p->seed);
   p->rngname=gsl_rng_name(p->rng);
+
+  /* Keep the minimum and maximum values of the random number generator. */
+  p->rngmin=gsl_rng_min(p->rng);
+  p->rngdiff=gsl_rng_max(p->rng)-p->rngmin;
 }
 
 
@@ -1027,6 +1070,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);
@@ -1035,7 +1083,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 7ffc5f0..fe5d2b3 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,
 };
 
 
@@ -88,6 +92,7 @@ enum option_keys_enum
   UI_KEY_UPMASKFILE,
   UI_KEY_UPMASKHDU,
   UI_KEY_UPNUM,
+  UI_KEY_UPRANGE,
   UI_KEY_UPSIGMACLIP,
   UI_KEY_UPNSIGMA,
 
diff --git a/bin/mkcatalog/upperlimit.c b/bin/mkcatalog/upperlimit.c
index 1e932a6..12be8d5 100644
--- a/bin/mkcatalog/upperlimit.c
+++ b/bin/mkcatalog/upperlimit.c
@@ -145,6 +145,122 @@ upperlimit_make_clump_tiles(struct mkcatalog_passparams 
*pp)
 /*********************************************************************/
 /*******************         For one tile         ********************/
 /*********************************************************************/
+static void
+upperlimit_random_range(struct mkcatalog_passparams *pp, gal_data_t *tile,
+                        size_t *min, size_t *max, int32_t clumplab)
+{
+  struct mkcatalogparams *p=pp->p;
+  size_t d, tstart, minext, maxext, coord[]={0,0};
+  size_t ndim=p->input->ndim, *dsize=p->input->dsize;
+
+  /* Set the minimum and maximum acceptable value for the range.  */
+  if(p->uprange)
+    {
+      tstart=gal_data_ptr_dist(tile->block->array, tile->array,
+                               p->input->type);
+      gal_dimension_index_to_coord(tstart, ndim, dsize, coord);
+    }
+
+  /* Go over the dimensions and set the range along each dimension. */
+  for(d=0;d<ndim;++d)
+    {
+      /* If uprange is given and it is not zero, then use it, otherwise,
+         just use the full possible range. */
+      if( p->uprange && p->uprange[d] )
+        {
+          /* Set the minimum of the random range. Since `size_t' is always
+             positive, to make sure the difference isn't negative, we need
+             to convert them to integer first. */
+          if( (int)coord[d] - ((int)p->uprange[d])/2 > 0 )
+            {
+              min[d] = coord[d]-p->uprange[d]/2;
+              maxext = 0;
+            }
+          else
+            {
+              min[d] = 0;
+              maxext = -1 * ((int)coord[d] - ((int)p->uprange[d])/2);
+            }
+
+          /* Set the maximum of the random range. */
+          if( coord[d] + p->uprange[d]/2 < dsize[d] - tile->dsize[d] )
+            {
+              max[d] = coord[d] + p->uprange[d]/2;
+              minext = 0;
+            }
+          else
+            {
+              max[d] = dsize[d] - tile->dsize[d] - 1;
+              minext = ( (coord[d] + p->uprange[d]/2)
+                         - (dsize[d] - tile->dsize[d]) );
+            }
+
+          /* `minadd' and `maxadd' were defined to account for the removed
+             smaller range when an object is on the edge. Their role is to
+             add to the other side of the range as much as possible when
+             one side is decreased on an edge. */
+          if(minext)
+            min[d] = ((int)(min[d]) - (int)minext >= 0) ? (min[d]-minext) : 0;
+          if(maxext)
+            max[d] = ( (max[d] + maxext < dsize[d] - tile->dsize[d])
+                       ? (max[d] + maxext) : (dsize[d]-tile->dsize[d]-1) );
+        }
+      else
+        {
+          min[d]=0;
+          max[d]=dsize[d]-tile->dsize[d]-1;
+        }
+
+      /* A small sanity check. */
+      if( max[d]-min[d] < 2*tile->dsize[d] )
+        {
+          if(clumplab)
+            fprintf(stderr, "WARNING: object %d clump %d: range of random "
+                    "positions (%zu) along dimension %zu for upper-limit "
+                    "calculations is smaller than double of its size (%zu) "
+                    "in this dimension.\n\n", pp->object, clumplab,
+                    max[d]-min[d], ndim-d, 2*tile->dsize[d]);
+          else
+            fprintf(stderr, "WARNING: object %d: range of random "
+                    "positions (%zu) along dimension %zu for upper-limit "
+                    "calculations is smaller than double of its size (%zu) "
+                    "in this dimension.\n\n", pp->object, max[d]-min[d],
+                    ndim-d, 2*tile->dsize[d]);
+        }
+    }
+}
+
+
+
+
+
+/* Return a random position in the requested dimension. */
+static size_t
+upperlimit_random_position(struct mkcatalog_passparams *pp, gal_data_t *tile,
+                           size_t dim, size_t *min, size_t *max)
+{
+  size_t r;
+  struct mkcatalogparams *p=pp->p;
+
+  /* `gsl_rng_get' returns an inclusive value between the minimum and
+     maximum of the particular generator. It may happen that the labeled
+     region extends the full range of a dimension. In that case, the only
+     possible starting point would be 0. */
+  if( (int)(p->input->dsize[dim]) - (int)(tile->dsize[dim]) > 0 )
+    {
+      r=gsl_rng_get(pp->rng); /* For easy reading. */
+      return lrint( (float)(min[dim])
+                    + ( (float)(r-p->rngmin)/(float)(p->rngdiff)
+                        * (float)(max[dim] - min[dim]) ) );
+    }
+  else
+    return 0;
+}
+
+
+
+
+
 static double
 upperlimit_one_tile(struct mkcatalog_passparams *pp, gal_data_t *tile,
                     unsigned long seed, int32_t clumplab)
@@ -158,9 +274,9 @@ upperlimit_one_tile(struct mkcatalog_passparams *pp, 
gal_data_t *tile,
   gal_data_t *sigclip;
   uint8_t *M=NULL, *st_m=NULL;
   float *uparr=pp->up_vals->array;
-  size_t increment, num_increment;
   float *I, *II, *SK, *st_i, *st_sky;
   size_t d, tcounter=0, counter=0, se_inc[2];
+  size_t min[3], max[3], increment, num_increment;
   int32_t *O, *oO, *st_o, *st_oo, *st_oc, *oC=NULL;
   size_t maxcount = p->upnum * MKCATALOG_UPPERLIMIT_STOP_MULTIP;
   size_t *rcoord=gal_data_malloc_array(GAL_TYPE_SIZE_T, ndim, __func__,
@@ -171,6 +287,10 @@ upperlimit_one_tile(struct mkcatalog_passparams *pp, 
gal_data_t *tile,
   gsl_rng_set(pp->rng, seed);
 
 
+  /* Set the range of random values for this tile. */
+  upperlimit_random_range(pp, tile, min, max, clumplab);
+
+
   /* `se_inc' is just used temporarily, the important thing here is
      `st_oo'. */
   st_oo = ( clumplab
@@ -182,15 +302,9 @@ upperlimit_one_tile(struct mkcatalog_passparams *pp, 
gal_data_t *tile,
   /* Continue measuring randomly until we get the desired total number. */
   while(tcounter<maxcount && counter<p->upnum)
     {
-      /* Get the random coordinates, note that `gsl_rng_uniform_int'
-         returns an inclusive value. It may happen that the labeled region
-         extends the full range of a dimension. In that case, the only
-         possible want the random starting point would be 0. */
+      /* Get the random coordinates. */
       for(d=0;d<ndim;++d)
-        rcoord[d] = ( (dsize[d]-tile->dsize[d])
-                      ? gsl_rng_uniform_int(pp->rng,
-                                            dsize[d]-tile->dsize[d]-1)
-                      : 0 );
+        rcoord[d] = upperlimit_random_position(pp, tile, d, min, max);
 
       /* Set the tile's new starting pointer. */
       tile->array = gal_data_ptr_increment(p->input->array,
diff --git a/bin/mkprof/mkprof.c b/bin/mkprof/mkprof.c
index bbe6768..f86932e 100644
--- a/bin/mkprof/mkprof.c
+++ b/bin/mkprof/mkprof.c
@@ -723,8 +723,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 a0da6bf..c3d3729 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/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index 4e2bfea..ac2b000 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -2,5 +2,6 @@ This file is meant to keep the names of the people who's help 
must be
 acknowledged in the next release.
 
 Leindert Boogaard
+Aurélien Jarno
 Takashi Ichikawa
 David Valls-Gabaud
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index bb44736..4a1c658 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -14192,6 +14192,11 @@ given to @option{--upnum}. If @option{--upnum} good 
samples cannot be found
 until this limit, it will set the upper-limit magnitude for that object to
 NaN (blank).
 
+MakeCatalog will also print a warning if the range of positions available
+for the labeled region is smaller than double the size of the region. In
+such cases, the limited range of random positions can artificially decrease
+the standard deviation of the final distribution.
+
 @table @option
 
 @item --upmaskfile=STR
@@ -14208,8 +14213,8 @@ ignored in the upper-limit magnitude measurements.
 For example, when you are using labels from another image, you can give
 NoiseChisel's objects image output for this image as the value to this
 option. In this way, you can be sure that regions with data do not harm
-your distribution. See @ref{Quantifying measurement limits} for more on the 
upper
-limit magnitude.
+your distribution. See @ref{Quantifying measurement limits} for more on the
+upper limit magnitude.
 
 @item --upmaskhdu=STR
 The extension in the file specified by @option{--upmask}.
@@ -14224,6 +14229,18 @@ can be sure that for each object, this many samples 
over undetected objects
 are made. See the upper limit magnitude discussion in @ref{Quantifying
 measurement limits} for more.
 
+@item --uprange=INT,INT
+The range/width of the region (in pixels) to do random sampling along each
+dimension of the input image around each object's position. This is not a
+mandatory option and if not given (or given a value of zero in a
+dimension), the full possible range of the dataset along that dimension
+will be used. This is useful when the noise properties of the dataset vary
+gradually. In such cases, using the full range of the input dataset is
+going to bias the result. However, note that decreasing the the range of
+available positions too much will also artificially decrease the standard
+deviation of the final distribution (and thus bias the upper-limit
+measurement).
+
 @item --envseed
 Read the random number generator type and seed value from the environment
 (see @ref{Generating random numbers}). Random numbers are used in
@@ -17682,6 +17699,13 @@ confronts).
 Only build the program, don't run it. By default, the built program is
 immediately run afterwards.
 
+@item --deletecompiled
+Delete the compiled binary file after running it. This option is only
+relevant when the compiled program is run after being built. In other
+words, it is only relevant when @option{--onlybuild} is not called. It can
+be useful when you are busy testing a program or just want a fast result
+and the actual binary/compiled file is not of later use.
+
 @item -a STR
 @itemx --la=STR
 Use the given @file{.la} file (Libtool control file) instead of the one
@@ -20473,19 +20497,30 @@ the inverse of the input indexs linked list. It is 
recommended to use
 output}.
 @end deftypefun
 
-@deftypefun 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})
+@deftypefun 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
+@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}.
+
+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
 
 
 
+
+
+
+
+
+
+
 @node World Coordinate System, Text files, FITS files, Gnuastro library
 @subsection World Coordinate System (@file{wcs.h})
 
@@ -20707,7 +20742,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
 
-@deftypefun void gal_txt_write (gal_data_t @code{*cols}, gal_list_str_t 
@code{*comment}, char @code{*filename}, int @code{dontdelete})
+@deftypefun 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:
 
@@ -20724,13 +20759,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
@@ -20889,18 +20925,24 @@ this line is ignored.
 @end itemize
 @end deftypefun
 
-@deftypefun void gal_table_write (gal_data_t @code{*cols}, gal_list_str_t 
@code{*comments}, int @code{tableformat}, char @code{*filename}, int 
@code{dontdelete})
+@deftypefun 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
-@code{comments!=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). If @code{filename} already exists and @code{dontdelete} is not
-zero, this function will abort the program with an error.
+@code{comments} 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
+@code{COMMENT} 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
 
-@deftypefun 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})
+@deftypefun 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
@@ -23123,7 +23165,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/doc/release-checklist.txt b/doc/release-checklist.txt
index 483e22c..0bc3241 100644
--- a/doc/release-checklist.txt
+++ b/doc/release-checklist.txt
@@ -253,10 +253,10 @@ Steps necessary to Package Gnuastro for Debian.
 
  - If the soname of the shared libraries has changed:
 
-     - Rename the file `debain/libgnuastroX.install' (set `X' to the new
+     - Rename the file `debian/libgnuastroX.install' (set `X' to the new
        soname).
 
-     - In `debian control, change all the old sonames to the new value.
+     - In `debian/control', change all the old sonames to the new value.
 
 
  - Update your version of `pbuilder':
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/options.c b/lib/options.c
index dea2d0e..29e1327 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -677,7 +677,7 @@ gal_options_parse_csv_strings(struct argp_option *option, 
char *arg,
 
 
 /* Parse the given string into a series of size values (integers, stored as
-   an array of size_t). The ouput array will be stored in the `value'
+   an array of size_t). The output array will be stored in the `value'
    element of the option. The last element of the array is
    `GAL_BLANK_SIZE_T' to allow finding the number of elements within it
    later (similar to a string which terminates with a '\0' element). */
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]