59main(
int argc,
char** argv) {
62 oc.
setApplicationName(
"emissionsDrivingCycle",
"Eclipse SUMO emissionsDrivingCycle Version " VERSION_STRING);
69 oc.
addDescription(
"timeline-file",
"Input",
TL(
"Defines the file to read the driving cycle from."));
72 oc.
addSynonyme(
"timeline.skip",
"timeline-file.skip");
73 oc.
addDescription(
"timeline-file.skip",
"Input",
TL(
"Skips the first NUM lines."));
76 oc.
addSynonyme(
"timeline.separator",
"timeline-file.separator");
77 oc.
addDescription(
"timeline-file.separator",
"Input",
TL(
"Defines the entry separator."));
82 oc.
addDescription(
"netstate-file",
"Input",
TL(
"Defines the netstate, route and trajectory files to read the driving cycles from."));
85 oc.
addDescription(
"additional-files",
"Input",
TL(
"Load emission parameters (vTypes) from FILE(s)"));
88 oc.
addDescription(
"emission-class",
"Input",
TL(
"Defines for which emission class the emissions shall be generated. "));
91 oc.
addDescription(
"vtype",
"Input",
TL(
"Defines the vehicle type to use for emission parameters."));
95 oc.
addDescription(
"compute-a",
"Processing",
TL(
"If set, the acceleration is computed instead of being read from the file. "));
98 oc.
addDescription(
"compute-a.forward",
"Processing",
TL(
"If set, the acceleration for time t is computed from v(t+1) - v(t) instead of v(t) - v(t-1). "));
101 oc.
addDescription(
"compute-a.zero-correction",
"Processing",
TL(
"If set, the acceleration for time t is set to 0 if the speed is 0. "));
104 oc.
addDescription(
"skip-first",
"Processing",
TL(
"If set, the first line of the read file is skipped."));
107 oc.
addDescription(
"kmh",
"Processing",
TL(
"If set, the given speed is interpreted as being given in km/h."));
110 oc.
addDescription(
"have-slope",
"Processing",
TL(
"If set, the fourth column is read and used as slope (in deg)."));
113 oc.
addDescription(
"slope",
"Processing",
TL(
"Sets a global slope (in deg) that is used if the file does not contain slope information."));
118 oc.
addDescription(
"output",
"Output",
TL(
"Defines the file to write the emission cycle results into."));
121 oc.
addDescription(
"output.attributes",
"Output",
TL(
"Defines the attributes to write."));
124 oc.
addDescription(
"emission-output",
"Output",
TL(
"Save the emission values of each vehicle in XML"));
128 oc.
addDescription(
"sum-output",
"Output",
TL(
"Save the aggregated and normed emission values of each vehicle in CSV"));
132 oc.
addDescription(
"emissions.volumetric-fuel",
"Emissions",
TL(
"Return fuel consumption values in (legacy) unit l instead of mg"));
135 oc.
addDescription(
"phemlight-path",
"Emissions",
TL(
"Determines where to load PHEMlight definitions from"));
138 oc.
addDescription(
"phemlight-year",
"Emissions",
TL(
"Enable fleet age modelling with the given reference year in PHEMlight5"));
141 oc.
addDescription(
"phemlight-temperature",
"Emissions",
TL(
"Set ambient temperature to correct NOx emissions in PHEMlight5"));
144 oc.
addDescription(
"begin",
"Processing",
TL(
"Defines the begin time in seconds;"));
147 oc.
addDescription(
"end",
"Processing",
TL(
"Defines the end time in seconds;"));
167 if (!oc.
isSet(
"timeline-file") && !oc.
isSet(
"netstate-file")) {
168 throw ProcessError(
TL(
"Either a timeline or a netstate / amitran file must be given."));
170 if (!oc.
isSet(
"output-file") && (oc.
isSet(
"timeline-file") || !oc.
isSet(
"emission-output"))) {
173 std::ostream* out =
nullptr;
174 if (oc.
isSet(
"output-file")) {
175 out =
new std::ofstream(oc.
getString(
"output-file").c_str());
177 long long int attributes = 0;
178 if (oc.
isSet(
"output.attributes")) {
181 if (attrName ==
"all") {
182 attributes = std::numeric_limits<long long int>::max() - 1;
184 WRITE_ERRORF(
TL(
"Unknown attribute '%' to write in output."), attrName);
190 attributes |= ((
long long int)1 << attr);
197 if (oc.
isSet(
"emission-output")) {
199 }
else if (out ==
nullptr) {
202 std::ostream* sumOut =
nullptr;
203 if (oc.
isSet(
"sum-output")) {
204 sumOut =
new std::ofstream(oc.
getString(
"sum-output").c_str());
205 (*sumOut) <<
"Vehicle,Cycle,Time,Speed,Gradient,Acceleration,FC,FCel,CO2,NOx,CO,HC,PM" << std::endl;
209 std::unique_ptr<EnergyParams> energyParams;
210 std::map<std::string, SUMOVTypeParameter*> vTypes;
211 if (oc.
isSet(
"vtype") || oc.
isSet(
"additional-files")) {
212 if (!oc.
isSet(
"additional-files")) {
213 throw ProcessError(
TL(
"Option --vtype requires option --additional-files for loading vehicle types"));
218 for (
const std::string& file : oc.
getStringVector(
"additional-files")) {
224 if (!oc.
isSet(
"vtype") && vTypes.size() != 1) {
227 const auto vTypeIt = oc.
isSet(
"vtype") ? vTypes.find(oc.
getString(
"vtype")) : vTypes.begin();
228 if (vTypeIt == vTypes.end()) {
232 emissionClass = vTypeIt->second->emissionClass;
234 energyParams = std::unique_ptr<EnergyParams>(
new EnergyParams(vTypeIt->second));
236 energyParams = std::unique_ptr<EnergyParams>(
new EnergyParams(emissionClass));
239 const bool computeA = oc.
getBool(
"compute-a") || oc.
getBool(
"compute-a.forward");
242 if (oc.
isSet(
"timeline-file")) {
243 int skip = oc.
getBool(
"skip-first") ? 1 : oc.
getInt(
"timeline-file.skip");
244 const bool inKMH = oc.
getBool(
"kmh");
245 const bool haveSlope = oc.
getBool(
"have-slope");
277 if (handler.
writeEmissions(*out,
"", emissionClass, energyParams.get(), attributes, t, v, a, s)) {
291 std::cout <<
"sums" << std::endl
292 <<
"length:" << l << std::endl;
294 if (sumOut !=
nullptr) {
296 << (l / time * 3.6) <<
"," << (totalS / time) <<
"," << (totalA / time) <<
",";
300 if (oc.
isSet(
"netstate-file")) {
307 if (out != &std::cout) {
315 if (std::string(e.what()) != std::string(
"Process Error") && std::string(e.what()) != std::string(
"")) {
327 if (ret == 0 && !quiet) {
328 std::cout <<
"Success." << std::endl;
#define WRITE_ERRORF(...)
std::vector< std::string > StringVector
Definition of a vector of strings.
@ SUMO_ATTR_AMOUNT
MSMeanData_Amitran.
const double INVALID_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
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.
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)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
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 SequentialStringBijection Attrs
The names of SUMO-XML attributes for use in netbuild.
int 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, const bool isExternal=false, const bool catchExceptions=true)
Runs the given handler on the given file; returns if everything's ok.
int main(int argc, char **argv)