# Re: converting 2D array to 3D array

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Apr 09 2012 - 12:54:37 MDT

Juky,

You enclosed a data file, but you didn't indicate how the data are written to this file, so I'm not sure how to read it in.

You can go from a 2D array to a 3D array by using a combination of ndtooned, onedtond, and possibly reordering commands.

I'm not sure how your 303 x 406 array is ordered with regard to the "3" and the "101" values. It depends on how it is laid out. That is, is it laid out as (3x101) x 406, or as (101x3) x 406?

If it is (3x101) x 406, then you could do something like:

;---Convert from 303 x 406 to 3 x 101 x 406
data3d = onedtond(ndtooned(data2d),(/3,101,406/))

;---Reorder to 101 x 406 x 3
data3d!0 = "dim0"
data3d!1 = "dim1"
data3d!2 = "dim2"
data3d_reorder = data3d( dim1 | :, dim2 | :, dim0 | :)

;---Check the results
printVarSummary(data3d_reorder)

If it's (101x3) x 406:

;---Convert from 303 x 406 to 101 x 3 x 406
data3d = onedtond(ndtooned(data2d),(/101,3,406/))

;---Reorder to 101 x 406 x 3
data3d!0 = "dim0"
data3d!1 = "dim1"
data3d!2 = "dim2"
data3d_reorder = data3d( dim0 | :, dim2 | :, dim1 | :)

;---Check the results
printVarSummary(data3d_reorder)

I used "dim0", "dim1" as examples here, but you should use whatever names are appropriate for your data's dimensions, like "lat", "lon", "time", etc.

--Mary

On Apr 6, 2012, at 3:19 AM, juki juki wrote:

> Hi all,
>
> I would like to convert 2D to 3D array and save it as ascii file (txt file). Enclosed file is an example. This file is from 3 hours observation(hourly) for latitude -10:10 and longitude 70:160E. I want to convert this 2D (303 x 406) to become 3D (101 x 406x 3) and save it to ascii file or if it is not possible to binary file. I think, almost all of NCAR data like OLR is 3D array format, but in nc file, how to produce it for text file or binary file using ncl language ? Thanks for sharing....
>
> JuKy
>
>
>
>
> <200111.txt>_______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Apr 9 12:54:44 2012

This archive was generated by hypermail 2.1.8 : Mon Apr 09 2012 - 13:43:03 MDT