/// <summary>
        /// 创建MATLAB文件头
        /// </summary>
        /// <param name="description">文件描述</param>
        /// <returns>返回BYTE[]</returns>
        public static byte[] CreateFileHeader(string description)
        {
            try
            {
                IntPtr retptr   = IntPtr.Zero;
                int    datasize = 0;
                description = "MATLAB 5.0 " + description;      //一定要加上MATLAB 5.0才能被再次读出来
                if (CommonMethod.Is64BitVersion())
                {
                    retptr = MATCreateFileHeader64(description, ref datasize);
                }
                else
                {
                    retptr = MATCreateFileHeader32(description, 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);
            }
        }
예제 #2
0
        /// <summary>
        /// 读取二进制的LOG数据
        /// </summary>
        public static byte[] GetLogBinary(byte[] fileData, int fileSize)
        {
            IntPtr retptr   = IntPtr.Zero;
            int    datasize = 0;

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

            return(CommonMethod.CopyByteFromIntptrAndFree(ref retptr, datasize));
        }
예제 #3
0
        /// <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>
        /// 创建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);
            }
        }