Skip to main content
Engineering LibreTexts

12.1: File Open

  • Page ID
    54324
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    A file must be opened before information can be written or read from a file. In order to open a file, the operating system needs some information about the file in order to correctly identify the file and establish the access parameters (i.e., read, write, etc.). The open statement “clauses” provide that information to the operating system.

    The file open statement is as follows:

    open (unit=<unit number>, file=<file name>,                &
            status=<file status>, action=<file action>,        &
            position=<file position>, iostat=<status variable>)
    

    The following table summarizes the various open statement clauses.

    Clause Explanation
    unit Unit number for subsequent file operations (i.e., read, write, etc.). Typically an integer between 10 and 99.
    file Name of file to be opened. Can be character literal or a character variable.
    status Status of file. Allowable options “old”, “new”, or “replace”
    “old” \(\rightarrow\) the file must already exist.
    “new” \(\rightarrow\) a new file will be created.
    “replace” \(\rightarrow\) a new file will be created, replacing an existing one if necessary.
    action Action or open operation. Allowable options are “read”, “write”, or “readwrite”.
    “read” \(\rightarrow\) read data from a file.
    “write” \(\rightarrow\) write data to a file.
    “readwrite” \(\rightarrow\) simultaneously read data from and write data to a file.
    position Position or place to start. Allowable options are “rewind” (beginning), “append” (end).
    iostat Name of variable for system to place a status code indicating the status (success or failure) of the operation. If the status variable is set to 0, the operation is successful. If the status variable is set to >0, an error occurred and the operation was unsuccessful.

    The unit number assigned should be between 10 and 99.


    This page titled 12.1: File Open is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by Ed Jorgensen via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?