The I/O functions of the sat-nms driver language (INPUT, PRINT, READ, WRITE and the REST I/O functions) all provide with the FUNCTION keyword a feature to translate a numeric value along a table of x/y value pairs. The result of the function is calculated by linear interpolation in this table.
File format
A FUNCTION requires the table of x/y values to be stored as a simple text file which looks like the following example:
# function table, defines a square root function
0.0 0.0
1.0 1.0
4.0 2.0
9.0 3.0
16.0 4.0
25.0 5.0
The table consists of two or more lines, each consisting of the x-value followed by one or more space characters and the corresponding y-value. Both values must be valid floating point numbers. Blanc lines and lines starting with a # character are ignored.
The x-values need no to be e equally spaced, but the values must be sorted in ascending order, starting with the lowest one.
Calculation method
The function calculates the the y-value to a given x-value by linear interpolation. This means, the curve defined by the x/y pairs is a polygonal line. The table should contain enough x/y-pairs to meet the expected accuracy of the function.
For x-values outside the range of x/y pairs defined in the table, the function extrapolates the y-value using the slope given by the outmost two x/y pairs. You may want to set two additional x/y-pairs outside the real table to set this slope to a particular value.
File name processing
When executed in an I/O statement, the function extends the function name defined in the driver to the name of the file containing the function table. First the letters .txt are appended to the function name. The .txt file extension makes it easy to open the file with a text editor from the file manager of any operating system. Function table must be placed in the base directory of the sat-nms installation (usually /home/satnms/).
If the function name starts with a - character, the name of the device is prepended to the function name. For example, a function name "-caltable" would expand to a file name DEVNAME-caltable.txt where DEVNAME is the name of the actual device. This is useful for e.g. calibration tables which are different for each particular device.
Error handling
The function checks if the file for this function exists. The driver raises a communcation fault if a FUNCTION clause with non-existing file is processed. If the file itself cannot be parsed for some reason, the function tries to do its best, recovering from this situation if possible. A note is written to the .panic.log file, if such an error occurs.