1818# '@export
1919rpath <- function (Rpath.params , eco.name = NA , eco.area = 1 ) {
2020 # Need to define variables to eliminate check() note about no visible binding
21- Type <- Group <- DetInput <- ProdCons <- PB <- QB <- noB <- noEE <- alive <- NULL
21+ Type <- Group <- DetInput <- ProdCons <- PB <- QB <- noB <- noEE <- alive <- noPB <- NULL
2222 BEE <- Biomass <- Q <- BioAcc <- BioQB <- diag.a <- EEa <- B <- M0 <- NULL
2323 QBloss <- Unassim <- Ex <- NULL
2424
@@ -99,11 +99,13 @@ rpath <- function(Rpath.params, eco.name = NA, eco.area = 1) {
9999 model [, noEE : = 0 ]
100100 model [, alive : = 0 ]
101101 model [, BEE : = 0 ]
102+ model [, noPB : = 0 ]
102103 model [is.na(Biomass ), noB : = 1 ]
103104 model [is.na(EE ), noEE : = 1 ]
104105 model [Type < 2 , alive : = 1 ]
105- model [noB == 0 & noEE == 0 , BEE : = 1 ]
106-
106+ model [noB == 0 & noEE == 0 , BEE : = 1 ]
107+ model [BEE == 1 & is.na(PB ), noPB : = 1 ]
108+
107109 # define detritus fate matrix
108110 detfate <- model [, (10 + 1 ): (10 + ndead ), with = F ]
109111 detdetfate <- model [Type == 2 , (10 + 1 ): (10 + ndead ), with = F ]
@@ -120,6 +122,7 @@ rpath <- function(Rpath.params, eco.name = NA, eco.area = 1) {
120122 # Set up A matrix
121123 living [noEE == 1 , diag.a : = Biomass * PB ]
122124 living [noEE == 0 , diag.a : = PB * EE ]
125+ living [noPB == 1 , diag.a : = Biomass * EE ] # this needs to be after noEE==0 case
123126
124127 # Special case where B and EE are known then need to solve for BA
125128 # living[BEE == 1, b := b - (Biomass * PB * EE)]
@@ -148,6 +151,9 @@ rpath <- function(Rpath.params, eco.name = NA, eco.area = 1) {
148151 living [, B : = x * noB ]
149152 living [is.na(Biomass ), Biomass : = B ]
150153
154+ living [, PBa : = x * noPB ]
155+ living [is.na(PB ), PB : = PBa ]
156+
151157 # detritus EE calcs
152158 living [, M0 : = PB * (1 - EE )]
153159 living [, QBloss : = QB ]
@@ -184,7 +190,7 @@ rpath <- function(Rpath.params, eco.name = NA, eco.area = 1) {
184190 inDetB <- model [(nliving + 1 ): (nliving + ndead ), Biomass ]
185191 DetPB <- ifelse(is.na(inDetPB ), Default_Detrital_PB , inDetPB )
186192 DetB <- ifelse(is.na(inDetB ), detinputs / DetPB , inDetB )
187- DetPB <- detinputs / DetB
193+ DetPB <- as.numeric( detinputs ) / DetB
188194
189195 # Trophic Level calcs
190196 b <- rep(1 , ngroups )
@@ -219,16 +225,18 @@ rpath <- function(Rpath.params, eco.name = NA, eco.area = 1) {
219225 # to match header file format (replacing NAs with 0.0s)
220226 Bplus <- c(living [, Biomass ], DetB , rep(0.0 , ngear ))
221227
222- PBplus <- model [, PB ]
223- PBplus [(nliving + 1 ): (nliving + ndead )] <- DetPB
228+ # PBplus <- model[, PB]
229+ # PBplus[(nliving + 1):(nliving + ndead)] <- DetPB
230+ PBplus <- c(living [,PB ],DetPB , rep(0.0 , ngear ))
224231 PBplus [is.na(PBplus )] <- 0.0
225232
226233 EEplus <- c(EE , rep(0.0 , ngear ))
227234
228235 QBplus <- model [, QB ]
229236 QBplus [is.na(QBplus )] <- 0.0
230237
231- GE [is.na(GE )] <- 0.0
238+ GE <- PBplus / QBplus
239+ GE [is.na(GE ) | is.nan(GE ) | is.infinite(GE )] <- 0.0
232240
233241 RemPlus <- model [, totcatch ]
234242 RemPlus [is.na(RemPlus )] <- 0.0
0 commit comments