ensightFile.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-2021 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::ensightFile
26 
27 Description
28  Ensight output with specialised write() for strings, integers and floats.
29  Correctly handles binary write as well.
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #ifndef ensightFile_H
34 #define ensightFile_H
35 
36 #include "OFstream.H"
37 #include "IOstream.H"
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43 
44 /*---------------------------------------------------------------------------*\
45  Class ensightFile Declaration
46 \*---------------------------------------------------------------------------*/
47 
48 class ensightFile
49 :
50  public OFstream
51 {
52  // Private Data
53 
54  //- Allow undef in results
55  static bool allowUndef_;
56 
57  //- Value to represent undef in results
58  static scalar undefValue_;
59 
60  //- The '*' mask appropriate for subDir
61  static string mask_;
62 
63  //- The printf format for zero-padded subdirectory numbers
64  static string dirFmt_;
65 
66 
67 public:
68 
69  // Constructors
70 
71  //- Construct from filePath
73  (
74  const fileName& filePath,
76  );
77 
78  //- Disallow default bitwise copy construction
79  ensightFile(const ensightFile&);
80 
81 
82  //- Destructor
83  ~ensightFile();
84 
85 
86  // Access
87 
88  //- Return setting for whether 'undef' values are allowed in results
89  static bool allowUndef();
90 
91  //- The '*' mask appropriate for subDir
92  static string mask();
93 
94  //- Consistent zero-padded numbers for subdirectories
95  static string subDir(const label);
96 
97  //- Set width of subDir and mask. Default width is 8 digits.
98  // Max width is 31 digits.
99  static void subDirWidth(const label);
100 
101  //- Return current width of subDir and mask.
102  static label subDirWidth();
103 
104 
105  // Edit
106 
107  static bool allowUndef(bool);
108 
109  //- Assign the value to represent undef in the results
110  // Returns the previous value
111  // NB: do not use values larger than floatScalarvGreat
112  static scalar undefValue(const scalar);
113 
114 
115  // Output
116 
117  //- Inherit write from Ostream
118  using Ostream::write;
119 
120  //- Binary write
121  virtual Ostream& write(const char* buf, std::streamsize count);
122 
123  //- Write element keyword with trailing newline, optionally with undef
124  virtual Ostream& writeKeyword(const string& key);
125 
126  //- Write "C Binary" for binary files (eg, geometry/measured)
128 
129  //- Write undef value
130  Ostream& writeUndef();
131 
132  //- Write C-string as "%80s" or as binary
133  Ostream& write(const char* value);
134 
135  //- Write string as "%80s" or as binary
136  Ostream& write(const string& value);
137 
138  //- Write integer as "%10d" or as binary
139  Ostream& write(const label value);
140 
141  //- Write integer with specified width or as binary
142  Ostream& write(const label value, const label fieldWidth);
143 
144  //- Write float as "%12.5e" or as binary
145  Ostream& write(const scalar value);
146 
147  //- Add carriage return to ascii stream
148  void newline();
149 
150 
151  // Member Operators
152 
153  //- Disallow default bitwise assignment
154  void operator=(const ensightFile&) = delete;
155 };
156 
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 } // End namespace Foam
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 #endif
165 
166 // ************************************************************************* //
Ostream & writeUndef()
Write undef value.
Definition: ensightFile.C:268
Ensight output with specialised write() for strings, integers and floats. Correctly handles binary wr...
Definition: ensightFile.H:47
virtual Ostream & write(const char)=0
Write character.
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
static scalar undefValue(const scalar)
Assign the value to represent undef in the results.
Definition: ensightFile.C:124
Output to file stream.
Definition: OFstream.H:82
label count(const ListType &l, typename ListType::const_reference x)
Count the number of occurrences of a value in a list.
static string subDir(const label)
Consistent zero-padded numbers for subdirectories.
Definition: ensightFile.C:49
virtual Ostream & writeKeyword(const string &key)
Write element keyword with trailing newline, optionally with undef.
Definition: ensightFile.C:275
~ensightFile()
Destructor.
Definition: ensightFile.C:104
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
static string mask()
The &#39;*&#39; mask appropriate for subDir.
Definition: ensightFile.C:43
streamFormat format() const
Return current stream format.
Definition: IOstream.H:374
virtual Ostream & write(const char *buf, std::streamsize count)
Binary write.
Definition: ensightFile.C:136
static bool allowUndef()
Return setting for whether &#39;undef&#39; values are allowed in results.
Definition: ensightFile.C:110
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
Ostream & writeBinaryHeader()
Write "C Binary" for binary files (eg, geometry/measured)
Definition: ensightFile.C:293
void newline()
Add carriage return to ascii stream.
Definition: ensightFile.C:259
void operator=(const ensightFile &)=delete
Disallow default bitwise assignment.
static label subDirWidth()
Return current width of subDir and mask.
Definition: ensightFile.C:76
Namespace for OpenFOAM.
ensightFile(const fileName &filePath, IOstream::streamFormat format=IOstream::BINARY)
Construct from filePath.
Definition: ensightFile.C:85