Ejemplo n.º 1
0
        private Ai.Hong.CommonLibrary.SpecFileFormatDouble ScanningSample(int scanCount, string specPath, string File, string addPara)
        {
            OpusCMD334.OpusCommand command = new OpusCMD334.OpusCommand();
            OpusCMD334.UnloadFile  unLoad  = new OpusCMD334.UnloadFile();
            Ai.Hong.CommonLibrary.SpecFileFormatDouble spcData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();

            string commandStr = "MeasureSample ({NSS = " + scanCount + "," + "PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
                                "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'" + addPara + "})";

            if (scanCount == 0)
            {
                commandStr = commandStr.Replace("NSS = " + scanCount + ",", string.Empty);
            }

            if (!command.Command(commandStr, true))
            {
                ErrorString = command.ErrorDesc;
                return(null);
            }
            specPath = specPath.Replace(".spc", string.Empty);
            if (!unLoad.Unload(specPath))
            {
                ErrorString = unLoad.ErrorDesc;
                return(null);
            }
            if (!spcData.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.SingleBeam))
            {
                ErrorString = spcData.ErrorString;
                return(null);
            }
            // System.Windows.MessageBox.Show(spcData.Parameter.)
            return(spcData);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 光谱兼容处理
        /// </summary>
        /// <param name="sourceFile">需要处理的光谱</param>
        /// <param name="destFile">标准光谱</param>
        /// <returns></returns>
        public override string MakeCompatiable(string sourceFile, string destFile)
        {
            Ai.Hong.CommonLibrary.SpecFileFormatDouble sourceData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            if (!sourceData.ReadFile(sourceFile))
            {
                return(null);
            }
            Ai.Hong.CommonLibrary.SpecFileFormatDouble destData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            if (!destData.ReadFile(destFile))
            {
                return(null);
            }
            try
            {
                if (sourceData.YDatas.Count() == destData.YDatas.Count())
                {
                    return(sourceFile);
                }
                double   step      = destData.XDatas[1] - destData.XDatas[0];
                double[] newXDatas = null;

                double orgfirstx = destData.Parameter.firstX;
                double orglastx  = destData.Parameter.lastX;
                //以DestFile为标准拟合dest
                destData.YDatas              = SpectrumStandardizingFit(destData, orgfirstx, orglastx, step, out newXDatas);
                destData.XDatas              = newXDatas;
                destData.Parameter.firstX    = newXDatas.Min();
                destData.Parameter.lastX     = newXDatas.Max();
                destData.Parameter.minYValue = destData.YDatas.Min();
                destData.Parameter.maxYValue = destData.YDatas.Max();
                destData.Parameter.dataCount = (uint)destData.YDatas.Count();
                //以DestFile为标准拟合source
                sourceData.YDatas              = SpectrumStandardizingFit(sourceData, orgfirstx, orglastx, step, out newXDatas);
                sourceData.XDatas              = newXDatas;
                sourceData.Parameter.firstX    = newXDatas.Min();
                sourceData.Parameter.lastX     = newXDatas.Max();
                sourceData.Parameter.minYValue = sourceData.YDatas.Min();
                sourceData.Parameter.maxYValue = sourceData.YDatas.Max();
                sourceData.Parameter.dataCount = (uint)sourceData.YDatas.Count();

                float[] floatData = new float[sourceData.YDatas.Count()];
                for (int i = 0; i < destData.YDatas.Count(); i++)
                {
                    floatData[i] = (float)destData.YDatas[i];
                }
                Ai.Hong.CommonLibrary.SPCFile.SaveFile(destFile, floatData, destData.Parameter);

                for (int i = 0; i < sourceData.YDatas.Count(); i++)
                {
                    floatData[i] = (float)sourceData.YDatas[i];
                }
                Ai.Hong.CommonLibrary.SPCFile.SaveFile(sourceFile, floatData, sourceData.Parameter);
            }
            catch { }
            return(sourceFile);
        }
        /// <summary>
        /// 计算吸收谱
        /// </summary>
        /// <param name="backFile">背景光谱</param>
        /// <param name="sampleFile">样品光谱</param>
        /// <returns></returns>
        public string CalculateAbs(string backFile, string sampleFile)
        {
            if (!System.IO.File.Exists(backFile) || !System.IO.File.Exists(sampleFile))
            {
                ErrorString = "Spectrum nos Exist!";
                return(null);
            }
            Ai.Hong.CommonLibrary.SpecFileFormatDouble back   = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            Ai.Hong.CommonLibrary.SpecFileFormatDouble sample = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            if (!back.ReadFile(backFile))
            {
                ErrorString = "Read Spectrum Error \r\n" + backFile;
                return(null);
            }
            if (!sample.ReadFile(sampleFile))
            {
                ErrorString = "Read Spectrum Error \r\n" + sample;
                return(null);
            }
            if (back.YDatas.Count() != sample.YDatas.Count())
            {
                ErrorString = "The points of back and sample not equal!";
                return(null);
            }
            int count = back.YDatas.Count() > sample.YDatas.Count() ? sample.YDatas.Count() : back.YDatas.Count();

            for (int i = 0; i < count; i++)
            {
                if (back.YDatas[i] == 0)
                {
                    back.YDatas[i] = 1;
                }
                else
                {
                    back.YDatas[i] = Math.Abs(sample.YDatas[i] / back.YDatas[i]);
                }
            }
            //得到吸收光谱
            for (int i = 0; i < back.YDatas.Count(); i++)
            {
                back.YDatas[i] = Math.Log10(1 / back.YDatas[i]);
            }
            float[] trData = new float[back.YDatas.Length];
            for (int index = 0; index < trData.Length; index++)
            {
                trData[index] = (float)back.YDatas[index];
            }
            string fileName = System.IO.Path.GetFileNameWithoutExtension(sampleFile);

            fileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(sampleFile), fileName + "_abs.spc");
            //存储样品吸光度光谱
            Ai.Hong.CommonLibrary.SPCFile.SaveFile(fileName, trData, sample.Parameter);
            return(fileName);
        }
        /// <summary>
        /// 计算吸收谱
        /// </summary>
        /// <param name="backFile">背景光谱</param>
        /// <param name="sampleFile">样品光谱</param>
        /// <returns></returns>
        public string CalculateAbs(string backFile, string sampleFile)
        {
            if (!System.IO.File.Exists(backFile) || !System.IO.File.Exists(sampleFile))
            {
                errorCode = -16;
                return(null);
            }
            Ai.Hong.CommonLibrary.SpecFileFormatDouble back   = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            Ai.Hong.CommonLibrary.SpecFileFormatDouble sample = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            if (!back.ReadFile(backFile))
            {
                errorCode = -17;
                return(null);
            }
            if (!sample.ReadFile(sampleFile))
            {
                errorCode = -17;
                return(null);
            }
            if (back.YDatas.Count() != sample.YDatas.Count())
            {
                errorCode = -18;
                return(null);
            }
            for (int i = 0; i < back.YDatas.Count(); i++)
            {
                if (back.YDatas[i] == 0)
                {
                    back.YDatas[i] = 1;
                }
                else
                {
                    back.YDatas[i] = Math.Abs(sample.YDatas[i] / back.YDatas[i]);
                }
            }
            //得到吸收光谱
            for (int i = 0; i < back.YDatas.Count(); i++)
            {
                back.YDatas[i] = Math.Log10(1 / back.YDatas[i]);
            }
            float[] trData = new float[back.YDatas.Length];
            for (int index = 0; index < trData.Length; index++)
            {
                trData[index] = (float)back.YDatas[index];
            }
            string fileName = System.IO.Path.GetFileNameWithoutExtension(sampleFile);

            fileName = Path.Combine(System.IO.Path.GetDirectoryName(sampleFile), fileName + "_abs.spc");
            //存储样品吸光度光谱
            Ai.Hong.CommonLibrary.SPCFile.SaveFile(fileName, trData, sample.Parameter);
            return(fileName);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 用新的参数拟合光谱
        /// </summary>
        /// <param name="fileData">原有光谱文件数据</param>
        /// <param name="xDatas">拟合后的X轴数据</param>
        /// <returns>拟合后的Y轴数据</returns>
        public static double[] SpectrumStandardizingFit(Ai.Hong.CommonLibrary.SpecFileFormatDouble fileData, double firstx, double lastx, double stepx, out double[] xDatas)
        {
            try
            {
                if (fileData == null || fileData.XDatas == null || fileData.YDatas == null ||
                    fileData.XDatas.Length == 0 || fileData.XDatas.Length != fileData.YDatas.Length)
                {
                    throw new Exception("原始光谱读取错误");
                }

                if ((stepx > 0 && lastx < firstx + stepx) || (stepx < 0 && lastx > firstx + stepx))
                {
                    throw new Exception("拟合参数错误");
                }

                //对转换为波数的nirstR.spc进行三次样条曲线拟合
                alglib.spline1dinterpolant c;
                alglib.spline1dbuildcubic(fileData.XDatas, fileData.YDatas, out c);

                //按照当前X轴校正后的坐标对Y轴重新插值
                int datacount = (int)((lastx - firstx) / stepx);
                xDatas = new double[datacount];

                double[] yDatas = new double[datacount];
                for (int i = 0; i < datacount; i++)
                {
                    xDatas[i] = firstx + i * stepx;
                    yDatas[i] = alglib.spline1dcalc(c, xDatas[i]);
                }

                return(yDatas);
            }
            catch (Exception ex)
            {
                xDatas      = null;
                ErrorString = ex.Message;
                return(null);
            }
        }
Ejemplo n.º 6
0
        private Ai.Hong.CommonLibrary.SpecFileFormatDouble ScanningBack(int scanCount, string specPath, string File, string addPara)
        {
            OpusCMD334.OpusCommand command = new OpusCMD334.OpusCommand();
            OpusCMD334.UnloadFile  unLoad  = new OpusCMD334.UnloadFile();
            Ai.Hong.CommonLibrary.SpecFileFormatDouble spcData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();

            string commandStr = "MeasureReference ({NSR = " + scanCount + ",APT='Open' " + addPara + "})";

            if (scanCount == 0)
            {
                commandStr = commandStr.Replace("NSR = " + scanCount + ",", string.Empty);
            }
            if (!command.Command(commandStr, true))
            {
                ErrorString = command.ErrorDesc;
                return(null);
            }
            //System.Windows.MessageBox.Show("Scan Complete! " + specPath);
            OpusCMD334.SaveReference saveBack = new OpusCMD334.SaveReference();
            //System.Windows.MessageBox.Show("begin Save reference " + File);
            if (!saveBack.SaveReference(System.IO.Path.GetFileName(File), System.IO.Path.GetDirectoryName(File)))
            {
                ErrorString = saveBack.ErrorDesc;
                return(null);
            }
            //System.Windows.MessageBox.Show("begin UnLoad " +File );
            if (System.IO.File.Exists(File) && !unLoad.Unload(File))
            {
                ErrorString = unLoad.ErrorDesc;
                return(null);
            }
            //System.Windows.MessageBox.Show("begin UnLoad " + specPath);
            if (System.IO.File.Exists(specPath) && !unLoad.Unload(specPath))
            {
                ErrorString = unLoad.ErrorDesc;
                return(null);
            }
            //System.Windows.MessageBox.Show("UnLoad Complete " + specPath);
            if (System.IO.File.Exists(specPath) && !spcData.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.Background))
            {
                //System.Windows.MessageBox.Show("read error !" + specPath);
                ErrorString = spcData.ErrorString;
                return(null);
            }
            if (System.IO.File.Exists(File) && !spcData.ReadFile(File, Ai.Hong.CommonLibrary.SpecFileFormat.specType.Background))
            {
                //System.Windows.MessageBox.Show("read error !" + File);
                ErrorString = spcData.ErrorString;
                return(null);
            }
            if (addPara != null && addPara.Contains("HFQ") && addPara.Contains("LFQ"))
            {
                try
                {
                    string[] temp     = addPara.Split(',');
                    string   fxString = (from p in temp where p.Contains("HFQ") select p).First().Trim().Replace("HFQ=", string.Empty);
                    string   lxString = (from p in temp where p.Contains("LFQ") select p).First().Trim().Replace("LFQ=", string.Empty);
                    Ai.Hong.CommonLibrary.SpecFileFormatDouble backData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
                    backData.Parameter = spcData.Parameter;
                    int indexX = Ai.Hong.SpectrumAlgorithm.SpectrumAlgorithm.FindNearestPosition(spcData.XDatas, 0, spcData.XDatas.Length - 1, Convert.ToInt32(fxString));
                    int indexY = Ai.Hong.SpectrumAlgorithm.SpectrumAlgorithm.FindNearestPosition(spcData.XDatas, 0, spcData.XDatas.Length - 1, Convert.ToInt32(lxString));

                    if (indexX != -1 && indexY != -1)
                    {
                        float[] tun = new float[Math.Abs(indexX - indexY) + 1];
                        backData.XDatas = new double[tun.Length];
                        backData.YDatas = new double[tun.Length];
                        for (int i = indexX; i < indexY + 1; i++)
                        {
                            tun[i - indexX]             = (float)spcData.XDatas[i];
                            backData.XDatas[i - indexX] = spcData.XDatas[i];
                            backData.YDatas[i - indexX] = spcData.YDatas[i];
                        }
                        backData.Parameter.dataCount = (uint)tun.Length;
                        if (tun.Length > 0)
                        {
                            backData.Parameter.firstX = tun[0];
                            backData.Parameter.lastX  = tun[tun.Length - 1];
                        }
                        backData.Parameter.maxYValue = (from p in tun select p).ToList().Max();
                        backData.Parameter.maxYValue = (from p in tun select p).ToList().Min();
                        spcData = backData;
                    }
                }
                catch { }
            }
            //Ai.Hong.CommonLibrary.SpecFileFormatDouble backData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            //backData.Parameter = spcData.Parameter;
            //int indexX = Ai.Hong.SpectrumAlgorithm.SpectrumAlgorithm.FindNearestPosition(spcData.XDatas, 0, spcData.XDatas.Length - 1, 4000);
            //int indexY = Ai.Hong.SpectrumAlgorithm.SpectrumAlgorithm.FindNearestPosition(spcData.XDatas, 0, spcData.XDatas.Length - 1, 12000);

            //if (indexX != -1 && indexY != -1)
            //{
            //    float[] tun = new float[Math.Abs(indexX - indexY) + 1];
            //    backData.XDatas = new double[tun.Length];
            //    backData.YDatas = new double[tun.Length];
            //    for (int i = indexX; i < indexY + 1; i++)
            //    {
            //        tun[i - indexX] = (float)spcData.XDatas[i];
            //        backData.XDatas[i - indexX] = spcData.XDatas[i];
            //        backData.YDatas[i - indexX] = spcData.YDatas[i];
            //    }
            //    backData.Parameter.dataCount = (uint)tun.Length;
            //    if (tun.Length > 0)
            //    {
            //        backData.Parameter.firstX = tun[0];
            //        backData.Parameter.lastX = tun[tun.Length - 1];
            //    }
            //    backData.Parameter.maxYValue = (from p in tun select p).ToList().Max();
            //    backData.Parameter.maxYValue = (from p in tun select p).ToList().Min();
            //    spcData = backData;
            //}
            return(spcData);
        }
