next up previous index
Next: M214 Conversion To Up: CERNLIB Previous: M107 Sort Rows

M109 Sort Rows of a Matrix

Routine ID: M109
Author(s): T. LindelöfLibrary: MATHLIB
Submitter: F. CarminatiSubmitted: 15.09.1978
Language: FortranRevised: 09.02.1989

SORTRQ rearranges the row order of a matrix in such a way that the elements of a selected column are either in increasing or decreasing order, as desired. Row orders are not necessarily preserved in case these elements are equal. Otherwise, SORTRQ does the same job as SORTR (M107), but SORTRQ is sometimes faster.

Structure:

SUBROUTINE subprogram
User Entry Names: SORTIQ, SORTRQ, SORTDQ
External References: USWOP (V301) (not on all machines)

Usage:

For t=I (type INTEGER), t=R (type REAL), t=D (type DOUBLE PRECISION),

    CALL SORTtQ(MX,NC,NR,NCS)
performs an ordering operation on the matrix MX of type t, dimensioned (NC,NR), using the NCS-th elements of each row as ordering criterion.

The matrix MX is stored by rows, the first element of a row following immediatly after the last element of the preceding row.

Obviously, 1 ≤|NCS| ≤NC is a condition. If this is not met, or if NR ≤1 , SORTtQ will do nothing.

If NCS > 0 , SORTRQ reorders the rows of MX in such a way that the NCS-th element of each row is the NCS-th element of the preceding row. If NCS < 0 , the rows of MX are reordered in the strict reverse order to that for NCS > 0 .

Based on an Algol procedure described in Ref. 1.

References:

  1. R.S. Scowen, Algorithm 271 QUICKERSORT, Collected Algorithms from CACM (1965).

M214


Janne Saarela
Mon Apr 3 15:06:23 METDST 1995