Example #1
0
        /// <summary> Opens dialog box to import CSV file with CDF </summary>
        private void btnImportCDF_Click(object sender, EventArgs e)
        {
            string filename = "";

            if (ofdImportCFD.ShowDialog() == DialogResult.OK)
            {
                filename = ofdImportCFD.FileName;
            }
            else
            {
                return;
            }

            if (filename == "")
            {
                return;
            }

            double[,] importedCDF = Read_CDF_file(filename);

            if (importedCDF == null)
            {
                return;
            }

            Exceedance exceed = new Exceedance();

            if (importedCDF.GetUpperBound(0) > 0)
            {
                thisExceed           = new Exceedance.ExceedanceCurve();
                thisExceed.exceedStr = txtExceed.Text.ToString();
                thisExceed.distSize  = 1000;
                thisExceed.xVals     = new double[1000];
                thisExceed.probDist  = new double[1000];
                thisExceed.cumulDist = new double[1000];

                exceed.Interpolate_CDF(ref thisExceed, importedCDF);
                exceed.Calc_PDF_from_CDF(ref thisExceed);

                txt_LowerBound.Text = Math.Round(importedCDF[0, 0] * 100, 3).ToString();
                txt_UpperBound.Text = Math.Round(importedCDF[importedCDF.GetUpperBound(0), 0] * 100, 3).ToString();

                Update_Mode_List();
                Update_plot();
            }
        }
Example #2
0
        /// <summary> Adds or edits one mode of exceedance curve. (Exceedance curves may be defined as multimodal distributions.) </summary>
        public void Add_Edit_Mode(bool isAddMode)
        {
            Add_Mode formMode = new Add_Mode();
            int      editInd  = 0;
            int      numModes = 0;

            if (thisExceed.modes != null)
            {
                numModes = thisExceed.modes.Length;
            }

            if (isAddMode == false)
            { // need to find the mode that was selected
                if (lstModes.SelectedItems.Count != 1)
                {
                    MessageBox.Show("Select one mode to edit.", "", MessageBoxButtons.OK);
                    return;
                }
                else
                {
                    for (int i = 0; i < numModes; i++)
                    {
                        double selMean   = Convert.ToDouble(lstModes.SelectedItems[0].SubItems[0].Text);
                        double selSD     = Convert.ToDouble(lstModes.SelectedItems[0].SubItems[1].Text);
                        double selWeight = Convert.ToDouble(lstModes.SelectedItems[0].SubItems[2].Text);

                        if (Math.Round(thisExceed.modes[i].mean, 3) == Math.Round(selMean / 100, 3) && Math.Round(thisExceed.modes[i].SD, 3) == Math.Round(selSD / 100, 3) &&
                            Math.Round(thisExceed.modes[i].weight, 0) == Math.Round(selWeight / 100))
                        {
                            formMode.txtMean.Text   = Math.Round(thisExceed.modes[i].mean * 100, 2).ToString();
                            formMode.txtSD.Text     = Math.Round(thisExceed.modes[i].SD * 100, 3).ToString();
                            formMode.txtWeight.Text = Math.Round(thisExceed.modes[i].weight * 100, 0).ToString();
                            editInd = i;
                            break;
                        }
                    }
                }
            }

            formMode.ShowDialog();

            if (formMode.okAdd == true && isAddMode == true)
            {
                // Add to list of modes
                int newModeInd = numModes;
                Array.Resize(ref thisExceed.modes, newModeInd + 1);
                thisExceed.modes[newModeInd].mean   = formMode.mean / 100;
                thisExceed.modes[newModeInd].SD     = formMode.SD / 100;
                thisExceed.modes[newModeInd].weight = formMode.weight / 100;
            }
            else if (formMode.okAdd == true && isAddMode == false)
            {
                thisExceed.modes[editInd].mean   = formMode.mean / 100;
                thisExceed.modes[editInd].SD     = formMode.SD / 100;
                thisExceed.modes[editInd].weight = formMode.weight / 100;
            }

            Update_Mode_List();
            thisExceed.lowerBound = Convert.ToSingle(txt_LowerBound.Text) / 100;
            thisExceed.upperBound = Convert.ToSingle(txt_UpperBound.Text) / 100;

            if (thisExceed.distSize == 0)
            {
                thisExceed.distSize = 1000;
                Array.Resize(ref thisExceed.xVals, 1000);
                Array.Resize(ref thisExceed.probDist, 1000);
                Array.Resize(ref thisExceed.cumulDist, 1000);
            }

            // Reset PDF and CDF
            thisExceed.probDist  = new double[thisExceed.distSize];
            thisExceed.cumulDist = new double[thisExceed.distSize];

            Exceedance exceed = new Exceedance();

            exceed.CalculateProbDist(ref thisExceed);
            exceed.Normalize_Dists(ref thisExceed);
            Update_plot();
        }