00001 SUBROUTINE DDASTP (X, Y, YPRIME, NEQ, RES, JAC, H, WT, JSTART,
00002 + IDID, RPAR, IPAR, PHI, DELTA, E, WM, IWM, ALPHA, BETA, GAMMA,
00003 + PSI, SIGMA, CJ, CJOLD, HOLD, S, HMIN, UROUND, IPHASE, JCALC,
00004 + K, KOLD, NS, NONNEG, NTEMP)
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 INTEGER NEQ, JSTART, IDID, IPAR(*), IWM(*), IPHASE, JCALC, K,
00095 * KOLD, NS, NONNEG, NTEMP
00096 DOUBLE PRECISION
00097 * X, Y(*), YPRIME(*), H, WT(*), RPAR(*), PHI(NEQ,*), DELTA(*),
00098 * E(*), WM(*), ALPHA(*), BETA(*), GAMMA(*), PSI(*), SIGMA(*), CJ,
00099 * CJOLD, HOLD, S, HMIN, UROUND
00100 EXTERNAL RES, JAC
00101
00102 EXTERNAL DDAJAC, DDANRM, DDASLV, DDATRP
00103 DOUBLE PRECISION DDANRM
00104
00105 INTEGER I, IER, IRES, J, J1, KDIFF, KM1, KNEW, KP1, KP2, LCTF,
00106 * LETF, LMXORD, LNJE, LNRE, LNST, M, MAXIT, NCF, NEF, NSF, NSP1
00107 DOUBLE PRECISION
00108 * ALPHA0, ALPHAS, CJLAST, CK, DELNRM, ENORM, ERK, ERKM1,
00109 * ERKM2, ERKP1, ERR, EST, HNEW, OLDNRM, PNORM, R, RATE, TEMP1,
00110 * TEMP2, TERK, TERKM1, TERKM2, TERKP1, XOLD, XRATE
00111 LOGICAL CONVGD
00112
00113 PARAMETER (LMXORD=3)
00114 PARAMETER (LNST=11)
00115 PARAMETER (LNRE=12)
00116 PARAMETER (LNJE=13)
00117 PARAMETER (LETF=14)
00118 PARAMETER (LCTF=15)
00119
00120 DATA MAXIT/4/
00121 DATA XRATE/0.25D0/
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 IDID=1
00137 XOLD=X
00138 NCF=0
00139 NSF=0
00140 NEF=0
00141 IF(JSTART .NE. 0) GO TO 120
00142
00143
00144
00145 IWM(LETF) = 0
00146 IWM(LCTF) = 0
00147 K=1
00148 KOLD=0
00149 HOLD=0.0D0
00150 JSTART=1
00151 PSI(1)=H
00152 CJOLD = 1.0D0/H
00153 CJ = CJOLD
00154 S = 100.D0
00155 JCALC = -1
00156 DELNRM=1.0D0
00157 IPHASE = 0
00158 NS=0
00159 120 CONTINUE
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 200 CONTINUE
00171 KP1=K+1
00172 KP2=K+2
00173 KM1=K-1
00174 XOLD=X
00175 IF(H.NE.HOLD.OR.K .NE. KOLD) NS = 0
00176 NS=MIN(NS+1,KOLD+2)
00177 NSP1=NS+1
00178 IF(KP1 .LT. NS)GO TO 230
00179
00180 BETA(1)=1.0D0
00181 ALPHA(1)=1.0D0
00182 TEMP1=H
00183 GAMMA(1)=0.0D0
00184 SIGMA(1)=1.0D0
00185 DO 210 I=2,KP1
00186 TEMP2=PSI(I-1)
00187 PSI(I-1)=TEMP1
00188 BETA(I)=BETA(I-1)*PSI(I-1)/TEMP2
00189 TEMP1=TEMP2+H
00190 ALPHA(I)=H/TEMP1
00191 SIGMA(I)=(I-1)*SIGMA(I-1)*ALPHA(I)
00192 GAMMA(I)=GAMMA(I-1)+ALPHA(I-1)/H
00193 210 CONTINUE
00194 PSI(KP1)=TEMP1
00195 230 CONTINUE
00196
00197
00198 ALPHAS = 0.0D0
00199 ALPHA0 = 0.0D0
00200 DO 240 I = 1,K
00201 ALPHAS = ALPHAS - 1.0D0/I
00202 ALPHA0 = ALPHA0 - ALPHA(I)
00203 240 CONTINUE
00204
00205
00206 CJLAST = CJ
00207 CJ = -ALPHAS/H
00208
00209
00210 CK = ABS(ALPHA(KP1) + ALPHAS - ALPHA0)
00211 CK = MAX(CK,ALPHA(KP1))
00212
00213
00214 TEMP1 = (1.0D0 - XRATE)/(1.0D0 + XRATE)
00215 TEMP2 = 1.0D0/TEMP1
00216 IF (CJ/CJOLD .LT. TEMP1 .OR. CJ/CJOLD .GT. TEMP2) JCALC = -1
00217 IF (CJ .NE. CJLAST) S = 100.D0
00218
00219
00220 IF(KP1 .LT. NSP1) GO TO 280
00221 DO 270 J=NSP1,KP1
00222 DO 260 I=1,NEQ
00223 260 PHI(I,J)=BETA(J)*PHI(I,J)
00224 270 CONTINUE
00225 280 CONTINUE
00226
00227
00228 X=X+H
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 300 CONTINUE
00242 DO 310 I=1,NEQ
00243 Y(I)=PHI(I,1)
00244 310 YPRIME(I)=0.0D0
00245 DO 330 J=2,KP1
00246 DO 320 I=1,NEQ
00247 Y(I)=Y(I)+PHI(I,J)
00248 320 YPRIME(I)=YPRIME(I)+GAMMA(J)*PHI(I,J)
00249 330 CONTINUE
00250 PNORM = DDANRM (NEQ,Y,WT,RPAR,IPAR)
00251
00252
00253
00254
00255
00256 CONVGD= .TRUE.
00257 M=0
00258 IWM(LNRE)=IWM(LNRE)+1
00259 IRES = 0
00260 CALL RES(X,Y,YPRIME,DELTA,IRES,RPAR,IPAR)
00261 IF (IRES .LT. 0) GO TO 380
00262
00263
00264
00265
00266
00267
00268
00269 IF(JCALC .NE. -1)GO TO 340
00270 IWM(LNJE)=IWM(LNJE)+1
00271 JCALC=0
00272 CALL DDAJAC(NEQ,X,Y,YPRIME,DELTA,CJ,H,
00273 * IER,WT,E,WM,IWM,RES,IRES,UROUND,JAC,RPAR,
00274 * IPAR,NTEMP)
00275 CJOLD=CJ
00276 S = 100.D0
00277 IF (IRES .LT. 0) GO TO 380
00278 IF(IER .NE. 0)GO TO 380
00279 NSF=0
00280
00281
00282
00283 340 CONTINUE
00284 DO 345 I=1,NEQ
00285 345 E(I)=0.0D0
00286
00287
00288
00289 350 CONTINUE
00290
00291
00292 TEMP1 = 2.0D0/(1.0D0 + CJ/CJOLD)
00293 DO 355 I = 1,NEQ
00294 355 DELTA(I) = DELTA(I) * TEMP1
00295
00296
00297
00298 CALL DDASLV(NEQ,DELTA,WM,IWM)
00299
00300
00301 DO 360 I=1,NEQ
00302 Y(I)=Y(I)-DELTA(I)
00303 E(I)=E(I)-DELTA(I)
00304 360 YPRIME(I)=YPRIME(I)-CJ*DELTA(I)
00305
00306
00307 DELNRM=DDANRM(NEQ,DELTA,WT,RPAR,IPAR)
00308 IF (DELNRM .LE. 100.D0*UROUND*PNORM) GO TO 375
00309 IF (M .GT. 0) GO TO 365
00310 OLDNRM = DELNRM
00311 GO TO 367
00312 365 RATE = (DELNRM/OLDNRM)**(1.0D0/M)
00313 IF (RATE .GT. 0.90D0) GO TO 370
00314 S = RATE/(1.0D0 - RATE)
00315 367 IF (S*DELNRM .LE. 0.33D0) GO TO 375
00316
00317
00318
00319
00320
00321 M=M+1
00322 IF(M.GE.MAXIT)GO TO 370
00323
00324
00325
00326 IWM(LNRE)=IWM(LNRE)+1
00327 IRES = 0
00328 CALL RES(X,Y,YPRIME,DELTA,IRES,
00329 * RPAR,IPAR)
00330 IF (IRES .LT. 0) GO TO 380
00331 GO TO 350
00332
00333
00334
00335
00336
00337
00338 370 CONTINUE
00339 IF(JCALC.EQ.0)GO TO 380
00340 JCALC=-1
00341 GO TO 300
00342
00343
00344
00345
00346
00347
00348 375 IF(NONNEG .EQ. 0) GO TO 390
00349 DO 377 I = 1,NEQ
00350 377 DELTA(I) = MIN(Y(I),0.0D0)
00351 DELNRM = DDANRM(NEQ,DELTA,WT,RPAR,IPAR)
00352 IF(DELNRM .GT. 0.33D0) GO TO 380
00353 DO 378 I = 1,NEQ
00354 378 E(I) = E(I) - DELTA(I)
00355 GO TO 390
00356
00357
00358
00359
00360
00361 380 CONVGD= .FALSE.
00362 390 JCALC = 1
00363 IF(.NOT.CONVGD)GO TO 600
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378 ENORM = DDANRM(NEQ,E,WT,RPAR,IPAR)
00379 ERK = SIGMA(K+1)*ENORM
00380 TERK = (K+1)*ERK
00381 EST = ERK
00382 KNEW=K
00383 IF(K .EQ. 1)GO TO 430
00384 DO 405 I = 1,NEQ
00385 405 DELTA(I) = PHI(I,KP1) + E(I)
00386 ERKM1=SIGMA(K)*DDANRM(NEQ,DELTA,WT,RPAR,IPAR)
00387 TERKM1 = K*ERKM1
00388 IF(K .GT. 2)GO TO 410
00389 IF(TERKM1 .LE. 0.5D0*TERK)GO TO 420
00390 GO TO 430
00391 410 CONTINUE
00392 DO 415 I = 1,NEQ
00393 415 DELTA(I) = PHI(I,K) + DELTA(I)
00394 ERKM2=SIGMA(K-1)*DDANRM(NEQ,DELTA,WT,RPAR,IPAR)
00395 TERKM2 = (K-1)*ERKM2
00396 IF(MAX(TERKM1,TERKM2).GT.TERK)GO TO 430
00397
00398 420 CONTINUE
00399 KNEW=K-1
00400 EST = ERKM1
00401
00402
00403
00404
00405 430 CONTINUE
00406 ERR = CK * ENORM
00407 IF(ERR .GT. 1.0D0)GO TO 600
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420 IDID=1
00421 IWM(LNST)=IWM(LNST)+1
00422 KDIFF=K-KOLD
00423 KOLD=K
00424 HOLD=H
00425
00426
00427
00428
00429
00430
00431
00432 IF(KNEW.EQ.KM1.OR.K.EQ.IWM(LMXORD))IPHASE=1
00433 IF(IPHASE .EQ. 0)GO TO 545
00434 IF(KNEW.EQ.KM1)GO TO 540
00435 IF(K.EQ.IWM(LMXORD)) GO TO 550
00436 IF(KP1.GE.NS.OR.KDIFF.EQ.1)GO TO 550
00437 DO 510 I=1,NEQ
00438 510 DELTA(I)=E(I)-PHI(I,KP2)
00439 ERKP1 = (1.0D0/(K+2))*DDANRM(NEQ,DELTA,WT,RPAR,IPAR)
00440 TERKP1 = (K+2)*ERKP1
00441 IF(K.GT.1)GO TO 520
00442 IF(TERKP1.GE.0.5D0*TERK)GO TO 550
00443 GO TO 530
00444 520 IF(TERKM1.LE.MIN(TERK,TERKP1))GO TO 540
00445 IF(TERKP1.GE.TERK.OR.K.EQ.IWM(LMXORD))GO TO 550
00446
00447
00448 530 K=KP1
00449 EST = ERKP1
00450 GO TO 550
00451
00452
00453 540 K=KM1
00454 EST = ERKM1
00455 GO TO 550
00456
00457
00458
00459 545 K = KP1
00460 HNEW = H*2.0D0
00461 H = HNEW
00462 GO TO 575
00463
00464
00465
00466
00467 550 HNEW=H
00468 TEMP2=K+1
00469 R=(2.0D0*EST+0.0001D0)**(-1.0D0/TEMP2)
00470 IF(R .LT. 2.0D0) GO TO 555
00471 HNEW = 2.0D0*H
00472 GO TO 560
00473 555 IF(R .GT. 1.0D0) GO TO 560
00474 R = MAX(0.5D0,MIN(0.9D0,R))
00475 HNEW = H*R
00476 560 H=HNEW
00477
00478
00479
00480 575 CONTINUE
00481 IF(KOLD.EQ.IWM(LMXORD))GO TO 585
00482 DO 580 I=1,NEQ
00483 580 PHI(I,KP2)=E(I)
00484 585 CONTINUE
00485 DO 590 I=1,NEQ
00486 590 PHI(I,KP1)=PHI(I,KP1)+E(I)
00487 DO 595 J1=2,KP1
00488 J=KP1-J1+1
00489 DO 595 I=1,NEQ
00490 595 PHI(I,J)=PHI(I,J)+PHI(I,J+1)
00491 RETURN
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505 600 IPHASE = 1
00506
00507
00508 X=XOLD
00509 IF(KP1.LT.NSP1)GO TO 630
00510 DO 620 J=NSP1,KP1
00511 TEMP1=1.0D0/BETA(J)
00512 DO 610 I=1,NEQ
00513 610 PHI(I,J)=TEMP1*PHI(I,J)
00514 620 CONTINUE
00515 630 CONTINUE
00516 DO 640 I=2,KP1
00517 640 PSI(I-1)=PSI(I)-H
00518
00519
00520
00521
00522 IF(CONVGD)GO TO 660
00523 IWM(LCTF)=IWM(LCTF)+1
00524
00525
00526
00527
00528
00529 IF(IER.EQ.0)GO TO 650
00530
00531
00532
00533
00534
00535 NSF=NSF+1
00536 R = 0.25D0
00537 H=H*R
00538 IF (NSF .LT. 3 .AND. ABS(H) .GE. HMIN) GO TO 690
00539 IDID=-8
00540 GO TO 675
00541
00542
00543
00544
00545
00546
00547 650 CONTINUE
00548 IF (IRES .GT. -2) GO TO 655
00549 IDID = -11
00550 GO TO 675
00551 655 NCF = NCF + 1
00552 R = 0.25D0
00553 H = H*R
00554 IF (NCF .LT. 10 .AND. ABS(H) .GE. HMIN) GO TO 690
00555 IDID = -7
00556 IF (IRES .LT. 0) IDID = -10
00557 IF (NEF .GE. 3) IDID = -9
00558 GO TO 675
00559
00560
00561
00562
00563
00564 660 NEF=NEF+1
00565 IWM(LETF)=IWM(LETF)+1
00566 IF (NEF .GT. 1) GO TO 665
00567
00568
00569
00570
00571 K = KNEW
00572 TEMP2 = K + 1
00573 R = 0.90D0*(2.0D0*EST+0.0001D0)**(-1.0D0/TEMP2)
00574 R = MAX(0.25D0,MIN(0.9D0,R))
00575 H = H*R
00576 IF (ABS(H) .GE. HMIN) GO TO 690
00577 IDID = -6
00578 GO TO 675
00579
00580
00581
00582
00583 665 IF (NEF .GT. 2) GO TO 670
00584 K = KNEW
00585 H = 0.25D0*H
00586 IF (ABS(H) .GE. HMIN) GO TO 690
00587 IDID = -6
00588 GO TO 675
00589
00590
00591
00592 670 K = 1
00593 H = 0.25D0*H
00594 IF (ABS(H) .GE. HMIN) GO TO 690
00595 IDID = -6
00596 GO TO 675
00597
00598
00599
00600
00601
00602
00603 675 CONTINUE
00604 CALL DDATRP(X,X,Y,YPRIME,NEQ,K,PHI,PSI)
00605 RETURN
00606
00607
00608
00609 690 GO TO 200
00610
00611
00612 END