;Function findi.pro finds the index of a the first element of a given ;vector that has the given value. ;Use is as follows: ; ind=findi(x,val,silent) ;Where ; input | x = input vector ; | val = value to find index of in x ; | silent = 1 for silent running, 0 otherwise ; ; optional input |silence = 0 for no displayed output, 1 otherwise ; ; output | ind = index where val exists in x. If val is not an exact ; location the surrounding indicies are displayed if ; silence~=0, but ind will always equal the higher ; of the two surrounding indicies. ;Written as a matlab function by BWBerger circa 10/95 ;Modified into an idl code by BWB on 4/16/99 function findi,x,val,silent n=len(x) found=0 if x(0) eq val then begin found=1 ind=0 endif i=1 while found eq 0 do begin if i ne n then begin if x(i) eq val then begin found=1 ind=i endif else begin if x(i) gt val and x(i-1) lt val then begin found=2 ind=i-1 endif else begin if x(i) lt val and x(i-1) gt val then begin found=3 ind=i-1 endif endelse endelse endif else begin ind=-1 found=4 endelse i=i+1 endwhile if (silent eq 0) then begin if found eq 1 then begin print, 'Value found at index ',ind endif else begin if (found eq 2) or (found eq 3) then begin print,'Value is between index ',ind,' and ',ind+1 endif else begin if found eq 4 then begin print, 'Value not found' endif endelse endelse endif return,ind end