gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 1b397c4 3/3: fits.h functions included in the


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 1b397c4 3/3: fits.h functions included in the book
Date: Sun, 18 Sep 2016 20:23:51 +0000 (UTC)

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

    fits.h functions included in the book
    
    The functions and necessary concepts for programming with `fits.h' have
    been fully explained in the book. FITS is the main data storage format in
    astronomy, so it was necessary to elaborate on how to work with
    them. Ofcourse, these functions are just an initial release and they will
    greatly evolve. During the process some of the functions and arguments were
    re-named (and corrected throughout Gnuastro) so the names can be more
    descriptive of what the function does. "The TEMPLATE utility" section was
    also moved to the "Developing" chapter.
---
 doc/gnuastro.texi             |  633 ++++++++++++++++++++++++++++++++++++++---
 lib/fits.c                    |  158 +++++-----
 lib/gnuastro/fits.h           |  103 +++----
 src/convertt/ui.c             |    2 +-
 src/header/header.c           |    4 +-
 src/header/main.h             |    4 +-
 src/header/ui.c               |    6 +-
 src/imgcrop/crop.c            |   10 +-
 src/imgcrop/imgcrop.c         |    4 +-
 src/imgcrop/ui.c              |    2 +-
 src/imgwarp/imgwarp.c         |   10 +-
 src/mkcatalog/ui.c            |    4 +-
 src/mknoise/mknoise.c         |   32 +--
 src/noisechisel/noisechisel.c |   42 ++-
 src/table/table.c             |    2 +-
 src/table/ui.c                |    2 +-
 16 files changed, 765 insertions(+), 253 deletions(-)

diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 1ab7f6d..a1fd689 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -498,7 +498,6 @@ Libraries
 
 * Review of library fundamentals::  Guide on libraries and linking.
 * Gnuastro library::            Description of all library functions.
-* The TEMPLATE utility::        Template for building a new utility.
 
 Review of library fundamentals
 
@@ -511,6 +510,13 @@ Gnuastro library
 
 * Overall package (gnuastro.h)::  Related to the whole package.
 * Bounding box (box.h)::        Finding bounding boxes in an image.
+* FITS files (fits.h)::         Reading and manipulating FITS data.
+
+FITS files (@file{fits.h})
+
+* CFITSIO datatype::            Addressing different types of data
+* FITS macros and data structures::  Gnuastro FITS related macros and 
structures.
+* FITS functions::              Functions to work on FITS data.
 
 Developing
 
@@ -532,6 +538,7 @@ Program source
 * Coding conventions::          Basic conventions for coding structure.
 * Multithreaded programming::   Gnuastro's multithreaded programming style.
 * Documentation::               Documentation is an integral part of Gnuastro.
+* The TEMPLATE utility::        A template to create new utilities.
 
 Mandatory source code files
 
@@ -14082,15 +14089,14 @@ use them in @ref{Review of library fundamentals}. The 
separate functions in
 the Gnuastro library are then introduced (classified by context) in
 @ref{Gnuastro library}. If you end up rutinely using a fixed set of library
 functions, with a well-defined input and output, it will be much more
-beneficial if you define a utility for the job. Therefore in @ref{The
-TEMPLATE utility} we discuss how you can modify a template utility that is
-provided with Gnuastro to easily add a new utility.
+beneficial if you define a utility for the job. You can also look into
address@hidden TEMPLATE utility} to easily define your own utility(s) from these
+and other libraries.
 
 
 @menu
 * Review of library fundamentals::  Guide on libraries and linking.
 * Gnuastro library::            Description of all library functions.
-* The TEMPLATE utility::        Template for building a new utility.
 @end menu
 
 @node Review of library fundamentals, Gnuastro library, Libraries, Libraries
@@ -14218,11 +14224,26 @@ definitions) comes with 
@file{lib/gnuastro/statistics.h} (only containing
 function declarations).
 
 The discussion above was mainly focused on functions, however, there are
-many more programming constructs such as data structures and pre-processor
-macros. Like functions, they also need to be known to the compiler when it
-confronts a call to them. So the header file also contains their
+many more programming constructs such as pre-processor macros and data
+structures. Like functions, they also need to be known to the compiler when
+it confronts a call to them. So the header file also contains their
 definitions or declarations when they are necessary for the functions.
 
address@hidden Macro
address@hidden Structures
address@hidden Data structures
address@hidden Pre-processor macros
+Pre-processor macros (or macros for short) are replaced with their defined
+value by the pre-processor before compilation. Conventionally they are
+written only in capital letters to be easily recognized. It is just
+important to understand that the compiler doesn't see the macros, it sees
+their fixed values. So when a header specifies macros you can do your
+programming without worrying about the actual values.  The standard C types
+(for example @code{int}, or @code{float}) are very low-level and basic. We
+can collect multiple C types into a @emph{structure} for a higher-level way
+to keep and pass-along data. See @ref{FITS macros and data structures} for
+some examples of macros and data structures.
+
 The contents in the header need to be @emph{include}d into the caller's
 source code with a special pre-processor command: @code{#include
 <path/to/header.h>}. As the name suggests, the @emph{pre-processor} goes
@@ -14674,7 +14695,7 @@ gnuastro-gcc myprog && ./myprog
 @end example
 
 
address@hidden Gnuastro library, The TEMPLATE utility, Review of library 
fundamentals, Libraries
address@hidden Gnuastro library,  , Review of library fundamentals, Libraries
 @section Gnuastro library
 
 Gnuastro library's exported constructs (functions, macros, data structures,
@@ -14728,6 +14749,7 @@ for changes in the interface.
 @menu
 * Overall package (gnuastro.h)::  Related to the whole package.
 * Bounding box (box.h)::        Finding bounding boxes in an image.
+* FITS files (fits.h)::         Reading and manipulating FITS data.
 @end menu
 
 @node Overall package (gnuastro.h), Bounding box (box.h), Gnuastro library, 
Gnuastro library
@@ -14763,7 +14785,7 @@ char *gnuastro_version=GAL_GNUASTRO_VERSION;
 
 
 
address@hidden Bounding box (box.h),  , Overall package (gnuastro.h), Gnuastro 
library
address@hidden Bounding box (box.h), FITS files (fits.h), Overall package 
(gnuastro.h), Gnuastro library
 @subsection Bounding box (@file{box.h})
 
 Functions related to reporing a the bouding box of certain inputs are
@@ -14771,53 +14793,514 @@ declared in @file{gnuastro/box.h}. All coordinates 
in this header are in
 the FITS format (first axis is the horizontal and the second axis is
 vertical).
 
address@hidden void gal_box_ellipse_in_box (double @var{A}, double @var{B}, 
double @var{theta_rad}, long @var{*width})
address@hidden void gal_box_ellipse_in_box (double @code{A}, double @code{B}, 
double @code{theta_rad}, long @code{*width})
 Any ellipse can be enclosed into a rectangular box. The purpose of this
-function is to give the height and width of that box. @var{A} is the
-ellipse major axis, @var{B} is the minor axis, @var{theta_rad} is the
-position angle in radians. The @var{width} array will contain the output
+function is to give the height and width of that box. @code{A} is the
+ellipse major axis, @code{B} is the minor axis, @code{theta_rad} is the
+position angle in radians. The @code{width} array will contain the output
 size in long integer type. @code{width[0]}, and @code{width[1]} are the
 number of pixels along the first and second FITS axis.
 @end deftypefun
 
address@hidden void gal_box_border_from_center (double @var{xc}, double 
@var{yc}, long @var{*width}, long @var{*fpixel}, long @var{*lpixel})
-Given the center (@var{xc} and @var{yc}) and width (two element array) of a
-box, return the coordinates of the first @var{fpixel} and last @var{lpixel}
address@hidden void gal_box_border_from_center (double @code{xc}, double 
@code{yc}, long @code{*width}, long @code{*fpixel}, long @code{*lpixel})
+Given the center (@code{xc} and @code{yc}) and width (two element array) of a
+box, return the coordinates of the first @code{fpixel} and last @code{lpixel}
 pixels (both are two element arrays.
 @end deftypefun
 
address@hidden int gal_box_overlap (long @var{*naxes}, long @var{*fpixel_i}, 
long @var{*lpixel_i}, long @var{*fpixel_o}, long @var{*lpixel_o})
-We have an image of size @var{naxes} and want to get the overlap of the
address@hidden int gal_box_overlap (long @code{*naxes}, long @code{*fpixel_i}, 
long @code{*lpixel_i}, long @code{*fpixel_o}, long @code{*lpixel_o})
+We have an image of size @code{naxes} and want to get the overlap of the
 image with a box. This function will return 1 if there is an overlap and 0
 if there isn't. The input and output box are specified by their first and
 last pixels. When there is an overlap, the coordinates of the first and
-last pixels of the overlap will be put in @var{fpixel_o} and
address@hidden
+last pixels of the overlap will be put in @code{fpixel_o} and
address@hidden
 @end deftypefun
 
address@hidden FITS files (fits.h),  , Bounding box (box.h), Gnuastro library
address@hidden FITS files (@file{fits.h})
+
address@hidden FITS
address@hidden CFITSIO
+The FITS format is the most common format to store data (images and tables)
+in astronomy. The CFITSIO library already provides a very good low-level
+set of functions for manipulating FITS data. Some CFITSIO operations (with
+well-defined inputs and outputs) are commonly needed in a special
+order. Therefore Gnuastro comes with the macros, data structures and
+functions introduced in this section. These functions are actually wrappers
+around CFITSIO functions for a higher-level (easier) access to FITS
+data. So if you feel these functions don't exactly do what you want, we
+strongly recommend reading the CFITSIO manual to use it directly.
+
+All the functions and macros introduced in this section are declared in
address@hidden/fits.h}.  When you include this header, you are also
+including CFITSIO's @file{fitsio.h} header. So you don't need to explicitly
+include @file{fitsio.h} anymore and can freely use any of its macros or
+functions in your code along with those discussed here. In @ref{CFITSIO
+datatype} we first have a look at the way data types are referenced in
+CFITSIO (and thus Gnuastro). @ref{FITS macros and data structures} defines
+the macros and data structures that can be used in functions for a unified
+format. This subsection finished with @ref{FITS functions}, which introduce
+the different Gnuastro functions available.
+
address@hidden
+* CFITSIO datatype::            Addressing different types of data
+* FITS macros and data structures::  Gnuastro FITS related macros and 
structures.
+* FITS functions::              Functions to work on FITS data.
address@hidden menu
+
address@hidden CFITSIO datatype, FITS macros and data structures, FITS files 
(fits.h), FITS files (fits.h)
address@hidden CFITSIO @code{datatype}
+
address@hidden Data type
address@hidden Type of data
address@hidden FITS: data type
+Data can have multiple types: standards to convert a number of bits (which
+can only have values of 0 and 1) to different number formats (for example
+integer or floating point numbers). To store data, the FITS standard
+defines two major formats: images and tables. An image has a single type
+for all its data elements (a pixel in a 2D image). A table has a single
+type for every one of its columns. In both cases, the FITS header stores
+this information. All the FITS data types correspond to C types (for
+example @code{short}, @code{int}, @code{float}, or @code{long}.
 
address@hidden CFITSIO
address@hidden @code{BITPIX}
+In images, the @code{BITPIX} header keyword specifies the type of data in
+each pixel. Within CFITSIO, the different acceptable values of
address@hidden are stored as macros ending with @code{_IMG}. For example
address@hidden, or @code{DOUBLE_IMG}. See Section 4.1, ``CFITSIO
+Definitions'', in the CFITSIO manual for the recognized CFITSIO types and
+their macros. However, the FITS standard also accepts tables: each column
+in a FITS table has a unique @code{TFORM} header keyword which specifies
+the type of data in that column. The variety of types in a FITS table can
+be much larger than an image and thus the standard for identifying them
+differs.
+
+To address these different formats of identifying the type in a uniform
+infra-structure, CFITSIO identifies a general collection of macros
+referring to types which can be internally used in all cases (images and
+tables). Thus in CFITSIO, the variable name @code{datatype} when we are
+referring to this general collection of types. The image types are a subset
+of the table column types, so each acceptable @code{datatype} corresponds
+to one of the table types. The macros for each recognized CFITSIO
address@hidden start with @code{T}, for example @code{TBYTE},
address@hidden In CFITSIO (and thus here in Gnuastro), the @code{datatype}
+is most commonly used, so this variable only accepts one of the accepted
address@hidden macros. When the @code{BITPIX} value is desired (as input or
+output), the variable is called @code{bitpix}.
+
+In Gnuastro, the functions @code{gal_fits_bitpix_to_datatype} and
address@hidden are provided to convert @code{bitpix} and
address@hidden values to @code{datatype}.
 
address@hidden
address@hidden
address@hidden @file{stdint.h}
address@hidden integer types:} CFITSIO does not use the standard fixed
+integer size types of @file{stdint.h}! It uses the subjective @code{short},
address@hidden and @code{long} variables which can differ in size from system
+to system. For example, the FITS standard defines @code{LONG_IMG} as a
+32bit signed integer type, but CFITSIO converts it to a local @code{long}
+which is 64 bits on a modern (64 bit) machine. To use CFITSIO, we had to
+adopt the same convention in Gnuastro. This issue can cause confusions, so
+be careful!
address@hidden cartouche
 
 
address@hidden FITS macros and data structures, FITS functions, CFITSIO 
datatype, FITS files (fits.h)
address@hidden FITS macros and data structures
+
+To facilitate handling of fixed/standard values and store, or pass multiple
+related variables in your programs, Gnuastro defines the following FITS
+related macros and data structures, see @ref{Headers} for a more detailed
+discussion.
+
address@hidden  Macro GAL_FITS_STRING_BLANK
address@hidden Macro GAL_FITS_BYTE_BLANK
address@hidden Macro GAL_FITS_LOGICAL_BLANK
address@hidden Macro GAL_FITS_SHORT_BLANK
address@hidden Macro GAL_FITS_LONG_BLANK
address@hidden Macro GAL_FITS_LLONG_BLANK
address@hidden Macro GAL_FITS_FLOAT_BLANK
address@hidden Macro GAL_FITS_DOUBLE_BLANK
address@hidden Macro GAL_FITS_INT_BLANK
address@hidden Macro GAL_FITS_SBYTE_BLANK
address@hidden Macro GAL_FITS_UINT_BLANK
address@hidden Macro GAL_FITS_USHORT_BLANK
address@hidden Macro GAL_FITS_ULONG_BLANK
address@hidden Blank pixel
+These macros keep Gnuastro's blank value constant for all the recognized
+datatypes in CFITSIO (see @ref{Blank pixels} for a discussion on blank
+values). The values for the different types are mostly the lowest or
+highest possible value for that type (for unsigned types and 8-bit types,
+the maximum is used). So you can safely ignore the actual value and simply
+use these values to check. See explanation under the @ref{CFITSIO datatype}
+function for more on types of data in FITS.
+
address@hidden NaN
address@hidden isnan
address@hidden IEEE NaN
+The @code{float} and @code{double} types use the IEEE NaN values and for
+string it is a @code{NULL} pointer. By definition, a NaN value fails in
+every condition check, so a NaN value is not equal to itself and the check
address@hidden will fail even if the value in
address@hidden is NaN. Therefore, to check for blank values in floating
+point types be careful to use C's @code{isnan} function.
address@hidden deffn
+
+
address@hidden Structure gal_fits_key
+Structure for reading FITS header keywords. This structure will keep the
+name and value of one keyword. The value will be stored in the element
+corresponding to the type of the value. When multiple keywords must be
+read, you can define an array of this structure, for example the following
+declaration will allocate an array of five keywords to be read.
+
address@hidden
+struct gal_fits_key keys[5];
address@hidden example
+
+The names of the keywords can then be stored separately in the array and
+this expression will store the values in each element.
+
address@hidden
+gal_fits_read_keywords("filename.fits", hdu, gal_fits_key, 5);
address@hidden example
+
+The FITS standard defines a maximum length for the value of keyword, so the
+space for the @code{str} element is statically allocated
+(@code{FLEN_VALUE}, which is defined in CFITSIO). So if the string value is
+necessary where @code{gal_fits_key} is no longer available, then you have
+to allocate space dynamically and copy the string there.
address@hidden deftp
address@hidden
+struct gal_fits_key
address@hidden
+  int            status;        /* CFITSIO status.        */
+  char         *keyname;        /* Name of keyword.       */
+  int          datatype;        /* Type of keyword value. */
+  char  str[FLEN_VALUE];        /* String value.          */
+  unsigned char       u;        /* Byte value.            */
+  short               s;        /* Short integer value.   */
+  long                l;        /* Long integer value.    */
+  LONGLONG            L;        /* Long Long value.       */
+  float               f;        /* Float value.           */
+  double              d;        /* Double value.          */
address@hidden;
address@hidden example
+
+
+
address@hidden Structure gal_fits_key_ll
address@hidden Linked list
address@hidden last-in-first-out
address@hidden first-in-first-out
+Structure for writing FITS keywords. This structure is used for one
+keyword. However, with the @code{next} element, it can link to another
+keyword thus creating a linked list to add any number of keywords easily
+and at any step during your program. Adding new keywords doesn't have to be
+done manually, the @code{gal_fits_add_to_key_ll} and
address@hidden will add new keywords for you to the
+start or end of the list to make a last-in-first-out or first-in-last-out
+list.
address@hidden deftp
address@hidden
+struct gal_fits_key_ll
address@hidden
+  int                    kfree;   /* ==1, free keyword name.   */
+  int                    vfree;   /* ==1, free keyword value.  */
+  int                    cfree;   /* ==1, free comment.        */
+  int                 datatype;   /* Keyword value datatype.   */
+  char                *keyname;   /* Keyword Name.             */
+  void                  *value;   /* Keyword value.            */
+  char                *comment;   /* Keyword comment.          */
+  char                   *unit;   /* Keyword unit.             */
+  struct gal_fits_key_ll *next;   /* Pointer next keyword.     */
address@hidden;
address@hidden example
+
+
+
address@hidden FITS functions,  , FITS macros and data structures, FITS files 
(fits.h)
address@hidden FITS functions
+
+Gnuastro provides the following functions to deal with FITS data related
+operations. FITS data can have a variety of types, see @ref{CFITSIO
+datatype} for a discussion on this, in particular the integer variables
+named @code{datatype}, @code{bitpix}, and @code{tform}. See @ref{FITS
+macros and data structures} for the strure and macro definitions.
+
address@hidden void gal_fits_io_error (int @code{status}, char @code{*message})
+Report the input or output error as a string and print it along with a
+short statement that an error in CFITSIO occurred. All CFITSIO functions
+will change the value of @code{status} if an error occurs. This function
+will print the CFITSIO error string from the value of @code{status}
+followed by an optional @code{message} that you can add to it. If the value
+of @code{message} is @code{NULL}, then a default message will be printed.
address@hidden deftypefun
+
address@hidden int gal_fits_name_is_fits (char @code{*name})
+Return @code{1} if the string pointed by @code{name} is a standard FITS
+filename (or more generally: can be read by CFITSIO) and @code{0} if it
+isn't. See @ref{Arguments} for the standard FITS filenames.
address@hidden deftypefun
+
address@hidden int gal_fits_suffix_is_fits (char @code{*suffix})
+Return @code{1} if the string pointed by @code{suffix} is a standard FITS
+suffix (or more generally: can be read by CFITSIO) and @code{0} if it
+isn't. @code{suffix} can contain a dot or not (for example both
address@hidden and @file{fits} will return @code{1}. See @ref{Arguments} for
+the standard FITS filenames.
address@hidden deftypefun
+
address@hidden int gal_fits_bitpix_to_datatype (int @code{bitpix})
+Return the datatype corresponding to the given @code{bitpix} (value to the
address@hidden header keyword) in a FITS image.
address@hidden deftypefun
+
address@hidden int gal_fits_tform_to_datatype (char @code{tform})
+Return the datatype corresponding to the given @code{tform} character of a
+FITS table column: value to the @code{TFORM} header keyword for the
+column. Note that in the FITS standard, @code{TFORM} values are characters.
address@hidden deftypefun
+
address@hidden void gal_fits_img_bitpix_size (fitsfile @code{*fptr}, int 
@code{*bitpix}, long @code{*naxes})
+Return the datatype (in FITS @code{BITPIX} format) and image size of a FITS
+HDU specified with the @code{fitsfile} pointer (defined in CFITSIO). So the
+HDU must have been already opened. If the number of dimentions is not 2,
+this function will retun an error and abort.
address@hidden deftypefun
+
address@hidden {void *} gal_fits_datatype_blank (int @code{datatype})
+Allocate the necessary space and put the blank value of type
address@hidden in it. Finally, return the pointer to the allocated
+space. This pointer is commonly necessary when calling CFITSIO read
+functions as @code{nulval}. See @ref{CFITSIO datatype}.
address@hidden deftypefun
+
address@hidden {void *} gal_fits_datatype_alloc (size_t @code{size}, int 
@code{datatype})
+Allocate an array of @code{size} elements of type @code{datatype}. See
address@hidden datatype}.
address@hidden deftypefun
+
address@hidden 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}.
address@hidden deftypefun
+
address@hidden void gal_fits_change_type (void @code{*in}, int @code{inbitpix}, 
size_t @code{size}, int @code{anyblank}, void @code{**out}, int 
@code{outbitpix})
+Convert the @code{in} array (with @code{inbitpix} type) into an array of
+type @code{outbitpix} that is pointed by @code{out}. Space will be
+allocated for the output array within this function.
address@hidden deftypefun
+
address@hidden void gal_fits_num_hdus (char @file{*filename}, int 
@code{*numhdu})
+Find the number of HDUs in @file{filename} and store it in the space
+pointed to by @code{numhdu}.
address@hidden deftypefun
+
address@hidden void gal_fits_read_hdu (char @code{*filename}, char @code{*hdu}, 
unsigned char @code{img0_tab1}, fitsfile @code{**outfptr})
+Open the HDU @code{hdu} (a string) of the @file{filename} FITS file into
+the @code{outfptr}. See @option{--hdu} option in @ref{Input output} for the
+accepted HDU formats.
address@hidden deftypefun
+
address@hidden void gal_fits_read_keywords (char @code{*filename}, char 
@code{*hdu}, struct gal_fits_key @code{*keys}, size_t @code{num})
+Read @code{num} keywords (identified in the @code{keys} array) in the
address@hidden HDU of @file{filename}. See @ref{FITS macros and data
+structures} for the definition of @code{gal_fits_key} and its recommended
+usage with this function.
+
+CFITSIO will look for the next keyword starting from the last keyword
+found. Therefore, it is most efficient to specify the keywords in the same
+order as they appear in the desired HDU.
address@hidden deftypefun
+
address@hidden void gal_fits_add_to_key_ll (struct gal_fits_key_ll 
@code{**list}, int @code{datatype}, char @code{*keyname}, int @code{kfree}, 
void @code{*value}, int @code{vfree}, char @code{*comment}, int @code{cfree}, 
char @code{*unit})
+Add an element to the top of the @code{gal_fits_key_ll} linked list for
+writing keywords. This structure (or linked list) is used to write FITS
+keywords and is fully described in @ref{FITS macros and data
+structures}. Each variable also has the same name as the structure element
+that is described there.
+
address@hidden last-in-first-out
+Assuming all the keywords were added with this function, you will have a
+last-in-first-out list: as the the name suggests, the last keyword you add
+to the list will be the first one that gets popped out and thus written in
+the FITS file header.
address@hidden deftypefun
+
address@hidden void gal_fits_add_to_key_ll_end (struct gal_fits_key_ll 
@code{**list}, int @code{datatype}, char @code{*keyname}, int @code{kfree}, 
void @code{*value}, int @code{vfree}, char @code{*comment}, int @code{cfree}, 
char @code{*unit})
address@hidden first-in-first-out
+Similar to @code{gal_fits_add_to_key_ll}, except the keyword is added to
+the end of the list, creating a first-in-first-out list. Therefore the
+order the keywords are written to the FITS header is the same as the order
+you have called this function.
address@hidden deftypefun
+
address@hidden void gal_fits_file_name_in_keywords (char @code{*keynamebase}, 
char @code{*filename}, struct gal_fits_key_ll @code{**list})
+Put a filename into the @code{gal_fits_key_ll} list to later write into a
+HDU header. The FITS standard sets a maximum length for the value of a
+keyword. This creates problems with file names (including directories),
+because they can become very long. Therefore, when the filename is longer
+than the maximum length of a FITS keyword value, this function will break
+it into several keywords. The @code{keynamebase} string will be appended
+with a @code{_N} (N>0) and used as the keyword name.
address@hidden deftypefun
+
address@hidden void gal_fits_add_wcs_to_header (fitsfile @code{*fptr}, char 
@code{*wcsheader}, int @code{nkeyrec})
+Add the WCS information into the header of the HDU pointed to by
address@hidden The WCS information must already be converted into a long
+string with the FITS conventions. To help in identifying the WCS
+information, a few blank lines and a title will be added ontop.
address@hidden deftypefun
+
address@hidden void gal_fits_update_keys (fitsfile @code{*fptr}, struct 
gal_fits_key_ll @code{**keylist})
+Given the an opened FITS HDU (pointed to by @code{fptr}), this function
+will write, or update, all the keywords given in @code{keylist}. See
address@hidden macros and data structures} for more information on the
address@hidden structure or linked list.
address@hidden deftypefun
+
address@hidden void gal_fits_write_keys_version (fitsfile @code{*fptr}, struct 
gal_fits_key_ll @code{*headers}, char @code{*spack_string})
+Write or update (all the) keyword(s) in @code{headers} into the FITS
+pointer, but also the date, name of your program (@code{spack_string}),
+along with the verisons of Gnuastro, CFITSIO, WCSLIB (when available) into
+the header, see @ref{Output headers}.  Since the data processing depends on
+the versions of the libraries you have used, it is strongly recommended to
+include this information in every FITS output. See @ref{FITS macros and
+data structures} for more information on the @code{gal_fits_key_ll}
+structure or linked list.
address@hidden deftypefun
+
address@hidden void gal_fits_read_wcs_from_pointer (fitsfile @code{*fptr}, int 
@code{*nwcs}, struct wcsprm @code{**wcs}, size_t @code{hstartwcs}, size_t 
@code{hendwcs})
+Read the WCSLIB WCS structure (@code{wcs}, and @code{nwcs} the number of WCS
+structures) from the FITS pointer @code{fptr}. In some cases, it might be
+necessary to only consider header keywords between a certain range. You can
+define the range of keywords to look for WCS information with the
address@hidden and @code{hendwcs} arguments. The range of header keywords
+will only be considered when the value of @code{hstartwcs} is less than
address@hidden, so if you don't want to limit the range, set both values to
+0. After you have finished using the WCS structure, use
address@hidden(&nwcs,&wcs);} to free it.
+
address@hidden
address@hidden
address@hidden WCSLIB
address@hidden Thread-saftey
address@hidden is not thread-safe: } WCSLIB's @code{wcspih} function is
+used by to read the FITS keywords into WCSLIB's internal WCS
+structures. Unfortunately this function is not thread-safe. Therefore be
+sure to call that function, or Gnuastro's
address@hidden and @code{gal_fits_read_wcs}
+functions, when you aren't using threads.
address@hidden cartouche
address@hidden deftypefun
+
address@hidden void gal_fits_read_wcs (char @code{*filename}, char @code{*hdu}, 
size_t @code{hstartwcs}, size_t @code{hendwcs}, int @code{*nwcs}, struct wcsprm 
@code{**wcs})
+Read the WCSLIB WCS structure (@code{wcs} and @code{nwcs} the number of WCS
+structures) from a FITS file (@code{hdu} in @code{filename}). This is
+basically just a wrapper around the @code{gal_fits_read_wcs_from_pointer}
+function, see that function for more.
address@hidden deftypefun
+
address@hidden int gal_fits_hdu_to_array (char @code{*filename}, char 
@code{*hdu}, int @code{*bitpix}, void @code{**array}, size_t @code{*s0}, size_t 
@code{*s1})
+Read the FITS image (in the @code{hdu} extension of @code{filename}). The
+image array will be stored in @code{array} and the number of pixels in the
+first and second C axis will be stored in @code{s0} and @code{s1}. The type
+of the array will be kept in @code{bitpix}. See @option{--hdu} in
address@hidden output} for the acceptable formats of @code{hdu}.
address@hidden deftypefun
+
address@hidden void gal_fits_array_to_file (char @code{*filename}, char 
@code{*extname}, int @code{bitpix}, void @code{*array}, size_t @code{s0}, 
size_t @code{s1}, int @code{anyblank}, struct wcsprm @code{*wcs}, struct 
gal_fits_key_ll @code{*headers}, char @code{*spack_string})
+Write the array @code{array} (with sizes @code{s0} and @code{s1}, type
address@hidden, and WCS structure @code{wcs}) into the FITS file
address@hidden and extension name @code{extname}. If the array has any
+blank pixels, then you can set @code{anyblank} to 1. All the headers in
address@hidden will also be written to this extension and
address@hidden is the name of your program (which can include a
+version number), which will be written in the output header.
address@hidden deftypefun
+
address@hidden void gal_fits_atof_correct_wcs (char @code{*filename}, char 
@code{*hdu}, int @code{bitpix}, void @code{*array}, size_t @code{s0}, size_t 
@code{s1}, char @code{*wcsheader}, int @code{wcsnkeyrec}, double @code{*crpix}, 
char @code{*spack_string})
+This is essentially the same as @code{gal_fits_array_to_file}, but through
+the two element @code{crpix} array, you can change the final @code{CRPIX}
+keywords that will be written in the FITS file.
address@hidden deftypefun
+
address@hidden void gal_fits_table_size (fitsfile @code{*fitsptr}, size_t 
@code{*nrows}, size_t @code{*ncols})
+Get the number of rows (@code{nrows}) and columns (@code{ncols}) in a FITS
+table within the @code{fitsptr}.
address@hidden deftypefun
+
address@hidden int gal_fits_table_type (fitsfile @code{*fptr})
+Return the type of the table: @code{ASCII_TBL} and @code{BINARY_TBL} for an
+ASCII or binary table. These two macros are defined by CFITSIO.
address@hidden deftypefun
+
address@hidden void gal_fits_file_or_ext_name (char @code{*inputname}, char 
@code{*inhdu}, int @code{othernameset}, char @code{**othername}, char 
@code{*ohdu}, int @code{ohduset}, char @code{*type})
+This is mainly a function used in Gnuastro utilities. Since a FITS image
+can have many extensions, usually related data are stored within one FITS
+file. For example an image, its masked pixels, and the sky standard
+deviation of the noise are various extensions of one FITS file. It would be
+very inconvenient if the same file name would have to be repeated in a call
+to a utility for all images that are within one file.
+
+To easily manage things, within Gnuastro, each input variable also has an
+integer variable with the same name, but suffixed with @code{set}. The job
+of this function is to use the name of the main input image and based on
+the other arguments, determine what filename should be used for each
+type. The final argument (@code{type}) is the type of input you want, for
+example, if you were expecting a mask image, you can give the value
address@hidden"mask"} as type. @code{type} is just used to report errors.
address@hidden deftypefun
+
address@hidden void gal_fits_file_to_float (char @code{*inputname}, char 
@code{*maskname}, char @code{*inhdu}, char @code{*mhdu}, float @code{**img}, 
int @code{*inbitpix}, int @code{*anyblank}, size_t @code{*ins0}, size_t 
@code{*ins1})
+Read a FITS image HDU (@code{inhdu} in @file{inputname}) as a @code{float}
+type array. An optional mask image and mask hdu can also be given. Single
+precision floating point types are one of the most common types to store
+data: the observation noise is usually much larger than the extra precision
+(and thus volume in your computer, and slower processing) offered by double
+precision floating point types. With this function, so when you work
+internally with floating points, you can use this function to directly read
+a FITS image array into a floating point array.
address@hidden deftypefun
+
address@hidden void gal_fits_file_to_double (char @code{*inputname}, char 
@code{*maskname}, char @code{*inhdu}, char @code{*mhdu}, double @code{**img}, 
int @code{*inbitpix}, int @code{*anyblank}, size_t @code{*ins0}, size_t 
@code{*ins1})
+Similar to @code{gal_fits_file_to_float}, but for double precision floating
+point type. In some contexts, the internal operations must be done in
+double precision floating point types, irrespective of the input type and
+this function can be used to directly read a file into an array of this
+type.
address@hidden deftypefun
+
address@hidden void gal_fits_file_to_long (char @code{*inputname}, char 
@code{*inhdu}, long @code{**img}, int @code{*inbitpix}, int @code{*anyblank}, 
size_t @code{*ins0}, size_t @code{*ins1})
address@hidden Labeled image
address@hidden Segmentation map
+Similar to @code{gal_fits_file_to_float}, but will read the image specified
+by @file{inputname} (@code{inhdu}) into a long integer type. Long integer
+types are commonly used to store things like segmentation maps or labeled
+images.
address@hidden deftypefun
+
address@hidden void gal_fits_prep_float_kernel (char @code{*inputname}, char 
@code{*inhdu}, float @code{**outkernel}, size_t @code{*ins0}, size_t 
@code{*ins1})
address@hidden Convolution kernel
address@hidden Kernel: convolution
+Read @file{inputname} (@code{inhdu}) will be read as a floating point array
+to be used as a convolution kernel. Convolution kernels are commonly
+necessary in astronomical image processing, but they need to have certain
+properties: their dimensions have to be an odd number and they must not
+have any blank pixels. In both cases, this function will abort with an
+error notice.
address@hidden deftypefun
+
address@hidden@deftypefun
address@hidden@end deftypefun
+
 
 
address@hidden The TEMPLATE utility,  , Gnuastro library, Libraries
address@hidden The TEMPLATE utility
 
-The extra creativity offered by libraries comes at a cost: you have to
-actually write your @code{main} function in the programming language of
-your choice, and compile it before you can use it. So when an operation can
-be done in a Gnuastro utility, it is much more worthwhile to simply use the
-utility, instead of the underlying libraries. Historically, Gnuastro was
-first designed to be a collection of utilities, but as shared functions
-between the separate utilities grew, we used internal (not installed)
-libraries in the first (0.1) release and with the 0.2 release, the
-libraries are installed for general use, independent of the utilities. To
-define a new utility (that satisfies Gnuastro's common behaviour explained
-in @ref{Common behavior}) for common library operations you can use the
-template utility in @file{src/TEMPLATE/}. You just have to copy that
-directory into a new one, choose a name for your new utility and begin
-writing your code (also see @ref{Mandatory source code files}).
 
 
 
@@ -15310,6 +15793,7 @@ read along.
 * Coding conventions::          Basic conventions for coding structure.
 * Multithreaded programming::   Gnuastro's multithreaded programming style.
 * Documentation::               Documentation is an integral part of Gnuastro.
+* The TEMPLATE utility::        A template to create new utilities.
 @end menu
 
 @node Mandatory source code files, Coding conventions, Program source, Program 
source
@@ -15789,7 +16273,7 @@ and also the ones that benefit most from threads, see 
the LLNL
 address@hidden@url{https://computing.llnl.gov/tutorials/parallel_comp/}}.
 
 
address@hidden Documentation,  , Multithreaded programming, Program source
address@hidden Documentation, The TEMPLATE utility, Multithreaded programming, 
Program source
 @subsection Documentation
 
 Documentation (this book) is an integral part of Gnuastro.
@@ -15864,6 +16348,72 @@ the book or had known of Gnuastro before you made your 
change).
 
 
 
address@hidden The TEMPLATE utility,  , Documentation, Program source
address@hidden The TEMPLATE utility
+
+The @file{src/} directory contains the source code for each utility in a
+separate subdirectory. The @file{src/TEMPLATE} directory contains the
+bare-minimum files to create a new utility. It can be used to understand
+the conventions described in @ref{Program source}, or to easily create a
+new utility.
+
+The extra creativity offered by libraries comes at a cost: you have to
+actually write your @code{main} function in the programming language of
+your choice, and compile it before you can use it. You will also need to
+find a way to pass input and output information to the function. So when an
+operation can be done in a Gnuastro utility, it is much more worthwhile to
+simply use the utility, instead of the underlying libraries.
+
+Historically, Gnuastro was first designed to be a collection of utilities,
+but as shared functions between the separate utilities grew, we used
+internal (not installed) libraries in the first (0.1) release and with the
+0.2 release, the libraries are installed for general use, independent of
+the utilities. To define your new utility based on this template, just take
+the following steps:
+
address@hidden
address@hidden
+Select a name for your new utility (for example @file{myutil}).
+
address@hidden
+Copy the @file{TEMPLATE} directory to a directory with your utility's name:
address@hidden
+$ cp -R src/TEMPLATE src/myutil
address@hidden example
+
address@hidden
+Open @file{configure.ac} in the top Gnuastro source. This file manages the
+operations that are done when a user runs @file{./configure}. Going down
+the file, you will notice repetative parts for each utility. Copy one of
+those and correct the names of the copied utility to your new utility
+name. We follow alphabetic ordering here, so please place it
+correctly. There are multiple places where this has to be done, so be
+patient and go down to the bottom of the file. Ultimately add
address@hidden/myutil/Makefile} to @code{AC_CONFIG_FILES}, only here the
+ordering depends on the length of the name.
+
address@hidden
+Open @file{Makefile.am} in the top Gnuastro source. Similar to the previous
+step, add your new utility similar to all the other utilites.
+
address@hidden
+Change @code{TEMPLATE} to @code{myutil} in the file names and contents of
+the files in the @file{src/myutil/} directory.
+
address@hidden
+Run the following command to re-build the configuration and build system to
+include your new utility:
address@hidden
+$ autoreconf -f
address@hidden example
address@hidden enumerate
+
+
+
+
+
+
+
 @node Building and debugging, Test scripts, Program source, Developing
 @section Building and debugging
 
@@ -16489,6 +17039,11 @@ arXiv:1505.01664}.
 (@file{astsubtractsky}, @ref{SubtractSky}) Find and subtract sky value by
 comparing the mode and median on a mesh grid.
 
address@hidden Table
+(@file{asttable}, @ref{Table}) Convert FITS binary and ASCII tables into
+other such tables, print them on the command-line, save them in a plain
+text file, or get the FITS table information.
+
 @end table
 
 
@@ -16783,7 +17338,7 @@ $ ./pgdemoXX
 
 @c Print the index and finish:
 @node Index,  , GNU Free Documentation License, Top
address@hidden Function index
address@hidden Index: Macros, structures and functions
 @printindex fn
 @unnumbered Index
 @printindex cp
diff --git a/lib/fits.c b/lib/fits.c
index e5d93d4..0c1a238 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -94,13 +94,13 @@ gal_fits_name_is_fits(char *name)
 
 
 int
-gal_fits_name_is_fits_suffix(char *name)
+gal_fits_suffix_is_fits(char *suffix)
 {
-  if (strcmp(name, "fits") == 0 || strcmp(name, ".fits") == 0
-      || strcmp(name, "fits.gz") == 0 || strcmp(name, ".fits.gz") == 0
-      || strcmp(name, "fits.Z") == 0 || strcmp(name, ".fits.Z") == 0
-      || strcmp(name, "imh") == 0 || strcmp(name, ".imh") == 0
-      || strcmp(name, "fits.fz") == 0 || strcmp(name, ".fits.fz") == 0)
+  if (strcmp(suffix, "fits") == 0 || strcmp(suffix, ".fits") == 0
+      || strcmp(suffix, "fits.gz") == 0 || strcmp(suffix, ".fits.gz") == 0
+      || strcmp(suffix, "fits.Z") == 0 || strcmp(suffix, ".fits.Z") == 0
+      || strcmp(suffix, "imh") == 0 || strcmp(suffix, ".imh") == 0
+      || strcmp(suffix, "fits.fz") == 0 || strcmp(suffix, ".fits.fz") == 0)
    return 1;
  else
    return 0;
@@ -127,30 +127,9 @@ gal_fits_name_is_fits_suffix(char *name)
 /*************************************************************
  **************      BITPIX Dependancies       ***************
  *************************************************************/
-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)");
-}
-
-
-
-
-
 /* Set datatype (in CFITSIO) based on BITPIX. */
 int
-gal_fits_bitpix_to_dtype(int bitpix)
+gal_fits_bitpix_to_datatype(int bitpix)
 {
   switch(bitpix)
     {
@@ -188,7 +167,7 @@ gal_fits_bitpix_to_dtype(int bitpix)
    column. So this function will do the conversion based on the CFITSIO
    manual.*/
 int
-gal_fits_tform_to_dtype(char tform)
+gal_fits_tform_to_datatype(char tform)
 {
   switch(tform)
     {
@@ -227,7 +206,7 @@ gal_fits_tform_to_dtype(char tform)
 
   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_tform_to_dtype function in fits.c.");
+        "gal_fits_tform_to_datatype function in fits.c.");
   return -1;
 }
 
@@ -235,6 +214,27 @@ gal_fits_tform_to_dtype(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)
 {
@@ -671,7 +671,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_dtype(outbitpix) );
+  *out=gal_fits_datatype_alloc(size, gal_fits_bitpix_to_datatype(outbitpix) );
   switch(outbitpix)
     {
     case BYTE_IMG:
@@ -1082,22 +1082,22 @@ gal_fits_read_hdu(char *filename, char *hdu, unsigned 
char img0_tab1,
 
 
 
-/* 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.
+/* Read keywords from a FITS file. The gal_fits_key pointer is an array of
+   gal_fits_key structures, which keep the basic information for each
+   keyword that is to be read and also stores the value in the appropriate
+   type.
 
    ABOUT THE STRING VALUES:
 
    The space for a string value is statically allocated within the
-   `gal_fits_read_header_keys' structure (to be `FLEN_VALUE' characters,
-   `FLEN_VALUE' is defined by CFITSIO). So if the value is necessary where
-   `gal_fits_read_header_keys' is no longer available, then you have to
-   allocate space dynamically and copy the string there.
+   `gal_fits_key' structure (to be `FLEN_VALUE' characters, `FLEN_VALUE' is
+   defined by CFITSIO). So if the value is necessary where `gal_fits_key'
+   is no longer available, then you have to allocate space dynamically and
+   copy the string there.
 */
 void
-gal_fits_read_keywords(char *filename, char *hdu,
-                       struct gal_fits_read_header_keys *keys, size_t num)
+gal_fits_read_keywords(char *filename, char *hdu, struct gal_fits_key *keys,
+                       size_t num)
 {
   int status=0;
   char *ffname;
@@ -1208,19 +1208,18 @@ gal_fits_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_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)
+gal_fits_add_to_key_ll(struct gal_fits_key_ll **list, int datatype,
+                       char *keyname, int kfree, void *value, int vfree,
+                       char *comment, int cfree, char *unit)
 {
-  struct gal_fits_header_ll *newnode;
+  struct gal_fits_key_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_fits_header_ll");
+          "linkedlist: new element in gal_fits_key_ll");
   newnode->datatype=datatype;
   newnode->keyname=keyname;
   newnode->value=value;
@@ -1239,19 +1238,18 @@ gal_fits_add_to_fits_header_ll(struct 
gal_fits_header_ll **list,
 
 
 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)
+gal_fits_add_to_key_ll_end(struct gal_fits_key_ll **list, int datatype,
+                           char *keyname, int kfree, void *value, int vfree,
+                           char *comment, int cfree, char *unit)
 {
-  struct gal_fits_header_ll *newnode, *tmp;
+  struct gal_fits_key_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_fits_header_ll");
+          "linkedlist: new element in gal_fits_key_ll");
   newnode->datatype=datatype;
   newnode->keyname=keyname;
   newnode->value=value;
@@ -1281,7 +1279,7 @@ gal_fits_add_to_fits_header_ll_end(struct 
gal_fits_header_ll **list,
 
 void
 gal_fits_file_name_in_keywords(char *keynamebase, char *filename,
-                               struct gal_fits_header_ll **list)
+                               struct gal_fits_key_ll **list)
 {
   char *keyname, *value;
   size_t numkey=1, maxlength;
@@ -1317,8 +1315,8 @@ gal_fits_file_name_in_keywords(char *keynamebase, char 
*filename,
          length was copied. */
       if(value[maxlength-1]=='\0')
         {
-          gal_fits_add_to_fits_header_ll_end(list, TSTRING, keyname, 1,
-                                             value, 1, NULL, 0, NULL);
+          gal_fits_add_to_key_ll_end(list, TSTRING, keyname, 1,
+                                     value, 1, NULL, 0, NULL);
           break;
         }
       else
@@ -1339,8 +1337,8 @@ gal_fits_file_name_in_keywords(char *keynamebase, char 
*filename,
                   filename, maxlength);
 
           /* Convert the last useful character and save the file name.*/
-          gal_fits_add_to_fits_header_ll_end(list, TSTRING, keyname, 1,
-                                             value, 1, NULL, 0, NULL);
+          gal_fits_add_to_key_ll_end(list, TSTRING, keyname, 1,
+                                     value, 1, NULL, 0, NULL);
           i+=j+1;
         }
     }
@@ -1385,15 +1383,14 @@ gal_fits_add_wcs_to_header(fitsfile *fptr, char 
*wcsheader, int nkeyrec)
 
 
 
-/* Write the keywords in the gal_fits_header_ll linked list to the FITS
+/* Write the keywords in the gal_fits_key_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_fits_update_keys(fitsfile *fptr,
-                     struct gal_fits_header_ll **keylist)
+gal_fits_update_keys(fitsfile *fptr, struct gal_fits_key_ll **keylist)
 {
   int status=0;
-  struct gal_fits_header_ll *tmp, *ttmp;
+  struct gal_fits_key_ll *tmp, *ttmp;
 
   tmp=*keylist;
   while(tmp!=NULL)
@@ -1434,9 +1431,8 @@ gal_fits_update_keys(fitsfile *fptr,
 
 
 void
-gal_fits_copyright_end(fitsfile *fptr,
-                       struct gal_fits_header_ll *headers,
-                       char *spack_string)
+gal_fits_write_keys_version(fitsfile *fptr, struct gal_fits_key_ll *headers,
+                            char *spack_string)
 {
   size_t i;
   int status=0;
@@ -1532,8 +1528,7 @@ gal_fits_copyright_end(fitsfile *fptr,
    Don't call this function within a thread or use a mutex.
 */
 void
-gal_fits_read_wcs_from_pointer(fitsfile *fptr, int *nwcs,
-                               struct wcsprm **wcs,
+gal_fits_read_wcs_from_pointer(fitsfile *fptr, int *nwcs, struct wcsprm **wcs,
                                size_t hstartwcs, size_t hendwcs)
 {
   /* Declaratins: */
@@ -1660,12 +1655,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_dtype(*bitpix);
+  datatype=gal_fits_bitpix_to_datatype(*bitpix);
   bitblank=gal_fits_datatype_blank(datatype);
   *array=gal_fits_datatype_alloc(*s0 * *s1, datatype);
 
   /* Read the image into the allocated array: */
-  fits_read_pix(fptr, gal_fits_bitpix_to_dtype(*bitpix), fpixel,
+  fits_read_pix(fptr, gal_fits_bitpix_to_datatype(*bitpix), fpixel,
                 *s0 * *s1, bitblank, *array, &anyblank, &status);
   if(status) gal_fits_io_error(status, NULL);
   free(bitblank);
@@ -1701,11 +1696,9 @@ gal_fits_hdu_to_array(char *filename, char *hdu, int 
*bitpix,
  ******************      Array to FITS      ******************
  *************************************************************/
 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)
+gal_fits_array_to_file(char *filename, char *extname, int bitpix, void *array,
+                       size_t s0, size_t s1, int anyblank, struct wcsprm *wcs,
+                       struct gal_fits_key_ll *headers, char *spack_string)
 {
   int nkeyrec;
   void *blank;
@@ -1714,7 +1707,7 @@ gal_fits_array_to_file(char *filename, char *hdu, int 
bitpix,
   int status=0, datatype;
   long fpixel=1, naxis=2, nelements, naxes[]={s1,s0};
 
-  datatype=gal_fits_bitpix_to_dtype(bitpix);
+  datatype=gal_fits_bitpix_to_datatype(bitpix);
   nelements=naxes[0]*naxes[1];
 
   if(access(filename,F_OK) != -1 )
@@ -1729,14 +1722,14 @@ gal_fits_array_to_file(char *filename, char *hdu, int 
bitpix,
     if(bitpix==BYTE_IMG || bitpix==SHORT_IMG
        || bitpix==LONG_IMG || bitpix==LONGLONG_IMG)
       {
-        blank=gal_fits_datatype_blank( gal_fits_bitpix_to_dtype(bitpix) );
+        blank=gal_fits_datatype_blank( gal_fits_bitpix_to_datatype(bitpix) );
         if(fits_write_key(fptr, datatype, "BLANK", blank,
                           "Pixels with no data.", &status) )
           gal_fits_io_error(status, "adding the BLANK keyword");
         free(blank);
       }
 
-  fits_write_key(fptr, TSTRING, "EXTNAME", hdu, "", &status);
+  fits_write_key(fptr, TSTRING, "EXTNAME", extname, "", &status);
   gal_fits_io_error(status, NULL);
 
   if(wcs)
@@ -1749,7 +1742,7 @@ gal_fits_array_to_file(char *filename, char *hdu, int 
bitpix,
       gal_fits_add_wcs_to_header(fptr, wcsheader, nkeyrec);
     }
 
-  gal_fits_copyright_end(fptr, headers, spack_string);
+  gal_fits_write_keys_version(fptr, headers, spack_string);
 
   fits_close_file(fptr, &status);
   gal_fits_io_error(status, NULL);
@@ -1763,16 +1756,15 @@ gal_fits_array_to_file(char *filename, char *hdu, int 
bitpix,
    `gal_fits_array_to_file' except that the WCS structure's CRPIX values
    have changed. */
 void
