0

Let's consider those two files:

from netCDF4 import Dataset as dset

for i in range(2):
     with dset('test_{}.nc'.format(i),'w') as f:
         f.createDimension('A',5)
         f.createDimension('B',8)
         f.createVariable('v1',float,('A',))
         f.createVariable('v2',float,('B',))
         f['v1'][:] = range(i*5,i*5+5)
         f['v2'][:] = range(i*8,i*8+8)

If the two dimensions are unlimited ncrcat works directly and concatenate v2 along B and v1 along A.

ncrcat test_0.nc test_1.nc test_01.nc

However if the dimensions are fixed size like in the example above I have to successively set A and B as record dimension to make them unlimited and then concatenate

ncks --mk_rec_dmn A test_0.nc test_0u.nc ; mv test_0u.nc test_0.nc
ncks --mk_rec_dmn B test_0.nc test_0u.nc ; mv test_0u.nc test_0.nc
ncks --mk_rec_dmn A test_1.nc test_1u.nc ; mv test_1u.nc test_1.nc
ncks --mk_rec_dmn B test_1.nc test_1u.nc ; mv test_1u.nc test_1.nc
ncrcat test_0.nc test_1.nc test_01.nc

Is there another way to do this with less lines?

1 Answer 1

1

Unfortunate --mk_rec_dmn only changes one dimension per invocation. Changing multiple fixed dimensions into record dimensions is on our TODO list (#1129). However, you can eliminate the mv statements by using the overwrite functionality with -O:

ncks -O --mk_rec_dmn A test_0.nc test_0.nc
ncks -O --mk_rec_dmn B test_0.nc test_0.nc
ncks -O --mk_rec_dmn A test_1.nc test_1.nc
ncks -O --mk_rec_dmn B test_1.nc test_1.nc
ncrcat test_0.nc test_1.nc test_01.nc

HTH, cz

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.