Пример #1
0
        //---------------------------------------------------------------------

        private void ReadPlugIn(out IEditablePlugIn <IDisturbance> disturbPlugIn,
                                out IEditablePlugIn <IOutput> outputPlugIn)
        {
            disturbPlugIn = null;
            outputPlugIn  = null;

            StringReader currentLine = new StringReader(CurrentLine);
            InputValue <Edu.Wisc.Forest.Flel.Util.PlugIns.Info> plugInInfo = ReadPlugInName(currentLine);

            if (plugInInfo.Actual.InterfaceType == typeof(IDisturbance))
            {
                CheckForRepeatedName(plugInInfo.Actual.Name);
                disturbPlugIn      = new EditablePlugIn <IDisturbance>();
                disturbPlugIn.Info = plugInInfo;
                ReadInitFile(disturbPlugIn, currentLine);
            }
            else if (plugInInfo.Actual.InterfaceType == typeof(IOutput))
            {
                nameLineNumbers.Clear();
                CheckForRepeatedName(plugInInfo.Actual.Name);
                outputPlugIn      = new EditablePlugIn <IOutput>();
                outputPlugIn.Info = plugInInfo;
                ReadInitFile(outputPlugIn, currentLine);
            }
            else
            {
                throw new InputValueException(plugInInfo.String,
                                              "\"{0}\" is not a disturbance or output plug-in.",
                                              plugInInfo.Actual.Name);
            }
            GetNextLine();
        }
        //---------------------------------------------------------------------

        private void ReadInitFile(EditablePlugIn plugIn,
                                  StringReader currentLine)
        {
            InputVar <string> initFile = new InputVar <string>("InitializationFile");

            ReadValue(initFile, currentLine);
            plugIn.InitFile = initFile.Value;

            CheckNoDataAfter("the " + initFile.Name + " column",
                             currentLine);
        }
        //---------------------------------------------------------------------

        private void ReadPlugIn(EditablePlugIn plugIn,
                                ValidPlugInTypes validTypes)
        {
            StringReader currentLine = new StringReader(CurrentLine);

            plugIn.Info = ReadPlugInName(currentLine);

            string error = null;

            switch (validTypes)
            {
            case ValidPlugInTypes.SuccessionOnly:
                if (!plugIn.Info.Actual.PlugInType.IsMemberOf("succession"))
                {
                    error = "is not a succession plug-in";
                }
                break;

            case ValidPlugInTypes.AnyButSuccession:
                if (plugIn.Info.Actual.PlugInType.IsMemberOf("succession"))
                {
                    error = "is a succession plug-in";
                }
                break;

            case ValidPlugInTypes.AnyButSuccessionOrDisturbance:
                if (plugIn.Info.Actual.PlugInType.IsMemberOf("succession"))
                {
                    error = "is a succession plug-in";
                }
                if (plugIn.Info.Actual.PlugInType.IsMemberOf("disturbance"))
                {
                    error = "is a disturbance plug-in";
                }
                break;

            default:
                throw new ArgumentException("Unknown value for parameter \"allowedTypes\"");
            }
            if (error != null)
            {
                throw new InputValueException(plugIn.Info.Actual.Name,
                                              "\"{0}\" {1}",
                                              plugIn.Info.Actual.Name,
                                              error);
            }
            CheckForRepeatedName(plugIn.Info.Actual.Name);
            ReadInitFile(plugIn, currentLine);
            GetNextLine();
        }
