//*****************************************************************************
// Labwindows/cvi8.5 线性拟合演示仪
// 自行编写
// szlihongtao
// 2010-07-27
//*****************************************************************************
#include <analysis.h>
#include <cvirte.h>
#include <userint.h>
#include "lin.h"
//*****************************************************************************
static int panelHandle;
//*****************************************************************************
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "lin.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
//*****************************************************************************
int CVICALLBACK func_exit (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}
//*****************************************************************************
int CVICALLBACK fit (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
double in[6],out[6],best[6],ftemp,slope,intercept,my;
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (panelHandle, PANEL_IN1, &ftemp);
in[0]=ftemp;
GetCtrlVal (panelHandle, PANEL_IN2, &ftemp);
in[1]=ftemp;
GetCtrlVal (panelHandle, PANEL_IN3, &ftemp);
in[2]=ftemp;
GetCtrlVal (panelHandle, PANEL_IN4, &ftemp);
in[3]=ftemp;
GetCtrlVal (panelHandle, PANEL_IN5, &ftemp);
in[4]=ftemp;
GetCtrlVal (panelHandle, PANEL_OUT1, &ftemp);
out[0]=ftemp;
GetCtrlVal (panelHandle, PANEL_OUT2, &ftemp);
out[1]=ftemp;
GetCtrlVal (panelHandle, PANEL_OUT3, &ftemp);
out[2]=ftemp;
GetCtrlVal (panelHandle, PANEL_OUT4, &ftemp);
out[3]=ftemp;
GetCtrlVal (panelHandle, PANEL_OUT5, &ftemp);
out[4]=ftemp;
LinFit (in, out, 5, best, &slope,&intercept,&my);
SetCtrlVal (panelHandle, PANEL_K, slope);
SetCtrlVal (panelHandle, PANEL_JIEJU, intercept);
SetCtrlVal (panelHandle, PANEL_BEST1, best[0]);
SetCtrlVal (panelHandle, PANEL_BEST2, best[1]);
SetCtrlVal (panelHandle, PANEL_BEST3, best[2]);
SetCtrlVal (panelHandle, PANEL_BEST4, best[3]);
SetCtrlVal (panelHandle, PANEL_BEST5, best[4]);
DeleteGraphPlot (panelHandle, PANEL_GRAPH, -1, VAL_IMMEDIATE_DRAW);
PlotXY (panelHandle, PANEL_GRAPH, in, out, 5, VAL_DOUBLE, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
PlotXY (panelHandle, PANEL_GRAPH, in, best, 5, VAL_DOUBLE, VAL_DOUBLE, VAL_THIN_LINE, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_BLUE);
break;
}
return 0;
}
//*****************************************************************************
//*****************************************************************************
//*****************************************************************************
文章评论(0条评论)
登录后参与讨论