// 写入副头文件 private bool WriteSubHdr(subhdr SubHdr) { byte[] bytData = StructToBytes(SubHdr); fileStream.Write(bytData, 0, bytData.Length); /* * bytData = null; * GC.Collect(); * GC.WaitForPendingFinalizers(); */ return(true); }
// 读取副头文件 private bool ReadSubHdr(out subhdr SubHdr) { SubHdr = new subhdr(); byte[] bytData = new byte[Marshal.SizeOf(SubHdr)]; fileStream.Read(bytData, 0, bytData.Length); SubHdr = (subhdr)BytesToStruct(bytData, typeof(subhdr)); /* * bytData = null; * GC.Collect(); * GC.WaitForPendingFinalizers(); */ return(true); }
// 打开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); }
/// <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); }
/// <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); }