[ncl-talk] populating lists with multidimensional arrays
Alan Brammer
abrammer at albany.edu
Thu Mar 3 11:05:14 MST 2016
Think this “trick" has been posted before, building on the sample from Wei, you can trick NCL into replicating the variable in the global namespace(?) and thus avoid the associative nature of lists while still keeping hold of the metadata.
To add to the potential list of bugs though, if you then use list_vars() after either workaround it seg faults.
undef("replicate_var")
function replicate_var(tmpvar)
local dummyvar
begin
dummyvar = (/tmpvar/)
copy_VarMeta(tmpvar, dummyvar)
return(dummyvar)
end
P = NewList("fifo") ;create new list
Q = NewList("fifo") ;another new list
x = (/(/1,2,3/),(/4,5,6/)/) ;a test array
x!0 = "dim0"
x!1 = "dim1"
do i = 0, 2
ListAppend(P,(/x/)) ;keep adding array 'x'
ListAppend( Q, replicate_var( x(:,:i) ))
end do
do i = 0, 2
print(Q[i])
end do
; list_vars() Segmentation Fault: 11
> On 3 Mar 2016, at 09:27, Wei Huang <whuang at univ-wea.com> wrote:
>
> Will,
>
> You’d better use (the sample) list this way:
>
> P = NewList("fifo") ;create new list
> Q = NewList("fifo") ;another new list
> x = (/(/1,2,3/),(/4,5,6/)/) ;a test array
>
> do i = 0, 2
>
> ListAppend(P,(/x/)) ;keep adding array 'x'
> ListAppend(Q,(/x(:,:i)/)) ;add a different sized subset of 'x'
>
> end do
>
> print(P[1])
> print(Q[0])
>
> Wei Huang
>
> From: ncl-talk-bounces at ucar.edu [mailto:ncl-talk-bounces at ucar.edu] On Behalf Of Rick Brownrigg
> Sent: Wednesday, March 02, 2016 11:25 PM
> To: Will Hobbs
> Cc: ncl-talk at ucar.edu
> Subject: Re: [ncl-talk] populating lists with multidimensional arrays
>
> Hi Will,
>
> It looks like you've uncovered a bug, and it seems to relate to the array-slicing in combination with the list. If I manually create a list comprised of different sized arrays, it works:
>
> l = [/ (/ 1, 2, 3 /), (/ 4, 5, 6, 7, 8 /) /]
> print(l)
>
> But if we take a condensed version of your example:
> We get:
>
> ListAppend(Q,x(:,:2))
> print(Q)
>
>
> Variable: Q
> Type: list
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> Type: list <fifo>
> Total items: 0
>
> which is clearly not right. I tried assigning the slice of the x-array to a temporary variable and then appending the temp-var to the list, but that does not work either.
>
> I will file a bug-report ticket in the morning and take a look at what is going on. I'm sorry that I don't have a good work-around offhand.
>
> Rick
>
>
> On Wed, Mar 2, 2016 at 7:56 PM, Will Hobbs <will.hobbs at utas.edu.au <mailto:will.hobbs at utas.edu.au>> wrote:
> Hi all
>
> My understanding from the documentation is that elements of an NCL list do not need to be the same size, but I am having trouble populating a list with arrays that are not the same size.
>
> Consider the following test case:
>
> P = NewList("fifo") ;create new list
> Q = NewList("fifo") ;another new list
> x = (/(/1,2,3/),(/4,5,6/)/) ;a test array
>
> do i = 0, 2
>
> ListAppend(P,x) ;keep adding array 'x'
> ListAppend(Q,x(:,:i)) ;add a different sized subset of 'x'
>
> end do
>
> print(P)
>
> ;returns the following (expected)
> ;Variable: P
> ;Type: list
> ;Total Size: 4 bytes
> ; 1 values;
> ;Number of Dimensions: 1
> ;Dimensions and sizes: [1]
> ;Coordinates:
> ;Type: list <fifo>
> ;Total items: 3
>
>
> print(Q)
> ;returns the following (an empty list)Variable: P
> Type: list
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> Type: list <fifo>
> Total items: 0
>
> What am I missing here?
>
> Many thanks
>
> Will
>
>
> University of Tasmania Electronic Communications Policy (December, 2014).
> This email is confidential, and is for the intended recipient only. Access, disclosure, copying, distribution, or reliance on any of it by anyone outside the intended recipient organisation is prohibited and may be a criminal offence. Please delete if obtained in error and email confirmation to the sender. The views expressed in this email are not necessarily the views of the University of Tasmania, unless clearly intended otherwise.
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu <mailto:ncl-talk at ucar.edu>
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk <https://urldefense.proofpoint.com/v2/url?u=http-3A__mailman.ucar.edu_mailman_listinfo_ncl-2Dtalk&d=BQMFaQ&c=qHNyRuJKHYeI-vwTnTfWXq4fkZpyjWUA1LcPL7eQSSQ&r=6RmpIe4P-G8omsHqYS85uBS-3JaNVk3lvOG-hmdOrr8&m=lBd74BJhsMxur2qbjvLn5ZxbQYoG5bap8U3d9FQunfE&s=dB7cfWtxSBDMVxj7lJp57b7VqtkKdyhrr-z9OkRoQpI&e=>
>
> _______________________________________________
> 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/20160303/330e806e/attachment.html
More information about the ncl-talk
mailing list