load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" begin ; List the analysis we care about and read in the file to get the variable names anal = "CFSR" numANA = dimsizes(anal) anaDIR = "data" a = addfile(anaDIR + "/" + "t2_daily_State_Data_US_cfsr.nc","r") vNames = getfilevarnames (a) nNames = dimsizes (vNames) print(vNames) delete(a) ; This section is taking the variable names and making them into a format we want ; for the plot titles. You can ignore it. printNames = vNames varNames = vNames ind1 = str_index_of_substr(vNames(1) , "_", -1) + 1 ind2 = ind1-2 do ii = 1,nNames-1 foo1 = stringtochar(vNames(ii)) foo2 = foo1(ind1:) foo3 = foo1(:ind2) printNames(ii) = chartostring(foo2) varNames(ii) = chartostring(foo3) delete ( [/foo1,foo2,foo3/] ) end do ; The ensembles we care about and set up the directory and root of the files ensembles = (/"rtty_1990"/) numENS = dimsizes(ensembles) DIR = "data/" rootFILE = "t2_daily_State_Data_US_" ; Number of PDFs we want to make numPDFs = numENS + numANA ; Setting up the legend and colours of the pdf lines legends = new(numPDFs,string) legends = " " legends(0) = "RTTY_1990" legends(1) = anal lines = new(numPDFs,float) lines = 2.5 colours = new(numPDFs,string) colours = (/"blue","black"/) ; Open the workstation to make the plot wks = gsn_open_wks ("X11","PDF_T2_Annual") ; Setting the plot resources res = True res@gsnDraw = False res@gsnFrame = False res@gsnMaximize = True res@tiYAxisString = "PDF (%)" res@xyLineThicknesses = lines res@xyLineColors = colours res@xyDashPatterns = 0 res@pmLegendDisplayMode = "Always" res@xyExplicitLegendLabels = legends res@pmLegendSide = "Top" ; Change location of res@pmLegendParallelPosF = .8425 ; move units right res@pmLegendOrthogonalPosF = -0.2325 ; move units down res@pmLegendWidthF = 0.125 ; Change width and res@pmLegendHeightF = 0.075 ; height of legend. res@lgPerimOn = True ; turn off/on box around res@lgLabelFontHeightF = .015 ; label font height ; Set PDF resources pdfres = True pdfres@bin_min = -40. ; Lowest bin is -40 pdfres@bin_max = 45. ; Highest bin is 45 nBin = 85 ; Number of bins ; Making a variable for the plot plots = new(nNames-1 , graphic) txid = new(2,graphic) amid = new(2,graphic) ; Loop through each variable for the analysis and ensembles. Make the PDFs do ivar =1,nNames-1 print("Working on " + vNames(ivar) ) do iens=0,numPDFs-1 if (iens .ge. numENS) then ana = addfile(anaDIR + "/" + "t2_daily_State_Data_US_cfsr.nc","r") var = ana->$vNames(ivar)$ var = var - 273.15 delete(ana) else ensFILES = systemfunc (" ls -1 " + DIR + "/" + rootFILE + ensembles(iens) + ".nc") ens = addfiles(ensFILES,"r") var = ens[:]->$vNames(ivar)$ delete(ensFILES) delete(ens) end if ; Make the PDF using the pdfx function ap = pdfx(var, nBin, pdfres) if (iens .eq. 0) then xx = new ( (/numPDFs,nBin/), typeof(ap)) yy = new ( (/numPDFs,nBin/), typeof(ap)) end if xx(iens,:) = ap@bin_center ; assign appropriate "x" axis values yy(iens,:) = (/ap/) delete(ap) delete(var) end do ; Set the title for each panel res@tiMainString = varNames(ivar) + " " +printNames(ivar) ; Make each of the PDF panels plots(ivar-1) = gsn_csm_xy (wks, xx, yy, res) delete( [/xx,yy/] ) end do ; Set panel plot resources pnlres = True pnlres@gsnMaximize = True ; Draw the panel plot gsn_panel(wks,(/plots/),(/1,2/),pnlres) ; End of program end