| 先贴代码 
 [Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode 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
 上面代码中,数组A()有5行,就想在 TimeLog.txt 的开头写入一个整数,此数表示后面有5行数据。
 上面代码写入nsize后会把前面写入的A都覆盖掉,不知道有没有什么办法,能否不覆盖?我尝试过在写入A之前,先写入一个空行,再写入A,最后再在开头写入nsize。但仍然会覆盖掉A。
 因为另外一个程序想读入这个文件,但想在一开头读入这个nsize,从而分配数组大小,再读入A()的内容。
 
 |