Steve Lantz, Adam Brazier (revisions)
Cornell Center for Advanced Computing

Revisions: 2/2023, 10/2014, 6/2012 (original)

Fortran provides tools to read and write both formatted (having a specification of how the data should be parsed for input, or presented for output) and unformatted (binary) data. File access can be sequential or random. The Fortran 2003 standard added streaming I/O. In this introduction we will only cover formatted, sequential I/O.

The read command is used for reading data. For writing data, the write command and the shorter print command (to write to standard output) can be used. The syntax of all three commands is very similar.

Objectives

After you complete this topic, you should be able to:

  • Use I/O routines
  • Print variables and strings to standard output
  • Write a format specification
  • Use edit descriptors to format variables and literal constants
  • Explain how to repeat and group a format
  • Demonstrate reading from and writing to a file
Prerequisites
  • Familiarity with an editor
  • Knowledge of how to execute simple commands on the command line
  • Some basic understanding of what a computer language is
 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Inclusivity Statement