% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ByChunks.R
\name{ByChunks}
\alias{ByChunks}
\title{Execute the operation by chunks}
\usage{
ByChunks(step_fun, cube_headers, ..., chunks = "auto", threads_load = 2,
  threads_compute = 1, cluster = NULL, ecflow_suite_dir = NULL,
  ecflow_server = NULL, silent = FALSE, debug = FALSE, wait = TRUE)
}
\arguments{
\item{step_fun}{A function with the class 'startR_step_fun' containing the 
details of operation.}

\item{cube_headers}{A list with the class 'startR_cube' returned by Start().
It contains the details of data to be operated.}

\item{chunks}{A named list of dimensions which to split the data along and 
the number of chunks to make for each. The chunked dimension can only be 
those not required as the target dimension in function Step(). The default
value is 'auto', which lists all the non-target dimensions and each one has
one chunk.}

\item{threads_load}{An integer indicating the number of execution threads to 
use for the data retrieval stage. The default value is 1.}

\item{threads_compute}{An integer indicating the number of execution threads
to use for the computation. The default value is 1.}

\item{cluster}{A list of components that define the configuration of the 
machine to be run on. The comoponents vary from the different machines.
Check https://earth.bsc.es/gitlab/es/startR/ for more details and examples.
Only needed when the computation is not run locally. The default value is 
NULL.}

\item{ecflow_suite_dir}{A character string indicating the path to a folder in
the local workstation where to store temporary files generated for the 
automatic management of the workflow. Only needed when the execution is run
remotely. The default value is NULL.}

\item{ecflow_server}{A named vector indicating the host and port of the 
EC-Flow server. The vector form should be 
\code{c(host = 'hostname', port = port_number)}. Only needed when the 
execution is run remotely. The default value is NULL.}

\item{silent}{A logical value deciding whether to print the computation 
progress (FALSE) on the R session or not (TRUE). It only works when the 
execution runs locally or the parameter 'wait' is TRUE. The default value
is FALSE.}

\item{debug}{A logical value deciding whether to return detailed messages on 
the progress and operations in a Compute() call (TRUE) or not (FALSE). 
Automatically changed to FALSE if parameter 'silent' is TRUE. The default 
value is FALSE.}

\item{wait}{A logical value deciding whether the R session waits for the 
Compute() call to finish (TRUE) or not (FALSE). If FALSE, it will return an
object with all the information of the startR execution that can be stored
in your disk. After that, the R session can be closed and the results can
be collected later with the Collect() function. The default value is TRUE.}

\item{{\dots}}{Additional parameters for the inputs of 'step_fun'.}
}
\value{
A list of data arrays for the output returned by the last step in the
 specified workflow. The configuration details and profiling information are
 attached as attributes to the returned list of arrays.
}
\description{
This is a function used in Compute(), executing the operation by the chunks 
specified in Compute(). It also returns the configuration details and 
profiling information.
}
\examples{
# ByChunks() is internally used in Compute(), not intended to be used by 
  users. The example just illustrates the inputs of ByChunks().
 data_path <- system.file('sample_data', package = 'startR')
 path_obs <- file.path(data_path, 'obs/monthly_mean/$var$/$var$_$sdate$.nc')
 sdates <- c('200011', '200012')
 data <- Start(dat = path_obs,
               var = 'tos',
               sdate = sdates,
               time = 'all',
               latitude = 'all',
               longitude = 'all',
               return_vars = list(latitude = 'dat', 
                                  longitude = 'dat', 
                                  time = 'sdate'),
               retrieve = FALSE)
 fun <- function(x) {
           lat = attributes(x)$Variables$dat1$latitude
           weight = sqrt(cos(lat * pi / 180))
           corrected = Apply(list(x), target_dims = "latitude",
                             fun = function(x) {x * weight})
         }
 step <- Step(fun = fun,
              target_dims = 'latitude',
              output_dims = 'latitude',
              use_libraries = c('multiApply'),
              use_attributes = list(data = "Variables"))
 ByChunks(step, data)

}

