Re: ind function ??

From: Mary Haley (haley AT XXXXXX)
Date: Thu Sep 05 2002 - 08:11:12 MDT


>
> Hi folks,
>
> I want to select data from a 4D field, that fulfill
> certain criteria (like .gt.10)
>
> For 1D fields I used succesfully
>
> iii= ind( d1field .gt. 10.)
>
> to get the indices of the elements that are larger than 10.
>
> The same construct gives an NCL error if I use a 4D field
> something like : (expecting 1D variable and not 4D...).
> Is this a real limitation for the ind function ?
> Is there a simple trick around ?
>
> Can anyone help ?
>
> Thanks, Adolf

Hi Adolf,

The "ind" function is indeed limited to 1D arrays. To use it with
multiply dimensioned arrays, you need to use the "onedtond" function,
which converts an nD array to a 1D array. For example, assume
"d4field" is your 4D array:

   iii = ind( ndtooned(d4field) .gt. 10.)

You can use the "ind_resolve" function to resolve the 1D indices to
their original 4D representation:

  d1field = ndtooned(d4field)
  iii4D = ind_resolve( ind(d1field .gt. 10.), dimsizes(d1field) )

"iii4D" will be a 2D array dimensioned N x M, where N is the number of
indices where the field was > 10, and M is the number of dimensions in
your original field (=4 in this case).

For more information on ind_resolve, go to:

    http://ngwww.ucar.edu/ngdoc/ng/ref/ncl/functions/indresolve.html

--Mary

_______________________________________________
ncl-talk mailing list
ncl-talk@ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk



This archive was generated by hypermail 2b29 : Thu Sep 05 2002 - 08:22:51 MDT