subroutine get_unit ( iunit ) !*****************************************************************************80 ! !! GET_UNIT returns a free FORTRAN unit number. ! ! Discussion: ! ! A "free" FORTRAN unit number is a value between 1 and 99 which ! is not currently associated with an I/O device. A free FORTRAN unit ! number is needed in order to open a file with the OPEN command. ! ! If IUNIT = 0, then no free FORTRAN unit could be found, although ! all 99 units were checked (except for units 5, 6 and 9, which ! are commonly reserved for console I/O). ! ! Otherwise, IUNIT is a value between 1 and 99, representing a ! free FORTRAN unit. Note that GET_UNIT assumes that units 5 and 6 ! are special, and will never return those values. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 26 October 2008 ! ! Author: ! ! John Burkardt ! ! Parameters: ! ! Output, integer IUNIT, the free unit number. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer i integer ios integer iunit logical lopen iunit = 0 do i = 1, 99 if ( i /= 5 .and. i /= 6 .and. i /= 9 ) then inquire ( unit = i, opened = lopen, iostat = ios ) if ( ios == 0 ) then if ( .not. lopen ) then iunit = i return end if end if end if end do return end subroutine predator_prey_conserved ( n, rf, h ) !*****************************************************************************80 ! !! predator_prey_conserved evaluates a conserved quantity. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 27 April 2020 ! ! Author: ! ! John Burkardt ! ! Reference: ! ! George Lindfield, John Penny, ! Numerical Methods Using MATLAB, ! Second Edition, ! Prentice Hall, 1999, ! ISBN: 0-13-012641-1, ! LC: QA297.P45. ! ! Input: ! ! integer N: the number of sets of variables. ! ! real ( kind = rk ) RF(N,2): the current solution variables, rabbits and foxes. ! ! Output: ! ! real ( kind = rk ) H(N): the value of the conserved quantity. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) integer n real ( kind = rk ) alpha real ( kind = rk ) beta real ( kind = rk ) delta real ( kind = rk ) gamma real ( kind = rk ) h(n) real ( kind = rk ) rf(n,2) call predator_prey_parameters ( alpha, beta, gamma, delta ) h(1:n) = delta * rf(1:n,1) - gamma * log ( rf(1:n,1) ) & + beta * rf(1:n,2) - alpha * log ( rf(1:n,2) ) return end subroutine predator_prey_deriv ( t, rf, drfdt ) !*****************************************************************************80 ! !! predator_prey_deriv evaluates the right hand side of the system. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 29 October 2020 ! ! Author: ! ! John Burkardt ! ! Input: ! ! real ( kind = rk ) T, the current time. ! ! real ( kind = rk ) RF(2), the current solution variables, rabbits and foxes. ! ! Output: ! ! real ( kind = rk ) DRFDT(2), the right hand side of the 2 ODE's. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) real ( kind = rk ) alpha real ( kind = rk ) beta real ( kind = rk ) delta real ( kind = rk ) drfdt(2) real ( kind = rk ) gamma real ( kind = rk ) rf(2) real ( kind = rk ) t call predator_prey_parameters ( alpha, beta, gamma, delta ) call r8_fake_use ( t ) drfdt(1) = alpha * rf(1) - beta * rf(1) * rf(2) drfdt(2) = - gamma * rf(2) + delta * rf(1) * rf(2) return end subroutine predator_prey_parameters ( alpha, beta, gamma, delta ) !*****************************************************************************80 ! !! predator_prey_parameters returns predator prey parameters. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 29 October 2020 ! ! Author: ! ! John Burkardt ! ! Output: ! ! real ( kind = rk ) ALPHA, BETA, GAMMA, DELTA: the parameter values. ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) real ( kind = rk ) alpha real ( kind = rk ) beta real ( kind = rk ) delta real ( kind = rk ) gamma alpha = 2.0D+00 beta = 0.001D+00 gamma = 10.0D+00 delta = 0.002D+00 return end subroutine r8_fake_use ( x ) !*****************************************************************************80 ! !! r8_fake_use pretends to use a variable. ! ! Discussion: ! ! Some compilers will issue a warning if a variable is unused. ! Sometimes there's a good reason to include a variable in a program, ! but not to use it. Calling this function with that variable as ! the argument will shut the compiler up. ! ! Licensing: ! ! This code is distributed under the MIT license. ! ! Modified: ! ! 21 April 2020 ! ! Author: ! ! John Burkardt ! ! Input: ! ! real ( kind = rk ) X, the variable to be "used". ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) real ( kind = rk ) x if ( x /= x ) then write ( *, '(a)' ) ' r8_fake_use: variable is NAN.' end if 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: ! ! 18 May 2013 ! ! Author: ! ! John Burkardt ! implicit none integer, parameter :: rk = kind ( 1.0D+00 ) 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