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

% Last Modified by GUIDE v2.5 21-Oct-2005 12:04:14

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

handles.force = varargin{1};
if ~isfield(handles.force,'r')
    
    % if the field r isn't defined, assume the input is just a list of rz's
    % and remake the force structure....
    temp = handles.force;
    handles.force = [];
    handles.force.r = temp;
end;
if isfield(handles.force,'tension')
    handles.tension     = handles.force.tension;
else
    handles.tension = 0;
end;
if isfield(handles.force,'pressure')
    handles.pressure    = handles.force.pressure;
else
    handles.pressure = 0;
end;
if isfield(handles.force,'spont')
    handles.spont       = handles.force.spont;
else
    handles.spont = 0;
end;
if isfield(handles.force,'stepsize')
    handles.stepsize    = handles.force.stepsize;
else
    handles.stepsize    =  .1;
end;
if isfield(handles.force,'normal_sign')
    handles.normal_sign = handles.force.normal_sign;
else
    handles.normal_sign = 1;
end;

if isfield( handles.force,'zmin' );
    handles.zmin = handles.force.zmin;
    handles.zmax = handles.force.zmax;
else
    handles.zmax = max(handles.force.r(:,2));
    handles.zmin = min(handles.force.r(:,2));
end;

if isfield( handles.force,'ms' );
    handles.ms = handles.force.ms;
    handles.rm = handles.force.rm;
    handles.mflag = handles.force.mflag;
else
    handles.ms    = 0.1;
    handles.rm    = 0.4;
    handles.mflag = 0;    
end;

guidata(hObject, handles);


reinterp_data(hObject, eventdata, handles);
handles = guidata(hObject);

init_dialog(hObject, eventdata, handles, varargin);

% Choose default command line output for ForceDialog
% handles.output = 'Yes';

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

% Insert custom Title and Text if specified by the user
% Hint: when choosing keywords, be sure they are not easily confused 
% with existing figure properties.  See the output of set(figure) for
% a list of figure properties.
% if(nargin > 3)
%     for index = 1:2:(nargin-3),
%         if nargin-3==index, break, end
%         switch lower(varargin{index})
%          case 'title'
%           set(hObject, 'Name', varargin{index+1});
%          case 'string'
%           set(handles.text1, 'String', varargin{index+1});
%         end
%     end
% end

% Determine the position of the dialog - centered on the callback figure
% if available, else, centered on the screen


% 
% FigPos=get(0,'DefaultFigurePosition');
% OldUnits = get(hObject, 'Units');
% set(hObject, 'Units', 'pixels');
% OldPos = get(hObject,'Position');
% FigWidth = OldPos(3);
% FigHeight = OldPos(4);
% if isempty(gcbf)
%     ScreenUnits=get(0,'Units');
%     set(0,'Units','pixels');
%     ScreenSize=get(0,'ScreenSize');
%     set(0,'Units',ScreenUnits);
% 
%     FigPos(1)=1/2*(ScreenSize(3)-FigWidth);
%     FigPos(2)=2/3*(ScreenSize(4)-FigHeight);
% else
%     GCBFOldUnits = get(gcbf,'Units');
%     set(gcbf,'Units','pixels');
%     GCBFPos = get(gcbf,'Position');
%     set(gcbf,'Units',GCBFOldUnits);
%     FigPos(1:2) = [(GCBFPos(1) + GCBFPos(3) / 2) - FigWidth / 2, ...
%                    (GCBFPos(2) + GCBFPos(4) / 2) - FigHeight / 2];
% end
% FigPos(3:4)=[FigWidth FigHeight];
% set(hObject, 'Position', FigPos);
% set(hObject, 'Units', OldUnits);
% 
% 
% 
% % Make the GUI modal
% set(handles.figure1,'WindowStyle','modal')




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

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



% The figure can be deleted now
delete(handles.figure1);

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

