function varargout= dspblknswit(action,varargin)
% DSPBLKNSWIT DSP Blockset N-Sample Switch block helper function.

% Copyright 1995-2000 The MathWorks, Inc.
% $Revision: 1.10 $ $Date: 2000/06/07 15:50:59 $

if nargin==0, action = 'dynamic'; end

blk     = gcbh;
fullblk = getfullname(blk);
reset   = strcmp(get_param(blk,'Reset'),'on');

switch action
case 'icon'
   % Construct block icon:
   
   % Determine string to display in icon
   % This represents the sample count parameter
   eval_cnt = varargin{1};  % evaluated sample count (could be empty if problem occurred)
   lit_cnt  = varargin{2};   % literal sample count string (exactly what user entered)
   
   if isempty(eval_cnt),
      % Problem probably occurred
      cntstr = lit_cnt;
   else
      % have an evaluated expression
      if ~isnumeric(eval_cnt) | prod(size(eval_cnt))~=1,
         cntstr = '?';
      else
         cntstr = num2str(eval_cnt);
      end
   end
   
   % Draw rest of icon:
   % Construct block icon:
   S=12; t=(0:S)/S*2*pi; a=0.05; xc=a*cos(t); yc=a*sin(t);
   xc4=[xc+.45 NaN xc+.45 NaN xc+.8];
   yc4=[yc+3/4 NaN yc+1/4 NaN yc+.5];
   x=[ .85 1 NaN 0 .4       NaN   0 .4      NaN .75 .525 NaN .595 .525 .55];
   y=[ .5 .5 NaN 3/4 3/4 NaN 1/4 1/4 NaN .5 .7       NaN .7 .7 .61];
   xs=[xc(4:9) xc(9)+[-.03 0 -.01] ]*3.5+.8;
   ys=[yc(4:9) yc(9)+[0.01 0 .03 ] ]*3.5+.5;
   
   % Concat all x/y pairs into a single x and y
   x = [x NaN xs NaN xc4];
   y = [y NaN ys NaN yc4];
   
   if reset, y = y+0.2; end
   
   varargout = {cntstr, x,y};
   
case 'update'
   
   enable_blk = [fullblk '/N-Sample Enable'];
   port_blk = [fullblk '/Rst'];
   
   % Check if 3rd inport block is present:
   port_present = ~isempty(find_system(blk,'searchdepth',1,...
      'followlinks','on','lookundermasks','on','name','Rst'));
   
   if reset,
      % Set the N-Sample Enable block to have reset port and trigger type:
      TriggerType = get_param(blk,'TriggerType');
      set_param(enable_blk,'reset','on', ...
                       'TriggerType',TriggerType);
      
      % Add a 3rd inport:
      if ~port_present,
         add_block('built-in/Inport',port_blk);
         set_param(port_blk,'Position',[20 85 40 105]);
         add_line(fullblk,'Rst/1','N-Sample Enable/1');
      end
      
   else
      if port_present,
         % Remove 3rd inport block:
         delete_line(fullblk,'Rst/1','N-Sample Enable/1');
         delete_block(port_blk);
      end
      set_param(enable_blk,'reset','off');
   end
   
case 'dynamic'
   % Dynamic dialog callback:
   
   mask_enables = get_param(blk,'maskenables');
   if reset,
      mask_enables{3} = 'on';
   else
      mask_enables{3} = 'off';
   end
   set_param(blk,'maskenables',mask_enables);
end

% [EOF] dspblknswit.m


