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 | Copyright (C) 2011-2016 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 container data entry. Reference column is always a scalar,
29  e.g. time
30 
31  \verbatim
32  <entryName> csvFile;
33  <entryName>Coeffs
34  {
35  nHeaderLine 4; // number of header lines
36  refColumn 0; // reference column index
37  componentColumns (1 2 3); // component column indices
38  separator ","; // optional (defaults to ",")
39  mergeSeparators no; // merge multiple separators
40  fileName "fileXYZ"; // name of csv data file
41  outOfBounds clamp; // optional out-of-bounds handling
42  interpolationScheme linear; // optional interpolation scheme
43  }
44  \endverbatim
45 
46 SourceFiles
47  CSV.C
48 
49 \*---------------------------------------------------------------------------*/
50 
51 #ifndef CSV_H
52 #define CSV_H
53 
54 #include "Function1.H"
55 #include "TableBase.H"
56 #include "Tuple2.H"
57 #include "labelList.H"
58 #include "ISstream.H"
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 namespace Foam
63 {
64 namespace Function1Types
65 {
66 
67 /*---------------------------------------------------------------------------*\
68  Class CSV Declaration
69 \*---------------------------------------------------------------------------*/
70 
71 template<class Type>
72 class CSV
73 :
74  public TableBase<Type>
75 {
76  // Private data
77 
78  //- Coefficients dictionary (for convenience on reading)
79  dictionary coeffs_;
80 
81  //- Number header lines
82  label nHeaderLine_;
83 
84  //- Column of the time
85  label refColumn_;
86 
87  //- Labels of the components
88  labelList componentColumns_;
89 
90  //- Separator character
91  char separator_;
92 
93  //- Merge separators flag, e.g. ',,,' becomes ','
94  bool mergeSeparators_;
95 
96  //- File name for csv table
97  fileName fName_;
98 
99 
100  // Private Member Functions
101 
102  //- Read csv data table
103  void read();
104 
105  //- Read the next value from the splitted string
106  Type readValue(const List<string>&);
107 
108  //- Disallow default bitwise assignment
109  void operator=(const CSV<Type>&);
110 
111 
112 public:
113 
114  //- Runtime type information
115  TypeName("csvFile");
116 
117 
118  // Constructors
119 
120  //- Construct from entry name and dictionary
121  CSV
122  (
123  const word& entryName,
124  const dictionary& dict,
125  const word& ext = "Coeffs"
126  );
127 
128  //- Copy constructor
129  CSV(const CSV<Type>& tbl);
130 
131  //- Construct and return a clone
132  virtual tmp<Function1<Type>> clone() const
133  {
134  return tmp<Function1<Type>>(new CSV<Type>(*this));
135  }
136 
137 
138  //- Destructor
139  virtual ~CSV();
140 
141 
142  // Member Functions
143 
144  //- Return const access to the file name
145  virtual const fileName& fName() const;
146 
147  //- Write in dictionary format
148  virtual void writeData(Ostream& os) const;
149 };
150 
151 
152 template<>
153 label CSV<label>::readValue(const List<string>& splitted);
154 
155 template<>
156 Foam::scalar CSV<scalar>::readValue(const List<string>& splitted);
157 
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 } // End namespace Function1Types
162 } // End namespace Foam
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 #ifdef NoRepository
167  #include "CSV.C"
168 #endif
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 #endif
173 
174 // ************************************************************************* //
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:88
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
virtual const fileName & fName() const
Return const access to the file name.
Definition: CSV.C:256
Templated CSV container data entry. Reference column is always a scalar, e.g. time.
Definition: CSV.H:71
CSV(const word &entryName, const dictionary &dict, const word &ext="Coeffs")
Construct from entry name and dictionary.
Definition: CSV.C:204
TypeName("csvFile")
Runtime type information.
const word & entryName
Definition: Function1.H:88
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: CSV.C:263
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 tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: CSV.H:131
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
A class for managing temporary objects.
Definition: PtrList.H:54
Namespace for OpenFOAM.