Re: Status Bar Help [message #13673] |
Thu, 19 November 1998 00:00 |
Bernard Puc
Messages: 65 Registered: January 1998
|
Member |
|
|
Craig Markwardt wrote:
>
> 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.
> Good luck,
>
...Examples deleted
Thats what I thought. I modified my code to read the file in chunks
and the resulting read took about 20% longer. But I have a neat
graphic to stare at... ;-)
--
Bernard Puc
AETC, Inc.
(703) 413-0500
bpuc@va.aetc.com
|
|
|
Re: Status Bar Help [message #13674 is a reply to message #13673] |
Thu, 19 November 1998 00:00  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
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
endfor
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
rows.
statusbar, /init
for i = 0L, nlines-1 do begin
readf, unit, data
process, data
if i MOD nupdate EQ 0 then statusbar, /update
endfor
statusbar, /close
Good luck,
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@astrog.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: Status Bar Help [message #13675 is a reply to message #13673] |
Thu, 19 November 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
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.
If you know how long it is going to take to read the
file, more or less, you could implement the progress
indicator with a Timer event. The problem is that you
couldn't do anything useful with a Cancel button, since
you couldn't interrupt the read.
Given this, why not save yourself the trouble and just
do an Hourglass while the read is going on?
I realize that a progress indicator makes the user feel a bit
more secure that *something* is going on. Even though,
in this case, it probably isn't what the user thinks
it is. Still, good programs certainly take user
psychology into account. That is, *IF* you can understand
user psychology. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Progamming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|