delete the last and first line in an interval

hey all
well I have been facing this problem for days and I don't seem to get an answer to it. I have written a code where my program is suppose to read specific number of lines within different ranges and then count the number of occurrence of r and s and divide the r by the s. here's a snap shot of my trace file I am working on


s 167.204369958 _7_ MAC  --- 29867 tcp 630 [13a 8 7 800] ------- [7:2 8:1 32 8] [330 0] 0 1..
r 167.209410087 _8_ MAC  --- 29867 tcp 572 [13a 8 7 800] ------- [7:2 8:1 32 8] [330 0] 1 1..
s 167.212674795 _7_ MAC  --- 29868 tcp 630 [13a 8 7 800] ------- [7:2 8:1 32 8] [331 0] 0 1..
r 167.217714923 _8_ MAC  --- 29868 tcp 572 [13a 8 7 800] ------- [7:2 8:1 32 8] [331 0] 1 1..
D 167.240723594 _8_ MAC  BSY 0 RTS 44 [162e 8 7 0] ..
D 167.243783594 _8_ MAC  BSY 0 RTS 44 [162e 8 7 0] ..
s 169.998902881 _7_ MAC  --- 30344 tcp 630 [13a 8 7 800] ------- [7:3 9:0 32 8] [147 0] 0 1..
r 170.003942963 _8_ MAC  --- 30344 tcp 572 [13a 8 7 800] ------- [7:3 9:0 32 8] [147 0] 1 1..
s 170.162989092 _7_ MAC  --- 30466 tcp 630 [13a 8 7 800] ------- [7:2 8:1 32 8] [334 0] 0 1..
r 170.168029172 _8_ MAC  --- 30466 tcp 572 [13a 8 7 800] ------- [7:2 8:1 32 8] [334 0] 1 1..
s 170.181482383 _7_ MAC  --- 30467 tcp 630 [13a 8 7 800] ------- [7:2 8:1 32 8] [335 0] 0 1..
r 170.186522463 _8_ MAC  --- 30467 tcp 572 [13a 8 7 800] ------- [7:2 8:1 32 8] [335 0] 1 1..
s 178.013133357 _7_ MAC  --- 32131 tcp 630 [13a 8 7 800] ------- [7:2 8:1 32 8] [340 0] 0 1..
r 180.725285180 _8_ MAC  --- 32716 tcp 572 [13a 8 7 800] ------- [7:2 8:1 32 8] [341 0] 1 1..

The program is running correctly but the problem takes place in such cases

s 169.998902881 _7_ MAC  --- 30344 tcp 630 [13a 8 7 800] ------- [7:3 9:0 32 8] [147 0] 0 1..
r 170.003942963 _8_ MAC  --- 30344 tcp 572 [13a 8 7 800] ------- [7:3 9:0 32 8] [147 0] 1 1..

where the s line is at the end of interval and the r line is received at the beginning of the second interval ...giving incorrect counting because in the second interval the received line will be greater than the send lines which gives a % higher than 100 which is incorrect.
I thought about checking if the s is followed by r within the interval if not delete the line and another check was to check for the sequence number which is this number 30344 this number should be equal for each r-s pair

here's my code


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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
  #include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>

    using namespace std;

