title: How to fill a matrix with data in Fortran 90
body: <p>I have an issue, maybe stupid, with a code that I wrote. I generated 30 datasets of 24 lines containing different values that represent, however, the same measure, but I can not print them in array format. Let me explain, I get a single column with all the values, I would be able to write them as a matrix of 24 rows by 30 columns. I tried to read various threads on this site and on others, but I got matrices of zeros alternating with my values, how can I do? The following is the code I wrote with trying to get the matrix "a" formed by the values of "diffu"</p>
  
  <pre><code>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
  </code></pre>