gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master ba07a051 1/2: Library (fits.h): reading functi


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master ba07a051 1/2: Library (fits.h): reading functions also require HDU option name
Date: Thu, 13 Jul 2023 13:26:04 -0400 (EDT)

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

    Library (fits.h): reading functions also require HDU option name
    
    Until now, when a requested HDU didn't exist, the library would always
    print a message suggesting to use '--hdu'. But generally, the problematic
    option may be another option (for example '--gridhdu' in Warp!).
    
    With this commit, the FITS reading functions take an extra option for the
    caller to optinally give the name of the option that is being used.
    
    This bug was reported by Aaron Watkins.
    
    This fixes bug #64420.
---
 NEWS                          |   2 +
 bin/arithmetic/arithmetic.c   |   2 +-
 bin/arithmetic/operands.c     |  12 ++--
 bin/arithmetic/ui.c           |   5 +-
 bin/convertt/ui.c             |   6 +-
 bin/convolve/convolve.c       |   3 +-
 bin/convolve/ui.c             |  21 +++---
 bin/crop/crop.c               |   5 +-
 bin/crop/ui.c                 |  12 ++--
 bin/fits/fits.c               |  19 ++---
 bin/fits/keywords.c           |  15 ++--
 bin/fits/meta.c               |   4 +-
 bin/match/match.c             |  19 +++--
 bin/match/ui.c                |  18 ++---
 bin/mkcatalog/mkcatalog.c     |   3 +-
 bin/mkcatalog/ui.c            |  18 +++--
 bin/mknoise/mknoise.c         |   2 +-
 bin/mknoise/ui.c              |  10 +--
 bin/mkprof/args.h             |   4 +-
 bin/mkprof/main.h             |   4 +-
 bin/mkprof/mkprof.c           |   7 +-
 bin/mkprof/oneprofile.c       |   3 +-
 bin/mkprof/ui.c               |  32 +++++----
 bin/noisechisel/noisechisel.c |   3 +-
 bin/noisechisel/ui.c          |  12 ++--
 bin/query/query.c             |  16 +++--
 bin/query/tap.c               |   2 +-
 bin/segment/segment.c         |   2 +-
 bin/segment/ui.c              |  20 +++---
 bin/statistics/sky.c          |   2 +-
 bin/statistics/statistics.c   |   6 +-
 bin/statistics/ui.c           |  17 +++--
 bin/table/arithmetic.c        |   2 +-
 bin/table/table.c             |   6 +-
 bin/table/ui.c                |  12 ++--
 bin/warp/ui.c                 |  12 ++--
 bin/warp/warp.c               |   4 +-
 doc/announce-acknowledge.txt  |   1 +
 doc/gnuastro.texi             |  65 ++++++++++++-----
 lib/arithmetic.c              |   3 +-
 lib/array.c                   |  25 ++++---
 lib/fits.c                    | 159 +++++++++++++++++++++++-------------------
 lib/gnuastro/array.h          |  13 ++--
 lib/gnuastro/fits.h           |  41 ++++++-----
 lib/gnuastro/table.h          |   5 +-
 lib/gnuastro/wcs.h            |  13 ++--
 lib/makeplugin.c              |   4 +-
 lib/table.c                   |  13 ++--
 lib/wcs.c                     |  14 ++--
 tests/buildprog/simpleio.c    |   2 +-
 tests/lib/multithread.c       |   2 +-
 51 files changed, 413 insertions(+), 289 deletions(-)

diff --git a/NEWS b/NEWS
index fe12ef2a..3780a020 100644
--- a/NEWS
+++ b/NEWS
@@ -125,6 +125,8 @@ See the end of the file for license conditions.
   bug #64357: Plain text metadata ignored when no name is present.
   bug #64392: Arithmetic's isnotblank operator producing zeros when no
               blanks present.
+  bug #64420: Error message of wrongly specified HDU doesn't give the
+              problematic option name; reported by Aaron Watkins.
 
 
 
diff --git a/bin/arithmetic/arithmetic.c b/bin/arithmetic/arithmetic.c
index 0d0f5045..0d75c481 100644
--- a/bin/arithmetic/arithmetic.c
+++ b/bin/arithmetic/arithmetic.c
@@ -1691,7 +1691,7 @@ arithmetic_final_read_file(struct arithmeticparams *p,
       /* Read the data, note that the WCS has already been set. */
       out=gal_array_read_one_ch(filename, hdu, NULL,
                                 p->cp.minmapsize,
-                                p->cp.quietmmap);
+                                p->cp.quietmmap, "--hdu");
       out->ndim=gal_dimension_remove_extra(out->ndim, out->dsize,
                                             NULL);
       if(!p->cp.quiet) printf(" - %s (hdu %s) is read.\n", filename, hdu);
diff --git a/bin/arithmetic/operands.c b/bin/arithmetic/operands.c
index 2f02024b..ec14fc79 100644
--- a/bin/arithmetic/operands.c
+++ b/bin/arithmetic/operands.c
@@ -179,16 +179,18 @@ operands_add(struct arithmeticparams *p, char *filename, 
gal_data_t *data)
               if(readwcs && p->refdata.wcs==NULL)
                 {
                   /* If the HDU is an image, read its size. */
-                  dsize = ( gal_fits_hdu_format(filename,
-                                                newnode->hdu)==IMAGE_HDU
+                  dsize = ( gal_fits_hdu_format(filename, newnode->hdu,
+                                                "--hdu")==IMAGE_HDU
                             ? gal_fits_img_info_dim(filename,
-                                                    newnode->hdu, &ndim)
+                                                    newnode->hdu, &ndim,
+                                                    "--hdu")
                             : NULL);
 
                   /* Read the WCS. */
                   p->refdata.wcs=gal_wcs_read(filename, newnode->hdu,
                                               p->cp.wcslinearmatrix,
-                                              0, 0, &p->refdata.nwcs);
+                                              0, 0, &p->refdata.nwcs,
+                                              "--hdu");
 
                   /* Remove extra (length of 1) dimensions (if we had an
                      image HDU). */
@@ -242,7 +244,7 @@ operands_pop(struct arithmeticparams *p, char *operator)
 
       /* Read the dataset and remove possibly extra dimensions. */
       data=gal_array_read_one_ch(filename, hdu, NULL, p->cp.minmapsize,
-                                 p->cp.quietmmap);
+                                 p->cp.quietmmap, "--hdu");
       data->ndim=gal_dimension_remove_extra(data->ndim, data->dsize, NULL);
 
       /* When the reference data structure's dimensionality is non-zero, it
diff --git a/bin/arithmetic/ui.c b/bin/arithmetic/ui.c
index e3ecbd33..a0788a35 100644
--- a/bin/arithmetic/ui.c
+++ b/bin/arithmetic/ui.c
@@ -386,12 +386,13 @@ ui_preparations(struct arithmeticparams *p)
   if(p->wcsfile && strcmp(p->wcsfile,"none"))
     {
       /* Read the number of dimensions and the size of each. */
-      dsize=gal_fits_img_info_dim(p->wcsfile, p->wcshdu, &ndim);
+      dsize=gal_fits_img_info_dim(p->wcsfile, p->wcshdu, &ndim,
+                                  "--wcshdu");
 
       /* Read the WCS. */
       p->refdata.wcs=gal_wcs_read(p->wcsfile, p->wcshdu,
                                   p->cp.wcslinearmatrix, 0, 0,
-                                  &p->refdata.nwcs);
+                                  &p->refdata.nwcs, "--wcshdu");
       if(p->refdata.wcs)
         {
           if(!p->cp.quiet)
diff --git a/bin/convertt/ui.c b/bin/convertt/ui.c
index 6f6e5a6b..441add87 100644
--- a/bin/convertt/ui.c
+++ b/bin/convertt/ui.c
@@ -753,9 +753,9 @@ ui_make_channels_ll(struct converttparams *p)
 
           /* Read in the array and its WCS information. */
           data=gal_fits_img_read(name->v, hdu, p->cp.minmapsize,
-                                 p->cp.quietmmap);
+                                 p->cp.quietmmap, "--hdu");
           data->wcs=gal_wcs_read(name->v, hdu, p->cp.wcslinearmatrix,
-                                 0, 0, &data->nwcs);
+                                 0, 0, &data->nwcs, "--hdu");
           data->ndim=gal_dimension_remove_extra(data->ndim, data->dsize,
                                                 data->wcs);
           gal_list_data_add(&p->chll, data);
@@ -1303,7 +1303,7 @@ ui_marks_read_raw(struct converttparams *p, gal_data_t 
**coord1,
   table=gal_table_read(p->marksname, p->markshdu, NULL, cols,
                        p->cp.searchin, p->cp.ignorecase,
                        p->cp.numthreads, p->cp.minmapsize,
-                       p->cp.quietmmap, NULL);
+                       p->cp.quietmmap, NULL, "--markshdu");
 
   /* Make sure that we have only one column for each entry (it may happen
      that a table has two columns with the same name!). */
diff --git a/bin/convolve/convolve.c b/bin/convolve/convolve.c
index 4a34027e..ad98d511 100644
--- a/bin/convolve/convolve.c
+++ b/bin/convolve/convolve.c
@@ -826,7 +826,8 @@ convolve(struct convolveparams *p)
       gal_fits_key_write_filename("input", p->filename, &cp->okeys, 1,
                                   cp->quiet);
       gal_fits_key_write_config(&cp->okeys, "Convolve configuration",
-                                "CONVOLVE-CONFIG", cp->output, "0");
+                                "CONVOLVE-CONFIG", cp->output, "0",
+                                "NONE");
     }
 
   /* Inform the user that the job is done. */
diff --git a/bin/convolve/ui.c b/bin/convolve/ui.c
index 38d3d99a..fe6d4716 100644
--- a/bin/convolve/ui.c
+++ b/bin/convolve/ui.c
@@ -266,7 +266,7 @@ ui_check_options_and_arguments(struct convolveparams *p)
 
           /* If its an image, make sure column isn't given (in case the
              user confuses an image with a table). */
-          p->hdu_type=gal_fits_hdu_format(p->filename, p->cp.hdu);
+          p->hdu_type=gal_fits_hdu_format(p->filename, p->cp.hdu, "--hdu");
           if(p->hdu_type==IMAGE_HDU && p->column)
             error(EXIT_FAILURE, 0, "%s (hdu: %s): is a FITS image "
                   "extension. The '--column' option is only applicable "
@@ -289,7 +289,8 @@ ui_check_options_and_arguments(struct convolveparams *p)
 
           /* If its an image, make sure column isn't given (in case the
              user confuses an image with a table). */
-          kernel_type=gal_fits_hdu_format(p->kernelname, p->khdu);
+          kernel_type=gal_fits_hdu_format(p->kernelname, p->khdu,
+                                          "--khdu");
           if(kernel_type==IMAGE_HDU && p->kernelcolumn)
             error(EXIT_FAILURE, 0, "%s (hdu: %s): is a FITS image "
                   "extension. The '--kernelcolumn' option is only "
@@ -343,7 +344,8 @@ ui_read_column(struct convolveparams *p, int i0k1)
   if(columnname==NULL)
     {
       /* Get the basic table information. */
-      cinfo=gal_table_info(filename, hdu, lines, &ncols, &nrows, &tformat);
+      cinfo=gal_table_info(filename, hdu, lines, &ncols, &nrows, &tformat,
+                           "--hdu");
       gal_data_array_free(cinfo, ncols, 1);
 
       /* See how many columns it has and take the proper action. */
@@ -380,7 +382,7 @@ ui_read_column(struct convolveparams *p, int i0k1)
   /* Read the desired column(s). */
   out=gal_table_read(filename, hdu, lines, column, p->cp.searchin,
                      p->cp.ignorecase, p->cp.numthreads,
-                     p->cp.minmapsize, p->cp.quietmmap, NULL);
+                     p->cp.minmapsize, p->cp.quietmmap, NULL, "--hdu");
   gal_list_str_free(lines, 1);
 
   /* Confirm if only one column was read (it is possible that a regexp
@@ -442,13 +444,13 @@ ui_read_input(struct convolveparams *p)
   if( p->filename && gal_array_name_recognized(p->filename) )
     if (p->isfits && p->hdu_type==IMAGE_HDU)
       {
-        p->input=gal_array_read_one_ch_to_type(p->filename, p->cp.hdu, NULL,
-                                               INPUT_USE_TYPE,
+        p->input=gal_array_read_one_ch_to_type(p->filename, p->cp.hdu,
+                                               NULL, INPUT_USE_TYPE,
                                                p->cp.minmapsize,
-                                               p->cp.quietmmap);
+                                               p->cp.quietmmap, "--hdu");
         p->input->wcs=gal_wcs_read(p->filename, p->cp.hdu,
                                    p->cp.wcslinearmatrix, 0, 0,
-                                   &p->input->nwcs);
+                                   &p->input->nwcs, "--hdu");
         p->input->ndim=gal_dimension_remove_extra(p->input->ndim,
                                                   p->input->dsize,
                                                   p->input->wcs);
@@ -477,7 +479,8 @@ ui_read_kernel(struct convolveparams *p)
       p->kernel = gal_array_read_one_ch_to_type(p->kernelname, p->khdu,
                                                 NULL, INPUT_USE_TYPE,
                                                 p->cp.minmapsize,
-                                                p->cp.quietmmap);
+                                                p->cp.quietmmap,
+                                                "--khdu");
       p->kernel->ndim=gal_dimension_remove_extra(p->kernel->ndim,
                                                  p->kernel->dsize,
                                                  p->kernel->wcs);
diff --git a/bin/crop/crop.c b/bin/crop/crop.c
index e64dd365..2f7b5a24 100644
--- a/bin/crop/crop.c
+++ b/bin/crop/crop.c
@@ -211,7 +211,8 @@ crop_mode_img(void *inparam)
   /* The whole catalog is from one image, so you can get the
      information here:*/
   img=&p->imgs[crp->in_ind];
-  crp->infits=gal_fits_hdu_open_format(img->name, p->cp.hdu, 0);
+  crp->infits=gal_fits_hdu_open_format(img->name, p->cp.hdu, 0,
+                                       "--hdu");
 
   /* Go over all the outputs that are assigned to this thread: */
   for(i=0; crp->indexs[i]!=GAL_BLANK_SIZE_T; ++i)
@@ -307,7 +308,7 @@ crop_mode_wcs(void *inparam)
           {
             /* Open the input FITS file. */
             crp->infits=gal_fits_hdu_open_format(p->imgs[crp->in_ind].name,
-                                                 p->cp.hdu, 0);
+                                                 p->cp.hdu, 0, "--hdu");
 
             /* If a name isn't set yet, set it. */
             if(crp->name==NULL) onecrop_name(crp);
diff --git a/bin/crop/ui.c b/bin/crop/ui.c
index b2bf7da0..98fbc0d5 100644
--- a/bin/crop/ui.c
+++ b/bin/crop/ui.c
@@ -715,9 +715,10 @@ ui_read_cols(struct cropparams *p)
 
 
   /* Read the desired columns from the file. */
-  cols=gal_table_read(p->catname, p->cathdu, NULL, colstrs, p->cp.searchin,
-                      p->cp.ignorecase, p->cp.numthreads, p->cp.minmapsize,
-                      p->cp.quietmmap, NULL);
+  cols=gal_table_read(p->catname, p->cathdu, NULL, colstrs,
+                      p->cp.searchin, p->cp.ignorecase,
+                      p->cp.numthreads, p->cp.minmapsize,
+                      p->cp.quietmmap, NULL, "--cathdu");
   if(cols==NULL)
     error(EXIT_FAILURE, 0, "%s: is empty! No usable information "
           "(un-commented lines) could be read from this file",
@@ -880,7 +881,8 @@ ui_preparations_to_img_mode(struct cropparams *p)
   double *darr, pixwidth, *pixscale;
   struct wcsprm *wcs=gal_wcs_read(p->inputs->v, p->cp.hdu,
                                   p->cp.wcslinearmatrix,
-                                  p->hstartwcs, p->hendwcs, &nwcs);
+                                  p->hstartwcs, p->hendwcs, &nwcs,
+                                  "--hdu");
 
   /* Make sure a WCS actually exists. */
   if(wcs==NULL)
@@ -1061,7 +1063,7 @@ ui_preparations(struct cropparams *p)
       status=0;
       img=&p->imgs[--input_counter];
       img->name=gal_list_str_pop(&p->inputs);
-      tmpfits=gal_fits_hdu_open_format(img->name, p->cp.hdu, 0);
+      tmpfits=gal_fits_hdu_open_format(img->name, p->cp.hdu, 0, "--hdu");
       gal_fits_img_info(tmpfits, &p->type, &img->ndim, &img->dsize,
                         NULL, NULL);
       img->wcs=gal_wcs_read_fitsptr(tmpfits, p->cp.wcslinearmatrix,
diff --git a/bin/fits/fits.c b/bin/fits/fits.c
index 9c3e4475..15017e85 100644
--- a/bin/fits/fits.c
+++ b/bin/fits/fits.c
@@ -103,7 +103,7 @@ fits_print_extension_info(struct fitsparams *p)
   /* Open the FITS file and read the first extension type, upon moving to
      the next extension, we will read its type, so for the first we will
      need to do it explicitly. */
-  fptr=gal_fits_hdu_open(p->input->v, "0", READONLY, 1);
+  fptr=gal_fits_hdu_open(p->input->v, "0", READONLY, 1, "NONE");
   if (fits_get_hdu_type(fptr, &hdutype, &status) )
     gal_fits_io_error(status, "reading first extension");
 
@@ -327,7 +327,7 @@ fits_hdu_number(struct fitsparams *p)
   int numhdu, status=0;
 
   /* Read the first extension (necessary for reading the rest). */
-  fptr=gal_fits_hdu_open(p->input->v, "0", READONLY, 1);
+  fptr=gal_fits_hdu_open(p->input->v, "0", READONLY, 1, "NONE");
 
   /* Get the number of HDUs. */
   if( fits_get_num_hdus(fptr, &numhdu, &status) )
@@ -347,7 +347,7 @@ fits_hdu_number(struct fitsparams *p)
 static void
 fits_datasum(struct fitsparams *p)
 {
-  printf("%ld\n", gal_fits_hdu_datasum(p->input->v, p->cp.hdu));
+  printf("%ld\n", gal_fits_hdu_datasum(p->input->v, p->cp.hdu, "--hdu"));
 }
 
 
@@ -363,7 +363,7 @@ fits_read_check_wcs(struct fitsparams *p, size_t *ndim,
 
   /* Read the desired WCS. */
   wcs=gal_wcs_read(p->input->v, p->cp.hdu, p->cp.wcslinearmatrix,
-                   0, 0, &nwcs);
+                   0, 0, &nwcs, "--hdu");
 
   /* If a WCS doesn't exist, let the user know and return. */
   if(wcs)
@@ -535,7 +535,7 @@ fits_skycoverage(struct fitsparams *p)
 
   /* Find the coverage. */
   if( gal_wcs_coverage(p->input->v, p->cp.hdu, &ndim,
-                       &center, &width, &min, &max)==0 )
+                       &center, &width, &min, &max, "--hdu")==0 )
     error(EXIT_FAILURE, 0, "%s (hdu %s): is not usable for finding "
           "sky coverage (either doesn't have a WCS, or isn't an image "
           "or cube HDU with 2 or 3 dimensions", p->input->v, p->cp.hdu);
@@ -576,7 +576,7 @@ fits_skycoverage(struct fitsparams *p)
 
       /* For the range type of coverage. */
       wcs=gal_wcs_read(p->input->v, p->cp.hdu, p->cp.wcslinearmatrix,
-                       0, 0, &nwcs);
+                       0, 0, &nwcs, "--hdu");
       printf("\nSky coverage by range along dimensions:\n");
       for(i=0;i<ndim;++i)
         printf("  %-8s %-15.10g%-15.10g\n", gal_wcs_dimension_name(wcs, i),
@@ -763,7 +763,7 @@ fits_hdu_remove(struct fitsparams *p, int *r)
       hdu=gal_list_str_pop(&p->remove);
 
       /* Open the FITS file at the specified HDU. */
-      fptr=gal_fits_hdu_open(p->input->v, hdu, READWRITE, 1);
+      fptr=gal_fits_hdu_open(p->input->v, hdu, READWRITE, 1, "--remove");
 
       /* Delete the extension. */
       if( fits_delete_hdu(fptr, &hdutype, &status) )
@@ -816,6 +816,7 @@ fits_hdu_copy(struct fitsparams *p, int cut1_copy0, int *r)
   char *hdu;
   int status=0, hdutype;
   fitsfile *in, *out=NULL;
+  char *hopt = cut1_copy0 ? "--cut" : "--copy";
   gal_list_str_t *list = cut1_copy0 ? p->cut : p->copy;
 
   /* Copy all the given extensions. */
@@ -826,11 +827,11 @@ fits_hdu_copy(struct fitsparams *p, int cut1_copy0, int 
*r)
 
       /* Open the FITS file at the specified HDU. */
       in=gal_fits_hdu_open(p->input->v, hdu,
-                           cut1_copy0 ? READWRITE : READONLY, 1);
+                           cut1_copy0 ? READWRITE : READONLY, 1, hopt);
 
       /* If the output isn't opened yet, open it.  */
       if(out==NULL)