-gal_fits_atof_correct_wcs(char *filename, char *hdu, int bitpix,
-                          void *array, size_t s0, size_t s1,
-                          char *wcsheader, int wcsnkeyrec,
+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)
 {
   fitsfile *fptr;
   int status=0, datatype;
   long fpixel=1, naxis=2, nelements, naxes[]={s1,s0};
 
-  datatype=gal_fits_bitpix_to_dtype(bitpix);
+  datatype=gal_fits_bitpix_to_datatype(bitpix);
   nelements=naxes[0]*naxes[1];
 
   if(access(filename,F_OK) != -1 )
@@ -1803,7 +1795,7 @@ gal_fits_atof_correct_wcs(char *filename, char *hdu, int 
bitpix,
         }
     }
 
-  gal_fits_copyright_end(fptr, NULL, spack_string);
+  gal_fits_write_keys_version(fptr, NULL, spack_string);
 
   fits_close_file(fptr, &status);
   gal_fits_io_error(status, NULL);
diff --git a/lib/gnuastro/fits.h b/lib/gnuastro/fits.h
index f867861..ba1703a 100644
--- a/lib/gnuastro/fits.h
+++ b/lib/gnuastro/fits.h
@@ -78,25 +78,6 @@ __BEGIN_C_DECLS  /* From C++ preparations */
 
 
 
