Пример #1
0
        //---------------------------------------------------------------------

        protected override IInputParameters Parse()
        {
            ReadLandisDataVar();

            InputParameters parameters = new InputParameters(SpeciesDataset.Count);

            InputVar <int> timestep = new InputVar <int>("Timestep");

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

            const string  LocalVariables          = "LocalVariables";
            const string  DerivedLocalVariables   = "DerivedLocalVariables";
            const string  NeighborhoodVariables   = "NeighborhoodVariables";
            const string  ClimateVariables        = "ClimateVariables";
            const string  DistanceVariables       = "DistanceVariables";
            const string  SpeciesModels           = "SpeciesModels";
            const string  LocalVarMapFileNames    = "LocalVarMapFileNames";
            const string  NeighborVarMapFileNames = "NeighborVarMapFileNames";
            const string  ClimateVarMapFileNames  = "ClimateVarMapFileNames";
            const string  DistanceVarMapFileNames = "DistanceVarMapFileNames";
            const string  SpeciesMapFileName      = "SpeciesMapFileNames";
            const string  LogFile             = "LogFile";
            const string  SpeciesLogFileNames = "SpeciesLogFileNames";
            List <string> keywordList         = new List <string> {
                LocalVariables, DerivedLocalVariables, NeighborhoodVariables, ClimateVariables, DistanceVariables, SpeciesModels, LocalVarMapFileNames, NeighborVarMapFileNames, ClimateVarMapFileNames, DistanceVarMapFileNames, SpeciesMapFileName, LogFile, SpeciesLogFileNames
            };

            if (ReadOptionalName(LocalVariables))
            {
                InputVar <string> speciesName = new InputVar <string>("Species");

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

                InputVar <string> mapName    = new InputVar <string>("Map Name");
                InputVar <string> forestType = new InputVar <string>("Forest Type");
                InputVar <string> ageKeyword = new InputVar <string>("Age Keyword");
                InputVar <int>    minAge     = new InputVar <int>("Min Age");
                InputVar <int>    maxAge     = new InputVar <int>("Max Age");

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


                const string nameDelimiter = "->";  // delimiter that separates map name and forest type

                IMapDefinition mapDefn = null;

                while (!AtEndOfInput && !keywordList.Contains(CurrentName))
                {
                    StringReader currentLine = new StringReader(CurrentLine);

                    //  If the current line has the delimiter, then read the map
                    //  name.
                    if (CurrentLine.Contains(nameDelimiter))
                    {
                        ReadValue(mapName, currentLine);
                        CheckForRepeatedName(mapName.Value, "map name", lineNumbers);

                        mapDefn      = new MapDefinition();
                        mapDefn.Name = mapName.Value;
                        parameters.ReclassMaps.Add(mapDefn);

                        TextReader.SkipWhitespace(currentLine);
                        string word = TextReader.ReadWord(currentLine);
                        if (word != nameDelimiter)
                        {
                            throw NewParseException("Expected \"{0}\" after the map name {1}.",
                                                    nameDelimiter, mapName.Value.String);
                        }

                        forestTypeLineNumbers.Clear();
                    }
                    else
                    {
                        //  If there is no name delimiter and we don't have the
                        //  name for the first map yet, then it's an error.
                        if (mapDefn == null)
                        {
                            throw NewParseException("Expected a line with map name followed by \"{0}\"", nameDelimiter);
                        }
                    }

                    ReadValue(forestType, currentLine);
                    CheckForRepeatedName(forestType.Value, "forest type",
                                         forestTypeLineNumbers);

                    IForestType currentForestType = new ForestType(SpeciesDataset.Count);
                    currentForestType.Name = forestType.Value;
                    mapDefn.ForestTypes.Add(currentForestType);

                    // Read the age ranges for the species:
                    ReadValue(ageKeyword, currentLine);
                    if (ageKeyword.Value == "All")
                    {
                        currentForestType.MinAge = 0;
                        int maxAgeAllSpecies = 0;
                        foreach (ISpecies species in PlugIn.ModelCore.Species)
                        {
                            if (species.Longevity > maxAgeAllSpecies)
                            {
                                maxAgeAllSpecies = species.Longevity;
                            }
                        }
                        currentForestType.MaxAge = maxAgeAllSpecies;
                    }
                    else
                    {
                        //ReadValue(minAge, currentLine);
                        currentForestType.MinAge = Convert.ToInt32(ageKeyword.Value);

                        TextReader.SkipWhitespace(currentLine);
                        string currentWord = TextReader.ReadWord(currentLine);
                        if (currentWord != "to")
                        {
                            StringBuilder message = new StringBuilder();
                            message.AppendFormat("Expected \"to\" after the minimum age ({0})",
                                                 minAge.Value.String);
                            if (currentWord.Length > 0)
                            {
                                message.AppendFormat(", but found \"{0}\" instead", currentWord);
                            }
                            throw NewParseException(message.ToString());
                        }

                        ReadValue(maxAge, currentLine);
                        currentForestType.MaxAge = maxAge.Value;
                    }
                    //  Read species for forest types

                    List <string> speciesNames = new List <string>();

                    TextReader.SkipWhitespace(currentLine);
                    while (currentLine.Peek() != -1)
                    {
                        ReadValue(speciesName, currentLine);
                        string name = speciesName.Value.Actual;
                        bool   negativeMultiplier = name.StartsWith("-");
                        if (negativeMultiplier)
                        {
                            name = name.Substring(1);
                            if (name.Length == 0)
                            {
                                throw new InputValueException(speciesName.Value.String,
                                                              "No species name after \"-\"");
                            }
                        }
                        if (name == "All")
                        {
                            foreach (ISpecies species in PlugIn.ModelCore.Species)
                            {
                                speciesNames.Add(species.Name);
                                currentForestType[species.Index] = 1;
                            }
                        }
                        else if (name == "None")
                        {
                            foreach (ISpecies species in PlugIn.ModelCore.Species)
                            {
                                speciesNames.Add(species.Name);
                                currentForestType[species.Index] = 0;
                            }
                        }
                        else
                        {
                            ISpecies species = GetSpecies(new InputValue <string>(name, speciesName.Value.String));
                            if (speciesNames.Contains(species.Name))
                            {
                                throw NewParseException("The species {0} appears more than once.", species.Name);
                            }
                            speciesNames.Add(species.Name);
                            currentForestType[species.Index] = negativeMultiplier ? -1 : 1;
                        }

                        TextReader.SkipWhitespace(currentLine);
                    }
                    if (speciesNames.Count == 0)
                    {
                        throw NewParseException("At least one species is required.");
                    }

                    GetNextLine();
                }
            }
            if (ReadOptionalName(DerivedLocalVariables))
            {
                Dictionary <string, int> lineNumbers = new Dictionary <string, int>();
                lineNumbers.Clear();
                InputVar <string> derVarName    = new InputVar <string>("Derived Variable Name");
                InputVar <string> derVarFormula = new InputVar <string>("Derived Variable Formula");
                const string      nameDelimiter = "->"; // delimiter that separates map name and forest type
                List <string>     formulaSymbol = new List <string>(new string[] { "+", "-", "*" });

                IVariableDefinition varDefn = null;
                while (!AtEndOfInput && !keywordList.Contains(CurrentName))
                {
                    StringReader currentLine = new StringReader(CurrentLine);

                    ReadValue(derVarName, currentLine);
                    CheckForRepeatedName(derVarName.Value, "var name", lineNumbers);

                    varDefn      = new VariableDefinition();
                    varDefn.Name = derVarName.Value;

                    TextReader.SkipWhitespace(currentLine);
                    string word = TextReader.ReadWord(currentLine);
                    if (word != nameDelimiter)
                    {
                        throw NewParseException("Expected \"{0}\" after the map name {1}.",
                                                nameDelimiter, derVarName.Value.String);
                    }

                    TextReader.SkipWhitespace(currentLine);
                    string variable = TextReader.ReadWord(currentLine);
                    varDefn.Variables.Add(variable);
                    while (currentLine.Peek() != -1)
                    {
                        TextReader.SkipWhitespace(currentLine);
                        string op = TextReader.ReadWord(currentLine);
                        if (op == "")
                        {
                            break;
                        }
                        varDefn.Operators.Add(op);

                        TextReader.SkipWhitespace(currentLine);
                        variable = TextReader.ReadWord(currentLine);
                        varDefn.Variables.Add(variable);
                    }
                    parameters.DerivedVars.Add(varDefn);

                    GetNextLine();
                }
            }
            if (ReadOptionalName(NeighborhoodVariables))
            {
                // Read Neighborhood Variables
                Dictionary <string, int> lineNumbers = new Dictionary <string, int>();
                lineNumbers.Clear();
                InputVar <string> neighborVarName = new InputVar <string>("Neighbor Variable Name");
                InputVar <string> localVarName    = new InputVar <string>("Local Variable Name");
                InputVar <int>    neighborRadius  = new InputVar <int>("Neighbor Radius");
                InputVar <string> transform       = new InputVar <string>("Transform");

                INeighborVariableDefinition neighborVarDefn = null;
                while (!AtEndOfInput && !keywordList.Contains(CurrentName))
                {
                    StringReader currentLine = new StringReader(CurrentLine);

                    ReadValue(neighborVarName, currentLine);
                    CheckForRepeatedName(neighborVarName.Value, "var name", lineNumbers);

                    neighborVarDefn      = new NeighborVariableDefinition();
                    neighborVarDefn.Name = neighborVarName.Value;

                    ReadValue(localVarName, currentLine);
                    neighborVarDefn.LocalVariable = localVarName.Value;

                    ReadValue(neighborRadius, currentLine);
                    neighborVarDefn.NeighborRadius = neighborRadius.Value;

                    ReadValue(transform, currentLine);
                    neighborVarDefn.Transform = transform.Value;

                    parameters.NeighborVars.Add(neighborVarDefn);
                    GetNextLine();
                }
            }
            if (ReadOptionalName(ClimateVariables))
            {
                // Read Climate Variables
                Dictionary <string, int> lineNumbers = new Dictionary <string, int>();
                lineNumbers.Clear();
                InputVar <string> climateVarName        = new InputVar <string>("Climate Variable Name");
                InputVar <string> climateLibraryVarName = new InputVar <string>("Climate Library Variable Name");
                InputVar <string> sourceName            = new InputVar <string>("Source Name");
                InputVar <string> varYear   = new InputVar <string>("Variable Year");
                InputVar <int>    minMonth  = new InputVar <int>("Min Month");
                InputVar <int>    maxMonth  = new InputVar <int>("Max Month");
                InputVar <string> transform = new InputVar <string>("Tranformation");

                IClimateVariableDefinition climateVarDefn = null;
                while (!AtEndOfInput && !keywordList.Contains(CurrentName))
                {
                    StringReader currentLine = new StringReader(CurrentLine);
                    ReadValue(climateVarName, currentLine);
                    CheckForRepeatedName(climateVarName.Value, "var name", lineNumbers);

                    climateVarDefn      = new ClimateVariableDefinition();
                    climateVarDefn.Name = climateVarName.Value;

                    ReadValue(varYear, currentLine);
                    climateVarDefn.Year = varYear.Value;

                    ReadValue(minMonth, currentLine);
                    climateVarDefn.MinMonth = minMonth.Value;

                    TextReader.SkipWhitespace(currentLine);
                    string currentWord = TextReader.ReadWord(currentLine);
                    if (currentWord != "to")
                    {
                        StringBuilder message = new StringBuilder();
                        message.AppendFormat("Expected \"to\" after the minimum month ({0})",
                                             minMonth.Value.String);
                        if (currentWord.Length > 0)
                        {
                            message.AppendFormat(", but found \"{0}\" instead", currentWord);
                        }
                        throw NewParseException(message.ToString());
                    }

                    ReadValue(maxMonth, currentLine);
                    climateVarDefn.MaxMonth = maxMonth.Value;

                    ReadValue(sourceName, currentLine);
                    climateVarDefn.SourceName = sourceName.Value;

                    ReadValue(climateLibraryVarName, currentLine);
                    climateVarDefn.ClimateLibVariable = climateLibraryVarName.Value;

                    ReadValue(transform, currentLine);
                    climateVarDefn.Transform = transform.Value;

                    parameters.ClimateVars.Add(climateVarDefn);
                    GetNextLine();
                }
            }
            if (ReadOptionalName(DistanceVariables))
            {
                // Read Distance Variables
                Dictionary <string, int> lineNumbers = new Dictionary <string, int>();
                lineNumbers.Clear();
                InputVar <string> distanceVarName = new InputVar <string>("Distance Variable Name");
                InputVar <string> localVarName    = new InputVar <string>("Local Variable Name");
                InputVar <string> transform       = new InputVar <string>("Transform");

                IDistanceVariableDefinition distanceVarDefn = null;
                while (!AtEndOfInput && !keywordList.Contains(CurrentName))
                {
                    StringReader currentLine = new StringReader(CurrentLine);

                    ReadValue(distanceVarName, currentLine);
                    CheckForRepeatedName(distanceVarName.Value, "var name", lineNumbers);

                    distanceVarDefn      = new DistanceVariableDefinition();
                    distanceVarDefn.Name = distanceVarName.Value;

                    ReadValue(localVarName, currentLine);
                    distanceVarDefn.LocalVariable = localVarName.Value;

                    ReadValue(transform, currentLine);
                    distanceVarDefn.Transform = transform.Value;

                    parameters.DistanceVars.Add(distanceVarDefn);
                    GetNextLine();
                }
            }
            // Read species models
            ReadName(SpeciesModels);

            InputVar <string> birdName   = new InputVar <string>("Bird Name");
            InputVar <string> parameter  = new InputVar <string>("Parameter");
            InputVar <string> paramType  = new InputVar <string>("Parameter Type");
            InputVar <double> paramValue = new InputVar <double>("Parameter Value");


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

            speciesLineNumbers.Clear();

            const string speciesNameDelimiter = "->";  // delimiter that separates map name and forest type

            IModelDefinition modelDefn = null;

            while (!AtEndOfInput && !keywordList.Contains(CurrentName))
            {
                StringReader currentLine = new StringReader(CurrentLine);

                //  If the current line has the delimiter, then read the map
                //  name.
                if (CurrentLine.Contains(speciesNameDelimiter))
                {
                    ReadValue(birdName, currentLine);
                    CheckForRepeatedName(birdName.Value, "bird name", speciesLineNumbers);

                    modelDefn      = new ModelDefinition();
                    modelDefn.Name = birdName.Value;
                    parameters.Models.Add(modelDefn);

                    TextReader.SkipWhitespace(currentLine);
                    string word = TextReader.ReadWord(currentLine);
                    if (word != speciesNameDelimiter)
                    {
                        throw NewParseException("Expected \"{0}\" after the map name {1}.",
                                                speciesNameDelimiter, birdName.Value.String);
                    }

                    speciesLineNumbers.Clear();
                }
                else
                {
                    //  If there is no name delimiter and we don't have the
                    //  name for the first map yet, then it's an error.
                    if (modelDefn == null)
                    {
                        throw NewParseException("Expected a line with map name followed by \"{0}\"", speciesNameDelimiter);
                    }
                }

                // Read the parameter name:
                ReadValue(parameter, currentLine);
                modelDefn.Parameters.Add(parameter.Value);

                // Read the parameter types:
                ReadValue(paramType, currentLine);
                modelDefn.ParamTypes.Add(paramType.Value);

                // Read the parameter value:
                ReadValue(paramValue, currentLine);
                modelDefn.Values.Add(paramValue.Value);

                GetNextLine();
            }

            // Template for filenames of maps
            InputVar <string> localVarMapFileNames = new InputVar <string>(LocalVarMapFileNames);
            bool readLocalMaps = false;

            if (ReadOptionalVar(localVarMapFileNames))
            {
                parameters.LocalVarMapFileNames = localVarMapFileNames.Value;
                readLocalMaps = true;
            }

            InputVar <string> neighborMapFileNames = new InputVar <string>(NeighborVarMapFileNames);
            bool readNeighborMaps = false;

            if (ReadOptionalVar(neighborMapFileNames))
            {
                parameters.NeighborMapFileNames = neighborMapFileNames.Value;
                readNeighborMaps = true;
            }

            InputVar <string> climateMapFileNames = new InputVar <string>(ClimateVarMapFileNames);
            bool readClimateMaps = false;

            if (ReadOptionalVar(climateMapFileNames))
            {
                parameters.ClimateMapFileNames = climateMapFileNames.Value;
                readClimateMaps = true;
            }

            InputVar <string> distanceMapFileNames = new InputVar <string>(DistanceVarMapFileNames);
            bool readDistanceMaps = false;

            if (ReadOptionalVar(distanceMapFileNames))
            {
                parameters.DistanceMapFileNames = distanceMapFileNames.Value;
                readDistanceMaps = true;
            }

            InputVar <string> speciesMapFileNames = new InputVar <string>(SpeciesMapFileName);
            bool readSpeciesMaps = false;

            if (ReadOptionalVar(speciesMapFileNames))
            {
                parameters.SpeciesMapFileNames = speciesMapFileNames.Value;
                readSpeciesMaps = true;
            }
            InputVar <string> speciesLogFileNames = new InputVar <string>(SpeciesLogFileNames);
            bool readSpeciesLogs = false;

            if (ReadOptionalVar(speciesLogFileNames))
            {
                parameters.SpeciesLogFileNames = speciesLogFileNames.Value;
                readSpeciesLogs = true;
            }
            InputVar <string> logFile = new InputVar <string>(LogFile);
            bool readLogFile          = false;

            if (ReadOptionalVar(logFile))
            {
                parameters.LogFileName = logFile.Value;
                readLogFile            = true;
            }

            if (readLogFile)
            {
                CheckNoDataAfter(string.Format("the {0} parameter", LogFile));
            }
            else if (readSpeciesLogs)
            {
                CheckNoDataAfter(string.Format("the {0} parameter", SpeciesLogFileNames));
            }
            else if (readSpeciesMaps)
            {
                CheckNoDataAfter(string.Format("the {0} parameter", SpeciesMapFileName));
            }
            else if (readDistanceMaps)
            {
                CheckNoDataAfter(string.Format("the {0} parameter", DistanceVarMapFileNames));
            }
            else if (readClimateMaps)
            {
                CheckNoDataAfter(string.Format("the {0} parameter", ClimateVarMapFileNames));
            }
            else if (readNeighborMaps)
            {
                CheckNoDataAfter(string.Format("the {0} parameter", NeighborVarMapFileNames));
            }
            else if (readLocalMaps)
            {
                CheckNoDataAfter(string.Format("the {0} parameter", LocalVarMapFileNames));
            }
            else
            {
                CheckNoDataAfter(string.Format("the {0} parameter", SpeciesModels));
            }

            return(parameters); //.GetComplete();
        }
