;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; colorbar.ncl ;; Carl Schreck (carl@cicsnc.org) ;; August 2012 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Description: Draw a colorbar (labelbar) on a blank plot ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 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" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl" ;load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl" ;load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/diagnostics_cam.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/time_axis_labels.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/ut_string.ncl" load "/home/carl/lib/print_clock.ncl" begin print_clock( "Here we go!" ) ;; These are some parameters that could be useful to have up top plotType = "png" plotName = "colorbar" plotDpi = 150 fontHeightF = 0.015 levels = ispan( -90,30,1) showLevels = (/ 28, 9, -30, -41, -53, -63, -69, -75, -80, -85, -90 /) labels = new( dimsizes(levels), string, "" ) do i = 0, dimsizes(levels)-1 if( any( levels(i).eq.showLevels ) ) then labels(i) = levels(i) end if end do ;; Customize base plot res = True ; res@gsnDraw = False ; res@gsnFrame = False res@lbTitleFontHeightF = fontHeightF res@lbLabelFontHeightF = fontHeightF res@vpHeightF = 0.8 res@vpWidthF = 0.3 ; res@lbBoxMinorExtentF = 0.1 ;; ...labelbar resources res@lbLabelBarOn = True res@lbLabelAutoStride = False res@lbOrientation = "Vertical" res@lbTitlePosition = "Bottom" res@lbTitleDirection = "Across" ; res@lbTitleString = "DegC" res@lbMonoFillPattern = True res@lbPerimOn = False res@lbBoxLinesOn = True res@lbAutoManage = False res@lbLabelAlignment = "InteriorEdges" print_clock( "Drawing the plot" ) ;; ...allows png or gif to work if( ( plotType.eq."png" ).or.( plotType.eq."gif" ) ) then plotTypeLocal = "eps" else plotTypeLocal = plotType end if ;; ...open the workstation wks = gsn_open_wks( plotTypeLocal, plotName ) gsn_merge_colormaps( wks, "dvorak_schreck", "dvorak_bd" ) ; drawNDCGrid(wks) res@lbFillColors = ispan( 121, 239, 1 ) res@lbLabelPosition = "Left" gsn_labelbar_ndc( wks, dimsizes(labels)-1, labels, 0.1, 0.9, res ) ; res@lbFillColors = ispan( 2, 120, 1 ) res@lbLabelPosition = "Right" res@lbBoxLinesOn = False gsn_labelbar_ndc( wks, dimsizes(labels)-1, labels, 0.4, 0.9, res ) res@lbBoxLinesOn = True res@lbBoxLineThicknessF = 5 gsn_labelbar_ndc( wks, dimsizes(labels)-1, labels, 0.7, 0.9, res ) res@lbBoxLinesOn = False gsn_labelbar_ndc( wks, dimsizes(labels)-1, labels, 0.7, 0.9, res ) txRes = True txRes@txFontHeightF = fontHeightF ; gsn_text_ndc( wks, "WMG", 0.5, 0.830, txRes ) ; gsn_text_ndc( wks, "OW", 0.5, 0.640, txRes ) ; gsn_text_ndc( wks, "DG", 0.5, 0.480, txRes ) ; gsn_text_ndc( wks, "MG", 0.5, 0.410, txRes ) ; gsn_text_ndc( wks, "LG", 0.5, 0.340, txRes ) ; gsn_text_ndc( wks, "B", 0.5, 0.285, txRes ) ; gsn_text_ndc( wks, "W", 0.5, 0.250, txRes ) ; gsn_text_ndc( wks, "CMG", 0.5, 0.210, txRes ) ; gsn_text_ndc( wks, "CDG", 0.5, 0.160, txRes ) frame( wks ) print_clock( "Convert the image, if necessary" ) if( ( plotType.eq."png" ).or.( plotType.eq."gif" ) ) then system( "convert -trim +repage -density " + plotDpi + " " \\ + plotName + ".eps " + plotName + "." + plotType ) system( "rm -f " + plotName + ".eps" ) end if print_clock( "Thank you, come again." ) end