#ifdef STATISTICS

/*
 * $Id$
 *
 * [ Description ]
 * 
 */

#include "Behavioural/include/Statistics.h"
#include <time.h>
#include <sstream>
#include <fstream>
using namespace std;

namespace morpheo              {
namespace behavioural          {

#undef  FUNCTION
#define FUNCTION "Statistics::generate_file"
  void Statistics::generate_file(string stat)
  {
    log_printf(FUNC,Behavioural,FUNCTION,"Begin");

    ostringstream filename;
    filename << _name << ".stat";

    cout << "Generate file \""<< filename.str() << "\"" << endl;

    ofstream file;
    file.open(filename.str().c_str(),ios::out | ios::trunc);

    time_t current_time;
    time (&current_time);

    // print header
    file << "<!-- "                                                    << endl
	 << "\tfile        : " << filename.str()                       << endl
	 << "\tdate        : " << ctime (&current_time )
	 << "\tcomment     : it's a autogenerated file : don't modify" << endl
	 << "-->"                                                      << endl
	 <<                                                               endl;
	 
    file << stat;
    
    file.close();

    log_printf(FUNC,Behavioural,FUNCTION,"End");
  }

#undef  FUNCTION
#define FUNCTION "Statistics::generate_file"
  void Statistics::generate_file(void)
  {
    log_printf(FUNC,Behavioural,FUNCTION,"Begin");

    generate_file(print(0));

    log_printf(FUNC,Behavioural,FUNCTION,"End");
  };

}; // end namespace behavioural          
}; // end namespace morpheo              

#endif
