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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

flexible Progressbar with Fortran

Status
Not open for further replies.

foruser00

Programmer
Mar 23, 2008
8
DE
Hi,

I want to write a progressbar.
The vertical position depends on what has been written in the shell before the program prints the following line.
The progress shall be described with a bar and number (50%). Therefore I need to jump with the cursor....

Example:

** Copying dataset to ... [===========...........] - [50%]


**********************************************************
- How can I access a relative (x,y)-position? This is (to my mind) necessary if I want to update to progress bar and the status (50%).
Has anybody an idea how I can solve this problem?

Thanks a lot
 
This is very OS/Compiler dependent

1) Which OS (Windows 9x, XP, Vista, Linux, Solaris) are you using
2) Which compiler are you using
3) Is this meant to work in a DOS box/xterm/ANSI compatible terminal?
 
If you are using xterms or any of the ANSI compatible terminal emulators, you can use the ANSI primitives (also available if you use curses). It is basically ESC [ row;col f or ESC [ row; col H.

 
and if I need to jump to column x=90 (and I do not know the number of characters/signs which I have already written in the line...)?
 
That escape sequence will jump to a specific position on the console. As long as you have an x (column) and y (row) position, it will go there. Just remember that x and y are the wrong way round.
 
Ok,

here is my example.
The subroutine gotox(..,..) shall print a string at position X=X-LEN_TRIM(str).
Unfortunately, I cannot replace the characters "81" by // strhlp(1:LEN_TRIM(strhlp)) // ...

SUBROUTINE GOTOX(X, STR)
!
INTEGER, INTENT(in) :: x
CHARACTER (LEN=*), INTENT(in) :: str
!
INTEGER :: xhlp
!
CHARACTER :: strhlp
!
INTRINSIC LEN, LEN_TRIM, TRIM
!
xhlp = 81 !X - trim(adjustl(STR))
write (xhlp,*) strhlp
! write(*,*) "strhlp", strhlp
strhlp="91"
!
print *,CHAR(27) // "[2A"
print *,CHAR(27) // "[81C", "[ " // str(1:LEN_TRIM(str)) //" ]"
!
RETURN
END SUBROUTINE GOTOX

PROGRAM MAIN
write(*,*) "Copying data to xxxx..."
CALL GOTOX(90,"100%")
END PROGRAM MAIN
 
Is there an opportunity to get the maximum number of columns?
 
To put a @ at row 10, column 50
Code:
print *, char(27) // '[10;50H' // '@'
There is probably an ansi sequence to get the screen width. I can't find it in but that doesn't mean there isn't one. There are over 461000 hits so there might be one somewhere.

As you've discovered, the numbers need to be trimmed with no spaces between the [ and ; and H.

The difference between f and H is that f moves the cursor but H doesn't. H just puts the character at the specified position without moving the cursor.

If you have access to curses from Fortran, it may be worth using that.
 
Excuse me, but I think we are still talking about different things.

Again, I am writing a line with write(*,*) "..." on the screen. The subroutine GOTOX shall print in the same line (wherever it is) at position xhlp=X-len_trim(str) the string str.
For instance X may be 90 and str="100%". This leads to:
*********************************************************
Copying data to xxxx... [ 100% ]
*********************************************************

That is why it does not make sense to set a specific row-number.
Moreover the column-number must be a value because the string-length is not always 4 (like str="100%" or str="99%").
 
Sorry, misunderstood the problem.

Do you want to keep on overwriting the same line? If you do, you can use advance='no' and output a char(13) before printing the line.

The problem here is that if you output a space, it doesn't always overwrite the chacter underneath. You might have to use underscores (char(95))
 
Yes, now we are talking about the same thing.

Could you just give an example with a variable x-position.
How do you copy the x-position into the print-statement???

I think I will have no problems with blanking since I want to write [ 1% ], [ 10% ], [ 100% ].
As you can see the text is getting always bigger. So you will not see what was below...
 
It is basically a combination of

1) advance='no'
2) the T format
3) a carriage return at the end of line

This is in F77 because I can't be bothered to wait for the machine with F90/F95 to boot up.
Code:
      program main
      integer tagmax
      parameter (tagmax = 5)
      character*10 tag(tagmax)
      data tag/ 'the', 'quick', 'brown', 'fox', 'jumps'/
      integer tt
      character*1 cr
      cr = char(13)

      ! Example of fixed text
      do tt = 1, tagmax
         write (*, 100, advance='no') tag(tt), tt * 20, cr
100      format ('Copying ', A,'[ ', I3, '% ]',A)
      end do
      write (*,*)

      ! Example of variable text
      do tt = 1, tagmax
         write (*, 100, advance='no') trim(tag(tt)), tt * 20, cr
      end do
      write (*,*)

      ! Example of variable text with fixed position
      do tt = 1, tagmax
         write (*, 110, advance='no') trim(tag(tt)), tt * 20, cr
110      format ('Copying ', A, T32,'[ ', I3, '% ]',A)
      end do
      write (*,*)

      stop
      end
 
Hi,

thanks for the little program.

One last question - can you replace the number of tabulators T32 by a variable???
 
No but there is a sneaky way of doing it
Code:
character*32 fmtstr
! Set the tab position in the format string
write (fmtstr, "('Copying ', A, T",I0,",'[ ', I3, '% ]',A)") posn
! Use the modified format string
write (*, fmtstr) whatever
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top