//--------------------------------------------------------------------- public static DataTable ReadWeatherFile(string path, IDynamicInputRecord[] regionRecords, ISeasonParameters[] seasonParms) { PlugIn.ModelCore.UI.WriteLine(" Loading Weather Data..."); CSVParser weatherParser = new CSVParser(); DataTable weatherTable = weatherParser.ParseToDataTable(path); int recordCount = 0; for (int i = 0; i <= 2; i++) { string seasName = seasonParms[i].NameOfSeason.ToString(); foreach (IDynamicInputRecord fire_region in regionRecords) { string ecoName = fire_region.Name; //PlugIn.ModelCore.Log.WriteLine("Read Weather File: Season={0}, FireRegion={1}.", seasName, ecoName); string selectText = ("FireRegion = '" + ecoName + "' AND Season = '" + seasName + "'"); //PlugIn.ModelCore.Log.WriteLine("Read Weather File SelectText = {0}.", selectText); DataRow[] foundRows = weatherTable.Select(selectText); if (foundRows.Length == 0) { selectText = ("FireRegion = 'All' AND Season = '" + seasName + "'"); foundRows = weatherTable.Select(selectText); } if ((foundRows.Length == 0) && (seasonParms[i].FireProbability > 0) && (fire_region.EcoIgnitionNum > 0)) { PlugIn.ModelCore.UI.WriteLine("WARNING (Ln 430): FireRegion " + ecoName + ", Season " + seasName + " has fire probability > 0, but 0 weather records. Using alternate season."); if (seasName == "Spring") { selectText = ("FireRegion = '" + ecoName + "' AND Season = 'Summer'"); //PlugIn.ModelCore.Log.WriteLine("Read Weather File SelectText = {0}.", selectText); foundRows = weatherTable.Select(selectText); if (foundRows.Length == 0) { selectText = ("FireRegion = '" + ecoName + "' AND Season = 'Fall'"); //PlugIn.ModelCore.Log.WriteLine("Read Weather File SelectText = {0}.", selectText); foundRows = weatherTable.Select(selectText); } if (foundRows.Length == 0) { PlugIn.ModelCore.UI.WriteLine("WARNING (Ln 445): FireRegion " + ecoName + " has fire probability > 0, but 0 weather records. No fires will occur in this fire region."); } } if (seasName == "Fall") { selectText = ("FireRegion = '" + ecoName + "' AND Season = 'Summer'"); //PlugIn.ModelCore.Log.WriteLine("Read Weather File SelectText = {0}.", selectText); foundRows = weatherTable.Select(selectText); if (foundRows.Length == 0) { selectText = ("FireRegion = '" + ecoName + "' AND Season = 'Spring'"); //PlugIn.ModelCore.Log.WriteLine("Read Weather File SelectText = {0}.", selectText); foundRows = weatherTable.Select(selectText); } if (foundRows.Length == 0) { PlugIn.ModelCore.UI.WriteLine("WARNING (Ln 464): FireRegion " + ecoName + " has fire probability > 0, but 0 weather records. No fires will occur in this fire region."); } } if (seasName == "Summer") { if (PlugIn.ModelCore.GenerateUniform() >= 0.5) { selectText = ("FireRegion = '" + ecoName + "' AND Season = 'Spring'"); //PlugIn.ModelCore.Log.WriteLine("Read Weather File SelectText = {0}.", selectText); foundRows = weatherTable.Select(selectText); if (foundRows.Length == 0) { selectText = ("FireRegion = '" + ecoName + "' AND Season = 'Fall'"); //PlugIn.ModelCore.Log.WriteLine("Read Weather File SelectText = {0}.", selectText); foundRows = weatherTable.Select(selectText); } if (foundRows.Length == 0) { PlugIn.ModelCore.UI.WriteLine("WARNING (Ln 485): FireRegion " + ecoName + " has fire probability > 0, but 0 weather records. No fires will occur in this fire region."); } } else { selectText = ("FireRegion = '" + ecoName + "' AND Season = 'Fall'"); //PlugIn.ModelCore.Log.WriteLine("Read Weather File SelectText = {0}.", selectText); foundRows = weatherTable.Select(selectText); if (foundRows.Length == 0) { selectText = ("FireRegion = '" + ecoName + "' AND Season = 'Spring'"); //PlugIn.ModelCore.Log.WriteLine("Read Weather File SelectText = {0}.", selectText); foundRows = weatherTable.Select(selectText); } if (foundRows.Length == 0) { PlugIn.ModelCore.UI.WriteLine("WARNING (Ln 503): FireRegion " + ecoName + " has fire probability > 0, but 0 weather records. No fires will occur in this fire region."); } } } } if(foundRows.Length > 0) { //Input validation double WSV, FFMC, BUI; int WINDDIR, FWIBIN; for(int j = 0; j < foundRows.Length; j ++) //weatherDataSet.Tables["Table"].Rows) { DataRow myDataRow = foundRows[j]; //WSV = (double)myDataRow["WSV"]; WSV = Convert.ToDouble(myDataRow["WSV"]); //Console.WriteLine("WSV: {0}", WSV); if (WSV < 0.0) { throw new System.ApplicationException("Error: Wind Speed < 0: FireRegion = " + ecoName + "; Season = " + seasName); } FFMC = Convert.ToDouble(myDataRow["FFMC"]); //Console.WriteLine("FFMC: {0}", FFMC); if (FFMC < 0.0) { throw new System.ApplicationException("Error: FFMC < 0: FireRegion = " + ecoName + "; Season = " + seasName); } else if (FFMC > 100.0) { throw new System.ApplicationException("Error: FFMC > 100: FireRegion = " + ecoName + "; Season = " + seasName); } BUI = Convert.ToDouble(myDataRow["BUI"]); //Console.WriteLine("BUI: {0}", BUI); if (BUI < 0.0) { throw new System.ApplicationException("Error: BUI < 0: FireRegion = " + ecoName + "; Season = " + seasName); } WINDDIR = (int) myDataRow["WindDir"]; //Console.WriteLine("WindDir: {0}", WINDDIR); if (WINDDIR < 0) { throw new System.ApplicationException("Error: WINDDIR < 0: FireRegion = " + ecoName + "; Season = " + seasName); } else if (WINDDIR > 360) { throw new System.ApplicationException("Error: WINDDIR > 360: FireRegion = " + ecoName + "; Season = " + seasName); } FWIBIN = (int) myDataRow["FWIBin"]; //Console.WriteLine("FWIBIN: {0}", FWIBIN); if (FWIBIN < 1) { throw new System.ApplicationException("Error: FWIBIN < 1: FireRegion = " + ecoName + "; Season = " + seasName); } else if (FWIBIN > 5) { throw new System.ApplicationException("Error: FWIBIN > 5: FireRegion = " + ecoName + "; Season = " + seasName); } } } if(seasName == "Fall") { fire_region.FallRecords = recordCount; } else if (seasName == "Spring") { fire_region.SpringRecords = recordCount; } else if (seasName == "Summer") { fire_region.SummerRecords = recordCount; } } } return weatherTable; }
//--------------------------------------------------------------------- public static DataTable ReadWeatherFile(string path, List <IFireRegion> ecoDataSet, ISeasonParameters[] seasonParms) { PlugIn.ModelCore.UI.WriteLine(" Loading Weather Data..."); CSVParser weatherParser = new CSVParser(); DataTable weatherTable = weatherParser.ParseToDataTable(path); int recordCount = 0; for (int i = 0; i <= 2; i++) { string seasName = seasonParms[i].NameOfSeason.ToString(); foreach (IFireRegion fire_region in ecoDataSet) { string ecoName = fire_region.Name; //PlugIn.ModelCore.UI.WriteLine("Read Weather File: Season={0}, FireRegion={1}.", seasName, ecoName); string selectText = ("Ecoregion = '" + ecoName + "' AND Season = '" + seasName + "'"); //PlugIn.ModelCore.UI.WriteLine("Read Weather File SelectText = {0}.", selectText); DataRow[] foundRows = weatherTable.Select(selectText); if (foundRows.Length == 0) { selectText = ("Ecoregion = 'All' AND Season = '" + seasName + "'"); foundRows = weatherTable.Select(selectText); } if (foundRows.Length > 0) { //Input validation double WSV, FFMC, BUI; int WINDDIR, FWIBIN; for (int j = 0; j < foundRows.Length; j++) //weatherDataSet.Tables["Table"].Rows) { DataRow myDataRow = foundRows[j]; WSV = System.Convert.ToDouble(myDataRow["WSV"]); //Console.WriteLine("WSV: {0}", WSV); if (WSV < 0.0) { throw new System.ApplicationException("Error: Wind Speed < 0: FireRegion = " + ecoName + "; Season = " + seasName); } FFMC = System.Convert.ToDouble(myDataRow["FFMC"]); //Console.WriteLine("FFMC: {0}", FFMC); if (FFMC < 0.0) { throw new System.ApplicationException("Error: FFMC < 0: FireRegion = " + ecoName + "; Season = " + seasName); } else if (FFMC > 100.0) { throw new System.ApplicationException("Error: FFMC > 100: FireRegion = " + ecoName + "; Season = " + seasName); } BUI = System.Convert.ToDouble(myDataRow["BUI"]); //Console.WriteLine("BUI: {0}", BUI); if (BUI < 0.0) { throw new System.ApplicationException("Error: BUI < 0: FireRegion = " + ecoName + "; Season = " + seasName); } WINDDIR = System.Convert.ToInt32(myDataRow["WindDir"]); //Console.WriteLine("WindDir: {0}", WINDDIR); if (WINDDIR < 0) { throw new System.ApplicationException("Error: WINDDIR < 0: FireRegion = " + ecoName + "; Season = " + seasName); } else if (WINDDIR > 360) { throw new System.ApplicationException("Error: WINDDIR > 360: FireRegion = " + ecoName + "; Season = " + seasName); } FWIBIN = System.Convert.ToInt32(myDataRow["FWIBin"]); //Console.WriteLine("FWIBIN: {0}", FWIBIN); if (FWIBIN < 1) { throw new System.ApplicationException("Error: FWIBIN < 1: FireRegion = " + ecoName + "; Season = " + seasName); } else if (FWIBIN > 5) { throw new System.ApplicationException("Error: FWIBIN > 5: FireRegion = " + ecoName + "; Season = " + seasName); } } } if ((foundRows.Length == 0) && (seasonParms[i].FireProbability > 0) && (fire_region.EcoIgnitionNum > 0)) { throw new System.ApplicationException("Error: Ecoregion " + ecoName + ", Season " + seasName + " has fire probability > 0, but 0 weather records"); } if (seasName == "Fall") { fire_region.FallRecords = recordCount; } else if (seasName == "Spring") { fire_region.SpringRecords = recordCount; } else if (seasName == "Summer") { fire_region.SummerRecords = recordCount; } } } return(weatherTable); }
//--------------------------------------------------------------------- public static DataTable ReadWeatherFile(string path, List<IFireRegion> ecoDataSet, ISeasonParameters[] seasonParms) { PlugIn.ModelCore.UI.WriteLine(" Loading Weather Data..."); CSVParser weatherParser = new CSVParser(); DataTable weatherTable = weatherParser.ParseToDataTable(path); int recordCount = 0; for (int i = 0; i <= 2; i++) { string seasName = seasonParms[i].NameOfSeason.ToString(); foreach (IFireRegion fire_region in ecoDataSet) { string ecoName = fire_region.Name; //PlugIn.ModelCore.UI.WriteLine("Read Weather File: Season={0}, FireRegion={1}.", seasName, ecoName); string selectText = ("Ecoregion = '" + ecoName + "' AND Season = '" + seasName + "'"); //PlugIn.ModelCore.UI.WriteLine("Read Weather File SelectText = {0}.", selectText); DataRow[] foundRows = weatherTable.Select(selectText); if (foundRows.Length == 0) { selectText = ("Ecoregion = 'All' AND Season = '" + seasName + "'"); foundRows = weatherTable.Select(selectText); } if(foundRows.Length > 0) { //Input validation double WSV, FFMC, BUI; int WINDDIR, FWIBIN; for(int j = 0; j < foundRows.Length; j ++) //weatherDataSet.Tables["Table"].Rows) { DataRow myDataRow = foundRows[j]; WSV = System.Convert.ToDouble(myDataRow["WSV"]); //Console.WriteLine("WSV: {0}", WSV); if (WSV < 0.0) { throw new System.ApplicationException("Error: Wind Speed < 0: FireRegion = " + ecoName + "; Season = " + seasName); } FFMC = System.Convert.ToDouble(myDataRow["FFMC"]); //Console.WriteLine("FFMC: {0}", FFMC); if (FFMC < 0.0) { throw new System.ApplicationException("Error: FFMC < 0: FireRegion = " + ecoName + "; Season = " + seasName); } else if (FFMC > 100.0) { throw new System.ApplicationException("Error: FFMC > 100: FireRegion = " + ecoName + "; Season = " + seasName); } BUI = System.Convert.ToDouble(myDataRow["BUI"]); //Console.WriteLine("BUI: {0}", BUI); if (BUI < 0.0) { throw new System.ApplicationException("Error: BUI < 0: FireRegion = " + ecoName + "; Season = " + seasName); } WINDDIR = System.Convert.ToInt32(myDataRow["WindDir"]); //Console.WriteLine("WindDir: {0}", WINDDIR); if (WINDDIR < 0) { throw new System.ApplicationException("Error: WINDDIR < 0: FireRegion = " + ecoName + "; Season = " + seasName); } else if (WINDDIR > 360) { throw new System.ApplicationException("Error: WINDDIR > 360: FireRegion = " + ecoName + "; Season = " + seasName); } FWIBIN = System.Convert.ToInt32(myDataRow["FWIBin"]); //Console.WriteLine("FWIBIN: {0}", FWIBIN); if (FWIBIN < 1) { throw new System.ApplicationException("Error: FWIBIN < 1: FireRegion = " + ecoName + "; Season = " + seasName); } else if (FWIBIN > 5) { throw new System.ApplicationException("Error: FWIBIN > 5: FireRegion = " + ecoName + "; Season = " + seasName); } } } if ((foundRows.Length == 0) && (seasonParms[i].FireProbability > 0) && (fire_region.EcoIgnitionNum > 0)) { throw new System.ApplicationException("Error: Ecoregion " + ecoName + ", Season " + seasName + " has fire probability > 0, but 0 weather records"); } if(seasName == "Fall") { fire_region.FallRecords = recordCount; } else if (seasName == "Spring") { fire_region.SpringRecords = recordCount; } else if (seasName == "Summer") { fire_region.SummerRecords = recordCount; } } } return weatherTable; }
//--------------------------------------------------------------------- //public static int GenerateFMC(ISeasonParameters season, IDynamicInputRecord fire_region) //{ // int FMC = 0; // if (season.NameOfSeason == SeasonName.Spring) // { // if (PlugIn.ModelCore.GenerateUniform() < fire_region.SpringFMCHiProp) // FMC = fire_region.SpringFMCHi; // else // FMC = fire_region.SpringFMCLo; // } // if (season.NameOfSeason == SeasonName.Summer) // { // if (PlugIn.ModelCore.GenerateUniform() < fire_region.SummerFMCHiProp) // FMC = fire_region.SummerFMCHi; // else // FMC = fire_region.SummerFMCLo; // } // if (season.NameOfSeason == SeasonName.Fall) // { // if (PlugIn.ModelCore.GenerateUniform() < fire_region.FallFMCHiProp) // FMC = fire_region.FallFMCHi; // else // FMC = fire_region.FallFMCLo; // } // return FMC; //} //--------------------------------------------------------------------- public static DataTable ReadWindFile(string path) { PlugIn.ModelCore.UI.WriteLine(" Loading Wind Input Data..."); CSVParser windParser = new CSVParser(); DataTable windTable = windParser.ParseToDataTable(path); string selectText = ("Day > 0 AND Day < 365"); DataRow[] foundRows = windTable.Select(selectText); if (foundRows.Length > 0) { //Input validation double WSV; int WINDDIR; for (int j = 0; j < foundRows.Length; j++) { DataRow myDataRow = foundRows[j]; WSV = Convert.ToDouble(myDataRow["WindSpeedVelocity"]); if (WSV < 0.0) { throw new System.ApplicationException("Error: Wind Speed < 0: Day = " + myDataRow["Day"]); } WINDDIR = (int)myDataRow["WindAzimuth"]; if (WINDDIR < 0) { throw new System.ApplicationException("Error: WINDDIR < 0: Day = " + myDataRow["Day"]); } else if (WINDDIR > 360) { throw new System.ApplicationException("Error: WINDDIR > 360: Day = " + myDataRow["Day"]); } } } return windTable; }