[ncl-talk] Retrieving variables from lists.

Brammer, Alan P abrammer at albany.edu
Mon Aug 4 15:26:04 MDT 2014


Dear NCL talk, 

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. 

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.  

Can I get an array of the variables names within a list so I can then pull “x” out using ListIndex or something similar.  
Is there a listIndex where I pass the variable name instead of the variable.  
Do I have to attach a list of names and index locations to the list so I know where things are in it? 


As always these example scripts are exemplifying much more complicated code therefore hard coding the answer isn’t really the solution I want. 


Thanks in advance, 

Alan. 




undef("list_test")
function list_test(a:logical)
local k, x, y, x, retlist
begin
  if(a)
      x = fspan(0,10, 11)
      y = fspan(100,120,11)   ;  just random arrays of numbers. 
      z = ispan(0,100,1)
      retlist = [/ x, y, z /]
  else
      k  = ispan(10,15, 1)
      x = fspan(10,20, 11)
      y = fspan(200,220,11)
      retlist = [/ k, x, y /]
  end if

  return(retlist)
end




begin

firstlist = list_test(True)
print(firstlist)

; xind = ind( firstlist .eq. “x”   )   ;;; is there some way for this to work?  firstlist at variable ? ?

secondlist = list_test(False)
print(secondlist)

; xind = ind( secondlist .eq. “x”   )   ;;;  

end



More information about the ncl-talk mailing list