ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / fileFormats / starcd / STARCDCore.C
blob07afd63d10035715ba235b68559fddc5e693fb49
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "STARCDCore.H"
27 #include "ListOps.H"
28 #include "clock.H"
29 #include "PackedBoolList.H"
30 #include "IStringStream.H"
32 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
34 Foam::fileFormats::STARCDCore::STARCDCore()
38 // * * * * * * * * * * *  Protected Member Functions * * * * * * * * * * * * //
40 bool Foam::fileFormats::STARCDCore::readHeader
42     IFstream& is,
43     const word& signature
46     if (!is.good())
47     {
48         FatalErrorIn
49         (
50             "fileFormats::STARCDCore::readHeader(...)"
51         )
52             << "cannot read " << signature  << "  " << is.name()
53             << abort(FatalError);
54     }
56     word header;
57     label majorVersion;
59     string line;
61     is.getLine(line);
62     IStringStream(line)() >> header;
64     is.getLine(line);
65     IStringStream(line)() >> majorVersion;
67     // add other checks ...
68     if (header != signature)
69     {
70         Info<< "header mismatch " << signature << "  " << is.name()
71             << endl;
72     }
74     return true;
78 void Foam::fileFormats::STARCDCore::writeHeader
80     Ostream& os,
81     const word& filetype
84     os  << "PROSTAR_" << filetype << nl
85         << 4000
86         << " " << 0
87         << " " << 0
88         << " " << 0
89         << " " << 0
90         << " " << 0
91         << " " << 0
92         << " " << 0
93         << endl;
97 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
99 bool Foam::fileFormats::STARCDCore::readPoints
101     IFstream& is,
102     pointField& points,
103     labelList& ids
106     if (!is.good())
107     {
108         FatalErrorIn
109         (
110             "fileFormats::STARCDedgeFormat::readPoints(...)"
111         )
112             << "Cannot read file " << is.name()
113             << exit(FatalError);
114     }
116     readHeader(is, "PROSTAR_VERTEX");
119     // reuse memory if possible
120     DynamicList<point> dynPoints(points.xfer());
121     DynamicList<label> dynPointId(ids.xfer());    // STAR-CD index of points
123     dynPoints.clear();
124     dynPointId.clear();
126     label lineLabel;
127     while ((is >> lineLabel).good())
128     {
129         scalar x, y, z;
131         is >> x >> y >> z;
133         dynPoints.append(point(x, y, z));
134         dynPointId.append(lineLabel);
135     }
137     points.transfer(dynPoints);
138     ids.transfer(dynPointId);
140     return true;
144 void Foam::fileFormats::STARCDCore::writePoints
146     Ostream& os,
147     const pointField& pointLst
150     writeHeader(os, "VERTEX");
152     // Set the precision of the points data to 10
153     os.precision(10);
155     // force decimal point for Fortran input
156     os.setf(std::ios::showpoint);
158     forAll(pointLst, ptI)
159     {
160         os
161             << ptI + 1 << " "
162             << pointLst[ptI].x() << " "
163             << pointLst[ptI].y() << " "
164             << pointLst[ptI].z() << nl;
165     }
166     os.flush();
172 // ************************************************************************* //