gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master e8d9751 087/125: MakeNoise now uses the new ga


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master e8d9751 087/125: MakeNoise now uses the new gal_data_t infrastructure
Date: Sun, 23 Apr 2017 22:36:44 -0400 (EDT)

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

    MakeNoise now uses the new gal_data_t infrastructure
    
    The fruits of the new data structure are now implemented in MakeNoise. In
    the process it was found that MakeNoise isn't reporting the correct seed
    value to the random number generator, this problem has been fixed. It also
    now reports the seed in verbose mode in any case (previously it would only
    report the seed when an environment seed was to be used).
    
    After finishing MakeNoise and running `make check' several of MakeProfiles
    tests (that depended on MakeNoise outputs) were also tested and the
    respective modifications were made in them to run successfully. In the
    process, two corrections were made in MakeProfiles:
    
      - The old `--inputascanvas' is now was re-instated but with a new name:
        `--clearcanvas'. It was mainly removed because of its non-clean
        implementation before. But sice MakeProfiles' `ui.c' is now clean,
        re-implementing this feature was very easy. It can be very useful for
        practical purposes, when making labeled image for example.
    
      - Until now, MakeProfiles would abort with an error when the input
        columns had blank values. But for masking it might happen that you set
        a blank magnitude. So this check has now been removed when reading the
        magnitude column.
---
 bin/mknoise/args.h                                | 254 +++----------
 bin/mknoise/astmknoise.conf                       |   6 +-
 bin/mknoise/main.c                                |   6 +-
 bin/mknoise/main.h                                |  77 ++--
 bin/mknoise/mknoise.c                             |  43 +--
 bin/mknoise/ui.c                                  | 437 +++++++++++-----------
 bin/mknoise/ui.h                                  |   8 +-
 bin/mkprof/args.h                                 |  19 +-
 bin/mkprof/main.h                                 |   2 +-
 bin/mkprof/ui.c                                   |  22 +-
 doc/gnuastro.texi                                 |  60 +--
 lib/checkset.c                                    |   2 +-
 lib/checkset.h                                    |   2 +-
 lib/data.c                                        |  16 +-
 lib/fits.c                                        |   5 +-
 lib/options.c                                     |   4 +-
 lib/timing.c                                      |   7 +-
 lib/timing.h                                      |   2 +-
 tests/Makefile.am                                 |  16 +-
 tests/mknoise/addnoise.sh                         |   2 +-
 tests/mkprof/{inputascanvas.sh => clearcanvas.sh} |   6 +-
 tests/mkprof/clearcanvas.txt                      |  16 +
 tests/mkprof/ellipticalmasks.sh                   |   4 +-
 tests/mkprof/ellipticalmasks.txt                  |  24 +-
 tests/mkprof/inputascanvas.txt                    |  12 -
 tmpfs-config-make                                 |   5 +-
 26 files changed, 457 insertions(+), 600 deletions(-)

diff --git a/bin/mknoise/args.h b/bin/mknoise/args.h
index 795921a..65c0626 100644
--- a/bin/mknoise/args.h
+++ b/bin/mknoise/args.h
@@ -5,7 +5,7 @@ MakeNoise is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <address@hidden>
 Contributing author(s):
-Copyright (C) 2015, Free Software Foundation, Inc.
+Copyright (C) 2016, Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by the
@@ -23,123 +23,69 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #ifndef ARGS_H
 #define ARGS_H
 
-#include <argp.h>
 
