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

        protected EconomicRankTable ReadEconomicRankTable()
        {
            SpeciesLineNumbers.Clear();  // in case parser re-used

            InputVar <byte>   rank       = new InputVar <byte>("Economic Rank");
            InputVar <ushort> minAge     = new InputVar <ushort>("Minimum Age");
            string            lastColumn = "the " + minAge.Name + " column";

            EconomicRankTable table = new EconomicRankTable();

            while (!AtEndOfInput && !namesThatFollowRankingMethod.Contains(CurrentName))
            {
                StringReader currentLine = new StringReader(CurrentLine);

                //  Species name
                ISpecies species = ReadSpecies(currentLine);

                //  Economic rank
                ReadValue(rank, currentLine);
                const byte maxRank = 100;
                if (rank.Value.Actual > maxRank)
                {
                    throw new InputValueException(rank.Value.String,
                                                  "Economic rank must be between 0 and {0}",
                                                  maxRank);
                }

                //  Minimum age
                ReadValue(minAge, currentLine);
                CheckNoDataAfter(lastColumn, currentLine);

                table[species] = new EconomicRankParameters(rank.Value.Actual,
                                                            minAge.Value.Actual);
                GetNextLine();
            }

            if (SpeciesLineNumbers.Count == 0)
            {
                throw NewParseException("Expected a line starting with a species name");
            }

            return(table);
        }
Пример #2
0
        //----------------------------------------------------------------------

        protected void ReadForestTypeTable()
        {
            SpeciesLineNumbers.Clear();  // in case parser re-used

            int optionalStatements = 0;

            //check if this is the ForestTypeTable
            if (CurrentName == Names.ForestTypeTable)
            {
                ReadName(Names.ForestTypeTable);

                //fresh input variables for table
                InputVar <string> inclusionRule = new InputVar <string>("Inclusion Rule");
                //InputVar<ushort> minAge = new InputVar<ushort>("Min Age");
                //InputVar<ushort> maxAge = new InputVar<ushort>("Max Age");
                InputVar <AgeRange> age_range      = new InputVar <AgeRange>("Age Range");
                InputVar <string>   percentOfCells = new InputVar <string>("PercentOfCells"); //as a string so it can include keyword 'highest'
                InputVar <string>   speciesName    = new InputVar <string>("Species");


                //list for each rule- each line is a separate rule
                List <InclusionRule> rule_list = new List <InclusionRule>();
                //keep reading until no longer in the ForestTypeTable
                while (!AtEndOfInput && !namesThatFollowForestType.Contains(CurrentName))
                {
                    StringReader currentLine = new StringReader(CurrentLine);

                    //  inclusionRule column
                    ReadValue(inclusionRule, currentLine);

                    //verify inclusion rule = 'optional', 'required', or 'forbidden'
                    if (inclusionRule.Value.Actual != "Optional" && inclusionRule.Value.Actual != "Required" &&
                        inclusionRule.Value.Actual != "Forbidden")
                    {
                        string[] ic_list = new string[] { "Valid Inclusion Rules:",
                                                          "    Optional",
                                                          "    Required",
                                                          "    Forbidden" };
                        throw new InputValueException(CurrentName, CurrentName + " is not a valid inclusion rule.",
                                                      new MultiLineText(ic_list));
                    }

                    if (inclusionRule.Value.Actual == "Optional")
                    {
                        optionalStatements++;
                    }


                    TextReader.SkipWhitespace(currentLine);
                    ReadValue(age_range, currentLine);

                    //percentage column
                    TextReader.SkipWhitespace(currentLine);
                    ReadValue(percentOfCells, currentLine);
                    //Model.Core.UI.WriteLine("percentOfCells = {0}", percentOfCells.Value.String);
                    //cannot validate until parsing is done.  will do this in the inclusionRule constructor

                    //a list in case there are multiple species on this line
                    List <string> species_list = new List <string>();
                    //add each species to this rule's species list
                    TextReader.SkipWhitespace(currentLine);
                    while (currentLine.Peek() != -1)
                    {
                        //species column (build list)

                        ReadValue(speciesName, currentLine);
                        string name = speciesName.Value.String;

                        ISpecies species = GetSpecies(new InputValue <string>(name, speciesName.Value.String));
                        if (species_list.Contains(species.Name))
                        {
                            throw NewParseException("The species {0} appears more than once.", species.Name);
                        }
                        species_list.Add(species.Name);

                        //species_list.Add(species.Value.String);
                        TextReader.SkipWhitespace(currentLine);
                    }

                    //add this new inclusion rule (by parameters)  to the requirement
                    rule_list.Add(new InclusionRule(inclusionRule.Value.String,
                                                    age_range.Value.Actual,
                                                    percentOfCells.Value.String,
                                                    species_list));

                    GetNextLine();
                }
                //create a new requirement with this list of rules
                IRequirement inclusionRequirement = new InclusionRequirement(rule_list);
                //add this requirement to the ranking method
                rankingMethod.AddRequirement(inclusionRequirement);
            }

            if (optionalStatements > 0 && optionalStatements < 2)
            {
                throw new InputValueException(CurrentName, "If there are optional statements, there must be more than one",
                                              "ForestTypeTable");
            }
        }