-        out = ( ( gal_fits_hdu_format(p->input->v, hdu)==IMAGE_HDU
+        out = ( ( gal_fits_hdu_format(p->input->v, hdu, hopt)==IMAGE_HDU
                   && p->primaryimghdu )
                 ? fits_open_to_write_no_blank(p->cp.output)
                 : gal_fits_open_to_write(p->cp.output) );
diff --git a/bin/fits/keywords.c b/bin/fits/keywords.c
index c6afff2e..359a55d5 100644
--- a/bin/fits/keywords.c
+++ b/bin/fits/keywords.c
@@ -53,7 +53,7 @@ static void
 keywords_open(struct fitsparams *p, fitsfile **fptr, int iomode)
 {
   if(*fptr==NULL)
-    *fptr=gal_fits_hdu_open(p->input->v, p->cp.hdu, iomode, 1);
+    *fptr=gal_fits_hdu_open(p->input->v, p->cp.hdu, iomode, 1, "--hdu");
 }
 
 
@@ -507,7 +507,8 @@ keywords_copykeys(struct fitsparams *p, char *inkeys, 
size_t numinkeys)
   int updatechecksum=0, checksumexists=0;
 
   /* Open the output HDU. */
-  fptr=gal_fits_hdu_open(p->cp.output, p->outhdu, READWRITE, 1);
+  fptr=gal_fits_hdu_open(p->cp.output, p->outhdu, READWRITE, 1,
+                         "--outhdu");
 
   /* See if a 'CHECKSUM' key exists in the HDU or not (to update in case we
      wrote anything). */
@@ -585,22 +586,22 @@ keywords_wcs_convert(struct fitsparams *p)
 
   /* If the extension has any data, read it, otherwise just make an empty
      array. */
-  if(gal_fits_hdu_format(p->input->v, p->cp.hdu)==IMAGE_HDU)
+  if(gal_fits_hdu_format(p->input->v, p->cp.hdu, "--hdu")==IMAGE_HDU)
     {
       /* Read the size of the dataset (we don't need the actual size!). */
-      insize=gal_fits_img_info_dim(p->input->v, p->cp.hdu, &ndim);
+      insize=gal_fits_img_info_dim(p->input->v, p->cp.hdu, &ndim, "--hdu");
       free(insize);
 
       /* If the number of dimensions is two, then read the dataset,
          otherwise, ignore it. */
       if(ndim==2)
         data=gal_fits_img_read(p->input->v, p->cp.hdu, p->cp.minmapsize,
-                               p->cp.quietmmap);
+                               p->cp.quietmmap, "--hdu");
     }
 
   /* Read the input's WCS and make sure one exists. */
   inwcs=gal_wcs_read(p->input->v, p->cp.hdu, p->cp.wcslinearmatrix,
-                     0, 0, &nwcs);
+                     0, 0, &nwcs, "--hdu");
   if(inwcs==NULL)
     error(EXIT_FAILURE, 0, "%s (hdu %s): doesn't have any WCS structure "
           "for converting its coordinate system or distortion",
@@ -946,7 +947,7 @@ keywords_value(struct fitsparams *p)
   for(input=p->input; input!=NULL; input=input->next)
     {
       /* Open the input FITS file. */
-      fptr=gal_fits_hdu_open(input->v, p->cp.hdu, READONLY, 1);
+      fptr=gal_fits_hdu_open(input->v, p->cp.hdu, READONLY, 1, "--hdu");
 
       /* Allocate the array to keep the keys. */
       i=0;
diff --git a/bin/fits/meta.c b/bin/fits/meta.c
index 8625a26b..64fc526e 100644
--- a/bin/fits/meta.c
+++ b/bin/fits/meta.c
@@ -68,8 +68,8 @@ meta_initialize(struct fitsparams *p, gal_warp_wcsalign_t *wa)
 
   /* Read the input image and its WCS, must free it when done. */
   input=gal_array_read_one_ch_to_type(inputname, hdu, NULL,
-                                      GAL_TYPE_FLOAT64, -1,  0);
-  input->wcs=gal_wcs_read(inputname, hdu, 0, 0, 0, &input->nwcs);
+                                      GAL_TYPE_FLOAT64, -1,  0, "--hdu");
+  input->wcs=gal_wcs_read(inputname, hdu, 0, 0, 0, &input->nwcs, "--hdu");
 
   /* Prepare the essential warping variables. */
   wa->input=input;
diff --git a/bin/match/match.c b/bin/match/match.c
index a92bb0cf..06524670 100644
--- a/bin/match/match.c
+++ b/bin/match/match.c
@@ -45,8 +45,10 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 /* Number of columns in a file. */
 static gal_list_str_t *
-match_add_all_cols(char *filename, char *extname, gal_list_str_t *stdinlines,
-                   gal_list_str_t *incols, size_t *num)
+match_add_all_cols(char *filename, char *extname,
+                   gal_list_str_t *stdinlines,
+                   gal_list_str_t *incols, size_t *num,
+                   char *hdu_option_name)
 {
   char *tstr;
   int tableformat;
@@ -64,8 +66,9 @@ match_add_all_cols(char *filename, char *extname, 
gal_list_str_t *stdinlines,
           if( numcols == GAL_BLANK_SIZE_T )
             {
               colinfo=gal_table_info(filename, extname,
-                                     filename ? NULL : stdinlines, &numcols,
-                                     &numrows, &tableformat);
+                                     filename ? NULL : stdinlines,
+                                     &numcols, &numrows, &tableformat,
+                                     hdu_option_name);
               gal_data_array_free(colinfo, numcols, 1);
             }
 
@@ -316,6 +319,7 @@ match_catalog_read_write_all(struct matchparams *p, size_t 
*permutation,
   gal_data_t *tmp, *cat;
   gal_list_str_t *cols, *tcol;
 
+  char *hopt             = (f1s2==1) ? "--hdu"       : "--hdu2";
   char *hdu              = (f1s2==1) ? p->cp.hdu     : p->hdu2;
   gal_list_str_t *incols = (f1s2==1) ? p->acols      : p->bcols;
   size_t *numcols        = (f1s2==1) ? &p->anum      : &p->bnum;
@@ -338,7 +342,7 @@ match_catalog_read_write_all(struct matchparams *p, size_t 
*permutation,
       if(hasall)
         {
           cols=match_add_all_cols(filename, hdu, p->stdinlines, incols,
-                                  numcols);
+                                  numcols, hopt);
           if(f1s2==1) { gal_list_str_free(p->acols, 0); p->acols=cols; }
           else        { gal_list_str_free(p->bcols, 0); p->bcols=cols; }
         }
@@ -360,7 +364,7 @@ match_catalog_read_write_all(struct matchparams *p, size_t 
*permutation,
     cat=gal_table_read(filename, hdu, filename ? NULL : p->stdinlines,
                        cols, p->cp.searchin, p->cp.ignorecase,
                        p->cp.numthreads, p->cp.minmapsize,
-                       p->cp.quietmmap, *numcolmatch);
+                       p->cp.quietmmap, *numcolmatch, hopt);
   else
     cat=match_cat_from_coord(p, cols, *numcolmatch);
 
@@ -886,6 +890,7 @@ match(struct matchparams *p)
                                   p->input2name?p->input2name:"--coord",
                                   &p->cp.okeys, 1, p->cp.quiet);
       gal_fits_key_write_config(&p->cp.okeys, "Match configuration",
-                                "MATCH-CONFIG", p->out1name, "0");
+                                "MATCH-CONFIG", p->out1name, "0",
+                                "NONE");
     }
 }
diff --git a/bin/match/ui.c b/bin/match/ui.c
index 7c51a489..ade4e5e7 100644
--- a/bin/match/ui.c
+++ b/bin/match/ui.c
@@ -360,7 +360,7 @@ ui_set_mode(struct matchparams *p)
      on plain text. */
   if( p->input1name && gal_fits_file_recognized(p->input1name) )
     {
-      tin1=gal_fits_hdu_format(p->input1name, p->cp.hdu);
+      tin1=gal_fits_hdu_format(p->input1name, p->cp.hdu, "--hdu");
       p->mode = (tin1 == IMAGE_HDU) ? MATCH_MODE_WCS : MATCH_MODE_CATALOG;
     }
   else
@@ -384,7 +384,7 @@ ui_set_mode(struct matchparams *p)
     {
       if(gal_fits_file_recognized(p->input2name))
         {
-          tin2=gal_fits_hdu_format(p->input2name, p->hdu2);
+          tin2=gal_fits_hdu_format(p->input2name, p->hdu2, "--hdu2");
           if(tin1==IMAGE_HDU && tin2!=IMAGE_HDU)
             {
               t1 = (tin1==IMAGE_HDU) ? "image" : "catalog";
@@ -720,8 +720,9 @@ ui_set_columns_from_coord(struct matchparams *p)
 /* We want to keep the columns as double type. So what-ever their original
    type is, convert it. */
 static gal_data_t *
-ui_read_columns_to_double(struct matchparams *p, char *filename, char *hdu,
-                          gal_list_str_t *cols, size_t numcols)
+ui_read_columns_to_double(struct matchparams *p, char *filename,
+                          char *hdu, gal_list_str_t *cols,
+                          size_t numcols, char *hdu_option_name)
 {
   gal_data_t *tmp, *ttmp, *tout, *out=NULL;
   struct gal_options_common_params *cp=&p->cp;
@@ -740,7 +741,8 @@ ui_read_columns_to_double(struct matchparams *p, char 
*filename, char *hdu,
                                           "input");
   tout=gal_table_read(filename, hdu, filename ? NULL : p->stdinlines,
                       cols, cp->searchin, cp->ignorecase, cp->numthreads,
-                      cp->minmapsize, p->cp.quietmmap, NULL);
+                      cp->minmapsize, p->cp.quietmmap, NULL,
+                      hdu_option_name);
 
   /* A small sanity check. */
   if(gal_list_data_number(tout)!=numcols)
@@ -802,7 +804,7 @@ ui_read_kdtree(struct matchparams *p)
   p->kdtreedata=gal_table_read(p->kdtree, p->kdtreehdu, NULL,
                                NULL, GAL_TABLE_SEARCH_NAME, 1,
                                p->cp.numthreads, p->cp.minmapsize,
-                               p->cp.quietmmap, NULL);
+                               p->cp.quietmmap, NULL, "--kdtreehdu");
 
   /* It has to have only two columns, with an unsigned 32-bit integer
      type in each. */
@@ -876,12 +878,12 @@ ui_read_columns(struct matchparams *p)
 
   /* Read-in the columns. */
   p->cols1=ui_read_columns_to_double(p, p->input1name, p->cp.hdu,
-                                     cols1, ndim);
+                                     cols1, ndim, "--hdu");
   if( p->kdtreemode!=MATCH_KDTREE_BUILD )
     p->cols2=( p->coord
                ? ui_set_columns_from_coord(p)
                : ui_read_columns_to_double(p, p->input2name, p->hdu2,
-                                           cols2, ndim) );
+                                           cols2, ndim, "--hdu2") );
 
   /* If an external k-d tree is given, read it and make sure it has the
      same number of rows as the first input and the proper datatype. */
diff --git a/bin/mkcatalog/mkcatalog.c b/bin/mkcatalog/mkcatalog.c
index f107f757..a0dfeca5 100644
--- a/bin/mkcatalog/mkcatalog.c
+++ b/bin/mkcatalog/mkcatalog.c
@@ -751,7 +751,8 @@ mkcatalog_write_outputs(struct mkcatalogparams *p)
       gal_fits_key_write_filename("input", p->objectsfile, &p->cp.okeys,
                                   1, p->cp.quiet);
       gal_fits_key_write_config(&p->cp.okeys, "MakeCatalog configuration",
-                                "MKCATALOG-CONFIG", p->objectsout, "0");
+                                "MKCATALOG-CONFIG", p->objectsout, "0",
+                                "NONE");
     }
 
 
diff --git a/bin/mkcatalog/ui.c b/bin/mkcatalog/ui.c
index 33a574dd..f3dced2a 100644
--- a/bin/mkcatalog/ui.c
+++ b/bin/mkcatalog/ui.c
@@ -544,7 +544,7 @@ ui_wcs_info(struct mkcatalogparams *p)
   /* Read the WCS meta-data. */
   p->objects->wcs=gal_wcs_read(p->objectsfile, p->cp.hdu,
                                p->cp.wcslinearmatrix, 0, 0,
-                               &p->objects->nwcs);
+                               &p->objects->nwcs, "--hdu");
 
   /* Read the basic WCS information. */
   if(p->objects->wcs)
@@ -843,7 +843,8 @@ ui_read_labels(struct mkcatalogparams *p)
 
   /* Read it into memory. */
   p->objects = gal_array_read_one_ch(p->objectsfile, p->cp.hdu, NULL,
-                                     p->cp.minmapsize, p->cp.quietmmap);
+                                     p->cp.minmapsize, p->cp.quietmmap,
+                                     "--hdu");
   p->objects->ndim=gal_dimension_remove_extra(p->objects->ndim,
                                               p->objects->dsize, NULL);
 
