[ncl-talk] populating lists with multidimensional arrays

Wei Huang whuang at univ-wea.com
Thu Mar 3 07:27:37 MST 2016


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=>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160303/5a9fb361/attachment.html 


More information about the ncl-talk mailing list