示例#1
0
        //---------------------------------------------------------------------

        private void CheckPercentageTable(string tableName,
                                          IPercentageTable table,
                                          string nextTableName)
        {
            inputLine.MatchName(tableName);
            bool haveLine = inputLine.GetNext();

            while (haveLine && inputLine.VariableName != nextTableName)
            {
                StringReader currentLine = new StringReader(inputLine.ToString());
                string       disturbance = ReadInputValue <string>(currentLine);

                PlugInType disturbanceType;
                if (disturbance == "(default)")
                {
                    disturbanceType = new PlugInType(disturbance);
                }
                else
                {
                    disturbanceType = new PlugInType("disturbance:" + disturbance);
                }

                PoolPercentages percentages = table[disturbanceType];
                Assert.AreEqual((double)percentages.Woody,
                                (double)ReadInputValue <Percentage>(currentLine));
                Assert.AreEqual((double)percentages.NonWoody,
                                (double)ReadInputValue <Percentage>(currentLine));

                haveLine = inputLine.GetNext();
            }
        }
示例#2
0
        //---------------------------------------------------------------------

        private void ParseTable(IPercentageTable table,
                                string tableName,
                                string nextTableName)
        {
            ReadName(tableName);

            PlugIn.ModelCore.UI.WriteLine("   Age-only-disturbances:  reading {0}.", tableName);

            InputVar <string>     disturbance      = new InputVar <string>("Disturbance");
            InputVar <Percentage> woodPercentage   = new InputVar <Percentage>("Woody");
            InputVar <Percentage> foliarPercentage = new InputVar <Percentage>("Non-Woody");
            string lastColumn = "the " + foliarPercentage.Name + " column";

            const string defaultName  = "(default)";
            bool         defaultFound = false;

            lineNums.Clear();
            while (!AtEndOfInput && CurrentName != nextTableName)
            {
                StringReader currentLine = new StringReader(CurrentLine);

                ReadValue(disturbance, currentLine);
                int lineNum;
                if (lineNums.TryGetValue(disturbance.Value.Actual, out lineNum))
                {
                    throw new InputValueException(disturbance.Value.Actual,
                                                  "The value \"{0}\" was previously used on line {1}",
                                                  disturbance.Value.Actual,
                                                  lineNum);
                }
                lineNums[disturbance.Value.String] = LineNumber;

                PoolPercentages percentages;
                if (disturbance.Value.Actual == defaultName)
                {
                    defaultFound = true;
                    percentages  = table.Default;
                }
                else
                {
                    ExtensionType disturbanceType = new ExtensionType("disturbance:" + disturbance.Value.Actual);

                    if (disturbance.Value.Actual == "Fire")
                    {
                        throw new InputValueException(disturbance.Value.Actual,
                                                      "\"{0}\" is not an allowable disturbance type, line {1}",
                                                      disturbance.Value.Actual,
                                                      lineNum);
                    }

                    percentages = table[disturbanceType];
                }

                ReadValue(woodPercentage, currentLine);
                percentages.Wood = woodPercentage.Value;

                ReadValue(foliarPercentage, currentLine);
                percentages.Foliar = foliarPercentage.Value;

                CheckNoDataAfter(lastColumn, currentLine);
                GetNextLine();
            }

            if (!defaultFound)
            {
                throw NewParseException("Missing the \"{0}\" row in the percentage table",
                                        defaultName);
            }
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance.
        /// </summary>

/*        public ParameterDataset(IPercentageTable cohortReductions,
 *                              IPercentageTable poolReductions)
 *      {
 *          this.cohortReductions = cohortReductions;
 *          this.poolReductions = poolReductions;
 *      }*/
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        public ParameterDataset()
        {
            cohortReductions = new PercentageTable();
            poolReductions   = new PercentageTable();
        }
 //---------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /*        public ParameterDataset(IPercentageTable cohortReductions,
                         IPercentageTable poolReductions)
 {
     this.cohortReductions = cohortReductions;
     this.poolReductions = poolReductions;
 }*/
 //---------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 public ParameterDataset()
 {
     cohortReductions = new PercentageTable();
     poolReductions = new PercentageTable();
 }
 //---------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 public ParameterDataset(IPercentageTable cohortReductions,
     IPercentageTable poolReductions)
 {
     this.cohortReductions = cohortReductions;
     this.poolReductions = poolReductions;
 }