Re: can't undestand warning

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu Jun 27 2013 - 13:54:54 MDT

Consider the following 'toy' script.

;--------------
undef("sample_")
function sample (x:float)
begin
   xx = 2*x ; multiply input x
   x = x^3
   return(xx) ; will return 2*x
end

; ++++++++++++++MAIN SCRIPT********************

;EXAMPLE 1
   a = 3.4 ; float (pass by reference)
   aa = sample(a) ; a passed by reference
   print(a) ; value changed; a=39.304 (=x^3)
   print(aa) ; will be float; aa=6.8

   print("%%%%%%%%%%%")

'EXAMPLE 2
   b = 5 ; integer
   bb = sample(b) ; integer b converted to float (temporary variable)
   print(b) ; will still be 5 (type integer; no change)
   print(bb) ; bb=10
;-------------------

[1] The function has prototyped the input argument as type float.
        x:float

[2] procedure/function arguments are passed by reference

     NCL Reference Manual:
http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclStatements.shtml#Procedures

=========================================

NCL passes arguments by reference (like fortran).
Hence, if you change the value of the input argument 'x'
within the function, NCL will return xx AND the value
of x will be changed.

EXAMPLE 1
NCL passes the address of input variable 'a' (pass by reference).
When 'a' ['x' in function] is operated upon the value changes
and the variable is passed baqck.

EXAMPLE 2 above
To match the 'float' prototype, NCL 'promotes' the integer
variable 'b' is promoted to a float and stores it in
*temporary variable*.
The reference to the temporary variable is what is passed
to the function.

Because the input was promoted, NCL issues the warning message.**

You can change the value of this temporary variable BUT
upon return it will not be demoted and affect the
value of the original variable i

=========================================
**If you do not want to see this error message

see the FAQ: http://www.ncl.ucar.edu/FAQ/#err_msgs_004

  err = NhlGetErrorObjectId()
   setvalues err
     "errLevel" : "Fatal" ; only report Fatal errors
   end setvalues

  06/27/2013 11:17 AM, Jim Means wrote:
