1 SUBROUTINE SLAMRG( N1, N2, A, STRD1, STRD2, INDEX ) 2* 3* -- LAPACK routine (version 3.0) -- 4* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., 5* Courant Institute, Argonne National Lab, and Rice University 6* September 30, 1994 7* 8* .. Scalar Arguments .. 9 INTEGER N1, N2, STRD1, STRD2 10* .. 11* .. Array Arguments .. 12 INTEGER INDEX( * ) 13 REAL A( * ) 14* .. 15* 16* Purpose 17* ======= 18* 19* SLAMRG will create a permutation list which will merge the elements 20* of A (which is composed of two independently sorted sets) into a 21* single set which is sorted in ascending order. 22* 23* Arguments 24* ========= 25* 26* N1 (input) INTEGER 27* N2 (input) INTEGER 28* These arguements contain the respective lengths of the two 29* sorted lists to be merged. 30* 31* A (input) REAL array, dimension (N1+N2) 32* The first N1 elements of A contain a list of numbers which 33* are sorted in either ascending or descending order. Likewise 34* for the final N2 elements. 35* 36* STRD1 (input) INTEGER 37* STRD2 (input) INTEGER 38* These are the strides to be taken through the array A. 39* Allowable strides are 1 and -1. They indicate whether a 40* subset of A is sorted in ascending (STRDx = 1) or descending 41* (STRDx = -1) order. 42* 43* INDEX (output) INTEGER array, dimension (N1+N2) 44* On exit this array will contain a permutation such that 45* if B( I ) = A( INDEX( I ) ) for I=1,N1+N2, then B will be 46* sorted in ascending order. 47* 48* ===================================================================== 49* 50* .. Local Scalars .. 51 INTEGER I, IND1, IND2, N1SV, N2SV 52* .. 53* .. Executable Statements .. 54* 55 N1SV = N1 56 N2SV = N2 57 IF( STRD1.GT.0 ) THEN 58 IND1 = 1 59 ELSE 60 IND1 = N1 61 END IF 62 IF( STRD2.GT.0 ) THEN 63 IND2 = 1 + N1 64 ELSE 65 IND2 = N1 + N2 66 END IF 67 I = 1 68* while ( (N1SV > 0) & (N2SV > 0) ) 69 10 CONTINUE 70 IF( N1SV.GT.0 .AND. N2SV.GT.0 ) THEN 71 IF( A( IND1 ).LE.A( IND2 ) ) THEN 72 INDEX( I ) = IND1 73 I = I + 1 74 IND1 = IND1 + STRD1 75 N1SV = N1SV - 1 76 ELSE 77 INDEX( I ) = IND2 78 I = I + 1 79 IND2 = IND2 + STRD2 80 N2SV = N2SV - 1 81 END IF 82 GO TO 10 83 END IF 84* end while 85 IF( N1SV.EQ.0 ) THEN 86 DO 20 N1SV = 1, N2SV 87 INDEX( I ) = IND2 88 I = I + 1 89 IND2 = IND2 + STRD2 90 20 CONTINUE 91 ELSE 92* N2SV .EQ. 0 93 DO 30 N2SV = 1, N1SV 94 INDEX( I ) = IND1 95 I = I + 1 96 IND1 = IND1 + STRD1 97 30 CONTINUE 98 END IF 99* 100 RETURN 101* 102* End of SLAMRG 103* 104 END 105