CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Check if a file is a valid foamFile (http://www.cfd-online.com/Forums/openfoam-programming-development/119433-check-if-file-valid-foamfile.html)

Sylv June 17, 2013 11:10

Check if a file is a valid foamFile
 
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


wyldckat June 17, 2013 17:43

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

Sylv June 18, 2013 05:31

Hello Bruno,

Thank you for the tip, it works!

Regards,
Marcel


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