%implements "custcode" "C"
%function ProcessRTWdata(RTWdata, system) void
%assign rootSystem = ::CompiledModel.System[NumSystems-1]
%assign sysName = GetSystemNameForStartOfComments(system)
%if SimulinkBlockComments
%assign ssNameInComment = "/* %<sysName> */"
%else
%assign ssNameInComment = ""
%endif
%switch Location
%case "Header File"
%case "Model Header"
%if EXISTS("Top")
%<LibHeaderFileCustomCode(ssNameInComment, "header")>
%<LibHeaderFileCustomCode(Top, "header")>
%endif
%if EXISTS("Bottom")
%<LibHeaderFileCustomCode(ssNameInComment, "trailer")>
%<LibHeaderFileCustomCode(Bottom, "trailer")>
%endif
%break
%case "Parameter File"
%if EXISTS("Top")
%<LibPrmFileCustomCode(ssNameInComment, "header")>
%<LibPrmFileCustomCode(Top, "header")>
%endif
%if EXISTS("Bottom")
%<LibPrmFileCustomCode(ssNameInComment, "trailer")>
%<LibPrmFileCustomCode(Bottom, "trailer")>
%endif
%break
%case "Source File"
%case "Model Source"
%if EXISTS("Top")
%<LibSourceFileCustomCode(ssNameInComment, "header")>
%<LibSourceFileCustomCode(Top, "header")>
%endif
%if EXISTS("Bottom")
%<LibSourceFileCustomCode(ssNameInComment + "/n", "trailer")>
%<LibSourceFileCustomCode(Bottom, "trailer")>
%endif
%break
%case "Registration File"
%if EXISTS("Top")
%<LibRegFileCustomCode(ssNameInComment, "header")>
%<LibRegFileCustomCode(Top, "header")>
%endif
%if EXISTS("Bottom")
%<LibRegFileCustomCode(ssNameInComment, "trailer")>
%<LibRegFileCustomCode(Bottom, "trailer")>
%endif
%break
%case "Registration Function"
%if EXISTS("Top")
%<LibMdlRegCustomCode(ssNameInComment, "header")>
%<LibMdlRegCustomCode(Top, "header")>
%endif
%if EXISTS("Middle")
%<LibMdlRegCustomCode(ssNameInComment, "execution")>
%<LibMdlRegCustomCode(Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibMdlRegCustomCode(ssNameInComment, "trailer")>
%<LibMdlRegCustomCode(Bottom, "trailer")>
%endif
%break
%case "Model Start Function"
%if EXISTS("Top")
%<LibMdlStartCustomCode(ssNameInComment, "header")>
%<LibMdlStartCustomCode(Top, "header")>
%endif
%if EXISTS("Middle")
%<LibMdlStartCustomCode(ssNameInComment, "execution")>
%<LibMdlStartCustomCode(Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibMdlStartCustomCode(ssNameInComment, "trailer")>
%<LibMdlStartCustomCode(Bottom, "trailer")>
%endif
%break
%case "Model Initialize Function"
%if EXISTS("Top")
%<LibSystemInitializeCustomCode(rootSystem, ssNameInComment, "header")>
%<LibSystemInitializeCustomCode(rootSystem, Top, "header")>
%endif
%if EXISTS("Middle")
%<LibSystemInitializeCustomCode(rootSystem, ssNameInComment, "execution")>
%<LibSystemInitializeCustomCode(rootSystem, Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibSystemInitializeCustomCode(rootSystem, ssNameInComment, "trailer")>
%<LibSystemInitializeCustomCode(rootSystem, Bottom, "trailer")>
%endif
%break
%case "Model Terminate Function"
%if EXISTS("Top")
%<LibMdlTerminateCustomCode(ssNameInComment, "header")>
%<LibMdlTerminateCustomCode(Top, "header")>
%endif
%if EXISTS("Middle")
%<LibMdlTerminateCustomCode(ssNameInComment, "execution")>
%<LibMdlTerminateCustomCode(Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibMdlTerminateCustomCode(ssNameInComment, "trailer")>
%<LibMdlTerminateCustomCode(Bottom, "trailer")>
%endif
%break
%case "Model Outputs Function"
%if EXISTS("Top")
%<LibSystemOutputCustomCode(rootSystem, ssNameInComment, "header")>
%<LibSystemOutputCustomCode(rootSystem, Top, "header")>
%endif
%if EXISTS("Middle")
%<LibSystemOutputCustomCode(rootSystem, ssNameInComment, "execution")>
%<LibSystemOutputCustomCode(rootSystem, Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibSystemOutputCustomCode(rootSystem, ssNameInComment, "trailer")>
%<LibSystemOutputCustomCode(rootSystem, Bottom, "trailer")>
%endif
%break
%case "Model Update Function"
%if EXISTS("Top")
%<LibSystemUpdateCustomCode(rootSystem, ssNameInComment, "header")>
%<LibSystemUpdateCustomCode(rootSystem, Top, "header")>
%endif
%if EXISTS("Middle")
%<LibSystemUpdateCustomCode(rootSystem, ssNameInComment, "execution")>
%<LibSystemUpdateCustomCode(rootSystem, Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibSystemUpdateCustomCode(rootSystem, ssNameInComment, "trailer")>
%<LibSystemUpdateCustomCode(rootSystem, Bottom, "trailer")>
%endif
%break
%case "Model Derivatives Function"
%if NumContStates < 1
%assign errTxt = "Cannot add custom MdlDerivatives code since " /
"there are no continuous states in the model"
%break
%endif
%if EXISTS("Top")
%<LibSystemDerivativeCustomCode(rootSystem, ssNameInComment , "header")>
%<LibSystemDerivativeCustomCode(rootSystem, Top, "header")>
%endif
%if EXISTS("Middle")
%<LibSystemDerivativeCustomCode(rootSystem, ssNameInComment, "execution")>
%<LibSystemDerivativeCustomCode(rootSystem, Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibSystemDerivativeCustomCode(rootSystem, ssNameInComment, "trailer")>
%<LibSystemDerivativeCustomCode(rootSystem, Bottom, "trailer")>
%endif
%break
%case "Subsystem Start Function"
%case "System Start Function"
%if EXISTS("Top")
%<LibMdlStartCustomCode(ssNameInComment, "header")>
%<LibMdlStartCustomCode(Top, "header")>
%endif
%if EXISTS("Middle")
%<LibMdlStartCustomCode(ssNameInComment, "execution")>
%<LibMdlStartCustomCode(Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibMdlStartCustomCode(ssNameInComment, "trailer")>
%<LibMdlStartCustomCode(Bottom, "trailer")>
%endif
%break
%case "Subsystem Outputs Function"
%case "System Outputs Function"
%if EXISTS("Top")
%<LibSystemOutputCustomCode(system, ssNameInComment, "header")>
%<LibSystemOutputCustomCode(system, Top, "header")>
%endif
%if EXISTS("Middle")
%<LibSystemOutputCustomCode(system, ssNameInComment, "execution")>
%<LibSystemOutputCustomCode(system, Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibSystemOutputCustomCode(system, ssNameInComment, "trailer")>
%<LibSystemOutputCustomCode(system, Bottom, "trailer")>
%endif
%break
%case "Subsystem Update Function"
%case "System Update Function"
%if EXISTS("Top")
%<LibSystemUpdateCustomCode(system, ssNameInComment , "header")>
%<LibSystemUpdateCustomCode(system, Top, "header")>
%endif
%if EXISTS("Middle")
%<LibSystemUpdateCustomCode(system, ssNameInComment , "execution")>
%<LibSystemUpdateCustomCode(system, Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibSystemUpdateCustomCode(system, ssNameInComment, "trailer")>
%<LibSystemUpdateCustomCode(system, Bottom, "trailer")>
%endif
%break
%case "Subsystem Terminate Function"
%case "System Terminate Function"
%if EXISTS("Top")
%<LibMdlTerminateCustomCode(ssNameInComment, "header")>
%<LibMdlTerminateCustomCode(Top, "header")>
%endif
%if EXISTS("Middle")
%<LibMdlTerminateCustomCode(ssNameInComment, "execution")>
%<LibMdlTerminateCustomCode(Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibMdlTerminateCustomCode(ssNameInComment, "trailer")>
%<LibMdlTerminateCustomCode(Bottom, "trailer")>
%endif
%break
%case "Subsystem Initialize Function"
%case "System Initialize Function"
%if EXISTS("system.SystemInitializeFcn") || ...
EXISTS("system.SystemResetFcn")
%if EXISTS("Top")
%<LibSystemInitializeCustomCode(system, ssNameInComment, "header")>
%<LibSystemInitializeCustomCode(system, Top, "header")>
%endif
%if EXISTS("Middle")
%<LibSystemInitializeCustomCode(system, ssNameInComment , "execution")>
%<LibSystemInitializeCustomCode(system, Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibSystemInitializeCustomCode(system, ssNameInComment , "trailer")>
%<LibSystemInitializeCustomCode(system, Bottom, "trailer")>
%endif
%else
%if EXISTS("Top")
%<LibMdlStartCustomCode(ssNameInComment, "header")>
%<LibMdlStartCustomCode(Top, "header")>
%endif
%if EXISTS("Middle")
%<LibMdlStartCustomCode(ssNameInComment, "execution")>
%<LibMdlStartCustomCode(Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibMdlStartCustomCode(ssNameInComment, "trailer")>
%<LibMdlStartCustomCode(Bottom, "trailer")>
%endif
%endif
%break
%case "Subsystem Derivatives Function"
%case "System Derivatives Function"
%if EXISTS("system.DerivativeFcn")
%if EXISTS("Top")
%<LibSystemDerivativeCustomCode(system, ssNameInComment, "header")>
%<LibSystemDerivativeCustomCode(system, Top, "header")>
%endif
%if EXISTS("Middle")
%<LibSystemDerivativeCustomCode(system, ssNameInComment , "execution")>
%<LibSystemDerivativeCustomCode(system, Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibSystemDerivativeCustomCode(system, ssNameInComment , "trailer")>
%<LibSystemDerivativeCustomCode(system, Bottom, "trailer")>
%endif
%else
%assign errTxt = "The System Derivatives custom code block "/
"cannot be placed in %<ssNameInComment> because the system does not "/
"have a derivatives function."
%<LibReportError(errTxt)>
%endif
%break
%case "Subsystem Enable Function"
%case "System Enable Function"
%if EXISTS("system.EnableFcn")
%if EXISTS("Top")
%<LibSystemEnableCustomCode(system, ssNameInComment , "header")>
%<LibSystemEnableCustomCode(system, Top, "header")>
%endif
%if EXISTS("Middle")
%<LibSystemEnableCustomCode(system, ssNameInComment , "execution")>
%<LibSystemEnableCustomCode(system, Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibSystemEnableCustomCode(system, ssNameInComment, "trailer")>
%<LibSystemEnableCustomCode(system, Bottom, "trailer")>
%endif
%else
%assign errTxt = "The System Enable custom code block "/
"cannot be placed in %<ssNameInComment> because the system does not "/
"have an enable function."
%<LibReportError(errTxt)>
%endif
%break
%case "Subsystem Disable Function"
%case "System Disable Function"
%if EXISTS("system.DisableFcn")
%if EXISTS("Top")
%<LibSystemDisableCustomCode(system, ssNameInComment, "header")>
%<LibSystemDisableCustomCode(system, Top, "header")>
%endif
%if EXISTS("Middle")
%<LibSystemDisableCustomCode(system, ssNameInComment , "execution")>
%<LibSystemDisableCustomCode(system, Middle, "execution")>
%endif
%if EXISTS("Bottom")
%<LibSystemDisableCustomCode(system, ssNameInComment , "trailer")>
%<LibSystemDisableCustomCode(system, Bottom, "trailer")>
%endif
%else
%assign errTxt = "The System Disable custom code block " ...
"cannot be placed in %<ssNameInComment> because the system does not " ...
"have a disable function."
%<LibReportError(errTxt)>
%endif
%break
%default
%assign errTxt = "Unknown custom code block: %<Location> " ...
"in %<ssNameInComment>"
%<LibReportError(errTxt)>
%break
%endswitch
%endfunction