60 main(
int argc,
char** argv) {
65 oc.
setApplicationName(
"emissionsDrivingCycle",
"Eclipse SUMO emissionsDrivingCycle Version " VERSION_STRING);
72 oc.
addDescription(
"timeline-file",
"Input",
"Defines the file to read the driving cycle from.");
75 oc.
addSynonyme(
"timeline.skip",
"timeline-file.skip");
76 oc.
addDescription(
"timeline-file.skip",
"Input",
"Skips the firs NUM lines.");
79 oc.
addSynonyme(
"timeline.separator",
"timeline-file.separator");
80 oc.
addDescription(
"timeline-file.separator",
"Input",
"Defines the entry separator.");
85 oc.
addDescription(
"netstate-file",
"Input",
"Defines the netstate, route and trajectory files to read the driving cycles from.");
88 oc.
addDescription(
"additional-files",
"Input",
"Load emission parameters (vTypes) from FILE(s)");
91 oc.
addDescription(
"emission-class",
"Input",
"Defines for which emission class the emissions shall be generated. ");
94 oc.
addDescription(
"vtype",
"Input",
"Defines the vehicle type to use for emission parameters.");
98 oc.
addDescription(
"compute-a",
"Processing",
"If set, the acceleration is computed instead of being read from the file. ");
101 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). ");
104 oc.
addDescription(
"compute-a.zero-correction",
"Processing",
"If set, the acceleration for time t is set to 0 if the speed is 0. ");
107 oc.
addDescription(
"skip-first",
"Processing",
"If set, the first line of the read file is skipped.");
110 oc.
addDescription(
"kmh",
"Processing",
"If set, the given speed is interpreted as being given in km/h.");
113 oc.
addDescription(
"have-slope",
"Processing",
"If set, the fourth column is read and used as slope (in deg).");
116 oc.
addDescription(
"slope",
"Processing",
"Sets a global slope (in deg) that is used if the file does not contain slope information.");
121 oc.
addDescription(
"output",
"Output",
"Defines the file to write the emission cycle results into. ");
124 oc.
addDescription(
"emission-output",
"Output",
"Save the emission values of each vehicle in XML");
128 oc.
addDescription(
"sum-output",
"Output",
"Save the aggregated and normed emission values of each vehicle in CSV");
132 oc.
addDescription(
"phemlight-path",
"Emissions",
"Determines where to load PHEMlight definitions from.");
135 oc.
addDescription(
"begin",
"Processing",
"Defines the begin time in seconds;");
138 oc.
addDescription(
"end",
"Processing",
"Defines the end time in seconds;");
158 if (!oc.
isSet(
"timeline-file") && !oc.
isSet(
"netstate-file")) {
159 throw ProcessError(
"Either a timeline or a netstate / amitran file must be given.");
161 if (!oc.
isSet(
"output-file") && (oc.
isSet(
"timeline-file") || !oc.
isSet(
"emission-output"))) {
164 std::ostream* out =
nullptr;
165 if (oc.
isSet(
"output-file")) {
166 out =
new std::ofstream(oc.
getString(
"output-file").c_str());
170 if (oc.
isSet(
"emission-output")) {
172 }
else if (out ==
nullptr) {
175 std::ostream* sumOut =
nullptr;
176 if (oc.
isSet(
"sum-output")) {
177 sumOut =
new std::ofstream(oc.
getString(
"sum-output").c_str());
178 (*sumOut) <<
"Vehicle,Cycle,Time,Speed,Gradient,Acceleration,FC,FCel,CO2,NOx,CO,HC,PM" << std::endl;
182 std::map<std::string, SUMOVTypeParameter*> vTypes;
183 if (oc.
isSet(
"vtype")) {
184 if (!oc.
isSet(
"additional-files")) {
185 throw ProcessError(
"Option --vtype requires option --additional-files for loading vehicle types");
196 if (vTypes.count(oc.
getString(
"vtype")) == 0) {
203 const bool computeA = oc.
getBool(
"compute-a") || oc.
getBool(
"compute-a.forward");
206 if (oc.
isSet(
"timeline-file")) {
207 int skip = oc.
getBool(
"skip-first") ? 1 : oc.
getInt(
"timeline-file.skip");
208 const bool inKMH = oc.
getBool(
"kmh");
209 const bool haveSlope = oc.
getBool(
"have-slope");
238 if (handler.
writeEmissions(*out,
"", defaultClass, &energyParams, t, v, a, s)) {
245 throw ProcessError(
"Missing an entry in line '" + line +
"'.");
247 throw ProcessError(
"Not numeric entry in line '" + line +
"'.");
252 std::cout <<
"sums" << std::endl
253 <<
"length:" << l << std::endl;
255 if (sumOut !=
nullptr) {
257 << (l / time * 3.6) <<
"," << (totalS / time) <<
"," << (totalA / time) <<
",";
261 if (oc.
isSet(
"netstate-file")) {
274 if (std::string(e.what()) != std::string(
"Process Error") && std::string(e.what()) != std::string(
"")) {
286 if (ret == 0 && !quiet) {
287 std::cout <<
"Success." << std::endl;
std::vector< std::string > StringVector
Definition of a vector of strings.
An upper class for objects with additional parameters.
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)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
bool isUsableFileList(const std::string &name) const
Checks whether the named option is usable as a file list (with at least a single file)
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, EnergyParams *params, double t, double &v, double &a, double &s)
An XML-Handler for amitran and netstate trajectories.
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)