2.3 Exercise 1: The Decay Problem
13
(not equal). If there is only one line in an IF-statement, the “ELSE” and closing
“END IF” statements can be dropped, such as in the following example:
DO k = nx+1,0,−1
eta(k) = 0.0
IF(k > 50) eta(k) = 1.0
END DO
Files for output can be opened with the statement:
OPEN(10, fil = ‘Ex1a.txt’, form = ‘formatted’, status = ‘unknown’)
The f rst entry (10) is a reference unit number for subsequent WRITE or READ
statements. The “file entry specifie the desired filename The “form” entry specifie whether to have ASCII numbers or binary numbers as output. I chose ASCII
output. The status entry “unknown” implies new creation of a fil if this does not
exist, otherwise an existing f le will be overwritten. Be careful not to overwrite file
that might be needed in the future. Other status options are “new” or “old”.
Output of data is done via “WRITE” statements such as
WRITE(10,
∗
) G
where the unit number (10 here) refers to a f le opened before, and the “*” symbol
creates a standard format. Note that the unit number 6 is reserved for output to the
screen as in our firs FORTRAN code. Similarly, “READ(5,*)” reads input from the
keyboard. Several outputs at once can be produced with:
WRITE(10,
∗
) eta(10), eta(20), eta(30)
Doing this repeatedly, there will be three columns of data. Output of an entire
row of an array is done with:
WRITE(10,
∗
) (eta(k), k = 1,nx)
Files no longer needed for output should be closed with the statement:
CLOSE(10)
2.3 Exercise 1: The Decay Problem
2.3.1 Aim
The aim of this exercise is to predict the decay of a substance according to (2.1)
using a FORTRAN code based on either the explicit or the implicit scheme.
Précédent

- 27/185

Suivant