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_);
96 autoPtr<ISstream> isPtr(
fileHandler().NewIFstream(expandedFile.expand()));
97 ISstream& is = isPtr();
102 <<
"Cannot open CSV file for reading." 106 DynamicList<Tuple2<scalar, Type>> values;
109 for (
label i = 0; i < nHeaderLine_; i++)
115 label nEntries =
max(componentColumns_);
126 DynamicList<string> splitted;
128 if (mergeSeparators_)
130 std::size_t nPos = 0;
132 while ((pos != std::string::npos) && (n <= nEntries))
137 nPos = line.find(separator_, pos);
139 if ((nPos != std::string::npos) && (nPos - pos == 0))
149 nPos = line.find(separator_, pos);
151 if (nPos == std::string::npos)
153 splitted.append(line.substr(pos));
159 splitted.append(line.substr(pos, nPos - pos));
167 while ((pos != std::string::npos) && (n <= nEntries))
169 std::size_t nPos = line.find(separator_, pos);
171 if (nPos == std::string::npos)
173 splitted.append(line.substr(pos));
179 splitted.append(line.substr(pos, nPos - pos));
187 if (splitted.size() <= 1)
192 scalar x =
readScalar(IStringStream(splitted[refColumn_])());
193 Type value = readValue(splitted);
195 values.append(Tuple2<scalar,Type>(x, value));
198 this->table_.transfer(values);
207 const word& entryName,
214 componentColumns_(dict.
lookup(
"componentColumns")),
217 fName_(dict.
lookup(
"file"))
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_;
CSV(const word &entryName, const dictionary &dict)
Construct from entry name and dictionary.
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.
Ostream & indent(Ostream &os)
Indent stream.
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 > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const word & name() const
Return the name of the entry.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Traits class for primitives.
virtual void writeData(Ostream &os) const
Write in dictionary format.
Base class for table with bounds handling, interpolation and integration.
A class for handling words, derived from string.
virtual void writeData(Ostream &os) const
Write in dictionary format.
const fileOperation & fileHandler()
Get current file handler.
streamFormat format() const
Return current stream format.
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.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
virtual const fileName & fName() const
Return const access to the file name.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
A class for handling character strings derived from std::string.
virtual void writeEntries(Ostream &os) const
Write keywords only in dictionary format. Used for non-inline.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.