Viewing contents of file '../idllib/user_contrib/hamill/still_busy.pro'
PRO STILL_BUSY, ANNOUNCEMENT
;+
; NAME:
; STILL_BUSY
;
; PURPOSE:
; This function can be embedded inside an IDL code that is expected to
; run for a long time, announcing with printed messages that the code is
; still running. Unlike a PRINT statement in a loop, STILL_BUSY makes its
; announcements just once a minute.
;
; CATEGORY:
; Calming down impatient users like the author.
;
; CALLING SEQUENCE:
; STILL_BUSY[, ANNOUNCEMENT]
;
; OPTIONAL INPUT:
; ANNOUNCEMENT: An array of messages or values to be printed. If no
; parameter is used, the message reads "STILL BUSY" plus the time and
; date.
;
; KEYWORD PARAMETERS:
; NONE.
;
; OUTPUT:
; NONE.
;
; COMMON BLOCKS:
; BIZZY
;
; SIDE EFFECTS:
; The overhead of calling this function many times might be onerous; so
; don't bury it deep inside nested loops.
;
; PROCEDURE:
; Each time the procedure is invoked, it decodes the !STIME system vari-
; able to see if the minute has changed since the last time. If so, then
; the program prints the announcement. If not, it returns and does
; nothing.
;
; EXAMPLE:
; The following code might be used in a coded procedure that runs for
; twenty minutes. About twenty times out of the 1000 passages through the
; loop, a message appears on the screen.
;
; for iter = 1, 1000 do begin
; number_cruncher, data, i
; STILL_BUSY, "Processing iteration number " + strtrim(i,2)
; endfor
;
; MODIFICATION HISTORY:
; Written by: James Hamill
; Siemens Medical Systems
; 2501 N. Barrington Rd.
; Hoffman Estates, IL 60195-7372
; (708)304-7760
; hamill@sgi.siemens.com
; October, 1989
;
;-
common bizzy, last_minute
now = !stime
colon_position = strpos(now,":")
minute = strmid(now,colon_position+1,2)
;-------------------------------------------------------------------------------; What minute was it the last time we checked? But maybe there was no "last
; time." Return if we printed a message less than 1 minute ago.
;-------------------------------------------------------------------------------
sizl = size(last_minute)
if sizl(1) eq 0 then last_minute = "xx" ; on the 1st call it's undefined
if minute eq last_minute then RETURN
;-------------------------------------------------------------------------------; Print one or more messages. The first line contains the words "STILL BUSY".
;-------------------------------------------------------------------------------
if n_params() eq 0 then $
PRINT, "STILL BUSY. "+!stime $
else begin
n_announcements = n_elements(ANNOUNCEMENT)
PRINT, "STILL BUSY. " + string(ANNOUNCEMENT(0))
if n_announcements gt 1 then for i=1,n_announcements-1 do $
PRINT, string(ANNOUNCEMENT(i))
endelse
;-------------------------------------------------------------------------------; Get ready for the next call: put this minute value in common.
;-------------------------------------------------------------------------------
last_minute = minute
return
end