FORTRAN I/O Statements: Comprehensive Guide and Syntax Overview

input and output statements n.w
1 / 5
Embed
Share

Explore the comprehensive set of input and output instructions in FORTRAN, including basic and advanced I/O operations. Learn how to read from standard input devices, write to output devices, and manipulate files managed by the operating system. Discover syntax examples for READ and WRITE statements, format-controlled and list-directed I/O, and more.

  • FORTRAN
  • I/O statements
  • Input Output
  • Syntax
  • Programming

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Input and Output Statements FORTRAN has always included a comprehensive set of I/O instructions. Can be used with standard input and output devices such as keyboards, terminal screens, printers, etc. Can be used to read and write files managed by the host OS. Basic instructions: READ reads input from a standard input device or a specified device or file. WRITE writes data to a standard output device (screen) or to a specified device or file. FORMAT defines the input or output format. Advanced instructions Used to manipulate files maintained by the OS file manager. Often dependent on features in a particular OS or computer.

  2. READ Statement Format controlled READ: Syntax: READ(dev_no, format_label) variable_list Read a record from dev_no using format_label and assign results to variables in variable_list Ex: READ(5,1000) A,B,C 1000 FORMAT(3F12.4) Device numbers 1-7 are defined as standard I/O devices and 1 is the keyboard, but 5 is also commonly taken as the keyboard (used to be card reader) Each READ reads one or more lines of data and any remaining data in a line that is read is dropped if not translated to one of the variables in the variable_list. Variable_list can include implied DO such as: READ(5,1000)(A(I),I=1,10)

  3. READ Statement contd List-directed READ Syntax: READ*, variable_list Read enough variables from the standard input device (usually a keyboard) to satisfy variable_list input items can be integer, real or character. characters must be enclosed in . input items are separated by commas. input items must agree in type with variables in variable_list. as many records (lines) will be read as needed to fill variable_list and any not used in the current line are dropped. each READ processes a new record (line). Ex: READ*,A,B,K read line and look for floating point values for A and B and an integer for K. Some compilers support: Syntax: READ(dev_num, *) variable_list Behaves just like above.

  4. WRITE Statement Format controlled WRITE Syntax: WRITE(dev_no, format_label) variable_list Write variables in variable_list to output dev_no using format specified in format statement with format_label Ex: WRITE(6,1000) A,B,KEY 1000 FORMAT(F12.4,E14.5,I6) Output: |----+----o----+----o----+----o----+----| 1234.5678 -0.12345E+02 12 Device number 6 is commonly the printer but can also be the screen (standard screen is 2) Each WRITE produces one or more output lines as needed to write out variable_list using format statement. Variable_list can include implied DO such as: WRITE(6,2000)(A(I),I=1,10)

  5. WRITE Statement contd List directed WRITE Syntax: PRINT*, variable_list Write variables in variable_list to standard output device using format appropriate to variable type. Variables are separated by either spaces or commas, depending on system used. Ex: PRINT*, X= ,X, Y= ,Y, N= ,N Output: X= 4.56, Y= 15.62, N= 4

Related


More Related Content