gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master ce08c34 14/16: FITS (binary) tables <--> plain


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master ce08c34 14/16: FITS (binary) tables <--> plain text in Table
Date: Wed, 24 Aug 2016 22:27:44 +0000 (UTC)

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

    FITS (binary) tables <--> plain text in Table
    
    Table can now convert an ASCII (theoretically, not yet tested) and Binary
    FITS table into an ASCII plain text file. It can also convert ASCII plain
    text files to binary FITS tables. ASCII FITS tables have a different
    `TFORMn' keyword format which made the work a little complicated so it was
    not implemented at this time. Maybe later (when the need arises) we can
    implement it is not hard, just needs some time (that I don't have now). Two
    tests were also written to test these conversions.
    
    Note that Table does have the `--fitstabletype' option to determine the
    output FITS table type, but currently if `ascii' is passed to it, it will
    inform the user that this is not yet implementend and that they should get
    in touch with us so we can implement it.
    
    Within Table, the old `tform' and `ttype' arrays in the `uiparams'
    structure were named after the FITS standard keywords. However, these names
    can be mis-leading, for example the "TTYPEn" is for the name of the column,
    not the data type. So they were renamed to the more appropriate names:
    `ttstr' (or table-type-string) and `tname'.
    
    Table can still use a lot of work to greatly improve, in particular to read
    plain text files by columns, this work will also benefit the `lib/txtarray'
    (and thus all the utitlies that use it). Also once it is mature enough,
    utilities that input or output tables/catalogs can do so from FITS
    tables. So it would be a very useful work.
    
    It would also be very interesting if we could adopt a human readable
    convention to include the column information (for example name, type and
    units) in a plain text file (for example as lines starting with `#c') so a
    binary table and plain text file can be exactly convertable. Currently they
    are not: the ascii to binary operation will read everything only as double.
    
    The following modifications were made compared to previous commits:
    
     - `lib/checkset.c': A new `gal_checkset_check_file_report' function was
       added to report the existance of file, rather than just do the default
       operation. Some cosmetic changes were also made (fixing some line
       lengths).
    
     - `lib/fits.c': The `assert.h' header was an ancient artifact of the time
       I used the `assert' function! But I had forgot to remove it after
       abandoning that practice. So it was removed here. A new function
       `gal_fits_table_type' was added to return the type of a FITS table file.
    
     - `tests/during-dev.sh': a missed parenthesis was corrected.
---
 lib/checkset.c                |   54 +++++---
 lib/fits.c                    |   40 +++++-
 lib/gnuastro/checkset.h       |    3 +
 lib/gnuastro/fits.h           |    3 +
 src/table/Makefile.am         |    5 +-
 src/table/args.h              |   17 ++-
 src/table/asttable.conf       |    1 +
 src/table/main.h              |   12 +-
 src/table/table.c             |  178 ++++++++++++++++++++-----
 src/table/ui.c                |  287 ++++++++++++++++++++++++++++++-----------
 src/table/ui.h                |    6 +-
 tests/Makefile.am             |    6 +-
 tests/during-dev.sh           |    2 +-
 tests/prepconf.sh             |    2 +-
 tests/table/asciitobinary.sh  |   51 ++++++++
 tests/table/asciitobinary.txt |    2 +
 tests/table/binarytoascii.sh  |   51 ++++++++
 17 files changed, 582 insertions(+), 138 deletions(-)

diff --git a/lib/checkset.c b/lib/checkset.c
index 58de7cd..1ad53e3 100644
--- a/lib/checkset.c
+++ b/lib/checkset.c
@@ -125,8 +125,8 @@ gal_checkset_int_zero_or_one(char *optarg, int *var, char 
*lo, char so,
 
 
 void
-gal_checkset_int_4_or_8(char *optarg, int *var, char *lo, char so, char *spack,
-                        char *filename, size_t lineno)
+gal_checkset_int_4_or_8(char *optarg, int *var, char *lo, char so,
+                        char *spack, char *filename, size_t lineno)
 {
   long tmp;
   char *tailptr;
@@ -150,8 +150,8 @@ gal_checkset_int_4_or_8(char *optarg, int *var, char *lo, 
char so, char *spack,
 
 
 void
-gal_checkset_int_el_zero(char *optarg, int *var, char *lo, char so, char 
*spack,
-                         char *filename, size_t lineno)
+gal_checkset_int_el_zero(char *optarg, int *var, char *lo, char so,
+                         char *spack, char *filename, size_t lineno)
 {
   long tmp;
   char *tailptr;
@@ -174,8 +174,8 @@ gal_checkset_int_el_zero(char *optarg, int *var, char *lo, 
char so, char *spack,
 
 
 void
-gal_checkset_int_l_zero(char *optarg, int *var, char *lo, char so, char *spack,
-                        char *filename, size_t lineno)
+gal_checkset_int_l_zero(char *optarg, int *var, char *lo, char so,
+                        char *spack, char *filename, size_t lineno)
 {
   long tmp;
   char *tailptr;
@@ -247,8 +247,8 @@ gal_checkset_long_el_zero(char *optarg, long *var, char 
*lo, char so,
 
 
 void
-gal_checkset_any_long(char *optarg, long *var, char *lo, char so, char *spack,
-                      char *filename, size_t lineno)
+gal_checkset_any_long(char *optarg, long *var, char *lo, char so,
+                      char *spack, char *filename, size_t lineno)
 {
   char *tailptr;
   *var=strtol(optarg, &tailptr, 0);
@@ -339,8 +339,8 @@ gal_checkset_sizet_p_odd(char *optarg, size_t *var, char 
*lo, char so,
 
 
 void
-gal_checkset_float_l_0(char *optarg, float *var, char *lo, char so, char* 
spack,
-                       char *filename, size_t lineno)
+gal_checkset_float_l_0(char *optarg, float *var, char *lo, char so,
+                       char* spack, char *filename, size_t lineno)
 {
   float tmp;
   char *tailptr;
@@ -386,8 +386,8 @@ gal_checkset_float_l_0_s_1(char *optarg, float *var, char 
*lo, char so,
 
 
 void
-gal_checkset_any_float(char *optarg, float *var, char *lo, char so, char 
*spack,
-                       char *filename, size_t lineno)
+gal_checkset_any_float(char *optarg, float *var, char *lo, char so,
+                       char *spack, char *filename, size_t lineno)
 {
   char *tailptr;
   *var=strtof(optarg, &tailptr);
@@ -622,6 +622,28 @@ gal_checkset_check_file(char *filename)
 
 
 
+/* Similar to `gal_checkset_check_file', but will report the result instead
+   of doing it quietly. */
+int
+gal_checkset_check_file_report(char *filename)
+{
+  FILE *tmpfile;
+  errno=0;
+  tmpfile = fopen(filename, "r");
+  if(tmpfile)                        /* The file opened. */
+    {
+      if(fclose(tmpfile)==EOF)
+        error(EXIT_FAILURE, errno, "%s", filename);
+      return 1;
+    }
+  else
+    return 0;
+}
+
+
+
+
+
 /* Check if a file exists. If so, remove it. */
 void
 gal_checkset_check_remove_file(char *filename, int dontdelete)
