ensightFile.H 5.24 KB
Newer Older
1 2 3 4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2015 OpenFOAM Foundation
6
     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
7 8 9 10
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

11 12 13 14
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
15 16 17 18 19 20 21

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    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 27 28 29 30 31

Class
    Foam::ensightFile

Description
    Ensight output with specialized write() for strings, integers and floats.
    Correctly handles binary write as well.

\*---------------------------------------------------------------------------*/
32

33 34 35 36 37 38
#ifndef ensightFile_H
#define ensightFile_H

#include "OFstream.H"
#include "IOstream.H"

39 40 41
#include "ensightFileName.H"
#include "ensightVarName.H"

42 43
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

44 45 46 47
namespace Foam
{

/*---------------------------------------------------------------------------*\
48
                         Class ensightFile Declaration
49 50 51 52 53 54
\*---------------------------------------------------------------------------*/

class ensightFile
:
    public OFstream
{
55 56
    // Private data

57
        //- Allow undef in results
58
        static bool allowUndef_;
59

60
        //- Value to represent undef in results
61
        static scalar undefValue_;
62

63 64 65 66 67 68
        //- The '*' mask appropriate for subDir
        static string mask_;

        //- The printf format for zero-padded subdirectory numbers
        static string dirFmt_;

69

70
    // Private Member Functions
71

72 73 74
        //- Initialize by setting the ASCII output formatting
        void initialize();

75
        //- Disallow default bitwise assignment
76
        void operator=(const ensightFile&) = delete;
77 78

        //- Disallow default copy constructor
79
        ensightFile(const ensightFile&) = delete;
80 81

public:
82

83 84 85 86 87
    // Forward declarations
    class FileName;
    class VarName;


88 89
    // Constructors

90 91
        //- Construct from pathname.
        //  The entire pathname is checked for valid ensight naming.
92 93 94 95 96 97
        ensightFile
        (
            const fileName& pathname,
            IOstream::streamFormat format=IOstream::BINARY
        );

98 99 100 101 102 103 104 105 106
        //- Construct from path and name.
        //  Only the name portion is checked for valid ensight naming.
        ensightFile
        (
            const fileName& path,
            const fileName& name,
            IOstream::streamFormat format=IOstream::BINARY
        );

107

108
    //- Destructor
109 110
    ~ensightFile();

111 112

    // Access
113

114 115 116
        //- Return setting for whether 'undef' values are allowed in results
        static bool allowUndef();

117
        //- The '*' mask appropriate for subDir
118 119
        static string mask();

120
        //- Consistent zero-padded numbers for subdirectories
121 122
        static string subDir(const label);

123 124 125 126 127 128 129
        //- Set width of subDir and mask. Default width is 8 digits.
        //  Max width is 31 digits.
        static void subDirWidth(const label);

        //- Return current width of subDir and mask.
        static label subDirWidth();

130

131
    // Edit
132

133 134 135 136 137
        static bool allowUndef(bool);

        //- Assign the value to represent undef in the results
        //  Returns the previous value
        //  NB: do not use values larger than floatScalarVGREAT
138
        static scalar undefValue(const scalar);
139

140

141 142
    // Output

143 144 145
        //- Inherit write from Ostream
        using Ostream::write;

146
        //- Binary write
147
        virtual Ostream& write(const char*, std::streamsize count);
148

149
        //- Write element keyword with trailing newline, optionally with undef
150
        virtual Ostream& writeKeyword(const keyType&);
151

152
        //- Write "C Binary" for binary files (eg, geometry/measured)
153 154
        Ostream& writeBinaryHeader();

155
        //- Write undef value
156 157
        Ostream& writeUndef();

158
        //- Write C-string as "%79s" or as binary (max 80 chars)
159
        Ostream& write(const char*);
160

161
        //- Write string as "%79s" or as binary (max 80 chars)
162
        Ostream& write(const string&);
163

164
        //- Write integer as "%10d" or as binary
165
        Ostream& write(const label);
166

167
        //- Write integer with specified width or as binary
168
        Ostream& write(const label, const label fieldWidth);
169

170
        //- Write float as "%12.5e" or as binary
171
        Ostream& write(const scalar);
172 173 174 175 176 177 178 179 180 181

        //- Add carriage return to ascii stream
        void newline();
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

182 183
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

184 185 186
#endif

// ************************************************************************* //