Write Matrix to File
- Suppose we have a matrix that we want to write to a file. The following code snippet will do that.
integer, intent(in) :: N
real(kind=8), intent(in), dimension(N,N) :: mat
character (len=*), intent(in) :: fname
integer :: i
end subroutine mat_w2f
It simply writes each entry of a matrix to a line in the file.
The reason for using
len=* is that we have a variable string input.
Note this is a simply hack to dump as an ASCII file. It's better to use a binary output (I use NetCDF)
- Formatted version
- Some references
Write Formatted Complex Number
- Suppose we want to output a nicely formatted complex number for output