#--------------------------------------------------------------------------- .help ab_index May94 source .ih NAME ab_index -- Compute effective index of data value in array. .endhelp #--------------------------------------------------------------------------- procedure ab_index (xa, n, x, index, rindex) double xa[n] # I: Vector to be searched int n # I: Number of points in vector double x # I: Value to search for int index # O: Index position of X double rindex # O: Fractional index position of X. # Declartions int hi, low begin # Initialize hi and low to end points low=1 hi=n # Bisect array and reset hi or low depending on which side of their # center x lies. # Stop when hi=low+1 while ((hi-low) > 1) { index=(hi+low)/2 if (xa[index] > x) hi=index else low=index } # Compute fractional index using interpolation index = low rindex = index + (x-xa[index])/(xa[index+1]-xa[index]) end #--------------------------------------------------------------------------- # End of ab_index #---------------------------------------------------------------------------