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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
struct OldNew
{
float Old, New;
};
struct Data
{
OldNew Time,x,y,z,distance,speed;
};
void SkipHeaderInfo(ifstream &Traj, int count);
void ReadData(ifstream &Traj,Data &data);
void WriteDistance(Data data, ofstream &dist);
void WriteSpeed(Data data, ofstream &spd);
void Distance(Data &data);
void UpdateOldStruct(Data &data);
void Speed(Data &data);
float msTokmh(float max_speed);
void MaxSpeed(Data data, float &max_speed, float &TimeOfMaxSpeed);
void TimeinTraffice(Data data, float &TimeInTraffic);
void Report(float max_speed, float TimeOfMaxSpeed,float Traveltime,float TimeInTraffic,ofstream &rpt);
int main()
{
ifstream Traj;
ofstream dist;
ofstream spd;
string Speed_name="Speed.txt";
ofstream rpt;
string Report_name="Report.txt";
Data data;
float max_speed=0,TimeOfMaxSpeed=0,TimeInTraffic=0,Traveltime=0;
int count=0;
data.Time.Old=0;
data.Time.New=0;
data.distance.Old=0;
data.distance.New=0;
data.x.New=0;
data.x.Old=0;
data.y.New=0;
data.y.Old=0;
data.z.New=0;
data.z.Old=0;
for(int i=0; i<100; i++)
{
Traj.open("VehicleTrajectory.txt");
SkipHeaderInfo(Traj, count);
count++;
ReadData(Traj, data); //fills New spot in struct OldNew
Distance(data); //calculates distance from x,y and z
UpdateOldStruct(data); //fills old spot in struct OldNew
Traj.close();
WriteDistance(data, dist);
}
WriteSpeed(data, spd);
Speed(data);
msTokmh(max_speed);
MaxSpeed(data, max_speed, TimeOfMaxSpeed);
TimeinTraffice(data, TimeInTraffic);
Report(max_speed, TimeOfMaxSpeed, Traveltime, TimeInTraffic, rpt);
}
void SkipHeaderInfo(ifstream &Traj, int count) // This function skips past the first lines of the input file
{
const int max_skip = 13;
for(int i=0; i<(max_skip + count); i++)
{
Traj.ignore(200,'\n');
}
}
void ReadData(ifstream &Traj,Data &data) // This function reads one line from the input data file, at the current position of the input file stream and
// updates Data.xxx.New
{
Traj>> data.Time.New;
Traj>> data.x.New;
Traj>> data.y.New;
Traj>> data.z.New;
}
void UpdateOldStruct(Data &data) //This function updates the values
//of xx.Old by replacing them by xx.New
{
data.Time.Old+= data.Time.New;
data.distance.Old+= data.distance.New;
data.x.Old= data.x.New;
data.y.Old= data.y.New;
data.z.Old= data.z.New;
}
void Distance(Data &data) //This function computes and updates the accumulated distance traveled.
{
data.distance.New= sqrt(pow((data.x.New - data.x.Old),2) + pow((data.y.New - data.y.Old),2) + pow((data.z.New - data.z.Old),2));
}
void WriteDistance(Data data, ofstream &dist) //This function writes one line to the âDistance.txtâ
{
string Distance_name="Distance.txt";
dist.open(Distance_name.c_str());
for(int i=0; i<100; i++)
{
dist << data.Time.Old<< " " << data.distance.Old << endl;
}
dist.close();
}
void WriteSpeed(Data data, ofstream &spd) //This function writes one line to the âSpeed.txtâ
{
}
void Speed(Data &data) //This function computes and updates the speed of vehicle by numerically differentiating the âDistanceâ
{
}
float msTokmh(float max_speed) //This function converts (m/s) to (km/h) and returns the value
{
int KMH=0;
return KMH;
}
void MaxSpeed(Data data, float &max_speed, float &TimeOfMaxSpeed) //This function updates the maximum speed (max_speed)
//and its time of occurrence (TimeOfMaxSpeed).
{
}
void TimeinTraffice(Data data, float &TimeInTraffic) //This function updates the TimeInTraffic
//which is the duration of time for which
//the speed of the vehicle < 0.05 m/s
{
}
void Report(float max_speed, float TimeOfMaxSpeed,float Traveltime,float TimeInTraffic,ofstream &rpt) // This function generates the âReport.txtâ
//Note that an output file
//stream object (rpt) is passed
//to this function as an argument.
{
}
|