<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
Dave & all,
<div><span class="Apple-tab-span" style="white-space:pre"></span>I think both your potential situations could be useful if available, but as you say would cause issue if just one function was used. I think variants of the ListIndex function would be a good
solution though. Even just a function to return the symbol names of the variables in the list would provide a way to then find the index and access the variable (though this is the in essence exactly the same as getting listindex to accept strings). I’m thinking
along the lines of Object.keys() in javascript.
<div><br>
</div>
<div><br>
</div>
<div>This is along the same line: </div>
<div>Is there a way to access the information that is printed in at the top of a print() or printVarSummary(), bolded below.. Similar to the list problem, I’ve passed files to a function and wanted to be able to access the filename but it seems like an unaccessible
region of metadata. </div>
<div><br>
</div>
<div>I can start a new thread about this is desired. </div>
<div><br>
</div>
<div>Alan. </div>
<div><br>
</div>
<div><br>
</div>
<div>e.g. </div>
<div><br>
ncl 1> inf = addfile("test.nc","r") <br>
ncl 2> print(inf)<br>
<br>
<b>Variable: inf</b><br>
<b>Type: file<br>
filename:<span class="Apple-tab-span" style="white-space:pre"> </span>test<br>
path:<span class="Apple-tab-span" style="white-space:pre"> </span>test.nc</b><br>
<br>
</div>
<div>;;; or per the previous emails. </div>
<div> firstlist = list_test(True)<br>
print(firstlist)</div>
<div>
<div>
<div><br>
<b>Variable: firstlist</b><br>
Type: list<br>
Total Size: 4 bytes<br>
1 values<br>
Number of Dimensions: 1<br>
Dimensions and sizes:<span class="Apple-tab-span" style="white-space:pre"> </span>
[1]<br>
Coordinates: <br>
Type: list <fifo><br>
Total items: 3<br>
<br>
List Item 0:<span class="Apple-tab-span" style="white-space:pre"> </span>NclVarClass<br>
<b>Variable: x</b><br>
Type: float<br>
Total Size: 44 bytes<br>
11 values<br>
Number of Dimensions: 1<br>
Dimensions and sizes:<span class="Apple-tab-span" style="white-space:pre"> </span>
[11]<br>
Coordinates: <br>
<br>
</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span></div>
<div><br>
</div>
<div><br>
</div>
<div><br>
<div>
<div>On Aug 5, 2014, at 16:21, David Brown <<a href="mailto:dbrown@ucar.edu">dbrown@ucar.edu</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<div dir="ltr">Hi Alan,
<div>We do see that ListIndex is currently limited to indexing variables within the current scope. I agree that it would be a good idea to allow for indexing based on the symbol name as a string. We will add a ticket for this feature. Our current thinking is
that we will allow the ListIndex function to accept strings as well as actual variable references unless we encounter unforeseen difficulties with that approach. Of course, one might want to index on variable values as well, in which case, there could be a
conflict between the string name of a variable and a string value. So it's possible we may need more than one function. </div>
<div> -dave</div>
<div><br>
</div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Mon, Aug 4, 2014 at 7:27 PM, Alan Brammer <span dir="ltr">
<<a href="mailto:abrammer@albany.edu" target="_blank">abrammer@albany.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto;">
<div>Spoke with Kyle offline; just for everyone else while this is useful info it does not address my issue.
<br>
<br>
The example shows that x is not defined in the main body so ListIndex does not work. The two instances of x in the list have different values as desired but how can one retrieve them without exactly knowing their location.
<br>
<br>
For now I am attaching my own naming attribute to each variable to then identify list items later on.<br>
<br>
Thanks, <br>
Alan. <br>
<div>
<div class="h5"><br>
<br>
<br>
<div class="gmail_quote">On 4 August 2014 17:57:13 GMT-04:00, Kyle Griffin <<a href="mailto:ksgriffin2@wisc.edu" target="_blank">ksgriffin2@wisc.edu</a>> wrote:
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex; position: static; z-index: auto;">
<div dir="ltr">So are you referencing the ListIndex function?
<div><br>
</div>
<div><a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/ListIndex.shtml" target="_blank">https://www.ncl.ucar.edu/Document/Functions/Built-in/ListIndex.shtml</a><br>
<div><br>
</div>
<div>From the list section of the manual... <a href="https://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclVariables.shtml#ListVariables" target="_blank">https://www.ncl.ucar.edu/Document/Manuals/Ref_Manual/NclVariables.shtml#ListVariables</a></div>
<div><br>
</div>
<div>I usually try to construct lists with ListPush and ListPop...this is more consistent with how lists are intended to work in other languages (I know it from Java, but I'm sure there are others) where they are intended to host any number of data types, but
the *order* of the items is what is relevant. You declare the list to be "first-in, first out" or "last-in, first out" and push things in or pop things out of the list, which will return items as intended. You can also get the index and pull it out as an object
from an array would as well, although this is not as simple.</div>
</div>
<div><br>
</div>
<div>Personally, I've had a few issues with how variables are treated once pushed/popped from a list last time I tried to use the feature, but I can't recall what the specific issue was off the top of my head. I'd be curious as well to hear more from those
who work with lists in NCL more often.</div>
<div><br>
</div>
<div><br>
</div>
<div>Kyle</div>
</div>
<div class="gmail_extra"><br clear="all">
<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>
<br>
<br>
<div class="gmail_quote">On Mon, Aug 4, 2014 at 4:26 PM, Brammer, Alan P <span dir="ltr">
<<a href="mailto:abrammer@albany.edu" target="_blank">abrammer@albany.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto;">
Dear NCL talk,<br>
<br>
I never really utilise lists in NCL as I struggle with how they work. Hopefully this mundane example can help clarify my desires and maybe find a solution. Or maybe I’m trying to use them in a way they were not meant.<br>
<br>
I have a function “list_test” as below, and in my script I call that and depending on the argument will get a return list back, that all works great. My question is how do I get say variable "x" out of the returned list. I can assume its location in the list
but that seems risky and unfriendly for development.<br>
<br>
Can I get an array of the variables names within a list so I can then pull “x” out using ListIndex or something similar.<br>
Is there a listIndex where I pass the variable name instead of the variable.<br>
Do I have to attach a list of names and index locations to the list so I know where things are in it?<br>
<br>
<br>
As always these example scripts are exemplifying much more complicated code therefore hard coding the answer isn’t really the solution I want.<br>
<br>
<br>
Thanks in advance,<br>
<br>
Alan.<br>
<br>
<br>
<br>
<br>
undef("list_test")<br>
function list_test(a:logical)<br>
local k, x, y, x, retlist<br>
begin<br>
if(a)<br>
x = fspan(0,10, 11)<br>
y = fspan(100,120,11) ; just random arrays of numbers.<br>
z = ispan(0,100,1)<br>
retlist = [/ x, y, z /]<br>
else<br>
k = ispan(10,15, 1)<br>
x = fspan(10,20, 11)<br>
y = fspan(200,220,11)<br>
retlist = [/ k, x, y /]<br>
end if<br>
<br>
return(retlist)<br>
end<br>
<br>
<br>
<br>
<br>
begin<br>
<br>
firstlist = list_test(True)<br>
print(firstlist)<br>
<br>
; xind = ind( firstlist .eq. “x” ) ;;; is there some way for this to work? firstlist@variable ? ?<br>
<br>
secondlist = list_test(False)<br>
print(secondlist)<br>
<br>
; xind = ind( secondlist .eq. “x” ) ;;;<br>
<br>
end<br>
<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>
</blockquote>
</div>
<br>
</div>
</blockquote>
</div>
</div>
</div>
</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>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</body>
</html>