public void Init()
        {
            List<Species.IParameters> speciesParms = new List<Species.IParameters>();
            speciesParms.Add(new Species.Parameters("oak",
                                                    400,    // longevity
                                                    0,      // maturity
                                                    0,      // shadeTolerance
                                                    0,      // fireTolerance
                                                    0,      // effectiveSeedDist
                                                    0,      // maxSeedDist
                                                    0,      // vegReprodProb
                                                    0,      // minSproutAge
                                                    0,      // maxSproutAge
                                                    Species.PostFireRegeneration.None));
            speciesParms.Add(new Species.Parameters("pine",
                                                    200,    // longevity
                                                    0,      // maturity
                                                    0,      // shadeTolerance
                                                    0,      // fireTolerance
                                                    0,      // effectiveSeedDist
                                                    0,      // maxSeedDist
                                                    0,      // vegReprodProb
                                                    0,      // minSproutAge
                                                    0,      // maxSproutAge
                                                    Species.PostFireRegeneration.Serotiny));
            Species.IDataset speciesDataset = new Species.Dataset(speciesParms);
            oak = speciesDataset["oak"];

            parser = new DatasetParser(10, speciesDataset);
        }
        public void Init()
        {
            List <Species.IParameters> speciesParms = new List <Species.IParameters>();

            speciesParms.Add(new Species.Parameters("oak",
                                                    400,    // longevity
                                                    0,      // maturity
                                                    0,      // shadeTolerance
                                                    0,      // fireTolerance
                                                    0,      // effectiveSeedDist
                                                    0,      // maxSeedDist
                                                    0,      // vegReprodProb
                                                    0,      // minSproutAge
                                                    0,      // maxSproutAge
                                                    Species.PostFireRegeneration.None));
            speciesParms.Add(new Species.Parameters("pine",
                                                    200,    // longevity
                                                    0,      // maturity
                                                    0,      // shadeTolerance
                                                    0,      // fireTolerance
                                                    0,      // effectiveSeedDist
                                                    0,      // maxSeedDist
                                                    0,      // vegReprodProb
                                                    0,      // minSproutAge
                                                    0,      // maxSproutAge
                                                    Species.PostFireRegeneration.Serotiny));
            Species.IDataset speciesDataset = new Species.Dataset(speciesParms);
            oak = speciesDataset["oak"];

            parser = new DatasetParser(10, speciesDataset);
        }
Exemple #3
0
        //---------------------------------------------------------------------

        protected override IDataset Parse()
        {
            ReadLandisDataVar();

            Dataset dataset = new Dataset();

            InputVar <byte>   mapCode     = new InputVar <byte>("MapCode");
            InputVar <string> speciesName = new InputVar <string>("Species");
            InputVar <ushort> age         = new InputVar <ushort>("Age");

            Dictionary <byte, int> mapCodeLineNumbers = new Dictionary <byte, int>();

            while (!AtEndOfInput)
            {
                //  Read initial community
                int mapCodeLineNum = LineNumber;
                ReadVar(mapCode);
                int lineNumber;
                if (mapCodeLineNumbers.TryGetValue(mapCode.Value.Actual, out lineNumber))
                {
                    throw new InputValueException(mapCode.Value.String,
                                                  "The map code {0} was previously used on line {1}",
                                                  mapCode.Value.Actual, lineNumber);
                }
                else
                {
                    mapCodeLineNumbers[mapCode.Value.Actual] = mapCodeLineNum;
                }

                //  Read species and their ages
                List <ISpeciesCohorts <AgeOnly.ICohort> > speciesCohortsList;
                speciesCohortsList = new List <ISpeciesCohorts <AgeOnly.ICohort> >();
                Dictionary <string, int> speciesLineNumbers = new Dictionary <string, int>();
                while (!AtEndOfInput && CurrentName != mapCode.Name)
                {
                    StringReader currentLine = new StringReader(CurrentLine);

                    ReadValue(speciesName, currentLine);
                    Species.ISpecies species = Model.Species[speciesName.Value.Actual];
                    if (species == null)
                    {
                        throw new InputValueException(speciesName.Value.String,
                                                      "{0} is not a species name.",
                                                      speciesName.Value.String);
                    }
                    if (speciesLineNumbers.TryGetValue(species.Name, out lineNumber))
                    {
                        throw new InputValueException(speciesName.Value.String,
                                                      "The species {0} was previously used on line {1}",
                                                      speciesName.Value.String, lineNumber);
                    }
                    else
                    {
                        speciesLineNumbers[species.Name] = LineNumber;
                    }

                    //  Read ages
                    List <ushort> ages = new List <ushort>();
                    TextReader.SkipWhitespace(currentLine);
                    while (currentLine.Peek() != -1)
                    {
                        ReadValue(age, currentLine);
                        if (ages.Contains(age.Value.Actual))
                        {
                            throw new InputValueException(age.Value.String,
                                                          "The age {0} appears more than once.",
                                                          age.Value.String);
                        }
                        if (age.Value.Actual > species.Longevity)
                        {
                            throw new InputValueException(age.Value.String,
                                                          "The age {0} is more than longevity ({1}).",
                                                          age.Value.String, species.Longevity);
                        }
                        ages.Add(age.Value.Actual);
                        TextReader.SkipWhitespace(currentLine);
                    }
                    if (ages.Count == 0)
                    {
                        //  Try reading age which will throw exception
                        ReadValue(age, currentLine);
                    }

                    speciesCohortsList.Add(new AgeOnly.SpeciesCohorts(species, ages));

                    GetNextLine();
                }

                dataset.Add(new Community(mapCode.Value.Actual,
                                          new AgeOnly.SiteCohorts(speciesCohortsList)));
            }

            return(dataset);
        }