Code
fortran
! Write to file
open(unit=10, file='output.txt', status='replace')
write(10, '(A, I0, A)') 'Count = ', 42, ' items'
write(10, '(F8.2)') 3.14159 ! ' 3.14'
close(10)
! Read from file
open(unit=11, file='input.txt', status='old')
do
read(11, '(A)', iostat=ios) line
if (ios /= 0) exit
print *, trim(line)
end do
close(11)
! Namelist (config files)
namelist /config/ nx, ny, dt, max_iter
nx = 100; ny = 100; dt = 0.01; max_iter = 1000
open(unit=12, file='config.nml')
write(12, nml=config)
close(12)
! Internal I/O (string <-> number)
character(20) :: str
real :: x
write(str, '(F0.4)') 3.14159 ! str = '3.1416'
read(str, *) x ! x = 3.1416