function [ outData ] = transformDiscreteEyeDiagramBlock( inData )
%transformDiscreteEyeDiagramBlock is called during automatic replacement of the 
% "Discrete-Time Eye Diagram Scope" block with the "Eye Diagram" block in the commsink2 and 
% commviewers2 libraries. Automatic block replacement carries over the old
% property values. The only difference regards the SampleOffset propery 
% which is adjusted accordingly:

% Specifically the display of the old block (<=14a) is driven by the following offset:
% >> user-specified-offset + round(SamplesPerSymbol/2)
% However, the display of the new block (>= 14b) is only driven by the user specified offset, 
% without the extra half symbol.

% This function automatically adjusts the offset value saved <= 14a, so
% that (>=14b) users attain the same display without any adjustements in their offset property.

%   Copyright 2014-2023 The MathWorks, Inc.

instanceData = inData.InstanceData;
outData.NewBlockPath = '';
outData.NewInstanceData = instanceData;

% Get the field type 'Name' from instanceData
[ParameterNames{1:length(instanceData)}] = instanceData.Name;

offsetIdx       = logical(strcmp(ParameterNames, 'offsetEye'));
[oldOffsetValue,  success(1)] = str2num(instanceData(offsetIdx).Value); %#ok<*ST2NM>

spsIdx          = logical(strcmp(ParameterNames, 'sampPerSymb'));
[sampPerSymb,     success(2)] = str2num(instanceData(spsIdx).Value);

sptrIdx         = logical(strcmp(ParameterNames, 'symbPerTrace'));
[symbPerTrace,    success(3)] = str2num(instanceData(sptrIdx).Value);

if ~all(success)
  return;
end

% remove the extra half-a-symbol offset:

% old value ranged in [0, SamplesPerSymbol*SymbolsPerTrace], so does the new value since 15a
adjustedOffsetValue = oldOffsetValue + round(sampPerSymb/2);
if adjustedOffsetValue >= sampPerSymb * symbPerTrace % wrap around
    adjustedOffsetValue = adjustedOffsetValue - sampPerSymb * symbPerTrace;
end

outData.NewInstanceData(offsetIdx).Value = num2str(adjustedOffsetValue);

end

