! This file: http://ftp.aset.psu.edu/pub/ger/fortran/hdk/prepend.f90 ! Program Prepend ! Illustrate how to prepend data to an existing file without copying it. ! F-Compiler compatible. ! H. D. Knoble, hdkLESS at SPAM psu dot edu, 20 July 2003. ! Character (Len=40) :: line, File1, File2 Integer :: j, ios File1="PREPEND.DAT" File2="EXISTING.DAT" ! Process the data to be prepended. open (unit=50,file=file1, action="READ", status="OLD", position="REWIND") j=0 do read(unit=50,fmt="(A)",iostat=ios) line if (ios == 0) then j=j+1 write(unit=*,FMT=*)"Record#",j,":",line else exit endif end do close(50) print *, "Total records prepended=",j ! Process the existing data. open (unit=50,file=file2, action="READ", status="OLD", position="REWIND") do read(unit=50,fmt="(A)",iostat=ios) line if (ios == 0) then j=j+1 write(unit=*,FMT=*)"Record#",j,":",line else exit endif end do close(50) print *, "Total records processed=",j end program prepend