[R] Reading a large netCDF file using R

sulochandhungel sulochandhungel at gmail.com
Tue May 10 03:29:35 CEST 2011


I got a netCDF file from a climate group and wanted to aggregate the data.
The file summary looks like this

library(ncdf)
nc=open.ncdf("NCEP_prec_1949_58.nc")

> nc
[1] "file NCEP_prec_1949_58.nc has 4 dimensions:"
[1] "Time   Size: 14608"
[1] "lat   Size: 99"
[1] "lon   Size: 199"
[1] "DateStrLen   Size: 20"
[1] "------------------------"
[1] "file NCEP_prec_1949_58.nc has 1 variables:"
[1] "float Prec[lon,lat,Time]  Longname:yearly accumulated precip
Missval:1e+30"

I tried to get the variable values using this command

> xx=get.var.ncdf(nc)
Error: cannot allocate vector of size 2.1 Gb

This file has six hourly data for the 199 x 99 points for 10 years. I wanted
to aggregate this data into a monthly scale. I tried used a simple code like
this 

for (i in 1:noofdays) {
	for (j in 0:3) {
		x= get.var.ncdf(nc,v1,start=c(1,1,(i+j)),count=c(199,99,1))
		temp_data_mat=temp_data_mat+x
	}
	
	for (x1 in 1:199) {
		for (x2 in 1:99) {
			data_mat_89_99[x1,x2,ctr]=temp_data_mat[x1,x2]
		}
	}
	ctr=ctr+1
	temp_data_mat=matrix(0,ncol=99,nrow=199)
}

I didnt think it worked... can u suggest me some other way ... I could not
use the start and count properly


--
View this message in context: http://r.789695.n4.nabble.com/Reading-a-large-netCDF-file-using-R-tp3510762p3510762.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list