#include <iostream.h>
#include <stdio.h>
#include <math.h>
#include <fstream.h>
#include <string.h>
#include "Complex.h"
#include "Random.h"
#include "flat_rayleigh.h"

main(int argc, char *argv[])
{
  const int blocklength = 4000;
  const int maxblocks = 100;
  const double fD = 0.01;

  char logfile[35];

  if (argc == 3)
    sprintf(logfile, argv[2]);
  else {
    sprintf(logfile, "logR%.3f.txt", fD);
  }
  
  // construct it
  long seed = -15;
  flat_rayleigh mychan(seed, fD);

  int i, blocknum;

  Complex inp[blocklength], outp[blocklength];  

  for (i=0; i<blocklength; i++)
	  inp[i] = Complex(1.0, 0.0);
  // If you want to run it on the background,
  // just comment out the following three lines.
  cout << "***********************************\n";
  cout << "************   BEGIN   ************\n";
  cout << "***********************************\n";
  for (blocknum = 1; blocknum<=maxblocks; blocknum++) {
	mychan.pass_through(blocklength, inp, outp);
    ofstream out(logfile, ios::app);
    if (!out)
		cout << "Sorry, I cannot write on the output file\n";
	else {
		for (i=0; i<blocklength; i++)
			out << i << "\t" << outp[i] << endl;
    }
	out.close();
  }
  return 0;
}

