24.11.2014 Views

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Input/Output<br />

10.4 Files<br />

Earlier we described the notion of a file as a collection of records. In <strong>FORTRAN</strong>, there are two kinds of<br />

files:<br />

1. External<br />

2. Internal<br />

10.4.1 External Files<br />

External files are files that exist or can be created upon external media such as disks, printers, terminal<br />

displays, etc. A file may exist before the execution of a <strong>FORTRAN</strong> program. It may be brought into<br />

existence or "created" during execution. It may also be deleted and therefore not exist after the execution<br />

of a <strong>FORTRAN</strong> program.<br />

All input/output statements may refer to files that exist. In addition, the INQUIRE, OPEN, CLOSE,<br />

WRITE, PRINT, and ENDFILE statements may refer to files that do not exist (and in so doing, may very<br />

well cause the file to be created).<br />

Properties of External Files<br />

Name<br />

Access<br />

In <strong>FORTRAN</strong>, a file may or may not have a name. If it does have a name then, not<br />

surprisingly, it is called a named file. All files in <strong>Open</strong> <strong>Watcom</strong> <strong>FORTRAN</strong> <strong>77</strong> have names<br />

and so it may seem odd to introduce this notion. However, we do since the INQUIRE<br />

statement lets you find out if a file is named and, if so, what its name is. File naming<br />

conventions may differ from one computing system to the next. As well, different<br />

<strong>FORTRAN</strong> <strong>77</strong> compilers may have different file naming conventions.<br />

"Access" simply refers to the way in which we can position to and read or write the data in<br />

a particular record in a file. There are two ways in which records can be accessed in a file;<br />

sequentially or directly.<br />

Using the sequential access method, records may be read or written in order starting with<br />

the first record and proceeding to the last record. For example, it would be quite<br />

impossible to read or write the tenth record in a file and then read or write the third record.<br />

Similarly the eleventh record must be read or written before we can access the twelfth<br />

record. If we adopt the convention that each record in a file has a record number then the<br />

first record is record number 1, the second is 2, and so on. This numbering convention is<br />

important when we look at the other access method which is "direct".<br />

Using the direct access method, records may be read or written in any order. It is possible<br />

to read or write the tenth record of a file and then the third and then the twelfth and so on.<br />

A caveat: a record cannot be read if it has never been written since the file was created. In<br />

direct access, the idea of a record number is very important and so by convention, we<br />

number them starting at 1 as the first record and proceeding on up. With direct access, if<br />

you create a new file and write record number 10 then the file has ten records regardless of<br />

the fact that only one has been written. You could, at some later time, write records 1<br />

through 9 (in whatever order you please) and add additional records by writing records with<br />

record numbers greater than 10.<br />

Some files have the property of being able to sustain both of these access methods. Some<br />

files may only have one of these properties. For example, most line printers cannot be<br />

Files 217

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!