LAPACK 3.12.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ slamrg()

subroutine slamrg ( integer  n1,
integer  n2,
real, dimension( * )  a,
integer  strd1,
integer  strd2,
integer, dimension( * )  index 
)

SLAMRG creates a permutation list to merge the entries of two independently sorted sets into a single set sorted in ascending order.

Download SLAMRG + dependencies [TGZ] [ZIP] [TXT]

Purpose:
 SLAMRG will create a permutation list which will merge the elements
 of A (which is composed of two independently sorted sets) into a
 single set which is sorted in ascending order.
Parameters
[in]N1
          N1 is INTEGER
[in]N2
          N2 is INTEGER
         These arguments contain the respective lengths of the two
         sorted lists to be merged.
[in]A
          A is REAL array, dimension (N1+N2)
         The first N1 elements of A contain a list of numbers which
         are sorted in either ascending or descending order.  Likewise
         for the final N2 elements.
[in]STRD1
          STRD1 is INTEGER
[in]STRD2
          STRD2 is INTEGER
         These are the strides to be taken through the array A.
         Allowable strides are 1 and -1.  They indicate whether a
         subset of A is sorted in ascending (STRDx = 1) or descending
         (STRDx = -1) order.
[out]INDEX
          INDEX is INTEGER array, dimension (N1+N2)
         On exit this array will contain a permutation such that
         if B( I ) = A( INDEX( I ) ) for I=1,N1+N2, then B will be
         sorted in ascending order.
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.

Definition at line 98 of file slamrg.f.

99*
100* -- LAPACK computational routine --
101* -- LAPACK is a software package provided by Univ. of Tennessee, --
102* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
103*
104* .. Scalar Arguments ..
105 INTEGER N1, N2, STRD1, STRD2
106* ..
107* .. Array Arguments ..
108 INTEGER INDEX( * )
109 REAL A( * )
110* ..
111*
112* =====================================================================
113*
114* .. Local Scalars ..
115 INTEGER I, IND1, IND2, N1SV, N2SV
116* ..
117* .. Executable Statements ..
118*
119 n1sv = n1
120 n2sv = n2
121 IF( strd1.GT.0 ) THEN
122 ind1 = 1
123 ELSE
124 ind1 = n1
125 END IF
126 IF( strd2.GT.0 ) THEN
127 ind2 = 1 + n1
128 ELSE
129 ind2 = n1 + n2
130 END IF
131 i = 1
132* while ( (N1SV > 0) & (N2SV > 0) )
133 10 CONTINUE
134 IF( n1sv.GT.0 .AND. n2sv.GT.0 ) THEN
135 IF( a( ind1 ).LE.a( ind2 ) ) THEN
136 index( i ) = ind1
137 i = i + 1
138 ind1 = ind1 + strd1
139 n1sv = n1sv - 1
140 ELSE
141 index( i ) = ind2
142 i = i + 1
143 ind2 = ind2 + strd2
144 n2sv = n2sv - 1
145 END IF
146 GO TO 10
147 END IF
148* end while
149 IF( n1sv.EQ.0 ) THEN
150 DO 20 n1sv = 1, n2sv
151 index( i ) = ind2
152 i = i + 1
153 ind2 = ind2 + strd2
154 20 CONTINUE
155 ELSE
156* N2SV .EQ. 0
157 DO 30 n2sv = 1, n1sv
158 index( i ) = ind1
159 i = i + 1
160 ind1 = ind1 + strd1
161 30 CONTINUE
162 END IF
163*
164 RETURN
165*
166* End of SLAMRG
167*
Here is the caller graph for this function: