function [ output_args ] = makePanelConfigAndParams(hFig, thisMapSet )
%MAKEPANELCONFIGANDPARAMS Summary of this function goes here
%   Detailed explanation goes here


    % ------------------------------------------------------------------------------------------------
    debugMsg( 'calling makePanelConfigAndParams()', 1 )
    % ------------------------------------------------------------------------------------------------
    figure(hFig)                    % set current figure 
    % ------------------------------------------------------------------------------------------------
    
%     thisMapSet
    paramData = thisMapSet.para;
    % -----------------------------------------------------------------------------------------------------------------
    colDs = [1 0 0];
    colDt = 'black';
%     colDs = 'rgb(1,0,0)'
    % -----------------------------------------------------------------------------------------------------------------
 %     annotation(hFig,'line',[0.025 0.975],[0.22 0.22],'LineWidth',1,'Color',[.8 .8 .8])
     
    hTitlePan = uipanel('Parent',hFig,'Title',[],...
              'Units','Pixel',...
              'Position',[920 935 500 30],...
              'BackgroundColor','white');
        
    % -----------------------------------------------------------------------------------------------------------------
    % Fix for old calculations, because the Spectroscopy is a new parameter.
    specStr = '';
    if isfield(paramData,'Spectroscopy')
        specStr = paramData.Spectroscopy;
    end    
    hui = uicontrol('Style','text',...
        'Parent',hTitlePan,...
         'String',[' ' specStr],...          % TODO: change to spectroscopy, not yet saved ['Info: '  thisMapSet.para.info ],... 
         'ForegroundColor','black',...
         'FontSize',16,...
         'FontWeight','bold',...
         'Position',[5,-2,100,30],...
         'BackgroundColor','white',...
         'HorizontalAlignment','left');
    set(hui,'fontunits','normalized')
     
    hui = uicontrol('Style','text',...
        'Parent',hTitlePan,...
         'String',paramData.Ion,...
         'ForegroundColor','black',...
         'FontSize',16,...
         'FontWeight','bold',...
         'Position',[110,-2,60,30],...
         'BackgroundColor','white',...
         'HorizontalAlignment','left');
    set(hui,'fontunits','normalized')
    
    hui = uicontrol('Style','text',...
        'Parent',hTitlePan,...
         'String',paramData.config_GS,...
         'ForegroundColor','black',...
         'FontSize',16,...
         'FontWeight','bold',...
         'Position',[170,-2,215,30],...
         'BackgroundColor','white',...
         'HorizontalAlignment','left');
    set(hui,'fontunits','normalized')

         % if Multimaps or join maps is selected, then specify which submap is displayed
        if getValTag('cb_splitMM') == 1  
            infoString = ['GS energy : ' num2str( getValTag('sl_selMultimap') ) ' of ' num2str( get(findobj('Tag','sl_selMultimap'),'max')) ];
        elseif getValTag('cb_joinMaps') == 1 
            infoString = [' Joined GS energies: 1 to ' num2str( getValTag('sl_selMultimap') ) ];
        else
            infoString = ['Lowest ' num2str( get(findobj('Tag','sl_selMultimap'),'max')) ' GS energies.' ];
        end    
        hui = uicontrol('Style','text',...
            'Parent',hTitlePan,...
             'String',infoString,...
             'ForegroundColor','black',...
             'Tag','uiPan_TitleString',...
             'FontSize',16,...
             'FontWeight','bold',...
             'Position',[270,-2,350,30],...
             'BackgroundColor','white',...
             'HorizontalAlignment','left');    
        set(hui,'fontunits','normalized')
         
     % ================================================================

    hAPPan = uipanel('Parent',hFig,'Title','Atomic Parameter',...
              'FontSize',12,...
              'Units','Pixel',...
              'Position',[920 700 500 230],...
              'BackgroundColor','white');

    % --------------------------------
    txtX0_1 = 5;     
    txtY0 = 190;     
    txtY0_soc = 55;     
    txtDY = 20;
    txtgapY = 1;
    
    % SLATER
    fieldNames = fieldnames(paramData);    
    for i = 7:((size(fieldNames,1)-2)/3)-7                  % skipping the first 6 entries, and the last 7
        slaterGS = paramData.(fieldNames{i});
        slaterIS = paramData.(fieldNames{i+18});
        slaterFS = paramData.(fieldNames{i+36});
        
        putUIText_ParamsSlater(hAPPan,txtX0_1,txtY0-(i-7)*(txtDY+txtgapY), fieldNames, {i, i+18, i+36}, slaterGS,slaterIS,slaterFS , ' eV', 'black' )        
    end
    % SOC        
    putUIText_ParamsSOC(hAPPan,txtX0_1,txtY0_soc-txtDY-txtgapY,  ['SOC' fieldNames{7}(4:5) ' :'],['SOC' fieldNames{25}(4:6) ' :'],['SOC' fieldNames{43}(4:6) ' :'], paramData.SOCc_GS,paramData.SOCc_IS,paramData.SOCc_FS , ' eV', 'black' )
    putUIText_ParamsSOC(hAPPan,txtX0_1,txtY0_soc-2*txtDY-txtgapY,['SOC' fieldNames{7}(6:7) ' :'],['SOC' fieldNames{25}(6:8) ' :'],['SOC' fieldNames{43}(6:8) ' :'], paramData.SOCv_GS,paramData.SOCv_IS,paramData.SOCv_FS , ' eV', 'black' )
    % ================================================================
    hCFPan = uipanel('Parent',hFig,'Title','Crystal Field Parameter',...
              'FontSize',12,...
              'Units','Pixel',...
              'Position',[920 545 500 150],...
              'BackgroundColor','white');
 
    txtY0 = 80;      
    % CF
    putUIText_ParamsCF(hCFPan,txtX0_1,txtY0,        'Dq :','','',  paramData.Dq_GS,paramData.Dq_IS,paramData.Dq_FS, ' eV', 'black' )
    putUIText_ParamsCF(hCFPan,txtX0_1,txtY0-txtDY,  'Ds :','','', paramData.Ds_GS,paramData.Ds_IS,paramData.Ds_FS, ' eV', 'black' )
    putUIText_ParamsCF(hCFPan,txtX0_1,txtY0-2*txtDY,'Dt :','','', paramData.Dt_GS,paramData.Dt_IS,paramData.Dt_FS, ' eV', 'black' )
    putUIText_ParamsCF(hCFPan,txtX0_1,txtY0-3*txtDY,'M  :','','', paramData.M_GS,paramData.M_IS,paramData.M_FS,  ' meV', 'black' )
    
    % ------------------------------------------------  
    % TS diagram for 3d
    axes('Parent',hCFPan,'Units','pixels','Position',[250 10 240 120]) ;
    plotDqDtDs( paramData.Dq_GS, paramData.Ds_GS, paramData.Dt_GS );
    % ------------------------------------------------  
    
   
    % ================================================================
    % Broadening Panel
    % --------------------------------
    txtX0_1 = 10;     
    txtX0_2 = 200;     
    txtY0 = 40; 
    txtDY = 20;
    
    hBroadPan = uipanel('Parent',hFig,'Title','Broadenings',...
              'FontSize',12,...
              'Units','Pixel',...
              'Position',[920 460 500 80],...
              'BackgroundColor','white');

    putUIText(hBroadPan,txtX0_1,txtY0,'L IS : ', num2str(paramData.L_IS), ' eV', 'black' )
    putUIText(hBroadPan,txtX0_1+150,txtY0,'L FS : ', num2str(paramData.L_FS), ' eV', 'black' )