-#include <commonargs.h>
-#include <fixedstringmacros.h>
 
 
 
 
-
-
-
-
-
-
-/**************************************************************/
-/**************        argp.h definitions       ***************/
-/**************************************************************/
-
-
-
-
-/* Definition parameters for the argp: */
-const char *argp_program_version=SPACK_STRING"\n"GAL_STRINGS_COPYRIGHT
-  "\n\nWritten by Mohammad Akhlaghi";
-const char *argp_program_bug_address=PACKAGE_BUGREPORT;
-static char args_doc[] = "ASTRdata ...";
-
-
-
-
-
-const char doc[] =
-  /* Before the list of options: */
-  GAL_STRINGS_TOP_HELP_INFO
-  SPACK_NAME" will add noise to all the pixels in an input image. The noise "
-  "parameters can be specified with the command line options. \n"
-  GAL_STRINGS_MORE_HELP_INFO
-  /* After the list of options: */
-  "\v"
-  PACKAGE_NAME" home page: "PACKAGE_URL;
-
-
-
-
-
-/* Available letters for short options:
-
-   a c f g i j k l m n p r t u v w x y
-   A B C E F G H I J L M O Q R T U W X Y Z
-
-   Number keys used: Nothing!
-
-   Options with keys (second structure element) larger than 500 do not
-   have a short version.
- */
-static struct argp_option options[] =
+/* Array of acceptable options. */
+struct argp_option program_options[] =
   {
     {
-      0, 0, 0, 0,
-      "Input:",
-      1
-    },
-    {
       "stdadd",
-      's',
+      ARGS_OPTION_KEY_STDADD,
       "FLT",
       0,
       "Standard deviation addition constant.",
-      1
+      GAL_OPTIONS_GROUP_INPUT,
+      &p->stdadd,
+      GAL_DATA_TYPE_FLOAT64,
+      GAL_OPTIONS_RANGE_GE_0,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
       "background",
-      'b',
+      ARGS_OPTION_KEY_BACKGROUND,
       "FLT",
       0,
-      "Fixed background magnitude for the image.",
-      1
+      "Fixed background magnitude for whole input.",
+      GAL_OPTIONS_GROUP_INPUT,
+      &p->background_mag,
+      GAL_DATA_TYPE_FLOAT64,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
       "zeropoint",
-      'z',
+      ARGS_OPTION_KEY_ZEROPOINT,
       "FLT",
       0,
-      "Image zeropoint magnitude.",
-      1
-    },
-    {
-      "envseed",
-      'e',
-      0,
-      0,
-      "Use GSL_RNG_SEED environment variable for seed.",
-      1
+      "Zeropoint magnitude of input.",
+      GAL_OPTIONS_GROUP_INPUT,
+      &p->zeropoint,
+      GAL_DATA_TYPE_FLOAT64,
+      GAL_OPTIONS_RANGE_GE_0,
+      GAL_OPTIONS_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
 
 
 
+
     {
-      0, 0, 0, 0,
-      "Output:",
-      2
-    },
-    {
-      "doubletype",
-      'd',
+      "envseed",
+      ARGS_OPTION_KEY_ENVSEED,
       0,
       0,
-      "Save output as a double precision floating point.",
-      2
-    },
-
-
-
-    {
-      0, 0, 0, 0,
-      "Operating modes:",
-      -1
+      "Use GSL_RNG_SEED environment variable for seed",
+      GAL_OPTIONS_GROUP_OPERATING_MODE,
+      &p->envseed,
+      GAL_OPTIONS_NO_ARG_TYPE,
+      GAL_OPTIONS_RANGE_0_OR_1,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
 
 
@@ -150,119 +96,21 @@ static struct argp_option options[] =
 
 
 
-/* Parse a single option: */
-static error_t
-parse_opt(int key, char *arg, struct argp_state *state)
-{
-  /* Save the arguments structure: */
-  struct mknoiseparams *p = state->input;
-
-  /* Set the pointer to the common parameters for all programs
-     here: */
-  state->child_inputs[0]=&p->cp;
-
-  /* In case the user incorrectly uses the equal sign (for example
-     with a short format or with space in the long format, then `arg`
-     start with (if the short version was called) or be (if the long
-     version was called with a space) the equal sign. So, here we
-     check if the first character of arg is the equal sign, then the
-     user is warned and the program is stopped: */
-  if(arg && arg[0]=='=')
-    argp_error(state, "incorrect use of the equal sign (`=`). For short "
-               "options, `=` should not be used and for long options, "
-               "there should be no space between the option, equal sign "
-               "and value");
-
-  switch(key)
-    {
-
-
-    /* Input: */
-    case 'b':
-      gal_checkset_any_double(arg, &p->mbackground, "background", key, SPACK,
-                              NULL, 0);
-      p->up.backgroundset=1;
-      break;
-    case 's':
-      gal_checkset_double_el_0(arg, &p->stdadd, "stdadd", key, SPACK,
-                               NULL, 0);
-      p->up.stdaddset=1;
-      break;
-    case 'z':
-      gal_checkset_any_double(arg, &p->zeropoint, "zeropoint", key, SPACK,
-                              NULL, 0);
-      p->up.zeropointset=1;
-      break;
-    case 'e':
-      p->envseed=1;
-      p->up.envseedset=1;
-      break;
-
-
-    /* Output: */
-    case 'd':
-      p->doubletype=1;
-      break;
-
-
-    /* Read the non-option arguments: */
-    case ARGP_KEY_ARG:
-
-      /* See what type of input value it is and put it in. */
-      if( gal_fits_name_is_fits(arg) )
-        {
-          if(p->up.inputname)
-            argp_error(state, "only one input image should be given");
-          else
-            p->up.inputname=arg;
-        }
-      else
-        argp_error(state, "%s is not a valid file type", arg);
-      break;
-
-
-
-
+/* Define the child argp structure. */
+struct argp
+gal_options_common_child = {gal_commonopts_options,
+                            gal_options_common_argp_parse,
+                            NULL, NULL, NULL, NULL, NULL};
 
-    /* The command line options and arguments are finished. */
-    case ARGP_KEY_END:
-      if(p->cp.setdirconf==0 && p->cp.setusrconf==0
-         && p->cp.printparams==0)
-        {
-          if(state->arg_num==0)
-            argp_error(state, "no argument given");
-          if(p->up.inputname==NULL)
-            argp_error(state, "no input FITS image(s) provided");
-        }
-      break;
-
-
-
-
-
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-
-
-
-
-/* Specify the children parsers: */
-struct argp_child children[]=
-  {
-    {&commonargp, 0, NULL, 0},
-    {0, 0, 0, 0}
-  };
-
-
-
-
-
-/* Basic structure defining the whole argument reading process. */
-static struct argp thisargp = {options, parse_opt, args_doc,
-                               doc, children, NULL, NULL};
+/* Use the child argp structure in list of children (only one for now). */
+struct argp_child
+children[]=
+{
+  {&gal_options_common_child, 0, NULL, 0},
+  {0, 0, 0, 0}
+};
 
+/* Set all the necessary argp parameters. */
+struct argp
+thisargp = {program_options, parse_opt, args_doc, doc, children, NULL, NULL};
 #endif
diff --git a/bin/mknoise/astmknoise.conf b/bin/mknoise/astmknoise.conf
index 1133d03..ea8a6e0 100644
--- a/bin/mknoise/astmknoise.conf
+++ b/bin/mknoise/astmknoise.conf
@@ -23,4 +23,8 @@
  stdadd         0.000
  zeropoint      0.00
 
-# Output:
\ No newline at end of file
+# Output:
+ type           float32
+
+# Common options
+ minmapsize     1000000000
\ No newline at end of file
diff --git a/bin/mknoise/main.c b/bin/mknoise/main.c
index f3c7f25..a8132f7 100644
--- a/bin/mknoise/main.c
+++ b/bin/mknoise/main.c
@@ -36,20 +36,20 @@ int
 main (int argc, char *argv[])
 {
   struct timeval t1;
-  struct mknoiseparams p={{0}, {0}, 0};
+  struct mknoiseparams p={{0}, 0};
 
   /* Set the starting time.*/
   time(&p.rawtime);
   gettimeofday(&t1, NULL);
 
   /* Read the input parameters. */
-  setparams(argc, argv, &p);
+  ui_read_check_inputs_setup(argc, argv, &p);
 
   /* Run MakeProfiles */
   mknoise(&p);
 
   /* Free all non-freed allocations. */
-  freeandreport(&p, &t1);
+  ui_free_report(&p);
 
   /* Return successfully.*/
   return EXIT_SUCCESS;
diff --git a/bin/mknoise/main.h b/bin/mknoise/main.h
index 82df529..a09c350 100644
--- a/bin/mknoise/main.h
+++ b/bin/mknoise/main.h
@@ -5,7 +5,7 @@ MakeNoise is part of GNU Astronomy Utilities (Gnuastro) package.
 Original author:
      Mohammad Akhlaghi <address@hidden>
 Contributing author(s):
-Copyright (C) 2015, Free Software Foundation, Inc.
+Copyright (C) 2016, Free Software Foundation, Inc.
 
 Gnuastro is free software: you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by the
@@ -23,68 +23,39 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #ifndef MAIN_H
 #define MAIN_H
 
-#include <pthread.h>
+/* Include necessary headers */
+#include <gnuastro/data.h>
 #include <gsl/gsl_rng.h>
 
-#include <gnuastro/fits.h>
+#include <options.h>
 
-#include <commonparams.h>
-
-/* Progarm name macros: */
-#define SPACK           "astmknoise" /* Subpackage executable name. */
-#define SPACK_NAME      "MakeNoise"     /* Subpackage full name.       */
-#define SPACK_STRING    SPACK_NAME" ("PACKAGE_NAME") "PACKAGE_VERSION
-
-
-
-
-
-
-struct uiparams
-{
-  char       *inputname;   /* Name of input file.                      */
-
-  int     backgroundset;
-  int      zeropointset;
-  int         stdaddset;
-  int       randseedset;
-  int        envseedset;
-};
+/* Progarm names.  */
+#define PROGRAM_NAME   "MakeNoise"     /* Program full name.       */
+#define PROGRAM_EXEC   "astmknoise"    /* Program executable name. */
+#define PROGRAM_STRING PROGRAM_NAME" (" PACKAGE_NAME ") " PACKAGE_VERSION
 
 
 
 
 
+/* Main program parameters structure */
 struct mknoiseparams
 {
-  /* Other structures: */
-  struct uiparams         up; /* User interface parameters.            */
-  struct gal_commonparams cp; /* Common parameters.                    */
-
-  /* Input: */
-  int            envseed;  /* ==1, generate a random seed.             */
-  double          *input;  /* Input image data in double precision.    */
-  int        inputbitpix;  /* Input BITPIX header keyword value.       */
-  size_t             is0;  /* The number of rows in the input image.   */
-  size_t             is1;  /* The number of columns in the input image.*/
-  int           anyblank;  /* ==1: There are blank pixels in input.    */
-  int               nwcs;  /* Number of WCS structures.                */
-  struct wcsprm     *wcs;  /* Pointer to WCS structures.               */
-  double      background;  /* Mean of noise probability distribution.  */
-  double     mbackground;  /* Background in magnitudes.                */
-  double          stdadd;  /* Standard deviation constants.            */
-  double       zeropoint;  /* Zeropoint magnitude of image.            */
-
-  /* Random number generator */
-  gsl_rng           *rng;  /* Main instance of random number generator.*/
-
-  /* Output: */
-  int         doubletype;  /* Save the output in double type.          */
-
-  /* Internal: */
-  time_t          rawtime; /* Starting time of the program.            */
-  char rng_type[FLEN_VALUE];   /* The type of the Random number gen.  */
-  long           rng_seed; /* Seed of Random number generator.         */
+  /* From command-line */
+  struct gal_options_common_params cp;   /* Common parameters.           */
+  char        *inputname;    /* Input filename.                          */
+  double          stdadd;    /* Standard deviation constants.            */
+  double       zeropoint;    /* Zeropoint magnitude of image.            */
+  double  background_mag;    /* Background in magnitudes.                */
+  uint8_t        envseed;    /* ==1, generate a random seed.             */
+
+  /* Internal */
+  gal_data_t      *input;    /* Input image data in double precision.    */
+  double      background;    /* Background in units of brightness.       */
+  gsl_rng           *rng;    /* Main instance of random number generator.*/
+  char         *rng_type;    /* The type of the Random number gen.       */
+  int64_t       rng_seed;    /* Seed of Random number generator.         */
+  time_t         rawtime;    /* Starting time of the program.            */
 };
 
 #endif
diff --git a/bin/mknoise/mknoise.c b/bin/mknoise/mknoise.c
index 8d1e877..7de46f0 100644
--- a/bin/mknoise/mknoise.c
+++ b/bin/mknoise/mknoise.c
@@ -54,51 +54,42 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 void
 convertsaveoutput(struct mknoiseparams *p)
 {
-  void *array;
   char keyname1[FLEN_KEYWORD];
   struct gal_fits_key_ll *headers=NULL;
   char keyname2[FLEN_KEYWORD], keyname3[FLEN_KEYWORD];
   char keyname4[FLEN_KEYWORD], keyname5[FLEN_KEYWORD];
 
-  /* Convert the output to the input image format: */
-  if(p->inputbitpix==DOUBLE_IMG || p->doubletype)
-    {
-      array=p->input;
-      p->inputbitpix=DOUBLE_IMG; /* Not converted and p->doubletype==1 */
-    }
-  else
-    gal_fits_change_type((void **)p->input, DOUBLE_IMG, p->is0*p->is1,
-                              p->anyblank, &array, p->inputbitpix);
 
   /* Add the proper information to the header of the output: */
-  gal_fits_file_name_in_keywords("INF", p->up.inputname, &headers);
+  gal_fits_key_write_filename("INF", p->inputname, &headers);
   strcpy(keyname1, "BCKGRND");
-  gal_fits_add_to_key_ll_end(&headers, TDOUBLE, keyname1, 0,
-                             &p->mbackground, 0, "Background "
+  gal_fits_key_add_to_ll_end(&headers, GAL_DATA_TYPE_FLOAT64, keyname1, 0,
+                             &p->background_mag, 0, "Background "
                              "value (in magnitude) for noise.",
                              0, NULL);
   strcpy(keyname2, "BZRPNT");
-  gal_fits_add_to_key_ll_end(&headers, TDOUBLE, keyname2, 0, &p->zeropoint,
-                             0, "Zeropoint magnitude of image.", 0, NULL);
+  gal_fits_key_add_to_ll_end(&headers, GAL_DATA_TYPE_FLOAT64, keyname2, 0,
+                             &p->zeropoint, 0,
+                             "Zeropoint magnitude of image.", 0, NULL);
   strcpy(keyname3, "STDADD");
-  gal_fits_add_to_key_ll_end(&headers, TDOUBLE, keyname3, 0, &p->stdadd, 0,
+  gal_fits_key_add_to_ll_end(&headers, GAL_DATA_TYPE_FLOAT64, keyname3, 0,
+                             &p->stdadd, 0,
                              "Instrumental noise in units of flux.", 0, NULL);
   strcpy(keyname4, "RNGTYPE");
-  gal_fits_add_to_key_ll_end(&headers, TSTRING, keyname4, 0, &p->rng_type,
-                             0, "Random number generator (by GSL) type.",
+  gal_fits_key_add_to_ll_end(&headers, GAL_DATA_TYPE_STRING, keyname4, 0,
+                             p->rng_type, 0,
+                             "Random number generator (by GSL) type.",
                              0, NULL);
   strcpy(keyname5, "RNGSEED");
-  gal_fits_add_to_key_ll_end(&headers, TLONG, keyname5, 0, &p->rng_seed,
+  gal_fits_key_add_to_ll_end(&headers, GAL_DATA_TYPE_INT64, keyname5, 0,
+                             &p->rng_seed,
                              0, "Random number generator (by GSL) seed.",
                              0, NULL);
 
   /* Save the output: */
-  gal_fits_array_to_file(p->cp.output, "NoiseAdded", p->inputbitpix,
-                         array, p->is0, p->is1, p->anyblank, p->wcs,
-                         headers, SPACK_STRING);
+  p->input=gal_data_copy_to_new_type_free(p->input, p->cp.type);
+  gal_fits_img_write(p->input, p->cp.output, headers, PROGRAM_STRING);
 
-  if(array!=p->input)
-    free(array);
 }
 
 
@@ -111,9 +102,9 @@ mknoise(struct mknoiseparams *p)
   double *d, *df, background=p->background, stdadd=p->stdadd;
 
   /* Add the noise: */
-  df=(d=p->input)+p->is0*p->is1;
+  df=(d=p->input->array)+p->input->size;
   do
-    *d+=background+gsl_ran_gaussian(p->rng, sqrt(stdadd+background+*d));
+    *d += background+gsl_ran_gaussian(p->rng, sqrt(stdadd+background+*d));
   while(++d<df);
 
   /* Convert and save the output in the proper format: */
diff --git a/bin/mknoise/ui.c b/bin/mknoise/ui.c
index 4da2bc5..6221182 100644
--- a/bin/mknoise/ui.c
+++ b/bin/mknoise/ui.c
@@ -22,203 +22,173 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 **********************************************************************/
 #include <config.h>
 
-#include <math.h>
-#include <stdio.h>
+#include <argp.h>
 #include <errno.h>
 #include <error.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fitsio.h>
+#include <stdio.h>
 
+#include <gnuastro/wcs.h>
 #include <gnuastro/fits.h>
-#include <gnuastro/txtarray.h>
+#include <gnuastro/table.h>
+#include <gnuastro/linkedlist.h>
 
-#include <nproc.h>               /* From Gnulib.                   */
-#include <timing.h>              /* Includes time.h and sys/time.h */
+#include <timing.h>
+#include <options.h>
 #include <checkset.h>
-#include <commonargs.h>
-#include <configfiles.h>
+#include <fixedstringmacros.h>
 
 #include "main.h"
 
-#include "ui.h"                  /* Needs main.h                   */
-#include "args.h"                /* Needs main.h, includes argp.h. */
+#include "ui.h"
+#include "authors-cite.h"
 
 
-/* Set the file names of the places where the default parameters are
-   put. */
-#define CONFIG_FILE SPACK CONF_POSTFIX
-#define SYSCONFIG_FILE SYSCONFIG_DIR "/" CONFIG_FILE
-#define USERCONFIG_FILEEND USERCONFIG_DIR CONFIG_FILE
-#define CURDIRCONFIG_FILE CURDIRCONFIG_DIR CONFIG_FILE
 
 
 
+/**************************************************************/
+/*********      Argp necessary global entities     ************/
+/**************************************************************/
+/* Definition parameters for the Argp: */
+const char *
+argp_program_version = PROGRAM_STRING "\n"
+                       GAL_STRINGS_COPYRIGHT
+                       "\n\nWritten/developed by "PROGRAM_AUTHORS;
 
+const char *
+argp_program_bug_address = PACKAGE_BUGREPORT;
 
+static char
+args_doc[] = "ASTRdata";
 
+const char
+doc[] = GAL_STRINGS_TOP_HELP_INFO PROGRAM_NAME" will add noise to all the "
+  "pixels in an input dataset. The noise parameters can be specified with "
+  "the command line options. \n"
+  GAL_STRINGS_MORE_HELP_INFO
+  /* After the list of options: */
+  "\v"
+  PACKAGE_NAME" home page: "PACKAGE_URL;
 
 
 
 
-/**************************************************************/
-/**************       Options and parameters    ***************/
-/**************************************************************/
-void
-readconfig(char *filename, struct mknoiseparams *p)
-{
-  FILE *fp;
-  size_t lineno=0, len=200;
-  char *line, *name, *value;
-  struct uiparams *up=&p->up;
-  struct gal_commonparams *cp=&p->cp;
-  char key='a';        /* Not used, just a place holder. */
-
-  /* When the file doesn't exist or can't be opened, it is ignored. It
-     might be intentional, so there is no error. If a parameter is
-     missing, it will be reported after all defaults are read. */
-  fp=fopen(filename, "r");
-  if (fp==NULL) return;
-
-
-  /* Allocate some space for `line` with `len` elements so it can
-     easily be freed later on. The value of `len` is arbitarary at
-     this point, during the run, getline will change it along with the
-     pointer to line. */
-  errno=0;
-  line=malloc(len*sizeof *line);
-  if(line==NULL)
-    error(EXIT_FAILURE, errno, "ui.c: %zu bytes in readdefaults",
-          len * sizeof *line);
 
-  /* Read the tokens in the file:  */
-  while(getline(&line, &len, fp) != -1)
-    {
-      /* Prepare the "name" and "value" strings, also set lineno. */
-      GAL_CONFIGFILES_START_READING_LINE;
+/* Available letters for short options:
 
+   a c f g i j k l m n p r t u v w x y
+   A B C E F G H I J L M O Q R T U W X Y Z  */
+enum option_keys_enum
+{
+  /* With short-option version. */
+  ARGS_OPTION_KEY_STDADD      = 's',
+  ARGS_OPTION_KEY_BACKGROUND  = 'b',
+  ARGS_OPTION_KEY_ZEROPOINT   = 'z',
+  ARGS_OPTION_KEY_ENVSEED     = 'e',
 
+  /* Only with long version (start with a value 1000, the rest will be set
+     automatically). */
+};
 
 
-      /* Inputs: */
-      if(strcmp(name, "hdu")==0)
-        gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->hduset);
 
-      else if(strcmp(name, "background")==0)
-        {
-          if(up->backgroundset) continue;
-          gal_checkset_any_double(value, &p->mbackground, value, key,
-                                  SPACK, filename, lineno);
-          up->backgroundset=1;
-        }
-      else if(strcmp(name, "zeropoint")==0)
-        {
-          if(up->zeropointset) continue;
-          gal_checkset_any_double(value, &p->zeropoint, value, key,
-                                  SPACK, filename, lineno);
-          up->zeropointset=1;
-        }
-      else if(strcmp(name, "stdadd")==0)
-        {
-          if(up->stdaddset) continue;
-          gal_checkset_double_el_0(value, &p->stdadd, value, key, SPACK,
-                                   filename, lineno);
-          up->stdaddset=1;
-        }
-      else if(strcmp(name, "envseed")==0)
-        {
-          if(up->envseedset) continue;
-          gal_checkset_int_zero_or_one(value, &p->envseed, name, key,
-                                       SPACK, filename, lineno);
-          up->envseedset=1;
-        }
 
 
 
-      /* Outputs */
-      else if(strcmp(name, "output")==0)
-        gal_checkset_allocate_copy_set(value, &cp->output, &cp->outputset);
 
 
 
 
-      /* Operating modes: */
-      /* Read options common to all programs */
-      GAL_CONFIGFILES_READ_COMMONOPTIONS_FROM_CONF
 
 
-      else
-        error_at_line(EXIT_FAILURE, 0, filename, lineno,
-                      "`%s` not recognized.\n", name);
-    }
 
-  free(line);
-  fclose(fp);
-}
 
 
 
 
 
-void
-printvalues(FILE *fp, struct mknoiseparams *p)
+
+/**************************************************************/
+/*********    Initialize & Parse command-line    **************/
+/**************************************************************/
+static void
+ui_initialize_options(struct mknoiseparams *p,
+                      struct argp_option *program_options,
+                      struct argp_option *gal_commonopts_options)
 {
-  struct uiparams *up=&p->up;
-  struct gal_commonparams *cp=&p->cp;
-
-  /* Print all the options that are set. Separate each group with a
-     commented line explaining the options in that group. */
-  fprintf(fp, "\n# Input image:\n");
-  if(cp->hduset)
-    GAL_CHECKSET_PRINT_STRING_MAYBE_WITH_SPACE("hdu", cp->hdu);
-  if(up->backgroundset)
-    fprintf(fp, CONF_SHOWFMT"%f\n", "background", p->mbackground);
-  if(up->zeropointset)
-    fprintf(fp, CONF_SHOWFMT"%f\n", "zeropoint", p->zeropoint);
-  if(up->stdaddset)
-    fprintf(fp, CONF_SHOWFMT"%f\n", "stdadd", p->stdadd);
-  if(up->envseedset)
-    fprintf(fp, CONF_SHOWFMT"%d\n", "envseed", p->envseed);
-
-
-  fprintf(fp, "\n# Output parameters:\n");
-  if(cp->outputset)
-    fprintf(fp, CONF_SHOWFMT"%s\n", "output", cp->output);
-
-
-  /* For the operating mode, first put the macro to print the common
-     options, then the (possible options particular to this
-     program). */
-  fprintf(fp, "\n# Operating mode:\n");
-  GAL_CONFIGFILES_PRINT_COMMONOPTIONS;
+  size_t i;
+  struct gal_options_common_params *cp=&p->cp;
+
+
+  /* Set the necessary common parameters structure. */
+  cp->program_name       = PROGRAM_NAME;
+  cp->program_exec       = PROGRAM_EXEC;
+  cp->program_bibtex     = PROGRAM_BIBTEX;
+  cp->program_authors    = PROGRAM_AUTHORS;
+  cp->poptions           = program_options;
+  cp->coptions           = gal_commonopts_options;
+
+
+  /* Set the mandatory common options. */
+  for(i=0; !gal_options_is_last(&cp->coptions[i]); ++i)
+    switch(cp->coptions[i].key)
+      {
+      case GAL_OPTIONS_KEY_TYPE:
+      case GAL_OPTIONS_KEY_MINMAPSIZE:
+        cp->coptions[i].mandatory=GAL_OPTIONS_MANDATORY;
+        break;
+
+      case GAL_OPTIONS_KEY_SEARCHIN:
+      case GAL_OPTIONS_KEY_TABLEFORMAT:
+        cp->coptions[i].flags=OPTION_HIDDEN;
+        break;
+      }
 }
 
 
 
 
 
-
-/* Note that numthreads will be used automatically based on the
-   configure time. */
-void
-checkifset(struct mknoiseparams *p)
+/* Parse a single option: */
+error_t
+parse_opt(int key, char *arg, struct argp_state *state)
 {
-  struct uiparams *up=&p->up;
-  struct gal_commonparams *cp=&p->cp;
+  struct mknoiseparams *p = state->input;
+
+  /* Pass `gal_options_common_params' into the child parser.  */
+  state->child_inputs[0] = &p->cp;
+
+  /* In case the user incorrectly uses the equal sign (for example
+     with a short format or with space in the long format, then `arg`
+     start with (if the short version was called) or be (if the long
+     version was called with a space) the equal sign. So, here we
+     check if the first character of arg is the equal sign, then the
+     user is warned and the program is stopped: */
+  if(arg && arg[0]=='=')
+    argp_error(state, "incorrect use of the equal sign (`=`). For short "
+               "options, `=` should not be used and for long options, "
+               "there should be no space between the option, equal sign "
+               "and value");
+
+  /* Set the key to this option. */
+  switch(key)
+    {
 
-  int intro=0;
-  if(cp->hduset==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("hdu");
+    /* Read the non-option tokens (arguments): */
+    case ARGP_KEY_ARG:
+      if(p->inputname)
+        argp_error(state, "only one argument (input file) should be given");
+      else
+        p->inputname=arg;
+      break;
 
-  if(up->backgroundset==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("background");
-  if(up->zeropointset==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("zeropoint");
-  if(up->stdaddset==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("stdadd");
 
+    /* This is an option, set its value. */
+    default:
+      return gal_options_set_from_key(key, arg, p->cp.poptions, &p->cp);
+    }
 
-  GAL_CONFIGFILES_END_OF_NOTSET_REPORT;
+  return 0;
 }
 
 
@@ -243,28 +213,38 @@ checkifset(struct mknoiseparams *p)
 /**************************************************************/
 /***************       Sanity Check         *******************/
 /**************************************************************/
-void
-sanitycheck(struct mknoiseparams *p)
+/* Read and check ONLY the options. When arguments are involved, do the
+   check in `ui_check_options_and_arguments'. */
+static void
+ui_read_check_only_options(struct mknoiseparams *p)
 {
 
-  /* Make sure the input file exists. */
-  gal_checkset_check_file(p->up.inputname);
+  /* Check if the format of the output table is valid, given the type of
+     the output. */
+  gal_table_check_fits_format(p->cp.output, p->cp.tableformat);
 
-  /* Set the output name: */
-  if(p->cp.output)
-    gal_checkset_check_remove_file(p->cp.output, p->cp.dontdelete);
-  else
-    gal_checkset_automatic_output(p->up.inputname, "_noised.fits",
-                                  p->cp.removedirinfo, p->cp.dontdelete,
-                                  &p->cp.output);
+}
 
-  /* Convert the background value from magnitudes to flux. Note that
-     magnitudes are actually calculated from the ratio of brightness,
-     not flux. But in the context of MakeNoise where everything is
-     done on pixels independently, brightness and flux are the same
-     (flux is multiplied by the area of one pixel (=1) to give
-     brightness).*/
-  p->background=pow(10, (p->zeropoint-p->mbackground)/2.5f);
+
+
+
+
+static void
+ui_check_options_and_arguments(struct mknoiseparams *p)
+{
+  /* Make sure an input file name was given and if it was a FITS file, that
+     a HDU is also given. */
+  if(p->inputname)
+    {
+      if( gal_fits_name_is_fits(p->inputname) && p->cp.hdu==NULL )
+        error(EXIT_FAILURE, 0, "no HDU specified. When the input is a FITS "
+              "file, a HDU must also be specified, you can use the `--hdu' "
+              "(`-h') option and give it the HDU number (starting from "
+              "zero), extension name, or anything acceptable by CFITSIO");
+
+    }
+  else
+    error(EXIT_FAILURE, 0, "no input file is specified");
 }
 
 
@@ -290,32 +270,39 @@ sanitycheck(struct mknoiseparams *p)
 /***************       Preparations         *******************/
 /**************************************************************/
 void
-preparearrays(struct mknoiseparams *p)
+ui_preparations(struct mknoiseparams *p)
 {
-  void *array;
-
-  /* Read in the input image: */
-  p->anyblank=gal_fits_hdu_to_array(p->up.inputname, p->cp.hdu,
-                                    &p->inputbitpix, &array,
-                                    &p->is0, &p->is1);
-  if(p->inputbitpix==DOUBLE_IMG)
-    p->input=array;
+  /* Read the input image as a double type */
+  p->input=gal_fits_img_read_to_type(p->inputname, p->cp.hdu,
+                                     GAL_DATA_TYPE_FLOAT64, p->cp.minmapsize);
+
+  /* Read the WSC structure. */
+  gal_wcs_read(p->inputname, p->cp.hdu, 0, 0, &p->input->nwcs,
+               &p->input->wcs);
+
+  /* Set the output name: */
+  if(p->cp.output)
+    gal_checkset_check_remove_file(p->cp.output, p->cp.dontdelete);
   else
-    {
-      gal_fits_change_type(array, p->inputbitpix, p->is0*p->is1,
-                                p->anyblank, (void **)&p->input,
-                                DOUBLE_IMG);
-      free(array);
-    }
-  gal_fits_read_wcs(p->up.inputname, p->cp.hdu, 0, 0, &p->nwcs, &p->wcs);
+    p->cp.output=gal_checkset_automatic_output(&p->cp, p->inputname,
+                                               "_noised.fits");
+
+  /* Convert the background value from magnitudes to flux. Note that
+     magnitudes are actually calculated from the ratio of brightness,
+     not flux. But in the context of MakeNoise where everything is
+     done on pixels independently, brightness and flux are the same
+     (flux is multiplied by the area of one pixel (=1) to give
+     brightness).*/
+  p->background=pow(10, (p->zeropoint-p->background_mag)/2.5f);
 
   /* Allocate the random number generator: */
   gsl_rng_env_setup();
   p->rng=gsl_rng_alloc(gsl_rng_default);
-  if(p->envseed==0)
-    gsl_rng_set(p->rng, gal_timing_time_based_rng_seed());
-  p->rng_seed=gsl_rng_default_seed;
-  strcpy(p->rng_type, gsl_rng_name(p->rng));
+  p->rng_seed = ( p->envseed
+                  ? gsl_rng_default_seed
+                  : gal_timing_time_based_rng_seed() );
+  gsl_rng_set(p->rng, p->rng_seed);
+  gal_checkset_allocate_copy(gsl_rng_name(p->rng), &p->rng_type);
 }
 
 
@@ -339,53 +326,69 @@ preparearrays(struct mknoiseparams *p)
 /**************************************************************/
 /************         Set the parameters          *************/
 /**************************************************************/
+
 void
-setparams(int argc, char *argv[], struct mknoiseparams *p)
+ui_read_check_inputs_setup(int argc, char *argv[], struct mknoiseparams *p)
 {
+  struct gal_options_common_params *cp=&p->cp;
   char message[GAL_TIMING_VERB_MSG_LENGTH_V];
-  struct gal_commonparams *cp=&p->cp;
 
-  /* Set the non-zero initial values, the structure was initialized to
-     have a zero value for all elements. */
-  cp->spack         = SPACK;
-  cp->verb          = 1;
-  cp->numthreads    = num_processors(NPROC_CURRENT);
-  cp->removedirinfo = 1;
 
-  /* Read the arguments. */
+  /* Include the parameters necessary for argp from this program (`args.h')
+     and for the common options to all Gnuastro (`commonopts.h'). We want
+     to directly put the pointers to the fields in `p' and `cp', so we are
+     simply including the header here to not have to use long macros in
+     those headers which make them hard to read and modify. This also helps
+     in having a clean environment: everything in those headers is only
+     available within the scope of this function. */
+#include <commonopts.h>
+#include "args.h"
+
+
+  /* Initialize the options and necessary information.  */
+  ui_initialize_options(p, program_options, gal_commonopts_options);
+
+
+  /* Read the command-line options and arguments. */
   errno=0;
   if(argp_parse(&thisargp, argc, argv, 0, 0, p))
     error(EXIT_FAILURE, errno, "parsing arguments");
 
-  /* Add the user default values and save them if asked. */
-  GAL_CONFIGFILES_CHECK_SET_CONFIG;
 
-  /* Check if all the required parameters are set. */
-  checkifset(p);
+  /* Read the configuration files and set the common values. */
+  gal_options_read_config_set(&p->cp);
+
 
-  /* Print the values for each parameter. */
-  if(cp->printparams)
-    GAL_CONFIGFILES_REPORT_PARAMETERS_SET;
+  /* Read the options into the program's structure, and check them and
+     their relations prior to printing. */
+  ui_read_check_only_options(p);
 
-  /* Make the array of input images. */
-  preparearrays(p);
 
-  /* Do a sanity check. */
-  sanitycheck(p);
+  /* Print the option values if asked. Note that this needs to be done
+     after the option checks so un-sane values are not printed in the
+     output state. */
+  gal_options_print_state(&p->cp);
+
+
+  /* Check that the options and arguments fit well with each other. Note
+     that arguments don't go in a configuration file. So this test should
+     be done after (possibly) printing the option values. */
+  ui_check_options_and_arguments(p);
+
+
+  /* Read/allocate all the necessary starting arrays. */
+  ui_preparations(p);
+
 
   /* Everything is ready, notify the user of the program starting. */
-  if(cp->verb)
+  if(!p->cp.quiet)
     {
-      printf(SPACK_NAME" started on %s", ctime(&p->rawtime));
+      printf(PROGRAM_NAME" started on %s", ctime(&p->rawtime));
       sprintf(message, "Random number generator type: %s",
               gsl_rng_name(p->rng));
       gal_timing_report(NULL, message, 1);
-      if(p->envseed)
-        {
-          sprintf(message, "Random number generator seed: %zu",
-                  gsl_rng_default_seed);
-          gal_timing_report(NULL, message, 1);
-        }
+      sprintf(message, "Random number generator seed: %ld", p->rng_seed);
+      gal_timing_report(NULL, message, 1);
     }
 }
 
@@ -412,21 +415,11 @@ setparams(int argc, char *argv[], struct mknoiseparams *p)
 /************      Free allocated, report         *************/
 /**************************************************************/
 void
-freeandreport(struct mknoiseparams *p, struct timeval *t1)
+ui_free_report(struct mknoiseparams *p)
 {
   /* Free the allocated arrays: */
-  free(p->input);
   free(p->cp.hdu);
+  free(p->rng_type);
   free(p->cp.output);
-
-  /* The world coordinate system: */
-  if(p->wcs)
-    wcsvfree(&p->nwcs, &p->wcs);
-
-  /* Free the random number generator: */
-  gsl_rng_free(p->rng);
-
-  /* Print the final message. */
-  if(p->cp.verb)
-    gal_timing_report(t1, SPACK_NAME" finished in: ", 0);
+  gal_data_free(p->input);
 }
diff --git a/bin/mknoise/ui.h b/bin/mknoise/ui.h
index 5e2dc96..1e8731c 100644
--- a/bin/mknoise/ui.h
+++ b/bin/mknoise/ui.h
@@ -20,13 +20,13 @@ General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
 **********************************************************************/
-#ifndef IMCROPUI_H
-#define IMCROPUI_H
+#ifndef UI_H
+#define UI_H
 
 void
-setparams(int argc, char *argv[], struct mknoiseparams *p);
+ui_read_check_inputs_setup(int argc, char *argv[], struct mknoiseparams *p);
 
 void
-freeandreport(struct mknoiseparams *p, struct timeval *t1);
+ui_free_report(struct mknoiseparams *p);
 
 #endif
diff --git a/bin/mkprof/args.h b/bin/mkprof/args.h
index 7060c57..25e9cc6 100644
--- a/bin/mkprof/args.h
+++ b/bin/mkprof/args.h
@@ -56,6 +56,19 @@ struct argp_option program_options[] =
       GAL_OPTIONS_NOT_MANDATORY,
       GAL_OPTIONS_NOT_SET
     },
+    {
+      "clearcanvas",
+      ARGS_OPTION_KEY_CLEARCANVAS,
+      0,
+      0,
+      "All pixels in background image read as zero.",
+      GAL_OPTIONS_GROUP_INPUT,
+      &p->clearcanvas,
+      GAL_OPTIONS_NO_ARG_TYPE,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
 
 
 
@@ -359,8 +372,8 @@ struct argp_option program_options[] =
       ARGS_OPTION_KEY_FCOL,
       "STR/INT",
       0,
-      "Sersic (1), Moffat (2), Gaussian (3), Point (4), "
-      "Flat (5), Circumference (6).",
+      "sersic (1), moffat (2), gaussian (3), point (4), "
+      "flat (5), circumference (6).",
       ARGS_GROUP_CATALOG,
       &p->fcol,
       GAL_DATA_TYPE_STRING,
@@ -451,7 +464,7 @@ struct argp_option program_options[] =
       ARGS_OPTION_KEY_MFORFLATPIX,
       0,
       0,
-      "mcol is flat pixel value (when fcol is 4 or 5)",
+      "mcol is flat pixel value (when fcol is 5 or 6)",
       ARGS_GROUP_CATALOG,
       &p->mforflatpix,
       GAL_OPTIONS_NO_ARG_TYPE,
diff --git a/bin/mkprof/main.h b/bin/mkprof/main.h
index 0635c40..eac8c1d 100644
--- a/bin/mkprof/main.h
+++ b/bin/mkprof/main.h
@@ -107,7 +107,7 @@ struct mkprofparams
   char             *catname;  /* Name of catalog of parameters.           */
   char             *backhdu;  /* HDU of background image.                 */
   long             naxes[2];  /* Size of the output image.                */
-  uint8_t     inputascanvas;  /* Input image's header for size and WCS.   */
+  uint8_t       clearcanvas;  /* Pixels in background image set to zero.  */
   uint8_t        oversample;  /* Oversampling scale.                      */
   uint8_t          psfinimg;  /* ==1: Build PSF profiles in image.        */
   uint8_t        individual;  /* ==1: Build all catalog separately.       */
diff --git a/bin/mkprof/ui.c b/bin/mkprof/ui.c
index cdc9633..083a26b 100644
--- a/bin/mkprof/ui.c
+++ b/bin/mkprof/ui.c
@@ -103,7 +103,7 @@ enum option_keys_enum
   ARGS_OPTION_KEY_BACKHDU         = 'B',
   ARGS_OPTION_KEY_NAXIS1          = 'x',
   ARGS_OPTION_KEY_NAXIS2          = 'y',
-  ARGS_OPTION_KEY_INPUTASCANVAS   = 'C',
+  ARGS_OPTION_KEY_CLEARCANVAS     = 'C',
   ARGS_OPTION_KEY_OVERSAMPLE      = 's',
   ARGS_OPTION_KEY_INDIVIDUAL      = 'i',
   ARGS_OPTION_KEY_NOMERGED        = 'm',
@@ -236,7 +236,10 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Read the non-option tokens (arguments): */
     case ARGP_KEY_ARG:
-      p->catname=arg;
+      if(p->catname)
+        argp_error(state, "only one argument (input catalog) may be given");
+      else
+        p->catname=arg;
       break;
 
 
@@ -396,7 +399,7 @@ ui_read_profile_function(struct mkprofparams *p, char 
**strarr)
       else if ( !strcmp("flat", strarr[i]) )
         p->f[i]=PROFILE_FLAT;
 
-      else if ( !strcmp("circumference", strarr[i]) )
+      else if ( !strcmp("circum", strarr[i]) )
         p->f[i]=PROFILE_CIRCUMFERENCE;
 
       else if ( !strcmp(GAL_DATA_BLANK_STRING, strarr[i]) )
@@ -416,6 +419,7 @@ static void
 ui_read_cols(struct mkprofparams *p)
 {
   char *colname;
+  int checkblank;
   size_t counter=0, i;
   gal_data_t *cols, *tmp, *corrtype;
   char *ax1col=p->racol?p->racol:p->xcol;
@@ -447,6 +451,9 @@ ui_read_cols(struct mkprofparams *p)
       /* Pop out the top node. */
       tmp=gal_data_pop_from_ll(&cols);
 
+      /* By default check if the column has blank values, but it can be
+         turned off for some columns. */
+      checkblank=1;
 
       /* Note that the input was a linked list, so the output order is the
          inverse of the input order. For the position, we will store the
@@ -524,6 +531,7 @@ ui_read_cols(struct mkprofparams *p)
           colname="magnitude (`mcol')";
           corrtype=gal_data_copy_to_new_type_free(tmp, GAL_DATA_TYPE_FLOAT32);
           p->m=corrtype->array;
+          checkblank=0;          /* Magnitude can be NaN: to mask regions. */
           break;
 
         case 1:
@@ -544,7 +552,7 @@ ui_read_cols(struct mkprofparams *p)
       if(corrtype)
         {
           /* Make sure there are no blank values in this column. */
-          if( gal_data_has_blank(corrtype) )
+          if( checkblank && gal_data_has_blank(corrtype) )
             error(EXIT_FAILURE, 0, "%s column has blank values. "
                   "Input columns cannot contain blank values", colname);
 
@@ -619,6 +627,7 @@ static void
 ui_prepare_canvas(struct mkprofparams *p)
 {
   int status=0;
+  float *f, *ff;
   double truncr;
   long width[2]={1,1};
   size_t i, ndim, dsize[2];
@@ -640,11 +649,16 @@ ui_prepare_canvas(struct mkprofparams *p)
                               1, p->cp.minmapsize, NULL, NULL, NULL);
       else
         {
+          /* Read the image. */
           p->out=gal_fits_img_read_to_type(p->backname, p->backhdu,
                                            GAL_DATA_TYPE_FLOAT32,
                                            p->cp.minmapsize);
           p->naxes[0]=p->out->dsize[1];
           p->naxes[1]=p->out->dsize[0];
+
+          /* Set all pixels to zero if the user wanted a clear canvas. */
+          if(p->clearcanvas)
+            {ff=(f=p->out->array)+p->out->size; do *f++=0.0f; while(f<ff);}
         }
 
       /* When a background image is specified, oversample must be 1 and
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index a25a7cc..9a92e15 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -13987,27 +13987,15 @@ will be ignored: @option{--naxis1}, 
@option{--naxis2}, @option{--crpix1},
 @option{--resolution}, @option{--oversample}, and data type (see
 @option{--type} in @ref{Input output}).
 
-The profiles will be built on the image (profile pixel values will be
-summed with the background image pixel values). If you want to use all the
-image information above, except for the pixel values (you want to have a
-blank canvas to build the profiles on, based on an input image), you can
-use @ref{Arithmetic} as below and feed the output into MakeProfiles with
-this option.
-
address@hidden
-$ astarithmetic img.fits 0 "*" --output=bz.fits
address@hidden example
-
-The command above will also preserve all the (possible) blank pixels in the
-image (see @ref{Blank pixels}). In case the input image has blank pixels
-and you want them to be zero too, you can do so with the following command
-(both Arithmetic operations can also be merged into one command, see
address@hidden polish notation}, recall that @option{-o} is the short version
-of @option{--output}, see @ref{Options}):
-
address@hidden
-$ astarithmetic bz.fits bz.fits isblank 0 where -oz.fits
address@hidden example
+The image will act like a canvas to build the profiles on: profile pixel
+values will be summed with the background image pixel values. With the
address@hidden option you can disable this behavior and replace the
+profile pixels with the background pixels. If you want to use all the image
+information above, except for the pixel values (you want to have a blank
+canvas to build the profiles on, based on an input image), you can call
address@hidden, to set all the input image's pixels to zero before
+starting to build the profiles over it (this is done in memory after
+reading the input, so nothing will happen to your input file).
 
 @item -B STR/INT
 @itemx --backhdu=STR/INT
@@ -14047,7 +14035,6 @@ convolution it will be the PSF.
 
 @item -i
 @itemx --individual
-
 @cindex Individual profiles
 @cindex Build individual profiles
 If this option is called, each profile is created in a separate FITS
@@ -14189,6 +14176,20 @@ profile. However, when using flat profiles with the
 address@hidden' option, you should be careful not to give a
 @code{0.0} value as the flat profile's pixel value.
 
address@hidden -C
address@hidden --clearcanvas
+When an input image is specified (with the @option{--background} option,
+set all its pixels to 0.0 immediately after reading it into
+memory. Effectively, this will allow you to use all its properties
+(described under the @option{--background} option), without having to worry
+about the pixel values.
+
address@hidden can come in handy in many situations, for example if
+you want to create a labeled image (segmentation map) for creating a
+catalog (see @ref{MakeCatalog}). In other cases, you might have modeled the
+objects in an image and want to create them on the same frame, but without
+the original pixel values.
+
 @item -w FLT
 @itemx --circumwidth=FLT
 The width of the circumference if the profile is to be an elliptical
@@ -14233,7 +14234,7 @@ Point source with address@hidden' or address@hidden'.
 @item
 Flat profile with address@hidden' or address@hidden'.
 @item
-Circumference profile with address@hidden' or address@hidden'. A fixed
+Circumference profile with address@hidden' or address@hidden'. A fixed
 value will be used for all pixels between the truncation radius
 (@mymath{r_t}) and @mymath{r_t-w} (@mymath{w} is the value to the
 @option{--circumwidth}).
@@ -14625,10 +14626,11 @@ $ GSL_RNG_TYPE="taus" GSL_RNG_SEED=345 astmknoise 
input.fits
 @end example
 
 @noindent
-In this manner the values will only be used for this particular
-execution of MakeNoise. To define them for the full period of your
-terminal session or script length, you can use the shell's
address@hidden command (for a script remove the @code{$} signs):
+In this manner the values will only be used for this particular execution
+of MakeNoise. Alternatively, you can define them for the full period of
+your terminal session or script length, using the shell's @command{export}
+command with the two separate commands below (for a script remove the
address@hidden signs):
 
 @example
 $ export GSL_RNG_TYPE="taus"
@@ -14640,8 +14642,8 @@ $ export GSL_RNG_SEED=345
 @noindent
 The subsequent programs which use GSL's random number generators will hence
 forth use these values in this session of the terminal you are running or
-while executing this script. In case you want set fixed values for these
-variables every time you use the GSL random number generator, you can add
+while executing this script. In case you want to set fixed values for these
+parameters every time you use the GSL random number generator, you can add
 these two lines to your @file{.bashrc} startup address@hidden't forget
 that if you are going to give your scripts (that use the GSL random number
 generator) to others you have to make sure you also tell them to set these
diff --git a/lib/checkset.c b/lib/checkset.c
index 1475f67..5c9ef53 100644
--- a/lib/checkset.c
+++ b/lib/checkset.c
@@ -91,7 +91,7 @@ gal_checkset_malloc_cat(char *inname, char *toappend)
 /* Copy the input string to the output (and also allocate the
    output. */
 void
-gal_checkset_allocate_copy(char *arg, char **copy)
+gal_checkset_allocate_copy(const char *arg, char **copy)
 {
   if(arg)
     {
diff --git a/lib/checkset.h b/lib/checkset.h
index b5a208d..1f33bdc 100644
--- a/lib/checkset.h
+++ b/lib/checkset.h
@@ -74,7 +74,7 @@ char *
 gal_checkset_malloc_cat(char *inname, char *toappend);
 
 void
-gal_checkset_allocate_copy(char *arg, char **copy);
+gal_checkset_allocate_copy(const char *arg, char **copy);
 
 void
 gal_checkset_allocate_copy_set(char *arg, char **copy, int *set);
diff --git a/lib/data.c b/lib/data.c
index 33e6ebb..9087004 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -1810,9 +1810,19 @@ gal_data_t *
 gal_data_copy_to_new_type_free(gal_data_t *in, uint8_t type)
 {
   gal_data_t *out;
-  out=gal_data_copy_to_new_type(in, type);
-  gal_data_free(in);
-  return out;
+
+  /* In a general application, it might happen that the type is equal with
+     the type of the input. Since the job of this function is to free the
+     input data set, so and the user just wants one dataset after this
+     function finishes, we can safely just return the input. */
+  if(type==in->type)
+    return in;
+  else
+    {
+      out=gal_data_copy_to_new_type(in, type);
+      gal_data_free(in);
+      return out;
+    }
 }
 
 
diff --git a/lib/fits.c b/lib/fits.c
index 2c33a4e..b3cb9ca 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -788,7 +788,10 @@ gal_fits_key_read(char *filename, char *hdu, gal_data_t 
*keysll,
 /* Add on keyword to the list of header keywords that need to be added
    to a FITS file. In the end, the keywords will have to be freed, so
    it is important to know before hand if they were allocated or
-   not. If not, they don't need to be freed. */
+   not. If not, they don't need to be freed.
+
+   NOTE FOR STRINGS: the value should be the pointer to the string its-self
+   (char *), not a pointer to a pointer (char **). */
 void
 gal_fits_key_add_to_ll(struct gal_fits_key_ll **list, uint8_t type,
                        char *keyname, int kfree, void *value, int vfree,
diff --git a/lib/options.c b/lib/options.c
index 800ec72..7a69271 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -637,10 +637,10 @@ gal_options_read_check(struct argp_option *option, char 
*arg, char *filename,
         error(EXIT_FAILURE, 0, "A bug! Please contact us at %s to "
               "correct it. Options with no arguments, must have "
               "type `%s' to be read in `gal_options_read_from_key'. "
-              "However, the option with key `%d' has type %s",
+              "However, the `%s' option has type %s",
               PACKAGE_BUGREPORT,
               gal_data_type_as_string(GAL_OPTIONS_NO_ARG_TYPE, 1),
-              option->key, gal_data_type_as_string(option->type, 1));
+              option->name, gal_data_type_as_string(option->type, 1));
     }
 
 
diff --git a/lib/timing.c b/lib/timing.c
index 2736dc8..3517be0 100644
--- a/lib/timing.c
+++ b/lib/timing.c
@@ -23,13 +23,16 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <config.h>
 
 #include <stdio.h>
+#include <stdint.h>
 
 #include "timing.h"
 
 
 
-/* Used to generate random numbers. */
-unsigned long int
+/* Used to generate random numbers, since the type of `tv_sec' and
+   `tv_usec' is `long int' (from the GNU C Library manual), this function
+   will also return a signed 64-bit integer. */
+int64_t
 gal_timing_time_based_rng_seed()
 {
   struct timeval tv;
diff --git a/lib/timing.h b/lib/timing.h
index e19f3e5..b37b18f 100644
--- a/lib/timing.h
+++ b/lib/timing.h
@@ -54,7 +54,7 @@ __BEGIN_C_DECLS  /* From C++ preparations */
 #define GAL_TIMING_VERB_MSG_LENGTHS_2_V  65
 #define GAL_TIMING_VERB_MSG_LENGTHS_2_T "65"
 
-unsigned long int
+int64_t
 gal_timing_time_based_rng_seed();
 
 void
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6489906..f8980fa 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -73,7 +73,7 @@ TESTS = $(check_PROGRAMS) prepconf.sh mkprof/mosaic1.sh 
mkprof/mosaic2.sh  \
   convertt/blankch.sh convertt/jpegtotxt.sh convertt/fitstojpegcmyk.sh     \
   convertt/jpegtofits.sh convertt/fitstopdf.sh convolve/spatial.sh         \
   convolve/frequency.sh warp/warp_scale.sh warp/homographic.sh             \
-  mknoise/addnoise.sh mkprof/ellipticalmasks.sh mkprof/inputascanvas.sh    \
+  mknoise/addnoise.sh mkprof/ellipticalmasks.sh mkprof/clearcanvas.sh      \
   header/write.sh header/print.sh header/update.sh header/delete.sh        \
   statistics/basicstats.sh subtractsky/subtractsky.sh                      \
   noisechisel/noisechisel.sh mkcatalog/simple.sh mkcatalog/aperturephot.sh \
@@ -87,10 +87,10 @@ TESTS = $(check_PROGRAMS) prepconf.sh mkprof/mosaic1.sh 
mkprof/mosaic2.sh  \
 
 
 # Files to distribute along with the tests.
-EXTRA_DIST = $(TESTS) during-dev.sh mkprof/mkprofcat1.txt                   \
-  mkprof/ellipticalmasks.txt mkprof/inputascanvas.txt                       \
-  mkprof/mkprofcat2.txt mkprof/mkprofcat3.txt mkprof/mkprofcat4.txt         \
-  mkprof/radeccat.txt crop/cat.txt table/table.txt
+EXTRA_DIST = $(TESTS) during-dev.sh mkprof/mkprofcat1.txt                 \
+  mkprof/ellipticalmasks.txt mkprof/clearcanvas.txt mkprof/mkprofcat2.txt \
+  mkprof/mkprofcat3.txt mkprof/mkprofcat4.txt mkprof/radeccat.txt         \
+  crop/cat.txt table/table.txt
 
 
 
@@ -154,11 +154,11 @@ convertt/jpegtofits.sh: convertt/blankch.sh.log
 convertt/fitstopdf.sh: crop/section.sh.log
 convolve/spatial.sh: mkprof/mosaic1.sh.log
 convolve/frequency.sh: mkprof/mosaic1.sh.log
-warp/imgwarp_scale.sh: convolve/spatial.sh.log
+warp/warp_scale.sh: convolve/spatial.sh.log
 warp/homographic.sh: convolve/spatial.sh.log
 mknoise/addnoise.sh: warp/warp_scale.sh.log
 mkprof/ellipticalmasks.sh: mknoise/addnoise.sh.log
-mkprof/inputascanvas.sh: mknoise/addnoise.sh.log
+mkprof/clearcanvas.sh: mknoise/addnoise.sh.log
 header/write.sh: mkprof/mosaic1.sh.log
 header/print.sh: header/write.sh.log
 header/update.sh: header/write.sh.log
@@ -168,7 +168,7 @@ subtractsky/subtractsky.sh: mknoise/addnoise.sh.log
 noisechisel/noisechisel.sh: mknoise/addnoise.sh.log
 mkcatalog/simple.sh: noisechisel/noisechisel.sh.log
 mkcatalog/aperturephot.sh: noisechisel/noisechisel.sh.log          \
-                           mkprof/inputascanvas.sh
+                           mkprof/clearcanvas.sh
 arithmetic/snimage.sh: noisechisel/noisechisel.sh.log
 arithmetic/where.sh: noisechisel/noisechisel.sh.log
 arithmetic/or.sh: noisechisel/noisechisel.sh.log
diff --git a/tests/mknoise/addnoise.sh b/tests/mknoise/addnoise.sh
index 62c5e18..a261f52 100755
--- a/tests/mknoise/addnoise.sh
+++ b/tests/mknoise/addnoise.sh
@@ -30,7 +30,7 @@
 prog=mknoise
 img1=convolve_spatial.fits
 execname=../bin/$prog/ast$prog
-img2=convolve_spatial_warped.fits
+img2=convolve_spatial_scaled.fits
 
 
 
diff --git a/tests/mkprof/inputascanvas.sh b/tests/mkprof/clearcanvas.sh
similarity index 88%
rename from tests/mkprof/inputascanvas.sh
rename to tests/mkprof/clearcanvas.sh
index e1f9e98..3b9d0cd 100755
--- a/tests/mkprof/inputascanvas.sh
+++ b/tests/mkprof/clearcanvas.sh
@@ -25,7 +25,7 @@
 prog=mkprof
 execname=../bin/$prog/ast$prog
 img=convolve_spatial_noised.fits
-cat=$topsrc/tests/$prog/inputascanvas.txt
+cat=$topsrc/tests/$prog/clearcanvas.txt
 
 
 
@@ -49,5 +49,5 @@ if [ ! -f $execname ] || [ ! -f $img ]; then exit 77; fi
 
 # Actual test script
 # ==================
-$execname $cat $img --mforflatpix --inputascanvas  \
-          --type=long --output="inputascanvas.fits"
+$execname $cat --background=$img --mforflatpix --clearcanvas  \
+          --type=int32 --output="clearcanvas.fits"
diff --git a/tests/mkprof/clearcanvas.txt b/tests/mkprof/clearcanvas.txt
new file mode 100644
index 0000000..3491f52
--- /dev/null
+++ b/tests/mkprof/clearcanvas.txt
@@ -0,0 +1,16 @@
+# Column 1:  ID                [count, u8]   Object ID
+# Column 2:  X                 [pixel, f64]  X axis position of profile center
+# Column 3:  Y                 [pixel, f64]  Y axis position of profile center
+# Column 4:  Function          [name, str4]  Profile's radial function
+# Column 5:  Width             [pixel, f64]  For Sersic: effective radius, for 
Moffat, FWHM
+# Column 6:  Sersic index      [none, f64]   Sersic index, or Moffat beta
+# Column 7:  Position angle    [deg, f64]    Position angle of profile
+# Column 8:  Axis ratio        [frac, f64]   Axis ratio of profile
+# Column 9:  Magnitude         [ABmag, f64]  Magnitude of profile within 
truncation radius
+# Column 10: Truncation radius [dist, f64]   Truncation radius to stop 
building profile
+#
+# Note that the positions and radii are multiplied by 5 compared to 
`mkprofcat1.txt',
+# because we are using the over-sampled image as a canvas.
+#
+1 502     502     flat 100   1 45.000 1.000  1 2.000
+2 251.605 254.135 flat 29.89 1 77.650 0.801  2 2.000
diff --git a/tests/mkprof/ellipticalmasks.sh b/tests/mkprof/ellipticalmasks.sh
index 59cb124..6d6478b 100755
--- a/tests/mkprof/ellipticalmasks.sh
+++ b/tests/mkprof/ellipticalmasks.sh
@@ -24,7 +24,7 @@
 # file exists (basicchecks.sh is in the source tree).
 prog=mkprof
 execname=../bin/$prog/ast$prog
-img=convolve_spatial_warped_noised.fits
+img=convolve_spatial_scaled_noised.fits
 cat=$topsrc/tests/$prog/ellipticalmasks.txt
 
 
@@ -49,5 +49,5 @@ if [ ! -f $execname ] || [ ! -f $img ]; then exit 77; fi
 
 # Actual test script
 # ==================
-$execname $cat $img --mforflatpix --replace --oversample=1 \
+$execname $cat --background=$img --mforflatpix --replace --oversample=1 \
           --output="ellipticalmasks.fits"
diff --git a/tests/mkprof/ellipticalmasks.txt b/tests/mkprof/ellipticalmasks.txt
index 3f1a20a..f3cf4fd 100644
--- a/tests/mkprof/ellipticalmasks.txt
+++ b/tests/mkprof/ellipticalmasks.txt
@@ -1,12 +1,12 @@
-# Column 0: ID
-# Column 1: X
-# Column 2: Y
-# Column 3: Function (0: Sersic, 1: Moffat, 2: Gaussian, 3: Point).
-# Column 4: Effective radius
-# Column 5: Sersic index.
-# Column 6: Position angle
-# Column 7: Axis ratio
-# Column 8: Magnitude
-# Column 9: Truncation radius
-1     100.40     100.40     5     20.00     2.500      45.000     1.000      
NaN     2.000
-2     50.321     50.827     4     5.978     1.320      77.650     0.801      
-1     2.000
+# Column 1:  ID                [count, u8]   Object ID
+# Column 2:  X                 [pixel, f64]  X axis position of profile center
+# Column 3:  Y                 [pixel, f64]  Y axis position of profile center
+# Column 4:  Function          [name, str7]  Profile's radial function
+# Column 5:  Width             [pixel, f64]  For Sersic: effective radius, for 
Moffat, FWHM
+# Column 6:  Sersic index      [none, f64]   Sersic index, or Moffat beta
+# Column 7:  Position angle    [deg, f64]    Position angle of profile
+# Column 8:  Axis ratio        [frac, f64]   Axis ratio of profile
+# Column 9:  Magnitude         [ABmag, f64]  Magnitude of profile within 
truncation radius
+# Column 10: Truncation radius [dist, f64]   Truncation radius to stop 
building profile
+1     100.40     100.40     circum   20.00     2.500      45.000     1.000     
 NaN     2.000
+2     50.321     50.827     flat     5.978     1.320      77.650     0.801     
 -1     2.000
diff --git a/tests/mkprof/inputascanvas.txt b/tests/mkprof/inputascanvas.txt
deleted file mode 100644
index d32a888..0000000
--- a/tests/mkprof/inputascanvas.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-# Column 0: ID
-# Column 1: X
-# Column 2: Y
-# Column 3: Function (0: Sersic, 1: Moffat, 2: Gaussian, 3: Point).
-# Column 4: Effective radius
-# Column 5: Sersic index.
-# Column 6: Position angle
-# Column 7: Axis ratio
-# Column 8: Magnitude
-# Column 9: Truncation radius
-1 100.40 100.40 4 20.00 1 45.000 1.000  1 2.000
-2 50.321 50.827 4 5.978 1 77.650 0.801  2 2.000
diff --git a/tmpfs-config-make b/tmpfs-config-make
index 1224cb3..09579f4 100755
--- a/tmpfs-config-make
+++ b/tmpfs-config-make
@@ -132,8 +132,9 @@ cd $build_dir
 if [ ! -f Makefile ]; then
     $srcdir/configure --srcdir=$srcdir --disable-shared CFLAGS="-g -O0"      \
                       --enable-arithmetic --enable-convertt --enable-convolve\
-                      --enable-cosmiccal --enable-crop --enable-header       \
-                      --enable-mkprof --enable-table --enable-warp
+                      --enable-cosmiccal  --enable-crop     --enable-header  \
+                      --enable-mknoise    --enable-mkprof   --enable-table   \
+                      --enable-warp
 fi
 
 



reply via email to

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