예제 #1
0
        // 写入文件头
        private bool WriteSpcHdr(spcdr SpcHdr)
        {
            byte[] bytData = StructToBytes(SpcHdr);
            fileStream.Write(bytData, 0, bytData.Length);

            /*
             * bytData = null;
             * GC.Collect();
             * GC.WaitForPendingFinalizers();
             */
            return(true);
        }
예제 #2
0
        // 读取文件头
        private bool ReadSpcHdr(out spcdr SpcHdr)
        {
            SpcHdr = new spcdr();
            byte[] bytData = new byte[Marshal.SizeOf(SpcHdr)];
            fileStream.Read(bytData, 0, bytData.Length);
            SpcHdr = (spcdr)BytesToStruct(bytData, typeof(spcdr));

            /*
             * bytData = null;
             * GC.Collect();
             * GC.WaitForPendingFinalizers();
             */

            return(true);
        }
예제 #3
0
        // 打开spc文件
        public bool Open(string fileName)
        {
            try
            {
                fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                m_SpcHdr   = new spcdr();
                m_SubHdr   = new subhdr();
            }
            catch (System.Exception ex)
            {
                m_strError = ex.Message;
                return(false);
            }


            return(true);
        }
예제 #4
0
        public const int G_RIGHTSPC_KEY_IS_FEXP   = 0x80; // ieee 32-bit floats

        // 判断Spc是否正确
        public bool IsRightSpcFile(string sFileName)
        {
            bool bRe = true;

            try
            {
                FileStream fs     = new FileStream(sFileName, FileMode.Open, FileAccess.Read);
                spcdr      SpcHdr = new spcdr();

                byte[] bytData = new byte[Marshal.SizeOf(SpcHdr)];
                fs.Read(bytData, 0, bytData.Length);
                SpcHdr = (spcdr)BytesToStruct(bytData, typeof(spcdr));

                if (SpcHdr.ftflgs != G_RIGHTSPC_KEY_IS_FTFLGS)
                {
                    bRe = false;
                }

                if (SpcHdr.fversn != G_RIGHTSPC_KEY_IS_FVERSN)
                {
                    bRe = false;
                }
                if (SpcHdr.fexper != G_RIGHTSPC_KEY_IS_FEXPER)
                {
                    bRe = false;
                }
                if (SpcHdr.fexp != G_RIGHTSPC_KEY_IS_FEXP)
                {
                    bRe = false;
                }
                bytData = null;
                fs.Flush();
                fs.Close();
                fs = null;
            }
            catch (System.Exception ex)
            {
                bRe = false;
            }
            finally
            {
            }

            return(bRe);
        }
예제 #5
0
        /// <summary>
        /// Read for single file type
        /// </summary>
        /// <param name="xdata"></param>
        /// <param name="ydata"></param>
        /// <returns></returns>
        public bool Read(out float[] xdata, out float[] ydata)
        {
            spcdr  strsd = m_SpcHdr;
            subhdr strsh = m_SubHdr;

            try
            {
                ReadSpcHdr(out strsd);
                int count = Convert.ToInt32(strsd.fnpts);
                ReadData(out xdata, count);
                ReadSubHdr(out strsh);
                ReadData(out ydata, count);
            }
            catch (Exception)
            {
                xdata = new float[1];
                ydata = new float[1];
                return(false);
            }

            return(true);
        }
예제 #6
0
        /// <summary>
        /// write for single file type
        /// </summary>
        /// <param name="xdata"></param>
        /// <param name="ydata"></param>
        /// <returns></returns>
        public bool Write(float[] xdata, float[] ydata)
        {
            spcdr  strsd = m_SpcHdr;
            subhdr strsh = m_SubHdr;

            if (xdata == null || ydata == null)
            {
                return(false);
            }

            if (xdata.Length != ydata.Length)
            {
                return(false);
            }

            // spchdr
            strsd.ftflgs = 0x80; // single file
            strsd.fversn = 0x4b; // new format
            strsd.fexper = 0x0b; // raman spectrum
            strsd.fexp   = 0x80; // ieee 32-bit floats
            strsd.fnpts  = Convert.ToUInt32(xdata.Length);
            strsd.ffirst = xdata[0];
            strsd.flast  = xdata[xdata.Length - 1];
            strsd.fnsub  = 1;              // only one subfile
            strsd.fxtype = 13;             // raman shift
            strsd.fytype = 4;              // counts
            strsd.fztype = 0;              // arbitrary
            strsd.fpost  = 0;              // 0
            strsd.fdate  = 0;
            ArrayClear(out strsd.fres, 9); // 0
            ArrayClear(out strsd.fsource, 9);
            strsd.fpeakpt = 0;             // not known
            ArrayClear(out strsd.fspare, 8);
            ArrayClear(out strsd.fcmnt, 130);
            ArrayClear(out strsd.fcatxt, 30);   // 0
            strsd.flogoff = 0;                  // no log block
            strsd.fmods   = 0;                  // 0
            strsd.fprocs  = 0;                  // 0
            strsd.flevel  = 0;                  // 0
            strsd.fsampin = 0;                  // 0
            strsd.ffactor = 0;                  // 0
            ArrayClear(out strsd.fmethod, 48);  // 0
            strsd.fzinc    = 0;                 // 0 for single file
            strsd.fwplanes = 0;                 // 0 for single file
            strsd.fwinc    = 0;                 // 0 for single file
            strsd.fwtype   = 0;                 // arbitrary
            ArrayClear(out strsd.freserv, 187); // 0

            // subhdr
            strsh.subflgs   = 0;              // 0
            strsh.subexp    = 0;              // fexp in spcdr is set
            strsh.subindx   = 0;              // only one sub file, 0 = start index
            strsh.subtime   = 0;              // 0
            strsh.subnext   = 0;              // 0
            strsh.subnois   = 0;              // 0
            strsh.subnpts   = 0;              // 0
            strsh.subscan   = 0;              // 0
            strsh.subwlevel = 0;              // 0
            ArrayClear(out strsh.subresv, 4); // 0

            // write private params
            //strsd.fdate = DateTime2Uint();
            //ArraySet(ref strsd.fsource, deviceName);
            //strsd.fspare[0] = Convert.ToSingle(laserPower);
            //strsd.fspare[1] = Convert.ToSingle(intTime);
            //strsd.fspare[2] = Convert.ToSingle(reNum);
            //strsd.fspare[3] = Convert.ToSingle();
            //strsd.fspare[4] = Convert.ToSingle();
            //strsd.fspare[5] = Convert.ToSingle();
            //strsd.fspare[6] = Convert.ToSingle();
            //strsd.fspare[7] = Convert.ToSingle();

            //string[] pair = new string[8];float[] peakPos
            //pair[0] =
            //pair[1] =
            //pair[2] =
            //pair[3] =
            //pair[4] =
            //pair[5] =
            //pair[6] =
            //pair[7] =
            //ArraySet(ref strsd.fcmnt, String.Join("|", pair));

            WriteSpcHdr(strsd);
            WriteData(xdata);
            WriteSubHdr(strsh);
            WriteData(ydata);
            fileStream.Flush();
            return(true);
        }