6
c Sorts the Complex*16 array in X into the order
7
c specified by WHICH and optionally applies the permutation to the
8
c Double precision array Y.
12
c ( WHICH, APPLY, N, X, Y )
15
c WHICH Character*2. (Input)
16
c 'LM' -> sort X into increasing order of magnitude.
17
c 'SM' -> sort X into decreasing order of magnitude.
18
c 'LR' -> sort X with real(X) in increasing algebraic order
19
c 'SR' -> sort X with real(X) in decreasing algebraic order
20
c 'LI' -> sort X with imag(X) in increasing algebraic order
21
c 'SI' -> sort X with imag(X) in decreasing algebraic order
23
c APPLY Logical. (Input)
24
c APPLY = .TRUE. -> apply the sorted order to array Y.
25
c APPLY = .FALSE. -> do not apply the sorted order to array Y.
30
c X Complex*16 array of length N. (INPUT/OUTPUT)
31
c This is the array to be sorted.
33
c Y Complex*16 array of length N. (INPUT/OUTPUT)
37
c-----------------------------------------------------------------------
42
c dlapy2 LAPACK routine to compute sqrt(x**2+y**2) carefully.
45
c Danny Sorensen Phuong Vu
46
c Richard Lehoucq CRPC / Rice University
47
c Dept. of Computational & Houston, Texas
52
c Adapted from the sort routine in LANSO.
54
c\SCCS Information: @(#)
55
c FILE: sortc.F SID: 2.2 DATE OF SID: 4/20/96 RELEASE: 2
59
c-----------------------------------------------------------------------
61
subroutine zsortc (which, apply, n, x, y)
63
c %------------------%
64
c | Scalar Arguments |
65
c %------------------%
88
c %--------------------%
89
c | External functions |
90
c %--------------------%
95
c %--------------------%
96
c | Intrinsic Functions |
97
c %--------------------%
101
c %-----------------------%
102
c | Executable Statements |
103
c %-----------------------%
107
if (which .eq. 'LM') then
109
c %--------------------------------------------%
110
c | Sort X into increasing order of magnitude. |
111
c %--------------------------------------------%
114
if (igap .eq. 0) go to 9000
122
temp1 = dlapy2(dble(x(j)),dimag(x(j)))
123
temp2 = dlapy2(dble(x(j+igap)),dimag(x(j+igap)))
125
if (temp1.gt.temp2) then
144
else if (which .eq. 'SM') then
146
c %--------------------------------------------%
147
c | Sort X into decreasing order of magnitude. |
148
c %--------------------------------------------%
151
if (igap .eq. 0) go to 9000
157
if (j .lt. 0) go to 60
159
temp1 = dlapy2(dble(x(j)),dimag(x(j)))
160
temp2 = dlapy2(dble(x(j+igap)),dimag(x(j+igap)))
162
if (temp1.lt.temp2) then
181
else if (which .eq. 'LR') then
183
c %------------------------------------------------%
184
c | Sort XREAL into increasing order of algebraic. |
185
c %------------------------------------------------%
188
if (igap .eq. 0) go to 9000
196
if (dble(x(j)).gt.dble(x(j+igap))) then
215
else if (which .eq. 'SR') then
217
c %------------------------------------------------%
218
c | Sort XREAL into decreasing order of algebraic. |
219
c %------------------------------------------------%
222
if (igap .eq. 0) go to 9000
227
if (j.lt.0) go to 120
229
if (dble(x(j)).lt.dble(x(j+igap))) then
248
else if (which .eq. 'LI') then
250
c %--------------------------------------------%
251
c | Sort XIMAG into increasing algebraic order |
252
c %--------------------------------------------%
255
if (igap .eq. 0) go to 9000
260
if (j.lt.0) go to 150
262
if (dimag(x(j)).gt.dimag(x(j+igap))) then
281
else if (which .eq. 'SI') then
283
c %---------------------------------------------%
284
c | Sort XIMAG into decreasing algebraic order |
285
c %---------------------------------------------%
288
if (igap .eq. 0) go to 9000
293
if (j.lt.0) go to 180
295
if (dimag(x(j)).lt.dimag(x(j+igap))) then