Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Array sorting

cacciatore
Beginner
1,484 Views
Hi
I need to sort the lines of a nx4 array, using the values of a column as the sorting parameter. The subs I found
in documentation are for one dimension arrays.
Can anyone help, indicating were can I find a subroutine that sorts a n x m array?
Thanks
Geraldo
0 Kudos
3 Replies
kdkeefer
Beginner
1,484 Views
Hi,
You didn't specify if the subsequent values in the first dimension are to be sorted subordinately to the prior ones. There are straightforward algorithims (see, e.g. Numerical Receipes, Press, et al.) in which one sorts an array whose sequential values contain the sequence number of the entry in the object array, were it sorted. This has the advantage that the entries in the array don't have to be moved.
Keith
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,484 Views
I use Michel Olagnon's sorting routines -- particularly, see MRGRNK, which doesn't sort but returns a rank array instead; you can use that to renumerate all items. You could possibly also try some qsort (QSORT or SORTQQ), basically treating the matrix as array of 4-byte structures.

Jugoslav
0 Kudos
cacciatore
Beginner
1,484 Views
Thanks Keith and Yugoslav.
I downloaded Orderpack, and will access Numerical Recipes ( I had it in my bookmarks but have never accessed it).
Will take some time to digest it all.
Geraldo
0 Kudos
Reply