Foam::fileName Foam::fileOperations::masterFileOperation::filePath
(
    const bool checkGlobal,
    const IOobject& io,
    pathType& searchType,
    word& newInstancePath
)
{
    newInstancePath = word::null;

    if (io.instance().isAbsolute())
    {
        fileName objectPath = io.instance()/io.name();
        if (Foam::isFile(objectPath))
        {
            searchType = fileOperation::ABSOLUTE;
            return objectPath;
        }
        else
        {
            searchType = fileOperation::NOTFOUND;
            return fileName::null;
        }
    }
    else
    {
        fileName path = io.path();
        fileName objectPath = path/io.name();

        if (Foam::isFile(objectPath))
        {
            searchType = fileOperation::OBJECT;
            return objectPath;
        }
        else
        {
            if
            (
                checkGlobal
             && io.time().processorCase()
             && (
                    io.instance() == io.time().system()
                 || io.instance() == io.time().constant()
                )
            )
            {
                fileName parentObjectPath =
                    io.rootPath()/io.time().globalCaseName()
                   /io.instance()/io.db().dbDir()/io.local()/io.name();

                if (Foam::isFile(parentObjectPath))
                {
                    searchType = fileOperation::PARENTOBJECT;
                    return parentObjectPath;
                }
            }

//- The big problem with findInstance is that it itself needs file
//  access through the fileHandler. Since this routine is only called on the
//  master we'll get a deadlock.
//            if (!Foam::isDir(path))
//            {
//                newInstancePath = io.time().findInstancePath
//                (
//                    instant(io.instance())
//                );
//
//                if (newInstancePath.size())
//                {
//                    fileName fName
//                    (
//                        io.rootPath()/io.caseName()
//                       /newInstancePath/io.db().dbDir()/io.local()/io.name()
//                    );
//
//                    if (Foam::isFile(fName))
//                    {
//                        searchType = fileOperation::FINDINSTANCE;
//                        return fName;
//                    }
//                }
//            }

            // Try constant & local
            {
                newInstancePath = io.time().constant();
                fileName fName
                (
                    io.rootPath()
                   /io.caseName()
                   /newInstancePath
                   /io.db().dbDir()
                   /io.local()
                   /io.name()
                );
                //DebugVar(fName);

                if (Foam::isFile(fName))
                {
                    searchType = fileOperation::FINDINSTANCE;
                    return fName;
                }
            }

        }

        return fileName::null;
    }
}
Foam::fileName Foam::fileOperations::masterFileOperation::objectPath
(
    const IOobject& io,
    const pathType& searchType,
    const word& instancePath
)
{
    // Replacement for IOobject::objectPath()

    switch (searchType)
    {
        case fileOperation::ABSOLUTE:
        {
            return io.instance()/io.name();
        }
        break;

        case fileOperation::OBJECT:
        {
            return io.path()/io.name();
        }
        break;

        case fileOperation::PROCESSORSOBJECT:
        {
            return processorsPath(io, io.instance())/io.name();
        }
        break;

        case fileOperation::PARENTOBJECT:
        {
            return
                io.rootPath()/io.time().globalCaseName()
               /io.instance()/io.db().dbDir()/io.local()/io.name();
        }
        break;

        case fileOperation::FINDINSTANCE:
        {
            return
                io.rootPath()/io.caseName()
               /instancePath/io.db().dbDir()/io.local()/io.name();
        }
        break;

        case fileOperation::PROCESSORSFINDINSTANCE:
        {
            return processorsPath(io, instancePath)/io.name();
        }
        break;

        case fileOperation::NOTFOUND:
        {
            return fileName::null;
        }
        break;

        default:
        {
            NotImplemented;
            return fileName::null;
        }
    }
}