error with sort [message #18456] |
Mon, 10 January 2000 00:00  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Hi,
SORT() is not platform independent!!!!!
Try this:
** Structure !VERSION, 5 tags, length=40:
ARCH STRING 'x86'
OS STRING 'Win32'
OS_FAMILY STRING 'Windows'
RELEASE STRING '5.2'
BUILD_DATE STRING 'Oct 30 1998'
OR
* Structure !VERSION, 5 tags, length=40:
ARCH STRING 'x86'
OS STRING 'Win32'
OS_FAMILY STRING 'Windows'
RELEASE STRING '5.3'
BUILD_DATE STRING 'Nov 11 1999'
a=[1,1,1,1,1]
idx=sort(a)
PRINT,idx
1 2 3 4 0
b=['A','B','C','D','E']
PRINT,b[idx]
B C D E A
** Structure !VERSION, 5 tags, length=40:
ARCH STRING 'ibmr2'
OS STRING 'AIX'
OS_FAMILY STRING 'unix'
RELEASE STRING '5.2.1'
BUILD_DATE STRING 'Jun 4 1999'
a=[1,1,1,1,1]
idx=sort(a)
PRINT,idx
1 0 2 4 3
b=['A','B','C','D','E']
PRINT,b[idx]
B A C E D
================================================
R.Bauer
-
Attachment: R.Bauer.vcf
(Size: 0.00KB, Downloaded 80 times)
|
|
|
|
Re: error with sort [message #18569 is a reply to message #18456] |
Thu, 13 January 2000 00:00  |
Martin Schultz
Messages: 515 Registered: August 1997
|
Senior Member |
|
|
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()
> 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) ;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= [,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 [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
|
|
|