[Fortran] 纯文本查看 复制代码
program main
implicit none
integer :: A(5,3), buf(15,1)
integer :: nsize, irow
nsize = 5
A( 1, : ) = [ 5, 4, 8 ]
A( 2, : ) = [ 4, 1, 9 ]
A( 3, : ) = [ 3, 4, 8 ]
A( 4, : ) = [ 1, 2, 8 ]
A( 5, : ) = [ 3, 1, 0 ]
Open(Unit=34, File="TimeLog.txt", Form="formatted", Access="sequential", Position='append', Status="old")
Do irow = 1, 5
write(34,*)A(irow,:)
End Do
Close(34)
Open(Unit=34, File="TimeLog.txt", Form="formatted", Access="sequential", Position='Rewind', Status="old")
write(34,'(I9)')nsize
Close(34)
end
[Fortran] 纯文本查看 复制代码
program main
implicit none
integer :: A(5,3)
integer :: nsize, irow
A( 1, : ) = [ 5, 4, 8 ]
A( 2, : ) = [ 4, 1, 9 ]
A( 3, : ) = [ 3, 4, 8 ]
A( 4, : ) = [ 1, 2, 8 ]
A( 5, : ) = [ 3, 1, 0 ]
Open(Unit=34, File="TimeLog.txt")
write(34,100) 0 !//假设暂时不知道大小,先写入一个 0 占位
Do irow = 1, size(A,1)
write(34,*) A(irow,:)
End Do
Close(34)
nsize = 5
Open(Unit=34, File="TimeLog.txt",form="formatted",access="direct",Status="old",recl=9)
write(34,100,rec=1) nSize
Close(34)
100 format(i9)
end program main