CreateRunOptions: crash with RunModel_Lag
The example provided for RunModel_Lag is incoherent. Both CreateInputsModel and CreateRunOptions uses FUN_MOD = RunModelGR4J to work. If, in example, we try to change the argument to FUN_MOD = RunModel_Lag, CreateRunOptions crashes:
> InputsModelInf <- CreateInputsModel(FUN_MOD = RunModel_Lag, DatesR = BasinObs$DatesR,
+ Precip = BasinObs$P, PotEvap = BasinObs$E,
+ Qupstream = Qupstream, LengthHydro = LengthHydro,
+ BasinAreas = BasinAreas)
> RunOptions <- CreateRunOptions(FUN_MOD = RunModel_Lag,
+ InputsModel = InputsModelInf, IndPeriod_Run = Ind_Run)
Error in rep(0, NState) : invalid 'times' argument
This is due to the fact that:
> class(InputsModelInf)
[1] "InputsModel" "daily" "SD" "SD"
And in CreateRunOptions there is a test for defining the size of the initial state vector restricted to if ("GR" %in% ObjectClass | "CemaNeige" %in% ObjectClass) and therefore Nstate is NULL when proceeding to the creation of the initial state vector.
I see 2 solutions:
- Define the default value of
NState <- 0instead ofNULLwhich could be generic to any future model outside GR family assuming the lack of initial state - Systematically call
CreateIniStateswith proper parameters for the cases where the parameterIniStatesis NULL (I have tested it withIniStates = CreateIniStates(RunModel_Lag, InputsModel), it works).