Search code examples
netcdfncocdo-climate

Modifying variable attribute of netcdf file


I'm trying to modify the calendar type of a time variable in a netcdf file to change from GREGORIAN to gregorian as I think it is causing problems when I try to access the time variables within a later analysis.

        double Time(Time) ;
                Time:long_name = "Time" ;
                Time:units = "days since 1979-01-01 00:00:00" ;
                Time:cartesian_axis = "T" ;
                Time:calendar_type = "GREGORIAN" ;
                Time:calendar = "GREGORIAN" ;
                Time:bounds = "Time_bounds" ;
                Time:_ChunkSizes = 1 ;

to

        double Time(Time) ;
                Time:long_name = "Time" ;
                Time:units = "days since 1979-01-01 00:00:00" ;
                Time:cartesian_axis = "T" ;
                Time:calendar_type = "gregorian" ;
                Time:calendar = "gregorian" ;
                Time:bounds = "Time_bounds" ;
                Time:_ChunkSizes = 1 ;

I have tried to use the nco function nccat but I can't seem to get the syntax correct. I tried:

ncatted -a 'calendar,time,o,c,"gregorian"' Ocean_v_1994_01.nc out.nc

Solution

  • The single quotes you placed around the ncatted argument causes the double quotes to become literals which is not what you want. There are no literals, spaces, or special characters in your argument, so just drop all quotes:

    ncatted -a calendar,time,o,c,gregorian Ocean_v_1994_01.nc out.nc