
;; Empty NCL template
;; run code in recipes, use it carefully

;;DIAG_NORCPM; RUNTHESECODES: print("    no ncl code run here")

function addcyclic(data)
begin
dims    = dimsizes(data)
ny      = dims(0)
mx      = dims(1)
mx1     = mx+1
newdata = new((/ny  ,mx1/),typeof(data))
newdata(:,0:mx-1) = data             ; pass everything
newdata(:,mx) = (/ data(:,0) /)  ; value only
if (data@units .eq. "degrees_east")then
newdata(:,mx) = data(:,0)+360.  ; value only
end if
return(newdata)
end

begin
f = addfile("sst_ano_ens_cor.nc","r")
var = f->sst(0,:,:)
gridf = addfile("/nird/home/pgchiu/scratch/norcpm_verify/grid_tnx1v4_20170622.nc","r")
plon = gridf->plon
plat  = gridf->plat
plon := addcyclic(plon)
plat := addcyclic(plat)
color_map =(/(/255,255,255/), \
        (/  0,  0,  0/), \
        (/255,255,255/), \
        (/255,250,169/), \
        (/255,231,120/), \
        (/200,255,190/), \
        (/150,245,141/), \
        (/ 80,240, 80/), \
        (/220,220,254/) , \
        (/160,140,255/), \
        (/112, 96,220/), \
        (/ 61, 40,181/) /)

cmap = tofloat(color_map)/255.

res = True
res@gsnAddCyclic = True ;; cause white vertical line
res@cnFillOn = True
res@cnLinesOn = False
res@cnFillMode = "CellFill"
res@sfXArray = plon
res@sfYArray = plat
res@mpMinLatF = -90.
res@mpMaxLatF =  90.
res@mpMinLonF = 30.
res@mpMaxLonF = 390.
res@mpCenterLonF = (res@mpMinLonF+res@mpMinLonF)/2
res@gsnLeftString = "Anomaly Corr. monthly SST Ens. mean vs. HadISST "
res@gsnRightString = ""
res@cnLevelSelectionMode = "ExplicitLevels"
res@cnLevels = fspan(.1,.9,9)


wks = gsn_open_wks("ps","sst_ano_ens_cor")
gsn_define_colormap(wks,cmap)

plot = gsn_csm_contour_map_ce(wks,var,res)
end


