/* This is curvefit.h
used to fit data (input from cin so far) to a curve, either
a straight line, an exponential function or a power of cosine */

#include<iostream.h>


class Fit; // Classes will be defined later	
class StraightLineFit;

/* 'class Data' is a base class used to store, manipulate (in a way so 
that the data can be used as an input for a fit function), and save 
different types of data input. */

class Data {
	
public:
	
	virtual ~Data() { };  	// destructor
	
	void ReadData(istream& in);  // read in data
	virtual void Linearize( float* &newX, float* &newY, 
				unsigned int& newSize) = 0; // "manipulation so I 
							// can use LS fit
	virtual void Formula(Fit& fit, char s[] ) = 0;
	void SaveData( Fit& fit); // Save data in a file
				// with the fitted formula
	void SetZero(float* &ptr);						
	unsigned int Size(); 	// get of arrays
	float* X(); 		// get x- and y-coordinates
	float* Y();
	
protected:
	unsigned int size;	// no of data sets
	float* ptr_x, *ptr_y;	// x- and y-data
};				



/* The following 3 classes are derived from Data. They will handle the
special functions neccessary for these 3 types of data input */

class LinearData : public Data
	{
public: 
	LinearData() ;
	LinearData( unsigned int n);
	~LinearData() ;
	void Linearize( float* &newX, float* &newY, 
				unsigned int& newSize);
	void Formula( Fit &fit, char s[]);
	};
	
	
class ExponentialData : public Data
	{
public:
	ExponentialData();
	ExponentialData( unsigned int n );
	~ExponentialData(); // destructor
	void Linearize( float* &newX, float* &newY, 
				unsigned int& newSize); // "takes ln"
	void Formula( Fit &fit, char s[]);
	
};


class CosineData : public Data
	{
public: 
	CosineData(); // constructor
	CosineData( unsigned int n );
	~CosineData();  // destructor
	void Linearize( float* &newX, float* &newY, 
				unsigned int& newSize); // "takes ln"
	void Formula( Fit &fit, char s[]);
	
};


	
	
/* 'Fit' is meant to be the base class for various ( one ) methods of 
fitting curves. */

class Fit
	{
public:
	
	virtual ~Fit(); 
	virtual int KindOfFit();	// To distiguish between fits
	virtual float Slope() = 0;		
	virtual float Intersect() = 0;
	
protected:
	float* convertedX, *convertedY;	// new data if conversion has taken
					// place; otherwise this is just 
					// the original data
	unsigned int convertedSize;	// in case the data contains values
				// that get the fit funtion in trouble.
	
};
	

/* StraightLineFit uses the method of least squares to find the best fit */

class StraightLineFit : public Fit
	{
public:
	StraightLineFit();  // Constructor
	StraightLineFit( Data &fitInput ); // this is the actual fitting
	~StraightLineFit() { };  // Destructor
	int KindOfFit();	// For when I get more than one!
	float Slope();		// Get slope
	float Intersect();	// Get y_intersection
	float DeltaSlope();	// Uncertainty in slope
	float DeltaIntc();	// Uncertainty in intersection
private:
	float slope, intersect, deltaSlope, deltaIntc;
	
};


float abs(float argument);	// absolute value of a float argument



