There appears to be a performance issue associated with UNFORMATTED files, either DIRECT or SEQUENTIAL access.
I had noticed that the work files created as DIRECT, UNFORMATTED seemed very slow to create, and slow to access. So, I ran a set of comparisons.
I wrote (and read) a file of 2000 records, of length=194 and timed the loop. The results are as follows:
For Direct Access (using REC= in the write or read)
Starting the test at: 20150123 151057.900
For access=direct format=unformatted, Written using REC=, in sequential order, file size=388,000
writing 2000 records took 44.0332
Starting the test at: 20150123 152815.356
For access=direct format=unformatted, Read using REC=, in sequential order
reading 2000 records took 2.12500
For Sequential access (see notation for use of REC=)
Starting the test at: 20150123 151600.514
For access=sequential, format=unformatted, written with no REC= , file size=392,000
writing 2000 records took 1.76172
Starting the test at: 20150123 151702.044
For access=sequential, format=unformatted, records written as REC=, sequentially, file size=388,000
writing 2000 records took 51.9512
Starting the test at: 20150123 153330.497
For access=sequential format=unformatted, read as sequential records
reading 2000 records took 1.73828
These data confirm that the act of creating a direct access file is about 25 times slower than sequential unformatted. I noticed that with Sequential/Unformatted, one can specify the REC= in the read or write. When REC= is specified, the creation of the file takes the equivalent amount of time.
It should also be noted that while using REC=, the amount of disk access that occurred was significantly more than for the faster records. I believe that is reflected in the timing data, although the root reason is unknown.
I have not bench-marked a sequential formatted file; my experience is that this is lightning fast.
!FTN95 application...
PROGRAM main
integer print_every
integer failed_open,failed_delete,failed_close,failed_write
character iorecord(194)
character*8 ddate
character*10 ttime
character*5 zzone
integer values(8)
character*20 access,form
! Test program to open a unformatted direct access file, then write several records
! then close it and try again. Each failure to open will be logged along with the error code and date/time
! a 2 second wait will be done, then re-try.
!
! The first time, we'll delete the file, then create as a new, then old from then on
!
print_every = 0
failed_open = 0
failed_delete = 0
failed_close = 0
failed_write = 0
call date_and_time(ddate,ttime,zzone,values)
print *,'Starting the test at: ',ddate(1:8),' ',ttime(1:10)
access = 'sequential'
form = 'unformatted'
max_recs=2000
! the READ tests require that the file exists, so change 'replace' to 'old'
open(unit=15,file='testfile.dat',access=access,iostat=icode,err=12000,&
form=form,recl=194,status='old',share='compat')
start_loop = high_res_clock@(.true.)
do i=1,max_recs
call randomfile(iorecord,194) ! this is always left in to even out the loop timing
!This next line must change to reflect read or write and rec= if needed
read(15,err=13000)iorecord
end do
end_loop = high_res_clock@(.false.)
print *,'For access=',access,' format=',form
print *,'writing ',max_recs,' records took ',end_loop-start_loop
close(unit=15)
pause
stop
13000 continue
print *,'io error'
stop
12000 continue
print *,'open error',icode
stop
END PROGRAM main
subroutine randomfile(iorecord,length)
character*1 iorecord(length)
do i=1,length
iorecord=char(int(255.*random@()))
end do
return
end