diff --git a/Dat2Bin.sln b/Dat2Bin.sln new file mode 100644 index 0000000..89c533a --- /dev/null +++ b/Dat2Bin.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30011.22 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dat2Bin", "Dat2Bin\Dat2Bin.csproj", "{E431FBFE-D292-45BB-BCD8-DEE8AE2D2392}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E431FBFE-D292-45BB-BCD8-DEE8AE2D2392}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E431FBFE-D292-45BB-BCD8-DEE8AE2D2392}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E431FBFE-D292-45BB-BCD8-DEE8AE2D2392}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E431FBFE-D292-45BB-BCD8-DEE8AE2D2392}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {48053491-F800-4F93-85E0-00D9177B2781} + EndGlobalSection +EndGlobal diff --git a/Dat2Bin/Dat2Bin.csproj b/Dat2Bin/Dat2Bin.csproj new file mode 100644 index 0000000..8fc0024 --- /dev/null +++ b/Dat2Bin/Dat2Bin.csproj @@ -0,0 +1,110 @@ + + + + + Debug + AnyCPU + {E431FBFE-D292-45BB-BCD8-DEE8AE2D2392} + WinExe + Dat2Bin + DatToolkit + v4.8 + 512 + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + true + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + true + + + Toolbox.ico + + + true + + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + + + + + + + + + + + + Form + + + Dat2BinForm.cs + + + + + + + + + Dat2BinForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/Dat2Bin/Dat2BinForm.Designer.cs b/Dat2Bin/Dat2BinForm.Designer.cs new file mode 100644 index 0000000..62d7136 --- /dev/null +++ b/Dat2Bin/Dat2BinForm.Designer.cs @@ -0,0 +1,469 @@ +namespace Dat2Bin +{ + partial class Dat2BinForm + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要修改 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Dat2BinForm)); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.buttonSplitDat = new System.Windows.Forms.Button(); + this.buttonReadStaNum2 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.cbUseBackGround = new System.Windows.Forms.CheckBox(); + this.pgbarPrecent = new System.Windows.Forms.ProgressBar(); + this.lblPrecent = new System.Windows.Forms.Label(); + this.buttonConvertBin = new System.Windows.Forms.Button(); + this.dtpEndTime = new System.Windows.Forms.DateTimePicker(); + this.dtpBeginTime = new System.Windows.Forms.DateTimePicker(); + this.label5 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.listBox1 = new System.Windows.Forms.ListBox(); + this.textBox_sps = new System.Windows.Forms.TextBox(); + this.listView1 = new System.Windows.Forms.ListView(); + this.textBoxSingleFileLength = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.buttonReadStaNum = new System.Windows.Forms.Button(); + this.buttonSelectData = new System.Windows.Forms.Button(); + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.tabPage1 = new System.Windows.Forms.TabPage(); + this.tabPage2 = new System.Windows.Forms.TabPage(); + this.textBoxConByFloat = new System.Windows.Forms.TextBox(); + this.button4 = new System.Windows.Forms.Button(); + this.textBoxFloat = new System.Windows.Forms.TextBox(); + this.cbBigEnd = new System.Windows.Forms.CheckBox(); + this.button3 = new System.Windows.Forms.Button(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.btnReadDatSingle = new System.Windows.Forms.Button(); + this.buttonSplitAsync = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + this.tabControl1.SuspendLayout(); + this.tabPage1.SuspendLayout(); + this.tabPage2.SuspendLayout(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.buttonSplitAsync); + this.groupBox1.Controls.Add(this.buttonSplitDat); + this.groupBox1.Controls.Add(this.buttonReadStaNum2); + this.groupBox1.Controls.Add(this.button2); + this.groupBox1.Controls.Add(this.button1); + this.groupBox1.Controls.Add(this.cbUseBackGround); + this.groupBox1.Controls.Add(this.pgbarPrecent); + this.groupBox1.Controls.Add(this.lblPrecent); + this.groupBox1.Controls.Add(this.buttonConvertBin); + this.groupBox1.Controls.Add(this.dtpEndTime); + this.groupBox1.Controls.Add(this.dtpBeginTime); + this.groupBox1.Controls.Add(this.label5); + this.groupBox1.Controls.Add(this.label4); + this.groupBox1.Controls.Add(this.listBox1); + this.groupBox1.Controls.Add(this.textBox_sps); + this.groupBox1.Controls.Add(this.listView1); + this.groupBox1.Controls.Add(this.textBoxSingleFileLength); + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Controls.Add(this.label3); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Controls.Add(this.buttonReadStaNum); + this.groupBox1.Controls.Add(this.buttonSelectData); + this.groupBox1.Location = new System.Drawing.Point(8, 6); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(1063, 375); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "groupBox1"; + // + // buttonSplitDat + // + this.buttonSplitDat.Location = new System.Drawing.Point(245, 20); + this.buttonSplitDat.Name = "buttonSplitDat"; + this.buttonSplitDat.Size = new System.Drawing.Size(97, 31); + this.buttonSplitDat.TabIndex = 19; + this.buttonSplitDat.Text = "同步分割"; + this.buttonSplitDat.UseVisualStyleBackColor = true; + this.buttonSplitDat.Click += new System.EventHandler(this.buttonSplitDat_Click); + // + // buttonReadStaNum2 + // + this.buttonReadStaNum2.Location = new System.Drawing.Point(244, 20); + this.buttonReadStaNum2.Name = "buttonReadStaNum2"; + this.buttonReadStaNum2.Size = new System.Drawing.Size(98, 32); + this.buttonReadStaNum2.TabIndex = 18; + this.buttonReadStaNum2.Text = "读取台站编号2"; + this.buttonReadStaNum2.UseVisualStyleBackColor = true; + this.buttonReadStaNum2.Visible = false; + this.buttonReadStaNum2.Click += new System.EventHandler(this.buttonReadStaNum2_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(941, 30); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(75, 23); + this.button2.TabIndex = 17; + this.button2.Text = "bin"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(851, 30); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 16; + this.button1.Text = "Dat"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // cbUseBackGround + // + this.cbUseBackGround.AutoSize = true; + this.cbUseBackGround.Location = new System.Drawing.Point(465, 29); + this.cbUseBackGround.Name = "cbUseBackGround"; + this.cbUseBackGround.Size = new System.Drawing.Size(72, 16); + this.cbUseBackGround.TabIndex = 15; + this.cbUseBackGround.Text = "后台进程"; + this.cbUseBackGround.UseVisualStyleBackColor = true; + this.cbUseBackGround.CheckedChanged += new System.EventHandler(this.cbUseBackGround_CheckedChanged); + // + // pgbarPrecent + // + this.pgbarPrecent.Location = new System.Drawing.Point(577, 27); + this.pgbarPrecent.Name = "pgbarPrecent"; + this.pgbarPrecent.Size = new System.Drawing.Size(153, 23); + this.pgbarPrecent.TabIndex = 14; + // + // lblPrecent + // + this.lblPrecent.AutoSize = true; + this.lblPrecent.Location = new System.Drawing.Point(750, 33); + this.lblPrecent.Name = "lblPrecent"; + this.lblPrecent.Size = new System.Drawing.Size(17, 12); + this.lblPrecent.TabIndex = 13; + this.lblPrecent.Text = "0%"; + // + // buttonConvertBin + // + this.buttonConvertBin.Location = new System.Drawing.Point(348, 20); + this.buttonConvertBin.Name = "buttonConvertBin"; + this.buttonConvertBin.Size = new System.Drawing.Size(97, 32); + this.buttonConvertBin.TabIndex = 12; + this.buttonConvertBin.Text = "转存Bin"; + this.buttonConvertBin.UseVisualStyleBackColor = true; + this.buttonConvertBin.Click += new System.EventHandler(this.buttonConvertBin_Click); + // + // dtpEndTime + // + this.dtpEndTime.CustomFormat = "yyyy-MM-dd HH:mm:ss"; + this.dtpEndTime.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.dtpEndTime.Location = new System.Drawing.Point(522, 66); + this.dtpEndTime.Name = "dtpEndTime"; + this.dtpEndTime.Size = new System.Drawing.Size(152, 21); + this.dtpEndTime.TabIndex = 11; + this.dtpEndTime.Value = new System.DateTime(2020, 10, 7, 13, 40, 0, 0); + // + // dtpBeginTime + // + this.dtpBeginTime.CustomFormat = "yyyy-MM-dd HH:mm:ss"; + this.dtpBeginTime.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.dtpBeginTime.Location = new System.Drawing.Point(281, 66); + this.dtpBeginTime.Name = "dtpBeginTime"; + this.dtpBeginTime.Size = new System.Drawing.Size(152, 21); + this.dtpBeginTime.TabIndex = 11; + this.dtpBeginTime.Value = new System.DateTime(2020, 10, 7, 10, 30, 0, 0); + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(463, 69); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(53, 12); + this.label5.TabIndex = 10; + this.label5.Text = "结束时间"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(222, 69); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(53, 12); + this.label4.TabIndex = 9; + this.label4.Text = "开始时间"; + // + // listBox1 + // + this.listBox1.FormattingEnabled = true; + this.listBox1.ItemHeight = 12; + this.listBox1.Location = new System.Drawing.Point(851, 93); + this.listBox1.Name = "listBox1"; + this.listBox1.Size = new System.Drawing.Size(206, 280); + this.listBox1.TabIndex = 6; + // + // textBox_sps + // + this.textBox_sps.Location = new System.Drawing.Point(747, 66); + this.textBox_sps.Name = "textBox_sps"; + this.textBox_sps.Size = new System.Drawing.Size(45, 21); + this.textBox_sps.TabIndex = 5; + this.textBox_sps.Text = "1000"; + this.textBox_sps.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // listView1 + // + this.listView1.HideSelection = false; + this.listView1.Location = new System.Drawing.Point(6, 93); + this.listView1.Name = "listView1"; + this.listView1.Size = new System.Drawing.Size(830, 276); + this.listView1.TabIndex = 4; + this.listView1.UseCompatibleStateImageBehavior = false; + // + // textBoxSingleFileLength + // + this.textBoxSingleFileLength.Location = new System.Drawing.Point(100, 66); + this.textBoxSingleFileLength.Name = "textBoxSingleFileLength"; + this.textBoxSingleFileLength.Size = new System.Drawing.Size(47, 21); + this.textBoxSingleFileLength.TabIndex = 3; + this.textBoxSingleFileLength.Text = "120"; + this.textBoxSingleFileLength.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(153, 69); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(29, 12); + this.label2.TabIndex = 2; + this.label2.Text = "分钟"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(694, 69); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(47, 12); + this.label3.TabIndex = 2; + this.label3.Text = "采样率:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(23, 69); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(71, 12); + this.label1.TabIndex = 2; + this.label1.Text = "单文件时长:"; + // + // buttonReadStaNum + // + this.buttonReadStaNum.Location = new System.Drawing.Point(142, 20); + this.buttonReadStaNum.Name = "buttonReadStaNum"; + this.buttonReadStaNum.Size = new System.Drawing.Size(96, 32); + this.buttonReadStaNum.TabIndex = 1; + this.buttonReadStaNum.Text = "读取台站编号"; + this.buttonReadStaNum.UseVisualStyleBackColor = true; + this.buttonReadStaNum.Visible = false; + this.buttonReadStaNum.Click += new System.EventHandler(this.buttonReadStaNum_Click); + // + // buttonSelectData + // + this.buttonSelectData.Location = new System.Drawing.Point(25, 20); + this.buttonSelectData.Name = "buttonSelectData"; + this.buttonSelectData.Size = new System.Drawing.Size(101, 32); + this.buttonSelectData.TabIndex = 0; + this.buttonSelectData.Text = "打开Dat数据"; + this.buttonSelectData.UseVisualStyleBackColor = true; + this.buttonSelectData.Click += new System.EventHandler(this.buttonSelectData_Click); + // + // tabControl1 + // + this.tabControl1.Controls.Add(this.tabPage1); + this.tabControl1.Controls.Add(this.tabPage2); + this.tabControl1.Location = new System.Drawing.Point(0, 0); + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + this.tabControl1.Size = new System.Drawing.Size(1103, 426); + this.tabControl1.TabIndex = 1; + // + // tabPage1 + // + this.tabPage1.Controls.Add(this.groupBox1); + this.tabPage1.Location = new System.Drawing.Point(4, 22); + this.tabPage1.Name = "tabPage1"; + this.tabPage1.Padding = new System.Windows.Forms.Padding(3); + this.tabPage1.Size = new System.Drawing.Size(1095, 400); + this.tabPage1.TabIndex = 0; + this.tabPage1.Text = "tabPage1"; + this.tabPage1.UseVisualStyleBackColor = true; + // + // tabPage2 + // + this.tabPage2.Controls.Add(this.textBoxConByFloat); + this.tabPage2.Controls.Add(this.button4); + this.tabPage2.Controls.Add(this.textBoxFloat); + this.tabPage2.Controls.Add(this.cbBigEnd); + this.tabPage2.Controls.Add(this.button3); + this.tabPage2.Controls.Add(this.textBox1); + this.tabPage2.Controls.Add(this.btnReadDatSingle); + this.tabPage2.Location = new System.Drawing.Point(4, 22); + this.tabPage2.Name = "tabPage2"; + this.tabPage2.Padding = new System.Windows.Forms.Padding(3); + this.tabPage2.Size = new System.Drawing.Size(1095, 400); + this.tabPage2.TabIndex = 1; + this.tabPage2.Text = "tabPage2"; + this.tabPage2.UseVisualStyleBackColor = true; + // + // textBoxConByFloat + // + this.textBoxConByFloat.Location = new System.Drawing.Point(8, 249); + this.textBoxConByFloat.Name = "textBoxConByFloat"; + this.textBoxConByFloat.Size = new System.Drawing.Size(165, 21); + this.textBoxConByFloat.TabIndex = 6; + // + // button4 + // + this.button4.Location = new System.Drawing.Point(8, 199); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(93, 32); + this.button4.TabIndex = 5; + this.button4.Text = "button4"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.button4_Click); + // + // textBoxFloat + // + this.textBoxFloat.Location = new System.Drawing.Point(8, 160); + this.textBoxFloat.Name = "textBoxFloat"; + this.textBoxFloat.Size = new System.Drawing.Size(165, 21); + this.textBoxFloat.TabIndex = 4; + // + // cbBigEnd + // + this.cbBigEnd.AutoSize = true; + this.cbBigEnd.Location = new System.Drawing.Point(122, 14); + this.cbBigEnd.Name = "cbBigEnd"; + this.cbBigEnd.Size = new System.Drawing.Size(60, 16); + this.cbBigEnd.TabIndex = 3; + this.cbBigEnd.Text = "BigEnd"; + this.cbBigEnd.UseVisualStyleBackColor = true; + // + // button3 + // + this.button3.Location = new System.Drawing.Point(8, 102); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(93, 31); + this.button3.TabIndex = 2; + this.button3.Text = "button3"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(8, 61); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(165, 21); + this.textBox1.TabIndex = 1; + this.textBox1.Text = "00000D34"; + // + // btnReadDatSingle + // + this.btnReadDatSingle.Location = new System.Drawing.Point(8, 6); + this.btnReadDatSingle.Name = "btnReadDatSingle"; + this.btnReadDatSingle.Size = new System.Drawing.Size(93, 30); + this.btnReadDatSingle.TabIndex = 0; + this.btnReadDatSingle.Text = "读取Dat"; + this.btnReadDatSingle.UseVisualStyleBackColor = true; + this.btnReadDatSingle.Click += new System.EventHandler(this.btnReadDatSingle_Click); + // + // buttonSplitAsync + // + this.buttonSplitAsync.Location = new System.Drawing.Point(142, 20); + this.buttonSplitAsync.Name = "buttonSplitAsync"; + this.buttonSplitAsync.Size = new System.Drawing.Size(96, 33); + this.buttonSplitAsync.TabIndex = 20; + this.buttonSplitAsync.Text = "异步分割"; + this.buttonSplitAsync.UseVisualStyleBackColor = true; + this.buttonSplitAsync.Click += new System.EventHandler(this.buttonSplitAsync_Click); + // + // Dat2BinForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1108, 430); + this.Controls.Add(this.tabControl1); + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.Name = "Dat2BinForm"; + this.Text = "Txgy.DatToolkit_20230319"; + this.Load += new System.EventHandler(this.Form1_Load); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.tabControl1.ResumeLayout(false); + this.tabPage1.ResumeLayout(false); + this.tabPage2.ResumeLayout(false); + this.tabPage2.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.TextBox textBoxSingleFileLength; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button buttonReadStaNum; + private System.Windows.Forms.Button buttonSelectData; + private System.Windows.Forms.ListView listView1; + private System.Windows.Forms.TextBox textBox_sps; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.DateTimePicker dtpBeginTime; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.ListBox listBox1; + private System.Windows.Forms.DateTimePicker dtpEndTime; + private System.Windows.Forms.Button buttonConvertBin; + private System.Windows.Forms.ProgressBar pgbarPrecent; + private System.Windows.Forms.Label lblPrecent; + private System.Windows.Forms.CheckBox cbUseBackGround; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.TabControl tabControl1; + private System.Windows.Forms.TabPage tabPage1; + private System.Windows.Forms.TabPage tabPage2; + private System.Windows.Forms.Button btnReadDatSingle; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.CheckBox cbBigEnd; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.TextBox textBoxFloat; + private System.Windows.Forms.TextBox textBoxConByFloat; + private System.Windows.Forms.Button buttonReadStaNum2; + private System.Windows.Forms.Button buttonSplitDat; + private System.Windows.Forms.Button buttonSplitAsync; + } +} + diff --git a/Dat2Bin/Dat2BinForm.cs b/Dat2Bin/Dat2BinForm.cs new file mode 100644 index 0000000..351abcd --- /dev/null +++ b/Dat2Bin/Dat2BinForm.cs @@ -0,0 +1,1416 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Microsoft.Win32; +using System.Threading; +using System.Reflection.Emit; +using System.Collections.ObjectModel; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.ProgressBar; +using System.Diagnostics; +using System.IO.MemoryMappedFiles; + +namespace Dat2Bin +{ + public partial class Dat2BinForm : Form + { + int erro = 5; + int headSize = 2048; + float sps_pers = 1000.0f;//每秒采样点个数 1k 32k 16k + int chNum = 1;//通道数 + int databits = 4;//24位 3字节 + DateTime beginTime, endTime; + DateTime systemTime; + int sysCnt = 0; + string saveBinPath = "\\bin"; + string saveDatPath = "\\splitdat"; + int binHeadSize = 96; + //原始数据文件链表 + public LinkList DataList = new LinkList(); + Dictionary pointStaNum = new Dictionary(); + bool useBackGround = false; + public BackgroundWorker bgwConvert; + public List StationList { get; set; } + public Dat2BinForm() + { + InitializeComponent(); + systemTime = new DateTime(2023, 5, 1); + InitControl(); + } + private void InitControl() + { + RegistryKey hklm = Registry.CurrentUser; //声明一个变量 + RegistryKey hksw = hklm.OpenSubKey(@"SOFTWARE\Microsoft", true); + //string sk = "Software\\Microsoft\\ms"; + RegistryKey hksm = hksw.OpenSubKey("ms", true); + //RegistryKey cn; + if (hksm == null) + { + hksw.CreateSubKey("ms"); + hksm = hksw.OpenSubKey("ms", true); + hksm.SetValue("cnt", "0"); + hksm.SetValue("cd", DateTime.Now.ToString()); + + } + sysCnt = int.Parse(hksm.GetValue("cnt").ToString()); + hksm.SetValue("cnt", (sysCnt + 1).ToString()); + systemTime = DateTime.Parse(hksm.GetValue("cd").ToString()); + //Console.WriteLine(systemTime.ToString()); + if (hklm != null) + { + hklm.Close(); + } + + if (hksw != null) + { + hksw.Close(); + + } + + if (hksm != null) + { + hksm.Close(); + } + + } + private void buttonSelectData_Click(object sender, EventArgs e) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Multiselect = true; + //saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif"; + ofd.Filter = "Dat数据(*.dat) |*.dat"; + ofd.Title = "Open an Data File"; + + if (ofd.ShowDialog() == DialogResult.OK) + { + //只读取Z分量数据 + //string[] fns = Directory.GetFiles(Path.GetDirectoryName(ofd.FileName), "*.dat"); + //string[] fnsZ = fns.Where(fn => fn.Contains("ch01")).ToArray(); + //savePath = Path.GetDirectoryName(ofd.FileName) + "\\bin"; + //if (!Directory.Exists(savePath)) + //{ + // Directory.CreateDirectory(savePath); + //} + //OpenDataFile(fnsZ); + //listView1.Items.Clear(); + //AddSourceDataFileToMyListView(); + + + //读取所有数据 + string[] fns = Directory.GetFiles(Path.GetDirectoryName(ofd.FileName), "*.dat"); + //string[] fnsZ = fns.Where(fn => fn.Contains("ch01")).ToArray(); + + saveBinPath = Path.GetDirectoryName(ofd.FileName) + "\\bin"; + if (!Directory.Exists(saveBinPath)) + { + Directory.CreateDirectory(saveBinPath); + } + saveDatPath = Path.GetDirectoryName(ofd.FileName) + "\\splitdat"; + if (!Directory.Exists(saveDatPath)) + { + Directory.CreateDirectory(saveDatPath); + } + OpenDataFile(fns); + listView1.Items.Clear(); + AddSourceDataFileToMyListView(); + } + } + + private void OpenDataFile(string[] FileNames) + { + //try + { + //清除原来的链表 + DataList.Clear(); + byte[] temp = new byte[headSize]; + bool isExist = false; + for (int i = 0; i < FileNames.Length; i++) + { + string fn = Path.GetFileName(FileNames[i]); + string channel = Path.GetFileNameWithoutExtension(fn).Substring(5, 4); + /*如果文件名已经存在则不添加*/ + for (int k = 1; k <= DataList.Length; k++) + { + if (DataList.GetnodeData(k).fileName == FileNames[i]) + { + isExist = true; + } + } + if (isExist) + { + isExist = false; + continue; + } + //以文件的全路对应的字符串和文件打开模式来初始化FileStream文件流实例 + FileStream OldDataFileStream = new FileStream(FileNames[i], FileMode.Open); + //以FileStream文件流来初始化BinaryReader文件阅读器 + BinaryReader OldDataReadLineSReader = new BinaryReader(OldDataFileStream); + if (OldDataFileStream.Length <= headSize) + { + + MessageBox.Show(fn + "数据文件大小不够"); + + } + else + { + OldDataReadLineSReader.Read(temp, 0, headSize); + // readLineSReader.Read() + + HEADInfo OldDataFileHead = (HEADInfo)BytesToStuct(temp, typeof(HEADInfo)); + OldDataFileHead.standby8 = channel; + if (OldDataFileHead.year < 2000) + { + OldDataFileHead.year += 2000; + } + DateTime fileStartTime = new DateTime(OldDataFileHead.year, OldDataFileHead.month, OldDataFileHead.day, + OldDataFileHead.hour, OldDataFileHead.minute, OldDataFileHead.sec); + + //UTC时间TO北京时间 + fileStartTime = fileStartTime.AddHours(8);//截取电流时候用 + + sps_pers = Convert.ToSingle(textBox_sps.Text); + //根据数据量计算和采样率计算采集时长 + //文件头 2个通道 每个数据4个字节 + long timesec = (OldDataFileStream.Length - headSize) / chNum / databits / (int)sps_pers; + DateTime fileEndTime = fileStartTime.AddSeconds(timesec); + // DateTime fileEndTime = fileStartTime.AddSeconds(timesec+1);//截取电流 + DataList.Add(FileNames[i], fn, fileStartTime, fileEndTime, OldDataFileHead); + } + OldDataReadLineSReader.Close(); + OldDataFileStream.Close(); + } + } + //catch (Exception ex) + //{ + // MessageBox.Show(ex.ToString()); + //} + } + public void AddSourceDataFileToMyListView() + { + if (DataList.Length <= 0) + { + return; + } + try + { + + ListViewItem[] boxitems = new ListViewItem[DataList.Length]; + for (int i = 0; i < DataList.Length; i++) + { + SiteParameter OldDateFiledata = DataList.GetnodeData(i + 1); + boxitems[i] = new ListViewItem(); + boxitems[i].Text = Convert.ToString(i + 1); + boxitems[i].SubItems.Add(OldDateFiledata.SafeFileName.ToString()); + boxitems[i].SubItems.Add(OldDateFiledata.fileStartTime.ToString("yyyy-MM-dd H:mm:ss", new CultureInfo("zh-CHS"))); + boxitems[i].SubItems.Add(OldDateFiledata.fileEndTime.ToString("yyyy-MM-dd H:mm:ss", new CultureInfo("zh-CHS"))); + } + DateTime maxStartTime = DataList.GetnodeData(1).fileStartTime; + DateTime minEndTime = DataList.GetnodeData(1).fileEndTime; + for (int i = 1; i < DataList.Length; i++) + { + if (DataList.GetnodeData(i).fileStartTime > maxStartTime) + { + maxStartTime = DataList.GetnodeData(i).fileStartTime; + } + if (DataList.GetnodeData(i).fileEndTime < minEndTime) + { + minEndTime = DataList.GetnodeData(i).fileEndTime; + } + } + dtpBeginTime.Value = maxStartTime; + dtpEndTime.Value = minEndTime; + listView1.Items.AddRange(boxitems); + } + catch (System.Exception ex) + { + Console.WriteLine(ex); + } + } + private void MyListView1Clear() + { + //清除原来的链表 + DataList.Clear(); + listView1.Items.Clear(); + } + public static byte[] StructToBytes(object structObj, int size)//对于TCP包需要直接指定大小 + { + //得到结构体的大小 + //int size = Marshal.SizeOf(structObj); + //创建byte数组 + byte[] bytes = new byte[size]; + //分配结构体大小的内存空间 + IntPtr structPtr = Marshal.AllocHGlobal(size); + //将结构体拷到分配好的内存空间 + Marshal.StructureToPtr(structObj, structPtr, false); + //从内存空间拷到byte数组 + Marshal.Copy(structPtr, bytes, 0, size); + //释放内存空间 + Marshal.FreeHGlobal(structPtr); + //返回byte数组 + return bytes; + } + public static object BytesToStuct(byte[] bytes, Type type) + { + //得到结构体的大小 + int size = Marshal.SizeOf(type); + //byte数组长度小于结构体的大小 + if (size > bytes.Length) + { + //返回空 + return null; + } + //分配结构体大小的内存空间 + IntPtr structPtr = Marshal.AllocHGlobal(size); + //将byte数组拷到分配好的内存空间 + Marshal.Copy(bytes, 0, structPtr, size); + + //将内存空间转换为目标结构体 + object obj = Marshal.PtrToStructure(structPtr, type); + //释放内存空间 + Marshal.FreeHGlobal(structPtr); + //返回结构体 + return obj; + } + + private void Form1_Load(object sender, EventArgs e) + { + //int temp1 = 0x05;//0B00000101 + //int temp2 = 0x09;//0B00001001 + //int checkBit3 = 0x04;//0B0000100 提取第三位 + //int checkBit8 = 0x08;//0B0000100 提取第四位 + //int result3 = temp1 & checkBit3; + //int result4 = temp2 & checkBit8; + //Console.WriteLine(result3); + //Console.WriteLine(result4); + cbUseBackGround.Checked = useBackGround; + this.Text = "DatToBin_20201015"; + SetMyListView1(); + } + private void SetMyListView1() + { + //double v = 3.5; + //double m = v % 1; + //Console.WriteLine(m.ToString()); + // Set the view to show details. + listView1.View = View.Details; + // Allow the user to edit item text. + listView1.LabelEdit = false; + // Allow the user to rearrange columns. + listView1.AllowColumnReorder = true; + // Display check boxes. + listView1.CheckBoxes = false; + // Select the item and subitems when selection is made. + listView1.FullRowSelect = true; + // Display grid lines. + listView1.GridLines = true; + int width = 200; + listView1.Columns.Add("编号", 50, HorizontalAlignment.Center); + listView1.Columns.Add("文件名称", 300, HorizontalAlignment.Center); + listView1.Columns.Add("开始采集时间", width, HorizontalAlignment.Center); + listView1.Columns.Add("结束采集时间", width, HorizontalAlignment.Center); + // listView1.Columns.Add("采样速率", 150, HorizontalAlignment.Center); + listView1.Visible = true; + listView1.Font = new System.Drawing.Font("Arial", 12); + + + } + + private void buttonReadStaNum_Click(object sender, EventArgs e) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Multiselect = true; + ofd.Filter = "台站编号(*.txt) |*.txt"; + ofd.Title = "Open a Text File"; + + if (ofd.ShowDialog() == DialogResult.OK) + { + pointStaNum = new Dictionary(); + StreamReader sr = new StreamReader(ofd.FileName, Encoding.Default); + while (sr.Peek() >= 0) + { + string[] strs = sr.ReadLine().Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); + pointStaNum.Add(int.Parse(strs[0]), int.Parse(strs[1])); + } + //listBox1.Items.AddRange(pointStaNum); + foreach (var item in pointStaNum) + { + listBox1.Items.Add(item.Key + "\t" + item.Value); + } + } + } + + private void buttonConvertBin_Click(object sender, EventArgs e) + { + if (useBackGround) + { + bgwConvert = new BackgroundWorker(); + bgwConvert.DoWork += BgwConvert_DoWork; + bgwConvert.ProgressChanged += BgwConvert_ProgressChanged; + bgwConvert.RunWorkerCompleted += BgwConvert_RunWorkerCompleted; + bgwConvert.WorkerReportsProgress = true; + bgwConvert.WorkerSupportsCancellation = true; + pgbarPrecent.Value = 0; + lblPrecent.Text = "0%"; + bgwConvert.RunWorkerAsync(); + } + else + { + DatToBinConvert(null, null); + + } + } + + private void BgwConvert_SplitDatRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + if (e.Cancelled) + { + MessageBox.Show("您取消了操作!"); + //pgbarPrecent.Value = 0; + //lblPrecent.Text = "0%"; + } + else if (e.Error != null) + { + MessageBox.Show("出现错误!"); + } + else + { + MessageBox.Show("完成"); + //pgbarPrecent.Value = 0; + //lblPrecent.Text = "0%"; + } + } + + private void BgwConvert_SplitDatProgressChanged(object sender, ProgressChangedEventArgs e) + { + pgbarPrecent.Value = e.ProgressPercentage; + lblPrecent.Text = (string)e.UserState + "%"; + } + + + private void BgwConvert_SplitDat(object sender, DoWorkEventArgs e) + { + SplitDatConvertAsync(sender, e); + } + public async void SplitDatConvertAsync(object sender, DoWorkEventArgs e) + { + beginTime = dtpBeginTime.Value; + endTime = dtpEndTime.Value; + ////单个文件时长 + //int singleFileLength = int.Parse(textBoxSingleFileLength.Text) * 60; + // 截取时长 + int splitLength = (int)(endTime - beginTime).TotalSeconds; + if (((DateTime.Now - systemTime).TotalDays < 30) && + ((DateTime.Now - systemTime).TotalDays >= 0) && + sysCnt < 90) + { + List nodeList = new List(); + //创建并启动计时器 + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + for (int dli = 0; dli < DataList.Length; dli++) + { + SiteParameter nodeData = this.DataList.GetnodeData(dli + 1); + nodeList.Add(nodeData); + //await ProcessFilesAsync(nodeData, beginTime, splitLength); + // WriteDatFile(nodeData, beginTime, splitLength); + //Task task=WriteDatFileTask(nodeData, beginTime, splitLength); + //task.Start(); + //tasks.Add(task); + + //WriteDatFileAsync(nodeData, beginTime, splitLength); + //task.Start(); + } + + await ProcessFilesAsync(nodeList, beginTime, splitLength); + stopwatch.Stop(); + TimeSpan elapsedTime = stopwatch.Elapsed; + // 打印执行时间 + Console.WriteLine($"异步分割时长: {elapsedTime.TotalMilliseconds}ms"); + nodeList = null; + MessageBox.Show("转换完成"); + } + else + { + MessageBox.Show("数据格式错误!"); + } + } + public async Task WriteDatFileAsync(SiteParameter nodeData, DateTime startTime, int secs) + { + + if (secs <= 0) + { + throw new ArgumentException("Parameter secs must be a positive integer."); + } + + FileInfo fileInfo = new FileInfo(nodeData.fileName); + int count = secs * 4000; + if (fileInfo.Length >= (count + 2048)) + { + DateTime dt = startTime.AddHours(-8); + string fileName = BuildNewFileName(nodeData, dt); + try + { + using (FileStream input = new FileStream(nodeData.fileName, FileMode.Open)) + using (BinaryReader reader = new BinaryReader(input)) + using (FileStream saveFileStream = new FileStream(saveDatPath + "\\" + fileName, FileMode.Create)) + using (BinaryWriter writeLineSReader = new BinaryWriter(saveFileStream)) + { + WriteFileHeader(writeLineSReader, nodeData, dt); + await WriteFileDataAsync(input, reader, writeLineSReader, startTime, nodeData, count); + } + } + catch (Exception ex) + { + // Log the exception or show an error message to the user. + Console.WriteLine($"Error: {ex.Message}"); + } + } + } + + private void WriteFileHeader(BinaryWriter writer, SiteParameter nodeData, DateTime dt) + { + nodeData.fileHead.year = (short)dt.Year; + nodeData.fileHead.month = (short)dt.Month; + nodeData.fileHead.day = (short)dt.Day; + nodeData.fileHead.hour = (short)(dt.Hour); + nodeData.fileHead.minute = (short)dt.Minute; + nodeData.fileHead.sec = (byte)dt.Second; + + byte[] hs = StructToBytes(nodeData.fileHead, this.headSize); + writer.Write(hs); + } + + private async Task WriteFileDataAsync(FileStream input, BinaryReader reader, BinaryWriter writer, DateTime startTime, SiteParameter nodeData, int count) + { + byte[] buffer = new byte[count]; + int seekOff = (int)((startTime - nodeData.fileStartTime).TotalSeconds) * 4000; + input.Seek((long)this.headSize + seekOff, SeekOrigin.Begin); + reader.Read(buffer, 0, count); + await writer.BaseStream.WriteAsync(buffer, 0, count); + } + + public async Task ProcessFilesAsync(List nodeDataList, DateTime startTime, int secs) + { + List tasks = new List(); + + foreach (SiteParameter nodeData in nodeDataList) + { + Task task = WriteDatFileAsync(nodeData, startTime, secs); + tasks.Add(task); + } + + await Task.WhenAll(tasks); + } + public void WriteDatFile(SiteParameter nodeData, DateTime startTime, int secs) + { + if (secs <= 0) + { + throw new ArgumentException("Parameter secs must be a positive integer."); + } + + FileInfo fileInfo = new FileInfo(nodeData.fileName); + int count = secs * 4000; + if (fileInfo.Length >= (count + 2048)) + { + DateTime dt = startTime.AddHours(-8); + string fileName = BuildNewFileName(nodeData, dt); + try + { + using (FileStream input = new FileStream(nodeData.fileName, FileMode.Open)) + using (BinaryReader reader = new BinaryReader(input)) + using (FileStream saveFileStream = new FileStream(saveDatPath + "\\" + fileName, FileMode.Create)) + using (BinaryWriter writeLineSReader = new BinaryWriter(saveFileStream)) + { + WriteFileHeader(writeLineSReader, nodeData, dt); + WriteFileData(input, reader, writeLineSReader, startTime, nodeData, count); + } + } + catch (Exception ex) + { + // Log the exception or show an error message to the user. + Console.WriteLine($"Error: {ex.Message}"); + } + } + } + + private string BuildNewFileName(SiteParameter nodeData, DateTime dt) + { + return nodeData.SafeFileName.Substring(0, 10) + dt.Year.ToString("0000") + dt.Month.ToString("00") + + dt.Day.ToString("00") + "_" + dt.Hour.ToString("00") + dt.Minute.ToString("00") + dt.Second.ToString("00") + ".dat"; + } + + private void WriteFileData(FileStream input, BinaryReader reader, BinaryWriter writer, DateTime startTime, SiteParameter nodeData, int count) + { + byte[] buffer = new byte[count]; + int seekOff = (int)((startTime - nodeData.fileStartTime).TotalSeconds) * 4000; + input.Seek((long)this.headSize + seekOff, SeekOrigin.Begin); + reader.Read(buffer, 0, count); + writer.Write(buffer); + } + + public Task WriteDatFileTask(SiteParameter nodeData, DateTime startTime, int secs) + { + FileInfo fileInfo = new FileInfo(nodeData.fileName); + int count = secs * 4000; + Task task = null; + if (fileInfo.Length >= (count + 2048)) + { + task = new Task(() => + { + DateTime dt = startTime.AddHours(-8); + string fileName = nodeData.SafeFileName.Substring(0, 10) + dt.Year.ToString("0000") + dt.Month.ToString("00") + + dt.Day.ToString("00") + "_" + dt.Hour.ToString("00") + dt.Minute.ToString("00") + dt.Second.ToString("00") + ".dat"; + + FileStream input = new FileStream(nodeData.fileName, FileMode.Open); + BinaryReader reader = new BinaryReader(input); + FileStream SaveFileStream = new FileStream(saveDatPath + "\\" + fileName, FileMode.Create); + BinaryWriter WriteLineSReader = new BinaryWriter(SaveFileStream); + nodeData.fileHead.year = (short)dt.Year; + nodeData.fileHead.month = (short)dt.Month; + nodeData.fileHead.day = (short)dt.Day; + nodeData.fileHead.hour = (short)(dt.Hour); + nodeData.fileHead.minute = (short)dt.Minute; + nodeData.fileHead.sec = (byte)dt.Second; + + byte[] hs = StructToBytes(nodeData.fileHead, this.headSize); + + WriteLineSReader.Write(hs); + + byte[] buffer = new byte[count]; + int seekOff = (int)((startTime - nodeData.fileStartTime).TotalSeconds) * 4000; + input.Seek((long)this.headSize + seekOff, SeekOrigin.Begin); + reader.Read(buffer, 0, count); + WriteLineSReader.Write(buffer); + input.Close(); + reader.Close(); + SaveFileStream.Close(); + WriteLineSReader.Close(); + }); + } + return task; + } + public void WriteDatFileTay(SiteParameter nodeData, DateTime startTime, int secs) + { + FileInfo fileInfo = new FileInfo(nodeData.fileName); + int count = secs * 4000; + if (fileInfo.Length >= (count + 2048)) + { + DateTime dt = startTime.AddHours(-8); + string fileName = nodeData.SafeFileName.Substring(0, 10) + dt.Year.ToString("0000") + dt.Month.ToString("00") + + dt.Day.ToString("00") + "_" + dt.Hour.ToString("00") + dt.Minute.ToString("00") + dt.Second.ToString("00") + ".dat"; + FileStream input = new FileStream(nodeData.fileName, FileMode.Open); + BinaryReader reader = new BinaryReader(input); + FileStream SaveFileStream = new FileStream(saveDatPath + "\\" + fileName, FileMode.Create); + BinaryWriter WriteLineSReader = new BinaryWriter(SaveFileStream); + nodeData.fileHead.year = (short)dt.Year; + nodeData.fileHead.month = (short)dt.Month; + nodeData.fileHead.day = (short)dt.Day; + nodeData.fileHead.hour = (short)(dt.Hour); + nodeData.fileHead.minute = (short)dt.Minute; + nodeData.fileHead.sec = (byte)dt.Second; + + byte[] hs = StructToBytes(nodeData.fileHead, this.headSize); + WriteLineSReader.Write(hs); + byte[] buffer = new byte[count]; + int seekOff = (int)((startTime - nodeData.fileStartTime).TotalSeconds) * 4000; + input.Seek((long)this.headSize + seekOff, SeekOrigin.Begin); + reader.Read(buffer, 0, count); + WriteLineSReader.Write(buffer); + input.Close(); + reader.Close(); + SaveFileStream.Close(); + WriteLineSReader.Close(); + } + } + public void WriteDatFileTestSpan(SiteParameter nodeData, DateTime startTime, int secs) + { + FileInfo fileInfo = new FileInfo(nodeData.fileName); + int count = secs * 4000; + if (fileInfo.Length >= (count + 2048)) + { + DateTime dt = startTime.AddHours(-8); + string fileName = nodeData.SafeFileName.Substring(0, 10) + dt.Year.ToString("0000") + dt.Month.ToString("00") + + dt.Day.ToString("00") + "_" + dt.Hour.ToString("00") + dt.Minute.ToString("00") + dt.Second.ToString("00") + ".dat"; + + FileStream input = new FileStream(nodeData.fileName, FileMode.Open); + BinaryReader reader = new BinaryReader(input); + FileStream SaveFileStream = new FileStream(saveDatPath + "\\" + fileName, FileMode.Create); + BinaryWriter WriteLineSReader = new BinaryWriter(SaveFileStream); + nodeData.fileHead.year = (short)dt.Year; + nodeData.fileHead.month = (short)dt.Month; + nodeData.fileHead.day = (short)dt.Day; + nodeData.fileHead.hour = (short)(dt.Hour); + nodeData.fileHead.minute = (short)dt.Minute; + nodeData.fileHead.sec = (byte)dt.Second; + + byte[] hs = StructToBytes(nodeData.fileHead, this.headSize); + //Stopwatch sw = Stopwatch.StartNew(); + + WriteLineSReader.Write(hs); + //sw.Stop(); + //Console.WriteLine($"写入头的时长:{sw.ElapsedMilliseconds}"); + /*sw.Start()*/; + byte[] buffer = new byte[count]; + + int seekOff = (int)((startTime - nodeData.fileStartTime).TotalSeconds) * 4000; + + input.Seek((long)this.headSize + seekOff, SeekOrigin.Begin); + reader.Read(buffer, 0, count); + //sw.Stop(); + //Console.WriteLine($"读取数据的时长:{sw.ElapsedMilliseconds}"); + //sw.Start(); + WriteLineSReader.Write(buffer); + //sw.Stop(); + //Console.WriteLine($"运行时长:{sw.ElapsedMilliseconds}ms"); + input.Close(); + reader.Close(); + SaveFileStream.Close(); + WriteLineSReader.Close(); + } + } + public async Task WriteDatFileAsyncIO(SiteParameter nodeData, DateTime startTime, int secs) + { + FileInfo fileInfo = new FileInfo(nodeData.fileName); + long count = secs * 4000L; + if (fileInfo.Length >= (count + 2048)) + { + DateTime dt = startTime.AddHours(-8); + string fileName = nodeData.SafeFileName.Substring(0, 10) + dt.Year.ToString("0000") + dt.Month.ToString("00") + + dt.Day.ToString("00") + "_" + dt.Hour.ToString("00") + dt.Minute.ToString("00") + dt.Second.ToString("00") + ".dat"; + + using (FileStream inputFileStream = new FileStream(nodeData.fileName, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true)) + { + using (FileStream SaveFileStream = new FileStream(saveDatPath + "\\" + fileName, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true)) + { + // 写入文件头 + nodeData.fileHead.year = (short)dt.Year; + nodeData.fileHead.month = (short)dt.Month; + nodeData.fileHead.day = (short)dt.Day; + nodeData.fileHead.hour = (short)(dt.Hour); + nodeData.fileHead.minute = (short)dt.Minute; + nodeData.fileHead.sec = (byte)dt.Second; + + byte[] hs = StructToBytes(nodeData.fileHead, this.headSize); + await SaveFileStream.WriteAsync(hs, 0, hs.Length); + + // 读取数据并写入新文件 + int seekOff = (int)((startTime - nodeData.fileStartTime).TotalSeconds) * 4000; + long offset = this.headSize + seekOff * sizeof(float); + long bytesToRead = count * sizeof(float); + long totalBytesRead = 0; + int bufferSize = 1024 * 1024; // 1MB buffer + byte[] buffer = new byte[bufferSize]; + + while (bytesToRead > 0) + { + int bytesRead = (int)Math.Min(bufferSize, bytesToRead); + + int numBytesRead = await inputFileStream.ReadAsync(buffer, 0, bytesRead); + if (numBytesRead == 0) + { + break; + } + + totalBytesRead += numBytesRead; + bytesToRead -= numBytesRead; + + await SaveFileStream.WriteAsync(buffer, 0, numBytesRead); + } + } + } + } + } + + public void WriteDatFileAsync2(SiteParameter nodeData, DateTime startTime, int secs) + { + FileInfo fileInfo = new FileInfo(nodeData.fileName); + long count = secs * 4000L; + if (fileInfo.Length >= (count + 2048)) + { + DateTime dt = startTime.AddHours(-8); + string fileName = nodeData.SafeFileName.Substring(0, 10) + dt.Year.ToString("0000") + dt.Month.ToString("00") + + dt.Day.ToString("00") + "_" + dt.Hour.ToString("00") + dt.Minute.ToString("00") + dt.Second.ToString("00") + ".dat"; + + using (var mmf = MemoryMappedFile.CreateFromFile(nodeData.fileName, FileMode.Open)) + { + using (var accessor = mmf.CreateViewAccessor()) + { + using (FileStream SaveFileStream = new FileStream(saveDatPath + "\\" + fileName, FileMode.Create)) + { + using (BinaryWriter writer = new BinaryWriter(SaveFileStream)) + { + // 写入文件头 + nodeData.fileHead.year = (short)dt.Year; + nodeData.fileHead.month = (short)dt.Month; + nodeData.fileHead.day = (short)dt.Day; + nodeData.fileHead.hour = (short)(dt.Hour); + nodeData.fileHead.minute = (short)dt.Minute; + nodeData.fileHead.sec = (byte)dt.Second; + + byte[] hs = StructToBytes(nodeData.fileHead, this.headSize); + writer.Write(hs); + + // 读取数据并写入新文件 + int seekOff = (int)((startTime - nodeData.fileStartTime).TotalSeconds) * 4000; + long offset = this.headSize + seekOff * sizeof(float); + long bytesToRead = count * sizeof(float); + long totalBytesRead = 0; + int bufferSize = 1024 * 1024; // 1MB buffer + byte[] buffer = new byte[bufferSize]; + + while (bytesToRead > 0) + { + int bytesRead = (int)Math.Min(bufferSize, bytesToRead); + accessor.ReadArray(offset + totalBytesRead, buffer, 0, bytesRead); + + totalBytesRead += bytesRead; + bytesToRead -= bytesRead; + + writer.Write(buffer, 0, bytesRead); + } + } + } + } + } + } + } + + private void BgwConvert_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + if (e.Cancelled) + { + MessageBox.Show("您取消了操作!"); + //pgbarPrecent.Value = 0; + //lblPrecent.Text = "0%"; + } + else if (e.Error != null) + { + MessageBox.Show("出现错误!"); + } + else + { + MessageBox.Show("完成"); + //pgbarPrecent.Value = 0; + //lblPrecent.Text = "0%"; + } + } + + private void BgwConvert_ProgressChanged(object sender, ProgressChangedEventArgs e) + { + pgbarPrecent.Value = e.ProgressPercentage; + lblPrecent.Text = (string)e.UserState + "%"; + } + + private void BgwConvert_DoWork(object sender, DoWorkEventArgs e) + { + DatToBinConvert(sender, e); + MessageBox.Show("转换完成"); + } + + public void DatToBinConvert(object sender, DoWorkEventArgs e) + { + beginTime = dtpBeginTime.Value; + endTime = dtpEndTime.Value; + DateTime CurTime; + //读取数据时长 + int totalSec = 0; + //当前时差 + int timeDiff = 0; + //单个文件时长 + int singleFileLength = int.Parse(textBoxSingleFileLength.Text) * 60; + for (int dli = 0; dli < DataList.Length; dli++) + { + SiteParameter nodeData = this.DataList.GetnodeData(dli + 1); + CurTime = beginTime; + while (nodeData.fileEndTime >= CurTime && CurTime >= nodeData.fileStartTime) + { + if (CurTime > endTime) + { + break; + } + else + { + //计算文件结束时间与当前时间的时差 + timeDiff = (int)(endTime - CurTime).TotalSeconds; + //如果当前时差小于单个文件时长,当前时间增加当前时差,否则当前时间增加单个文件时长 + if (timeDiff <= 0) + { + break; + } + else if (timeDiff < singleFileLength) + { + totalSec = timeDiff; + } + else + { + totalSec = singleFileLength; + } + //读取Dat数据,生成Bin文件 + WriteBinData(nodeData, CurTime, totalSec); + } + if (useBackGround) + { + float precent = (dli + 1f) / ((float)DataList.Length) * 100f; + bgwConvert.ReportProgress((int)precent, Math.Round(precent, 2).ToString()); + } + CurTime = CurTime.AddSeconds(totalSec); + } + + } + } + + private void cbUseBackGround_CheckedChanged(object sender, EventArgs e) + { + useBackGround = cbUseBackGround.Checked; + } + public void ReadByte(string fn) + { + FileStream input = new FileStream(fn, FileMode.Open); + BinaryReader reader = new BinaryReader(input); + input.Seek((long)this.headSize, SeekOrigin.Begin); + byte[] buffer = new byte[4]; + reader.Read(buffer, 0, 4); + int intData = BitConverter.ToInt32(buffer, 0); + //byte[] b2 = Int32ToBytes(intData); + + float f = (float)(intData * 0.000000000011641532f); + byte[] b2 = FloatToBytes(f, false); + Console.WriteLine("[0]:{0}\t[1]:{1}\t[2]:{2}\t[3]:{3}", b2[0], b2[1], b2[2], b2[3]); + //Console.WriteLine("[0]:{0}\t[1]:{1}\t[2]:{2}\t[3]:{3}\tint:{4}\tfloat:{5}", buffer[0], buffer[1], buffer[2], buffer[3],intData, f); + input.Close(); + reader.Close(); + } + public void WriteBinData(SiteParameter nodeData, DateTime curTime, int totalSeconds) + { + HEADInfo info = (HEADInfo)BytesToStuct(StructToBytes(nodeData.fileHead, this.headSize), typeof(HEADInfo)); + int staNum = int.Parse(info.Nst.ToString().Substring(2, 2)); + int pointNum = staNum; + if (pointStaNum.Count > 0) + { + var psnw = pointStaNum.Where(psn => psn.Value == staNum); + if (psnw == null) + { + return; + } + if (psnw.Count() == 0) + { + return; + } + //var psnr = psnw.First(); + //if (psnr.) + //{ + // return; + //} + pointNum = psnw.First().Key; + } + string fileName = "N" + String.Format("{0:d3}", pointNum) + "_" + + curTime.Year.ToString("0000") + "-" + curTime.Month.ToString("00") + "-" + curTime.Day.ToString("00") + + "~" + curTime.Hour.ToString("00") + "_" + String.Format("{0:d3}", 1) + ".bin"; + + FileStream input = new FileStream(nodeData.fileName, FileMode.Open); + BinaryReader reader = new BinaryReader(input); + FileStream SaveFileStream = new FileStream(saveBinPath + "\\" + fileName, FileMode.Create); + BinaryWriter WriteLineSReader = new BinaryWriter(SaveFileStream); + + int count = (this.chNum * this.databits) * ((int)this.sps_pers); + byte[] buffer = new byte[count]; + char[] chars = new char[this.binHeadSize]; + byte[] buffer3 = new byte[count]; + int seekOff = (int)((curTime - nodeData.fileStartTime).TotalSeconds) * 4000; + + input.Seek((long)this.headSize + seekOff, SeekOrigin.Begin); + for (int j = 0; j < totalSeconds; j++) + { + reader.Read(buffer, 0, count); + for (int k = 0; k < count; k += 4) + { + //buffer3[k] = buffer[k + 3]; + //buffer3[k + 1] = buffer[k + 2]; + //buffer3[k + 2] = buffer[k + 1]; + //buffer3[k + 3] = buffer[k ]; + //if (buffer[k + 3] == 0) + //{ + // buffer3[k + 1] = 0xFF; + //} + //else + //{ + // buffer3[k + 1] = buffer[k + 3]; + //} + + //buffer3[k + 2] = buffer[k + 2]; + //buffer3[k + 3] = buffer[k + 1]; + //buffer3[k] = buffer[k]; + buffer3[k] = 0xFF; + if (buffer[k + 3] == 0) + { + buffer3[k + 1] = 0xFF; + } + else + { + buffer3[k + 1] = buffer[k + 3]; + } + + buffer3[k + 2] = buffer[k + 2]; + buffer3[k + 3] = buffer[k + 1]; + } + DateTime time = curTime.AddSeconds((double)j); + string[] strArray4 = new string[] { "$GPRMC,", time.Hour.ToString("00"), + time.Minute.ToString("00"), time.Second.ToString("00"), ".00,A,", + info.channel[0].Y.ToString("0000.00000"), ",N,", + info.channel[0].X.ToString("00000.00000"), + ",E,0.002,,", time.Day.ToString("00"), time.Month.ToString("00"), + (time.Year - 0x7d0).ToString("00"), ",,,A*7\r\n" }; + string str6 = string.Concat(strArray4); + string[] strArray5 = new string[0x10]; + strArray5[0] = "$$175B"; + strArray5[1] = time.Year.ToString("0000"); + strArray5[2] = "-"; + strArray5[3] = time.Month.ToString("00"); + strArray5[4] = "-"; + strArray5[5] = time.Day.ToString("00"); + strArray5[6] = " "; + strArray5[7] = time.Hour.ToString("00"); + strArray5[8] = ":"; + strArray5[9] = time.Minute.ToString("00"); + strArray5[10] = ":"; + strArray5[11] = time.Second.ToString("00"); + strArray5[12] = " "; + strArray5[13] = (pointNum).ToString("00"); + strArray5[14] = " "; + strArray5[15] = str6; + chars = string.Concat(strArray5).ToCharArray(); + WriteLineSReader.Write(chars); + WriteLineSReader.Write(buffer3); + } + input.Close(); + reader.Close(); + SaveFileStream.Close(); + WriteLineSReader.Close(); + } + + private void button1_Click(object sender, EventArgs e) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Multiselect = true; + + ofd.Filter = "Dat数据(*.dat) |*.dat"; + ofd.Title = "Open an Data File"; + + if (ofd.ShowDialog() == DialogResult.OK) + { + ReadByte(ofd.FileName); + } + } + + private void button2_Click(object sender, EventArgs e) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Multiselect = true; + + ofd.Filter = "Dat数据(*.bin) |*.bin"; + ofd.Title = "Open an Data File"; + + if (ofd.ShowDialog() == DialogResult.OK) + { + FileStream input = new FileStream(ofd.FileName, FileMode.Open); + BinaryReader reader = new BinaryReader(input); + input.Seek(96, SeekOrigin.Begin); + byte[] buffer = new byte[4]; + reader.Read(buffer, 0, 4); + int intData = ByteToInt32(buffer); + //string utmp = String.Join("", (BitConverter.ToString(buffer, 0)).Split('-')); + //Int64 intData = (GetBaseNum(utmp)); + float ff = -5.516708f; + int dd = (int)(ff / 0.0000000000582f); + byte[] b2 = Int32ToBytes(dd); + float fd = (float)(intData * 2.5f / 4294967296f); + + //Console.WriteLine("byte:{0}\tint:{1}\tint:{2}", buffer, intData,fd); + Console.WriteLine("[0]:{0}\t[1]:{1}\t[2]:{2}\t[3]:{3}", b2[0], b2[1], b2[2], b2[3]); + //Console.WriteLine("[0]:{0}\t[1]:{1}\t[2]:{2}\t[3]:{3}\tint:{4}\tfloat:{5}", buffer[0], buffer[1], buffer[2], buffer[3], intData, fd); + input.Close(); + reader.Close(); + + } + } + public float BytesToFloat(byte[] tempbyte, bool isBigEnd) + { + float tempInput = 0f; + char[] tempchar = new char[8]; + MemoryStream membuff = new MemoryStream(4); + BinaryWriter bin2mem = new BinaryWriter(membuff); + byte[] tb = new byte[4]; + BinaryReader mem2float = new BinaryReader(membuff); + if (isBigEnd) + { + tb[3] = tempbyte[0]; + tb[2] = tempbyte[1]; + tb[1] = tempbyte[2]; + tb[0] = tempbyte[3]; + + } + else + { + tb = tempbyte; + } + + bin2mem.Write(tb, 0, 4); + membuff.Position = 0; + tempInput = mem2float.ReadSingle(); + return tempInput; + } + public byte[] FloatToBytes(float value, bool isBigEnd) + { + byte[] tempbyte = new byte[4]; + byte[] rtnBytes = new byte[4]; + MemoryStream membuff = new MemoryStream(4); + BinaryWriter bin2mem = new BinaryWriter(membuff); + membuff.Position = 0; + bin2mem.Write(value); + tempbyte = membuff.ToArray(); + if (isBigEnd) + { + for (int i = 0; i < tempbyte.Length; i++) + { + rtnBytes[i] = tempbyte[3 - i]; + } + } + else + { + rtnBytes = tempbyte; + } + + return rtnBytes; + } + private int ByteToInt32(Byte[] arrByte) + { + //按两个字节一个整数解析,前一字节当做整数低位,后一字节当做整数高位,调用系统函数转化 + Byte[] tmpBytes = new Byte[4] { arrByte[3], arrByte[2], arrByte[1], arrByte[0] }; + return BitConverter.ToInt32(tmpBytes, 0); + } + public byte[] Int32ToBytes(int indata) + { + byte[] destByteArr = new byte[4]; + destByteArr[0] = Convert.ToByte((indata & 0x000000FF)); + destByteArr[1] = Convert.ToByte((indata & 0x0000FF00) >> 8); + destByteArr[2] = Convert.ToByte((indata & 0x00FF0000) >> 16); + destByteArr[3] = Convert.ToByte((indata & 0xFF000000) >> 24); + return destByteArr; + } + int GetBaseNum(String sComplement) + { + Int64 iTmp = Convert.ToInt32(sComplement, 16); + + if (iTmp >= 0x80000000) + { + iTmp = ~(iTmp - 1); + //MessageBox.Show("1"); + //iTmp = 0x1000000000 - iTmp; + } + + return (int)iTmp; + } + //byte数组变为 float数值 + private static float ToFloat(byte[] data) + { + //undefined + unsafe + { + //undefined + float a = 0.0F; + byte i; + byte[] x = data; + void* pf; + fixed (byte* px = x) + { + //undefined + pf = &a; + for (i = 0; i < data.Length; i++) + { + //undefined + *((byte*)pf + i) = *(px + i); + } + } + return a; + } + } + + private void btnReadDatSingle_Click(object sender, EventArgs e) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Multiselect = true; + //saveFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif"; + ofd.Filter = "Dat数据(*.dat) |*.dat"; + ofd.Title = "Open an Data File"; + + if (ofd.ShowDialog() == DialogResult.OK) + { + string[] fns = Directory.GetFiles(Path.GetDirectoryName(ofd.FileName), "*.dat"); + string[] fnsZ = fns.Where(fn => fn.Contains("ch01")).ToArray(); + saveBinPath = Path.GetDirectoryName(ofd.FileName) + "\\bin"; + if (!Directory.Exists(saveBinPath)) + { + Directory.CreateDirectory(saveBinPath); + } + OpenDataFile(fnsZ); + listView1.Items.Clear(); + AddSourceDataFileToMyListView(); + } + } + + private void button3_Click(object sender, EventArgs e) + { + string str = textBox1.Text; + int si = GetBaseNum(str); + Console.WriteLine(si); + double dv = si * 5.82E-10; + + textBoxFloat.Text = dv.ToString(); + int li = (int)(dv / 5.82E-10); + Console.WriteLine(li); + byte[] bs = BitConverter.GetBytes(li); + string strx2 = ""; + foreach (var item in bs) + { + strx2 += item.ToString("X2"); + Console.WriteLine(item.ToString("X2")); + } + textBoxConByFloat.Text = strx2; + ////string[] strs = str.Split(new char[] { ' '}); + //byte[] bytes = Convert.FromBase64String(str); + ////byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(str); + ////string str2= BitConverter.ToString(byteArray); + //string str2 = Convert.ToBase64String(bytes); + ////int intData = BitConverter.ToInt32(bytes, 0); + ////byte[] b2 = Int32ToBytes(intData); + + //// float f = (float)(intData * 0.000000000011641532f); + //float ff = BytesToFloat(bytes, cbBigEnd.Checked); + //textBoxFloat.Text = ff.ToString(); + //Console.WriteLine(ff.ToString()); + ////Console.WriteLine(str2); + ////foreach (var item in byteArray) + ////{ + //// Console.WriteLine(item); + ////} + } + + private void button4_Click(object sender, EventArgs e) + { + byte[] bs = FloatToBytes(float.Parse(textBoxFloat.Text), cbBigEnd.Checked); + string str = ""; + for (int i = 0; i < bs.Length; i++) + { + str += bs[i].ToString("X2"); + } + textBoxConByFloat.Text = str; + + } + + private void buttonReadStaNum2_Click(object sender, EventArgs e) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Multiselect = true; + ofd.Filter = "台站编号(*.spj) |*.spj"; + ofd.Title = "Open a Text File"; + if (ofd.ShowDialog() == DialogResult.OK) + { + pointStaNum = new Dictionary(); + string[] rows = File.OpenText(ofd.FileName).ReadToEnd().Trim().Split('\n'); + File.OpenText(ofd.FileName).Close(); + int rowNum = 0; + while (rowNum < rows.Length) + { + //台站信息 + if (rows[rowNum].Contains("[台站信息]")) + { + int subNum = rowNum + 2; + while (!rows[subNum].Contains("[井信息]")) + { + string[] cols = rows[subNum].Split('\t'); + pointStaNum.Add(int.Parse(cols[0]), int.Parse(cols[1])); + subNum++; + } + rowNum = subNum; + continue; + } + rowNum++; + } + + //listBox1.Items.AddRange(pointStaNum); + listBox1.Items.Clear(); + foreach (var item in pointStaNum) + { + listBox1.Items.Add(item.Key + "\t" + item.Value); + } + } + } + + private void buttonSplitDat_Click(object sender, EventArgs e) + { + SplitDatConvert(null,null); + } + public void SplitDatConvert(object sender, DoWorkEventArgs e) + { + beginTime = dtpBeginTime.Value; + endTime = dtpEndTime.Value; + ////单个文件时长 + //int singleFileLength = int.Parse(textBoxSingleFileLength.Text) * 60; + // 截取时长 + int splitLength = (int)(endTime - beginTime).TotalSeconds; + if (((DateTime.Now - systemTime).TotalDays < 30) && + ((DateTime.Now - systemTime).TotalDays >= 0) && + sysCnt < 90) + { + List nodeList = new List(); + //创建并启动计时器 + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + for (int dli = 0; dli < DataList.Length; dli++) + { + SiteParameter nodeData = this.DataList.GetnodeData(dli + 1); + nodeList.Add(nodeData); + //await ProcessFilesAsync(nodeData, beginTime, splitLength); + WriteDatFile(nodeData, beginTime, splitLength); + //Task task=WriteDatFileTask(nodeData, beginTime, splitLength); + //task.Start(); + //tasks.Add(task); + + //WriteDatFileAsync(nodeData, beginTime, splitLength); + //task.Start(); + } + + // await ProcessFilesAsync(nodeList, beginTime, splitLength); + stopwatch.Stop(); + TimeSpan elapsedTime = stopwatch.Elapsed; + // 打印执行时间 + Console.WriteLine($"同步分割时长: {elapsedTime.TotalMilliseconds}ms"); + MessageBox.Show("转换完成"); + } + else + { + MessageBox.Show("数据格式错误!"); + } + } + private void buttonSplitAsync_Click(object sender, EventArgs e) + { + if (useBackGround) + { + bgwConvert = new BackgroundWorker(); + bgwConvert.DoWork += BgwConvert_SplitDat; + bgwConvert.ProgressChanged += BgwConvert_SplitDatProgressChanged; + bgwConvert.RunWorkerCompleted += BgwConvert_SplitDatRunWorkerCompleted; ; + bgwConvert.WorkerReportsProgress = true; + bgwConvert.WorkerSupportsCancellation = true; + pgbarPrecent.Value = 0; + lblPrecent.Text = "0%"; + bgwConvert.RunWorkerAsync(); + } + else + { + SplitDatConvertAsync(null, null); + } + + } + + public void WriteBinDataBak20201212(SiteParameter nodeData, DateTime curTime, int totalSeconds) + { + HEADInfo info = (HEADInfo)BytesToStuct(StructToBytes(nodeData.fileHead, this.headSize), typeof(HEADInfo)); + int staNum = int.Parse(info.Nst.ToString().Substring(2, 2)); + int pointNum = staNum; + if (pointStaNum.Count > 0) + { + pointNum = (pointStaNum.First(psn => psn.Value == staNum).Key); + } + string fileName = "N" + String.Format("{0:d3}", pointNum) + "_" + + curTime.Year.ToString("0000") + "-" + curTime.Month.ToString("00") + "-" + curTime.Day.ToString("00") + + "~" + curTime.Hour.ToString("00") + "_" + String.Format("{0:d3}", 1) + ".bin"; + + FileStream input = new FileStream(nodeData.fileName, FileMode.Open); + BinaryReader reader = new BinaryReader(input); + FileStream SaveFileStream = new FileStream(saveBinPath + "\\" + fileName, FileMode.Create); + BinaryWriter WriteLineSReader = new BinaryWriter(SaveFileStream); + + int count = (this.chNum * this.databits) * ((int)this.sps_pers); + byte[] buffer = new byte[count]; + char[] chars = new char[this.binHeadSize]; + byte[] buffer3 = new byte[count]; + int seekOff = (int)((curTime - nodeData.fileStartTime).TotalSeconds) * 4000; + + input.Seek((long)this.headSize + seekOff, SeekOrigin.Begin); + for (int j = 0; j < totalSeconds; j++) + { + reader.Read(buffer, 0, count); + for (int k = 0; k < count; k += 4) + { + //buffer3[k] = buffer[k]; + buffer3[k] = 0xFF; + if (buffer[k + 3] == 0) + { + buffer3[k + 1] = 0xFF; + } + else + { + buffer3[k + 1] = buffer[k + 3]; + } + + buffer3[k + 2] = buffer[k + 2]; + buffer3[k + 3] = buffer[k + 1]; + } + DateTime time = curTime.AddSeconds((double)j); + string[] strArray4 = new string[] { "$GPRMC,", time.Hour.ToString("00"), + time.Minute.ToString("00"), time.Second.ToString("00"), ".00,A,", + info.channel[0].Y.ToString("0000.00000"), ",N,", + info.channel[0].X.ToString("00000.00000"), + ",E,0.002,,", time.Day.ToString("00"), time.Month.ToString("00"), + (time.Year - 0x7d0).ToString("00"), ",,,A*7\r\n" }; + string str6 = string.Concat(strArray4); + string[] strArray5 = new string[0x10]; + strArray5[0] = "$$175B"; + strArray5[1] = time.Year.ToString("0000"); + strArray5[2] = "-"; + strArray5[3] = time.Month.ToString("00"); + strArray5[4] = "-"; + strArray5[5] = time.Day.ToString("00"); + strArray5[6] = " "; + strArray5[7] = time.Hour.ToString("00"); + strArray5[8] = ":"; + strArray5[9] = time.Minute.ToString("00"); + strArray5[10] = ":"; + strArray5[11] = time.Second.ToString("00"); + strArray5[12] = " "; + strArray5[13] = (pointNum).ToString("00"); + strArray5[14] = " "; + strArray5[15] = str6; + chars = string.Concat(strArray5).ToCharArray(); + WriteLineSReader.Write(chars); + WriteLineSReader.Write(buffer3); + } + input.Close(); + reader.Close(); + SaveFileStream.Close(); + WriteLineSReader.Close(); + } + } + public class StationModel + { + public string Name { get; set; } + public int ID { get; set; } + public double X { get; set; } + public double Y { get; set; } + /// + /// 海拔 + /// + public double Z { get; set; } + public double Size { get; set; } + public Color Color { get; set; } = Color.Red; + } +} diff --git a/Dat2Bin/Dat2BinForm.resx b/Dat2Bin/Dat2BinForm.resx new file mode 100644 index 0000000..36e27a6 --- /dev/null +++ b/Dat2Bin/Dat2BinForm.resx @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + + AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAABAAAMMOAADDDgAAAAAAAAAA + AAATGyEHExshbRMbId0TGyH6Exsh+xMbIfsTGyH7Exsh+xMbIfsTGyH7Exsh+xMbIe8TGyFeExshABMb + IQAAAAAAAAAAABMbIQATGyEAExshZxMbIfYTGyH/Exsh/xMbIf8TGyH/Exsh/xMbIf8TGyH/Exsh/xMb + IeITGyFwExshBxMbIW8TGyHzExsh/xMbIf4TGyH9Exsh/RMbIf0TGyH9Exsh/RMbIf0TGyH+Exsh/xMb + IZcTGyEAExshAAAAAAAAAAAAExshABIaKQATGyGdExsh/xMbIf4TGyH9Exsh/RMbIf0TGyH9Exsh/RMb + If0TGyH+Exsh/xMbIfMTGyFuExsh4hMbIf8TGyG6ExshWxMbIVYTGyFWExshVhMbIVYTGyFWExshVxMb + IcITGyH/ExshmxMbIQATGyEAAAAAAAAAAAATGyEAFBwiARMbIaITGyH/ExshvRMbIVYTGyFWExshVhMb + IVYTGyFWExshVhMbIVsTGyG+Exsh/xMbId4TGyH/Exsh/BMbIVUTGyEAExshABMbIQATGyEAExshABMb + IQATGyEAExshnxMbIf8TGyGeCBAQABMbIQAAAAAAAAAAABMbIQATGyIBExshpBMbIf8TGyGYExshABMb + IQATGyEAExshABMbIQATGyEAExshABMbIVwTGyH+Exsh+hMbIf8TGyH7ExshTxMbIQATGyEAAQEBAAAA + AAAAAAAAExshABcdJgATGyGdExsh/xMbIaEUHCEBExshAAAAAAAAAAAAExshABMbIQITGyGnExsh/xMb + IZYTGyAAExshAAAAAAAAAAAAAQMEABMbIQATGyEAExshVhMbIf0TGyH7Exsh/xMbIfsTGyFQExshAAAA + AAAAAAAAAAAAAAAAAAATGyEAExshABMbIZoTGyH/ExshpBMbIgETGyEAAAAAAAAAAAATGyEAExshAxMb + IaoTGyH/ExshkxMbIQATGyEAAAAAAAAAAAAAAAAAAQMEABMbIQATGyFWExsh/RMbIfsTGyH/Exsh+xMb + IVATGyEAAAAAAAAAAAAAAAAAAAAAABMbIQATGyAAExshlxMbIf8TGyGnExshAhMbIQAAAAAAAAAAABMb + IQATGyEEExshrRMbIf8TGyGQExshABMbIQAAAAAAAAAAAAAAAAAAAAAAExshABMbIVYTGyH9Exsh+xMb + If8TGyH7ExshUBMbIQAAAAAAAAAAAAAAAAAAAAAAExshABMbIQATGyGUExsh/xMbIaoTGyEDExshAAAA + AAAAAAAAExshABMbIQQTGyGwExsh/xMbIY0TGyEAExshAAAAAAAAAAAAAAAAAAAAAAATGyEAExshVhMb + If0TGyH7Exsh/xMbIfsTGyFQExshAAAAAAAAAAAAAAAAABMbIQATGyEAExshABMbIZYTGyH/ExshrhMb + IQQTGyEAAAAAAAAAAAATGyEAExshBRMbIbMTGyH/ExshjhMbIQATGyEAExshAAAAAAAAAAAAAAAAABMb + IQATGyFWExsh/RMbIfsTGyH/Exsh+xMbIVATGyEAAAAAAAAAAAATGyEAExshABMbIQATGyE6Exsh3RMb + If8TGyGnExshAhMbIQAAAAAAAAAAABMbIQATGyEDExshqxMbIf8TGyHXExshMxMbIQATGyEADSkfAAAA + AAAAAAAAExshABMbIVYTGyH9Exsh+xMbIf8TGyH7ExshUBMbIQAAAAAAAAAAABMbIQATGyEAExshHhMb + IckTGyH/Exsh4RMbIUMTGyEAERUYAEOy/wBDsv8AERYZABMbIQATGyFBExsh3xMbIf8TGyHCExshGhMb + IQATGyEAAAAAAAAAAAATGyEAExshVhMbIf0TGyH7Exsh/xMbIfsTGyFQExshAAAAAAALGSIAExshABMb + IQMTGyGRExsh/xMbIe0TGyFRIEVeAEKu+QBDsv8AQ7L/AEOy/wBDsv8AQq75AB9AVwATGyFOExsh7BMb + If8TGyGIExshARMbIQAUGyEAAAAAABMbIQATGyFWExsh/RMbIfsTGyH/Exsh+xMbIVATGyEAAAAAABMb + IQATGyEAExshNhMbIesTGyH/ExshgD6j6ABEtv8QQ7L/W0Oy/21Dsv9sQ7L/bEOy/21Dsv9aRLb/DziO + yQATGyF/Exsh/xMbIecTGyEwExshABMbIQAAAAAAExshABMbIVYTGyH9Exsh+xMbIf8TGyH7ExshUBMb + IQAAAAAAExshABMbIQATGyGIExsh/xMbIdMTGyEbM4C1AEOy/11Dsv//Q7L//0Oy//9Dsv//Q7L//0Oy + //5Dsv9YM3+0ABMbIRwTGyHUExsh/xMbIYETGyEAExshAAAAAAATGyEAExshVhMbIf0TGyH7Exsh/xMb + IfsTGyFQExshAAAAAAATGyEAExshDRMbIcUTGyH/ExshiBMbIQBCsPsAQ7L/NEOy/7xDsv/OQ7L/zUOy + /81Dsv/OQ7L/ukOy/zFCr/oAExshABMbIYsTGyH/ExshvxMbIQsTGyEAAAAAABMbIQATGyFWExsh/RMb + IfsTGyH/Exsh+xMbIVATGyEAAAAAABMbIQATGyEhExsh4hMbIf0TGyFTExshAP///wA8m90ARbn/CkW3 + /xBFt/8QRbf/EEW3/xBFuf8KPaDkABUhLAATGyEAExshWBMbIf8TGyHdExshHRMbIQAAAAAAExshABMb + IVYTGyH9Exsh+xMbIf8TGyH7ExshUBMbIQAAAAAAExshABMbISsTGyHqExsh9xMbIUETGyEAEhkfAB4+ + UwAODAsHDQcECA0HBAgNBwQIDQcECA4MCwcYKzgAExkfABMbIQATGyFGExsh+hMbIecTGyEmExshAAAA + AAATGyEAExshVxMbIf4TGyH8Exsh/xMbIfsTGyFQExshAAAAAAATGyEAExshJBMbIeUTGyH8ExshThMb + IQABADIAExshXxMbIbwTGyG9ExshvRMbIb0TGyG9ExshuxMbIVsTGyEAExshABMbIVITGyH9Exsh4RMb + ISATGyEAAAAAABMbIQATGyE6Exsh4xMbIdETGyH/Exsh+xMbIVATGyEAAAAAABMbIQATGyERExshzBMb + If8TGyF9ExshABMbIQgTGyG9Exsh/xMbIf8TGyH/Exsh/xMbIf8TGyH/ExshuBMbIQYTGyEAExshgRMb + If8TGyHHExshDhMbIQAAAAAAExshABMbIQMTGyEtExshIhMbIf8TGyH7ExshUBMbIQAAAAAAExshABUe + JAATGyGVExsh/xMbIckTGyEUExshCBMbIb8TGyH/ExshvRMbIX4TGyF+ExshwRMbIf8TGyG6ExshBhMb + IRYTGyHMExsh/xMbIY8TGyEAExshAAAAAAATGyEAExshABMbIQATGyEAExsh/xMbIfsTGyFQExshAAAA + AAATGyEAExshABMbIUETGyHxExsh/hMbIXkTGyEJExshvhMbIf8TGyF6ExshABMbIQATGyGBExsh/xMb + IbkTGyEIExshexMbIf8TGyHvExshPBMbIQATGyEAAAAAAAAAAAAAAAAAAAAAAAAAAAATGyH/Exsh+xMb + IVATGyEAAAAAABIbIgATGyEAExshBRMbIZkTGyH/Exsh7xMbIW8TGyHDExsh/xMbIXwTGyEAExshABMb + IYMTGyH/ExshvxMbIW0TGyHvExsh/xMbIZQTGyEEExshABMbIgAAAAAAExshABMbIQATGyEAExshABMb + If8TGyH7ExshUBMbIQAAAAAAAAAAABMbIQATGyEAExshHhMbIcETGyH/Exsh9hMbIfUTGyH/ExshfBMb + IQATGyEAExshgxMbIf8TGyHzExsh9hMbIf8TGyG9ExshHBMbIQATGyEAAAAAAAAAAAATGyEAExshBRMb + IToTGyEsExsh/xMbIfsTGyFQExshAAAAAAAAAAAAEhshABMbIQATGyEAExshJxMbIbgTGyH/Exsh/xMb + If8TGyF9ExshABMbIQATGyGEExsh/xMbIf8TGyH/ExshtBMbISQTGyEAExshABMcIQAAAAAAAAAAABMb + IQATGyE+Exsh6xMbIdsTGyH/Exsh+xMbIVATGyEAAAAAAAAAAAAAAAAAExshABMbIQATGyEAExshFBMb + IXkTGyHYExsh7xMbIVoTGyEAExshABMbIWATGyHwExsh1hMbIXYTGyESExshABMbIQATGyEAAAAAAAAA + AAAAAAAAExshABMbIVcTGyH+Exsh/BMbIf8TGyH7ExshUBMbIQAAAAAAAAAAAAAAAAAAAAAAExshABMb + IQATGyEAExshABMbIR4TGyE1ExshCRMbIQATGyEAExshCRMbITUTGyEcExshABMbIQATGyEAExshAAAA + AAAAAAAAAAAAAAAAAAATGyEAExshVhMbIf0TGyH7Exsh/xMbIfsTGyFQExshAAAAAAAAAAAAAAAAAAAA + AAAAAAAAExshABMbIQATGyEAExshABMbIQATGyEAExshABMbIQATGyEAExshABMbIQATGyEAExshABMb + IQAAAAAAAAAAAAAAAAAAAAAAAAABABMbIQATGyFWExsh/RMbIfsTGyH/Exsh+xMbIU8TGyEAExohAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAATGyEAExshABMbIVYTGyH9Exsh+xMbIf8TGyH8ExshVBMb + IQATGyEAExshABMbIQATGyEAExshABMbIQATGyEAExshABMbIQATGyEAExshABMbIQATGyEAExshABMb + IQATGyEAExshABMbIQATGyEAExshABMbIQATGyEAExshABMbIQATGyEAExshWxMbIf4TGyH6Exsh4xMb + If8TGyG2ExshVBMbIU8TGyFQExshUBMbIVATGyFQExshUBMbIVATGyFQExshUBMbIVATGyFQExshUBMb + IVATGyFQExshUBMbIVATGyFQExshUBMbIVATGyFQExshUBMbIVATGyFQExshTxMbIVUTGyG6Exsh/xMb + Id4TGyFzExsh9BMbIf8TGyH8Exsh+xMbIfsTGyH7Exsh+xMbIfsTGyH7Exsh+xMbIfsTGyH7Exsh+xMb + IfsTGyH7Exsh+xMbIfsTGyH7Exsh+xMbIfsTGyH7Exsh+xMbIfsTGyH7Exsh+xMbIfsTGyH7Exsh/BMb + If8TGyHzExshbhMbIQkTGyFzExsh4xMbIf8TGyH/Exsh/xMbIf8TGyH/Exsh/xMbIf8TGyH/Exsh/xMb + If8TGyH/Exsh/xMbIf8TGyH/Exsh/xMbIf8TGyH/Exsh/xMbIf8TGyH/Exsh/xMbIf8TGyH/Exsh/xMb + If8TGyH/Exsh4hMbIXATGyEHAAGAAAABgAAAAYAAAAGAAAMBgMAPAYDgDwGA8A8BgPAOAYBwDAGAMAwA + ADAIAAAQCAAAEAgAABAIAAAQCAAAEAgAABAIAAAQCAAAEAgAABAIAAAfCAAAEAwAADAMAAAwDgAAcA8A + APAPgAHgB///4AAAAAAAAAAAAAAAAAAAAAA= + + + \ No newline at end of file diff --git a/Dat2Bin/LinkList.cs b/Dat2Bin/LinkList.cs new file mode 100644 index 0000000..b8623c1 --- /dev/null +++ b/Dat2Bin/LinkList.cs @@ -0,0 +1,246 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Net; +using System.Net.Sockets; +namespace Dat2Bin +{ + public class LinkList + { + /// + /// + /// + private int _length;//ÿһɾһ + public int Length + { + get { return _length; } + }//ȵĽӿֻ + private Node _head;//ͷ + public Node head + { + get { return _head; } + } + + private Node _end;//β + public Node End + { + get { return _end; } + } + + /// + /// ֵindexڵ㡣 + /// + /// + /// + /// + private Node FindNodeByIndex(int index) + { + //Խ׳쳣 + //쳣УΪ0indexΪ0ҲΪ쳣index<0ΪԽ硣 + if (_length <= index || index < 0) throw new IndexOutOfRangeException("ޡ"); + Node flag = null; + int hcount = index;//ͷĿ + int ecount = _length - index - 1;//βĿ + //ͷҵĿСڵڴβҵĿʹͷʼ顣 + if (hcount <= ecount) + { + flag = _head; + int count = hcount;//ؼһΪ˫ + //ʼƶǣֱƵҪҵĽڵλ + while (count > 0) + { + flag = flag.Next; + count--; + } + } + else + { + flag = _end; + int count = ecount;//ؼһΪ˫ + //ʼƶǣֱƵҪҵĽڵλ + while (count > 0) + { + flag = flag.Pre; + count--; + } + } + //ʱflagλñ + return flag; + } + public LinkList() + { + //½һ,Ϊ0 + _head = null; + _end = null; + _length = 0; + } + + /// + /// T͵dataװλ + /// + /// + /// + public void Add(string fileName, string SafeFileName, DateTime fileStartTime, DateTime fileEndTime, HEADInfo file_head) + { + //½һڵ + Node newNode = new Node(); + newNode.Next = null;//ΪβnextָضΪ + + newNode.data.fileName = fileName; + newNode.data.SafeFileName = SafeFileName; + newNode.data.fileStartTime = fileStartTime; + newNode.data.fileEndTime = fileEndTime; + newNode.data.fileHead = file_head; + + + if (_head == null) //ͷڵΪգΪգ + { + _head = newNode; //_headֱָ½Ľڵ㡣 + _head.Pre = null; //½ĽڵǰΪnull + + } + else + { + _end.Next = newNode; + newNode.Pre = _end; //һ֡ + + } + _end = newNode; //λΪβ + _length++; //ȼһ + } + public void Add(string fileName, string SafeFileName, DateTime fileStartTime, DateTime fileEndTime, HEADInfo file_head, byte transtimeOK) + { + //½һڵ + Node newNode = new Node(); + newNode.Next = null;//ΪβnextָضΪ + + newNode.data.fileName = fileName; + newNode.data.SafeFileName = SafeFileName; + newNode.data.fileStartTime = fileStartTime; + newNode.data.fileEndTime = fileEndTime; + newNode.data.fileHead = file_head; + newNode.data.transtimeOK = transtimeOK; + + if (_head == null) //ͷڵΪգΪգ + { + _head = newNode; //_headֱָ½Ľڵ㡣 + _head.Pre = null; //½ĽڵǰΪnull + + } + else + { + _end.Next = newNode; + newNode.Pre = _end; //һ֡ + + } + _end = newNode; //λΪβ + _length++; //ȼһ + } + + /// + /// T͵dataװλ + /// + /// + /// + public void Add(SiteParameter data) + { + //½һڵ + Node newNode = new Node(); + newNode.Next = null;//ΪβnextָضΪ + newNode.data = data; + if (_head == null) //ͷڵΪգΪգ + { + _head = newNode; //_headֱָ½Ľڵ㡣 + _head.Pre = null; //½ĽڵǰΪnull + + } + else + { + _end.Next = newNode; + newNode.Pre = _end; //һ֡ + + } + _end = newNode; //λΪβ + _length++; //ȼһ + } + + + /// + /// ƳָλõԪ + /// + /// + public void RemoveAt(int index) + { + //ԽexceptionѾFindNodeByIndexдˡ + Node flag = FindNodeByIndex(index); + //flagѾҪɾĽڵ㴦 + + if (_head.Next == null)//ֻһڵ㣬indexûԽ缴ɾ_head + { + //ֱӸ + _head = null; + _end = null; + //öΪ flag.Next.Pre = flag.Pre; + //_head.NextΪվͲPreָ + } + else//жһĽڵ,indexûԽ,ͼֿͳһ + { + //ɾڵ + if (index == _length - 1) _end = _end.Pre; + else flag.Next.Pre = flag.Pre; + if (index == 0) _head = flag.Next; + else flag.Pre.Next = flag.Next; + } + _length--;//ǿҳûԽ磬ʳɾ֮󣬱Ȼһ + //һֶΣͱҪһԡ + } + public SiteParameter GetnodeData(int position) + { + Node flag = FindNodeByIndex(position - 1);//1ʼ + return flag.data; + + } + public void SetNodeData(int position, ref SiteParameter data) + { + Node flag = FindNodeByIndex(position - 1);//1ʼ + flag.data = data; + } + + /// + /// SiteParameterߵֵ + /// + /// + /// + public SiteParameter this[int index] + { + get + { + Node flag = FindNodeByIndex(index); + return flag.data; + } + set + { + Node flag = FindNodeByIndex(index); + flag.data = value; + } + } + + /// + /// + /// + public void Clear() + { + _head = null; + _end = null; + _length = 0; + } + + /// + /// ȡԪصĸ + /// + public int GetLength() + { + return _length; + } + } +} diff --git a/Dat2Bin/MTEMHead.cs b/Dat2Bin/MTEMHead.cs new file mode 100644 index 0000000..71fdce0 --- /dev/null +++ b/Dat2Bin/MTEMHead.cs @@ -0,0 +1,276 @@ +using System; +using System.Text; +using System.Windows.Forms; +using System.Runtime.InteropServices; +using System.IO; + +namespace Dat2Bin +{ + public struct MTEMFreqFile + { + public byte No;//0-29 + public ushort CycleLen;// + public ushort CycleNum;// + public int WaveStyle;// + public float SampleRate;// + public sbyte pro;// + public byte OutCurrent;// + public float Time;// + public float Freq;//。 + + } + [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] + public struct MTEM_TInfo + { + public short day; // 日 + public short month; // 月 + public short year; // 年 2001-2999 + public short hour; // 时 + public short minute; // 分 + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)] + public string geo; // 工作地区 - 地名 + public byte sec; // 秒 + public byte met; // 记录方法代码: + //0-31 + public short end_year; // 年 2001-2999 + public short end_month; // 月 + public short end_day; // 日 + public short end_hour; // 时 + public short end_minute; // 分 + public byte end_sec; // 秒 + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)] + public string standby1; // 备用 + public sbyte pro; // ADC量化代码: + public byte kan; // number of channels 通道数 + public byte valid; // 该记录是否有效 + public short ab1; // 发射源AB的第一个电极的位置 + public short ab2; //发射源AB的第二个电极的位置 + public short ab3; // 发射机的位置 + public short res; // 接地电阻 + public float Tok; // 发射电流 I(A) + public float Voltage; // 发射电压 V(V) + + + //32-71 + + public byte Tgu; // 发射波形: 1-doubling + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 17)] + public string standby5; // 备用 + public int Nom; // record of number 记录号与文件名相对应 + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 6)] + public string standby6; // 备用 + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)] + public string Fam; // surname of the operator 操作员 + + // 72-119 + + public int Lps; // number of points in record 记录的数据点数 + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 18)] + public string standby7; // 备用 + + public short Nst; // MeterNum 仪器号 + /// + /// 通道号 + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)] + public string standby8; // 备用,临时改为通道号ch01-ch03 + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 48)] + public string Com; + // string of the comment 注释行 + + //120-199 + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 90)] + public short[] Isw; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 132)] + public string standby9; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)] + public ChInfo[] channel; + + + } + [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] + public struct HEADInfo + { + public short day; // 日 + public short month; // 月 + public short year; // 年 2001-2999 + public short hour; // 时 + public short minute; // 分 + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)] + public string geo; // 工作地区 - 地名 + public byte sec; // 秒 + public byte met; // 记录方法代码: + //0-31 + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 21)] + public string standby1; // 备用 + public sbyte pro; // ADC量化代码: + public byte kan; // number of channels 通道数 + public byte standby2; // 备用 + public short ab1; // Lab(meters) length of ab1, 发射源AB的长度 发射极距 + public short ab2; // number AB 发射点号 + public short ab3; // + public short standby3; // 备用 + public float Tok; // 发射电流 I(A) + public uint standby4; // 备用 + + + //32-71 + + public byte Tgu; // 发射波形: 1-doubling + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 17)] + public string standby5; // 备用 + public int Nom; // record of number 记录号与文件名相对应 + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 6)] + public string standby6; // 备用 + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)] + public string Fam; // surname of the operator 操作员 + + // 72-119 + + public int Lps; // number of points in record 记录的数据点数 + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 18)] + public string standby7; // 备用 + + public short Nst; // MeterNum 仪器号 + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)] + public string standby8; // 备用 + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 48)] + public string Com; + // string of the comment 注释行 + + //120-199 + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 90)] + public short[] Isw; + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 132)] + public string standby9; + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)] + public ChInfo[] channel; + + + } + // 406-511 + [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]//按一个字节对齐 + public struct ChInfo + { + public byte Idk; // + public byte standby0; + public sbyte Uko; // + public byte Ufl; // 测站号 + public short Pkt; // 测点号 + public short Prf; // 测线号 + public short ab; // 电极距 + public short datatype; // 数据类型 + //1)数据类型: + // 1- Hall + // 2- 电极 + // 4- 接收 + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)] + public string standby1; + + public float X; //coordinate 'x' (not use) + public float Y; //coordinate 'y' (not use) + public float Z; //coordinate 'z' (not use) + public float Ecs; // LSB + + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 28)] + public string standby2; + } // 64*24=1536 + public struct FreqFileHead + { + + public MTEMFreqFile[] MTEMfreqfile; + public int totalpoint ; //用于总采样点数label_totsize + public float totaltime ; //采集总时间 + public string SafeFileName; + public string FileName; + } + + [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]//按一个字节对齐 + public struct SEGYFileHead + { + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3200)] + public byte[] ASCIIByte; + public secPartSEGYFileHead secPartSEGYFileHead;/// + } + + [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]//按一个字节对齐 + public struct secPartSEGYFileHead + { + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 12)] + public byte[] standby;//Not use + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] channelNumber; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] standby2; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] sampleGap; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] standby3; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] samplePointerNumber; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] standby5; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] codeStyle; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 28)] + public byte[] standby4; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] measureFormat; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 344)] + public byte[] standby6; + + } + + [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]//按一个字节对齐 + public struct SEGYChannelHead + { + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] + public byte[] fileNumber; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] + public byte[] channelNumber; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] + public byte[] origNumber; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] + public byte[] standby; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] channelObject; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 50)] + public byte[] standby1; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] + public byte[] xScale; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] + public byte[] yScale; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] scaleObject; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)] + public byte[] standby2 ; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] channelSamplePointer; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] channelSampleGap; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 38)] + public byte[] standby3; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] year; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] day; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] hour; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] mins; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] second; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] + public byte[] UTC; + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 72)] + public byte[] standby4 ; + } +} diff --git a/Dat2Bin/Node.cs b/Dat2Bin/Node.cs new file mode 100644 index 0000000..8a05321 --- /dev/null +++ b/Dat2Bin/Node.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Dat2Bin +{ + public class Node + { + public SiteParameter data; + public Node Next; + public Node Pre; + } +} diff --git a/Dat2Bin/Program.cs b/Dat2Bin/Program.cs new file mode 100644 index 0000000..dab6fda --- /dev/null +++ b/Dat2Bin/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Dat2Bin +{ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Dat2BinForm()); + } + } +} diff --git a/Dat2Bin/Properties/AssemblyInfo.cs b/Dat2Bin/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a15d475 --- /dev/null +++ b/Dat2Bin/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Dat2Bin")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Dat2Bin")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("e431fbfe-d292-45bb-bcd8-dee8ae2d2392")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Dat2Bin/Properties/Resources.Designer.cs b/Dat2Bin/Properties/Resources.Designer.cs new file mode 100644 index 0000000..42e06a2 --- /dev/null +++ b/Dat2Bin/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能导致不正确的行为,如果 +// 重新生成代码,则所做更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace Dat2Bin.Properties +{ + + + /// + /// 强类型资源类,用于查找本地化字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 返回此类使用的缓存 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Dat2Bin.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 覆盖当前线程的 CurrentUICulture 属性 + /// 使用此强类型的资源类的资源查找。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Dat2Bin/Properties/Resources.resx b/Dat2Bin/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Dat2Bin/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Dat2Bin/Properties/Settings.Designer.cs b/Dat2Bin/Properties/Settings.Designer.cs new file mode 100644 index 0000000..de61141 --- /dev/null +++ b/Dat2Bin/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Dat2Bin.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Dat2Bin/Properties/Settings.settings b/Dat2Bin/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Dat2Bin/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Dat2Bin/SiteParameter.cs b/Dat2Bin/SiteParameter.cs new file mode 100644 index 0000000..c81d812 --- /dev/null +++ b/Dat2Bin/SiteParameter.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Net; +using System.Net.Sockets; +namespace Dat2Bin +{ + public struct SiteParameter + { + public ushort fileId; + public string fileName; + public string SafeFileName; + public DateTime fileStartTime; + public DateTime fileEndTime; + public HEADInfo fileHead; + public IPAddress boxip; + public ushort upfileId; + public byte transtimeOK; + public byte LogFile;//LOG :1 OTHER:0 + + } +} \ No newline at end of file diff --git a/Dat2Bin/Toolbox.ico b/Dat2Bin/Toolbox.ico new file mode 100644 index 0000000..0d59fc6 Binary files /dev/null and b/Dat2Bin/Toolbox.ico differ diff --git a/Dat2Bin/app.config b/Dat2Bin/app.config new file mode 100644 index 0000000..3e0e37c --- /dev/null +++ b/Dat2Bin/app.config @@ -0,0 +1,3 @@ + + + diff --git a/Dat2Bin/packages.config b/Dat2Bin/packages.config new file mode 100644 index 0000000..b184c7a --- /dev/null +++ b/Dat2Bin/packages.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file