Trend <- function(ens, interval = 1, siglev = 0.95, conf = TRUE) {
  
  ensmean <- rowMeans(ens, na.rm = TRUE)
  
  if (any(!is.na(ensmean))) {
     mon <- seq(ensmean) * interval
     lm.out <- lm(ensmean ~ mon, na.action = na.omit)
     trend <- c(lm.out$coefficients[2], lm.out$coefficients[1])
     if (conf) {
        conf.int <- confint(lm.out, level = siglev)[2, 1:2]
        }
        detrend <- ensmean[is.na(ensmean) == FALSE] - lm.out$fitted.values
        }
                 
  
 
  # 
  #  Outputs
  # ~~~~~~~~~
  # 
  invisible(list(trend = trend, conf.int = conf.int, detrended = detrend))
}
