001:       SUBROUTINE SLAMRG( N1, N2, A, STRD1, STRD2, INDEX )
002: *
003: *  -- LAPACK routine (version 3.2) --
004: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
005: *     November 2006
006: *
007: *     .. Scalar Arguments ..
008:       INTEGER            N1, N2, STRD1, STRD2
009: *     ..
010: *     .. Array Arguments ..
011:       INTEGER            INDEX( * )
012:       REAL               A( * )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  SLAMRG will create a permutation list which will merge the elements
019: *  of A (which is composed of two independently sorted sets) into a
020: *  single set which is sorted in ascending order.
021: *
022: *  Arguments
023: *  =========
024: *
025: *  N1     (input) INTEGER
026: *  N2     (input) INTEGER
027: *         These arguements contain the respective lengths of the two
028: *         sorted lists to be merged.
029: *
030: *  A      (input) REAL array, dimension (N1+N2)
031: *         The first N1 elements of A contain a list of numbers which
032: *         are sorted in either ascending or descending order.  Likewise
033: *         for the final N2 elements.
034: *
035: *  STRD1  (input) INTEGER
036: *  STRD2  (input) INTEGER
037: *         These are the strides to be taken through the array A.
038: *         Allowable strides are 1 and -1.  They indicate whether a
039: *         subset of A is sorted in ascending (STRDx = 1) or descending
040: *         (STRDx = -1) order.
041: *
042: *  INDEX  (output) INTEGER array, dimension (N1+N2)
043: *         On exit this array will contain a permutation such that
044: *         if B( I ) = A( INDEX( I ) ) for I=1,N1+N2, then B will be
045: *         sorted in ascending order.
046: *
047: *  =====================================================================
048: *
049: *     .. Local Scalars ..
050:       INTEGER            I, IND1, IND2, N1SV, N2SV
051: *     ..
052: *     .. Executable Statements ..
053: *
054:       N1SV = N1
055:       N2SV = N2
056:       IF( STRD1.GT.0 ) THEN
057:          IND1 = 1
058:       ELSE
059:          IND1 = N1
060:       END IF
061:       IF( STRD2.GT.0 ) THEN
062:          IND2 = 1 + N1
063:       ELSE
064:          IND2 = N1 + N2
065:       END IF
066:       I = 1
067: *     while ( (N1SV > 0) & (N2SV > 0) )
068:    10 CONTINUE
069:       IF( N1SV.GT.0 .AND. N2SV.GT.0 ) THEN
070:          IF( A( IND1 ).LE.A( IND2 ) ) THEN
071:             INDEX( I ) = IND1
072:             I = I + 1
073:             IND1 = IND1 + STRD1
074:             N1SV = N1SV - 1
075:          ELSE
076:             INDEX( I ) = IND2
077:             I = I + 1
078:             IND2 = IND2 + STRD2
079:             N2SV = N2SV - 1
080:          END IF
081:          GO TO 10
082:       END IF
083: *     end while
084:       IF( N1SV.EQ.0 ) THEN
085:          DO 20 N1SV = 1, N2SV
086:             INDEX( I ) = IND2
087:             I = I + 1
088:             IND2 = IND2 + STRD2
089:    20    CONTINUE
090:       ELSE
091: *     N2SV .EQ. 0
092:          DO 30 N2SV = 1, N1SV
093:             INDEX( I ) = IND1
094:             I = I + 1
095:             IND1 = IND1 + STRD1
096:    30    CONTINUE
097:       END IF
098: *
099:       RETURN
100: *
101: *     End of SLAMRG
102: *
103:       END
104: