Issues with FORMAT TLn

Issues with FORMAT TLn

Hello,

I have the console application developed to handle large data. Since it takes longer time, I wanted to report % completion. Attached the simple code I tested. Unfortunately, TL4 doesn't work, but it keeps printing continuously (as if TL4 is not added in the format). Can someone help me fixing this?

Thanks,
Mohan

!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PROGRAM test
   
    IMPLICIT NONE
    INTEGER    :: i
   
    WRITE(*,'(A,$)') 'Completion ...  0%'
    DO i = 1,10000
        WRITE(*,'(TL4,I3,A,$)') INT(i*100/10000),'%'
    END DO
    WRITE(*,*)
   
END PROGRAM test

 

3 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项
Steve Lionel (Intel)的头像

You can't do it that way. The left margin (for the TL) is reset for each of the WRITEs in the loop. All the $ does is prevent a newline from being written as well.

One way to do this sort of thing is like this:


PROGRAM test
    IMPLICIT NONE

    INTEGER    :: i
    WRITE(*,'(A)',ADVANCE='NO') 'Completion ...  0%'

    DO i = 1,10000

        IF (MOD(I,1000) == 0) THEN

          WRITE (*,'(A,I0,A)',ADVANCE='NO') '..',I/100,'%'

        END IF

    END DO

    WRITE(*,*)
END PROGRAM test

Steve
Best Reply

Thanks Steve. Using ADVANCE='NO', I got the idea using backspace through ACHAR. Following code worked for me and this solves the problem.

-----------------
PROGRAM test

IMPLICIT NONE

INTEGER :: i

WRITE(*,'(A)',ADVANCE='NO') 'Test Start ... 0%'
DO i = 1,10000
WRITE (*,'(A,I3,A)',ADVANCE='NO') REPEAT(ACHAR(8),4),I/100,'%'
END DO

END PROGRAM test

登陆并发表评论。