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

From: Lunde, Bruce N CIV NAVOCEANO, NP1 <bruce.lunde_at_nyahnyahspammersnyahnyah>
Date: Thu, 23 Aug 2007 11:43:22 -0500

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
Received on Thu Aug 23 2007 - 10:43:22 MDT

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