/************************************************************************
HOSIM 3+ :	1) A 1D/2D/3D PROGRAM TO SIMULATE COMPLEX GEOLOGICAL PATTERNS
				    USING HIGH-ORDER SPATIAL CUMULANTS (SPLINES+LEGENDRE)
            2) FUTUR FEATURE: SIMULATION WITHOUT TRAINING IMAGES

AUTHOR	 :	DR. ILNUR MINNIAKHMETOV
			DR. HUSSEIN MUSTAPHA
            MODELING & SIMULATION : SOFTWARE ENGINEERING
            MODELISATION & SIMULATION : SOFTWARE ENGINEERING 
			      MONTREAL, CANADA

COPYRIGHT:	ILNUR MINNIAKHMETOV (DELNURO@GMAIL.COM)
			HUSSEIN MUSTAPHA (HUSSEIN_MUSTAPHA@HOTMAIL.COM)
			
DATE	 :	SEPTEMBER 30 2015
************************************************************************/
/* STANDARD LIBRARIES*/

#include "utilities_all_classes.hpp"
#include <iostream>
#include <math.h>
#include <time.h>
#include "stdio.h"
#if _DEBUG
//#include "vld.h"
#endif
using namespace std;


/* MAIN GLOBAL CLASSES */
/**/
Grid grid;
InfoIn infoin;
InfoExt infoext;
TrainingImage ti;
Samples sdata;
Tools tools;
Stats stats;
HosDataManager hosmanger;

/* MAIN FUNCTION OF THE PROGRAM */
/* WRITTEN BY: H. MUSTAPHA */

int main(int argc, char *argv[] )
{
#ifdef USE_MPI
cout<<"======================MPI_run============================"<<endl;
		 MPI_Init(&argc,&argv);
#else 
cout<<"======================NO MPI==========================="<<endl;
#endif
  /* TIMING VARIABLES*/
  time_t start_all,end_all;
  /* TOTAL CPU TIME */
	double dif;
  /* START THE TIMER*/
  time (&start_all);
  //ILNUR. Read parameter file name from arguments to have the ability of using scripts
  infoext=hosmanger.ReadArgs(argc,argv);
  
  /*INTRODUCION*/
  hosmanger.Intro();
  /*INITIALIZATION : READING INPUT & DATA STRUCTURE CREACTION */
  hosmanger.ReadAll(infoin,infoext);
  
  hosmanger.CreateAll(infoin,grid,ti,sdata,tools,stats);
  // RUN THE SIMULATOR TO GENERATE DIFFERENT REALIZATIONS
  hosmanger.SimulateAll(infoin, grid, ti, sdata, tools,stats);
  /* STOP THE TIMER */
  time (&end_all);
  /* THE TOTAL RUN TIME */
  dif = difftime (end_all,start_all);	
  /* PRINT OUT THE TOTAL TIME */
  cout << "-----------------------------------------------"<<endl;
  cout << "ALL REALIZATIONS ARE SUCCESSFULLY GENERATED    "<<endl;
  cout << "TOTAL CPU TIME (SECONDS) IS:                   "<<" "<<dif<<endl;
  hosmanger.WriteTiming(infoin,tools,dif);
  
  #ifdef USE_MPI 
     MPI_Finalize();
#endif
 // system("pause");  
  return 0;
}

