//---------------------------------------------------------------------

        protected override IInputParameters Parse()
        {
            InputVar <string> landisData = new InputVar <string>("LandisData");

            ReadVar(landisData);
            if (landisData.Value.Actual != PlugIn.ExtensionName)
            {
                throw new InputValueException(landisData.Value.String, "The value is not \"{0}\"", PlugIn.ExtensionName);
            }

            InputParameters parameters = new InputParameters();

            InputVar <int> timestep = new InputVar <int>(Names.Timestep);

            ReadVar(timestep);
            parameters.Timestep = timestep.Value;

            InputVar <int> StartYear = new InputVar <int>(Names.StartYear);

            ReadVar(StartYear);
            parameters.StartYear = StartYear.Value;

            InputVar <SeedingAlgorithms> seedAlg = new InputVar <SeedingAlgorithms>(Names.SeedingAlgorithm);

            ReadVar(seedAlg);
            parameters.SeedAlgorithm = seedAlg.Value;

            //---------------------------------------------------------------------------------

            InputVar <string> initCommunities = new InputVar <string>("InitialCommunities");

            ReadVar(initCommunities);
            parameters.InitialCommunities = initCommunities.Value;

            InputVar <string> communitiesMap = new InputVar <string>("InitialCommunitiesMap");

            ReadVar(communitiesMap);
            parameters.InitialCommunitiesMap = communitiesMap.Value;

            InputVar <string> climateFileName = new InputVar <string>(Names.climateFileName);

            ReadVar(climateFileName);
            parameters.climateFileName = climateFileName.Value;

            InputVar <int> Latitude = new InputVar <int>(Names.Latitude);

            ReadVar(Latitude);
            parameters.Latitude = Util.CheckBiomassParm(Latitude.Value, -90, 90);

            InputVar <string> CanopyLayerBiomassCategories = new InputVar <string>(Names.CanopyLayerBiomassCategories);

            ReadVar(CanopyLayerBiomassCategories);
            CanopyLayerCategories.InitializeCanopyLayers(Names.CanopyLayerBiomassCategories, CanopyLayerBiomassCategories.Value);

            //InputVar<int> CanopyLayerAgeSpan = new InputVar<int>(Names.CanopyLayerAgeSpan);
            //ReadVar(CanopyLayerAgeSpan);
            //parameters.CanopyLayerAgeSpan = int.Parse(Util.CheckBiomassParm(CanopyLayerAgeSpan.Value, 0, int.MaxValue).ToString());

            if (ReadOptionalName(Names.PNEToutputsites) == true)
            {
                while (!AtEndOfInput && CurrentName != Names.SpeciesParameterFile)
                {
                    StringReader currentLine = new StringReader(CurrentLine);

                    InputVar <int> row = new InputVar <int>("Output row");
                    InputVar <int> col = new InputVar <int>("Output column");

                    ReadValue(row, currentLine);
                    ReadValue(col, currentLine);

                    foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
                    {
                        if (site.Location.Row == row.Value && site.Location.Column == col.Value)
                        {
                            parameters.HasSiteOutput[site] = true;
                        }
                    }


                    GetNextLine();
                }
            }

            //-------------------------
            //  SpeciesParameters table

            InputVar <string> SpeciesParameterFile = new InputVar <string>(Names.SpeciesParameterFile);

            ReadVar(SpeciesParameterFile);
            parameters = ReadSpeciesParameters(SpeciesParameterFile.Value, parameters);

            InputVar <string> EstRadSensitivity = new InputVar <string>(Names.EstRadSensitivity);

            if (ReadOptionalVar(EstRadSensitivity))
            {
                InitEstablishmentTable(EstRadSensitivity.Value, Names.EstRadSensitivity, parameters.EstRadSensitivity);
            }
            else
            {
                InitEstablishmentTable(Names.EstRadSensitivity, parameters.EstRadSensitivity);
            }

            InputVar <string> EstMoistureSensitivity = new InputVar <string>(Names.EstMoistureSensitivity);

            if (ReadOptionalVar(EstMoistureSensitivity))
            {
                InitEstablishmentTable(EstMoistureSensitivity.Value, Names.EstMoistureSensitivity, parameters.EstMoistureSensitivity);
            }
            else
            {
                InitEstablishmentTable(Names.EstMoistureSensitivity, parameters.EstMoistureSensitivity);
            }

            ReadName(Names.EcoregionParameters);

            InputVar <string> ecoregionName       = new InputVar <string>("Ecoregion Name");
            InputVar <int>    aet                 = new InputVar <int>("Actual Evapotranspiration");
            InputVar <float>  whc                 = new InputVar <float>("Water holding capacity");
            InputVar <float>  evaporationfraction = new InputVar <float>("EvaporationFraction");
            InputVar <float>  leakagefraction     = new InputVar <float>("LeakageFraction");

            Dictionary <string, int> lineNumbers = new Dictionary <string, int>();

            string lastColumn = "the " + aet.Name + " column";

            while (!AtEndOfInput && CurrentName != Names.AgeOnlyDisturbanceParms)
            {
                StringReader currentLine = new StringReader(CurrentLine);

                ReadValue(ecoregionName, currentLine);

                IEcoregion ecoregion = GetEcoregion(ecoregionName.Value,
                                                    lineNumbers);

                ReadValue(aet, currentLine);
                parameters.AET[ecoregion] = Util.CheckBiomassParm(aet.Value, 0, int.MaxValue);

                ReadValue(whc, currentLine);
                parameters.WHC[ecoregion] = Util.CheckBiomassParm(whc.Value, 0, int.MaxValue);

                ReadValue(evaporationfraction, currentLine);
                parameters.EvaporationFraction[ecoregion] = Util.CheckBiomassParm(evaporationfraction.Value, 0, 1);

                ReadValue(leakagefraction, currentLine);
                parameters.LeakageFraction[ecoregion] = Util.CheckBiomassParm(leakagefraction.Value, 0, 1);


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


            string lastParameter = null;

            if (!AtEndOfInput && CurrentName == Names.AgeOnlyDisturbanceParms)
            {
                InputVar <string> ageOnlyDisturbanceParms = new InputVar <string>(Names.AgeOnlyDisturbanceParms);
                ReadVar(ageOnlyDisturbanceParms);
                parameters.AgeOnlyDisturbanceParms = ageOnlyDisturbanceParms.Value;

                lastParameter = "the " + Names.AgeOnlyDisturbanceParms + " parameter";
            }

            if (lastParameter != null)
            {
                CheckNoDataAfter(lastParameter);
            }

            return(parameters);
        }
        static public void DefineBiomassLayers(ActiveSite site)
        {
            if (PlugIn.Cohorts[site] == null)
            {
                return;
            }

            CalculateBiomassSums(site);

            canopy.Clear();

            int maxage = 0;

            List <ISpecies> species          = new List <ISpecies>();
            List <int>      cohort_index     = new List <int>();
            List <float>    biomass          = new List <float>();
            List <int>      old_canopylayers = new List <int>();

            foreach (ISpeciesCohorts speciesCohorts in PlugIn.Cohorts[site])
            {
                int index = 0;
                foreach (ICohort cohort in speciesCohorts)
                {
                    if (cohort.Age > maxage)
                    {
                        maxage = cohort.Age;
                    }
                    int a = 0;
                    for (a = 0; a < biomass.Count; a++)
                    {
                        if (biomass[a] > cohort.Biomass)
                        {
                            biomass.Insert(a, cohort.Biomass);
                            species.Insert(a, cohort.Species);
                            cohort_index.Insert(a, index);
                            old_canopylayers.Insert(a, cohort.CanopyLayer);
                            break;
                        }
                    }
                    if (a == biomass.Count)
                    {
                        species.Add(cohort.Species);
                        biomass.Add(cohort.Biomass);
                        cohort_index.Add(index);
                        old_canopylayers.Add(cohort.CanopyLayer);
                    }
                    index++;
                }
            }
            if (TotalBiomass[site] <= 0)
            {
                return;
            }
            float[] fractions = CanopyLayerCategories.GetCumBiomFractions(maxage);

            float includedbiomfrac = 0;

            for (int b = 0; b < biomass.Count(); b++)
            {
                includedbiomfrac += biomass[b] / TotalBiomass[site];

                for (int f = 0; f < fractions.Count(); f++)
                {
                    if (includedbiomfrac <= fractions[f])
                    {
                        int CanopyLayer = Math.Max(old_canopylayers[b], f);
                        while (canopy.Count < CanopyLayer + 1)
                        {
                            canopy.Add(new CanopyLayerBiomass());
                        }
                        canopy[CanopyLayer].Add(new CohortBiomass(site, PlugIn.Cohorts[site][species[b]].Get(cohort_index[b]), cohort_index[b]));
                        break;
                    }
                }
            }
        }