Write matrix with Fortran

我们两清 提交于 2019-12-25 16:38:12

问题


I need to output a matrix with FORTRAN. I have a working code that calculates the values, but instead of a matrix, I get single a column. The matrix is huge, ixj = ~2000x2000.

Here is my sample code:

  open(19, file="results1.txt", status="old", position="rewind", 
 & action="write") 

  do j=0,p
  do i=0,o
  write(19,*) mat_user_yield_surface(d, eps(i), deps(j), 200.0d0)
  end do
  end do

  close(19)

回答1:


Use an implied do loop:

do j=0,p
   write(19,'(2000g22.14)') (mat_user_yield_surface(d, eps(i), deps(j),200.0d0),i=0,o)
end do

I suggest not using "o" as a variable name, since it is easily confused with zero.




回答2:


This "write(19,'(2000g22.14)')" worked perfectly! Thanks. So the final code is:

  open(19, file="results1.txt", status="old", position="rewind",
 & action="write") 

  do j=0,p
  write(19,'(2000g22.14)') (mat_user_yield_surface(d, eps(i), 
 & deps(j), 200.0d0), i=0,o)
  end do

  close(19)


来源:https://stackoverflow.com/questions/28674860/write-matrix-with-fortran

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!