Exemple #1
0
 private void InitStepSensitivity(ManagementItem mi, CropParameterItem pi, RunOptionItem roi, SiteItem sii, SoilItem soi,
                                  CropParameterItem vi, double[] deltaValue, int[] index)
 {
     if (oneByOne)
     {
         foreach (var sri in SensitivityRuns)
         {
             var initialValue = sri.GetValue(mi, pi, roi, sii, soi, vi);
             sri.InitialValue = initialValue;
             sri.Step         = 0;
             sri.SetValue(mi, pi, roi, sii, soi, vi, initialValue);
             deltaValue[index[0]] = initialValue;
         }
     }
     else
     {
         foreach (var sri in SensitivityRuns)
         {
             var initialValue = sri.GetValue(mi, pi, roi, sii, soi, vi);
             sri.InitialValue = initialValue;
             sri.SetStep(0, mi, pi, roi, sii, soi, vi);
             deltaValue[index[0]] = sri.InitialValue;
         }
     }
 }
Exemple #2
0
        public void SetValue(ManagementItem mi, CropParameterItem pi, RunOptionItem roi, SiteItem sii, SoilItem soi, CropParameterItem vi, double value)
        {
            var fileID       = GetFileID();
            var propertyName = GetPropertyName();

            if (fileID == "Crop")
            {
                //look in non varietal file
                if (pi.paramValue.ContainsKey(propertyName))
                {
                    pi.paramValue[propertyName] = value;
                }
                else
                {
                    //look in varietal file
                    if (vi.paramValue.ContainsKey(propertyName))
                    {
                        vi.paramValue[propertyName] = value;
                    }
                    else
                    {
                        throw new Exception("Parameter " + propertyName + " was not found in the varietal or non varietal files");
                    }
                }
            }
            else
            {
                var item = GetItem(mi, roi, sii, soi);
                if (propertyInfo == null)
                {
                    propertyInfo = item.GetType().GetProperty(propertyName);
                }
                propertyInfo.SetValue(item, value, null);
            }
        }
Exemple #3
0
        private bool Increment(int stepIndex, ManagementItem mi, CropParameterItem pi, RunOptionItem roi, SiteItem sii, SoilItem soi, CropParameterItem vi)
        {
            if (oneByOne)
            {
                var sensitivityRunCount = SensitivityRuns.Count;
                var found = false;
                var i     = 0;
                while (!found && i < sensitivityRunCount)
                {
                    var sensitivityRun       = SensitivityRuns[i];
                    var sensitivityRunNbStep = sensitivityRun.NbStep;
                    if (stepIndex < sensitivityRunNbStep)
                    {
                        sensitivityRun.SetStep(stepIndex, mi, pi, roi, sii, soi, vi);
                        found = true;
                    }
                    else
                    {
                        if (stepIndex == sensitivityRunNbStep)
                        {
                            sensitivityRun.SetValue(mi, pi, roi, sii, soi, vi, sensitivityRun.InitialValue);
                        }
                        stepIndex -= sensitivityRunNbStep;
                    }
                    ++i;
                }
                return(!found);
            }
            else
            {
                var end = true;
                var i   = SensitivityRuns.Count - 1;

                while (i >= 0 && end)
                {
                    var sensitivityRun     = SensitivityRuns[i];
                    var sensitivityRunStep = sensitivityRun.Step;
                    if (sensitivityRunStep == sensitivityRun.NbStep - 1)
                    {
                        sensitivityRun.SetStep(0, mi, pi, roi, sii, soi, vi);
                    }
                    else
                    {
                        sensitivityRun.SetStep(sensitivityRunStep + 1, mi, pi, roi, sii, soi, vi);
                        end = false;
                    }
                    --i;
                }
                return(end);
            }
        }
        internal static PageData Run(string runItemName, bool extract, bool isNormalRun, string miName, string piName, string roiName, string siiName, string soiName, string viName)
        {
            ManagementItem    mi  = null;
            CropParameterItem pi  = null;
            RunOptionItem     roi = null;
            SiteItem          sii = null;
            SoilItem          soi = null;
            CropParameterItem vi  = null;

            GetItems(runItemName, miName, piName, roiName, siiName, soiName, viName,
                     ref mi, ref pi, ref roi, ref sii, ref soi, ref vi);

            return(Run(runItemName, extract, isNormalRun, mi, pi, roi, sii, soi, vi));
        }
