Ian, good suggestions. It looks like I'll have to do something like that (read below).
Paul, I was using a 1 second delay before attempting to retry the operation. Sometimes, it never worked (60 seconds). Other times, after a few (4-10) it would succeed.
First, before changing the OPENing code, I took the exclusive access off of this file, just letting it remain a regular file. Still failed, but much more rarely. In the 167 file openings, it first failed on file 57. Same bizarre status code (10005).
Second, I tried to open the file as 'TRANSPARENT' but that did not seem to work with using record numbers in the read/write's. Abandoned this.
Next, I recoded the open. The significant change is that I did not try to delete the file before opening it, like I did when the file is to be opened as NEW (UNKNOWN). I did not trap any errors. However, accessing the file itself now appears to be exceedingly slow, which was unexpected. Still trying to track that down, as other files that are opened as OLD, direct access don't seem to be slow in their access.
By way of explanation, deleting the file allowed me to use the file for different temporary purposes as needed. However, a different record length applied to an existing file would cause an error to be thrown (IOSTAT=105 or 108 ). So, if it is opened as new, delete the file first to prevent this error.
I even tried placing the file on a different logical drive, just to make sure it was not some fluke of where the file resided. No difference in performance; still slow.
Lastly, I implemented a delete operation just prior to the OPEN for a status of NEW (UNKNOWN). This code segment is below. Better, but no joy. The 10005 error still occurs. Referring to the tracing statements in the code, the following happens:
File is found to exist.
File is deleted.
File is found not to exist.
Initial open results in IOSTAT=10005
Try again to open the file, IOSTAT=10005
Code stops trying.
The code that is running at this time is in a fairly tight loop, finding the target file to be opened from a list of files, then opening that file which causes the temporary file to be opened, processing the file contents into the direct access, unformatted file I'm having an issue with. At the end, of writing this work file, the work file is closed and control is returned to the looping section. If the direct access file cannot be opened, the lower level routine quits and returns an error indicator, stopping the loop.
Any additional insight would be much appreciated. Yes, the code looks horrible. Will be cleaned up once I understand what can and cannot work!!
ICHECK=0 ! ENSURE THE RETURN CODE IS SET APPROPRIATELY
if(old_new.eq.2) then
if(fexists@(trim(fname),icheck)) then
if(icheck .ne. 0) print *,'fexists@ returned',icheck
call erase@(trim(fname),icheck)
print *,'Deleting file before 'new':',trim(fname),icheck
do 2211 ii=1,10
if(.not.fexists@(trim(fname),icheck)) go to 2212
call sleep1@(0.2)
2211 continue
2212 print *,'Waited to delete',ii
endif
endif
OPEN(UNIT=IUNIT,FILE=TRIM(FNAME),STATUS=FILE_STATUS(OLD_NEW),
$ ACCESS=FILE_ACCESS(SEQ_DA),RECL=IISIZE,FORM=FILE_FORM(SEQ_DA),
$ SHARE=FILE_CONTENTION(ACCESS_STYLE),IOSTAT=ICHECK)
if(icheck .ne. 0) then !don't know what the issue was, but can't be good.
print *,'1st open icheck=',icheck,' file=',trim(fname)
if(old_new .eq. 1) then ! attempting to open an old file
if(icheck .eq. 2 ) go to 2905 ! attempt to open and old file, and it wasn't there.
c --- unexpected status for an old file
print *,'da Open:','Status:',icheck,' File:',trim(fname),
$ 'Option:',iopt
go to 2905
endif
else ! icheck == 0
go to 2900 ! success
endif ! end icheck on initial open of the file
c --- unknown error opening a DA file as new/unknown
c --- second attempt, attempting as a sequential unformatted, recl=1
print *,'Initial attempt to open failed. Try to open,'//
$'delete,open again. File=',trim(fname),icheck,iopt
OPEN(UNIT=IUNIT,FILE=TRIM(FNAME),STATUS='UNKNOWN',
$ ACCESS='SEQUENTIAL',RECL=1,FORM=FILE_FORM(SEQ_DA)
$ ,IOSTAT=ICHECK)
IF(ICHECK .NE. 0) THEN ! then this has failed as well
PRINT *,'Attempt to open again has failed. Status=',icheck
go to 2905
endif
close(unit=iunit,status='delete',iostat=icheck)
if(icheck .ne. 0) then
print *,'Attempt to delete DA file failed. Status=',icheck
go to 2905
endif
print *,'3rd Attempt to open new/unk DA file',trim(fname),
$ icheck,iopt
OPEN(UNIT=IUNIT,FILE=TRIM(FNAME),STATUS=FILE_STATUS(OLD_NEW),
$ ACCESS=FILE_ACCESS(SEQ_DA),RECL=IISIZE,FORM=FILE_FORM(SEQ_DA),
$ SHARE=FILE_CONTENTION(ACCESS_STYLE),IOSTAT=ICHECK)