39 const dictionary&
dict 48 is.format(IOstreamOption::ASCII);
55 <<
name <<
" with " << cols
56 <<
" does not have the expected length " 70 const UList<string>& strings
75 if (std::is_integral<Type>::value)
85 readScalar(strings[componentColumns_[cmpt]]);
96 fileName expandedFile(fName_);
97 autoPtr<ISstream> isPtr(
fileHandler().NewIFstream(expandedFile.expand()));
98 ISstream& is = isPtr();
103 <<
"Cannot open CSV file for reading." 107 const label maxEntry =
108 max(refColumn_, componentColumns_[
findMax(componentColumns_)]);
114 for (label i = 0; i < nHeaderLine_; ++i)
120 DynamicList<Tuple2<scalar, Type>>
values;
121 DynamicList<string> strings(maxEntry+1);
135 (
pos != std::string::npos) && (
n <= maxEntry);
139 if (mergeSeparators_)
144 const auto nPos = line.find(separator_,
pos);
146 if ((nPos != std::string::npos) && (nPos -
pos == 0))
157 const auto nPos = line.find(separator_,
pos);
159 if (nPos == std::string::npos)
161 strings.push_back(line.substr(
pos));
166 strings.push_back(line.substr(
pos, nPos -
pos));
171 if (strings.size() <= 1)
176 if (strings.size() <= maxEntry)
179 <<
"Not enough columns near line " << lineNo
180 <<
". Require " << (maxEntry+1) <<
" but found " 185 scalar
x = readScalar(strings[refColumn_]);
186 Type value = readValue(strings);
191 this->table_.transfer(
values);
200 const word& entryName,
207 nHeaderLine_(
dict.
get<label>(
"nHeaderLine")),
208 refColumn_(
dict.
get<label>(
"refColumn")),
209 componentColumns_(getComponentColumns(
"componentColumns",
dict)),
210 separator_(
dict.getOrDefault<
string>(
"separator",
",")[0]),
211 mergeSeparators_(
dict.
get<bool>(
"mergeSeparators")),
224 nHeaderLine_(csv.nHeaderLine_),
225 refColumn_(csv.refColumn_),
226 componentColumns_(csv.componentColumns_),
227 separator_(csv.separator_),
228 mergeSeparators_(csv.mergeSeparators_),
249 os.writeEntry(
"nHeaderLine", nHeaderLine_);
250 os.writeEntry(
"refColumn", refColumn_);
254 os.writeEntry(
"componentColumns", componentColumns_);
257 os.writeEntry(
"separator",
string(separator_));
258 os.writeEntry(
"mergeSeparators", mergeSeparators_);
259 os.writeEntry(
"file", fName_);
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
label findMax(const ListType &input, label start=0)
Linear search for the index of the max element, similar to std::max_element but for lists and returns...
A class for handling file names.
errorManipArg< error, int > exit(error &err, const int errNo=1)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
constexpr char nl
The newline '\n' character (0x0a)
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
refPtr< fileOperation > fileHandler(std::nullptr_t)
Delete current file handler - forwards to fileOperation::handler()
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Various functions to operate on Lists.
virtual void writeData(Ostream &os) const
Write in dictionary format.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
dimensionedScalar pos(const dimensionedScalar &ds)
Base class for table with bounds handling, interpolation and integration.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
A class for handling words, derived from Foam::string.
void initialise()
Check the table for size and consistency.
virtual void writeData(Ostream &os) const
Write in dictionary format.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
OBJstream os(runTime.globalPath()/outputName)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
virtual const fileName & fName() const
Return const access to the file name.
List< label > labelList
A List of labels.
Registry of regIOobjects.
label & setComponent(label &val, const direction) noexcept
Non-const access to integer-type (has no components)
A class for handling character strings derived from std::string.
virtual void writeEntries(Ostream &os) const
Write keywords only in dictionary format.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
CSV(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr, const fileName &fName=fileName::null)
Construct from entry name, dictionary and optional registry.