- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Suppose I have a stiuation like this:
integer q(1:20),nq,nx
realx(1:20)
print 101,x(1:nx), q(1:nq)
101 format("x=",4F20.12," q=",4I10)
This works fine as long as nx=4, and nq is <= 4.
But if those values change, I want the FORMAT statement to reflect that.
The way I now handle that is to modify the FORMAT statment at execution time by
putting it in a CHARACTER array.
Has Fortran come up with a cleaner way to do this? I couldn't find anything.
integer q(1:20),nq,nx
realx(1:20)
print 101,x(1:nx), q(1:nq)
101 format("x=",4F20.12," q=",4I10)
This works fine as long as nx=4, and nq is <= 4.
But if those values change, I want the FORMAT statement to reflect that.
The way I now handle that is to modify the FORMAT statment at execution time by
putting it in a CHARACTER array.
Has Fortran come up with a cleaner way to do this? I couldn't find anything.
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The Fortran standard doesn't have a cleaner way of doing what you want. In some circumstances, the Fortran 2008 "unlimited group repeat count" feature can help, but not here.
Intel Fortran supports an old extension that does what you want, called Variable Format Expressions. The syntax would be:
101 format("x=".F20.12,"q=",I10)
This extension is widely implemented, but not universally so.
Intel Fortran supports an old extension that does what you want, called Variable Format Expressions. The syntax would be:
101 format("x=".
This extension is widely implemented, but not universally so.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, I will try that. Thanks ! !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No - what goes inside the <> is just an ordinary expression.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For your specific example you could do something like the following, without having to resort to extensions:
[bash] WRITE (*, "('x=',*F20.12)", ADVANCE='NO') x(:nq) WRITE (*, "(' q=',*I10)") q(:nq)[/bash]
[bash] WRITE (*, "('x=',*F20.12)", ADVANCE='NO') x(:nq) WRITE (*, "(' q=',*I10)") q(:nq)[/bash]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dang - I should have thought of that! Thanks, Ian!

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page