gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] (no subject)


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] (no subject)
Date: Fri, 3 Jun 2016 11:24:40 +0000 (UTC)

branch: master
commit f89bfd8d119232bdc139081dead31b742d620cff
Author: Mohammad Akhlaghi <address@hidden>
Date:   Fri Jun 3 19:39:08 2016 +0900

    Renamed fitsarrayvv library to fits
    
    The fitsarrayvv library was one of the first libraries I wrote long before
    Gnuastro. Its ancient relics are still available on Github (
    https://github.com/makhlaghi/fitsarrayvv ). Actually, I wrote it even
    before learning Git, so even the dates there can't show how old this name
    is! Any way, at that time, I was only concerned with writing a wrapper on
    CFITSIO to easily read and write a FITS array into a C array, so I chose
    this very long name to only suite the job I had back then.
    
    But it has since grown to do many more things: practically everything to do
    with FITS files in Gnuastro. So the name was only just confusing and also
    long. Now that we have the special `gnuastro/' directory to keep all the
    headers, we can easily specify any generic name we like for the libraries
    since they cannot be mixed with other headers. So I renamed this library to
    `fits'. It can easily be included with `#include <gnuastro/fits.h>'.
    
    With the change of the library name, all the functions which were defined
    in it were also renamed. Correcting the function names, some of the
    functions were also renamed to remove the redundant `fits' string in their
    names. Ofcourse we still have to work on making them more readable and
    clear for libraries, and this correction was a step towards that goal.
    
    The last few functions were actually not related to FITS at all, they were
    purely WCSLIB functions. So a new library (`wcs') was defined to keep these
    types of functions. In the future we might want to include other file
    formats (for example HDF5), so this modularization is necessary.
---
 configure.ac                   |    2 +-
 doc/gnuastro.texi              |    2 +-
 lib/Makefile.am                |   14 +-
 lib/{fitsarrayvv.c => fits.c}  |  512 ++++++++++++++--------------------------
 lib/gnuastro/fits.h            |  245 +++++++++++++++++++
 lib/gnuastro/fitsarrayvv.h     |  262 --------------------
 lib/gnuastro/wcs.h             |   39 +++
 lib/mesh.c                     |   54 ++---
 lib/wcs.c                      |  178 ++++++++++++++
 src/arithmetic/Makefile.am     |    4 +-
 src/arithmetic/arithmetic.c    |   29 ++-
 src/arithmetic/main.h          |    2 +-
 src/arithmetic/ui.c            |    8 +-
 src/convertt/Makefile.am       |    2 +-
 src/convertt/convertt.c        |   10 +-
 src/convertt/jpeg.c            |    2 +-
 src/convertt/ui.c              |   16 +-
 src/convolve/Makefile.am       |    2 +-
 src/convolve/convolve.c        |   56 ++---
 src/convolve/ui.c              |   24 +-
 src/cosmiccal/Makefile.am      |    5 +-
 src/cosmiccal/ui.c             |    2 +-
 src/header/Makefile.am         |    5 +-
 src/header/args.h              |    2 +-
 src/header/header.c            |   22 +-
 src/header/main.h              |    6 +-
 src/header/ui.c                |   10 +-
 src/imgcrop/Makefile.am        |    4 +-
 src/imgcrop/args.h             |    2 +-
 src/imgcrop/crop.c             |   50 ++--
 src/imgcrop/crop.h             |    4 +-
 src/imgcrop/imgcrop.c          |   18 +-
 src/imgcrop/main.h             |    2 +-
 src/imgcrop/ui.c               |   18 +-
 src/imgcrop/wcsmode.c          |    7 +-
 src/imgstat/Makefile.am        |    4 +-
 src/imgstat/args.h             |    2 +-
 src/imgstat/ui.c               |    6 +-
 src/imgwarp/Makefile.am        |    6 +-
 src/imgwarp/args.h             |    2 +-
 src/imgwarp/imgwarp.c          |   16 +-
 src/imgwarp/ui.c               |   12 +-
 src/mkcatalog/Makefile.am      |    2 +-
 src/mkcatalog/args.h           |    2 +-
 src/mkcatalog/columns.c        |    4 +-
 src/mkcatalog/main.h           |    2 +-
 src/mkcatalog/mkcatalog.c      |   13 +-
 src/mkcatalog/ui.c             |   29 ++-
 src/mknoise/Makefile.am        |    4 +-
 src/mknoise/args.h             |    2 +-
 src/mknoise/main.h             |    2 +-
 src/mknoise/mknoise.c          |   24 +-
 src/mknoise/ui.c               |   13 +-
 src/mkprof/Makefile.am         |    8 +-
 src/mkprof/args.h              |    2 +-
 src/mkprof/main.h              |    2 +-
 src/mkprof/mkprof.c            |   22 +-
 src/mkprof/oneprofile.c        |    8 +-
 src/mkprof/ui.c                |   13 +-
 src/noisechisel/Makefile.am    |    2 +-
 src/noisechisel/args.h         |    2 +-
 src/noisechisel/binary.c       |   28 +--
 src/noisechisel/binary.h       |    2 +-
 src/noisechisel/clumps.c       |    2 +-
 src/noisechisel/detection.c    |   74 +++---
 src/noisechisel/label.c        |    8 +-
 src/noisechisel/label.h        |   19 +-
 src/noisechisel/main.h         |    2 +-
 src/noisechisel/noisechisel.c  |   78 +++---
 src/noisechisel/segmentation.c |   46 ++--
 src/noisechisel/sky.c          |    4 +-
 src/noisechisel/thresh.c       |    2 +-
 src/noisechisel/ui.c           |   29 ++-
 src/subtractsky/Makefile.am    |    2 +-
 src/subtractsky/args.h         |    2 +-
 src/subtractsky/main.h         |    2 +-
 src/subtractsky/subtractsky.c  |   32 +--
 src/subtractsky/ui.c           |   11 +-
 78 files changed, 1101 insertions(+), 1066 deletions(-)

diff --git a/configure.ac b/configure.ac
index 28deddd..99e46b3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,7 +40,7 @@ AC_INIT([GNU Astronomy Utilities],
         [http://www.gnu.org/software/gnuastro/])
 AC_CONFIG_AUX_DIR([bootstrapped/build-aux])
 AM_INIT_AUTOMAKE([-Wall subdir-objects gnu])
-AC_CONFIG_SRCDIR([lib/fitsarrayvv.c])
+AC_CONFIG_SRCDIR([lib/fits.c])
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_MACRO_DIRS([bootstrapped/m4])
 
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index a2d7572..a9bb9ec 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -14136,7 +14136,7 @@ Installed library header files (for example 
@file{cfitsio.h} or
 @file{nproc.h}). Note that the latter are imported with @code{""}, not
 @code{<>}, for example @code{#include <nproc.h>}.
 @item
-Gnuastro common headers and libraries, for example @file{fitsarrayvv.h} or
+Gnuastro common headers and libraries, for example @file{fits.h} or
 @file{neighbors.h}, see @ref{Header files}.
 @item
 For utilities, the @file{main.h} file (which is needed by the next group of
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 791c0cd..c6fc1c9 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -25,14 +25,17 @@
 ## Make libraries of the files that are shared between all the
 ## programs:
 headersdir=$(top_srcdir)/lib/gnuastro
-noinst_LTLIBRARIES = libgalconfigfiles.la libgalfitsarrayvv.la           \
+noinst_LTLIBRARIES = libgalconfigfiles.la libgalfits.la                        
  \
 libgaltxtarrayvv.la libgalcheckset.la libgallinkedlist.la libgaltiming.la \
-libgalthreads.la libgalbox.la libgalarraymanip.la libgalstatistics.la \
+libgalthreads.la libgalbox.la libgalarraymanip.la libgalstatistics.la    \
 libgalspatialconvolve.la libgalmesh.la libgalmode.la libgalqsort.la      \
-libgalpolygon.la
+libgalpolygon.la libgalwcs.la
 
 libgalbox_la_SOURCES = box.c $(headersdir)/box.h
-libgalbox_la_LIBADD = -lm
+
+libgalwcs_la_SOURCES = wcs.c $(headersdir)/wcs.h
+
+libgalfits_la_SOURCES = fits.c $(headersdir)/fits.h
 
 libgalmesh_la_SOURCES = mesh.c $(headersdir)/mesh.h
 
@@ -58,9 +61,6 @@ libgaltxtarrayvv_la_SOURCES = txtarrayvv.c 
$(headersdir)/txtarrayvv.h
 
 libgalconfigfiles_la_SOURCES = configfiles.c $(headersdir)/configfiles.h
 
-libgalfitsarrayvv_la_SOURCES = fitsarrayvv.c $(headersdir)/fitsarrayvv.h
-libgalfitsarrayvv_la_LIBADD = -lwcs -lcfitsio -lm
-
 
 
 # Dependent libraries:
diff --git a/lib/fitsarrayvv.c b/lib/fits.c
similarity index 71%
rename from lib/fitsarrayvv.c
rename to lib/fits.c
index 0e31f2c..f282dd8 100644
--- a/lib/fitsarrayvv.c
+++ b/lib/fits.c
@@ -1,5 +1,5 @@
 /*********************************************************************
-Functions to convert a FITS array to a C array and vice versa.
+Functions to work with FITS image data.
 This is part of GNU Astronomy Utilities (Gnuastro) package.
 
 Original author:
@@ -31,8 +31,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <unistd.h>
 #include <assert.h>
 
+#include <gnuastro/fits.h>
 #include <gnuastro/checkset.h>
-#include <gnuastro/fitsarrayvv.h>
 #include <gnuastro/fixedstringmacros.h>
 
 
@@ -40,7 +40,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
  **************        Reporting errors:       ***************
  *************************************************************/
 void
-gal_fitsarray_io_error(int status, char *message)
+gal_fits_io_error(int status, char *message)
 {
   char defmessage[]="Error in CFITSIO, see above.";
   if(status)
@@ -76,7 +76,7 @@ gal_fitsarray_io_error(int status, char *message)
  **************      Acceptable FITS names     ***************
  *************************************************************/
 int
-gal_fitsarray_name_is_fits(char *name)
+gal_fits_name_is_fits(char *name)
 {
   size_t len;
   len=strlen(name);
@@ -95,7 +95,7 @@ gal_fitsarray_name_is_fits(char *name)
 
 
 int
-gal_fitsarray_name_is_fits_suffix(char *name)
+gal_fits_name_is_fits_suffix(char *name)
 {
   if (strcmp(name, "fits") == 0 || strcmp(name, ".fits") == 0
       || strcmp(name, "fits.gz") == 0 || strcmp(name, ".fits.gz") == 0
@@ -129,12 +129,12 @@ gal_fitsarray_name_is_fits_suffix(char *name)
  **************      BITPIX Dependancies       ***************
  *************************************************************/
 void
-gal_fitsarray_img_bitpix_size(fitsfile *fptr, int *bitpix, long *naxes)
+gal_fits_img_bitpix_size(fitsfile *fptr, int *bitpix, long *naxes)
 {
   int status=0, maxdim=10, naxis;
 
   if( fits_get_img_param(fptr, maxdim, bitpix, &naxis, naxes, &status) )
-    gal_fitsarray_io_error(status, NULL);
+    gal_fits_io_error(status, NULL);
 
   if(naxis!=2)
     error(EXIT_FAILURE, 0, "currently only a 2 dimensional image array "
@@ -151,7 +151,7 @@ gal_fitsarray_img_bitpix_size(fitsfile *fptr, int *bitpix, 
long *naxes)
 
 /* Set datatype (in CFITSIO) based on BITPIX. */
 int
-gal_fitsarray_bitpix_to_dtype(int bitpix)
+gal_fits_bitpix_to_dtype(int bitpix)
 {
   switch(bitpix)
     {
@@ -179,7 +179,7 @@ gal_fitsarray_bitpix_to_dtype(int bitpix)
 
 
 void *
-gal_fitsarray_bitpix_blank(int bitpix)
+gal_fits_bitpix_blank(int bitpix)
 {
   unsigned char *b;
   short *s;
@@ -195,42 +195,42 @@ gal_fitsarray_bitpix_blank(int bitpix)
       b=malloc(sizeof(unsigned char));
       if(b==NULL)
        error(EXIT_FAILURE, errno, "%lu bytes", sizeof(unsigned char));
-      *b=GAL_FITSARRAY_BYTE_BLANK;
+      *b=GAL_FITS_BYTE_BLANK;
       return b;
 
     case SHORT_IMG:
       s=malloc(sizeof(short));
       if(s==NULL)
        error(EXIT_FAILURE, errno, "%lu bytes", sizeof(short));
-      *s=GAL_FITSARRAY_SHORT_BLANK;
+      *s=GAL_FITS_SHORT_BLANK;
       return s;
 
     case LONG_IMG:
       l=malloc(sizeof(long));
       if(l==NULL)
        error(EXIT_FAILURE, errno, "%lu bytes", sizeof(long));
-      *l=GAL_FITSARRAY_LONG_BLANK;
+      *l=GAL_FITS_LONG_BLANK;
       return l;
 
     case LONGLONG_IMG:
       L=malloc(sizeof(LONGLONG));
       if(L==NULL)
        error(EXIT_FAILURE, errno, "%lu bytes", sizeof(LONGLONG));
-      *L=GAL_FITSARRAY_LLONG_BLANK;
+      *L=GAL_FITS_LLONG_BLANK;
       return L;
 
     case FLOAT_IMG:
       f=malloc(sizeof(float));
       if(f==NULL)
        error(EXIT_FAILURE, errno, "%lu bytes", sizeof(float));
-      *f=GAL_FITSARRAY_FLOAT_BLANK;
+      *f=GAL_FITS_FLOAT_BLANK;
       return f;
 
     case DOUBLE_IMG:
       d=malloc(sizeof(double));
       if(d==NULL)
        error(EXIT_FAILURE, errno, "%lu bytes", sizeof(double));
-      *d=GAL_FITSARRAY_FLOAT_BLANK;
+      *d=GAL_FITS_FLOAT_BLANK;
       return d;
 
     default:
@@ -247,7 +247,7 @@ gal_fitsarray_bitpix_blank(int bitpix)
 
 /* Allocate an array based on the value of bitpix. */
 void *
-gal_fitsarray_bitpix_alloc(size_t size, int bitpix)
+gal_fits_bitpix_alloc(size_t size, int bitpix)
 {
   void *array;
 
@@ -316,32 +316,32 @@ blanktovalue(void *array, int bitpix, size_t size, void 
*value)
     {
     case BYTE_IMG:
       bf=(b=array)+size;
-      do if(*b==GAL_FITSARRAY_BYTE_BLANK) *b=bv; while(++b<bf);
+      do if(*b==GAL_FITS_BYTE_BLANK) *b=bv; while(++b<bf);
       break;
 
     case SHORT_IMG:
       sf=(s=array)+size;
-      do if(*s==GAL_FITSARRAY_SHORT_BLANK) *s=sv; while(++s<sf);
+      do if(*s==GAL_FITS_SHORT_BLANK) *s=sv; while(++s<sf);
       break;
 
     case LONG_IMG:
       lf=(l=array)+size;
-      do if(*l==GAL_FITSARRAY_LONG_BLANK) *l=lv; while(++l<lf);
+      do if(*l==GAL_FITS_LONG_BLANK) *l=lv; while(++l<lf);
       break;
 
     case LONGLONG_IMG:
       Lf=(L=array)+size;
-      do if(*L==GAL_FITSARRAY_LLONG_BLANK) *L=Lv; while(++L<Lf);
+      do if(*L==GAL_FITS_LLONG_BLANK) *L=Lv; while(++L<Lf);
       break;
 
     case FLOAT_IMG:
       ff=(f=array)+size;
-      do if(*f==GAL_FITSARRAY_FLOAT_BLANK) *f=fv; while(++f<ff);
+      do if(*f==GAL_FITS_FLOAT_BLANK) *f=fv; while(++f<ff);
       break;
 
     case DOUBLE_IMG:
       df=(d=array)+size;
-      do if(*d==GAL_FITSARRAY_FLOAT_BLANK) *d=dv; while(++d<df);
+      do if(*d==GAL_FITS_FLOAT_BLANK) *d=dv; while(++d<df);
       break;
 
     default:
@@ -357,7 +357,7 @@ blanktovalue(void *array, int bitpix, size_t size, void 
*value)
 
 
 void
-gal_fitsarray_change_type(void *in, int inbitpix, size_t size, int anyblank,
+gal_fits_change_type(void *in, int inbitpix, size_t size, int anyblank,
                           void **out, int outbitpix)
 {
   size_t i=0;
@@ -369,7 +369,7 @@ gal_fitsarray_change_type(void *in, int inbitpix, size_t 
size, int anyblank,
   double *d, *df, *id=in, *iid=in;
 
   /* Allocate space for the output and start filling it. */
-  *out=gal_fitsarray_bitpix_alloc(size, outbitpix);
+  *out=gal_fits_bitpix_alloc(size, outbitpix);
   switch(outbitpix)
     {
     case BYTE_IMG:
@@ -380,38 +380,38 @@ gal_fitsarray_change_type(void *in, int inbitpix, size_t 
size, int anyblank,
        case SHORT_IMG:
          bf=(b=*out)+size; do *b=*is++; while(++b<bf);
           if(anyblank)
-            {b=*out; do {b[i]=(iis[i]==GAL_FITSARRAY_SHORT_BLANK)
-                         ?GAL_FITSARRAY_BYTE_BLANK:b[i];}
+            {b=*out; do {b[i]=(iis[i]==GAL_FITS_SHORT_BLANK)
+                         ?GAL_FITS_BYTE_BLANK:b[i];}
               while(++i!=size);}
           return;
        case LONG_IMG:
          bf=(b=*out)+size; do *b=*il++; while(++b<bf);
           if(anyblank)
-            {b=*out; do {b[i]=(iil[i]==GAL_FITSARRAY_LONG_BLANK)
-                         ?GAL_FITSARRAY_BYTE_BLANK:b[i];}
+            {b=*out; do {b[i]=(iil[i]==GAL_FITS_LONG_BLANK)
+                         ?GAL_FITS_BYTE_BLANK:b[i];}
               while(++i!=size);}
           return;
        case LONGLONG_IMG:
          bf=(b=*out)+size; do *b=*iL++; while(++b<bf);
           if(anyblank)
-            {b=*out; do {b[i]=(iiL[i]==GAL_FITSARRAY_LLONG_BLANK)
-                         ?GAL_FITSARRAY_BYTE_BLANK:b[i];}
+            {b=*out; do {b[i]=(iiL[i]==GAL_FITS_LLONG_BLANK)
+                         ?GAL_FITS_BYTE_BLANK:b[i];}
               while(++i!=size);}
           return;
        case FLOAT_IMG:
          bf=(b=*out)+size; do *b=roundf(*iif++); while(++b<bf);
           if(anyblank)
-            {b=*out; do {b[i]=isnan(iiif[i])?GAL_FITSARRAY_BYTE_BLANK:b[i];}
+            {b=*out; do {b[i]=isnan(iiif[i])?GAL_FITS_BYTE_BLANK:b[i];}
               while(++i!=size);}
           return;
        case DOUBLE_IMG:
          bf=(b=*out)+size; do *b=round(*id++); while(++b<bf);
           if(anyblank)
-            {b=*out; do {b[i]=isnan(iid[i])?GAL_FITSARRAY_BYTE_BLANK:b[i];}
+            {b=*out; do {b[i]=isnan(iid[i])?GAL_FITS_BYTE_BLANK:b[i];}
               while(++i!=size);}
           return;
        default:
-         error(EXIT_FAILURE, 0, "a bug!  In gal_fitsarray_change_type "
+         error(EXIT_FAILURE, 0, "a bug!  In gal_fits_change_type "
                 "(fitsarrayvv.c). BITPIX=%d of input not recognized.  Please "
                 "contact us so we can fix it", inbitpix);
        }
@@ -423,8 +423,8 @@ gal_fitsarray_change_type(void *in, int inbitpix, size_t 
size, int anyblank,
        case BYTE_IMG:
          sf=(s=*out)+size; do *s=*ib++; while(++s<sf);
           if(anyblank)
-            {s=*out; do {s[i]=(iib[i]==GAL_FITSARRAY_BYTE_BLANK)
-                         ?GAL_FITSARRAY_SHORT_BLANK:s[i];}
+            {s=*out; do {s[i]=(iib[i]==GAL_FITS_BYTE_BLANK)
+                         ?GAL_FITS_SHORT_BLANK:s[i];}
               while(++i!=size);}
           return;
        case SHORT_IMG:
@@ -432,31 +432,31 @@ gal_fitsarray_change_type(void *in, int inbitpix, size_t 
size, int anyblank,
        case LONG_IMG:
          sf=(s=*out)+size; do *s=*il++; while(++s<sf);
           if(anyblank)
-            {s=*out; do {s[i]=(iil[i]==GAL_FITSARRAY_LONG_BLANK)
-                         ?GAL_FITSARRAY_SHORT_BLANK:s[i];}
+            {s=*out; do {s[i]=(iil[i]==GAL_FITS_LONG_BLANK)
+                         ?GAL_FITS_SHORT_BLANK:s[i];}
               while(++i!=size);}
           return;
        case LONGLONG_IMG:
          sf=(s=*out)+size; do *s=*iL++; while(++s<sf);
           if(anyblank)
-            {s=*out; do {s[i]=(iiL[i]==GAL_FITSARRAY_LLONG_BLANK)
-                         ?GAL_FITSARRAY_SHORT_BLANK:s[i];}
+            {s=*out; do {s[i]=(iiL[i]==GAL_FITS_LLONG_BLANK)
+                         ?GAL_FITS_SHORT_BLANK:s[i];}
               while(++i!=size);}
           return;
        case FLOAT_IMG:
          sf=(s=*out)+size; do *s=roundf(*iif++); while(++s<sf);
           if(anyblank)
-            {s=*out; do {s[i]=isnan(iiif[i])?GAL_FITSARRAY_SHORT_BLANK:s[i];}
+            {s=*out; do {s[i]=isnan(iiif[i])?GAL_FITS_SHORT_BLANK:s[i];}
               while(++i!=size);}
           return;
        case DOUBLE_IMG:
          sf=(s=*out)+size; do *s=round(*id++); while(++s<sf);
           if(anyblank)
-            {s=*out; do {s[i]=isnan(iid[i])?GAL_FITSARRAY_SHORT_BLANK:s[i];}
+            {s=*out; do {s[i]=isnan(iid[i])?GAL_FITS_SHORT_BLANK:s[i];}
               while(++i!=size);}
           return;
        default:
-         error(EXIT_FAILURE, 0, "a bug!  In gal_fitsarray_change_type "
+         error(EXIT_FAILURE, 0, "a bug!  In gal_fits_change_type "
                 "(fitsarrayvv.c).  BITPIX=%d of input not recognized.  Please "
                 "contact us so we can fix it", inbitpix);
        }
@@ -468,15 +468,15 @@ gal_fitsarray_change_type(void *in, int inbitpix, size_t 
size, int anyblank,
        case BYTE_IMG:
          lf=(l=*out)+size; do *l=*ib++; while(++l<lf);
           if(anyblank)
-            {l=*out; do {l[i]=(iib[i]==GAL_FITSARRAY_BYTE_BLANK)
-                         ?GAL_FITSARRAY_LONG_BLANK:l[i];}
+            {l=*out; do {l[i]=(iib[i]==GAL_FITS_BYTE_BLANK)
+                         ?GAL_FITS_LONG_BLANK:l[i];}
               while(++i!=size);}
           return;
        case SHORT_IMG:
          lf=(l=*out)+size; do *l=*is++; while(++l<lf);
           if(anyblank)
-            {l=*out; do {l[i]=(iis[i]==GAL_FITSARRAY_SHORT_BLANK)
-                         ?GAL_FITSARRAY_LONG_BLANK:l[i];}
+            {l=*out; do {l[i]=(iis[i]==GAL_FITS_SHORT_BLANK)
+                         ?GAL_FITS_LONG_BLANK:l[i];}
               while(++i!=size);}
           return;
        case LONG_IMG:
@@ -484,24 +484,24 @@ gal_fitsarray_change_type(void *in, int inbitpix, size_t 
size, int anyblank,
        case LONGLONG_IMG:
          lf=(l=*out)+size; do *l=*iL++; while(++l<lf);
           if(anyblank)
-            {l=*out; do {l[i]=(iiL[i]==GAL_FITSARRAY_LLONG_BLANK)
-                         ?GAL_FITSARRAY_LONG_BLANK:l[i];}
+            {l=*out; do {l[i]=(iiL[i]==GAL_FITS_LLONG_BLANK)
+                         ?GAL_FITS_LONG_BLANK:l[i];}
               while(++i!=size);}
           return;
        case FLOAT_IMG:
          lf=(l=*out)+size; do *l=roundf(*iif++); while(++l<lf);
           if(anyblank)
-            {l=*out; do {l[i]=isnan(iiif[i])?GAL_FITSARRAY_LONG_BLANK:l[i];}
+            {l=*out; do {l[i]=isnan(iiif[i])?GAL_FITS_LONG_BLANK:l[i];}
               while(++i!=size);}
           return;
        case DOUBLE_IMG:
          lf=(l=*out)+size; do *l=round(*id++); while(++l<lf);
           if(anyblank)
-            {l=*out; do {l[i]=isnan(iid[i])?GAL_FITSARRAY_LONG_BLANK:l[i];}
+            {l=*out; do {l[i]=isnan(iid[i])?GAL_FITS_LONG_BLANK:l[i];}
               while(++i!=size);}
           return;
        default:
-         error(EXIT_FAILURE, 0, "a bug!  In gal_fitsarray_change_type "
+         error(EXIT_FAILURE, 0, "a bug!  In gal_fits_change_type "
                 "(fitsarrayvv.c).  BITPIX=%d of input not recognized.  Please "
                 "contact us so we can fix it", inbitpix);
        }
@@ -513,22 +513,22 @@ gal_fitsarray_change_type(void *in, int inbitpix, size_t 
size, int anyblank,
        case BYTE_IMG:
          Lf=(L=*out)+size; do *L=*ib++; while(++L<Lf);
           if(anyblank)
-            {L=*out; do {L[i]=(iib[i]==GAL_FITSARRAY_BYTE_BLANK)
-                         ?GAL_FITSARRAY_LLONG_BLANK:L[i];}
+            {L=*out; do {L[i]=(iib[i]==GAL_FITS_BYTE_BLANK)
+                         ?GAL_FITS_LLONG_BLANK:L[i];}
               while(++i!=size);}
           return;
        case SHORT_IMG:
          Lf=(L=*out)+size; do *L=*is++; while(++L<Lf);
           if(anyblank)
-            {L=*out; do {L[i]=(iis[i]==GAL_FITSARRAY_SHORT_BLANK)
-                         ?GAL_FITSARRAY_LLONG_BLANK:L[i];}
+            {L=*out; do {L[i]=(iis[i]==GAL_FITS_SHORT_BLANK)
+                         ?GAL_FITS_LLONG_BLANK:L[i];}
               while(++i!=size);}
           return;
        case LONG_IMG:
          Lf=(L=*out)+size; do *L=*il++; while(++L<Lf);
           if(anyblank)
-            {L=*out; do {L[i]=(iil[i]==GAL_FITSARRAY_LONG_BLANK)
-                         ?GAL_FITSARRAY_LLONG_BLANK:L[i];}
+            {L=*out; do {L[i]=(iil[i]==GAL_FITS_LONG_BLANK)
+                         ?GAL_FITS_LLONG_BLANK:L[i];}
               while(++i!=size);}
           return;
        case LONGLONG_IMG:
@@ -536,17 +536,17 @@ gal_fitsarray_change_type(void *in, int inbitpix, size_t 
size, int anyblank,
        case FLOAT_IMG:
          Lf=(L=*out)+size; do *L=roundf(*iif++); while(++L<Lf);
           if(anyblank)
-            {L=*out; do {L[i]=isnan(iiif[i])?GAL_FITSARRAY_LLONG_BLANK:L[i];}
+            {L=*out; do {L[i]=isnan(iiif[i])?GAL_FITS_LLONG_BLANK:L[i];}
               while(++i!=size);}
           return;
        case DOUBLE_IMG:
          Lf=(L=*out)+size; do *L=round(*id++); while(++L<Lf);
           if(anyblank)
-            {L=*out; do {L[i]=isnan(iid[i])?GAL_FITSARRAY_LLONG_BLANK:L[i];}
+            {L=*out; do {L[i]=isnan(iid[i])?GAL_FITS_LLONG_BLANK:L[i];}
               while(++i!=size);}
           return;
        default:
-         error(EXIT_FAILURE, 0, "a bug!  In gal_fitsarray_change_type "
+         error(EXIT_FAILURE, 0, "a bug!  In gal_fits_change_type "
                 "(fitsarrayvv.c).  BITPIX=%d of input not recognized.  Please "
                 "contact us so we can fix it", inbitpix);
        }
@@ -558,29 +558,29 @@ gal_fitsarray_change_type(void *in, int inbitpix, size_t 
size, int anyblank,
        case BYTE_IMG:
          ff=(f=*out)+size; do *f=*ib++; while(++f<ff);
           if(anyblank)
-            {f=*out; do {f[i]=iib[i]==GAL_FITSARRAY_BYTE_BLANK
-                         ?GAL_FITSARRAY_FLOAT_BLANK:f[i];}
+            {f=*out; do {f[i]=iib[i]==GAL_FITS_BYTE_BLANK
+                         ?GAL_FITS_FLOAT_BLANK:f[i];}
               while(++i!=size);}
           return;
        case SHORT_IMG:
          ff=(f=*out)+size; do *f=*is++; while(++f<ff);
           if(anyblank)
-            {f=*out; do {f[i]=iis[i]==GAL_FITSARRAY_SHORT_BLANK
-                         ?GAL_FITSARRAY_FLOAT_BLANK:f[i];}
+            {f=*out; do {f[i]=iis[i]==GAL_FITS_SHORT_BLANK
+                         ?GAL_FITS_FLOAT_BLANK:f[i];}
               while(++i!=size);}
           return;
        case LONG_IMG:
          ff=(f=*out)+size; do *f=*il++; while(++f<ff);
           if(anyblank)
-            {f=*out; do {f[i]=iil[i]==GAL_FITSARRAY_LONG_BLANK
-                         ?GAL_FITSARRAY_FLOAT_BLANK:f[i];}
+            {f=*out; do {f[i]=iil[i]==GAL_FITS_LONG_BLANK
+                         ?GAL_FITS_FLOAT_BLANK:f[i];}
               while(++i!=size);}
           return;
        case LONGLONG_IMG:
          ff=(f=*out)+size; do *f=*iL++; while(++f<ff);
           if(anyblank)
-            {f=*out; do {f[i]=iiL[i]==GAL_FITSARRAY_LLONG_BLANK
-                         ?GAL_FITSARRAY_FLOAT_BLANK:f[i];}
+            {f=*out; do {f[i]=iiL[i]==GAL_FITS_LLONG_BLANK
+                         ?GAL_FITS_FLOAT_BLANK:f[i];}
               while(++i!=size);}
           return;
        case FLOAT_IMG:
@@ -588,7 +588,7 @@ gal_fitsarray_change_type(void *in, int inbitpix, size_t 
size, int anyblank,
        case DOUBLE_IMG:
          ff=(f=*out)+size; do *f=*id++; while(++f<ff); return;
        default:
-         error(EXIT_FAILURE, 0, "a bug!  In gal_fitsarray_change_type "
+         error(EXIT_FAILURE, 0, "a bug!  In gal_fits_change_type "
                 "(fitsarrayvv.c).  BITPIX=%d of input not recognized.  Please "
                 "contact us so we can fix it", inbitpix);
        }
@@ -600,29 +600,29 @@ gal_fitsarray_change_type(void *in, int inbitpix, size_t 
size, int anyblank,
        case BYTE_IMG:
          df=(d=*out)+size; do *d=*ib++; while(++d<df);
           if(anyblank)
-            {d=*out; do {d[i]=iib[i]==GAL_FITSARRAY_BYTE_BLANK
-                         ?GAL_FITSARRAY_FLOAT_BLANK:d[i];}
+            {d=*out; do {d[i]=iib[i]==GAL_FITS_BYTE_BLANK
+                         ?GAL_FITS_FLOAT_BLANK:d[i];}
               while(++i!=size);}
           return;
        case SHORT_IMG:
          df=(d=*out)+size; do *d=*is++; while(++d<df);
           if(anyblank)
-            {d=*out; do {d[i]=iis[i]==GAL_FITSARRAY_SHORT_BLANK
-                         ?GAL_FITSARRAY_FLOAT_BLANK:d[i];}
+            {d=*out; do {d[i]=iis[i]==GAL_FITS_SHORT_BLANK
+                         ?GAL_FITS_FLOAT_BLANK:d[i];}
               while(++i!=size);}
           return;
        case LONG_IMG:
          df=(d=*out)+size; do *d=*il++; while(++d<df);
           if(anyblank)
-            {d=*out; do {d[i]=iil[i]==GAL_FITSARRAY_LONG_BLANK
-                         ?GAL_FITSARRAY_FLOAT_BLANK:d[i];}
+            {d=*out; do {d[i]=iil[i]==GAL_FITS_LONG_BLANK
+                         ?GAL_FITS_FLOAT_BLANK:d[i];}
               while(++i!=size);}
           return;
        case LONGLONG_IMG:
          df=(d=*out)+size; do *d=*iL++; while(++d<df);
           if(anyblank)
-            {d=*out; do {d[i]=iiL[i]==GAL_FITSARRAY_LLONG_BLANK
-                         ?GAL_FITSARRAY_FLOAT_BLANK:d[i];}
+            {d=*out; do {d[i]=iiL[i]==GAL_FITS_LLONG_BLANK
+                         ?GAL_FITS_FLOAT_BLANK:d[i];}
               while(++i!=size);}
           return;
        case FLOAT_IMG:
@@ -630,7 +630,7 @@ gal_fitsarray_change_type(void *in, int inbitpix, size_t 
size, int anyblank,
        case DOUBLE_IMG:
          df=(d=*out)+size; do *d=*id++; while(++d<df); return;
        default:
-         error(EXIT_FAILURE, 0, "a bug!  In gal_fitsarray_change_type "
+         error(EXIT_FAILURE, 0, "a bug!  In gal_fits_change_type "
                 "(fitsarrayvv.c).  BITPIX=%d of input not recognized.  Please "
                 "contact us so we can fix it", inbitpix);
        }
@@ -640,7 +640,7 @@ gal_fitsarray_change_type(void *in, int inbitpix, size_t 
size, int anyblank,
     default:
       error(EXIT_FAILURE, 0, "a bug! Output Bitpix value of %d is not "
            "recognized. This should not happen here "
-            "(gal_fitsarray_change_type in fitsarrayvv.c). Please "
+            "(gal_fits_change_type in fitsarrayvv.c). Please "
             "contact us to see how this happened", outbitpix);
     }
 }
@@ -664,7 +664,7 @@ gal_fitsarray_change_type(void *in, int inbitpix, size_t 
size, int anyblank,
  **************      Number of extensions:     ***************
  *************************************************************/
 void
-gal_fitsarray_num_hdus(char *filename, int *numhdu)
+gal_fits_num_hdus(char *filename, int *numhdu)
 {
   int status=0;
   fitsfile *fptr;
@@ -679,7 +679,7 @@ gal_fitsarray_num_hdus(char *filename, int *numhdu)
 
   fits_close_file(fptr, &status);
 
-  gal_fitsarray_io_error(status, NULL);
+  gal_fits_io_error(status, NULL);
 }
 
 
@@ -730,8 +730,8 @@ hdutypestring(int hdutype)
 /* Check the desired HDU in a FITS image and also if it has the
    desired type. */
 void
-gal_fitsarray_read_fits_hdu(char *filename, char *hdu, int desiredtype,
-                            fitsfile **outfptr)
+gal_fits_read_hdu(char *filename, char *hdu, int desiredtype,
+                       fitsfile **outfptr)
 {
   size_t len;
   char *ffname;
@@ -748,12 +748,12 @@ gal_fitsarray_read_fits_hdu(char *filename, char *hdu, 
int desiredtype,
 
   /* Open the FITS file: */
   if( fits_open_file(outfptr, ffname, READONLY, &status) )
-    gal_fitsarray_io_error(status, "reading this FITS file");
+    gal_fits_io_error(status, "reading this FITS file");
   fptr=*outfptr;
 
   /* Check the Type of the given HDU: */
   if (fits_get_hdu_type(fptr, &hdutype, &status) )
-    gal_fitsarray_io_error(status, NULL);
+    gal_fits_io_error(status, NULL);
 
   if(hdutype!=desiredtype)
     error(EXIT_FAILURE, 0, "%s: HDU %s is %s, not %s",
@@ -767,13 +767,13 @@ gal_fitsarray_read_fits_hdu(char *filename, char *hdu, 
int desiredtype,
 
 
 
-/* Read keywords from a FITS file. The gal_fitsarray_read_header_keys pointer 
is
-   an array of gal_fitsarray_read_header_keys structures, which keep the basic
+/* Read keywords from a FITS file. The gal_fits_read_header_keys pointer is
+   an array of gal_fits_read_header_keys structures, which keep the basic
    information for each keyword that is to be read and also stores the
    value in the appropriate type.*/
 void
-gal_fitsarray_read_keywords(char *filename, char *hdu,
-                            struct gal_fitsarray_read_header_keys *keys,
+gal_fits_read_keywords(char *filename, char *hdu,
+                            struct gal_fits_read_header_keys *keys,
                             size_t num)
 {
   int status=0;
@@ -792,7 +792,7 @@ gal_fitsarray_read_keywords(char *filename, char *hdu,
 
   /* Open the FITS file: */
   if( fits_open_file(&fptr, ffname, READONLY, &status) )
-    gal_fitsarray_io_error(status, "reading this FITS file");
+    gal_fits_io_error(status, "reading this FITS file");
 
   /* Get the desired keywords. */
   for(i=0;i<num;++i)
@@ -826,12 +826,12 @@ gal_fitsarray_read_keywords(char *filename, char *hdu,
         }
       if( fits_read_key(fptr, keys[i].datatype, keys[i].keyname,
                         valueptr, NULL, &status) )
-        gal_fitsarray_io_error(status, "reading the keyword");
+        gal_fits_io_error(status, "reading the keyword");
     }
 
   /* Close the FITS file. */
   fits_close_file(fptr, &status);
-  gal_fitsarray_io_error(status, NULL);
+  gal_fits_io_error(status, NULL);
 
   /* Clean up. */
   free(ffname);
@@ -864,19 +864,19 @@ gal_fitsarray_read_keywords(char *filename, char *hdu,
    it is important to know before hand if they were allocated or
    not. If not, they don't need to be freed. */
 void
-gal_fitsarray_add_to_fits_header_ll(struct gal_fitsarray_header_ll **list,
+gal_fits_add_to_fits_header_ll(struct gal_fits_header_ll **list,
                                     int datatype, char *keyname, int kfree,
                                     void *value, int vfree, char *comment,
                                     int cfree, char *unit)
 {
-  struct gal_fitsarray_header_ll *newnode;
+  struct gal_fits_header_ll *newnode;
 
   /* Allocate space for the new node and fill it in. */
   errno=0;
   newnode=malloc(sizeof *newnode);
   if(newnode==NULL)
     error(EXIT_FAILURE, errno,
-         "linkedlist: new element in gal_fitsarray_header_ll");
+         "linkedlist: new element in gal_fits_header_ll");
   newnode->datatype=datatype;
   newnode->keyname=keyname;
   newnode->value=value;
@@ -895,19 +895,19 @@ gal_fitsarray_add_to_fits_header_ll(struct 
gal_fitsarray_header_ll **list,
 
 
 void
-gal_fitsarray_add_to_fits_header_ll_end(struct gal_fitsarray_header_ll **list,
+gal_fits_add_to_fits_header_ll_end(struct gal_fits_header_ll **list,
                                         int datatype, char *keyname, int kfree,
                                         void *value, int vfree, char *comment,
                                         int cfree, char *unit)
 {
-  struct gal_fitsarray_header_ll *newnode, *tmp;
+  struct gal_fits_header_ll *newnode, *tmp;
 
   /* Allocate space for the new node and fill it in. */
   errno=0;
   newnode=malloc(sizeof *newnode);
   if(newnode==NULL)
     error(EXIT_FAILURE, errno,
-         "linkedlist: new element in gal_fitsarray_header_ll");
+         "linkedlist: new element in gal_fits_header_ll");
   newnode->datatype=datatype;
   newnode->keyname=keyname;
   newnode->value=value;
@@ -936,8 +936,8 @@ gal_fitsarray_add_to_fits_header_ll_end(struct 
gal_fitsarray_header_ll **list,
 
 
 void
-gal_fitsarray_file_name_in_keywords(char *keynamebase, char *filename,
-                                    struct gal_fitsarray_header_ll **list)
+gal_fits_file_name_in_keywords(char *keynamebase, char *filename,
+                                    struct gal_fits_header_ll **list)
 {
   char *keyname, *value;
   size_t numkey=1, maxlength;
@@ -973,7 +973,7 @@ gal_fitsarray_file_name_in_keywords(char *keynamebase, char 
*filename,
         length was copied. */
       if(value[maxlength-1]=='\0')
        {
-         gal_fitsarray_add_to_fits_header_ll_end(list, TSTRING, keyname, 1,
+         gal_fits_add_to_fits_header_ll_end(list, TSTRING, keyname, 1,
                                                   value, 1, NULL, 0, NULL);
          break;
        }
@@ -995,7 +995,7 @@ gal_fitsarray_file_name_in_keywords(char *keynamebase, char 
*filename,
                  maxlength);
 
          /* Convert the last useful character and save the file name.*/
-         gal_fitsarray_add_to_fits_header_ll_end(list, TSTRING, keyname, 1,
+         gal_fits_add_to_fits_header_ll_end(list, TSTRING, keyname, 1,
                                                   value, 1, NULL, 0, NULL);
          i+=j+1;
        }
@@ -1009,7 +1009,7 @@ gal_fitsarray_file_name_in_keywords(char *keynamebase, 
char *filename,
 /* Write the WCS and begin the part on this particular program's
    key words. */
 void
-gal_fitsarray_add_wcs_to_header(fitsfile *fptr, char *wcsheader, int nkeyrec)
+gal_fits_add_wcs_to_header(fitsfile *fptr, char *wcsheader, int nkeyrec)
 {
   size_t i;
   int h, status=0;
@@ -1024,32 +1024,32 @@ gal_fitsarray_add_wcs_to_header(fitsfile *fptr, char 
*wcsheader, int nkeyrec)
 
   /* Print the first two lines before the WCS header information. */
   if(fits_write_record(fptr, blankrec, &status))
-    gal_fitsarray_io_error(status, NULL);
+    gal_fits_io_error(status, NULL);
   sprintf(titlerec, "%sWCS information", startblank);
   for(i=strlen(titlerec);i<79;++i)
     titlerec[i]=' ';
   if(fits_write_record(fptr, titlerec, &status))
-    gal_fitsarray_io_error(status, NULL);
+    gal_fits_io_error(status, NULL);
 
   /* Write the keywords one by one: */
   for(h=0;h<nkeyrec-1;++h)
     fits_write_record(fptr, &wcsheader[h*80], &status);
-  gal_fitsarray_io_error(status, NULL);
+  gal_fits_io_error(status, NULL);
 }
 
 
 
 
 
-/* Write the keywords in the gal_fitsarray_header_ll linked list to the FITS
+/* Write the keywords in the gal_fits_header_ll linked list to the FITS
    file. Every keyword that is written is freed, that is why we need
    the pointer to the linked list (to correct it after we finish). */
 void
-gal_fitsarray_update_keys(fitsfile *fptr,
-                          struct gal_fitsarray_header_ll **keylist)
+gal_fits_update_keys(fitsfile *fptr,
+                          struct gal_fits_header_ll **keylist)
 {
   int status=0;
-  struct gal_fitsarray_header_ll *tmp, *ttmp;
+  struct gal_fits_header_ll *tmp, *ttmp;
 
   tmp=*keylist;
   while(tmp!=NULL)
@@ -1059,16 +1059,16 @@ gal_fitsarray_update_keys(fitsfile *fptr,
         {
           if( fits_update_key(fptr, tmp->datatype, tmp->keyname, tmp->value,
                               tmp->comment, &status) )
-            gal_fitsarray_io_error(status, NULL);
+            gal_fits_io_error(status, NULL);
         }
       else
         {
           if(fits_update_key_null(fptr, tmp->keyname, tmp->comment, &status))
-            gal_fitsarray_io_error(status, NULL);
+            gal_fits_io_error(status, NULL);
         }
       if(tmp->unit && fits_write_key_unit(fptr, tmp->keyname,
                                          tmp->unit, &status) )
-       gal_fitsarray_io_error(status, NULL);
+       gal_fits_io_error(status, NULL);
 
       /* Free the value pointer if desired: */
       if(tmp->kfree) free(tmp->keyname);
@@ -1089,8 +1089,8 @@ gal_fitsarray_update_keys(fitsfile *fptr,
 
 
 void
-gal_fitsarray_copyright_end(fitsfile *fptr,
-                            struct gal_fitsarray_header_ll *headers,
+gal_fits_copyright_end(fitsfile *fptr,
+                            struct gal_fits_header_ll *headers,
                             char *spack_string)
 {
   size_t i;
@@ -1120,11 +1120,11 @@ gal_fitsarray_copyright_end(fitsfile *fptr,
   sprintf(titlerec, "%s%s:", startblank, spack_string);
   for(i=strlen(titlerec);i<79;++i) titlerec[i]=' ';
   fits_write_record(fptr, titlerec, &status);
-  gal_fitsarray_io_error(status, NULL);
+  gal_fits_io_error(status, NULL);
 
   /* If any header keywords are specified add them: */
   if(headers)
-    gal_fitsarray_update_keys(fptr, &headers);
+    gal_fits_update_keys(fptr, &headers);
 
   /* Set the version of CFITSIO as a string. */
   sprintf(cfitsioversion, "%-.2f", CFITSIO_VERSION);
@@ -1147,7 +1147,7 @@ gal_fitsarray_copyright_end(fitsfile *fptr,
   fits_write_comment(fptr, GAL_STRINGS_SHORT_COPYRIGHT, &status);
   fits_write_comment(fptr, GAL_STRINGS_SHORT_LICENSE, &status);
   */
-  gal_fitsarray_io_error(status, NULL);
+  gal_fits_io_error(status, NULL);
 }
 
 
@@ -1187,8 +1187,9 @@ gal_fitsarray_copyright_end(fitsfile *fptr,
    Don't call this function within a thread or use a mutex.
 */
 void
-gal_fitsarray_read_wcs(fitsfile *fptr, int *nwcs, struct wcsprm **wcs,
-                       size_t hstartwcs, size_t hendwcs)
+gal_fits_read_wcs_from_pointer(fitsfile *fptr, int *nwcs,
+                               struct wcsprm **wcs,
+                               size_t hstartwcs, size_t hendwcs)
 {
   /* Declaratins: */
   int nkeys=0, status=0;
@@ -1199,7 +1200,7 @@ gal_fitsarray_read_wcs(fitsfile *fptr, int *nwcs, struct 
wcsprm **wcs,
 
   /* CFITSIO function: */
   if( fits_hdr2str(fptr, 1, NULL, 0, &fullheader, &nkeys, &status) )
-    gal_fitsarray_io_error(status, NULL);
+    gal_fits_io_error(status, NULL);
 
   /* Only consider the header keywords in the current range: */
   if(hendwcs>hstartwcs)
@@ -1242,7 +1243,7 @@ gal_fitsarray_read_wcs(fitsfile *fptr, int *nwcs, struct 
wcsprm **wcs,
       *wcs=NULL; *nwcs=0;
     }
   if (fits_free_memory(fullheader, &status) )
-    gal_fitsarray_io_error(status, "problem in fitsarrayvv.c for freeing "
+    gal_fits_io_error(status, "problem in fitsarrayvv.c for freeing "
                            "the memory used to keep all the headers");
 
   /* Set the internal structure: */
@@ -1268,21 +1269,21 @@ gal_fitsarray_read_wcs(fitsfile *fptr, int *nwcs, 
struct wcsprm **wcs,
 
 
 void
-gal_fitsarray_read_fits_wcs(char *filename, char *hdu, size_t hstartwcs,
-                            size_t hendwcs, int *nwcs, struct wcsprm **wcs)
+gal_fits_read_wcs(char *filename, char *hdu, size_t hstartwcs,
+                  size_t hendwcs, int *nwcs, struct wcsprm **wcs)
 {
   int status=0;
   fitsfile *fptr;
 
   /* Check HDU for realistic conditions: */
-  gal_fitsarray_read_fits_hdu(filename, hdu, IMAGE_HDU, &fptr);
+  gal_fits_read_hdu(filename, hdu, IMAGE_HDU, &fptr);
 
   /* Read the WCS information: */
-  gal_fitsarray_read_wcs(fptr, nwcs, wcs, hstartwcs, hendwcs);
+  gal_fits_read_wcs_from_pointer(fptr, nwcs, wcs, hstartwcs, hendwcs);
 
   /* Close the FITS file: */
   fits_close_file(fptr, &status);
-  gal_fitsarray_io_error(status, NULL);
+  gal_fits_io_error(status, NULL);
 }
 
 
@@ -1297,7 +1298,7 @@ gal_fitsarray_read_fits_wcs(char *filename, char *hdu, 
size_t hstartwcs,
    function. The value that is placed for those pixels is defined by
    the macros in fitsarrayvv.h and depends on the type of the data.*/
 int
-gal_fitsarray_fits_img_to_array(char *filename, char *hdu, int *bitpix,
+gal_fits_hdu_to_array(char *filename, char *hdu, int *bitpix,
                                 void **array, size_t *s0, size_t *s1)
 {
   void *bitblank;
@@ -1306,26 +1307,26 @@ gal_fitsarray_fits_img_to_array(char *filename, char 
*hdu, int *bitpix,
   long naxes[2], fpixel[]={1,1};
 
   /* Check HDU for realistic conditions: */
-  gal_fitsarray_read_fits_hdu(filename, hdu, IMAGE_HDU, &fptr);
+  gal_fits_read_hdu(filename, hdu, IMAGE_HDU, &fptr);
 
   /* Get the bitpix and size of the image: */
-  gal_fitsarray_img_bitpix_size(fptr, bitpix, naxes);
+  gal_fits_img_bitpix_size(fptr, bitpix, naxes);
   *s0=naxes[1];
   *s1=naxes[0];
 
   /* Allocate space for the array. */
-  bitblank=gal_fitsarray_bitpix_blank(*bitpix);
-  *array=gal_fitsarray_bitpix_alloc(*s0 * *s1, *bitpix);
+  bitblank=gal_fits_bitpix_blank(*bitpix);
+  *array=gal_fits_bitpix_alloc(*s0 * *s1, *bitpix);
 
   /* Read the image into the allocated array: */
-  fits_read_pix(fptr, gal_fitsarray_bitpix_to_dtype(*bitpix), fpixel, *s0 * 
*s1,
+  fits_read_pix(fptr, gal_fits_bitpix_to_dtype(*bitpix), fpixel, *s0 * *s1,
                bitblank, *array, &anyblank, &status);
-  if(status) gal_fitsarray_io_error(status, NULL);
+  if(status) gal_fits_io_error(status, NULL);
   free(bitblank);
 
   /* Close the FITS file: */
   fits_close_file(fptr, &status);
-  gal_fitsarray_io_error(status, NULL);
+  gal_fits_io_error(status, NULL);
 
   /* Return the number of blank pixels: */
   return anyblank;
@@ -1354,11 +1355,11 @@ gal_fitsarray_fits_img_to_array(char *filename, char 
*hdu, int *bitpix,
  ******************      Array to FITS      ******************
  *************************************************************/
 void
-gal_fitsarray_array_to_fits_img(char *filename, char *hdu, int bitpix,
-                                void *array, size_t s0, size_t s1, int 
anyblank,
-                                struct wcsprm *wcs,
-                                struct gal_fitsarray_header_ll *headers,
-                                char *spack_string)
+gal_fits_array_to_file(char *filename, char *hdu, int bitpix,
+                       void *array, size_t s0, size_t s1, int anyblank,
+                       struct wcsprm *wcs,
+                       struct gal_fits_header_ll *headers,
+                       char *spack_string)
 {
   int nkeyrec;
   void *blank;
@@ -1367,7 +1368,7 @@ gal_fitsarray_array_to_fits_img(char *filename, char 
*hdu, int bitpix,
   int status=0, datatype;
   long fpixel=1, naxis=2, nelements, naxes[]={s1,s0};
 
-  datatype=gal_fitsarray_bitpix_to_dtype(bitpix);
+  datatype=gal_fits_bitpix_to_dtype(bitpix);
   nelements=naxes[0]*naxes[1];
 
   if(access(filename,F_OK) != -1 )
@@ -1382,15 +1383,15 @@ gal_fitsarray_array_to_fits_img(char *filename, char 
*hdu, int bitpix,
     if(bitpix==BYTE_IMG || bitpix==SHORT_IMG
        || bitpix==LONG_IMG || bitpix==LONGLONG_IMG)
       {
-        blank=gal_fitsarray_bitpix_blank(bitpix);
+        blank=gal_fits_bitpix_blank(bitpix);
         if(fits_write_key(fptr, datatype, "BLANK", blank,
                           "Pixels with no data.", &status) )
-          gal_fitsarray_io_error(status, "adding the BLANK keyword");
+          gal_fits_io_error(status, "adding the BLANK keyword");
         free(blank);
       }
 
   fits_write_key(fptr, TSTRING, "EXTNAME", hdu, "", &status);
-  gal_fitsarray_io_error(status, NULL);
+  gal_fits_io_error(status, NULL);
 
   if(wcs)
     {
@@ -1399,13 +1400,13 @@ gal_fitsarray_array_to_fits_img(char *filename, char 
*hdu, int bitpix,
       if(status)
        error(EXIT_FAILURE, 0, "wcshdo ERROR %d: %s", status,
              wcs_errmsg[status]);
-      gal_fitsarray_add_wcs_to_header(fptr, wcsheader, nkeyrec);
+      gal_fits_add_wcs_to_header(fptr, wcsheader, nkeyrec);
     }
 
-  gal_fitsarray_copyright_end(fptr, headers, spack_string);
+  gal_fits_copyright_end(fptr, headers, spack_string);
 
   fits_close_file(fptr, &status);
-  gal_fitsarray_io_error(status, NULL);
+  gal_fits_io_error(status, NULL);
 }
 
 
@@ -1413,7 +1414,7 @@ gal_fitsarray_array_to_fits_img(char *filename, char 
*hdu, int bitpix,
 
 
 void
-gal_fitsarray_atof_correct_wcs(char *filename, char *hdu, int bitpix,
+gal_fits_atof_correct_wcs(char *filename, char *hdu, int bitpix,
                                void *array, size_t s0, size_t s1,
                                char *wcsheader, int wcsnkeyrec,
                                double *crpix, char *spack_string)
@@ -1422,7 +1423,7 @@ gal_fitsarray_atof_correct_wcs(char *filename, char *hdu, 
int bitpix,
   int status=0, datatype;
   long fpixel=1, naxis=2, nelements, naxes[]={s1,s0};
 
-  datatype=gal_fitsarray_bitpix_to_dtype(bitpix);
+  datatype=gal_fits_bitpix_to_dtype(bitpix);
   nelements=naxes[0]*naxes[1];
 
   if(access(filename,F_OK) != -1 )
@@ -1434,27 +1435,27 @@ gal_fitsarray_atof_correct_wcs(char *filename, char 
*hdu, int bitpix,
   fits_write_img(fptr, datatype, fpixel, nelements, array, &status);
 
   fits_write_key(fptr, TSTRING, "EXTNAME", hdu, "", &status);
-  gal_fitsarray_io_error(status, NULL);
+  gal_fits_io_error(status, NULL);
 
   fits_delete_key(fptr, "COMMENT", &status);
   fits_delete_key(fptr, "COMMENT", &status);
-  gal_fitsarray_io_error(status, NULL);
+  gal_fits_io_error(status, NULL);
 
   if(wcsheader)
     {
-      gal_fitsarray_add_wcs_to_header(fptr, wcsheader, wcsnkeyrec);
+      gal_fits_add_wcs_to_header(fptr, wcsheader, wcsnkeyrec);
       if(crpix)
        {
          fits_update_key(fptr, TDOUBLE, "CRPIX1", &crpix[0], NULL, &status);
          fits_update_key(fptr, TDOUBLE, "CRPIX2", &crpix[1], NULL, &status);
-         gal_fitsarray_io_error(status, NULL);
+         gal_fits_io_error(status, NULL);
        }
     }
 
-  gal_fitsarray_copyright_end(fptr, NULL, spack_string);
+  gal_fits_copyright_end(fptr, NULL, spack_string);
 
   fits_close_file(fptr, &status);
-  gal_fitsarray_io_error(status, NULL);
+  gal_fits_io_error(status, NULL);
 }
 
 
@@ -1485,7 +1486,7 @@ gal_fitsarray_atof_correct_wcs(char *filename, char *hdu, 
int bitpix,
    this function is to determine which is the case and set othername
    to the appropriate value. */
 void
-gal_fitsarray_file_or_ext_name(char *inputname, char *inhdu, int othernameset,
+gal_fits_file_or_ext_name(char *inputname, char *inhdu, int othernameset,
                                char **othername, char *ohdu, int ohduset,
                                char *type)
 {
@@ -1529,7 +1530,7 @@ gal_fitsarray_file_or_ext_name(char *inputname, char 
*inhdu, int othernameset,
    original input bitpix will be stored so if you want to, you can
    return it back to the input type if you please. */
 void
-gal_fitsarray_file_to_float(char *inputname, char *maskname, char *inhdu,
+gal_fits_file_to_float(char *inputname, char *maskname, char *inhdu,
                             char *mhdu, float **img, int *inbitpix,
                             int *anyblank, size_t *ins0, size_t *ins1)
 {
@@ -1539,13 +1540,13 @@ gal_fitsarray_file_to_float(char *inputname, char 
*maskname, char *inhdu,
   size_t maskanyblank, s0, s1;
 
   /* Read the input array and convert it to float. */
-  *anyblank=gal_fitsarray_fits_img_to_array(inputname, inhdu, inbitpix,
-                                            &array, ins0, ins1);
+  *anyblank=gal_fits_hdu_to_array(inputname, inhdu, inbitpix,
+                                  &array, ins0, ins1);
   if(*inbitpix==FLOAT_IMG)
     *img=array;
   else
     {
-      gal_fitsarray_change_type(array, *inbitpix, *ins0 * *ins1, *anyblank,
+      gal_fits_change_type(array, *inbitpix, *ins0 * *ins1, *anyblank,
                                 (void **)img, FLOAT_IMG);
       free(array);
     }
@@ -1554,8 +1555,8 @@ gal_fitsarray_file_to_float(char *inputname, char 
*maskname, char *inhdu,
      the corresponding pixels of the input image to NaN. */
   if(maskname)
     {
-      maskanyblank=gal_fitsarray_fits_img_to_array(maskname, mhdu, &maskbitpix,
-                                                   &array, &s0, &s1);
+      maskanyblank=gal_fits_hdu_to_array(maskname, mhdu, &maskbitpix,
+                                         &array, &s0, &s1);
 
       if(maskbitpix==FLOAT_IMG || maskbitpix==DOUBLE_IMG)
         fprintf(stderr, "WARNING: the mask image (%s, hdu: %s) has a %s "
@@ -1577,7 +1578,7 @@ gal_fitsarray_file_to_float(char *inputname, char 
*maskname, char *inhdu,
         mask=array;
       else
         {
-          gal_fitsarray_change_type(array, maskbitpix, *ins0 * *ins1,
+          gal_fits_change_type(array, maskbitpix, *ins0 * *ins1,
                                     maskanyblank, (void **)(&mask), FLOAT_IMG);
           free(array);
         }
@@ -1594,7 +1595,7 @@ gal_fitsarray_file_to_float(char *inputname, char 
*maskname, char *inhdu,
 
 /* Similar to filetofloat, but for double type */
 void
-gal_fitsarray_file_to_double(char *inputname, char *maskname, char *inhdu,
+gal_fits_file_to_double(char *inputname, char *maskname, char *inhdu,
                              char *mhdu, double **img, int *inbitpix,
                              int *anyblank, size_t *ins0, size_t *ins1)
 {
@@ -1604,13 +1605,13 @@ gal_fitsarray_file_to_double(char *inputname, char 
*maskname, char *inhdu,
   size_t maskanyblank, s0, s1;
 
   /* Read the input array and convert it to double. */
-  *anyblank=gal_fitsarray_fits_img_to_array(inputname, inhdu, inbitpix,
-                                            &array, ins0, ins1);
+  *anyblank=gal_fits_hdu_to_array(inputname, inhdu, inbitpix,
+                                  &array, ins0, ins1);
   if(*inbitpix==DOUBLE_IMG)
     *img=array;
   else
     {
-      gal_fitsarray_change_type(array, *inbitpix, *ins0 * *ins1, *anyblank,
+      gal_fits_change_type(array, *inbitpix, *ins0 * *ins1, *anyblank,
                                 (void **)img, DOUBLE_IMG);
       free(array);
     }
@@ -1619,9 +1620,8 @@ gal_fitsarray_file_to_double(char *inputname, char 
*maskname, char *inhdu,
      the corresponding pixels of the input image to NaN. */
   if(maskname)
     {
-      maskanyblank=gal_fitsarray_fits_img_to_array(maskname,
-                                                   mhdu, &maskbitpix,
-                                                   &array, &s0, &s1);
+      maskanyblank=gal_fits_hdu_to_array(maskname, mhdu, &maskbitpix,
+                                         &array, &s0, &s1);
 
       if(maskbitpix==FLOAT_IMG || maskbitpix==DOUBLE_IMG)
         fprintf(stderr, "WARNING: the mask image (%s, hdu: %s) has a %s "
@@ -1643,7 +1643,7 @@ gal_fitsarray_file_to_double(char *inputname, char 
*maskname, char *inhdu,
         mask=array;
       else
         {
-          gal_fitsarray_change_type(array, maskbitpix, *ins0 * *ins1,
+          gal_fits_change_type(array, maskbitpix, *ins0 * *ins1,
                                     maskanyblank, (void **)(&mask),
                                     DOUBLE_IMG);
           free(array);
@@ -1661,20 +1661,20 @@ gal_fitsarray_file_to_double(char *inputname, char 
*maskname, char *inhdu,
 
 
 void
-gal_fitsarray_file_to_long(char *inputname, char *inhdu, long **img,
+gal_fits_file_to_long(char *inputname, char *inhdu, long **img,
                            int *inbitpix, int *anyblank, size_t *ins0,
                            size_t *ins1)
 {
   void *array;
 
   /* Read the input array and convert it to float. */
-  *anyblank=gal_fitsarray_fits_img_to_array(inputname, inhdu, inbitpix,
-                                            &array, ins0, ins1);
+  *anyblank=gal_fits_hdu_to_array(inputname, inhdu, inbitpix,
+                                  &array, ins0, ins1);
   if(*inbitpix==LONG_IMG)
     *img=array;
   else
     {
-      gal_fitsarray_change_type(array, *inbitpix, *ins0 * *ins1, *anyblank,
+      gal_fits_change_type(array, *inbitpix, *ins0 * *ins1, *anyblank,
                                 (void **)img, LONG_IMG);
       free(array);
     }
@@ -1685,7 +1685,7 @@ gal_fitsarray_file_to_long(char *inputname, char *inhdu, 
long **img,
 
 
 void
-gal_fitsarray_prep_float_kernel(char *inputname, char *inhdu, float 
**outkernel,
+gal_fits_prep_float_kernel(char *inputname, char *inhdu, float **outkernel,
                                 size_t *ins0, size_t *ins1)
 {
   size_t i, size;
@@ -1694,7 +1694,7 @@ gal_fitsarray_prep_float_kernel(char *inputname, char 
*inhdu, float **outkernel,
   float *f, *fp, *kernel, tmp;
 
   /* Read the kernel as a float array: */
-  gal_fitsarray_file_to_float(inputname, NULL, inhdu, NULL, outkernel, &bitpix,
+  gal_fits_file_to_float(inputname, NULL, inhdu, NULL, outkernel, &bitpix,
                               &anyblank, ins0, ins1);
   size = *ins0 * *ins1;
   kernel=*outkernel;
@@ -1724,161 +1724,3 @@ gal_fitsarray_prep_float_kernel(char *inputname, char 
*inhdu, float **outkernel,
       kernel[size-i-1]=tmp;
     }
 }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/**************************************************************/
-/**********              XY to RADEC               ************/
-/**************************************************************/
-/* Convert the X and y coordinates in a larger array to ra and dec
-   coordinates in that same array. xy points to the first element in
-   the X column and radec points to the first element in the RA
-   column. The columns for Y and Dec have to be immediately after X
-   and RA.
-
-   It appears that WCSLIB can only deal with static allocation. At
-   least in its tests it only uses static allocation. I tried dynamic
-   allocation, but it didn't work. So I can't use the vector
-   functionalities of WCSLIB and have to translate each point
-   separately.
-*/
-void
-gal_fitsarray_xy_array_to_radec(struct wcsprm *wcs, double *xy, double *radec,
-                                size_t number, size_t width)
-{
-  size_t i;
-  double imgcrd[2], phi, theta;
-  int stat, status=0, ncoord=1, nelem=2;
-
-  for(i=0;i<number;++i)
-    {
-      if(isnan(xy[i*width]) || isnan(xy[i*width+1]))
-        radec[i*width]=radec[i*width+1]=NAN;
-      else
-        {
-          status=wcsp2s(wcs, ncoord, nelem, xy+i*width, imgcrd, &phi,
-                        &theta, radec+i*width, &stat);
-          if(status)
-            error(EXIT_FAILURE, 0, "wcsp2s ERROR %d: %s", status,
-                  wcs_errmsg[status]);
-
-          /* For a check:
-             printf("(%f, %f) --> (%f, %f)\n", xy[i*width], xy[i*width+1],
-                    radec[i*width], radec[i*width+1]);
-          */
-        }
-    }
-}
-
-
-
-
-
-void
-gal_fitsarray_radec_array_to_xy(struct wcsprm *wcs, double *radec, double *xy,
-                                size_t number, size_t width)
-{
-  size_t i;
-  double imgcrd[2], phi, theta;
-  int stat, status=0, ncoord=1, nelem=2;
-
-  for(i=0;i<number;++i)
-    {
-      if(isnan(radec[i*width]) || isnan(radec[i*width+1]))
-        radec[i*width]=radec[i*width+1]=NAN;
-      else
-        {
-          status=wcss2p(wcs, ncoord, nelem, radec+i*width, &phi, &theta,
-                        imgcrd, xy+i*width, &stat);
-          if(status)
-            error(EXIT_FAILURE, 0, "wcss2p ERROR %d: %s", status,
-                  wcs_errmsg[status]);
-          /* For a check:
-             printf("(%f, %f) --> (%f, %f)\n", xy[i*width], xy[i*width+1],
-                    radec[i*width], radec[i*width+1]);
-          */
-        }
-    }
-}
-
-
-
-
-/* The distance (along a great circle) on a sphere between two points
-   is calculated here. Since the pixel sides are usually very small,
-   we won't be using the direct formula:
-
-   cos(distance)=sin(d1)*sin(d2)+cos(d1)*cos(d2)*cos(r1-r2)
-
-   We will be using the haversine formula which better considering
-   floating point errors (from Wikipedia:)
-
-   sin^2(distance)/2=sin^2( (d1-d2)/2 )+cos(d1)*cos(d2)*sin^2( (r1-r2)/2 )
-*/
-double
-angulardistance(double r1, double d1, double r2, double d2)
-{
-  double a=sin( (d1-d2)/2 );
-  double b=sin( (r1-r2)/2 );
-
-  return 2*asin( sqrt( a*a + cos(d1)*cos(d2)*b*b) );
-}
-
-
-
-
-
-/* Report the arcsec^2 area of the pixels in the image based on the
-   WCS information in that image. We first use the angular distance of
-   two edges of one pixel in radians. Then the radians are multiplied
-   to give stradians and finally, the stradians are converted to
-   arcsec^2. */
-double
-gal_fitsarray_pixel_area_arcsec2(struct wcsprm *wcs)
-{
-  double xy[]={0,0,1,0,0,1};
-  double st, *d, *df, radec[6];
-
-  /* Get the RA and Dec of the bottom left, bottom right and top left
-     sides of the first pixel in the image. */
-  gal_fitsarray_xy_array_to_radec(wcs, xy, radec, 3, 2);
-
-  /* Covert the RA and dec values to radians for easy calculation: */
-  df=(d=radec)+6; do *d++ *= M_PI/180.0f; while(d<df);
-
-  /* For a check:
-  printf("\n\nAlong first axis: %g\nAlong second axis: %g\n\n",
-         ( angulardistance(radec[0], radec[1], radec[2], radec[3])
-           *180/M_PI*3600 ),
-         ( angulardistance(radec[0], radec[1], radec[4], radec[5])
-           *180/M_PI*3600 ) );
-  */
-
-  /* Get the area in stradians. */
-  st= ( angulardistance(radec[0], radec[1], radec[2], radec[3]) *
-        angulardistance(radec[0], radec[1], radec[4], radec[5]) );
-
-  /* Convert the stradians to arcsec^2:
-
-     1deg^2 = (180/PI)^2 * 1stradian.
-     1arcsec^2 = (3600*3600) * 1degree^2
-   */
-  return st*180.0f*180.0f*3600.0f*3600.0f/(M_PI*M_PI);
-}
diff --git a/lib/gnuastro/fits.h b/lib/gnuastro/fits.h
new file mode 100644
index 0000000..cca2c14
--- /dev/null
+++ b/lib/gnuastro/fits.h
@@ -0,0 +1,245 @@
+/*********************************************************************
+Functions to convert a FITS array to a C array and vice versa.
+This is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+     Mohammad Akhlaghi <address@hidden>
+Contributing author(s):
+Copyright (C) 2015, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#ifndef __GAL_FITS_H__
+#define __GAL_FITS_H__
+
+#include <math.h>
+#include <float.h>
+#include <stdint.h>
+
+#include <fitsio.h>
+#include <wcslib/wcs.h>
+#include <wcslib/wcshdr.h>
+#include <wcslib/wcsfix.h>
+
+#define GAL_FITS_STRING_BLANK   NULL
+#define GAL_FITS_BYTE_BLANK     UCHAR_MAX /* 0 is often meaningful here! */
+#define GAL_FITS_SHORT_BLANK    INT16_MIN
+#define GAL_FITS_LONG_BLANK     INT32_MIN
+#define GAL_FITS_LLONG_BLANK    INT64_MIN
+#define GAL_FITS_FLOAT_BLANK    NAN
+
+
+
+
+
+/*
+
+For some reason, CFITSIO does not use the standard stdint fixed size
+types! It uses the subjective 'short', 'int' and 'long' variables
+which can differ in size from system to system!!!!!!!!!!!!!!!
+
+In the 32bit systems that 'long' was 32 bits or 4 bytes, has passed
+but the names have stuck! The FITS standard defines LONG_IMG as a
+32bit signed type, but CFITSIO converts it to a local 'long' which is
+64 bits on a modern (64 bit) system!!!! This is simply absurd and very
+confusing!!!! It should have stuck to the standard, not the name of
+the variable!
+
+Because of this we have to stick to this wrong convention too.
+
+ */
+
+
+/*************************************************************
+ ******************         Basic          *******************
+ *************************************************************/
+void
+gal_fits_io_error(int status, char *message);
+
+int
+gal_fits_name_is_fits(char *name);
+
+int
+gal_fits_name_is_fits_suffix(char *name);
+
+void
+gal_fits_num_hdus(char *filename, int *numhdu);
+
+
+
+
+
+/*************************************************************
+ ******************         Header          ******************
+ *************************************************************/
+/* To create a linked list of headers. */
+struct gal_fits_header_ll
+{
+  int                 kfree;   /* ==1, keyname will be freed.          */
+  int                 vfree;   /* ==1, value will be freed.            */
+  int                 cfree;   /* ==1, comment will be freed.          */
+  int              datatype;   /* Data type of the keyword             */
+  char             *keyname;   /* Name of keyword.                     */
+  void               *value;   /* Pointer to the value of the keyword. */
+  char             *comment;   /* Comment for the keyword.             */
+  char                *unit;   /* Units of the keyword.                */
+  struct gal_fits_header_ll *next;   /* Pointer to the next element.         */
+};
+
+
+
+
+
+struct gal_fits_read_header_keys
+{
+  char   *keyname;
+  int    datatype;
+  char         *c;
+  unsigned char u;
+  short         s;
+  long          l;
+  LONGLONG      L;
+  float         f;
+  double        d;
+};
+
+
+
+
+
+void
+gal_fits_read_keywords(char *filename, char *hdu,
+                       struct gal_fits_read_header_keys *out,
+                       size_t num);
+
+void
+gal_fits_add_to_fits_header_ll(struct gal_fits_header_ll **list,
+                               int datatype, char *keyname, int kfree,
+                               void *value, int vfree, char *comment,
+                               int cfree, char *unit);
+
+void
+gal_fits_add_to_fits_header_ll_end(struct gal_fits_header_ll **list,
+                                   int datatype, char *keyname, int kfree,
+                                   void *value, int vfree, char *comment,
+                                   int cfree, char *unit);
+
+void
+gal_fits_file_name_in_keywords(char *keynamebase, char *filename,
+                                    struct gal_fits_header_ll **list);
+
+void
+gal_fits_add_wcs_to_header(fitsfile *fptr, char *wcsheader, int nkeyrec);
+
+void
+gal_fits_update_keys(fitsfile *fptr,
+                     struct gal_fits_header_ll **keylist);
+
+void
+gal_fits_copyright_end(fitsfile *fptr,
+                       struct gal_fits_header_ll *headers,
+                       char *spack_string);
+
+
+
+
+
+/*************************************************************
+ ******************        Read/Write        *****************
+ *************************************************************/
+void *
+gal_fits_bitpix_blank(int bitpix);
+
+void
+gal_fits_convert_blank(void *array, int bitpix, size_t size, void *value);
+
+int
+gal_fits_bitpix_to_dtype(int bitpix);
+
+void
+gal_fits_img_bitpix_size(fitsfile *fptr, int *bitpix, long *naxis);
+
+void
+gal_fits_read_hdu(char *filename, char *hdu, int desiredtype,
+                  fitsfile **outfptr);
+
+void *
+gal_fits_bitpix_alloc(size_t size, int bitpix);
+
+void
+gal_fits_change_type(void *in, int inbitpix, size_t size, int anyblank,
+                          void **out, int outbitpix);
+
+void
+gal_fits_read_wcs_from_pointer(fitsfile *fptr, int *nwcs,
+                               struct wcsprm **wcs,
+                               size_t hstart, size_t hend);
+
+void
+gal_fits_read_wcs(char *filename, char *hdu, size_t hstartwcs,
+                  size_t hendwcs, int *nwcs, struct wcsprm **wcs);
+
+int
+gal_fits_hdu_to_array(char *filename, char *hdu, int *bitpix,
+                      void **array, size_t *s0, size_t *s1);
+
+void
+gal_fits_array_to_file(char *filename, char *hdu, int bitpix,
+                       void *array, size_t s0, size_t s1, int anyblank,
+                       struct wcsprm *wcs,
+                       struct gal_fits_header_ll *headers,
+                       char *spack_string);
+
+void
+gal_fits_atof_correct_wcs(char *filename, char *hdu, int bitpix,
+                          void *array, size_t s0, size_t s1,
+                          char *wcsheader, int wcsnkeyrec,
+                          double *crpix, char *spack_string);
+
+
+
+
+
+/**************************************************************/
+/**********          Check prepare file            ************/
+/**************************************************************/
+void
+gal_fits_file_or_ext_name(char *inputname, char *inhdu, int othernameset,
+                          char **othername, char *ohdu, int ohduset,
+                          char *type);
+
+void
+gal_fits_set_mask_name(char *inputname, char **maskname, char *inhdu,
+                       char *mhdu);
+
+void
+gal_fits_file_to_double(char *inputname, char *maskname, char *inhdu,
+                        char *mhdu, double **img, int *inbitpix,
+                        int *anyblank, size_t *ins0, size_t *ins1);
+
+void
+gal_fits_file_to_float(char *inputname, char *maskname, char *inhdu,
+                       char *mhdu, float **img, int *inbitpix,
+                       int *anyblank, size_t *ins0, size_t *ins1);
+
+void
+gal_fits_file_to_long(char *inputname, char *inhdu, long **img,
+                      int *inbitpix, int *anyblank, size_t *ins0,
+                      size_t *ins1);
+
+void
+gal_fits_prep_float_kernel(char *inputname, char *inhdu, float **kernel,
+                           size_t *ins0, size_t *ins1);
+
+#endif
diff --git a/lib/gnuastro/fitsarrayvv.h b/lib/gnuastro/fitsarrayvv.h
deleted file mode 100644
index 3530ad4..0000000
--- a/lib/gnuastro/fitsarrayvv.h
+++ /dev/null
@@ -1,262 +0,0 @@
-/*********************************************************************
-Functions to convert a FITS array to a C array and vice versa.
-This is part of GNU Astronomy Utilities (Gnuastro) package.
-
-Original author:
-     Mohammad Akhlaghi <address@hidden>
-Contributing author(s):
-Copyright (C) 2015, Free Software Foundation, Inc.
-
-Gnuastro is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by the
-Free Software Foundation, either version 3 of the License, or (at your
-option) any later version.
-
-Gnuastro is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
-**********************************************************************/
-#ifndef __GAL_FITSMATRIX_H__
-#define __GAL_FITSMATRIX_H__
-
-#include <math.h>
-#include <float.h>
-#include <stdint.h>
-
-#include <fitsio.h>
-#include <wcslib/wcshdr.h>
-#include <wcslib/wcsfix.h>
-#include <wcslib/wcs.h>
-
-#define GAL_FITSARRAY_STRING_BLANK   NULL
-#define GAL_FITSARRAY_BYTE_BLANK     UCHAR_MAX /* 0 is often meaningful here! 
*/
-#define GAL_FITSARRAY_SHORT_BLANK    INT16_MIN
-#define GAL_FITSARRAY_LONG_BLANK     INT32_MIN
-#define GAL_FITSARRAY_LLONG_BLANK    INT64_MIN
-#define GAL_FITSARRAY_FLOAT_BLANK    NAN
-
-
-
-
-
-/*
-
-For some reason, CFITSIO does not use the standard stdint fixed size
-types! It uses the subjective 'short', 'int' and 'long' variables
-which can differ in size from system to system!!!!!!!!!!!!!!!
-
-In the 32bit systems that 'long' was 32 bits or 4 bytes, has passed
-but the names have stuck! The FITS standard defines LONG_IMG as a
-32bit signed type, but CFITSIO converts it to a local 'long' which is
-64 bits on a modern (64 bit) system!!!! This is simply absurd and very
-confusing!!!! It should have stuck to the standard, not the name of
-the variable!
-
-Because of this we have to stick to this wrong convention too.
-
- */
-
-
-/*************************************************************
- ******************         Basic          *******************
- *************************************************************/
-void
-gal_fitsarray_io_error(int status, char *message);
-
-int
-gal_fitsarray_name_is_fits(char *name);
-
-int
-gal_fitsarray_name_is_fits_suffix(char *name);
-
-void
-gal_fitsarray_num_hdus(char *filename, int *numhdu);
-
-
-
-
-
-/*************************************************************
- ******************         Header          ******************
- *************************************************************/
-/* To create a linked list of headers. */
-struct gal_fitsarray_header_ll
-{
-  int                 kfree;   /* ==1, keyname will be freed.          */
-  int                 vfree;   /* ==1, value will be freed.            */
-  int                 cfree;   /* ==1, comment will be freed.          */
-  int              datatype;   /* Data type of the keyword             */
-  char             *keyname;   /* Name of keyword.                     */
-  void               *value;   /* Pointer to the value of the keyword. */
-  char             *comment;   /* Comment for the keyword.             */
-  char                *unit;   /* Units of the keyword.                */
-  struct gal_fitsarray_header_ll *next;   /* Pointer to the next element.      
   */
-};
-
-
-
-
-
-struct gal_fitsarray_read_header_keys
-{
-  char   *keyname;
-  int    datatype;
-  char         *c;
-  unsigned char u;
-  short         s;
-  long          l;
-  LONGLONG      L;
-  float         f;
-  double        d;
-};
-
-
-
-
-
-void
-gal_fitsarray_read_keywords(char *filename, char *hdu,
-                            struct gal_fitsarray_read_header_keys *out,
-                            size_t num);
-
-void
-gal_fitsarray_add_to_fits_header_ll(struct gal_fitsarray_header_ll **list,
-                                    int datatype, char *keyname, int kfree,
-                                    void *value, int vfree, char *comment,
-                                    int cfree, char *unit);
-
-void
-gal_fitsarray_add_to_fits_header_ll_end(struct gal_fitsarray_header_ll **list,
-                                        int datatype, char *keyname, int kfree,
-                                        void *value, int vfree, char *comment,
-                                        int cfree, char *unit);
-
-void
-gal_fitsarray_file_name_in_keywords(char *keynamebase, char *filename,
-                                    struct gal_fitsarray_header_ll **list);
-
-void
-gal_fitsarray_add_wcs_to_header(fitsfile *fptr, char *wcsheader, int nkeyrec);
-
-void
-gal_fitsarray_update_keys(fitsfile *fptr,
-                          struct gal_fitsarray_header_ll **keylist);
-
-void
-gal_fitsarray_copyright_end(fitsfile *fptr,
-                            struct gal_fitsarray_header_ll *headers,
-                            char *spack_string);
-
-
-
-
-
-/*************************************************************
- ******************        Read/Write        *****************
- *************************************************************/
-void *
-gal_fitsarray_bitpix_blank(int bitpix);
-
-void
-gal_fitsarray_convert_blank(void *array, int bitpix, size_t size, void *value);
-
-int
-gal_fitsarray_bitpix_to_dtype(int bitpix);
-
-void
-gal_fitsarray_img_bitpix_size(fitsfile *fptr, int *bitpix, long *naxis);
-
-void
-gal_fitsarray_read_fits_hdu(char *filename, char *hdu, int desiredtype,
-                            fitsfile **outfptr);
-
-void *
-gal_fitsarray_bitpix_alloc(size_t size, int bitpix);
-
-void
-gal_fitsarray_change_type(void *in, int inbitpix, size_t size, int anyblank,
-                          void **out, int outbitpix);
-
-void
-gal_fitsarray_read_wcs(fitsfile *fptr, int *nwcs, struct wcsprm **wcs,
-                       size_t hstart, size_t hend);
-
-void
-gal_fitsarray_read_fits_wcs(char *filename, char *hdu, size_t hstartwcs,
-                            size_t hendwcs, int *nwcs, struct wcsprm **wcs);
-
-int
-gal_fitsarray_fits_img_to_array(char *filename, char *hdu, int *bitpix,
-                                void **array, size_t *s0, size_t *s1);
-
-void
-gal_fitsarray_array_to_fits_img(char *filename, char *hdu, int bitpix,
-                                void *array, size_t s0, size_t s1, int 
anyblank,
-                                struct wcsprm *wcs,
-                                struct gal_fitsarray_header_ll *headers,
-                                char *spack_string);
-
-void
-gal_fitsarray_atof_correct_wcs(char *filename, char *hdu, int bitpix,
-                               void *array, size_t s0, size_t s1,
-                               char *wcsheader, int wcsnkeyrec,
-                               double *crpix, char *spack_string);
-
-
-
-
-
-/**************************************************************/
-/**********          Check prepare file            ************/
-/**************************************************************/
-void
-gal_fitsarray_file_or_ext_name(char *inputname, char *inhdu, int othernameset,
-                               char **othername, char *ohdu, int ohduset,
-                               char *type);
-
-void
-gal_fitsarray_set_mask_name(char *inputname, char **maskname, char *inhdu,
-                            char *mhdu);
-
-void
-gal_fitsarray_file_to_double(char *inputname, char *maskname, char *inhdu,
-                             char *mhdu, double **img, int *inbitpix,
-                             int *anyblank, size_t *ins0, size_t *ins1);
-
-void
-gal_fitsarray_file_to_float(char *inputname, char *maskname, char *inhdu,
-                            char *mhdu, float **img, int *inbitpix,
-                            int *anyblank, size_t *ins0, size_t *ins1);
-
-void
-gal_fitsarray_file_to_long(char *inputname, char *inhdu, long **img,
-                           int *inbitpix, int *anyblank, size_t *ins0,
-                           size_t *ins1);
-
-void
-gal_fitsarray_prep_float_kernel(char *inputname, char *inhdu, float **kernel,
-                                size_t *ins0, size_t *ins1);
-
-
-
-
-
-/**************************************************************/
-/**********              XY to RADEC               ************/
-/**************************************************************/
-void
-gal_fitsarray_xy_array_to_radec(struct wcsprm *wcs, double *xy, double *radec,
-                                size_t number, size_t width);
-
-void
-gal_fitsarray_radec_array_to_xy(struct wcsprm *wcs, double *radec, double *xy,
-                                size_t number, size_t width);
-
-double
-gal_fitsarray_pixel_area_arcsec2(struct wcsprm *wcs);
-
-#endif
diff --git a/lib/gnuastro/wcs.h b/lib/gnuastro/wcs.h
new file mode 100644
index 0000000..2cb80a6
--- /dev/null
+++ b/lib/gnuastro/wcs.h
@@ -0,0 +1,39 @@
+/*********************************************************************
+Functions to that only use WCSLIB's functions, not related to FITS.
+This is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+     Mohammad Akhlaghi <address@hidden>
+Contributing author(s):
+Copyright (C) 2015, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#ifndef __GAL_WCS_H__
+#define __GAL_WCS_H__
+
+#include <wcslib/wcs.h>
+
+void
+gal_wcs_xy_array_to_radec(struct wcsprm *wcs, double *xy, double *radec,
+                          size_t number, size_t width);
+
+void
+gal_wcs_radec_array_to_xy(struct wcsprm *wcs, double *radec, double *xy,
+                          size_t number, size_t width);
+
+double
+gal_wcs_pixel_area_arcsec2(struct wcsprm *wcs);
+
+#endif
diff --git a/lib/mesh.c b/lib/mesh.c
index 0e6d3f5..930d64c 100644
--- a/lib/mesh.c
+++ b/lib/mesh.c
@@ -30,13 +30,13 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <stdlib.h>
 #include <string.h>
 
+#include <gnuastro/fits.h>
 #include <gnuastro/mesh.h>
 #include <gnuastro/mode.h>
 #include <gnuastro/qsort.h>
 #include <gnuastro/neighbors.h>
 #include <gnuastro/linkedlist.h>
 #include <gnuastro/statistics.h>
-#include <gnuastro/fitsarrayvv.h>
 #include <gnuastro/spatialconvolve.h>
 
 
@@ -347,13 +347,13 @@ gal_mesh_full_garray(struct gal_mesh_params *mp, int 
reverse)
     }
 
   /* Just for a check:
-  gal_fitsarray_array_to_fits_img("nochannels.fits", "fgarray1", FLOAT_IMG, 
fgarray1,
-                 mp->nch2*mp->gs0, mp->nch1*mp->gs1, 1, NULL, NULL,
-                 "mesh");
+  gal_fits_array_to_file("nochannels.fits", "fgarray1", FLOAT_IMG,
+                         fgarray1, mp->nch2*mp->gs0, mp->nch1*mp->gs1, 1,
+                         NULL, NULL, "mesh");
   if(mp->ngarrays==2)
-    gal_fitsarray_array_to_fits_img("nochannels.fits", "fgarray2", FLOAT_IMG, 
fgarray2,
-                   mp->nch2*mp->gs0, mp->nch1*mp->gs1, 1, NULL, NULL,
-                   "mesh");
+    gal_fits_array_to_file("nochannels.fits", "fgarray2", FLOAT_IMG,
+                           fgarray2, mp->nch2*mp->gs0, mp->nch1*mp->gs1,
+                           1, NULL, NULL, "mesh");
   */
 }
 
@@ -494,29 +494,29 @@ gal_mesh_value_file(struct gal_mesh_params *mp, char 
*filename, char *extname1,
          used for this job. In cgarray the meshs are ordered
          differently. */
       if(mp->garray1==mp->cgarray1) gal_mesh_full_garray(mp, 0);
-      gal_fitsarray_array_to_fits_img(filename, extname1, FLOAT_IMG,
-                                      mp->fgarray1, mp->gs0*mp->nch2,
-                                      mp->gs1*mp->nch1, 0, wcs, NULL,
-                                      spack_string);
+      gal_fits_array_to_file(filename, extname1, FLOAT_IMG,
+                             mp->fgarray1, mp->gs0*mp->nch2,
+                             mp->gs1*mp->nch1, 0, wcs, NULL,
+                             spack_string);
       if(mp->ngarrays==2)
         /* Note that gal_mesh_full_garray will correct both the meshs if there
            are two.*/
-        gal_fitsarray_array_to_fits_img(filename, extname2, FLOAT_IMG,
-                                        mp->fgarray2, mp->gs0*mp->nch2,
-                                        mp->gs1*mp->nch1, 0, wcs, NULL,
-                                        spack_string);
+        gal_fits_array_to_file(filename, extname2, FLOAT_IMG,
+                               mp->fgarray2, mp->gs0*mp->nch2,
+                               mp->gs1*mp->nch1, 0, wcs, NULL,
+                               spack_string);
 
     }
   else
     {
       gal_mesh_check_garray(mp, &tmp1, &tmp2);
-      gal_fitsarray_array_to_fits_img(filename, extname1, FLOAT_IMG, tmp1,
-                                      mp->s0, mp->s1, 0, wcs, NULL,
-                                      spack_string);
+      gal_fits_array_to_file(filename, extname1, FLOAT_IMG, tmp1,
+                             mp->s0, mp->s1, 0, wcs, NULL,
+                             spack_string);
       if(mp->ngarrays==2)
-        gal_fitsarray_array_to_fits_img(filename, extname2, FLOAT_IMG, tmp2,
-                                        mp->s0, mp->s1, 0, wcs, NULL,
-                                        spack_string);
+        gal_fits_array_to_file(filename, extname2, FLOAT_IMG, tmp2,
+                               mp->s0, mp->s1, 0, wcs, NULL,
+                               spack_string);
       free(tmp1);
       free(tmp2);
     }
@@ -1311,12 +1311,12 @@ gal_mesh_interpolate(struct gal_mesh_params *mp, char 
*errstart)
 
   /* For a check
   system("rm test.fits");
-  gal_fitsarray_array_to_fits_img("test.fits", "garray1", FLOAT_IMG, 
mp->garray1,
-                 mp->nch2*mp->gs0, mp->nch1*mp->gs1, 1, NULL, NULL,
-                 "mesh");
-  gal_fitsarray_array_to_fits_img("test.fits", "garray2", FLOAT_IMG, 
mp->garray2,
-                 mp->nch2*mp->gs0, mp->nch1*mp->gs1, 1, NULL, NULL,
-                 "mesh");
+  gal_fits_array_to_file("test.fits", "garray1", FLOAT_IMG, mp->garray1,
+                          mp->nch2*mp->gs0, mp->nch1*mp->gs1, 1, NULL, NULL,
+                          "mesh");
+  gal_fits_array_to_file("test.fits", "garray2", FLOAT_IMG, mp->garray2,
+                         mp->nch2*mp->gs0, mp->nch1*mp->gs1, 1, NULL, NULL,
+                         "mesh");
   */
 
   /* Clean up. */
diff --git a/lib/wcs.c b/lib/wcs.c
new file mode 100644
index 0000000..bb2fc4e
--- /dev/null
+++ b/lib/wcs.c
@@ -0,0 +1,178 @@
+/*********************************************************************
+Functions to that only use WCSLIB functionality.
+This is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+     Mohammad Akhlaghi <address@hidden>
+Contributing author(s):
+Copyright (C) 2015, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#include <config.h>
+
+#include <time.h>
+#include <errno.h>
+#include <error.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <assert.h>
+
+#include <gnuastro/wcs.h>
+#include <gnuastro/fits.h>
+
+
+
+
+
+/**************************************************************/
+/**********              XY to RADEC               ************/
+/**************************************************************/
+/* Convert the X and y coordinates in a larger array to ra and dec
+   coordinates in that same array. xy points to the first element in
+   the X column and radec points to the first element in the RA
+   column. The columns for Y and Dec have to be immediately after X
+   and RA.
+
+   It appears that WCSLIB can only deal with static allocation. At
+   least in its tests it only uses static allocation. I tried dynamic
+   allocation, but it didn't work. So I can't use the vector
+   functionalities of WCSLIB and have to translate each point
+   separately.
+*/
+void
+gal_wcs_xy_array_to_radec(struct wcsprm *wcs, double *xy, double *radec,
+                          size_t number, size_t width)
+{
+  size_t i;
+  double imgcrd[2], phi, theta;
+  int stat, status=0, ncoord=1, nelem=2;
+
+  for(i=0;i<number;++i)
+    {
+      if(isnan(xy[i*width]) || isnan(xy[i*width+1]))
+        radec[i*width]=radec[i*width+1]=NAN;
+      else
+        {
+          status=wcsp2s(wcs, ncoord, nelem, xy+i*width, imgcrd, &phi,
+                        &theta, radec+i*width, &stat);
+          if(status)
+            error(EXIT_FAILURE, 0, "wcsp2s ERROR %d: %s", status,
+                  wcs_errmsg[status]);
+
+          /* For a check:
+             printf("(%f, %f) --> (%f, %f)\n", xy[i*width], xy[i*width+1],
+                    radec[i*width], radec[i*width+1]);
+          */
+        }
+    }
+}
+
+
+
+
+
+void
+gal_wcs_radec_array_to_xy(struct wcsprm *wcs, double *radec, double *xy,
+                          size_t number, size_t width)
+{
+  size_t i;
+  double imgcrd[2], phi, theta;
+  int stat, status=0, ncoord=1, nelem=2;
+
+  for(i=0;i<number;++i)
+    {
+      if(isnan(radec[i*width]) || isnan(radec[i*width+1]))
+        radec[i*width]=radec[i*width+1]=NAN;
+      else
+        {
+          status=wcss2p(wcs, ncoord, nelem, radec+i*width, &phi, &theta,
+                        imgcrd, xy+i*width, &stat);
+          if(status)
+            error(EXIT_FAILURE, 0, "wcss2p ERROR %d: %s", status,
+                  wcs_errmsg[status]);
+          /* For a check:
+             printf("(%f, %f) --> (%f, %f)\n", xy[i*width], xy[i*width+1],
+                    radec[i*width], radec[i*width+1]);
+          */
+        }
+    }
+}
+
+
+
+
+/* The distance (along a great circle) on a sphere between two points
+   is calculated here. Since the pixel sides are usually very small,
+   we won't be using the direct formula:
+
+   cos(distance)=sin(d1)*sin(d2)+cos(d1)*cos(d2)*cos(r1-r2)
+
+   We will be using the haversine formula which better considering
+   floating point errors (from Wikipedia:)
+
+   sin^2(distance)/2=sin^2( (d1-d2)/2 )+cos(d1)*cos(d2)*sin^2( (r1-r2)/2 )
+*/
+double
+angulardistance(double r1, double d1, double r2, double d2)
+{
+  double a=sin( (d1-d2)/2 );
+  double b=sin( (r1-r2)/2 );
+
+  return 2*asin( sqrt( a*a + cos(d1)*cos(d2)*b*b) );
+}
+
+
+
+
+
+/* Report the arcsec^2 area of the pixels in the image based on the
+   WCS information in that image. We first use the angular distance of
+   two edges of one pixel in radians. Then the radians are multiplied
+   to give stradians and finally, the stradians are converted to
+   arcsec^2. */
+double
+gal_wcs_pixel_area_arcsec2(struct wcsprm *wcs)
+{
+  double xy[]={0,0,1,0,0,1};
+  double st, *d, *df, radec[6];
+
+  /* Get the RA and Dec of the bottom left, bottom right and top left
+     sides of the first pixel in the image. */
+  gal_wcs_xy_array_to_radec(wcs, xy, radec, 3, 2);
+
+  /* Covert the RA and dec values to radians for easy calculation: */
+  df=(d=radec)+6; do *d++ *= M_PI/180.0f; while(d<df);
+
+  /* For a check:
+  printf("\n\nAlong first axis: %g\nAlong second axis: %g\n\n",
+         ( angulardistance(radec[0], radec[1], radec[2], radec[3])
+           *180/M_PI*3600 ),
+         ( angulardistance(radec[0], radec[1], radec[4], radec[5])
+           *180/M_PI*3600 ) );
+  */
+
+  /* Get the area in stradians. */
+  st= ( angulardistance(radec[0], radec[1], radec[2], radec[3]) *
+        angulardistance(radec[0], radec[1], radec[4], radec[5]) );
+
+  /* Convert the stradians to arcsec^2:
+
+     1deg^2 = (180/PI)^2 * 1stradian.
+     1arcsec^2 = (3600*3600) * 1degree^2
+   */
+  return st*180.0f*180.0f*3600.0f*3600.0f/(M_PI*M_PI);
+}
diff --git a/src/arithmetic/Makefile.am b/src/arithmetic/Makefile.am
index 3fa5b26..f0531ad 100644
--- a/src/arithmetic/Makefile.am
+++ b/src/arithmetic/Makefile.am
@@ -29,8 +29,8 @@ astarithmetic_SOURCES = main.c main.h cite.h ui.c ui.h args.h 
\
 arithmetic.c arithmetic.h
 
 astarithmetic_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la       \
--lgalconfigfiles -lgalfitsarrayvv -lgalcheckset -lgaltiming            \
--lgallinkedlist -lgalmode -lgalstatistics -lgalarraymanip -lgalqsort
+-lgalconfigfiles -lgalfits -lgalcheckset -lgaltiming -lgallinkedlist   \
+-lgalmode -lgalstatistics -lgalarraymanip -lgalqsort
 
 
 
diff --git a/src/arithmetic/arithmetic.c b/src/arithmetic/arithmetic.c
index 7269408..7cc3204 100644
--- a/src/arithmetic/arithmetic.c
+++ b/src/arithmetic/arithmetic.c
@@ -29,10 +29,10 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <string.h>
 #include <stdlib.h>
 
+#include <gnuastro/fits.h>
 #include <gnuastro/checkset.h>
 #include <gnuastro/arraymanip.h>
 #include <gnuastro/statistics.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 #include "arithmetic.h"            /* needs main.h.                  */
@@ -74,7 +74,7 @@ add_operand(struct imgarithparams *p, char *filename, double 
number,
   newnode->number=number;
   newnode->filename=filename;
 
-  if(strlen(filename) && gal_fitsarray_name_is_fits(filename))
+  if(strlen(filename) && gal_fits_name_is_fits(filename))
     {
       /* Set the HDU for this filename. */
       gal_linkedlist_pop_from_stll(&p->hdus, &newnode->hdu);
@@ -143,10 +143,9 @@ pop_operand(struct imgarithparams *p, double *number, 
double **array,
         {
           mhdu=up->mhdu;
           maskname=up->maskname;
-          gal_fitsarray_read_fits_wcs(filename, hdu, 0, 0, &p->nwcs,
-                                      &p->wcs);
+          gal_fits_read_wcs(filename, hdu, 0, 0, &p->nwcs, &p->wcs);
         }
-      gal_fitsarray_file_to_double(filename, maskname, hdu, mhdu,
+      gal_fits_file_to_double(filename, maskname, hdu, mhdu,
                                    array, &bitpix, &p->anyblank, &s0, &s1);
 
       /* If the output size was not set yet, then set it. Otherwise,
@@ -802,7 +801,7 @@ reversepolish(struct imgarithparams *p)
       /* If we have a name or number, then add it to the operands
          linked list. Otherwise, pull out two members and do the
          specified operation on them. */
-      if(gal_fitsarray_name_is_fits(token->v))
+      if(gal_fits_name_is_fits(token->v))
         add_operand(p, token->v, NOOPTNUMBER, NOOPTARRAY);
       else if(strisdouble(token->v, &number))
         add_operand(p, NOOPTFILENAME, number, NOOPTARRAY);
@@ -845,19 +844,19 @@ reversepolish(struct imgarithparams *p)
          last operand must be an array. */
       if(p->obitpix==FLOAT_IMG)
         {
-          gal_fitsarray_change_type(p->operands->array, DOUBLE_IMG,
+          gal_fits_change_type(p->operands->array, DOUBLE_IMG,
                                     p->s0*p->s1, p->anyblank,
                                     (void **)(&farray), FLOAT_IMG);
-          gal_fitsarray_array_to_fits_img(p->cp.output, "astimgarith",
-                                          FLOAT_IMG, farray, p->s0, p->s1,
-                                          p->anyblank, p->wcs, NULL,
-                                          SPACK_STRING);
+          gal_fits_array_to_file(p->cp.output, "astimgarith",
+                                 FLOAT_IMG, farray, p->s0, p->s1,
+                                 p->anyblank, p->wcs, NULL,
+                                 SPACK_STRING);
         }
       else
-        gal_fitsarray_array_to_fits_img(p->cp.output, "astimgarith",
-                                        DOUBLE_IMG, p->operands->array,
-                                        p->s0, p->s1, p->anyblank,
-                                        p->wcs, NULL, SPACK_STRING);
+        gal_fits_array_to_file(p->cp.output, "astimgarith",
+                               DOUBLE_IMG, p->operands->array,
+                               p->s0, p->s1, p->anyblank,
+                               p->wcs, NULL, SPACK_STRING);
     }
   else
     printf("%g\n", p->operands->number);
diff --git a/src/arithmetic/main.h b/src/arithmetic/main.h
index 074ff25..3b330d4 100644
--- a/src/arithmetic/main.h
+++ b/src/arithmetic/main.h
@@ -23,8 +23,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #ifndef MAIN_H
 #define MAIN_H
 
+#include <gnuastro/fits.h>
 #include <gnuastro/linkedlist.h>
-#include <gnuastro/fitsarrayvv.h>
 #include <gnuastro/commonparams.h>
 
 /* Progarm name macros: */
diff --git a/src/arithmetic/ui.c b/src/arithmetic/ui.c
index 023d92f..1a8f14d 100644
--- a/src/arithmetic/ui.c
+++ b/src/arithmetic/ui.c
@@ -32,11 +32,11 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 #include <nproc.h>              /* From Gnulib.                     */
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>    /* Includes time.h and sys/time.h   */
 #include <gnuastro/checkset.h>
 #include <gnuastro/commonargs.h>
 #include <gnuastro/configfiles.h>
-#include <gnuastro/fitsarrayvv.h>
 #include <gnuastro/fixedstringmacros.h>
 
 #include "main.h"
@@ -266,7 +266,7 @@ negchartodashcountfits(struct imgarithparams *p)
   /* Go through all the tokens and do the job(s). */
   for(token=p->tokens; token!=NULL; token=token->next)
     {
-      if(gal_fitsarray_name_is_fits(token->v))
+      if(gal_fits_name_is_fits(token->v))
         ++p->numfits;
       else if(token->v[0]==NEGDASHREPLACE && isdigit(token->v[1]) )
         token->v[0]='-';
@@ -289,10 +289,10 @@ sanitycheck(struct imgarithparams *p)
      file name operations are only necessary for the first FITS file
      in the token list. */
   for(token=p->tokens; token!=NULL; token=token->next)
-    if(gal_fitsarray_name_is_fits(token->v))
+    if(gal_fits_name_is_fits(token->v))
     {
       /* Set the p->up.maskname accordingly: */
-      gal_fitsarray_file_or_ext_name(token->v, p->cp.hdu,
+      gal_fits_file_or_ext_name(token->v, p->cp.hdu,
                                      p->up.masknameset, &p->up.maskname,
                                      p->up.mhdu, p->up.mhduset, "mask");
 
diff --git a/src/convertt/Makefile.am b/src/convertt/Makefile.am
index 0ab864c..331dac5 100644
--- a/src/convertt/Makefile.am
+++ b/src/convertt/Makefile.am
@@ -29,7 +29,7 @@ astconvertt_SOURCES = main.c main.h args.h cite.h ui.c ui.h 
eps.c     \
 eps.h jpeg.c jpeg.h convertt.c convertt.h
 
 astconvertt_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la         \
--lgalconfigfiles -lgalfitsarrayvv -lgaltxtarrayvv -lgalcheckset                
\
+-lgalconfigfiles -lgalfits -lgaltxtarrayvv -lgalcheckset               \
 -lgaltiming -lgallinkedlist -lgalstatistics -lgalarraymanip -lgalqsort
 
 
diff --git a/src/convertt/convertt.c b/src/convertt/convertt.c
index 266a607..dadc9f0 100644
--- a/src/convertt/convertt.c
+++ b/src/convertt/convertt.c
@@ -29,10 +29,10 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <string.h>
 #include <stdlib.h>
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>
 #include <gnuastro/statistics.h>
 #include <gnuastro/txtarrayvv.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -217,16 +217,16 @@ savefits(struct converttparams *p)
     {
       /* Make sure array is in the correct format. */
       if(p->bitpixs[i]!=DOUBLE_IMG)
-        gal_fitsarray_change_type(p->ch[i], DOUBLE_IMG, size, p->numnul[i],
+        gal_fits_change_type(p->ch[i], DOUBLE_IMG, size, p->numnul[i],
                                   &array, p->bitpixs[i]);
       else
         array=p->ch[i];
 
       /* Write array to a FITS file.*/
       sprintf(hdu, "Channel%lu", i+1);
-      gal_fitsarray_array_to_fits_img(p->cp.output, hdu, p->bitpixs[i], array,
-                                      p->s0[i], p->s1[i], 0, NULL, NULL,
-                                      SPACK_STRING);
+      gal_fits_array_to_file(p->cp.output, hdu, p->bitpixs[i], array,
+                             p->s0[i], p->s1[i], 0, NULL, NULL,
+                             SPACK_STRING);
 
       /* If array was allocated separately, free it. */
       if(p->bitpixs[i]!=DOUBLE_IMG)
diff --git a/src/convertt/jpeg.c b/src/convertt/jpeg.c
index f985497..3701f31 100644
--- a/src/convertt/jpeg.c
+++ b/src/convertt/jpeg.c
@@ -32,7 +32,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
   #include <jpeglib.h>
 #endif
 
-#include <gnuastro/fitsarrayvv.h>
+#include <gnuastro/fits.h>
 
 #include "main.h"
 #include "jpeg.h"
diff --git a/src/convertt/ui.c b/src/convertt/ui.c
index b9001e6..51dae98 100644
--- a/src/convertt/ui.c
+++ b/src/convertt/ui.c
@@ -32,11 +32,11 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 #include <nproc.h>              /* From Gnulib.                     */
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>    /* Includes time.h and sys/time.h   */
 #include <gnuastro/txtarrayvv.h>
 #include <gnuastro/linkedlist.h>
 #include <gnuastro/configfiles.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -460,10 +460,10 @@ sanitycheck(struct converttparams *p)
   /* The output file name. First find the first non-blank file name: */
   if(cp->outputset)
     {
-      if(gal_fitsarray_name_is_fits(cp->output))
+      if(gal_fits_name_is_fits(cp->output))
         {
           p->outputtype=FITSFORMAT;
-          if( gal_fitsarray_name_is_fits_suffix(cp->output) )
+          if( gal_fits_name_is_fits_suffix(cp->output) )
             adddotautomaticoutput(p);
         }
       else if(nameisjpeg(cp->output))
@@ -576,7 +576,7 @@ preparearrays(struct converttparams *p)
       if(strcmp(names[i], "blank")) gal_checkset_check_file(names[i]);
 
       /* FITS: */
-      if( gal_fitsarray_name_is_fits(names[i]) )
+      if( gal_fits_name_is_fits(names[i]) )
         {
           switch(p->numch) /* Get the HDU value for this channel. */
             {
@@ -588,11 +588,9 @@ preparearrays(struct converttparams *p)
                            "problem and fix it");
             }
           p->numnul[p->numch]=
-            gal_fitsarray_fits_img_to_array(names[i], hdu,
-                                            &p->bitpixs[p->numch], &array,
-                                            &p->s0[p->numch],
-                                            &p->s1[p->numch]);
-          gal_fitsarray_change_type(array, p->bitpixs[p->numch],
+            gal_fits_hdu_to_array(names[i], hdu, &p->bitpixs[p->numch],
+                                  &array, &p->s0[p->numch], &p->s1[p->numch]);
+          gal_fits_change_type(array, p->bitpixs[p->numch],
                                     p->s0[p->numch]*p->s1[p->numch],
                                     p->numnul[p->numch],
                                     (void **)(&p->ch[p->numch]), DOUBLE_IMG);
diff --git a/src/convolve/Makefile.am b/src/convolve/Makefile.am
index 30acaaf..5b70f21 100644
--- a/src/convolve/Makefile.am
+++ b/src/convolve/Makefile.am
@@ -29,7 +29,7 @@ astconvolve_SOURCES = main.c main.h args.h ui.c ui.h 
convolve.c       \
 convolve.h cite.h
 
 astconvolve_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la            \
--lgalcheckset -lgalfitsarrayvv -lgaltiming -lgalconfigfiles -lgalmesh     \
+-lgalcheckset -lgalfits -lgaltiming -lgalconfigfiles -lgalmesh            \
 -lgalthreads -lgalspatialconvolve -lgalbox -lgalarraymanip -lgalstatistics \
 -lgalqsort -lgallinkedlist
 
diff --git a/src/convolve/convolve.c b/src/convolve/convolve.c
index 6062897..b47fc11 100644
--- a/src/convolve/convolve.c
+++ b/src/convolve/convolve.c
@@ -29,9 +29,9 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <stdlib.h>
 #include <gsl/gsl_errno.h>
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>
 #include <gnuastro/threads.h>
-#include <gnuastro/fitsarrayvv.h>
 #include <gnuastro/spatialconvolve.h>
 
 #include "main.h"
@@ -637,14 +637,14 @@ frequencyconvolve(struct convolveparams *p)
   if(p->viewfreqsteps)
     {
       complextoreal(p->pimg, p->ps0*p->ps1, COMPLEXTOREALREAL, &tmp);
-      gal_fitsarray_array_to_fits_img(p->up.freqstepsname, "Input padded",
-                                      DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
-                                      NULL, NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->up.freqstepsname, "Input padded",
+                             DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
+                             NULL, NULL, SPACK_STRING);
       free(tmp);
       complextoreal(p->pker, p->ps0*p->ps1, COMPLEXTOREALREAL, &tmp);
-      gal_fitsarray_array_to_fits_img(p->up.freqstepsname, "Kernel padded",
-                                      DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
-                                      NULL, NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->up.freqstepsname, "Kernel padded",
+                             DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
+                             NULL, NULL, SPACK_STRING);
       free(tmp);
     }
 
@@ -660,14 +660,14 @@ frequencyconvolve(struct convolveparams *p)
   if(p->viewfreqsteps)
     {
       complextoreal(p->pimg, p->ps0*p->ps1, COMPLEXTOREALSPEC, &tmp);
-      gal_fitsarray_array_to_fits_img(p->up.freqstepsname, "Input transform",
-                                      DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
-                                      NULL, NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->up.freqstepsname, "Input transform",
+                             DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
+                             NULL, NULL, SPACK_STRING);
       free(tmp);
       complextoreal(p->pker, p->ps0*p->ps1, COMPLEXTOREALSPEC, &tmp);
-      gal_fitsarray_array_to_fits_img(p->up.freqstepsname, "Kernel transform",
-                                      DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
-                                      NULL, NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->up.freqstepsname, "Kernel transform",
+                             DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
+                             NULL, NULL, SPACK_STRING);
       free(tmp);
     }
 
@@ -686,9 +686,9 @@ frequencyconvolve(struct convolveparams *p)
   if(p->viewfreqsteps)
     {
       complextoreal(p->pimg, p->ps0*p->ps1, COMPLEXTOREALSPEC, &tmp);
-      gal_fitsarray_array_to_fits_img(p->up.freqstepsname, operation,
-                                      DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
-                                      NULL, NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->up.freqstepsname, operation,
+                             DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
+                             NULL, NULL, SPACK_STRING);
       free(tmp);
     }
 
@@ -700,9 +700,9 @@ frequencyconvolve(struct convolveparams *p)
   if(verb) gal_timing_report(&t1, "Converted back to the spatial domain.", 1);
   if(p->viewfreqsteps)
     {
-      gal_fitsarray_array_to_fits_img(p->up.freqstepsname, "Spatial",
-                                      DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
-                                      NULL, NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->up.freqstepsname, "Spatial",
+                             DOUBLE_IMG, tmp, p->ps0, p->ps1, 0,
+                             NULL, NULL, SPACK_STRING);
       free(tmp);
     }
 
@@ -762,13 +762,13 @@ convolve(struct convolveparams *p)
       if(p->meshname)
         {
           gal_check_mesh_id(mp, &meshindexs);
-          gal_fitsarray_array_to_fits_img(p->meshname, "Input", FLOAT_IMG,
-                                          p->mp.img, mp->s0, mp->s1,
-                                          p->anyblank, p->wcs, NULL,
+          gal_fits_array_to_file(p->meshname, "Input", FLOAT_IMG,
+                                 p->mp.img, mp->s0, mp->s1,
+                                 p->anyblank, p->wcs, NULL,
                                           SPACK_STRING);
-          gal_fitsarray_array_to_fits_img(p->meshname, "MeshIndexs", LONG_IMG,
-                                          meshindexs, mp->s0, mp->s1, 0, 
p->wcs,
-                                          NULL, SPACK_STRING);
+          gal_fits_array_to_file(p->meshname, "MeshIndexs", LONG_IMG,
+                                 meshindexs, mp->s0, mp->s1, 0, p->wcs,
+                                 NULL, SPACK_STRING);
           free(meshindexs);
         }
 
@@ -784,7 +784,7 @@ convolve(struct convolveparams *p)
 
   /* Save the output (which is in p->input) array. Note that p->input
      will be freed in ui.c. */
-  gal_fitsarray_array_to_fits_img(p->cp.output, "Convolved", FLOAT_IMG,
-                                  p->input, p->is0, p->is1, p->anyblank, 
p->wcs,
-                                  NULL, SPACK_STRING);
+  gal_fits_array_to_file(p->cp.output, "Convolved", FLOAT_IMG,
+                         p->input, p->is0, p->is1, p->anyblank, p->wcs,
+                         NULL, SPACK_STRING);
 }
diff --git a/src/convolve/ui.c b/src/convolve/ui.c
index b2343dc..0ac5c77 100644
--- a/src/convolve/ui.c
+++ b/src/convolve/ui.c
@@ -31,12 +31,12 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 #include <nproc.h>              /* From Gnulib.                   */
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>   /* Includes time.h and sys/time.h */
 #include <gnuastro/checkset.h>
 #include <gnuastro/statistics.h>
 #include <gnuastro/arraymanip.h>
 #include <gnuastro/configfiles.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -350,7 +350,7 @@ sanitycheck(struct convolveparams *p)
   gal_checkset_check_file(p->up.inputname);
 
   /* Set maskname accordingly: */
-  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
+  gal_fits_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
                                  &p->up.maskname, p->up.mhdu,
                                  p->up.mhduset, "mask");
 
@@ -425,10 +425,10 @@ preparearrays(struct convolveparams *p)
   float *f, *fp, tmp, *kernel, sum;
 
   /* First read the input image: */
-  gal_fitsarray_file_to_float(up->inputname, up->maskname, cp->hdu, up->mhdu,
+  gal_fits_file_to_float(up->inputname, up->maskname, cp->hdu, up->mhdu,
                               &p->input, &bitpix, &p->anyblank,
                               &p->is0, &p->is1);
-  gal_fitsarray_read_fits_wcs(up->inputname, cp->hdu, 0, 0, &p->nwcs, &p->wcs);
+  gal_fits_read_wcs(up->inputname, cp->hdu, 0, 0, &p->nwcs, &p->wcs);
   if(p->frequency && p->anyblank)
     fprintf(stderr, "\n----------------------------------------\n"
             "######## %s WARNING ########\n"
@@ -449,7 +449,7 @@ preparearrays(struct convolveparams *p)
   if(p->makekernel)
     {
       /* Read in the kernel array: */
-      gal_fitsarray_file_to_float(up->kernelname, NULL, up->khdu, NULL,
+      gal_fits_file_to_float(up->kernelname, NULL, up->khdu, NULL,
                                   &p->kernel, &bitpix, &anyblank,
                                   &p->ks0, &p->ks1);
       if(p->ks0!=p->is0 || p->ks1!=p->is1)
@@ -470,17 +470,17 @@ preparearrays(struct convolveparams *p)
       gal_arraymanip_fmultip_const(p->kernel, size, 1/sum);
     }
 
-  /* Read the kernel. If there is anything particular to Convolve,
-     then don't use the standard kernel reading function in
-     fitsarrayvv.c. Otherwise just use the same one that all programs
-     use. The standard one is faster because it mixes the NaN
-     conversion and also the normalization into one loop.*/
+  /* Read the kernel. If there is anything particular to Convolve, then
+     don't use the standard kernel reading function in fits.c. Otherwise
+     just use the same one that all programs use. The standard one is
+     faster because it mixes the NaN conversion and also the normalization
+     into one loop.*/
   else
     {
       if(p->kernelnorm==0 || p->kernelflip==0)
         {
           /* Read in the kernel array: */
-          gal_fitsarray_file_to_float(up->kernelname, NULL, up->khdu, NULL,
+          gal_fits_file_to_float(up->kernelname, NULL, up->khdu, NULL,
                                       &p->kernel, &bitpix, &anyblank,
                                       &p->ks0, &p->ks1);
           size=p->ks0*p->ks1;
@@ -514,7 +514,7 @@ preparearrays(struct convolveparams *p)
               }
         }
       else
-        gal_fitsarray_prep_float_kernel(up->kernelname, up->khdu, &p->kernel,
+        gal_fits_prep_float_kernel(up->kernelname, up->khdu, &p->kernel,
                                         &p->ks0, &p->ks1);
     }
 }
diff --git a/src/cosmiccal/Makefile.am b/src/cosmiccal/Makefile.am
index 2ca7826..2bcb9eb 100644
--- a/src/cosmiccal/Makefile.am
+++ b/src/cosmiccal/Makefile.am
@@ -28,9 +28,8 @@ bin_PROGRAMS = astcosmiccal
 astcosmiccal_SOURCES = main.c main.h cite.h ui.c ui.h args.h   \
 cosmiccal.c cosmiccal.h
 
-astcosmiccal_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la        \
--lgalconfigfiles -lgalfitsarrayvv -lgalcheckset -lgaltiming    \
--lgallinkedlist
+astcosmiccal_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la                
\
+-lgalconfigfiles -lgalfits -lgalcheckset -lgaltiming -lgallinkedlist
 
 
 
diff --git a/src/cosmiccal/ui.c b/src/cosmiccal/ui.c
index b516cba..030883a 100644
--- a/src/cosmiccal/ui.c
+++ b/src/cosmiccal/ui.c
@@ -33,12 +33,12 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <nproc.h>              /* From Gnulib.                     */
 #include <gsl/gsl_const_mksa.h>
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>    /* Includes time.h and sys/time.h   */
 #include <gnuastro/checkset.h>
 #include <gnuastro/txtarrayvv.h>
 #include <gnuastro/commonargs.h>
 #include <gnuastro/configfiles.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
diff --git a/src/header/Makefile.am b/src/header/Makefile.am
index d1bfa4d..35a5c96 100644
--- a/src/header/Makefile.am
+++ b/src/header/Makefile.am
@@ -28,9 +28,8 @@ bin_PROGRAMS = astheader
 astheader_SOURCES = main.c main.h cite.h ui.c ui.h args.h      \
 header.c header.h
 
-astheader_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la   \
--lgalconfigfiles -lgalfitsarrayvv -lgalcheckset -lgaltiming    \
--lgallinkedlist
+astheader_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la           \
+-lgalconfigfiles -lgalfits -lgalcheckset -lgaltiming -lgallinkedlist
 
 
 
diff --git a/src/header/args.h b/src/header/args.h
index 020831a..8402d46 100644
--- a/src/header/args.h
+++ b/src/header/args.h
@@ -251,7 +251,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( gal_fitsarray_name_is_fits(arg) )
+      if( gal_fits_name_is_fits(arg) )
         {
           if(p->up.inputname)
             argp_error(state, "only one input image should be given");
diff --git a/src/header/header.c b/src/header/header.c
index 4f2b889..8cce5ea 100644
--- a/src/header/header.c
+++ b/src/header/header.c
@@ -28,8 +28,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <string.h>
 #include <stdlib.h>
 
+#include <gnuastro/fits.h>
 #include <gnuastro/linkedlist.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -79,11 +79,11 @@ haserror(struct headerparams *p, int actionid, char 
*string, int status)
 
 
 void
-writeupdatekeys(fitsfile *fptr, struct gal_fitsarray_header_ll **keylist,
+writeupdatekeys(fitsfile *fptr, struct gal_fits_header_ll **keylist,
                 int u1w2)
 {
   int status=0;
-  struct gal_fitsarray_header_ll *tmp, *ttmp;
+  struct gal_fits_header_ll *tmp, *ttmp;
 
   tmp=*keylist;
   while(tmp!=NULL)
@@ -96,13 +96,13 @@ writeupdatekeys(fitsfile *fptr, struct 
gal_fitsarray_header_ll **keylist,
             {
               if( fits_update_key(fptr, tmp->datatype, tmp->keyname,
                                   tmp->value, tmp->comment, &status) )
-                gal_fitsarray_io_error(status, NULL);
+                gal_fits_io_error(status, NULL);
             }
           else
             {
               if(fits_write_key_null(fptr, tmp->keyname, tmp->comment,
                                      &status))
-                gal_fitsarray_io_error(status, NULL);
+                gal_fits_io_error(status, NULL);
             }
         }
       else if (u1w2==2)
@@ -111,17 +111,17 @@ writeupdatekeys(fitsfile *fptr, struct 
gal_fitsarray_header_ll **keylist,
             {
               if( fits_write_key(fptr, tmp->datatype, tmp->keyname,
                                  tmp->value, tmp->comment, &status) )
-                gal_fitsarray_io_error(status, NULL);
+                gal_fits_io_error(status, NULL);
             }
           else
             {
               if(fits_write_key_null(fptr, tmp->keyname, tmp->comment,
                                      &status))
-                gal_fitsarray_io_error(status, NULL);
+                gal_fits_io_error(status, NULL);
             }
           if(tmp->unit
              && fits_write_key_unit(fptr, tmp->keyname, tmp->unit, &status) )
-            gal_fitsarray_io_error(status, NULL);
+            gal_fits_io_error(status, NULL);
         }
       else
         error(EXIT_FAILURE, 0, "a bug! Please contact us at `%s' so we can "
@@ -131,7 +131,7 @@ writeupdatekeys(fitsfile *fptr, struct 
gal_fitsarray_header_ll **keylist,
       /* Add the unit: */
       if(tmp->unit
          && fits_write_key_unit(fptr, tmp->keyname, tmp->unit, &status) )
-        gal_fitsarray_io_error(status, NULL);
+        gal_fits_io_error(status, NULL);
 
       /* Free the value pointer if desired: */
       if(tmp->kfree) free(tmp->keyname);
@@ -163,7 +163,7 @@ header(struct headerparams *p)
   if(p->onlyview)
     {
       if( fits_hdr2str(p->fptr, 0, NULL, 0, &fullheader, &nkeys, &status) )
-        gal_fitsarray_io_error(status, NULL);
+        gal_fits_io_error(status, NULL);
 
       /* FLEN_CARD supposes that the NULL string character is in the
          end of each keyword header card. In fits_hdr2str, the NULL
@@ -181,7 +181,7 @@ header(struct headerparams *p)
       printf("\n");
 
       if (fits_free_memory(fullheader, &status) )
-        gal_fitsarray_io_error(status, "problem in header.c for freeing "
+        gal_fits_io_error(status, "problem in header.c for freeing "
                                "the memory used to keep all the headers");
     }
   else
diff --git a/src/header/main.h b/src/header/main.h
index 284e090..ada8cd8 100644
--- a/src/header/main.h
+++ b/src/header/main.h
@@ -23,7 +23,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #ifndef MAIN_H
 #define MAIN_H
 
-#include <gnuastro/fitsarrayvv.h>
+#include <gnuastro/fits.h>
 #include <gnuastro/commonparams.h>
 
 /* Progarm name macros: */
@@ -67,8 +67,8 @@ struct headerparams
   struct gal_linkedlist_stll *delete; /* Keywords to remove.          */
   struct gal_linkedlist_stll *renamefrom; /* The initial value of the keyword. 
*/
   struct gal_linkedlist_stll *renameto; /* The final value of the keyword. */
-  struct gal_fitsarray_header_ll *update; /* Linked list of keywords to 
update. */
-  struct gal_fitsarray_header_ll *write; /* Linked list of keywords to add. */
+  struct gal_fits_header_ll  *update; /* Linked list of keywords to update. */
+  struct gal_fits_header_ll  *write; /* Linked list of keywords to add. */
 
   /* Operating mode: */
   int             quitonerror;  /* Quit if an error occurs.           */
diff --git a/src/header/ui.c b/src/header/ui.c
index 3f8e265..70aa2cc 100644
--- a/src/header/ui.c
+++ b/src/header/ui.c
@@ -32,12 +32,12 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 #include <nproc.h>              /* From Gnulib.                     */
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>    /* Includes time.h and sys/time.h   */
 #include <gnuastro/checkset.h>
 #include <gnuastro/txtarrayvv.h>
 #include <gnuastro/commonargs.h>
 #include <gnuastro/configfiles.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -276,7 +276,7 @@ setuprename(struct headerparams *p)
 
 void
 fillfitsheaderll(struct gal_linkedlist_stll *input,
-                 struct gal_fitsarray_header_ll **output)
+                 struct gal_fits_header_ll **output)
 {
   long l, *lp;
   void *fvalue;
@@ -384,7 +384,7 @@ fillfitsheaderll(struct gal_linkedlist_stll *input,
         }
 
 
-      gal_fitsarray_add_to_fits_header_ll(output, datatype, keyname, 0,
+      gal_fits_add_to_fits_header_ll(output, datatype, keyname, 0,
                                           fvalue, vfree, comment, 0, unit);
       free(original);
     }
@@ -415,7 +415,7 @@ preparearrays(struct headerparams *p)
   else
     iomode=READWRITE;
   if( fits_open_file(&p->fptr, ffname, iomode, &status) )
-    gal_fitsarray_io_error(status, "reading file");
+    gal_fits_io_error(status, "reading file");
   free(ffname);
 
   /* Separate the comma-separated values:  */
@@ -516,7 +516,7 @@ freeandreport(struct headerparams *p)
 
   /* Close the FITS file: */
   if(fits_close_file(p->fptr, &status))
-    gal_fitsarray_io_error(status, NULL);
+    gal_fits_io_error(status, NULL);
 
   if(p->wcs)
     wcsvfree(&p->nwcs, &p->wcs);
diff --git a/src/imgcrop/Makefile.am b/src/imgcrop/Makefile.am
index 4d792c4..efb3a5e 100644
--- a/src/imgcrop/Makefile.am
+++ b/src/imgcrop/Makefile.am
@@ -28,8 +28,8 @@ bin_PROGRAMS = astimgcrop
 astimgcrop_SOURCES = main.c main.h cite.h ui.c ui.h args.h imgcrop.c   \
 imgcrop.h wcsmode.c wcsmode.h crop.c crop.h
 
-astimgcrop_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la          \
--lgalconfigfiles -lgalfitsarrayvv -lgaltxtarrayvv -lgalcheckset         \
+astimgcrop_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la          \
+-lgalconfigfiles -lgalwcs -lgalfits -lgaltxtarrayvv -lgalcheckset      \
 -lgallinkedlist -lgaltiming -lgalthreads -lgalbox -lgalpolygon
 
 
diff --git a/src/imgcrop/args.h b/src/imgcrop/args.h
index f721f52..b468569 100644
--- a/src/imgcrop/args.h
+++ b/src/imgcrop/args.h
@@ -458,7 +458,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( gal_fitsarray_name_is_fits(arg) )
+      if( gal_fits_name_is_fits(arg) )
        {
          gal_linkedlist_add_to_stll(&p->up.gal_linkedlist_stll, arg);
          ++p->numimg;
diff --git a/src/imgcrop/crop.c b/src/imgcrop/crop.c
index fa84a2b..31b0a7f 100644
--- a/src/imgcrop/crop.c
+++ b/src/imgcrop/crop.c
@@ -32,10 +32,10 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <stdlib.h>
 
 #include <gnuastro/box.h>
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>
 #include <gnuastro/polygon.h>
 #include <gnuastro/checkset.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -326,7 +326,7 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
   switch(bitpix)
     {
     case BYTE_IMG:
-      bb=gal_fitsarray_bitpix_blank(bitpix);
+      bb=gal_fits_bitpix_blank(bitpix);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
@@ -335,7 +335,7 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
       free(bb);
       break;
     case SHORT_IMG:
-      sb=gal_fitsarray_bitpix_blank(bitpix);
+      sb=gal_fits_bitpix_blank(bitpix);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
@@ -344,7 +344,7 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
       free(sb);
       break;
     case LONG_IMG:
-      lb=gal_fitsarray_bitpix_blank(bitpix);
+      lb=gal_fits_bitpix_blank(bitpix);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
@@ -353,7 +353,7 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
       free(lb);
       break;
     case LONGLONG_IMG:
-      Lb=gal_fitsarray_bitpix_blank(bitpix);
+      Lb=gal_fits_bitpix_blank(bitpix);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
@@ -362,7 +362,7 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
       free(Lb);
       break;
     case FLOAT_IMG:
-      fb=gal_fitsarray_bitpix_blank(bitpix);
+      fb=gal_fits_bitpix_blank(bitpix);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
@@ -371,7 +371,7 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
       free(fb);
       break;
     case DOUBLE_IMG:
-      db=gal_fitsarray_bitpix_blank(bitpix);
+      db=gal_fits_bitpix_blank(bitpix);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
@@ -611,17 +611,17 @@ firstcropmakearray(struct cropparams *crp, long *fpixel_i,
   /* Create the FITS image extension and array and fill it with null
      values. */
   if(fits_create_file(&crp->outfits, outname, &status))
-    gal_fitsarray_io_error(status, "creating file");
+    gal_fits_io_error(status, "creating file");
   ofp=crp->outfits;
   if(fits_create_img(ofp, bitpix, naxis, naxes, &status))
-    gal_fitsarray_io_error(status, "creating image");
+    gal_fits_io_error(status, "creating image");
   if(bitpix==BYTE_IMG || bitpix==SHORT_IMG
      || bitpix==LONG_IMG || bitpix==LONGLONG_IMG)
     if(fits_write_key(ofp, crp->p->datatype, "BLANK",
                      crp->p->bitnul, "pixels with no data", &status) )
-      gal_fitsarray_io_error(status, "adding Blank");
+      gal_fits_io_error(status, "adding Blank");
   if(fits_write_null_img(ofp, 1, naxes[0]*naxes[1], &status))
-    gal_fitsarray_io_error(status, "writing null array");
+    gal_fits_io_error(status, "writing null array");
 
 
   /* Write the WCS header keywords in the output FITS image, then
@@ -631,7 +631,7 @@ firstcropmakearray(struct cropparams *crp, long *fpixel_i,
       crpix0 = img->wcs->crpix[0] - (fpixel_i[0]-1) + (fpixel_c[0]-1);
       crpix1 = img->wcs->crpix[1] - (fpixel_i[1]-1) + (fpixel_c[1]-1);
       if(fits_write_record(ofp, blankrec, &status))
-        gal_fitsarray_io_error(status, NULL);
+        gal_fits_io_error(status, NULL);
       sprintf(titlerec, "%sWCS information", startblank);
       for(i=strlen(titlerec);i<79;++i)
         titlerec[i]=' ';
@@ -640,18 +640,18 @@ firstcropmakearray(struct cropparams *crp, long *fpixel_i,
         fits_write_record(ofp, &img->wcstxt[i*80], &status);
       fits_update_key(ofp, TDOUBLE, "CRPIX1", &crpix0, NULL, &status);
       fits_update_key(ofp, TDOUBLE, "CRPIX2", &crpix1, NULL, &status);
-      gal_fitsarray_io_error(status, NULL);
+      gal_fits_io_error(status, NULL);
     }
 
 
   /* Add the Crop information. */
   if(fits_write_record(ofp, blankrec, &status))
-    gal_fitsarray_io_error(status, NULL);
+    gal_fits_io_error(status, NULL);
   sprintf(titlerec, "%sCrop information", startblank);
   for(i=strlen(titlerec);i<79;++i)
     titlerec[i]=' ';
   if(fits_write_record(ofp, titlerec, &status))
-    gal_fitsarray_io_error(status, NULL);
+    gal_fits_io_error(status, NULL);
 }
 
 
@@ -676,7 +676,7 @@ onecrop(struct cropparams *crp)
   char basename[FLEN_KEYWORD];
   long fpixel_i[2] , lpixel_i[2];
   fitsfile *ifp=crp->infits, *ofp;
-  struct gal_fitsarray_header_ll *headers=NULL;
+  struct gal_fits_header_ll *headers=NULL;
   int status=0, anynul=0, bitpix=p->bitpix;
   long fpixel_o[2], lpixel_o[2], inc[2]={1,1};
   char region[FLEN_VALUE], regionkey[FLEN_KEYWORD];
@@ -704,11 +704,11 @@ onecrop(struct cropparams *crp)
       /* Read the desired part of the image, then write it into this
         array. */
       cropsize=(lpixel_i[0]-fpixel_i[0]+1)*(lpixel_i[1]-fpixel_i[1]+1);
-      array=gal_fitsarray_bitpix_alloc(cropsize, bitpix);
+      array=gal_fits_bitpix_alloc(cropsize, bitpix);
       status=0;
       if(fits_read_subset(ifp, p->datatype, fpixel_i, lpixel_i, inc,
                          p->bitnul, array, &anynul, &status))
-       gal_fitsarray_io_error(status, NULL);
+       gal_fits_io_error(status, NULL);
 
 
       /* If we have a floating point or double image, pixels with zero
@@ -736,21 +736,21 @@ onecrop(struct cropparams *crp)
       status=0;
       if( fits_write_subset(ofp, p->datatype, fpixel_o, lpixel_o,
                            array, &status) )
-       gal_fitsarray_io_error(status, NULL);
+       gal_fits_io_error(status, NULL);
 
 
       /* A section has been added to the cropped image from this input
         image, so increment crp->imgcount and save the information of
         this image. */
       sprintf(basename, "ICF%lu", ++p->log[crp->outindex].numimg);
-      gal_fitsarray_file_name_in_keywords(basename, img->name, &headers);
+      gal_fits_file_name_in_keywords(basename, img->name, &headers);
       sprintf(regionkey, "%sPIX", basename);
       sprintf(region, "%ld:%ld,%ld:%ld", fpixel_i[0], lpixel_i[0]+1,
              fpixel_i[1], lpixel_i[1]+1);
-      gal_fitsarray_add_to_fits_header_ll_end(&headers, TSTRING, regionkey, 0,
+      gal_fits_add_to_fits_header_ll_end(&headers, TSTRING, regionkey, 0,
                                               region, 0, "Range of pixels "
                                               "used for this output.", 0, 
NULL);
-      gal_fitsarray_update_keys(ofp, &headers);
+      gal_fits_update_keys(ofp, &headers);
 
 
       /* Free the allocated array. */
@@ -808,7 +808,7 @@ iscenterfilled(struct cropparams *crp)
 
   /* Get the final size of the output image. */
   if( fits_get_img_size(ofp, maxdim, naxes, &status) )
-    gal_fitsarray_io_error(status, NULL);
+    gal_fits_io_error(status, NULL);
 
   /* Get the size and range of the central region to check. The +1 is
      because in FITS, counting begins from 1, not zero. */
@@ -819,10 +819,10 @@ iscenterfilled(struct cropparams *crp)
 
   /* Allocate the array and read in the pixels. */
   size=checkcenter*checkcenter;
-  array=gal_fitsarray_bitpix_alloc(size, bitpix);
+  array=gal_fits_bitpix_alloc(size, bitpix);
   if( fits_read_subset(ofp, p->datatype, fpixel, lpixel, inc,
                       p->bitnul, array, &anynul, &status) )
-    gal_fitsarray_io_error(status, NULL);
+    gal_fits_io_error(status, NULL);
 
   /* Depending on bitpix, check the central pixels of the image. */
   nulcount=0;
diff --git a/src/imgcrop/crop.h b/src/imgcrop/crop.h
index 3035414..29c3fb6 100644
--- a/src/imgcrop/crop.h
+++ b/src/imgcrop/crop.h
@@ -23,9 +23,9 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #ifndef CROP_H
 #define CROP_H
 
-#include <gnuastro/threads.h>
+#include <fitsio.h>
 
-#include "main.h"
+#include <gnuastro/threads.h>
 
 struct cropparams
 {
diff --git a/src/imgcrop/imgcrop.c b/src/imgcrop/imgcrop.c
index 3ffd8c4..cd123ba 100644
--- a/src/imgcrop/imgcrop.c
+++ b/src/imgcrop/imgcrop.c
@@ -29,10 +29,10 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <string.h>
 #include <stdlib.h>
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>
 #include <gnuastro/threads.h>
 #include <gnuastro/checkset.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -61,7 +61,7 @@ imgmodecrop(void *inparam)
   /* The whole catalog is from one image, so you can get the
      information here:*/
   img=&p->imgs[crp->imgindex];
-  gal_fitsarray_read_fits_hdu(img->name, cp->hdu, IMAGE_HDU, &crp->infits);
+  gal_fits_read_hdu(img->name, cp->hdu, IMAGE_HDU, &crp->infits);
 
   /* Go over all the outputs that are assigned to this thread: */
   for(i=0;crp->indexs[i]!=GAL_THREADS_NON_THRD_INDEX;++i)
@@ -83,10 +83,10 @@ imgmodecrop(void *inparam)
          log->centerfilled=iscenterfilled(crp);
 
          /* Add the final headers and close output FITS image: */
-         gal_fitsarray_copyright_end(crp->outfits, NULL, SPACK_STRING);
+         gal_fits_copyright_end(crp->outfits, NULL, SPACK_STRING);
          status=0;
          if( fits_close_file(crp->outfits, &status) )
-           gal_fitsarray_io_error(status, "CFITSIO could not close "
+           gal_fits_io_error(status, "CFITSIO could not close "
                                    "the opened file");
 
          /* Remove the output image if its center was not filled. */
@@ -113,7 +113,7 @@ imgmodecrop(void *inparam)
   /* Close the input image. */
   status=0;
   if( fits_close_file(crp->infits, &status) )
-    gal_fitsarray_io_error(status, "imgmode.c: imgcroponthreads could "
+    gal_fits_io_error(status, "imgmode.c: imgcroponthreads could "
                            "not close FITS file");
 
   /* Wait until all other threads finish. */
@@ -159,7 +159,7 @@ wcsmodecrop(void *inparam)
       do
        if(radecoverlap(crp))
          {
-           gal_fitsarray_read_fits_hdu(p->imgs[crp->imgindex].name, p->cp.hdu,
+           gal_fits_read_hdu(p->imgs[crp->imgindex].name, p->cp.hdu,
                                         IMAGE_HDU, &crp->infits);
 
            if(log->name==NULL) cropname(crp);
@@ -168,7 +168,7 @@ wcsmodecrop(void *inparam)
 
            status=0;
            if( fits_close_file(crp->infits, &status) )
-             gal_fitsarray_io_error(status, "imgmode.c: imgcroponthreads "
+             gal_fits_io_error(status, "imgmode.c: imgcroponthreads "
                                      "could not close FITS file");
          }
       while ( ++(crp->imgindex) < p->numimg );
@@ -179,10 +179,10 @@ wcsmodecrop(void *inparam)
        {
          log->centerfilled=iscenterfilled(crp);
 
-         gal_fitsarray_copyright_end(crp->outfits, NULL, SPACK_STRING);
+         gal_fits_copyright_end(crp->outfits, NULL, SPACK_STRING);
          status=0;
          if( fits_close_file(crp->outfits, &status) )
-           gal_fitsarray_io_error(status, "CFITSIO could not close the "
+           gal_fits_io_error(status, "CFITSIO could not close the "
                                      "opened file");
 
          if(log->centerfilled==0 && p->keepblankcenter==0)
diff --git a/src/imgcrop/main.h b/src/imgcrop/main.h
index 634c0cc..b8c9be7 100644
--- a/src/imgcrop/main.h
+++ b/src/imgcrop/main.h
@@ -24,8 +24,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #define MAIN_H
 
 
+#include <gnuastro/fits.h>
 #include <gnuastro/linkedlist.h>
-#include <gnuastro/fitsarrayvv.h>
 #include <gnuastro/commonparams.h>
 
 
diff --git a/src/imgcrop/ui.c b/src/imgcrop/ui.c
index 454d765..1bebce6 100644
--- a/src/imgcrop/ui.c
+++ b/src/imgcrop/ui.c
@@ -31,12 +31,12 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 #include <nproc.h>              /* From Gnulib.                     */
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>    /* Includes time.h and sys/time.h   */
 #include <gnuastro/checkset.h>
 #include <gnuastro/txtarrayvv.h>
 #include <gnuastro/commonargs.h>
 #include <gnuastro/configfiles.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 #include "crop.h"
@@ -594,8 +594,8 @@ preparearrays(struct imgcropparams *p)
   fitsfile *tmpfits;
   struct timeval t1;
   struct inputimgs *img;
-  char msg[GAL_TIMING_VERB_MSG_LENGTH_V];
   int i, status, firstbitpix=0;
+  char msg[GAL_TIMING_VERB_MSG_LENGTH_V];
 
   if(p->cp.verb) gettimeofday(&t1, NULL);
 
@@ -620,10 +620,10 @@ preparearrays(struct imgcropparams *p)
       status=0;
       img=&p->imgs[i];
       gal_linkedlist_pop_from_stll(&p->up.gal_linkedlist_stll, &img->name);
-      gal_fitsarray_read_fits_hdu(img->name, p->cp.hdu, IMAGE_HDU, &tmpfits);
-      gal_fitsarray_img_bitpix_size(tmpfits, &p->bitpix, img->naxes);
-      gal_fitsarray_read_wcs(tmpfits, &img->nwcs, &img->wcs, p->hstartwcs,
-                             p->hendwcs);
+      gal_fits_read_hdu(img->name, p->cp.hdu, IMAGE_HDU, &tmpfits);
+      gal_fits_img_bitpix_size(tmpfits, &p->bitpix, img->naxes);
+      gal_fits_read_wcs_from_pointer(tmpfits, &img->nwcs, &img->wcs,
+                                     p->hstartwcs, p->hendwcs);
       if(img->wcs)
         {
           status=wcshdo(0, img->wcs, &img->nwcskeys, &img->wcstxt);
@@ -639,15 +639,15 @@ preparearrays(struct imgcropparams *p)
                 "Image Mode (note that the crops will lack WCS "
                 "header information)", img->name, p->cp.hdu);
       fits_close_file(tmpfits, &status);
-      gal_fitsarray_io_error(status, NULL);
+      gal_fits_io_error(status, NULL);
 
       /* Make sure all the images have the same BITPIX and set the
         basic BITPIX related parameters. */
       if(firstbitpix==0)
        {
          firstbitpix=p->bitpix;
-         p->datatype=gal_fitsarray_bitpix_to_dtype(p->bitpix);
-         p->bitnul=gal_fitsarray_bitpix_blank(p->bitpix);
+         p->datatype=gal_fits_bitpix_to_dtype(p->bitpix);
+         p->bitnul=gal_fits_bitpix_blank(p->bitpix);
        }
       else if(firstbitpix!=p->bitpix)
        error(EXIT_FAILURE, 0, "%s: BITPIX=%d. Previous images had a "
diff --git a/src/imgcrop/wcsmode.c b/src/imgcrop/wcsmode.c
index 9134e4e..989fa8b 100644
--- a/src/imgcrop/wcsmode.c
+++ b/src/imgcrop/wcsmode.c
@@ -29,9 +29,10 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <float.h>
 #include <stdlib.h>
 
-#include <gnuastro/fitsarrayvv.h>
+#include <gnuastro/wcs.h>
 
 #include "main.h"
+
 #include "crop.h"
 
 
@@ -291,8 +292,8 @@ fillcrpipolygon(struct cropparams *crp)
 
   /* Fill in the crp->ipolygon array by converting the WCS polygon
      vertices to this image's coordinates. */
-  gal_fitsarray_radec_array_to_xy(p->imgs[crp->imgindex].wcs, p->wpolygon,
-                                  crp->ipolygon, p->nvertices, 2);
+  gal_wcs_radec_array_to_xy(p->imgs[crp->imgindex].wcs, p->wpolygon,
+                            crp->ipolygon, p->nvertices, 2);
 }
 
 
diff --git a/src/imgstat/Makefile.am b/src/imgstat/Makefile.am
index e103329..7f380cd 100644
--- a/src/imgstat/Makefile.am
+++ b/src/imgstat/Makefile.am
@@ -29,8 +29,8 @@ astimgstat_SOURCES = main.c main.h cite.h ui.c ui.h args.h    
\
 imgstat.c imgstat.h
 
 astimgstat_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la          \
--lgalconfigfiles -lgalfitsarrayvv -lgalcheckset -lgaltiming            \
--lgallinkedlist -lgalmode -lgalstatistics -lgalarraymanip -lgalqsort
+-lgalconfigfiles -lgalfits -lgalcheckset -lgaltiming -lgallinkedlist   \
+-lgalmode -lgalstatistics -lgalarraymanip -lgalqsort
 
 
 
diff --git a/src/imgstat/args.h b/src/imgstat/args.h
index 3c845e2..f293a5b 100644
--- a/src/imgstat/args.h
+++ b/src/imgstat/args.h
@@ -537,7 +537,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( gal_fitsarray_name_is_fits(arg) )
+      if( gal_fits_name_is_fits(arg) )
         {
           if(p->up.inputname)
             argp_error(state, "only one input image should be given");
diff --git a/src/imgstat/ui.c b/src/imgstat/ui.c
index 3faab03..fb367be 100644
--- a/src/imgstat/ui.c
+++ b/src/imgstat/ui.c
@@ -32,6 +32,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 #include <nproc.h>              /* From Gnulib.                     */
 
+#include <gnuastro/fits.h>
 #include <gnuastro/qsort.h>
 #include <gnuastro/timing.h>   /* Includes time.h and sys/time.h   */
 #include <gnuastro/checkset.h>
@@ -40,7 +41,6 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro/txtarrayvv.h>
 #include <gnuastro/commonargs.h>
 #include <gnuastro/configfiles.h>
-#include <gnuastro/fitsarrayvv.h>
 #include <gnuastro/fixedstringmacros.h>
 
 #include "main.h"
@@ -381,7 +381,7 @@ sanitycheck(struct imgstatparams *p)
   gal_checkset_check_file(p->up.inputname);
 
   /* Set the p->up.maskname accordingly: */
-  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
+  gal_fits_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
                                  &p->up.maskname, p->up.mhdu,
                                  p->up.mhduset, "mask");
 
@@ -476,7 +476,7 @@ preparearrays(struct imgstatparams *p)
   struct uiparams *up=&p->up;
 
   /* Read the input and mask arrays: */
-  gal_fitsarray_file_to_float(up->inputname, up->maskname, p->cp.hdu, up->mhdu,
+  gal_fits_file_to_float(up->inputname, up->maskname, p->cp.hdu, up->mhdu,
                               &p->img, &bitpix, &anyblank, &s0, &s1);
   p->size=s0*s1;
 
diff --git a/src/imgwarp/Makefile.am b/src/imgwarp/Makefile.am
index 99ec7d4..f0ffa5c 100644
--- a/src/imgwarp/Makefile.am
+++ b/src/imgwarp/Makefile.am
@@ -28,9 +28,9 @@ bin_PROGRAMS = astimgwarp
 astimgwarp_SOURCES = main.c main.h cite.h ui.c ui.h args.h     \
 imgwarp.c imgwarp.h
 
-astimgwarp_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la  \
--lgalconfigfiles -lgalfitsarrayvv -lgaltxtarrayvv -lgalcheckset        \
--lgaltiming -lgalthreads -lgalpolygon
+astimgwarp_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la          \
+-lgalconfigfiles -lgalfits -lgaltxtarrayvv -lgalcheckset -lgaltiming   \
+-lgalthreads -lgalpolygon
 
 
 
diff --git a/src/imgwarp/args.h b/src/imgwarp/args.h
index 95d31f6..28d11f8 100644
--- a/src/imgwarp/args.h
+++ b/src/imgwarp/args.h
@@ -235,7 +235,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( gal_fitsarray_name_is_fits(arg) )
+      if( gal_fits_name_is_fits(arg) )
         {
           if(p->up.inputname)
             argp_error(state, "only one input image should be given");
diff --git a/src/imgwarp/imgwarp.c b/src/imgwarp/imgwarp.c
index a9dfdc3..ad421d7 100644
--- a/src/imgwarp/imgwarp.c
+++ b/src/imgwarp/imgwarp.c
@@ -28,8 +28,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <float.h>
 #include <stdlib.h>
 
+#include <gnuastro/fits.h>
 #include <gnuastro/polygon.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 #include "imgwarp.h"
@@ -427,7 +427,7 @@ correctwcssaveoutput(struct imgwarpparams *p)
   void *array;
   double *m=p->matrix;
   char keyword[9*FLEN_KEYWORD];
-  struct gal_fitsarray_header_ll *headers=NULL;
+  struct gal_fits_header_ll *headers=NULL;
   double tpc[4], tcrpix[3], *crpix=p->wcs->crpix, *pc=p->wcs->pc;
   double tinv[4]={p->inverse[0]/p->inverse[8], p->inverse[1]/p->inverse[8],
                   p->inverse[3]/p->inverse[8], p->inverse[4]/p->inverse[8]};
@@ -458,25 +458,25 @@ correctwcssaveoutput(struct imgwarpparams *p)
       p->inputbitpix=DOUBLE_IMG; /* In case it wasn't and p->doubletype==1 */
     }
   else
-    gal_fitsarray_change_type((void **)p->output, DOUBLE_IMG,
+    gal_fits_change_type((void **)p->output, DOUBLE_IMG,
                               p->onaxes[1]*p->onaxes[0],
                               p->numnul, &array, p->inputbitpix);
 
   /* Add the appropriate headers: */
-  gal_fitsarray_file_name_in_keywords("INF", p->up.inputname, &headers);
+  gal_fits_file_name_in_keywords("INF", p->up.inputname, &headers);
   for(i=0;i<9;++i)
     {
       sprintf(&keyword[i*FLEN_KEYWORD], "WMTX%lu_%lu", i/3+1, i%3+1);
-      gal_fitsarray_add_to_fits_header_ll_end(&headers, TDOUBLE,
+      gal_fits_add_to_fits_header_ll_end(&headers, TDOUBLE,
                                               &keyword[i*FLEN_KEYWORD], 0,
                                               &p->matrix[i], 0, "Warp matrix "
                                               "element value.", 0, NULL);
     }
 
   /* Save the output: */
-  gal_fitsarray_array_to_fits_img(p->cp.output, "Warped", p->inputbitpix, 
array,
-                                  p->onaxes[1], p->onaxes[0], p->numnul, 
p->wcs,
-                                  headers, SPACK_STRING);
+  gal_fits_array_to_file(p->cp.output, "Warped", p->inputbitpix, array,
+                         p->onaxes[1], p->onaxes[0], p->numnul, p->wcs,
+                         headers, SPACK_STRING);
 
   if(array!=p->output)
     free(array);
diff --git a/src/imgwarp/ui.c b/src/imgwarp/ui.c
index 145a66a..555cc9e 100644
--- a/src/imgwarp/ui.c
+++ b/src/imgwarp/ui.c
@@ -31,12 +31,12 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 #include <nproc.h>              /* From Gnulib.                     */
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>           /* Includes time.h and sys/time.h   */
 #include <gnuastro/checkset.h>
 #include <gnuastro/txtarrayvv.h>
 #include <gnuastro/commonargs.h>
 #include <gnuastro/configfiles.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -405,18 +405,18 @@ preparearrays(struct imgwarpparams *p)
   double *inv, *m=p->matrix;
 
   /* Read in the input image: */
-  numnul=gal_fitsarray_fits_img_to_array(p->up.inputname, p->cp.hdu,
-                                         &p->inputbitpix, &array, &p->is0,
-                                         &p->is1);
+  numnul=gal_fits_hdu_to_array(p->up.inputname, p->cp.hdu,
+                                     &p->inputbitpix, &array, &p->is0,
+                                     &p->is1);
   if(p->inputbitpix==DOUBLE_IMG)
     p->input=array;
   else
     {
-      gal_fitsarray_change_type(array, p->inputbitpix, p->is0*p->is1, numnul,
+      gal_fits_change_type(array, p->inputbitpix, p->is0*p->is1, numnul,
                                 (void **)&p->input, DOUBLE_IMG);
       free(array);
     }
-  gal_fitsarray_read_fits_wcs(p->up.inputname, p->cp.hdu, p->hstartwcs,
+  gal_fits_read_wcs(p->up.inputname, p->cp.hdu, p->hstartwcs,
                               p->hendwcs, &p->nwcs, &p->wcs);
 
   /* Make the inverse matrix: */
diff --git a/src/mkcatalog/Makefile.am b/src/mkcatalog/Makefile.am
index e459e1b..c0a2825 100644
--- a/src/mkcatalog/Makefile.am
+++ b/src/mkcatalog/Makefile.am
@@ -29,7 +29,7 @@ astmkcatalog_SOURCES = main.c main.h cite.h ui.c ui.h args.h  
\
 mkcatalog.c mkcatalog.h columns.c columns.h
 
 astmkcatalog_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la        \
--lgalconfigfiles -lgalfitsarrayvv -lgalcheckset -lgaltiming    \
+-lgalconfigfiles -lgalfits -lgalwcs -lgalcheckset -lgaltiming  \
 -lgallinkedlist -lgaltxtarrayvv
 
 
diff --git a/src/mkcatalog/args.h b/src/mkcatalog/args.h
index 5db091f..21fd6ba 100644
--- a/src/mkcatalog/args.h
+++ b/src/mkcatalog/args.h
@@ -849,7 +849,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( gal_fitsarray_name_is_fits(arg) )
+      if( gal_fits_name_is_fits(arg) )
         {
           if(p->up.inputname)
             argp_error(state, "only one input image should be given");
diff --git a/src/mkcatalog/columns.c b/src/mkcatalog/columns.c
index 7ca3637..d3cdd99 100644
--- a/src/mkcatalog/columns.c
+++ b/src/mkcatalog/columns.c
@@ -37,6 +37,8 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <string.h>
 #include <stdlib.h>
 
+#include <gnuastro/wcs.h>
+
 #include "main.h"
 
 #include "columns.h"
@@ -538,7 +540,7 @@ preparewcs(struct mkcatalogparams *p, size_t col)
       /* Do the conversion. Note that the p->icols is added because
          the first row is not used by any object or colump (since
          their indexes begin from 1).*/
-      gal_fitsarray_xy_array_to_radec(p->wcs, p->info+p->icols+xc,
+      gal_wcs_xy_array_to_radec(p->wcs, p->info+p->icols+xc,
                                       p->info+p->icols+rc,
                                       p->num, p->icols);
 
diff --git a/src/mkcatalog/main.h b/src/mkcatalog/main.h
index 10a8c02..3160b1f 100644
--- a/src/mkcatalog/main.h
+++ b/src/mkcatalog/main.h
@@ -23,7 +23,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #ifndef MAIN_H
 #define MAIN_H
 
-#include <gnuastro/fitsarrayvv.h>
+#include <gnuastro/fits.h>
 #include <gnuastro/commonparams.h>
 
 /* Progarm name macros: */
diff --git a/src/mkcatalog/mkcatalog.c b/src/mkcatalog/mkcatalog.c
index 178dbdf..dacc664 100644
--- a/src/mkcatalog/mkcatalog.c
+++ b/src/mkcatalog/mkcatalog.c
@@ -30,10 +30,11 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <string.h>
 #include <stdlib.h>
 
+#include <gnuastro/wcs.h>
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>
 #include <gnuastro/neighbors.h>
 #include <gnuastro/txtarrayvv.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -50,12 +51,12 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 /* Macro to see if the label is indexable (belongs to an object or
    not). See the explanation in src/noisechisel/label.h. */
-#if GAL_FITSARRAY_LONG_BLANK<0
+#if GAL_FITS_LONG_BLANK<0
 #define ISINDEXABLEOBJLABEL (objects[i]>0)
 #define ISINDEXABLECLPLABEL (clumps[i]>0)
 #else
-#define ISINDEXABLEOBJLABEL (objects[i] && 
objects[i]!=GAL_FITSARRAY_LONG_BLANK)
-#define ISINDEXABLECLPLABEL (clumps[i] && clumps[i]!=GAL_FITSARRAY_LONG_BLANK)
+#define ISINDEXABLEOBJLABEL (objects[i] && objects[i]!=GAL_FITS_LONG_BLANK)
+#define ISINDEXABLECLPLABEL (clumps[i] && clumps[i]!=GAL_FITS_LONG_BLANK)
 #endif
 
 
@@ -301,7 +302,7 @@ secondpass(struct mkcatalogparams *p)
       /* We are on a detected region but not a clump (with a negative
          label). This region can be used to find properties like the
          river fluxs in the vicinity of clumps. */
-      else if (clumps[i]!=GAL_FITSARRAY_LONG_BLANK)
+      else if (clumps[i]!=GAL_FITS_LONG_BLANK)
 
         /* We want to check the river pixels in each detection that
            has a clump. Recall that each detection can host more than
@@ -404,7 +405,7 @@ makeoutput(struct mkcatalogparams *p)
 
 
   /* Calculate the pixel area in arcseconds^2: */
-  pixarea=gal_fitsarray_pixel_area_arcsec2(p->wcs);
+  pixarea=gal_wcs_pixel_area_arcsec2(p->wcs);
 
 
   /* First make the objects catalog, then the clumps catalog. */
diff --git a/src/mkcatalog/ui.c b/src/mkcatalog/ui.c
index 60e9ecd..f1e7411 100644
--- a/src/mkcatalog/ui.c
+++ b/src/mkcatalog/ui.c
@@ -32,12 +32,12 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 #include <nproc.h>              /* From Gnulib.                     */
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>    /* Includes time.h and sys/time.h   */
 #include <gnuastro/checkset.h>
 #include <gnuastro/txtarrayvv.h>
 #include <gnuastro/commonargs.h>
 #include <gnuastro/configfiles.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -823,48 +823,48 @@ checkifset(struct mkcatalogparams *p)
 void
 sanitycheck(struct mkcatalogparams *p)
 {
-  struct gal_fitsarray_read_header_keys keys[2];
+  struct gal_fits_read_header_keys keys[2];
 
   /* Make sure the input file exists. */
   gal_checkset_check_file(p->up.inputname);
 
   /* Set the names of the files. */
-  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
+  gal_fits_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
                                  &p->up.maskname, p->up.mhdu, p->up.mhduset,
                                  "mask");
-  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu,
+  gal_fits_file_or_ext_name(p->up.inputname, p->cp.hdu,
                                  p->up.objlabsnameset, &p->up.objlabsname,
                                  p->up.objhdu, p->up.objhduset,
                                  "object labels");
-  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu,
+  gal_fits_file_or_ext_name(p->up.inputname, p->cp.hdu,
                                  p->up.clumplabsnameset, &p->up.clumplabsname,
                                  p->up.clumphdu, p->up.clumphduset,
                                  "clump labels");
-  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.skynameset,
+  gal_fits_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.skynameset,
                                  &p->up.skyname, p->up.skyhdu, p->up.skyhduset,
                                  "sky value image");
-  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.stdnameset,
+  gal_fits_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.stdnameset,
                                  &p->up.stdname, p->up.stdhdu, p->up.stdhduset,
                                  "sky standard deviation");
 
   /* Read the number of labels for the objects:  */
   keys[0].keyname="DETSN";        keys[0].datatype=TDOUBLE;
   keys[1].keyname="NOBJS";        keys[1].datatype=TLONG;
-  gal_fitsarray_read_keywords(p->up.objlabsname, p->up.objhdu, keys, 2);
+  gal_fits_read_keywords(p->up.objlabsname, p->up.objhdu, keys, 2);
   p->detsn=keys[0].d;
   p->numobjects=keys[1].l;
 
   /* Read the clumps information. Note that the datatypes don't change. */
   keys[0].keyname="CLUMPSN";
   keys[1].keyname="NCLUMPS";
-  gal_fitsarray_read_keywords(p->up.clumplabsname, p->up.clumphdu, keys, 2);
+  gal_fits_read_keywords(p->up.clumplabsname, p->up.clumphdu, keys, 2);
   p->clumpsn=keys[0].d;
   p->numclumps=keys[1].l;
 
   /* Read the minimum and maximum standard deviation values. */
   keys[0].keyname="MINSTD";       keys[0].datatype=TFLOAT;
   keys[1].keyname="MEDSTD";       keys[1].datatype=TFLOAT;
-  gal_fitsarray_read_keywords(p->up.stdname, p->up.stdhdu, keys, 2);
+  gal_fits_read_keywords(p->up.stdname, p->up.stdhdu, keys, 2);
   p->minstd=keys[0].f;
   p->medstd=keys[1].f;
   p->cpscorr = p->minstd>1 ? 1.0f : p->minstd;
@@ -934,7 +934,7 @@ checksetlong(struct mkcatalogparams *p, char *filename, 
char *hdu,
   int bitpix, anyblank;
 
   /* Read the file: */
-  gal_fitsarray_file_to_long(filename, hdu, array, &bitpix,
+  gal_fits_file_to_long(filename, hdu, array, &bitpix,
                              &anyblank, &s0, &s1);
 
   /* Make sure it has an integer type. */
@@ -964,7 +964,7 @@ checksetfloat(struct mkcatalogparams *p, char *filename, 
char *hdu,
   int bitpix, anyblank;
 
   /* Read the array: */
-  gal_fitsarray_file_to_float(filename, NULL, hdu, NULL, array, &bitpix,
+  gal_fits_file_to_float(filename, NULL, hdu, NULL, array, &bitpix,
                               &anyblank, &s0, &s1);
 
   /* Make sure it has no blank pixels. */
@@ -1164,11 +1164,10 @@ preparearrays(struct mkcatalogparams *p)
      check the parameters, there is no input file name. */
   if(p->up.inputname)
     {
-      gal_fitsarray_file_to_float(p->up.inputname, p->up.maskname, p->cp.hdu,
+      gal_fits_file_to_float(p->up.inputname, p->up.maskname, p->cp.hdu,
                                   p->up.mhdu, &p->img, &bitpix, &anyblank,
                                   &p->s0, &p->s1);
-      gal_fitsarray_read_fits_wcs(p->up.inputname, p->cp.hdu, 0, 0,
-                                  &p->nwcs, &p->wcs);
+      gal_fits_read_wcs(p->up.inputname, p->cp.hdu, 0, 0, &p->nwcs, &p->wcs);
 
 
       /* Read and check the other arrays: */
diff --git a/src/mknoise/Makefile.am b/src/mknoise/Makefile.am
index 4351c76..e79b161 100644
--- a/src/mknoise/Makefile.am
+++ b/src/mknoise/Makefile.am
@@ -28,8 +28,8 @@ bin_PROGRAMS = astmknoise
 astmknoise_SOURCES = main.c main.h cite.h ui.c ui.h args.h     \
 mknoise.c mknoise.h
 
-astmknoise_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la           \
--lgalconfigfiles -lgalfitsarrayvv -lgalcheckset -lgaltiming -lgalthreads
+astmknoise_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la          \
+-lgalconfigfiles -lgalfits -lgalcheckset -lgaltiming -lgalthreads
 
 
 
diff --git a/src/mknoise/args.h b/src/mknoise/args.h
index 041af23..2d1ec21 100644
--- a/src/mknoise/args.h
+++ b/src/mknoise/args.h
@@ -208,7 +208,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( gal_fitsarray_name_is_fits(arg) )
+      if( gal_fits_name_is_fits(arg) )
         {
           if(p->up.inputname)
             argp_error(state, "only one input image should be given");
diff --git a/src/mknoise/main.h b/src/mknoise/main.h
index a7cb8c8..879b116 100644
--- a/src/mknoise/main.h
+++ b/src/mknoise/main.h
@@ -26,7 +26,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <pthread.h>
 #include <gsl/gsl_rng.h>
 
-#include <gnuastro/fitsarrayvv.h>
+#include <gnuastro/fits.h>
 #include <gnuastro/commonparams.h>
 
 /* Progarm name macros: */
diff --git a/src/mknoise/mknoise.c b/src/mknoise/mknoise.c
index 673abc4..83e6dec 100644
--- a/src/mknoise/mknoise.c
+++ b/src/mknoise/mknoise.c
@@ -33,7 +33,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gsl/gsl_randist.h>    /* To make noise.        */
 
 #include <gnuastro/timing.h>
-#include <gnuastro/fitsarrayvv.h>
+#include <gnuastro/fits.h>
 
 #include "main.h"
 
@@ -54,7 +54,7 @@ void
 convertsaveoutput(struct mknoiseparams *p)
 {
   void *array;
-  struct gal_fitsarray_header_ll *headers=NULL;
+  struct gal_fits_header_ll *headers=NULL;
   char keyname1[FLEN_KEYWORD], keyname2[FLEN_KEYWORD];
   char keyname3[FLEN_KEYWORD], keyname4[FLEN_KEYWORD], keyname5[FLEN_KEYWORD];
 
@@ -65,37 +65,37 @@ convertsaveoutput(struct mknoiseparams *p)
       p->inputbitpix=DOUBLE_IMG; /* In case it wasn't and p->doubletype==1 */
     }
   else
-    gal_fitsarray_change_type((void **)p->input, DOUBLE_IMG, p->is0*p->is1,
+    gal_fits_change_type((void **)p->input, DOUBLE_IMG, p->is0*p->is1,
                               p->anyblank, &array, p->inputbitpix);
 
   /* Add the proper information to the header of the output: */
-  gal_fitsarray_file_name_in_keywords("INF", p->up.inputname, &headers);
+  gal_fits_file_name_in_keywords("INF", p->up.inputname, &headers);
   strcpy(keyname1, "BCKGRND");
-  gal_fitsarray_add_to_fits_header_ll_end(&headers, TDOUBLE, keyname1, 0,
+  gal_fits_add_to_fits_header_ll_end(&headers, TDOUBLE, keyname1, 0,
                                           &p->mbackground, 0, "Background "
                                           "value (in magnitude) for noise.",
                                           0, NULL);
   strcpy(keyname2, "BZRPNT");
-  gal_fitsarray_add_to_fits_header_ll_end(&headers, TDOUBLE, keyname2, 0,
+  gal_fits_add_to_fits_header_ll_end(&headers, TDOUBLE, keyname2, 0,
                                           &p->zeropoint, 0, "Zeropoint "
                                           "magnitude of image.", 0, NULL);
   strcpy(keyname3, "STDADD");
-  gal_fitsarray_add_to_fits_header_ll_end(&headers, TDOUBLE, keyname3, 0,
+  gal_fits_add_to_fits_header_ll_end(&headers, TDOUBLE, keyname3, 0,
                                           &p->stdadd, 0, "Instrumental noise "
                                           "in units of flux.", 0, NULL);
   strcpy(keyname4, "RNGTYPE");
-  gal_fitsarray_add_to_fits_header_ll_end(&headers, TSTRING, keyname4, 0,
+  gal_fits_add_to_fits_header_ll_end(&headers, TSTRING, keyname4, 0,
                                           &p->rng_type, 0, "Random number "
                                           "generator (by GSL) type.", 0, NULL);
   strcpy(keyname5, "RNGSEED");
-  gal_fitsarray_add_to_fits_header_ll_end(&headers, TLONG, keyname5, 0,
+  gal_fits_add_to_fits_header_ll_end(&headers, TLONG, keyname5, 0,
                                           &p->rng_seed, 0, "Random number "
                                           "generator (by GSL) seed.", 0, NULL);
 
   /* Save the output: */
-  gal_fitsarray_array_to_fits_img(p->cp.output, "NoiseAdded", p->inputbitpix,
-                                  array, p->is0, p->is1, p->anyblank, p->wcs,
-                                  headers, SPACK_STRING);
+  gal_fits_array_to_file(p->cp.output, "NoiseAdded", p->inputbitpix,
+                         array, p->is0, p->is1, p->anyblank, p->wcs,
+                         headers, SPACK_STRING);
 
   if(array!=p->input)
     free(array);
diff --git a/src/mknoise/ui.c b/src/mknoise/ui.c
index 6529dd2..c410fa9 100644
--- a/src/mknoise/ui.c
+++ b/src/mknoise/ui.c
@@ -32,12 +32,12 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 #include <nproc.h>              /* From Gnulib.                     */
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>    /* Includes time.h and sys/time.h   */
 #include <gnuastro/checkset.h>
 #include <gnuastro/txtarrayvv.h>
 #include <gnuastro/commonargs.h>
 #include <gnuastro/configfiles.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -286,20 +286,19 @@ preparearrays(struct mknoiseparams *p)
   void *array;
 
   /* Read in the input image: */
-  p->anyblank=gal_fitsarray_fits_img_to_array(p->up.inputname, p->cp.hdu,
-                                              &p->inputbitpix, &array,
-                                              &p->is0, &p->is1);
+  p->anyblank=gal_fits_hdu_to_array(p->up.inputname, p->cp.hdu,
+                                    &p->inputbitpix, &array,
+                                    &p->is0, &p->is1);
   if(p->inputbitpix==DOUBLE_IMG)
     p->input=array;
   else
     {
-      gal_fitsarray_change_type(array, p->inputbitpix, p->is0*p->is1,
+      gal_fits_change_type(array, p->inputbitpix, p->is0*p->is1,
                                 p->anyblank, (void **)&p->input,
                                 DOUBLE_IMG);
       free(array);
     }
-  gal_fitsarray_read_fits_wcs(p->up.inputname, p->cp.hdu, 0, 0,
-                              &p->nwcs, &p->wcs);
+  gal_fits_read_wcs(p->up.inputname, p->cp.hdu, 0, 0, &p->nwcs, &p->wcs);
 
   /* Allocate the random number generator: */
   gsl_rng_env_setup();
diff --git a/src/mkprof/Makefile.am b/src/mkprof/Makefile.am
index 84cddc1..475cdb9 100644
--- a/src/mkprof/Makefile.am
+++ b/src/mkprof/Makefile.am
@@ -28,10 +28,10 @@ bin_PROGRAMS = astmkprof
 astmkprof_SOURCES = main.c main.h ui.c ui.h mkprof.c mkprof.h args.h   \
 oneprofile.c oneprofile.h profiles.c profiles.h cite.h
 
-astmkprof_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la           \
--lgalconfigfiles -lgalfitsarrayvv -lgaltxtarrayvv -lgalcheckset                
\
--lgallinkedlist -lgaltiming -lgalthreads -lgalbox -lgalstatistics      \
--lgalarraymanip -lgalqsort
+astmkprof_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la            \
+-lgalconfigfiles -lgalfits -lgaltxtarrayvv -lgalcheckset -lgallinkedlist \
+-lgaltiming -lgalthreads -lgalbox -lgalstatistics -lgalarraymanip       \
+-lgalqsort
 
 
 
diff --git a/src/mkprof/args.h b/src/mkprof/args.h
index 5ff7bb6..f1c27de 100644
--- a/src/mkprof/args.h
+++ b/src/mkprof/args.h
@@ -606,7 +606,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( gal_fitsarray_name_is_fits(arg) )
+      if( gal_fits_name_is_fits(arg) )
        {
          if(p->up.backname)
            argp_error(state, "only one input FITS image (the background) "
diff --git a/src/mkprof/main.h b/src/mkprof/main.h
index c120103..ac08fcb 100644
--- a/src/mkprof/main.h
+++ b/src/mkprof/main.h
@@ -26,7 +26,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <pthread.h>
 #include <gsl/gsl_rng.h>
 
-#include <gnuastro/fitsarrayvv.h>
+#include <gnuastro/fits.h>
 #include <gnuastro/commonparams.h>
 
 
diff --git a/src/mkprof/mkprof.c b/src/mkprof/mkprof.c
index 1acb6d0..7b71fb2 100644
--- a/src/mkprof/mkprof.c
+++ b/src/mkprof/mkprof.c
@@ -30,13 +30,13 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <stdlib.h>
 
 #include <gnuastro/box.h>
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>
 #include <gnuastro/threads.h>
 #include <gnuastro/checkset.h>
 #include <gnuastro/statistics.h>
 #include <gnuastro/arraymanip.h>
 #include <gnuastro/txtarrayvv.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -217,11 +217,11 @@ saveindividual(struct mkonthread *mkp)
   /* Write the array to file (A separately built PSF doesn't need WCS
      coordinates): */
   if(ibq->ispsf && p->psfinimg==0)
-    gal_fitsarray_array_to_fits_img(outname, "MockImg", FLOAT_IMG, ibq->img,
-                                    mkp->width[1], mkp->width[0], 0, NULL, 
NULL,
-                                    SPACK_STRING);
+    gal_fits_array_to_file(outname, "MockImg", FLOAT_IMG, ibq->img,
+                           mkp->width[1], mkp->width[0], 0, NULL, NULL,
+                           SPACK_STRING);
   else
-    gal_fitsarray_atof_correct_wcs(outname, "MockImg", FLOAT_IMG, ibq->img,
+    gal_fits_atof_correct_wcs(outname, "MockImg", FLOAT_IMG, ibq->img,
                                    mkp->width[1], mkp->width[0], p->wcsheader,
                                    p->wcsnkeyrec, crpix, SPACK_STRING);
   ibq->indivcreated=1;
@@ -619,17 +619,17 @@ write(struct mkprofparams *p)
       if(p->up.backname)
         {
           if(bitpix==FLOAT_IMG) array=out;
-          else gal_fitsarray_change_type(p->out, FLOAT_IMG,
+          else gal_fits_change_type(p->out, FLOAT_IMG,
                                          p->naxes[1]*p->naxes[0],
                                          p->anyblank, &array, bitpix);
-          gal_fitsarray_array_to_fits_img(p->mergedimgname, "MockImg on back",
-                                          bitpix, array, p->naxes[1],
-                                          p->naxes[0], p->anyblank, p->wcs,
-                                          NULL, SPACK_STRING);
+          gal_fits_array_to_file(p->mergedimgname, "MockImg on back",
+                                 bitpix, array, p->naxes[1],
+                                 p->naxes[0], p->anyblank, p->wcs,
+                                 NULL, SPACK_STRING);
           if(bitpix!=FLOAT_IMG) free(array);
         }
       else
-        gal_fitsarray_atof_correct_wcs(p->mergedimgname, "MockImg", FLOAT_IMG,
+        gal_fits_atof_correct_wcs(p->mergedimgname, "MockImg", FLOAT_IMG,
                                        out, p->naxes[1], p->naxes[0],
                                        p->wcsheader, p->wcsnkeyrec,
                                        NULL, SPACK_STRING);
diff --git a/src/mkprof/oneprofile.c b/src/mkprof/oneprofile.c
index d621f15..75abd3a 100644
--- a/src/mkprof/oneprofile.c
+++ b/src/mkprof/oneprofile.c
@@ -33,12 +33,12 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gsl/gsl_randist.h>    /* To make noise.       */
 #include <gsl/gsl_integration.h> /* gsl_integration_qng  */
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>
 #include <gnuastro/neighbors.h>
 #include <gnuastro/arraymanip.h>
 #include <gnuastro/statistics.h>
 #include <gnuastro/linkedlist.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -310,7 +310,7 @@ makepixbypix(struct mkonthread *mkp)
           /*
             printf("\tac: %f, ap: %f, frac: %f\n", img[p], approx,
             fabs(img[p]-approx)/img[p]);
-            gal_fitsarray_array_to_fits_img("tmp.fits", "", FLOAT_IMG, img, 
is0, is1,
+            gal_fits_array_to_file("tmp.fits", "", FLOAT_IMG, img, is0, is1,
             NULL, SPACK_STRING);
           */
 
@@ -360,8 +360,8 @@ makepixbypix(struct mkonthread *mkp)
       if(ispeak) { mkp->peakflux=img[p]; ispeak=0; }
 
       /*
-      gal_fitsarray_array_to_fits_img("tmp.fits", "", FLOAT_IMG, img, is0, is1,
-                    NULL, SPACK_STRING);
+      gal_fits_array_to_file("tmp.fits", "", FLOAT_IMG, img, is0, is1,
+                            NULL, SPACK_STRING);
       */
       /* Go over the neighbours and add them to queue of elements
         to check. */
diff --git a/src/mkprof/ui.c b/src/mkprof/ui.c
index 9dec861..919c83e 100644
--- a/src/mkprof/ui.c
+++ b/src/mkprof/ui.c
@@ -32,13 +32,13 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <nproc.h>              /* From Gnulib.                   */
 
 #include <gnuastro/box.h>
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>     /* Includes time.h and sys/time.h */
 #include <gnuastro/checkset.h>
 #include <gnuastro/statistics.h>
 #include <gnuastro/txtarrayvv.h>
 #include <gnuastro/commonargs.h>
 #include <gnuastro/configfiles.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 #include "mkprof.h"
@@ -658,11 +658,10 @@ preparearrays(struct mkprofparams *p)
   if(p->up.backname)
     {
       /* Read in the background image and its coordinates: */
-      p->anyblank=gal_fitsarray_fits_img_to_array(p->up.backname, p->cp.hdu,
-                                                  &p->bitpix, &array,
-                                                  &naxes[1], &naxes[0]);
-      gal_fitsarray_read_fits_wcs(p->up.backname, p->cp.hdu, 0, 0,
-                                  &p->nwcs, &p->wcs);
+      p->anyblank=gal_fits_hdu_to_array(p->up.backname, p->cp.hdu,
+                                        &p->bitpix, &array,
+                                        &naxes[1], &naxes[0]);
+      gal_fits_read_wcs(p->up.backname, p->cp.hdu, 0, 0, &p->nwcs, &p->wcs);
       p->naxes[1]=naxes[1];
       p->naxes[0]=naxes[0];
 
@@ -672,7 +671,7 @@ preparearrays(struct mkprofparams *p)
         p->out=array;
       else
         {
-          gal_fitsarray_change_type(array, p->bitpix, p->naxes[1]*p->naxes[0],
+          gal_fits_change_type(array, p->bitpix, p->naxes[1]*p->naxes[0],
                                     p->anyblank, (void **)(&p->out), 
FLOAT_IMG);
           free(array);
         }
diff --git a/src/noisechisel/Makefile.am b/src/noisechisel/Makefile.am
index 0a0d2c7..d8e3143 100644
--- a/src/noisechisel/Makefile.am
+++ b/src/noisechisel/Makefile.am
@@ -31,7 +31,7 @@ label.c label.h detection.c detection.h sky.c sky.h 
segmentation.c    \
 segmentation.h clumps.c clumps.h
 
 astnoisechisel_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la      \
--lgalconfigfiles -lgalfitsarrayvv -lgalcheckset -lgaltiming -lgalmesh  \
+-lgalconfigfiles -lgalfits -lgalcheckset -lgaltiming -lgalmesh         \
 -lgalspatialconvolve -lgalthreads -lgalmode -lgalstatistics            \
 -lgalarraymanip -lgalqsort -lgallinkedlist -lgalbox
 
diff --git a/src/noisechisel/args.h b/src/noisechisel/args.h
index ce9ff53..8b8f4e1 100644
--- a/src/noisechisel/args.h
+++ b/src/noisechisel/args.h
@@ -789,7 +789,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( gal_fitsarray_name_is_fits(arg) )
+      if( gal_fits_name_is_fits(arg) )
         {
           if(p->up.inputname)
             argp_error(state, "only one input image should be given");
diff --git a/src/noisechisel/binary.c b/src/noisechisel/binary.c
index 18693dd..75b4954 100644
--- a/src/noisechisel/binary.c
+++ b/src/noisechisel/binary.c
@@ -28,7 +28,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <error.h>
 #include <stdlib.h>
 
-#include <gnuastro/fitsarrayvv.h>
+#include <gnuastro/fits.h>
 
 #include "main.h"
 
@@ -43,7 +43,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
  **************            Binary NAN           *****************
  ****************************************************************/
 /* When the float image has NaN pixels, set the respective byt value
-   to GAL_FITSARRAY_BYTE_BLANK. */
+   to GAL_FITS_BYTE_BLANK. */
 void
 setbytblank(float *img, unsigned char *byt, size_t size)
 {
@@ -51,7 +51,7 @@ setbytblank(float *img, unsigned char *byt, size_t size)
   do
     {
       if(isnan(*img++))
-        *byt=GAL_FITSARRAY_BYTE_BLANK;
+        *byt=GAL_FITS_BYTE_BLANK;
       ++byt;
     }
   while(img<end);
@@ -98,7 +98,7 @@ count_f_b_onregion(unsigned char *byt, size_t startind, 
size_t s0,
     {
       fb = ( b = byt + startind + is1*row++ ) + s1;
       do
-        *b ? (*b==GAL_FITSARRAY_BYTE_BLANK ? *anyblank=1: ++nf) : ++nb;
+        *b ? (*b==GAL_FITS_BYTE_BLANK ? *anyblank=1: ++nf) : ++nb;
       while(++b<fb);
     }
   while(row<s0);
@@ -533,8 +533,8 @@ fh_makeinv(unsigned char *byt, size_t s0, size_t s1,
       tp=tinv+start+row*idy;
       bf = ( bp = byt + row++ * s1 ) + s1;
       if(anyblank)
-        do *tp++ = *bp==GAL_FITSARRAY_BYTE_BLANK
-             ? GAL_FITSARRAY_BYTE_BLANK : !*bp; while(++bp<bf);
+        do *tp++ = *bp==GAL_FITS_BYTE_BLANK
+             ? GAL_FITS_BYTE_BLANK : !*bp; while(++bp<bf);
       else
         do *tp++ = !*bp; while(++bp<bf);
     }
@@ -624,12 +624,12 @@ fillboundedholes(unsigned char *in, size_t s0, size_t s1, 
int anyblank)
 
 
   /* For a check
-  gal_fitsarray_array_to_fits_img("fbh.fits", "INPUT", BYTE_IMG, in,
-                 s0, s1, anyblank, NULL, NULL, "tmp");
-  gal_fitsarray_array_to_fits_img("fbh.fits", "INV", BYTE_IMG, inv,
-                 idx, idy, anyblank, NULL, NULL, "tmp");
-  gal_fitsarray_array_to_fits_img("fbh.fits", "HLAB", LONG_IMG, hlab,
-                 idx, idy, anyblank, NULL, NULL, "tmp");
+  gal_fits_array_to_file("fbh.fits", "INPUT", BYTE_IMG, in,
+                         s0, s1, anyblank, NULL, NULL, "tmp");
+  gal_fits_array_to_file("fbh.fits", "INV", BYTE_IMG, inv,
+                         idx, idy, anyblank, NULL, NULL, "tmp");
+  gal_fits_array_to_file("fbh.fits", "HLAB", LONG_IMG, hlab,
+                         idx, idy, anyblank, NULL, NULL, "tmp");
   */
 
   /* Correct the labels: */
@@ -645,8 +645,8 @@ fillboundedholes(unsigned char *in, size_t s0, size_t s1, 
int anyblank)
 
 
   /* For a check:
-  gal_fitsarray_array_to_fits_img("fbh.fits", "INPUT", BYTE_IMG, in,
-                 s0, s1, anyblank, NULL, NULL, "tmp");
+  gal_fits_array_to_file("fbh.fits", "INPUT", BYTE_IMG, in,
+                         s0, s1, anyblank, NULL, NULL, "tmp");
   exit(0);
   */
 
diff --git a/src/noisechisel/binary.h b/src/noisechisel/binary.h
index 5675b95..a6d42bd 100644
--- a/src/noisechisel/binary.h
+++ b/src/noisechisel/binary.h
@@ -28,7 +28,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 
 /* For the GAL_FITSARRAY_BYTE_BLANK value: */
-#include <gnuastro/fitsarrayvv.h>
+#include <gnuastro/fits.h>
 
 
 
diff --git a/src/noisechisel/clumps.c b/src/noisechisel/clumps.c
index 7275ecc..2c9dddb 100644
--- a/src/noisechisel/clumps.c
+++ b/src/noisechisel/clumps.c
@@ -29,6 +29,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <string.h>
 #include <stdlib.h>
 
+#include <gnuastro/fits.h>
 #include <gnuastro/qsort.h>
 #include <gnuastro/timing.h>
 #include <gnuastro/checkset.h>
@@ -36,7 +37,6 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro/arraymanip.h>
 #include <gnuastro/linkedlist.h>
 #include <gnuastro/statistics.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
diff --git a/src/noisechisel/detection.c b/src/noisechisel/detection.c
index d358b1e..0cdf39e 100644
--- a/src/noisechisel/detection.c
+++ b/src/noisechisel/detection.c
@@ -27,6 +27,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <error.h>
 #include <stdlib.h>
 
+#include <gnuastro/fits.h>
 #include <gnuastro/mesh.h>
 #include <gnuastro/qsort.h>
 #include <gnuastro/timing.h>
@@ -34,7 +35,6 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro/checkset.h>
 #include <gnuastro/arraymanip.h>
 #include <gnuastro/statistics.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -75,9 +75,9 @@ initialdetection(struct noisechiselparams *p)
   findapplyqthreshold(p);
   if(p->anyblank)  setbytblank(p->img, p->byt, s0*s1);
   if(detectionname)
-    gal_fitsarray_array_to_fits_img(detectionname, "Thresholded", BYTE_IMG,
-                                    p->byt, s0, s1, p->anyblank, p->wcs, NULL,
-                                    SPACK_STRING);
+    gal_fits_array_to_file(detectionname, "Thresholded", BYTE_IMG,
+                           p->byt, s0, s1, p->anyblank, p->wcs, NULL,
+                           SPACK_STRING);
   if(verb)
     {
       sprintf(report, "%.2f quantile threshold found and applied.",
@@ -95,9 +95,9 @@ initialdetection(struct noisechiselparams *p)
     for(i=0;i<p->erode;++i)
       dilate0_erode1_8con(p->byt, s0, s1, 1);
   if(detectionname)
-    gal_fitsarray_array_to_fits_img(detectionname, "Eroded", BYTE_IMG, p->byt,
-                                    s0, s1, p->anyblank, p->wcs, NULL,
-                                    SPACK_STRING);
+    gal_fits_array_to_file(detectionname, "Eroded", BYTE_IMG, p->byt,
+                           s0, s1, p->anyblank, p->wcs, NULL,
+                           SPACK_STRING);
   if(verb)
     {
       sprintf(report, "Eroded %lu times (%s connectivity).",
@@ -110,9 +110,9 @@ initialdetection(struct noisechiselparams *p)
   /* Do the opening: */
   opening(p->byt, s0, s1, p->opening, p->openingngb);
   if(detectionname)
-    gal_fitsarray_array_to_fits_img(detectionname, "Opened", BYTE_IMG, p->byt,
-                                    s0, s1, p->anyblank, p->wcs, NULL,
-                                    SPACK_STRING);
+    gal_fits_array_to_file(detectionname, "Opened", BYTE_IMG, p->byt,
+                           s0, s1, p->anyblank, p->wcs, NULL,
+                           SPACK_STRING);
   if(verb)
     {
       sprintf(report, "Opened (depth: %lu, %s connectivity).",
@@ -126,9 +126,9 @@ initialdetection(struct noisechiselparams *p)
      ui.c and will be freed there. */
   p->numobjects=BF_concmp(p->byt, p->olab, s0, s1, p->anyblank, 4);
   if(detectionname)
-    gal_fitsarray_array_to_fits_img(detectionname, "Labeled", LONG_IMG, 
p->olab,
-                                    s0, s1, p->anyblank, p->wcs, NULL,
-                                    SPACK_STRING);
+    gal_fits_array_to_file(detectionname, "Labeled", LONG_IMG, p->olab,
+                           s0, s1, p->anyblank, p->wcs, NULL,
+                           SPACK_STRING);
 }
 
 
@@ -246,9 +246,9 @@ detlabelsn(struct noisechiselparams *p, size_t *numlabs, 
float **outsntable)
           ++b;
         }
       while(++lab<lf);
-      gal_fitsarray_array_to_fits_img(p->detectionname, "For S/N", BYTE_IMG,
-                                      p->dbyt, p->smp.s0, p->smp.s1,
-                                      p->anyblank, p->wcs, NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->detectionname, "For S/N", BYTE_IMG,
+                             p->dbyt, p->smp.s0, p->smp.s1,
+                             p->anyblank, p->wcs, NULL, SPACK_STRING);
     }
 
 
@@ -335,7 +335,7 @@ applydetsn(struct noisechiselparams *p, float *sntable, 
size_t numpseudo)
   lf= (lab=clab) + p->smp.s0*p->smp.s1;
   do
     {
-      if(*lab!=GAL_FITSARRAY_LONG_BLANK)
+      if(*lab!=GAL_FITS_LONG_BLANK)
         *b = newlabs[*lab] > 0;
       ++b;
     }
@@ -343,9 +343,9 @@ applydetsn(struct noisechiselparams *p, float *sntable, 
size_t numpseudo)
 
 
   if(p->detectionname)
-    gal_fitsarray_array_to_fits_img(p->detectionname, "True pseudo-detections",
-                                    BYTE_IMG, p->dbyt, p->smp.s0, p->smp.s1,
-                                    p->anyblank, p->wcs, NULL, SPACK_STRING);
+    gal_fits_array_to_file(p->detectionname, "True pseudo-detections",
+                           BYTE_IMG, p->dbyt, p->smp.s0, p->smp.s1,
+                           p->anyblank, p->wcs, NULL, SPACK_STRING);
 
   free(newlabs);
 }
@@ -390,8 +390,8 @@ bytpartfromlarge(struct noisechiselparams *p, unsigned char 
*out,
       bf = ( b = p->byt + start + r++ * is1 ) + s1;
       do
         {
-          *out++ = *b==b0f1 ? *d : (*b==GAL_FITSARRAY_BYTE_BLANK
-                                    ? GAL_FITSARRAY_BYTE_BLANK : 0);
+          *out++ = *b==b0f1 ? *d : (*b==GAL_FITS_BYTE_BLANK
+                                    ? GAL_FITS_BYTE_BLANK : 0);
           ++d;
         }
       while(++b<bf);
@@ -467,7 +467,7 @@ detectpseudos(void *inparams)
       if(p->anyblank)
         {
           bf=(b=thisbyt)+s0*s1;
-          do if(*b++==GAL_FITSARRAY_BYTE_BLANK) { anyblank=1; break; }
+          do if(*b++==GAL_FITS_BYTE_BLANK) { anyblank=1; break; }
           while(b<bf);
         }
 
@@ -557,9 +557,9 @@ detsnthresh(struct noisechiselparams *p)
                     "p->stepnum (%d) is not recognized in detsnthresh "
                     "(detection.c)", PACKAGE_BUGREPORT, p->stepnum);
             }
-          gal_fitsarray_array_to_fits_img(p->detectionname, extname, BYTE_IMG,
-                                          p->dbyt, s0, s1, p->anyblank, p->wcs,
-                                          NULL, SPACK_STRING);
+          gal_fits_array_to_file(p->detectionname, extname, BYTE_IMG,
+                                 p->dbyt, s0, s1, p->anyblank, p->wcs,
+                                 NULL, SPACK_STRING);
           ++p->stepnum;
         }
       free(tmp);
@@ -575,9 +575,9 @@ detsnthresh(struct noisechiselparams *p)
      quantile. */
   numpseudo=BF_concmp(p->dbyt, p->clab, s0, s1, p->anyblank, 4);
   if(p->detectionname)
-    gal_fitsarray_array_to_fits_img(p->detectionname, "Labeled", LONG_IMG,
-                                    p->clab, s0, s1, p->anyblank, p->wcs,
-                                    NULL, SPACK_STRING);
+    gal_fits_array_to_file(p->detectionname, "Labeled", LONG_IMG,
+                           p->clab, s0, s1, p->anyblank, p->wcs,
+                           NULL, SPACK_STRING);
   detlabelsn(p, &numpseudo, &sntable);
 
 
@@ -658,7 +658,7 @@ dbytolaboverlap(struct noisechiselparams *p)
   if(p->dilate)
     do
       {
-        if(*lab!=GAL_FITSARRAY_LONG_BLANK)
+        if(*lab!=GAL_FITS_LONG_BLANK)
           *byt=tokeep[*lab]>0;
         ++byt;
       }
@@ -666,7 +666,7 @@ dbytolaboverlap(struct noisechiselparams *p)
   else
     do
       {
-        if(*lab!=GAL_FITSARRAY_LONG_BLANK)
+        if(*lab!=GAL_FITS_LONG_BLANK)
           *byt = ( *lab = tokeep[*lab] ) > 0;
         ++byt;
       }
@@ -721,9 +721,9 @@ onlytruedetections(struct noisechiselparams *p)
   /* Apply the false detection removal threshold to the image. */
   applydetectionthresholdskysub(p);
   if(detectionname)
-    gal_fitsarray_array_to_fits_img(detectionname, "InitalSkySubtracted",
-                                    FLOAT_IMG, p->imgss, s0, s1, p->anyblank,
-                                    p->wcs, NULL, SPACK_STRING);
+    gal_fits_array_to_file(detectionname, "InitalSkySubtracted",
+                           FLOAT_IMG, p->imgss, s0, s1, p->anyblank,
+                           p->wcs, NULL, SPACK_STRING);
   if(verb)
     {
       sprintf(report, "Initial sky threshold (%.3f sigma) applied.",
@@ -742,9 +742,9 @@ onlytruedetections(struct noisechiselparams *p)
   /* Select the true detections: */
   dbytolaboverlap(p);
   if(detectionname)
-    gal_fitsarray_array_to_fits_img(detectionname, "TrueDetections",
-                                    BYTE_IMG, p->byt, s0, s1, p->anyblank,
-                                    p->wcs, NULL, SPACK_STRING);
+    gal_fits_array_to_file(detectionname, "TrueDetections",
+                           BYTE_IMG, p->byt, s0, s1, p->anyblank,
+                           p->wcs, NULL, SPACK_STRING);
   if(verb)
     {            /* p->numobjects changed in dbytlaboverlap. */
       sprintf(report, "%lu false detections removed.",
diff --git a/src/noisechisel/label.c b/src/noisechisel/label.c
index 986768f..5bf7050 100644
--- a/src/noisechisel/label.c
+++ b/src/noisechisel/label.c
@@ -28,9 +28,9 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <string.h>
 #include <stdlib.h>
 
+#include <gnuastro/fits.h>
 #include <gnuastro/neighbors.h>
 #include <gnuastro/linkedlist.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -77,7 +77,7 @@ BF_concmp(unsigned char *byt, long *lab, size_t s0, size_t s1,
      array, then give them the blank labeled array. Note that since
      their value will not be 0, they will also not be labeled. */
   if(anyblank)
-    do *l++ = *b==GAL_FITSARRAY_BYTE_BLANK ? GAL_FITSARRAY_LONG_BLANK
+    do *l++ = *b==GAL_FITS_BYTE_BLANK ? GAL_FITS_LONG_BLANK
          : 0; while(++b<bf);
   else
     memset(lab, 0, size*sizeof *lab);
@@ -311,13 +311,13 @@ removesmallarea_relabel(long *in, unsigned char *byt, 
size_t size,
   if(byt)
     {
       for(i=0;i<size;++i)
-        if(in[i]!=GAL_FITSARRAY_LONG_BLANK)
+        if(in[i]!=GAL_FITS_LONG_BLANK)
           byt[i] = (in[i]=newlabs[in[i]]) > 0;
     }
   else
     {
       for(i=0;i<size;++i)
-        if(in[i]!=GAL_FITSARRAY_LONG_BLANK)
+        if(in[i]!=GAL_FITS_LONG_BLANK)
           in[i]=newlabs[in[i]];
     }
 
diff --git a/src/noisechisel/label.h b/src/noisechisel/label.h
index e0badc7..d849e12 100644
--- a/src/noisechisel/label.h
+++ b/src/noisechisel/label.h
@@ -27,22 +27,21 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 
 
-/* For the GAL_FITSARRAY_LONG_BLANK and GAL_FITSARRAY_BYTE_BLANK macros: */
-#include <gnuastro/fitsarrayvv.h>
+/* For the GAL_FITS_LONG_BLANK and GAL_FITS_BYTE_BLANK macros: */
+#include <gnuastro/fits.h>
 
 
 /* In case the blank value for the long type is negative, the only
    necessary check to see if we are on a label or not is to see if its
-   value is positive. But since we don't want to impose this condition
-   on the fitsarrayvv.h macro (which is used by all Gnuastro programs)
-   we allow for it to be positive through this C preprocessor
-   check. The compiler has no idea of our convention to label things
-   with positive indices, so we can't rely on the compiler to optimize
-   this. */
-#if GAL_FITSARRAY_LONG_BLANK<0
+   value is positive. But since we don't want to impose this condition on
+   the fits.h macro (which is used by all Gnuastro programs) we allow for
+   it to be positive through this C preprocessor check. The compiler has no
+   idea of our convention to label things with positive indices, so we
+   can't rely on the compiler to optimize this. */
+#if GAL_FITS_LONG_BLANK<0
 #define ISINDEXABLELABEL (*lab>0)
 #else
-#define ISINDEXABLELABEL (*lab && *lab!=GAL_FITSARRAY_LONG_BLANK)
+#define ISINDEXABLELABEL (*lab && *lab!=GAL_FITS_LONG_BLANK)
 #endif
 
 
diff --git a/src/noisechisel/main.h b/src/noisechisel/main.h
index 771e5ca..2043a9d 100644
--- a/src/noisechisel/main.h
+++ b/src/noisechisel/main.h
@@ -24,7 +24,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #define MAIN_H
 
 #include <gnuastro/mesh.h>
-#include <gnuastro/fitsarrayvv.h>
+#include <gnuastro/fits.h>
 #include <gnuastro/commonparams.h>
 
 /* Progarm name macros: */
diff --git a/src/noisechisel/noisechisel.c b/src/noisechisel/noisechisel.c
index 0eaddb5..cd65b3e 100644
--- a/src/noisechisel/noisechisel.c
+++ b/src/noisechisel/noisechisel.c
@@ -28,9 +28,9 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <string.h>
 #include <stdlib.h>
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>
 #include <gnuastro/arraymanip.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -61,28 +61,28 @@ makeoutput(struct noisechiselparams *p)
   double *dpt;
   long num[0];
   float *sky=NULL, *std=NULL;
-  struct gal_fitsarray_header_ll *keys=NULL;
+  struct gal_fits_header_ll *keys=NULL;
   size_t s0=p->smp.s0, s1=p->smp.s1;
 
 
   /* First put a copy of the input image. */
-  gal_fitsarray_array_to_fits_img(p->cp.output, "Input", FLOAT_IMG, p->img,
-                                  s0, s1, 0, p->wcs, NULL, SPACK_STRING);
+  gal_fits_array_to_file(p->cp.output, "Input", FLOAT_IMG, p->img,
+                         s0, s1, 0, p->wcs, NULL, SPACK_STRING);
 
 
   /* The object labels image with a keyword mentioning the number of
      objects. */
   num[0]=p->numobjects-1;
-  gal_fitsarray_add_to_fits_header_ll(&keys, TLONG, "NOBJS", 0, num, 0,
+  gal_fits_add_to_fits_header_ll(&keys, TLONG, "NOBJS", 0, num, 0,
                                       "Number of objects in the image.", 0,
                                       NULL);
   dpt=&p->detsn;
-  gal_fitsarray_add_to_fits_header_ll(&keys, TDOUBLE, "DETSN", 0, dpt, 0,
+  gal_fits_add_to_fits_header_ll(&keys, TDOUBLE, "DETSN", 0, dpt, 0,
                                       "Signal to noise of true "
                                       "pseudo-detections.", 0, NULL);
-  gal_fitsarray_array_to_fits_img(p->cp.output, "Objects", LONG_IMG, p->olab,
-                                  s0, s1, p->anyblank, p->wcs, keys,
-                                  SPACK_STRING);
+  gal_fits_array_to_file(p->cp.output, "Objects", LONG_IMG, p->olab,
+                         s0, s1, p->anyblank, p->wcs, keys,
+                         SPACK_STRING);
   keys=NULL;     /* keys was freed after writing. */
 
 
@@ -91,21 +91,21 @@ makeoutput(struct noisechiselparams *p)
      extension filled so the sky and its standard deviation can remain
      on the 3rd and 4th extensions. */
   num[0] = p->detectonly ? 0 : p->numclumps-1;
-  gal_fitsarray_add_to_fits_header_ll(&keys, TLONG, "NCLUMPS", 0, num, 0,
+  gal_fits_add_to_fits_header_ll(&keys, TLONG, "NCLUMPS", 0, num, 0,
                                       "Number of clumps in the image.", 0,
                                       NULL);
   dpt=&p->clumpsn;
-  gal_fitsarray_add_to_fits_header_ll(&keys, TDOUBLE, "CLUMPSN", 0, dpt, 0,
+  gal_fits_add_to_fits_header_ll(&keys, TDOUBLE, "CLUMPSN", 0, dpt, 0,
                                       "Signal to noise of true clumps.", 0,
                                       NULL);
-  gal_fitsarray_array_to_fits_img(p->cp.output, "Clumps", LONG_IMG, p->clab, 
s0,
-                                  s1, p->anyblank, p->wcs, keys, SPACK_STRING);
+  gal_fits_array_to_file(p->cp.output, "Clumps", LONG_IMG, p->clab, s0,
+                         s1, p->anyblank, p->wcs, keys, SPACK_STRING);
   keys=NULL;
 
   /* The sky image: */
   gal_mesh_check_garray(&p->smp, &sky, &std);
-  gal_fitsarray_array_to_fits_img(p->cp.output, "Sky", FLOAT_IMG, sky,
-                                  s0, s1, 0, p->wcs, NULL, SPACK_STRING);
+  gal_fits_array_to_file(p->cp.output, "Sky", FLOAT_IMG, sky,
+                         s0, s1, 0, p->wcs, NULL, SPACK_STRING);
 
 
   /* The sky standard deviation image. Note that since this is a
@@ -114,20 +114,20 @@ makeoutput(struct noisechiselparams *p)
      interpolating or smoothing the image, so we have put a "raw" in
      the comments of each variable.*/
   fpt=&p->maxstd;
-  gal_fitsarray_add_to_fits_header_ll(&keys, TFLOAT, "MAXSTD", 0, fpt, 0,
+  gal_fits_add_to_fits_header_ll(&keys, TFLOAT, "MAXSTD", 0, fpt, 0,
                                       "Maximum raw mesh sky standard "
                                       "deviation.", 0, NULL);
   fpt=&p->minstd;
-  gal_fitsarray_add_to_fits_header_ll(&keys, TFLOAT, "MINSTD", 0, fpt, 0,
+  gal_fits_add_to_fits_header_ll(&keys, TFLOAT, "MINSTD", 0, fpt, 0,
                                       "Minimum raw mesh sky standard "
                                       "deviation.", 0, NULL);
   fpt=&p->medstd;
-  gal_fitsarray_add_to_fits_header_ll(&keys, TFLOAT, "MEDSTD", 0, fpt, 0,
+  gal_fits_add_to_fits_header_ll(&keys, TFLOAT, "MEDSTD", 0, fpt, 0,
                                       "Median raw mesh standard "
                                       "deviation.", 0, NULL);
-  gal_fitsarray_array_to_fits_img(p->cp.output, "Standard deviation",
-                                  FLOAT_IMG, std, s0, s1, 0, p->wcs,
-                                  keys, SPACK_STRING);
+  gal_fits_array_to_file(p->cp.output, "Standard deviation",
+                         FLOAT_IMG, std, s0, s1, 0, p->wcs,
+                         keys, SPACK_STRING);
   keys=NULL;
 
 
@@ -157,12 +157,12 @@ noisechisel(struct noisechiselparams *p)
   gal_mesh_spatial_convolve_on_mesh(smp, &p->conv);
   if(p->detectionname)
     {
-      gal_fitsarray_array_to_fits_img(p->detectionname, "Input", FLOAT_IMG,
-                                      smp->img, s0, s1, p->anyblank, p->wcs,
-                                      NULL, SPACK_STRING);
-      gal_fitsarray_array_to_fits_img(p->detectionname, "Convolved", FLOAT_IMG,
-                                      p->conv, s0, s1, p->anyblank, p->wcs,
-                                      NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->detectionname, "Input", FLOAT_IMG,
+                             smp->img, s0, s1, p->anyblank, p->wcs,
+                             NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->detectionname, "Convolved", FLOAT_IMG,
+                             p->conv, s0, s1, p->anyblank, p->wcs,
+                             NULL, SPACK_STRING);
     }
   if(verb) gal_timing_report(&t1, "Convolved with kernel.", 1);
 
@@ -220,25 +220,25 @@ noisechisel(struct noisechiselparams *p)
         }
     }
   if(p->detectionname)
-    gal_fitsarray_array_to_fits_img(p->detectionname, "Dilated", LONG_IMG,
-                                    p->olab, s0, s1, p->anyblank, p->wcs,
-                                    NULL, SPACK_STRING);
+    gal_fits_array_to_file(p->detectionname, "Dilated", LONG_IMG,
+                           p->olab, s0, s1, p->anyblank, p->wcs,
+                           NULL, SPACK_STRING);
   if(p->maskdetname)
     {
-      gal_fitsarray_array_to_fits_img(p->maskdetname, "Input", FLOAT_IMG,
-                                      p->img, s0, s1, p->anyblank, p->wcs,
-                                      NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->maskdetname, "Input", FLOAT_IMG,
+                             p->img, s0, s1, p->anyblank, p->wcs,
+                             NULL, SPACK_STRING);
       gal_arraymanip_float_copy(p->img, s0*s1, &imgcopy);
       maskbackorforeground(imgcopy, s0*s1, p->byt, 0);
-      gal_fitsarray_array_to_fits_img(p->maskdetname, "Undetected masked",
-                                      FLOAT_IMG, imgcopy, s0, s1, p->anyblank,
-                                      p->wcs, NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->maskdetname, "Undetected masked",
+                             FLOAT_IMG, imgcopy, s0, s1, p->anyblank,
+                             p->wcs, NULL, SPACK_STRING);
       free(imgcopy);
       gal_arraymanip_float_copy(p->img, s0*s1, &imgcopy);
       maskbackorforeground(imgcopy, s0*s1, p->byt, 1);
-      gal_fitsarray_array_to_fits_img(p->maskdetname, "Detected masked",
-                                      FLOAT_IMG, imgcopy, s0, s1, p->anyblank,
-                                      p->wcs, NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->maskdetname, "Detected masked",
+                             FLOAT_IMG, imgcopy, s0, s1, p->anyblank,
+                             p->wcs, NULL, SPACK_STRING);
       free(imgcopy);
     }
 
diff --git a/src/noisechisel/segmentation.c b/src/noisechisel/segmentation.c
index abf31f3..4130d6d 100644
--- a/src/noisechisel/segmentation.c
+++ b/src/noisechisel/segmentation.c
@@ -28,9 +28,9 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <string.h>
 #include <stdlib.h>
 
+#include <gnuastro/fits.h>
 #include <gnuastro/qsort.h>
 #include <gnuastro/neighbors.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -734,7 +734,7 @@ clabwithnoseg(long *olab, long *clab, size_t size, int 
anyblank)
 
   if(anyblank)
     do
-      *clab++ = ( *olab==GAL_FITSARRAY_LONG_BLANK ? GAL_FITSARRAY_LONG_BLANK
+      *clab++ = ( *olab==GAL_FITS_LONG_BLANK ? GAL_FITS_LONG_BLANK
                   : ( *olab>0 ? SEGMENTINIT : 0 ) );
     while(++olab<end);
   else
@@ -770,16 +770,16 @@ segmentation(struct noisechiselparams *p)
   /* Start the steps image: */
   if(segmentationname)
     {
-      gal_fitsarray_array_to_fits_img(segmentationname, "Input", FLOAT_IMG,
-                                      p->img, s0, s1, p->anyblank, p->wcs,
-                                      NULL, SPACK_STRING);
-      gal_fitsarray_array_to_fits_img(segmentationname,
-                                      "Convolved-SkySubtracted", FLOAT_IMG,
-                                      p->conv, s0, s1, p->anyblank, p->wcs,
-                                      NULL, SPACK_STRING);
-      gal_fitsarray_array_to_fits_img(segmentationname, "InitialLabels",
-                                      LONG_IMG, p->olab, s0, s1, p->anyblank,
-                                      p->wcs, NULL, SPACK_STRING);
+      gal_fits_array_to_file(segmentationname, "Input", FLOAT_IMG,
+                             p->img, s0, s1, p->anyblank, p->wcs,
+                             NULL, SPACK_STRING);
+      gal_fits_array_to_file(segmentationname,
+                             "Convolved-SkySubtracted", FLOAT_IMG,
+                             p->conv, s0, s1, p->anyblank, p->wcs,
+                             NULL, SPACK_STRING);
+      gal_fits_array_to_file(segmentationname, "InitialLabels",
+                             LONG_IMG, p->olab, s0, s1, p->anyblank,
+                             p->wcs, NULL, SPACK_STRING);
     }
 
 
@@ -792,7 +792,7 @@ segmentation(struct noisechiselparams *p)
   if(p->anyblank)
     {
       b=p->byt;lf=(l=p->clab)+s0*s1;
-      do *l = *b++==GAL_FITSARRAY_BYTE_BLANK ? GAL_FITSARRAY_LONG_BLANK
+      do *l = *b++==GAL_FITS_BYTE_BLANK ? GAL_FITS_LONG_BLANK
            : 0; while(++l<lf);
     }
   else
@@ -805,10 +805,10 @@ segmentation(struct noisechiselparams *p)
   findclumpsn(p);
   if(p->segmentationname)
     {
-      gal_fitsarray_array_to_fits_img(p->segmentationname,
-                                      "Noise Oversegmentaion", LONG_IMG,
-                                      p->clab, p->smp.s0, p->smp.s1,
-                                      p->anyblank, p->wcs, NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->segmentationname,
+                             "Noise Oversegmentaion", LONG_IMG,
+                             p->clab, p->smp.s0, p->smp.s1,
+                             p->anyblank, p->wcs, NULL, SPACK_STRING);
     }
 
 
@@ -817,7 +817,7 @@ segmentation(struct noisechiselparams *p)
   if(p->anyblank)
     {
       lf=(l=p->clab)+s0*s1;
-      do *l = *l==GAL_FITSARRAY_LONG_BLANK ? GAL_FITSARRAY_LONG_BLANK
+      do *l = *l==GAL_FITS_LONG_BLANK ? GAL_FITS_LONG_BLANK
            : 0; while(++l<lf);
     }
   else memset(p->clab, 0, s0*s1*sizeof *p->clab);
@@ -843,7 +843,7 @@ segmentation(struct noisechiselparams *p)
           if(p->anyblank)
             {
               lf=(l=p->clab)+s0*s1;
-              do *l = *l==GAL_FITSARRAY_LONG_BLANK ? GAL_FITSARRAY_LONG_BLANK
+              do *l = *l==GAL_FITS_LONG_BLANK ? GAL_FITS_LONG_BLANK
                    : 0; while(++l<lf);
             }
           else memset(p->clab, 0, s0*s1*sizeof *p->clab);
@@ -873,10 +873,10 @@ segmentation(struct noisechiselparams *p)
                     "unrecognized value of %d", PACKAGE_BUGREPORT,
                     p->stepnum);
             }
-          gal_fitsarray_array_to_fits_img(p->segmentationname, extname,
-                                          LONG_IMG, forfits, s0, s1,
-                                          p->anyblank, p->wcs, NULL,
-                                          SPACK_STRING);
+          gal_fits_array_to_file(p->segmentationname, extname,
+                                 LONG_IMG, forfits, s0, s1,
+                                 p->anyblank, p->wcs, NULL,
+                                 SPACK_STRING);
           ++p->stepnum;
         }
     }
diff --git a/src/noisechisel/sky.c b/src/noisechisel/sky.c
index 018bd04..285429a 100644
--- a/src/noisechisel/sky.c
+++ b/src/noisechisel/sky.c
@@ -133,8 +133,8 @@ findavestdongrid(struct noisechiselparams *p, char *outname)
   if(outname)
     {
       if(smp->meshbasedcheck==0)
-        gal_fitsarray_array_to_fits_img(outname, "Detected", BYTE_IMG, p->byt,
-                                        s0, s1, 0, p->wcs, NULL, SPACK_STRING);
+        gal_fits_array_to_file(outname, "Detected", BYTE_IMG, p->byt,
+                               s0, s1, 0, p->wcs, NULL, SPACK_STRING);
       gal_mesh_value_file(smp, outname, "Calculated Sky", "Calculated Sky STD",
                           p->wcs, SPACK_STRING);
     }
diff --git a/src/noisechisel/thresh.c b/src/noisechisel/thresh.c
index 2e2b531..950b78c 100644
--- a/src/noisechisel/thresh.c
+++ b/src/noisechisel/thresh.c
@@ -274,7 +274,7 @@ applydetectionthresholdskysub(struct noisechiselparams *p)
                  image, they will be checked. */
               *b = ( (*f++=*in-sky) > dthresh*std
                      ? 1
-                     : isnan(*in) ? GAL_FITSARRAY_BYTE_BLANK : 0 );
+                     : isnan(*in) ? GAL_FITS_BYTE_BLANK : 0 );
               ++in;
             }
           while(++b<bf);
diff --git a/src/noisechisel/ui.c b/src/noisechisel/ui.c
index 73a6387..583bc34 100644
--- a/src/noisechisel/ui.c
+++ b/src/noisechisel/ui.c
@@ -32,6 +32,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 #include <nproc.h>              /* From Gnulib.                     */
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>    /* includes time.h and sys/time.h   */
 #include <gnuastro/checkset.h>
 #include <gnuastro/txtarrayvv.h>
@@ -39,7 +40,6 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro/arraymanip.h>
 #include <gnuastro/statistics.h>
 #include <gnuastro/configfiles.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -686,7 +686,7 @@ sanitycheck(struct noisechiselparams *p)
   gal_checkset_check_file(p->up.inputname);
 
   /* Set the maskname and mask hdu accordingly: */
-  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
+  gal_fits_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
                                  &p->up.maskname, p->up.mhdu, p->up.mhduset,
                                  "mask");
 
@@ -869,11 +869,10 @@ preparearrays(struct noisechiselparams *p)
      done on the convolved image and some on the actual image, we will
      need to change the mesh's img value some times and the p->img
      will be used to keep its actual value. */
-  gal_fitsarray_file_to_float(p->up.inputname, p->up.maskname, p->cp.hdu,
+  gal_fits_file_to_float(p->up.inputname, p->up.maskname, p->cp.hdu,
                               p->up.mhdu, (float **)&smp->img, &p->bitpix,
                               &p->anyblank, &smp->s0, &smp->s1);
-  gal_fitsarray_read_fits_wcs(p->up.inputname, p->cp.hdu, 0, 0,
-                              &p->nwcs, &p->wcs);
+  gal_fits_read_wcs(p->up.inputname, p->cp.hdu, 0, 0, &p->nwcs, &p->wcs);
   s0=smp->s0; s1=smp->s1;
 
   /* make sure the channel sizes fit the channel sizes. */
@@ -908,7 +907,7 @@ preparearrays(struct noisechiselparams *p)
 
   /* Read the kernel: */
   if(p->up.kernelnameset)
-    gal_fitsarray_prep_float_kernel(p->up.kernelname, p->up.khdu, &smp->kernel,
+    gal_fits_prep_float_kernel(p->up.kernelname, p->up.khdu, &smp->kernel,
                                     &smp->ks0, &smp->ks1);
   else
     {
@@ -977,18 +976,18 @@ preparearrays(struct noisechiselparams *p)
   gal_mesh_make_mesh(lmp);
   if(p->meshname)
     {
-      gal_fitsarray_array_to_fits_img(p->meshname, "Input", FLOAT_IMG,
-                                      smp->img, s0, s1, p->anyblank, p->wcs,
-                                      NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->meshname, "Input", FLOAT_IMG,
+                             smp->img, s0, s1, p->anyblank, p->wcs,
+                             NULL, SPACK_STRING);
       gal_check_mesh_id(smp, &meshindexs);
-      gal_fitsarray_array_to_fits_img(p->meshname, "SmallMeshIndexs",
-                                      LONG_IMG, meshindexs, s0, s1, 0, p->wcs,
-                                      NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->meshname, "SmallMeshIndexs",
+                             LONG_IMG, meshindexs, s0, s1, 0, p->wcs,
+                             NULL, SPACK_STRING);
       free(meshindexs);
       gal_check_mesh_id(lmp, &meshindexs);
-      gal_fitsarray_array_to_fits_img(p->meshname, "LargeMeshIndexs", LONG_IMG,
-                                      meshindexs, s0, s1, 0, p->wcs,
-                                      NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->meshname, "LargeMeshIndexs", LONG_IMG,
+                             meshindexs, s0, s1, 0, p->wcs,
+                             NULL, SPACK_STRING);
       free(meshindexs);
     }
 }
diff --git a/src/subtractsky/Makefile.am b/src/subtractsky/Makefile.am
index 647c9fa..8d3935c 100644
--- a/src/subtractsky/Makefile.am
+++ b/src/subtractsky/Makefile.am
@@ -29,7 +29,7 @@ astsubtractsky_SOURCES = main.c main.h cite.h ui.c ui.h 
args.h        \
 subtractsky.c subtractsky.h
 
 astsubtractsky_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la      \
--lgalconfigfiles -lgalfitsarrayvv -lgalcheckset -lgaltiming -lgalmesh  \
+-lgalconfigfiles -lgalfits -lgalcheckset -lgaltiming -lgalmesh         \
 -lgalspatialconvolve -lgalthreads -lgalmode -lgalstatistics            \
 -lgalarraymanip -lgalqsort -lgallinkedlist -lgalbox
 
diff --git a/src/subtractsky/args.h b/src/subtractsky/args.h
index 860f46e..7d1bb72 100644
--- a/src/subtractsky/args.h
+++ b/src/subtractsky/args.h
@@ -446,7 +446,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
     case ARGP_KEY_ARG:
 
       /* See what type of input value it is and put it in. */
-      if( gal_fitsarray_name_is_fits(arg) )
+      if( gal_fits_name_is_fits(arg) )
         {
           if(p->up.inputname)
             argp_error(state, "only one input image should be given");
diff --git a/src/subtractsky/main.h b/src/subtractsky/main.h
index 7f85d89..266befa 100644
--- a/src/subtractsky/main.h
+++ b/src/subtractsky/main.h
@@ -24,7 +24,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #define MAIN_H
 
 #include <gnuastro/mesh.h>
-#include <gnuastro/fitsarrayvv.h>
+#include <gnuastro/fits.h>
 #include <gnuastro/commonparams.h>
 
 /* Progarm name macros: */
diff --git a/src/subtractsky/subtractsky.c b/src/subtractsky/subtractsky.c
index 040dca5..5ada80c 100644
--- a/src/subtractsky/subtractsky.c
+++ b/src/subtractsky/subtractsky.c
@@ -27,13 +27,13 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <error.h>
 #include <stdlib.h>
 
+#include <gnuastro/fits.h>
 #include <gnuastro/mesh.h>
 #include <gnuastro/mode.h>
 #include <gnuastro/qsort.h>
 #include <gnuastro/timing.h>
 #include <gnuastro/statistics.h>
 #include <gnuastro/arraymanip.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -159,12 +159,12 @@ subtractsky(struct subtractskyparams *p)
   if(p->meshname)
     {
       gal_check_mesh_id(mp, &meshindexs);
-      gal_fitsarray_array_to_fits_img(p->meshname, "Input", FLOAT_IMG,
-                                      p->mp.img, s0, s1, p->anyblank, p->wcs,
-                                      NULL, SPACK_STRING);
-      gal_fitsarray_array_to_fits_img(p->meshname, "MeshIndexs", LONG_IMG,
-                                      meshindexs, s0, s1, 0, p->wcs,
-                                      NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->meshname, "Input", FLOAT_IMG,
+                             p->mp.img, s0, s1, p->anyblank, p->wcs,
+                             NULL, SPACK_STRING);
+      gal_fits_array_to_file(p->meshname, "MeshIndexs", LONG_IMG,
+                             meshindexs, s0, s1, 0, p->wcs,
+                             NULL, SPACK_STRING);
       free(meshindexs);
     }
   if(p->cp.verb) gal_timing_report(&t1, "Mesh grid ready.", 1);
@@ -177,12 +177,12 @@ subtractsky(struct subtractskyparams *p)
       gal_mesh_spatial_convolve_on_mesh(mp, &p->conv);
       if(p->convname)
         {
-          gal_fitsarray_array_to_fits_img(p->convname, "Input", FLOAT_IMG,
-                                          p->mp.img, s0, s1, p->anyblank,
-                                          p->wcs, NULL, SPACK_STRING);
-          gal_fitsarray_array_to_fits_img(p->convname, "Input", FLOAT_IMG,
-                                          p->conv, s0, s1, p->anyblank, p->wcs,
-                                          NULL, SPACK_STRING);
+          gal_fits_array_to_file(p->convname, "Input", FLOAT_IMG,
+                                 p->mp.img, s0, s1, p->anyblank,
+                                 p->wcs, NULL, SPACK_STRING);
+          gal_fits_array_to_file(p->convname, "Input", FLOAT_IMG,
+                                 p->conv, s0, s1, p->anyblank, p->wcs,
+                                 NULL, SPACK_STRING);
         }
     }
   else p->conv=p->mp.img;
@@ -231,9 +231,9 @@ subtractsky(struct subtractskyparams *p)
   /* Subtract the sky value */
   gal_arraymanip_fmultip_const(sky, s0*s1, -1.0f);
   skysubtracted=gal_arraymanip_fsum_arrays(mp->img, sky, s0*s1);
-  gal_fitsarray_array_to_fits_img(p->cp.output ,"SkySubtracted", FLOAT_IMG,
-                                  skysubtracted, s0, s1, p->anyblank, p->wcs,
-                                  NULL, SPACK_STRING);
+  gal_fits_array_to_file(p->cp.output ,"SkySubtracted", FLOAT_IMG,
+                         skysubtracted, s0, s1, p->anyblank, p->wcs,
+                         NULL, SPACK_STRING);
 
 
   /* Clean up: */
diff --git a/src/subtractsky/ui.c b/src/subtractsky/ui.c
index 72c5943..7fe97a8 100644
--- a/src/subtractsky/ui.c
+++ b/src/subtractsky/ui.c
@@ -32,6 +32,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 #include <nproc.h>              /* From Gnulib.                     */
 
+#include <gnuastro/fits.h>
 #include <gnuastro/timing.h>           /* Includes time.h and sys/time.h   */
 #include <gnuastro/checkset.h>
 #include <gnuastro/txtarrayvv.h>
@@ -39,7 +40,6 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro/arraymanip.h>
 #include <gnuastro/commonargs.h>
 #include <gnuastro/configfiles.h>
-#include <gnuastro/fitsarrayvv.h>
 
 #include "main.h"
 
@@ -457,7 +457,7 @@ sanitycheck(struct subtractskyparams *p)
   gal_checkset_check_file(p->up.inputname);
 
   /* Set the maskname and mask hdu accordingly: */
-  gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
+  gal_fits_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.masknameset,
                                  &p->up.maskname, p->up.mhdu, p->up.mhduset,
                                  "mask");
 
@@ -533,15 +533,14 @@ preparearrays(struct subtractskyparams *p)
   struct gal_mesh_params *mp=&p->mp;
 
   /* Read the input image. */
-  gal_fitsarray_file_to_float(p->up.inputname, p->up.maskname, p->cp.hdu,
+  gal_fits_file_to_float(p->up.inputname, p->up.maskname, p->cp.hdu,
                               p->up.mhdu, (float **)&p->mp.img, &p->bitpix,
                               &p->anyblank, &mp->s0, &mp->s1);
-  gal_fitsarray_read_fits_wcs(p->up.inputname, p->cp.hdu, 0, 0,
-                              &p->nwcs, &p->wcs);
+  gal_fits_read_wcs(p->up.inputname, p->cp.hdu, 0, 0, &p->nwcs, &p->wcs);
 
   /* Read the kernel: */
   if(p->up.kernelnameset)
-    gal_fitsarray_prep_float_kernel(p->up.kernelname, p->up.khdu, &mp->kernel,
+    gal_fits_prep_float_kernel(p->up.kernelname, p->up.khdu, &mp->kernel,
                                     &mp->ks0, &mp->ks1);
 
   /* Check if the input sizes and channel sizes are exact



reply via email to

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