Reading a specific range in a file

hey all
I am trying to read a specific range in a file and perform on it a certain calculation. I tried to specify the range using if condition

if (b > 0 && b <= 10 )
Calculate The throughput1
if (b > 10 && b <=20 )
Calculate the throughput2 

Throughput is calculated using the same equation
and so on my file stops at 150s. After getting the throughput of each range I should add them up to compute their average. AT the end I should print out in a separate file
10 throughput1 =
20 throughput2 =
and so on.

The problem is that the program is really long, my throughput is looped, Any ideas how can I do it in an easier way. plz help me. Here's what I have done so far
thanx in advance
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <cmath>
#include <cstdio>
using namespace std;

int main() {
    char c;
    string line;
    int numlines = 0, sum = 0,num, h,ze;
    double b, S, T,time = 0.0;
    string m,d,e,f,g,q,i,o,j,k,l,y,n,p,r,z,x,w;
    double Tp = 0.0, Thput = 0.0,Throughput = 0.0;
   
ifstream myfile ("RN1-9.tr");
ofstream MYFILE("TvThr.tr");
ofstream MF("Bcheck.tr");
//ifstream myfile ("New1-9.tr");
if(myfile.is_open()) {
while (getline(myfile,line)) {
	numlines++;
	istringstream input(line);
    input >> c >> b >> m >> d >> e >> f >> g >> h >> q >> i >> o >> j>> k;
	
   if (b > 11.0 && b <21.0 ) {
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(9);
	MF << "b=" << b << ".\n";
if (c== 'r')
	sum = sum + h;
//cout << "sum =" << sum << ".\n";
	switch (c)
	{
		case 's':
		T = b;
		break;
		
		case 'r' :
		S = b- T;
		cout << "S(ze)= " << S << ".\n";
		time = time + S;
		cout << "Total Time =" << time << ".\n";
		break;	
	}	
}
Tp = sum * 8;
cout << "Bits =" << Tp << ".\n";
Thput = Tp /(time); 
Throughput = Thput/1000000;
MYFILE << "10 " << " " << Throughput << "Mbps" <<".\n";


if (b > 21 && b <31.0 ) {
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(9);
	MF << "b=" << b << ".\n";
if (c== 'r')
	sum = sum + h;
//cout << "sum =" << sum << ".\n";
	switch (c)
	{
		case 's':
		T = b;
		break;
		
		case 'r' :
		S = b- T;
		cout << "S(ze)= " << S << ".\n";
		time = time + S;
		cout << "Total Time =" << time << ".\n";
		break;	
	}	
}

Tp = sum * 8;
cout << "Bits =" << Tp << ".\n";
Thput = Tp /(time); 
Throughput = Thput/1000000;
MYFILE << "20 " << " " << Throughput << "Mbps" <<".\n";

 
}
myfile.close();
}

else cout << "Unable to open file";


return 0;
}

here's a snap shot of the file I am working on.

s 11.028519653 _1_ MAC  --- 13 tcp 118 [ba 9 1 800] ------- [1:1 9:0 32 9] [0 0] 0 0.
r 11.029335769 _9_ MAC  --- 13 tcp 60 [ba 9 1 800] ------- [1:1 9:0 32 9] [0 0] 1 0.
s 11.147216817 _1_ MAC  --- 55 tcp 1118 [ba 9 1 800] ------- [1:1 9:0 32 9] [1 0] 0 0.
s 11.226461648 _1_ MAC  --- 55 tcp 1118 [ba 9 1 800] ------- [1:1 9:0 32 9] [1 0] 0 0.
r 11.235277743 _9_ MAC  --- 55 tcp 1060 [ba 9 1 800] ------- [1:1 9:0 32 9] [1 0] 1 0.
s 11.280090956 _1_ MAC  --- 56 tcp 1118 [ba 9 1 800] ------- [1:1 9:0 32 9] [2 0] 0 0.
r 11.288907047 _9_ MAC  --- 56 tcp 1060 [ba 9 1 800] ------- [1:1 9:0 32 9] [2 0] 1 0.
s 11.480615106 _1_ MAC  --- 116 tcp 1118 [ba 9 1 800] ------- [1:1 9:0 32 9] [3 0] 0 0.
r 11.489431193 _9_ MAC  --- 116 tcp 1060 [ba 9 1 800] ------- [1:1 9:0 32 9] [3 0] 1 0.
s 11.507915092 _1_ MAC  --- 117 tcp 1118 [ba 9 1 800] ------- [1:1 9:0 32 9] [4 0] 0 0.
r 11.516731179 _9_ MAC  --- 117 tcp 1060 [ba 9 1 800] ------- [1:1 9:0 32 9] [4 0] 1 0.
Last edited on
Topic archived. No new replies allowed.