public WaterStressTable(InputParameters parameters)
        {
            H2 = parameters.GetSpeciesParameterValues<float>("H2", 0, float.MaxValue);
            H3 = parameters.GetSpeciesParameterValues<float>("H3", 0, float.MaxValue);
            H4 = parameters.GetSpeciesParameterValues<float>("H4", 0, float.MaxValue);

            foreach (ISpecies species in PlugIn.ModelCore.Species)
            {
                List<float> values = new List<float>();
                for (int ph = 0; ph <= H4[species]; ph++)
                {
                    values.Add(GetFWater(species, ph));
                }
                table[species] = values.ToArray();
                table2[species.Index] = values.ToArray();
            }
        }
예제 #2
0
        InputParameters ReadSpeciesParameters(string FileName, InputParameters parameters)
        {
            // to get the option to read species parameters from an external file
            SpeciesParameterParser parser = new SpeciesParameterParser();

            IInputParameters speciesparameters = (IInputParameters)Landis.Data.Load <IInputParameters>(FileName, parser);

            foreach (ISpecies species in PlugIn.ModelCore.Species)
            {
                parameters.TOroot[species]    = speciesparameters.TOroot[species];
                parameters.TOwood[species]    = speciesparameters.TOwood[species];
                parameters.TOfol[species]     = speciesparameters.TOfol[species];
                parameters.FolRet[species]    = speciesparameters.FolRet[species];
                parameters.AmaxA[species]     = speciesparameters.AmaxA[species];
                parameters.AmaxB[species]     = speciesparameters.AmaxB[species];
                parameters.BFolResp[species]  = speciesparameters.BFolResp[species];
                parameters.GrMstSens[species] = speciesparameters.GrMstSens[species];
                parameters.WltPnt[species]    = speciesparameters.WltPnt[species];
                parameters.DVPD1[species]     = speciesparameters.DVPD1[species];
                parameters.DVPD2[species]     = speciesparameters.DVPD2[species];
                parameters.FolN[species]      = speciesparameters.FolN[species];
                parameters.HalfSat[species]   = speciesparameters.HalfSat[species];
                parameters.MaintResp[species] = speciesparameters.MaintResp[species];
                parameters.DNSC[species]      = speciesparameters.DNSC[species];
                parameters.RtStRatio[species] = speciesparameters.RtStRatio[species];
                parameters.K[species]         = speciesparameters.K[species];
                parameters.PsnAgeRed[species] = speciesparameters.PsnAgeRed[species];
                parameters.PsnTMin[species]   = speciesparameters.PsnTMin[species];
                parameters.PsnTOpt[species]   = speciesparameters.PsnTOpt[species];
                parameters.Q10[species]       = speciesparameters.Q10[species];
                parameters.CDDFolEnd[species] = speciesparameters.CDDFolEnd[species];
                parameters.SLWmax[species]    = speciesparameters.SLWmax[species];
                parameters.SLWDel[species]    = speciesparameters.SLWDel[species];
                parameters.WUEcnst[species]   = speciesparameters.WUEcnst[species];
                parameters.GDDFolSt[species]  = speciesparameters.GDDFolSt[species];
                parameters.EstMoist[species]  = speciesparameters.EstMoist[species];
                parameters.EstRad[species]    = speciesparameters.EstRad[species];
                parameters.KWdLit[species]    = speciesparameters.KWdLit[species];
                parameters.FolLignin[species] = speciesparameters.FolLignin[species];
            }

            return(parameters);
        }
        InputParameters ReadSpeciesParameters(string FileName, InputParameters parameters)
        {
            // to get the option to read species parameters from an external file
            SpeciesParameterParser parser = new SpeciesParameterParser();

            IInputParameters speciesparameters = (IInputParameters)PlugIn.ModelCore.Load <IInputParameters>(FileName, parser);

            foreach (ISpecies species in PlugIn.ModelCore.Species)
            {
                parameters.RootTurnover[species]              = speciesparameters.RootTurnover[species];
                parameters.WoodTurnover[species]              = speciesparameters.WoodTurnover[species];
                parameters.FoliageTurnover[species]           = speciesparameters.FoliageTurnover[species];
                parameters.FolReten[species]                  = speciesparameters.FolReten[species];
                parameters.AmaxA[species]                     = speciesparameters.AmaxA[species];
                parameters.AmaxB[species]                     = speciesparameters.AmaxB[species];
                parameters.BaseFolRespFrac[species]           = speciesparameters.BaseFolRespFrac[species];
                parameters.GrowthMoistureSensitivity[species] = speciesparameters.GrowthMoistureSensitivity[species];
                parameters.WiltingPoint[species]              = speciesparameters.WiltingPoint[species];
                parameters.DVPD1[species]                     = speciesparameters.DVPD1[species];
                parameters.DVPD2[species]                     = speciesparameters.DVPD2[species];
                parameters.FolNCon[species]                   = speciesparameters.FolNCon[species];
                parameters.HalfSat[species]                   = speciesparameters.HalfSat[species];
                parameters.EstRadSensitivity[species]         = speciesparameters.EstRadSensitivity[species];
                parameters.EstMoistureSensitivity[species]    = speciesparameters.EstMoistureSensitivity[species];
                parameters.MaintResp[species]                 = speciesparameters.MaintResp[species];
                parameters.DNSC[species]          = speciesparameters.DNSC[species];
                parameters.RootStemRatio[species] = speciesparameters.RootStemRatio[species];
                parameters.K[species]             = speciesparameters.K[species];
                parameters.PsnAgeRed[species]     = speciesparameters.PsnAgeRed[species];
                parameters.PsnTMin[species]       = speciesparameters.PsnTMin[species];
                parameters.PsnTOpt[species]       = speciesparameters.PsnTOpt[species];
                parameters.RespQ10[species]       = speciesparameters.RespQ10[species];
                parameters.SenescStart[species]   = speciesparameters.SenescStart[species];
                parameters.SLWmax[species]        = speciesparameters.SLWmax[species];
                parameters.SLWDel[species]        = speciesparameters.SLWDel[species];
                parameters.WUEConst[species]      = speciesparameters.WUEConst[species];
                parameters.GDDFolStart[species]   = speciesparameters.GDDFolStart[species];
                parameters.GDDFolEnd[species]     = speciesparameters.GDDFolEnd[species];
            }

            return(parameters);
        }
