##SCRAPE CRN DATA #station list (outdatred but readable( http://mi3.ncdc.noaa.gov/mi3report/MISC/CRN-STATIONS.TXT #also "http://www.ncdc.noaa.gov/app/isis/stationlist?networkid=1" read.uscrn=function(id) { month0=c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") #obtain period of record loc=paste("http://www.ncdc.noaa.gov/crn/hourly?station_id=",id,sep="") fred=readLines(loc) N=grep("Period of record is",fred) test=fred[N+1];N=nchar(test) year1=as.numeric(substr(test,N-3,N)); month1=(1:12)[!is.na(match(month0,substr(test,N-10,N-8)))]+1 g=function(x,y){g=100*x+y;g} time0=sort(outer(year1:2007,1:12,g)) temp=(time0g(2007,7)) time0=time0[!temp];M=length(time0) #scrape monthly data station=ts(array(NA,dim=c(M,4)),start=c(year1,month1),freq=12) dimnames(station)[[2]]=c("avg","max","min","m2") for (i in 1:M){ loc=paste("http://www.ncdc.noaa.gov/crn/newmonthsummary?station_id=",id,"&yyyymm=",time0[i],sep="") download.file(loc,"temp.dat") fred=readLines("temp.dat") N=grep("Mean",fred)# 810 test=substr(fred[c(N+2,N+4,N+7,N+10)],23,27) test=gsub("/","",test);test=gsub("<","",test) station[i,]=as.numeric(test) Sys.sleep(1) } read.uscrn=station read.uscrn } #source("http://www.climateaudit.org/scripts/station/read.uscrn.txt" #test=read.uscrn(id=1039) #Goodridge MN #goodridge=test #plot.ts(goodridge[,4]) #test=read.ghcnd(usid=213236,url="uspaste")