handles.force.tension    = handles.tension             ;
handles.force.pressure   = handles.pressure     ;
handles.force.spont      = handles.spont             ;
handles.force.stepsize   = handles.stepsize;
handles.force.normal_sign= handles.normal_sign;
handles.force.zmin       = handles.zmin;
handles.force.zmax       = handles.zmax;
handles.force.ms         = handles.ms;
handles.force.rm         = handles.rm;
handles.force.mflag     = handles.mflag;

guidata(hObject, handles);

close(handles.fighand);
% Use UIRESUME instead of delete because the OutputFcn needs
% to get the updated handles structure.
uiresume(handles.figure1);




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

uiresume(handles.figure1);



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



pressure = str2double(get(hObject, 'String'));
if isnan(pressure)
    errordlg('Input must be a number','Error');
    set(handles.PressureEdit,        'String',sprintf('%g',  handles.pressure));
else
    if get(handles.LockToggle,'Value')
        handles.tension = handles.tension/handles.pressure*pressure;
        set(handles.TensionEdit,        'String',sprintf('%g',  handles.tension));
    end
    handles.pressure = pressure;        
    guidata(hObject, handles);
    set(handles.PressureEdit,        'String',sprintf('%g',  handles.pressure));
    DrawDataCall( hObject, eventdata, handles);

end;

DrawDataCall(hObject, eventdata, handles);


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



tension = str2double(get(hObject, 'String'));
if isnan(tension)
    errordlg('Input must be a number','Error');
    set(handles.TensionEdit,        'String',sprintf('%g',  handles.tension));
else
    if get(handles.LockToggle,'Value')
        handles.pressure = handles.pressure/handles.tension*tension;
        set(handles.PressureEdit,        'String',sprintf('%g',  handles.pressure));
    end
    handles.tension = tension;
    guidata(hObject, handles);
    set(handles.TensionEdit,        'String',sprintf('%g',  handles.tension));
    DrawDataCall( hObject, eventdata, handles);

end;

DrawDataCall(hObject, eventdata, handles);


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



set(handles.PressureEdit,     'String',sprintf('%g',handles.pressure));
set(handles.TensionEdit,      'String',sprintf('%g',handles.tension));
set(handles.SpontEdit,        'String',sprintf('%g',handles.spont));
set(handles.ForceStepSizeEdit,'String',sprintf('%g',handles.stepsize));
set(handles.ZMinEdit,         'String',sprintf('%g',handles.zmin));
set(handles.ZMaxEdit,         'String',sprintf('%g',handles.zmax));
set(handles.msEdit,           'String',sprintf('%g',handles.ms));
set(handles.rmEdit,           'String',sprintf('%g',handles.rm));

set(handles.ColorMapPopup, 'Value', 1);
set(handles.MagicCheckBox, 'Value', handles.mflag);

handles.fighand = figure();
guidata(hObject, handles);

DrawDataCall(hObject, eventdata, handles);

handles = guidata(hObject);


set(handles.LockToggle,'Value',0);

%AvgCurvText_make(hObject, eventdata, handles)
%TotalAreaText_make(hObject, eventdata, handles)

%handles


