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

Home » Public Forums » archive » Inconsistency: "sort" on UNIX <-> Windows
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
Inconsistency: "sort" on UNIX <-> Windows [message #20542] Fri, 07 July 2000 00:00 Go to next message
Daniel Luebbert is currently offline  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 #20720 is a reply to message #20542] Tue, 18 July 2000 00:00 Go to previous messageGo to next message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
David Fanning wrote:
>
> Daniel Luebbert (luebbert@stanford.edu) writes:

>> 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.
>>

>
> P.S. There is not much that can be done, except sort
> the other dimension by some consistent criteria (e.g.
> the "order" in the original array). Ugly, but perhaps
> necessary depending upon your application.
>
> David

... and for this you could use my multisort.pro which you find at
http://www.mpimet.mpg.de/~schultz.martin/idl/

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 [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
Re: Inconsistency: "sort" on UNIX <-> Windows [message #21047 is a reply to message #20542] Fri, 04 August 2000 00:00 Go to previous message
R.Bauer is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: User-added Postscript fonts
Next Topic: Strange PRINTER Coordinates

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

Current Time: Sun Oct 12 08:16:43 PDT 2025

Total time taken to generate the page: 0.80030 seconds