[Thread Prev][Thread Next][Index]

Re: writing several .nc files to 1 file

This is a followup so that the solution will be entered into the mail
archives.  Many thanks to Steve Hankin and Emilio Mayorga for their help
and patience.

I'll summarize things so you don't have to weed through a bunch of

The problem:
I've got 17 netcdf that I want to combine into 1 netcdf file.  They all
are of dimension 144x37x1 (no time) of the same variable (ao).
The 144x37 are the same but they each have a different z-axis. (1000, 925,
850, 700....)  I want to combine them into a 144x37x17 file.

The solution:
There are really 2 different problems, one where the data to be put into
the file has no existing z-axis and 1 where the data does.  My
particular problem did have z-axis in the original files.

You can easily see this by running show grid var[d=dset] and looking if
there's a z-axis.

The original solution was provided by Emilio who wrote:
It seems you need to first define the common Z axis with DEFINE AXIS. Say
the name is "depth". You have irregularly spaced values, and I
can't remember right now how to create such an axis.
!NOTE: I created the axis that I needed with:
define axis/units=mb/depth my_zax =

After the axis is created, create a "z stamp" variable:
 LET zstamp = Z[GZ=my_zax] * 0
 Now to write the first ao z-slice, define a new ao variable to
stamp ao with its z value:
LET aoz = ao[d=1] + zstamp[K=1]

 Now you can write this first value into the file
 SAVE/FILE=verttest.nc/KLIMITS=1:17/CLOBBER/K=1 aoz

 For subsequent z slices, eg, K=5:
 LET aoz = ao[d=1] + zstamp[K=5]
 SAVE/FILE=verttest.nc/APPEND/K=5 aoz

NB: This will not work if your original data contained a z-axis.  Steve
Hankin showed me the way around this.  Steve wrote:

If there is a Z axis on variable ao then key is in the expression
 LET aoz = ao[d=2] + zstamp[K=1]
 When ao and zstamp are defined on differing Z axes then
    "ao[d=2] + zstamp[k=1]"  will inherit the Z axis of ao (on which K
is unspecified) whereas
"ao[d=2,k=1] + zstamp"  will inherit the Z axis of zstamp (on which
K is unspecified)
This is necessary so that expressions like "aoz[k=5]" are meaningful.
Use the SHOW GRID command to see the Z axis of "ao" and "aoz".
If ao does have a Z axis then replace
LET aoz = ao[d=2] + zstamp[K=1]
LET aoz = ao[d=2,k=1] + zstamp

and then write the file as before.

Thanks again Emilio and Steve.


- Brent

Brent A. McDaniel

Dept of Earth and Atmospheric Sciences
Georgia Institute of Technology
Atlanta, Ga.  USA

[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement