function varargout = barStrength(varargin)
% BARSTRENGTH M-file for barStrength.fig
%      BARSTRENGTH - Calculates the strength of a bar.
% Note height is consistantly misspelled throughout this program.
%
%  Created by Dr. C. S. Tritt 
%  Last revised 2/2/07 (version 1.0)

% Copyright 2002-2003 The MathWorks, Inc.

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

% Last Modified by GUIDE v2.5 02-Feb-2007 09:59:12

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

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

% Update handles structure
guidata(hObject, handles);

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


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

curValue = str2double(get(hObject,'String'));
if ~(curValue > 0.0)
   curString = 'Error';
else
   curString = sprintf('%f', curValue);
end
set(hObject, 'String', curString);

% --- Executes during object creation, after setting all properties.
function heigthEdit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to heigthEdit (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 widthEdit_Callback(hObject, eventdata, handles)
% hObject    handle to widthEdit (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 widthEdit as text
%        str2double(get(hObject,'String')) returns contents of widthEdit as a double

curValue = str2double(get(hObject,'String'));
if ~(curValue >= 0.0)
   curString = 'Error';
else
   curString = sprintf('%f', curValue);
end
set(hObject, 'String', curString);


% --- Executes during object creation, after setting all properties.
function widthEdit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to widthEdit (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 depthEdit_Callback(hObject, eventdata, handles)
% hObject    handle to depthEdit (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 depthEdit as text
%        str2double(get(hObject,'String')) returns contents of depthEdit as a double

curValue = str2double(get(hObject,'String'));
if ~(curValue >= 0.0)
   curString = 'Error';
else
   curString = sprintf('%f', curValue);
end
set(hObject, 'String', curString);


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

% Set up error flag
error = false;

% Retreive and revalidate each input.
heigth = str2double(get(handles.heigthEdit,'String'));
if ~(heigth > 0.0)
   curString = 'Error';
   error = true;
else
   curString = sprintf('%f', heigth);
end
set(handles.heigthEdit, 'String', curString);

width = str2double(get(handles.widthEdit,'String'));
if ~(width >= 0.0)
   curString = 'Error';
   error = true;
else
   curString = sprintf('%f', width);
end
set(handles.widthEdit, 'String', curString);

depth = str2double(get(handles.depthEdit,'String'));
if ~(depth >= 0.0)
   curString = 'Error';
   error = true;
else
   curString = sprintf('%f', depth);
end
set(handles.depthEdit, 'String', curString);

if get(handles.brRadio, 'Value') == 1
   k = 5.;
elseif  get(handles.alRadio, 'Value') == 1
   k = 10.;
elseif  get(handles.ssRadio, 'Value') == 1
   k = 20.;
elseif  get(handles.ccRadio, 'Value') == 1
   k = 35.;
else
   k = 0.; % Should never happen.
end

if error
   set(handles.strengthText, 'String', 'Error');
else
   % Disable input controls only if  strength can be calculated
   set(handles.heigthEdit, 'Enable', 'off');
   set(handles.widthEdit, 'Enable', 'off');
   set(handles.depthEdit, 'Enable', 'off');
   
   strength = k*width*depth/heigth;
   curString = sprintf('%f', strength);
   set(handles.strengthText, 'String', curString);
end

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

% Clear output and re-enable inputs.

set(handles.strengthText, 'String', '');
set(handles.heigthEdit, 'Enable', 'on');
set(handles.widthEdit, 'Enable', 'on');
set(handles.depthEdit, 'Enable', 'on');


