Commit 53118958 authored by Ludovic Courtès's avatar Ludovic Courtès

data_storage: Separate out ALTA header parsing.

parent 5219ee9d
...@@ -19,6 +19,48 @@ ...@@ -19,6 +19,48 @@
# include <endian.h> # include <endian.h>
#endif #endif
// Key/value association list.
typedef std::map<std::string, std::string> alist;
// Read the ALTA header on INPUT and fill in RESULT as a list of key/value
// pairs.
static void read_header(std::istream &input, alist &result)
{
while(input.good())
{
if (input.peek() == '#')
{
input.get(); // consume the hash sign
std::string line;
std::getline(input, line);
std::stringstream linestream(line);
// Lines starting with '# ' are real comments and we ignore them.
// Others are key/value associations that we want to use.
if (linestream.peek() != ' ')
{
std::string key, rest;
linestream >> key;
if (!key.empty())
{
getline(linestream, rest);
if (key == "ALTA" && rest == "END HEADER")
{
break;
}
else
{
result[key] = rest;
}
}
}
}
// The first non-comment line terminates the header.
else break;
}
}
void vertical_segment::load_data_from_text(std::istream& input, void vertical_segment::load_data_from_text(std::istream& input,
vertical_segment& result, vertical_segment& result,
const arguments& args) const arguments& args)
...@@ -28,72 +70,61 @@ void vertical_segment::load_data_from_text(std::istream& input, ...@@ -28,72 +70,61 @@ void vertical_segment::load_data_from_text(std::istream& input,
result._nX = 0 ; result._nY = 0 ; result._nX = 0 ; result._nY = 0 ;
std::vector<int> vs ; int current_vs = 0 ; std::vector<int> vs ; int current_vs = 0 ;
while(input.good())
{
std::string line ;
std::getline(input, line) ;
std::stringstream linestream(line) ;
// Discard incorrect lines
if(linestream.peek() == '#')
{
linestream.ignore(1) ;
std::string comment ; alist header;
linestream >> comment ; read_header(input, header);
if(comment == std::string("DIM")) {
{ std::stringstream dim(header["DIM"]);
linestream >> result._nX >> result._nY ; dim >> result._nX >> result._nY;
}
vs.reserve(result.dimY()) ; vs.reserve(result.dimY()) ;
for(int k=0; k<result.dimY(); ++k) for(int k=0; k<result.dimY(); ++k)
{ {
vs[k] = 0 ; vs[k] = 0 ;
} }
result._min.resize(result.dimX()) ; result._min.resize(result.dimX()) ;
result._max.resize(result.dimX()) ; result._max.resize(result.dimX()) ;
min = args.get_vec("min", result._nX, -std::numeric_limits<float>::max()) ; min = args.get_vec("min", result._nX, -std::numeric_limits<float>::max()) ;
max = args.get_vec("max", result._nX, std::numeric_limits<float>::max()) ; max = args.get_vec("max", result._nX, std::numeric_limits<float>::max()) ;
#ifdef DEBUG #ifdef DEBUG
std::cout << "<<DEBUG>> data will remove outside of " << min << " -> " << max << " x-interval" << std::endl; std::cout << "<<DEBUG>> data will remove outside of " << min << " -> " << max << " x-interval" << std::endl;
#endif #endif
ymin = args.get_vec("ymin", result._nY, -std::numeric_limits<float>::max()) ; ymin = args.get_vec("ymin", result._nY, -std::numeric_limits<float>::max()) ;
ymax = args.get_vec("ymax", result._nY, std::numeric_limits<float>::max()) ; ymax = args.get_vec("ymax", result._nY, std::numeric_limits<float>::max()) ;
#ifdef DEBUG #ifdef DEBUG
std::cout << "<<DEBUG>> data will remove outside of " << ymin << " -> " << ymax << " y-interval" << std::endl; std::cout << "<<DEBUG>> data will remove outside of " << ymin << " -> " << ymax << " y-interval" << std::endl;
#endif #endif
for(int k=0; k<result.dimX(); ++k) for(int k=0; k<result.dimX(); ++k)
{ {
result._min[k] = std::numeric_limits<double>::max() ; result._min[k] = std::numeric_limits<double>::max() ;
result._max[k] = -std::numeric_limits<double>::max() ; result._max[k] = -std::numeric_limits<double>::max() ;
} }
}
else if(comment == std::string("VS")) result._in_param = params::parse_input(header["PARAM_IN"]);
{ result._out_param = params::parse_output(header["PARAM_OUT"]);
int t ;
linestream >> t ; {
vs[current_vs] = t ; ++current_vs ; int number;
} std::stringstream line(header["VS"]);
else if(comment == std::string("PARAM_IN")) line >> number;
{ vs[current_vs] = number; ++current_vs ;
std::string param; }
linestream >> param;
result._in_param = params::parse_input(param); // Now read the body.
} while(input.good())
else if(comment == std::string("PARAM_OUT")) {
{ std::string line ;
std::string param; std::getline(input, line) ;
linestream >> param; std::stringstream linestream(line) ;
result._out_param = params::parse_output(param);
} // Discard comments and empty lines.
continue ; if(line.empty() || linestream.peek() == '#')
}
else if(line.empty())
{ {
continue ; continue ;
} }
......
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