[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 1acc441: Library (txt.c): no error when sexage
[gnuastro-commits] master 1acc441: Library (txt.c): no error when sexagesimal used for column info
Sun, 24 Oct 2021 16:42:59 -0400 (EDT)
Author: Mohammad Akhlaghi <firstname.lastname@example.org>
Commit: Mohammad Akhlaghi <email@example.com>
Library (txt.c): no error when sexagesimal used for column info
Until now, when a plain-text table with no metadata contained sexagesimal
values in the first row (that is used to extract metadata for the rest of
the rows), Table would crash with an error saying that the sexagesimal
number couldn't be interpretted as a number! As a result a basic command
like below (which is even in the "Invoking asttable" section of the book),
echo "7h34m35.5498 31d53m14.352s" | asttable
This had happened because of a recent change in the plain-text reading
library that was added to make sure that the first un-commented line of a
file without metadata actually has numbers in it (bug #60999).
With this commit, that part of the code has been corrected to also check
for sexagesimal inputs, not just raw numbers. Also, to make sure that this
situation is tested every time, the command above has been added to the
'make check' tests.
This fixes bug #61378.
NEWS | 1 +
lib/txt.c | 15 +++++++----
tests/Makefile.am | 3 ++-
tests/table/sexagesimal-to-deg.sh | 56 +++++++++++++++++++++++++++++++++++++++
4 files changed, 69 insertions(+), 6 deletions(-)
diff --git a/NEWS b/NEWS
index e8d604e..a219776 100644
@@ -24,6 +24,7 @@ See the end of the file for license conditions.
** Bugs fixed
bug #61329: make check crash in macOS in convolve/spectrum-1d.sh, found
and fixed with the help of Sebastian Luna-Valero.
+ bug #61378: Table crash when input is sexagesimal RA/DEC and no metadata.
diff --git a/lib/txt.c b/lib/txt.c
index 8f4b706..4ad22ae 100644
@@ -411,12 +411,17 @@ txt_info_from_first_row(char *in_line, gal_data_t
**datall, int format,
if( *datall==NULL || format==TXT_FORMAT_TABLE )
- /* Make sure the token is actually a number and print a good
- error message when the input isn't actually a number but a
- string (like uncommented metadata).*/
- if( gal_type_from_string( &tmpdptr, token, GAL_TYPE_FLOAT64) )
+ /* Make sure the token is actually a number (or RA/Dec
+ written in Sexagesimal format) and print a good error
+ message when the input isn't actually a number but a
+ string (this test was added because of uncommented
+ metadata)! */
+ if( gal_type_from_string( &tmpdptr, token, GAL_TYPE_FLOAT64)
+ && isnan( gal_units_ra_to_degree(token) )
+ && isnan( gal_units_dec_to_degree(token) ) )
error(EXIT_FAILURE, 0, "'%s' couldn't be read as a number "
- "(element %zu of first uncommented line)", token, n);
+ "(element %zu of first uncommented line) %f ", token, n,
/* Allocate this column's dataset and set it's 'status' to
the column number that it corresponds to. */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 261cda7..31182ff 100644
@@ -187,12 +187,13 @@ endif
MAYBE_TABLE_TESTS = table/txt-to-fits-binary.sh \
table/fits-binary-to-txt.sh table/txt-to-fits-ascii.sh \
+ table/fits-ascii-to-txt.sh table/sexagesimal-to-deg.sh
+ table/sexagesimal-to-deg.sh: prepconf.sh.log
MAYBE_WARP_TESTS = warp/warp_scale.sh warp/homographic.sh
diff --git a/tests/table/sexagesimal-to-deg.sh
new file mode 100755
@@ -0,0 +1,56 @@
+# Convert sexagesimal coordinates to degrees, while also reading input from
+# a pipe.
+# See the Tests subsection of the manual for a complete explanation
+# (in the Installing gnuastro section).
+# Original author:
+# Mohammad Akhlaghi <firstname.lastname@example.org>
+# Contributing author(s):
+# Copyright (C) 2021, Free Software Foundation, Inc.
+# 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.
+# Set the variables (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).
+# 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 ]; then echo "$execname not created."; exit 77; fi
+# Actual test script
+# 'check_with_program' can be something like 'Valgrind' or an empty
+# string. Such programs will execute the command if present and help in
+# debugging when the developer doesn't have access to the user's system.
+echo "7h34m35.5498 31d53m14.352s" | $check_with_program $execname
|[Prev in Thread]
||[Next in Thread]|
- [gnuastro-commits] master 1acc441: Library (txt.c): no error when sexagesimal used for column info,
Mohammad Akhlaghi <=