OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Searches the current case directory for valid times
00027     and sets the time list to these.
00028     This is done if a times File does not exist.
00029 
00030 \*---------------------------------------------------------------------------*/
00031 
00032 #include "Time.H"
00033 #include "OSspecific.H"
00034 #include "IStringStream.H"
00035 
00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00037 
00038 Foam::instantList Foam::Time::findTimes(const fileName& directory)
00039 {
00040     if (debug)
00041     {
00042         Info<< "Time::findTimes(const fileName&): finding times in directory "
00043             << directory << endl;
00044     }
00045 
00046     // Read directory entries into a list
00047     fileNameList dirEntries(readDir(directory, fileName::DIRECTORY));
00048 
00049     // Initialise instant list
00050     instantList Times(dirEntries.size() + 1);
00051     label nTimes = 0;
00052 
00053     // Check for "constant"
00054     bool haveConstant = false;
00055     forAll(dirEntries, i)
00056     {
00057         if (dirEntries[i] == "constant")
00058         {
00059             Times[nTimes].value() = 0;
00060             Times[nTimes].name() = dirEntries[i];
00061             nTimes++;
00062             haveConstant = true;
00063             break;
00064         }
00065     }
00066 
00067     // Read and parse all the entries in the directory
00068     forAll(dirEntries, i)
00069     {
00070         IStringStream timeStream(dirEntries[i]);
00071         token timeToken(timeStream);
00072 
00073         if (timeToken.isNumber() && timeStream.eof())
00074         {
00075             Times[nTimes].value() = timeToken.number();
00076             Times[nTimes].name() = dirEntries[i];
00077             nTimes++;
00078         }
00079     }
00080 
00081     // Reset the length of the times list
00082     Times.setSize(nTimes);
00083 
00084     if (haveConstant)
00085     {
00086         if (nTimes > 2)
00087         {
00088             std::sort(&Times[1], Times.end(), instant::less());
00089         }
00090     }
00091     else if (nTimes > 1)
00092     {
00093         std::sort(&Times[0], Times.end(), instant::less());
00094     }
00095 
00096     return Times;
00097 }
00098 
00099 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd