www.mooseframework.org
Public Types | Public Member Functions | Public Attributes | Protected Attributes | Private Member Functions | List of all members
MooseUtils::DelimitedFileReader Class 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

 DelimitedFileReader (const std::string &filename, const libMesh::Parallel::Communicator *comm=nullptr)
 
void read ()
 Perform the actual data reading. More...
 
const std::vector< std::string > & getNames () const
 Return the column/row names. More...
 
const std::vector< std::vector< double > > & getData () const
 Return the rows/columns of data. More...
 
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< double > & getData (const std::string &name) const
 Return the row/column of data for a specified header entry. More...
 
const std::vector< double > & getData (std::size_t index) const
 
void setHeaderFlag (bool value)
 Deprecated. More...
 
const std::vector< std::string > & getColumnNames () const
 
const std::vector< std::vector< double > > & getColumnData () const
 
const std::vector< double > & getColumnData (const std::string &name) const
 
 DelimitedFileReader (const std::string &filename, const bool header, const std::string delimiter, const libMesh::Parallel::Communicator *comm=nullptr)
 

Public Attributes

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

Protected Attributes

const 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< double > > _data
 Storage for the read data columns. More...
 
const libMesh::Parallel::Communicator * _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< double > &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< double > &output)
 Read the numeric data as rows or columns into a single vector. More...
 
void readRowData (std::ifstream &stream_data, std::vector< double > &output)
 

Detailed Description

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 35 of file DelimitedFileReader.h.

Member Enumeration Documentation

◆ FormatFlag

Enumerator
COLUMNS 
ROWS 

Definition at line 45 of file DelimitedFileReader.h.

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

◆ HeaderFlag

Enumerator
OFF 
ON 
AUTO 

Definition at line 38 of file DelimitedFileReader.h.

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

Constructor & Destructor Documentation

◆ DelimitedFileReader() [1/2]

MooseUtils::DelimitedFileReader::DelimitedFileReader ( const std::string &  filename,
const libMesh::Parallel::Communicator *  comm = nullptr 
)

Definition at line 24 of file DelimitedFileReader.C.

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

◆ DelimitedFileReader() [2/2]

MooseUtils::DelimitedFileReader::DelimitedFileReader ( const std::string &  filename,
const bool  header,
const std::string  delimiter,
const libMesh::Parallel::Communicator *  comm = nullptr 
)

Definition at line 357 of file DelimitedFileReader.C.

361  : _filename(filename),
364  _ignore_empty_lines(true),
367 {
368  mooseDeprecated("Use setHeader and setDelimiter method rather than specifying in constructor.");
369 }
std::string _delimiter
The delimiter separating the supplied data entires.
HeaderFlag _header_flag
Flag indicating if the file contains a header.
bool _ignore_empty_lines
Flag for ignoring empty lines.
FormatFlag _format_flag
Format "rows" vs "columns".
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 libMesh::Parallel::Communicator * _communicator
Communicator.
const std::string _filename
The supplied filename.
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:237
MPI_Comm comm
const std::string & delimiter(const std::string &line)
Determine the delimiter.

Member Function Documentation

◆ delimiter()

const std::string & MooseUtils::DelimitedFileReader::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 318 of file DelimitedFileReader.C.

Referenced by header(), processLine(), readColumnData(), and readRowData().

319 {
320  if (_delimiter.empty())
321  {
322  if (line.find(",") != std::string::npos)
323  _delimiter = ",";
324  else if (line.find("\t") != std::string::npos)
325  _delimiter = "\t";
326  else
327  _delimiter = " ";
328  }
329  return _delimiter;
330 }
std::string _delimiter
The delimiter separating the supplied data entires.

◆ getColumnData() [1/2]

const std::vector< std::vector< double > > & MooseUtils::DelimitedFileReader::getColumnData ( ) const

Definition at line 379 of file DelimitedFileReader.C.

380 {
381  mooseDeprecated("Use getData instead.");
382  return getData();
383 }
const std::vector< std::vector< double > > & getData() const
Return the rows/columns of data.
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:237

◆ getColumnData() [2/2]

const std::vector< double > & MooseUtils::DelimitedFileReader::getColumnData ( const std::string &  name) const

Definition at line 386 of file DelimitedFileReader.C.

387 {
388  mooseDeprecated("Use getData instead.");
389  return getData(name);
390 }
const std::vector< std::vector< double > > & getData() const
Return the rows/columns of data.
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:237

◆ getColumnNames()

const std::vector< std::string > & MooseUtils::DelimitedFileReader::getColumnNames ( ) const

Definition at line 372 of file DelimitedFileReader.C.

373 {
374  mooseDeprecated("Use getNames instead.");
375  return getNames();
376 }
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:237
const std::vector< std::string > & getNames() const
Return the column/row names.

◆ getComment()

const std::string& MooseUtils::DelimitedFileReader::getComment ( ) const
inline

Definition at line 86 of file DelimitedFileReader.h.

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

◆ getData() [1/3]

const std::vector< std::vector< double > > & MooseUtils::DelimitedFileReader::getData ( ) const

Return the rows/columns of data.

The outer vector is column and the inner the rows.

Definition at line 130 of file DelimitedFileReader.C.

Referenced by Piecewise::buildFromFile(), CSVReader::execute(), getColumnData(), and CSVTimeSequenceStepper::init().

131 {
132  return _data;
133 }
std::vector< std::vector< double > > _data
Storage for the read data columns.

◆ getData() [2/3]

const std::vector< double > & MooseUtils::DelimitedFileReader::getData ( const std::string &  name) const

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

Definition at line 136 of file DelimitedFileReader.C.

137 {
138  const auto it = find(_names.begin(), _names.end(), name);
139  if (it == _names.end())
140  mooseError("Could not find '", name, "' in header of file ", _filename, ".");
141  return _data[std::distance(_names.begin(), it)];
142 }
std::vector< std::vector< double > > _data
Storage for the read data columns.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
std::vector< std::string > _names
Storage for the read or generated column names.
const std::string _filename
The supplied filename.

◆ getData() [3/3]

const std::vector< double > & MooseUtils::DelimitedFileReader::getData ( std::size_t  index) const

Definition at line 145 of file DelimitedFileReader.C.

146 {
147  if (index >= _data.size())
148  mooseError("The supplied index ",
149  index,
150  " is out-of-range for the available data in file '",
151  _filename,
152  "' which contains ",
153  _data.size(),
154  " items.");
155  return _data[index];
156 }
std::vector< std::vector< double > > _data
Storage for the read data columns.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
const std::string _filename
The supplied filename.

◆ getFormatFlag()

FormatFlag MooseUtils::DelimitedFileReader::getFormatFlag ( ) const
inline

Definition at line 77 of file DelimitedFileReader.h.

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

◆ getHeaderFlag()

HeaderFlag MooseUtils::DelimitedFileReader::getHeaderFlag ( ) const
inline

Definition at line 83 of file DelimitedFileReader.h.

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

◆ getIgnoreEmptyLines()

bool MooseUtils::DelimitedFileReader::getIgnoreEmptyLines ( ) const
inline

Definition at line 74 of file DelimitedFileReader.h.

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

◆ getNames()

const std::vector< std::string > & MooseUtils::DelimitedFileReader::getNames ( ) const

Return the column/row names.

Definition at line 124 of file DelimitedFileReader.C.

Referenced by CSVReader::execute(), getColumnNames(), and CSVReader::initialize().

125 {
126  return _names;
127 }
std::vector< std::string > _names
Storage for the read or generated column names.

◆ header()

bool MooseUtils::DelimitedFileReader::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 333 of file DelimitedFileReader.C.

Referenced by readColumnData(), and readRowData().

