//**************************************************************************
//
//      CSE 585 Project #2
//      By Anirudh Modi (anirudh@bart.aero.psu.edu) on 4/10/2000-Mon
//       & Shin Chin (scc136@psu.edu)
//       & Ming Ni (ni@cse.psu.edu)
//
//**************************************************************************
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <stdlib.h>     // for atoi()
#include <string.h>
#include <math.h>
#include <time.h>
#include "utils.h"
#include "image.h"
#include "matrix.h"
#include "edgeflow.h"
#include "edgedetect.h"
//**************************************************************************
int main (int argc, char *argv[])
{
if (argc < 3)
        {
         cerr << "Syntax: " << argv[0] << " <real-matrix> <imag-matrix>" << endl;
         exit(-1);
        }
cout << endl << "Progam BEGINS." << endl;

time_t begin_time, end_time;
time(&begin_time);

Matrix Fr, Fi;

Fr.ReadFromFile(argv[1]);
Fi.ReadFromFile(argv[2]);

char *name = ExtractName(argv[1]);
name[strlen(name)-2]='\0';
char filename[50];

int height = Fr.nx;
int width = Fr.ny;

Matrix Edge(height, width);
DetectEdge(&Edge, &Fr, &Fi);

Edge.Threshold(1.0e-30);

sprintf(filename, "%s.edge", name);
Edge.WriteImage(filename);

time(&end_time);
cout << endl << "Progam ENDS." << endl;

cout << "Total time consumed = " << (double) (end_time - begin_time) 
        << " sec" << endl;
cout.flush();
}
//**************************************************************************