function freblkUpdateLength(blk,IsExternalSource,InputSignalType,IsHz,Frequencies,NumOfEstPeriod,NumOfSetPeriod,NumPeriods,Order,Ts)
%   Utility function of FRE block

%   Author: R. Chen
%   Copyright 2018 The MathWorks, Inc.

% Display experiment length information
% Note that mask variables such as Frequencies, NumOfEstPeriod,
% NumOfSetPeriod can be empty if they are defined as workspace variables.
% Mask callback code needs to be robust to handle such cases.

maskObj = Simulink.Mask.get(blk);
objectD = maskObj.getDialogControl('DurationLabel');
if IsExternalSource
    if strcmp(InputSignalType,'Sinestream')
        if IsHz
            objectD.Prompt = getString(message('Slcontrol:onlinefre:descSSHzPort'));
        else
            objectD.Prompt = getString(message('Slcontrol:onlinefre:descSSRadianPort'));
        end
    elseif strcmp(InputSignalType,'Superposition')
        if IsHz
            objectD.Prompt = getString(message('Slcontrol:onlinefre:descSIHzPort'));
        else
            objectD.Prompt = getString(message('Slcontrol:onlinefre:descSIRadianPort'));
        end
    else
        if IsHz
            objectD.Prompt = getString(message('Slcontrol:onlinefre:descPRBSHzPort'));
        else
            objectD.Prompt = getString(message('Slcontrol:onlinefre:descPRBSRadianPort'));
        end
    end
else
    if IsHz
        Frequencies = Frequencies*2*pi;
    end
    if strcmp(InputSignalType,'Sinestream')
        len = length(Frequencies);
        if isscalar(NumOfEstPeriod)
            NumOfEstPeriod = NumOfEstPeriod.*ones(len,1);
        else
            NumOfEstPeriod = reshape(NumOfEstPeriod,len,1);
        end
        if isscalar(NumOfSetPeriod)
            NumOfSetPeriod = NumOfSetPeriod.*ones(len,1);
        else
            NumOfSetPeriod = reshape(NumOfSetPeriod,len,1);
        end
        T = reshape(2*pi./Frequencies,len,1);
        if Ts>0
            Tf = sum(T.*(NumOfEstPeriod+NumOfSetPeriod)) + 2*Ts*len;
        else
            Tf = sum(T.*(NumOfEstPeriod+NumOfSetPeriod));
        end
        objectD.Prompt = getString(message('Slcontrol:onlinefre:descSSDialog',num2str(Tf)));
    elseif strcmp(InputSignalType,'Superposition')
        if isempty(Frequencies)
            duration = 0;
        else
            duration = 6*(2*pi/min(Frequencies));
        end
        objectD.Prompt = getString(message('Slcontrol:onlinefre:descSIDialog',num2str(duration)));
    else
        Wmin = min(Frequencies);
        Wmax = max(Frequencies);
        if Ts>0
            duration = Ts*((2^Order-1)*NumPeriods-1);
            [NumPeriodsMax,OrderMin] = frest.frestutils.initializePRBSParameters(Ts,Wmin,Wmax);
            PRBSDurationStr = getString(message('Slcontrol:onlinefre:descPRBSDialog',num2str(duration)));
            PRBSParamStr = getString(message('Slcontrol:onlinefre:descPRBSParam',num2str(NumPeriodsMax),num2str(OrderMin)));
        else
            PRBSDurationStr = getString(message('Slcontrol:onlinefre:descPRBSDialogEmpty'));
            PRBSParamStr = '';
        end            
        objectD.Prompt = [PRBSDurationStr,' ',PRBSParamStr];
    end
end
