function updcorrplt(action)

% This function plots [wvn, intensity] pairs info of 2D-COS axes
% last revision: Apr 02, 2023 (Peter Lasch)
% Copyright Peter Lasch 2000-2023. CC-BY-NC license

if nargin ~= 1
   action                           = 1;
end

try
h.Axis.Corr                         = findobj('Tag','AxisCorrelation');
h.Axis.Trace                        = findobj(gcf,'Tag','AxisCspectra');
h.Figure.CorrMat                    = findobj('Tag','CorrmatrixWindow');
h.Figure.Trace                      = findobj(gcf,'Tag','1DtracePlot');
h.Text.CursorPos                    = findobj('Tag','ActCursorPos');
h.Text.CorrCoeff                    = findobj('Tag','ActCorrCoeff');
h.Text.TrcWvnPos                    = findobj(gcf,'Tag','TraceWvnPos');

if action == 0 % rm text
    set(h.Text.CursorPos,'String','');
    set(h.Text.CorrCoeff,'String','');
elseif action == 1
    wvintstrng                      = 'Corrcoeff: ';
    updxy(h,wvintstrng);
elseif isempty(find([2 3 4]==action,1)) == 0
    wvintstrng                      = '2D-COS (Pareto): ';
    updxy(h,wvintstrng);
elseif action == 5
    wvintstrng                      = 'Synchr. (stats): ';
    updxy(h,wvintstrng)
elseif action == 6
    wvintstrng                      = 'Asynchr. (stats): ';
    updxy(h,wvintstrng)
elseif action == 7
    wvintstrng                      = 'disrelation: ';
    updxy(h,wvintstrng)
elseif action == 8
    wvintstrng                      = 'Synchr. (fft): ';
    updxy(h,wvintstrng)
elseif action == 9
    wvintstrng                      = 'Asynchr. (fft): ';
    updxy(h,wvintstrng)
elseif action > 9
    updtrc(h)
end

catch
    set(h.Text.CursorPos,'String', '' );
    set(h.Text.CorrCoeff,'String', '');
end

%% ************************************************************************
function updxy(h,wvintstrng) % plot [x,y] coordinates and 2D-COS intensity
% *************************************************************************

pts                                 = round(get(h.Axis.Corr,'CurrentPoint'));
ZData                               = get(findobj(h.Axis.Corr,'Type','Surface'),'ZData');
ZData                               = ZData';
[szx,szy]                           = size(ZData);
XLim                                = get(h.Axis.Corr,'XLim');
YLim                                = get(h.Axis.Corr,'YLim');

if pts(1,1) >= XLim(1) && pts(1,1) <= XLim(2) &&  pts(2,2) >= YLim(1) && pts(2,2) <= YLim(2)
   indx                             = round((pts(1,1)-XLim(1))/(XLim(2)-XLim(1)) * szx);
   indy                             = round((pts(2,2)-YLim(1))/(YLim(2)-YLim(1)) * szy);
   ActZVal                          = ZData(indx,indy);
   printstrA                        = ['actual [x,y] coordinates: ' num2str(pts(1,1)) ' x ' num2str(pts(2,2))];
   printstrB                        = [wvintstrng num2str(ActZVal)];
   set(h.Text.CursorPos,'String',printstrA);
   set(h.Text.CorrCoeff,'String',printstrB);
end

%% ************************************************************************
function updtrc(h)     % update info of 1D-COS slice plots
% *************************************************************************

pts                                 = round(get(h.Axis.Trace,'CurrentPoint'));
set(h.Text.TrcWvnPos,'String',['wavenumber position: ' num2str(pts(1,1)) ' [1/cm]' ]);