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

◆ dlamrg()

subroutine dlamrg ( integer n1,
integer n2,
double precision, dimension( * ) a,
integer dtrd1,
integer dtrd2,
integer, dimension( * ) index )

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

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

Purpose:
!>
!> DLAMRG 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 DOUBLE PRECISION 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]DTRD1
!>          DTRD1 is INTEGER
!> 
[in]DTRD2
!>          DTRD2 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 (DTRDx = 1) or descending
!>         (DTRDx = -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 96 of file dlamrg.f.

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