Basic Input/Output

8.1 List-directed I/O

program io_basic
  implicit none
  integer :: n
  real :: x
  character(len=50) :: name

  print *, "Enter your name, an integer, and a real:"
  read *, name, n, x                  ! list-directed input (spaces/commas separate values)
  print *, "Hello ", trim(name), n, x
  write(*, *) "Same as print *"
end program io_basic

8.2 Formatted output (preview — see §19)

write(*, '(a, i5, f10.3)') "Values:", 42, 3.14159
print '(a, es12.4)', "Scientific: ", 6.02214e23
write(*, '(3(f8.2, 1x))') 1.0, 2.0, 3.0
write(*, '(*(g0, :, ", "))') 1, 2.5, "three"     ! g0: minimal width; * repeat

8.3 Standard units

use, intrinsic :: iso_fortran_env, only: output_unit, error_unit, input_unit
write(error_unit, *) "Error message to stderr"
flush(output_unit)