作者UDP (阿猫)
看板Fortran
标题Re: [问题] 未知大小矩阵读取的问题
时间Tue Aug 11 23:31:32 2009
※ 引述《openfire (疲惫...)》之铭言:
: 我尝试使用terryys版友的建议写出来了
: 在这边野人献曝一下
: program main
: implicit none
: integer n,i
: character row
: real,allocatable:: a(:,:)
: n=0 !先读取档案判断矩阵阶数
: open (11,file='matrix.txt',status='old')
: do while(.not. eof(11))
: read(11,*) row
: n=n+1
: enddo
: allocate ( a(n,n) )
: rewind(11) !将读取位置回到档案开头
: do i=1,n !将档案读进矩阵中
: read(11,*) a(:,i)
: 11 format (I3)
: enddo
: write(*,*)'The input matrix a =' !先在萤幕上print出读取的档案状况
: write(*,*) a !以确认读取无误
: end
: 不过老实说我对於a(:,i)的意思还并不是很了解
: 刚刚翻了一下书也没找到这个指令的详细说明
: 还是请高手们给点方向吧! 感谢
: 再次跟提供意见的板友们致谢^^
program main
implicit none
integer n,i,j
character row
real*8,allocatable:: a(:,:)
n=0 !先读取档案判断矩阵阶数
open (11,file='test.txt',status='old')
do while(.not. eof(11))
read(11,*)row
n=n+1
end do
allocate ( a(n,n) )
rewind(11) !将读取位置回到档案开头
do i=1,n !将档案读进矩阵中
read(11,*) a(i,:)
end do
do i =1,n
do j= 1,n
write(*,"(a2,i1,a1,i1,a2,f5.3)")'a(',i,',',j,')=',a(i,j) !以确认读取无误
end do
end do
end program
修改了你的程式码,我觉得这样写比较对....= =
可是按照你提出的方法,只能用於row=column的方阵
对於row,column不相等的矩阵,还是难以抓出....
--
猫の会社卖场
http://class.ruten.com.tw/user/index00.php?c=&m=&o=&p=&s=auto_cat
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.127.181.230
※ 编辑: UDP 来自: 140.127.181.230 (08/12 00:31)
1F:推 openfire:恩..的确如此,row,column不相等的方阵再未知情况下应该 08/12 02:48
2F:→ openfire:是如您所言 无解的样子Orz 08/12 02:49
3F:→ openfire:Semisphere提供的意见我正在尝试中 搞不好有机会弄得出来 08/12 02:50