gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 5c41564 1/2: New function to return the size o


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 5c41564 1/2: New function to return the size of FITS datatype
Date: Fri, 21 Oct 2016 21:07:30 +0000 (UTC)

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

    New function to return the size of FITS datatype
    
    The new `gal_fits_datatype_size' was added to `lib/gnuastro/fits.h' and
    `lib/fits.c' and is now included in the library. An entry was also added to
    the manual. As described, this function will return the size of the given
    datatype.
---
 doc/gnuastro.texi   |    5 +++
 lib/fits.c          |   85 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 lib/gnuastro/fits.h |    3 ++
 3 files changed, 92 insertions(+), 1 deletion(-)

diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index e09a8bc..54d9295 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -15655,6 +15655,11 @@ Allocate an array of @code{size} elements of type 
@code{datatype}. See
 @ref{CFITSIO datatype}.
 @end deftypefun
 
address@hidden size_t gal_fits_datatype_size (int @code{datatype})
+Return the size (in bytes) of the type specified by @code{datatype}, see
address@hidden datatype}.
address@hidden deftypefun
+
 @deftypefun void gal_fits_blank_to_value (void @code{*array}, int 
@code{datatype}, size_t @code{size}, void @code{*value})
 Convert the blank values in @code{array} (with @code{size} elements) into
 the value pointed by @code{value}.
diff --git a/lib/fits.c b/lib/fits.c
index ba024db..e543622 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -392,7 +392,7 @@ gal_fits_datatype_blank(int datatype)
 
 
 
-/* Allocate an array based on the value of bitpix. Note that the argument
+/* 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. */
@@ -502,6 +502,89 @@ gal_fits_datatype_alloc(size_t size, int datatype)
 
 
 
+size_t
+gal_fits_datatype_size(int datatype)
+{
+  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);
+
+    default:
+      error(EXIT_FAILURE, 0, "datatype value of %d not recognized in "
+            "gal_fits_datatype_size", datatype);
+    }
+
+  return 0;
+}
+
+
+
+
+
 void
 gal_fits_blank_to_value(void *array, int datatype, size_t size, void *value)
 {
diff --git a/lib/gnuastro/fits.h b/lib/gnuastro/fits.h
index ba1703a..e0c361e 100644
--- a/lib/gnuastro/fits.h
+++ b/lib/gnuastro/fits.h
@@ -190,6 +190,9 @@ gal_fits_read_hdu(char *filename, char *hdu, unsigned char 
img0_tab1,
 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);



reply via email to

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