program main
implicit none
character,allocatable:: A(:,:)
integer:: m,n,nx,ny
character(len=200):: filename
integer:: i,j,iunit,mbc
filename="d:\2.txt"
nx=2
ny=2
allocate(A(nx,ny))
call read_txt(A,1,filename,m,n,nx,ny)
print*,A
end program
subroutine read_txt(input,iunit,filename,m,n,nx,ny)
implicit none
!函数内部变量声明
integer:: iunit,m,n
integer:: nx,ny
character(len=200):: filename
character(len=200):: input(nx,ny)
!局部变量
integer:: i,j
character(len=200):: line
character,allocatable:: temp(:)
open(unit=iunit,file=filename)
read(iunit,"(a)")line
read(line,*)m,n
allocate(temp(n))
do i=1,m
read(iunit,"(a)")line
read(line,*)(temp(j),j=1,n)
do j=1,n
!print*,temp(j)
input(i,j)=temp(j)
enddo
enddo
close(iunit)
end subroutine
QQ图片20190529144606.png (12.16 KB, 下载次数: 198)
subroutine read_txt(input,iunit,filename,m,n,nx,ny)
implicit none
!函数内部变量声明
integer:: iunit,m,n
integer:: nx,ny,i
character(len=200):: filename
character:: input(nx,ny)
!局部变量
open(unit=iunit,file=filename)
read(iunit,*) m,n
do i = 1 , m
read(iunit,*) input(i,:n)
end do
end subroutine
胡文刚 发表于 2019-5-29 15:20
实参的字符串长度是1
character,allocatable:: A(:,:)
虚参的字符串长度是200
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |