Search code examples
variablesnetcdfdimensioncdo-climatenco

NCO: Change time dimension back to unlimited


I've been trying to change the time dimension back to unlimited in a NetCDF file and haven't been successful. I made a new file and appended everything together:

dimensions:

    lon = UNLIMITED ; // (71 currently)
    lat = 36 ;
    expver = 2 ;
    time = 1000 ;

variables:

    double lon(lon) ;
            lon:standard_name = "longitude" ;
            lon:long_name = "longitude" ;
            lon:units = "degrees_east" ;
            lon:axis = "X" ;
    double lat(lat) ;
            lat:standard_name = "latitude" ;
            lat:long_name = "latitude" ;
            lat:units = "degrees_north" ;
            lat:axis = "Y" ;
    int expver(expver) ;
            expver:long_name = "expver" ;
            expver:axis = "Z" ;
    int time(time) ;
            time:standard_name = "time" ;
            time:long_name = "time" ;
            time:units = "hours since 1900-01-01 00:00:00.0" ;
            time:calendar = "gregorian" ;
            time:axis = "T" ;
    short t2m(lon, lat, expver, time) ;
            t2m:long_name = "2 metre temperature" ;
            t2m:units = "K" ;
            t2m:add_offset = 256.094308687104 ;
            t2m:scale_factor = 0.00181231329107926 ;
            t2m:_FillValue = -32767s ;
            t2m:missing_value = -32767s ;

After changing the order of the variables in t2m (from time,lon,lat,expver to lon,lat,expver,time) as needed in the program I'm running on Linux, it changes the lon dimension to unlimited and the time to fixed.

I've tried re-appending, lots of ncks commands, and really any combination that gives me time as unlimited. Once I have to put everything together, the time variable always goes to fixed.

I've taken the first four variables out, put them into a new file, taken t2m out, put them into a new file, and then tried to append it all together, which I get this error:

ERROR: nco_def_var() failed to nc_def_var() variable "t2m" nco_err_exit(): ERROR Short NCO-generated message (usually name of function that triggered error): nco_def_var() nco_err_exit(): ERROR Error code is -47. Translation into English with nc_strerror(-47) is "NetCDF: NC_UNLIMITED in the wrong index" nco_err_exit(): ERROR NCO will now exit with system call exit(EXIT_FAILURE)

Does anyone know how I can just change time back to unlimited and lon to fixed without changing the order of anything?


Solution

  • You're almost there. You may not realize that there can be only one dimension that is unlimited in netCDF classic files, and that dimension must be the first (leading) dimension in variables. That's probably why when you permuted the dimension order earlier, it re-assigned lon to be unlimited. In other words, there's no way to make time unlimited and have it be the last dimension in a netCDF3 file :) The only way to do that is to change the file to netCDF4, e.g.,

    ncks -4 --mk_rec_dmn time in.nc out.nc
    ncks --fix_rec_dmn lon out.nc out2.nc
    

    See --mk_rec_dmn and --fix_rec_dmn documentation.