[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 725daa8 2/2: Arithmetic only reads the headers
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 725daa8 2/2: Arithmetic only reads the headers when necessary |
Date: |
Fri, 6 Apr 2018 11:12:00 -0400 (EDT) |
branch: master
commit 725daa87569c8913321b279c9802d89d249a9e0c
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
Arithmetic only reads the headers when necessary
Some file formats (like JPEG) don't need any headers. Therefore Arithmetic
will not attempt to assign them a HDU and will instead pass a NULL pointer
to their HDU element (as it should be).
Also, I found out that the `addcounter' element in Arithmetic's main
structure was extra and no longer used. So it was removed.
---
bin/arithmetic/arithmetic.c | 8 ++++----
bin/arithmetic/main.h | 1 -
bin/arithmetic/operands.c | 10 ++++++----
doc/gnuastro.texi | 5 +++++
lib/array.c | 46 +++++++++++++++++++++++++++++++++++++--------
lib/gnuastro/array.h | 3 +++
6 files changed, 56 insertions(+), 17 deletions(-)
diff --git a/bin/arithmetic/arithmetic.c b/bin/arithmetic/arithmetic.c
index 54729e2..c8b25af 100644
--- a/bin/arithmetic/arithmetic.c
+++ b/bin/arithmetic/arithmetic.c
@@ -597,7 +597,7 @@ reversepolish(struct arithmeticparams *p)
/* Prepare the processing: */
p->operands=NULL;
- p->addcounter=p->popcounter=0;
+ p->popcounter=0;
/* Go over each input token and do the work. */
@@ -606,7 +606,7 @@ reversepolish(struct arithmeticparams *p)
/* If we have a name or number, then add it to the operands linked
list. Otherwise, pull out two members and do the specified
operation on them. */
- if(gal_fits_name_is_fits(token->v))
+ if(gal_array_name_recognized(token->v))
operands_add(p, token->v, NULL);
else if( (d1=gal_data_copy_string_to_number(token->v)) )
operands_add(p, NULL, d1);
@@ -744,8 +744,8 @@ reversepolish(struct arithmeticparams *p)
/* Finished checks with known operators */
else
error(EXIT_FAILURE, 0, "the argument \"%s\" could not be "
- "interpretted as a FITS file, number, or operator",
- token->v);
+ "interpretted as a recognized input file name, number, or "
+ "operator", token->v);
/* See if the arithmetic library must be called or not. */
diff --git a/bin/arithmetic/main.h b/bin/arithmetic/main.h
index 29c2515..c0c2a1d 100644
--- a/bin/arithmetic/main.h
+++ b/bin/arithmetic/main.h
@@ -70,7 +70,6 @@ struct arithmeticparams
/* Input: */
gal_list_str_t *hdus; /* List of all given HDU strings. */
gal_list_str_t *tokens; /* List of all arithmetic tokens. */
- size_t addcounter; /* The number of FITS images added. */
size_t popcounter; /* The number of FITS images popped. */
gal_data_t refdata; /* Container for information of the data. */
char *globalhdu; /* Single HDU for all inputs. */
diff --git a/bin/arithmetic/operands.c b/bin/arithmetic/operands.c
index bab5625..48d3632 100644
--- a/bin/arithmetic/operands.c
+++ b/bin/arithmetic/operands.c
@@ -31,6 +31,7 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
#include <gnuastro/wcs.h>
#include <gnuastro/fits.h>
+#include <gnuastro/tiff.h>
#include <gnuastro/array.h>
#include <gnuastro-internal/checkset.h>
@@ -78,17 +79,18 @@ operands_add(struct arithmeticparams *p, char *filename,
gal_data_t *data)
newnode->data=data;
newnode->filename=filename;
- if(filename != NULL && gal_fits_name_is_fits(filename))
+ /* See if a HDU must be read or not. */
+ if(filename != NULL
+ && ( gal_fits_name_is_fits(filename)
+ || gal_tiff_name_is_tiff(filename) ) )
{
/* Set the HDU for this filename. */
if(p->globalhdu)
gal_checkset_allocate_copy(p->globalhdu, &newnode->hdu);
else
newnode->hdu=gal_list_str_pop(&p->hdus);
-
- /* Increment the FITS counter. */
- ++p->addcounter;
}
+ else newnode->hdu=NULL;
/* Make the link to the previous list. */
newnode->next=p->operands;
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index f5b11f7..848625a 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -21977,6 +21977,11 @@ library, for example @ref{FITS files} or @ref{TIFF
files}. If the file type
of the input/output file is already known, you can use the functions in
those sections respectively.
address@hidden int gal_array_name_recognized (char @code{*filename})
+Return 1 if the given file name corresponds to one of the recognized file
+types for reading arrays.
address@hidden deftypefun
+
@deftypefun gal_data_t gal_array_read (char @code{*filename}, char
@code{*extension}, size_t @code{minmapsize})
Read the array within the given extension (@code{extension}) of
@code{filename}. If the array is larger than @code{minmapsize} bytes, then
diff --git a/lib/array.c b/lib/array.c
index 62965bc..0aa708e 100644
--- a/lib/array.c
+++ b/lib/array.c
@@ -45,6 +45,26 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
/*********************************************************************/
/***************** High-level functions ****************/
/*********************************************************************/
+int
+gal_array_name_recognized(char *name)
+{
+ if( gal_fits_name_is_fits(name) ) return 1;
+ else if ( gal_tiff_name_is_tiff(name) ) return 1;
+ else if ( gal_jpeg_name_is_jpeg(name) ) return 1;
+ else return 0;
+
+ /* Control should not get to here, but just to avoid compiler warnings,
+ we'll return a NULL. */
+ error(EXIT_FAILURE, 0, "%s: a bug! Please contact us at %s to solve the "
+ "problem. Control must not reach the end of this function", __func__,
+ PACKAGE_BUGREPORT);
+ return 0;
+}
+
+
+
+
+
/* Read (all the possibly existing) color channels within each
extension/dir of the given file. */
gal_data_t *
@@ -113,18 +133,28 @@ gal_array_read_to_type(char *filename, char *extension,
uint8_t type,
gal_data_t *
gal_array_read_one_ch(char *filename, char *extension, size_t minmapsize)
{
+ char *fname;
gal_data_t *out;
out=gal_array_read(filename, extension, minmapsize);
if(out->next)
- error(EXIT_FAILURE, 0, "%s (hdu %s): contains %zu channels (it isn't "
- "monochrome).\n\n"
- "You can use Gnuastro's ConvertType program to separate the "
- "(color) channels into separate extensions of a FITS file, with "
- "a command like this:\n\n"
- " $ astconvertt %s -h%s --output=sep-ch.fits",
- filename, extension, gal_list_data_number(out), filename,
- extension);
+ {
+ if(extension)
+ {
+ if( asprintf(&fname, "%s (hdu %s)", filename, extension)<0 )
+ error(EXIT_FAILURE, 0, "%s: asprintf allocation error", __func__);
+ }
+ else
+ fname=filename;
+
+ error(EXIT_FAILURE, 0, "%s: contains %zu channels (it isn't "
+ "monochrome).\n\n"
+ "You can use Gnuastro's ConvertType program to separate the "
+ "(color) channels into separate extensions of a FITS file, with "
+ "a command like this:\n\n"
+ " $ astconvertt %s -h%s --output=sep-ch.fits",
+ fname, gal_list_data_number(out), filename, extension);
+ }
return out;
}
diff --git a/lib/gnuastro/array.h b/lib/gnuastro/array.h
index 91a102c..aaff1fd 100644
--- a/lib/gnuastro/array.h
+++ b/lib/gnuastro/array.h
@@ -52,6 +52,9 @@ __BEGIN_C_DECLS /* From C++ preparations */
/* Functions */
+int
+gal_array_name_recognized(char *name);
+
gal_data_t *
gal_array_read(char *filename, char *extension, size_t minmapsize);