function commblkquantenc(block, action, varargin)
% COMMBLKQUANTENC Mask dynamic dialog function for the Quantizing Encoder block

% Copyright 1996-2011 The MathWorks, Inc.

%*********************************************************************
% --- Action switch -- Determines which of the callback functions is called
%*********************************************************************

switch(action)

    %*********************************************************************
    % Function Name:     init
    % Description:       Main initialization code
    % Inputs:            current block
    % Return Values:     none
    %********************************************************************
  case 'init'

    % --- Set Field index numbers
    maskPartition = varargin{1};
    maskCodebook  = varargin{2};

    % --- Ensure that the mask and the underlying blocks are consistent
    setOutDataType(block);

    % Error checking
    partSize = size(maskPartition);
    CodeBkSize = size(maskCodebook);
    if((partSize(1) ~= 1) && (CodeBkSize(1) ~= 1))
        error(message('comm:commblkquantenc:InvalidPartitionAndCodeBookSize'));
    end

    if(partSize(2) ~= CodeBkSize(2)-1)
        error(message('comm:commblkquantenc:InvalidPartitionVecLength'));
    end


    % ---- end of case 'init'

    %----------------------------------------------------------------------
    %   Callback interfaces
    %----------------------------------------------------------------------

  otherwise
    error(message('comm:commblkquantenc:InvalidArg'));

end     % end of switch(action) statement

% ----------------
% --- Subfunctions
% ----------------
%*****************************************************************************
% Function Name:    setOutDataType
% Description:      Modify the mask based on the popup choice for the index
%                     output data type
% Inputs:           current block
% Return Values:    None, although the output data type of the underlying Scalar
%                     Quantizing Encoder is changed as a result
%*****************************************************************************
function setOutDataType(block)

% --- Set Field index numbers
idxIdxDType = dspGetMaskParamIdx(block, 'idxDType');

Vals  = get_param(block, 'maskvalues');

% Control the type cast of the Data Type Conversion block, which then propagates
% to the output of the Comms Quantizing Encoder block
set_param([block '/Data Type Conversion'], 'OutDataTypeStr', Vals{idxIdxDType});

% [EOF] commblkquantenc.m