-
-/*
-
-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          *******************
  *************************************************************/
@@ -107,10 +88,7 @@ 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);
+gal_fits_suffix_is_fits(char *suffix);
 
 
 
@@ -120,35 +98,35 @@ gal_fits_num_hdus(char *filename, int *numhdu);
  ******************         Header          ******************
  *************************************************************/
 /* To create a linked list of headers. */
-struct gal_fits_header_ll
+struct gal_fits_key_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.         */
+  int                    kfree;   /* ==1, free keyword name.   */
+  int                    vfree;   /* ==1, free keyword value.  */
+  int                    cfree;   /* ==1, free comment.        */
+  int                 datatype;   /* Keyword value datatype.   */
+  char                *keyname;   /* Keyword Name.             */
+  void                  *value;   /* Keyword value.            */
+  char                *comment;   /* Keyword comment.          */
+  char                   *unit;   /* Keyword unit.             */
+  struct gal_fits_key_ll *next;   /* Pointer next keyword.     */
 };
 
 
 
 
 
-struct gal_fits_read_header_keys
+struct gal_fits_key
 {
-  int            status;
-  char         *keyname;
-  int          datatype;
-  char  str[FLEN_VALUE];
-  unsigned char       u;
-  short               s;
-  long                l;
-  LONGLONG            L;
-  float               f;
-  double              d;
+  int            status;        /* CFITSIO status.        */
+  char         *keyname;        /* Name of keyword.       */
+  int          datatype;        /* Type of keyword value. */
+  char  str[FLEN_VALUE];        /* String value.          */
+  unsigned char       u;        /* Byte value.            */
+  short               s;        /* Short integer value.   */
+  long                l;        /* Long integer value.    */
+  LONGLONG            L;        /* Long Long value.       */
+  float               f;        /* Float value.           */
+  double              d;        /* Double value.          */
 };
 
 
@@ -156,37 +134,32 @@ struct gal_fits_read_header_keys
 
 
 void
-gal_fits_read_keywords(char *filename, char *hdu,
-                       struct gal_fits_read_header_keys *out,
+gal_fits_read_keywords(char *filename, char *hdu, struct gal_fits_key *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);
+gal_fits_add_to_key_ll(struct gal_fits_key_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);
+gal_fits_add_to_key_ll_end(struct gal_fits_key_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);
+                               struct gal_fits_key_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);
+gal_fits_update_keys(fitsfile *fptr, struct gal_fits_key_ll **keylist);
 
 void
-gal_fits_copyright_end(fitsfile *fptr,
-                       struct gal_fits_header_ll *headers,
-                       char *spack_string);
+gal_fits_write_keys_version(fitsfile *fptr, struct gal_fits_key_ll *headers,
+                            char *spack_string);
 
 
 
@@ -205,7 +178,7 @@ void
 gal_fits_blank_to_value(void *array, int datatype, size_t size, void *value);
 
 int
-gal_fits_bitpix_to_dtype(int bitpix);
+gal_fits_bitpix_to_datatype(int bitpix);
 
 void
 gal_fits_img_bitpix_size(fitsfile *fptr, int *bitpix, long *naxis);
@@ -222,6 +195,9 @@ gal_fits_change_type(void *in, int inbitpix, size_t size, 
int anyblank,
                      void **out, int outbitpix);
 
 void
+gal_fits_num_hdus(char *filename, int *numhdu);
+
+void
 gal_fits_read_wcs_from_pointer(fitsfile *fptr, int *nwcs,
                                struct wcsprm **wcs,
                                size_t hstart, size_t hend);
@@ -237,8 +213,7 @@ gal_fits_hdu_to_array(char *filename, char *hdu, int 
*bitpix,
 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,
+                       struct wcsprm *wcs, struct gal_fits_key_ll *headers,
                        char *spack_string);
 
 void
@@ -255,7 +230,7 @@ gal_fits_atof_correct_wcs(char *filename, char *hdu, int 
bitpix,
 /**********                  Table                 ************/
 /**************************************************************/
 int
-gal_fits_tform_to_dtype(char tform);
+gal_fits_tform_to_datatype(char tform);
 
 void
 gal_fits_table_size(fitsfile *fitsptr, size_t *nrows, size_t *ncols);
diff --git a/src/convertt/ui.c b/src/convertt/ui.c
index 0a943f8..7cfe044 100644
--- a/src/convertt/ui.c
+++ b/src/convertt/ui.c
@@ -464,7 +464,7 @@ sanitycheck(struct converttparams *p)
       if(gal_fits_name_is_fits(cp->output))
         {
           p->outputtype=FITSFORMAT;
-          if( gal_fits_name_is_fits_suffix(cp->output) )
+          if( gal_fits_suffix_is_fits(cp->output) )
             adddotautomaticoutput(p);
         }
       else if(nameisjpeg(cp->output))
diff --git a/src/header/header.c b/src/header/header.c
index 56ff673..16ea9eb 100644
--- a/src/header/header.c
+++ b/src/header/header.c
@@ -79,11 +79,11 @@ haserror(struct headerparams *p, int actionid, char 
*string, int status)
 
 
 void
-writeupdatekeys(fitsfile *fptr, struct gal_fits_header_ll **keylist,
+writeupdatekeys(fitsfile *fptr, struct gal_fits_key_ll **keylist,
                 int u1w2)
 {
   int status=0;
-  struct gal_fits_header_ll *tmp, *ttmp;
+  struct gal_fits_key_ll *tmp, *ttmp;
 
   tmp=*keylist;
   while(tmp!=NULL)
diff --git a/src/header/main.h b/src/header/main.h
index ada8cd8..caa820d 100644
--- a/src/header/main.h
+++ b/src/header/main.h
@@ -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_fits_header_ll  *update; /* Linked list of keywords to update. */
-  struct gal_fits_header_ll  *write; /* Linked list of keywords to add. */
+  struct gal_fits_key_ll *update; /* Linked list of keywords to update. */
+  struct gal_fits_key_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 f2819aa..96251f2 100644
--- a/src/header/ui.c
+++ b/src/header/ui.c
@@ -268,7 +268,7 @@ setuprename(struct headerparams *p)
 
 void
 fillfitsheaderll(struct gal_linkedlist_stll *input,
-                 struct gal_fits_header_ll **output)
+                 struct gal_fits_key_ll **output)
 {
   long l, *lp;
   void *fvalue;
@@ -376,8 +376,8 @@ fillfitsheaderll(struct gal_linkedlist_stll *input,
         }
 
 
-      gal_fits_add_to_fits_header_ll(output, datatype, keyname, 0,
-                                     fvalue, vfree, comment, 0, unit);
+      gal_fits_add_to_key_ll(output, datatype, keyname, 0,
+                             fvalue, vfree, comment, 0, unit);
       free(original);
     }
 }
diff --git a/src/imgcrop/crop.c b/src/imgcrop/crop.c
index 244f3cd..b09d52e 100644
--- a/src/imgcrop/crop.c
+++ b/src/imgcrop/crop.c
@@ -685,7 +685,7 @@ onecrop(struct cropparams *crp)
   char basename[FLEN_KEYWORD];
   long fpixel_i[2] , lpixel_i[2];
   fitsfile *ifp=crp->infits, *ofp;
-  struct gal_fits_header_ll *headers=NULL;
+  struct gal_fits_key_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];
@@ -756,9 +756,9 @@ onecrop(struct cropparams *crp)
       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_fits_add_to_fits_header_ll_end(&headers, TSTRING, regionkey, 0,
-                                         region, 0, "Range of pixels "
-                                         "used for this output.", 0, NULL);
+      gal_fits_add_to_key_ll_end(&headers, TSTRING, regionkey, 0, region, 0,
+                                 "Range of pixels used for this output.", 0,
+                                 NULL);
       gal_fits_update_keys(ofp, &headers);
 
 
@@ -828,7 +828,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_dtype(bitpix) );
+  array=gal_fits_datatype_alloc(size, gal_fits_bitpix_to_datatype(bitpix) );
   if( fits_read_subset(ofp, p->datatype, fpixel, lpixel, inc,
                        p->bitnul, array, &anynul, &status) )
     gal_fits_io_error(status, NULL);
diff --git a/src/imgcrop/imgcrop.c b/src/imgcrop/imgcrop.c
index 2f17b09..674ee2c 100644
--- a/src/imgcrop/imgcrop.c
+++ b/src/imgcrop/imgcrop.c
@@ -112,7 +112,7 @@ imgmodecrop(void *inparam)
           log->centerfilled=iscenterfilled(crp);
 
           /* Add the final headers and close output FITS image: */
-          gal_fits_copyright_end(crp->outfits, NULL, SPACK_STRING);
+          gal_fits_write_keys_version(crp->outfits, NULL, SPACK_STRING);
           status=0;
           if( fits_close_file(crp->outfits, &status) )
             gal_fits_io_error(status, "CFITSIO could not close "
@@ -200,7 +200,7 @@ wcsmodecrop(void *inparam)
         {
           log->centerfilled=iscenterfilled(crp);
 
-          gal_fits_copyright_end(crp->outfits, NULL, SPACK_STRING);
+          gal_fits_write_keys_version(crp->outfits, NULL, SPACK_STRING);
           status=0;
           if( fits_close_file(crp->outfits, &status) )
             gal_fits_io_error(status, "CFITSIO could not close the "
diff --git a/src/imgcrop/ui.c b/src/imgcrop/ui.c
index 61813c0..5144a51 100644
--- a/src/imgcrop/ui.c
+++ b/src/imgcrop/ui.c
@@ -634,7 +634,7 @@ preparearrays(struct imgcropparams *p)
       if(firstbitpix==0)
         {
           firstbitpix=p->bitpix;
-          p->datatype=gal_fits_bitpix_to_dtype(p->bitpix);
+          p->datatype=gal_fits_bitpix_to_datatype(p->bitpix);
           p->bitnul=gal_fits_datatype_blank(p->datatype);
         }
       else if(firstbitpix!=p->bitpix)
diff --git a/src/imgwarp/imgwarp.c b/src/imgwarp/imgwarp.c
index 62624af..2786bc3 100644
--- a/src/imgwarp/imgwarp.c
+++ b/src/imgwarp/imgwarp.c
@@ -431,7 +431,7 @@ correctwcssaveoutput(struct imgwarpparams *p)
   void *array;
   double *m=p->matrix;
   char keyword[9*FLEN_KEYWORD];
-  struct gal_fits_header_ll *headers=NULL;
+  struct gal_fits_key_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]};
@@ -471,10 +471,10 @@ correctwcssaveoutput(struct imgwarpparams *p)
   for(i=0;i<9;++i)
     {
       sprintf(&keyword[i*FLEN_KEYWORD], "WMTX%lu_%lu", i/3+1, i%3+1);
-      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);
+      gal_fits_add_to_key_ll_end(&headers, TDOUBLE,
+                                 &keyword[i*FLEN_KEYWORD], 0,
+                                 &p->matrix[i], 0, "Warp matrix "
+                                 "element value.", 0, NULL);
     }
 
   /* Save the output: */
diff --git a/src/mkcatalog/ui.c b/src/mkcatalog/ui.c
index 7c86b7e..881561e 100644
--- a/src/mkcatalog/ui.c
+++ b/src/mkcatalog/ui.c
@@ -850,8 +850,8 @@ void
 sanitycheck(struct mkcatalogparams *p)
 {
   struct uiparams *up=&p->up;
+  struct gal_fits_key keys[1];
   struct gal_commonparams *cp=&p->cp;
-  struct gal_fits_read_header_keys keys[1];
 
   /* Make sure the input file exists. */
   gal_checkset_check_file(up->inputname);
@@ -1008,7 +1008,7 @@ readkeywords(struct mkcatalogparams *p)
   long numobjects;
   size_t size=p->s0*p->s1;
   struct uiparams *up=&p->up;
-  struct gal_fits_read_header_keys keys[2];
+  struct gal_fits_key keys[2];
 
   /* Read keywords from the standard deviation image:  */
   keys[0].keyname="MINSTD";   keys[0].datatype=TFLOAT;
diff --git a/src/mknoise/mknoise.c b/src/mknoise/mknoise.c
index 830f94c..e4109c6 100644
--- a/src/mknoise/mknoise.c
+++ b/src/mknoise/mknoise.c
@@ -55,7 +55,7 @@ convertsaveoutput(struct mknoiseparams *p)
 {
   void *array;
   char keyname1[FLEN_KEYWORD];
-  struct gal_fits_header_ll *headers=NULL;
+  struct gal_fits_key_ll *headers=NULL;
   char keyname2[FLEN_KEYWORD], keyname3[FLEN_KEYWORD];
   char keyname4[FLEN_KEYWORD], keyname5[FLEN_KEYWORD];
 
@@ -72,26 +72,24 @@ convertsaveoutput(struct mknoiseparams *p)
   /* Add the proper information to the header of the output: */
   gal_fits_file_name_in_keywords("INF", p->up.inputname, &headers);
   strcpy(keyname1, "BCKGRND");
-  gal_fits_add_to_fits_header_ll_end(&headers, TDOUBLE, keyname1, 0,
-                                     &p->mbackground, 0, "Background "
-                                     "value (in magnitude) for noise.",
-                                     0, NULL);
+  gal_fits_add_to_key_ll_end(&headers, TDOUBLE, keyname1, 0,
+                             &p->mbackground, 0, "Background "
+                             "value (in magnitude) for noise.",
+                             0, NULL);
   strcpy(keyname2, "BZRPNT");
-  gal_fits_add_to_fits_header_ll_end(&headers, TDOUBLE, keyname2, 0,
-                                     &p->zeropoint, 0, "Zeropoint "
-                                     "magnitude of image.", 0, NULL);
+  gal_fits_add_to_key_ll_end(&headers, TDOUBLE, keyname2, 0, &p->zeropoint,
+                             0, "Zeropoint magnitude of image.", 0, NULL);
   strcpy(keyname3, "STDADD");
-  gal_fits_add_to_fits_header_ll_end(&headers, TDOUBLE, keyname3, 0,
-                                     &p->stdadd, 0, "Instrumental noise "
-                                     "in units of flux.", 0, NULL);
+  gal_fits_add_to_key_ll_end(&headers, TDOUBLE, keyname3, 0, &p->stdadd, 0,
+                             "Instrumental noise in units of flux.", 0, NULL);
   strcpy(keyname4, "RNGTYPE");
-  gal_fits_add_to_fits_header_ll_end(&headers, TSTRING, keyname4, 0,
-                                     &p->rng_type, 0, "Random number "
-                                     "generator (by GSL) type.", 0, NULL);
+  gal_fits_add_to_key_ll_end(&headers, TSTRING, keyname4, 0, &p->rng_type,
+                             0, "Random number generator (by GSL) type.",
+                             0, NULL);
   strcpy(keyname5, "RNGSEED");
-  gal_fits_add_to_fits_header_ll_end(&headers, TLONG, keyname5, 0,
-                                     &p->rng_seed, 0, "Random number "
-                                     "generator (by GSL) seed.", 0, NULL);
+  gal_fits_add_to_key_ll_end(&headers, TLONG, keyname5, 0, &p->rng_seed,
+                             0, "Random number generator (by GSL) seed.",
+                             0, NULL);
 
   /* Save the output: */
   gal_fits_array_to_file(p->cp.output, "NoiseAdded", p->inputbitpix,
diff --git a/src/noisechisel/noisechisel.c b/src/noisechisel/noisechisel.c
index b0efc83..ab34441 100644
--- a/src/noisechisel/noisechisel.c
+++ b/src/noisechisel/noisechisel.c
@@ -61,7 +61,7 @@ makeoutput(struct noisechiselparams *p)
   double *dpt;
   long num[0];
   float *sky=NULL, *std=NULL;
-  struct gal_fits_header_ll *keys=NULL;
+  struct gal_fits_key_ll *keys=NULL;
   size_t s0=p->smp.s0, s1=p->smp.s1;
 
 
@@ -72,17 +72,14 @@ makeoutput(struct noisechiselparams *p)
 
   /* Add the necessary FITS keywords for MakeCatalog when reading the
      objects image. */
-  gal_fits_add_to_fits_header_ll(&keys, TSTRING, "WCLUMPS", 0, "yes", 0,
-                                 "Is there a clumps image companion?",
-                                 0, NULL);
+  gal_fits_add_to_key_ll(&keys, TSTRING, "WCLUMPS", 0, "yes", 0,
+                         "Is there a clumps image companion?", 0, NULL);
   num[0]=p->numobjects-1;
-  gal_fits_add_to_fits_header_ll(&keys, TLONG, "NOBJS", 0, num, 0,
-                                 "Number of objects in the image.", 0,
-                                 NULL);
+  gal_fits_add_to_key_ll(&keys, TLONG, "NOBJS", 0, num, 0,
+                         "Number of objects in the image.", 0, NULL);
   dpt=&p->detsn;
-  gal_fits_add_to_fits_header_ll(&keys, TDOUBLE, "DETSN", 0, dpt, 0,
-                                 "Signal to noise of true "
-                                 "pseudo-detections.", 0, NULL);
+  gal_fits_add_to_key_ll(&keys, TDOUBLE, "DETSN", 0, dpt, 0,
+                         "Signal to noise of true pseudo-detections.", 0, 
NULL);
   gal_fits_array_to_file(p->cp.output, "Objects", LONG_IMG, p->olab,
                          s0, s1, p->anyblank, p->wcs, keys,
                          SPACK_STRING);
@@ -94,13 +91,11 @@ 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_fits_add_to_fits_header_ll(&keys, TLONG, "NCLUMPS", 0, num, 0,
-                                 "Number of clumps in the image.", 0,
-                                 NULL);
+  gal_fits_add_to_key_ll(&keys, TLONG, "NCLUMPS", 0, num, 0,
+                         "Number of clumps in the image.", 0, NULL);
   dpt=&p->clumpsn;
-  gal_fits_add_to_fits_header_ll(&keys, TDOUBLE, "CLUMPSN", 0, dpt, 0,
-                                 "Signal to noise of true clumps.", 0,
-                                 NULL);
+  gal_fits_add_to_key_ll(&keys, TDOUBLE, "CLUMPSN", 0, dpt, 0,
+                         "Signal to noise of true clumps.", 0, NULL);
   gal_fits_array_to_file(p->cp.output, "Clumps", LONG_IMG, p->clab, s0,
                          s1, p->anyblank, p->wcs, keys, SPACK_STRING);
   keys=NULL;
@@ -117,17 +112,14 @@ 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_fits_add_to_fits_header_ll(&keys, TFLOAT, "MAXSTD", 0, fpt, 0,
-                                      "Maximum raw mesh sky standard "
-                                      "deviation.", 0, NULL);
+  gal_fits_add_to_key_ll(&keys, TFLOAT, "MAXSTD", 0, fpt, 0,
+                         "Maximum raw mesh sky standard deviation.", 0, NULL);
   fpt=&p->minstd;
-  gal_fits_add_to_fits_header_ll(&keys, TFLOAT, "MINSTD", 0, fpt, 0,
-                                      "Minimum raw mesh sky standard "
-                                      "deviation.", 0, NULL);
+  gal_fits_add_to_key_ll(&keys, TFLOAT, "MINSTD", 0, fpt, 0,
+                         "Minimum raw mesh sky standard deviation.", 0, NULL);
   fpt=&p->medstd;
-  gal_fits_add_to_fits_header_ll(&keys, TFLOAT, "MEDSTD", 0, fpt, 0,
-                                      "Median raw mesh standard "
-                                      "deviation.", 0, NULL);
+  gal_fits_add_to_key_ll(&keys, TFLOAT, "MEDSTD", 0, fpt, 0,
+                         "Median raw mesh standard deviation.", 0, NULL);
   gal_fits_array_to_file(p->cp.output, "Standard deviation",
                          FLOAT_IMG, std, s0, s1, 0, p->wcs,
                          keys, SPACK_STRING);
diff --git a/src/table/table.c b/src/table/table.c
index 6b682b0..d00e6d1 100644
--- a/src/table/table.c
+++ b/src/table/table.c
@@ -284,7 +284,7 @@ saveouttofits(struct tableparams *p)
                        ocols[i].data, ocols[i].nulval, &status);
 
   /* Include the ending comments and close the file. */
-  gal_fits_copyright_end(fptr, NULL, SPACK_STRING);
+  gal_fits_write_keys_version(fptr, NULL, SPACK_STRING);
   fits_close_file(fptr, &status);
   gal_fits_io_error(status, NULL);
 
diff --git a/src/table/ui.c b/src/table/ui.c
index d4825d1..2a22504 100644
--- a/src/table/ui.c
+++ b/src/table/ui.c
@@ -487,7 +487,7 @@ allfitscolinfo(struct tableparams *p)
           if(index<ncols)
             {
               gal_checkset_allocate_copy(&value[1], &up->ttstr[index] );
-              up->datatype[index]=gal_fits_tform_to_dtype(value[1]);
+              up->datatype[index]=gal_fits_tform_to_datatype(value[1]);
             }
         }
       else if(strncmp(keyname, "TTYPE", 5)==0)



reply via email to

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