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

Home » Public Forums » archive » Re: Search routines
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Search routines [message #12829] Fri, 18 September 1998 00:00
bowman is currently offline  bowman
Messages: 121
Registered: September 1991
Senior Member
In article <3602D89B.15BF8C2D@ssec.wisc.edu>, Liam Gumley
<Liam.Gumley@ssec.wisc.edu> wrote:

> Kenneth P. Bowman wrote:
>> IDL has a pretty good SORT routine, but no SEARCH routine that I have been
>> able to find (that is, a procedure to find the index of the closest/first
>> match in an ordered list). Once again, this can be done with loops, but
>> such an implementation would almost certainly be much slower than a
>> built-in function. Since searching and sorting are such basic operations,
>> does anyone know why there is no SEARCH in IDL?
>
> How about the MIN function, e.g.
>
> array = findgen(100)
> value = 37.2
> result = min( abs( value - array ), location )
> help, location

Again, I'm sure this is an order-N operation, as MIN has to check every
element, just like WHERE. It has no knowledge that the list is ordered.

Ken

--
Kenneth P. Bowman, Professor 409-862-4060
Department of Meteorology 409-862-4466 fax
Texas A&M University bowmanATcsrp.tamu.edu
College Station, TX 77843-3150 Change the AT to @
Re: Search routines [message #12831 is a reply to message #12829] Fri, 18 September 1998 00:00 Go to previous message
Liam Gumley is currently offline  Liam Gumley
Messages: 473
Registered: November 1994
Senior Member
Kenneth P. Bowman wrote:
> IDL has a pretty good SORT routine, but no SEARCH routine that I have been
> able to find (that is, a procedure to find the index of the closest/first
> match in an ordered list). Once again, this can be done with loops, but
> such an implementation would almost certainly be much slower than a
> built-in function. Since searching and sorting are such basic operations,
> does anyone know why there is no SEARCH in IDL?

How about the MIN function, e.g.

array = findgen(100)
value = 37.2
result = min( abs( value - array ), location )
help, location

Cheers,
Liam.

---
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
1225 W. Dayton St., Madison WI 53706, USA
Phone (608) 265-5358, Fax (608) 262-5974
http://cimss.ssec.wisc.edu/~gumley
Re: Search routines [message #12841 is a reply to message #12829] Fri, 18 September 1998 00:00 Go to previous message
landsman is currently offline  landsman
Messages: 93
Registered: August 1991
Member
>
> I realize that WHERE will do the job, but at very low efficiency. WHERE
> makes no assumptions about the list being ordered. It seems to me it has
> to check every element of the array, requiring N steps for an N-element
> array. This is even worse than a linear search of an ordered list, which
> would require an average of N/2 steps. A simple bisection search would be
> LOG2(N) on average, which is, of course, very advantageous for large N.
>

The procedure tabinv.pro in http://idlastro.gsfc.nasa.gov/pub/ftp/math

will perform a vectorized binary search of a monotonic array.

Wayne Landsman landsman@mpb.gsfc.nasa.gov
Re: Search routines [message #12844 is a reply to message #12829] Fri, 18 September 1998 00:00 Go to previous message
bowman is currently offline  bowman
Messages: 121
Registered: September 1991
Senior Member
In article <MPG.106c1a47e9769edd9896bd@news.frii.com>, davidf@dfanning.com
(David Fanning) wrote:

> I thought that was the point of the WHERE function. :-)

I realize that WHERE will do the job, but at very low efficiency. WHERE
makes no assumptions about the list being ordered. It seems to me it has
to check every element of the array, requiring N steps for an N-element
array. This is even worse than a linear search of an ordered list, which
would require an average of N/2 steps. A simple bisection search would be
LOG2(N) on average, which is, of course, very advantageous for large N.

In article <36027091.59F@plato.sr.unh.edu>, Alexander Proussevitch
<alexp@plato.sr.unh.edu> wrote:

> Of course, there is such a routine. Check
>
> UNIQ !!!! It does any kind of search for you.

UNIQ seems to suffer from the same problem as WHERE, and I'm not sure what
use it is with floating point numbers.

Still looking ... ;-)

Ken

--
Dr. Kenneth P. Bowman, Professor 409-862-4060
Department of Meteorology 409-862-4466 fax
Texas A&M University bowmanATcsrp.tamu.edu
College Station, TX 77843-3150 Replace AT with @
Re: Search routines [message #12846 is a reply to message #12829] Fri, 18 September 1998 00:00 Go to previous message
Alexander Proussevitc is currently offline  Alexander Proussevitc
Messages: 3
Registered: September 1998
Junior Member
Kenneth P. Bowman wrote:
>
> IDL has a pretty good SORT routine, but no SEARCH routine that I have been
> able to find (that is, a procedure to find the index of the closest/first
> match in an ordered list). Once again, this can be done with loops, but
> such an implementation would almost certainly be much slower than a
> built-in function. Since searching and sorting are such basic operations,
> does anyone know why there is no SEARCH in IDL?
>
> Ken Bowman
>
> --
> Dr. Kenneth P. Bowman, Professor 409-862-4060
> Department of Meteorology 409-862-4466 fax
> Texas A&M University bowmanATcsrp.tamu.edu
> College Station, TX 77843-3150 Replace AT with @


Hi Kenneth:

Of course, there is such a routine. Check

UNIQ !!!! It does any kind of search for you.

-Alex P.
------------------------------------------------------------ ------
Alexander A. Proussevitch alex.proussevitch@unh.edu
Research Scientist

Climate Change Research Center, office (603)862-4796
Institute for the Study of fax (603)862-0188
Earth, Oceans, and Space,
University of New Hampshire,
Morse Hall, Room 357,
Durham, NH 03824-3525, USA
------------------------------------------------------------ ------
Re: Search routines [message #12849 is a reply to message #12829] Fri, 18 September 1998 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Kenneth P. Bowman (bowman@null.edu) writes:

> IDL has a pretty good SORT routine, but no SEARCH routine that I have been
> able to find (that is, a procedure to find the index of the closest/first
> match in an ordered list). Once again, this can be done with loops, but
> such an implementation would almost certainly be much slower than a
> built-in function. Since searching and sorting are such basic operations,
> does anyone know why there is no SEARCH in IDL?

I thought that was the point of the WHERE function. :-)

Cheers,

David

----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438, Toll-Free Book Orders: 1-888-461-0155
Coyote's Guide to IDL Programming: http://www.dfanning.com/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Cumulative total
Next Topic: Re: Multiple plot windows

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

Current Time: Wed Oct 08 16:00:25 PDT 2025

Total time taken to generate the page: 0.00681 seconds