David Leal wrote:
>
> Is it possible with fortran 90 to rewrite in a line?
>
> I would like to do the following:
> to write: a c e
> the to go to previus line and write in the blank spaces b d f and to get
> the following result
> abcdef
>
> I thought to use the following idea but it doesn't work
>
> program graf_prog
> open(unit=10,file='graf.out')
> write(10,'(3(a1,1x))') 'a','c','e'
> rewind 10
> write(10,'(3(1x,a1))') 'b','d','f'
> close(10)
> end program graf_prog
>
> any ideas?
>
> Thanks in advance,
>
> David
I believe that the second write, overwrites the entire line. The write
statement doesn't know not to overwrite when you have a blank in what
you are writing. If it did then when you overwrite an existing file you
have to explicitly set all non-blank characters to blank before
writing. Some people would think this was inconvenient !
I guess the easiest way around your problem would be to read the
original line back into character string, write your new line into a
character string and put the new into the old where there is a blank.
Note that you cannot do this with a where statement since a character
string is not an array. The following seems to work.
Shaun
program graf_prog
integer,parameter::lstring=20
character(len=lstring):: old
character(len=lstring):: new
integer::i
open(unit=10,file='graf.out')
write(10,'(3(a1,1x))') 'a','c','e'
rewind(10)
read(10,'(a)') old
write(new,'(3(1x,a1))') 'b','d','f'
do i=1,len(new)
select case(old(i:i))
case(' ')
old(i:i)= new(i:i)
end select
end do
backspace(10)
write(10,*) old
close(10)
end program graf_prog
--
#####################################################################
Dr Shaun Forth
Applied Mathematics & Operational Research
Cranfield University, RMCS Shrivenham
Swindon SN6 8LA, England
tel: +44 (0)1793 785311
fax: +44 (0)1793 784196
email: [log in to unmask]
http://www.rmcs.cran.ac.uk/departments/dois/amorg/staff/sf/sf.shtml
#####################################################################
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|