UFH Library Functions
These are contants:
Pi is 3.14159...
Enatural is 2.718281...
Rad2Deg is 57.295779...
These are variables and are set up at script start-up:
Argc
is the number of command-line arguments available to the user's script including the name of the script file itself [as argument 0]. Argc is always greater than 0.
Argv
is an array of strings holding the command-line arguments available to the suer's script. Note that Argv[0] is the name of the script file.
nArgs()
returns the number of actual arguments passed to the current function plus one. The extra argument is the name of the function itself.
nthArgs(i)
returns the value of the ith argument passed to the current function. The zeroeth argument is the name of the function.
Arithmetic
max(a,b,c,...)
min(a,b,c,...)
Returns the arithmetic maximum and miminum of their arguments. There must be at least one argument and there is no upper limit on the number of arguments. These functions work properly even if arguments have different types.
Example
Shape Management
flatten(a,b,c,...)
recursively examines all of its arguments and returns a one-dimensional array of the elements of which consist of all the terminal values of the recursively explored arguments.
The routine is a little unusual, at first, to those of us whose higher sensibilities have been permanently damaged by lifelong exposure to Fortran and other toxic materials. It actually has a number of important uses.
Initialization of vectors
Here is an easy way to initialize a vector:
v = flatten(fVector(2,0),iseq(3),q,0,3.5);
if q is an array with two elements then v ends up with, in order,
{ 0, 0, 0, 1, 2, q[0], q[1], 0, 3.5 }
flatten() keeps track of the types of end-members it encounters while recursively examining its arguments. If all end-members are numeric and there is at least one element, then flatten() returns an fVector. In the above example v would hold an fVector.
Mathematical
sin()
cos()
atan()
log()
log10()
exp()
sqrt()
abs()
int()
Trigonometric expressions return a value in radians.
Input / Output
getTokenLine(stream)
getTokenLine(stream, separators)
reads the next line of input from stream, breaks the input into tokens, and returns those tokens in an array.
Tokens are normally taken to be anything between unquoted bits of whitespace or a comma or semicolon. In the second form, the characters in the argument separators are the characters used to delimit tokens. A newline is always recognized as the end-of-line delimiter. On end-of-file, returns the special value Nothing.
fopen(filename, mode)
Opens an I/O stream to the file filename and returns a stream. Mode should be one of:
| r | open for reading |
| w | open for writing (truncate or create if necessary) |
| a | open for writing at end (create if necessary) |
| r+ | open for update (reading and writing) |
| w+ | truncate or create and open for update |
fclose(stream)
Closes a stream.
fflush(stream)
Causes any pending I/O stream to occur. Returns 0 on success and -1 on failure.
popen(command,mode)
pclose(stream)
Similar to fopen() and fclose() except that the stream connects to another process, the one specified by the command line in command. Mode must be either "r" or "w".
Example Script utilizing an attached ASCII file for associating group elevations with the seismic dataset.
Type Predicates
isDouble(x)
returns true (1) if the variable x currently holds a value of type Double.
isString(x)
isNothing(x)
isArray(x)
isfVector(x)
all do what you think they ought to do.
Sequence
sequence(number)
sequence(from,to)
sequence(from,to,step)
These functions all produce an fVector initialized with a sequence of values as specified by their arguments.
fVectors
fVector(i)
fVector(i,c)
These constructors return floating-point vectors of the requested length. The first form doesn't initialize the new fVector's values; the second form sets them all equal to c. These functions are redundant with sequence above.