set8 - Simple File Input & Output Handout Eight...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Simple File Input & Output Handout Eight Although we are looking at file I/O (Input/Output) rather late in this course, it is actually one of the most important features of any programming language. The ability of a program to communicate small or very large amounts of data to itself or another program at a known or unknown later date is of great importance. Fortran 90 has a wealth of commands for I/O and in this course we will only study a few of them. For example your matrix library module could be written so that it could write and read matrices to and from files saving you the trouble of having to type it in from the keyboard every time you run a code. We will look briefly at two types of files, formatted and unformatted files. 1 The OPEN statement Before we can READ from or WRITE to a file the file must first be opened and a UNIT number assigned to it. The general form of the OPEN statement is OPEN( specification list ) the specification list is a comma separated list of specifiers that determine how the file should be opened. The list below contains the specifiers you need to know for this course but be aware that there are many more. UNIT = unit number FILE = file name FORM = file type STATUS = file status ACTION = allowed actions The specifiers are explained below. unit number : This must be present and is an integer. Note this number identifies the file and must be unique so if you have more than one file open then you must specify a different unit number for each file. Avoid using 0,5 or 6 as these UNIT s are typically picked to be used by Fortran as follows. Standard Error = 0 : Used to print error messages to the screen. Standard In = 5 : Used to read in data from the keyboard. Standard Out = 6 : Used to print general output to the screen. file name : A string that holds the name of the file which we would like to open. There are situations in Fortran where you do not need to specify a file name, however this course will not require them so a file name will always be required. file type : A string that holds the type of file that we would like to open, ie FORMATTED or UNFORMATTED , both of these are explained later. If this specifier is not present then the FORM will default to FORMATTED . file status : A string that holds the status of the file that we would like to open. Note : the default option is compiler dependent so it is recommended that you always specify one of these. We will consider three options; 1 NEW : This indicates that the file should not yet exist and if it does exist the OPEN statement will fail. If it does not exist then the OPEN statement will create it....
View Full Document

Page1 / 5

set8 - Simple File Input & Output Handout Eight...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online