3

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
ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
Hayden
  • 107
  • 8
  • 1
    While you are at it, I suggest adding a `standard_name` attribute to the `Time` variable, with attribute value `time`. – alani May 26 '20 at 08:40

3 Answers3

3

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

Charlie Zender
  • 5,929
  • 14
  • 19
2

I found a way to do this using R and the ncdf4 package. The solution was:

library(ncdf4)
mydata <- nc_open("Ocean_v_1994_01.nc", write = TRUE)

ncatt_put(mydata, "Time", 'calendar', attval = 'gregorian', prec = 'text')
ncatt_put(mydata, "Time", 'calendar_type', attval = 'gregorian', prec = 'text')

# check result 
ncatt_get(mydata, "Time")

nc_sync(mydata)
nc_close(mydata)
Hayden
  • 107
  • 8
1

I think you could also sort this by using the cdo setcalendar command:

 cdo setcalendar,proleptic_gregorian in.nc out.nc
ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86