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

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

begin
    dfn = "ens_TREFHT_JJA_trend.nc" ;; usually T2m or Tsfc 
    vn  = "TREFHT"
    dfn2= "ens_sst_JJA_trend.nc" ;; overlay, usually be sst
    vn2 = "sst"
    ofig= "TREFHT_ens_JJA_trend"
    
    isoverlay = isfilepresent(dfn2) 

    df = addfile(dfn,"r")
    var = df->$vn$(0,:,:)
    var = var*10 ;; annual trend to decadal trend

    if (isoverlay) then
        df2 = addfile(dfn2,"r")
        var2 = df2->$vn2$(0,:,:)
        var2 = var2*10 ;; annual trend to decadal trend
        ;; for micom
        gridf = addfile("/trd-project4/NS9039K/shared/pgchiu/diag_norcpm/grid_norcpm1_ocn.nc","r")
        var2@lat2d = gridf->plat
        var2@lon2d = gridf->plon
    end if
    res = True
        res@mpCenterLonF = 210.
        res@mpFillOn = False
        res@cnFillOn = True
        res@cnLinesOn = False
        res@cnFillMode = "CellFill"
        res@cnLevelSelectionMode = "ExplicitLevels"
        res@cnLevels = (/-.3,.3,.5,.7,.9/)
        res@cnFillColors = (/(/225,239,223,255/), (/255,255,255,255/), (/248,246,226,255/), (/244,218,140,255/), (/241,192,45,255/), (/168,129,32,255/)/)
        res@cnFillColors := res@cnFillColors / 255.
        
        res@gsnLeftString = "HIST Decadal trend t2m"
        res@gsnRightString = "JJA"

        res@gsnFrame = False
        res@gsnDraw  = False

    res2 = True
        res2@cnFillOn = True
        res2@cnLinesOn = False
        res2@cnFillMode = "CellFill"
        res2@cnLevelSelectionMode = "ExplicitLevels"
        res2@cnLevels = (/-.2,-.1,.1,.2,.3,.4/)
        res2@cnFillColors = (/(/189,202,232,255/), (/207,217,239,255/), (/255,255,255,0/), (/245,219,223,255/), (/244,198,200,255/), (/246,175,179,255/), (/247,155,157,255/)/)
        res2@cnFillColors := res2@cnFillColors / 255.
        res2@gsnDraw = False
        res2@gsnFrame = False
        res2@gsnAddCyclic = True
        res2@gsnLeftString = ""
        res2@gsnRightString = ""
        res2@lbTopMarginF = 0.4
        res2@lbLabelFontHeightF = 0.01

    if(isoverlay)then
        res@lbOrientation = "vertical"
        res@lbLabelFontHeightF = 0.01
        res@lbRightMarginF =  0.70
        res@lbLeftMarginF = -0.05
        res@gsnLeftString = "HIST Decadal trend t2m and "+vn2
    end if

        
    wks = gsn_open_wks("ps",ofig)
    plot = gsn_csm_contour_map(wks,var,res)

    if(isoverlay)then
        plot2 = gsn_csm_contour(wks,var2,res2)
        overlay(plot,plot2)
        res3 = res
        ;delete(res3@mpCenterLonF) ;; avoid  warning
        ;delete(res3@gsnLeftString)
        ;delete(res3@gsnRightString)
        ;plot3 = gsn_csm_contour(wks,var,res3)
        ;overlay(plot,plot3)
    end if

    draw(plot)
    frame(wks)
end