int main()
{
    ofstream fout("TPDR[3-4-30].tr");
    ifstream fin("TTEST.tr");// if u use this as ur input file u will always get ur num as 6 because the range stops at 50 therefore u will get the throughputs calculated as 0z 
    ofstream fOut("TPDR30(3-4).tr");
    ofstream MYFILE("TPDR(3-4).tr");
    
    if (!fin)
    {
        cout << "input file not open" << endl;
        return 1;
    }

    fout << fixed << setprecision(9);
    fOut << fixed << setprecision(9);
    cout << fixed << setprecision(9);
    MYFILE << fixed << setprecision(9);

    double timelimit = 0.0;    // ending time of first block of data
    double timeincr  = 10.0;   // duration of each block of data

    string s1, s2, s3, sequenceno1,sequenceno2, s4, s5; // dummy variables to hold unwanted data 
    string line,oldline;
    
    char   type;   
    double time;   
    int    bytes;  
    int num = 0;
    istringstream ss;
    double received[21] = {0.0}; 
    double send[21] = {0.0}; 
    int drop[21] = {0}; 
    double Re[21]= {0.0};
    double Se[21] = {0.0};
    double De[21] = {0.0};
     int R = 0;
     int S = 0;
    double PDR =0.0;
    double PDRR[21] = {0.0};
    int Range; 
   
     
    //------- Priming read. Get first line.
    getline(fin, line);
    ss.str(line);
    ss >> type >> time;

    while (fin)
    {
        while (ss && time <= timelimit)
        {
			 
            //------------- process the line here ------------------
                 // ss >> s1 >> s2  >> s3 >> s4 >> s5 ;
                   
                             
                                
         if (type == 's') {
									  
		          ss >> s1 >> s2 >> s3 >> sequenceno1 >> s4 >> s5;
					  oldline = line;
					  send[num]++; 
					  S = send[num]; 
					  Se[num] = S; 
				  }
					  
					                  
               if (type =='r') {
					
					  ss >> s1 >> s2 >> s3 >> sequenceno2 >> s4 >> s5;
				  if ((time < timelimit)&&(sequenceno1 == sequenceno2)) {
					  cout << sequenceno1 << "   " << sequenceno2 << "    " << time << "    " << timelimit << ".\n";
				     received[num]++;
					 R = received[num];
					 Re[num] = R;
					 PDR = Re[num]/ Se[num];
					 PDRR[num] = PDR*100;
	
	fout << "Received = " << Re[num] <<"     " << time <<"    " << "Send= " << Se[num] << "  " << "Packet Delivery Ratio" << PDRR[num]  << "    "<< "sequenceno1 =" << sequenceno1 << "      "<< "sequenceno2 ="  << sequenceno2 << ".\n"; 
		
		
                }
        
                }
         
            //------------- end of process, now read the next line -----

            if (getline(fin, line))
            {
                ss.clear();             // clear all flags
                ss.str(line);
                ss >> type >> time;
            }
            else
            {
                ss.clear(ios::failbit); // set the fail flag
         
            }
            
        }
        
        

        timelimit += timeincr; // increment limit to next value
        cout << timelimit << ".\n\n";
        num++; 
        fout << "\n------------------\n";
        fout << "time limit: " << timelimit << endl;
        cout << "num = " << num << ".\n";
    } 
    
   // ..... Writting the Range and PDR within each Range in a separate File .....
   
for (Range = 10,num =1; Range <= 200, num <=20; Range+=10, num++) {
	fOut << Range << "     " << PDRR[num] << ".\n";
 } 
 
 double average = 0.0;
 double TPDR = 0.0;
 
 for (num = 1; num <=20 ; num++) {   // For loop to compute the Total PDR within each Range 
	 TPDR += PDRR[num]; 
	// cout << "TPDR" << TPDR << "%" << ".\n"; 
 }
 
 average = TPDR /(num-1);
 cout << "average = " << average << "%" <<  ".\n";// Compute Average PDR 
 
    cout << "Done" << endl;
    return 0;
}


here's the output


time limit: 180.000000000
r 170.003942963 _8_ MAC  --- 30344 tcp 572 [13a 8 7 800] ------- [7:3 9:0 32 8] [147 0] 1 1...
s 169.998902881 _7_ MAC  --- 30344 tcp 630 [13a 8 7 800] ------- [7:3 9:0 32 8] [147 0] 0 1...

don't know y is it comparing with the s from previous interval ?
Not logic output

Received = 1.000000000     170.003942963    Send= 0.000000000  Packet Delivery Ratioinf    sequenceno1 =30344      sequenceno2 =30344.

plz help me out
@chervil can u plz help me out
Topic archived. No new replies allowed.