[ncl-talk] A NCL Mystery Solved

Alan Brammer abrammer at albany.edu
Thu Oct 19 09:15:29 MDT 2017


:= effectively deletes the variable on the left hand side (if it exists)
then points to the right hand side to the newly defined variable.
Therefore you can't use indexing and := as the left hand side variable no
longer exists.

it would
​kind of ​
be the same as:

if(isdefined("Hits_1"))
     delete(Hits_1)
end if
Hits_1(i_day) = Hits_4km(i_day) + Hits_1(i_day)
​;; not going to work as Hits_1 is now undefined.

;;  ​Right hand side will work, but left hand side will fail.
You've deleted Hits_1 so there is no dimension or coordinates associated.
As Marston said though, your code just add's a bunch of zeros together,
hopefully that was just pseudocode and there is something else going on.

If the right hand side is a different shape, type to the left hand side
then you need the := operator, if you actually want to redefine the left
hand side.   It's hard to answer why you got an error based on code we
can't see.

The := is great to easily handle redefining variables, but if you just
throw it around everywhere then things will happen that you're not
expecting.
 Rather than blindly solving issues with the := operator, workout why you
have the issue then decide if redefining the variable is the right answer.





On Thu, Oct 19, 2017 at 11:09 AM, Barry Lynn <barry.h.lynn at gmail.com> wrote:

> and I am wondering why it is needed...
>
> On Thu, Oct 19, 2017 at 5:49 PM, Barry Lynn <barry.h.lynn at gmail.com>
> wrote:
>
>> Hi:
>>
>> It only gives the error when the : is included after Hits_1(i_day), as in
>> :=.
>>
>> The : was needed before I subscripted the variable with i_day.
>>
>> Barry
>>
>> On Thu, Oct 19, 2017 at 5:31 PM, Marston Johnston <shejo284 at gmail.com>
>> wrote:
>>
>>> Hi Barry,
>>>
>>>
>>>
>>> A couple things, not to be nit-picky but just my experience. I rewrote
>>> the script a bit. But I’m confused, your arrays are always empty so Hits_1
>>> will always be 0.
>>>
>>> This version of the script doesn’t give the error:
>>>
>>>
>>>
>>> begin
>>>
>>>   n_days  = 3
>>>
>>>   dims = 9
>>>
>>>   Hits_1 = new(n_days,"float")
>>>
>>>   Hits_4km = new(n_days,"float")
>>>
>>>   Hits_1 = 0.0
>>>
>>>   Hits_4km = 0.0
>>>
>>>   do ii_day = 0,dims-1
>>>
>>>     if (ii_day .eq.0)then
>>>
>>>       i_day = 0
>>>
>>>     else
>>>
>>>       i_day = (mod(ii_day,3))
>>>
>>>     end if
>>>
>>>     ;printVarSummary(i_day)
>>>
>>>     ;print("i_day = "+ i_day)
>>>
>>>     Hits_1(i_day) = Hits_4km(i_day) + Hits_1(i_day)
>>>
>>>     print(Hits_1(i_day))
>>>
>>>   end do
>>>
>>> end
>>>
>>>
>>>
>>> /M
>>>
>>>
>>>
>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>
>>> Marston S. Ward, PhD
>>>
>>> Department of Earth Sciences
>>>
>>> University of Gothenburg, Sweden
>>>
>>> Email: marston.johnston at gu.se
>>>
>>> SkypeID: marston.johnston
>>>
>>> Phone: +46-31-7864901 <+46%2031%20786%2049%2001>
>>>
>>> Only the fruitful thing is true!
>>>
>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>
>>>
>>>
>>>
>>>
>>> *From: *ncl-talk <ncl-talk-bounces at ucar.edu> on behalf of Barry Lynn <
>>> barry.h.lynn at gmail.com>
>>> *Date: *Thursday, 19 October 2017 at 16:18
>>> *To: *ncl-talk <ncl-talk at ucar.edu>
>>> *Subject: *[ncl-talk] A NCL Mystery Solved
>>>
>>>
>>>
>>> Hi:
>>>
>>>
>>>
>>> I have this error (it didn't obviously show up with a Google search).
>>>
>>>
>>>
>>> fatal:Assign: Hits_1 is undefined, can not subscript an undefined
>>> variable
>>>
>>> fatal:["Execute.c":8575]:Execute: Error occurred at or near line 17 in
>>> file ./test.ncl
>>>
>>> Before defining Hits_1 as an array of size n_days, I needed the : to do
>>> the sum.
>>>
>>> However, it is the : that causes the error when the variable is defined
>>> as an array.
>>>
>>> I am not sure why, but I thought I would make a note of it for those who
>>> encounter the same error message.
>>>
>>>
>>>
>>> begin
>>>
>>>   n_days  = 3
>>>
>>>   dims = 9
>>>
>>>   Hits_1 = new(n_days,float)
>>>
>>>   printVarSummary(Hits_1)
>>>
>>>   Hits_4km = new(n_days,float)
>>>
>>>   Hits_1 = 0
>>>
>>>   Hits_4km = 0
>>>
>>>   do ii_day = 0,dims,1
>>>
>>>    if (ii_day .eq.0)then
>>>
>>>    i_day = tointeger(0)
>>>
>>>    else
>>>
>>>    i_day = (mod(ii_day,3))
>>>
>>>    end if
>>>
>>>    printVarSummary(i_day)
>>>
>>>    print("i_day = " + i_day)
>>>
>>>     *Hits_1(i_day) := Hits_4km(i_day) + Hits_1(i_day) ; **remove colon
>>> if Hits_1 is defined as an array.*
>>>
>>>   end do
>>>
>>> end
>>>
>>>
>>>
>>>
>>>
>>> --
>>>
>>> Barry H. Lynn, Ph.D
>>>
>>> Senior Lecturer,
>>>
>>> The Institute of the Earth Science,
>>> The Hebrew University of Jerusalem,
>>> Givat Ram, Jerusalem 91904, Israel
>>>
>>> Tel: 972 547 231 170
>>> Fax: (972)-25662581
>>>
>>>
>>>
>>> C.E.O, Weather It Is, LTD
>>> Weather and Climate Focus
>>> http://weather-it-is.com
>>> Jerusalem, Israel
>>> Local: 02 930 9525
>>> Cell: 054 7 231 170
>>> Int-IS: x972 2 930 9525
>>> US 914 432 3108 <(914)%20432-3108>
>>>
>>> _______________________________________________ ncl-talk mailing list
>>> ncl-talk at ucar.edu List instructions, subscriber options, unsubscribe:
>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>
>>
>>
>> --
>> Barry H. Lynn, Ph.D
>> Senior Lecturer,
>> The Institute of the Earth Science,
>> The Hebrew University of Jerusalem,
>> Givat Ram, Jerusalem 91904, Israel
>> Tel: 972 547 231 170
>> Fax: (972)-25662581
>>
>> C.E.O, Weather It Is, LTD
>> Weather and Climate Focus
>> http://weather-it-is.com
>> Jerusalem, Israel
>> Local: 02 930 9525
>> Cell: 054 7 231 170
>> Int-IS: x972 2 930 9525
>> US 914 432 3108 <(914)%20432-3108>
>>
>
>
>
> --
> Barry H. Lynn, Ph.D
> Senior Lecturer,
> The Institute of the Earth Science,
> The Hebrew University of Jerusalem,
> Givat Ram, Jerusalem 91904, Israel
> Tel: 972 547 231 170
> Fax: (972)-25662581
>
> C.E.O, Weather It Is, LTD
> Weather and Climate Focus
> http://weather-it-is.com
> Jerusalem, Israel
> Local: 02 930 9525
> Cell: 054 7 231 170
> Int-IS: x972 2 930 9525
> US 914 432 3108 <(914)%20432-3108>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20171019/12b850a2/attachment-0001.html>


More information about the ncl-talk mailing list