;
; Create an Apr-Sep mean timeseries of gridded MSLP from monthly observed MSLP.
; Also plots the long-term mean and s.d.
;
print,'Reading in Phil Jones N. Hemi. MSLP gridded data'
ncid=ncdf_open('/cru/u2/f055/detect/obsdat/NH_MSLP_18731995.mon.nc')
fdmon=crunc_rddata(ncid,tst=[1922,0],tend=[1995,11],grid=g,info=i)
ncdf_close,ncid
;
; Compute April-September means from the data (requiring full data by default)
;
nmon=12
nyr=g.nt/nmon
fdmon=reform(fdmon,g.nx*g.ny,nmon,nyr)
fdseas=mkseason(fdmon,3,8)
fdseas=reform(fdseas,g.nx,g.ny,nyr)
timey=findgen(nyr)+g.year(0)
;
xlon=g.x
ylat=g.y
nx=g.nx
ny=g.ny
;
; Following discussion with Phil, certain regions are removed.
; We've already removed everything prior to 1922.
;
; (1) Remove 80N and 85N (due to Arctic High problems etc.)
;
kl=where(ylat lt 80.,ny)
ylat=ylat(kl)
fdseas=fdseas(*,kl,*)
;
; (2) Remove 15N
;
kl=where(ylat gt 15.,ny)
ylat=ylat(kl)
fdseas=fdseas(*,kl,*)
;
; (3) Set to missing the pre-1950 data at 70N & 75N from 100E to 60W
;
kx=where( (xlon gt 100.) and (xlon le 300.) , nxmiss)
ky=where( ylat ge 70. , nymiss)
kt=where( timey lt 1950. , ntmiss)
for ix = 0 , nxmiss-1 do begin
  for iy = 0 , nymiss-1 do begin
    for it = 0 , ntmiss-1 do begin
      fdseas(kx(ix),ky(iy),kt(it))=!values.f_nan
    endfor
  endfor
endfor
;
; Now compute 1961-90 mean and s.d. (requiring 25 yrs of data as minimum)
;
kt=where( (timey ge 1961) and (timey le 1990) , nref)
fdd=double(fdseas(*,*,kt))
fdtot=total(fdd,3,/nan)
fdnum=float(total(finite(fdd),3))
fdltm=fdtot/fdnum
ml=where(fdnum lt 25.,nmiss)
if nmiss gt 0 then fdltm(ml)=!values.f_nan
;
fdsqu=total(fdd^2,3,/nan)
fdsqu=fdsqu/fdnum
fdsd=sqrt(fdsqu-fdltm^2)
;
; Convert all values to anomalies
;
for i = 0 , nyr-1 do fdseas(*,*,i)=fdseas(*,*,i)-fdltm(*,*)
;
; Also produce a year-by-year timeseries of the fraction of missing data
;
nall=total(finite(fdltm))
nmiss=float(total(finite(fdseas),1))
nmiss=1.-(total(nmiss,1)/nall)
missfrac=nmiss
;
save,filename='obs_mslp_as.idlsave',timey,fdseas,xlon,ylat,nyr,nx,ny,$
  fdltm,fdsd,missfrac
;
loadct,39
multi_plot,nrow=2
if !d.name eq 'X' then window,ysize=850
;
map=def_map(/npolar) & map.limit(0)=15.
coast=def_coast(/get_device)  &  coast.double=0  &  coast.fill=1
coast.fillcolor=50
labels=def_labels(/off)
sm=def_sm()  &  sm.thresh=0.1 & sm.method=3
;
def_1color,cr,cg,cb,50,color='vlgrey'
;
levels=findgen(21)*2.+1000.
c_thick=fltarr(21)+3.
;
inter_confd,fdltm,xlon,ylat,$
  title='1961-90 mean Apr-Sep MSLP',$
  map=map,coast=coast,labels=labels,sm=sm,$
  /hi_on,/follow,levels=levels,c_thick=c_thick,miss_grey='white'
;
levels=findgen(21)*0.5
c_thick=fltarr(21)+3.
;
inter_confd,fdsd,xlon,ylat,$
  title='1961-90 standard deviation Apr-Sep MSLP',$
  map=map,coast=coast,labels=labels,sm=sm,$
  /hi_on,/follow,levels=levels,c_thick=c_thick,miss_grey='white'
;
; Finally: compute & plot fraction of data missing in each summer
;
pause
plot,timey,nmiss,psym=10,/xstyle,xtitle='Year',$
  ytitle='Fraction of data missing per summer',yrange=[0,0.5],/ystyle
;
end
