Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

stats.c File Reference

#include "precomp.h"
#include "stats.h"

Go to the source code of this file.

Functions

BOOL Get_Stats (double *array, long num_samples, const filter_option, long var_limit, PTEST_STATS stats)
BOOL GetAverage (double Sample_Array[], long No_Samples, double *Average)
BOOL GetStdDev (double Sample_Array[], double Average, long No_Samples, double *varcoef)
void SortUp (double *array, long array_size)
BOOL FilterResults (double Sorted_Array[], double *tmpAverage, double *tmpSD, long *tmpNumSamples, long limit, const filter_option)


Function Documentation

BOOL FilterResults double  Sorted_Array[],
double *  tmpAverage,
double *  tmpSD,
long *  tmpNumSamples,
long  limit,
const  filter_option
 

Definition at line 280 of file stats.c.

References FALSE, GetStdDev(), HI_FILTER, HI_LO_FILTER, LO_FILTER, and TRUE.

Referenced by Get_Stats().

00287 { 00288 00289 00290 switch (filter_option) 00291 { 00292 case HI_FILTER: 00293 { 00294 while(*tmpSD > (double)limit) 00295 { 00296 00297 if(*tmpNumSamples <= 2)return FALSE; 00298 00299 (*tmpAverage) *= (*tmpNumSamples); 00300 (*tmpAverage) -= Sorted_Array[(*tmpNumSamples) - 1]; 00301 (*tmpNumSamples)--; 00302 (*tmpAverage) /= (*tmpNumSamples); 00303 00304 GetStdDev(Sorted_Array, *tmpAverage, *tmpNumSamples, &(*tmpSD)); 00305 00306 } 00307 00308 if(*tmpSD < 0)return FALSE; 00309 } 00310 break; 00311 00312 case LO_FILTER: 00313 { 00314 00315 while(*tmpSD > (double)limit) 00316 { 00317 00318 if(*tmpNumSamples <= 2)return FALSE; 00319 00320 (*tmpAverage) *= (*tmpNumSamples); 00321 (*tmpAverage) -= (*Sorted_Array); 00322 Sorted_Array++; 00323 (*tmpNumSamples)--; 00324 (*tmpAverage) /= (*tmpNumSamples); 00325 00326 GetStdDev(Sorted_Array, *tmpAverage, *tmpNumSamples, &(*tmpSD)); 00327 00328 } 00329 00330 if(*tmpSD < 0)return FALSE; 00331 00332 } 00333 break; 00334 00335 case HI_LO_FILTER: 00336 { 00337 00338 while(*tmpSD > (double)limit) 00339 { 00340 00341 if(*tmpNumSamples <= 2)return FALSE; 00342 00343 if(fabs((*Sorted_Array) - (*tmpAverage)) > fabs(Sorted_Array[*tmpNumSamples - 1] - *tmpAverage)) 00344 { 00345 (*tmpAverage) *= (*tmpNumSamples); 00346 (*tmpAverage) -= (*Sorted_Array); 00347 Sorted_Array++; 00348 } 00349 else 00350 { 00351 (*tmpAverage) *= (*tmpNumSamples); 00352 (*tmpAverage) -= Sorted_Array[(*tmpNumSamples) - 1]; 00353 } 00354 00355 (*tmpNumSamples)--; 00356 (*tmpAverage) /= (*tmpNumSamples); 00357 00358 GetStdDev(Sorted_Array, *tmpAverage, *tmpNumSamples, &(*tmpSD)); 00359 00360 } 00361 00362 if(*tmpSD < 0)return FALSE; 00363 00364 } 00365 break; 00366 00367 default: 00368 return FALSE; 00369 00370 } //switch filter_option 00371 00372 return TRUE; 00373 00374 }

BOOL Get_Stats double *  array,
long  num_samples,
const  filter_option,
long  var_limit,
PTEST_STATS  stats
 

Definition at line 61 of file stats.c.

References _TEST_STATS::Average, FALSE, FilterResults(), GetAverage(), GetStdDev(), _TEST_STATS::Maximum_Result, _TEST_STATS::Minimum_Result, NO_FILTER, _TEST_STATS::NumSamplesValid, PTEST_STATS, SortUp(), _TEST_STATS::StdDev, and TRUE.

Referenced by WndProc().

00068 { 00069 00070 double Averagetmp; 00071 double StdDevtmp; 00072 long NumSamplestmp; 00073 00074 if(!GetAverage(array, num_samples, &Averagetmp)) 00075 return FALSE; 00076 00077 SortUp(array, num_samples); 00078 00079 if(!GetStdDev(array, Averagetmp, num_samples, &StdDevtmp)) 00080 return FALSE; 00081 00082 stats->Minimum_Result = array[0]; 00083 stats->Maximum_Result = array[num_samples - 1]; 00084 00085 if(filter_option == NO_FILTER) 00086 { 00087 stats->Average = Averagetmp; 00088 stats->StdDev = StdDevtmp; 00089 stats->NumSamplesValid = num_samples; 00090 return TRUE; 00091 } 00092 00093 00094 NumSamplestmp = num_samples; 00095 if(!FilterResults(array,&Averagetmp,&StdDevtmp,&NumSamplestmp,var_limit,filter_option)) 00096 return FALSE; 00097 00098 stats->Average = Averagetmp; 00099 stats->StdDev = StdDevtmp; 00100 stats->NumSamplesValid = NumSamplestmp; 00101 return TRUE; 00102 00103 }

BOOL GetAverage double  Sample_Array[],
long  No_Samples,
double *  Average
 

Definition at line 126 of file stats.c.

References FALSE, and TRUE.

Referenced by Get_Stats().

00130 { 00131 long i; 00132 (*Average) = 0.0; 00133 00134 if(No_Samples == 0)return FALSE; 00135 00136 for(i = 0; i < No_Samples; i++) 00137 { 00138 (*Average) += Sample_Array[i]; 00139 } 00140 00141 (*Average) /= No_Samples; 00142 00143 return TRUE; 00144 00145 }

BOOL GetStdDev double  Sample_Array[],
double  Average,
long  No_Samples,
double *  varcoef
 

Definition at line 172 of file stats.c.

References FALSE, L, Sum, and TRUE.

Referenced by FilterResults(), and Get_Stats().

00177 { 00178 long i; 00179 double tmp; 00180 double Sum = 0.0; 00181 00182 if(No_Samples <= 1L) 00183 { 00184 return FALSE; 00185 } 00186 00187 for(i=0; i<No_Samples; i++) 00188 { 00189 tmp = (Sample_Array[i] - Average); 00190 Sum += (tmp*tmp); 00191 } 00192 00193 Sum /= (No_Samples - 1); 00194 00195 if(fabs( (float)Average) < 1.E-6) 00196 { 00197 *varcoef = (-sqrt(Sum)); // return the Standard Deviation itself in negative sign for distinction 00198 } 00199 else 00200 { 00201 *varcoef = (100*sqrt(Sum)/Average); // return the variation coeficient in percents 00202 } 00203 00204 return TRUE; 00205 }

void SortUp double *  array,
long  array_size
 

Definition at line 226 of file stats.c.

Referenced by Get_Stats().

00229 { 00230 long gap, i, j; 00231 double temp; 00232 00233 for(gap = array_size/2; gap > 0; gap /= 2) 00234 for(i = gap; i < array_size; i++) 00235 for(j = i - gap; j >= 0 && array[j] > array[j + gap]; j -= gap) 00236 { 00237 temp = array[j]; 00238 array[j] = array[j + gap]; 00239 array[j + gap] = temp; 00240 } 00241 00242 }


Generated on Sat May 15 19:45:40 2004 for test by doxygen 1.3.7