Re: Array of objects

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Thu Jan 27 2011 - 15:49:56 MST

Hi Daniel,

There are some undocumented capabilities in NCL 5.2.1 for doing some of things you are looking for. In 6.0.0 there will be additional capabilities. I am attaching a small script that shows what you can do now. Note that a major hole in the functionality is a way to get a count of the number of elements in the list without keeping an independent count. That should be available in 6.0.0, along with syntax for creating a list from literal elements (i.e., given variables, any type, create a list l):

l = [/ a, b, c /]

Briefly, the routines available now are:

functions:
l = NewList(listtype : string) ; valid types are "cat", "join" (both specific to file lists -- at least for now), "fifo" (first in first out), and "lifo" (last in first out)
v = ListPop(l) ; removes and returns an element from the list
s2 = ListGetType(l) ; returns a string array of length two : (0) "cat" or "join" (1) "fifo" or "lifo"

procedures:

ListPush(l, var_or_value)
ListSetType(l, listtype : string) ; only accepts a single string, not an array.

As far as I can tell the "lifo" and "fifo" options do not seem to do anything currently, and of course "cat" and "join" seem kind of meaningless for heterogeneous lists.

These are undocumented because as you can see they are not all completely defined, and some aspects of their behavior may change.
But we would be happy for you to try out what is available and please make suggestions.

 -dave

On Jan 27, 2011, at 9:39 AM, <Daniel.Leuenberger@meteoswiss.ch> <Daniel.Leuenberger@meteoswiss.ch> wrote:

> Dear NCL Community,
>
> I would like to pass many objects to a procedure or function, but I know
> the number only at run time. How can I pass multiple objects in an array
> to the procedure? Consider the following small ncl script:
>
> ;For example, I have a procedure
> procedure proc(x,y)
> begin
> print(x)
> print(y)
> End
>
> begin
> ; here, I define an object a with an attribute attr
> a=(/1,2,3/)
> a@attr="a1"
> ; likewise the object b
> b=(/4,5,6/)
> b@attr="b1"
>
> ;Now I can pass those variables to the procedure
> proc(a,b)
> end
>
> and I get, what I want. No problem. Now, if I had many objects
> like a and b and I would like to store them in an array and pass them
> to a procedure which takes an array of objects as argument.
> Inside the procedure, I would like to access the elements of the arrays
> including their attributes, dimensions and so on. If I create an array
> of a and b such as c = (/a,b/), I loose all attributes of a and b. The
> objects
> May also be graphics objects.
>
> I have found a topic in the mailing list archive, in which you announce
> the type "list". Is this already implemented? When is it foreseen? What
> would you suggest in the meanwhile?
>
> A "list" type would be an extremely helpful feature of the NCL language.
>
> Many thanks and best regards
> Daniel Leuenberger
>
> ________________________________________
>
> Daniel Leuenberger
> Numerical Models
>
> Federal Departement of Home Affairs FDHA Federal Office of Meteorology
> and Climatology MeteoSwiss
>
> Kraehbuehlstrasse 58, P.O. Box 514, CH-8044 Zurich, Switzerland
>
> Tel. +41 44 256 97 10
> Fax +41 44 256 92 78
> daniel.leuenberger@meteoswiss.ch
> www.meteoswiss.ch - First-hand information
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

Received on Thu Jan 27 15:50:00 2011

This archive was generated by hypermail 2.1.8 : Mon Jan 31 2011 - 10:38:24 MST