function outData = commblkseqgentransform(inData)
%COMMBLKSEQGENTRANSFORM Sequence generator blocks transform function
%   Transforms sequence generator blocks from pre R2020a to R2020a and
%   beyond. This is an internal function called by Simulink(R) during model
%   load.

% Copyright 2019 The MathWorks, Inc.

% Get old instance data
instanceData = inData.InstanceData;

oldBlockName = inData.ForwardingTableEntry.('__slOldName__');
sfunBlocks = {'PN', 'Gold', 'Kasami'};
isSfunBlock = contains(oldBlockName, sfunBlocks);

newCount = 1;
frameBased = false;
for p=1:length(instanceData)
  switch instanceData(p).Name
    case 'length'
      if contains(oldBlockName, 'Barker')
        newInstanceData(newCount).Name = 'LengthSimulink'; %#ok<*AGROW>
      else
        newInstanceData(newCount).Name = 'Length';
      end
      newInstanceData(newCount).Value = instanceData(p).Value;
      newCount = newCount + 1;
    case 'spreadFact'
      newInstanceData(newCount).Name = 'SpreadingFactor';
      newInstanceData(newCount).Value = instanceData(p).Value;
      newCount = newCount + 1;
    case 'index'
      newInstanceData(newCount).Name = 'Index';
      newInstanceData(newCount).Value = instanceData(p).Value;
      newCount = newCount + 1;
    case 'ts'
      if isSfunBlock
        newInstanceData(newCount).Name = instanceData(p).Name;
      else
        newInstanceData(newCount).Name = 'SampleTime';
      end
      newInstanceData(newCount).Value = instanceData(p).Value;
      newCount = newCount + 1;
    case 'frameBased'
      if strcmp(instanceData(p).Value, 'on')
        frameBased = true;
      end
    case 'sampPerFrame'
      if isSfunBlock
        newInstanceData(newCount).Name = instanceData(p).Name;
      else
        newInstanceData(newCount).Name = 'SamplesPerFrame';
      end        
      if frameBased
        newInstanceData(newCount).Value = instanceData(p).Value;
      else
        newInstanceData(newCount).Value = '1';
      end
      newCount = newCount + 1;
    case 'outDataType'
      if isSfunBlock
        newInstanceData(newCount).Name = instanceData(p).Name;
      else
        newInstanceData(newCount).Name = 'OutputDataType';
      end        
      newInstanceData(newCount).Value = instanceData(p).Value;
      newCount = newCount + 1;
    otherwise
      newInstanceData(newCount).Name = instanceData(p).Name;
      newInstanceData(newCount).Value = instanceData(p).Value;
      newCount = newCount + 1;
  end
end

outData.NewBlockPath = '';
outData.NewInstanceData = newInstanceData;
