0

I have the problem, that I cannot convert the numeric dates from NetCDF file:

2114380800 2114384400 2114388000 2114391600 2114395200 2114398800 2114402400 2114406000...

to the dates on R. I have tried the most common possibility that I've found:

library(ncdf4)
library(RNetCDF)
library(chron)
ncin <- nc_open("meteo.nc")
vars <-c(names(ncin$var))
t <- ncvar_get(ncin, "time")
tunits <- ncatt_get(ncin,"time","units")
tustr <- strsplit(tunits$value, " ")
tdstr <- strsplit(unlist(tustr)[3], "-")
tmonth <- as.integer(unlist(tdstr)[2])
tday <- as.integer(unlist(tdstr)[3])
tyear <- as.integer(unlist(tdstr)[1])
chron(t,origin=c(tmonth, tday, tyear))

This chron function really gives me the date,s but they are unrealistic (I know there should be january to august 2017):

01/04/28 11/12/37 09/21/47 07/30/57 06/08/67 04/16/77 02/23/87 01/01/97 ...

I guess the problem is the tunits refer to "seconds since 1950-01-01 00:00:00", not days. Please, help me to find solution for the seconds.

  • hi alina, do any of these answers help? https://stackoverflow.com/questions/46001573/convert-a-netcdf-time-variable-to-an-r-date-object – ClimateUnboxed Feb 12 '20 at 14:12
  • Does this answer your question? [convert a netcdf time variable to an R date object](https://stackoverflow.com/questions/46001573/convert-a-netcdf-time-variable-to-an-r-date-object) – ClimateUnboxed Feb 12 '20 at 14:12

0 Answers0