removing zero dimensions ...

From: Ufuk Utku Turuncoglu (BE) <u.utku.turuncoglu_at_nyahnyahspammersnyahnyah>
Date: Wed Jun 01 2011 - 03:48:04 MDT

Hi,

I just wonder that is there any NCL function or procedure (i could not
find in the documentation) that removes the dimensions that it's actual
length is one (i call it as zero dimension). For example, i have a 4d
array and its dimension sizes are "tmp(10, 3, 1, 45)" and i want to
remove the third dimension and the result array would be "tmp(10,3,45)".
I actually wrote the following function to do that but i just want to be
sure it is a generic solution or not

;---------------------------------------------------------
; Removes the zero dimensions from the variable
; Input:
; data - original data
; Output:
; tmp - modified data
;---------------------------------------------------------
undef("rm_empty_dims")
function rm_empty_dims(data:numeric)
begin
   ;--- get dimension size of the data ---
   dims = dimsizes(data)
   rank1 = dimsizes(dims)

   ;--- find the indices of the non-zero dimensions ---
   indx = ind(dims .ne. 1)
   rank2 = dimsizes(indx)

   ;--- if zero dimension exist, create new data array ---
   if (rank1 .ne. rank2) then
     tmp = new(dims(indx), typeof(data))
     tmp = data
     return(tmp)
   else
     return(data)
   end if
end

because, as you can see from the code i could do nothing about
attributes. How can be sure that result field will have correct
metadata? May be additional code can be implemented to ensure that. Is
the "tmp = data" operation safe between variables that are in different
rank (there could be shifting if it is not safe). Also note that the
current version of the code is working in my case.

--ufuk
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Jun 1 03:48:19 2011

This archive was generated by hypermail 2.1.8 : Wed Jun 01 2011 - 12:41:15 MDT