Hi all!
I received assistance from Dr Walt Brainerd of the Fortran Company.
See Fortran code for this request:
program Gary
implicit none
character(len=*), parameter :: text = "Gary"
character(len=100) :: line
integer :: gary_unit, ios
logical :: found_it
open (newunit=gary_unit, file="gary_file", &
status="old", action="read", position="rewind")
found_it = .false.
do
read(unit=gary_unit, fmt="(a)", iostat=ios) line
if (is_iostat_end(ios)) exit
if (index(line, text) > 0) then
! Uncomment this "if" test to insert the line just once
! if (.not. found_it) &
write(unit=*, fmt="(a)") "Line to be inserted"
found_it = .true.
end if
write(unit=*, fmt="(a)") trim(line)
end do
end program Gary
Here is the input file "gary_file". Create it with this name, no file extension.
line 1 aaaaaaaaa
line 2 bbbGarybbbb
line 3 ccccccc
line 4 Gary ddddd
line 5 eeee
Here is the output:
line 1 aaaaaaaaa
Line to be inserted
line 2 bbbGarybbbb
line 3 ccccccc
Line to be inserted
line 4 Gary ddddd
line 5 eeee