> Hi Katja,
>
> Just a guess, but could it be because label_ndc expects an integer, but
> dimsizes is an integer array that you are using as if it were an
> integer, so it needs to be coerced (changed) into integer type?
>
> Jim
>
> On 6/27/2013 16:58, Katja Lohmüller wrote:
>> Hi NCL-talk,
>>
>> I'm working on my plot and I always get a warning in the terminal I
>> can't understand or figure out of which function is meant. Is anyone
>> able to help me?
>>
>> Thank you,
>> Katja
>>
>> My script is as follows:
>>
>> ;*************************************************
>> ; traj_2.ncl
>> ;*************************************************
>> 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
>> ;*************************************
>> ; read in data
>> ;************************************
>> path = "/home/lohmueller/Desktop/BA/Amdardaten/Flutra01JanDLH_1.asc"
>> data = asciiread(path,(/72,4/),"float")
>> ; print(data)
>> ntime=72
>>
>> ;********************************************
>> wks = gsn_open_wks("pdf","trajectory") ; open workstation
>> ;*********************************************
>> ; color preps
>> ;*****************************
>>
>>
>> cnLevels=fspan(-65.0,0.0,14)
>>
>> ;colors =
>> (/"RoyalBlue","IndianRed","PaleGreen","MidnightBlue","DeepSkyBlue1","DarkTurquoise","DarkGreen","LimeGreen","yellow","OrangeRed","VioletRed","VioletRed3","MediumOrchid4","MediumPurple3"/)
>> ; rgb = span_named_colors(colors,False)
>> ;gsn_define_colormap(wks,rgb)
>>
>> ;color="/home/lohmueller/Desktop/BA/NCL/Tempe.rgb"
>> ;gsn_define_colormap(wks,"BlWhRe")
>>
>> cmap = gsn_retrieve_colormap (wks)
>>
>> gsn_define_colormap (wks,"BlWhRe")
>>
>> ;cmap= RGBtoCmap("/home/lohmueller/Desktop/BA/NCL/Temp.rgb")
>> ;gsn_define_colormap (wks,cmap)
>>
>>
>>
>>
>>
>>
>> res = True ; map resources
>>
>>
>> res@gsnDraw = False ; don't draw
>> res@gsnFrame = False ; don't advance frame
>> res@vpWidthF = 0.70 ; make map bigger
>> res@vpHeightF = 0.70
>> res@mpMaxLatF = 55 ; select subregion
>> res@mpMinLatF = 20
>> res@mpMaxLonF = 65
>> res@mpMinLonF = 5
>>
>> res@gsnMaximize = True
>> res@gsnPaperOrientation = "landscape"
>> res@gsnSpreadColors = True ; use full
>> range of colors
>> res@mpFillOn = True ; turn map fill on
>> res@mpOutlineOn = True ; turn the map outline on
>> color1 = NhlNewColor(wks,0.75,0.75,0.75) ; add a
>> lighter gray to the color map
>> res@mpFillColors = (/ -1,-1,102,-1/) ; color of the
>> continents: gray
>>
>>
>> ; label bar resources
>> res_lb = True
>> res_lb@vpWidthF = 0.60
>> res_lb@vpHeightF = 0.10
>> res_lb@lbPerimOn = False ; Turn off perimeter.
>> res_lb@lbOrientation = "Horizontal" ; Default is vertical.
>> res_lb@lbLabelStride = 2 ; an welchen Strich was stehen soll
>> res_lb@lbLabelAlignment = "InteriorEdges" ; Default is "BoxCenters".
>> res_lb@lbMonoFillPattern = True ; Fill them all solid.
>> res_lb@lbLabelFontHeightF = 0.015
>> res_lb@lbFillColors = cmap(:,:) ; Colors for boxes.
>>
>> res@tiMainString = "Flug 601 01.Januar DLH" ; title
>> res@gsnCenterString = "Tempereatur [°C]"
>>
>> map = gsn_csm_map_ce(wks,res) ; create map
>> delete(res)
>> ;*********************************************
>> ;trajectory parameters
>> ;*********************************************
>>
>>
>> xpt= new(ntime,float)
>> ypt= new(ntime,float)
>> t= new(ntime,float)
>>
>>
>> ;*********************************************
>> ;plot parameters
>> ;*********************************************
>>
>> pres = True
>> pres@gsLineThicknessF = 2.0
>>
>> mres = True
>> first= True
>> last= True
>>
>> ;*********************************************
>>
>> do i=0,ntime-1
>> ypt(i) = data(i,0) ;extract latitude(Breite(N))
>> xpt(i)= data(i,1) ;extract longitude(Länge(E))
>> t(i) = data(i,3)
>> end do
>>
>>
>> print(t)
>>
>> draw(map)
>>
>>
>> do j= 0,ntime-2
>> pres@gsLineColor=GetFillColor(cnLevels,cmap,t(j))
>> ;pres@gsLineColor=GetFillColor(cnLevels,cmap,avg((/t(j),t(j+1)/)))
>> gsn_polyline(wks,map,(/xpt(j),xpt(j+1)/),(/ypt(j),ypt(j+1)/),pres)
>> ;gsn_polyline(wks,map,xpt(j),ypt(j),pres)
>> end do
>>
>>
>> ;; create a unique marker to indicate the start of the trajectory
>>
>> first@gsMarkerSizeF = 5.0 ; marker size
>> first@gsMarkerColor = "red" ; marker color
>> last@gsMarkerSizeF = 9.0 ; marker size
>> last@gsMarkerColor = "blue" ; marker color
>>
>> gsn_polymarker(wks,map,xpt(0),ypt(0),first) ;draw start of trajectory
>> gsn_polymarker(wks,map,xpt(71),ypt(71),last) ;draw end of trajectory
>> ;delete(first@gsMarkerColor)
>> ;delete(first@gsMarkerSizeF)
>>
>>
>>
>> gsn_labelbar_ndc(wks,dimsizes(cnLevels)+1,cnLevels,0.20,0.20,res_lb)
>> frame(wks)
>>
>>
>>
>> print(dimsizes(cnLevels))
>>
>> end
>>
>>
>> warning:Argument 2 of the current function or procedure was coerced to
>> the appropriate type and thus will not change if the function or
>> procedure modifies its value
>>
>>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Jun 27 13:55:07 2013

This archive was generated by hypermail 2.1.8 : Mon Jul 01 2013 - 12:35:42 MDT