PlotBox <- function(exp, obs, yr1, yr2, toptitle = '', ytitle = '', 
                    expname = "exp 1", obsname = "obs 1", 
                    fileout = "output_PlotBox.ps") {
  if (is.numeric(exp)) {
    if (is.null(dim(exp)) || length(dim(exp)) == 1) {
      dim(exp) <- c(1, length(exp))
    }
  }
  if (!is.numeric(exp) || length(dim(exp)) != 2) {
    stop("Parameter exp shoulw be a numeric vector or array of dimensions c(forecast horizons/start dates) or c(ensemble members, forecast horizons/start dates)")
  }
  if (is.numeric(obs)) {
    if (is.null(dim(obs)) || length(dim(obs)) == 1) {
      dim(obs) <- c(1, length(obs))
    }
  }
  if (!is.numeric(obs) || length(dim(obs)) != 2) {
    stop("Parameter obs should be a numeric vector or array of dimensions c(forecast horizons/start dates) or c(1, forecast horizons/start dates)")
  }
  nyr <- dim(obs)[2]
  postscript(fileout, horizontal = TRUE)
  ## Observed time series.
  pc.o <- ts(obs[1, ], deltat = 1, start = yr1, end = yr2)
  ## Normalization of obs, forecast members. Fabian
  ## Normalization of forecast should be according to ensemble
  ## mean, to keep info on ensemble spread, no? Lauriane pc.o <-
  ## pc.o/sd(pc.o) sd.fc <- apply(exp,c(1),sd)
  ## exp <- exp/sd.fc mn.fc <-
  ## apply(exp,2, mean) exp <-
  ## exp/sd(mn.fc) Produce plot.
  par(mar = c(5, 6, 4, 2))
  boxplot(exp, add = FALSE, main = paste(toptitle), 
    ylab = "", xlab = "", col = "red", lwd = 2, t = "b", 
    axes = FALSE, cex.main = 2, ylim = c(-max(abs(c(exp, pc.o))), max(abs(c(exp, pc.o)))))
  lines(1:nyr, pc.o, lwd = 3, col = "blue")
  abline(h = 0, lty = 1)
  legend("bottomleft", c(obsname, expname), lty = c(1, 1), lwd = c(3, 
    3), pch = c(NA, NA), col = c("blue", "red"), horiz = TRUE, 
    bty = "n", cex = 2.2)
  axis(1, c(1:nyr), NA, cex.axis = 2)
  axis(1, seq(1, nyr, by = 1), seq(start(pc.o)[1], end(pc.o)[1], 
    by = 1), cex.axis = 2)
  ##mtext(1, line = 3, text = tar, cex = 1.9)
  mtext(3, line = -2, text = paste(" AC =", round(cor(pc.o, 
    apply(exp, c(2), mean)), 2)), cex = 1.9, 
    adj = 0)
  axis(2, cex.axis = 2)
  mtext(2, line = 3, text = ytitle, cex = 1.9)
  box()
  dev.off()
}

