Commit e82a2f50 authored by Jan Oliver Oelerich's avatar Jan Oliver Oelerich

Allowing tab character as delimiter in the input file.

parent a438aec7
......@@ -58,7 +58,7 @@ void stemsalabim::Crystal::init(const std::string &crystal_file_content) {
regex e("Lattice=\"([0-9\\seE+-\\.]+)\"", regex_constants::icase);
smatch m;
if(regex_search(line, m, e)) {
tokens = algorithms::split(m[1], ' ');
tokens = algorithms::split(m[1], " \t");
algorithms::trim(tokens[0]);
algorithms::trim(tokens[4]);
......@@ -71,7 +71,7 @@ void stemsalabim::Crystal::init(const std::string &crystal_file_content) {
output::error("Wrong syntax of extended XYZ file line 2.");
}
} else {
tokens = algorithms::split(line, ' ');
tokens = algorithms::split(line, " \t");
algorithms::trim(tokens[0]);
algorithms::trim(tokens[1]);
......@@ -91,7 +91,7 @@ void stemsalabim::Crystal::init(const std::string &crystal_file_content) {
if(line.length() == 0)
continue;
tokens = algorithms::split(line, ' ');
tokens = algorithms::split(line, " \t");
if(tokens.size() != 5 && tokens.size() != 6) {
output::error("Init file needs to have 5 or 6 columns!\n");
......@@ -162,7 +162,7 @@ void stemsalabim::Crystal::readFieldFile(const std::string &field_file_content)
if(line.length() == 0)
continue;
tokens = algorithms::split(line, ' ');
tokens = algorithms::split(line, " \t");
if(tokens.size() != 4) {
output::error("Field file needs to have 4 columns!\n");
......
......@@ -65,24 +65,33 @@ namespace stemsalabim {
/*!
* Split a string by a (char) delimiter.
* @param s The string to split
* @param delim The delimiter character
* @param str The string to split
* @param delimiters The delimiter characters
* @param trimEmpty Whether or not empty tokens should be excluded.
* @return vector of strings of the parts after splitting
*/
inline std::vector<std::string> split(const std::string &s, char delim) {
// clear the result vector
std::vector<std::string> elems;
inline std::vector<std::string>
split(const std::string &str, const std::string &delimiters = " ", bool trimEmpty = true) {
std::string::size_type pos, lastPos = 0, length = str.length();
// this will hold our token
std::string item("");
std::vector<std::string> tokens;
// use stdlib to tokenize the string
std::stringstream ss(s);
while(getline(ss, item, delim))
if(!item.empty())
elems.push_back(item);
using value_type = typename std::vector<std::string>::value_type;
using size_type = typename std::vector<std::string>::size_type;
return elems;
while(lastPos < length + 1) {
pos = str.find_first_of(delimiters, lastPos);
if(pos == std::string::npos) {
pos = length;
}
if(pos != lastPos || !trimEmpty)
tokens.emplace_back(value_type(str.data() + lastPos, (size_type) pos - lastPos));
lastPos = pos + 1;
}
return tokens;
}
/*!
......@@ -353,8 +362,7 @@ namespace stemsalabim {
* @return The rescaled image as a similar, flattened vector of intensities.
*/
inline
std::vector<float>
inline std::vector<float>
bilinearRescale(const std::vector<float> &input, unsigned int dest_width, unsigned int dest_height,
unsigned int src_width, unsigned int src_height) {
std::vector<float> out(dest_width * dest_height, 0);
......
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