pro map_discon, day, time, rate, qdiscon, gaptim, print=print, err_log=err_log, strec=strec, enrec=enrec, info=info
;
;HISTORY:
;	Written Fall '91 by M.Morrison
;	 4-Jun-92 (MDM) - modified to allow error to be .25 seconds off
;			  since there appears to be a "blip" when changing
;			  rates of .25 seconds
;
ms_day = 86400000            		; 1 day = 86400000 msec
start_time = systime(1)
;
qprint = 0
qerr_log = 0
if (keyword_set(print)) then qprint=1
if (keyword_set(err_log)) then qerr_log=1
;
n = n_elements(time)
;
qdiscon = bytarr(n)
gaptim = fltarr(n)		;number of seconds over the expected
				;delta time
;
qdiscon(0) = 1			;first value is always a discontinuity
;
ss = indgen(n-1)
diff = (day(ss+1)-day(ss))*ms_day + (time(ss+1)-time(ss))
;
ist = 1
if (keyword_set(strec)) then ist = strec
ien = n-1
if (keyword_set(enrec)) then ien = enrec
;
for i=ist,ien do begin
    del_tim  = diff(i-1)/1000.		;-1 because shift by one to get delta
    dp_rate0 = rate(i-1)/32		;previous rate - /32 to only look at high 3 bits
    dp_rate1 = rate(i)/32		;current rate
    dp_rate0 = dp_rate0>0<5
    dp_rate1 = dp_rate1>0<5
    ;ref_tim = dprate2sec(dp_rate0)*1.005	;allow 0.5% erroor
    ref_tim = (dprate2sec(dp_rate0)+0.25) *1.005	;allow 0.5% error - 4-Jun-92 allowed error of .25 seconds for rate changes
    if (del_tim gt ref_tim) then begin	
	int2ex, time(i), day(i), daytim
	str = 'Discontinuity of :' + string(del_tim) + ' sec' + $
		' Record:' + string(i) + ' at ' + $
		string(daytim(0:3), format='(i2,":",i2.2,":",i2.2,".",i3.3)')
	if (qprint) then print, str
	if (qerr_log) then err_log, 'STR', 'WRN/CON: ' + str
	qdiscon(i) = 1
	gaptim(i) = del_tim - dprate2sec(dp_rate0)	;
    end
end
;
;TODO - "Vectorize?"
;
end_time = systime(1)
if (keyword_set(info)) then begin
    dtim = end_time - start_time
    print, 'MAP_DISCON took ', dtim, ' seconds for ', (ien-ist), ' major frames'
    print, '    which is     ', dtim*1280/(ien-ist), ' seconds for 1280 major frames'
end
;
end
