R/AtomicToArray.R

#Wrapper function for atomic extreme functions
AtomicToArray <- function(fun_name, proj, ref, loop_dims = NULL, mean_dims = NULL, ...) {
  ext_fun <- fun_name
  mods <- dim(proj)[1]
  membs <- dim(proj)[2]
  lons <- dim(proj)[3]
  lats <- dim(proj)[4]
  index <- c()
  output <- list()
  for (mod in 1 : mods) {
    for (memb in 1 : membs) {
      for (lon in 1 : lons) {
        for (lat in 1 : lats) {
          index <- ext_fun(proj[mod, memb, lon, lat, ], ref[mod, memb, lon, lat, ], ...)
          for (i in 1 : length(index)) {
            output[[mod, memb, lon, lat]][i] <- index[i]
          }
        }
        }
      }
  }
  index <- unlist(index)
  invisible(result <- as.array(index, c(mods, membs, lons, lats)))
}
alasdairhunter/MagicWP7 documentation built on May 10, 2019, 8:50 a.m.