CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

Check if a file is a valid foamFile

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 2 Post By wyldckat

Reply
 
LinkBack Thread Tools Display Modes
Old   June 17, 2013, 11:10
Default Check if a file is a valid foamFile
  #1
New Member
 
Marcel Vonlanthen
Join Date: Nov 2012
Location: Zurich, Switzerland
Posts: 27
Rep Power: 4
Sylv is on a distinguished road
Dear Foamer,

Is there a function/method to check if a file is a well formatted foamFile? Namely, if it start by a valid header? I'm looking for something, which return a bool, then I can handle the different cases...

For example:

example 1: well formatted
Code:
FoamFile
{
    version     2.0;
    format      ascii;
    class       vectorField;
    object      values;
}
example 2: well formatted
Code:
// blah blah blah
FoamFile
{
    version     2.0;
    format      ascii;
    class       vectorField;
    object      values;
}
example 3: badly formatted:
Code:
//blah blah blah
324
456.8
5.7
34
Sylv is offline   Reply With Quote

Old   June 17, 2013, 17:43
Default
  #2
Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 8,253
Blog Entries: 34
Rep Power: 84
wyldckat is just really nicewyldckat is just really nicewyldckat is just really nicewyldckat is just really nice
Greetings Marcel,

In OpenFOAM's source code applications folder, you should be able to find several examples like the following, which can be seen online here:
Quote:
https://github.com/OpenFOAM/OpenFOAM...ryLayer.C#L167
Code:
        // Turbulence omega
        IOobject omegaHeader
        (
            "omega",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::NO_WRITE,
            false
        );

        if (omegaHeader.headerOk())
        {
            volScalarField omega(omegaHeader, mesh);
            omega =
                epsilon
               /(
                   Cmu*k+dimensionedScalar("VSMALL", k.dimensions(), VSMALL)
                );
            omega.correctBoundaryConditions();

            Info<< "Writing omega\n" << endl;
            omega.write();
        }
As you can see, it first only loads up the header mechanism, to check if the header is OK. Only then does it finally load the whole field file and process it.

Best regards,
Bruno
Tobi and Sylv like this.
wyldckat is offline   Reply With Quote

Old   June 18, 2013, 05:31
Default
  #3
New Member
 
Marcel Vonlanthen
Join Date: Nov 2012
Location: Zurich, Switzerland
Posts: 27
Rep Power: 4
Sylv is on a distinguished road
Hello Bruno,

Thank you for the tip, it works!

Regards,
Marcel
Sylv is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
swak4foam building problem GGerber OpenFOAM Installation 54 April 24, 2015 16:02
swak4Foam-groovyBC build problem zxj160 OpenFOAM 18 July 30, 2013 13:14
which tutorial can find that include Riemann boundary condition? immortality OpenFOAM Running, Solving & CFD 12 May 3, 2013 18:21
friction forces icoFoam ofslcm OpenFOAM 3 April 7, 2012 10:57
error message with modeling a cube with a hold at the center hsingtzu OpenFOAM Native Meshers: blockMesh 2 March 14, 2012 10:56


All times are GMT -4. The time now is 10:21.