Re: A Simple where() Function for NCL Versions prior to 4.3.0

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu, 23 Aug 2007 10:50:03 -0600

THX ...

People update their NCL version for assorted reasons.
Often, when they see a new feature and want to use it.

To avoid future support conflicts, I suggest that users call Bruce's
function "WHERE". That way it is clear which where/WHERE :-)
we are talking about.

D
Lunde, Bruce N CIV NAVOCEANO, NP1 wrote:
> Hello,
>
> Here is a simple where() function for users of NCL versions prior to
> 4.3.0.
> No guarantees :) If you use it and have any suggestions or find any
> errors,
> please let me know.
>
> Thanks, Bruce
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;;;;;;;;
> ; PURPOSE:
> ; A where() function for NCL versions prior to V4.3.0 which performs
> simple
> ; substitutions such as
> ; anew = where(aold, aold.gt.3.3, 45.5)
> ; and preserves the existence/nonexistence of any _FillValue
> attribute.
> ; NOTES:
> ; * The third argument MUST be a scalar.
> ; HISTORY:
> ; 07-08-20 Bruce Lunde. Based on suggestions from Dennis Shea and Mary
> Haley
> ; in NCL-Talk archives.
> ; EXAMPLE:
> ; a=random_uniform(-2,2,(/2,2,2/))
> ; print(where(a,a.gt.1.1,888))
> ; a@_FillValue = 7777
> ; print(where(a,a.lt.-0.5,888))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> ;;;;;;;;
>
> undef("where")
> function where(foo,foomask,fooval)
> local fvexists, fvold, ans
> begin
> fvexists = False
> if( isatt(foo,"_FillValue") )then
> fvexists = True
> fvold = foo@_FillValue
> end if
> foo@_FillValue = fooval
> ans = mask(foo,foomask,False)
> delete(ans@_FillValue) ;.. Necessary so that fooval not changed to
> _FillValue
> if( fvexists )then
> foo@_FillValue = fvold
> ans@_FillValue = fvold
> else
> delete(foo@_FillValue)
> end if
> return(ans)
> end
>
>
>
>
> =====
> Bruce Lunde
> Bruce.Lunde_at_navy.mil
> 228-688-5843
> Code NP1
> Naval Oceanographic Office
> Stennis Space Center, MS
> =====
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>

-- 
======================================================
Dennis J. Shea                  tel: 303-497-1361    |
P.O. Box 3000                   fax: 303-497-1333    |
Climate Analysis Section                             |
Climate & Global Dynamics Div.                       |
National Center for Atmospheric Research             |
Boulder, CO  80307                                   |
USA                        email: shea 'at' ucar.edu |
======================================================
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Aug 23 2007 - 10:50:03 MDT

This archive was generated by hypermail 2.2.0 : Mon Aug 27 2007 - 14:59:53 MDT