int main(int argc, char *argv[])
{
    argList::addNote
    (
        "upgrade the syntax of system/fvSolution::solvers"
    );

    argList::noParallel();
    argList::addBoolOption
    (
        "test",
        "suppress writing the updated system/fvSolution file"
    );

#   include "setRootCase.H"
#   include "createTime.H"

    IOdictionary solutionDict
    (
        IOobject
        (
            "fvSolution",
            runTime.system(),
            runTime,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE,
            false
        )
    );

    label nChanged = 0;
    entry* e = solutionDict.lookupEntryPtr("solvers", false, false);
    if (e && e->isDict())
    {
        nChanged = solution::upgradeSolverDict(e->dict(), true);
    }

    Info<< nChanged << " solver settings changed" << nl << endl;
    if (nChanged)
    {
        if (args.optionFound("test"))
        {
            Info<< "-test option: no changes made" << nl << endl;
        }
        else
        {
            if (mvBak(solutionDict.objectPath(), "old"))
            {
                Info<< "Backup to    "
                    << (solutionDict.objectPath() + ".old") << nl;
            }

            solutionDict.writeObject
            (
                IOstream::ASCII,
                IOstream::currentVersion,
                IOstream::UNCOMPRESSED
            );

            Info<< "Write  to    "
                << solutionDict.objectPath() << nl << endl;
        }
    }

    return 0;
}
void rewriteField
(
    const bool isTestRun,
    const Time& runTime,
    const word& fieldName,
    const HashTable<word>& thisNames,
    const HashTable<word>& nbrNames
)
{
    // Read dictionary. (disable class type checking so we can load
    // field)
    Info<< "Loading field " << fieldName << endl;
    const word oldTypeName = IOdictionary::typeName;
    const_cast<word&>(IOdictionary::typeName) = word::null;

    IOdictionary fieldDict
    (
        IOobject
        (
            fieldName,
            runTime.timeName(),
            runTime,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE,
            false
        )
    );
    const_cast<word&>(IOdictionary::typeName) = oldTypeName;
    // Fake type back to what was in field
    const_cast<word&>(fieldDict.type()) = fieldDict.headerClassName();



    dictionary& boundaryField = fieldDict.subDict("boundaryField");

    label nChanged = 0;

    forAllConstIter(HashTable<word>, thisNames, iter)
    {
        const word& patchName = iter.key();
        const word& newName = iter();

        Info<< "Looking for entry for patch " << patchName << endl;

        // Find old patch name either direct or through wildcards
        // Find new patch name direct only

        if
        (
            boundaryField.found(patchName)
        && !boundaryField.found(newName, false, false)
        )
        {
            Info<< "    Changing entry " << patchName << " to " << newName
                << endl;

            dictionary& patchDict = boundaryField.subDict(patchName);

            if (patchDict.found("value"))
            {
                // Remove any value field since wrong size.
                patchDict.remove("value");
            }


            boundaryField.changeKeyword(patchName, newName);
            boundaryField.add
            (
                nbrNames[patchName],
                patchDict
            );
            Info<< "    Adding entry " << nbrNames[patchName] << endl;

            nChanged++;
        }
    }

    // Info<< "New boundaryField:" << boundaryField << endl;

    if (returnReduce(nChanged, sumOp<label>()) > 0)
    {
        if (isTestRun)
        {
            // Info<< "-test option: no changes made" << endl;
        }
        else
        {
            if (mvBak(fieldDict.objectPath(), "old"))
            {
                Info<< "Backup to    "
                    << (fieldDict.objectPath() + ".old") << nl;
            }

            Info<< "Write  to    "
                << fieldDict.objectPath() << endl;
            fieldDict.regIOobject::write();
        }
    }
    else
    {
        Info<< "No changes made to field " << fieldName << endl;
    }
    Info<< endl;
}
int main(int argc, char *argv[])
{
    argList::noParallel();
    argList::addBoolOption("rewrite");
    argList::addBoolOption("show");

    argList args(argc, argv);

    Time runTime(args.rootPath(), args.caseName());

    const word dictName("fvSolution");

    bool optRewrite = args.optionFound("rewrite");
    bool optShow = args.optionFound("show");

    IOdictionary solutionDict
    (
        IOobject
        (
            dictName,
            "system",
            runTime,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE,
            false
        )
    );

    if (!solutionDict.found("solvers"))
    {
        Info<<"no solvers entry found in : " << dictName << endl;
        return 2;
    }

    if (optRewrite && solutionDict.instance() != "system")
    {
        Info<<"instance is not 'system' "
            "- disabling rewrite for this file" << nl;
        optRewrite = false;
    }

    dictionary& solverDict = solutionDict.subDict("solvers");

    wordList names = solverDict.toc();
    wordList oldNames = names;

    bool changed = false;
    for (label orig = 0; orig < names.size()-1; ++orig)
    {
        // skip patterns or entries that have already been done
        if (names[orig].empty() || wordRe::isPattern(names[orig]))
        {
            continue;
        }

        const dictionary& dict1 = solverDict.subDict(names[orig]);

        for (label check = orig+1; check < names.size(); ++check)
        {
            // skip patterns or entries that have already been done
            if (names[check].empty() || wordRe::isPattern(names[check]))
            {
                continue;
            }

            const dictionary& dict2 = solverDict.subDict(names[check]);

            // check for identical content
            if (checkDictionaryContent(dict1, dict2))
            {
                names[orig] += "|" + names[check];
                names[check].clear();
                changed = true;
            }
        }
    }

    if (changed)
    {
        forAll(names, nameI)
        {
            if (names[nameI].empty())
            {
                solverDict.remove(oldNames[nameI]);
                Info<<"  #remove " << oldNames[nameI];
            }
            else
            {
                Info<< "  " << oldNames[nameI];

                if (names[nameI] != oldNames[nameI])
                {
                    // make "(abc|def)" pattern
                    keyType renamed( "(" + names[nameI] + ")", true);

                    solverDict.changeKeyword(oldNames[nameI], renamed);

                    Info<< " -> " << renamed;
                }
            }
            Info<< endl;
        }

        if (optRewrite)
        {
            mvBak(solutionDict.objectPath(), "orig");
            Info<< "Backup to .orig" << nl
                << "Writing " << solutionDict.objectPath() << nl << endl;

            solutionDict.regIOobject::write();
        }
        else if (optShow)
        {
            IOobject::writeDivider(Info);
            solutionDict.dictionary::write(Info, false);
        }
        else
        {
            Info<< "\nFile not rewritten" << endl;
        }
    }
    else
    {