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