readdata.cpp
来自「故障诊断工作涉及的领域相当广泛」· C++ 代码 · 共 104 行
CPP
104 行
// readdata.cpp: implementation of the readdata class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "richtest.h"
#include "readdata.h"
#include "mydata.h"
#include "mat.h"
#define BASELTH 4
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
void readdata::file2double(mydata *data,CArchive& ar)
{ int count=0,i=0;
CFile* fp=ar.GetFile();
int lth=fp->GetLength();
char* bag0=new char[64];
ibag=new double[lth/2];
char* bag=bag0,c;
CString info;
info.Empty();
do{
count++;
ar>>c;
info+=c;
info_lth++;
}while(c!='{'&&count<lth);
info+='\0';
do{ count++;
ar>>c;
if(c>='0'&&c<='9')
*(bag++)=c;
else if((c==',')||c=='}'||c==' ')
{
*(ibag+i++)=atof(bag0);
bag=bag0;
if(c=='}')
goto tail;
}
}while(count<lth);
tail:
data->set_data(info.GetBuffer(4),info_lth+4,type_dou,i,ibag);
delete []bag0;
delete []ibag;
}
readdata::readdata(mydata* in,LPCTSTR docname)
{
this->docname=docname;
pdata=in;
info_lth=0;
this->is_from_file=is_from_file;
}
readdata::~readdata()
{
}
BOOL readdata::input()
{
CString filename,line,fileext;
filename.Empty();
CFileDialog dlg(TRUE);
if(IDOK==dlg.DoModal())
{
filename=dlg.GetFileName();
fileext=dlg.GetFileExt();
if(!filename.IsEmpty())
{
MATFile* pmf=matOpen(filename.GetBuffer(1),"r");
mxArray* data=matGetVariable(pmf,"data");
mxArray* t=matGetVariable(pmf,"T");
static mwArray bag[2];
bag[0]=mwArray(data);
bag[1]=mwArray(t);
pdata->mset_data(NULL,0,type_mw,NULL,NULL,2,bag);
// mxDestroyArray(data);
matClose(pmf);
//static char* bag0,*bag;
// CFile* filebin=new CFile(filename,CFile::modeRead);
// if(filebin!=NULL)
// {
// CArchive ar(filebin,CArchive::load);
// file2double(pdata,ar);
// }
}
else
return FALSE;
}
else
return FALSE;
return TRUE;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?