Eno_new <- function(obs, posdim, na.action = na.pass, ncores = NULL) {

  #Check params:

  if (is.null(obs)) {
    stop("Parameter 'obs' cannot be NULL.")
  }
  if (!is.numeric(obs)) {
    stop("Parameter 'obs' must be a numeric array.")
  }

  if (is.null(posdim)) {
    stop("Parameter 'posdim' cannot be NULL.")
  }

  if (!is.numeric(posdim) && !is.character(posdim)) {
      stop("Parameter 'posdim' must be an positive integer or character.")
  }

  if (is.numeric(posdim)) {
    if (posdim <= 0 | posdim %% 1 != 0) {
      stop("Parameter 'posdim' must be a positive integer or character.")
    } else if (posdim > length(dim(obs))) {
      stop("Parameter 'posdim' excesses the dimension length of parameter 'obs'.")
    } else {  #posdim is okay for being integer. But change it to character.
      if (!is.null(names(dim(obs)))) {
        posdim <- names(dim(obs))[posdim]
      } else {
        names(dim(obs)) <- paste0("D", 1:length(dim(obs)))
        posdim <- names(dim(obs))[posdim]
      }
    }
  }

  if (is.character(posdim)) {
    if (is.null(names(dim(obs)))) {
      stop(paste0("Parameter 'obs' doesn't have dimension names. ",
                  "Add names or specify parameter 'posdim' by number."))
    } else if (!any(posdim %in% names(dim(obs)))) {
      stop(paste0("Parameter 'posdim' does not match any dimension name of ",
                  "parameter 'obs'."))
    }
  }

  if (as.character(substitute(na.action)) != c("na.pass") &&
      as.character(substitute(na.action)) != c("na.fail")) {
      stop("Parameter 'na.action' must be either 'na.pass' or 'na.fail'.")
  }

  if(as.character(substitute(na.action))== c("na.fail") && any(is.na(obs))) {
    stop(paste0("NA value in paratemter 'obs', which is not accepted when ",
                "parameter 'na.action' = 'na.fail'."))
  }

  if (!is.null(ncores)) {
    if (!is.numeric(ncores)) {
      stop("Parameter 'ncores' must be a positive integer.")
    } else if (ncores %% 1 != 0) {
      stop("Parameter 'ncores' must be a positive integer.")
    }
  }

  #Calculation:

  effnumobs <- Apply(data = list(obs),
                     target_dims = posdim,
                     fun = .Eno,
                     na.action = na.action,
                     ncores = ncores)$output1

  return(effnumobs)
}

.Eno <- function(x, na.action) {

  # Checks:
  if (!is.numeric(x)) {
      stop("Parameter 'x' must be a numeric vector.")
  }

  if (length(sort(x)) > 1) {
    n <- length(sort(x))
#    if (n == 0) {
#      n <- 1
#  }
    a <- acf(x, lag.max = n - 1, plot = FALSE,
             na.action = na.action)$acf[2:n, 1, 1]
    s <- 0
    for (k in 1:(n - 1)) {
      s <- s + (((n - k) / n) * a[k])
    }

    eno <- min(n / (1 + (2 * s)), n)

  } else {
    eno <- NA
  }
  eno
}

