if(UpdateCohPlot)
   action =  'CohPlot';
   ii = TSfigInd(gcf); 
   if length(TSc) >= ii
      if ~isempty(TSc{ii})
         h = findobj;
         if(isempty(find(TSc{ii}.hAx==h)))
            UpdateCohPlot = 0;
            return
         else
            nOut = sum(TSc{ii}.CohInd(:,1));
            nIn = sum(TSc{ii}.CohInd(:,2));
            if(nOut == 0 | nIn == 0)
               UpdateCohPlot = 0;
               return
            end
         end
      else
         return
      end
   else
      return        
   end
else
   action = get(gcbo,'Tag');
   ii = get(gcf,'UserData');
   h = gcbo;
end

switch action
   case 'CohCheckBox'
      kk = get(h,'Value');
      kl = get(h,'UserData');
      k = kl(1); l = kl(2);
      if kk==1
         for j=1:3
            TSc{ii}.CohInd(l,j) = 0;
            ud = [ j l];
            set(findobj('Tag','CohCheckBox','UserData',ud),'Value',0);
         end
         TSc{ii}.CohInd(l,k) = 1;
         set(h,'Value',1);
      else
         TSc{ii}.CohInd(l,k) = 0;
      end

   case 'CohPlot'
      FullTS = get(findobj('Tag','FullTS','Parent',TSc{ii}.hFig),'value');
      in = find(TSc{ii}.CohInd(:,2));
      out = find(TSc{ii}.CohInd(:,1));
      given = find(TSc{ii}.CohInd(:,3));
      inCh = [TSd{ii}.ch_id(in,:) TSd{ii}.sta(in,:)];
      outCh = [ TSd{ii}.ch_id(out,:) TSd{ii}.sta(out,:)];
      ctitle1 = ['R^2 : Input Channels: '];
      ctitle2 = [];
      if(length(in) <=2)
         for k = 1:length(in);
            ctitle1 = [ ctitle1 inCh(k,:) ';'];
         end
      else
         for k = 1:2;
            ctitle1 = [ ctitle1 inCh(k,:) ';'];
         end
         for k = 3:length(in);
            ctitle2 = [ ctitle2 inCh(k,:) ';'];
         end
      end
      if (~isempty(given))
         giveCh = [ TSd{ii}.ch_id(given,:) TSd{ii}.sta(given,:)];
         ctitle3 = ['Given channels:'];
         for k = 1:length(given)
            ctitle3 = [ctitle3 giveCh(k,:) ';'];
         end
         if(isempty(ctitle2))
            ctitle = {ctitle1 ctitle3};
         else
            ctitle = {ctitle1 ctitle2 ctitle3};
         end
      else
         if(isempty(ctitle2))
            ctitle = {ctitle1};
         else
            ctitle = {ctitle1 ctitle2};
         end
      end
      lgnd = [];
      for k = 1:length(out)
         lgnd{k} = outCh(k,:);
      end 
      if FullTS
         [dum,npts] = size(TSdata{ii});
         i0 = 1; i1 = npts;
      else
         i0 = TSw{ii}.i0;
         i1 = TSw{ii}.i1;
      end

      NcB = TSc{ii}.NcB;
      [T,R,S] = mCoh(TSdata{ii}(:,i0:i1),in,out,given,NcB); 
      T = T.*TSd1.dt;   % periods in seconds
      axes(TSc{ii}.hAx);
      hold off
      Hlines = semilogx(T,R);
      set(Hlines,'Linewidth',2);
      title(ctitle,'FontWeight','demi');
      xlabel 'Period (s)';
      legH = legend(Hlines,lgnd,'Location','Best');
      set (legH,'Interpreter','none')
      set(TSc{ii}.hAx,'FontWeight','demi',...
	'Ylim',[0,1]);
   case 'NcB'
      NcohBand = str2num(get(h,'String'));
      if NcohBand > 0
         TSc{ii}.NcB=NcohBand;
      else
         set(h,'String',num2str(TSc{ii}.NcB));
      end
end
UpdateCohPlot = 0;
