#####Sample R script to open "hcrut3V-JAS.nc", from NOAA/NCDC Paleoclimatology World Data Center. Author: Eugene R. Wahl, 9-7-2010. #####This script can also be used with minimal modification to open any file of the form "hcrut3X-YYY.nc". #####NOTE: The time values in files of the form "hcrut3X-YYY.nc" are ordered from the earliest year to the latest year. #####This script was developed for R 2.8.1. It likely is back-compatible with earlier versions of R, but this has not been systematically checked. ##source("PUT APPROPRIATE FILEPATH AND FILENAME HERE") #USE THIS LINE TO SOURCE THIS FILE DIRECTLY IN R, ONCE FILEPATH AND FILENAME ARE SPECIFIED FOR LOCAL CIRCUMSTANCE. # rm(list=ls()) # Commented out, Remove pound sign to activate. ACTIVATION REMOVES ALL OBJECTS IN R WORKSPACE -- BE CAREFUL TO INSURE YOU WANT TO DO THIS. library (ncdf) ##Set-up Information filepath<-("//Dinobast/paleo_fileshare/2000-reconstruction/HadCRUT3v/") #REPLACE WITH APPROPRIATE FILEPATH FOR LOCAL CIRCUMSTANCE. filename<-("hcrut3V-JAS.nc") ##Open netCDF File nc<-open.ncdf(paste(filepath,filename,sep="")) print (nc) time<-get.var.ncdf(nc,"time") dim(time) time zlev<-get.var.ncdf(nc,"zlev") #elevation in relation to sea level dim(zlev) zlev lat<-get.var.ncdf(nc,"lat") dim(lat) lat lon<-get.var.ncdf(nc,"lon") dim(lon) lon temp<-get.var.ncdf(nc,"surf_temp_anom") dimnames(temp)<-list(lon,lat,time) dim(temp) nc_array_timelatlon<-array(dim=c(dim(time),dim(lat),dim(lon))) for (i in 1:dim(lon)) { for (j in 1:dim(lat)) { nc_array_timelatlon[,j,i]<-temp[i,j,] }} dimnames(nc_array_timelatlon)<-list(time,lat,lon) dim(nc_array_timelatlon) nc_array_latlontime<-array(dim=c(dim(lat),dim(lon),dim(time))) for (i in 1:dim(lon)) { for (j in 1:dim(lat)) { nc_array_latlontime[j,i,]<-temp[i,j,] }} dimnames(nc_array_latlontime)<-list(lat,lon,time) dim(nc_array_latlontime) ##View R array for ~ continental United States for specific sample of years nc_array_latlontime[lat<=47.5 & lat>=27.5,lon>=-122.5 & lon<=-62.5,time<=2009 & time>=2000] ##View R array for ~ Europe for specific sample of years nc_array_latlontime[lat<=67.5 & lat>=37.5,lon>=-7.5 & lon<=42.5,time<=2009 & time>=2000] #####END