Dear CSAG R users, I will be glad if someone can point out what I am doing wrong or not doing at all in this. I am trying to write out netcdf file in R. I have 26 time step but only the first time step is written. For example:>library(ncdf) >path <- '/home/work/' >forecast <- open.ncdf(paste(path,'cam.1980.2005.nc',sep="")) > fore <- get.var.ncdf(forecast,'ppt') > lon <- get.var.ncdf(forecast,'lon') > lat <- get.var.ncdf(forecast,'lat') >dim(fore)[3] >26 > times <- 1:dim(fore)[3] > write.netcdf.time(paste(path,'cam_fore.nc',sep=""), fore,lon,lat,times)[1] "put.var.ncdf: warning: you asked to write 1440 values, but the passed data array has 37440 entries!" [[1]] [1] 6 Warning message: In 1:nt : numerical expression has 26 elements: only the first used ################# function for writing out the netcdf file ############# write.netcdf.time <- function(filename='outputfile.nc',data,lons,lats,nt){ lon <- dim.def.ncdf('lon','degrees_east',lons) lat <- dim.def.ncdf('lat','degrees_north',lats) times <- 1:nt tdim <- dim.def.ncdf('time','days since 1980-01-01', times, unlim=TRUE) # levs <- dim.def.ncdf('lev','pressure',levs) var <- var.def.ncdf('data','unitless',list(lon,lat,tdim),-999.9) ncid <- create.ncdf(filename,list(var)) put.var.ncdf(ncid, var, data) close.ncdf(ncid) } ##########################end of function####################### Thank you. Nana Browne =================================================================== There is no key to happiness. The door is always open. [[alternative HTML version deleted]]
Dear R users, I will be glad if someone can point out what I am doing wrong or not doing at all in this. I am trying to write out netcdf file in R. I have 26 time step but only the first time step is written. For example:>library(ncdf) >path <- '/home/work/' >forecast <- open.ncdf(paste(path,'cam.1980.2005.nc',sep="")) > fore <- get.var.ncdf(forecast,'ppt') > lon <- get.var.ncdf(forecast,'lon') > lat <- get.var.ncdf(forecast,'lat') >dim(fore)[3] >26 > times <- 1:dim(fore)[3] > write.netcdf.time(paste(path,'cam_fore.nc',sep=""), fore,lon,lat,times)[1] "put.var.ncdf: warning: you asked to write 1440 values, but the passed data array has 37440 entries!" [[1]] [1] 6 Warning message: In 1:nt : numerical expression has 26 elements: only the first used ################# function for writing out the netcdf file ############# write.netcdf.time <- function(filename='outputfile.nc',data,lons,lats,nt){ lon <- dim.def.ncdf('lon','degrees_east',lons) lat <- dim.def.ncdf('lat','degrees_north',lats) times <- 1:nt tdim <- dim.def.ncdf('time','days since 1980-01-01', times, unlim=TRUE) # levs <- dim.def.ncdf('lev','pressure',levs) var <- var.def.ncdf('data','unitless',list(lon,lat,tdim),-999.9) ncid <- create.ncdf(filename,list(var)) put.var.ncdf(ncid, var, data) close.ncdf(ncid) } ##########################end of function####################### Thank you. Nana Browne =================================================================== There is no key to happiness. The door is always open. [[alternative HTML version deleted]]
Hi Nana, This is not a r-devel question. I suspect this should be something like: write.netcdf.time(paste(path,'cam_fore.nc',sep=""), fore[,,times] ,lon,lat,times) Robert On Tue, Nov 10, 2009 at 8:31 AM, nana <amabro23 at yahoo.com> wrote:> Dear CSAG R users, > > I will be glad if someone can point out what I am doing wrong or not doing at all in this. > > I am trying to write out netcdf file in R. I have 26 time step but only the first time step is written. > > For example: >>library(ncdf) >>path <- '/home/work/' >>forecast <- open.ncdf(paste(path,'cam.1980.2005.nc',sep="")) >> fore <- get.var.ncdf(forecast,'ppt') >> lon <- get.var.ncdf(forecast,'lon') >> lat <- get.var.ncdf(forecast,'lat') >>dim(fore)[3] >>26 >> times <- 1:dim(fore)[3] >> write.netcdf.time(paste(path,'cam_fore.nc',sep=""), fore,lon,lat,times) > [1] "put.var.ncdf: warning: you asked to write 1440 values, but the passed data array has 37440 entries!" > [[1]] > [1] 6 > > Warning message: > In 1:nt : numerical expression has 26 elements: only the first used > > > ################# function for writing out the netcdf file ############# > write.netcdf.time <- function(filename='outputfile.nc',data,lons,lats,nt){ > lon <- dim.def.ncdf('lon','degrees_east',lons) > lat <- dim.def.ncdf('lat','degrees_north',lats) > times <- 1:nt > tdim <- dim.def.ncdf('time','days since 1980-01-01', times, unlim=TRUE) > # levs <- dim.def.ncdf('lev','pressure',levs) > var <- var.def.ncdf('data','unitless',list(lon,lat,tdim),-999.9) > ncid <- create.ncdf(filename,list(var)) > put.var.ncdf(ncid, var, data) > close.ncdf(ncid) > } > > ##########################end of function####################### > > Thank you. > Nana Browne > > ===================================================================> > There is no key to happiness. The door is always open. > > > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Dear Users, I have corrected the errors. Many thanks. For this error,> [1] "put.var.ncdf: warning: you asked to write 1440 values, but the passed data array has 37440 entries!"I added start= c(1,1,1), count=c(length(lons),length(lats),length(nt)) in the put.var.ncdf function. so put.var.ncdf(ncid, var, data) became put.var.ncdf(ncid, var, data, start= c(1,1,1), count=c(length(lons),length(lats),length(nt))) For this,> Warning message: > In 1:nt : numerical expression has 26 elements: only the first usedI replaced "times" with "nt" in the tdim in the dim.def.ncdf function. so tdim <- dim.def.ncdf('time','days since 1980-01-01', times, unlim=TRUE) became tdim <- dim.def.ncdf('time','days since 1980-01-01', nt, unlim=TRUE) Thanks all. Nana Browne =================================================================== There is no key to happiness. The door is always open. [[alternative HTML version deleted]]