[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastrocommits] master 21eef31 5/5: Letters, not symbols for Arithmet
From: 
Mohammad Akhlaghi 
Subject: 
[gnuastrocommits] master 21eef31 5/5: Letters, not symbols for Arithmetic's conditional operators 
Date: 
Fri, 26 Aug 2016 17:37:28 +0000 (UTC) 
branch: master
commit 21eef319f98814523eb3b60e6db4bc37fbc04d1f
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
Letters, not symbols for Arithmetic's conditional operators
The characters `<', `>' and `=' have special meaning on the
shell. Eventhough using them as operators in Arithmetic was not wrong,
however, they can cause confusion to the eye when reading a script. all the
conditional operators are now replaced with letter equivalents.
This finishes task #13870.

doc/gnuastro.texi  42 +++++++++++++++++++++
src/arithmetic/args.h  13 +++++++++++
src/arithmetic/arithmetic.c  28 ++++++++++++++
tests/arithmetic/where.sh  2 +
4 files changed, 47 insertions(+), 38 deletions()
diff git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 17ce0cb..7192a7a 100644
 a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ 6956,31 +6956,31 @@ the average of the respective pixels in all operands in
the stack
Similar to @command{min}, but the pixels of the output will contain
the median of the respective pixels in all operands in the stack.
address@hidden <
Smaller than: If the second popped (or left operand in infix notation, see
address@hidden polish notation}) value is smaller than the right operand,
then this function will return a value of 1, otherwise it will return a
value of 0. If both operands are images, then all the pixels will be
compared with their counter parts in the other image. If only one operand
is an image, then all the pixels will be compared with the number. Finally
if both are numbers, then the output is also just one number (0 or 1).

address@hidden >
Larger than: similar to the @code{<} (smaller than operator), but returning
1 when the second popped operand is larger than the first.

