The Queen's University of Belfast
Parallel Computer Centre

[Next] [Previous] [Top]

File-based Input and Output


File-based Input and Output

Topics

Unit Numbers

Read Statement

General form

READ format, list !not covered

READ(clist) [io_list]

[UNIT=] unit-number,

[FMT=] format

[,REC= record-number]

[,IOSTAT=ios]

[,ADVANCE=adv]

[,SIZE=integer_variable]

[,EOR=label]

[,END=label]

[,ERR=label]

Examples

READ(*,*) a, b, c

READ(5,*) line

READ(5,100) x, y, z

READ (UNIT=10,FMT=100, &

ERR=10,IOSTAT=ios)

Write Statement

General Form

WRITE(clist) [io_list]

[UNIT=] unit-number,

[FMT=] format-spec

[,REC= record-number]

[,IOSTAT=ios]

[ADVANCE=adv]

[,SIZE=integer-variable]

[,EOR=label]

[,ERR=label]

Examples

WRITE(*,*)

WRITE(6,*) i,j

WRITE(6,100) i

WRITE(6,*,ERR=10) line

WRITE(UNIT=file1,FMT=100,&

REC=recordnumber, ERR=10) &

newline

Open Statement

OPEN (unit, [olist] )

olist

FILE=filename

where filename is a valid filename

STATUS=st

st may be 'OLD', 'NEW', 'REPLACE', 'SCRATCH' or 'UNKNOWN'

ERR=label

Go to label if an error occurs.

IOSTAT=ios

ios is an integer variable which is set to zero if the statement is executed successfully or to an implementation dependent constant otherwise.

FORM=fm

fm may be 'FORMATTED' or 'UNFORMATTED', the default is 'FORMATTED' for sequential files and 'UNFORMATTED' for direct access files.

ACCESS=acc

acc may be 'SEQUENTIAL' or 'DIRECT'

RECL=rl

rl is the maximum record length (positive integer) for a direct access file. For formatted files this is the number of characters and for unformatted it is usually the number of bytes or words (system dependent).

BLANK=bl

bl is either 'NULL' or 'ZERO'

POSITION=pos

pos may be 'ASIS', 'REWIND' or 'APPEND'. Defaults to ASIS.

PAD=pad

pad may be 'YES' or 'NO'

DELIM=del

del may be 'APOSTROPHE' or 'QUOTE' or 'NONE'. Defaults to 'NONE'.

ACTION=act

act may be 'READ', 'WRITE' or 'READWRITE'. Default is processor dependent.

Examples

OPEN (UNIT=10,FILE='fibonacci.out')

OPEN (UNIT=11,FILE='fibonacci.out',&

STATUS='NEW',ERR=10)

.......

10 WRITE(6,*) 'Error opening file:&

&fibonacci.out.'

OPEN (UNIT=12, STATUS='OLD',&

FILE='student.records',&

ACCESS='DIRECT',RECL=200,&

FORM='FORMATTED',&

ERR=20, IOSTAT=IOS)

........

20 IF (ERR .GE. 0) THEN

WRITE(6,*) 'Error opening file:&

&student.records.'

WRITE(6,*) 'IOS = ',IOS

ENDIF

STOP

Close Statement

CLOSE([UNIT=]u [,IOSTAT=ios]

[,ERR=label] [,STATUS=st])

CLOSE(10)

CLOSE(UNIT=nunit, ERR=10)

CLOSE(10,STATUS='DELETE',ERR=10)

Inquire Statement

INQUIRE (inquiry-list)

where inquiry-list must contain either

FILE=fname

or

UNIT=unum

plus any of the following

Inquiry list

EXIST=lex !true or false

OPENED=lod !true or false

NUMBER=unum !unit number

NAME=fnm !filename

ACCESS=acc !'DIRECT' or

!'SEQUENTIAL'

SEQUENTIAL=seq !'YES or 'NO'

DIRECT=dir !'YES' or 'NO'

FORMATTED=fmt !'YES' or 'NO'

UNFORMATTED=unfmt !'YES' or 'NO'

FORM=frm !'FORMATTED' or

!'UNFORMATTED'

NEXTREC=recn !number of next record

RECL=recl !record length

Direct Access Files

OPEN (UNIT=10,FILE='STAFF.RECORDS',&

RECL=200, ACCESS='DIRECT')

READ(UNIT=10,FMT=100,REC=20)&

staffrecord

WRITE(UNIT=10,FMT=100,REC=20) &

staffrecord


[Next] [Previous] [Top]
All documents are the responsibility of, and copyright, © their authors and do not represent the views of The Parallel Computer Centre, nor of The Queen's University of Belfast.
Maintained by Alan Rea, email A.Rea@qub.ac.uk
Generated with CERN WebMaker