pro bcs_sub_dp, dp_sync, ndp_sync, info=info, err_log=err_log
;
;Take the raw DP_SYNC record and get counts/sec where possible
;
ms_day = 86400000            		; 1 day = 86400000 msec
start_time = systime(1)
;
n = ndp_sync
dp_sync = dp_sync(0:n-1)
day  = dp_sync.day
time = dp_sync.time
;
if (n gt 1) then begin
    map_discon, day, time, dp_sync.dp_rate, qdiscon, err_log=err_log, /print
end else begin
    qdiscon = intarr(1)+1	;one value and it is a discontinuity
end
;
all_cnts = long(unsign( dp_sync.all_cnts, 16))
lim_cnts = long(unsign( dp_sync.lim_cnts, 16))
acc_cnts = long(unsign( dp_sync.acc_cnts, 16))		;make sure they are "long" type for the conversion to a 1-D array
;
;---------------- Case where there was a discontinuity - do nothing
;
ss = where(qdiscon eq 1)
if (ss(0) ne -1) then begin
    dp_sync(ss).acc_interval(0) = 0	;At a minimum, the first value is always raw (discontinuity)
end
;
;---------------- Case where there were no discontinuities - difference with previous major frame
;
ss = where(qdiscon eq 0)
if (ss(0) ne -1) then begin		 ;ss will never start at 0
    n = n_elements(ss)
    ;----- IDL cannot insert a (4,1,n) array into a structure that thinks it is (4,n)
    ;      so we must make it think that it is (4,n)
    dp_sync(ss).all_cnts(*,0) = long( bcs_do_diff( all_cnts(*,0,ss), all_cnts(*,1,ss-1) ), 0,4,n)
    dp_sync(ss).lim_cnts(*,0) = long( bcs_do_diff( lim_cnts(*,0,ss), lim_cnts(*,1,ss-1) ), 0,4,n)
    dp_sync(ss).acc_cnts(*,0) = long( bcs_do_diff( acc_cnts(*,0,ss), acc_cnts(*,1,ss-1) ), 0,4,n)
    dp_sync(ss).acc_interval(0) = dprate2sec( dp_sync(ss-1).dp_rate ) / 2.	;2 values per major frame
    ;TODO - what about case where there is a rate change... what is the accumulation interval?
end
;
;---------------- In all cases, a difference within the major frame can be done
;
n = n_elements(dp_sync)
ss = indgen(n)
dp_sync(ss).all_cnts(*,1) = long( bcs_do_diff( all_cnts(*,1,ss), all_cnts(*,0,ss) ), 0,4,n)
dp_sync(ss).lim_cnts(*,1) = long( bcs_do_diff( lim_cnts(*,1,ss), lim_cnts(*,0,ss) ), 0,4,n)
dp_sync(ss).acc_cnts(*,1) = long( bcs_do_diff( acc_cnts(*,1,ss), acc_cnts(*,0,ss) ), 0,4,n)
dp_sync(ss).acc_interval(1)  = dprate2sec( dp_sync(ss).dp_rate ) / 2.		;2 values per major frame
;
;---------------- TODO: Temporary fix to flag all cases where rate had changed 
;
;Removed temporary fix to mask out where rate changes occur on 2-Dec-91
;;ss = indgen(n-1)+1
;;ss = where(dp_sync(ss).dp_rate ne dp_sync(ss-1).dp_rate)
;;if (ss(0) ne -1) then begin
;;    dp_sync(ss+1).acc_interval = 0	;avoid rate transition cases
;;end
;
end_time = systime(1)
if (keyword_set(info)) then begin
    dtim = end_time - start_time
    print, 'BCS_SUB_DP took ', dtim, ' seconds for ', n, ' major frames'
    print, '    which is     ', dtim*1280/n, ' seconds for 1280 major frames'
end
;
end
