gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 7992531: Txt and Table libraries now in manual


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 7992531: Txt and Table libraries now in manual
Date: Sun, 30 Apr 2017 23:41:19 -0400 (EDT)

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

    Txt and Table libraries now in manual
    
    The `txt.h' and `table.h' headers have been added to the manual. The Table
    header included several low-level functions that were too specific to the
    programs and would only cause confusion for the library users. So those
    functions have been moved to an internal
    `lib/gnuastro-internal/tableintern.h' header (and `lib/tableinternal.c'
    source file).
---
 bin/crop/ui.c                                      |   9 +-
 bin/mkcatalog/ui.c                                 |   3 +-
 bin/mknoise/ui.c                                   |   3 +-
 bin/mkprof/ui.c                                    |   9 +-
 bin/statistics/ui.c                                |  13 +-
 bin/table/ui.c                                     |   3 +-
 doc/gnuastro.texi                                  | 277 +++++++++++-
 lib/Makefile.am                                    |   7 +-
 lib/fits.c                                         |  10 +-
 .../txt.h => gnuastro-internal/tableintern.h}      |  67 ++-
 lib/gnuastro/table.h                               | 102 ++---
 lib/gnuastro/txt.h                                 |  10 +-
 lib/options.c                                      |  11 +-
 lib/table.c                                        | 464 ++-------------------
 lib/tableintern.c                                  | 419 +++++++++++++++++++
 lib/txt.c                                          |  46 +-
 16 files changed, 852 insertions(+), 601 deletions(-)

diff --git a/bin/crop/ui.c b/bin/crop/ui.c
index 1fb3d0b..04ced63 100644
--- a/bin/crop/ui.c
+++ b/bin/crop/ui.c
@@ -38,6 +38,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro-internal/timing.h>
 #include <gnuastro-internal/options.h>
 #include <gnuastro-internal/checkset.h>
+#include <gnuastro-internal/tableintern.h>
 #include <gnuastro-internal/fixedstringmacros.h>
 
 #include "main.h"
@@ -552,10 +553,10 @@ ui_read_cols(struct cropparams *p)
 
       /* Print an error if there were too many columns. */
       if(toomanycols)
-        gal_table_error_col_selection(p->catname, p->cathdu, "too many "
-                                      "columns were selected by the given "
-                                      "values to the options ending in "
-                                      "`col'.");
+        gal_tableintern_error_col_selection(p->catname, p->cathdu, "too many "
+                                            "columns were selected by the "
+                                            "given values to the options "
+                                            "ending in `col'.");
 
       /* Sanity check and clean up.  Note that it might happen that the
          input structure is already freed. In that case, `corrtype' will be
diff --git a/bin/mkcatalog/ui.c b/bin/mkcatalog/ui.c
index 0fc988e..ee64156 100644
--- a/bin/mkcatalog/ui.c
+++ b/bin/mkcatalog/ui.c
@@ -41,6 +41,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro-internal/timing.h>
 #include <gnuastro-internal/options.h>
 #include <gnuastro-internal/checkset.h>
+#include <gnuastro-internal/tableintern.h>
 #include <gnuastro-internal/fixedstringmacros.h>
 
 #include "main.h"
@@ -702,7 +703,7 @@ ui_preparations_outnames(struct mkcatalogparams *p)
     {
       /* Make sure the given output filename corresponds to the
          `tableformat' option. */
-      gal_table_check_fits_format(p->cp.output, p->cp.tableformat);
+      gal_tableintern_check_fits_format(p->cp.output, p->cp.tableformat);
 
       /* If a clumps image has been read, we have two outputs. */
       if(p->clumps)  ui_preparations_both_names(p, p->cp.output);
diff --git a/bin/mknoise/ui.c b/bin/mknoise/ui.c
index 5e41eb3..5aa402a 100644
--- a/bin/mknoise/ui.c
+++ b/bin/mknoise/ui.c
@@ -36,6 +36,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro-internal/timing.h>
 #include <gnuastro-internal/options.h>
 #include <gnuastro-internal/checkset.h>
+#include <gnuastro-internal/tableintern.h>
 #include <gnuastro-internal/fixedstringmacros.h>
 
 #include "main.h"
@@ -275,7 +276,7 @@ ui_preparations(struct mknoiseparams *p)
   /* If we are dealing with an input table, make sure the format of the
      output table is valid, given the type of the output. */
   if(p->input->ndim==1)
-    gal_table_check_fits_format(p->cp.output, p->cp.tableformat);
+    gal_tableintern_check_fits_format(p->cp.output, p->cp.tableformat);
 
 
   /* Set the output name: */
diff --git a/bin/mkprof/ui.c b/bin/mkprof/ui.c
index 3c1071e..73c00d0 100644
--- a/bin/mkprof/ui.c
+++ b/bin/mkprof/ui.c
@@ -38,6 +38,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro-internal/timing.h>
 #include <gnuastro-internal/options.h>
 #include <gnuastro-internal/checkset.h>
+#include <gnuastro-internal/tableintern.h>
 #include <gnuastro-internal/fixedstringmacros.h>
 
 #include "main.h"
@@ -498,10 +499,10 @@ ui_read_cols(struct mkprofparams *p)
         /* If the index isn't recognized, then it is larger, showing that
            there was more than one match for the given criteria */
         default:
-          gal_table_error_col_selection(p->catname, p->cp.hdu, "too many "
-                                        "columns were selected by the given "
-                                        "values to the options ending in "
-                                        "`col'.");
+          gal_tableintern_error_col_selection(p->catname, p->cp.hdu, "too many 
"
+                                              "columns were selected by the "
+                                              "given values to the options "
+                                              "ending in `col'.");
         }
 
       /* Sanity check and clean up.  Note that it might happen that the
diff --git a/bin/statistics/ui.c b/bin/statistics/ui.c
index 05df0e8..fd97f56 100644
--- a/bin/statistics/ui.c
+++ b/bin/statistics/ui.c
@@ -41,6 +41,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro-internal/timing.h>
 #include <gnuastro-internal/options.h>
 #include <gnuastro-internal/checkset.h>
+#include <gnuastro-internal/tableintern.h>
 #include <gnuastro-internal/fixedstringmacros.h>
 
 #include "main.h"
@@ -379,7 +380,7 @@ ui_read_check_only_options(struct statisticsparams *p)
 
   /* Check if the format of the output table is valid, given the type of
      the output. */
-  gal_table_check_fits_format(p->cp.output, p->cp.tableformat);
+  gal_tableintern_check_fits_format(p->cp.output, p->cp.tableformat);
 
 
   /* If in tile-mode, we must have at least one single valued option. */
@@ -763,11 +764,11 @@ ui_read_columns(struct statisticsparams *p)
 
       /* Print an error if there are too many columns: */
       if(toomanycols)
-        gal_table_error_col_selection(p->inputname, p->cp.hdu, "too many "
-                                      "columns were selected by the given "
-                                      "values to the `--column' and/or "
-                                      "`--refcol' options. Only one "
-                                      "is acceptable for each.");
+        gal_tableintern_error_col_selection(p->inputname, p->cp.hdu, "too many 
"
+                                            "columns were selected by the "
+                                            "given values to the `--column' "
+                                            "and/or `--refcol' options. Only "
+                                            "one is acceptable for each.");
     }
 
   /* Clean up. */
diff --git a/bin/table/ui.c b/bin/table/ui.c
index f8977aa..15ec59d 100644
--- a/bin/table/ui.c
+++ b/bin/table/ui.c
@@ -34,6 +34,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro-internal/timing.h>
 #include <gnuastro-internal/options.h>
 #include <gnuastro-internal/checkset.h>
+#include <gnuastro-internal/tableintern.h>
 #include <gnuastro-internal/fixedstringmacros.h>
 
 #include "main.h"
@@ -214,7 +215,7 @@ ui_read_check_only_options(struct tableparams *p)
 
   /* Check if the format of the output table is valid, given the type of
      the output. */
-  gal_table_check_fits_format(p->cp.output, p->cp.tableformat);
+  gal_tableintern_check_fits_format(p->cp.output, p->cp.tableformat);
 
 }
 
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index a2b1ac8..595b605 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -18926,23 +18926,26 @@ error message informing the user of the problem.
 @deftypefun {gal_data_t *} gal_fits_tab_info (char @code{*filename}, char 
@code{*hdu}, size_t @code{*numcols}, size_t @code{*numrows}, int 
@code{*tableformat})
 Store the information of each column in @code{hdu} of @code{filename} into
 an array of data structures with @code{numcols} elements (one data
-structure for each column), see @ref{Arrays of datasets}. The number of
-rows is stored as the @code{size} element of each data structure. The
-format of the table (e.g., FITS binary or ASCII table) will be put in
address@hidden (macros defined in @ref{Table input output}).
+structure for each column) see @ref{Arrays of datasets}. The total number
+of rows in the table is also put into the memory that @code{numrows} points
+to. The format of the table (e.g., FITS binary or ASCII table) will be put
+in @code{tableformat} (macros defined in @ref{Table input output}).
 
 Note that other than the character strings (column name, units and
 comments), nothing in the data structure(s) will be allocated by this
 function for the actual data (e.g., the @code{array} or @code{dsize}
-elements). This function is just for column information.
+elements). This function is just for column information. This is a
+low-level function particular to reading tables in FITS format. It is
+recommended to use @code{gal_table_info} to be generic (see @ref{Table
+input output}).
 @end deftypefun
 
 @deftypefun {gal_data_t *} gal_fits_tab_read (char @code{*filename}, char 
@code{*hdu}, size_t @code{numrows}, gal_data_t @code{*colinfo}, 
gal_list_sizet_t @code{*indexll}, int @code{minmapsize})
 Read the columns given in the list @code{indexll} from a FITS table into a
 linked list of data structures, see @ref{List of size_t} and @ref{List of
 gal_data_t}. If the necessary space for each column is larger than