@@ -672,10 +694,10 @@ gal_checkset_dir_0_file_1(char *name, int dontdelete)
   struct stat nameinfo;
 
   if(name==NULL)
-    error(EXIT_FAILURE, 0, "a bug! The input to the gal_checkset_dir_0_file_1 "
-          "function in checkset.c should not be NULL. Please contact us at "
-          PACKAGE_BUGREPORT" so we can see what went wrong and fix it in "
-          "future updates");
+    error(EXIT_FAILURE, 0, "a bug! The input to the "
+          "gal_checkset_dir_0_file_1 function in checkset.c should not "
+          "be NULL. Please contact us at "PACKAGE_BUGREPORT" so we can "
+          "see what went wrong and fix it in future updates");
 
   errno=0;
   if(stat(name, &nameinfo)!=0)
diff --git a/lib/fits.c b/lib/fits.c
index d5d7d91..38ecb07 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -29,7 +29,6 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <assert.h>
 
 #include <gnuastro/fits.h>
 #include <gnuastro/checkset.h>
@@ -1854,6 +1853,45 @@ gal_fits_table_size(fitsfile *fitsptr, size_t *nrows, 
size_t *ncols)
 
 
 
+int
+gal_fits_table_type(fitsfile *fptr)
+{
+  int status=0;
+  char value[FLEN_VALUE];
+
+  fits_read_key(fptr, TSTRING, "XTENSION", value, NULL, &status);
+
+  if(status==0)
+    {
+      if(!strcmp(value, "TABLE   "))
+        return ASCII_TBL;
+      else if(!strcmp(value, "BINTABLE"))
+        return BINARY_TBL;
+      else
+        error(EXIT_FAILURE, 0, "The `XTENSION' keyword of this FITS file "
+              "doesn't have a standard value (`%s')", value);
+    }
+  else
+    {
+      if(status==KEY_NO_EXIST)
+        error(EXIT_FAILURE, 0, "the `gal_fits_table_type' function was "
+              "called on a FITS extension which is not a table. As part "
+              "of a utility, this is bug, so please contact us at %s so "
+              "we can fix it.", PACKAGE_BUGREPORT);
+      else
+        gal_fits_io_error(status, NULL);
+    }
+
+  error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we can fix it. "
+        "for some reason, the control of `gal_fits_table_type' has reached "
+        "the end of the function! This must not happen", PACKAGE_BUGREPORT);
+  return -1;
+}
+
+
+
+
+
 
 
 
diff --git a/lib/gnuastro/checkset.h b/lib/gnuastro/checkset.h
index 532a64d..1de6428 100644
--- a/lib/gnuastro/checkset.h
+++ b/lib/gnuastro/checkset.h
@@ -205,6 +205,9 @@ gal_checkset_allocate_copy_set(char *arg, char **copy, int 
*set);
 void
 gal_checkset_check_file(char *filename);
 
+int
+gal_checkset_check_file_report(char *filename);
+
 void
 gal_checkset_check_remove_file(char *filename, int dontdelete);
 
diff --git a/lib/gnuastro/fits.h b/lib/gnuastro/fits.h
index 9e759c1..4a81360 100644
--- a/lib/gnuastro/fits.h
+++ b/lib/gnuastro/fits.h
@@ -242,6 +242,9 @@ gal_fits_tform_to_dtype(char tform);
 void
 gal_fits_table_size(fitsfile *fitsptr, size_t *nrows, size_t *ncols);
 
+int
+gal_fits_table_type(fitsfile *fptr);
+
 
 
 
diff --git a/src/table/Makefile.am b/src/table/Makefile.am
index d5c6289..4c66f48 100644
--- a/src/table/Makefile.am
+++ b/src/table/Makefile.am
@@ -28,8 +28,9 @@ bin_PROGRAMS = asttable
 asttable_SOURCES = main.c main.h cite.h ui.c ui.h args.h       \
 table.c table.h
 
-asttable_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la            \
--lgalconfigfiles -lgalfits -lgalcheckset -lgaltiming -lgallinkedlist
+asttable_LDADD = $(top_builddir)/bootstrapped/lib/libgnu.la             \
+-lgalconfigfiles -lgalfits -lgalcheckset -lgaltiming -lgallinkedlist    \
+-lgaltxtarray
 
 
 
diff --git a/src/table/args.h b/src/table/args.h
index 8708878..ac82696 100644
--- a/src/table/args.h
+++ b/src/table/args.h
@@ -73,7 +73,7 @@ const char doc[] =
 
 /* Available letters for short options:
 
-   a b d e f g j k l m n p r s t u v w x y z
+   a b d e f g j k l m n p r s u v w x y z
    A B C E F G H J L M O Q R T U W X Y Z
 
    Number keys used: 1008
@@ -177,6 +177,14 @@ static struct argp_option options[] =
       "`double' column(s) precision.",
       2
     },
+    {
+      "fitstabletype",
+      't',
+      "STR",
+      0,
+      "Only `ascii', or `binary' are acceptable.",
+      2
+    },
 
 
 
@@ -245,7 +253,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
 
     /* Output: */
     case 1001:
-      checkfge(arg, &p->up.feg);
+      checksetfge(arg, &p->up.feg, NULL, 0);
       p->up.fegset=1;
       break;
 
@@ -291,6 +299,11 @@ parse_opt(int key, char *arg, struct argp_state *state)
       p->up.doubleprecisionset=1;
       break;
 
+    case 't':
+      checksetfitstabletype(arg, &p->up.feg, NULL, 0);
+      p->up.fitstabletypeset=1;
+      break;
+
 
     /* Operating modes: */
     case 'i':
diff --git a/src/table/asttable.conf b/src/table/asttable.conf
index 77973eb..7bb2a00 100644
--- a/src/table/asttable.conf
+++ b/src/table/asttable.conf
@@ -29,3 +29,4 @@
  strwidth        20
  floatprecision   3
  doubleprecision  8
