[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master cc2055d 1/2: Reading blank value in plain text
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master cc2055d 1/2: Reading blank value in plain text table corrected |
Date: |
Thu, 18 May 2017 11:52:08 -0400 (EDT) |
branch: master
commit cc2055d423ee00bddb91470810a4fd558ac2bcc5
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
Reading blank value in plain text table corrected
We were mistakenly writing the blank value provided by the comment lines in
Gnuastro's plain text table format into a copy of where it should have been
stored, not the actual dataset pointer (in
`gal_tableintern_col_print_info'). This has been corrected in this
commit.
Also, in the same function, the direct call to `malloc' has been changed to
`gal_data_malloc_array' for more clarity. Finally, the spacings in
`txt_info_from_comment' between components were homogenized to two spaces
for easier readability (similar to the other parts).
---
lib/tableintern.c | 10 ++--------
lib/txt.c | 8 +++++++-
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/lib/tableintern.c b/lib/tableintern.c
index f7c0590..15d4c38 100644
--- a/lib/tableintern.c
+++ b/lib/tableintern.c
@@ -408,8 +408,6 @@ gal_tableintern_col_print_info(gal_data_t *col, int
tableformat,
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. */
@@ -424,13 +422,9 @@ gal_tableintern_read_blank(gal_data_t *col, char *blank)
`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) )
+ if( !gal_type_from_string((void **)(&col->array), 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=gal_data_malloc_array(GAL_TYPE_SIZE_T, 1);
col->dsize[0]=col->ndim=col->size=1;
}
}
diff --git a/lib/txt.c b/lib/txt.c
index dcc174c..67dcd03 100644
--- a/lib/txt.c
+++ b/lib/txt.c
@@ -191,6 +191,7 @@ txt_info_from_comment(char *line, gal_data_t **datall, char
*comm_start)
++line;
}
+
/* Read the column number as an integer. If it can't be read as an
integer, or is zero or negative then just return without adding
anything to this line. */
@@ -198,7 +199,6 @@ txt_info_from_comment(char *line, gal_data_t **datall, char
*comm_start)
if(*tailptr!='\0' || index<=0) return;
-
/* If there was no name (the line is just `# Column N:'), then ignore
the line. Relying on the column count from the first line is more
robust and less prone to human error, for example typing a number
@@ -206,11 +206,13 @@ txt_info_from_comment(char *line, gal_data_t **datall,
char *comm_start)
name=txt_trim_space(name);
if(name==NULL) return;
+
/* If this is a repeated index, ignore it. */
for(tmp=*datall; tmp!=NULL; tmp=tmp->next)
if(tmp->status==index)
return;
+
/* If there were brackets, then break it up. */
if(inbrackets)
{
@@ -227,6 +229,7 @@ txt_info_from_comment(char *line, gal_data_t **datall, char
*comm_start)
}
}
+
/* If `typestr' was given, then check if this is a standard type. If
`typestr' wasn't specified, then the default double type code will
be used (see the variable definitions above). If the given type
@@ -250,6 +253,7 @@ txt_info_from_comment(char *line, gal_data_t **datall, char
*comm_start)
}
}
+
/* Add this column's information into the columns linked list. We
will define the data structur's array to have zero dimensions (no
array) by default. If there is a blank value its value will be put
@@ -259,12 +263,14 @@ txt_info_from_comment(char *line, gal_data_t **datall,
char *comm_start)
gal_list_data_add_alloc(datall, NULL, type, 0, NULL, NULL, 0, -1, name,
txt_trim_space(unit), txt_trim_space(comment) );
+
/* Put the number of this column into the status variable of the data
structure. If the type is string, then also copy the width into
the structure. */
(*datall)->status=index;
(*datall)->disp_width = type==GAL_TYPE_STRING ? strw : 0;
+
/* Write the blank value into the array. Note that this is not the
final column, we are just collecting information now. */
gal_tableintern_read_blank(*datall, txt_trim_space(blank));