Inheritance: Landis.Library.Harvest.AgeCohortHarvest, IChange
示例#1
0
        LandCover.IChange ProcessLandCoverChange(InputVar <string> landCoverChangeType)
        {
            InputVar <bool> repeatableHarvest = new InputVar <bool>("RepeatHarvest?");
            bool            repeatHarvest     = false;

            if (ReadOptionalVar(repeatableHarvest))
            {
                repeatHarvest = repeatableHarvest.Value.Actual;
            }
            LandCover.IChange landCoverChange = null;
            if (landCoverChangeType.Value.Actual == LandCover.NoChange.TypeName)
            {
                landCoverChange = noLandCoverChange;
            }
            else if (landCoverChangeType.Value.Actual == LandCover.RemoveTrees.TypeName)
            {
                LandCover.LandCover.DontParseTrees = true;
                PartialThinning.CohortSelectors.Clear();    //Clear static storage selector to prevent writing across land uses
                InputValues.Register <AgeRange>(PartialThinning.ReadAgeOrRange);
                ICohortSelector selector = selector = ReadSpeciesAndCohorts("LandUse",
                                                                            ParameterNames.Plant,
                                                                            "Tony Bonanza",
                                                                            "LandCoverChange");
                ICohortCutter cohortCutter = CohortCutterFactory.CreateCutter(selector,
                                                                              Main.ExtType);
                Planting.SpeciesList speciesToPlant = ReadSpeciesToPlant();

                landCoverChange = new LandCover.RemoveTrees(cohortCutter, speciesToPlant, repeatHarvest);
                PartialThinning.CohortSelectors.Clear();    //Prevent interactions with Biomass Harvest
                LandCover.LandCover.DontParseTrees = false;
            }
            else if (landCoverChangeType.Value.Actual == LandCover.InsectDefoliation.TypeName)
            {
                //Insects will reduce biomass of cohorts rather than directly affecting demographics
                InputValues.Register <AgeRange>(LandCover.LandCover.ReadAgeOrRange);
                ICohortSelector selector = ReadSpeciesAndCohorts("LandUse",
                                                                 ParameterNames.Plant,
                                                                 "Vito Tortellini",
                                                                 "LandCoverChange");
                Planting.SpeciesList speciesToPlant = ReadSpeciesToPlant();
                landCoverChange = new LandCover.InsectDefoliation(LandCover.LandCover.CohortSelectors, speciesToPlant, repeatHarvest);
                LandCover.LandCover.CohortSelectors.Clear();    //Clear static storage selector to prevent writing across land uses
            }
            else
            {
                throw new InputValueException(landCoverChangeType.Value.String,
                                              "\"{0}\" is not a type of land cover change",
                                              landCoverChangeType.Value.Actual);
            }
            //landCoverChange.PrintLandCoverDetails();
            return(landCoverChange);
        }
        //---------------------------------------------------------------------

        protected void ReadLandUses()
        {
            InputVar <string> name                = new InputVar <string>("LandUse");
            InputVar <ushort> mapCode             = new InputVar <ushort>("MapCode");
            InputVar <bool>   allowHarvest        = new InputVar <bool>("AllowHarvest?");
            InputVar <string> landCoverChangeType = new InputVar <string>("LandCoverChange");

            Dictionary <string, int> nameLineNumbers    = new Dictionary <string, int>();
            Dictionary <ushort, int> mapCodeLineNumbers = new Dictionary <ushort, int>();

            while (!AtEndOfInput)
            {
                int nameLineNum = LineNumber;
                ReadVar(name);
                int lineNumber;
                if (nameLineNumbers.TryGetValue(name.Value.Actual, out lineNumber))
                {
                    throw new InputValueException(name.Value.String,
                                                  "The land use \"{0}\" was previously used on line {1}",
                                                  name.Value.Actual, lineNumber);
                }
                else
                {
                    nameLineNumbers[name.Value.Actual] = nameLineNum;
                }

                int mapCodeLineNum = LineNumber;
                ReadVar(mapCode);
                if (mapCodeLineNumbers.TryGetValue(mapCode.Value.Actual, out lineNumber))
                {
                    throw new InputValueException(mapCode.Value.String,
                                                  "The map code \"{0}\" was previously used on line {1}",
                                                  mapCode.Value.Actual, lineNumber);
                }
                else
                {
                    mapCodeLineNumbers[mapCode.Value.Actual] = mapCodeLineNum;
                }

                ReadVar(allowHarvest);

                // By default, a land use allows trees to establish.
                bool allowEstablishment = true;

                ReadVar(landCoverChangeType);
                LandCover.IChange landCoverChange = null;
                if (landCoverChangeType.Value.Actual == LandCover.NoChange.TypeName)
                {
                    landCoverChange = noLandCoverChange;
                }
                else if (landCoverChangeType.Value.Actual == LandCover.RemoveTrees.TypeName)
                {
                    ICohortSelector selector = ReadSpeciesAndCohorts("LandUse",
                                                                     ParameterNames.Plant,
                                                                     ParameterNames.PreventEstablishment);
                    ICohortCutter cohortCutter = CohortCutterFactory.CreateCutter(selector,
                                                                                  Main.ExtType);
                    Planting.SpeciesList speciesToPlant = ReadSpeciesToPlant();
                    landCoverChange = new LandCover.RemoveTrees(cohortCutter, speciesToPlant);

                    if (ReadPreventEstablishment())
                    {
                        allowEstablishment = false;
                    }
                }
                else
                {
                    throw new InputValueException(landCoverChangeType.Value.String,
                                                  "\"{0}\" is not a type of land cover change",
                                                  landCoverChangeType.Value.Actual);
                }

                LandUse landUse = new LandUse(name.Value.Actual,
                                              mapCode.Value.Actual,
                                              allowHarvest.Value.Actual,
                                              allowEstablishment,
                                              landCoverChange);
                LandUseRegistry.Register(landUse);
            }
        }