Re: coerced parameter ........

From: gibies george <gibies_at_nyahnyahspammersnyahnyah>
Date: Thu Feb 24 2011 - 00:48:46 MST

Thank you Mary and Dave for the detailed discussion.

Now the picture is very much clear.

Thank you very much.

The recently added links from
http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclExpressions.shtml#Functions
is
very much helpfull.

Thanks for everything.

On 24 February 2011 00:02, David Brown <dbrown@ucar.edu> wrote:

> Adding just a bit more information: there is a more complete discussion of
> coercion with a table of NCL's coercion rules at:
>
> http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclDataTypes.shtml#Coercion
> Note particularly the 3rd bulleted note directly following the table.
>
> I will add links to this section from the discussion in
> NclExpressions.shtml.
> -dave
>
> P.S. But I agree with Mary that an example is the best way to explain.
>
> On Feb 23, 2011, at 9:03 AM, Mary Haley wrote:
>
> The best way to demonstrate what this document means is with an example.
>
> Basically, if you define an NCL function where one of the input values gets
> changed, and you call this function with a value that is not the type that
> the function expects, then the function will try to coerce the value to the
> correct type, but it won't allow the value to be changed once it comes back
> out of the function.
>
> Consider the NCL script below. The function "addit" simply adds a constant
> value to a 1D float array, "x". "x" is changed inside the function, so it
> should show up as changed in the calling code as well.
>
> However, if you pass an integer 1D array to "addit", you will get a warning
> and "x" will NOT be changed. NCL can't safely coerce the input float values
> to an integer array without possibility losing precision.
>
> Try running the code below, and try uncommenting one of the "ispan" lines
> below, to change "y" from a float to an integer. You will see that "y" will
> not be affected after "addit" is called, if it went in as an integer.
>
> --Mary
>
> ;---This function adds a constant to x, and attempts to change x directly.
>
> function addit(x:float[*],constant[1]:numeric)
> begin
> x = x + constant
> return(x)
> end
>
> begin
> y = ispan(1,10,1) ; y is an integer
>
> ; y = ispan(1,10,1)*1. ; y is a float
>
>
> ;
>
> ; If "y" is an integer, it will be coerced to a float
>
> ; for the "addit" function, AND the "y" values will
>
> ; not be changed after the function is called.
>
> ;
>
> ; You will also see this warning:
>
> ; warning:Argument 0 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
>
> ;
>
> ; If "y" is a float", the values will be changed after the
>
> ; function is called.
>
> ;
>
> print("before 'addit': y = " + y)
> z = addit(y,10)
> print("------------------------------------------------------")
> print("y and z should be the same, unless y had to be coerced")
> print("------------------------------------------------------")
> print("after 'addit': y = " + y + " (z = " + z + ")")
> end
>
>
>
> On Feb 23, 2011, at 5:31 AM, gibies george wrote:
>
> I have read the following information in NCL Reference Manual
>
> http://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclExpressions.shtml#Functions
>
> _______________________________________________________________
>
> One very important thing to note is that all parameters are *passed by
> reference* in NCL, meaning a change of a value in a variable within the
> function changes the value of the parameter.
>
> However, if a parameter is coerced before the function is called, changes
> within the function *will not* be reflected in the parameter, because
> coercion can only be applied in a single direction. A warning message is
> given in this instance.
>
> ________________________________________________________________
>
> Can anybody give details about the statement *"....* if a *parameter is
> coerced....."*
>
> *Thanking you in advance.*
> --
> *Gibies George, CSIR-RF,
> Climate and Global Modelling Division,
> Indian Institute of Tropical Meteorology,
> Dr. Homi Bhabha Road,
> NCL (P. O.), Pashan,
> Pune 411008, India.*
>
> *http://sites.google.com/site/gibiesge/*
>
> Think about the environment. Save paper; Save Trees. Please don't print
> this e-mail unless it is necessary.
> _______________________________________________
> 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
>
>
>

-- 
*Gibies George,   CSIR-RF,
Climate and Global Modelling Division,
Indian Institute of Tropical Meteorology,
Dr. Homi Bhabha Road,
NCL (P. O.), Pashan,
Pune 411008, India.*
*http://sites.google.com/site/gibiesge/*
Think about the environment. Save paper; Save Trees. Please don't print this
e-mail unless it is necessary.
Received on Thu Feb 24 00:48:51 2011

This archive was generated by hypermail 2.1.8 : Fri Feb 25 2011 - 08:50:46 MST