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

时间:2016-10-04 10:48:56

标签: matrix file-io fortran fortran77

我有这样的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类似的东西。

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

1 个答案:

答案 0 :(得分:2)

如果文件已经打开(从上一篇文章开始),你可以使用

开始文件的开头
  rewind(unitnumber)

然后再开始写作。它将删除文件的原始内容并重新开始。如果你想回去只是几个记录,你可以使用backtrace(),但你可能不想在这里。

如果它没有打开,只需打开它并开始书写即可。除非您打开附加内容,否则它将覆盖原始内容。