function varargout = Tune3DPipe(varargin)
% Tune3DPipe M-file for Tune3DPipe.fig
%      TEXT99, by itself, creates a new TEXT99 or raises the existing
%      singleton*.
%
%      H = Tune3DPipe returns the handle to a new Tune3DPipe or the handle to
%      the existing singleton*.
%
%      Tune3DPipe('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in Tune3DPipe.M with the given input arguments.
%
%      Tune3DPipe('Property','Value',...) creates a new Tune3DPipe or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Tune3DPipe_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Tune3DPipe_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Tune3DPipe

% Last Modified by GUIDE v2.5 02-Jan-2007 14:28:21

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @Tune3DPipe_OpeningFcn, ...
    'gui_OutputFcn',  @Tune3DPipe_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Tune3DPipe is made visible.
function Tune3DPipe_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Tune3DPipe (see VARARGIN)

% Choose default command line output for Tune3DPipe
handles.output = hObject;
handles.Callingfunction=varargin{2};
%eval([varargin{1} '=' char(varargin{2}) ';']);
for i=2:(nargin-3)/2;
    try
        set(eval(varargin{2*i-1}),'string',eval(varargin{2*i}));
        if i<=10
            eval([varargin{2*i-1}(findstr(varargin{2*i-1},'.')+6:end) '=' varargin{2*i} ';']);
        else
            eval([varargin{2*i-1}(findstr(varargin{2*i-1},'.')+6:end) '=' varargin{2*i} ';']);
        end
    catch
        if isequal(varargin{2*i},'off')
            eval([varargin{2*i-1}(findstr(varargin{2*i-1},'.')+10:end) '=0;']);
            set(eval(varargin{2*i-1}),'Value',0);
        else
            eval([varargin{2*i-1}(findstr(varargin{2*i-1},'.')+10:end) '=1;']);
            set(eval(varargin{2*i-1}),'Value',1);
        end
    end

end
PipelineData.r=D/2;
PipelineData.theta=theta/360*2*pi;
PipelineData.L1=L1;
PipelineData.V_G1=pi*PipelineData.r^2*(L1-H2-L3)*(1-FG);
PipelineData.FG=FG;
PipelineData.A2=PipelineData.r^2*pi;
PipelineData.H1=2*PipelineData.r/cos(PipelineData.theta);
PipelineData.H2=H2;
PipelineData.H3=2*PipelineData.r;
PipelineData.L3=L3;
PipelineData.A1=PipelineData.A2/sin(PipelineData.theta);
PipelineData.A3=PipelineData.H3*PipelineData.L3;
PipelineData.rho_L=rho_L;
PipelineData.R=8314;
PipelineData.T=T;
PipelineData.M_G=M_G;
PipelineData.g=9.81;
PipelineData.V_T=PipelineData.A2*PipelineData.H2+PipelineData.A3*PipelineData.H3;
InitCond.mG_in=mG_in;
InitCond.mL_in=mL_in;
InitCond.z=z;
InitCond.P1=P1+1.013;
InitCond.P2=P2+1.013;
InitCond.P3=P3+1.013;
InitCond.h1=PipelineData.H1*0.9;
PipelineData.n=n;
PipelineData.PdepFeed=PdepFeed;
if PdepFeed
    set(handles.edit_P_f,'Enable','on')
    InitCond.P_f=P_f+1.013;
    PipelineData.alpha_L_in=mL_in/(mL_in+mG_in);
else
    set(handles.edit_P_f,'Enable','off')
end
handles.PipelineData=PipelineData;
handles.InitCond=InitCond;
handles.TuningData.Zvec=str2num(get(handles.edit_Zvec,'String'));
handles=AnalyzeCase(handles);
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Tune3DPipe wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Tune3DPipe_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

function edit_rho_L_Callback(hObject, eventdata, handles)
handles.PipelineData.rho_L=str2num(get(hObject,'String'));
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_rho_L_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_D_Callback(hObject, eventdata, handles)
handles.PipelineData.r=str2num(get(hObject,'String'))/2;
handles.PipelineData.V_G1=pi*handles.PipelineData.r^2*...
    (handles.PipelineData.L1-handles.PipelineData.H2-handles.PipelineData.L3)...
    *(1-handles.PipelineData.FG);
handles.PipelineData.A2=handles.PipelineData.r^2*pi;
handles.PipelineData.H1=2*handles.PipelineData.r/cos(handles.PipelineData.theta);
handles.PipelineData.H3=2*handles.PipelineData.r;
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_D_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_theta_Callback(hObject, eventdata, handles)
handles.PipelineData.theta=str2num(get(hObject,'String'))/360*2*pi;
handles.PipelineData.H1=2*handles.PipelineData.r/cos(handles.PipelineData.theta);
handles.PipelineData.A1=handles.PipelineData.A2/sin(handles.PipelineData.theta);
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_theta_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_L3_Callback(hObject, eventdata, handles)
handles.PipelineData.L3=str2num(get(hObject,'String'));
handles.PipelineData.V_G1=pi*handles.PipelineData.r^2*...
    (handles.PipelineData.L1-handles.PipelineData.H2-handles.PipelineData.L3)...
    *(1-handles.PipelineData.FG);
handles.PipelineData.A3=handles.PipelineData.H3*handles.PipelineData.L3;
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_L3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_T_Callback(hObject, eventdata, handles)
handles.PipelineData.T=str2num(get(hObject,'String'));
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_T_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_M_G_Callback(hObject, eventdata, handles)
handles.PipelineData.M_G=str2num(get(hObject,'String'));
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_M_G_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_L1_Callback(hObject, eventdata, handles)
handles.PipelineData.L1=str2num(get(hObject,'String'));
handles.PipelineData.V_G1=pi*handles.PipelineData.r^2*...
    (handles.PipelineData.L1-handles.PipelineData.H2-handles.PipelineData.L3)...
    *(1-handles.PipelineData.FG);
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_L1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_H2_Callback(hObject, eventdata, handles)
handles.PipelineData.H2=str2num(get(hObject,'String'));
handles.PipelineData.V_G1=pi*handles.PipelineData.r^2*...
    (handles.PipelineData.L1-handles.PipelineData.H2-handles.PipelineData.L3)...
    *(1-handles.PipelineData.FG);
handles.PipelineData.V_T=handles.PipelineData.A2*handles.PipelineData.H2+...
    handles.PipelineData.A3*handles.PipelineData.H3;
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_H2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_FG_Callback(hObject, eventdata, handles)
handles.PipelineData.FG=str2num(get(hObject,'String'));
handles.PipelineData.V_G1=pi*handles.PipelineData.r^2*(handles.PipelineData.L1-handles.PipelineData.H2-handles.PipelineData.L3)*(1-handles.PipelineData.FG);
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_FG_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_n_Callback(hObject, eventdata, handles)
handles.PipelineData.n=str2num(get(hObject,'String'));
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_n_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_mG_in_Callback(hObject, eventdata, handles)
handles.InitCond.mG_in=str2num(get(hObject,'String'));
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_mG_in_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_mL_in_Callback(hObject, eventdata, handles)
handles.InitCond.mL_in=str2num(get(hObject,'String'));
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_mL_in_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_z_Callback(hObject, eventdata, handles)
handles.InitCond.z=str2num(get(hObject,'String'));
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_z_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_P1_Callback(hObject, eventdata, handles)
handles.InitCond.P1=str2num(get(hObject,'String'))+1.013;
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_P1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_P2_Callback(hObject, eventdata, handles)
handles.InitCond.P2=str2num(get(hObject,'String'))+1.013;
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_P2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_P3_Callback(hObject, eventdata, handles)
handles.InitCond.P3=str2num(get(hObject,'String'))+1.013;
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_P3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function LogBox_Callback(hObject, eventdata, handles)

function LogBox_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_K1_Callback(hObject, eventdata, handles)

function edit_K1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_K2_Callback(hObject, eventdata, handles)

function edit_K2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_K3_Callback(hObject, eventdata, handles)

function edit_K3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_p1_Callback(hObject, eventdata, handles)

function edit_p1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_p2_Callback(hObject, eventdata, handles)

function edit_p2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_p3_Callback(hObject, eventdata, handles)

function edit_p3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_Zvec_Callback(hObject, eventdata, handles)
handles.TuningData.Zvec=str2num(get(hObject,'String'));
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_Zvec_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function pb_CompBif_Callback(hObject, eventdata, handles)
z_vec=handles.TuningData.Zvec;
T_sim=3*3600;
[x0,y_stasj]=initialize_3Dpipe(handles.InitCond,handles.PipelineData);
options=odeset('AbsTol',1e-8,'RelTol',1e-8,'MaxStep',60);
updatelog(handles.LogBox,'Starting simulation')
for i=1:length(z_vec)
    if handles.PipelineData.PdepFeed
        u=[z_vec(i);0;0;handles.InitCond.P3;handles.InitCond.P_f];
    else
        u=[z_vec(i);handles.InitCond.mG_in;handles.InitCond.mL_in;handles.InitCond.P3];
    end
    y=[];
    [t,x]=ode23t(@slug_3D_sim,[0;T_sim],x0*1.001,options,u,'derivatives',handles.PipelineData);
    I=[1:10:10*((rem(length(t),10)~=0)*(floor(length(t)/10)+1)+(rem(length(t),10)==0)*(floor(length(t)/10))),length(t)];
    for j=1:length(I)
        y(j,:)=slug_3D_sim(t(I(j)),x(I(j),:),u,'measurements',handles.PipelineData);
    end
    axes(handles.axes_simCurrent)
    plot(t(I)/60,y(:,1:2));legend('P1','DP');
    xlabel('time [min]');ylabel('Pressure [bara]')
    drawnow;
    J=find(abs(t(I)-T_sim*3/4)==min(abs((t(I)-T_sim*3/4))));
    maxP1m(i)=max(y(J:length(t(I)),1));
    minP1m(i)=min(y(J:length(t(I)),1));
    maxP2m(i)=max(y(J:length(t(I)),2));
    minP2m(i)=min(y(J:length(t(I)),2));
    axes(handles.axes_bifP1)
    plot(z_vec(1:i),maxP1m(1:i),'b',z_vec(1:i),minP1m(1:i),'b');
    title('P1 vs Valve opening');
    axes(handles.axes_bifDP)
    plot(z_vec(1:i),maxP2m(1:i),'b',z_vec(1:i),minP2m(1:i),'b');
    title('DP vs Valve opening');
    updatelog(handles.LogBox,['Finished simulation with valve opening ' num2str(z_vec(i))]);
    x0=x(end,:);
    drawnow;
end
function PB_close_Callback(hObject, eventdata, handles)
set_param(handles.Callingfunction,'rho_L',num2str(handles.PipelineData.rho_L));
set_param(handles.Callingfunction,'D',num2str(handles.PipelineData.r*2));
set_param(handles.Callingfunction,'L1',num2str(handles.PipelineData.L1));
set_param(handles.Callingfunction,'H2',num2str(handles.PipelineData.H2));
set_param(handles.Callingfunction,'theta',num2str(handles.PipelineData.theta*360/2/pi));
set_param(handles.Callingfunction,'L3',num2str(handles.PipelineData.L3));
set_param(handles.Callingfunction,'T',num2str(handles.PipelineData.T));
set_param(handles.Callingfunction,'M_G',num2str(handles.PipelineData.M_G));
set_param(handles.Callingfunction,'n',num2str(handles.PipelineData.n));
set_param(handles.Callingfunction,'FG',num2str(handles.PipelineData.FG));
set_param(handles.Callingfunction,'mG_in',num2str(handles.InitCond.mG_in));
set_param(handles.Callingfunction,'mL_in',num2str(handles.InitCond.mL_in));
set_param(handles.Callingfunction,'z',num2str(handles.InitCond.z));
set_param(handles.Callingfunction,'P1',num2str(handles.InitCond.P1-1.013));
set_param(handles.Callingfunction,'P2',num2str(handles.InitCond.P2-1.013));
set_param(handles.Callingfunction,'P3',num2str(handles.InitCond.P3-1.013));
if handles.PipelineData.PdepFeed
set_param(handles.Callingfunction,'P_f',num2str(handles.InitCond.P_f-1.013));
end
if handles.PipelineData.PdepFeed==1
    set_param(handles.Callingfunction,'PdepFeed','on');
else
    set_param(handles.Callingfunction,'PdepFeed','off');
end
h=get(0,'CurrentFigure');
close(h);

function handles=AnalyzeCase(handles)
handles.PipelineData=ComputeConstants(handles.InitCond,handles.PipelineData);
set(handles.edit_K1,'string', num2str(handles.PipelineData.K1));
set(handles.edit_K2,'string', num2str(handles.PipelineData.K2));
set(handles.edit_K3,'string', num2str(handles.PipelineData.K3));
if handles.PipelineData.PdepFeed
    set(handles.edit_K4,'string', num2str(handles.PipelineData.K4));
else
    set(handles.edit_K4,'string', 'Not used');
end
if isreal(handles.PipelineData.K1)&&isreal(handles.PipelineData.K2)&&isreal(handles.PipelineData.K3)
    updatelog(handles.LogBox,'Data OK')
    handles.TuningData.Status.RealConstants=1;
else
    updatelog(handles.LogBox,'Case is not feasible, change pipeline or initial data')
    handles.TuningData.Status.RealConstants=0;
    set(handles.edit_p1,'string', 'N/A');
    set(handles.edit_p2,'string', 'N/A');
    set(handles.edit_p3,'string', 'N/A');
end
if handles.TuningData.Status.RealConstants
    [x0,y_stasj]=initialize_3Dpipe(handles.InitCond,handles.PipelineData);
    if ~isreal(y_stasj);
        updatelog(handles.LogBox,'Model initialization failed')
        handles.TuningData.Status.ModelInitialized=0;
    else
        handles.TuningData.Status.ModelInitialized=1;
    end
else
    handles.TuningData.Status.ModelInitialized=1;
end
if handles.TuningData.Status.ModelInitialized&&handles.TuningData.Status.RealConstants
    if handles.PipelineData.PdepFeed
        d=[0;0;handles.InitCond.P3;handles.InitCond.P_f];
    else
        d=[handles.InitCond.mG_in;handles.InitCond.mL_in;handles.InitCond.P3];
    end
    [A,B,C,D,E,F,ys,status]=Linearize(@slug_3D_sim,[],x0(1:3),handles.InitCond.z,...
        d,'linearize',handles.PipelineData);
    handles.TuningData.Status.Linearized=status.status;
    if status.status
        handles.TuningData.Poles=eig(A);
        set(handles.edit_p1,'string', num2str(handles.TuningData.Poles(1)));
        set(handles.edit_p2,'string', num2str(handles.TuningData.Poles(2)));
        set(handles.edit_p3,'string', num2str(handles.TuningData.Poles(3)));
        updatelog(handles.LogBox,'Poles calculated')
    else
        updatelog(handles.LogBox,status.errormsg)
        set(handles.edit_p1,'string', 'N/A');
        set(handles.edit_p2,'string', 'N/A');
        set(handles.edit_p3,'string', 'N/A');
    end
end
if handles.TuningData.Status.ModelInitialized&&handles.TuningData.Status.RealConstants&&...
        handles.TuningData.Status.Linearized
    options=odeset('AbsTol',1e-8,'RelTol',1e-8,'MaxStep',60);
    updatelog(handles.LogBox,'Simulating, please wait...')
    if handles.PipelineData.PdepFeed
        u=[handles.InitCond.z;0;0;handles.InitCond.P3;handles.InitCond.P_f];
    else
        u=[handles.InitCond.z;handles.InitCond.mG_in;handles.InitCond.mL_in;handles.InitCond.P3];
    end
    [t,x]=ode23t(@slug_3D_sim,[0;3600],x0*1.001,options,u,'derivatives',handles.PipelineData);
    I=[1:10:10*((rem(length(t),10)~=0)*(floor(length(t)/10)+1)+(rem(length(t),10)==0)*(floor(length(t)/10))),length(t)];
    for i=1:length(I)
        y(i,:)=slug_3D_sim(t(I(i)),x(I(i),:),u,'measurements',handles.PipelineData);
    end
    axes(handles.axes_simCurrent)
    plot(t(I)/60,y(:,1:2));legend('P1','DP');
    xlabel('time [min]');ylabel('Pressure [bara]')
    updatelog(handles.LogBox,'Simulation finished')
end

function updatelog(handle,newline)
CurrentText=get(handle,'String');
NewText=strvcat(CurrentText,newline);
set(handle,'String',NewText);
set(handle,'listboxTop',max(size(CurrentText,1)-5,1));
drawnow;



function edit26_Callback(hObject, eventdata, handles)
% hObject    handle to edit26 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit26 as text
%        str2double(get(hObject,'String')) returns contents of edit26 as a double


% --- Executes during object creation, after setting all properties.
function edit26_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit26 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function edit_P_f_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function edit_P_f_Callback(hObject, eventdata, handles)
handles.InitCond.P_f=str2num(get(hObject,'String'))+1.013;
handles=AnalyzeCase(handles);guidata(hObject, handles);


% --- Executes on button press in checkbox_PdepFeed.
function checkbox_PdepFeed_Callback(hObject, eventdata, handles)
handles.PipelineData.PdepFeed=get(hObject,'Value');
if handles.PipelineData.PdepFeed
    set(handles.edit_P_f,'Enable','on')
    handles.PipelineData.alpha_L_in=handles.InitCond.mL_in/(handles.InitCond.mL_in+handles.InitCond.mG_in);
else
    set(handles.edit_P_f,'Enable','off')
end
handles=AnalyzeCase(handles);guidata(hObject, handles);

function edit_K4_Callback(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function edit_K4_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


