/// <summary>
        /// 读取文件中组分列表
        /// <param name="fileData">文件内容</param>
        /// </summary>
        public static string[] GetComponentName(byte[] fileData)
        {
            MainHeader mainheader = GetMainHeader(fileData);

            if (mainheader.fileMark == UInt16.MaxValue)  //读取文件头错误
            {
                return(null);
            }

            string[] retData   = new string[mainheader.componentCount];
            byte[]   nameArray = new byte[CompNameLength]; //组分名称最长0x10

            for (int i = 0; i < mainheader.componentCount; i++)
            {
                Array.Copy(mainheader.components, i * CompNameLength, nameArray, 0, CompNameLength);
                retData[i] = CommonMethod.CovertByteArrayToString(nameArray, Encoding.Default);
            }

            return(retData);
        }
        /// <summary>
        /// 获取模型的组分信息
        /// </summary>
        /// <param name="fileData">模型文件数据</param>
        /// <returns>组分信息列表</returns>
        public static List <Ai.Hong.FileFormat.QuantModelFormat.QuantComponentInfo> GetComponentList(byte[] fileData)
        {
            var comps = QuantGetComponentInfo(fileData);

            if (comps == null)
            {
                return(null);
            }

            var retDatas = new List <Ai.Hong.FileFormat.QuantModelFormat.QuantComponentInfo>();

            foreach (var item in comps)
            {
                var curInfo = new Ai.Hong.FileFormat.QuantModelFormat.QuantComponentInfo();
                curInfo.name = CommonMethod.CovertByteArrayToString(item.name, Encoding.Default);
                curInfo.unit = CommonMethod.CovertByteArrayToString(item.unit, Encoding.Default);
                retDatas.Add(curInfo);
            }

            return(retDatas);
        }
        /// <summary>
        /// 读取文本的LOG数据
        /// </summary>
        public static string GetLogText(byte[] fileData, int fileSize)
        {
            IntPtr retptr   = IntPtr.Zero;
            int    datasize = 0;

            if (CommonMethod.Is64BitVersion())
            {
                retptr = SPCGetLogText64(fileData, fileSize, ref datasize);
            }
            else
            {
                retptr = SPCGetLogText32(fileData, fileSize, ref datasize);
            }

            byte[] tempdatas = CommonMethod.CopyByteFromIntptrAndFree(ref retptr, datasize);
            if (tempdatas == null)
            {
                return(null);
            }

            return(Encoding.ASCII.GetString(tempdatas));     //这里假定都是ASCII格式字符串
        }
        /// <summary>
        /// 读取Y轴数据
        /// </summary>
        /// <param name="fileData"></param>
        /// <param name="fileSize"></param>
        /// <returns></returns>
        private static double[] GetYData(byte[] fileData, int fileSize)
        {
            try
            {
                IntPtr retptr   = IntPtr.Zero;
                int    datasize = 0;
                if (CommonMethod.Is64BitVersion())
                {
                    retptr = SPAGetYDatas64(fileData, fileSize, ref datasize);
                }
                else
                {
                    retptr = SPAGetYDatas32(fileData, fileSize, ref datasize);
                }

                return(CommonMethod.CopyDataArrayFromIntptrAndFree <double>(ref retptr, datasize));
            }
            catch (Exception ex)
            {
                ErrorString = ex.Message;
                return(null);
            }
        }
        /// <summary>
        /// 读取子数据的结构
        /// </summary>
        /// <param name="fileData">文件数据</param>
        /// <param name="fileSize">文件大小</param>
        /// <param name="subIndex">需要获取子结构的序号</param>
        /// <returns>子数据的结构</returns>
        private static SPCSubHeader GetSubHeader(byte[] fileData, int fileSize, int subIndex)
        {
            IntPtr retptr   = IntPtr.Zero;
            int    datasize = 0;

            if (CommonMethod.Is64BitVersion())
            {
                retptr = SPCGetSubHeader64(fileData, fileSize, subIndex, ref datasize);
            }
            else
            {
                retptr = SPCGetSubHeader32(fileData, fileSize, subIndex, ref datasize);
            }

            bool         retOK;
            SPCSubHeader retheader = CommonMethod.CopyStructureFromIntptrAndFree <SPCSubHeader>(ref retptr, out retOK);

            if (!retOK)
            {
                retheader.subnpts = int.MaxValue;     //表示错误数据
            }
            return(retheader);
        }
        /// <summary>
        /// 创建double类型的数据块(不压缩格式)
        /// </summary>
        /// <param name="fileData">数据</param>
        /// <param name="dataRows">数据行数</param>
        /// <param name="entryName">数据块名称</param>
        /// <returns>Matlab数据块</returns>
        public static byte[] CreateDoubleEntry(double[] fileData, int dataRows, string entryName = ACloudSpectrumDataName)
        {
            if (fileData == null || fileData.Length < 0 || (fileData.Length % dataRows) != 0 || string.IsNullOrWhiteSpace(entryName))
            {
                ErrorString = "Invalid parameters";
                return(null);
            }

            try
            {
                int dataCols = fileData.Length / dataRows;

                IntPtr retptr   = IntPtr.Zero;
                int    datasize = 0;
                if (CommonMethod.Is64BitVersion())
                {
                    retptr = MATCreateDoubleEntry64(fileData, fileData.Length, entryName, dataRows, dataCols, ref datasize);
                }
                else
                {
                    retptr = MATCreateDoubleEntry32(fileData, fileData.Length, entryName, dataRows, dataCols, ref datasize);
                }

                if (retptr == IntPtr.Zero)
                {
                    ErrorString = FileFormat.GetDLLErrorMessage();
                    return(null);
                }

                return(CommonMethod.CopyByteFromIntptrAndFree(ref retptr, datasize));
            }
            catch (Exception ex)
            {
                ErrorString = ex.Message;
                return(null);
            }
        }
        //将文件保存为JCAMP_DX格式
        public static byte[] SaveFile(FileFormat fileFormat)
        {
            StreamWriter stream = null;

            if (fileFormat == null)
            {
                return(null);
            }

            //临时文件
            string tempSaveFile = Path.GetTempFileName();

            try
            {
                stream = new StreamWriter(tempSaveFile, false, Encoding.UTF8);

                //文件头
                DateTime filetime = File.GetCreationTime(tempSaveFile);

                //如果有多个数据块,需要一个总的文件头
                if (fileFormat.yDataList.Count > 1)
                {
                    stream.WriteLine("##TITLE=ACloud Export File");
                    stream.WriteLine("##JCAMP-DX=5.01");
                    stream.WriteLine("##DATA TYPE= LINK");
                    stream.WriteLine("##BLOCKS= " + fileFormat.yDataList.Count);
                }

                for (int i = 0; i < fileFormat.yDataList.Count; i++)
                {
                    //如果多个X轴,取对应的X,否则取第一个X轴
                    double[] xDatas = fileFormat.xDataList.Count > i ? fileFormat.xDataList[i] : fileFormat.xDatas;
                    if (WriteOneBlock(stream, fileFormat.fileInfo, fileFormat.dataInfoList[i], xDatas, fileFormat.yDataList[i]) == false)
                    {
                        throw new Exception(ErrorString);
                    }
                }
                stream.Close();
                stream = null;

                //将全部文件读出
                byte[] retData = CommonMethod.ReadBinaryFile(tempSaveFile);
                if (retData == null)
                {
                    throw new Exception(CommonMethod.ErrorString);
                }

                return(retData);
            }
            catch (System.Exception ex)
            {
                ErrorString = ex.Message;
                return(null);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }

                if (File.Exists(tempSaveFile))
                {
                    File.Delete(tempSaveFile);
                }
            }
        }
        /// <summary>
        /// 保存光谱
        /// </summary>
        /// <param name="fileFormat">光谱数据</param>
        /// <param name="serialNo">仪器序列号</param>
        /// <param name="compNames">组分名称</param>
        /// <param name="compDatas">组分浓度</param>
        /// <param name="fileTimes">文件时间</param>
        /// <returns></returns>
        public static byte[] SaveFile(FileFormat fileFormat, string serialNo, string[] compNames, double[] compDatas, DateTime[] fileTimes)
        {
            //必须相同的X轴才能保存
            for (int i = 1; i < fileFormat.xDataList.Count; i++)
            {
                if (CommonMethod.IsSameXDatas(fileFormat.xDataList[i], fileFormat.xDataList[0]) == false)
                {
                    ErrorString = "X datas is different";
                    return(null);
                }
            }

            //Y轴数据点数必须相同
            for (int i = 1; i < fileFormat.yDataList.Count; i++)
            {
                if (fileFormat.yDataList[i].Length != fileFormat.yDataList[0].Length)
                {
                    ErrorString = "Y datas is different";
                    return(null);
                }
            }

            //如果提供了组分名称,必须提供相应的组分浓度数据
            if (compNames != null)
            {
                if (compDatas == null || compNames.Length * fileFormat.yDataList.Count != compDatas.Length)
                {
                    ErrorString = "Invalid component datas";
                    return(null);
                }
            }

            if (fileTimes != null && fileTimes.Length != fileFormat.yDataList.Count)
            {
                ErrorString = "Invalid file times";
                return(null);
            }

            //获取保存文件的大小
            int saveSize = GetFileSaveSize(fileFormat.dataInfoList.Count, fileFormat.fileInfo.dataCount);

            if (saveSize == 0)
            {
                return(null);
            }
            byte[] retDatas = new byte[saveSize];

            //主结构
            byte[] mainHeader = CreateMainHeader(fileFormat.dataInfoList.Count, fileFormat.fileInfo.createTime, fileFormat.fileInfo.dataCount, fileFormat.dataInfo.firstX, fileFormat.dataInfo.lastX, compNames, fileFormat.fileInfo.fileMemo, fileFormat.fileInfo.instDescription, serialNo);
            if (mainHeader == null)
            {
                return(null);
            }
            Array.Copy(mainHeader, 0, retDatas, 0, mainHeader.Length);

            int copyOffset = mainHeader.Length;

            //创建样品序号
            string[] sampleNo = new string[fileFormat.yDataList.Count];
            for (int i = 0; i < fileFormat.yDataList.Count; i++)
            {
                sampleNo[i] = string.IsNullOrWhiteSpace(fileFormat.dataInfoList[i].dataTitle) ? i.ToString() : fileFormat.dataInfoList[i].dataTitle;
            }

            //逐条增加光谱数据
            for (int i = 0; i < fileFormat.yDataList.Count; i++)
            {
                //拷贝浓度数据
                double[] curCompData = null;
                if (compNames != null)
                {
                    curCompData = new double[compNames.Length];
                    Array.Copy(compDatas, i * compNames.Length, curCompData, 0, compNames.Length);
                }

                DateTime curtime  = fileTimes == null ? fileFormat.fileInfo.createTime : fileTimes[i];  //文件创建时间
                byte[]   fileData = CreateFileData(sampleNo[i], i, curtime, fileFormat.yDataList[i], curCompData);
                if (fileData == null)
                {
                    return(null);
                }

                Array.Copy(fileData, 0, retDatas, copyOffset, fileData.Length);

                copyOffset += fileData.Length;
            }

            //添加文件索引
            var indexData = CreateIndexData(sampleNo);

            if (indexData == null)
            {
                return(null);
            }
            Array.Copy(indexData, 0, retDatas, copyOffset, indexData.Length);

            return(retDatas);
        }
        /// <summary>
        /// 读取光谱文件
        /// </summary>
        public static bool ReadFile(byte[] fileData, FileFormat fileFormat)
        {
            fileFormat.dataInfoList    = null;
            fileFormat.acquisitionInfo = null;
            fileFormat.xDataList       = null;
            fileFormat.fileInfo        = null;
            fileFormat.yDataList       = null;

            MainHeader mainheader = GetMainHeader(fileData);

            if (mainheader.fileMark == UInt16.MaxValue)  //读取文件头错误
            {
                return(false);
            }

            //填充光谱文件信息
            fileFormat.fileInfo            = new FileFormat.FileInfo();
            fileFormat.fileInfo.createTime = CreateFileDateTime(mainheader.fileTime);
            fileFormat.fileInfo.dataCount  = (int)mainheader.specCols;
            fileFormat.fileInfo.fileMemo   = CommonMethod.CovertByteArrayToString(mainheader.tile, Encoding.Default);
            //仪器描述 仪器名称-序列号
            fileFormat.fileInfo.instDescription = CommonMethod.CovertByteArrayToString(mainheader.instrument, Encoding.Default) + instSerialSeprator +
                                                  CommonMethod.CovertByteArrayToString(mainheader.serialNo, Encoding.Default);
            fileFormat.fileInfo.modifyFlag = 0;
            fileFormat.fileInfo.resolution = 16;                        //固定值

            fileFormat.fileInfo.specType = FileFormat.SPECTYPE.SPCNIR;  //固定值
            fileFormat.fileInfo.xType    = FileFormat.XAXISTYPE.XNMETR; //mainheader.xType = 1
            fileFormat.fileInfo.zType    = FileFormat.ZAXISTYPE.XMSEC;  //固定值
            fileFormat.fileInfo.fzinc    = 0.5f;                        //固定值
            fileFormat.fileInfo.fspare   = new float[8];                //固定值

            //读取X轴数据(肯定是均匀的X轴)
            fileFormat.xDataList = new List <double[]>();
            double[] tempx = new double[mainheader.specCols];
            int      index = 0;

            for (int i = 0; i < mainheader.rangeCount; i++)  //每个光谱段读取
            {
                for (int j = 0; j < mainheader.rangeCols[i]; j++)
                {
                    tempx[index] = mainheader.rangeFirstX[i] + j * mainheader.rangeStepX[i];
                    index++;
                }
            }
            fileFormat.xDataList.Add(tempx);

            //获取Y数据以及格式信息
            fileFormat.dataInfoList = new List <FileFormat.DataInfo>();
            fileFormat.yDataList    = new List <double[]>();

            for (int i = 0; i < mainheader.fileCount; i++)
            {
                FileHeader fileHeader = GetFileHeader(fileData, i);
                if (fileHeader.position == UInt16.MaxValue)
                {
                    return(false);
                }

                //读取Y轴数据
                double[] ydata = GetSpectrumData(fileData, i);
                if (ydata == null || ydata.Length == 0)
                {
                    return(false);
                }
                fileFormat.yDataList.Add(ydata);

                //Y轴数据格式
                FileFormat.DataInfo info = new FileFormat.DataInfo();
                info.dataTitle = CommonMethod.CovertByteArrayToString(fileHeader.sampleNo, Encoding.Default);
                info.dataType  = FileFormat.YAXISTYPE.YABSRB;
                info.firstX    = mainheader.rangeFirstX[0];
                info.lastX     = mainheader.rangeLastX[mainheader.rangeCount - 1];
                info.maxYValue = ydata.Max();
                info.minYValue = ydata.Min();
                fileFormat.dataInfoList.Add(info);
            }

            //读取光谱参数
            fileFormat.acquisitionInfo          = new FileFormat.AcquisitionInfo();
            fileFormat.acquisitionInfo.GAIN     = 0;
            fileFormat.acquisitionInfo.HIGHPASS = 0;
            fileFormat.acquisitionInfo.LOWPASS  = 0;
            fileFormat.acquisitionInfo.LWN      = 0;
            fileFormat.acquisitionInfo.SPEED    = null;
            fileFormat.acquisitionInfo.SCANS    = 0;
            fileFormat.acquisitionInfo.SCANSBG  = 0;
            fileFormat.acquisitionInfo.IRMODE   = FileFormat.enumIRMODE.NearIR;

            return(true);
        }
        /// <summary>
        /// 创建光谱文件块
        /// </summary>
        /// <param name="fileCount">文件数量</param>
        /// <param name="fileTime">光谱创建时间</param>
        /// <param name="specCols">光谱数据点数量</param>
        /// <param name="firstX">起始波数</param>
        /// <param name="lastX">结束波数</param>
        /// <param name="compNames">组分名称</param>
        /// <param name="title">文件描述</param>
        /// <param name="instrument">仪器名称</param>
        /// <param name="serialNo">仪器序列号</param>
        /// <returns></returns>
        private static byte[] CreateMainHeader(int fileCount, DateTime fileTime, int specCols, double firstX, double lastX, string[] compNames, string title, string instrument, string serialNo)
        {
            try
            {
                IntPtr retptr   = IntPtr.Zero;
                int    datasize = 0;

                //创建主结构
                UInt32 time      = CreateFileDateTime(fileTime);
                int    compCount = compNames == null ? 0 : compNames.Length; //组分数量

                if (CommonMethod.Is64BitVersion())
                {
                    retptr = FossCreateMainHeader64((UInt32)fileCount, (UInt32)specCols, time, firstX, lastX, compCount, ref datasize);
                }
                else
                {
                    retptr = FossCreateMainHeader32((UInt32)fileCount, (UInt32)specCols, time, firstX, lastX, compCount, ref datasize);
                }

                byte[] headerDatas = CommonMethod.CopyDataArrayFromIntptrAndFree <byte>(ref retptr, datasize);
                if (headerDatas == null)
                {
                    ErrorString = CommonMethod.ErrorString;
                    return(null);
                }

                //文件描述
                if (!string.IsNullOrWhiteSpace(title))
                {
                    if (AddMainHeaderInfo(headerDatas, MAIN_TITLE, Encoding.Default.GetBytes(title)) == false)
                    {
                        return(null);
                    }
                }

                //仪器描述
                if (!string.IsNullOrWhiteSpace(instrument))
                {
                    if (AddMainHeaderInfo(headerDatas, MAIN_INSTRUMENT, Encoding.Default.GetBytes(instrument)) == false)
                    {
                        return(null);
                    }
                }

                //仪器序列号
                if (!string.IsNullOrWhiteSpace(serialNo))
                {
                    if (AddMainHeaderInfo(headerDatas, MAIN_SERIALNO, Encoding.Default.GetBytes(serialNo)) == false)
                    {
                        return(null);
                    }
                }

                //组分信息
                if (compNames != null && compNames.Length != 0)
                {
                    byte[] compBytes = new byte[compNames.Length * CompNameLength];   //一个组分长度为CompNameLength
                    for (int i = 0; i < compNames.Length; i++)
                    {
                        var namebytes = StringToBytesArray(compNames[i], CompNameLength);
                        Array.Copy(namebytes, 0, compBytes, i * CompNameLength, CompNameLength);
                    }
                    if (AddMainHeaderInfo(headerDatas, MAIN_COMPONENT, compBytes) == false)
                    {
                        return(null);
                    }
                }

                return(headerDatas);
            }
            catch (Exception ex)
            {
                ErrorString = ex.Message;
                return(null);
            }
        }
        public static byte[] SaveFile(FileFormat fileFormat)
        {
            if (fileFormat.xDatas == null || fileFormat.xDatas.Length == 0)
            {
                return(null);
            }
            if (fileFormat.yDataList == null || fileFormat.yDataList.Count == 0)
            {
                return(null);
            }
            if (fileFormat.dataInfoList == null || fileFormat.dataInfoList.Count != fileFormat.yDataList.Count)
            {
                return(null);
            }
            if (fileFormat.xDataList.Count == 1)     //统一的X轴
            {
                //检查是否所有Y轴数据点数量与X数量相同
                foreach (var item in fileFormat.yDataList)
                {
                    if (item.Length != fileFormat.xDatas.Length)
                    {
                        return(null);
                    }
                }
            }
            else
            {
                //检查是否所有Y轴数据点数量与对应的X轴数据数量相同
                if (fileFormat.xDataList.Count != fileFormat.yDataList.Count)
                {
                    return(null);
                }
                for (int i = 0; i < fileFormat.xDataList.Count; i++)
                {
                    if (fileFormat.xDataList[i].Length != fileFormat.yDataList[i].Length)
                    {
                        return(null);
                    }
                }
            }

            //子文件类型
            byte[] subTypes = (from p in fileFormat.dataInfoList select(byte) p.dataType).ToArray();

            //文件主结构
            SPCHeader header = new SPCHeader();

            header.ftflgs  = 0;
            header.fexper  = (byte)fileFormat.fileInfo.specType;
            header.fexp    = 0x80;  //float
            header.fnpts   = (uint)fileFormat.xDatas.Length;
            header.ffirst  = fileFormat.dataInfo.firstX;
            header.flast   = fileFormat.dataInfo.lastX;
            header.fnsub   = (uint)fileFormat.dataInfoList.Count;
            header.fxtype  = (byte)fileFormat.fileInfo.xType;
            header.fytype  = (byte)fileFormat.dataInfo.dataType;
            header.fdate   = CommonMethod.DataTimeToDWord(DateTime.Now);
            header.fres    = fileFormat.fileInfo.resolution.ToString(); // CommonMethod.ConvertStringToFixedByte(fileFormat.fileInfo.resolution.ToString(), header.fres, 9);
            header.fsource = fileFormat.fileInfo.instDescription;       //CommonMethod.ConvertStringToFixedByte(fileFormat.fileInfo.instDescription, header.fsource, 9);
            header.fcmnt   = fileFormat.fileInfo.fileMemo;              //CommonMethod.ConvertStringToFixedByte(fileFormat.fileInfo.fileMemo, header.fcmnt, 130);
            header.fmods   = fileFormat.fileInfo.modifyFlag;
            //CommonMethod.CopyDataArrayToFixedPtr<float>(header.fspare, 8, fileFormat.fileInfo.fspare);
            header.fspare = fileFormat.fileInfo.fspare;

            //设置Z轴格式
            if (fileFormat.dataInfoList.Count < 2)
            {
                header.fztype = 0;
                header.fzinc  = 0;
            }
            else
            {
                header.fztype = fileFormat.fileInfo.fzinc == 0 ? (byte)FileFormat.ZAXISTYPE.XMSEC : (byte)fileFormat.fileInfo.zType; //如果没有设置fzinc,缺省设置为单位=秒
                header.fzinc  = fileFormat.fileInfo.fzinc == 0 ? 0.5f : fileFormat.fileInfo.fzinc;                                   //如果没有设置fzinc,缺省设置为0.5s
            }
            string logstr = ToSPCLogData(fileFormat.acquisitionInfo);

            byte[] logText = Encoding.ASCII.GetBytes(logstr);

            int[] dataPoints = null;    //xData的数据点数

            //XDatas转换到float
            float[] floatxdatas = null;

            //判断是否为均匀的X
            double stepx = (fileFormat.dataInfo.lastX - fileFormat.dataInfo.firstX) / (fileFormat.fileInfo.dataCount - 1);

            stepx += stepx / 1000;  //稍微放大一点
            stepx  = Math.Abs(stepx);

            bool isevenlyx = true;

            if (fileFormat.xDataList.Count > 1)     //超过1个X数据,一定是多X文件
            {
                isevenlyx  = false;
                dataPoints = (from p in fileFormat.xDataList select p.Length).ToArray();    //记录每个X轴的数据点数
            }
            else
            {
                for (int i = 1; i < fileFormat.xDatas.Length; i++)
                {
                    if (Math.Abs(fileFormat.xDatas[i] - fileFormat.xDatas[i - 1]) > stepx)
                    {
                        isevenlyx = false;
                        break;
                    }
                }
            }

            //将所有X轴转换为float,合并在一个Array
            int index = 0;

            if (!isevenlyx && fileFormat.xDatas != null)
            {
                int xcount = (from p in fileFormat.xDataList select p.Length).Sum();     //所有X轴的数据数量
                floatxdatas = new float[xcount];
                foreach (var xdatas in fileFormat.xDataList)
                {
                    for (int i = 0; i < xdatas.Length; i++)
                    {
                        floatxdatas[index++] = (float)xdatas[i];
                    }
                }
            }

            //所有YDatas转换到float,合并在一个Array
            int ycount = (from p in fileFormat.yDataList select p.Length).Sum();     //所有X轴的数据数量

            float[] floatydatas = new float[ycount];
            index = 0;
            foreach (var ydatas in fileFormat.yDataList)
            {
                for (int i = 0; i < ydatas.Length; i++)
                {
                    floatydatas[index++] = (float)ydatas[i];
                }
            }

            return(CreateCommonXFile(header, subTypes, dataPoints, floatxdatas, floatydatas, logText, fileFormat.additionalData));
        }
        public static bool ReadFile(byte[] fileData, int fileSize, FileFormat fileFormat)
        {
            fileFormat.dataInfoList    = null;
            fileFormat.acquisitionInfo = null;
            fileFormat.xDataList       = null;
            fileFormat.fileInfo        = null;
            fileFormat.yDataList       = null;

            SPCHeader mainheader = GetMainHeader(fileData, fileSize);

            if (mainheader.fnpts == int.MaxValue)  //读取文件头错误
            {
                return(false);
            }

            //填充光谱文件信息
            fileFormat.fileInfo                 = new FileFormat.FileInfo();
            fileFormat.fileInfo.createTime      = CommonMethod.DWordToDateTime(mainheader.fdate);
            fileFormat.fileInfo.dataCount       = (int)mainheader.fnpts;
            fileFormat.fileInfo.fileMemo        = mainheader.fcmnt;   //CommonMethod.ConvertFixedByteToString(mainheader.fcmnt, 130);
            fileFormat.fileInfo.instDescription = mainheader.fsource; //CommonMethod.ConvertFixedByteToString(mainheader.fsource, 9);
            fileFormat.fileInfo.modifyFlag      = mainheader.fmods;
            double tempres = 0;                                       //resolution
            string resstr  = mainheader.fres;                         // CommonMethod.ConvertFixedByteToString(mainheader.fres, 9);

            fileFormat.fileInfo.resolution = double.TryParse(resstr, out tempres) == true ? tempres : 0;

            fileFormat.fileInfo.specType = mainheader.fexper == 0 ? FileFormat.SPECTYPE.SPCNIR : (FileFormat.SPECTYPE)mainheader.fexper;
            fileFormat.fileInfo.xType    = (FileFormat.XAXISTYPE)mainheader.fxtype;
            fileFormat.fileInfo.zType    = (FileFormat.ZAXISTYPE)mainheader.fztype;
            fileFormat.fileInfo.fzinc    = mainheader.fzinc;
            fileFormat.fileInfo.fspare   = mainheader.fspare; //CommonMethod.CopyDataArrayFromFixedPtr<float>(mainheader.fspare, 8);

            //读取X轴数据
            if ((mainheader.ftflgs & (byte)Ftflgs.TXYXYS) == 0)     //统一的X轴
            {
                fileFormat.xDataList = new List <double[]>();
                double[] tempx = GetXData(fileData, fileSize, 0);
                fileFormat.xDataList.Add(tempx);
            }
            else    //多个X轴
            {
                fileFormat.xDataList = new List <double[]>();
                for (int i = 0; i < mainheader.fnsub; i++)
                {
                    double[] tempx = GetXData(fileData, fileSize, i);
                    fileFormat.xDataList.Add(tempx);
                }
            }

            //获取Y数据以及格式信息
            fileFormat.dataInfoList = new List <FileFormat.DataInfo>();
            fileFormat.yDataList    = new List <double[]>();
            for (int i = 0; i < mainheader.fnsub; i++)
            {
                SPCSubHeader subheader = GetSubHeader(fileData, fileSize, i);
                if (subheader.subnpts == int.MaxValue)      //读取结构错误
                {
                    return(false);
                }

                //读取Y轴数据
                double[] ydata = GetYData(fileData, fileSize, i);
                if (ydata == null || ydata.Length == 0)
                {
                    return(false);
                }

                //Y轴数据格式
                FileFormat.DataInfo info = new FileFormat.DataInfo();
                if (subheader.subscan == 0)      //用这个属性来记录子数据的类型(吸收谱,干涉谱等等)
                {
                    info.dataType = mainheader.fytype == 0 ? FileFormat.YAXISTYPE.YABSRB : (FileFormat.YAXISTYPE)mainheader.fytype;
                }
                else
                {
                    info.dataType = (FileFormat.YAXISTYPE)subheader.subscan;
                }
                info.firstX    = mainheader.ffirst;
                info.lastX     = mainheader.flast;
                info.maxYValue = ydata.Max();
                info.minYValue = ydata.Min();

                fileFormat.dataInfoList.Add(info);
                fileFormat.yDataList.Add(ydata);
            }

            //读取光谱参数
            string parastr = GetLogText(fileData, fileSize);

            if (parastr != null)
            {
                fileFormat.acquisitionInfo = FromSPCLogData(parastr);
            }
            if (fileFormat.acquisitionInfo == null)
            {
                fileFormat.acquisitionInfo = new FileFormat.AcquisitionInfo();
            }

            return(true);
        }