Inheritance: IFuelType
Example #1
0
        //---------------------------------------------------------------------

        public InputParameters()
        {
            seasons            = new SeasonParameters[3];
            damages            = new List <IFireDamage>();
            dynamicFireRegions = new List <IDynamicFireRegion>();
            dynamicWeather     = new List <IDynamicWeather>();

            fuelTypeParameters = new FuelType[100];
            for (int i = 0; i < 100; i++)
            {
                fuelTypeParameters[i] = new FuelType();
            }
        }
        //---------------------------------------------------------------------

        public InputParameters()
        {
            seasons = new SeasonParameters[3];
            damages = new List<IFireDamage>();
            dynamicFireRegions = new List<IDynamicFireRegion>();
            dynamicWeather = new List<IDynamicWeather>();
            
            fuelTypeParameters = new FuelType[100];
            for(int i=0; i<100; i++)
                fuelTypeParameters[i] = new FuelType();
        }
Example #3
0
        //---------------------------------------------------------------------

        protected override IInputParameters Parse()
        {
            ReadLandisDataVar();

            //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>("Timestep");

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

            InputVar <SizeType> st = new InputVar <SizeType>("EventSizeType");

            ReadVar(st);
            parameters.FireSizeType = st.Value;

            InputVar <bool> bbui = new InputVar <bool>("BuildUpIndex");

            ReadVar(bbui);
            parameters.BUI = bbui.Value;

            InputVar <int> wrand = new InputVar <int>("WeatherRandomizer");

            if (ReadOptionalVar(wrand))
            {
                if (wrand.Value.Actual < 0 || wrand.Value.Actual > 4)
                {
                    throw new InputValueException(wrand.Value.String,
                                                  "The weather randomizer code {0} must be 0 - 4",
                                                  wrand.Value.Actual);
                }
                else
                {
                    PlugIn.WeatherRandomizer = wrand.Value;
                }
            }

            //----------------------------------------------------------
            // First, read table of additional parameters for ecoregions
            PlugIn.ModelCore.UI.WriteLine("   Loading FireRegion data...");
            //IEditableFireRegionDataset dataset = new EditableFireRegionDataset();
            List <IFireRegion> dataset = new List <IFireRegion>(0);

            Dictionary <string, int> nameLineNumbers    = new Dictionary <string, int>();
            Dictionary <ushort, int> mapCodeLineNumbers = new Dictionary <ushort, int>();

            InputVar <string> name              = new InputVar <string>("Name");
            InputVar <ushort> mapCode           = new InputVar <ushort>("Map Code");
            InputVar <double> meanSize          = new InputVar <double>("Mean Size");
            InputVar <double> standardDeviation = new InputVar <double>("Standard Deviation");
            InputVar <int>    maxSize           = new InputVar <int>("Max Size");
            InputVar <int>    spLo              = new InputVar <int>("Spring Low FMC");
            InputVar <int>    spHi              = new InputVar <int>("Spring High FMC");
            InputVar <double> spHiPro           = new InputVar <double>("Spring High FMC proportion");
            InputVar <int>    suLo              = new InputVar <int>("Summer Low FMC");
            InputVar <int>    suHi              = new InputVar <int>("Summer High FMC");
            InputVar <double> suHiPro           = new InputVar <double>("Summer High FMC proportion");
            InputVar <int>    faLo              = new InputVar <int>("Fall Low FMC");
            InputVar <int>    faHi              = new InputVar <int>("Fall High FMC");
            InputVar <double> faHiPro           = new InputVar <double>("Fall High FMC proportion");
            InputVar <int>    ftc = new InputVar <int>("Open Type Fuel");
            InputVar <double> ein = new InputVar <double>("FireRegion Ignition Number");

            Dictionary <string, int> lineNumbers              = new Dictionary <string, int>();
            const string             DynamicFireRegionTable   = "DynamicEcoregionTable";
            const string             InitialFireEcoregionsMap = "InitialFireEcoregionsMap";

            int fireRegionIndex = 0;

            while (!AtEndOfInput && CurrentName != InitialFireEcoregionsMap)
            {
                //IEditableFireRegionParameters ecoparameters = new EditableFireRegionParameters();
                IFireRegion ecoparameters = new FireRegion(fireRegionIndex);

                dataset.Add(ecoparameters);

                StringReader currentLine = new StringReader(CurrentLine);

                int lineNumber;

                ReadValue(mapCode, currentLine);
                if (mapCodeLineNumbers.TryGetValue(mapCode.Value.Actual, out lineNumber))
                {
                    throw new InputValueException(mapCode.Value.String,
                                                  "The map code {0} was previously used on line {1}",
                                                  mapCode.Value.Actual, lineNumber);
                }
                else
                {
                    mapCodeLineNumbers[mapCode.Value.Actual] = LineNumber;
                }
                ecoparameters.MapCode = mapCode.Value;

                ReadValue(name, currentLine);
                if (nameLineNumbers.TryGetValue(name.Value.Actual, out lineNumber))
                {
                    throw new InputValueException(name.Value.String,
                                                  "The name \"{0}\" was previously used on line {1}",
                                                  name.Value.Actual, lineNumber);
                }
                else
                {
                    nameLineNumbers[name.Value.Actual] = LineNumber;
                }
                ecoparameters.Name = name.Value;

                ReadValue(meanSize, currentLine);
                ecoparameters.MeanSize = meanSize.Value;

                ReadValue(standardDeviation, currentLine);
                ecoparameters.StandardDeviation = standardDeviation.Value;

                ReadValue(maxSize, currentLine);
                ecoparameters.MaxSize = maxSize.Value;

                ReadValue(spLo, currentLine);
                ecoparameters.SpringFMCLo = spLo.Value;

                ReadValue(spHi, currentLine);
                ecoparameters.SpringFMCHi = spHi.Value;

                ReadValue(spHiPro, currentLine);
                ecoparameters.SpringFMCHiProp = spHiPro.Value;

                ReadValue(suLo, currentLine);
                ecoparameters.SummerFMCLo = suLo.Value;

                ReadValue(suHi, currentLine);
                ecoparameters.SummerFMCHi = suHi.Value;

                ReadValue(suHiPro, currentLine);
                ecoparameters.SummerFMCHiProp = suHiPro.Value;

                ReadValue(faLo, currentLine);
                ecoparameters.FallFMCLo = faLo.Value;

                ReadValue(faHi, currentLine);
                ecoparameters.FallFMCHi = faHi.Value;

                ReadValue(faHiPro, currentLine);
                ecoparameters.FallFMCHiProp = faHiPro.Value;

                ReadValue(ftc, currentLine);
                ecoparameters.OpenFuelType = ftc.Value;

                ReadValue(ein, currentLine);
                ecoparameters.EcoIgnitionNum = ein.Value;

                fireRegionIndex++;

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

                GetNextLine();
            }

            //Moved below since FireRegions now include seasonRecords
            FireRegions.Dataset = dataset;

            InputVar <string> ecoregionsMap = new InputVar <string>("InitialFireEcoregionsMap");

            ReadVar(ecoregionsMap);
            FireRegions.ReadMap(ecoregionsMap.Value);

            //----------------------------------------------------------
            // Read in the table of dynamic ecoregions:

            ReadName(DynamicFireRegionTable);

            InputVar <string> mapName = new InputVar <string>("Dynamic Map Name");
            InputVar <int>    year    = new InputVar <int>("Year to read in new FireRegion Map");

            const string GroundSlopeFile = "GroundSlopeFile";
            const string Season          = "SeasonTable";
            double       previousYear    = 0;

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

                //IEditableDynamicFireRegion dynEco = new EditableDynamicFireRegion();
                IDynamicFireRegion dynEco = new DynamicFireRegion();

                parameters.DynamicFireRegions.Add(dynEco);

                ReadValue(year, currentLine);
                dynEco.Year = year.Value;

                if (year.Value.Actual <= previousYear)
                {
                    throw new InputValueException(year.Value.String,
                                                  "Year must > the year ({0}) of the preceeding ecoregion map",
                                                  previousYear);
                }

                previousYear = year.Value.Actual;


                ReadValue(mapName, currentLine);
                dynEco.MapName = mapName.Value;

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


            //----------------------------------------------------------
            // Optional topographic maps
            InputVar <string> groundSlopeFile = new InputVar <string>("GroundSlopeFile");

            if (ReadOptionalVar(groundSlopeFile))
            {
                PlugIn.ModelCore.UI.WriteLine("   Loading Slope data...");

                Topography.ReadGroundSlopeMap(groundSlopeFile.Value);
                //ValidatePath(groundSlopeFile.Value);
                //FireRegions.Dataset = FireRegionDataset.ReadFile(ecoregionsFile.Value);

                InputVar <string> uphillSlopeMap = new InputVar <string>("UphillSlopeAzimuthMap");
                ReadVar(uphillSlopeMap);

                PlugIn.ModelCore.UI.WriteLine("   Loading Azimuth data...");

                Topography.ReadUphillSlopeAzimuthMap(uphillSlopeMap.Value);
            }

            //-------------------------------------------------------------------
            //  Read table of Seasons.
            //  Arranged in any order.
            PlugIn.ModelCore.UI.WriteLine("   Loading Seasons data...");

            ReadName(Season);

            InputVar <SeasonName> seasonName = new InputVar <SeasonName>("Season Name");
            InputVar <double>     fp         = new InputVar <double>("Season fire probability");
            InputVar <int>        cc         = new InputVar <int>("Curing Percent");
            InputVar <LeafOnOff>  loo        = new InputVar <LeafOnOff>("Leaves on or off?");
            InputVar <double>     dlp        = new InputVar <double>("Day length proportion");

            const string DynamicWeatherTable = "DynamicWeatherTable";
            const string WeatherPath         = "InitialWeatherDatabase";

            int sn = 1;

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

                ReadValue(seasonName, currentLine);
                sn = (int)seasonName.Value.Actual;

                //PlugIn.ModelCore.UI.WriteLine("      Season index = {0}.", sn);

                ISeasonParameters seasonParms = new SeasonParameters();
                parameters.SeasonParameters[sn] = seasonParms;

                seasonParms.NameOfSeason = seasonName.Value;

                ReadValue(loo, currentLine);
                seasonParms.LeafStatus = loo.Value;

                ReadValue(fp, currentLine);
                seasonParms.FireProbability = fp.Value;

                ReadValue(cc, currentLine);
                seasonParms.PercentCuring = cc.Value;

                ReadValue(dlp, currentLine);
                seasonParms.DayLengthProp = dlp.Value;

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

                GetNextLine();
            }
            //------------------------------------------------------------------
            //  Read path to weather table

            InputVar <string> weatherPath = new InputVar <string>("InitialWeatherDatabase");

            ReadVar(weatherPath);
            parameters.InitialWeatherPath = weatherPath.Value;

            //----------------------------------------------------------
            // Read in the table of dynamic weather:

            ReadName(DynamicWeatherTable);

            InputVar <string> fileName = new InputVar <string>("Dynamic Database Name");
            InputVar <int>    yearW    = new InputVar <int>("Year to read in new Weather data");

            const string FuelTypes = "FuelTypeTable";

            previousYear = 0;

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

                IDynamicWeather dynWeather = new DynamicWeather();
                parameters.DynamicWeather.Add(dynWeather);

                ReadValue(yearW, currentLine);
                dynWeather.Year = yearW.Value;

                if (yearW.Value.Actual <= previousYear)
                {
                    throw new InputValueException(yearW.Value.String,
                                                  "Year must > the year ({0}) of the preceeding weather database",
                                                  previousYear);
                }

                previousYear = yearW.Value.Actual;


                ReadValue(fileName, currentLine);
                dynWeather.FileName = fileName.Value;

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

            //-------------------------------------------------------------------
            //  Read table of Fuel Types.
            //  Arranged in any order.
            PlugIn.ModelCore.UI.WriteLine("   Loading Fuels data...");

            ReadName(FuelTypes);

            InputVar <int>             fuelIndex = new InputVar <int>("Fuel Type Index");
            InputVar <BaseFuelType>    bft       = new InputVar <BaseFuelType>("Base Fuel Type");
            InputVar <SurfaceFuelType> sft       = new InputVar <SurfaceFuelType>("Surface Fuel Type");
            InputVar <double>          ip        = new InputVar <double>("Fuel type initiation probability");
            InputVar <int>             a         = new InputVar <int>("Fuel type coefficient - a");
            InputVar <double>          b         = new InputVar <double>("Fuel type coefficient - b");
            InputVar <double>          c         = new InputVar <double>("Fuel type coefficient - c");
            InputVar <double>          q         = new InputVar <double>("Fuel type coefficient - q");
            InputVar <int>             bui       = new InputVar <int>("Fuel type coefficient - bui");
            InputVar <double>          maxbe     = new InputVar <double>("Fuel type coefficient - Maximum BE");
            InputVar <int>             cbh       = new InputVar <int>("Crown Base Height");

            const string FireDamage        = "FireDamageTable";
            const string SeverityCalibrate = "SeverityCalibrationFactor";

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

                IFuelType fuelParms = new FuelType();

                ReadValue(fuelIndex, currentLine);
                fuelParms.FuelIndex = fuelIndex.Value;

                ReadValue(bft, currentLine);
                fuelParms.BaseFuel = bft.Value;

                ReadValue(sft, currentLine);
                fuelParms.SurfaceFuel = sft.Value;

                ReadValue(ip, currentLine);
                fuelParms.InitiationProbability = ip.Value;

                ReadValue(a, currentLine);
                fuelParms.A = a.Value;

                ReadValue(b, currentLine);
                fuelParms.B = b.Value;

                ReadValue(c, currentLine);
                fuelParms.C = c.Value;

                ReadValue(q, currentLine);
                fuelParms.Q = q.Value;

                ReadValue(bui, currentLine);
                fuelParms.BUI = bui.Value;

                ReadValue(maxbe, currentLine);
                fuelParms.MaxBE = maxbe.Value;

                ReadValue(cbh, currentLine);
                fuelParms.CBH = cbh.Value;

                parameters.FuelTypeParameters[fuelIndex.Value] = fuelParms;

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

                GetNextLine();
            }

            //Read in Severity Calibration Factor
            InputVar <double> sevCalib = new InputVar <double>("SeverityCalibrationFactor");

            ReadVar(sevCalib);
            parameters.SeverityCalibrate = sevCalib.Value;


            //-------------------------------------------------------------------
            //  Read table of Fire Damage classes.
            //  Damages are in increasing order.
            PlugIn.ModelCore.UI.WriteLine("   Loading Fire Damage data...");

            ReadName(FireDamage);

            InputVar <Percentage> maxAge = new InputVar <Percentage>("Max Survival Age");
            InputVar <int>        severTolerDifference = new InputVar <int>("Severity Tolerance Diff");

            const string MapNames       = "MapNames";
            int          previousNumber = -5;
            double       previousMaxAge = 0.0;

            while (!AtEndOfInput && CurrentName != MapNames &&
                   previousNumber != 4)
            {
                StringReader currentLine = new StringReader(CurrentLine);

                IFireDamage damage = new FireDamage();
                parameters.FireDamages.Add(damage);

                ReadValue(maxAge, currentLine);
                damage.MaxAge = maxAge.Value;
                if (maxAge.Value.Actual <= 0)
                {
                    //  Maximum age for damage must be > 0%
                    throw new InputValueException(maxAge.Value.String,
                                                  "Must be > 0% for the all damage classes");
                }
                if (maxAge.Value.Actual > 1)
                {
                    //  Maximum age for damage must be <= 100%
                    throw new InputValueException(maxAge.Value.String,
                                                  "Must be <= 100% for the all damage classes");
                }
                //  Maximum age for every damage must be >
                //  maximum age of previous damage.
                if (maxAge.Value.Actual <= previousMaxAge)
                {
                    throw new InputValueException(maxAge.Value.String,
                                                  "MaxAge must > the maximum age ({0}) of the preceeding damage class",
                                                  previousMaxAge);
                }

                previousMaxAge = (double)maxAge.Value.Actual;

                ReadValue(severTolerDifference, currentLine);
                damage.SeverTolerDifference = severTolerDifference.Value;

                //Check that the current damage number is > than
                //the previous number (numbers are must be in increasing
                //order).
                if (severTolerDifference.Value.Actual <= previousNumber)
                {
                    throw new InputValueException(severTolerDifference.Value.String,
                                                  "Expected the damage number {0} to be greater than previous {1}",
                                                  damage.SeverTolerDifference, previousNumber);
                }
                if (severTolerDifference.Value.Actual > 4)
                {
                    throw new InputValueException(severTolerDifference.Value.String,
                                                  "Expected the damage number {0} to be less than 5",
                                                  damage.SeverTolerDifference);
                }

                previousNumber = severTolerDifference.Value.Actual;

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

            if (parameters.FireDamages.Count == 0)
            {
                throw NewParseException("No damage classes defined.");
            }

            InputVar <string> mapNames = new InputVar <string>(MapNames);

            ReadVar(mapNames);
            parameters.MapNamesTemplate = mapNames.Value;

            InputVar <string> logFile = new InputVar <string>("LogFile");

            ReadVar(logFile);
            parameters.LogFileName = logFile.Value;

            InputVar <string> summaryLogFile = new InputVar <string>("SummaryLogFile");

            ReadVar(summaryLogFile);
            parameters.SummaryLogFileName = summaryLogFile.Value;

            CheckNoDataAfter(string.Format("the {0} parameter", summaryLogFile.Name));

            return(parameters); //.GetComplete();
        }