~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to scipy/integrate/odepack/lsodi.f

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
      subroutine lsodi (res, adda, jac, neq, y, ydoti, t, tout, itol,
 
2
     1  rtol, atol, itask, istate, iopt, rwork, lrw, iwork, liw, mf )
 
3
      external res, adda, jac
 
4
      integer neq, itol, itask, istate, iopt, lrw, iwork, liw, mf
 
5
      double precision y, ydoti, t, tout, rtol, atol, rwork
 
6
      dimension neq(1), y(1), ydoti(1), rtol(1), atol(1), rwork(lrw),
 
7
     1          iwork(liw)
 
8
c-----------------------------------------------------------------------
 
9
c this is the march 30, 1987 version of lsodi..
 
10
c  livermore solver for ordinary differential equations (implicit form).
 
11
c this version is in double precision.
 
12
c
 
13
c lsodi solves the initial value problem for linearly implicit
 
14
c systems of first order ode-s,
 
15
c     a(t,y) * dy/dt = g(t,y) ,  where a(t,y) is a square matrix,
 
16
c or, in component form,
 
17
c     ( a   * ( dy / dt ))  + ... +  ( a     * ( dy   / dt ))  =
 
18
c        i,1      1                     i,neq      neq
 
19
c
 
20
c      =   g ( t, y , y ,..., y    )   ( i = 1,...,neq )
 
21
c           i      1   2       neq
 
22
c
 
23
c if a is singular, this is a differential-algebraic system.
 
24
c
 
25
c lsodi is a variant version of the lsode package.
 
26
c-----------------------------------------------------------------------
 
27
c reference..
 
28
c     alan c. hindmarsh,  odepack, a systematized collection of ode
 
29
c     solvers, in scientific computing, r. s. stepleman et al. (eds.),
 
30
c     north-holland, amsterdam, 1983, pp. 55-64.
 
31
c-----------------------------------------------------------------------
 
32
c authors...  jeffrey f. painter  and
 
33
c             alan c. hindmarsh
 
34
c             computing and mathematics research division, l-316
 
35
c             lawrence livermore national laboratory
 
36
c             livermore, ca 94550.
 
37
c
 
38
c-----------------------------------------------------------------------
 
39
c summary of usage.
 
40
c
 
41
c communication between the user and the lsodi package, for normal
 
42
c situations, is summarized here.  this summary describes only a subset
 
43
c of the full set of options available.  see the full description for
 
44
c details, including optional communication, nonstandard options,
 
45
c and instructions for special situations.  see also the example
 
46
c problem (with program and output) following this summary.
 
47
c
 
48
c a. first, provide a subroutine of the form..
 
49
c               subroutine res (neq, t, y, s, r, ires)
 
50
c               dimension y(neq), s(neq), r(neq)
 
51
c which computes the residual function
 
52
c     r = g(t,y)  -  a(t,y) * s ,
 
53
c as a function of t and the vectors y and s.  (s is an internally
 
54
c generated approximation to dy/dt.)  the arrays y and s are inputs
 
55
c to the res routine and should not be altered.  the residual
 
56
c vector is to be stored in the array r.  the argument ires should be
 
57
c ignored for casual use of lsodi.  (for uses of ires, see the
 
58
c paragraph on res in the full description below.)
 
59
c
 
60
c b. next, decide whether full or banded form is more economical
 
61
c for the storage of matrices.  lsodi must deal internally with the
 
62
c matrices a and dr/dy, where r is the residual function defined above.
 
63
c lsodi generates a linear combination of these two matrices, and
 
64
c this is treated in either full or banded form.
 
65
c     the matrix structure is communicated by a method flag mf,
 
66
c which is 21 or 22 for the full case, and 24 or 25 in the band case.
 
67
c     in the banded case, lsodi requires two half-bandwidth
 
68
c parameters ml and mu.  these are, respectively, the widths of the
 
69
c lower and upper parts of the band, excluding the main diagonal.
 
70
c thus the band consists of the locations (i,j) with
 
71
c i-ml .le. j .le. i+mu, and the full bandwidth is ml+mu+1.
 
72
c note that the band must accommodate the nonzero elements of
 
73
c a(t,y), dg/dy, and d(a*s)/dy (s fixed).  alternatively, one
 
74
c can define a band that encloses only the elements that are relatively
 
75
c large in magnitude, and gain some economy in storage and possibly
 
76
c also efficiency, although the appropriate threshhold for
 
77
c retaining matrix elements is highly problem-dependent.
 
78
c
 
79
c c. you must also provide a subroutine of the form..
 
80
c               subroutine adda (neq, t, y, ml, mu, p, nrowp)
 
81
c               dimension y(neq), p(nrowp,neq)
 
82
c which adds the matrix a = a(t,y) to the contents of the array p.
 
83
c t and the y array are input and should not be altered.
 
84
c     in the full matrix case, this routine should add elements of
 
85
c to p in the usual order.  i.e., add a(i,j) to p(i,j).  (ignore the
 
86
c ml and mu arguments in this case.)
 
87
c     in the band matrix case, this routine should add element a(i,j)
 
88
c to p(i-j+mu+1,j).  i.e., add the diagonal lines of a to the rows of
 
89
c p from the top down (the top line of a added to the first row of p).
 
90
c
 
91
c d. for the sake of efficiency, you are encouraged to supply the
 
92
c jacobian matrix dr/dy in closed form, where r = g(t,y) - a(t,y)*s
 
93
c (s = a fixed vector) as above.  if dr/dy is being supplied,
 
94
c use mf = 21 or 24, and provide a subroutine of the form..
 
95
c               subroutine jac (neq, t, y, s, ml, mu, p, nrowp)
 
96
c               dimension y(neq), s(neq), p(nrowp,neq)
 
97
c which computes dr/dy as a function of t, y, and s.  here t, y, and
 
98
c s are inputs, and the routine is to load dr/dy into p as follows..
 
99
c     in the full matrix case (mf = 21), load p(i,j) with dr(i)/dy(j),
 
100
c the partial derivative of r(i) with respect to y(j).  (ignore the
 
101
c ml and mu arguments in this case.)
 
102
c     in the band matrix case (mf = 24), load p(i-j+mu+1,j) with
 
103
c dr(i)/dy(j), i.e. load the diagonal lines of dr/dy into the rows of
 
104
c p from the top down.
 
105
c     in either case, only nonzero elements need be loaded, and the
 
106
c indexing of p is the same as in the adda routine.
 
107
c     note that if a is independent of y (or this dependence
 
108
c is weak enough to be ignored) then jac is to compute dg/dy.
 
109
c     if it is not feasible to provide a jac routine, use
 
110
c mf = 22 or 25, and lsodi will compute an approximate jacobian
 
111
c internally by difference quotients.
 
112
c
 
113
c e. next decide whether or not to provide the initial value of the
 
114
c derivative vector dy/dt.  if the initial value of a(t,y) is
 
115
c nonsingular (and not too ill-conditioned), you may let lsodi compute
 
116
c this vector (istate = 0).  (lsodi will solve the system a*s = g for
 
117
c s, with initial values of a and g.)  if a(t,y) is initially
 
118
c singular, then the system is a differential-algebraic system, and
 
119
c you must make use of the particular form of the system to compute the
 
120
c initial values of y and dy/dt.  in that case, use istate = 1 and
 
121
c load the initial value of dy/dt into the array ydoti.
 
122
c the input array ydoti and the initial y array must be consistent with
 
123
c the equations a*dy/dt = g.  this implies that the initial residual
 
124
c r = g(t,y) - a(t,y)*ydoti   must be approximately zero.
 
125
c
 
126
c f. write a main program which calls subroutine lsodi once for
 
127
c each point at which answers are desired.  this should also provide
 
128
c for possible use of logical unit 6 for output of error messages
 
129
c by lsodi.  on the first call to lsodi, supply arguments as follows..
 
130
c res    = name of user subroutine for residual function r.
 
131
c adda   = name of user subroutine for computing and adding a(t,y).
 
132
c jac    = name of user subroutine for jacobian matrix dr/dy
 
133
c          (mf = 21 or 24).  if not used, pass a dummy name.
 
134
c note.. the names for the res and adda routines and (if used) the
 
135
c        jac routine must be declared external in the calling program.
 
136
c neq    = number of scalar equations in the system.
 
137
c y      = array of initial values, of length neq.
 
138
c ydoti  = array of length neq (containing initial dy/dt if istate = 1).
 
139
c t      = the initial value of the independent variable.
 
140
c tout   = first point where output is desired (.ne. t).
 
141
c itol   = 1 or 2 according as atol (below) is a scalar or array.
 
142
c rtol   = relative tolerance parameter (scalar).
 
143
c atol   = absolute tolerance parameter (scalar or array).
 
144
c          the estimated local error in y(i) will be controlled so as
 
145
c          to be roughly less (in magnitude) than
 
146
c             ewt(i) = rtol*abs(y(i)) + atol     if itol = 1, or
 
147
c             ewt(i) = rtol*abs(y(i)) + atol(i)  if itol = 2.
 
148
c          thus the local error test passes if, in each component,
 
149
c          either the absolute error is less than atol (or atol(i)),
 
150
c          or the relative error is less than rtol.
 
151
c          use rtol = 0.0 for pure absolute error control, and
 
152
c          use atol = 0.0 (or atol(i) = 0.0) for pure relative error
 
153
c          control.  caution.. actual (global) errors may exceed these
 
154
c          local tolerances, so choose them conservatively.
 
155
c itask  = 1 for normal computation of output values of y at t = tout.
 
156
c istate = integer flag (input and output).  set istate = 1 if the
 
157
c          initial dy/dt is supplied, and 0 otherwise.
 
158
c iopt   = 0 to indicate no optional inputs used.
 
159
c rwork  = real work array of length at least..
 
160
c             22 +  9*neq + neq**2           for mf = 21 or 22,
 
161
c             22 + 10*neq + (2*ml + mu)*neq  for mf = 24 or 25.
 
162
c lrw    = declared length of rwork (in user-s dimension).
 
163
c iwork  = integer work array of length at least 20 + neq.
 
164
c          if mf = 24 or 25, input in iwork(1),iwork(2) the lower
 
165
c          and upper half-bandwidths ml,mu.
 
166
c liw    = declared length of iwork (in user-s dimension).
 
167
c mf     = method flag.  standard values are..
 
168
c          21 for a user-supplied full jacobian.
 
169
c          22 for an internally generated full jacobian.
 
170
c          24 for a user-supplied banded jacobian.
 
171
c          25 for an internally generated banded jacobian.
 
172
c          for other choices of mf, see the paragraph on mf in
 
173
c          the full description below.
 
174
c note that the main program must declare arrays y, ydoti, rwork, iwork,
 
175
c and possibly atol.
 
176
c
 
177
c g. the output from the first call (or any call) is..
 
178
c      y = array of computed values of y(t) vector.
 
179
c      t = corresponding value of independent variable (normally tout).
 
180
c istate = 2  if lsodi was successful, negative otherwise.
 
181
c          -1 means excess work done on this call (check all inputs).
 
182
c          -2 means excess accuracy requested (tolerances too small).
 
183
c          -3 means illegal input detected (see printed message).
 
184
c          -4 means repeated error test failures (check all inputs).
 
185
c          -5 means repeated convergence failures (perhaps bad jacobian
 
186
c             supplied or wrong choice of tolerances).
 
187
c          -6 means error weight became zero during problem. (solution
 
188
c             component i vanished, and atol or atol(i) = 0.)
 
189
c          -7 cannot occur in casual use.
 
190
c          -8 means lsodi was unable to compute the initial dy/dt.
 
191
c             in casual use, this means a(t,y) is initially singular.
 
192
c             supply ydoti and use istate = 1 on the first call.
 
193
c
 
194
c  if lsodi returns istate = -1, -4, or -5, then the output of
 
195
c  lsodi also includes ydoti = array containing residual vector
 
196
c  r = g - a * dy/dt  evaluated at the current t, y, and dy/dt.
 
197
c
 
198
c h. to continue the integration after a successful return, simply
 
199
c reset tout and call lsodi again.  no other parameters need be reset.
 
200
c
 
201
c
 
202
c-----------------------------------------------------------------------
 
203
c example problem.
 
204
c
 
205
c the following is a simple example problem, with the coding
 
206
c needed for its solution by lsodi.  the problem is from chemical
 
207
c kinetics, and consists of the following three equations..
 
208
c     dy1/dt = -.04*y1 + 1.e4*y2*y3
 
