Re: Masking an array

From: Adam Phillips (asphilli AT XXXXXX)
Date: Wed Aug 14 2002 - 15:14:17 MDT


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@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@ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk



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