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!

Help with Format statement

Status
Not open for further replies.

BrooksVH

Programmer
Jul 8, 2009
14
US
Does anybody know how to use format codes to write into a single place on the screen in order to get something that looks like clock hands? I know to use the characters -,\,|,/ to get the desired effect but I need to write them in the same location to get the effect that something is being done.

Thanks,
BrooksVH

 
This works with g95 and gfortran on Windows (MinGW/MSYS)
Code:
[COLOR=#a020f0]program[/color] write2scr
  [COLOR=#804040][b]do[/b][/color] i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color],[COLOR=#ff00ff]100[/color]
    [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(a)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#ff00ff]'\'[/color]
    [COLOR=#a020f0]call[/color] sleep([COLOR=#ff00ff]1[/color]) [COLOR=#0000ff]! wait 1 second[/color]
    [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(a)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#008080]char[/color]([COLOR=#ff00ff]8[/color]) [COLOR=#0000ff]! backspace[/color]
    [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(a)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#ff00ff]'|'[/color]
    [COLOR=#a020f0]call[/color] sleep([COLOR=#ff00ff]1[/color]) [COLOR=#0000ff]! wait 1 second[/color]
    [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(a)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#008080]char[/color]([COLOR=#ff00ff]8[/color]) [COLOR=#0000ff]! backspace[/color]
    [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(a)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#ff00ff]'/'[/color]
    [COLOR=#a020f0]call[/color] sleep([COLOR=#ff00ff]1[/color]) [COLOR=#0000ff]! wait 1 second[/color]
    [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(a)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#008080]char[/color]([COLOR=#ff00ff]8[/color]) [COLOR=#0000ff]! backspace[/color]
    [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(a)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#ff00ff]'-'[/color]
    [COLOR=#a020f0]call[/color] sleep([COLOR=#ff00ff]1[/color]) [COLOR=#0000ff]! wait 1 second[/color]
    [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(a)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#008080]char[/color]([COLOR=#ff00ff]8[/color]) [COLOR=#0000ff]! backspace[/color]
  [COLOR=#804040][b]end do[/b][/color]
[COLOR=#a020f0]end program[/color] write2scr
 
Fortran has for positional editing the descriptors T, TL, TR
but they didn't work on my MSYS console as I expected.
When I tried this
Code:
program write2scr
  do i=1,100
    write (*,'(T1a)',advance='no') '\'
    call sleep(1) ! wait 1 second
    write (*,'(TL1a)',advance='no') '|'
    call sleep(1) ! wait 1 second
    write (*,'(TL1a)',advance='no') '/'
    call sleep(1) ! wait 1 second
    write (*,'(TL1a)',advance='no') '-'
    call sleep(1) ! wait 1 second
  end do
end program write2scr
I got this result
Code:
$ g95 write2scr.f90 -o write2scr

$ write2scr
\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-
 
Mikrom,

Thanks very much-- didn't think about backspace but had tried TL1a before and didn't work.

BrooksVH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top