209
c     dy2/dt = .04*y1 - 1.e4*y2*y3 - 3.e7*y2**2
 
210
c       0.   = y1 + y2 + y3 - 1.
 
211
c on the interval from t = 0.0 to t = 4.e10, with initial conditions
 
212
c y1 = 1.0, y2 = y3 = 0.
 
213
c
 
214
c the following coding solves this problem with lsodi, using mf = 21
 
215
c and printing results at t = .4, 4., ..., 4.e10.  it uses
 
216
c itol = 2 and atol much smaller for y2 than y1 or y3 because
 
217
c y2 has much smaller values.  dy/dt is supplied in ydoti. we had
 
218
c obtained the initial value of dy3/dt by differentiating the
 
219
c third equation and evaluating the first two at t=0.
 
220
c at the end of the run, statistical quantities of interest are
 
221
c printed (see optional outputs in the full description below).
 
222
c
 
223
c     external resid, aplusp, dgbydy
 
224
c     double precision atol, rtol, rwork, t, tout, y, ydoti
 
225
c     dimension y(3), ydoti(3), atol(3), rwork(58), iwork(23)
 
226
c     neq = 3
 
227
c     y(1) = 1.d0
 
228
c     y(2) = 0.d0
 
229
c     y(3) = 0.d0
 
230
c     ydoti(1) = -.04d0
 
231
c     ydoti(2) =  .04d0
 
232
c     ydoti(3) =  0.d0
 
233
c     t = 0.d0
 
234
c     tout = .4d0
 
235
c     itol = 2
 
236
c     rtol = 1.d-4
 
237
c     atol(1) = 1.d-6
 
238
c     atol(2) = 1.d-10
 
239
c     atol(3) = 1.d-6
 
240
c     itask = 1
 
241
c     istate = 1
 
242
c     iopt = 0
 
243
c     lrw = 58
 
244
c     liw = 23
 
245
c     mf = 21
 
246
c     do 40  iout = 1,12
 
247
c        call lsodi(resid, aplusp, dgbydy, neq, y, ydoti, t, tout, itol,
 
248
c    1      rtol, atol, itask, istate, iopt, rwork, lrw, iwork, liw, mf)
 
249
c        write (6,20)  t, y(1), y(2), y(3)
 
250
c  20    format(' at t =',e12.4,'   y =',3e14.6)
 
251
c        if (istate .lt. 0 )  go to 80
 
252
c  40    tout = tout*10.d0
 
253
c     write (6,60)  iwork(11), iwork(12), iwork(13)
 
254
c  60 format(/' no. steps =',i4,'  no. r-s =',i4,
 
255
c    1         '  no. j-s =',i4)
 
256
c     stop
 
257
c  80 write (6,90)  istate
 