예제 #4
0
        protected override IInputParameters Parse()
        {
            StringReader    currentLine;
            InputParameters parameters = new InputParameters();


            // to get the option to read species parameters from an external file
            MakeSureFileContainsKeyWord(InputParametersParser.Names.PnETSpeciesParameters);


            currentLine = new StringReader(CurrentLine);

            string line = currentLine.ReadLine().Trim();

            if (line.Contains("SpeciesName"))
            {
                line = line.Replace("SpeciesName", "");
                MakeSureAllHeadersAreThere(line);
                GetNextLine();
            }



            speciesLineNums.Clear();  //  If parser re-used (i.e., for testing purposes)

            InputVar <string> SpeciesNameHeader = new InputVar <string>("SpeciesName");

            // Make sure that all index numbers are called, if not throw an error
            bool[] AccountedFor = new bool[PlugIn.ModelCore.Species.Count];

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

                ISpecies species = ReadSpecies(currentLine);
                AccountedFor[species.Index] = true;

                foreach (string label in headerlabels)
                {
                    InputVar <float> var = new InputVar <float>(label);

                    ReadValue(var, currentLine);

                    if (TrySet(label, "FoliageTurnover", var.Value, 0, 1000, species, parameters.FoliageTurnover))
                    {
                        continue;
                    }
                    if (TrySet(label, "FolReten", var.Value, 0, 1, species, parameters.FolReten))
                    {
                        continue;
                    }
                    if (TrySet(label, "RootTurnover", var.Value, 0, 1, species, parameters.RootTurnover))
                    {
                        continue;
                    }
                    if (TrySet(label, "WoodTurnover", var.Value, 0, 1, species, parameters.WoodTurnover))
                    {
                        continue;
                    }
                    if (TrySet(label, "GDDFolStart", var.Value, 1, 2000, species, parameters.GDDFolStart))
                    {
                        continue;
                    }
                    if (TrySet(label, "GDDFolEnd", var.Value, parameters.GDDFolStart[species], float.MaxValue, species, parameters.GDDFolEnd))
                    {
                        continue;
                    }
                    if (TrySet(label, "AmaxA", var.Value, -500, 500, species, parameters.AmaxA))
                    {
                        continue;
                    }
                    if (TrySet(label, "AmaxB", var.Value, 0, float.MaxValue, species, parameters.AmaxB))
                    {
                        continue;
                    }
                    if (TrySet(label, "HalfSat", var.Value, 0, float.MaxValue, species, parameters.HalfSat))
                    {
                        continue;
                    }
                    if (TrySet(label, "BaseFolRespFrac", var.Value, 0, 1000, species, parameters.BaseFolRespFrac))
                    {
                        continue;
                    }
                    if (TrySet(label, "GrowthMoistureSensitivity", var.Value, 0, float.MaxValue, species, parameters.GrowthMoistureSensitivity))
                    {
                        continue;
                    }
                    if (TrySet(label, "WiltingPoint", var.Value, 0, 1, species, parameters.WiltingPoint))
                    {
                        continue;
                    }
                    if (TrySet(label, "PsnAgeRed", var.Value, 0, float.MaxValue, species, parameters.PsnAgeRed))
                    {
                        continue;
                    }
                    if (TrySet(label, "RespQ10", var.Value, 0, 10, species, parameters.RespQ10))
                    {
                        continue;
                    }
                    if (TrySet(label, "PsnTMin", var.Value, 0, 10, species, parameters.PsnTMin))
                    {
                        continue;
                    }
                    if (TrySet(label, "PsnTOpt", var.Value, 0, 40, species, parameters.PsnTOpt))
                    {
                        continue;
                    }
                    if (TrySet(label, "SLWmax", var.Value, 0, 1000, species, parameters.SLWmax))
                    {
                        continue;
                    }
                    if (TrySet(label, "SLWDel", var.Value, 0, 2, species, parameters.SLWDel))
                    {
                        continue;
                    }
                    if (TrySet(label, "SenescStart", var.Value, 0, 365, species, parameters.SenescStart))
                    {
                        continue;
                    }
                    if (TrySet(label, "k", var.Value, 0, 2, species, parameters.K))
                    {
                        continue;
                    }
                    if (TrySet(label, "FolNCon", var.Value, 0, 10, species, parameters.FolNCon))
                    {
                        continue;
                    }
                    if (TrySet(label, "DVPD1", var.Value, 0, 5, species, parameters.DVPD1))
                    {
                        continue;
                    }
                    if (TrySet(label, "DVPD2", var.Value, 0, 5, species, parameters.DVPD2))
                    {
                        continue;
                    }
                    if (TrySet(label, "WUEConst", var.Value, 0, float.MaxValue, species, parameters.WUEConst))
                    {
                        continue;
                    }
                    if (TrySet(label, "MaintResp", var.Value, 0, 1, species, parameters.MaintResp))
                    {
                        continue;
                    }
                    if (TrySet(label, "DNSC", var.Value, 0, 1, species, parameters.DNSC))
                    {
                        continue;
                    }
                    if (TrySet(label, "RootStemRatio", var.Value, 0, 1, species, parameters.RootStemRatio))
                    {
                        continue;
                    }

                    throw new System.Exception("Undetermined parameter label name " + label);
                }
                GetNextLine();
            }

            return(parameters);
        }
        //---------------------------------------------------------------------

        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);
        }
