function varargout = mapCalc(varargin)
% MAPCALC M-file for mapCalc.fig
%      
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Copyright 2002-2003 The MathWorks, Inc.

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

% Last Modified by GUIDE v2.5 16-Jan-2007 14:32:03

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @mapCalc_OpeningFcn, ...
                   'gui_OutputFcn',  @mapCalc_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 mapCalc is made visible.
function mapCalc_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 mapCalc (see VARARGIN)

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

% Added Code: set up appdata storage of systolic and diastolic pressures.

handles.Psys = 0.0; % Systolic pressure in mm Hg.
handles.Pdia = 0.0; % Diastolic pressure in mm Hg.
handles.Pmap = 0.0; % MAP in mm Hg, may be used later. 

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = mapCalc_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 sysEdit_Callback(hObject, eventdata, handles)
% hObject    handle to sysEdit (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 sysEdit as text
%        str2double(get(hObject,'String')) returns contents of sysEdit as a double

% Get entered text and convert to double.
handles.Psys = str2double(get(hObject,'String'));

% Create formated echo string.
sysStr = sprintf('%g', handles.Psys);

% Echo the formated input.
set(hObject, 'String', sysStr);

% Update guidata with new handles structure.
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function sysEdit_CreateFcn(hObject, eventdata, handles);
% hObject    handle to sysEdit (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


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

% Get entered text and convert to double.
handles.Pdia = str2double(get(hObject,'String'));

% Create formated echo string.
diaStr = sprintf('%g', handles.Pdia);

% Echo the formated input.
set(hObject, 'String', diaStr);

% Update central handles structure.
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function diaEdit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to diaEdit (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


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

% Disable input.
set(handles.sysEdit, 'Enable', 'off');
set(handles.diaEdit, 'Enable', 'off');

% Calculate and save map.
handles.Pmap = 0.333*handles.Psys + 0.667*handles.Pdia;

% Create formated ouptput string.
mapStr = sprintf('%.0f', handles.Pmap);

% Display the formated input.
set(handles.mapText, 'String', mapStr);

% Update central handles structure.
guidata(hObject, handles);


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

% Clear output
set(handles.mapText, 'String', '');

% Reenable inputs.
set(handles.sysEdit, 'Enable', 'on');
set(handles.diaEdit, 'Enable', 'on');