Exemplo n.º 1
0
        /// <summary>
        /// This routine updates our frontend. All updates are performed in a threadsafe manner, as the
        /// stochastic methods can take place on a separate thread
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ReflCalc_Update(object sender, EventArgs e)
        {
            //Necessary due to the possibility of updating from a separate thread (such as stochastic fitting). Otherwise, events are fired which reset some of the values
            //below. A lock isn't necessary this isn't necessarilly a race condition
            m_isupdating = true;

            SubRough.ThreadSafeSetText(ReflCalc.GetSubRoughness.ToString());

            if (ReflCalc.ImpNormCB)
            {
                NormCorrectTB.ThreadSafeSetText(ReflCalc.NormalizationFactor.ToString());
            }

            Holdsigma.ThreadSafeChecked(ReflCalc.IsOneSigma);
            BoxCount.ThreadSafeSetText(ReflCalc.BoxCount.ToString());
            ImpNormCB.ThreadSafeChecked(ReflCalc.ImpNormCB);

            //Blank our Rho data from the previous iteration
            for (int i = 0; i < RhoArray.Count; i++)
            {
                if (!m_bUseSLD)
                {
                    RhoArray[i].ThreadSafeSetText(ReflCalc.RhoArray[i].ToString());
                }
                else
                {
                    RhoArray[i].ThreadSafeSetText((ReflCalc.RhoArray[i] / ReflCalc.SubphaseSLD).ToString());
                }

                LengthArray[i].ThreadSafeSetText(ReflCalc.LengthArray[i].ToString());
                SigmaArray[i].ThreadSafeSetText(ReflCalc.SigmaArray[i].ToString());
            }

            if (Holdsigma.Checked)
            {
                ChangeRoughnessArray();
            }

            if (m_bmodelreset)
            {
                ReflGraphing.Clear();
                ReflGraphing.LoadDatawithErrorstoGraph("Reflectivity Data", Color.Black, SymbolType.Circle, 5, ReflData.Instance.GetQData, ReflData.Instance.GetReflData);
                m_bmodelreset = false;
            }

            GreyFields();
            //Update graphs
            RhoGraphing.Pane.XAxis.Scale.Min = 0;
            RhoGraphing.Pane.XAxis.Scale.Max = ReflCalc.Z[ReflCalc.Z.Length - 1];

            ReflGraphing.LoadfromArray("modelrefl", ReflData.Instance.GetQData, ReflCalc.ReflectivityMap, System.Drawing.Color.Black, SymbolType.XCross, 4, true, string.Empty);
            RhoGraphing.LoadfromArray("Model Dependent Fit", ReflCalc.Z, ReflCalc.ElectronDensityArray, System.Drawing.Color.Turquoise, SymbolType.None, 0, true, string.Empty);
            RhoGraphing.LoadfromArray("Model Dependent Box Fit", ReflCalc.Z, ReflCalc.BoxElectronDensityArray, System.Drawing.Color.Red, SymbolType.None, 0, false, string.Empty);

            chisquaretb.ThreadSafeSetText(ReflCalc.MakeChiSquare().ToString());
            FitnessScoreTB.ThreadSafeSetText(ReflCalc.MakeFitnessScore().ToString());

            m_isupdating = false;
        }
Exemplo n.º 2
0
        private void LoadDataFile(string origreflfilename)
        {
            try
            {
                if (!ReflData.Instance.SetReflData(origreflfilename, !errorsAreInVarianceToolStripMenuItem.Checked))
                {
                    throw new Exception("Could not load file");
                }

                FileNameTB.Text = origreflfilename;
                settingsfile    = origreflfilename + "settings.xml";
                reflgraphobject.SetAllFonts("Garamond", 20, 18);
                reflgraphobject.SubSLD         = SubSLDTB.ToDouble();
                reflgraphobject.SupSLD         = SupSLDTB.ToDouble();
                reflgraphobject.GetHighQOffset = ReflData.Instance.GetNumberDataPoints;
                reflgraphobject.GetLowQOffset  = 0;
                reflgraphobject.SetGraphType(forceRQ4GraphingToolStripMenuItem.Checked, fresnelcb.Checked);
                //Load the modeled files if they are available
                if (File.Exists(settingsfile) && !m_bloadfromcommandline)
                {
                    if (MessageBox.Show("Do you want to load the previous run?", "Resume?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        rhographobject.Clear();
                        reflgraphobject.Clear();

                        if (!LoadSettings())
                        {
                            return;
                        }


                        string tempfile = ReflData.Instance.GetWorkingDirectory + "\\rho.dat";

                        if (File.Exists(tempfile))
                        {
                            LoadZ(tempfile);
                            rhographobject.SubSLD = double.Parse(SubSLDTB.Text);
                            rhographobject.UseSLD = UseSLDToolStripMenuItem.Checked;

                            if (UseSLDToolStripMenuItem.Checked)
                            {
                                rhographobject.SetAxisTitles("Z", "SLD");
                                rhographobject.Title = "Model Independent SLD Fit";
                            }
                            else
                            {
                                rhographobject.SetAxisTitles("Z", "Normalized Electron Density");
                                rhographobject.Title = "Model Independent Electron Density Fit";
                            }
                            rhographobject.LoadFiletoGraph(tempfile.ToString(), rhomodelname, "Model Independent Electron Density Fit", Color.Tomato, SymbolType.None, 0, true);
                        }

                        tempfile = ReflData.Instance.GetWorkingDirectory + "\\rf.dat";

                        if (File.Exists(tempfile))
                        {
                            reflgraphobject.SubSLD = double.Parse(SubSLDTB.Text);
                            reflgraphobject.SupSLD = double.Parse(SupSLDTB.Text);
                            reflgraphobject.SetGraphType(forceRQ4GraphingToolStripMenuItem.Checked, fresnelcb.Checked);
                            reflgraphobject.GetLowQOffset  = int.Parse(critedgeoffTB.Text);
                            reflgraphobject.GetHighQOffset = ReflData.Instance.GetNumberDataPoints - int.Parse(HQoffsetTB.Text);
                            //Load the data file to the graph
                            reflgraphobject.LoadDatawithErrorstoGraph("Reflectivity Data", Color.Black, SymbolType.Circle, 5, ReflData.Instance.GetQData, ReflData.Instance.GetReflData);
                            reflgraphobject.LoadFiletoGraph(tempfile.ToString(), modelreflname, "Model Independent Reflectivity", Color.Tomato, SymbolType.Square, 2, true);
                        }

                        GraphCollection.Instance.MainReflGraph = reflgraphobject;
                        GraphCollection.Instance.MainRhoGraph  = rhographobject;

                        UpdateReportParameters();
                    }
                    else
                    {
                        //Clear the report
                        ReportGenerator.Instance.ClearAll();

                        //Load the data file to the graph
                        reflgraphobject.LoadDatawithErrorstoGraph("Reflectivity Data", Color.Black, SymbolType.Circle, 5, ReflData.Instance.GetQData, ReflData.Instance.GetReflData);

                        FileInfo info = new FileInfo(settingsfile);

                        if (File.Exists(info.DirectoryName + "\\pop.dat"))
                        {
                            //Create a backup folder if we don't have one
                            if (!System.IO.Directory.Exists(info.DirectoryName + "\\FitBackUp"))
                            {
                                System.IO.Directory.CreateDirectory(info.DirectoryName + "\\FitBackUp");
                            }

                            int index = 0;
                            for (; ;)
                            {
                                if (!System.IO.Directory.Exists(info.DirectoryName + "\\FitBackUp\\Fit" + index.ToString()))
                                {
                                    System.IO.Directory.CreateDirectory(info.DirectoryName + "\\FitBackUp\\Fit" + index.ToString());
                                    break;
                                }
                                index++;
                            }
                            string fileloc = info.DirectoryName + "\\FitBackUp\\Fit" + index.ToString();


                            File.Move(info.DirectoryName + "\\pop.dat", fileloc + "\\pop.dat");
                            File.Move(settingsfile, fileloc + "\\" + info.Name);

                            if (File.Exists(info.DirectoryName + "\\rf.dat"))
                            {
                                File.Move(info.DirectoryName + "\\rf.dat", fileloc + "\\rf.dat");
                            }

                            if (File.Exists(info.DirectoryName + "\\rho.dat"))
                            {
                                File.Move(info.DirectoryName + "\\rho.dat", fileloc + "\\rho.dat");
                            }

                            if (File.Exists(info.DirectoryName + "\\reflfile.dat"))
                            {
                                File.Move(info.DirectoryName + "\\reflfile.dat", fileloc + "\\reflfile.dat");
                            }

                            if (File.Exists(info.DirectoryName + "\\reflrhofit.dat"))
                            {
                                File.Move(info.DirectoryName + "\\reflrhofit.dat", fileloc + "\\reflrhofit.dat");
                            }
                        }
                    }
                }
                else
                {
                    //Load the data file to the graph
                    reflgraphobject.LoadDatawithErrorstoGraph("Reflectivity Data", Color.Black, SymbolType.Circle, 5, ReflData.Instance.GetQData, ReflData.Instance.GetReflData);
                }

                DisableInterface(false);
                Cancelbutton.Enabled = false;
                reflgraphobject.SetBounds();

                SubAbs.Enabled = SupAbsTB.Enabled = SurfAbs.Enabled = UseAbsCB.Checked;
            }
            catch (Exception ex)
            {
                origreflfilename = string.Empty;
                FileNameTB.Clear();
                DisableInterface(true);
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 3
0
        public ConstrainedReflmodeling(RhoFit RhoCalc)
        {
            InitializeComponent();

            ReflCalc  = new ReflFit(RhoCalc as BoxReflFitBase);
            m_bUseSLD = Properties.Settings.Default.UseSLDSingleSession;

            SigmaArray      = new List <TextBox>(6);
            LengthArray     = new List <TextBox>(6);
            RhoArray        = new List <TextBox>(6);
            HoldSigmaArray  = new List <CheckBox>(6);
            HoldLengthArray = new List <CheckBox>(6);
            HoldRhoArray    = new List <CheckBox>(6);

            if (m_bUseSLD)
            {
                tabControl1.TabPages[1].Text = "SLD";
                RhoLabel.Text = "SLD";
            }
            else
            {
                tabControl1.TabPages[1].Text = "Electron Density";
            }

            WavelengthTB.Text = ((double)(1.24)).ToString();

            //Initialize the arrays
            MakeArrays();

            //Copy over the values
            BoxCount.Text     = RhoCalc.BoxCount.ToString();
            SubRough.Text     = RhoCalc.GetSubRoughness.ToString();
            SubphaseSLD.Text  = RhoCalc.SubphaseSLD.ToString();
            SupSLDTB.Text     = RhoCalc.SuperphaseSLD.ToString();
            Holdsigma.Checked = RhoCalc.IsOneSigma;


            //Setup the Graph
            ReflGraphing = new Graphing(string.Empty);
            ReflGraphing.SetGraphType(Properties.Settings.Default.ForceRQ4, DBFCB.Checked);
            ReflGraphing.SubSLD = SubphaseSLD.ToDouble();
            ReflGraphing.SupSLD = SupSLDTB.ToDouble();
            ReflGraphing.CreateGraph(RhoGraph, "Reflectivity", "Q/Qc", "Intensity / Fresnel", AxisType.Log);
            ReflGraphing.LoadDatawithErrorstoGraph("Reflectivity Data", System.Drawing.Color.Black, SymbolType.Circle, 5, ReflData.Instance.GetQData, ReflData.Instance.GetReflData);

            //Set up ED Graph
            RhoGraphing        = new Graphing(string.Empty);
            RhoGraphing.SubSLD = SubphaseSLD.ToDouble();
            RhoGraphing.UseSLD = m_bUseSLD;
            RhoGraphing.SetGraphType(false, false);

            if (m_bUseSLD == false)
            {
                RhoGraphing.CreateGraph(EDzedGraphControl1, "Electron Density Profile", "Z", "Normalized Electron Density", AxisType.Linear);
            }
            else
            {
                RhoGraphing.CreateGraph(EDzedGraphControl1, "SLD Profile", "Z", "SLD", AxisType.Linear);
            }


            RhoGraphing.Pane.XAxis.Scale.Min = 0;
            RhoGraphing.Pane.XAxis.Scale.Max = ReflCalc.Z[ReflCalc.Z.Length - 1];

            loadingCircle2.Visible           = loadingCircle1.Visible = false;
            loadingCircle2.NumberSpoke       = loadingCircle1.NumberSpoke = 25;
            loadingCircle2.InnerCircleRadius = loadingCircle1.InnerCircleRadius = 60;
            loadingCircle2.OuterCircleRadius = loadingCircle1.OuterCircleRadius = 120;
            loadingCircle2.RotationSpeed     = loadingCircle1.RotationSpeed = 150;
            loadingCircle2.SpokeThickness    = loadingCircle1.SpokeThickness = 3;

            //Initialize constrain form
            ConstrForm = new Constraints(6);
            GreyFields();

            //Setup the callback if the graph updates the bounds
            ReflGraphing.ChangedBounds += new Graphing.ChangedEventHandler(PointChanged);

            //Setup the callback to update the frontend with new information
            ReflCalc.Update += new BoxReflFitBase.UpdateProfileHandler(ReflCalc_Update);
            ReflCalc_Update(null, null);
            MakeReflectivity();
        }