library(oce)
t.start <- as.POSIXct("2008-01-01", tz="UTC")
t <- seq(t.start, length.out=48, by="30 min")
y <- sin(as.numeric(t - t.start) * 2 * pi / (12 * 3600))
oce.plot.ts(t, y, type='l', xaxs='i')
weatherplot <- function(id=6358, time=as.POSIXlt(Sys.Date()))
{
## The default stationID is Halifax, NS, Canada
site <- "http://www.climate.weatheroffice.gc.ca/climateData/bulkdata_e.html"
time <- as.POSIXlt(time)
f <- paste(site,
"?StationID=", id,
"&Year=", time$year+1900,
"&Month=", time$mon+1,
"&Day=", time$mday,
"&format=csv&type=hly", sep="")
## Read lines first, to see where header ends. Cannot parse header, owing
## to multi-byte strings there.
ll <- readLines(f)
skip <- which(grepl("Date", ll, perl=TRUE))
d <- read.csv(f, skip=skip, header=FALSE)
t <- as.POSIXct(d[,1])
p <- d[,19]
oce.plot.ts(t, p, type='l', ylab="Pressure [dbar]", cex=2/3, main=paste("Station", id))
}
weatherplot()
Run the code above in your browser using DataLab