function interp_all,x,y,y2,miss ;------------------------------------------------------------------ ; ; for a curve x vs. y, find all interpolates x2 corresponding to ; the user input point y2. This routine assumes the function x vs. y ; could be multi valued (e.g. like a sine wave). ; 2-point interpolation is used. ; ; input: ; x......x axis variables (vector) ; y......y axis variables (vector) ; y2.....interpolate to this value (scalar) ; miss...missing data value ; ; output: ; x2.....the data values from x at y2 ; ; source: Mark Hervig ; ;------------------------------------------------------------------ if (n_elements(x) ne n_elements(y)) then begin print,'x and y arrays are not the same size in interp_all.pro !!!' stop endif n = n_elements(y) x2 = miss dydx = miss if (y2 gt max(y) or y2 lt min(y)) then return,x2 nans = 0 ; the number of interpolates ok = where(x ne miss,nok) if (nok gt 1) then begin slp = fltarr(nok) xa = x(ok) ya = y(ok) for jj = 0,nok-2 do begin j = ok(jj) slp(j) = ( (ya(j)-ya(j+1)) / (xa(j)-xa(j+1)) ) if ( (ya(j) ge y2 and ya(j+1) lt y2) or (ya(j) lt y2 and ya(j+1) ge y2) ) then begin term = (y2-ya(j)) / (ya(j+1)-ya(j)) ans = term * (xa(j+1)-xa(j)) + xa(j) nans = nans + 1 x2 = [x2,ans] dydx = [dydx,slp(j)] endif endfor if (nans gt 0) then begin x2 = x2(1:nans) dydx = dydx(1:nans) ;/ max(slp) endif endif return,x2 end