Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.mrao.cam.ac.uk/~rachael/compphys/examples/exercise1.f90
Дата изменения: Tue Oct 11 19:37:46 2005
Дата индексирования: Tue Oct 2 11:40:10 2012
Кодировка:

Поисковые слова: спрайты
! Example solution to suggested exercise 1
! from self-study guide 2

program exercise1
implicit none

! define constants
real, parameter :: g = 9.8
real, parameter :: pi = 3.1415927

integer :: n, i
real :: a, u, delt
real :: ttot, t, x, y

! Read values for u and a from terminal
write(*,*) 'Enter initial speed u:'
read(*,*) u
write(*,*) 'Enter initial angle a in degrees:'
read(*,*) a

! convert angle to radians
a = a * pi / 180.0

! Calculate time of flight
ttot = 2.0 * u * sin(a) / g
write(*,*) 'Time of flight: ',ttot

! Read value for time interval from terminal
write(*,*) 'Enter time interval:'
read(*,*) delt
if (delt <= 0.0) stop 'Invalid time interval!'

! Calculate number of time intervals
n = ttot / delt

! Open output file
open(9,file='projectile.dat')

! Loop over time intervals
do i = 0, n

! Calculate position at this time
t = i * delt
x = u * cos(a) * t
y = u * sin(a) * t - 0.5 * g * t * t

! Output position to file
write(9,*) x, y

end do

! Close output file
close(9)

end program exercise1