Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        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);
        }