FORTRAN Reference Manual

Introduction to File I/O in the HP NonStop
Environment
FORTRAN Reference Manual528615-001
5-15
Specifying File Attributes
Example: Connecting Units to Files
As an example, consider the following FORTRAN program:
?UNIT (2, input.data, REC 200, UNITNAME vector)
?UNIT (3, result.file, REC 200, EXCLUSIVE)
?UNIT (6, , CODE 101)
PROGRAM example
CHARACTER result file * 34, text * 72
REAL values (100)
READ (4,*, PROMPT =' Iterations: ', END = 30)
& iterations
READ (4, 10, PROMPT = ' Result file: ', END = 30)
& result file
READ (5, 10) text
10 FORMAT (A)
WRITE (6, 20) text
20 FORMAT ('1', A)
WRITE (1) iterations
READ (2) values
...
OPEN (3, FILE = result file, RECL = 400)
WRITE (3) values
30 listing = 7
WRITE (listing, 20) text
STOP
END
num is an unsigned integer. In an OPEN statement, exp is an integer expression.
access is I-O, INPUT, or OUTPUT. In an OPEN statement, cexp is a character expression whose
value is one of these.
exclusion is SHARED, PROTECTED, or EXCLUSIVE. In the OPEN statement, cexp is a character
expression whose value is one of these.
Table 5-5. File Attribute Specification (page2of2)
Attribute Default Unit Directive
Assign
Command Open Statement