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

Home » Public Forums » archive » Re: How do you sort an array in IDL?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: How do you sort an array in IDL? [message #11485 is a reply to message #11484] Thu, 02 April 1998 00:00 Go to previous messageGo to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Hi Folks,

> Here is a little example in which a two-column array is
> sorted by the values in the second column, it can
> easily be converted to a function that returns an
> array sorted by any column.

I'm in procrastination mode today. Here is my SortByColumn
function. As you can see, most of it is error checking. :-)

Call it like this:

sortedArray = SortByColumn(array, 3)

Cheers,

David

-----------------------------------------------------------
FUNCTION SortByColumn, array, column

; This function returns a sorted array of the same size and
; type as ARRAY, sorted over the values of the specified COLUMN.

; ARRAY -- 2D array to sort
; COLUMN -- The column to sort over.

On_Error, 1

; Required positional parameters.

IF N_Params() NE 2 THEN $
Message, 'ARRAY and COLUMN parameters are required'

; Get size of the array. Check parameters.

s = Size(array)
IF s[0] NE 2 THEN Message, 'Input array must be 2D. Returning...'

ncolumns = s[1]
IF column GT ncolumns THEN $
Message, "Specified COLUMN doesn't exist. Returning..."

; Sort the data by the specified column.

sortIndex = Sort(array[column,*])

RETURN, array[*,sortIndex]
END


-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Write-mask problem with "win" device?
Next Topic: drawing a shaded sphere

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

Current Time: Sun Oct 12 09:39:28 PDT 2025

Total time taken to generate the page: 1.03655 seconds