
load_multimodel_splitted <- function(recipe) {
  
  # Retrieve data dimension only without loading data
  dims <- dims_multimodel(recipe)
  data_order <- names(dims$dim.hcst)
  
  # Create empty array with desired dimensions
  data <- list(hcst = NULL, fcst = NULL, obs = NULL)
  data$hcst$data <- array(data = NA, dim = dims$dim.hcst)
  if (!is.null(recipe$Analysis$Time$fcst_year)) {
    data$fcst$data <- array(data = NA, dim = dims$dim.fcst)
  }

  files_hcst <- list()
  files_fcst <- list()
  files_obs <- list()
  
  # Loop over system to load hindcast and forecast data
  for (sys in 1:length(recipe$Analysis$Datasets$System$models)) {
    
    recipe_aux <- recipe
    system_load <- recipe$Analysis$Datasets$System$models[sys]
    recipe_aux$Analysis$Datasets$System$models <- system_load
    
    data_aux <- load_multimodel(recipe_aux)
    system_idx <- which(recipe$Analysis$Datasets$System$models == system_load)
    n_members <- 1:dim(data_aux$hcst$data)['ensemble']
    # Add system data to the hindcast array
    data$hcst$data[,,,,,system_idx,,,,n_members] <- s2dv::Reorder(data = data_aux$hcst$data,
                                                                  order = data_order)
    # Print object size for debugging purposes
    debug(recipe$Run$logger,
          paste("hcst size:", object.size(data$hcst, units = "GB"), "GB"))
    # Add system data to the forecast array
    if (!is.null(recipe$Analysis$Time$fcst_year)) {
      data$fcst$data[,,,,,system_idx,,,,n_members] <- s2dv::Reorder(data = data_aux$fcst$data,
                                                                    order = data_order)
    }
    # Append source files
    files_hcst <- append(files_hcst, data_aux$hcst$attrs$source_files) # , after = length(files_hcst))
    files_fcst <- append(files_fcst, data_aux$fcst$attrs$source_files) # , after = length(files_fcst))
    files_obs <- append(files_obs, data_aux$obs$attrs$source_files) # , after = length(files_obs))

  } # close loop on sys
  
  # Define obs data
  data$obs$data <- data_aux$obs$data
  
  # Include data attributes
  data$hcst$attrs <- data_aux$hcst$attrs
  data$fcst$attrs <- data_aux$fcst$attrs
  data$obs$attrs <- data_aux$obs$attrs
  data$hcst$coords <- data_aux$hcst$coords
  data$fcst$coords <- data_aux$fcst$coords
  data$obs$coords <- data_aux$obs$coords
  
  # Remove temporary data_aux
  rm(data_aux)
  
  return(list(data = data, 
              files_hcst = files_hcst, 
              files_fcst = files_fcst, 
              files_obs = files_obs))
}
