The functions provided by default for use with algebraic expressions, while powerful, may not provide all the operations you need. For this reason, it is possible to write your own extensions to the expression language. In this way you can specify abritrarily complicated functions. Note however that this will only allow you to define new columns or subsets where each cell is a function only of the other cells in the same row - it will not allow values in one row to be functions of values in another.
In order to do this, you have to write and compile a (probably short) program in the Java language. A full discussion of how to go about this is beyond the scope of this document, so if you are new to Java and/or programming you may need to find a friendly local programmer to assist (or mail the author). The following explanation is aimed at Java programmers, but may not be incomprehensible to non-specialists.
The steps you need to follow are:
jel.classes
system property (colon-separated if there are several)
as described in Section 3.3
Any public static methods defined in the classes thus specified will then be available for use. They should be defined to take and return the relevant primitive or Object types for the function required. For instance a class written as follows would define a three-value average:
public class AuxFuncs { public static double average3(double x, double y, double z) { return (x + y + z) / 3.0; } }and the command
stilts tpipe cmd='addcol AVERAGE "average3($1,$2,$3)"'would add a new column named AVERAGE giving the average of the first three existing columns. Exactly how you would build this is dependent on your system, but it might involve doing something like the following:
AuxFuncs.java
containing the above codejavac AuxFuncs.java
"tpipe
using the flags
"stilts -classpath . -Djel.classes=AuxFuncs tpipe
"Note that (in versions later than STILTS 3.0-6) variable-length argument lists are supported where the final declared argument is an array, so for instance a method declared like:
public static double sum(double[] values) { double total = 0; for (int i = 0; i < values.length; i++) { total += values[i]; } return total; }can be invoked like "
sum(UMAG,GMAG,RMAG,IMAG,ZMAG)
".
The alternative form "double... values
" can be used in
the declaration with identical effect.