Re: array reordering

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Fri, 31 Mar 2006 10:08:47 -0700 (MST)

On Fri, 31 Mar 2006, Jim Edwards wrote:

> I have an array v with dims time,lat,lev,lon and I would like an array x
> with dims time,lev,ncol where ncol
> represents a collapse of lat x lon , the following gives a fairly
> uninformative syntax error. Oh wise and wonderful ncl oracle won't you
> suggest a better way?
>
> dims = getvardims(v)
> do i=0,sizes(1)-1
> do j=0,sizes(3)-1
> n=i*sizes(3)+j
> x($dims(0)$ | :,$dims(2)$ | :,n) = v($dims(0)$ |
> :,i,$dims(2)$ | :,j)
> end do
> end do
>

Hi Jim,

You can use the onedtond and ndtooned functions for converting to
1D and then back to an nD array of your choice. Note that you
don't need the "dims" variable:

; Reorder and convert to one-dimension.
   v1d = ndtooned(v($v!0$|:,$v!2$|:,$v!1$|:,$v!3$|:))

; Get dimension sizes
   dsizes = dimsizes(v)

; Convert to time x lev x latlon
   vnew = onedtond(v1d,(/dsizes(0),dsizes(2),dsizes(1)*dsizes(3)/))

; Rename dimensions
   vnew!0 = "time"
   vnew!1 = "lev"
   vnew!2 = "whatever"

--Mary
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Fri Mar 31 2006 - 10:08:47 MST

This archive was generated by hypermail 2.2.0 : Fri Mar 31 2006 - 10:32:42 MST