[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 888032e: Arithmetic uses x instead of * for mu
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 888032e: Arithmetic uses x instead of * for multiplication |
Date: |
Mon, 22 May 2017 19:38:07 -0400 (EDT) |
branch: master
commit 888032ec91cce1aa846b657a47945851217b18bd
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
Arithmetic uses x instead of * for multiplication
Until now `*' represented multiplication in the Arithmetic
program. However, `*' is meaningful to the shell (all the files in a
directory), so the users would have to quote it when they wanted to
multiply inputs. So as suggested by Guillaume Mahler, we are now using the
easier to use `x' which is also more similar to the way we write
multiplication on paper. It is not really too likely someone will want to
work on a file named `x', so it is reasonable.
Other issues solved with this commit:
- The main parameters structure of Arithmetic was still called
`imgarithparams'! This is now corrected to `arithmeticparams'.
- When reading the `ge' operator, we were mistakenly setting the operator
to `GAL_ARITHMETIC_OP_LE'! This has been corrected.
- For easier readability (mainly done in the process of finding the
previous issue), the operators in `BINARY_RT_LT_SET' are now immediately
under each other.
---
bin/arithmetic/arithmetic.c | 10 ++---
bin/arithmetic/arithmetic.h | 2 +-
bin/arithmetic/main.c | 2 +-
bin/arithmetic/main.h | 2 +-
bin/arithmetic/operands.c | 6 +--
bin/arithmetic/operands.h | 6 +--
bin/arithmetic/ui.c | 12 +++---
bin/arithmetic/ui.h | 4 +-
doc/gnuastro.texi | 19 ++--------
lib/arithmetic-binary.c | 84 ++++++++++++++++++++---------------------
tests/arithmetic/onlynumbers.sh | 2 +-
11 files changed, 69 insertions(+), 80 deletions(-)
diff --git a/bin/arithmetic/arithmetic.c b/bin/arithmetic/arithmetic.c
index 4c8bc6b..1456a12 100644
--- a/bin/arithmetic/arithmetic.c
+++ b/bin/arithmetic/arithmetic.c
@@ -59,7 +59,7 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
CTYPE a=*(CTYPE *)(data->array); if(a>0) return a; }
static size_t
-set_number_of_operands(struct imgarithparams *p, gal_data_t *data,
+set_number_of_operands(struct arithmeticparams *p, gal_data_t *data,
char *token_string)
{
/* Check if its a number. */
@@ -129,7 +129,7 @@ set_number_of_operands(struct imgarithparams *p, gal_data_t
*data,
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)
+reversepolish(struct arithmeticparams *p)
{
int op=0, nop=0;
unsigned int numop, i;
@@ -163,7 +163,7 @@ reversepolish(struct imgarithparams *p)
{ op=GAL_ARITHMETIC_OP_PLUS; nop=2; }
else if (!strcmp(token->v, "-" ))
{ op=GAL_ARITHMETIC_OP_MINUS; nop=2; }
- else if (!strcmp(token->v, "*" ))
+ else if (!strcmp(token->v, "x" ))
{ op=GAL_ARITHMETIC_OP_MULTIPLY; nop=2; }
else if (!strcmp(token->v, "/" ))
{ op=GAL_ARITHMETIC_OP_DIVIDE; nop=2; }
@@ -220,7 +220,7 @@ reversepolish(struct imgarithparams *p)
else if (!strcmp(token->v, "gt" ))
{ op=GAL_ARITHMETIC_OP_GT; nop=2; }
else if (!strcmp(token->v, "ge"))
- { op=GAL_ARITHMETIC_OP_LE; nop=2; }
+ { op=GAL_ARITHMETIC_OP_GE; nop=2; }
else if (!strcmp(token->v, "eq"))
{ op=GAL_ARITHMETIC_OP_EQ; nop=2; }
else if (!strcmp(token->v, "ne"))
@@ -393,7 +393,7 @@ reversepolish(struct imgarithparams *p)
/************* Top function *************/
/***************************************************************/
void
-imgarith(struct imgarithparams *p)
+imgarith(struct arithmeticparams *p)
{
/* Parse the arguments */
reversepolish(p);
diff --git a/bin/arithmetic/arithmetic.h b/bin/arithmetic/arithmetic.h
index 2b72b44..e7f2ea0 100644
--- a/bin/arithmetic/arithmetic.h
+++ b/bin/arithmetic/arithmetic.h
@@ -24,6 +24,6 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
#define IMGARITH_H
void
-imgarith(struct imgarithparams *p);
+imgarith(struct arithmeticparams *p);
#endif
diff --git a/bin/arithmetic/main.c b/bin/arithmetic/main.c
index 5756181..96d0f13 100644
--- a/bin/arithmetic/main.c
+++ b/bin/arithmetic/main.c
@@ -36,7 +36,7 @@ int
main (int argc, char *argv[])
{
struct timeval t1;
- struct imgarithparams p={{{0},0},0};
+ struct arithmeticparams p={{{0},0},0};
/* Set the starting time. */
time(&p.rawtime);
diff --git a/bin/arithmetic/main.h b/bin/arithmetic/main.h
index a81347e..78ac2fb 100644
--- a/bin/arithmetic/main.h
+++ b/bin/arithmetic/main.h
@@ -62,7 +62,7 @@ struct operand
-struct imgarithparams
+struct arithmeticparams
{
/* Other structures: */
struct gal_options_common_params cp; /* Common parameters. */
diff --git a/bin/arithmetic/operands.c b/bin/arithmetic/operands.c
index 73e1514..3d6b77a 100644
--- a/bin/arithmetic/operands.c
+++ b/bin/arithmetic/operands.c
@@ -42,7 +42,7 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
size_t
-operands_num(struct imgarithparams *p)
+operands_num(struct arithmeticparams *p)
{
size_t counter=0;
struct operand *tmp=NULL;
@@ -56,7 +56,7 @@ operands_num(struct imgarithparams *p)
void
-operands_add(struct imgarithparams *p, char *filename, gal_data_t *data)
+operands_add(struct arithmeticparams *p, char *filename, gal_data_t *data)
{
struct operand *newnode;
@@ -96,7 +96,7 @@ operands_add(struct imgarithparams *p, char *filename,
gal_data_t *data)
gal_data_t *
-operands_pop(struct imgarithparams *p, char *operator)
+operands_pop(struct arithmeticparams *p, char *operator)
{
size_t i;
gal_data_t *data;
diff --git a/bin/arithmetic/operands.h b/bin/arithmetic/operands.h
index 8ea6e97..0854e98 100644
--- a/bin/arithmetic/operands.h
+++ b/bin/arithmetic/operands.h
@@ -24,13 +24,13 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
#define OPERANDS_H
size_t
-operands_num(struct imgarithparams *p);
+operands_num(struct arithmeticparams *p);
void
-operands_add(struct imgarithparams *p, char *filename, gal_data_t *data);
+operands_add(struct arithmeticparams *p, char *filename, gal_data_t *data);
gal_data_t *
-operands_pop(struct imgarithparams *p, char *operator);
+operands_pop(struct arithmeticparams *p, char *operator);
#endif
diff --git a/bin/arithmetic/ui.c b/bin/arithmetic/ui.c
index 5640ceb..ce995e6 100644
--- a/bin/arithmetic/ui.c
+++ b/bin/arithmetic/ui.c
@@ -72,7 +72,7 @@ doc[] = GAL_STRINGS_TOP_HELP_INFO PROGRAM_NAME" will do
arithmetic "
"b.fits + 2 /' (or more simply use the `average' operator with "
"`a.fits b.fits average'). Please see the manual for more information. "
"\n\n"PROGRAM_NAME" recognizes a large collection of standard operators, "
- "including basic arithmetic (e.g., +, -, *, /), mathematical (e.g., abs, "
+ "including basic arithmetic (e.g., +, -, x, /), mathematical (e.g., abs, "
"pow, sqrt, log), statistical (minvalue, min, max, average), comparison "
"(e.g., lt, le, gt), logical (e.g., and, or, not), the full set of bitwise "
"operators, and numeric type conversion operators to all known types. "
@@ -108,7 +108,7 @@ doc[] = GAL_STRINGS_TOP_HELP_INFO PROGRAM_NAME" will do
arithmetic "
/********* Initialize & Parse command-line **************/
/**************************************************************/
static void
-ui_initialize_options(struct imgarithparams *p,
+ui_initialize_options(struct arithmeticparams *p,
struct argp_option *program_options,
struct argp_option *gal_commonopts_options)
{
@@ -166,7 +166,7 @@ ui_initialize_options(struct imgarithparams *p,
error_t
parse_opt(int key, char *arg, struct argp_state *state)
{
- struct imgarithparams *p = state->input;
+ struct arithmeticparams *p = state->input;
/* Pass `gal_options_common_params' into the child parser. */
state->child_inputs[0] = &p->cp;
@@ -226,7 +226,7 @@ parse_opt(int key, char *arg, struct argp_state *state)
/* Sanity check on options AND arguments. If only option values are to be
checked, use `ui_read_check_only_options'. */
static void
-ui_check_options_and_arguments(struct imgarithparams *p)
+ui_check_options_and_arguments(struct arithmeticparams *p)
{
int output_checked=0;
size_t numfits=0, numhdus=0;
@@ -305,7 +305,7 @@ ui_check_options_and_arguments(struct imgarithparams *p)
/************ Set the parameters *************/
/**************************************************************/
void
-ui_read_check_inputs_setup(int argc, char *argv[], struct imgarithparams *p)
+ui_read_check_inputs_setup(int argc, char *argv[], struct arithmeticparams *p)
{
size_t i;
struct gal_options_common_params *cp=&p->cp;
@@ -380,7 +380,7 @@ ui_read_check_inputs_setup(int argc, char *argv[], struct
imgarithparams *p)
/************ Free allocated, report *************/
/**************************************************************/
void
-freeandreport(struct imgarithparams *p, struct timeval *t1)
+freeandreport(struct arithmeticparams *p, struct timeval *t1)
{
free(p->cp.output);
diff --git a/bin/arithmetic/ui.h b/bin/arithmetic/ui.h
index 169b51b..7ef7468 100644
--- a/bin/arithmetic/ui.h
+++ b/bin/arithmetic/ui.h
@@ -24,9 +24,9 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
#define UI_H
void
-ui_read_check_inputs_setup(int argc, char *argv[], struct imgarithparams *p);
+ui_read_check_inputs_setup(int argc, char *argv[], struct arithmeticparams *p);
void
-freeandreport(struct imgarithparams *p, struct timeval *t1);
+freeandreport(struct arithmeticparams *p, struct timeval *t1);
#endif
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index cff80b2..4877f69 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -8480,20 +8480,9 @@ Addition, so address@hidden 5 +}'' is equivalent to
@mymath{4+5}.
@item -
Subtraction, so address@hidden 5 -}'' is equivalent to @mymath{4-5}.
address@hidden *
-Multiplication, so address@hidden 5 "*"}'' is equivalent to
address@hidden On the command-line or in scripts, be sure to quote
-the multiplication sign (for example @command{"*"}).
-
address@hidden
address@hidden
address@hidden reminder for multiplication:} please quote the
address@hidden sign (for example, @command{"*"} or
address@hidden'*'}). Without quotation, the shell will replace @command{*}
-with a list of all the files in your working directory which can
-produce unpredictable outputs. In any case, the input images are not
-affected, they are only read.
address@hidden cartouche
address@hidden x
+Multiplication, so address@hidden 5 x}'' is equivalent to
address@hidden
@item /
Division, so address@hidden 5 /}'' is equivalent to @mymath{4/5}.
@@ -8878,7 +8867,7 @@ $ astarithmetic -q 10.32 3.84 - 2.7 pow
$ astarithmetic 1 image.fits / --out=inverse.fits
## Multiply each pixel in image by -1:
-$ astarithmetic image.fits -1 "*" --out=negative.fits
+$ astarithmetic image.fits -1 x --out=negative.fits
## Subtract extension 4 from extension 1 (counting from zero):
$ astarithmetic image.fits image.fits - --out=skysub.fits \
diff --git a/lib/arithmetic-binary.c b/lib/arithmetic-binary.c
index 651c023..db2e2f2 100644
--- a/lib/arithmetic-binary.c
+++ b/lib/arithmetic-binary.c
@@ -235,48 +235,48 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
/* Left and right types set, choose what to do based on operator. */
-#define BINARY_RT_LT_SET(RT, LT) \
- switch(operator) \
- { \
- case GAL_ARITHMETIC_OP_PLUS: \
- BINARY_OP_RT_LT_SET(+, RT, LT); \
- break; \
- case GAL_ARITHMETIC_OP_MINUS: \
- BINARY_OP_RT_LT_SET(-, RT, LT); \
- break; \
- case GAL_ARITHMETIC_OP_MULTIPLY: \
- BINARY_OP_RT_LT_SET(*, RT, LT); \
- break; \
- case GAL_ARITHMETIC_OP_DIVIDE: \
- BINARY_OP_RT_LT_SET(/, RT, LT); \
- break; \
- case GAL_ARITHMETIC_OP_LT: \
- BINARY_OP_OT_RT_LT_SET(<, uint8_t, RT, LT); \
- break; \
- case GAL_ARITHMETIC_OP_LE: \
- BINARY_OP_OT_RT_LT_SET(<=, uint8_t, RT, LT); \
- break; \
- case GAL_ARITHMETIC_OP_GT: \
- BINARY_OP_OT_RT_LT_SET(>, uint8_t, RT, LT); \
- break; \
- case GAL_ARITHMETIC_OP_GE: \
- BINARY_OP_OT_RT_LT_SET(>=, uint8_t, RT, LT); \
- break; \
- case GAL_ARITHMETIC_OP_EQ: \
- BINARY_OP_OT_RT_LT_SET(==, uint8_t, RT, LT); \
- break; \
- case GAL_ARITHMETIC_OP_NE: \
- BINARY_OP_OT_RT_LT_SET(!=, uint8_t, RT, LT); \
- break; \
- case GAL_ARITHMETIC_OP_AND: \
- BINARY_OP_INCR_OT_RT_LT_SET(&&, uint8_t, RT, LT); \
- break; \
- case GAL_ARITHMETIC_OP_OR: \
- BINARY_OP_INCR_OT_RT_LT_SET(||, uint8_t, RT, LT); \
- break; \
- default: \
- error(EXIT_FAILURE, 0, "%s: operator code %d not recognized",\
- "BINARY_RT_LT_SET", operator); \
+#define BINARY_RT_LT_SET(RT, LT) \
+ switch(operator) \
+ { \
+ case GAL_ARITHMETIC_OP_PLUS: \
+ BINARY_OP_RT_LT_SET( +, RT, LT); \
+ break; \
+ case GAL_ARITHMETIC_OP_MINUS: \
+ BINARY_OP_RT_LT_SET( -, RT, LT); \
+ break; \
+ case GAL_ARITHMETIC_OP_MULTIPLY: \
+ BINARY_OP_RT_LT_SET( *, RT, LT); \
+ break; \
+ case GAL_ARITHMETIC_OP_DIVIDE: \
+ BINARY_OP_RT_LT_SET( /, RT, LT); \
+ break; \
+ case GAL_ARITHMETIC_OP_LT: \
+ BINARY_OP_OT_RT_LT_SET( <, uint8_t, RT, LT); \
+ break; \
+ case GAL_ARITHMETIC_OP_LE: \
+ BINARY_OP_OT_RT_LT_SET( <=, uint8_t, RT, LT); \
+ break; \
+ case GAL_ARITHMETIC_OP_GT: \
+ BINARY_OP_OT_RT_LT_SET( >, uint8_t, RT, LT); \
+ break; \
+ case GAL_ARITHMETIC_OP_GE: \
+ BINARY_OP_OT_RT_LT_SET( >=, uint8_t, RT, LT); \
+ break; \
+ case GAL_ARITHMETIC_OP_EQ: \
+ BINARY_OP_OT_RT_LT_SET( ==, uint8_t, RT, LT); \
+ break; \
+ case GAL_ARITHMETIC_OP_NE: \
+ BINARY_OP_OT_RT_LT_SET( !=, uint8_t, RT, LT); \
+ break; \
+ case GAL_ARITHMETIC_OP_AND: \
+ BINARY_OP_INCR_OT_RT_LT_SET( &&, uint8_t, RT, LT); \
+ break; \
+ case GAL_ARITHMETIC_OP_OR: \
+ BINARY_OP_INCR_OT_RT_LT_SET( ||, uint8_t, RT, LT); \
+ break; \
+ default: \
+ error(EXIT_FAILURE, 0, "%s: operator code %d not recognized", \
+ "BINARY_RT_LT_SET", operator); \
}
diff --git a/tests/arithmetic/onlynumbers.sh b/tests/arithmetic/onlynumbers.sh
index c903ee7..785e76a 100755
--- a/tests/arithmetic/onlynumbers.sh
+++ b/tests/arithmetic/onlynumbers.sh
@@ -44,4 +44,4 @@ if [ ! -f $execname ]; then echo "$execname not created.";
exit 77; fi
# Actual test script
# ==================
-$execname -1 3.45 "*"
+$execname -1 3.45 x
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master 888032e: Arithmetic uses x instead of * for multiplication,
Mohammad Akhlaghi <=