program aveamp real total, cnt, average, amp integer goodline C If GOODLINE = 0, line was read in fine C if GOODLINE > 0, line was read, but didn't match format - problem C if GOODLINE < 0, end of file has been reached total = 0.0 cnt = 0.0 open(1, + file='/data2/fortran_class/transfer/lightning.sm.txt', + status='old') open(10,file='amp.out',status='unknown') read(1,1000,iostat=goodline) amp do while (goodline.eq.0) total = total + amp cnt = cnt + 1.0 read(1,1000,iostat=goodline) amp print *, goodline, amp end do average = total / cnt write(*,'("Average amp is ",f4.1)') average write(10,1010) average 1000 format(34x,f8.1) 1010 format("Average amp is ",f14.1) stop end