5

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.

wonea
  • 4,783
  • 17
  • 86
  • 139
zhr
  • 419
  • 2
  • 6
  • 14

1 Answers1

7

Using NCO:

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

Charlie Zender
  • 5,929
  • 14
  • 19
  • Is there a way to maintain A's attributes in A_new? – Dave X Mar 08 '17 at 19:51
  • A_new will have the same dimensions A. You might be using an older versiono of ncap2. Please update and try again. – Charlie Zender Feb 13 '20 at 19:42
  • I also find this removes the attributes of A in A_new, using NCO netCDF Operators version 4.9.2 "Delirium" built by brew on Catalina at Apr 6 2020 18:39:20 ncap2 version 4.9.2 – ClimateUnboxed Sep 23 '20 at 12:29
  • Adrian, I tried (not too hard, though) and I cannot reproduce this behavior. Troubling that it fails for you and works for me. See output at http://dust.ess.uci.edu/tmp/adrian.txt – Charlie Zender Sep 23 '20 at 23:27