[ncl-talk] := or =

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Sat Oct 15 10:08:41 MDT 2022


Ehsan, := is called the "reassignment operator".  It completely deletes the
variable on the left, if any, before assigning the new array value.  The
normal assignment operator "=" does not do this.  It replaces only the
numeric values, and preserves any metadata on the left

Now consider that an assignment like b = a*b, or b := a*b, is evaluated in
two separate stages.  First the right side is evaluated.  Then the result
is copied to the left side.  Also, any math expression like a*b removes all
metadata from the input arrays, including coordinates and dimension names.
Therefore:

* With b = a*b, only the numeric values in b are replaced, and previous
metadata on b is left intact.
* With b := a*b, b is deleted after calculation, and before assignment.  A
brand new array for b is calculated, and all previous metadata on b is lost.

There are several consecutive sections covering this in the NCL users
manual, starting with "Variable Assignment".


On Sat, Oct 15, 2022 at 9:11 AM Ehsan Taghizadeh via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:

> Hi,
> I faced something interesting which I didn’t know in NCL. It might be
> obvious for many of you, however, I would like to share it.
> I tried to plot wind barb at 10m level above the ground from GFS0.25 data.
> First, I used following lines:
> u10 = fi->UGRD_P0_L103_GLL0({10},:,:)
> v10 = fi->VGRD_P0_L103_GLL0({10},:,:)
> u10 := u10*1.94386 ; Turn wind into knots
> v10 := v10*1.94386
> u10 at units = "kts"
> v10 at units = "kts"
> The resulted map was something like plt1 which is wrong.
> Then I tried to use the following lines:
> u10 = u10*1.94386 ; Turn wind into knots
> v10 = v10*1.94386
> This turn the resulted map (plt2) was correct.
> I’ll be thankful if some one could explain me why using “:=” is false and
> using “=” is true in this situation.
>
> *-----------------------------------------------------------------------------*
> *Sincerely,*
> *Ehsan Taghizadeh*
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20221015/62d5da8a/attachment.htm>


More information about the ncl-talk mailing list