[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: error with sort



If you are worried about what SORT does to equal values, you might
instead want to use the program bsort.pro, available at

ftp://idlastro.gsfc.nasa.gov/pub/pro/misc/bsort.pro

This procedure ensures that equal values are always maintained in the
initial order, i.e.

IDL> print,bsort([1,1,1,1,1])
           0           1           2           3           4

One place where this procedure is useful is when you are sorting on more
than one parameter.    For example, suppose you have a set of
temperature and pressure measurements (T, P), and want the primary sort
to be by temperature -- but whenever temperatures are equal, you want
the values sorted by pressure.   One can do this as follows:

     i1 = sort(P)                 ;Secondary sort on pressure
     i2 = bsort(T[i1])            ;primary sort on temperature

and i2 will give the desired indexing.
Of course, BSORT will be slower than the intrinsic SORT function.

Wayne Landsman                        landsman@mpb.gsfc.nasa.gov


Sent via Deja.com http://www.deja.com/
Before you buy.