Skip to content
Snippets Groups Projects
mgui.m 53.3 KiB
Newer Older
marwan's avatar
marwan committed
function mgui(action);
% MGUI   GUI for data analysis programmes.
%    MGUI starts a GUI and supplies Matlab programmes
%    for their easy application to data which are in 
%    the Matlab workspace. 
%
%    The presented programmes are stored in the file
%    MGUI.RC where own programmes can be added. Just
%    include a line with the name of the programme and
%    the minimal and maximal number of arguments, divided
%    by a blank space or tabulator as a separator, e.g.
%
%       plot 1 4
%
%    If the embedded programmes provide an output, then 
%    this output will be stored in the variable ANS in
%    the Matlab workspace.
%
%    See also MGUICLEAN.

marwan's avatar
marwan committed
% Copyright (c) 2002-2006 by 
marwan's avatar
marwan committed
%         AGNLD, Institute of Physics
%         Potsdam University, Germany
%         Christian Hoennicke, Norbert Marwan, Andre Sitz
%         http://www.agnld.uni-potsdam.de
%
% $Date$
% $Revision$
%
% $Log$
marwan's avatar
marwan committed
% Revision 1.9  2004/11/10 07:05:21  marwan
% initial import
%
marwan's avatar
marwan committed
%
% This program is part of the new generation XXII series.
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or any later version.

warning off

if nargin==0
  action='init';
end

    font.FontName=get(0,'factoryTextFontName');
    font.FontUnits=get(0,'factoryTextFontUnits');
    font.FontSize=get(0,'factoryTextFontSize');
    font.FontWeight=get(0,'factoryTextFontWeight');
    font.FontAngle=get(0,'factoryTextFontAngle');

    props.root.defaultUIControlBackgroundColor=get(0,'factoryUIControlBackgroundColor');
    props.root.defaultUIControlForegroundColor=get(0,'factoryUIControlForegroundColor');
    props.root.defaultTextColor=get(0,'factoryUIControlForegroundColor');
    props.window.Color=[0.8008 0.7500 0.6875];
    props.window.Units='Char';
    props.window.Colormap=[[0 0 0];[props.window.Color]];
    props.newwindow.Color=[.8 .8 .8];
    props.newwindow.Units='Pixels';
    props.frame=font;
    props.frame.Style='frame';    
    props.frame.BackgroundColor=props.window.Color;
    props.frame.ForegroundColor=[0 0 0];
    props.frame.Units='Char';
    props.listbox=font;
    props.listbox.FontName='lucida';
    props.listbox.FontSize=10;
    props.listbox.Style='listbox';    
    props.listbox.BackgroundColor=[0.9297 0.8711 0.7969];
    props.listbox.ForegroundColor=[0 0 0];
    props.listbox.Units='Char';
    props.button=font;
    props.button.Style='pushbutton';    
    props.button.BackgroundColor=[0.8008 0.7500 0.6875];
    props.button.ForegroundColor=[0 0 0];
    props.button.Units='Char';
    props.checkbox=font;
    props.checkbox.Style='checkbox';
    props.checkbox.HorizontalAlignment='left';
    props.checkbox.BackgroundColor=props.window.Color;
    props.checkbox.ForegroundColor=[0 0 0];
    props.checkbox.Units='Char';
    props.text=font;
    props.text.Style='text';
    props.text.HorizontalAlignment='left';
    props.text.BackgroundColor=props.window.Color;
    props.text.ForegroundColor=[0 0 0];
    props.text.Units='Char';
    props.msgbox=font;
    props.msgbox.FontSize=get(0,'factoryUIControlFontSize');
    props.msgbox.BackgroundColor=props.window.Color;
    props.msgbox.ForegroundColor=[0 0 0];
    props.msgboxwin.Color=props.msgbox.BackgroundColor;
    v=version;
    if str2num(v(findstr(v,'(R')+2:findstr(v,')')-1))<=12;
      props.msgboxwin.Colormap=[[0 0 0];[props.msgbox.BackgroundColor]];
    end
    props.logo.Visible='off';
    props.logo.Units='Char';
    props.logo.Color=props.window.Color;

    set(0,'Units','Character'), sc=get(0,'ScreenSize'); 
    set(0,'Units','Pixels'), sc2=get(0,'ScreenSize');
    po=get(0,'defaultFigurePosition');
    props.window.Position=[4 sc(4)-32 125.1667 29.0714]; % Mainframe
    props.newwindow.Position=[sc2(3)-1.05*po(3) po(2) po(3) po(4)]; % Ausgabefenster
    props.frame.Position=[28.0000  5.5 94.8333 21.67]; % frame um die parameterliste
    props.listbox_function_select.Position=[  3.1667  5.5 23.5000 22.1000]; % Funktionselect [.1 .8 .8 .1]
    props.button_apply.Position=[ 99.8333  1.8571 16.8333  2.1429]; % Knopf 1 :: Ausfhren [.52 .05 .38 .10]
    props.button_parm_le.Position=[ 28.9 24.3  3.5000  1.5000]; % parm_le :: Parameter verringern [.1 .1 .3 .1]
    props.button_parm_ge.Position=[117.9 24.3  3.5000  1.5000]; % parm_ge :: Parameter erhhen [.1 .2 .3 .1]
    props.listbox_parm.Position=[ 34.  7.9000 18.5000 16.5000]; % PopupBox (Listbox)
    props.button_ok.Position=[ 34.  6.4 18.5000  1.5000]; % Knopf schliesen
    props.button_parm.Position=[ 34. 24.3 18.5000  1.5000]; % ParameterButton
    props.button_help.Position=[ 76.5000  1.8571 10.1667  2.1429]; % Knopf 5 :: Help
    props.button_close.Position=[ 88.1667  1.8571 10.1667  2.1429]; % Knopf 6 :: Close
    props.text_disclaimer.Position=[  11.5  0.7 23.5000  3.6429]; % Disclaimer
    props.logo.Position=[  3.1667  0.9 6.8 3.5]; % Disclaimer
    props.checkbox_CheckNewWindow.Position=[  36.1667  1.3571 35.1667  1.5000]; % CheckNewWindow
    props.checkbox_ForceSameLength.Position=[ 36.1667  3.0000 35.1667  1.5000]; % ForceSameLength
    props.text_funktion_helptext.Position=[ 29 26.2857 93.5000  1.2857]; % funktion_helptext
    
