Having read the code that opens the 2 files, why do they have to be fixed length record, direct access text files at all ? There is no reference to record numbers in either the read or write statement provided, ( can they be omitted ?)
Couldn't the file on unit 10 be opened as a default text file ? I've never used formatted direct access files (in over 30 years) to know the answer.
Why not simply set up a table in memory of all the values for CIK, CNUM, CIC, YEAR . It would only be 22,663 x 200 bytes long ! ( or only 22,633 x 21 bytes based on the format statement )
Another alternative could be :
! open 'COMPSTATCIKCUSIP.DAT' as a text file and
! generate 'COMPCIKCUSIP9.DAT' as a 23 byte record direct access file
!
C
CHARACTER*10 CIK
CHARACTER*6 CNUM
CHARACTER*3 CIC
INTEGER*4 YEAR , i
!
i = 0
OPEN(UNIT=10,FILE='COMPSTATCIKCUSIP.DAT',STATUS='OLD',ERR=200)
OPEN(UNIT=12,FILE='COMPCIKCUSIP9.DAT',ACCESS='DIRECT',RECL=23,
* STATUS='NEW',ERR=100)
do i = 1,999999
READ (UNIT=10,FMT='(A10,A6,A3,12X,I4/)',ERR=100,END=100) CIK, CNUM, CIC, YEAR
WRITE(UNIT=12,rec=i,ERR=100) CIK, CNUM, CIC, YEAR
end do
100 write (*,*) i-1,' recorde creared in ','COMPCIKCUSIP9.DAT'
CLOSE (UNIT=10)
CLOSE (UNIT=12)
STOP
200 write (*,*) 'could not open original file'
END