The READ statement has the following forms:
READ(*,*) var1, var2, ..., varn READ(*,*)
The first form starts with READ(*,*), followed by a list of variable names, separated by commas. The computer will read values from the keyboard successively and puts the value into the variables. The second form only has READ(*,*), which has a special meaning.
INTEGER :: Factor, N REAL :: Multiple, tolerance READ(*,*) Factor, N, Multiple, tolerance
CHARACTER(LEN=10) :: Title REAL :: Height, Length, Area READ(*,*) Title, Height, Length, Area
Preparing input data is simple. Here are the rules:
For the following READ
The input data may look like the following:CHARACTER(LEN=5) :: Name REAL :: height, length INTEGER :: count, MaxLength READ(*,*) Name, height, count, length, MaxLength
Note that all input data are on the same line and separated with spaces. After reading in this line, the contents of the variables are"Smith" 100.0 25 123.579 10000
Name "Smith" height 100.0 count 25 length 123.579 MaxLength 100000
"Smith" 100.0 25 123.579 10000
If the above READ statements are used to read the following input lines,INTEGER :: I, J, K, L, M, N READ(*,*) I, J READ(*,*) K, L, M READ(*,*) N
then I, J, K, L, M and N will receive 100, 200, 300, 400, 500 and 600, respectively.100 200 300 400 500 600
If the input lines areINTEGER :: I, J, K, L, M, N READ(*,*) I, J, K READ(*,*) L, M, N
Variables I, J and K receive 100, 200 and 300, respectively. Since the second READ starts with a new line, L, M and N receive 500, 600 and 700, respectively. 400 on the first input line is lost. The next READ will start reading with the third line, picking up 900. Hence, 800 is lost.100 200 300 400 500 600 700 800 900
But, if the input value is a real number and the corresponding variable is of INTEGER type, an error will occur.
The length of the input string and the length of the corresponding CHARACTER variable do not have to be equal. If they are not equal, truncation or padding with spaces will occur as discussed in the PARAMETER attribute page.
If the input lines areINTEGER :: P, Q, R, S READ(*,*) P, Q READ(*,*) READ(*,*) R, S
The first READ reads 100 and 200 into P and Q and 300 is lost. The second READ starts with a new input line, which is the second one. It does not read in anything. The third READ starts with the third line and reads 700 and 800 into R and S. As a result, the three input values (i.e., 400, 500 and 600) are all lost. The third value on the third line, 900, is also lost.100 200 300 400 500 600 700 800 900