89 subroutine print_solution(status, solution, filename_o, separator_o, fmt_w_o, fmt_d_o, fmt_e_o, start_o, end_o, step_o, &
90 & prt_titles_o, t_min_o, t_max_o, tag_o, append_o)
91 use,
intrinsic :: iso_fortran_env, only: output_unit
95 integer,
intent(out) :: status
96 real(kind=
rk),
intent(in) :: solution(:,:)
97 character(len=*),
intent(in),
optional :: filename_o, separator_o
98 integer,
intent(in),
optional :: fmt_e_o, fmt_d_o, fmt_w_o, start_o, end_o, step_o, tag_o
99 real(kind=
rk),
intent(in),
optional :: t_min_o, t_max_o
100 logical,
intent(in),
optional :: prt_titles_o, append_o
102 integer :: fmt_e, fmt_d, fmt_w, start_idx, end_idx, step, y_dim, sol_y_idx, tag
103 logical :: prt_titles, append
104 integer :: i, num_int, num_real, out_io_stat, out_io_unit
105 character(len=:),
allocatable :: fmt, separator, access_mode, fmt_r_str, fmt_i_str, fmt_a_str
106 character(len=512) :: tmp_str
109 if (
present(append_o)) append = append_o
110 prt_titles = .not. append
111 if (
present(prt_titles_o)) prt_titles = prt_titles_o
113 if (
present(tag_o)) tag = tag_o
115 if (
present(step_o)) step = step_o
117 if (
present(fmt_d_o)) fmt_d = fmt_d_o
119 if (
present(fmt_e_o)) fmt_e = fmt_e_o
121 if (
present(fmt_w_o)) fmt_w = fmt_w_o
124 if (
present(start_o)) start_idx = start_o
125 end_idx =
size(solution, 2)
126 if (
present(end_o)) end_idx = min(end_o,
size(solution, 2))
127 if (
present(separator_o))
then
128 separator = separator_o
137 y_dim = (
size(solution, 1) - 1) / 2
142 write(tmp_str,
'("f",i0,".",i0)') fmt_w, fmt_d
143 fmt_r_str = trim(tmp_str)
146 write(tmp_str,
'("e",i0,".",i0)') fmt_w, fmt_d
147 fmt_r_str = trim(tmp_str)
149 write(tmp_str,
'("e",i0)') fmt_e
150 fmt_r_str = fmt_r_str // trim(tmp_str)
153 write(tmp_str,
'("i",i0)') fmt_w
154 fmt_i_str = trim(tmp_str)
158 write(tmp_str,
'("a",i0)') fmt_w
159 fmt_a_str = trim(tmp_str)
162 num_real =
size(solution, 1)
171 access_mode =
'APPEND'
173 access_mode =
'SEQUENTIAL'
175 if (
present(filename_o))
then
176 open(newunit=out_io_unit, file=filename_o, form=
'formatted', action=
'write', access=access_mode, iostat=out_io_stat)
177 if (out_io_stat /= 0)
then
182 out_io_unit = output_unit
186 fmt =
"(" // fmt_a_str //
")"
188 write(out_io_unit, fmt=fmt, advance=
"no")
"tag"
189 write(out_io_unit, fmt=
'(a)', advance=
"no") separator
191 write(out_io_unit, fmt=fmt, advance=
"no")
"i"
192 write(out_io_unit, fmt=
'(a)', advance=
"no") separator
193 write(out_io_unit, fmt=fmt, advance=
"no")
"t"
195 write(out_io_unit, fmt=
'(a)', advance=
"no") separator
196 write(tmp_str, fmt=
'("y",i0)') i
197 write(out_io_unit, fmt=fmt, advance=
"no") trim(tmp_str)
200 write(out_io_unit, fmt=
'(a)', advance=
"no") separator
201 write(tmp_str, fmt=
'("dy",i0)') i
202 write(out_io_unit, fmt=fmt, advance=
"no") trim(tmp_str)
204 write(out_io_unit, fmt=
'()')
207 if (tag>=0) fmt = fmt // fmt_i_str //
',"' // separator //
'",'
208 fmt = fmt // fmt_i_str
209 fmt = fmt // repeat(
',"' // separator //
'",' // fmt_r_str, num_real)
211 do i=start_idx,end_idx,step
212 if (
present(t_min_o))
then
213 if (solution(1, i) < t_min_o) cycle
215 if (
present(t_max_o))
then
216 if (solution(1, i) > t_max_o) cycle
219 write (out_io_unit, fmt=fmt) i, solution(1, i), solution(sol_y_idx:(sol_y_idx+2*y_dim-1), i)
221 write (out_io_unit, fmt=fmt) tag, i, solution(1, i), solution(sol_y_idx:(sol_y_idx+2*y_dim-1), i)
225 if (
present(filename_o))
then
226 close(unit=out_io_unit, status=
'keep', iostat=out_io_stat)
227 if (out_io_stat /= 0)
then
252 subroutine print_istats(status, istats, idxs_to_prt_o, filename_o, fmt_w_o, prt_zeros_o)
253 use,
intrinsic :: iso_fortran_env, only: output_unit
257 integer,
intent(out) :: status
259 integer,
intent(in),
optional :: idxs_to_prt_o(:), fmt_w_o
260 logical,
intent(in),
optional :: prt_zeros_o
261 character(len=*),
intent(in),
optional :: filename_o
263 integer,
allocatable :: idxs_to_prt(:)
264 integer :: out_io_stat, out_io_unit, i, fmt_w
266 character(len=32) :: tmp_str1, tmp_str2
269 if (
present(prt_zeros_o)) prt_zeros = prt_zeros_o
271 if (
present(idxs_to_prt_o)) idxs_to_prt = idxs_to_prt_o
273 if (
present(fmt_w_o)) fmt_w = fmt_w_o
275 if (
present(filename_o))
then
276 open(newunit=out_io_unit, file=filename_o, form=
'formatted', action=
'write', iostat=out_io_stat)
277 if (out_io_stat /= 0)
then
282 out_io_unit = output_unit
285 write(out_io_unit, fmt=
'(a25)')
"ISTATS Contents"
286 write(tmp_str1,
'("(a",i0,",i",i0,")")')
istats_str_lng + 7 + 2 + 3 + 2 + 1, fmt_w
287 do i=1,
size(idxs_to_prt)
289 if ((istats(idxs_to_prt(i)) > 0) .or. prt_zeros)
then
290 write(tmp_str2,
'(i2.2)') i
291 write (out_io_unit, fmt=tmp_str1) (trim(
istats_strs(idxs_to_prt(i))) //
": istats(" // trim(tmp_str2) //
"): "), istats(idxs_to_prt(i))
296 if (
present(filename_o))
then
297 close(unit=out_io_unit, status=
'keep', iostat=out_io_stat)
298 if (out_io_stat /= 0)
then
330 subroutine analyze_solution(status, solution, filename_o, start_o, end_o, y_delta_len_idxs_o, fmt_w_o, fmt_d_o, fmt_e_o)
331 use,
intrinsic :: iso_fortran_env, only: output_unit
335 integer,
intent(out) :: status
336 real(kind=
rk),
intent(in) :: solution(:,:)
337 character(len=*),
intent(in),
optional :: filename_o
338 integer,
intent(in),
optional :: y_delta_len_idxs_o(:), start_o, end_o, fmt_e_o, fmt_d_o, fmt_w_o
340 integer :: y_dim, end_idx, start_idx, fmt_e, fmt_d, fmt_w, i, out_io_stat, out_io_unit
341 real(kind=
rk) :: t_max, t_min, t_delta_max, t_delta_min, y_delta_len_max, y_delta_len_min
342 real(kind=
rk),
allocatable :: dy_max(:), dy_min(:), y_max(:), y_min(:), y_delta_max(:), y_delta_min(:)
343 character(len=32) :: tmp_str
344 character(len=:),
allocatable :: fmt, fmt_r_str, fmt_i_str
347 if (
present(fmt_d_o)) fmt_d = fmt_d_o
349 if (
present(fmt_e_o)) fmt_e = fmt_e_o
351 if (
present(fmt_w_o)) fmt_w = fmt_w_o
353 if (
present(start_o)) start_idx = start_o
354 end_idx =
size(solution, 2)
355 if (
present(end_o)) end_idx = min(end_o,
size(solution, 2))
359 write(tmp_str,
'("f",i0,".",i0)') fmt_w, fmt_d
360 fmt_r_str = trim(tmp_str)
363 write(tmp_str,
'("e",i0,".",i0)') fmt_w, fmt_d
364 fmt_r_str = trim(tmp_str)
366 write(tmp_str,
'("e",i0)') fmt_e
367 fmt_r_str = fmt_r_str // trim(tmp_str)
370 write(tmp_str,
'("i",i0)') fmt_w
371 fmt_i_str = trim(tmp_str)
373 y_dim = (
size(solution, 1) - 1) / 2
374 if(end_idx - start_idx > 1)
then
375 t_delta_max = abs(solution(1, start_idx+1) - solution(1, start_idx))
376 t_delta_min = t_delta_max
377 if (
present(y_delta_len_idxs_o))
then
378 y_delta_len_max = norm2(solution(y_delta_len_idxs_o + 2 - 1, start_idx+1) - solution(y_delta_len_idxs_o + 2 - 1, start_idx))
380 y_delta_len_max = norm2(solution(2:(2+y_dim-1), start_idx+1) - solution(2:(2+y_dim-1), start_idx))
382 y_delta_len_min = y_delta_len_max
383 y_delta_max = abs(solution(2:(2+y_dim-1), start_idx+1) - solution(2:(2+y_dim-1), start_idx))
384 y_delta_min = y_delta_max
386 y_max = solution(2:(2+y_dim-1), start_idx)
388 dy_max = solution((2+y_dim):(2+2*y_dim-1), start_idx)
390 t_max = solution(1, start_idx)
392 do i=(start_idx+1),end_idx
393 y_max = max(y_max, solution(2:(2+y_dim-1), i))
394 y_min = min(y_min, solution(2:(2+y_dim-1), i))
395 dy_max = max(dy_max, solution((2+y_dim):(2+2*y_dim-1), i))
396 dy_min = min(dy_min, solution((2+y_dim):(2+2*y_dim-1), i))
397 t_max = max(t_max, solution(1, i))
398 t_min = min(t_min, solution(1, i))
399 t_delta_max = max(t_delta_max, abs(solution(1, i) - solution(1, i-1)))
400 t_delta_min = min(t_delta_min, abs(solution(1, i) - solution(1, i-1)))
401 if (
present(y_delta_len_idxs_o))
then
402 y_delta_len_max = max(y_delta_len_max, norm2(solution(y_delta_len_idxs_o + 2 - 1, i) - solution(y_delta_len_idxs_o + 2 - 1, i-1)))
403 y_delta_len_min = min(y_delta_len_min, norm2(solution(y_delta_len_idxs_o + 2 - 1, i) - solution(y_delta_len_idxs_o + 2 - 1, i-1)))
405 y_delta_len_max = max(y_delta_len_max, norm2(solution(2:(2+y_dim-1), i) - solution(2:(2+y_dim-1), i-1)))
406 y_delta_len_min = min(y_delta_len_min, norm2(solution(2:(2+y_dim-1), i) - solution(2:(2+y_dim-1), i-1)))
408 y_delta_max = max(y_delta_max, abs(solution(2:(2+y_dim-1), i) - solution(2:(2+y_dim-1), i-1)))
409 y_delta_min = min(y_delta_min, abs(solution(2:(2+y_dim-1), i) - solution(2:(2+y_dim-1), i-1)))
412 if (
present(filename_o))
then
413 open(newunit=out_io_unit, file=filename_o, form=
'formatted', action=
'write', iostat=out_io_stat)
414 if (out_io_stat /= 0)
then
419 out_io_unit = output_unit
422 write(out_io_unit, fmt=
'(a25)')
"Solution Analysis "
423 fmt =
'(a25,' // fmt_i_str //
')'
424 write(out_io_unit, fmt=fmt)
" size 1: ",
size(solution, 1)
425 write(out_io_unit, fmt=fmt)
" size 2: ",
size(solution, 2)
426 fmt =
'(a25,*(' // fmt_r_str //
'))'
427 write(out_io_unit, fmt=fmt)
" Max y: ", y_max
428 write(out_io_unit, fmt=fmt)
" Min y: ", y_min
429 write(out_io_unit, fmt=fmt)
" Max dy: ", dy_max
430 write(out_io_unit, fmt=fmt)
" Min dy: ", dy_min
431 write(out_io_unit, fmt=fmt)
" Max t: ", t_max
432 write(out_io_unit, fmt=fmt)
" Min t: ", t_min
433 write(out_io_unit, fmt=fmt)
" Max delta t: ", t_delta_max
434 write(out_io_unit, fmt=fmt)
" Min delta t: ", t_delta_min
435 write(out_io_unit, fmt=fmt)
" Max delta y: ", y_delta_max
436 write(out_io_unit, fmt=fmt)
" Min delta y: ", y_delta_min
437 write(out_io_unit, fmt=fmt)
" Max delta y len: ", y_delta_len_max
438 write(out_io_unit, fmt=fmt)
" Min delta y len: ", y_delta_len_min
440 if (
present(filename_o))
then
441 close(unit=out_io_unit, status=
'keep', iostat=out_io_stat)
442 if (out_io_stat /= 0)
then
474 subroutine seq(status, t, from_o, to_o, step_o, max_pts_o)
478 integer,
intent(out) :: status
479 real(kind=
rk),
intent(out) :: t(:)
480 real(kind=
rk),
optional,
intent(in) :: from_o, to_o, step_o
481 integer,
optional,
intent(in) :: max_pts_o
483 integer :: n_v, i, max_pts, num_args
484 real(kind=
rk) :: from_v, to_v, step_v
487 if (
present(max_pts_o)) max_pts = min(max_pts, max_pts_o)
489 if (
present(from_o)) num_args = num_args + 1
490 if (
present(to_o)) num_args = num_args + 1
491 if (
present(step_o)) num_args = num_args + 1
492 if (num_args < 2)
then
497 if (.not. (
present(from_o)))
then
502 from_v = -step_v * n_v + to_v
503 elseif (.not. (
present(to_o)))
then
507 to_v = step_v * n_v + from_v
508 elseif (.not. (
present(step_o)))
then
513 step_v = -(-to_v + from_v) / n_v
519 if (abs((step_v * n_v) - (to_v - from_v)) >
zero_epsilon)
then
526 if (status == 0)
then
528 t(i+1) = from_v+i*step_v
586 integer,
intent(in) :: status
588 if (status <= 0)
then
590 elseif ((status >= 1) .and. (status <= 255))
then
592 elseif ((status >= 256) .and. (status <= 511))
then
594 elseif ((status >= 512) .and. (status <= 767))
then
596 elseif ((status >= 1232) .and. (status <= 1247))
then
598 elseif ((status >= 1248) .and. (status <= 1263))
then
600 elseif ((status >= 1216) .and. (status <= 1231))
then
602 elseif ((status >= 1200) .and. (status <= 1215))
then
604 elseif ((status >= 1184) .and. (status <= 1199))
then
606 elseif ((status >= 1263) .and. (status <= 1279))
then
608 elseif ((status >= 1120) .and. (status <= 1151))
then
610 elseif ((status >= 1024) .and. (status <= 1055))
then
612 elseif ((status >= 1280) .and. (status <= 1296))
then
614 elseif ((status >= 1056) .and. (status <= 1119))
then
616 elseif ((status >= 1152) .and. (status <= 1183))
then
618 elseif ((status >= 1297) .and. (status <= 1313))
then
620 elseif ((status >= 1314) .and. (status <= 1330))
then
622 elseif ((status >= 1331) .and. (status <= 1347))
then
624 elseif ((status >= 1348) .and. (status <= 1364))
then
626 elseif ((status >= 1365) .and. (status <= 1381))
then
subroutine, public print_solution(status, solution, filename_o, separator_o, fmt_w_o, fmt_d_o, fmt_e_o, start_o, end_o, step_o, prt_titles_o, t_min_o, t_max_o, tag_o, append_o)
Output an RK solution matrix.