csvSetWriter.C
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-2023 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 \*---------------------------------------------------------------------------*/
25 
26 #include "csvSetWriter.H"
27 #include "coordSet.H"
28 #include "fileName.H"
29 #include "OFstream.H"
30 #include "OSspecific.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
40 }
41 
42 
43 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
44 
46 {
47  os << separator_;
48 }
49 
50 
52 {}
53 
54 
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56 
58 (
59  const IOstream::streamFormat writeFormat,
60  const IOstream::compressionType writeCompression
61 )
62 :
63  setWriter(writeFormat, writeCompression),
64  separator_(',')
65 {}
66 
67 
69 :
70  setWriter(dict),
71  separator_(dict.lookupOrDefault<string>("separator", string(","))[0])
72 {}
73 
74 
76 :
77  setWriter(writer),
78  separator_(writer.separator_)
79 {}
80 
81 
82 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
83 
85 {}
86 
87 
88 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
89 
91 (
92  const fileName& outputDir,
93  const fileName& setName,
94  const coordSet& set,
95  const wordList& valueSetNames
96  #define TypeValueSetsConstArg(Type, nullArg) \
97  , const UPtrList<const Field<Type>>& Type##ValueSets
100 ) const
101 {
102  if (!isDir(outputDir))
103  {
104  mkDir(outputDir);
105  }
106 
107  OFstream os
108  (
109  outputDir/setName + ".csv",
112  writeCompression_
113  );
114 
115  writeTableHeader
116  (
117  set,
118  valueSetNames,
119  #define TypeValueSetsParameter(Type, nullArg) Type##ValueSets,
122  os
123  );
124 
125  os << nl;
126 
127  writeTable
128  (
129  set,
130  #define TypeValueSetsParameter(Type, nullArg) Type##ValueSets,
133  os
134  );
135 }
136 
137 
138 // ************************************************************************* //
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Macros for easy insertion into run-time selection tables.
Pre-declare SubField and related Field type.
Definition: Field.H:82
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
Output to file stream.
Definition: OFstream.H:86
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:66
Holds list of sampling positions.
Definition: coordSet.H:51
Write set in csv format.
Definition: csvSetWriter.H:51
virtual void write(const fileName &outputDir, const fileName &setName, const coordSet &set, const wordList &valueSetNames #define TypeValueSetsConstArg(Type, nullArg)) const
Write a coordSet and associated data.
Definition: csvSetWriter.C:91
virtual void writeSegmentSeparator(Ostream &os) const
Write a segment separator.
Definition: csvSetWriter.C:51
csvSetWriter(const IOstream::streamFormat writeFormat, const IOstream::compressionType writeCompression)
Construct given write options.
Definition: csvSetWriter.C:58
virtual void writeValueSeparator(Ostream &os) const
Write a value separator.
Definition: csvSetWriter.C:45
virtual ~csvSetWriter()
Destructor.
Definition: csvSetWriter.C:84
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A class for handling file names.
Definition: fileName.H:82
Base class for writing coordinate sets with data.
Definition: setWriter.H:64
A class for handling character strings derived from std::string.
Definition: string.H:79
A class for handling words, derived from string.
Definition: word.H:62
#define TypeValueSetsParameter(Type, nullArg)
#define TypeValueSetsConstArg(Type, nullArg)
Namespace for OpenFOAM.
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:290
FOR_ALL_FIELD_TYPES(DefineContiguousFvWallLocationDataType)
defineTypeNameAndDebug(combustionModel, 0)
bool isDir(const fileName &, const bool followLink=true)
Does the name exist as a directory in the file system?
Definition: POSIX.C:539
static const char nl
Definition: Ostream.H:260
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
dictionary dict