+ fitstabletype    binary
diff --git a/src/table/main.h b/src/table/main.h
index 2e7bfd1..50f5c80 100644
--- a/src/table/main.h
+++ b/src/table/main.h
@@ -41,6 +41,7 @@ struct outcolumn
   size_t inindex;               /* Row index (from 0) in input array.   */
   int   datatype;               /* Type of data (from CFITSIO macros).  */
   int     anynul;               /* If there is any blank characters.    */
+  void   *nulval;               /* The blank value for this column.     */
   void     *data;               /* Array keeping the column data.       */
   char fmt[MAX_COL_FORMAT_LENGTH];  /* format to use in printf.         */
 };
@@ -60,9 +61,11 @@ struct uiparams
   /* Input table parameters. */
   size_t                ncols;  /* Number of columns in table.          */
   int               *datatype;  /* Type of data in column.              */
-  char                **tform;  /* TFORM (another format for type).     */
-  char                **ttype;  /* Column name (one word).              */
+  char                **ttstr;  /* TFORM (another format for type).     */
+  char                **tname;  /* Column name (one word).              */
   char                **tunit;  /* Unit of values in column.            */
+  double            *txtarray;  /* Array keeping text file values.      */
+  int         infitstabletype;  /* Input table is ASCII or binary.      */
 
   /* Print parameters: */
   int                     feg;  /* format of floating points.           */
@@ -86,6 +89,7 @@ struct uiparams
   int             strwidthset;
   int       floatprecisionset;
   int      doubleprecisionset;
+  int        fitstabletypeset;
 
 
   struct gal_linkedlist_stll *columns;
@@ -109,6 +113,10 @@ struct tableparams
   size_t                nrows;  /* Number of rows in table.             */
   size_t               nocols;  /* Number of output columns.            */
   struct outcolumn     *ocols;  /* Array of output column informatio.   */
+  int            outputtofits;  /* ==1: output is a FITS file.          */
+  int             outputtotxt;  /* ==1: output is a text file.          */
+  int          outputtostdout;  /* ==1: output is the standard output.  */
+  int           fitstabletype;  /* ASCII, or binary table CFITSIO macro.*/
 
   /* Internal: */
   int                onlyview;
diff --git a/src/table/table.c b/src/table/table.c
index 588aa42..6b682b0 100644
--- a/src/table/table.c
+++ b/src/table/table.c
@@ -27,6 +27,7 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 #include <gnuastro/fits.h>
 
@@ -156,34 +157,57 @@ setformatstring(struct tableparams *p, size_t outcolid)
 void
 readinputcols(struct tableparams *p)
 {
-  size_t i;
-  void *nulval;
+  double *colfromtxt;
   struct outcolumn *col;
   int datatype, status=0;
+  size_t i, j, nrows=p->nrows, incols=p->up.ncols;
 
   /* Get the contents of each table column: */
   for(i=0;i<p->nocols;++i)
     {
       /* Variables for simple reading */
       col=&p->ocols[i];
-      datatype=col->datatype;
-
-      /* Allocate the blank value and array to keep the actual of this
-         column. */
-      nulval=gal_fits_datatype_blank(datatype);
-      col->data=gal_fits_datatype_alloc(p->nrows, datatype);
-
-      /* Call CFITSIO to read the column information. */
-      fits_read_col(p->fitsptr, datatype, col->inindex+1, 1, 1,
-                    p->nrows, nulval, col->data, &col->anynul,
-                    &status);
 
-      /* Free the space allocated for the blank value, we don't need it any
-         more: it is an internal macro to Gnuastro (see `fits.h'), */
-      free(nulval);
+      datatype=col->datatype;
 
-      /* Set the format string to print the column values. */
-      setformatstring(p, i);
+      /* Allocate the blank value for this column. Note that we will also
+         need the blankvalue for a text file when outputing to a FITS. */
+      col->nulval=gal_fits_datatype_blank(datatype);
+
+      /* Read the input column. */
+      if(p->fitsptr)
+        {
+          /* Allocate space for the data in this column */
+          col->data=gal_fits_datatype_alloc(nrows, datatype);
+
+          /* Call CFITSIO to read the column information. */
+          fits_read_col(p->fitsptr, datatype, col->inindex+1, 1, 1,
+                        nrows, col->nulval, col->data, &col->anynul,
+                        &status);
+        }
+      else
+        {
+          /* This is a text file, read by Gnuastro's current txtarray
+             library. This library currently only reads a 2D table into a
+             2D array of type double. The important thing here is that the
+             array is row-contiguous. But here we want column contiguous
+             data. So we allocate an array to only put this column's values
+             in.*/
+          errno=0;
+          colfromtxt=col->data=malloc(nrows * sizeof *col->data);
+
+          if(col->data==NULL)
+            error(EXIT_FAILURE, errno, "%lu bytes for col->data",
+                  nrows * sizeof *col->data);
+          for(j=0;j<nrows;++j)
+            colfromtxt[j]=p->up.txtarray[ j * incols + col->inindex ];
+        }
+
+      /* Set the format string to print the column values if the output is
+         to be printed as text (either in a text file or to the standard
+         output. */
+      if(p->outputtotxt || p->outputtostdout)
+        setformatstring(p, i);
     }
 }
 
@@ -210,11 +234,90 @@ readinputcols(struct tableparams *p)
 /***************       Output table         *******************/
 /**************************************************************/
 void
