Code Snippet
#include <stdlib.h>
#include <windows.h> /* Compiler's include files's */
#include <string.h>
#include <stdio.h>
HWND hWndMain; /* handle for main window */
LONG FAR PASCAL MainMessageHandler (HWND, UINT, WPARAM, LPARAM);
int PASCAL
WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR CmdLine, int nCmdShow)
{
}
void bubbleSort(int numbers[], int array_size);
struct Sensor
{
int nr,n,a;
float d;
double s1,s2,s3,s4;
};
LONG FAR PASCAL
MainMessageHandler(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
HDC hDC; /* handle for the display device */
PAINTSTRUCT ps; /* holds PAINT information */
TEXTMETRIC tm; /* holds TEXT information */
static HRGN hRgn; /* Rectangle region Handles */
static int CharWidth, CharHeight;
static unsigned short DataVal, DataVal1, DataVal2, DataVal3;
static unsigned long DataVal0, DataVal10, DataVal20, DataVal30;
struct Sensor s[100];
int i, j,n,nr;
double Sys_[4][5];
double b_[4];
double z_[5];
int s11,s12,s13,s14;
int d,s1,s2,s3,s4;
int lam2,lam3,lam4,lam5;
FILE *fp;
fp = fopen("Data2.txt", "r");
for ( i = 1; i<=100; i ++)
{
fscanf(fp, "%d %f %d %d %d %d ", &(s[i].nr), &(s[i].d), &(s[i].s1), &(s[i].s2), &(s[i].s3), &(s[i].s4));
}
switch (Message) /* Windows Message Loop */
{
case WM_PAINT: /* Repaint client area of window */
hDC = BeginPaint(hWndMain, &ps);
x = CharWidth * 2; /* Position cursor within window */
y = CharHeight; /* One line down and 2 chars in */
TextOut(hDC, x, y, str, strlen (str));
y += CharHeight; /* Print current index */
cbAIn (BOARD_NUM, 0, ADRANGE, &DataVal);
cbAIn (BOARD_NUM, 1, ADRANGE, &DataVal1);
cbAIn (BOARD_NUM, 2, ADRANGE, &DataVal2);
cbAIn (BOARD_NUM, 3, ADRANGE, &DataVal3);
mu = t / ( t + 3 );
DataVal0 = (double)mu * ( (double)DataVal - (double)DataVal0 ) + DataVal0;
DataVal10 = (double)mu * ( (double)DataVal1 - (double)DataVal10 ) + DataVal10;
DataVal20 = (double)mu * ( (double)DataVal2 - (double)DataVal20 ) + DataVal20;
DataVal30 = (double)mu * ( (double)DataVal3 - (double)DataVal30 ) + DataVal30;
for ( i = 0 ; i <= 100 ;i++ )
{
s[i].a = ( ( s[i].s1 -DataVal0) * (s[i].s1 - DataVal0 ) + (s[i].s2 - DataVal10 )*( s[i].s2 - DataVal10 ) + (s[i].s3 - DataVal20) * (s[i].s3-DataVal20) + ( s[i].s4 - DataVal20 ) * ( s[i].s4 - DataVal20 ) );
}
y += CharHeight*2; /* Print raw data value */
sprintf (OutString,"Sensor0 = %f ", s[1].a);
TextOut(hDC, x, y, OutString, strlen (OutString));
y += CharHeight*2; /* Print raw data value */
sprintf (OutString,"Sensor1 = %u ", s[2].a);
TextOut(hDC, x, y, OutString, strlen (OutString));
y += CharHeight*2; /* Print raw data value */
sprintf (OutString,"Sensor2 = %u ", s[3].a);
TextOut(hDC, x, y, OutString, strlen (OutString));
y += CharHeight*2; /* Print raw data value */
sprintf (OutString,"Sensor3 = %u ", s[4].a);
TextOut(hDC, x, y, OutString, strlen (OutString));
SetTextAlign(hDC, TA_LEFT | TA_TOP);
EndPaint(hWndMain, &ps);
break;
return (0l);
}
void bubbleSort(int numbers[], int array_size)
{
int i, j, temp;
for (i = (array_size - 1); i >= 0; i--)
{
for (j = 1; j <= i; j++)
{
if (numbers[j-1] > numbers[j])
{
temp = numbers[j-1];
numbers[j-1] = numbers[j];
numbers[j] = temp;
}
}
}
}