| Tobias 2006-10-30, 7:16 pm |
| Hi,
Sharad_Regmi@hotmail.com wrote:
> My file looks like this; I will have to change some numbers (not text)
> and write the file with a different name.
The following program copies test.dat into out.dat and changes some of
the numbers in the line after 'perm':
--- test.dat 2006-10-30 18:01:09.000000000 +0100
+++ out.dat 2006-10-30 18:15:49.000000000 +0100
@@ -8,3 +8,3 @@
perm
-1 22491 1 6.793e-12 6.793e-12 6.793e-13
+ 1 22491 44 -0.33178293 6.793E-12 6.793E-13
22492 67473 1 1.019e-12 1.019e-12 1.019e-13
program copy
implicit none
integer, parameter :: IN = 66, out = 77
character(len=200) :: str
integer :: iostat, i1, i2, i3
real :: r1, r2, r3
open(in,file='test.dat',status='old',position='rewind')
open(out,file='out.dat',status='new')
do
read(in,'(a)',iostat=iostat) str
if(iostat /= 0) exit
write(out,'(a)') trim(str)
! we now want to change the line after perm
str = adjustl(str) ! remove spaces on the left
if(str(1:5) == 'perm') then
read(in,*) i1,i2,i3,r1,r2,r3
i3 = 44
r1 = sin(real(i2))
write(out,*) i1,i2,i3,r1,r2,r3
end if
end do
close(in)
close(out)
end program copy
|