set(0,'defaultUIControlBackgroundColor',props.msgbox.BackgroundColor,...
      'defaultUIControlForegroundColor',props.msgbox.ForegroundColor,...
      'defaultTextColor',props.text.ForegroundColor)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% splash the GPL

filename='mgui';
which_res=which([filename,'.m']);
gplrc_path=[strrep(which_res,[filename,'.m'],''), 'private'];
gplrc_file=[gplrc_path, filesep, '.gpl.',filename];
if ~exist(gplrc_path)
  mkdir(strrep(which_res,[filename,'.m'],''),'private')
end
if ~exist(gplrc_file)
  fid=fopen(gplrc_file,'w');
  fprintf(fid,'%s\n','If you delete this file, the GNU Public License will');
  fprintf(fid,'%s','splash up at the next time the programme starts.');
  fclose(fid);

  if exist('gpl')
    txt=gpl;
  else
    txt={'The GNU General Public License was not found.'};
  end
  h=figure('NumberTitle','off',...,
         'ButtonDownFcn','close',...
         'Name','GNU General Public License');
  ha=get(h,'Position');
  h=uicontrol('Style','Listbox',...
            'ButtonDownFcn','close',...
            'CallBack','close',...
            'Position',[0 0 ha(3) ha(4)],...
	    'FontName','Courier',...
	    'BackgroundColor',[.8 .8 .8],...
	    'String',txt);
  waitfor(h)
end


hMF = findobj('Tag','MainFrame');
if ~(isempty(hMF)), props = get(hMF,'UserData'); end
if ~isempty(findobj('Tag','helpdlgbox')), delete(findobj('tag','helpdlgbox')), end
hfs    = findobj('Tag','function_select');
select = get(hfs,'Value');
funktion = get(hfs,'UserData');
if ~isempty(funktion)
  FktName = char(funktion(select).name);
  if strcmp(FktName,'------------');
    select=select+1;
    set(hfs,'Value',select)
    mgui action
  end
end
set(0,'ShowHiddenHandles','off')

% Und "Aktion!" - hier geht es los
switch(action)

  case 'init'

  %%% Hier wird der Programmablauf vorbereitet,
  %%% * die Graphikkoordinaten festgelegt
  %%% * die Funktionslisten aus der Datei generiert
  %%% * das Grundfenster gezeichnet

   % Lsche bestehende Fenster gleichen Tags
    if ~isempty(findobj('Tag','MainFrame'))
      delete(findobj('Tag','MainFrame'))
    end

    % Die Funktionen Load und Save am Anfang einfuegen
    i = 1;
    funktion(i).name = cellstr('load');
    funktion(i).min = 0;
    funktion(i).max = 0;
    funktion(i).akt = 0; 
    funktion(i).klicklist{4}=[];
    funktion(i).klickstring{4}=[];
    i=i+1;

    funktion(i).name = cellstr('save');
    funktion(i).min = 1;
    funktion(i).max = 1;
    funktion(i).akt = 1; 
    funktion(i).klicklist{4}=[];
    funktion(i).klickstring{4}=[];
    i=i+1;

    funktion(i).name = cellstr('add programme');
    funktion(i).min = 0;
    funktion(i).max = 0;
    funktion(i).akt = 0; 
    funktion(i).klicklist{4}=[];
    funktion(i).klickstring{4}=[];
    i=i+1;

    funktion(i).name = cellstr('------------');
    funktion(i).min = 0;
    funktion(i).max = 0;
    funktion(i).akt = 0; 
    funktion(i).klicklist{4}=[];
    funktion(i).klickstring{4}=[];

    %% Einlesen der Funktionsliste
    % ffnen der Datei mit den Funktionensnamen und -parametern
    fid = fopen('mgui.rc','r');
    if (fid ~= -1) % fopen liefert im Fehlerfall "-1"
      line = fgetl(fid); 
      while (line ~=-1) %EOF
        if ~isempty(line) & line(1)~='%' %einlesen erster Parameter
          i = i + 1;
          [name,line] = strtok(line);
          funktion(i).name = cellstr(name);
          [min,line] = strtok(line);
          if ~isempty(min)
            funktion(i).min = str2num(min);
            [max,line] = strtok(line);
            if ~isempty(max) 
              % Hack : mehr als 4 Parameter werden nicht zugelassen
              funktion(i).max = str2num(max);
              if (funktion(i).max > 4)
                funktion(i).max = 4;
              end
              funktion(i).akt = str2num(min);
	      funktion(i).klicklist{4}=[];
	      funktion(i).klickstring{4}=[];
              % Fehlerfall min > max
              if funktion(i).min > funktion(i).max
                h=errordlg([' Error in data structure at: ' char(funktion(i).name) ' -> (min>max)'],'Initialization');
                set(h,props.msgboxwin),h2=guihandles(h);set(h2.OKButton,props.msgbox)
		waitfor(h)
              end
         % Fehler: "Zu wenige Parameter" einsammeln
            else
              h=errordlg([' Error in data structure at: ' char(funktion(i).name) ' -> (to less parameter)'],'Initialization');
              set(h,props.msgboxwin),h2=guihandles(h);set(h2.OKButton,props.msgbox)
	      waitfor(h)
              funktion(i).min = 0;
              funktion(i).max = 0;
              funktion(i).akt = 0;
	      funktion(i).klicklist{4}=[];
	      funktion(i).klickstring{4}=[];
            end
          else
            h=errordlg([' Error in data structure at: ' char(funktion(i).name) ' -> (to less parameter)'],'Initialization'); 
	    set(h,props.msgboxwin),h2=guihandles(h);set(h2.OKButton,props.msgbox)
            waitfor(h)
            funktion(i).min = 0;
            funktion(i).max = 0;
            funktion(i).akt = 0;
	    funktion(i).klicklist{4}=[];
	    funktion(i).klickstring{4}=[];
          end
        end
        line = fgetl(fid); % Zeilenweises lesen
      end
      fclose(fid); % schliesen der Datei

    % Wenn fopen() fehlgeschlagen ist
    else
      h=error('File mgui.rc not found.');
%       funktion.name = cellstr('Empty');
%       funktion.min = 0;
%       funktion.max = 0;
%       funktion.akt = 0;
%       funktion.klicklist{4}=[];
%       funktion(i).klickstring{4}=[];
    end

    % Schmeie alle unbekannten Funktionen raus...
    j = size(funktion,2); i=5;
    while i<=j
      if isempty(double(which(char(funktion(i).name))))
        funktion(i) = [];
        i = i-1;
        j = j-1;
      end
        i=i+1;
    end

    %% Zeichnen der Obeflche
    % Zeichnen des Grundfensters (Hack: Koordinaten sind fix)
    figure(props.window,'Tag','MainFrame',...
           'NumberTitle','off',...
           'Name','Controlpanel',...
           'MenuBar','None',...
	   'DeleteFcn','mgui winclose',...
           'UserData',props,...
           'Resize','Off');

    uicontrol(props.frame);
    
    if length(funktion)>4, select=5; else select=3; end

    uicontrol(props.listbox, props.listbox_function_select,...
              'Tag','function_select',... 
              'String', [funktion.name]',...
              'UserData', funktion,...
	      'Value',select,...
              'Callback', 'mgui mod2', 'ButtonDownFcn','helpwin mgui');

    % Knopf 3 :: Parameter verringern
