Find the point in an array that crosses a threshold.
Loading LOADSUB ALL FROM "CROSS.HTS"
or LOADSUB FROM "MATHLIB.HTS"
Usage INTEGER K,N,S
REAL A(*),T
K=FNCrossing(A(*),T,S,N)
Description
FNCrossingfinds thenth time that the values in the arrayA, beginning with elements, cross the threshold valuetand returns the index of the crossing. Ifnis negative, the search is done backwards from thesth element for thenth crossing; otherwise, the search is done forward from thesth element.
The values inAare considered to crosstwhen an element ofAis equal totand the previous element was not equal tot, when the first element inAequalst, when an element inAis greater thantand the previous element was less thant, or when an element inAis less thantand the previous element was greater thant. In the latter two cases, the crossing occurs between two elements inA; the value returned is the index of the elementafterthe crossing.
The value ofsand the value returned are with reference to the lower bound specified whenAwas dimensioned or the value specified in the OPTION BASE in effect whenAwas dimensioned, if no lower bound was specified.
If the portion ofAfromsto the end ofA(n> 0) or the portion ofAfromsto the beginning ofA(n< 0) contains fewer thanncrossings of the value oft, -1 is returned.
Errors
FNCrossingcauses an HTBasic error if its arguments are not of the types shown in the USAGEsection, above, or ifsis not in the range of the subscripts ofA.