//
//	Copyright 1997
//	Eric McRae	eric@elmi.com
//	Electro-Logic Machines, Inc.
//	Port Townsend, WA
//
//
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

// You may have to adjust the following for your machine/compiler
// Just make sure that the size of the variable matches the number of bits
// in the type.
typedef unsigned char u8;
typedef unsigned long u32;


// statics

// function declarations

// Functions, methods, etc.


int
main( int argc, char **argv )
{
    ifstream infile;
    float energyF = 0.0F;
    int itemCountN;

    switch( argc )
    {	
    case 2:
	infile.open( *(argv+1) );
	break;

    default:
	cerr << "Usage: " << *argv << " infile" << endl;
	return( -2 );
    }

    if( ! infile.good() )	// see if we could open the input file
    {
	cerr << *argv << ": can't open input file: " << *(argv+1) << endl;
	return( -3 );
    }

    // Now read the input file and create an array of pointers to
    // each of the Items.

				    // set stdout stream format too
    cout.setf(ios::fixed,ios::floatfield);	// fixed point
    cout.setf(ios::right,ios::adjustfield);	// right justified

    float x1, x2, y1, y2;

    infile >> x1 >> y1;		// read two floats

    for(itemCountN = 1; 1; itemCountN++ )
    {
	float dxF, dyF;

	infile >> x2 >> y2;		// read two floats
	if( infile.eof() )		// If that read hit EOF
	    break;			// bail out of loop

	dxF = fabs( x2 - x1 );
	dyF = fabs( y2 - y1 );
	energyF += sqrt( (dxF * dxF) + (dyF * dyF) );
	x1 = x2;
	y1 = y2;
    }
    cout << "List Energy: " << energyF << endl;

    return(0);
}