b=[fliplr(triu(ones(10,10))),triu(ones(10,10))];
b=rot90(b(:,1:2:end));
for i=1:3,
c=(b==1)*props.button.BackgroundColor(i)+(b==0)*props.button.ForegroundColor(i);
icon(:,:,i)=c(:,1:2:end);
end
    uicontrol(props.button, props.button_parm_le,...
              'Tag','parm_le',...
	      'CData',icon,...
              'Visible', 'off',...
              'Callback','mgui ChangeNumberOfParameters',... 
              'ToolTip','Decreases the number of parameters.');

    for i =1:4,
        uicontrol(props.button, 'Tag',['button_parm' num2str(i)],...
                  'Position', [(props.button_parm.Position(1) + ((i - 1) * 21.2)), props.button_parm.Position(2), props.button_parm.Position(3), props.button_parm.Position(4)],...
                  'String', ['Parm' num2str(i)],...
                  'Visible', 'off',...
                  'Callback', 'mgui Vis');
		  
       h=uicontrol(props.listbox, 'Tag',['listbox_parm' num2str(i)],...
                  'Value',[],...
                  'Max',2,...  %Hack: scheinbar beliebig Zahl(>1) mglich...
 		  'ButtonDownFcn','mgui selectcolumn',...
                  'Visible', 'off',...
                  'Position', [(props.listbox_parm.Position(1) + ((i - 1) * 21.2)), props.listbox_parm.Position(2), props.listbox_parm.Position(3), props.listbox_parm.Position(4)],...
                  'Callback','mgui klickreihenfolge'); 
		  
        uicontrol(props.button, 'Tag',['button_close_parm' num2str(i)],...
                  'String', 'OK',...
                  'Visible', 'off',...
                  'Position', [(props.button_ok.Position(1) + ((i - 1) * 21.2)), props.button_ok.Position(2), props.button_ok.Position(3), props.button_ok.Position(4)],...
                  'Callback', 'mgui UnVis',...
                  'UserData',[]);
    end


    % Knopf 4:: Parameter erhhen
 b=[fliplr(triu(ones(10,10))),triu(ones(10,10))];
 b=rot90(b(:,1:2:end),-1);
 for i=1:3,
 c=(b==1)*props.button.BackgroundColor(i)+(b==0)*props.button.ForegroundColor(i);
 icon(:,:,i)=c(:,1:2:end);
 end

    uicontrol(props.button, props.button_parm_ge,...
              'Tag','parm_ge',...
	      'CData',icon,...
              'Visible', 'on',...
              'Callback','mgui ChangeNumberOfParameters',... 
              'ToolTip','Increases the number of parameters.');

    uicontrol(props.checkbox, props.checkbox_ForceSameLength, ...
              'Tag','ForceSameLength',...
              'Value',0,...
	      'ToolTip','Fills parameter vectors with NaN in order to get the same vector lengths.',...
              'String','Force equal data length.');

    uicontrol(props.checkbox, props.checkbox_CheckNewWindow, ...
              'Tag','CheckNewWindow',...
              'Value',0,...
	      'ToolTip','Every apply click will create a new figure.',...
              'String','Create new figure.');

    % Knopf 5 :: Help
    uicontrol(props.button, props.button_help,...
              'Tag','help',...   
              'String','Help',...
              'Callback', 'mgui help',...
              'ToolTip','Helpwindow.', 'ButtonDownFcn','helpwin mgui');

    % Knopf 6 :: Close
    uicontrol(props.button, props.button_close, ...
              'Tag','close',...
              'String','Close',...
              'Callback', 'mgui close',...
              'ToolTip','Closing the GUI.', 'ButtonDownFcn','helpwin mgui');

    % Knopf 1 :: Ausfhren
    uicontrol(props.button, props.button_apply, 'Tag','apply',...  
              'String','Apply',...
              'Enable','off',...
              'Callback', 'mgui apply',...
              'ToolTip','Apply the choosen function.', 'ButtonDownFcn','helpwin mgui');

    h=axes;
    logo=load('logo');
    imagesc([logo.logo fliplr(logo.logo)], 'ButtonDownFcn','helpwin mgui')
    set(h,props.logo)

    h=uicontrol(props.text, props.text_disclaimer, ...
              'HandleVis','off',...
              'Tag','disclaimer',...
	       'ButtonDownFcn','helpwin mgui');
marwan's avatar
marwan committed
    h2=textwrap(h,{[char(169),' AGNLD'],'University of Potsdam','2002-2006'});
marwan's avatar
marwan committed
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
    set(h,'String',h2)
    
 
     mgui mod2;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  case 'mod2'

    %%% erlegt den ganzen init-kram, wenn eine Funktion ausgewhlt wurde

    % Anzahl der Parameter und Auswahlboxen beim Start anpassen und zeichnen
    % lesen der Anzahl der minimalen/maximalen Parameter
    FN_Min  = funktion(select).min;
    FN_Max  = funktion(select).max;
    FN_Akt  = funktion(select).akt;
    FN_Name = funktion(select).name;

%%% kurzhilfe einblenden
    if strcmp(FN_Name, 'add programme');
      fnhelptext='ADD PROGRAMME   Adds a programme into the MGUI and its related RC file.';
      ind=length(fnhelptext);
    else
      fnhelptext=help(char(FN_Name));
      ind=findstr(char(10),fnhelptext);
    end

    hfh=findobj('Tag','funktion_helptext');
    if isempty(hfh)
      hfh=uicontrol(props.text, props.text_funktion_helptext,...
                'Tag','funktion_helptext',...
                'String',[fnhelptext(1:ind(1))],...
		'ButtonDownFcn','helpwin mgui');
    else
      set(hfh,'string',[fnhelptext(1:ind(1))])
    end
    h=get(hfh,'Extent');h2=get(hfh,'Position');
    set(hfh,'Position',[h2(1:2) h(3) h2(4)])
    drawnow

    %% Knppe in Ausgangsstellung bringen
    % Wenn, mehrere Parameter erlaubt sind, die Knpfe aktivieren
    % Es sind mehr Parameter mglich

    set(findobj('Tag','parm_le'),'Visible','on');
    set(findobj('Tag','parm_ge'),'Visible','on');

    if (FN_Akt == FN_Max)
      set(findobj('Tag','parm_ge'),'Visible','off');
    end

    if (FN_Akt == FN_Min)
      set(findobj('Tag','parm_le'),'Visible','off');
    end

    check_workspace;
    check_apply

    %% aufdecken 
    for i = 1 : FN_Akt
      hparm = findobj('Tag',['button_parm' num2str(i)]);
      hlbox = findobj('Tag',['listbox_parm' num2str(i)]);
      hbcp  = findobj('Tag',['button_close_parm' num2str(i)]);
      set(hparm,'Visible','on');
      set(hlbox,'Visible','on');
      set(hbcp,'Visible','on');
      temp=funktion(select).klicklist;
      if ~isempty(temp), klick_list=temp{i}; else, klick_list = []; end
      if isempty(klick_list), klick_list = get(hbcp,'UserData'); end
      klick_string=funktion(select).klickstring{i};
      if isempty(klick_string)
        klick_string=get(hparm,'String');
      end
    end

    %% Verdeckt
    for i = (FN_Akt +1) : 4 % HACK: es sind nicht mehr als 4 paramter vorgesehen
      hparm = findobj('Tag',['button_parm' num2str(i)]);
      hlbox = findobj('Tag',['listbox_parm' num2str(i)]);
      hbcp  = findobj('Tag',['button_close_parm' num2str(i)]);
      set(hparm,'Visible','off');
      set(hlbox,'Visible','off');
      set(hbcp,'Visible','off');
    end

    if strcmp(FN_Name, 'load');
       mgui load
    end

    if strcmp(FN_Name, 'add programme');
       mgui add_programme
    end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%       
  case 'apply' 
    %%% Alle Parameter werden ausgelesen und hintereinander zusammengestellt und ausgefhrt
             
    %% Init
    FN_Akt = funktion(select).akt;
    FktName = char(funktion(select).name);

    %% 'save' und 'load' rausfischen -> selbst geschrieben
    if strcmp(FktName,'save')
      mgui save;
      return;
    end 

    if strcmp(FktName,'load')
      mgui load;
      return;
    end 

    if strcmp(FktName, 'add programme');
      mgui add_programme;
      return;
    end

    %% Auszufhrenden String zusammenbasteln
    Argumente = '(';
    for j=1 : FN_Akt
      Arg = ['Arg',num2str(j)];
%    %% Init
      var_list = get(findobj('Tag',['listbox_parm' num2str(j)]),'UserData');
      temp=funktion(select).klicklist;
      if ~isempty(temp), klick_list=temp{j}; else, klick_list=[]; end
      if isempty(klick_list), klick_list=get(findobj('Tag',['button_close_parm', num2str(j)]),'UserData'); end

      Matrix = []; % Zu speichernder Inhalt

      %% Parameterinhalt zusammenstellen
      for i = 1:size(klick_list,2); 
        % Einlesen des Variablennamens und zuweisen seines Inhaltes
        VarName = var_list(klick_list(1,i)).name;

        try
          VarValue = evalin('base',VarName);
        catch
          h=warndlg(['Variable ' VarName ' could not be found and will be ignored henceforth.'],'Scan workspace'); 
	  set(h,props.msgboxwin),h2=guihandles(h);set(h2.OKButton,props.msgbox)
          set(h,'Tag','helpdlgbox','HandleVisibility','On');
          continue;
        end

        % Zeilenvektor in Spaltenvektor transformieren 
        if (size(VarValue,1)) == 1
          VarValue = VarValue';
        end

        % Feststellen der gewnschten Reihen
        SelectRows = klick_list(find(klick_list(:,i)),i);
        SelectRows(1,:) = []; % Lsche Kopf (Enthlt Verweis auf den Variablennamen)

        % Wenn Spalten gewhlt wurden, dann den Varibleninhalt darauf begrenzen
        if ~isempty(SelectRows)
           VarValue = VarValue(:,SelectRows);
        end

        % Unterschiedliche Lnge -> Auffllen mit "NaN"
        if (size(Matrix,1) ~= size(VarValue,1)) & (size(Matrix,1) ~= 0)
          % Matrix zu lang
          if (size(Matrix,1) > size(VarValue,1))  
             VarValue((size(VarValue,1)+1):size(Matrix,1),:) = NaN;
          % Spaltenvektor zu lang
          else
            Matrix((size(Matrix,1)+1):size(VarValue,1),:) = NaN;
          end
        end

        Matrix = [Matrix VarValue]; 
      end


    % zusammenfgen aller gewhlten Variablen

        % Wertzuweisung eines Paramters
        eval([Arg '= Matrix;']);

        Argumente = strcat(Argumente, Arg);

%        if j < FN_Akt
        Argumente = strcat(Argumente,',');    
%        end    
    end
    Argumente(end) = [];
    Argumente = strcat(Argumente,')');

    %% Alle Parameter erhalten die gleiche Lnge (wenn gewnscht)
    if get(findobj('Tag','ForceSameLength'),'Value')

      % Init
      MaxLength = 0;

      % Suche des lngsten Parameters
      for i = 1:FN_Akt
        Matrix = eval(['Arg' num2str(i)]);
        if (size(Matrix, 1) > MaxLength)
          MaxLength = size(Matrix, 1);
        end
      end

      % Alle Parameter auf die gleiche Lnge trimmen
      for i = 1:FN_Akt
        Matrix = eval(['Arg' num2str(i)]); % laden
        Matrix(size(Matrix,1):MaxLength,:)= NaN;
        eval([['Arg' num2str(i)] '= Matrix;']); % speichern
      end

    end

    %% Ausgabe der Funktionswerte
    % Erstellt auf Wunsch ein neues Ausgabefenster
    hnpw = findobj('Tag','CheckNewWindow');
    bNewWindow = get(hnpw,'Value');
    if bNewWindow
        figure(props.newwindow,'Tag','PrintWindow');
    end

    %% Ausfhren der ganzen Mhe (mit Errorhandling)

    % Schreibschutz aktivieren 
    set(hMF, 'HandleVisibility','Off');
    % Ausfhren 

    try
      set(0,props.root);
      eval([FktName Argumente]);
%       if ~isempty(ans)
%         assignin('base','ans',ans)
%       end
    catch
      set(0,'defaultUIControlBackgroundColor',props.msgbox.BackgroundColor,...
      'defaultUIControlForegroundColor',props.msgbox.ForegroundColor,...
      'defaultTextColor',props.text.ForegroundColor)
      h=errordlg(lasterr,['Call ',upper(FktName)]);
      set(h,props.msgboxwin),h2=guihandles(h);set(h2.OKButton,props.msgbox)
      waitfor(h);
    end

    % Schreibschutz deaktivieren
    set(hMF, 'HandleVisibility','on');
    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  case 'ChangeNumberOfParameters'

    %%% verndern der aktuellen Parameteranzahl
    %%% parm_le => verringern; parm_ge => vergroessern

    %% Init
    hcall  = gcbo;
    caller = get(hcall,'Tag');

    FN_Akt = funktion(select).akt;
    FN_Min = funktion(select).min;
    FN_Max = funktion(select).max;
    
    %% Anzahl sichtbarer Parameter verringern
    if strcmp('parm_le',[caller])
      if FN_Akt > FN_Min 
        set(findobj('Tag',['button_parm' num2str(FN_Akt)]),'Visible','off');
        set(findobj('Tag',['button_close_parm' num2str(FN_Akt)]),'Visible','off');
        set(findobj('Tag',['listbox_parm' num2str(FN_Akt)]),'Visible','off');

        funktion(select).akt = FN_Akt - 1;
        set(hfs,'UserData',funktion);
        if funktion(select).akt <= FN_Min
          set(hcall,'Visible','off');
        end
        set(findobj('Tag','parm_ge'),'Visible','on');
      end

      %if ~isempty(get(findobj('Tag',['button_close_parm', num2str(FN_Akt-1)]),'UserData'))
      %  set(findobj('Tag','apply'),'Enable','on');
      %end
    %% Anzahl sichtbarer Parameter erhhen (parm_ge)
    else
      if FN_Akt < FN_Max 
        funktion(select).akt = FN_Akt + 1;

        set(findobj('Tag',['button_parm' num2str(FN_Akt+1)]),'Visible','on');
        set(findobj('Tag',['button_close_parm' num2str(FN_Akt+1)]),'Visible','on');
        set(findobj('Tag',['listbox_parm' num2str(FN_Akt+1)]),'Visible','on');

        set(hfs,'UserData',funktion);
        if funktion(select).akt >= FN_Max 
          set(hcall,'Visible','off');
        end
        set(findobj('Tag','parm_le'),'Visible','on');
        % Den Apply-Knopf deaktivieren
       % if isempty(get(findobj('Tag',['button_close_parm', num2str(FN_Akt+1)]),'UserData'))
       %   set(findobj('Tag','apply'),'Enable','off');
       % end
      end
    end

    %% Alle "Klick_listen" durchsuchen, ob "Apply" ausgefhrt werden darf
    FN_Akt   = funktion(select).akt;

    trigger = 0;
    % Alle "Klick_list"en durchsuchen
    for i = 1 : FN_Akt
      hbcp = findobj('Tag',['button_close_parm' num2str(i)]);
      temp=funktion(select).klicklist;
      if ~isempty(temp), klick_list=temp{i}; else, klick_list=[]; end
      if isempty(klick_list), klick_list=get(hbcp,'UserData'); end
      if isempty(klick_list)
        trigger = 1;
      end
    end
    % Wenn mindestens eine leere dabei, dann die Ausfhrung verhindern
    if trigger
      set(findobj('Tag','apply'),'Enable','off');
    else
      set(findobj('Tag','apply'),'Enable','on');
    end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
  case 'Vis'
    %%% Macht die geforderte Listbox + Closebutton sichtbar

    % Aufrufender = akt. Parameter wird rot gefrbt
    hcall = gcbo;

    %% Bestimmen des zugehrigen Auswahlfensters und Closebuttons
    caller = get(hcall,'Tag');
    caller_lbox = strrep(caller,'button','listbox');
    caller_bc   = strrep(caller,'button','button_close');

    lokal_ws=check_workspace;

%%%%%%%%%%%%%%
% check for erased variables
nparm = str2num(strrep(caller,'button_parm',''));                             
tmplist = funktion(select).klicklist{nparm};                                  
tmpstr = funktion(select).klickstring{nparm};                                 
if ~isempty(tmpstr)                                                           
ParmBereiche =[0 find(tmpstr == ',') size(tmpstr,2)+1];                       
                                                                             
% jeden Parameter einzeln checken                                             
for i = 1:size(ParmBereiche,2)-1                                              
  varname = tmpstr(ParmBereiche(i)+1:ParmBereiche(i+1)-1);                    
  trigger = 0;                                                                
  for j = 1:size(lokal_ws,2)                                                  
    if strcmp(lokal_ws(j).name,varname)                                       
      trigger =1;                                                             
      tmplist(1,i) = j;                                                       
      break;                                                                  
    end                                                                       
  end                                                                         
  if trigger == 0                                                             
    tmplist(i) = NaN;                                                         
    tmpstr(ParmBereiche(i)+1:ParmBereiche(i+1)-1) = ' ';                      
  end                                                                         
end                                                                           
tmplist(find(isnan(tmplist(1,:)))) = [];                                      
end                                                                           
%% hier noch die richtigen pfade eintragen                                    
%set(findobj('tag',caller_bc),'UserData',tmplist);                            
%set(hparm,'String',tmpstr);                                                  
funktion(select).klicklist{nparm}= tmplist;                                   
funktion(select).klickstring{nparm}=tmpstr;                                   
set(hfs,'UserData',funktion);                                                 
%%%%%%%%%%%%%%


    %% Aktivieren der angeforderten Listbox + Closebutton
    % Erst Listbox
    hlbox=findobj('Tag',[caller_lbox]);
    set(hlbox,'Visible','on');
