#include "Mesh.h"
#include "MeshCCMIO.h"
#include "MeshNGEOM.h"
#include "PostCCMIO.h"
#include "PostNPOST.h"
#include "IOException.h"
#include <iostream>

using namespace std;

const char kDefaultState[] = "default";

Mesh* BuildMesh( const char* filename )
{
    if (strstr(filename, ".ngeom"))
	return(new MeshNGEOM(filename));
    else if (strstr(filename, ".sff"))
	return(new MeshCCMIO(filename));
    return(NULL);
}

int main( int argc, char *argv[] )
{
    if (argc < 3)
    {
	cout << "Usage:  " << argv[0] << " file1 file2 [file2.npost]" << endl;
	cout << "\tfilen may be either an CCMIO or NGEOM file" << endl;
	return(0);
    }
    
    bool result;
    Mesh *mesh1, *mesh2;

    mesh1 = BuildMesh(argv[1]);
    if (!mesh1)
    {
	cout << "'" << argv[1] << "' is not a readable file format." << endl;
	return(1);
    }
    cout << "Mesh " << argv[1] << ":" << endl;
    mesh1->PrintInfo();

    mesh2 = BuildMesh(argv[2]);
    if (!mesh2)
    {
	cout << "'" << argv[2] << "' is not a readable file format." << endl;
	return(1);
    }
    cout << "Mesh " << argv[2] << ":" << endl;
    mesh2->PrintInfo();
    cout << endl;

    result = ((*mesh1) == (*mesh2));
    if (result)
	cout << "The two meshes are equal." << endl;
    else
	cout << "The two meshes DIFFER." << endl;

    if (argc == 4)
	try
	{
	    PostCCMIO post1(argv[1], kDefaultState);
	    PostNPOST post2(argv[3]);

	    if (post1 == post2)
		cout << "The two solution data are equal." << endl;
	    else
		cout << "The two solution data DIFFER." << endl;
	}
	catch(IOException& e)
	{
	    cerr << e.what() << endl;
	}

    return(result);
}
