FUNCTION DI_floatIdx, ar, val ;;----------------------------------------------------------------------------- ;; PURPOSE: ;; Find the equivilant floating point index of the value val in the ;; monotonically increasing array ar. This can then be used with ;; interpolate to dramatically increase the the efficiency of the interpl ;; command. ;; ;; !!! Warning !!! This routine does not ensure that the array is ;; monotonically increasing, so if ar is not, the routine will produce ;; unpredictable results. ;; ;; CALLING SEQUENCE: ;; x = DI_floatIdx(ar,val) ;; ;; REQUIRED INPUTS: ;; ar - monotonically increasing array ;; val - value to find in the array ar. This can be an array of values ;; to find ;; ;; OUTPUTS: ;; RETURN - floating point index where the val would appear in ar if ;; it were continuous. Assumes linear interpolation between ;; the points. ;; ;; OPTIONAL INPUT KEYWORDS: ;; ;; EXAMPLE: ;; IDL> idx = DI_floatidx(ar, val) ;; ;; PROCEDURES USED (i.e. called directly!): ;; ;; MODIFICATION HISTORY: ;; 2004-10-14 M. Desnoyer Created ;; ;;----------------------------------------------------------------------------- ;; Setup the initial bounds lo = reform(lonarr(n_elements(val)),size(val,/dimensions)) hi = (n_elements(ar)-1)+lo ;; Perform a binary search WHILE max(hi-lo) GT 1 DO BEGIN mid = lo + (hi-lo)/2 w = where(ar[mid] LT val, cntw, complement=v,ncomplement=cntv) IF cntw GT 0 THEN lo[w]=mid[w] IF cntv GT 0 THEN hi[v]=mid[v] ENDWHILE RETURN, lo+(val-ar[lo])/(ar[hi]-ar[lo]) END