Commit 4453a6fa authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

v1.6.3.50 style: format comments in RunModel_GR* functions

Refs #14
parent eb0ad606
Pipeline #17483 failed with stages
in 1 second
Package: airGR
Type: Package
Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling
Version: 1.6.3.49
Version: 1.6.3.50
Date: 2020-11-11
Authors@R: c(
person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")),
......
......@@ -4,7 +4,7 @@
### 1.6.3.49 Release Notes (2020-11-11)
### 1.6.3.50 Release Notes (2020-11-11)
#### New features
......
RunModel_GR1A <- function(InputsModel, RunOptions, Param) {
## Initialization of variables
NParam <- 1
FortranOutputs <- .FortranOutputs(GR = "GR1A")$GR
......
RunModel_GR2M <- function(InputsModel,RunOptions,Param) {
## Initialization of variables
NParam <- 2;
FortranOutputs <- .FortranOutputs(GR = "GR2M")$GR
##Arguments_check
## Arguments_check
if (inherits(InputsModel,"InputsModel")==FALSE) { stop("'InputsModel' must be of class 'InputsModel'") }
if (inherits(InputsModel,"monthly" )==FALSE) { stop("'InputsModel' must be of class 'monthly' ") }
if (inherits(InputsModel,"GR" )==FALSE) { stop("'InputsModel' must be of class 'GR' ") }
......@@ -23,27 +26,27 @@ RunModel_GR2M <- function(InputsModel,RunOptions,Param) {
Param[2L] <- Param_X1X2_threshold
}
##Input_data_preparation
## Input_data_preparation
if (identical(RunOptions$IndPeriod_WarmUp,as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL; }
IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp,RunOptions$IndPeriod_Run);
LInputSeries <- as.integer(length(IndPeriod1))
if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs));
} else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim); }
##Output_data_preparation
## Output_data_preparation
IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries;
ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim;
ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim;
##Use_of_IniResLevels
## Use_of_IniResLevels
if (!is.null(RunOptions$IniResLevels)) {
RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm)
RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[2]; ### routing store level (mm)
RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm)
RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[2]; ### routing store level (mm)
}
##Call_fortan
## Call_fortan
RESULTS <- .Fortran("frun_gr2M",PACKAGE="airGR",
##inputs
## inputs
LInputs=LInputSeries, ### length of input and output series
InputsPrecip=InputsModel$Precip[IndPeriod1], ### input series of total precipitation [mm/month]
InputsPE=InputsModel$PotEvap[IndPeriod1], ### input series potential evapotranspiration [mm/month]
......@@ -53,9 +56,9 @@ RunModel_GR2M <- function(InputsModel,RunOptions,Param) {
StateStart=RunOptions$IniStates, ### state variables used when the model run starts
NOutputs=as.integer(length(IndOutputs)), ### number of output series
IndOutputs=IndOutputs, ### indices of output series
##outputs
Outputs=matrix(as.double(-999.999),nrow=LInputSeries,ncol=length(IndOutputs)), ### output series [mm]
StateEnd=rep(as.double(-999.999),length(RunOptions$IniStates)) ### state variables at the end of the model run
## outputs
Outputs=matrix(as.double(-999.999),nrow=LInputSeries,ncol=length(IndOutputs)), ### output series [mm]
StateEnd=rep(as.double(-999.999),length(RunOptions$IniStates)) ### state variables at the end of the model run
)
RESULTS$Outputs [round(RESULTS$Outputs ,3)==(-999.999)] <- NA;
RESULTS$StateEnd[round(RESULTS$StateEnd,3)==(-999.999)] <- NA;
......@@ -68,29 +71,28 @@ RunModel_GR2M <- function(InputsModel,RunOptions,Param) {
}
##Output_data_preparation
##OutputsModel_only
## Output_data_preparation
## OutputsModel_only
if (ExportDatesR==FALSE & ExportStateEnd==FALSE) {
OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]);
names(OutputsModel) <- FortranOutputs[IndOutputs]; }
##DatesR_and_OutputsModel_only
## DatesR_and_OutputsModel_only
if (ExportDatesR==TRUE & ExportStateEnd==FALSE) {
OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]),
lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]) );
names(OutputsModel) <- c("DatesR",FortranOutputs[IndOutputs]); }
##OutputsModel_and_SateEnd_only
## OutputsModel_and_SateEnd_only
if (ExportDatesR==FALSE & ExportStateEnd==TRUE) {
OutputsModel <- c( lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]),
list(RESULTS$StateEnd) );
names(OutputsModel) <- c(FortranOutputs[IndOutputs],"StateEnd"); }
##DatesR_and_OutputsModel_and_SateEnd
if ((ExportDatesR==TRUE & ExportStateEnd==TRUE) | "all" %in% RunOptions$Outputs_Sim) {
## DatesR_and_OutputsModel_and_SateEnd
OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]),
lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]),
list(RESULTS$StateEnd) );
names(OutputsModel) <- c("DatesR",FortranOutputs[IndOutputs],"StateEnd"); }
##End
## End
rm(RESULTS);
class(OutputsModel) <- c("OutputsModel","monthly","GR");
return(OutputsModel);
......
RunModel_GR4H <- function(InputsModel,RunOptions,Param) {
## Initialization of variables
NParam <- 4;
FortranOutputs <- .FortranOutputs(GR = "GR4H")$GR
##Arguments_check
## Arguments_check
if (inherits(InputsModel,"InputsModel")==FALSE) { stop("'InputsModel' must be of class 'InputsModel'") }
if (inherits(InputsModel,"hourly" )==FALSE) { stop("'InputsModel' must be of class 'hourly' ") }
if (inherits(InputsModel,"GR" )==FALSE) { stop("'InputsModel' must be of class 'GR' ") }
......@@ -28,27 +31,27 @@ RunModel_GR4H <- function(InputsModel,RunOptions,Param) {
Param[4L] <- Param_X4_threshold
}
##Input_data_preparation
## Input_data_preparation
if (identical(RunOptions$IndPeriod_WarmUp,as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL; }
IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp,RunOptions$IndPeriod_Run);
LInputSeries <- as.integer(length(IndPeriod1))
if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs));
} else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim); }
##Output_data_preparation
## Output_data_preparation
IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries;
ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim;
ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim;
##Use_of_IniResLevels
## Use_of_IniResLevels
if (!is.null(RunOptions$IniResLevels)) {
RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm)
RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3]; ### routing store level (mm)
}
##Call_fortan
## Call_fortan
RESULTS <- .Fortran("frun_gr4h",PACKAGE="airGR",
##inputs
## inputs
LInputs=LInputSeries, ### length of input and output series
InputsPrecip=InputsModel$Precip[IndPeriod1], ### input series of total precipitation [mm/h]
InputsPE=InputsModel$PotEvap[IndPeriod1], ### input series potential evapotranspiration [mm/h]
......@@ -58,9 +61,9 @@ RunModel_GR4H <- function(InputsModel,RunOptions,Param) {
StateStart=RunOptions$IniStates, ### state variables used when the model run starts
NOutputs=as.integer(length(IndOutputs)), ### number of output series
IndOutputs=IndOutputs, ### indices of output series
##outputs
Outputs=matrix(as.double(-999.999),nrow=LInputSeries,ncol=length(IndOutputs)), ### output series [mm]
StateEnd=rep(as.double(-999.999),length(RunOptions$IniStates)) ### state variables at the end of the model run
## outputs
Outputs=matrix(as.double(-999.999),nrow=LInputSeries,ncol=length(IndOutputs)), ### output series [mm]
StateEnd=rep(as.double(-999.999),length(RunOptions$IniStates)) ### state variables at the end of the model run
)
RESULTS$Outputs[ round(RESULTS$Outputs ,3)==(-999.999)] <- NA;
RESULTS$StateEnd[round(RESULTS$StateEnd,3)==(-999.999)] <- NA;
......@@ -73,29 +76,29 @@ RunModel_GR4H <- function(InputsModel,RunOptions,Param) {
verbose = FALSE)
}
##Output_data_preparation
##OutputsModel_only
## Output_data_preparation
## OutputsModel_only
if (ExportDatesR==FALSE & ExportStateEnd==FALSE) {
OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]);
names(OutputsModel) <- FortranOutputs[IndOutputs]; }
##DatesR_and_OutputsModel_only
## DatesR_and_OutputsModel_only
if (ExportDatesR==TRUE & ExportStateEnd==FALSE) {
OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]),
lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]) );
names(OutputsModel) <- c("DatesR",FortranOutputs[IndOutputs]); }
##OutputsModel_and_SateEnd_only
## OutputsModel_and_SateEnd_only
if (ExportDatesR==FALSE & ExportStateEnd==TRUE) {
OutputsModel <- c( lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]),
list(RESULTS$StateEnd) );
names(OutputsModel) <- c(FortranOutputs[IndOutputs],"StateEnd"); }
##DatesR_and_OutputsModel_and_SateEnd
## DatesR_and_OutputsModel_and_SateEnd
if ((ExportDatesR==TRUE & ExportStateEnd==TRUE) | "all" %in% RunOptions$Outputs_Sim) {
OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]),
lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]),
list(RESULTS$StateEnd) );
names(OutputsModel) <- c("DatesR",FortranOutputs[IndOutputs],"StateEnd"); }
##End
## End
rm(RESULTS);
class(OutputsModel) <- c("OutputsModel","hourly","GR");
return(OutputsModel);
......
RunModel_GR4J <- function(InputsModel,RunOptions,Param) {
## Initialization of variables
NParam <- 4;
FortranOutputs <- .FortranOutputs(GR = "GR4J")$GR
##Arguments_check
## Arguments_check
if (inherits(InputsModel,"InputsModel")==FALSE) { stop("'InputsModel' must be of class 'InputsModel'") }
if (inherits(InputsModel,"daily" )==FALSE) { stop("'InputsModel' must be of class 'daily' ") }
if (inherits(InputsModel,"GR" )==FALSE) { stop("'InputsModel' must be of class 'GR' ") }
......@@ -28,26 +31,26 @@ RunModel_GR4J <- function(InputsModel,RunOptions,Param) {
Param[4L] <- Param_X4_threshold
}
##Input_data_preparation
## Input_data_preparation
if (identical(RunOptions$IndPeriod_WarmUp,as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL; }
IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp,RunOptions$IndPeriod_Run);
LInputSeries <- as.integer(length(IndPeriod1))
if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs));
} else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim); }
##Input_data_preparation
## Input_data_preparation
IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries;
ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim;
ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim;
##Use_of_IniResLevels
## Use_of_IniResLevels
if (!is.null(RunOptions$IniResLevels)) {
RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm)
RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3]; ### routing store level (mm)
RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm)
RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3]; ### routing store level (mm)
}
##Call_fortan
## Call_fortan
RESULTS <- .Fortran("frun_gr4j",PACKAGE="airGR",
##inputs
## inputs
LInputs=LInputSeries, ### length of input and output series
InputsPrecip=InputsModel$Precip[IndPeriod1], ### input series of total precipitation [mm/d]
InputsPE=InputsModel$PotEvap[IndPeriod1], ### input series potential evapotranspiration [mm/d]
......@@ -57,9 +60,9 @@ RunModel_GR4J <- function(InputsModel,RunOptions,Param) {
StateStart=RunOptions$IniStates, ### state variables used when the model run starts
NOutputs=as.integer(length(IndOutputs)), ### number of output series
IndOutputs=IndOutputs, ### indices of output series
##outputs
Outputs=matrix(as.double(-999.999),nrow=LInputSeries,ncol=length(IndOutputs)), ### output series [mm]
StateEnd=rep(as.double(-999.999),length(RunOptions$IniStates)) ### state variables at the end of the model run
## outputs
Outputs=matrix(as.double(-999.999),nrow=LInputSeries,ncol=length(IndOutputs)), ### output series [mm]
StateEnd=rep(as.double(-999.999),length(RunOptions$IniStates)) ### state variables at the end of the model run
)
RESULTS$Outputs[ round(RESULTS$Outputs ,3)==(-999.999)] <- NA;
RESULTS$StateEnd[round(RESULTS$StateEnd,3)==(-999.999)] <- NA;
......@@ -72,29 +75,29 @@ RunModel_GR4J <- function(InputsModel,RunOptions,Param) {
verbose = FALSE)
}
##Output_data_preparation
##OutputsModel_only
## Output_data_preparation
## OutputsModel_only
if (ExportDatesR==FALSE & ExportStateEnd==FALSE) {
OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]);
names(OutputsModel) <- FortranOutputs[IndOutputs]; }
##DatesR_and_OutputsModel_only
## DatesR_and_OutputsModel_only
if (ExportDatesR==TRUE & ExportStateEnd==FALSE) {
OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]),
lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]) );
names(OutputsModel) <- c("DatesR",FortranOutputs[IndOutputs]); }
##OutputsModel_and_StateEnd_only
## OutputsModel_and_StateEnd_only
if (ExportDatesR==FALSE & ExportStateEnd==TRUE) {
OutputsModel <- c( lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]),
list(RESULTS$StateEnd) );
names(OutputsModel) <- c(FortranOutputs[IndOutputs],"StateEnd"); }
##DatesR_and_OutputsModel_and_StateEnd
## DatesR_and_OutputsModel_and_StateEnd
if ((ExportDatesR==TRUE & ExportStateEnd==TRUE) | "all" %in% RunOptions$Outputs_Sim) {
OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]),
lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]),
list(RESULTS$StateEnd) );
names(OutputsModel) <- c("DatesR",FortranOutputs[IndOutputs],"StateEnd"); }
##End
## End
rm(RESULTS);
class(OutputsModel) <- c("OutputsModel","daily","GR");
return(OutputsModel);
......
RunModel_GR5H <- function(InputsModel,RunOptions,Param) {
## Initialization of variables
NParam <- 5;
FortranOutputs <- .FortranOutputs(GR = "GR5H")$GR
IsIntStore <- inherits(RunOptions, "interception")
......@@ -9,7 +11,8 @@ RunModel_GR5H <- function(InputsModel,RunOptions,Param) {
Imax <- -99
}
##Arguments_check
## Arguments_check
if (inherits(InputsModel,"InputsModel")==FALSE) { stop("'InputsModel' must be of class 'InputsModel'") }
if (inherits(InputsModel,"hourly" )==FALSE) { stop("'InputsModel' must be of class 'hourly' ") }
if (inherits(InputsModel,"GR" )==FALSE) { stop("'InputsModel' must be of class 'GR' ") }
......@@ -34,30 +37,30 @@ RunModel_GR5H <- function(InputsModel,RunOptions,Param) {
Param[4L] <- Param_X4_threshold
}
##Input_data_preparation
## Input_data_preparation
if (identical(RunOptions$IndPeriod_WarmUp,as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL; }
IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp,RunOptions$IndPeriod_Run);
LInputSeries <- as.integer(length(IndPeriod1))
if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs));
} else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim); }
##Output_data_preparation
## Output_data_preparation
IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries;
ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim;
ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim;
##Use_of_IniResLevels
## Use_of_IniResLevels
if (!is.null(RunOptions$IniResLevels)) {
RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm)
RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3]; ### routing store level (mm)
RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm)
RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3]; ### routing store level (mm)
if (IsIntStore) {
RunOptions$IniStates[4] <- RunOptions$IniResLevels[4] * Imax; ### interception store level (mm)
RunOptions$IniStates[4] <- RunOptions$IniResLevels[4] * Imax; ### interception store level (mm)
}
}
##Call_fortan
## Call_fortan
RESULTS <- .Fortran("frun_gr5h",PACKAGE="airGR",
##inputs
## inputs
LInputs=LInputSeries, ### length of input and output series
InputsPrecip=InputsModel$Precip[IndPeriod1], ### input series of total precipitation [mm/h]
InputsPE=InputsModel$PotEvap[IndPeriod1], ### input series potential evapotranspiration [mm/h]
......@@ -68,9 +71,9 @@ RunModel_GR5H <- function(InputsModel,RunOptions,Param) {
Imax=Imax, ### maximal capacity of interception store
NOutputs=as.integer(length(IndOutputs)), ### number of output series
IndOutputs=IndOutputs, ### indices of output series
##outputs
Outputs=matrix(as.double(-999.999),nrow=LInputSeries,ncol=length(IndOutputs)), ### output series [mm or mm/h]
StateEnd=rep(as.double(-999.999),length(RunOptions$IniStates)) ### state variables at the end of the model run
## outputs
Outputs=matrix(as.double(-999.999),nrow=LInputSeries,ncol=length(IndOutputs)), ### output series [mm or mm/h]
StateEnd=rep(as.double(-999.999),length(RunOptions$IniStates)) ### state variables at the end of the model run
)
RESULTS$Outputs[ round(RESULTS$Outputs ,3)==(-999.999)] <- NA;
RESULTS$StateEnd[round(RESULTS$StateEnd,3)==(-999.999)] <- NA;
......@@ -84,29 +87,29 @@ RunModel_GR5H <- function(InputsModel,RunOptions,Param) {
verbose = FALSE)
}
##Output_data_preparation
##OutputsModel_only
## Output_data_preparation
## OutputsModel_only
if (ExportDatesR==FALSE & ExportStateEnd==FALSE) {
OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]);
names(OutputsModel) <- FortranOutputs[IndOutputs]; }
##DatesR_and_OutputsModel_only
## DatesR_and_OutputsModel_only
if (ExportDatesR==TRUE & ExportStateEnd==FALSE) {
OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]),
lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]) );
names(OutputsModel) <- c("DatesR",FortranOutputs[IndOutputs]); }
##OutputsModel_and_StateEnd_only
## OutputsModel_and_StateEnd_only
if (ExportDatesR==FALSE & ExportStateEnd==TRUE) {
OutputsModel <- c( lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]),
list(RESULTS$StateEnd) );
names(OutputsModel) <- c(FortranOutputs[IndOutputs],"StateEnd"); }
##DatesR_and_OutputsModel_and_StateEnd
## DatesR_and_OutputsModel_and_StateEnd
if ((ExportDatesR==TRUE & ExportStateEnd==TRUE) | "all" %in% RunOptions$Outputs_Sim) {
OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]),
lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]),
list(RESULTS$StateEnd) );
names(OutputsModel) <- c("DatesR",FortranOutputs[IndOutputs],"StateEnd"); }
##End
## End
rm(RESULTS);
class(OutputsModel) <- c("OutputsModel","hourly","GR");
if (IsIntStore) {
......
RunModel_GR5J <- function(InputsModel,RunOptions,Param) {
## Initialization of variables
NParam <- 5;
FortranOutputs <- .FortranOutputs(GR = "GR5J")$GR
##Arguments_check
## Arguments_check
if (inherits(InputsModel,"InputsModel")==FALSE) { stop("'InputsModel' must be of class 'InputsModel'") }
if (inherits(InputsModel,"daily" )==FALSE) { stop("'InputsModel' must be of class 'daily' ") }
if (inherits(InputsModel,"GR" )==FALSE) { stop("'InputsModel' must be of class 'GR' ") }
......@@ -28,27 +31,27 @@ RunModel_GR5J <- function(InputsModel,RunOptions,Param) {
Param[4L] <- Param_X4_threshold
}
##Input_data_preparation
## Input_data_preparation
if (identical(RunOptions$IndPeriod_WarmUp,as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL; }
IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp,RunOptions$IndPeriod_Run);
LInputSeries <- as.integer(length(IndPeriod1))
if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs));
} else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim); }
##Output_data_preparation
## Output_data_preparation
IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries;
ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim;
ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim;
##Use_of_IniResLevels
## Use_of_IniResLevels
if (!is.null(RunOptions$IniResLevels)) {
RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm)
RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3]; ### routing store level (mm)
RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm)
RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3]; ### routing store level (mm)
}
##Call_fortan
## Call_fortan
RESULTS <- .Fortran("frun_gr5j",PACKAGE="airGR",
##inputs
## inputs
LInputs=LInputSeries, ### length of input and output series
InputsPrecip=InputsModel$Precip[IndPeriod1], ### input series of total precipitation [mm/d]
InputsPE=InputsModel$PotEvap[IndPeriod1], ### input series potential evapotranspiration [mm/d]
......@@ -58,9 +61,9 @@ RunModel_GR5J <- function(InputsModel,RunOptions,Param) {
StateStart=RunOptions$IniStates, ### state variables used when the model run starts
NOutputs=as.integer(length(IndOutputs)), ### number of output series
IndOutputs=IndOutputs, ### indices of output series
##outputs
Outputs=matrix(as.double(-999.999),nrow=LInputSeries,ncol=length(IndOutputs)), ### output series [mm]
StateEnd=rep(as.double(-999.999),length(RunOptions$IniStates)) ### state variables at the end of the model run
## outputs
Outputs=matrix(as.double(-999.999),nrow=LInputSeries,ncol=length(IndOutputs)), ### output series [mm]
StateEnd=rep(as.double(-999.999),length(RunOptions$IniStates)) ### state variables at the end of the model run
)
RESULTS$Outputs[ round(RESULTS$Outputs ,3)==(-999.999)] <- NA;
RESULTS$StateEnd[round(RESULTS$StateEnd,3)==(-999.999)] <- NA;
......@@ -73,29 +76,29 @@ RunModel_GR5J <- function(InputsModel,RunOptions,Param) {
verbose = FALSE)
}
##Output_data_preparation
##OutputsModel_only
## Output_data_preparation
## OutputsModel_only
if (ExportDatesR==FALSE & ExportStateEnd==FALSE) {
OutputsModel <- lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]);
names(OutputsModel) <- FortranOutputs[IndOutputs]; }
##DatesR_and_OutputsModel_only
## DatesR_and_OutputsModel_only
if (ExportDatesR==TRUE & ExportStateEnd==FALSE) {
OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]),
lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]) );
names(OutputsModel) <- c("DatesR",FortranOutputs[IndOutputs]); }
##OutputsModel_and_SateEnd_only
## OutputsModel_and_SateEnd_only
if (ExportDatesR==FALSE & ExportStateEnd==TRUE) {
OutputsModel <- c( lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]),
list(RESULTS$StateEnd) );
names(OutputsModel) <- c(FortranOutputs[IndOutputs],"StateEnd"); }
##DatesR_and_OutputsModel_and_SateEnd
## DatesR_and_OutputsModel_and_SateEnd
if ((ExportDatesR==TRUE & ExportStateEnd==TRUE) | "all" %in% RunOptions$Outputs_Sim) {
OutputsModel <- c( list(InputsModel$DatesR[RunOptions$IndPeriod_Run]),
lapply(seq_len(RESULTS$NOutputs), function(i) RESULTS$Outputs[IndPeriod2,i]),
list(RESULTS$StateEnd) );
names(OutputsModel) <- c("DatesR",FortranOutputs[IndOutputs],"StateEnd"); }
##End
## End
rm(RESULTS);
class(OutputsModel) <- c("OutputsModel","daily","GR");
return(OutputsModel);
......
RunModel_GR6J <- function(InputsModel,RunOptions,Param) {
## Initialization of variables
NParam <- 6;
FortranOutputs <- .FortranOutputs(GR = "GR6J")$GR
##Arguments_check
## Arguments_check
if (inherits(InputsModel,"InputsModel")==FALSE) { stop("'InputsModel' must be of class 'InputsModel'") }
if (inherits(InputsModel,"daily" )==FALSE) { stop("'InputsModel' must be of class 'daily' ") }
if (inherits(InputsModel,"GR" )==FALSE) { stop("'InputsModel' must be of class 'GR' ") }
......@@ -32,28 +35,28 @@ RunModel_GR6J <- function(InputsModel,RunOptions,Param) {
Param[6L] <- Param_X1X3X6_threshold
}
##Input_data_preparation
## Input_data_preparation
if (identical(RunOptions$IndPeriod_WarmUp,as.integer(0))) { RunOptions$IndPeriod_WarmUp <- NULL; }
IndPeriod1 <- c(RunOptions$IndPeriod_WarmUp,RunOptions$IndPeriod_Run);
LInputSeries <- as.integer(length(IndPeriod1))
if ("all" %in% RunOptions$Outputs_Sim) { IndOutputs <- as.integer(1:length(FortranOutputs));
} else { IndOutputs <- which(FortranOutputs %in% RunOptions$Outputs_Sim); }
##Output_data_preparation
## Output_data_preparation
IndPeriod2 <- (length(RunOptions$IndPeriod_WarmUp)+1):LInputSeries;
ExportDatesR <- "DatesR" %in% RunOptions$Outputs_Sim;
ExportStateEnd <- "StateEnd" %in% RunOptions$Outputs_Sim;
##Use_of_IniResLevels
## Use_of_IniResLevels
if (!is.null(RunOptions$IniResLevels)) {
RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm)
RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3]; ### routing store level (mm)
RunOptions$IniStates[3] <- RunOptions$IniResLevels[3] ### exponential store level (mm)
RunOptions$IniStates[1] <- RunOptions$IniResLevels[1]*Param[1]; ### production store level (mm)
RunOptions$IniStates[2] <- RunOptions$IniResLevels[2]*Param[3]; ### routing store level (mm)
RunOptions$IniStates[3] <- RunOptions$IniResLevels[3] ### exponential store level (mm)
}
##Call_fortan
## Call_fortan
RESULTS <- .Fortran("frun_gr6j",PACKAGE="airGR",
##inputs
## inputs
LInputs=LInputSeries, ### length of input and output series
InputsPrecip=InputsModel$Precip[IndPeriod1], ### input series of total precipitation [mm/d]
InputsPE=InputsModel$PotEvap[IndPeriod1], ### input series potential evapotranspiration [mm/d]
......@@ -63,9 +66,9 @@ RunModel_GR6J <- function(InputsModel,RunOptions,Param) {
StateStart=RunOptions$IniStates, ### state variables used when the model run starts
NOutputs=as.integer(length(IndOutputs)), ### number of output series
IndOutputs=IndOutputs, ### indices of output series
##outputs
Outputs=matrix(as.double(-999.999),nrow=LInputSeries,ncol=length(IndOutputs)), ### output series [mm]
StateEnd=rep(as.double(-999.999),length(RunOptions$IniStates)) ### state variables at the end of the model run
## outputs
Outputs=matrix(as.double(-999.999),nrow=LInputSeries,ncol=length(IndOutputs)), ### output series [mm]