#' Compute the Multivariate Scores for Spatial Functional Data.
#'
#' @param EEM concatenated scores.
#' @param SM_vec list of variable eigenvectors.
#' @param SM_FSD list of univariate spatial functional principal component analysis.
#' @param X list of univariate spatial functional data.
#' @param J number of functional multivariate spatial principal components.
#' @return a list of the multivariate scores.
#' @keywords mfsd
#' @export

mfsd_Scores = function (EEM, SM_vec, SM_FSD, X, J)
{

  if (!inherits(SM_vec, "SM_vec")) {
    stop("'SM_vec' is not a SM_vec type.")
  }

  if (!inherits(SM_FSD, "SM_FSD")) {
    stop("'SM_FSD' is not a SM_FSD type.")
  }

  y <- length(SM_FSD)

  SML_Scores = vector("list", y)
  oldClass(SML_Scores) <- ("SML_Scores")

  y <- length(SML_Scores)
  var = 1
  for(i in 1:y){
    tryCatch({
      SML_Scores[[i]] <- EEM[,var:(J+var-1)]
      SML_Scores[[i]] <- SML_Scores[[i]] %*% SM_vec[[i]]

      SML_Scores[[i]] <- array(t(SML_Scores[[i]]), dim = c(dim(SML_Scores[[i]])[2],    dim(X[[1]][["coefs"]])[2], dim(X[[1]][["coefs"]])[3]))
      var = var + dim(SM_FSD[[i]][["scores"]])[1]
    }, error = function(e) {
      message("An error occurred in mfsd_Scores while processing the element ", i, ": ", conditionMessage(e), "\n")
    })}

  return(SML_Scores)

}
