[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] (no subject)
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] (no subject) |
Date: |
Sun, 29 May 2016 11:47:50 +0000 (UTC) |
branch: master
commit c63305c10f47e27886ae058fbca48ab00445f90c
Merge: c011627 4d75eda
Author: Mohammad Akhlaghi <address@hidden>
Date: Sun May 29 15:23:26 2016 +0900
Library naming convention merged into master
The Library naming convention that was defined as part of task #13765 and
implemented by Mosè Giordano in a separate branch has now been merged into
master. All the work that was subsequently added to Gnuastro was thus
modified to fit this naming convention.
doc/gnuastro.texi | 35 ++++
include/arraymanip.h | 68 +++----
include/astrthreads.h | 14 +-
include/box.h | 14 +-
include/checkset.h | 106 +++++-----
include/commonargs.h | 18 +-
include/commonparams.h | 6 +-
include/configfiles.h | 74 +++----
include/fitsarrayvv.h | 147 +++++++-------
include/fixedstringmacros.h | 92 +++++----
include/forqsort.h | 20 +-
include/linkedlist.h | 123 ++++++------
include/mesh.h | 50 ++---
include/mode.h | 36 ++--
include/neighbors.h | 14 +-
include/polygon.h | 46 ++---
include/spatialconvolve.h | 21 +-
include/statistics.h | 135 +++++++------
include/timing.h | 16 +-
include/txtarrayvv.h | 19 +-
lib/arraymanip.c | 67 +++----
lib/astrthreads.c | 8 +-
lib/box.c | 10 +-
lib/checkset.c | 127 ++++++------
lib/configfiles.c | 15 +-
lib/fitsarrayvv.c | 421 ++++++++++++++++++++++------------------
lib/forqsort.c | 20 +-
lib/linkedlist.c | 193 +++++++++---------
lib/mesh.c | 248 +++++++++++------------
lib/mode.c | 89 +++++----
lib/polygon.c | 66 ++++---
lib/spatialconvolve.c | 45 +++--
lib/statistics.c | 230 +++++++++++-----------
lib/timing.c | 9 +-
lib/txtarrayvv.c | 37 ++--
src/arithmetic/args.h | 17 +-
src/arithmetic/arithmetic.c | 84 ++++----
src/arithmetic/cite.h | 10 +-
src/arithmetic/main.h | 8 +-
src/arithmetic/ui.c | 65 ++++---
src/convertt/args.h | 33 ++--
src/convertt/cite.h | 6 +-
src/convertt/convertt.c | 21 +-
src/convertt/eps.c | 8 +-
src/convertt/main.h | 6 +-
src/convertt/ui.c | 125 ++++++------
src/convolve/args.h | 29 +--
src/convolve/cite.h | 6 +-
src/convolve/convolve.c | 81 ++++----
src/convolve/main.h | 4 +-
src/convolve/ui.c | 157 ++++++++-------
src/cosmiccal/args.h | 20 +-
src/cosmiccal/cite.h | 6 +-
src/cosmiccal/main.h | 2 +-
src/cosmiccal/ui.c | 58 +++---
src/header/args.h | 18 +-
src/header/cite.h | 4 +-
src/header/header.c | 25 +--
src/header/main.h | 22 +--
src/header/ui.c | 45 ++---
src/imgcrop/args.h | 45 +++--
src/imgcrop/cite.h | 4 +-
src/imgcrop/crop.c | 105 +++++-----
src/imgcrop/imgcrop.c | 46 ++---
src/imgcrop/main.h | 6 +-
src/imgcrop/ui.c | 105 +++++-----
src/imgcrop/wcsmode.c | 4 +-
src/imgstat/args.h | 53 ++---
src/imgstat/cite.h | 6 +-
src/imgstat/imgstat.c | 65 ++++---
src/imgstat/main.h | 4 +-
src/imgstat/ui.c | 186 +++++++++---------
src/imgwarp/args.h | 17 +-
src/imgwarp/cite.h | 6 +-
src/imgwarp/imgwarp.c | 52 ++---
src/imgwarp/main.h | 2 +-
src/imgwarp/ui.c | 79 ++++----
src/mkcatalog/args.h | 57 +++---
src/mkcatalog/cite.h | 6 +-
src/mkcatalog/columns.c | 5 +-
src/mkcatalog/main.h | 4 +-
src/mkcatalog/mkcatalog.c | 21 +-
src/mkcatalog/ui.c | 315 +++++++++++++++++-------------
src/mknoise/args.h | 17 +-
src/mknoise/cite.h | 6 +-
src/mknoise/main.h | 4 +-
src/mknoise/mknoise.c | 41 ++--
src/mknoise/ui.c | 77 ++++----
src/mkprof/args.h | 77 +++++---
src/mkprof/cite.h | 4 +-
src/mkprof/main.h | 2 +-
src/mkprof/mkprof.c | 79 ++++----
src/mkprof/oneprofile.c | 32 +--
src/mkprof/ui.c | 223 +++++++++++----------
src/noisechisel/args.h | 111 ++++++-----
src/noisechisel/binary.c | 17 +-
src/noisechisel/binary.h | 2 +-
src/noisechisel/cite.h | 6 +-
src/noisechisel/clumps.c | 37 ++--
src/noisechisel/detection.c | 111 ++++++-----
src/noisechisel/label.c | 11 +-
src/noisechisel/label.h | 6 +-
src/noisechisel/main.h | 8 +-
src/noisechisel/noisechisel.c | 135 +++++++------
src/noisechisel/segmentation.c | 56 +++---
src/noisechisel/sky.c | 51 ++---
src/noisechisel/thresh.c | 66 ++++---
src/noisechisel/ui.c | 375 ++++++++++++++++++-----------------
src/subtractsky/args.h | 48 +++--
src/subtractsky/cite.h | 4 +-
src/subtractsky/main.h | 6 +-
src/subtractsky/subtractsky.c | 87 +++++----
src/subtractsky/ui.c | 168 ++++++++--------
113 files changed, 3507 insertions(+), 3052 deletions(-)
diff --cc doc/gnuastro.texi
index 7405e97,b37708f..9417204
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@@ -14151,6 -12251,6 +14151,39 @@@ As much as order does not matter when y
group, sort them by length, see above.
@item
++Regarding naming of exported header files, functions, variables, macros,
++and library functions, we adopted similar conventions to those used by the
++GNU Scientific
address@hidden@url{https://www.gnu.org/software/gsl/design/gsl-design.html#SEC15}}.
++In particular, in order to avoid clashes with the names of functions and
++variables coming from other libraries we decided to use the namespace
address@hidden, which stands for @emph{G}NU @emph{A}stronomy @emph{L}ibrary.
++
address@hidden
address@hidden
++All exported header files should have a filename with the prefix @code{gal_}.
++
address@hidden
++All function names, variables, etc should be in lower case. Macros and
++preprocessor variables should be in upper case.
++
address@hidden
address@hidden GNU coding standards
++For all exported functions and variables use the base name of the file in
++which they are defined as prefix, followed by the rest of the name, using
++underscores to separate address@hidden convention to use underscores to
++separate words, called ``snake case'' (or ``snake_case''). This is also
++recommended by the GNU coding standards.}. The same applies to exported
++macros, but in upper case. For example, the prototype of function
address@hidden is in @code{gal_box.h}, and the macro
address@hidden is defined in @code{gal_polygon.h}. This
++facilitates looking up their definitions.
++
address@hidden
++All installed libraries should have a name like @code{libgalbox.a}.
address@hidden itemize
++
address@hidden
@cindex GNU Emacs
@cindex Trailing space
There should be no trailing white space in a line. To do this
@@@ -14186,65 -12286,38 +14219,67 @@@ very important for easily understandin
@end itemize
-Regarding naming of exported header files, functions, variables, macros,
-and installed libraries, we adopted similar conventions to those used by
-the GSL
address@hidden@url{https://www.gnu.org/software/gsl/design/gsl-design.html#SEC15}}.
-In particular, in order to avoid clashes with the names of functions and
-variables coming from other libraries we decided to use the namespace
address@hidden, which stands for @emph{G}NU @emph{A}stronomy @emph{L}ibrary.
address@hidden
address@hidden
-All exported header files should have a filename with the prefix @code{gal_}.
+
address@hidden
-All function names, variables, etc should be in lower case. Macros and
-preprocessor variables should be in upper case.
+The last two conventions are not common and might benefit from a short
+discussion here. With a good experience in advanced text editor
+operations, to some extent the last two are redundant for a
+professional developer. However, recall that Gnuastro aspires to be
+friendly to un-familiar, and un-experienced (in programming) eyes. In
+other words, as discussed in @ref{Science and its tools}, we want the
+code to appear welcoming to someone who is completely new to coding
+and only has a scientific curiosity.
+
+Newcomers to coding and development, who are curious enough to venture
+into the code, will not be using (or have any knowledge of) advanced
+text editors. They will see the raw code in the webpage or on a simple
+text editor (like Gedit) as plain text. Trying to learn and understand
+a file with dense functions that are all spaced with one or two blank
+lines can be very taunting for a newcomer. But when they scroll
+through the file and see clear titles and meaningful spaces for
+similar functions (less, meaningful density), we are helping them find and
+focus on the part they are most interested in sooner and easier.
address@hidden
address@hidden GNU coding standards
-For all exported functions and variables use as prefix the base name of
-the file in which they are defined, followed by the rest of the name,
-using underscores to separate address@hidden convention to use
-underscores to separate words, called ``snake case'' (or
-``snake_case''), is the one suggested by the GNU coding standards.}.
-The same applies to exported macros, but in upper case. For example,
-the prototype of function @code{gal_box_border_from_center} is in
address@hidden, and the macro @code{GAL_POLYGON_MAX_CORNERS} is
-defined in @code{gal_polygon.h}. This makes also easier to look up
-their definitions.
address@hidden
address@hidden GNU Emacs
address@hidden
address@hidden Emacs, the recommended text editor:} GNU Emacs is an
+extensible and easily customizable text editor which many programmers
+rely on for developing due to its countless features. Among them, it
+allows specification of certain settings that are applied to a single
+file or to all files in a directory and its sub-directories. In order
+to harmonize code coming from different contributors, Gnuastro comes
+with a @file{.dir-locals.el} file which automatically configures Emacs
+to satisfy most of the coding conventions above when you are using it
+within Gnuastro's directories. Thus, Emacs users can readily start
+hacking into Gnuastro. If you are new to developing, we strongly
+recommend this editor. Emacs was the first project released by GNU and
+is still one of its flagship projects. Some resources can be found at:
+
address@hidden @asis
address@hidden Official manual
+At @url{https://www.gnu.org/software/emacs/manual/emacs.html}. This is a
+great and very complete manual which is being improved for over 30 years
+and is the best starting point to learn it. It just requires a little
+patience and practice, but rest assured that you will be rewarded. If you
+install Emacs, you also have access to this manual on the command-line with
+the following command (see @ref{Info}).
+
address@hidden
+$ info emacs
address@hidden example
+
address@hidden A guided tour of emacs
+At @url{https://www.gnu.org/software/emacs/tour/}. A short visual tour
+of Emacs, officially maintained by the Emacs developers.
+
address@hidden Unofficial mini-manual
+At @url{https://tuhdo.github.io/emacs-tutor.html}. A shorter manual
+which contains nice animated images of using Emacs.
+
address@hidden table
address@hidden cartouche
address@hidden
-All installed libraries should have a name like @code{libgalbox.a}.
address@hidden itemize
+
@node Multithreaded programming, Documentation, Coding conventions, Program
source
@subsection Multithreaded programming
diff --cc include/arraymanip.h
index 184877e,48d472b..761c4d7
--- a/include/arraymanip.h
+++ b/include/arraymanip.h
@@@ -20,103 -20,46 +20,103 @@@ General Public License for more details
You should have received a copy of the GNU General Public License
along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
**********************************************************************/
- #ifndef ARRAYMANIP_H
- #define ARRAYMANIP_H
+ #ifndef __GAL_ARRAYMANIP_H__
+ #define __GAL_ARRAYMANIP_H__
void
- ucharinitonregion(unsigned char *in, const unsigned char v,
- size_t start, size_t s0, size_t s1, size_t is1);
+ gal_arraymanip_uchar_init_on_region(unsigned char *in, const unsigned char v,
+ size_t start, size_t s0, size_t s1,
+ size_t is1);
void
- longinit(long *in, size_t size, const long v);
+ gal_arraymanip_long_init(long *in, size_t size, const long v);
void
- longinitonregion(long *in, const long v, size_t start, size_t s0,
- size_t s1, size_t is1);
+ gal_arraymanip_long_init_on_region(long *in, const long v, size_t start,
+ size_t s0, size_t s1, size_t is1);
void
- ucharcopy(unsigned char *in, size_t size, unsigned char **out);
+ gal_arraymanip_uchar_copy(unsigned char *in, size_t size, unsigned char
**out);
void
- floatcopy(float *in, size_t size, float **out);
+ gal_arraymanip_float_copy(float *in, size_t size, float **out);
void
- floatcopyvalues(float *in, size_t size, float **out);
+ gal_arraymanip_float_copy_values(float *in, size_t size, float **out);
void
- fsetconst(float *in, size_t size, float a);
+ gal_arraymanip_fset_const(float *in, size_t size, float a);
void
- freplacevalue(float *in, size_t size, float from, float to);
+ gal_arraymanip_freplace_value(float *in, size_t size, float from, float to);
void
- nonans(float *in, size_t *size);
+ gal_arraymanip_no_nans(float *in, size_t *size);
void
- nonansdouble(double *in, size_t *size);
++gal_arraymanip_no_nans_double(double *in, size_t *size);
+
+void
- fmultipconst(float *in, size_t size, float a);
+ gal_arraymanip_fmultip_const(float *in, size_t size, float a);
void
- fsumconst(float *in, size_t size, float a);
+ gal_arraymanip_fsum_const(float *in, size_t size, float a);
float *
- fsumarrays_return(float *in1, float *in2, size_t size);
+ gal_arraymanip_fsum_arrays(float *in1, float *in2, size_t size);
+
+void
- dmultipconst(double *in, size_t size, double a);
++gal_arraymanip_dmultip_const(double *in, size_t size, double a);
+
+void
- dmultiparrays(double *in1, double *in2, size_t size);
++gal_arraymanip_dmultip_arrays(double *in1, double *in2, size_t size);
+
+
+void
- ddivideconst(double *in, size_t size, double a);
++gal_arraymanip_ddivide_const(double *in, size_t size, double a);
+
+void
- dconstdivide(double *in, size_t size, double a);
++gal_arraymanip_dconst_divide(double *in, size_t size, double a);
+
+void
- ddividearrays(double *in1, double *in2, size_t size);
++gal_arraymanip_ddivide_arrays(double *in1, double *in2, size_t size);
+
+
+void
- dsumconst(double *in, size_t size, double a);
++gal_arraymanip_dsum_const(double *in, size_t size, double a);
+
+void
- dsumarrays(double *in1, double *in2, size_t size);
++gal_arraymanip_dsum_arrays(double *in1, double *in2, size_t size);
+
+
+void
- dsubtractconst(double *in, size_t size, double a);
++gal_arraymanip_dsubtract_const(double *in, size_t size, double a);
+
+void
- dconstsubtract(double *in, size_t size, double a);
++gal_arraymanip_dconst_subtract(double *in, size_t size, double a);
+
+void
- dsubtractarrays(double *in1, double *in2, size_t size);
++gal_arraymanip_dsubtract_arrays(double *in1, double *in2, size_t size);
+
+
+void
- dpowerconst(double *in, size_t size, double a);
++gal_arraymanip_dpower_const(double *in, size_t size, double a);
+
+void
- dconstpower(double *in, size_t size, double a);
++gal_arraymanip_dconst_power(double *in, size_t size, double a);
+
+void
- dpowerarrays(double *in1, double *in2, size_t size);
-
++gal_arraymanip_dpower_arrays(double *in1, double *in2, size_t size);
+
+
+void
- dlogarray(double *in1, size_t size);
++gal_arraymanip_dlog_array(double *in1, size_t size);
+
+void
- dlog10array(double *in1, size_t size);
++gal_arraymanip_dlog10_array(double *in1, size_t size);
+
+void
- dabsarray(double *in1, size_t size);
++gal_arraymanip_dabs_array(double *in1, size_t size);
+
#endif
diff --cc include/checkset.h
index 009b3bd,cce1a51..42d411e
--- a/include/checkset.h
+++ b/include/checkset.h
@@@ -84,72 -77,74 +84,74 @@@ strisdouble(char *string, double *out)
/********* Read arguments and check their values **************/
/**************************************************************/
void
- intzeroorone(char *optarg, int *var, char *lo, char so, char* spack,
- char *filename, size_t lineno);
+ gal_checkset_int_zero_or_one(char *optarg, int *var, char *lo, char so,
+ char* spack, char *filename, size_t lineno);
void
- int4or8(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);
void
- intelzero(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);
void
- intlzero(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);
void
- intsmallerequalto(char *optarg, int *var, char *lo, char so, char *spack,
- char *filename, size_t lineno, long maxvalue);
+ gal_checkset_int_smaller_equal_to(char *optarg, int *var, char *lo, char so,
+ char *spack, char *filename, size_t lineno,
+ long maxvalue);
void
- longelzero(char *optarg, long *var, char *lo, char so, char *spack,
- char *filename, size_t lineno);
+ gal_checkset_long_el_zero(char *optarg, long *var, char *lo, char so,
+ char *spack, char *filename, size_t lineno);
void
- anylong(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);
void
- sizetelzero(char *optarg, size_t *var, char *lo, char so, char *spack,
- char *filename, size_t lineno);
+ gal_checkset_sizet_el_zero(char *optarg, size_t *var, char *lo, char so,
+ char *spack, char *filename, size_t lineno);
void
- sizetlzero(char *optarg, size_t *var, char *lo, char so, char *spack,
- char *filename, size_t lineno);
+ gal_checkset_sizet_l_zero(char *optarg, size_t *var, char *lo, char so,
+ char *spack, char *filename, size_t lineno);
void
- sizetpodd(char *optarg, size_t *var, char *lo, char so, char* spack,
- char *filename, size_t lineno);
+ gal_checkset_sizet_p_odd(char *optarg, size_t *var, char *lo, char so,
+ char* spack, char *filename, size_t lineno);
void
- floatl0(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);
void
- floatl0s1(char *optarg, float *var, char *lo, char so, char *spack,
- char *filename, size_t lineno);
+ gal_checkset_float_l_0_s_1(char *optarg, float *var, char *lo, char so,
+ char *spack, char *filename, size_t lineno);
void
- anyfloat(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);
void
- doublel0(char *optarg, double *var, char *lo, char so, char *spack,
- char *filename, size_t lineno);
+ gal_checkset_double_l_0(char *optarg, double *var, char *lo, char so,
+ char *spack, char *filename, size_t lineno);
void
--doublele0(char *optarg, double *var, char *lo, char so, char* spack,
-- char *filename, size_t lineno);
++gal_checkset_double_el_0(char *optarg, double *var, char *lo, char so,
++ char* spack, char *filename, size_t lineno);
void
- doublelvalue(char *optarg, double *var, char *lo, char so, char* spack,
- double value, char *filename, size_t lineno);
+ gal_checkset_double_l_value(char *optarg, double *var, char *lo, char so,
+ char* spack, double value, char *filename,
+ size_t lineno);
void
- anydouble(char *optarg, double *var, char *lo, char so, char *spack,
- char *filename, size_t lineno);
+ gal_checkset_any_double(char *optarg, double *var, char *lo, char so,
+ char *spack, char *filename, size_t lineno);
@@@ -164,16 -159,13 +166,16 @@@
/********** My String functions: ************/
/**************************************************************/
int
- stringhasspace(char *in);
+ gal_checkset_string_has_space(char *in);
char *
- malloccat(char *inname, char *toappend);
+ gal_checkset_malloc_cat(char *inname, char *toappend);
void
- allocatecopy(char *arg, char **copy);
++gal_checkset_allocate_copy(char *arg, char **copy);
+
+void
- allocatecopyset(char *arg, char **copy, int *set);
+ gal_checkset_allocate_copy_set(char *arg, char **copy, int *set);
diff --cc include/configfiles.h
index e16f952,fc7cf48..34f4ce6
--- a/include/configfiles.h
+++ b/include/configfiles.h
@@@ -73,21 -75,22 +75,21 @@@ along with Gnuastro. If not, see <http:
\
readconfig(CURDIRCONFIG_FILE, p); \
if(cp->setdirconf) \
- SAVE_LOCAL_CONFIG(CURDIRCONFIG_DIR); \
+ GAL_CONFIGFILES_SAVE_LOCAL_CONFIG(CURDIRCONFIG_DIR); \
- if(cp->onlyversionset && strcmp(cp->onlyversion, SPACK_VERSION)) \
- error(EXIT_FAILURE, 0, "The running version of %s is `%s'. " \
- "However, you have asked for this %s run to be with " \
- "version `%s'. Either on the command line or in a " \
- "configuration file with the `--onlyversion' option. " \
- "Please either remove it, or set it to `%s' with a command " \
- "like:\n\n" \
- " %s --onlyversion=%s --setdirconf\n\n" \
- "Alternatively, you can install %s %s.\n" \
- "NOTE: If this option was a configuration file, probably " \
- "it is intended for reproducability. If so, to be exactly " \
- "reproducible, it is advised to install the requested " \
- "version.", SPACK_NAME, SPACK_VERSION, SPACK_NAME, \
- cp->onlyversion, SPACK_VERSION, SPACK, SPACK_VERSION, \
- SPACK_NAME, SPACK_VERSION); \
+ if(cp->onlyversionset && strcmp(cp->onlyversion, PACKAGE_VERSION)) \
+ error(EXIT_FAILURE, 0, "You are currently running Gnuastro %s. " \
+ "However, this run should be with version `%s'.\n\n" \
+ "To resolve the situation, use the the '--onlyversion' " \
+ "option, either on the command-line or in a configuration " \
+ "file. For example, set it to `%s' by repeating the " \
+ "previous command with:\n\n" \
+ " --onlyversion=%s\n\n" \
+ "Alternatively, you can install Gnuastro %s.\n\n" \
+ "NOTE: If you didn't set this option on the command-line, " \
+ "it was probably intended for reproducability. If so, it " \
+ "is advised to install Gnuastro %s.", \
+ PACKAGE_VERSION, cp->onlyversion, PACKAGE_VERSION, \
+ PACKAGE_VERSION, cp->onlyversion, cp->onlyversion); \
\
if(cp->onlydirconf==0) \
{ \
diff --cc include/fitsarrayvv.h
index 6394e23,060dd4c..3530ad4
--- a/include/fitsarrayvv.h
+++ b/include/fitsarrayvv.h
@@@ -204,29 -214,27 +214,32 @@@ gal_fitsarray_atof_correct_wcs(char *fi
/********** Check prepare file ************/
/**************************************************************/
void
- fileorextname(char *inputname, char *inhdu, int othernameset,
- char **othername, char *ohdu, int ohduset, char *type);
+ gal_fitsarray_file_or_ext_name(char *inputname, char *inhdu, int othernameset,
+ char **othername, char *ohdu, int ohduset,
+ char *type);
void
- setmaskname(char *inputname, char **maskname, char *inhdu, char *mhdu);
+ gal_fitsarray_set_mask_name(char *inputname, char **maskname, char *inhdu,
+ char *mhdu);
void
- filetodouble(char *inputname, char *maskname, char *inhdu, char *mhdu,
- double **img, int *inbitpix, int *anyblank, size_t *ins0,
- size_t *ins1);
++gal_fitsarray_file_to_double(char *inputname, char *maskname, char *inhdu,
++ char *mhdu, double **img, int *inbitpix,
++ int *anyblank, size_t *ins0, size_t *ins1);
+
+void
- filetofloat(char *inputname, char *maskname, char *inhdu, char *mhdu,
- float **img, int *inbitpix, int *anyblank, size_t *ins0,
- size_t *ins1);
+ gal_fitsarray_file_to_float(char *inputname, char *maskname, char *inhdu,
+ char *mhdu, float **img, int *inbitpix,
+ int *anyblank, size_t *ins0, size_t *ins1);
void
- filetolong(char *inputname, char *inhdu, long **img, int *inbitpix,
- int *anyblank, size_t *ins0, size_t *ins1);
+ gal_fitsarray_file_to_long(char *inputname, char *inhdu, long **img,
+ int *inbitpix, int *anyblank, size_t *ins0,
+ size_t *ins1);
void
- prepfloatkernel(char *inputname, char *inhdu, float **kernel,
- size_t *ins0, size_t *ins1);
+ gal_fitsarray_prep_float_kernel(char *inputname, char *inhdu, float **kernel,
+ size_t *ins0, size_t *ins1);
diff --cc include/fixedstringmacros.h
index 4c59814,99bdc77..74033bb
--- a/include/fixedstringmacros.h
+++ b/include/fixedstringmacros.h
@@@ -20,67 -20,67 +20,73 @@@ General Public License for more details
You should have received a copy of the GNU General Public License
along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
**********************************************************************/
- #ifndef COPYRIGHT_H
- #define COPYRIGHT_H
+ #ifndef __GAL_COPYRIGHT_H__
+ #define __GAL_COPYRIGHT_H__
- #define SHORTCOPYRIGHT "Copyright (C) 2016, Free Software Foundation, Inc."
-#define GAL_STRINGS_SHORT_COPYRIGHT "Copyright (C) 2015, Free Software
Foundation, Inc."
++#define GAL_STRINGS_SHORT_COPYRIGHT \
++ "Copyright (C) 2015-2016, Free Software Foundation, Inc."
- #define SHORTLICENSE "License GPLv3+: GNU General public license version 3
or later."
-#define GAL_STRINGS_SHORT_LICENSE "License GPLv3+: GNU General public
license version 3 or later."
++#define GAL_STRINGS_SHORT_LICENSE \
++ "License GPLv3+: GNU General public license version 3 or later."
- #define COPYRIGHT SHORTCOPYRIGHT"\n"SHORTLICENSE"\n" \
-#define GAL_STRINGS_COPYRIGHT
GAL_STRINGS_SHORT_COPYRIGHT"\n"GAL_STRINGS_SHORT_LICENSE"\n" \
++
++#define GAL_STRINGS_COPYRIGHT \
++ GAL_STRINGS_SHORT_COPYRIGHT"\n"GAL_STRINGS_SHORT_LICENSE"\n" \
"This is free software: you are free to change and redistribute it.\n" \
-- "There is NO WARRANTY, to the extent permitted by law." \
++ "There is NO WARRANTY, to the extent permitted by law." \
- #define TOPHELPINFO "\n"SPACK_NAME" is part of "PACKAGE_STRING".\n"
-#define GAL_STRINGS_TOP_HELP_INFO "\n"SPACK_NAME" is part of
"PACKAGE_STRING".\n"
++#define GAL_STRINGS_TOP_HELP_INFO \
++ "\n"SPACK_NAME" is part of "PACKAGE_STRING".\n"
/* This is fixed for all the packages. */
- #define MOREHELPINFO "\nFor more information, please run any of the "
\
- "following commands. They will respectively show you the `Invoking "
\
- SPACK_NAME"' subsection, the complete `"SPACK_NAME"' section, or the "\
- "full "PACKAGE_NAME" manual. In particular the first contains " \
- "a very complete explanation of each option.\n\n" \
- " info "SPACK"\n\n" \
- " info "SPACK_NAME"\n\n"
\
- " info "PACKAGE_TARNAME"\n\n" \
- "If you couldn't find your answer in the manual, you can get " \
- "direct help from experienced Gnuastro users and developers. " \
- "For more information, please run:\n\n" \
- " info help-gnuastro\n\n" \
- SPACK_NAME" options:" \
-
-
-
- #define GNUASTROBIBTEX \
- "@ARTICLE{noisechisel,\n" \
- " author = {{Akhlaghi}, M. and {Ichikawa}, T.},\n" \
-#define GAL_STRINGS_MORE_HELP_INFO "\nFor more information, please run any
of the " \
- "following commands. They will respectively show you the `Invoking "
\
- SPACK_NAME"' subsection, the complete `"SPACK_NAME"' section, or the "\
- "full "PACKAGE_NAME" manual. In particular the first contains " \
- "a very complete explanation of each option.\n\n" \
- " info "SPACK"\n\n" \
- " info "SPACK_NAME"\n\n"
\
- " info "PACKAGE_TARNAME"\n\n" \
- "If you couldn't find your answer in the manual, you can get " \
- "direct help from experienced Gnuastro users and developers. " \
- "For more information, please run:\n" \
- " info help-gnuastro\n\n" \
- SPACK_NAME" options:" \
-
-
-
-#define GAL_STRINGS_BIBTEX \
- "@ARTICLE{noisechisel,\n" \
- " author = {{Akhlaghi}, M. and {Ichikawa}, T.},\n" \
++#define GAL_STRINGS_MORE_HELP_INFO \
++ "\nFor more information, please run any of the " \
++ "following commands. They will respectively show you the `Invoking "
\
++ SPACK_NAME"' subsection, the complete `"SPACK_NAME"' section, or the " \
++ "full "PACKAGE_NAME" manual. In particular the first contains " \
++ "a very complete explanation of each option.\n\n" \
++ " info "SPACK"\n\n" \
++ " info "SPACK_NAME"\n\n"
\
++ " info "PACKAGE_TARNAME"\n\n" \
++ "If you couldn't find your answer in the manual, you can get " \
++ "direct help from experienced Gnuastro users and developers. " \
++ "For more information, please run:\n\n" \
++ " info help-gnuastro\n\n" \
++ SPACK_NAME" options:" \
++
++
++
++#define GAL_STRINGS_MAIN_BIBTEX \
++ "@ARTICLE{noisechisel,\n" \
++ " author = {{Akhlaghi}, M. and {Ichikawa}, T.},\n" \
" title = \"{Noise-based Detection and Segmentation of Nebulous
Objects}\",\n" \
- " journal = {\\apjs},\n" \
- "archivePrefix = \"arXiv\",\n" \
- " eprint = {1505.01664},\n" \
- " primaryClass = \"astro-ph.IM\",\n" \
- " keywords = {galaxies: irregular, galaxies: photometry, " \
- "galaxies: structure, methods: data analysis, " \
- "techniques: image processing, techniques: photometric},\n" \
- " year = 2015,\n" \
- " month = sep,\n" \
- " volume = 220,\n" \
- " eid = {1},\n" \
- " pages = {1},\n" \
- " doi = {10.1088/0067-0049/220/1/1},\n" \
- " adsurl = {http://adsabs.harvard.edu/abs/2015ApJS..220....1A},\n" \
- " adsnote = {Provided by the SAO/NASA Astrophysics Data System}\n" \
- " journal = {\apjs},\n" \
- "archivePrefix = \"arXiv\",\n" \
- " eprint = {1505.01664},\n" \
- " primaryClass = \"astro-ph.IM\",\n" \
- " keywords = {galaxies: irregular, galaxies: photometry, " \
- "galaxies: structure, methods: data analysis, " \
- "techniques: image processing, techniques: photometric},\n" \
- " year = 2015,\n" \
- " month = sep,\n" \
- " volume = 220,\n" \
- " eid = {1},\n" \
- " pages = {1},\n" \
- " doi = {10.1088/0067-0049/220/1/1},\n" \
- " adsurl = {http://adsabs.harvard.edu/abs/2015ApJS..220....1A},\n" \
- " adsnote = {Provided by the SAO/NASA Astrophysics Data System}\n" \
++ " journal = {\\apjs},\n" \
++ "archivePrefix = \"arXiv\",\n" \
++ " eprint = {1505.01664},\n" \
++ " primaryClass = \"astro-ph.IM\",\n" \
++ " keywords = {galaxies: irregular, galaxies: photometry, " \
++ "galaxies: structure, methods: data analysis, " \
++ "techniques: image processing, techniques: photometric},\n" \
++ " year = 2015,\n" \
++ " month = sep,\n" \
++ " volume = 220,\n" \
++ " eid = {1},\n" \
++ " pages = {1},\n" \
++ " doi = {10.1088/0067-0049/220/1/1},\n" \
++ " adsurl = {http://adsabs.harvard.edu/abs/2015ApJS..220....1A},\n" \
++ " adsnote = {Provided by the SAO/NASA Astrophysics Data System}\n" \
"}"
/* This can be used in the end of error messages related to option
values. */
- #define HOWTOCHECKVALUES \
- " You can check all the input values with the `--printparams' " \
-#define GAL_STRINGS_HOW_TO_CHECK_VALUES \
- " You can check all the input values with the `--printparams' " \
++#define GAL_STRINGS_HOW_TO_CHECK_VALUES \
++ " You can check all the input values with the `--printparams' " \
"(-P) option."
#endif
diff --cc include/linkedlist.h
index 5e306b7,1e1b935..fecca17
--- a/include/linkedlist.h
+++ b/include/linkedlist.h
@@@ -115,26 -119,22 +119,26 @@@ gal_linkedlist_free_fll_array(struct ga
/******************* String: */
- struct stll
+ struct gal_linkedlist_stll
{
char *v;
- struct stll *next;
+ struct gal_linkedlist_stll *next;
};
+
void
- add_to_stll(struct stll **list, char *value);
+ gal_linkedlist_add_to_stll(struct gal_linkedlist_stll **list, char *value);
void
- pop_from_stll(struct stll **list, char **value);
+ gal_linkedlist_pop_from_stll(struct gal_linkedlist_stll **list, char **value);
void
- reverse_stll(struct stll **list);
++gal_linkedlist_reverse_stll(struct gal_linkedlist_stll **list);
+
+void
- print_stll(struct stll *list);
+ gal_linkedlist_print_stll(struct gal_linkedlist_stll *list);
size_t
- numinstll(struct stll *list);
+ gal_linkedlist_num_in_stll(struct gal_linkedlist_stll *list);
diff --cc include/statistics.h
index 8604266,b364301..ad910e1
--- a/include/statistics.h
+++ b/include/statistics.h
@@@ -31,49 -31,48 +31,54 @@@ along with Gnuastro. If not, see <http:
***************** Mininum and Maximum ********************
****************************************************************/
void
- floatmin(float *in, size_t size, float *min);
+ gal_statistics_float_min(float *in, size_t size, float *min);
void
- floatmax(float *in, size_t size, float *max);
+ gal_statistics_float_max(float *in, size_t size, float *max);
void
- doublemin(double *in, size_t size, double *min);
+ gal_statistics_double_min(double *in, size_t size, double *min);
+double
- doublemin_r(double *in, size_t size);
++gal_statistics_double_min_return(double *in, size_t size);
+
void
- doublemax(double *in, size_t size, double *max);
+ gal_statistics_double_max(double *in, size_t size, double *max);
+double
- doublemax_r(double *in, size_t size);
++gal_statistics_double_max_return(double *in, size_t size);
+
void
- floatmaxmasked(float *in, unsigned char *mask, size_t size, float *max);
+ gal_statistics_float_max_masked(float *in, unsigned char *mask, size_t size,
+ float *max);
void
- floatsecondmax(float *in, size_t size, float *secondmax);
+ gal_statistics_float_second_max(float *in, size_t size, float *secondmax);
void
- floatsecondmin(float *in, size_t size, float *secondmin);
+ gal_statistics_float_second_min(float *in, size_t size, float *secondmin);
void
- fminmax(float *in, size_t size, float *min, float *max);
+ gal_statistics_f_min_max(float *in, size_t size, float *min, float *max);
void
- dminmax(double *in, size_t size, double *min, double *max);
+ gal_statistics_d_min_max(double *in, size_t size, double *min, double *max);
void
- dmax_withindex(double *in, size_t size, double *max, size_t *index);
+ gal_statistics_d_max_with_index(double *in, size_t size, double *max,
+ size_t *index);
void
- fmax_withindex(float *in, size_t size, float *max, size_t *index);
+ gal_statistics_f_max_with_index(float *in, size_t size, float *max,
+ size_t *index);
void
- dmin_withindex(double *in, size_t size, double *min, size_t *index);
+ gal_statistics_d_min_with_index(double *in, size_t size, double *min,
+ size_t *index);
void
- fmin_withindex(float *in, size_t size, float *min, size_t *index);
+ gal_statistics_f_min_with_index(float *in, size_t size, float *min,
+ size_t *index);
@@@ -112,34 -115,38 +121,41 @@@ gal_statistics_float_sum_squared_mask_l
**************** Standard deviation ********************
****************************************************************/
float
- floataverage(float *in, size_t size);
+ gal_statistics_float_average(float *in, size_t size);
+double
- doubleaverage(double *in, size_t size);
++gal_statistics_double_average(double *in, size_t size);
+
void
- fave(float *in, size_t size, float *ave, unsigned char *mask);
+ gal_statistics_f_ave(float *in, size_t size, float *ave, unsigned char *mask);
void
- favel(float *in, size_t size, float *ave, long *mask);
+ gal_statistics_f_ave_l(float *in, size_t size, float *ave, long *mask);
void
- favestd(float *in, size_t size, float *ave, float *std, unsigned char *mask);
+ gal_statistics_f_ave_std(float *in, size_t size, float *ave,
+ float *std, unsigned char *mask);
void
- favestdl(float *in, size_t size, float *ave, float *std, long *mask);
+ gal_statistics_f_ave_std_l(float *in, size_t size, float *ave,
+ float *std, long *mask);
void
- floatavestdmaskbyt0inregion(float *in, unsigned char *byt,
- unsigned char *mask, size_t startind,
- size_t s0, size_t s1, size_t is1,
- float *ave, float *std);
+ gal_statistics_f_ave_std_mask_byt_0_in_region(float *in, unsigned char *byt,
+ unsigned char *mask,
+ size_t startind, size_t s0,
+ size_t s1, size_t is1,
+ float *ave, float *std);
void
- floatavestdmaskbyt0inregionsclip(float *in, unsigned char *byt,
- unsigned char *mask, size_t startind,
- size_t s0, size_t s1, size_t is1,
- size_t numback, float *ave, float *std);
+ gal_statistics_f_ave_std_mask_byt_0_in_regions_clip(float *in,
+ unsigned char *byt,
+ unsigned char *mask,
+ size_t startind,
+ size_t s0, size_t s1,
+ size_t is1,
+ size_t numback, float
*ave,
+ float *std);
@@@ -149,11 -156,8 +165,11 @@@
***************** Median ******************
****************************************************************/
float
- median(float *array, size_t insize);
+ gal_statistics_median(float *array, size_t insize);
+double
- mediandoubleinplace(double *array, size_t insize);
++gal_statistics_median_double_in_place(double *array, size_t insize);
+
diff --cc lib/arraymanip.c
index 04607b3,3b92d56..0f453c0
--- a/lib/arraymanip.c
+++ b/lib/arraymanip.c
@@@ -228,25 -229,6 +229,25 @@@ gal_arraymanip_no_nans(float *in, size_
+void
- nonansdouble(double *in, size_t *size)
++gal_arraymanip_no_nans_double(double *in, size_t *size)
+{
+ size_t outsize=0;
+ double *f=in, *fp=in+*size;
+ do
+ if(!isnan(*in))
+ {
+ *f++=*in;
+ ++outsize;
+ }
+ while(++in<fp);
+ *size=outsize;
+}
+
+
+
+
+
@@@ -308,196 -290,3 +309,196 @@@ gal_arraymanip_fsum_arrays(float *in1,
return out;
}
+
+
+
+
+
+void
- dmultipconst(double *in, size_t size, double a)
++gal_arraymanip_dmultip_const(double *in, size_t size, double a)
+{
+ double *dpt;
+ dpt=in+size;
+ do *in *= a; while(++in<dpt);
+}
+
+
+
+
+void
- dmultiparrays(double *in1, double *in2, size_t size)
++gal_arraymanip_dmultip_arrays(double *in1, double *in2, size_t size)
+{
+ double *dpt;
+ dpt=in1+size;
+ do *in1 *= *in2++; while(++in1<dpt);
+}
+
+
+
+
+
+void
- ddivideconst(double *in, size_t size, double a)
++gal_arraymanip_ddivide_const(double *in, size_t size, double a)
+{
+ double *dpt;
+ dpt=in+size;
+ do *in /= a; while(++in<dpt);
+}
+
+
+
+
+
+void
- dconstdivide(double *in, size_t size, double a)
++gal_arraymanip_dconst_divide(double *in, size_t size, double a)
+{
+ double *dpt;
+ dpt=in+size;
+ do *in = a / *in; while(++in<dpt);
+}
+
+
+
+
+void
- ddividearrays(double *in1, double *in2, size_t size)
++gal_arraymanip_ddivide_arrays(double *in1, double *in2, size_t size)
+{
+ double *dpt;
+ dpt=in1+size;
+ do *in1 /= *in2++; while(++in1<dpt);
+}
+
+
+
+
+void
- dsumconst(double *in, size_t size, double a)
++gal_arraymanip_dsum_const(double *in, size_t size, double a)
+{
+ double *dpt;
+ dpt=in+size;
+ do *in += a; while(++in<dpt);
+}
+
+
+
+
+
+void
- dsumarrays(double *in1, double *in2, size_t size)
++gal_arraymanip_dsum_arrays(double *in1, double *in2, size_t size)
+{
+ double *dpt;
+ dpt=in1+size;
+ do *in1 += *in2++; while(++in1<dpt);
+}
+
+
+
+void
- dsubtractconst(double *in, size_t size, double a)
++gal_arraymanip_dsubtract_const(double *in, size_t size, double a)
+{
+ double *dpt;
+ dpt=in+size;
+ do *in -= a; while(++in<dpt);
+}
+
+
+
+
+
+void
- dconstsubtract(double *in, size_t size, double a)
++gal_arraymanip_dconst_subtract(double *in, size_t size, double a)
+{
+ double *dpt;
+ dpt=in+size;
+ do *in = a - *in; while(++in<dpt);
+}
+
+
+
+
+
+void
- dsubtractarrays(double *in1, double *in2, size_t size)
++gal_arraymanip_dsubtract_arrays(double *in1, double *in2, size_t size)
+{
+ double *dpt;
+ dpt=in1+size;
+ do *in1 -= *in2++; while(++in1<dpt);
+}
+
+
+
+void
- dpowerconst(double *in, size_t size, double a)
++gal_arraymanip_dpower_const(double *in, size_t size, double a)
+{
+ double *dpt;
+ dpt=in+size;
+
+ /* Since simply multiplying or taking the square root are more
+ efficient than calling the power function. */
+ if(a==2.0f) do *in *= *in; while(++in<dpt);
+ else if(a==0.5f) do *in = sqrt(*in); while(++in<dpt);
+ else do *in = pow(*in, a); while(++in<dpt);
+}
+
+
+
+
+
+void
- dconstpower(double *in, size_t size, double a)
++gal_arraymanip_dconst_power(double *in, size_t size, double a)
+{
+ double *dpt;
+ dpt=in+size;
+ do *in = pow(a, *in); while(++in<dpt);
+}
+
+
+
+
+
+void
- dpowerarrays(double *in1, double *in2, size_t size)
++gal_arraymanip_dpower_arrays(double *in1, double *in2, size_t size)
+{
+ double *dpt;
+ dpt=in1+size;
+ do *in1 = pow(*in1, *in2++); while(++in1<dpt);
+}
+
+
+
+
+
+void
- dlogarray(double *in, size_t size)
++gal_arraymanip_dlog_array(double *in, size_t size)
+{
+ double *dpt;
+ dpt=in+size;
+
+ do *in = log(*in); while(++in<dpt);
+}
+
+
+
+
+
+void
- dlog10array(double *in, size_t size)
++gal_arraymanip_dlog10_array(double *in, size_t size)
+{
+ double *dpt;
+ dpt=in+size;
+
+ do *in = log10(*in); while(++in<dpt);
+}
+
+
+
+
+
+void
- dabsarray(double *in, size_t size)
++gal_arraymanip_dabs_array(double *in, size_t size)
+{
+ double *dpt;
+ dpt=in+size;
+
+ do *in = fabs(*in); while(++in<dpt);
+}
diff --cc lib/checkset.c
index bb895e6,9f75cce..6fa50c9
--- a/lib/checkset.c
+++ b/lib/checkset.c
@@@ -422,8 -384,8 +423,8 @@@ gal_checkset_double_l_0(char *optarg, d
void
--doublele0(char *optarg, double *var, char *lo, char so, char* spack,
-- char *filename, size_t lineno)
++gal_checkset_double_el_0(char *optarg, double *var, char *lo, char so,
++ char* spack, char *filename, size_t lineno)
{
double tmp;
char *tailptr;
@@@ -541,22 -504,6 +543,22 @@@ gal_checkset_malloc_cat(char *inname, c
+/* Copy the input string to the output (and also allocate the
+ output. */
+void
- allocatecopy(char *arg, char **copy)
++gal_checkset_allocate_copy(char *arg, char **copy)
+{
+ /* Allocate the necessary space: */
+ errno=0;
+ *copy=malloc(strlen(arg)+1);
+ if(*copy==NULL)
+ error(EXIT_FAILURE, errno, "%lu bytes to copy %s",
+ strlen(arg)+1, arg);
+ strcpy(*copy, arg);
+}
+
+
+
/* This function is mainly for reading in the arguments (from the
command line or configuration files) that need to be copied. The
@@@ -731,14 -678,17 +733,14 @@@ gal_checkset_automatic_output(char *inn
char *out;
size_t i, l, offset=0;
- /* Check if the input file is actually a readable file or not! */
- gal_checkset_check_file(inname);
-
- /* Note that we are just using gal_checkset_malloc_cat here to allocate the
- right space! The contents of the allocated space will be changed after
+ /* Note that we are just using malloccat here to allocate the right
+ space! The contents of the allocated space will be changed after
this.*/
- out=malloccat(inname, suffix);
+ out=gal_checkset_malloc_cat(inname, suffix);
- /* Put the input in the space and remove all elements including and
- after '.'. Note that if there is no '.' in the name, malloccat
- has already appended inname and suffix.*/
+ /* Put the input in the space and remove all elements including and after
'.'.
+ Note that if there is no '.' in the name, gal_checkset_malloc_cat has
+ already appended inname and suffix.*/
l=strlen(inname);
strcpy(out, inname);
for(i=l;i!=0;--i)
diff --cc lib/fitsarrayvv.c
index c826605,3b26338..9f793f9
--- a/lib/fitsarrayvv.c
+++ b/lib/fitsarrayvv.c
@@@ -1563,75 -1593,11 +1593,78 @@@ gal_fitsarray_file_to_float(char *input
+/* Similar to filetofloat, but for double type */
+void
- filetodouble(char *inputname, char *maskname, char *inhdu, char *mhdu,
- double **img, int *inbitpix, int *anyblank, size_t *ins0,
- size_t *ins1)
++gal_fitsarray_file_to_double(char *inputname, char *maskname, char *inhdu,
++ char *mhdu, double **img, int *inbitpix,
++ int *anyblank, size_t *ins0, size_t *ins1)
+{
+ void *array;
+ int maskbitpix;
+ double *mask, *f, *ff, *fp;
+ size_t maskanyblank, s0, s1;
+
+ /* Read the input array and convert it to double. */
- *anyblank=fitsimgtoarray(inputname, inhdu, inbitpix,
- &array, ins0, ins1);
++ *anyblank=gal_fitsarray_fits_img_to_array(inputname, inhdu, inbitpix,
++ &array, ins0, ins1);
+ if(*inbitpix==DOUBLE_IMG)
+ *img=array;
+ else
+ {
- changetype(array, *inbitpix, *ins0 * *ins1, *anyblank,
- (void **)img, DOUBLE_IMG);
++ gal_fitsarray_change_type(array, *inbitpix, *ins0 * *ins1, *anyblank,
++ (void **)img, DOUBLE_IMG);
+ free(array);
+ }
+
+ /* If a mask was specified, read it as a double image, then set all
+ the corresponding pixels of the input image to NaN. */
+ if(maskname)
+ {
- maskanyblank=fitsimgtoarray(maskname, mhdu, &maskbitpix,
- &array, &s0, &s1);
++ maskanyblank=gal_fitsarray_fits_img_to_array(maskname,
++ mhdu, &maskbitpix,
++ &array, &s0, &s1);
+
+ if(maskbitpix==FLOAT_IMG || maskbitpix==DOUBLE_IMG)
+ fprintf(stderr, "WARNING: the mask image (%s, hdu: %s) has a %s "
+ "precision floating point data type (BITPIX=%d). The mask "
+ "image is usually an integer type. Therefore this might "
+ "be due to a mistake in the inputs and the results might "
+ "not be what you intended. However, the program will not "
+ "abort and continue working only with zero valued pixels in "
+ "the given masked image.", maskname, mhdu,
+ maskbitpix==FLOAT_IMG ? "single" : "double", maskbitpix);
+
+ if(s0!=*ins0 || s1!=*ins1)
+ error(EXIT_FAILURE, 0, "The input image %s (hdu: %s) has size: "
+ "%lu x %lu. The mask image %s (hdu: %s) has size %lu x %lu. "
+ "The two images have to have the same size.", inputname,
+ inhdu, *ins1, *ins0, maskname, mhdu, s1, s0);
+
+ if(maskbitpix==DOUBLE_IMG)
+ mask=array;
+ else
+ {
- changetype(array, maskbitpix, *ins0 * *ins1, maskanyblank,
- (void **)(&mask), DOUBLE_IMG);
++ gal_fitsarray_change_type(array, maskbitpix, *ins0 * *ins1,
++ maskanyblank, (void **)(&mask),
++ DOUBLE_IMG);
+ free(array);
+ }
+
+ ff=mask;
+ fp=(f=*img)+s0*s1;
+ do if(*ff++!=0.0f) {*f=NAN; ++(*anyblank);} while(++f<fp);
+ free(mask);
+ }
+}
+
+
+
+
void
- filetolong(char *inputname, char *inhdu, long **img, int *inbitpix,
- int *anyblank, size_t *ins0, size_t *ins1)
+ gal_fitsarray_file_to_long(char *inputname, char *inhdu, long **img,
+ int *inbitpix, int *anyblank, size_t *ins0,
+ size_t *ins1)
{
void *array;
diff --cc lib/linkedlist.c
index 748bf09,4b7c7ac..5371836
--- a/lib/linkedlist.c
+++ b/lib/linkedlist.c
@@@ -334,26 -340,9 +340,26 @@@ gal_linkedlist_pop_from_stll(struct gal
void
- reverse_stll(struct stll **list)
++gal_linkedlist_reverse_stll(struct gal_linkedlist_stll **list)
+{
+ char *thisstring;
- struct stll *correctorder=NULL;
++ struct gal_linkedlist_stll *correctorder=NULL;
+
+ while(*list!=NULL)
+ {
- pop_from_stll(list, &thisstring);
- add_to_stll(&correctorder, thisstring);
++ gal_linkedlist_pop_from_stll(list, &thisstring);
++ gal_linkedlist_add_to_stll(&correctorder, thisstring);
+ }
+ *list=correctorder;
+}
+
+
+
+
+void
- print_stll(struct stll *list)
+ gal_linkedlist_print_stll(struct gal_linkedlist_stll *list)
{
- struct stll *tmp;
+ struct gal_linkedlist_stll *tmp;
for(tmp=list; tmp!=NULL; tmp=tmp->next)
printf("%s\n", tmp->v);
}
diff --cc lib/statistics.c
index 29ab7b8,d542c24..bc504c2
--- a/lib/statistics.c
+++ b/lib/statistics.c
@@@ -89,23 -89,8 +89,23 @@@ gal_statistics_double_min(double *in, s
+double
- doublemin_r(double *in, size_t size)
++gal_statistics_double_min_return(double *in, size_t size)
+{
+ double tmin=FLT_MAX, *fpt;
+ fpt=in+size;
+ do /* Works for NAN, since NAN is not smaller than any number. */
+ if(*in<tmin) tmin=*in;
+ while(++in<fpt);
+ return tmin;
+}
+
+
+
+
+
void
- doublemax(double *in, size_t size, double *max)
+ gal_statistics_double_max(double *in, size_t size, double *max)
{
double tmax=-FLT_MAX, *fpt;
fpt=in+size;
@@@ -118,23 -103,9 +118,24 @@@
+
+double
- doublemax_r(double *in, size_t size)
++gal_statistics_double_max_return(double *in, size_t size)
+{
+ double tmax=-FLT_MAX, *fpt;
+ fpt=in+size;
+ do /* Works for NAN, since NAN is not larger than any number. */
+ if(*in>tmax) tmax=*in;
+ while(++in<fpt);
+ return tmax;
+}
+
+
+
+
void
- floatmaxmasked(float *in, unsigned char *mask, size_t size, float *max)
+ gal_statistics_float_max_masked(float *in, unsigned char *mask, size_t size,
+ float *max)
{
float tmax=-FLT_MAX, *fpt;
fpt=in+size;
@@@ -394,38 -366,8 +396,38 @@@ gal_statistics_float_sum_num(float *in
+
+double
+doublesumnum(double *in, size_t *size)
+{
+ double *fpt;
+ double sum=0;
+
+ /* If size is initially zero, then return 0. */
+ if(*size==0) return 0.0f;
+
+ /* Go through all the array: */
+ fpt=in+*size;
+ *size=0;
+ do
+ if(!isnan(*in))
+ {
+ sum+=*in;
+ ++(*size);
+ }
+ while(++in<fpt);
+
+ /* If the size was not initially zero, but after going through the
+ whole array, it is still zero, then the whole array had NaN
+ values. */
+ return *size ? sum : NAN;
+}
+
+
+
+
float
- floatsumsquared(float *in, size_t size)
+ gal_statistics_float_sum_squared(float *in, size_t size)
{
float *fpt;
double sum=0;
@@@ -577,12 -519,19 +579,12 @@@ gal_statistics_float_average(float *in
-void
-fave_old(float *in, size_t size, float *ave, unsigned char *mask)
+double
- doubleaverage(double *in, size_t size)
++gal_statistics_double_average(double *in, size_t size)
{
- float sum;
- size_t nsize;
- if(mask==NULL)
- sum=gal_statistics_float_sum(in, size);
- else
- {
- sum=gal_statistics_float_sum_mask(in, mask, size, &nsize);
- size=nsize;
- }
- *ave=sum/size;
+ double sum;
+ sum=doublesumnum(in, &size);
+ return sum/size;
}
@@@ -773,35 -707,6 +760,35 @@@ gal_statistics_median(float *array, siz
+double
- mediandoubleinplace(double *array, size_t insize)
++gal_statistics_median_double_in_place(double *array, size_t insize)
+{
+ size_t size=insize, medind;
+
+ /* Shift all its non-NaN elements to the start of the array, then
+ sort them and find the median. */
- nonansdouble(array, &size);
++ gal_arraymanip_no_nans_double(array, &size);
+
+ /* If all the elements are NaN (size==0), then return NaN,
+ otherwise, find the median. */
+ if(size)
+ {
- qsort(array, size, sizeof*array, doubleincreasing);
- medind=indexfromquantile(size, 0.5);
++ qsort(array, size, sizeof*array, gal_qsort_double_increasing);
++ medind=gal_statistics_index_from_quantile(size, 0.5);
+
+ if(size%2)
+ return array[medind];
+ else
+ return (array[medind]+array[medind-1])/2;
+ }
+ else
+ return NAN;
+}
+
+
+
+
+
diff --cc src/arithmetic/args.h
index 63343a9,f9f945c..648b3c8
--- a/src/arithmetic/args.h
+++ b/src/arithmetic/args.h
@@@ -44,11 -43,12 +44,11 @@@ along with Gnuastro. If not, see <http:
-
/* Definition parameters for the argp: */
- const char *argp_program_version=SPACK_STRING"\n"COPYRIGHT
+ const char *argp_program_version=SPACK_STRING"\n"GAL_STRINGS_COPYRIGHT
"\n\nWritten by Mohammad Akhlaghi";
const char *argp_program_bug_address=PACKAGE_BUGREPORT;
-static char args_doc[] = "ASTRdata ...";
+static char args_doc[] = "ASTRdata or number [ASTRdata] OPERATOR ...";
@@@ -56,21 -56,10 +56,21 @@@
const char doc[] =
/* Before the list of options: */
- TOPHELPINFO
+ GAL_STRINGS_TOP_HELP_INFO
- SPACK_NAME" will add noise to all the pixels in an input image. The noise "
- "parameters can be specified with the command line options. \n"
+ SPACK_NAME" will do arithmetic operations on one or multiple images and "
+ "numbers. Simply put, the name of the image along with the arithmetic "
+ "operators and possible numbers are given as arguments. The extensions of "
+ "each input image are expected as options (starting with `hdu') listed "
+ "below. Please note that currently "SPACK_NAME" only supports postfix "
+ "or reverse polish notation. For example to get the result of `5+6', you "
+ "should write `5 6 +', or to get the average of two images, you should "
+ "write `a.fits b.fits + 2 /' (or more simply a.fits b.fits average). "
+ "Please see the manual for more information. "
+ "\n\nThe operators/functions recognized by "SPACK_NAME" are: +, -, *, /, "
+ "abs, pow, sqrt, log, log10, minvalue, maxvalue, min, max, average and "
+ "median. Note that multiplication should be quoted like \"*\" to avoid "
+ "shell expansion.\n"
- MOREHELPINFO
+ GAL_STRINGS_MORE_HELP_INFO
/* After the list of options: */
"\v"
PACKAGE_NAME" home page: "PACKAGE_URL;
@@@ -172,24 -176,24 +172,25 @@@ parse_opt(int key, char *arg, struct ar
switch(key)
{
+ /* Commandline options don't need to be allocated, since they are
+ already in static memory and their pointers will not
+ change. They also don't need to be freed for the same
+ reason. However, later on, we will also be reading from the
+ configuration files and there, we need to allocate space (and
+ free it later). So to consistently free all the poped strings,
+ we are allocating a copy here too. */
+ case 'h':
- allocatecopy(arg, &tokeephdu);
- add_to_stll(&p->hdus, tokeephdu);
++ gal_checkset_allocate_copy(arg, &tokeephdu);
++ gal_linkedlist_add_to_stll(&p->hdus, tokeephdu);
+ break;
/* Input: */
- case 'b':
- gal_checkset_any_double(arg, &p->mbackground, "background", key, SPACK,
- NULL, 0);
- p->up.backgroundset=1;
- break;
- case 's':
- doublele0(arg, &p->stdadd, "stdadd", key, SPACK, NULL, 0);
- p->up.stdaddset=1;
- break;
- case 'z':
- gal_checkset_any_double(arg, &p->zeropoint, "zeropoint", key, SPACK,
- NULL, 0);
- p->up.zeropointset=1;
+ case 'M':
- allocatecopyset(arg, &p->up.maskname, &p->up.masknameset);
++ gal_checkset_allocate_copy_set(arg, &p->up.maskname,
++ &p->up.masknameset);
break;
- case 'e':
- p->envseed=1;
+ case 'H':
- allocatecopyset(arg, &p->up.mhdu, &p->up.mhduset);
++ gal_checkset_allocate_copy_set(arg, &p->up.mhdu, &p->up.mhduset);
break;
@@@ -201,8 -206,16 +202,8 @@@
/* Read the non-option arguments: */
case ARGP_KEY_ARG:
- /* See what type of input value it is and put it in. */
- if( gal_fitsarray_name_is_fits(arg) )
- {
- if(p->up.inputname)
- argp_error(state, "Only one input image should be given.");
- else
- p->up.inputname=arg;
- }
- else
- argp_error(state, "%s is not a valid file type.", arg);
+ /* Add the argument to the list of tokens: */
- add_to_stll(&p->tokens, arg);
++ gal_linkedlist_add_to_stll(&p->tokens, arg);
break;
diff --cc src/arithmetic/arithmetic.c
index 5016ab6,0000000..83a9f8f
mode 100644,000000..100644
--- a/src/arithmetic/arithmetic.c
+++ b/src/arithmetic/arithmetic.c
@@@ -1,896 -1,0 +1,900 @@@
+/*********************************************************************
+ImageArithmetic - Do arithmetic operations on images.
+ImageArithmetic is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+ Mohammad Akhlaghi <address@hidden>
+Contributing author(s):
+Copyright (C) 2015, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#include <config.h>
+
+#include <math.h>
+#include <stdio.h>
+#include <errno.h>
+#include <error.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "checkset.h"
+#include "arraymanip.h"
+#include "statistics.h"
+#include "fitsarrayvv.h"
+
+#include "main.h"
+#include "arithmetic.h" /* needs main.h. */
+
+
+
+
+/***************************************************************/
+/************* Operand linked list functions *************/
+/***************************************************************/
+size_t
+num_operands(struct imgarithparams *p)
+{
+ size_t counter=0;
+ struct operand *tmp=NULL;
+ for(tmp=p->operands;tmp!=NULL;tmp=tmp->next)
+ ++counter;
+ return counter;
+}
+
+
+
+
+
+void
+add_operand(struct imgarithparams *p, char *filename, double number,
+ double *array)
+{
+ struct operand *newnode;
+
+ /* Allocate space for the new operand. */
+ errno=0;
+ newnode=malloc(sizeof *newnode);
+ if(newnode==NULL)
+ error(EXIT_FAILURE, errno, "imgarith.c: Making new element in operand");
+
+ /* Fill in the values. */
+ newnode->array=array;
+ newnode->number=number;
+ newnode->filename=filename;
+
- if(strlen(filename) && nameisfits(filename))
++ if(strlen(filename) && gal_fitsarray_name_is_fits(filename))
+ {
+ /* Set the HDU for this filename. */
- pop_from_stll(&p->hdus, &newnode->hdu);
++ gal_linkedlist_pop_from_stll(&p->hdus, &newnode->hdu);
+
+ /* Increment the FITS counter. */
+ ++p->addcounter;
+ }
+
+ /* Make the link to the previous list. */
+ newnode->next=p->operands;
+ p->operands=newnode;
+}
+
+
+
+
+
+void
+pop_operand(struct imgarithparams *p, double *number, double **array,
+ char *operator)
+{
+ int bitpix;
+ size_t s0, s1;
+ struct uiparams *up=&p->up;
+ struct operand *operands=p->operands;
+ char *maskname, *mhdu, *filename, *hdu;
+
+ /* If the operand linked list has finished, then give an error and
+ exit. */
+ if(operands==NULL)
+ error(EXIT_FAILURE, 0, "Not enough operands for the \"%s\" operator.",
+ operator);
+
+
+ /* Do a sanity check. The basic idea behind this is that all the
+ conditionals below will evaluate to 1 or 0. So if more than one
+ of them are true, then the sum will be larger than 1 and if none
+ of them are true then the sum will be 0. So if the sum (check) is
+ not equal to 1, then there is a bug and the user should be
+ warned. The parenthesis will help in avoiding compiler
+ warnings.*/
+ if( (strlen(operands->filename)>0) + !(isnan(operands->number))
+ + (operands->array!=NOOPTARRAY) != 1)
+ error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we can fix the "
+ "problem. For some reason, one node in the operands linked list "
+ "has more than one value.", PACKAGE_BUGREPORT);
+
+
+ /* Set the array output. If filename is present then read the file
+ and fill in the array, if not then just set the array. */
+ if(strlen(operands->filename))
+ {
+ hdu=operands->hdu;
+ filename=operands->filename;
+
+ /* In case this is the first image that is read, then read the
+ WCS information and set the mask name so masked pixels can be
+ set to NaN. For the other images, the mask can be completely
+ ignored. */
+ if(p->popcounter) /* This is not the first FITS file. */
+ {
+ maskname=NULL;
+ mhdu=NULL;
+ }
+ else
+ {
+ mhdu=up->mhdu;
+ maskname=up->maskname;
- readfitswcs(filename, hdu, 0, 0, &p->nwcs, &p->wcs);
++ gal_fitsarray_read_fits_wcs(filename, hdu, 0, 0, &p->nwcs,
++ &p->wcs);
+ }
- filetodouble(filename, maskname, hdu, mhdu, array, &bitpix,
- &p->anyblank, &s0, &s1);
++ gal_fitsarray_file_to_double(filename, maskname, hdu, mhdu,
++ array, &bitpix, &p->anyblank, &s0, &s1);
+
+ /* If the output size was not set yet, then set it. Otherwise,
+ make sure the size of this image is the same as the previous
+ images. */
+ if(p->s0==0 && p->s1==0)
+ {
+ p->s0=s0;
+ p->s1=s1;
+ }
+ else
+ {
+ if(p->s0!=s0 || p->s1!=s1)
+ error(EXIT_FAILURE, 0, "%s (hdu=%s): has size of %lu x %lu. "
+ "However, previous images had a size of %lu x %lu. All "
+ "the images must be the same size in order for "
+ "ImageArithmetic to work.", filename, hdu, s0, s1,
+ p->s0, p->s1);
+ }
+
+ /* Free the HDU string: */
+ free(hdu);
+
+ /* Set the bitpix of the output. */
+ if(bitpix==DOUBLE_IMG) p->obitpix=DOUBLE_IMG;
+
+ /* Add to the number of popped FITS images: */
+ ++p->popcounter;
+ }
+ else
+ *array=operands->array;
+
+ /* Set the number: */
+ *number=operands->number;
+
+ /* Remove this node from the queue. */
+ p->operands=operands->next;
+ free(operands);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/***************************************************************/
+/************* Operators *************/
+/***************************************************************/
+void
+sum(struct imgarithparams *p)
+{
+ size_t size;
+ char *operator="+";
+ double fnum, snum; /* First or second number. */
+ double *farr, *sarr; /* First or second array. */
+
+ /* Pop out the number of operands needed. */
+ pop_operand(p, &fnum, &farr, operator);
+ pop_operand(p, &snum, &sarr, operator);
+
+ /* Set the total number of pixels, note that we can't do this in the
+ definition of the variable because p->s0 and p->s1 will be set in
+ pop_operand for the first image. */
+ size=p->s0*p->s1;
+
+ /* Do the operation: */
+ if(farr && sarr) /* Both are arrays. */
+ {
+ /* Do the operation, note that the output is stored in the first
+ input. */
- dsumarrays(farr, sarr, size);
++ gal_arraymanip_dsum_arrays(farr, sarr, size);
+
+ /* Push the output onto the stack. */
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, farr);
+
+ /* Clean up. */
+ free(sarr);
+ }
+ else if(farr) /* Only the first is an array. */
+ {
- dsumconst(farr, size, snum);
++ gal_arraymanip_dsum_const(farr, size, snum);
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, farr);
+ }
+ else if(sarr) /* Only the first is an array. */
+ {
- dsumconst(sarr, size, fnum);
++ gal_arraymanip_dsum_const(sarr, size, fnum);
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, sarr);
+ }
+ else /* Both are numbers. */
+ add_operand(p, NOOPTFILENAME, fnum+snum, NOOPTARRAY);
+}
+
+
+
+
+
+void
+subtract(struct imgarithparams *p)
+{
+ size_t size;
+ char *operator="-";
+ double fnum, snum; /* First or second number. */
+ double *farr, *sarr; /* First or second array. */
+
+ /* Pop out the number of operands needed. */
+ pop_operand(p, &fnum, &farr, operator);
+ pop_operand(p, &snum, &sarr, operator);
+
+ /* Set the total number of pixels, note that we can't do this in the
+ definition of the variable because p->s0 and p->s1 will be set in
+ pop_operand for the first image. */
+ size=p->s0*p->s1;
+
+ /* Do the operation: */
+ if(farr && sarr) /* Both are arrays. */
+ {
+
+ /* Do the operation, note that the output is stored in the first
+ input. Also note that since the linked list is
+ first-in-first-out, the second operand should be put first
+ here. */
- dsubtractarrays(sarr, farr, size);
++ gal_arraymanip_dsubtract_arrays(sarr, farr, size);
+
+ /* Push the output onto the stack. */
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, sarr);
+
+ /* Clean up. */
+ free(farr);
+ }
+ else if(farr) /* Only the first is an array. */
+ {
- dconstsubtract(farr, size, snum);
++ gal_arraymanip_dconst_subtract(farr, size, snum);
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, farr);
+ }
+ else if(sarr) /* Only the first is an array. */
+ {
- dsubtractconst(sarr, size, fnum);
++ gal_arraymanip_dsubtract_const(sarr, size, fnum);
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, sarr);
+ }
+ else /* Both are numbers. */
+ add_operand(p, NOOPTFILENAME, snum-fnum, NOOPTARRAY);
+}
+
+
+
+
+
+void
+multiply(struct imgarithparams *p)
+{
+ size_t size;
+ char *operator="*";
+ double fnum, snum; /* First or second number. */
+ double *farr, *sarr; /* First or second array. */
+
+ /* Pop out the number of operands needed. */
+ pop_operand(p, &fnum, &farr, operator);
+ pop_operand(p, &snum, &sarr, operator);
+
+ /* Set the total number of pixels, note that we can't do this in the
+ definition of the variable because p->s0 and p->s1 will be set in
+ pop_operand for the first image. */
+ size=p->s0*p->s1;
+
+ /* Do the operation: */
+ if(farr && sarr) /* Both are arrays. */
+ {
+ /* Do the operation, note that the output is stored in farr. */
- dmultiparrays(farr, sarr, size);
++ gal_arraymanip_dmultip_arrays(farr, sarr, size);
+
+ /* Push the output onto the stack. */
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, farr);
+
+ /* Clean up. */
+ free(sarr);
+ }
+ else if(farr) /* Only the first is an array. */
+ {
- dmultipconst(farr, size, snum);
++ gal_arraymanip_dmultip_const(farr, size, snum);
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, farr);
+ }
+ else if(sarr) /* Only the first is an array. */
+ {
- dmultipconst(sarr, size, fnum);
++ gal_arraymanip_dmultip_const(sarr, size, fnum);
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, sarr);
+ }
+ else /* Both are numbers. */
+ add_operand(p, NOOPTFILENAME, fnum*snum, NOOPTARRAY);
+}
+
+
+
+
+
+void
+divide(struct imgarithparams *p)
+{
+ size_t size;
+ char *operator="/";
+ double fnum, snum; /* First or second number. */
+ double *farr, *sarr; /* First or second array. */
+
+ /* Pop out the number of operands needed. */
+ pop_operand(p, &fnum, &farr, operator);
+ pop_operand(p, &snum, &sarr, operator);
+
+ /* Set the total number of pixels, note that we can't do this in the
+ definition of the variable because p->s0 and p->s1 will be set in
+ pop_operand for the first image. */
+ size=p->s0*p->s1;
+
+ /* Do the operation: */
+ if(farr && sarr) /* Both are arrays. */
+ {
+ /* Do the operation, note that the output is stored in the first
+ input. Also note that since the linked list is
+ first-in-first-out, the second operand should be put first
+ here. */
- ddividearrays(sarr, farr, size);
++ gal_arraymanip_ddivide_arrays(sarr, farr, size);
+
+ /* Push the output onto the stack. */
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, sarr);
+
+ /* Clean up. */
+ free(farr);
+ }
+ else if(farr) /* Only the first is an array. */
+ {
- dconstdivide(farr, size, snum);
++ gal_arraymanip_dconst_divide(farr, size, snum);
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, farr);
+ }
+ else if(sarr) /* Only the first is an array. */
+ {
- ddivideconst(sarr, size, fnum);
++ gal_arraymanip_ddivide_const(sarr, size, fnum);
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, sarr);
+ }
+ else /* Both are numbers. */
+ add_operand(p, NOOPTFILENAME, snum/fnum, NOOPTARRAY);
+}
+
+
+
+
+
+void
+topower(struct imgarithparams *p, char *op)
+{
+ size_t size;
+ char *operator = op?op:"pow";
+ double fnum, snum; /* First or second number. */
+ double *farr, *sarr; /* First or second array. */
+
+ /* Pop out the number of operands needed. */
+ pop_operand(p, &fnum, &farr, operator);
+ pop_operand(p, &snum, &sarr, operator);
+
+ /* Set the total number of pixels, note that we can't do this in the
+ definition of the variable because p->s0 and p->s1 will be set in
+ pop_operand for the first image. */
+ size=p->s0*p->s1;
+
+ /* Do the operation: */
+ if(farr && sarr) /* Both are arrays. */
+ {
+
+ /* Do the operation, note that the output is stored in the first
+ input. Also note that since the linked list is
+ first-in-first-out, the second operand should be put first
+ here. */
- dpowerarrays(sarr, farr, size);
++ gal_arraymanip_dpower_arrays(sarr, farr, size);
+
+ /* Push the output onto the stack. */
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, sarr);
+
+
+ /* Clean up. */
+ free(farr);
+ }
+ else if(farr) /* Only the first is an array. */
+ {
- dconstpower(farr, size, snum);
++ gal_arraymanip_dconst_power(farr, size, snum);
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, farr);
+ }
+ else if(sarr) /* Only the first is an array. */
+ {
- dpowerconst(sarr, size, fnum);
++ gal_arraymanip_dpower_const(sarr, size, fnum);
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, sarr);
+ }
+ else /* Both are numbers. */
+ add_operand(p, NOOPTFILENAME, pow(snum, fnum), NOOPTARRAY);
+}
+
+
+
+
+
+void
+alloppixs(struct imgarithparams *p, char *operator)
+{
+ int i, j; /* Integer to allow negative checks. */
+ double num; /* Temporary number holder. */
+ double *arr; /* Temporary array holder. */
+ int firstisarray=-1; /* ==-1: unset. ==1: array. ==0: number. */
+ double *allpixels=NULL; /* Array for all values in one pixel. */
+ double **allarrays=NULL; /* Array for pointers to input arrays. */
+ size_t size, numop=num_operands(p);
+ double (*thisfunction)(double *, size_t)=NULL;
+
+
+ /* First set the appropriate function to call. */
+ if(!strcmp(operator, "min"))
- thisfunction = &doublemin_r;
++ thisfunction = &gal_statistics_double_min_return;
+ else if(!strcmp(operator, "max"))
- thisfunction = &doublemax_r;
++ thisfunction = &gal_statistics_double_max_return;
+ else if(!strcmp(operator, "median"))
- thisfunction = &mediandoubleinplace;
++ thisfunction = &gal_statistics_median_double_in_place;
+ else if(!strcmp(operator, "average"))
- thisfunction = &doubleaverage;
++ thisfunction = &gal_statistics_double_average;
+ else
+ error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we "
+ "can address the problem. The value of `operator' in "
+ "alloppixs (%s) is not recognized.",
+ PACKAGE_BUGREPORT, operator);
+
+
+ /* Allocate the array of pointers to all input arrays and also the
+ array to temporarily keep all values for each pixel */
+ errno=0;
+ allarrays=malloc(numop*sizeof *allarrays);
+ if(allarrays==NULL)
+ error(EXIT_FAILURE, errno, "%lu bytes for allarrays in alloppixs.",
+ numop*sizeof *allarrays);
+ errno=0;
+ allpixels=malloc(numop*sizeof *allpixels);
+ if(allpixels==NULL)
+ error(EXIT_FAILURE, errno, "%lu bytes for allpixels in alloppixs.",
+ numop*sizeof *allpixels);
+
+
+ /* Prepare all the inputs, note that since it is a linked list, the
+ operands pop from the last to first. Here order is not important,
+ but in other cases that it might be (and also for debugging),
+ here the inputs are put in order so the indexs start from the
+ last to first. */
+ for(i=numop-1;i>=0;--i)
+ {
+ /* Pop out the operand. */
+ pop_operand(p, &num, &arr, operator);
+
+ /* Do the appropriate action if it is an array or a number. */
+ if(arr)
+ switch(firstisarray)
+ {
+ case -1:
+ firstisarray=1;
+ allarrays[i]=arr;
+ break;
+ case 1:
+ allarrays[i]=arr;
+ break;
+ case 0:
+ error(EXIT_FAILURE, 0, "For the %s operator, all operands "
+ "must be either an array or number.", operator);
+ break;
+ default:
+ error(EXIT_FAILURE, 0, "A Bug! Please contact us at %s so we "
+ "can address the problem. The value of firstisarray (%d) "
+ "in the alloppixs function is not recognized.",
+ PACKAGE_BUGREPORT, firstisarray);
+ }
+ else
+ switch(firstisarray)
+ {
+ case -1:
+ firstisarray=0;
+ allpixels[i]=num;
+ break;
+ case 0:
+ allpixels[i]=num;
+ break;
+ case 1:
+ error(EXIT_FAILURE, 0, "For the %s operator, all operands "
+ "must be either an array or number.", operator);
+ break;
+ default:
+ error(EXIT_FAILURE, 0, "A Bug! Please contact us at %s so we "
+ "can address the problem. The value of firstisarray (%d) "
+ "in the alloppixs function is not recognized.",
+ PACKAGE_BUGREPORT, firstisarray);
+ }
+ }
+
+
+ /* Set the total number of pixels, note that we can't do this in the
+ definition of the variable because p->s0 and p->s1 will be set in
+ pop_operand for the first image. */
+ size=p->s0*p->s1;
+
+
+ /* Do the operation and report the result: */
+ if(arr)
+ {
+ /* Find the value and replace it with the first operand. */
+ for(i=0;i<size;++i)
+ {
+ /* Go over all the inputs and put the appropriate pixel
+ values in the allpixels array. */
+ for(j=0;j<numop;++j)
+ allpixels[j]=allarrays[j][i];
+
+ /* Do the appropriate action. */
+ allarrays[0][i]=(*thisfunction)(allpixels, numop);
+ }
+
+ /* Push the output onto the stack. */
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, allarrays[0]);
+
+ /* Free all the extra operands */
+ for(i=1;i<numop;++i) free(allarrays[i]);
+ }
+ else
+ add_operand(p, NOOPTFILENAME, (*thisfunction)(allpixels, numop),
+ NOOPTARRAY);
+
+ /* Clean up: */
+ free(allarrays);
+ free(allpixels);
+}
+
+
+
+
+
+void
+takesqrt(struct imgarithparams *p)
+{
+ char *operator="sqrt";
+
+ /* Add a 0.5 number to the operand stack */
+ add_operand(p, NOOPTFILENAME, 0.5f, NOOPTARRAY);
+
+ /* Call the power operator. */
+ topower(p, operator);
+}
+
+
+
+
+
+void
+takelog(struct imgarithparams *p)
+{
+ char *operator="log";
+ double fnum, *farr;
+
+ /* Pop out the number of operands needed. */
+ pop_operand(p, &fnum, &farr, operator);
+
+ /* Do the operation: */
+ if(farr) /* Operand is array. */
+ {
+ /* Do the operation, note that the output is stored in the first
+ input. Also note that since the linked list is
+ first-in-first-out, the second operand should be put first
+ here. */
- dlogarray(farr, p->s0*p->s1);
++ gal_arraymanip_dlog_array(farr, p->s0*p->s1);
+
+ /* Push the output onto the stack. */
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, farr);
+ }
+ else /* Operand is a number. */
+ add_operand(p, NOOPTFILENAME, log(fnum), NOOPTARRAY);
+}
+
+
+
+
+
+void
+takelog10(struct imgarithparams *p)
+{
+ char *operator="log10";
+ double fnum, *farr;
+
+ /* Pop out the number of operands needed. */
+ pop_operand(p, &fnum, &farr, operator);
+
+ /* Do the operation: */
+ if(farr) /* Operand is array. */
+ {
+ /* Do the operation, note that the output is stored in the first
+ input. Also note that since the linked list is
+ first-in-first-out, the second operand should be put first
+ here. */
- dlog10array(farr, p->s0*p->s1);
++ gal_arraymanip_dlog10_array(farr, p->s0*p->s1);
+
+ /* Push the output onto the stack. */
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, farr);
+ }
+ else /* Operand is a number. */
+ add_operand(p, NOOPTFILENAME, log10(fnum), NOOPTARRAY);
+}
+
+
+
+
+
+void
+takeabs(struct imgarithparams *p)
+{
+ char *operator="abs";
+ double fnum, *farr;
+
+ /* Pop out the number of operands needed. */
+ pop_operand(p, &fnum, &farr, operator);
+
+ /* Do the operation: */
+ if(farr) /* Operand is array. */
+ {
+ /* Do the operation, note that the output is stored in the first
+ input. Also note that since the linked list is
+ first-in-first-out, the second operand should be put first
+ here. */
- dabsarray(farr, p->s0*p->s1);
++ gal_arraymanip_dabs_array(farr, p->s0*p->s1);
+
+ /* Push the output onto the stack. */
+ add_operand(p, NOOPTFILENAME, NOOPTNUMBER, farr);
+ }
+ else /* Operand is a number. */
+ add_operand(p, NOOPTFILENAME, fabs(fnum), NOOPTARRAY);
+}
+
+
+
+
+
+void
+findmin(struct imgarithparams *p)
+{
+ char *operator="min";
+ double min, fnum, *farr;
+
+ /* Pop out the number of operands needed. */
+ pop_operand(p, &fnum, &farr, operator);
+
+ /* Do the operation: */
+ if(farr) /* Operand is array. */
+ {
+ /* Do the operation, note that the output is stored in the first
+ input. Also note that since the linked list is
+ first-in-first-out, the second operand should be put first
+ here. */
- doublemin(farr, p->s0*p->s1, &min);
++ gal_statistics_double_min(farr, p->s0*p->s1, &min);
+
+ /* Push the output onto the stack. */
+ add_operand(p, NOOPTFILENAME, min, NOOPTARRAY);
+
+ /* Clean up. */
+ free(farr);
+ }
+ else /* Operand is a number. */
+ add_operand(p, NOOPTFILENAME, fnum, NOOPTARRAY);
+}
+
+
+
+
+
+void
+findmax(struct imgarithparams *p)
+{
+ char *operator="max";
+ double max, fnum, *farr;
+
+ /* Pop out the number of operands needed. */
+ pop_operand(p, &fnum, &farr, operator);
+
+ /* Do the operation: */
+ if(farr) /* Operand is array. */
+ {
+ /* Do the operation, note that the output is stored in the first
+ input. Also note that since the linked list is
+ first-in-first-out, the second operand should be put first
+ here. */
- doublemax(farr, p->s0*p->s1, &max);
++ gal_statistics_double_max(farr, p->s0*p->s1, &max);
+
+ /* Push the output onto the stack. */
+ add_operand(p, NOOPTFILENAME, max, NOOPTARRAY);
+
+ /* Clean up. */
+ free(farr);
+ }
+ else /* Operand is a number. */
+ add_operand(p, NOOPTFILENAME, fnum, NOOPTARRAY);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/***************************************************************/
+/************* Reverse Polish algorithm *************/
+/***************************************************************/
+/* This function implements the reverse polish algorithm as explained
+ in the Wikipedia page.
+
+ NOTE that in ui.c, the input linked list of tokens was ordered to
+ have the same order as what the user provided. */
+void
+reversepolish(struct imgarithparams *p)
+{
+ float *farray;
+ double number;
+ char *tokeepvalue;
- struct stll *token;
++ struct gal_linkedlist_stll *token;
+
+ /* Prepare the processing: */
+ p->s0=p->s1=0;
+ p->operands=NULL;
+ p->obitpix=FLOAT_IMG;
+ p->addcounter=p->popcounter=0;
+
+ /* Go over each input token and do the work. */
+ for(token=p->tokens;token!=NULL;token=token->next)
+ {
+ /* 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(nameisfits(token->v))
++ if(gal_fitsarray_name_is_fits(token->v))
+ add_operand(p, token->v, NOOPTNUMBER, NOOPTARRAY);
+ else if(strisdouble(token->v, &number))
+ add_operand(p, NOOPTFILENAME, number, NOOPTARRAY);
+ else
+ {
+ if (!strcmp(token->v, "+")) sum(p);
+ else if(!strcmp(token->v, "-")) subtract(p);
+ else if(!strcmp(token->v, "*")) multiply(p);
+ else if(!strcmp(token->v, "/")) divide(p);
+ else if(!strcmp(token->v, "abs")) takeabs(p);
+ else if(!strcmp(token->v, "pow")) topower(p, NULL);
+ else if(!strcmp(token->v, "sqrt")) takesqrt(p);
+ else if(!strcmp(token->v, "log")) takelog(p);
+ else if(!strcmp(token->v, "log10")) takelog10(p);
+ else if(!strcmp(token->v, "minvalue"))findmin(p);
+ else if(!strcmp(token->v, "maxvalue"))findmax(p);
+ else if(!strcmp(token->v, "min")
+ || !strcmp(token->v, "max")
+ || !strcmp(token->v, "average")
+ || !strcmp(token->v, "median")) alloppixs(p, token->v);
+ else
+ error(EXIT_FAILURE, 0, "The argument \"%s\" could not be "
+ "interpretted as an operator.", token->v);
+ }
+ }
+
+ /* If there is more than one node in the operands stack, then the
+ user has given too many operands and there is an error. */
+ if(p->operands->next!=NULL)
+ error(EXIT_FAILURE, 0, "There are too many operands for the operators "
+ "in the given expression.");
+
+
+ /* If the remaining operand is an array then save the array as a
+ FITS image, if not, simply print the floating point number. */
+ if(p->operands->array)
+ {
+ /* If none of the inputs had a double type, then convert the
+ output array into a float and then save it. Note that the
+ last operand must be an array. */
+ if(p->obitpix==FLOAT_IMG)
+ {
- changetype(p->operands->array, DOUBLE_IMG, p->s0*p->s1,
- p->anyblank, (void **)(&farray), FLOAT_IMG);
- arraytofitsimg(p->cp.output, "astimgarith", FLOAT_IMG, farray,
- p->s0, p->s1, p->anyblank, p->wcs, NULL,
- SPACK_STRING);
++ gal_fitsarray_change_type(p->operands->array, DOUBLE_IMG,
++ p->s0*p->s1, p->anyblank,
++ (void **)(&farray), FLOAT_IMG);
++ gal_fitsarray_array_to_fits_img(p->cp.output, "astimgarith",
++ FLOAT_IMG, farray, p->s0, p->s1,
++ p->anyblank, p->wcs, NULL,
++ SPACK_STRING);
+ }
+ else
- arraytofitsimg(p->cp.output, "astimgarith", DOUBLE_IMG,
- p->operands->array, p->s0, p->s1, p->anyblank,
- p->wcs, NULL, SPACK_STRING);
++ gal_fitsarray_array_to_fits_img(p->cp.output, "astimgarith",
++ DOUBLE_IMG, p->operands->array,
++ p->s0, p->s1, p->anyblank,
++ p->wcs, NULL, SPACK_STRING);
+ }
+ else
+ printf("%g\n", p->operands->number);
+
+
+ /* If there are any remaining HDUs in the hdus linked list, then
+ free them. */
+ while(p->hdus!=NULL)
+ {
- pop_from_stll(&p->hdus, &tokeepvalue);
++ gal_linkedlist_pop_from_stll(&p->hdus, &tokeepvalue);
+ free(tokeepvalue);
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/***************************************************************/
+/************* Top function *************/
+/***************************************************************/
+void
+imgarith(struct imgarithparams *p)
+{
+ reversepolish(p);
+}
diff --cc src/arithmetic/cite.h
index 425d1a2,c57984c..90e961c
--- a/src/arithmetic/cite.h
+++ b/src/arithmetic/cite.h
@@@ -1,6 -1,6 +1,6 @@@
/*********************************************************************
- ImageArithmetic - Do arithmetic operations on images.
- ImageArithmetic is part of GNU Astronomy Utilities (Gnuastro) package.
-ImageCrop - Crop a given size from one or multiple images.
-ImageCrop is part of GNU Astronomy Utilities (Gnuastro) package.
++Arithmetic - Do arithmetic operations on images.
++Arithmetic is part of GNU Astronomy Utilities (Gnuastro) package.
Original author:
Mohammad Akhlaghi <address@hidden>
@@@ -23,15 -23,15 +23,15 @@@ along with Gnuastro. If not, see <http:
#ifndef CITE_H
#define CITE_H
- #define HEADERBIBTEX ""
-#define IMGCROPBIBTEX ""
++#define ARITHMETICBIBTEX ""
#define PRINTCITEABORT { \
printf("\nWe hope %s has been useful for your research.\n"
\
"Citations are vital for the continued work on %s.\n" \
"Thank you for citing it in your research paper.\n" \
"\nPlease cite as \"%s\":\n\n%s\n\n%s", \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GNUASTROBIBTEX, \
- HEADERBIBTEX); \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GAL_STRINGS_BIBTEX, \
- IMGCROPBIBTEX); \
++ SPACK_NAME, SPACK_NAME, SPACK_STRING, \
++ GAL_STRINGS_MAIN_BIBTEX, ARITHMETICBIBTEX);
\
exit(EXIT_SUCCESS);
\
}
diff --cc src/arithmetic/main.h
index ca57963,0000000..9faa66a
mode 100644,000000..100644
--- a/src/arithmetic/main.h
+++ b/src/arithmetic/main.h
@@@ -1,111 -1,0 +1,111 @@@
+/*********************************************************************
+ImageArithmetic - Do arithmetic operations on images.
+ImageArithmetic is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+ Mohammad Akhlaghi <address@hidden>
+Contributing author(s):
+Copyright (C) 2015, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#ifndef MAIN_H
+#define MAIN_H
+
+#include "linkedlist.h"
+#include "fitsarrayvv.h"
+#include "commonparams.h"
+
+/* Progarm name macros: */
+#define SPACK "astarithmetic" /* Subpackage executable name. */
+#define SPACK_NAME "Arithmetic" /* Subpackage full name. */
+#define SPACK_STRING SPACK_NAME" ("PACKAGE_NAME") "PACKAGE_VERSION
+
+
+/* Do not use the main commonargs.h option reader for the --hdu
+ option. */
+#define NOTCOMMONHDU 1
+
+
+/* Constants: */
+#define NEGDASHREPLACE 11 /* A vertical tab (ASCII=11) for negative dash */
+#define NOOPTARRAY NULL
+#define NOOPTNUMBER NAN
+#define NOOPTFILENAME ""
+
+
+/* The operands can be in three ways:
+
+ 1. A file name which is not read yet. When inactive, NOOPTFILENAME.
+ 2. A number which is not used yet. When inactive, NOOPTNUMBER.
+ 3. An array (operator output). When inactive, NOOPTARRAY.
+
+ In every node of the operand linked list, only one of these should
+ be active. The other two should be inactive. Otherwise it will be a
+ bug and will cause problems. All the operands operate on this
+ premise.
+*/
+struct operand
+{
+ char *filename;
+ char *hdu;
+ double number;
+ double *array;
+ struct operand *next;
+};
+
+
+struct uiparams
+{
+ char *maskname; /* Name of mask image. */
+ char *mhdu; /* Mask image HDU. */
+
+ int masknameset;
+ int masknameallocated;
+ int mhduset;
+};
+
+
+struct imgarithparams
+{
+ /* Other structures: */
- struct uiparams up; /* User interface parameters. */
- struct commonparams cp; /* Common parameters. */
++ struct uiparams up; /* User interface parameters. */
++ struct gal_commonparams cp; /* Common parameters. */
+
+ /* Input: */
- struct stll *hdus; /* String linked list for given HDUs. */
- struct stll *tokens; /* Tokens to do arithmetic. */
++ struct gal_linkedlist_stll *hdus; /* List of all given HDU strings. */
++ struct gal_linkedlist_stll *tokens; /* List of all arithmetic tokens. */
+ float *array; /* Main array to keep results. */
+ float *tmp; /* Secondary array for temporary reading. */
+ size_t numfits; /* Total number of input FITS images. */
+ size_t addcounter; /* The number of FITS images added. */
+ size_t popcounter; /* The number of FITS images popped. */
+ size_t s0; /* Length of image along first C axis. */
+ size_t s1; /* Length of image along second C axis. */
+ int obitpix; /* The type of the output image. */
+ int nwcs; /* The number of WCS coordinates. */
+ struct wcsprm *wcs; /* The WCS structure. */
+ int anyblank; /* If there are blank pixels in the image. */
+
+ /* Output: */
+
+
+ /* Operating mode: */
+
+ /* Internal: */
+ struct operand *operands; /* The operands linked list. */
+ time_t rawtime; /* Starting time of the program. */
+};
+
+#endif
diff --cc src/arithmetic/ui.c
index bc67249,0000000..7d16c5c
mode 100644,000000..100644
--- a/src/arithmetic/ui.c
+++ b/src/arithmetic/ui.c
@@@ -1,380 -1,0 +1,383 @@@
+/*********************************************************************
+ImageArithmetic - Do arithmetic operations on images.
+ImageArithmetic is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+ Mohammad Akhlaghi <address@hidden>
+Contributing author(s):
+Copyright (C) 2015, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#include <config.h>
+
+#include <math.h>
+#include <stdio.h>
+#include <errno.h>
+#include <error.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fitsio.h>
+
+#include <nproc.h> /* From Gnulib. */
+
+#include "timing.h" /* Includes time.h and sys/time.h */
+#include "checkset.h"
+#include "commonargs.h"
+#include "configfiles.h"
+#include "fitsarrayvv.h"
+#include "fixedstringmacros.h"
+
+#include "main.h"
+
+#include "ui.h" /* Needs main.h */
+#include "args.h" /* Needs main.h, includes argp.h. */
+
+
+/* Set the file names of the places where the default parameters are
+ put. */
+#define CONFIG_FILE SPACK CONF_POSTFIX
+#define SYSCONFIG_FILE SYSCONFIG_DIR "/" CONFIG_FILE
+#define USERCONFIG_FILEEND USERCONFIG_DIR CONFIG_FILE
+#define CURDIRCONFIG_FILE CURDIRCONFIG_DIR CONFIG_FILE
+
+
+
+
+
+
+
+
+
+
+/**************************************************************/
+/************** Options and parameters ***************/
+/**************************************************************/
+void
+readconfig(char *filename, struct imgarithparams *p)
+{
+ FILE *fp;
+ char *tokeephdu;
+ size_t lineno=0, len=200;
+ char *line, *name, *value;
+ struct uiparams *up=&p->up;
- struct commonparams *cp=&p->cp;
++ struct gal_commonparams *cp=&p->cp;
+ char key='a'; /* Not used, just a place holder. */
+
+ /* When the file doesn't exist or can't be opened, it is ignored. It
+ might be intentional, so there is no error. If a parameter is
+ missing, it will be reported after all defaults are read. */
+ fp=fopen(filename, "r");
+ if (fp==NULL) return;
+
+
+ /* Allocate some space for `line` with `len` elements so it can
+ easily be freed later on. The value of `len` is arbitarary at
+ this point, during the run, getline will change it along with the
+ pointer to line. */
+ errno=0;
+ line=malloc(len*sizeof *line);
+ if(line==NULL)
+ error(EXIT_FAILURE, errno, "ui.c: %lu bytes in readdefaults",
+ len * sizeof *line);
+
+ /* Read the tokens in the file: */
+ while(getline(&line, &len, fp) != -1)
+ {
+ /* Prepare the "name" and "value" strings, also set lineno. */
- STARTREADINGLINE;
++ GAL_CONFIGFILES_START_READING_LINE;
+
+
+
+ /* Inputs: */
+ if(strcmp(name, "hdu")==0)
+ {
- allocatecopy(value, &tokeephdu);
- add_to_stll(&p->hdus, tokeephdu);
++ gal_checkset_allocate_copy(value, &tokeephdu);
++ gal_linkedlist_add_to_stll(&p->hdus, tokeephdu);
+ }
+
+ else if (strcmp(name, "mask")==0)
- allocatecopyset(value, &up->maskname, &up->masknameset);
++ gal_checkset_allocate_copy_set(value, &up->maskname,
++ &up->masknameset);
+
+ else if (strcmp(name, "mhdu")==0)
- allocatecopyset(value, &up->mhdu, &up->mhduset);
++ gal_checkset_allocate_copy_set(value, &up->mhdu, &up->mhduset);
+
+
+
+
+
+ /* Outputs */
+ else if(strcmp(name, "output")==0)
- allocatecopyset(value, &cp->output, &cp->outputset);
++ gal_checkset_allocate_copy_set(value, &cp->output, &cp->outputset);
+
+
+ /* Operating modes: */
+ /* Read options common to all programs */
- READ_COMMONOPTIONS_FROM_CONF
++ GAL_CONFIGFILES_READ_COMMONOPTIONS_FROM_CONF
+
+
+ else
+ error_at_line(EXIT_FAILURE, 0, filename, lineno,
+ "`%s` not recognized.\n", name);
+ }
+
+ free(line);
+ fclose(fp);
+}
+
+
+
+
+
+void
+printvalues(FILE *fp, struct imgarithparams *p)
+{
- struct stll *hdu;
+ struct uiparams *up=&p->up;
- struct commonparams *cp=&p->cp;
++ struct gal_linkedlist_stll *hdu;
++ struct gal_commonparams *cp=&p->cp;
+
+ /* Print all the options that are set. Separate each group with a
+ commented line explaining the options in that group. */
+ fprintf(fp, "\n# Input image(s):\n");
+
+ /* The order of the HDU linked list has already been corrected, so
+ just print them as they were read in. */
+ for(hdu=p->hdus; hdu!=NULL; hdu=hdu->next)
- PRINTSTINGMAYBEWITHSPACE("hdu", hdu->v);
++ GAL_CHECKSET_PRINT_STRING_MAYBE_WITH_SPACE("hdu", hdu->v);
+
+ if(up->masknameset)
- PRINTSTINGMAYBEWITHSPACE("mask", up->maskname);
++ GAL_CHECKSET_PRINT_STRING_MAYBE_WITH_SPACE("mask", up->maskname);
+ if(up->mhdu)
- PRINTSTINGMAYBEWITHSPACE("mhdu", up->mhdu);
++ GAL_CHECKSET_PRINT_STRING_MAYBE_WITH_SPACE("mhdu", up->mhdu);
+
+ /* Output: */
+ fprintf(fp, "\n# Output:\n");
+ if(cp->outputset)
+ fprintf(fp, CONF_SHOWFMT"%s\n", "output", cp->output);
+
+
+ /* For the operating mode, first put the macro to print the common
+ options, then the (possible options particular to this
+ program). */
+ fprintf(fp, "\n# Operating mode:\n");
- PRINT_COMMONOPTIONS;
++ GAL_CONFIGFILES_PRINT_COMMONOPTIONS;
+}
+
+
+
+
+
+
+/* Note that numthreads will be used automatically based on the
+ configure time. Note that those options which are not mandatory
+ must not be listed here. */
+void
+checkifset(struct imgarithparams *p)
+{
+ int intro=0;
+ char comment[100];
- size_t numhdus=numinstll(p->hdus);
++ size_t numhdus=gal_linkedlist_num_in_stll(p->hdus);
+
+ /* Make sure the number of HDUs is not less than the total number of
+ FITS images. If there are more HDUs than there are FITS images,
+ there is no problem (since they can come from the configuration
+ files). It is expected that the user can call their own desired
+ number of HDUs, and not rely on the configuration files too much,
+ however, if the configuration file does contain some HDUs, then
+ it will be a real pain to first clean the configuration file and
+ then re-run arithmetic. The best way is to simply ignore them. */
+ if(numhdus<p->numfits)
+ {
+ sprintf(comment, "hdu (%lu FITS file(s), %lu HDUs)",
+ p->numfits, numhdus);
- REPORT_NOTSET(comment);
++ GAL_CONFIGFILES_REPORT_NOTSET(comment);
+ }
+
+ /* Report the (possibly) missing options. */
- END_OF_NOTSET_REPORT;
++ GAL_CONFIGFILES_END_OF_NOTSET_REPORT;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**************************************************************/
+/*************** Sanity Check *******************/
+/**************************************************************/
+
+/* The dash of a negative number will cause problems for the users,
+ so to work properly we will go over all the options/arguments and
+ if any one starts with a dash and is followed by a number, then
+ the dash is replaced by NEGDASHREPLACE. */
+void
+dashtonegchar(int argc, char *argv[])
+{
+ size_t i;
+ for(i=0;i<argc;++i)
+ if(argv[i][0]=='-' && isdigit(argv[i][1]))
+ argv[i][0]=NEGDASHREPLACE;
+}
+
+
+
+
+
+/* Return the negative character back to the dash (to be read as a
+ number in imgarith.c). When the token is not a FITS file name and
+ since no operators or numbers begin with NEGDASHREPLACE, so if the
+ token starts with NEGDASHREPLACE and its next character is a digit,
+ it must be a negative number. If not, it is either an ordinary
+ number or an operator.*/
+void
+negchartodashcountfits(struct imgarithparams *p)
+{
- struct stll *token;
++ struct gal_linkedlist_stll *token;
+
+ /* Initialize the numfits variable (just incase!) */
+ p->numfits=0;
+
+ /* Go through all the tokens and do the job(s). */
+ for(token=p->tokens; token!=NULL; token=token->next)
+ {
- if(nameisfits(token->v))
++ if(gal_fitsarray_name_is_fits(token->v))
+ ++p->numfits;
+ else if(token->v[0]==NEGDASHREPLACE && isdigit(token->v[1]) )
+ token->v[0]='-';
+ }
+}
+
+
+
+
+
+/* Standard sanity checks. */
+void
+sanitycheck(struct imgarithparams *p)
+{
- struct stll *token;
++ struct gal_linkedlist_stll *token;
+
+ /* Set the output file name (if any is needed). Note that since the
+ lists are already reversed, the first FITS file encountered, is
+ the first FITS file given by teh user. Also, notet that these
+ file name operations are only necessary for the first FITS file
+ in the token list. */
+ for(token=p->tokens; token!=NULL; token=token->next)
- if(nameisfits(token->v))
++ if(gal_fitsarray_name_is_fits(token->v))
+ {
+ /* Set the p->up.maskname accordingly: */
- fileorextname(token->v, p->cp.hdu, p->up.masknameset,
- &p->up.maskname, p->up.mhdu, p->up.mhduset, "mask");
++ gal_fitsarray_file_or_ext_name(token->v, p->cp.hdu,
++ p->up.masknameset, &p->up.maskname,
++ p->up.mhdu, p->up.mhduset, "mask");
+
+ /* Set the name of the output file: */
+ if(p->cp.outputset)
- checkremovefile(p->cp.output, p->cp.dontdelete);
++ gal_checkset_check_remove_file(p->cp.output, p->cp.dontdelete);
+ else
- automaticoutput(token->v, "_arith.fits", p->cp.removedirinfo,
- p->cp.dontdelete, &p->cp.output);
++ gal_checkset_automatic_output(token->v, "_arith.fits",
++ p->cp.removedirinfo,
++ p->cp.dontdelete, &p->cp.output);
+
+ /* These were only necessary for the first FITS file in the
+ tokens, so break out of the loop. */
+ break;
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**************************************************************/
+/************ Set the parameters *************/
+/**************************************************************/
+void
+setparams(int argc, char *argv[], struct imgarithparams *p)
+{
- struct commonparams *cp=&p->cp;
++ struct gal_commonparams *cp=&p->cp;
+
+ /* Set the non-zero initial values, the structure was initialized to
+ have a zero value for all elements. */
+ cp->spack = SPACK;
+ cp->verb = 1;
+ cp->numthreads = num_processors(NPROC_CURRENT);
+ cp->removedirinfo = 1;
+
+ p->hdus = NULL;
+ p->tokens = NULL;
+ p->up.maskname = NULL;
+
+ /* The hyphen of a negative number can be confused with a dash, so
+ we will temporarily replace such hyphens with other
+ characters. */
+ dashtonegchar(argc, argv);
+
+ /* Read the arguments. */
+ errno=0;
+ if(argp_parse(&thisargp, argc, argv, 0, 0, p))
+ error(EXIT_FAILURE, errno, "Parsing arguments");
+
+ /* Revert the conversion of the hyphen above back to the original
+ character. */
+ negchartodashcountfits(p);
+
+ /* Add the user default values and save them if asked. */
- CHECKSETCONFIG;
++ GAL_CONFIGFILES_CHECK_SET_CONFIG;
+
+ /* The inputs are put in a lastin-firstout (simple) linked list, so
+ change them to the correct order so the order we pop a node is
+ the same order that the user input a value. */
- reverse_stll(&p->hdus);
- reverse_stll(&p->tokens);
++ gal_linkedlist_reverse_stll(&p->hdus);
++ gal_linkedlist_reverse_stll(&p->tokens);
+
+ /* Check if all the required parameters are set. */
+ checkifset(p);
+
+ /* Print the values for each parameter. */
+ if(cp->printparams)
- REPORT_PARAMETERS_SET;
++ GAL_CONFIGFILES_REPORT_PARAMETERS_SET;
+
+ /* Do a sanity check. */
+ sanitycheck(p);
+}
diff --cc src/convertt/cite.h
index 92d8502,7b5701c..fa5054b
--- a/src/convertt/cite.h
+++ b/src/convertt/cite.h
@@@ -23,15 -23,15 +23,15 @@@ along with Gnuastro. If not, see <http:
#ifndef CITE_H
#define CITE_H
--#define MKPROFBIBTEX ""
++#define CONVERTTBIBTEX ""
#define PRINTCITEABORT { \
printf("\nWe hope %s has been useful for your research.\n"
\
"Citations are vital for the continued work on %s.\n" \
"Thank you for citing it in your research paper.\n" \
"\nPlease cite as \"%s\":\n\n%s\n\n%s", \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GNUASTROBIBTEX, \
- MKPROFBIBTEX); \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GAL_STRINGS_BIBTEX, \
- MKPROFBIBTEX); \
++ SPACK_NAME, SPACK_NAME, SPACK_STRING, \
++ GAL_STRINGS_MAIN_BIBTEX, CONVERTTBIBTEX); \
exit(EXIT_SUCCESS);
\
}
diff --cc src/convertt/eps.c
index 04b43c5,deb9e8e..eb3e415
--- a/src/convertt/eps.c
+++ b/src/convertt/eps.c
@@@ -353,15 -353,20 +353,15 @@@ saveepsorpdf(struct converttparams *p
/* EPS filename */
if(p->outputtype==EPSFORMAT)
- epsfilename=p->cp.output;
+ {
+ epsfilename=p->cp.output;
- checkremovefile(epsfilename, p->cp.dontdelete);
++ gal_checkset_check_remove_file(epsfilename, p->cp.dontdelete);
+ }
else if (p->outputtype==PDFFORMAT)
{
- checkremovefile(p->cp.output, p->cp.dontdelete);
- automaticoutput(p->cp.output, ".ps", 0, p->cp.dontdelete,
- &epsfilename);
- /* In ui.c we removed the output if it already existed, so it doesn't
- exist now. But gal_checkset_automatic_output is based on an input
- (which must exist), so temporarily make the file. */
- sprintf(command, "touch %s", p->cp.output);
- if(system(command))
- error(EXIT_FAILURE, 0, "The command `%s` could not be run!", command);
++ gal_checkset_check_remove_file(p->cp.output, p->cp.dontdelete);
+ gal_checkset_automatic_output(p->cp.output, ".ps", 0, p->cp.dontdelete,
- &epsfilename);
- sprintf(command, "rm %s", p->cp.output);
- if(system(command))
- error(EXIT_FAILURE, 0, "The command `%s` could not be run!", command);
++ &epsfilename);
}
else
error(EXIT_FAILURE, 0, "A bug! In `saveeps`, for outputtype is "
diff --cc src/convertt/main.h
index 28b2197,649ba04..03acac9
--- a/src/convertt/main.h
+++ b/src/convertt/main.h
@@@ -92,11 -93,11 +92,11 @@@ struct uiparam
struct converttparams
{
/* Before actual program: */
- struct commonparams cp; /* Common parameters. */
- struct uiparams up; /* User interface parameters. */
++ struct uiparams up; /* User interface parameters. */
+ struct gal_commonparams cp; /* Common parameters. */
- struct uiparams up; /* User interface parameters. */
/* Input: */
- struct stll *inputnames; /* The names of input files. */
+ struct gal_linkedlist_stll *inputnames; /* The names of input files. */
size_t numinputs; /* Number of input files. */
int inputtype; /* The type of the input file. */
diff --cc src/convertt/ui.c
index 208becc,0731eaa..0527abb
--- a/src/convertt/ui.c
+++ b/src/convertt/ui.c
@@@ -571,11 -570,8 +572,11 @@@ preparearrays(struct converttparams *p
"files) has exceeded 4! Note that one file can contain more "
"than one color channel.");
+ /* Make sure this input file exists (if it isn't blank). */
- if(strcmp(names[i], "blank")) checkfile(names[i]);
++ if(strcmp(names[i], "blank")) gal_checkset_check_file(names[i]);
+
/* FITS: */
- if( nameisfits(names[i]) )
+ if( gal_fitsarray_name_is_fits(names[i]) )
{
switch(p->numch) /* Get the HDU value for this channel. */
{
diff --cc src/convolve/cite.h
index 30421e0,d715a37..cb319f1
--- a/src/convolve/cite.h
+++ b/src/convolve/cite.h
@@@ -23,15 -23,15 +23,15 @@@ along with Gnuastro. If not, see <http:
#ifndef CITE_H
#define CITE_H
--#define MKPROFBIBTEX ""
++#define CONVOLVEBIBTEX ""
#define PRINTCITEABORT { \
printf("\nWe hope %s has been useful for your research.\n"
\
"Citations are vital for the continued work on %s.\n" \
"Thank you for citing it in your research paper.\n" \
"\nPlease cite as \"%s\":\n\n%s\n\n%s", \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GNUASTROBIBTEX, \
- MKPROFBIBTEX); \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GAL_STRINGS_BIBTEX, \
- MKPROFBIBTEX); \
++ SPACK_NAME, SPACK_NAME, SPACK_STRING, \
++ GAL_STRINGS_MAIN_BIBTEX, CONVOLVEBIBTEX); \
exit(EXIT_SUCCESS);
\
}
diff --cc src/convolve/ui.c
index de63e55,27082df..2c14bbe
--- a/src/convolve/ui.c
+++ b/src/convolve/ui.c
@@@ -345,12 -344,10 +346,13 @@@ sanitycheck(struct convolveparams *p
{
char *outsuffix = p->makekernel ? "_kernel.fits" : "_convolved.fits";
+ /* Make sure the input file exists. */
- checkfile(p->up.inputname);
++ gal_checkset_check_file(p->up.inputname);
+
/* Set maskname accordingly: */
- fileorextname(p->up.inputname, p->cp.hdu, p->up.masknameset,
- &p->up.maskname, p->up.mhdu, p->up.mhduset, "mask");
+ gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu,
p->up.masknameset,
+ &p->up.maskname, p->up.mhdu,
+ p->up.mhduset, "mask");
/* Check the output file name: */
if(p->cp.outputset)
diff --cc src/cosmiccal/args.h
index 41fa9ab,f9f945c..6db8d2a
--- a/src/cosmiccal/args.h
+++ b/src/cosmiccal/args.h
@@@ -46,10 -45,10 +46,10 @@@ along with Gnuastro. If not, see <http:
/* Definition parameters for the argp: */
- const char *argp_program_version=SPACK_STRING"\n"COPYRIGHT
+ const char *argp_program_version=SPACK_STRING"\n"GAL_STRINGS_COPYRIGHT
"\n\nWritten by Mohammad Akhlaghi";
const char *argp_program_bug_address=PACKAGE_BUGREPORT;
-static char args_doc[] = "ASTRdata ...";
+static char args_doc[] = "";
@@@ -57,9 -56,10 +57,9 @@@
const char doc[] =
/* Before the list of options: */
- TOPHELPINFO
+ GAL_STRINGS_TOP_HELP_INFO
- SPACK_NAME" will add noise to all the pixels in an input image. The noise "
- "parameters can be specified with the command line options. \n"
+ SPACK_NAME" will produce cosmological calculations.\n"
- MOREHELPINFO
+ GAL_STRINGS_MORE_HELP_INFO
/* After the list of options: */
"\v"
PACKAGE_NAME" home page: "PACKAGE_URL;
@@@ -193,25 -178,22 +193,29 @@@ parse_opt(int key, char *arg, struct ar
/* Input: */
- case 'b':
- gal_checkset_any_double(arg, &p->mbackground, "background", key, SPACK,
- NULL, 0);
- p->up.backgroundset=1;
+ case 'z':
- doublele0(arg, &p->redshift, "redshift", key, SPACK, NULL, 0);
++ gal_checkset_double_el_0(arg, &p->redshift, "redshift", key,
++ SPACK, NULL, 0);
+ p->up.redshiftset=1;
break;
- case 's':
- doublele0(arg, &p->stdadd, "stdadd", key, SPACK, NULL, 0);
- p->up.stdaddset=1;
+ case 'H':
- doublele0(arg, &p->H0, "H0", key, SPACK, NULL, 0);
++ gal_checkset_double_el_0(arg, &p->H0, "H0", key, SPACK, NULL, 0);
+ p->up.H0set=1;
break;
- case 'z':
- gal_checkset_any_double(arg, &p->zeropoint, "zeropoint", key, SPACK,
- NULL, 0);
- p->up.zeropointset=1;
+ case 'l':
- doublele0(arg, &p->olambda, "olambda", key, SPACK, NULL, 0);
++ gal_checkset_double_el_0(arg, &p->olambda, "olambda", key,
++ SPACK, NULL, 0);
+ p->up.olambdaset=1;
+ break;
+ case 'm':
- doublele0(arg, &p->omatter, "omatter", key, SPACK, NULL, 0);
++ gal_checkset_double_el_0(arg, &p->omatter, "omatter", key,
++ SPACK, NULL, 0);
+ p->up.omatterset=1;
break;
- case 'e':
- p->envseed=1;
+ case 'r':
- doublele0(arg, &p->oradiation, "oradiation", key, SPACK, NULL, 0);
++ gal_checkset_double_el_0(arg, &p->oradiation, "oradiation",
++ key, SPACK, NULL, 0);
+ p->up.oradiationset=1;
break;
diff --cc src/cosmiccal/cite.h
index bdc3810,c57984c..d6d54b9
--- a/src/cosmiccal/cite.h
+++ b/src/cosmiccal/cite.h
@@@ -23,15 -23,15 +23,15 @@@ along with Gnuastro. If not, see <http:
#ifndef CITE_H
#define CITE_H
- #define HEADERBIBTEX ""
-#define IMGCROPBIBTEX ""
++#define COSMICCALBIBTEX ""
#define PRINTCITEABORT { \
printf("\nWe hope %s has been useful for your research.\n"
\
"Citations are vital for the continued work on %s.\n" \
"Thank you for citing it in your research paper.\n" \
"\nPlease cite as \"%s\":\n\n%s\n\n%s", \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GNUASTROBIBTEX, \
- HEADERBIBTEX); \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GAL_STRINGS_BIBTEX, \
- IMGCROPBIBTEX); \
++ SPACK_NAME, SPACK_NAME, SPACK_STRING, \
++ GAL_STRINGS_MAIN_BIBTEX, COSMICCALBIBTEX); \
exit(EXIT_SUCCESS);
\
}
diff --cc src/cosmiccal/main.h
index 1bf706e,0000000..4d33e80
mode 100644,000000..100644
--- a/src/cosmiccal/main.h
+++ b/src/cosmiccal/main.h
@@@ -1,84 -1,0 +1,84 @@@
+/*********************************************************************
+CosmicCalculator - Calculate cosmological parameters
+CosmicCalculator is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+ Mohammad Akhlaghi <address@hidden>
+Contributing author(s):
+Copyright (C) 2016, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#ifndef MAIN_H
+#define MAIN_H
+
+#include "commonparams.h"
+
+/* Progarm name macros: */
+#define SPACK "astcosmiccal" /* Subpackage executable name. */
+#define SPACK_NAME "CosmicCalculator" /* Subpackage full name. */
+#define SPACK_STRING SPACK_NAME" ("PACKAGE_NAME") "PACKAGE_VERSION
+
+
+
+
+
+
+struct uiparams
+{
+ int redshiftset;
+ int curvatureset;
+ int H0set;
+ int olambdaset;
+ int omatterset;
+ int oradiationset;
+
+ int onlyvolumeset;
+ int onlyabsmagconvset;
+};
+
+
+
+
+
+struct cosmiccalparams
+{
+ /* Other structures: */
+ struct uiparams up; /* User interface parameters. */
- struct commonparams cp; /* Common parameters. */
++ struct gal_commonparams cp; /* Common parameters. */
+
+ /* Input: */
+ double redshift; /* Redshift of interest. */
+ double H0; /* Current expansion rate (km/sec/Mpc). */
+ double olambda; /* Current cosmological constant dens. */
+ double omatter; /* Current matter density. */
+ double oradiation; /* Current radiation density. */
+ double solidangle; /* Solid angle for volume (in stradian).*/
+
+ /* Output: */
+ int onlyvolume; /* Only print the volume in Mpc^3. */
+ int onlyabsmagconv; /* Only print conversion to abs. mag. */
+
+ /* Operating mode: */
+
+ /* Internal: */
+ double K; /* Curvature constant. */
+ double c; /* Speed of light. */
+ double H0s; /* Current expansion rate (1/sec). */
+ double ocurv; /* Curvature density today. */
+
+ time_t rawtime; /* Starting time of the program. */
+};
+
+#endif
diff --cc src/cosmiccal/ui.c
index 9ef7757,0000000..7d6974a
mode 100644,000000..100644
--- a/src/cosmiccal/ui.c
+++ b/src/cosmiccal/ui.c
@@@ -1,365 -1,0 +1,365 @@@
+/*********************************************************************
+CosmicCalculator - Calculate cosmological parameters
+CosmicCalculator is part of GNU Astronomy Utilities (Gnuastro) package.
+
+Original author:
+ Mohammad Akhlaghi <address@hidden>
+Contributing author(s):
+Copyright (C) 2016, Free Software Foundation, Inc.
+
+Gnuastro is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by the
+Free Software Foundation, either version 3 of the License, or (at your
+option) any later version.
+
+Gnuastro is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
+**********************************************************************/
+#include <config.h>
+
+#include <math.h>
+#include <stdio.h>
+#include <errno.h>
+#include <error.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fitsio.h>
+
+#include <nproc.h> /* From Gnulib. */
+#include <gsl/gsl_const_mksa.h>
+
+#include "timing.h" /* Includes time.h and sys/time.h */
+#include "checkset.h"
+#include "txtarrayvv.h"
+#include "commonargs.h"
+#include "configfiles.h"
+#include "fitsarrayvv.h"
+
+#include "main.h"
+
+#include "ui.h" /* Needs main.h */
+#include "args.h" /* Needs main.h, includes argp.h. */
+
+
+/* Set the file names of the places where the default parameters are
+ put. */
+#define CONFIG_FILE SPACK CONF_POSTFIX
+#define SYSCONFIG_FILE SYSCONFIG_DIR "/" CONFIG_FILE
+#define USERCONFIG_FILEEND USERCONFIG_DIR CONFIG_FILE
+#define CURDIRCONFIG_FILE CURDIRCONFIG_DIR CONFIG_FILE
+
+
+
+
+
+
+
+
+
+
+/**************************************************************/
+/************** Options and parameters ***************/
+/**************************************************************/
+void
+readconfig(char *filename, struct cosmiccalparams *p)
+{
+ FILE *fp;
+ size_t lineno=0, len=200;
+ char *line, *name, *value;
+ struct uiparams *up=&p->up;
- struct commonparams *cp=&p->cp;
++ struct gal_commonparams *cp=&p->cp;
+ char key='a'; /* Not used, just a place holder. */
+
+ /* When the file doesn't exist or can't be opened, it is ignored. It
+ might be intentional, so there is no error. If a parameter is
+ missing, it will be reported after all defaults are read. */
+ fp=fopen(filename, "r");
+ if (fp==NULL) return;
+
+
+ /* Allocate some space for `line` with `len` elements so it can
+ easily be freed later on. The value of `len` is arbitarary at
+ this point, during the run, getline will change it along with the
+ pointer to line. */
+ errno=0;
+ line=malloc(len*sizeof *line);
+ if(line==NULL)
+ error(EXIT_FAILURE, errno, "ui.c: %lu bytes in readdefaults",
+ len * sizeof *line);
+
+ /* Read the tokens in the file: */
+ while(getline(&line, &len, fp) != -1)
+ {
+ /* Prepare the "name" and "value" strings, also set lineno. */
- STARTREADINGLINE;
++ GAL_CONFIGFILES_START_READING_LINE;
+
+
+
+
+ /* Inputs: */
+ if(strcmp(name, "redshift")==0)
+ {
+ if(up->redshiftset) continue;
- doublele0(value, &p->redshift, name, key, SPACK,
- filename, lineno);
++ gal_checkset_double_el_0(value, &p->redshift, name, key,
++ SPACK, filename, lineno);
+ up->redshiftset=1;
+ }
+ else if(strcmp(name, "H0")==0)
+ {
+ if(up->H0set) continue;
- doublele0(value, &p->H0, name, key, SPACK,
- filename, lineno);
++ gal_checkset_double_el_0(value, &p->H0, name, key, SPACK,
++ filename, lineno);
+ up->H0set=1;
+ }
+ else if(strcmp(name, "olambda")==0)
+ {
+ if(up->olambdaset) continue;
- doublele0(value, &p->olambda, name, key, SPACK,
- filename, lineno);
++ gal_checkset_double_el_0(value, &p->olambda, name, key,
++ SPACK, filename, lineno);
+ up->olambdaset=1;
+ }
+ else if(strcmp(name, "omatter")==0)
+ {
+ if(up->omatterset) continue;
- doublele0(value, &p->omatter, name, key, SPACK,
- filename, lineno);
++ gal_checkset_double_el_0(value, &p->omatter, name, key,
++ SPACK, filename, lineno);
+ up->omatterset=1;
+ }
+ else if(strcmp(name, "oradiation")==0)
+ {
+ if(up->oradiationset) continue;
- doublele0(value, &p->oradiation, name, key, SPACK,
- filename, lineno);
++ gal_checkset_double_el_0(value, &p->oradiation, name, key,
++ SPACK, filename, lineno);
+ up->oradiationset=1;
+ }
+
+
+
+ /* Outputs */
+ else if(strcmp(name, "onlyvolume")==0)
+ {
+ if(up->onlyvolumeset) continue;
- intzeroorone(value, &p->onlyvolume, name, key, SPACK,
- filename, lineno);
++ gal_checkset_int_zero_or_one(value, &p->onlyvolume, name, key,
++ SPACK, filename, lineno);
+ up->onlyvolumeset=1;
+ }
+ else if(strcmp(name, "onlyabsmagconv")==0)
+ {
+ if(up->onlyabsmagconvset) continue;
- intzeroorone(value, &p->onlyabsmagconv, name, key, SPACK,
- filename, lineno);
++ gal_checkset_int_zero_or_one(value, &p->onlyabsmagconv, name,
++ key, SPACK, filename, lineno);
+ up->onlyabsmagconvset=1;
+ }
+
+
+
+ /* Operating modes: */
+ /* Read options common to all programs */
- READ_COMMONOPTIONS_FROM_CONF
++ GAL_CONFIGFILES_READ_COMMONOPTIONS_FROM_CONF
+
+
+ else
+ error_at_line(EXIT_FAILURE, 0, filename, lineno,
+ "`%s` not recognized.\n", name);
+ }
+
+ free(line);
+ fclose(fp);
+}
+
+
+
+
+
+void
+printvalues(FILE *fp, struct cosmiccalparams *p)
+{
+ struct uiparams *up=&p->up;
- struct commonparams *cp=&p->cp;
++ struct gal_commonparams *cp=&p->cp;
+
+
+ /* Print all the options that are set. Separate each group with a
+ commented line explaining the options in that group. */
+ fprintf(fp, "\n# Input:\n");
+ if(up->redshiftset)
+ fprintf(fp, CONF_SHOWFMT"%.3f\n", "redshift", p->redshift);
+ if(up->H0set)
+ fprintf(fp, CONF_SHOWFMT"%.3f\n", "H0", p->H0);
+
+
+ fprintf(fp, "\n# Current densities per current critical density:\n");
+ if(up->olambdaset)
+ fprintf(fp, CONF_SHOWFMT"%.3f\n", "olambda", p->olambda);
+ if(up->omatterset)
+ fprintf(fp, CONF_SHOWFMT"%.3f\n", "omatter", p->omatter);
+ if(up->oradiationset)
+ fprintf(fp, CONF_SHOWFMT"%.3f\n", "oradiation", p->oradiation);
+
+
+ /* For the operating mode, first put the macro to print the common
+ options, then the (possible options particular to this
+ program). */
+ fprintf(fp, "\n# Operating mode:\n");
- PRINT_COMMONOPTIONS;
++ GAL_CONFIGFILES_PRINT_COMMONOPTIONS;
+}
+
+
+
+
+
+
+/* Note that numthreads will be used automatically based on the
+ configure time. */
+void
+checkifset(struct cosmiccalparams *p)
+{
+ struct uiparams *up=&p->up;
- /*struct commonparams *cp=&p->cp;*/
++ /*struct gal_commonparams *cp=&p->cp;*/
+
+ int intro=0;
+ if(up->redshiftset==0)
- REPORT_NOTSET("redshift");
++ GAL_CONFIGFILES_REPORT_NOTSET("redshift");
+ if(up->H0set==0)
- REPORT_NOTSET("H0");
++ GAL_CONFIGFILES_REPORT_NOTSET("H0");
+ if(up->olambdaset==0)
- REPORT_NOTSET("olambda");
++ GAL_CONFIGFILES_REPORT_NOTSET("olambda");
+ if(up->omatterset==0)
- REPORT_NOTSET("omatter");
++ GAL_CONFIGFILES_REPORT_NOTSET("omatter");
+ if(up->oradiationset==0)
- REPORT_NOTSET("oradiation");
++ GAL_CONFIGFILES_REPORT_NOTSET("oradiation");
+
+
- END_OF_NOTSET_REPORT;
++ GAL_CONFIGFILES_END_OF_NOTSET_REPORT;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**************************************************************/
+/************ Sanity check *************/
+/**************************************************************/
+void
+sanitycheck(struct cosmiccalparams *p)
+{
+ int check=p->onlyvolume+p->onlyabsmagconv;
+
+ /* If only one of the single output options are called, then check
+ should be 1, if none are called, then it should be zero. However,
+ if more than one is called, check will be larger than one. So in
+ this case, report an error. */
+ if(check>1)
+ error(EXIT_FAILURE, 0, "Only a single option starting with `--only' "
+ "can be called.");
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**************************************************************/
+/************ Preparations *************/
+/**************************************************************/
+void
+preparations(struct cosmiccalparams *p)
+{
+ /* Speed of light: */
+ p->c=GSL_CONST_MKSA_SPEED_OF_LIGHT;
+
+ /* The curvature fractional density: */
+ p->ocurv=1-(p->olambda+p->omatter+p->oradiation);
+
+ /* Convert H0 from km/sec/Mpc to 1/sec: */
+ p->H0s=p->H0/1000/GSL_CONST_MKSA_PARSEC;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/**************************************************************/
+/************ Set the parameters *************/
+/**************************************************************/
+void
+setparams(int argc, char *argv[], struct cosmiccalparams *p)
+{
- struct commonparams *cp=&p->cp;
++ struct gal_commonparams *cp=&p->cp;
+
+ /* Set the non-zero initial values, the structure was initialized to
+ have a zero value for all elements. */
+ cp->spack = SPACK;
+ cp->verb = 1;
+ cp->numthreads = num_processors(NPROC_CURRENT);
+ cp->removedirinfo = 1;
+
+ /* Read the arguments. */
+ errno=0;
+ if(argp_parse(&thisargp, argc, argv, 0, 0, p))
+ error(EXIT_FAILURE, errno, "Parsing arguments");
+
+ /* Add the user default values and save them if asked. */
- CHECKSETCONFIG;
++ GAL_CONFIGFILES_CHECK_SET_CONFIG;
+
+ /* Check if all the required parameters are set. */
+ checkifset(p);
+
+ /* Do a sanity check */
+ sanitycheck(p);
+
+ /* Make the preparations */
+ preparations(p);
+
+ /* Print the values for each parameter. */
+ if(cp->printparams)
- REPORT_PARAMETERS_SET;
++ GAL_CONFIGFILES_REPORT_PARAMETERS_SET;
+}
diff --cc src/header/cite.h
index 5acf8a2,e355d81..f6c2b0c
--- a/src/header/cite.h
+++ b/src/header/cite.h
@@@ -30,8 -30,8 +30,8 @@@ along with Gnuastro. If not, see <http:
"Citations are vital for the continued work on %s.\n" \
"Thank you for citing it in your research paper.\n" \
"\nPlease cite as \"%s\":\n\n%s\n\n%s", \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GNUASTROBIBTEX, \
- HEADERBIBTEX); \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GAL_STRINGS_BIBTEX, \
- HEADERBIBTEX); \
++ SPACK_NAME, SPACK_NAME, SPACK_STRING, \
++ GAL_STRINGS_MAIN_BIBTEX, HEADERBIBTEX); \
exit(EXIT_SUCCESS);
\
}
diff --cc src/header/main.h
index 26b310a,a833889..756a5ad
--- a/src/header/main.h
+++ b/src/header/main.h
@@@ -38,10 -39,10 +38,10 @@@ along with Gnuastro. If not, see <http:
struct uiparams
{
- char *inputname; /* Name of input file. */
- struct stll *rename; /* Rename a keyword. */
- struct stll *update; /* For keywords to update. */
- struct stll *write; /* Full argument for keywords to add.*/
- char *inputname; /* Name of input file.
*/
- struct gal_linkedlist_stll *rename; /* Rename a keyword.
*/
- struct gal_linkedlist_stll *update; /* For keywords to update.
*/
- struct gal_linkedlist_stll *write; /* Full argument for keywords to
add.*/
++ char *inputname; /* Name of input file. */
++ struct gal_linkedlist_stll *rename; /* Rename a keyword. */
++ struct gal_linkedlist_stll *update; /* For keywords to update. */
++ struct gal_linkedlist_stll *write; /* Full arg. for keywords to add. */
};
diff --cc src/imgcrop/cite.h
index 2054cdb,c57984c..580c64b
--- a/src/imgcrop/cite.h
+++ b/src/imgcrop/cite.h
@@@ -30,8 -30,8 +30,8 @@@ along with Gnuastro. If not, see <http:
"Citations are vital for the continued work on %s.\n" \
"Thank you for citing it in your research paper.\n" \
"\nPlease cite as \"%s\":\n\n%s\n\n%s", \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GNUASTROBIBTEX, \
- IMGCROPBIBTEX); \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GAL_STRINGS_BIBTEX, \
- IMGCROPBIBTEX); \
++ SPACK_NAME, SPACK_NAME, SPACK_STRING, \
++ GAL_STRINGS_MAIN_BIBTEX, IMGCROPBIBTEX); \
exit(EXIT_SUCCESS);
\
}
diff --cc src/imgcrop/main.h
index 83d1e9f,2b6acec..e7996c9
--- a/src/imgcrop/main.h
+++ b/src/imgcrop/main.h
@@@ -77,7 -78,7 +77,7 @@@ struct inputimg
struct uiparams
{
char *catname; /* Catalog file name. */
- struct stll *stll; /* Linked list keeping input file names. */
- struct gal_linkedlist_stll *gal_linkedlist_stll; /* Linked list keeping
input file names. */
++ struct gal_linkedlist_stll *gal_linkedlist_stll; /* Input file names. */
char *polygon; /* String of input polygon vertices. */
/* Check if all parameters are read (use .def file for
@@@ -114,8 -115,8 +114,8 @@@
struct imgcropparams
{
/* Before actual program: */
- struct commonparams cp; /* Common parameters. */
- struct uiparams up; /* User interface parameters. */
++ struct uiparams up; /* User interface parameters. */
+ struct gal_commonparams cp; /* Common parameters. */
- struct uiparams up; /* User interface parameters. */
/* Operating modes: */
int imgmode; /* ==1: will use X and Y coordiates. */
diff --cc src/imgstat/cite.h
index 708d7b3,a3bd373..074bd84
--- a/src/imgstat/cite.h
+++ b/src/imgstat/cite.h
@@@ -23,15 -23,15 +23,15 @@@ along with Gnuastro. If not, see <http:
#ifndef CITE_H
#define CITE_H
--#define HEADERBIBTEX ""
++#define IMGSTATBIBTEX ""
#define PRINTCITEABORT { \
printf("\nWe hope %s has been useful for your research.\n"
\
"Citations are vital for the continued work on %s.\n" \
"Thank you for citing it in your research paper.\n" \
"\nPlease cite as \"%s\":\n\n%s\n\n%s", \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GNUASTROBIBTEX, \
- HEADERBIBTEX); \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GAL_STRINGS_BIBTEX, \
- HEADERBIBTEX); \
++ SPACK_NAME, SPACK_NAME, SPACK_STRING, \
++ GAL_STRINGS_MAIN_BIBTEX, IMGSTATBIBTEX); \
exit(EXIT_SUCCESS);
\
}
diff --cc src/imgstat/main.h
index 2acdd9e,0493b38..bab3a61
--- a/src/imgstat/main.h
+++ b/src/imgstat/main.h
@@@ -76,8 -77,8 +76,8 @@@ struct uiparam
struct imgstatparams
{
/* Other structures: */
-- struct uiparams up; /* User interface parameters. */
- struct commonparams cp; /* Common parameters. */
++ struct uiparams up; /* User interface parameters. */
+ struct gal_commonparams cp; /* Common parameters. */
/* Input: */
float *img; /* Input image array. */
diff --cc src/imgstat/ui.c
index 571cfb6,03b503b..3132778
--- a/src/imgstat/ui.c
+++ b/src/imgstat/ui.c
@@@ -377,12 -375,10 +377,13 @@@ sanitycheck(struct imgstatparams *p
{
char *basename;
+ /* Make sure the input file exists. */
- checkfile(p->up.inputname);
++ gal_checkset_check_file(p->up.inputname);
+
/* Set the p->up.maskname accordingly: */
- fileorextname(p->up.inputname, p->cp.hdu, p->up.masknameset,
- &p->up.maskname, p->up.mhdu, p->up.mhduset, "mask");
+ gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu,
p->up.masknameset,
+ &p->up.maskname, p->up.mhdu,
+ p->up.mhduset, "mask");
/* Set the names of the output files: */
if(p->cp.outputset) basename=p->cp.output;
diff --cc src/imgwarp/cite.h
index bbad19c,8a2279f..c589224
--- a/src/imgwarp/cite.h
+++ b/src/imgwarp/cite.h
@@@ -23,15 -23,15 +23,15 @@@ along with Gnuastro. If not, see <http:
#ifndef CITE_H
#define CITE_H
--#define IMGCROPBIBTEX ""
++#define IMGWARPBIBTEX ""
#define PRINTCITEABORT { \
printf("\nWe hope %s has been useful for your research.\n"
\
"Citations are vital for the continued work on %s.\n" \
"Thank you for citing it in your research paper.\n" \
"\nPlease cite as \"%s\":\n\n%s\n\n%s", \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GNUASTROBIBTEX, \
- IMGCROPBIBTEX); \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GAL_STRINGS_BIBTEX, \
- IMGCROPBIBTEX); \
++ SPACK_NAME, SPACK_NAME, SPACK_STRING, \
++ GAL_STRINGS_MAIN_BIBTEX, IMGWARPBIBTEX); \
exit(EXIT_SUCCESS);
\
}
diff --cc src/imgwarp/ui.c
index 2906298,bdf4c43..a22b573
--- a/src/imgwarp/ui.c
+++ b/src/imgwarp/ui.c
@@@ -314,8 -313,6 +315,8 @@@ sanitycheck(struct imgwarpparams *p
{
double *d, *df, *tmp, *m=p->matrix;
+ /* Make sure the input file exists. */
- checkfile(p->up.inputname);
++ gal_checkset_check_file(p->up.inputname);
/* Set the output name: */
if(p->cp.output)
diff --cc src/mkcatalog/args.h
index c04e464,a5959c2..4a4a0dc
--- a/src/mkcatalog/args.h
+++ b/src/mkcatalog/args.h
@@@ -643,15 -517,11 +645,17 @@@ parse_opt(int key, char *arg, struct ar
p->skysubtracted=1;
p->up.skysubtractedset=1;
break;
+ case 'T':
- anydouble(arg, &p->threshold, "threshold", key, SPACK, NULL, 0);
++ gal_checkset_any_double(arg, &p->threshold, "threshold", key, SPACK,
++ NULL, 0);
+ p->up.thresholdset=1;
+ break;
/* Output: */
case 521:
- anydouble(arg, &p->nsigmag, "nsigmag", key, SPACK, NULL, 0);
- gal_checkset_any_double(arg, &p->nsigmag, "nsigmag", key, SPACK, NULL,
0);
++ gal_checkset_any_double(arg, &p->nsigmag, "nsigmag", key, SPACK,
++ NULL, 0);
p->up.nsigmagset=1;
break;
case 516:
diff --cc src/mkcatalog/cite.h
index 96c425e,0b5f0f3..c2b6377
--- a/src/mkcatalog/cite.h
+++ b/src/mkcatalog/cite.h
@@@ -23,15 -23,15 +23,15 @@@ along with Gnuastro. If not, see <http:
#ifndef CITE_H
#define CITE_H
--#define HEADERBIBTEX ""
++#define MKCATALOGBIBTEX ""
#define PRINTCITEABORT { \
printf("\nWe hope %s has been useful for your research.\n"
\
"Citations are vital for the continued work on %s.\n" \
"Thank you for citing it in your research paper.\n" \
"\nPlease cite as \"%s\":\n\n%s\n\n%s", \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GNUASTROBIBTEX, \
- HEADERBIBTEX); \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GAL_STRINGS_BIBTEX, \
- HEADERBIBTEX); \
++ SPACK_NAME, SPACK_NAME, SPACK_STRING, \
++ GAL_STRINGS_MAIN_BIBTEX, MKCATALOGBIBTEX); \
exit(EXIT_SUCCESS);
\
}
diff --cc src/mkcatalog/columns.c
index 4f187ae,897e958..7dce7ee
--- a/src/mkcatalog/columns.c
+++ b/src/mkcatalog/columns.c
@@@ -52,514 -43,21 +52,515 @@@ along with Gnuastro. If not, see <http:
-/* MakeCatalogs and these column functions:
- ========================================
+/******************************************************************/
+/******* Information table modifications *************/
+/******************************************************************/
+/* Correct the average Sky and Sky standard deviation value for
+ objects and clumps. Note that during the passes, these were just
+ sums of pixel values, they need to be divided by the area of the
+ object/clump, which is done here. */
+void
+setskystd(struct mkcatalogparams *p, size_t col)
+{
+ size_t ac;
+ double *row = p->info + p->icols;
+ double *end = row + (p->icols * p->num);
+
+ /* Only do the correction if this column is not already flagged. */
+ if(p->info[col]==0.0f)
+ {
+
+ /* Set the area column: */
+ ac = p->obj0clump1 ? CALLAREA : OALLAREA;
+
+ /* Go over every row and do the correction. */
+ do
+ {
+ row[col] = ( row[ac]>0.0f ? row[col]/row[ac] : NAN );
+ row+=p->icols;
+ }
+ while(row<end);
+
+ /* Set the flag so this operation is not done again. */
+ p->info[col]=1.0f;
+ }
+}
+
+
+
+
+
+/* Correct the average river value, after the passes, it is just the
+ sum. */
+void
+setaveriver(struct mkcatalogparams *p)
+{
+ double *row = p->info + p->icols;
+ double *end = row + (p->icols * p->num);
+
+ /* Only do the correction if this column is not already flagged. */
+ if(p->info[CRivAve]==0.0f)
+ {
+
+ /* Make sure the Sky values are corrected */
+ setskystd(p, CSKY);
+
+ /* Go over every row and do the correction. Note that in cases
+ where the grown clumps are used instead of the clumps, we are
+ not going to have any rivers (row[CRivArea]==0.0f). In such
+ situations, set the per-pixel average river value to the Sky
+ value under the clump. The reason is that for the clumps, Sky
+ subtraction was not done on the Clump brightness, so this
+ value will be used, and if there was no river, then we need
+ something to replace it. */
+ do
+ {
+ row[CRivAve] = ( row[CRivArea]>0.0f
+ ? row[CRivAve]/row[CRivArea] : row[CSKY] );
+ row+=p->icols;
+ }
+ while(row<end);
+
+ /* Set the flag so this operation is not done again. */
+ p->info[CRivAve]=1.0f;
+ }
+}
+
+
+
+
+
+/* The clump brightness values are not Sky subtracted since the river
+ values (which are also not Sky subtracted) should be subtracted
+ from them. Here that job is done. */
+void
+setclumpbrightness(struct mkcatalogparams *p)
+{
+ double *row = p->info + p->icols;
+ double *end = row + (p->icols * p->num);
+
+ /* Only do the correction if this column is not already flagged. */
+ if(p->info[CBrightness]==0.0f)
+ {
+
+ /* Make sure the average river value is calculated */
+ setaveriver(p);
+
+ /* On a clump, we have to subtract the average river flux
+ multiplied by the the area of the clump. The value in the
+ CBrightness column is simply the sum of pixels. Note that
+ here we are multiplying by the area of the clump (CALLAREA)
+ irrespective of threshold, while in setaveriver(), we divided
+ by the area of the river (CRivArea). */
+ do
+ {
+ row[CBrightness] -= row[CRivAve]*row[CAREA];
+ row+=p->icols;
+ }
+ while(row<end);
+
+ /* Set the flag so this operation is not done again. */
+ p->info[CBrightness]=1.0f;
+ }
+}
+
+
+
+
+
+/* Find the geometric center of the profile (average position,
+ ignoring any flux of the pixels). */
+void
+geoxy(struct mkcatalogparams *p, size_t col)
+{
+ size_t ac=-1;
+ double *row = p->info + p->icols;
+ double *end = row + (p->icols * p->num);
+
+ /* Only if this column is not flagged as already done (==1.0f). */
+ if(p->info[col]==0.0f)
+ {
+
+ /* First, set the columns to use for the conversion. */
+ if(p->obj0clump1) ac=CAREA;
+ else
+ {
+ if (col==OGeoX || col==OGeoY) ac=OAREA;
+ else if (col==OGeoCX || col==OGeoCY) ac=OAREAC;
+ else
+ error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we "
+ "can fix this. The given column in the --OBJECTS-- "
+ "information table was not recognized for calculating the "
+ "geometric X and/or Y.", PACKAGE_BUGREPORT);
+ }
+
+ /* Go over all the rows and correct this column. */
+ do
+ {
+ /* Set the value for this row. Note that unlike the
+ calculations here that start counting with zero, the FITS
+ standard starts counting from 1, so add a one after
+ dividing by the area. If the area is zero, then set
+ NaN. */
+ row[col] = row[ac]>0.0f ? row[col] / row[ac] : NAN;
+
+ /* Go onto the next row: */
+ row+=p->icols;
+ }
+ while(row<end);
+
+ /* Flag this column as complete for future reference. */
+ p->info[col]=1.0f;
+ }
+}
+
+
+
+
+
+/* A low-level function used to find the flux weighted center, since
+ it is needed by multiple columns. The geometric center for this
+ axis colum (geocol) and area column (areacol) are needed for backup
+ (when there might not be any positive flux pixel/data values to use
+ for weight). */
+void
+flxwhtimg(struct mkcatalogparams *p, size_t col)
+{
+ size_t wc=-1, gc=-1;
+ double *row = p->info + p->icols;
+ double *end = row + (p->icols * p->num);;
+
+
+ /* Only if this column is not flagged as already done (==1.0f). */
+ if(p->info[col]==0.0f)
+ {
+
+ /* First, set the columns to use for the conversion. */
+ if(p->obj0clump1)
+ {
+ wc=CPosBright;
+ if (col==CFlxWhtX) gc=CGeoX;
+ else if(col==CFlxWhtY) gc=CGeoY;
+ else
+ error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we "
+ "can fix this. The given column in the --CLUMPS-- "
+ "information table was not recognized for calculating the "
+ "final flux weighted X and/or Y.", PACKAGE_BUGREPORT);
+ }
+ else
+ {
+ if (col==OFlxWhtX || col==OFlxWhtY)
+ {
+ wc=OPosBright;
+ gc = col==OFlxWhtX ? OGeoX : OGeoY;
+ }
+ else if (col==OFlxWhtCX || col==OFlxWhtCY)
+ {
+ wc=OPosBrightC;
+ gc = col==OFlxWhtCX ? OGeoCX : OGeoCY;
+ }
+ else
+ error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we "
+ "can fix this. The given column in the --OBJECTS-- "
+ "information table was not recognized for calculating the "
+ "final flux weighted X and/or Y.", PACKAGE_BUGREPORT);
+ }
+
+
+ /* The geometric positions act as a backup for the flux weighted
+ centers, so make sure the appropriate geometric center is
+ defined. */
+ geoxy(p, gc);
+
+ /* For a check, uncomment these two lines:
+ printf("\n\nInfocol: %lu (%s, %lu)\n", col,
+ p->info==p->oinfo?"Objects":"Clumps", p->num);
+ Then add these two lines before and after row[col] in the loop*/
+ /*printf("%lu: %f --> ", (row-p->info)/p->icols, row[col]);*/
+ /*printf("%f\n", row[col]);*/
+
+ /* Go over all the rows and correct this column. */
+ do
+ {
+ /* Set the value for this row. When a positive weight is
+ present, we are adding with one (1) because of the FITS
+ standard. */
+ row[col] = row[wc]>0.0f ? (row[col]/row[wc]) : row[gc];
+
+ /* Go onto the next row: */
+ row+=p->icols;
+ }
+ while(row<end);
+
+ /* Set the flag for this column to one, so this whole proces is
+ not done again. */
+ p->info[col]=1.0f;
+ }
+}
+
+
+
+
+
+/* To correct the second moment, we need three variables: the first
+ moment in first axis, first moment in second axis and the total
+ weight. The first two are the same when the second moment is a
+ power of one axis. The weight is either the total positive flux
+ used for the weights, or is the area. */
+void
+setsecondmoment(struct mkcatalogparams *p, size_t col)
+{
+ double *row = p->info + p->icols;
+ double *end = row + (p->icols * p->num);
+ size_t fc=-1, sc=-1, wc=-1, sfc=-1, ssc=-1;
+
+
+ /* Only if this column is not flagged as already done (==1.0f). */
+ if(p->info[col]==0.0f)
+ {
+
+ /* First, set the columns to use for the conversion. Note that
+ since we also need to correct the column, we have merged the
+ setting of fc and sc and the calling of the flxwhtimg
+ function into one call. */
+ if(p->obj0clump1)
+ switch(col)
+ {
+ /* Clump brightness weighted */
+ case CFlxWhtXX:
+ wc=CPosBright; fc=sc=CFlxWhtX; flxwhtimg(p, fc);
+ sfc=ssc=CPOSSHIFTX; break;
+ case CFlxWhtYY:
+ wc=CPosBright; fc=sc=CFlxWhtY; flxwhtimg(p, fc);
+ sfc=ssc=CPOSSHIFTY; break;
+ case CFlxWhtXY:
+ wc=CPosBright;
+ flxwhtimg(p, fc=CFlxWhtX); flxwhtimg(p, sc=CFlxWhtY);
+ sfc=CPOSSHIFTX; ssc=CPOSSHIFTY; break;
+
+ /* Clump geometric: */
+ case CGeoXX:
+ wc=CAREA; fc=sc=CGeoX; geoxy(p, fc);
+ sfc=ssc=CPOSSHIFTX; break;
+ case CGeoYY:
+ wc=CAREA; fc=sc=CGeoY; geoxy(p, fc);
+ sfc=ssc=CPOSSHIFTY; break;
+ case CGeoXY:
+ wc=CAREA; geoxy(p, fc=CGeoX); geoxy(p, sc=CGeoY);
+ sfc=CPOSSHIFTX; ssc=CPOSSHIFTY; break;
+
+ default:
+ error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we "
+ "can fix this. The given column in setsecondmoment's "
+ "--CLUMP-- information table (%lu) was not recognized for "
+ "correcting the second moment.", PACKAGE_BUGREPORT, col);
+ }
+ else
+ switch(col)
+ {
+ /* All object brightness weighted: */
+ case OFlxWhtXX:
+ wc=OPosBright; fc=sc=OFlxWhtX; flxwhtimg(p, fc);
+ sfc=ssc=OPOSSHIFTX; break;
+ case OFlxWhtYY:
+ wc=OPosBright; fc=sc=OFlxWhtY; flxwhtimg(p, fc);
+ sfc=ssc=OPOSSHIFTY; break;
+ case OFlxWhtXY:
+ wc=OPosBright;
+ flxwhtimg(p, fc=OFlxWhtX); flxwhtimg(p, sc=OFlxWhtY);
+ sfc=OPOSSHIFTX; ssc=OPOSSHIFTY; break;
+
+ /* All object geometric: */
+ case OGeoXX:
+ wc=OAREA; fc=sc=OGeoX; geoxy(p, fc);
+ sfc=ssc=OPOSSHIFTX; break;
+ case OGeoYY:
+ wc=OAREA; fc=sc=OGeoY; geoxy(p, fc);
+ sfc=ssc=OPOSSHIFTY; break;
+ case OGeoXY:
+ wc=OAREA; geoxy(p, fc=OGeoX); geoxy(p, sc=OGeoY);
+ sfc=OPOSSHIFTX; ssc=OPOSSHIFTY; break;
+
+ /* Clumps in object brightness weighted: */
+ case OFlxWhtCXX:
+ wc=OPosBrightC; fc=sc=OFlxWhtCX; flxwhtimg(p, fc);
+ sfc=ssc=OPOSSHIFTX; break;
+ case OFlxWhtCYY:
+ wc=OPosBrightC; fc=sc=OFlxWhtCY; flxwhtimg(p, fc);
+ sfc=ssc=OPOSSHIFTY; break;
+ case OFlxWhtCXY:
+ wc=OPosBrightC;
+ flxwhtimg(p, fc=OFlxWhtCX); flxwhtimg(p, sc=OFlxWhtCY);
+ sfc=OPOSSHIFTX; ssc=OPOSSHIFTY; break;
+
+ /* Clumps in object geometric: */
+ case OGeoCXX:
+ wc=OAREAC; fc=sc=OGeoCX; geoxy(p, fc);
+ sfc=ssc=OPOSSHIFTX; break;
+ case OGeoCYY:
+ wc=OAREAC; fc=sc=OGeoCY; geoxy(p, fc);
+ sfc=ssc=OPOSSHIFTY; break;
+ case OGeoCXY:
+ wc=OAREAC; geoxy(p, fc=OGeoCX); geoxy(p, sc=OGeoCY);
+ sfc=OPOSSHIFTX; ssc=OPOSSHIFTY; break;
+ default:
+ error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we "
+ "can fix this. The given column in setsecondmoment's "
+ "--OBJECT-- information table (%lu) was not recognized for "
+ "correcting the second moment.", PACKAGE_BUGREPORT, col);
+ }
+
+ /* Go over all the rows and correct this column. */
+ do
+ {
+
+ /* Set the value for this row, including the shift in
+ calculating the second order moments. */
+ row[col] = ( row[col]/row[wc] -
+ (row[fc]-row[sfc]) * (row[sc]-row[ssc]) );
+
+ /* Go onto the next row: */
+ row+=p->icols;
+ }
+ while(row<end);
+
+ /* Set the flag for this column to one, so this whole proces is
+ not done again. */
+ p->info[col]=1.0f;
+ }
+}
+
+
+
+
+
+/* Fill in the RA and Dec columns, note that we will need the X and Y
+ colums first for this. */
+void
+preparewcs(struct mkcatalogparams *p, size_t col)
+{
+ /* Initialize all the columns to -1 (largest possible number in the
+ C's unsigned char, so if there is any bugs, we get a good error. */
+ int wht0geo1=-1;
+ size_t xc=-1, yc=-1, rc=-1, dc=-1;
+
+
+ /* RA and Dec are usually needed together and must also be
+ calculated together, but here, we are giving the user complete
+ freedom in setting the columns in which ever order they want. So
+ after calculating the RA and Dec once for either of the two,
+ there is no more need to do the calculation again. */
+ if(p->info[col]==0.0f)
+ {
+
+ /* First, set the columns to use for the conversion. */
+ if(p->obj0clump1)
+ {
+ /* Clump, flux weighted: */
+ if(col==CFlxWhtRA || col==CFlxWhtDec)
+ {
+ xc=CFlxWhtX; yc=CFlxWhtY;
+ rc=CFlxWhtRA; dc=CFlxWhtDec;
+ wht0geo1=0;
+ }
+ /* Clump, geometric: */
+ else if(col==CGeoRA || col==CGeoDec)
+ {
+ xc=CGeoX; yc=CGeoY;
+ rc=CGeoRA; dc=CGeoDec;
+ wht0geo1=1;
+ }
+ else
+ error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we "
+ "can fix this. The given column in the --CLUMPS-- "
+ "information table was not recognized for calculating the "
+ "RA and Dec.", PACKAGE_BUGREPORT);
+ }
+ else
+ {
+ /* All clumps in object, flux weighted: */
+ if(col==OFlxWhtCRA || col==OFlxWhtCDec)
+ {
+ xc=OFlxWhtCX; yc=OFlxWhtCY;
+ rc=OFlxWhtCRA; dc=OFlxWhtCDec;
+ wht0geo1=0;
+ }
+ /* All clumps in object, geometric: */
+ else if(col==OGeoCRA || col==OGeoCDec)
+ {
+ xc=OGeoCX; yc=OGeoCY;
+ rc=OGeoCRA; dc=OGeoCDec;
+ wht0geo1=1;
+ }
+ /* All object, flux weighted */
+ else if(col==OFlxWhtRA || col==OFlxWhtDec)
+ {
+ xc=OFlxWhtX; yc=OFlxWhtY;
+ rc=OFlxWhtRA; dc=OFlxWhtDec;
+ wht0geo1=0;
+ }
+ /* All object, geometric */
+ else if(col==OGeoRA || col==OGeoDec)
+ {
+ xc=OGeoX; yc=OGeoY;
+ rc=OGeoRA; dc=OGeoDec;
+ wht0geo1=1;
+ }
+ else
+ error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we "
+ "can fix this. The given column in the --OBJECT-- "
+ "information table was not recognized for calculating the "
+ "RA and Dec.", PACKAGE_BUGREPORT);
+ }
+
+
+ /* Finalize the relevant X and Y positions first (which are
+ needed for the WCS conversion). Note that if they are ready
+ to use (their flag is 1.0f), these functions will not do
+ anything. But if the user hasn't already asked for X and Y,
+ then these columns will be corrected here.*/
+ switch(wht0geo1)
+ {
+ case 0:
+ flxwhtimg(p, xc);
+ flxwhtimg(p, yc);
+ break;
+ case 1:
+ geoxy(p, xc);
+ geoxy(p, yc);
+ break;
+ default:
+ error(EXIT_FAILURE, 0, "A bug! Please contact us at %s so we "
+ "can fix this. The value of the wht0geo1 variable (%d) is "
+ "not recognized.", PACKAGE_BUGREPORT, wht0geo1);
+ }
+
+
+ /* Do the conversion. Note that the p->icols is added because
+ the first row is not used by any object or colump (since
+ their indexes begin from 1).*/
- xyarraytoradec(p->wcs, p->info+p->icols+xc, p->info+p->icols+rc,
- p->num, p->icols);
++ gal_fitsarray_xy_array_to_radec(p->wcs, p->info+p->icols+xc,
++ p->info+p->icols+rc,
++ p->num, p->icols);
+
+
+ /* Set the flag of the converted columns to 1.0f, so the
+ calculations are not repeated if any of the columns is needed
+ again. Note that it is irrelevant which one of the RA or Dec
+ were calculated, so we are not using `col' here. */
+ p->info[rc]=p->info[dc]=1.0f;
+ }
+}
+
+
+
+
+
+
+
- In order to print the information in any of the desired columns
- this is the procedure we have taken:
- There is a base array for information on objects (p->oinfo) and
- clumps (p->cinfo) which is filled in mkcatalog.c's first and second
- pass functions. Most of the necessary information can be found in
- two passes and if the desired calculation doesn't exist, adding it
- is very easy: just add to the macros of main.h and include the
- calculation in any of the passes.
- These information arrays keep the raw data that is then converted
- into the output catalog through the functions in this file. */
diff --cc src/mkcatalog/mkcatalog.c
index ff1a99d,a3a8663..1911386
--- a/src/mkcatalog/mkcatalog.c
+++ b/src/mkcatalog/mkcatalog.c
@@@ -43,14 -43,9 +43,14 @@@ along with Gnuastro. If not, see <http:
+
+/*********************************************************************/
+/***************** Fill information tables *******************/
+/*********************************************************************/
+
/* Macro to see if the label is indexable (belongs to an object or
not). See the explanation in src/noisechisel/label.h. */
- #if FITSLONGBLANK<0
+ #if GAL_FITSARRAY_LONG_BLANK<0
#define ISINDEXABLEOBJLABEL (objects[i]>0)
#define ISINDEXABLECLPLABEL (clumps[i]>0)
#else
@@@ -517,13 -465,11 +517,12 @@@ makeoutput(struct mkcatalogparams *p
strcat(comment, "#\n# Columns:\n# --------\n");
- /* Fill the catalog array, in the end set the last elements in
- intcols and accucols to -1, so arraytotxt knows when to
- stop. */
+ /* Fill the catalog array, in the end set the last elements in intcols
and
+ accucols to -1, so gal_txtarray_array_to_txt knows when to stop. */
for(p->curcol=0;p->curcol<p->numcols;++p->curcol)
{
- switch(cols[p->curcol])
+ col=cols[p->curcol];
+ switch(col)
{
case CATID:
diff --cc src/mkcatalog/ui.c
index 393aced,aec7635..66a5f8c
--- a/src/mkcatalog/ui.c
+++ b/src/mkcatalog/ui.c
@@@ -133,17 -134,10 +136,17 @@@ readconfig(char *filename, struct mkcat
else if (strcmp(name, "skysubtracted")==0)
{
if(up->skysubtractedset) continue;
- intzeroorone(value, &p->skysubtracted, name, key, SPACK,
- filename, lineno);
+ gal_checkset_int_zero_or_one(value, &p->skysubtracted, name, key,
+ SPACK, filename, lineno);
up->skysubtractedset=1;
}
+ else if(strcmp(name, "threshold")==0)
+ {
+ if(up->thresholdset) continue;
- anydouble(value, &p->threshold, name, key, SPACK,
++ gal_checkset_any_double(value, &p->threshold, name, key, SPACK,
+ filename, lineno);
+ up->thresholdset=1;
+ }
/* Outputs */
@@@ -255,22 -260,6 +269,24 @@@
add_to_sll(&p->allcolsll, CATY);
up->yset=1;
}
+ else if(strcmp(name, "geox")==0)
+ {
+ if(up->geoxset) continue;
- intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
++ gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
++ filename, lineno);
+ if(!yes) continue;
+ add_to_sll(&p->allcolsll, CATGEOX);
+ up->geoxset=1;
+ }
+ else if(strcmp(name, "geoy")==0)
+ {
+ if(up->geoyset) continue;
- intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
++ gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
++ filename, lineno);
+ if(!yes) continue;
+ add_to_sll(&p->allcolsll, CATGEOY);
+ up->geoyset=1;
+ }
else if(strcmp(name, "clumpsx")==0)
{
if(up->clumpsxset) continue;
@@@ -287,22 -278,6 +305,24 @@@
add_to_sll(&p->allcolsll, CATCLUMPSY);
up->clumpsyset=1;
}
+ else if(strcmp(name, "clumpsgeox")==0)
+ {
+ if(up->clumpsgeoxset) continue;
- intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
++ gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
++ filename, lineno);
+ if(!yes) continue;
+ add_to_sll(&p->allcolsll, CATCLUMPSGEOX);
+ up->clumpsgeoxset=1;
+ }
+ else if(strcmp(name, "clumpsgeoy")==0)
+ {
+ if(up->clumpsgeoyset) continue;
- intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
++ gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
++ filename, lineno);
+ if(!yes) continue;
+ add_to_sll(&p->allcolsll, CATCLUMPSGEOY);
+ up->clumpsgeoyset=1;
+ }
else if(strcmp(name, "ra")==0)
{
if(up->raset) continue;
@@@ -319,22 -296,6 +341,24 @@@
add_to_sll(&p->allcolsll, CATDEC);
up->decset=1;
}
+ else if(strcmp(name, "geora")==0)
+ {
+ if(up->georaset) continue;
- intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
++ gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
++ filename, lineno);
+ if(!yes) continue;
+ add_to_sll(&p->allcolsll, CATGEORA);
+ up->georaset=1;
+ }
+ else if(strcmp(name, "geodec")==0)
+ {
+ if(up->geodecset) continue;
- intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
++ gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
++ filename, lineno);
+ if(!yes) continue;
+ add_to_sll(&p->allcolsll, CATGEODEC);
+ up->geodecset=1;
+ }
else if(strcmp(name, "clumpsra")==0)
{
if(up->clumpsraset) continue;
@@@ -351,22 -314,6 +377,24 @@@
add_to_sll(&p->allcolsll, CATCLUMPSDEC);
up->clumpsdecset=1;
}
+ else if(strcmp(name, "clumpsgeora")==0)
+ {
+ if(up->clumpsgeoraset) continue;
- intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
++ gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
++ filename, lineno);
+ if(!yes) continue;
+ add_to_sll(&p->allcolsll, CATCLUMPSGEORA);
+ up->clumpsgeoraset=1;
+ }
+ else if(strcmp(name, "clumpsgeodec")==0)
+ {
+ if(up->clumpsgeodecset) continue;
- intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
++ gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
++ filename, lineno);
+ if(!yes) continue;
+ add_to_sll(&p->allcolsll, CATCLUMPSGEODEC);
+ up->clumpsgeodecset=1;
+ }
else if(strcmp(name, "brightness")==0)
{
if(up->brightnessset) continue;
@@@ -383,14 -332,6 +413,15 @@@
add_to_sll(&p->allcolsll, CATCLUMPSBRIGHTNESS);
p->up.clumpsbrightnessset=1;
}
+ else if(strcmp(name, "noriverbrightness")==0)
+ {
+ if(up->noriverbrightnessset) continue;
- intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
++ gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
++ filename, lineno);
+ if(!yes) continue;
+ add_to_sll(&p->allcolsll, CATNORIVERBRIGHTNESS);
+ p->up.noriverbrightnessset=1;
+ }
else if(strcmp(name, "magnitude")==0)
{
if(up->magnitudeset) continue;
@@@ -447,54 -395,6 +485,60 @@@
add_to_sll(&p->allcolsll, CATSTD);
up->stdset=1;
}
+ else if(strcmp(name, "semimajor")==0)
+ {
+ if(up->semimajorset) continue;
- intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
++ gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
++ filename, lineno);
+ if(!yes) continue;
+ add_to_sll(&p->allcolsll, CATSEMIMAJOR);
+ up->semimajorset=1;
+ }
+ else if(strcmp(name, "semiminor")==0)
+ {
+ if(up->semiminorset) continue;
- intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
++ gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
++ filename, lineno);
+ if(!yes) continue;
+ add_to_sll(&p->allcolsll, CATSEMIMINOR);
+ up->semiminorset=1;
+ }
+ else if(strcmp(name, "positionangle")==0)
+ {
+ if(up->positionangleset) continue;
- intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
++ gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
++ filename, lineno);
+ if(!yes) continue;
+ add_to_sll(&p->allcolsll, CATPOSITIONANGLE);
+ up->positionangleset=1;
+ }
+ else if(strcmp(name, "geosemimajor")==0)
+ {
+ if(up->geosemimajorset) continue;
- intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
++ gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
++ filename, lineno);
+ if(!yes) continue;
+ add_to_sll(&p->allcolsll, CATGEOSEMIMAJOR);
+ up->geosemimajorset=1;
+ }
+ else if(strcmp(name, "geosemiminor")==0)
+ {
+ if(up->geosemiminorset) continue;
- intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
++ gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
++ filename, lineno);
+ if(!yes) continue;
+ add_to_sll(&p->allcolsll, CATGEOSEMIMINOR);
+ up->geosemiminorset=1;
+ }
+ else if(strcmp(name, "geopositionangle")==0)
+ {
+ if(up->geopositionangleset) continue;
- intzeroorone(value, &yes, name, key, SPACK, filename, lineno);
++ gal_checkset_int_zero_or_one(value, &yes, name, key, SPACK,
++ filename, lineno);
+ if(!yes) continue;
+ add_to_sll(&p->allcolsll, CATGEOPOSITIONANGLE);
+ up->geopositionangleset=1;
+ }
@@@ -779,26 -632,26 +823,29 @@@ checkifset(struct mkcatalogparams *p
void
sanitycheck(struct mkcatalogparams *p)
{
- struct readheaderkeys keys[2];
+ struct gal_fitsarray_read_header_keys keys[2];
+ /* Make sure the input file exists. */
- checkfile(p->up.inputname);
++ gal_checkset_check_file(p->up.inputname);
+
/* Set the names of the files. */
- fileorextname(p->up.inputname, p->cp.hdu, p->up.masknameset,
- &p->up.maskname, p->up.mhdu, p->up.mhduset, "mask");
- fileorextname(p->up.inputname, p->cp.hdu, p->up.objlabsnameset,
- &p->up.objlabsname, p->up.objhdu, p->up.objhduset,
- "object labels");
- fileorextname(p->up.inputname, p->cp.hdu, p->up.clumplabsnameset,
- &p->up.clumplabsname, p->up.clumphdu, p->up.clumphduset,
- "clump labels");
- fileorextname(p->up.inputname, p->cp.hdu, p->up.skynameset,
- &p->up.skyname, p->up.skyhdu, p->up.skyhduset,
- "sky value image");
- fileorextname(p->up.inputname, p->cp.hdu, p->up.stdnameset,
- &p->up.stdname, p->up.stdhdu, p->up.stdhduset,
- "sky standard deviation");
+ gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu,
p->up.masknameset,
+ &p->up.maskname, p->up.mhdu, p->up.mhduset,
+ "mask");
+ gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu,
+ p->up.objlabsnameset, &p->up.objlabsname,
+ p->up.objhdu, p->up.objhduset,
+ "object labels");
+ gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu,
+ p->up.clumplabsnameset, &p->up.clumplabsname,
+ p->up.clumphdu, p->up.clumphduset,
+ "clump labels");
+ gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.skynameset,
+ &p->up.skyname, p->up.skyhdu,
p->up.skyhduset,
+ "sky value image");
+ gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu, p->up.stdnameset,
+ &p->up.stdname, p->up.stdhdu,
p->up.stdhduset,
+ "sky standard deviation");
/* Read the number of labels for the objects: */
keys[0].keyname="DETSN"; keys[0].datatype=TDOUBLE;
@@@ -1148,29 -933,8 +1201,29 @@@ preparearrays(struct mkcatalogparams *p
else p->clumpcat=NULL;
}
+
+ /* Allocate two arrays to keep all the basic information about each
+ object and clump. Note that there should be one row more than the
+ total number of objects or clumps. This is because we want each
+ label to be its row number and we don't have any object label of
+ zero.*/
+ errno=0; p->oinfo=calloc(OCOLUMNS*(p->numobjects+1), sizeof *p->oinfo);
+ if(p->oinfo==NULL)
+ error(EXIT_FAILURE, errno, "%lu bytes for p->oinfo in mkcatalog "
+ "(mkcatalog.c)", OCOLUMNS*(p->numobjects+1)*sizeof *p->oinfo);
+ errno=0; p->cinfo=calloc(CCOLUMNS*(p->numclumps+1), sizeof *p->cinfo);
+ if(p->cinfo==NULL)
+ error(EXIT_FAILURE, errno, "%lu bytes for p->cinfo in mkcatalog "
+ "(mkcatalog.c)", CCOLUMNS*(p->numclumps+1)*sizeof *p->cinfo);
+
+ /* Set the shift values to NAN for all the objects and clumps: */
+ for(i=1;i<=p->numobjects;++i)
+ p->oinfo[i*OCOLUMNS+OPOSSHIFTX]=p->oinfo[i*OCOLUMNS+OPOSSHIFTY]=NAN;
+ for(i=1;i<=p->numclumps;++i)
+ p->cinfo[i*CCOLUMNS+CPOSSHIFTX]=p->cinfo[i*CCOLUMNS+CPOSSHIFTY]=NAN;
+
/* Clean up: */
- freesll(p->allcolsll);
+ gal_linkedlist_free_sll(p->allcolsll);
}
diff --cc src/mknoise/args.h
index 6a2fb88,f9f945c..290fe6d
--- a/src/mknoise/args.h
+++ b/src/mknoise/args.h
@@@ -183,7 -184,7 +184,8 @@@ parse_opt(int key, char *arg, struct ar
p->up.backgroundset=1;
break;
case 's':
-- doublele0(arg, &p->stdadd, "stdadd", key, SPACK, NULL, 0);
++ gal_checkset_double_el_0(arg, &p->stdadd, "stdadd", key, SPACK,
++ NULL, 0);
p->up.stdaddset=1;
break;
case 'z':
diff --cc src/mknoise/cite.h
index b6bfe97,15b0f27..78ef494
--- a/src/mknoise/cite.h
+++ b/src/mknoise/cite.h
@@@ -23,15 -23,15 +23,15 @@@ along with Gnuastro. If not, see <http:
#ifndef CITE_H
#define CITE_H
--#define IMGCROPBIBTEX ""
++#define MKNOISEBIBTEX ""
#define PRINTCITEABORT { \
printf("\nWe hope %s has been useful for your research.\n"
\
"Citations are vital for the continued work on %s.\n" \
"Thank you for citing it in your research paper.\n" \
"\nPlease cite as \"%s\":\n\n%s\n\n%s", \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GNUASTROBIBTEX, \
- IMGCROPBIBTEX); \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GAL_STRINGS_BIBTEX, \
- IMGCROPBIBTEX); \
++ SPACK_NAME, SPACK_NAME, SPACK_STRING, \
++ GAL_STRINGS_MAIN_BIBTEX, MKNOISEBIBTEX); \
exit(EXIT_SUCCESS);
\
}
diff --cc src/mknoise/main.h
index be8795e,928aa8f..09c5661
--- a/src/mknoise/main.h
+++ b/src/mknoise/main.h
@@@ -56,8 -57,8 +56,8 @@@ struct uiparam
struct mknoiseparams
{
/* Other structures: */
-- struct uiparams up; /* User interface parameters. */
- struct commonparams cp; /* Common parameters. */
++ struct uiparams up; /* User interface parameters. */
+ struct gal_commonparams cp; /* Common parameters. */
/* Input: */
int envseed; /* ==1, generate a random seed. */
diff --cc src/mknoise/ui.c
index db96db8,942b099..caf949d
--- a/src/mknoise/ui.c
+++ b/src/mknoise/ui.c
@@@ -121,7 -119,7 +121,8 @@@ readconfig(char *filename, struct mknoi
else if(strcmp(name, "stdadd")==0)
{
if(up->stdaddset) continue;
-- doublele0(value, &p->stdadd, value, key, SPACK, filename, lineno);
++ gal_checkset_double_el_0(value, &p->stdadd, value, key, SPACK,
++ filename, lineno);
up->stdaddset=1;
}
@@@ -236,16 -234,13 +237,17 @@@ checkifset(struct mknoiseparams *p
void
sanitycheck(struct mknoiseparams *p)
{
+
+ /* Make sure the input file exists. */
- checkfile(p->up.inputname);
++ gal_checkset_check_file(p->up.inputname);
+
/* Set the output name: */
if(p->cp.output)
- checkremovefile(p->cp.output, p->cp.dontdelete);
+ gal_checkset_check_remove_file(p->cp.output, p->cp.dontdelete);
else
- automaticoutput(p->up.inputname, "_noised.fits", p->cp.removedirinfo,
- p->cp.dontdelete, &p->cp.output);
+ gal_checkset_automatic_output(p->up.inputname, "_noised.fits",
+ p->cp.removedirinfo, p->cp.dontdelete,
+ &p->cp.output);
/* Convert the background value from magnitudes to flux. Note that
magnitudes are actually calculated from the ratio of brightness,
diff --cc src/mkprof/cite.h
index 2b8a9f9,e844d0b..cdd76bb
--- a/src/mkprof/cite.h
+++ b/src/mkprof/cite.h
@@@ -30,8 -30,8 +30,8 @@@ along with Gnuastro. If not, see <http:
"Citations are vital for the continued work on %s.\n" \
"Thank you for citing it in your research paper.\n" \
"\nPlease cite as \"%s\":\n\n%s\n\n%s", \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GNUASTROBIBTEX, \
- MKPROFBIBTEX); \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GAL_STRINGS_BIBTEX, \
- MKPROFBIBTEX); \
++ SPACK_NAME, SPACK_NAME, SPACK_STRING, \
++ GAL_STRINGS_MAIN_BIBTEX, MKPROFBIBTEX); \
exit(EXIT_SUCCESS);
\
}
diff --cc src/mkprof/ui.c
index 8e7afc7,9070afb..2f374d4
--- a/src/mkprof/ui.c
+++ b/src/mkprof/ui.c
@@@ -469,9 -480,6 +482,9 @@@ sanitycheck(struct mkprofparams *p
size_t i, j, columns[9], cs1=p->cs1;
+ /* Make sure the input file exists. */
- checkfile(p->up.catname);
++ gal_checkset_check_file(p->up.catname);
+
/* Check if over-sampling is an odd number, then convert the
oversampling rate into the double type. */
diff --cc src/noisechisel/args.h
index c67470a,1b25e81..afa1870
--- a/src/noisechisel/args.h
+++ b/src/noisechisel/args.h
@@@ -559,27 -583,30 +559,31 @@@ parse_opt(int key, char *arg, struct ar
/* Input: */
case 'M':
- allocatecopyset(arg, &p->up.maskname, &p->up.masknameset);
- gal_checkset_allocate_copy_set(arg, &p->up.maskname,
&p->up.masknameset);
++ gal_checkset_allocate_copy_set(arg, &p->up.maskname,
++ &p->up.masknameset);
break;
case 'H':
- allocatecopyset(arg, &p->up.mhdu, &p->up.mhduset);
+ gal_checkset_allocate_copy_set(arg, &p->up.mhdu, &p->up.mhduset);
break;
- case 'K':
+ case 'k':
- allocatecopyset(arg, &p->up.kernelname, &p->up.kernelnameset);
+ gal_checkset_allocate_copy_set(arg, &p->up.kernelname,
+ &p->up.kernelnameset);
break;
case 'U':
- allocatecopyset(arg, &p->up.khdu, &p->up.khduset);
+ gal_checkset_allocate_copy_set(arg, &p->up.khdu, &p->up.khduset);
break;
case 'E':
p->skysubtracted=1;
p->up.skysubtractedset=1;
break;
case 'B':
- floatl0s1(arg, &p->minbfrac, "minbfrac", key, SPACK, NULL, 0);
- gal_checkset_float_l_0_s_1(arg, &p->minbfrac, "minbfrac", key, SPACK,
- NULL, 0);
++ gal_checkset_float_l_0_s_1(arg, &p->minbfrac, "minbfrac", key,
++ SPACK, NULL, 0);
p->up.minbfracset=1;
break;
case 'F':
- sizetlzero(arg, &p->minnumfalse, "minnumfalse", key, SPACK, NULL, 0);
- gal_checkset_sizet_l_zero(arg, &p->minnumfalse, "minnumfalse", key,
SPACK,
- NULL, 0);
++ gal_checkset_sizet_l_zero(arg, &p->minnumfalse, "minnumfalse", key,
++ SPACK, NULL, 0);
p->up.minnumfalseset=1;
break;
@@@ -594,32 -624,36 +598,38 @@@
/* Mesh grid: */
case 's':
- sizetlzero(arg, &p->smp.meshsize, "smeshsize", key, SPACK, NULL, 0);
- gal_checkset_sizet_l_zero(arg, &p->smp.meshsize, "smeshsize", key,
SPACK,
- NULL, 0);
++ gal_checkset_sizet_l_zero(arg, &p->smp.meshsize, "smeshsize", key,
++ SPACK, NULL, 0);
p->up.smeshsizeset=1;
break;
case 'l':
- sizetlzero(arg, &p->lmp.meshsize, "lmeshsize", key, SPACK, NULL, 0);
- gal_checkset_sizet_l_zero(arg, &p->lmp.meshsize, "lmeshsize", key,
SPACK,
- NULL, 0);
++ gal_checkset_sizet_l_zero(arg, &p->lmp.meshsize, "lmeshsize", key,
++ SPACK, NULL, 0);
p->up.lmeshsizeset=1;
break;
case 'a':
- sizetlzero(arg, &p->smp.nch1, "nch1", key, SPACK, NULL, 0);
- gal_checkset_sizet_l_zero(arg, &p->smp.nch1, "nch1", key, SPACK, NULL,
0);
++ gal_checkset_sizet_l_zero(arg, &p->smp.nch1, "nch1", key, SPACK,
++ NULL, 0);
p->up.nch1set=1;
break;
case 'b':
- sizetlzero(arg, &p->smp.nch2, "nch2", key, SPACK, NULL, 0);
- gal_checkset_sizet_l_zero(arg, &p->smp.nch2, "nch2", key, SPACK, NULL,
0);
++ gal_checkset_sizet_l_zero(arg, &p->smp.nch2, "nch2", key, SPACK,
++ NULL, 0);
p->up.nch2set=1;
break;
case 'L':
- floatl0s1(arg, &p->smp.lastmeshfrac, "lastmeshfrac", key, SPACK,
- NULL, 0);
- gal_checkset_float_l_0_s_1(arg, &p->smp.lastmeshfrac, "lastmeshfrac",
key,
- SPACK, NULL, 0);
++ gal_checkset_float_l_0_s_1(arg, &p->smp.lastmeshfrac, "lastmeshfrac",
++ key, SPACK, NULL, 0);
p->up.lastmeshfracset=1;
break;
case 'd':
- floatl0(arg, &p->smp.mirrordist, "mirrordist", key, SPACK, NULL, 0);
- gal_checkset_float_l_0(arg, &p->smp.mirrordist, "mirrordist", key,
SPACK,
- NULL, 0);
++ gal_checkset_float_l_0(arg, &p->smp.mirrordist, "mirrordist", key,
++ SPACK, NULL, 0);
p->up.mirrordistset=1;
break;
case 'Q':
- floatl0s1(arg, &p->smp.minmodeq, "minmodeq", key, SPACK, NULL, 0);
- gal_checkset_float_l_0_s_1(arg, &p->smp.minmodeq, "minmodeq", key,
SPACK,
- NULL, 0);
++ gal_checkset_float_l_0_s_1(arg, &p->smp.minmodeq, "minmodeq", key,
++ SPACK, NULL, 0);
p->up.minmodeqset=1;
break;
case 511:
@@@ -675,17 -716,17 +692,18 @@@
p->up.openingngbset=1;
break;
case 'u':
- floatl0(arg, &p->sigclipmultip, "sigclipmultip", key, SPACK,
- NULL, 0);
- gal_checkset_float_l_0(arg, &p->sigclipmultip, "sigclipmultip", key,
SPACK,
- NULL, 0);
++ gal_checkset_float_l_0(arg, &p->sigclipmultip, "sigclipmultip", key,
++ SPACK, NULL, 0);
p->up.sigclipmultipset=1;
break;
case 'r':
- floatl0s1(arg, &p->sigcliptolerance, "sigcliptolerance", key, SPACK,
- NULL, 0);
- gal_checkset_float_l_0_s_1(arg, &p->sigcliptolerance,
"sigcliptolerance",
- key, SPACK, NULL, 0);
++ gal_checkset_float_l_0_s_1(arg, &p->sigcliptolerance,
++ "sigcliptolerance", key, SPACK, NULL, 0);
p->up.sigcliptoleranceset=1;
break;
case 'R':
- anyfloat(arg, &p->dthresh, "dthresh", key, SPACK, NULL, 0);
- gal_checkset_any_float(arg, &p->dthresh, "dthresh", key, SPACK, NULL,
0);
++ gal_checkset_any_float(arg, &p->dthresh, "dthresh", key, SPACK,
++ NULL, 0);
p->up.dthreshset=1;
break;
case 'i':
@@@ -693,8 -735,8 +712,8 @@@
p->up.detsnminareaset=1;
break;
case 510:
- sizetelzero(arg, &p->detsnhistnbins, "detsnhistnbins", key,
- SPACK, NULL, 0);
- gal_checkset_sizet_el_zero(arg, &p->detsnhistnbins, "detsnhistnbins",
key,
- SPACK, NULL, 0);
++ gal_checkset_sizet_el_zero(arg, &p->detsnhistnbins, "detsnhistnbins",
++ key, SPACK, NULL, 0);
p->up.detsnhistnbinsset=1;
break;
case 'c':
@@@ -750,9 -799,9 +773,9 @@@
break;
case 514:
- sizetelzero(arg, &p->clumpsnhistnbins, "clumpsnhistnbins", key,
- SPACK, NULL, 0);
- gal_checkset_sizet_el_zero(arg, &p->segsnhistnbins, "segsnhistnbins",
key,
- SPACK, NULL, 0);
- p->up.segsnhistnbinsset=1;
++ gal_checkset_sizet_el_zero(arg, &p->clumpsnhistnbins,
++ "clumpsnhistnbins", key, SPACK, NULL, 0);
+ p->up.clumpsnhistnbinsset=1;
break;
case 513:
p->segmentationname="a";
diff --cc src/noisechisel/cite.h
index 38b6c28,8748c5b..e587b45
--- a/src/noisechisel/cite.h
+++ b/src/noisechisel/cite.h
@@@ -23,15 -23,15 +23,15 @@@ along with Gnuastro. If not, see <http:
#ifndef CITE_H
#define CITE_H
--#define SUBTRACTSKYBIBTEX ""
++#define NOISECHISELBIBTEX ""
#define PRINTCITEABORT { \
printf("\nWe hope %s has been useful for your research.\n"
\
"Citations are vital for the continued work on %s.\n" \
"Thank you for citing it in your research paper.\n" \
"\nPlease cite as \"%s\":\n\n%s\n\n%s", \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GNUASTROBIBTEX, \
- SUBTRACTSKYBIBTEX); \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GAL_STRINGS_BIBTEX, \
- SUBTRACTSKYBIBTEX); \
++ SPACK_NAME, SPACK_NAME, SPACK_STRING, \
++ GAL_STRINGS_MAIN_BIBTEX, NOISECHISELBIBTEX);
\
exit(EXIT_SUCCESS);
\
}
diff --cc src/noisechisel/detection.c
index cc647ff,336b3e8..1d6f04f
--- a/src/noisechisel/detection.c
+++ b/src/noisechisel/detection.c
@@@ -251,35 -255,30 +255,37 @@@ detlabelsn(struct noisechiselparams *p
/* calculate the signal to noise for successful detections: */
for(i=1;i<*numlabs;++i)
- if(areas[i]>detsnminarea && xys[i*xyscol+2]>0.0f)
- {
- /* Find the flux weighted center of this object in each
- dimension to find the mesh it belongs to and get the
- standard deviation at this point. Note that the standard
- deviation on the grid was stored in smp->garray2. The error
- should then be taken to the power of two and if the sky is
- subtracted, a 2 should be multiplied to it.*/
- err =
- smp->garray2[gal_mesh_img_xy_to_mesh_id(smp,
-
xys[i*xyscol]/xys[i*xyscol+2],
-
xys[i*xyscol+1]/xys[i*xyscol+2])];
- err *= p->skysubtracted ? err : 2.0f*err;
-
- /* Set the index in the sntable to store the Signal to noise
- ratio. When we are dealing with the noise, we only want the
- non-zero signal to noise values, so we will just use a
- counter. But for initial detections, it is very important
- that their Signal to noise ratio be placed in the same
- index as their label. */
- ave=brightnesses[i]/areas[i];
- ind = p->b0f1 ? i : counter++;
- sntable[ind]=sqrt( (float)(areas[i])/cpscorr ) * ave / sqrt(ave+err);
- }
+ {
+ ave=brightnesses[i]/areas[i];
+ if(areas[i]>detsnminarea && ave>0.0f && xys[i*xyscol+2]>0.0f)
+ {
+ /* Find the flux weighted center of this object in each
+ dimension to find the mesh it belongs to and get the
+ standard deviation at this point. Note that the standard
+ deviation on the grid was stored in smp->garray2. The error
+ should then be taken to the power of two and if the sky is
+ subtracted, a 2 should be multiplied to it.*/
- err = smp->garray2[imgxytomeshid(smp, xys[i*xyscol]/xys[i*xyscol+2],
- xys[i*xyscol+1]/xys[i*xyscol+2])];
++ err = smp->garray2[
++ gal_mesh_img_xy_to_mesh_id(smp,
++ xys[i*xyscol]/xys[i*xyscol+2],
++ xys[i*xyscol+1]/xys[i*xyscol+2]) ];
+ err *= p->skysubtracted ? err : 2.0f*err;
+
+ /* Set the index in the sntable to store the Signal to noise
+ ratio. When we are dealing with the noise, we only want the
+ non-zero signal to noise values, so we will just use a
+ counter. But for initial detections, it is very important
+ that their Signal to noise ratio be placed in the same
+ index as their label. */
+ ind = p->b0f1 ? i : counter++;
+ sntable[ind] = ( sqrt( (float)(areas[i])/cpscorr )
+ * ave / sqrt(ave+err) );
+ }
+ }
+
+
- /* In background mdoe, set the number of labels to the number of
++ /* In background mode, set the number of labels to the number of
+ acceptable S/N values measured. */
if(p->b0f1==0) *numlabs=counter;
diff --cc src/noisechisel/noisechisel.c
index 9402719,e2b29a7..388ca01
--- a/src/noisechisel/noisechisel.c
+++ b/src/noisechisel/noisechisel.c
@@@ -110,18 -115,28 +115,23 @@@ makeoutput(struct noisechiselparams *p
interpolating or smoothing the image, so we have put a "raw" in
the comments of each variable.*/
fpt=&p->maxstd;
- add_to_fitsheaderll(&keys, TFLOAT, "MAXSTD", 0, fpt, 0,
- "Maximum raw mesh sky standard deviation.", 0, NULL);
+ gal_fitsarray_add_to_fits_header_ll(&keys, TFLOAT, "MAXSTD", 0, fpt, 0,
+ "Maximum raw mesh sky standard "
+ "deviation.", 0, NULL);
fpt=&p->minstd;
- add_to_fitsheaderll(&keys, TFLOAT, "MINSTD", 0, fpt, 0,
- "Minimum raw mesh sky standard deviation.", 0, NULL);
+ gal_fitsarray_add_to_fits_header_ll(&keys, TFLOAT, "MINSTD", 0, fpt, 0,
+ "Minimum raw mesh sky standard "
+ "deviation.", 0, NULL);
fpt=&p->medstd;
- add_to_fitsheaderll(&keys, TFLOAT, "MEDSTD", 0, fpt, 0,
- "Median raw mesh standard deviation.", 0, NULL);
- arraytofitsimg(p->cp.output, "Standard deviation", FLOAT_IMG, std,
- s0, s1, 0, p->wcs, keys, SPACK_STRING);
+ gal_fitsarray_add_to_fits_header_ll(&keys, TFLOAT, "MEDSTD", 0, fpt, 0,
+ "Median raw mesh standard "
+ "deviation.", 0, NULL);
+ gal_fitsarray_array_to_fits_img(p->cp.output, "Standard deviation",
+ FLOAT_IMG, std, s0, s1, 0, p->wcs,
+ keys, SPACK_STRING);
keys=NULL;
- /* Save the sky subtracted image if desired: */
- if(p->skysubedname)
- gal_fitsarray_array_to_fits_img(p->skysubedname, "Sky subtracted",
- FLOAT_IMG, p->imgss, s0, s1, p->anyblank,
- p->wcs, NULL, SPACK_STRING);
+
/* Clean up: */
free(sky);
free(std);
diff --cc src/noisechisel/thresh.c
index 61a853f,f00b6f3..ab634e3
--- a/src/noisechisel/thresh.c
+++ b/src/noisechisel/thresh.c
@@@ -329,16 -337,8 +331,16 @@@ snthresh(struct noisechiselparams *p, f
/* Sort the signal to noise ratios and remove their outliers */
- qsort(sntable, size, sizeof *sntable, floatincreasing);
+ qsort(sntable, size, sizeof *sntable, gal_qsort_float_increasing);
- gal_statistics_remove_outliers_flat_cdf(sntable, &size);
+
+ /* The removal of outliers was useful when the S/N was calculated
+ separately on each mesh (thus there were very few
+ points). However, now that the S/N is calculated over the full
+ image, the number of pseudo-detections and clumps is so high that
+ these outliers will not play a significant role in the S/N
+ threshold (unless you set unreasonably high quantiles!). So This
+ is commented now. */
- /*removeoutliers_flatcdf(sntable, &size);*/
++ /*gal_statistics_remove_outliers_flat_cdf(sntable, &size);*/
/* Store the SN value. */
@@@ -364,15 -364,19 +366,15 @@@
ff=(f=sntable)+numlabs; do printf("%f\n", *f++); while(f<ff);
*/
- /* histname has to be set to NULL so automaticoutput can
+ /* histname has to be set to NULL so gal_checkset_automatic_output can
safey free it. */
- histname=NULL;
sprintf(cline, "# %s\n# %s started on %s"
"# Input: %s (hdu: %s)\n"
"# S/N distribution histogram of %lu sky %s.\n"
"# The %.3f quantile has an S/N of %.4f.",
SPACK_STRING, SPACK_NAME, ctime(&p->rawtime),
p->up.inputname, p->cp.hdu, size, name, quant, sn);
- savehist(sntable, size, snhistnbins, histname, cline);
- gal_checkset_automatic_output(p->up.inputname, suffix,
- p->cp.removedirinfo, p->cp.dontdelete,
- &histname);
+ gal_statistics_save_hist(sntable, size, snhistnbins, histname, cline);
free(histname);
}
}
diff --cc src/noisechisel/ui.c
index a2875c0,b662082..84c7f35
--- a/src/noisechisel/ui.c
+++ b/src/noisechisel/ui.c
@@@ -385,15 -385,16 +387,16 @@@ readconfig(char *filename, struct noise
else if(strcmp(name, "segquant")==0)
{
if(up->segquantset) continue;
- floatl0s1(value, &p->segquant, name, key, SPACK, filename, lineno);
+ gal_checkset_float_l_0_s_1(value, &p->segquant, name, key, SPACK,
+ filename, lineno);
up->segquantset=1;
}
- else if(strcmp(name, "segsnhistnbins")==0)
+ else if(strcmp(name, "clumpsnhistnbins")==0)
{
- if(up->segsnhistnbinsset) continue;
- gal_checkset_sizet_el_zero(value, &p->segsnhistnbins, name, key,
- SPACK, filename, lineno);
- up->segsnhistnbinsset=1;
+ if(up->clumpsnhistnbinsset) continue;
- sizetelzero(value, &p->clumpsnhistnbins, name, key, SPACK,
- filename, lineno);
++ gal_checkset_sizet_el_zero(value, &p->clumpsnhistnbins, name, key,
++ SPACK,filename, lineno);
+ up->clumpsnhistnbinsset=1;
}
else if(strcmp(name, "gthresh")==0)
{
@@@ -447,40 -448,40 +450,15 @@@ printvalues(FILE *fp, struct noisechise
commented line explaining the options in that group. */
fprintf(fp, "\n# Input:\n");
if(cp->hduset)
-- {
- if(stringhasspace(cp->hdu))
- fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "hdu", cp->hdu);
- else
- fprintf(fp, CONF_SHOWFMT"%s\n", "hdu", cp->hdu);
- }
- if(gal_checkset_string_has_space(cp->hdu))
- fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "hdu", cp->hdu);
- else
- fprintf(fp, CONF_SHOWFMT"%s\n", "hdu", cp->hdu);
- }
++ GAL_CHECKSET_PRINT_STRING_MAYBE_WITH_SPACE("hdu", cp->hdu);
if(up->masknameset)
-- {
- if(stringhasspace(up->maskname))
- fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "mask", up->maskname);
- else
- fprintf(fp, CONF_SHOWFMT"%s\n", "mask", up->maskname);
- }
- if(gal_checkset_string_has_space(up->maskname))
- fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "mask", up->maskname);
- else
- fprintf(fp, CONF_SHOWFMT"%s\n", "mask", up->maskname);
- }
++ GAL_CHECKSET_PRINT_STRING_MAYBE_WITH_SPACE("mask", up->maskname);
if(up->mhdu)
-- {
- if(stringhasspace(up->mhdu))
- fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "mhdu", up->mhdu);
- else
- fprintf(fp, CONF_SHOWFMT"%s\n", "mhdu", up->mhdu);
- }
- if(gal_checkset_string_has_space(up->mhdu))
- fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "mhdu", up->mhdu);
- else
- fprintf(fp, CONF_SHOWFMT"%s\n", "mhdu", up->mhdu);
- }
++ GAL_CHECKSET_PRINT_STRING_MAYBE_WITH_SPACE("mhdu", up->mhdu);
if(up->kernelnameset)
-- {
- if(stringhasspace(up->kernelname))
- fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "kernel", up->kernelname);
- else
- fprintf(fp, CONF_SHOWFMT"%s\n", "kernel", up->kernelname);
- }
- if(gal_checkset_string_has_space(up->kernelname))
- fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "kernel", up->kernelname);
- else
- fprintf(fp, CONF_SHOWFMT"%s\n", "kernel", up->kernelname);
- }
++ GAL_CHECKSET_PRINT_STRING_MAYBE_WITH_SPACE("kernel", up->kernelname);
if(up->khdu)
-- {
- if(stringhasspace(up->khdu))
- fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "khdu", up->khdu);
- else
- fprintf(fp, CONF_SHOWFMT"%s\n", "khdu", up->khdu);
- }
- if(gal_checkset_string_has_space(up->khdu))
- fprintf(fp, CONF_SHOWFMT"\"%s\"\n", "khdu", up->khdu);
- else
- fprintf(fp, CONF_SHOWFMT"%s\n", "khdu", up->khdu);
- }
++ GAL_CHECKSET_PRINT_STRING_MAYBE_WITH_SPACE("khdu", up->khdu);
if(up->skysubtractedset)
fprintf(fp, CONF_SHOWFMT"%d\n", "skysubtracted", p->skysubtracted);
if(up->minbfracset)
@@@ -660,21 -661,21 +638,21 @@@ checkifset(struct noisechiselparams *p
/* Segmentation: */
if(up->segsnminareaset==0)
- REPORT_NOTSET("segsnminarea");
+ GAL_CONFIGFILES_REPORT_NOTSET("segsnminarea");
if(up->keepmaxnearriverset==0)
- REPORT_NOTSET("keepmaxnearriver");
+ GAL_CONFIGFILES_REPORT_NOTSET("keepmaxnearriver");
if(up->segquantset==0)
- REPORT_NOTSET("segquant");
+ GAL_CONFIGFILES_REPORT_NOTSET("segquant");
- if(up->segsnhistnbinsset==0)
- GAL_CONFIGFILES_REPORT_NOTSET("segsnhistnbins");
+ if(up->clumpsnhistnbinsset==0)
- REPORT_NOTSET("clumpsnhistnbins");
++ GAL_CONFIGFILES_REPORT_NOTSET("clumpsnhistnbins");
if(up->gthreshset==0)
- REPORT_NOTSET("gthresh");
+ GAL_CONFIGFILES_REPORT_NOTSET("gthresh");
if(up->minriverlengthset==0)
- REPORT_NOTSET("minriverlength");
+ GAL_CONFIGFILES_REPORT_NOTSET("minriverlength");
if(up->objbordersnset==0)
- REPORT_NOTSET("objbordersn");
+ GAL_CONFIGFILES_REPORT_NOTSET("objbordersn");
- END_OF_NOTSET_REPORT;
+ GAL_CONFIGFILES_END_OF_NOTSET_REPORT;
}
@@@ -702,91 -703,99 +680,102 @@@
void
sanitycheck(struct noisechiselparams *p)
{
- struct meshparams *smp=&p->smp;
+ struct gal_mesh_params *smp=&p->smp;
+ /* Make sure the input file exists. */
- checkfile(p->up.inputname);
++ gal_checkset_check_file(p->up.inputname);
+
/* Set the maskname and mask hdu accordingly: */
- fileorextname(p->up.inputname, p->cp.hdu, p->up.masknameset,
- &p->up.maskname, p->up.mhdu, p->up.mhduset, "mask");
+ gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu,
p->up.masknameset,
+ &p->up.maskname, p->up.mhdu, p->up.mhduset,
+ "mask");
/* Set the output name: */
if(p->cp.output)
- gal_checkset_check_remove_file(p->cp.output, p->cp.dontdelete);
+ {
- checkremovefile(p->cp.output, p->cp.dontdelete);
++ gal_checkset_check_remove_file(p->cp.output, p->cp.dontdelete);
+
+ /* When the output name is given (possibly with directory
+ information), the user certainly wants the directory
+ information, if they have bothered to include it. */
+ p->cp.removedirinfo=0;
+
+ }
else
- automaticoutput(p->up.inputname, "_labeled.fits", p->cp.removedirinfo,
- p->cp.dontdelete, &p->cp.output);
+ gal_checkset_automatic_output(p->up.inputname, "_labeled.fits",
+ p->cp.removedirinfo, p->cp.dontdelete,
+ &p->cp.output);
/* Set the check image names: */
if(p->meshname)
{
p->meshname=NULL; /* Was not allocated before! */
- automaticoutput(p->cp.output, "_meshs.fits", p->cp.removedirinfo,
- p->cp.dontdelete, &p->meshname);
- gal_checkset_automatic_output(p->up.inputname, "_meshs.fits",
++ gal_checkset_automatic_output(p->cp.output, "_meshs.fits",
+ p->cp.removedirinfo, p->cp.dontdelete,
+ &p->meshname);
}
if(p->threshname)
{
p->threshname=NULL;
- automaticoutput(p->cp.output, "_thresh.fits", p->cp.removedirinfo,
- p->cp.dontdelete, &p->threshname);
- gal_checkset_automatic_output(p->up.inputname, "_thresh.fits",
++ gal_checkset_automatic_output(p->cp.output, "_thresh.fits",
+ p->cp.removedirinfo, p->cp.dontdelete,
+ &p->threshname);
}
if(p->detectionname)
{
p->detectionname=NULL;
- automaticoutput(p->cp.output, "_det.fits", p->cp.removedirinfo,
- p->cp.dontdelete, &p->detectionname);
- gal_checkset_automatic_output(p->up.inputname, "_det.fits",
++ gal_checkset_automatic_output(p->cp.output, "_det.fits",
+ p->cp.removedirinfo, p->cp.dontdelete,
+ &p->detectionname);
}
if(p->detectionskyname)
{
p->detectionskyname=NULL;
- automaticoutput(p->cp.output, "_detsky.fits", p->cp.removedirinfo,
- p->cp.dontdelete, &p->detectionskyname);
- gal_checkset_automatic_output(p->up.inputname, "_detsky.fits",
++ gal_checkset_automatic_output(p->cp.output, "_detsky.fits",
+ p->cp.removedirinfo, p->cp.dontdelete,
+ &p->detectionskyname);
}
- if(p->detectionsnname)
+ if(p->detsnhistnbins)
{
- p->detectionsnname=NULL;
- gal_checkset_automatic_output(p->up.inputname, "_detsn.fits",
+ p->detectionsnhist=NULL;
- automaticoutput(p->cp.output, "_detsn.txt", p->cp.removedirinfo,
- p->cp.dontdelete, &p->detectionsnhist);
++ gal_checkset_automatic_output(p->cp.output, "_detsn.fits",
+ p->cp.removedirinfo, p->cp.dontdelete,
- &p->detectionsnname);
++ &p->detectionsnhist);
}
if(p->skyname)
{
p->skyname=NULL;
- automaticoutput(p->cp.output, "_sky.fits", p->cp.removedirinfo,
- p->cp.dontdelete, &p->skyname);
- gal_checkset_automatic_output(p->up.inputname, "_sky.fits",
++ gal_checkset_automatic_output(p->cp.output, "_sky.fits",
+ p->cp.removedirinfo, p->cp.dontdelete,
+ &p->skyname);
}
if(p->segmentationname)
{
p->segmentationname=NULL;
- automaticoutput(p->cp.output, "_seg.fits", p->cp.removedirinfo,
- p->cp.dontdelete, &p->segmentationname);
- gal_checkset_automatic_output(p->up.inputname, "_seg.fits",
- p->cp.removedirinfo, p->cp.dontdelete,
- &p->segmentationname);
++ gal_checkset_automatic_output(p->cp.output, "_seg.fits",
++ p->cp.removedirinfo,
++ p->cp.dontdelete, &p->segmentationname);
}
- if(p->clumpsnname)
+ if(p->clumpsnhistnbins)
{
- p->clumpsnname=NULL;
- gal_checkset_automatic_output(p->up.inputname, "_clumpsn.fits",
- p->cp.removedirinfo, p->cp.dontdelete,
- &p->clumpsnname);
- }
- if(p->skysubedname)
- {
- p->skysubedname=NULL;
- gal_checkset_automatic_output(p->up.inputname, "_skysubed.fits",
- p->cp.removedirinfo, p->cp.dontdelete,
- &p->skysubedname);
+ p->clumpsnhist=NULL;
- automaticoutput(p->cp.output, "_clumpsn.txt", p->cp.removedirinfo,
- p->cp.dontdelete, &p->clumpsnhist);
++ gal_checkset_automatic_output(p->cp.output, "_clumpsn.txt",
++ p->cp.removedirinfo,
++ p->cp.dontdelete, &p->clumpsnhist);
}
if(p->maskdetname)
{
p->maskdetname=NULL;
- automaticoutput(p->cp.output, "_maskdet.fits", p->cp.removedirinfo,
- p->cp.dontdelete, &p->maskdetname);
- gal_checkset_automatic_output(p->up.inputname, "_maskdet.fits",
++ gal_checkset_automatic_output(p->cp.output, "_maskdet.fits",
+ p->cp.removedirinfo, p->cp.dontdelete,
+ &p->maskdetname);
}
-
/* Other checks: */
- if(smp->numnearest<MINACCEPTABLENEAREST)
+ if(smp->numnearest<GAL_MESH_MIN_ACCEPTABLE_NEAREST)
error(EXIT_FAILURE, 0, "The smallest possible number for `--numnearest' "
- "(`-n') is %d. You have asked for: %lu.", MINACCEPTABLENEAREST,
- smp->numnearest);
+ "(`-n') is %d. You have asked for: %lu.",
+ GAL_MESH_MIN_ACCEPTABLE_NEAREST, smp->numnearest);
}
diff --cc src/subtractsky/cite.h
index 54ec484,ec98919..f010378
--- a/src/subtractsky/cite.h
+++ b/src/subtractsky/cite.h
@@@ -30,8 -30,8 +30,8 @@@ along with Gnuastro. If not, see <http:
"Citations are vital for the continued work on %s.\n" \
"Thank you for citing it in your research paper.\n" \
"\nPlease cite as \"%s\":\n\n%s\n\n%s", \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GNUASTROBIBTEX, \
- SUBTRACTSKYBIBTEX); \
- SPACK_NAME, SPACK_NAME, SPACK_STRING, GAL_STRINGS_BIBTEX, \
- SUBTRACTSKYBIBTEX); \
++ SPACK_NAME, SPACK_NAME, SPACK_STRING, \
++ GAL_STRINGS_MAIN_BIBTEX, SUBTRACTSKYBIBTEX);
\
exit(EXIT_SUCCESS);
\
}
diff --cc src/subtractsky/main.h
index 0aa9a83,c130a8d..dff3d6e
--- a/src/subtractsky/main.h
+++ b/src/subtractsky/main.h
@@@ -69,9 -70,9 +69,9 @@@ struct uiparam
struct subtractskyparams
{
/* Other structures: */
-- struct uiparams up; /* User interface parameters. */
- struct commonparams cp; /* Common parameters. */
- struct meshparams mp; /* Mesh grid of input image. */
++ struct uiparams up; /* User interface parameters. */
+ struct gal_commonparams cp; /* Common parameters. */
- struct gal_mesh_params mp; /* Mesh grid of input image. */
++ struct gal_mesh_params mp; /* Mesh grid of input image. */
/* Input: */
int nwcs; /* Number of WCS structures. */
diff --cc src/subtractsky/ui.c
index 707e881,2914b58..ed3edf4
--- a/src/subtractsky/ui.c
+++ b/src/subtractsky/ui.c
@@@ -452,13 -450,10 +452,14 @@@ checkifset(struct subtractskyparams *p
void
sanitycheck(struct subtractskyparams *p)
{
+
+ /* Make sure the input file exists. */
- checkfile(p->up.inputname);
++ gal_checkset_check_file(p->up.inputname);
+
/* Set the maskname and mask hdu accordingly: */
- fileorextname(p->up.inputname, p->cp.hdu, p->up.masknameset,
- &p->up.maskname, p->up.mhdu, p->up.mhduset, "mask");
+ gal_fitsarray_file_or_ext_name(p->up.inputname, p->cp.hdu,
p->up.masknameset,
+ &p->up.maskname, p->up.mhdu, p->up.mhduset,
+ "mask");
/* Set the output name: */
if(p->cp.output)
- [gnuastro-commits] [gnuastro] master updated (c011627 -> 3cfdb3e), Mohammad Akhlaghi, 2016/05/29
- [gnuastro-commits] (no subject), Mohammad Akhlaghi, 2016/05/29
- [gnuastro-commits] (no subject), Mohammad Akhlaghi, 2016/05/29
- [gnuastro-commits] (no subject), Mohammad Akhlaghi, 2016/05/29
- [gnuastro-commits] (no subject), Mohammad Akhlaghi, 2016/05/29
- [gnuastro-commits] (no subject),
Mohammad Akhlaghi <=
- [gnuastro-commits] (no subject), Mohammad Akhlaghi, 2016/05/29