//--------------------------------------------------------------------- private ISpecies ReadSpecies(StringReader currentLine) { InputVar <string> speciesName = new InputVar <string>("Species"); speciesName.ReadValue(currentLine); ISpecies species = speciesDataset[speciesName.Value.Actual]; Assert.IsNotNull(species); return(species); }
//--------------------------------------------------------------------- private void CheckParameterTable <TParm>(string tableName, Species.AuxParm <Ecoregions.AuxParm <TParm> > parmValues, string nextTableName) { inputLine.MatchName(tableName); bool haveLine = inputLine.GetNext(); List <IEcoregion> ecoregions = ReadEcoregions(); while (haveLine && inputLine.VariableName != nextTableName) { StringReader currentLine = new StringReader(inputLine.ToString()); ISpecies species = ReadSpecies(currentLine); foreach (IEcoregion ecoregion in ecoregions) { Assert.AreEqual(ReadInputValue <TParm>(currentLine), parmValues[species][ecoregion]); } haveLine = inputLine.GetNext(); } }
//--------------------------------------------------------------------- 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(); } }