gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master dec2b22 078/125: ImageCrop works with gal_data


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master dec2b22 078/125: ImageCrop works with gal_data_t features
Date: Sun, 23 Apr 2017 22:36:41 -0400 (EDT)

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

    ImageCrop works with gal_data_t features
    
    ImageCrop now works with all the new features of `gal_data_t', and the
    option management system. Some new features were also added. This is a very
    large set of changes, so everything will be discussed as the list below:
    
    ImageCrop:
    
     - ImageCrop doesn't have separate `--imgmode' and `--wcsmode'
       options. There is now one `--mode' option which takes two values: `img'
       and `wcs'. This was both useful from the user's perspective and from the
       developer's prespective.
    
     - In the output of `--help' the options have become much better organized
       and classified compared to before.
    
     - ImageCrop can now read the name of the crop based on the value in a
       given column (task #14101).
    
     - In many cases, the old `naxes[2]' array (which was in log type and FITS
       order) was replaced by the new `dsize[2]' array of `gal_data_t' which is
       in C format and has the `size_t' type. This was done because slowly we
       will be completely removing the use of `naxes[2]' outside of
       `gnuastro/fits.c'. When programming in C, it is much less buggy and more
       clear if things follow the C standard.
    
     - Like MakeProfiles, the log file is now created by a linked list of
       `gal_data_t' structures and is written by the new library function
       `gal_options_print_log' function.
    
     - ImageCrop test scripts and test catalog were updated to be usable with
       the new features.
    
    Rest of Gnuastro:
    
     - The old `cite.h' files have been updated to `authors-cite' in all the
       progams, to facilitate porting them later.
    
     - Writing a log file has many common issues between the different
       programs, so based on what we had written for MakeProfiles, a new
       `gal_options_print_log' function was created and after filling in the
       log-file information, programs can just define comments, and this
       function will do the job of making a standard log file.
    
     - The new `gal_options_print_log' is now also used in MakeProfiles.
    
     - arXiv:1611.06387 was added as a citation for the MakeProfiles program.
    
     - In order to use size_t types safely, we a new `GAL_CONFIG_SIZEOF_SIZE_T'
       has been defined in `configure.ac'. Using this macro, we now have a new
       `GAL_DATA_TYPE_SIZE_T' which will be replaced by the appropriate type
       for 32 and 64 bit systems.
    
     - With the usage of `size_t' type options (thanks to the
       `GAL_DATA_TYPE_SIZE_T' macro above) the old default binary operator
       types weren't enough to do integer-only binary operators. So now,
       `unsigned long' type is also one of the default types for binary
       operators.
    
     - Just as a sanity check, a test was also added for integer-only binary
       operators: when the larger compiled type is no longer an integer, it
       will abort with an error.
    
     - `gal_data_copy_to_new_type' will now also copy a number type data-set to
       a string data-set and vice-versa. Several new static functions were
       added to `lib/data.c' to make this easily possible.
    
     - `gal_data_write_to_string' is a new function to print the value in a
       pointer into a string. It came from the `options_print_any_type'
       function from configuration file printing, but was useful in other
       places too, so it was brought out to use easily.
    
     - The new `gal_table_too_many_columns' function is now in charge of
       printing an error for users who give too many columns for a program.
    
     - The new `GAL_OPTIONS_RANGE_0_OR_ODD' range was defined to accept 0 and
       odd numbers.
    
    This finishes task #14101.
---
 bin/TEMPLATE/{cite.h => authors-cite.h}    |   32 +-
 bin/convertt/{cite.h => authors-cite.h}    |   30 +-
 bin/convolve/{cite.h => authors-cite.h}    |   32 +-
 bin/imgcrop/args.h                         |  653 +++++++---------
 bin/imgcrop/astimgcrop.conf                |   16 +-
 bin/imgcrop/{cite.h => authors-cite.h}     |   30 +-
 bin/imgcrop/crop.c                         |  287 +++----
 bin/imgcrop/crop.h                         |   18 +-
 bin/imgcrop/imgcrop.c                      |  254 +++++--
 bin/imgcrop/main.c                         |    6 +-
 bin/imgcrop/main.h                         |  187 ++---
 bin/imgcrop/ui.c                           | 1142 +++++++++++++++-------------
 bin/imgcrop/ui.h                           |   10 +-
 bin/imgcrop/wcsmode.c                      |   88 ++-
 bin/imgcrop/wcsmode.h                      |    2 +-
 bin/imgstat/{cite.h => authors-cite.h}     |   30 +-
 bin/imgwarp/{cite.h => authors-cite.h}     |   30 +-
 bin/mkcatalog/authors-cite.h               |   54 ++
 bin/mkcatalog/cite.h                       |   38 -
 bin/mknoise/{cite.h => authors-cite.h}     |   30 +-
 bin/mkprof/args.h                          |    2 +-
 bin/mkprof/mkprof.c                        |   47 +-
 bin/mkprof/ui.c                            |   28 +-
 bin/noisechisel/{cite.h => authors-cite.h} |   30 +-
 bin/subtractsky/{cite.h => authors-cite.h} |   30 +-
 bin/table/main.c                           |    2 +-
 bin/table/ui.c                             |    4 +-
 bin/table/ui.h                             |    2 +-
 configure.ac                               |   13 +-
 doc/gnuastro.texi                          |   80 +-
 lib/Makefile.am                            |    1 +
 lib/arithmetic-binary.c                    |    2 +-
 lib/arithmetic-onlyint.c                   |   17 +-
 lib/commonopts.h                           |    7 +-
 lib/config.h.in                            |    1 +
 lib/data.c                                 |  327 +++++++-
 lib/fits.c                                 |    5 +-
 lib/gnuastro/data.h                        |   38 +-
 lib/gnuastro/table.h                       |    3 +
 lib/options.c                              |  136 ++--
 lib/options.h                              |   10 +
 lib/table.c                                |   24 +
 tests/imgcrop/cat.txt                      |    9 +-
 tests/imgcrop/imgcat.sh                    |    4 +-
 tests/imgcrop/imgoutpolygon.sh             |    2 +-
 tests/imgcrop/imgpolygon.sh                |    2 +-
 tests/imgcrop/wcscat.sh                    |    3 +-
 tests/imgcrop/wcspolygon.sh                |    2 +-
 tmpfs-config-make                          |    2 +-
 49 files changed, 2078 insertions(+), 1724 deletions(-)

diff --git a/bin/TEMPLATE/cite.h b/bin/TEMPLATE/authors-cite.h
similarity index 64%
rename from bin/TEMPLATE/cite.h
rename to bin/TEMPLATE/authors-cite.h
index c57e149..33d40d3 100644
--- a/bin/TEMPLATE/cite.h
+++ b/bin/TEMPLATE/authors-cite.h
@@ -13,9 +13,9 @@ TEMPLATE - Source code for a blank utility for easy creation 
of new
 TEMPLATE is part of GNU Astronomy Utilities (Gnuastro) package.
 
 Original author:
-     Your name <address@hidden>
+     Mohammad Akhlaghi <address@hidden>
 Contributing author(s):
-Copyright (C) YYYY, Free Software Foundation, Inc.
+Copyright (C) 2017, 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
@@ -30,19 +30,19 @@ 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 CITE_H
-#define CITE_H
-
-#define TEMPLATEBIBTEX ""
-
-#define PRINTCITEABORT {                                                \
-    printf("\nWe hope %s has been useful for your research.\n"          \
-           "Citations are vital for the continued work on %s.\n"        \
-           "Thank you for citing it in your research paper.\n"          \
-           "\nPlease cite as \"%s\":\n\n%s\n\n%s",                      \
-           SPACK_NAME, SPACK_NAME, SPACK_STRING,                        \
-           GAL_STRINGS_MAIN_BIBTEX, TEMPLATEBIBTEX);                    \
-    exit(EXIT_SUCCESS);                                                 \
-  }
+#ifndef AUTHORS_CITE_H
+#define AUTHORS_CITE_H
+
+/* When any specific citation is necessary, please add its BibTeX (from ADS
+   hopefully) to this variable along with a title decribing what this
+   paper/book does for the progarm in a short line. In the following line
+   put a row of `-' with the same length and then put the BibTeX.
+
+   See the `gnuastro_bibtex' variable in `lib/options' (from the top
+   Gnuastro source code directory) as an example.*/
+
+#define PROGRAM_BIBTEX "";
+
+#define PROGRAM_AUTHORS "Mohammad Akhlaghi";
 
 #endif
diff --git a/bin/convertt/cite.h b/bin/convertt/authors-cite.h
similarity index 57%
rename from bin/convertt/cite.h
rename to bin/convertt/authors-cite.h
index 2a98ece..376124f 100644
--- a/bin/convertt/cite.h
+++ b/bin/convertt/authors-cite.h
@@ -5,7 +5,7 @@ ConvertType 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) 2017, 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
@@ -20,19 +20,19 @@ 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 CITE_H
-#define CITE_H
-
-#define CONVERTTBIBTEX ""
-
-#define PRINTCITEABORT {                                                \
-    printf("\nWe hope %s has been useful for your research.\n"          \
-           "Citations are vital for the continued work on %s.\n"        \
-           "Thank you for citing it in your research paper.\n"          \
-           "\nPlease cite as \"%s\":\n\n%s\n\n%s",                      \
-           SPACK_NAME, SPACK_NAME, SPACK_STRING,                        \
-           GAL_STRINGS_MAIN_BIBTEX, CONVERTTBIBTEX);                    \
-    exit(EXIT_SUCCESS);                                                 \
-}
+#ifndef AUTHORS_CITE_H
+#define AUTHORS_CITE_H
+
+/* When any specific citation is necessary, please add its BibTeX (from ADS
+   hopefully) to this variable along with a title decribing what this
+   paper/book does for the progarm in a short line. In the following line
+   put a row of `-' with the same length and then put the BibTeX.
+
+   See the `gnuastro_bibtex' variable in `lib/options' (from the top
+   Gnuastro source code directory) as an example.*/
+
+#define PROGRAM_BIBTEX "";
+
+#define PROGRAM_AUTHORS "Mohammad Akhlaghi";
 
 #endif
diff --git a/bin/convolve/cite.h b/bin/convolve/authors-cite.h
similarity index 57%
rename from bin/convolve/cite.h
rename to bin/convolve/authors-cite.h
index 1139592..6d526a1 100644
--- a/bin/convolve/cite.h
+++ b/bin/convolve/authors-cite.h
@@ -5,7 +5,7 @@ Convolve 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) 2017, 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
@@ -18,21 +18,21 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See 
the GNU
 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/>.x
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
 **********************************************************************/
-#ifndef CITE_H
-#define CITE_H
-
-#define CONVOLVEBIBTEX ""
-
-#define PRINTCITEABORT {                                                \
-    printf("\nWe hope %s has been useful for your research.\n"          \
-           "Citations are vital for the continued work on %s.\n"        \
-           "Thank you for citing it in your research paper.\n"          \
-           "\nPlease cite as \"%s\":\n\n%s\n\n%s",                      \
-           SPACK_NAME, SPACK_NAME, SPACK_STRING,                        \
-           GAL_STRINGS_MAIN_BIBTEX, CONVOLVEBIBTEX);                    \
-    exit(EXIT_SUCCESS);                                                 \
-}
+#ifndef AUTHORS_CITE_H
+#define AUTHORS_CITE_H
+
+/* When any specific citation is necessary, please add its BibTeX (from ADS
+   hopefully) to this variable along with a title decribing what this
+   paper/book does for the progarm in a short line. In the following line
+   put a row of `-' with the same length and then put the BibTeX.
+
+   See the `gnuastro_bibtex' variable in `lib/options' (from the top
+   Gnuastro source code directory) as an example.*/
+
+#define PROGRAM_BIBTEX "";
+
+#define PROGRAM_AUTHORS "Mohammad Akhlaghi";
 
 #endif
