>
> >Does anyone have a suggestion how to do this
> >without using a do loop, so it's faster? Thanks.
> >
> > do ilat=0,359
> > do ilon=0,719
> >
> > if (var(ilat,ilon).ge.30.) then
> > var(ilat,ilon)=30.
> > end if
> > if (var(ilat,ilon).le.-30.) then
> > var(ilat,ilon)=-30.
> > end if
> >
> > end do
> > end do
>
> **untested**
>
> Use NCL's "ind" function. This will be quite fast.
>
> var_1d = ndtooned(var) ; convert to 1D
> inda = ind(var_1d.gt. 30) ; indices
> indb = ind(var_1d.lt.-30)
>
> if (.not.any(ismissing(inda))) then ; makes sure inda not "missing"
> var_1d(inda) = 30.
> end if
>
> if (.not.any(ismissing(indb))) then
> var_1d(indb) = -30.
> end if
>
> var = onedtond(var_1d, dimsizes(var)) ; reconstruct
>
This is a good solution, especially if you have complicated
things that you need to test for inside the "ind" statement.
A solution that doesn't require you to use "ndtooned" and "onedtond"
is to use the "<" and ">" operators:
var = var < 30
var = var > -30
Here's the description of these two operators:
Less-than selection <
For arrays, the less-than selection operator selects all values in
the left operand that are less than the corresponding value in the
right operand. If the value of the left side is greater than or
equal to the corresponding value of the right side, then the right
side value is placed in the result. For a scalar and an array, the
same selection rules apply, but the scalar is compared against
each value in the array operand.
Greater-than selection >
For arrays, the greater-than selection operator selects all values
in the left operand that are greater than the corresponding value
in the right operand. If the value of the left side is less than
or equal to the corresponding value of the right side, then the
right side value is placed in the result. For a scalar and an
array, the same selection rules apply, but the scalar is compared
against each value in the array operand.
--Mary
-------------------------------------------------
Mary Haley haley@ucar.edu
NCAR/SCD/VETS 303-497-1254 (voice)
1850 Table Mesa Dr 303-497-1804 (fax)
Boulder, CO 80305
-------------------------------------------------
_______________________________________________
ncl-talk mailing list
ncl-talk@ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
This archive was generated by hypermail 2b29 : Tue Jun 22 2004 - 15:05:37 MDT