Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29234 Discussions

How does one overwrite text on the console?

geoffreybernardo
Beginner
1,273 Views
I want to show, in percentages,the progresswith a calculationdone in a DO-loop. Instead of having a new line for each percentage, I want the new percentage to overwrite the same percentage on the same line. This is what I have so far, but it does not work:

[cpp]DO Number = 1, Maximum
    WRITE(*, 100, ADVANCE = "No") REAL(Number)/REAL(Maximum)*100
    100 FORMAT(TL10, F10.2)
END DO








[/cpp]
0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,273 Views
This works:

[plain]OPEN (UNIT=6,FORM='FORMATTED',CARRIAGECONTROL='FORTRAN')
MAXIMUM = 100 
DO Number = 1, MAXIMUM
 WRITE(6, 100) REAL(Number)/REAL(Maximum)*100  
 100 FORMAT('+', F10.2)  
 END DO 
 END[/plain]
The '+' carriage control character is for "overprinting". You have to ask for 'FORTRAN' carriage control, however, as that is not the default. I will note that carriage control was deleted from the Fortran 2003 standard, but it is still supported by Intel Fortran. The CARRIAGECONTROL keyword for OPEN is non-standard.
0 Kudos
geoffreybernardo
Beginner
1,273 Views
Thank you, Steve. But how do I write it to the console? With the OPEN statement, it seems to write to a file.

EDIT:
No problem. I found the argument FILETYPE = 'TTY' for the OPEN statement.
0 Kudos
Steven_L_Intel1
Employee
1,273 Views

Opening unit 6 should write to the console. It does for me.
0 Kudos
jirina
New Contributor I
1,273 Views
I have a very old code where following is used and works well if you want to stay on 1 line when writing to the console:
[cpp]write(*,'(1h+,a,f5.1,a)') 'Progress: ', pct, '%'[/cpp]
1h+ does the trick, but I am not sure if it is not something what should not be used.
0 Kudos
TimP
Honored Contributor III
1,273 Views
Quoting - jirina
I have a very old code where following is used and works well if you want to stay on 1 line when writing to the console:
[cpp]write(*,'(1h+,a,f5.1,a)') 'Progress: ', pct, '%'[/cpp]
1h+ does the trick, but I am not sure if it is not something what should not be used.
It's exactly equivalent to Steve's suggestion, except that you are mixing a Fortran 66 feature which was removed from f77, and an f77 feature which wasn't present in f66, so you depend on a compiler which supports this mixture.
0 Kudos
yingwu
Beginner
1,273 Views
This works:

[plain]OPEN (UNIT=6,FORM='FORMATTED',CARRIAGECONTROL='FORTRAN')
MAXIMUM = 100
DO Number = 1, MAXIMUM
WRITE(6, 100) REAL(Number)/REAL(Maximum)*100
100 FORMAT('+', F10.2)
END DO
END[/plain]
The '+' carriage control character is for "overprinting". You have to ask for 'FORTRAN' carriage control, however, as that is not the default. I will note that carriage control was deleted from the Fortran 2003 standard, but it is still supported by Intel Fortran. The CARRIAGECONTROL keyword for OPEN is non-standard.


Hi, Steve. This is so so useful. I have been looking for this for a long long time. Thanks
0 Kudos
Reply