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-2018 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  //- Disallow default bitwise assignment
108  void operator=(const CSV<Type>&);
109 
110 
111 public:
112 
113  //- Runtime type information
114  TypeName("csvFile");
115 
116 
117  // Constructors
118 
119  //- Construct from entry name and dictionary
120  CSV
121  (
122  const word& entryName,
123  const dictionary& dict
124  );
125 
126  //- Copy constructor
127  CSV(const CSV<Type>& tbl);
128 
129 
130  //- Destructor
131  virtual ~CSV();
132 
133 
134  // Member Functions
135 
136  //- Return const access to the file name
137  virtual const fileName& fName() const;
138 
139  //- Write in dictionary format
140  virtual void writeData(Ostream& os) const;
141 };
142 
143 
144 template<>
146 
147 template<>
148 Foam::scalar CSV<scalar>::readValue(const List<string>& split);
149 
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 } // End namespace Function1Types
154 } // End namespace Foam
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 #ifdef NoRepository
159  #include "CSV.C"
160 #endif
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 #endif
165 
166 // ************************************************************************* //
CSV(const word &entryName, const dictionary &dict)
Construct from entry name and dictionary.
Definition: CSV.C:206
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:69
const word const dictionary & dict
Definition: Function1.H:90
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Templated CSV function.
Definition: CSV.H:73
TypeName("csvFile")
Runtime type information.
const word & entryName
Definition: Function1.H:90
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:263
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:249
virtual const fileName & fName() const
Return const access to the file name.
Definition: CSV.C:256
Namespace for OpenFOAM.