0

I am a beginner with nco and I would appreciate some advice on my workflow and some help with a problem I an struggling with.

I have these data which contain 3D salinity values at two different time steps:

dimensions:
    t = 780 ;
    z = 54 ;
    y = 450 ;
    x = 3600 ;
variables:
    double time(t) ;
        time:units = "days since 1-1-1 00:00:0.0" ;
    float level(z) ;
        level:units = "[m]" ;
    float lat(y) ;
    float lon(x) ;
    float salt(x, y, z) ;
        salt:units = "psu * 1000 + 35" ;
        salt:missingvalue = "-1.0E34" ;
        salt:longname = "salinity" ;

I want to concatenate the two netcdf files.

To do so I first use ncecat *.nc -O merged.nc:

dimensions:
    record = UNLIMITED ; // (2 currently)
    t = 780 ;
    z = 54 ;
    y = 450 ;
    x = 3600 ;
variables:
    double time(record, t) ;
        time:units = "days since 1-1-1 00:00:0.0" ;
    float level(record, z) ;
        level:units = "[m]" ;
    float lat(record, y) ;
    float lon(record, x) ;
    float salt(record, x, y, z) ;
        salt:units = "psu * 1000 + 35" ;
        salt:missingvalue = "-1.0E34" ;
        salt:longname = "salinity" ;

where now the variable time and dimension t are spurious. So, I delete them with ncks -O -x -v time merged.nc merged.nc:

    record = UNLIMITED ; // (2 currently)
    y = 450 ;
    z = 54 ;
    x = 3600 ;
variables:
    float lat(record, y) ;
    float level(record, z) ;
        level:units = "[m]" ;
    float lon(record, x) ;
    float salt(record, x, y, z) ;
        salt:units = "psu * 1000 + 35" ;
        salt:missingvalue = "-1.0E34" ;
        salt:longname = "salinity" ;

Now, I want to rename the dimension record with: ncrename -d record,time merged.nc. The command runs with no errors or warnings. But when I do ncdump -h merged.nc I get this error:

ncdump: merged.nc: NetCDF: HDF error

What does this mean? Where do I do wrong?

EDIT

Following the answer posted by Charlie Zender

ncecat -O -u time *.nc merged.nc
ncks -O -x -v time merged.nc merged.nc

result in:

dimensions:
    time = UNLIMITED ; // (2 currently)
    y = 450 ;
    z = 54 ;
    x = 3600 ;
    t = 780 ;
variables:
    float lat(time, y) ;
    float level(time, z) ;
        level:units = "[m]" ;
    float lon(time, x) ;
    float salt(time, x, y, z) ;
        salt:units = "psu * 1000 + 35" ;
        salt:missingvalue = "-1.0E34" ;
        salt:longname = "salinity" ;
    double time(time, t) ;
        time:units = "days since 1-1-1 00:00:0.0" ;

// global attributes:
        :history = "Tue Jun  5 09:08:25 2018: ncks -O -x -v time merged.nc merged.nc\nTue Jun  5 09:08:19 2018: ncecat -O -u time OFES_salt_mmean_607.nc OFES_salt_mmean_608.nc merged.nc" ;
        :NCO = "netCDF Operators version 4.7.4 (http://nco.sf.net)" ;
        :nco_openmp_thread_number = 1 ;
shamalaia
  • 2,282
  • 3
  • 23
  • 35

1 Answers1

4

Firstly, the command I recommend is

ncecat -O -u time *.nc merged.nc

That prevents the need to rename record to time. Then

ncks -O -x -v time merged.nc merged.nc

Does that work?

Answer to EDITed question:

Regarding the error received with ncrename, you may have encountered a netCDF4 library bug described here. The recommended solution is to convert to netCDF3, rename, then convert back to netCDF4 if desired:

ncks -3 in.nc out.nc
ncrename -d record,time out.nc
ncks -4 out.nc out.nc
Charlie Zender
  • 5,929
  • 14
  • 19