address@hidden, don't keep it in the RAM, but in a file on memory, see
-the description under the same name in @ref{Generic data container}.
address@hidden, don't keep it in the RAM, but in a file in the HDD/SSD,
+see the description under the same name in @ref{Generic data container}.
 
 Note that this is a low-level function, so the output data linked list is
 the inverse of the input indexs linked list. It is recommended to use
@@ -18965,10 +18968,268 @@ FITS file (see @ref{List of strings}.
 @node Text files, Table input output, FITS files, Gnuastro library
 @subsection Text files (@file{txt.h})
 
+FITS files are the primary data container in astronomy. FITS indeed as many
+useful features, but the most universal and portable format for data
+storage are plain text files. They can be viewed and edited on any text
+editor or even on the command-line. Therefore the functions in this section
+are defined to simplify reading from and writing to plain text
+files.
+
+Gnuastro defines a simple format for metadata of table columns in a plain
+text file that is discussed in @ref{Gnuastro text table format}. The
+functions to get information from, read from and write to plain text files
+also follow those conventions.
+
+
address@hidden Macro GAL_TXT_LINESTAT_INVALID
address@hidden Macro GAL_TXT_LINESTAT_BLANK
address@hidden Macro GAL_TXT_LINESTAT_COMMENT
address@hidden Macro GAL_TXT_LINESTAT_DATAROW
+Status codes for lines in a plain text file that may be returned by
address@hidden). Lines which have a @key{#} character as their
+first non-white character are considered to be comments. Lines with nothing
+but white space characters are considered blank.
address@hidden deffn
+
address@hidden int gal_txt_line_stat (char @code{*line})
+Check the contents of @code{line} and see if it is a blank, comment, or
+data line. The returned values are the macros that start with
address@hidden
address@hidden deftypefun
+
address@hidden {gal_data_t *} gal_txt_table_info (char @code{*filename}, size_t 
@code{*numcols}, size_t @code{*numrows})
+Store the information of each column in @code{filename} into an array of
+data structures with @code{numcols} elements (one data structure for each
+column) see @ref{Arrays of datasets}. The total number of rows in the table
+is also put into the memory that @code{numrows} points to.
+
+Note that other than the character strings (column name, units and
+comments), nothing in the data structure(s) will be allocated by this
+function for the actual data (e.g., the @code{array} or @code{dsize}
+elements). This function is just for column information. This is a
+low-level function particular to reading tables in FITS format. It is
+recommended to use @code{gal_table_info} which will allow getting
+information from a variety of table formats (see @ref{Table input output}).
address@hidden deftypefun
+
address@hidden {gal_data_t *} gal_txt_table_read (char @code{*filename}, size_t 
@code{numrows}, gal_data_t @code{*colinfo}, gal_list_sizet_t @code{*indexll}, 
size_t @code{minmapsize})
+Read the columns given in the list @code{indexll} from a plain text table
+into a linked list of data structures, see @ref{List of size_t} and
address@hidden of gal_data_t}. If the necessary space for each column is larger
+than @code{minmapsize}, don't keep it in the RAM, but in a file on the
+HDD/SSD, see the description under the same name in @ref{Generic data
+container}.
+
+Note that this is a low-level function, so the output data list is the
+inverse of the input indexs linked list. It is recommended to use
address@hidden for generic reading of tables in any format, see
address@hidden input output}.
address@hidden deftypefun
+
address@hidden {gal_data_t *} gal_txt_image_read (char @code{*filename}, size_t 
@code{minmapsize})
+Read the 2D plain text dataset in @code{filename} into a dataset and return
+the dataset. If the necessary space for the image is larger than
address@hidden, don't keep it in the RAM, but in a file on the HDD/SSD,
+see the description under the same name in @ref{Generic data container}.
address@hidden deftypefun
+
address@hidden void gal_txt_write (gal_data_t @code{*cols}, gal_list_str_t 
@code{*comment}, char @code{*filename}, int @code{dontdelete})
+Write @code{cols} in a plain text file @code{filename}. @code{cols} may
+have one or two dimensions which determines the output:
+
address@hidden @asis
address@hidden 1D
address@hidden is treated as a column and a list of datasets (see @ref{List of
+gal_data_t}): every node in the list is written as one column in a
+table.
+
address@hidden 2D
address@hidden is a two dimensional array, it cannot be treated as a list
+(only one 2D array can currently be written to a text file). So if
address@hidden>next!=NULL} the next nodes in the list are ignored and will not
+be written.
address@hidden table
+
+If @code{filename} already exists and @code{dontdelete} is non-zero, then
+this function will abort with an error and will not write over the existing
+file. If @code{comments!=NULL}, a @code{#} will be put at the start of each
+node of the list of strings and will be written in the file before the
+column meta-data in @code{filename} (see @ref{List of strings}).
+
+Note that this is a low-level function for tables. It is recommended to use
address@hidden for generic writing of tables in a variety of
+formats, see @ref{Table input output}.
address@hidden deftypefun
+
+
 @node Table input output, Arithmetic on datasets, Text files, Gnuastro library
 @subsection Table input output (@file{table.h})
 
-Functions to read columns from/to tables.
+Tables are a collection of one dimensional datasets that are packed
+together into one file. They are the single most common format to store
+high-level (processed) information, hence they play a very important role
+in Gnuastro. For a more thorough introduction, please see Gnuastro's
address@hidden Gnuastro's Table program and all the other programs that can
+read and write into tables use the functions of this section.
+
+Currently only plain text (see @ref{Gnuastro text table format}) and FITS
+tables are supported by Gnuastro. However, the low-level table
+infra-structure is written such that for other formats are also possible
+and in future releases more formats will be supported, please let us know
+your priorities so they get higher priorities.
+
address@hidden  Macro GAL_TABLE_DEF_WIDTH_STR
address@hidden Macro GAL_TABLE_DEF_WIDTH_INT
address@hidden Macro GAL_TABLE_DEF_WIDTH_LINT
address@hidden Macro GAL_TABLE_DEF_WIDTH_FLT
address@hidden Macro GAL_TABLE_DEF_WIDTH_DBL
address@hidden Macro GAL_TABLE_DEF_PRECISION_INT
address@hidden Macro GAL_TABLE_DEF_PRECISION_FLT
address@hidden Macro GAL_TABLE_DEF_PRECISION_DBL
address@hidden @code{printf}
+The default width and precision for generic types to use in writing numeric
+types into a text file (plain text and FITS ASCII tables). When the dataset
+doesn't have any pre-set width and precision (see @code{disp_width} and
address@hidden in @ref{Generic data container}) these will be
+directly used in C's @code{printf} command to write the number as a string.
address@hidden deffn
+
address@hidden  Macro GAL_TABLE_DISPLAY_FMT_STRING
address@hidden Macro GAL_TABLE_DISPLAY_FMT_DECIMAL
address@hidden Macro GAL_TABLE_DISPLAY_FMT_UDECIMAL
address@hidden Macro GAL_TABLE_DISPLAY_FMT_OCTAL
address@hidden Macro GAL_TABLE_DISPLAY_FMT_HEX
address@hidden Macro GAL_TABLE_DISPLAY_FMT_FLOAT
address@hidden Macro GAL_TABLE_DISPLAY_FMT_EXP
address@hidden Macro GAL_TABLE_DISPLAY_FMT_GENERAL
+The display format used in C's @code{printf} to display data of different
+types. The @code{_STRING} and @code{_DECIMAL} are unique for printing
+strings and signed integers, they are mainly here for
+completeness. However, unsigned integers and flating points can be
+displayed in multiple formats:
+
address@hidden @asis
address@hidden Unsigned integer
+For unsigned integers, it is possible to choose from @code{_UDECIMAL}
+(unsigned decimal), @code{_OCTAL} (octal notation, for example @code{125}
+in decimal will be displayed as @code{175}), and @code{_HEX} (hexadecimal
+notation, for example @code{125} in decimal will be displayed as
address@hidden).
+
address@hidden Floating point
+For floating point, it is possible to display the number in @code{_FLOAT}
+(floating point, for example @code{1500.345}), @code{_EXP} (exponential,
+for example @code{1.500345e+03}), or @code{_GENERAL} which is the best of
+the two for the given number.
address@hidden table
address@hidden deffn
+
address@hidden  Macro GAL_TABLE_FORMAT_INVALID
address@hidden Macro GAL_TABLE_FORMAT_TXT
address@hidden Macro GAL_TABLE_FORMAT_AFITS
address@hidden Macro GAL_TABLE_FORMAT_BFITS
+All the current acceptable table formats to Gnuastro. The @code{AFITS} and
address@hidden represent FITS ASCII tables and FITS Binary tables. You can
+use these anywhere you see the @code{tableformat} variable.
address@hidden deffn
+
address@hidden  Macro GAL_TABLE_SEARCH_INVALID
address@hidden Macro GAL_TABLE_SEARCH_NAME
address@hidden Macro GAL_TABLE_SEARCH_UNIT
address@hidden Macro GAL_TABLE_SEARCH_COMMENT
+When the desired column is not a number, these values determine if the
+string to match, or regular expression to search, be in the @emph{name},
address@hidden or @emph{comments} of the column meta data. These values
+should be used for the @code{searchin} variables of the functions.
address@hidden deffn
+
address@hidden {gal_data_t *} gal_table_info (char @code{*filename}, char 
@code{*hdu}, size_t @code{*numcols}, size_t @code{*numrows}, int 
@code{*tableformat})
+Store the information of each column in a table (either as a text file or
+as a FITS table) into an array of data structures with @code{numcols}
+structures (one data structure for each column). The number of rows is
+stored in the space that @code{numrows} points to. The format of the table
+(e.g., ascii text file, or FITS binary or ASCII table) will be put in
address@hidden (macros defined above). If the filename is not a FITS
+file, then @code{hdu} will not be used (can be @code{NULL}).
+
+Note that other than the character strings (column name, units and
+comments), nothing in the data structure(s) will be allocated by this
+function for the actual data (e.g., the `array' or `dsize' elements). This
+function is just for column information (meta-data), not column contents.
address@hidden deftypefun
+
address@hidden void gal_table_print_info (gal_data_t @code{*allcols}, size_t 
@code{numcols}, size_t @code{numrows})
+This program will print the column information for all the columns (output
+of @code{gal_table_info}). The output is in the same format as this command
+with Gnuastro Table program (see @ref{Table}):
address@hidden
+$ asttable --info table.fits
address@hidden example
address@hidden deftypefun
+
address@hidden {gal_data_t *} gal_table_read (char @code{*filename}, char 
@code{*hdu}, gal_list_str_t @code{*cols}, int @code{searchin}, int 
@code{ignorecase}, int @code{minmapsize})
+Read the specified columns in a text file (named @code{filename}) into a
+linked list of data structures. If the file is FITS, then @code{hdu} will
+also be used, otherwise, @code{hdu} is ignored.
+
address@hidden AWK
address@hidden GNU AWK
+The information to search for columns should be specified by the
address@hidden list of strings (see @ref{List of strings}). The string in each
+node of the list may be a number, an exact match to a column name, or a
+regular expression (in GNU AWK format) enclosed in @code{/ /}. The
address@hidden value must be one of the macros defined above. If
address@hidden is NULL, then this function will read the full table.
+
+The output is a linked list with the same order of the @code{cols}
+list. Note that one column node in the @code{cols} list might give multiple
+columns (for example from regular expressions), in this case, the order of
+output columns that correspond to that one input, are in order of the table
+(which column was read first).  So the first requested column is the first
+popped data structure and so on.
address@hidden deftypefun
+
address@hidden Git
address@hidden void gal_table_comments_add_intro (gal_list_str_t 
@code{**comments}, char @code{*program_string}, time_t @code{*rawtime})
+Add some basic information to the list of @code{comments}. This basic
+information includes the following information
address@hidden
address@hidden
+If the program is run in a Git version controlled directory, Git's
+description is printed (see description under @code{COMMIT} in @ref{Output
+headers}).
address@hidden
+The calendar time that is stored in @code{rawtime} (@code{time_t} is C's
+calendar time format defined in @file{time.h}). You can calculate the time
+in this format with the following expressions:
address@hidden
+time_t rawtime;
+time(&rawtime);
address@hidden example
address@hidden
+The name of your program in @code{program_string}. If it is @code{NULL},
+this line is ignored.
address@hidden itemize
address@hidden deftypefun
+
address@hidden void gal_table_write (gal_data_t @code{*cols}, gal_list_str_t 
@code{*comments}, int @code{tableformat}, char @code{*filename}, int 
@code{dontdelete})
+Write the @code{cols} list of datasets into a table in @code{filename} (see
address@hidden of gal_data_t}). The format of the table can be determined with
address@hidden that accepts the macros defined above. If
address@hidden, then the list of comments will also be printed into
+the output table. When the output table is a plain text file, each node's
+string will be printed after a @code{#} (so it can be considered as a
+comment). If @code{filename} already exists and @code{dontdelete} is not
+zero, this function will abort the program with an error.
address@hidden deftypefun
+
address@hidden void gal_table_write_log (gal_data_t @code{*logll}, char 
@code{*program_string}, time_t @code{*rawtime}, gal_list_str_t 
@code{*comments}, char @code{*filename}, int @code{dontdelete}, int 
@code{quiet})
+Write the @code{logll} list of datasets into a table in @code{filename}
+(see @ref{List of gal_data_t}). This function is just a wrapper around
address@hidden and @code{gal_table_write} (see
+above). If @code{quiet} is non-zero, this function will print a message
+saying that the @code{filename} has been created.
address@hidden deftypefun
 
 @node Arithmetic on datasets, Tessellation library, Table input output, 
Gnuastro library
 @subsection Arithmetic on datasets (@file{arithmetic.h})
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 1f87c7d..ef281ea 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -53,8 +53,8 @@ libgnuastro_la_LIBADD = 
$(top_builddir)/bootstrapped/lib/libgnu.la
 libgnuastro_la_SOURCES = arithmetic.c arithmetic-binary.c                  \
   arithmetic-onlyint.c binary.c blank.c box.c checkset.c convolve.c data.c \
   fits.c git.c interpolate.c list.c options.c permutation.c polygon.c      \
-  qsort.c dimension.c statistics.c table.c threads.c tile.c timing.c txt.c \
-  type.c wcs.c
+  qsort.c dimension.c statistics.c table.c tableintern.c threads.c tile.c  \
+  timing.c txt.c type.c wcs.c
 
 
 
@@ -89,7 +89,8 @@ EXTRA_DIST = gnuastro.pc.in $(headersdir)/README 
$(internaldir)/README   \
   $(internaldir)/arithmetic-binary.h $(internaldir)/arithmetic-onlyint.h \
   $(internaldir)/checkset.h $(internaldir)/commonopts.h                  \
   $(internaldir)/config.h.in $(internaldir)/fixedstringmacros.h          \
-  $(internaldir)/options.h $(internaldir)/timing.h
+  $(internaldir)/options.h $(internaldir)/tableintern.h                  \
+  $(internaldir)/timing.h
 
 
 
diff --git a/lib/fits.c b/lib/fits.c
index 87adddf..69bd122 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -41,6 +41,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro/blank.h>
 
 #include <gnuastro-internal/checkset.h>
+#include <gnuastro-internal/tableintern.h>
 #include <gnuastro-internal/fixedstringmacros.h>
 
 
@@ -1758,8 +1759,8 @@ set_display_format(char *tdisp, gal_data_t *data, char 
*filename, char *hdu,
 
     case '\0':     /* No precision given, use a default value.     */
       data->disp_precision = ( isanint
-                               ? GAL_TABLE_DEF_INT_PRECISION
-                               : GAL_TABLE_DEF_FLT_PRECISION );
+                               ? GAL_TABLE_DEF_PRECISION_INT
+                               : GAL_TABLE_DEF_PRECISION_FLT );
       break;
 
     default:
@@ -1999,7 +2000,7 @@ gal_fits_tab_info(char *filename, char *hdu, size_t 
*numcols,
                         "blank value cannot be deduced", filename, hdu,
                         keyname, index+1);
               else
-                gal_table_read_blank(&allcols[index], value);
+                gal_tableintern_read_blank(&allcols[index], value);
             }
         }
 
