Exemplo n.º 1
0
        public void Setup(EasySpinHelper matlab)
        {
            NumberFormatInfo nfi = new NumberFormatInfo();

            nfi.NumberDecimalSeparator = ".";

            var exp = new StringBuilder();

            exp.Append("Exp  = struct(");
            exp.Append("'mwFreq'," + this.frequency.ToString(nfi) + ",");
            exp.Append("'nPoints'," + this.resolution + ",");
            exp.Append("'Range', [" + this.Xmin.ToString(nfi) + " " + this.Xmax.ToString(nfi) + "],");
            exp.Append("'Temperature'," + this.Temperature.ToString(nfi) + ",");
            exp.Append("'Harmonic'," + this.Harmonic + ");");

            Debug.WriteLine(exp.ToString());
            matlab.Execute(exp.ToString());
        }
Exemplo n.º 2
0
        public double[] AddSim(Sys sys, Exp exp, EPRSpectrum spc)
        {
            EasySpinHelper matlab = new EasySpinHelper(Properties.Settings.Default.es_plug);

            matlab.SetPath(Properties.Settings.Default.es_path);
            matlab.Execute("clc, clear");

            matlab.Put("y", spc.getY());
            if (sys.Spin > 0.5)
            {
                matlab.pepper(sys, exp);
            }
            else
            {
                matlab.garlic(sys, exp);
            }
            matlab.Execute("spc = rescale(spc,y,'lsq0');");
            matlab.Execute("spc = spc - max(y)/2");
            object data = matlab.Get("spc");

            double[,] datax = (double[, ])data;
            double[] y = BPUtil.singleCol(datax);
            return(y);
        }
Exemplo n.º 3
0
        //setup sys
        public void Setup(EasySpinHelper matlab)
        {
            NumberFormatInfo nfi = new NumberFormatInfo();

            nfi.NumberDecimalSeparator = ".";

            var sys = new StringBuilder();

            sys.Append("Sys = struct(");
            //no check for S
            sys.Append("'S', " + this.Spin.ToString(nfi) + ",");

            //g block start
            sys.Append("'g', [");
            for (int i = 0; i <= this.g.Length - 1; i++)
            {
                if (this.g[i] != 0)
                {
                    sys.Append(g[i].ToString(nfi));
                    if (i < this.g.Length - 1)
                    {
                        sys.Append(',');
                    }
                }
            }
            sys.Append("],");
            //g block end

            if (this.lw != 0)
            {
                sys.Append("'lw'," + this.lw.ToString(nfi) + ",");
            }

            //A block start
            if (this.A != null && this.A.Length > 0)
            {
                sys.Append("'A', [");
                for (int i = 0; i <= this.A.Length - 1; i++)
                {
                    sys.Append(this.A[i].ToString(nfi));
                    if (i < this.A.Length - 1)
                    {
                        sys.Append(',');
                    }
                }
                sys.Append("],");
            }

            //block nucs start
            if (this.Nucs != null && this.Nucs.Length > 0)
            {
                sys.Append("'Nucs', '");
                for (int i = 0; i <= this.Nucs.Length - 1; i++)
                {
                    sys.Append(this.Nucs[i]);
                    if (i < this.Nucs.Length - 1)
                    {
                        sys.Append(',');
                    }
                }
                sys.Append("',");
            }
            //blicks nucs end

            if (this.n != null && this.n.Length > 0)
            {
                sys.Append("'n', [");
                for (int i = 0; i <= this.n.Length - 1; i++)
                {
                    sys.Append(this.n[i]);
                    if (i < this.Nucs.Length - 1)
                    {
                        sys.Append(',');
                    }
                }
                sys.Append("],");
            }

            if (this.D != null && this.D.Length > 0)
            {
                sys.Append("'D', [");
                for (int i = 0; i <= this.D.Length - 1; i++)
                {
                    sys.Append(this.D[i].ToString(nfi));
                    if (i < this.D.Length - 1)
                    {
                        sys.Append(',');
                    }
                }
                sys.Append("],");
            }
            if (this.gStrain != null && this.gStrain.Length > 0)
            {
                sys.Append("'gStrain', [");
                for (int i = 0; i <= this.gStrain.Length - 1; i++)
                {
                    sys.Append(this.gStrain[i].ToString(nfi));
                    if (i < this.gStrain.Length - 1)
                    {
                        sys.Append(',');
                    }
                }
                sys.Append("],");
            }
            if (this.additional.Length != 0)
            {
                sys.Append(this.additional);
                sys.Append(",");
            }

            string _sys = "";
            //remove last comma
            var index = sys.ToString().LastIndexOf(',');

            if (index > 0)
            {
                _sys = sys.ToString().Substring(0, index);
            }

            sys = new StringBuilder();
            sys.Append(_sys);
            sys.Append(");");

            Debug.WriteLine(sys.ToString());
            //send to matlab
            matlab.Execute(sys.ToString());
        }