Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

how to modify an output file

Zhanghong_T_
Novice
427 Views
I have a group of data to be output. Some of the data must be write at the beginning of the file, but the data may be changed after I wrote other data. How can I change the file in Fortran?
integer i, j
integer ij(2, 20)
....
open(1, file='test.txt')
i=10
write(1,*)i
do j=1, 20
write(1,*)ij(:,j)
enddo
...
i=100 ! this means i have changed
! ????????????
! what should I do to modify the beginnig of the file 'test.txt' but need
! notrewrite other data?
! ????????????
close(1)
Thanks,
Zhanghong Tang
0 Kudos
4 Replies
TimP
Honored Contributor III
427 Views
Use a direct access file.
0 Kudos
Zhanghong_T_
Novice
427 Views
Thank you very much!
Can you give more detailed example? or just modify my code given above?
0 Kudos
TimP
Honored Contributor III
427 Views
http://www.navo.hpc.mil/pet/Video/Courses/f90/Extra/dafor.html
Basically, supply the access='direct', form='formatted', and recl=.... keywords in your OPEN(), WRITE the file record by record, and keep track of the specific record numbers which you will want to update. While not the most common form of WRITE, this has been supported for a very long time.
0 Kudos
Steven_L_Intel1
Employee
427 Views
Be aware that the file will not be something you can type or print, as it will not have line delimiters. If you want line delimiters, add the /fpscomp:general option.
0 Kudos
Reply