public bool Load1DReal(string file, UInt32 dataNum) { this.Text = file; FileInfo fi = new FileInfo(file); long size = fi.Length; int itemSize = 2 * sizeof(double); UInt32 cNum = SpaceDigitizer.FFTW_HALF_N(dataNum); long itemCount = cNum; if (itemCount * itemSize != size) { MessageBox.Show("File size mismatch"); } else { double vr, vi; DataTable tbl = new DataTable("Data"); tbl.Columns.Add("k", typeof(double)); tbl.Columns.Add("Real", typeof(double)); tbl.Columns.Add("Imag", typeof(double)); BinaryReader br = new BinaryReader(new FileStream(file, FileMode.Open)); for (int i = 0; i < itemCount; i++) { vr = br.ReadDouble(); vi = br.ReadDouble(); tbl.Rows.Add(i, Math.Round(vr, 10), Math.Round(vi, 10)); } br.Close(); dataGridView1.DataSource = tbl; dataGridView1.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; return(true); } return(false); }
public bool Load2DReal(string file, UInt32 dataNum) { this.Text = file; FileInfo fi = new FileInfo(file); long size = fi.Length; int itemSize = 2 * sizeof(double); UInt32 rNum = SpaceDigitizer.SPACE_POINTS(dataNum); UInt32 rNum2 = rNum * rNum; UInt32 cNum = SpaceDigitizer.FFTW_HALF_N(dataNum); long itemCount = rNum * cNum; if (itemCount * itemSize != size) { MessageBox.Show("File size mismatch"); } else { object[] vs; int i, j; double vr, vi; DataTable tbl = new DataTable("Data"); //i-frequency column tbl.Columns.Add("k", typeof(int)); //j-data columns for (j = 0; j < cNum; j++) { tbl.Columns.Add(string.Format(CultureInfo.InvariantCulture, "Col{0}", j), typeof(string)); tbl.Columns[j + 1].Caption = j.ToString(CultureInfo.InvariantCulture); } BinaryReader br = new BinaryReader(new FileStream(file, FileMode.Open)); //row-major indexing for (i = 0; i < rNum; i++) { vs = new object[cNum + 1]; vs[0] = i; //the first column is i-frequency for (j = 0; j < cNum; j++) { vr = br.ReadDouble(); vi = br.ReadDouble(); vs[j + 1] = string.Format(CultureInfo.InvariantCulture, "{0}[{1}]", Math.Round(vr, 6), Math.Round(vi, 6)); } tbl.Rows.Add(vs); } br.Close(); dataGridView1.DataSource = tbl; dataGridView1.Columns[0].Frozen = true; return(true); } return(false); }