39 const dictionary&
dict
47 ITstream& is =
dict.lookup(name);
48 is.format(IOstream::ASCII);
50 dict.checkITstream(is, name);
52 if (cols.size() != pTraits<Type>::nComponents)
55 <<
name <<
" with " << cols
56 <<
" does not have the expected length "
57 << pTraits<Type>::nComponents <<
nl
58 <<
exit(FatalIOError);
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."
115 <<
exit(FatalIOError);
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_);
Various functions to operate on Lists.
virtual const fileName & fName() const
Return const access to the file name.
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Base class for table with bounds handling, interpolation and integration.
void initialise()
Check the table for size and consistency.
virtual void writeEntries(Ostream &os) const
Write keywords only in dictionary format.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
A class for handling file names.
Registry of regIOobjects.
A class for handling character strings derived from std::string.
A class for handling words, derived from Foam::string.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
const fileOperation & fileHandler()
Get current file handler.
dimensionedScalar pos(const dimensionedScalar &ds)
List< label > labelList
A List of labels.
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
label findMax(const ListType &input, label start=0)
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a)