|
int CVICALLBACK OPEN (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int o,xb=0;
int ret;
int i,j,k;
int n=2;//dts文件中一个数据所占用的字节
int max=0;
double *Ydataa1;
double *Ydataa2;
float adc[2];
unsigned char *data;
unsigned short int *dataH;
unsigned short int *dataH1;
unsigned short int *dataH2;
unsigned short int *dataL;
switch (event)
{
case EVENT_COMMIT:
ret=FileSelectPopup ("c:\\", "*.dts", "*.dts;*.dtd", "选择驱动器文件",
VAL_LOAD_BUTTON, 0, 0, 1, 1, pathName);
if(ret!=VAL_EXISTING_FILE_SELECTED)
return 0;
InsertTextBoxLine (cHandle, PANEL_TEXTBOX, 0, pathName);
xb=strlen(pathName);
if(pathName[xb-1]=='S'||pathName[xb-1]=='s')
{td=0;
SetCtrlVal (cHandle, PANEL_CHANNEL, td);
}
if(pathName[xb-1]=='D'||pathName[xb-1]=='d')
{td=1;
SetCtrlVal (cHandle, PANEL_CHANNEL, td);
}
if(td==0) //单通道
{
GetFileInfo (pathName, &filesize);
pf=(int)(filesize/(2.56*n));
data=(unsigned char*)malloc(filesize);
dataH=(unsigned short int*)malloc(filesize);
dataL=(unsigned short int*)malloc(filesize);
Ydata=(float*)malloc(filesize*n);
Xdata=(float*)malloc(filesize*n);
o=0;
for(i=0;i<260;i++)
{
if(pathName!=NULL)
pts=pathName;
else {pts[xb-3]='P';
break;}
}
o=0;
GetFileInfo (pts, &ptsfilesize);
fp=fopen(pts,"rb");
fread(& T,sizeof(struct pt),1,fp);
switch(PT.freq) //采样频率
{
case 2:SetCtrlVal (cHandle, PANEL_RINGKNOB, 0); sj=0.390625; py=2.56; break;
case 5:SetCtrlVal (cHandle, PANEL_RINGKNOB, 1); sj=0.1953125; py=5.12; break;
case 25:SetCtrlVal (cHandle, PANEL_RINGKNOB, 2);sj=0.0390625; py=25.6; break;
case 256: SetCtrlVal (cHandle, PANEL_RINGKNOB, 3);sj=0.00390625; py=256; break;
case 1280:SetCtrlVal (cHandle, PANEL_RINGKNOB, 4);sj=0.00078125; py=1280; break;
case 2560:SetCtrlVal (cHandle, PANEL_RINGKNOB, 5);sj=0.000390625; py=2560; break;
case 5120:SetCtrlVal (cHandle, PANEL_RINGKNOB, 6);sj=0.0001953125; py=5120; break;
case 25600:SetCtrlVal (cHandle, PANEL_RINGKNOB, 7);sj=0.0000390625;py=25600; break;
}
//
switch(PT.blocks1) //数据块数
{
case 1: SetCtrlVal (cHandle, PANEL_DATANUMBLE, 0); break;
case 2: SetCtrlVal (cHandle, PANEL_DATANUMBLE, 1); break;
case 4: SetCtrlVal (cHandle, PANEL_DATANUMBLE, 2); break;
case 8: SetCtrlVal (cHandle, PANEL_DATANUMBLE, 3); break;
case 16: SetCtrlVal (cHandle, PANEL_DATANUMBLE, 4); break;
}
// 给X轴数据赋值
//
Xdata[0]=0.00000000; //
for(i=1;i<filesize/n;i++) //
Xdata= Xdata[i-1]+sj; //
FileToArray (pathName, data,VAL_UNSIGNED_CHAR, filesize, 1, VAL_GROUPS_TOGETHER,
VAL_GROUPS_AS_ROWS, VAL_BINARY); //以INTEGER为单位长度读入数祝橹??
for(i=0,j=0,k=0;j<filesize;i++,k++)
{
dataH=(unsigned short int)(data[j]);
dataL[k]=(unsigned short int)(data[j+1]);
Ydata=(float)(((double)((dataH+dataL*256-2048)*5000/2048)/100)*100/PT.adc);
j=j+2;
}
DeleteGraphPlot (cHandle, PANEL_WAVE, -1, VAL_IMMEDIATE_DRAW);
DeleteGraphPlot (cHandle, PANEL_FFTWAVE, -1, VAL_IMMEDIATE_DRAW);
DeleteGraphPlot (cHandle, PANEL_WAVET, -1, VAL_IMMEDIATE_DRAW);
DeleteGraphPlot (cHandle, PANEL_FFTWAVET, -1, VAL_IMMEDIATE_DRAW);
PlotXY (cHandle, PANEL_WAVE, Xdata, Ydata, filesize/n, VAL_FLOAT,
VAL_FLOAT, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1,
VAL_RED);
SetAxisRange (cHandle, PANEL_WAVE, VAL_MANUAL, 0.0, Xdata[pf]/2,
VAL_AUTOSCALE, 0.0, 1.0);
for(i=0;i<9;i++)
{
SetCtrlVal (cHandle, 52-i, 0.00);
SetCtrlVal (cHandle, 43-i, 0.00);
}
for(i=0;i<9;i++)
{
SetCtrlVal (cHandle, 34-i, 0.00);
SetCtrlVal (cHandle, 25-i, 0.00);
}
lj=0;
}
/*****************双通道*************************/
else if(td==1){//ret=FileSelectPopup ("c:\\", "*.dtd", "*.dtd;*.ptd", "选择驱动器文件",
// VAL_LOAD_BUTTON, 0, 1, 1, 0, pathName);
//if(ret!=VAL_EXISTING_FILE_SELECTED)
// return 0;
GetFileInfo (pathName, &filesize);
pf=(int)(filesize/(2.56*n));
data=(unsigned char*)malloc(filesize);
dataH=(unsigned short int*)malloc(filesize);
dataL=(unsigned short int*)malloc(filesize);
Ydata=(float*)malloc(filesize*n);
Ydata1=(float*)malloc(filesize/2*n);
Ydata2=(float*)malloc(filesize/2*n);
Xdata=(float*)malloc(filesize/2*n);
for(i=0;i<260;i++)
{
if(pathName!=NULL)
ptd=pathName;
else {ptd[i-3]='P';
ptd[i-2]='T';
ptd[i-1]='D';
break;}
}
GetFileInfo (ptd, &ptdfilesize);
fp=fopen(ptd,"rb");
fread(& D,sizeof(struct pd),1,fp);
fseek (fp, 62, SEEK_SET);
fread (&adc[0], 4, 1, fp);
fseek (fp, 66, SEEK_SET);
fread (&adc[1], 4, 1, fp);
switch(PD.freq) //采样频率
{
case 2:SetCtrlVal (cHandle, PANEL_RINGKNOB, 0); sj=0.390625; py=2.56; break;
case 5:SetCtrlVal (cHandle, PANEL_RINGKNOB, 1); sj=0.1953125; py=5.12; break;
case 25:SetCtrlVal (cHandle, PANEL_RINGKNOB, 2);sj=0.0390625; py=25.6; break;
case 256: SetCtrlVal (cHandle, PANEL_RINGKNOB, 3);sj=0.00390625; py=256; break;
case 1280:SetCtrlVal (cHandle, PANEL_RINGKNOB, 4);sj=0.00078125; py=1280; break;
case 2560:SetCtrlVal (cHandle, PANEL_RINGKNOB, 5);sj=0.000390625; py=2560; break;
case 5120:SetCtrlVal (cHandle, PANEL_RINGKNOB, 6);sj=0.0001953125; py=5120; break;
case 25600:SetCtrlVal (cHandle, PANEL_RINGKNOB, 7);sj=0.0000390625;py=25600; break;
}
//
switch(PD.blocks1) //数据块数
{
case 1: SetCtrlVal (cHandle, PANEL_DATANUMBLE, 0); break;
case 2: SetCtrlVal (cHandle, PANEL_DATANUMBLE, 1); break;
case 4: SetCtrlVal (cHandle, PANEL_DATANUMBLE, 2); break;
case 8: SetCtrlVal (cHandle, PANEL_DATANUMBLE, 3); break;
case 16: SetCtrlVal (cHandle, PANEL_DATANUMBLE, 4); break;
}
// 给X轴数据赋值
//
Xdata[0]=0.00000000; //
for(i=1;i<filesize/2/n;i++) //
Xdata= Xdata[i-1]+sj; //
FileToArray (pathName, data,VAL_UNSIGNED_CHAR, filesize, 1, VAL_GROUPS_TOGETHER,
VAL_GROUPS_AS_ROWS, VAL_BINARY); //以INTEGER为单位长度读入数祝橹??
for(i=0,j=0,k=0;j<filesize;i++,k++)
{
dataH=(unsigned short int)(data[j]);
dataL[k]=(unsigned short int)(data[j+1]);
Ydata=((float)((dataH+dataL*256-2048)*5000/2048))/100;
j=j+2;
}
for(i=0,j=0;j<filesize/2;i++)
{
Ydata1=(float)(Ydata[j]*100/adc[0]);
Ydata2=(float)(Ydata[j+1]*100/adc[1]);
j=j+2;
}
DeleteGraphPlot (cHandle, PANEL_WAVE, -1, VAL_IMMEDIATE_DRAW);
DeleteGraphPlot (cHandle, PANEL_FFTWAVE, -1, VAL_IMMEDIATE_DRAW);
DeleteGraphPlot (cHandle, PANEL_WAVET, -1, VAL_IMMEDIATE_DRAW);
DeleteGraphPlot (cHandle, PANEL_FFTWAVET, -1, VAL_IMMEDIATE_DRAW);
PlotXY (cHandle, PANEL_WAVE, Xdata, Ydata1, filesize/n/2, VAL_FLOAT,
VAL_FLOAT, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1,
VAL_RED);
PlotXY (cHandle, PANEL_WAVET, Xdata, Ydata2, filesize/n/2, VAL_FLOAT,
VAL_FLOAT, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1,
VAL_RED);
SetAxisRange (cHandle, PANEL_WAVE, VAL_MANUAL, 0.0, Xdata[pf]/2,
VAL_AUTOSCALE, 0.0, 1.0);
SetAxisRange (cHandle, PANEL_WAVET, VAL_MANUAL, 0.0, Xdata[pf]/2,
VAL_AUTOSCALE, 0.0, 1.0);
for(i=0;i<9;i++)
{
SetCtrlVal (cHandle, 52-i, 0.00);
SetCtrlVal (cHandle, 43-i, 0.00);
}
for(i=0;i<9;i++)
{
SetCtrlVal (cHandle, 34-i, 0.00);
SetCtrlVal (cHandle, 25-i, 0.00);
}
lj=0;
}
o=0;
/****************************FFT变换****************************/
if(td==0) //单通道
{
Img1=malloc(filesize/n*sizeof(double));
Ydataa1=(double*)malloc(filesize*2*n);
pydata1=(double*)malloc(filesize*2*n);
zcdata1=(double*)malloc(pf*2*2*n);
zc1=(int*)malloc(pf*2*2);
for(i=0;i<filesize/n;i++)
{Img1=0;
Ydataa1=(double)Ydata;
pydata1=0+(py*n/filesize)*i;
}
Mag1=malloc(filesize/n*sizeof(double));
Phase1=malloc(filesize/n*sizeof(double));
FFT (Ydataa1, Img1, filesize/n);
ToPolar1D (Ydataa1, Img1, filesize/n, Mag1, Phase1);
for(i=0;i<filesize/n;i++)
//Mag1=(20*log10 (Mag1)-20*log10 (0.00002));
Mag1=((Mag1*Mag1+Phase1[1]*Phase1[1])*2*sj)/(filesize/n);
DeleteGraphPlot (cHandle, PANEL_FFTWAVE, -1, VAL_IMMEDIATE_DRAW);
PlotXY (cHandle, PANEL_FFTWAVE, pydata1, Mag1, filesize/n, VAL_DOUBLE, VAL_DOUBLE,
VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE);
SetAxisRange (cHandle, PANEL_FFTWAVE, VAL_MANUAL, 0.0, py/2.56,
VAL_AUTOSCALE, 0.0, 1.0);
for(i=2,j=0;i<pf;i++)
{if(Mag1>Mag1[i-1]&&Mag1>Mag1[i+1]) //&&Mag1[i-1]>Mag1[i-2]&&Mag1[i+1]>Mag1[i+2]
{
zcdata1[j]=Mag1;
zc1[j]=i;
j=j+1;
}}
kt=0;
}
else //、双通道
{
Img1=malloc(filesize/2/n*sizeof(double));
Img2=malloc(filesize/2/n*sizeof(double));
Ydataa1=(double*)malloc(filesize*n);
Ydataa2=(double*)malloc(filesize*n);
pydata1=(double*)malloc(filesize*2*n);
pydata2=(double*)malloc(filesize*2*n);
zcdata1=(double*)malloc(pf*2*2*n);
zc1=(int*)malloc(pf*2*2);
zcdata2=(double*)malloc(pf*2*2*n);
zc2=(int*)malloc(pf*2*2);
for(i=0;i<filesize/2/n;i++)
{Img1=0;
Ydataa1=(double)Ydata1;
Ydataa2=(double)Ydata2;
pydata1=0+(py*n/filesize)*i;
pydata2=0+(py*n/filesize)*i;
}
Mag1=malloc(filesize/2/n*sizeof(double));
Mag2=malloc(filesize/2/n*sizeof(double));
Phase1=malloc(filesize/2/n*sizeof(double));
Phase2=malloc(filesize/2/n*sizeof(double));
FFT (Ydataa1, Img1, filesize/n/2);
FFT (Ydataa2, Img2, filesize/n/2);
ToPolar1D (Ydataa1, Img1, filesize/2/n, Mag1, Phase1);
ToPolar1D (Ydataa2, Img2, filesize/2/n, Mag2, Phase2);
for(i=0;i<filesize/n/2;i++)
{//Mag1=(20*log10 (Mag1)-20*log10 (0.00002));
//Mag2=(20*log10 (Mag1)-20*log10 (0.00002));
Mag1=((Mag1*Mag1+Phase1[1]*Phase1[1])*2*sj)/(filesize/n);
Mag2=((Mag2*Mag2+Phase2[1]*Phase2[1])*2*sj)/(filesize/n);
}
DeleteGraphPlot (cHandle, PANEL_FFTWAVET, -1, VAL_IMMEDIATE_DRAW);
PlotXY (cHandle, PANEL_FFTWAVET, pydata2, Mag2, filesize/2/n, VAL_DOUBLE, VAL_DOUBLE,
VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_GREEN);
SetAxisRange (cHandle, PANEL_FFTWAVET, VAL_MANUAL, 0.0, py/2.56,
VAL_AUTOSCALE, 0.0, 1.0);
return 0;
}
运行是老是说什么? SetCtrlVal (cHandle, 34-i, 0.00); 该地方应该是int,而不是double ?但改过后又是double,而不是int? |
|