function guess=getGuess(model,x0,sol,starttime,horizon)
tic 

uopt=[sol.qhf(:) sol.qhr(:) sol.qair(:)];
xopt=[sol.Tf(:) sol.Tr(:) sol.mr(:) sol.co2];
% time=linspace(starttime,starttime+horizon,100);

time=linspace(starttime,sol.t_f,100);

%Extrapolate inputs
usim = interp1(sol.t(:),uopt,time,'nearest','extrap');

%Simulate system with extrapolated inputs to ge the states
U  = iddata([], usim , 'Ts', [],'SamplingInstants',time);


[Y,Yd,xfinal]=sim(model,U,x0);  

toc

guess.t=time';
guess.qhf=usim(:,1);
guess.qhr=usim(:,2);
guess.qair=usim(:,3);


guess.Tf=xfinal(:,1);
guess.Tr=xfinal(:,2);
guess.mr=xfinal(:,3);
guess.co2=xfinal(:,4);
guess.t_f=sol.t_f;

guess.To=Y.OutputData(:,6);
guess.price=Y.OutputData(:,7);
guess.J=Y.OutputData(:,5); 
% plot(sol.t,sol.co2,guess.t,guess.co2,'r')
% pause