@@ -48,16 +48,27 @@ matchBiomasses <- function(params, species = NULL) {
48
48
if (length(species ) == 0 ) {
49
49
return (params )
50
50
}
51
+
52
+ error_message <- " "
51
53
for (sp in seq_len(nrow(params @ species_params ))[species ]) {
52
54
cutoff <- params @ species_params $ biomass_cutoff [[sp ]]
53
55
if (is.null(cutoff ) || is.na(cutoff )) {
54
56
cutoff <- 0
55
57
}
56
58
total <- sum((params @ initial_n [sp , ] * params @ w * params @ dw )
57
59
[params @ w > = cutoff ])
60
+ if (! (total > 0 )) {
61
+ error_message <- paste(
62
+ error_message , params @ species_params $ species [[sp ]],
63
+ " does not grow up to the biomass_cutoff size of" ,
64
+ cutoff , " grams.\n " )
65
+ }
58
66
factor <- params @ species_params $ biomass_observed [[sp ]] / total
59
67
params @ initial_n [sp , ] <- params @ initial_n [sp , ] * factor
60
68
}
69
+ if (error_message != " " ) {
70
+ stop(error_message )
71
+ }
61
72
62
73
setBevertonHolt(params )
63
74
}
@@ -112,16 +123,30 @@ matchNumbers <- function(params, species = NULL) {
112
123
return .logical = TRUE ) &
113
124
! is.na(params @ species_params $ number_observed ) &
114
125
params @ species_params $ number_observed > 0
126
+ if (length(species ) == 0 ) {
127
+ return (params )
128
+ }
129
+
130
+ error_message <- " "
115
131
for (sp in seq_len(nrow(params @ species_params ))[species ]) {
116
132
cutoff <- params @ species_params $ number_cutoff [[sp ]]
117
133
if (is.null(cutoff ) || is.na(cutoff )) {
118
134
cutoff <- 0
119
135
}
120
136
total <- sum((params @ initial_n [sp , ] * params @ dw )
121
137
[params @ w > = cutoff ])
138
+ if (! (total > 0 )) {
139
+ error_message <- paste(
140
+ error_message , params @ species_params $ species [[sp ]],
141
+ " does not grow up to the biomass_cutoff size of" ,
142
+ cutoff , " grams.\n " )
143
+ }
122
144
factor <- params @ species_params $ number_observed [[sp ]] / total
123
145
params @ initial_n [sp , ] <- params @ initial_n [sp , ] * factor
124
146
}
147
+ if (error_message != " " ) {
148
+ stop(error_message )
149
+ }
125
150
126
151
setBevertonHolt(params )
127
152
}
0 commit comments