;+
; NAME:
;     GET_DELAYBITS
; PURPOSE:
;     Returns delay bit normalization factors for the antennas used, for
;     this data record.
; CATEGORY:
;     OVRO APC DATA CALIBRATION
; CALLING SEQUENCE:
;     dlafac = get_delaybits(data)
; INPUTS:
;     data     The data record for which to return the normalization factors
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
; ROUTINES CALLED:
;     getdata, tl_decode
; OUTPUTS:
;     dlafac   The normalization factors for each antenna for the set
;                delays in this data record
; COMMENTS:
; SIDE EFFECTS:
; RESTRICTIONS:
; MODIFICATION HISTORY:
;     Written 21-May-1999 by Dale E. Gary
;-
function get_delaybits,data

   common dlabit, afac, bfac
   mask = ['1000'x,'800'x,'400'x,'200'x,'100'x,'80'x,'40'x,'20'x,'10'x,$
            '8'x,'4'x,'2'x,'1'x]

   delay_ch = data(12:16)
   adla = 4023      ; A-channel delay (should be obtained from CFG segment)
   bdla = 4025      ; B-channel delay (should be obtained from CFG segment)
   ; TP factors for channels A and B
   fac = fltarr(2)*0. + 1.
   ; Go through each bit in turn.  Those that are set should have the
   ; factor applied in a multiplicative sense.
   for i = 0, 12 do begin
      if (((delay_ch[0]+adla) and mask[i]) gt 0) then fac[0] = fac[0]*afac[i]
      if (((delay_ch[1]+bdla) and mask[i]) gt 0) then fac[1] = fac[1]*bfac[i]
   endfor
return,fac
end
