comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: A faster way to INTERPOL

A faster way to INTERPOL
type: item
description: I find that using INTERPOL to do 1-d interpolations on large irregular grids can be extremely time consuming. The problem with INTERPOL is that it uses a linear search to find where a given field point fits into the irregular grid. Below you'll find my solution to the problem. The procedure FINDEX uses a binary search to obtain a "floating point index" which can be used with INTERPOLATE. I have found that the FINDEX + INTERPOLATE method can be up to 70 times faster than using INTERPOL. I am donating this procedure to the IDL community in hopes of saving untold millions of machine cycles that would otherwise have been wasted in futile linear searches. But seriously, give it a try and let me know if it breaks. Regards, Paul Ricchiazzi ---------8<---------8<---------8<---------8<---------8<---------8 <---------8< function findex,u,v ;+ ; ROUTINE: findex ; ; PURPOSE: Compute "floating point index" into a table using binary ; search. The resulting output may be used with INTERPOLATE. ; ; USEAGE: result = findex(u,v) ; ; INPUT: ; u a monitically increasing or decreasing 1-D grid ; v a scalor, or array of values ; ; OUTPUT: ; result Floating point index. Integer part of RESULT(i) gives ; the index into to U such that V(i) is between ; U(RESULT(i)) and U(RESULT(i)+1). The fractional part ; is the weighting factor ; ; V(i)-U(RESULT(i)) ; --------------------- ; U(RESULT(i)+1)-U(RESULT(i)) ; ; ; DISCUSSION: ; This routine is used to expedite one dimensional ; interpolation on irregular 1-d grids. Using this routine ; with INTERPOLATE is much faster then IDL's INTERPOL ; procedure because it uses a binary instead of linear ; search algorithm. The speedup is even more dramatic when ; the same independent variable (V) and grid (U) are used ; for several dependent variable interpolations. ; ; ; EXAMPLE: ; ;; In this example I found the FINDEX + INTERPOLATE combination ;; to be about 60 times faster then INTERPOL. ; ; u=randomu(iseed,200000) & u=u(sort(u)) ; v=randomu(iseed,10) & …
creator: paul
date: 1997-02-21T08:00:00-00:00