BUG: pointHitSort: define operator<
[OpenFOAM-1.7.x.git] / src / surfMesh / surfaceFormats / surfaceFormatsCore.C
blobe6ba574c5878ba5d2dde69f15373723dafb553e1
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
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 "surfaceFormatsCore.H"
28 #include "Time.H"
29 #include "IFstream.H"
30 #include "OFstream.H"
31 #include "SortableList.H"
32 #include "surfMesh.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 Foam::word Foam::fileFormats::surfaceFormatsCore::nativeExt("ofs");
38 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
40 Foam::string Foam::fileFormats::surfaceFormatsCore::getLineNoComment
42     IFstream& is
45     string line;
46     do
47     {
48         is.getLine(line);
49     }
50     while ((line.empty() || line[0] == '#') && is.good());
52     return line;
56 #if 0
57 Foam::fileName Foam::fileFormats::surfaceFormatsCore::localMeshFileName
59     const word& surfName
62     const word name(surfName.size() ? surfName : surfaceRegistry::defaultName);
64     return fileName
65     (
66         surfaceRegistry::prefix/name/surfMesh::meshSubDir
67       / name + "." + nativeExt
68     );
72 Foam::fileName Foam::fileFormats::surfaceFormatsCore::findMeshInstance
74     const Time& t,
75     const word& surfName
78     fileName localName = localMeshFileName(surfName);
80     // Search back through the time directories list to find the time
81     // closest to and lower than current time
83     instantList ts = t.times();
84     label instanceI;
86     for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
87     {
88         if (ts[instanceI].value() <= t.timeOutputValue())
89         {
90             break;
91         }
92     }
94     // Noting that the current directory has already been searched
95     // for mesh data, start searching from the previously stored time directory
97     if (instanceI >= 0)
98     {
99         for (label i = instanceI; i >= 0; --i)
100         {
101             if (isFile(t.path()/ts[i].name()/localName))
102             {
103                 return ts[i].name();
104             }
105         }
106     }
108     return "constant";
112 Foam::fileName Foam::fileFormats::surfaceFormatsCore::findMeshFile
114     const Time& t,
115     const word& surfName
118     fileName localName = localMeshFileName(surfName);
120     // Search back through the time directories list to find the time
121     // closest to and lower than current time
123     instantList ts = t.times();
124     label instanceI;
126     for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
127     {
128         if (ts[instanceI].value() <= t.timeOutputValue())
129         {
130             break;
131         }
132     }
134     // Noting that the current directory has already been searched
135     // for mesh data, start searching from the previously stored time directory
137     if (instanceI >= 0)
138     {
139         for (label i = instanceI; i >= 0; --i)
140         {
141             fileName testName(t.path()/ts[i].name()/localName);
143             if (isFile(testName))
144             {
145                 return testName;
146             }
147         }
148     }
150     // fallback to "constant"
151     return t.path()/"constant"/localName;
153 #endif
156 bool Foam::fileFormats::surfaceFormatsCore::checkSupport
158     const wordHashSet& available,
159     const word& ext,
160     const bool verbose,
161     const word& functionName
164     if (available.found(ext))
165     {
166         return true;
167     }
168     else if (verbose)
169     {
170         wordList toc = available.toc();
171         SortableList<word> known(toc.xfer());
173         Info<<"Unknown file extension for " << functionName
174             << " : " << ext << nl
175             <<"Valid types: (";
176         // compact output:
177         forAll(known, i)
178         {
179             Info<<" " << known[i];
180         }
181         Info<<" )" << endl;
182     }
184     return false;
188 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
190 Foam::fileFormats::surfaceFormatsCore::surfaceFormatsCore()
194 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
196 Foam::fileFormats::surfaceFormatsCore::~surfaceFormatsCore()
200 // ************************************************************************* //