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

% Last Modified by GUIDE v2.5 20-Jan-2012 14:14:07

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

% Choose default command line output for testGUI_1
handles.output = hObject;
% %TEST!!!!
% iInc = 1;
% 
% 
% folder_name = uigetdir('C:\Users\WinAdmin\Desktop\MATLAB\Bilder');
% listOfContent = dir(fullfile(folder_name, '*.dat'));
% lengthOfList = length(listOfContent);
% 
% handles.tofPicNow = dlmread(fullfile(folder_name, listOfContent(1).name));
% handles.tofPicNext = dlmread(fullfile(folder_name, listOfContent(2).name));
handles.tofPicNow = rand(100,100);
imagesc(handles.tofPicNow,'Parent',handles.axes1);
imagesc(abs(fft2(handles.tofPicNow)),'Parent',handles.axes2);

% handles.listOfContent = listOfContent;
% handles.lengthOfList = lengthOfList;
% handles.folder_name = folder_name;
% handles.iInc = iInc;

% Update handles structure
guidata(hObject, handles);

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



% --- Outputs from this function are returned to the command line.
function varargout = testGUI_1_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 loadList.
function loadList_Callback(hObject, eventdata, handles)
% hObject    handle to loadList (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% folder_name = uigetdir('c:\uni\');
% listOfContent = dir(fullfile(folder_name, '*.dat'));
% lengthOfList = length(listOfContent);

%Man kann auch alle Felder eines CellArrays in ein Array schreiben
%mit, X = {listOfContent.name}; Dann aber('daten1.dat',...)

% handles.listOfContent
% handles.lengthOfList
% handles.folder_name


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

if (handles.iInc <= handles.lengthOfList),
    handles.iInc = handles.iInc + 1;

    imagesc(handles.tofPicNext,'Parent',handles.axes1);
    imagesc(abs(fft2(handles.tofPicNext)),'Parent',handles.axes2);
 
    handles.tofPicBefore = handles.tofPicNow;
    handles.tofPicNow = handles.tofPicAfter;
    handles.tofPicAfter = dlmread(fullfile(handles.folder_name, handles.listOfContent(handles.iInc + 1).name));
   
    set(handles.statusText,'String',handles.iInc);
end
guidata(hObject, handles);


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

if (handles.iInc > 0),
    handles.iInc = handles.iInc - 1;
    
    imagesc(handles.tofPic.Before,'Parent',handles.axes1);
    imagesc(abs(fft2(handles.tofPic.Before)),'Parent',handles.axes2);
    
    handles.tofPicNext = handles.tofPicNow;
    handles.tofPicNow = handles.tofPicBefore;
    handles.tofPicBefore = dlmread(fullfile(handles.folder_name, handles.listOfContent(handles.iInc - 1).name));
        
    set(handles.statusText,'String',handles.iInc);
end
guidata(hObject, handles);

%---Do a Gauss-fit for the given data
function parameters = Gaussfit(datenmatrix)
[X,Y] = meshgrid(1:size(datenmatrix,1), 1:size(datenmatrix,2));
x(:,1) = X(:);
x(:,2) = Y(:);
daten= datenmatrix;
gauss = @(s,x) s(1)*exp(-((x(:,1)-s(2))/s(3)).^2-((x(:,2)-s(4))/s(5)).^2);
%options = optimset ('TolX', 1e-6);
anfangsparameter = [1 1 1 1 1];
parameters = lsqfitcurve(gauss, anfangsparameter, x, daten);



