public override void StepRun(bool serialize, int i, string variety = null, string parameterName = null, double parameterValue = 0) { if (i == 0) { ///<Behnam> string miName, piName, riName, roiName, siiName, soiName, viName; miName = RunItem.Normal.ManagementItem; piName = RunItem.Normal.ParameterItem; riName = RunItem.Name; roiName = RunItem.Normal.RunOptionItem; siiName = RunItem.Normal.SiteItem; soiName = RunItem.Normal.SoilItem; viName = RunItem.Normal.VarietyItem; ManagementItem mi = null; CropParameterItem pi = null; RunOptionItem roi = null; SiteItem sii = null; SoilItem soi = null; CropParameterItem vi = null; RunCore.GetItems(riName, miName, piName, roiName, siiName, soiName, viName, ref mi, ref pi, ref roi, ref sii, ref soi, ref vi); switch (roi.OutputPattern) { case "V13": ProjectFile.OutputVersion = OutputVersion.V13; break; case "V15": ProjectFile.OutputVersion = OutputVersion.V15; break; case "Cus": ProjectFile.OutputVersion = OutputVersion.Cus; break; case "Maize": ProjectFile.OutputVersion = OutputVersion.Maize; break; } ///</Behnam> ///<Behnam (2016.01.19)> ///<Comment>Adding the Summary file to the outputs of a Normal run</Comment> var SumOutputFileName = OutputFile.ExtractMultiRunHeader(); SumOutputFileName.Title = OutputFileName.Replace(OutputExtention, SumOutputExtention); Book.Add(SumOutputFileName); Run.isFirstYear = true; var excelPage = RunCore.Run(RunItem.Name, true, true, ManagementItem, ParameterItem, RunOptionItem, SiteItem, SoilItem, VarietyItem); excelPage.Title = OutputFileName; Book.Add(excelPage); var WarningOutputFileName = OutputFile.ExtractWarningsNormalRun(RunCore.RunInstance); WarningOutputFileName.Title = "Warnings"; Book.Add(WarningOutputFileName); if (serialize) { RunCore.Save(excelPage, AbsoluteOutputPath, true); } if (ProjectFile.OutputVersion == OutputVersion.Cus) { Run.SecondLine = false; Book[0].Add(OutputFile.ExtractMultiRunLine(RunCore.RunInstance)); } Book[0].Add(OutputFile.ExtractMultiRunLine(RunCore.RunInstance)); ///</Behnam> } else { throw new RunException(RunItem.Name, "Normal run index != 0"); } }
public override void StepRun(bool serialize, int i, string variety = null, string parameterName = null, double parameterValue = 0) { #region get items string miName, piName, riName, roiName, siiName, soiName, viName, exName; if (MultiRuns.Count > 0) { var item = MultiRuns[i]; miName = item.ManagementItemSelected; piName = item.ParameterItemSelected; riName = RunItem.Name; roiName = item.RunOptionItemSelected; siiName = item.SiteItemSelected; soiName = item.SoilItemSelected; viName = item.VarietyItemSelected; exName = item.ExperimentSelected; } else { miName = RunItem.Normal.ManagementItem; piName = RunItem.Normal.ParameterItem; riName = RunItem.Name; roiName = RunItem.Normal.RunOptionItem; siiName = RunItem.Normal.SiteItem; soiName = RunItem.Normal.SoilItem; viName = RunItem.Normal.VarietyItem; exName = RunItem.Normal.ExperimentItem; } ManagementItem mi = null; CropParameterItem pi = null; RunOptionItem roi = null; SiteItem sii = null; SoilItem soi = null; CropParameterItem vi = null; RunCore.GetItems(riName, miName, piName, roiName, siiName, soiName, viName, ref mi, ref pi, ref roi, ref sii, ref soi, ref vi); #endregion #region override some parameters if (variety != null) { if (variety == viName) { vi.ParamValue[parameterName] = parameterValue; } } #endregion if (!multiYear) { switch (roi.OutputPattern) { case "V13": ProjectFile.OutputVersion = OutputVersion.V13; break; case "V15": ProjectFile.OutputVersion = OutputVersion.V15; break; case "Cus": ProjectFile.OutputVersion = OutputVersion.Cus; break; case "Maize": ProjectFile.OutputVersion = OutputVersion.Maize; break; } ///<Behnam> ///<Comment> ///Modifications related to estimating sowing window and forcing the model ///to put daily outputs into one file if the names of the daily output files ///are identical for two successive years. ///</Comment> var yy = sii.MaxSowingDate.Year - sii.MinSowingDate.Year; mi.SowingDate = new DateTime(mi.SowingDate.Year, mi.SowingDate.Month, mi.SowingDate.Day); sii.MinSowingDate = new DateTime(mi.SowingDate.Year, sii.MinSowingDate.Month, sii.MinSowingDate.Day); sii.MaxSowingDate = new DateTime(mi.SowingDate.Year + yy, sii.MaxSowingDate.Month, sii.MaxSowingDate.Day); Run.isFirstYear = true; ///</Behnam> //Debug var excelPage = RunCore.Run(riName, exportNormalRuns, false, mi, pi, roi, sii, soi, vi); ///<Behnam> if (i == 0) { Book.Clear(); var outputFile = OutputFile.ExtractMultiRunHeader(); outputFile.Title = OutputFileName; Book.Add(outputFile); } if (exportNormalRuns) { var dailyOutputFileName = OutputPatternVarDef.OutputPatternValue(dailyOutputPattern, miName, piName, riName, roiName, siiName, soiName, viName, exName) + RunItem.Normal.OutputExtention; dailyOutputFileName = dailyOutputFileName.Replace(VarMultiYearSowingYear, ""); excelPage.Title = dailyOutputFileName; Book.Add(excelPage); if (serialize) { RunCore.Save(excelPage, AbsoluteOutputDirectory + "\\" + dailyOutputFileName); } if (i == 0) { warningFile = OutputFile.ExtractWarningsHeader(); warningFile.Title = "warnings"; } LineData line = OutputFile.ExtractWarningsMultiRun(RunCore.RunInstance); if (line != null) { warningFile.Add(line); } } if (i == 0 && ProjectFile.OutputVersion == OutputVersion.Cus) { Run.SecondLine = false; Book[0].Add(OutputFile.ExtractMultiRunLine(RunCore.RunInstance)); } ///</Behnam> Book[0].Add(OutputFile.ExtractMultiRunLine(RunCore.RunInstance)); /// Behnam (2016.06.01): Added to write the summaty file after each run is finished. /// Other way, if one simulations is not completed, the summary file is not pronted at all. if (serialize) { RunCore.Save(Book[0], AbsoluteOutputPath); } } else { mi = mi.Clone(); ///<Behnam> switch (roi.OutputPattern) { case "V13": ProjectFile.OutputVersion = OutputVersion.V13; break; case "V15": ProjectFile.OutputVersion = OutputVersion.V15; break; case "Cus": ProjectFile.OutputVersion = OutputVersion.Cus; break; case "Maize": ProjectFile.OutputVersion = OutputVersion.Maize; break; } for (var j = firstYear; j <= lastYear; ++j) { foreach (var dateApp in mi.DateApplications) { dateApp.Date = new DateTime(j + (dateApp.Date.Year - mi.SowingDate.Year), dateApp.Date.Month, dateApp.Date.Day); } var yy = sii.MaxSowingDate.Year - sii.MinSowingDate.Year; mi.SowingDate = new DateTime(j, mi.SowingDate.Month, mi.SowingDate.Day); sii.MinSowingDate = new DateTime(j, sii.MinSowingDate.Month, sii.MinSowingDate.Day); sii.MaxSowingDate = new DateTime(j + yy, sii.MaxSowingDate.Month, sii.MaxSowingDate.Day); Run.isFirstYear = (j == firstYear); var excelPage = RunCore.Run(riName, exportNormalRuns, false, mi, pi, roi, sii, soi, vi); if (i == 0 && j == firstYear) { Book.Clear(); var outputFile = OutputFile.ExtractMultiRunHeader(); outputFile.Title = OutputFileName; Book.Add(outputFile); } if (exportNormalRuns) { var dailyOutputFileName = OutputPatternVarDef.OutputPatternValue(dailyOutputPattern, miName, piName, riName, roiName, siiName, soiName, viName, exName) + RunItem.Normal.OutputExtention; dailyOutputFileName = dailyOutputFileName.Replace(VarMultiYearSowingYear, sii.MinSowingDate.Year.ToString()); excelPage.Title = dailyOutputFileName; Book.Add(excelPage); if (j == firstYear || (j != firstYear && oldDailyOutputFileName != dailyOutputFileName)) { if (serialize) { RunCore.Save(excelPage, AbsoluteOutputDirectory + "\\" + dailyOutputFileName, true); } } else { if (serialize) { RunCore.Save(excelPage, AbsoluteOutputDirectory + "\\" + dailyOutputFileName, false); } } oldDailyOutputFileName = dailyOutputFileName; } if (i == 0 && j == firstYear && ProjectFile.OutputVersion == OutputVersion.Cus) { Run.SecondLine = false; Book[0].Add(OutputFile.ExtractMultiRunLine(RunCore.RunInstance)); } Book[0].Add(OutputFile.ExtractMultiRunLine(RunCore.RunInstance)); /// Behnam (2016.06.01): Added to write the summaty file after each run is finished. /// Other way, if one simulations is not completed, the summary file is not pronted at all. if (serialize) { RunCore.Save(Book[0], AbsoluteOutputPath); } ///</Behnam> //Warnings if (i == 0 && j == firstYear) { warningFile = OutputFile.ExtractWarningsHeader(); warningFile.Title = "warnings"; } LineData line = OutputFile.ExtractWarningsMultiRun(RunCore.RunInstance); if (line != null) { warningFile.Add(line); } } } if (i == (MultiRuns.Count - 1)) { Book.Add(warningFile); } }