35 const List<string>& splitted
38 if (componentColumns_[0] >= splitted.size())
41 <<
"No column " << componentColumns_[0] <<
" in " 46 return readLabel(IStringStream(splitted[componentColumns_[0]])());
53 const List<string>& splitted
56 if (componentColumns_[0] >= splitted.size())
59 <<
"No column " << componentColumns_[0] <<
" in " 64 return readScalar(IStringStream(splitted[componentColumns_[0]])());
73 for (
label i = 0; i < pTraits<Type>::nComponents; i++)
75 if (componentColumns_[i] >= splitted.size())
78 <<
"No column " << componentColumns_[i] <<
" in " 84 readScalar(IStringStream(splitted[componentColumns_[i]])());
94 fileName expandedFile(fName_);
95 IFstream is(expandedFile.expand());
100 <<
"Cannot open CSV file for reading." 104 DynamicList<Tuple2<scalar, Type>> values;
107 for (
label i = 0; i < nHeaderLine_; i++)
113 label nEntries =
max(componentColumns_);
124 DynamicList<string> splitted;
126 if (mergeSeparators_)
128 std::size_t nPos = 0;
130 while ((pos != std::string::npos) && (n <= nEntries))
135 nPos = line.find(separator_, pos);
137 if ((nPos != std::string::npos) && (nPos - pos == 0))
147 nPos = line.find(separator_, pos);
149 if (nPos == std::string::npos)
151 splitted.append(line.substr(pos));
157 splitted.append(line.substr(pos, nPos - pos));
165 while ((pos != std::string::npos) && (n <= nEntries))
167 std::size_t nPos = line.find(separator_, pos);
169 if (nPos == std::string::npos)
171 splitted.append(line.substr(pos));
177 splitted.append(line.substr(pos, nPos - pos));
185 if (splitted.size() <= 1)
190 scalar x =
readScalar(IStringStream(splitted[refColumn_])());
191 Type value = readValue(splitted);
193 values.append(Tuple2<scalar,Type>(x, value));
196 this->table_.transfer(values);
205 const word& entryName,
211 coeffs_(dict.
subDict(entryName + ext)),
212 nHeaderLine_(
readLabel(coeffs_.lookup(
"nHeaderLine"))),
213 refColumn_(
readLabel(coeffs_.lookup(
"refColumn"))),
214 componentColumns_(coeffs_.lookup(
"componentColumns")),
215 separator_(coeffs_.lookupOrDefault<
string>(
"separator",
string(
","))[0]),
216 mergeSeparators_(
readBool(coeffs_.lookup(
"mergeSeparators"))),
217 fName_(coeffs_.lookup(
"fileName"))
222 << componentColumns_ <<
" does not have the expected length of " 237 nHeaderLine_(tbl.nHeaderLine_),
238 refColumn_(tbl.refColumn_),
239 componentColumns_(tbl.componentColumns_),
240 separator_(tbl.separator_),
241 mergeSeparators_(tbl.mergeSeparators_),
283 os << componentColumns_;
288 os << componentColumns_;
streamFormat format() const
Return current stream format.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
A class for handling file names.
const word & name() const
Return the name of the entry.
Ostream & indent(Ostream &os)
Indent stream.
virtual void writeEntries(Ostream &os) const
Write keywords only in dictionary format. Used for non-inline.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A list of keyword definitions, which are a keyword followed by any number of values (e...
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
virtual const fileName & fName() const
Return const access to the file name.
Templated CSV container data entry. Reference column is always a scalar, e.g. time.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
CSV(const word &entryName, const dictionary &dict, const word &ext="Coeffs")
Construct from entry name and dictionary.
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Traits class for primitives.
virtual void writeData(Ostream &os) const
Write in dictionary format.
virtual void writeData(Ostream &os) const
Write in dictionary format.
bool read(const char *, int32_t &)
Base class for table with bounds handling, interpolation and integration.
A class for handling words, derived from string.
label readLabel(Istream &is)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
virtual ~CSV()
Destructor.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
A class for handling character strings derived from std::string.