View previous topic :: View next topic |
Author |
Message |
GeoffreyBernardo
Joined: 14 Sep 2009 Posts: 2
|
Posted: Sat Sep 19, 2009 11:31 am Post subject: How do I overwrite the current line on console screen? |
|
|
I want to display the progress of a calculation done with a DO-loop, on the console screen. I can print out the progress variable to the terminal like this:
Code: |
PROGRAM TextOverWrite_WithLoop
IMPLICIT NONE
INTEGER :: Number, Maximum = 10
DO Number = 1, MAXIMUM
WRITE(*, 100, ADVANCE='NO') REAL(Number)/REAL(Maximum)*100
100 FORMAT(TL10, F10.2)
! Calcultations on Number
END DO
END PROGRAM TextOverWrite_WithLoop |
The output of the above code on the console screen is:
10.00 20.00 30.00 40.00 50.00 60.00 70.00 80.00 90.00 100.00
All on the same line, wrapped only by the console window.
The ADVANCE='No' argument and the TL10 (tab left so many spaces) edit descriptor works well to overwrite text on the same line, e.g. the output of the following code:
Code: | WRITE(*, 100, ADVANCE='NO') 100, 500
100 FORMAT(I3, 1X, TL4, I3) |
Is:
500
Instead of:
100 500
Because of the TL4 edit descriptor.
From these two instances one can conclude that the WRITE statement cannot overwrite what has been written by another WRITE statement or by a previous execution of the same WRITE satement (as in a DO-loop).
Can this be overcome somehow?
I am using the FTN95 compiler on Windows 7 RC1. (The setup program of the G95 compiler bluescreens Windows 7 RC1, even thought it works fine on Vista.)
Thanks in advance. |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Mon Sep 21, 2009 12:34 am Post subject: |
|
|
The following works on my XP cmd.exe dos box. You may be able to adapt it to work on W7. Let us know if it does.
Code: | character cr, string*8
integer*4 number, maximum
cr = char (13) ! CR
maximum = 50
do number = 1,maximum
write (string,1001) REAL(number)/REAL(Maximum)*100
call coua@ (cr)
call coua@ (string)
call sleep@ (0.1)
end do
1001 format (f8.2)
end
|
|
|
Back to top |
|
 |
GeoffreyBernardo
Joined: 14 Sep 2009 Posts: 2
|
Posted: Tue Sep 22, 2009 6:49 pm Post subject: Re: |
|
|
Hi John,
Thanks for your effort, but I only get the cursor blinking in place at the beginning of an empty line.
I do not understand the variable named string that you use as the first argument of the WRITE statement. If I want to write to the screen, should I not have the * as the first argument? |
|
Back to top |
|
 |
brucebowler Guest
|
Posted: Tue Sep 22, 2009 7:41 pm Post subject: |
|
|
the 'write(string,1001)...' is an "internal write" which actually "writes" to the string. The coua@ is what (should) cause the string to appear on the console. |
|
Back to top |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Sun Sep 27, 2009 5:05 pm Post subject: |
|
|
I tried the suggestion from John. Works fine. However, is there perhaps a possibility to place the cursor at some specified place on the screen? I know from from older program versions (internal software) that the cursor was placed at some pre-defined location to display the program status.
The section in the documentation FTN95 Library -> Console input and output only explains commands which are location (xy position on the screen) independant. Are there perhaps some console functions which needs the xy location on the screen? Or perhaps Clearwin? |
|
Back to top |
|
 |
|