%     putUIText(hBroadPan,txtX0_1,txtY0-2*txtDY,'G IS : ', num2str(paramData.G_IS), ' eV', 'black' )
%     putUIText(hBroadPan,txtX0_1,txtY0-3*txtDY,'G FS : ', num2str(paramData.G_FS), ' eV', 'black' )
    % ================================================================================================================================

    
    % ================================================================================================================================    
    if (length(thisMapSet.valuesGS) > 0)
        % ------------------------------------------------  
        figure(hFig)                    % set current figure     
        % ------------------------------------------------  
        % TERMSCHEME with the enrgies
        hTSPan = uipanel('Parent',hFig,'Title',[],...
                  'Units','Pixel',...
                  'Position',[920 10 500 445],...
                  'BackgroundColor','white');
        hTStitle = uicontrol('Style','text',...
                 'Parent',hTSPan,...
                 'String',['Term scheme with the lowest ' num2str(size(thisMapSet.valuesGS,1)) ' energies'],...
                 'ForegroundColor','black',...
                 'FontSize',13,...
                 'FontWeight','bold',...
                 'Position',[100,420,300,20],...
                 'BackgroundColor','white',...
                 'HorizontalAlignment','center');       
        set(hTStitle,'fontunits','normalized')
        % ------------------------------------------------  
        % GS Energy diagram
        axTS_GS = axes('Parent',hTSPan,'Units','Normalized') ;     
        set(axTS_GS,'Position',[0.05 0.05 0.25 0.85],'Box','on')    
        valsGS = thisMapSet.valuesGS(:,1);
        plotTS( valsGS, 1 )
        title('Ground State')

        hGSlab = uibutton('Style','text',...
            'Parent',hTSPan,...
             'String',[paramData.config_GS(1:2) '^{' num2str(str2num(paramData.config_GS(3:4))) '} ' paramData.config_GS(6:7) '^{' num2str(str2num(paramData.config_GS(8:9))) '}' ],...
             'ForegroundColor','black',...
             'FontSize',13,...                      %             'FontWeight','bold',...
             'Position',[45,2,80,20],...           
             'BackgroundColor','white',...
             'HorizontalAlignment','center');
        set(hGSlab,'fontunits','normalized')         
        % ------------------------------------------------  
                 
        % ------------------------------------------------  
        % IS Diagramm
        figure(hFig)                    % set current figure     
        axTS_IS = axes('Parent',hTSPan,'Units','Normalized') ;     
        set(axTS_IS,'Position',[0.375 0.05 0.25 0.85],'Box','on')           % set(axTS_IS,'Position',[0.375 0.02 0.25 0.88],'Box','on')   
        valsIS = thisMapSet.valuesIS(:,1);
        plotTS( valsIS, 0 )
        title('Intermediate State')
        
        hGSlab = uibutton('Style','text',...
            'Parent',hTSPan,...
             'String',[paramData.config_IS(1:2) '^{' num2str(str2num(paramData.config_IS(3:4))) '} ' paramData.config_IS(6:7) '^{' num2str(str2num(paramData.config_IS(8:9))) '}' ],...
             'ForegroundColor','black',...
             'FontSize',13,...                      %             'FontWeight','bold',...
             'Position',[210,2,80,20],...           
             'BackgroundColor','white',...
             'HorizontalAlignment','center');
        set(hGSlab,'fontunits','normalized')         
        % ------------------------------------------------  
                 
        % ------------------------------------------------  
        % FS Diagramm
        figure(hFig)                    % set current figure     
        axTS_FS = axes('Parent',hTSPan,'Units','Normalized') ;     
        set(axTS_FS,'Position',[0.715 0.05 0.25 0.85],'Box','on')    
        valsFS = thisMapSet.valuesFS(:,1);
        plotTS( valsFS, 0 )    
        title('Final State')
        
        hGSlab = uibutton('Style','text',...
            'Parent',hTSPan,...
             'String',[paramData.config_FS(1:2) '^{' num2str(str2num(paramData.config_FS(3:4))) '} ' paramData.config_FS(6:7) '^{' num2str(str2num(paramData.config_FS(8:9))) '}' ],...
             'ForegroundColor','black',...
             'FontSize',13,...                      %             'FontWeight','bold',...
             'Position',[380,2,80,20],...           
             'BackgroundColor','white',...
             'HorizontalAlignment','center');
        set(hGSlab,'fontunits','normalized')         
        % ------------------------------------------------  
                     
        

        % ------------------------------------------------  
    end
    clear valsGS valsIS valsFS thisMapSet paramData axTS_GS axTS_IS axTS_FS
    % ================================================================================================================================
    % ================================================================================================================================
          
          
end

