Beispiel #1
0
        public bool Load1DComplex(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);
            //int cNum = dataNum + 1;
            long itemCount = rNum;

            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, vr, vi);
                }
                br.Close();
                dataGridView1.DataSource = tbl;
                dataGridView1.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        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);
        }