Go to the documentation of this file.
37 const List<string>& splitted
40 if (componentColumns_[0] >= splitted.size())
43 <<
"No column " << componentColumns_[0] <<
" in "
48 return readLabel(splitted[componentColumns_[0]]);
55 const List<string>& splitted
58 if (componentColumns_[0] >= splitted.size())
61 <<
"No column " << componentColumns_[0] <<
" in "
66 return readScalar(splitted[componentColumns_[0]]);
73 const List<string>& splitted
78 for (
label i = 0; i < pTraits<Type>::nComponents; ++i)
80 if (componentColumns_[i] >= splitted.size())
83 <<
"No column " << componentColumns_[i] <<
" in "
88 result[i] = readScalar(splitted[componentColumns_[i]]);
98 fileName expandedFile(fName_);
99 autoPtr<ISstream> isPtr(
fileHandler().NewIFstream(expandedFile.expand()));
100 ISstream& is = isPtr();
105 <<
"Cannot open CSV file for reading."
109 DynamicList<Tuple2<scalar, Type>>
values;
112 for (
label i = 0; i < nHeaderLine_; i++)
118 label nEntries =
max(componentColumns_);
129 DynamicList<string> splitted;
131 if (mergeSeparators_)
133 std::size_t nPos = 0;
135 while ((
pos != std::string::npos) && (
n <= nEntries))
140 nPos = line.find(separator_,
pos);
142 if ((nPos != std::string::npos) && (nPos -
pos == 0))
152 nPos = line.find(separator_,
pos);
154 if (nPos == std::string::npos)
156 splitted.append(line.substr(
pos));
162 splitted.append(line.substr(
pos, nPos -
pos));
170 while ((
pos != std::string::npos) && (
n <= nEntries))
172 std::size_t nPos = line.find(separator_,
pos);
174 if (nPos == std::string::npos)
176 splitted.append(line.substr(
pos));
182 splitted.append(line.substr(
pos, nPos -
pos));
190 if (splitted.size() <= 1)
195 scalar
x = readScalar(splitted[refColumn_]);
196 Type value = readValue(splitted);
198 values.append(Tuple2<scalar,Type>(
x, value));
201 this->table_.transfer(
values);
210 const word& entryName,
216 nHeaderLine_(
dict.get<
label>(
"nHeaderLine")),
217 refColumn_(
dict.get<
label>(
"refColumn")),
219 separator_(
dict.getOrDefault<
string>(
"separator",
",")[0]),
220 mergeSeparators_(
dict.get<
bool>(
"mergeSeparators")),
221 fName_(fName.empty() ?
dict.get<
fileName>(
"file") : fName)
226 is.
format(IOstream::ASCII);
227 is >> componentColumns_;
228 dict.checkITstream(is,
"componentColumns");
233 << componentColumns_ <<
" does not have the expected length of "
248 nHeaderLine_(csv.nHeaderLine_),
249 refColumn_(csv.refColumn_),
250 componentColumns_(csv.componentColumns_),
251 separator_(csv.separator_),
252 mergeSeparators_(csv.mergeSeparators_),
284 os.
writeEntry(
"componentColumns", componentColumns_);
287 os.
writeEntry(
"separator",
string(separator_));
288 os.
writeEntry(
"mergeSeparators", mergeSeparators_);
A class for handling words, derived from Foam::string.
A class for handling file names.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
streamFormat format() const noexcept
Get the current stream format.
const fileOperation & fileHandler()
Get current file handler.
CSV(const word &entryName, const dictionary &dict, const fileName &fName=fileName::null)
Construct from entry name and dictionary.
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
An input stream of tokens.
word name(const complex &c)
Return string representation of complex.
virtual void writeData(Ostream &os) const
Write in dictionary format.
virtual void writeData(Ostream &os) const
Write in dictionary format.
virtual Ostream & endEntry()
Write end entry (';') followed by newline.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
virtual Ostream & endBlock()
Write end block group.
streamFormat
Data format (ascii | binary)
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
errorManipArg< error, int > exit(error &err, const int errNo=1)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Traits class for primitives.
virtual void writeEntries(Ostream &os) const
Write keywords only in dictionary format.
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Base class for table with bounds handling, interpolation and integration.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual const fileName & fName() const
Return const access to the file name.
dimensionedScalar pos(const dimensionedScalar &ds)