private void btnReset_Click(object sender, EventArgs e)
 {
     if (ccb_Added.Items.Count != 0)
     {
         mz_id_to_process.Clear();
         ccb_Added.Items.Clear();
         R_matrix.refresh();
         update_figure(threshold);
     }
 }
        public void update_ccbox()
        {
            ccb_Added.Items.Clear();
            int st_inc = 0;
            int st_exc = 0;

            if (mz_id_to_process.Sum() > 0 && mz_id_to_process.Sum() < R_matrix.mz_array.Length)
            {
                for (int i = 1; i < mz_id_to_process.Length; i++)
                {
                    if (mz_id_to_process[i] != mz_id_to_process[i - 1])
                    {
                        if (mz_id_to_process[i - 1] == 0)
                        {
                            CCBoxItem item = new CCBoxItem(R_matrix.mz_array[st_exc], R_matrix.mz_array[i - 1], false);
                            ccb_Added.Items.Add(item);
                            st_inc = i;
                        }
                        else
                        {
                            CCBoxItem item = new CCBoxItem(R_matrix.mz_array[st_inc], R_matrix.mz_array[i - 1], true);
                            ccb_Added.Items.Add(item);
                            st_exc = i;
                        }
                    }
                }
                if (mz_id_to_process[mz_id_to_process.Length - 1] == 0)
                {
                    CCBoxItem item = new CCBoxItem(R_matrix.mz_array[st_exc], R_matrix.mz_array[mz_id_to_process.Length - 1], false);
                    ccb_Added.Items.Add(item);
                }
                else
                {
                    CCBoxItem item = new CCBoxItem(R_matrix.mz_array[st_inc], R_matrix.mz_array[mz_id_to_process.Length - 1], true);
                    ccb_Added.Items.Add(item);
                }
            }
            else
            {
                R_matrix.refresh();
            }
        }
        public void read_r_matrix(string fileName)
        {
            try
            {
                //var mzxml = new LIMPFileReader.LimpXml(fileName, (float)0, true);

                Cursor = Cursors.WaitCursor;
                var reader    = new MatReader(fileName);
                var structure = reader["data"];
                var cType     = structure["spectra"].ValueType;
                var fields    = structure.Fields;

                //var scans = (reader["result"]["scans"].GetValue<int[,]>()).ToDouble();
                var scans = reader["data"]["spectra"].GetValue <double[, ]>().Transpose();
                R_matrix.mz_array = reader["data"]["mz"].GetValue <double[, ]>().ToJagged()[0];
                mzmin             = R_matrix.mz_array[0];
                mzmax             = R_matrix.mz_array[R_matrix.mz_array.Length - 1];
                n_precision       = (int)(Math.Round(1.0 / (R_matrix.mz_array[1] - R_matrix.mz_array[0])));


                rf = new double[scans.Columns(), scans.Columns()];
                R_matrix.matrix = rf;
                rf2             = new double[rf.Columns(), rf.Rows()];

                R_matrix.scans = scans.Transpose();
                int mzlength     = scans.GetLength(0);
                var scannames    = reader["data"]["filenames"];
                var scan_of_file = (reader["data"]["scan_of_file"].GetValue <double[, ]>()).ToInt32();
                scannames_count = scan_of_file.Length;
                sampleNameList.Clear();
                sampleNameList.Add(scannames[scan_of_file[0, 0]].Value.ToString());
                sampleCoordList.Clear();
                sampleCoordList.Add(0.0);
                scanNamesList.Clear();
                int intercept = 0;
                for (int i = 0; i < scannames_count; i++)
                {
                    scanNamesList.Add(scannames[scan_of_file[0, i]].Value.ToString());
                    if (i > 0)
                    {
                        if (scannames[scan_of_file[0, i]].Value.ToString() != scannames[scan_of_file[0, i - 1]].Value.ToString())
                        {
                            sampleNameList.Add(scannames[scan_of_file[0, i]].Value.ToString());
                            sampleCoordList.Add(i);
                            intercept = i;
                        }
                    }
                    sampleScanList.Add(Convert.ToString(i + 1 - intercept));
                }
                R_matrix.scan_names = sampleScanList;
                R_matrix.file_names = sampleNameList;
                R_matrix.refresh();
                update_figure(threshold);
                Cursor = Cursors.Arrow;
            }
            catch (Exception e)
            {
                var msg = e.Message;
                Cursor = Cursors.Arrow;
                MessageBox.Show(msg, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
                return;
            }
        }