@@ -2192,7 +2193,8 @@ fits_table_prepare_arrays(gal_data_t *cols, size_t 
numcols, int tableformat,
         case GAL_TABLE_FORMAT_AFITS:
 
             /* Fill the printing format. */
-            gal_table_col_print_info(col, GAL_TABLE_FORMAT_AFITS, fmt, lng);
+            gal_tableintern_col_print_info(col, GAL_TABLE_FORMAT_AFITS,
+                                           fmt, lng);
 
             /* We need to check if the blank value needs is larger than the
                expected width or not. Its initial width is set the output
diff --git a/lib/gnuastro/txt.h b/lib/gnuastro-internal/tableintern.h
similarity index 51%
copy from lib/gnuastro/txt.h
copy to lib/gnuastro-internal/tableintern.h
index 89b797d..5f21b2c 100644
--- a/lib/gnuastro/txt.h
+++ b/lib/gnuastro-internal/tableintern.h
@@ -1,5 +1,5 @@
 /*********************************************************************
-txt -- functions to deal with plain text files.
+tableintern -- Internalfunctions for table input and output.
 This is part of GNU Astronomy Utilities (Gnuastro) package.
 
 Original author:
@@ -20,12 +20,13 @@ General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
 **********************************************************************/
-#ifndef __GAL_TXT_H__
-#define __GAL_TXT_H__
+#ifndef __GAL_TABLEINTERN_H__
+#define __GAL_TABLEINTERN_H__
 
 /* Include other headers if necessary here. Note that other header files
    must be included before the C++ preparations below */
 
+#include <gnuastro/fits.h> /* Includes `gnuastro/data.h' and `fitsio.h' */
 #include <gnuastro/list.h>
 
 
@@ -52,54 +53,50 @@ __BEGIN_C_DECLS  /* From C++ preparations */
 
 
 
-/* Macros.
-
- Note on `GAL_TXT_STRING_BLANK': Within Gnuastro, a blank string value is
- just a NULL pointer, but here, we are dealing with the outside world. In
- particular we want to write the column to the outside world. So this macro
- acts as a place holder for the blank string columns ONLY in ASCII
- tables.*/
-#define GAL_TXT_DELIMITERS     " ,\t\f\v"
-#define GAL_TXT_MAX_FMT_LENGTH 20
-
-
 
+/************************************************************************/
+/***************              Error messages              ***************/
+/************************************************************************/
+void
+gal_tableintern_error_col_selection(char *filename, char *hdu,
+                                    char *errorstring);
 
 
-/* Status of a line: */
-enum gal_txt_line_status_enums
-{
-  GAL_TXT_LINESTAT_INVALID,
 
-  GAL_TXT_LINESTAT_BLANK,
-  GAL_TXT_LINESTAT_COMMENT,
-  GAL_TXT_LINESTAT_DATAROW,
-};
 
+/************************************************************************/
+/***************                 Formats                  ***************/
+/************************************************************************/
+uint8_t
+gal_tableintern_string_to_format(char *string);
 
+char *
+gal_tableintern_format_as_string(uint8_t tableformat);
 
+uint8_t
+gal_tableintern_string_to_searchin(char *string);
 
+char *
+gal_tableintern_searchin_as_string(uint8_t searchin);
 
-/* Functions */
-int
-gal_txt_line_stat(char *line);
+void
+gal_tableintern_check_fits_format(char *filename, int tableformat);
 
-gal_data_t *
-gal_txt_table_info(char *filename, size_t *numcols, size_t *numrows);
 
-gal_data_t *
-gal_txt_table_read(char *filename, size_t numrows, gal_data_t *colinfo,
-                   gal_list_sizet_t *indexll, size_t minmapsize);
 
-gal_data_t *
-gal_txt_image_read(char *filename, size_t minmapsize);
+/************************************************************************/
+/***************          Printing information            ***************/
+/************************************************************************/
+void
+gal_tableintern_col_print_info(gal_data_t *col, int tableformat,
+                               char *fmt, char *lng);
 
 void
-gal_txt_write(gal_data_t *cols, gal_list_str_t *comment, char *filename,
-              int dontdelete);
+gal_tableintern_read_blank(gal_data_t *col, char *blank);
+
 
 
 
 __END_C_DECLS    /* From C++ preparations */
 
-#endif           /* __GAL_TXT_H__ */
+#endif           /* __GAL_TABLE_H__ */
diff --git a/lib/gnuastro/table.h b/lib/gnuastro/table.h
index 3d3d6c9..279571b 100644
--- a/lib/gnuastro/table.h
+++ b/lib/gnuastro/table.h
@@ -56,44 +56,15 @@ __BEGIN_C_DECLS  /* From C++ preparations */
 
 /* `printf' default formattings. Note that the string type shouldn't have
    any precision and for the width,  */
-#define GAL_TABLE_DEF_STR_WIDTH       6
-#define GAL_TABLE_DEF_INT_WIDTH       6
-#define GAL_TABLE_DEF_LINT_WIDTH      10
-#define GAL_TABLE_DEF_FLT_WIDTH       13
-#define GAL_TABLE_DEF_DBL_WIDTH       18
+#define GAL_TABLE_DEF_WIDTH_STR       6
+#define GAL_TABLE_DEF_WIDTH_INT       6
+#define GAL_TABLE_DEF_WIDTH_LINT      10
+#define GAL_TABLE_DEF_WIDTH_FLT       13
+#define GAL_TABLE_DEF_WIDTH_DBL       18
 
-#define GAL_TABLE_DEF_INT_PRECISION   0
-#define GAL_TABLE_DEF_FLT_PRECISION   6
-#define GAL_TABLE_DEF_DBL_PRECISION   14
-
-
-
-/* Formats of table storage for input or output, as strings and
-   integers. */
-enum gal_table_types
-{
-  GAL_TABLE_FORMAT_INVALID,       /* Invalid (=0 by C standard).       */
-
-  GAL_TABLE_FORMAT_TXT,           /* Plain text table.                 */
-  GAL_TABLE_FORMAT_AFITS,         /* FITS ASCII table.                 */
-  GAL_TABLE_FORMAT_BFITS,         /* FITS binary table.                */
-};
-
-
-
-
-
-/* When the desired column is not a number, should the string match or
-   regular expression search be in the name, units or comments of the
-   columns? */
-enum gal_table_where_to_search
-{
-  GAL_TABLE_SEARCH_INVALID,       /* Invalid (=0 by C standard).     */
-
-  GAL_TABLE_SEARCH_NAME,          /* Match/search in names.          */
-  GAL_TABLE_SEARCH_UNIT,          /* Match/search in units.          */
-  GAL_TABLE_SEARCH_COMMENT,       /* Match/search in comments.       */
-};
+#define GAL_TABLE_DEF_PRECISION_INT   0
+#define GAL_TABLE_DEF_PRECISION_FLT   6
+#define GAL_TABLE_DEF_PRECISION_DBL   14
 
 
 
@@ -121,48 +92,32 @@ enum gal_table_diplay_formats
 
 
 
-/************************************************************************/
-/***************              Error messages              ***************/
-/************************************************************************/
-void
-gal_table_error_col_selection(char *filename, char *hdu, char *errorstring);
-
-
-
-
-/************************************************************************/
-/***************                 Formats                  ***************/
-/************************************************************************/
-uint8_t
-gal_table_string_to_format(char *string);
-
-char *
-gal_table_format_as_string(uint8_t format);
+/* Formats of table storage for input or output, as strings and
+   integers. */
+enum gal_table_types
+{
+  GAL_TABLE_FORMAT_INVALID,       /* Invalid (=0 by C standard).       */
 
-uint8_t
-gal_table_string_to_searchin(char *string);
+  GAL_TABLE_FORMAT_TXT,           /* Plain text table.                 */
+  GAL_TABLE_FORMAT_AFITS,         /* FITS ASCII table.                 */
+  GAL_TABLE_FORMAT_BFITS,         /* FITS binary table.                */
+};
 
-char *
-gal_table_searchin_as_string(uint8_t searchin);
 
-void
-gal_table_check_fits_format(char *filename, int tableformat);
 
 
 
-/************************************************************************/
-/***************          Printing information            ***************/
-/************************************************************************/
-void
-gal_table_print_info(gal_data_t *allcols, size_t numcols, size_t numrows);
-
-void
-gal_table_col_print_info(gal_data_t *col, int tableformat,
-                         char *fmt, char *lng);
-
-void
-gal_table_read_blank(gal_data_t *col, char *blank);
+/* When the desired column is not a number, should the string match or
+   regular expression search be in the name, units or comments of the
+   columns? */
+enum gal_table_where_to_search
+{
+  GAL_TABLE_SEARCH_INVALID,       /* Invalid (=0 by C standard).     */
 
+  GAL_TABLE_SEARCH_NAME,          /* Match/search in names.          */
+  GAL_TABLE_SEARCH_UNIT,          /* Match/search in units.          */
+  GAL_TABLE_SEARCH_COMMENT,       /* Match/search in comments.       */
+};
 
 
 
@@ -173,6 +128,9 @@ gal_data_t *
 gal_table_info(char *filename, char *hdu, size_t *numcols,
                size_t *numrows, int *tableformat);
 
+void
+gal_table_print_info(gal_data_t *allcols, size_t numcols, size_t numrows);
+
 
 
 /************************************************************************/
diff --git a/lib/gnuastro/txt.h b/lib/gnuastro/txt.h
index 89b797d..b8373dd 100644
--- a/lib/gnuastro/txt.h
+++ b/lib/gnuastro/txt.h
@@ -52,13 +52,7 @@ __BEGIN_C_DECLS  /* From C++ preparations */
 
 
 
-/* Macros.
-
- Note on `GAL_TXT_STRING_BLANK': Within Gnuastro, a blank string value is
- just a NULL pointer, but here, we are dealing with the outside world. In
- particular we want to write the column to the outside world. So this macro
- acts as a place holder for the blank string columns ONLY in ASCII
- tables.*/
+/* Macros.*/
 #define GAL_TXT_DELIMITERS     " ,\t\f\v"
 #define GAL_TXT_MAX_FMT_LENGTH 20
 
@@ -95,7 +89,7 @@ gal_data_t *
 gal_txt_image_read(char *filename, size_t minmapsize);
 
 void
-gal_txt_write(gal_data_t *cols, gal_list_str_t *comment, char *filename,
+gal_txt_write(gal_data_t *input, gal_list_str_t *comment, char *filename,
               int dontdelete);
 
 
diff --git a/lib/options.c b/lib/options.c
index 611fd71..de32e35 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -39,6 +39,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro-internal/timing.h>
 #include <gnuastro-internal/options.h>
 #include <gnuastro-internal/checkset.h>
+#include <gnuastro-internal/tableintern.h>
 
 
 
@@ -442,7 +443,7 @@ gal_options_read_searchin(struct argp_option *option, char 
*arg,
       /* Note that `gal_data_type_as_string' returns a static string. But
          the output must be an allocated string so we can free it. */
       gal_checkset_allocate_copy(
-        gal_table_searchin_as_string( *(uint8_t *)(option->value)), &str);
+        gal_tableintern_searchin_as_string( *(uint8_t *)(option->value)), 
&str);
       return str;
     }
   else
@@ -451,8 +452,8 @@ gal_options_read_searchin(struct argp_option *option, char 
*arg,
       if(option->set) return NULL;
 
       /* Read the value. */
-      if( ( *(uint8_t *)(option->value)=gal_table_string_to_searchin(arg) )
-          == GAL_TABLE_SEARCH_INVALID )
+      if(( *(uint8_t *)(option->value)=gal_tableintern_string_to_searchin(arg))
+         == GAL_TABLE_SEARCH_INVALID )
         error_at_line(EXIT_FAILURE, 0, filename, lineno, "`%s' (value to "
                       "`%s' option) couldn't be recognized as a known table "
                       "search-in field (`name', `unit', or `comment').\n\n"
@@ -482,7 +483,7 @@ gal_options_read_tableformat(struct argp_option *option, 
char *arg,
       /* Note that `gal_data_type_as_string' returns a static string. But
          the output must be an allocated string so we can free it. */
       gal_checkset_allocate_copy(
-        gal_table_format_as_string( *(uint8_t *)(option->value)), &str);
+        gal_tableintern_format_as_string( *(uint8_t *)(option->value)), &str);
       return str;
     }
   else
@@ -491,7 +492,7 @@ gal_options_read_tableformat(struct argp_option *option, 
char *arg,
       if(option->set) return NULL;
 
       /* Read the value. */
-      if( (*(uint8_t *)(option->value) = gal_table_string_to_format(arg) )
+      if( (*(uint8_t *)(option->value) = gal_tableintern_string_to_format(arg) 
)
           ==GAL_TABLE_FORMAT_INVALID )
         error_at_line(EXIT_FAILURE, 0, filename, lineno, "`%s' (value to "
                       "`%s' option) couldn't be recognized as a known table "
diff --git a/lib/table.c b/lib/table.c
index 17f1f23..5191722 100644
--- a/lib/table.c
+++ b/lib/table.c
@@ -36,51 +36,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 
 #include <gnuastro-internal/timing.h>
 #include <gnuastro-internal/checkset.h>
-
-
-
-
-
-
-/************************************************************************/
-/***************              Error messages              ***************/
-/************************************************************************/
-void
-gal_table_error_col_selection(char *filename, char *hdu, char *errorstring)
-{
-  char *c, *name, *command;
-
-  /* Set the proper pointers. */
-  if(gal_fits_name_is_fits(filename))
-    {
-      asprintf(&name, "%s (hdu: %s)", filename, hdu);
-      c=hdu; while(*c!='\0') if(isspace(*c++)) break;
-      asprintf(&command, *c=='\0' ? "%s --hdu=%s" : "%s --hdu=\"%s\"",
-               filename, hdu);
-    }
-  else command=name=filename;
-
-  /* Abort with with the proper error. */
-  error(EXIT_FAILURE, 0, "%s: %s\n\nFor more information on selecting "
-        "columns in Gnuastro, please run the following command (press "
-        "`SPACE' to go down and `q' to return to the command-line):\n\n"
-        "    $ info gnuastro \"Selecting table columns\"\n\n"
-        "To define a better column selection criteria, you can see "
-        "the list of column meta-data in this table, with the following "
-        "command:\n\n"
-        "    $ asttable %s --info\n", name, errorstring, command);
-}
-
-
-
-
-
-
-
-
-
-
-
+#include <gnuastro-internal/tableintern.h>
 
 
 
@@ -91,134 +47,42 @@ gal_table_error_col_selection(char *filename, char *hdu, 
char *errorstring)
 
 
 /************************************************************************/
-/***************                 Formats                  ***************/
+/***************         Information about a table        ***************/
 /************************************************************************/
-/* Return the type of desired table based on a standard string. */
-uint8_t
-gal_table_string_to_format(char *string)
-{
-  if(string)                    /* Its not NULL. */
-    {
-      if(!strcmp(string, "txt"))              return GAL_TABLE_FORMAT_TXT;
-      else if(!strcmp(string,"fits-ascii"))   return GAL_TABLE_FORMAT_AFITS;
-      else if(!strcmp(string, "fits-binary")) return GAL_TABLE_FORMAT_BFITS;
-      else                                    return GAL_TABLE_FORMAT_INVALID;
-    }
-  else                                        return GAL_TABLE_FORMAT_INVALID;
-}
-
-
-
-
-
-char *
-gal_table_format_as_string(uint8_t format)
-{
-  switch(format)
-    {
-    case GAL_TABLE_FORMAT_TXT:    return "txt";
-    case GAL_TABLE_FORMAT_AFITS:  return "fits-ascii";
-    case GAL_TABLE_FORMAT_BFITS:  return "fits-binary";
-    default:
-      error(EXIT_FAILURE, 0, "%s: code %d not recognized", __func__, format);
-      return NULL;
-    }
-}
-
-
-
-
-
-
-/* In programs, the `searchin' variable is much more easier to format in as
-   a description than an integer (which is what `gal_table_read_cols'
-   needs). This function will check the string value and give the
-   corresponding integer value.*/
-uint8_t
-gal_table_string_to_searchin(char *string)
-{
-  if(string)                    /* Its not NULL. */
-    {
-      if(!strcmp(string, "name"))          return GAL_TABLE_SEARCH_NAME;
-      else if(!strcmp(string, "unit"))     return GAL_TABLE_SEARCH_UNIT;
-      else if(!strcmp(string, "comment"))  return GAL_TABLE_SEARCH_COMMENT;
-      else                                 return GAL_TABLE_SEARCH_INVALID;
-    }
-  else                                     return GAL_TABLE_SEARCH_INVALID;
-}
-
-
-
-
+/* Store the information of each column in a table (either as a text file
+   or as a FITS table) into an array of data structures with `numcols'
+   structures (one data structure for each column). The number of rows is
+   stored in `numrows'. The type of the table (e.g., ascii text file, or
+   FITS binary or ASCII table) will be put in `tableformat' (macros defined
+   in `gnuastro/table.h'.
 
-char *
-gal_table_searchin_as_string(uint8_t searchin)
+   Note that other than the character strings (column name, units and
+   comments), nothing in the data structure(s) will be allocated by this
+   function for the actual data (e.g., the `array' or `dsize' elements). */
+gal_data_t *
+gal_table_info(char *filename, char *hdu, size_t *numcols, size_t *numrows,
+               int *tableformat)
 {
-  switch(searchin)
+  /* Get the table format and size (number of columns and rows). */
+  if(gal_fits_name_is_fits(filename))
+    return gal_fits_tab_info(filename, hdu, numcols, numrows, tableformat);
+  else
     {
-    case GAL_TABLE_SEARCH_NAME:    return "name";
-    case GAL_TABLE_SEARCH_UNIT:    return "unit";
-    case GAL_TABLE_SEARCH_COMMENT: return "comment";
-    default:
-      error(EXIT_FAILURE, 0, "%s: code %d not recognized as a valid search "
-            "field", __func__, searchin);
-      return NULL;
+      *tableformat=GAL_TABLE_FORMAT_TXT;
+      return gal_txt_table_info(filename, numcols, numrows);
     }
-}
-
-
-
-
 
-/* For programs that output tables, the `--tableformat' option will be used
-   to specify what format the output table should be in. When the output
-   file is a FITS file, there are multiple formats, so to simplify the
-   coding in each program, this function will do a sanity check on the
-   value given to the `--tableformat' parameter. */
-void
-gal_table_check_fits_format(char *filename, int tableformat)
-{
-  if( filename && gal_fits_name_is_fits(filename) )
-    {
-      /* When `--tableformat' was not given. */
-      if(tableformat==GAL_TABLE_FORMAT_INVALID)
-        error(EXIT_FAILURE, 0, "`%s' (output file) is a FITS file but the "
-              "desired format of the FITS table has not been specified with "
-              "the `--tableformat' option. For FITS tables, this option can "
-              "take two values: `fits-ascii', or `fits-binary'", filename);
-
-      /* When `--tableformat' didn't have the correct value. */
-      if( tableformat != GAL_TABLE_FORMAT_AFITS
-          && tableformat != GAL_TABLE_FORMAT_BFITS )
-        error(EXIT_FAILURE, 0, "`%s' (output file) is a FITS file but "
-              "is not a recognized FITS table format. For FITS tables, "
-              "`--tableformat' can take two values: `fits-ascii', or "
-              "`fits-binary'", filename);
-    }
+  /* Abort with an error if we get to this point. */
+  error(EXIT_FAILURE, 0, "%s: a bug! please contact us at %s so we can fix "
+        "the problem. Control must not have reached the end of this function",
+        __func__, PACKAGE_BUGREPORT);
+  return NULL;
 }
 
 
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/************************************************************************/
-/***************          Printing information            ***************/
-/************************************************************************/
 void
 gal_table_print_info(gal_data_t *allcols, size_t numcols, size_t numrows)
 {
@@ -274,259 +138,6 @@ gal_table_print_info(gal_data_t *allcols, size_t numcols, 
size_t numrows)
 
 
 
-/* Fill in/adjust the basic information necessary to print a column. This
-   information can be used for printing a plain text file or for FITS ASCII
-   tables. The `fmt' and `lng' should point to pre-allocated arrays. The
-   best way is: `char fmt[2], lng[3];' in the same function calling this.
-
-   The width and precision, which are also necessary for printing, are
-   updated in the data structure's `disp_width' and `disp_precision'
-   elements.
-*/
-void
-gal_table_col_print_info(gal_data_t *col, int tableformat, char *fmt,
-                         char *lng)
-{
-  size_t j;
-  char **strarr;
-  int maxstrlen, width=0, precision=0;
-
-
-  /* First do a sanity check, so we can safly stop checking in the steps
-     below. */
-  switch(tableformat)
-    {
-    case GAL_TABLE_FORMAT_TXT:
-    case GAL_TABLE_FORMAT_AFITS:
-      break;
-    default:
-      error(EXIT_FAILURE, 0, "%s: tableformat code %d not recognized",
-            __func__, tableformat);
-    }
-
-
-
-  /* Set the formats and widths based on the type of the column. Initialize
-     the characters and blank pointer. The long prefix is not necessary for
-     most types, so just initialize it once up here.*/
-  fmt[0]=fmt[1]=lng[0]=lng[1]=lng[2]='\0';
-  switch(col->type)
-    {
-    case GAL_TYPE_BIT:
-      error(EXIT_FAILURE, 0, "%s: printing of bit types is currently "
-            "not supported", __func__);
-      break;
-
-
-
-
-    case GAL_TYPE_STRING:
-
-      /* Set the basic information. */
-      fmt[0] = tableformat==GAL_TABLE_FORMAT_TXT ? 's' : 'A';
-
-      /* Go through all the strings in the column and find the maximum
-         length to use as printing. If the user asked for a larger width
-         (through the data structure's disp_width element), then set
-         that. */
-      maxstrlen=0;
-      strarr=col->array;
-      for(j=0;j<col->size;++j)
-        maxstrlen = ( (int)strlen(strarr[j]) > maxstrlen
-                      ? (int)strlen(strarr[j]) : maxstrlen );
-      width = col->disp_width>maxstrlen ? col->disp_width : maxstrlen;
-      break;
-
-
-
-
-    case GAL_TYPE_UINT8:
-    case GAL_TYPE_UINT16:
-    case GAL_TYPE_UINT32:
-    case GAL_TYPE_UINT64:
-
-      /* For the FITS ASCII table, there is only one format for all
-         integers.  */
-      if(tableformat==GAL_TABLE_FORMAT_AFITS)
-        fmt[0]='I';
-      else
-        switch(col->disp_fmt)
-          {
-          case GAL_TABLE_DISPLAY_FMT_UDECIMAL: fmt[0]='u'; break;
-          case GAL_TABLE_DISPLAY_FMT_OCTAL:    fmt[0]='o'; break;
-          case GAL_TABLE_DISPLAY_FMT_HEX:      fmt[0]='X'; break;
-          default:                             fmt[0]='u';
-          }
-
-      /* If we have a long type, then make changes. */
-      if(col->type==GAL_TYPE_UINT64)
-        {
-          lng[0]='l';
-          width=( col->disp_width<=0 ? GAL_TABLE_DEF_LINT_WIDTH
-                  : col->disp_width );
-        }
-      else width=( col->disp_width<=0 ? GAL_TABLE_DEF_INT_WIDTH
-                    : col->disp_width );
-      precision=( col->disp_precision<=0 ? GAL_TABLE_DEF_INT_PRECISION
-                  : col->disp_precision );
-      break;
-
-
-
-
-    case GAL_TYPE_INT8:
-    case GAL_TYPE_INT16:
-    case GAL_TYPE_INT32:
-      fmt[0] = tableformat==GAL_TABLE_FORMAT_TXT ? 'd' : 'I';
-      width = ( col->disp_width<=0 ? GAL_TABLE_DEF_INT_WIDTH
-                : col->disp_width );
-      precision = ( col->disp_precision<=0 ? GAL_TABLE_DEF_INT_PRECISION
-                    : col->disp_precision );
-      break;
-
-
-
-
-    case GAL_TYPE_INT64:
-      lng[0] = 'l';
-      fmt[0] = tableformat==GAL_TABLE_FORMAT_TXT ? 'd' : 'I';
-      width=( col->disp_width<=0 ? GAL_TABLE_DEF_LINT_WIDTH
-              : col->disp_width );
-      precision=( col->disp_precision<=0 ? GAL_TABLE_DEF_INT_PRECISION
-                  : col->disp_precision );
-      break;
-
-
-
-    /* We need a default value (because in most cases, it won't be set. */
-    case GAL_TYPE_FLOAT32:
-    case GAL_TYPE_FLOAT64:
-      switch(col->disp_fmt)
-        {
-        case GAL_TABLE_DISPLAY_FMT_FLOAT:
-          fmt[0] = tableformat==GAL_TABLE_FORMAT_TXT ? 'f' : 'F'; break;
-        case GAL_TABLE_DISPLAY_FMT_EXP:
-          fmt[0] = tableformat==GAL_TABLE_FORMAT_TXT ? 'e' : 'E'; break;
-        case GAL_TABLE_DISPLAY_FMT_GENERAL:
-          fmt[0] = tableformat==GAL_TABLE_FORMAT_TXT ? 'g' : 'E'; break;
-        default:
-          fmt[0] = tableformat==GAL_TABLE_FORMAT_TXT ? 'g' : 'E'; break;
-        }
-      width = ( col->disp_width<=0
-                ? ( col->type==GAL_TYPE_FLOAT32
-                    ? GAL_TABLE_DEF_FLT_WIDTH
-                    : GAL_TABLE_DEF_DBL_WIDTH )
-                : col->disp_width );
-      precision = ( col->disp_precision<=0 ? GAL_TABLE_DEF_FLT_PRECISION
-                    : col->disp_precision );
-      break;
-
-
-
-    default:
-      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
-            __func__, col->type);
-    }
-
-  /* Write the final width and precision into the column's data structure. */
-  col->disp_width=width;
-  col->disp_precision=precision;
-}
-
-
-
-
-
-/* Use the input `blank' string and the input column to put the blank value
-   in the column's array. This function should later be generalized into a
-   function to read a string into a given data type (see
-   `gal_data_string_to_array_elem'). It is only here temporarily. */
-void
-gal_table_read_blank(gal_data_t *col, char *blank)
-{
-  void *colarr=col->array;
-
-  /* If there is nothing to use as blank, then don't continue, note that
-     the column data structure was initialized to mean that there is no
-     blank value. */
-  if(blank==NULL) return;
-
-  /* Just for a sanity check, the ndim and array elements should be zero. */
-  if(col->ndim || col->array)
-    error(EXIT_FAILURE, 0, "%s: a bug! The number of dimensions, and the "
-          "`array' element of a column must be zero", __func__);
-
-  /* Read the blank value as the given type. If successful, then
-     `gal_data_string_to_type' will return 0. In that case, we need to
-     initialize the necessary paramters to read this data structure
-     correctly. */
-  if( !gal_type_from_string(&colarr, blank, col->type) )
-    {
-      errno=0;
-      col->dsize=malloc(sizeof *col->dsize);
-      if(col->dsize==NULL)
-        error(EXIT_FAILURE, 0, "%s: allocating %zu bytes for `col->dsize'",
-              __func__, sizeof *col->dsize);
-      col->dsize[0]=col->ndim=col->size=1;
-    }
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/************************************************************************/
-/***************         Information about a table        ***************/
-/************************************************************************/
-/* Store the information of each column in a table (either as a text file
-   or as a FITS table) into an array of data structures with `numcols'
-   structures (one data structure for each column). The number of rows is
-   stored as the `size' element of each data structure. The type of the
-   table (e.g., ascii text file, or FITS binary or ASCII table) will be put
-   in `tableformat' (macros defined in `gnuastro/table.h'.
-
-   Note that other than the character strings (column name, units and
-   comments), nothing in the data structure(s) will be allocated by this
-   function for the actual data (e.g., the `array' or `dsize' elements). */
-gal_data_t *
-gal_table_info(char *filename, char *hdu, size_t *numcols, size_t *numrows,
-               int *tableformat)
-{
-  /* Get the table format and size (number of columns and rows). */
-  if(gal_fits_name_is_fits(filename))
-    return gal_fits_tab_info(filename, hdu, numcols, numrows, tableformat);
-  else
-    {
-      *tableformat=GAL_TABLE_FORMAT_TXT;
-      return gal_txt_table_info(filename, numcols, numrows);
-    }
-
-  /* Abort with an error if we get to this point. */
-  error(EXIT_FAILURE, 0, "%s: a bug! please contact us at %s so we can fix "
-        "the problem. Control must not have reached the end of this function",
-        __func__, PACKAGE_BUGREPORT);
-  return NULL;
-}
-
-
-
-
-
 
 
 
@@ -549,7 +160,7 @@ gal_table_info(char *filename, char *hdu, size_t *numcols, 
size_t *numrows,
 /* Function to print regular expression error. This is taken from the GNU C
    library manual, with small modifications to fit out style, */
 static void
-regexerrorexit(int errcode, regex_t *compiled, char *input)
+table_regexerrorexit(int errcode, regex_t *compiled, char *input)
 {
   char *regexerrbuf;
   size_t length = regerror (errcode, compiled, NULL, 0);
@@ -652,7 +263,7 @@ make_list_of_indexs(gal_list_str_t *cols, gal_data_t 
*allcols,
                                           ? RE_SYNTAX_AWK | REG_ICASE
                                           : RE_SYNTAX_AWK ) );
           if(regreturn)
-            regexerrorexit(regreturn, regex, str);
+            table_regexerrorexit(regreturn, regex, str);
 
 
           /* With the regex structure "compile"d you can go through all the
@@ -746,8 +357,8 @@ make_list_of_indexs(gal_list_str_t *cols, gal_data_t 
*allcols,
       if(nummatch==0)
         {
           asprintf(&errorstring, "`%s' didn't match any of the column %ss.",
-                   tmp->v, gal_table_searchin_as_string(searchin));
-          gal_table_error_col_selection(filename, hdu, errorstring);
+                   tmp->v, gal_tableintern_searchin_as_string(searchin));
+          gal_tableintern_error_col_selection(filename, hdu, errorstring);
         }
     }
 
@@ -760,13 +371,13 @@ make_list_of_indexs(gal_list_str_t *cols, gal_data_t 
*allcols,
 
 
 
-/* Read the specified columns in a text file (named `filename') into a
-   linked list of data structures. If the file is FITS, then `hdu' will
-   also be used, otherwise, `hdu' is ignored. The information to search for
-   columns should be specified by the `cols' linked list as string values
-   in each node of the list, the strings in each node can be a number, an
-   exact match to a column name, or a regular expression (in GNU AWK
-   format) enclosed in `/ /'. The `searchin' value comes from the
+/* Read the specified columns in a table (named `filename') into a linked
+   list of data structures. If the file is FITS, then `hdu' will also be
+   used, otherwise, `hdu' is ignored. The information to search for columns
+   should be specified by the `cols' linked list as string values in each
+   node of the list, the strings in each node can be a number, an exact
+   match to a column name, or a regular expression (in GNU AWK format)
+   enclosed in `/ /'. The `searchin' value comes from the
    `gal_table_where_to_search' enumerator and has to be one of its given
    types. If `cols' is NULL, then this function will read the full table.
 
@@ -886,7 +497,8 @@ gal_table_comments_add_intro(gal_list_str_t **comments, 
char *program_string,
   /* Program name: this will be the top of the list (first line). We will
      need to set the allocation flag for this one, because program_string
      is usually statically allocated.*/
-  gal_list_str_add(comments, program_string, 1);
+  if(program_string)
+    gal_list_str_add(comments, program_string, 1);
 }
 
 
diff --git a/lib/tableintern.c b/lib/tableintern.c
new file mode 100644
index 0000000..fded702
--- /dev/null
+++ b/lib/tableintern.c
@@ -0,0 +1,419 @@
+/*********************************************************************
+table -- Functions for I/O on tables.
+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 <stdio.h>
+#include <errno.h>
+#include <error.h>
+#include <regex.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <gnuastro/git.h>
+#include <gnuastro/txt.h>
+#include <gnuastro/blank.h>
+#include <gnuastro/table.h>
+
+#include <gnuastro-internal/timing.h>
+#include <gnuastro-internal/checkset.h>
+
+
+
+
+
+
+/************************************************************************/
+/***************              Error messages              ***************/
+/************************************************************************/
+void
+gal_tableintern_error_col_selection(char *filename, char *hdu,
+                                    char *errorstring)
+{
+  char *c, *name, *command;
+
+  /* Set the proper pointers. */
+  if(gal_fits_name_is_fits(filename))
+    {
+      asprintf(&name, "%s (hdu: %s)", filename, hdu);
+      c=hdu; while(*c!='\0') if(isspace(*c++)) break;
+      asprintf(&command, *c=='\0' ? "%s --hdu=%s" : "%s --hdu=\"%s\"",
+               filename, hdu);
+    }
+  else command=name=filename;
+
+  /* Abort with with the proper error. */
+  error(EXIT_FAILURE, 0, "%s: %s\n\nFor more information on selecting "
+        "columns in Gnuastro, please run the following command (press "
+        "`SPACE' to go down and `q' to return to the command-line):\n\n"
+        "    $ info gnuastro \"Selecting table columns\"\n\n"
+        "To define a better column selection criteria, you can see "
+        "the list of column meta-data in this table, with the following "
+        "command:\n\n"
+        "    $ asttable %s --info\n", name, errorstring, command);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/************************************************************************/
+/***************                 Formats                  ***************/
+/************************************************************************/
+/* Return the type of desired table based on a standard string. */
+uint8_t
+gal_tableintern_string_to_format(char *string)
+{
+  if(string)                    /* Its not NULL. */
+    {
+      if(!strcmp(string, "txt"))              return GAL_TABLE_FORMAT_TXT;
+      else if(!strcmp(string,"fits-ascii"))   return GAL_TABLE_FORMAT_AFITS;
+      else if(!strcmp(string, "fits-binary")) return GAL_TABLE_FORMAT_BFITS;
+      else                                    return GAL_TABLE_FORMAT_INVALID;
+    }
+  else                                        return GAL_TABLE_FORMAT_INVALID;
+}
+
+
+
+
+
+char *
+gal_tableintern_format_as_string(uint8_t tableformat)
+{
+  switch(tableformat)
+    {
+    case GAL_TABLE_FORMAT_TXT:    return "txt";
+    case GAL_TABLE_FORMAT_AFITS:  return "fits-ascii";
+    case GAL_TABLE_FORMAT_BFITS:  return "fits-binary";
+    default:
+      error(EXIT_FAILURE, 0, "%s: code %d not recognized", __func__,
+            tableformat);
+      return NULL;
+    }
+}
+
+
+
+
+
+
+/* In programs, the `searchin' variable is much more easier to format in as
+   a description than an integer (which is what `gal_table_read_cols'
+   needs). This function will check the string value and give the
+   corresponding integer value.*/
+uint8_t
+gal_tableintern_string_to_searchin(char *string)
+{
+  if(string)                    /* Its not NULL. */
+    {
+      if(!strcmp(string, "name"))          return GAL_TABLE_SEARCH_NAME;
+      else if(!strcmp(string, "unit"))     return GAL_TABLE_SEARCH_UNIT;
+      else if(!strcmp(string, "comment"))  return GAL_TABLE_SEARCH_COMMENT;
+      else                                 return GAL_TABLE_SEARCH_INVALID;
+    }
+  else                                     return GAL_TABLE_SEARCH_INVALID;
+}
+
+
+
+
+
+char *
+gal_tableintern_searchin_as_string(uint8_t searchin)
+{
+  switch(searchin)
+    {
+    case GAL_TABLE_SEARCH_NAME:    return "name";
+    case GAL_TABLE_SEARCH_UNIT:    return "unit";
+    case GAL_TABLE_SEARCH_COMMENT: return "comment";
+    default:
+      error(EXIT_FAILURE, 0, "%s: code %d not recognized as a valid search "
+            "field", __func__, searchin);
+      return NULL;
+    }
+}
+
+
+
+
+
+/* For programs that output tables, the `--tableformat' option will be used
+   to specify what format the output table should be in. When the output
+   file is a FITS file, there are multiple formats, so to simplify the
+   coding in each program, this function will do a sanity check on the
+   value given to the `--tableformat' parameter. */
+void
+gal_tableintern_check_fits_format(char *filename, int tableformat)
+{
+  if( filename && gal_fits_name_is_fits(filename) )
+    {
+      /* When `--tableformat' was not given. */
+      if(tableformat==GAL_TABLE_FORMAT_INVALID)
+        error(EXIT_FAILURE, 0, "`%s' (output file) is a FITS file but the "
+              "desired format of the FITS table has not been specified with "
+              "the `--tableformat' option. For FITS tables, this option can "
+              "take two values: `fits-ascii', or `fits-binary'", filename);
+
+      /* When `--tableformat' didn't have the correct value. */
+      if( tableformat != GAL_TABLE_FORMAT_AFITS
+          && tableformat != GAL_TABLE_FORMAT_BFITS )
+        error(EXIT_FAILURE, 0, "`%s' (output file) is a FITS file but "
+              "is not a recognized FITS table format. For FITS tables, "
+              "`--tableformat' can take two values: `fits-ascii', or "
+              "`fits-binary'", filename);
+    }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/************************************************************************/
+/***************          Printing information            ***************/
+/************************************************************************/
+/* Fill in/adjust the basic information necessary to print a column. This
+   information can be used for printing a plain text file or for FITS ASCII
+   tables. The `fmt' and `lng' should point to pre-allocated arrays. The
+   best way is: `char fmt[2], lng[3];' in the same function calling this.
+
+   The width and precision, which are also necessary for printing, are
+   updated in the data structure's `disp_width' and `disp_precision'
+   elements. */
+void
+gal_tableintern_col_print_info(gal_data_t *col, int tableformat,
+                               char *fmt, char *lng)
+{
+  size_t j;
+  char **strarr;
+  int maxstrlen, width=0, precision=0;
+
+
+  /* First do a sanity check, so we can safly stop checking in the steps
+     below. */
+  switch(tableformat)
+    {
+    case GAL_TABLE_FORMAT_TXT:
+    case GAL_TABLE_FORMAT_AFITS:
+      break;
+    default:
+      error(EXIT_FAILURE, 0, "%s: is only for plain text or FITS ASCII "
+            "tables. The input `tableformat' code %d not recognized",
+            __func__, tableformat);
+    }
+
+
+
+  /* Set the formats and widths based on the type of the column. Initialize
+     the characters and blank pointer. The long prefix is not necessary for
+     most types, so just initialize it once up here.*/
+  fmt[0]=fmt[1]=lng[0]=lng[1]=lng[2]='\0';
+  switch(col->type)
+    {
+    case GAL_TYPE_BIT:
+      error(EXIT_FAILURE, 0, "%s: printing of bit types is currently "
+            "not supported", __func__);
+      break;
+
+
+
+
+    case GAL_TYPE_STRING:
+
+      /* Set the basic information. */
+      fmt[0] = tableformat==GAL_TABLE_FORMAT_TXT ? 's' : 'A';
+
+      /* Go through all the strings in the column and find the maximum
+         length to use as printing. If the user asked for a larger width
+         (through the data structure's disp_width element), then set
+         that. */
+      maxstrlen=0;
+      strarr=col->array;
+      for(j=0;j<col->size;++j)
+        maxstrlen = ( (int)strlen(strarr[j]) > maxstrlen
+                      ? (int)strlen(strarr[j]) : maxstrlen );
+      width = col->disp_width>maxstrlen ? col->disp_width : maxstrlen;
+      break;
+
+
+
+
+    case GAL_TYPE_UINT8:
+    case GAL_TYPE_UINT16:
+    case GAL_TYPE_UINT32:
+    case GAL_TYPE_UINT64:
+
+      /* For the FITS ASCII table, there is only one format for all
+         integers.  */
+      if(tableformat==GAL_TABLE_FORMAT_AFITS)
+        fmt[0]='I';
+      else
+        switch(col->disp_fmt)
+          {
+          case GAL_TABLE_DISPLAY_FMT_UDECIMAL: fmt[0]='u'; break;
+          case GAL_TABLE_DISPLAY_FMT_OCTAL:    fmt[0]='o'; break;
+          case GAL_TABLE_DISPLAY_FMT_HEX:      fmt[0]='X'; break;
+          default:                             fmt[0]='u';
+          }
+
+      /* If we have a long type, then make changes. */
+      if(col->type==GAL_TYPE_UINT64)
+        {
+          lng[0]='l';
+          width=( col->disp_width<=0 ? GAL_TABLE_DEF_WIDTH_LINT
+                  : col->disp_width );
+        }
+      else width=( col->disp_width<=0 ? GAL_TABLE_DEF_WIDTH_INT
+                    : col->disp_width );
+      precision=( col->disp_precision<=0 ? GAL_TABLE_DEF_PRECISION_INT
+                  : col->disp_precision );
+      break;
+
+
+
+
+    case GAL_TYPE_INT8:
+    case GAL_TYPE_INT16:
+    case GAL_TYPE_INT32:
+      fmt[0] = tableformat==GAL_TABLE_FORMAT_TXT ? 'd' : 'I';
+      width = ( col->disp_width<=0 ? GAL_TABLE_DEF_WIDTH_INT
+                : col->disp_width );
+      precision = ( col->disp_precision<=0 ? GAL_TABLE_DEF_PRECISION_INT
+                    : col->disp_precision );
+      break;
+
+
+
+
+    case GAL_TYPE_INT64:
+      lng[0] = 'l';
+      fmt[0] = tableformat==GAL_TABLE_FORMAT_TXT ? 'd' : 'I';
+      width=( col->disp_width<=0 ? GAL_TABLE_DEF_WIDTH_LINT
+              : col->disp_width );
+      precision=( col->disp_precision<=0 ? GAL_TABLE_DEF_PRECISION_INT
+                  : col->disp_precision );
+      break;
+
+
+
+    /* We need a default value (because in most cases, it won't be set. */
+    case GAL_TYPE_FLOAT32:
+    case GAL_TYPE_FLOAT64:
+      switch(col->disp_fmt)
+        {
+        case GAL_TABLE_DISPLAY_FMT_FLOAT:
+          fmt[0] = tableformat==GAL_TABLE_FORMAT_TXT ? 'f' : 'F'; break;
+        case GAL_TABLE_DISPLAY_FMT_EXP:
+          fmt[0] = tableformat==GAL_TABLE_FORMAT_TXT ? 'e' : 'E'; break;
+        case GAL_TABLE_DISPLAY_FMT_GENERAL:
+          fmt[0] = tableformat==GAL_TABLE_FORMAT_TXT ? 'g' : 'E'; break;
+        default:
+          fmt[0] = tableformat==GAL_TABLE_FORMAT_TXT ? 'g' : 'E'; break;
+        }
+      width = ( col->disp_width<=0
+                ? ( col->type==GAL_TYPE_FLOAT32
+                    ? GAL_TABLE_DEF_WIDTH_FLT
+                    : GAL_TABLE_DEF_WIDTH_DBL )
+                : col->disp_width );
+      precision = ( col->disp_precision<=0 ? GAL_TABLE_DEF_PRECISION_FLT
+                    : col->disp_precision );
+      break;
+
+
+
+    default:
+      error(EXIT_FAILURE, 0, "%s: type code %d not recognized",
+            __func__, col->type);
+    }
+
+  /* Write the final width and precision into the column's data structure. */
+  col->disp_width=width;
+  col->disp_precision=precision;
+}
+
+
+
+
+
+/* Use the input `blank' string and the input column to put the blank value
+   in the column's array. This function should later be generalized into a
+   function to read a string into a given data type (see
+   `gal_data_string_to_array_elem'). It is only here temporarily. */
+void
+gal_tableintern_read_blank(gal_data_t *col, char *blank)
+{
+  void *colarr=col->array;
+
+  /* If there is nothing to use as blank, then don't continue, note that
+     the column data structure was initialized to mean that there is no
+     blank value. */
+  if(blank==NULL) return;
+
+  /* Just for a sanity check, the ndim and array elements should be zero. */
+  if(col->ndim || col->array)
+    error(EXIT_FAILURE, 0, "%s: the number of dimensions, and the "
+          "`array' element of `col' must be zero", __func__);
+
+  /* Read the blank value as the given type. If successful, then
+     `gal_data_string_to_type' will return 0. In that case, we need to
+     initialize the necessary paramters to read this data structure
+     correctly. */
+  if( !gal_type_from_string(&colarr, blank, col->type) )
+    {
+      errno=0;
+      col->dsize=malloc(sizeof *col->dsize);
+      if(col->dsize==NULL)
+        error(EXIT_FAILURE, 0, "%s: allocating %zu bytes for `col->dsize'",
+              __func__, sizeof *col->dsize);
+      col->dsize[0]=col->ndim=col->size=1;
+    }
+}
diff --git a/lib/txt.c b/lib/txt.c
index bfe4e0c..bd58174 100644
--- a/lib/txt.c
+++ b/lib/txt.c
@@ -36,7 +36,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <gnuastro/table.h>
 
 #include <gnuastro-internal/checkset.h>
-
+#include <gnuastro-internal/tableintern.h>
 
 
 
@@ -267,7 +267,7 @@ txt_info_from_comment(char *line, gal_data_t **datall, char 
*comm_start)
 
       /* Write the blank value into the array. Note that this is not the
          final column, we are just collecting information now. */
-      gal_table_read_blank(*datall, txt_trim_space(blank));
+      gal_tableintern_read_blank(*datall, txt_trim_space(blank));
     }
 }
 
@@ -1054,7 +1054,7 @@ make_fmts_for_printf(gal_data_t *datall, int leftadjust, 
size_t *len)
 
 
       /* Fill in the printing paramters. */
-      gal_table_col_print_info(data, GAL_TABLE_FORMAT_TXT, fmt, lng);
+      gal_tableintern_col_print_info(data, GAL_TABLE_FORMAT_TXT, fmt, lng);
 
 
       /* Adjust the width if a blank string was defined. */
@@ -1228,7 +1228,7 @@ txt_open_file_write_info(gal_data_t *datall, char **fmts,
 
 
 void
-gal_txt_write(gal_data_t *datall, gal_list_str_t *comment, char *filename,
+gal_txt_write(gal_data_t *input, gal_list_str_t *comment, char *filename,
               int dontdelete)
 {
   FILE *fp;
@@ -1238,32 +1238,32 @@ gal_txt_write(gal_data_t *datall, gal_list_str_t 
*comment, char *filename,
 
 
   /* Currently only 1 and 2 dimension datasets are acceptable. */
-  if( datall->ndim!=1 && datall->ndim!=2 )
+  if( input->ndim!=1 && input->ndim!=2 )
     error(EXIT_FAILURE, 0, "%s: only 1 and 2 dimensional datasets are "
           "currently supported. The input dataset has %zu dimensions",
-          __func__, datall->ndim);
+          __func__, input->ndim);
 
 
   /* For a 2D dataset, we currently don't accept a list, we can only print
      one column. So keep the next pointer separately and restore it after
      the job of this function is finished. */
-  if(datall->ndim==2)
+  if(input->ndim==2)
     {
-      next2d=datall->next;
-      datall->next=NULL;
+      next2d=input->next;
+      input->next=NULL;
     }
 
 
   /* Find the number of columns, do a small sanity check, and get the
      maximum width of the name and unit string if they are present. */
-  for(data=datall;data!=NULL;data=data->next)
+  for(data=input;data!=NULL;data=data->next)
     {
       /* Count. */
       ++num;
 
       /* Check if the dimensionality and size is the same for all the
          elements. */
-      if( datall!=data && gal_data_dsize_is_different(datall, data) )
+      if( input!=data && gal_data_dsize_is_different(input, data) )
         error(EXIT_FAILURE, 0, "%s: the input list of datasets must have the "
               "same sizes (dimentionality and length along each dimension)",
               __func__);
@@ -1272,25 +1272,25 @@ gal_txt_write(gal_data_t *datall, gal_list_str_t 
*comment, char *filename,
 
   /* Prepare the necessary formats for each column, then allocate the space
      for the full list and concatenate all the separate inputs into it. */
-  fmts=make_fmts_for_printf(datall, 1, &fmtlen);
+  fmts=make_fmts_for_printf(input, 1, &fmtlen);
 
 
   /* Set the output FILE pointer: if it isn't NULL, its an actual file,
      otherwise, its the standard output. */
   fp = ( filename
-         ? txt_open_file_write_info(datall, fmts, comment, filename,
+         ? txt_open_file_write_info(input, fmts, comment, filename,
                                     dontdelete)
          : stdout );
 
 
   /* Print the dataset */
-  switch(datall->ndim)
+  switch(input->ndim)
     {
     case 1:
-      for(i=0;i<datall->size;++i)                        /* Row.    */
+      for(i=0;i<input->size;++i)                        /* Row.    */
         {
           j=0;
-          for(data=datall;data!=NULL;data=data->next)    /* Column. */
+          for(data=input;data!=NULL;data=data->next)    /* Column. */
             txt_print_value(fp, data->array, data->type, i,
                             fmts[j++ * FMTS_COLS]);
           fprintf(fp, "\n");
@@ -1299,19 +1299,19 @@ gal_txt_write(gal_data_t *datall, gal_list_str_t 
*comment, char *filename,
 
 
     case 2:
-      for(i=0;i<datall->dsize[0];++i)
+      for(i=0;i<input->dsize[0];++i)
         {
-          for(j=0;j<datall->dsize[1];++j)
-            txt_print_value(fp, datall->array, datall->type,
-                            i*datall->dsize[1]+j, fmts[0]);
+          for(j=0;j<input->dsize[1];++j)
+            txt_print_value(fp, input->array, input->type,
+                            i*input->dsize[1]+j, fmts[0]);
           fprintf(fp, "\n");
         }
       break;
 
 
     default:
-      error(EXIT_FAILURE, 0, "%s: a bug! datall->ndim=%zu is not recognized",
-            __func__, datall->ndim);
+      error(EXIT_FAILURE, 0, "%s: a bug! input->ndim=%zu is not recognized",
+            __func__, input->ndim);
     }
 
 
@@ -1336,5 +1336,5 @@ gal_txt_write(gal_data_t *datall, gal_list_str_t 
*comment, char *filename,
     }
 
   /* Restore the next pointer for a 2D dataset. */
-  if(datall->ndim==2) datall->next=next2d;
+  if(input->ndim==2) input->next=next2d;
 }



reply via email to

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