Re: fortran program reading an external text (and numbers) file and writing with edits



Hi,

Sharad_Regmi@xxxxxxxxxxx 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

.



Relevant Pages

  • Re: How do I exit my program at any time?
    ... I can put at the beginning or the end, that says my program to exit ... str = super ... Or if you are not comfortable with redefining methods in Kernel, ...
    (comp.lang.ruby)
  • Re: replace letter o with 0
    ... print $str; ... Its giving desired output. ... if it is "9o28" it should be changed to 9028 with perl. ...
    (perl.beginners)
  • Re: Record Problem
    ... > IMPLICIT NONE is used earlier in the file, ... How long is str? ... As you are using list-directed formatting, the resulting string can ...
    (comp.lang.fortran)
  • Free System memory
    ... I have a sources code like this: ... var P1,P2:integer; ... P1:= System.Pos, Str); ... if P1=0 then exit; ...
    (borland.public.delphi.nativeapi)
  • Re: hit return key without input
    ... input supplied from the keyboard before pressing enter key? ... implicit none ... read') str ...
    (comp.lang.fortran)