SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
emissionsMap_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // Main for an emissions map writer
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2013-2013 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #ifdef HAVE_VERSION_H
33 #include <version.h>
34 #endif
35 
37 #include <iostream>
38 #include <string>
39 #include <ctime>
41 #include <utils/options/Option.h>
47 #include <utils/common/ToString.h>
48 #include <utils/xml/XMLSubSys.h>
51 
52 #ifdef CHECK_MEMORY_LEAKS
53 #include <foreign/nvwa/debug_new.h>
54 #endif // CHECK_MEMORY_LEAKS
55 
56 
57 // ===========================================================================
58 // functions
59 // ===========================================================================
60 
61 
62 /* -------------------------------------------------------------------------
63  * main
64  * ----------------------------------------------------------------------- */
65 void single(const std::string& of, const std::string& className, SUMOEmissionClass c,
66  SUMOReal vMin, SUMOReal vMax, SUMOReal vStep,
67  SUMOReal aMin, SUMOReal aMax, SUMOReal aStep,
68  SUMOReal sMin, SUMOReal sMax, SUMOReal sStep,
69  bool verbose) {
70  if (verbose) {
71  WRITE_MESSAGE("Writing map of '" + className + "' into '" + of + "'.");
72  }
73  std::ofstream o(of.c_str());
74  for (SUMOReal v = vMin; v <= vMax; v += vStep) {
75  for (SUMOReal a = aMin; a <= aMax; a += aStep) {
76  for (SUMOReal s = sMin; s <= sMax; s += sStep) {
78  o << v << ";" << a << ";" << s << ";" << "CO" << ";" << result.CO << std::endl;
79  o << v << ";" << a << ";" << s << ";" << "CO2" << ";" << result.CO2 << std::endl;
80  o << v << ";" << a << ";" << s << ";" << "HC" << ";" << result.HC << std::endl;
81  o << v << ";" << a << ";" << s << ";" << "PMx" << ";" << result.PMx << std::endl;
82  o << v << ";" << a << ";" << s << ";" << "NOx" << ";" << result.NOx << std::endl;
83  o << v << ";" << a << ";" << s << ";" << "fuel" << ";" << result.fuel << std::endl;
84  }
85  }
86  }
87 }
88 
89 
90 
91 
92 int
93 main(int argc, char** argv) {
94  // build options
96  // give some application descriptions
97  oc.setApplicationDescription("Builds and writes an emissions map.");
98  oc.setApplicationName("emissionsMap", "SUMO emissionsMap Version " + (std::string)VERSION_STRING);
99  // add options
101  oc.addOptionSubTopic("Processing");
102  oc.doRegister("iterate", 'i', new Option_Bool(false));
103  oc.addDescription("iterate", "Processing", "If set, maps for all available emissions are written.");
104 
105  oc.doRegister("emission-class", 'e', new Option_String());
106  oc.addDescription("emission-class", "Processing", "Defines the name of the emission class to generate the map for.");
107 
108  oc.doRegister("v-min", new Option_Float(0.));
109  oc.addDescription("v-min", "Processing", "Defines the minimum velocity boundary of the map to generate (in m/s).");
110  oc.doRegister("v-max", new Option_Float(50.));
111  oc.addDescription("v-max", "Processing", "Defines the maximum velocity boundary of the map to generate (in m/s).");
112  oc.doRegister("v-step", new Option_Float(2.));
113  oc.addDescription("v-step", "Processing", "Defines the velocity step size (in m/s).");
114  oc.doRegister("a-min", new Option_Float(-4.));
115  oc.addDescription("a-min", "Processing", "Defines the minimum acceleration boundary of the map to generate (in m/s^2).");
116  oc.doRegister("a-max", new Option_Float(4.));
117  oc.addDescription("a-max", "Processing", "Defines the maximum acceleration boundary of the map to generate (in m/s^2).");
118  oc.doRegister("a-step", new Option_Float(.5));
119  oc.addDescription("a-step", "Processing", "Defines the acceleration step size (in m/s^2).");
120  oc.doRegister("s-min", new Option_Float(-10.));
121  oc.addDescription("s-min", "Processing", "Defines the minimum slope boundary of the map to generate (in deg).");
122  oc.doRegister("s-max", new Option_Float(10.));
123  oc.addDescription("s-max", "Processing", "Defines the maximum slope boundary of the map to generate (in deg).");
124  oc.doRegister("s-step", new Option_Float(1.));
125  oc.addDescription("s-step", "Processing", "Defines the slope step size (in deg).");
126 
127  oc.addOptionSubTopic("Output");
128  oc.doRegister("output-file", 'o', new Option_String());
129  oc.addSynonyme("output", "output-file");
130  oc.addDescription("output", "Output", "Defines the file (or the path if --iterate was set) to write the map(s) into.");
131 
132  oc.addOptionSubTopic("Emissions");
133  oc.doRegister("phemlight-path", new Option_FileName("./PHEMlight/"));
134  oc.addDescription("phemlight-path", "Emissions", "Determines where to load PHEMlight definitions from.");
135 
137 
138  // run
139  int ret = 0;
140  try {
141  // initialise the application system (messaging, xml, options)
142  XMLSubSys::init();
143  OptionsIO::getOptions(true, argc, argv);
145  if (oc.processMetaOptions(argc < 2)) {
147  return 0;
148  }
149 
150  SUMOReal vMin = oc.getFloat("v-min");
151  SUMOReal vMax = oc.getFloat("v-max");
152  SUMOReal vStep = oc.getFloat("v-step");
153  SUMOReal aMin = oc.getFloat("a-min");
154  SUMOReal aMax = oc.getFloat("a-max");
155  SUMOReal aStep = oc.getFloat("a-step");
156  SUMOReal sMin = oc.getFloat("s-min");
157  SUMOReal sMax = oc.getFloat("s-max");
158  SUMOReal sStep = oc.getFloat("s-step");
159  if (!oc.getBool("iterate")) {
160  if (!oc.isSet("emission-class")) {
161  throw ProcessError("The emission class (-e) must be given.");
162  }
163  if (!oc.isSet("output-file")) {
164  throw ProcessError("The output file (-o) must be given.");
165  }
166  const SUMOEmissionClass c = PollutantsInterface::getClassByName(oc.getString("emission-class"));
167  single(oc.getString("output-file"), oc.getString("emission-class"),
168  c, vMin, vMax, vStep, aMin, aMax, aStep, sMin, sMax, sStep, oc.getBool("verbose"));
169  } else {
170  if (!oc.isSet("output-file")) {
171  oc.set("output-file", "./");
172  }
173  const std::vector<SUMOEmissionClass> classes = PollutantsInterface::getAllClasses();
174  for (std::vector<SUMOEmissionClass>::const_iterator ci = classes.begin(); ci != classes.end(); ++ci) {
175  SUMOEmissionClass c = *ci;
177  c, vMin, vMax, vStep, aMin, aMax, aStep, sMin, sMax, sStep, oc.getBool("verbose"));
178  }
179  }
180  } catch (InvalidArgument& e) {
182  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
183  ret = 1;
184  } catch (ProcessError& e) {
185  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
187  }
188  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
189  ret = 1;
190 #ifndef _DEBUG
191  } catch (...) {
192  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
193  ret = 1;
194 #endif
195  }
197  if (ret == 0) {
198  std::cout << "Success." << std::endl;
199  }
200  return ret;
201 }
202 
203 
204 
205 /****************************************************************************/
206 
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:84
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:58
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
Definition: SystemFrame.cpp:74
static void getOptions(bool loadConfig, int argc=0, char **argv=0)
Parses the command line arguments and loads the configuration optionally.
Definition: OptionsIO.cpp:64
static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope)
Returns the amount of all emitted pollutants given the vehicle type and state (in mg/s or ml/s for fu...
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Storage for collected values of all emission types.
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
static void close()
Closes all of an applications subsystems.
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
Definition: SystemFrame.cpp:50
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
int main(int argc, char **argv)
int SUMOEmissionClass
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
static const std::vector< SUMOEmissionClass > getAllClasses()
Checks whether the string describes a known vehicle class.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
#define VERSION_STRING
Definition: config.h:227
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:89
A storage for options typed value containers)
Definition: OptionsCont.h:108
void single(const std::string &of, const std::string &className, SUMOEmissionClass c, SUMOReal vMin, SUMOReal vMax, SUMOReal vStep, SUMOReal aMin, SUMOReal aMax, SUMOReal aStep, SUMOReal sMin, SUMOReal sMax, SUMOReal sStep, bool verbose)
#define SUMOReal
Definition: config.h:215
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.