/usr/share/doc/stilts/sun256/jelExtend.html is in stilts-doc 3.1.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="sun-style.css">
<title>Adding User-Defined Functions</title>
</head>
<body>
<hr>
<a href="taskApi.html">Next</a> <a href="instanceMethods.html">Previous</a> <a href="jelAdvanced.html">Up</a> <a href="index.html">Contents</a> <br> <b>Next: </b><a href="taskApi.html">Programmatic Invocation</a><br>
<b>Up: </b><a href="jelAdvanced.html">Advanced Topics</a><br>
<b>Previous: </b><a href="instanceMethods.html">Instance Methods</a><br>
<hr>
<h4><a name="jelExtend">10.7.3 Adding User-Defined Functions</a></h4>
<p>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.
</p>
<p>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.
</p>
<p>The steps you need to follow are:
<ol>
<li>Write and compile a class containing one or more static public
methods representing the function(s) required
</li>
<li>Make this class available on the application's classpath at runtime
as described in <a href="jvmClasspath.html">Section 3.1</a></li>
<li>Specify the class's name to the application, as the value of the
<code>jel.classes</code>
system property (colon-separated if there are several)
as described in <a href="sysProperties.html">Section 3.3</a></li>
</ol>
</p>
<p>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:
<pre>
public class AuxFuncs {
public static double average3(double x, double y, double z) {
return (x + y + z) / 3.0;
}
}
</pre>
and the command
<pre>
stilts tpipe cmd='addcol AVERAGE "average3($1,$2,$3)"'
</pre>
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:
<ol>
<li>Writing a file named <code>AuxFuncs.java</code>
containing the above code
</li>
<li>Compiling it using a command like "<code>javac AuxFuncs.java</code>"
</li>
<li>Running <code>tpipe</code> using the flags
"<code>stilts -classpath . -Djel.classes=AuxFuncs tpipe</code>"
</li>
</ol>
</p>
<p>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:
<pre>
public static double sum(double[] values) {
double total = 0;
for (int i = 0; i < values.length; i++) {
total += values[i];
}
return total;
}
</pre>
can be invoked like "<code>sum(UMAG,GMAG,RMAG,IMAG,ZMAG)</code>".
The alternative form "<code>double... values</code>" can be used in
the declaration with identical effect.
</p>
<hr><a href="taskApi.html">Next</a> <a href="instanceMethods.html">Previous</a> <a href="jelAdvanced.html">Up</a> <a href="index.html">Contents</a> <br> <b>Next: </b><a href="taskApi.html">Programmatic Invocation</a><br>
<b>Up: </b><a href="jelAdvanced.html">Advanced Topics</a><br>
<b>Previous: </b><a href="instanceMethods.html">Instance Methods</a><br>
<hr><i>STILTS - Starlink Tables Infrastructure Library Tool Set<br>Starlink User Note256<br>STILTS web page:
<a href="http://www.starlink.ac.uk/stilts/">http://www.starlink.ac.uk/stilts/</a><br>Author email:
<a href="mailto:m.b.taylor@bristol.ac.uk">m.b.taylor@bristol.ac.uk</a><br>Mailing list:
<a href="mailto:topcat-user@jiscmail.ac.uk">topcat-user@jiscmail.ac.uk</a><br></i></body>
</html>
|