Go to the documentation of this file.
39 const dictionary&
dict
48 is.format(IOstream::ASCII);
52 if (cols.size() != pTraits<Type>::nComponents)
55 <<
name <<
" with " << cols
56 <<
" does not have the expected length "
57 << pTraits<Type>::nComponents <<
nl
70 const List<string>& strings
73 return readLabel(strings[componentColumns_[0]]);
80 const List<string>& strings
83 return readScalar(strings[componentColumns_[0]]);
90 const List<string>& strings
95 for (label i = 0; i < pTraits<Type>::nComponents; ++i)
97 result[i] = readScalar(strings[componentColumns_[i]]);
107 fileName expandedFile(fName_);
108 autoPtr<ISstream> isPtr(
fileHandler().NewIFstream(expandedFile.expand()));
109 ISstream& is = isPtr();
114 <<
"Cannot open CSV file for reading."
118 const label maxEntry =
119 max(refColumn_, componentColumns_[
findMax(componentColumns_)]);
125 for (label i = 0; i < nHeaderLine_; ++i)
131 DynamicList<Tuple2<scalar, Type>>
values;
132 DynamicList<string> strings(maxEntry+1);
146 (
pos != std::string::npos) && (
n <= maxEntry);
150 if (mergeSeparators_)
155 const auto nPos = line.find(separator_,
pos);
157 if ((nPos != std::string::npos) && (nPos -
pos == 0))
168 const auto nPos = line.find(separator_,
pos);
170 if (nPos == std::string::npos)
172 strings.append(line.substr(
pos));
177 strings.append(line.substr(
pos, nPos -
pos));
182 if (strings.size() <= 1)
187 if (strings.size() <= maxEntry)
190 <<
"Not enough columns near line " << lineNo
191 <<
". Require " << (maxEntry+1) <<
" but found "
196 scalar
x = readScalar(strings[refColumn_]);
197 Type value = readValue(strings);
199 values.append(Tuple2<scalar,Type>(
x, value));
202 this->table_.transfer(
values);
211 const word& entryName,
217 nHeaderLine_(
dict.get<label>(
"nHeaderLine")),
218 refColumn_(
dict.get<label>(
"refColumn")),
219 componentColumns_(getComponentColumns(
"componentColumns",
dict)),
220 separator_(
dict.getOrDefault<
string>(
"separator",
",")[0]),
221 mergeSeparators_(
dict.get<
bool>(
"mergeSeparators")),
222 fName_(fName.empty() ?
dict.get<
fileName>(
"file") : fName)
234 nHeaderLine_(csv.nHeaderLine_),
235 refColumn_(csv.refColumn_),
236 componentColumns_(csv.componentColumns_),
237 separator_(csv.separator_),
238 mergeSeparators_(csv.mergeSeparators_),
265 os.
writeEntry(
"componentColumns", componentColumns_);
268 os.
writeEntry(
"separator",
string(separator_));
269 os.
writeEntry(
"mergeSeparators", mergeSeparators_);
List< label > labelList
A List of labels.
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.
void writeEntries(Ostream &os) const
Write coefficient entries in dictionary 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.
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
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.
label findMax(const ListType &input, label start=0)
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.
Various functions to operate on Lists.
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)