[Thread Prev][Thread Next][Index]

Re: 3D to 2D



Hi ,
You could use a repeat loop and list the data for each time:

yes? REPEAT/L=1:73 \
(list/file=2DD.domain.dat/append/format=(G12.2)/append 3dcr2[L=`L`])

This makes a long list with one data value per record, and with text at the
start of each time step.  If you want to list the data without the header
information, you could use the /NOHEADER qualifier on the LIST command.

Ansley

R Prabowo wrote:

Hi Ansley,

Thanks for your solution. It works well. However, I have another problem from reshaping the data especially when my output is in ascii form (I want to use it in different package using input ascii file). The reshaped data will be (65*33 x 73). When I created output ascii file using:

list/clobber/file=2D.domain.dat 5dcr2D

It worked well, but when I did 'vi 2D.domain.dat', it will be '... listing every 120th point'

when I used:

list/clobber/order=tx/file= 2DD.domain.dat 5dcr2D

it will be '... listing every 4th point'.
I want to avoid this thing (... listing every ..), so I hunted the mail archive, there is one answer from Steve dated back to 31 Aug 1995. The thing is when I used:

list/format=(2145G12.2)/clobber/file= 2D.domain.dat 5dcr2D
LISTing to file 2D.domain.dat
**ERROR: (2145G12.2)xÌô: Error 0
list/format=(2145G12.2)/clobber/file= 2D.domain.dat 5dcr2D
Command file, command group, or REPEAT execution aborted

When I used:

list/format=(100G12.2)/clobber/order=tx/file=2DD.domain.dat 5dcr2D

The 'vi 2DD.domain.dat' will be:

VARIABLE : RESHAPE(VAR3D,VAR2D)
FILENAME : 3D.domain.nc
BAD FLAG : -9.9999998E+33
SUBSET : 73 by 2145 points (TIME-X)
TIME : 01-JAN :00:00 to 31-DEC 12:09
X : 0.5 to 2145.5
0.24E+03 0.24E+03 0.24E+03 0.24E+03 0.24E+03 0.24E+03 0.24E+03 0.24E+03 0.24E+03 0.24E+03 0.24E+03 0.24E+03 0.24E+03 0.24E+03 0.24E+03 0.23E+03 0.23E+03 0.23E+03 0.23E+03 0.23E+03 0.23E+03 ...

My concern is 'is any way to do non-decimated LIST output' for big file? Thank you very much.


mrp

Ansley Manke <ansley.b.manke@noaa.gov> wrote:

Hi,
I don't think your question reached the Users' List,
but here's a simple answer. The function RESHAPE(A,B) wraps argument A onto the grid of argument B. We can define the output grid with an abstract X axis of length NX*NY, and the same time axis as the input grid, create a dummy variable on the output grid, then use RESHAPE
to define the output 2D variable

Here is a simple example:


! Define a small 3-D variable

yes? def axis/x=1:5:1 xax
yes? def axis/y=1:3:1 yax
yes? def axis/t=1:4:1 tax
yes? let var3d = x[gx=xax] + 10*y[gy=yax] + 100*t[gt=tax]
yes? list/l=1/j=1 var3d
VARIABLE : X[GX=XAX] + 10*Y[GY=YAX] + 100*T[GT=TAX]
SUBSET : 5 points (X)
Y : 1
T : 1
1 1
1 / 1: 111.0
2 / 2: 112.0
3 / 3: 113.0
4 / 4: 114.0
5 / 5: 115.0
yes? list/l=4/j=2 var3d
VARIABLE : X[GX=XAX] + 10*Y[GY=YAX] + 100*T[GT=TAX]
SUBSET : 5 points (X)
Y : 2
T : 4
2 2
1 / 1: 421.0
2 / 2: 422.0
3 / 3: 423.0
4 / 4: 424.0
5 / 5: 425.0

! Define a 2-D grid and a variable on it.

yes? def axis/x=1:`5*3`:1 space_ax
!-> def axis/x=1:15:1 space_ax
yes? let var2d = 0*x[gx=space_ax] + 0*t[gt=tax]

! Use the RESHAPE function to create the output 2-D variable.
! Check the values.

yes? let outvar = reshape(var3d,var2d)
yes? list/l=1 outvar
VARIABLE : RESHAPE(VAR3D,VAR2D)
SUBSET : 15 points (X)
T : 1
1 / 1: 111.0
2 / 2: 112.0
3 / 3: 113.0
4 / 4: 114.0
5 / 5: 115.0
6 / 6: 121.0
7 / 7: 122.0
8 / 8: 123.0
9 / 9: 124.0
10 / 10: 125.0
11 / 11: 131.0
12 / 12: 132.0
13 / 13: 133.0
14 / 14: 134.0
15 / 15: 135.0
yes? list/l=4 outvar
VARIABLE : RESHAPE(VAR3D,VAR2D)
SUBSET : 15 points (X)
T : 4
1 / 1: 411.0
2 / 2: 412.0
3 / 3: 413.0
4 / 4: 414.0
5 / 5: 415.0
6 / 6: 421.0
7 / 7: 422.0
8 / 8: 423.0
9 / 9: 424.0
10 / 10: 425.0
11 / 11: 431.0
12 / 12: 432.0
13 / 13: 433.0
14 / 14: 434.0
15 / 15: 435.0




R Prabowo wrote:


Hi there,

I have a 3D data (long, lat, time) size of (65, 33, 73). I want make this 3D data become a 2D data (long-lat, time or 65x33, 73). I have been trying to do it by using nested repeat command as script bellows. But up 1995 iteration, there is error saying that:

**ERROR: a program limit has been reached: too many user-defined variables
cancel or redefine some variables
DEFINE VARIABLE 5dcr2D1995=5dcr[i=45,j=31]
Command file, command group, or REPEAT execution aborted

The script I used is:

can data/all
can var/all
SET MEMORY/SIZE=15
use/regulart data.nc
show data/full
DEFINE AXIS/T=3-JAN:29-DEC/npoints=73 tpentad LET zero=T[gt=tpentad@mod] * 0 REPEAT/l=1:73 ( \
REPEAT/j=1:33 ( \
REPEAT/i=1:65 ( \
let ij = `i`+(`j`-1)*65; \
let 5dcr2D`ij`=5dcr[i=`i`,j=`j`]); \
let 5dcr2D= 5dcr2D`ij`+zero[l=`l`]; \
save/append/file= data2D.nc 5dcr2D))

Is there any one has any elegant way to do this work? Thank you very much.








[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement