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

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

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
begin
    ifile = "NPac_ts.nc"
    obsfn = "HadISST2ens_NPac_ts.nc"
    obsfn = "HadISST_NPac_ts.nc"
    f = addfile(ifile,"r")
    a = f->avg
    s = f->std
    vmax = f->max
    vmin = f->min
    boxset = (/vmin,a-s,a,a+s,vmax/)
    boxset!0 = "box"
    boxset!1 = "time"
    boxset := boxset(time|:,box|:)
    nt = tofloat(ispan(1,dimsizes(a),1))

    obsf = addfile(obsfn,"r")
    ;obsts = obsf->avg
    obstime = obsf->time
    needobstime = tofloat(cd_convert(a&time,obstime@units))
    oa = obsf->sst
    ;oa = obsf->avg({needobstime})
    ;oa = obsf->sst({needobstime})
    ;os = obsf->std({needobstime})
    ;ovmax = obsf->max({needobstime})
    ;ovmin = obsf->min({needobstime})
    ;;oa = oa-273.15
    ;ovmax = ovmax-273.15
    ;ovmin = ovmin-273.15
    ;oboxset = (/ovmin,oa-os,oa,oa+os,ovmax/)
    ;;oboxset!0 = "box"
    ;oboxset!1 = "time"
    ;oboxset := oboxset(time|:,box|:)

    wks = gsn_open_wks("ps","NPac_monts")
    boxOpts = True
    plotres = True
        plotres@tiMainString = "NPac SSTa mean"

    lineres = True

    plot1 = boxplot(wks,nt,boxset,boxOpts,plotres,lineres)
    lineres@gsLineColor = "darkgreen"
    lineres@DrawOrder = "PostDraw"
    ;plot2 = boxplot(wks,nt,oboxset,boxOpts,plotres,lineres)
    ;;plot2 = gsn_add_polyline(wks,plot1,nt,oa,lineres)
    gsn_polyline(wks,plot1,nt,oa,lineres)

    ;; legend
    lgres = True
        lgres@lgLineLabelStrings = (/"",""/)
        lgres@vpWidthF  = .2
        lgres@vpHeightF = .1
        lgres@lgPerimOn = False
        lgres@lgJustification = "TopLeft"
        lgres@lgLineColors =       (/"green","black"/)
        lgres@lgDashIndexes = (/0,0/)
    gsn_legend_ndc(wks,2,(/"HadISST1","Model ens"/),.6,.8,lgres)
    ;drawNDCGrid(wks)
    draw(plot1)
    ;;draw(plot2)
    frame(wks)
end


