CSV.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2017-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::Function1Types::CSV
29
30Description
31 Templated CSV function.
32
33 Reference column is always a scalar, e.g. time.
34
35 Usage:
36 \verbatim
37 <entryName> csvFile;
38 <entryName>Coeffs
39 {
40 nHeaderLine 4; // number of header lines
41 refColumn 0; // reference column index
42 componentColumns (1 2 3); // component column indices
43 separator ","; // optional (defaults to ",")
44 mergeSeparators no; // merge multiple separators
45 file "fileXYZ"; // name of csv data file
46 outOfBounds clamp; // optional out-of-bounds handling
47 interpolationScheme linear; // optional interpolation scheme
48 }
49 \endverbatim
50
51SourceFiles
52 CSV.C
53
54\*---------------------------------------------------------------------------*/
55
56#ifndef Function1Types_CSV_H
57#define Function1Types_CSV_H
58
59#include "Function1.H"
60#include "TableBase.H"
61#include "Tuple2.H"
62#include "labelList.H"
63
64// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65
66namespace Foam
67{
68namespace Function1Types
69{
70
71/*---------------------------------------------------------------------------*\
72 Class CSV Declaration
73\*---------------------------------------------------------------------------*/
74
75template<class Type>
76class CSV
77:
78 public TableBase<Type>
79{
80 // Private Data
81
82 //- Number header lines
83 const label nHeaderLine_;
84
85 //- Column of the time
86 const label refColumn_;
87
88 //- Labels of the components
89 const labelList componentColumns_;
90
91 //- Separator character
92 const char separator_;
93
94 //- Merge separators flag, e.g. ',,,' becomes ','
95 const bool mergeSeparators_;
96
97 //- File name for csv table
98 fileName fName_;
99
100
101 // Private Member Functions
102
103 //- Get component columns entry
104 static labelList getComponentColumns
105 (
106 const word& name,
107 const dictionary& dict
108 );
109
110 //- Read csv data table
111 void read();
112
113 //- Read component values from the split string
114 Type readValue(const List<string>& strings) const;
115
116 //- No copy assignment
117 void operator=(const CSV<Type>&) = delete;
118
119
120public:
121
122 //- Declare type-name, virtual type (with debug switch)
123 TypeName("csvFile");
124
125
126 // Constructors
127
128 //- Construct from entry name, dictionary and optional registry
129 CSV
130 (
131 const word& entryName,
132 const dictionary& dict,
133 const objectRegistry* obrPtr = nullptr,
135 );
136
137 //- Copy construct
138 explicit CSV(const CSV<Type>& csv);
139
140 //- Construct and return a clone
141 virtual tmp<Function1<Type>> clone() const
142 {
143 return tmp<Function1<Type>>(new CSV<Type>(*this));
144 }
145
146
147 //- Destructor
148 virtual ~CSV() = default;
149
150
151 // Member Functions
152
153 //- Return const access to the file name
154 virtual const fileName& fName() const;
155
156 //- Write in dictionary format
157 virtual void writeData(Ostream& os) const;
158
159 //- Write coefficient entries in dictionary format
160 virtual void writeEntries(Ostream& os) const;
161};
162
163
164// Template specialisations
165template<>
166label CSV<label>::readValue(const List<string>& strings) const;
167
168template<>
169scalar CSV<scalar>::readValue(const List<string>& strings) const;
170
171
172// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173
174} // End namespace Function1Types
175} // End namespace Foam
176
177// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178
179#ifdef NoRepository
180 #include "CSV.C"
181#endif
182
183// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184
185#endif
186
187// ************************************************************************* //
Templated CSV function.
Definition: CSV.H:78
virtual ~CSV()=default
Destructor.
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: CSV.H:140
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: CSV.C:275
virtual const fileName & fName() const
Return const access to the file name.
Definition: CSV.C:247
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: CSV.C:254
TypeName("csvFile")
Declare type-name, virtual type (with debug switch)
Base class for table with bounds handling, interpolation and integration.
Definition: TableBase.H:63
const word const dictionary & dict
Definition: Function1.H:134
const word const dictionary const objectRegistry * obrPtr
Definition: Function1.H:136
const word & entryName
Definition: Function1.H:133
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A class for handling file names.
Definition: fileName.H:76
const word & name() const noexcept
The name of the entry.
Registry of regIOobjects.
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73