address@hidden ==
Equality: similar to the @code{<} (smaller than operator), but returning 1
address@hidden lt
+Less than: If the second popped (or left operand in infix notation, see
address@hidden polish notation}) value is smaller than the first popped
+operand, then this function will return a value of 1, otherwise it will
+return a value of 0. If both operands are images, then all the pixels will
+be compared with their counterparts in the other image. If only one operand
+is an image, then all the pixels will be compared with the the single value
+(number) of the other operand. Finally if both are numbers, then the output
+is also just one number (0 or 1).
+
address@hidden gt
+Greater than: similar to @code{lt} (`less than' operator), but
+returning 1 when the second popped operand is greater than the first.
+
address@hidden eq
+Equality: similar to @code{lt} (`less than' operator), but returning 1
when the second popped operand is equal (to double precison floating point
accuracy) to the first.
address@hidden <=
Smaller or equal: similar to the @code{<} (smaller than operator), but
returning 1 when the second popped operand is smaller or equal to the
first.
address@hidden le
+Less or equal: similar to @code{lt} (`less than' operator), but returning 1
+when the second popped operand is smaller or equal to the first.
address@hidden >=
Larger or equal: similar to the @code{<} (smaller than operator), but
address@hidden ge
+Greater or equal: similar to @code{lt} (`less than' operator), but
returning 1 when the second popped operand is larger or equal to the first.
@item where
diff git a/src/arithmetic/args.h b/src/arithmetic/args.h
index f34a4eb..d352413 100644
 a/src/arithmetic/args.h
+++ b/src/arithmetic/args.h
@@ 165,8 +165,17 @@ parse_opt(int key, char *arg, struct argp_state *state)
here: */
state>child_inputs[0]=&p>cp;
 /* There is no check for the equal character here because in
 Arithmetic, the equal sign can be an argument. */
+ /* In case the user incorrectly uses the equal sign (for example
+ with a short format or with space in the long format, then `arg`
+ start with (if the short version was called) or be (if the long
+ version was called with a space) the equal sign. So, here we
+ check if the first character of arg is the equal sign, then the
+ user is warned and the program is stopped: */
+ if(arg && arg[0]=='=')
+ argp_error(state, "incorrect use of the equal sign (`=`). For short "
+ "options, `=` should not be used and for long options, "
+ "there should be no space between the option, equal sign "
+ "and value");
switch(key)
{
diff git a/src/arithmetic/arithmetic.c b/src/arithmetic/arithmetic.c
index f0925d1..870af04 100644
 a/src/arithmetic/arithmetic.c
+++ b/src/arithmetic/arithmetic.c
@@ 744,11 +744,11 @@ findmax(struct imgarithparams *p)
int
smaller(double left, double right)
+lessthan(double left, double right)
{ return left<right; }
int
larger(double left, double right)
+greaterthan(double left, double right)
{ return left>right; }
int
@@ 756,11 +756,11 @@ equal(double left, double right)
{ return left==right; }
int
smallerequal(double left, double right)
+lessequal(double left, double right)
{ return left<=right; }
int
largerequal(double left, double right)
+greaterequal(double left, double right)
{ return left>=right; }
@@ 785,11 +785,11 @@ conditionals(struct imgarithparams *p, char *operator)
pop_operand for the first image. */
size=p>s0*p>s1;
 if(!strcmp(operator, "<")) thisfunction = &smaller;
 else if(!strcmp(operator, ">")) thisfunction = &larger;
 else if(!strcmp(operator, "==")) thisfunction = &equal;
 else if(!strcmp(operator, "<=")) thisfunction = &smallerequal;
 else if(!strcmp(operator, ">=")) thisfunction = &largerequal;
+ if(!strcmp(operator, "lt")) thisfunction = &lessthan;
+ else if(!strcmp(operator, "gt")) thisfunction = &greaterthan;
+ else if(!strcmp(operator, "eq")) thisfunction = &equal;
+ else if(!strcmp(operator, "le")) thisfunction = &lessequal;
+ else if(!strcmp(operator, "ge")) thisfunction = &greaterequal;
else
error(EXIT_FAILURE, 0, "a bug! Please contact us at %s so we "
"can address the problem. The value of `operator' in "
@@ 949,11 +949,11 @@ reversepolish(struct imgarithparams *p)
 !strcmp(token>v, "max")
 !strcmp(token>v, "average")
 !strcmp(token>v, "median")) alloppixs(p, token>v);
 else if(!strcmp(token>v, "<")
  !strcmp(token>v, ">")
  !strcmp(token>v, "==")
  !strcmp(token>v, "<=")
  !strcmp(token>v, ">=")) conditionals(p, token>v);
+ else if(!strcmp(token>v, "lt")
+  !strcmp(token>v, "gt")
+  !strcmp(token>v, "eq")
+  !strcmp(token>v, "le")
+  !strcmp(token>v, "ge")) conditionals(p, token>v);
else if(!strcmp(token>v, "where")) where(p);
else
error(EXIT_FAILURE, 0, "the argument \"%s\" could not be "
diff git a/tests/arithmetic/where.sh b/tests/arithmetic/where.sh
index 93b3401..f4c371e 100755
 a/tests/arithmetic/where.sh
+++ b/tests/arithmetic/where.sh
@@ 48,4 +48,4 @@ if [ ! f $execname ]  [ ! f $img ]; then exit 77; fi
# Actual test script
# ==================
$execname $img 0 == $img nan where h1 h0 output=where.fits
+$execname $img 0 eq $img nan where h1 h0 output=where.fits
 [gnuastrocommits] master updated (edc8c5e > 21eef31), Mohammad Akhlaghi, 2016/08/26
 [gnuastrocommits] master 376edc9 1/5: Simple conditional operators added to Arithmetic, Mohammad Akhlaghi, 2016/08/26
 [gnuastrocommits] master ffd7f18 3/5: Output type print and checks moved to libraries, Mohammad Akhlaghi, 2016/08/26
 [gnuastrocommits] master 804eb22 2/5: Operator in Arithmetic to change pixel values, Mohammad Akhlaghi, 2016/08/26
 [gnuastrocommits] master 21eef31 5/5: Letters, not symbols for Arithmetic's conditional operators,
Mohammad Akhlaghi <=
 [gnuastrocommits] master 62c3bd2 4/5: Option for Arithmetic's output type, Mohammad Akhlaghi, 2016/08/26