;
; Plots distributions and cutoffs of trends and means of different length
; segments.
;
; Get pre-analysed data
;
restore,filename='trendmean_distrib.idlsave'
;  ntry,tlen,nts,alltit,tren95,mean95,binmean,bintren,freqmean,freqtren,$
;  nbin,binsc
;
; Prepare window/paper for plotting
;
loadct,39
multi_plot,nrow=3,ncol=2
if !d.name eq 'X' then begin
  window, ysize=800
  !p.font=-1
endif else begin
  !p.font=0
  device,/helvetica,/bold,font_size=12
endelse
;
; Select which distributions to show
;
;iuse=[2,6,12]
iuse=[6]
nuse=n_elements(iuse)
;
; Compute distribution totals for scaling by
;
fmtot=total(freqmean,1)/100.
fttot=total(freqtren,1)/100.
;
; Repeat for each time series
;
for its = 0 , nts-1 do begin
  ;
  pause
;  plot,binmean*binsc(its),freqmean(*,iuse(0),its,0),/nodata,$
;    /xstyle,xtitle='Mean anomaly  (!Uo!NC)',$
;    /ystyle,ytitle='Frequency of occurrence!C!C(%)',yrange=[0.,50.]
;  oplot,[0.,0.],!y.crange,linestyle=1
  ;
;  for j = 0 , nuse-1 do begin
;    oplot,binmean*binsc(its),freqmean(*,iuse(j),its,0)/fmtot(iuse(j),its,0),$
;      thick=4
;    oplot,binmean*binsc(its),freqmean(*,iuse(j),its,1)/fmtot(iuse(j),its,1)
;  endfor
  ;
  plot,bintren*binsc(its),freqtren(*,iuse(0),its,0),/nodata,$
    /xstyle,xtitle='Trend  (!Uo!NC per 30 yr)',$
    /ystyle,ytitle='Frequency of occurrence!C!C(%)',yrange=[0.,30.]
  oplot,[0.,0.],!y.crange,linestyle=1
  ;
  xyouts,/normal,0.5,0.33+0.33*(!p.multi(0)-1)*0.5,align=0.5,alltit(its)
  ;
  for j = 0 , nuse-1 do begin
    oplot,bintren*binsc(its),freqtren(*,iuse(j),its,0)/fttot(iuse(j),its,0),$
      thick=4
    oplot,bintren*binsc(its),freqtren(*,iuse(j),its,1)/fttot(iuse(j),its,1)
  endfor
  ;
;  if its le 2 then yr=[0.,0.3] else yr=[0.,1.0]
;  plot,tlen,mean95(*,its,0),thick=4,psym=-def_sym(10),$
;    /xstyle,xtitle='Segment length  (years)',$
;    ytitle='95th centile of segment means!C!C(!Uo!NC)',$
;    /ystyle,yrange=yr
;  oplot,tlen,mean95(*,its,1),psym=-def_sym(15)
  ;
  if its le 2 then yr=[0.,0.6] else yr=[0.,2.6]
  plot,tlen,30.*tren95(*,its,0)/tlen,thick=4,psym=-def_sym(10),$
    /xstyle,xrange=[10,100],xtitle='Segment length  (years)',$
    ytitle='95th centile of segment trends!C!C(!Uo!NC per 30 yr)',$
    /ystyle,yrange=yr
  oplot,tlen,30.*tren95(*,its,1)/tlen,psym=-def_sym(15)
  ;
endfor
;
end
