<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Hi NCL Users</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
I am currently using the function decimalPlaces like this below:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Round = decimalPlaces(rcMaxLon,2,True)
<div> Round1 = decimalPlaces(rcMaxLon@yave,2,True)</div>
<div><br>
</div>
<div> pr4@long_name = ""+model(gg)+"" </div>
<div>  pr4@units     = "s="+Round+" lat="+Round1+""</div>
<div><br>
</div>
<div>However, when I plot up my 39 CMIP models there are 3 in which the rounding to 2 decimal places has not worked properly...any ideas why this would be and any suggestions to fix it will be highly appreciated. </div>
<div><br>
</div>
<div><img style="max-width:100%" class="w-802 h-795" size="583899" contenttype="image/png" data-outlook-trace="F:1|T:1" src="cid:12776569-4ae3-473e-8535-21eef4fc0956"><br>
</div>
<div><img style="max-width:100%" class="w-802 h-594" size="378613" contenttype="image/png" data-outlook-trace="F:1|T:1" src="cid:dbfe906c-9598-431d-b6de-970a9e9b1607"><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>Kindest Regards</div>
<div>Melissa</div>
<div><br>
</div>
<div>Full code below:</div>
<div><br>
</div>
<div>
<div>;*************************************************</div>
<div>; regline_panel plots.ncl</div>
<div>;</div>
<div><br>
</div>
<div>;*************************************************</div>
<div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"</div>
<div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"</div>
<div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"</div>
<div><br>
</div>
<div>begin</div>
<div>;************************************************</div>
<div>; Read in Precip Data.</div>
<div>;************************************************</div>
<div><br>
</div>
<div>;Models</div>
<div><br>
</div>
<div>model = (/"ACCESS1-0","ACCESS1-3","bcc-csm1-1","BNU-ESM","CanESM2","CCSM4","CESM1-BGC","CESM1-CAM5","CMCC-CM","CMCC-CMS","CNRM-CM5","CSIRO-Mk3-6-0","EC-EARTH","FGOALS-g2","FIO-ESM","GFDL-CM3","GFDL-ESM2G","GFDL-ESM2M","GISS-E2-H_p1","GISS-E2-H_p2","GISS-E2-H_p3","GISS-E2-R_p1","GISS-E2-R_p2","GISS-E2-R_p3","HadGEM2-AO","HadGEM2-CC","HadGEM2-ES","inmcm4","IPSL-CM5A-LR","IPSL-CM5A-MR","IPSL-CM5B-LR","MIROC5","MIROC-ESM","MIROC-ESM-CHEM","MPI-ESM-LR","MPI-ESM-MR","MRI-CGCM3","NorESM1-M","NorESM1-ME"/)</div>
<div><br>
</div>
<div>wks  = gsn_open_wks("X11","2022_PHD_IPCC_Model_regline_historical_overlay_1981-2010_25-50")              ; specifies a plot</div>
<div>gsn_define_colormap(wks,"BlueOrangeRed")  ; choose color map</div>
<div>gsn_reverse_colormap(wks)</div>
<div>plot = new (dimsizes(model),"graphic")</div>
<div>do gg = 0,dimsizes(model)-1</div>
<div>    in=addfile("/mnt/geog/ml382/ml382_sals000408_home_dir/melsicz/historicalregline1981_2010IPCC/pr_Amon_"+model(gg)+"_historical_safrica_climDJF2022.nc","r")                    </div>
<div> lat   = in->lat                                      ; get lat</div>
<div> lon   = in->lon                                      ; get lon</div>
<div> time  = in->time                                     ; get time </div>
<div><br>
</div>
<div>   pr1 = in->pr(:,:,:)</div>
<div> </div>
<div><br>
</div>
<div>  pr2 = pr1(time|0, {lat|-30:0}, {lon|25:50})</div>
<div><br>
</div>
<div> dimpr2   = dimsizes(pr2)</div>
<div>    nlat     = dimpr2(0)</div>
<div>    mlon     = dimpr2(1)   </div>
<div>     </div>
<div> pr2MaxLon = new ( mlon, typeof(pr2), pr2@_FillValue)</div>
<div>    </div>
<div>   do ml=0,mlon-1</div>
<div>      imax = maxind(pr2(:,ml))</div>
<div>      pr2MaxLon(ml) = dble2flt(lat(imax))</div>
<div>   end do</div>
<div><br>
</div>
<div>   print(pr2MaxLon)</div>
<div>   print(pr2&lon)  </div>
<div>   </div>
<div>   print("-------------------------------")</div>
<div>   print("pr2MaxLon: "+pr2&lon+"   "+pr2MaxLon)</div>
<div><br>
</div>
<div>   ;Regression Line</div>
<div><br>
</div>
<div>   rcMaxLon = regline(pr2&lon,pr2MaxLon)</div>
<div>   print(rcMaxLon)</div>
<div><br>
</div>
<div>   print(rcMaxLon@yave)</div>
<div><br>
</div>
<div>   bMaxLon  = rcMaxLon@yintercept</div>
<div>   print(bMaxLon)</div>
<div><br>
</div>
<div>   xMaxLon  = pr2&lon</div>
<div>   print(xMaxLon)</div>
<div>   yMaxLon  = rcMaxLon*pr2&lon + bMaxLon</div>
<div>   print(yMaxLon)</div>
<div><br>
</div>
<div>   print("-------------------------------")</div>
<div>   print(xMaxLon+"   "+yMaxLon)</div>
<div> </div>
<div>;************************************************</div>
<div>; create an array to hold both the original data</div>
<div>; and the calculated regression line   </div>
<div>;************************************************</div>
<div> </div>
<div> data      = new ( (/2,dimsizes(pr2MaxLon)/), typeof(pr2MaxLon))</div>
<div><br>
</div>
<div> data(1,:) = dble2flt(rcMaxLon)*(dble2flt(xMaxLon)-dble2flt(rcMaxLon@xave)) + dble2flt(rcMaxLon@yave)</div>
<div><br>
</div>
<div>;************************************************</div>
<div>; Read in Precip Data with larger domain.</div>
<div>;************************************************  </div>
<div><br>
</div>
<div>f=addfile("/mnt/geog/ml382/ml382_sals000408_home_dir/melsicz/historicalregline1981_2010largeIPCC/pr_Amon_"+model(gg)+"_historical_safrica_climDJF2022.nc","r")                    </div>
<div> </div>
<div>  lat1   = f->lat                                      ; get lat</div>
<div>  lon1   = f->lon                                      ; get lon</div>
<div>  time1  = f->time </div>
<div> </div>
<div>  pr6 = f->pr(:,:,:)</div>
<div>     </div>
<div>  pr4 = pr6(time|0,{lat|-40:10}, {lon|-10:70})</div>
<div><br>
</div>
<div>;************************************************</div>
<div>; Read in Precip Data.</div>
<div>;************************************************</div>
<div> ;Obs </div>
<div> cin  = addfile("/mnt/geog/ml382/melphd/regressionline/SIOCZ/pr_CMAP_historical_safrica_climDJF_small.nc","r")                    </div>
<div> prcmap = cin->precip(:,:,:)</div>
<div> pr5 = prcmap(time|0, {lat|-30:0}, {lon|25:50})</div>
<div><br>
</div>
<div>  </div>
<div>;*************************************************************</div>
<div>;Calculations of max precip for lat and lon values observations (CMAP)</div>
<div>;**************************************************************</div>
<div>    </div>
<div>    dimpr5   = dimsizes(pr5)</div>
<div>    nlat     = dimpr5(0)</div>
<div>    mlon     = dimpr5(1)   </div>
<div>     </div>
<div> pr5MaxLon = new ( mlon, typeof(pr5), pr5@_FillValue)</div>
<div>    </div>
<div>   do ml=0,mlon-1</div>
<div>      imax = maxind(pr5(:,ml))</div>
<div>      pr5MaxLon(ml) = dble2flt(lat(imax))</div>
<div>   end do</div>
<div><br>
</div>
<div>   print(pr5MaxLon)</div>
<div>   print(pr5&lon)  </div>
<div>   </div>
<div>   print("-------------------------------")</div>
<div>   print("pr5MaxLon: "+pr5&lon+"   "+pr5MaxLon)</div>
<div><br>
</div>
<div>   ;Regression Line</div>
<div><br>
</div>
<div>   regcMaxLon = regline(pr5&lon,pr5MaxLon)</div>
<div>   print(regcMaxLon)</div>
<div><br>
</div>
<div>   print(regcMaxLon@yave)</div>
<div><br>
</div>
<div>   bMaxLon  = regcMaxLon@yintercept</div>
<div>   print(bMaxLon)</div>
<div><br>
</div>
<div>   xMaxLon  = pr5&lon</div>
<div>   print(xMaxLon)</div>
<div>   yMaxLon  = regcMaxLon*pr5&lon + bMaxLon</div>
<div>   print(yMaxLon)</div>
<div><br>
</div>
<div>   print("-------------------------------")</div>
<div>   print(xMaxLon+"   "+yMaxLon)</div>
<div><br>
</div>
<div>;************************************************</div>
<div>; create an array to hold both the original data</div>
<div>; and the calculated regression line   </div>
<div>;************************************************</div>
<div> </div>
<div> datac      = new ( (/2,dimsizes(pr5MaxLon)/), typeof(pr5MaxLon))</div>
<div><br>
</div>
<div> datac(1,:) = dble2flt(regcMaxLon)*(dble2flt(xMaxLon)-dble2flt(regcMaxLon@xave)) + dble2flt(regcMaxLon@yave)</div>
<div><br>
</div>
<div>   </div>
<div>   ; resource lists</div>
<div><br>
</div>
<div> res                     = True               ; plot mods desired</div>
<div> res@gsnAddCyclic        = False</div>
<div> res@cnFillOn            = True               ; color on</div>
<div> res@lbLabelStride       = 2                  ; every other label</div>
<div> res@gsnSpreadColors     = True               ; use full range of color map</div>
<div> res@cnLineLabelsOn      = False              ; no contour line labels</div>
<div> res@lbLabelBarOn        = False</div>
<div> res@gsnDraw             = False              ; do not draw the plot</div>
<div> res@gsnFrame            = False  </div>
<div>                </div>
<div>  </div>
<div>;pr4   = pr6(0,{-40:10},{-10:70})</div>
<div><br>
</div>
<div>dimpr4   = dimsizes(pr4)</div>
<div>latn     = dimpr4(0)</div>
<div>lonm     = dimpr4(1)    </div>
<div><br>
</div>
<div><br>
</div>
<div>res@mpLimitMode       = "Corners"  ;  </div>
<div>res@mpLeftCornerLonF  = lon1(0)</div>
<div>res@mpRightCornerLonF = lon1(lonm-1)</div>
<div>res@mpLeftCornerLatF  = lat1(0)</div>
<div>res@mpRightCornerLatF = lat1(latn-1)</div>
<div><br>
</div>
<div>   </div>
<div> res@tmXBMode      = "Explicit"     ; Define own tick mark labels.</div>
<div> res@tmXBValues    = (/ -9.,0.,10.,20.,30.,40.,50.,60.,69 /)</div>
<div> res@tmXBLabels    = (/ "10W","0","10E","20E","30E","40E","50E","60E","70E" /)</div>
<div> </div>
<div> res@tmYLMode      = "Explicit"     ; Define own tick mark labels.</div>
<div> res@tmYLValues    = (/  -39.,-30.,-20.,-10.,-0.,9 /)</div>
<div> res@tmYLLabels    = (/"40S","30S","20S","10S","0","10N" /)</div>
<div><br>
</div>
<div> res@vpXF             = 0.12               ; default is 0.2 change aspect</div>
<div> res@vpYF             = 0.8                ; default is 0.8 ration</div>
<div> res@vpHeightF        = 0.4                ; default is 0.6</div>
<div> res@vpWidthF         = 0.8                ; default is 0.6</div>
<div><br>
</div>
<div> res@cnLevelSelectionMode = "ManualLevels"  ; manual levels</div>
<div> res@cnMinLevelValF       =  0              ; min level</div>
<div> res@cnMaxLevelValF       =  400            ; max level</div>
<div> res@cnLevelSpacingF      =  50           ; contour spacing</div>
<div><br>
</div>
<div>  res@tmXBLabelFontHeightF = 0.022                ; resize tick labels</div>
<div>  res@tmYLLabelFontHeightF = 0.022    </div>
<div>  res@pmLabelBarOrthogonalPosF = .25           ; move whole thing down</div>
<div><br>
</div>
<div> </div>
<div>;************************************************</div>
<div>; plotting parameters</div>
<div>;************************************************</div>
<div> sres                      = True                   ; plot mods desired</div>
<div> sres@gsnMaximize          = True                   ; maximize plot in frame</div>
<div> sres@xyMarkLineModes      = (/"Markers","Lines"/)  ; choose which have markers</div>
<div> sres@xyMarkers            = 16                     ; choose type of marker</div>
<div> sres@xyLineColors         = (/"blue","black"/)</div>
<div> sres@xyMonoDashPattern    = True</div>
<div> sres@gsnLineDashPattern    = 1  </div>
<div> sres@xyDashPattern        = 16                     ; solid line</div>
<div> sres@xyLineThicknesses    = (/1,3/)                ; set second line to 2</div>
<div> sres@gsnDraw = False                        ; do not draw the plot</div>
<div> sres@gsnFrame = False </div>
<div><br>
</div>
<div> </div>
<div> ; reverse the first two colors</div>
<div>  setvalues wks            </div>
<div>    "wkColorMap"        : "BlueOrangeRed" ;"BkBlAqGrYeOrReViWh200"  </div>
<div>    "wkForegroundColor" : (/0.,0.,0./)  </div>
<div>    "wkBackgroundColor" : (/1.,1.,1./) </div>
<div>  end setvalues</div>
<div><br>
</div>
<div>;************************************************</div>
<div>; plotting parameters</div>
<div>;************************************************</div>
<div> cres                     = True                   ; plot mods desired</div>
<div> cres@gsnMaximize         = True                   ; maximize plot in frame</div>
<div> cres@xyMarkLineModes     = "Lines"                ; choose which have markers</div>
<div> cres@xyDashPatterns      = 0                      ; solid line</div>
<div> cres@xyLineThicknesses   = (/1,3/)               ; set second line to 2</div>
<div> cres@gsnDraw = False                        ; do not draw the plot</div>
<div> cres@gsnFrame = False                       </div>
<div>  </div>
<div> </div>
<div>  ; reverse the first two colors</div>
<div>  setvalues wks            </div>
<div>    "wkColorMap"        : "BlueOrangeRed" ;"BkBlAqGrYeOrReViWh200"  </div>
<div>    "wkForegroundColor" : (/0.,0.,0./)  </div>
<div>    "wkBackgroundColor" : (/1.,1.,1./) </div>
<div>  end setvalues</div>
<div><br>
</div>
<div>Round = decimalPlaces(rcMaxLon,2,True)</div>
<div> Round1 = decimalPlaces(rcMaxLon@yave,2,True)</div>
<div><br>
</div>
<div> pr4@long_name = ""+model(gg)+"" </div>
<div>   ;pr4@units     = "s="+rcMaxLon+" lat="+rcMaxLon@yave+""</div>
<div> pr4@units     = "s="+Round+" lat="+Round1+""</div>
<div><br>
</div>
<div><br>
</div>
<div> print(rcMaxLon)</div>
<div> print(Round)</div>
<div> print(Round1)</div>
<div>  </div>
<div>  res@tmXBLabelsOn         = False              ; do not draw bottom labels</div>
<div>  res@tmXBOn               = False              ; no bottom tickmarks</div>
<div>  res@tmYLLabelsOn         = False              ; no right labels</div>
<div>  res@tmYLOn               = False              ; no right tickmarks</div>
<div><br>
</div>
<div> if((gg.eq.36) .or. (gg.eq.37) .or. (gg.eq.38)) then</div>
<div><br>
</div>
<div>       res@tmXBLabelsOn         = True              ; do not draw bottom labels</div>
<div>       res@tmXBOn               = True              ; no bottom tickmarks</div>
<div>    else</div>
<div>      res@tmXBLabelsOn         = False              ; do not draw bottom labels</div>
<div>      res@tmXBOn               = False              ; no bottom tickmarks</div>
<div>  end if</div>
<div><br>
</div>
<div> if((gg.eq.0) .or. (gg.eq.4) .or. (gg.eq.8) .or. (gg.eq.12) .or. (gg.eq.16) .or. (gg.eq.20) .or.(gg.eq.24) .or. (gg.eq.28) .or. (gg.eq.32) .or. (gg.eq.36)) then</div>
<div>       res@tmYLLabelsOn         = True              ; do not draw bottom labels</div>
<div>       res@tmYLOn               = True              ; no bottom tickmarks</div>
<div>    else</div>
<div>      res@tmYLLabelsOn         = False              ; do not draw bottom labels</div>
<div>      res@tmYLOn               = False              ; no bottom tickmarks</div>
<div>  end if</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div> </div>
<div> plot(gg)  = gsn_csm_contour_map(wks,pr4({-40:10},{-10:70}),res)        ; create plot</div>
<div> plot2  = gsn_csm_xy(wks,pr2&lon,data,sres)        ; create plot</div>
<div> plot3  = gsn_csm_xy(wks,pr5&lon,datac,cres)        ; create plot</div>
<div> overlay(plot(gg),plot2)</div>
<div> overlay(plot(gg),plot3)  </div>
<div> </div>
<div>  delete(pr4)</div>
<div>end do</div>
<div><br>
</div>
<div>; panel resource list  (if necessary)</div>
<div><br>
</div>
<div>panres                = True              ; mod panel plot</div>
<div>panres@gsnPanelLabelBar    = True                ; add common colorbar</div>
<div>panres@lbLabelFontHeightF =.012                 ; make labels larger</div>
<div>panres@gsnMaximize = True ; Maximize plot in frame. </div>
<div><br>
</div>
<div>gsn_panel(wks,plot(:23),(/6,4/),panres)    ; panel 16 models at a time.</div>
<div>gsn_panel(wks,plot(24:),(/6,4/),panres)</div>
<div>;gsn_panel(wks,plot(32:),(/4,4/),panres)</div>
<div>;gsn_panel(wks,plot(25:32),(/4,4/),panres)</div>
<div>;gsn_panel(wks,plot(33:),(/4,2/),panres)</div>
<div>;gsn_panel(wks,plot(41:),(/4,2/),panres)</div>
<div>;gsn_panel(wks,plot(::),(/4,2/),panres)</div>
<div>end</div>
<br>
</div>
<br>
</div>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="Signature">
<div>
<div style="font-family:Tahoma; font-size:13px"></div>
<div style="font-family:Tahoma; font-size:13px">
<div style="font-family:Tahoma; font-size:13px">Dr. Melissa Lazenby
<div>Lecturer in Climate Change</div>
<div>Department of Geography</div>
<div>Chichester 1 C150</div>
<div>University of Sussex</div>
<div><br>
</div>
<div><i style="color: inherit; font-family: inherit; font-size: inherit; font-variant-ligatures: inherit; font-variant-caps: inherit; font-weight: inherit;">"Education is the most powerful weapon which you can use to change the world" Nelson Mandela</i><br>
</div>
<div><i style="color: inherit; font-family: inherit; font-size: inherit; font-variant-ligatures: inherit; font-variant-caps: inherit; font-weight: inherit;"><br>
</i></div>
<div><i style="color: inherit; font-family: inherit; font-size: inherit; font-variant-ligatures: inherit; font-variant-caps: inherit; font-weight: inherit;"><img style="max-width:100%" data-outlook-trace="F:1|T:1" src="cid:32ebdb21-ea12-42a7-874a-c8cd6971e615"><br>
</i></div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>