胡文刚 发表于 2019-5-29 15:20 啊啊,就是这样,万分感谢,我自己马大哈了,没注意到。之前为了排除问题就先读入了temp。再次感谢!! |
实参的字符串长度是1 character,allocatable:: A(:,:) 虚参的字符串长度是200 character(len=200):: input(nx,ny) 自然就错了。 另外,你为什么先读到 temp 里?不能直接读到 input 里吗? [Fortran] 纯文本查看 复制代码 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 |
捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )
GMT+8, 2024-11-23 20:46