function writeparameterfile
%   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 selectfilemonitor element gruppcell faktorstring anzahlfaktoren stufenvec aktiverfaktor zielmat cellstr vergleichecell dim anzahldims anzahlstimuli paramat operatorcell filenamecell filenamestatus stimnummercell

[savefilename,savefilepath]=uiputfile('*.txt','Bitte benennen Sie das neue Parameterfile:');
if isequal(savefilename,0)|isequal(savefilepath,0)
    msgbox('Invalid Filename!','Fehler')
    return
end


prompt={'Bitte geben Sie den Namen der einzufügenden Gruppierungsvariable ein:'};
def={''};
dlgTitle='Parameterfileergänzung:';
lineNo=1;
answer=inputdlg(prompt,dlgTitle,lineNo,def);
savefile=[savefilepath savefilename];
fid = fopen(savefile,'wt');


%header
fprintf (fid,dim{1});
for i=2:size(dim,2)-1
    fprintf(fid,['\t',dim{1,i}]);
end

fprintf(fid,['\t',answer{1}]);
fprintf (fid,'\n');

for j=1:size(paramat,1)
    fprintf(fid,[filenamecell{j},'\t']);
    
    fprintf(fid,num2str(paramat(j,1)));   
    for k=2:size(paramat,2)
        fprintf(fid,['\t',num2str(paramat(j,k))]);
    end
    
    gruppe = -1;
    for o=1:length(stimnummercell)
    if sum(j==stimnummercell{o})>0
        gruppe = o;
    end
    end
    
    if gruppe == -1;
        gruppenstring = '0';
    else 
        gruppenstring = num2str(gruppe);
    end
    
    fprintf(fid,['\t',num2str(gruppenstring)]);   
    fprintf(fid,'\n');
end

fclose (fid);
return
        
        


    











return