Search code examples
netcdfnco

Define a new dimension to one of the variables in netCDF file


I have a NetCDF file which include lots of variables (1d, 2d, 3d, and 4d). I want to add a new dimension to one of the 3d variables.

To make it more clear, suppose:

I have a 3d variable: A(d1, d2, d3)

I want to have 4d variable: A(d1, d2, d3, d4)

In fact, d4 is the new dimension which I would like to add to my variable. I do not have d4 in my file. I know it has just one value.

I would appreciate that if anyone guide me.


Solution

  • Using NCO:

    ncap2 -s 'defdim("d4",737);A_new[$d1,$d2,$d3,$d4]=A' in.nc out.nc