Inconsistency: "sort" on UNIX <-> Windows [message #20542] |
Fri, 07 July 2000 00:00  |
Daniel Luebbert
Messages: 6 Registered: May 2000
|
Junior Member |
|
|
Hi,
I've been using the "sort" routine to sort an 2D-array by increasing
values of its first column.
The "sort" routine seems to behave differently in the UNIX and the
Windows versions of IDL5.3.
Here is a little test routine I wrote:
;**************************
pro test_sort
data = [[1,3], $
[2,5], $
[1,4], $
[4,7], $
[1,2] $
]
print,"original: "
print,data
print,"sorted: "
print,data[*,sort(data[0,*])]
end
;**************************
The result on UNIX (Linux) is what I would expect:
;**************************
original:
1 3
2 5
1 4
4 7
1 2
sorted:
1 3
1 4
1 2
2 5
4 7
;**************************
BUT: The result on Windows is different:
;**************************
original:
1 3
2 5
1 4
4 7
1 2
sorted:
1 2
1 4
1 3
2 5
4 7
;**************************
In other words: The "sort" routine on Windows doesn't preserve the
original order of entries which have the same value (see the 3
"1"-values in my test data), but apparently rearranges them in a random
way.
What I'd like to know is:
How can it be that such a basic routine behaves differently in differnet
implementations of IDL?
And, more importantly: can anybody tell me how to make the
Windows-version of "sort" behave correctly,
without writing my own routine for sorting?
THanks for any hint,
Daniel
--
------------------------------------------------------------ ------------
Dr. Daniel L�bbert
Stanford Synchrotron Radiation Laboratory (SSRL)
Bldg. 137, Mailstop 69, 2575 Sandhill Road, Menlo Park, CA 94025, USA
Phone: (650) 926-4010 FAX: (650) 926-4100
luebbert@slac.stanford.edu
|
|
|
|
Re: Inconsistency: "sort" on UNIX <-> Windows [message #21047 is a reply to message #20542] |
Fri, 04 August 2000 00:00  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
here is another sort method from our library too.
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_source/idl_ html/dbase/download/n_sort.tar.gz
; NAME:
; n_sort
;
; PURPOSE:
; sort an array according to n columns
;
; CATEGORY:
; MATH
;
; CALLING SEQUENCE:
; result=n_sort(matrix)
;
; INPUTS:
; matrix : the input matrix, which shoul be sorted
;
; KEYWORD PARAMETERS:
; INDEX: a vector of column numbers (default: indgen(number of
columns))
; it defines the order of the columns, how the matrix will be
sorted
;
; DECREASING_ORDER: the matrix will be sorted decreasingly
;
; OUTPUTS:
; j_index: the vector of sorted line numbers
;
; EXAMPLE:
; matrix = [[ 2, 3, 4 ], $
; [ 1, 4, 6 ], $
; [ 1, 4, 5 ]]
; j_index=n_sort(matrix)
; j_index=[2,1,0]
;
; matrix = [[ 1, 4, 5 ], $
; [ 1, 4, 6 ], $
; [ 2, 3, 4 ]]
; j_index=n_sort(matrix,index=[1,0,2])
; j_index=[2,0,1]
Reimar Bauer
|
|
|