Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: Outputting integers with minimum width
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))



Report this thread to moderator Post Follow-up to this message
Old Post
Michel OLAGNON
12-15-04 08:59 PM


Re: Outputting integers with minimum width
Michel 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

Report this thread to moderator Post Follow-up to this message
Old Post
Arjen Markus
12-15-04 08:59 PM


Re: Outputting integers with minimum width

Arjen 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

Report this thread to moderator Post Follow-up to this message
Old Post
Gordon Sande
12-15-04 08:59 PM


Re: Outputting integers with minimum width
Gordon 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

Report this thread to moderator Post Follow-up to this message
Old Post
Simon Geard
12-15-04 08:59 PM


Re: Outputting integers with minimum width
Gordon 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

Report this thread to moderator Post Follow-up to this message
Old Post
Arjen Markus
12-16-04 08:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:40 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.