[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Status Bar Help

Bernard Puc <bpuc@va.aetc.com> writes:
> 	I have a status bar widget which shows progress of a file read when
> that read involves a loop.  Are there any ways of doing the same
> thing but for a single read without a loop?  I have large image
> arrays which can take many seconds to load and would like a
> graphical feedback as to the progress.

The technique I use is to use a loop, but read a large chunk of data
in each step of the loop.  If you follow this technique, then you
could still update your status widget each time.

In the example below, you read data in 10000 line chunks. This is
really pseudocode, but you'll get the idea.  The choice of your chunk
size depends on the tradeoff between performance and memory usage
(when doesn't it!), but you want to be sure that you read and process
enough data in one chunk to compensate for the compute time spent
updating your status bar.

; buffer size is 10000 lines
buffer = dblarr(5,10000)
; Initialize status bar here...
statusbar, /init
for i = 0, nchunks-1 do begin
  readu, unit, buffer   ;; Read a chunk of data all at once
  process, buffer       ;; Process the data all at once
  statusbar, percent=double(i)/nchunks
statusbar, /close  

If the actual reading of your data from the file is not a problem,
but updating the status bar is, then you could still read each line
and process it individually, but only update the status bar every N

statusbar, /init
for i = 0L, nlines-1 do begin
  readf, unit, data
  process, data
  if i MOD nupdate EQ 0 then statusbar, /update
statusbar, /close

Good luck,


Craig B. Markwardt, Ph.D.         EMAIL: craigmnet@astrog.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response