! Program Example from "Essential Fortran 90 & 95" by Loren P. Meissner
! Copyright 1996. Copying for sale requires permission from the author.
! Otherwise, distribution is permitted if these three lines are included.

! Example 4.11. Predator-prey population dynamics.
  program E11
    implicit none
    real, parameter :: RB = 3.0, RD = 0.002, FB = 0.0006, FD = 0.5
    real :: R, F, T, Delta_R, Delta_F, Delta_T, T_Out, T_Max
    integer :: N, Loop, N_Out
! start program E11
    R = 1000
    F = 200
    Delta_T = 0.001
    T_Out = 0.25
    T_Max = 4.0
    N = nint( T_Max / Delta_T )
    N_Out = nint( T_Out / Delta_T )
    do Loop = 0, N
      T = Loop * Delta_T
      Delta_R = (RB - RD * F) * R * Delta_T
      Delta_F = (FB * R - FD) * F * Delta_T
      if (modulo( Loop, N_Out ) == 0) then
        write (unit = *, fmt = *) T, R, F, Delta_R, Delta_F
      end if
      R = R + Delta_R
      F = F + Delta_F
      if ((R <= 0.0) .or. (F <= 0.0)) then
        exit  ! No more rabbits or no more foxes.
      end if
    end do
    stop
  end program E11
