WSL/SLF GitLab Repository

Commit 64036efa authored by Thomas Egger's avatar Thomas Egger
Browse files

Bugfix for libsmet and thus release of the readSpecialPoints function in...

Bugfix for libsmet and thus release of the readSpecialPoints function in SMETIO.cc. It is now possible to read a vector of Coords objects through SMETIO, the format of the SMET file could be something like this:

SMET 1.1 ASCII
[HEADER]
station_id = my_pts
epsg 	   = 32632
nodata	   = -999
fields 	   = easting northing altitude
[DATA]
713700 5.05578e+06 0
730900 5.15678e+06 0
674200 5.06278e+06 0
674400 5.08078e+06 0
parent c7daa0b4
......@@ -701,7 +701,7 @@ void SMETReader::convert_to_MKSA(const bool& in_mksa)
std::string SMETReader::get_field_name(const size_t& nr_of_field)
{
if (nr_of_field < nr_of_fields){
return vec_fieldnames[nr_of_fields];
return vec_fieldnames[nr_of_field];
} else {
stringstream ss;
ss << "Trying to access field #" << nr_of_field << " (starting from 0) of " << nr_of_fields << " fields in file \"" << filename << "\". ";
......@@ -1006,7 +1006,7 @@ void SMETReader::read(std::vector<std::string>& vec_timestamp, std::vector<doubl
void SMETReader::read(std::vector<double>& vec_data)
{
if (timestamp_present)
SMETException("Requesting not to read timestamp when there is one present in '"+filename+"'", SMET_AT);
throw SMETException("Requesting not to read timestamp when there is one present in '"+filename+"'", SMET_AT);
vector<string> tmp_vec;
......@@ -1081,7 +1081,7 @@ void SMETReader::read_data_ascii(std::ifstream& fin, std::vector<std::string>& v
}
for (size_t ii=0; ii<tmp_vec.size(); ii++){
if (ii == timestamp_field){
if (timestamp_present && (ii == timestamp_field)) {
vec_timestamp.push_back(tmp_vec[ii]);
shift = 1;
} else {
......
......@@ -707,9 +707,6 @@ bool SMETIO::checkConsistency(const std::vector<MeteoData>& vecMeteo, StationDat
void SMETIO::readSpecialPoints(std::vector<Coords>& pts)
{
//The code below is not valid yet, due to issues with libsmet -> invalid this method
throw IOException("Nothing implemented here", AT);
std::string filename="", line_in="";
cfg.getValue("SPECIALPTSFILE", "Input", filename);
if (!IOUtils::fileExists(filename)) {
......@@ -723,33 +720,36 @@ void SMETIO::readSpecialPoints(std::vector<Coords>& pts)
const int epsg = myreader.get_header_intvalue("epsg");
const double smet_nodata = myreader.get_header_doublevalue("nodata");
if(myreader.location_in_data(smet::WGS84)==true) {
if (myreader.location_in_data(smet::WGS84)==true) {
size_t lat_fd=IOUtils::unodata, lon_fd=IOUtils::unodata;
size_t alt_fd=IOUtils::unodata;
for(size_t ii=0; ii<nr_fields; ii++) {
for (size_t ii=0; ii<nr_fields; ii++) {
const string tmp = myreader.get_field_name(ii);
if(tmp=="latitude") lat_fd=ii;
if(tmp=="longitude") lon_fd=ii;
if(tmp=="altitude") alt_fd=ii;
if (tmp=="latitude") lat_fd=ii;
if (tmp=="longitude") lon_fd=ii;
if (tmp=="altitude") alt_fd=ii;
}
for(size_t ii=0; ii<vec_data.size(); ii+=nr_fields) {
for (size_t ii=0; ii<vec_data.size(); ii+=nr_fields) {
Coords point;
point.setLatLon(vec_data[ii+lat_fd], vec_data[ii+lon_fd], vec_data[ii+alt_fd]);
pts.push_back(point);
}
} else if(myreader.location_in_data(smet::EPSG)==true) {
if(epsg==(int)floor(smet_nodata + 0.1))
} else if (myreader.location_in_data(smet::EPSG)==true) {
if (epsg==(int)floor(smet_nodata + 0.1))
throw InvalidFormatException("In file \""+filename+"\", missing EPSG code in header!", AT);
size_t east_fd=IOUtils::unodata, north_fd=IOUtils::unodata;
size_t alt_fd=IOUtils::unodata;
for(size_t ii=0; ii<nr_fields; ii++) {
for (size_t ii=0; ii<nr_fields; ii++) {
const string tmp = myreader.get_field_name(ii);
if(tmp=="easting") east_fd=ii;
if(tmp=="northing") north_fd=ii;
if(tmp=="altitude") alt_fd=ii;
if (tmp=="easting") east_fd=ii;
if (tmp=="northing") north_fd=ii;
if (tmp=="altitude") alt_fd=ii;
}
for(size_t ii=0; ii<vec_data.size(); ii+=nr_fields) {
if ((east_fd == IOUtils::unodata) || (north_fd == IOUtils::unodata) || (alt_fd == IOUtils::unodata))
throw InvalidFormatException("File \""+filename+"\" does not contain all data fields necessary for EPSG coordinates", AT);
for (size_t ii=0; ii<vec_data.size(); ii+=nr_fields) {
Coords point;
point.setEPSG(epsg);
point.setXY(vec_data[ii+east_fd], vec_data[ii+north_fd], vec_data[ii+alt_fd]);
......@@ -758,10 +758,6 @@ void SMETIO::readSpecialPoints(std::vector<Coords>& pts)
} else {
throw InvalidFormatException("File \""+filename+"\" does not contain expected location information in DATA section!", AT);
}
for(size_t ii=0; ii<pts.size(); ii++) {
std::cout << pts[ii] << "\n";
}
}
void SMETIO::write2DGrid(const Grid2DObject& /*grid_in*/, const std::string& /*name*/)
......
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