58 main(
int argc,
char** argv) {
63 oc.
setApplicationName(
"emissionsDrivingCycle",
"Eclipse SUMO emissionsDrivingCycle Version " VERSION_STRING);
70 oc.
addDescription(
"timeline-file",
"Input",
"Defines the file to read the driving cycle from.");
73 oc.
addSynonyme(
"timeline.skip",
"timeline-file.skip");
74 oc.
addDescription(
"timeline-file.skip",
"Input",
"Skips the firs NUM lines.");
77 oc.
addSynonyme(
"timeline.separator",
"timeline-file.separator");
78 oc.
addDescription(
"timeline-file.separator",
"Input",
"Defines the entry separator.");
83 oc.
addDescription(
"netstate-file",
"Input",
"Defines the netstate, route and trajectory files to read the driving cycles from.");
86 oc.
addDescription(
"emission-class",
"Input",
"Defines for which emission class the emissions shall be generated. ");
91 oc.
addDescription(
"compute-a",
"Processing",
"If set, the acceleration is computed instead of being read from the file. ");
94 oc.
addDescription(
"compute-a.forward",
"Processing",
"If set, the acceleration for time t is computed from v(t+1) - v(t) instead of v(t) - v(t-1). ");
97 oc.
addDescription(
"compute-a.zero-correction",
"Processing",
"If set, the acceleration for time t is set to 0 if the speed is 0. ");
100 oc.
addDescription(
"skip-first",
"Processing",
"If set, the first line of the read file is skipped.");
103 oc.
addDescription(
"kmh",
"Processing",
"If set, the given speed is interpreted as being given in km/h.");
106 oc.
addDescription(
"have-slope",
"Processing",
"If set, the fourth column is read and used as slope (in deg).");
109 oc.
addDescription(
"slope",
"Processing",
"Sets a global slope (in deg) that is used if the file does not contain slope information.");
114 oc.
addDescription(
"output",
"Output",
"Defines the file to write the emission cycle results into. ");
117 oc.
addDescription(
"emission-output",
"Output",
"Save the emission values of each vehicle in XML");
121 oc.
addDescription(
"sum-output",
"Output",
"Save the aggregated and normed emission values of each vehicle in CSV");
125 oc.
addDescription(
"phemlight-path",
"Emissions",
"Determines where to load PHEMlight definitions from.");
145 if (!oc.
isSet(
"timeline-file") && !oc.
isSet(
"netstate-file")) {
146 throw ProcessError(
"Either a timeline or a netstate / amitran file must be given.");
148 if (!oc.
isSet(
"output-file") && (oc.
isSet(
"timeline-file") || !oc.
isSet(
"emission-output"))) {
151 std::ostream* out =
nullptr;
152 if (oc.
isSet(
"output-file")) {
153 out =
new std::ofstream(oc.
getString(
"output-file").c_str());
157 if (oc.
isSet(
"emission-output")) {
159 }
else if (out ==
nullptr) {
162 std::ostream* sumOut =
nullptr;
163 if (oc.
isSet(
"sum-output")) {
164 sumOut =
new std::ofstream(oc.
getString(
"sum-output").c_str());
165 (*sumOut) <<
"Vehicle,Cycle,Time,Speed,Gradient,Acceleration,FC,FCel,CO2,NOx,CO,HC,PM" << std::endl;
169 const bool computeA = oc.
getBool(
"compute-a") || oc.
getBool(
"compute-a.forward");
172 if (oc.
isSet(
"timeline-file")) {
173 int skip = oc.
getBool(
"skip-first") ? 1 : oc.
getInt(
"timeline-file.skip");
174 const bool inKMH = oc.
getBool(
"kmh");
175 const bool haveSlope = oc.
getBool(
"have-slope");
211 throw ProcessError(
"Missing an entry in line '" + line +
"'.");
213 throw ProcessError(
"Not numeric entry in line '" + line +
"'.");
218 std::cout <<
"sums" << std::endl
219 <<
"length:" << l << std::endl;
221 if (sumOut !=
nullptr) {
223 << (l / time * 3.6) <<
"," << (totalS / time) <<
"," << (totalA / time) <<
",";
227 if (oc.
isSet(
"netstate-file")) {
239 if (std::string(e.what()) != std::string(
"Process Error") && std::string(e.what()) != std::string(
"")) {
251 if (ret == 0 && !quiet) {
252 std::cout <<
"Success." << std::endl;
std::vector< std::string > StringVector
Definition of a vector of strings.
Retrieves a file linewise and reports the lines to a handler.
bool readLine(LineHandler &lh)
Reads a single (the next) line from the file and reports it to the given LineHandler.
bool hasMore() const
Returns whether another line may be read (the file was not read completely)
std::string getFileName() const
Returns the name of the used file.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
A storage for options typed value containers)
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Static storage of an output device and its base (abstract) implementation.
static bool createDeviceByOption(const std::string &optionName, const std::string &rootElement="", const std::string &schemaFile="")
Creates the device using the output definition stored in the named option.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
bool hasNext()
returns the information whether further substrings exist
std::string next()
returns the next substring when it exists. Otherwise the behaviour is undefined
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static std::string prune(const std::string &str)
Removes trailing and leading whitechars.
static void close()
Closes all of an applications subsystems.
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
An XML-Handler for amitran and netstate trajectories.
void writeNormedSums(std::ostream &o, const std::string id, const double factor)
void writeSums(std::ostream &o, const std::string id)
static const int INVALID_VALUE
bool writeEmissions(std::ostream &o, const std::string id, const SUMOEmissionClass c, double t, double &v, double &a, double &s)
static void init()
Initialises the xml-subsystem.
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false, const bool isRoute=false)
Runs the given handler on the given file; returns if everything's ok.
int main(int argc, char **argv)