@@ -935,7 +936,7 @@ ui_read_labels(struct mkcatalogparams *p)
       /* Read the clumps image. */
       p->clumps = gal_array_read_one_ch(p->usedclumpsfile, p->clumpshdu,
                                         NULL, p->cp.minmapsize,
-                                        p->cp.quietmmap);
+                                        p->cp.quietmmap, "--clumpshdu");
       p->clumps->ndim=gal_dimension_remove_extra(p->clumps->ndim,
                                                  p->clumps->dsize, NULL);
 
@@ -1299,7 +1300,8 @@ ui_preparations_read_inputs(struct mkcatalogparams *p)
                                               p->valueshdu,
                                               NULL, GAL_TYPE_FLOAT32,
                                               p->cp.minmapsize,
-                                              p->cp.quietmmap);
+                                              p->cp.quietmmap,
+                                              "--valueshdu");
       p->values->ndim=gal_dimension_remove_extra(p->values->ndim,
                                                  p->values->dsize, NULL);
 
@@ -1355,7 +1357,8 @@ ui_preparations_read_inputs(struct mkcatalogparams *p)
           p->sky=gal_array_read_one_ch_to_type(p->usedskyfile, p->skyhdu,
                                                NULL, GAL_TYPE_FLOAT32,
                                                p->cp.minmapsize,
-                                               p->cp.quietmmap);
+                                               p->cp.quietmmap,
+                                               "--skyhdu");
           p->sky->ndim=gal_dimension_remove_extra(p->sky->ndim,
                                                   p->sky->dsize, NULL);
 
@@ -1387,7 +1390,7 @@ ui_preparations_read_inputs(struct mkcatalogparams *p)
       p->std=gal_array_read_one_ch_to_type(p->usedstdfile, p->stdhdu,
                                            NULL, GAL_TYPE_FLOAT32,
                                            p->cp.minmapsize,
-                                           p->cp.quietmmap);
+                                           p->cp.quietmmap, "--stdhdu");
       p->std->ndim=gal_dimension_remove_extra(p->std->ndim,
                                               p->std->dsize, NULL);
 
@@ -1423,7 +1426,8 @@ ui_preparations_read_inputs(struct mkcatalogparams *p)
           /* Read the mask image. */
           p->upmask = gal_array_read_one_ch(p->upmaskfile, p->upmaskhdu,
                                             NULL, p->cp.minmapsize,
-                                            p->cp.quietmmap);
+                                            p->cp.quietmmap,
+                                            "--upmaskhdu");
           p->upmask->ndim=gal_dimension_remove_extra(p->upmask->ndim,
                                                      p->upmask->dsize,
                                                      NULL);
diff --git a/bin/mknoise/mknoise.c b/bin/mknoise/mknoise.c
index 1b316941..24e37c41 100644
--- a/bin/mknoise/mknoise.c
+++ b/bin/mknoise/mknoise.c
@@ -122,7 +122,7 @@ convertsaveoutput(struct mknoiseparams *p)
   gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1,
                               p->cp.quiet);
   gal_fits_key_write_config(&p->cp.okeys, "MakeNoise configuration",
-                            "MKNOISE-CONFIG", p->cp.output, "0");
+                            "MKNOISE-CONFIG", p->cp.output, "0", "NONE");
 }
 
 
diff --git a/bin/mknoise/ui.c b/bin/mknoise/ui.c
index 18da75b4..163e8094 100644
--- a/bin/mknoise/ui.c
+++ b/bin/mknoise/ui.c
@@ -310,10 +310,12 @@ ui_preparations(struct mknoiseparams *p)
 {
   /* Read the input image as a double type */
   p->input=gal_array_read_one_ch_to_type(p->inputname, p->cp.hdu, NULL,
-                                         GAL_TYPE_FLOAT64, p->cp.minmapsize,
-                                         p->cp.quietmmap);
-  p->input->wcs=gal_wcs_read(p->inputname, p->cp.hdu, p->cp.wcslinearmatrix,
-                             0, 0, &p->input->nwcs);
+                                         GAL_TYPE_FLOAT64,
+                                         p->cp.minmapsize,
+                                         p->cp.quietmmap, "--hdu");
+  p->input->wcs=gal_wcs_read(p->inputname, p->cp.hdu,
+                             p->cp.wcslinearmatrix, 0, 0, &p->input->nwcs,
+                             "--hdu");
   p->input->ndim=gal_dimension_remove_extra(p->input->ndim, p->input->dsize,
                                             p->input->wcs);
 
diff --git a/bin/mkprof/args.h b/bin/mkprof/args.h
index efa52c63..aea22994 100644
--- a/bin/mkprof/args.h
+++ b/bin/mkprof/args.h
@@ -90,7 +90,7 @@ struct argp_option program_options[] =
       0,
       "File for 'custom-prof' profile.",
       GAL_OPTIONS_GROUP_INPUT,
-      &p->customprofname,
+      &p->customtablename,
       GAL_TYPE_STRING,
       GAL_OPTIONS_RANGE_ANY,
       GAL_OPTIONS_NOT_MANDATORY,
@@ -103,7 +103,7 @@ struct argp_option program_options[] =
       0,
       "HDU of table given to '--customtable'.",
       GAL_OPTIONS_GROUP_INPUT,
-      &p->customprofhdu,
+      &p->customtablehdu,
       GAL_TYPE_STRING,
       GAL_OPTIONS_RANGE_ANY,
       GAL_OPTIONS_NOT_MANDATORY,
diff --git a/bin/mkprof/main.h b/bin/mkprof/main.h
index 49268431..fd7238f4 100644
--- a/bin/mkprof/main.h
+++ b/bin/mkprof/main.h
@@ -119,8 +119,8 @@ struct mkprofparams
   char            *backname;  /* Name of background image file name.      */
   char             *catname;  /* Name of catalog of parameters.           */
   char             *backhdu;  /* HDU of background image.                 */
-  char      *customprofname;  /* Table to use for radial profile.         */
-  char       *customprofhdu;  /* HDU of table to use for radial profile.  */
+  char     *customtablename;  /* Table to use for radial profile.         */
+  char      *customtablehdu;  /* HDU of table to use for radial profile.  */
   gal_list_str_t *customimgname;  /* Image to insert into the image.      */
   gal_list_str_t  *customimghdu;  /* HDU of images for custom image.      */
   size_t             *dsize;  /* Size of the output image.                */
diff --git a/bin/mkprof/mkprof.c b/bin/mkprof/mkprof.c
index ac4edaaf..815b1f11 100644
--- a/bin/mkprof/mkprof.c
+++ b/bin/mkprof/mkprof.c
@@ -266,8 +266,8 @@ saveindividual(struct mkonthread *mkp)
                         "not full profile", 0, NULL, 0);
 
   gal_fits_key_list_reverse(&keys);
-  gal_fits_key_write_config(&keys, "Profile configuration", "PROFILE-CONFIG",
-                            filename, "0");
+  gal_fits_key_write_config(&keys, "Profile configuration",
+                            "PROFILE-CONFIG", filename, "0", "NONE");
 
 
   /* Report if in verbose mode. */
@@ -723,7 +723,8 @@ mkprof_write(struct mkprofparams *p)
       gal_fits_key_write_filename("input", p->catname, &p->cp.okeys, 1,
                                   p->cp.quiet);
       gal_fits_key_write_config(&p->cp.okeys, "MakeProfiles configuration",
-                                "MKPROF-CONFIG", p->mergedimgname, "0");
+                                "MKPROF-CONFIG", p->mergedimgname, "0",
+                                "NONE");
 
       /* In verbose mode, print the information. */
       if(!p->cp.quiet)
diff --git a/bin/mkprof/oneprofile.c b/bin/mkprof/oneprofile.c
index 75c6e30a..907a24d8 100644
--- a/bin/mkprof/oneprofile.c
+++ b/bin/mkprof/oneprofile.c
@@ -558,7 +558,8 @@ oneprofile_custom_img(struct mkprofparams *p, size_t id)
   if(p->customimghdu->next)
     for(i=1;i<imgcounter;++i) thdu=thdu->next;
   out=gal_fits_img_read_to_type(timg->v, thdu->v, GAL_TYPE_FLOAT32,
-                                p->cp.minmapsize, p->cp.quietmmap);
+                                p->cp.minmapsize, p->cp.quietmmap,
+                                "--customimghdu");
 
   /* Make sure the image has an odd number of pixels on each side. */
   if( out->dsize[0]%2==0 || out->dsize[1]%2==0 )
diff --git a/bin/mkprof/ui.c b/bin/mkprof/ui.c
index 91ec89f1..e58e097f 100644
--- a/bin/mkprof/ui.c
+++ b/bin/mkprof/ui.c
@@ -703,7 +703,7 @@ ui_read_cols_general(struct mkprofparams *p, gal_list_str_t 
*colstrs)
   lines=gal_options_check_stdin(p->catname, p->cp.stdintimeout, "input");
   cols=gal_table_read(p->catname, p->cp.hdu, lines, colstrs,
                       p->cp.searchin, p->cp.ignorecase, p->cp.numthreads,
-                      p->cp.minmapsize, p->cp.quietmmap, NULL);
+                      p->cp.minmapsize, p->cp.quietmmap, NULL, "--hdu");
   gal_list_str_free(lines, 1);
 
   /* The name of the input catalog is only for informative steps from now
@@ -1336,7 +1336,7 @@ ui_prepare_columns(struct mkprofparams *p)
     {
       if(p->f[i]==PROFILE_CUSTOM_PROF)
         {
-          if(p->customprofname==NULL)
+          if(p->customtablename==NULL)
             error(EXIT_FAILURE, 0, "at least one custom profile "
                   "requested (first occurrence in row %zu), but no "
                   "file/table was given to the '--customtable' "
@@ -1521,9 +1521,10 @@ ui_prepare_canvas(struct mkprofparams *p)
          no merged image is desired, we just need the WCS information of
          the background image and the number of its dimensions. So
          'ndim==0' and what 'dsize' points to is irrelevant. */
-      tdsize=gal_fits_img_info_dim(p->backname, p->backhdu, &tndim);
+      tdsize=gal_fits_img_info_dim(p->backname, p->backhdu, &tndim,
+                                   "--backhdu");
       p->wcs=gal_wcs_read(p->backname, p->backhdu, p->cp.wcslinearmatrix,
-                          0, 0, &p->nwcs);
+                          0, 0, &p->nwcs, "--backhdu");
       tndim=gal_dimension_remove_extra(tndim, tdsize, p->wcs);
       free(tdsize);
       if(p->nomerged==0)
@@ -1843,10 +1844,10 @@ ui_read_custom_table(struct mkprofparams *p)
   double *min, *max;
 
   /* Read the input radial table. */
-  cols=gal_table_read(p->customprofname, p->customprofhdu,
+  cols=gal_table_read(p->customtablename, p->customtablehdu,
                       NULL, NULL, p->cp.searchin, p->cp.ignorecase,
                       p->cp.numthreads, p->cp.minmapsize,
-                      p->cp.quietmmap, NULL);
+                      p->cp.quietmmap, NULL, "--customtablehdu");
 
   /* Make sure the table only has three columns. */
   if(gal_list_data_number(cols) != 3 )
@@ -1855,8 +1856,8 @@ ui_read_custom_table(struct mkprofparams *p)
           "value. Column 2: the radial interval's higher value. "
           "Column 3: the value to use for pixels within that radius "
           "interval",
-          gal_fits_name_save_as_string(p->customprofname,
-                                       p->customprofhdu),
+          gal_fits_name_save_as_string(p->customtablename,
+                                       p->customtablehdu),
           gal_list_data_number(cols));
 
   /* Make sure none of the three columns are string type. */
@@ -1864,8 +1865,8 @@ ui_read_custom_table(struct mkprofparams *p)
       || cols->next->type==GAL_TYPE_STRING
       || cols->next->next->type==GAL_TYPE_STRING )
     error(EXIT_FAILURE, 0, "%s: the columns should only have numeric "
-          "data types", gal_fits_name_save_as_string(p->customprofname,
-                                                     p->customprofhdu));
+          "data types", gal_fits_name_save_as_string(p->customtablename,
+                                                     p->customtablehdu));
 
   /* Fill the final table as a double type. */
   p->custom=gal_data_copy_to_new_type(cols, GAL_TYPE_FLOAT64);
@@ -1885,8 +1886,8 @@ ui_read_custom_table(struct mkprofparams *p)
             "value %g). However, the first column is the lower-limit "
             "of the radial interval and the second column is the "
             "upper-limit. So the first column must have a lower value",
-            gal_fits_name_save_as_string(p->customprofname,
-                                         p->customprofhdu), i+1,
+            gal_fits_name_save_as_string(p->customtablename,
+                                         p->customtablehdu), i+1,
             min[i], max[i]);
 
   /* Check if the input table is regular and sorted (which can greatly
@@ -1944,7 +1945,7 @@ ui_read_ndim(struct mkprofparams *p)
             {
               /* Get the number of the background image's dimensions. */
               dsize=gal_fits_img_info_dim(p->backname, p->backhdu,
-                                          &p->ndim);
+                                          &p->ndim, "--backhdu");
               p->ndim=gal_dimension_remove_extra(p->ndim, dsize, NULL);
               free(dsize);
             }
@@ -1954,7 +1955,8 @@ ui_read_ndim(struct mkprofparams *p)
               p->out=gal_array_read_one_ch_to_type(p->backname, p->backhdu,
                                                    NULL, GAL_TYPE_FLOAT32,
                                                    p->cp.minmapsize,
-                                                   p->cp.quietmmap);
+                                                   p->cp.quietmmap,
+                                                   "--backhdu");
               p->out->ndim=gal_dimension_remove_extra(p->out->ndim,
                                                       p->out->dsize, NULL);
               p->ndim=p->out->ndim;
@@ -1998,7 +2000,7 @@ ui_preparations(struct mkprofparams *p)
   ui_prepare_columns(p);
 
   /* Read the radial table. */
-  if(p->customprofname) ui_read_custom_table(p);
+  if(p->customtablename) ui_read_custom_table(p);
 
   /* If the kernel option was given, some parameters need to be
      over-written: */
diff --git a/bin/noisechisel/noisechisel.c b/bin/noisechisel/noisechisel.c
index e8e8c37a..fa9456e5 100644
--- a/bin/noisechisel/noisechisel.c
+++ b/bin/noisechisel/noisechisel.c
@@ -209,7 +209,8 @@ noisechisel_output(struct noisechiselparams *p)
   gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1,
                               p->cp.quiet);
   gal_fits_key_write_config(&p->cp.okeys, "NoiseChisel configuration",
-                            "NOISECHISEL-CONFIG", p->cp.output, "0");
+                            "NOISECHISEL-CONFIG", p->cp.output, "0",
+                            "NONE");
 
 
   /* Let the user know that the output is written. */
diff --git a/bin/noisechisel/ui.c b/bin/noisechisel/ui.c
index c73d6bb0..d5220a4e 100644
--- a/bin/noisechisel/ui.c
+++ b/bin/noisechisel/ui.c
@@ -451,7 +451,7 @@ ui_prepare_kernel(struct noisechiselparams *p)
           /* Read the kernel into memory. */
           p->kernel=gal_fits_img_read_kernel(p->kernelname, p->khdu,
                                              p->cp.minmapsize,
-                                             p->cp.quietmmap);
+                                             p->cp.quietmmap, "--khdu");
 
           /* Make sure it has the same dimensions as the input. */
           if( p->kernel->ndim != p->input->ndim )
@@ -481,7 +481,8 @@ ui_prepare_kernel(struct noisechiselparams *p)
      ignore it. */
   if(p->widekernelname)
     p->widekernel=gal_fits_img_read_kernel(p->widekernelname, p->whdu,
-                                           p->cp.minmapsize, p->cp.quietmmap);
+                                           p->cp.minmapsize,
+                                           p->cp.quietmmap, "--whdu");
 }
 
 
@@ -609,10 +610,10 @@ ui_preparations_read_input(struct noisechiselparams *p)
   p->input = gal_array_read_one_ch_to_type(p->inputname, p->cp.hdu,
                                            NULL, GAL_TYPE_FLOAT32,
                                            p->cp.minmapsize,
-                                           p->cp.quietmmap);
+                                           p->cp.quietmmap, "--hdu");
   p->input->wcs = gal_wcs_read(p->inputname, p->cp.hdu,
                                p->cp.wcslinearmatrix, 0, 0,
-                               &p->input->nwcs);
+                               &p->input->nwcs, "--hdu");
   p->input->ndim=gal_dimension_remove_extra(p->input->ndim,
                                             p->input->dsize,
                                             p->input->wcs);
@@ -682,7 +683,8 @@ ui_preparations(struct noisechiselparams *p)
       p->conv = gal_array_read_one_ch_to_type(p->convolvedname, p->chdu,
                                               NULL, GAL_TYPE_FLOAT32,
                                               p->cp.minmapsize,
-                                              p->cp.quietmmap);
+                                              p->cp.quietmmap,
+                                              "--chdu");
 
       /* Make sure the convolved image is the same size as the input. */
       if( gal_dimension_is_different(p->input, p->conv) )
