Skip to content
Snippets Groups Projects
Commit 6a7aa4b2 authored by Marco Matthies's avatar Marco Matthies
Browse files

Introduce initcropmodel, initfields! functions for switchable crop models

parent 0332362a
No related branches found
No related tags found
No related merge requests found
......@@ -144,6 +144,7 @@ include("world/landscape.jl")
include("world/weather.jl")
include("crop/farmplot.jl")
include("crop/cropmodels.jl")
include("crop/almass.jl")
include("crop/simplecrop.jl")
......
......@@ -117,23 +117,9 @@ function initmodel(settings::Dict{String, Any})
settings["world.weatherfile"]),
settings["core.startdate"],
settings["core.enddate"])
# TODO: make this switching on cropmodel simpler
if settings["crop.cropmodel"] == "almass"
Tcroptype = ALMaSS.CropType
Tcropstate = ALMaSS.CropState
crops = ALMaSS.readcropparameters(settings["crop.cropfile"],
settings["crop.growthfile"])
elseif settings["crop.cropmodel"] == "simple"
Tcroptype = SimpleCrop.CropType
Tcropstate = SimpleCrop.CropState
crops_almass = ALMaSS.readcropparameters(settings["crop.cropfile"],
crops, Tcroptype, Tcropstate = initcropmodel(settings["crop.cropmodel"],
settings["crop.cropfile"],
settings["crop.growthfile"])
crops = Dict(name => SimpleCrop.CropType(ct.name) for (name, ct) in crops_almass)
else
error("Init for crop model \"$(settings["crop.cropmodel"])\" not implemented")
end
farmers = Vector{Farmer}()
farmplots = Vector{FarmPlot{Tcropstate}}()
model = AgricultureModel{Tcroptype,Tcropstate}(
......@@ -154,14 +140,7 @@ function initmodel(settings::Dict{String, Any})
)
saveinputfiles(model)
if settings["crop.cropmodel"] == "almass"
ALMaSS.initfields!(model)
elseif settings["crop.cropmodel"] == "simple"
SimpleCrop.initfields!(model)
else
error("initfields! for crop model \"$(settings["crop.cropmodel"])\" not implemented")
end
initfields!(model, settings["crop.cropmodel"])
initfarms!(model)
initnature!(model)
model
......
### Persefone.jl - a model of agricultural landscapes and ecosystems in Europe.
###
### Crop model helper functions.
###
function initcropmodel(cropmodel::AbstractString, cropfile::AbstractString, growthfile::AbstractString)
if cropmodel == "almass"
Tcroptype = ALMaSS.CropType
Tcropstate = ALMaSS.CropState
crops = ALMaSS.readcropparameters(cropfile, growthfile)
elseif cropmodel == "simple"
Tcroptype = SimpleCrop.CropType
Tcropstate = SimpleCrop.CropState
crops_almass = ALMaSS.readcropparameters(cropfile, growthfile)
crops = Dict(name => SimpleCrop.CropType(ct.name) for (name, ct) in crops_almass)
else
error("initcropmodel: no implementation for crop model '$cropmodel'")
end
return crops, Tcroptype, Tcropstate
end
function initfields!(model::SimulationModel, cropmodel::AbstractString)
if cropmodel == "almass"
ALMaSS.initfields!(model)
elseif cropmodel == "simple"
SimpleCrop.initfields!(model)
else
error("initfields! for crop model '$cropmodel'")
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment