@@ -48,7 +48,7 @@ subroutine jacobian_sub(n,y,df)
4848 subroutine output_sub (nr ,xold ,x ,y ,iha ,qa ,irtrn )
4949 import wp
5050 integer , intent (in ) :: nr
51- ! ! Number of successful steps that have been taken
51+ ! ! Number of the current grid point, starting at 1 for the initial value
5252 real (wp), intent (in ) :: xold
5353 ! ! Previous value of the independent variable
5454 real (wp), intent (in ) :: x
@@ -106,7 +106,7 @@ subroutine stiff3_auto(n,fun,x,y,xend,jac,h0,eps,w,solout,stats,hmax)
106106 procedure (output_sub), optional :: solout
107107 ! ! User supplied subprogram for output.
108108 integer , intent (out ), optional :: stats(6 )
109- ! ! Statistics array with `[nfev, njev, nlu, nacc, nrej , nsol]`.
109+ ! ! Statistics array with `[nacc, nrej, nfev, njev, nlu , nsol]`.
110110 real (wp), intent (in ), optional :: hmax
111111 ! ! Maximum absolute half-step size. If absent or zero, defaults to
112112 ! ! `abs(xend - x)`.
@@ -154,7 +154,7 @@ subroutine stiff3_work(n,fun,x,y,xend,jac,h0,eps,w,rwork,iwork,solout,stats,hmax
154154 procedure (output_sub), optional :: solout
155155 ! ! User supplied subprogram for output.
156156 integer , intent (out ), optional :: stats(6 )
157- ! ! Statistics array with `[nfev, njev, nlu, nacc, nrej , nsol]`.
157+ ! ! Statistics array with `[nacc, nrej, nfev, njev, nlu , nsol]`.
158158 real (wp), intent (in ), optional :: hmax
159159 ! ! Maximum absolute half-step size. If absent or zero, defaults to
160160 ! ! `abs(xend - x)`.
@@ -194,15 +194,14 @@ subroutine stiff3_core(n,fun,x,y,xend,jac,h0,eps,w, &
194194 integer , intent (out ), optional :: stats(6 )
195195 real (wp), intent (in ), optional :: hmax
196196
197- integer :: icon, iha, i, j, nr, irtrn
197+ integer :: icon, iha, i, j, irtrn
198198 integer :: nfev, njev, nlu, nacc, nrej, nsol
199199 real (wp) :: x_current, xold, h, e, es, q, qa, hmax_used
200200 logical :: have_f
201201
202202 ! icon = 0 except for last step which ends exactly at x1
203203 icon = 0
204204
205- nr = 0
206205 x_current = x
207206 if (present (hmax)) then
208207 if (hmax < 0.0_wp ) error stop ' stiff3: hmax must be a non-negative real value'
@@ -223,6 +222,16 @@ subroutine stiff3_core(n,fun,x,y,xend,jac,h0,eps,w, &
223222 nsol = 0
224223 have_f = .false.
225224
225+ if (present (solout)) then
226+ irtrn = 0
227+ call solout(1 ,x_current,x_current,y,0 ,0.0_wp ,irtrn)
228+ if (irtrn < 0 ) then
229+ h0 = h
230+ if (present (stats)) stats = [nacc, nrej, nfev, njev, nlu, nsol]
231+ return
232+ end if
233+ end if
234+
226235 outer: do
227236
228237 ! last step - or first step longer than interval
@@ -342,14 +351,13 @@ subroutine stiff3_core(n,fun,x,y,xend,jac,h0,eps,w, &
342351
343352 ! perform output if appropriate
344353
345- nr = nr + 1
346354 nacc = nacc + 1
347355 if (present (solout)) then
348356 irtrn = 0
349- call solout(nr ,xold,x_current,y,iha,qa,irtrn)
357+ call solout(nacc +1 ,xold,x_current,y,iha,qa,irtrn)
350358 if (irtrn < 0 ) then
351359 h0 = h
352- if (present (stats)) stats = [nfev, njev, nlu, nacc, nrej , nsol]
360+ if (present (stats)) stats = [nacc, nrej, nfev, njev, nlu , nsol]
353361 return
354362 end if
355363 end if
@@ -358,7 +366,7 @@ subroutine stiff3_core(n,fun,x,y,xend,jac,h0,eps,w, &
358366
359367 if (icon == 1 ) then
360368 h0 = h
361- if (present (stats)) stats = [nfev, njev, nlu, nacc, nrej , nsol]
369+ if (present (stats)) stats = [nacc, nrej, nfev, njev, nlu , nsol]
362370 return
363371 end if
364372
0 commit comments