%    set(hlbox,'String',[Ausgabe]);
%    set(hlbox,'UserData',lokal_ws);
    if isempty(get(hcall,'tooltip'))
      set(hlbox,'Value',[]); % beim oeffnen ist nichts ausgewaehlt
    end

    % Dann Closebutton
    hbcp=findobj('Tag',[caller_bc]);
    set(hbcp,'Visible','on');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  case 'UnVis'
    %%% macht die Listbox + Closebutton unsichtbar

    %% bestimmen des zugehrigen Auswahlfensters und Closebuttons
    hcall = gcbo;
    caller = get(hcall,'Tag');
    caller_lbox = strrep(caller,'button_close','listbox');
    caller_parm = strrep(caller,'button_close','button');

    %% deaktivieren der angeforderten Elemente
    hlbox=findobj('Tag',[caller_lbox]);
    set(hlbox,'Visible','off');
    set(hcall,'Visible','off');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  case 'help'
    %%% Es werden die die Standart-Matlab-Hilfetexte angezeigt

    %% Entsprechenden Hilfetext auswhlen und anzeigen
    if ~isempty(select)
      % 'Load' und 'Save' haben eigenen Hilfstext
      if strcmp(funktion(select).name,'load') | strcmp(funktion(select).name,'save') | strcmp(funktion(select).name,'add programme')
        if strcmp(funktion(select).name,'load')
          h=helpdlg(['Load workspace variables from an extern data file.',char(10),'Additionally text lines (e.g. header lines) will be skipped.'],'Help');
        elseif strcmp(funktion(select).name,'save') % (funktion(select).name == 'SAVE')
          h=helpdlg(['Save workspace variables into an extern data file.',char(10),'The file format will be plain ASCII.'],'Help');
        else
	  h=helpdlg(['Adds a new programme into the function list of this MGUI.',char(10),...
	             'The minimal and maximal number of input parameters for this',char(10),...
		     'programme has to be specified. Finally, this changing will', char(10),...
		     'be done in the mgui.rc file.'],'Help');
	end
	set(h,props.msgboxwin),h2=guihandles(h);set(h2.OKButton,props.msgbox)
 	set(h,'Tag','helpdlgbox','HandleVisibility','On');
   else
      % Hilfstext
        eval(['helpwin ', char(funktion(select).name)]);
      end
    else % wenn keine Funktion ausgewhlt wurde
      helpwin mgui;
    end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  case 'close'
    % beendet das Programm
    close(hMF)
    warning on
    % clear all
    tx{1}='Thank you for your blind trust.';
    tx{2}='You really like this?';
    tx{3}='Thanks, that you believe in us.';
    tx{4}='We hope we could satisfy you.';
    tx{5}='Thank you for working with us.';
    tx{6}='Now you should go home.';
    tx{7}='Did you always find us in the WorldWideWeb?';
    tx{8}='Your cat might be hungry.';
    tx{9}='Maybe your Matlab license will be needed by others?';
    tx{10}='Can you imagine, how long we have worked for that?';
    tx{11}='Thank you for your responsiveness.';
    tx{12}='Now ready for publishing?';
    disp(tx{round((length(tx)-1)*rand)+1})
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  case 'winclose'
    % koennte noetig werden, wenn noch irgendwelche settings 
    % zurueckgestellt werden muessen
    set(0,props.root);
    warning on

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  case 'klickreihenfolge'

    %%% Die Klickreihenfolge wird im parm_button_close gespeichert

    %% Bestimmung des Aufrufers
    hlbox = gcbo;

    % die passenden Handel initialisieren
    tmp = strrep(get(hlbox,'Tag'),'listbox','button_close');
    hbcp   = findobj('Tag',[tmp]);

    tmp = strrep(get(hlbox,'Tag'),'listbox','button');
    hparm = findobj('Tag',[tmp]);

    %% Init
    nparm = str2num(strrep(get(gcbo,'Tag'),'listbox_parm',''));
    temp=funktion(select).klicklist;
    if ~isempty(temp), 
       klick_list=temp{nparm}; 
    else
       klick_list = [];
    end
    if isempty(klick_list), klick_list = get(hbcp,'UserData'); end
    klick_akt  = get(hlbox,'Value');
    if isempty(klick_akt), return;, end; % Keine Variable gewhlt
    klick_string = [];

    var_list   = get(hlbox,'UserData');
    if isempty(var_list(1).name), return;, end; % Keine Variable vorhanden

    %% Akualisieren der Klick_list (und anzeigen)
    % Wenn ausversehen mehr als ein Wert gewhlt wurde
    if (size(klick_akt,2) > 1)
      h=errordlg('Choose only one variable.','Parameter selection');
      set(h,props.msgboxwin),h2=guihandles(h);set(h2.OKButton,props.msgbox)
      waitfor(h)
      set(hlbox,'Value',klick_list(1,:));
      return;
    else

    % Aktualisieren
    if isempty(klick_list)
      posi=[];
    else
      posi = find(klick_list(1,:) == klick_akt);
    end

    if(isempty(posi))
      % Einfgen
      klick_list(1,(end +1)) = klick_akt;
    else
      % Lschen
      klick_list(:,posi) = [];
    end

    % Das der Nutzer sein klicken sieht (Listbox)
    set(hlbox,'Value',klick_list(1,:));

    klick_string=make_klick_string(hparm,klick_list,var_list);

       set(hparm,'String',klick_string);
       set(hparm,'ToolTip',klick_string);

      % Speichern der ganzen Mhe
      set(hbcp,'UserData',klick_list);
      funktion(select).klicklist{nparm}=klick_list;
      funktion(select).klickstring{nparm}=klick_string;
      set(hfs,'UserData',funktion)
    end
     
    check_apply

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  case('selectcolumn')
    
    %%% Hier erfolgt die Auswahl der Spalten

    %% Bestimmung des Aufrufers
    hcall = gcbo;
    caller= get(hcall,'Tag');

    % die passenden Handel initialisieren
    tmp   = strrep(caller,'listbox','button_close');
    hbcp   = findobj('Tag',[tmp]);

    hlbox = hcall;

    tmp = strrep(caller,'listbox','button');
    hparm = findobj('Tag',[tmp]);

    %% Init
    nparm = str2num(strrep(get(hlbox,'Tag'),'listbox_parm',''));
    temp=funktion(select).klicklist;
    if ~isempty(temp), klick_list=temp{nparm}; else, klick_list = []; end
    if isempty(klick_list), klick_list = get(hbcp,'UserData'); end
    if isempty(klick_list), return;, end; % Keine Variable ausgewhlt
    var_list   = get(hlbox,'UserData');
    if isempty(var_list(1).name), return;, end; % Keine Variable vorhanden

    klick_string = [];
    VarName = var_list(klick_list(1,end)).name;
    VarValue = evalin('base',VarName);
    [Zeilen Spalten] = size(VarValue); % Begrenzungen ermitteln  

    %% Einlesen der gewnschten Spalten   
    % Zeilenvektor -> wie Spaltenvektor behandeln
    if Zeilen == 1
      [Spalten Zeilen] = size(VarValue); % Vertauschen 
    end

    % Wenn vorhanden, dann soll die alte Auswahl angezeigt werden
    oldcolumns = klick_list([2:end],end);
    oldcolumns = oldcolumns(find(oldcolumns(:))); % Nur gewhltes zeigen
    oldcolumns = cellstr(num2str(oldcolumns')); % Umwandeln zu Textausgabe
    if isempty(oldcolumns)
      oldcolumns = cellstr(' ');
    end

    % Eingabe der Spalten
    set(0,'DefaultUIControlBackgroundColor',props.msgbox.BackgroundColor);
    answer = inputdlg('Use '','' or '':'' or '' '' for selecting the columns.','Multi-column vector',1,oldcolumns);
    set(0,props.root);

    % Wenn etwas eingegeben wurde
    if ~isempty(answer) 
      if strcmp(answer,':') | strcmp(answer,' '), answer='0'; end
      answer3 = str2num(char(answer)); % Umwandel in Zahlen
      answer3(find(answer3 > Spalten)) = []; % Gewhltes <= Max. Spalten

      % Fehler sammeln -> Verarbeitung abbrechen