gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master c10c4be 002/125: Moved type code and alloc fun


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master c10c4be 002/125: Moved type code and alloc functions into data.h
Date: Sun, 23 Apr 2017 22:36:24 -0400 (EDT)

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

    Moved type code and alloc functions into data.h
    
    The function to allocate an array for a given datatype and that for
    allocating a blank value were moved to `data.h' from `fits.h', also the
    basic variable for specifying type was changed from `datatype' to `type'
    (from `data.h').
    
    New functions:
     gal_data_alloc
     gal_data_sizeof
     gal_data_alloc_blank
     gal_fits_tform_to_type
     gal_fits_bitpix_to_type
     gal_fits_type_to_datatype
     gal_fits_datatype_to_type
    
    Deleted functions:
     gal_fits_datatype_size
     gal_fits_datatype_alloc
     gal_fits_datatype_blank
     gal_fits_tform_to_datatype
     gal_fits_bitpix_to_datatype
---
 bin/imgcrop/crop.c  |  37 ++--
 bin/imgcrop/ui.c    |   7 +-
 bin/table/table.c   |  10 +-
 bin/table/ui.c      |  13 +-
 lib/Makefile.am     |   6 +-
 lib/data.c          | 256 ++++++++++++++++++++++++++++
 lib/fits.c          | 473 ++++++++++++++--------------------------------------
 lib/gnuastro/data.h |  56 +++++--
 lib/gnuastro/fits.h |  38 +++--
 9 files changed, 481 insertions(+), 415 deletions(-)

diff --git a/bin/imgcrop/crop.c b/bin/imgcrop/crop.c
index 3bdebf4..60f9b53 100644
--- a/bin/imgcrop/crop.c
+++ b/bin/imgcrop/crop.c
@@ -295,9 +295,10 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
   float *fb, *fa=array;
   LONGLONG *Lb, *La=array;
   unsigned char *bb, *ba=array;
+  int outpolygon=crp->p->outpolygon;
   double *db, *ipolygon, point[2], *da=array;
+  int type=gal_fits_datatype_to_type(crp->p->datatype);
   size_t i, *ordinds, size=s0*s1, nvertices=crp->p->nvertices;
-  int outpolygon=crp->p->outpolygon, datatype=crp->p->datatype;
 
 
   /* First of all, allocate enough space to put a copy of the input
@@ -326,10 +327,10 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
 
   /* Go over all the pixels in the image and if they are within the
      polygon keep them if the user has asked for it.*/
-  switch(datatype)
+  switch(type)
     {
-    case TBYTE:
-      bb=gal_fits_datatype_blank(datatype);
+    case GAL_DATA_TYPE_UCHAR:
+      bb=gal_data_alloc_blank(type);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
@@ -338,8 +339,8 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
         }
       free(bb);
       break;
-    case TSHORT:
-      sb=gal_fits_datatype_blank(datatype);
+    case GAL_DATA_TYPE_SHORT:
+      sb=gal_data_alloc_blank(type);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
@@ -348,8 +349,8 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
         }
       free(sb);
       break;
-    case TLONG:
-      lb=gal_fits_datatype_blank(datatype);
+    case GAL_DATA_TYPE_LONG:
+      lb=gal_data_alloc_blank(type);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
@@ -358,8 +359,8 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
         }
       free(lb);
       break;
-    case TLONGLONG:
-      Lb=gal_fits_datatype_blank(datatype);
+    case GAL_DATA_TYPE_LONGLONG:
+      Lb=gal_data_alloc_blank(type);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
@@ -368,8 +369,8 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
         }
       free(Lb);
       break;
-    case TFLOAT:
-      fb=gal_fits_datatype_blank(datatype);
+    case GAL_DATA_TYPE_FLOAT:
+      fb=gal_data_alloc_blank(type);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
@@ -378,8 +379,8 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
         }
       free(fb);
       break;
-    case TDOUBLE:
-      db=gal_fits_datatype_blank(datatype);
+    case GAL_DATA_TYPE_DOUBLE:
+      db=gal_data_alloc_blank(type);
       for(i=0;i<size;++i)
         {
           point[0]=i%s1+1; point[1]=i/s1+1;
@@ -391,8 +392,8 @@ polygonmask(struct cropparams *crp, void *array, long 
*fpixel_i,
     default:
       error(EXIT_FAILURE, 0, "a bug! Please contact us at %s, so we "
             "can fix the problem. For some reason, an unrecognized "
-            "datatype value (%d) has been seen in polygonmask (crop.c)",
-            PACKAGE_BUGREPORT, datatype);
+            "type value (%d) has been seen in polygonmask (crop.c)",
+            PACKAGE_BUGREPORT, type);
     }
 
   /* Clean up: */
@@ -714,7 +715,7 @@ 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_fits_datatype_alloc(cropsize, p->datatype);
+      array=gal_data_alloc(gal_fits_datatype_to_type(p->datatype), cropsize);
       status=0;
       if(fits_read_subset(ifp, p->datatype, fpixel_i, lpixel_i, inc,
                           p->bitnul, array, &anynul, &status))
@@ -829,7 +830,7 @@ iscenterfilled(struct cropparams *crp)
 
   /* Allocate the array and read in the pixels. */
   size=checkcenter*checkcenter;
-  array=gal_fits_datatype_alloc(size, gal_fits_bitpix_to_datatype(bitpix) );
+  array=gal_data_alloc(gal_fits_bitpix_to_type(bitpix), size);
   if( fits_read_subset(ofp, p->datatype, fpixel, lpixel, inc,
                        p->bitnul, array, &anynul, &status) )
     gal_fits_io_error(status, NULL);
diff --git a/bin/imgcrop/ui.c b/bin/imgcrop/ui.c
index 5379942..8346167 100644
--- a/bin/imgcrop/ui.c
+++ b/bin/imgcrop/ui.c
@@ -582,7 +582,7 @@ preparearrays(struct imgcropparams *p)
   fitsfile *tmpfits;
   struct timeval t1;
   struct inputimgs *img;
-  int i, status, firstbitpix=0;
+  int i, type, status, firstbitpix=0;
   char msg[GAL_TIMING_VERB_MSG_LENGTH_V];
 
   if(p->cp.verb) gettimeofday(&t1, NULL);
@@ -634,8 +634,9 @@ preparearrays(struct imgcropparams *p)
       if(firstbitpix==0)
         {
           firstbitpix=p->bitpix;
-          p->datatype=gal_fits_bitpix_to_datatype(p->bitpix);
-          p->bitnul=gal_fits_datatype_blank(p->datatype);
+          type=gal_fits_bitpix_to_type(p->bitpix);
+          p->bitnul = gal_data_alloc_blank(type);
+          p->datatype = gal_fits_type_to_datatype(type);
         }
       else if(firstbitpix!=p->bitpix)
         error(EXIT_FAILURE, 0, "%s: BITPIX=%d. Previous images had a "
diff --git a/bin/table/table.c b/bin/table/table.c
index c95521f..4bcaedd 100644
--- a/bin/table/table.c
+++ b/bin/table/table.c
@@ -159,7 +159,7 @@ readinputcols(struct tableparams *p)
 {
   double *colfromtxt;
   struct outcolumn *col;
-  int datatype, status=0;
+  int type, status=0;
   size_t i, j, nrows=p->nrows, incols=p->up.ncols;
 
   /* Get the contents of each table column: */
@@ -168,20 +168,20 @@ readinputcols(struct tableparams *p)
       /* Variables for simple reading */
       col=&p->ocols[i];
 
-      datatype=col->datatype;
+      type=gal_fits_datatype_to_type(col->datatype);
 
       /* Allocate the blank value for this column. Note that we will also
          need the blankvalue for a text file when outputing to a FITS. */
-      col->nulval=gal_fits_datatype_blank(datatype);
+      col->nulval=gal_data_alloc_blank(type);
 
       /* Read the input column. */
       if(p->fitsptr)
         {
           /* Allocate space for the data in this column */
-          col->data=gal_fits_datatype_alloc(nrows, datatype);
+          col->data=gal_data_alloc(type, nrows);
 
           /* Call CFITSIO to read the column information. */
-          fits_read_col(p->fitsptr, datatype, col->inindex+1, 1, 1,
+          fits_read_col(p->fitsptr, col->datatype, col->inindex+1, 1, 1,
                         nrows, col->nulval, col->data, &col->anynul,
                         &status);
         }
diff --git a/bin/table/ui.c b/bin/table/ui.c
index c7b8fd5..42e4ace 100644
--- a/bin/table/ui.c
+++ b/bin/table/ui.c
@@ -447,7 +447,7 @@ void
 allfitscolinfo(struct tableparams *p)
 {
   char *tailptr;
-  int i, status=0;
+  int i, status=0, type;
   struct uiparams *up=&p->up;
   size_t index, ncols=p->up.ncols;
   char keyname[FLEN_KEYWORD]="XXXXXXXXXXXXX", value[FLEN_VALUE];
@@ -486,8 +486,9 @@ allfitscolinfo(struct tableparams *p)
           index=strtoul(&keyname[5], &tailptr, 10)-1;
           if(index<ncols)
             {
+              type=gal_fits_tform_to_type(value[1]);
+              up->datatype[index]=gal_fits_type_to_datatype(type);
               gal_checkset_allocate_copy(&value[1], &up->ttstr[index] );
-              up->datatype[index]=gal_fits_tform_to_datatype(value[1]);
             }
         }
       else if(strncmp(keyname, "TTYPE", 5)==0)
@@ -871,10 +872,12 @@ outputcolumns(struct tableparams *p)
   i=p->nocols-1;
   while(colsll)
     {
+      int type;
       gal_linkedlist_pop_from_sll(&colsll, &inindex);
       p->ocols[i].inindex=inindex;
       p->ocols[i].datatype=up->datatype[inindex];
-      p->ocols[i].esize=gal_fits_datatype_size(up->datatype[inindex]);
+      type=gal_fits_datatype_to_type(p->ocols[i].datatype);
+      p->ocols[i].esize=gal_data_sizeof(type);
       --i;
     }
 }
@@ -906,9 +909,11 @@ preparearrays(struct tableparams *p)
               p->nocols * sizeof *p->ocols);
       for(i=0;i<p->nocols;++i)
         {
+          int type;
           p->ocols[i].inindex=i;
           p->ocols[i].datatype=up->datatype[i];
-          p->ocols[i].esize=gal_fits_datatype_size(p->ocols[i].datatype);
+          type=gal_fits_datatype_to_type(p->ocols[i].datatype);
+          p->ocols[i].esize=gal_data_sizeof(type);
         }
     }
 }
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 9e2d6cc..136a449 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -31,9 +31,9 @@ libgnuastro_la_LDFLAGS = -version-info $(GAL_LT_VERSION)
 
 
 # Specify the library .c files
-libgnuastro_la_SOURCES = array.c box.c checkset.c configfiles.c fits.c  \
-  git.c linkedlist.c mesh.c mode.c polygon.c qsort.c spatialconvolve.c  \
-  statistics.c threads.c timing.c txtarray.c wcs.c
+libgnuastro_la_SOURCES = array.c box.c checkset.c configfiles.c data.c  \
+  fits.c git.c linkedlist.c mesh.c mode.c polygon.c qsort.c             \
+  spatialconvolve.c statistics.c threads.c timing.c txtarray.c wcs.c
 
 
 # Installed headers, note that we are not blindly including all `.h' files
diff --git a/lib/data.c b/lib/data.c
new file mode 100644
index 0000000..8d3291a
--- /dev/null
+++ b/lib/data.c
@@ -0,0 +1,256 @@
+/*********************************************************************
+data -- Structure and functions to represent/work with data
+This is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+     Mohammad Akhlaghi <address@hidden>
+Contributing author(s):
+Copyright (C) 2016, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+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 <errno.h>
+#include <error.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <gnuastro/data.h>
+
+
+
+
+
+
+
+
+
+
+/*********************************************************************/
+/*************      Type size and allocation       *******************/
+/*********************************************************************/
+size_t
+gal_data_sizeof(int type)
+{
+  /* Allocate space for the array to keep the image. */
+  switch(type)
+    {
+    case GAL_DATA_TYPE_BIT:
+      error(EXIT_FAILURE, 0, "Currently Gnuastro doesn't support TBIT "
+            "datatype, please get in touch with us to implement it.");
+
+      /* The parenthesis after sizeof is not a function, it is actually a
+         type cast, so we have put a space between size of and the
+         parenthesis to highlight this. In C, `sizeof' is an operator, not
+         a function.*/
+    case GAL_DATA_TYPE_UCHAR:
+      return sizeof (unsigned char);
+
+    case GAL_DATA_TYPE_LOGICAL: case GAL_DATA_TYPE_CHAR:
+      return sizeof (char);
+
+    case GAL_DATA_TYPE_STRING:
+      return sizeof (char *);
+
+    case GAL_DATA_TYPE_USHORT:
+      return sizeof (unsigned short);
+
+    case GAL_DATA_TYPE_SHORT:
+      return sizeof (short);
+
+    case GAL_DATA_TYPE_UINT:
+      return sizeof (unsigned int);
+
+    case GAL_DATA_TYPE_INT:
+      return sizeof (int);
+
+    case GAL_DATA_TYPE_ULONG:
+      return sizeof (unsigned long);
+
+    case GAL_DATA_TYPE_LONG:
+      return sizeof (long);
+
+    case GAL_DATA_TYPE_LONGLONG:
+      return sizeof (long long);
+
+    case GAL_DATA_TYPE_FLOAT:
+      if( sizeof (float) != 4 )
+        error(EXIT_FAILURE, 0, "`float` is not 32 bits on this machine");
+      return sizeof (float);
+
+    case GAL_DATA_TYPE_DOUBLE:
+      if( sizeof (double) != 8 )
+        error(EXIT_FAILURE, 0, "`double` is not 64 bits on this machine");
+      return sizeof (double);
+
+    case GAL_DATA_TYPE_COMPLEX:
+      if( sizeof (float) != 4 )
+        error(EXIT_FAILURE, 0, "`float` is not 32 bits on this machine");
+      return sizeof (gsl_complex_float);
+
+    case GAL_DATA_TYPE_DCOMPLEX:
+      if( sizeof (double) != 8 )
+        error(EXIT_FAILURE, 0, "`double` is not 64 bits on this machine");
+      return sizeof (gsl_complex);
+
+    default:
+      error(EXIT_FAILURE, 0, "type value of %d not recognized in "
+            "gal_data_sizeof", type);
+    }
+
+  error(EXIT_FAILURE, 0, "Control has reached the end of `gal_data_sizeof' "
+        "This is a bug! Please contact us at %s so we can find the cause of "
+        "the problem.", PACKAGE_BUGREPORT);
+  return -1;
+}
+
+
+
+
+
+/* Allocate an array based on the value of type. Note that the argument
+   `size' is the number of elements, necessary in the array, the number of
+   bytes each element needs will be determined internaly by this function
+   using the datatype argument, so you don't have to worry about it. */
+void *
+gal_data_alloc(int type, size_t size)
+{
+  void *array;
+
+  errno=0;
+  array=malloc( size * gal_data_sizeof(type) );
+  if(array==NULL)
+    error(EXIT_FAILURE, errno, "array of %zu bytes in gal_data_alloc",
+          size * gal_data_sizeof(type));
+
+  return array;
+}
+
+
+
+
+
+void *
+gal_data_alloc_blank(int type)
+{
+  /* Define the pointers. */
+  void *allocated;
+  unsigned char *b;
+  char *c;
+  char **str;
+  unsigned short *us;
+  short *s;
+  unsigned int *ui;
+  int *i;
+  unsigned long *ul;
+  long *l;
+  long long *L;
+  float *f;
+  double *d;
+  gsl_complex_float *cx;
+  gsl_complex *dcx;
+
+  /* Allocate the space for the blank value: */
+  allocated=gal_data_alloc(1, type);
+
+  /* Put the blank value into it. */
+  errno=0;
+  switch(type)
+    {
+    case GAL_DATA_TYPE_BIT:
+      error(EXIT_FAILURE, 0, "Currently Gnuastro doesn't support blank "
+            "values for `GAL_DATA_TYPE_BIT', please get in touch with "
+            "us to see how we can implement it.");
+
+    case GAL_DATA_TYPE_UCHAR:
+      b=allocated;
+      *b=GAL_DATA_BLANK_UCHAR;
+      return b;
+
+      /* CFITSIO says "int for keywords, char for table columns". Here we
+         are only assuming table columns. So in practice this also applies
+         to TSBYTE.*/
+    case GAL_DATA_TYPE_CHAR: case GAL_DATA_TYPE_LOGICAL:
+      c=allocated;
+      *c=GAL_DATA_BLANK_CHAR;
+      return c;
+
+    case GAL_DATA_TYPE_STRING:
+      str=allocated;
+      *str=GAL_DATA_BLANK_STRING;
+      return str;
+
+    case GAL_DATA_TYPE_USHORT:
+      us=allocated;
+      *us=GAL_DATA_BLANK_USHORT;
+      return us;
+
+    case GAL_DATA_TYPE_SHORT:
+      s=allocated;
+      *s=GAL_DATA_BLANK_SHORT;
+      return s;
+
+    case GAL_DATA_TYPE_UINT:
+      ui=allocated;
+      *ui=GAL_DATA_BLANK_UINT;
+      return ui;
+
+    case GAL_DATA_TYPE_INT:
+      i=allocated;
+      *i=GAL_DATA_BLANK_INT;
+      return i;
+
+    case GAL_DATA_TYPE_ULONG:
+      ul=allocated;
+      *ul=GAL_DATA_BLANK_ULONG;
+      return ul;
+
+    case GAL_DATA_TYPE_LONG:
+      l=allocated;
+      *l=GAL_DATA_BLANK_LONG;
+      return l;
+
+    case GAL_DATA_TYPE_LONGLONG:
+      L=allocated;
+      *L=GAL_DATA_BLANK_LONGLONG;
+      return L;
+
+    case GAL_DATA_TYPE_FLOAT:
+      f=allocated;
+      *f=GAL_DATA_BLANK_FLOAT;
+      return f;
+
+    case GAL_DATA_TYPE_DOUBLE:
+      d=allocated;
+      *d=GAL_DATA_BLANK_DOUBLE;
+      return d;
+
+    case GAL_DATA_TYPE_COMPLEX:
+      cx=allocated;
+      GSL_SET_COMPLEX(cx, GAL_DATA_BLANK_FLOAT, GAL_DATA_BLANK_FLOAT);
+      return cx;
+
+    case GAL_DATA_TYPE_DCOMPLEX:
+      dcx=allocated;
+      GSL_SET_COMPLEX(dcx, GAL_DATA_BLANK_DOUBLE, GAL_DATA_BLANK_DOUBLE);
+      return dcx;
+
+    default:
+      error(EXIT_FAILURE, 0, "type value of %d not recognized in "
+            "`gal_data_alloc_blank'", type);
+    }
+
+  return NULL;
+}
diff --git a/lib/fits.c b/lib/fits.c
index 2f28f6f..e4b7f31 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -136,32 +136,31 @@ gal_fits_suffix_is_fits(char *suffix)
 
 
 /*************************************************************
- **************      BITPIX Dependancies       ***************
+ **************           Type codes           ***************
  *************************************************************/
-/* Set datatype (in CFITSIO) based on BITPIX. */
 int
-gal_fits_bitpix_to_datatype(int bitpix)
+gal_fits_bitpix_to_type(int bitpix)
 {
   switch(bitpix)
     {
     case BYTE_IMG:
-      return TBYTE;
+      return GAL_DATA_TYPE_UCHAR;
+    case SBYTE_IMG:
+      return GAL_DATA_TYPE_CHAR;
+    case USHORT_IMG:
+      return GAL_DATA_TYPE_USHORT;
     case SHORT_IMG:
-      return TSHORT;
+      return GAL_DATA_TYPE_SHORT;
+    case ULONG_IMG:
+      return GAL_DATA_TYPE_ULONG;
     case LONG_IMG:
-      return TLONG;
+      return GAL_DATA_TYPE_LONG;
     case LONGLONG_IMG:
-      return TLONGLONG;
+      return GAL_DATA_TYPE_LONGLONG;
     case FLOAT_IMG:
-      return TFLOAT;
+      return GAL_DATA_TYPE_FLOAT;
     case DOUBLE_IMG:
-      return TDOUBLE;
-    case SBYTE_IMG:
-      return TSBYTE;
-    case USHORT_IMG:
-      return TUSHORT;
-    case ULONG_IMG:
-      return TULONG;
+      return GAL_DATA_TYPE_DOUBLE;
     default:
       error(EXIT_FAILURE, 0, "bitpix value of %d not recognized",
             bitpix);
@@ -178,38 +177,36 @@ gal_fits_bitpix_to_datatype(int bitpix)
    column. So this function will do the conversion based on the CFITSIO
    manual.*/
 int
-gal_fits_tform_to_datatype(char tform)
+gal_fits_tform_to_type(char tform)
 {
   switch(tform)
     {
     case 'X':
-      return TBIT;
+      return GAL_DATA_TYPE_BIT;
     case 'B':
-      return TBYTE;
-    case 'L':
-      return TLOGICAL;
+      return GAL_DATA_TYPE_UCHAR;
+    case 'S': case 'L':
+      return GAL_DATA_TYPE_CHAR;
     case 'A':
-      return TSTRING;
+      return GAL_DATA_TYPE_STRING;
+    case 'V':
+      return GAL_DATA_TYPE_UINT;
+    case 'U':
+      return GAL_DATA_TYPE_USHORT;
     case 'I':
-      return TSHORT;
+      return GAL_DATA_TYPE_SHORT;
     case 'J':
-      return TLONG;
+      return GAL_DATA_TYPE_LONG;
     case 'K':
-      return TLONGLONG;
+      return GAL_DATA_TYPE_LONGLONG;
     case 'E':
-      return TFLOAT;
+      return GAL_DATA_TYPE_FLOAT;
     case 'D':
-      return TDOUBLE;
+      return GAL_DATA_TYPE_DOUBLE;
     case 'C':
-      return TCOMPLEX;
+      return GAL_DATA_TYPE_COMPLEX;
     case 'M':
-      return TDBLCOMPLEX;
-    case 'S':
-      return TSBYTE;
-    case 'V':
-      return TUINT;
-    case 'U':
-      return TUSHORT;
+      return GAL_DATA_TYPE_DCOMPLEX;
     default:
       error(EXIT_FAILURE, 0, "'%c' is not a recognized CFITSIO value for "
             "the TFORMn header keyword(s).", tform);
@@ -225,369 +222,151 @@ gal_fits_tform_to_datatype(char tform)
 
 
 
-void
-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_fits_io_error(status, NULL);
-
-  if(naxis!=2)
-    error(EXIT_FAILURE, 0, "currently only a 2 dimensional image array "
-          "is supported. Your array is %d dimension(s). %s", naxis,
-          naxis ? "Please contact us to add this feature." : "This might "
-          "Be due to the fact that the data in images with multiple "
-          "extensions are sometimes put on the second extension. If this "
-          "is the case, try changing the hdu (maybe to --hdu=1)");
-}
-
-
-
-
-
-void *
-gal_fits_datatype_blank(int datatype)
+int
+gal_fits_type_to_datatype(int type)
 {
-  /* Define the pointers, note that we are ordering them based on the
-     CFITSIO manual to be more easily comparable. */
-  unsigned char *b;
-  char *c;
-  char **str;
-  short *s;
-  long *l;
-  LONGLONG *L;
-  float *f;
-  double *d;
-  gsl_complex_float *cx;
-  gsl_complex *dcx;
-  int *i;
-  unsigned int *ui;
-  unsigned short *us;
-  unsigned long *ul;
-
-  errno=0;
-  switch(datatype)
+  switch(type)
     {
-    case TBIT:
-      error(EXIT_FAILURE, 0, "Currently Gnuastro doesn't support TBIT "
-            "datatype, please get in touch with us to implement it.");
+    case GAL_DATA_TYPE_BIT:
+      return TBIT;
 
-    case TBYTE:
-      b=malloc(sizeof *b);
-      if(b==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for blank TBYTE",
-              sizeof *b);
-      *b=GAL_DATA_BLANK_UCHAR;
-      return b;
-
-      /* CFITSIO says "int for keywords, char for table columns". Here we
-         are only assuming table columns. So in practice this also applies
-         to TSBYTE.*/
-    case TLOGICAL: case TSBYTE:
-      c=malloc(sizeof *c);
-      if(c==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for blank TLOGICAL, or TSBYTE",
-              sizeof *c);
-      *c=GAL_DATA_BLANK_LOGICAL;
-      return c;
+    case GAL_DATA_TYPE_UCHAR:
+      return TBYTE;
 
-    case TSTRING:
-      str=malloc(sizeof *str);
-      if(str==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for blank TSTRING",
-              sizeof *s);
-      *str=GAL_DATA_BLANK_STRING;
-      return str;
+    case GAL_DATA_TYPE_CHAR:
+      return TSBYTE;
 
-    case TSHORT:
-      s=malloc(sizeof *s);
-      if(s==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for blank TSHORT",
-              sizeof *s);
-      *s=GAL_DATA_BLANK_SHORT;
-      return s;
+    case GAL_DATA_TYPE_STRING:
+      return TSTRING;
 
-    case TLONG:
-      l=malloc(sizeof *l);
-      if(l==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for blank TLONG",
-              sizeof *l);
-      *l=GAL_DATA_BLANK_LONG;
-      return l;
+    case GAL_DATA_TYPE_USHORT:
+      return TUSHORT;
 
-    case TLONGLONG:
-      L=malloc(sizeof *L);
-      if(L==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for blank TLONGLONG",
-              sizeof *L);
-      *L=GAL_DATA_BLANK_LONGLONG;
-      return L;
+    case GAL_DATA_TYPE_SHORT:
+      return TSHORT;
 
-    case TFLOAT:
-      f=malloc(sizeof *f);
-      if(f==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for blank TFLOAT",
-              sizeof *f);
-      *f=GAL_DATA_BLANK_FLOAT;
-      return f;
+    case GAL_DATA_TYPE_UINT:
+      return TUINT;
 
-    case TDOUBLE:
-      d=malloc(sizeof *d);
-      if(d==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for blank TDOUBLE",
-              sizeof *d);
-      *d=GAL_DATA_BLANK_DOUBLE;
-      return d;
+    case GAL_DATA_TYPE_INT:
+      return TINT;
 
-    case TCOMPLEX:
-      cx=malloc(sizeof *cx);
-      if(cx==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for blank TCOMPLEX",
-              sizeof *cx);
-      GSL_SET_COMPLEX(cx,GAL_DATA_BLANK_FLOAT,GAL_DATA_BLANK_FLOAT);
-      return cx;
+    case GAL_DATA_TYPE_ULONG:
+      return TULONG;
 
-    case TDBLCOMPLEX:
-      dcx=malloc(sizeof *dcx);
-      if(dcx==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for blank TDBLCOMPLEX",
-              sizeof *dcx);
-      GSL_SET_COMPLEX(dcx,GAL_DATA_BLANK_DOUBLE,GAL_DATA_BLANK_DOUBLE);
-      return dcx;
+    case GAL_DATA_TYPE_LONG:
+      return TLONG;
 
-    case TINT:
-      i=malloc(sizeof *i);
-      if(i==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for blank TINT",
-              sizeof *i);
-      *i=GAL_DATA_BLANK_INT;
-      return i;
+    case GAL_DATA_TYPE_LONGLONG:
+      return TLONGLONG;
 
-    case TUINT:
-      ui=malloc(sizeof *ui);
-      if(ui==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for blank TUINT",
-              sizeof *ui);
-      *ui=GAL_DATA_BLANK_UINT;
-      return ui;
+    case GAL_DATA_TYPE_FLOAT:
+      return TFLOAT;
 
-    case TUSHORT:
-      us=malloc(sizeof *us);
-      if(us==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for blank TUSHORT",
-              sizeof *us);
-      *us=GAL_DATA_BLANK_USHORT;
-      return us;
+    case GAL_DATA_TYPE_DOUBLE:
+      return TDOUBLE;
 
-    case TULONG:
-      ul=malloc(sizeof *ul);
-      if(ul==NULL)
-        error(EXIT_FAILURE, errno, "%zu bytes for blank TULONG",
-              sizeof *ul);
-      *ul=GAL_DATA_BLANK_ULONG;
-      return ul;
+    case GAL_DATA_TYPE_COMPLEX:
+      return TCOMPLEX;
 
+    case GAL_DATA_TYPE_DCOMPLEX:
+      return TDBLCOMPLEX;
 
     default:
-      error(EXIT_FAILURE, 0, "datatype value of %d not recognized",
-            datatype);
+      error(EXIT_FAILURE, 0, "'%d' is not a recognized Gnuastro type. "
+            "It was given to `gal_fits_type_to_datatype'.", type);
     }
 
-  return NULL;
+  error(EXIT_FAILURE, 0, "A bug! Please contact us so we can fix this. "
+        "For some reason, control has reached to the end of the "
+        "gal_fits_type_to_datatype function in fits.c.");
+  return -1;
 }
 
 
 
 
 
-/* Allocate an array based on the value of datatype. Note that the argument
-   `size' is the number of elements, necessary in the array, the number of
-   bytes each element needs will be determined internaly by this function
-   using the datatype argument, so you don't have to worry about it. */
-void *
-gal_fits_datatype_alloc(size_t size, int datatype)
+int
+gal_fits_datatype_to_type(int datatype)
 {
-  void *array;
-
-  /* Allocate space for the array to keep the image. */
   switch(datatype)
     {
     case TBIT:
-      error(EXIT_FAILURE, 0, "Currently Gnuastro doesn't support TBIT "
-            "datatype, please get in touch with us to implement it.");
+      return GAL_DATA_TYPE_BIT;
 
-      /* The parenthesis after sizeof is not a function, it is actually a
-         type cast, so we have put a space between size of and the
-         parenthesis to highlight this. In C, `sizeof' is an operator, not
-         a function.*/
     case TBYTE:
-      size *= sizeof (unsigned char);
-      break;
+      return GAL_DATA_TYPE_UCHAR;
 
-    case TLOGICAL: case TSBYTE:
-      size *= sizeof (char);
-      break;
+    case TSBYTE:
+      return GAL_DATA_TYPE_CHAR;
 
     case TSTRING:
-      size *= sizeof (char *);
-      break;
+      return GAL_DATA_TYPE_STRING;
+
+    case TUSHORT:
+      return GAL_DATA_TYPE_USHORT;
 
     case TSHORT:
-      size *= sizeof (short);
-      break;
+      return GAL_DATA_TYPE_SHORT;
+
+    case TUINT:
+      return GAL_DATA_TYPE_UINT;
+
+    case TINT:
+      return GAL_DATA_TYPE_INT;
+
+    case TULONG:
+      return GAL_DATA_TYPE_ULONG;
 
     case TLONG:
-      size *= sizeof (long);
-      break;
+      return GAL_DATA_TYPE_LONG;
 
     case TLONGLONG:
-      size *= sizeof (LONGLONG);
-      break;
+      return GAL_DATA_TYPE_LONGLONG;
 
     case TFLOAT:
-      if( sizeof (float) != 4 )
-        error(EXIT_FAILURE, 0,
-              "`float` is not 32bits on this machine. The FITS standard "
-              "Requires this size");
-      size *= sizeof (float);
-      break;
+      return GAL_DATA_TYPE_FLOAT;
 
     case TDOUBLE:
-      if( sizeof (double) != 8 )
-        error(EXIT_FAILURE, 0,
-              "`double` is not 64bits on this machine. The FITS standard "
-              "requires this size");
-      size *= sizeof (double);
-      break;
+      return GAL_DATA_TYPE_DOUBLE;
 
     case TCOMPLEX:
-      if( sizeof (float) != 4 )
-        error(EXIT_FAILURE, 0,
-              "`float` is not 32bits on this machine. The FITS standard "
-              "Requires this size");
-      size *= sizeof (gsl_complex_float);
-      break;
+      return GAL_DATA_TYPE_COMPLEX;
 
     case TDBLCOMPLEX:
-      if( sizeof (double) != 8 )
-        error(EXIT_FAILURE, 0,
-              "`double` is not 64bits on this machine. The FITS standard "
-              "requires this size");
-      size *= sizeof (gsl_complex);
-      break;
-
-    case TINT:
-      size *= sizeof (int);
-      break;
-
-    case TUINT:
-      size *= sizeof (unsigned int);
-      break;
-
-    case TUSHORT:
-      size *= sizeof (unsigned short);
-      break;
-
-    case TULONG:
-      size *= sizeof (unsigned long);
-      break;
+      return GAL_DATA_TYPE_DCOMPLEX;
 
     default:
-      error(EXIT_FAILURE, 0, "datatype value of %d not recognized in "
-            "gal_fits_datatype_alloc", datatype);
+      error(EXIT_FAILURE, 0, "'%d' is not a recognized CFITSIO datatype. "
+            "It was given to `gal_fits_datatype_to_type'.", datatype);
     }
 
-  errno=0;
-  array=malloc(size);
-  if(array==NULL)
-    error(EXIT_FAILURE, errno,
-          "array of %zu bytes in gal_fits_datatype_alloc", size);
-
-  return array;
+  error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we can fix "
+        "this. For some reason, control has reached to the end of the "
+        "gal_fits_datatype_to_type function in fits.c.", PACKAGE_BUGREPORT);
+  return -1;
 }
 
 
 
 
 
-size_t
-gal_fits_datatype_size(int datatype)
+void
+gal_fits_img_bitpix_size(fitsfile *fptr, int *bitpix, long *naxes)
 {
-  switch(datatype)
-    {
-    case TBIT:
-      error(EXIT_FAILURE, 0, "Currently Gnuastro doesn't support TBIT "
-            "datatype, please get in touch with us to implement it.");
-
-      /* The parenthesis after sizeof is not a function, it is actually a
-         type cast, so we have put a space between size of and the
-         parenthesis to highlight this. In C, `sizeof' is an operator, not
-         a function.*/
-    case TBYTE:
-      return sizeof (unsigned char);
-
-    case TLOGICAL: case TSBYTE:
-      return sizeof (char);
-
-    case TSTRING:
-      return sizeof (char *);
-
-    case TSHORT:
-      return sizeof (short);
-
-    case TLONG:
-      return sizeof (long);
-
-    case TLONGLONG:
-      return sizeof (LONGLONG);
-
-    case TFLOAT:
-      if( sizeof (float) != 4 )
-        error(EXIT_FAILURE, 0,
-              "`float` is not 32bits on this machine. The FITS standard "
-              "Requires this size");
-      return sizeof (float);
-
-    case TDOUBLE:
-      if( sizeof (double) != 8 )
-        error(EXIT_FAILURE, 0,
-              "`double` is not 64bits on this machine. The FITS standard "
-              "requires this size");
-      return sizeof (double);
-
-    case TCOMPLEX:
-      if( sizeof (float) != 4 )
-        error(EXIT_FAILURE, 0,
-              "`float` is not 32bits on this machine. The FITS standard "
-              "Requires this size");
-      return sizeof (gsl_complex_float);
-
-    case TDBLCOMPLEX:
-      if( sizeof (double) != 8 )
-        error(EXIT_FAILURE, 0,
-              "`double` is not 64bits on this machine. The FITS standard "
-              "requires this size");
-      return sizeof (gsl_complex);
-
-    case TINT:
-      return sizeof (int);
-
-    case TUINT:
-      return sizeof (unsigned int);
-
-    case TUSHORT:
-      return sizeof (unsigned short);
-
-    case TULONG:
-      return sizeof (unsigned long);
+  int status=0, maxdim=10, naxis;
 
-    default:
-      error(EXIT_FAILURE, 0, "datatype value of %d not recognized in "
-            "gal_fits_datatype_size", datatype);
-    }
+  if( fits_get_img_param(fptr, maxdim, bitpix, &naxis, naxes, &status) )
+    gal_fits_io_error(status, NULL);
 
-  return 0;
+  if(naxis!=2)
+    error(EXIT_FAILURE, 0, "currently only a 2 dimensional image array "
+          "is supported. Your array is %d dimension(s). %s", naxis,
+          naxis ? "Please contact us to add this feature." : "This might "
+          "Be due to the fact that the data in images with multiple "
+          "extensions are sometimes put on the second extension. If this "
+          "is the case, try changing the hdu (maybe to --hdu=1)");
 }
 
 
@@ -765,7 +544,7 @@ gal_fits_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_fits_datatype_alloc(size, gal_fits_bitpix_to_datatype(outbitpix) );
+  *out=gal_data_alloc(gal_fits_bitpix_to_type(outbitpix), size);
   switch(outbitpix)
     {
     case BYTE_IMG:
@@ -1758,7 +1537,7 @@ gal_fits_hdu_to_array(char *filename, char *hdu, int 
*bitpix,
   void *bitblank;
   fitsfile *fptr;
   long naxes[2], fpixel[]={1,1};
-  int status=0, anyblank=0, datatype;
+  int status=0, anyblank=0, type;
 
   /* Check HDU for realistic conditions: */
   gal_fits_read_hdu(filename, hdu, 0, &fptr);
@@ -1769,12 +1548,12 @@ gal_fits_hdu_to_array(char *filename, char *hdu, int 
*bitpix,
   *s1=naxes[0];
 
   /* Allocate space for the array. */
-  datatype=gal_fits_bitpix_to_datatype(*bitpix);
-  bitblank=gal_fits_datatype_blank(datatype);
-  *array=gal_fits_datatype_alloc(*s0 * *s1, datatype);
+  type=gal_fits_bitpix_to_type(*bitpix);
+  bitblank=gal_data_alloc_blank(type);
+  *array=gal_data_alloc(type, *s0 * *s1);
 
   /* Read the image into the allocated array: */
-  fits_read_pix(fptr, gal_fits_bitpix_to_datatype(*bitpix), fpixel,
+  fits_read_pix(fptr, gal_fits_type_to_datatype(type), fpixel,
                 *s0 * *s1, bitblank, *array, &anyblank, &status);
   if(status) gal_fits_io_error(status, NULL);
   free(bitblank);
@@ -1818,10 +1597,11 @@ gal_fits_array_to_file(char *filename, char *extname, 
int bitpix, void *array,
   void *blank;
   fitsfile *fptr;
   char *wcsheader;
-  int status=0, datatype;
+  int status=0, type, datatype;
   long fpixel=1, naxis=2, nelements, naxes[]={s1,s0};
 
-  datatype=gal_fits_bitpix_to_datatype(bitpix);
+  type=gal_fits_bitpix_to_type(bitpix);
+  datatype=gal_fits_type_to_datatype(type);
   nelements=naxes[0]*naxes[1];
 
   if(access(filename,F_OK) != -1 )
@@ -1836,7 +1616,7 @@ gal_fits_array_to_file(char *filename, char *extname, int 
bitpix, void *array,
     if(bitpix==BYTE_IMG || bitpix==SHORT_IMG
        || bitpix==LONG_IMG || bitpix==LONGLONG_IMG)
       {
-        blank=gal_fits_datatype_blank( gal_fits_bitpix_to_datatype(bitpix) );
+        blank=gal_data_alloc_blank(type);
         if(fits_write_key(fptr, datatype, "BLANK", blank,
                           "Pixels with no data.", &status) )
           gal_fits_io_error(status, "adding the BLANK keyword");
@@ -1875,10 +1655,11 @@ gal_fits_atof_correct_wcs(char *filename, char *hdu, 
int bitpix, void *array,
                           double *crpix, char *spack_string)
 {
   fitsfile *fptr;
-  int status=0, datatype;
+  int status=0, type, datatype;
   long fpixel=1, naxis=2, nelements, naxes[]={s1,s0};
 
-  datatype=gal_fits_bitpix_to_datatype(bitpix);
+  type=gal_fits_bitpix_to_type(bitpix);
+  datatype=gal_fits_type_to_datatype(type);
   nelements=naxes[0]*naxes[1];
 
   if(access(filename,F_OK) != -1 )
diff --git a/lib/gnuastro/data.h b/lib/gnuastro/data.h
index 5b99460..32deba8 100644
--- a/lib/gnuastro/data.h
+++ b/lib/gnuastro/data.h
@@ -25,9 +25,12 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 /* Include other headers if necessary here. Note that other header files
    must be included before the C++ preparations below */
+#include <math.h>
 #include <limits.h>
-#include <wcslib/wcs.h>
+#include <stdint.h>
 
+#include <wcslib/wcs.h>
+#include <gsl/gsl_complex.h>
 
 /* C++ Preparations */
 #undef __BEGIN_C_DECLS
@@ -63,10 +66,10 @@ __BEGIN_C_DECLS  /* From C++ preparations */
 #define GAL_DATA_BLANK_CHAR       SCHAR_MAX
 #define GAL_DATA_BLANK_LOGICAL    SCHAR_MAX
 #define GAL_DATA_BLANK_STRING     NULL
-#define GAL_DATA_BLANK_UINT       UINT_MAX
-#define GAL_DATA_BLANK_INT        INT_MIN
 #define GAL_DATA_BLANK_USHORT     USHRT_MAX
 #define GAL_DATA_BLANK_SHORT      INT16_MIN
+#define GAL_DATA_BLANK_UINT       UINT_MAX
+#define GAL_DATA_BLANK_INT        INT_MIN
 #define GAL_DATA_BLANK_ULONG      ULONG_MAX
 #define GAL_DATA_BLANK_LONG       INT32_MIN
 #define GAL_DATA_BLANK_LONGLONG   INT64_MIN
@@ -81,21 +84,22 @@ __BEGIN_C_DECLS  /* From C++ preparations */
    parenthesis is the equivalent macro in CFITSIO. */
 enum gal_data_alltypes
 {
-  GAL_DATA_BIT,        /* Bit              (TBIT).      */
-  GAL_DATA_UCHAR,      /* Unsigned char    (TBYTE).     */
-  GAL_DATA_CHAR,       /* char             (TSBYTE).    */
-  GAL_DATA_STRING,     /* string           (TSTRING).   */
-  GAL_DATA_UINT,       /* unsigned int     (TUINT).     */
-  GAL_DATA_INT,        /* int              (TINT).      */
-  GAL_DATA_USHORT,     /* unsigned short   (TUSHORT).   */
-  GAL_DATA_SHORT,      /* short            (TSHORT).    */
-  GAL_DATA_ULONG,      /* unsigned long    (TLONG).     */
-  GAL_DATA_LONG,       /* long             (TLONG).     */
-  GAL_DATA_LONGLONG,   /* long long        (TLONGLONG). */
-  GAL_DATA_FLOAT,      /* float            (TFLOAT).    */
-  GAL_DATA_DOUBLE,     /* double           (TDOUBLE).   */
-  GAL_DATA_COMPLEX,    /* Complex float    (TCOMPLEX).  */
-  GAL_DATA_DCOMPLEX,   /* Complex double   (TDCOMPLEX). */
+  GAL_DATA_TYPE_BIT,       /* Bit              (TBIT).        */
+  GAL_DATA_TYPE_UCHAR,     /* Unsigned char    (TBYTE).       */
+  GAL_DATA_TYPE_CHAR,      /* char             (TSBYTE).      */
+  GAL_DATA_TYPE_LOGICAL,   /* char             (TLOGICAL).    */
+  GAL_DATA_TYPE_STRING,    /* string           (TSTRING).     */
+  GAL_DATA_TYPE_USHORT,    /* unsigned short   (TUSHORT).     */
+  GAL_DATA_TYPE_SHORT,     /* short            (TSHORT).      */
+  GAL_DATA_TYPE_UINT,      /* unsigned int     (TUINT).       */
+  GAL_DATA_TYPE_INT,       /* int              (TINT).        */
+  GAL_DATA_TYPE_ULONG,     /* unsigned long    (TLONG).       */
+  GAL_DATA_TYPE_LONG,      /* long             (TLONG).       */
+  GAL_DATA_TYPE_LONGLONG,  /* long long        (TLONGLONG).   */
+  GAL_DATA_TYPE_FLOAT,     /* float            (TFLOAT).      */
+  GAL_DATA_TYPE_DOUBLE,    /* double           (TDOUBLE).     */
+  GAL_DATA_TYPE_COMPLEX,   /* Complex float    (TCOMPLEX).    */
+  GAL_DATA_TYPE_DCOMPLEX,  /* Complex double   (TDBLCOMPLEX). */
 };
 
 
@@ -118,6 +122,22 @@ typedef struct
   struct wcsprm *wcs;  /* WCS information for this dataset.        */
 } gal_data;
 
+
+
+
+
+/* Functions */
+size_t
+gal_data_sizeof(int type);
+
+void *
+gal_data_alloc(int type, size_t size);
+
+void *
+gal_data_alloc_blank(int type);
+
+
+
 __END_C_DECLS    /* From C++ preparations */
 
 #endif           /* __GAL_BOX_H__ */
diff --git a/lib/gnuastro/fits.h b/lib/gnuastro/fits.h
index 74dc45c..1cd8531 100644
--- a/lib/gnuastro/fits.h
+++ b/lib/gnuastro/fits.h
@@ -27,13 +27,11 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
    must be included before the C++ preparations below */
 #include <math.h>
 #include <float.h>
-#include <stdint.h>
-#include <limits.h>
+
 #include <fitsio.h>
 #include <wcslib/wcs.h>
 #include <wcslib/wcshdr.h>
 #include <wcslib/wcsfix.h>
-#include <gsl/gsl_complex.h>
 
 #include <gnuastro/data.h>
 
@@ -146,20 +144,33 @@ gal_fits_write_keys_version(fitsfile *fptr, struct 
gal_fits_key_ll *headers,
 
 
 /*************************************************************
- ******************        Read/Write        *****************
+ **************           Type codes           ***************
  *************************************************************/
-void *
-gal_fits_datatype_blank(int datatype);
+int
+gal_fits_bitpix_to_type(int bitpix);
+
+int
+gal_fits_tform_to_type(char tform);
+
+int
+gal_fits_type_to_datatype(int type);
+
+int
+gal_fits_datatype_to_type(int type);
+
+
 
+
+
+/*************************************************************
+ ******************        Read/Write        *****************
+ *************************************************************/
 void
 gal_fits_convert_blank(void *array, int bitpix, size_t size, void *value);
 
 void
 gal_fits_blank_to_value(void *array, int datatype, size_t size, void *value);
 
-int
-gal_fits_bitpix_to_datatype(int bitpix);
-
 void
 gal_fits_img_bitpix_size(fitsfile *fptr, int *bitpix, long *naxis);
 
@@ -167,12 +178,6 @@ void
 gal_fits_read_hdu(char *filename, char *hdu, unsigned char img0_tab1,
                   fitsfile **outfptr);
 
-void *
-gal_fits_datatype_alloc(size_t size, int datatype);
-
-size_t
-gal_fits_datatype_size(int datatype);
-
 void
 gal_fits_change_type(void *in, int inbitpix, size_t size, int anyblank,
                      void **out, int outbitpix);
@@ -212,9 +217,6 @@ gal_fits_atof_correct_wcs(char *filename, char *hdu, int 
bitpix,
 /**************************************************************/
 /**********                  Table                 ************/
 /**************************************************************/
-int
-gal_fits_tform_to_datatype(char tform);
-
 void
 gal_fits_table_size(fitsfile *fitsptr, size_t *nrows, size_t *ncols);
 



reply via email to

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