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

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-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 Application
00025     foamInfoExec
00026 
00027 Description
00028     Interrogates a case and prints information to screen
00029 
00030 Usage
00031 
00032     - foamInfoExec [OPTIONS]
00033 
00034     @param -dictionary <dictionary name>\n
00035     Use specified dictionary.
00036 
00037     @param -entry <entry name>\n
00038     Use specified entry from dictionary (parent:child notation)
00039 
00040     @param -keywords \n
00041     List keywords in the dictionary.
00042 
00043     @param -times \n
00044     List all time steps.
00045 
00046     @param -case <dir>\n
00047     Case directory.
00048 
00049     @param -help \n
00050     Display help message.
00051 
00052     @param -doc \n
00053     Display Doxygen API documentation page for this application.
00054 
00055     @param -srcDoc \n
00056     Display Doxygen source documentation page for this application.
00057 
00058 \*---------------------------------------------------------------------------*/
00059 
00060 #include <OpenFOAM/argList.H>
00061 #include <OpenFOAM/Time.H>
00062 #include <OpenFOAM/dictionary.H>
00063 #include <OpenFOAM/IFstream.H>
00064 
00065 using namespace Foam;
00066 
00067 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00068 // Main program:
00069 
00070 int main(int argc, char *argv[])
00071 {
00072     argList::noParallel();
00073     argList::validOptions.insert("times", "");
00074     argList::validOptions.insert("dictionary", "dictionary name");
00075     argList::validOptions.insert("keywords", "");
00076     argList::validOptions.insert("entry", "entry name");
00077 
00078 #   include <OpenFOAM/setRootCase.H>
00079 
00080     Info<< endl;
00081 
00082     if (args.optionFound("times"))
00083     {
00084         instantList times
00085         (
00086             Foam::Time::findTimes(args.rootPath()/args.caseName())
00087         );
00088 
00089         forAll (times, i)
00090         {
00091             Info<< times[i].name() << endl;
00092         }
00093     }
00094 
00095     if (args.optionFound("dictionary"))
00096     {
00097         fileName dictFileName
00098         (
00099             args.rootPath()/args.caseName()/args.option("dictionary")
00100         );
00101 
00102         IFstream dictFile(dictFileName);
00103 
00104         if (dictFile.good())
00105         {
00106             dictionary dict(dictFile);
00107 
00108             if (args.optionFound("keywords") && !args.optionFound("entry"))
00109             {
00110                 for
00111                 (
00112                     IDLList<entry>::iterator iter = dict.begin();
00113                     iter != dict.end();
00114                     ++iter
00115                 )
00116                 {
00117                     Info<< iter().keyword() << endl;
00118                 }
00119             }
00120             else if (args.optionFound("entry"))
00121             {
00122                 wordList entryNames
00123                 (
00124                     fileName(args.option("entry")).components(':')
00125                 );
00126 
00127                 if (dict.found(entryNames[0]))
00128                 {
00129                     const entry* entPtr = &dict.lookupEntry
00130                     (
00131                         entryNames[0],
00132                         false,
00133                         true            // wildcards
00134                     );
00135 
00136                     for (int i=1; i<entryNames.size(); i++)
00137                     {
00138                         if (entPtr->dict().found(entryNames[i]))
00139                         {
00140                             entPtr = &entPtr->dict().lookupEntry
00141                             (
00142                                 entryNames[i],
00143                                 false,
00144                                 true    // wildcards
00145                             );
00146                         }
00147                         else
00148                         {
00149                             FatalErrorIn(args.executable())
00150                                 << "Cannot find sub-entry " << entryNames[i]
00151                                 << " in entry " << args.option("entry")
00152                                 << " in dictionary " << dictFileName;
00153                             FatalError.exit(3);
00154                         }
00155                     }
00156 
00157                     if (args.optionFound("keywords"))
00158                     {
00159                         /*
00160                         if (ent[1] != token::BEGIN_BLOCK)
00161                         {
00162                             FatalErrorIn(args.executable())
00163                                 << "Cannot find entry "
00164                                 << args.option("entry")
00165                                 << " in dictionary " << dictFileName
00166                                 << " is not a sub-dictionary";
00167                             FatalError.exit(4);
00168                         }
00169                         */
00170 
00171                         const dictionary& dict(entPtr->dict());
00172                         for
00173                         (
00174                             IDLList<entry>::const_iterator iter = dict.begin();
00175                             iter != dict.end();
00176                             ++iter
00177                         )
00178                         {
00179                             Info<< iter().keyword() << endl;
00180                         }
00181                     }
00182                     else
00183                     {
00184                         Info<< *entPtr << endl;
00185                     }
00186                 }
00187                 else
00188                 {
00189                     FatalErrorIn(args.executable())
00190                         << "Cannot find entry "
00191                         << entryNames[0]
00192                         << " in dictionary " << dictFileName;
00193                     FatalError.exit(2);
00194                 }
00195             }
00196             else
00197             {
00198                 Info<< dict;
00199             }
00200         }
00201         else
00202         {
00203             FatalErrorIn(args.executable())
00204                 << "Cannot open file " << dictFileName;
00205             FatalError.exit(1);
00206         }
00207     }
00208 
00209     return 0;
00210 }
00211 
00212 
00213 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines