Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6937081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:19:06+00:00 2026-05-27T12:19:06+00:00

How can I read and write to the standard input, output and error streams

  • 0

How can I read and write to the standard input, output and error streams stdin, stdout and stderr in Fortran? I’ve heard writing to stderr, for example, used to be write(5, fmt=...), with 5 the unit for stderr, and I know the way to write to stdout is to use write(*, fmt=...).

How do I read and write to the standard input and output units with the ifort compiler?

Compiler version:

Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 10.0 Build 20070426 Package ID: l_fc_p_10.0.023 Copyright (C) 1985-2007 Intel Corporation. All rights reserved

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:19:06+00:00Added an answer on May 27, 2026 at 12:19 pm

    If you have a Fortran 2003 compiler, the intrinsic module iso_fortran_env defines the variables input_unit, output_unit and error_unit which point to standard in, standard out and standard error respectively.

    I tend to use something like

    #ifdef f2003
    use, intrinsic :: iso_fortran_env, only : stdin=>input_unit, &
                                              stdout=>output_unit, &
                                              stderr=>error_unit
    #else
    #define stdin  5
    #define stdout 6
    #define stderr 0
    #endif
    

    in my input/output routines. Although this of course means preprocessing your source file (to do this with ifort, use the -fpp flag when compiling your source code or change the source file extension from .f to .F or from .f90 to .F90).

    An alternative to this would be to write your own, non-intrinsic, iso_fortran_env module (if you don’t have a Fortran 2003 compiler), as discussed here (this link has died since this answer was posted). In this example they use a module:

    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
    

    As noted in other answers, 0, 5 and 6 are usually stderr, stdin and stdout (this is true for ifort on Linux) but this is not defined by the Fortran standard. Using the iso_fortran_env module is the correct way to portably write to these units.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I read from standard input and write to standard output. System.Diagnostics.Process.StandardInput's MSDN
I want to be able to write bytes and read them from standard input/output
Is there any class in the .NET framework that can read/write standard .ini files:
I have two (UNIX) programs A and B that read and write from stdin/stdout.
I created a SQLite database on Android device. The program can read/write to database
How can I read/write serializable object instances to a RandomAccessFile in Java? I want
I'm looking for an editor that can read and write remote PHP files via
Is there a stand-alone GUI designer that can read and write the .form files
With D and Tango library can I read and write in the ANSI encoding
How can i check the read/ write permission of the file storing media? ie

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.