Format files associate names with string and numeric fields separated by literal information in a record. A numeric field is given in a format file as a dollar sign, followed by curly braces enclosing a variable name:
This is a numeric field: ${vname}
A string variable is enclosed in parentheses:
This is a string field: $(sname)
The program attempts to match literal information in the input format to its input and assign string and numeric fields accordingly. If a string or numeric field variable appears more than once in the input format, input values for the corresponding fields must match (ie. have the same value) for the whole record to match. Numeric values are allowed some deviation, on the order of 0.1%, but string variables must match exactly. Thus, dummy variables for "don't care" fields should be given unique names so that they are not all required to take on the same value.
For each valid input record, an output record is produced in its corresponding format. Output field widths are given implicitly by the space occupied in the format file, including the dollar sign and braces. This makes it impossible to produce fields with fewer than four characters. If the -b option is specified, input records must exactly match the template. By default, the character following each input field is used as a delimiter. This implies that string fields that are followed by white space cannot contain strings with white space. Also, numeric fields followed but not preceded by white space will not accept numbers preceded by white space. Adjacent input fields are advisable only with the -b option. Numeric output fields may contain expressions as well as variables. A dollar sign may appear in a literal as two dollar signs ($$).
The definitions specified in -e and -f options relate numeric output fields to numeric input fields. For the default record format, a field is a variable of the form $N, where N is the column number, beginning with 1. Output columns appear on the left-hand side of assignments, input columns appear on the right-hand side.
A variable definition has the form:
var = expression ;
Any instance of the variable in an expression will be replaced with its definition.
An expression contains real numbers, variable names, function calls, and the following operators:
A function definition has the form:
func(a1, a2, ..) = expression ;
The expression can contain instances of the function arguments as well as other variables and functions. Function names can be passed as arguments. Recursive functions can be defined using calls to the defined function or other functions calling the defined function.
The variable cond, if defined, will determine whether the current input record produces an output record. If cond is positive, output is produced. If cond is less than or equal to zero, the record is skipped and no other expressions are evaluated. This provides a convenient method for avoiding inappropriate calculations. The following library of predefined functions and variables is provided:
if(cond, then, else)
if cond is greater than zero, then is evaluated,
otherwise else is evaluated. This function is
necessary for recursive definitions.
select(N, a1, a2, ..)
return aN (N is rounded to the nearest integer).
This function provides array capabilities. If N
is zero, the number of available arguments is
returned.
asin(x), acos(x), atan(x)
inverse trigonometric functions.
atan2(y, x)
inverse tangent of y/x (range -pi to pi).
rcalc -e `$1=sqrt($2);$2=$1*$3' inputfile > outputfile
Tabs count as single spaces inside fields.