Ejemplo n.º 7
0
        private string ScanSpec(string scanMethodFile, int scanCount, string File, bool IsScanBack, string addPara = "")
        {
            if (!LoadXPM(scanMethodFile) || !System.IO.Path.HasExtension(File))
            {
                return(null);
            }
            if (IsScanBack)
            {
                MoveWheel(0, scanMethodFile);
            }
            string specPath = File + ".0";

            if (System.IO.File.Exists(specPath))
            {
                OpusCMD334.UnloadFile unLoadFile = new OpusCMD334.UnloadFile();
                unLoadFile.Unload(specPath);
                System.IO.File.Delete(specPath);
            }
            if (System.IO.File.Exists(File))
            {
                System.IO.File.Delete(File);
            }

            OpusCMD334.OpusCommand command = new OpusCMD334.OpusCommand();
            OpusCMD334.UnloadFile  unLoad  = new OpusCMD334.UnloadFile();
            Ai.Hong.CommonLibrary.SpecFileFormatDouble spcData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            if (IsScanBack)
            {
                string para = addPara;
                if (addPara == null || (addPara != null && !addPara.Contains("HFQ") && !addPara.Contains("LFQ")))
                {
                    //OpusCMD334.ReadParameter read = new OpusCMD334.ReadParameter();
                    //if (!read.ReadParm("HFQ", scanMethodFile))
                    //{
                    //    ErrorString = "Read HFQ Error! Please Restart System";
                    //    return null;
                    //}
                    //para += ",HFQ=" + read.Value;
                    //if (!read.ReadParm("LFQ", scanMethodFile))
                    //{
                    //    ErrorString = "Read LFQ Error! Please Restart System";
                    //    return null;
                    //}
                    //para += ",LFQ=" + read.Value;
                    para += ",HFQ=4000,LFQ=12000";//默认为4000-12000
                }
                //System.Windows.MessageBox.Show("begin Scan " + specPath);
                spcData = ScanningBack(scanCount, specPath, File, para);
            }
            else
            {
                spcData = ScanningSample(scanCount, specPath, File, addPara);
                //if (spcData == null)
                //{
                //    ScanningBack(scanCount, specPath, File);
                //    spcData = ScanningSample(scanCount, specPath, File, addPara);
                //}
            }
            if (spcData == null)
            {
                ErrorString = "Scan Error";
                return(null);
            }
            float[] tr = new float[spcData.YDatas.Count()];
            for (int i = 0; i < spcData.YDatas.Count(); i++)
            {
                tr[i] = (float)spcData.YDatas[i];
            }
            Ai.Hong.CommonLibrary.SPCFile.SaveFile(File, tr, spcData.Parameter);

            //System.IO.File.Move(specPath, File);
            if (System.IO.File.Exists(specPath) && !string.Equals(specPath, File))
            {
                unLoad.Unload(specPath);
                System.IO.File.Delete(specPath);
            }
            return(File);
            //if (!LoadXPM(scanMethodFile) || !System.IO.Path.HasExtension(File))
            //{
            //    return null;
            //}
            //if (IsScanBack)
            //{
            //    MoveWheel(0, scanMethodFile);
            //}
            //string specPath = File.Replace(".spc", ".0");
            //if (System.IO.File.Exists(specPath))
            //{
            //    OpusCMD334.UnloadFile unLoadFile = new OpusCMD334.UnloadFile();
            //    unLoadFile.Unload(specPath);
            //    System.IO.File.Delete(specPath);
            //}
            //if (System.IO.File.Exists(File))
            //{
            //    System.IO.File.Delete(File);
            //}

            //OpusCMD334.OpusCommand command = new OpusCMD334.OpusCommand();
            //OpusCMD334.UnloadFile unLoad = new OpusCMD334.UnloadFile();

            //Ai.Hong.CommonLibrary.SpecFileFormatDouble data = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            //if (IsScanBack)
            //{
            //    string commandString = "MeasureReference ({PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
            //        "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'" + addPara + " })";
            //    bool retcode = command.Command(commandString, true);
            //    string[] retstrs = command.CommandResult.Split('\n');
            //    if (retcode == false || retstrs.Length < 1 || retstrs[0] != "OK")
            //    {
            //        ErrorString = command.ErrorDesc;
            //        return null;
            //    }
            //    if (addPara != null)
            //        addPara = addPara.Replace("NSR", "NSS");
            //    commandString = "MeasureSample ({PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
            //        "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'" + addPara + "})";
            //    retcode = command.Command(commandString, true);
            //    retstrs = command.CommandResult.Split('\n');
            //    if (retcode == false || retstrs.Length < 4 || retstrs[0] != "OK")
            //    {
            //        ErrorString = command.ErrorDesc;
            //        return null;
            //    }
            //    UnloadFileByCommand(retstrs[3]);
            //    //if (!unLoad.Unload(specPath))
            //    //{
            //    //    ErrorString = unLoad.ErrorDesc;
            //    //    return null;
            //    //}
            //    if (!data.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.Background))
            //    {
            //        ErrorString = data.ErrorString;
            //        return null;
            //    }

            //}
            //else
            //{
            //    string cmdstr = "MeasureSample ({PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
            //        "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'" + addPara + "})";
            //    if (!command.Command(cmdstr, true))
            //    {
            //        ErrorString = command.ErrorDesc;
            //        return null;
            //    }
            //    if (!unLoad.Unload(specPath))
            //    {
            //        ErrorString = unLoad.ErrorDesc;
            //        return null;
            //    }
            //    if (!data.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.SingleBeam))
            //    {
            //        ErrorString = data.ErrorString;
            //        return null;
            //    }
            //}
            //float[] tr = new float[data.YDatas.Count()];
            //for (int i = 0; i < data.YDatas.Count(); i++)
            //{
            //    tr[i] = (float)data.YDatas[i];
            //}
            //Ai.Hong.CommonLibrary.SPCFile.SaveFile(File, tr, data.Parameter);


            //if (System.IO.File.Exists(specPath) && !string.Equals(specPath, File))
            //{
            //    unLoad.Unload(specPath);
            //    System.IO.File.Delete(specPath);
            //}
            //return File;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 光谱兼容处理
        /// </summary>
        /// <param name="sourceFile">需要处理的光谱</param>
        /// <param name="destFile">标准光谱</param>
        /// <returns></returns>
        public override string MakeCompatiable(string sourceFile, string destFile)
        {
            Ai.Hong.CommonLibrary.SpecFileFormatDouble sourceData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            if (!sourceData.ReadFile(sourceFile))
            {
                return(null);
            }
            Ai.Hong.CommonLibrary.SpecFileFormatDouble destData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            if (!destData.ReadFile(destFile))
            {
                return(null);
            }
            bool IsNeedChange = false;

            if (sourceData.YDatas.Count() < destData.YDatas.Count())
            {
                IsNeedChange = true;
                string temp = sourceFile;
                sourceFile = destFile;
                destFile   = temp;
            }
            string opusSrcFile = LoadFileByCommand(sourceFile);
            string opusDstFile = LoadFileByCommand(destFile);

            if (opusSrcFile == null || opusDstFile == null)
            {
                if (opusSrcFile != null)
                {
                    UnloadFileByCommand(opusSrcFile);
                }

                if (opusDstFile != null)
                {
                    UnloadFileByCommand(opusDstFile);
                }
                return(null);
            }

            if (ChangeDataBlockType(opusSrcFile, "Spec", "AB") == false)
            {
                return(null);
            }

            if (ChangeDataBlockType(opusDstFile, "Spec", "AB") == false)
            {
                return(null);
            }

            //谱图兼容
            OpusCMD334.OpusCommand cmd = new OpusCMD334.OpusCommand();
            string cmdstr  = string.Format("MakeCompatible ([{0}:Spec], [{1}:Spec], {{}});", opusDstFile, opusSrcFile);
            bool   cmdcode = cmd.Command(cmdstr);

            string[] cmdrets = cmd.CommandResult.Split('\n');
            if (cmdcode == false || cmdrets.Length < 4 || cmdrets[0] != "OK")
            {
                return(null);
            }



            //SaveAsSPC(opusSrcFile, sourceFile);
            //SaveAsSPC(opusDstFile, destFile);

            //
            if (SaveFileByCommand(opusSrcFile) == false ||
                SaveFileByCommand(opusDstFile) == false ||
                UnloadFileByCommand(opusSrcFile) == false ||
                UnloadFileByCommand(opusDstFile) == false)
            {
                return(null);
            }
            if (IsNeedChange)
            {
                string temp = sourceFile;
                sourceFile = destFile;
                destFile   = temp;
            }
            return(sourceFile);
        }
Ejemplo n.º 9
0
        private string ScanSpec(string scanMethodFile, int scanCount, string File, bool IsScanBack, string addPara = "")
        {
            //if (!LoadXPM(scanMethodFile) || !System.IO.Path.HasExtension(File))
            //{
            //    return null;
            //}
            //if (IsScanBack)
            //{
            //    MoveWheel(0, scanMethodFile);
            //}
            //string specPath = File + ".0";
            //if (System.IO.File.Exists(specPath))
            //{
            //    OpusCMD334.UnloadFile unLoadFile = new OpusCMD334.UnloadFile();
            //    unLoadFile.Unload(specPath);
            //    System.IO.File.Delete(specPath);
            //}
            //if (System.IO.File.Exists(File))
            //{
            //    System.IO.File.Delete(File);
            //}

            //OpusCMD334.OpusCommand command = new OpusCMD334.OpusCommand();
            //OpusCMD334.UnloadFile unLoad = new OpusCMD334.UnloadFile();
            //Ai.Hong.CommonLibrary.SpecFileFormatDouble spcData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            //if (IsScanBack)
            //{
            //    if (!command.Command("MeasureReference ({NSR = " + scanCount + "})", true))
            //    {
            //        ErrorString = command.ErrorDesc;
            //        return null;
            //    }
            //    OpusCMD334.SaveReference saveBack = new OpusCMD334.SaveReference();
            //    if (!saveBack.SaveReference(System.IO.Path.GetFileName(File), System.IO.Path.GetDirectoryName(File)))
            //    {
            //        ErrorString = saveBack.ErrorDesc;
            //        return null;
            //    }
            //    if (!unLoad.Unload(specPath))
            //    {
            //        ErrorString = unLoad.ErrorDesc;
            //        return null;
            //    }
            //    if (!spcData.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.Background))
            //    {
            //        ErrorString = spcData.ErrorString;
            //        return null;
            //    }
            //    Ai.Hong.CommonLibrary.SpecFileFormatDouble backData = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            //    backData.Parameter = spcData.Parameter;
            //    int indexX = Ai.Hong.SpectrumAlgorithm.SpectrumAlgorithm.FindNearestPosition(spcData.XDatas, 0, spcData.XDatas.Length - 1, 4000);
            //    int indexY = Ai.Hong.SpectrumAlgorithm.SpectrumAlgorithm.FindNearestPosition(spcData.XDatas, 0, spcData.XDatas.Length - 1, 12000);

            //    if (indexX != -1 && indexY != -1)
            //    {
            //        float[] tun = new float[Math.Abs(indexX - indexY) + 1];
            //        backData.XDatas = new double[tun.Length];
            //        backData.YDatas = new double[tun.Length];
            //        for (int i = indexX; i < indexY + 1; i++)
            //        {
            //            tun[i - indexX] = (float)spcData.XDatas[i];
            //            backData.XDatas[i - indexX] = spcData.XDatas[i];
            //            backData.YDatas[i - indexX] = spcData.YDatas[i];
            //        }
            //        backData.Parameter.dataCount = (uint)tun.Length;
            //        if (tun.Length > 0)
            //        {
            //            backData.Parameter.firstX = tun[0];
            //            backData.Parameter.lastX = tun[tun.Length - 1];
            //        }
            //        backData.Parameter.maxYValue = (from p in tun select p).ToList().Max();
            //        backData.Parameter.maxYValue = (from p in tun select p).ToList().Min();
            //        spcData = backData;
            //    }
            //}
            //else
            //{
            //    if (!command.Command("MeasureSample ({NSS = " + scanCount + "," + "PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
            //        "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'})", true))
            //    {
            //        ErrorString = command.ErrorDesc;
            //        return null;
            //    }
            //    specPath = specPath.Replace(".spc", string.Empty);
            //    if (!unLoad.Unload(specPath))
            //    {
            //        ErrorString = unLoad.ErrorDesc;
            //        return null;
            //    }
            //    if (!spcData.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.SingleBeam))
            //    {
            //        ErrorString = spcData.ErrorString;
            //        return null;
            //    }
            //}
            //float[] tr = new float[spcData.YDatas.Count()];
            //for (int i = 0; i < spcData.YDatas.Count(); i++)
            //{
            //    tr[i] = (float)spcData.YDatas[i];
            //}
            //Ai.Hong.CommonLibrary.SPCFile.SaveFile(File, tr, spcData.Parameter);

            ////System.IO.File.Move(specPath, File);
            //if (System.IO.File.Exists(specPath) && !string.Equals(specPath, File))
            //{
            //    unLoad.Unload(specPath);
            //    System.IO.File.Delete(specPath);
            //}
            //return File;
            if (!LoadXPM(scanMethodFile) || !System.IO.Path.HasExtension(File))
            {
                return(null);
            }
            if (IsScanBack)
            {
                MoveWheel(0, scanMethodFile);
            }
            string specPath = File.Replace(".spc", ".0");

            if (System.IO.File.Exists(specPath))
            {
                OpusCMD334.UnloadFile unLoadFile = new OpusCMD334.UnloadFile();
                unLoadFile.Unload(specPath);
                System.IO.File.Delete(specPath);
            }
            if (System.IO.File.Exists(File))
            {
                System.IO.File.Delete(File);
            }

            OpusCMD334.OpusCommand command = new OpusCMD334.OpusCommand();
            OpusCMD334.UnloadFile  unLoad  = new OpusCMD334.UnloadFile();

            Ai.Hong.CommonLibrary.SpecFileFormatDouble data = new Ai.Hong.CommonLibrary.SpecFileFormatDouble();
            if (IsScanBack)
            {
                string commandString = "MeasureReference ({PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
                                       "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'" + addPara + " })";
                bool     retcode = command.Command(commandString, true);
                string[] retstrs = command.CommandResult.Split('\n');
                if (retcode == false || retstrs.Length < 1 || retstrs[0] != "OK")
                {
                    ErrorString = command.ErrorDesc;
                    return(null);
                }
                if (addPara != null)
                {
                    addPara = addPara.Replace("NSR", "NSS");
                }
                commandString = "MeasureSample ({PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
                                "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'" + addPara + "})";
                retcode = command.Command(commandString, true);
                retstrs = command.CommandResult.Split('\n');
                if (retcode == false || retstrs.Length < 4 || retstrs[0] != "OK")
                {
                    ErrorString = command.ErrorDesc;
                    return(null);
                }
                UnloadFileByCommand(retstrs[3]);
                //if (!unLoad.Unload(specPath))
                //{
                //    ErrorString = unLoad.ErrorDesc;
                //    return null;
                //}
                if (!data.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.Background))
                {
                    ErrorString = data.ErrorString;
                    return(null);
                }
            }
            else
            {
                string cmdstr = "MeasureSample ({PTH='" + System.IO.Path.GetDirectoryName(File) + "'," +
                                "NAM='" + System.IO.Path.GetFileNameWithoutExtension(File) + "'" + addPara + "})";
                if (!command.Command(cmdstr, true))
                {
                    ErrorString = command.ErrorDesc;
                    return(null);
                }
                if (!unLoad.Unload(specPath))
                {
                    ErrorString = unLoad.ErrorDesc;
                    return(null);
                }
                if (!data.ReadFile(specPath, Ai.Hong.CommonLibrary.SpecFileFormat.specType.SingleBeam))
                {
                    ErrorString = data.ErrorString;
                    return(null);
                }
            }
            float[] tr = new float[data.YDatas.Count()];
            for (int i = 0; i < data.YDatas.Count(); i++)
            {
                tr[i] = (float)data.YDatas[i];
            }
            Ai.Hong.CommonLibrary.SPCFile.SaveFile(File, tr, data.Parameter);


            if (System.IO.File.Exists(specPath) && !string.Equals(specPath, File))
            {
                unLoad.Unload(specPath);
                System.IO.File.Delete(specPath);
            }
            return(File);
        }