;	bso_bst

close,/al

	CASE !version.OS OF

'windows':	Delim='\'

'Win32':	Delim='\'

ELSE:		Delim='/'

	ENDCASE

Name_in=pickfile(/read,filt='*.bso',path=getenv('spk_dat'))
Name_out=subdir(name_in)+delim+(name_extract(name_in))(1)+'.bst'

openr,Lun_in,Name_in,/get_lun
BlockAOR0=SSRT_file_struc(LUN_in,Fileformat=Fileformat, $
   Offset=Offset, Dt=Dt, Date=Date, Length=Length)

x=assoc(Lun_in,BlockAOR0,Offset)

N_blocks=length/32



ScansetAOR1={ScansetAOR1, AttrEW:0B, LEW:bytarr(192), $
REW:bytarr(192), AttrSN:0B, LSN:bytarr(192), RSN:bytarr(192)}


Sum_chan=[180,192]
Offset1=(4L+2*2L*Sum_chan(1))



Pattern=make_array(192,2,/int,val=128)

Fyear=fix('19'+strmid(date,6,2))
Fdate=[byte(fix(strmid(date,0,2))),byte(fix(strmid(date,3,2)))]

openw,Lun_Out,Name_out,/get_lun
writeu,LUN_Out,Fyear,Fdate,Pattern

BlockAOR1={time:0L, Set32:replicate(ScansetAOR1,32)}

y=assoc(Lun_Out,BlockAOR1,Offset1)



	FOR j=0,N_blocks-1 DO BEGIN

print,'Block No ',strtrim(j+1,2),' of ',strtrim(N_blocks,2),' processed'

tmp0=x(j)
tmp1=BlockAOR1
tmp1.time=tmp0.time

		FOR k=0,31 DO BEGIN

tmp1.set32(k)={ScansetAOR1,AttrEW:(tmp0.set32.attr)(k),	$
	LEW:((tmp0.set32.i)(*,k)-(tmp0.set32.v)(*,k))/2b,	$
	REW:((tmp0.set32.i)(*,k)+(tmp0.set32.v)(*,k))/2b,	$
	AttrSN:0B,	 $
	LSN:bytarr(192), $
	RSN:bytarr(192)}

		ENDFOR

y(j)=tmp1
	ENDFOR



free_lun,Lun_Out
free_lun,Lun_In





end
