___I am trying to get average of number of events between particular range saved in a text file. Every event has 1024 values. My macro is crashing after giving some output averages without error. After giving some output values, all values are coming zero. Here is my code.
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <string>
#include <vector>
#include <dirent.h>
#include <sys/types.h>
using namespace std;
void avg(){
string line;
float time;
ifstream file("wave_7.txt");
ofstream MyFile("filename.txt");
for(int e=0;e<=1831;e++)
{
int l = 1032*e + 9;
for(int i=1;i<l;i++){
getline(file,line);
}
time = 0;
double sum=0.0;
int num=0;
double avg=0.0;
for(int j=1;j<=1024;j++){
getline(file,line);
if(line != "")
{
double dataPoint = std::stod(line);
if(time>=10 && time<=50)
{
sum=sum+dataPoint;
num=num+1;
}
time += 0.2;
if(time>50)
{
avg=sum/num;
break;
}
}
}
//MyFile << s;
cout<<avg<<"\n";
}
// Close the file
MyFile.close();
}
Do i need to add any debug statement? if yes, how and which statement should i add to run it? Please solve this issue.
ROOT Version: 6.24/02
Platform: WSL
Compiler: Not Provided