Exemplo n.º 1
0
        //---------------------------------------------------------------------

        private void CompareDatasetAndFile(IDataset dataset,
                                           string filename)
        {
            FileLineReader file      = OpenFile(filename);
            InputLine      inputLine = new InputLine(file);

            InputVar <string> LandisData = new InputVar <string>(Landis.Data.InputVarName);

            inputLine.ReadVar(LandisData);

            int expectedIndex = 0;

            foreach (IEcoregion ecoregion in dataset)
            {
                Assert.AreEqual(expectedIndex, ecoregion.Index);
                expectedIndex++;

                Assert.IsTrue(inputLine.GetNext());
                currentLine = new StringReader(inputLine.ToString());

                Assert.AreEqual(ReadValue <bool>(), ecoregion.Active);
                Assert.AreEqual(ReadValue <byte>(), ecoregion.MapCode);
                Assert.AreEqual(ReadValue <string>(), ecoregion.Name);
                Assert.AreEqual(ReadValue <string>(), ecoregion.Description);
            }
            Assert.IsFalse(inputLine.GetNext());
            file.Close();
        }
Exemplo n.º 2
0
        //---------------------------------------------------------------------

        private void CompareDatasetAndFile(ISpeciesDataset dataset,
                                           string filename)
        {
            FileLineReader file      = OpenFile(filename);
            InputLine      inputLine = new InputLine(file);

            InputVar <string> LandisData = new InputVar <string>(Landis.Data.InputVarName);

            inputLine.ReadVar(LandisData);

            int expectedIndex = 0;

            foreach (ISpecies species in dataset)
            {
                Assert.AreEqual(expectedIndex, species.Index);
                expectedIndex++;

                Assert.IsTrue(inputLine.GetNext());
                currentLine = new StringReader(inputLine.ToString());

                Assert.AreEqual(ReadValue <string>(), species.Name);
                Assert.AreEqual(ReadValue <int>(), species.Longevity);
                Assert.AreEqual(ReadValue <int>(), species.Maturity);
                Assert.AreEqual(ReadValue <byte>(), species.ShadeTolerance);
                Assert.AreEqual(ReadValue <byte>(), species.FireTolerance);
                Assert.AreEqual(ReadEffectiveSeedDist(), species.EffectiveSeedDist);
                Assert.AreEqual(ReadValue <int>(), species.MaxSeedDist);
                Assert.AreEqual(ReadValue <float>(), species.VegReprodProb);
                Assert.AreEqual(ReadValue <int>(), species.MinSproutAge);
                Assert.AreEqual(ReadValue <int>(), species.MaxSproutAge);
                Assert.AreEqual(ReadValue <PostFireRegeneration>(), species.PostFireRegeneration);
            }
            Assert.IsFalse(inputLine.GetNext());
            file.Close();
        }
Exemplo n.º 3
0
        //---------------------------------------------------------------------

        private TValue ReadInputVar <TValue>(string name)
        {
            InputVar <TValue> var = new InputVar <TValue>(name);

            inputLine.ReadVar(var);
            inputLine.GetNext();
            return(var.Value.Actual);
        }
Exemplo n.º 4
0
        //---------------------------------------------------------------------

        private void ReadAndCheckParameters(string filename)
        {
            IParameters parameters;

            try {
                reader     = OpenFile(filename);
                parameters = parser.Parse(reader);
            }
            finally {
                reader.Close();
            }

            try {
                //  Now that we know the data file is properly formatted, read
                //  data from it and compare it against parameter object.
                reader    = OpenFile(filename);
                inputLine = new InputLine(reader);

                Assert.AreEqual(parser.LandisDataValue, ReadInputVar <string>("LandisData"));

                Assert.AreEqual(ReadInputVar <int>("Timestep"), parameters.Timestep);
                Assert.AreEqual(ReadInputVar <SeedingAlgorithms>("SeedingAlgorithm"),
                                parameters.SeedAlgorithm);

                inputLine.MatchName("MinRelativeBiomass");
                inputLine.GetNext();
                List <IEcoregion> ecoregions = ReadEcoregions();
                for (byte shadeClass = 1; shadeClass <= 5; shadeClass++)
                {
                    StringReader currentLine = new StringReader(inputLine.ToString());
                    Assert.AreEqual(shadeClass, ReadInputValue <byte>(currentLine));
                    foreach (IEcoregion ecoregion in ecoregions)
                    {
                        //  TODO: Eventually allow equality testing for Percentage
                        Assert.AreEqual((double)ReadInputValue <Percentage>(currentLine),
                                        (double)parameters.MinRelativeBiomass[shadeClass][ecoregion]);
                    }
                    inputLine.GetNext();
                }

                inputLine.MatchName("BiomassParameters");
                inputLine.GetNext();
                while (inputLine.VariableName != "EstablishProbabilities")
                {
                    StringReader currentLine = new StringReader(inputLine.ToString());
                    ISpecies     species     = ReadSpecies(currentLine);
                    Assert.AreEqual(ReadInputValue <double>(currentLine),
                                    parameters.LeafLongevity[species]);
                    Assert.AreEqual(ReadInputValue <double>(currentLine),
                                    parameters.WoodyDecayRate[species]);
                    Assert.AreEqual(ReadInputValue <double>(currentLine),
                                    parameters.MortCurveShapeParm[species]);
                    inputLine.GetNext();
                }

                CheckParameterTable("EstablishProbabilities",
                                    parameters.EstablishProbability,
                                    "MaxANPP");

                CheckParameterTable("MaxANPP",
                                    parameters.MaxANPP,
                                    "LeafLitter:DecayRates");

                const string AgeOnlyDisturbanceParms = "AgeOnlyDisturbances:BiomassParameters";
                CheckParameterTable("LeafLitter:DecayRates",
                                    parameters.LeafLitterDecayRate,
                                    AgeOnlyDisturbanceParms);

                if (parameters.AgeOnlyDisturbanceParms != null)
                {
                    Assert.AreEqual(ReadInputVar <string>(AgeOnlyDisturbanceParms),
                                    parameters.AgeOnlyDisturbanceParms);
                }
            }
            finally {
                inputLine = null;
                reader.Close();
            }
        }
Exemplo n.º 5
0
        //---------------------------------------------------------------------

        private void AssertNoMoreLines(InputLine line)
        {
            Assert.IsFalse(line.GetNext());
            AssertLineAtEnd(line);
        }