function [ outData ] = transformOQPSK( inData )
%transformOQPSK is called during loading of pre-R2017b OQPSK
%Modulator blocks in R2017b or later releases. We establish a configuration
%that ensures backwards compatibility.

%   Copyright 2017 The MathWorks, Inc.

outData.NewBlockPath = '';
outData.NewInstanceData = [];

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

if (~ismember('PulseShape', ParameterNames))
    % PulseShape is not present in old link. Block is from before R2017b.
    % Make it load with configuration that is equivalent to pre-R2017b
    % behavior.
    instanceData(end+1).Name = 'pulseShape';
    instanceData(end).Value = 'Custom';
    
    instanceData(end+1).Name = 'sps';
    instanceData(end).Value = '2';
    
    instanceData(end+1).Name = 'num';
    instanceData(end).Value = '[0.7071 0.7071]';
    
    % remove old parameters, so that old models do not load with warnings:
    oldModProps = {'outUDDataType', 'outWordLen', 'outFracLenMode', ...
          'outFracLen', 'outDataTypeStr', 'outLastDataTypeStr'};
    oldDemodProps = {'outDtype1', 'derotateFactorDTMode', 'derotateFactorWordLen', ...
          'derotateFactorDataTypeStr', 'derotateFactorLastDataTypeStr', 'accumMode', 'accumWordLength', ...
          'accumFracLength', 'accumDataTypeStr', 'roundingMode', 'overflowMode', 'OvFlMode', ...
          'accumLastDataTypeStr', 'OvFlModeLastStrValue', 'mappingInputMode', 'mappingInputWordLength', ...
          'mappingInputFracLength', 'mappingInputDataTypeStr', 'mappingInputLastDataTypeStr'};
    pos = [];
    for idx = 1:length(instanceData)
      
      % in parallel, change dropped data types to supported ones:
      if strcmp(instanceData(idx).Name, 'outDtype') % Modulator
        if ~any(strcmp(instanceData(idx).Value, {'double', 'single'}))
          instanceData(idx).Value = 'double';
        end
      end
      
      if strcmp(instanceData(idx).Name, 'outDtype2') % Demodulator
        if contains(instanceData(idx).Value(1:4), 'int')
          instanceData(idx).Value = 'uint8'; % map all int types to uint8
        elseif ~any(strcmp(instanceData(idx).Value, {'double', 'single'}))
          instanceData(idx).Value = 'double';
        end
      end
      
      if strcmp(instanceData(idx).Name, 'RateOptions') && strcmp(instanceData(idx).Value, 'Inherit from input (this choice will be removed - see release notes)')
        instanceData(idx).Value = 'Enforce single-rate processing';
      end
      
      % mark for removal:
      if any(strcmp(instanceData(idx).Name, [oldModProps oldDemodProps]))
        pos = [pos idx]; %#ok<AGROW>
      end
    end
    instanceData(pos) = [];
end

outData.NewInstanceData = instanceData;

end