diff --git a/bin/query/query.c b/bin/query/query.c
index 8720cb6d..a6280f47 100644
--- a/bin/query/query.c
+++ b/bin/query/query.c
@@ -78,7 +78,7 @@ query_output_meta_database(struct queryparams *p)
   /* Get the downloaded metadata column information so we can ask for the
      proper columns. */
   allcols=gal_table_info(p->downloadname, "1", NULL, &numcols,
-                         &numrows, &tableformat);
+                         &numrows, &tableformat, "NONE");
 
   /* Parse the column information to set the necessary columns. */
   if( query_output_meta_col(&cols, allcols, numcols, "table_name") == 0 )
@@ -97,7 +97,8 @@ query_output_meta_database(struct queryparams *p)
   gal_list_str_reverse(&cols);
   table=gal_table_read(p->downloadname, "1", NULL, cols,
                        GAL_TABLE_SEARCH_NAME, 1, p->cp.numthreads,
-                       p->cp.minmapsize, p->cp.quietmmap, NULL);
+                       p->cp.minmapsize, p->cp.quietmmap, NULL,
+                       "NONE");
 
   /* Set the basic columns for easy reading. */
   name=table->array;
@@ -189,7 +190,7 @@ query_output_meta_dataset(struct queryparams *p)
   /* Get the downloaded metadata column information so we can ask for the
      proper columns. */
   allcols=gal_table_info(p->downloadname, "1", NULL, &numcols,
-                         &numrows, &tableformat);
+                         &numrows, &tableformat, "NONE");
 
   /* Parse the column information to set the necessary columns. */
   if( query_output_meta_col(&cols, allcols, numcols, "column_name") == 0 )
@@ -210,7 +211,8 @@ query_output_meta_dataset(struct queryparams *p)
   gal_list_str_reverse(&cols);
   table=gal_table_read(p->downloadname, "1", NULL, cols,
                        GAL_TABLE_SEARCH_NAME, 1, p->cp.numthreads,
-                       p->cp.minmapsize, p->cp.quietmmap, NULL);
+                       p->cp.minmapsize, p->cp.quietmmap, NULL,
+                       "NONE");
 
   /* It may happen that the required dataset name isn't recognized by the
      database. In this case, 'table' will have 0 rows. */
@@ -276,7 +278,8 @@ query_output_data(struct queryparams *p)
      downloaded table is compressed in any special FITS way). */
   table=gal_table_read(p->downloadname, "1", NULL, NULL,
                        GAL_TABLE_SEARCH_NAME, 1, p->cp.numthreads,
-                       p->cp.minmapsize, p->cp.quietmmap, NULL);
+                       p->cp.minmapsize, p->cp.quietmmap, NULL,
+                       "NONE");
   gal_table_write(table, NULL, NULL, p->cp.tableformat,
                   p->cp.output ? p->cp.output : p->cp.output,
                   "QUERY", 0);
@@ -356,7 +359,8 @@ query_output_finalize(struct queryparams *p)
       gal_fits_key_list_fullcomment_add_end(&p->cp.okeys,
                                             p->finalcommand, 1);
       gal_fits_key_write_config(&p->cp.okeys, "Query settings",
-                                "QUERY-CONFIG", p->cp.output, "0");
+                                "QUERY-CONFIG", p->cp.output, "0",
+                                "NONE");
     }
 }
 
diff --git a/bin/query/tap.c b/bin/query/tap.c
index c4e4bff9..a8674b86 100644
--- a/bin/query/tap.c
+++ b/bin/query/tap.c
@@ -161,7 +161,7 @@ tap_query_construct_spatial(struct queryparams *p)
     {
       /* Calculate the Sky coverage of the overlap dataset. */
       gal_wcs_coverage(p->overlapwith, p->cp.hdu, &ndim, &ocenter,
-                       &owidth, &omin, &omax);
+                       &owidth, &omin, &omax, "--hdu");
 
       /* Make sure a WCS existed in the file. */
       if(owidth==NULL)
diff --git a/bin/segment/segment.c b/bin/segment/segment.c
index 27e958a8..ab593238 100644
--- a/bin/segment/segment.c
+++ b/bin/segment/segment.c
@@ -1453,7 +1453,7 @@ segment_output(struct segmentparams *p)
   gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1,
                               p->cp.quiet);
   gal_fits_key_write_config(&p->cp.okeys, "Segment configuration",
-                            "SEGMENT-CONFIG", p->cp.output, "0");
+                            "SEGMENT-CONFIG", p->cp.output, "0", "NONE");
 
   /* Let the user know that the output is written. */
   if(!p->cp.quiet)
diff --git a/bin/segment/ui.c b/bin/segment/ui.c
index 50e33455..95a65588 100644
--- a/bin/segment/ui.c
+++ b/bin/segment/ui.c
@@ -414,10 +414,10 @@ ui_prepare_inputs(struct segmentparams *p)
   p->input = gal_array_read_one_ch_to_type(p->inputname, p->cp.hdu,
                                            NULL, GAL_TYPE_FLOAT32,
                                            p->cp.minmapsize,
-                                           p->cp.quietmmap);
+                                           p->cp.quietmmap, "--hdu");
   p->input->wcs = gal_wcs_read(p->inputname, p->cp.hdu,
                                p->cp.wcslinearmatrix, 0, 0,
-                               &p->input->nwcs);
+                               &p->input->nwcs, "--hdu");
   p->input->ndim=gal_dimension_remove_extra(p->input->ndim,
                                             p->input->dsize,
                                             p->input->wcs);
@@ -445,7 +445,7 @@ ui_prepare_inputs(struct segmentparams *p)
       p->conv = gal_array_read_one_ch_to_type(p->convolvedname, p->chdu,
                                               NULL, GAL_TYPE_FLOAT32,
                                               p->cp.minmapsize,
-                                              p->cp.quietmmap);
+                                              p->cp.quietmmap, "--chdu");
       p->conv->ndim=gal_dimension_remove_extra(p->conv->ndim,
                                                p->conv->dsize,
                                                p->conv->wcs);
@@ -467,7 +467,7 @@ ui_prepare_inputs(struct segmentparams *p)
       /* Read the dataset into memory. */
       p->olabel = gal_array_read_one_ch(p->useddetectionname, p->dhdu,
                                         NULL, p->cp.minmapsize,
-                                        p->cp.quietmmap);
+                                        p->cp.quietmmap, "--dhdu");
       p->olabel->ndim=gal_dimension_remove_extra(p->olabel->ndim,
                                                  p->olabel->dsize, NULL);
       if( gal_dimension_is_different(p->input, p->olabel) )
@@ -564,7 +564,7 @@ ui_prepare_kernel(struct segmentparams *p)
           /* Read the kernel into memory. */
           p->kernel=gal_fits_img_read_kernel(p->kernelname, p->khdu,
                                              p->cp.minmapsize,
-                                             p->cp.quietmmap);
+                                             p->cp.quietmmap, "--khdu");
           p->kernel->ndim=gal_dimension_remove_extra(p->kernel->ndim,
                                                      p->kernel->dsize,
                                                      NULL);
@@ -775,7 +775,8 @@ ui_read_std_and_sky(struct segmentparams *p)
       /* Read the STD image. */
       p->std=gal_array_read_one_ch_to_type(p->usedstdname, p->stdhdu,
                                            NULL, GAL_TYPE_FLOAT32,
-                                           p->cp.minmapsize, p->cp.quietmmap);
+                                           p->cp.minmapsize,
+                                           p->cp.quietmmap, "--stdhdu");
       p->std->ndim=gal_dimension_remove_extra(p->std->ndim,
                                               p->std->dsize, NULL);
 
@@ -835,13 +836,14 @@ ui_read_std_and_sky(struct segmentparams *p)
           /* Read the Sky dataset. */
           sky=gal_array_read_one_ch_to_type(p->skyname, p->skyhdu,
                                             NULL, GAL_TYPE_FLOAT32,
-                                            p->cp.minmapsize, p->cp.quietmmap);
+                                            p->cp.minmapsize,
+                                            p->cp.quietmmap, "--skyhdu");
           sky->ndim=gal_dimension_remove_extra(sky->ndim, sky->dsize,
                                                NULL);
 
           /* Check its size. */
-          ui_check_size(p->input, sky, tl->tottiles, p->inputname, p->cp.hdu,
-                        p->skyname, p->skyhdu);
+          ui_check_size(p->input, sky, tl->tottiles, p->inputname,
+                        p->cp.hdu, p->skyname, p->skyhdu);
         }
 
       /* Subtract the sky from the input. */
diff --git a/bin/statistics/sky.c b/bin/statistics/sky.c
index b6f83e5d..992c6ac2 100644
--- a/bin/statistics/sky.c
+++ b/bin/statistics/sky.c
@@ -290,7 +290,7 @@ sky(struct statisticsparams *p)
   gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1,
                               p->cp.quiet);
   gal_fits_key_write_config(&p->cp.okeys, "Statistics configuration",
-                            "STATISTICS-CONFIG", outname, "0");
+                            "STATISTICS-CONFIG", outname, "0", "NONE");
   if(!cp->quiet)
     printf("  - Sky and its STD written to '%s'.\n", outname);
 
diff --git a/bin/statistics/statistics.c b/bin/statistics/statistics.c
index e4e3e5ec..27f4454d 100644
--- a/bin/statistics/statistics.c
+++ b/bin/statistics/statistics.c
@@ -308,7 +308,7 @@ statistics_interpolate_and_write(struct statisticsparams *p,
   gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1,
                               p->cp.quiet);
   gal_fits_key_write_config(&p->cp.okeys, "Statistics configuration",
-                            "STATISTICS-CONFIG", output, "0");
+                            "STATISTICS-CONFIG", output, "0", "NONE");
 }
 
 
@@ -688,7 +688,7 @@ write_output_table(struct statisticsparams *p, gal_data_t 
*table,
       gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1,
                                   p->cp.quiet);
       gal_fits_key_write_config(&p->cp.okeys, "Statistics configuration",
-                                "STATISTICS-CONFIG", output, "0");
+                                "STATISTICS-CONFIG", output, "0", "NONE");
     }
 
 
@@ -863,7 +863,7 @@ histogram_2d(struct statisticsparams *p)
       gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys, 1,
                                   p->cp.quiet);
       gal_fits_key_write_config(&p->cp.okeys, "Statistics configuration",
-                                "STATISTICS-CONFIG", output, "0");
+                                "STATISTICS-CONFIG", output, "0", "NONE");
 
       /* Clean up and let the user know that the histogram is built. */
       free(ctype[0]);
diff --git a/bin/statistics/ui.c b/bin/statistics/ui.c
index d2b618b1..efd6d815 100644
--- a/bin/statistics/ui.c
+++ b/bin/statistics/ui.c
@@ -623,7 +623,8 @@ ui_check_options_and_arguments(struct statisticsparams *p)
 
           /* If its an image, make sure column isn't given (in case the
              user confuses an image with a table). */
-          p->hdu_type=gal_fits_hdu_format(p->inputname, p->cp.hdu);
+          p->hdu_type=gal_fits_hdu_format(p->inputname, p->cp.hdu,
+                                          "--hdu");
           if(p->hdu_type==IMAGE_HDU && p->columns)
             error(EXIT_FAILURE, 0, "%s (hdu: %s): is a FITS image "
                   "extension. The '--column' option is only applicable "
@@ -910,7 +911,7 @@ ui_read_columns(struct statisticsparams *p)
     {
       /* Get the basic table information. */
       cinfo=gal_table_info(p->inputname, p->cp.hdu, lines, &ncols, &nrows,
-                           &tformat);
+                           &tformat, "NONE");
       gal_data_array_free(cinfo, ncols, 1);
 
       /* See how many columns it has and take the proper action. */
@@ -946,7 +947,7 @@ ui_read_columns(struct statisticsparams *p)
   /* Read the desired column(s). */
   cols=gal_table_read(p->inputname, p->cp.hdu, lines, p->columns,
                       p->cp.searchin, p->cp.ignorecase, p->cp.numthreads,
-                      p->cp.minmapsize, p->cp.quietmmap, NULL);
+                      p->cp.minmapsize, p->cp.quietmmap, NULL, "--hdu");
   gal_list_str_free(lines, 1);
   p->input=cols;
 
@@ -1037,7 +1038,7 @@ ui_preparations_fitestimate(struct statisticsparams *p)
                                   NULL, fecols,
                                   p->cp.searchin, p->cp.ignorecase, 1,
                                   p->cp.minmapsize, p->cp.quietmmap,
-                                  NULL);
+                                  NULL, "--fitestimatehdu");
 
       /* If more than one column matched, inform the user. */
       if(p->fitestval->next)
@@ -1136,10 +1137,11 @@ ui_preparations(struct statisticsparams *p)
     {
       p->inputformat=INPUT_FORMAT_IMAGE;
       p->input=gal_array_read_one_ch(p->inputname, cp->hdu, NULL,
-                                     cp->minmapsize, p->cp.quietmmap);
+                                     cp->minmapsize, p->cp.quietmmap,
+                                     "--hdu");
       p->input->wcs=gal_wcs_read(p->inputname, cp->hdu,
                                  p->cp.wcslinearmatrix, 0, 0,
-                                 &p->input->nwcs);
+                                 &p->input->nwcs, "--hdu");
       p->input->ndim=gal_dimension_remove_extra(p->input->ndim,
                                                 p->input->dsize,
                                                 p->input->wcs);
@@ -1160,7 +1162,8 @@ ui_preparations(struct statisticsparams *p)
   if(p->sky && p->kernelname)
     {
       p->kernel=gal_fits_img_read_kernel(p->kernelname, p->khdu,
-                                         cp->minmapsize, p->cp.quietmmap);
+                                         cp->minmapsize, p->cp.quietmmap,
+                                         "--khdu");
       p->kernel->ndim=gal_dimension_remove_extra(p->kernel->ndim,
                                                  p->kernel->dsize, NULL);
     }
diff --git a/bin/table/arithmetic.c b/bin/table/arithmetic.c
index edb323c0..4ccc5f1f 100644
--- a/bin/table/arithmetic.c
+++ b/bin/table/arithmetic.c
@@ -169,7 +169,7 @@ arithmetic_init_wcs(struct tableparams *p, char *operator)
 
       /* Read the WCS. */
       p->wcs=gal_wcs_read(p->wcsfile, p->wcshdu, p->cp.wcslinearmatrix,
-                          0, 0, &p->nwcs);
+                          0, 0, &p->nwcs, "--wcshdu");
       if(p->wcs==NULL)
         error(EXIT_FAILURE, 0, "%s (hdu: %s): no WCS could be read by "
               "WCSLIB", p->wcsfile, p->wcshdu);
diff --git a/bin/table/table.c b/bin/table/table.c
index 30011aa1..8133420f 100644
--- a/bin/table/table.c
+++ b/bin/table/table.c
@@ -878,7 +878,7 @@ table_catcolumn(struct tableparams *p)
       tocat=gal_table_read(filell->v, hdu, NULL, p->catcolumns,
                            cp->searchin, cp->ignorecase,
                            cp->numthreads, cp->minmapsize,
-                           p->cp.quietmmap, NULL);
+                           p->cp.quietmmap, NULL, "--catcolumnhdu");
 
       /* Check the number of rows. */
       if(tocat->dsize[0]!=p->table->dsize[0])
@@ -1135,7 +1135,7 @@ table_catrows_prepare(struct tableparams *p)
     {
       hdu=table_catrows_findhdu(filell->v, &hdull);
       gal_table_info(filell->v, hdu, NULL, &numcols, &numrows,
-                     &tableformat);
+                     &tableformat, "--catrowhdu");
       nrows+=numrows;
     }
 
@@ -1216,7 +1216,7 @@ table_catrows(struct tableparams *p)
       new=gal_table_read(filell->v, hdu, NULL, p->columns,
                          p->cp.searchin, p->cp.ignorecase,
                          p->cp.numthreads, p->cp.minmapsize,
-                         p->cp.quietmmap, NULL);
+                         p->cp.quietmmap, NULL, "--catrowhdu");
 
       /* Make sure that the same number of columns were extracted from this
          table as they were from the original table. */
diff --git a/bin/table/ui.c b/bin/table/ui.c
index 2a2b9ef6..0dd58062 100644
--- a/bin/table/ui.c
+++ b/bin/table/ui.c
@@ -619,7 +619,7 @@ ui_print_info_exit(struct tableparams *p)
   /* Read the table information for the number of columns and rows. */
   lines=gal_options_check_stdin(p->filename, p->cp.stdintimeout, "input");
   allcols=gal_table_info(p->filename, p->cp.hdu, lines, &numcols,
-                         &numrows, &tableformat);
+                         &numrows, &tableformat, "--hdu");
   if(p->filename==NULL) p->filename="Standard-input";
   gal_list_str_free(lines, 1);
 
@@ -719,7 +719,8 @@ ui_columns_prepare(struct tableparams *p, gal_list_str_t 
*lines)
              information. */
           if(colinfo==NULL)
             colinfo=gal_table_info(p->filename, p->cp.hdu, lines,
-                                   &numcols, &numrows, &tableformat);
+                                   &numcols, &numrows, &tableformat,
+                                   "--hdu");
 
           /* Check if '$_all' is in the string. */
           for(c=str; *c!='\0'; ++c)
@@ -772,7 +773,7 @@ ui_columns_prepare(struct tableparams *p, gal_list_str_t 
*lines)
               if(colinfo==NULL)
                 colinfo=gal_table_info(p->filename, p->cp.hdu, lines,
                                        &numcols, &numrows,
-                                       &tableformat);
+                                       &tableformat, "--hdu");
 
               /* Add all the input column counters to the list of columns
                  to read */
@@ -987,7 +988,7 @@ ui_check_select_sort_before(struct tableparams *p, 
gal_list_str_t *lines,
 
   /* Get all the input table's column information. */
   allcols=gal_table_info(p->filename, p->cp.hdu, lines, &numcols,
-                         &numrows, &tableformat);
+                         &numrows, &tableformat, "--hdu");
 
 
   /* If '--noblank' is given an '_all', we should replace it with the
@@ -1327,7 +1328,8 @@ ui_preparations(struct tableparams *p)
   /* Read the necessary columns. */
   p->table=gal_table_read(p->filename, cp->hdu, lines, p->columns,
                           cp->searchin, cp->ignorecase, cp->numthreads,
-                          cp->minmapsize, p->cp.quietmmap, p->colmatch);
+                          cp->minmapsize, p->cp.quietmmap, p->colmatch,
+                          "--hdu");
   if(p->filename==NULL) p->filename="stdin";
   gal_list_str_free(lines, 1);
 
diff --git a/bin/warp/ui.c b/bin/warp/ui.c
index 21665a3b..69af5f7e 100644
--- a/bin/warp/ui.c
+++ b/bin/warp/ui.c
@@ -343,13 +343,15 @@ ui_check_gridfile(struct warpparams *p)
 
   /* Read the WCS and save to a standard PC convention WCS struct. */
   wa->twcs=gal_wcs_read(p->gridfile, p->gridhdu,
-                        GAL_WCS_LINEAR_MATRIX_PC, 0, 0, &nwcs);
+                        GAL_WCS_LINEAR_MATRIX_PC, 0, 0, &nwcs,
+                        "--gridhdu");
   if(wa->twcs==NULL)
     error(EXIT_FAILURE, 0, "%s (hdu %s): no readable WCS structure",
           p->gridfile, p->gridhdu);
 
   /* Correct the WCS dimensions if necessary. */
-  dsize=gal_fits_img_info_dim(p->gridfile, p->gridhdu, &ndim);
+  dsize=gal_fits_img_info_dim(p->gridfile, p->gridhdu, &ndim,
+                              "--gridhdu");
   ndim=gal_dimension_remove_extra(ndim, dsize, wa->twcs);
   if(ndim!=2)
     error(EXIT_FAILURE, 0, "%s (hdu %s): the target WCS must "
@@ -612,7 +614,7 @@ ui_check_options_and_arguments_wcsalign(struct warpparams 
*p)
       /* Get sky coverage information about the input image. Note that
          this allocates the pointers that have to be freed later. */
       if( gal_wcs_coverage(p->inputname, p->cp.hdu, &indim, &icenter,
-                           &iwidth, &imin, &imax)==0 )
+                           &iwidth, &imin, &imax, "--hdu")==0 )
         error(EXIT_FAILURE, 0, "%s (hdu %s): is not usable for finding "
               "sky coverage", p->inputname, p->cp.hdu);
 
@@ -676,12 +678,12 @@ ui_check_options_and_arguments(struct warpparams *p)
   p->input=gal_array_read_one_ch_to_type(p->inputname, p->cp.hdu,
                                          NULL, GAL_TYPE_FLOAT64,
                                          p->cp.minmapsize,
-                                         p->cp.quietmmap);
+                                         p->cp.quietmmap, "--hdu");
 
   /* Read the WCS and remove one-element wide dimension(s). */
   p->input->wcs=gal_wcs_read(p->inputname, p->cp.hdu,
                              p->cp.wcslinearmatrix, p->hstartwcs,
-                             p->hendwcs, &p->input->nwcs);
+                             p->hendwcs, &p->input->nwcs, "--hdu");
   p->input->ndim=gal_dimension_remove_extra(p->input->ndim,
                                             p->input->dsize,
                                             p->input->wcs);
diff --git a/bin/warp/warp.c b/bin/warp/warp.c
index 2f0d6688..d8cad9a5 100644
--- a/bin/warp/warp.c
+++ b/bin/warp/warp.c
@@ -430,10 +430,10 @@ warp_write_to_file(struct warpparams *p, int hasmatrix)
   gal_fits_key_write_filename("input", p->inputname, &p->cp.okeys,
                               1, p->cp.quiet);
   gal_fits_key_write_config(&p->cp.okeys, "Warp configuration",
-                            "WARP-CONFIG", p->cp.output, "0");
+                            "WARP-CONFIG", p->cp.output, "0", "NONE");
 
   /* Write headers on HDU/extension '1'. */
-  gal_fits_key_write(&headers, NULL, p->cp.output, "1");
+  gal_fits_key_write(&headers, NULL, p->cp.output, "1", "NONE");
 }
 
 
diff --git a/doc/announce-acknowledge.txt b/doc/announce-acknowledge.txt
index 34b0736a..9d7a6bdd 100644
--- a/doc/announce-acknowledge.txt
+++ b/doc/announce-acknowledge.txt
@@ -1,5 +1,6 @@
 Alphabetically ordered list to acknowledge in the next release.
 
+Aaron Watkins
 Agata Rożek
 Irene Pintos Castro
 Rashid Yaaqib
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 9793cbe5..0fe795b6 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -36306,7 +36306,7 @@ Similar to @code{gal_array_name_recognized}, but for 
FITS files, it will also ch
 See the description of @code{gal_fits_file_recognized} for more (@ref{FITS 
macros errors filenames}).
 @end deftypefun
 
-@deftypefun gal_data_t gal_array_read (char @code{*filename}, char 
@code{*extension}, gal_list_str_t @code{*lines}, size_t @code{minmapsize}, int 
@code{quietmmap})
+@deftypefun gal_data_t gal_array_read (char @code{*filename}, char 
@code{*extension}, gal_list_str_t @code{*lines}, size_t @code{minmapsize}, int 
@code{quietmmap}, char @code{*ext_option_name})
 Read the array within the given extension (@code{extension}) of 
@code{filename}, or the @code{lines} list (see below).
 If the array is larger than @code{minmapsize} bytes, then it will not be read 
into RAM, but a file on the HDD/SSD (no difference for the programmer).
 Messages about the memory-mapped file can be disabled with @code{quietmmap}.
@@ -36321,14 +36321,18 @@ Thus if you just want a single array (and want to 
check if the user has not give
 @code{lines} is a list of strings with each node representing one line 
(including the new-line character), see @ref{List of strings}.
 It will mostly be the output of @code{gal_txt_stdin_read}, which is used to 
read the program's input as separate lines from the standard input (see 
@ref{Text files}).
 Note that @code{filename} and @code{lines} are mutually exclusive and one of 
them must be @code{NULL}.
+
+@code{ext_option_name} is used in error messages related to the extensions 
(e.g., HDUs in FITS) and is expected to the command-line option name that users 
to your program can specify the HDU for this particular input.
+For example if the given @code{extension} doesn't exist in @file{filename}, a 
descriptive error message is printed which instructs the users how to find and 
fix the problem.
+In that error message it also suggests the option to use to help the users of 
your program.
 @end deftypefun
 
-@deftypefun void gal_array_read_to_type (char @code{*filename}, char 
@code{*extension}, gal_list_str_t @code{*lines}, uint8_t @code{type}, size_t 
@code{minmapsize}, int @code{quietmmap})
+@deftypefun void gal_array_read_to_type (char @code{*filename}, char 
@code{*extension}, gal_list_str_t @code{*lines}, uint8_t @code{type}, size_t 
@code{minmapsize}, int @code{quietmmap}, char @code{*ext_option_name})
 Similar to @code{gal_array_read}, but the output data structure(s) will
 have a numeric data type of @code{type}, see @ref{Numeric data types}.
 @end deftypefun
 
-@deftypefun void gal_array_read_one_ch (char @code{*filename}, char 
@code{*extension}, gal_list_str_t @code{*lines}, size_t @code{minmapsize}, int 
@code{quietmmap})
+@deftypefun void gal_array_read_one_ch (char @code{*filename}, char 
@code{*extension}, gal_list_str_t @code{*lines}, size_t @code{minmapsize}, int 
@code{quietmmap}, char @code{*ext_option_name})
 @cindex Channel
 @cindex Color channel
 Read the dataset within @code{filename} (extension/hdu/dir @code{extension}) 
and make sure it is only a single channel.
@@ -36336,9 +36340,11 @@ This is just a simple wrapper around 
@code{gal_array_read} that checks if there
 
 Formats like JPEG or TIFF support multiple channels per input, but it may 
happen that your program only works on a single dataset.
 This function can be a convenient way to make sure that the data that comes 
into your program is only one channel.
+
+Regarding @code{*ext_option_name}, see the description for the same argument 
in the description of @code{gal_array_read}.
 @end deftypefun
 
-@deftypefun void gal_array_read_one_ch_to_type (char @code{*filename}, char 
@code{*extension}, gal_list_str_t @code{*lines}, uint8_t @code{type}, size_t 
@code{minmapsize}, int @code{quietmmap})
+@deftypefun void gal_array_read_one_ch_to_type (char @code{*filename}, char 
@code{*extension}, gal_list_str_t @code{*lines}, uint8_t @code{type}, size_t 
@code{minmapsize}, int @code{quietmmap}, char @code{*ext_option_name})
 Similar to @code{gal_array_read_one_ch}, but the output data structure will
 has a numeric data type of @code{type}, see @ref{Numeric data types}.
 @end deftypefun
@@ -36465,7 +36471,7 @@ This function is just for column information 
(meta-data), not column contents.
 @end example
 @end deftypefun
 
-@deftypefun void gal_table_print_info (gal_data_t @code{*allcols}, size_t 
@code{numcols}, size_t @code{numrows})
+@deftypefun void gal_table_print_info (gal_data_t @code{*allcols}, size_t 
@code{numcols}, size_t @code{numrows}, char @code{*hdu_option_name})
 Print the column information for all the columns (output of 
@code{gal_table_info}) to standard output.
 The output is in the same format as this command with Gnuastro Table program 
(see @ref{Invoking asttable}):
 @example
@@ -36473,10 +36479,11 @@ $ asttable --info table.fits
 @end example
 @end deftypefun
 
-@deftypefun {gal_data_t *} gal_table_read (char @code{*filename}, char 
@code{*hdu}, gal_list_str_t @code{*lines}, gal_list_str_t @code{*cols}, int 
@code{searchin}, int @code{ignorecase}, size_t @code{numthreads}, size_t 
@code{minmapsize}, int @code{quietmmap}, size_t @code{*colmatch})
+@deftypefun {gal_data_t *} gal_table_read (char @code{*filename}, char 
@code{*hdu}, gal_list_str_t @code{*lines}, gal_list_str_t @code{*cols}, int 
@code{searchin}, int @code{ignorecase}, size_t @code{numthreads}, size_t 
@code{minmapsize}, int @code{quietmmap}, size_t @code{*colmatch}, char 
@code{*hdu_option_name})
 
 Read the specified columns in a file (named @code{filename}), or list of 
strings (@code{lines}) into a linked list of data structures.
 If the file is FITS, then @code{hdu} will also be used, otherwise, @code{hdu} 
is ignored.
+For more on @code{hdu_option_name} see the description of 
@code{gal_fits_hdu_open} in @ref{FITS HDUs}.
 
 @code{lines} is a list of strings with each node representing one line 
(including the new-line character), see @ref{List of strings}.
 It will mostly be the output of @code{gal_txt_stdin_read}, which is used to 
read the program's input as separate lines from the standard input (see 
@ref{Text files}).
@@ -36696,10 +36703,12 @@ If @file{filename} does not exist, the file will be 
created which contains a bla
 Return the number of HDUs/extensions in @file{filename}.
 @end deftypefun
 
-@deftypefun {unsigned long} gal_fits_hdu_datasum (char @code{*filename}, char 
@code{*hdu})
+@deftypefun {unsigned long} gal_fits_hdu_datasum (char @code{*filename}, char 
@code{*hdu}, char @code{*hdu_option_name})
 @cindex @code{DATASUM}: FITS keyword
 Return the @code{DATASUM} of the given HDU in the given FITS file.
 For more on @code{DATASUM} in the FITS standard, see @ref{Keyword inspection 
and manipulation} (under the @code{checksum} component of @option{--write}).
+For more on @code{hdu_option_name} see the description of 
@code{gal_fits_hdu_open}.
+
 @end deftypefun
 
 @deftypefun {unsigned long} gal_fits_hdu_datasum_ptr (fitsfile @code{*fptr})
@@ -36708,9 +36717,10 @@ Return the @code{DATASUM} of the already opened HDU in 
@code{fptr}.
 For more on @code{DATASUM} in the FITS standard, see @ref{Keyword inspection 
and manipulation} (under the @code{checksum} component of @option{--write}).
 @end deftypefun
 
-@deftypefun int gal_fits_hdu_format (char @code{*filename}, char @code{*hdu})
+@deftypefun int gal_fits_hdu_format (char @code{*filename}, char @code{*hdu}, 
char @code{*hdu_option_name})
 Return the format of the HDU as one of CFITSIO's recognized macros:
 @code{IMAGE_HDU}, @code{ASCII_TBL}, or @code{BINARY_TBL}.
+For more on @code{hdu_option_name} see the description of 
@code{gal_fits_hdu_open}.
 @end deftypefun
 
 @deftypefun int gal_fits_hdu_is_healpix (fitsfile @code{*fptr})
@@ -36719,7 +36729,7 @@ Return @code{1} if the dataset may be a HEALpix grid 
and @code{0} otherwise.
 Technically, it is considered to be a HEALPix if the HDU is not an ASCII 
table, and has the @code{NSIDE}, @code{FIRSTPIX} and @code{LASTPIX}.
 @end deftypefun
 
-@deftypefun {fitsfile *} gal_fits_hdu_open (char @code{*filename}, char 
@code{*hdu}, int @code{iomode}, int @code{exitonerror})
+@deftypefun {fitsfile *} gal_fits_hdu_open (char @code{*filename}, char 
@code{*hdu}, int @code{iomode}, int @code{exitonerror}, char 
@code{*hdu_option_name})
 Open the HDU/extension @code{hdu} from @file{filename} and return a pointer to 
CFITSIO's @code{fitsfile}.
 @code{iomode} determines how the FITS file will be opened using CFITSIO's 
macros: @code{READONLY} or @code{READWRITE}.
 
@@ -36729,12 +36739,18 @@ See the description under @option{--hdu} in 
@ref{Input output options} for more.
 
 If @code{exitonerror!=0} and the given HDU cannot be opened for any reason, 
the function will exit the program, and print an informative message.
 Otherwise, when the HDU cannot be opened, it will just return a NULL pointer.
+
+@code{hdu_option_name} is used in error messages related to the given HDU 
name/identifier.
+It is expected to the command-line option name that users to your program can 
specify the HDU for this particular input.
+For example if the given @code{hdu} doesn't exist in @file{filename}, a 
descriptive error message is printed which instructs the users how to find and 
fix the problem.
+The text in that error message, also suggests the option to use to fix the 
problem (hence the purpose of this argument).
 @end deftypefun
 
-@deftypefun {fitsfile *} gal_fits_hdu_open_format (char @code{*filename}, char 
@code{*hdu}, int @code{img0_tab1})
+@deftypefun {fitsfile *} gal_fits_hdu_open_format (char @code{*filename}, char 
@code{*hdu}, int @code{img0_tab1}, char @code{*hdu_option_name})
 Open (in read-only format) the @code{hdu} HDU/extension of @file{filename} as 
an image or table.
 When @code{img0_tab1} is @code{0}(zero) but the HDU is a table, this function 
will abort with an error.
 It will also abort with an error when @code{img0_tab1} is @code{1} (one), but 
the HDU is an image.
+For more on @code{hdu_option_name} see the description of 
@code{gal_fits_hdu_open}.
 
 A FITS HDU may contain both tables or images.
 When your program needs one of these formats, you can call this function so if 
the user provided the wrong HDU/file, it will abort and inform the user that 
the file/HDU is has the wrong format.
@@ -37036,20 +37052,23 @@ Since the data processing depends on the versions of 
the libraries you have used
 @code{gal_fits_img_write} and @code{gal_fits_tab_write} will automatically use 
this function.
 @end deftypefun
 
-@deftypefun void gal_fits_key_write_config (gal_fits_list_key_t 
@code{**keylist}, char @code{*title}, char @code{*extname}, char 
@code{*filename}, char @code{*hdu})
+@deftypefun void gal_fits_key_write_config (gal_fits_list_key_t 
@code{**keylist}, char @code{*title}, char @code{*extname}, char 
@code{*filename}, char @code{*hdu}, char @code{*hdu_option_name})
 Write the given keyword list (@code{keylist}) into the @code{hdu} extension of 
@code{filename}, ending it with version information.
 This function will write @code{extname} as the name of the extension (value to 
the standard @code{EXTNAME} FITS keyword).
 The list of keywords will then be printed under a title called @code{title}.
 
 This function is used by many Gnuastro programs and is primarily intended for 
writing configuration settings of a program into the zero-th extension of their 
FITS outputs (which is empty when the FITS file is created by Gnuastro's 
program and this library).
+
+For more on @code{hdu_option_name} see the description of 
@code{gal_fits_hdu_open} in @ref{FITS HDUs}.
 @end deftypefun
 
 @deftypefun {gal_list_str_t *} gal_fits_with_keyvalue (gal_list_str_t *files, 
char *hdu, char *name, gal_list_str_t *values)
 Given a list of FITS file names (@code{files}), a certain HDU (@code{hdu}), a 
certain keyword name (@code{name}), and a list of acceptable values 
(@code{values}), return the subset of file names where the requested keyword 
name has one of the acceptable values.
 @end deftypefun
 
-@deftypefun {gal_list_str_t *} gal_fits_unique_keyvalues (gal_list_str_t 
*files, char *hdu, char *name)
+@deftypefun {gal_list_str_t *} gal_fits_unique_keyvalues (gal_list_str_t 
@code{*files}, char @code{*hdu}, char @code{*name}, char 
@code{*hdu_option_name})
 Given a list of FITS file names (@code{files}), a certain HDU (@code{hdu}), a 
certain keyword name (@code{name}), return the list of unique values to that 
keyword name in all the files.
+For more on @code{hdu_option_name} see the description of 
@code{gal_fits_hdu_open} in @ref{FITS HDUs}.
 @end deftypefun
 
 
@@ -37068,16 +37087,18 @@ Read the type (see @ref{Library data types}), number 
of dimensions, and size alo
 If @code{name} and @code{unit} are not @code{NULL} (point to a @code{char *}), 
then if the image has a name and units, the respective string will be put in 
these pointers.
 @end deftypefun
 
-@deftypefun {size_t *} gal_fits_img_info_dim (char @code{*filename}, char 
@code{*hdu}, size_t @code{*ndim})
+@deftypefun {size_t *} gal_fits_img_info_dim (char @code{*filename}, char 
@code{*hdu}, size_t @code{*ndim}, char @code{*hdu_option_name})
 Put the number of dimensions in the @code{hdu} extension of @file{filename}
 in the space that @code{ndim} points to and return the size of the dataset
 along each dimension as an allocated array with @code{*ndim} elements.
+For more on @code{hdu_option_name} see the description of 
@code{gal_fits_hdu_open} in @ref{FITS HDUs}.
 @end deftypefun
 
 @deftypefun {gal_data_t *} gal_fits_img_read (char @code{*filename}, char 
@code{*hdu}, size_t @code{minmapsize}, int @code{quietmmap})
 Read the contents of the @code{hdu} extension/HDU of @code{filename} into a 
Gnuastro generic data container (see @ref{Generic data container}) and return 
it.
 If the necessary space is larger than @code{minmapsize}, then do not keep the 
data in RAM, but in a file on the HDD/SSD.
 For more on @code{minmapsize} and @code{quietmmap} see the description under 
the same name in @ref{Generic data container}.
+For more on @code{hdu_option_name} see the description of 
@code{gal_fits_hdu_open} in @ref{FITS HDUs}.
 
 Note that this function only reads the main data within the requested FITS 
extension, the WCS will not be read into the returned dataset.
 To read the WCS, you can use @code{gal_wcs_read} function as shown below.
@@ -37088,7 +37109,7 @@ data->wcs=gal_wcs_read(filename, hdu, 0, 0, 0, 
&data->wcs->nwcs);
 @end example
 @end deftypefun
 
-@deftypefun {gal_data_t *} gal_fits_img_read_to_type (char @code{*inputname}, 
char @code{*inhdu}, uint8_t @code{type}, size_t @code{minmapsize}, int 
@code{quietmmap})
+@deftypefun {gal_data_t *} gal_fits_img_read_to_type (char @code{*inputname}, 
char @code{*inhdu}, uint8_t @code{type}, size_t @code{minmapsize}, int 
@code{quietmmap}, char @code{*hdu_option_name})
 Read the contents of the @code{hdu} extension/HDU of @code{filename} into a 
Gnuastro generic data container (see @ref{Generic data container}) of type 
@code{type} and return it.
 
 This is just a wrapper around @code{gal_fits_img_read} (to read the 
image/array of any type) and @code{gal_data_copy_to_new_type_free} (to convert 
it to @code{type} and free the initially read dataset).
@@ -37098,12 +37119,14 @@ See the description there for more.
 @cindex NaN
 @cindex Convolution kernel
 @cindex Kernel, convolution
-@deftypefun {gal_data_t *} gal_fits_img_read_kernel (char @code{*filename}, 
char @code{*hdu}, size_t @code{minmapsize}, int @code{quietmmap})
+@deftypefun {gal_data_t *} gal_fits_img_read_kernel (char @code{*filename}, 
char @code{*hdu}, size_t @code{minmapsize}, int @code{quietmmap}, char 
@code{*hdu_option_name})
 Read the @code{hdu} of @code{filename} as a convolution kernel.
 A convolution kernel must have an odd size along all dimensions, it must not 
have blank (NaN in floating point types) values and must be flipped around the 
center to make the proper convolution (see @ref{Convolution process}).
 If there are blank values, this function will change the blank values to 
@code{0.0}.
 If the input image does not have the other two requirements, this function 
will abort with an error describing the condition to the user.
 The finally returned dataset will have a @code{float32} type.
+
+For more on @code{hdu_option_name} see the description of 
@code{gal_fits_hdu_open} in @ref{FITS HDUs}.
 @end deftypefun
 
 @deftypefun {fitsfile *} gal_fits_img_write_to_ptr (gal_data_t @code{*input}, 
char @code{*filename})
@@ -37161,10 +37184,11 @@ This function will return 
@code{GAL_TABLE_FORMAT_AFITS} or @code{GAL_TABLE_FORMA
 If the @code{fitsptr} is not a table, this function will abort the program 
with an error message informing the user of the problem.
 @end deftypefun
 
-@deftypefun {gal_data_t *} gal_fits_tab_info (char @code{*filename}, char 
@code{*hdu}, size_t @code{*numcols}, size_t @code{*numrows}, int 
@code{*tableformat})
+@deftypefun {gal_data_t *} gal_fits_tab_info (char @code{*filename}, char 
@code{*hdu}, size_t @code{*numcols}, size_t @code{*numrows}, int 
@code{*tableformat}, char @code{*hdu_option_name})
 Store the information of each column in @code{hdu} of @code{filename} into an 
array of data structures with @code{numcols} elements (one data structure for 
each column) see @ref{Arrays of datasets}.
 The total number of rows in the table is also put into the memory that 
@code{numrows} points to.
 The format of the table (e.g., FITS binary or ASCII table) will be put in 
@code{tableformat} (macros defined in @ref{Table input output}).
+For more on @code{hdu_option_name} see the description of 
@code{gal_fits_hdu_open} in @ref{FITS HDUs}.
 
 This function is just for column information.
 Therefore it only stores meta-data like column name, units and comments.
@@ -37173,8 +37197,9 @@ This is a low-level function particular to reading 
tables in FITS format.
 To be generic, it is recommended to use @code{gal_table_info} which will allow 
getting information from a variety of table formats based on the filename (see 
@ref{Table input output}).
 @end deftypefun
 
-@deftypefun {gal_data_t *} gal_fits_tab_read (char @code{*filename}, char 
@code{*hdu}, size_t @code{numrows}, gal_data_t @code{*colinfo}, 
gal_list_sizet_t @code{*indexll}, size_t @code{numthreads}, size_t 
@code{minmapsize}, int @code{quietmmap})
+@deftypefun {gal_data_t *} gal_fits_tab_read (char @code{*filename}, char 
@code{*hdu}, size_t @code{numrows}, gal_data_t @code{*colinfo}, 
gal_list_sizet_t @code{*indexll}, size_t @code{numthreads}, size_t 
@code{minmapsize}, int @code{quietmmap}, char @code{*hdu_option_name})
 Read the columns given in the list @code{indexll} from a FITS table (in 
@file{filename} and HDU/extension @code{hdu}) into the returned linked list of 
data structures, see @ref{List of size_t} and @ref{List of gal_data_t}.
+For more on @code{hdu_option_name} see the description of 
@code{gal_fits_hdu_open} in @ref{FITS HDUs}.
 
 Each column will be read independently, therefore they will be read in 
@code{numthreads} CPU threads to greatly speed up the reading when there are 
many columns and rows.
 However, this only happens if CFITSIO was configured with 
@option{--enable-reentrant}.
@@ -37735,10 +37760,11 @@ This function is just a wrapper over WCSLIB's 
@code{wcspih} function which is no
 Therefore, be sure to not call this function simultaneously (over multiple 
threads).
 @end deftypefun
 
-@deftypefun {struct wcsprm *} gal_wcs_read (char @code{*filename}, char 
@code{*hdu}, int @code{linearmatrix}, size_t @code{hstartwcs}, size_t 
@code{hendwcs}, int @code{*nwcs})
+@deftypefun {struct wcsprm *} gal_wcs_read (char @code{*filename}, char 
@code{*hdu}, int @code{linearmatrix}, size_t @code{hstartwcs}, size_t 
@code{hendwcs}, int @code{*nwcs}, char @code{*hdu_option_name})
 [@strong{Not thread-safe}] Return the WCSLIB structure that is read from the 
HDU/extension @code{hdu} of the file @code{filename}.
 Also put the number of coordinate representations found into the space that 
@code{nwcs} points to.
 Please see @code{gal_wcs_read_fitsptr} for more.
+For more on @code{hdu_option_name} see the description of 
@code{gal_fits_hdu_open} in @ref{FITS HDUs}.
 
 After processing has finished, you should free the WCS structure that this 
function returns with @code{gal_wcs_free}.
 @end deftypefun
@@ -37939,10 +37965,11 @@ This only works when the input dataset has at least 
two dimensions and the units
 In other cases, this function will return a NaN.
 @end deftypefun
 
-@deftypefun int gal_wcs_coverage (char @code{*filename}, char @code{*hdu}, 
size_t @code{*ondim}, double @code{**ocenter}, double @code{**owidth}, double 
@code{**omin}, double @code{**omax})
+@deftypefun int gal_wcs_coverage (char @code{*filename}, char @code{*hdu}, 
size_t @code{*ondim}, double @code{**ocenter}, double @code{**owidth}, double 
@code{**omin}, double @code{**omax}, char @code{*hdu_option_name})
 Find the sky coverage of the image HDU (@code{hdu}) within @file{filename}.
 The number of dimensions is written into @code{ndim}, and space for the 
various output arrays is internally allocated and filled with the respective 
values.
 Therefore you need to free them afterwards.
+For more on @code{hdu_option_name} see the description of 
@code{gal_fits_hdu_open} in @ref{FITS HDUs}.
 
 Currently this function only supports images that are less than 180 degrees in 
width (which is usually the case!).
 This requirement has been necessary to account for images that cross the RA=0 
hour circle on the sky.
diff --git a/lib/arithmetic.c b/lib/arithmetic.c
index d2645f2e..586b8e1d 100644
--- a/lib/arithmetic.c
+++ b/lib/arithmetic.c
@@ -3140,7 +3140,8 @@ gal_arithmetic_load_col(char *str, int searchin, int 
ignorecase,
 
   /* Read the column from the table. */
   out=gal_table_read(filename, hdu, NULL, colid, searchin, ignorecase,
-                     numthreads, minmapsize, quietmmap, NULL);
+                     numthreads, minmapsize, quietmmap, NULL,
+                     "WITHIN-LOAD-COL");
 
   /* Make sure that only a single column matched. */
   if(out->next)
diff --git a/lib/array.c b/lib/array.c
index 9819497d..62b08462 100644
--- a/lib/array.c
+++ b/lib/array.c
@@ -100,13 +100,14 @@ gal_array_file_recognized(char *name)
    extension/dir of the given file. */
 gal_data_t *
 gal_array_read(char *filename, char *extension, gal_list_str_t *lines,
-               size_t minmapsize, int quietmmap)
+               size_t minmapsize, int quietmmap, char *ext_option_name)
 {
   size_t ext;
 
   /* FITS  */
   if( gal_fits_file_recognized(filename) )
-    return gal_fits_img_read(filename, extension, minmapsize, quietmmap);
+    return gal_fits_img_read(filename, extension, minmapsize, quietmmap,
+                             ext_option_name);
 
   /* TIFF */
   else if ( gal_tiff_name_is_tiff(filename) )
@@ -139,11 +140,13 @@ gal_array_read(char *filename, char *extension, 
gal_list_str_t *lines,
 gal_data_t *
 gal_array_read_to_type(char *filename, char *extension,
                        gal_list_str_t *lines, uint8_t type,
-                       size_t minmapsize, int quietmmap)
+                       size_t minmapsize, int quietmmap,
+                       char *ext_option_name)
 {
   gal_data_t *out=NULL;
   gal_data_t *next, *in=gal_array_read(filename, extension, lines,
-                                       minmapsize, quietmmap);
+                                       minmapsize, quietmmap,
+                                       ext_option_name);
 
   /* Go over all the channels. */
   while(in)
@@ -165,12 +168,14 @@ gal_array_read_to_type(char *filename, char *extension,
 
 /* Read the input array and make sure it is only one channel. */
 gal_data_t *
-gal_array_read_one_ch(char *filename, char *extension, gal_list_str_t *lines,
-                      size_t minmapsize, int quietmmap)
+gal_array_read_one_ch(char *filename, char *extension,
+                      gal_list_str_t *lines, size_t minmapsize,
+                      int quietmmap, char *ext_option_name)
 {
   char *fname;
   gal_data_t *out;
-  out=gal_array_read(filename, extension, lines, minmapsize, quietmmap);
+  out=gal_array_read(filename, extension, lines, minmapsize, quietmmap,
+                     ext_option_name);
 
   if(out->next)
     {
@@ -202,10 +207,12 @@ gal_array_read_one_ch(char *filename, char *extension, 
gal_list_str_t *lines,
 gal_data_t *
 gal_array_read_one_ch_to_type(char *filename, char *extension,
                               gal_list_str_t *lines, uint8_t type,
-                              size_t minmapsize, int quietmmap)
+                              size_t minmapsize, int quietmmap,
+                              char *ext_option_name)
 {
   gal_data_t *out=gal_array_read_one_ch(filename, extension, lines,
-                                        minmapsize, quietmmap);
+                                        minmapsize, quietmmap,
+                                        ext_option_name);
 
   return gal_data_copy_to_new_type_free(out, type);
 }
diff --git a/lib/fits.c b/lib/fits.c
index 53a38a2d..97708841 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -717,14 +717,15 @@ gal_fits_hdu_num(char *filename)
 
 /* Calculate the datasum of the given HDU in the given file. */
 unsigned long
-gal_fits_hdu_datasum(char *filename, char *hdu)
+gal_fits_hdu_datasum(char *filename, char *hdu, char *hdu_option_name)
 {
   int status=0;
   fitsfile *fptr;
   unsigned long datasum;
 
   /* Read the desired extension (necessary for reading the rest). */
-  fptr=gal_fits_hdu_open(filename, hdu, READONLY, 1);
+  fptr=gal_fits_hdu_open(filename, hdu, READONLY, 1,
+                         hdu_option_name);
 
   /* Calculate the datasum. */
   datasum=gal_fits_hdu_datasum_ptr(fptr);
@@ -766,13 +767,14 @@ gal_fits_hdu_datasum_ptr(fitsfile *fptr)
        ASCII_TBL:    An ASCII table HDU.
        BINARY_TBL:   BINARY TABLE HDU.       */
 int
-gal_fits_hdu_format(char *filename, char *hdu)
+gal_fits_hdu_format(char *filename, char *hdu, char *hdu_option_name)
 {
   fitsfile *fptr;
   int hdutype, status=0;
 
   /* Open the HDU. */
-  fptr=gal_fits_hdu_open(filename, hdu, READONLY, 1);
+  fptr=gal_fits_hdu_open(filename, hdu, READONLY, 1,
+                         hdu_option_name);
 
   /* Check the type of the given HDU: */
   if (fits_get_hdu_type(fptr, &hdutype, &status) )
@@ -819,11 +821,13 @@ gal_fits_hdu_is_healpix(fitsfile *fptr)
      READONLY:   read-only.
      READWRITE:  read and write.         */
 fitsfile *
-gal_fits_hdu_open(char *filename, char *hdu, int iomode, int exitonerror)
+gal_fits_hdu_open(char *filename, char *hdu, int iomode, int exitonerror,
+                  char *hdu_option_name)
 {
   int status=0;
   char *ffname;
   fitsfile *fptr;
+  char *hduon = hdu_option_name ? hdu_option_name : "--hdu";
 
   /* Add hdu to filename: */
   if( asprintf(&ffname, "%s[%s#]", filename, hdu)<0 )
@@ -846,19 +850,17 @@ gal_fits_hdu_open(char *filename, char *hdu, int iomode, 
int exitonerror)
             {
               if(exitonerror)
                 error(EXIT_FAILURE, 0, "%s: only has one HDU.\n\n"
-                      "You should tell Gnuastro's command-line "
-                      "programs to look for data in the primary HDU "
-                      "with the '--hdu=0' option (or '-h0'). For library "
-                      "users, you can put \"0\" (a string literal) for "
-                      "the function's HDU argument. For more, see the "
-                      "FOOTNOTE below.\n\n"
+                      "You should inform this program to look for your "
+                      "desired input data in the primary HDU with the "
+                      "'%s=0' option. For more, see the FOOTNOTE "
+                      "below.\n\n"
                       "Pro TIP: if your desired HDU has a name (value to "
                       "'EXTNAME' keyword), it is best to just use that "
-                      "name with '--hdu' instead of relying on a "
-                      "counter. You can see the list of HDUs in a FITS "
-                      "file (with their data format, type, size and "
-                      "possibly HDU name) using Gnuastro's 'astfits' "
-                      "program, for example:\n\n"
+                      "name with '%s' instead of relying on a counter. "
+                      "You can see the list of HDUs in a FITS file (with "
+                      "their data format, type, size and possibly HDU "
+                      "name) using Gnuastro's 'astfits' program, for "
+                      "example:\n\n"
                       "    astfits %s\n\n"
                       "FOOTNOTE -- When writing a new FITS file, "
                       "Gnuastro leaves the pimary HDU only for metadata. "
@@ -871,10 +873,11 @@ gal_fits_hdu_open(char *filename, char *hdu, int iomode, 
int exitonerror)
                       "contains the option names and values that the "
                       "program was run with. Because of this, Gnuastro's "
                       "default HDU to read data in a FITS file is the "
-                      "second (or '--hdu=1'). This error is commonly "
+                      "second (or '%s=1'). This error is commonly "
                       "caused when the FITS file wasn't created by "
                       "Gnuastro or by a program respecting this "
-                      "convention.", filename, filename);
+                      "convention.", filename, hduon, hduon, filename,
+                      hduon);
               else return NULL;
             }
           break;
@@ -887,22 +890,22 @@ gal_fits_hdu_open(char *filename, char *hdu, int iomode, 
int exitonerror)
            reporting that we have already prepared. */
         default:
           if(exitonerror)
-            gal_fits_io_error(status, "opening the given extension/HDU in "
-                              "the given file");
+            gal_fits_io_error(status, "opening the given extension/HDU "
+                              "in the given file");
           else return NULL;
         }
 
       if(exitonerror)
-        error(EXIT_FAILURE, 0, "%s: extension/HDU '%s' doesn't exist. Please "
-              "run the following command to see the extensions/HDUs in "
-              "'%s':\n\n"
+        error(EXIT_FAILURE, 0, "%s: extension/HDU '%s' doesn't exist. "
+              "Please run the following command to see the "
+              "extensions/HDUs in '%s':\n\n"
               "    $ astfits %s\n\n"
-              "The respective HDU number (or name, when present) may be used "
-              "with the '--hdu' option in Gnuastro's programs (or the 'hdu' "
-              "argument in Gnuastro's libraries) to open the respective HDU. "
-              "If you are using counters/numbers to identify your HDUs, note "
-              "that since Gnuastro uses CFITSIO for FITS input/output, HDU "
-              "counting starts from 0", filename, hdu, filename, filename);
+              "The respective HDU number (or name, when present) may be "
+              "used with the '%s' option to open your desired input here. "
+              "If you are using counters/numbers to identify your HDUs, "
+              "note that since Gnuastro uses CFITSIO for FITS "
+              "input/output, HDU counting starts from 0", filename, hdu,
+              filename, filename, hduon);
       else return NULL;
     }
 
@@ -918,7 +921,8 @@ gal_fits_hdu_open(char *filename, char *hdu, int iomode, 
int exitonerror)
 /* Check the desired HDU in a FITS image and also if it has the
    desired type. */
 fitsfile *
-gal_fits_hdu_open_format(char *filename, char *hdu, int img0_tab1)
+gal_fits_hdu_open_format(char *filename, char *hdu, int img0_tab1,
+                         char *hdu_option_name)
 {
   fitsfile *fptr;
   int status=0, hdutype;
@@ -928,7 +932,7 @@ gal_fits_hdu_open_format(char *filename, char *hdu, int 
img0_tab1)
     error(EXIT_FAILURE, 0, "no HDU specified for %s", filename);
 
   /* Open the HDU. */
-  fptr=gal_fits_hdu_open(filename, hdu, READONLY, 1);
+  fptr=gal_fits_hdu_open(filename, hdu, READONLY, 1, hdu_option_name);
 
   /* Check the type of the given HDU: */
   if (fits_get_hdu_type(fptr, &hdutype, &status) )
@@ -2019,10 +2023,11 @@ gal_fits_key_write_wcsstr(fitsfile *fptr, struct wcsprm 
*wcs,
    specified FITS file. */
 void
 gal_fits_key_write(gal_fits_list_key_t **keylist, char *title,
-                   char *filename, char *hdu)
+                   char *filename, char *hdu, char *hdu_option_name)
 {
   int status=0;
-  fitsfile *fptr=gal_fits_hdu_open(filename, hdu, READWRITE, 1);
+  fitsfile *fptr=gal_fits_hdu_open(filename, hdu, READWRITE, 1,
+                                   hdu_option_name);
 
   /* Write the title */
   gal_fits_key_write_title_in_ptr(title, fptr);
@@ -2162,10 +2167,12 @@ gal_fits_key_write_in_ptr(gal_fits_list_key_t 
**keylist, fitsfile *fptr)
    file. */
 void
 gal_fits_key_write_version(gal_fits_list_key_t **keylist, char *title,
-                           char *filename, char *hdu)
+                           char *filename, char *hdu,
+                           char *hdu_option_name)
 {
   int status=0;
-  fitsfile *fptr=gal_fits_hdu_open(filename, hdu, READWRITE, 1);
+  fitsfile *fptr=gal_fits_hdu_open(filename, hdu, READWRITE, 1,
+                                   hdu_option_name);
 
   /* Write the given keys followed by the versions. */
   gal_fits_key_write_version_in_ptr(keylist, title, fptr);
@@ -2274,10 +2281,12 @@ gal_fits_key_write_version_in_ptr(gal_fits_list_key_t 
**keylist,
    Gnuastro's program and this library). */
 void
 gal_fits_key_write_config(gal_fits_list_key_t **keylist, char *title,
-                          char *extname, char *filename, char *hdu)
+                          char *extname, char *filename, char *hdu,
+                          char *hdu_option_name)
 {
   int status=0;
-  fitsfile *fptr=gal_fits_hdu_open(filename, hdu, READWRITE, 1);
+  fitsfile *fptr=gal_fits_hdu_open(filename, hdu, READWRITE, 1,
+                                   hdu_option_name);
 
   /* Delete the two extra comment lines describing the FITS standard that
      CFITSIO puts in when it creates a new extension. We'll set status to 0
@@ -2307,7 +2316,7 @@ gal_fits_key_write_config(gal_fits_list_key_t **keylist, 
char *title,
    certain value(s) in a certain keyword.*/
 gal_list_str_t *
 gal_fits_with_keyvalue(gal_list_str_t *files, char *hdu, char *name,
-                       gal_list_str_t *values)
+                       gal_list_str_t *values, char *hdu_option_name)
 {
   int status=0;
   fitsfile *fptr;
@@ -2319,7 +2328,7 @@ gal_fits_with_keyvalue(gal_list_str_t *files, char *hdu, 
char *name,
   for(f=files; f!=NULL; f=f->next)
     {
       /* Open the file. */
-      fptr=gal_fits_hdu_open(f->v, hdu, READONLY, 0);
+      fptr=gal_fits_hdu_open(f->v, hdu, READONLY, 0, hdu_option_name);
 
       /* Only attempt to read the value if the requested HDU could be
          opened ('fptr!=NULL'). */
@@ -2364,7 +2373,8 @@ gal_fits_with_keyvalue(gal_list_str_t *files, char *hdu, 
char *name,
 /* From an input list of FITS files and a HDU, select those that have a
    certain value(s) in a certain keyword.*/
 gal_list_str_t *
-gal_fits_unique_keyvalues(gal_list_str_t *files, char *hdu, char *name)
+gal_fits_unique_keyvalues(gal_list_str_t *files, char *hdu, char *name,
+                          char *hdu_option_name)
 {
   fitsfile *fptr;
   int status=0, newvalue;
@@ -2376,7 +2386,7 @@ gal_fits_unique_keyvalues(gal_list_str_t *files, char 
*hdu, char *name)
   for(f=files; f!=NULL; f=f->next)
     {
       /* Open the file. */
-      fptr=gal_fits_hdu_open(f->v, hdu, READONLY, 0);
+      fptr=gal_fits_hdu_open(f->v, hdu, READONLY, 0, hdu_option_name);
 
       /* Only attempt to read the value if the requested HDU could be
          opened ('fptr!=NULL'). */
@@ -2529,7 +2539,8 @@ gal_fits_img_info(fitsfile *fptr, int *type, size_t 
*ndim, size_t **dsize,
 
 /* Get the basic array info to remove extra dimensions if necessary. */
 size_t *
-gal_fits_img_info_dim(char *filename, char *hdu, size_t *ndim)
+gal_fits_img_info_dim(char *filename, char *hdu, size_t *ndim,
+                      char *hdu_option_name)
 {
   fitsfile *fptr;
   size_t *dsize=NULL;
@@ -2537,7 +2548,8 @@ gal_fits_img_info_dim(char *filename, char *hdu, size_t 
*ndim)
 
   /* Open the given header, read the basic image information and close it
      again. */
-  fptr=gal_fits_hdu_open(filename, hdu, READONLY, 1);
+  fptr=gal_fits_hdu_open(filename, hdu, READONLY, 1,
+                         hdu_option_name);
   gal_fits_img_info(fptr, &type, ndim, &dsize, NULL, NULL);
   if( fits_close_file(fptr, &status) ) gal_fits_io_error(status, NULL);
 
@@ -2551,7 +2563,7 @@ gal_fits_img_info_dim(char *filename, char *hdu, size_t 
*ndim)
 /* Read a FITS image HDU into a Gnuastro data structure. */
 gal_data_t *
 gal_fits_img_read(char *filename, char *hdu, size_t minmapsize,
-                  int quietmmap)
+                  int quietmmap, char *hdu_option_name)
 {
   void *blank;
   long *fpixel;
@@ -2560,10 +2572,11 @@ gal_fits_img_read(char *filename, char *hdu, size_t 
minmapsize,
   size_t i, ndim, *dsize;
   char *name=NULL, *unit=NULL;
   int status=0, type, anyblank;
+  char *hduon = hdu_option_name ? hdu_option_name : "--hdu";
 
 
   /* Check HDU for realistic conditions: */
-  fptr=gal_fits_hdu_open_format(filename, hdu, 0);
+  fptr=gal_fits_hdu_open_format(filename, hdu, 0, NULL);
 
 
   /* Get the info and allocate the data structure. */
@@ -2573,13 +2586,13 @@ gal_fits_img_read(char *filename, char *hdu, size_t 
minmapsize,
   /* Check if there is any dimensions (the first header can sometimes have
      no images). */
   if(ndim==0)
-    error(EXIT_FAILURE, 0, "%s (hdu: %s) has 0 dimensions! The most common "
-          "cause for this is a wrongly specified HDU. In some FITS images, "
-          "the first HDU doesn't have any data, the data is in subsequent "
-          "extensions. So probably reading the second HDU (with '--hdu=1' "
-          "or '-h1') will solve the problem (following CFITSIO's "
-          "convention, currently HDU counting starts from 0)." , filename,
-          hdu);
+    error(EXIT_FAILURE, 0, "%s (hdu: %s) has 0 dimensions! The most "
+          "common cause for this is a wrongly specified HDU. In some "
+          "FITS images, the first HDU doesn't have any data, the data "
+          "is in subsequent extensions. So probably reading the second "
+          "HDU (with '%s=1') will solve the problem (following CFITSIO's "
+          "convention, currently HDU counting starts from 0)", filename,
+          hdu, hduon);
 
 
   /* Set the fpixel array (first pixel in all dimensions). Note that the
@@ -2627,12 +2640,14 @@ gal_fits_img_read(char *filename, char *hdu, size_t 
minmapsize,
    used to convert the input file to the desired type. */
 gal_data_t *
 gal_fits_img_read_to_type(char *inputname, char *hdu, uint8_t type,
-                          size_t minmapsize, int quietmmap)
+                          size_t minmapsize, int quietmmap,
+                          char *hdu_option_name)
 {
   gal_data_t *in, *converted;
 
   /* Read the specified input image HDU. */
-  in=gal_fits_img_read(inputname, hdu, minmapsize, quietmmap);
+  in=gal_fits_img_read(inputname, hdu, minmapsize, quietmmap,
+                       hdu_option_name);
 
   /* If the input had another type, convert it to float. */
   if(in->type!=type)
@@ -2652,7 +2667,7 @@ gal_fits_img_read_to_type(char *inputname, char *hdu, 
uint8_t type,
 
 gal_data_t *
 gal_fits_img_read_kernel(char *filename, char *hdu, size_t minmapsize,
-                         int quietmmap)
+                         int quietmmap, char *hdu_option_name)
 {
   size_t i;
   int check=0;
@@ -2662,7 +2677,7 @@ gal_fits_img_read_kernel(char *filename, char *hdu, 
size_t minmapsize,
 
   /* Read the image as a float and if it has a WCS structure, free it. */
   kernel=gal_fits_img_read_to_type(filename, hdu, GAL_TYPE_FLOAT32,
-                                   minmapsize, quietmmap);
+                                   minmapsize, quietmmap, hdu_option_name);
   if(kernel->wcs) { wcsfree(kernel->wcs); kernel->wcs=NULL; }
 
   /* Check if the size along each dimension of the kernel is an odd
@@ -3190,7 +3205,7 @@ fits_correct_bin_table_int_types(gal_data_t *allcols, int 
tfields,
 /* See the descriptions of 'gal_table_info'. */
 gal_data_t *
 gal_fits_tab_info(char *filename, char *hdu, size_t *numcols,
-                  size_t *numrows, int *tableformat)
+                  size_t *numrows, int *tableformat, char *hdu_option_name)
 {
   long repeat;
   int tfields;        /* The maximum number of fields in FITS is 999 */
@@ -3210,7 +3225,7 @@ gal_fits_tab_info(char *filename, char *hdu, size_t 
*numcols,
 
 
   /* Open the FITS file and get the basic information. */
-  fptr=gal_fits_hdu_open_format(filename, hdu, 1);
+  fptr=gal_fits_hdu_open_format(filename, hdu, 1, hdu_option_name);
   *tableformat=gal_fits_tab_format(fptr);
   gal_fits_tab_size(fptr, numrows, numcols);
 
@@ -3569,22 +3584,23 @@ fits_tab_read_ascii_float_special(char *filename, char 
*hdu,
 /* Read one column of the table in parallel. */
 struct fits_tab_read_onecol_params
 {
-  char              *filename;  /* Name of FITS file with table.     */
-  char                   *hdu;  /* HDU of input table.               */
-  size_t              numrows;  /* Number of rows in table to read.  */
-  size_t              numcols;  /* Number of columns.                */
-  size_t           minmapsize;  /* Minimum space to memory-map.      */
-  int               quietmmap;  /* Don't print memory-mapping info.  */
-  gal_data_t         *allcols;  /* Information of all columns.       */
-  gal_data_t       **colarray;  /* Array of pointers to all columns. */
-  gal_list_sizet_t   *indexll;  /* Index of columns to read.         */
+  char              *filename;  /* Name of FITS file with table.        */
+  char                   *hdu;  /* HDU of input table.                  */
+  size_t              numrows;  /* Number of rows in table to read.     */
+  size_t              numcols;  /* Number of columns.                   */
+  size_t           minmapsize;  /* Minimum space to memory-map.         */
+  int               quietmmap;  /* Don't print memory-mapping info.     */
+  gal_data_t         *allcols;  /* Information of all columns.          */
+  gal_data_t       **colarray;  /* Array of pointers to all columns.    */
+  gal_list_sizet_t   *indexll;  /* Index of columns to read.            */
+  char       *hdu_option_name;  /* HDU option name (for error message). */
 };
 
 
 
 
 
-void *
+static void *
 fits_tab_read_onecol(void *in_prm)
 {
   /* Low-level definitions to be done first. */
@@ -3604,7 +3620,8 @@ fits_tab_read_onecol(void *in_prm)
   size_t i, j, c, ndim, strw, repeat, indout, indin=GAL_BLANK_SIZE_T;
 
   /* Open the FITS file. */
-  fptr=gal_fits_hdu_open_format(p->filename, p->hdu, 1);
+  fptr=gal_fits_hdu_open_format(p->filename, p->hdu, 1,
+                                p->hdu_option_name);
 
   /* See if its a Binary or ASCII table (necessary for floating point
      blank values). */
@@ -3751,7 +3768,8 @@ fits_tab_read_onecol(void *in_prm)
 gal_data_t *
 gal_fits_tab_read(char *filename, char *hdu, size_t numrows,
                   gal_data_t *allcols, gal_list_sizet_t *indexll,
-                  size_t numthreads, size_t minmapsize, int quietmmap)
+                  size_t numthreads, size_t minmapsize, int quietmmap,
+                  char *hdu_option_name)
 {
   size_t i;
   gal_data_t *out=NULL;
@@ -3787,6 +3805,7 @@ gal_fits_tab_read(char *filename, char *hdu, size_t 
numrows,
       p.filename = filename;
       p.quietmmap = quietmmap;
       p.minmapsize = minmapsize;
+      p.hdu_option_name = hdu_option_name;
       gal_threads_spin_off(fits_tab_read_onecol, &p, p.numcols, nthreads,
                            minmapsize, quietmmap);
 
diff --git a/lib/gnuastro/array.h b/lib/gnuastro/array.h
index 3c833f14..f6b9a500 100644
--- a/lib/gnuastro/array.h
+++ b/lib/gnuastro/array.h
@@ -63,21 +63,24 @@ gal_array_file_recognized(char *name);
 
 gal_data_t *
 gal_array_read(char *filename, char *extension, gal_list_str_t *lines,
-               size_t minmapsize, int quietmmap);
+               size_t minmapsize, int quietmmap, char *ext_option_name);
 
 gal_data_t *
 gal_array_read_to_type(char *filename, char *extension,
                        gal_list_str_t *lines, uint8_t type,
-                       size_t minmapsize, int quietmmap);
+                       size_t minmapsize, int quietmmap,
+                       char *ext_option_name);
 
 gal_data_t *
-gal_array_read_one_ch(char *filename, char *extension, gal_list_str_t *lines,
-                      size_t minmapsize, int quietmmap);
+gal_array_read_one_ch(char *filename, char *extension,
+                      gal_list_str_t *lines, size_t minmapsize,
+                      int quietmmap, char *ext_option_name);
 
 gal_data_t *
 gal_array_read_one_ch_to_type(char *filename, char *extension,
                               gal_list_str_t *lines, uint8_t type,
-                              size_t minmapsize, int quietmmap);
+                              size_t minmapsize, int quietmmap,
+                              char *ext_option_name);
 
 
 __END_C_DECLS    /* From C++ preparations */
diff --git a/lib/gnuastro/fits.h b/lib/gnuastro/fits.h
index 55ca2908..0a3725ff 100644
--- a/lib/gnuastro/fits.h
+++ b/lib/gnuastro/fits.h
@@ -160,23 +160,24 @@ size_t
 gal_fits_hdu_num(char *filename);
 
 unsigned long
-gal_fits_hdu_datasum(char *filename, char *hdu);
+gal_fits_hdu_datasum(char *filename, char *hdu, char *hdu_option_name);
 
 unsigned long
 gal_fits_hdu_datasum_ptr(fitsfile *fptr);
 
 int
-gal_fits_hdu_format(char *filename, char *hdu);
+gal_fits_hdu_format(char *filename, char *hdu, char *hdu_option_name);
 
 int
 gal_fits_hdu_is_healpix(fitsfile *fptr);
 
 fitsfile *
-gal_fits_hdu_open(char *filename, char *hdu, int iomode,
-                  int exitonerror);
+gal_fits_hdu_open(char *filename, char *hdu, int iomode, int exitonerror,
+                  char *hdu_option_name);
 
 fitsfile *
-gal_fits_hdu_open_format(char *filename, char *hdu, int img0_tab1);
+gal_fits_hdu_open_format(char *filename, char *hdu, int img0_tab1,
+                         char *hdu_option_name);
 
 
 
@@ -251,14 +252,15 @@ gal_fits_key_write_wcsstr(fitsfile *fptr, struct wcsprm 
*wcs,
 
 void
 gal_fits_key_write(gal_fits_list_key_t **keylist, char *title,
-                   char *filename, char *hdu);
+                   char *filename, char *hdu, char *hdu_option_name);
 
 void
 gal_fits_key_write_in_ptr(gal_fits_list_key_t **keylist, fitsfile *fptr);
 
 void
 gal_fits_key_write_version(gal_fits_list_key_t **keylist, char *title,
-                           char *filename, char *hdu);
+                           char *filename, char *hdu,
+                           char *hdu_option_name);
 
 void
 gal_fits_key_write_version_in_ptr(gal_fits_list_key_t **keylist, char *title,
@@ -266,14 +268,16 @@ gal_fits_key_write_version_in_ptr(gal_fits_list_key_t 
**keylist, char *title,
 
 void
 gal_fits_key_write_config(gal_fits_list_key_t **keylist, char *title,
-                          char *extname, char *filename, char *hdu);
+                          char *extname, char *filename, char *hdu,
+                          char *hdu_option_name);
 
 gal_list_str_t *
 gal_fits_with_keyvalue(gal_list_str_t *files, char *hdu, char *name,
-                       gal_list_str_t *values);
+                       gal_list_str_t *values, char *hdu_option_name);
 
 gal_list_str_t *
-gal_fits_unique_keyvalues(gal_list_str_t *files, char *hdu, char *name);
+gal_fits_unique_keyvalues(gal_list_str_t *files, char *hdu, char *name,
+                          char *hdu_option_name);
 
 
 
@@ -287,18 +291,21 @@ gal_fits_img_info(fitsfile *fptr, int *type, size_t 
*ndim, size_t **dsize,
                   char **name, char **unit);
 
 size_t *
-gal_fits_img_info_dim(char *filename, char *hdu, size_t *ndim);
+gal_fits_img_info_dim(char *filename, char *hdu, size_t *ndim,
+                      char *hdu_option_name);
 
 gal_data_t *
-gal_fits_img_read(char *filename, char *hdu, size_t minmapsize, int quietmmap);
+gal_fits_img_read(char *filename, char *hdu, size_t minmapsize,
+                  int quietmmap, char *hdu_option_name);
 
 gal_data_t *
 gal_fits_img_read_to_type(char *inputname, char *hdu, uint8_t type,
-                          size_t minmapsize, int quietmmap);
+                          size_t minmapsize, int quietmmap,
+                          char *hdu_option_name);
 
 gal_data_t *
 gal_fits_img_read_kernel(char *filename, char *hdu, size_t minmapsize,
-                         int quietmmap);
+                         int quietmmap, char *hdu_option_name);
 
 fitsfile *
 gal_fits_img_write_to_ptr(gal_data_t *data, char *filename);
@@ -333,12 +340,14 @@ gal_fits_tab_format(fitsfile *fptr);
 
 gal_data_t *
 gal_fits_tab_info(char *filename, char *hdu, size_t *numcols,
-                  size_t *numrows, int *tableformat);
+                  size_t *numrows, int *tableformat,
+                  char *hdu_option_name);
 
 gal_data_t *
 gal_fits_tab_read(char *filename, char *hdu, size_t numrows,
                   gal_data_t *allcols, gal_list_sizet_t *indexll,
-                  size_t numthreads, size_t minmapsize, int quietmmap);
+                  size_t numthreads, size_t minmapsize, int quietmmap,
+                  char *hdu_option_name);
 
 void
 gal_fits_tab_write(gal_data_t *cols, gal_list_str_t *comments,
diff --git a/lib/gnuastro/table.h b/lib/gnuastro/table.h
index 7609a675..d0700e1d 100644
--- a/lib/gnuastro/table.h
+++ b/lib/gnuastro/table.h
@@ -139,7 +139,8 @@ gal_table_displayflt_to_str(uint8_t fmt);
 /************************************************************************/
 gal_data_t *
 gal_table_info(char *filename, char *hdu, gal_list_str_t *lines,
-               size_t *numcols, size_t *numrows, int *tableformat);
+               size_t *numcols, size_t *numrows, int *tableformat,
+               char *hdu_option_name);
 
 void
 gal_table_print_info(gal_data_t *allcols, size_t numcols, size_t numrows);
@@ -153,7 +154,7 @@ gal_data_t *
 gal_table_read(char *filename, char *hdu, gal_list_str_t *lines,
                gal_list_str_t *cols, int searchin, int ignorecase,
                size_t numthreads, size_t minmapsize, int quietmmap,
-               size_t *colmatch);
+               size_t *colmatch, char *hdu_option_name);
 
 gal_list_sizet_t *
 gal_table_list_of_indexs(gal_list_str_t *cols, gal_data_t *allcols,
diff --git a/lib/gnuastro/wcs.h b/lib/gnuastro/wcs.h
index b407f7b0..5e46b5a6 100644
--- a/lib/gnuastro/wcs.h
+++ b/lib/gnuastro/wcs.h
@@ -104,8 +104,9 @@ gal_wcs_read_fitsptr(fitsfile *fptr, int linearmatrix, 
size_t hstartwcs,
                      size_t hendwcs, int *nwcs);
 
 struct wcsprm *
-gal_wcs_read(char *filename, char *hdu, int linearmatrix, size_t hstartwcs,
-             size_t hendwcs, int *nwcs);
+gal_wcs_read(char *filename, char *hdu, int linearmatrix,
+             size_t hstartwcs, size_t hendwcs, int *nwcs,
+             char *hdu_option_name);
 
 struct wcsprm *
 gal_wcs_create(double *crpix, double *crval, double *cdelt,
@@ -209,9 +210,11 @@ double
 gal_wcs_pixel_area_arcsec2(struct wcsprm *wcs);
 
 int
-gal_wcs_coverage(char *filename, char *hdu, size_t *ndim,
-                 double **center, double **width, double **min,
-                 double **max);
+gal_wcs_coverage(char *filename, char *hdu, size_t *ondim,
+                 double **ocenter, double **owidth, double **omin,
+                 double **omax, char *hdu_option_name);
+
+
 
 
 
diff --git a/lib/makeplugin.c b/lib/makeplugin.c
index 19b43d1d..2ee4e181 100644
--- a/lib/makeplugin.c
+++ b/lib/makeplugin.c
@@ -240,7 +240,7 @@ makeplugin_fits_with_keyvalue(const char *caller, unsigned 
int argc,
      values and find the output files.*/
   files=gal_list_str_extract(argv[3]);
   values=gal_list_str_extract(argv[1]);
-  outlist=gal_fits_with_keyvalue(files, hdu, name, values);
+  outlist=gal_fits_with_keyvalue(files, hdu, name, values, NULL);
 
   /* Write the output string */
   out=gal_list_str_cat(outlist, ' ');
@@ -276,7 +276,7 @@ makeplugin_fits_unique_keyvalues(const char *caller, 
unsigned int argc,
   /* Extract the components in the arguments with possibly multiple
      values and find the output files.*/
   files=gal_list_str_extract(argv[2]);
-  outlist=gal_fits_unique_keyvalues(files, hdu, name);
+  outlist=gal_fits_unique_keyvalues(files, hdu, name, NULL);
 
   /* Write the output value. */
   out=gal_list_str_cat(outlist, ' ');
diff --git a/lib/table.c b/lib/table.c
index 0093ecde..2f89e3b7 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -102,11 +102,13 @@ gal_table_displayflt_to_str(uint8_t fmt)
    of the output's elements. */
 gal_data_t *
 gal_table_info(char *filename, char *hdu, gal_list_str_t *lines,
-               size_t *numcols, size_t *numrows, int *tableformat)
+               size_t *numcols, size_t *numrows, int *tableformat,
+               char *hdu_option_name)
 {
   /* Get the table format and size (number of columns and rows). */
   if(filename && gal_fits_file_recognized(filename))
-    return gal_fits_tab_info(filename, hdu, numcols, numrows, tableformat);
+    return gal_fits_tab_info(filename, hdu, numcols, numrows, tableformat,
+                             hdu_option_name);
   else
     {
       *tableformat=GAL_TABLE_FORMAT_TXT;
@@ -483,7 +485,7 @@ gal_data_t *
 gal_table_read(char *filename, char *hdu, gal_list_str_t *lines,
                gal_list_str_t *cols, int searchin, int ignorecase,
                size_t numthreads, size_t minmapsize, int quietmmap,
-               size_t *colmatch)
+               size_t *colmatch, char *hdu_option_name)
 {
   int tableformat;
   gal_list_sizet_t *indexll;
@@ -492,7 +494,7 @@ gal_table_read(char *filename, char *hdu, gal_list_str_t 
*lines,
 
   /* First get the information of all the columns. */
   allcols=gal_table_info(filename, hdu, lines, &numcols, &numrows,
-                         &tableformat);
+                         &tableformat, hdu_option_name);
 
   /* If there was no actual data in the file, then return NULL. */
   if(allcols==NULL) return NULL;
@@ -514,7 +516,8 @@ gal_table_read(char *filename, char *hdu, gal_list_str_t 
*lines,
     case GAL_TABLE_FORMAT_AFITS:
     case GAL_TABLE_FORMAT_BFITS:
       out=gal_fits_tab_read(filename, hdu, numrows, allcols, indexll,
-                            numthreads, minmapsize, quietmmap);
+                            numthreads, minmapsize, quietmmap,
+                            hdu_option_name);
       break;
 
     default:
diff --git a/lib/wcs.c b/lib/wcs.c
index c29073ce..542ec8b8 100644
--- a/lib/wcs.c
+++ b/lib/wcs.c
@@ -403,7 +403,8 @@ gal_wcs_read_fitsptr(fitsfile *fptr, int linearmatrix, 
size_t hstartwcs,
 
 struct wcsprm *
 gal_wcs_read(char *filename, char *hdu, int linearmatrix,
-             size_t hstartwcs, size_t hendwcs, int *nwcs)
+             size_t hstartwcs, size_t hendwcs, int *nwcs,
+             char *hdu_option_name)
 {
   int status=0;
   fitsfile *fptr;
@@ -414,7 +415,7 @@ gal_wcs_read(char *filename, char *hdu, int linearmatrix,
     return NULL;
 
   /* Check HDU for realistic conditions: */
-  fptr=gal_fits_hdu_open_format(filename, hdu, 0);
+  fptr=gal_fits_hdu_open_format(filename, hdu, 0, hdu_option_name);
 
   /* Read the WCS information: */
   wcs=gal_wcs_read_fitsptr(fptr, linearmatrix, hstartwcs,
@@ -2076,7 +2077,7 @@ gal_wcs_pixel_area_arcsec2(struct wcsprm *wcs)
 int
 gal_wcs_coverage(char *filename, char *hdu, size_t *ondim,
                  double **ocenter, double **owidth, double **omin,
-                 double **omax)
+                 double **omax, char *hdu_option_name)
 {
   fitsfile *fptr;
   struct wcsprm *wcs;
@@ -2090,19 +2091,20 @@ gal_wcs_coverage(char *filename, char *hdu, size_t 
*ondim,
   /* Read the desired WCS (note that the linear matrix is irrelevant here,
      we'll just select PC because its the default WCS mode. */
   wcs=gal_wcs_read(filename, hdu, GAL_WCS_LINEAR_MATRIX_PC,
-                   0, 0, &nwcs);
+                   0, 0, &nwcs, hdu_option_name);
 
   /* If a WCS doesn't exist, return NULL. */
   if(wcs==NULL) return 0;
 
   /* Make sure the input HDU is an image. */
-  if( gal_fits_hdu_format(filename, hdu) != IMAGE_HDU )
+  if( gal_fits_hdu_format(filename, hdu, hdu_option_name) != IMAGE_HDU )
     error(EXIT_FAILURE, 0, "%s (hdu %s): is not an image HDU, the "
           "'--skycoverage' option only applies to image extensions",
           filename, hdu);
 
   /* Get the array information of the image. */
-  fptr=gal_fits_hdu_open(filename, hdu, READONLY, 1);
+  fptr=gal_fits_hdu_open(filename, hdu, READONLY, 1,
+                         hdu_option_name);
   gal_fits_img_info(fptr, &type, ondim, &dsize, &name, &unit);
   fits_close_file(fptr, &status);
   ndim=*ondim;
diff --git a/tests/buildprog/simpleio.c b/tests/buildprog/simpleio.c
index bdb07c0b..a66a96cf 100644
--- a/tests/buildprog/simpleio.c
+++ b/tests/buildprog/simpleio.c
@@ -39,7 +39,7 @@ main(int argc, char *argv[])
     }
 
   /* Read the image into memory. */
-  image=gal_fits_img_read(argv[1], argv[2], -1, 1);
+  image=gal_fits_img_read(argv[1], argv[2], -1, 1, "ARGUMENT-2");
 
   /* Let the user know. */
   printf("%s (hdu %s) is read into memory.\n", argv[1], argv[2]);
diff --git a/tests/lib/multithread.c b/tests/lib/multithread.c
index 002cf350..ec9f8788 100644
--- a/tests/lib/multithread.c
+++ b/tests/lib/multithread.c
@@ -98,7 +98,7 @@ main(void)
 
   /* Read the image into memory as a float32 data type. */
   p.image=gal_fits_img_read_to_type(filename, hdu, GAL_TYPE_FLOAT32,
-                                    minmapsize, quietmmap);
+                                    minmapsize, quietmmap, "HARDCODED");
 
 
   /* Print some basic information before the actual contents: */



reply via email to

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