[Rd] NetCDF output in R

From: nana <amabro23_at_yahoo.com>
Date: Tue, 10 Nov 2009 08:31:59 -0800 (PST)


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 Received on Tue 10 Nov 2009 - 19:49:19 GMT

This archive was generated by hypermail 2.2.0 : Tue 10 Nov 2009 - 19:50:37 GMT