将矩阵更新到文本文件中而不附加结果

Update a matrix into a text file without appending the results

我有一个类似这样的 Fortran 77 代码,或多或少:

nMaxRow=100
nMaxStep=100
! initialization of the matrix if Step=1
do step=1,nMaxStep

   if (step.eq.1) then
      do ii=1,nMaxRow
         do jj=1,nMaxStep
            A(ii,jj)=0
         end do
      end do
   end if


!now for each step and for each row update the cell of the matrix
   do ii=1,nMaxRow
      A(ii,step)=X(ii)  !X(ii) is a number associated with the specific ow at that specific step
   end do

!Now I want to write the updated matrix at this step into a text file,
!How can I do that????

end do   !close the do step... 

是否可以更新矩阵的值并将更新后的矩阵在特定步骤写入文本文件?我的意思是,不附加每一步的结果...

我发现 Fortran 90 存在 'REPLACE' 命令...但我找不到 Fortran 77 的任何类似命令。

一个简单的想法是在写入新文件之前删除文件...但我不喜欢它,而且我也不知道该怎么做。

如果文件已经打开(从之前的写作开始),您可以使用

转到文件的开头
  rewind(unitnumber)

又开始写了。它将删除文件的原始内容并重新开始。如果你只想返回几条记录,你可以使用 backtrace(),但你可能不想在这里使用它。

如果没有打开,就打开它开始写吧。除非打开或追加,否则会覆盖原来的内容。