function outData = commMNLTransform(inData)
    %COMMMNLTRANSFORM Transformation function from the subsystem-based
    %Memoryless Nonlinearity block to either the System object-based
    %Memoryless Nonlinearity block or the same subsystem-based Memoryless
    %Nonlinearity block that lives in commobslib library.

    % Copyright 2022 The MathWorks, Inc.

    InstanceData = inData.InstanceData;
    oldBlockParams = {InstanceData.Name};
    newInstanceData = InstanceData;
    newBlockPath = sprintf('commrflib2/Memoryless\nNonlinearity');

    modelIdx = strcmp(oldBlockParams, 'model_select');
    modelParam = newInstanceData(modelIdx);
    if ~isempty(modelParam)
        switch modelParam.Value
            case {'Hyperbolic tangent', 'Ghorbani model'}
                newBlockPath = 'commobslib/Memoryless Nonlinearity';
            case 'Cubic polynomial'
                % Check AM/PM conversion value
                ampmIdx = strcmp(oldBlockParams, 'am2pm');
                ampmParam = newInstanceData(ampmIdx);
                if str2double(ampmParam.Value) ~= 0
                    newBlockPath = sprintf('commobslib/Memoryless\nNonlinearity');
                end
        end
    end

    if strncmp(newBlockPath, 'commrf', 6)
        % Transform & remove parameters

        for p=length(oldBlockParams):-1:1
            switch oldBlockParams{p}
                case 'model_select'
                    newInstanceData(p).Name = 'Model';
                    switch newInstanceData(p).Value
                        case 'Rapp model'
                            % 'Rapp model' is called 'Modified Rapp'. It
                            % has two additional parameters - add them with
                            % default values.
                            newInstanceData(p).Value = 'Modified Rapp';
                            newInstanceData(end+1) = newInstanceData(p); %#ok<AGROW>
                            newInstanceData(end).Name = 'PhaseGainRadian';
                            newInstanceData(end).Value = num2str(0);
                            newInstanceData(end+1) = newInstanceData(p); %#ok<AGROW>
                            newInstanceData(end).Name = 'PhaseSaturation';
                            newInstanceData(end).Value = num2str(1);
                        case 'Saleh model'
                            % 'Saleh model' is called 'Saleh'
                            newInstanceData(p).Value = 'Saleh';
                    end
                case 'linGaindB'
                    % linGaindB was used for all the modes. The new block
                    % uses LinearGainDB for Cubic polynomial and
                    % MagnitudeGainDB for Modified Rapp.
                    newInstanceData(p).Name = 'LinearGainDB';
                    newInstanceData(end+1) = newInstanceData(p); %#ok<AGROW>
                    newInstanceData(end).Name = 'MagnitudeGainDB';
                case 'GindB'
                    newInstanceData(p).Name = 'InputScaleDB';
                case 'iip3'
                    newInstanceData(p).Name = 'IIP3';
                case {'am2pm', 'LPwrLimAMPM', 'UPwrLimAMPM', 'x', 'y'}
                    % Remove the parameters related to AM/PM conversion in
                    % Cubic polynomial & Ghorbani (not supported anymore)
                    newInstanceData(p) = [];
                case 'amam'
                    newInstanceData(p).Name = 'AmAmParameters';
                case 'ampm'
                    newInstanceData(p).Name = 'AmPmParameters';
                case 'p'
                    newInstanceData(p).Name = 'MagnitudeSmooth';
                case 'GoutdB'
                    newInstanceData(p).Name = 'OutputScaleDB';
                case 'vsat'
                    newInstanceData(p).Name = 'Vsat';
            end
        end
    end

    outData.NewBlockPath = newBlockPath;
    outData.NewInstanceData = newInstanceData;
end
