WSL/SLF GitLab Repository

Commit 75333daa authored by Mathias Bavay's avatar Mathias Bavay
Browse files

A lot of writes were using std::endl for end of line, which forces a buffer...

A lot of writes were using std::endl for end of line, which forces a buffer flush. This lead to a visible performance cost (as shown by the profiling project made in collaboration with HES_SO). These have been replaced by "\n" that lets ostream manage its buffer as it wants.
parent cee160c6
......@@ -390,9 +390,9 @@ void SMETWriter::write_signature()
{
fout << "SMET " << SMETCommon::smet_version << " ";
if (smet_type == ASCII)
fout << "ASCII" << endl;
fout << "ASCII" << "\n";
else
fout << "BINARY" << endl;
fout << "BINARY" << "\n";
}
bool SMETWriter::valid_header()
......@@ -504,64 +504,64 @@ void SMETWriter::write_header()
write_signature();
fout << "[HEADER]" << endl;
fout << "station_id = " << header["station_id"] << endl;
fout << "[HEADER]" << "\n";
fout << "station_id = " << header["station_id"] << "\n";
it = header.find("station_name");
if (it != header.end())
fout << "station_name = " << it->second << endl;
fout << "station_name = " << it->second << "\n";
if (location_in_header){
if (location_wgs84 == 7){
fout << "latitude = " << header["latitude"] << endl;
fout << "longitude = " << header["longitude"] << endl;
fout << "altitude = " << header["altitude"] << endl;
fout << "latitude = " << header["latitude"] << "\n";
fout << "longitude = " << header["longitude"] << "\n";
fout << "altitude = " << header["altitude"] << "\n";
}
if (location_epsg == 15){
fout << "easting = " << header["easting"] << endl;
fout << "northing = " << header["northing"] << endl;
fout << "easting = " << header["easting"] << "\n";
fout << "northing = " << header["northing"] << "\n";
if (location_wgs84 != 7)
fout << "altitude = " << header["altitude"] << endl;
fout << "epsg = " << header["epsg"] << endl;
fout << "altitude = " << header["altitude"] << "\n";
fout << "epsg = " << header["epsg"] << "\n";
}
} else {
if (location_in_data_epsg)
fout << "epsg = " << header["epsg"] << endl;
fout << "epsg = " << header["epsg"] << "\n";
}
fout << "nodata = " << header["nodata"] << endl;
fout << "nodata = " << header["nodata"] << "\n";
//Optional header keys:
it = header.find("tz");
if (it != header.end())
fout << "tz = " << it->second << endl;
fout << "tz = " << it->second << "\n";
it = header.find("creation");
if (it != header.end())
fout << "creation = " << it->second << endl;
fout << "creation = " << it->second << "\n";
it = header.find("source");
if (it != header.end())
fout << "source = " << it->second << endl;
fout << "source = " << it->second << "\n";
it = header.find("units_offset");
if (it != header.end())
fout << "units_offset = " << it->second << endl;
fout << "units_offset = " << it->second << "\n";
it = header.find("units_multiplier");
if (it != header.end())
fout << "units_multiplier = " << it->second << endl;
fout << "units_multiplier = " << it->second << "\n";
it = header.find("comment");
if (it != header.end())
fout << "comment = " << it->second << endl;
fout << "comment = " << it->second << "\n";
for (size_t ii=0; ii<other_header_keys.size(); ii++){
fout << other_header_keys[ii] << " = " << header[other_header_keys[ii]] << endl;
fout << other_header_keys[ii] << " = " << header[other_header_keys[ii]] << "\n";
}
fout << "fields = " << header["fields"] << endl;
fout << "fields = " << header["fields"] << "\n";
fout << "[DATA]" << endl;
}
......@@ -608,7 +608,7 @@ void SMETWriter::write_data_line_ascii(const std::string& timestamp, const std::
if (data[ii] == nodata_value) fout << nodata_string; //to have a nicer representation
else fout << data[ii];
}
fout << endl;
fout << "\n";
}
void SMETWriter::check_formatting()
......
......@@ -192,7 +192,6 @@ void ARCIO::read2DGrid(Grid2DObject& grid_out, const std::string& filename)
//Read one line after the other and parse values into Grid2DObject
for (unsigned int kk=nrows-1; (kk < nrows); kk--) {
getline(fin, line, eoln); //read complete line
//cout << "k:" << kk << "\n" << line << endl;
if (IOUtils::readLineToVec(line, tmpvec) != ncols) {
throw InvalidFormatException("Premature End " + filename, AT);
......@@ -224,7 +223,7 @@ void ARCIO::readDEM(DEMObject& dem_out)
void ARCIO::readLanduse(Grid2DObject& landuse_out)
{
string filename="";
cfg.getValue("LANDUSEFILE", "Input", filename); // cout << tmp << endl;
cfg.getValue("LANDUSEFILE", "Input", filename);
read2DGrid(landuse_out, filename);
}
......@@ -234,7 +233,7 @@ void ARCIO::readAssimilationData(const Date& date_in, Grid2DObject& da_out)
date_in.getDate(yyyy, MM, dd, hh, mm);
string filepath="";
cfg.getValue("DAPATH", "Input", filepath); // cout << tmp << endl;
cfg.getValue("DAPATH", "Input", filepath);
stringstream ss;
ss.fill('0');
......@@ -282,18 +281,18 @@ void ARCIO::write2DGrid(const Grid2DObject& grid_in, const std::string& name)
llcorner.setProj(coordout, coordoutparam);
fout << fixed << showpoint << setprecision(6);
fout << "ncols " << setw(23-6) << grid_in.ncols << endl;
fout << "nrows " << setw(23-6) << grid_in.nrows << endl;
fout << "xllcorner " << setw(23-10) << setprecision(3) << llcorner.getEasting() << endl;
fout << "yllcorner " << setw(23-10) << setprecision(3) << llcorner.getNorthing() << endl;
fout << "cellsize " << setw(23-9) << setprecision(3) << grid_in.cellsize << endl;
fout << "NODATA_value " << (int)(IOUtils::nodata) << endl;
fout << "ncols " << setw(23-6) << grid_in.ncols << "\n";
fout << "nrows " << setw(23-6) << grid_in.nrows << "\n";
fout << "xllcorner " << setw(23-10) << setprecision(3) << llcorner.getEasting() << "\n";
fout << "yllcorner " << setw(23-10) << setprecision(3) << llcorner.getNorthing() << "\n";
fout << "cellsize " << setw(23-9) << setprecision(3) << grid_in.cellsize << "\n";
fout << "NODATA_value " << (int)(IOUtils::nodata) << "\n";
for (unsigned int kk=grid_in.nrows-1; kk < grid_in.nrows; kk--) {
for (unsigned int ll=0; ll < grid_in.ncols; ll++){
fout << grid_in.grid2D(ll, kk) << " ";
}
fout << endl;
fout << "\n";
}
} catch(...) {
cout << "[E] " << AT << ": "<< endl;
......
......@@ -374,7 +374,7 @@ void CosmoXMLIO::writeHeader(std::stringstream& XMLdata)
//Writes station data
void CosmoXMLIO::writeLocationHeader(const StationData& station, std::stringstream& XMLdata)
{
XMLdata << "<col>\n<ttable id=\"data\">\n<row>" << endl;
XMLdata << "<col>\n<ttable id=\"data\">\n<row>" << "\n";
XMLdata << "<col id=\"identifier\">" << station.getStationName() << "</col>\n";
XMLdata << "<col id=\"station_abbreviation\">" << station.getStationID() << "</col>\n";
......
......@@ -118,7 +118,7 @@ void GSNIO::initGSNConnection(){
cfg.getValue("ENDPOINT", "INPUT", endpoint, Config::nothrow);
if (endpoint != ""){
gsn.soap_endpoint = endpoint.c_str();
cout << "\tUsing GSN Endpoint: " << endpoint << endl;
cout << "\tUsing GSN Endpoint: " << endpoint << "\n";
}
/*
......@@ -215,9 +215,9 @@ void GSNIO::readMeteoData(const Date& dateStart, const Date& dateEnd,
readData(dateStart, dateEnd, vecMeteo[ii], ii);
reverse(vecMeteo[ii].begin(), vecMeteo[ii].end()); //this is necessary because GSN data comes sorted descending by date
/*//The following block can be commented in for testing purposes
cout << "vecMeteo[" <<ii << "].size() = " << vecMeteo[ii].size() << endl;
cout << "vecMeteo[" <<ii << "].size() = " << vecMeteo[ii].size() << "\n";
for (size_t jj=0; jj<vecMeteo[ii].size(); jj++){
cout << vecMeteo[ii][jj] << endl;
cout << vecMeteo[ii][jj] << "\n";
}*/
}
}
......@@ -451,7 +451,6 @@ void GSNIO::parse_streamElement(const std::vector<size_t>& index, const bool& ol
if ((olwr_present) && (tmpmeteo(MeteoData::TSS) == IOUtils::nodata))
tmpmeteo(MeteoData::TSS) = olwr_to_tss(tmpmeteo("OLWR"));
//cout << endl << tmpmeteo << endl;
vecMeteo.push_back(tmpmeteo);
tmpmeteo(MeteoData::TSS) = IOUtils::nodata; //if tss has been set, then it needs to be reset manually
}
......@@ -483,7 +482,7 @@ void GSNIO::readStationNames()
if (current_station != ""){
vecStationName.push_back(current_station); //add station name to vector of all station names
cout << "\tRead stationname '" << current_station << "'" << endl;
cout << "\tRead stationname '" << current_station << "'\n";
}
current_stationnr++;
......@@ -504,9 +503,9 @@ void GSNIO::listSensors(std::vector<std::string>& vec_names)
_ns1__listVirtualSensorNames sensor_req;
if (gsn.listVirtualSensorNames(&sensor_req, &sensor_names) == SOAP_OK){
cout << "[I] No STATIONS specified... Using all " << sensor_names.virtualSensorName.size() << " sensors available through GSN" << endl;
cout << "[I] No STATIONS specified... Using all " << sensor_names.virtualSensorName.size() << " sensors available through GSN\n";
for (size_t ii=0; ii<sensor_names.virtualSensorName.size(); ii++){
cout << "\tSTATION" << ii+1 << " = " << sensor_names.virtualSensorName[ii] << endl;
cout << "\tSTATION" << ii+1 << " = " << sensor_names.virtualSensorName[ii] << "\n";
vec_names.push_back(sensor_names.virtualSensorName[ii]);
}
} else {
......
......@@ -179,7 +179,7 @@ void GeotopIO::writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMe
if (jj==0){ //This is for writing the header
if (kk==0) fout << "Date";
fout << "," << vecSequence[kk];
if (kk==(vecSequence.size()-1)) fout << endl;
if (kk==(vecSequence.size()-1)) fout << "\n";
}
//Write all the data, make sure to transform the nodata values correctly
......@@ -188,7 +188,7 @@ void GeotopIO::writeMeteoData(const std::vector< std::vector<MeteoData> >& vecMe
else
ss << ", " << setprecision(7) << tmpmd(mapParam[vecSequence[kk]]);
}
fout << ss.str() << endl;
fout << ss.str() << "\n";
}
fout.close();
......@@ -220,10 +220,9 @@ void GeotopIO::readMeteoData(const Date& dateStart, const Date& dateEnd,
cfg.getValue("METEOPREFIX", "Input", prefix);
vector<StationData> myStations;
/*
* read _meteo.txt to find out how many stations exist
* at what locations they are and what column headers to use
*/
//read _meteo.txt to find out how many stations exist
//at what locations they are and what column headers to use
readMetaData(myStations, vecColumnNames, path + "/" + prefix + ".txt");
if (vec_streampos.size() == 0) //the vec_streampos save file pointers for certain dates
vec_streampos = vector< map<Date, std::streampos> >(myStations.size());
......@@ -238,7 +237,6 @@ void GeotopIO::readMeteoData(const Date& dateStart, const Date& dateEnd,
ss << path << "/" << prefix << setw(4) << (ii+1) << ".txt";
filename = ss.str();
//cout << ss.str() << endl;
if (!IOUtils::validFileName(filename))
throw InvalidFileNameException(filename, AT);
......
......@@ -137,7 +137,6 @@ void GrassIO::read2DGrid(Grid2DObject& grid_out, const std::string& filename)
//Read one line after the other and parse values into Grid2DObject
for (unsigned int kk=nrows-1; (kk < nrows); kk--) {
getline(fin, line, eoln); //read complete line
//cout << "k:" << kk << "\n" << line << endl;
if (IOUtils::readLineToVec(line, tmpvec) != ncols) {
throw InvalidFormatException("Premature End " + filename, AT);
......@@ -177,7 +176,7 @@ void GrassIO::readDEM(DEMObject& dem_out)
void GrassIO::readLanduse(Grid2DObject& landuse_out)
{
string filename="";
cfg.getValue("LANDUSEFILE", "Input", filename); // cout << tmp << endl;
cfg.getValue("LANDUSEFILE", "Input", filename);
read2DGrid(landuse_out, filename);
}
......@@ -187,7 +186,7 @@ void GrassIO::readAssimilationData(const Date& date_in, Grid2DObject& da_out)
date_in.getDate(yyyy, MM, dd, hh, mm);
string filepath="";
cfg.getValue("DAPATH", "Input", filepath); // cout << tmp << endl;
cfg.getValue("DAPATH", "Input", filepath);
stringstream ss;
ss.fill('0');
......@@ -237,12 +236,12 @@ void GrassIO::write2DGrid(const Grid2DObject& grid_in, const std::string& name)
fout << setprecision(6) << fixed;
try {
fout << "north:" << (llcorner.getNorthing()+grid_in.cellsize*grid_in.nrows) << std::endl;
fout << "south:" << llcorner.getNorthing() << std::endl;
fout << "east:" << (llcorner.getEasting()+grid_in.cellsize*grid_in.ncols) << std::endl;
fout << "west:" << llcorner.getEasting() << std::endl;
fout << "rows:" << grid_in.nrows << std::endl;
fout << "cols:" << grid_in.ncols << std::endl;
fout << "north:" << (llcorner.getNorthing()+grid_in.cellsize*grid_in.nrows) << "\n";
fout << "south:" << llcorner.getNorthing() << "\n";
fout << "east:" << (llcorner.getEasting()+grid_in.cellsize*grid_in.ncols) << "\n";
fout << "west:" << llcorner.getEasting() << "\n";
fout << "rows:" << grid_in.nrows << "\n";
fout << "cols:" << grid_in.ncols << "\n";
for (unsigned int kk=grid_in.nrows-1; kk < grid_in.nrows; kk--) {
unsigned int ll = 0;
......@@ -260,7 +259,7 @@ void GrassIO::write2DGrid(const Grid2DObject& grid_in, const std::string& name)
} else {
fout << grid_in.grid2D(ll, kk);
}
fout << std::endl;
fout << "\n";
}
} catch(const std::exception& e) {
cout << "[E] " << AT << ": " << e.what() << std::endl;
......
......@@ -387,11 +387,11 @@ void ImisIO::readStationIDs(std::vector<std::string>& vecStationID)
cfg.getValue(ss.str(), "Input", current_station, Config::nothrow);
if (current_station != "") {
cout << "\tRead stationname " << ss.str() << ": '" << current_station << "'" << endl;
cout << "\tRead stationname " << ss.str() << ": '" << current_station << "'\n";
if (!isdigit(current_station[0])) {
vecStationID.push_back(current_station);
} else {
cout << "\t ==> discarded as neither IMIS, nor ENET, nor ANETZ station!" << endl;
cout << "\t ==> discarded as neither IMIS, nor ENET, nor ANETZ station!\n";
}
}
......@@ -497,7 +497,7 @@ void ImisIO::assimilateAnetzData(const Date& dateStart, const AnetzData& ad,
if (counter >= current_station_psum.size()) { break; } //should never happen
//cout << "Current slice date: " << current_slice_date.toString(Date::ISO)
// << " value: " << current_station_psum.at(counter) << endl;
// << " value: " << current_station_psum.at(counter) << "\n";
double& hnw = vecMeteo[stationindex][jj](MeteoData::HNW);
//cout << vecMeteo[stationindex][jj].date.toString(Date::ISO) << ": " << hnw;
......@@ -505,7 +505,7 @@ void ImisIO::assimilateAnetzData(const Date& dateStart, const AnetzData& ad,
//replace by psum if there is no own value measured
hnw = current_station_psum.at(counter);
}
//cout << " ---> " << hnw << endl;
//cout << " ---> " << hnw << "\n";
}
}
......@@ -528,8 +528,6 @@ void ImisIO::getAnetzHNW(const AnetzData& ad, const std::map<std::string, size_t
sum += ad.coeffs[ii] * vec_of_psums.at(vecIndex[ii])[kk];
}
psum.push_back(sum/12.0);
//cout << kk << " --> sum: " << sum/12 << endl;
}
} else {
if (ad.nrOfCoefficients != 3)
......@@ -540,8 +538,8 @@ void ImisIO::getAnetzHNW(const AnetzData& ad, const std::map<std::string, size_t
double sum = 0.0;
const double& hnw0 = vec_of_psums.at(vecIndex.at(0))[kk];
const double& hnw1 = vec_of_psums.at(vecIndex.at(1))[kk];
//cout << "0: Using " << ad.anetzstations[0] << " with hnw: " << hnw0 << endl;
//cout << "1: Using " << ad.anetzstations[1] << " with hnw: " << hnw1 << endl;
//cout << "0: Using " << ad.anetzstations[0] << " with hnw: " << hnw0 << "\n";
//cout << "1: Using " << ad.anetzstations[1] << " with hnw: " << hnw1 << "\n";
sum += ad.coeffs[0] * hnw0;
sum += ad.coeffs[1] * hnw1;
sum += ad.coeffs[2] * hnw0 * hnw1;
......
......@@ -136,7 +136,6 @@ void PGMIO::read2DGrid(Grid2DObject& grid_out, const std::string& filename)
//Read one line after the other and parse values into Grid2DObject
for (unsigned int kk=nrows-1; (kk < nrows); kk--) {
getline(fin, line, eoln); //read complete line
//cout << "k:" << kk << "\n" << line << endl;
if (IOUtils::readLineToVec(line, tmpvec) != ncols) {
throw InvalidFormatException("Premature End " + filename, AT);
......@@ -246,7 +245,7 @@ void PGMIO::write2DGrid(const Grid2DObject& grid_in, const std::string& name)
else
fout << "0" << " ";
}
fout << endl;
fout << "\n";
}
} catch(...) {
cout << "[E] " << AT << ": "<< endl;
......
......@@ -381,9 +381,6 @@ void SMETIO::copy_data(const smet::SMETReader& myreader,
if ((olwr_present) && (tmp_md(MeteoData::TSS) == IOUtils::nodata)) {//HACK
tmp_md(MeteoData::TSS) = olwr_to_tss(tmp_md("OLWR"));
}
//cout << tmp_md << endl;
//cout << endl;
}
}
......
......@@ -304,7 +304,7 @@ void SNIO::readMetaData()
}
}
vecAllStations.push_back(sd);
cout << "\t[i] Read meta data for station ID '" << station_id << "'" << endl;
cout << "\t[i] Read meta data for station ID '" << station_id << "'\n";
}
current_stationnr++;
......@@ -756,7 +756,7 @@ void SNIO::writeStationMeteo(const std::vector<MeteoData>& vecmd, const std::str
}
}
fout << endl;
fout << "\n";
}
fout << "END" << endl;
......@@ -764,7 +764,7 @@ void SNIO::writeStationMeteo(const std::vector<MeteoData>& vecmd, const std::str
if ((failure_count > 0) || (Dirichlet_failure_count > 0) || (optional_failure_count > 0)) {
cout << "[W] " << failure_count << " basic input data, " << Dirichlet_failure_count <<
" Dirichlet boundary condition data, and " << optional_failure_count <<
" optional data found missing when writing " << file_name << std::endl;
" optional data found missing when writing " << file_name << "\n";
}
}
......
Supports Markdown
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