simple example which calculates mean and standard deviation of values in a file read from disk
#include <bias_config.h>
#include <math.h>
#include <Base/Debug/Debug.hh>
#include <Base/Debug/Error.hh>
#include <iostream>
#include <Base/Common/BIASpragma.hh>
using namespace BIAS;
using namespace std;
int main(int argc, char *argv[])
{
if (argc<3) {
cerr << "Not enough parameters given!" << endl;
cout << "Usage: ExampleMeanAndDev [file name] [columns]" << endl;
exit(0);
}
FILE* myfile = fopen(argv[1], "r");
const int column = atoi(argv[2]);
char thestring[1024];
int nummeasurements = 0;
float *value = new float[column];
double valuesum=0,mean=0;
while (fgets(thestring, 1020, myfile)) {
if (sscanf(thestring, "%f %f %f",&(value[0]),&(value[1]),&(value[2])) <
column) continue;
nummeasurements++;
valuesum += value[column-1];
}
fclose(myfile);
mean = valuesum / double(nummeasurements);
myfile = fopen(argv[1], "r");
nummeasurements = 0;
valuesum = 0;
while (fgets(thestring, 1020, myfile)) {
if (sscanf(thestring, "%f %f %f",&(value[0]),&(value[1]),&(value[2])) <
column) continue;
nummeasurements++;
valuesum += (mean-value[column-1]) * (mean-value[column-1]);
}
valuesum /= double(nummeasurements-1);
cout<<"Mean is "<< mean << " and dev is "<<sqrt(valuesum)<<" on "
<<nummeasurements<<" measurements"<<endl;
fclose(myfile);
return 0;
}