%Track_stationary.m
clear all
global data IX IU IFIXU uorg
load data
IX=1:3;
IU=4:7;
IFIXU=2:4;
mG_in=6.1717e-5*1.5;
mL_in=0.0455;
P0=1.013;
P_feed=0.31e5+1.013e5;
z=0.10;
load xinit010
u=[z;mG_in;P_feed;P0];
z1=[x0(1:3)';u];
load xinit011
z=0.11
u=[z;mG_in;P_feed;P0];
uorg=u;
z2=[x0(1:3)';u];
[out,uu,step1,tt]=secant_cont_circle('slug_wrapper',z2,z1,0.001);
disp('Computing measurements')
xs=out(:,IX)';us=out(:,IU)';
for i=1:length(out)
    y(i,:)=slug_3D_sim(0,xs(:,i),us(:,i),'measurements',data);
end
load slugdata2
load eksperimentelle_data
%return
y(:,1)=y(:,1)-1.013; %gjor om til barg
maxP1=maxP1m-1.013;
minP1=minP1m-1.013;
maxP2=maxP2m-1.013;
minP2=minP2m-1.013;
us=us*100;
z_vec=z_vecm*100;
figure(1)
subplot(2,1,1)
plot(us(1,:),y(:,1),'r--',z_vec,maxP1,'r-',z_vec,minP1,'r-');
hold on
plot(Z,P1_max,'b:',Z,P1_min,'b:')
ylabel('P_1 [barg]')
axis([0 100 0 0.25])
hold off
subplot(2,1,2)
plot(us(1,:),y(:,2),'r--',z_vec,maxP2,'r-',z_vec,minP2,'r-')
hold on
plot(Z,P2_max,'b:',Z,P2_min,'b:')
ylabel('P_2 [barg]')
hold off
xlabel('Ventilåpning %')
axis([0 100 0 0.2])

%pause
g=gcf;
set(g,'PaperUnits','centimeters','PaperType','A4')
opts = struct('FontMode','fixed','FontSize',9,'Width',10,'Color','rgb');
exportfig(g,'simulering_trykk_mot_ventil2.eps',opts)
% previewfig(g,opts)


% P1=y(:,1);
% P2=y(:,2);
% z=us(1,:);
% %h1=xs(4,:);
% save Stationary P1 z xs
% % plot(us(1,:),y(:,3))
% % P1=y(:,3);
% % z=us(1,:);
% % rho_mix=xs(4,:);rho_T=xs(5,:);
% % save Stationary4 P1 z rho_mix rho_T xs
% T=find(abs(us(1,:)-0.08)==min(abs(us(1,:)-0.08)))
% P1(T)-3.25e5