[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master ad2810d 029/125: Work started on getting text
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master ad2810d 029/125: Work started on getting text table information |
Date: |
Sun, 23 Apr 2017 22:36:30 -0400 (EDT) |
branch: master
commit ad2810dab6a7ea72afeff473afec194ec9795481
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
Work started on getting text table information
`gal_txt_table_info' is in charge of reading the table information from a
plain text file. Work has started on doing the job, with this commit, it
will open the file, and identify the comment, non-comment, and blank lines.
---
bin/table/ui.c | 8 +++--
bootstrap.conf | 1 +
lib/txt.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 99 insertions(+), 6 deletions(-)
diff --git a/bin/table/ui.c b/bin/table/ui.c
index c3f8c29..1ecc510 100644
--- a/bin/table/ui.c
+++ b/bin/table/ui.c
@@ -322,10 +322,12 @@ sanitycheck(struct tableparams *p)
else
{
if( gal_fits_name_is_fits(p->cp.output)
- && p->outtabletype==GAL_TABLE_TYPE_TXT)
+ && ( p->outtabletype !=GAL_TABLE_TYPE_AFITS
+ && p->outtabletype !=GAL_TABLE_TYPE_BFITS ) )
error(EXIT_FAILURE, 0, "desired output table is a FITS file, but "
- "`outtabletype' is not a FITS table type. Please set it to "
- "`fits-ascii', or `fits-binary'");
+ "`outtabletype' is not %s. Please set it to "
+ "`fits-ascii', or `fits-binary'",
+ up->outtabletypeset ? "a FITS table type" : "set");
}
}
diff --git a/bootstrap.conf b/bootstrap.conf
index 0409677..a9c3d30 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -164,6 +164,7 @@ gnulib_modules="
regex
error
nproc
+ getline
strcase
gendocs
git-version-gen
diff --git a/lib/txt.c b/lib/txt.c
index 7272238..f784c9f 100644
--- a/lib/txt.c
+++ b/lib/txt.c
@@ -35,13 +35,103 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
#include <checkset.h>
-/************************************************************************/
-/*************** Information about a txt table ***************/
-/************************************************************************/
+
+
+
+/* Status of a line: */
+enum txt_line_stat
+{
+ TXT_LINESTAT_BLANK,
+ TXT_LINESTAT_ISCOMMENT,
+ TXT_LINESTAT_NOTCOMMENT,
+};
+
+
+
+
+
+/* Return one of the `txt_line_stat' constant values. */
+int
+get_line_stat(char *line)
+{
+ while(*line!='\n')
+ {
+ switch(*line)
+ {
+ /* Characters to ignore. */
+ case ' ': case ',': case '\t':
+ break;
+ case '#':
+ return TXT_LINESTAT_ISCOMMENT;
+ default:
+ return TXT_LINESTAT_NOTCOMMENT;
+ }
+ ++line;
+ }
+ return TXT_LINESTAT_BLANK;
+}
+
+
+
+
+
+/* Return the information about a text file table. */
gal_data_t *
gal_txt_table_info(char *filename, size_t *numcols)
{
+ FILE *fp;
+ char *line;
+ size_t linelen=10; /* This will be increased later by `getline'. */
+
+ /* Open the file. */
+ errno=0;
+ fp=fopen(filename, "r");
+ if(fp==NULL)
+ error(EXIT_FAILURE, errno, "%s: could't open to read as a text table",
+ filename);
+
+ /* Get the maximum line length and allocate the space necessary to keep
+ copies of all lines as we parse them. Note that `getline' is going to
+ put the string NULL character also, so we need one more character. */
+ errno=0;
+ line=malloc(linelen*sizeof *line);
+ if(line==NULL)
+ error(EXIT_FAILURE, errno, "%zu bytes for line in `gal_txt_table_info'",
+ linelen*sizeof *line);
+
+ /* Read the comments of the line for possible information about the
+ lines, but also confirm the info by trying to read the first
+ uncommented line. */
+ while( getline(&line, &linelen, fp) != -1 )
+ switch(get_line_stat(line))
+ {
+ case TXT_LINESTAT_BLANK:
+ printf("blank\n");
+ break;
+
+ case TXT_LINESTAT_ISCOMMENT:
+ printf("comment\n");
+ break;
+
+ case TXT_LINESTAT_NOTCOMMENT:
+ printf("not comment\n");
+ break;
+
+ default:
+ error(EXIT_FAILURE, 0, "linestatus code %d not recognized in "
+ "`gal_txt_table_info'",
+ linestat);
+ }
+
+ /* Clean up, close the file and return. */
+ free(line);
+ errno=0;
+ if(fclose(fp))
+ error(EXIT_FAILURE, errno, "%s: couldn't close file after reading ASCII "
+ "table information", filename);
+ printf("\n----end of tableinfo----\n");
+ exit(0);
return NULL;
}
- [gnuastro-commits] master 1ea9ea2 009/125: Data structure mmap information updated, (continued)
- [gnuastro-commits] master 1ea9ea2 009/125: Data structure mmap information updated, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 531c263 008/125: Operators treated as macros, not string, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master ff9258a 006/125: Arithmetic with internal type conversion, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 5336d5c 024/125: Small but important corrections, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c2fcb3e 020/125: Absolute value operator in gal_data_arithmetic, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master fdb6183 019/125: Where operator implemented in gal_data_arithmetic, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 493bc6f 001/125: Defined new gnuastro/data.h header, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c6462d1 016/125: Type conversion operators in Arithmetic, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c10c4be 002/125: Moved type code and alloc functions into data.h, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master a4c5b9d 012/125: Binary operator arithmetic works on uncompiled types, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master ad2810d 029/125: Work started on getting text table information,
Mohammad Akhlaghi <=
- [gnuastro-commits] master bc57ade 021/125: Minimum and maximum value operators implemented, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 2dea9a7 011/125: All binary operator types set at configure time, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master ff0b76d 018/125: New Data types section in book, bitwise not added, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master c62b01e 031/125: Corrected incrementation issue with and and or operators, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 0a32a82 027/125: Any number of searched columns from FITS are read, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master d0aa78e 005/125: Arithmetic operation on data structures in library, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 0ad0906 014/125: Bitwise operators available in arithmetic operations, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 3ad83a4 010/125: data-arithmetic and data-copy separated from data.c, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master 6c6382a 013/125: Use of function instead of macros for binary operators, Mohammad Akhlaghi, 2017/04/23
- [gnuastro-commits] master ce73959 030/125: Reading FITS keywords into linked list not array, Mohammad Akhlaghi, 2017/04/23