If you want to include intrinsic functions, such as logarithms and trigonometric functions in your calculations, or perhaps you need some function for an integer expression that is not supplied by the C-shell, such as finding the maximum or the absolute value, calc may be the solution. It offers the 28 functions tabulated below.
Here are a few examples.
set a = 5
set b = (3 4 6 -2)
set c = `calc exp="'min( $a, $b[1], $b[2], $b[3] )'"`
set d = `calc exp="'dim( $b[4], $a ) + dim( $b[3], $a )'"`
The first expression finds the minimum of the four integers, namely
3 and assigns it to variable c. The second expression
sums two positive differences: 0 and 1 respectively.
set mag = `calc exp="'-2.5 * LOG10( $counts )'"`
set separation = `calc exp="atand2(35.3,$dist)"`
echo The nearest index is `calc exp="nint($x+0.5)"`
Variable mag is the magnitude derived from the flux
stored in variable counts. separation is assigned
the inverse tangent of 35.3 divided by the value of variable
dist measured between
| Function | Number of arguments | Description |
| SQRT | 1 | square root:
|
| LOG | 1 | natural logarithm:
|
| LOG10 | 1 | common logarithm:
|
| EXP | 1 | exponential:
|
| ABS | 1 | absolute (positive) value:
|
| NINT | 1 | nearest integer value to arg |
| MAX | 2 or more | maximum of arguments |
| MIN | 2 or more | minimum of arguments |
| DIM | 2 | Fortran DIM (positive difference) function |
| MOD | 2 | Fortran MOD (remainder) function |
| SIGN | 2 | Fortran SIGN (transfer of sign) function |
| SIN* | 1 | sine function:
|
| COS* | 1 | cosine function:
|
| TAN* | 1 | tangent function:
|
| ASIN* | 1 | inverse sine function:
|
| ACOS* | 1 | inverse cosine function:
|
| ATAN* | 1 | inverse tangent function:
|
| ATAN2* | 2 | inverse tangent function:
|
| SINH* | 1 | hyperbolic sine function:
|
| COSH* | 1 | hyperbolic cosine function:
|
| TANH* | 1 | hyperbolic tangent function:
|
| SIND* | 1 | sine function:
|
| COSD* | 1 | cosine function:
|
| TAND* | 1 | tangent function:
|
| ASIND* | 1 | inverse sine function:
|
| ACOSD* | 1 | inverse cosine function:
|
| ATAND* | 1 | inverse tangent function:
|
| ATAN2D* | 2 | inverse tangent function:
|
| *Function does not support integer arithmetic. | ||
C-shell Cookbook