Пример #2
0
        //---------------------------------------------------------------------

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

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

            AgentParameters agentParameters = new AgentParameters(PlugIn.ModelCore.Species.Count, PlugIn.ModelCore.Ecoregions.Count);

            InputVar <string> agentName = new InputVar <string>("EDAAgentName");

            ReadVar(agentName);
            agentParameters.AgentName = agentName.Value;

            InputVar <SHImode> shi = new InputVar <SHImode>("SHIMode");

            ReadVar(shi);
            agentParameters.SHImode = shi.Value;

            InputVar <int> startYear = new InputVar <int>("StartYear");

            if (CurrentName == "StartYear")
            {
                ReadVar(startYear);
                agentParameters.StartYear = startYear.Value;
            }
            else
            {
                agentParameters.StartYear = 0;
            }

            InputVar <int> endYear = new InputVar <int>("EndYear");

            if (CurrentName == "EndYear")
            {
                ReadVar(endYear);
                agentParameters.EndYear = endYear.Value;
            }
            else
            {
                agentParameters.EndYear = PlugIn.ModelCore.EndTime;
            }

            // - Climate Input -
            //ADD HERE
            // Read Climate Variables
            ReadName("ClimateVariables");
            Dictionary <string, int> lineNumbers = new Dictionary <string, int>();

            lineNumbers.Clear();
            InputVar <string> climateVarName        = new InputVar <string>("Climate Variable Name");
            InputVar <string> climateLibraryVarName = new InputVar <string>("Climate Library Variable Name");
            InputVar <string> sourceName            = new InputVar <string>("Source Name");
            InputVar <string> transform             = new InputVar <string>("Tranformation");

            IClimateVariableDefinition climateVarDefn = null;

            while (!AtEndOfInput && (CurrentName != "DerivedClimateVariables"))
            {
                StringReader currentLine = new StringReader(CurrentLine);
                ReadValue(climateVarName, currentLine);
                CheckForRepeatedName(climateVarName.Value, "var name", lineNumbers);

                climateVarDefn      = new ClimateVariableDefinition();
                climateVarDefn.Name = climateVarName.Value;

                ReadValue(sourceName, currentLine);
                climateVarDefn.SourceName = sourceName.Value;

                ReadValue(climateLibraryVarName, currentLine);
                climateVarDefn.ClimateLibVariable = climateLibraryVarName.Value;

                ReadValue(transform, currentLine);
                climateVarDefn.Transform = transform.Value;

                agentParameters.ClimateVars.Add(climateVarDefn);
                GetNextLine();
            }
            // Read Derived Climate Variables
            ReadName("DerivedClimateVariables");
            lineNumbers.Clear();
            InputVar <string>       derivedClimateVarName = new InputVar <string>("Derived Climate Variable Name");
            InputVar <string>       derSource             = new InputVar <string>("Derived Climate Variable Source");
            InputVar <string>       derVariableName       = new InputVar <string>("Derived Climate Variable source Variable Name");
            InputVar <string>       function           = new InputVar <string>("Function");
            InputVar <string>       time               = new InputVar <string>("Time");
            InputVar <int>          count              = new InputVar <int>("Count");
            IDerivedClimateVariable derivedClimateVars = null;
            Queue <string>          formulaVars        = new Queue <string>();

            while (!AtEndOfInput && !(formulaVars.Contains(CurrentName)))
            {
                StringReader currentLine = new StringReader(CurrentLine);
                ReadValue(derivedClimateVarName, currentLine);
                CheckForRepeatedName(derivedClimateVarName.Value, "var name", lineNumbers);

                derivedClimateVars      = new DerivedClimateVariable();
                derivedClimateVars.Name = derivedClimateVarName.Value;

                ReadValue(derSource, currentLine);
                derivedClimateVars.Source = derSource.Value;

                if (derivedClimateVars.Source == "Formula")
                {
                    formulaVars.Enqueue(derivedClimateVars.Name);
                }

                ReadValue(derVariableName, currentLine);
                derivedClimateVars.ClimateVariable = derVariableName.Value;

                ReadValue(function, currentLine);
                derivedClimateVars.Function = function.Value;

                ReadValue(time, currentLine);
                derivedClimateVars.Time = time.Value;

                ReadValue(count, currentLine);
                derivedClimateVars.Count = count.Value;

                agentParameters.DerivedClimateVars.Add(derivedClimateVars);

                GetNextLine();
            }

            foreach (string formulaName in formulaVars)
            {
                // Read Temp Index model
                ReadName(formulaName);
                formulaVars.Dequeue();

                lineNumbers.Clear();
                InputVar <string> tempIndexVarName     = new InputVar <string>("Temp Index Variable Name");
                InputVar <string> tempIndexParamValue  = new InputVar <string>("Parameter Value");
                List <string>     tempIndexParameters  = new List <string>();
                List <string>     tempIndexParamValues = new List <string>();
                IFormula          tempIndexModel       = new Formula();

                while (!AtEndOfInput && (CurrentName != "WeatherIndexVariables") && !(formulaVars.Contains(CurrentName)))
                {
                    StringReader currentLine = new StringReader(CurrentLine);
                    ReadValue(tempIndexVarName, currentLine);
                    CheckForRepeatedName(tempIndexVarName.Value, "var name", lineNumbers);
                    tempIndexModel.Parameters.Add(tempIndexVarName.Value);
                    //agentParameters.TempIndexModel.Parameters.Add(tempIndexVarName.Value);

                    ReadValue(tempIndexParamValue, currentLine);
                    tempIndexModel.Values.Add(tempIndexParamValue.Value);
                    //agentParameters.TempIndexModel.Values.Add(tempIndexParamValue.Value);

                    GetNextLine();
                }
                agentParameters.VarFormula = tempIndexModel;
                if (formulaVars.Count == 0)
                {
                    break;
                }
            }
            // Read Weather Index Variables
            ReadName("WeatherIndexVariables");
            lineNumbers.Clear();
            InputVar <string> weatherIndexVarName = new InputVar <string>("Weather Index Variable Name");

            while (!AtEndOfInput && (CurrentName != "AnnualWeatherIndex"))
            {
                StringReader currentLine = new StringReader(CurrentLine);
                ReadValue(weatherIndexVarName, currentLine);
                CheckForRepeatedName(weatherIndexVarName.Value, "var name", lineNumbers);

                agentParameters.WeatherIndexVars.Add(weatherIndexVarName.Value);

                GetNextLine();
            }

            //Read Annual Weather Index
            ReadName("AnnualWeatherIndex");
            WeatherIndex      weatherIndex          = new WeatherIndex();
            StringReader      annualWeatherLine     = new StringReader(CurrentLine);
            InputVar <int>    minMonth              = new InputVar <int>("Min Month");
            InputVar <int>    maxMonth              = new InputVar <int>("Max Month");
            InputVar <string> annualWeatherFunction = new InputVar <string>("Function");

            ReadValue(minMonth, annualWeatherLine);
            weatherIndex.MinMonth = minMonth.Value;
            TextReader.SkipWhitespace(annualWeatherLine);
            string currentWord = TextReader.ReadWord(annualWeatherLine);

            if (currentWord != "to")
            {
                StringBuilder message = new StringBuilder();
                message.AppendFormat("Expected \"to\" after the minimum month ({0})",
                                     minMonth.Value.String);
                if (currentWord.Length > 0)
                {
                    message.AppendFormat(", but found \"{0}\" instead", currentWord);
                }
                throw NewParseException(message.ToString());
            }
            ReadValue(maxMonth, annualWeatherLine);
            weatherIndex.MaxMonth = maxMonth.Value;

            ReadValue(annualWeatherFunction, annualWeatherLine);
            weatherIndex.Function = annualWeatherFunction.Value;

            agentParameters.AnnualWeatherIndex = weatherIndex;
            GetNextLine();

            // - Transmission Input -

            InputVar <double> tr = new InputVar <double>("TransmissionRate");

            ReadVar(tr);
            agentParameters.TransmissionRate = tr.Value;

            InputVar <double> ar = new InputVar <double>("AcquisitionRate");

            ReadVar(ar);
            agentParameters.AcquisitionRate = ar.Value;

            InputVar <string> epiMap = new InputVar <string>("InitialEpidemMap");

            ReadVar(epiMap);
            agentParameters.InitEpiMap = epiMap.Value;

            InputVar <DispersalType> dt = new InputVar <DispersalType>("DispersalType");

            ReadVar(dt);
            agentParameters.DispersalType = dt.Value;

            InputVar <DispersalTemplate> dk = new InputVar <DispersalTemplate>("DispersalKernel");

            ReadVar(dk);
            agentParameters.DispersalKernel = dk.Value;

            InputVar <int> dmax = new InputVar <int>("DispersalMaxDist");

            ReadVar(dmax);
            agentParameters.DispersalMaxDist = dmax.Value;

            InputVar <double> ac = new InputVar <double>("AlphaCoef");

            ReadVar(ac);
            agentParameters.AlphaCoef = ac.Value;

            //--------- Read In Ecoregion Table ---------------------------------------
            PlugIn.ModelCore.UI.WriteLine("Begin parsing ECOREGION table.");

            InputVar <string> ecoName     = new InputVar <string>("Ecoregion Name");
            InputVar <double> ecoModifier = new InputVar <double>("Ecoregion Modifier");

            lineNumbers.Clear();
            const string DistParms = "DisturbanceModifiers";
            const string SppParms  = "EDASpeciesParameters";

            while (!AtEndOfInput && CurrentName != DistParms && CurrentName != SppParms)
            {
                StringReader currentLine = new StringReader(CurrentLine);

                ReadValue(ecoName, currentLine);
                IEcoregion ecoregion = EcoregionsDataset[ecoName.Value.Actual];
                if (ecoregion == null)
                {
                    throw new InputValueException(ecoName.Value.String,
                                                  "{0} is not an ecoregion name.",
                                                  ecoName.Value.String);
                }
                int lineNumber;
                if (lineNumbers.TryGetValue(ecoregion.Name, out lineNumber))
                {
                    throw new InputValueException(ecoName.Value.String,
                                                  "The ecoregion {0} was previously used on line {1}",
                                                  ecoName.Value.String, lineNumber);
                }
                else
                {
                    lineNumbers[ecoregion.Name] = LineNumber;
                }

                IEcoParameters ecoParms = new EcoParameters();
                agentParameters.EcoParameters[ecoregion.Index] = ecoParms;

                ReadValue(ecoModifier, currentLine);
                ecoParms.EcoModifier = ecoModifier.Value;

                CheckNoDataAfter("the " + ecoModifier.Name + " column",
                                 currentLine);
                GetNextLine();
            }

            if (CurrentName == DistParms)
            {
                //--------- Read In Disturbance Modifier Table -------------------------------
                PlugIn.ModelCore.UI.WriteLine("Begin parsing DISTURBANCE table.");

                ReadName(DistParms);

                InputVar <string> prescriptionName = new InputVar <string>("Disturbance Type");
                InputVar <int>    duration         = new InputVar <int>("Duration");
                InputVar <double> distModifier     = new InputVar <double>("Disturbance Modifier");

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


                while (!AtEndOfInput && CurrentName != SppParms)
                {
                    StringReader currentLine = new StringReader(CurrentLine);

                    ReadValue(distModifier, currentLine);

                    IDisturbanceType currentDisturbanceType = new DisturbanceType();
                    agentParameters.DisturbanceTypes.Add(currentDisturbanceType);

                    currentDisturbanceType.SHIModifier = distModifier.Value;

                    ReadValue(duration, currentLine);
                    currentDisturbanceType.ImpactDuration = duration.Value;

                    List <string> prescriptionNames = new List <string>();
                    TextReader.SkipWhitespace(currentLine);
                    while (currentLine.Peek() != -1)
                    {
                        ReadValue(prescriptionName, currentLine);
                        prescriptionNames.Add(prescriptionName.Value);

                        TextReader.SkipWhitespace(currentLine);
                    }
                    if (prescriptionNames.Count == 0)
                    {
                        throw NewParseException("At least one disturbance type is required.");
                    }

                    currentDisturbanceType.PrescriptionNames = prescriptionNames;

                    CheckNoDataAfter("the " + distModifier.Name + " column",
                                     currentLine);
                    GetNextLine();
                }
            }

            //--------- Read In Species Table ---------------------------------------
            PlugIn.ModelCore.UI.WriteLine("Begin parsing SPECIES table.");

            ReadName(SppParms);

            //Species Name
            InputVar <string> sppName = new InputVar <string>("Species");

            //SHI (Host Index)
            InputVar <int> lowHostAge      = new InputVar <int>("Low Host Index Age");
            InputVar <int> lowHostScore    = new InputVar <int>("Low Host Index Score");
            InputVar <int> mediumHostAge   = new InputVar <int>("Medium Host Index Age");
            InputVar <int> mediumHostScore = new InputVar <int>("Medium Host Index Score");
            InputVar <int> highHostAge     = new InputVar <int>("High Host Index Age");
            InputVar <int> highHostScore   = new InputVar <int>("High Host Index Score");

            //SHV (Vulnerability)
            InputVar <int>    lowVulnHostAge         = new InputVar <int>("Low Vulnerability Host Age");
            InputVar <double> lowVulnHostMortProb    = new InputVar <double>("Low Vulnerability Host MortProb");
            InputVar <int>    mediumVulnHostAge      = new InputVar <int>("Medium Vulnerability Host Age");
            InputVar <double> mediumVulnHostMortProb = new InputVar <double>("Medium Vulnerability Host MortProb");
            InputVar <int>    highVulnHostAge        = new InputVar <int>("High Vulnerability Host Age");
            InputVar <double> highVulnHostMortProb   = new InputVar <double>("High Vulnerability Host MortProb");

            //CFS
            InputVar <bool> cfsConifer = new InputVar <bool>("CFS Conifer type:  yes/no");

            //MORTALITY SPECIES TO CONSIDER FOR PLOTTING
            InputVar <bool> mortSppFlag = new InputVar <bool>("Mortality plot:  yes/no");

            // species to ignore in SHI calculation
            const string NegSpp = "IgnoredSpecies";

            while ((!AtEndOfInput) && (CurrentName != NegSpp))
            {
                StringReader currentLine = new StringReader(CurrentLine);

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

                ISppParameters sppParms = new SppParameters();
                agentParameters.SppParameters[species.Index] = sppParms;

                //SHI
                ReadValue(lowHostAge, currentLine);
                sppParms.LowHostAge = lowHostAge.Value;

                ReadValue(lowHostScore, currentLine);
                sppParms.LowHostScore = lowHostScore.Value;

                ReadValue(mediumHostAge, currentLine);
                sppParms.MediumHostAge = mediumHostAge.Value;

                ReadValue(mediumHostScore, currentLine);
                sppParms.MediumHostScore = mediumHostScore.Value;

                ReadValue(highHostAge, currentLine);
                sppParms.HighHostAge = highHostAge.Value;

                ReadValue(highHostScore, currentLine);
                sppParms.HighHostScore = highHostScore.Value;

                //SHV
                ReadValue(lowVulnHostAge, currentLine);
                sppParms.LowVulnHostAge = lowVulnHostAge.Value;

                ReadValue(lowVulnHostMortProb, currentLine);
                sppParms.LowVulnHostMortProb = lowVulnHostMortProb.Value;

                ReadValue(mediumVulnHostAge, currentLine);
                sppParms.MediumVulnHostAge = mediumVulnHostAge.Value;

                ReadValue(mediumVulnHostMortProb, currentLine);
                sppParms.MediumVulnHostMortProb = mediumVulnHostMortProb.Value;

                ReadValue(highVulnHostAge, currentLine);
                sppParms.HighVulnHostAge = highVulnHostAge.Value;

                ReadValue(highVulnHostMortProb, currentLine);
                sppParms.HighVulnHostMortProb = highVulnHostMortProb.Value;

                //CFS
                ReadValue(cfsConifer, currentLine);
                sppParms.CFSConifer = cfsConifer.Value;

                //MORTALITY SPECIES FLAG
                ReadValue(mortSppFlag, currentLine);
                sppParms.MortSppFlag = mortSppFlag.Value;

                CheckNoDataAfter("the " + mortSppFlag.Name + " column",
                                 currentLine);

                GetNextLine();
            }

            //--------- Read In Ignored Species List ---------------------------------------
            List <ISpecies> negSppList = new List <ISpecies>();

            if (!AtEndOfInput)
            {
                ReadName(NegSpp);
                InputVar <string> negSppName = new InputVar <string>("Ignored Spp Name");

                while (!AtEndOfInput)
                {
                    StringReader currentLine = new StringReader(CurrentLine);

                    ReadValue(negSppName, currentLine);
                    ISpecies species = SpeciesDataset[negSppName.Value.Actual];
                    if (species == null)
                    {
                        throw new InputValueException(negSppName.Value.String,
                                                      "{0} is not a species name.",
                                                      negSppName.Value.String);
                    }
                    int lineNumber;
                    if (lineNumbers.TryGetValue(species.Name, out lineNumber))
                    {
                        PlugIn.ModelCore.UI.WriteLine("WARNING: The species {0} was previously used on line {1}.  Being listed in the IgnoredSpecies list will override any settings in the Host table.", negSppName.Value.String, lineNumber);
                    }
                    else
                    {
                        lineNumbers[species.Name] = LineNumber;
                    }

                    negSppList.Add(species);

                    GetNextLine();
                }
            }
            agentParameters.NegSppList = negSppList;
            return(agentParameters);
        }