139
140
141
142
143
144
145 LOGICAL ORGATI
146 INTEGER INFO, KNITER
147 REAL FINIT, RHO, TAU
148
149
150 REAL D( 3 ), Z( 3 )
151
152
153
154
155
156 INTEGER MAXIT
157 parameter( maxit = 40 )
158 REAL ZERO, ONE, TWO, THREE, FOUR, EIGHT
159 parameter( zero = 0.0e0, one = 1.0e0, two = 2.0e0,
160 $ three = 3.0e0, four = 4.0e0, eight = 8.0e0 )
161
162
163 REAL SLAMCH
165
166
167 REAL DSCALE( 3 ), ZSCALE( 3 )
168
169
170 LOGICAL SCALE
171 INTEGER I, ITER, NITER
172 REAL A, B, BASE, C, DDF, DF, EPS, ERRETM, ETA, F,
173 $ FC, SCLFAC, SCLINV, SMALL1, SMALL2, SMINV1,
174 $ SMINV2, TEMP, TEMP1, TEMP2, TEMP3, TEMP4,
175 $ LBD, UBD
176
177
178 INTRINSIC abs, int, log, max, min, sqrt
179
180
181
182 info = 0
183
184 IF( orgati ) THEN
185 lbd = d(2)
186 ubd = d(3)
187 ELSE
188 lbd = d(1)
189 ubd = d(2)
190 END IF
191 IF( finit .LT. zero )THEN
192 lbd = zero
193 ELSE
194 ubd = zero
195 END IF
196
197 niter = 1
198 tau = zero
199 IF( kniter.EQ.2 ) THEN
200 IF( orgati ) THEN
201 temp = ( d( 3 )-d( 2 ) ) / two
202 c = rho + z( 1 ) / ( ( d( 1 )-d( 2 ) )-temp )
203 a = c*( d( 2 )+d( 3 ) ) + z( 2 ) + z( 3 )
204 b = c*d( 2 )*d( 3 ) + z( 2 )*d( 3 ) + z( 3 )*d( 2 )
205 ELSE
206 temp = ( d( 1 )-d( 2 ) ) / two
207 c = rho + z( 3 ) / ( ( d( 3 )-d( 2 ) )-temp )
208 a = c*( d( 1 )+d( 2 ) ) + z( 1 ) + z( 2 )
209 b = c*d( 1 )*d( 2 ) + z( 1 )*d( 2 ) + z( 2 )*d( 1 )
210 END IF
211 temp = max( abs( a ), abs( b ), abs( c ) )
212 a = a / temp
213 b = b / temp
214 c = c / temp
215 IF( c.EQ.zero ) THEN
216 tau = b / a
217 ELSE IF( a.LE.zero ) THEN
218 tau = ( a-sqrt( abs( a*a-four*b*c ) ) ) / ( two*c )
219 ELSE
220 tau = two*b / ( a+sqrt( abs( a*a-four*b*c ) ) )
221 END IF
222 IF( tau .LT. lbd .OR. tau .GT. ubd )
223 $ tau = ( lbd+ubd )/two
224 IF( d(1).EQ.tau .OR. d(2).EQ.tau .OR. d(3).EQ.tau ) THEN
225 tau = zero
226 ELSE
227 temp = finit + tau*z(1)/( d(1)*( d( 1 )-tau ) ) +
228 $ tau*z(2)/( d(2)*( d( 2 )-tau ) ) +
229 $ tau*z(3)/( d(3)*( d( 3 )-tau ) )
230 IF( temp .LE. zero )THEN
231 lbd = tau
232 ELSE
233 ubd = tau
234 END IF
235 IF( abs( finit ).LE.abs( temp ) )
236 $ tau = zero
237 END IF
238 END IF
239
240
241
242
243
244
245
248 small1 = base**( int( log(
slamch(
'SafMin' ) ) / log( base ) /
249 $ three ) )
250 sminv1 = one / small1
251 small2 = small1*small1
252 sminv2 = sminv1*sminv1
253
254
255
256
257 IF( orgati ) THEN
258 temp = min( abs( d( 2 )-tau ), abs( d( 3 )-tau ) )
259 ELSE
260 temp = min( abs( d( 1 )-tau ), abs( d( 2 )-tau ) )
261 END IF
262 scale = .false.
263 IF( temp.LE.small1 ) THEN
264 scale = .true.
265 IF( temp.LE.small2 ) THEN
266
267
268
269 sclfac = sminv2
270 sclinv = small2
271 ELSE
272
273
274
275 sclfac = sminv1
276 sclinv = small1
277 END IF
278
279
280
281 DO 10 i = 1, 3
282 dscale( i ) = d( i )*sclfac
283 zscale( i ) = z( i )*sclfac
284 10 CONTINUE
285 tau = tau*sclfac
286 lbd = lbd*sclfac
287 ubd = ubd*sclfac
288 ELSE
289
290
291
292 DO 20 i = 1, 3
293 dscale( i ) = d( i )
294 zscale( i ) = z( i )
295 20 CONTINUE
296 END IF
297
298 fc = zero
299 df = zero
300 ddf = zero
301 DO 30 i = 1, 3
302 temp = one / ( dscale( i )-tau )
303 temp1 = zscale( i )*temp
304 temp2 = temp1*temp
305 temp3 = temp2*temp
306 fc = fc + temp1 / dscale( i )
307 df = df + temp2
308 ddf = ddf + temp3
309 30 CONTINUE
310 f = finit + tau*fc
311
312 IF( abs( f ).LE.zero )
313 $ GO TO 60
314 IF( f .LE. zero )THEN
315 lbd = tau
316 ELSE
317 ubd = tau
318 END IF
319
320
321
322
323
324
325
326
327
328
329
330
331 iter = niter + 1
332
333 DO 50 niter = iter, maxit
334
335 IF( orgati ) THEN
336 temp1 = dscale( 2 ) - tau
337 temp2 = dscale( 3 ) - tau
338 ELSE
339 temp1 = dscale( 1 ) - tau
340 temp2 = dscale( 2 ) - tau
341 END IF
342 a = ( temp1+temp2 )*f - temp1*temp2*df
343 b = temp1*temp2*f
344 c = f - ( temp1+temp2 )*df + temp1*temp2*ddf
345 temp = max( abs( a ), abs( b ), abs( c ) )
346 a = a / temp
347 b = b / temp
348 c = c / temp
349 IF( c.EQ.zero ) THEN
350 eta = b / a
351 ELSE IF( a.LE.zero ) THEN
352 eta = ( a-sqrt( abs( a*a-four*b*c ) ) ) / ( two*c )
353 ELSE
354 eta = two*b / ( a+sqrt( abs( a*a-four*b*c ) ) )
355 END IF
356 IF( f*eta.GE.zero ) THEN
357 eta = -f / df
358 END IF
359
360 tau = tau + eta
361 IF( tau .LT. lbd .OR. tau .GT. ubd )
362 $ tau = ( lbd + ubd )/two
363
364 fc = zero
365 erretm = zero
366 df = zero
367 ddf = zero
368 DO 40 i = 1, 3
369 IF ( ( dscale( i )-tau ).NE.zero ) THEN
370 temp = one / ( dscale( i )-tau )
371 temp1 = zscale( i )*temp
372 temp2 = temp1*temp
373 temp3 = temp2*temp
374 temp4 = temp1 / dscale( i )
375 fc = fc + temp4
376 erretm = erretm + abs( temp4 )
377 df = df + temp2
378 ddf = ddf + temp3
379 ELSE
380 GO TO 60
381 END IF
382 40 CONTINUE
383 f = finit + tau*fc
384 erretm = eight*( abs( finit )+abs( tau )*erretm ) +
385 $ abs( tau )*df
386 IF( ( abs( f ).LE.four*eps*erretm ) .OR.
387 $ ( (ubd-lbd).LE.four*eps*abs(tau) ) )
388 $ GO TO 60
389 IF( f .LE. zero )THEN
390 lbd = tau
391 ELSE
392 ubd = tau
393 END IF
394 50 CONTINUE
395 info = 1
396 60 CONTINUE
397
398
399
400 IF( scale )
401 $ tau = tau*sclinv
402 RETURN
403
404
405
real function slamch(cmach)
SLAMCH