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

Check if a file is a valid foamFile

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By wyldckat

Reply
 
LinkBack Thread Tools Search this Thread 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: 28
Rep Power: 13
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
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,975
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
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: 28
Rep Power: 13
Sylv is on a distinguished road
Hello Bruno,

Thank you for the tip, it works!

Regards,
Marcel
Sylv is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[swak4Foam] swak4foam building problem GGerber OpenFOAM Community Contributions 54 April 24, 2015 16:02
[swak4Foam] swak4Foam-groovyBC build problem zxj160 OpenFOAM Community Contributions 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
[blockMesh] error message with modeling a cube with a hold at the center hsingtzu OpenFOAM Meshing & Mesh Conversion 2 March 14, 2012 09:56


All times are GMT -4. The time now is 19:55.