+saveouttofits(struct tableparams *p)
+{
+  size_t i;
+  int status=0;
+  fitsfile *fptr;
+  struct uiparams *up=&p->up;
+  char **ttype, **tform, **tunit;
+  struct outcolumn *ocols=p->ocols;
+
+  /* Allocate the information arrays for CFITSIO. */
+  errno=0;
+  ttype=malloc(p->nocols*sizeof *ttype);
+  if(ttype==NULL)
+    error(EXIT_FAILURE, errno, "%lu bytes for ttype",
+          p->nocols*sizeof *ttype);
+  errno=0;
+  tform=malloc(p->nocols*sizeof *tform);
+  if(tform==NULL)
+    error(EXIT_FAILURE, errno, "%lu bytes for tform",
+          p->nocols*sizeof *tform);
+  errno=0;
+  tunit=malloc(p->nocols*sizeof *tunit);
+  if(tunit==NULL)
+    error(EXIT_FAILURE, errno, "%lu bytes for tunit",
+          p->nocols*sizeof *tunit);
+
+  /* Fill in the information arrays: */
+  for(i=0;i<p->nocols;++i)
+    {
+      tform[i]=up->ttstr[ ocols[i].inindex ];
+      ttype[i]=up->tname[ ocols[i].inindex ];
+      tunit[i]=up->tunit[ ocols[i].inindex ];
+    }
+
+  /* Open the output FITS file. */
+  if(access(p->cp.output,F_OK) != -1 )
+    fits_open_file(&fptr, p->cp.output, READWRITE, &status);
+  else
+    fits_create_file(&fptr, p->cp.output, &status);
+
+  /* Create a new table extension */
+  fits_create_tbl(fptr, p->fitstabletype, p->nrows, p->nocols, ttype,
+                  tform, tunit, "Table", &status);
+
+  /* Write this column's data into the FITS file. */
+  for(i=0;i<p->nocols;++i)
+    fits_write_colnull(fptr, ocols[i].datatype, i+1, 1, 1, p->nrows,
+                       ocols[i].data, ocols[i].nulval, &status);
+
+  /* Include the ending comments and close the file. */
+  gal_fits_copyright_end(fptr, NULL, SPACK_STRING);
+  fits_close_file(fptr, &status);
+  gal_fits_io_error(status, NULL);
+
+  /* Clean up */
+  free(ttype);
+  free(tform);
+  free(tunit);
+}
+
+
+
+
+
+void
 printoutput(struct tableparams *p)
 {
+  FILE *fp;
   size_t i, row;
   struct outcolumn *ocols=p->ocols;
 
+  /* Determine the output stream and open the file for writing if its a
+     file. */
+  if(p->outputtotxt)
+    {
+      errno=0;
+      fp=fopen(p->cp.output, "w");
+      if(fp==NULL)
+        error(EXIT_FAILURE, errno, "%s", p->cp.output);
+    }
+  else
+    fp=stdout;
+
+  /* Print each column and each row: */
   for(row=0;row<p->nrows;++row)
     {
       for(i=0;i<p->nocols;++i)
@@ -226,35 +329,35 @@ printoutput(struct tableparams *p)
                   "it.", PACKAGE_BUGREPORT);
 
           case TBYTE:
-            printf(ocols[i].fmt, ((unsigned char *)ocols[i].data)[row]);
+            fprintf(fp, ocols[i].fmt, ((unsigned char *)ocols[i].data)[row]);
             break;
 
           case TLOGICAL: case TSBYTE:
-            printf(ocols[i].fmt, ((char *)ocols[i].data)[row]);
+            fprintf(fp, ocols[i].fmt, ((char *)ocols[i].data)[row]);
             break;
 
           case TSTRING:
-            printf(ocols[i].fmt, ((char **)ocols[i].data)[row]);
+            fprintf(fp, ocols[i].fmt, ((char **)ocols[i].data)[row]);
             break;
 
           case TSHORT:
-            printf(ocols[i].fmt, ((short *)ocols[i].data)[row]);
+            fprintf(fp, ocols[i].fmt, ((short *)ocols[i].data)[row]);
             break;
 
           case TLONG:
-            printf(ocols[i].fmt, ((long *)ocols[i].data)[row]);
+            fprintf(fp, ocols[i].fmt, ((long *)ocols[i].data)[row]);
             break;
 
           case TLONGLONG:
-            printf(ocols[i].fmt, ((LONGLONG *)ocols[i].data)[row]);
+            fprintf(fp, ocols[i].fmt, ((LONGLONG *)ocols[i].data)[row]);
             break;
 
           case TFLOAT:
-            printf(ocols[i].fmt, ((float *)ocols[i].data)[row]);
+            fprintf(fp, ocols[i].fmt, ((float *)ocols[i].data)[row]);
             break;
 
           case TDOUBLE:
-            printf(ocols[i].fmt, ((double *)ocols[i].data)[row]);
+            fprintf(fp, ocols[i].fmt, ((double *)ocols[i].data)[row]);
             break;
 
           case TCOMPLEX:
@@ -270,26 +373,34 @@ printoutput(struct tableparams *p)
             break;
 
           case TINT:
-            printf(ocols[i].fmt, ((char *)ocols[i].data)[row]);
+            fprintf(fp, ocols[i].fmt, ((char *)ocols[i].data)[row]);
             break;
 
           case TUINT:
-            printf(ocols[i].fmt, ((unsigned int *)ocols[i].data)[row]);
+            fprintf(fp, ocols[i].fmt, ((unsigned int *)ocols[i].data)[row]);
             break;
 
           case TUSHORT:
-            printf(ocols[i].fmt, ((unsigned short *)ocols[i].data)[row]);
+            fprintf(fp, ocols[i].fmt, ((unsigned short *)ocols[i].data)[row]);
             break;
 
           case TULONG:
-            printf(ocols[i].fmt, ((unsigned long *)ocols[i].data)[row]);
+            fprintf(fp, ocols[i].fmt, ((unsigned long *)ocols[i].data)[row]);
             break;
 
           default:
             error(EXIT_FAILURE, 0, "datatype value of %d not recognized in "
                   "printoutput", ocols[i].datatype);
           }
-      printf("\n");
+      fprintf(fp, "\n");
+    }
+
+  /* If we printed to a file, then close it. */
+  if(p->outputtotxt)
+    {
+      errno=0;
+      if( fclose(fp) == EOF )
+        error(EXIT_FAILURE, errno, "%s", p->cp.output);
     }
 }
 
@@ -319,5 +430,8 @@ table(struct tableparams *p)
 {
   readinputcols(p);
 
-  printoutput(p);
+  if(p->outputtofits)
+    saveouttofits(p);
+  else
+    printoutput(p);
 }
diff --git a/src/table/ui.c b/src/table/ui.c
index f65a344..d4825d1 100644
--- a/src/table/ui.c
+++ b/src/table/ui.c
@@ -67,13 +67,46 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 /**************************************************************/
 /* Check the value given for the fge option. */
 void
-checkfge(char *optarg, int *fge)
+checksetfge(char *optarg, int *fge, char *filename, size_t lineno)
 {
   *fge=optarg[0];
   if( *fge!='f' && *fge!='g' && *fge!='g' )
-    error(EXIT_FAILURE, 0, "the value of `--fge' (`-f') must only be "
-          "one of the three `f', `g', or `e' characters. You have "
-          "given `%s'.", optarg);
+    {
+      if(filename)
+        error_at_line(EXIT_FAILURE, 0, filename, lineno,
+                      "the value of `fge' must only be one of the three "
+                      "`f', `g', or `e' characters. You have given `%s'",
+                      optarg);
+      else
+        error(EXIT_FAILURE, 0, "the value of `--fge' (`-f') must only be "
+              "one of the three `f', `g', or `e' characters. You have "
+              "given `%s'", optarg);
+    }
+}
+
+
+
+
+
+void
+checksetfitstabletype(char *optarg, int *fitstabletype, char *filename,
+                   size_t lineno)
+{
+  if( !strcmp(optarg, "ascii") )
+    *fitstabletype=ASCII_TBL;
+  else if( !strcmp(optarg, "binary") )
+    *fitstabletype=BINARY_TBL;
+  else
+    {
+      if(filename)
+        error_at_line(EXIT_FAILURE, 0, filename, lineno,
+                      "The value to the `fitstabletype' must be either "
+                      "`ascii', or `binary'. You have given `%s'", optarg);
+      else
+        error(EXIT_FAILURE, 0, "The value to the `--fitstabletype' (`-t') "
+              "option must be either one of `ascii', or `binary'. You have, "
+              "given `%s'", optarg);
+    }
 }
 
 
@@ -118,7 +151,7 @@ readconfig(char *filename, struct tableparams *p)
 
       /* Inputs: */
       if(strcmp(name, "hdu")==0)
-        gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->outputset);
+        gal_checkset_allocate_copy_set(value, &cp->hdu, &cp->hduset);
 
       else if(strcmp(name, "column")==0)
         {
@@ -143,7 +176,7 @@ readconfig(char *filename, struct tableparams *p)
       else if (strcmp(name, "feg")==0)
         {
           if(p->up.fegset) continue;
-          checkfge(value, &p->up.feg);
+          checksetfge(value, &p->up.feg, filename, lineno);
           p->up.fegset=1;
         }
 
@@ -202,6 +235,12 @@ readconfig(char *filename, struct tableparams *p)
                                        name, key, SPACK, filename, lineno);
           p->up.doubleprecisionset=1;
         }
+      else if (strcmp(name, "fitstabletype")==0)
+        {
+          if(p->up.fitstabletypeset) continue;
+          checksetfitstabletype(value, &p->fitstabletype, filename, lineno);
+          p->up.fitstabletypeset=1;
+        }
 
 
 
@@ -269,6 +308,9 @@ printvalues(FILE *fp, struct tableparams *p)
     fprintf(fp, CONF_SHOWFMT"%lu\n", "floatprecision", up->floatprecision);
   if(up->doubleprecisionset)
     fprintf(fp, CONF_SHOWFMT"%lu\n", "doubleprecision", up->doubleprecision);
+  if(up->fitstabletypeset)
+    fprintf(fp, CONF_SHOWFMT"%s\n", "fitstabletype",
+            p->fitstabletype==ASCII_TBL ? "ascii" : "binary");
 
 
   /* For the operating mode, first put the macro to print the common
@@ -315,6 +357,8 @@ checkifset(struct tableparams *p)
     GAL_CONFIGFILES_REPORT_NOTSET("floatprecision");
   if(up->doubleprecisionset==0)
     GAL_CONFIGFILES_REPORT_NOTSET("doubleprecision");
+  if(up->fitstabletypeset==0)
+    GAL_CONFIGFILES_REPORT_NOTSET("fitstabletype");
 
   GAL_CONFIGFILES_END_OF_NOTSET_REPORT;
 }
@@ -337,9 +381,62 @@ checkifset(struct tableparams *p)
 
 
 
+
 /**************************************************************/
 /************     Read and Write column info    ***************/
 /**************************************************************/
+
+/*  */
+  /* Allocate the arrays to keep the column information. Initialize the
+     arrays with a NULL pointer to make sure that they are all found in the
+     end if they are necessary. The values that are directly read from the
+     input file are initialized to NULL, so they can be treated
+     appropriately if they do not exist in the input (for example if they
+     are mandatory, or if they need to be printed).*/
+void
+allocinputcolinfo(struct tableparams *p)
+{
+  char **c, **fc;
+  size_t ncols=p->up.ncols;
+  struct uiparams *up=&p->up;
+
+  /* up->datatype keeps the type of data in each column as CFITSIO type
+     macros. */
+  errno=0;
+  up->datatype=malloc(ncols * sizeof *up->datatype);
+  if(up->datatype==NULL)
+    error(EXIT_FAILURE, errno, "%lu bytes for up->datatype",
+          ncols * sizeof *up->datatype);
+
+  /* up->ttstr keeps the actual string used to specify the datatype. */
+  errno=0;
+  up->ttstr=malloc(ncols * sizeof *up->ttstr);
+  if(up->ttstr==NULL)
+    error(EXIT_FAILURE, errno, "%lu bytes for ttstr",
+          ncols * sizeof *up->ttstr);
+  fc=(c=up->ttstr)+ncols; do *c++=NULL; while(c<fc);
+
+  /* up->tname keeps the name of the column. */
+  errno=0;
+  up->tname=malloc(ncols * sizeof *up->tname);
+  if(up->tname==NULL)
+    error(EXIT_FAILURE, errno, "%lu bytes for tname",
+          ncols * sizeof *up->tname);
+  fc=(c=up->tname)+ncols; do *c++=NULL; while(c<fc);
+
+  /* up->tunit keeps the input units of the column. */
+  errno=0;
+  up->tunit=malloc(ncols * sizeof *up->tunit);
+  if(up->tunit==NULL)
+    error(EXIT_FAILURE, errno, "%lu bytes for tunit",
+          ncols * sizeof *up->tunit);
+  fc=(c=up->tunit)+ncols; do *c++=NULL; while(c<fc);
+}
+
+
+
+
+
 /* This function will read all the table information from a FITS table HDU
    and store them in arrays for use later. It is mainly good for getting
    all the information in a FITS table HDU. This function will only go
@@ -347,38 +444,17 @@ checkifset(struct tableparams *p)
    the keywords, so it is much more efficient than having to ask for each
    column's information separately.*/
 void