diff --git a/bin/imgcrop/args.h b/bin/imgcrop/args.h
index 1f75a1e..00cfda2 100644
--- a/bin/imgcrop/args.h
+++ b/bin/imgcrop/args.h
@@ -5,7 +5,7 @@ ImageCrop 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,113 +23,83 @@ 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[] = "[ASCIIcatalog] ASTRdata ...";
-
-
-
-
-
-const char doc[] =
-  /* Before the list of options: */
-  GAL_STRINGS_TOP_HELP_INFO
-  SPACK_NAME" will create cutouts, thumbnails, postage stamps or crops of "
-  "region(s) from input image(s) using image or celestial coordinates. "
-  "If muliple crops are desired, a catalog must be provided. When in WCS "
-  "mode, if the cut out covers more than one input image, all overlapping "
-  "input images will be stitched in the output.\n"
-  GAL_STRINGS_MORE_HELP_INFO
-  /* After the list of options: */
-  "\v"
-  PACKAGE_NAME" home page: "PACKAGE_URL;
-
-
-
-
-
-/* Available letters for short options:
-
-   e k m n t u v
-   A B C E F G H J L M O Q R T U X Y Z
-
-   Number keys used<=502
-
-   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[] =
   {
+    /* Input. */
     {
-      0, 0, 0, 0,
-      "Operating modes:",
-      -1
+      "hstartwcs",
+      ARGS_OPTION_KEY_HSTARTWCS,
+      "INT",
+      0,
+      "Header keyword number to start reading WCS.",
+      GAL_OPTIONS_GROUP_INPUT,
+      &p->hstartwcs,
+      GAL_DATA_TYPE_SIZE_T,
+      GAL_OPTIONS_RANGE_GE_0,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
-      "imgmode",
-      'I',
-      0,
+      "hendwcs",
+      ARGS_OPTION_KEY_HENDWCS,
+      "INT",
       0,
-      "Use image coordinates (x and y).",
-      -1
+      "Header keyword number to stop reading WCS.",
+      GAL_OPTIONS_GROUP_INPUT,
+      &p->hendwcs,
+      GAL_DATA_TYPE_SIZE_T,
+      GAL_OPTIONS_RANGE_GE_0,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
-      "wcsmode",
-      'W',
+      "zeroisnotblank",
+      ARGS_OPTION_KEY_ZEROISNOTBLANK,
       0,
       0,
-      "Use WCS coordinates (Ra and Dec).",
-      -1
+      "0.0 in float or double images are not blank.",
+      GAL_OPTIONS_GROUP_INPUT,
+      &p->zeroisnotblank,
+      GAL_OPTIONS_NO_ARG_TYPE,
+      GAL_OPTIONS_RANGE_0_OR_1,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
 
 
 
 
-
-
-    {
-      0, 0, 0, 0,
-      "Input:",
-      1
-    },
+    /* Output. */
     {
-      "hstartwcs",
-      501,
-      "INT",
+      "noblank",
+      ARGS_OPTION_KEY_NOBLANK,
       0,
-      "Header keyword number to start reading WCS.",
-      1
+      0,
+      "Remove parts of the crop box out of input image.",
+      GAL_OPTIONS_GROUP_OUTPUT,
+      &p->noblank,
+      GAL_OPTIONS_NO_ARG_TYPE,
+      GAL_OPTIONS_RANGE_0_OR_1,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
-      "hendwcs",
-      502,
-      "INT",
+      "suffix",
+      ARGS_OPTION_KEY_SUFFIX,
+      "STR",
       0,
-      "Header keyword number to stop reading WCS.",
-      1
+      "Suffix (postfix) of cropped images.",
+      GAL_OPTIONS_GROUP_OUTPUT,
+      &p->suffix,
+      GAL_DATA_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
 
 
@@ -138,32 +108,47 @@ static struct argp_option options[] =
 
     {
       0, 0, 0, 0,
-      "Output:",
-      2
+      "Crop by center (general settings)",
+      ARGS_GROUP_CENTER_GENERAL
     },
     {
-      "noblank",
-      'b',
-      0,
+      "checkcenter",
+      ARGS_OPTION_KEY_CHECKCENTER,
+      "INT",
       0,
-      "Remove parts of the crop box out of input image.",
-      2
+      "Width (in pixels) of box at center to check.",
+      ARGS_GROUP_CENTER_GENERAL,
+      &p->checkcenter,
+      GAL_DATA_TYPE_SIZE_T,
+      GAL_OPTIONS_RANGE_0_OR_ODD,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
-      "checkcenter",
-      'c',
+      "iwidth",
+      ARGS_OPTION_KEY_IWIDTH,
       "INT",
       0,
-      "Side of box (in pixels) to check.",
-      2
+      "Width (pixels) when crop defined by X,Y.",
+      ARGS_GROUP_CENTER_GENERAL,
+      &p->iwidthin,
+      GAL_DATA_TYPE_SIZE_T,
+      GAL_OPTIONS_RANGE_GT_0_ODD,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
-      "suffix",
-      'p',
-      "STR",
+      "wwidth",
+      ARGS_OPTION_KEY_WWIDTH,
+      "FLT",
       0,
-      "Suffix (postfix) of cropped images.",
-      2
+      "Width (arcseconds) for crops defined by RA,Dec.",
+      ARGS_GROUP_CENTER_GENERAL,
+      &p->wwidth,
+      GAL_DATA_TYPE_DOUBLE,
+      GAL_OPTIONS_RANGE_GT_0,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
 
 
@@ -172,347 +157,259 @@ static struct argp_option options[] =
 
     {
       0, 0, 0, 0,
-      "Crop:",
-      3
+      "Crop by center (single crop)",
+      ARGS_GROUP_CENTER_SINGLE
     },
     {
-      "racol",
-      'f',
-      "INT",
+      "ra",
+      ARGS_OPTION_KEY_RA,
+      "FLT",
       0,
-      "Column of Right Ascension (RA) in catalog.",
-      3
+      "Right ascension of one crop box center.",
+      ARGS_GROUP_CENTER_SINGLE,
+      &p->ra,
+      GAL_DATA_TYPE_DOUBLE,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
-      "deccol",
-      'g',
-      "INT",
+      "dec",
+      ARGS_OPTION_KEY_DEC,
+      "FLT",
       0,
-      "Column of Declination (Dec) in catalog.",
-      3
+      "Declination of one crop box center.",
+      ARGS_GROUP_CENTER_SINGLE,
+      &p->dec,
+      GAL_DATA_TYPE_DOUBLE,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
-      "ra",
-      'r',
+      "xc",
+      ARGS_OPTION_KEY_XC,
       "FLT",
       0,
-      "Right ascension of one crop box center.",
-      3
+      "First axis position of one crop box center.",
+      ARGS_GROUP_CENTER_SINGLE,
+      &p->xc,
+      GAL_DATA_TYPE_DOUBLE,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
-      "dec",
-      'd',
+      "yc",
+      ARGS_OPTION_KEY_YC,
       "FLT",
       0,
-      "Declination of one crop box center.",
-      3
+      "Second axis position of one crop box center.",
+      ARGS_GROUP_CENTER_SINGLE,
+      &p->yc,
+      GAL_DATA_TYPE_DOUBLE,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
+
+
+
+
+
+
+
+    {
+      0, 0, 0, 0,
+      "Crop by center (catalog)",
+      ARGS_GROUP_CENTER_CATALOG
     },
     {
-      "xcol",
-      'i',
-      "INT",
+      "catalog",
+      ARGS_OPTION_KEY_CATALOG,
+      "STR",
       0,
-      "Column of X (first FITS axis) value in catalog.",
-      3
+      "Input catalog filename.",
+      ARGS_GROUP_CENTER_CATALOG,
+      &p->catname,
+      GAL_DATA_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
-      "ycol",
-      'j',
-      "INT",
+      "cathdu",
+      ARGS_OPTION_KEY_CATHDU,
+      "STR/INT",
       0,
-      "Column of Y (second FITS axis) in catalog.",
-      3
+      "HDU of catalog, if it is a FITS table.",
+      ARGS_GROUP_CENTER_CATALOG,
+      &p->cathdu,
+      GAL_DATA_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
-      "xc",
-      'x',
-      "FLT",
+      "namecol",
+      ARGS_OPTION_KEY_NAMECOL,
+      "STR/INT",
       0,
-      "First axis position for only one crop.",
-      3
+      "Column no./info of crop filename (no suffix).",
+      ARGS_GROUP_CENTER_CATALOG,
+      &p->namecol,
+      GAL_DATA_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
-      "yc",
-      'y',
-      "FLT",
+      "racol",
+      ARGS_OPTION_KEY_RACOL,
+      "STR/INT",
       0,
-      "Second axis position for only one crop.",
-      3,
+      "Column number/info of Right Ascension (RA).",
+      ARGS_GROUP_CENTER_CATALOG,
+      &p->racol,
+      GAL_DATA_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
-      "iwidth",
-      'a',
-      "INT",
+      "deccol",
+      ARGS_OPTION_KEY_DECCOL,
+      "STR/INT",
       0,
-      "Image mode width (in pixels).",
-      3
+      "Column number/info of Declination.",
+      ARGS_GROUP_CENTER_CATALOG,
+      &p->deccol,
+      GAL_DATA_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
-      "wwidth",
-      'w',
-      "FLT",
+      "xcol",
+      ARGS_OPTION_KEY_XCOL,
+      "STR/INT",
       0,
-      "WCS mode width (in arc seconds).",
-      3
+      "Column number/info of X (first FITS axis).",
+      ARGS_GROUP_CENTER_CATALOG,
+      &p->xcol,
+      GAL_DATA_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
+    {
+      "ycol",
+      ARGS_OPTION_KEY_YCOL,
+      "STR/INT",
+      0,
+      "Column number/info of Y (second FITS axis).",
+      ARGS_GROUP_CENTER_CATALOG,
+      &p->ycol,
+      GAL_DATA_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
+
+
+
+
+
+    {
+      0, 0, 0, 0,
+      "Crop by region",
+      ARGS_GROUP_REGION
     },
     {
       "section",
-      's',
+      ARGS_OPTION_KEY_SECTION,
       "STR",
       0,
       "Image section string specifying crop range.",
-      3
+      ARGS_GROUP_REGION,
+      &p->section,
+      GAL_DATA_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
       "polygon",
-      'l',
+      ARGS_OPTION_KEY_POLYGON,
       "STR",
       0,
-      "Polygon vertices of region to crop.",
-      3
+      "Polygon vertices of region to crop, keep inside.",
+      ARGS_GROUP_REGION,
+      &p->polygon,
+      GAL_DATA_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
     {
       "outpolygon",
-      500,
+      ARGS_OPTION_KEY_OUTPOLYGON,
       0,
       0,
       "Keep the polygon's outside, mask the inside.",
-      3
-    },
-    {
-      "zeroisnotblank",
-      'z',
-      0,
-      0,
-      "0.0 in float or double images are not blank.",
-      3
+      ARGS_GROUP_REGION,
+      &p->outpolygon,
+      GAL_OPTIONS_NO_ARG_TYPE,
+      GAL_OPTIONS_RANGE_0_OR_1,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
     },
 
 
 
-    {0}
-  };
 
 
 
+    /* Operating mode */
+    {
+      "mode",
+      ARGS_OPTION_KEY_MODE,
+      "STR",
+      0,
+      "Coordinate mode `img' or `wcs'",
+      GAL_OPTIONS_GROUP_OPERATING_MODE,
+      &p->modestr,
+      GAL_DATA_TYPE_STRING,
+      GAL_OPTIONS_RANGE_ANY,
+      GAL_OPTIONS_NOT_MANDATORY,
+      GAL_OPTIONS_NOT_SET
+    },
 
 
-/* Parse a single option: */
-static error_t
-parse_opt(int key, char *arg, struct argp_state *state)
-{
-  /* A temporary variable. */
-  size_t tmp;
-
-  /* Save the arguments structure: */
-  struct imgcropparams *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)
-    {
 
-    /* Operating modes: */
-    case 'I':
-      if(p->up.imgmodeset)
-        argp_error(state, "only one of Image or WCS modes can be chosen");
-      p->imgmode=1;
-      p->wcsmode=0;
-      p->up.imgmodeset=p->up.wcsmodeset=1;
-      break;
-    case 'W':
-      if(p->up.wcsmodeset)
-        argp_error(state, "only one of Image or WCS modes can be chosen");
-      p->imgmode=0;
-      p->wcsmode=1;
-      p->up.imgmodeset=p->up.wcsmodeset=1;
-      break;
-
-
-
-
-
-    /* Input */
-    case 501:
-      gal_checkset_sizet_el_zero(arg, &p->hstartwcs, "hstartwcs", key, SPACK,
-                                 NULL, 0);
-      p->up.hstartwcsset=1;
-      break;
-    case 502:
-      gal_checkset_sizet_el_zero(arg, &p->hendwcs, "hendwcs", key, SPACK,
-                                 NULL, 0);
-      p->up.hendwcsset=1;
-      break;
-
-
-
-
-
-    /* Output parameters: */
-    case 'b':
-      p->noblank=1;
-      break;
-    case 'c':
-      gal_checkset_sizet_el_zero(arg, &p->checkcenter, "checkcenter",
-                                 key, SPACK, NULL, 0);
-      p->up.checkcenterset=1;
-      break;
-    case 'p':
-      gal_checkset_allocate_copy_set(arg, &p->suffix, &p->up.suffixset);
-      break;
-
-
-
-
-
-    /* Crop: */
-    case 'f':
-      gal_checkset_sizet_el_zero(arg, &p->racol, "racol", key, SPACK,
-                                 NULL, 0);
-      p->up.racolset=1;
-      break;
-    case 'g':
-      gal_checkset_sizet_el_zero(arg, &p->deccol, "deccol", key, SPACK,
-                                 NULL, 0);
-      p->up.deccolset=1;
-      break;
-    case 'r':
-      gal_checkset_any_double(arg, &p->ra, "ra", key, SPACK, NULL, 0);
-      p->up.raset=1;
-      break;
-    case 'd':
-      gal_checkset_any_double(arg, &p->dec, "dec", key, SPACK, NULL, 0);
-      p->up.decset=1;
-      break;
-    case 'i':
-      gal_checkset_sizet_el_zero(arg, &p->xcol, "xcol", key, SPACK, NULL, 0);
-      p->up.xcolset=1;
-      break;
-    case 'j':
-      gal_checkset_sizet_el_zero(arg, &p->ycol, "ycol", key, SPACK, NULL, 0);
-      p->up.ycolset=1;
-      break;
-    case 'x':
-      gal_checkset_any_double(arg, &p->xc, "xc", key, SPACK, NULL, 0);
-      p->up.xcset=1;            /* Using FITS standard, not C. */
-      break;
-    case 'y':
-      gal_checkset_any_double(arg, &p->yc, "yc", key, SPACK, NULL, 0);
-      p->up.ycset=1;            /* Using FITS standard, not C. */
-      break;
-    case 'a':
-      gal_checkset_sizet_l_zero(arg, &tmp, "iwidth", key, SPACK, NULL, 0);
-      p->iwidth[0]=p->iwidth[1]=tmp;
-      p->up.iwidthset=1;
-      break;
-    case 'w':
-      gal_checkset_double_l_0(arg, &p->wwidth, "wwidth", key, SPACK,
-                              NULL, 0);
-      p->up.wwidthset=1;
-      break;
-    case 's':
-      p->section=arg;
-      p->up.sectionset=1;
-      break;
-    case 'l':
-      p->up.polygon=arg;
-      p->up.polygonset=1;
-      break;
-    case 500:
-      p->outpolygon=1;
-      break;
-    case 'z':
-      p->zeroisnotblank=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) )
-        {
-          gal_linkedlist_add_to_stll(&p->up.gal_linkedlist_stll, arg);
-          ++p->numimg;
-        }
-      else
-        {
-          if(p->up.catname)
-            argp_error(state, "only one catalog file can be given");
-          else
-            {
-              p->up.catname=arg;
-              p->up.catset=1;
-            }
-        }
-      break;
-
-
-
-
-
-    /* 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.catname==NULL && !(p->up.xcset    || p->up.ycset
-                                      || p->up.raset || p->up.decset
-                                      || p->up.sectionset
-                                      || p->up.polygonset))
-            argp_error(state, "no catalog provided");
-          if(p->up.gal_linkedlist_stll==NULL)
-            argp_error(state, "no 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}
+
+    {0}
   };
 
 
 
 
 
-/* Basic structure defining the whole argument reading process. */
-static struct argp thisargp = {options, parse_opt, args_doc,
-                               doc, children, NULL, NULL};
+/* Define the child argp structure. */
+struct argp
+gal_options_common_child = {gal_commonopts_options,
+                            gal_options_common_argp_parse,
+                            NULL, NULL, NULL, 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/imgcrop/astimgcrop.conf b/bin/imgcrop/astimgcrop.conf
index c2fb09b..99abf3b 100644
--- a/bin/imgcrop/astimgcrop.conf
+++ b/bin/imgcrop/astimgcrop.conf
@@ -17,21 +17,19 @@
 # notice and this notice are preserved.  This file is offered as-is,
 # without any warranty.
 
-# Operating mode:
- imgmode        0
- wcsmode        1
-
 # Input image and catalog parameters:
  hdu            0
- xcol           1
- ycol           2
+ cathdu         1
  iwidth         201
- racol          3
- deccol         4
  wwidth         3
  hstartwcs      0
  hendwcs        0
 
 # Output parameters:
  checkcenter    0
- suffix        _cropped.fits
+ suffix         _cropped.fits
+
+# Operating mode:
+ mode          wcs
+ searchin      name
+ minmapsize    1000000000
\ No newline at end of file
diff --git a/bin/imgcrop/cite.h b/bin/imgcrop/authors-cite.h
similarity index 57%
rename from bin/imgcrop/cite.h
rename to bin/imgcrop/authors-cite.h
index 9987c8b..276c0f4 100644
--- a/bin/imgcrop/cite.h
+++ b/bin/imgcrop/authors-cite.h
@@ -5,7 +5,7 @@ ImageCrop 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) 2017, 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
@@ -20,19 +20,19 @@ 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 CITE_H
-#define CITE_H
-
-#define IMGCROPBIBTEX ""
-
-#define PRINTCITEABORT {                                                \
-    printf("\nWe hope %s has been useful for your research.\n"          \
-           "Citations are vital for the continued work on %s.\n"        \
-           "Thank you for citing it in your research paper.\n"          \
-           "\nPlease cite as \"%s\":\n\n%s\n\n%s",                      \
-           SPACK_NAME, SPACK_NAME, SPACK_STRING,                        \
-           GAL_STRINGS_MAIN_BIBTEX, IMGCROPBIBTEX);                     \
-    exit(EXIT_SUCCESS);                                                 \
-}
+#ifndef AUTHORS_CITE_H
+#define AUTHORS_CITE_H
+
+/* When any specific citation is necessary, please add its BibTeX (from ADS
+   hopefully) to this variable along with a title decribing what this
+   paper/book does for the progarm in a short line. In the following line
+   put a row of `-' with the same length and then put the BibTeX.
+
+   See the `gnuastro_bibtex' variable in `lib/options' (from the top
+   Gnuastro source code directory) as an example.*/
+
+#define PROGRAM_BIBTEX "";
+
+#define PROGRAM_AUTHORS "Mohammad Akhlaghi";
 
 #endif
diff --git a/bin/imgcrop/crop.c b/bin/imgcrop/crop.c
index 1f0f5d1..317dcf8 100644
--- a/bin/imgcrop/crop.c
+++ b/bin/imgcrop/crop.c
@@ -71,7 +71,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 /* Read the section string and set the starting and ending pixels
    based on that. */
 void
-sectionparser(struct imgcropparams *p, long *naxes,
+sectionparser(struct imgcropparams *p, size_t *dsize,
               long *fpixel, long *lpixel)
 {
   int add;
@@ -79,6 +79,7 @@ sectionparser(struct imgcropparams *p, long *naxes,
   size_t dim=0;
   char *tailptr;
   char forl='f', *pt=p->section;
+  long naxes[2]={dsize[1], dsize[0]};
 
   /* If control reached here, then the cropped region is not defined by its
      center. So it makes no sense to check if the center is blank. */
@@ -175,13 +176,13 @@ sectionparser(struct imgcropparams *p, long *naxes,
 
 
 void
-polygonparser(struct imgcropparams *p)
+crop_polygonparser(struct imgcropparams *p)
 {
   size_t dim=0;
   char *tailptr;
   double read[2], *array;
   struct gal_linkedlist_tdll *gal_linkedlist_tdll=NULL;
-  char *pt=p->up.polygon;
+  char *pt=p->polygon;
 
   /* If control reached here, then the cropped region is not defined by its
      center. So it makes no sense to check if the center is blank. */
@@ -195,13 +196,13 @@ polygonparser(struct imgcropparams *p)
         case ',':
           ++dim;
           if(dim==2)
-            error(EXIT_FAILURE, 0, "Extra `,` in `%s`", p->up.polygon);
+            error(EXIT_FAILURE, 0, "Extra `,` in `%s`", p->polygon);
           ++pt;
           break;
         case ':':
           if(dim==0)
             error(EXIT_FAILURE, 0, "not enough coordinates for at least "
-                  "one polygon vertex (in %s)", p->up.polygon);
+                  "one polygon vertex (in %s)", p->polygon);
           dim=0;
           ++pt;
           break;
@@ -256,8 +257,8 @@ polygonparser(struct imgcropparams *p)
   /* Convert the linked list to an array: */
   gal_linkedlist_tdll_to_array_inv(gal_linkedlist_tdll, &array,
                                    &p->nvertices);
-  if(p->imgmode) { p->ipolygon=array; p->wpolygon=NULL;  }
-  else           { p->ipolygon=NULL;  p->wpolygon=array; }
+  if(p->mode==IMGCROP_MODE_IMG) { p->ipolygon=array; p->wpolygon=NULL;  }
+  else                          { p->ipolygon=NULL;  p->wpolygon=array; }
 
   /* Put them in the proper order in WCS mode: */
 
@@ -313,11 +314,11 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
   long *lb, *la=array;
   short *sb, *sa=array;
   float *fb, *fa=array;
+  int type=crp->p->type;
   LONGLONG *Lb, *La=array;
   unsigned char *bb, *ba=array;
   int outpolygon=crp->p->outpolygon;
   double *db, *ipolygon, point[2], *da=array;
-  int type=gal_fits_datatype_to_type(crp->p->datatype);
   size_t i, *ordinds, size=s0*s1, nvertices=crp->p->nvertices;
 
 
@@ -443,21 +444,21 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
 /******************          One crop.         *********************/
 /*******************************************************************/
 void
-changezerotonan(void *array, size_t size, int bitpix)
+changezerotonan(void *array, size_t size, int type)
 {
   float *fp, *ffp;
   double *dp, *fdp;
 
-  switch(bitpix)
+  switch(type)
     {
-    case FLOAT_IMG:
+    case GAL_DATA_TYPE_FLOAT:
       ffp=(fp=array)+size;
       do
         if(*fp==0.0f) *fp=NAN;
       while(++fp<ffp);
       break;
 
-    case DOUBLE_IMG:
+    case GAL_DATA_TYPE_DOUBLE:
       fdp=(dp=array)+size;
       do
         if(*dp==0.0f) *dp=NAN;
@@ -465,10 +466,8 @@ changezerotonan(void *array, size_t size, int bitpix)
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "in changezerotonan, bitpix is not "
-            "recognized! This is out of the users control and is a bug, "
-            "please report it to us so we see how it was caused and fix "
-            "it");
+      error(EXIT_FAILURE, 0, "%d is not a recognized type in "
+            "`changezerotonan'", type);
     }
 }
 
@@ -481,34 +480,40 @@ changezerotonan(void *array, size_t size, int bitpix)
 void
 cropname(struct cropparams *crp)
 {
+  char **strarr;
   struct imgcropparams *p=crp->p;
-  struct gal_commonparams *cp=&p->cp;
-  struct imgcroplog *log=&crp->p->log[crp->outindex];
+  struct gal_options_common_params *cp=&p->cp;
 
   /* Set the output name and crop sides: */
-  if(p->up.catset)
+  if(p->catname)
     {
-      errno=0;
-      log->name=malloc(crp->outlen);
-      if(log->name==NULL)
-        error(EXIT_FAILURE, errno, "imgmode.c, %zu bytes on "
-              "imgcroponthreads", crp->outlen);
-      sprintf(log->name, "%s%zu%s", cp->output, crp->outindex+1,
-              p->suffix);
-      gal_checkset_check_remove_file(log->name, cp->dontdelete);
+      /* If a name column was set, use it, otherwise, use the ID of the
+         profile. */
+      if(p->name)
+        {
+          strarr=p->name;
+          asprintf(&crp->name, "%s%s%s", cp->output, strarr[crp->out_ind],
+                   p->suffix);
+        }
+      else
+        asprintf(&crp->name, "%s%zu%s", cp->output, crp->out_ind+1,
+                 p->suffix);
+
+      /* Make sure the file doesn't exist. */
+      gal_checkset_check_remove_file(crp->name, cp->dontdelete);
     }
   else
     {
       /* Set the output name. */
       if(p->outnameisfile)            /* An output file was specified. */
         {
-          log->name=cp->output;
-          gal_checkset_check_remove_file(log->name, cp->dontdelete);
+          crp->name=cp->output;
+          gal_checkset_check_remove_file(crp->name, cp->dontdelete);
         }
       else          /* The output was a directory, use automatic output. */
-        gal_checkset_automatic_output(p->imgs[crp->imgindex].name,
-                                      p->suffix, cp->removedirinfo,
-                                      cp->dontdelete, &log->name);
+        crp->name=gal_checkset_automatic_output(cp,
+                                                p->imgs[crp->in_ind].name,
+                                                p->suffix);
     }
 }
 
@@ -523,21 +528,22 @@ cropflpixel(struct cropparams *crp)
 {
   struct imgcropparams *p=crp->p;
   int ncoord=1, nelem=2, status[2]={0,0};
-  long *naxes=p->imgs[crp->imgindex].naxes;
+  size_t *dsize=p->imgs[crp->in_ind].dsize;
   double pixcrd[2], imgcrd[2], phi[1], theta[1];
   long *fpixel=crp->fpixel, *lpixel=crp->lpixel;
 
-  if(p->imgmode)
+  switch(p->mode)
     {
-      if(p->up.catset)
-        gal_box_border_from_center(p->cat[crp->outindex*p->cs1+p->xcol],
-                                   p->cat[crp->outindex*p->cs1+p->ycol],
+
+    case IMGCROP_MODE_IMG:
+      if(p->catname)
+        gal_box_border_from_center(p->c1[crp->out_ind], p->c2[crp->out_ind],
                                    p->iwidth, fpixel, lpixel);
-      else if(p->up.xcset)
+      else if(!isnan(p->xc))
         gal_box_border_from_center(p->xc, p->yc, p->iwidth, fpixel, lpixel);
-      else if(p->up.sectionset)
-        sectionparser(p, naxes, fpixel, lpixel);
-      else if(p->up.polygonset)
+      else if(p->section)
+        sectionparser(p, dsize, fpixel, lpixel);
+      else if(p->polygon)
         {
           if(p->outpolygon==0)
             imgpolygonflpixel(p->ipolygon, p->nvertices, fpixel, lpixel);
@@ -549,18 +555,19 @@ cropflpixel(struct cropparams *crp)
               "to see how it got to this impossible place! You should "
               "have been warned of this condition long before ImageCrop "
               "reaches this point");
-    }
-  else if(p->wcsmode) /* In wcsmode, crp->world is already filled.       */
-    {                 /* Note that p->iwidth was set based on p->wwidth. */
-      if(p->up.polygonset)
-        { /* Fill crp->ipolygon in wcspolygonpixel, then set flpixel*/
+      break;
+
+    case IMGCROP_MODE_WCS: /* In wcsmode, crp->world is already filled.   */
+      if(p->polygon)       /* Note: p->iwidth was set based on p->wwidth. */
+        {
+          /* Fill crp->ipolygon in wcspolygonpixel, then set flpixel*/
           fillcrpipolygon(crp);
           if(p->outpolygon==0)
             imgpolygonflpixel(crp->ipolygon, p->nvertices, fpixel, lpixel);
         }
       else
         {
-          if(wcss2p(p->imgs[crp->imgindex].wcs, ncoord, nelem, crp->world,
+          if(wcss2p(p->imgs[crp->in_ind].wcs, ncoord, nelem, crp->world,
                     phi, theta, imgcrd, pixcrd, status) )
             if(status[0] || status[1])
               error(EXIT_FAILURE, 0, "wcss2p error %d: %s",
@@ -573,19 +580,21 @@ cropflpixel(struct cropparams *crp)
                    pixcrd[1], fpixel[0], fpixel[1], lpixel[0], lpixel[1]);
           */
         }
+      break;
+
+    default:
+      error(EXIT_FAILURE, 0, "a bug! in cropflpixel (crop.c), "
+            "neither imgmode or wcsmode are set. Please contact us so "
+            "we can see how it got to this impossible place");
     }
-  else
-    error(EXIT_FAILURE, 0, "a bug! in cropflpixel (crop.c), "
-          "neither imgmode or wcsmode are set. Please contact us so "
-          "we can see how it got to this impossible place");
 
   /* If the user only wants regions outside to the polygon, then set
      the fpixel and lpixel to cover the full input image. */
-  if(p->up.polygonset && p->outpolygon)
+  if(p->polygon && p->outpolygon)
     {
-      crp->lpixel[0]=naxes[0];
-      crp->lpixel[1]=naxes[1];
       crp->fpixel[0]=crp->fpixel[1]=1;
+      crp->lpixel[0]=dsize[1];
+      crp->lpixel[1]=dsize[0];
     }
 }
 
@@ -610,13 +619,13 @@ firstcropmakearray(struct cropparams *crp, long *fpixel_i,
   size_t i;
   fitsfile *ofp;
   long naxes[2];
+  int type=crp->p->type;
   double crpix0, crpix1;
   int naxis=2, status=0;
-  int bitpix=crp->p->bitpix;
+  char *outname=crp->name;
   char *cp, *cpf, blankrec[80], titlerec[80];
   char startblank[]="                      / ";
-  char *outname=crp->p->log[crp->outindex].name;
-  struct inputimgs *img=&crp->p->imgs[crp->imgindex];
+  struct inputimgs *img=&crp->p->imgs[crp->in_ind];
 
 
   /* Set the last element of the blank array. */
@@ -627,7 +636,7 @@ firstcropmakearray(struct cropparams *crp, long *fpixel_i,
 
 
   /* Set the size of the output, in WCS mode, noblank==0. */
-  if(crp->p->noblank && crp->p->wcsmode==0)
+  if(crp->p->noblank && crp->p->mode==IMGCROP_MODE_IMG)
     {
       fpixel_c[0]=fpixel_c[1]=1;
       lpixel_c[0]=naxes[0]=lpixel_i[0]-fpixel_i[0]+1;
@@ -645,11 +654,11 @@ firstcropmakearray(struct cropparams *crp, long *fpixel_i,
   if(fits_create_file(&crp->outfits, outname, &status))
     gal_fits_io_error(status, "creating file");
   ofp=crp->outfits;
-  if(fits_create_img(ofp, bitpix, naxis, naxes, &status))
+  if( fits_create_img(ofp, gal_fits_type_to_bitpix(type),
+                      naxis, naxes, &status) )
     gal_fits_io_error(status, "creating image");
-  if(bitpix==BYTE_IMG || bitpix==SHORT_IMG
-     || bitpix==LONG_IMG || bitpix==LONGLONG_IMG)
-    if(fits_write_key(ofp, crp->p->datatype, "BLANK",
+  if( type!=GAL_DATA_TYPE_FLOAT && type!=GAL_DATA_TYPE_DOUBLE )
+    if(fits_write_key(ofp, gal_fits_type_to_datatype(crp->p->type), "BLANK",
                       crp->p->bitnul, "pixels with no data", &status) )
       gal_fits_io_error(status, "adding Blank");
   if(fits_write_null_img(ofp, 1, naxes[0]*naxes[1], &status))
@@ -701,17 +710,17 @@ void
 onecrop(struct cropparams *crp)
 {
   struct imgcropparams *p=crp->p;
-  struct inputimgs *img=&p->imgs[crp->imgindex];
+  struct inputimgs *img=&p->imgs[crp->in_ind];
 
   void *array;
   size_t cropsize;
+  int status=0, anynul=0;
   char basename[FLEN_KEYWORD];
-  long fpixel_i[2] , lpixel_i[2];
   fitsfile *ifp=crp->infits, *ofp;
   struct gal_fits_key_ll *headers=NULL;
-  int status=0, anynul=0, bitpix=p->bitpix;
   long fpixel_o[2], lpixel_o[2], inc[2]={1,1};
   char region[FLEN_VALUE], regionkey[FLEN_KEYWORD];
+  long naxes[]={img->dsize[1], img->dsize[0]}, fpixel_i[2] , lpixel_i[2];
 
 
   /* Find the first and last pixel of this crop box from this input
@@ -723,7 +732,7 @@ onecrop(struct cropparams *crp)
 
 
   /* Find the overlap and apply it if there is any overlap. */
-  if( gal_box_overlap(img->naxes, fpixel_i, lpixel_i, fpixel_o, lpixel_o) )
+  if( gal_box_overlap(naxes, fpixel_i, lpixel_i, fpixel_o, lpixel_o) )
     {
       /* Make the output FITS image and initialize it with an array of
          NaN or BLANK values. Note that for FLOAT_IMG and DOUBLE_IMG,
@@ -735,11 +744,12 @@ onecrop(struct cropparams *crp)
 
       /* Read the desired part of the image, then write it into this
          array. */
-      cropsize=(lpixel_i[0]-fpixel_i[0]+1)*(lpixel_i[1]-fpixel_i[1]+1);
-      array=gal_data_alloc(gal_fits_datatype_to_type(p->datatype), cropsize);
       status=0;
-      if(fits_read_subset(ifp, p->datatype, fpixel_i, lpixel_i, inc,
-                          p->bitnul, array, &anynul, &status))
+      cropsize=(lpixel_i[0]-fpixel_i[0]+1)*(lpixel_i[1]-fpixel_i[1]+1);
+      array=gal_data_malloc_array(p->type, cropsize);
+      if(fits_read_subset(ifp, gal_fits_type_to_datatype(p->type),
+                          fpixel_i, lpixel_i, inc, p->bitnul, array,
+                          &anynul, &status))
         gal_fits_io_error(status, NULL);
 
 
@@ -747,34 +757,34 @@ onecrop(struct cropparams *crp)
          value should actually be a NaN. Unless the user specificly
          asks for it, make the conversion.*/
       if(p->zeroisnotblank==0
-         && (bitpix==FLOAT_IMG || bitpix==DOUBLE_IMG) )
-        changezerotonan(array, cropsize, bitpix);
+         && (p->type==GAL_DATA_TYPE_FLOAT || p->type==GAL_DATA_TYPE_DOUBLE) )
+        changezerotonan(array, cropsize, p->type);
 
 
       /* If a polygon is given, remove all the pixels within or
          outside of it.*/
-      if(p->up.polygonset)
+      if(p->polygon)
         {
           /* In WCS mode, crp->ipolygon was allocated and filled in
              wcspolygonflpixel (wcsmode.c). */
-          if(p->imgmode) crp->ipolygon=p->ipolygon;
+          if(p->mode==IMGCROP_MODE_IMG) crp->ipolygon=p->ipolygon;
           polygonmask(crp, array, fpixel_i, lpixel_i[1]-fpixel_i[1]+1,
                       lpixel_i[0]-fpixel_i[0]+1);
-          if(p->wcsmode) free(crp->ipolygon);
+          if(p->mode==IMGCROP_MODE_WCS) free(crp->ipolygon);
         }
 
 
       /* Write the array into the image. */
       status=0;
-      if( fits_write_subset(ofp, p->datatype, fpixel_o, lpixel_o,
-                            array, &status) )
+      if( fits_write_subset(ofp, gal_fits_type_to_datatype(p->type),
+                            fpixel_o, lpixel_o, array, &status) )
         gal_fits_io_error(status, NULL);
 
 
       /* A section has been added to the cropped image from this input
          image, so increment crp->imgcount and save the information of
          this image. */
-      sprintf(basename, "ICF%zu", ++p->log[crp->outindex].numimg);
+      sprintf(basename, "ICF%zu", ++crp->numimg);
       gal_fits_file_name_in_keywords(basename, img->name, &headers);
       sprintf(regionkey, "%sPIX", basename);
       sprintf(region, "%ld:%ld,%ld:%ld", fpixel_i[0], lpixel_i[0],
@@ -789,7 +799,7 @@ onecrop(struct cropparams *crp)
       free(array);
     }
   else
-    if(p->up.polygonset && p->outpolygon==0 && p->wcsmode)
+    if(p->polygon && p->outpolygon==0 && p->mode==IMGCROP_MODE_WCS)
       free(crp->ipolygon);
 
 
@@ -823,18 +833,20 @@ iscenterfilled(struct cropparams *crp)
 {
   struct imgcropparams *p=crp->p;
 
-  size_t size;
   void *array;
+  size_t size, ndim, *dsize;
   fitsfile *ofp=crp->outfits;
+  int status=0, anynul=0, type;
   long checkcenter=p->checkcenter;
-  int status=0, anynul=0, tmp_bitpix;
   long naxes[2], fpixel[2], lpixel[2], inc[2]={1,1};
 
   /* If checkcenter is zero, then don't check. */
-  if(checkcenter==0) return CENTER_NOT_CHECKED;
+  if(checkcenter==0) return GAL_DATA_BLANK_UCHAR;
 
   /* Get the final size of the output image. */
-  gal_fits_img_bitpix_size(ofp, &tmp_bitpix, naxes);
+  gal_fits_img_info(ofp, &type, &ndim, &dsize);
+  naxes[0]=dsize[1];
+  naxes[1]=dsize[0];
 
   /* Get the size and range of the central region to check. The +1 is
      because in FITS, counting begins from 1, not zero. It might happen
@@ -855,9 +867,9 @@ iscenterfilled(struct cropparams *crp)
   */
 
   /* Allocate the array and read in the pixels. */
-  array=gal_data_alloc(gal_fits_bitpix_to_type(bitpix), size);
-  if( fits_read_subset(ofp, p->datatype, fpixel, lpixel, inc,
-                       p->bitnul, array, &anynul, &status) )
+  array=gal_data_malloc_array(type, size);
+  if( fits_read_subset(ofp, gal_fits_type_to_datatype(type), fpixel, lpixel,
+                       inc, p->bitnul, array, &anynul, &status) )
     gal_fits_io_error(status, NULL);
   free(array);
 
@@ -866,106 +878,3 @@ iscenterfilled(struct cropparams *crp)
      of this function is just the inverse of that number. */
   return !anynul;
 }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/*******************************************************************/
-/******************          Log file          *********************/
-/*******************************************************************/
-void
-printlog(struct imgcropparams *p)
-{
-  size_t i;
-  FILE *logfile;
-  struct imgcroplog *log=p->log;
-  char msg[GAL_TIMING_VERB_MSG_LENGTH_V];
-  size_t numfiles=0, numcentfilled=0, numstitched=0;
-
-  /* Only for a catalog are these statistics worth it! */
-  if(p->up.catset && p->cp.verb)
-    for(i=0;log[i].name;++i)
-      if(log[i].numimg)
-        {
-          if(log[i].centerfilled)
-            {
-              ++numfiles;
-              if(log[i].numimg>1)
-                ++numstitched;
-            }
-          if(log[i].centerfilled)
-            ++numcentfilled;
-        }
-
-  /* Check to see if the file exists and remove if if it is ok. */
-  gal_checkset_check_remove_file(LOGFILENAME, p->cp.dontdelete);
-
-  /* Make the file and print the top comments. If the file can't be
-     opened for write mode, there is no problem, this is a log file,
-     the user can set it on verbose mode and the same information will
-     be printed. */
-  errno=0;
-  logfile=fopen(LOGFILENAME, "w");
-  if(logfile)
-    {
-      /* First print the comments to the file. */
-      fprintf(logfile,
-              "# "SPACK_STRING" log file.\n"
-              "# "SPACK_NAME" was run on %s#\n",
-              ctime(&p->rawtime));
-      if(p->checkcenter)
-        fprintf(logfile,
-                "# The central %zu pixels were checked for blank values.\n"
-                "# NOTE: by default when the crops are defined by "
-                "their center,\n"
-                "# crops with a blank center are deleted.\n"
-                "# To keep such images, run again with `--checkcenter=0`.\n"
-                "#\n", p->checkcenter);
-      fprintf(logfile,
-              "# Column 1: Output file name.\n"
-              "# Column 2: Number of images used in this cropped image.\n"
-              "# Column 3: Are the central pixels filled? (1: yes, 0: no, "
-              "%d: not checked)\n", CENTER_NOT_CHECKED);
-
-      /* Then print each output's information. */
-      for(i=0;log[i].name;++i)
-        fprintf(logfile, "%s     %-8zu%-2d\n", log[i].name,
-                log[i].numimg, log[i].centerfilled);
-
-      /* Report Summary: */
-      if(p->cp.verb && p->up.catset)
-        {
-          sprintf(msg, "%zu images created.", numfiles);
-          gal_timing_report(NULL, msg, 1);
-          sprintf(msg, "%zu filled in the center.",
-                  numcentfilled);
-          gal_timing_report(NULL, msg, 1);
-          if(numstitched)
-            {
-              sprintf(msg, "%zu used more than one input.",
-                      numstitched);
-              gal_timing_report(NULL, msg, 1);
-            }
-        }
-
-      /* Close the file. */
-      errno=0;
-      if(fclose(logfile))
-        error(EXIT_FAILURE, errno, LOGFILENAME" could not be closed");
-    }
-}
diff --git a/bin/imgcrop/crop.h b/bin/imgcrop/crop.h
index 908e87c..4cfcadb 100644
--- a/bin/imgcrop/crop.h
+++ b/bin/imgcrop/crop.h
@@ -35,32 +35,32 @@ struct cropparams
   struct imgcropparams *p;
 
   /* About input image. */
-  size_t        imgindex;  /* Index of this image in the input names.  */
+  size_t          in_ind;  /* Index of this image in the input names.  */
   fitsfile       *infits;  /* Pointer to the input FITS image.         */
   long         fpixel[2];  /* Position of first pixel in input image.  */
   long         lpixel[2];  /* Position of last pixel in input image.   */
   double       *ipolygon;  /* Input image based polygon vertices.      */
 
   /* Output (cropped) image. */
+  size_t         out_ind;  /* Index of this crop in the output list.   */
   double        world[2];  /* World coordinates of crop center.        */
   double        sized[2];  /* Width and height of image in degrees.    */
   double      corners[8];  /* RA and Dec of this crop's four sides.    */
   double  equatorcorr[2];  /* Crop crosses the equator, see wcsmode.c. */
-  size_t          outlen;  /* Length of output name.                   */
-  size_t        outindex;  /* Index of this crop in the output list.   */
   fitsfile      *outfits;  /* Pointer to the output FITS image.        */
 
+  /* For log */
+  char             *name;  /* Filename of crop.                        */
+  size_t          numimg;  /* Number of images used to make this crop. */
+  unsigned char centerfilled;   /* ==1 if the center is filled.        */
+
   /* Thread parameters. */
   size_t         *indexs;  /* Indexs to be used in this thread.        */
   pthread_barrier_t   *b;  /* pthread barrier to keep threads waiting. */
 };
 
 void
-polygonparser(struct imgcropparams *p);
-
-void
-sectionparser(struct imgcropparams *p, long *naxes,
-              long *fpixel, long *lpixel);
+crop_polygonparser(struct imgcropparams *p);
 
 void
 cropname(struct cropparams *crp);
@@ -75,6 +75,6 @@ int
 iscenterfilled(struct cropparams *crp);
 
 void
-printlog(struct imgcropparams *p);
+crop_print_log(struct imgcropparams *p);
 
 #endif
diff --git a/bin/imgcrop/imgcrop.c b/bin/imgcrop/imgcrop.c
index 61055d3..65a3a4c 100644
--- a/bin/imgcrop/imgcrop.c
+++ b/bin/imgcrop/imgcrop.c
@@ -53,24 +53,26 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
    file should be used for checking the outputs, not the outputs printed on
    the screen. */
 void
-reportcrop(struct imgcroplog *log)
+imgcrop_verbose_info(struct cropparams *crp)
 {
   char *filestatus, *msg;
-  size_t outnamelen=strlen(log->name);;
+  size_t outnamelen=strlen(crp->name);;
 
   /* Human readable values. */
-  filestatus = ( log->centerfilled==0
-                 ? "not created (blank center)" : "created");
+  filestatus = ( crp->centerfilled==0
+                 ? ( crp->numimg == 0
+                     ? "no overlap"
+                     : "removed (blank center)" )
+                 : "created");
 
   /* Define the output string based on the length of the output file. */
   if ( outnamelen > FILENAME_BUFFER_IN_VERB )
-    asprintf(&msg, "...%s %s from %zu input%s.",
-            &log->name[ outnamelen - FILENAME_BUFFER_IN_VERB + 3 ],
-            filestatus, log->numimg, log->numimg > 1 ? "s" : "");
+    asprintf(&msg, "...%s %s: %zu input%s.",
+             &crp->name[ outnamelen - FILENAME_BUFFER_IN_VERB + 3 ],
+             filestatus, crp->numimg, crp->numimg==1 ?  "" :"s");
   else
-    asprintf(&msg, "%-" MACROSTR(FILENAME_BUFFER_IN_VERB) "s %s from %zu "
-             "input%s.", log->name, filestatus, log->numimg,
-             log->numimg > 1 ? "s" : "");
+    asprintf(&msg, "%-*s %s: %zu input%s.", FILENAME_BUFFER_IN_VERB,
+             crp->name, filestatus, crp->numimg, crp->numimg==1 ? "" : "s");
 
   /* Print the results. */
   gal_timing_report(NULL, msg, 2);
@@ -81,64 +83,166 @@ reportcrop(struct imgcroplog *log)
 
 
 
+/* Print final statistics in verbose mode. */
+void
+imgcrop_verbose_final(struct imgcropparams *p)
+{
+  char *msg;
+  gal_data_t *tmp;
+  size_t i, counter=0, numcrops=0, numstitched=0, numcfilled=0;
+
+  /* This function is only useful in verbose (non-quiet) mode. */
+  if(p->cp.quiet) return;
+
+  /* The information is only available if the user asks for a log file. */
+  if(p->catname && p->log)
+    {
+      /* Get the basic counts. */
+      for(tmp=p->log; tmp!=NULL; tmp=tmp->next)
+        switch(++counter)
+          {
+          case 2:
+            for(i=0;i<p->numout;++i)
+              if( ((unsigned short *)(tmp->array))[i] > 1) ++numstitched;
+            break;
+          case 3:
+            /* When the center wasn't checked it has a value of -1, and
+               when it was checked and the center was filled, it has a
+               value of 1. So if `array[i]==0', we know that the file was
+               removed. */
+            for(i=0;i<p->numout;++i)
+              {
+                if( ((unsigned char *)(tmp->array))[i] )      ++numcrops;
+                if( ((unsigned char *)(tmp->array))[i] == 1 ) ++numcfilled;
+              }
+
+            break;
+          }
+
+      /* Print the basic information. */
+      asprintf(&msg, "%zu crops created.", numcrops);
+      gal_timing_report(NULL, msg, 1);
+      free(msg);
+
+      /* Only if the user wanted to check the center. */
+      if(p->checkcenter)
+        {
+          asprintf(&msg, "%zu filled in the center.",
+                   numcfilled);
+          gal_timing_report(NULL, msg, 1);
+          free(msg);
+        }
+
+      /* Only if there were stitched images. */
+      if(numstitched)
+        {
+          asprintf(&msg, "%zu crops used more than one input.",
+                  numstitched);
+          gal_timing_report(NULL, msg, 1);
+          free(msg);
+        }
+    }
+
+}
+
+
+
+
+
+void
+imgcrop_write_to_log(struct cropparams *crp)
+{
+  char **strarr;
+  gal_data_t *tmp;
+  size_t counter=0;
+
+  for(tmp=crp->p->log; tmp!=NULL; tmp=tmp->next)
+    {
+      switch(++counter)
+        {
+        case 1:
+          strarr=tmp->array;
+          gal_checkset_allocate_copy(crp->name, &strarr[crp->out_ind]);
+          break;
+
+        case 2:
+          ((unsigned short *)(tmp->array))[crp->out_ind]=crp->numimg;
+          break;
+
+        case 3:
+          ((unsigned char *)(tmp->array))[crp->out_ind]=crp->centerfilled;
+          break;
+
+        default:
+          error(EXIT_FAILURE, 0, "a bug! Please contact us at %s to fix the "
+                "problem. For some reason `counter' has become %zu in "
+                "`imgcrop_write_to_log'", PACKAGE_BUGREPORT, counter);
+        }
+    }
+}
+
+
+
+
+
 void *
 imgmodecrop(void *inparam)
 {
   struct cropparams *crp=(struct cropparams *)inparam;
   struct imgcropparams *p=crp->p;
-  struct gal_commonparams *cp=&p->cp;
 
   size_t i;
   int status;
   struct inputimgs *img;
-  struct imgcroplog *log;
 
   /* In image mode, we always only have one image. */
-  crp->imgindex=0;
+  crp->in_ind=0;
 
   /* The whole catalog is from one image, so you can get the
      information here:*/
-  img=&p->imgs[crp->imgindex];
-  gal_fits_read_hdu(img->name, cp->hdu, 0, &crp->infits);
+  img=&p->imgs[crp->in_ind];
+  crp->infits=gal_fits_read_hdu(img->name, p->cp.hdu, 0);
 
   /* Go over all the outputs that are assigned to this thread: */
   for(i=0;crp->indexs[i]!=GAL_THREADS_NON_THRD_INDEX;++i)
     {
       /* Set all the output parameters: */
-      crp->outindex=crp->indexs[i];
-      log=&p->log[crp->outindex];
+      crp->out_ind=crp->indexs[i];
       crp->outfits=NULL;
-      log->numimg=0;
+      crp->numimg=0;
       cropname(crp);
 
       /* Crop the image. */
       onecrop(crp);
 
       /* Check the final output: */
-      if(log->numimg)
+      if(crp->numimg)
         {
           /* Check if the center of the crop is filled or not. */
-          log->centerfilled=iscenterfilled(crp);
+          crp->centerfilled=iscenterfilled(crp);
 
           /* Add the final headers and close output FITS image: */
-          gal_fits_write_keys_version(crp->outfits, NULL, SPACK_STRING);
+          gal_fits_write_keys_version(crp->outfits, NULL, PROGRAM_STRING);
           status=0;
           if( fits_close_file(crp->outfits, &status) )
             gal_fits_io_error(status, "CFITSIO could not close "
                                    "the opened file");
 
           /* Remove the output image if its center was not filled. */
-          if(log->centerfilled==0)
+          if(crp->centerfilled==0)
             {
               errno=0;
-              if(unlink(log->name))
-                error(EXIT_FAILURE, errno, "%s", log->name);
+              if(unlink(crp->name))
+                error(EXIT_FAILURE, errno, "can't delet %s (center"
+                      "was blank)", crp->name);
             }
+
         }
-      else log->centerfilled=0;
+      else crp->centerfilled=0;
 
       /* Report the status on stdout if verbose mode is requested. */
-      if(cp->verb) reportcrop(log);
+      if(!p->cp.quiet) imgcrop_verbose_info(crp);
+      if(p->cp.log)    imgcrop_write_to_log(crp);
     }
 
   /* Close the input image. */
@@ -148,7 +252,7 @@ imgmodecrop(void *inparam)
                       "not close FITS file");
 
   /* Wait until all other threads finish. */
-  if(cp->numthreads>1)
+  if(p->cp.numthreads>1)
     pthread_barrier_wait(crp->b);
 
   return NULL;
@@ -165,18 +269,17 @@ wcsmodecrop(void *inparam)
   struct imgcropparams *p=crp->p;
 
   size_t i;
-  int status, tcatset=0;
-  struct imgcroplog *log;
+  int status;
+
 
   /* Go over all the output objects for this thread. */
   for(i=0;crp->indexs[i]!=GAL_THREADS_NON_THRD_INDEX;++i)
     {
       /* Set all the output parameters: */
-      crp->outindex=crp->indexs[i];
-      log=&p->log[crp->outindex];
+      crp->out_ind=crp->indexs[i];
       crp->outfits=NULL;
-      log->name=NULL;
-      log->numimg=0;
+      crp->name=NULL;
+      crp->numimg=0;
 
 
       /* Set the sides of the crop in RA and Dec */
@@ -185,57 +288,58 @@ wcsmodecrop(void *inparam)
 
       /* Go over all the images to see if this target is within their
          range or not. */
-      crp->imgindex=0;
+      crp->in_ind=0;
       do
         if(radecoverlap(crp))
           {
-            gal_fits_read_hdu(p->imgs[crp->imgindex].name, p->cp.hdu,
-                              0, &crp->infits);
+            /* Open the input FITS file. */
+            crp->infits=gal_fits_read_hdu(p->imgs[crp->in_ind].name,
+                                          p->cp.hdu, 0);
 
-            if(log->name==NULL) cropname(crp);
+            /* If a name isn't set yet, set it. */
+            if(crp->name==NULL) cropname(crp);
 
+            /* Do the crop. */
             onecrop(crp);
 
+            /* Close the file. */
             status=0;
             if( fits_close_file(crp->infits, &status) )
               gal_fits_io_error(status, "imgmode.c: imgcroponthreads "
                                      "could not close FITS file");
           }
-      while ( ++(crp->imgindex) < p->numimg );
+      while ( ++(crp->in_ind) < p->numin );
 
 
       /* Check the final output: */
-      if(log->numimg)
+      if(crp->numimg)
         {
-          log->centerfilled=iscenterfilled(crp);
+          crp->centerfilled=iscenterfilled(crp);
 
-          gal_fits_write_keys_version(crp->outfits, NULL, SPACK_STRING);
+          gal_fits_write_keys_version(crp->outfits, NULL, PROGRAM_STRING);
           status=0;
           if( fits_close_file(crp->outfits, &status) )
             gal_fits_io_error(status, "CFITSIO could not close the "
                                      "opened file");
 
-          if(log->centerfilled==0)
+          if(crp->centerfilled==0)
             {
               errno=0;
-              if(unlink(log->name))
-                error(EXIT_FAILURE, errno, "%s", log->name);
+              if(unlink(crp->name))
+                error(EXIT_FAILURE, errno, "%s", crp->name);
             }
         }
       else
         {
-          if(p->up.catset==0)    /* Trick cropname into making a catalog */
-            {                    /* So we have a name for log report.    */
-              tcatset=1;
-              p->up.catset=1;
-            }
           cropname(crp);
-          if(tcatset) p->up.catset=0;
-          log->centerfilled=0;
+          crp->centerfilled=0;
         }
 
+
+
       /* Report the status on stdout if verbose mode is requested. */
-      if(p->cp.verb) reportcrop(log);
+      if(!p->cp.quiet) imgcrop_verbose_info(crp);
+      if(p->cp.log)    imgcrop_write_to_log(crp);
     }
 
   /* Wait until all other threads finish, then return. */
@@ -274,6 +378,7 @@ void
 imgcrop(struct imgcropparams *p)
 {
   int err=0;
+  char *comments;
   pthread_t t; /* We don't use the thread id, so all are saved here. */
   pthread_attr_t attr;
   pthread_barrier_t b;
@@ -282,15 +387,10 @@ imgcrop(struct imgcropparams *p)
   size_t nt=p->cp.numthreads, nb;
   void *(*modefunction)(void *)=NULL;
 
+
   /* Set the function to run: */
-  if(p->imgmode)
-    modefunction=&imgmodecrop;
-  else if(p->wcsmode)
-    modefunction=&wcsmodecrop;
-  else
-    error(EXIT_FAILURE, 0, "a bug! Somehow in imgcrop (imgcrop.c), "
-          "neither the imgmode is on or the wcsmode! Please contact us "
-          "so we can fix it, thanks");
+  modefunction = p->mode==IMGCROP_MODE_IMG ? &imgmodecrop : &wcsmodecrop;
+
 
   /* Allocate the array of structures to keep the thread and parameters for
      each thread. */
@@ -301,15 +401,9 @@ imgcrop(struct imgcropparams *p)
           "%zu bytes in imgcrop (imgcrop.c) for crp", nt*sizeof *crp);
 
 
-  /* Get the length of the output, no reasonable integer can have more
-     than 50 characters! Since this is fixed for all the threads and
-     images, we will just find it once here. */
-  crp[0].outlen=strlen(p->cp.output)+strlen(p->suffix)+50;
-
-
   /* Distribute the indexs into the threads (this is needed even if we
      only have one object where p->cs0 is not defined): */
-  gal_threads_dist_in_threads(p->up.catset ? p->cs0 : 1, nt,
+  gal_threads_dist_in_threads(p->catname ? p->numout : 1, nt,
                               &indexs, &thrdcols);
 
 
@@ -327,8 +421,8 @@ imgcrop(struct imgcropparams *p)
          (that spinns off the nt threads) is also a thread, so the
          number the barrier should be one more than the number of
          threads spinned off. */
-      if(p->cs0<nt) nb=p->cs0+1;
-      else          nb=nt+1;
+      if(p->numout<nt) nb=p->numout+1;
+      else             nb=nt+1;
       gal_threads_attr_barrier_init(&attr, &b, nb);
 
       /* Spin off the threads: */
@@ -337,7 +431,6 @@ imgcrop(struct imgcropparams *p)
           {
             crp[i].p=p;
             crp[i].b=&b;
-            crp[i].outlen=crp[0].outlen;
             crp[i].indexs=&indexs[i*thrdcols];
             err=pthread_create(&t, &attr, modefunction, &crp[i]);
             if(err)
@@ -351,12 +444,21 @@ imgcrop(struct imgcropparams *p)
     }
 
 
-  /* Print the log file: */
-  if(!p->cp.nolog)
-    printlog(p);
-
+  /* Print the log file. */
+  if(p->cp.log)
+    {
+      if(p->checkcenter)
+        asprintf(&comments, "# Width of central check box: %zu\n#",
+                 p->checkcenter);
+      else
+        comments=NULL;
+      gal_options_print_log(p->log, PROGRAM_STRING, &p->rawtime, comments,
+                            LOGFILENAME, &p->cp);
+      if(comments) free(comments);
+    }
 
-  /* Clean up. */
-  free(crp);
+  /* Print the final verbose info, save log, and clean up: */
+  imgcrop_verbose_final(p);
   free(indexs);
+  free(crp);
 }
diff --git a/bin/imgcrop/main.c b/bin/imgcrop/main.c
index ad3942a..0f2ef09 100644
--- a/bin/imgcrop/main.c
+++ b/bin/imgcrop/main.c
@@ -36,20 +36,20 @@ int
 main (int argc, char *argv[])
 {
   struct timeval t1;
-  struct imgcropparams p={{0}, {0}, 0};
+  struct imgcropparams 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 Image Crop */
   imgcrop(&p);
 
   /* Free all non-freed allocations. */
-  freeandreport(&p, &t1);
+  ui_free_report(&p, &t1);
 
   /* Return successfully.*/
   return EXIT_SUCCESS;
diff --git a/bin/imgcrop/main.h b/bin/imgcrop/main.h
index 8e92004..9e1a921 100644
--- a/bin/imgcrop/main.h
+++ b/bin/imgcrop/main.h
@@ -5,7 +5,7 @@ ImageCrop 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,50 +23,34 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #ifndef MAIN_H
 #define MAIN_H
 
+/* Include necessary headers */
+#include <gnuastro/data.h>
 
-#include <gnuastro/fits.h>
-#include <gnuastro/linkedlist.h>
+#include <options.h>
 
-#include <commonparams.h>
+/* Progarm names.  */
+#define PROGRAM_NAME "ImageCrop"     /* Program full name.       */
+#define PROGRAM_EXEC "astimgcrop"    /* Program executable name. */
+#define PROGRAM_STRING PROGRAM_NAME" (" PACKAGE_NAME ") " PACKAGE_VERSION
 
 
 
-/* Progarm name macros: */
-#define SPACK           "astimgcrop" /* Subpackage executable name. */
-#define SPACK_NAME      "ImageCrop"  /* Subpackage full name.       */
-#define SPACK_STRING    SPACK_NAME" ("PACKAGE_NAME") "PACKAGE_VERSION
-#define LOGFILENAME     SPACK".log"
 
 
-
-
-
-/* Set the maximum length given to a file name when run in verbose
-   mode. The STR macro function is used to convert the numerical macro
-   value into a string (which is necessary). STR_HELPER(x) uses the C
-   pre-processor's "stringification" functionality. See the
-   "Stringification" section of the GNU C Pre-Processor manual for a
-   thorough explanation. Note that this is part of the C standard, not just
-   GNU C. */
-#define STRINGIFY(x) #x
-#define MACROSTR(x) STRINGIFY(x)
+/* Macros */
+#define LOGFILENAME             PROGRAM_EXEC".log"
 #define FILENAME_BUFFER_IN_VERB 30
-#define CENTER_NOT_CHECKED      -1
-
-
 
 
 
-/* Structure for the log file. Since we are operating in parallel
-   mode, writing to a file will significantly decrease the speed. So
-   we will make an array to keep the status of each output.*/
-struct imgcroplog
+/* Modes of operation. */
+enum imgcrop_modes
 {
-  char         *name; /* The name of this output.                  */
-  size_t      numimg; /* The number of images used in this output. */
-  int   centerfilled; /* Is the center filled? (0 or 1)            */
-};
+  IMGCROP_MODE_INVALID,         /* For sanity checks.     */
 
+  IMGCROP_MODE_IMG,             /* Use image coordinates. */
+  IMGCROP_MODE_WCS,             /* Use WCS coordinates.   */
+};
 
 
 
@@ -77,7 +61,8 @@ struct imgcroplog
 struct inputimgs
 {
   char             *name;  /* File name of input image.                   */
-  long          naxes[2];  /* Size of the image.                          */
+  size_t            ndim;  /* Number of dimensions of this image.         */
+  size_t          *dsize;  /* Size of the image.                          */
   int               nwcs;  /* Number of WCS in each input image.          */
   struct wcsprm     *wcs;  /* WCS structure of each input image.          */
   char           *wcstxt;  /* Text output of each WCS.                    */
@@ -91,100 +76,54 @@ struct inputimgs
 
 
 
-/* User interface parameters: */
-struct uiparams
-{
-  char      *catname;  /* Catalog file name.                            */
-  struct gal_linkedlist_stll *gal_linkedlist_stll; /* Input file names. */
-  char      *polygon;  /* String of input polygon vertices.             */
-
-  /* Check if all parameters are read (use .def file for
-     comparison). The non optional parameters (like the catalog and
-     input FITS images that come in from arguments, not options) are
-     checked in the args.h files. */
-  int         catset;
-  int     imgmodeset;
-  int     wcsmodeset;
-  int       racolset;
-  int      deccolset;
-  int          raset;
-  int         decset;
-  int        xcolset;
-  int        ycolset;
-  int          xcset;
-  int          ycset;
-  int      iwidthset;
-  int      wwidthset;
-  int     sectionset;
-  int     polygonset;
-  int      suffixset;
-  int checkcenterset;
-  int   hstartwcsset;
-  int     hendwcsset;
-};
-
-
-
-
-
-
 /* Main program parameters: */
 struct imgcropparams
 {
-  /* Before actual program: */
-  struct uiparams         up; /* User interface parameters.            */
-  struct gal_commonparams cp; /* Common parameters.                    */
-
-  /* Operating modes: */
-  int            imgmode;  /* ==1: will use X and Y coordiates.        */
-  int            wcsmode;  /* ==1: will use Ra and Dec coordiates.     */
-
-  /* Input */
-  size_t          numimg;  /* Number of given image names.             */
-  size_t            xcol;  /* Catalog X column                         */
-  size_t            ycol;  /* Catalog Y column                         */
-  int            noblank;  /* ==1: no blank (out of image) pixels.     */
-  char          *section;  /* Section string.                          */
-  double       *wpolygon;  /* Array of WCS polygon vertices.           */
-  double       *ipolygon;  /* Array of image polygon vertices.         */
-  size_t       nvertices;  /* Number of polygon vertices.              */
-  double              xc;  /* The center point, one crop (FITS stnrd). */
-  double              yc;  /* The center point, one crop (FITS stnrd). */
-  long         iwidth[2];  /* Image mode width (in pixels).            */
-  size_t           racol;  /* Catalog RA column                        */
-  size_t          deccol;  /* Catalog Dec column                       */
-  double              ra;  /* RA of one crop box center.               */
-  double             dec;  /* Dec of one crop box center.              */
-  double             res;  /* Resolution in arcseconds                 */
-  double          wwidth;  /* WCS mode width (in arcseconds).          */
-  size_t     checkcenter;  /* width of a box to check for zeros        */
-  int    keepblankcenter;  /* ==1: If center is not filled, remove.    */
-  int     zeroisnotblank;  /* ==1: In float or double, keep 0.0 pixels.*/
-  int         outpolygon;  /* ==1: Keep the inner polygon region.      */
-  size_t       hstartwcs;  /* Header keyword No. to start reading WCS. */
-  size_t         hendwcs;  /* Header keyword No. to end reading WCS.   */
-
-  /* Output: */
-  char           *suffix;  /* Ending of output file name.              */
-
-  /* INTERNAL PARAMETERS: */
-  struct inputimgs *imgs;  /* Basic WCS and size information for input.*/
-  struct imgcroplog *log;  /* To keep the log of the outputs.          */
-  time_t         rawtime;  /* Starting time of the program.            */
-  int      outnameisfile;  /* Output filename is a directory.          */
-  double            *cat;  /* Data of catalog.                         */
-  size_t             cs0;  /* Number of rows in the catalog.           */
-  size_t             cs1;  /* Number of columns in the catalog.        */
-  int             bitpix;  /* BITPIX value for all images.             */
-  void           *bitnul;  /* Null value for this data-type.           */
-  int           datatype;  /* CFITSIO datatype value for this image.   */
+  /* Directly from command-line */
+  struct gal_options_common_params cp;  /* Common parameters.             */
+  struct gal_linkedlist_stll  *inputs;  /* All input FITS files.          */
+  size_t             hstartwcs;  /* Header keyword No. to start read WCS. */
+  size_t               hendwcs;  /* Header keyword No. to end read WCS.   */
+  unsigned char zeroisnotblank;  /* ==1: In float or double, keep 0.0.    */
+  unsigned char        noblank;  /* ==1: no blank (out of image) pixels.  */
+  char                 *suffix;  /* Ending of output file name.           */
+  size_t           checkcenter;  /* width of a box to check for zeros     */
+  size_t              iwidthin;  /* Image mode width (in pixels).         */
+  double                wwidth;  /* WCS mode width (in arcseconds).       */
+  double                    ra;  /* RA of one crop box center.            */
+  double                   dec;  /* Dec of one crop box center.           */
+  double                    xc;  /* Center point, one crop (FITS stnrd).  */
+  double                    yc;  /* Center point, one crop (FITS stnrd).  */
+  char                *catname;  /* Name of input catalog.                */
+  char                 *cathdu;  /* HDU of catalog if its a FITS file.    */
+  char                *namecol;  /* Filename (without suffix) of crop col.*/
+  char                  *racol;  /* Catalog RA column                     */
+  char                 *deccol;  /* Catalog Dec column                    */
+  char                   *xcol;  /* Catalog X column                      */
+  char                   *ycol;  /* Catalog Y column                      */
+  char                *section;  /* Section string.                       */
+  char                *polygon;  /* Input string of polygon vertices.     */
+  unsigned char     outpolygon;  /* ==1: Keep the inner polygon region.   */
+  char                *modestr;  /* ==1: will use X and Y coordiates.     */
+
+  /* Internal */
+  int                     mode;  /* Image or WCS mode.                    */
+  size_t                 numin;  /* Number of input images.               */
+  size_t                numout;  /* Number of output images.              */
+  double                   *c1;  /* First coordinate from catalog.        */
+  double                   *c2;  /* Second coordinate from catalog.       */
+  char                  **name;  /* filename of crop in row.              */
+  double             *wpolygon;  /* Array of WCS polygon vertices.        */
+  double             *ipolygon;  /* Array of image polygon vertices.      */
+  size_t             nvertices;  /* Number of polygon vertices.           */
+  long               iwidth[2];  /* Image mode width (in pixels).         */
+  double                   res;  /* Resolution in arcseconds              */
+  time_t               rawtime;  /* Starting time of the program.         */
+  int            outnameisfile;  /* Output filename is a directory.       */
+  int                     type;  /* Type of output(s).                    */
+  void                 *bitnul;  /* Null value for this data-type.        */
+  struct inputimgs       *imgs;  /* WCS and size information for inputs.  */
+  gal_data_t              *log;  /* Log file contents.                    */
 };
 
-
-
-
-/* Function declarations: */
-void
-imgcrop(struct imgcropparams *p);
-
 #endif
diff --git a/bin/imgcrop/ui.c b/bin/imgcrop/ui.c
index 818449e..48b560c 100644
--- a/bin/imgcrop/ui.c
+++ b/bin/imgcrop/ui.c
@@ -5,7 +5,7 @@ ImageCrop 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
@@ -22,528 +22,469 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 **********************************************************************/
 #include <config.h>
 
-#include <stdio.h>
+#include <argp.h>
 #include <errno.h>
 #include <error.h>
-#include <stdlib.h>
+#include <stdio.h>
 #include <string.h>
-#include <fitsio.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"
 #include "crop.h"
 #include "wcsmode.h"
+#include "authors-cite.h"
 
-#include "ui.h"                  /* Needs main.h                   */
-#include "args.h"                /* Needs main.h, includes argp.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[] = "[ASCIIcatalog] ASTRdata ...";
 
+const char
+doc[] = GAL_STRINGS_TOP_HELP_INFO PROGRAM_NAME" will create cutouts, "
+  "thumbnails, postage stamps or crops of region(s) from input image(s) "
+  "using image or celestial coordinates. If muliple crops are desired, a "
+  "catalog must be provided. When in WCS mode, if the cut out covers more "
+  "than one input image, all overlapping input images will be stitched in "
+  "the output.\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 imgcropparams *p)
+/* Option groups particular to this program. */
+enum program_args_groups
 {
-  FILE *fp;
-  int zeroorone;
-  char *line, *name, *value;
-  struct uiparams *up=&p->up;
-  size_t lineno=0, len=200, tmp;
-  struct gal_commonparams *cp=&p->cp;
-  char key='a';                   /* Not used, just a place holder.     */
-  int imgmodeset=0, wcsmodeset=0; /* Unambiguous default file checking. */
-
-  /* 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);
+  ARGS_GROUP_CENTER_GENERAL = GAL_OPTIONS_GROUP_AFTER_COMMON,
+  ARGS_GROUP_CENTER_SINGLE,
+  ARGS_GROUP_CENTER_CATALOG,
+  ARGS_GROUP_REGION,
+};
 
-  /* 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;
 
-      /* Operating modes: */
-      if(strcmp(name, "imgmode")==0)
-        {
-          gal_checkset_int_zero_or_one(value, &zeroorone, name, key, SPACK,
-                       filename, lineno);
-          if(zeroorone)
-            {
-              imgmodeset=1;
-              if(wcsmodeset)
-                error_at_line(EXIT_FAILURE, 0, filename, lineno,
-                              "Image and WCS modes cannot be called "
-                              "together. It is ambiguous.");
-              if(up->imgmodeset==0)
-                {
-                  p->imgmode=1;
-                  p->wcsmode=0;
-                  up->imgmodeset=up->wcsmodeset=1;
-                }
-            }
-        }
-      else if(strcmp(name, "wcsmode")==0)
-        {
-          gal_checkset_int_zero_or_one(value, &zeroorone, name, key, SPACK,
-                       filename, lineno);
-          if(zeroorone)
-            {
-              wcsmodeset=1;
-              if(imgmodeset)
-                error_at_line(EXIT_FAILURE, 0, filename, lineno,
-                              "Image and WCS modes cannot be called "
-                              "together. It is ambiguous.");
-              if(up->wcsmodeset==0)
-                {
-                  p->imgmode=0;
-                  p->wcsmode=1;
-                  up->imgmodeset=up->wcsmodeset=1;
-                }
-            }
-        }
 
 
 
+/* Available letters for short options:
 
+   e k m t u v
+   A B E F G H I J L O Q R T U W X Y Z  */
+enum option_keys_enum
+{
+  /* With short-option version. */
+  ARGS_OPTION_KEY_CATALOG        = 'C',
+  ARGS_OPTION_KEY_NOBLANK        = 'b',
+  ARGS_OPTION_KEY_CHECKCENTER    = 'c',
+  ARGS_OPTION_KEY_SUFFIX         = 'p',
+  ARGS_OPTION_KEY_NAMECOL        = 'n',
+  ARGS_OPTION_KEY_RACOL          = 'f',
+  ARGS_OPTION_KEY_DECCOL         = 'g',
+  ARGS_OPTION_KEY_RA             = 'r',
+  ARGS_OPTION_KEY_DEC            = 'd',
+  ARGS_OPTION_KEY_XCOL           = 'i',
+  ARGS_OPTION_KEY_YCOL           = 'j',
+  ARGS_OPTION_KEY_XC             = 'x',
+  ARGS_OPTION_KEY_YC             = 'y',
+  ARGS_OPTION_KEY_IWIDTH         = 'a',
+  ARGS_OPTION_KEY_WWIDTH         = 'w',
+  ARGS_OPTION_KEY_SECTION        = 's',
+  ARGS_OPTION_KEY_POLYGON        = 'l',
+  ARGS_OPTION_KEY_ZEROISNOTBLANK = 'z',
+  ARGS_OPTION_KEY_MODE           = 'M',
 
-      /* Inputs: */
-      else if(strcmp(name, "hdu")==0)
-        gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->hduset);
-
-      else if(strcmp(name, "racol")==0)
-        {
-          if(up->racolset) continue;
-          gal_checkset_sizet_el_zero(value, &p->racol, name, key, SPACK,
-                      filename, lineno);
-          up->racolset=1;
-        }
-      else if(strcmp(name, "deccol")==0)
-        {
-          if(up->deccolset) continue;
-          gal_checkset_sizet_el_zero(value, &p->deccol, name, key, SPACK,
-                      filename, lineno);
-          up->deccolset=1;
-        }
-      else if(strcmp(name, "xcol")==0)
-        {
-          if(up->xcolset) continue;
-          gal_checkset_sizet_el_zero(value, &p->xcol, name, key, SPACK,
-                      filename, lineno);
-          up->xcolset=1;
-        }
-      else if(strcmp(name, "ycol")==0)
-        {
-          if(up->ycolset) continue;
-          gal_checkset_sizet_el_zero(value, &p->ycol, name, key, SPACK,
-                      filename, lineno);
-          up->ycolset=1;
-        }
-      else if(strcmp(name, "iwidth")==0)
-        {
-          if(up->iwidthset) continue;
-          gal_checkset_sizet_l_zero(value, &tmp, name, key, SPACK,
-                     filename, lineno);
-          p->iwidth[0]=p->iwidth[1]=tmp;
-          up->iwidthset=1;
-        }
-      else if(strcmp(name, "wwidth")==0)
-        {
-          if(up->wwidthset) continue;
-          gal_checkset_double_l_0(value, &p->wwidth, name, key, SPACK,
-                   filename, lineno);
-          up->wwidthset=1;
-        }
-      else if(strcmp(name, "hstartwcs")==0)
-        {
-          if(up->hstartwcsset) continue;
-          gal_checkset_sizet_el_zero(value, &p->hstartwcs, name, key, SPACK,
-                      filename, lineno);
-          up->hstartwcsset=1;
-        }
-      else if(strcmp(name, "hendwcs")==0)
-        {
-          if(up->hendwcsset) continue;
-          gal_checkset_sizet_el_zero(value, &p->hendwcs, name, key, SPACK,
-                      filename, lineno);
-          up->hendwcsset=1;
-        }
-
+  /* Only with long version (start with a value 1000, the rest will be set
+     automatically). */
+  ARGS_OPTION_KEY_CATHDU         = 1000,
+  ARGS_OPTION_KEY_HSTARTWCS,
+  ARGS_OPTION_KEY_HENDWCS,
+  ARGS_OPTION_KEY_OUTPOLYGON,
+};
 
 
-      /* Outputs */
-      else if(strcmp(name, "checkcenter")==0)
-        {
-          if(up->checkcenterset) continue;
-          gal_checkset_sizet_el_zero(value, &p->checkcenter, name, key,
-                                     SPACK, filename, lineno);
-          up->checkcenterset=1;
-        }
-      else if(strcmp(name, "output")==0)
-        gal_checkset_allocate_copy_set(value, &cp->output, &cp->outputset);
 
-      else if(strcmp(name, "suffix")==0)
-        gal_checkset_allocate_copy_set(value, &p->suffix, &up->suffixset);
 
 
 
-      /* 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 imgcropparams *p)
-{
-  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);
-
-
-  fprintf(fp, "\n# Output parameters:\n");
-  if(up->checkcenterset)
-    fprintf(fp, CONF_SHOWFMT"%zu\n", "checkcenter", p->checkcenter);
-  if(cp->outputset)
-    fprintf(fp, CONF_SHOWFMT"%s\n", "output", cp->output);
-  if(up->suffixset)
-    fprintf(fp, CONF_SHOWFMT"%s\n", "suffix", p->suffix);
-
-
-  fprintf(fp, "\n# Crop parameters:\n");
-  if(up->xcolset)
-    fprintf(fp, CONF_SHOWFMT"%zu\n", "xcol", p->xcol);
-  if(up->ycolset)
-    fprintf(fp, CONF_SHOWFMT"%zu\n", "ycol", p->ycol);
-  if(up->iwidthset)
-    fprintf(fp, CONF_SHOWFMT"%ld\n", "iwidth", p->iwidth[0]);
-  if(up->racolset)
-    fprintf(fp, CONF_SHOWFMT"%zu\n", "racol", p->racol);
-  if(up->deccolset)
-    fprintf(fp, CONF_SHOWFMT"%zu\n", "deccol", p->deccol);
-  if(up->wwidthset)
-    fprintf(fp, CONF_SHOWFMT"%.3f\n", "wwidth", p->wwidth);
-  if(up->hstartwcsset)
-    fprintf(fp, CONF_SHOWFMT"%zu\n", "hstartwcs", p->hstartwcs);
-  if(up->hendwcsset)
-    fprintf(fp, CONF_SHOWFMT"%zu\n", "hendwcs", p->hendwcs);
-
-
-  /* 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;
-  if(up->imgmodeset)
-    fprintf(fp, CONF_SHOWFMT"%d\n", "imgmode", p->imgmode);
-  if(up->wcsmodeset)
-    fprintf(fp, CONF_SHOWFMT"%d\n", "wcsmode", p->wcsmode);
-}
 
 
 
 
 
 
-/* Note that numthreads will be used automatically based on the
-   configure time. */
-void
-checkifset(struct imgcropparams *p)
+/**************************************************************/
+/*********    Initialize & Parse command-line    **************/
+/**************************************************************/
+static void
+ui_initialize_options(struct imgcropparams *p,
+                      struct argp_option *program_options,
+                      struct argp_option *gal_commonopts_options)
 {
-  struct uiparams *up=&p->up;
-  struct gal_commonparams *cp=&p->cp;
-
-  int intro=0;
-  if(up->imgmodeset==0 && up->wcsmodeset==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("imgmode or wcsmode");
-  if(cp->hduset==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("hdu");
-  if(up->xcolset==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("xcol");
-  if(up->ycolset==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("ycol");
-  if(up->iwidthset==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("iwidth");
-  if(up->racolset==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("racol");
-  if(up->deccolset==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("deccol");
-  if(up->wwidthset==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("wwidth");
-  if(up->suffixset==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("suffix");
-  if(up->checkcenterset==0)
-    GAL_CONFIGFILES_REPORT_NOTSET("checkcenter");
-
-  GAL_CONFIGFILES_END_OF_NOTSET_REPORT;
-}
+  size_t i;
+  struct gal_options_common_params *cp=&p->cp;
 
 
+  /* Set the necessary common parameters structure. */
+  cp->poptions           = program_options;
+  cp->program_name       = PROGRAM_NAME;
+  cp->program_exec       = PROGRAM_EXEC;
+  cp->program_bibtex     = PROGRAM_BIBTEX;
+  cp->program_authors    = PROGRAM_AUTHORS;
+  cp->coptions           = gal_commonopts_options;
 
 
+  /* Initalize necessary parameters. */
+  p->xc=p->yc=p->ra=p->dec=NAN;
+  p->mode         = IMGCROP_MODE_INVALID;
+  cp->searchin    = GAL_TABLE_SEARCH_INVALID;
 
 
+  /* 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_HDU:
+        cp->coptions[i].mandatory=GAL_OPTIONS_MANDATORY;
+        cp->coptions[i].doc="Extension name or number of (all) input(s).";
+        break;
+
+      case GAL_OPTIONS_KEY_MINMAPSIZE:
+        cp->coptions[i].mandatory=GAL_OPTIONS_MANDATORY;
+        break;
+
+      case GAL_OPTIONS_KEY_SEARCHIN:
+        cp->coptions[i].group=ARGS_GROUP_CENTER_CATALOG;
+        break;
+
+      case GAL_OPTIONS_KEY_IGNORECASE:
+        cp->coptions[i].group=ARGS_GROUP_CENTER_CATALOG;
+        break;
+      }
 
 
+  /* Read the number of threads available to the user, this should be done
+     before reading command-line and configuration file options, since they
+     can change it.  */
+  cp->numthreads=gal_threads_number();
+}
 
 
 
 
 
+/* Parse a single option: */
+error_t
+parse_opt(int key, char *arg, struct argp_state *state)
+{
+  struct imgcropparams *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)
+    {
 
+    /* Read the non-option tokens (arguments): */
+    case ARGP_KEY_ARG:
+      gal_linkedlist_add_to_stll(&p->inputs, arg, 0);
+      ++p->numin;
+      break;
 
 
+    /* This is an option, set its value. */
+    default:
+      return gal_options_set_from_key(key, arg, p->cp.poptions, &p->cp);
+    }
 
+  return 0;
+}
 
 
 
 
-/**************************************************************/
-/***************       Sanity Check         *******************/
-/**************************************************************/
-void
-sanitycheck(struct imgcropparams *p)
-{
-  int checksum;
-  char forerr[100];
-  struct uiparams *up=&p->up;
-  struct gal_commonparams *cp=&p->cp;
 
 
-  /* Width and checkcenter are odd */
-  if(p->iwidth[0]<3)
-    error(EXIT_FAILURE, 0, "--iwidth has to be 3 or more pixels");
-  else if(p->iwidth[0]%2==0)
-    error(EXIT_FAILURE, 0, "the given value to `iwidth' (%ld) has to "
-          "be an odd number (the pixel corresponding to the desired "
-          "coordinate to be in the center)", p->iwidth[0]);
-  p->iwidth[1]=p->iwidth[0];
-  if(p->checkcenter && p->checkcenter%2==0)
-    error(EXIT_FAILURE, 0, "`checkcenter' has to be an odd number. The "
-          "current value is %zu", p->checkcenter);
 
 
 
-  /* deccol!=racol and xcol!=ycol */
-  if(p->racol==p->deccol)
-    error(EXIT_FAILURE, 0, "the columns for RA and Dec must be "
-          "different");
-  if(p->xcol==p->ycol)
-    error(EXIT_FAILURE, 0, "the columns for x and y must be "
-          "different");
 
 
 
-  /* Make sure that if any of --ra or --dec are given, the other is
-     also given. */
-  checksum=up->raset+up->decset;
-  if(checksum==2) {p->imgmode=0; p->wcsmode=1;}
-  else if(checksum)/* is not zero */
-    error(EXIT_FAILURE, 0, "the options `--ra` and `--dec` should be "
-          "called together");
 
 
 
-  /* Make sure that if any of --xc or --yc are given, the other is
-     also given. */
-  checksum=up->xcset+up->ycset;
-  if(checksum==2) {p->imgmode=1; p->wcsmode=0;}
-  else if(checksum)/* is not zero */
-    error(EXIT_FAILURE, 0, "the options `--xc` and `--yc` should be "
-          "called together");
 
 
 
-  /* --section is given, it goes into image mode: */
-  if(up->sectionset) {p->imgmode=1; p->wcsmode=0;}
 
 
+/**************************************************************/
+/***************       Sanity Check         *******************/
+/**************************************************************/
+/* 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 imgcropparams *p)
+{
+  int checksum;
 
-  /* Make sure that the multiple one crop box options have not been
-     called together. */
-  checksum=up->raset+up->xcset+up->sectionset+up->polygonset;
-  if(checksum)
+  /* Read the mode from the string the user specified. */
+  if(p->modestr)
     {
-      /* Only one of the three should be called. */
-      if(checksum!=1)
-        {
-          forerr[0]='\0';
-          if(up->raset)
-            strcat(forerr, "(`--ra' and `--dec'), ");
-          if(up->xcset)
-            strcat(forerr, "(`--xc' and `--yc'), ");
-          if(up->sectionset)
-            strcat(forerr, "(`--section'), ");
-          if(up->polygonset)
-            strcat(forerr, "(`--polygon'), ");
-          error(EXIT_FAILURE, 0, "there are several ways to specify a crop "
-                "box on the command line, see `--help`. But they should "
-                "not be called together. You have asked for %s "
-                "simultaneously", forerr);
-        }
+      if      (!strcmp(p->modestr, "img"))   p->mode=IMGCROP_MODE_IMG;
+      else if (!strcmp(p->modestr, "wcs"))   p->mode=IMGCROP_MODE_WCS;
+      else
+        error(EXIT_FAILURE, 0, "`%s' (value to `--mode') not recognized as "
+              "an input mode. Recognized values are `img' and `wcs'. This "
+              "option is necessary when the inputs are not sufficient to "
+              "identify the nature of the coordinates.\n\n"
+              "Please run the following command for more information "
+              "(press the `SPACE' key to go down and `q' to return to the "
+              "command-line):\n\n"
+              "    $ info gnuastro \"ImageCrop modes\"\n", p->modestr);
+    }
 
-      /* Check if the value for --output is a file or a directory? */
-      p->outnameisfile=gal_checkset_dir_0_file_1(cp->output,
-                                                 cp->dontdelete);
 
-      /* When there is only one output, only one thread is needed. */
-      cp->numthreads=1;
 
-      /* Not with a catalog. */
-      if(up->catname)
-        {
-          if(up->sectionset) strcpy(forerr, "`--section'");
-          if(up->polygonset) strcpy(forerr, "`--polygon'");
-          if(up->xcset) strcpy(forerr, "`--xc' and `--yc'");
-          if(up->raset) strcpy(forerr, "`--ra' and `--dec'");
-          error(EXIT_FAILURE, 0, "a catalog name (%s) and command line "
-                "crop parameters (%s) cannot be given together",
-                up->catname, forerr);
-        }
-    }
-  else
-    {
-      /* Only one mode. Note that when the box is specified on the
-         command line, in the steps above, we set the image mode or
-         wcs mode.*/
-      if(p->imgmode && p->wcsmode)
-        error(EXIT_FAILURE, 0, "only one of imgmode or wcsmode "
-              "must be called. They cannot operate together");
-      else if(p->imgmode==0 && p->wcsmode==0)
-        error(EXIT_FAILURE, 0, "at least one of imgmode or "
-              "wcsmode must be called");
-
-      /* Make sure a catalog is set. */
-      if(up->catset)
-        {
-          if(p->numimg>1 && p->imgmode)
-            error(EXIT_FAILURE, 0, "in image mode, when a catalog is "
-                  "specified, only one image may be provided");
-        }
-      else
-        error(EXIT_FAILURE, 0, "no catalog. When no crop coordinates "
-              "are specified on the command line, a catalog must be "
-              "provided");
 
-      /* Make sure the given output is a directory. */
-      gal_checkset_check_dir_write_add_slash(&cp->output);
+  /* Check that if one of the coordinates is given, the other is also
+     given. Note that if both are not given, their sum will be 0, if both
+     are given, then the sum will be 2. If only one is given, then the sum
+     will be 1. */
+  if( (isnan(p->ra) + isnan(p->dec)) == 1 )
+    error(EXIT_FAILURE, 0, "no `--%s' given, it is mandatory with the `--%s' "
+          "option", isnan(p->ra)?"ra":"dec", isnan(p->ra)?"dec":"ra");
 
-      /* Make sure the columns of data are within the catalog range of
-         columns: */
-      if(p->imgmode)
-        {
-          GAL_CHECKSET_CHECK_COL_IN_CAT(p->xcol, "xcol");
-          GAL_CHECKSET_CHECK_COL_IN_CAT(p->ycol, "ycol");
-        }
-      else
-        {
-          GAL_CHECKSET_CHECK_COL_IN_CAT(p->racol, "racol");
-          GAL_CHECKSET_CHECK_COL_IN_CAT(p->deccol, "deccol");
-        }
-    }
+  if( (isnan(p->xc) + isnan(p->yc)) == 1 )
+    error(EXIT_FAILURE, 0, "no `--%s' given, it is mandatory with the `--%s' "
+          "option", isnan(p->xc)?"xc":"yc", isnan(p->xc)?"yc":"xc");
 
+  if( ((p->racol!=NULL) + (p->deccol!=NULL)) == 1 )
+    error(EXIT_FAILURE, 0, "no `--%scol' given, it is mandatory with the "
+          "`--%scol' option", p->racol?"dec":"ra",
+          p->racol?"ra":"dec");
 
+  if( ((p->xcol!=NULL) + (p->ycol!=NULL)) == 1 )
+    error(EXIT_FAILURE, 0, "no `--%scol' given, it is mandatory with the "
+          "`--%scol' option", p->xcol?"y":"x", p->xcol?"x":"y");
 
-  /* If in image mode, there should only be one input image. */
-  if(p->imgmode && p->numimg>1)
-    error(EXIT_FAILURE, 0, "in image mode, only one input image may be "
-          "specified");
 
 
+  /* Make sure that the single crop modes are not called together. */
+  checksum = ( (!isnan(p->xc)) + (!isnan(p->ra)) + (p->catname!=NULL)
+               + (p->section!=NULL) + (p->polygon!=NULL) );
+  switch(checksum)
+    {
+    case 0:
+      error(EXIT_FAILURE, 0, "no crop definition, you can use any of the "
+            "following options to define the crop(s): (`--xc', `--yc'), "
+            "(`--ra', `--dec'), `--catalog', `--section', `--polygon'. "
+            "Please run this command for more information:\n\n"
+            "    $ info gnuastro \"ImageCrop modes\"\n");
+    case 1:
+      /* Everything is ok, just ignore the switch structure. */
+      break;
+    default:
+      error(EXIT_FAILURE, 0, "more than one crop type specified. In each "
+            "run, only one crop definition is acceptable on the "
+            "command-line, or in configuration files. You have called "
+            "%s%s%s%s%s\b\b.",
+            !isnan(p->xc) ? "(`--xc', `--yc'), " : "",
+            !isnan(p->ra) ? "(`--ra', `--dec'), " : "",
+            p->catname!=NULL ? "`--catalog', " : "",
+            p->section!=NULL ? "`--section', " : "",
+            p->polygon!=NULL ? "`--polygon', " : "");
+    }
 
 
-  /* If we are in WCS mode, noblanks must be off */
-  if(p->wcsmode && p->noblank)
-    error(EXIT_FAILURE, 0, "`--noblanks` (`-b`) is only for image mode. "
-          "You have called it with WCS mode");
 
+  /* Sanity checks and mode setting based on the desired crop. */
+  if(p->catname)
+    {
+      /* If the searchin option has been given. */
+      if(p->cp.searchin==GAL_TABLE_SEARCH_INVALID)
+        error(EXIT_FAILURE, 0, "%s: no field specified to search for "
+              "columns. Please use the `--searchin' option to specify "
+              "which column meta-data you would like to search in: `%s', "
+              "`%s' and `%s'. You may also select columns by their number, "
+              "which won't use this option, but for complentess its best "
+              "for this option to have a value", p->catname,
+              GAL_TABLE_STRING_SEARCH_NAME, GAL_TABLE_STRING_SEARCH_UNIT,
+              GAL_TABLE_STRING_SEARCH_COMMENT);
+
+      /* If it is a FITS file, we need the HDU. */
+      if( gal_fits_name_is_fits(p->catname) && p->cathdu==NULL )
+        error(EXIT_FAILURE, 0, "%s: no hdu given. Please use the `--cathdu' "
+              "option to specify which extension contains the table",
+              p->catname);
+
+      /* Atleast one of the (X,Y), and (RA,Dec) set of columns are
+         necessary. Note that we have checked that they are together if
+         given, so we only need to check one of the two in each couple. */
+      if(p->xcol==NULL && p->racol==NULL)
+        error(EXIT_FAILURE, 0, "no crop center position column given "
+              "to read from the input catalog (`%s'). Please use either of "
+              "(`--xcol', `--ycol') or (`--racol', `--deccol'). For more "
+              "information on how to select columns in Gnuastro, please run "
+              "the following command:\n\n"
+              "    $ info gnuastro \"Selecting table columns\"", p->catname);
+
+      /* If only image columns are specified, then we have Image mode, if
+         only WCS columns are specified, we have WSC mode. If both are
+         specified, the mode is mandatory */
+      if(p->xcol && p->racol)
+        {
+          if(p->mode==IMGCROP_MODE_INVALID)
+            error(EXIT_FAILURE, 0, "both image and WCS coordinate columns "
+                  "are specified to read the center of the crops in the "
+                  "input catalog (%s). You can use the `--mode=img', or "
+                  "`--mode=wcs' options to specify which set of columns "
+                  "should be used", p->catname);
+        }
+      else
+        p->mode = p->xcol ? IMGCROP_MODE_IMG : IMGCROP_MODE_WCS;
+    }
+  else if(p->polygon)
+    {
+      if(p->mode==IMGCROP_MODE_INVALID)
+        error(EXIT_FAILURE, 0, "the polygon option works in both image and "
+              "wcs mode, please specify how the vertices should be "
+              "interpreted with `--mode=img', or `--mode=wcs' options to "
+              "specify which set of columns should be used");
+    }
+  else if(!isnan(p->xc))
+    p->mode = IMGCROP_MODE_IMG;
+  else if(!isnan(p->ra))
+    p->mode = IMGCROP_MODE_WCS;
+  else if( p->section)
+    p->mode = IMGCROP_MODE_IMG;
 
 
-  /* Parse the polygon vertices if they are given to make sure that
-     there is no error: */
-  if(p->up.polygonset)
+  /* Parse the polygon vertices if they are given to make sure that it is
+     in the proper format. */
+  if(p->polygon)
     {
-      polygonparser(p);
+      crop_polygonparser(p);
       if(p->nvertices<3)
         error(EXIT_FAILURE, 0, "a polygon has to have 3 or more vertices, "
-              "you have only given %zu (%s)", p->nvertices, p->up.polygon);
-      if(p->outpolygon && p->numimg>1)
+              "you have only given %zu (%s)", p->nvertices, p->polygon);
+      if(p->outpolygon && p->numin>1)
         error(EXIT_FAILURE, 0, "currently in WCS mode, outpolygon can only "
               "be set to zero when there is one image, you have given %zu "
               "images. For multiple images the region will be very large. "
               "It is best if you first crop out the larger region you want "
-              "into one image, then mask the polygon", p->numimg);
+              "into one image, then mask the polygon", p->numin);
     }
   else
     p->wpolygon=p->ipolygon=NULL;
 
 
+  /* If we are in WCS mode, noblanks must be off */
+  if(p->mode==IMGCROP_MODE_WCS && p->noblank)
+    error(EXIT_FAILURE, 0, "`--noblanks` (`-b`) is only for image mode. "
+          "You have called it with WCS mode");
+}
+
+
+
+
+
+static void
+ui_check_options_and_arguments(struct imgcropparams *p)
+{
+  /* Make sure we do actually have inputs. */
+  if(p->inputs==NULL)
+    error(EXIT_FAILURE, 0, "no input file given");
+
+  /* Make sure an input file name was given and if it was a FITS file, that
+     a HDU is also given. */
+  if(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");
+
+  /* If in image mode, there should only be one input image. */
+  if(p->mode==IMGCROP_MODE_IMG && p->numin>1)
+    error(EXIT_FAILURE, 0, "in image mode, only one input image may be "
+          "specified");
+
+  /* If no output name is given, set it to the current directory. */
+  if(p->cp.output==NULL)
+    gal_checkset_allocate_copy("./", &p->cp.output);
 
+  /* Only catalog mode needs multiple threads and a directory for the
+     output. */
+  if(p->catname)
+    {
+      /* When multiple threads need to access a file, CFITSIO needs to be
+         configured with the `--enable-reentrant` option. */
+      if(p->cp.numthreads>1 && fits_is_reentrant()==0)
+        error(EXIT_FAILURE, 0, "CFITSIO was not configured with the "
+              "`--enable-reentrant` option but you have asked to crop "
+              "on %zu threads.\n\nPlease configure, make and install CFITSIO "
+              "again with this flag. Alternatively, to avoid this error "
+              "you can set the number of threads to 1 by adding the "
+              "`--numthreads=1` or `-N1` options. Please run the following "
+              "command to learn more about configuring CFITSIO:\n\n"
+              "    $ info gnuastro CFITSIO", p->cp.numthreads);
 
-  /* Check that if multiple threads are beeing requested, CFITSIO is
-     configured with the `--enable-reentrant` option. This is put here
-     because the number of threads may change above. */
-  if(cp->numthreads>1 && fits_is_reentrant()==0)
-    error(EXIT_FAILURE, 0, "CFITSIO was not configured with the "
-          "`--enable-reentrant` option but you have asked to operate "
-          "on %zu threads. Please configure, make and install CFITSIO "
-          "again with this flag to use multiple threads, run `info %s "
-          "CFITSIO` for more information. Alternatively you can set "
-          "the number of threads to 1 by adding the `--numthreads=1` "
-          "or `-N1` options", cp->numthreads, PACKAGE);
+      /* Make sure the given output is a directory. */
+      gal_checkset_check_dir_write_add_slash(&p->cp.output);
+    }
+  else
+    {
+      p->cp.numthreads=1;
+      p->outnameisfile=gal_checkset_dir_0_file_1(p->cp.output,
+                                                 p->cp.dontdelete);
+    }
 }
 
 
@@ -568,43 +509,205 @@ sanitycheck(struct imgcropparams *p)
 /**************************************************************/
 /***************       Preparations         *******************/
 /**************************************************************/
-/* It is important that the image names are stored in an array (for
-   WCS mode in particular). We do that here. */
+static void
+ui_read_cols(struct imgcropparams *p)
+{
+  char *colname;
+  size_t counter=0;
+  int toomanycols=0;
+  gal_data_t *cols, *tmp, *corrtype=NULL;
+  struct gal_linkedlist_stll *colstrs=NULL;
+  char *ax1col = p->mode==IMGCROP_MODE_IMG ? p->xcol : p->racol;
+  char *ax2col = p->mode==IMGCROP_MODE_IMG ? p->ycol : p->deccol;
+
+  /* Specify the order of columns. */
+  if(p->namecol)
+    gal_linkedlist_add_to_stll(&colstrs, p->namecol, 0);
+  gal_linkedlist_add_to_stll(&colstrs, ax1col, 0);
+  gal_linkedlist_add_to_stll(&colstrs, ax2col, 0);
+
+  /* Read the desired columns from the file. */
+  cols=gal_table_read(p->catname, p->cathdu, colstrs, p->cp.searchin,
+                      p->cp.ignorecase, p->cp.minmapsize);
+
+  /* Set the number of objects. */
+  p->numout=cols->size;
+
+  /* For a sanity check, make sure that the total number of columns read is
+     the same as those that were wanted (it might be more). */
+  while(cols!=NULL)
+    {
+      /* Pop out the top node. */
+      tmp=gal_data_pop_from_ll(&cols);
+
+      /* 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
+         values into the `x' and `y' arrays even if they are RA/Dec. */
+      switch(++counter)
+        {
+        case 3:
+          colname="crop name prefix";
+          if(p->namecol)
+            {
+              if(tmp->type==GAL_DATA_TYPE_STRING)
+                {
+                  p->name=tmp->array;
+                  tmp->array=NULL;
+                  gal_data_free(tmp);
+                }
+              else
+                {
+                  corrtype=gal_data_copy_to_new_type_free(tmp,
+                                            GAL_DATA_TYPE_STRING);
+                  p->name=corrtype->array;
+                }
+            }
+          else
+            toomanycols=1;
+          break;
+
+        case 2:
+          colname="first axis position";
+          corrtype=gal_data_copy_to_new_type_free(tmp, GAL_DATA_TYPE_DOUBLE);
+          p->c1=corrtype->array;
+          break;
+
+        case 1:
+          colname="second axis position";
+          corrtype=gal_data_copy_to_new_type_free(tmp, GAL_DATA_TYPE_DOUBLE);
+          p->c2=corrtype->array;
+          break;
+
+        /* If the index isn't recognized, then it is larger, showing that
+           there was more than one match for the given criteria */
+        default:
+          toomanycols=1;
+        }
+
+      /* Print an error if there were too many columns. */
+      if(toomanycols)
+        gal_table_too_many_columns(p->catname);
+
+      /* Sanity check and clean up.  Note that it might happen that the
+         input structure is already freed. In that case, `corrtype' will be
+         NULL. */
+      if(corrtype)
+        {
+          /* Make sure there are no blank values in this column. */
+          if( gal_data_has_blank(corrtype) )
+            error(EXIT_FAILURE, 0, "%s column has blank values. "
+                  "Input columns cannot contain blank values", colname);
+
+          /* Free the unnecessary sturcture information. The correct-type
+             (`corrtype') data structure's array is necessary for later
+             steps, so its pointer has been copied in the main program's
+             structure. Hence, we should set the structure's pointer to
+             NULL so the important data isn't freed.*/
+          corrtype->array=NULL;
+          gal_data_free(corrtype);
+          corrtype=NULL;
+        }
+    }
+}
+
+
+
+
+
+/* Add all the columns of the log file. Just note that since this is a
+   linked list, we have to add them in the opposite order. */
+static void
+ui_make_log(struct imgcropparams *p)
+{
+  char *comment;
+
+  /* Return if no long file is to be created. */
+  if(p->cp.log==0) return;
+
+  /* If central pixels are filled. */
+  asprintf(&comment, "Are the central pixels filled? (1: yes, 0: no, "
+           "%u: not checked)", GAL_DATA_BLANK_UCHAR);
+  gal_data_add_to_ll(&p->log, NULL, GAL_DATA_TYPE_UCHAR, 1, &p->numout,
+                     NULL, 1, p->cp.minmapsize, "CENTER_FILLED", "bool",
+                     comment);
+  free(comment);
+
+  /* Number of images used. */
+  gal_data_add_to_ll(&p->log, NULL, GAL_DATA_TYPE_USHORT, 1, &p->numout,
+                     NULL, 1, p->cp.minmapsize, "NUM_INPUTS", "count",
+                     "Number of input images used to make this crop.");
+
+  /* Row number in input catalog. */
+  gal_data_add_to_ll(&p->log, NULL, GAL_DATA_TYPE_STRING, 1, &p->numout,
+                     NULL, 1, p->cp.minmapsize, "CROP_NAME", "name",
+                     "File name of crop.");
+}
+
+
+
+
+
 void
-preparearrays(struct imgcropparams *p)
+ui_preparations(struct imgcropparams *p)
 {
-  size_t size, num;
+  char *msg;
   fitsfile *tmpfits;
   struct timeval t1;
+  size_t input_counter;
   struct inputimgs *img;
-  int i, type, status, firstbitpix=0;
-  char msg[GAL_TIMING_VERB_MSG_LENGTH_V];
+  int status, firsttype=0;
+
 
-  if(p->cp.verb) gettimeofday(&t1, NULL);
+  /* Set the initial iwidth. */
+  p->iwidth[0]=p->iwidth[1]=p->iwidthin;
 
-  /* Fill in the WCS information of each image. This is done here
-     because WCSLIB is unfortunately not thread-safe when reading the
-     WCS information from the FITS files. In cases where the number of
-     cropped images are more than the input images, this can also be a
-     preformance boost because each image information is only read
-     once.
 
-     The images are filled in opposite order because we used a linked
-     list to read them in, which is a first in first out structure.*/
+  /* For polygon and section, there should be no center checking. */
+  if(p->polygon || p->section)
+    p->checkcenter=0;
+
+
+  /* Read the columns if there is a catalog, otherwise, set the number
+     of images (crops) to 1.*/
+  if(p->catname)
+    ui_read_cols(p);
+  else
+    p->numout=1;
+
+
+  /* Everything is ready, notify the user of the program starting. */
+  if(!p->cp.quiet)
+    {
+      gettimeofday(&t1, NULL);
+      printf(PROGRAM_NAME" started on %s", ctime(&p->rawtime));
+    }
+
+
+  /* Allocate space for all the input images. This is done here because
+     WCSLIB is unfortunately not thread-safe when reading the WCS
+     information from the FITS files. In cases where the number of cropped
+     images are more than the input images, this can also be a preformance
+     boost because each image information is only read once.
+
+     The images are filled in opposite order because we used a linked list
+     to read them in, which is a first in first out structure.*/
   errno=0;
-  size=p->numimg*sizeof *p->imgs;
-  p->imgs=malloc(size);
+  p->imgs=malloc(p->numin*sizeof *p->imgs);
   if(p->imgs==NULL)
-    error(EXIT_FAILURE, errno, "ui.c: %zu bytes for p->imgs", size);
+    error(EXIT_FAILURE, errno, "ui.c: %zu bytes for p->imgs",
+          p->numin*sizeof *p->imgs);
+
 
-  for(i=p->numimg-1;i>=0;--i)
+  /* Fill in the WCS information of each image. */
+  input_counter=p->numin;
+  while(p->inputs)
     {
-      /* Get the image properties. */
+      /* Pop from the list of input images and get the info. */
       status=0;
-      img=&p->imgs[i];
-      gal_linkedlist_pop_from_stll(&p->up.gal_linkedlist_stll, &img->name);
-      gal_fits_read_hdu(img->name, p->cp.hdu, 0, &tmpfits);
-      gal_fits_img_bitpix_size(tmpfits, &p->bitpix, img->naxes);
+      img=&p->imgs[--input_counter];
+      gal_linkedlist_pop_from_stll(&p->inputs, &img->name);
+      tmpfits=gal_fits_read_hdu(img->name, p->cp.hdu, 0);
+      gal_fits_img_info(tmpfits, &p->type, &img->ndim, &img->dsize);
       gal_fits_read_wcs_from_pointer(tmpfits, &img->nwcs, &img->wcs,
                                      p->hstartwcs, p->hendwcs);
       if(img->wcs)
@@ -616,7 +719,7 @@ preparearrays(struct imgcropparams *p)
                   wcs_errmsg[status]);
         }
       else
-        if(p->wcsmode)
+        if(p->mode==IMGCROP_MODE_WCS)
           error(EXIT_FAILURE, 0, "the WCS structure of %s (hdu: %s) "
                 "image is not recognized. So RA and Dec cannot be used "
                 "as input. You can try with pixel coordinates in the "
@@ -625,47 +728,44 @@ preparearrays(struct imgcropparams *p)
       fits_close_file(tmpfits, &status);
       gal_fits_io_error(status, NULL);
 
-      /* Make sure all the images have the same BITPIX and set the
-         basic BITPIX related parameters. */
-      if(firstbitpix==0)
+      /* Make sure all the images have the same type. */
+      if(firsttype==0)
         {
-          firstbitpix=p->bitpix;
-          type=gal_fits_bitpix_to_type(p->bitpix);
-          p->bitnul = gal_data_alloc_blank(type);
-          p->datatype = gal_fits_type_to_datatype(type);
+          firsttype=p->type;
+          p->bitnul = gal_data_alloc_blank(p->type);
+        }
+      else
+        {
+          if(firsttype!=p->type)
+            error(EXIT_FAILURE, 0, "%s: type is `%s' while revious image(s) "
+                  "were `%s' type. All inputs must have the same pixel data "
+                  "type.\n\nYou can use Gnuastro's Arithmetic program to "
+                  "convert `%s' to `%s', please run this command for more "
+                  "information (press `SPACE' for going down and `q' to "
+                  "return to the command-line):\n\n"
+                  "    $ info Arithmetic\n",
+                  img->name, gal_data_type_as_string(p->type, 1),
+                  gal_data_type_as_string(firsttype, 1), img->name,
+                  gal_data_type_as_string(p->type, 1));
         }
-      else if(firstbitpix!=p->bitpix)
-        error(EXIT_FAILURE, 0, "%s: BITPIX=%d. Previous images had a "
-              "BITPIX value of %d, For "SPACK_NAME" to work, all images "
-              "must have the same pixel data type",
-              img->name, p->bitpix, firstbitpix);
 
       /* In WCS mode, Check resolution and get the first pixel
          positions. */
-      if(p->wcsmode) wcscheckprepare(p, img);
+      if(p->mode==IMGCROP_MODE_WCS) wcs_check_prepare(p, img);
     }
 
-  /* Array of log structures. We will make one more than the needed
-     numbers so that we can put a NULL character in the name section
-     of it to sign its end (something like a string). This is done so
-     we don't have to worry about the length calculation any more! */
-  if(p->up.xcset || p->up.sectionset || p->up.raset || p->up.polygonset)
-    num=1;
-  else
-    num=p->cs0;
-  errno=0;
-  p->log=calloc(num+1, sizeof *p->log);
-  if(p->log==NULL)
-    error(EXIT_FAILURE, errno, "ui.c: %zu bytes for p->log",
-          num+1 * sizeof *p->log);
 
   /* Report timing: */
-  if(p->cp.verb)
+  if(!p->cp.quiet)
     {
-      sprintf(msg, "Read metadata of %zu image%s.", p->numimg,
-              p->numimg>1 ? "s" : "");
+      asprintf(&msg, "Read metadata of %zu image%s.", p->numin,
+              p->numin>1 ? "s" : "");
       gal_timing_report(&t1, msg, 1);
     }
+
+
+  /* Prepare the log file if the user has asked for it. */
+  ui_make_log(p);
 }
 
 
@@ -689,59 +789,57 @@ preparearrays(struct imgcropparams *p)
 /**************************************************************/
 /************         Set the parameters          *************/
 /**************************************************************/
+
 void
-setparams(int argc, char *argv[], struct imgcropparams *p)
+ui_read_check_inputs_setup(int argc, char *argv[], struct imgcropparams *p)
 {
-  struct gal_commonparams *cp=&p->cp;
+  struct gal_options_common_params *cp=&p->cp;
+
+
+  /* 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);
 
-  /* 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. */
+  /* 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 catalog if given. */
-  if(p->up.catname)
-    gal_txtarray_txt_to_array(p->up.catname, &p->cat, &p->cs0, &p->cs1);
+  /* Read the options into the program's structure, and check them and
+     their relations prior to printing. */
+  ui_read_check_only_options(p);
 
-  /* If cp->output was not specified on the command line or in any of
-     the configuration files, then automatic output should be used, in
-     which case, cp->output should be the current directory. */
-  if(p->cp.outputset==0)
-    {
-      p->cp.output=malloc(2+1); /* 2 is length of "./" */
-      if(p->cp.output==NULL)
-        error(EXIT_FAILURE, errno, "space for output");
-      strcpy(p->cp.output, "./");
-      p->cp.outputset=1;
-    }
 
-  /* Do a sanity check. */
-  sanitycheck(p);
-  gal_checkset_check_remove_file(GAL_TXTARRAY_LOG, 0);
+  /* 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);
 
-  /* Everything is ready, notify the user of the program starting. */
-  if(cp->verb)
-    printf(SPACK_NAME" started on %s", ctime(&p->rawtime));
 
-  /* Make the array of input images. */
-  preparearrays(p);
+  /* 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);
 }
 
 
@@ -767,42 +865,32 @@ setparams(int argc, char *argv[], struct imgcropparams *p)
 /************      Free allocated, report         *************/
 /**************************************************************/
 void
-freeandreport(struct imgcropparams *p, struct timeval *t1)
+ui_free_report(struct imgcropparams *p, struct timeval *t1)
 {
   size_t i;
-  int status;
-
-  /* Free the allocated arrays: */
-  free(p->cat);
-  free(p->cp.hdu);
-  free(p->bitnul);
-  free(p->suffix);
-  free(p->wpolygon);
-  free(p->ipolygon);
-
-  /* If these two pointers point to the same place,, that plce will be
-     freed below. */
-  if(p->log[0].name != p->cp.output)
-    free(p->cp.output);
-
-  /* Free the allocated WCS parameters: */
-  for(i=0;i<p->numimg;++i)
-    if(p->imgs[i].wcs)
-      {
-        free(p->imgs[i].wcstxt);
-        status=wcsvfree(&p->imgs[i].nwcs, &p->imgs[i].wcs);
-        if(status)
-          error(EXIT_FAILURE, 0, "wcsvfree ERROR %d: %s", status,
-                wcs_errmsg[status]);
-      }
-  free(p->imgs);
 
-  /* Free the log array: */
-  for(i=0;p->log[i].name;++i)
-    free(p->log[i].name);
-  free(p->log);
+  /* Free the simple arrays (if they were set). */
+  if(p->c1) free(p->c1);
+  if(p->c2) free(p->c2);
+  if(p->cp.hdu) free(p->cp.hdu);
+  if(p->cathdu) free(p->cathdu);
+  if(p->catname) free(p->catname);
+
+  /* The arguments (note that the values were not allocated). */
+  gal_linkedlist_free_stll(p->inputs, 0);
+
+  /* Free the name/ array.  */
+  if(p->name)
+    {
+      for(i=0;i<p->numout;++i)
+        free(p->name[i]);
+      free(p->name);
+    }
+
+  /* Free the log information. */
+  if(p->cp.log) gal_data_free_ll(p->log);
 
   /* Print the final message. */
-  if(p->cp.verb)
-    gal_timing_report(t1, SPACK_NAME" finished in: ", 0);
+  if(!p->cp.quiet)
+    gal_timing_report(t1, PROGRAM_NAME" finished in: ", 0);
 }
diff --git a/bin/imgcrop/ui.h b/bin/imgcrop/ui.h
index b21b6c6..3df472f 100644
--- a/bin/imgcrop/ui.h
+++ b/bin/imgcrop/ui.h
@@ -5,7 +5,7 @@ ImageCrop 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
@@ -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 imgcropparams *p);
+ui_read_check_inputs_setup(int argc, char *argv[], struct imgcropparams *p);
 
 void
-freeandreport(struct imgcropparams *p, struct timeval *t1);
+ui_free_report(struct imgcropparams *p, struct timeval *t1);
 
 #endif
diff --git a/bin/imgcrop/wcsmode.c b/bin/imgcrop/wcsmode.c
index d572e2a..9d99c17 100644
--- a/bin/imgcrop/wcsmode.c
+++ b/bin/imgcrop/wcsmode.c
@@ -48,7 +48,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 /* This function is called from ui.c. Its job is to check the WCS
    values of this  */
 void
-wcscheckprepare(struct imgcropparams *p, struct inputimgs *img)
+wcs_check_prepare(struct imgcropparams *p, struct inputimgs *img)
 {
   double twidth, *pixscale;
   struct wcsprm *wcs=img->wcs;
@@ -76,6 +76,8 @@ wcscheckprepare(struct imgcropparams *p, struct inputimgs 
*img)
           "increase in the declination. You have to flip the "
           "image along the first axis before running ImageCrop",
           img->name, p->cp.hdu);
+
+
   /* Since we are dealing with very accurate values, a multiplication
      by -1 might cause a floating point error. So we have to account
      for the floating point error. */
@@ -123,11 +125,12 @@ wcscheckprepare(struct imgcropparams *p, struct inputimgs 
*img)
     }
 
 
-  /* Get the coordinates of the first pixel in the image. */
+  /* Get the coordinates of the first pixel in the image. Note that `dsize'
+     is in C axises, while pixcrd is in FITS axises. */
   pixcrd[0]=1;               pixcrd[1]=1;
-  pixcrd[2]=img->naxes[0];   pixcrd[3]=1;
-  pixcrd[4]=1;               pixcrd[5]=img->naxes[1];
-  pixcrd[6]=img->naxes[0];   pixcrd[7]=img->naxes[1];
+  pixcrd[2]=img->dsize[1];   pixcrd[3]=1;
+  pixcrd[4]=1;               pixcrd[5]=img->dsize[0];
+  pixcrd[6]=img->dsize[1];   pixcrd[7]=img->dsize[0];
   wcsp2s(wcs, ncoord, nelem, pixcrd, imgcrd, phi, theta,
          img->corners, status);
 
@@ -139,9 +142,10 @@ wcscheckprepare(struct imgcropparams *p, struct inputimgs 
*img)
 
 
   /* Fill in the size of the image in celestial degrees from the first
-     pixel in the image.*/
-  img->sized[0]=img->naxes[0]*p->res/cos(img->corners[1]*M_PI/180);
-  img->sized[1]=img->naxes[1]*p->res;
+     pixel in the image. Note that `dsize' is in C axises, while pixcrd is
+     in FITS axises. */
+  img->sized[0]=img->dsize[1]*p->res/cos(img->corners[1]*M_PI/180);
+  img->sized[1]=img->dsize[0]*p->res;
 
 
   /* In case the image crosses the equator, we will calculate these
@@ -208,7 +212,7 @@ setcsides(struct cropparams *crp)
   double maxra=-FLT_MAX, maxdec=-FLT_MAX;
 
   /* Set the four corners of the WCS region. */
-  if(p->up.polygonset)
+  if(p->polygon)
     {
       /* Find their minimum and maximum values. */
       for(i=0;i<p->nvertices;++i)
@@ -227,16 +231,17 @@ setcsides(struct cropparams *crp)
     }
   else
     {
-      if(p->up.raset)
+      if(p->catname)
         {
-          r=crp->world[0]=p->ra;
-          d=crp->world[1]=p->dec;
+          r=crp->world[0]=p->c1[crp->out_ind];
+          d=crp->world[1]=p->c2[crp->out_ind];
         }
       else
         {
-          r=crp->world[0]=p->cat[ crp->outindex * p->cs1 + p->racol ];
-          d=crp->world[1]=p->cat[ crp->outindex * p->cs1 + p->deccol ];
+          r=crp->world[0]=p->ra;
+          d=crp->world[1]=p->dec;
         }
+
       h=p->wwidth/2;
       dr=d*M_PI/180;
       hr=h*M_PI/180;
@@ -285,24 +290,45 @@ setcsides(struct cropparams *crp)
 
 
 
-/* We have the polygon coordinates */
+/* We have the polygon vertices in WCS coordinates and need to change them
+   to one input image's pixel coordinates. */
 void
 fillcrpipolygon(struct cropparams *crp)
 {
+  size_t i;
+  double *x, *y, *ra, *dec;
   struct imgcropparams *p=crp->p;
 
-  /* Allocate the array to keep the image based polygon sides */
-  errno=0;
-  crp->ipolygon=malloc(2*p->nvertices*sizeof *crp->ipolygon);
-  if(crp->ipolygon==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for crpp->ipolygon in "
-          "onecrop (crop.c)",
-          2*p->nvertices*sizeof *crp->ipolygon);
-
-  /* Fill in the crp->ipolygon array by converting the WCS polygon
-     vertices to this image's coordinates. */
-  gal_wcs_radec_array_to_xy(p->imgs[crp->imgindex].wcs, p->wpolygon,
-                            crp->ipolygon, p->nvertices, 2);
+  /* Allocate the necessary arrays. */
+  x=gal_data_calloc_array(GAL_DATA_TYPE_DOUBLE, p->nvertices);
+  y=gal_data_calloc_array(GAL_DATA_TYPE_DOUBLE, p->nvertices);
+  ra=gal_data_calloc_array(GAL_DATA_TYPE_DOUBLE, p->nvertices);
+  dec=gal_data_calloc_array(GAL_DATA_TYPE_DOUBLE, p->nvertices);
+  crp->ipolygon=gal_data_malloc_array(GAL_DATA_TYPE_DOUBLE, 2*p->nvertices);
+
+  /* Fill in the RA and Dec columns. */
+  for(i=0;i<p->nvertices;++i)
+    {
+      ra[i]=p->wpolygon[i*2];
+      dec[i]=p->wpolygon[i*2+1];
+    }
+
+  /* Convert them to image coordinates. */
+  gal_wcs_world_to_img(p->imgs[crp->in_ind].wcs, ra, dec, &x, &y,
+                       p->nvertices);
+
+  /* Put them in the image polygon vertice array. */
+  for(i=0;i<p->nvertices;++i)
+    {
+      crp->ipolygon[i*2]   = x[i];
+      crp->ipolygon[i*2+1] = y[i];
+    }
+
+  /* Clean up. */
+  free(x);
+  free(y);
+  free(ra);
+  free(dec);
 }
 
 
@@ -469,9 +495,9 @@ radecoverlap(struct cropparams *crp)
 
   /* First check if the four sides of the crop box are in the image.*/
   fd=(d=crp->corners)+8;
-  s=p->imgs[crp->imgindex].sized;
-  i=p->imgs[crp->imgindex].corners;
-  c=p->imgs[crp->imgindex].equatorcorr;
+  s=p->imgs[crp->in_ind].sized;
+  i=p->imgs[crp->in_ind].corners;
+  c=p->imgs[crp->in_ind].equatorcorr;
   do
     {
       if( radecinimg(d, i, s, c) ) return 1;
@@ -484,7 +510,7 @@ radecoverlap(struct cropparams *crp)
   s=crp->sized;
   i=crp->corners;
   c=crp->equatorcorr;
-  fd=(d=p->imgs[crp->imgindex].corners)+8;
+  fd=(d=p->imgs[crp->in_ind].corners)+8;
   do
     {
       if( radecinimg(d, i, s, c) ) return 1;
diff --git a/bin/imgcrop/wcsmode.h b/bin/imgcrop/wcsmode.h
index 11055fe..e63cf01 100644
--- a/bin/imgcrop/wcsmode.h
+++ b/bin/imgcrop/wcsmode.h
@@ -24,7 +24,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #define WCSMODE_H
 
 void
-wcscheckprepare(struct imgcropparams *p, struct inputimgs *img);
+wcs_check_prepare(struct imgcropparams *p, struct inputimgs *img);
 
 void
 setcsides(struct cropparams *crp);
diff --git a/bin/imgstat/cite.h b/bin/imgstat/authors-cite.h
similarity index 57%
rename from bin/imgstat/cite.h
rename to bin/imgstat/authors-cite.h
index 4193345..1178af1 100644
--- a/bin/imgstat/cite.h
+++ b/bin/imgstat/authors-cite.h
@@ -5,7 +5,7 @@ ImgeStatistics 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) 2017, 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
@@ -20,19 +20,19 @@ 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 CITE_H
-#define CITE_H
-
-#define IMGSTATBIBTEX ""
-
-#define PRINTCITEABORT {                                                \
-    printf("\nWe hope %s has been useful for your research.\n"          \
-           "Citations are vital for the continued work on %s.\n"        \
-           "Thank you for citing it in your research paper.\n"          \
-           "\nPlease cite as \"%s\":\n\n%s\n\n%s",                      \
-           SPACK_NAME, SPACK_NAME, SPACK_STRING,                        \
-           GAL_STRINGS_MAIN_BIBTEX, IMGSTATBIBTEX);                     \
-    exit(EXIT_SUCCESS);                                                 \
-}
+#ifndef AUTHORS_CITE_H
+#define AUTHORS_CITE_H
+
+/* When any specific citation is necessary, please add its BibTeX (from ADS
+   hopefully) to this variable along with a title decribing what this
+   paper/book does for the progarm in a short line. In the following line
+   put a row of `-' with the same length and then put the BibTeX.
+
+   See the `gnuastro_bibtex' variable in `lib/options' (from the top
+   Gnuastro source code directory) as an example.*/
+
+#define PROGRAM_BIBTEX "";
+
+#define PROGRAM_AUTHORS "Mohammad Akhlaghi";
 
 #endif
diff --git a/bin/imgwarp/cite.h b/bin/imgwarp/authors-cite.h
similarity index 57%
rename from bin/imgwarp/cite.h
rename to bin/imgwarp/authors-cite.h
index 8a88e17..23958b5 100644
--- a/bin/imgwarp/cite.h
+++ b/bin/imgwarp/authors-cite.h
@@ -5,7 +5,7 @@ ImageWarp 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) 2017, 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
@@ -20,19 +20,19 @@ 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 CITE_H
-#define CITE_H
-
-#define IMGWARPBIBTEX ""
-
-#define PRINTCITEABORT {                                                \
-    printf("\nWe hope %s has been useful for your research.\n"          \
-           "Citations are vital for the continued work on %s.\n"        \
-           "Thank you for citing it in your research paper.\n"          \
-           "\nPlease cite as \"%s\":\n\n%s\n\n%s",                      \
-           SPACK_NAME, SPACK_NAME, SPACK_STRING,                        \
-           GAL_STRINGS_MAIN_BIBTEX, IMGWARPBIBTEX);                     \
-    exit(EXIT_SUCCESS);                                                 \
-}
+#ifndef AUTHORS_CITE_H
+#define AUTHORS_CITE_H
+
+/* When any specific citation is necessary, please add its BibTeX (from ADS
+   hopefully) to this variable along with a title decribing what this
+   paper/book does for the progarm in a short line. In the following line
+   put a row of `-' with the same length and then put the BibTeX.
+
+   See the `gnuastro_bibtex' variable in `lib/options' (from the top
+   Gnuastro source code directory) as an example.*/
+
+#define PROGRAM_BIBTEX "";
+
+#define PROGRAM_AUTHORS "Mohammad Akhlaghi";
 
 #endif
diff --git a/bin/mkcatalog/authors-cite.h b/bin/mkcatalog/authors-cite.h
new file mode 100644
index 0000000..5022b41
--- /dev/null
+++ b/bin/mkcatalog/authors-cite.h
@@ -0,0 +1,54 @@
+/*********************************************************************
+MakeCatalog - Make a catalog from an input and labeled image.
+MakeCatalog is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+     Mohammad Akhlaghi <address@hidden>
+Contributing author(s):
+Copyright (C) 2017, 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
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+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 AUTHORS_CITE_H
+#define AUTHORS_CITE_H
+
+/* When any specific citation is necessary, please add its BibTeX (from ADS
+   hopefully) to this variable along with a title decribing what this
+   paper/book does for the progarm in a short line. In the following line
+   put a row of `-' with the same length and then put the BibTeX.
+
+   See the `gnuastro_bibtex' variable in `lib/options' (from the top
+   Gnuastro source code directory) as an example.*/
+
+#define PROGRAM_BIBTEX                                                 \
+  "Description of MakeCatalog"                                         \
+  "--------------------------"                                         \
+  "@ARTICLE{2016arXiv161106387A,\n"                                    \
+  "   author = {{Akhlaghi}, M.},\n"                                    \
+  "    title = \"{Separating detection and catalog production}\",\n"   \
+  "  journal = {ASP Conf. Ser. (in press)},\n"                         \
+  "archivePrefix = \"arXiv\",\n"                                       \
+  "   eprint = {1611.06387},\n"                                        \
+  "primaryClass = \"astro-ph.IM\",\n"                                  \
+  " keywords = {Astrophysics - Instrumentation and Methods for "       \
+               "Astrophysics},\n"                                      \
+  "     year = 2016,\n"                                                \
+  "    month = nov,\n"                                                 \
+  "   adsurl = {http://adsabs.harvard.edu/abs/2016arXiv161106387A},\n"; \
+  "  adsnote = {Provided by the SAO/NASA Astrophysics Data System}\n"  \
+  "};\n"
+
+#define PROGRAM_AUTHORS "Mohammad Akhlaghi";
+
+#endif
diff --git a/bin/mkcatalog/cite.h b/bin/mkcatalog/cite.h
deleted file mode 100644
index 5b5c609..0000000
--- a/bin/mkcatalog/cite.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*********************************************************************
-MakeCatalog - Make a catalog from an input and labeled image.
-MakeCatalog is part of GNU Astronomy Utilities (Gnuastro) package.
-
-Original author:
-     Mohammad Akhlaghi <address@hidden>
-Contributing author(s):
-Copyright (C) 2015, 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
-Free Software Foundation, either version 3 of the License, or (at your
-option) any later version.
-
-Gnuastro is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-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 CITE_H
-#define CITE_H
-
-#define MKCATALOGBIBTEX ""
-
-#define PRINTCITEABORT {                                                \
-    printf("\nWe hope %s has been useful for your research.\n"          \
-           "Citations are vital for the continued work on %s.\n"        \
-           "Thank you for citing it in your research paper.\n"          \
-           "\nPlease cite as \"%s\":\n\n%s\n\n%s",                      \
-           SPACK_NAME, SPACK_NAME, SPACK_STRING,                        \
-           GAL_STRINGS_MAIN_BIBTEX, MKCATALOGBIBTEX);                   \
-    exit(EXIT_SUCCESS);                                                 \
-}
-
-#endif
diff --git a/bin/mknoise/cite.h b/bin/mknoise/authors-cite.h
similarity index 57%
rename from bin/mknoise/cite.h
rename to bin/mknoise/authors-cite.h
index b72eda7..3a4bb5e 100644
--- a/bin/mknoise/cite.h
+++ b/bin/mknoise/authors-cite.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) 2017, 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
@@ -20,19 +20,19 @@ 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 CITE_H
-#define CITE_H
-
-#define MKNOISEBIBTEX ""
-
-#define PRINTCITEABORT {                                                \
-    printf("\nWe hope %s has been useful for your research.\n"          \
-           "Citations are vital for the continued work on %s.\n"        \
-           "Thank you for citing it in your research paper.\n"          \
-           "\nPlease cite as \"%s\":\n\n%s\n\n%s",                      \
-           SPACK_NAME, SPACK_NAME, SPACK_STRING,                        \
-           GAL_STRINGS_MAIN_BIBTEX, MKNOISEBIBTEX);                     \
-    exit(EXIT_SUCCESS);                                                 \
-}
+#ifndef AUTHORS_CITE_H
+#define AUTHORS_CITE_H
+
+/* When any specific citation is necessary, please add its BibTeX (from ADS
+   hopefully) to this variable along with a title decribing what this
+   paper/book does for the progarm in a short line. In the following line
+   put a row of `-' with the same length and then put the BibTeX.
+
+   See the `gnuastro_bibtex' variable in `lib/options' (from the top
+   Gnuastro source code directory) as an example.*/
+
+#define PROGRAM_BIBTEX "";
+
+#define PROGRAM_AUTHORS "Mohammad Akhlaghi";
 
 #endif
diff --git a/bin/mkprof/args.h b/bin/mkprof/args.h
index 860c8f3..c37f8d1 100644
--- a/bin/mkprof/args.h
+++ b/bin/mkprof/args.h
@@ -170,7 +170,7 @@ struct argp_option program_options[] =
       "No. of random points in Monte Carlo integration.",
       ARGS_GROUP_PROFILES,
       &p->numrandom,
-      GAL_DATA_TYPE_ULONG,
+      GAL_DATA_TYPE_SIZE_T,
       GAL_OPTIONS_RANGE_GT_0,
       GAL_OPTIONS_MANDATORY,
       GAL_OPTIONS_NOT_SET
diff --git a/bin/mkprof/mkprof.c b/bin/mkprof/mkprof.c
index 3da39cb..00239e3 100644
--- a/bin/mkprof/mkprof.c
+++ b/bin/mkprof/mkprof.c
@@ -367,44 +367,6 @@ mkprof_build(void *inparam)
 /**************************************************************/
 /************              The writer             *************/
 /**************************************************************/
-static void
-mkprof_write_log(struct mkprofparams *p)
-{
-  char *comments, gitdescribe[100], *gd;
-
-  /* This function is only relevant if a log file was desired. */
-  if(!p->cp.log) return;
-
-  /* Get the Git description in the running folder. */
-  gd=gal_git_describe();
-  if(gd) sprintf(gitdescribe, " from %s,", gd);
-  else   gitdescribe[0]='\0';
-
-  /* Make the comments. */
-  asprintf(&comments, "# %s\n# Created%s on %s# Zeropoint: %.4f",
-           PROGRAM_STRING, gitdescribe, ctime(&p->rawtime), p->zeropoint);
-
-  /* Write the log file to disk */
-  gal_table_write(p->log, comments, GAL_TABLE_FORMAT_TXT, LOGFILENAME,
-                  p->cp.dontdelete);
-  free(comments);
-
-  /* In verbose mode, print the information. */
-  if(!p->cp.quiet)
-    {
-      asprintf(&comments, "%s created.", LOGFILENAME);
-      gal_timing_report(NULL, comments, 1);
-      free(comments);
-    }
-
-  /* Clean up. */
-  gal_data_free_ll(p->log);
-}
-
-
-
-
-
 void
 mkprof_write(struct mkprofparams *p)
 {
@@ -607,6 +569,7 @@ mkprof(struct mkprofparams *p)
 {
   int err;
   pthread_t t;            /* Thread id not used, all are saved here. */
+  char *comments;
   pthread_attr_t attr;
   pthread_barrier_t b;
   struct mkonthread *mkp;
@@ -677,7 +640,13 @@ mkprof(struct mkprofparams *p)
   mkprof_write(p);
 
   /* Write the log file. */
-  mkprof_write_log(p);
+  if(p->cp.log)
+    {
+      asprintf(&comments, "# Zeropoint: %.4f", p->zeropoint);
+      gal_options_print_log(p->log, PROGRAM_STRING, &p->rawtime, comments,
+                            LOGFILENAME, &p->cp);
+      free(comments);
+    }
 
   /* If numthreads>1, then wait for all the jobs to finish and destroy
      the attribute and barrier. */
diff --git a/bin/mkprof/ui.c b/bin/mkprof/ui.c
index 2bcb4ca..db92037 100644
--- a/bin/mkprof/ui.c
+++ b/bin/mkprof/ui.c
@@ -302,11 +302,6 @@ ui_read_check_only_options(struct mkprofparams *p)
           "a column for the position along the %s axis with the `%s' option",
           p->racol?"racol":"deccol", p->racol?"Dec":"RA",
           p->xcol?"deccol":"racol");
-
-  /* If a log file is to be created, make sure that one doesn't already
-     exist. */
-  if(p->cp.log)
-    gal_checkset_check_remove_file(LOGFILENAME, p->cp.dontdelete);
 }
 
 
@@ -455,9 +450,6 @@ ui_read_cols(struct mkprofparams *p)
      the same as those that were wanted (it might be more). */
   while(cols!=NULL)
     {
-      /* Increment the column counter. */
-      ++counter;
-
       /* Pop out the top node. */
       tmp=gal_data_pop_from_ll(&cols);
 
@@ -465,7 +457,7 @@ ui_read_cols(struct mkprofparams *p)
       /* 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
          values into the `x' and `y' arrays even if they are RA/Dec. */
-      switch(counter)
+      switch(++counter)
         {
         case 9:
           colname="first axis position";
@@ -548,17 +540,7 @@ ui_read_cols(struct mkprofparams *p)
         /* If the index isn't recognized, then it is larger, showing that
            there was more than one match for the given criteria */
         default:
-          error(EXIT_FAILURE, 0, "there was more than one match for at "
-                "least one of the input columns from `%s'. You can check "
-                "the column information with the following command, and "
-                "correct the options ending with `col' appropriately.\n\n"
-                "   $ asttable --information %s\n\n"
-                "The current values to all options can be checked by calling "
-                "the `--printparams' (or `-P') option. To learn more about "
-                "how the columns are selected, please try the following "
-                "command:\n\n"
-                "   $ info gnuastro \"Selecting table columns\" ",
-                p->catname, p->catname);
+          gal_table_too_many_columns(p->catname);
         }
 
       /* Sanity check and clean up.  Note that it might happen that the
@@ -577,7 +559,7 @@ ui_read_cols(struct mkprofparams *p)
              structure. Hence, we should set the structure's pointer to
              NULL so the important data isn't freed.*/
           corrtype->array=NULL;
-          free(corrtype);
+          gal_data_free(corrtype);
         }
     }
 }
@@ -1086,6 +1068,10 @@ ui_free_report(struct mkprofparams *p, struct timeval 
*t1)
   /* Free the random number generator: */
   gsl_rng_free(p->rng);
 
+  /* Free the log file information. */
+  if(p->cp.log)
+    gal_data_free_ll(p->log);
+
   /* Report the duration of the job */
   if(!p->cp.quiet)
     gal_timing_report(t1,  PROGRAM_NAME" finished in", 0);
diff --git a/bin/noisechisel/cite.h b/bin/noisechisel/authors-cite.h
similarity index 57%
rename from bin/noisechisel/cite.h
rename to bin/noisechisel/authors-cite.h
index 5777694..9589300 100644
--- a/bin/noisechisel/cite.h
+++ b/bin/noisechisel/authors-cite.h
@@ -5,7 +5,7 @@ NoiseChisel 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) 2017, 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
@@ -20,19 +20,19 @@ 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 CITE_H
-#define CITE_H
-
-#define NOISECHISELBIBTEX ""
-
-#define PRINTCITEABORT {                                                \
-    printf("\nWe hope %s has been useful for your research.\n"          \
-           "Citations are vital for the continued work on %s.\n"        \
-           "Thank you for citing it in your research paper.\n"          \
-           "\nPlease cite as \"%s\":\n\n%s\n\n%s",                      \
-           SPACK_NAME, SPACK_NAME, SPACK_STRING,                        \
-           GAL_STRINGS_MAIN_BIBTEX, NOISECHISELBIBTEX);                 \
-    exit(EXIT_SUCCESS);                                                 \
-}
+#ifndef AUTHORS_CITE_H
+#define AUTHORS_CITE_H
+
+/* When any specific citation is necessary, please add its BibTeX (from ADS
+   hopefully) to this variable along with a title decribing what this
+   paper/book does for the progarm in a short line. In the following line
+   put a row of `-' with the same length and then put the BibTeX.
+
+   See the `gnuastro_bibtex' variable in `lib/options' (from the top
+   Gnuastro source code directory) as an example.*/
+
+#define PROGRAM_BIBTEX "";
+
+#define PROGRAM_AUTHORS "Mohammad Akhlaghi";
 
 #endif
diff --git a/bin/subtractsky/cite.h b/bin/subtractsky/authors-cite.h
similarity index 57%
rename from bin/subtractsky/cite.h
rename to bin/subtractsky/authors-cite.h
index 866153d..ad08147 100644
--- a/bin/subtractsky/cite.h
+++ b/bin/subtractsky/authors-cite.h
@@ -5,7 +5,7 @@ SubtractSky 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) 2017, 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
@@ -20,19 +20,19 @@ 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 CITE_H
-#define CITE_H
-
-#define SUBTRACTSKYBIBTEX ""
-
-#define PRINTCITEABORT {                                                \
-    printf("\nWe hope %s has been useful for your research.\n"          \
-           "Citations are vital for the continued work on %s.\n"        \
-           "Thank you for citing it in your research paper.\n"          \
-           "\nPlease cite as \"%s\":\n\n%s\n\n%s",                      \
-           SPACK_NAME, SPACK_NAME, SPACK_STRING,                        \
-           GAL_STRINGS_MAIN_BIBTEX, SUBTRACTSKYBIBTEX);                 \
-    exit(EXIT_SUCCESS);                                                 \
-}
+#ifndef AUTHORS_CITE_H
+#define AUTHORS_CITE_H
+
+/* When any specific citation is necessary, please add its BibTeX (from ADS
+   hopefully) to this variable along with a title decribing what this
+   paper/book does for the progarm in a short line. In the following line
+   put a row of `-' with the same length and then put the BibTeX.
+
+   See the `gnuastro_bibtex' variable in `lib/options' (from the top
+   Gnuastro source code directory) as an example.*/
+
+#define PROGRAM_BIBTEX "";
+
+#define PROGRAM_AUTHORS "Mohammad Akhlaghi";
 
 #endif
diff --git a/bin/table/main.c b/bin/table/main.c
index d34ebd1..663c8ce 100644
--- a/bin/table/main.c
+++ b/bin/table/main.c
@@ -49,7 +49,7 @@ main (int argc, char *argv[])
   table(&p);
 
   /* Free all non-freed allocations. */
-  freeandreport(&p);
+  ui_free_report(&p);
 
   /* Return successfully.*/
   return EXIT_SUCCESS;
diff --git a/bin/table/ui.c b/bin/table/ui.c
index b96b6b9..9b0cf4e 100644
--- a/bin/table/ui.c
+++ b/bin/table/ui.c
@@ -317,7 +317,7 @@ ui_preparations(struct tableparams *p)
          information. */
       if(p->information)
         {
-          freeandreport(p);
+          ui_free_report(p);
           exit(EXIT_SUCCESS);
         }
       else
@@ -444,7 +444,7 @@ ui_read_check_inputs_setup(int argc, char *argv[], struct 
tableparams *p)
 /************      Free allocated, report         *************/
 /**************************************************************/
 void
-freeandreport(struct tableparams *p)
+ui_free_report(struct tableparams *p)
 {
   /* Free the allocated arrays: */
   free(p->cp.hdu);
diff --git a/bin/table/ui.h b/bin/table/ui.h
index 471948d..a0f5420 100644
--- a/bin/table/ui.h
+++ b/bin/table/ui.h
@@ -27,6 +27,6 @@ void
 ui_read_check_inputs_setup(int argc, char *argv[], struct tableparams *p);
 
 void
-freeandreport(struct tableparams *p);
+ui_free_report(struct tableparams *p);
 
 #endif
diff --git a/configure.ac b/configure.ac
index 68bdf2f..266955d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -131,6 +131,17 @@ AC_FUNC_MALLOC
 
 
 
+
+# Check the size of `size_t'.
+AC_CHECK_SIZEOF([size_t])
+AC_SUBST(SIZEOF_SIZE_T, [$ac_cv_sizeof_size_t])
+AC_DEFINE_UNQUOTED([GAL_CONFIG_SIZEOF_SIZE_T], [$ac_cv_sizeof_size_t],
+                   [On 32bit will be 4, on 64 bit, will be 8])
+
+
+
+
+
 # Search for necessary libraries. After each library is found,
 # AC_SEARCH_LIBS adds the -lLIBRARY flag to the LIBS variable which is then
 # given to all the Makefiles. Each new flag is added to the left of the old
@@ -282,7 +293,7 @@ binop_ushort=0
 binop_short=0
 binop_uint=0
 binop_int=0
-binop_ulong=0
+binop_ulong=1
 binop_long=1
 binop_longlong=0
 binop_float=1
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index f229ebc..d53448c 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -6971,14 +6971,15 @@ can be defined in multiple ways as listed below.
 @table @asis
 @item Center of multiple crops (in a catalog)
 The center of (possibly multiple) crops are read from a text file. A
-catalog can also contain WCS coordinates, so @option{--imgmode} has to be
-called/activated. The @option{--xcol} and @option{--ycol} columns in the
-catalog are interpreted as the center of a square crop with a width of
address@hidden pixels (an odd number). The columns can contain any
-floating point value. The value to @option{--output} option is seen as a
-directory which will host (the possibly multiple) separate crop files, see
address@hidden output} for more. For a tutorial using this feature, please
-see @ref{Hubble visually checks and classifies his catalog}.
+catalog can also contain WCS coordinates, so @option{--mode=img} is
+necessary to avoid ambiguity when all columns are specified. The
address@hidden and @option{--ycol} columns in the catalog are interpreted
+as the center of a square crop with a width of @option{--iwidth} pixels (an
+odd number). The columns can contain any floating point value. The value to
address@hidden option is seen as a directory which will host (the
+possibly multiple) separate crop files, see @ref{ImageCrop output} for
+more. For a tutorial using this feature, please see @ref{Hubble visually
+checks and classifies his catalog}.
 
 @item Center of a single crop (on the command-line)
 The center of the crop is given on the command-line with the @option{--xc}
@@ -6997,8 +6998,8 @@ The latter option (@option{--polygon}) is a higher-level 
method to define
 any convex polygon (with any number of vertices) with floating point
 values. Please see the description of this option in @ref{Invoking
 astimgcrop} for its syntax. It is available in both Image and WCS modes,
-hence, to read the vertices as pixel coordinates, @option{--imgmode} has to
-be called/activated.
+hence, to read the vertices as pixel coordinates, @option{--mode=img} has
+to be called.
 @end table
 
 @item WCS coordinates
@@ -7027,10 +7028,11 @@ listed below.
 @table @asis
 
 @item Center of multiple crops (in a catalog)
-Similar to catalog inputs in Image mode (above), but @option{--wcsmode} has
-to be activated. The central RA and Dec value for each crop will be read
-from the @option{--racol} and @option{--deccol} columns of the input
-catalog. The square cropped box will have an odd number of pixels.
+Similar to catalog inputs in Image mode (above), but @option{--mode=wcs}
+has to be activated to avoid ambiguity. The central RA and Dec value for
+each crop will be read from the @option{--racol} and @option{--deccol}
+columns of the input catalog. The square cropped box will have an odd
+number of pixels.
 
 @item Center of a single crop (on the command-line)
 You can specify the center of only one crop box with the @option{--ra} and
@@ -7042,7 +7044,7 @@ The @option{--polygon} option is a high-level method to 
define any convex
 polygon (with any number of vertices). Please see the description of this
 option in @ref{Invoking astimgcrop} for its syntax. It is available in both
 Image and WCS modes, hence, to read the vertices as RA and Dec coordinates,
address@hidden has to be called/activated.
address@hidden has to be called/activated.
 @end table
 
 @cartouche
@@ -7060,22 +7062,25 @@ align the input image with these coordinates, see 
@ref{ImageWarp}.
 As a summary, if you don't specify a catalog, you have to define the
 cropped region manually on the command-line. Other than the
 @option{--polygon} option, the other methods to define a single crop are
-uniqe to each mode, so the mode options (@option{--imgmode} or
address@hidden) will be ignored. When using a catalog, or
address@hidden, the modes have to be specified to correctly interpret
-the values.
+uniqe to each mode, so the mode (@option{--mode}) will be ignored. When
+using a catalog to define the crop centers, if the columns to only one mode
+are given (for example only @option{--xcol} and @option{--ycol}, not the
+WCS columns) then the mode is irrelevant. However, when all image and WCS
+mode columns are given, @option{--mode} is mandatory (you can keep the
+columns in a configuration file and simply set the mode, see
address@hidden files} and @ref{Selecting table columns}). When using
address@hidden the mode is mandatory to interpret the values correctly.
 
 
 @node Crop section syntax, Blank pixels, ImageCrop modes, ImageCrop
 @subsection Crop section syntax
 
 @cindex Crop a given section of image
-When in image mode, one of the methods to crop only one rectangular
-section from the input image is to use the @option{--section}
-option. ImageCrop has a powerful syntax to read the box parameters
-from a string of characters. If you leave certain parts of the string
-to be empty, ImageCrop can fill them for you based on the input image
-sizes.
+When in image mode, one of the methods to crop only one rectangular section
+from the input image is to use the @option{--section} option. ImageCrop has
+a powerful syntax to read the box parameters from a string of
+characters. If you leave certain parts of the string to be empty, ImageCrop
+can fill them for you based on the input image sizes.
 
 @cindex Define section to crop
 To define a box, you need the coordinates of two points: the first
@@ -7364,12 +7369,12 @@ the shallow region? Running ImageCrop with 
@option{--polygon} will easily
 pull out this region of the image for you irrespective of the
 resolution. If you have set the operating mode to WCS mode in your nearest
 configuration file (see @ref{Configuration files}), there is no need to
-call @option{--wcsmode} on the command line. You may also provide many FITS
+call @option{--mode=wcs} on the command line. You may also provide many FITS
 images/tiles and ImageCrop will stitch them to produce this cropped region:
 
 @example
-$ astimgcrop --wcsmode desired-filter-image(s).fits        \
-  --polygon="53.187414,-27.779152 : 53.159507,-27.759633 : \
+$ astimgcrop --mode=wcs desired-filter-image(s).fits        \
+  --polygon="53.187414,-27.779152 : 53.159507,-27.759633 :  \
              53.134517,-27.787144 : 53.161906,-27.807208"
 @end example
 
@@ -7453,8 +7458,9 @@ the weight images as input and @option{--suffix=_w.fits}.
 @item -b
 @itemx --noblank
 Pixels outside of the input image that are in the crop box will not be
-used. By default they are filled with blank values (depending on
-type), see @ref{Blank pixels}.
+used. By default they are filled with blank values (depending on type), see
address@hidden pixels}. This option only applies only in Image mode, see
address@hidden modes}.
 
 @item -z
 @itemx --zeroisnotblank
@@ -7469,15 +7475,11 @@ with this option, see @ref{Blank pixels}.
 Operating mode options:
 @table @option
 
address@hidden -I
address@hidden --imgmode
-Operate in Image mode as described above. This option is only useful
-when catalog is being provided. If coordinates are given on the
-command-line, the mode is automatically set based on them.
-
address@hidden -W
address@hidden --wcsmode
-Operate in WCS mode. See explanations for @option{--imgmode}.
address@hidden -M STR
address@hidden --mode=STR
+Operate in Image mode or WCS mode when the input coordinates can be both
+image or WCS. The value must either be @option{img} or @option{wcs}, see
address@hidden modes} for a full description.
 
 @end table
 
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 9d32013..c198e9f 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -117,6 +117,7 @@ gnuastro/config.h: Makefile config.h.in
               -e 's|@address@hidden|$(HAVE_BIN_OP_LONGLONG)|g'  \
               -e 's|@address@hidden|$(HAVE_BIN_OP_FLOAT)|g'        \
               -e 's|@address@hidden|$(HAVE_BIN_OP_DOUBLE)|g'      \
+              -e 's|@address@hidden|$(SIZEOF_SIZE_T)|g'                \
                $(srcdir)/config.h.in >> address@hidden
        chmod a-w address@hidden
        mv address@hidden $@
diff --git a/lib/arithmetic-binary.c b/lib/arithmetic-binary.c
index 9fd0d62..654d723 100644
--- a/lib/arithmetic-binary.c
+++ b/lib/arithmetic-binary.c
@@ -469,7 +469,7 @@ arithmetic_binary(int operator, unsigned char flags, 
gal_data_t *lo,
       BINARY_LT_IS_DOUBLE;
     default:
       error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`data_arithmetic_binary'", l->type);
+            "`arithmetic_binary'", l->type);
     }
 
 
diff --git a/lib/arithmetic-onlyint.c b/lib/arithmetic-onlyint.c
index b848edc..831bb65 100644
--- a/lib/arithmetic-onlyint.c
+++ b/lib/arithmetic-onlyint.c
@@ -354,6 +354,21 @@ arithmetic_onlyint_binary(int operator, unsigned char 
flags,
   r=gal_arithmetic_convert_to_compiled_type(ro, flags);
 
 
+  /* Sanity check: see if the compiled type is actually an integer. */
+  if( l->type>=GAL_DATA_TYPE_FLOAT || r->type>=GAL_DATA_TYPE_FLOAT )
+    error(EXIT_FAILURE, 0, "no larger integer compiled type. The `%s' "
+          "operator can only work on integer types. The left and right "
+          "operands had types `%s' and `%s'.\n\nYou can use the "
+          "`--enable-bin-op-XXXX' at configure time to compile a larger "
+          "type (note that unsigned types are considered to be larger than "
+          "signed ones). You can run the following command for more "
+          "information on these options (press the `SPACE' key to go down "
+          "and `q' to return to the command-line):\n\n"
+          "    $ info gnuastro \"Gnuastro configure options\"\n",
+          gal_arithmetic_operator_string(operator),
+          gal_data_type_as_string(lo->type, 1),
+          gal_data_type_as_string(ro->type, 1));
+
   /* Set the output type. */
   otype=gal_data_out_type(l, r);
 
@@ -401,7 +416,7 @@ arithmetic_onlyint_binary(int operator, unsigned char flags,
       BINOIN_LT_IS_LONGLONG;
     default:
       error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`data_arithmetic_binary'", l->type);
+            "`arithmetic_onlyint_binary'", l->type);
     }
 
 
diff --git a/lib/commonopts.h b/lib/commonopts.h
index 067c7f9..6012fa8 100644
--- a/lib/commonopts.h
+++ b/lib/commonopts.h
@@ -85,7 +85,6 @@ struct argp_option gal_commonopts_options[] =
 
 
 
-
     {
       0, 0, 0, 0,
       "Output:",
@@ -174,7 +173,7 @@ struct argp_option gal_commonopts_options[] =
       "Number of CPU threads to use.",
       GAL_OPTIONS_GROUP_OPERATING_MODE,
       &cp->numthreads,
-      GAL_DATA_TYPE_ULONG,
+      GAL_DATA_TYPE_SIZE_T,
       GAL_OPTIONS_RANGE_GT_0,
       GAL_OPTIONS_NOT_MANDATORY,
       GAL_OPTIONS_NOT_SET
@@ -187,7 +186,7 @@ struct argp_option gal_commonopts_options[] =
       "Minimum no. bytes to map arrays to hdd/ssd.",
       GAL_OPTIONS_GROUP_OPERATING_MODE,
       &cp->minmapsize,
-      GAL_DATA_TYPE_ULONG,
+      GAL_DATA_TYPE_SIZE_T,
       GAL_OPTIONS_RANGE_GE_0,
       GAL_OPTIONS_NOT_MANDATORY,
       GAL_OPTIONS_NOT_SET
@@ -197,7 +196,7 @@ struct argp_option gal_commonopts_options[] =
       GAL_OPTIONS_KEY_LOG,
       0,
       0,
-      "No log file for programs which make one.",
+      "Information about output(s) in a log file.",
       GAL_OPTIONS_GROUP_OPERATING_MODE,
       &cp->log,
       GAL_OPTIONS_NO_ARG_TYPE,
diff --git a/lib/config.h.in b/lib/config.h.in
index 8a79b06..8071c55 100644
--- a/lib/config.h.in
+++ b/lib/config.h.in
@@ -49,6 +49,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #define GAL_CONFIG_BIN_OP_FLOAT         @HAVE_BIN_OP_FLOAT@
 #define GAL_CONFIG_BIN_OP_DOUBLE        @HAVE_BIN_OP_DOUBLE@
 
+#define GAL_CONFIG_SIZEOF_SIZE_T        @SIZEOF_SIZE_T@
 
 
 /* C++ Preparations */
diff --git a/lib/data.c b/lib/data.c
index e7adcb0..2a4cf8f 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -1846,9 +1846,224 @@ gal_data_flag_blank(gal_data_t *data)
 
 
 /*************************************************************
- **************       Types and copying        ***************
+ **************            Copying             ***************
  *************************************************************/
 
+/* Only to be used in `data_copy_from_string'. */
+static void
+data_copy_to_string_not_parsed(char *string, void *to, int type)
+{
+  if( strcmp(string, GAL_DATA_BLANK_STRING) )
+    gal_data_set_blank(to, type);
+  else
+    error(EXIT_FAILURE, 0, "`%s' couldn't be parsed as `%s' type",
+          string, gal_data_type_as_string(type, 1));
+}
+
+
+
+
+
+/* The `from' array is an array of strings. We want to keep it as
+   numbers. Note that the case where both input and output structures are
+   string was */
+static void
+data_copy_from_string(gal_data_t *from, gal_data_t *to)
+{
+  size_t i;
+  void *ptr;
+  char **strarr=from->array, **outstrarr=to->array;
+
+  /* Sanity check. */
+  if(from->type!=GAL_DATA_TYPE_STRING)
+    error(EXIT_FAILURE, 0, "`from' in `data_copy_from_string' must have "
+          "a string type.");
+
+  /* Do the copying. */
+  for(i=0;i<from->size;++i)
+    {
+      /* Set the pointer. */
+      switch(to->type)
+        {
+        case GAL_DATA_TYPE_UCHAR:    ptr = (unsigned char *)(to->array) + i;
+          break;
+        case GAL_DATA_TYPE_CHAR:     ptr = (char *)(to->array) + i;
+          break;
+        case GAL_DATA_TYPE_USHORT:   ptr = (unsigned short *)(to->array) + i;
+          break;
+        case GAL_DATA_TYPE_SHORT:    ptr = (short *)(to->array) + i;
+          break;
+        case GAL_DATA_TYPE_UINT:     ptr = (unsigned int *)(to->array) + i;
+          break;
+        case GAL_DATA_TYPE_INT:      ptr = (int *)(to->array) + i;
+          break;
+        case GAL_DATA_TYPE_ULONG:    ptr = (unsigned long *)(to->array) + i;
+          break;
+        case GAL_DATA_TYPE_LONG:     ptr = (long *)(to->array) + i;
+          break;
+        case GAL_DATA_TYPE_LONGLONG: ptr = (LONGLONG *)(to->array) + i;
+          break;
+        case GAL_DATA_TYPE_FLOAT:    ptr = (float *)(to->array) + i;
+          break;
+        case GAL_DATA_TYPE_DOUBLE:   ptr = (double *)(to->array) + i;
+          break;
+
+        case GAL_DATA_TYPE_BIT:
+        case GAL_DATA_TYPE_STRLL:
+        case GAL_DATA_TYPE_COMPLEX:
+        case GAL_DATA_TYPE_DCOMPLEX:
+          error(EXIT_FAILURE, 0, "`data_copy_from_string' currently doesn't "
+                "support copying to %s type",
+                gal_data_type_as_string(to->type, 1));
+          break;
+
+        default:
+          error(EXIT_FAILURE, 0, "type %d not recognized for to->type in "
+                "`data_copy_from_string'", to->type);
+        }
+
+      /* Read/put the input into the output. */
+      if(to->type==GAL_DATA_TYPE_STRING)
+        gal_checkset_allocate_copy(strarr[i], &outstrarr[i]);
+      else
+        {
+          if( gal_data_string_to_type(&ptr, strarr[i], to->type) )
+            data_copy_to_string_not_parsed(strarr[i], ptr, to->type);
+        }
+    }
+}
+
+
+
+
+
+/* Convert any given type into a string by printing it into the elements of
+   the already allocated `to->array'. */
+static void
+data_copy_to_string(gal_data_t *from, gal_data_t *to)
+{
+  size_t i;
+  int isblank;
+  char **strarr=to->array, **instrarr=from->array;
+
+  unsigned char  *uc=from->array;
+  char            *c=from->array;
+  unsigned short *us=from->array;
+  short           *s=from->array;
+  unsigned int   *ui=from->array;
+  int            *ii=from->array;
+  unsigned long  *ul=from->array;
+  long            *l=from->array;
+  LONGLONG        *L=from->array;
+  float           *f=from->array;
+  double          *d=from->array;
+
+  /* Sanity check */
+  if(to->type!=GAL_DATA_TYPE_STRING)
+    error(EXIT_FAILURE, 0, "`to' in `data_copy_to_string' must have a "
+          "string type");
+
+  /* Do the copying */
+  switch(from->type)
+    {
+    case GAL_DATA_TYPE_UCHAR:
+      for(i=0;i<from->size;++i)
+        {if(uc[i]!=GAL_DATA_BLANK_UCHAR) asprintf(&strarr[i], "%u", uc[i]);
+         else gal_checkset_allocate_copy(GAL_DATA_BLANK_STRING, &strarr[i]);}
+      break;
+
+    case GAL_DATA_TYPE_CHAR:
+      for(i=0;i<from->size;++i)
+        {if(c[i]!=GAL_DATA_BLANK_CHAR) asprintf(&strarr[i], "%d", c[i]);
+         else gal_checkset_allocate_copy(GAL_DATA_BLANK_STRING, &strarr[i]);}
+      break;
+
+    case GAL_DATA_TYPE_USHORT:
+      for(i=0;i<from->size;++i)
+        {if(us[i]!=GAL_DATA_BLANK_USHORT) asprintf(&strarr[i], "%u", us[i]);
+         else gal_checkset_allocate_copy(GAL_DATA_BLANK_STRING, &strarr[i]);}
+      break;
+
+    case GAL_DATA_TYPE_SHORT:
+      for(i=0;i<from->size;++i)
+        {if(s[i]!=GAL_DATA_BLANK_SHORT) asprintf(&strarr[i], "%d", s[i]);
+         else gal_checkset_allocate_copy(GAL_DATA_BLANK_STRING, &strarr[i]);}
+      break;
+
+    case GAL_DATA_TYPE_UINT:
+      for(i=0;i<from->size;++i)
+        {if(ui[i]!=GAL_DATA_BLANK_UINT) asprintf(&strarr[i], "%u", ui[i]);
+         else gal_checkset_allocate_copy(GAL_DATA_BLANK_STRING, &strarr[i]);}
+      break;
+
+    case GAL_DATA_TYPE_INT:
+      for(i=0;i<from->size;++i)
+        {if(ii[i]!=GAL_DATA_BLANK_INT) asprintf(&strarr[i], "%d", ii[i]);
+         else gal_checkset_allocate_copy(GAL_DATA_BLANK_STRING, &strarr[i]);}
+      break;
+
+    case GAL_DATA_TYPE_ULONG:
+      for(i=0;i<from->size;++i)
+        {if(ul[i]!=GAL_DATA_BLANK_ULONG) asprintf(&strarr[i], "%lu", ul[i]);
+         else gal_checkset_allocate_copy(GAL_DATA_BLANK_STRING, &strarr[i]);}
+      break;
+
+    case GAL_DATA_TYPE_LONG:
+      for(i=0;i<from->size;++i)
+        {if(l[i]!=GAL_DATA_BLANK_LONG) asprintf(&strarr[i], "%ld", l[i]);
+         else gal_checkset_allocate_copy(GAL_DATA_BLANK_STRING, &strarr[i]);}
+      break;
+
+    case GAL_DATA_TYPE_LONGLONG:
+      for(i=0;i<from->size;++i)
+        {if(L[i]!=GAL_DATA_BLANK_LONGLONG) asprintf(&strarr[i], "%lld", L[i]);
+         else gal_checkset_allocate_copy(GAL_DATA_BLANK_STRING, &strarr[i]);}
+      break;
+
+    case GAL_DATA_TYPE_FLOAT:
+      for(i=0;i<from->size;++i)
+        {
+          if(isnan(GAL_DATA_BLANK_FLOAT)) isblank = isnan(f[i]) ? 1 : 0;
+          else isblank = GAL_DATA_BLANK_FLOAT==f[i] ? 1 : 0;
+          if(isblank==0) asprintf(&strarr[i], "%f", f[i]);
+          else gal_checkset_allocate_copy(GAL_DATA_BLANK_STRING, &strarr[i]);
+        }
+      break;
+
+    case GAL_DATA_TYPE_DOUBLE:
+      for(i=0;i<from->size;++i)
+        {
+          if(isnan(GAL_DATA_BLANK_FLOAT)) isblank = isnan(d[i]) ? 1 : 0;
+          else isblank = GAL_DATA_BLANK_FLOAT==d[i] ? 1 : 0;
+          if(isblank==0) asprintf(&strarr[i], "%f", d[i]);
+          else gal_checkset_allocate_copy(GAL_DATA_BLANK_STRING, &strarr[i]);
+        }
+      break;
+
+    case GAL_DATA_TYPE_STRING:
+      for(i=0;i<from->size;++i)
+        gal_checkset_allocate_copy(instrarr[i], &strarr[i]);
+      break;
+
+    case GAL_DATA_TYPE_BIT:
+    case GAL_DATA_TYPE_STRLL:
+    case GAL_DATA_TYPE_COMPLEX:
+    case GAL_DATA_TYPE_DCOMPLEX:
+      error(EXIT_FAILURE, 0, "`data_copy_to_string' currently doesn't "
+            "support copying to %s type",
+            gal_data_type_as_string(from->type, 1));
+      break;
+
+    default:
+      error(EXIT_FAILURE, 0, "type %d not recognized for `from->type' in "
+            "`data_copy_to_string'", from->type);
+    }
+}
+
+
+
+
+
 /* Copy to a new type for integers. */
 #define COPY_OTYPE_ITYPE_SET_INT(otype, itype) {                        \
     itype *ia=in->array, iblank;                                        \
@@ -1962,13 +2177,17 @@ gal_data_flag_blank(gal_data_t *data)
       COPY_OTYPE_ITYPE_SET_FLT(otype, double);                          \
       break;                                                            \
                                                                         \
+    case GAL_DATA_TYPE_STRING:                                          \
+      data_copy_from_string(in, out);                                   \
+      break;                                                            \
+                                                                        \
     case GAL_DATA_TYPE_BIT:                                             \
     case GAL_DATA_TYPE_STRLL:                                           \
     case GAL_DATA_TYPE_COMPLEX:                                         \
     case GAL_DATA_TYPE_DCOMPLEX:                                        \
       error(EXIT_FAILURE, 0, "`gal_data_copy_to_new_type' currently "   \
-            "doesn't support copying from %s type",                     \
-            gal_data_type_as_string(in->type, 1));                      \
+            "doesn't support copying from %s type to a numeric (real) " \
+            "type", gal_data_type_as_string(in->type, 1));              \
       break;                                                            \
                                                                         \
     default:                                                            \
@@ -2043,6 +2262,10 @@ gal_data_copy_to_new_type(gal_data_t *in, int newtype)
       COPY_OTYPE_SET(double);
       break;
 
+    case GAL_DATA_TYPE_STRING:
+      data_copy_to_string(in, out);
+      break;
+
     case GAL_DATA_TYPE_BIT:
     case GAL_DATA_TYPE_STRLL:
     case GAL_DATA_TYPE_COMPLEX:
@@ -2052,11 +2275,6 @@ gal_data_copy_to_new_type(gal_data_t *in, int newtype)
             gal_data_type_as_string(newtype, 1));
       break;
 
-    case GAL_DATA_TYPE_STRING:
-      error(EXIT_FAILURE, 0, "`gal_data_copy_to_new_type' is only for "
-            "numeric data types, the desired new type is a string");
-      break;
-
     default:
       error(EXIT_FAILURE, 0, "type %d not recognized for "
             "for newtype in gal_data_copy_to_new_type", newtype);
@@ -2152,6 +2370,99 @@ gal_data_to_same_type(gal_data_t *f,   gal_data_t *s,
 
 
 /*************************************************************
+ **************              Write             ***************
+ *************************************************************/
+char *
+gal_data_write_to_string(void *ptr, int type, int quote_if_str_has_space)
+{
+  char *c, *str;
+  switch(type)
+    {
+    /* For a string we might need to make sure it has no white space
+       characters, if it does, it can be printed it within quotation
+       signs. */
+    case GAL_DATA_TYPE_STRING:
+      if(quote_if_str_has_space)
+        {
+          c=*(char **)ptr; while(*c!='\0') if(isspace(*c++)) break;
+          if(*c=='\0') asprintf(&str, "%s",      *(char **)ptr);
+          else         asprintf(&str, "\"%s\" ", *(char **)ptr);
+        }
+      else
+        asprintf(&str, "%s", *(char **)ptr);
+      break;
+
+    case GAL_DATA_TYPE_UCHAR:
+      asprintf(&str, "%u", *(unsigned char *)ptr);
+      break;
+
+    case GAL_DATA_TYPE_CHAR:
+      asprintf(&str, "%d", *(char *)ptr);
+      break;
+
+    case GAL_DATA_TYPE_USHORT:
+      asprintf(&str, "%u", *(unsigned short *)ptr);
+      break;
+
+    case GAL_DATA_TYPE_SHORT:
+      asprintf(&str, "%d", *(short *)ptr);
+      break;
+
+    case GAL_DATA_TYPE_UINT:
+      asprintf(&str, "%u", *(unsigned int *)ptr);
+      break;
+
+    case GAL_DATA_TYPE_INT:
+      asprintf(&str, "%d", *(int *)ptr);
+      break;
+
+    case GAL_DATA_TYPE_ULONG:
+      asprintf(&str, "%lu", *(unsigned long *)ptr);
+      break;
+
+    case GAL_DATA_TYPE_LONG:
+      asprintf(&str, "%ld", *(long *)ptr);
+      break;
+
+    case GAL_DATA_TYPE_LONGLONG:
+      asprintf(&str, "%lld", *(LONGLONG *)ptr);
+      break;
+
+    case GAL_DATA_TYPE_FLOAT:
+      asprintf(&str, "%.6f", *(float *)ptr);
+      break;
+
+    case GAL_DATA_TYPE_DOUBLE:
+      asprintf(&str, "%.10f", *(double *)ptr);
+      break;
+
+    default:
+      error(EXIT_FAILURE, 0, "type code %d not recognized in "
+            "`gal_data_write_to_string'", type);
+    }
+  return str;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/*************************************************************
  **************              Read              ***************
  *************************************************************/
 /* If the data structure was correctly created (the string was a number),
diff --git a/lib/fits.c b/lib/fits.c
index 80235bc..dcde619 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -1219,7 +1219,10 @@ gal_fits_read_wcs(char *filename, char *hdu, size_t 
hstartwcs,
  *************************************************************/
 
 /* Note that the FITS standard defines any array as an `image',
-   irrespective of how many dimensions it has. */
+   irrespective of how many dimensions it has. This function will return
+   the Gnuastro-type and also the number of dimensions and size along each
+   dimension of the image. Note that `*dsize' will be allocated here, so it
+   must not point to any already allocated space. */
 void
 gal_fits_img_info(fitsfile *fptr, int *type, size_t *ndim, size_t **dsize)
 {
diff --git a/lib/gnuastro/data.h b/lib/gnuastro/data.h
index f58d71b..c3431ca 100644
--- a/lib/gnuastro/data.h
+++ b/lib/gnuastro/data.h
@@ -35,6 +35,17 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 #include <gnuastro/linkedlist.h>
 
+/* When we are within Gnuastro's building process, `IN_GNUASTRO_BUILD' is
+   defined. In the build process, installation information (in particular
+   `GAL_CONFIG_SIZEOF_SIZE_T' that we need below) is kept in
+   `config.h'. When building a user's programs, this information is kept in
+   `gnuastro/config.h'. Note that all `.c' files in Gnuastro's source must
+   start with the inclusion of `config.h' and that `gnuastro/config.h' is
+   only created at installation time (not present during the building of
+   Gnuastro).*/
+#ifndef IN_GNUASTRO_BUILD
+#include <gnuastro/config.h>
+#endif
 
 /* C++ Preparations */
 #undef __BEGIN_C_DECLS
@@ -85,7 +96,11 @@ __BEGIN_C_DECLS  /* From C++ preparations */
 
 
 /* Macros to identify the type of data. The macros in the comment
-   parenthesis is the equivalent macro in CFITSIO. */
+   parenthesis is the equivalent macro in CFITSIO.
+
+   IMPORTANT: the integer types must have a smaller value than the floating
+              point types.
+*/
 enum gal_data_types
 {
   GAL_DATA_TYPE_INVALID,   /* Invalid (=0 by C standard).    */
@@ -94,7 +109,6 @@ enum gal_data_types
   GAL_DATA_TYPE_UCHAR,     /* unsigned char    (TBYTE).       */
   GAL_DATA_TYPE_CHAR,      /* char             (TSBYTE).      */
   GAL_DATA_TYPE_LOGICAL,   /* char             (TLOGICAL).    */
-  GAL_DATA_TYPE_STRING,    /* string           (TSTRING).     */
   GAL_DATA_TYPE_USHORT,    /* unsigned short   (TUSHORT).     */
   GAL_DATA_TYPE_SHORT,     /* short            (TSHORT).      */
   GAL_DATA_TYPE_UINT,      /* unsigned int     (TUINT).       */
@@ -102,14 +116,27 @@ enum gal_data_types
   GAL_DATA_TYPE_ULONG,     /* unsigned long    (TLONG).       */
   GAL_DATA_TYPE_LONG,      /* long             (TLONG).       */
   GAL_DATA_TYPE_LONGLONG,  /* long long        (TLONGLONG).   */
+
   GAL_DATA_TYPE_FLOAT,     /* float            (TFLOAT).      */
   GAL_DATA_TYPE_DOUBLE,    /* double           (TDOUBLE).     */
   GAL_DATA_TYPE_COMPLEX,   /* Complex float    (TCOMPLEX).    */
   GAL_DATA_TYPE_DCOMPLEX,  /* Complex double   (TDBLCOMPLEX). */
 
+  GAL_DATA_TYPE_STRING,    /* string           (TSTRING).     */
+
   GAL_DATA_TYPE_STRLL,     /* String linked list.             */
 };
 
+/* `size_t' is 4 and 8 bytes on 32 and 64 bit systems respectively. In both
+   cases, the standard defines `size_t' to be unsigned. During
+   `./configure' the sizeof size_t was found and is stored in
+   `GAL_CONFIG_SIZEOF_SIZE_T'. */
+#if GAL_CONFIG_SIZEOF_SIZE_T == 4
+#define GAL_DATA_TYPE_SIZE_T GAL_DATA_TYPE_UINT
+#else
+#define GAL_DATA_TYPE_SIZE_T GAL_DATA_TYPE_ULONG
+#endif
+
 
 
 
@@ -303,6 +330,13 @@ gal_data_to_same_type(gal_data_t *f, gal_data_t *s,
                       int type, int freeinputs);
 
 
+/*************************************************************
+ **************              Write             ***************
+ *************************************************************/
+char *
+gal_data_write_to_string(void *ptr, int type, int quote_if_str_has_space);
+
+
 
 /*************************************************************
  **************              Read              ***************
diff --git a/lib/gnuastro/table.h b/lib/gnuastro/table.h
index b334c24..ef06086 100644
--- a/lib/gnuastro/table.h
+++ b/lib/gnuastro/table.h
@@ -138,6 +138,9 @@ int
 gal_table_string_to_searchin(char *string);
 
 void
+gal_table_too_many_columns(char *filename);
+
+void
 gal_table_print_info(gal_data_t *allcols, size_t numcols, size_t numrows);
 
 void
diff --git a/lib/options.c b/lib/options.c
index 4326c5a..9c036b1 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -28,13 +28,14 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <stdlib.h>
 #include <string.h>
 
+#include <gnuastro/git.h>
 #include <gnuastro/txt.h>
 #include <gnuastro/data.h>
 #include <gnuastro/table.h>
 #include <gnuastro/arithmetic.h>
 #include <gnuastro/linkedlist.h>
 
-
+#include <timing.h>
 #include <options.h>
 #include <checkset.h>
 
@@ -188,7 +189,7 @@ options_print_citation_exit(struct 
gal_options_common_params *cp)
   char *gnuastro_bibtex=
     "Gnuastro package/infrastructure\n"
     "-------------------------------\n"
-    "  @ARTICLE{noisechisel-gnuastro,\n"
+    "  @ARTICLE{2015ApJS..220....1A,\n"
     "     author = {{Akhlaghi}, M. and {Ichikawa}, T.},\n"
     "      title = \"{Noise-based Detection and Segmentation of Nebulous "
     "Objects}\",\n"
@@ -214,7 +215,9 @@ options_print_citation_exit(struct 
gal_options_common_params *cp)
   printf("\nThank you for using %s (%s) %s.\n\n", cp->program_name,
          PACKAGE_NAME, PACKAGE_VERSION);
   printf("Citations are vital for the continued work on Gnuastro.\n\n"
-         "Please cite these BibTeX record(s) in your paper(s).\n\n%s\n\n",
+         "Please cite these BibTeX record(s) in your paper(s).\n"
+         "(don't forget to also include the version as shown above)\n\n"
+         "%s\n\n",
          gnuastro_bibtex);
 
 
@@ -386,6 +389,20 @@ options_sanity_check(struct argp_option *option, char *arg,
       multicheckop=GAL_ARITHMETIC_OP_AND;
       break;
 
+    case GAL_OPTIONS_RANGE_0_OR_ODD:
+      message="greater than, or equal to, zero and odd";
+      ref1=gal_data_alloc(NULL, GAL_DATA_TYPE_UCHAR, 1, &dsize, NULL,
+                          0, -1, NULL, NULL, NULL);
+      ref2=gal_data_alloc(NULL, GAL_DATA_TYPE_UCHAR, 1, &dsize, NULL,
+                          0, -1, NULL, NULL, NULL);
+      *(unsigned char *)(ref1->array)=0;
+      *(unsigned char *)(ref2->array)=2;
+
+      operator1=GAL_ARITHMETIC_OP_EQ;
+      operator2=GAL_ARITHMETIC_OP_MODULO;
+      multicheckop=GAL_ARITHMETIC_OP_OR;
+      break;
+
     default:
       error(EXIT_FAILURE, 0, "range code %d not recognized in "
             "`gal_options_check_set'", option->range);
@@ -439,18 +456,22 @@ gal_options_read_check(struct argp_option *option, char 
*arg, char *filename,
     {
       /* Read the string argument into the value. */
       if( gal_data_string_to_type(&option->value, arg, option->type) )
-
         /* Fortunately `error_at_line' will behave like `error' when the
            filename is NULL (the option was read from a command-line). */
         error_at_line(EXIT_FAILURE, 0, filename, lineno,
-                      "`%s' (value to option `%s') couldn't be read into "
+                      "`%s' (value to option `--%s') couldn't be read into "
                       "the proper numerical type. Common causes for this "
                       "error are:\n"
-                      "  - It contains non-numerical characters\n"
+                      "  - It contains non-numerical characters.\n"
                       "  - It is negative, but the expected value is "
-                      "positive\n"
+                      "positive.\n"
                       "  - It is floating point, but the expected value "
-                      "is an integer\n", arg, option->name);
+                      "is an integer.\n"
+                      "  - The previous option required a value, but you "
+                      "forgot to give it one, so the next option's "
+                      "name(+value, if there are no spaces between them) "
+                      "is read as the value of the previous option.", arg,
+                      option->name);
     }
 
   /* Do a sanity check. */
@@ -1014,65 +1035,10 @@ option_is_printable(struct argp_option *option)
 static int
 options_print_any_type(void *ptr, int type, int width, FILE *fp)
 {
-  char *c, *str;
-  switch(type)
-    {
-    /* For a string we need to make sure it has no white space characters,
-       if it does, it should be printed it within quotation signs. */
-    case GAL_DATA_TYPE_STRING:
-      c=*(char **)ptr; while(*c!='\0') if(isspace(*c++)) break;
-      if(*c=='\0') asprintf(&str, "%s",      *(char **)ptr);
-      else         asprintf(&str, "\"%s\" ", *(char **)ptr);
-      break;
-
-    case GAL_DATA_TYPE_UCHAR:
-      asprintf(&str, "%u", *(unsigned char *)ptr);
-      break;
-
-    case GAL_DATA_TYPE_CHAR:
-      asprintf(&str, "%d", *(char *)ptr);
-      break;
-
-    case GAL_DATA_TYPE_USHORT:
-      asprintf(&str, "%u", *(unsigned short *)ptr);
-      break;
-
-    case GAL_DATA_TYPE_SHORT:
-      asprintf(&str, "%d", *(short *)ptr);
-      break;
+  char *str;
 
-    case GAL_DATA_TYPE_UINT:
-      asprintf(&str, "%u", *(unsigned int *)ptr);
-      break;
-
-    case GAL_DATA_TYPE_INT:
-      asprintf(&str, "%d", *(int *)ptr);
-      break;
-
-    case GAL_DATA_TYPE_ULONG:
-      asprintf(&str, "%lu", *(unsigned long *)ptr);
-      break;
-
-    case GAL_DATA_TYPE_LONG:
-      asprintf(&str, "%ld", *(long *)ptr);
-      break;
-
-    case GAL_DATA_TYPE_LONGLONG:
-      asprintf(&str, "%lld", *(LONGLONG *)ptr);
-      break;
-
-    case GAL_DATA_TYPE_FLOAT:
-      asprintf(&str, "%.6f", *(float *)ptr);
-      break;
-
-    case GAL_DATA_TYPE_DOUBLE:
-      asprintf(&str, "%.10f", *(double *)ptr);
-      break;
-
-    default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`options_print_any_type'", type);
-    }
+  /* Write the value into a string. */
+  str=gal_data_write_to_string(ptr, type, 1);
 
   /* If only the width was desired, don't actually print the string, just
      return its length. Otherwise, print it. */
@@ -1419,3 +1385,41 @@ gal_options_print_state(struct gal_options_common_params 
*cp)
           break;
         }
 }
+
+
+
+
+
+void
+gal_options_print_log(gal_data_t *logll, char *program_string,
+                      time_t *rawtime, char *comments, char *filename,
+                      struct gal_options_common_params *cp)
+{
+  char *finalcomment;
+  char *msg, gitdescribe[100], *gd;
+
+  /* Get the Git description in the running folder. */
+  gd=gal_git_describe();
+  if(gd) sprintf(gitdescribe, " from %s,", gd);
+  else   gitdescribe[0]='\0';
+
+  /* Write the top level comment. */
+  asprintf(&finalcomment, "# %s\n# Created%s on %s%s",
+           program_string, gitdescribe, ctime(rawtime),
+           comments ? comments : "#");
+
+  /* Write the log file to disk */
+  gal_table_write(logll, finalcomment, GAL_TABLE_FORMAT_TXT, filename,
+                  cp->dontdelete);
+
+  /* In verbose mode, print the information. */
+  if(!cp->quiet)
+    {
+      asprintf(&msg, "%s created.", filename);
+      gal_timing_report(NULL, msg, 1);
+      free(msg);
+    }
+
+  /* Clean up. */
+  free(finalcomment);
+}
diff --git a/lib/options.h b/lib/options.h
index 3deb04c..db9f03f 100644
--- a/lib/options.h
+++ b/lib/options.h
@@ -115,6 +115,7 @@ enum gal_options_range_values
   GAL_OPTIONS_RANGE_GE_0_LE_1,
 
   GAL_OPTIONS_RANGE_GT_0_ODD,
+  GAL_OPTIONS_RANGE_0_OR_ODD,
 };
 
 
@@ -231,8 +232,17 @@ void
 gal_options_read_config_set(struct gal_options_common_params *cp);
 
 
+
+
+/**********************************************************************/
+/************              Printing/Writing             ***************/
+/**********************************************************************/
 void
 gal_options_print_state(struct gal_options_common_params *cp);
 
+void
+gal_options_print_log(gal_data_t *logll, char *program_string,
+                      time_t *rawtime, char *comments, char *filename,
+                      struct gal_options_common_params *cp);
 
 #endif
diff --git a/lib/table.c b/lib/table.c
index 15fe7a8..9ed5e76 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -139,6 +139,29 @@ gal_table_string_to_searchin(char *string)
 
 
 
+/* Programs that read columns might match more than one column for a given
+   property, for example it might happen (due to bad table design) that
+   multiple columns have the same name, or the user uses regular
+   expressions badly. In such cases, the following error message will be
+   useful and commonly repeated by the programs, so we are putting it here
+   for easiness and a clean code. */
+void
+gal_table_too_many_columns(char *filename)
+{
+  error(EXIT_FAILURE, 0, "there was more than one match for at least one of "
+        "the input columns from `%s'. You can check the column information "
+        "with the following command, and correct the options ending with "
+        "`col' appropriately.\n\n"
+        "   $ asttable --information %s\n\n"
+        "The current values to all options can be checked by calling the "
+        "`--printparams' (or `-P') option. To learn more about how the "
+        "columns are selected, please try the following command:\n\n"
+        "   $ info gnuastro \"Selecting table columns\" ", filename,
+        filename);
+}
+
+
+
 
 
 
@@ -430,6 +453,7 @@ gal_table_read_blank(gal_data_t *col, char *blank)
 
 
 
+
 /************************************************************************/
 /***************         Information about a table        ***************/
 /************************************************************************/
diff --git a/tests/imgcrop/cat.txt b/tests/imgcrop/cat.txt
index 03fd28e..652ebab 100644
--- a/tests/imgcrop/cat.txt
+++ b/tests/imgcrop/cat.txt
@@ -1,2 +1,7 @@
-0  500.00  500.00   0.99917157   1.0008283
-1  251.00  251.00   0.99958658   1.0004150
+# Column 1: NAME       [name,str4]  Name of object.
+# Column 2: X_CENTER   [pixels,d]   Image X axis position.
+# Column 3: Y_CENTER   [pixels,d]   Image Y axis position.
+# Column 4: RA_CENTER  [deg,d]      Right Ascension.
+# Column 5: DEC_CENTER [deg,d]      Declination.
+A0B1  500.00  500.00   0.99917157   1.0008283
+c2d3  251.00  251.00   0.99958658   1.0004150
diff --git a/tests/imgcrop/imgcat.sh b/tests/imgcrop/imgcat.sh
index ef42ad7..9b6db5e 100755
--- a/tests/imgcrop/imgcat.sh
+++ b/tests/imgcrop/imgcat.sh
@@ -53,5 +53,5 @@ if [ ! -f $execname ] || [ ! -f $img ]; then exit 77; fi
 # enable multithreaded access to files, the tests pass. It is the
 # users choice to enable this feature.
 cat=$topsrc/tests/$prog/cat.txt
-$execname $img $cat --imgmode --suffix=_imgcat.fits --zeroisnotblank \
-          --numthreads=1
+$execname $img --catalog=$cat --mode=img --suffix=_imgcat.fits    \
+          --zeroisnotblank --xcol=X_CENTER --ycol=Y_CENTER --namecol=NAME
diff --git a/tests/imgcrop/imgoutpolygon.sh b/tests/imgcrop/imgoutpolygon.sh
index a0e3668..617aff8 100755
--- a/tests/imgcrop/imgoutpolygon.sh
+++ b/tests/imgcrop/imgoutpolygon.sh
@@ -52,6 +52,6 @@ if [ ! -f $execname ] || [ ! -f $img ]; then exit 77; fi
 # The number of threads is one so if CFITSIO does is not configured to
 # enable multithreaded access to files, the tests pass. It is the
 # users choice to enable this feature.
-$execname $img $cat --imgmode --zeroisnotblank --outpolygon                   \
+$execname $img $cat --mode=img --zeroisnotblank --outpolygon                  \
           --polygon=209,50:436.76,151:475.64,438.2:210.6,454.04:121.4,289.88  \
           --output=imgoutpolygon.fits
diff --git a/tests/imgcrop/imgpolygon.sh b/tests/imgcrop/imgpolygon.sh
index 9b25baf..a1256fe 100755
--- a/tests/imgcrop/imgpolygon.sh
+++ b/tests/imgcrop/imgpolygon.sh
@@ -48,5 +48,5 @@ if [ ! -f $execname ] || [ ! -f $img ]; then exit 77; fi
 
 # Actual test script
 # ==================
-$execname $img $cat --imgmode --zeroisnotblank --output=imgpolygon.fits      \
+$execname $img $cat --mode=img --zeroisnotblank --output=imgpolygon.fits      \
           --polygon=209,50:436.76,151:475.64,438.2:210.6,454.04:121.4,289.88
diff --git a/tests/imgcrop/wcscat.sh b/tests/imgcrop/wcscat.sh
index 5ffef76..0475671 100755
--- a/tests/imgcrop/wcscat.sh
+++ b/tests/imgcrop/wcscat.sh
@@ -53,4 +53,5 @@ for fn in $img; do if [ ! -f $fn ]; then exit 77; fi; done
 # enable multithreaded access to files, the tests pass. It is the
 # users choice to enable this feature.
 cat=$topsrc/tests/$prog/cat.txt
-$execname $cat $img --suffix=_wcscat.fits --zeroisnotblank --numthreads=1
+$execname $img --catalog=$cat --mode=wcs --suffix=_wcscat.fits        \
+          --zeroisnotblank --racol=4 --deccol=DEC_CENTER --numthreads=1
diff --git a/tests/imgcrop/wcspolygon.sh b/tests/imgcrop/wcspolygon.sh
index 78bc0e3..256d5b7 100755
--- a/tests/imgcrop/wcspolygon.sh
+++ b/tests/imgcrop/wcspolygon.sh
@@ -48,5 +48,5 @@ for fn in $img; do if [ ! -f $fn ]; then exit 77; fi; done
 
 # Actual test script
 # ==================
-$execname $img --wcsmode --zeroisnotblank --output=wcspolygon.fits             
\
+$execname $img --mode=wcs --zeroisnotblank --output=wcspolygon.fits           \
           --polygon=0.99980497,1.0001967:0.998378,1.0012267:0.9999766,1.0013217
diff --git a/tmpfs-config-make b/tmpfs-config-make
index 60b7fba..5310a84 100755
--- a/tmpfs-config-make
+++ b/tmpfs-config-make
@@ -132,7 +132,7 @@ cd $build_dir
 if [ ! -f Makefile ]; then
     $srcdir/configure --srcdir=$srcdir --disable-shared CFLAGS="-g -O0"      \
                       --enable-arithmetic --enable-cosmiccal --enable-header \
-                      --enable-mkprof --enable-table
+                      --enable-imgcrop --enable-mkprof --enable-table
 fi
 
 



reply via email to

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