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.

10 Input/Output<br />

10.1 Introduction<br />

<strong>FORTRAN</strong> <strong>77</strong> provides a means of communicating information or data between a <strong>FORTRAN</strong> program<br />

and the computing environment. The computing environment may include a number of devices which are<br />

capable of the recording, retrieval, display, and input of data. Disk and magnetic tape devices are capable<br />

of storing large amounts of data. Other devices such as printers and display terminals can be used to<br />

present a visual (i.e., human-readable) representation of the data. Yet other devices such as terminal<br />

keyboards and card-readers make possible the entry of new data into the computing environment.<br />

For the purposes of our discussion, data is any information which can be processed by an executing<br />

<strong>FORTRAN</strong> program. Some examples of data are names, addresses, telephone numbers, credit card<br />

balances, flight trajectories, bus schedules, athletic records, etc. In computing, such information is usually<br />

well-organized in order to make it useful for processing.<br />

To use an example, consider the entries in a telephone book. There are essentially three pieces of data<br />

listed for each entry; a name, an address, and a number.<br />

Smith J 32 Arthur St--------------------------555-3208<br />

Smith JW 512 King St--------------------------555-9229<br />

Smith Jack 255-113 Queen St N-----------------555-0572<br />

Each entry is a record. The organization of the book is clear. The name is always listed first, the address<br />

second, and the number last. The records are sorted, for our convenience, by name (within each city or<br />

geographical location). The length of each record is the same. This fixed length does sometimes lead to<br />

problems since entries which have a long name or address won’t fit in a record. The phone company<br />

solved this by continuing the information in subsequent records. We might have solved this problem by<br />

increasing the length of a record with the disadvantage of wasting a lot of printing space. Alternatively, we<br />

could have used a variable length record. This solves the problem of wasted space but creates a severe<br />

problem when trying to display the records in nice orderly columns. The telephone book itself is a<br />

collection of records or a file.<br />

We have introduced much of the terminology of data processing: "data", "records", "fixed and variable<br />

record sizes", "files", "sorted", etc.<br />

10.2 Reading and Writing<br />

<strong>FORTRAN</strong> provides a mechanism called "reading" for transferring data into the environment of an<br />

executing program. The READ statement is used to do this. Similarly "writing" is the mechanism for<br />

transferring data out of an executing program. The WRITE and PRINT statements are used to do this.<br />

Other statements provide additional functions such as positioning to a certain record in a file, establishing<br />

which files are to be processed by the program, or making inquiries about files.<br />

Reading and Writing 215

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

Saved successfully!

Ooh no, something went wrong!