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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Language</strong> <strong>Reference</strong><br />

10.3 Records<br />

<strong>FORTRAN</strong> distinguishes between three kinds of records, namely:<br />

1. Formatted<br />

2. Unformatted<br />

3. Endfile<br />

We shall describe each of these in the following sections.<br />

10.3.1 Formatted Record<br />

A formatted record consists of characters. The length of a formatted record is determined by the number of<br />

characters in it. A formatted record may contain no characters at all and thus has zero length. Formatted<br />

records are read or written using formatted input/output statements. An excellent example of a file<br />

consisting of formatted records is our telephone book example.<br />

10.3.2 Unformatted Record<br />

An unformatted record consists of values such as integers, real numbers, complex numbers, etc. It may also<br />

consist of characters. Essentially, these values have the same representation in a record as they have in the<br />

computer’s memory. The length of an unformatted record depends on the amount of storage required to<br />

represent these values in the computer’s memory. For example, on this computer an integer value is stored<br />

using 4 bytes of memory (a byte is a grouping of 8 binary digits). Thus, integer values in unformatted<br />

records also require 4 bytes of storage. For example, 3 integer values stored in an unformatted record<br />

would require 12 bytes of storage. Unformatted records are read or written using unformatted input/output<br />

statements.<br />

To illustrate the difference between a formatted and unformatted record consider the following example.<br />

Example:<br />

INTEGER NUMBER<br />

NUMBER=12345<br />

PRINT 100, NUMBER<br />

100 FORMAT(1X,I5)<br />

WRITE( UNIT=7 ) NUMBER<br />

If you print the variable NUMBER on a printer, it requires 5 character positions. If you write it to a file<br />

using an unformatted WRITE statement, it only requires 4 bytes or character positions in the record. Note<br />

that a character is conveniently represented in one byte of storage, hence we sometimes use the term "byte"<br />

or "character" interchangeably when talking about the size of variables.<br />

10.3.3 Endfile Record<br />

An endfile record is a special record that follows all other records in a file. Simply stated, an endfile record<br />

occurs at the end of a file. Actually, an endfile record is a conceptual thing. It has no length. When the<br />

end of a file is reached (i.e., an attempt to read a record results in the endfile record being read), an<br />

"end-of-file" condition exists. There are no more records following the endfile record. There is only one<br />

endfile record so it is strictly illegal to attempt to read another record after the endfile record has been read<br />

(i.e., when the end-of-file condition exists).<br />

216 Records

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

Saved successfully!

Ooh no, something went wrong!