334 {
335  switch (_header_flag)
336  {
337  case HeaderFlag::OFF:
338  return false;
339  case HeaderFlag::ON:
340  return true;
341  default:
342 
343  // Attempt to convert the line, if it fails assume it is a header
344  std::vector<double> row;
345  bool contains_alpha = !MooseUtils::tokenizeAndConvert<double>(line, row, delimiter(line));
346 
347  // Based on auto detect set the flag to TRUE|FALSE to short-circuit this check for each line
348  // in the case of row data.
349  _header_flag = contains_alpha ? HeaderFlag::ON : HeaderFlag::OFF;
350  return contains_alpha;
351  }
352 }
HeaderFlag _header_flag
Flag indicating if the file contains a header.
const std::string & delimiter(const std::string &line)
Determine the delimiter.

◆ preprocessLine()

bool MooseUtils::DelimitedFileReader::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 282 of file DelimitedFileReader.C.

Referenced by readColumnData(), and readRowData().

283 {
284  // Handle row comments
285  std::size_t index = _row_comment.empty() ? line.size() : line.find_first_of(_row_comment);
286  line = MooseUtils::trim(line.substr(0, index));
287 
288  // Ignore empty lines
289  if (line.empty())
290  {
292  return true;
293  else
294  mooseError("Failed to read line ", num, " in file ", _filename, ". The line is empty.");
295  }
296  return false;
297 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
bool _ignore_empty_lines
Flag for ignoring empty lines.
std::string trim(const std::string &str, const std::string &white_space=" \\\)
Standard scripting language trim function.
Definition: MooseUtils.C:112
const std::string _filename
The supplied filename.
std::string _row_comment
Hide row comments.

◆ processLine()

void MooseUtils::DelimitedFileReader::processLine ( const std::string &  line,
std::vector< double > &  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 300 of file DelimitedFileReader.C.

Referenced by readColumnData(), and readRowData().

303 {
304  // Separate the row and error if it fails
305  bool status = MooseUtils::tokenizeAndConvert<double>(line, row, delimiter(line));
306  if (!status)
307  mooseError("Failed to convert a delimited data into double when reading line ",
308  num,
309  " in file ",
310  _filename,
311  ".\n LINE ",
312  num,
313  ": ",
314  line);
315 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
const std::string _filename
The supplied filename.
const std::string & delimiter(const std::string &line)
Determine the delimiter.

◆ read()

void MooseUtils::DelimitedFileReader::read ( )

Perform the actual data reading.

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

Definition at line 35 of file DelimitedFileReader.C.

Referenced by Piecewise::buildFromFile(), CSVTimeSequenceStepper::init(), and CSVReader::initialize().

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

◆ readColumnData()

void MooseUtils::DelimitedFileReader::readColumnData ( std::ifstream &  stream_data,
std::vector< double > &  output 
)
private

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

Definition at line 159 of file DelimitedFileReader.C.

Referenced by read().

160 {
161  // Local storage for the data being read
162  std::string line;
163  std::vector<double> row;
164 
165  // Keep track of the line number for error reporting
166  unsigned int count = 0;
167 
168  // Number of columns expected based on the first row of the data
169  std::size_t n_cols = INVALID_SIZE;
170 
171  // Read the lines
172  while (std::getline(stream_data, line))
173  {
174  // Increment line counter and clear any tokenized data
175  count++;
176  row.clear();
177 
178  // Ignore empty and/or comment lines, if applicable
179  if (preprocessLine(line, count))
180  continue;
181 
182  // Read header, if the header exists and the column names do not exist.
183  if (_names.empty() && header(line))
184  {
185  MooseUtils::tokenize(line, _names, 1, delimiter(line));
186  for (std::string & str : _names)
187  str = MooseUtils::trim(str);
188  continue;
189  }
190 
191  // Separate the row and error if it fails
192  processLine(line, row, count);
193 
194  // Set the number of columns
195  if (n_cols == INVALID_SIZE)
196  n_cols = row.size();
197 
198  // Check number of columns
199  if (row.size() != n_cols)
200  mooseError("The number of columns read (",
201  row.size(),
202  ") does not match the number of columns expected (",
203  n_cols,
204  ") based on the first row of the file when reading row ",
205  count,
206  " in file ",
207  _filename,
208  ".");
209 
210  // Append data
211  output.insert(output.end(), row.begin(), row.end());
212  }
213 
214  // If the names have not been assigned, create the default names
215  if (_names.empty())
216  {
217  _names.resize(n_cols);
218  int padding = MooseUtils::numDigits(n_cols);
219  for (std::size_t i = 0; i < n_cols; ++i)
220  {
221  std::stringstream ss;
222  ss << "column_" << std::setw(padding) << std::setfill('0') << i;
223  _names[i] = ss.str();
224  }
225  }
226 }
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:377
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
bool preprocessLine(std::string &line, const unsigned int &num)
Check the content of the line and if it should be skipped.
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...
std::string trim(const std::string &str, const std::string &white_space=" \\\)
Standard scripting language trim function.
Definition: MooseUtils.C:112
const std::string _filename
The supplied filename.
int numDigits(const T &num)
Return the number of digits for a number.
Definition: MooseUtils.h:528
const std::string & delimiter(const std::string &line)
Determine the delimiter.
void processLine(const std::string &line, std::vector< double > &row, const unsigned int &num)
Populate supplied vector with content from line.

◆ readRowData()

void MooseUtils::DelimitedFileReader::readRowData ( std::ifstream &  stream_data,
std::vector< double > &  output 
)
private

Definition at line 229 of file DelimitedFileReader.C.

Referenced by read().

230 {
231  // Local storage for the data being read
232  std::string line;
233  std::vector<double> row;
234  unsigned int linenum = 0; // line number in file
235 
236  // Clear existing data
237  _names.clear();
238  _row_offsets.clear();
239 
240  // Read the lines
241  while (std::getline(stream_data, line))
242  {
243  // Increment line counter and clear any tokenized data
244  linenum++;
245  row.clear();
246 
247  // Ignore empty lines
248  if (preprocessLine(line, linenum))
249  continue;
250 
251  if (header(line))
252  {
253  std::size_t index = line.find_first_of(delimiter(line));
254  _names.push_back(line.substr(0, index));
255  line = line.substr(index);
256  }
257 
258  // Separate the row and error if it fails
259  processLine(line, row, linenum);
260 
261  // Store row offsets to allow for un-even rows
262  _row_offsets.push_back(row.size());
263 
264  // Append data
265  output.insert(output.end(), row.begin(), row.end());
266  }
267 
268  // Assign row names if not provided via header
269  if (_names.empty())
270  {
271  int padding = MooseUtils::numDigits(_row_offsets.size());
272  for (std::size_t i = 0; i < _row_offsets.size(); ++i)
273  {
274  std::stringstream ss;
275  ss << "row_" << std::setw(padding) << std::setfill('0') << i;
276  _names.push_back(ss.str());
277  }
278  }
279 }
bool preprocessLine(std::string &line, const unsigned int &num)
Check the content of the line and if it should be skipped.
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...
int numDigits(const T &num)
Return the number of digits for a number.
Definition: MooseUtils.h:528
const std::string & delimiter(const std::string &line)
Determine the delimiter.
std::vector< std::size_t > _row_offsets
Row offsets (only used with _format == "rows")
void processLine(const std::string &line, std::vector< double > &row, const unsigned int &num)
Populate supplied vector with content from line.

◆ setComment()

void MooseUtils::DelimitedFileReader::setComment ( const std::string &  value)
inline

Definition at line 85 of file DelimitedFileReader.h.

Referenced by Piecewise::buildFromFile().

85 { _row_comment = value; }
std::string _row_comment
Hide row comments.

◆ setDelimiter() [1/2]

void MooseUtils::DelimitedFileReader::setDelimiter ( const std::string &  value)
inline

Definition at line 79 of file DelimitedFileReader.h.

Referenced by CSVReader::CSVReader(), and CSVTimeSequenceStepper::init().

79 { _delimiter = value; }
std::string _delimiter
The delimiter separating the supplied data entires.

◆ setDelimiter() [2/2]

const std::string& MooseUtils::DelimitedFileReader::setDelimiter ( ) const
inline

Definition at line 80 of file DelimitedFileReader.h.

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

◆ setFormatFlag()

void MooseUtils::DelimitedFileReader::setFormatFlag ( FormatFlag  value)
inline

Definition at line 76 of file DelimitedFileReader.h.

Referenced by Piecewise::buildFromFile().

76 { _format_flag = value; }
FormatFlag _format_flag
Format "rows" vs "columns".

◆ setHeaderFlag() [1/2]

void MooseUtils::DelimitedFileReader::setHeaderFlag ( HeaderFlag  value)
inline

Definition at line 82 of file DelimitedFileReader.h.

Referenced by CSVReader::CSVReader(), and CSVTimeSequenceStepper::init().

82 { _header_flag = value; }
HeaderFlag _header_flag
Flag indicating if the file contains a header.

◆ setHeaderFlag() [2/2]

void MooseUtils::DelimitedFileReader::setHeaderFlag ( bool  value)

Deprecated.

Definition at line 393 of file DelimitedFileReader.C.

394 {
395  mooseDeprecated("Use header method with HeaderFlag input.");
397 }
HeaderFlag _header_flag
Flag indicating if the file contains a header.
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
Definition: MooseError.h:237

◆ setIgnoreEmptyLines()

void MooseUtils::DelimitedFileReader::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 73 of file DelimitedFileReader.h.

Referenced by CSVReader::CSVReader().

73 { _ignore_empty_lines = value; }
bool _ignore_empty_lines
Flag for ignoring empty lines.

Member Data Documentation

◆ _communicator

const libMesh::Parallel::Communicator* MooseUtils::DelimitedFileReader::_communicator
protected

Communicator.

Definition at line 143 of file DelimitedFileReader.h.

Referenced by read().

◆ _data

std::vector<std::vector<double> > MooseUtils::DelimitedFileReader::_data
protected

Storage for the read data columns.

Definition at line 140 of file DelimitedFileReader.h.

Referenced by getData(), and read().

◆ _delimiter

std::string MooseUtils::DelimitedFileReader::_delimiter
protected

The delimiter separating the supplied data entires.

Definition at line 131 of file DelimitedFileReader.h.

Referenced by delimiter(), and setDelimiter().

◆ _filename

const std::string MooseUtils::DelimitedFileReader::_filename
protected

The supplied filename.

Definition at line 125 of file DelimitedFileReader.h.

Referenced by getData(), preprocessLine(), processLine(), read(), and readColumnData().

◆ _format_flag

FormatFlag MooseUtils::DelimitedFileReader::_format_flag
protected

Format "rows" vs "columns".

Definition at line 146 of file DelimitedFileReader.h.

Referenced by getFormatFlag(), read(), and setFormatFlag().

◆ _header_flag

HeaderFlag MooseUtils::DelimitedFileReader::_header_flag
protected

Flag indicating if the file contains a header.

Definition at line 128 of file DelimitedFileReader.h.

Referenced by getHeaderFlag(), header(), and setHeaderFlag().

◆ _ignore_empty_lines

bool MooseUtils::DelimitedFileReader::_ignore_empty_lines
protected

Flag for ignoring empty lines.

Definition at line 134 of file DelimitedFileReader.h.

Referenced by getIgnoreEmptyLines(), preprocessLine(), and setIgnoreEmptyLines().

◆ _names

std::vector<std::string> MooseUtils::DelimitedFileReader::_names
protected

Storage for the read or generated column names.

Definition at line 137 of file DelimitedFileReader.h.

Referenced by getData(), getNames(), read(), readColumnData(), and readRowData().

◆ _row_comment

std::string MooseUtils::DelimitedFileReader::_row_comment
protected

Hide row comments.

Definition at line 152 of file DelimitedFileReader.h.

Referenced by getComment(), preprocessLine(), and setComment().

◆ _row_offsets

std::vector<std::size_t> MooseUtils::DelimitedFileReader::_row_offsets
protected

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

Definition at line 149 of file DelimitedFileReader.h.

Referenced by read(), and readRowData().

◆ INVALID_SIZE

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

Definition at line 51 of file DelimitedFileReader.h.

Referenced by readColumnData().


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