258
c  90 format(///' error halt.. istate =',i3)
 
259
c     stop
 
260
c     end
 
261
c
 
262
c     subroutine resid(neq, t, y, s, r, ires)
 
263
c     double precision r, s, t, y
 
264
c     dimension y(3), s(3), r(3)
 
265
c     r(1) = -.04d0*y(1) + 1.d4*y(2)*y(3) - s(1)
 
266
c     r(2) = .04d0*y(1) - 1.d4*y(2)*y(3) - 3.d7*y(2)*y(2) - s(2)
 
267
c     r(3) = y(1) + y(2) + y(3) - 1.d0
 
268
c     return
 
269
c     end
 
270
c
 
271
c     subroutine aplusp(neq, t, y, ml, mu, p, nrowp)
 
272
c     double precision p, t, y
 
273
c     dimension y(3), p(nrowp,3)
 
274
c     p(1,1) = p(1,1) + 1.d0
 
275
c     p(2,2) = p(2,2) + 1.d0
 
276
c     return
 
277
c     end
 
278
c
 
279
c     subroutine dgbydy(neq, t, y, s, ml, mu, p, nrowp)
 
280
c     double precision s, t, p, y
 
281
c     dimension y(3), s(3), p(nrowp,3)
 
282
c     p(1,1) = -.04d0
 
283
c     p(1,2) = 1.d4*y(3)
 
284
c     p(1,3) = 1.d4*y(2)
 
285
c     p(2,1) = .04d0
 
286
c     p(2,2) = -1.d4*y(3) - 6.d7*y(2)
 
287
c     p(2,3) = -1.d4*y(2)
 
288
c     p(3,1) = 1.d0
 
289
c     p(3,2) = 1.d0
 
290
c     p(3,3) = 1.d0
 
291
c     return
 
292
c     end
 
293
c
 
294
c the output of this program (on a cdc-7600 in single precision)
 
295
c is as follows..
 
296
c
 
297
c   at t =  4.0000e-01   y =  9.851726e-01  3.386406e-05  1.479357e-02
 
298
c   at t =  4.0000e+00   y =  9.055142e-01  2.240418e-05  9.446344e-02
 
299
c   at t =  4.0000e+01   y =  7.158050e-01  9.184616e-06  2.841858e-01
 
300
c   at t =  4.0000e+02   y =  4.504846e-01  3.222434e-06  5.495122e-01
 
301
c   at t =  4.0000e+03   y =  1.831701e-01  8.940379e-07  8.168290e-01
 
302
c   at t =  4.0000e+04   y =  3.897016e-02  1.621193e-07  9.610297e-01
 
303
c   at t =  4.0000e+05   y =  4.935213e-03  1.983756e-08  9.950648e-01
 
304
c   at t =  4.0000e+06   y =  5.159269e-04  2.064759e-09  9.994841e-01
 
305
c   at t =  4.0000e+07   y =  5.306413e-05  2.122677e-10  9.999469e-01
 
306
c   at t =  4.0000e+08   y =  5.494532e-06  2.197826e-11  9.999945e-01
 
307
c   at t =  4.0000e+09   y =  5.129457e-07  2.051784e-12  9.999995e-01
 
308
c   at t =  4.0000e+10   y = -7.170472e-08 -2.868188e-13  1.000000e+00
 
309
c
 
310
c   no. steps = 330  no. r-s = 404  no. j-s =  69
 
311
c-----------------------------------------------------------------------
 
312
c full description of user interface to lsodi.
 
313
c
 
314
c the user interface to lsodi consists of the following parts.
 
315
c
 
316
c i.   the call sequence to subroutine lsodi, which is a driver
 
317
c      routine for the solver.  this includes descriptions of both
 
318
c      the call sequence arguments and of user-supplied routines.
 
319
c      following these descriptions is a description of
 
320
c      optional inputs available through the call sequence, and then
 
321
c      a description of optional outputs (in the work arrays).
 
322
c
 
323
c ii.  descriptions of other routines in the lsodi package that may be
 
324
c      (optionally) called by the user.  these provide the ability to
 
325
c      alter error message handling, save and restore the internal
 
326
c      common, and obtain specified derivatives of the solution y(t).
 
327
c
 
328
c iii. descriptions of common blocks to be declared in overlay
 
329
c      or similar environments, or to be saved when doing an interrupt
 
330
c      of the problem and continued solution later.
 
331
c
 
332
c iv.  description of two routines in the lsodi package, either of
 
333
c      which the user may replace with his own version, if desired.
 
334
c      these relate to the measurement of errors.
 
335
c
 
336
c-----------------------------------------------------------------------
 
337
c part i.  call sequence.
 
338
c
 
339
c the call sequence parameters used for input only are
 
340
c     res, adda, jac, neq, tout, itol, rtol, atol, itask,
 
341
c     iopt, lrw, liw, mf,
 
342
c and those used for both input and output are
 
343
c     y, t, istate, ydoti.
 
344
c the work arrays rwork and iwork are also used for conditional and
 
345
c optional inputs and optional outputs.  (the term output here refers
 
346
c to the return from subroutine lsodi to the user-s calling program.)
 
347
c
 
348
c the legality of input parameters will be thoroughly checked on the
 
349
c initial call for the problem, but not checked thereafter unless a
 
350
c change in input parameters is flagged by istate = 3 on input.
 
351
c
 
352
c the descriptions of the call arguments are as follows.
 
353
c
 
354
c res    = the name of the user-supplied subroutine which supplies
 
355
c          the residual vector for the ode system, defined by
 
356
c            r = g(t,y) - a(t,y) * s
 
357
c          as a function of the scalar t and the vectors
 
358
c          s and y ( s approximates dy/dt ). this
 
359
c          subroutine is to have the form
 
360
c              subroutine res ( neq, t, y, s, r, ires )
 
361
c              dimension y(1), s(1), r(1)
 
362
c          where neq, t, y, s, and ires are input, and r and
 
363
c          ires are output. y, s, and r are arrays of length neq.
 
364
c          in dimension statements such as that above, 1 is a
 
365
c          dummy dimension. it can be replaced by any value.
 
366
c             on input, ires indicates how lsodi will use the
 
367
c          returned array r, as follows..
 
368
c             ires = 1  means that lsodi needs the full residual,
 
369
c                       r = g - a*s, exactly.
 
370
c             ires = -1 means that lsodi is using r only to compute
 
371
c                       the jacobian dr/dy by difference quotients.
 
372
c          the res routine can ignore ires, or it can omit some terms
 
373
c          if ires = -1.  if a does not depend on y, then res can
 
374
c          just return r = g when ires = -1.  if g - a*s contains other
 
375
c          additive terms that are independent of y, these can also be
 
376
c          dropped, if done consistently, when ires = -1.
 
377
c             the subroutine should set the flag ires if it
 
378
c          encounters a halt condition or illegal input.
 
379
c          otherwise, it should not reset ires.  on output,
 
380
c             ires = 1 or -1 represents a normal return, and
 
381
c          lsodi continues integrating the ode.  leave ires
 
382
c          unchanged from its input value.
 
383
c             ires = 2 tells lsodi to immediately return control
 
384
c          to the calling program, with istate = 3.  this lets
 
385
c          the calling program change parameters of the prob-
 
386
c          lem if necessary.
 
387
c             ires = 3 represents an error condition (for example, an
 
388
c          illegal value of y). lsodi tries to integrate the ode without
 
389
c          getting ires = 3 from res.  if it cannot, lsodi returns
 
390
c          with istate = -7 or -1.
 
391
c             on an lsodi return with istate = 3, -1, or -7, the values
 
392
c          of t and y returned correspond to the last point reached
 
393
c          successfully without getting the flag ires = 2 or 3.
 
394
c             the flag values ires = 2 and 3 should not be used to
 
395
c          handle switches or root-stop conditions.  this is better
 
396
c          done by calling lsodi in a one-step mode and checking the
 
397
c          stopping function for a sign change at each step.
 
398
c             if quantities computed in the res routine are needed
 
399
c          externally to lsodi, an extra call to res should be made
 
400
c          for this purpose, for consistent and accurate results.
 
401
c          to get the current dy/dt for the s argument, use intdy.
 
402
c             res must be declared external in the calling
 
403
c          program.  see note below for more about res.
 
404
c
 
405
c adda   = the name of the user-supplied subroutine which adds
 
406
c          the matrix a = a(t,y) to another matrix stored in the same
 
407
c          form as a. the storage form is determined by miter (see
 
408
c          mf).  this subroutine is to have the form
 
409
c               subroutine adda ( neq, t, y, ml, mu, p, nrowp )
 
410
c               dimension y(1), p(nrowp,1)
 
411
c          where neq, t, y, ml, mu, and nrowp are input and p is
 
412
c          output. y is an array of length neq, and the matrix p is
 
413
c          stored in an nrowp by neq array.
 
414
c             in the full matrix case ( miter =  1 or 2 ) adda should
 
415
c          add  a    to p(i,j). ml and mu are ignored.
 
416
c                i,j
 
417
c             in the band matrix case ( miter = 4 or 5 ) adda should
 
418
c          add  a    to  p(i-j+mu+1,j).
 
419
c                i,j
 
420
c          see jac for details on this band storage form.
 
421
c             adda must be declared external in the calling program.
 
422
c          see note below for more information about adda.
 
423
c
 
424
c jac    = the name of the user-supplied subroutine which supplies
 
425
c          the jacobian matrix, dr/dy, where r = g-a*s. the form of the
 
426
c          jacobian matrix is determined by miter. jac is required
 
427
c          if miter = 1 or 4 -- otherwise a dummy name can be
 
428
c          passed. this subroutine is to have the form
 
429
c               subroutine jac ( neq, t, y, s, ml, mu, p, nrowp )
 
430
c               dimension y(1), s(1), p(nrowp,1)
 
431
c          where neq, t, y, s, ml, mu, and nrowp are input and p
 
432
c          is output. y and s are arrays of length neq, and the
 
433
c          matrix p is stored in an nrowp by neq array.
 
434
c          p is to be loaded with partial derivatives ( elements
 
435
c          of the jacobian matrix ) on output.
 
436
c             in the full matrix case ( miter = 1 ), ml and mu
 
437
c          are ignored and the jacobian is to be loaded into p
 
438
c          by columns- i.e., dr(i)/dy(j) is loaded into p(i,j).
 
439
c             in the band matrix case ( miter = 4 ), the ele-
 
440
c          ments within the band are to be loaded into p by
 
441
c          by columns, with diagonal lines of dr/dy loaded into
 
442
c          the rows of p.  thus dr(i)/dy(j) is to be loaded
 
443
c          into p(i-j+mu+1,j). the locations in p in the two
 
444
c          triangular areas which correspond to nonexistent matrix
 
445
c          elements can be ignored or loaded arbitrarily, as they
 
446
c          they are overwritten by lsodi. ml and mu are the half-
 
447
c          bandwidth parameters ( see iwork ).
 
448
c               in either case, p is preset to zero by the solver,
 
449
c          so that only the nonzero elements need be loaded by jac.
 
450
c          each call to jac is preceded by a call to res with the same
 
451
c          arguments neq, t, y, and s.  thus to gain some efficiency,
 
452
c          intermediate quantities shared by both calculations may be
 
453
c          saved in a user common block by res and not recomputed by jac
 
454
c          if desired.  also, jac may alter the y array, if desired.
 
455
c               jac need not provide dr/dy exactly.  a crude
 
456
c          approximation (possibly with a smaller bandwidth) will do.
 
457
c               jac must be declared external in the calling program.
 
458
c               see note below for more about jac.
 
459
c
 
460
c       note on res, adda, and jac--  these
 
461
c          subroutines may access user-defined quantities in
 
462
c          neq(2),... and/or in y(neq(1)+1),... if neq is an array
 
463
c          (dimensioned in the subroutines) and/or y has length
 
464
c          exceeding neq(1).  however, these routines should not alter
 
465
c          neq(1), y(1),...,y(neq) or any other input variables.
 
466
c          see the descriptions of neq and y below.
 
467
c
 
468
c neq    = the size of the system (number of first order ordinary
 
469
c          differential equations or scalar algebraic equations).
 
470
c          used only for input.
 
471
c          neq may be decreased, but not increased, during the problem.
 
472
c          if neq is decreased (with istate = 3 on input), the
 
473
c          remaining components of y should be left undisturbed, if
 
474
c          these are to be accessed in res, adda, or jac.
 
475
c
 
476
c          normally, neq is a scalar, and it is generally referred to
 
477
c          as a scalar in this user interface description.  however,
 
478
c          neq may be an array, with neq(1) set to the system size.
 
479
c          (the lsodi package accesses only neq(1).)  in either case,
 
480
c          this parameter is passed as the neq argument in all calls
 
481
c          to res, adda, and jac.  hence, if it is an array,
 
482
c          locations neq(2),... may be used to store other integer data
 
483
c          and pass it to  res, adda, or jac.  each such subroutine
 
484
c          must include neq in a dimension statement in that case.
 
485
c
 
486
c y      = a real array for the vector of dependent variables, of
 
487
c          length neq or more.  used for both input and output on the
 
488
c          first call (istate = 0 or 1), and only for output on other
 
489
c          calls.  on the first call, y must contain the vector of
 
490
c          initial values.  on output, y contains the computed solution
 
491
c          vector, evaluated at t.  if desired, the y array may be used
 
492
c          for other purposes between calls to the solver.
 
493
c
 
494
c          this array is passed as the y argument in all calls to res,
 
495
c          adda, and jac.  hence its length may exceed neq,
 
496
c          and locations y(neq+1),... may be used to store other real
 
497
c          data and pass it to res, adda, or jac.  (the lsodi
 
498
c          package accesses only y(1),...,y(neq). )
 
499
c
 
500
c ydoti  = a real array for the initial value of the vector
 
501
c          dy/dt and for work space, of dimension at least neq.
 
502
c
 
503
c          on input...
 
504
c            if istate = 0 then lsodi will compute the initial value
 
505
c          of dy/dt, if a is nonsingular.  thus ydoti will
 
506
c          serve only as work space and may have any value.
 
507
c            if istate = 1 then ydoti must contain the initial value
 
508
c          of dy/dt.
 
509
c            if istate = 2 or 3 (continuation calls) then ydoti
 
510
c          may have any value.
 
511
c            n.b.- if the initial value of a is singular, then
 
512
c          lsodi cannot compute the initial value of dy/dt, so
 
513
c          it must be provided in ydoti, with istate=1.
 
514
c
 
515
c          on output, when lsodi terminates abnormally with istate =
 
516
c          -1, -4, or -5, ydoti will contain the residual
 
517
c          r = g(t,y) - a(t,y)*(dy/dt).  if r is large, t is near
 
518
c          its initial value, and ydoti is supplied with istate=1,
 
519
c          there may have been an incorrect input value of
 
520
c          ydoti = dy/dt or the problem ( as given to lsodi )
 
521
c          may not have a solution.
 
522
c
 
523
c          if desired, the ydoti array may be used for other
 
524
c          purposes between calls to the solver.
 
525
c
 
526
c t      = the independent variable.  on input, t is used only on the
 
527
c          first call, as the initial point of the integration.
 
528
c          on output, after each call, t is the value at which a
 
529
c          computed solution y is evaluated (usually the same as tout).
 
530
c          on an error return, t is the farthest point reached.
 
531
c
 
532
c tout   = the next value of t at which a computed solution is desired.
 
533
c          used only for input.
 
534
c
 
535
c          when starting the problem (istate = 0 or 1), tout may be
 
536
c          equal to t for one call, then should .ne. t for the next
 
537
c          call.  for the initial t, an input value of tout .ne. t is
 
538
c          used in order to determine the direction of the integration
 
539
c          (i.e. the algebraic sign of the step sizes) and the rough
 
540
c          scale of the problem.  integration in either direction
 
541
c          (forward or backward in t) is permitted.
 
542
c
 
543
c          if itask = 2 or 5 (one-step modes), tout is ignored after
 
544
c          the first call (i.e. the first call with tout .ne. t).
 
545
c          otherwise, tout is required on every call.
 
546
c
 
547
c          if itask = 1, 3, or 4, the values of tout need not be
 
548
c          monotone, but a value of tout which backs up is limited
 
549
c          to the current internal t interval, whose endpoints are
 
550
c          tcur - hu and tcur (see optional outputs, below, for
 
551
c          tcur and hu).
 
552
c
 
553
c itol   = an indicator for the type of error control.  see
 
554
c          description below under atol.  used only for input.
 
555
c
 
556
c rtol   = a relative error tolerance parameter, either a scalar or
 
557
c          an array of length neq.  see description below under atol.
 
558
c          input only.
 
559
c
 
560
c atol   = an absolute error tolerance parameter, either a scalar or
 
561
c          an array of length neq.  input only.
 
562
c
 
563
c             the input parameters itol, rtol, and atol determine
 
564
c          the error control performed by the solver.  the solver will
 
565
c          control the vector e = (e(i)) of estimated local errors
 
566
c          in y, according to an inequality of the form
 
567
c                      rms-norm of ( e(i)/ewt(i) )   .le.   1,
 
568
c          where       ewt(i) = rtol(i)*abs(y(i)) + atol(i),
 
569
c          and the rms-norm (root-mean-square norm) here is
 
570
c          rms-norm(v) = sqrt(sum v(i)**2 / neq).  here ewt = (ewt(i))
 
571
c          is a vector of weights which must always be positive, and
 
572
c          the values of rtol and atol should all be non-negative.
 
573
c          the following table gives the types (scalar/array) of
 
574
c          rtol and atol, and the corresponding form of ewt(i).
 
575
c
 
576
c             itol    rtol       atol          ewt(i)
 
577
c              1     scalar     scalar     rtol*abs(y(i)) + atol
 
578
c              2     scalar     array      rtol*abs(y(i)) + atol(i)
 
579
c              3     array      scalar     rtol(i)*abs(y(i)) + atol
 
580
c              4     array      scalar     rtol(i)*abs(y(i)) + atol(i)
 
581
c
 
582
c          when either of these parameters is a scalar, it need not
 
583
c          be dimensioned in the user-s calling program.
 
584
c
 
585
c          if none of the above choices (with itol, rtol, and atol
 
586
c          fixed throughout the problem) is suitable, more general
 
587
c          error controls can be obtained by substituting
 
588
c          user-supplied routines for the setting of ewt and/or for
 
589
c          the norm calculation.  see part iv below.
 
590
c
 
591
c          if global errors are to be estimated by making a repeated
 
592
c          run on the same problem with smaller tolerances, then all
 
593
c          components of rtol and atol (i.e. of ewt) should be scaled
 
594
c          down uniformly
 
595
c
 
596
c itask  = an index specifying the task to be performed.
 
597
c          input only.  itask has the following values and meanings.
 
598
c          1  means normal computation of output values of y(t) at
 
599
c             t = tout (by overshooting and interpolating).
 
600
c          2  means take one step only and return.
 
601
c          3  means stop at the first internal mesh point at or
 
602
c             beyond t = tout and return.
 
603
c          4  means normal computation of output values of y(t) at
 
604
c             t = tout but without overshooting t = tcrit.
 
605
c             tcrit must be input as rwork(1).  tcrit may be equal to
 
606
c             or beyond tout, but not behind it in the direction of
 
607
c             integration.  this option is useful if the problem
 
608
c             has a singularity at or beyond t = tcrit.
 
609
c          5  means take one step, without passing tcrit, and return.
 
610
c             tcrit must be input as rwork(1).
 
611
c
 
612
c          note..  if itask = 4 or 5 and the solver reaches tcrit
 
613
c          (within roundoff), it will return t = tcrit (exactly) to
 
614
c          indicate this (unless itask = 4 and tout comes before tcrit,
 
615
c          in which case answers at t = tout are returned first).
 
616
c
 
617
c istate = an index used for input and output to specify the
 
618
c          state of the calculation.
 
619
c
 
620
c          on input, the values of istate are as follows.
 
621
c          0  means this is the first call for the problem, and
 
622
c             lsodi is to compute the initial value of dy/dt
 
623
c             (while doing other initializations).  see note below.
 
624
c          1  means this is the first call for the problem, and
 
625
c             the initial value of dy/dt has been supplied in
 
626
c             ydoti (lsodi will do other initializations). see note
 
627
c             below.
 
628
c          2  means this is not the first call, and the calculation
 
629
c             is to continue normally, with no change in any input
 
630
c             parameters except possibly tout and itask.
 
631
c             (if itol, rtol, and/or atol are changed between calls
 
632
c             with istate = 2, the new values will be used but not
 
633
c             tested for legality.)
 
634
c          3  means this is not the first call, and the
 
635
c             calculation is to continue normally, but with
 
636
c             a change in input parameters other than
 
637
c             tout and itask.  changes are allowed in
 
638
c             neq, itol, rtol, atol, iopt, lrw, liw, mf, ml, mu,
 
639
c             and any of the optional inputs except h0.
 
640
c             (see iwork description for ml and mu.)
 
641
c          note..  a preliminary call with tout = t is not counted
 
642
c          as a first call here, as no initialization or checking of
 
643
c          input is done.  (such a call is sometimes useful for the
 
644
c          purpose of outputting the initial conditions.)
 
645
c          thus the first call for which tout .ne. t requires
 
646
c          istate = 0 or 1 on input.
 
647
c
 
648
c          on output, istate has the following values and meanings.
 
649
c           0 or 1  means nothing was done, as tout was equal to t with
 
650
c              istate = 0 or 1 on input.  (however, an internal counter
 
651
c              was set to detect and prevent repeated calls of this
 
652
c              type. )
 
653
c           2  means that the integration was performed successfully.
 
654
c           3  means that the user-supplied subroutine res signalled
 
655
c              lsodi to halt the integration and return (ires=2).
 
656
c              integration as far as t was achieved with no occurrence
 
657
c              of ires=2, but this flag was set on attempting the next
 
658
c              step.
 
659
c          -1  means an excessive amount of work (more than mxstep
 
660
c              steps) was done on this call, before completing the
 
661
c              requested task, but the integration was otherwise
 
662
c              successful as far as t.  (mxstep is an optional input
 
663
c              and is normally 500.)  to continue, the user may
 
664
c              simply reset istate to a value .gt. 1 and call again
 
665
c              (the excess work step counter will be reset to 0).
 
666
c              in addition, the user may increase mxstep to avoid
 
667
c              this error return (see below on optional inputs).
 
668
c          -2  means too much accuracy was requested for the precision
 
669
c              of the machine being used.  this was detected before
 
670
c              completing the requested task, but the integration
 
671
c              was successful as far as t.  to continue, the tolerance
 
672
c              parameters must be reset, and istate must be set
 
673
c              to 3.  the optional output tolsf may be used for this
 
674
c              purpose.  (note.. if this condition is detected before
 
675
c              taking any steps, then an illegal input return
 
676
c              (istate = -3) occurs instead.)
 
677
c          -3  means illegal input was detected, before taking any
 
678
c              integration steps.  see written message for details.
 
679
c              note..  if the solver detects an infinite loop of calls
 
680
c              to the solver with illegal input, it will cause
 
681
c              the run to stop.
 
682
c          -4  means there were repeated error test failures on
 
683
c              one attempted step, before completing the requested
 
684
c              task, but the integration was successful as far as t.
 
685
c              the problem may have a singularity, or the input
 
686
c              may be inappropriate.
 
687
c          -5  means there were repeated convergence test failures on
 
688
c              one attempted step, before completing the requested
 
689
c              task, but the integration was successful as far as t.
 
690
c              this may be caused by an inaccurate jacobian matrix.
 
691
c          -6  means ewt(i) became zero for some i during the
 
692
c              integration.  pure relative error control (atol(i)=0.0)
 
693
c              was requested on a variable which has now vanished.
 
694
c              the integration was successful as far as t.
 
695
c          -7  means that the user-supplied subroutine res set
 
696
c              its error flag (ires = 3) despite repeated tries by
 
697
c              lsodi to avoid that condition.
 
698
c          -8  means that istate was 0 on input but lsodi was unable
 
699
c              to compute the initial value of dy/dt.  see the
 
700
c              printed message for details.
 
701
c
 
702
c          note..  since the normal output value of istate is 2,
 
703
c          it does not need to be reset for normal continuation.
 
704
c          similarly, istate need not be reset if res told lsodi
 
705
c          to return because the calling program must change
 
706
c          the parameters of the problem.
 
707
c          also, since a negative input value of istate will be
 
708
c          regarded as illegal, a negative output value requires the
 
709
c          user to change it, and possibly other inputs, before
 
710
c          calling the solver again.
 
711
c
 
712
c iopt   = an integer flag to specify whether or not any optional
 
713
c          inputs are being used on this call.  input only.
 
714
c          the optional inputs are listed separately below.
 
715
c          iopt = 0 means no optional inputs are being used.
 
716
c                   default values will be used in all cases.
 
717
c          iopt = 1 means one or more optional inputs are being used.
 
718
c
 
719
c rwork  = a real working array (double precision).
 
720
c          the length of rwork must be at least
 
721
c             20 + nyh*(maxord + 1) + 3*neq + lenwm    where
 
722
c          nyh    = the initial value of neq,
 
723
c          maxord = 12 (if meth = 1) or 5 (if meth = 2) (unless a
 
724
c                   smaller value is given as an optional input),
 
725
c          lenwm   = neq**2 + 2    if miter is 1 or 2, and
 
726
c          lenwm   = (2*ml+mu+1)*neq + 2 if miter is 4 or 5.
 
727
c          (see mf description for the definition of meth and miter.)
 
728
c          thus if maxord has its default value and neq is constant,
 
729
c          this length is
 
730
c             22 + 16*neq + neq**2         for mf = 11 or 12,
 
731
c             22 + 17*neq + (2*ml+mu)*neq  for mf = 14 or 15,
 
732
c             22 +  9*neq + neq**2         for mf = 21 or 22,
 
733
c             22 + 10*neq + (2*ml+mu)*neq  for mf = 24 or 25.
 
734
c          the first 20 words of rwork are reserved for conditional
 
735
c          and optional inputs and optional outputs.
 
736
c
 
737
c          the following word in rwork is a conditional input..
 
738
c            rwork(1) = tcrit = critical value of t which the solver
 
739
c                       is not to overshoot.  required if itask is
 
740
c                       4 or 5, and ignored otherwise.  (see itask.)
 
741
c
 
742
c lrw    = the length of the array rwork, as declared by the user.
 
743
c          (this will be checked by the solver.)
 
744
c
 
745
c iwork  = an integer work array.  the length of iwork must be at least
 
746
c          20 + neq .  the first few words of iwork are used for
 
747
c          conditional and optional inputs and optional outputs.
 
748
c
 
749
c          the following 2 words in iwork are conditional inputs..
 
750
c            iwork(1) = ml     these are the lower and upper
 
751
c            iwork(2) = mu     half-bandwidths, respectively, of the
 
752
c                       matrices in the problem-- the jacobian dr/dy
 
753
c                       and the left-hand side matrix a. these half-
 
754
c                       bandwidths exclude the main diagonal, so
 
755
c                       the total bandwidth is ml + mu + 1 .
 
756
c                       the band is defined by the matrix locations
 
757
c                       (i,j) with i-ml .le. j .le. i+mu.  ml and mu
 
758
c                       must satisfy  0 .le.  ml,mu  .le. neq-1.
 
759
c                       these are required if miter is 4 or 5, and
 
760
c                       ignored otherwise.
 
761
c                       ml and mu may in fact be the band parameters for
 
762
c                       matrices to which dr/dy and a are only
 
763
c                       approximately equal.
 
764
c
 
765
c liw    = the length of the array iwork, as declared by the user.
 
766
c          (this will be checked by the solver.)
 
767
c
 
768
c note..  the work arrays must not be altered between calls to lsodi
 
769
c for the same problem, except possibly for the conditional and
 
770
c optional inputs, and except for the last 3*neq words of rwork.
 
771
c the latter space is used for internal scratch space, and so is
 
772
c available for use by the user outside lsodi between calls, if
 
773
c desired (but not for use by res, adda, or jac).
 
774
c
 
775
c mf     = the method flag.  used only for input.  the legal values of
 
776
c          mf are 11, 12, 14, 15, 21, 22, 24, and 25.
 
777
c          mf has decimal digits meth and miter.. mf = 10*meth + miter.
 
778
c            meth indicates the basic linear multistep method..
 
779
c              meth = 1 means the implicit adams method.
 
780
c              meth = 2 means the method based on backward
 
781
c                       differentiation formulas (bdf-s).
 
782
c                the bdf method is strongly preferred for stiff prob-
 
783
c              lems, while the adams method is preferred when the prob-
 
784
c              lem is not stiff. if the matrix a(t,y) is nonsingular,
 
785
c              stiffness here can be taken to mean that of the explicit
 
786
c              ode system dy/dt = a**(-1) * g.  if a is singular, the
 
787
c              concept of stiffness is not well defined.
 
788
c                if you do not know whether the problem is stiff, we
 
789
c              recommend using meth = 2.  if it is stiff, the advan-
 
790
c              tage of meth = 2 over 1 will be great, while if it is
 
791
c              not stiff, the advantage of meth = 1 will be slight.
 
792
c              if maximum efficiency is important, some experimentation
 
793
c              with meth may be necessary.
 
794
c            miter indicates the corrector iteration method..
 
795
c              miter = 1 means chord iteration with a user-supplied
 
796
c                        full (neq by neq) jacobian.
 
797
c              miter = 2 means chord iteration with an internally
 
798
c                        generated (difference quotient) full jacobian.
 
799
c                        this uses neq+1 extra calls to res per dr/dy
 
800
c                        evaluation.
 
801
c              miter = 4 means chord iteration with a user-supplied
 
802
c                        banded jacobian.
 
803
c              miter = 5 means chord iteration with an internally
 
804
c                        generated banded jacobian (using ml+mu+2
 
805
c                        extra calls to res per dr/dy evaluation).
 
806
c              if miter = 1 or 4, the user must supply a subroutine jac
 
807
c              (the name is arbitrary) as described above under jac.
 
808
c              for other values of miter, a dummy argument can be used.
 
809
c-----------------------------------------------------------------------
 
810
c optional inputs.
 
811
c
 
812
c the following is a list of the optional inputs provided for in the
 
813
c call sequence.  (see also part ii.)  for each such input variable,
 
814
c this table lists its name as used in this documentation, its
 
815
c location in the call sequence, its meaning, and the default value.
 
816
c the use of any of these inputs requires iopt = 1, and in that
 
817
c case all of these inputs are examined.  a value of zero for any
 
818
c of these optional inputs will cause the default value to be used.
 
819
c thus to use a subset of the optional inputs, simply preload
 
820
c locations 5 to 10 in rwork and iwork to 0.0 and 0 respectively, and
 
821
c then set those of interest to nonzero values.
 
822
c
 
823
c name    location      meaning and default value
 
824
c
 
825
c h0      rwork(5)  the step size to be attempted on the first step.
 
826
c                   the default value is determined by the solver.
 
827
c
 
828
c hmax    rwork(6)  the maximum absolute step size allowed.
 
829
c                   the default value is infinite.
 
830
c
 
831
c hmin    rwork(7)  the minimum absolute step size allowed.
 
832
c                   the default value is 0.  (this lower bound is not
 
833
c                   enforced on the final step before reaching tcrit
 
834
c                   when itask = 4 or 5.)
 
835
c
 
836
c maxord  iwork(5)  the maximum order to be allowed.  the default
 
837
c                   value is 12 if meth = 1, and 5 if meth = 2.
 
838
c                   if maxord exceeds the default value, it will
 
839
c                   be reduced to the default value.
 
840
c                   if maxord is changed during the problem, it may
 
841
c                   cause the current order to be reduced.
 
842
c
 
843
c mxstep  iwork(6)  maximum number of (internally defined) steps
 
844
c                   allowed during one call to the solver.
 
845
c                   the default value is 500.
 
846
c
 
847
c mxhnil  iwork(7)  maximum number of messages printed (per problem)
 
848
c                   warning that t + h = t on a step (h = step size).
 
849
c                   this must be positive to result in a non-default
 
850
c                   value.  the default value is 10.
 
851
c-----------------------------------------------------------------------
 
852
c optional outputs.
 
853
c
 
854
c as optional additional output from lsodi, the variables listed
 
855
c below are quantities related to the performance of lsodi
 
856
c which are available to the user.  these are communicated by way of
 
857
c the work arrays, but also have internal mnemonic names as shown.
 
858
c except where stated otherwise, all of these outputs are defined
 
859
c on any successful return from lsodi, and on any return with
 
860
c istate = -1, -2, -4, -5, -6, or -7. on a return with -3 (illegal
 
861
c input) or -8, they will be unchanged from their existing values
 
862
c (if any), except possibly for tolsf, lenrw, and leniw.
 
863
c on any error return, outputs relevant to the error will be defined,
 
864
c as noted below.
 
865
c
 
866
c name    location      meaning
 
867
c
 
868
c hu      rwork(11) the step size in t last used (successfully).
 
869
c
 
870
c hcur    rwork(12) the step size to be attempted on the next step.
 
871
c
 
872
c tcur    rwork(13) the current value of the independent variable
 
873
c                   which the solver has actually reached, i.e. the
 
874
c                   current internal mesh point in t.  on output, tcur
 
875
c                   will always be at least as far as the argument
 
876
c                   t, but may be farther (if interpolation was done).
 
877
c
 
878
c tolsf   rwork(14) a tolerance scale factor, greater than 1.0,
 
879
c                   computed when a request for too much accuracy was
 
880
c                   detected (istate = -3 if detected at the start of
 
881
c                   the problem, istate = -2 otherwise).  if itol is
 
882
c                   left unaltered but rtol and atol are uniformly
 
883
c                   scaled up by a factor of tolsf for the next call,
 
884
c                   then the solver is deemed likely to succeed.
 
885
c                   (the user may also ignore tolsf and alter the
 
886
c                   tolerance parameters in any other way appropriate.)
 
887
c
 
888
c nst     iwork(11) the number of steps taken for the problem so far.
 
889
c
 
890
c nre     iwork(12) the number of residual evaluations (res calls)
 
891
c                   for the problem so far.
 
892
c
 
893
c nje     iwork(13) the number of jacobian evaluations (each involving
 
894
c                   an evaluation of a and dr/dy) for the problem so
 
895
c                   far.  this equals the number of calls to adda and
 
896
c                   (if miter = 1 or 4) jac, and the number of matrix
 
897
c                   l-u decompositions.
 
898
c
 
899
c nqu     iwork(14) the method order last used (successfully).
 
900
c
 
901
c nqcur   iwork(15) the order to be attempted on the next step.
 
902
c
 
903
c imxer   iwork(16) the index of the component of largest magnitude in
 
904
c                   the weighted local error vector ( e(i)/ewt(i) ),
 
905
c                   on an error return with istate = -4 or -5.
 
906
c
 
907
c lenrw   iwork(17) the length of rwork actually required.
 
908
c                   this is defined on normal returns and on an illegal
 
909
c                   input return for insufficient storage.
 
910
c
 
911
c leniw   iwork(18) the length of iwork actually required.
 
912
c                   this is defined on normal returns and on an illegal
 
913
c                   input return for insufficient storage.
 
914
c
 
915
c
 
916
c the following two arrays are segments of the rwork array which
 
917
c may also be of interest to the user as optional outputs.
 
918
c for each array, the table below gives its internal name,
 
919
c its base address in rwork, and its description.
 
920
c
 
921
c name    base address      description
 
922
c
 
923
c yh      21             the nordsieck history array, of size nyh by
 
924
c                        (nqcur + 1), where nyh is the initial value
 
925
c                        of neq.  for j = 0,1,...,nqcur, column j+1
 
926
c                        of yh contains hcur**j/factorial(j) times
 
927
c                        the j-th derivative of the interpolating
 
928
c                        polynomial currently representing the solution,
 
929
c                        evaluated at t = tcur.
 
930
c
 
931
c acor     lenrw-neq+1   array of size neq used for the accumulated
 
932
c                        corrections on each step, scaled on output to
 
933
c                        represent the estimated local error in y on the
 
934
c                        last step. this is the vector e in the descrip-
 
935
c                        tion of the error control.  it is defined only
 
936
c                        on a return from lsodi with istate = 2.
 
937
c
 
938
c-----------------------------------------------------------------------
 
939
c part ii.  other routines callable.
 
940
c
 
941
c the following are optional calls which the user may make to
 
942
c gain additional capabilities in conjunction with lsodi.
 
943
c (the routines xsetun and xsetf are designed to conform to the
 
944
c slatec error handling package.)
 
945
c
 
946
c     form of call                  function
 
947
c   call xsetun(lun)          set the logical unit number, lun, for
 
948
c                             output of messages from lsodi, if
 
949
c                             the default is not desired.
 
950
c                             the default value of lun is 6.
 
951
c
 
952
c   call xsetf(mflag)         set a flag to control the printing of
 
953
c                             messages by lsodi.
 
954
c                             mflag = 0 means do not print. (danger..
 
955
c                             this risks losing valuable information.)
 
956
c                             mflag = 1 means print (the default).
 
957
c
 
958
c                             either of the above calls may be made at
 
959
c                             any time and will take effect immediately.
 
960
c
 
961
c   call srcom(rsav,isav,job) saves and restores the contents of
 
962
c                             the internal common blocks used by
 
963
c                             lsodi (see part iii below).
 
964
c                             rsav must be a real array of length 218
 
965
c                             or more, and isav must be an integer
 
966
c                             array of length 41 or more.
 
967
c                             job=1 means save common into rsav/isav.
 
968
c                             job=2 means restore common from rsav/isav.
 
969
c                                srcom is useful if one is
 
970
c                             interrupting a run and restarting
 
971
c                             later, or alternating between two or
 
972
c                             more problems solved with lsodi.
 
973
c
 
974
c   call intdy(,,,,,)         provide derivatives of y, of various
 
975
c        (see below)          orders, at a specified point t, if
 
976
c                             desired.  it may be called only after
 
977
c                             a successful return from lsodi.
 
978
c
 
979
c the detailed instructions for using intdy are as follows.
 
980
c the form of the call is..
 
981
c
 
982
c   call intdy (t, k, rwork(21), nyh, dky, iflag)
 
983
c
 
984
c the input parameters are..
 
985
c
 
986
c t         = value of independent variable where answers are desired
 
987
c             (normally the same as the t last returned by lsodi).
 
988
c             for valid results, t must lie between tcur - hu and tcur.
 
989
c             (see optional outputs for tcur and hu.)
 
990
c k         = integer order of the derivative desired.  k must satisfy
 
991
c             0 .le. k .le. nqcur, where nqcur is the current order
 
992
c             (see optional outputs).  the capability corresponding
 
993
c             to k = 0, i.e. computing y(t), is already provided
 
994
c             by lsodi directly.  since nqcur .ge. 1, the first
 
995
c             derivative dy/dt is always available with intdy.
 
996
c rwork(21) = the base address of the history array yh.
 
997
c nyh       = column length of yh, equal to the initial value of neq.
 
998
c
 
999
c the output parameters are..
 
1000
c
 
1001
c dky       = a real array of length neq containing the computed value
 
1002
c             of the k-th derivative of y(t).
 
1003
c iflag     = integer flag, returned as 0 if k and t were legal,
 
1004
c             -1 if k was illegal, and -2 if t was illegal.
 
1005
c             on an error return, a message is also written.
 
1006
c-----------------------------------------------------------------------
 
1007
c part iii.  common blocks.
 
1008
c
 
1009
c if lsodi is to be used in an overlay situation, the user
 
1010
c must declare, in the primary overlay, the variables in..
 
1011
c   (1) the call sequence to lsodi,
 
1012
c   (2) the two internal common blocks
 
1013
c         /ls0001/  of length  257  (218 double precision words
 
1014
c                         followed by 39 integer words),
 
1015
c         /eh0001/  of length  2 (integer words).
 
1016
c
 
1017
c if lsodi is used on a system in which the contents of internal
 
1018
c common blocks are not preserved between calls, the user should
 
1019
c declare the above two common blocks in his main program to insure
 
1020
c that their contents are preserved.
 
1021
c
 
1022
c if the solution of a given problem by lsodi is to be interrupted
 
1023
c and then later continued, such as when restarting an interrupted run
 
1024
c or alternating between two or more problems, the user should save,
 
1025
c following the return from the last lsodi call prior to the
 
1026
c interruption, the contents of the call sequence variables and the
 
1027
c internal common blocks, and later restore these values before the
 
1028
c next lsodi call for that problem.  to save and restore the common
 
1029
c blocks, use subroutine srcom (see part ii above).
 
1030
c
 
1031
c-----------------------------------------------------------------------
 
1032
c part iv.  optionally replaceable solver routines.
 
1033
c
 
1034
c below are descriptions of two routines in the lsodi package which
 
1035
c relate to the measurement of errors.  either routine can be
 
1036
c replaced by a user-supplied version, if desired.  however, since such
 
1037
c a replacement may have a major impact on performance, it should be
 
1038
c done only when absolutely necessary, and only with great caution.
 
1039
c (note.. the means by which the package version of a routine is
 
1040
c superseded by the user-s version may be system-dependent.)
 
1041
c
 
1042
c (a) ewset.
 
1043
c the following subroutine is called just before each internal
 
1044
c integration step, and sets the array of error weights, ewt, as
 
1045
c described under itol/rtol/atol above..
 
1046
c     subroutine ewset (neq, itol, rtol, atol, ycur, ewt)
 
1047
c where neq, itol, rtol, and atol are as in the lsodi call sequence,
 
1048
c ycur contains the current dependent variable vector, and
 
1049
c ewt is the array of weights set by ewset.
 
1050
c
 
1051
c if the user supplies this subroutine, it must return in ewt(i)
 
1052
c (i = 1,...,neq) a positive quantity suitable for comparing errors
 
1053
c in y(i) to.  the ewt array returned by ewset is passed to the
 
1054
c vnorm routine (see below), and also used by lsodi in the computation
 
1055
c of the optional output imxer, the diagonal jacobian approximation,
 
1056
c and the increments for difference quotient jacobians.
 
1057
c
 
1058
c in the user-supplied version of ewset, it may be desirable to use
 
1059
c the current values of derivatives of y.  derivatives up to order nq
 
1060
c are available from the history array yh, described above under
 
1061
c optional outputs.  in ewset, yh is identical to the ycur array,
 
1062
c extended to nq + 1 columns with a column length of nyh and scale
 
1063
c factors of h**j/factorial(j).  on the first call for the problem,
 
1064
c given by nst = 0, nq is 1 and h is temporarily set to 1.0.
 
1065
c the quantities nq, nyh, h, and nst can be obtained by including
 
1066
c in ewset the statements..
 
1067
c     double precision h, rls
 
1068
c     common /ls0001/ rls(218),ils(39)
 
1069
c     nq = ils(35)
 
1070
c     nyh = ils(14)
 
1071
c     nst = ils(36)
 
1072
c     h = rls(212)
 
1073
c thus, for example, the current value of dy/dt can be obtained as
 
1074
c ycur(nyh+i)/h  (i=1,...,neq)  (and the division by h is
 
1075
c unnecessary when nst = 0).
 
1076
c
 
1077
c (b) vnorm.
 
1078
c the following is a real function routine which computes the weighted
 
1079
c root-mean-square norm of a vector v..
 
1080
c     d = vnorm (n, v, w)
 
1081
c where..
 
1082
c   n = the length of the vector,
 
1083
c   v = real array of length n containing the vector,
 
1084
c   w = real array of length n containing weights,
 
1085
c   d = sqrt( (1/n) * sum(v(i)*w(i))**2 ).
 
1086
c vnorm is called with n = neq and with w(i) = 1.0/ewt(i), where
 
1087
c ewt is as set by subroutine ewset.
 
1088
c
 
1089
c if the user supplies this function, it should return a non-negative
 
1090
c value of vnorm suitable for use in the error control in lsodi.
 
1091
c none of the arguments should be altered by vnorm.
 
1092
c for example, a user-supplied vnorm routine might..
 
1093
c   -substitute a max-norm of (v(i)*w(i)) for the rms-norm, or
 
1094
c   -ignore some components of v in the norm, with the effect of
 
1095
c    suppressing the error control on those components of y.
 
1096
c-----------------------------------------------------------------------
 
1097
c-----------------------------------------------------------------------
 
1098
c other routines in the lsodi package.
 
1099
c
 
1100
c in addition to subroutine lsodi, the lsodi package includes the
 
1101
c following subroutines and function routines..
 
1102
c  ainvg    computes the initial value of the vector
 
1103
c             dy/dt = inverse(a) * g
 
1104
c  intdy    computes an interpolated value of the y vector at t = tout.
 
1105
c  stodi    is the core integrator, which does one step of the
 
1106
c           integration and the associated error control.
 
1107
c  cfode    sets all method coefficients and test constants.
 
1108
c  prepji   computes and preprocesses the jacobian matrix
 
1109
c           and the newton iteration matrix p.
 
1110
c  solsy    manages solution of linear system in chord iteration.
 
1111
c  ewset    sets the error weight vector ewt before each step.
 
1112
c  vnorm    computes the weighted r.m.s. norm of a vector.
 
1113
c  srcom    is a user-callable routine to save and restore
 
1114
c           the contents of the internal common blocks.
 
1115
c  dgefa and dgesl   are routines from linpack for solving full
 
1116
c           systems of linear algebraic equations.
 
1117
c  dgbfa and dgbsl   are routines from linpack for solving banded
 
1118
c           linear systems.
 
1119
c  daxpy, dscal, idamax, and ddot   are basic linear algebra modules
 
1120
c           (blas) used by the above linpack routines.
 
1121
c  d1mach   computes the unit roundoff in a machine-independent manner.
 
1122
c  xerrwv, xsetun, and xsetf   handle the printing of all error
 
1123
c           messages and warnings.  xerrwv is machine-dependent.
 
1124
c note..  vnorm, idamax, ddot, and d1mach are function routines.
 
1125
c all the others are subroutines.
 
1126
c
 
1127
c the intrinsic and external routines used by lsodi are..  dabs,
 
1128
c dmax1, dmin1, dfloat, iabs, max0, min0, mod, dsign, dsqrt, and write.
 
1129
c
 
1130
c a block data subprogram is also included with the package,
 
1131
c for loading some of the variables in internal common.
 
1132
c
 
1133
c-----------------------------------------------------------------------
 
1134
c the following card is for optimized compilation on llnl compilers.
 
1135
clll. optimize
 
1136
c-----------------------------------------------------------------------
 
1137
      external prepji, solsy
 
1138
      integer illin, init, lyh, lewt, lacor, lsavr, lwm, liwm,
 
1139
     1   mxstep, mxhnil, nhnil, ntrep, nslast, nyh, iowns
 
1140
      integer icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter,
 
1141
     1   maxord, maxcor, msbp, mxncf, n, nq, nst, nre, nje, nqu
 
1142
      integer i, i1, i2, ier, iflag, imxer, ires, kgo,
 
1143
     1   leniw, lenrw, lenwm, lp, lyd0, ml, mord, mu, mxhnl0, mxstp0
 
1144
      double precision rowns,
 
1145
     1   ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround
 
1146
      double precision atoli, ayi, big, ewti, h0, hmax, hmx, rh, rtoli,
 
1147
     1   tcrit, tdist, tnext, tol, tolsf, tp, size, sum, w0,
 
1148
     2   d1mach, vnorm
 
1149
      dimension mord(2)
 
1150
      logical ihit
 
1151
c-----------------------------------------------------------------------
 
1152
c the following internal common block contains
 
1153
c (a) variables which are local to any subroutine but whose values must
 
1154
c     be preserved between calls to the routine (own variables), and
 
1155
c (b) variables which are communicated between subroutines.
 
1156
c common block ls0001 is shared by the lsodi and lsode packages.
 
1157
c the structure of ls0001 is as follows..  all real variables are
 
1158
c listed first, followed by all integers.  within each type, the
 
1159
c variables are grouped with those local to subroutine lsodi first,
 
1160
c then those local to subroutine stodi, and finally those used
 
1161
c for communication.  the block is declared in subroutines
 
1162
c lsodi, intdy, stodi, prepji, and solsy.  groups of variables are
 
1163
c replaced by dummy arrays in the common declarations in routines
 
1164
c where those variables are not used.
 
1165
c-----------------------------------------------------------------------
 
1166
      common /ls0001/ rowns(209),
 
1167
     1   ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround,
 
1168
     2   illin, init, lyh, lewt, lacor, lsavr, lwm, liwm,
 
1169
     3   mxstep, mxhnil, nhnil, ntrep, nslast, nyh, iowns(6),
 
1170
     4   icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter,
 
1171
     5   maxord, maxcor, msbp, mxncf, n, nq, nst, nre, nje, nqu
 
1172
c
 
1173
      data  mord(1),mord(2)/12,5/, mxstp0/500/, mxhnl0/10/
 
1174
c-----------------------------------------------------------------------
 
1175
c block a.
 
1176
c this code block is executed on every call.
 
1177
c it tests istate and itask for legality and branches appropriately.
 
1178
c if istate .gt. 1 but the flag init shows that initialization has
 
1179
c not yet been done, an error return occurs.
 
1180
c if istate = 0 or 1 and tout = t, jump to block g and return
 
1181
c immediately.
 
1182
c-----------------------------------------------------------------------
 
1183
      if (istate .lt. 0 .or. istate .gt. 3) go to 601
 
1184
      if (itask .lt. 1 .or. itask .gt. 5) go to 602
 
1185
      if (istate .le. 1) go to 10
 
1186
      if (init .eq. 0) go to 603
 
1187
      if (istate .eq. 2) go to 200
 
1188
      go to 20
 
1189
 10   init = 0
 
1190
      if (tout .eq. t) go to 430
 
1191
 20   ntrep = 0
 
1192
c-----------------------------------------------------------------------
 
1193
c block b.
 
1194
c the next code block is executed for the initial call (istate = 0 or 1)
 
1195
c or for a continuation call with parameter changes (istate = 3).
 
1196
c it contains checking of all inputs and various initializations.
 
1197
c
 
1198
c first check legality of the non-optional inputs neq, itol, iopt,
 
1199
c mf, ml, and mu.
 
1200
c-----------------------------------------------------------------------
 
1201
      if (neq(1) .le. 0) go to 604
 
1202
      if (istate .le. 1) go to 25
 
1203
      if (neq(1) .gt. n) go to 605
 
1204
 25   n = neq(1)
 
1205
      if (itol .lt. 1 .or. itol .gt. 4) go to 606
 
1206
      if (iopt .lt. 0 .or. iopt .gt. 1) go to 607
 
1207
      meth = mf/10
 
1208
      miter = mf - 10*meth
 
1209
      if (meth .lt. 1 .or. meth .gt. 2) go to 608
 
1210
      if (miter .le. 0 .or. miter .gt. 5) go to 608
 
1211
      if (miter .eq. 3)  go to 608
 
1212
      if (miter .lt. 3) go to 30
 
1213
      ml = iwork(1)
 
1214
      mu = iwork(2)
 
1215
      if (ml .lt. 0 .or. ml .ge. n) go to 609
 
1216
      if (mu .lt. 0 .or. mu .ge. n) go to 610
 
1217
 30   continue
 
1218
c next process and check the optional inputs. --------------------------
 
1219
      if (iopt .eq. 1) go to 40
 
1220
      maxord = mord(meth)
 
1221
      mxstep = mxstp0
 
1222
      mxhnil = mxhnl0
 
1223
      if (istate .le. 1) h0 = 0.0d0
 
1224
      hmxi = 0.0d0
 
1225
      hmin = 0.0d0
 
1226
      go to 60
 
1227
 40   maxord = iwork(5)
 
1228
      if (maxord .lt. 0) go to 611
 
1229
      if (maxord .eq. 0) maxord = 100
 
1230
      maxord = min0(maxord,mord(meth))
 
1231
      mxstep = iwork(6)
 
1232
      if (mxstep .lt. 0) go to 612
 
1233
      if (mxstep .eq. 0) mxstep = mxstp0
 
1234
      mxhnil = iwork(7)
 
1235
      if (mxhnil .lt. 0) go to 613
 
1236
      if (mxhnil .eq. 0) mxhnil = mxhnl0
 
1237
      if (istate .gt. 1) go to 50
 
1238
      h0 = rwork(5)
 
1239
      if ((tout - t)*h0 .lt. 0.0d0) go to 614
 
1240
 50   hmax = rwork(6)
 
1241
      if (hmax .lt. 0.0d0) go to 615
 
1242
      hmxi = 0.0d0
 
1243
      if (hmax .gt. 0.0d0) hmxi = 1.0d0/hmax
 
1244
      hmin = rwork(7)
 
1245
      if (hmin .lt. 0.0d0) go to 616
 
1246
c-----------------------------------------------------------------------
 
1247
c set work array pointers and check lengths lrw and liw.
 
1248
c pointers to segments of rwork and iwork are named by prefixing l to
 
1249
c the name of the segment.  e.g., the segment yh starts at rwork(lyh).
 
1250
c segments of rwork (in order) are denoted yh, wm, ewt, savr, acor.
 
1251
c-----------------------------------------------------------------------
 
1252
 60   lyh = 21
 
1253
      if (istate .le. 1) nyh = n
 
1254
      lwm = lyh + (maxord + 1)*nyh
 
1255
      if (miter .le. 2) lenwm = n*n + 2
 
1256
      if (miter .ge. 4) lenwm = (2*ml + mu + 1)*n + 2
 
1257
      lewt = lwm + lenwm
 
1258
      lsavr = lewt + n
 
1259
      lacor = lsavr + n
 
1260
      lenrw = lacor + n - 1
 
1261
      iwork(17) = lenrw
 
1262
      liwm = 1
 
1263
      leniw = 20 + n
 
1264
      iwork(18) = leniw
 
1265
      if (lenrw .gt. lrw) go to 617
 
1266
      if (leniw .gt. liw) go to 618
 
1267
c check rtol and atol for legality. ------------------------------------
 
1268
      rtoli = rtol(1)
 
1269
      atoli = atol(1)
 
1270
      do 70 i = 1,n
 
1271
        if (itol .ge. 3) rtoli = rtol(i)
 
1272
        if (itol .eq. 2 .or. itol .eq. 4) atoli = atol(i)
 
1273
        if (rtoli .lt. 0.0d0) go to 619
 
1274
        if (atoli .lt. 0.0d0) go to 620
 
1275
 70     continue
 
1276
      if (istate .le. 1) go to 100
 
1277
c if istate = 3, set flag to signal parameter changes to stodi. --------
 
1278
      jstart = -1
 
1279
      if (nq .le. maxord) go to 90
 
1280
c maxord was reduced below nq.  copy yh(*,maxord+2) into ydoti.---------
 
1281
      do 80 i = 1,n
 
1282
 80     ydoti(i) = rwork(i+lwm-1)
 
1283
c reload wm(1) = rwork(lwm), since lwm may have changed. ---------------
 
1284
 90   rwork(lwm) = dsqrt(uround)
 
1285
      if (n .eq. nyh) go to 200
 
1286
c neq was reduced.  zero part of yh to avoid undefined references. -----
 
1287
      i1 = lyh + l*nyh
 
1288
      i2 = lyh + (maxord + 1)*nyh - 1
 
1289
      if (i1 .gt. i2) go to 200
 
1290
      do 95 i = i1,i2
 
1291
 95     rwork(i) = 0.0d0
 
1292
      go to 200
 
1293
c-----------------------------------------------------------------------
 
1294
c block c.
 
1295
c the next block is for the initial call only (istate = 0 or 1).
 
1296
c it contains all remaining initializations, the call to ainvg
 
1297
c (if istate = 1), and the calculation of the initial step size.
 
1298
c the error weights in ewt are inverted after being loaded.
 
1299
c-----------------------------------------------------------------------
 
1300
 100  uround = d1mach(4)
 
1301
      tn = t
 
1302
      if (itask .ne. 4 .and. itask .ne. 5) go to 105
 
1303
      tcrit = rwork(1)
 
1304
      if ((tcrit - tout)*(tout - t) .lt. 0.0d0) go to 625
 
1305
      if (h0 .ne. 0.0d0 .and. (t + h0 - tcrit)*h0 .gt. 0.0d0)
 
1306
     1   h0 = tcrit - t
 
1307
 105  jstart = 0
 
1308
      rwork(lwm) = dsqrt(uround)
 
1309
      nhnil = 0
 
1310
      nst = 0
 
1311
      nre = 0
 
1312
      nje = 0
 
1313
      nslast = 0
 
1314
      hu = 0.0d0
 
1315
      nqu = 0
 
1316
      ccmax = 0.3d0
 
1317
      maxcor = 3
 
1318
      msbp = 20
 
1319
      mxncf = 10
 
1320
c compute initial dy/dt, if necessary, and load it and initial y into yh
 
1321
      lyd0 = lyh + nyh
 
1322
      lp = lwm + 1
 
1323
      if (istate .eq. 1) go to 120
 
1324
c lsodi must compute initial dy/dt (lyd0 points to yh(*,2)). -----------
 
1325
         call ainvg( res, adda, neq, t, y, rwork(lyd0), miter,
 
1326
     1               ml, mu, rwork(lp), iwork(21), ier )
 
1327
         nre = nre + 1
 
1328
         if (ier.lt.0) go to 560
 
1329
         if (ier.eq.0) go to 110
 
1330
         go to 565
 
1331
 110     continue
 
1332
         do 115 i = 1,n
 
1333
 115        rwork(i+lyh-1) = y(i)
 
1334
         go to 130
 
1335
c initial dy/dt has been supplied. -------------------------------------
 
1336
 120     do 125 i = 1,n
 
1337
            rwork(i+lyh-1) = y(i)
 
1338
 125        rwork(i+lyd0-1) = ydoti(i)
 
1339
c load and invert the ewt array.  (h is temporarily set to 1.0.) -------
 
1340
 130  continue
 
1341
      nq = 1
 
1342
      h = 1.0d0
 
1343
      call ewset (n, itol, rtol, atol, rwork(lyh), rwork(lewt))
 
1344
      do 135 i = 1,n
 
1345
        if (rwork(i+lewt-1) .le. 0.0d0) go to 621
 
1346
 135    rwork(i+lewt-1) = 1.0d0/rwork(i+lewt-1)
 
1347
c-----------------------------------------------------------------------
 
1348
c the coding below computes the step size, h0, to be attempted on the
 
1349
c first step, unless the user has supplied a value for this.
 
1350
c first check that tout - t differs significantly from zero.
 
1351
c a scalar tolerance quantity tol is computed, as max(rtol(i))
 
1352
c if this is positive, or max(atol(i)/abs(y(i))) otherwise, adjusted
 
1353
c so as to be between 100*uround and 1.0e-3.
 
1354
c then the computed value h0 is given by..
 
1355
c                                      neq
 
1356
c   h0**2 = tol / ( w0**-2 + (1/neq) * sum ( ydot(i)/ywt(i) )**2  )
 
1357
c                                       1
 
1358
c where   w0      = max ( abs(t), abs(tout) ),
 
1359
c         ydot(i) = i-th component of initial value of dy/dt,
 
1360
c         ywt(i)  = ewt(i)/tol  (a weight for y(i)).
 
1361
c the sign of h0 is inferred from the initial values of tout and t.
 
1362
c-----------------------------------------------------------------------
 
1363
      if (h0 .ne. 0.0d0) go to 180
 
1364
      tdist = dabs(tout - t)
 
1365
      w0 = dmax1(dabs(t),dabs(tout))
 
1366
      if (tdist .lt. 2.0d0*uround*w0) go to 622
 
1367
      tol = rtol(1)
 
1368
      if (itol .le. 2) go to 145
 
1369
      do 140 i = 1,n
 
1370
 140    tol = dmax1(tol,rtol(i))
 
1371
 145  if (tol .gt. 0.0d0) go to 160
 
1372
      atoli = atol(1)
 
1373
      do 150 i = 1,n
 
1374
        if (itol .eq. 2 .or. itol .eq. 4) atoli = atol(i)
 
1375
        ayi = dabs(y(i))
 
1376
        if (ayi .ne. 0.0d0) tol = dmax1(tol,atoli/ayi)
 
1377
 150    continue
 
1378
 160  tol = dmax1(tol,100.0d0*uround)
 
1379
      tol = dmin1(tol,0.001d0)
 
1380
      sum = vnorm (n, rwork(lyd0), rwork(lewt))
 
1381
      sum = 1.0d0/(tol*w0*w0) + tol*sum**2
 
1382
      h0 = 1.0d0/dsqrt(sum)
 
1383
      h0 = dmin1(h0,tdist)
 
1384
      h0 = dsign(h0,tout-t)
 
1385
c adjust h0 if necessary to meet hmax bound. ---------------------------
 
1386
 180  rh = dabs(h0)*hmxi
 
1387
      if (rh .gt. 1.0d0) h0 = h0/rh
 
1388
c load h with h0 and scale yh(*,2) by h0. ------------------------------
 
1389
      h = h0
 
1390
      do 190 i = 1,n
 
1391
 190    rwork(i+lyd0-1) = h0*rwork(i+lyd0-1)
 
1392
      go to 270
 
1393
c-----------------------------------------------------------------------
 
1394
c block d.
 
1395
c the next code block is for continuation calls only (istate = 2 or 3)
 
1396
c and is to check stop conditions before taking a step.
 
1397
c-----------------------------------------------------------------------
 
1398
 200  nslast = nst
 
1399
      go to (210, 250, 220, 230, 240), itask
 
1400
 210  if ((tn - tout)*h .lt. 0.0d0) go to 250
 
1401
      call intdy (tout, 0, rwork(lyh), nyh, y, iflag)
 
1402
      if (iflag .ne. 0) go to 627
 
1403
      t = tout
 
1404
      go to 420
 
1405
 220  tp = tn - hu*(1.0d0 + 100.0d0*uround)
 
1406
      if ((tp - tout)*h .gt. 0.0d0) go to 623
 
1407
      if ((tn - tout)*h .lt. 0.0d0) go to 250
 
1408
      go to 400
 
1409
 230  tcrit = rwork(1)
 
1410
      if ((tn - tcrit)*h .gt. 0.0d0) go to 624
 
1411
      if ((tcrit - tout)*h .lt. 0.0d0) go to 625
 
1412
      if ((tn - tout)*h .lt. 0.0d0) go to 245
 
1413
      call intdy (tout, 0, rwork(lyh), nyh, y, iflag)
 
1414
      if (iflag .ne. 0) go to 627
 
1415
      t = tout
 
1416
      go to 420
 
1417
 240  tcrit = rwork(1)
 
1418
      if ((tn - tcrit)*h .gt. 0.0d0) go to 624
 
1419
 245  hmx = dabs(tn) + dabs(h)
 
1420
      ihit = dabs(tn - tcrit) .le. 100.0d0*uround*hmx
 
1421
      if (ihit) go to 400
 
1422
      tnext = tn + h*(1.0d0 + 4.0d0*uround)
 
1423
      if ((tnext - tcrit)*h .le. 0.0d0) go to 250
 
1424
      h = (tcrit - tn)*(1.0d0 - 4.0d0*uround)
 
1425
      if (istate .eq. 2) jstart = -2
 
1426
c-----------------------------------------------------------------------
 
1427
c block e.
 
1428
c the next block is normally executed for all calls and contains
 
1429
c the call to the one-step core integrator stodi.
 
1430
c
 
1431
c this is a looping point for the integration steps.
 
1432
c
 
1433
c first check for too many steps being taken, update ewt (if not at
 
1434
c start of problem), check for too much accuracy being requested, and
 
1435
c check for h below the roundoff level in t.
 
1436
c-----------------------------------------------------------------------
 
1437
 250  continue
 
1438
      if ((nst-nslast) .ge. mxstep) go to 500
 
1439
      call ewset (n, itol, rtol, atol, rwork(lyh), rwork(lewt))
 
1440
      do 260 i = 1,n
 
1441
        if (rwork(i+lewt-1) .le. 0.0d0) go to 510
 
1442
 260    rwork(i+lewt-1) = 1.0d0/rwork(i+lewt-1)
 
1443
 270  tolsf = uround*vnorm (n, rwork(lyh), rwork(lewt))
 
1444
      if (tolsf .le. 1.0d0) go to 280
 
1445
      tolsf = tolsf*2.0d0
 
1446
      if (nst .eq. 0) go to 626
 
1447
      go to 520
 
1448
 280  if ((tn + h) .ne. tn) go to 290
 
1449
      nhnil = nhnil + 1
 
1450
      if (nhnil .gt. mxhnil) go to 290
 
1451
      call xerrwv('lsodi--  warning..internal t (=r1) and h (=r2) are',
 
1452
     1   50, 101, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1453
      call xerrwv(
 
1454
     1  '      such that in the machine, t + h = t on the next step  ',
 
1455
     1   60, 101, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1456
      call xerrwv('      (h = step size). solver will continue anyway',
 
1457
     1   50, 101, 0, 0, 0, 0, 2, tn, h)
 
1458
      if (nhnil .lt. mxhnil) go to 290
 
1459
      call xerrwv('lsodi--  above warning has been issued i1 times.  ',
 
1460
     1   50, 102, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1461
      call xerrwv('      it will not be issued again for this problem',
 
1462
     1   50, 102, 0, 1, mxhnil, 0, 0, 0.0d0, 0.0d0)
 
1463
 290  continue
 
1464
c-----------------------------------------------------------------------
 
1465
c     call stodi(neq,y,yh,nyh,yh1,ewt,savf,savr,acor,wm,iwm,res,
 
1466
c                adda,jac,prepji,solsy)
 
1467
c note... savf in stodi occupies the same space as ydoti in lsodi.
 
1468
c-----------------------------------------------------------------------
 
1469
      call stodi (neq, y, rwork(lyh), nyh, rwork(lyh), rwork(lewt),
 
1470
     1   ydoti, rwork(lsavr), rwork(lacor), rwork(lwm),
 
1471
     2   iwork(liwm), res, adda, jac, prepji, solsy )
 
1472
      kgo = 1 - kflag
 
1473
      go to (300, 530, 540, 400, 550), kgo
 
1474
c
 
1475
c kgo = 1,success. 2,error test failure. 3,convergence failure.
 
1476
c       4,res ordered return. 5,res returned error.
 
1477
c-----------------------------------------------------------------------
 
1478
c block f.
 
1479
c the following block handles the case of a successful return from the
 
1480
c core integrator (kflag = 0).  test for stop conditions.
 
1481
c-----------------------------------------------------------------------
 
1482
 300  init = 1
 
1483
      go to (310, 400, 330, 340, 350), itask
 
1484
c itask = 1.  if tout has been reached, interpolate. -------------------
 
1485
 310  if ((tn - tout)*h .lt. 0.0d0) go to 250
 
1486
      call intdy (tout, 0, rwork(lyh), nyh, y, iflag)
 
1487
      t = tout
 
1488
      go to 420
 
1489
c itask = 3.  jump to exit if tout was reached. ------------------------
 
1490
 330  if ((tn - tout)*h .ge. 0.0d0) go to 400
 
1491
      go to 250
 
1492
c itask = 4.  see if tout or tcrit was reached.  adjust h if necessary.
 
1493
 340  if ((tn - tout)*h .lt. 0.0d0) go to 345
 
1494
      call intdy (tout, 0, rwork(lyh), nyh, y, iflag)
 
1495
      t = tout
 
1496
      go to 420
 
1497
 345  hmx = dabs(tn) + dabs(h)
 
1498
      ihit = dabs(tn - tcrit) .le. 100.0d0*uround*hmx
 
1499
      if (ihit) go to 400
 
1500
      tnext = tn + h*(1.0d0 + 4.0d0*uround)
 
1501
      if ((tnext - tcrit)*h .le. 0.0d0) go to 250
 
1502
      h = (tcrit - tn)*(1.0d0 - 4.0d0*uround)
 
1503
      jstart = -2
 
1504
      go to 250
 
1505
c itask = 5.  see if tcrit was reached and jump to exit. ---------------
 
1506
 350  hmx = dabs(tn) + dabs(h)
 
1507
      ihit = dabs(tn - tcrit) .le. 100.0d0*uround*hmx
 
1508
c-----------------------------------------------------------------------
 
1509
c block g.
 
1510
c the following block handles all successful returns from lsodi.
 
1511
c if itask .ne. 1, y is loaded from yh and t is set accordingly.
 
1512
c istate is set to 2, the illegal input counter is zeroed, and the
 
1513
c optional outputs are loaded into the work arrays before returning.  if
 
1514
c istate = 0 or 1 and tout = t, there is a return with no action taken,
 
1515
c except that if this has happened repeatedly, the run is terminated.
 
1516
c-----------------------------------------------------------------------
 
1517
 400  do 410 i = 1,n
 
1518
 410    y(i) = rwork(i+lyh-1)
 
1519
      t = tn
 
1520
      if (itask .ne. 4 .and. itask .ne. 5) go to 420
 
1521
      if (ihit) t = tcrit
 
1522
 420  istate = 2
 
1523
      if (kflag .eq. -3) istate = 3
 
1524
      illin = 0
 
1525
      rwork(11) = hu
 
1526
      rwork(12) = h
 
1527
      rwork(13) = tn
 
1528
      iwork(11) = nst
 
1529
      iwork(12) = nre
 
1530
      iwork(13) = nje
 
1531
      iwork(14) = nqu
 
1532
      iwork(15) = nq
 
1533
      return
 
1534
c
 
1535
 430  ntrep = ntrep + 1
 
1536
      if (ntrep .lt. 5) return
 
1537
      call xerrwv(
 
1538
     1  'lsodi--  repeated calls with istate= 0 or 1 and tout= t(=r1)',
 
1539
     1   60, 301, 0, 0, 0, 0, 1, t, 0.0d0)
 
1540
      go to 800
 
1541
c-----------------------------------------------------------------------
 
1542
c block h.
 
1543
c the following block handles all unsuccessful returns other than
 
1544
c those for illegal input.  first the error message routine is called.
 
1545
c if there was an error test or convergence test failure, imxer is set.
 
1546
c then y is loaded from yh, t is set to tn, and the illegal input
 
1547
c counter illin is set to 0.  the optional outputs are loaded into
 
1548
c the work arrays before returning.
 
1549
c-----------------------------------------------------------------------
 
1550
c the maximum number of steps was taken before reaching tout. ----------
 
1551
 500  call xerrwv('lsodi--  at current t (=r1), mxstep (=i1) steps   ',
 
1552
     1   50, 201, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1553
      call xerrwv('      taken on this call before reaching tout     ',
 
1554
     1   50, 201, 0, 1, mxstep, 0, 1, tn, 0.0d0)
 
1555
      istate = -1
 
1556
      go to 580
 
1557
c ewt(i) .le. 0.0 for some i (not at start of problem). ----------------
 
1558
 510  ewti = rwork(lewt+i-1)
 
1559
      call xerrwv('lsodi--  at t (=r1), ewt(i1) has become r2 .le. 0.',
 
1560
     1   50, 202, 0, 1, i, 0, 2, tn, ewti)
 
1561
      istate = -6
 
1562
      go to 590
 
1563
c too much accuracy requested for machine precision. -------------------
 
1564
 520  call xerrwv('lsodi--  at t (=r1), too much accuracy requested  ',
 
1565
     1   50, 203, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1566
      call xerrwv('      for precision of machine..  see tolsf (=r2) ',
 
1567
     1   50, 203, 0, 0, 0, 0, 2, tn, tolsf)
 
1568
      rwork(14) = tolsf
 
1569
      istate = -2
 
1570
      go to 590
 
1571
c kflag = -1.  error test failed repeatedly or with abs(h) = hmin. -----
 
1572
 530  call xerrwv('lsodi--  at t(=r1) and step size h(=r2), the error',
 
1573
     1   50, 204, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1574
      call xerrwv('      test failed repeatedly or with abs(h) = hmin',
 
1575
     1   50, 204, 0, 0, 0, 0, 2, tn, h)
 
1576
      istate = -4
 
1577
      go to 570
 
1578
c kflag = -2.  convergence failed repeatedly or with abs(h) = hmin. ----
 
1579
 540  call xerrwv('lsodi--  at t (=r1) and step size h (=r2), the    ',
 
1580
     1   50, 205, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1581
      call xerrwv('      corrector convergence failed repeatedly     ',
 
1582
     1   50, 205, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1583
      call xerrwv('      or with abs(h) = hmin   ',
 
1584
     1   30, 205, 0, 0, 0, 0, 2, tn, h)
 
1585
      istate = -5
 
1586
      go to 570
 
1587
c ires = 3 returned by res, despite retries by stodi. ------------------
 
1588
 550  call xerrwv('lsodi--  at t (=r1) residual routine returned     ',
 
1589
     1   50, 206, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1590
      call xerrwv('      error ires = 3 repeatedly         ',
 
1591
     1   40, 206, 0, 0, 0, 0, 1, tn, 0.0d0)
 
1592
      istate = -7
 
1593
      go to 590
 
1594
c ainvg failed because a-matrix was singular. --------------------------
 
1595
 560  ier = -ier
 
1596
      call xerrwv(
 
1597
     1  'lsodi-- attempt to initialize dy/dt failed.. matrix a is    ',
 
1598
     1   60, 207, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1599
      call xerrwv('      singular.  sgefa or sgbfa returned info=(i1)',
 
1600
     2   50, 207, 0, 1, ier, 0, 0, 0.0d0, 0.0d0)
 
1601
      istate = -8
 
1602
      return
 
1603
c ainvg failed because res set ires to 2 or 3. -------------------------
 
1604
 565  call xerrwv('lsodi--  attempt to initialize dy/dt failed       ',
 
1605
     1   50, 208, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1606
      call xerrwv('      because residual routine set its error flag ',
 
1607
     1   50, 208, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1608
      call xerrwv('      to ires = (i1)',
 
1609
     1   20, 208, 0, 1, ier, 0, 0, 0.0d0, 0.0d0)
 
1610
      istate = -8
 
1611
      return
 
1612
c compute imxer if relevant. -------------------------------------------
 
1613
 570  big = 0.0d0
 
1614
      imxer = 1
 
1615
      do 575 i = 1,n
 
1616
        size = dabs(rwork(i+lacor-1)*rwork(i+lewt-1))
 
1617
        if (big .ge. size) go to 575
 
1618
        big = size
 
1619
        imxer = i
 
1620
 575    continue
 
1621
      iwork(16) = imxer
 
1622
c compute residual if relevant. ----------------------------------------
 
1623
 580  lyd0 = lyh + nyh
 
1624
      do 585 i = 1,n
 
1625
         rwork(i+lsavr-1) = rwork(i+lyd0-1)/h
 
1626
 585     y(i) = rwork(i+lyh-1)
 
1627
      ires = 1
 
1628
      call res ( neq, tn, y, rwork(lsavr), ydoti, ires )
 
1629
      nre = nre + 1
 
1630
      if (ires .le. 1) go to 595
 
1631
      call xerrwv('lsodi--  residual routine set its flag ires       ',
 
1632
     1   50, 210, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1633
      call xerrwv('      to (i1) when called for final output.       ',
 
1634
     1   50, 210, 0, 1, ires, 0, 0, 0.0d0, 0.0d0)
 
1635
      go to 595
 
1636
c set y vector, t, illin, and optional outputs. ------------------------
 
1637
 590  do 592 i = 1,n
 
1638
 592    y(i) = rwork(i+lyh-1)
 
1639
 595  t = tn
 
1640
      illin = 0
 
1641
      rwork(11) = hu
 
1642
      rwork(12) = h
 
1643
      rwork(13) = tn
 
1644
      iwork(11) = nst
 
1645
      iwork(12) = nre
 
1646
      iwork(13) = nje
 
1647
      iwork(14) = nqu
 
1648
      iwork(15) = nq
 
1649
      return
 
1650
c-----------------------------------------------------------------------
 
1651
c block i.
 
1652
c the following block handles all error returns due to illegal input
 
1653
c (istate = -3), as detected before calling the core integrator.
 
1654
c first the error message routine is called.  then if there have been
 
1655
c 5 consecutive such returns just before this call to the solver,
 
1656
c the run is halted.
 
1657
c-----------------------------------------------------------------------
 
1658
 601  call xerrwv('lsodi--  istate (=i1) illegal ',
 
1659
     1   30, 1, 0, 1, istate, 0, 0, 0.0d0, 0.0d0)
 
1660
      go to 700
 
1661
 602  call xerrwv('lsodi--  itask (=i1) illegal  ',
 
1662
     1   30, 2, 0, 1, itask, 0, 0, 0.0d0, 0.0d0)
 
1663
      go to 700
 
1664
 603  call xerrwv('lsodi--  istate .gt. 1 but lsodi not initialized  ',
 
1665
     1   50, 3, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1666
      go to 700
 
1667
 604  call xerrwv('lsodi--  neq (=i1) .lt. 1     ',
 
1668
     1   30, 4, 0, 1, neq(1), 0, 0, 0.0d0, 0.0d0)
 
1669
      go to 700
 
1670
 605  call xerrwv('lsodi--  istate = 3 and neq increased (i1 to i2)  ',
 
1671
     1   50, 5, 0, 2, n, neq(1), 0, 0.0d0, 0.0d0)
 
1672
      go to 700
 
1673
 606  call xerrwv('lsodi--  itol (=i1) illegal   ',
 
1674
     1   30, 6, 0, 1, itol, 0, 0, 0.0d0, 0.0d0)
 
1675
      go to 700
 
1676
 607  call xerrwv('lsodi--  iopt (=i1) illegal   ',
 
1677
     1   30, 7, 0, 1, iopt, 0, 0, 0.0d0, 0.0d0)
 
1678
      go to 700
 
1679
 608  call xerrwv('lsodi--  mf (=i1) illegal     ',
 
1680
     1   30, 8, 0, 1, mf, 0, 0, 0.0d0, 0.0d0)
 
1681
      go to 700
 
1682
 609  call xerrwv('lsodi--  ml(=i1) illegal.. .lt. 0 or .ge. neq(=i2)',
 
1683
     1   50, 9, 0, 2, ml, neq(1), 0, 0.0d0, 0.0d0)
 
1684
      go to 700
 
1685
 610  call xerrwv('lsodi--  mu(=i1) illegal.. .lt. 0 or .ge. neq(=i2)',
 
1686
     1   50, 10, 0, 2, mu, neq(1), 0, 0.0d0, 0.0d0)
 
1687
      go to 700
 
1688
 611  call xerrwv('lsodi--  maxord (=i1) .lt. 0  ',
 
1689
     1   30, 11, 0, 1, maxord, 0, 0, 0.0d0, 0.0d0)
 
1690
      go to 700
 
1691
 612  call xerrwv('lsodi--  mxstep (=i1) .lt. 0  ',
 
1692
     1   30, 12, 0, 1, mxstep, 0, 0, 0.0d0, 0.0d0)
 
1693
      go to 700
 
1694
 613  call xerrwv('lsodi--  mxhnil (=i1) .lt. 0  ',
 
1695
     1   30, 13, 0, 1, mxhnil, 0, 0, 0.0d0, 0.0d0)
 
1696
      go to 700
 
1697
 614  call xerrwv('lsodi--  tout (=r1) behind t (=r2)      ',
 
1698
     1   40, 14, 0, 0, 0, 0, 2, tout, t)
 
1699
      call xerrwv('      integration direction is given by h0 (=r1)  ',
 
1700
     1   50, 14, 0, 0, 0, 0, 1, h0, 0.0d0)
 
1701
      go to 700
 
1702
 615  call xerrwv('lsodi--  hmax (=r1) .lt. 0.0  ',
 
1703
     1   30, 15, 0, 0, 0, 0, 1, hmax, 0.0d0)
 
1704
      go to 700
 
1705
 616  call xerrwv('lsodi--  hmin (=r1) .lt. 0.0  ',
 
1706
     1   30, 16, 0, 0, 0, 0, 1, hmin, 0.0d0)
 
1707
      go to 700
 
1708
 617  call xerrwv(
 
1709
     1  'lsodi--  rwork length needed, lenrw (=i1), exceeds lrw (=i2)',
 
1710
     1   60, 17, 0, 2, lenrw, lrw, 0, 0.0d0, 0.0d0)
 
1711
      go to 700
 
1712
 618  call xerrwv(
 
1713
     1  'lsodi--  iwork length needed, leniw (=i1), exceeds liw (=i2)',
 
1714
     1   60, 18, 0, 2, leniw, liw, 0, 0.0d0, 0.0d0)
 
1715
      go to 700
 
1716
 619  call xerrwv('lsodi--  rtol(=i1) is r1 .lt. 0.0       ',
 
1717
     1   40, 19, 0, 1, i, 0, 1, rtoli, 0.0d0)
 
1718
      go to 700
 
1719
 620  call xerrwv('lsodi--  atol(=i1) is r1 .lt. 0.0       ',
 
1720
     1   40, 20, 0, 1, i, 0, 1, atoli, 0.0d0)
 
1721
      go to 700
 
1722
 621  ewti = rwork(lewt+i-1)
 
1723
      call xerrwv('lsodi--  ewt(=i1) is r1 .le. 0.0        ',
 
1724
     1   40, 21, 0, 1, i, 0, 1, ewti, 0.0d0)
 
1725
      go to 700
 
1726
 622  call xerrwv(
 
1727
     1  'lsodi--  tout (=r1) too close to t(=r2) to start integration',
 
1728
     1   60, 22, 0, 0, 0, 0, 2, tout, t)
 
1729
      go to 700
 
1730
 623  call xerrwv(
 
1731
     1  'lsodi--  itask = i1 and tout (=r1) behind tcur - hu (= r2)  ',
 
1732
     1   60, 23, 0, 1, itask, 0, 2, tout, tp)
 
1733
      go to 700
 
1734
 624  call xerrwv(
 
1735
     1  'lsodi--  itask = 4 or 5 and tcrit (=r1) behind tcur (=r2)   ',
 
1736
     1   60, 24, 0, 0, 0, 0, 2, tcrit, tn)
 
1737
      go to 700
 
1738
 625  call xerrwv(
 
1739
     1  'lsodi--  itask = 4 or 5 and tcrit (=r1) behind tout (=r2)   ',
 
1740
     1   60, 25, 0, 0, 0, 0, 2, tcrit, tout)
 
1741
      go to 700
 
1742
 626  call xerrwv('lsodi--  at start of problem, too much accuracy   ',
 
1743
     1   50, 26, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1744
      call xerrwv(
 
1745
     1  '      requested for precision of machine..  see tolsf (=r1) ',
 
1746
     1   60, 26, 0, 0, 0, 0, 1, tolsf, 0.0d0)
 
1747
      rwork(14) = tolsf
 
1748
      go to 700
 
1749
 627  call xerrwv('lsodi--  trouble from intdy. itask = i1, tout = r1',
 
1750
     1   50, 27, 0, 1, itask, 0, 1, tout, 0.0d0)
 
1751
c
 
1752
 700  if (illin .eq. 5) go to 710
 
1753
      illin = illin + 1
 
1754
      istate = -3
 
1755
      return
 
1756
 710  call xerrwv('lsodi--  repeated occurrences of illegal input    ',
 
1757
     1   50, 302, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1758
c
 
1759
 800  call xerrwv('lsodi--  run aborted.. apparent infinite loop     ',
 
1760
     1   50, 303, 2, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1761
      return
 
1762
c----------------------- end of subroutine lsodi -----------------------
 
1763
      end