program main !*****************************************************************************80 ! !! three_body_ode_test() tests three_body_ode(). ! ! Discussion: ! ! three_body_ode() uses RKF45 as an integrator for the simple version ! of the three-body problem. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 03 April 2011 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) call timestamp ( ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'three_body_ode_test():' write ( *, '(a)' ) ' Fortran90 version' write ( *, '(a)' ) ' Simulate the behavior of three bodies which are' write ( *, '(a)' ) ' constrained to lie in a plane, moving under the' write ( *, '(a)' ) ' influence of gravity.' write ( *, '(a)' ) ' ' write ( *, '(a)' ) ' Use RKF45 for the ODE integrator.' call three_body_ode_run ( ) ! ! Terminate. ! write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'three_body_ode_test' write ( *, '(a)' ) ' Normal end of execution.' write ( *, '(a)' ) ' ' call timestamp ( ) stop 0 end subroutine three_body_ode_run ( ) !*****************************************************************************80 ! !! three_body_ode_run() runs the simple three body ODE system. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 04 April 2011 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer, parameter :: neqn = 12 integer, parameter :: step_num = 630 real ( kind = rk ) abserr integer flag real ( kind = rk ) m0 real ( kind = rk ) m1 real ( kind = rk ) m2 real ( kind = rk ) relerr external three_body_deriv integer step real ( kind = rk ) t character ( len = 80 ) :: t_filename = 'three_body_ode_t.txt' real ( kind = rk ) t_out real ( kind = rk ) t_start real ( kind = rk ) t_stop real ( kind = rk ) ts(0:step_num) real ( kind = rk ) y(neqn) character ( len = 80 ) :: y_filename = 'three_body_ode_y.txt' real ( kind = rk ) yp(neqn) real ( kind = rk ) ys(neqn,0:step_num) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'three_body_ode_run():' write ( *, '(a)' ) ' Simulate the planar three-body problem as an ODE system' write ( *, '(a)' ) ' using RKF45 for the ODE integration.' m0 = 5.0D+00 m1 = 3.0D+00 m2 = 4.0D+00 abserr = 1.0D-10 relerr = 1.0D-10 flag = 1 t_start = 0.0D+00 t_stop = 63.0D+00 t = 0.0D+00 t_out = 0.0D+00 y(1:neqn) = (/ 1.0D+00, -1.0D+00, 0.0D+00, 0.0D+00, & 1.0D+00, 3.0D+00, 0.0D+00, 0.0D+00, & -2.0D+00, -1.0D+00, 0.0D+00, 0.0D+00 /) call three_body_deriv ( t, y, yp ) ys(1:neqn,0) = y(1:neqn) ts(0) = t do step = 1, step_num t = ( real ( step_num - step + 1, kind = rk ) * t_start & + real ( step - 1, kind = rk ) * t_stop ) & / real ( step_num, kind = rk ) t_out = ( real ( step_num - step, kind = rk ) * t_start & + real ( step, kind = rk ) * t_stop ) & / real ( step_num, kind = rk ) call rkf45 ( three_body_deriv, neqn, y, yp, t, t_out, relerr, abserr, flag ) if ( abs ( flag ) /= 2 ) then write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'three_body_ode_run(): Warning!' write ( *, '(a,i4,a,g14.6)' ) ' Output value of FLAG = ', flag, & ' at T_OUT = ', t_out end if ys(1:neqn,step) = y(1:neqn) ts(step) = t_out end do call r8mat_write ( t_filename, 1, step_num + 1, ts ) call r8mat_write ( y_filename, neqn, step_num + 1, ys ) write ( *, '(a)' ) ' ' write ( *, '(a)' ) 'three_body_ode_run():' write ( *, '(a)' ) ' Time data written to "' // trim ( t_filename ) // '".' write ( *, '(a)' ) ' Solution data written to "' // trim ( y_filename ) // '".' return end subroutine timestamp ( ) !*****************************************************************************80 ! !! timestamp() prints the current YMDHMS date as a time stamp. ! ! Example: ! ! 31 May 2001 9:45:54.872 AM ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 15 August 2021 ! ! Author: ! ! John Burkardt ! implicit none character ( len = 8 ) ampm integer d integer h integer m integer mm character ( len = 9 ), parameter, dimension(12) :: month = (/ & 'January ', 'February ', 'March ', 'April ', & 'May ', 'June ', 'July ', 'August ', & 'September', 'October ', 'November ', 'December ' /) integer n integer s integer values(8) integer y call date_and_time ( values = values ) y = values(1) m = values(2) d = values(3) h = values(5) n = values(6) s = values(7) mm = values(8) if ( h < 12 ) then ampm = 'AM' else if ( h == 12 ) then if ( n == 0 .and. s == 0 ) then ampm = 'Noon' else ampm = 'PM' end if else h = h - 12 if ( h < 12 ) then ampm = 'PM' else if ( h == 12 ) then if ( n == 0 .and. s == 0 ) then ampm = 'Midnight' else ampm = 'AM' end if end if end if write ( *, '(i2.2,1x,a,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)' ) & d, trim ( month(m) ), y, h, ':', n, ':', s, '.', mm, trim ( ampm ) return end