#reviewed March 11, 2010 #new data set ftp://srvx6.img.univie.ac.at/pub/rich_gridded_2009.nc get.rich.trp=function(method="trp") { source("http://www.climateaudit.info/scripts/utilities/getx_var_ncdf.txt") loc="ftp://srvx6.img.univie.ac.at/pub/rich_gridded_2009.nc" #formerly 2008 ### loc="ftp://srvx6.img.univie.ac.at/pub/rich_gridded_clim_1979-1998.nc" : climatology download.file(loc,"temp.nc",mode="wb") v<-open.ncdf("temp.nc") length(v$dim) names(v$dim) # #[1] "lon" "lat" "pressure" "time" sapply(v$dim,function(A) A$len) # lon lat pressure time # 36 18 12 612 v$dim$lon$vals # 10 degree Dateline to Dateline v$dim$lat$vals # 10 degree N to S v$dim$pressure$vals # 850 700 500 400 300 250 200 150 100 70 50 30 K=length(v$dim$pressure$vals) #12 v$dim$time$vals # "days since 1958-01-01 00:00:00" #monthly tsp(ts( v$dim$time$vals,start=1958,freq=12) ) # 1958.000 2008.917 12.000 names(v$var) #anomalies sapply(v$var$anomalies,length) sapply(v$var$anomalies$dim,function(A) A$len) # 36 18 12 612 instr <- getx.var.ncdf( v, v$var[[1]]) # 1850 2006 dim(instr) #36 18 12 588 temp= abs(v$dim$lat$vals)<20;sum(temp) #4 instr=instr[,temp,,];dim(instr) # 36 4 12 612 instr=aperm(instr,c(4,1,2,3)); dim(instr) # 588 36 4 12 dim0=dim(instr) instr=array(instr,dim=c(dim0[1],144,12) );dim(instr) rich= ts( array (NA,dim=c(dim0[1],12) ),start= 1958,freq=12);tsp(rich) # 1958.000 2006.917 for(i in 1:12) rich[,i]= apply(instr[,,i],1,mean,na.rm=T) dimnames(rich)[[2]]= v$dim$pressure$vals # 850 700 500 400 300 250 200 150 100 70 50 30 dim(rich) if(method=="T2LT") {rich_t2lt.trp= apply(rich[,c("850","700")],1, function(x) weighted.mean(x,c(.33,.67)) ) rich_t2lt.trp=ts (rich_t2lt.trp,start=1958,freq=12) rich=rich_t2lt.trp} return(rich) }