Authors@R: person('David', 'Dorchies', email = 'david.dorchies@inrae.fr', role = c('cre', 'aut'))
Description: IRMaRA is a R Shiny interface providing probability of failure of flood and drought objective at key locations downstream of the 4 lakes regulating the Seine River.
#' Run simulations of VGEST for all objectives and store results
#'
#' @param reservoirRuleSet rank of the set of parameters describing the reservoirs and their management rules (constraints and local instructions)
#' @param networkSet rank of the set of parameters describing the network
#' @param Qfile name of the flow data file (hydrological regime without reservoirs)
#' @param startDate start of calculation period in "dd/mm/yyyy" format
#' @param endDate end of calculation period in "dd/mm/yyyy" format
#' @param distributionType see Details section of [vgest_write_batch()]
#' @param distributionOption see Details section of [vgest_write_batch()]
#' @param vgest_location location of the vgest software (default "../vgest")
#' @param objective_file name of the file used for storing the threshold hydrograph
#' @param result.dir path for storing the result of vgest run. The result is stored in a subfolder named high or low (depending on \code{bFlood}) followed by the threshold
#' @param ... Extra parameters used by \code{\link{get_objectives}}
#'
#' @return
#' @export
#'
#' @examples
#' \donttest{
#' # Run all objectives for reservoir configuration #1,
#' # network configuration #1 and a task repartition
#' # function of present volumes and maximum usable volume
#' # replenishment times from the start of time steps
#' Prepare, run and store results of a VGEST instance
#'
#' @param Qfile
#' @param startDate
#' @param endDate
#' @param station
#' @param bFlood
#' @param threshold
#' @param vgest_location
#' @param objective_file
#' @param result.dir
#' @param reservoirRuleSet rank of the set of parameters describing the reservoirs and their management rules (constraints and local instructions)
#' @param networkSet rank of the set of parameters describing the network
#' @param station name of the station where the flow target is located
#' @param Qfile name of the flow data file (hydrological regime without reservoirs)
#' @param bFlood boolean describing the objective type: \code{FALSE} for low flow support, \code{TRUE} for high flow lamination
#' @param startDate start of calculation period in "dd/mm/yyyy" format
#' @param endDate end of calculation period in "dd/mm/yyyy" format
#' @param threshold value of the threshold in m3/s
#' @param distributionType see in details the description of line 10 of CHOIX.TXT
#' @param distributionOption for \code{distributionType=1}, this should contains the relative change in comparison with a repartition based on storage capacity of fixed repartition between reservoirs. If \code{distributionType=4} or \code{5}, see in details the description of line 11 of CHOIX.TXT (default \code{NULL})
#' @param vgest_location location of the vgest software (default "../vgest")
#' @param objective_file name of the file used for storing the threshold hydrograph
#' @param result.dir path for storing the result of vgest run. The result is stored in a subfolder named high or low (depending on \code{bFlood}) followed by the threshold
#' Write CHOIX.TXT and objective file in VGEST folder
#' Write configuration files for running VGEST
#'
#' Write CHOIX.TXT, objective file and eventually REGLAGES.TXT in PARAMETR folder of VGEST.
#'
#' @param station
#' @param Qfile
#' @param bFlood
#' @param startDate
#' @param endDate
#' @param threshold
#' @param vgest_location
#' @param objective_file
#' @details
#' The format of the PARAMETR/CHOIX.TXT file is as follow:
#'
#' - line 1: name of the station where the flow target is located
#' - line 2: rank of the set of parameters describing the reservoirs and their management rules (constraints and local instructions)
#' - line 3: rank of the set of parameters describing the network
#' - line 4: name of the flow data file (hydrological regime without reservoirs)
#' - line 5: name of the file describing the annual objective hydrograph at the bottom station of the system
#' - line 6: objective type: 0 for low flow support, 1 for high flow lamination
#' - line 7: start of calculation period
#' - line 8: end of calculation period
#' - line 9: code for output format of volume results: 1 for absolute values in m3 , 2 for relative values with respect to Vtot or sum(Vtot)
#' - line 10: code indicating how the flow to be stored is distributed between the reservoirs:
#' - 1=fixed;
#' - 2=function of present volumes and maximum usable volume replenishment times from the start of time steps;
#' - 3=aimed at balancing the filling rates at the end of the time step;
#' - 4=aiming to balance at the end of the time step the times Tpot of reservoir evolution towards extreme state (see line 11) with average inputs; 5=aiming to balance at the end of the time step the times Tpot of reservoir evolution towards extreme state (see line 11) with average inputs.
#' - 5=aiming to balance at the end of the time step the times Tpot of evolution of the reservoir towards extreme state (see line 11) with given quantity of the contributions of each quantity.
#' - line 11 (used only if 4 or 5 on line 10): code indicating the nature of Tpot :
#' - 1 : Tpot is the minimum potential duration Tpot1 of reconstitution of the maximum usable volume (obtaining V=Vtot or V=0, depending on the nature of the objective (support or rolling) and the direction of the calculations)
#' - 2 : Tpot is the minimum potential duration Tpot2 of exhaustion of the usable volume (obtaining V=Vtot or V=0, depending on the nature of the objective (support or rolling) and the direction of the calculations)
#'
#' @param reservoirRuleSet rank of the set of parameters describing the reservoirs and their management rules (constraints and local instructions)
#' @param networkSet rank of the set of parameters describing the network
#' @param station name of the station where the flow target is located
#' @param Qfile name of the flow data file (hydrological regime without reservoirs)
#' @param bFlood boolean describing the objective type: \code{FALSE} for low flow support, \code{TRUE} for high flow lamination
#' @param startDate start of calculation period in "dd/mm/yyyy" format
#' @param endDate end of calculation period in "dd/mm/yyyy" format
#' @param threshold value of the threshold in m3/s
#' @param distributionType see in details the description of line 10 of CHOIX.TXT
#' @param distributionOption for \code{distributionType=1}, this should contains the relative change in comparison with a repartition based on storage capacity of fixed repartition between reservoirs. If \code{distributionType=4} or \code{5}, see in details the description of line 11 of CHOIX.TXT (default \code{NULL})
#' @param vgest_location location of the vgest software (default "../vgest")
#' @param objective_file name of the file used for storing the threshold hydrograph