Commit 82c5f095 authored by Sonja Happ's avatar Sonja Happ
Browse files

Merge branch 'scenario_file_comments' into 'master'

Add possibility to use comments in scenario files

See merge request !7
parents 659f015b f58ad3d4
......@@ -48,7 +48,7 @@ public:
void finish_time_measurements(unsigned long &stop_at);
//general file reading
void read_file_mpi(char* path, bool contains_header, std::vector<std::string> &line_vector, int &n_columns, int &n_rows, const MPI_Comm &communicator);
void read_file_mpi(char* path, std::vector<std::string> &line_vector, int &n_columns, int &n_rows, const MPI_Comm &communicator);
//profile reading
void read_profiles(Profile *comp_profiles);
......
......@@ -136,7 +136,7 @@ void ModelIO::init_db() {
// initialize database and table (once!) and connect all threads to the database
//
if (rank == 0) {
d_props.result.dbconn->initializePostgreSQLDB();
}
......@@ -185,7 +185,7 @@ void ModelIO::init_db() {
d_props.result.dbconn->addTimeMeasurementType("calculatecomponents","Time for calculating components in us");
d_props.result.dbconn->addTimeMeasurementType("backward_sweep","Time for backward sweeping in us");
d_props.result.dbconn->addTimeMeasurementType("forward_sweep","Time for forward sweeping in us");
d_props.result.dbconn->addTimeMeasurementType("load_behavior","Time for load behavior in us");
d_props.result.dbconn->addTimeMeasurementType("pv_behavior","Time for PV behavior in us");
d_props.result.dbconn->addTimeMeasurementType("ev_behavior","Time for EV behavior in us");
......@@ -390,7 +390,7 @@ void ModelIO::log_results_for_tick() {
"," + std::to_string(tm_db_add->get_duration() / 1000000.0)
);
#ifdef USE_DB
if(d_props.result.db_results){
......@@ -424,7 +424,7 @@ void ModelIO::log_results_for_tick() {
tm_behaviors->get_duration(), tick);
d_props.result.dbconn->addTimeMeasurement(tm_rt_tick->get_time_measurement_type(), tm_rt_tick->getId(),
tm_rt_tick->get_duration(), tick);
// Agent behavior time measurements
/*
d_props.result.dbconn->addTimeMeasurement(tm_load->get_time_measurement_type(), tm_load->getId(), tm_load->get_duration(), tick);
......@@ -489,7 +489,7 @@ void ModelIO::reset_time_measurements() {
tm_msg_proc_internal->reset();
tm_msg_proc_external->reset();
tm_behaviors->reset();
tm_load->reset();
tm_pv->reset();
tm_ev->reset();
......@@ -551,8 +551,8 @@ void ModelIO::set_result_file_header() {
"DB serializing," <<
"DB adding" <<
std::endl;
}
/*! \brief Log one line in csv file
......@@ -680,7 +680,7 @@ bool ModelIO::read_profile_file(char* path, double* &t, std::vector<double*> &va
int n_rows = 0;
/* profile file does contain header but it is needed here */
this->read_file_mpi(path, false, line_vector, n_columns, n_rows, MPI_COMM_WORLD);
this->read_file_mpi(path, line_vector, n_columns, n_rows, MPI_COMM_WORLD);
num_values = n_rows-1;
/* allocate memory */
......@@ -754,7 +754,7 @@ bool ModelIO::read_components_file(char* path, boost::multi_array<int, 2> &value
int n_columns = 0;
int n_rows = 0;
this->read_file_mpi(path, false, line_vector, n_columns, n_rows, MPI_COMM_WORLD);
this->read_file_mpi(path, line_vector, n_columns, n_rows, MPI_COMM_WORLD);
//resize values
boost::multi_array<int, 2>::extent_gen extents;
......@@ -847,7 +847,7 @@ bool ModelIO::read_elgrid_file(char* path, boost::multi_array<int, 2> &values, b
int n_columns = 0;
int n_rows = 0;
this->read_file_mpi(path, false, line_vector, n_columns, n_rows, MPI_COMM_WORLD);
this->read_file_mpi(path, line_vector, n_columns, n_rows, MPI_COMM_WORLD);
//resize values
boost::multi_array<int, 2>::extent_gen extents;
......@@ -916,7 +916,7 @@ bool ModelIO::read_comm_data_file(char* path, double * values){
int n_columns = 0;
int n_rows = 0;
this->read_file_mpi(path, false, line_vector, n_columns, n_rows, MPI_COMM_WORLD);
this->read_file_mpi(path, line_vector, n_columns, n_rows, MPI_COMM_WORLD);
int row = 0, col = 0;
......@@ -1156,13 +1156,12 @@ void ModelIO::read_profiles(Profile *comp_profiles)
/*! \brief Read the content of a csv file using MPI functions
* \param path [in] path to csv file
* \param contains_header [in] true if csv has header line, false otherwise
* \param line_vector [out] vector storing the lines of the file
* \param n_columns [out] number of columns of the file
* \param n_rows [out] number of rows of the file
* \param communicator [in] MPI communicator for file reading
* */
void ModelIO::read_file_mpi(char* path, bool contains_header, std::vector<std::string> &line_vector, int &n_columns, int &n_rows, const MPI_Comm &communicator) {
void ModelIO::read_file_mpi(char* path, std::vector<std::string> &line_vector, int &n_columns, int &n_rows, const MPI_Comm &communicator) {
char* buffer;
std::string file_content;
......@@ -1212,27 +1211,18 @@ void ModelIO::read_file_mpi(char* path, bool contains_header, std::vector<std::s
std::stringstream file_stream(file_content);
std::string line;
/*get first line and count number of columns*/
std::getline( file_stream, line, '\n' );
n_rows++;
n_columns = ( unsigned int ) std::count( line.begin(), line.end(), ',' ) + 1;
if(!contains_header) {
//no header available, first line contains already data
line_vector.push_back(line);
}
file_stream.clear();
/* read all remaining lines */
/* read file line by line */
n_columns = (unsigned int) 0;
while ( !file_stream.eof() ) {
std::getline( file_stream, line, '\n' );
if(!line.empty()) {
if(!line.empty() && line.rfind('#',0) != 0) { //ignore empty lines and comments
line_vector.push_back(line);
n_columns = (int) std::max((unsigned int) std::count( line.begin(), line.end(), ',') + 1, (unsigned int) n_columns);
n_rows++;
}
}
log_info("rows:" + std::to_string(n_rows) + " columns: " + std::to_string(n_columns) + " (columns based on first row)");
log_info("rows:" + std::to_string(n_rows) + " max columns: " + std::to_string(n_columns));
}
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