% --- Executes on selection change in ColorMapPopup.
function ColorMapPopup_Callback(hObject, eventdata, handles)
% hObject    handle to ColorMapPopup (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 ColorMapPopup contents as cell array
%        contents{get(hObject,'Value')} returns selected item from ColorMapPopup



menunum = get(hObject, 'Value');
switch menunum
    case 1
        handles.colormap = 'Total Force';
       % 'default'
    case 2
        handles.colormap = 'Force Density';
        %'gray'
    case 3
        handles.colormap = 'Curvature';
        %'hot'
end
guidata(hObject, handles);




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

set(hObject, 'String', {'default', 'gray', 'hot'});


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

% Hint: get(hObject,'Value') returns toggle state of ChooseRangeToggle

if get(hObject,'Value') == 0
    handles.choose_range_flag = 0;
else
    handles.choose_range_flag = 1;
end;

guidata(hObject, handles);

    
    
    
    


% --- Executes on selection change in ColorMapPopupM.
function ComputePopup_Callback(hObject, eventdata, handles)
% hObject    handle to ColorMapPopupM (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 ColorMapPopupM contents as cell array
%        contents{get(hObject,'Value')} returns selected item from ColorMapPopupM

value = get(hObject,'Value');

DrawDataCall(hObject, eventdata, handles);


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

spont = str2double(get(hObject, 'String'));
if isnan(spont)
    errordlg('Input must be a number','Error');
    set(handles.SpontEdit,        'String',sprintf('%g',  handles.spont));
else
    handles.spont = spont;
    guidata(hObject, handles);
    set(handles.SpontEdit,        'String',sprintf('%g',  handles.spont));
    DrawDataCall( hObject, eventdata, handles);

end;


DrawDataCall(hObject, eventdata, handles);

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

set(hObject,'String',{'Total Force','Force Density','Curvature','tangents'});


function DrawDataCall(hObject, eventdata, handles)


if ~get(handles.ReInterpCheckBox, 'Value')
    [Result_String] = forcecalc13(handles.tension,handles.pressure,handles.spont,handles.force.r,get(handles.ComputePopup,'Value'),handles.fighand,handles.normal_sign,handles.zmin,handles.zmax,get(handles.WhichParamPopup,'Value'));
elseif handles.mflag
    [Result_String] = forcecalc13(handles.tension,handles.pressure,handles.spont,handles.rr,get(handles.ComputePopup,'Value'),handles.fighand,handles.normal_sign,handles.zmin,handles.zmax,get(handles.WhichParamPopup,'Value'));
else
    [Result_String] = forcecalc13(handles.tension,handles.pressure,handles.spont,handles.r,get(handles.ComputePopup,'Value'),handles.fighand,handles.normal_sign,handles.zmin,handles.zmax,get(handles.WhichParamPopup,'Value'));
end;

    %set(handles.DataText,        'String',Result_String);
    
    
    guidata(hObject, handles);

    

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

% Hint: get(hObject,'Value') returns toggle state of LockToggle


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

% Hint: get(hObject,'Value') returns toggle state of NNToggle

if handles.normal_sign > 0
    handles.normal_sign = -1;
else
     handles.normal_sign = 1;
end;   

guidata(hObject,handles);

DrawDataCall( hObject, eventdata, handles);

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



stepsize = str2double(get(hObject, 'String'));
if isnan(stepsize)
    errordlg('Input must be a number','Error');
    set(handles.ForceStepSizeEdit,        'String',sprintf('%g',  handles.stepsize));
else
    handles.stepsize = stepsize;
    guidata(hObject, handles);
    set(handles.ForceStepSizeEdit,        'String',sprintf('%g',  handles.stepsize));
    
    reinterp_data(hObject, eventdata, handles);
    handles = guidata(hObject);
    
    DrawDataCall( hObject, eventdata, handles);
end;

handles = guidata(hObject);


%AvgCurvText_make(hObject, eventdata, handles);
%TotalAreaText_make(hObject, eventdata, handles);









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


%compute ds

rlength = max(size(handles.force.r));

s = zeros(rlength,1);
ds = zeros(rlength-1,1);

for i=2:rlength;
    ds(i-1) = norm(handles.force.r(i,:)-handles.force.r((i-1),:));
    s(i) = sum(ds(1:(i-1)));
end;

smax = s(rlength);

snew = 0:handles.stepsize:smax;

if max(size(snew)) < 8
    handles.stepsize = mean(ds);
    guidata(hObject,handles);
    reinterp_data(hObject, eventdata, handles);
    handles = guidata(hObject);
else
    handles.r = interp1(s,handles.force.r,snew,'spline');
end;


handles.rr = data_maker2(handles.force.r,handles.rm,handles.ms);

guidata(hObject,handles);


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



function TotalAreaText_make(hObject, eventdata, handles);

    set(handles.TotalAreaText,  'String',sprintf('%g',  handles.area));

    


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


function FGuessText_CreateFcn(hObject, eventdata, handles)
% hObject    handle to AvgCurvText (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called



function AvgCurvText_make(hObject, eventdata, handles)


    set(handles.AvgCurvText,  'String',sprintf('%g',  handles.ac));



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


zmax = str2double(get(hObject, 'String'));
if isnan(zmax)
    errordlg('Input must be a number','Error');
    set(handles.ZMaxEdit,        'String',sprintf('%g',  handles.zmax));
else
    handles.zmax = zmax;        
    guidata(hObject, handles);
    set(handles.ZMaxEdit,        'String',sprintf('%g',  handles.zmax));
    DrawDataCall( hObject, eventdata, handles);

end;

DrawDataCall(hObject, eventdata, handles);


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



zmin = str2double(get(hObject, 'String'));
if isnan(zmin)
    errordlg('Input must be a number','Error');
    set(handles.ZMinEdit,        'String',sprintf('%g',  handles.zmin));
else
    handles.zmin = zmin;        
    guidata(hObject, handles);
    set(handles.ZMinEdit,        'String',sprintf('%g',  handles.zmin));
    DrawDataCall( hObject, eventdata, handles);

end;

DrawDataCall(hObject, eventdata, handles);



% --- Executes during object creation, after setting all properties.
function ZMinEdit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ZMinEdit (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 button press in ComputeMinButton.
function ComputeMinButton_Callback(hObject, eventdata, handles)
% hObject    handle to ComputeMinButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ComputeMinButton



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


% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ZMaxEdit (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 button press in MagicCheckBox.
function MagicCheckBox_Callback(hObject, eventdata, handles)
% hObject    handle to MagicCheckBox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of MagicCheckBox

handles.mflag = get(hObject,'Value');
DrawDataCall(hObject, eventdata, handles);



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




ms = str2double(get(hObject, 'String'));
if isnan(ms)
    errordlg('Input must be a number','Error');
    set(handles.msEdit,        'String',sprintf('%g',  handles.ms));
else
    handles.ms = ms;
    guidata(hObject, handles);
    set(handles.msEdit,        'String',sprintf('%g',  handles.ms));
    
    reinterp_data(hObject, eventdata, handles);
    handles = guidata(hObject);
    
    DrawDataCall( hObject, eventdata, handles);
end;

handles = guidata(hObject);



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





rm = str2double(get(hObject, 'String'));
if isnan(rm)
    errordlg('Input must be a number','Error');
    set(handles.rmEdit,        'String',sprintf('%g',  handles.rm));
else
    handles.rm = rm;
    guidata(hObject, handles);
    set(handles.rmEdit,        'String',sprintf('%g',  handles.rm));
    
    reinterp_data(hObject, eventdata, handles);
    handles = guidata(hObject);
    
    DrawDataCall( hObject, eventdata, handles);
end;

handles = guidata(hObject);




% --- Executes during object creation, after setting all properties.
function rmEdit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to rmEdit (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 WhichParamPopup.
function WhichParamPopup_Callback(hObject, eventdata, handles)
% hObject    handle to WhichParamPopup (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 WhichParamPopup contents as cell array
%        contents{get(hObject,'Value')} returns selected item from WhichParamPopup




    DrawDataCall( hObject, eventdata, handles);


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


set(hObject,'String',{'Manual Param','min(f^2) 2 Fit','min(f^3) 3 Fit','min(dF^2) 2 Fit','min(dF^3) 3 Fit'});


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

% Hint: get(hObject,'Value') returns toggle state of ReInterpCheckBox

   handles = guidata(hObject);
    
    DrawDataCall( hObject, eventdata, handles);
