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

% Last Modified by GUIDE v2.5 16-Sep-2013 13:46:53

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

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

% Update handles structure
guidata(hObject, handles);


% UIWAIT makes untitled wait for user response (see UIRESUME)
%uiwait(handles.samGui);


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


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

%Call the BatteryDialogBox to input infos(name, Ah, Temp)
DialogBoxTest

%GUI can not save automaticly the data to workspace. With save command can
%all infos save in a mat file called guioutput and then load it
save guioutput
LoadGUIOutput= load('guioutput');

%display the name of Measured battery in GUI Textbox
% MeasuredBatName=s;
% MeasuredBatName=source_files1;
% set(handles.Mytext1,'String',MeasuredBatName)

save guioutputDialogBox
 
% %==========================================================================
% %Handel for popup-menu
% %==========================================================================
% --- Executes on selection change in popupmenu4.
function popupmenu4_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.popupmenu4, 'String', {sourcefiles1.name})
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu4 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu4


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


%===========================================================================
% Read TextRead.m
%===========================================================================
TextRead
% By min to 0Hz
MeasuredFreq=Frequency;
set(handles.Mytext2,'String',MeasuredFreq)
MeasuredZreal=Zreal;
set(handles.Mytext3,'String',MeasuredZreal)
MeasuredZimaginar=Zimaginar;
set(handles.Mytext4,'String',MeasuredZimaginar)
% By 1000Hz
MeasuredZreal1000Hz=Zre1000;
set(handles.Mytext18,'String',MeasuredZreal1000Hz)
MeasuredZimaginar1000Hz=Zim1000;
set(handles.Mytext19,'String',MeasuredZimaginar1000Hz)

save guioutputTextRead

%===========================================================================
% Read AllFileReadTest.m
%===========================================================================
AllFileReadTest1 

MeasuredFreqCompare=FrequencyCompare;
set(handles.Mytext5,'String',MeasuredFreqCompare)
MeasuredZrealCompare=ZrealCompare;
set(handles.Mytext6,'String',MeasuredZrealCompare)
MeasuredZimaginarCompare=ZimCompare;
set(handles.Mytext7,'String',MeasuredZimaginarCompare)

BatteryDiagnostics=Filename;
set(handles.Mytext8,'String',BatteryDiagnostics)


MeasuredZrealCompare1000=closestValZre1000;
set(handles.Mytext24,'String',MeasuredZrealCompare1000)
MeasuredZimaginarCompare1000=closestValZim1000;
set(handles.Mytext25,'String',MeasuredZimaginarCompare1000)


BatteryDiagnosticsZre1000=FilenameOfZre1000;
set(handles.Mytext29,'String',BatteryDiagnosticsZre1000)
BatteryDiagnosticsZim1000=FilenameOfZim1000;
set(handles.Mytext31,'String',BatteryDiagnosticsZim1000)


% Test
MeasuredDivideVal=divideVal1000;
set(handles.Mytext39,'String',MeasuredDivideVal)
MeasuredDivideCompare=closestValDivide1000;
set(handles.Mytext40,'String',MeasuredDivideCompare)

MeasuredDivideVal=divideVal;
set(handles.Mytext33,'String',MeasuredDivideVal)
MeasuredDivideCompare=closestValDivide;
set(handles.Mytext35,'String',MeasuredDivideCompare)


BatteryDiagnosticsDivideVal=FilenameOfDivideVal;
set(handles.Mytext37,'String',BatteryDiagnosticsDivideVal)


%Test
BatteryDiagnosticsDivideVal=FilenameOfDivideVal1000;
set(handles.Mytext41,'String',BatteryDiagnosticsDivideVal)


%SOC
BattSoCLastDiagnose=SOCDiagnose;
set(handles.Mytext47,'String',BattSoCLastDiagnose)

%SOH
BattSoHLastDiagnose=SOHDiagnose;
set(handles.Mytext48,'String',BattSoHLastDiagnose)


save guioutputMain
 

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

set(handles.Mytext1,'String','')
set(handles.Mytext2,'String','')
set(handles.Mytext3,'String','')
set(handles.Mytext4,'String','')
set(handles.Mytext5,'String','')
set(handles.Mytext6,'String','')
set(handles.Mytext7,'String','')
set(handles.Mytext8,'String','')
set(handles.Mytext18,'String','')
set(handles.Mytext19,'String','')
set(handles.Mytext24,'String','')
set(handles.Mytext25,'String','')
set(handles.Mytext29,'String','')
set(handles.Mytext31,'String','')
set(handles.Mytext33,'String','')
set(handles.Mytext35,'String','')
set(handles.Mytext37,'String','')
set(handles.Mytext39,'String','')
set(handles.Mytext40,'String','')
set(handles.Mytext41,'String','')
set(handles.Mytext47,'String','')
set(handles.Mytext48,'String','')
%===========================================================================
% clear everything
%===========================================================================




TextRead
clear all

DialogBoxTest
clear all

AllFileReadTest1
clear all

% delete guioutputDialogBox.mat
% delete guioutputTextRead.mat
% delete guioutputMain.mat



