- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am running a simulation of which I would like to print the value of a current variable to stdout (integration time step), such that I can have a "running" counter on the console.
I have to admit that I am not too used to the FORMAT concept of FORTRAN but I guess I understood the issue with the "1X" etc. I some documentation I found that putting the character "+" instead of a blank or a "1X" will result in printing the given value in the same line. I thought that might do the trick.
As a simple example I would like to print the values of k as a counter to stdout:
DO k=1,100
WRITE(*,100) k
100 FORMAT (1X, I3)
ENDDO
which is nice if I want all the numbers below each other. But what I would like to have is that in each iteration of the loop, the previous value of k is overwritten "on top" of the previous value of k.
My idea was to place the identifier "+" (as found in a FORTRAN book) as the first character of the output line to tell the "printer" to "not go" into a new line. But with that I get error messages from the compiler.
My idea was:
DO k=1,100
WRITE(*,100) k
100 FORMAT (+, I3)
ENDDO
such that the output line internally lokks like "+###" such that no new line is started. I can find the "+" in some docs but no code example where it is used.
I hope I explained the problem thoroughly and that somebody can give me a hint.
Thanks in advance
Bastian
I have to admit that I am not too used to the FORMAT concept of FORTRAN but I guess I understood the issue with the "1X" etc. I some documentation I found that putting the character "+" instead of a blank or a "1X" will result in printing the given value in the same line. I thought that might do the trick.
As a simple example I would like to print the values of k as a counter to stdout:
DO k=1,100
WRITE(*,100) k
100 FORMAT (1X, I3)
ENDDO
which is nice if I want all the numbers below each other. But what I would like to have is that in each iteration of the loop, the previous value of k is overwritten "on top" of the previous value of k.
My idea was to place the identifier "+" (as found in a FORTRAN book) as the first character of the output line to tell the "printer" to "not go" into a new line. But with that I get error messages from the compiler.
My idea was:
DO k=1,100
WRITE(*,100) k
100 FORMAT (+, I3)
ENDDO
such that the output line internally lokks like "+###" such that no new line is started. I can find the "+" in some docs but no code example where it is used.
I hope I explained the problem thoroughly and that somebody can give me a hint.
Thanks in advance
Bastian
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are using Fortran carriage control, which is not the default (and which is deprecated in the Fortran standard.) To use this, you must write to a numbered unit (such as 6) which you have opened with the option CARRIAGECONTROL='FORTRAN'. Please note that this type of carriage control was defined in the era of line printers and it can have odd effects when displayed on monitors.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve!
Thanks for your reply. I am aware that the concept of the carriage control is an old one, but I guessed that it might be preserved as an easy-to-understand concept.
I don't have to stick to my solution, I am grateful to a hint towards a more standard-conform solution. As far as I see, the standard output always assumes to output on a new line (and so far I could not find a solution to suppress that).
Can you give me a hint?
Thanks in advance
BAstian
Thanks for your reply. I am aware that the concept of the carriage control is an old one, but I guessed that it might be preserved as an easy-to-understand concept.
I don't have to stick to my solution, I am grateful to a hint towards a more standard-conform solution. As far as I see, the standard output always assumes to output on a new line (and so far I could not find a solution to suppress that).
Can you give me a hint?
Thanks in advance
BAstian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is no standard-conforming solution to this. Some might think that "non-advancing I/O" would do it, but the standard does not specify that partial records "become available" until the final advancing write is done. You can do it this way, though, without requiring Fortran carriage control:
use ifport ! For SLEEPQQ
do i=1,10
write (*,'($,I0)') i
call sleepqq(1000)
end do
write (*, *) 'Done'
end
The $ format means "suppress new line at the end of this write" and is an extension.
use ifport ! For SLEEPQQ
do i=1,10
write (*,'($,I0)') i
call sleepqq(1000)
end do
write (*, *) 'Done'
end
The $ format means "suppress new line at the end of this write" and is an extension.

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