diff --git a/src/crop/almass.jl b/src/crop/almass.jl index e2f4e99180eeceff2d7c3703512990929e97de7f..3c735a2ab2ae46e70e31934b81ae5560ec1266ce 100644 --- a/src/crop/almass.jl +++ b/src/crop/almass.jl @@ -67,7 +67,6 @@ function Base.show(io::IO, ::MIME"text/plain", curve::CropCurveParams) (curve.GDD, "GDD"), (curve.LAItotal, "LAItotal"), (curve.LAIgreen, "LAIgreen"), - # (curve.height, "height"), ] println(" $name:") for (phase, arr) in dict @@ -333,8 +332,9 @@ function growcrop!(cs::CropState, delta_gdd::Real, model::SimulationModel) error("Missing curve") end points = curve.GDD[cs.phase] + if length(points) == 1 && points[1] == 99999.0 - !(cs.phase in (janfirst, sow)) && (cs.mature = true) #FIXME only in the last phase? + !(cs.phase in (janfirst, sow)) && (cs.mature = true) # FIXME only in the last phase? return # the marker that there is no further growth this phase end @@ -344,14 +344,25 @@ function growcrop!(cs::CropState, delta_gdd::Real, model::SimulationModel) idx = findfirst(x -> x > total_gdd, points) if isnothing(idx) idx = lastindex(points) - # elseif idx != firstindex(points) - # idx -= 1 # we need the last index that is not > total_gdd + elseif idx != firstindex(points) + idx -= 1 # we need the last index that is smaller than total_gdd end cs.height += curve.height[cs.phase][idx] * delta_gdd cs.LAItotal += curve.LAItotal[cs.phase][idx] * delta_gdd cs.LAIgreen += curve.LAIgreen[cs.phase][idx] * delta_gdd - #if cs.phase == janfirst && length(points + function lastphase(cs::CropState) + if cs.croptype.name == "maize" + return sow + else + return marchfirst + end + end + + # set mature if it's the last growth point of the last phase + if idx == lastindex(points) && cs.phase == lastphase(cs) + cs.mature = true + end end end # module ALMaSS