34 namespace TableReaders
40 label Csv<label>::readValue(
const List<string>& split)
const
42 if (componentColumns_[0] >= split.size())
45 <<
"No column " << componentColumns_[0] <<
" in "
50 return readLabel(IStringStream(split[componentColumns_[0]])());
55 scalar Csv<scalar>::readValue(
const List<string>& split)
const
57 if (componentColumns_[0] >= split.size())
60 <<
"No column " << componentColumns_[0] <<
" in "
65 return readScalar(IStringStream(split[componentColumns_[0]])());
70 Type Csv<Type>::readValue(
const List<string>& split)
const
74 for(
label i = 0;i < pTraits<Type>::nComponents; i++)
76 if (componentColumns_[i] >= split.size())
79 <<
"No column " << componentColumns_[i] <<
" in "
86 IStringStream(split[componentColumns_[i]])()
104 List<Tuple2<scalar, Type>>& data
107 DynamicList<Tuple2<scalar, Type>> values;
110 for (
label i = 0; i < nHeaderLine_; i++)
116 const label nEntries =
max(refColumn_,
max(componentColumns_));
126 DynamicList<string> split;
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 split.append(line.substr(
pos));
159 split.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 split.append(line.substr(
pos));
179 split.append(line.substr(
pos, nPos -
pos));
186 if (split.size() <= 1)
191 scalar
x =
readScalar(IStringStream(split[refColumn_])());
192 Type value = readValue(split);
194 values.append(Tuple2<scalar,Type>(
x, value));
197 data.transfer(values);
212 nHeaderLine_(
dict.lookup<
label>(
"nHeaderLine")),
213 refColumn_(
dict.lookup<
label>(
"refColumn")),
214 componentColumns_(
dict.lookup(
"componentColumns")),
216 mergeSeparators_(
readBool(
dict.lookup(
"mergeSeparators")))
221 << componentColumns_ <<
" does not have the expected length "
250 writeEntry(os,
"componentColumns", componentColumns_);
251 writeEntry(os,
"separator",
string(separator_));
252 writeEntry(os,
"mergeSeparators", mergeSeparators_);
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void size(const label)
Override size to be inconsistent with allocated storage.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Base class to read table data for tables.
virtual void write(Ostream &os, const List< Tuple2< scalar, Type >> &table) const
Write additional information.
Reads an interpolation table from a file in CSV-format. Entries govern the layout of the CSV file....
Csv(const word &name, const dictionary &dict, List< Tuple2< scalar, Type >> &table)
Construct from dictionary.
virtual void write(Ostream &os, const List< Tuple2< scalar, Type >> &table) const
Write the CSV parameters.
virtual ~Csv()
Destructor.
A 2-tuple for storing two objects of different types.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Traits class for primitives.
A class for handling character strings derived from std::string.
A class for handling words, derived from string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensionedScalar pos(const dimensionedScalar &ds)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
label readLabel(Istream &is)
word name(const complex &)
Return a string representation of a complex.