gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 21877f7: Implementing __func__ in error messag


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 21877f7: Implementing __func__ in error messages
Date: Sat, 29 Apr 2017 14:36:31 -0400 (EDT)

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

    Implementing __func__ in error messages
    
    Work is continuing on documenting the library. In the process, I recognized
    that Gnulib provides the `func' module that will enable us to use the
    `__func__' pre-defined identifier. It is standardized in C99, but as Gnulib
    discusses, it is not fully implemented on all systems, so it wasn't used in
    Gnuastro. But after importing Gnulib's implementation of it, we can safely
    use it even if the host system doesn't recognize it.
    
    This new format of including the function name in the error messages has
    now been implemented in nearly all library functions (except those that are
    just about file opening or closing for example and can confuse the user
    program users) and all internal function errors in programs: not errors
    that directly relate to the user's inputs. For error messages that are
    about the user's input, adding function names will most probably confuse
    the user and reduce the affectiveness of the error message.
---
 bin/arithmetic/arithmetic.c    |   4 +-
 bin/arithmetic/operands.c      |   9 +-
 bin/convertt/convertt.c        |  16 ++--
 bin/convertt/eps.c             |  10 +--
 bin/convertt/jpeg.c            |  28 ++++---
 bin/convertt/ui.c              |   4 +-
 bin/convolve/convolve.c        |  34 ++++----
 bin/crop/crop.c                |  15 ++--
 bin/crop/onecrop.c             |  27 +++---
 bin/fits/fits.c                |  19 ++---
 bin/fits/keywords.c            |   6 +-
 bin/fits/ui.c                  |  11 +--
 bin/mkcatalog/columns.c        |  58 ++++++-------
 bin/mkprof/mkprof.c            |  16 ++--
 bin/mkprof/oneprofile.c        |  10 +--
 bin/noisechisel/clumps.c       |  21 +++--
 bin/noisechisel/detection.c    |  22 +++--
 bin/noisechisel/segmentation.c |   7 +-
 bin/noisechisel/sky.c          |   5 +-
 bin/noisechisel/threshold.c    |  11 ++-
 bin/statistics/statistics.c    |  27 +++---
 bin/warp/warp.c                |   7 +-
 bootstrap.conf                 |   1 +
 doc/gnuastro.texi              |  17 +++-
 lib/arithmetic-binary.c        |  17 ++--
 lib/arithmetic-onlyint.c       |  28 +++----
 lib/arithmetic.c               | 108 ++++++++++++------------
 lib/binary.c                   |  66 +++++++--------
 lib/blank.c                    |  50 +++++------
 lib/checkset.c                 |  35 ++++----
 lib/convolve.c                 |  25 +++---
 lib/data.c                     | 185 ++++++++++++++++++++---------------------
 lib/dimension.c                |  11 ++-
 lib/fits.c                     | 175 +++++++++++++++++++-------------------
 lib/git.c                      |   4 +-
 lib/interpolate.c              |  11 ++-
 lib/list.c                     |  31 +++----
 lib/options.c                  |  43 +++++-----
 lib/polygon.c                  |  11 ++-
 lib/statistics.c               | 122 +++++++++++++--------------
 lib/table.c                    |  62 +++++++-------
 lib/threads.c                  |  19 +++--
 lib/tile.c                     |  28 +++----
 lib/txt.c                      |  79 +++++++++---------
 lib/type.c                     |  50 +++++------
 lib/wcs.c                      |  32 +++----
 46 files changed, 774 insertions(+), 803 deletions(-)

diff --git a/bin/arithmetic/arithmetic.c b/bin/arithmetic/arithmetic.c
index 7be6317..95ddf58 100644
--- a/bin/arithmetic/arithmetic.c
+++ b/bin/arithmetic/arithmetic.c
@@ -90,8 +90,8 @@ set_number_of_operands(struct imgarithparams *p, gal_data_t 
*data,
             "operator must be an integer type", token_string);
 
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`set_number_of_operands", data->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, data->type);
     }
 
   /* If control reaches here, then the number must have been a negative
diff --git a/bin/arithmetic/operands.c b/bin/arithmetic/operands.c
index 6dbf876..e8c7dd0 100644
--- a/bin/arithmetic/operands.c
+++ b/bin/arithmetic/operands.c
@@ -69,8 +69,8 @@ add_operand(struct imgarithparams *p, char *filename, 
gal_data_t *data)
       errno=0;
       newnode=malloc(sizeof *newnode);
       if(newnode==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for newnode in"
-              "add_operand", sizeof *newnode);
+        error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `newnode'",
+              __func__, sizeof *newnode);
 
       /* Fill in the values. */
       newnode->data=data;
@@ -147,8 +147,9 @@ pop_operand(struct imgarithparams *p, char *operator)
           errno=0;
           p->refdata.dsize=malloc(p->refdata.ndim * sizeof *p->refdata.dsize);
           if(p->refdata.dsize==NULL)
-            error(EXIT_FAILURE, errno, "%zu bytes for p->refdata.dsize in "
-                  "`operands.c'", p->refdata.ndim * sizeof *p->refdata.dsize);
+            error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for "
+                  "p->refdata.dsize", __func__,
+                  p->refdata.ndim * sizeof *p->refdata.dsize);
 
           /* Write the values into it. */
           for(i=0;i<p->refdata.ndim;++i)
diff --git a/bin/convertt/convertt.c b/bin/convertt/convertt.c
index 93682a3..8f057ad 100644
--- a/bin/convertt/convertt.c
+++ b/bin/convertt/convertt.c
@@ -113,9 +113,9 @@ convertt_trunc_function(int operator, gal_data_t *data, 
gal_data_t *value)
   /* A small sanity check. The process must be in-place so the original
      data structure must not have changed. */
   if(out!=data)
-    error(EXIT_FAILURE, 0, "a bug! please contact us at %s to solve the "
-          "problem. The `out' and `data' pointers in "
-          "`convertt_trunc_function' are not equal", PACKAGE_BUGREPORT);
+    error(EXIT_FAILURE, 0, "%s: a bug! please contact us at %s to solve the "
+          "problem. The `out' and `data' pointers are the same", __func__,
+          PACKAGE_BUGREPORT);
 
 
   /* Clean up. */
@@ -190,8 +190,8 @@ save_with_gnuastro_lib(struct converttparams *p)
 
     /* Not recognized. */
     default:
-      error(EXIT_FAILURE, 0, "a bug! output format code `%d' not "
-            "recognized in `save_with_gnuastro_lib'", p->outformat);
+      error(EXIT_FAILURE, 0, "%s: a bug! output format code `%d' not "
+            "recognized", __func__, p->outformat);
     }
 }
 
@@ -403,8 +403,8 @@ convertt(struct converttparams *p)
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "a bug! The internal type of the output is "
-            "not recognized. Please contact us so we can find the problem "
-            "and fix it");
+      error(EXIT_FAILURE, 0, "%s: a bug! Please contact us so we can find "
+            "the problem and fix it The internal type of the output is "
+            "not recognized. ", __func__);
     }
 }
diff --git a/bin/convertt/eps.c b/bin/convertt/eps.c
index 6e75ea7..4108c68 100644
--- a/bin/convertt/eps.c
+++ b/bin/convertt/eps.c
@@ -345,9 +345,9 @@ eps_write_image(struct converttparams *p, FILE *fp)
     case 3: fprintf(fp, "/DeviceRGB setcolorspace\n");  break;
     case 4: fprintf(fp, "/DeviceCMYK setcolorspace\n"); break;
     default:
-      error(EXIT_FAILURE, 0, "a bug! In saveepsorpdf the number of channels "
-            "is not 1, 3 or 4. Please contact us so we can find the issue "
-            "and fix it");
+      error(EXIT_FAILURE, 0, "%s: a bug! The number of channels (%zu) is not "
+            "1, 3 or 4. Please contact us so we can find the issue and fix it",
+            __func__, p->numch);
     }
   fprintf(fp, "<<\n");
   fprintf(fp, "  /ImageType 1\n");
@@ -397,8 +397,8 @@ eps_write_eps_or_pdf(struct converttparams *p)
       epsfilename=gal_checkset_automatic_output(&p->cp, p->cp.output, ".ps");
     }
   else
-    error(EXIT_FAILURE, 0, "a bug! In `saveeps`, for outformat is "
-          "neither eps or pdf! Please contact us so we fix it");
+    error(EXIT_FAILURE, 0, "%s: a bug! code %d not recognized for "
+          "`p->outformat'", __func__, p->outformat);
 
 
   /* Open the output file and write the top comments. */
diff --git a/bin/convertt/jpeg.c b/bin/convertt/jpeg.c
index b4742a9..c4b8cbe 100644
--- a/bin/convertt/jpeg.c
+++ b/bin/convertt/jpeg.c
@@ -149,7 +149,8 @@ makejsample(JSAMPLE **a, size_t size)
   errno=0;
   jsarr=malloc(size*sizeof *jsarr);
   if(jsarr==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for jsarr", size*sizeof *jsarr);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for jsarr",
+          __func__, size*sizeof *jsarr);
 
   *a=jsarr;
 }
@@ -183,7 +184,7 @@ readjpg(char *inname, size_t *outs0, size_t *outs1, size_t 
*numcolors)
     {
       jpeg_destroy_decompress(&cinfo);
       fclose(infile);
-      error(EXIT_FAILURE, 0, "problem in reading %s", inname);
+      error(EXIT_FAILURE, 0, "%s: problem in reading %s", __func__, inname);
     }
   jpeg_create_decompress(&cinfo);
   jpeg_stdio_src(&cinfo, infile);
@@ -204,14 +205,15 @@ readjpg(char *inname, size_t *outs0, size_t *outs1, 
size_t *numcolors)
   errno=0;
   all=malloc(nc*sizeof *all);
   if(all==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for all", nc*sizeof *all);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `all'",
+          __func__, nc*sizeof *all);
   for(i=0;i<nc;++i)
     {
       errno=0;
       all[i]=malloc(s0*s1*sizeof *all[i]);
       if(all[i]==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for all[%zu]",
-              s0*s1*sizeof *all[i], i);
+        error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `all[%zu]'",
+              __func__, s0*s1*sizeof *all[i], i);
     }
 
   /* Read the image line by line: */
@@ -336,9 +338,9 @@ jpeg_write_array(JSAMPLE *jsr, struct converttparams *p)
       cinfo.in_color_space = JCS_CMYK;
       break;
     default:
-      error(EXIT_FAILURE, 0, "a bug! The number of channels in writejpeg "
-            "is not 1, 3 or 4, but %zu. This should not happen. Please "
-            "contact us so we can fix the problem", p->numch);
+      error(EXIT_FAILURE, 0, "%s: a bug! The number of channels is not 1, 3 "
+            "or 4, but %zu. This should not happen. Please contact us so we "
+            "can fix the problem", __func__, p->numch);
     }
 
   jpeg_set_defaults(&cinfo);
@@ -374,18 +376,18 @@ jpeg_write(struct converttparams *p)
 
   /* A small sanity check */
   if(p->numch==2 || p->numch>4)
-    error(EXIT_FAILURE, 0, "in jpeg, only 1, 3, and 4 color channels are "
-          "acceptable, ");
+    error(EXIT_FAILURE, 0, "%s: only 1, 3, and 4 color channels are "
+          "acceptable", __func__);
 
   /* Make sure the JSAMPLE is 8bits, then allocate the necessary space
      based on the number of channels. */
   if(sizeof *jsr!=1)
-    error(EXIT_FAILURE, 0, "JSAMPLE has to be 8bit");
+    error(EXIT_FAILURE, 0, "%s: JSAMPLE has to be 8bit", __func__);
   errno=0;
   jsr=malloc(numch * p->chll->size * sizeof *jsr);
   if(jsr==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for jsr",
-          numch * p->chll->size * sizeof *jsr );
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for jsr",
+          __func__, numch * p->chll->size * sizeof *jsr );
 
   /* Set the pointers to each color. */
   i=0;
diff --git a/bin/convertt/ui.c b/bin/convertt/ui.c
index 17fd946..01dbd40 100644
--- a/bin/convertt/ui.c
+++ b/bin/convertt/ui.c
@@ -354,8 +354,8 @@ ui_make_change_struct(char *arg)
               errno=0;
               ch=malloc(sizeof *ch);
               if(ch==NULL)
-                error(EXIT_FAILURE, errno, "%zu bytes for ch in "
-                      "`ui_make_change_struct'", sizeof *ch);
+                error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `ch'",
+                      __func__, sizeof *ch);
 
               /* If the last structure has already been defined (!=NULL)
                  then we should set its next element to `ch' and change it
diff --git a/bin/convolve/convolve.c b/bin/convolve/convolve.c
index eff74b9..9e7030a 100644
--- a/bin/convolve/convolve.c
+++ b/bin/convolve/convolve.c
@@ -74,9 +74,8 @@ complextoreal(double *c, size_t size, int action, double 
**output)
       do { *o++ = *c;                            c+=2; } while(o<of);
       break;
     default:
-      error(EXIT_FAILURE, 0, "a bug! Please contact us at %s so we can "
-            "correct it. For some reason, the action code for "
-            "complextoreal in convolve.c (%d) is not recognized",
+      error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we can "
+            "correct it. The `action' code %d is not recognized", __func__,
             PACKAGE_BUGREPORT, action);
     }
 }
@@ -306,8 +305,8 @@ fftinitializer(struct convolveparams *p, struct 
fftonthreadparams **outfp)
   errno=0;
   *outfp=fp=malloc(p->cp.numthreads*sizeof *fp);
   if(fp==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes in forward2dfft for fp",
-          p->cp.numthreads*sizeof *fp);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for fp",
+          __func__, p->cp.numthreads*sizeof *fp);
 
   /* Initialize the gsl_fft_wavetable structures (these are thread
      safe): */
@@ -360,9 +359,8 @@ correctdeconvolve(struct convolveparams *p, double 
**spatial)
 
   /* Check if the image has even sides. */
   if(ps0%2 || ps1%2)
-    error(EXIT_FAILURE, 0, "a bug! Please contact us at %s. In "
-          "correctdeconvolve, the padded image sides are not an "
-          "even number", PACKAGE_BUGREPORT);
+    error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s. The padded "
+          "image sides are not an even number", __func__, PACKAGE_BUGREPORT);
 
   /* First convert the complex image to a real image: */
   complextoreal(p->pimg, ps0*ps1, COMPLEX_TO_REAL_SPEC, &s);
@@ -371,8 +369,8 @@ correctdeconvolve(struct convolveparams *p, double 
**spatial)
   errno=0;
   n=malloc(ps0*ps1*sizeof *n);
   if(n==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for n in correctdeconvolve "
-          "(convolve.c). ", ps0*ps1*sizeof *n);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `n'",
+          __func__, ps0*ps1*sizeof *n);
 
 
   /* Put the elements in their proper place: For example in one
@@ -528,10 +526,10 @@ twodimensionfft(struct convolveparams *p, struct 
fftonthreadparams *fp,
   if(forward1backwardn1==1)       multiple=2;
   else if(forward1backwardn1==-1) multiple=1;
   else
-    error(EXIT_FAILURE, 0, "a bug! In forward2dfft, the value of the "
-          "variable forward1backwardn1 is somehow not 1 or 2, but %d. "
-          "Please contact us at "PACKAGE_BUGREPORT" so we can find the "
-          "cause of the problem and fix it", forward1backwardn1);
+    error(EXIT_FAILURE, 0, "%s: a bug! The value of the variable "
+          "`forward1backwardn1' is %d not 1 or 2. Please contact us at %s "
+          "so we can find the cause of the problem and fix it", __func__,
+          forward1backwardn1, PACKAGE_BUGREPORT);
 
 
   /* ==================== */
@@ -566,8 +564,8 @@ twodimensionfft(struct convolveparams *p, struct 
fftonthreadparams *fp,
             fp[i].forward1backwardn1=forward1backwardn1;
             err=pthread_create(&t, &attr, onedimensionfft, &fp[i]);
             if(err)
-              error(EXIT_FAILURE, 0, "can't create thread %zu for rows",
-                    i);
+              error(EXIT_FAILURE, 0, "%s: can't create thread %zu for rows",
+                    __func__, i);
           }
 
       /* Wait for all threads to finish and free the spaces. */
@@ -605,8 +603,8 @@ twodimensionfft(struct convolveparams *p, struct 
fftonthreadparams *fp,
             fp[i].forward1backwardn1=forward1backwardn1;
             err=pthread_create(&t, &attr, onedimensionfft, &fp[i]);
             if(err)
-              error(EXIT_FAILURE, 0,
-                    "can't create thread %zu for columns", i);
+              error(EXIT_FAILURE, 0, "%s: can't create thread %zu for columns",
+                    __func__, i);
           }
       pthread_barrier_wait(&b);
       pthread_attr_destroy(&attr);
diff --git a/bin/crop/crop.c b/bin/crop/crop.c
index 6e7b576..1e8f02a 100644
--- a/bin/crop/crop.c
+++ b/bin/crop/crop.c
@@ -174,9 +174,9 @@ crop_write_to_log(struct onecropparams *crp)
           break;
 
         default:
-          error(EXIT_FAILURE, 0, "a bug! Please contact us at %s to fix the "
-                "problem. For some reason `counter' has become %zu in "
-                "`crop_write_to_log'", PACKAGE_BUGREPORT, counter);
+          error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s to fix "
+                "the problem. The value of %zu is not valid for `counter'",
+                __func__, PACKAGE_BUGREPORT, counter);
         }
     }
 }
@@ -233,7 +233,7 @@ imgmodecrop(void *inparam)
             {
               errno=0;
               if(unlink(crp->name))
-                error(EXIT_FAILURE, errno, "can't delet %s (center"
+                error(EXIT_FAILURE, errno, "can't delete %s (center"
                       "was blank)", crp->name);
             }
 
@@ -400,8 +400,8 @@ crop(struct cropparams *p)
   errno=0;
   crp=malloc(nt*sizeof *crp);
   if(crp==NULL)
-    error(EXIT_FAILURE, errno,
-          "%zu bytes in crop (crop.c) for crp", nt*sizeof *crp);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `crp'",
+          __func__, nt*sizeof *crp);
 
 
   /* Distribute the indexs into the threads (this is needed even if we
@@ -437,7 +437,8 @@ crop(struct cropparams *p)
             crp[i].indexs=&indexs[i*thrdcols];
             err=pthread_create(&t, &attr, modefunction, &crp[i]);
             if(err)
-              error(EXIT_FAILURE, 0, "can't create thread %zu", i);
+              error(EXIT_FAILURE, 0, "%s: can't create thread %zu",
+                    __func__, i);
           }
 
       /* Wait for all threads to finish and free the spaces. */
diff --git a/bin/crop/onecrop.c b/bin/crop/onecrop.c
index 3b818d0..ad1e2e4 100644
--- a/bin/crop/onecrop.c
+++ b/bin/crop/onecrop.c
@@ -335,12 +335,12 @@ polygonmask(struct onecropparams *crp, void *array, long 
*fpixel_i,
      anti-clickwise manner.) */
   errno=0; ipolygon=malloc(2*nvertices*sizeof *ipolygon);
   if(ipolygon==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for ipolygon in polygonmask "
-          "(crop.c)", 2*nvertices*sizeof *ipolygon);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for ipolygon",
+          __func__, 2*nvertices*sizeof *ipolygon);
   errno=0; ordinds=malloc(nvertices*sizeof *ordinds);
   if(ordinds==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for ordinds in polygonmask "
-          "(crop.c)", nvertices*sizeof *ordinds);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for ordinds",
+          __func__, nvertices*sizeof *ordinds);
 
 
   /* Find the order of the polygons and put the elements in the proper
@@ -368,10 +368,9 @@ polygonmask(struct onecropparams *crp, void *array, long 
*fpixel_i,
     case GAL_TYPE_FLOAT32:  POLYGON_MASK(float);    break;
     case GAL_TYPE_FLOAT64:  POLYGON_MASK(double);   break;
     default:
-      error(EXIT_FAILURE, 0, "a bug! Please contact us at %s, so we "
-            "can fix the problem. For some reason, an unrecognized "
-            "type value (%d) has been seen in polygonmask (crop.c)",
-            PACKAGE_BUGREPORT, type);
+      error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s, so we "
+            "can fix the problem. Type code %d is not recognized",
+            __func__, PACKAGE_BUGREPORT, type);
     }
 
   /* Clean up: */
@@ -423,8 +422,8 @@ changezerotonan(void *array, size_t size, int type)
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "%d is not a recognized type in "
-            "`changezerotonan'", type);
+      error(EXIT_FAILURE, 0, "%s: %d is not a recognized type",
+            __func__, type);
     }
 }
 
@@ -527,7 +526,7 @@ cropflpixel(struct onecropparams *crp)
           if(wcss2p(p->imgs[crp->in_ind].wcs, ncoord, nelem, crp->world,
                     phi, theta, imgcrd, pixcrd, status) )
             if(status[0] || status[1])
-              error(EXIT_FAILURE, 0, "wcss2p error %d: %s",
+              error(EXIT_FAILURE, 0, "%s: wcss2p error %d: %s", __func__,
                     status[0] ? status[0] : status[1],
                     wcs_errmsg[status[0] ? status[0] : status[1]]);
           gal_box_border_from_center(pixcrd[0], pixcrd[1], p->iwidth, fpixel,
@@ -540,9 +539,9 @@ cropflpixel(struct onecropparams *crp)
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "a bug! in cropflpixel (crop.c), "
-            "neither imgmode or wcsmode are set. Please contact us so "
-            "we can see how it got to this impossible place");
+      error(EXIT_FAILURE, 0, "%s: a bug! The domain (WCS or image) are not "
+            "set. Please contact us at %s so we can see how it got to this "
+            "impossible place", __func__, PACKAGE_BUGREPORT);
     }
 
   /* If the user only wants regions outside to the polygon, then set
diff --git a/bin/fits/fits.c b/bin/fits/fits.c
index 4518b81..7a3c5d4 100644
--- a/bin/fits/fits.c
+++ b/bin/fits/fits.c
@@ -56,15 +56,15 @@ fits_has_error(struct fitsparams *p, int actioncode, char 
*string, int status)
     case FITS_ACTION_REMOVE:        action="renoved";      break;
 
     default:
-      error(EXIT_FAILURE, 0, "a bug! Please contact us at `%s' so we can fix "
-            "this problem. In `header.c'. The value of actionid in "
-            "`haserror' must not be %d", PACKAGE_BUGREPORT, actioncode);
+      error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at `%s' so we "
+            "can fix this problem. The value of `actioncode' must not be %d",
+            __func__, PACKAGE_BUGREPORT, actioncode);
     }
 
   if(p->quitonerror)
     {
       fits_report_error(stderr, status);
-      error(EXIT_FAILURE, 0, "not %s: %s\n", action, string);
+      error(EXIT_FAILURE, 0, "%s: not %s: %s\n", __func__, action, string);
     }
   else
     {
@@ -151,8 +151,8 @@ fits_print_extension_info(struct fitsparams *p)
           break;
 
         default:
-          error(EXIT_FAILURE, 0, "a bug! the `hdutype' code %d not "
-                "recognized", hdutype);
+          error(EXIT_FAILURE, 0, "%s: a bug! the `hdutype' code %d not "
+                "recognized", __func__, hdutype);
         }
 
 
@@ -345,10 +345,9 @@ fits(struct fitsparams *p)
 
     /* Not recognized. */
     default:
-      error(EXIT_FAILURE, 0, "a bug! please contact us at %s to address "
-            "the problem. The code %d is not recognized for p->mode in the "
-            "`fits' function of the Fits program", PACKAGE_BUGREPORT,
-            p->mode);
+      error(EXIT_FAILURE, 0, "%s: a bug! please contact us at %s to address "
+            "the problem. The code %d is not recognized for p->mode",
+            __func__, PACKAGE_BUGREPORT, p->mode);
     }
 
   return r;
diff --git a/bin/fits/keywords.c b/bin/fits/keywords.c
index ac507f1..36944e6 100644
--- a/bin/fits/keywords.c
+++ b/bin/fits/keywords.c
@@ -176,9 +176,9 @@ keywords_write_update(struct fitsparams *p, fitsfile **fptr,
             gal_fits_io_error(status, NULL);
         }
       else
-        error(EXIT_FAILURE, 0, "a bug! Please contact us at `%s' so we can "
-              "fix this problem. In `header.c'. The value of u1w2 in "
-              "writeupdatekeys must not be %d\n", PACKAGE_BUGREPORT, u1w2);
+        error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at `%s' so we "
+              "can fix this problem. The value %d is not valid for `u1w2'",
+              __func__, PACKAGE_BUGREPORT, u1w2);
 
       /* Add the unit (if one was given). */
       if(keyll->unit
diff --git a/bin/fits/ui.c b/bin/fits/ui.c
index 99fdb96..f232e81 100644
--- a/bin/fits/ui.c
+++ b/bin/fits/ui.c
@@ -328,7 +328,8 @@ ui_fill_fits_headerll(gal_list_str_t *input, struct 
gal_fits_key_ll **output)
       errno=0;
       original=malloc(strlen(tmp->v)+1);
       if(original==NULL)
-        error(EXIT_FAILURE, errno, "space for c in setuprename");
+        error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `original'",
+              __func__, strlen(tmp->v)+1);
       strcpy(original, tmp->v);
 
       /* Tokenize the input. Note that strlen does not include the \0
@@ -392,8 +393,8 @@ ui_fill_fits_headerll(gal_list_str_t *input, struct 
gal_fits_key_ll **output)
           errno=0;
           fvalue=lp=malloc(sizeof *lp);
           if(lp==NULL)
-            error(EXIT_FAILURE, errno, "%zu bytes for long integer",
-                  sizeof *lp);
+            error(EXIT_FAILURE, errno, "%s: %zu bytes for `lp'",
+                  __func__, sizeof *lp);
           *lp=l;
         }
       else
@@ -407,8 +408,8 @@ ui_fill_fits_headerll(gal_list_str_t *input, struct 
gal_fits_key_ll **output)
               errno=0;
               fvalue=dp=malloc(sizeof *dp);
               if(dp==NULL)
-                error(EXIT_FAILURE, errno, "%zu bytes for double",
-                      sizeof *dp);
+                error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `dp'",
+                      __func__, sizeof *dp);
               *dp=d;
             }
           else
diff --git a/bin/mkcatalog/columns.c b/bin/mkcatalog/columns.c
index a5ad6e0..94a867c 100644
--- a/bin/mkcatalog/columns.c
+++ b/bin/mkcatalog/columns.c
@@ -60,8 +60,8 @@ columns_alloc_radec(struct mkcatalogparams *p)
       errno=0;
       p->rd_vo = malloc(p->input->ndim * sizeof *p->rd_vo);
       if(p->rd_vo==NULL)
-        error(EXIT_FAILURE, 0, "%zu bytes for p->rd_vo, "
-              "`columns_alloc_radec'", p->input->ndim * sizeof *p->rd_vo );
+        error(EXIT_FAILURE, 0, "%s: allocating %zu bytes for p->rd_vo",
+              __func__, p->input->ndim * sizeof *p->rd_vo );
 
       /* Space for each dimension. */
       p->rd_vo[0] = gal_data_malloc_array(GAL_TYPE_FLOAT64, p->numobjects);
@@ -72,9 +72,8 @@ columns_alloc_radec(struct mkcatalogparams *p)
           errno=0;
           p->rd_vc = malloc(p->input->ndim * sizeof *p->rd_vc);
           if(p->rd_vc==NULL)
-            error(EXIT_FAILURE, 0, "%zu bytes for p->rd_vo, "
-                  "`columns_alloc_radec'",
-                  p->input->ndim * sizeof *p->rd_vc );
+            error(EXIT_FAILURE, 0, "%s: allocating %zu bytes for p->rd_vo",
+                  __func__, p->input->ndim * sizeof *p->rd_vc );
 
           /* Space for each dimension. */
           p->rd_vc[0]=gal_data_malloc_array(GAL_TYPE_FLOAT64, p->numclumps);
@@ -97,8 +96,8 @@ columns_alloc_georadec(struct mkcatalogparams *p)
       errno=0;
       p->rd_go = malloc(p->input->ndim * sizeof *p->rd_go);
       if(p->rd_go==NULL)
-        error(EXIT_FAILURE, 0, "%zu bytes for p->rd_go, "
-              "`columns_alloc_radec'", p->input->ndim * sizeof *p->rd_go );
+        error(EXIT_FAILURE, 0, "%s: allocating %zu bytes for `p->rd_go'",
+              __func__, p->input->ndim * sizeof *p->rd_go );
 
       /* Space for each dimension. */
       p->rd_go[0] = gal_data_malloc_array(GAL_TYPE_FLOAT64, p->numobjects);
@@ -109,9 +108,8 @@ columns_alloc_georadec(struct mkcatalogparams *p)
           errno=0;
           p->rd_gc = malloc(p->input->ndim * sizeof *p->rd_gc);
           if(p->rd_gc==NULL)
-            error(EXIT_FAILURE, 0, "%zu bytes for p->rd_go, "
-                  "`columns_alloc_radec'",
-                  p->input->ndim * sizeof *p->rd_gc );
+            error(EXIT_FAILURE, 0, "%s: allocating %zu bytes for `p->rd_go'",
+                  __func__, p->input->ndim * sizeof *p->rd_gc );
 
           /* Space for each dimension. */
           p->rd_gc[0]=gal_data_malloc_array(GAL_TYPE_FLOAT64, p->numclumps);
@@ -134,8 +132,8 @@ columns_alloc_clumpsradec(struct mkcatalogparams *p)
       errno=0;
       p->rd_vcc = malloc(p->input->ndim * sizeof *p->rd_vcc);
       if(p->rd_vcc==NULL)
-        error(EXIT_FAILURE, 0, "%zu bytes for p->rd_vcc, "
-              "`columns_alloc_radec'", p->input->ndim * sizeof *p->rd_vcc );
+        error(EXIT_FAILURE, 0, "%s: allocating %zu bytes for `p->rd_vcc'",
+              __func__, p->input->ndim * sizeof *p->rd_vcc );
 
       /* Space for each dimension. */
       p->rd_vcc[0] = gal_data_malloc_array(GAL_TYPE_FLOAT64, p->numobjects);
@@ -157,8 +155,8 @@ columns_alloc_clumpsgeoradec(struct mkcatalogparams *p)
       errno=0;
       p->rd_gcc = malloc(p->input->ndim * sizeof *p->rd_gcc);
       if(p->rd_gcc==NULL)
-        error(EXIT_FAILURE, 0, "%zu bytes for p->rd_gcc, "
-              "`columns_alloc_radec'", p->input->ndim * sizeof *p->rd_gcc );
+        error(EXIT_FAILURE, 0, "%s: allocating %zu bytes for `p->rd_gcc'",
+              __func__, p->input->ndim * sizeof *p->rd_gcc );
 
       /* Space for each dimension. */
       p->rd_gcc[0] = gal_data_malloc_array(GAL_TYPE_FLOAT64, p->numobjects);
@@ -867,10 +865,9 @@ columns_define_alloc(struct mkcatalogparams *p)
           break;
 
         default:
-          error(EXIT_FAILURE, 0, "a bug! please contact us at %s to fix the "
-                "problem. The code %d is not an internally recognized "
-                "column code, this is due to some mistake in the programming",
-                PACKAGE_BUGREPORT, colcode->v);
+          error(EXIT_FAILURE, 0, "%s: a bug! please contact us at %s to fix "
+                "the problem. The code %d is not an internally recognized "
+                "column code", __func__, PACKAGE_BUGREPORT, colcode->v);
         }
 
       /* If this is an objects column, add it to the list of columns. We
@@ -1060,8 +1057,8 @@ columns_second_order(struct mkcatalog_passparams *pp, 
double *row,
 
     /* Error. */
     default:
-      error(EXIT_FAILURE, 0, "a bug! Code %d not a recognized key in "
-            "`columns_second_order'", key);
+      error(EXIT_FAILURE, 0, "%s: a bug! Code %d not a recognized key",
+            __func__, key);
     }
 
   /* Return the output. */
@@ -1089,9 +1086,9 @@ columns_second_order(struct mkcatalog_passparams *pp, 
double *row,
 
   /* Control should not reach here! If it does, its a bug, so abort and let
      the user know. */
-  error(EXIT_FAILURE, 0, "a bug! control has reached the end of "
-        "`columns_second_order' (which should not have happened). Please "
-        "contact us at %s, so we can address the problem", PACKAGE_BUGREPORT);
+  error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s, so we can "
+        "address the problem. Control should not have reached the end of "
+        "this function", __func__, PACKAGE_BUGREPORT);
   return NAN;
 }
 
@@ -1309,10 +1306,9 @@ columns_fill(struct mkcatalog_passparams *pp)
           break;
 
         default:
-          error(EXIT_FAILURE, 0, "a bug! the output column code %d not "
-                "recognized in `mkcatalog_fill_output_columns' (for "
-                "objects). Please contact us at %s to solve the problem",
-                key, PACKAGE_BUGREPORT);
+          error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s to "
+                "solve the problem. the output column code %d not recognized "
+                "(for objects). ", __func__, PACKAGE_BUGREPORT, key);
         }
     }
 
@@ -1461,10 +1457,10 @@ columns_fill(struct mkcatalog_passparams *pp)
             break;
 
           default:
-            error(EXIT_FAILURE, 0, "a bug! the output column code %d not "
-                  "recognized in `mkcatalog_fill_output_columns' (for "
-                  "clumps). Please contact us at %s to solve the problem",
-                  key, PACKAGE_BUGREPORT);
+            error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s to "
+                  "solve the problem. The output column code %d not "
+                  "recognized (for clumps). ", __func__, PACKAGE_BUGREPORT,
+                  key);
           }
       }
 }
diff --git a/bin/mkprof/mkprof.c b/bin/mkprof/mkprof.c
index 4ca9da2..7db17e8 100644
--- a/bin/mkprof/mkprof.c
+++ b/bin/mkprof/mkprof.c
@@ -75,8 +75,8 @@ builtqueue_addempty(struct builtqueue **bq)
   errno=0;
   tbq=malloc(sizeof *tbq);
   if(tbq==NULL)
-    error(EXIT_FAILURE, 0, "%zu byte element in builtqueue_addempty",
-          sizeof *tbq);
+    error(EXIT_FAILURE, 0, "%s: allocating %zu bytes for `tbq'",
+          __func__, sizeof *tbq);
 
   /* Initialize some of the values. */
   tbq->img=NULL;
@@ -575,8 +575,8 @@ mkprof(struct mkprofparams *p)
   errno=0;
   mkp=malloc(nt*sizeof *mkp);
   if(mkp==NULL)
-    error(EXIT_FAILURE, errno,
-          "%zu bytes in mkprof (mkprof.c) for mkp", (nt-1)*sizeof *mkp);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `mkp'",
+          __func__, (nt-1)*sizeof *mkp);
 
   /* Distribute the different profiles for different threads. Note
      that one thread is left out for writing, while nt-1 are left
@@ -607,9 +607,10 @@ mkprof(struct mkprofparams *p)
 
       /* Initialize the condition variable and mutex. */
       err=pthread_mutex_init(&p->qlock, NULL);
-      if(err) error(EXIT_FAILURE, 0, "mutex not initialized");
+      if(err) error(EXIT_FAILURE, 0, "%s: mutex not initialized", __func__);
       err=pthread_cond_init(&p->qready, NULL);
-      if(err) error(EXIT_FAILURE, 0, "condition variable not initialized");
+      if(err) error(EXIT_FAILURE, 0, "%s: condition variable not initialized",
+                    __func__);
 
       /* Spin off the threads: */
       for(i=0;i<nt;++i)
@@ -623,7 +624,8 @@ mkprof(struct mkprofparams *p)
             mkp[i].indexs=&indexs[i*thrdcols];
             err=pthread_create(&t, &attr, mkprof_build, &mkp[i]);
             if(err)
-              error(EXIT_FAILURE, 0, "can't create thread %zu", i);
+              error(EXIT_FAILURE, 0, "%s: can't create thread %zu",
+                    __func__, i);
           }
     }
 
diff --git a/bin/mkprof/oneprofile.c b/bin/mkprof/oneprofile.c
index 295651f..6ffa274 100644
--- a/bin/mkprof/oneprofile.c
+++ b/bin/mkprof/oneprofile.c
@@ -510,10 +510,9 @@ oneprof_set_prof_params(struct mkonthread *mkp)
 
 
     default:
-      error(EXIT_FAILURE, 0, "a bug in setprofparams (oneprofile.c)! "
-            "The profile code is not recognized. This should have been "
-            "seen and reported prior to this step. Please contact us so "
-            "we can correct this");
+      error(EXIT_FAILURE, 0, "%s: a bug! Please contact us so we can correct "
+            "this problem. The profile code %d is not recognized.", __func__,
+            mkp->func);
     }
 }
 
@@ -575,7 +574,8 @@ oneprofile_make(struct mkonthread *mkp)
   size=mkp->width[0]*mkp->width[1];
   mkp->ibq->img=calloc(size, sizeof *mkp->ibq->img);
   if(mkp->ibq->img==NULL)
-    error(EXIT_FAILURE, 0, "%zu bytes for object in row %zu of data in %s",
+    error(EXIT_FAILURE, 0, "%s: allocating %zu bytes for object in row %zu of "
+          "data in %s", __func__,
           size*sizeof *mkp->ibq->img, mkp->ibq->id, p->catname);
 
 
diff --git a/bin/noisechisel/clumps.c b/bin/noisechisel/clumps.c
index 164c503..6f81a3b 100644
--- a/bin/noisechisel/clumps.c
+++ b/bin/noisechisel/clumps.c
@@ -147,10 +147,10 @@ clumps_oversegment(struct clumps_thread_params *cltprm)
 
             /* A small sanity check. */
             if(Q!=NULL || cleanup!=NULL)
-              error(EXIT_FAILURE, 0, "a bug! Please contact us at %s so we "
-                    "can fix this problem. In `clumps_oversegment', `Q' and "
-                    "`cleanup' should be NULL but while checking the equal"
-                    "flux regions they aren't", PACKAGE_BUGREPORT);
+              error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we 
"
+                    "can fix this problem. `Q' and `cleanup' should be NULL "
+                    "but while checking the equal flux regions they aren't",
+                    __func__, PACKAGE_BUGREPORT);
 
             /* Add this pixel to a queue. */
             gal_list_sizet_add(&Q, *a);
@@ -927,9 +927,9 @@ clumps_correct_sky_labels_for_check(struct 
clumps_thread_params *cltprm,
 
   /* A small sanity check. */
   if(gal_tile_block(tile)!=p->clabel)
-    error(EXIT_FAILURE, 0, "a bug! the tile->block' must point to the "
-          "`clabel' dataset. Please contact us at %s to address the "
-          "problem, thank you", PACKAGE_BUGREPORT);
+    error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s to address the "
+          "problem. `tile->block' must point to the `clabel' dataset",
+          __func__, PACKAGE_BUGREPORT);
 
 
   /* Allocate a dataset with the new indexs, note that it will need to have
@@ -1238,10 +1238,9 @@ clumps_true_find_sn_thresh(struct noisechiselparams *p)
             case 1: p->clabel->name = "SKY_CLUMPS_ALL";  break;
             case 2: p->clabel->name = "SKY_CLUMPS_FOR_SN";   break;
             default:
-              error(EXIT_FAILURE, 0, "a bug! the value %d is not recognized "
-                    "in `clumps_true_find_sn_thresh'. Please contact us at "
-                    "%s so we can address the issue", clprm.step,
-                    PACKAGE_BUGREPORT);
+              error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so "
+                    "we can address the issue. The value %d is not valid for "
+                    "clprm.step", __func__, PACKAGE_BUGREPORT, clprm.step);
             }
 
           /* Write the demonstration array into the check image. The
diff --git a/bin/noisechisel/detection.c b/bin/noisechisel/detection.c
index 37de617..fc7aaaf 100644
--- a/bin/noisechisel/detection.c
+++ b/bin/noisechisel/detection.c
@@ -339,10 +339,9 @@ detection_pseudo_find(struct noisechiselparams *p, 
gal_data_t *workbin,
               bin->name="OPENED";
               break;
             default:
-              error(EXIT_FAILURE, 0, "a bug! the value %d is not recognized "
-                    "in `detection_pseudo_find'. Please contact us at %s so "
-                    "we can address the issue", fho_prm.step,
-                    PACKAGE_BUGREPORT);
+              error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so "
+                    "we can address the issue. the value %d is not "
+                    "recognized.", __func__, PACKAGE_BUGREPORT, fho_prm.step);
             }
 
           /* Write the temporary array into the check image. */
@@ -449,16 +448,15 @@ detection_sn(struct noisechiselparams *p, gal_data_t 
*worklab, size_t num,
 
   /* Sanity check. */
   if(p->input->type!=GAL_TYPE_FLOAT32)
-    error(EXIT_FAILURE, 0, "the input dataset to `detection_sn' "
-          "must be float32 type, it is %s",
-          gal_type_to_string(p->input->type, 1));
+    error(EXIT_FAILURE, 0, "%s: the input dataset must be float32 type, "
+          "it is %s", __func__, gal_type_to_string(p->input->type, 1));
   if(!isnan(GAL_BLANK_FLOAT32))
-    error(EXIT_FAILURE, 0, "currently `detection_sn' only "
-          "recognizes a NaN value for blank floating point data types, the "
-          "blank value is defined to be %f", GAL_BLANK_FLOAT32);
+    error(EXIT_FAILURE, 0, "%s: only a NaN value is recognized for blank "
+          "floating point data types, the blank value is defined to be %f",
+          __func__, GAL_BLANK_FLOAT32);
   if(ndim!=2)
-    error(EXIT_FAILURE, 0, "currently `detection_sn' only "
-          "works on 2D datasets, your input is %zu dimensions", ndim);
+    error(EXIT_FAILURE, 0, "%s: only 2D datasets are acceptable, your input "
+          "is %zu dimensions", __func__, ndim);
 
 
   /* Allocate all the necessary arrays, note that since we want to put each
diff --git a/bin/noisechisel/segmentation.c b/bin/noisechisel/segmentation.c
index 782a3ab..ddba01d 100644
--- a/bin/noisechisel/segmentation.c
+++ b/bin/noisechisel/segmentation.c
@@ -725,10 +725,9 @@ segmentation_detections(struct noisechiselparams *p)
               break;
 
             default:
-              error(EXIT_FAILURE, 0, "a bug! the value %d is not recognized "
-                    "in `segmentation_detections'. Please contact us at "
-                    "%s so we can address the issue", clprm.step,
-                    PACKAGE_BUGREPORT);
+              error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so "
+                    "we can address the issue. The value %d is not recognized "
+                    "for clprm.step", __func__, PACKAGE_BUGREPORT, clprm.step);
             }
 
           /* Write the demonstration array into the check image. The
diff --git a/bin/noisechisel/sky.c b/bin/noisechisel/sky.c
index b90ddf8..96e6f24 100644
--- a/bin/noisechisel/sky.c
+++ b/bin/noisechisel/sky.c
@@ -240,8 +240,9 @@ sky_subtract(struct noisechiselparams *p)
 
   /* A small sanity check. */
   if(p->sky->type!=GAL_TYPE_FLOAT32)
-    error(EXIT_FAILURE, 0, "`sky_subtract' currently only works on float32 "
-          "type sky values.");
+    error(EXIT_FAILURE, 0, "%s: only `float32' type is acceptable "
+          "for sky values. but `p->sky' has type `%s'", __func__,
+          gal_type_to_string(p->sky->type, 1));
 
   /* Go over all the tiles. */
   for(tid=0; tid<p->cp.tl.tottiles; ++tid)
diff --git a/bin/noisechisel/threshold.c b/bin/noisechisel/threshold.c
index a765553..a555164 100644
--- a/bin/noisechisel/threshold.c
+++ b/bin/noisechisel/threshold.c
@@ -137,10 +137,9 @@ threshold_apply_on_thread(void *in_prm)
 
 
         default:
-          error(EXIT_FAILURE, 0, "a bug! please contact us at %s so we can "
-                "address the problem. For some reason a value of %d had "
-                "been given to `type' in `threshold_apply'",
-                PACKAGE_BUGREPORT, taprm->kind);
+          error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we can 
"
+                "address the problem. A value of %d had for `taprm->kind' "
+                "is not valid", __func__, PACKAGE_BUGREPORT, taprm->kind);
         }
     }
 
@@ -256,8 +255,8 @@ threshold_interp_smooth(struct noisechiselparams *p, 
gal_data_t **first,
 
   /* A small sanity check. */
   if( (*first)->next )
-    error(EXIT_FAILURE, 0, "the `first' argument to "
-          "`threshold_interp_smooth' must not have any `next' pointer.");
+    error(EXIT_FAILURE, 0, "%s: the `first' argument to must not have any "
+          "`next' pointer.", __func__);
 
 
   /* Do the interpolation of both arrays. */
diff --git a/bin/statistics/statistics.c b/bin/statistics/statistics.c
index 3636d84..3502157 100644
--- a/bin/statistics/statistics.c
+++ b/bin/statistics/statistics.c
@@ -73,10 +73,9 @@ statistics_read_check_args(struct statisticsparams *p)
 {
   double d;
   if(p->tp_args==NULL)
-    error(EXIT_FAILURE, 0, "a bug! Not enough arguments for the "
-          "requested single measurement options. Please contact "
-          "us at %s so we can address the problem",
-          PACKAGE_BUGREPORT);
+    error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we can "
+          "address the problem. Not enough arguments for the requested "
+          "single measurement options", __func__, PACKAGE_BUGREPORT);
   d=gal_list_f64_pop(&p->tp_args);
   return d;
 }
@@ -137,9 +136,9 @@ statistics_print_one_row(struct statisticsparams *p)
 
       /* The option isn't recognized. */
       default:
-        error(EXIT_FAILURE, 0, "A bug! Operation code %d not recognized in "
-              "`statistics_print_one_row'. Please contact us at %s so we "
-              "can address the problem", tmp->v, PACKAGE_BUGREPORT);
+        error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we "
+              "can address the problem. Operation code %d not recognized",
+              __func__, PACKAGE_BUGREPORT, tmp->v);
       }
 
 
@@ -302,8 +301,8 @@ statistics_on_tile(struct statisticsparams *p)
           type=GAL_TYPE_FLOAT64; break;
 
         default:
-          error(EXIT_FAILURE, 0, "a bug! %d is not a recognized operation "
-                "code in `statistics_on_tile'", operation->v);
+          error(EXIT_FAILURE, 0, "%s: a bug! %d is not a recognized operation "
+                "code", __func__, operation->v);
         }
 
       /* Allocate the space necessary to keep the value for each tile. */
@@ -377,10 +376,9 @@ statistics_on_tile(struct statisticsparams *p)
               break;
 
             default:
-              error(EXIT_FAILURE, 0, "a bug! please contact us at %s to "
-                    "fix the problem. THe operation code %d is not "
-                    "recognized in `statistics_on_tile'", PACKAGE_BUGREPORT,
-                    operation->v);
+              error(EXIT_FAILURE, 0, "%s: a bug! please contact us at %s to "
+                    "fix the problem. The operation code %d is not "
+                    "recognized", __func__, PACKAGE_BUGREPORT, operation->v);
             }
 
           /* Put the output value into the `values' array and clean up. */
@@ -672,7 +670,8 @@ print_mirror_hist_cfp(struct statisticsparams *p)
     write_output_table(p, table, "_mirror_hist_cfp",
                        "Histogram and CFP of mirror distribution");
   else
-    error(EXIT_FAILURE, 0, "mirror value %g is out of range", p->mirror);
+    error(EXIT_FAILURE, 0, "%s: mirror value %g is out of range",
+          __func__, p->mirror);
 }
 
 
diff --git a/bin/warp/warp.c b/bin/warp/warp.c
index 1508b9c..ba9eaf7 100644
--- a/bin/warp/warp.c
+++ b/bin/warp/warp.c
@@ -508,8 +508,8 @@ warp(struct warpparams *p)
   errno=0;
   iwp=malloc(nt*sizeof *iwp);
   if(iwp==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes in warp (warp.c) for iwp",
-          nt*sizeof *iwp);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for iwp",
+          __func__, nt*sizeof *iwp);
 
 
   /* Prepare the output array and all the necessary things: */
@@ -546,7 +546,8 @@ warp(struct warpparams *p)
             iwp[i].indexs=&indexs[i*thrdcols];
             err=pthread_create(&t, &attr, warponthread, &iwp[i]);
             if(err)
-              error(EXIT_FAILURE, 0, "can't create thread %zu", i);
+              error(EXIT_FAILURE, 0, "%s: can't create thread %zu",
+                    __func__, i);
           }
 
       /* Wait for all threads to finish and free the spaces. */
diff --git a/bootstrap.conf b/bootstrap.conf
index d98e28e..790ded0 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -212,6 +212,7 @@ bootstrap_epilogue()
 # gnulib modules used by this package.
 gnulib_modules="
     fdl
+    func
     math
     argp
     regex
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index a564cb3..1e7a97f 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -550,6 +550,7 @@ Data container (@file{data.h})
 * Generic data container::
 * Dataset size and allocation::
 * Arrays of datasets::
+* Copying datasets::
 
 Linked lists (@file{linkedlist.h})
 
@@ -17043,6 +17044,7 @@ generic dataset, Gnuastro defines the @code{gal_data_t} 
as input or output.
 * Generic data container::
 * Dataset size and allocation::
 * Arrays of datasets::
+* Copying datasets::
 @end menu
 
 @node Generic data container, Dataset size and allocation, Library data 
container, Library data container
@@ -17467,7 +17469,7 @@ Free all the address@hidden pointers in 
@code{gal_data_t}, then free the
 actual data structure.
 @end deftypefun
 
address@hidden Arrays of datasets,  , Dataset size and allocation, Library data 
container
address@hidden Arrays of datasets, Copying datasets, Dataset size and 
allocation, Library data container
 @subsubsection Arrays of datasets
 
 Gnuastro's generic data container (@code{gal_data_t}) is a very versatile
@@ -17509,6 +17511,19 @@ element of all the datasets will also be freed, see 
@ref{Generic data
 container}.
 @end deftypefun
 
address@hidden Copying datasets,  , Arrays of datasets, Library data container
address@hidden Copying datasets
+
+The functions in this section describes Gnuastro's facilities to copy a
+given datset into another. The new dataset can have a different type
+(including a string), it can be already allocated (in which case only the
+values will be written into it). In all these cases, if the input dataset
+is a tile, only the data within the tile are copied.
+
address@hidden {gal_data_t *} gal_data_copy (gal_data_t @code{*in})
+Return a new dataset that is a copy of @code{in}.
address@hidden deftypefun
+
 @node Linked lists, Table input output, Library data container, Gnuastro 
library
 @subsection Linked lists (@file{linkedlist.h})
 
diff --git a/lib/arithmetic-binary.c b/lib/arithmetic-binary.c
index 2ed3f46..886537e 100644
--- a/lib/arithmetic-binary.c
+++ b/lib/arithmetic-binary.c
@@ -274,8 +274,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
       BINARY_OP_INCR_OT_RT_LT_SET(||, uint8_t, RT, LT);            \
       break;                                                       \
     default:                                                       \
-      error(EXIT_FAILURE, 0, "operator code %d not recognized in " \
-            "`BINARY_RT_LT_SET", operator);                        \
+      error(EXIT_FAILURE, 0, "%s: operator code %d not recognized",\
+            "BINARY_RT_LT_SET", operator);                         \
     }
 
 
@@ -298,8 +298,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
       BINARY_LT_SET_RT_IS_FLOAT32(LT);                             \
       BINARY_LT_SET_RT_IS_FLOAT64(LT);                             \
     default:                                                       \
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "     \
-            "`BINARY_LT_SET'", r->type);                           \
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",    \
+            "BINARY_LT_SET", r->type);                             \
     }
 
 
@@ -339,8 +339,9 @@ arithmetic_binary(int operator, uint8_t flags, gal_data_t 
*lo,
   /* Simple sanity check on the input sizes */
   if( !( (flags & GAL_ARITHMETIC_NUMOK) && (lo->size==1 || ro->size==1))
       && gal_data_dsize_is_different(lo, ro) )
-    error(EXIT_FAILURE, 0, "the non-number inputs to %s don't have the "
-          "same dimension/size", gal_arithmetic_operator_string(operator));
+    error(EXIT_FAILURE, 0, "%s: the non-number inputs to %s don't have the "
+          "same dimension/size", __func__,
+          gal_arithmetic_operator_string(operator));
 
 
   /* Set the final output type (independent of which types are
@@ -408,8 +409,8 @@ arithmetic_binary(int operator, uint8_t flags, gal_data_t 
*lo,
       BINARY_LT_IS_FLOAT32;
       BINARY_LT_IS_FLOAT64;
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`arithmetic_binary'", l->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, l->type);
     }
 
 
diff --git a/lib/arithmetic-onlyint.c b/lib/arithmetic-onlyint.c
index 028385f..b776496 100644
--- a/lib/arithmetic-onlyint.c
+++ b/lib/arithmetic-onlyint.c
@@ -215,8 +215,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
       BINOIN_OP_RT_LT_SET(>>, RT, LT);                             \
       break;                                                       \
     default:                                                       \
-      error(EXIT_FAILURE, 0, "operator code %d not recognized in " \
-            "`BINOIN_RT_LT_SET", operator);                        \
+      error(EXIT_FAILURE, 0, "%s: operator code %d not recognized",\
+            "BINOIN_RT_LT_SET", operator);                         \
     }
 
 
@@ -237,8 +237,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
       BINOIN_LT_SET_RT_IS_UINT64(LT);                              \
       BINOIN_LT_SET_RT_IS_INT64(LT);                               \
     default:                                                       \
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "     \
-            "`BINOIN_LT_SET'", r->type);                           \
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",    \
+            "BINOIN_LT_SET", r->type);                             \
     }
 
 
@@ -279,13 +279,13 @@ arithmetic_onlyint_binary(int operator, unsigned char 
flags,
   /* Simple sanity check on the input sizes and types */
   if( !( (flags & GAL_ARITHMETIC_NUMOK) && (lo->size==1 || ro->size==1))
       && gal_data_dsize_is_different(lo, ro) )
-    error(EXIT_FAILURE, 0, "the non-number inputs to %s don't have the "
-          "same dimension/size", opstring);
+    error(EXIT_FAILURE, 0, "%s: the non-number inputs to %s don't have the "
+          "same dimension/size", __func__, opstring);
 
   if( lo->type==GAL_TYPE_FLOAT32 || lo->type==GAL_TYPE_FLOAT64
       || ro->type==GAL_TYPE_FLOAT32 || ro->type==GAL_TYPE_FLOAT64 )
-      error(EXIT_FAILURE, 0, "the %s operator can only work on integer "
-            "type operands", opstring);
+      error(EXIT_FAILURE, 0, "%s: the %s operator can only work on integer "
+            "type operands", __func__, opstring);
 
 
   /* Set the final output type (independent of which types are
@@ -362,8 +362,8 @@ arithmetic_onlyint_binary(int operator, unsigned char flags,
       BINOIN_LT_IS_UINT64;
       BINOIN_LT_IS_INT64;
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`arithmetic_onlyint_binary'", l->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, l->type);
     }
 
 
@@ -425,8 +425,8 @@ arithmetic_onlyint_bitwise_not(unsigned char flags, 
gal_data_t *in)
     {
     case GAL_TYPE_FLOAT32:
     case GAL_TYPE_FLOAT64:
-      error(EXIT_FAILURE, 0, "the bitwise not (one's complement) "
-            "operator can only work on integer types");
+      error(EXIT_FAILURE, 0, "%s: bitwise not (one's complement) "
+            "operator can only work on integer types", __func__);
     }
 
   /* If we want inplace output, set the output pointer to the input
@@ -465,8 +465,8 @@ arithmetic_onlyint_bitwise_not(unsigned char flags, 
gal_data_t *in)
       oi64=o->array;  do *oi64++ = ~(*ii64++);   while(ii64<ii64f);   break;
 
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "data_arithmetic_bitwise_not", in->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, in->type);
     }
 
 
diff --git a/lib/arithmetic.c b/lib/arithmetic.c
index 252e0a6..7055de8 100644
--- a/lib/arithmetic.c
+++ b/lib/arithmetic.c
@@ -65,8 +65,8 @@ arithmetic_change_type(gal_data_t *data, int operator, 
unsigned char flags)
     case GAL_ARITHMETIC_OP_TO_FLOAT32:  type=GAL_TYPE_FLOAT32;  break;
     case GAL_ARITHMETIC_OP_TO_FLOAT64:  type=GAL_TYPE_FLOAT64;  break;
     default:
-      error(EXIT_FAILURE, 0, "operator value of %d not recognized in "
-            "`arithmetic_change_type'", operator);
+      error(EXIT_FAILURE, 0, "%s: operator value of %d not recognized",
+            __func__, operator);
     }
 
   /* Copy to the new type. */
@@ -119,12 +119,12 @@ arithmetic_not(gal_data_t *data, unsigned char flags)
     case GAL_TYPE_FLOAT64: TYPE_CASE_FOR_NOT(double);    break;
 
     case GAL_TYPE_BIT:
-      error(EXIT_FAILURE, 0, "Currently Gnuastro doesn't support bit "
-            "datatype, please get in touch with us to implement it.");
+      error(EXIT_FAILURE, 0, "%s: bit datatypes are not yet supported, "
+            "please get in touch with us to implement it.", __func__);
 
     default:
-      error(EXIT_FAILURE, 0, "type value (%d) not recognized "
-            "in `arithmetic_not'", data->type);
+      error(EXIT_FAILURE, 0, "%s: type value (%d) not recognized",
+            __func__, data->type);
     }
 
   /* Delete the input structure if the user asked for it. */
@@ -184,8 +184,8 @@ arithmetic_abs(unsigned char flags, gal_data_t *in)
     case GAL_TYPE_FLOAT32: ARITHMETIC_ABS_SGN( float,   fabsf );  break;
     case GAL_TYPE_FLOAT64: ARITHMETIC_ABS_SGN( double,  fabs  );  break;
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`arithmetic_abs'", in->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, in->type);
     }
 
   /* Clean up and return */
@@ -308,8 +308,8 @@ arithmetic_check_float_input(gal_data_t *in, int operator, 
char *numstr)
       UNIFUNC_RUN_FUNCTION_ON_ELEMENT(double, OP)                       \
       break;                                                            \
     default:                                                            \
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "          \
-            "`UNIFUNC_PER_ELEMENT'", in->type);                         \
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",         \
+            "UNIARY_FUNCTION_ON_ELEMENT", in->type);                    \
     }
 
 
@@ -345,8 +345,8 @@ arithmetic_unary_function(int operator, unsigned char 
flags, gal_data_t *in)
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "operator code %d not recognized in "
-            "arithmetic_unary_function", operator);
+      error(EXIT_FAILURE, 0, "%s: operator code %d not recognized",
+            __func__, operator);
     }
 
 
@@ -412,9 +412,8 @@ arithmetic_unary_function(int operator, unsigned char 
flags, gal_data_t *in)
       BINFUNC_RUN_FUNCTION(double, RT, LT, OP);                         \
       break;                                                            \
     default:                                                            \
-      error(EXIT_FAILURE, 0, "type %d not recognized in "               \
-            "for o->type in BINFUNC_F_OPERATOR_LEFT_RIGHT_SET",         \
-            o->type);                                                   \
+      error(EXIT_FAILURE, 0, "%s: type %d not recognized for o->type ", \
+            "BINFUNC_F_OPERATOR_LEFT_RIGHT_SET", o->type);              \
     }
 
 
@@ -431,8 +430,8 @@ arithmetic_unary_function(int operator, unsigned char 
flags, gal_data_t *in)
       BINFUNC_F_OPERATOR_LEFT_RIGHT_SET(double, LT, OP);                \
       break;                                                            \
     default:                                                            \
-      error(EXIT_FAILURE, 0, "type %d not recognized in "               \
-            "for r->type in BINFUNC_F_OPERATOR_LEFT_SET", r->type);     \
+      error(EXIT_FAILURE, 0, "%s: type %d not recognized for r->type",  \
+            "BINFUNC_F_OPERATOR_LEFT_SET", r->type);                    \
     }
 
 
@@ -449,8 +448,8 @@ arithmetic_unary_function(int operator, unsigned char 
flags, gal_data_t *in)
       BINFUNC_F_OPERATOR_LEFT_SET(double, OP);                          \
       break;                                                            \
     default:                                                            \
-      error(EXIT_FAILURE, 0, "type %d not recognized in "               \
-            "for l->type in BINFUNC_F_OPERATOR_SET", l->type);          \
+      error(EXIT_FAILURE, 0, "%s: type %d not recognized for l->type",  \
+            "BINFUNC_F_OPERATOR_SET", l->type);                         \
     }
 
 
@@ -469,8 +468,8 @@ arithmetic_binary_function_flt(int operator, unsigned char 
flags,
   /* Simple sanity check on the input sizes */
   if( !( (flags & GAL_ARITHMETIC_NUMOK) && (l->size==1 || r->size==1))
       && gal_data_dsize_is_different(l, r) )
-    error(EXIT_FAILURE, 0, "the input datasets don't have the same "
-          "dimension/size in data_arithmetic_binary_function");
+    error(EXIT_FAILURE, 0, "%s: the input datasets don't have the same "
+          "dimension/size", __func__);
 
   /* Check for the types of the left and right operands. */
   arithmetic_check_float_input(l, operator, "first");
@@ -513,8 +512,8 @@ arithmetic_binary_function_flt(int operator, unsigned char 
flags,
     {
     case GAL_ARITHMETIC_OP_POW:  BINFUNC_F_OPERATOR_SET( pow  ); break;
     default:
-      error(EXIT_FAILURE, 0, "Operator code %d not recognized in "
-            "data_arithmetic_binary_function", operator);
+      error(EXIT_FAILURE, 0, "%s: operator code %d not recognized",
+            __func__, operator);
     }
 
 
@@ -598,8 +597,8 @@ arithmetic_binary_function_flt(int operator, unsigned char 
flags,
     case GAL_TYPE_FLOAT32:  DO_WHERE_OPERATION( float,    OT);  break;  \
     case GAL_TYPE_FLOAT64:  DO_WHERE_OPERATION( double,   OT);  break;  \
     default:                                                            \
-      error(EXIT_FAILURE, 0, "type code %d not recognized for the "     \
-            "`iftrue' dataset of `WHERE_OUT_SET'", iftrue->type);       \
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized for the " \
+            "`iftrue' dataset", "WHERE_OUT_SET", iftrue->type);         \
     }
 
 
@@ -614,15 +613,15 @@ arithmetic_where(unsigned char flags, gal_data_t *out, 
gal_data_t *cond,
 
   /* The condition operator has to be unsigned char. */
   if(cond->type!=GAL_TYPE_UINT8)
-    error(EXIT_FAILURE, 0, "the condition operand to `arithmetic_where' "
-          "must be an `unsigned char' type, but the given condition "
-          "operator has a `%s' type", gal_type_to_string(cond->type, 1));
+    error(EXIT_FAILURE, 0, "%s: the condition operand must be an "
+          "`uint8' type, but the given condition operand has a "
+          "`%s' type", __func__, gal_type_to_string(cond->type, 1));
 
   /* The dimension and sizes of the out and condition data sets must be the
      same. */
   if(gal_data_dsize_is_different(out, cond))
-    error(EXIT_FAILURE, 0, "the output and condition data sets of the "
-          "`where' operator must be the same size");
+    error(EXIT_FAILURE, 0, "%s: the output and condition data sets of the "
+          "must be the same size", __func__);
 
   /* Do the operation. */
   switch(out->type)
@@ -638,8 +637,8 @@ arithmetic_where(unsigned char flags, gal_data_t *out, 
gal_data_t *cond,
     case GAL_TYPE_FLOAT32:       WHERE_OUT_SET( float    );      break;
     case GAL_TYPE_FLOAT64:       WHERE_OUT_SET( double   );      break;
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized for the `out' "
-            "dataset of `arithmetic_where'", out->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized for the `out'",
+            __func__, out->type);
     }
 
   /* Clean up if necessary. */
@@ -883,7 +882,7 @@ arithmetic_where(unsigned char flags, gal_data_t *out, 
gal_data_t *cond,
     errno=0;                                                            \
     a=malloc(dnum*sizeof *a);                                           \
     if(a==NULL)                                                         \
-      error(EXIT_FAILURE, 0, "%zu bytes for `arrays' in "               \
+      error(EXIT_FAILURE, 0, "%s: %zu bytes for `a'",                   \
             "MULTIOPERAND_TYPE_SET", dnum*sizeof *a);                   \
                                                                         \
     /* Fill in the array pointers and the blank value for this type. */ \
@@ -923,8 +922,8 @@ arithmetic_where(unsigned char flags, gal_data_t *out, 
gal_data_t *cond,
         break;                                                          \
                                                                         \
       default:                                                          \
-        error(EXIT_FAILURE, 0, "the operator code %d not recognized "   \
-              "in MULTIOPERAND_TYPE_SET", operator);                    \
+        error(EXIT_FAILURE, 0, "%s: operator code %d not recognized",   \
+              "MULTIOPERAND_TYPE_SET", operator);                       \
       }                                                                 \
                                                                         \
     /* Clean up. */                                                     \
@@ -960,14 +959,14 @@ arithmetic_multioperand(int operator, unsigned char 
flags, gal_data_t *list)
 
       /* Check the types. */
       if(tmp->type!=list->type)
-        error(EXIT_FAILURE, 0, "the types of all operands to the %s "
-              "operator must be same",
+        error(EXIT_FAILURE, 0, "%s: the types of all operands to the %s "
+              "operator must be same", __func__,
               gal_arithmetic_operator_string(operator));
 
       /* Check the sizes. */
       if( gal_data_dsize_is_different(list, tmp) )
-        error(EXIT_FAILURE, 0, "the sizes of all operands to the %s "
-              "operator must be same",
+        error(EXIT_FAILURE, 0, "%s: the sizes of all operands to the %s "
+              "operator must be same", __func__,
               gal_arithmetic_operator_string(operator));
     }
 
@@ -1021,8 +1020,8 @@ arithmetic_multioperand(int operator, unsigned char 
flags, gal_data_t *list)
       MULTIOPERAND_TYPE_SET(double,    gal_qsort_float64_increasing);
       break;
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`arithmetic_multioperand'", list->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, list->type);
     }
 
 
@@ -1194,8 +1193,7 @@ arithmetic_nearest_compiled_type(int intype)
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "type %d not recognized in "
-            "binary_type_for_convert_to_compiled_type", intype);
+      error(EXIT_FAILURE, 0, "%s: type %d not recognized", __func__, intype);
     }
 
   return 0;
@@ -1287,13 +1285,13 @@ gal_arithmetic_operator_string(int operator)
     case GAL_ARITHMETIC_OP_TO_FLOAT64:   return "float64";
 
     default:
-      error(EXIT_FAILURE, 0, "Operator code %d not recognized in "
-            "gal_data_operator_to_string", operator);
+      error(EXIT_FAILURE, 0, "%s: operator code %d not recognized",
+            __func__, operator);
     }
 
-  error(EXIT_FAILURE, 0, "A bug! Please contact us to fix the problem. "
-        "for some reason, control of the `gal_data_operator_to_string' "
-        "function has reached its end! This should not have happened");
+  error(EXIT_FAILURE, 0, "%s: a bug! Please contact us to fix the problem. "
+        "Control has reached the end of this function. This should not have "
+        "happened", __func__);
   return NULL;
 }
 
@@ -1346,9 +1344,9 @@ gal_arithmetic_convert_to_compiled_type(gal_data_t *in, 
unsigned char flags)
 
   /* Return the output data structure */
   if(out==NULL)
-    error(EXIT_FAILURE, 0, "A bug! Please contact us at %s, so we can fix "
-          "the problem. For some reason, the `out' array in "
-          "`binary_convert_to_compiled_type' is not set", PACKAGE_BUGREPORT);
+    error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s, so we can "
+          "fix the problem. For some reason, the `out' array has not been "
+          "set", __func__, PACKAGE_BUGREPORT);
   return out;
 }
 
@@ -1375,8 +1373,8 @@ arithmetic_from_statistics(int operator, unsigned char 
flags,
     case GAL_ARITHMETIC_OP_MEDIANVAL:
       out=gal_statistics_median(input, ip); break;
     default:
-      error(EXIT_FAILURE, 0, "operator code %d not recognized in "
-            "`arithmetic_from_statistics'", operator);
+      error(EXIT_FAILURE, 0, "%s: operator code %d not recognized",
+            __func__, operator);
     }
 
   /* If the input is to be freed, then do so and return the output. */
@@ -1521,8 +1519,8 @@ gal_arithmetic(int operator, unsigned char flags, ...)
 
     /* When operator is not recognized. */
     default:
-      error(EXIT_FAILURE, 0, "the argument \"%d\" could not be "
-            "interpretted as an operator", operator);
+      error(EXIT_FAILURE, 0, "%s: the argument \"%d\" could not be "
+            "interpretted as an operator", __func__, operator);
     }
 
   /* End the variable argument structure and return. */
diff --git a/lib/binary.c b/lib/binary.c
index 571c411..67fd22c 100644
--- a/lib/binary.c
+++ b/lib/binary.c
@@ -54,10 +54,9 @@ binary_erode_dilate_2d_4con(gal_data_t *input, int 
dilate0_erode1)
 
   /* Do a sanity check: */
   if(dilate0_erode1!=1 && dilate0_erode1!=0)
-    error(EXIT_FAILURE, 0, "a bug! Please contact us at %s so we can fix "
-          "this problem. In binary_2d_4con, the value to `dilate0_erode1' "
-          "is %u while it should be 0 or 1", PACKAGE_BUGREPORT,
-          dilate0_erode1);
+    error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we can "
+          "fix this problem. The value to `dilate0_erode1' is %u while it "
+          "should be 0 or 1", __func__, PACKAGE_BUGREPORT, dilate0_erode1);
 
   /* Set the foreground and background values. */
   if(dilate0_erode1==0) {f=1; b=0;}
@@ -138,10 +137,9 @@ binary_erode_dilate_2d_8con(gal_data_t *input, unsigned 
char dilate0_erode1)
 
   /* Do a sanity check: */
   if(dilate0_erode1!=1 && dilate0_erode1!=0)
-    error(EXIT_FAILURE, 0, "a bug! Please contact us at %s so we can fix "
-          "this problem. In dilate0_erode1_4con (binary.c), the value to "
-          "dilate0_erode1 is %u while it should be 0 or 1", PACKAGE_BUGREPORT,
-          dilate0_erode1);
+    error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we can fix "
+          "this problem. The value to dilate0_erode1 is %u while it should "
+          "be 0 or 1", __func__, PACKAGE_BUGREPORT, dilate0_erode1);
 
   /* Set the foreground and background values: */
   if(dilate0_erode1==0) {f=1; b=0;}
@@ -242,8 +240,9 @@ binary_erode_dilate(gal_data_t *input, size_t num, int 
connectivity,
 
   /* Currently this only works on blocks. */
   if(input->block)
-    error(EXIT_FAILURE, 0, "`gal_binary_erode' currently only works on a "
-          "fully allocated block of memory");
+    error(EXIT_FAILURE, 0, "%s: currently only works on a fully "
+          "allocated block of memory, but the input is a tile (its `block' "
+          "element is not NULL)", __func__);
 
   /* Set the dataset to work on. */
   binary = ( (inplace && input->type==GAL_TYPE_UINT8)
@@ -260,14 +259,14 @@ binary_erode_dilate(gal_data_t *input, size_t num, int 
connectivity,
           case 4: binary_erode_dilate_2d_4con(binary, d0e1); break;
           case 8: binary_erode_dilate_2d_8con(binary, d0e1); break;
           default:
-            error(EXIT_FAILURE, 0, "%d not acceptable for connectivity in "
-                  "a 2D dataset", connectivity);
+            error(EXIT_FAILURE, 0, "%s: %d not acceptable for connectivity "
+                  "in a 2D dataset", __func__, connectivity);
           }
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "`gal_binary_erode' currently doesn't work on "
-            "%zu dimensional datasets", binary->ndim);
+      error(EXIT_FAILURE, 0, "%s: currently doesn't work on %zu "
+            "dimensional datasets", __func__, binary->ndim);
     }
 
   /* Clean up and return. */
@@ -362,11 +361,11 @@ gal_binary_connected_components(gal_data_t *binary, 
gal_data_t **out,
 
   /* Two small sanity checks. */
   if(binary->type!=GAL_TYPE_UINT8)
-    error(EXIT_FAILURE, 0, "the input data structure to "
-          "`gal_binary_connected_components' must be `uint8' type");
+    error(EXIT_FAILURE, 0, "%s: the input data set type must be `uint8'",
+          __func__);
   if(binary->block)
-    error(EXIT_FAILURE, 0, "currently, the input data structure to "
-          "`gal_binary_connected_components' must not be a tile");
+    error(EXIT_FAILURE, 0, "%s: currently, the input data structure to "
+          "must not be a tile", __func__);
 
 
   /* Prepare the dataset for the labels. */
@@ -377,14 +376,13 @@ gal_binary_connected_components(gal_data_t *binary, 
gal_data_t **out,
 
       /* Make sure the given dataset has the same size as the input. */
       if( gal_data_dsize_is_different(binary, lab) )
-        error(EXIT_FAILURE, 0, "the `binary' and `out' datasets must have "
-              "the same size in `gal_binary_connected_components'");
+        error(EXIT_FAILURE, 0, "%s: the `binary' and `out' datasets must have "
+              "the same size", __func__);
 
       /* Make sure it has a `int32' type. */
       if( lab->type!=GAL_TYPE_INT32 )
-        error(EXIT_FAILURE, 0, "the `out' dataset in "
-              "`gal_binary_connected_components' must have `int32' type"
-              "but the array you have given is `%s' type",
+        error(EXIT_FAILURE, 0, "%s: the `out' dataset must have `int32' type"
+              "but the array you have given is `%s' type", __func__,
               gal_type_to_string(lab->type, 1));
 
       /* Reset all its values to zero. */
@@ -487,19 +485,19 @@ gal_binary_connected_adjacency_matrix(gal_data_t 
*adjacency,
 
   /* Some small sanity checks. */
   if(adjacency->type != GAL_TYPE_UINT8)
-    error(EXIT_FAILURE, 0, "`gal_binary_connected_adjacency_matrix' only "
-          "accepts a `uint8' numeric type. However, the input dataset has "
-          "type of `%s'", gal_type_to_string(adjacency->type, 1));
+    error(EXIT_FAILURE, 0, "%s: input must have type `uint8'. However, the "
+          "input dataset has type of `%s'", __func__,
+          gal_type_to_string(adjacency->type, 1));
 
   if(adjacency->ndim != 2)
-    error(EXIT_FAILURE, 0, "`gal_binary_connected_adjacency_matrix' only "
-          "accepts a 2-dimensional array. However, the input dataset has "
-          "%zu dimensions", adjacency->ndim);
+    error(EXIT_FAILURE, 0, "%s: input must be 2-dimensional (a matrix)."
+          "However, the input dataset has %zu dimensions", __func__,
+          adjacency->ndim);
 
   if(adjacency->dsize[0] != adjacency->dsize[1])
-    error(EXIT_FAILURE, 0, "`gal_binary_connected_adjacency_matrix' only "
-          "accepts a square matrix. However, the input dataset has a size "
-          "of %zu x %zu", adjacency->dsize[0], adjacency->dsize[1]);
+    error(EXIT_FAILURE, 0, "%s: input must be square (same length in both "
+          "dimensions). However, the input dataset has a size of %zu x %zu",
+          __func__, adjacency->dsize[0], adjacency->dsize[1]);
 
 
   /* Allocate (and clear) the output datastructure. */
@@ -673,8 +671,8 @@ gal_binary_fill_holes(gal_data_t *input)
 
   /* A small sanity check. */
   if( input->type != GAL_TYPE_UINT8 )
-    error(EXIT_FAILURE, 0, "input to `gal_binary_fill_holes' must have "
-          "`uint8' type, but its input dataset has `%s' type",
+    error(EXIT_FAILURE, 0, "%s: input must have `uint8' type, but its "
+          "input dataset has `%s' type", __func__,
           gal_type_to_string(input->type, 1));
 
 
diff --git a/lib/blank.c b/lib/blank.c
index c7bd893..8cc48e4 100644
--- a/lib/blank.c
+++ b/lib/blank.c
@@ -65,13 +65,13 @@ gal_blank_write(void *ptr, uint8_t type)
     /* Complex types */
     case GAL_TYPE_COMPLEX32:
     case GAL_TYPE_COMPLEX64:
-      error(EXIT_FAILURE, 0, "complex types are not yet supported in "
-            "`gal_blank_write'");
+      error(EXIT_FAILURE, 0, "%s: complex types are not yet supported",
+            __func__);
 
     /* Unrecognized type. */
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`gal_blank_write'", type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized", __func__,
+            type);
     }
 }
 
@@ -192,8 +192,8 @@ gal_blank_present(gal_data_t *input, int updateflag)
     /* String. */
     case GAL_TYPE_STRING:
       if(input!=block)
-        error(EXIT_FAILURE, 0, "tile mode is currently not supported for "
-              "strings");
+        error(EXIT_FAILURE, 0, "%s: tile mode is currently not supported for "
+              "strings", __func__);
       strf = (str=input->array) + input->size;
       do if(!strcmp(*str++,GAL_BLANK_STRING)) return 1; while(str<strf);
       break;
@@ -201,17 +201,17 @@ gal_blank_present(gal_data_t *input, int updateflag)
     /* Complex types */
     case GAL_TYPE_COMPLEX32:
     case GAL_TYPE_COMPLEX64:
-      error(EXIT_FAILURE, 0, "complex types are not yet supported in "
-            "`gal_blank_write'");
+      error(EXIT_FAILURE, 0, "%s: complex types are not yet supported",
+            __func__);
 
     /* Bit */
     case GAL_TYPE_BIT:
-      error(EXIT_FAILURE, 0, "bit type datasets are not yet supported in "
-            "`gal_blank_present'");
+      error(EXIT_FAILURE, 0, "%s: bit type datasets are not yet supported",
+            __func__);
 
     default:
-      error(EXIT_FAILURE, 0, "type value (%d) not recognized "
-            "in `gal_blank_present'", block->type);
+      error(EXIT_FAILURE, 0, "%s: type value (%d) not recognized",
+            __func__, block->type);
     }
 
   /* Update the flag if requested. */
@@ -287,13 +287,13 @@ gal_blank_flag(gal_data_t *input)
         case GAL_TYPE_BIT:
         case GAL_TYPE_COMPLEX32:
         case GAL_TYPE_COMPLEX64:
-          error(EXIT_FAILURE, 0, "%s type not yet supported in "
-                "`gal_blank_flag'", gal_type_to_string(input->type, 1));
+          error(EXIT_FAILURE, 0, "%s: %s type not yet supported",
+                __func__, gal_type_to_string(input->type, 1));
 
           /* Bad input. */
         default:
-          error(EXIT_FAILURE, 0, "type value (%d) not recognized "
-                "in `gal_blank_flag'", input->type);
+          error(EXIT_FAILURE, 0, "%s: type value (%d) not recognized",
+                __func__, input->type);
         }
     }
   else
@@ -328,9 +328,9 @@ gal_blank_remove(gal_data_t *input)
 
   /* This function currently assumes a contiguous patch of memory. */
   if(input->block && input->ndim!=1 )
-    error(EXIT_FAILURE, 0, "`gal_blank_remove' doesn't currently work on "
-          "tiles in datasets with more dimensions than 1, your input has "
-          "%zu dimensions", input->ndim);
+    error(EXIT_FAILURE, 0, "%s: tiles in datasets with more dimensions than "
+          "1 are not yet supported. Your input has %zu dimensions",
+          __func__, input->ndim);
 
   /* If the dataset doesn't have blank values, then just get the size. */
   if( gal_blank_present(input, 0) )
@@ -349,8 +349,8 @@ gal_blank_remove(gal_data_t *input)
         case GAL_TYPE_FLOAT32:  BLANK_REMOVE( float    );    break;
         case GAL_TYPE_FLOAT64:  BLANK_REMOVE( double   );    break;
         default:
-          error(EXIT_FAILURE, 0, "type code %d not recognized in "
-                "`gal_blank_remove'", input->type);
+          error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+                __func__, input->type);
         }
     }
   else num=input->size;
@@ -380,8 +380,8 @@ gal_blank_as_string(uint8_t type, int width)
   switch(type)
     {
     case GAL_TYPE_BIT:
-      error(EXIT_FAILURE, 0, "bit types are not implemented in "
-            "`gal_data_blank_as_string' yet.");
+      error(EXIT_FAILURE, 0, "%s: bit types are not implemented yet",
+            __func__);
       break;
 
     case GAL_TYPE_STRING:
@@ -448,8 +448,8 @@ gal_blank_as_string(uint8_t type, int width)
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`gal_blank_as_string'", type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized", __func__,
+            type);
     }
   return blank;
 }
diff --git a/lib/checkset.c b/lib/checkset.c
index 24de5aa..ffb1981 100644
--- a/lib/checkset.c
+++ b/lib/checkset.c
@@ -77,8 +77,8 @@ gal_checkset_malloc_cat(char *inname, char *toappend)
   errno=0;
   out=malloc(inl+apl+1);
   if(out==NULL)
-    error(EXIT_FAILURE, errno,
-          "allocating %zu bytes in gal_checkset_malloc_cat", inl+apl+1);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes", __func__,
+          inl+apl+1);
 
   strcpy(out, inname);
   strcat(out, toappend);
@@ -98,7 +98,7 @@ gal_checkset_allocate_copy(const char *arg, char **copy)
       errno=0;
       *copy=malloc(strlen(arg)+1);
       if(*copy==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes to copy %s",
+        error(EXIT_FAILURE, errno, "%s: %zu bytes to copy %s", __func__,
               strlen(arg)+1, arg);
       strcpy(*copy, arg);
     }
@@ -123,7 +123,7 @@ gal_checkset_allocate_copy_set(char *arg, char **copy, int 
*set)
   errno=0;
   *copy=malloc(strlen(arg)+1);
   if(*copy==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes to copy %s",
+    error(EXIT_FAILURE, errno, "%s: %zu bytes to copy %s", __func__,
           strlen(arg)+1, arg);
   strcpy(*copy, arg);
   *set=1;
@@ -259,10 +259,9 @@ gal_checkset_dir_0_file_1(char *name, int dontdelete)
   struct stat nameinfo;
 
   if(name==NULL)
-    error(EXIT_FAILURE, 0, "a bug! The input to the "
-          "gal_checkset_dir_0_file_1 function in checkset.c should not "
-          "be NULL. Please contact us at "PACKAGE_BUGREPORT" so we can "
-          "see what went wrong and fix it in future updates");
+    error(EXIT_FAILURE, 0, "%s: a bug! The input should not be NULL. "
+          "Please contact us at %s so we can see what went wrong and "
+          "fix it in future updates", __func__, PACKAGE_BUGREPORT);
 
   errno=0;
   if(stat(name, &nameinfo)!=0)
@@ -299,10 +298,9 @@ gal_checkset_dir_0_file_1(char *name, int dontdelete)
   else                                 /* Not a file or a dir, ABORT */
     error(EXIT_FAILURE, 0, "%s not a file or a directory", name);
 
-  error(EXIT_FAILURE, 0, "a bug! In gal_checkset_dir_0_file_1, (in "
-        "checkset.c). The process should not reach the end of the "
-        "function! Please contact us at "PACKAGE_BUGREPORT" so we can "
-        "see what went wrong and fix it in future updates");
+  error(EXIT_FAILURE, 0, "%s: a bug! The process should not reach the end "
+        "of the function! Please contact us at %s so we can see what went "
+        "wrong and fix it in future updates", __func__, PACKAGE_BUGREPORT);
   return 0;
 }
 
@@ -411,8 +409,8 @@ gal_checkset_dir_part(char *input)
       errno=0;
       out=malloc(3*sizeof *out);
       if(out==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for current directory "
-              "gal_checkset_dir_part", 3*sizeof *out);
+        error(EXIT_FAILURE, errno, "%s: %zu bytes for current directory name",
+              __func__, 3*sizeof *out);
       strcpy(out, "./");
     }
   else
@@ -420,7 +418,7 @@ gal_checkset_dir_part(char *input)
       errno=0;
       out=malloc((l+1)*sizeof *out);
       if(out==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for gal_checkset_dir_part",
+        error(EXIT_FAILURE, errno, "%s: %zu bytes for `out'", __func__,
               (l+1)*sizeof *out);
       strcpy(out, input);
       out[i+1]='\0';
@@ -453,7 +451,8 @@ gal_checkset_not_dir_part(char *input)
   errno=0;
   out=malloc((l+1)*sizeof *out);
   if(out==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for notdir", (l+1)*sizeof *out);
+    error(EXIT_FAILURE, errno, "%s: %zu bytes for notdir", __func__,
+          (l+1)*sizeof *out);
 
   strcpy(out, tmp);
   return out;
@@ -482,8 +481,8 @@ gal_checkset_check_dir_write_add_slash(char **dirname)
   errno=0;
   file_d=mkstemp(tmpname);
   if(file_d==-1)
-    error(EXIT_FAILURE, errno, "cannot write output in the directory %s",
-          indir);
+    error(EXIT_FAILURE, errno, "cannot write output in the directory "
+          "%s", indir);
   /*
   errno=0;
   printf("\n\n%s\n\n", tmpname);
diff --git a/lib/convolve.c b/lib/convolve.c
index 786ba1d..93ba823 100644
--- a/lib/convolve.c
+++ b/lib/convolve.c
@@ -523,12 +523,12 @@ gal_convolve_spatial_general(gal_data_t *tiles, 
gal_data_t *kernel,
 
   /* Small sanity checks. */
   if(tiles->ndim!=kernel->ndim)
-    error(EXIT_FAILURE, 0, "The number of dimensions between the kernel and "
-          "input should be the same in `gal_convolve_spatial'");
+    error(EXIT_FAILURE, 0, "%s: The number of dimensions between the kernel "
+          "and input should be the same", __func__);
   if( block->type!=GAL_TYPE_FLOAT32
       || kernel->type!=GAL_TYPE_FLOAT32 )
-    error(EXIT_FAILURE, 0, "`gal_convolve_spatial' currently only works on "
-          "`float32' type input and kernel");
+    error(EXIT_FAILURE, 0, "%s: only accepts `float32' type input and "
+          "kernel currently", __func__);
 
 
   /* Set the output datastructure.  */
@@ -561,8 +561,8 @@ gal_convolve_spatial_general(gal_data_t *tiles, gal_data_t 
*kernel,
   errno=0;
   params.pprm=malloc(numthreads * sizeof *params.pprm);
   if(params.pprm==NULL)
-    error(EXIT_FAILURE, 0, "%zu bytes for `params.p' in "
-          "`gal_convolve_spatial_general'", numthreads * sizeof *params.pprm);
+    error(EXIT_FAILURE, 0, "%s: %zu bytes for `params.pprm'",
+          __func__, numthreads * sizeof *params.pprm);
 
 
   /* Do the spatial convolution on threads. */
@@ -612,14 +612,13 @@ gal_convolve_spatial_correct_ch_edge(gal_data_t *tiles, 
gal_data_t *kernel,
 
   /* Some small sanity checks. */
   if( gal_data_dsize_is_different(block, tocorrect) )
-    error(EXIT_FAILURE, 0, "the `tocorrect' dataset has to have the same "
-          "dimensions/size as the block of the `tiles' input in "
-          "`gal_convolve_spatial_correct_ch_edge'");
+    error(EXIT_FAILURE, 0, "%s: the `tocorrect' dataset has to have the "
+          "same dimensions/size as the block of the `tiles' input", __func__);
   if( block->type != tocorrect->type )
-    error(EXIT_FAILURE, 0, "the `tocorrect' dataset has to have the same "
-          "type as the block of the `tiles' input in "
-          "`gal_convolve_spatial_correct_ch_edge'. The given types are `%s' "
-          "and `%s' respectively", gal_type_to_string(tocorrect->type, 1),
+    error(EXIT_FAILURE, 0, "%s: the `tocorrect' dataset has to have the same "
+          "type as the block of the `tiles' input. The given types are `%s' "
+          "and `%s' respectively", __func__,
+          gal_type_to_string(tocorrect->type, 1),
           gal_type_to_string(block->type, 1));
 
   /* Call the general function, which will do the correction. */
diff --git a/lib/data.c b/lib/data.c
index d279a68..de3163b 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -135,7 +135,7 @@ gal_data_malloc_array(uint8_t type, size_t size)
   errno=0;
   array=malloc( size * gal_type_sizeof(type) );
   if(array==NULL)
-    error(EXIT_FAILURE, errno, "array of %zu bytes in gal_data_malloc_array",
+    error(EXIT_FAILURE, errno, "%s: array of %zu bytes", __func__,
           size * gal_type_sizeof(type));
 
   return array;
@@ -153,7 +153,7 @@ gal_data_calloc_array(uint8_t type, size_t size)
   errno=0;
   array=calloc( size,  gal_type_sizeof(type) );
   if(array==NULL)
-    error(EXIT_FAILURE, errno, "array of %zu bytes in gal_data_calloc_array",
+    error(EXIT_FAILURE, errno, "%s: array of %zu bytes", __func__,
           size * gal_type_sizeof(type));
 
   return array;
@@ -183,14 +183,15 @@ gal_data_mmap(gal_data_t *data, int clear)
   /*filedes=open(filename, O_RDWR | O_CREAT | O_EXCL | O_TRUNC );*/
   filedes=mkstemp(filename);
   if(filedes==-1)
-    error(EXIT_FAILURE, errno, "%s couldn't be created", filename);
+    error(EXIT_FAILURE, errno, "%s: %s couldn't be created",
+          __func__, filename);
 
 
   /* Make enough space to keep the array data. */
   errno=0;
   if( lseek(filedes, bsize, SEEK_SET) == -1 )
-    error(EXIT_FAILURE, errno, "%s: unable to change file position by "
-          "%zu bytes", filename, bsize);
+    error(EXIT_FAILURE, errno, "%s: %s: unable to change file position by "
+          "%zu bytes", __func__, filename, bsize);
 
 
   /* Write to the newly set file position so the space is allocated. To do
@@ -198,8 +199,8 @@ gal_data_mmap(gal_data_t *data, int clear)
      we identified by `lseek' (above). This will ensure that this space is
      set a side for this array and prepare us to use `mmap'. */
   if( write(filedes, &uc, 1) == -1)
-    error(EXIT_FAILURE, errno, "%s: unable to write one byte at the "
-          "%zu-th position", filename, bsize);
+    error(EXIT_FAILURE, errno, "%s: %s: unable to write one byte at the "
+          "%zu-th position", __func__, filename, bsize);
 
 
   /* Map the memory. */
@@ -208,7 +209,8 @@ gal_data_mmap(gal_data_t *data, int clear)
 
   /* Close the file. */
   if( close(filedes) == -1 )
-    error(EXIT_FAILURE, errno, "%s couldn't be closed", filename);
+    error(EXIT_FAILURE, errno, "%s: %s couldn't be closed",
+          __func__, filename);
 
   /* Keep the filename. */
   data->mmapname=filename;
@@ -276,8 +278,8 @@ gal_data_initialize(gal_data_t *data, void *array, uint8_t 
type,
       errno=0;
       data->dsize=malloc(ndim*sizeof *data->dsize);
       if(data->dsize==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for data->dsize in "
-              "`gal_data_alloc'", ndim*sizeof *data->dsize);
+        error(EXIT_FAILURE, errno, "%s: %zu bytes for data->dsize",
+              __func__, ndim*sizeof *data->dsize);
 
 
       /* Fill in the `dsize' array and in the meantime set `size': */
@@ -286,9 +288,9 @@ gal_data_initialize(gal_data_t *data, void *array, uint8_t 
type,
         {
           /* Do a small sanity check. */
           if(dsize[i]<=0)
-            error(EXIT_FAILURE, 0, "the size of a dimension cannot be zero "
-                  "or negative. dsize[%zu] in `gal_data_alloc' has a value "
-                  "of %ld", i, dsize[i]);
+            error(EXIT_FAILURE, 0, "%s: the size of a dimension cannot be zero 
"
+                  "or negative. dsize[%zu], but has a value of %ld", __func__,
+                  i, dsize[i]);
 
           /* Write this dimension's size, also correct the total number of
              elements. */
@@ -343,8 +345,8 @@ gal_data_alloc(void *array, uint8_t type, size_t ndim, 
size_t *dsize,
   errno=0;
   out=malloc(sizeof *out);
   if(out==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for gal_data_t in gal_data_alloc",
-          sizeof *out);
+    error(EXIT_FAILURE, errno, "%s: %zu bytes for gal_data_t",
+          __func__, sizeof *out);
 
   /* Initialize the allocated array. */
   gal_data_initialize(out, array, type, ndim, dsize, wcs, clear, minmapsize,
@@ -380,8 +382,8 @@ gal_data_free_contents(gal_data_t *data)
   char **strarr;
 
   if(data==NULL)
-    error(EXIT_FAILURE, 0, "the input data structure to "
-          "`gal_data_free_contents' was a NULL pointer");
+    error(EXIT_FAILURE, 0, "%s: the input data structure to "
+          "`gal_data_free_contents' was a NULL pointer", __func__);
 
   /* Free all the possible allocations. */
   if(data->name)    { free(data->name);    data->name=NULL;    }
@@ -462,8 +464,8 @@ gal_data_array_calloc(size_t size)
   errno=0;
   out=malloc(size*sizeof *out);
   if(out==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for `out' in "
-          "`gal_data_calloc_dataarray'", size*sizeof *out);
+    error(EXIT_FAILURE, errno, "%s: %zu bytes for `out'", __func__,
+          size*sizeof *out);
 
 
   /* Set the pointers to NULL if they didn't exist and the non-pointers to
@@ -538,30 +540,6 @@ gal_data_array_free(gal_data_t *dataarr, size_t size, int 
free_array)
 /*************************************************************
  **************            Copying             ***************
  *************************************************************/
-/* Wrapper for `gal_data_copy_to_new_type', but will copy to the same type
-   as the input. Recall that if the input is a tile (a part of the input,
-   which is not-contiguous if it has more than one dimension), then the
-   output will have only the elements that cover the tile.*/
-gal_data_t *
-gal_data_copy(gal_data_t *in)
-{
-  return gal_data_copy_to_new_type(in, gal_tile_block(in)->type);
-}
-
-
-
-
-/* Copy the input dataset into the already allocated space of out. */
-void
-gal_data_copy_to_allocated(gal_data_t *in, gal_data_t *out)
-{
-  gal_data_copy_to_new_type_to_allocated(in, out, out->type);
-}
-
-
-
-
-
 /* Only to be used in `data_copy_from_string'. */
 static void
 data_copy_to_string_not_parsed(char *string, void *to, uint8_t type)
@@ -569,8 +547,8 @@ data_copy_to_string_not_parsed(char *string, void *to, 
uint8_t type)
   if( strcmp(string, GAL_BLANK_STRING) )
     gal_blank_write(to, type);
   else
-    error(EXIT_FAILURE, 0, "`%s' couldn't be parsed as `%s' type",
-          string, gal_type_to_string(type, 1));
+    error(EXIT_FAILURE, 0, "%s: `%s' couldn't be parsed as `%s' type",
+          __func__, string, gal_type_to_string(type, 1));
 }
 
 
@@ -589,12 +567,11 @@ data_copy_from_string(gal_data_t *from, gal_data_t *to)
 
   /* Sanity check. */
   if(from->type!=GAL_TYPE_STRING)
-    error(EXIT_FAILURE, 0, "`from' in `data_copy_from_string' must have "
-          "a string type.");
+    error(EXIT_FAILURE, 0, "%s: `from' must have a string type.", __func__);
   if(from->block)
-    error(EXIT_FAILURE, 0, "'data_copyt_from_string' doesn't currently "
-          "support tile inputs. Please contact us at %s so we can implement "
-          "this feature", PACKAGE_BUGREPORT);
+    error(EXIT_FAILURE, 0, "%s: tiles not currently supported (`block' "
+          "element must be NULL). Please contact us at %s so we can "
+          "implement this feature", __func__, PACKAGE_BUGREPORT);
 
   /* Do the copying. */
   for(i=0;i<from->size;++i)
@@ -616,14 +593,13 @@ data_copy_from_string(gal_data_t *from, gal_data_t *to)
         case GAL_TYPE_STRLL:
         case GAL_TYPE_COMPLEX32:
         case GAL_TYPE_COMPLEX64:
-          error(EXIT_FAILURE, 0, "`data_copy_from_string' currently doesn't "
-                "support copying to %s type",
-                gal_type_to_string(to->type, 1));
+          error(EXIT_FAILURE, 0, "%s: copying to %s type not currently "
+                "supported", __func__, gal_type_to_string(to->type, 1));
           break;
 
         default:
-          error(EXIT_FAILURE, 0, "type %d not recognized for to->type in "
-                "`data_copy_from_string'", to->type);
+          error(EXIT_FAILURE, 0, "%s: type %d not recognized for to->type",
+                __func__, to->type);
         }
 
       /* Read/put the input into the output. */
@@ -674,12 +650,11 @@ data_copy_to_string(gal_data_t *from, gal_data_t *to)
 
   /* Sanity check */
   if(to->type!=GAL_TYPE_STRING)
-    error(EXIT_FAILURE, 0, "`to' in `data_copy_to_string' must have a "
-          "string type");
+    error(EXIT_FAILURE, 0, "%s: `to' must have a string type", __func__);
   if(from->block)
-    error(EXIT_FAILURE, 0, "'data_copyt_to_string' doesn't currently "
-          "support tile inputs. Please contact us at %s so we can implement "
-          "this feature", PACKAGE_BUGREPORT);
+    error(EXIT_FAILURE, 0, "%s: tile inputs not currently supported (`block' "
+          "element must be NULL). Please contact us at %s so we can implement "
+          "this feature", __func__, PACKAGE_BUGREPORT);
 
   /* Do the copying */
   switch(from->type)
@@ -723,14 +698,13 @@ data_copy_to_string(gal_data_t *from, gal_data_t *to)
     case GAL_TYPE_STRLL:
     case GAL_TYPE_COMPLEX32:
     case GAL_TYPE_COMPLEX64:
-      error(EXIT_FAILURE, 0, "`data_copy_to_string' currently doesn't "
-            "support copying to %s type",
-            gal_type_to_string(from->type, 1));
+      error(EXIT_FAILURE, 0, "%s: copying to %s type not currently supported",
+            __func__, gal_type_to_string(from->type, 1));
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "type %d not recognized for `from->type' in "
-            "`data_copy_to_string'", from->type);
+      error(EXIT_FAILURE, 0, "%s: type %d not recognized for `from->type'",
+            __func__, from->type);
     }
 }
 
@@ -815,20 +789,44 @@ data_copy_to_string(gal_data_t *from, gal_data_t *to)
     case GAL_TYPE_STRLL:                                                \
     case GAL_TYPE_COMPLEX32:                                            \
     case GAL_TYPE_COMPLEX64:                                            \
-      error(EXIT_FAILURE, 0, "`gal_data_copy_to_new_type' currently "   \
-            "doesn't support copying from %s type to a numeric (real) " \
-            "type", gal_type_to_string(in->type, 1));                   \
+      error(EXIT_FAILURE, 0, "%s: copying from %s type to a numeric "   \
+            "(real) type not supported", "COPY_OT_SET",                 \
+            gal_type_to_string(in->type, 1));                           \
       break;                                                            \
                                                                         \
     default:                                                            \
-      error(EXIT_FAILURE, 0, "type code %d not recognized for "         \
-            "`in->type' in COPY_OT_SET", in->type);                     \
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized for "     \
+            "`in->type'", "COPY_OT_SET", in->type);                     \
     }
 
 
 
 
 
+/* Wrapper for `gal_data_copy_to_new_type', but will copy to the same type
+   as the input. Recall that if the input is a tile (a part of the input,
+   which is not-contiguous if it has more than one dimension), then the
+   output will have only the elements that cover the tile.*/
+gal_data_t *
+gal_data_copy(gal_data_t *in)
+{
+  return gal_data_copy_to_new_type(in, gal_tile_block(in)->type);
+}
+
+
+
+
+/* Copy the input dataset into the already allocated space of out. */
+void
+gal_data_copy_to_allocated(gal_data_t *in, gal_data_t *out)
+{
+  gal_data_copy_to_new_type_to_allocated(in, out, out->type);
+}
+
+
+
+
+
 /* Copy a given data structure to a new one with any type (for the
    output). The input can be a tile, in which case the output will be a
    contiguous patch of memory that has all the values within the input tile
@@ -878,21 +876,20 @@ gal_data_copy_to_new_type_to_allocated(gal_data_t *in, 
gal_data_t *out,
      output is not smaller than the input. Note that the type is irrelevant
      because we will be doing type conversion if they differ.*/
   if( out->size < in->size  )
-    error(EXIT_FAILURE, 0, "the output dataset must be equal or larger than "
-          "the input in `gal_data_copy_to_new_type_allocated', the sizes "
-          "are %zu and %zu respectively", out->size, in->size);
+    error(EXIT_FAILURE, 0, "%s: the output dataset must be equal or larger "
+          "than the input. the sizes are %zu and %zu respectively", __func__,
+          out->size, in->size);
   if( out->ndim != in->ndim )
-    error(EXIT_FAILURE, 0, "the output dataset must have the same number of "
-          "dimensions in `gal_data_copy_to_new_type_allocated', the "
-          "dimensions "
-          "are %zu and %zu respectively", out->ndim, in->ndim);
-
-  /* Write the constant values. */
-  out->flag=in->flag;
-  out->next=in->next;
-  out->status=in->status;
-  out->disp_width=in->disp_width;
-  out->disp_precision=in->disp_precision;
+    error(EXIT_FAILURE, 0, "%s: the output dataset must have the same number "
+          "of dimensions, the dimensions are %zu and %zu respectively",
+          __func__, out->ndim, in->ndim);
+
+  /* Write the basic meta-data. */
+  out->flag           = in->flag;
+  out->next           = in->next;
+  out->status         = in->status;
+  out->disp_width     = in->disp_width;
+  out->disp_precision = in->disp_precision;
 
   /* Do the copying. */
   switch(out->type)
@@ -913,14 +910,13 @@ gal_data_copy_to_new_type_to_allocated(gal_data_t *in, 
gal_data_t *out,
     case GAL_TYPE_STRLL:
     case GAL_TYPE_COMPLEX32:
     case GAL_TYPE_COMPLEX64:
-      error(EXIT_FAILURE, 0, "`gal_data_copy_to_new_type' currently doesn't "
-            "support copying to %s type",
-            gal_type_to_string(out->type, 1));
+      error(EXIT_FAILURE, 0, "%s: copying to %s type not yet supported",
+            __func__, gal_type_to_string(out->type, 1));
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "type %d not recognized for "
-            "for `out->type' in gal_data_copy_to_new_type", out->type);
+      error(EXIT_FAILURE, 0, "%s: type %d not recognized for `out->type'",
+            __func__, out->type);
     }
 
   /* Correct the sizes of the output to be the same as the input. If it is
@@ -991,8 +987,8 @@ gal_data_copy_element_same_type(gal_data_t *input, size_t 
index, void *ptr)
     case GAL_TYPE_FLOAT32:   COPY_ELEM( float    );    break;
     case GAL_TYPE_FLOAT64:   COPY_ELEM( double   );    break;
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`gal_data_copy_elem'", input->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized", __func__,
+            input->type);
     }
 }
 
@@ -1051,8 +1047,7 @@ gal_data_write_to_string(void *ptr, uint8_t type, int 
quote_if_str_has_space)
     case GAL_TYPE_FLOAT64: WRITE_TO_STRING( double,   "%.10g"   );  break;
 
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`gal_data_write_to_string'", type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized", __func__, 
type);
     }
   return str;
 }
@@ -1262,8 +1257,8 @@ gal_data_string_to_type(void **out, char *string, uint8_t 
type)
                 case GAL_TYPE_UINT32: *(uint32_t *)  value=l;   break;
                 case GAL_TYPE_UINT64: *(uint64_t *)  value=l;   break;
                 default:
-                  error(EXIT_FAILURE, 0, "type code %d not recognized in "
-                        "`gal_data_string_to_type'", type);
+                  error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+                        __func__, type);
                 }
           }
     }
diff --git a/lib/dimension.c b/lib/dimension.c
index 0536440..fe683c4 100644
--- a/lib/dimension.c
+++ b/lib/dimension.c
@@ -80,8 +80,7 @@ gal_dimension_num_neighbors(size_t ndim)
   if(ndim)
     return pow(3, ndim)-1;
   else
-    error(EXIT_FAILURE, 0, "ndim cannot be zero in "
-          "`gal_dimension_num_neighbors'");
+    error(EXIT_FAILURE, 0, "%s: ndim cannot be zero", __func__);
   return 0;
 }
 
@@ -126,8 +125,8 @@ gal_dimension_coord_to_index(size_t ndim, size_t *dsize, 
size_t *coord)
   switch(ndim)
     {
     case 0:
-      error(EXIT_FAILURE, 0, "`gal_dimension_coord_to_index' doesn't accept "
-            "0 dimensional arrays");
+      error(EXIT_FAILURE, 0, "%s: doesn't accept 0 dimensional arrays",
+            __func__);
 
     case 1:
       ind=coord[0];
@@ -176,8 +175,8 @@ gal_dimension_index_to_coord(size_t ind, size_t ndim, 
size_t *dsize,
   switch(ndim)
     {
     case 0:
-      error(EXIT_FAILURE, 0, "a 0-dimensional dataset is not defined in "
-            "`gal_dimension_ind_to_coord'");
+      error(EXIT_FAILURE, 0, "%s: a 0-dimensional dataset is not defined",
+            __func__);
 
     /* One dimensional dataset. */
     case 1:
diff --git a/lib/fits.c b/lib/fits.c
index 2f3bb3c..31069d0 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -186,8 +186,8 @@ gal_fits_bitpix_to_type(int bitpix)
     case FLOAT_IMG:                 return GAL_TYPE_FLOAT32;
     case DOUBLE_IMG:                return GAL_TYPE_FLOAT64;
     default:
-      error(EXIT_FAILURE, 0, "bitpix value of %d not recognized in "
-            "gal_fits_bitpix_to_type", bitpix);
+      error(EXIT_FAILURE, 0, "%s: bitpix value of %d not recognized",
+            __func__, bitpix);
     }
   return 0;
 }
@@ -217,12 +217,12 @@ gal_fits_type_to_bitpix(uint8_t type)
     case GAL_TYPE_UINT64:
     case GAL_TYPE_COMPLEX32:
     case GAL_TYPE_COMPLEX64:
-      error(EXIT_FAILURE, 0, "type %s not recognized for FITS image BITPIX",
-            gal_type_to_string(type, 1));
+      error(EXIT_FAILURE, 0, "%s: type %s not recognized for FITS image "
+            "BITPIX", __func__, gal_type_to_string(type, 1));
 
     default:
-      error(EXIT_FAILURE, 0, "type value of %d not recognized in "
-            "gal_fits_type_to_bitpix", type);
+      error(EXIT_FAILURE, 0, "%s: type value of %d not recognized",
+            __func__, type);
     }
   return 0;
 }
@@ -257,19 +257,17 @@ gal_fits_type_to_bin_tform(uint8_t type)
 
     /* Not recognized by CFITSIO. */
     case GAL_TYPE_UINT64:
-      error(EXIT_FAILURE, 0, "type %s not recognized for FITS binary "
-            "table TFORM", gal_type_to_string(type, 1));
+      error(EXIT_FAILURE, 0, "%s: type %s not recognized for FITS binary "
+            "table TFORM", __func__, gal_type_to_string(type, 1));
       break;
 
     /* Wrong type code. */
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`gal_fits_type_to_bin_tform'", type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized", __func__, 
type);
     }
 
-  error(EXIT_FAILURE, 0, "A bug! Please contact us so we can fix this. "
-        "For some reason, control has reached to the end of the "
-        "`gal_fits_type_to_bin_tform'");
+  error(EXIT_FAILURE, 0, "%s: s bug! Please contact us so we can fix this. "
+        "Control must not reach the end of this function", __func__);
   return '\0';
 }
 
@@ -336,20 +334,20 @@ gal_fits_type_to_datatype(uint8_t type)
 
     /* Wrong type. */
     default:
-      error(EXIT_FAILURE, 0, "'%d' is not a recognized Gnuastro type. "
-            "It was given to `gal_fits_type_to_datatype'.", type);
+      error(EXIT_FAILURE, 0, "%s: type code %d is not a recognized",
+            __func__, type);
     }
 
   /* If control reaches, here, there was a problem with the host types. */
   if(w)
-    error(EXIT_FAILURE, 0, "this system doesn't have a %d byte integer "
-          "type, so type `%s' cannot be written to FITS", w,
+    error(EXIT_FAILURE, 0, "%s: this system doesn't have a %d byte integer "
+          "type, so type `%s' cannot be written to FITS", __func__, w,
           gal_type_to_string(type, 1));
   else
-    error(EXIT_FAILURE, 0, "a bug! please contact us at %s so we can "
-          "fix theh problem. Control must not have reached the end of "
-          "`gal_fits_type_to_datatype', for the given type `%s'",
-          PACKAGE_BUGREPORT, gal_type_to_string(type, 1));
+    error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we can "
+          "fix the problem. Control must not have reached the end for the "
+          "given type `%s'", __func__, PACKAGE_BUGREPORT,
+          gal_type_to_string(type, 1));
   return -1;
 }
 
@@ -446,13 +444,13 @@ gal_fits_datatype_to_type(int datatype, int 
is_table_column)
 
     /* A bug! */
     default:
-      error(EXIT_FAILURE, 0, "'%d' is not a recognized CFITSIO datatype. "
-            "It was given to `gal_fits_datatype_to_type'.", datatype);
+      error(EXIT_FAILURE, 0, "%s: %d is not a recognized CFITSIO datatype",
+            __func__, datatype);
     }
 
-  error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we can fix "
-        "this. For some reason, control has reached to the end of the "
-        "`gal_fits_datatype_to_type' function in fits.c.", PACKAGE_BUGREPORT);
+  error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we can fix "
+        "this. Control must not have reached the end of this function.",
+        __func__, PACKAGE_BUGREPORT);
   return -1;
 }
 
@@ -776,9 +774,8 @@ gal_fits_key_read_from_ptr(fitsfile *fptr, gal_data_t 
*keysll,
                                   : gal_data_malloc_array(tmp->type, 1) );
             valueptr=strarray[0]=malloc(FLEN_VALUE * sizeof *strarray[0]);
             if(strarray[0]==NULL)
-              error(EXIT_FAILURE, errno, "%zu bytes for strarray[0] in "
-                    "`gal_fits_read_keywords_fprt'",
-                    FLEN_VALUE * sizeof *strarray[0]);
+              error(EXIT_FAILURE, errno, "%s: %zu bytes for strarray[0]",
+                    __func__, FLEN_VALUE * sizeof *strarray[0]);
             break;
 
           default:
@@ -793,9 +790,8 @@ gal_fits_key_read_from_ptr(fitsfile *fptr, gal_data_t 
*keysll,
             errno=0;
             tmp->comment=malloc(FLEN_COMMENT * sizeof *tmp->comment);
             if(tmp->comment==NULL)
-              error(EXIT_FAILURE, errno, "%zu bytes for tmp->comment in "
-                    "`gal_fits_read_keywords_fprt'",
-                    FLEN_COMMENT * sizeof *tmp->comment);
+              error(EXIT_FAILURE, errno, "%s: %zu bytes for tmp->comment",
+                    __func__, FLEN_COMMENT * sizeof *tmp->comment);
           }
         else
           tmp->comment=NULL;
@@ -812,9 +808,8 @@ gal_fits_key_read_from_ptr(fitsfile *fptr, gal_data_t 
*keysll,
             errno=0;
             tmp->unit=malloc(FLEN_COMMENT * sizeof *tmp->unit);
             if(tmp->unit==NULL)
-              error(EXIT_FAILURE, errno, "%zu bytes for tmp->unit in "
-                    "`gal_fits_read_keywords_fprt'",
-                    FLEN_COMMENT * sizeof *tmp->unit);
+              error(EXIT_FAILURE, errno, "%s: %zu bytes for tmp->unit",
+                    __func__, FLEN_COMMENT * sizeof *tmp->unit);
             fits_read_key_unit(fptr, tmp->name, tmp->unit, &tmp->status);
 
             /* If the string is empty, free the space and set it to NULL. */
@@ -857,7 +852,7 @@ gal_fits_key_read(char *filename, char *hdu, gal_data_t 
*keysll,
   len=strlen(filename)+strlen(hdu)+4;
   ffname=malloc(len*sizeof *ffname);
   if(ffname==NULL)
-    error(EXIT_FAILURE, errno, "%zu characters", len);
+    error(EXIT_FAILURE, errno, "%s: %zu characters", __func__, len);
   sprintf(ffname, "%s[%s#]", filename, hdu);
 
   /* Open the FITS file: */
@@ -897,8 +892,7 @@ gal_fits_key_add_to_ll(struct gal_fits_key_ll **list, 
uint8_t type,
   errno=0;
   newnode=malloc(sizeof *newnode);
   if(newnode==NULL)
-    error(EXIT_FAILURE, errno,
-          "linkedlist: new element in gal_fits_key_ll");
+    error(EXIT_FAILURE, errno, "%s: allocating new node", __func__);
   newnode->type=type;
   newnode->keyname=keyname;
   newnode->value=value;
@@ -927,8 +921,7 @@ gal_fits_key_add_to_ll_end(struct gal_fits_key_ll **list, 
uint8_t type,
   errno=0;
   newnode=malloc(sizeof *newnode);
   if(newnode==NULL)
-    error(EXIT_FAILURE, errno,
-          "linkedlist: new element in gal_fits_key_ll");
+    error(EXIT_FAILURE, errno, "%s: allocation of new node", __func__);
   newnode->type=type;
   newnode->keyname=keyname;
   newnode->value=value;
@@ -977,7 +970,8 @@ gal_fits_key_write_filename(char *keynamebase, char 
*filename,
       errno=0;
       keyname=malloc(FLEN_KEYWORD);
       if(keyname==NULL)
-        error(EXIT_FAILURE, errno, "%d bytes", FLEN_KEYWORD);
+        error(EXIT_FAILURE, errno, "%s: %d bytes for `keyname'", __func__,
+              FLEN_KEYWORD);
       sprintf(keyname, "%s_%zu", keynamebase, numkey++);
 
       /* Set the keyword value: */
@@ -985,7 +979,8 @@ gal_fits_key_write_filename(char *keynamebase, char 
*filename,
       thislen=strlen(&filename[i]);
       value=malloc(maxlength);
       if(value==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes", thislen);
+        error(EXIT_FAILURE, errno, "%s: allocating %zu bytes", __func__,
+              thislen);
       strncpy(value, &filename[i], maxlength);
 
       /* If the FROM string (=&filename[i]) in strncpy is shorter than
@@ -1010,9 +1005,9 @@ gal_fits_key_write_filename(char *keynamebase, char 
*filename,
                 break;
               }
           if(j==0)
-            error(EXIT_FAILURE, 0, "the filename `%sP has at least one "
+            error(EXIT_FAILURE, 0, "%s: the filename `%sP has at least one "
                   "span of %zu characters without a `/`. It cannot be "
-                  "written to the header of the output fits file",
+                  "written to the header of the output fits file", __func__,
                   filename, maxlength);
 
           /* Convert the last useful character and save the file name.*/
@@ -1379,10 +1374,10 @@ gal_fits_img_read_kernel(char *filename, char *hdu, 
size_t minmapsize)
   for(i=0;i<kernel->ndim;++i)
     check += kernel->dsize[i]%2;
   if(check!=kernel->ndim)
-    error(EXIT_FAILURE, 0, "the kernel image has to have an odd number "
+    error(EXIT_FAILURE, 0, "%s: the kernel image has to have an odd number "
           "of pixels in all dimensions (there has to be one element/pixel "
           "in the center). At least one of the dimensions of %s (hdu: %s) "
-          "doesn't have an odd number of pixels", filename, hdu);
+          "doesn't have an odd number of pixels", __func__, filename, hdu);
 
   /* If there are any NaN pixels, set them to zero and normalize it. A
      blank pixel in a kernel is going to make a completely blank output.*/
@@ -1499,8 +1494,8 @@ gal_fits_img_write_to_ptr(gal_data_t *input, char 
*filename)
       /* Convert the WCS information to text. */
       status=wcshdo(WCSHDO_safe, towrite->wcs, &nkeyrec, &wcsstr);
       if(status)
-        error(EXIT_FAILURE, 0, "wcshdo ERROR %d: %s", status,
-              wcs_errmsg[status]);
+        error(EXIT_FAILURE, 0, "%s: wcshdo ERROR %d: %s", __func__,
+              status, wcs_errmsg[status]);
       gal_fits_key_write_wcsstr(fptr, wcsstr, nkeyrec);
     }
 
@@ -1582,8 +1577,8 @@ gal_fits_img_write_corr_wcs_str(gal_data_t *data, char 
*filename,
 
   /* The data should not have any WCS structure for this function. */
   if(data->wcs)
-    error(EXIT_FAILURE, 0, "`gal_fits_write_img_wcs_string' can only "
-          "accept inputs with no WCS.");
+    error(EXIT_FAILURE, 0, "%s: input must not have WCS meta-data",
+          __func__);
 
   /* Write the data array into a FITS file and keep it open. */
   fptr=gal_fits_img_write_to_ptr(data, filename);
@@ -1671,21 +1666,21 @@ gal_fits_tab_type(fitsfile *fptr)
       else if(!strcmp(value, "BINTABLE"))
         return GAL_TABLE_FORMAT_BFITS;
       else
-        error(EXIT_FAILURE, 0, "The `XTENSION' keyword of this FITS file "
-              "doesn't have a standard value (`%s')", value);
+        error(EXIT_FAILURE, 0, "%s: the `XTENSION' keyword of this FITS "
+              "table (`%s') doesn't have a standard value", __func__, value);
     }
   else
     {
       if(status==KEY_NO_EXIST)
-        error(EXIT_FAILURE, 0, "the `gal_fits_table_type' function was "
-              "called on a FITS extension which is not a table.");
+        error(EXIT_FAILURE, 0, "%s: input fitsfile pointer isn't a table",
+              __func__);
       else
         gal_fits_io_error(status, NULL);
     }
 
-  error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we can fix it. "
-        "for some reason, the control of `gal_fits_table_type' has reached "
-        "the end of the function! This must not happen", PACKAGE_BUGREPORT);
+  error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we can fix it. 
"
+        "Control should not have reached the end of this function", __func__,
+        PACKAGE_BUGREPORT);
   return -1;
 }
 
@@ -1744,8 +1739,8 @@ set_display_format(char *tdisp, gal_data_t *data, char 
*filename, char *hdu,
 
     default:
       error(EXIT_FAILURE, 0, "%s (hdu: %s): Format character `%c' in the "
-            "value (%s) of the keywork %s not recognized", filename, hdu,
-            tdisp[0], tdisp, keyname);
+            "value (%s) of the keywork %s not recognized in %s", filename, hdu,
+            tdisp[0], tdisp, keyname, __func__);
     }
 
   /* Parse the rest of the string to see if a width and precision are given
@@ -1758,7 +1753,7 @@ set_display_format(char *tdisp, gal_data_t *data, char 
*filename, char *hdu,
       if(*tailptr!='\0')
         error(EXIT_FAILURE, 0, "%s (hdu: %s): The value `%s' of the "
               "`%s' keyword could not recognized (it doesn't finish after "
-              "the precision)", filename, hdu, tdisp, keyname);
+              "the precision) in %s", filename, hdu, tdisp, keyname, __func__);
       break;
 
     case '\0':     /* No precision given, use a default value.     */
@@ -1770,8 +1765,8 @@ set_display_format(char *tdisp, gal_data_t *data, char 
*filename, char *hdu,
     default:
       error(EXIT_FAILURE, 0, "%s (hdu: %s): The value `%s' of the "
             "`%s' keyword could not recognized (it doesn't have a `.', or "
-            "finish, after the width)", filename, hdu, tdisp,
-            keyname);
+            "finish, after the width) in %s", filename, hdu, tdisp,
+            keyname, __func__);
     }
 
 
@@ -1861,13 +1856,13 @@ gal_fits_tab_info(char *filename, char *hdu, size_t 
*numcols,
   errno=0;
   tscal=calloc(tfields, sizeof *tscal);
   if(tscal==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for tscal in "
-          "`gal_fits_table_info'", tfields*sizeof *tscal);
+    error(EXIT_FAILURE, errno, "%s: %zu bytes for tscal", __func__,
+          tfields*sizeof *tscal);
   errno=0;
   tzero=calloc(tfields, sizeof *tzero);
   if(tzero==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for tzero in "
-          "`gal_fits_table_info'", tfields*sizeof *tzero);
+    error(EXIT_FAILURE, errno, "%s: %zu bytes for tzero", __func__,
+          tfields*sizeof *tzero);
 
 
   /* Read all the keywords one by one and if they match, then put them in
@@ -1925,7 +1920,8 @@ gal_fits_tab_info(char *filename, char *hdu, size_t 
*numcols,
                         error(EXIT_FAILURE, 0, "%s (hdu: %s): the value to "
                               "keyword `%s' (`%s') is not in `Aw' format "
                               "(for strings) as required by the FITS "
-                              "standard", filename, hdu, keyname, value);
+                              "standard in %s", filename, hdu, keyname, value,
+                              __func__);
                     }
                   allcols[index].disp_width=repeat;
                 }
@@ -1941,8 +1937,8 @@ gal_fits_tab_info(char *filename, char *hdu, size_t 
*numcols,
               tscal[index]=strtol(value, &tailptr, 0);
               if(*tailptr!='\0')
                 error(EXIT_FAILURE, 0, "%s (hdu: %s): value to %s keyword "
-                      "(`%s') couldn't be read as a number", filename, hdu,
-                      keyname, value);
+                      "(`%s') couldn't be read as a number in %s", filename,
+                      hdu, keyname, value, __func__);
             }
         }
 
@@ -1955,8 +1951,8 @@ gal_fits_tab_info(char *filename, char *hdu, size_t 
*numcols,
               tzero[index]=strtoll(value, &tailptr, 0);
               if(*tailptr!='\0')
                 error(EXIT_FAILURE, 0, "%s (hdu: %s): value to %s keyword "
-                      "(`%s') couldn't be read as a number", filename, hdu,
-                      keyname, value);
+                      "(`%s') couldn't be read as a number in %s", filename,
+                      hdu, keyname, value, __func__);
             }
         }
 
@@ -2076,8 +2072,8 @@ gal_fits_tab_read(char *filename, char *hdu, size_t 
numrows,
             errno=0;
             strarr[i]=calloc(allcols[ind->v].disp_width+1, sizeof *strarr[i]);
             if(strarr[i]==NULL)
-              error(EXIT_FAILURE, errno, "%zu bytes for strarr[%zu] in "
-                    "`gal_fits_table_read'",
+              error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for "
+                    "strarr[%zu]", __func__,
                     (allcols[ind->v].disp_width+1) * sizeof *strarr[i], i);
           }
 
@@ -2129,9 +2125,8 @@ fits_string_fixed_alloc_size(gal_data_t *data)
       errno=0;
       tmp=calloc(maxlen+1, sizeof *strarr[i]);
       if(tmp==NULL)
-        error(EXIT_FAILURE, 0, "%zu bytes for tmp in "
-              "`gal_data_fixed_alloc_size_for_string'",
-              maxlen+1*sizeof *strarr[i]);
+        error(EXIT_FAILURE, 0, "%s: %zu bytes for tmp", __func__,
+              (maxlen+1)*sizeof *strarr[i]);
 
       /* Put the old array into the newly allocated space. `tmp' was
          cleared (all values set to `\0', so we don't need to set the final
@@ -2167,18 +2162,18 @@ fits_table_prepare_arrays(gal_data_t *cols, size_t 
numcols, int tabletype,
   errno=0;
   tform=*outtform=malloc(numcols*sizeof *tform);
   if(tform==NULL)
-    error(EXIT_FAILURE, 0, "%zu bytes for tform in "
-          "`fits_table_prepare_arrays'", numcols*sizeof *tform);
+    error(EXIT_FAILURE, 0, "%s: %zu bytes for tform", __func__,
+          numcols*sizeof *tform);
   errno=0;
   ttype=*outttype=malloc(numcols*sizeof *ttype);
   if(ttype==NULL)
-    error(EXIT_FAILURE, 0, "%zu bytes for ttype in "
-          "`fits_table_prepare_arrays'", numcols*sizeof *ttype);
+    error(EXIT_FAILURE, 0, "%s: %zu bytes for ttype", __func__,
+          numcols*sizeof *ttype);
   errno=0;
   tunit=*outtunit=malloc(numcols*sizeof *tunit);
   if(tunit==NULL)
-    error(EXIT_FAILURE, 0, "%zu bytes for tunit in "
-          "`fits_table_prepare_arrays'", numcols*sizeof *tunit);
+    error(EXIT_FAILURE, 0, "%s: %zu bytes for tunit", __func__,
+          numcols*sizeof *tunit);
 
 
   /* Go over each column and fill in these arrays. */
@@ -2237,8 +2232,8 @@ fits_table_prepare_arrays(gal_data_t *cols, size_t 
numcols, int tabletype,
                 break;
 
               default:
-                error(EXIT_FAILURE, 0, "col->type code %d not recognized "
-                      "fits_table_prepare_arrays", col->type);
+                error(EXIT_FAILURE, 0, "%s: col->type code %d not recognized",
+                      __func__, col->type);
               }
           break;
 
@@ -2257,8 +2252,8 @@ fits_table_prepare_arrays(gal_data_t *cols, size_t 
numcols, int tabletype,
           break;
 
         default:
-          error(EXIT_FAILURE, 0, "tabletype code %d not recognized in "
-                "`fits_table_prepare_arrays'", tabletype);
+          error(EXIT_FAILURE, 0, "%s: tabletype code %d not recognized",
+                __func__, tabletype);
         }
 
 
@@ -2328,8 +2323,8 @@ fits_write_tnull_tcomm(fitsfile *fptr, gal_data_t *col, 
int tabletype,
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "tabletype code %d not recognized in "
-            "`fits_write_tnulls_tcomms'", tabletype);
+      error(EXIT_FAILURE, 0, "%s: tabletype code %d not recognized",
+            __func__, tabletype);
     }
 
   /* Write the comments if there is any. */
@@ -2369,8 +2364,8 @@ gal_fits_tab_write(gal_data_t *cols, gal_list_str_t 
*comments,
     {
       if(numrows==-1) numrows=col->size;
       else if(col->size!=numrows)
-        error(EXIT_FAILURE, 0, "The number of records/rows in the input "
-              "columns to `gal_fits_table_write' are not equal");
+        error(EXIT_FAILURE, 0, "%s: the number of records/rows in the input "
+              "columns are not equal", __func__);
       ++numcols;
     }
 
diff --git a/lib/git.c b/lib/git.c
index b6cdff4..2661863 100644
--- a/lib/git.c
+++ b/lib/git.c
@@ -63,8 +63,8 @@ gal_git_describe(void)
       errno=0;
       describe_return=malloc(strlen(buf.ptr)+1);
       if(describe_return==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes to copy Git's describe",
-              strlen(buf.ptr)+1);
+        error(EXIT_FAILURE, errno, "%s: allocating %zu bytes to copy "
+              "Git's describe", __func__, strlen(buf.ptr)+1);
       strcpy(describe_return, buf.ptr);
     }
 
diff --git a/lib/interpolate.c b/lib/interpolate.c
index 479e2a2..ba3b30f 100644
--- a/lib/interpolate.c
+++ b/lib/interpolate.c
@@ -244,9 +244,9 @@ interpolate_close_neighbors_on_thread(void *in_prm)
              interpolation. Normally, this loop should only be exited
              through the `currentnum>=numnearest' check above. */
           if(sQ==NULL)
-            error(EXIT_FAILURE, 0, "only %zu neighbors found while you had "
-                  "asked to use %zu neighbors for close neighbor "
-                  "interpolation", ngb_counter, prm->numneighbors);
+            error(EXIT_FAILURE, 0, "%s: only %zu neighbors found while "
+                  "you had asked to use %zu neighbors for close neighbor "
+                  "interpolation", __func__, ngb_counter, prm->numneighbors);
         }
 
       /* Calculate the median of the values and write it in the output. */
@@ -388,9 +388,8 @@ gal_interpolate_close_neighbors(gal_data_t *input,
       {
         /* A small sanity check. */
         if( gal_data_dsize_is_different(input, tin) )
-          error(EXIT_FAILURE, 0, "The other datasets in the list must "
-                "have the same dimension and size in "
-                "`gal_interpolate_close_neighbors'");
+          error(EXIT_FAILURE, 0, "%s: all datasets in the list must have "
+                "the same dimension and size", __func__);
 
         /* Allocate the output array for this node. */
         gal_list_data_add_alloc(&prm.out, NULL, tin->type, tin->ndim,
diff --git a/lib/list.c b/lib/list.c
index 638f8c4..2ed56c8 100644
--- a/lib/list.c
+++ b/lib/list.c
@@ -54,8 +54,7 @@ gal_list_str_add(gal_list_str_t **list, char *value,
   errno=0;
   newnode=malloc(sizeof *newnode);
   if(newnode==NULL)
-    error(EXIT_FAILURE, errno,
-          "list: New element in gal_list_stll");
+    error(EXIT_FAILURE, errno, "%s: allocating new node", __func__);
 
   if(allocate)
     gal_checkset_allocate_copy(value, &newnode->v);
@@ -180,8 +179,7 @@ gal_list_i32_add(gal_list_i32_t **list, int32_t value)
   errno=0;
   newnode=malloc(sizeof *newnode);
   if(newnode==NULL)
-    error(EXIT_FAILURE, errno,
-          "list: New element in gal_list_ill");
+    error(EXIT_FAILURE, errno, "%s: allocating new node", __func__);
 
   newnode->v=value;
   newnode->next=*list;
@@ -331,8 +329,7 @@ gal_list_sizet_add(gal_list_sizet_t **list, size_t value)
   errno=0;
   newnode=malloc(sizeof *newnode);
   if(newnode==NULL)
-    error(EXIT_FAILURE, errno,
-          "list: New element in gal_list_sll");
+    error(EXIT_FAILURE, errno, "%s: allocating new node", __func__);
 
   newnode->v=value;
   newnode->next=*list;
@@ -481,8 +478,7 @@ gal_list_f32_add(gal_list_f32_t **list, float value)
   errno=0;
   newnode=malloc(sizeof *newnode);
   if(newnode==NULL)
-    error(EXIT_FAILURE, errno, "list: New element in "
-          "gal_list_f32_t");
+    error(EXIT_FAILURE, errno, "%s: allocating new node", __func__);
 
   newnode->v=value;
   newnode->next=*list;
@@ -639,8 +635,7 @@ gal_list_f64_add(gal_list_f64_t **list, double value)
   errno=0;
   newnode=malloc(sizeof *newnode);
   if(newnode==NULL)
-    error(EXIT_FAILURE, errno, "list: New element in "
-          "gal_list_dll");
+    error(EXIT_FAILURE, errno, "%s: allocating new node", __func__);
 
   newnode->v=value;
   newnode->next=*list;
@@ -796,8 +791,7 @@ gal_list_void_add(gal_list_void_t **list, void *value)
   errno=0;
   newnode=malloc(sizeof *newnode);
   if(newnode==NULL)
-    error(EXIT_FAILURE, errno,
-          "list: New element in gal_list_ill");
+    error(EXIT_FAILURE, errno, "%s: allocating new node", __func__);
 
   newnode->v=value;
   newnode->next=*list;
@@ -908,8 +902,7 @@ gal_list_osizet_add(gal_list_osizet_t **list,
   errno=0;
   newnode=malloc(sizeof *newnode);
   if(newnode==NULL)
-    error(EXIT_FAILURE, errno, "list: New element "
-          "in gal_list_osll");
+    error(EXIT_FAILURE, errno, "%s: allocating new node", __func__);
 
   newnode->v=value;
   newnode->s=tosort;
@@ -1027,8 +1020,7 @@ gal_list_dosizet_add(gal_list_dosizet_t **largest,
   errno=0;
   newnode=malloc(sizeof *newnode);
   if(newnode==NULL)
-    error(EXIT_FAILURE, errno, "list: New element "
-          "in gal_list_tosll");
+    error(EXIT_FAILURE, errno, "%s: allocating new node", __func__);
 
   newnode->v=value;
   newnode->s=tosort;
@@ -1096,10 +1088,9 @@ gal_list_dosizet_pop_smallest(gal_list_dosizet_t 
**largest,
     {
       /* If `smallest' is NULL, `largest' should also be NULL. */
       if(*largest)
-        error(EXIT_FAILURE, 0, "`largest' and `smallest' pointers to "
-              "`gal_list_dosizet_pop_smallest' must both be non-NULL or "
-              "both be NULL. However, in this call, `smallest' was NULL "
-              "while `largest' isn't NULL");
+        error(EXIT_FAILURE, 0, "%s: `largest' and `smallest' pointers must "
+              "both be non-NULL or both be NULL. However, in this call, "
+              "`smallest' was NULL while `largest' isn't NULL", __func__);
       value=GAL_BLANK_SIZE_T;
       *tosort=NAN;
     }
diff --git a/lib/options.c b/lib/options.c
index d78f17a..7172e83 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -147,8 +147,7 @@ options_get_home()
   char *home;
   home=getenv("HOME");
   if(home==NULL)
-    error(EXIT_FAILURE, 0, "the HOME environment variable "
-          "is not defined");
+    error(EXIT_FAILURE, 0, "HOME environment variable not defined");
   return home;
 }
 
@@ -538,11 +537,11 @@ gal_options_parse_sizes_reverse(struct argp_option 
*option, char *arg,
       for(i=num-1;i>=0;--i)
         {
           if( nc > PARSE_SIZES_STATICSTR_LEN-100 )
-            error(EXIT_FAILURE, 0, "a bug! please contact us at %s so we "
+            error(EXIT_FAILURE, 0, "%s: a bug! please contact us at %s so we "
                   "can address the problem. The number of necessary "
-                  "characters in the statically allocated string of "
-                  "`gal_options_parse_sizes' has become too close to %d",
-                  PACKAGE_BUGREPORT, PARSE_SIZES_STATICSTR_LEN);
+                  "characters in the statically allocated string has become "
+                  "too close to %d", __func__, PACKAGE_BUGREPORT,
+                  PARSE_SIZES_STATICSTR_LEN);
           nc += sprintf(sstr+nc, "%zu,", array[i]);
         }
       sstr[nc-1]='\0';
@@ -833,8 +832,8 @@ options_sanity_check(struct argp_option *option, char *arg,
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "range code %d not recognized in "
-            "`gal_options_check_set'", option->range);
+      error(EXIT_FAILURE, 0, "%s: range code %d not recognized",
+            __func__, option->range);
     }
 
 
@@ -949,11 +948,10 @@ gal_options_read_check(struct argp_option *option, char 
*arg, char *filename,
       if(option->type==GAL_OPTIONS_NO_ARG_TYPE)
         *(uint8_t *)(option->value)=1;
       else
-        error(EXIT_FAILURE, 0, "A bug! Please contact us at %s to "
+        error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s to "
               "correct it. Options with no arguments, must have "
-              "type `%s' to be read in `gal_options_read_from_key'. "
-              "However, the `%s' option has type %s",
-              PACKAGE_BUGREPORT,
+              "type `%s'. However, the `%s' option has type %s",
+              __func__, PACKAGE_BUGREPORT,
               gal_type_to_string(GAL_OPTIONS_NO_ARG_TYPE, 1),
               option->name, gal_type_to_string(option->type, 1));
     }
@@ -1259,7 +1257,7 @@ options_parse_file(char *filename,  struct 
gal_options_common_params *cp,
       if(errno==ENOENT && enoent_abort==0)
         return;
       else
-        error(EXIT_FAILURE, errno, "%s: to read as a configuration file",
+        error(EXIT_FAILURE, errno, "%s: to be read as a configuration file",
               filename);
     }
 
@@ -1270,8 +1268,8 @@ options_parse_file(char *filename,  struct 
gal_options_common_params *cp,
   errno=0;
   line=malloc(linelen*sizeof *line);
   if(line==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for `line' in `gal_txt_table_read'",
-          linelen*sizeof *line);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `line'",
+          __func__, linelen*sizeof *line);
 
 
   /* Read the parameters line by line. */
@@ -1303,7 +1301,7 @@ options_parse_file(char *filename,  struct 
gal_options_common_params *cp,
   errno=0;
   if(fclose(fp))
     error(EXIT_FAILURE, errno, "%s: couldn't close after reading as "
-          "a configuration file", filename);
+          "a configuration file in %s", filename, __func__);
 
   /* Clean up and return. */
   free(line);
@@ -1351,10 +1349,9 @@ gal_options_parse_config_files(struct 
gal_options_common_params *cp)
   /* A small sanity check because in multiple places, we have assumed the
      on/off options have a type of `unsigned char'. */
   if(GAL_OPTIONS_NO_ARG_TYPE != GAL_TYPE_UINT8)
-    error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we can fix the "
-          "problem. The `GAL_OPTIONS_NO_ARG_TYPE' must have the "
-          "`unsigned char' type. But",
-          PACKAGE_BUGREPORT);
+    error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we can fix "
+          "the problem. `GAL_OPTIONS_NO_ARG_TYPE' must be the "
+          "`uint8' type", __func__, PACKAGE_BUGREPORT);
 
   /* The program's current directory configuration file. */
   asprintf(&filename, ".%s/%s.conf", PACKAGE, cp->program_exec);
@@ -1545,8 +1542,8 @@ options_correct_max_lengths(struct argp_option *option, 
int *max_nlen,
     {
       /* A small sanity check. */
       if(option->type!=GAL_TYPE_STRLL)
-        error(EXIT_FAILURE, 0, "currently only string linked lists "
-              "are acceptable for printing");
+        error(EXIT_FAILURE, 0, "%s: currently only string linked lists "
+              "are acceptable for printing", __func__);
 
       /* Check each node, one by one. */
       for(tmp=*(gal_list_str_t **)(option->value);
@@ -1728,7 +1725,7 @@ options_print_all(struct gal_options_common_params *cp, 
char *dirname,
       fp=fopen(filename, "w");
       if(fp==NULL)
         error(EXIT_FAILURE, errno, "%s: could't open to write "
-              "configuration file", dirname);
+              "configuration file in %s", dirname, __func__);
 
       /* Print the basic information as comments in the file first. */
       time(&rawtime);
diff --git a/lib/polygon.c b/lib/polygon.c
index e67d17d..bb3c709 100644
--- a/lib/polygon.c
+++ b/lib/polygon.c
@@ -125,12 +125,11 @@ gal_polygon_ordered_corners(double *in, size_t n, size_t 
*ordinds)
     tindexs[GAL_POLYGON_MAX_CORNERS];
 
   if(n>GAL_POLYGON_MAX_CORNERS)
-    error(EXIT_FAILURE, 0, "most probably a bug! The number of corners "
-          "given to `gal_polygon_ordered_corners' is more than %d. This is an "
-          "internal value and cannot be set from the outside. Most probably "
-          "Some bug has caused this un-normal value. Please contact us at "
-          PACKAGE_BUGREPORT" so we can solve this problem",
-          GAL_POLYGON_MAX_CORNERS);
+    error(EXIT_FAILURE, 0, "%s: most probably a bug! The number of corners "
+          "is more than %d. This is an internal value and cannot be set from "
+          "the outside. Most probably some bug has caused this un-normal "
+          "value. Please contact us at %s so we can solve this problem",
+          __func__, GAL_POLYGON_MAX_CORNERS, PACKAGE_BUGREPORT);
 
   /* For a check:
   printf("\n\nBefore sorting:\n");
diff --git a/lib/statistics.c b/lib/statistics.c
index 7ee242a..0daa22e 100644
--- a/lib/statistics.c
+++ b/lib/statistics.c
@@ -246,8 +246,8 @@ statistics_median_in_sorted_no_blank(gal_data_t *sorted, 
void *median)
     case GAL_TYPE_FLOAT32:   MED_IN_SORTED( float    );    break;
     case GAL_TYPE_FLOAT64:   MED_IN_SORTED( double   );    break;
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`gal_statistics_median_in_sorted_no_blank'", sorted->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, sorted->type);
     }
 }
 
@@ -286,9 +286,8 @@ gal_statistics_quantile_index(size_t size, double quant)
   double floatindex;
 
   if(quant<0.0f || quant>1.0f)
-    error(EXIT_FAILURE, 0, "the quantile in `gal_statistics_quantile_index' "
-          "should be between 0.0 and 1.0 (inclusive). You have asked for "
-          "%g", quant);
+    error(EXIT_FAILURE, 0, "%s: the input quantile should be between 0.0 "
+          "and 1.0 (inclusive). You have asked for %g", __func__, quant);
 
   /* Find the index of the quantile. */
   floatindex=(double)(size-1)*quant;
@@ -363,8 +362,8 @@ gal_statistics_quantile_function_index(gal_data_t *input, 
gal_data_t *value,
 
   /* A sanity check. */
   if(nbs->type!=value->type)
-    error(EXIT_FAILURE, 0, "the types of the input dataset and value to "
-          "`gal_statistics_quantile_function' have to be the same");
+    error(EXIT_FAILURE, 0, "%s: the types of the input dataset and requested "
+          "value have to be the same", __func__);
 
   /* Find the result: */
   switch(nbs->type)
@@ -380,8 +379,8 @@ gal_statistics_quantile_function_index(gal_data_t *input, 
gal_data_t *value,
     case GAL_TYPE_FLOAT32:   STATS_QFUNC( float    );     break;
     case GAL_TYPE_FLOAT64:   STATS_QFUNC( double   );     break;
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`gal_statistics_quantile_function'", nbs->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, nbs->type);
     }
 
   /* Clean up and return. */
@@ -547,8 +546,8 @@ mode_mirror_max_index_diff(struct statistics_mode_params 
*p, size_t m)
         case GAL_TYPE_FLOAT32:   MIRR_MAX_DIFF( float    );   break;
         case GAL_TYPE_FLOAT64:   MIRR_MAX_DIFF( double   );   break;
         default:
-          error(EXIT_FAILURE, 0, "type code %d not recognized in "
-                "`mode_mirror_max_diff'", p->data->type);
+          error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+                __func__, p->data->type);
         }
 
       /*
@@ -786,15 +785,14 @@ mode_symmetricity(struct statistics_mode_params *p, 
size_t m, void *b_val)
     case GAL_TYPE_FLOAT32:    MODE_SYM( float    );    break;
     case GAL_TYPE_FLOAT64:    MODE_SYM( double   );    break;
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`mode_symmetricity'", p->data->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, p->data->type);
     }
 
   /* Control shouldn't reach here! */
-  error(EXIT_FAILURE, 0, "a bug! please contact us at %s so we can address "
-        "the problem. For some reason control has reached the end of "
-        "`mode_symmetricity', this should not have happened",
-        PACKAGE_BUGREPORT);
+  error(EXIT_FAILURE, 0, "%s: a bug! please contact us at %s so we can "
+        "address the problem. Control must not have reached the end of this "
+        "function", __func__, PACKAGE_BUGREPORT);
   return NAN;
 }
 
@@ -840,8 +838,8 @@ gal_statistics_mode(gal_data_t *input, float mirrordist, 
int inplace)
 
   /* A small sanity check. */
   if(mirrordist<=0)
-    error(EXIT_FAILURE, 0, "%f not acceptable as a value to `mirrordist'. "
-          "Only positive values can be given to it", mirrordist);
+    error(EXIT_FAILURE, 0, "%s: %f not acceptable as a value to `mirrordist'. "
+          "Only positive values can be given to it", __func__, mirrordist);
 
 
   /* Make sure the input doesn't have blank values and is sorted.  */
@@ -939,10 +937,9 @@ statistics_make_mirror(gal_data_t *noblank_sorted, size_t 
index,
   /* Make sure the index is less than or equal to the number of
      elements. */
   if( index >= noblank_sorted->size )
-    error(EXIT_FAILURE, 0, "the index value to `statistics_make_mirror' "
-          "must be less than or equal to the number of elements in the "
-          "input, but it isn't: index: %zu, size of input: %zu", index,
-          noblank_sorted->size);
+    error(EXIT_FAILURE, 0, "%s: the index value must be less than or equal "
+          "to the number of elements in the input, but it isn't: index: "
+          "%zu, size of input: %zu", __func__, index, noblank_sorted->size);
 
   /* Fill in the mirror array. */
   switch(noblank_sorted->type)
@@ -1072,14 +1069,14 @@ gal_statistics_is_sorted(gal_data_t *data)
     case GAL_TYPE_FLOAT32:   IS_SORTED( float    );    break;
     case GAL_TYPE_FLOAT64:   IS_SORTED( double   );    break;
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`gal_statistics_is_sorted'", data->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, data->type);
     }
 
   /* Control shouldn't reach this point. */
-  error(EXIT_FAILURE, 0, "a bug! Please contact us at %s so we can fix the "
-        "problem. For some reason, control has reached the end of "
-        "`gal_statistics_is_sorted'", PACKAGE_BUGREPORT);
+  error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we can fix the 
"
+        "problem. Control must not have reached the end of this function",
+        __func__, PACKAGE_BUGREPORT);
   return -1;
 }
 
@@ -1118,8 +1115,8 @@ gal_statistics_sort_increasing(gal_data_t *data)
     case GAL_TYPE_FLOAT64:
       STATISTICS_SORT(gal_qsort_float64_increasing);  break;
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`gal_statistics_sort_increasing'", data->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, data->type);
     }
 }
 
@@ -1154,8 +1151,8 @@ gal_statistics_sort_decreasing(gal_data_t *data)
     case GAL_TYPE_FLOAT64:
       STATISTICS_SORT(gal_qsort_float64_decreasing);  break;
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`gal_statistics_sort_decreasing'", data->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, data->type);
     }
 }
 
@@ -1312,8 +1309,8 @@ gal_statistics_regular_bins(gal_data_t *data, gal_data_t 
*inrange,
 
   /* Some sanity checks. */
   if(numbins==0)
-    error(EXIT_FAILURE, 0, "`numbins' in `gal_statistics_regular_bins' "
-          "cannot be given a value of 0");
+    error(EXIT_FAILURE, 0, "%s: `numbins' cannot be given a value of 0",
+          __func__);
 
 
   /* Set the minimum and maximum values. */
@@ -1328,8 +1325,8 @@ gal_statistics_regular_bins(gal_data_t *data, gal_data_t 
*inrange,
       /* Set the minimum and maximum of the bins. */
       ra=range->array;
       if( (range->size)%2 )
-        error(EXIT_FAILURE, 0, "Quantile ranges are not implemented in "
-              "`gal_statistics_regular_bins' yet.");
+        error(EXIT_FAILURE, 0, "%s: quantile ranges are not implemented yet",
+              __func__);
       else
         {
           /* If the minimum isn't set (is blank), find it. */
@@ -1442,17 +1439,16 @@ gal_statistics_histogram(gal_data_t *data, gal_data_t 
*bins, int normalize,
      either use the old implementation, or GSL's histogram
      functionality. */
   if(bins==NULL)
-    error(EXIT_FAILURE, 0, "no `bins' in `gal_statistics_histogram");
+    error(EXIT_FAILURE, 0, "%s: `bins' is NULL", __func__);
   if(bins->status!=GAL_STATISTICS_BINS_REGULAR)
-    error(EXIT_FAILURE, 0, "the input bins to `gal_statistics_histogram' "
-          "are not regular. Currently it is only implemented for regular "
-          "bins");
+    error(EXIT_FAILURE, 0, "%s: the input bins are not regular. Currently "
+          "it is only implemented for regular bins", __func__);
 
 
   /* Check if normalize and `maxone' are not called together. */
   if(normalize && maxone)
-    error(EXIT_FAILURE, 0, "only one of `normalize' and `maxone' may "
-          "be given to `gal_statistics_histogram'");
+    error(EXIT_FAILURE, 0, "%s: only one of `normalize' and `maxone' may "
+          "be given", __func__);
 
 
   /* Allocate the histogram (note that we are clearning it so all values
@@ -1484,8 +1480,8 @@ gal_statistics_histogram(gal_data_t *data, gal_data_t 
*bins, int normalize,
     case GAL_TYPE_FLOAT32:   HISTOGRAM_TYPESET(float);       break;
     case GAL_TYPE_FLOAT64:   HISTOGRAM_TYPESET(double);      break;
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`gal_statistics_histogram'", data->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, data->type);
     }
 
 
@@ -1572,9 +1568,8 @@ gal_statistics_cfp(gal_data_t *data, gal_data_t *bins, 
int normalize)
      either use the old implementation, or GSL's histogram
      functionality. */
   if(bins->status!=GAL_STATISTICS_BINS_REGULAR)
-    error(EXIT_FAILURE, 0, "the input bins to `gal_statistics_cfp' "
-          "are not regular. Currently it is only implemented for regular "
-          "bins");
+    error(EXIT_FAILURE, 0, "%s: the input bins are not regular. Currently "
+          "it is only implemented for regular bins", __func__);
 
 
   /* Prepare the histogram. */
@@ -1624,8 +1619,8 @@ gal_statistics_cfp(gal_data_t *data, gal_data_t *bins, 
int normalize)
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`gal_statistics_cfp'", cfp->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, cfp->type);
     }
 
 
@@ -1742,16 +1737,15 @@ gal_statistics_sigma_clip(gal_data_t *input, float 
multip, float param,
 
   /* Some sanity checks. */
   if( multip<=0 )
-    error(EXIT_FAILURE, 0, "`multip', must be greater than zero in "
-          "`gal_statistics_sigma_clip'. The given value was %g", multip);
+    error(EXIT_FAILURE, 0, "%s: `multip', must be greater than zero. The "
+          "given value was %g", __func__, multip);
   if( param<=0 )
-    error(EXIT_FAILURE, 0, "`param', must be greater than zero in "
-          "`gal_statistics_sigma_clip'. The given value was %g", param);
+    error(EXIT_FAILURE, 0, "%s: `param', must be greater than zero. The "
+          "given value was %g", __func__, param);
   if( param >= 1.0f && ceil(param) != param )
-    error(EXIT_FAILURE, 0, "when `param' is larger than 1.0, it is "
-          "interpretted as an absolute number of clips in "
-          "`gal_statistics_sigma_clip'. So it must be an integer. However, "
-          "your given value %g", param);
+    error(EXIT_FAILURE, 0, "%s: when `param' is larger than 1.0, it is "
+          "interpretted as an absolute number of clips. So it must be an "
+          "integer. However, your given value %g", __func__, param);
 
 
   /* Allocate the necessary spaces. */
@@ -1818,8 +1812,8 @@ gal_statistics_sigma_clip(gal_data_t *input, float 
multip, float param,
         case GAL_TYPE_FLOAT32:   SIGCLIP( float    );   break;
         case GAL_TYPE_FLOAT64:   SIGCLIP( double   );   break;
         default:
-          error(EXIT_FAILURE, 0, "type code %d not recognized in "
-                "`gal_statistics_sigma_clip'", type);
+          error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+                __func__, type);
         }
 
       /* Set the values from this round in the old elements, so the next
@@ -1861,7 +1855,7 @@ gal_statistics_sigma_clip(gal_data_t *input, float 
multip, float param,
 
 
 
-
+#if 0
 /* Using the cumulative distribution function this funciton will
    remove outliers from a dataset. */
 void
@@ -1869,7 +1863,6 @@ gal_statistics_remove_outliers_flat_cdf(float *sorted, 
size_t *outsize)
 {
   printf("\n ... in gal_statistics_remove_outliers_flat_cdf ... \n");
   exit(1);
-#if 0
   int firstfound=0;
   size_t size=*outsize, i, maxind;
   float *slopes, minslope, maxslope;
@@ -1878,9 +1871,8 @@ gal_statistics_remove_outliers_flat_cdf(float *sorted, 
size_t *outsize)
      you want to think about slopes. */
   errno=0; slopes=malloc(size*sizeof *slopes);
   if(slopes==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for slopes in "
-          "gal_statistics_remove_outliers_flat_cdf (statistics.c)",
-          size*sizeof *slopes);
+    error(EXIT_FAILURE, errno, "%s: %zu bytes for slopes",
+          __func__, size*sizeof *slopes);
 
   /* Calcuate the slope of the CDF and put it in the slopes array. */
   for(i=1;i<size-1;++i)
@@ -1919,5 +1911,5 @@ gal_statistics_remove_outliers_flat_cdf(float *sorted, 
size_t *outsize)
   */
 
   free(slopes);
-#endif
 }
+#endif
diff --git a/lib/table.c b/lib/table.c
index 428d725..1814dc3 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -120,8 +120,7 @@ gal_table_format_as_string(uint8_t format)
     case GAL_TABLE_FORMAT_AFITS:  return "fits-ascii";
     case GAL_TABLE_FORMAT_BFITS:  return "fits-binary";
     default:
-      error(EXIT_FAILURE, 0, "code %d not recognized as a valid format "
-            "in `gal_table_format_as_string'", format);
+      error(EXIT_FAILURE, 0, "%s: code %d not recognized", __func__, format);
       return NULL;
     }
 }
@@ -161,8 +160,8 @@ gal_table_searchin_as_string(uint8_t searchin)
     case GAL_TABLE_SEARCH_UNIT:    return "unit";
     case GAL_TABLE_SEARCH_COMMENT: return "comment";
     default:
-      error(EXIT_FAILURE, 0, "code %d not recognized as a valid search "
-            "field in `gal_table_searchin_as_string'", searchin);
+      error(EXIT_FAILURE, 0, "%s: code %d not recognized as a valid search "
+            "field", __func__, searchin);
       return NULL;
     }
 }
@@ -301,8 +300,8 @@ gal_table_col_print_info(gal_data_t *col, int tableformat, 
char *fmt,
     case GAL_TABLE_FORMAT_AFITS:
       break;
     default:
-      error(EXIT_FAILURE, 0, "tableformat code %d not recognized in "
-            "`gal_table_col_print_info'", tableformat);
+      error(EXIT_FAILURE, 0, "%s: tableformat code %d not recognized",
+            __func__, tableformat);
     }
 
 
@@ -314,8 +313,8 @@ gal_table_col_print_info(gal_data_t *col, int tableformat, 
char *fmt,
   switch(col->type)
     {
     case GAL_TYPE_BIT:
-      error(EXIT_FAILURE, 0, "printing of bit types is currently "
-            "not supported");
+      error(EXIT_FAILURE, 0, "%s: printing of bit types is currently "
+            "not supported", __func__);
       break;
 
 
@@ -425,8 +424,8 @@ gal_table_col_print_info(gal_data_t *col, int tableformat, 
char *fmt,
 
 
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`gal_table_col_print_info'", col->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, col->type);
     }
 
   /* Write the final width and precision into the column's data structure. */
@@ -454,9 +453,8 @@ gal_table_read_blank(gal_data_t *col, char *blank)
 
   /* Just for a sanity check, the ndim and array elements should be zero. */
   if(col->ndim || col->array)
-    error(EXIT_FAILURE, 0, "A bug! The number of dimensions, and the pointer "
-          "to the array in the data structure passed "
-          "`to gal_table_read_blank' must be zero");
+    error(EXIT_FAILURE, 0, "%s: a bug! The number of dimensions, and the "
+          "`array' element of a column must be zero", __func__);
 
   /* Read the blank value as the given type. If successful, then
      `gal_data_string_to_type' will return 0. In that case, we need to
@@ -467,8 +465,8 @@ gal_table_read_blank(gal_data_t *col, char *blank)
       errno=0;
       col->dsize=malloc(sizeof *col->dsize);
       if(col->dsize==NULL)
-        error(EXIT_FAILURE, 0, "%zu bytes for `col->dsize' in "
-              "`txt_read_blank' ", sizeof *col->dsize);
+        error(EXIT_FAILURE, 0, "%s: allocating %zu bytes for `col->dsize'",
+              __func__, sizeof *col->dsize);
       col->dsize[0]=col->ndim=col->size=1;
     }
 }
@@ -519,9 +517,9 @@ gal_table_info(char *filename, char *hdu, size_t *numcols, 
size_t *numrows,
     }
 
   /* Abort with an error if we get to this point. */
-  error(EXIT_FAILURE, 0, "A bug! please contact us at %s so we can fix "
-        "the problem. For some reason, control has reached the end of "
-        "`gal_table_info'", PACKAGE_BUGREPORT);
+  error(EXIT_FAILURE, 0, "%s: a bug! please contact us at %s so we can fix "
+        "the problem. Control must not have reached the end of this function",
+        __func__, PACKAGE_BUGREPORT);
   return NULL;
 }
 
@@ -559,11 +557,12 @@ regexerrorexit(int errcode, regex_t *compiled, char 
*input)
   errno=0;
   regexerrbuf=malloc(length);
   if(regexerrbuf==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for regexerrbuf", length);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for regexerrbuf",
+          __func__, length);
   (void) regerror(errcode, compiled, regexerrbuf, length);
 
-  error(EXIT_FAILURE, 0, "Regular expression error: %s in value to "
-        "`--column' (`-c'): `%s'", regexerrbuf, input);
+  error(EXIT_FAILURE, 0, "%s: regular expression error: %s in value to "
+        "`--column' (`-c'): `%s'", __func__, regexerrbuf, input);
 }
 
 
@@ -586,13 +585,13 @@ table_set_strcheck(gal_data_t *col, int searchin)
       return col->comment;
 
     default:
-      error(EXIT_FAILURE, 0, "the code %d to searchin was not "
-            "recognized in `table_set_strcheck'", searchin);
+      error(EXIT_FAILURE, 0, "%s: the code %d to searchin was not "
+            "recognized", __func__, searchin);
     }
 
-  error(EXIT_FAILURE, 0, "A bug! Please contact us at %s, For some reason "
-        "control has reached the end of `table_set_strcheck'. This must "
-        "not have happened", PACKAGE_BUGREPORT);
+  error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we can "
+        "address the problem. Control must not have reached the end of "
+        "this function", __func__, PACKAGE_BUGREPORT);
   return NULL;
 }
 
