问题
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