-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprog_steps.pro
More file actions
35 lines (30 loc) · 1.51 KB
/
prog_steps.pro
File metadata and controls
35 lines (30 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
; this_step: 0-based iteration
; nsteps: number of iterations to be completed
; loop_times: vector of length nsteps with values filled in up to this_step
; nprogsteps: optional, number of evenly spaced progress steps to report (default = 5)
; progress_steps: optional, list of step indices to report progress on
; (default = [nprogsteps evenly spaced values starting at 0])
pro prog_steps, this_step, nsteps, loop_times, nprogsteps = nprogsteps, $
progress_steps = progress_steps
compile_opt defint32, logical_predicate, strictarr, strictarrsubs
if n_elements(progress_steps) eq 0 then begin
; get progress reports periodically + on 3rd step (for early estimate for time to finish)
if n_elements(nprogsteps) eq 0 then begin
; default to 20%
nprogsteps = 5
endif
progress_steps = round(nsteps * findgen(nprogsteps) / double(nprogsteps))
endif
wh = where(progress_steps eq this_step, count)
if count gt 0 then begin
pct_done = round(100d * (this_step + 1) / (nsteps))
print, 'progress: finished step ' + number_formatter(this_step + 1) + $
' of ' + number_formatter(nsteps) + ' (~ ' + number_formatter(pct_done) + '% done)'
ave_t = mean(loop_times[0 : this_step])
t_left = ave_t * (nsteps - this_step - 1)
t_left_str = timing_string(t_left)
print, 'peak memory used: ' + number_formatter(memory(/highwater) / 1.e9, format = '(d8.1)') $
+ ' GB; ave step time: ' + number_formatter(ave_t, format = '(d8.2)') $
+ '; approx. time remaining: ' + t_left_str
endif
end