Files
OpenFOAM-12/src/OpenFOAM/primitives/functions/Function1/Table/TableReader/Csv/CsvTableReader.H
Henry Weller 4e183e33d4 Function1::Table: simplified and rationalised
TableBase, TableFile and Table now combined into a single simpler Table class
which handle both the reading of embedded and file data using the generalised
TableReader.  The new EmbeddedTableReader handles the embedded data reading
providing the functionality of the original Table class within the same
structure that can read the data from separate files.

The input format defaults to 'embedded' unless the 'file' entry is present and
the Table class is added to the run-time selection table under the name 'table'
and 'tableFile' which provides complete backward comparability.  However it is
advisable to migrate cases to use the new 'table' entry and all tutorial cases
have been updated.
2020-11-16 23:48:47 +00:00

151 lines
4.2 KiB
C++

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::TableReaders::Csv
Description
Reads an interpolation table from a file in CSV-format. Entries govern the
layout of the CSV file. The index of the first (x) column of the table is
given by the refColumn entry, and is always scalar. The indices of the
components of the second (y) column are given by the componentColumns
entry.
Usage:
\verbatim
nHeaderLine 4; // number of header lines
refColumn 0; // reference column index
componentColumns (1 2 3); // component column indices
separator ","; // optional (defaults to ",")
mergeSeparators no; // merge multiple separators
\endverbatim
SourceFiles
CsvTableReader.C
\*---------------------------------------------------------------------------*/
#ifndef CsvTableReader_H
#define CsvTableReader_H
#include "TableFileReader.H"
#include "labelList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace TableReaders
{
/*---------------------------------------------------------------------------*\
Class Csv Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class Csv
:
public TableFileReader<Type>
{
// Private Data
//- Number of header lines
const label nHeaderLine_;
//- Reference column
const label refColumn_;
//- Labels of the components
const labelList componentColumns_;
//- Separator character
const char separator_;
//- Merge separators flag; e.g. ',,,' becomes ','
bool mergeSeparators_;
// Private Member functions
//- Read the next value from the split string
Type readValue(const List<string>&) const;
//- Read a 1D table
virtual void read(ISstream&, List<Tuple2<scalar, Type>>&) const;
public:
//- Runtime type information
TypeName("csv");
// Constructors
//- Construct from dictionary
Csv
(
const word& name,
const dictionary &dict,
List<Tuple2<scalar, Type>>& table
);
//- Construct and return a copy
virtual autoPtr<TableReader<Type>> clone() const
{
return autoPtr<TableReader<Type>>(new Csv<Type>(*this));
}
//- Destructor
virtual ~Csv();
// Member Functions
//- Write the CSV parameters
virtual void write
(
Ostream& os,
const List<Tuple2<scalar, Type>>& table
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace TableReaders
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "CsvTableReader.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //