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

Re: error with sort



landsman@my-deja.com wrote:
> 
> 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

For this purpose, I have written a multisort routine that is (hopefully)
still available at
http://www-as.harvard.edu/chemistry/trop/staff/mgs/idl
This allows "hierarchical" sorting for (I believe) up to 5 variables.

Usage: multisort,array,index=[2,1,0]  [,revert=[0,1,0] ]
to sort a >= 3-dimensional array for primary key 'column 2', secondary
key 'column 1' and tertiary key 'column 3'. The revert option allows you
to do an inverse sort for any hierarchy level.

I'd be interested to know how multisort performs compared to the bsort
method you proposed.

Cheers,
Martin

-- 
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
[[ Dr. Martin Schultz   Max-Planck-Institut fuer Meteorologie    [[
[[                      Bundesstr. 55, 20146 Hamburg             [[
[[                      phone: +49 40 41173-308                  [[
[[                      fax:   +49 40 41173-298                  [[
[[ martin.schultz@dkrz.de                                        [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[