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