// ========================================================================== //
// Local libraries
#include "Options/options.hpp"
#include "StreamSurfaces/StreamSurfaces.hpp"
#include "Timer/Timer.hpp"

// Standard libraries
#include <string>

// Parallelisation
#if USE_MPI == 1
    #include <mpi.h>
#endif

// Macros
#ifndef MPI_VERSION
    #define MPI_VERSION 0
#endif

// ========================================================================== //
// Main driver

int main(int argc, char **argv) {
    // This function will run a test with variables specified through the first
    // input. This input should be the name of an Options file.

#if MPI_VERSION > 0
    // Startup the mpi instancing
    MPI_Init(&argc, &argv);
#endif

    // Setup variables and inputs
    Options opt = argc > 1 ? Options(argv[1]) : Options();

    // Initialise timing
    Timer times;

    // Initialise the object reading the input files
    StreamSurfaces streamsurf(opt);
    times.add("init");

    streamsurf.prepare_fixed();
    times.add("iso_contouring");

    // Create the surfaces
    streamsurf.create_surfaces();
    times.add("surface");

    // Adjacency extraction
    streamsurf.compute_indicator();
    times.add("extract");

    // Complete the exports
    streamsurf.save();
    times.add("export");

    //  Report the results and time spent
    streamsurf.print_surfaces();
    times.print();

#if MPI_VERSION > 0
    // Conclude MPI execution
    MPI_Barrier(MPI_COMM_WORLD);
    MPI_Finalize();
#endif

    return EXIT_SUCCESS;
}

// End of File
// ========================================================================== //