[Fortran] 纯文本查看 复制代码 module constant
implicit none
integer n,nmax,cnum
character(*):: filename
character*1 sign
integer count
integer error
end module constant
module dealfile
use constant
contains
subroutine totalnum(filename,count,nmax,sign,cnum())
integer count,nmax,i,n,tonum
character*1 buffer(1:nmax)
character(*):: filename
character*1 sign
character,allocatable :: string(:)
integer,allocatable :: cnum(:)
open(10,FILE=filename)
allocate(string(n))
allocate(cnum(n))
do n=1,count
READ(10,100) string(n)
100 format(<nmax>A1)
write(*,*)string(n)
buffer=string(n)
cnum(1)=1
do i=1,nmax-1
if((buffer(i)==sign) .AND. (buffer(i+1)/=sign)) cnum(n)=cnum(n)+1
end do
tonum=tonum+cnum(n)
end do
close(10)
end subroutine totalnum
end module dealfile
program main
use constant
use dealfile
print*,'文件名:'
read*,filename
count=0
open(10,file=filename,status='old')
do while (.true.)
read(10,*,iostat=error) line
if(error/=0)exit
count=count+1
end do
close(10)
print*,'行数:'
write(*,*)count
print*,'行的最大列数:'
read*,nmax
print*,'分隔符:'
read(*,100),sign
100 format(A1)
call totalnum(filename,count,nmax,sign,cnum(n))
print*,tonum
end program
|