# data format for input in CSIndicators SPEI functions
data_format_csindicators <- function(data, vars, var.list) {
  dict <- c('tas' = 'tmean', 
            'tasmax' = 'tmax', 
            'tasmin' = 'tmin', 
            'prlr' = 'pr', 
            'pet' = 'pet',
            'hurs' = 'hurs',
            'tdps' = 'tdps')
  dim.names <- names(dim(data$data))
  
  result <- list()
  for (var in vars) {
    if (var %in% var.list) {
      data.var <- CST_Subset(x = data,
                             var_dim = "var",
                             dat_dim = "dat",
                             along = "var",
                             indices = list(which(var.list == var)),
                             drop = FALSE)
    
      # read original units
      var.metadata.pos <- which(names(data$attrs$Variable$metadata) == var)
      units <- data$attrs$Variable$metadata[[var.metadata.pos]]$units

      ## TODO: Is this needed in any way?
      data.var$attrs$Units <- units
    } else {
      data.var <- NULL
    }
    # append all variables in a list of s2dv_cubes
    result <- append(result, list(data.var))
  }
  names(result) <- dict[vars]
  return(result)
}
