expressions: Standard expression syntax in IRAF tasks

Package: language

Introduction

Many IRAF tasks use expressions. These all go through the same basic expression evaluator. This provides a standard set of operators and functions with a common syntax similar to the CL. However, each application can customize

*
how expressions are input; e.g. from files or with special prefixes
*
how variables (called operands) are specified; e.g. with leading special characters such as '$' or with single letter capitals
*
where the values are obtained; e.g. from image header keywords or from data files
*
special, application specific functions; e.g. airmass or arcsep

This help topic covers the common features of expressions. The individual task help descriptions may also include this material or just describe the customization.

Expressions

Expressions consist of operands, numeric and string constants, operators, and functions. Parentheses are also used to control the evaluation order as in standard algebraic expressions. String constants are quoted strings and numeric constants are pure unquoted numbers. Numbers may be given in sexagesimal notation and are automatically converted to decimal numbers. The operators are arithmetic, logical, and string.

Operands

The way applications refer to operands is generally unique to that task. Sometimes they are simply alphanumeric identifiers, sometimes they have prefixes such '$', sometimes they are limited to specific identifiers, and sometimes they have additional structure such as <image>.<keyword> where <image> is an identifier for an image and <keyword> refers to a keyword in the image. Common types of operands refer to images, table columns, and keywords.

There is one special common syntax for operands that include characters that correspond to the operators in expressions. In this case the operand identifier must be quoted as a string and then referenced using a leading @ character; e.g. @'mjd-obs'.

Operators

The following operators are recognized in expressions. With the exception of the operators "?", "?=", and "@", the operator set is equivalent to that available in the CL.

+  -  *  /              arithmetic operators
**                      exponentiation
//                      string concatenation
!  -                    boolean not, unary negation
<  <= >  >=             order comparison (works for strings)
== != && ||             equals, not equals, and, or
?=                      string equals pattern
? :                     conditional expression (ternary operator)
@                       reference a operand

The operators "==", "&&", and "||" may be abbreviated as "=", "&", and "|" if desired. The ?= operator performs pattern matching upon strings. The pattern syntax is that described for the task match. The @ operator is required to reference keywords with one of the operator characters. This is most likely to be used as:

@"date-obs"

A point to be aware of is that in the ?: conditional expression both possible result values are evaluated though the result of the expression is only one of them.

Functions

A number of standard intrinsic functions are recognized within expressions. Many of these may not be useful in the context of the application but are part of the language. The set of functions currently supported is shown below.

abs     atan2   deg     log     min     real    sqrt
acos    bool    double  log10   mod     short   str
asin    cos     exp     long    nint    sin     tan
atan    cosh    int     max     rad     sinh    tanh

The trigonometric functions operate in units of radians. The min and max functions may have any number of arguments up to a maximum of sixteen or so (configurable). The arguments need not all be of the same datatype.

A function call may take either of the following forms:

<identifier> '(' arglist ')'
<string_expr> '(' arglist ')'

The first form is the conventional form found in all programming languages. The second permits the generation of function names by string valued expressions and might be useful on rare occasions.

See also

imexpr hedit hselect asthedit astcalc irproc ircatalog ccget mskexpr mskreg import export agetcat pcalc pconvert pdump pselect tbcalc tbdump tbselect txcalc txdump txselect