Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have a Fortran 2003 compiler, the intrinsic module <a href="http://fortranwiki.org/fortran/show/iso_fortran_env" rel="noreferrer"><code>iso_fortran_env</code></a> defines the variables <code>input_unit</code>, <code>output_unit</code> and <code>error_unit</code> which point to standard in, standard out and standard error respectively.</p> <p>I tend to use something like</p> <pre><code>#ifdef f2003 use, intrinsic :: iso_fortran_env, only : stdin=&gt;input_unit, &amp; stdout=&gt;output_unit, &amp; stderr=&gt;error_unit #else #define stdin 5 #define stdout 6 #define stderr 0 #endif </code></pre> <p>in my input/output routines. Although this of course means <a href="http://fortranwiki.org/fortran/show/Preprocessors" rel="noreferrer">preprocessing</a> your source file (to do this with <code>ifort</code>, use the <code>-fpp</code> flag when compiling your source code or change the source file extension from <code>.f</code> to <code>.F</code> or from <code>.f90</code> to <code>.F90</code>).</p> <p>An alternative to this would be to write your own, non-intrinsic, <code>iso_fortran_env</code> module (if you don't have a Fortran 2003 compiler)<del>, as discussed <a href="http://old.nabble.com/iso_fortran_env-td6041849.html" rel="noreferrer">here</a></del> (this link has died since this answer was posted). In this example they use a module:</p> <pre><code>module iso_fortran_env ! Nonintrinsic version for Lahey/Fujitsu Fortran for Linux. ! See Subclause 13.8.2 of the Fortran 2003 standard. implicit NONE public integer, parameter :: Character_Storage_Size = 8 integer, parameter :: Error_Unit = 0 integer, parameter :: File_Storage_Size = 8 integer, parameter :: Input_Unit = 5 integer, parameter :: IOSTAT_END = -1 integer, parameter :: IOSTAT_EOR = -2 integer, parameter :: Numeric_Storage_Size = 32 integer, parameter :: Output_Unit = 6 end module iso_fortran_env </code></pre> <p>As noted in other answers, 0, 5 and 6 are <em>usually</em> <code>stderr</code>, <code>stdin</code> and <code>stdout</code> (this is true for <code>ifort</code> on Linux) but this is <strong>not</strong> defined by the Fortran standard. Using the <code>iso_fortran_env</code> module is the correct way to portably write to these units.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload