<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">Kyle,</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">The list looplist2 at the end seg. faulted when doing "ListPop" is definitely a bug.</div><div class="gmail_default" style="font-family:verdana,sans-serif">I have created a JIRA ticket: <a class="" href="https://vets.development.ucar.edu/jira/browse/NCL-2129" id="key-val" rel="92414" style="font-family:Arial,sans-serif;font-size:14px;line-height:20px;color:rgb(59,115,175);text-decoration:none">NCL-2129</a> for this.</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">I will work on this and report back.</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">Thanks,</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">Wei</div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><font face="tahoma, sans-serif">================================================</font><div><font face="tahoma, sans-serif">1850 Table Mesa Dr.</font></div><div><font face="tahoma, sans-serif">Boulder, CO 80307</font></div><div><font face="tahoma, sans-serif">Phone: 303-497-8924</font></div></div></div></div>
<br><div class="gmail_quote">On Tue, Jan 27, 2015 at 4:52 PM, Walter Kolczynski <span dir="ltr"><<a href="mailto:walter.kolczynski@noaa.gov" target="_blank">walter.kolczynski@noaa.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Kyle,<br>
<br>
My understanding is that the list only holds a reference to the
variable, which is why when you delete the variable, the list now
references something that doesn't exist (something that doesn't come
up in Java). I have a utility function I use to create an anonymous
copy to add variables to lists without fear of them being deleted:<br>
<br>
<tt>;</tt><tt><br>
</tt><tt>; Creates an anonymous copy of a variable for inclusion in
lists without causing issues if the variable is deleted.</tt><tt><br>
</tt><tt>;</tt><tt><br>
</tt><tt>if isdefined("echo") then undef("echo") end if</tt><tt><br>
</tt><tt>function echo(variable)</tt><tt><br>
</tt><tt> local variable2</tt><tt><br>
</tt><tt> begin</tt><tt><br>
</tt><tt> variable2 = variable</tt><tt><br>
</tt><tt> return variable2</tt><tt><br>
</tt><tt> end ; echo</tt><br>
<br>
Then you can just add it to a list like so:<br>
<tt>ListPush( listName, echo(variable) )</tt><br>
<br>
All of the elements in the list will retain all of their metadata
when you pop them off or access them directly via [ ].<br>
<br>
- Walter<div><div class="h5"><br>
<br>
<div>On 27-Jan-15 11:13, Kyle Griffin wrote:<br>
</div>
</div></div><blockquote type="cite"><div><div class="h5">
<div dir="ltr">Hi all,
<div><br>
</div>
<div>Some questions as to the interactions between all three of
these (attributes, arrays, and lists) and some discussion as
to the desired functionality of each.</div>
<div><br>
</div>
<div>I've included (in raw text) some code at the end that
demonstrates some of my concerns.</div>
<div><br>
</div>
<div>First: Is it possible for individual elements of an array
to maintain their individual attributes while in an array?
(Parts 1/2 below)</div>
<div>Current practice is to set any individual attributes to the
attributes of the array variable and, when individual elements
are returned, return the elements with all attributes from the
array, even if the attributes have been changed or others
added.</div>
<div><br>
</div>
<div>Secondly, I know Lists are relatively new additions to NCL,
but I'd also like to question how variables are handled when
the lists are being created. (Parts 3/4 below)</div>
<div>It seems that there is not a functional way to create a
list without having a unique variable for each member (e.g.
Part 3). This is a nice workaround to my question above, as
each member keeps its own attributes as well.</div>
<div>However, in order to use these lists in a more practical
sense, the addition of a variable via a loop does *not* work
well, although I believe it is working as designed. When a
variable is added to a list, the original variable must be
maintained in memory and any changes to that variable outside
of the list will be reflected inside the list as well. This
makes sense, as the variable is simply a member of the list -
the list is simply an organizational structure for
pre-existing variables. In order to do this in a loop, one
would need to have a unique name for each variable to be added
to the list OR disassociated the variable that is being added
to the list from its reference variable outside the list. The
unique_string function, while useful for attribute names, does
not work for variable names, e.g.</div>
<div><br>
</div>
<div>varname = unique_string("")</div>
<div>$varname$ = ....data to put in list...</div>
<div><br>
</div>
<div>As a result, lists are essentially useless without a
unique, hand-made variable for each member, something that is
simply not practical in many situations.</div>
<div><br>
</div>
<div>The biggest red flag I've seen, however, is when trying to
add only the value of the variable, via (/.../), to the list.
This would be a potential alternative to creating individual
variables and allowing for subsequent alterations to the
variable in order to add attributes, for example. The
subsequently created list, when popped with ListPop, instantly
seg faults.</div>
<div><br>
</div>
<div>As I write this email, I realize that my Java training from
many years ago comes to mind, especially the ArrayList
functionality. I'm not 100% sure that's what I've tried to
describe in this email, but it might be a start, where
"objects" (any variable with attributes) can be stored (like
lists) but with the index functionality of arrays as well. It
still doesn't get around the "unique name" issue, however.
Thanks for reading...I'm sure these are lofty goals to see any
of this in the future, but the apparent desire to add lists
tells me there is some motivation for this type of data
structure even if the current utility of Lists seems
unintentionally low.</div>
<div><br>
</div>
<div><br>
</div>
<div>Kyle</div>
<div><br>
</div>
<div>test code (on 64-bit RHEL, 6.2.1):</div>
<div>
<div>begin</div>
<div><br>
</div>
<div> a = True</div>
<div> a@thing = 1</div>
<div> a@thing2 = 2</div>
<div> b = True</div>
<div> b@thing = 10</div>
<div> b@thing3 = 20</div>
<div> c = True</div>
<div> c@thing = 100</div>
<div> c@thing2 = 200</div>
<div><br>
</div>
<div> ;Part 1</div>
<div> arraylist = new(3,typeof(a))</div>
<div> arraylist(0) = a</div>
<div> arraylist(1) = b</div>
<div> arraylist(2) = c</div>
<div> print(arraylist(0)) ;expecting value/atts of a</div>
<div> k = arraylist(0)</div>
<div> print(k@thing) ; keeps atts of arraylist, which are
those of c</div>
<div> delete(k)</div>
<div> print("###############################")</div>
<div> ;Part 2</div>
<div> arraylist2 = (/a,b,c/)</div>
<div> print(arraylist(0))</div>
<div> k = arraylist(0)</div>
<div> print(k@thing) ; does same as first example.</div>
<div><br>
</div>
<div> print("###############################")</div>
<div> ;Part 3</div>
<div> thelist = NewList("fifo")</div>
<div> ListPush(thelist,a)</div>
<div> ListPush(thelist,b)</div>
<div> ListPush(thelist,c)</div>
<div> print(thelist) ; keeps values AND attributes</div>
<div><br>
</div>
<div> print("###############################")</div>
<div> ;Part 4</div>
<div> looplist = NewList("fifo")</div>
<div> looplist2 = NewList("fifo")</div>
<div> do i=0,2</div>
<div> thevar = i</div>
<div> thevar@att1 = i*12.0</div>
<div> ListPush(looplist,thevar)</div>
<div> ListPush(looplist2,(/thevar/))</div>
<div> end do</div>
<div> print(looplist)</div>
<div> y=ListPop(looplist)</div>
<div> print("First var from list, should be 0 with att of
0:")</div>
<div> print(y)</div>
<div> print("###############################")</div>
<div> print(looplist2)</div>
<div> print("###############################")</div>
<div> x=ListPop(looplist2) ; SEG FAULT here.</div>
<div> print(x)</div>
<div><br>
</div>
<div>end</div>
</div>
<div>
<div>
<div>
<div dir="ltr">----------------------------------------
<div>Kyle S. Griffin</div>
<div>Department of Atmospheric and Oceanic Sciences</div>
<div>University of Wisconsin - Madison</div>
<div>Room 1421</div>
<div>1225 W Dayton St, Madison, WI 53706</div>
<div>Email: <a href="mailto:ksgriffin2@wisc.edu" target="_blank">ksgriffin2@wisc.edu</a></div>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset></fieldset>
<br>
</div></div><pre>_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a>
</pre>
</blockquote>
<br>
</div>
<br>_______________________________________________<br>
ncl-talk mailing list<br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>