Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How write several times on the same line?

Status
Not open for further replies.

finjawa

Programmer
Aug 21, 2006
4
FI
Hi!

I couldn't find anywhere how to write several times on the same line or how to read and write on the same line (for example first write c:\ and then read the input). I have thought about this before but have always been able to bypass it somehow. At the moment I would need this to make a status bar for program of scientific calculation.

Thank you in advance!
 
I am assuming you only want to go forwards and not backwards. If so, when writing use advance='no'.
Code:
      program progress
      integer complete
      do complete = 1, 39
         write (*, 10, advance='no')
10       format ('X')
      enddo
!     Newline to complete
      write (*, 10)
      stop
      end
 
It helped - thank you! But I would also be interested in going backwards. I tried BACKSPACE but I just ended up with illegal seek error message. Can this command be used in this contex?
 
Okay, I found one way to go backwards

WRITE(*,'(A)',ADVANCE='NO')8

which prints a backspace. However, for some reason this cannot be used to for example indicate progress. So loop

DO i=1,10000
IF (MODULO(i,100)==0)
WRITE(*,'(A)',ADVANCE='NO')8
WRITE(*,'(A)',ADVANCE='NO')i/100
END IF
END DO

would write everything after the loop is done! With a program that does nothing else you don't see this as it runs too fast but when I inserted a similar loop into my program (which is relatively heavy) it just showed the end result (100).
 
The problem with what you've done is printing i/100 in A format. It will go through the full ascii sequence. Try this one. It seems to work OK on a 160MHz P1. You may need to increase the delay to see any effects
Code:
      program progressmeter
      integer PROGINIT, PROGRUN, PROGDONE
      parameter (PROGINIT=1, PROGRUN=2, PROGDONE=3)
      call progress(PROGINIT)
      do i = 1, 20
         call delay
         call progress(PROGRUN)
      enddo
      call progress(PROGDONE)
      stop
      end

      subroutine progress (stage)
      integer stage
      integer PROGINIT, PROGRUN, PROGDONE
      parameter (PROGINIT=1, PROGRUN=2, PROGDONE=3)
      character*3 bsp
      integer complete
      save bsp, complete
      select case (stage)
      case (PROGINIT)
!        initalize
         bsp(1:1) = char(8)
         bsp(2:2) = char(8)
         bsp(3:3) = char(8)
         complete = 0
      case (PROGRUN)
!        progress
         complete = complete + 5
         write (*, 20, advance='no') bsp, complete
20       format (A3,I3)
      case (PROGDONE)
!        done
         write (*, 20) bsp, complete
      end select
      return
      end

      subroutine delay
      integer waiter
      x = 1E38
      do i = 1, 200
      do waiter = 1, 30000
         x = x / 9.0
      end do
      enddo
      return
      end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top