From dbc4e94b55151bd1983b37d3537afb43b515944b Mon Sep 17 00:00:00 2001
From: Marco Matthies <71844+marcom@users.noreply.github.com>
Date: Mon, 28 Oct 2024 11:58:34 +0100
Subject: [PATCH] ALMaSS: fix logic when choosing low or high nutrient growth
 curves

Previously, we chose the lownutrientgrowth curve when the was a
`fertiliser` event for the cropstate, otherwise the highnutrientgrowth
curve.

It should be the other way around.
---
 src/crop/almass.jl | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/crop/almass.jl b/src/crop/almass.jl
index 1903cbb..25d6c4d 100644
--- a/src/crop/almass.jl
+++ b/src/crop/almass.jl
@@ -599,8 +599,17 @@ end
 get_dddegs(model::SimulationModel) = bounds(supply_temperature(model))
 
 # TODO efficiency: the fertiliser check is done in many places
-growthcurve(cs::CropState) =
-    fertiliser in cs.events ? cs.croptype.lownutrientgrowth : cs.croptype.highnutrientgrowth
+function growthcurve(cs::CropState)
+    curve = if fertiliser in cs.events
+        cs.croptype.highnutrientgrowth
+    else
+        cs.croptype.lownutrientgrowth
+    end
+    if ismissing(curve)
+        error("Growth curve is missing for cropstate:\n $cs")
+    end
+    return curve
+end
 
 # Function in original ALMaSS code:
 #     `double PlantGrowthData::GetStartValue(int a_veg_type, int a_phase, int a_type)` in `Landscape/Plants.h`, line 142
-- 
GitLab