function selfilewaehlen(varargin)
%   This software is protected by german copyright and international treaties.             
%   Copyright 2004 Markus Junghöfer & Peter Peyk. All Rights Reserved.                     
%                                                                                          
%   THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE        
%   NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO,    
%   WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE    
%   OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
%   TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT,       
%   INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE      
%   OR DOCUMENTATION.                                                                      

global gruppcell gruppdims filepath filename dim anzahldims anzahlstimuli paramat filenamecell... 
        dim anzahldims anzahlstimuli paramat filenamecell filenamestatus filepath filename

if nargin < 8;filepath=[];filename=[];end
if isempty(filepath) & isempty(filename)
    [filename, filepath] = uigetfile('*.txt', 'Bitte wählen Sie das gewünscht File aus:', 300, 300);
end


if isequal(filename,0)|isequal(filepath,0)
    msgbox('File not found')
else
    %datenfile einlesen
    %--------------------
    [dim,anzahldims,anzahlstimuli,paramat,filenamecell]=readparamat(filename,filepath,paramat);  
    if isempty(dim)
        return
    end
    filemonitor=findobj('tag','selfilemonitor');
    set(filemonitor, 'string', strcat(filename));
    cell1popup=findobj('tag','cell1auswahl');
    set(cell1popup,'Enable','on');
    cell2popup=findobj('tag','cell2auswahl');
    set(cell2popup,'Enable','on');
    operatorpopup=findobj('tag','operatorpopup');
    set(operatorpopup,'Enable','on');
    alphapopup=findobj('tag','alphapopup');
    set(alphapopup,'Enable','on');
    dimensionauswahl=findobj('tag','dimensionauswahl');
    set(dimensionauswahl,'Enable','on');
    addbutton=findobj('tag','addbutton');
    set(addbutton,'Enable','on');
    dimstring='';
    set(dimensionauswahl,'String',dim);
    scenarioradio=findobj('tag','scenarioradio');
    statisticsradio=findobj('tag','statisticsradio');
    parameterfileradio=findobj('tag','parameterfileradio');
    xachsenpopup=findobj('tag','xachsenpopup');
    set(xachsenpopup,'Enable','on');
    set(xachsenpopup,'String',dim); 
    yachsenpopup=findobj('tag','yachsenpopup');
    set(yachsenpopup,'Enable','on');
    set(yachsenpopup,'String',dim); 
    zachsenpopup=findobj('tag','zachsenpopup');
    set(zachsenpopup,'String',dim); 
    gruppenpopup=findobj('tag','gruppenpopup');
    [a,b]=find(paramat==0);
    nullersetzmat=paramat;
    nullersetzmat(a,b)=1;
    warning off
    depp3=paramat./round(nullersetzmat);
    warning on
    [a,b]=find(depp3==0);
    depp3(a,b)=1;
    intvec=sum(depp3); 
    gruppcell=cell(1);
    gruppdims=[];
    gruppdims=find(intvec==anzahlstimuli);
    
    if ~isempty(gruppdims);
    for hanswurst=1:length(gruppdims);
        gruppcell{hanswurst,1}=dim{gruppdims(hanswurst)+1};
    end
    
    end
    set(gruppenpopup,'String',gruppcell); 
    drawbutton=findobj('tag','drawbutton');
    set(drawbutton,'Enable','on');
    set(scenarioradio,'Enable','on');
    set(statisticsradio,'Enable','on');
    set(parameterfileradio,'Enable','on');
        for j=1:anzahldims-2
            dimstring=[dimstring,dim{j},' '];
        end
        msgbox(['File mit Dateinamen und ',num2str(length(dim)-1),' dimensionen (',dimstring,') und ',num2str(anzahlstimuli),' Stimuli gefunden.'],'Bericht:')
end



return