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

Home » Public Forums » archive » Multi-column sort
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Multi-column sort [message #79404] Thu, 01 March 2012 07:02 Go to previous message
Percy Pugwash is currently offline  Percy Pugwash
Messages: 12
Registered: January 2012
Junior Member
I would like to sort a 2D string by column, specifying primary,
secondary and further sort criteria (i.e. rows which are equal based
on criterion 1 are sorted by criterion 2).

Is there any neat way to do this in IDL?

I'd thought of using the following:

tosort = [3,1,5] ; Sort by column 3, then 1, then 5
maxlen = max(strlen(sortarray[tosort,*])) ; Length of longest string
paddedarray =
string(sortarray[tosort,*],format='(a'+string(maxlen,format= '(i0)') +
')' ) ; Pad all strings to match longest length
concatarray = paddedarray[0,*]
for i = 0, n_elements(tosort)-1 do concatarray += paddedarray[i,*] ;
Concatenate strings across columns
indices = sort(concatarray) ; Sort the concatenated strings

However, this method does not allow me to specify which direction the
sort should go for each of the sort columns. Can anyone think of a way
to extend the method to allow this (or a completely different method
which achieves the same effect!)?

Thanks,

P
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How 2 show animations.
Next Topic: Re: Read Andor CCD camera .sif file format in IDL?

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

Current Time: Fri Oct 10 23:47:43 PDT 2025

Total time taken to generate the page: 1.04072 seconds