Exemple #5
0
        public void SetStep(int step, ManagementItem mi, CropParameterItem pi, RunOptionItem roi, SiteItem sii, SoilItem soi, CropParameterItem vi)
        {
            Step = step;
            switch (Mode)
            {
            case SensitivityMode.RegularMinMax:
                SetValue(mi, pi, roi, sii, soi, vi, Min + Step * (Max - Min) / ((double)NbStep - 1));
                break;

            case SensitivityMode.RegularPercent:
                var minValue = Min * InitialValue / 100.0;
                var maxValue = Max * InitialValue / 100.0;
                SetValue(mi, pi, roi, sii, soi, vi, minValue + Step * (maxValue - minValue) / ((double)NbStep - 1));
                break;
            }
        }
        internal static PageData Run(string runItemName, bool extract, bool isNormalRun,
                                     ManagementItem mi,
                                     CropParameterItem pi,
                                     RunOptionItem roi,
                                     SiteItem sii,
                                     SoilItem soi,
                                     CropParameterItem vi)
        {
            RunInstance.Start(vi, soi, sii, mi, pi, roi);

            if (extract)
            {
                return(OutputFile.ExtractNormalRun(RunInstance));
            }
            return(null);
        }
        public static void GetItems(string runItemName,
                                    string miName, string piName, string roiName, string siiName, string soiName, string viName,
                                    ref ManagementItem mi, ref CropParameterItem pi, ref RunOptionItem roi, ref SiteItem sii, ref SoilItem soi, ref CropParameterItem vi)
        {
            mi = ProjectFile.This.FileContainer.ManagementFile[miName];
            pi = ProjectFile.This.FileContainer.NonVarietyFile[piName];
            if (pi == null)
            {
                pi = ProjectFile.This.FileContainer.MaizeNonVarietyFile[piName];
            }
            roi = ProjectFile.This.FileContainer.RunOptionFile[roiName];
            sii = ProjectFile.This.FileContainer.SiteFile[siiName];
            soi = ProjectFile.This.FileContainer.SoilFile[soiName];
            vi  = ProjectFile.This.FileContainer.VarietyFile[viName];
            if (vi == null)
            {
                vi = ProjectFile.This.FileContainer.MaizeVarietyFile[viName];
            }

            if (mi == null)
            {
                throw new RunException(runItemName, "Management not found: " + miName);
            }
            if (pi == null)
            {
                throw new RunException(runItemName, "Parameter not found: " + piName);
            }
            if (roi == null)
            {
                throw new RunException(runItemName, "Element option not found: " + roiName);
            }
            if (sii == null)
            {
                throw new RunException(runItemName, "Site not found: " + siiName);
            }
            if (soi == null)
            {
                throw new RunException(runItemName, "Soil not found: " + soiName);
            }
            if (vi == null)
            {
                throw new RunException(runItemName, "Variety not found: " + viName);
            }
        }
Exemple #8
0
        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");
            }
        }
Exemple #9
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);
            }
        }
Exemple #10
0
        public override void StepRun(bool serialize, int i, string variety = null, string parameterName = null, double parameterValue = 0)
        {
            BindingList <MultiRunItem> multiRuns = RunItem.Multi.MultiRuns;
            var multiYear = RunItem.Multi.MultiYear;

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

            mi  = mi.Clone();
            pi  = pi.Clone();
            roi = roi.Clone();
            sii = sii.Clone();
            soi = soi.Clone();
            vi  = vi.Clone();

            #endregion

            ///<Behnam>
            var deltaHeader = new string[SensitivityRuns.Count];
            var index1      = 0;

            if (oneByOne)
            {
                nbSensitivityStep = 1;
                SensitivityRuns.Iterate(
                    delegate(SensitivityRunItem item)
                {
                    nbSensitivityStep    += item.NbStep;
                    deltaHeader[index1++] = item.GetHeader();
                });
            }
            else
            {
                nbSensitivityStep = 1;
                SensitivityRuns.Iterate(
                    delegate(SensitivityRunItem item)
                {
                    nbSensitivityStep    *= item.NbStep;
                    deltaHeader[index1++] = item.GetHeader();
                });
            }
            ///</Behnam>

            var   deltaValue = new double[SensitivityRuns.Count];
            int[] index      = { 0 };

            if (!multiYear)
            {
                ///<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;
                }
                ///</Behnam>

                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>

                var end = false;
                InitStepSensitivity(mi, pi, roi, sii, soi, vi, deltaValue, index);

                var stepIndex = 0;
                while (!end)
                {
                    var excelPage        = RunCore.Run(riName, exportNormalRuns, false, mi, pi, roi, sii, soi, vi);
                    var deltaSensitivity = "";

                    index[0] = 0;
                    SensitivityRuns.Iterate(
                        item =>
                    {
                        deltaValue[index[0]] = item.GetValue(mi, pi, roi, sii, soi, vi);
                        deltaSensitivity    += item.GetHeader() + "_" + Math.Round(deltaValue[index[0]], 4) + "_";
                        ++index[0];
                    });

                    ///<Behnam>
                    if (i == 0 && stepIndex == 0)
                    {
                        Book.Clear();
                        var outputFile = OutputFile.ExtractSensitivityRunHeader(deltaHeader);
                        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(VarDeltaSensitivity, deltaSensitivity);
                        dailyOutputFileName = dailyOutputFileName.Replace(RunItemModeMulti.VarMultiYearSowingYear, "");
                        excelPage.Title     = dailyOutputFileName;
                        Book.Add(excelPage);
                        if (serialize)
                        {
                            RunCore.Save(excelPage, AbsoluteOutputDirectory + "\\" + dailyOutputFileName);
                        }
                    }

                    if (i == 0 && ProjectFile.OutputVersion == OutputVersion.Cus && stepIndex == 0)
                    {
                        Run.SecondLine = false;
                        Book[0].Add(OutputFile.ExtractSensitivityRunLine(RunCore.RunInstance, deltaHeader, deltaValue));
                    }
                    Book[0].Add(OutputFile.ExtractSensitivityRunLine(RunCore.RunInstance, deltaHeader, deltaValue));
                    ///</Behnam>

                    end = Increment(stepIndex, mi, pi, roi, sii, soi, vi);
                    ++stepIndex;
                }
            }
            else
            {
                ///<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;
                }
                ///</Behnam>

                var firstYear = RunItem.Multi.FirstYear;
                var lastYear  = RunItem.Multi.LastYear;

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

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

                    var end = false;
                    InitStepSensitivity(mi, pi, roi, sii, soi, vi, deltaValue, index);

                    var stepIndex = 0;

                    while (!end)
                    {
                        var excelPage        = RunCore.Run(riName, exportNormalRuns, false, mi, pi, roi, sii, soi, vi);
                        var deltaSensitivity = "";

                        index[0] = 0;
                        var index0 = index[0];
                        SensitivityRuns.Iterate(
                            delegate(SensitivityRunItem item)
                        {
                            deltaValue[index0] = item.GetValue(mi, pi, roi, sii, soi, vi);
                            deltaSensitivity  += item.GetHeader() + "_" + Math.Round(deltaValue[index[0]], 4) + "_";
                            ++index0;
                        });

                        ///<Behnam (2016.11.12)>
                        if (i == 0 && j == firstYear && stepIndex == 0)
                        {
                            Book.Clear();
                            var outputFile = OutputFile.ExtractSensitivityRunHeader(deltaHeader);
                            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(VarDeltaSensitivity, deltaSensitivity);
                            dailyOutputFileName = dailyOutputFileName.Replace(RunItemModeMulti.VarMultiYearSowingYear, mi.FinalSowingDate.Year.ToString());
                            excelPage.Title     = dailyOutputFileName;
                            Book.Add(excelPage);

                            if ((j == firstYear || (j != firstYear && oldDailyOutputFileName != dailyOutputFileName)) && stepIndex == 0)
                            {
                                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 && stepIndex == 0)
                        {
                            Run.SecondLine = false;
                            Book[0].Add(OutputFile.ExtractSensitivityRunLine(RunCore.RunInstance, deltaHeader, deltaValue));
                        }
                        Book[0].Add(OutputFile.ExtractSensitivityRunLine(RunCore.RunInstance, deltaHeader, deltaValue));
                        ///</Behnam>

                        end = Increment(stepIndex, mi, pi, roi, sii, soi, vi);
                        ++stepIndex;
                    }
                }
            }
        }
Exemple #11
0
        public override int InitRun(bool serialize)
        {
            ///<Behnam 92015.12.08)>
            #region get items
            string miName, piName, riName, roiName, siiName, soiName, viName, exName;
            BindingList <MultiRunItem> multiRuns = RunItem.Multi.MultiRuns;
            var multiYear = RunItem.Multi.MultiYear;

            if (multiRuns.Count > 0)
            {
                var item = multiRuns[0];
                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);

            mi  = mi.Clone();
            pi  = pi.Clone();
            roi = roi.Clone();
            sii = sii.Clone();
            soi = soi.Clone();
            vi  = vi.Clone();

            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;
            }
            #endregion
            ///</Behnam>

            if (RunItem.Multi.MultiYear && RunItem.Multi.FirstYear > RunItem.Multi.LastYear)
            {
                throw new RunException(RunItem.Name, "First year (" + RunItem.Multi.FirstYear + ") must be <= to last year (" + RunItem.Multi.LastYear + ")");
            }

            var deltaHeader = new string[SensitivityRuns.Count];
            var index       = 0;

            if (oneByOne)
            {
                nbSensitivityStep = 1;
                SensitivityRuns.Iterate(
                    delegate(SensitivityRunItem item)
                {
                    nbSensitivityStep   += item.NbStep;
                    deltaHeader[index++] = item.GetHeader();
                });
            }
            else
            {
                nbSensitivityStep = 1;
                SensitivityRuns.Iterate(
                    delegate(SensitivityRunItem item)
                {
                    nbSensitivityStep   *= item.NbStep;
                    deltaHeader[index++] = item.GetHeader();
                });
            }

            if (Book != null)
            {
                Book.Clear();
            }
            else
            {
                Book = new Book();
            }
            var page = OutputFile.ExtractSensitivityRunHeader(deltaHeader);
            page.Title = OutputFileName;
            Book.Add(page);
            return(Math.Max(1, RunItem.Multi.MultiRuns.Count));
        }