SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RODFDetFlowLoader.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // A loader for detector flows
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
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 #include <string>
33 #include <fstream>
34 #include <sstream>
42 #include "RODFDetFlowLoader.h"
43 
44 #ifdef CHECK_MEMORY_LEAKS
45 #include <foreign/nvwa/debug_new.h>
46 #endif // CHECK_MEMORY_LEAKS
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
53  RODFDetectorFlows& into,
54  SUMOTime startTime, SUMOTime endTime,
55  SUMOTime timeOffset, SUMOTime timeScale)
56  : myStorage(into), myTimeOffset(timeOffset), myTimeScale(timeScale),
57  myStartTime(startTime), myEndTime(endTime), myDetectorContainer(dets),
58  myHaveWarnedAboutOverridingBoundaries(false), myHaveWarnedAboutPartialDefs(false) {}
59 
60 
61 
63 
64 
65 void
66 RODFDetFlowLoader::read(const std::string& file) {
67  LineReader lr(file);
68  // parse first line
69  myLineHandler.reinit(lr.readLine(), ";", ";", true, true);
70  // parse values
71  while (lr.hasMore()) {
72  std::string line = lr.readLine();
73  if (line.find(';') == std::string::npos) {
74  continue;
75  }
77  try {
78  std::string detName = myLineHandler.get("detector");
79  if (!myDetectorContainer.knows(detName)) {
80  continue;
81  }
82  const SUMOTime time = TplConvert::_2int((myLineHandler.get("time").c_str())) * myTimeScale - myTimeOffset;
83  if (time < myStartTime || time > myEndTime) {
86  WRITE_WARNING("At least one value lies beyond given time boundaries.");
87  }
88  continue;
89  }
90  FlowDef fd;
91  fd.isLKW = 0;
92  fd.qPKW = TplConvert::_2SUMOReal(myLineHandler.get("qpkw").c_str());
93  fd.vPKW = 0;
94  if (myLineHandler.know("vPKW")) {
95  fd.vPKW = TplConvert::_2SUMOReal(myLineHandler.get("vpkw").c_str());
96  }
97  fd.qLKW = 0;
98  if (myLineHandler.know("qLKW")) {
99  fd.qLKW = TplConvert::_2SUMOReal(myLineHandler.get("qlkw").c_str());
100  }
101  fd.vLKW = 0;
102  if (myLineHandler.know("vLKW")) {
103  fd.vLKW = TplConvert::_2SUMOReal(myLineHandler.get("vlkw").c_str());
104  }
105  if (fd.qLKW < 0) {
106  fd.qLKW = 0;
107  }
108  if (fd.qPKW < 0) {
109  fd.qPKW = 0;
110  }
111  myStorage.addFlow(detName, time, fd);
114  WRITE_WARNING("At least one line does not contain the correct number of columns.");
115  }
116  continue;
117  } catch (UnknownElement&) {} catch (OutOfBoundsException&) {} catch (NumberFormatException&) {}
118  throw ProcessError("The detector-flow-file '" + lr.getFileName() + "' is corrupt;\n"
119  + " The following values must be supplied : 'Detector', 'Time', 'qPKW'\n"
120  + " The according column names must be given in the first line of the file.");
121  }
122 }
123 
124 
125 /****************************************************************************/
126