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

foamInfoExec.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     Interrogates a case and prints information to screen
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "argList.H"
00031 #include "Time.H"
00032 #include "dictionary.H"
00033 #include "IFstream.H"
00034 
00035 using namespace Foam;
00036 
00037 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00038 // Main program:
00039 
00040 int main(int argc, char *argv[])
00041 {
00042     argList::noParallel();
00043     argList::validOptions.insert("times", "");
00044     argList::validOptions.insert("dictionary", "dictionary name");
00045     argList::validOptions.insert("keywords", "");
00046     argList::validOptions.insert("entry", "entry name");
00047 
00048 #   include "setRootCase.H"
00049 
00050     Info<< endl;
00051 
00052     if (args.optionFound("times"))
00053     {
00054         instantList times
00055         (
00056             Foam::Time::findTimes(args.rootPath()/args.caseName())
00057         );
00058 
00059         forAll (times, i)
00060         {
00061             Info<< times[i].name() << endl;
00062         }
00063     }
00064 
00065     if (args.optionFound("dictionary"))
00066     {
00067         fileName dictFileName
00068         (
00069             args.rootPath()/args.caseName()/args.option("dictionary")
00070         );
00071 
00072         IFstream dictFile(dictFileName);
00073 
00074         if (dictFile.good())
00075         {
00076             dictionary dict(dictFile);
00077 
00078             if (args.optionFound("keywords") && !args.optionFound("entry"))
00079             {
00080                 for
00081                 (
00082                     IDLList<entry>::iterator iter = dict.begin();
00083                     iter != dict.end();
00084                     ++iter
00085                 )
00086                 {
00087                     Info<< iter().keyword() << endl;
00088                 }
00089             }
00090             else if (args.optionFound("entry"))
00091             {
00092                 wordList entryNames
00093                 (
00094                     fileName(args.option("entry")).components(':')
00095                 );
00096 
00097                 if (dict.found(entryNames[0]))
00098                 {
00099                     const entry* entPtr = &dict.lookupEntry
00100                     (
00101                         entryNames[0],
00102                         false,
00103                         true            // wildcards
00104                     );
00105 
00106                     for (int i=1; i<entryNames.size(); i++)
00107                     {
00108                         if (entPtr->dict().found(entryNames[i]))
00109                         {
00110                             entPtr = &entPtr->dict().lookupEntry
00111                             (
00112                                 entryNames[i],
00113                                 false,
00114                                 true    // wildcards
00115                             );
00116                         }
00117                         else
00118                         {
00119                             FatalErrorIn(args.executable())
00120                                 << "Cannot find sub-entry " << entryNames[i]
00121                                 << " in entry " << args.option("entry")
00122                                 << " in dictionary " << dictFileName;
00123                             FatalError.exit(3);
00124                         }
00125                     }
00126 
00127                     if (args.optionFound("keywords"))
00128                     {
00129                         /*
00130                         if (ent[1] != token::BEGIN_BLOCK)
00131                         {
00132                             FatalErrorIn(args.executable())
00133                                 << "Cannot find entry "
00134                                 << args.option("entry")
00135                                 << " in dictionary " << dictFileName
00136                                 << " is not a sub-dictionary";
00137                             FatalError.exit(4);
00138                         }
00139                         */
00140 
00141                         const dictionary& dict(entPtr->dict());
00142                         for
00143                         (
00144                             IDLList<entry>::const_iterator iter = dict.begin();
00145                             iter != dict.end();
00146                             ++iter
00147                         )
00148                         {
00149                             Info<< iter().keyword() << endl;
00150                         }
00151                     }
00152                     else
00153                     {
00154                         Info<< *entPtr << endl;
00155                     }
00156                 }
00157                 else
00158                 {
00159                     FatalErrorIn(args.executable())
00160                         << "Cannot find entry "
00161                         << entryNames[0]
00162                         << " in dictionary " << dictFileName;
00163                     FatalError.exit(2);
00164                 }
00165             }
00166             else
00167             {
00168                 Info<< dict;
00169             }
00170         }
00171         else
00172         {
00173             FatalErrorIn(args.executable())
00174                 << "Cannot open file " << dictFileName;
00175             FatalError.exit(1);
00176         }
00177     }
00178 
00179     return 0;
00180 }
00181 
00182 
00183 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd