Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Public Types | Public Member Functions | Public Attributes | Protected Attributes | Private Member Functions | List of all members
MooseUtils::DelimitedFileReaderTempl< T > Class Template Reference

Utility class for reading delimited data (e.g., CSV data). More...

#include <DelimitedFileReader.h>

Public Types

enum  HeaderFlag { HeaderFlag::OFF = 0, HeaderFlag::ON = 1, HeaderFlag::AUTO = 2 }
 
enum  FormatFlag { FormatFlag::COLUMNS = 0, FormatFlag::ROWS = 1 }
 

Public Member Functions

 DelimitedFileReaderTempl (const std::string &filename, const libMesh::Parallel::Communicator *comm=nullptr)
 
void read ()
 Perform the actual data reading. More...
 
std::size_t numEntries () const
 Get the total number of entries in the file. More...
 
void setFileName (const std::string &new_file)
 Set the file name, used to change the file to read from We also reset the column/row names as a second read might have different names. More...
 
const std::vector< std::string > & getNames () const
 Return the column/row names. More...
 
const std::vector< std::vector< T > > & getData () const
 Return the rows/columns of data. More...
 
const std::vector< Point > getDataAsPoints () const
 Get the data in Point format. More...
 
template<>
const std::vector< Point > getDataAsPoints () const
 
void setIgnoreEmptyLines (bool value)
 Set/Get methods for file format controls. More...
 
bool getIgnoreEmptyLines () const
 
void setFormatFlag (FormatFlag value)
 
FormatFlag getFormatFlag () const
 
void setDelimiter (const std::string &value)
 
const std::string & setDelimiter () const
 
void setHeaderFlag (HeaderFlag value)
 
HeaderFlag getHeaderFlag () const
 
void setComment (const std::string &value)
 
const std::string & getComment () const
 
const std::vector< T > & getData (const std::string &name) const
 Return the row/column of data for a specified header entry. More...
 
const std::vector< T > & getData (std::size_t index) const
 

Public Attributes

const std::size_t INVALID_SIZE = std::numeric_limits<std::size_t>::max()
 

Protected Attributes

std::string _filename
 The supplied filename. More...
 
HeaderFlag _header_flag
 Flag indicating if the file contains a header. More...
 
std::string _delimiter
 The delimiter separating the supplied data entires. More...
 
bool _ignore_empty_lines
 Flag for ignoring empty lines. More...
 
std::vector< std::string > _names
 Storage for the read or generated column names. More...
 
std::vector< std::vector< T > > _data
 Storage for the read data columns. More...
 
const libMesh::Parallel::Communicator *const _communicator
 Communicator. More...
 
FormatFlag _format_flag
 Format "rows" vs "columns". More...
 
std::vector< std::size_t > _row_offsets
 Row offsets (only used with _format == "rows") More...
 
std::string _row_comment
 Hide row comments. More...
 

Private Member Functions

void processLine (const std::string &line, std::vector< T > &row, const unsigned int &num)
 Populate supplied vector with content from line. More...
 
bool preprocessLine (std::string &line, const unsigned int &num)
 Check the content of the line and if it should be skipped. More...
 
const std::string & delimiter (const std::string &line)
 Determine the delimiter. More...
 
bool header (const std::string &line)
 Return the header flag, if it is set to AUTO attempt to determine if a header exists in line. More...
 
void readColumnData (std::ifstream &stream_data, std::vector< T > &output)
 Read the numeric data as rows or columns into a single vector. More...
 
void readRowData (std::ifstream &stream_data, std::vector< T > &output)
 

Detailed Description

template<typename T>
class MooseUtils::DelimitedFileReaderTempl< T >

Utility class for reading delimited data (e.g., CSV data).

Parameters
filenameA string for the filename to read.
commA pointer to a Communicator object (see below).

This class assumes that all data is numeric and can be converted to a C++ double. If a Communicator is provide then it will only read on processor 0 and broadcast the data to all processors. If not provided it will read on all processors.

Definition at line 36 of file DelimitedFileReader.h.

Member Enumeration Documentation

◆ FormatFlag

template<typename T >
enum MooseUtils::DelimitedFileReaderTempl::FormatFlag
strong
Enumerator
COLUMNS 
ROWS 

Definition at line 46 of file DelimitedFileReader.h.

47  {
48  COLUMNS = 0,
49  ROWS = 1
50  };

◆ HeaderFlag

template<typename T >
enum MooseUtils::DelimitedFileReaderTempl::HeaderFlag
strong
Enumerator
OFF 
ON 
AUTO 

Definition at line 39 of file DelimitedFileReader.h.

40  {
41  OFF = 0,
42  ON = 1,
43  AUTO = 2
44  };

Constructor & Destructor Documentation

◆ DelimitedFileReaderTempl()

template<typename T >
MooseUtils::DelimitedFileReaderTempl< T >::DelimitedFileReaderTempl ( const std::string &  filename,
const libMesh::Parallel::Communicator comm = nullptr 
)

Definition at line 26 of file DelimitedFileReader.C.

28  : _filename(filename),
30  _ignore_empty_lines(true),
31  _communicator(comm),
33 {
34 }
HeaderFlag _header_flag
Flag indicating if the file contains a header.
std::string _filename
The supplied filename.
const libMesh::Parallel::Communicator *const _communicator
Communicator.
bool _ignore_empty_lines
Flag for ignoring empty lines.
FormatFlag _format_flag
Format "rows" vs "columns".

Member Function Documentation

◆ delimiter()

template<typename T >
const std::string & MooseUtils::DelimitedFileReaderTempl< T >::delimiter ( const std::string &  line)
private

Determine the delimiter.

If the setDelimiter method is not called the data is inspected, if a ',' is found it is assumed to be the delimiter as is the case for . Otherwise a space is used.

Definition at line 389 of file DelimitedFileReader.C.

390 {
391  if (_delimiter.empty())
392  {
393  if (line.find(",") != std::string::npos)
394  _delimiter = ",";
395  else if (line.find("\t") != std::string::npos)
396  _delimiter = "\t";
397  else
398  _delimiter = " ";
399  }
400  return _delimiter;
401 }
std::string _delimiter
The delimiter separating the supplied data entires.

◆ getComment()

template<typename T >
const std::string& MooseUtils::DelimitedFileReaderTempl< T >::getComment ( ) const
inline

Definition at line 93 of file DelimitedFileReader.h.

93 { return _row_comment; }
std::string _row_comment
Hide row comments.

◆ getData() [1/3]

template<typename T >
const std::vector< std::vector< T > > & MooseUtils::DelimitedFileReaderTempl< T >::getData ( ) const

◆ getData() [2/3]

template<typename T >
const std::vector< T > & MooseUtils::DelimitedFileReaderTempl< T >::getData ( const std::string &  name) const

Return the row/column of data for a specified header entry.

Definition at line 192 of file DelimitedFileReader.C.

193 {
194  const auto it = find(_names.begin(), _names.end(), name);
195  if (it == _names.end())
196  mooseError("Could not find '", name, "' in header of file ", _filename, ".");
197  return _data[std::distance(_names.begin(), it)];
198 }
std::string name(const ElemQuality q)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::string _filename
The supplied filename.
std::vector< std::string > _names
Storage for the read or generated column names.
std::vector< std::vector< T > > _data
Storage for the read data columns.

◆ getData() [3/3]

template<typename T >
const std::vector< T > & MooseUtils::DelimitedFileReaderTempl< T >::getData ( std::size_t  index) const

Definition at line 202 of file DelimitedFileReader.C.

203 {
204  if (index >= _data.size())
205  mooseError("The supplied index ",
206  index,
207  " is out-of-range for the available data in file '",
208  _filename,
209  "' which contains ",
210  _data.size(),
211  " items.");
212  return _data[index];
213 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::string _filename
The supplied filename.
std::vector< std::vector< T > > _data
Storage for the read data columns.

◆ getDataAsPoints() [1/2]

template<typename T >
const std::vector< Point > MooseUtils::DelimitedFileReaderTempl< T >::getDataAsPoints ( ) const

Get the data in Point format.

This performs checks that the data is of valid dimensions to do so.

Definition at line 185 of file DelimitedFileReader.C.

Referenced by FilePositions::FilePositions(), CombinerGenerator::fillPositions(), MultiApp::fillPositions(), and XYDelaunayGenerator::XYDelaunayGenerator().

186 {
187  mooseError("Not implemented");
188 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302

◆ getDataAsPoints() [2/2]

template<>
const std::vector< Point > MooseUtils::DelimitedFileReaderTempl< double >::getDataAsPoints ( ) const

Definition at line 153 of file DelimitedFileReader.C.

154 {
155  std::vector<Point> point_data;
156 
157  for (std::size_t i = 0; i < _data.size(); ++i)
158  {
159  Point point;
160 
161  // Other checks in this class ensure that each data entry has the same number of values;
162  // here we just need to check that each data set has LIBMESH_DIM entries (which we could do by
163  // equivalently checking that the total number of entries is divisibly by LIBMESH_DIM
164  // _and_ one of these data sets has LIBMESH_DIM entries (consider the fringe case where
165  // LIBMESH_DIM is 3, but you accidentally put a point file like
166  // 0 0
167  // 1 0
168  // 2 0
169  // where each point is the same length _and_ the total points is still divisible by 3.
170  // This check here is more exact.
171  if (_data.at(i).size() != LIBMESH_DIM)
172  mooseError("Each point in file ", _filename, " must have ", LIBMESH_DIM, " entries");
173 
174  for (std::size_t j = 0; j < LIBMESH_DIM; ++j)
175  point(j) = _data.at(i).at(j);
176 
177  point_data.push_back(point);
178  }
179 
180  return point_data;
181 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::string _filename
The supplied filename.
std::vector< std::vector< T > > _data
Storage for the read data columns.

◆ getFormatFlag()

template<typename T >
FormatFlag MooseUtils::DelimitedFileReaderTempl< T >::getFormatFlag ( ) const
inline

Definition at line 84 of file DelimitedFileReader.h.

84 { return _format_flag; }
FormatFlag _format_flag
Format "rows" vs "columns".

◆ getHeaderFlag()

template<typename T >
HeaderFlag MooseUtils::DelimitedFileReaderTempl< T >::getHeaderFlag ( ) const
inline

Definition at line 90 of file DelimitedFileReader.h.

90 { return _header_flag; }
HeaderFlag _header_flag
Flag indicating if the file contains a header.

◆ getIgnoreEmptyLines()

template<typename T >
bool MooseUtils::DelimitedFileReaderTempl< T >::getIgnoreEmptyLines ( ) const
inline

Definition at line 81 of file DelimitedFileReader.h.

81 { return _ignore_empty_lines; }
bool _ignore_empty_lines
Flag for ignoring empty lines.

◆ getNames()

template<typename T >
const std::vector< std::string > & MooseUtils::DelimitedFileReaderTempl< T >::getNames ( ) const

Return the column/row names.

Definition at line 139 of file DelimitedFileReader.C.

Referenced by TimedSubdomainModifier::buildFromFile(), PiecewiseTabularBase::buildFromFile(), and CSVReaderVectorPostprocessor::CSVReaderVectorPostprocessor().

140 {
141  return _names;
142 }
std::vector< std::string > _names
Storage for the read or generated column names.

◆ header()

template<typename T >
bool MooseUtils::DelimitedFileReaderTempl< T >::header ( const std::string &  line)
private

Return the header flag, if it is set to AUTO attempt to determine if a header exists in line.

Definition at line 405 of file DelimitedFileReader.C.

406 {
407  switch (_header_flag)
408  {
409  case HeaderFlag::OFF:
410  return false;
411  case HeaderFlag::ON:
412  return true;
413  default:
414 
415  // Attempt to convert the line, if it fails assume it is a header
416  std::vector<double> row;
417  bool contains_alpha = !MooseUtils::tokenizeAndConvert<double>(line, row, delimiter(line));
418 
419  // Based on auto detect set the flag to TRUE|FALSE to short-circuit this check for each line
420  // in the case of row data.
421  _header_flag = contains_alpha ? HeaderFlag::ON : HeaderFlag::OFF;
422  return contains_alpha;
423  }
424 }
HeaderFlag _header_flag
Flag indicating if the file contains a header.
const std::string & delimiter(const std::string &line)
Determine the delimiter.

◆ numEntries()

template<typename T >
std::size_t MooseUtils::DelimitedFileReaderTempl< T >::numEntries ( ) const

Get the total number of entries in the file.

Returns
number of entries in file

Definition at line 128 of file DelimitedFileReader.C.

129 {
130  std::size_t n_entries = 0;
131  for (std::size_t i = 0; i < _data.size(); ++i)
132  n_entries += _data[i].size();
133 
134  return n_entries;
135 }
std::vector< std::vector< T > > _data
Storage for the read data columns.

◆ preprocessLine()

template<typename T >
bool MooseUtils::DelimitedFileReaderTempl< T >::preprocessLine ( std::string &  line,
const unsigned int num 
)
private

Check the content of the line and if it should be skipped.

Parameters
lineComplete line being read.
numThe current line number.
Returns
True if the line should be skipped.

Definition at line 342 of file DelimitedFileReader.C.

343 {
344  // Handle row comments
345  std::size_t index = _row_comment.empty() ? line.size() : line.find_first_of(_row_comment);
346  line = MooseUtils::trim(line.substr(0, index));
347 
348  // Ignore empty lines
349  if (line.empty())
350  {
352  return true;
353  else
354  mooseError("Failed to read line ", num, " in file ", _filename, ". The line is empty.");
355  }
356  return false;
357 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::string _filename
The supplied filename.
std::string trim(const std::string &str, const std::string &white_space=" \\\)
Standard scripting language trim function.
Definition: MooseUtils.C:221
bool _ignore_empty_lines
Flag for ignoring empty lines.
std::string _row_comment
Hide row comments.

◆ processLine()

template<typename T >
void MooseUtils::DelimitedFileReaderTempl< T >::processLine ( const std::string &  line,
std::vector< T > &  row,
const unsigned int num 
)
private

Populate supplied vector with content from line.

Parameters
lineThe line to extract data from.
rowThe vector to populate.
numThe current line number.

Definition at line 361 of file DelimitedFileReader.C.

364 {
365  std::string line_copy = line;
366  // Convert booleans to numeric
367  if constexpr (!std::is_same_v<T, std::string>)
368  {
369  line_copy = MooseUtils::toLower(line_copy);
370  line_copy = MooseUtils::replaceAll(line_copy, "true", "1");
371  line_copy = MooseUtils::replaceAll(line_copy, "false", "0");
372  }
373 
374  // Separate the row and error if it fails
375  bool status = MooseUtils::tokenizeAndConvert<T>(line_copy, row, delimiter(line));
376  if (!status)
377  mooseError("Failed to convert a delimited data into double when reading line ",
378  num,
379  " in file ",
380  _filename,
381  ".\n LINE ",
382  num,
383  ": ",
384  line);
385 }
std::string toLower(const std::string &name)
Convert supplied string to lower case.
Definition: MooseUtils.C:1068
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::string _filename
The supplied filename.
MPI_Status status
const std::string & delimiter(const std::string &line)
Determine the delimiter.
std::string replaceAll(std::string str, const std::string &from, const std::string &to)
Replaces all occurrences of from in str with to and returns the result.
Definition: MooseUtils.C:141

◆ read()

template<typename T >
void MooseUtils::DelimitedFileReaderTempl< T >::read ( )

Perform the actual data reading.

This is a separate method to allow for the filename to be read multiple times.

Definition at line 38 of file DelimitedFileReader.C.

Referenced by TimedSubdomainModifier::buildFromFile(), PiecewiseTabularBase::buildFromFile(), CSVFileTimes::CSVFileTimes(), CSVReaderVectorPostprocessor::CSVReaderVectorPostprocessor(), FilePositions::FilePositions(), CombinerGenerator::fillPositions(), MultiApp::fillPositions(), PropertyReadFile::getFileNames(), CSVTimeSequenceStepper::init(), PropertyReadFile::readData(), and XYDelaunayGenerator::XYDelaunayGenerator().

39 {
40  // Number of columns
41  std::size_t n_cols;
42 
43  // Storage for the raw data
44  std::vector<T> raw;
45  std::size_t size_raw = 0;
46  std::size_t size_offsets = 0;
47 
48  // Read data
49  if (_communicator == nullptr || _communicator->rank() == 0)
50  {
51  // Check the file
53 
54  // Create the file stream and do nothing if the file is empty
55  std::ifstream stream_data(_filename);
56  if (stream_data.peek() == std::ifstream::traits_type::eof())
57  return;
58 
59  // Read/generate the header
61  readRowData(stream_data, raw);
62  else
63  readColumnData(stream_data, raw);
64 
65  // Set the number of columns
66  n_cols = _names.size();
67 
68  // Close the stream
69  stream_data.close();
70 
71  // Set raw data vector size
72  size_raw = raw.size();
73  size_offsets = _row_offsets.size();
74  }
75 
76  if (_communicator != nullptr)
77  {
78  // Broadcast column names
79  _communicator->broadcast(n_cols);
80  _names.resize(n_cols);
82 
83  // Broadcast raw data
84  _communicator->broadcast(size_raw);
85  raw.resize(size_raw);
87 
88  // Broadcast row offsets
90  {
91  _communicator->broadcast(size_offsets);
92  _row_offsets.resize(size_offsets);
94  }
95  }
96 
97  // Resize the internal storage
98  _data.resize(n_cols);
99 
100  // Process "row" formatted data
102  {
103  typename std::vector<T>::iterator start = raw.begin();
104  for (std::size_t j = 0; j < n_cols; ++j)
105  {
106  _data[j] = std::vector<T>(start, start + _row_offsets[j]);
107  std::advance(start, _row_offsets[j]);
108  }
109  }
110 
111  // Process "column" formatted data
112  else
113  {
114  mooseAssert(raw.size() % n_cols == 0,
115  "The raw data is not evenly divisible by the number of columns.");
116  const std::size_t n_rows = raw.size() / n_cols;
117  for (std::size_t j = 0; j < n_cols; ++j)
118  {
119  _data[j].resize(n_rows);
120  for (std::size_t i = 0; i < n_rows; ++i)
121  _data[j][i] = raw[i * n_cols + j];
122  }
123  }
124 }
void readRowData(std::ifstream &stream_data, std::vector< T > &output)
std::string _filename
The supplied filename.
const libMesh::Parallel::Communicator *const _communicator
Communicator.
void readColumnData(std::ifstream &stream_data, std::vector< T > &output)
Read the numeric data as rows or columns into a single vector.
processor_id_type rank() const
std::vector< std::string > _names
Storage for the read or generated column names.
std::vector< std::vector< T > > _data
Storage for the read data columns.
bool checkFileReadable(const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true, bool check_for_git_lfs_pointer=true)
Checks to see if a file is readable (exists and permissions)
Definition: MooseUtils.C:260
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
FormatFlag _format_flag
Format "rows" vs "columns".
std::vector< std::size_t > _row_offsets
Row offsets (only used with _format == "rows")

◆ readColumnData()

template<typename T >
void MooseUtils::DelimitedFileReaderTempl< T >::readColumnData ( std::ifstream &  stream_data,
std::vector< T > &  output 
)
private

Read the numeric data as rows or columns into a single vector.

Definition at line 217 of file DelimitedFileReader.C.

218 {
219  // Local storage for the data being read
220  std::string line;
221  std::vector<T> row;
222 
223  // Keep track of the line number for error reporting
224  unsigned int count = 0;
225 
226  // Number of columns expected based on the first row of the data
227  std::size_t n_cols = INVALID_SIZE;
228 
229  // Read the lines
230  while (std::getline(stream_data, line))
231  {
232  // Increment line counter and clear any tokenized data
233  count++;
234  row.clear();
235 
236  // Ignore empty and/or comment lines, if applicable
237  if (preprocessLine(line, count))
238  continue;
239 
240  // Read header, if the header exists and the column names do not exist.
241  if (_names.empty() && header(line))
242  {
243  MooseUtils::tokenize(line, _names, 1, delimiter(line));
244  for (std::string & str : _names)
245  str = MooseUtils::trim(str);
246  continue;
247  }
248 
249  // Separate the row and error if it fails
250  processLine(line, row, count);
251 
252  // Set the number of columns
253  if (n_cols == INVALID_SIZE)
254  n_cols = row.size();
255 
256  // Check number of columns
257  if (row.size() != n_cols)
258  mooseError("The number of columns read (",
259  row.size(),
260  ") does not match the number of columns expected (",
261  n_cols,
262  ") based on the first row of the file when reading row ",
263  count,
264  " in file ",
265  _filename,
266  ".");
267 
268  // Append data
269  output.insert(output.end(), row.begin(), row.end());
270  }
271 
272  // If the names have not been assigned, create the default names
273  if (_names.empty())
274  {
275  _names.resize(n_cols);
276  int padding = MooseUtils::numDigits(n_cols);
277  for (std::size_t i = 0; i < n_cols; ++i)
278  {
279  std::stringstream ss;
280  ss << "column_" << std::setw(padding) << std::setfill('0') << i;
281  _names[i] = ss.str();
282  }
283  }
284 }
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
Definition: MooseUtils.h:812
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::string _filename
The supplied filename.
std::vector< std::string > _names
Storage for the read or generated column names.
std::string trim(const std::string &str, const std::string &white_space=" \\\)
Standard scripting language trim function.
Definition: MooseUtils.C:221
bool header(const std::string &line)
Return the header flag, if it is set to AUTO attempt to determine if a header exists in line...
const std::string & delimiter(const std::string &line)
Determine the delimiter.
bool preprocessLine(std::string &line, const unsigned int &num)
Check the content of the line and if it should be skipped.
int numDigits(const T &num)
Return the number of digits for a number.
Definition: MooseUtils.h:984
void processLine(const std::string &line, std::vector< T > &row, const unsigned int &num)
Populate supplied vector with content from line.

◆ readRowData()

template<typename T >
void MooseUtils::DelimitedFileReaderTempl< T >::readRowData ( std::ifstream &  stream_data,
std::vector< T > &  output 
)
private

Definition at line 288 of file DelimitedFileReader.C.

289 {
290  // Local storage for the data being read
291  std::string line;
292  std::vector<T> row;
293  unsigned int linenum = 0; // line number in file
294 
295  // Clear existing data
296  _names.clear();
297  _row_offsets.clear();
298 
299  // Read the lines
300  while (std::getline(stream_data, line))
301  {
302  // Increment line counter and clear any tokenized data
303  linenum++;
304  row.clear();
305 
306  // Ignore empty lines
307  if (preprocessLine(line, linenum))
308  continue;
309 
310  if (header(line))
311  {
312  std::size_t index = line.find_first_of(delimiter(line));
313  _names.push_back(line.substr(0, index));
314  line = line.substr(index);
315  }
316 
317  // Separate the row and error if it fails
318  processLine(line, row, linenum);
319 
320  // Store row offsets to allow for un-even rows
321  _row_offsets.push_back(row.size());
322 
323  // Append data
324  output.insert(output.end(), row.begin(), row.end());
325  }
326 
327  // Assign row names if not provided via header
328  if (_names.empty())
329  {
330  int padding = MooseUtils::numDigits(_row_offsets.size());
331  for (std::size_t i = 0; i < _row_offsets.size(); ++i)
332  {
333  std::stringstream ss;
334  ss << "row_" << std::setw(padding) << std::setfill('0') << i;
335  _names.push_back(ss.str());
336  }
337  }
338 }
std::vector< std::string > _names
Storage for the read or generated column names.
bool header(const std::string &line)
Return the header flag, if it is set to AUTO attempt to determine if a header exists in line...
const std::string & delimiter(const std::string &line)
Determine the delimiter.
bool preprocessLine(std::string &line, const unsigned int &num)
Check the content of the line and if it should be skipped.
int numDigits(const T &num)
Return the number of digits for a number.
Definition: MooseUtils.h:984
void processLine(const std::string &line, std::vector< T > &row, const unsigned int &num)
Populate supplied vector with content from line.
std::vector< std::size_t > _row_offsets
Row offsets (only used with _format == "rows")

◆ setComment()

template<typename T >
void MooseUtils::DelimitedFileReaderTempl< T >::setComment ( const std::string &  value)
inline

Definition at line 92 of file DelimitedFileReader.h.

Referenced by TimedSubdomainModifier::buildFromFile(), and PiecewiseTabularBase::buildFromFile().

92 { _row_comment = value; }
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
std::string _row_comment
Hide row comments.

◆ setDelimiter() [1/2]

template<typename T >
void MooseUtils::DelimitedFileReaderTempl< T >::setDelimiter ( const std::string &  value)
inline

Definition at line 86 of file DelimitedFileReader.h.

Referenced by TimedSubdomainModifier::buildFromFile(), CSVReaderVectorPostprocessor::CSVReaderVectorPostprocessor(), and CSVTimeSequenceStepper::init().

86 { _delimiter = value; }
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
std::string _delimiter
The delimiter separating the supplied data entires.

◆ setDelimiter() [2/2]

template<typename T >
const std::string& MooseUtils::DelimitedFileReaderTempl< T >::setDelimiter ( ) const
inline

Definition at line 87 of file DelimitedFileReader.h.

87 { return _delimiter; }
std::string _delimiter
The delimiter separating the supplied data entires.

◆ setFileName()

template<typename T >
void MooseUtils::DelimitedFileReaderTempl< T >::setFileName ( const std::string &  new_file)
inline

Set the file name, used to change the file to read from We also reset the column/row names as a second read might have different names.

Definition at line 98 of file DelimitedFileReader.h.

Referenced by PropertyReadFile::initialize().

99  {
100  _filename = new_file;
101  _names.clear();
102  }
std::string _filename
The supplied filename.
std::vector< std::string > _names
Storage for the read or generated column names.

◆ setFormatFlag()

template<typename T >
void MooseUtils::DelimitedFileReaderTempl< T >::setFormatFlag ( FormatFlag  value)
inline

◆ setHeaderFlag()

template<typename T >
void MooseUtils::DelimitedFileReaderTempl< T >::setHeaderFlag ( HeaderFlag  value)
inline

Definition at line 89 of file DelimitedFileReader.h.

Referenced by TimedSubdomainModifier::buildFromFile(), CSVReaderVectorPostprocessor::CSVReaderVectorPostprocessor(), PropertyReadFile::getFileNames(), and CSVTimeSequenceStepper::init().

89 { _header_flag = value; }
HeaderFlag _header_flag
Flag indicating if the file contains a header.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ setIgnoreEmptyLines()

template<typename T >
void MooseUtils::DelimitedFileReaderTempl< T >::setIgnoreEmptyLines ( bool  value)
inline

Set/Get methods for file format controls.

IgnoreEmptyLines: When true all empty lines are ignored, when false an error is produced. FormatFlag: Set the file format (rows vs. columns). Delimiter: Set the file delimiter (if unset it will be detected). HeaderFlag: Set the header flag (TRUE used the first row has header, FALSE assumes no header, and AUTO will attempt to determine if a header exists). Comment: Set the comment character, by default no comment character is used.

Definition at line 80 of file DelimitedFileReader.h.

Referenced by CSVReaderVectorPostprocessor::CSVReaderVectorPostprocessor().

Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
bool _ignore_empty_lines
Flag for ignoring empty lines.

Member Data Documentation

◆ _communicator

template<typename T >
const libMesh::Parallel::Communicator* const MooseUtils::DelimitedFileReaderTempl< T >::_communicator
protected

Communicator.

Definition at line 150 of file DelimitedFileReader.h.

◆ _data

template<typename T >
std::vector<std::vector<T> > MooseUtils::DelimitedFileReaderTempl< T >::_data
protected

Storage for the read data columns.

Definition at line 147 of file DelimitedFileReader.h.

◆ _delimiter

template<typename T >
std::string MooseUtils::DelimitedFileReaderTempl< T >::_delimiter
protected

The delimiter separating the supplied data entires.

Definition at line 138 of file DelimitedFileReader.h.

Referenced by MooseUtils::DelimitedFileReaderTempl< T >::setDelimiter().

◆ _filename

template<typename T >
std::string MooseUtils::DelimitedFileReaderTempl< T >::_filename
protected

The supplied filename.

Definition at line 132 of file DelimitedFileReader.h.

Referenced by MooseUtils::DelimitedFileReaderTempl< T >::setFileName().

◆ _format_flag

template<typename T >
FormatFlag MooseUtils::DelimitedFileReaderTempl< T >::_format_flag
protected

◆ _header_flag

template<typename T >
HeaderFlag MooseUtils::DelimitedFileReaderTempl< T >::_header_flag
protected

Flag indicating if the file contains a header.

Definition at line 135 of file DelimitedFileReader.h.

Referenced by MooseUtils::DelimitedFileReaderTempl< T >::getHeaderFlag(), and MooseUtils::DelimitedFileReaderTempl< T >::setHeaderFlag().

◆ _ignore_empty_lines

template<typename T >
bool MooseUtils::DelimitedFileReaderTempl< T >::_ignore_empty_lines
protected

◆ _names

template<typename T >
std::vector<std::string> MooseUtils::DelimitedFileReaderTempl< T >::_names
protected

Storage for the read or generated column names.

Definition at line 144 of file DelimitedFileReader.h.

Referenced by MooseUtils::DelimitedFileReaderTempl< T >::setFileName().

◆ _row_comment

template<typename T >
std::string MooseUtils::DelimitedFileReaderTempl< T >::_row_comment
protected

◆ _row_offsets

template<typename T >
std::vector<std::size_t> MooseUtils::DelimitedFileReaderTempl< T >::_row_offsets
protected

Row offsets (only used with _format == "rows")

Definition at line 156 of file DelimitedFileReader.h.

◆ INVALID_SIZE

template<typename T >
const std::size_t MooseUtils::DelimitedFileReaderTempl< T >::INVALID_SIZE = std::numeric_limits<std::size_t>::max()

Definition at line 52 of file DelimitedFileReader.h.


The documentation for this class was generated from the following files: