function CT_d_frd(action)

% stellt GUI-Interface für "direktes CT-Problem" zur Verfügung
% eigentliche Berrechnung und Animation in "ct_dcalc.m"

% Komponenten :

% 1. Buttons
%               startBnt
%               exportBnt
%               closeBnt
%               invBnt
% 2. Edits
%               phiEdt
%               stepEdt
%               inEdt
%               sizeEdt
%               alphaEdt
%               raynumEdt
%               (Matrix import)
% 3. Checkbox
%               animChk
%               traceChk


% --------------------  BEGIN  --------------------------------------------------------------

play= 1;
stop=-1;

if nargin<1,
    action='initialize';
end;


if strcmp(action,'initialize'),
    oldFigNumber=watchon;

    figNumber=figure( ...
        'Name','CT Simulation - direktes Problem', ...
        'Position',[5 5 792 592], ...
        'NumberTitle','off', ...
        'Visible','off', ...
        'MenuBar', 'none');
    axes( ...
        'Units','normalized', ...
        'Position',[0.05 0.2 0.75 0.75], ...
        'Visible','off');

    axis([-1 1 -1 1]);

% !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    
    clear global; % !!!!!!!!!!!!!!!!!!!!!!!
% !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    

% --------------------  GUI CONTROLS BEGIN --------------------------------------------------------

%====================================

% Information for all BUTTONS

            labelColor=[0.8 0.8 0.8];
            yInitPos=0.90;
            xPos=0.85;
            btnLen=0.10;
            btnWid=0.05;
            
        % Spacing between the button and the next command's label
            spacing=0.025;
            
        %====================================
        
        % The CONSOLE frame
        
            frmBorder=0.02;
            yPos=0.05-frmBorder;
            frmPos=[xPos-frmBorder yPos btnLen+2*frmBorder 0.9+2*frmBorder];
            h=uicontrol( ...
                         'Style','frame', ...
                         'Units','normalized', ...
                         'Position',frmPos, ...
                         'BackgroundColor',[0.50 0.50 0.50]);
    
        %====================================
        
        % The START button
    
            btnNumber=1;
            yPos=0.90-(btnNumber-1)*(btnWid+spacing);
            labelStr='Start';
            cmdStr='start';
            callbackStr='CT_d_frd(''start'');';
      
            btnPos=[xPos yPos-spacing btnLen btnWid];
            startBnt=uicontrol( ...
                                'Style','pushbutton', ...
                                'Units','normalized', ...
                                'Position',btnPos, ...
                                'String',labelStr, ...
                                'Interruptible','yes', ...
                                'Callback',callbackStr);

        %====================================
        
        % The EXPORT button
    
            btnNumber=2;
            yPos=0.90-(btnNumber-1)*(btnWid+spacing);
            labelStr='Export';
            callbackStr='CT_d_frd(''export'');';
    
            btnPos=[xPos yPos-spacing btnLen btnWid];
            exportBnt=uicontrol( ...
                                 'Style','pushbutton', ...
                                 'Units','normalized', ...
                                 'Position',btnPos, ...
                                 'Enable','off', ...
                                 'String',labelStr, ...
                                 'Callback',callbackStr);
                                                                  
        %====================================
        
        % The CLOSE button
        
            labelStr='Close';
            btnNumber=3;
            callbackStr='close(gcf)';
            yPos=0.90-(btnNumber-1)*(btnWid+spacing);    
            btnPos=[xPos yPos-spacing btnLen btnWid];
    
            closeBnt=uicontrol( ...
                                'Style','push', ...
                                'Units','normalized', ...
                                'Position',btnPos, ...
                                'string',labelStr, ...
                                'call',callbackStr);

        %====================================
        
        % The INVERSE button
        
%            labelStr='Solve';
%            btnNumber=4;
%            callbackStr='CT_d_frd(''solve'');';
%            yPos=0.90-(btnNumber-1)*(btnWid+spacing);    
%            btnPos=[xPos yPos-spacing btnLen btnWid];
    
%            invBnt=uicontrol( ...
%                                'Style','push', ...
%                                'Units','normalized', ...
%                                'Position',btnPos, ...
%                                'string',labelStr, ...
%                                'call',callbackStr);
    

% ===================================
        
% Information for all EDITS

            labelColor=[0.8 0.8 0.8];
            backColor=[1 1 1];
            yEdtPos=0.5;    
            xPos=0.85;
            edtLen=0.10;
            edtWid=0.03;
            
        % Spacing between the edits and the next command's label        
            spacing=0.05;
    
        %====================================

        % The SIZE edit
    
            edtNumber=1;
            yPos=yEdtPos-(edtNumber-1)*(edtWid+spacing);
            labelStr='10';

            edtPos=[xPos yPos-spacing edtLen edtWid];
            sizeEdt=uicontrol( ...
                               'Style','edit', ...
                               'Units','normalized', ...
                               'Position',edtPos, ...
                               'String',labelStr, ...
                               'BackgroundColor',backColor, ...
                               'Interruptible','yes');


        % ===================================
    
        % The STEP edit
    
            edtNumber=2;
            yPos=yEdtPos-(edtNumber-1)*(edtWid+spacing);
            labelStr='45';

            edtPos=[xPos yPos-spacing edtLen edtWid];
            stepEdt=uicontrol( ...
                               'Style','edit', ...
                               'Units','normalized', ...
                               'Position',edtPos, ...
                               'String',labelStr, ...
                               'BackgroundColor',backColor, ...
                               'Interruptible','yes');

        % ===================================
    
        % The INTEN edit
    
            edtNumber=3;
            yPos=yEdtPos-(edtNumber-1)*(edtWid+spacing);
            labelStr='100';

            edtPos=[xPos yPos-spacing edtLen edtWid];
            inEdt=uicontrol( ...
                               'Style','edit', ...
                               'Units','normalized', ...
                               'Position',edtPos, ...
                               'String',labelStr, ...
                               'BackgroundColor',backColor, ...
                               'Interruptible','yes');

        % ===================================
    
        % The ALPHA edit
    
            edtNumber=4;
            yPos=yEdtPos-(edtNumber-1)*(edtWid+spacing);
            labelStr='30';

            edtPos=[xPos yPos-spacing edtLen edtWid];
            alphaEdt=uicontrol( ...
                               'Style','edit', ...
                               'Units','normalized', ...
                               'Position',edtPos, ...
                               'String',labelStr, ...
                               'BackgroundColor',backColor, ...
                               'Interruptible','yes');
                               
        % ===================================
    
        % The RAYNUM edit
    
            edtNumber=5;
            yPos=yEdtPos-(edtNumber-1)*(edtWid+spacing);
            labelStr='9';

            edtPos=[xPos yPos-spacing edtLen edtWid];
            raynumEdt=uicontrol( ...
                               'Style','edit', ...
                               'Units','normalized', ...
                               'Position',edtPos, ...
                               'String',labelStr, ...
                               'BackgroundColor',backColor, ...
                               'Interruptible','yes');                               

        % ===================================
    
        % The PHI edit
    
            edtNumber=6;
            yPos=yEdtPos-(edtNumber-1)*(edtWid+spacing);
            labelStr='0';

            edtPos=[xPos yPos-spacing edtLen edtWid];
            phiEdt=uicontrol( ...
                               'Style','edit', ...
                               'Units','normalized', ...
                               'Position',edtPos, ...
                               'String',labelStr, ...
                               'BackgroundColor',backColor, ...
                               'Interruptible','yes');                                                              
        
% ===================================

