如何使用Fortran 90中的数据填充矩阵

时间:2014-12-16 09:19:56

标签: file matrix fortran fortran90

我有一个问题,也许是愚蠢的,我写的代码。我生成了30个24行的数据集,其中包含不同的值,但这些数据表示相同的度量,但我无法以数组格式打印它们。让我解释一下,我得到一个包含所有值的列,我可以将它们写成24行乘30列的矩阵。我尝试在这个网站和其他网站上阅读各种线程,但我的零值矩阵与我的价值观交替,我该怎么办?以下是我写的代码,试图获得矩阵" a"由" diffu"

的值组成
program deviation
 implicit none

 character(len=20) :: filein,fileout,fileinp
 integer :: row,i,h,io,n,j,l,m,col
 real :: usv,usf,tsv,tsf,su,st
 real :: diffu, difft
 real, dimension(24,30) :: a
 real, dimension(720) :: u
 n = 39
 row = 24
 col = n-9
 write(*,'(2x,''Input file .......''/)')
 read(*,'(a15)') filein
 write(*,'(2x,''Output file........''/)')
 read(*,'(a15)') fileout

 open(unit = 20,File=fileout)

 a = 0.

  fileLoop : do i = 10,n
  fileinp = 'lin*27-'
  write(fileinp, '("lin*27-",I2,".dat")') i
  open(unit = i+40,File=fileinp)
  open(unit = 30,File=filein)

  do j = 1, row
  read(30,*,IOSTAT = io) h,usv,tsv
  read(i+40,*,IOSTAT = io) h,usf,tsf
   if(io/=0) then
    write(*,*) 'End of file!'
   exit
   else if(io==0) then
    diffu = ((usf - usv)**2)
    difft = ((tsf - tsv)**2)
    write(20,*) diffu,difft 

   endif
   enddo
  enddo
 close(i+40)
 close(30)

 enddo fileLoop
 close(20)

 open(unit=20,STATUS='OLD',FILE=fileout)
  do r = 1, 720
  read(20,*,IOSTAT = io) diffu,difft
  u(r) = diffu
  if(io/=0) then
  write(*,*) "Error!"
  exit
  else if(io==0) then
   do m = 1, 24
    do l = 1, col
     a(m,l) = a(m,l) + u(r)

    enddo
   enddo
 endif
 enddo  
 write(*,*) a
 close(20)


end program deviation

0 个答案:

没有答案