Re: progress bar in fortran
- From: Mark Mackey <markm@xxxxxxxxxxxxxxxxxxxxxx>
- Date: 03 Apr 2008 12:14:08 +0100 (BST)
In article <d46a483c-164d-4cd8-8f4e-04bb0ca26566@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
rudra <bnrj.rudra@xxxxxxxxx> wrote:
is there any way to generate something like that using fortran? where
the progress percentage will update in the same line?
Probably non-standard, but writing char(13) writes a carriage-return
which moves the cursor back to the start of the line.
Really crappy somewhat non-standard F77 code follows: works under g77 on
linux and IRIX and IFC on Linux. It uses an external C function
hires_time() to get a double precision time value (secs since the epoch
in our case): I'm sure you can roll your own version, and there may
well be an F90/F95 equivalent.
Not thread safe. Use at own risk. Warranty void if protective sticker
removed. You should really be using something more modern than F77
anyway :).
c print a 'progress bar' to unit 0.
c Call with ndone=0 before each bar starts
c Call with ndone=ntotal to finish
c
subroutine progress(string,ndone,ntotal)
implicit none
character*(*) string
character*255 prog,oldprog
double precision oldtime,hires_time,tl
integer ndone,ntotal,i
save oldprog,oldtime
if (ndone.eq.0) oldtime=hires_time()
tl=hires_time()-oldtime
if (tl.lt.0) tl=0
if (ndone.gt.0) tl=(1.0*ntotal/ndone)*tl-tl
c When finished, print the total time taken rather
c than just 00:00!
if (ndone.eq.ntotal) tl=hires_time()-oldtime
write(prog,'(a25,1x,''['')') string
do i=1,40
prog(27+i:27+i)=' '
enddo
write(prog(43:51),'(f7.1,''%'')') 100.0*ndone/ntotal
do i=1,40
if ((1.0*ndone/ntotal).gt.(1.0*i/40)) then
if (prog(27+i:27+i).eq.' ') prog(27+i:27+i)='#'
endif
enddo
prog(67:67)=']'
write(prog(70:72),'(i2.2,'':'')')int(tl/3600)
write(prog(73:75),'(i2.2,'':'')')int((tl-int(tl/3600)*3600)/60)
write(prog(76:77),'(i2.2)')int((tl-int(tl/60)*60))
if (prog.ne.oldprog) write(0,'(a,a,$)') prog(1:77),char(13)
oldprog=prog
if (ndone.eq.ntotal) write(0,*)
return
end
--
Mark Mackey http://www.swallowtail.org/
code code code code code code code code code code code code code bug code co
de code code code bug code code code code code code code code code code code
code code code code code code code code code code code code code code code c
.
- References:
- progress bar in fortran
- From: rudra
- progress bar in fortran
- Prev by Date: Re: Some Basic Questions
- Next by Date: Re: Some Basic Questions
- Previous by thread: Re: progress bar in fortran
- Next by thread: unresolved external symbol
- Index(es):
Relevant Pages
|
|