![发贴心情](skins/Default/topicface/face1.gif)
The following fortran 90 program can read in a text file and then print it out on the screen. It has an added feature that when the output covers the whole screen it will pause and wait for the user to press enter key to continue. Currently I use the "PAUSE" to implement this feature. But I would like to know the direct way of reading in the enter key. Please do offer your wisdom. I appreciate it!
program ex0905
implicit none
character(len=79) :: filename
character(len=79) :: buffer
integer, parameter :: fileid = 10
integer :: status = 0,count=0
logical alive
character(len=1) :: c
write(*,*) "Filename:"
read (*,"(A79)") filename
inquire( file=filename, exist=alive)
if ( alive ) then
open(unit=fileid, file=filename, &
access="sequential", status="old")
do while(.true.)
read(unit=fileid, fmt="(A79)", iostat=status ) buffer
if ( status/=0 ) exit
!write(*,"(A79)") buffer
count = count+1
if (count<24) then
write(*,"(A79)") buffer
else
!write(*,*) "Please type Enter to continue: "
pause
count=0
!read(*,"(A1)") c
!if (c==char(13)) then
! write(*,"(A79)") buffer
!else
! write(*,*) "This is not the 'Enter' key!!"
! exit
!end if
end if
end do
else
write(*,*) TRIM(filename)," doesn't exist."
end if
stop
end
[Sorry for typing English =,=]
program ex0905
implicit none
character(len=79) :: filename
character(len=79) :: buffer
integer, parameter :: fileid = 10
integer :: status = 0,count=0
logical alive
character(len=1) :: c
write(*,*) "Filename:"
read (*,"(A79)") filename
inquire( file=filename, exist=alive)
if ( alive ) then
open(unit=fileid, file=filename, &
access="sequential", status="old")
do while(.true.)
read(unit=fileid, fmt="(A79)", iostat=status ) buffer
if ( status/=0 ) exit
!write(*,"(A79)") buffer
count = count+1
if (count<24) then
write(*,"(A79)") buffer
else
!write(*,*) "Please type Enter to continue: "
pause
count=0
!read(*,"(A1)") c
!if (c==char(13)) then
! write(*,"(A79)") buffer
!else
! write(*,*) "This is not the 'Enter' key!!"
! exit
!end if
end if
end do
else
write(*,*) TRIM(filename)," doesn't exist."
end if
stop
end
[Sorry for typing English =,=]
[此贴子已经被作者于2014-6-27 4:33:06编辑过]