module common public :: initial,euler,print_table integer, public, parameter :: double = 8 real (kind = double), public :: y,v,a,t,dt real (kind = double), public, parameter :: g = 9.8 contains subroutine initial() t = 0 ! initial time (sec) y = 10 ! initial height (m) v = 0 ! initial velocity a = -g print *, "time step dt =" read *, dt end subroutine initial subroutine euler() y = y + v*dt ! use velocity at beginning of interval ! following included to remind us that acceleration is constant a = -g ! y positive upward v = v + a*dt t = t + dt end subroutine euler subroutine print_table(nshow) integer, intent (in out) :: nshow if (t == 0) then print *, "number of time steps between output = " read *, nshow print "(t8,a,t24,a,t34,a,t48,a)", "time","y","velocity","accel" print *, "" end if print "(4f13.4)", t,y,v,a end subroutine print_table end module common program free_fall ! no air resistance use common integer :: nshow,counter call initial() ! initial conditions and parameters call print_table(nshow) ! print initial conditions counter = 0 iterate: do if (y <= 0) then exit iterate end if call euler() counter = counter + 1 if (modulo(counter,nshow) == 0) then call print_table(nshow) end if end do iterate call print_table(nshow) ! print values at surface end program free_fall