Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read an avg file

Status
Not open for further replies.

ltsi

Programmer
Jul 10, 2003
7
FR
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] = &quot; &quot;;
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(&quot;m_nPnts= %d \n&quot;,erp->pnts);
m_Rate=erp->rate;TRACE(&quot;m_Rate= %d \n&quot;,m_Rate);
m_nChannels=erp->nchannels;TRACE(&quot;m_nChannels= %d \n&quot;,m_nChannels);
// get values of member variables
for (i=0; i<20; i++) {
TRACE(&quot;c= %c \n&quot;,erp->doctor);
m_Doctor=erp->doctor;
m_Hospital=erp->hospital;
m_Id=erp->id;
m_Patient=erp->patient;
}
TRACE(&quot;docteur= %s \n&quot;,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(&quot;Entre dans CAverage::Serialize\n&quot;);
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(&quot;\n nom du fichier: %s \n&quot;, ar.GetFile()->GetFileName());

ar.Read(chan,2);
m_nChannels=atoi(chan);
TRACE(&quot;\n m_nChannels = %d \n&quot;,m_nChannels);

ar.Read(un,4);
iun=atoi(un);
TRACE(&quot;m_nPts= %d \n\n&quot;,iun);

m_nPnts=(short unsigned) iun;
ar.Read(un,4);
iun=atoi(un);
TRACE(&quot;m_Rate= %d \n&quot;,iun);
m_Rate=(unsigned short)iun;
ar.Read(xmin,10);
m_xmin=atof(xmin);
ar.Read(xmax,10);
m_xmax=atof(xmax);
TRACE(&quot;\n !!!!!!!!!!!!!!!nChannels dans CAverage::Serialize %d \n&quot;,m_nChannels);
TRACE(&quot;\n !!!!!!!!!!!!!!!nRate dans CAverage::Serialize %d \n&quot;,m_Rate);
TRACE(&quot;\n !!!!!!!!!!!!!!!m_nPnts dans CAverage::Serialize %d \n&quot;,m_nPnts);
TRACE(&quot;\n !!!!!!!!!!!!!!!xmin dans CAverage::Serialize %f \n&quot;,m_xmin);
TRACE(&quot;\n !!!!!!!!!!!!!!!xmax dans CAverage::Serialize %f \n&quot;,m_xmax);
// ar.Read(data,10);
// fdata=atof(data);
// TRACE(&quot;premiere data = %f \n&quot;,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);
}
}
}




}


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top