diff --git a/DESCRIPTION b/DESCRIPTION index 3f755b762f815d0c5f937ae4aed636623d0b532f..e949a9750a2f942381326382f76d4e0db23e4f31 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: airGR Type: Package Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling -Version: 1.6.3.51 +Version: 1.6.3.52 Date: 2020-11-11 Authors@R: c( person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")), diff --git a/NEWS.md b/NEWS.md index 72b585ff088b6fb93e8bb999defe78f5f56209b1..0ff11b945e16be71d6cf1584b44a07c62477db45 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,7 @@ -### 1.6.3.51 Release Notes (2020-11-11) +### 1.6.3.52 Release Notes (2020-11-11) #### New features diff --git a/R/RunModel_GR2M.R b/R/RunModel_GR2M.R index fa0a1d6f148d448374c93bb0671e257f45f30d5b..a40a49666d8c2832d0d1a620a6c4984fd3f57b94 100644 --- a/R/RunModel_GR2M.R +++ b/R/RunModel_GR2M.R @@ -7,13 +7,13 @@ RunModel_GR2M <- function(InputsModel,RunOptions,Param) { ## 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' ") } - if (inherits(RunOptions,"RunOptions" )==FALSE) { stop("'RunOptions' must be of class 'RunOptions' ") } - if (inherits(RunOptions,"GR" )==FALSE) { stop("'RunOptions' must be of class 'GR' ") } + 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' ") } + if (inherits(RunOptions,"RunOptions" ) == FALSE) { stop("'RunOptions' must be of class 'RunOptions' ") } + if (inherits(RunOptions,"GR" ) == FALSE) { stop("'RunOptions' must be of class 'GR' ") } if (!is.vector(Param) | !is.numeric(Param)) { stop("'Param' must be a numeric vector") } - if (sum(!is.na(Param))!=NParam) { stop(paste("'Param' must be a vector of length ",NParam," and contain no NA",sep="")) } + if (sum(!is.na(Param))! = NParam) { stop(paste("'Param' must be a vector of length ",NParam," and contain no NA",sep = "")) } Param <- as.double(Param); Param_X1X2_threshold <- 1e-2 @@ -45,23 +45,23 @@ RunModel_GR2M <- function(InputsModel,RunOptions,Param) { } ## Call_fortan - RESULTS <- .Fortran("frun_gr2M",PACKAGE="airGR", + RESULTS <- .Fortran("frun_gr2M",PACKAGE = "airGR", ## 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] - NParam=as.integer(length(Param)), ### number of model parameter - Param=Param, ### parameter set - NStates=as.integer(length(RunOptions$IniStates)), ### number of state variables used for model initialising - 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 + 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] + NParam = as.integer(length(Param)), ### number of model parameter + Param = Param, ### parameter set + NStates = as.integer(length(RunOptions$IniStates)), ### number of state variables used for model initialising + 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 = 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; + RESULTS$Outputs [round(RESULTS$Outputs ,3) == (-999.999)] <- NA; + RESULTS$StateEnd[round(RESULTS$StateEnd,3) == (-999.999)] <- NA; if (ExportStateEnd) { RESULTS$StateEnd <- CreateIniStates(FUN_MOD = RunModel_GR2M, InputsModel = InputsModel, ProdStore = RESULTS$StateEnd[1L], RoutStore = RESULTS$StateEnd[2L], ExpStore = NULL, diff --git a/R/RunModel_GR4H.R b/R/RunModel_GR4H.R index 6b2b55a04bbeacc7cfb449e7d0ed3339bcf02668..7cbe925a6772162d62b87d5402bbaeabe304a4ac 100644 --- a/R/RunModel_GR4H.R +++ b/R/RunModel_GR4H.R @@ -7,13 +7,13 @@ RunModel_GR4H <- function(InputsModel,RunOptions,Param) { ## 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' ") } - if (inherits(RunOptions,"RunOptions" )==FALSE) { stop("'RunOptions' must be of class 'RunOptions' ") } - if (inherits(RunOptions,"GR" )==FALSE) { stop("'RunOptions' must be of class 'GR' ") } + 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' ") } + if (inherits(RunOptions,"RunOptions" ) == FALSE) { stop("'RunOptions' must be of class 'RunOptions' ") } + if (inherits(RunOptions,"GR" ) == FALSE) { stop("'RunOptions' must be of class 'GR' ") } if (!is.vector(Param) | !is.numeric(Param)) { stop("'Param' must be a numeric vector") } - if (sum(!is.na(Param))!=NParam) { stop(paste("'Param' must be a vector of length ",NParam," and contain no NA",sep="")) } + if (sum(!is.na(Param))! = NParam) { stop(paste("'Param' must be a vector of length ",NParam," and contain no NA",sep = "")) } Param <- as.double(Param); Param_X1X3_threshold <- 1e-2 @@ -50,23 +50,23 @@ RunModel_GR4H <- function(InputsModel,RunOptions,Param) { } ## Call_fortan - RESULTS <- .Fortran("frun_gr4h",PACKAGE="airGR", + RESULTS <- .Fortran("frun_gr4h",PACKAGE = "airGR", ## 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] - NParam=as.integer(length(Param)), ### number of model parameter - Param=Param, ### parameter set - NStates=as.integer(length(RunOptions$IniStates)), ### number of state variables used for model initialising - 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 + 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] + NParam = as.integer(length(Param)), ### number of model parameter + Param = Param, ### parameter set + NStates = as.integer(length(RunOptions$IniStates)), ### number of state variables used for model initialising + 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 = 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; + RESULTS$Outputs[ round(RESULTS$Outputs ,3) == (-999.999)] <- NA; + RESULTS$StateEnd[round(RESULTS$StateEnd,3) == (-999.999)] <- NA; if (ExportStateEnd) { RESULTS$StateEnd[-3L] <- ifelse(RESULTS$StateEnd[-3L] < 0, 0, RESULTS$StateEnd[-3L]) ### remove negative values except for the ExpStore location RESULTS$StateEnd <- CreateIniStates(FUN_MOD = RunModel_GR4H, InputsModel = InputsModel, @@ -78,21 +78,21 @@ RunModel_GR4H <- function(InputsModel,RunOptions,Param) { ## Output_data_preparation ## OutputsModel_only - if (ExportDatesR==FALSE & ExportStateEnd==FALSE) { + 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 - if (ExportDatesR==TRUE & ExportStateEnd==FALSE) { + 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 - if (ExportDatesR==FALSE & ExportStateEnd==TRUE) { + 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) { + 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) ); diff --git a/R/RunModel_GR4J.R b/R/RunModel_GR4J.R index 0bcade5ff642e5e25a25493ee22839d1a275c205..4ba3dac322291ef8c106967ddfc66856dd643fb1 100644 --- a/R/RunModel_GR4J.R +++ b/R/RunModel_GR4J.R @@ -7,13 +7,13 @@ RunModel_GR4J <- function(InputsModel,RunOptions,Param) { ## 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' ") } - if (inherits(RunOptions,"RunOptions" )==FALSE) { stop("'RunOptions' must be of class 'RunOptions' ") } - if (inherits(RunOptions,"GR" )==FALSE) { stop("'RunOptions' must be of class 'GR' ") } + 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' ") } + if (inherits(RunOptions,"RunOptions" ) == FALSE) { stop("'RunOptions' must be of class 'RunOptions' ") } + if (inherits(RunOptions,"GR" ) == FALSE) { stop("'RunOptions' must be of class 'GR' ") } if (!is.vector(Param) | !is.numeric(Param)) { stop("'Param' must be a numeric vector") } - if (sum(!is.na(Param))!=NParam) { stop(paste("'Param' must be a vector of length ",NParam," and contain no NA",sep="")) } + if (sum(!is.na(Param))! = NParam) { stop(paste("'Param' must be a vector of length ",NParam," and contain no NA",sep = "")) } Param <- as.double(Param); Param_X1X3_threshold <- 1e-2 @@ -49,23 +49,23 @@ RunModel_GR4J <- function(InputsModel,RunOptions,Param) { } ## Call_fortan - RESULTS <- .Fortran("frun_gr4j",PACKAGE="airGR", + RESULTS <- .Fortran("frun_gr4j",PACKAGE = "airGR", ## 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] - NParam=as.integer(length(Param)), ### number of model parameter - Param=Param, ### parameter set - NStates=as.integer(length(RunOptions$IniStates)), ### number of state variables used for model initialising - 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 + 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] + NParam = as.integer(length(Param)), ### number of model parameter + Param = Param, ### parameter set + NStates = as.integer(length(RunOptions$IniStates)), ### number of state variables used for model initialising + 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 = 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; + RESULTS$Outputs[ round(RESULTS$Outputs ,3) == (-999.999)] <- NA; + RESULTS$StateEnd[round(RESULTS$StateEnd,3) == (-999.999)] <- NA; if (ExportStateEnd) { RESULTS$StateEnd[-3L] <- ifelse(RESULTS$StateEnd[-3L] < 0, 0, RESULTS$StateEnd[-3L]) ### remove negative values except for the ExpStore location RESULTS$StateEnd <- CreateIniStates(FUN_MOD = RunModel_GR4J, InputsModel = InputsModel, @@ -77,21 +77,21 @@ RunModel_GR4J <- function(InputsModel,RunOptions,Param) { ## Output_data_preparation ## OutputsModel_only - if (ExportDatesR==FALSE & ExportStateEnd==FALSE) { + 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 - if (ExportDatesR==TRUE & ExportStateEnd==FALSE) { + 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 - if (ExportDatesR==FALSE & ExportStateEnd==TRUE) { + 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 - if ((ExportDatesR==TRUE & ExportStateEnd==TRUE) | "all" %in% RunOptions$Outputs_Sim) { + 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) ); diff --git a/R/RunModel_GR5H.R b/R/RunModel_GR5H.R index f57c6b74f3f99305d93d1909b33fcaf089f55ba9..c6ec844a68c164a9b30b45ce6c8b6544778dedda 100644 --- a/R/RunModel_GR5H.R +++ b/R/RunModel_GR5H.R @@ -13,13 +13,13 @@ RunModel_GR5H <- function(InputsModel,RunOptions,Param) { ## 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' ") } - if (inherits(RunOptions,"RunOptions" )==FALSE) { stop("'RunOptions' must be of class 'RunOptions' ") } - if (inherits(RunOptions,"GR" )==FALSE) { stop("'RunOptions' must be of class 'GR' ") } + 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' ") } + if (inherits(RunOptions,"RunOptions" ) == FALSE) { stop("'RunOptions' must be of class 'RunOptions' ") } + if (inherits(RunOptions,"GR" ) == FALSE) { stop("'RunOptions' must be of class 'GR' ") } if (!is.vector(Param) | !is.numeric(Param)) { stop("'Param' must be a numeric vector") } - if (sum(!is.na(Param))!=NParam) { stop(paste("'Param' must be a vector of length ",NParam," and contain no NA",sep="")) } + if (sum(!is.na(Param))! = NParam) { stop(paste("'Param' must be a vector of length ",NParam," and contain no NA",sep = "")) } Param <- as.double(Param); Param_X1X3_threshold <- 1e-2 @@ -59,24 +59,24 @@ RunModel_GR5H <- function(InputsModel,RunOptions,Param) { } ## Call_fortan - RESULTS <- .Fortran("frun_gr5h",PACKAGE="airGR", + RESULTS <- .Fortran("frun_gr5h",PACKAGE = "airGR", ## 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] - NParam=as.integer(length(Param)), ### number of model parameter - Param=Param, ### parameter set - NStates=as.integer(length(RunOptions$IniStates)), ### number of state variables used for model initialising - StateStart=RunOptions$IniStates, ### state variables used when the model run starts - Imax=Imax, ### maximal capacity of interception store - NOutputs=as.integer(length(IndOutputs)), ### number of output series - IndOutputs=IndOutputs, ### indices of output series + 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] + NParam = as.integer(length(Param)), ### number of model parameter + Param = Param, ### parameter set + NStates = as.integer(length(RunOptions$IniStates)), ### number of state variables used for model initialising + StateStart = RunOptions$IniStates, ### state variables used when the model run starts + 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 = 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; + RESULTS$Outputs[ round(RESULTS$Outputs ,3) == (-999.999)] <- NA; + RESULTS$StateEnd[round(RESULTS$StateEnd,3) == (-999.999)] <- NA; if (ExportStateEnd) { RESULTS$StateEnd[-3L] <- ifelse(RESULTS$StateEnd[-3L] < 0, 0, RESULTS$StateEnd[-3L]) ### remove negative values except for the ExpStore location RESULTS$StateEnd <- CreateIniStates(FUN_MOD = RunModel_GR5H, InputsModel = InputsModel, @@ -89,21 +89,21 @@ RunModel_GR5H <- function(InputsModel,RunOptions,Param) { ## Output_data_preparation ## OutputsModel_only - if (ExportDatesR==FALSE & ExportStateEnd==FALSE) { + 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 - if (ExportDatesR==TRUE & ExportStateEnd==FALSE) { + 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 - if (ExportDatesR==FALSE & ExportStateEnd==TRUE) { + 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 - if ((ExportDatesR==TRUE & ExportStateEnd==TRUE) | "all" %in% RunOptions$Outputs_Sim) { + 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) ); diff --git a/R/RunModel_GR5J.R b/R/RunModel_GR5J.R index e7d4f474eda642d9d9352f3a34d3f94d3f4bd95e..e1b9a85a75b2a7270cff9982631f2c0e60342ceb 100644 --- a/R/RunModel_GR5J.R +++ b/R/RunModel_GR5J.R @@ -7,13 +7,13 @@ RunModel_GR5J <- function(InputsModel,RunOptions,Param) { ## 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' ") } - if (inherits(RunOptions,"RunOptions" )==FALSE) { stop("'RunOptions' must be of class 'RunOptions' ") } - if (inherits(RunOptions,"GR" )==FALSE) { stop("'RunOptions' must be of class 'GR' ") } + 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' ") } + if (inherits(RunOptions,"RunOptions" ) == FALSE) { stop("'RunOptions' must be of class 'RunOptions' ") } + if (inherits(RunOptions,"GR" ) == FALSE) { stop("'RunOptions' must be of class 'GR' ") } if (!is.vector(Param) | !is.numeric(Param)) { stop("'Param' must be a numeric vector") } - if (sum(!is.na(Param))!=NParam) { stop(paste("'Param' must be a vector of length ",NParam," and contain no NA",sep="")) } + if (sum(!is.na(Param))! = NParam) { stop(paste("'Param' must be a vector of length ",NParam," and contain no NA",sep = "")) } Param <- as.double(Param); Param_X1X3_threshold <- 1e-2 @@ -50,23 +50,23 @@ RunModel_GR5J <- function(InputsModel,RunOptions,Param) { } ## Call_fortan - RESULTS <- .Fortran("frun_gr5j",PACKAGE="airGR", + RESULTS <- .Fortran("frun_gr5j",PACKAGE = "airGR", ## 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] - NParam=as.integer(length(Param)), ### number of model parameter - Param=Param, ### parameter set - NStates=as.integer(length(RunOptions$IniStates)), ### number of state variables used for model initialising - 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 + 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] + NParam = as.integer(length(Param)), ### number of model parameter + Param = Param, ### parameter set + NStates = as.integer(length(RunOptions$IniStates)), ### number of state variables used for model initialising + 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 = 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; + RESULTS$Outputs[ round(RESULTS$Outputs ,3) == (-999.999)] <- NA; + RESULTS$StateEnd[round(RESULTS$StateEnd,3) == (-999.999)] <- NA; if (ExportStateEnd) { RESULTS$StateEnd[-3L] <- ifelse(RESULTS$StateEnd[-3L] < 0, 0, RESULTS$StateEnd[-3L]) ### remove negative values except for the ExpStore location RESULTS$StateEnd <- CreateIniStates(FUN_MOD = RunModel_GR5J, InputsModel = InputsModel, @@ -78,21 +78,21 @@ RunModel_GR5J <- function(InputsModel,RunOptions,Param) { ## Output_data_preparation ## OutputsModel_only - if (ExportDatesR==FALSE & ExportStateEnd==FALSE) { + 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 - if (ExportDatesR==TRUE & ExportStateEnd==FALSE) { + 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 - if (ExportDatesR==FALSE & ExportStateEnd==TRUE) { + 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) { + 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) ); diff --git a/R/RunModel_GR6J.R b/R/RunModel_GR6J.R index 19bdac9911b1bc0fe659c108a666053c781eb93a..9b98e18e01aaff1b2dec8ef0bb0fdf249bce998b 100644 --- a/R/RunModel_GR6J.R +++ b/R/RunModel_GR6J.R @@ -7,13 +7,13 @@ RunModel_GR6J <- function(InputsModel,RunOptions,Param) { ## 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' ") } - if (inherits(RunOptions,"RunOptions" )==FALSE) { stop("'RunOptions' must be of class 'RunOptions' ") } - if (inherits(RunOptions,"GR" )==FALSE) { stop("'RunOptions' must be of class 'GR' ") } + 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' ") } + if (inherits(RunOptions,"RunOptions" ) == FALSE) { stop("'RunOptions' must be of class 'RunOptions' ") } + if (inherits(RunOptions,"GR" ) == FALSE) { stop("'RunOptions' must be of class 'GR' ") } if (!is.vector(Param) | !is.numeric(Param)) { stop("'Param' must be a numeric vector") } - if (sum(!is.na(Param))!=NParam) { stop(paste("'Param' must be a vector of length ",NParam," and contain no NA",sep="")) } + if (sum(!is.na(Param))! = NParam) { stop(paste("'Param' must be a vector of length ",NParam," and contain no NA",sep = "")) } Param <- as.double(Param); Param_X1X3X6_threshold <- 1e-2 @@ -55,23 +55,23 @@ RunModel_GR6J <- function(InputsModel,RunOptions,Param) { } ## Call_fortan - RESULTS <- .Fortran("frun_gr6j",PACKAGE="airGR", + RESULTS <- .Fortran("frun_gr6j",PACKAGE = "airGR", ## 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] - NParam=as.integer(length(Param)), ### number of model parameter - Param=Param, ### parameter set - NStates=as.integer(length(RunOptions$IniStates)), ### number of state variables used for model initialising - 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 + 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] + NParam = as.integer(length(Param)), ### number of model parameter + Param = Param, ### parameter set + NStates = as.integer(length(RunOptions$IniStates)), ### number of state variables used for model initialising + 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 = 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; + RESULTS$Outputs[ round(RESULTS$Outputs ,3) == (-999.999)] <- NA; + RESULTS$StateEnd[round(RESULTS$StateEnd,3) == (-999.999)] <- NA; if (ExportStateEnd) { RESULTS$StateEnd[-3L] <- ifelse(RESULTS$StateEnd[-3L] < 0, 0, RESULTS$StateEnd[-3L]) ### remove negative values except for the ExpStore location RESULTS$StateEnd <- CreateIniStates(FUN_MOD = RunModel_GR6J, InputsModel = InputsModel, @@ -83,21 +83,21 @@ RunModel_GR6J <- function(InputsModel,RunOptions,Param) { ## Output_data_preparation ## OutputsModel_only - if (ExportDatesR==FALSE & ExportStateEnd==FALSE) { + 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 - if (ExportDatesR==TRUE & ExportStateEnd==FALSE) { + 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 - if (ExportDatesR==FALSE & ExportStateEnd==TRUE) { + 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) { + 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) );