Michael Kupferschmid, "Classical Fortran: Programming for Engineering and Scientific Applications", Taylor & Francis Group, 2009
The generalized form of READ command is as follows,
READ (unit, format) list
where, the value of 'unit' could be any value ranging from 0-99 or star symbol '*'. Both 5 or * means standard-in (usually keyboards). If the 'format' is *, then the format will be according to the compiler default. However if 'format' is not * , then it will refer the label of the FORMAT statement. Note that the FORMAT statement is used to specify exactly how the input/output will be. The 'list' is the list of variables to be read.
Any of the commands are used to read an input for variable A,
READ (*,*) A
READ *,A
An example of FORMAT statement (just copy and paste in your editor)
PROGRAM readonce
REAL*8 X/1.23D0/, Y/53.0D0/
J=37
WRITE(6,901) J,X,Y
901 FORMAT(1X,I3/'X=',T7,F5.2/D8.2)
STOP
END PROGRAM readonce
37
X= 1.23
0.53D+02
Field spec. Meaning
------------------------------------------------------------------------------------------------------------------------------------
nX skip n space
Iw print an integer right justified in w column
mIw m times Iw
Fw.d print a real number with w column and d digit after decimal point
Dw.d same as Fw.d same as F but use fraction-exponent form
L1 print a logical value as T or F
Zh print a hexadecimal value having h hexits
Tn tab to column n
'string' print the text string
/ skip to the next line
------------------------------------------------------------------------------------------------------------------------------------
(pp.149 of Kupferschmid M., 2009)
Now see what happens by running the following program (just copy and paste),
program read3
write(6,
10)
10 format('enter a number: ')
read(5,*) Z
stop
end
After running the above program you will be asked to enter a value. Enter a numerical value 456. Here the output you will see as follows,
enter a number:
456
program read3
write(6,10)
10 format('enter a number: ',$)
read(5,*) Z
stop
end
enter a number: 456
Code: The Hidden Language of Computer Hardware and Software
The Code Book: The Science of Secrecy from Ancient Egypt to Quantum Cryptography
Code Complete: A Practical Handbook of Software Construction
The Da Vinci Code