I am trying currently to extract datas from a .avg file (datas from brain recordings) within a visual c++ application.
Each file contains a header in which two structures are defined : SETUP and ELECTLOC.
Using sizeof, I don't pass the get real size of the header.
Therefore the reading of the header and the datas (time on X-Axis and Volts on Y-Axis) is not the good one : it is shifted.
How can I do?
Here is the code of the extraction:
CAverage::CAverage()
{
//valeur par defaut:
int i;
for(i=0;i<20;i++)
{
m_Doctor=' ';
m_Hospital=' ';
m_Id=' ';
m_Patient=' ';
}
m_Rate=1000;
m_nPnts=2;
m_nChannels=32;
matrix_datapoint_alloc(&m_data,m_nChannels,m_nPnts);
for(i=0;i<32;i++)
{
m_data[0].fXVal=-0.082;
m_data[0].fYVal=0.0;
m_data[1].fXVal=0.738;
m_data[1].fYVal=0.0;
}
}
CAverage::~CAverage()
{
matrix_datapoint_free(&m_data);
}
void CAverage::Extract(CArchive &ar)
{
char dummy[5] = " ";
int i, j;
SETUP *erp;
erp = (SETUP *) malloc (sizeof (SETUP));
ar.GetFile()->SeekToBegin();
// read the general part of the header
ar.Read (erp, 900);
m_nPnts=erp->pnts;
TRACE("m_nPnts= %d \n",erp->pnts);
m_Rate=erp->rate;TRACE("m_Rate= %d \n",m_Rate);
m_nChannels=erp->nchannels;TRACE("m_nChannels= %d \n",m_nChannels);
// get values of member variables
for (i=0; i<20; i++) {
TRACE("c= %c \n",erp->doctor);
m_Doctor=erp->doctor;
m_Hospital=erp->hospital;
m_Id=erp->id;
m_Patient=erp->patient;
}
TRACE("docteur= %s \n",erp->doctor);
// read the channel specific part of the header
ar.Read(&(erp->elect_tab[0]), 75*erp->nchannels);
matrix_datapoint_free(&m_data);
matrix_datapoint_alloc (&m_data, erp->nchannels, erp->pnts);
for (i = 0; i < erp->nchannels; i++)
{
ar.Read (dummy, 5);
ar.Read (m_data, sizeof (TDataPoint)* erp->pnts);
for (j = 0; j < erp->pnts; j++)
{
m_data[j].fYVal = erp->elect_tab.calib / erp->elect_tab.n;
m_data[j].fXVal = -0.082+((double)j)/((double) erp->rate); //-0.082??
}
}
free(erp);
}
void CAverage::Serialize(CArchive &ar)
{
TRACE("Entre dans CAverage::Serialize\n"
if (ar.IsStoring()) {
}
else {
Extract(ar);
CString st;
char un[4];
int iun;
char chan [2];
char data [10];
char xmax[10];
char xmin[10];
double fdata;
TRACE("\n nom du fichier: %s \n", ar.GetFile()->GetFileName());
ar.Read(chan,2);
m_nChannels=atoi(chan);
TRACE("\n m_nChannels = %d \n",m_nChannels);
ar.Read(un,4);
iun=atoi(un);
TRACE("m_nPts= %d \n\n",iun);
m_nPnts=(short unsigned) iun;
ar.Read(un,4);
iun=atoi(un);
TRACE("m_Rate= %d \n",iun);
m_Rate=(unsigned short)iun;
ar.Read(xmin,10);
m_xmin=atof(xmin);
ar.Read(xmax,10);
m_xmax=atof(xmax);
TRACE("\n !!!!!!!!!!!!!!!nChannels dans CAverage::Serialize %d \n",m_nChannels);
TRACE("\n !!!!!!!!!!!!!!!nRate dans CAverage::Serialize %d \n",m_Rate);
TRACE("\n !!!!!!!!!!!!!!!m_nPnts dans CAverage::Serialize %d \n",m_nPnts);
TRACE("\n !!!!!!!!!!!!!!!xmin dans CAverage::Serialize %f \n",m_xmin);
TRACE("\n !!!!!!!!!!!!!!!xmax dans CAverage::Serialize %f \n",m_xmax);
// ar.Read(data,10);
// fdata=atof(data);
// TRACE("premiere data = %f \n",fdata);
matrix_datapoint_free(&m_data);
matrix_datapoint_alloc(&m_data,m_nChannels,m_nPnts);
//lecture des donnees
short unsigned j;
for(int i=0;i<m_nChannels;i++)
{
for(j=0;j<m_nPnts;j++)
{
ar.Read(data,10);
fdata=atof(data);
m_data[j].fYVal = fdata;
m_data[j].fXVal = -0.082+((double)j)/((double) m_Rate);
}
}
}
}
Each file contains a header in which two structures are defined : SETUP and ELECTLOC.
Using sizeof, I don't pass the get real size of the header.
Therefore the reading of the header and the datas (time on X-Axis and Volts on Y-Axis) is not the good one : it is shifted.
How can I do?
Here is the code of the extraction:
CAverage::CAverage()
{
//valeur par defaut:
int i;
for(i=0;i<20;i++)
{
m_Doctor=' ';
m_Hospital=' ';
m_Id=' ';
m_Patient=' ';
}
m_Rate=1000;
m_nPnts=2;
m_nChannels=32;
matrix_datapoint_alloc(&m_data,m_nChannels,m_nPnts);
for(i=0;i<32;i++)
{
m_data[0].fXVal=-0.082;
m_data[0].fYVal=0.0;
m_data[1].fXVal=0.738;
m_data[1].fYVal=0.0;
}
}
CAverage::~CAverage()
{
matrix_datapoint_free(&m_data);
}
void CAverage::Extract(CArchive &ar)
{
char dummy[5] = " ";
int i, j;
SETUP *erp;
erp = (SETUP *) malloc (sizeof (SETUP));
ar.GetFile()->SeekToBegin();
// read the general part of the header
ar.Read (erp, 900);
m_nPnts=erp->pnts;
TRACE("m_nPnts= %d \n",erp->pnts);
m_Rate=erp->rate;TRACE("m_Rate= %d \n",m_Rate);
m_nChannels=erp->nchannels;TRACE("m_nChannels= %d \n",m_nChannels);
// get values of member variables
for (i=0; i<20; i++) {
TRACE("c= %c \n",erp->doctor);
m_Doctor=erp->doctor;
m_Hospital=erp->hospital;
m_Id=erp->id;
m_Patient=erp->patient;
}
TRACE("docteur= %s \n",erp->doctor);
// read the channel specific part of the header
ar.Read(&(erp->elect_tab[0]), 75*erp->nchannels);
matrix_datapoint_free(&m_data);
matrix_datapoint_alloc (&m_data, erp->nchannels, erp->pnts);
for (i = 0; i < erp->nchannels; i++)
{
ar.Read (dummy, 5);
ar.Read (m_data, sizeof (TDataPoint)* erp->pnts);
for (j = 0; j < erp->pnts; j++)
{
m_data[j].fYVal = erp->elect_tab.calib / erp->elect_tab.n;
m_data[j].fXVal = -0.082+((double)j)/((double) erp->rate); //-0.082??
}
}
free(erp);
}
void CAverage::Serialize(CArchive &ar)
{
TRACE("Entre dans CAverage::Serialize\n"
if (ar.IsStoring()) {
}
else {
Extract(ar);
CString st;
char un[4];
int iun;
char chan [2];
char data [10];
char xmax[10];
char xmin[10];
double fdata;
TRACE("\n nom du fichier: %s \n", ar.GetFile()->GetFileName());
ar.Read(chan,2);
m_nChannels=atoi(chan);
TRACE("\n m_nChannels = %d \n",m_nChannels);
ar.Read(un,4);
iun=atoi(un);
TRACE("m_nPts= %d \n\n",iun);
m_nPnts=(short unsigned) iun;
ar.Read(un,4);
iun=atoi(un);
TRACE("m_Rate= %d \n",iun);
m_Rate=(unsigned short)iun;
ar.Read(xmin,10);
m_xmin=atof(xmin);
ar.Read(xmax,10);
m_xmax=atof(xmax);
TRACE("\n !!!!!!!!!!!!!!!nChannels dans CAverage::Serialize %d \n",m_nChannels);
TRACE("\n !!!!!!!!!!!!!!!nRate dans CAverage::Serialize %d \n",m_Rate);
TRACE("\n !!!!!!!!!!!!!!!m_nPnts dans CAverage::Serialize %d \n",m_nPnts);
TRACE("\n !!!!!!!!!!!!!!!xmin dans CAverage::Serialize %f \n",m_xmin);
TRACE("\n !!!!!!!!!!!!!!!xmax dans CAverage::Serialize %f \n",m_xmax);
// ar.Read(data,10);
// fdata=atof(data);
// TRACE("premiere data = %f \n",fdata);
matrix_datapoint_free(&m_data);
matrix_datapoint_alloc(&m_data,m_nChannels,m_nPnts);
//lecture des donnees
short unsigned j;
for(int i=0;i<m_nChannels;i++)
{
for(j=0;j<m_nPnts;j++)
{
ar.Read(data,10);
fdata=atof(data);
m_data[j].fYVal = fdata;
m_data[j].fXVal = -0.082+((double)j)/((double) m_Rate);
}
}
}
}