86
87
88
89
90
91
92 CHARACTER ID
93 INTEGER INFO, N
94
95
96 REAL D( * )
97
98
99
100
101
102 INTEGER SELECT
103 parameter( SELECT = 20 )
104
105
106 INTEGER DIR, ENDD, I, J, START, STKPNT
107 REAL D1, D2, D3, DMNMX, TMP
108
109
110 INTEGER STACK( 2, 32 )
111
112
113 LOGICAL LSAME
115
116
118
119
120
121
122
123 info = 0
124 dir = -1
125 IF(
lsame( id,
'D' ) )
THEN
126 dir = 0
127 ELSE IF(
lsame( id,
'I' ) )
THEN
128 dir = 1
129 END IF
130 IF( dir.EQ.-1 ) THEN
131 info = -1
132 ELSE IF( n.LT.0 ) THEN
133 info = -2
134 END IF
135 IF( info.NE.0 ) THEN
136 CALL xerbla(
'SLASRT', -info )
137 RETURN
138 END IF
139
140
141
142 IF( n.LE.1 )
143 $ RETURN
144
145 stkpnt = 1
146 stack( 1, 1 ) = 1
147 stack( 2, 1 ) = n
148 10 CONTINUE
149 start = stack( 1, stkpnt )
150 endd = stack( 2, stkpnt )
151 stkpnt = stkpnt - 1
152 IF( endd-start.LE.SELECT .AND. endd-start.GT.0 ) THEN
153
154
155
156 IF( dir.EQ.0 ) THEN
157
158
159
160 DO 30 i = start + 1, endd
161 DO 20 j = i, start + 1, -1
162 IF( d( j ).GT.d( j-1 ) ) THEN
163 dmnmx = d( j )
164 d( j ) = d( j-1 )
165 d( j-1 ) = dmnmx
166 ELSE
167 GO TO 30
168 END IF
169 20 CONTINUE
170 30 CONTINUE
171
172 ELSE
173
174
175
176 DO 50 i = start + 1, endd
177 DO 40 j = i, start + 1, -1
178 IF( d( j ).LT.d( j-1 ) ) THEN
179 dmnmx = d( j )
180 d( j ) = d( j-1 )
181 d( j-1 ) = dmnmx
182 ELSE
183 GO TO 50
184 END IF
185 40 CONTINUE
186 50 CONTINUE
187
188 END IF
189
190 ELSE IF( endd-start.GT.SELECT ) THEN
191
192
193
194
195
196 d1 = d( start )
197 d2 = d( endd )
198 i = ( start+endd ) / 2
199 d3 = d( i )
200 IF( d1.LT.d2 ) THEN
201 IF( d3.LT.d1 ) THEN
202 dmnmx = d1
203 ELSE IF( d3.LT.d2 ) THEN
204 dmnmx = d3
205 ELSE
206 dmnmx = d2
207 END IF
208 ELSE
209 IF( d3.LT.d2 ) THEN
210 dmnmx = d2
211 ELSE IF( d3.LT.d1 ) THEN
212 dmnmx = d3
213 ELSE
214 dmnmx = d1
215 END IF
216 END IF
217
218 IF( dir.EQ.0 ) THEN
219
220
221
222 i = start - 1
223 j = endd + 1
224 60 CONTINUE
225 70 CONTINUE
226 j = j - 1
227 IF( d( j ).LT.dmnmx )
228 $ GO TO 70
229 80 CONTINUE
230 i = i + 1
231 IF( d( i ).GT.dmnmx )
232 $ GO TO 80
233 IF( i.LT.j ) THEN
234 tmp = d( i )
235 d( i ) = d( j )
236 d( j ) = tmp
237 GO TO 60
238 END IF
239 IF( j-start.GT.endd-j-1 ) THEN
240 stkpnt = stkpnt + 1
241 stack( 1, stkpnt ) = start
242 stack( 2, stkpnt ) = j
243 stkpnt = stkpnt + 1
244 stack( 1, stkpnt ) = j + 1
245 stack( 2, stkpnt ) = endd
246 ELSE
247 stkpnt = stkpnt + 1
248 stack( 1, stkpnt ) = j + 1
249 stack( 2, stkpnt ) = endd
250 stkpnt = stkpnt + 1
251 stack( 1, stkpnt ) = start
252 stack( 2, stkpnt ) = j
253 END IF
254 ELSE
255
256
257
258 i = start - 1
259 j = endd + 1
260 90 CONTINUE
261 100 CONTINUE
262 j = j - 1
263 IF( d( j ).GT.dmnmx )
264 $ GO TO 100
265 110 CONTINUE
266 i = i + 1
267 IF( d( i ).LT.dmnmx )
268 $ GO TO 110
269 IF( i.LT.j ) THEN
270 tmp = d( i )
271 d( i ) = d( j )
272 d( j ) = tmp
273 GO TO 90
274 END IF
275 IF( j-start.GT.endd-j-1 ) THEN
276 stkpnt = stkpnt + 1
277 stack( 1, stkpnt ) = start
278 stack( 2, stkpnt ) = j
279 stkpnt = stkpnt + 1
280 stack( 1, stkpnt ) = j + 1
281 stack( 2, stkpnt ) = endd
282 ELSE
283 stkpnt = stkpnt + 1
284 stack( 1, stkpnt ) = j + 1
285 stack( 2, stkpnt ) = endd
286 stkpnt = stkpnt + 1
287 stack( 1, stkpnt ) = start
288 stack( 2, stkpnt ) = j
289 END IF
290 END IF
291 END IF
292 IF( stkpnt.GT.0 )
293 $ GO TO 10
294 RETURN
295
296
297
subroutine xerbla(srname, info)
logical function lsame(ca, cb)
LSAME