예제 #6
0
        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 " + landisData.Value.Actual + " not \"{0}\"" + dataFile, 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 <int> Latitude = new InputVar <int>(Names.Latitude);

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

            if (ReadOptionalName("CanopyLayerBiomassCategories"))
            {
                throw new System.Exception("CanopyLayerBiomassCategories are depreciated, use " + Names.CanopyLayersMax);
            }

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

                    InputVar <string> age = new InputVar <string>("Output age");
                    ReadValue(age, currentLine);

                    int MyAge;

                    if (int.TryParse(age.Value, out MyAge))
                    {
                        parameters.CanopyLayerAges.Add(MyAge);
                    }
                    else if (age.Value == "MAX")
                    {
                        throw new System.Exception("MAX is no longer valid for CanopyLayerAges " + dataFile + " the model automatically uses the number of layers associated with the max entered age when age exceeds max age of the top layer.");
                    }
                    else
                    {
                        throw new System.Exception("Cannot add canopy age " + age.Value + " in " + dataFile + " expecting integer");
                    }

                    InputVar <string> numbers = new InputVar <string>("Max foliage layers");
                    ReadValue(numbers, currentLine);

                    int MyNumbers;
                    if (int.TryParse(numbers.Value, out MyNumbers))
                    {
                        parameters.CanopyLayerNumbers.Add(MyNumbers);
                    }

                    else
                    {
                        throw new System.Exception("Expected integers or for CanopyLayerAges in " + dataFile);
                    }


                    GetNextLine();
                }
            }



            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);


            ReadName(Names.EcoregionParameters);


            InputVar <string> ecoregionName   = new InputVar <string>("Ecoregion");
            InputVar <int>    aet             = new InputVar <int>("AET");
            InputVar <float>  whc             = new InputVar <float>("WHC");
            InputVar <float>  PrecipLossFrac  = new InputVar <float>("PrecipLossFrac");
            InputVar <float>  LeakageFraction = new InputVar <float>("LeakageFraction");
            InputVar <float>  Porosity        = new InputVar <float>("Porosity");
            InputVar <string> climateFileName = new InputVar <string>(Names.climateFileName);

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

            string[] ReadHeaders = CurrentLine.Split(new char[] { ',', '\t', ' ' }, System.StringSplitOptions.RemoveEmptyEntries);

            if (ReadHeaders[0] != "Ecoregion")
            {
                throw new System.Exception("The first column header in ecoregion parameters in " + dataFile + " should be 'Ecoregion'. Note that the headerline should NOT be outcommented as in Biomass Succession");
            }

            string[] ExpectedHeaders = new string[] { "Ecoregion", "AET", "WHC", "PrecLossFrac", "LeakageFraction", "Porosity", Names.climateFileName };


            AssureAllHeadersAreProvided(ReadHeaders, ExpectedHeaders);

            GetNextLine();

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

                ReadValue(ecoregionName, currentLine);

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

                foreach (string label in ReadHeaders)
                {
                    if (label == "Ecoregion")
                    {
                        continue;
                    }

                    InputVar <string> var = new InputVar <string>(label);

                    ReadValue(var, currentLine);

                    if (TrySet(label, "AET", var.Value, 0, 1000, ecoregion, parameters.AET))
                    {
                        continue;
                    }
                    else if (TrySet(label, "WHC", var.Value, 0, 1000, ecoregion, parameters.WHC))
                    {
                        continue;
                    }
                    else if (TrySet(label, "PrecLossFrac", var.Value, 0, 1000, ecoregion, parameters.PrecipLossFrac))
                    {
                        continue;
                    }
                    else if (TrySet(label, "LeakageFraction", var.Value, 0, 1000, ecoregion, parameters.LeakageFrac))
                    {
                        continue;
                    }
                    else if (TrySet(label, "Porosity", var.Value, 0, 1000, ecoregion, parameters.Porosity))
                    {
                        continue;
                    }
                    else if (TrySet(label, Names.climateFileName, var.Value, ecoregion, parameters.climateFileName))
                    {
                        continue;
                    }
                    else
                    {
                        throw new System.Exception("Cannot assign parameter " + label);
                    }
                }
                GetNextLine();
            }


            foreach (IEcoregion ecoregion in PlugIn.modelCore.Ecoregions)
            {
                if (parameters.Porosity[ecoregion] < parameters.WHC[ecoregion])
                {
                    throw new System.Exception("Porosity for " + ecoregion + " cannot exceed water holding capacity in " + dataFile);
                }
            }

            return(parameters);
        }
