changing time axis values of netcdf4 file using R

31 Views Asked by At

I'm tried to change time axis of given netcdf4 file with given .csv table, like pasting all contents of table into the netcdf4 file. however, every method I took using R with ncdf4 or python cdo failed so far. and ncvar_put command dosen't seems to be working.

as of R, I have tried such a thing.

>library(ncdf4)

>nc_data<-nc_open('/home/vboxuser/netcdf4.nc')

#original time axis
> time<-ncvar_get(nc_data, "time")
> print(time)
 [1] 1449619200 1449622800 1449626400 1449630000 1449633600 1449637200
 [7] 1449640800 1449644400 1449648000 1449651600 1449655200 1449658800
[13] 1449662400 1449666000 1449669600 1449673200 1449676800 1449680400
[19] 1449684000 1449687600 1449691200 1449694800 1449698400 1449702000
[25] 1449705600 1449709200 1449712800 1449716400 1449720000 1449723600
[31] 1449727200 1449730800 1449734400 1449738000 1449741600 1449745200
[37] 1449748800 1449752400 1449756000 1449759600 1449763200 1449766800
[43] 1449770400 1449774000 1449777600 1449781200 1449784800 1449788400
[49] 1449792000

#new time axis which is to be implemented
> time_n<-read.csv('/home/vboxuser/time.csv')
> print(time_n)
             
1  2014-10-01 00:00:00
...
49 2014-10-03 00:00:00

#pasting time axis to the said netcdf file.
> ncatt_put(nc_data,var, "time", time_n)
Error in ncatt_put(nc_data, var, "time", time_n) : 
  ncatt_put: the netcdf file has not been written to disk yet, or was not opened in write mode!

> ncvar_put(nc_data,"time", "time_n", verbose=TRUE)
[1] "ncvar_put: entering"
Error in ncvar_put(nc_data, "time", "time_n", verbose = TRUE) : 
  Error: called with a nc object that is NOT a writable netcdf file! Passed nc file name:  /home/vboxuser/netcdf4.nc
0

There are 0 best solutions below