PRO binavgt

;The procedure computes average values of trajectory lengths-vs-cdist
;distribution in 10 bins along the relative distance in the
;penumbra and plots it in a .PS figure 'binavgt.ps'.
;Used for Suetterlin's penumbra.
;
; The info is extracted from vxy10i.log, vxy10o.log
; Optional output to ps/eps files.
; 8 February 1999, modified 26 Apr 2000

;reading data

restore,'vxy/vxy10i.log'
restore,'vxy/vxy10o.log'
ddi=reform(vxylogi(3,*))	; distances w.r. to center (")
ddo=reform(vxylogo(3,*))
vi=reform(vxylogi(2,*))		; trajectory lengths (")
vo=reform(vxylogo(2,*))


;normalization of positions to 0--1 (min--max)

ddi=ddi>7.3	;setting artifitial boundaries at 7.3" and 18.5"
ddi=ddi<18.5	;  to compensate for the slight asymmetry
ddo=ddo>7.3
ddo=ddo<18.5

m0i=min(ddi)
m0o=min(ddo)
m0=m0i<m0o
m1i=max(ddi)
m1o=max(ddo)
m1=m1i>m1o
dni=(ddi-m0)/(m1-m0) < 0.999	;relative distances
dno=(ddo-m0)/(m1-m0) < 0.999

;Trajectory lengths ----------------------------------------------

;bins 0-.1 ... .9 - 1

avi=fltarr(2,10)
avo=fltarr(2,10)
ci=lonarr(10)
co=lonarr(10)

for i=0,9 do begin
  wi=where(dni ge i/10. and dni lt (i+1)/10.,cii)
  wo=where(dno ge i/10. and dno lt (i+1)/10.,coo)
  ci(i)=cii
  co(i)=coo

  if ci(i) ge 2 then begin
	avi(1,i)=stdev(vi(wi),mea)
	avi(0,i)=mea
  endif
  if ci(i) eq 1 then begin
	avi(1,i)=0
	avi(0,i)=vi(wi(0))
  endif
  if ci(i) eq 0 then begin
	avi(1,i)=0
	avi(0,i)=(-1)
  endif

  if co(i) ge 2 then begin
	avo(1,i)=stdev(vo(wo),mea)
	avo(0,i)=mea
  endif
  if co(i) eq 1 then begin
	avo(1,i)=0
	avo(0,i)=vo(wo(0))
  endif
  if co(i) eq 0 then begin
	avo(1,i)=0
	avo(0,i)=(-1)
  endif
endfor

xx=indgen(10)/10.+0.05

  set_plot,'ps'
  device,filename='binavgt.ps',xsiz=15,ysiz=10,yoffs=15,encapsulated=0
;  device,filename='binavgt.eps',xsiz=15,ysiz=10,yoffs=15,encapsulated=1

  plot,xx-0.01,avi(0,*),psym=7,yra=[0,3], thick=2,xthick=2,ythick=2, $
   symsiz=1.1,/yst,  $
   ytitle='Average Trajectory Length (")',charsiz=1.1,charthick=2,  $
   xtitle='Relative Position in the Penumbra'
  errplot,xx-0.01,avi(0,*)-avi(1,*),avi(0,*)+avi(1,*)
  oplot,xx+0.01,avo(0,*),psym=6,symsiz=1.1,thick=2
  errplot,xx+0.01,avo(0,*)-avo(1,*),avo(0,*)+avo(1,*)

;plotting number of PGs in each bin
;for i=0,9 do begin
;   if ci(i) eq 0 then goto,bkipi
;   xyouts,xx(i)-0.03,1.67,strtrim(ci(i),2),/data,charsiz=1.1,charthick=2
;  bkipi:
;endfor
;for i=0,9 do begin
;   if co(i) eq 0 then goto,bkipo
;   xyouts,xx(i)-0.03,1.58,strtrim(co(i),2),/data,charsiz=1.1,charthick=2
;  bkipo:
;endfor
;oplot,[0.15],[1.42],psym=7,symsiz=1.1,thick=2
;xyouts,0.18,1.4,'= INW',charsiz=1.1,charthick=2
;oplot,[0.15],[1.32],psym=6,symsiz=1.1,thick=2
;xyouts,0.18,1.3,'= OUT',charsiz=1.1,charthick=2

  device,/close
  !p.multi=0
  set_plot,'x'

end