get_times <- function(store.freq, fcst.horizon, leadtimes, sdate, calendar) {
  # Generates time dimensions and the corresponding metadata.
  ## TODO: Subseasonal

  switch(fcst.horizon,
         "seasonal" = {time <- leadtimes; ref <- 'hours since ';
                       stdname <- paste(strtoi(leadtimes), collapse=", ")},
         "subseasonal" = {len <- 4; ref <- 'hours since ';
                          stdname <- ''},
         "decadal" = {time <- leadtimes; ref <- 'hours since ';
                      stdname <- paste(strtoi(leadtimes), collapse=", ")})

  dim(time) <- length(time)
  sdate <- as.Date(sdate, format = '%Y%m%d') # reformatting
  metadata <- list(time = list(units = paste0(ref, sdate, 'T00:00:00'),
                   calendar = calendar))
  attr(time, 'variables') <- metadata
  names(dim(time)) <- 'time'

  sdate <- 1:length(sdate)
  dim(sdate) <- length(sdate)
  metadata <- list(sdate = list(standard_name = paste(strtoi(sdate),
                                                      collapse=", "),
                                units = paste0('Init date')))
  attr(sdate, 'variables') <- metadata
  names(dim(sdate)) <- 'sdate'

  return(list(time=time))
}

