Code Comments
Programming Forum and web based access to our favorite programming groups.
In article <41c046e9$0$78013$ed2619ec@ptn-nntp-reader01.plus.net>, Simon Geard <simon@quint
ic.co.uk> writes:
>I want to output the result of some function evaluations, e.g.
>
>f(2) = [20]
>f(10) = [100]
>
>in java I'd do
>
>System.out.println("f(" + m + " = [" + n + "]");
>
>but I can't find a simple way of doing this in f90 since I don't know
>what the field width is in advance. The only way I can think ofdoing it
>is do dynamically create the format string as in the example below, but
>surely there is an easier way of doing this. Any ideas?
>
write(fmt,'(I20)') n
write(*,'("[",a,"]")') trim(adjustl(fmt))
Post Follow-up to this messageMichel OLAGNON wrote:
>
> In article <41c046e9$0$78013$ed2619ec@ptn-nntp-reader01.plus.net>, Simon G
eard <simon@quintic.co.uk> writes:
>
> write(fmt,'(I20)') n
> write(*,'("[",a,"]")') trim(adjustl(fmt))
Another way is the format '(I0)'. For instance:
program test123
write(*,'(1x,10(i0,''=''))') 1, 234455, 3, -12
end program
gives:
1=234455=3=-12=
Regards,
Arjen
Post Follow-up to this messageArjen Markus wrote: > Michel OLAGNON wrote: > > > > Another way is the format '(I0)'. For instance: > > program test123 > write(*,'(1x,10(i0,''=''))') 1, 234455, 3, -12 > end program > > gives: > 1=234455=3=-12= This is the F95 solution. The question becomes did the OP mean F90 or F95 when the question was posed about f90? It is such a useful feature that it is hard to think that any "Fortran 90" compiler/run time being offered would not in fact be Fortran 95. But there are a few folks who must soldier on with legacy compilers. (Or perhaps they prefer Microsoft Workstation. Or perhaps their PHB does. ;-)) > Regards, > > Arjen
Post Follow-up to this messageGordon Sande wrote: > > > Arjen Markus wrote: > ... > > > This is the F95 solution. The question becomes did the OP mean > F90 or F95 when the question was posed about f90? > > It is such a useful feature that it is hard to think that any > "Fortran 90" compiler/run time being offered would not in fact > be Fortran 95. But there are a few folks who must soldier on with > legacy compilers. (Or perhaps they prefer Microsoft Workstation. > Or perhaps their PHB does. ;-)) > All the compilers I'm using support f95 so thanks very much for this solution - very helpful. Simon
Post Follow-up to this messageGordon Sande wrote: > > Arjen Markus wrote: > > This is the F95 solution. The question becomes did the OP mean > F90 or F95 when the question was posed about f90? > > It is such a useful feature that it is hard to think that any > "Fortran 90" compiler/run time being offered would not in fact > be Fortran 95. But there are a few folks who must soldier on with > legacy compilers. (Or perhaps they prefer Microsoft Workstation. > Or perhaps their PHB does. ;-)) > Oops, I have gotten so used to F95, that this subtle difference to F90 escaped my attention. Yes, it is very useful! Regards, Arjen
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.