% Information for all LABELS
        
        YLblPos=0.48;
        LblSize=0.08;
        
        % ===================================
        
        % The SIZE label

            labelNum=1;
            yPos=YLblPos-(labelNum-1)*LblSize;
            labelPos=[xPos yPos 0.1 0.03];
            uicontrol( ...
                       'Style','text', ...
                       'Units','normalized', ...
                       'Position',labelPos, ...
                       'BackgroundColor',[0.50 0.50 0.50], ...
                       'ForegroundColor',[1 1 1], ...
                       'String','Größe');
                       
        % ===================================
        
        % The STEP label

            labelNum=2;                    
            yPos=YLblPos-(labelNum-1)*LblSize;
            labelPos=[xPos yPos 0.1 0.03];
            uicontrol( ...
                       'Style','text', ...
                       'Units','normalized', ...
                       'Position',labelPos, ...
                       'BackgroundColor',[0.50 0.50 0.50], ...
                       'ForegroundColor',[1 1 1], ...
                       'String','Schritte');
    
        %====================================
              
        % The INTEN label

            labelNum=3;
            yPos=YLblPos-(labelNum-1)*LblSize;
            labelPos=[xPos yPos 0.1 0.03];
            uicontrol( ...
                       'Style','text', ...
                       'Units','normalized', ...
                       'Position',labelPos, ...
                       'BackgroundColor',[0.50 0.50 0.50], ...
                       'ForegroundColor',[1 1 1], ...
                       'String','Intensität');
                       
        % ===================================
        
        % The ALPHA label
                       
            labelNum=4;
            yPos=YLblPos-(labelNum-1)*LblSize;
            labelPos=[xPos yPos 0.1 0.03];
            uicontrol( ...
                       'Style','text', ...
                       'Units','normalized', ...
                       'Position',labelPos, ...
                       'BackgroundColor',[0.50 0.50 0.50], ...
                       'ForegroundColor',[1 1 1], ...
                       'String','Spreizung °');   
        
        % ===================================        
        
        % The RAYNUM label

            labelNum=5;
            yPos=YLblPos-(labelNum-1)*LblSize;
            labelPos=[xPos yPos 0.1 0.03];
            uicontrol( ...
                       'Style','text', ...
                       'Units','normalized', ...
                       'Position',labelPos, ...
                       'BackgroundColor',[0.50 0.50 0.50], ...
                       'ForegroundColor',[1 1 1], ...
                       'String','Strahlen');
                       
        % ===================================
        
        % The PHI label
                       
            labelNum=6;
            yPos=YLblPos-(labelNum-1)*LblSize;
            labelPos=[xPos yPos 0.1 0.03];
            uicontrol( ...
                       'Style','text', ...
                       'Units','normalized', ...
                       'Position',labelPos, ...
                       'BackgroundColor',[0.50 0.50 0.50], ...
                       'ForegroundColor',[1 1 1], ...
                       'String','Startwinkel °');
                       
        % ===================================
        
        % The steps label
                       
            labelNum=6;
            labelPos=[0.1 0.05 0.1 0.03];
            stepsLbl= uicontrol( ...
                                 'Style','text', ...
                                 'Units','normalized', ...
                                 'Position',labelPos, ...
                                 'BackgroundColor',[0 0 0], ...
                                 'ForegroundColor',[1 1 1], ...
                                 'String','step 0');
                       
        % ===================================
        
        % The time label
                       
            labelNum=6;
            yPos=YLblPos-(labelNum-1)*LblSize;
            labelPos=[0.4 0.05 0.1 0.03];
            timeLbl = uicontrol( ...
                                 'Style','text', ...
                                 'Units','normalized', ...
                                 'Position',labelPos, ...
                                 'BackgroundColor',[0 0 0], ...
                                 'ForegroundColor',[1 1 1], ...
                                 'String','time 0');

           
% ===================================

% Information for all CHECKBOXES
        
        YChkPos=0.6;
        ChkSize=0.08;
        
        % ===================================
                      
        % The ANIM checkbox

            labelNum=1;   
            labelPos=[xPos YChkPos 0.1 0.03];
            animChk = uicontrol( ...
                                 'Style','checkbox', ...
                                 'Units','normalized', ...
                                 'Position',labelPos, ...
                                 'BackgroundColor',[0.50 0.50 0.50], ...
                                 'ForegroundColor',[1 1 1], ...
                                 'Value', 1, ...
                                 'String','Animation');
        
        %====================================

        % The ANIM checkbox

%            labelNum=1;
%            labelPos=[xPos YChkPos-0.05 0.1 0.03];
%            traceChk = uicontrol( ...
%                                  'Style','checkbox', ...
%                                  'Units','normalized', ...
%                                  'Position',labelPos, ...
%                                  'BackgroundColor',[0.50 0.50 0.50], ...
%                                  'ForegroundColor',[1 1 1], ...
%                                  'String','Verlauf');
        
        %====================================

        
%--------------------  GUI CONTROLS END  ------------------------------------------------------------


% Uncover the figure
    
    hndlList=[startBnt exportBnt closeBnt ...
              phiEdt stepEdt inEdt sizeEdt alphaEdt raynumEdt ...
              animChk ...
              stepsLbl timeLbl ...
             ];
    ctmenu(2,figNumber);
    set(figNumber,'Visible','on', ...
        'UserData',hndlList);

    watchoff(oldFigNumber);
    figure(figNumber);

