;
; Plots regional correlations of low frequency timeseries from sliding 40-yr
; windows
;
;plot,[0,1]
multi_plot,nrow=6,ncol=2,layout='large'
if !d.name eq 'X' then begin
  window,ysize=900
endif
!x.margin(1)=0
;
thalf=10.
pp=[1881,1940]
refp=[ [1881,1975] , [pp] , [pp] , [pp] , [pp] , [pp] , [pp] , [pp] , [pp] , $
  [pp] , [pp] ]
;
; Get region info
;
restore,filename='regboxes.idlsave'
regtit=regname
regtit(0:2)=['ESIB','CSIB','WSIB']
for ireg = 0 , nreg-1 do begin
  refperiod=reform(refp(*,ireg))
  restore,filename='instradj_'+regname(ireg)+'.idlsave'
  wdens=instradj
  mknormal,wdens,x,refperiod=refperiod,refmean=refmean,refsd=refsd
  filter_cru,thalf,tsin=wdens,tslow=instrlow,tshigh=instrhi,/nan
  ;
  restore,filename='densadj_'+regname(ireg)+'.idlsave'
  mknormal,densadj,x,refperiod=refperiod,refmean=refmean,refsd=refsd
  filter_cru,thalf,tsin=densadj,tslow=denslow,tshigh=denshi,/nan
  ;
  restore,filename='rwidadj_'+regname(ireg)+'.idlsave'
  mknormal,rwidadj,x,refperiod=refperiod,refmean=refmean,refsd=refsd
  filter_cru,thalf,tsin=rwidadj,tslow=rwidlow,tshigh=rwidhi,/nan
  ;
  ; and overplot correlation of 15-yr segments (implicitly high freq.)
  ;
  seglen=40
  nlin=1992-1881+1-seglen
  a15h=fltarr(nlin)
  a15hr=fltarr(nlin)
  for ii = 0 , nlin-1 do begin
    xx=indgen(seglen)+1881-1600+ii
    a15h(ii)=correlate(denslow(xx),instrlow(xx))
    a15hr(ii)=correlate(rwidlow(xx),instrlow(xx))
  endfor
  plot,findgen(nlin)+1881+seglen/2.,a15h,thick=4,$
    /ystyle,yrange=[-1.,1.],ytitle='Correlation',$
    /xstyle,xrange=[1888.5,1984.5],xtitle='Year',title=regtit(ireg)
  oplot,findgen(nlin)+1881+seglen/2.,a15hr
  oplot,!x.crange,[0.,0.],linestyle=1
  ;
endfor
;
plot,[0,1],/nodata,xstyle=4,ystyle=4
legend,['r(low) from sliding 40-yr window','MXD vs. temperature',$
  'TRW vs. temperature'],linestyle=[-1,0,0],thick=[0,4,1]
;
end
