-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataBuffer.cpp
86 lines (69 loc) · 2.37 KB
/
dataBuffer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "dataBuffer.h"
using namespace std;
dataBuffer::dataBuffer()
{
// declaring variables
numElement = 0;
numSample = 0;
scanline = 0;
dataMatrix = NULL;
next = NULL;
}
dataBuffer::dataBuffer(std::ifstream *imagFile, std::ifstream *realFile, int inputNumElement, int inputNumSample, int inputScanline)
{
// Assigning variables to the corresponding counterpart of the class component variables
numElement = inputNumElement;
numSample = inputNumSample;
scanline = inputScanline;
dataMatrix = createDataMatrix();
loadRFData(dataMatrix, imagFile, realFile); // populating the dataMatrix, imagFile and realFile are two ifstream pointers that point to the file object for data reading
}
dataBuffer::~dataBuffer()
{
deleteDataMatrix(); // releasing the 2D array dynamically allocated for dataMatrix
}
complex **dataBuffer::createDataMatrix()
{
complex **RFData = new complex *[numElement];
// allocates a complex array of length numElement to each of the RFData pointer
for (int i = 0; i < numElement; i++)
{
RFData[i] = new complex[numSample];
}
return RFData;
}
int dataBuffer::loadRFData(complex **RFData, std::ifstream *imagFile, std::ifstream *realFile)
{
// create a 'real' and 'imag' character array with a maximum length of 50 characters to store the imput file data
char real[50];
char imag[50];
// Getline() command is used to extract the data lines from the txt files
for (int i = 0; i < numElement; i++)
{
for (int j = 0; j < numSample; j++)
{
imagFile->getline(imag, 50);
realFile->getline(real, 50);
RFData[i][j].imag = atof(imag);
RFData[i][j].real = atof(real);
}
}
return 0;
}
float dataBuffer::getRealRFData(int element,int sample)
{
return dataMatrix[element][sample].real; // Returns the real component of the complex data stored in dataMatrix
}
float dataBuffer::getImagRFData(int element,int sample)
{
return dataMatrix[element][sample].imag; // Returns the imaginary component of the complex data stored in dataMatrix
}
void dataBuffer::deleteDataMatrix()
// releasing the 2D dataMatrix array
{
for (int i = 0; i < numElement; i++)
{
delete dataMatrix[i];
}
delete dataMatrix;
}