elseif strcmp(action,'start'),
    clear global;

    axHndl=gca;
    figNumber=gcf;
    hndlList=get(figNumber,'UserData');
    startBnt=hndlList(1);
    exportBnt=hndlList(2);
    closeBnt=hndlList(3);

    phiEdt=hndlList(4); 
    stepEdt=hndlList(5);
    inEdt=hndlList(6);
    sizeEdt=hndlList(7);
    alphaEdt=hndlList(8);
    raynumEdt=hndlList(9);
    
    animChk = hndlList(10);

    set(startBnt,'Enable','off');
    oldFigNumber=watchon;
    
    set(axHndl, ...
        'XLim',[0 40],'YLim',[0 40], ...
        'Userdata',play, ...
        'XTick',[],'YTick',[], ...
        'Drawmode','fast', ...
        'Visible','off', ...
        'NextPlot','add', ...
        'View',[-37.5,30]);

    phiVal = str2num(get(phiEdt, 'String'));
    stepVal = str2num(get(stepEdt, 'String'));
    inVal = str2num(get(inEdt, 'String'));
    sizeVal = str2num(get(sizeEdt, 'String'));
    alphaVal = str2num(get(alphaEdt, 'String'));
    raynumVal = str2num(get(raynumEdt, 'String'));    
    
    set(axHndl, 'Userdata', [get(animChk,'Value')])        
        
    % ======= FUNCTION CALL ======
 
%        global Iout;

%        global L;
%        global kI;

        sizeVal;
        stepVal;
        raynumVal;
        L = sparse(stepVal*raynumVal, 4*sizeVal*sizeVal);
        kI = 0;        
        SL = 0;
              
        Iout = ct_dcalc(phiVal, stepVal, inVal, sizeVal, alphaVal, raynumVal);
        
    % ======= FUNCTION CALL ======
    
    watchoff(oldFigNumber);
    set(startBnt,'Enable','on');
    set(exportBnt,'Enable','on');      

elseif strcmp(action,'export'),

    figNumber=gcf;
    hndlList=get(figNumber,'UserData');

    phiEdt=hndlList(4); 
    stepEdt=hndlList(5);
    inEdt=hndlList(6);
    sizeEdt=hndlList(7);
    alphaEdt=hndlList(8);
    raynumEdt=hndlList(9);

    phiVal = str2num(get(phiEdt, 'String'));
    stepVal = str2num(get(stepEdt, 'String'));
    inVal = str2num(get(inEdt, 'String'));
    sizeVal = str2num(get(sizeEdt, 'String'));
    alphaVal = str2num(get(alphaEdt, 'String'));
    raynumVal = str2num(get(raynumEdt, 'String'));    

    global kI;
    I = kI;
    global L;
    
    s_vec=[phiVal stepVal inVal sizeVal alphaVal raynumVal];

    save 'direct.mat'  I  L s_vec
    disp('calc saved in direct.mat')

elseif strcmp(action,'course'),
    hold off;
    hndlList=get(gcf,'UserData');
    stepsLbl=hndlList(11);
    timeLbl=hndlList(12);
    
    set(stepsLbl, 'String', '');
    set(timeLbl, 'String', '');    

    global SL;
    spy(SL);

elseif strcmp(action,'weak'),
    figNumber=gcf;
    hold off;
    hndlList=get(figNumber,'UserData');

    phiEdt=hndlList(4); 
    stepEdt=hndlList(5);
    inEdt=hndlList(6);
    sizeEdt=hndlList(7);
    alphaEdt=hndlList(8);
    raynumEdt=hndlList(9);

    stepsLbl=hndlList(11);
    timeLbl=hndlList(12);
    
    set(stepsLbl, 'String', '');
    set(timeLbl, 'String', '');    

    phiVal = str2num(get(phiEdt, 'String'));
    stepVal = str2num(get(stepEdt, 'String'));
    inVal = str2num(get(inEdt, 'String'));
    sizeVal = str2num(get(sizeEdt, 'String'));
    alphaVal = str2num(get(alphaEdt, 'String'));
    raynumVal = str2num(get(raynumEdt, 'String'));    

    global kI;    

    plot(1:stepVal, exp(kI((raynumVal+1)/2:raynumVal:stepVal*raynumVal))*100);
    P = axis;
    axis([1 stepVal 0 P(4)]);

    
end;    % if strcmp(action, ...                                           

% --------------------  END  --------------------------------------------------------------
