
function sxt_cba2os1, cbaii, cbadd, os1=os1
;
;+
;   Name: sxt_cba2os1
;
;   Purpose: extract OS1 from CBA 'index,data'
;
;   Input Parametesr:
;      cbaii, cbadd - index,data from 'rd_xda,cbafiles,-1,cbaii,cbadd'
;
;   Output:
;      function returns extracted OS1 structure vector
;
;   History:
;      Circa August 5, 20001  S.L.Freeland 
;                             (for shuttere encoder investigations)
;
;-

if n_params() lt 2 or (1-data_chk(cbaii,/struct)) then begin 
   box_message,['Need CBA index,data..',$
                'IDL> os1=sxt_cba2os1(cbaindex,cbadata)']
   return,-1
endif

nout=n_elements(cbaii)

sxt_struct,sxt_enginlog=os1_struct
retval=replicate(os1_struct,nout(0))

os1=getos1(cbadd)

s1mf=indgen(8)*8+5
s2mf=indgen(8)*8+6
s3mf=2
s4mf=57

retval.time=cbaii.gen.time
retval.day=cbaii.gen.day
retval.dp_mode=cbaii.gen.dp_mode
retval.dp_rate=cbaii.gen.dp_rate

retval.os1_status1=reform(os1(s1mf,*))
retval.os1_status2=reform(os1(s2mf,*))
retval.os1_status3=reform(os1(s3mf,*))
retval.os1_status4=reform(os1(s4mf,*))
retval.os1_flushcommand=reform(os1(3,*))
retval.os1_shutterodom= fix(reform(os1(34,*)))*(2.^16.) + $
                        fix(reform(os1(35,*)))*(2.^8.)  + $
                        fix(os1(36,*)) 
return,retval
end
