Silverfrost Forums

Welcome to our forums

How do I overwrite the current line on console screen?

19 Sep 2009 10:31 #4990

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:

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:

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.

20 Sep 2009 11:34 #4997

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.

      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
22 Sep 2009 5:49 #5014

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?

27 Sep 2009 4:05 #5050

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?

Please login to reply.