예제 #7
0
        protected override IInputParameters Parse()
        {
            StringReader    currentLine;
            InputParameters parameters = new InputParameters();


            // to get the option to read species parameters from an external file
            MakeSureFileContainsKeyWord(InputParametersParser.Names.PnETSpeciesParameters);


            currentLine = new StringReader(CurrentLine);

            string line = currentLine.ReadLine().Trim();

            if (line.Contains("SpeciesName"))
            {
                line = line.Replace("SpeciesName", "");
                string[] Headers = new string[] { "TOfol", "FolRet", "TOroot", "TOwood", "GDDFolSt", "AmaxA", "AmaxB", "HalfSat", "BFolResp", "GrMstSens", "WltPnt", "PsnAgeRed",
                                                  "Q10", "PsnTMin", "PsnTOpt", "SLWmax", "SLWDel", "CDDFolEnd", "k", "FolN",
                                                  "DVPD1", "DVPD2", "WUEcnst", "MaintResp", "DNSC", "RtStRatio", "EstMoist", "EstRad", "KWdLit", "FolLignin" };


                headerlabels = CheckHeaderLabels(line, Headers);
                GetNextLine();
            }



            speciesLineNums.Clear();  //  If parser re-used (i.e., for testing purposes)

            InputVar <string> SpeciesNameHeader = new InputVar <string>("SpeciesName");

            // Make sure that all index numbers are called, if not throw an error
            bool[] AccountedFor = new bool[PlugIn.ModelCore.Species.Count];

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

                ISpecies species = ReadSpecies(currentLine);
                AccountedFor[species.Index] = true;

                foreach (string label in headerlabels)
                {
                    InputVar <float> var = new InputVar <float>(label);

                    ReadValue(var, currentLine);

                    if (TrySet(label, "TOfol", var.Value, 0, 1000, species, parameters.TOfol))
                    {
                        continue;
                    }
                    if (TrySet(label, "FolRet", var.Value, 0, 1, species, parameters.FolRet))
                    {
                        continue;
                    }
                    if (TrySet(label, "TOroot", var.Value, 0, 1, species, parameters.TOroot))
                    {
                        continue;
                    }
                    if (TrySet(label, "TOwood", var.Value, 0, 1, species, parameters.TOwood))
                    {
                        continue;
                    }
                    if (TrySet(label, "GDDFolSt", var.Value, 1, 2000, species, parameters.GDDFolSt))
                    {
                        continue;
                    }
                    if (TrySet(label, "AmaxA", var.Value, -500, 500, species, parameters.AmaxA))
                    {
                        continue;
                    }
                    if (TrySet(label, "AmaxB", var.Value, 0, float.MaxValue, species, parameters.AmaxB))
                    {
                        continue;
                    }
                    if (TrySet(label, "HalfSat", var.Value, 0, float.MaxValue, species, parameters.HalfSat))
                    {
                        continue;
                    }
                    if (TrySet(label, "BFolResp", var.Value, 0, 1000, species, parameters.BFolResp))
                    {
                        continue;
                    }
                    if (TrySet(label, "GrMstSens", var.Value, 0.1F, float.MaxValue, species, parameters.GrMstSens))
                    {
                        continue;
                    }
                    if (TrySet(label, "WltPnt", var.Value, 0, 1, species, parameters.WltPnt))
                    {
                        continue;
                    }
                    if (TrySet(label, "PsnAgeRed", var.Value, 1.0F / float.MaxValue, float.MaxValue, species, parameters.PsnAgeRed))
                    {
                        continue;
                    }
                    if (TrySet(label, "Q10", var.Value, 0, 10, species, parameters.Q10))
                    {
                        continue;
                    }
                    if (TrySet(label, "PsnTMin", var.Value, -10, 10, species, parameters.PsnTMin))
                    {
                        continue;
                    }
                    if (TrySet(label, "PsnTOpt", var.Value, 0, 40, species, parameters.PsnTOpt))
                    {
                        continue;
                    }
                    if (TrySet(label, "SLWmax", var.Value, 0, 1000, species, parameters.SLWmax))
                    {
                        continue;
                    }
                    if (TrySet(label, "SLWDel", var.Value, 0, 2, species, parameters.SLWDel))
                    {
                        continue;
                    }
                    if (TrySet(label, "CDDFolEnd", var.Value, 0, 5000, species, parameters.CDDFolEnd))
                    {
                        continue;
                    }
                    if (TrySet(label, "k", var.Value, 0, 2, species, parameters.K))
                    {
                        continue;
                    }
                    if (TrySet(label, "FolN", var.Value, 0, 10, species, parameters.FolN))
                    {
                        continue;
                    }
                    if (TrySet(label, "DVPD1", var.Value, 0, 5, species, parameters.DVPD1))
                    {
                        continue;
                    }
                    if (TrySet(label, "DVPD2", var.Value, 0, 5, species, parameters.DVPD2))
                    {
                        continue;
                    }
                    if (TrySet(label, "WUEcnst", var.Value, 0, float.MaxValue, species, parameters.WUEcnst))
                    {
                        continue;
                    }
                    if (TrySet(label, "MaintResp", var.Value, 0, 1, species, parameters.MaintResp))
                    {
                        continue;
                    }
                    if (TrySet(label, "DNSC", var.Value, 0, 10, species, parameters.DNSC))
                    {
                        continue;
                    }
                    if (TrySet(label, "RtStRatio", var.Value, 0, 1, species, parameters.RtStRatio))
                    {
                        continue;
                    }
                    if (TrySet(label, "EstMoist", var.Value, 0, float.MaxValue, species, parameters.EstMoist))
                    {
                        continue;
                    }
                    if (TrySet(label, "EstRad", var.Value, 0, float.MaxValue, species, parameters.EstRad))
                    {
                        continue;
                    }
                    if (TrySet(label, "KWdLit", var.Value, 0, float.MaxValue, species, parameters.KWdLit))
                    {
                        continue;
                    }

                    if (label == "KNWdLit")
                    {
                        throw new System.Exception("KNWdLit is depreciated per 6/24/2014, foliage decomposition rate is calculated from leaf lignin (FolLignin) and site specific AET");
                    }

                    if (TrySet(label, "FolLignin", var.Value, 0, float.MaxValue, species, parameters.FolLignin))
                    {
                        continue;
                    }

                    throw new System.Exception("Undetermined parameter label name " + label);
                }
                GetNextLine();
            }

            foreach (ISpecies spc in PlugIn.modelCore.Species)
            {
                if (AccountedFor[spc.Index] == false)
                {
                    throw new System.Exception(spc.Name + " is not accounted for in PnET-Species parameter file");
                }
            }
            return(parameters);
        }