34 const List<string>& split
37 if (componentColumns_[0] >= split.size())
40 <<
"No column " << componentColumns_[0] <<
" in " 45 return readLabel(IStringStream(split[componentColumns_[0]])());
52 const List<string>& split
55 if (componentColumns_[0] >= split.size())
58 <<
"No column " << componentColumns_[0] <<
" in " 63 return readScalar(IStringStream(split[componentColumns_[0]])());
72 for (
label i = 0; i < pTraits<Type>::nComponents; i++)
74 if (componentColumns_[i] >= split.size())
77 <<
"No column " << componentColumns_[i] <<
" in " 83 readScalar(IStringStream(split[componentColumns_[i]])());
93 fileName expandedFile(fName_);
94 autoPtr<ISstream> isPtr(
fileHandler().NewIFstream(expandedFile.expand()));
95 ISstream& is = isPtr();
100 <<
"Cannot open CSV file for reading." 104 DynamicList<Tuple2<scalar, Type>> values;
107 for (
label i = 0; i < nHeaderLine_; i++)
113 const label nEntries =
max(refColumn_,
max(componentColumns_));
124 DynamicList<string> split;
126 if (mergeSeparators_)
128 std::size_t nPos = 0;
130 while ((pos != std::string::npos) && (n <= nEntries))
135 nPos = line.find(separator_, pos);
137 if ((nPos != std::string::npos) && (nPos - pos == 0))
147 nPos = line.find(separator_, pos);
149 if (nPos == std::string::npos)
151 split.append(line.substr(pos));
157 split.append(line.substr(pos, nPos - pos));
165 while ((pos != std::string::npos) && (n <= nEntries))
167 std::size_t nPos = line.find(separator_, pos);
169 if (nPos == std::string::npos)
171 split.append(line.substr(pos));
177 split.append(line.substr(pos, nPos - pos));
185 if (split.size() <= 1)
190 scalar x =
readScalar(IStringStream(split[refColumn_])());
191 Type value = readValue(split);
193 values.append(Tuple2<scalar,Type>(x, value));
196 this->table_.transfer(values);
205 const word& entryName,
212 componentColumns_(dict.
lookup(
"componentColumns")),
215 fName_(dict.
lookup(
"file"))
220 << componentColumns_ <<
" does not have the expected length of " 235 nHeaderLine_(tbl.nHeaderLine_),
236 refColumn_(tbl.refColumn_),
237 componentColumns_(tbl.componentColumns_),
238 separator_(tbl.separator_),
239 mergeSeparators_(tbl.mergeSeparators_),
274 writeEntry(os,
"componentColumns", componentColumns_);
275 writeEntry(os,
"separator",
string(separator_));
276 writeEntry(os,
"mergeSeparators", mergeSeparators_);
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.
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.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
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.
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.