Hi all,
I have been migrating some old code which has been through the migration mill a few times (Microsoft -> DEC -> Compaq -> Intel), so it's a bit of a mixed bag in terms of use of extensions. The code does a fair amount of reading and writing data to a binary file and I've replaced most of these operations using binary stream I/O. But in doing this I encountered a problem where a file opened with form='binary', access='stream' would sometimes fail with an end-of-file during a read. I tracked the problem down and have replicated it in the piece of code at the end. In this cut down version, the initial data is written out to the file with a dummy integer at the start of the file. After some processing, the dummy integer is rewritten with its true value and that works fine. But in the final stage, fseek is used to reposition the file before updating the integer and then the subsequent read fails with an end of file condition.
So my question is whether this is a bug in the Intel portability library or is there something that says that you can't use portability functions on stream files? I do hope that it's not the latter as it'll save me a lot of rewriting of code.
Many thanks
John Paine
program test_stream
use ifport
implicit none
integer i,iRet
integer idata
integer ndata
integer iz(2048)
c open the stream data file
idata=1234
open(idata,file='test_stream.dat',form='binary',access='stream',status='unknown')
c initialise the data
do i=1,2048
iz(i)=0
end do
c write it out to the data file with a dummy count at the start of the file
ndata=0
write(idata)ndata
write(idata)(iz(i),i=1,2048)
c do some calculations to work out the actual count to be written at the start of the file
ndata=2048
c write out the new count
write(idata,pos=1)ndata
c read the data following the count value to check that the file has not been truncated by the write
read(idata,iostat=iRet)(iz(i),i=1,2048)
if(iRet.ne.0) then
write(*,'(a)')' Bad read after write using pos=1'
stop
endif
c got here ok, so the file wasn't truncated, so now use fseek to reposition to the start of the file
iRet=fseek(idata,0,0)
c write out the new count
write(idata,pos=1)ndata
c read the data following the count value to check that the file has not been truncated by the write
read(idata,iostat=iRet)(iz(i),i=1,2048)
if(iRet.ne.0) then
write(*,'(a)')' Bad read after using fseek followed by a write using pos=1'
stop
endif
c close and delete the file if we get to this part of the code as everything worked fine
close(idata,status='delete')
end





