How to format a PRINT or WRITE statement to overwrite the current line on the console screen?

I want to display the progress of a calculation done using DO-loop on the console screen. I can print the progress variable on the terminal as follows:

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:

10.00 20.00 30.00 40.00 50.00 60.00 70.00 80.00 90.00 100.00

All in one line, wrapped only in the console window.

The argument ADVANCE = 'No' , and TL10 (the tab left so many spaces), the edit descriptor works well to overwrite text on the same line, for example. output of the following code:

WRITE(*, 100, ADVANCE='NO') 100, 500
100 FORMAT(I3, 1X, TL4, I3)

There is:

500

Instead:

100 500

Due to TL4 edit descriptor.

, WRITE , WRITE, WRITE ( DO-loop).

- ?

FTN95 Windows 7 RC1. ( G95 bluescreens Windows 7 RC1, , Vista.)

Fortran 95, , , ; , .

.

+5
4

Fortran . , Fortran (GNU Fortran , -fbackslash),

  write (*,"(A)",advance="no") "foo"
  call sleep(1)
  write (*,"(A)",advance="no") "\b\b\bbar"
  call sleep(1)
  write (*,"(A)",advance="no") "\b\b\bgee"
  call sleep(1)
  write (*,*)
  end

(\b) .

NB: advance="no", , , $ .

+3

ACHAR(13) .

          character*1 creturn
    !   CODE::
          creturn = achar(13)  !  generate carriage return
    !   other code ...
          WRITE( * , 101 , ADVANCE='NO' ) creturn , i , npoint
101     FORMAT( a , 'Point number : ',i7,' out of a total of ',i7)
+8

g95 fortran:

      NF = NF + 1
      IF(MOD(NF,5).EQ.0) WRITE(6,42,ADVANCE='NO') NF, ' PDFs'//CHAR(13)
  42  FORMAT(I6,A)

:    5 PDF

# 1 . , 5 10. ASCII 13 () .

0
OPEN(6,CARRIAGECONTROL ='FORTRAN')
DO I=1,5
WRITE(6,'(1H+" ",I)') I
ENDDO
-1

All Articles