CST_Analogs.R 48.6 KB
Newer Older
Carmen Alvarez-Castro's avatar
Carmen Alvarez-Castro committed
  if (any(unlist(lapply(names_exp[-latlon_dim_exp],
                        function(x){x == names_obs[-latlon_dim_obs]})))) {
    original_pos <- lapply(names_exp, 
                           function(x) which(x == names_obs[-latlon_dim_obs]))
    original_pos <- lapply(original_pos, length) > 0
    names_exp[original_pos] <- paste0(names_exp[original_pos], "_exp")
  }
  return(names_exp)
}

replace_time_dimnames <- function(dataL, time_name = 'time', 
                                  stdate_name='stdate', ftime_name='ftime') {
  names_obs=names(dim(dataL))
  if (!is.character(names_obs)) {
    stop("Parameter 'names_obs' must be a vector of characters.")
  }
  time_dim_obs <- which(names_obs == time_name | 
                          names_obs == stdate_name | names_obs == ftime_name)
  if(length(time_dim_obs) >1){
    stop ("more than 1 time dimension, please give just 1")
  }
  if(length(time_dim_obs) == 0){
    warning ("name of time dimension is not 'ftime' or 'time' or 'stdate' 
             or time dimension is null")
  }
  if(length(time_dim_obs)!=0){ names_obs[time_dim_obs]= time_name}
  names(dim(dataL))=names_obs
  return(dataL)
}