pro wrt1wda, lun, bytout, nmf, $
			gen_index0, gen_index1, wbs_index0, wbs_index1, $
			wbs_dhk, wbs_pc, wbs_ph
;
;
;
;	27-Feb-92 Changed the .sxs1, ... field definitions from
;		  total(wbs_pc.sxs_pc11 + wbs_pc.sxs_pc12)/ 32 (avg cnts per acc interval)
;		  to cnts/sec
;	25-Mar-92 Changed the .sxs1 from pc12 to pc21
;		  and changed .sxs2 from pc21 to pc22
;
qdebug = 1
;
ref_struct, ref, dpos1, dpos2, sxtos1, sxtos2, sxtos3, stat1
rsiz = ref.WBS_Fil_Rec_Siz
;
;----- Write the following data only to the first Gen_Index
;
if (not btest0(nmf,0)) then begin
    ;First half of data set (first major frame of 2) is missing
    ;copy second half to first half
    gen_index0 = gen_index1
end
if (not btest0(nmf,1)) then begin
    ;Secon d half of data set (first major frame of 2) is missing
    err_log, 'STR', 'ERR/WBS: GEN_INDEX1 not defined - why not!!'
    gen_index1 = gen_index0
end
;
;----- Write the following data only to the first WBS_Index
;
t = dprate2sec(gen_index0.dp_rate)*2	;*2 because 2 major frames
wbs_index0.sxs1         = total(wbs_pc.sxs_pc21)/t
wbs_index0.sxs2         = total(wbs_pc.sxs_pc22)/t
wbs_index0.hxs          = total(hxt_decomp(wbs_pc.hxs_pc1)  + hxt_decomp(wbs_pc.hxs_pc2) )/ t
wbs_index0.grs1         = total(hxt_decomp(wbs_pc.grs_pc11) + hxt_decomp(wbs_pc.grs_pc21) )/ t
wbs_index0.grs2         = total(hxt_decomp(wbs_pc.grs_pc12) + hxt_decomp(wbs_pc.grs_pc22) )/ t
wbs_index0.rbmsc        = total(wbs_pc.rbm_sc_pc1 + wbs_pc.rbm_sc_pc2)/ t 
wbs_index0.rbmsd        = total(wbs_pc.rbm_sd_pc) / t
wbs_index0.unit_time    = t*100
wbs_index0.nmf          = nmf
;
gen_index0.nIndexByte	= 2*(get_nbytes(gen_index0) + get_nbytes(wbs_index0))
gen_index0.nDataByte	= get_nbytes(wbs_dhk) + get_nbytes(wbs_pc) + get_nbytes(wbs_ph)
;
;-------------------- Write out index structures
;
rdwrt, 'W', lun, bytout, rsiz, gen_index0, 1
rdwrt, 'W', lun, bytout, rsiz, wbs_index0, 1
rdwrt, 'W', lun, bytout, rsiz, gen_index1, 1
rdwrt, 'W', lun, bytout, rsiz, wbs_index1, 1
;
;-------------------- Write WBS Data 
;
rdwrt, 'W', lun, bytout, rsiz, wbs_dhk, 1
rdwrt, 'W', lun, bytout, rsiz, wbs_pc, 1
rdwrt, 'W', lun, bytout, rsiz, wbs_ph, 1
;
end
