60 main(
int argc,
char** argv) {
66 oc.
setApplicationName(
"emissionsDrivingCycle",
"Eclipse SUMO emissionsDrivingCycle Version " VERSION_STRING);
73 oc.
addDescription(
"timeline-file",
"Input",
"Defines the file to read the driving cycle from.");
76 oc.
addSynonyme(
"timeline.skip",
"timeline-file.skip");
77 oc.
addDescription(
"timeline-file.skip",
"Input",
"Skips the firs NUM lines.");
80 oc.
addSynonyme(
"timeline.separator",
"timeline-file.separator");
81 oc.
addDescription(
"timeline-file.separator",
"Input",
"Defines the entry separator.");
86 oc.
addDescription(
"netstate-file",
"Input",
"Defines the netstate, route and trajectory files to read the driving cycles from.");
89 oc.
addDescription(
"additional-files",
"Input",
"Load emission parameters (vTypes) from FILE(s)");
92 oc.
addDescription(
"emission-class",
"Input",
"Defines for which emission class the emissions shall be generated. ");
95 oc.
addDescription(
"vtype",
"Input",
"Defines the vehicle type to use for emission parameters.");
99 oc.
addDescription(
"compute-a",
"Processing",
"If set, the acceleration is computed instead of being read from the file. ");
102 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). ");
105 oc.
addDescription(
"compute-a.zero-correction",
"Processing",
"If set, the acceleration for time t is set to 0 if the speed is 0. ");
108 oc.
addDescription(
"skip-first",
"Processing",
"If set, the first line of the read file is skipped.");
111 oc.
addDescription(
"kmh",
"Processing",
"If set, the given speed is interpreted as being given in km/h.");
114 oc.
addDescription(
"have-slope",
"Processing",
"If set, the fourth column is read and used as slope (in deg).");
117 oc.
addDescription(
"slope",
"Processing",
"Sets a global slope (in deg) that is used if the file does not contain slope information.");
122 oc.
addDescription(
"output",
"Output",
"Defines the file to write the emission cycle results into.");
125 oc.
addDescription(
"output.attributes",
"Output",
"Defines the attributes to write.");
128 oc.
addDescription(
"emission-output",
"Output",
"Save the emission values of each vehicle in XML");
132 oc.
addDescription(
"sum-output",
"Output",
"Save the aggregated and normed emission values of each vehicle in CSV");
136 oc.
addDescription(
"emissions.volumetric-fuel",
"Emissions",
"Return fuel consumption values in (legacy) unit l instead of mg");
139 oc.
addDescription(
"phemlight-path",
"Emissions",
"Determines where to load PHEMlight definitions from");
142 oc.
addDescription(
"phemlight-year",
"Emissions",
"Enable fleet age modelling with the given reference year in PHEMlight5");
145 oc.
addDescription(
"phemlight-temperature",
"Emissions",
"Set ambient temperature to correct NOx emissions in PHEMlight5");
148 oc.
addDescription(
"begin",
"Processing",
"Defines the begin time in seconds;");
151 oc.
addDescription(
"end",
"Processing",
"Defines the end time in seconds;");
171 if (!oc.
isSet(
"timeline-file") && !oc.
isSet(
"netstate-file")) {
172 throw ProcessError(
"Either a timeline or a netstate / amitran file must be given.");
174 if (!oc.
isSet(
"output-file") && (oc.
isSet(
"timeline-file") || !oc.
isSet(
"emission-output"))) {
177 std::ostream* out =
nullptr;
178 if (oc.
isSet(
"output-file")) {
179 out =
new std::ofstream(oc.
getString(
"output-file").c_str());
181 long long int attributes = 0;
182 if (oc.
isSet(
"output.attributes")) {
185 if (attrName ==
"all") {
186 attributes = std::numeric_limits<long long int>::max() - 1;
188 WRITE_ERROR(
"Unknown attribute '" + attrName +
"' to write in output.");
194 attributes |= ((
long long int)1 << attr);
201 if (oc.
isSet(
"emission-output")) {
203 }
else if (out ==
nullptr) {
206 std::ostream* sumOut =
nullptr;
207 if (oc.
isSet(
"sum-output")) {
208 sumOut =
new std::ofstream(oc.
getString(
"sum-output").c_str());
209 (*sumOut) <<
"Vehicle,Cycle,Time,Speed,Gradient,Acceleration,FC,FCel,CO2,NOx,CO,HC,PM" << std::endl;
213 std::map<std::string, SUMOVTypeParameter*> vTypes;
214 if (oc.
isSet(
"vtype")) {
215 if (!oc.
isSet(
"additional-files")) {
216 throw ProcessError(
"Option --vtype requires option --additional-files for loading vehicle types");
227 if (vTypes.count(oc.
getString(
"vtype")) == 0) {
234 const bool computeA = oc.
getBool(
"compute-a") || oc.
getBool(
"compute-a.forward");
237 if (oc.
isSet(
"timeline-file")) {
238 int skip = oc.
getBool(
"skip-first") ? 1 : oc.
getInt(
"timeline-file.skip");
239 const bool inKMH = oc.
getBool(
"kmh");
240 const bool haveSlope = oc.
getBool(
"have-slope");
272 if (handler.
writeEmissions(*out,
"", defaultClass, &energyParams, attributes, t, v, a, s)) {
279 throw ProcessError(
"Missing an entry in line '" + line +
"'.");
281 throw ProcessError(
"Not numeric entry in line '" + line +
"'.");
286 std::cout <<
"sums" << std::endl
287 <<
"length:" << l << std::endl;
289 if (sumOut !=
nullptr) {
291 << (l / time * 3.6) <<
"," << (totalS / time) <<
"," << (totalA / time) <<
",";
295 if (oc.
isSet(
"netstate-file")) {
308 if (std::string(e.what()) != std::string(
"Process Error") && std::string(e.what()) != std::string(
"")) {
320 if (ret == 0 && !quiet) {
321 std::cout <<
"Success." << std::endl;
std::vector< std::string > StringVector
Definition of a vector of strings.
@ SUMO_ATTR_AMOUNT
MSMeanData_Amitran.
const double INVALID_DOUBLE
An upper class for objects with additional parameters.
Retrieves a file linewise and reports the lines to a handler.
bool good() const
Returns the information whether the stream is readable.
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
static void setupI18n(const std::string &locale="")
set up gettext stuff
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.
static StringBijection< int > Attrs
The names of SUMO-XML attributes for use in netbuild.
T get(const std::string &str) const
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, long long int attributes, 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)