function varargout = commblkfreqoffset(action)
% COMMBLKFREQOFFSET Mask dialog function for Frequency/Phase Offset block.

% Copyright 1996-2012 The MathWorks, Inc.

blkh = gcbh;
freqOffsetFromPort = strcmpi(get_param(blkh,'freqPort'), 'on');

if strcmpi(action,'init')
    % -------------------------------------------
    % Execute mask dialog param callback code to
    % ensure dialog graphical settings up-to-date
    % (avoid potential 'model dirty' flag)
    % -------------------------------------------
    phaseFreqOffsetBlkDialogCallback(blkh, freqOffsetFromPort);
    
    % Form I/O port label info return structure
    s.i1 = 1; s.i1s = '';
    s.i2 = 1; s.i2s = '';
    
    if (freqOffsetFromPort == 1)
        % Two input ports (labels are required)
        s.i1 = 1; s.i1s = 'In';
        s.i2=  2; s.i2s = 'Frq';
    end
    varargout{1} = s;
else
    % Dialog parameter callback (no return value needed)
    phaseFreqOffsetBlkDialogCallback(blkh, freqOffsetFromPort);
end


function phaseFreqOffsetBlkDialogCallback(blkh, freqOffsetFromPort)
% Update dialog widget Visibilities and Enables
vs = get_param(blkh, 'MaskVisibilities');

if(freqOffsetFromPort)
    % Hide 'Frequency offset' dialog parameter
    freqVsEnStr = 'off';
else
    % Show 'Frequency offset' dialog parameter
    freqVsEnStr = 'on';
end

% Only update dialog widget Visibilities/Enables if settings changed
if (~strcmpi(vs{3},freqVsEnStr))
    en    = get_param(blkh, 'MaskEnables');
    en{3} = freqVsEnStr;
    vs{3} = freqVsEnStr;
    set_param(blkh, 'MaskVisibilities', vs, 'MaskEnables', en);
end

% [EOF]
