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,
218 nHeaderLine_(
dict.get<label>(
"nHeaderLine")),
219 refColumn_(
dict.get<label>(
"refColumn")),
220 componentColumns_(getComponentColumns(
"componentColumns",
dict)),
221 separator_(
dict.getOrDefault<
string>(
"separator",
",")[0]),
222 mergeSeparators_(
dict.get<
bool>(
"mergeSeparators")),
223 fName_(fName.empty() ?
dict.get<
fileName>(
"file") : fName)
235 nHeaderLine_(csv.nHeaderLine_),
236 refColumn_(csv.refColumn_),
237 componentColumns_(csv.componentColumns_),
238 separator_(csv.separator_),
239 mergeSeparators_(csv.mergeSeparators_),
260 os.writeEntry(
"nHeaderLine", nHeaderLine_);
261 os.writeEntry(
"refColumn", refColumn_);
265 os.writeEntry(
"componentColumns", componentColumns_);
268 os.writeEntry(
"separator",
string(separator_));
269 os.writeEntry(
"mergeSeparators", mergeSeparators_);
270 os.writeEntry(
"file", fName_);
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.
void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
const fileOperation & fileHandler()
Get current file handler.
Registry of regIOobjects.
virtual void writeData(Ostream &os) const
Write in dictionary format.
virtual void writeData(Ostream &os) const
Write in dictionary format.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
OBJstream os(runTime.globalPath()/outputName)
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.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
CSV(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr, const fileName &fName=fileName::null)
Construct from entry name, dictionary and optional registry.
#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)