SeasonSelect <- function(data, seasons) {
  time_dim <- which(names(dim(data)) == "time")
  metadata <- attributes(data)
  num_models <- dim(data)[which(names(dim(data)) == "model")]
  ##Subset the data based on the users selected season:
  dates <- attributes(data)$Variables$dat1$time
  dates <- as.PCICt(dates, cal = attributes(dates)$variables$time$calendar, format = "%Y%m%d")
  jdays <- as.numeric(strftime(dates, format = "%j"))
  if (seasons == "DJF") {
    days <- c(c(335 : 365), c(1 : 59))
  } else if (seasons == "MAM") {
    days <- c(60 : 151)
  } else if (seasons == "JJA") {
    days <- c(152 : 243)
  } else {
    days <- c(244 : 334)
  }
  index <- which(jdays %in% days)
  data <- Subset(data, along = time_dim, indices = index, drop = "non-selected")
  for(i in 1:num_models){
  metadata$Variables[[i+1]]$time <- Subset(metadata$Variables[[i+1]]$time, along = 1, indices = index)
  }
  metadata$Variables$common$tasmax$dim[[time_dim]]$len <- length(metadata$Variables$dat1$time)
  metadata$Variables$common$tasmax$dim[[time_dim]]$vals <- Subset(  metadata$Variables$common$tasmax$dim[[time_dim]]$vals, along = 1, indices = index)

 # dims <- dim(data)
#  which_time_dim <- which(names(dims) == 'time')
 # if (length(which_time_dim) > 0) {
  #  new_dims <- c()
  #  if (which_time_dim > 1) {
  #    new_dims <- c(new_dims, dims[1:(which_time_dim - 1)])
  #  }
  #  new_dims <- c(new_dims, day = length(days), year = unname(dims['time']) / length(days))
  #  if (which_time_dim < length(dims)) {
  #    new_dims <- c(new_dims, dims[(which_time_dim + 1):length(dims)])
  #  }
  #}
  #  dim(data) <- new_dims
  attr(data, 'Variables') <- metadata$Variables
  return(data)
}