PRINT formatString , Variables |
WRITE (dev# , formatString) Variables |
|
|
(Mainly because I want to focus on other issues)
Example:
PRINT *, Variables |
WRITE (6, *) Variables |
'( format-spec, format-spec, ... )' |
A format-spec can be:
|
X | one space |
/ | new line |
A | one character (ASCII code) |
I# | integer number, with "#" of digits (overflow is printed as ****) |
F#1.#2 | fixed point number notation, with "#1" characters (i.e., spaces to print) and "#2" digits precision |
E#1.#2 | floating point number notation, with "#1" characters and
"#2" digits precision
NOTE: the number printed will be "-0.xxxxxxE-xx".
|
D#1.#2 |
Double precision float number notation,
with "#1" characters and
"#2" digits precision
NOTE: the number printed will be "-0.xxxxxxE-xx".
(I can't see any difference in behavior from E... :-)) |
Examples:
I5 xxx (5 digits integers) <---> 5 char F10.2 xxxxx.xx <--------> 10 char E15.6 0.xxxxxxE+xx <----> 6 char <-------------> 15 char |
The count " repeats " the given format descriptor
4X | XXXX |
2I8 | I8 I8 |
print '(F7.2, 4X, F7.2)', A, B, C, D, E ^^^^ ^^^^ |
print '(F7.2, 4X, (F7.2))', A, B, C, D, E |
is processed as:
print '(F7.2, 4X, F7.2)', A, B print '(F7.2)', C print '(F7.2)', D print '(F7.2)', E |
Example: one-dimensional array
PRINT *, (A(i), i = 1, 3) is equavalent to: PRINT *, A(1), A(2), A(3) |
Example: two-dimensional array
PRINT *, ( (A(i,j), i = 1, 3), j = 1, 3 ) is equavalent to: PRINT *, A(1,1), A(1,2), A(1,3), A(2,1), A(2,2), A(2,3),... |
REAL, DIMENSION(10) :: A print '("Table form of A"/(2F8.2))', (A(i), i = 1, 10) |
output looks like this:
Table form of A A(1) A(2) A(3) A(4) A(5) A(6) A(7) A(8) A(9) A(10) |
REAL, DIMENSION(10, 10) :: A print '("Matrix A"/(10F8.2))', ((A(i,j), i = 1, 10), j = 1, 10) |
output looks like this:
Matrix A A(1,1) A(1,2) A(1,3) A(1,4) A(1,5) ... A(2,1) A(2,2) ... A(3,1) A(3,2) ... A(4,1) A(4,2) ... .... A(10,1) A(10,2) ... |
print *, "Matrix B" DO i = 1, N DO j = 1, N write (6, "(F8.2)", ADVANCE="NO") B(i, j) END DO print * END DO |
READ Format-String , Variables READ (5 , Format-String) Variables |
The terminal input is device 5
|
INTEGER A READ (5, "(I3)" ) A ! reads a 3 digit integer |
|
Example:
INTEGER A READ (5 , *) A |
OPEN( DeviceNumber, FILE='InputFileName' ) |
OPEN( 10, FILE='myFile' ) |
READ ( 10, Format-String ) Variables |
WRITE ( 10, Format-String , [advance="NO"]) Variables |
|
PROGRAM main IMPLICIT NONE REAL, DIMENSION(4,4) :: B INTEGER i, j OPEN ( 10, FILE="inputMatrix" ) READ (10, *) ((B(i, j), i = 1, 4), j = 1, 4) END |
CLOSE(deviceNumber) |
Check with manufacturer....