-readallcolinfo(fitsfile *fitsptr, size_t ncols, int **otypecode,
-               char ***otform, char ***ottype, char ***otunit)
+allfitscolinfo(struct tableparams *p)
 {
-  size_t index;
-  char *tailptr, **c, **fc;
-  int i, status=0, *typecode;
-  char **tform, **ttype, **tunit;
+  char *tailptr;
+  int i, status=0;
+  struct uiparams *up=&p->up;
+  size_t index, ncols=p->up.ncols;
   char keyname[FLEN_KEYWORD]="XXXXXXXXXXXXX", value[FLEN_VALUE];
 
 
-  /* Allocate the arrays to keep the column information. Initialize the
-     arrays with a NULL pointer to make sure that they are all found in the
-     end if they are necessary.*/
-  errno=0; typecode=*otypecode=malloc(ncols * sizeof *typecode);
-  if(typecode==NULL)
-    error(EXIT_FAILURE, errno, "%lu bytes for typecode",
-          ncols * sizeof *typecode);
-  errno=0; tform=*otform=malloc(ncols * sizeof *tform);
-  if(tform==NULL)
-    error(EXIT_FAILURE, errno, "%lu bytes for tform",
-          ncols * sizeof *tform);
-  fc=(c=tform)+ncols; do *c++=NULL; while(c<fc);
-  errno=0; ttype=*ottype=malloc(ncols * sizeof *ttype);
-  if(ttype==NULL)
-    error(EXIT_FAILURE, errno, "%lu bytes for ttype",
-          ncols * sizeof *ttype);
-  fc=(c=ttype)+ncols; do *c++=NULL; while(c<fc);
-  errno=0; tunit=*otunit=malloc(ncols * sizeof *tunit);
-  if(tunit==NULL)
-    error(EXIT_FAILURE, errno, "%lu bytes for tunit",
-          ncols * sizeof *tunit);
-  fc=(c=tunit)+ncols; do *c++=NULL; while(c<fc);
+  /* First allocate the arrays to keep the input column information. */
+  allocinputcolinfo(p);
 
 
   /* Read all the keywords one by one and if they match, then put them in
@@ -388,7 +464,7 @@ readallcolinfo(fitsfile *fitsptr, size_t ncols, int 
**otypecode,
   for(i=9; strcmp(keyname, "END"); ++i)
     {
       /* Read the next keyword. */
-      fits_read_keyn(fitsptr, i, keyname, value, NULL, &status);
+      fits_read_keyn(p->fitsptr, i, keyname, value, NULL, &status);
 
       /* Check the type of the keyword. */
       if(strncmp(keyname, "TFORM", 5)==0)
@@ -410,8 +486,8 @@ readallcolinfo(fitsfile *fitsptr, size_t ncols, int 
**otypecode,
           index=strtoul(&keyname[5], &tailptr, 10)-1;
           if(index<ncols)
             {
-              gal_checkset_allocate_copy(&value[1], &tform[index] );
-              typecode[index]=gal_fits_tform_to_dtype(value[1]);
+              gal_checkset_allocate_copy(&value[1], &up->ttstr[index] );
+              up->datatype[index]=gal_fits_tform_to_dtype(value[1]);
             }
         }
       else if(strncmp(keyname, "TTYPE", 5)==0)
@@ -424,29 +500,61 @@ readallcolinfo(fitsfile *fitsptr, size_t ncols, int 
**otypecode,
           value[strlen(value)-1]='\0';
           index=strtoul(&keyname[5], &tailptr, 10)-1;
           if(index<ncols)
-            gal_checkset_allocate_copy(&value[1], &ttype[index] );
+            gal_checkset_allocate_copy(&value[1], &up->tname[index] );
         }
       else if(strncmp(keyname, "TUNIT", 5)==0)
         {
-          /* similar to ttype, see above.*/
+          /* similar to tname, see above.*/
           value[strlen(value)-1]='\0';
           index=strtoul(&keyname[5], &tailptr, 10)-1;
           if(index<ncols)
-            gal_checkset_allocate_copy(&value[1], &tunit[index] );
+            gal_checkset_allocate_copy(&value[1], &up->tunit[index] );
         }
     }
 
 
   /* Check if the mandatory TFORMn values are set: */
   for(i=0;i<ncols;++i)
-    if(!tform[i])
+    if(!up->ttstr[i])
       error(EXIT_FAILURE, 0, "TFORM%d could not be found in header", i+1);
+}
+
+
 
 
-  /* For a checkup:
-  for(i=1;i<=*ncols;++i)
-    printf("%d: %s, %s, %s\n", i, tform[i], ttype[i], tunit[i]);
-  */
+
+/* Prepare column information from a text input file. Note that we are
+   currently using Gnuastro's very simple txtarray library, which was only
+   designed for a 2D array of floating point numbers. Later, we must update
+   it to be more aware of the types of input columns and also accept
+   non-number columns.*/
+void
+alltxtcolinfo(struct tableparams *p)
+{
+  size_t i;
+  size_t ncols=p->up.ncols;
+
+  /* Check if there were any strings in the array. If there were strings,
+     then warn the user that we currently can't deal with them. */
+  if(gal_checkset_check_file_report(GAL_TXTARRAY_LOG))
+    error(EXIT_FAILURE, 0, "The input text file `%s' contained "
+          "non-numerical values (probably strings). Please see `%s' for "
+          "a listing of all such terms. Currently Table cannot operate on "
+          "such files. We are working on correcting this issue.",
+          p->up.txtname, GAL_TXTARRAY_LOG);
+
+  /* Allocate the arrays to keep the input column information. */
+  allocinputcolinfo(p);
+
+  /* Set all the column types to double and leave the other fields
+     blank.*/
+  for(i=0;i<ncols;++i)
+    {
+      p->up.datatype[i]=TDOUBLE;
+      gal_checkset_allocate_copy("D", &p->up.ttstr[i] );
+      gal_checkset_allocate_copy("", &p->up.tname[i] );
+      gal_checkset_allocate_copy("", &p->up.tunit[i] );
+    }
 }
 
 
@@ -460,8 +568,11 @@ printinfo(struct tableparams *p)
   char *typestring=NULL;
   struct uiparams *up=&p->up;
 
-  printf("%s (hdu: %s)\n", p->up.fitsname, p->cp.hdu);
   printf("---------------------------------------------------------\n");
+  if(up->fitsname)
+    printf("%s (hdu: %s)\n", p->up.fitsname, p->cp.hdu);
+  else
+    printf("%s\n", p->up.txtname);
   printf("%-5s%-25s%-15s%s\n", "No.", "Column name", "Units",
          "Data type");
   printf("---------------------------------------------------------\n");
@@ -514,9 +625,9 @@ printinfo(struct tableparams *p)
         default:
           error(EXIT_FAILURE, 0, "%d (from TFORM%lu='%c') is not a "
                 "recognized CFITSIO datatype.", up->datatype[i],
-                i, up->tform[i][0]);
+                i, up->ttstr[i][0]);
         }
