#include <stdio.h>
#include <math.h>
#include "nrutil.h"
#include "nr.h"
#include <stdlib.h>
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include <malloc.h>
#define NPT 5000

void fit(float x[], float y[], int ndata, float sig[], int mwt, float *a,
	float *b, float *siga, float *sigb, float *chi2, float *q);
void usage();
void usage() {
	cout<<"useFit inputfile"<<endl;
	exit(1);
}

int main(int argc, char **argv)
{
	int i,mwt,dim=0;
	ifstream input;
	if(argc<2) usage();
	input.open(argv[1],ios::in);
	float a,b,chi2,q,siga,sigb,*sig,*x,*y;
//	x=vector(1,NPT);
//	y=vector(1,NPT);
//	sig=vector(1,NPT);
	x=new float [NPT];
	y=new float [NPT];
	sig=new float [NPT];
	input>>dim;
//	cout<<"dim:"<<dim<<endl;
	for(i=1;i<=dim;i++){
		input>>x[i]>>y[i];
//		cout<<x[i]<<"\t"<<y[i]<<endl;
	}
	input.close();
	for(mwt=0;mwt<=1;mwt++){
		fit(x,y,dim,sig,mwt,&a,&b,&siga,&sigb,&chi2,&q);
		printf("a= %10.5f   b= %10.5f\n",a,b);
	}
}