Пример #4
0
        //---------------------------------------------------------------------

        protected override IScenario Parse()
        {
            ReadLandisDataVar();

            IEditableScenario scenario = new EditableScenario();

            InputVar <int> duration = new InputVar <int>("Duration");

            ReadVar(duration);
            scenario.Duration = duration.Value;

            InputVar <string> species = new InputVar <string>("Species");

            ReadVar(species);
            scenario.Species = species.Value;

            InputVar <string> ecoregions = new InputVar <string>("Ecoregions");

            ReadVar(ecoregions);
            scenario.Ecoregions = ecoregions.Value;

            InputVar <string> ecoregionsMap = new InputVar <string>("EcoregionsMap");

            ReadVar(ecoregionsMap);
            scenario.EcoregionsMap = ecoregionsMap.Value;

            InputVar <float> cellLength = new InputVar <float>("CellLength");

            if (ReadOptionalVar(cellLength))
            {
                scenario.CellLength = cellLength.Value;
            }

            InputVar <string> initCommunities = new InputVar <string>("InitialCommunities");

            ReadVar(initCommunities);
            scenario.InitialCommunities = initCommunities.Value;

            InputVar <string> communitiesMap = new InputVar <string>("InitialCommunitiesMap");

            ReadVar(communitiesMap);
            scenario.InitialCommunitiesMap = communitiesMap.Value;

            if (AtEndOfInput)
            {
                throw ExpectedPlugInException(typeof(ISuccession));
            }
            ReadPlugIn(scenario.Succession);

            //  Disturbance plug-ins

            nameLineNumbers.Clear();  // Parse called more than once
            const string DisturbancesRandomOrder = "DisturbancesRandomOrder";
            const string RandomNumberSeed        = "RandomNumberSeed";

            while (!AtEndOfInput && CurrentName != DisturbancesRandomOrder &&
                   CurrentName != RandomNumberSeed &&
                   scenario.Outputs.Count == 0)
            {
                IEditablePlugIn <IDisturbance> disturbPlugIn;
                IEditablePlugIn <IOutput>      outputPlugIn;
                ReadPlugIn(out disturbPlugIn, out outputPlugIn);
                if (disturbPlugIn != null)
                {
                    scenario.Disturbances.InsertAt(scenario.Disturbances.Count,
                                                   disturbPlugIn);
                }
                else
                {
                    scenario.Outputs.InsertAt(scenario.Outputs.Count,
                                              outputPlugIn);
                }
            }

            //  Check for optional DisturbancesRandomOrder parameter
            InputVar <bool> randomOrder = new InputVar <bool>(DisturbancesRandomOrder);

            if (ReadOptionalVar(randomOrder))
            {
                scenario.DisturbancesRandomOrder = randomOrder.Value;
            }

            //  Output plug-ins

            if (scenario.Outputs.Count == 0)
            {
                nameLineNumbers.Clear();
            }
            while (!AtEndOfInput && CurrentName != RandomNumberSeed)
            {
                IEditablePlugIn <IOutput> plugIn = new EditablePlugIn <IOutput>();
                ReadPlugIn(plugIn);
                scenario.Outputs.InsertAt(scenario.Outputs.Count, plugIn);
            }
            if (scenario.Outputs.Count == 0)
            {
                throw ExpectedPlugInException(typeof(IOutput));
            }

            //	Either at end of file or we've encountered the optional
            //	RandomNumberSeed parameter.
            if (!AtEndOfInput)
            {
                InputVar <uint> seed = new InputVar <uint>(RandomNumberSeed);
                ReadVar(seed);
                scenario.RandomNumberSeed = seed.Value;
                CheckNoDataAfter(string.Format("the {0} parameter", RandomNumberSeed));
            }

            return(scenario.GetComplete());
        }
        //---------------------------------------------------------------------

        protected override Scenario Parse()
        {
            ReadLandisDataVar();

            EditableScenario scenario = new EditableScenario();

            scenario.StartTime = new InputValue <int>(0, "0");

            InputVar <int> duration = new InputVar <int>("Duration");

            ReadVar(duration);
            scenario.EndTime = duration.Value;

            InputVar <string> species = new InputVar <string>("Species");

            ReadVar(species);
            scenario.Species = species.Value;

            InputVar <string> ecoregions = new InputVar <string>("Ecoregions");

            ReadVar(ecoregions);
            scenario.Ecoregions = ecoregions.Value;

            InputVar <string> ecoregionsMap = new InputVar <string>("EcoregionsMap");

            ReadVar(ecoregionsMap);
            scenario.EcoregionsMap = ecoregionsMap.Value;

            InputVar <float> cellLength = new InputVar <float>("CellLength");

            if (ReadOptionalVar(cellLength))
            {
                scenario.CellLength = cellLength.Value;
            }

            InputVar <string> initCommunities = new InputVar <string>("InitialCommunities");

            ReadVar(initCommunities);
            scenario.InitialCommunities = initCommunities.Value;

            InputVar <string> communitiesMap = new InputVar <string>("InitialCommunitiesMap");

            ReadVar(communitiesMap);
            scenario.InitialCommunitiesMap = communitiesMap.Value;

            //  Table of plug-ins
            nameLineNumbers.Clear();  // if Parse called more than once

            //  Succession plug-in must be first entry in table
            if (AtEndOfInput)
            {
                throw NewParseException("Expected a succession plug-in");
            }
            ReadPlugIn(scenario.Succession, ValidPlugInTypes.SuccessionOnly);

            //  0 or more disturbance plug-ins

            const string DisturbancesRandomOrder = "DisturbancesRandomOrder";
            const string RandomNumberSeed        = "RandomNumberSeed";

            while (!AtEndOfInput && CurrentName != DisturbancesRandomOrder &&
                   CurrentName != RandomNumberSeed &&
                   scenario.OtherPlugIns.Count == 0)
            {
                EditablePlugIn plugIn = new EditablePlugIn();
                ReadPlugIn(plugIn, ValidPlugInTypes.AnyButSuccession);
                if (plugIn.Info.Actual.PlugInType.IsMemberOf("disturbance"))
                {
                    scenario.Disturbances.Add(plugIn);
                }
                else
                {
                    scenario.OtherPlugIns.Add(plugIn);
                }
            }

            //  Check for optional DisturbancesRandomOrder parameter
            InputVar <bool> randomOrder = new InputVar <bool>(DisturbancesRandomOrder);

            if (ReadOptionalVar(randomOrder))
            {
                scenario.DisturbancesRandomOrder = randomOrder.Value;
            }

            //  All other plug-ins besides succession and disturbances (e.g.,
            //  output, metapopulation)

            if (scenario.OtherPlugIns.Count == 0)
            {
                nameLineNumbers.Clear();
            }
            while (!AtEndOfInput && CurrentName != RandomNumberSeed)
            {
                EditablePlugIn plugIn = new EditablePlugIn();
                ReadPlugIn(plugIn, ValidPlugInTypes.AnyButSuccessionOrDisturbance);
                scenario.OtherPlugIns.Add(plugIn);
            }

            //    Either at end of file or we've encountered the optional
            //    RandomNumberSeed parameter.
            if (!AtEndOfInput)
            {
                InputVar <uint> seed = new InputVar <uint>(RandomNumberSeed);
                ReadVar(seed);
                scenario.RandomNumberSeed = seed.Value;
                CheckNoDataAfter(string.Format("the {0} parameter", RandomNumberSeed));
            }

            return(scenario.GetComplete());
        }
        //---------------------------------------------------------------------

        public EditableScenario()
        {
            this.succession   = new EditablePlugIn <ISuccession>();
            this.disturbances = new EditablePlugInList <IDisturbance>();
            this.outputs      = new EditablePlugInList <IOutput>();
        }
