UFH Array and fVector Expressions
Suppose that v is an array or fVector, then we can access the individual values in the array with:
v[i]
which is just what you are used to with Fortran or C. Note that the indexing always starts from zero.
There is also a special form of indexing involving the "$" symbol. The "$" stands for the index of the last element presently in the array. This symbol can be used to access elements near the end vonveniently. It can also be used to extend the array off of its end.
Example
for ( i = 0; i < 20; i++ ) {
x[i] = i * i;
}
/* at this point x[0], ... x[19] exist */
x[$ + 1] = 7;
/* Now x[20] exists and is == 7 */
NOTE: this type of assignment is VERY slow in the current ufh release and should be avoided for large datasets. Full vector assignment [see below] on the other hand is very fast. For instance to set a whole trace to zero use:
Tr.Series[0:nsamp-1] = 0;
Subranging
A much different expression is one of these:
| v[i:j] | has the value of a vector formed from the elements v[i], ..., v[j] from v |
| v | has the value of a vector formed from all the elements of v. (that is, a copy of v). |
Each of these has a value that is itself a vector. The subrange notation [i:j] has several convenience forms. First, a "$" can be used in either slot. Second, if the first value is omitted, it is assumed to be zero. Finally, if the second value is omitted, it is assume to be th evalue of "$".
Example
/* make v a 10 element vector initialized to zero */
v = fVector(10,0);
/* set the third element of v equal to 7 */
v[3] = 7;
/* assign a subvector of v into q */
q = v[2:5];
/* q now holds {0, 7, 0, 0} */
Array Arithmetic
Array and fVector values can be manipulated using many of the operators used to manipulate numbers. At this moment ufh supports these bits of vector arithmetic:
| Expression | Result |
| a + b | a[i] + b[i] |
| a - b | a[i] - b[i] |
| a * b | a[i] * b[i] |