38#include <boost/algorithm/string.hpp>
39#include <boost/tokenizer.hpp>
44#include <boost/format.hpp>
60 :
PtsIO(pComm, sharedFilesystem)
74 size_t nTotvars = ptsField->GetNFields() + ptsField->GetDim();
75 size_t np = ptsField->GetNpoints();
77 std::string filename =
SetUpOutput(outFile,
true, backup);
80 std::ofstream ptsFile;
81 ptsFile.open(filename.c_str());
83 std::vector<std::string> xyz;
87 xyz.resize(ptsField->GetDim());
89 std::string fn = boost::algorithm::join(xyz,
",");
90 ptsFile <<
"# " << fn <<
",";
91 fn = boost::algorithm::join(ptsField->GetFieldNames(),
",");
96 ptsField->GetPts(pts);
97 for (
size_t i = 0; i < np; ++i)
100 for (
size_t j = 1; j < nTotvars; ++j)
102 ptsFile <<
"," << pts[j][i];
104 ptsFile << std::endl;
114 std::stringstream errstr;
115 errstr <<
"Unable to load file: " << inFile << std::endl;
116 std::ifstream in(inFile.c_str());
117 ASSERTL0(in.is_open(), errstr.str());
120 std::getline(in, line);
121 boost::erase_first(line,
"#");
123 std::vector<std::string> fieldNames;
125 ASSERTL0(valid,
"Unable to process list of fields from line: " + line);
128 for (
auto &it : fieldNames)
130 if (it ==
"x" || it ==
"y" || it ==
"z")
136 ASSERTL0(dim,
"Failed to find a paramater labelled \"x\",\"y\" or \"z\" "
138 inFile +
". Is the coordinated labelled something else?");
140 size_t totvars = fieldNames.size();
141 std::vector<std::string> dimNames = {
"x",
"y",
"z"};
143 for (
int i = 0; i < dim; ++i)
145 auto p =
std::find(fieldNames.begin(), fieldNames.end(), dimNames[i]);
146 if (
p != fieldNames.end())
148 auto j = std::distance(fieldNames.begin(),
p);
154 std::vector<NekDouble> ptsSerial;
155 typedef boost::tokenizer<boost::escaped_list_separator<char>> Tokenizer;
157 while (getline(in, line))
161 ASSERTL0(std::distance(tok.begin(), tok.end()) ==
162 std::iterator_traits<Tokenizer::iterator>::difference_type(
164 "wrong number of columns in line: " + line);
166 bool ReadValue =
true;
173 for (
int j = 0; j < dim; ++j)
175 if (cnt == loc_coord[j])
177 NekDouble CoordVal = boost::lexical_cast<NekDouble>(
178 boost::trim_copy(std::string(it)));
183 if ((CoordVal < Range->m_xmin) ||
184 (CoordVal > Range->m_xmax))
192 if ((CoordVal < Range->m_ymin) ||
193 (CoordVal > Range->m_ymax))
201 if ((CoordVal < Range->m_zmin) ||
202 (CoordVal > Range->m_zmax))
219 ptsSerial.push_back(boost::lexical_cast<NekDouble>(
220 boost::trim_copy(std::string(it))));
222 catch (
const boost::bad_lexical_cast &)
225 "could not convert line: " + line);
231 size_t npts = ptsSerial.size() / totvars;
234 for (
size_t i = 0; i < totvars; ++i)
239 for (
size_t i = 0; i < npts; ++i)
241 for (
size_t j = 0; j < totvars; ++j)
243 pts[j][i] = ptsSerial[i * totvars + j];
248 for (
int i = 0; i < dim; ++i)
250 auto p =
std::find(fieldNames.begin(), fieldNames.end(), dimNames[i]);
251 if (
p != fieldNames.end())
253 auto j = std::distance(fieldNames.begin(),
p);
264 std::string tmp2 = fieldNames[i];
265 fieldNames[i] = fieldNames[j];
266 fieldNames[j] = tmp2;
269 fieldNames.erase(fieldNames.begin(), fieldNames.begin() + dim);
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
void Write(const std::string &outFile, const PtsFieldSharedPtr &ptsField, const bool backup=false)
Save a pts field to a file.
virtual void v_ImportFieldData(const std::string inFile, PtsFieldSharedPtr &ptsField, DomainRangeShPtr &Range) override
virtual std::string v_GetFileEnding() const override
CsvIO(LibUtilities::CommSharedPtr pComm, bool sharedFilesystem=false)
std::string SetUpOutput(const std::string outname, bool perRank, bool backup=false)
Set up the filesystem ready for output.
void SetUpFieldMetaData(const std::string outname)
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
std::shared_ptr< PtsField > PtsFieldSharedPtr
std::shared_ptr< DomainRange > DomainRangeShPtr
static DomainRangeShPtr NullDomainRangeShPtr
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
The above copyright notice and this permission notice shall be included.