comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Is there a better way?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Is there a better way? [message #9169 is a reply to message #9162] Tue, 10 June 1997 00:00 Go to previous message
William Clodius is currently offline  William Clodius
Messages: 30
Registered: December 1996
Member
Kelly Dean wrote:
>
> Is there a better way to locate a value in a table (or array)? I would
> like to come in with an array of radaince values and convert them to
> temperatures. The method below only takes the one number (rad) then
> search for the best match in the table (or array).
>
> If you can thing of a better method, send me a note.

The best routine depends on the detailed statistics of your data, i.e.
it is often appropriate to cache the last point and search outwards.
The following takes of the order log base 2 of 200 operations, i.e., 8 *
a small factor, while your method takes on the order of 200 operations,
unless the data always lies at small values.

lbound= 0
ubound = 199
guess = 100
while ubound - lbound gt 1 do begin
IF rad GT WVRADarr(guess) then $
lbound = guess $
else ubound = guess
guess = (ubound + lbound) / 2L
endwhile
TempK = WVTEMParr(lbound)

The following should be a vectorizable version of the same idea

lbound = Lonarr(N_elements(rad))
ubound = lbound + 199
guess = lbound + 100
n_iterate = 9
for i=0, n_iterate-1 do begin
ndx = where(rad GT WVRADarr(guess), count)
if count gt 0 then lbound(ndx) = guess(ndx)
ndx = where(rad LE WVRADarr(guess), count)
if count gt 0 then ubound(ndx) = guess(ndx)
guess = (ubound + lbound) / 2L
endfor

TempK = WVTEMParr(lbound)

Mind you I haven't checked the following for boundary conditions, in
particular it might be that n_iterate should be 8 or lbound might be off
by 1 from what you want.

--

William B. Clodius Phone: (505)-665-9370
Los Alamos Nat. Lab., NIS-2 FAX: (505)-667-3815
PO Box 1663, MS-C323 Group office: (505)-667-5776
Los Alamos, NM 87545 Email: wclodius@lanl.gov
[Message index]
 
Read Message
Read Message
Previous Topic: AVI in PV-Wave
Next Topic: watershed segmentation

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 10:15:53 PDT 2025

Total time taken to generate the page: 0.64000 seconds