-      printf("%-5lu%-25s%-15s%s\n", i+1, up->ttype[i] ? up->ttype[i] : "---",
+      printf("%-5lu%-25s%-15s%s\n", i+1, up->tname[i] ? up->tname[i] : "---",
              up->tunit[i] ? up->tunit[i] : "---", typestring);
     }
 
@@ -553,38 +664,56 @@ sanitycheck(struct tableparams *p)
 {
   struct uiparams *up=&p->up;
 
-  /* Set the FITS pointer and check the type of the fits file. */
-  if(p->up.fitsname)
+  /* If the desired FITS output type is ASCII, then inform the user that
+     this type is not yet supported. */
+  if(up->fitsname && p->fitstabletype==ASCII_TBL)
+    error(EXIT_FAILURE, 0, "output to ASCII type FITS tables is currently "
+          "not supported (due to lack of need!). If you need this feature, "
+          "please get in touch with us at %s so we can increase the "
+          "priority of this feature.", PACKAGE_BUGREPORT);
+
+  if(up->fitsname)
     {
+      /* Set the FITS pointer and check the type of the fits file. */
       gal_fits_read_hdu(p->up.fitsname, p->cp.hdu, 1, &p->fitsptr);
       gal_fits_table_size(p->fitsptr, &p->nrows, &up->ncols);
-      readallcolinfo(p->fitsptr, up->ncols, &up->datatype,
-                     &up->tform, &up->ttype, &up->tunit);
+      up->infitstabletype=gal_fits_table_type(p->fitsptr);
+      allfitscolinfo(p);
     }
   else
-    error(EXIT_FAILURE, 0, "Table is a new addition to Gnuastro and "
-          "and under heavy development, it currently doesn't support "
-          "anything other than a FITS binary table.");
-
+    {
+      /* Read the text file into an input array and make the basic column
+         information. */
+      gal_txtarray_txt_to_array(up->txtname, &up->txtarray, &p->nrows,
+                                &up->ncols);
+      alltxtcolinfo(p);
+    }
 
   /* Print the column information and exit successfully if the
      `--information' option is given. */
   if(p->up.information)
     {
-      if(p->up.fitsname)
-        {
-          printinfo(p);
-          freeandreport(p);
-          exit(EXIT_SUCCESS);
-        }
-      else
-        error(EXIT_FAILURE, 0, "the `--information' (`-i') option is only "
-              "defined for FITS tables");
+      printinfo(p);
+      freeandreport(p);
+      exit(EXIT_SUCCESS);
     }
 
-  /* The user doesn't just want to see the table information, they actually
-     want to print something. So if no columns are specified, then print
-     all columns. */
+  /* Check the status of the output file. If no output file is set, then
+     the output will be printed to standard output on the terminal.*/
+  p->outputtofits=p->outputtotxt=p->outputtostdout=0;
+  if(p->cp.outputset)
+    {
+      /* First check if the file exists and remove it if it does. */
+      gal_checkset_check_remove_file(p->cp.output, p->cp.dontdelete);
+
+      /* Now set the type of output. */
+      if(gal_fits_name_is_fits(p->cp.output))
+        p->outputtofits=1;
+      else
+        p->outputtotxt=1;
+    }
+  else
+    p->outputtostdout=1;
 }
 
 
@@ -605,6 +734,7 @@ sanitycheck(struct tableparams *p)
 
 
 
+
 /**************************************************************/
 /***************       Preparations         *******************/
 /**************************************************************/
