(* ::Package:: *)

(*This file is used to fit the scale factor and its first and second derivative. The fitting function will be imported and used for next iteration*)
t0=-4;
Nstep=60000;
tstep=Table[t0+(i-1)*0.0001,{i,Nstep+1}];
myPath="/deac/phy/andersonGrp/gaol18";
file = ToFileName[myPath,"scalefresult0m2i0t4.dat"];
atot = Import[file,{"Data"}];
adata=Transpose[atot];
a1=Transpose[{tstep,adata[[1,1;;Nstep+1]]}];
a2=Transpose[{tstep,adata[[2,1;;Nstep+1]]}];
a3=Transpose[{tstep,adata[[3,1;;Nstep+1]]}];
af1=FindFit[a1,e+b*t+c*t^2+d*t^3+g*t^4+l*t^5+p*t^6+i*t^7+o*t^8+m*t^9+k*t^10+q*t^11+v*t^12+j*t^13+h*t^14,{e,b,c,d,g,l,p,i,o,m,k,q,v,j,h},t];
afit1 = {e,b,c,d,g,l,p,i,o,m,k,q,v,j,h}/.af1;
outputpath="/deac/phy/andersonGrp/gaol18/";
Export[outputpath<>"afit0m2i1t4.dat",afit1,"Table"];
ap1f1=FindFit[a2,e+b*t+c*t^2+d*t^3+g*t^4+l*t^5+p*t^6+i*t^7+o*t^8+m*t^9+k*t^10+q*t^11+v*t^12+j*t^13+h*t^14,{e,b,c,d,g,l,p,i,o,m,k,q,v,j,h},t];
ap1fit1 = {e,b,c,d,g,l,p,i,o,m,k,q,v,j,h}/.ap1f1;
Export[outputpath<>"ap1fit0m2i1t4.dat",ap1fit1,"Table"];
ap2f1=FindFit[a3,e+b*t+c*t^2+d*t^3+g*t^4+l*t^5+p*t^6+i*t^7+o*t^8+m*t^9+k*t^10+q*t^11+v*t^12+j*t^13+h*t^14,{e,b,c,d,g,l,p,i,o,m,k,q,v,j,h},t];
ap2fit1 = {e,b,c,d,g,l,p,i,o,m,k,q,v,j,h}/.ap2f1;
Export[outputpath<>"ap2fit0m2i1t4.dat",ap2fit1,"Table"];
