par = MiniLoop_parameters();

global u0
% **** System Inputs ****
z0 = 30; % NB! This is choke valve opening [0 100]
% System goes unstable at z= 0.265
QG_in = 4.5; %litr/min
QL_lin = 4; %litr/min
wG_in0 = par.Rog_n*QG_in/(60*1000); %kg/s
wL_in0 = par.rho_L*QL_lin/(60*1000); %kg/s
u0 = [z0;wG_in0;wL_in0];
[x0,y0,par] = MiniLoop_initialize(u0,par);
%%
p_r=timeseries( y0(1)+0.7*[0 0 -1 -1 -2 -2 -2.5 -2.5 -2.7 -2.7 -2.8 -2.8 -2 -1 -1 0 0 1 1 2 2 3 3],[0 70 70 150 150 200 200 300 300 350 350 400 400 450 450 500 500 550 550 600 600 650 650]);
simtime=400;
sim('simLinModelAdapt_1MEAS_NLSIM')
close all
figure(1)
subplot(211)
    Pbottom.Name='P';
plot(Pbottom)
hold on
plot(Pref+y0(1),'r')
subplot(212)
z_c.Name='z_c';
plot(z_c)

figure(2)
subplot(211)
Ku.Name='Ku';
plot(Ku)
subplot(212)
Kp.Name='Kp';
plot(Kp)
tilefigs