how to write a huge matrix to file row by row (fortran 90)

早过忘川 提交于 2019-11-30 10:54:07

expanding on my comment, you should also use an implicit loop..try this:

open(unit=2, file='graph1.txt', ACTION="write", STATUS="replace")
do i=1,N
     write(2, '(1000F14.7)')( real(Vec(i,j)) ,j=1,M)
end do

or for sufficiently modern compilers (I'm not sure how new.. )

     write(2, '(*(F14.7))')( real(Vec(i,j)) ,j=1,M)

Note as has been pointed out, the parenthesis around (F14.7) are required for the * unlimited-format-item in the 2008 standard.

may as well pull in the other comments, you can also do this:

      write(2, '(*(F14.7))')real(Vec(i,:M))

ifort uses a default record length of 80. Everything beyond that is put on the next line. You can extend that at runtime by issueing export FORT_FMT_RECL=250, which extends that to 250 characters. (You need to adjust that number, of course).

But my guess would be the format specifier of your write statement. Did you try writing the matrix row-by-row instead of element-wise? Then you could directly specify the number of elements (instead of using advance='no').

This post might be helpful as well!

EDIT: Writing row-by-row could be realized like this:

open(unit=2, file='graph1.txt', ACTION="write", STATUS="replace")
do i=1,N
  write(2,*) real( Vec(i,:) ) 
end do
close(2)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!