Hello all,
David R. Leal Valmana wrote:
...
> 1. How can I put a variable format code repetition?
...
> I use the following sentence
> write(*,'(<n>f3.1)') a(1:n)
> it works under HP-UX 10.20 fortran, but under DVF
> it gives me sometime problem,then
> Is the form <n> also from the standard fortran?
No, which is probably why DVF is giving you problems.
> if not,
> how can I use a variable format code repetition with the
> standard fortran(ISO-ANSI).
The typical way is to use a character variable to contain the format string,
and use "internal writes" into the string to fill in the variable pieces of
the format, as follows:
integer :: n = 2
character( len=20 ) :: fmt_str = '('
!...
write( fmt_str(2:20), * ) n, 'f3.1)'
!...
write( *, fmt_str) a(1:n)
> NOTE:
> I was looking in the following book and I did not find
> the information about the variable format code
> repetition.
>
> Fortran 95 handbook : complete ISO-ANSI reference / Jeanne C. Adams
> ... [et
> al.]. -- Cambridge (Massachusetts) [etc.] : MIT Press, [1997]
> 711 p. ; 23 cm. -- (Scientific and engineering computation series)
> ISBN 0262510960
This is actually more of a Fortran 77 issue than a Fortran 90/95 issue, since
everything in my example (except the variable initializations and the
*LIST-DIRECTED* internal write) is part of the F77 standard.
> 2. How can I write in a file a vector in column form without restricting
> an especific
> format(type,length and width). If I use:
> write(10,*) vector
> it writes in row format
> does not work:
> write(10,()) vector
> so I have to add some format to my output vector:
> write(10,'(f3.1)') vector
> but for writing in row form I do not need such especification about
> the format code.
If I truly understand you correctly, you wish to write out a single column of
numbers, with each number in a list-directed form. Again, this is a Fortran
77 problem in a sense, and it too has a Fortran 77 solution:
do i = lbound(vector,1), ubound(vector,1)
write( 10, * ) vector( i )
end do
This is not a very efficient way to do I/O on most systems, but I doubt that
formatted I/O of vectors is a bottleneck in most Fortran programs.
> Thanks in advance,
You're welcome. I hope this helped.
-- Roger Glover
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|