function varargout = TNFalpha(varargin)
% TNFALPHA M-file for TNFalpha.fig
%      TNFALPHA, by itself, creates a new TNFALPHA or raises the existing
%      singleton*.
%
%      H = TNFALPHA returns the handle to a new TNFALPHA or the handle to
%      the existing singleton*.
%
%      TNFALPHA('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in TNFALPHA.M with the given input arguments.
%
%      TNFALPHA('Property','Value',...) creates a new TNFALPHA or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before TNFalpha_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to TNFalpha_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 TNFalpha

% Last Modified by GUIDE v2.5 17-Dec-2007 14:17:41

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @TNFalpha_OpeningFcn, ...
                   'gui_OutputFcn',  @TNFalpha_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

global ODEFILE
global PARAMETERFILE
global INITVALUEFILE
global TSPAN
global TSPANVAR
global TRANGE
global T
global Y
global U
global DYDP
global SENSCHOICE
global DIMCHOICE
global PARAMCHOICE
global PLOTANALYSIS
global PLOTPARVARIATION


% --- Executes just before TNFalpha is made visible.
function TNFalpha_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 TNFalpha (see VARARGIN)

% Choose default command line output for TNFalpha
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = TNFalpha_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;


% --- Executes on button press in runParamVar.
function runParamVar_Callback(hObject, eventdata, handles)
% hObject    handle to runParamVar (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global TSPANVAR
global TRANGE
%global INITVALUEFILE
%global PARAMETERFILE

startVariation = str2num(get(handles.startTimeVarParam, 'String'));
stopVariation = str2num(get(handles.stopTimeVarParam, 'String'));
stepVariation = str2num(get(handles.stepsVarParam, 'String'));

TSPANVAR = linspace(startVariation,stopVariation,stepVariation);

startSpanVar = str2num(get(handles.startSpanVar, 'String'));
stopSpanVar = str2num(get(handles.stopSpanVar, 'String'));
stepSpanVar = str2num(get(handles.stepSpanVar, 'String'));

TRANGE = linspace(startSpanVar,stopSpanVar,stepSpanVar);

parvar('odefile',TSPANVAR,INITVALUEFILE,[],PARAMETERFILE);
 

% --- Executes on button press in cancelParamVar.
function cancelParamVar_Callback(hObject, eventdata, handles)
% hObject    handle to cancelParamVar (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

button = questdlg('Do you really want to exit?','Warning','Yes','No','Yes')
switch button
    case{'No'}
    case{'Yes'}  
        close TNFalpha
end


% --- Executes on button press in runAnalysis.
function runAnalysis_Callback(hObject, eventdata, handles)
% hObject    handle to runAnalysis (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%global INITVALUEFILE
%global PARAMETERFILE
global SENSCHOICE
global TSPAN

tstart = str2num(get(handles.editStartTimeAnalysis, 'String'));
tstop = str2num(get(handles.editStopTimeAnalysis, 'String'));
tstep = str2num(get(handles.editStepsAnalysis, 'String'));

TSPAN = linspace(tstart,tstop,tstep);

if(SENSCHOICE == 2)
    analysis_sys('odefile',TSPAN,INITVALUEFILE,[],PARAMETERFILE);
elseif (SENSCHOICE == 1)
    analysis_ind('odefile',TSPAN,INITVALUEFILE,[],PARAMETERFILE);
else
    msgBox('Please make a selection');
end


% --- Executes on button press in cancelAnalysis.
function cancelAnalysis_Callback(hObject, eventdata, handles)
% hObject    handle to cancelAnalysis (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

button = questdlg('Do you really want to exit?','Warning','Yes','No','Yes')
switch button
    case{'Yes'}  
        close TNFalpha
    case{'No'}
end


% --- Executes on selection change in dimChoiceAnalysis.
function dimChoiceAnalysis_Callback(hObject, eventdata, handles)
% hObject    handle to dimChoiceAnalysis (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns dimChoiceAnalysis contents as cell array
%        contents{get(hObject,'Value')} returns selected item from dimChoiceAnalysis

global DIMCHOICE

DIMCHOICE = get(hObject, 'Value')
string_list = get(hObject,'String');
selected_string = string_list{DIMCHOICE};
%axes(handles.plotAnalysis)
switch selected_string
    case{'Parameter'}
        paramPlot()
    case{'Component'}
        compPlot()
    case{'Time'}
        timePlot()
end


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

% Hint: popupmenu 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


function editStartTimeAnalysis_Callback(hObject, eventdata, handles)
% hObject    handle to editStartTimeAnalysis (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 editStartTimeAnalysis as text
%        str2double(get(hObject,'String')) returns contents of editStartTimeAnalysis as a double

startTimeAnalysis = str2double(get(handles.editStartTimeAnalysis, 'String'));
if isnan(startTimeAnalysis)
    errordlg('You must enter a numeric value','Bad Input','modal')
end


% --- Executes during object creation, after setting all properties.
function editStartTimeAnalysis_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editStartTimeAnalysis (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


function editStopTimeAnalysis_Callback(hObject, eventdata, handles)
% hObject    handle to editStopTimeAnalysis (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 editStopTimeAnalysis as text
%        str2double(get(hObject,'String')) returns contents of editStopTimeAnalysis as a double

stopTimeAnalysis = str2double(get(handles.editStopTimeAnalysis, 'String'));
if isnan(stopTimeAnalysis)
    errordlg('You must enter a numeric value','Bad Input','modal')
end


% --- Executes during object creation, after setting all properties.
function editStopTimeAnalysis_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editStopTimeAnalysis (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


function editStepsAnalysis_Callback(hObject, eventdata, handles)
% hObject    handle to editStepsAnalysis (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 editStepsAnalysis as text
%        str2double(get(hObject,'String')) returns contents of editStepsAnalysis as a double

stepsAnalysis = str2double(get(handles.editStepsAnalysis, 'String'));
if isnan(stepsAnalysis)
    errordlg('You must enter a numeric value','Bad Input','modal')
end


% --- Executes during object creation, after setting all properties.
function editStepsAnalysis_CreateFcn(hObject, eventdata, handles)
% hObject    handle to editStepsAnalysis (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 on selection change in sensChoice.
function sensChoice_Callback(hObject, eventdata, handles)
% hObject    handle to sensChoice (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns sensChoice contents as cell array
%        contents{get(hObject,'Value')} returns selected item from sensChoice

global SENSCHOICE

SENSCHOICE = get(hObject,'Value')
string_list = get(hObject,'String');
selected_string = string_list{SENSCHOICE};
switch selected_string
    case{'sens_ind'}
    case{'sens_sys'}
end


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

% Hint: popupmenu 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 on selection change in paramChoiceVar.
function paramChoiceVar_Callback(hObject, eventdata, handles)
% hObject    handle to paramChoiceVar (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns paramChoiceVar contents as cell array
%        contents{get(hObject,'Value')} returns selected item from paramChoiceVar

global PARAMCHOICE

PARAMCHOICE = get(hObject, 'Value')


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

% Hint: popupmenu 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


function startSpanVar_Callback(hObject, eventdata, handles)
% hObject    handle to startSpanVar (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 startSpanVar as text
%        str2double(get(hObject,'String')) returns contents of startSpanVar as a double

startSpanVar = str2double(get(handles.startSpanVar, 'String'))
if isnan(startSpanVar)
    errordlg('You must enter a numeric value','Bad Input','modal')
end


% --- Executes during object creation, after setting all properties.
function startSpanVar_CreateFcn(hObject, eventdata, handles)
% hObject    handle to startSpanVar (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


function stopSpanVar_Callback(hObject, eventdata, handles)
% hObject    handle to stopSpanVar (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 stopSpanVar as text
%        str2double(get(hObject,'String')) returns contents of stopSpanVar as a double

stopSpanVar = str2double(get(handles.stopSpanVar, 'String'))
if isnan(stopSpanVar)
    errordlg('You must enter a numeric value','Bad Input','modal')
end


% --- Executes during object creation, after setting all properties.
function stopSpanVar_CreateFcn(hObject, eventdata, handles)
% hObject    handle to stopSpanVar (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


function stepSpanVar_Callback(hObject, eventdata, handles)
% hObject    handle to stepSpanVar (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 stepSpanVar as text
%        str2double(get(hObject,'String')) returns contents of stepSpanVar as a double

stepSpanVar = str2double(get(handles.stepSpanVar, 'String'))
if isnan(stepSpanVar)
    errordlg('You must enter a numeric value','Bad Input','modal')
end


% --- Executes during object creation, after setting all properties.
function stepSpanVar_CreateFcn(hObject, eventdata, handles)
% hObject    handle to stepSpanVar (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


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


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


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


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


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

global ODEFILE

ODEFILE = uigetfile
set(hObject,'UserData',ODEFILE)

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

global PARAMETERFILE

PARAMETERFILE = load(uigetfile())
set(handles.paramChoiceVar,'String',PARAMETERFILE);


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

global INITVALUEFILE

INITVALUEFILE = uigetfile


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

doneAnalysis = uiimport(uigetfile)

% --------------------------------------------------------------------

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

global PLOTANALYSIS
%set(handles.plotAnalysis)


function startTimeVarParam_Callback(hObject, eventdata, handles)
% hObject    handle to startTimeVarParam (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 startTimeVarParam as text
%        str2double(get(hObject,'String')) returns contents of startTimeVarParam as a double

startVar = str2double(get(handles.startTimeVarParam, 'String'))
if isnan(startVar)
    errordlg('You must enter a numeric value','Bad Input','modal')
end

% --- Executes during object creation, after setting all properties.
function startTimeVarParam_CreateFcn(hObject, eventdata, handles)
% hObject    handle to startTimeVarParam (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


function stepsVarParam_Callback(hObject, eventdata, handles)
% hObject    handle to stepsVarParam (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 stepsVarParam as text
%        str2double(get(hObject,'String')) returns contents of stepsVarParam as a double

stepsVar = str2double(get(handles.stepsVarParam, 'String'))
if isnan(stepsVar)
    errordlg('You must enter a numeric value','Bad Input','modal')
end


% --- Executes during object creation, after setting all properties.
function stepsVarParam_CreateFcn(hObject, eventdata, handles)
% hObject    handle to stepsVarParam (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


function stopTimeVarParam_Callback(hObject, eventdata, handles)
% hObject    handle to stopTimeVarParam (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 stopTimeVarParam as text
%        str2double(get(hObject,'String')) returns contents of stopTimeVarParam as a double

stopVar = str2double(get(handles.stopTimeVarParam, 'String'))
if isnan(stopVar)
    errordlg('You must enter a numeric value','Bad Input','modal')
end


% --- Executes during object creation, after setting all properties.
function stopTimeVarParam_CreateFcn(hObject, eventdata, handles)
% hObject    handle to stopTimeVarParam (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


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


