NetCDF output in R
On Tue, 10 Nov 2009, nana wrote:
I will be glad if someone can point out what I am doing wrong or not doing at all in this.
Sending the same message to both r-help and r-devel is one thing you are doing wrong.
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
This looks like the cause of your problem. The function has times <- 1:nt implying that nt is a single number, but you are passing the vector 'times' as the argument.
################# 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-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle