FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

findTimes.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Description
00025     Searches the current case directory for valid times
00026     and sets the time list to these.
00027     This is done if a times File does not exist.
00028 
00029 \*---------------------------------------------------------------------------*/
00030 
00031 #include "Time.H"
00032 #include <OpenFOAM/OSspecific.H>
00033 #include <OpenFOAM/IStringStream.H>
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 
00037 Foam::instantList Foam::Time::findTimes(const fileName& directory)
00038 {
00039     if (debug)
00040     {
00041         Info<< "Time::findTimes(const fileName&): finding times in directory "
00042             << directory << endl;
00043     }
00044 
00045     // Read directory entries into a list
00046     fileNameList dirEntries(readDir(directory, fileName::DIRECTORY));
00047 
00048     // Initialise instant list
00049     instantList Times(dirEntries.size() + 1);
00050     label nTimes = 0;
00051 
00052     // Check for "constant"
00053     bool haveConstant = false;
00054     forAll(dirEntries, i)
00055     {
00056         if (dirEntries[i] == "constant")
00057         {
00058             Times[nTimes].value() = 0;
00059             Times[nTimes].name() = dirEntries[i];
00060             nTimes++;
00061             haveConstant = true;
00062             break;
00063         }
00064     }
00065 
00066     // Read and parse all the entries in the directory
00067     forAll(dirEntries, i)
00068     {
00069         IStringStream timeStream(dirEntries[i]);
00070         token timeToken(timeStream);
00071 
00072         if (timeToken.isNumber() && timeStream.eof())
00073         {
00074             Times[nTimes].value() = timeToken.number();
00075             Times[nTimes].name() = dirEntries[i];
00076             nTimes++;
00077         }
00078     }
00079 
00080     // Reset the length of the times list
00081     Times.setSize(nTimes);
00082 
00083     if (haveConstant)
00084     {
00085         if (nTimes > 2)
00086         {
00087             std::sort(&Times[1], Times.end(), instant::less());
00088         }
00089     }
00090     else if (nTimes > 1)
00091     {
00092         std::sort(&Times[0], Times.end(), instant::less());
00093     }
00094 
00095     return Times;
00096 }
00097 
00098 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines