Write float arrays to a text file: Difference between revisions

m
Line 476:
 
=={{header|Fortran}}==
=== Fortran 90 ===
In ANSI FORTRAN 77 or later use OPEN STATEMENT, and formatted WRITE statement with implied DO loop:
<lang fortran> real x(4), y(4)
data x / 1.0, 2.0, 4.0, 1.0e11 /
do 10 i = 1, 4
y = sqrt(x)
10 continue
open(unit=15, file='two_cols.txt', status='new')
write(15,'(f20.3,f21.4)') (x(I), y(I), I = 1, 4)
end</lang>
 
{{works with|Fortran|90 and later}}
<lang fortran>program writefloats
Line 517 ⟶ 506:
 
The arrays x and y should have same bounds (and size); this constraint is not checked.
 
=== Fortran 77 ===
<lang fortran> program writefloats
integer i
double precision x(4), y(4)
data x / 1.01d0, 2.02d0, 4.04d0, 1.0e11 1d11/
 
do 10 i = 1, 4
y = sqrt(x)
10 continue
 
open(unit=15, file='two_cols.txt', status='new')
write(15, '(f20.3,f21.4)') (x(Ii), y(Ii), Ii = 1, 4)
end</lang>
 
=={{header|FreeBASIC}}==
1,336

edits