Пример #7
0
        //---------------------------------------------------------------------

        public EditableScenario()
        {
            this.succession   = new EditablePlugIn();
            this.disturbances = new EditablePlugInList();
            this.otherPlugIns = new EditablePlugInList();
        }
        //---------------------------------------------------------------------

        protected override IScenario Parse()
        {
            ReadLandisDataVar();

            IEditableScenario scenario = new EditableScenario();

            InputVar <int> duration = new InputVar <int>("Duration");

            ReadVar(duration);
            scenario.Duration = duration.Value;

            InputVar <string> species = new InputVar <string>("Species");

            ReadVar(species);
            scenario.Species = species.Value;

            InputVar <string> ecoregions = new InputVar <string>("Ecoregions");

            ReadVar(ecoregions);
            scenario.Ecoregions = ecoregions.Value;

            InputVar <string> ecoregionsMap = new InputVar <string>("EcoregionsMap");

            ReadVar(ecoregionsMap);
            scenario.EcoregionsMap = ecoregionsMap.Value;

            InputVar <string> initCommunities = new InputVar <string>("InitialCommunities");

            ReadVar(initCommunities);
            scenario.InitialCommunities = initCommunities.Value;

            InputVar <string> communitiesMap = new InputVar <string>("InitialCommunitiesMap");

            ReadVar(communitiesMap);
            scenario.InitialCommunitiesMap = communitiesMap.Value;

            if (AtEndOfInput)
            {
                throw ExpectedPlugInException(typeof(ISuccession));
            }
            ReadPlugIn(scenario.Succession);

            //  Disturbance plug-ins

            nameLineNumbers.Clear();  // Parse called more than once
            const string DisturbancesRandomOrder = "DisturbancesRandomOrder";

            while (!AtEndOfInput && CurrentName != DisturbancesRandomOrder &&
                   scenario.Outputs.Count == 0)
            {
                IEditablePlugIn <IDisturbance> disturbPlugIn;
                IEditablePlugIn <IOutput>      outputPlugIn;
                ReadPlugIn(out disturbPlugIn, out outputPlugIn);
                if (disturbPlugIn != null)
                {
                    scenario.Disturbances.InsertAt(scenario.Disturbances.Count,
                                                   disturbPlugIn);
                }
                else
                {
                    scenario.Outputs.InsertAt(scenario.Outputs.Count,
                                              outputPlugIn);
                }
            }

            //  Check for optional DisturbancesRandomOrder parameter
            InputVar <bool> randomOrder = new InputVar <bool>(DisturbancesRandomOrder);

            if (ReadOptionalVar(randomOrder))
            {
                scenario.DisturbancesRandomOrder = randomOrder.Value;
            }

            //  Output plug-ins

            if (scenario.Outputs.Count == 0)
            {
                nameLineNumbers.Clear();
            }
            while (!AtEndOfInput)
            {
                IEditablePlugIn <IOutput> plugIn = new EditablePlugIn <IOutput>();
                ReadPlugIn(plugIn);
                scenario.Outputs.InsertAt(scenario.Outputs.Count, plugIn);
            }
            if (scenario.Outputs.Count == 0)
            {
                throw ExpectedPlugInException(typeof(IOutput));
            }

            return(scenario.GetComplete());
        }