[ncl-talk] *ListIndex*: 1D array only
Liang Guo
liang.guo.81 at gmail.com
Wed Nov 5 04:26:23 MST 2014
Hello,
I try to use *ListIndex* to retrieve the index of a named variable (2-D)
that has been pushed into a List variable. But, it failed.
Then, I spent some time to explore the reason. I start with a simple 1-D
example that is gave by NCL webpage (
http://www.ncl.ucar.edu/Document/Functions/Built-in/ListIndex.shtml). It
does what it does. However, when I expended those example arrays into 2-D,
function *ListIndes* collapsed. Here are what I did and what output shows:
*> ; for 1D, it works fine*
*> x = (/1,2,3,4/)*
*> x at attr = "integer array"*
*> y = (/6.,7.,8.,9./)*
*> y at attr = "float array"*
*> s = (/"one","two","three"/)*
*> s at attr = "string array"**> *
*> my_list = NewList("lifo")**> *
*> ListPush(my_list,x)*
*> ListPush(my_list,y)*
*> ListPush(my_list,s)**> *
*> cnt = ListCount(my_list)*
*> print(cnt)**> *
*> idx = ListIndex(my_list, x)*
*> print(idx)**> *
*> ; For 2D*
*> nx = dimsizes ( x )**> **X = conform_dims ( (/2,nx/), x, 1 )*
*> ny = dimsizes ( y )**> Y = conform_dims ( (/2,ny/), y, 1 )*
*> ns = dimsizes ( s )*
*> S = conform_dims ( (/2,ns/), s, 1 )**> *
*> MY_list = NewList("lifo")**> *
*> ListPush(MY_list,X)*
*> ListPush(MY_list,Y)*
*> ListPush(MY_list,S)**> *
*> Cnt = ListCount(MY_list)*
*> print(Cnt)**> *
*> Idx = ListIndex(MY_list, X)**> print(Idx)*
And the output is:
*> Variable: cnt> Type: integer*
*> Total Size: 4 bytes*
*> 1 values*
*> Number of Dimensions: 1*
*> Dimensions and sizes: [1]*
*> Coordinates: *
*> (0) 3**> *
*> *
*> Variable: idx*
*> Type: integer*
*> Total Size: 4 bytes*
*> 1 values*
*> Number of Dimensions: 1*
*> Dimensions and sizes: [1]*
*> Coordinates: *
*> (0) 2**> *
*> *
*> Variable: Cnt*
*> Type: integer*
*> Total Size: 4 bytes*
*> 1 values*
*> Number of Dimensions: 1*
*> Dimensions and sizes: [1]*
*> Coordinates: *
*> (0) 3*
*> fatal:Number of dimensions in parameter (1) of (ListIndex) is (2), (1)
dimensions were expected *
*> fatal:["Execute.c":8578]:Execute: Error occurred at or near line 40 in
file test_ListIndex.ncl**> *
*> fatal:Variable (Idx) is undefined**> fatal:["Execute.c":8578]:Execute:
Error occurred at or near line 41 in file test_ListIndex.ncl*
As shown in the 4th line from the bottom of the output, *ListIndex* expects
a 1-D array, while a 2-D array is fed in, it does not retrieve anything and
collapse.
Any idea about this?
Best,
Liang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141105/4e2d395d/attachment.html
More information about the ncl-talk
mailing list