@@ -633,7 +632,8 @@ make_list_of_indexs(gal_list_str_t *cols, gal_data_t 
*allcols,
           errno=0;
           regex=malloc(sizeof *regex);
           if(regex==NULL)
-            error(EXIT_FAILURE, errno, "%zu bytes for regex", sizeof *regex);
+            error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for regex",
+                  __func__, sizeof *regex);
 
           /* First we have to "compile" the string into the regular
              expression, see the "POSIX Regular Expression Compilation"
@@ -695,9 +695,9 @@ make_list_of_indexs(gal_list_str_t *cols, gal_data_t 
*allcols,
             {
               /* Make sure the number is larger than zero! */
               if(tlong<=0)
-                error(EXIT_FAILURE, 0, "column numbers must be positive "
+                error(EXIT_FAILURE, 0, "%s: column numbers must be positive "
                       "(not zero or negative). You have asked for column "
-                      "number %ld", tlong);
+                      "number %ld", __func__, tlong);
 
               /* Check if the given value is not larger than the number of
                  columns in the input catalog (note that the user is
@@ -822,8 +822,8 @@ gal_table_read(char *filename, char *hdu, gal_list_str_t 
*cols,
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "table format code %d not recognized for "
-            "`tableformat' in `gal_table_read_cols'", tableformat);
+      error(EXIT_FAILURE, 0, "%s: table format code %d not recognized for "
+            "`tableformat'", __func__, tableformat);
     }
 
   /* Clean up. */
