program check_rand_binary !------------------------------------------------------------------------------ !Program: Random Binary File Reader !Author: Chris Harper !Date: 4/8/2008 !------------------------------------------------------------------------------ implicit none integer :: a, i, EOF i = 2 !open an unformatted direct access file with 4 bytes per record open (unit = 10, file = "randombi.dat", status = "old", form = "unformatted", & access = "direct", recl = 4) do !read record i read (10, rec = i, iostat = EOF) a if (EOF < 0) then !if EOF, exit loop print *, "EOF" exit else if (EOF > 0) then !if error, print a message and exit print *, "File read error occured. Error Number: ", EOF exit endif !print record pos and value print "(I4, 2X, I5)", i, a !increment record pos if (i == 2) then i = 100 else i = i + 100 end if end do close (10) end program