This is a discussion on Fortran to edit one line of text file - Fortran ; Due to historical reasons, have a long formated sequential (text) file of data. Need to re-write one of the early header cards. Tried the open and rewrite scheme below, but rest of file disappears after rewriting the required line. So, ...
Due to historical reasons, have a long formated sequential (text) file of
data. Need to re-write one of the early header cards. Tried the open and
rewrite scheme below, but rest of file disappears after rewriting the
required line.
So, short of copying the rest of the file, how can one do this?
File needs to be sequential & formated:
The open is
open( iU, file = cFileName )
write(iU,'(a)') ' VERSION_1 '
write(iU,'(a)') ' some text'
write(iU,'(79a)') cTitle
write(iU,*) rReal, iDum1, iDum2, iDum3
write 1000's of lines of data.
Now, need to change line 4 and keep all data following line 4. The
following deletes all data after line 4.
rewind( iU )
do i = 1, 3
read(iU,*)
enddo
read(iU,*) rReal, iDum1, iDum2, iDum3
backspace(iU)
iDum3 = iNewValue ! change parameter value
write(iU,*) rReal, iDum1, iDum2, iDum3
close(iU)
So, how to change only one line of this data file without reading /
rewriting the entire file.
Thanks.