diff --git a/lib/threads.c b/lib/threads.c
index a4d99ef..16883b8 100644
--- a/lib/threads.c
+++ b/lib/threads.c
@@ -56,20 +56,20 @@ pthread_barrier_init(pthread_barrier_t *b, 
pthread_barrierattr_t *attr,
   if(limit==0)
     {
       errno = EINVAL;
-      error(EXIT_FAILURE, errno, "in pthread_barrier_init, limit is zero");
+      error(EXIT_FAILURE, errno, "%s: limit is zero", __func__);
     }
 
   /* Initialize the mutex: */
   err=pthread_mutex_init(&b->mutex, 0);
   if(err)
-    error(EXIT_FAILURE, err, "inializing mutex in pthread_barrier_init");
+    error(EXIT_FAILURE, err, "%s: inializing mutex", __func__);
 
   /* Initialize the condition variable: */
   err=pthread_cond_init(&b->cond, 0);
   if(err)
     {
       pthread_mutex_destroy(&b->mutex);
-      error(EXIT_FAILURE, err, "inializing cond in pthread_barrier_init");
+      error(EXIT_FAILURE, err, "%s: inializing cond", __func__);
     }
 
   /* set the values: */
@@ -195,7 +195,7 @@ gal_threads_dist_in_threads(size_t numactions, size_t 
numthreads,
   errno=0;
   thrds=*outthrds=malloc(numthreads*thrdcols*sizeof *thrds);
   if(thrds==NULL)
-    error(EXIT_FAILURE, errno, "allocating thrds in prepindexsinthreads");
+    error(EXIT_FAILURE, errno, "%s: allocating thrds", __func__);
 
   /* Initialize all the elements to NONINDEX. */
   fp=(sp=thrds)+numthreads*thrdcols;
@@ -230,11 +230,12 @@ gal_threads_attr_barrier_init(pthread_attr_t *attr, 
pthread_barrier_t *b,
   int err;
 
   err=pthread_attr_init(attr);
-  if(err) error(EXIT_FAILURE, 0, "thread attr not initialized");
+  if(err) error(EXIT_FAILURE, 0, "%s: thread attr not initialized", __func__);
   err=pthread_attr_setdetachstate(attr, PTHREAD_CREATE_DETACHED);
-  if(err) error(EXIT_FAILURE, 0, "thread attr not detached");
+  if(err) error(EXIT_FAILURE, 0, "%s: thread attr not detached", __func__);
   err=pthread_barrier_init(b, NULL, limit);
-  if(err) error(EXIT_FAILURE, 0, "thread barrier not initialized");
+  if(err) error(EXIT_FAILURE, 0, "%s: thread barrier not initialized",
+                __func__);
 }
 
 
@@ -341,8 +342,8 @@ gal_threads_spin_off(void *(*function)(void *), void 
*caller_params,
 
   /* Sanity check. */
   if(numthreads==0)
-    error(EXIT_FAILURE, 0, "the number of threads (`numthreads') in "
-          "`gal_threads_spin_off' cannot be zero");
+    error(EXIT_FAILURE, 0, "%s: the number of threads (`numthreads') "
+          "cannot be zero", __func__);
 
   /* Allocate the array of parameters structure structures. */
   errno=0;
diff --git a/lib/tile.c b/lib/tile.c
index 3cb8e6b..c274b20 100644
--- a/lib/tile.c
+++ b/lib/tile.c
@@ -352,14 +352,14 @@ gal_tile_block_increment(gal_data_t *block, size_t *tsize,
   size_t *b=block->dsize, *t=tsize;
 
   if(n>3)
-    error(EXIT_FAILURE, 0, "`gal_tile_block-increment' is currently only "
-          "implemented for at most 3 dimensions");
+    error(EXIT_FAILURE, 0, "%s: currently only implemented for at most 3 "
+          "dimensions", __func__);
 
   switch(n)
     {
     case 0:
-      error(EXIT_FAILURE, 0, "zero dimensional input is not acceptable in "
-            "`gal_tile_block_parse'");
+      error(EXIT_FAILURE, 0, "%s: zero dimensional input is not acceptable",
+            __func__);
 
     /* 1D: the increment is just the tile size. */
     case 1:
@@ -432,9 +432,8 @@ gal_tile_block_write_const_value(gal_data_t *tilevalues, 
gal_data_t *tilesll,
   /* A small sanity check. */
   for(tile=tilesll; tile!=NULL; tile=tile->next) ++nt;
   if(nt!=nv)
-    error(EXIT_FAILURE, 0, "the number of elements in `tilevalues' (%zu) "
-          "and `tilesll' (%zu) must be the same in "
-          "`gal_tile_block_write_const_value'", nv, nt);
+    error(EXIT_FAILURE, 0, "%s: the number of elements in `tilevalues' (%zu) "
+          "and `tilesll' (%zu) must be the same", __func__, nv, nt);
 
   /* Allocate the output array. */
   tofill=gal_data_alloc(NULL, type, block->ndim, block->dsize, block->wcs,
@@ -921,10 +920,9 @@ gal_tile_full_two_layers(gal_data_t *input,
   tl->totchannels = gal_dimension_total_size(ndim, tl->numchannels);
   for(i=0;i<ndim;++i)
     if(junk[i]!=tl->numchannels[i])
-      error(EXIT_FAILURE, 0, "the input and output number of channels in "
-            "`gal_tile_full_two_layers' don't match in dimension %zu, with "
-            "values of %zu and %zu respectively.", ndim-i,
-            tl->numchannels[i], junk[i]);
+      error(EXIT_FAILURE, 0, "%s: the input and output number of channels "
+            "don't match in dimension %zu: %zu and %zu respectively.",
+            __func__, ndim-i, tl->numchannels[i], junk[i]);
   free(junk);
   free(junk2);
 
@@ -1090,8 +1088,8 @@ gal_tile_full_values_write(gal_data_t *tilevalues,
         {
           /* A small sanity check. */
           if(tl->permutation==NULL)
-            error(EXIT_FAILURE, 0, "no permutation defined for the input "
-                  "tessellation to `gal_tile_full_values_write'");
+            error(EXIT_FAILURE, 0, "%s: no permutation defined for the input "
+                  "tessellation", __func__);
 
           /* Writing tile values to disk is not done for checking, not for
              efficiency. So to be safe (allow the caller to work on
@@ -1129,8 +1127,8 @@ gal_tile_full_values_smooth(gal_data_t *tilevalues,
 
   /* Check if the width is odd. */
   if(width%2==0)
-    error(EXIT_FAILURE, 0, "%zu not acceptable as width to "
-          "`gal_tile_full_values_smooth'. It has to be an odd number", width);
+    error(EXIT_FAILURE, 0, "%s: %zu not acceptable as width. It has to be "
+          "an odd number", __func__, width);
 
 
   /* Prepare the kernel size along every dimension. */
diff --git a/lib/txt.c b/lib/txt.c
index 24a7085..f67e6dd 100644
--- a/lib/txt.c
+++ b/lib/txt.c
@@ -522,8 +522,8 @@ txt_get_info(char *filename, int format, size_t *numdata, 
size_t *dsize)
     case TXT_FORMAT_TABLE: format_err="table"; comm_start="# Column "; break;
     case TXT_FORMAT_IMAGE: format_err="image"; comm_start="# Image ";  break;
     default:
-      error(EXIT_FAILURE, 0, "code %d not recognized in `txt_get_info'",
-            format);
+      error(EXIT_FAILURE, 0, "%s: code %d not recognized",
+            __func__, format);
     }
 
 
@@ -531,8 +531,8 @@ txt_get_info(char *filename, int format, size_t *numdata, 
size_t *dsize)
   errno=0;
   fp=fopen(filename, "r");
   if(fp==NULL)
-    error(EXIT_FAILURE, errno, "%s: could't open to read as a plain text %s",
-          filename, format_err);
+    error(EXIT_FAILURE, errno, "%s: could't open to read as a plain "
+          "text %s in %s", filename, format_err, __func__);
 
 
   /* Allocate the space necessary to keep each line as we parse it. Note
@@ -541,8 +541,8 @@ txt_get_info(char *filename, int format, size_t *numdata, 
size_t *dsize)
   errno=0;
   line=malloc(linelen*sizeof *line);
   if(line==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for line in `txt_get_info'",
-          linelen*sizeof *line);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for line",
+          __func__, linelen*sizeof *line);
 
 
   /* Read the comments of the line for possible information about the
@@ -590,7 +590,7 @@ txt_get_info(char *filename, int format, size_t *numdata, 
size_t *dsize)
   errno=0;
   if(fclose(fp))
     error(EXIT_FAILURE, errno, "%s: couldn't close file after reading plain "
-          "text %s information", filename, format_err);
+          "text %s information in %s", filename, format_err, __func__);
 
 
   /* Return the array of column information. */
@@ -738,8 +738,8 @@ txt_read_token(gal_data_t *data, gal_data_t *info, char 
*token,
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`txt_fill_columns'", data->type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, data->type);
     }
 
   /* If a number couldn't be read properly, then report an error. */
@@ -830,8 +830,8 @@ txt_fill(char *line, char **tokens, size_t maxcolnum, 
gal_data_t *info,
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "`txt_fill' only works for 1 and 2 "
-            "dimensional datasets");
+      error(EXIT_FAILURE, 0, "%s: currently only 1 and 2 dimensional "
+            "datasets acceptable", __func__);
     }
 }
 
@@ -855,8 +855,8 @@ gal_txt_read(char *filename, size_t *dsize, gal_data_t 
*info,
   errno=0;
   fp=fopen(filename, "r");
   if(fp==NULL)
-    error(EXIT_FAILURE, errno, "%s: could't open to read as a text table",
-          filename);
+    error(EXIT_FAILURE, errno, "%s: could't open to read as a text table "
+          "in %s", filename, __func__);
 
   /* Allocate the space necessary to keep a copy of each line as we parse
      it. Note that `getline' is going to later `realloc' this space to fit
@@ -864,8 +864,8 @@ gal_txt_read(char *filename, size_t *dsize, gal_data_t 
*info,
   errno=0;
   line=malloc(linelen*sizeof *line);
   if(line==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for `line' in `gal_txt_table_read'",
-          linelen*sizeof *line);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `line'",
+          __func__, linelen*sizeof *line);
 
   /* Allocate all the desired columns for output. We will be reading the
      text file line by line, and writing in the necessary values of each
@@ -891,9 +891,9 @@ gal_txt_read(char *filename, size_t *dsize, gal_data_t 
*info,
     /* This is an image. */
     case TXT_FORMAT_IMAGE:
       if(info->next)
-        error(EXIT_FAILURE, 0, "currently reading only one image (2d "
-              "array) from a text file is possible, the `info' input to "
-              "`gal_txt_read' has more than one element");
+        error(EXIT_FAILURE, 0, "%s: currently reading only one image (2d "
+              "array) from a text file is possible, the `info' input has "
+              "more than one element", __func__);
       ndim=2;
       maxcolnum=dsize[1];
       out=gal_data_alloc(NULL, info->type, ndim, dsize, NULL, 0, minmapsize,
@@ -903,8 +903,8 @@ gal_txt_read(char *filename, size_t *dsize, gal_data_t 
*info,
 
     /* Not recognized. */
     default:
-      error(EXIT_FAILURE, 0, "format code %d not recognized in "
-            "`gal_txt_read'", format);
+      error(EXIT_FAILURE, 0, "%s: format code %d not recognized",
+            __func__, format);
     }
 
   /* Allocate the space to keep the pointers to each token in the
@@ -915,8 +915,8 @@ gal_txt_read(char *filename, size_t *dsize, gal_data_t 
*info,
   errno=0;
   tokens=malloc((maxcolnum+1)*sizeof *tokens);
   if(tokens==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for `tokens' in "
-          "`gal_txt_table_read'", (maxcolnum+1)*sizeof *tokens);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `tokens'",
+          __func__, (maxcolnum+1)*sizeof *tokens);
 
   /* Read the data columns. */
   while( getline(&line, &linelen, fp) != -1 )
@@ -931,7 +931,7 @@ gal_txt_read(char *filename, size_t *dsize, gal_data_t 
*info,
   errno=0;
   if(fclose(fp))
     error(EXIT_FAILURE, errno, "%s: couldn't close file after reading ASCII "
-          "table information", filename);
+          "table information in %s", filename, __func__);
   free(tokens);
   free(line);
 
@@ -1017,8 +1017,8 @@ make_fmts_for_printf(gal_data_t *datall, int leftadjust, 
size_t *len)
   errno=0;
   fmts=malloc(FMTS_COLS*num*sizeof *fmts);
   if(fmts==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for fmts in `make_fmts_for_printf'",
-          FMTS_COLS*num*sizeof *fmts);
+    error(EXIT_FAILURE, errno, "%s: %zu bytes for fmts",
+          __func__, FMTS_COLS*num*sizeof *fmts);
 
 
   /* Initialize the length to 0. */
@@ -1033,9 +1033,8 @@ make_fmts_for_printf(gal_data_t *datall, int leftadjust, 
size_t *len)
       fmts[ i*FMTS_COLS   ] = malloc(GAL_TXT_MAX_FMT_LENGTH*sizeof **fmts);
       fmts[ i*FMTS_COLS+1 ] = malloc(GAL_TXT_MAX_FMT_LENGTH*sizeof **fmts);
       if(fmts[i*FMTS_COLS]==NULL || fmts[i*FMTS_COLS+1]==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for fmts[%zu] or fmts[%zu] "
-              "in `make_fmts_for_printf' of txt.c",
-              GAL_TXT_MAX_FMT_LENGTH*sizeof **fmts,
+        error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for fmts[%zu] "
+              "or fmts[%zu]", __func__, GAL_TXT_MAX_FMT_LENGTH*sizeof **fmts,
               i*FMTS_COLS, i*FMTS_COLS+1);
 
 
@@ -1126,8 +1125,8 @@ txt_print_value(FILE *fp, void *array, int type, size_t 
ind, char *fmt)
       break;
 
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized for "
-            "col->type in `txt_print_value'", type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, type);
     }
 }
 
@@ -1154,7 +1153,7 @@ txt_open_file_write_info(gal_data_t *datall, char **fmts,
   fp=fopen(filename, "w");
   if(fp==NULL)
     error(EXIT_FAILURE, errno, "%s: couldn't be open to write text "
-          "table", filename);
+          "table by %s", filename, __func__);
 
 
   /* Write the comments if there were any. */
@@ -1240,9 +1239,9 @@ gal_txt_write(gal_data_t *datall, gal_list_str_t 
*comment, char *filename,
 
   /* Currently only 1 and 2 dimension datasets are acceptable. */
   if( datall->ndim!=1 && datall->ndim!=2 )
-    error(EXIT_FAILURE, 0, "currently `gal_txt_write' only supports 1 and "
-          "2 dimensional datasets. The input dataset has %zu dimensions",
-          datall->ndim);
+    error(EXIT_FAILURE, 0, "%s: only 1 and 2 dimensional datasets are "
+          "currently supported. The input dataset has %zu dimensions",
+          __func__, datall->ndim);
 
 
   /* For a 2D dataset, we currently don't accept a list, we can only print
@@ -1265,9 +1264,9 @@ gal_txt_write(gal_data_t *datall, gal_list_str_t 
*comment, char *filename,
       /* Check if the dimensionality and size is the same for all the
          elements. */
       if( datall!=data && gal_data_dsize_is_different(datall, data) )
-        error(EXIT_FAILURE, 0, "the input list of datasets to "
-              "`gal_txt_write' must have the same sizes (dimentionality "
-              "and length along each dimension).");
+        error(EXIT_FAILURE, 0, "%s: the input list of datasets must have the "
+              "same sizes (dimentionality and length along each dimension)",
+              __func__);
     }
 
 
@@ -1311,8 +1310,8 @@ gal_txt_write(gal_data_t *datall, gal_list_str_t 
*comment, char *filename,
 
 
     default:
-      error(EXIT_FAILURE, 0, "a bug! datall->ndim=%zu is not recognized "
-            "in `gal_txt_write'", datall->ndim);
+      error(EXIT_FAILURE, 0, "%s: a bug! datall->ndim=%zu is not recognized",
+            __func__, datall->ndim);
     }
 
 
@@ -1333,7 +1332,7 @@ gal_txt_write(gal_data_t *datall, gal_list_str_t 
*comment, char *filename,
       errno=0;
       if(fclose(fp))
         error(EXIT_FAILURE, errno, "%s: couldn't close file after writing "
-              "of text table", filename);
+              "of text table in %s", filename, __func__);
     }
 
   /* Restore the next pointer for a 2D dataset. */
diff --git a/lib/type.c b/lib/type.c
index 3e4eaf7..12a644b 100644
--- a/lib/type.c
+++ b/lib/type.c
@@ -41,8 +41,8 @@ gal_type_sizeof(uint8_t type)
   switch(type)
     {
     case GAL_TYPE_BIT:
-      error(EXIT_FAILURE, 0, "Currently Gnuastro doesn't support bit "
-            "types, please get in touch with us to implement it.");
+      error(EXIT_FAILURE, 0, "%s: bit types are not currently supported, "
+            "please get in touch with us to implement it", __func__);
 
       /* The parenthesis after sizeof is not a function, it is actually a
          type cast, so we have put a space between size of and the
@@ -59,35 +59,39 @@ gal_type_sizeof(uint8_t type)
 
     case GAL_TYPE_FLOAT32:
       if( sizeof (float) != 4 )
-        error(EXIT_FAILURE, 0, "`float` is not 32 bits on this machine");
+        error(EXIT_FAILURE, 0, "%s: `float' is not 32 bits on this machine",
+              __func__);
       return sizeof (float);
 
     case GAL_TYPE_FLOAT64:
       if( sizeof (double) != 8 )
-        error(EXIT_FAILURE, 0, "`double` is not 64 bits on this machine");
+        error(EXIT_FAILURE, 0, "%s: `double' is not 64 bits on this machine",
+              __func__);
       return sizeof (double);
 
     case GAL_TYPE_COMPLEX32:
       if( sizeof (float) != 4 )
-        error(EXIT_FAILURE, 0, "`float` is not 32 bits on this machine");
+        error(EXIT_FAILURE, 0, "%s: `float' is not 32 bits on this machine",
+              __func__);
       return sizeof (gsl_complex_float);
 
     case GAL_TYPE_COMPLEX64:
       if( sizeof (double) != 8 )
-        error(EXIT_FAILURE, 0, "`double` is not 64 bits on this machine");
+        error(EXIT_FAILURE, 0, "%s: `double` is not 64 bits on this machine",
+              __func__);
       return sizeof (gsl_complex);
 
     case GAL_TYPE_STRING:
       return sizeof (char *);
 
     default:
-      error(EXIT_FAILURE, 0, "type value of %d not recognized in "
-            "gal_data_sizeof", type);
+      error(EXIT_FAILURE, 0, "%s: type value of %d not recognized",
+            __func__, type);
     }
 
-  error(EXIT_FAILURE, 0, "Control has reached the end of `gal_data_sizeof' "
-        "This is a bug! Please contact us at %s so we can find the cause "
-        "of the problem.", PACKAGE_BUGREPORT);
+  error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we can find "
+        "the cause of the problem. Control should not have reached the end of "
+        "this function", __func__, PACKAGE_BUGREPORT);
   return -1;
 }
 
@@ -146,16 +150,15 @@ gal_type_to_string(uint8_t type, int long_name)
       if(long_name) return "string linked list";  else return "strll";
 
     default:
-      error(EXIT_FAILURE, 0, "type value of %d not recognized in "
-            "`gal_data_type_as_string'", type);
+      error(EXIT_FAILURE, 0, "%s: type value of %d not recognized",
+            __func__, type);
     }
 
   /* Any of the cases above should return this function, so if control
      reaches here, there is a bug. */
-  error(EXIT_FAILURE, 0, "a bug! Please contact us at %s so we can address "
-        "the problem. For some reason control has reached the end of "
-        "the `gal_data_type_as_string' function. This must not happen",
-        PACKAGE_BUGREPORT);
+  error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we can "
+        "address the problem. Control should not have reached the end of "
+        "this function", __func__, PACKAGE_BUGREPORT);
   return NULL;
 }
 
@@ -213,10 +216,9 @@ gal_type_from_string(char *str)
 
   /* Any of the cases above should return this function, so if control
      reaches here, there is a bug. */
-  error(EXIT_FAILURE, 0, "a bug! Please contact us at %s so we can address "
-        "the problem. For some reason control has reached the end of "
-        "the `gal_data_string_as_type' function. This must not happen",
-        PACKAGE_BUGREPORT);
+  error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s so we can "
+        "address the problem. Control must not have reached the end of this "
+        "function", __func__, PACKAGE_BUGREPORT);
   return 0;
 }
 
@@ -243,8 +245,7 @@ gal_type_min(uint8_t type, void *in)
     case GAL_TYPE_FLOAT32:      *(float *)    in = -FLT_MAX;     break;
     case GAL_TYPE_FLOAT64:      *(double *)   in = -DBL_MAX;     break;
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`gal_data_type_min'", type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized", __func__, 
type);
     }
 }
 
@@ -268,8 +269,7 @@ gal_type_max(uint8_t type, void *in)
     case GAL_TYPE_FLOAT32:      *(float *)    in = FLT_MAX;      break;
     case GAL_TYPE_FLOAT64:      *(double *)   in = DBL_MAX;      break;
     default:
-      error(EXIT_FAILURE, 0, "type code %d not recognized in "
-            "`gal_data_type_min'", type);
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized", __func__, 
type);
     }
 }
 
diff --git a/lib/wcs.c b/lib/wcs.c
index a8f6153..ae9f5b0 100644
--- a/lib/wcs.c
+++ b/lib/wcs.c
@@ -137,8 +137,8 @@ gal_wcs_read_from_fitsptr(fitsfile *fptr, int *nwcs, struct 
wcsprm **wcs,
 
   /* Initialize the wcsprm struct
   if ((status = wcsset(*wcs)))
-    error(EXIT_FAILURE, 0, "wcsset ERROR %d: %s.\n", status,
-          wcs_errmsg[status]);
+    error(EXIT_FAILURE, 0, "%s: wcsset ERROR %d: %s.\n", __func__,
+          status, wcs_errmsg[status]);
   */
 }
 
@@ -199,8 +199,8 @@ gal_wcs_copy(struct wcsprm *in, size_t ndim)
       errno=0;
       out=malloc(sizeof *out);
       if(out==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for out in `gal_wcs_copy'",
-              sizeof *out);
+        error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `out'",
+              __func__, sizeof *out);
 
       /* Initialize the allocated WCS structure. The WCSLIB manual says "On
          the first invokation, and only the first invokation, wcsprm::flag
@@ -283,8 +283,8 @@ gal_wcs_warp_matrix(struct wcsprm *wcs)
   errno=0;
   out=malloc(size*sizeof *out);
   if(out==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for `out' in "
-          "`gal_wcs_array_from_wcsprm'", size*sizeof *out);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `out'",
+          __func__, size*sizeof *out);
 
   /* Fill in the array. */
   if(wcs->altlin & 0x1)        /* Has a PCi_j array. */
@@ -299,8 +299,8 @@ gal_wcs_warp_matrix(struct wcsprm *wcs)
         out[i]=wcs->cd[i];
     }
   else
-    error(EXIT_FAILURE, 0, "currently, `gal_wcs_array_from_wcsprm' only "
-          "recognizes PCi_ja and CDi_ja keywords");
+    error(EXIT_FAILURE, 0, "%s: currently only PCi_ja and CDi_ja keywords "
+          "are recognized", __func__);
 
   /* Return the result */
   return out;
@@ -413,12 +413,12 @@ gal_wcs_pixel_scale_deg(struct wcsprm *wcs)
   /* Allocate space for the `v' and `pixscale' arrays. */
   errno=0; v=malloc(n*n*sizeof *v);
   if(v==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for `v' in "
-          "`gal_wcs_pixel_scale_deg'", n*n*sizeof *v);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `v'",
+          __func__, n*n*sizeof *v);
   errno=0; pixscale=malloc(n*sizeof *pixscale);
   if(pixscale==NULL)
-    error(EXIT_FAILURE, errno, "%zu bytes for `pixscale' in "
-          "`gal_wcs_pixel_scale_deg'", n*sizeof *pixscale);
+    error(EXIT_FAILURE, errno, "%s: allocating %zu bytes for `pixscale'",
+          __func__, n*sizeof *pixscale);
 
   /* Write the full matrix into an array, irrespective of what type it was
      stored in the wcsprm structure (`PCi_j' style or `CDi_j' style). */
@@ -459,8 +459,8 @@ gal_wcs_pixel_area_arcsec2(struct wcsprm *wcs)
      can find which ones correlate to RA and Dec and use them to find the
      pixel area in arcsec^2. */
   if(wcs->naxis!=2)
-    error(EXIT_FAILURE, 0, "`gal_wcs_pixel_area_arcsec2' can currently "
-          "calculate the area only when the image has 2 dimensions.");
+    error(EXIT_FAILURE, 0, "%s: currently only 2D datasets supported. "
+          "The input WCS has %d dimensions", __func__, wcs->naxis);
 
   /* Get the pixel scales along each axis in degrees, then multiply. */
   pixscale=gal_wcs_pixel_scale_deg(wcs);
@@ -522,7 +522,7 @@ gal_wcs_world_to_img(struct wcsprm *wcs, double *ra, double 
*dec,
   /* Use WCSLIB's `wcss2p'. */
   status=wcss2p(wcs, ncoord, nelem, world, phi, theta, imgcrd, pixcrd, stat);
   if(status)
-    error(EXIT_FAILURE, 0, "wcss2p ERROR %d: %s", status,
+    error(EXIT_FAILURE, 0, "%s: wcss2p ERROR %d: %s", __func__, status,
           wcs_errmsg[status]);
 
   /* For a sanity check:
@@ -579,7 +579,7 @@ gal_wcs_img_to_world(struct wcsprm *wcs, double *x, double 
*y,
   /* Use WCSLIB's wcsp2s for the conversion. */
   status=wcsp2s(wcs, ncoord, nelem, pixcrd, imgcrd, phi, theta, world, stat);
   if(status)
-    error(EXIT_FAILURE, 0, "wcsp2s ERROR %d: %s", status,
+    error(EXIT_FAILURE, 0, "%s: wcsp2s ERROR %d: %s", __func__, status,
           wcs_errmsg[status]);
 
   /* For a sanity check:



reply via email to

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