I am having a hard time figuring out what the problem with my file I/O subroutine is. I am trying to use "unformatted" form and "buffered" writes to write large result files in one of my applications that are then read in another application. I was able to extract a minimal working example to reproduce the issues I have:
PROGRAM test implicit none INTEGER(KIND=4) :: dummy_int4, i, j INTEGER(KIND=4), DIMENSION(:,:), ALLOCATABLE :: array open(unit=20, file='debug.dat', status='replace', action='write', form='unformatted', buffered='yes') allocate(array(50000,26)) do j=1, 26 do i=1, 50000 array(i,j) = i*j end do end do dummy_int4 = 1 write(20) dummy_int4 dummy_int4 = 2 write(20) dummy_int4 do j=1, 26 write(20) array(:,j) end do close(unit=20) open(unit=20, file='debug.dat', status='old', action='read', form='unformatted', buffered='yes') read(20) dummy_int4 write(*,*) dummy_int4 read(20) dummy_int4 write(*,*) dummy_int4 close(unit=20) END PROGRAM test
The output of the program in this version is:
Which is not what I would expect. Changing the file opening clauses to buffered='no' yields the expected output 1 and 2. Where exactly am I going wrong here?
Intel fortran compiler version 17.0.4, Opensuse 42.2, Linux kernel version 4.4.87-18.29-default