read,print, andwrite–Statements for reading and writing data to files on disk or standard streams, such as standard input, output, or error- Format strings –For formatting values of any built-in data type into text.
open,close, andinquire–Statements to open, close, and get information about a file, respectivelytrim–A built-in function that returns the input character string without any trailing blanks
Summary
- Six core syntax elements provide most of Fortran’s I/O functionality:
read,print,write,open,close, andinquire. - Use
readandwritefor input and output of any data, respectively. - You can access standard input, output, and error streams from the
iso_fortran _envmodule asinput_unit,output_unit, anderror_unit. - Fortran I/O units are unique integer identifiers that let you access standard streams and files on disk that you work with, akin to file handles in other programming languages. Use them in your code to write to standard streams in a portable way.
- Use format strings to convert numbers and other non-text data into text. For example,
i3formats an integer into text with width 3, whereasf5.2will format a real number into text with a total width of 5 and a width of 2 for the fractional part. - You can use the
openstatement to open existing or new files, as well as to redirect output from standard streams to files on disk. - You can use the
inquirestatement to get information about a file, including whether the file is open or not.
New Fortran elements, at a glance