RE: [ncl-talk] Masking an array

From: Richard Carpenter (rcarpenter AT XXXXXX)
Date: Wed Aug 14 2002 - 15:39:15 MDT


Thanks, Alan. That did the trick.

Richard Carpenter

-----Original Message-----
From: Adam Phillips [mailto:asphilli AT cgd.ucar.edu]
Sent: Wednesday, August 14, 2002 4:14 PM
To: rcarpenter AT wdtinc.com
Cc: ncl-talk AT ucar.edu
Subject: Re: Masking an array

Richard,

Try this:

begin
  temp = (/ (/10.0, 20.0, 30.0/), (/20.0, 30.0, 40.0/), (/30.0, 40.0, 50.0/)
/)
  print (temp)

  hi_val = 12.0
  lo_val = 5.0

  array = temp ; just to get the dimensions
  array = hi_val

  array = mask( array, (temp .ge. 40.0), False )
  print (array)

  newarray = ndtooned(array) ;Needed for use in ind function

  indmsg = ind(ismissing(newarray))
  newarray(indmsg) = 5. ;Set all data that was missing to 5.
  final = onedtond(newarray,dimsizes(array))
  delete(array)
  delete(newarray)
  print(final)
end

The key is to convert the multidimensional array to one-dimensional, that
way
you can use ind and you can also use the results of ind(ismissing(array)) as
subscripts to assign the value that you want (in my example,
newarray(indmsg)=5)

Adam
-------------------------------------------------------------
Adam Phillips email: asphilli AT ucar.edu
Climate and Global Dynamics Division tel: (303) 497-1726
National Center for Atmospheric Research fax: (303) 497-1333
P.O. Box 3000
Boulder, CO 80307-3000 http://www.cgd.ucar.edu/~asphilli

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



This archive was generated by hypermail 2b29 : Thu Aug 15 2002 - 07:28:58 MDT