@@ -711,9 +841,9 @@ outputcolumns(struct tableparams *p)
           /* With the regex structure "compile"d you can go through all the
              column names. Just note that column names are not mandatory in
              the FITS standard, so some (or all) columns might not have
-             names, if so `p->ttype[i]' will be NULL. */
+             names, if so `p->tname[i]' will be NULL. */
           for(i=0;i<up->ncols;++i)
-            if(up->ttype[i] && regexec(regex, up->ttype[i], 0, 0, 0)==0)
+            if(up->tname[i] && regexec(regex, up->tname[i], 0, 0, 0)==0)
               gal_linkedlist_add_to_sll(&colsll, i);
 
           /* Free the regex_t structure: */
@@ -758,6 +888,9 @@ preparearrays(struct tableparams *p)
   size_t i;
   struct uiparams *up=&p->up;
 
+  /* Reverse the columns linked list here (before possibly printing).*/
+  gal_linkedlist_reverse_stll(&up->columns);
+
   /* Set the columns that should be included in the output. If up->columns
      is set, then use it, otherwise, set all the columns for printing. */
   if(p->up.columns)
@@ -816,7 +949,7 @@ setparams(int argc, char *argv[], struct tableparams *p)
   p->ocols=NULL;
   up->columns=NULL;
   up->txtname=up->fitsname=NULL;
-  up->tform=up->ttype=up->tunit=NULL;
+  up->ttstr=up->tname=up->tunit=NULL;
 
   /* Read the arguments. */
   errno=0;
@@ -829,9 +962,6 @@ setparams(int argc, char *argv[], struct tableparams *p)
   /* Check if all the required parameters are set. */
   checkifset(p);
 
-  /* Reverse the columns linked list here (before possibly printing).*/
-  gal_linkedlist_reverse_stll(&up->columns);
-
   /* Print the values for each parameter. */
   if(cp->printparams)
     GAL_CONFIGFILES_REPORT_PARAMETERS_SET;
@@ -882,17 +1012,18 @@ freeandreport(struct tableparams *p)
   /* Free the input column information: */
   for(i=0;i<up->ncols;++i)
     {
-      if(up->tform) free(up->tform[i]);
-      if(up->ttype) free(up->ttype[i]);
+      if(up->ttstr) free(up->ttstr[i]);
+      if(up->tname) free(up->tname[i]);
       if(up->tunit) free(up->tunit[i]);
     }
-  free(up->tform);
-  free(up->ttype);
+  free(up->ttstr);
+  free(up->tname);
   free(up->tunit);
 
   /* Free the output column information: */
   for(i=0;i<p->nocols;++i)
     {
+      free(p->ocols[i].nulval);
       if(p->ocols[i].datatype==TSTRING)
         {
           rowofstrings=(char **)(p->ocols[i].data);
diff --git a/src/table/ui.h b/src/table/ui.h
index 76c304e..1b949be 100644
--- a/src/table/ui.h
+++ b/src/table/ui.h
@@ -24,7 +24,11 @@ along with Gnuastro. If not, see 
<http://www.gnu.org/licenses/>.
 #define UI_H
 
 void
-checkfge(char *optarg, int *fge);
+checksetfge(char *optarg, int *fge, char *filename, size_t lineno);
+
+void
+checksetfitstabletype(char *optarg, int *fitstabletype, char *filename,
+                   size_t lineno);
 
 void
 setparams(int argc, char *argv[], struct tableparams *p);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f9810ab..7008c4b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -42,12 +42,12 @@ mkprof/ellipticalmasks.sh mkprof/inputascanvas.sh 
header/write.sh           \
 header/print.sh header/update.sh header/delete.sh imgstat/basicstats.sh     \
 subtractsky/subtractsky.sh noisechisel/noisechisel.sh mkcatalog/simple.sh   \
 mkcatalog/aperturephot.sh arithmetic/snimage.sh arithmetic/onlynumbers.sh   \
-cosmiccal/simpletest.sh
+cosmiccal/simpletest.sh table/asciitobinary.sh table/binarytoascii.sh
 
 EXTRA_DIST = $(TESTS) during-dev.sh mkprof/mkprofcat1.txt                  \
 mkprof/ellipticalmasks.txt mkprof/inputascanvas.txt mkprof/mkprofcat2.txt  \
 mkprof/mkprofcat3.txt mkprof/mkprofcat4.txt mkprof/radeccat.txt            \
-imgcrop/cat.txt
+imgcrop/cat.txt table/asciitobinary.txt
 
 CLEANFILES = *.log *.txt *.jpg *.fits *.pdf *.eps
 
@@ -78,6 +78,8 @@ mkprof/mosaic2.sh: prepconf.sh.log
 mkprof/mosaic3.sh: prepconf.sh.log
 mkprof/mosaic4.sh: prepconf.sh.log
 mkprof/radeccat.sh: prepconf.sh.log
+table/asciitobinary.sh: prepconf.sh.log
+table/binarytoascii.sh: table/asciitobinary.sh.log
 imgcrop/imgcat.sh: mkprof/mosaic1.sh.log
 imgcrop/wcscat.sh: mkprof/mosaic1.sh.log mkprof/mosaic2.sh.log     \
                    mkprof/mosaic3.sh.log mkprof/mosaic4.sh.log
diff --git a/tests/during-dev.sh b/tests/during-dev.sh
index 410e3ac..61065b1 100755
--- a/tests/during-dev.sh
+++ b/tests/during-dev.sh
@@ -139,7 +139,7 @@ if make -C "$builddir"; then
     # onlydirconf option. We are first printing an empty line just in case
     # the last line in the configuration file doesn't actualy end with a
     # new line (in which case the appended string will be added to the end
-    # of the last line.
+    # of the last line).
     cp "$srcdir/src/$utilname/ast$utilname.conf" .gnuastro/
     echo ""               >> .gnuastro/ast$utilname.conf
     echo " onlydirconf 1" >> .gnuastro/ast$utilname.conf
diff --git a/tests/prepconf.sh b/tests/prepconf.sh
index 437ec72..068c06b 100755
--- a/tests/prepconf.sh
+++ b/tests/prepconf.sh
@@ -76,7 +76,7 @@ EOF
 # by `make check'.
 for prog in arithmetic convertt convolve cosmiccal header imgcrop \
             imgstat imgwarp mkcatalog mknoise mkprof noisechisel  \
-            subtractsky
+            subtractsky table
 do
 
     # Copy the configuration file from the utility source and add the
diff --git a/tests/table/asciitobinary.sh b/tests/table/asciitobinary.sh
new file mode 100755
index 0000000..42ae47b
--- /dev/null
+++ b/tests/table/asciitobinary.sh
@@ -0,0 +1,51 @@
+# Convert an ASCII table to a binary table
+#
+# See the Tests subsection of the manual for a complete explanation
+# (in the Installing gnuastro section).
+#
+# Original author:
+#     Mohammad Akhlaghi <address@hidden>
+# Contributing author(s):
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.  This file is offered as-is,
+# without any warranty.
+
+
+
+
+
+# Preliminaries
+# =============
+#
+# Set the variabels (The executable is in the build tree). Do the
+# basic checks to see if the executable is made or if the defaults
+# file exists (basicchecks.sh is in the source tree).
+prog=table
+execname=../src/$prog/ast$prog
+table=$topsrc/tests/$prog/asciitobinary.txt
+
+
+
+
+
+# Skip?
+# =====
+#
+# If the dependencies of the test don't exist, then skip it. There are two
+# types of dependencies:
+#
+#   - The executable was not made (for example due to a configure option),
+#
+#   - The input data was not made (for example the test that created the
+#     data file failed).
+if [ ! -f $execname ] || [ ! -f $img ]; then exit 77; fi
+
+
+
+
+
+# Actual test script
+# ==================
+$execname $table --output=asciitobinary.fits
diff --git a/tests/table/asciitobinary.txt b/tests/table/asciitobinary.txt
new file mode 100644
index 0000000..c4533a0
--- /dev/null
+++ b/tests/table/asciitobinary.txt
@@ -0,0 +1,2 @@
+1 2.323 43.34
+2 3213  1232
diff --git a/tests/table/binarytoascii.sh b/tests/table/binarytoascii.sh
new file mode 100755
index 0000000..5eb8cc0
--- /dev/null
+++ b/tests/table/binarytoascii.sh
@@ -0,0 +1,51 @@
+# Convert an ASCII table to a binary table
+#
+# See the Tests subsection of the manual for a complete explanation
+# (in the Installing gnuastro section).
+#
+# Original author:
+#     Mohammad Akhlaghi <address@hidden>
+# Contributing author(s):
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.  This file is offered as-is,
+# without any warranty.
+
+
+
+
+
+# Preliminaries
+# =============
+#
+# Set the variabels (The executable is in the build tree). Do the
+# basic checks to see if the executable is made or if the defaults
+# file exists (basicchecks.sh is in the source tree).
+prog=table
+execname=../src/$prog/ast$prog
+table=asciitobinary.fits
+
+
+
+
+
+# Skip?
+# =====
+#
+# If the dependencies of the test don't exist, then skip it. There are two
+# types of dependencies:
+#
+#   - The executable was not made (for example due to a configure option),
+#
+#   - The input data was not made (for example the test that created the
+#     data file failed).
+if [ ! -f $execname ] || [ ! -f $img ]; then exit 77; fi
+
+
+
+
+
+# Actual test script
+# ==================
+$execname $table --output=binarytoascii.txt -h1



reply via email to

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