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

Home » Public Forums » archive » Re: 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
Re: Inconsistency: "sort" on UNIX <-> Windows [message #20539] Fri, 07 July 2000 00:00
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Daniel Luebbert (luebbert@stanford.edu) writes:

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

What makes you think the Windows version is behaving "incorrectly"?
In fact, it could well be the UNIX version is screwy, as I prefer
to believe. :-)

But the truth of the matter is that you get different results because
IDL uses the system supplied qsort() routine on each platform,
and as they are different implementations, they are free to
return different sub-orders for the identical elements.

Why the Windows qsort is different from everyone else's
is a matter best taken up with Mr. Gates himself. If I
had to guess, I would guess that it's because the algorithm
used in the Windows qsort is an order of magnitude (at least)
faster than the qsort algorithm used in UNIX. :^)

Cheers,

David

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 Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Inconsistency: "sort" on UNIX <-> Windows [message #20540 is a reply to message #20539] Fri, 07 July 2000 00:00 Go to previous message
Liam E. Gumley is currently offline  Liam E. Gumley
Messages: 378
Registered: January 2000
Senior Member
Daniel Luebbert wrote:
> 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?

Search for 'BSORT' at
http://www.astro.washington.edu/deutsch/idl/htmlhelp/index.h tml

Cheers,
Liam.
http://cimss.ssec.wisc.edu/~gumley
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Object Graphics Selection
Next Topic: Object definition

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

Current Time: Wed Oct 08 15:36:35 PDT 2025

Total time taken to generate the page: 0.00589 seconds