Ok, I'm new on programming world. Be patient please.
I'm reading introduction to FORTRAN95 by this website: http://www.oceanmodelling.com/Tutorials/FORTRAN_1_3.html
So, on the DO LOOPS examples they shown this:
PROGRAM Do_Loop_Examples
IMPLICIT NONE
! Declaration section
INTEGER, PARAMETER :: ntot = 100 ! total number of counts
INTEGER, PARAMETER :: nx = 100 ! channel dimension
REAL :: h(nx) ! declaration of a channel with 100 elements
REAL :: dt ! time step in seconds
REAL :: time, time2 ! time counters
INTEGER :: n, k ! integer counters
! Assignment of parameter values
dt = 60.0 ! time step is set to 60 seconds
!=========
! Example 1: A simple time counter
WRITE(6,) 'EXAMPLE 1: A SIMPLE TIME COUNTER'
PAUSE
DO n = 1, ntot ! change n from 1 to ntot at steps of 1
! DO n = ntot, 1, -1 ! this would count backwards from ntot to 1 at steps of -1
! DO n = 1, ntot, 2 ! this would count at steps of 2 ⇒ n = 1,3,5,6,etc
time = REAL(n)dt ! time in seconds
WRITE(6,) time,' secs; ', time/60.0,' min; ', time/3600.0,' hrs'
! PAUSE ! enable this if you want to see each step
END DO ! this is the end reference of the DO loop
!=========
! Example 2: Illustration of round-off errors
WRITE(6,) 'EXAMPLE 2: ILLUSTRATION OF ROUND_OFF ERRORS'
PAUSE
time = 0.0
time2 = 0.0
DO n = 1,102460 ! total number can be expressed as basic calculations
time = REAL(n)dt/(24.03600.0) ! exact time in days
time2 = time2+dt/(24.03600.0) ! time calculated from time increments
END DO
WRITE(6,)'Time error is ', (time-time2)24.03600.0,' seconds'
!=========
! Example 3: Configuration of a channel with depths decreasing from 200 metres to
! 100 metres over the channel length
WRITE(6,*) 'EXAMPLE 3: ASSIGMENT OF CHANNEL DEPTHS'
PAUSE
DO k = 1, nx
h(k) = 200.0-REAL(k-1)/REAL(nx-1)100.0
END DO
WRITE(6,) (h(k),k=1,nx,10) ! simplified form of DO loop for WRITE statements
END PROGRAM Do_Loop_Examples
I have some questions:
In the EXAMPLE 2:
Why he define time and time 2 equal to 0.0?
I dont understood the time2 on the 'DO'. time2 = time2+dt/(24.0*3600.0) ! time calculated from time increments
What increments? 'time' is a matrix calculated by the loop in 'n', but time2 have no loop, why (tempo-tempo2)24.03600.0 is just the number 114.862? In the finish of the DO, the error is (tempo-tempo2)24.03600.0 .. WHY?
Someone's patient can help me please?? :?: