WSL/SLF GitLab Repository

Commit 75aefa3f authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Fixed a bug in data_converter than was leading to segfault when a station ID...

Fixed a bug in data_converter than was leading to segfault when a station ID was duplicated in the io.ini. Code cleanup in ImisIO (since I first looked there for the bug!).
parent 9d2dae3e
......@@ -23,7 +23,6 @@ void real_main(int argc, char** argv) {
IOUtils::convertString(Tstep, argv[3]);
Tstep /= 24.; //convert to sampling rate in days
std::vector< std::vector<MeteoData> > vecMeteo;
IOManager io(cfg);
std::cout << "Reading input data" << std::endl;
......@@ -32,14 +31,16 @@ void real_main(int argc, char** argv) {
std::map<std::string, size_t> mapIDs; //over a large time range, the number of stations might change... this is the way to make it work
std::vector<MeteoData> Meteo; //we need some intermediate storage, for storing data sets for 1 timestep
std::vector< std::vector<MeteoData> > vecMeteo; //so we can keep and output the data that has been read
for(; d1<=d2; d1+=Tstep) { //time loop
io.getMeteoData(d1, Meteo); //read 1 timestep at once, forcing resampling to the timestep
size_t insert_position = 0;
for(size_t ii=0; ii<Meteo.size(); ii++) {
const std::string stationID( Meteo[ii].meta.stationID );
if (mapIDs.count( stationID )==0) { //if this is the first time we encounter this station, save where it should be inserted
mapIDs[ stationID ] = ii;
if (ii>=vecMeteo.size()) vecMeteo.push_back( std::vector<MeteoData>() ); //allocating the new station
mapIDs[ stationID ] = insert_position++;
vecMeteo.push_back( std::vector<MeteoData>() ); //allocating the new station
}
vecMeteo[ mapIDs[stationID] ].push_back(Meteo[ii]); //fill the data manually into the vector of vectors
}
......
......@@ -239,7 +239,10 @@ void ImisIO::closeDBConnection(oracle::occi::Environment*& env, oracle::occi::Co
try {
if (conn != NULL)
env->terminateConnection(conn);
Environment::terminateEnvironment(env); // static OCCI function
if (env != NULL)
Environment::terminateEnvironment(env); // static OCCI function
conn = NULL;
env = NULL;
} catch (const exception&){
Environment::terminateEnvironment(env); // static OCCI function
}
......@@ -380,7 +383,7 @@ void ImisIO::readMeteoData(const Date& dateStart, const Date& dateEnd,
}
if (vecStationMetaData.empty()) { //if there are no stations -> return
if ((env != NULL) || (conn != NULL)) closeDBConnection(env, conn);
closeDBConnection(env, conn);
return;
}
......@@ -428,7 +431,7 @@ void ImisIO::readMeteoData(const Date& dateStart, const Date& dateEnd,
closeDBConnection(env, conn);
} catch (const exception& e){
closeDBConnection(env, conn);
throw IOException("Oracle Error when reading stations' data: " + string(e.what()), AT); //Translation of OCCI exception to IOException
throw IOException("Oracle Error when reading stations' data: " + std::string(e.what()), AT); //Translation of OCCI exception to IOException
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment