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
Re: Multi-column sort [message #79456 is a reply to message #79404] Mon, 05 March 2012 02:59 Go to previous messageGo to previous message
Percy Pugwash is currently offline  Percy Pugwash
Messages: 12
Registered: January 2012
Junior Member
**bear in mind.

Oh dear...

P

On Monday, 5 March 2012 10:53:17 UTC, Percy Pugwash wrote:
> Thanks very much. I had looked at Craig Markwardt's multisort, but it didn't quite do what I wanted (the number of columns to sort by was limited and could not easily be changed at run-time).
>
> I've not looked at bsort yet, but will have a look, thanks. My only concern is that I'm aware that bubble sort is usually much slower than quicksort, which I believe sort() uses... Might still be worth it though.
>
> The solution I came up with is below, in case anyone is interested. Please bare in mind that it has not been properly tested, but seems to be working.
>
> P
>
> function sort_strcolumns, strtable, indices
> maxlen = max(strlen(strtable[abs(indices),*]))
> ncols = n_elements(indices)
> nrows = (size(strtable,/dim))[1]
> sortlist = reform(string(strtable[abs(indices),*],f='(a-'+string(maxlen ,f='(i0)')+')'),ncols,nrows,/overwrite)
> sortlist = reform(byte(sortlist),maxlen*ncols,nrows,/overwrite)
> for i=0,n_elements(indices)*maxlen-1 do sortlist[i,*] *= (-1)^(indices[i/maxlen] lt 0)
> return, sort(string(sortlist))
> end
>
> On Friday, 2 March 2012 12:26:00 UTC, Gianguido Cianci wrote:
>> Firstly, sort() does not maintain the order of identical elements so I'd use bsort() which you can find online somewhere, can't remember where... I believe it has a /reverse or /invert option, not at my computer right now.
>>
>> Secondly, you should bsort columns in increasing order of importance, with the most important sort last.
>>
>> I have a dumb for-loop procedure that does that. This requires multiple searches through the array, which might not be optimal, but once you write it, you'll never use sort instead of bsort again :-)
>>
>> G
[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: Sat Oct 11 12:58:11 PDT 2025

Total time taken to generate the page: 1.12131 seconds