%if EXISTS("_FCNIOLIB_") == 0
%assign _FCNIOLIB_ = 1
%function SLibGetElementIdxFromVarGroup(aVarGroupIdx, aElementSrcOrIndex) void
%if TYPE(aElementSrcOrIndex) == "String"
%assign numElement = SLibVarGroupNumElements(aVarGroupIdx)
%foreach mIdx = numElement
%if SLibVarGroupElementSource(aVarGroupIdx, mIdx) == aElementSrcOrIndex
%return mIdx
%endif
%endforeach
%return -1
%endif
%assert TYPE(aElementSrcOrIndex) == "Number"
%return aElementSrcOrIndex
%endfunction
%function SLibIsBlockInstanceAccessedViaPointerInSelf(aBlock)
%assign childSelfCoderGroupIndex = SLibGetChildSelfCoderGroupIndex(aBlock)
%if childSelfCoderGroupIndex != -1
%assign blockInterface = GetModelrefInterface(aBlock)
%assign childCoderGroupsRecord = blockInterface.CoderDataGroups.CoderDataGroup
%assign numChildCoderGroups = SIZE(childCoderGroupsRecord, 1)
%if numChildCoderGroups > 1
%assign childSelfCoderGroup = childCoderGroupsRecord[childSelfCoderGroupIndex]
%else
%assign childSelfCoderGroup = childCoderGroupsRecord
%endif
%assign groupIndexWithChildSelfNameInCurrentModel = ...
SLibCoderDataGroupIndex(childSelfCoderGroup.Name)
%assign childSelfGroupNameRegisteredInCurrentModel = ...
groupIndexWithChildSelfNameInCurrentModel != -1
%assign childSelfGroupIsInParent = ...
ISFIELD(childSelfCoderGroup, "AsStructure") && ...
childSelfCoderGroup.AsStructure == "InParent"
%if SLibGetDoesSelfHasCoderDataGroup()
%assign currentModelSelfGroup = ::CompiledModel.CoderDataGroup[SLibGetSelfCoderDataGroupIndex()]
%assign childAndParentHaveDifferentSelfGroups = ...
currentModelSelfGroup.Name != childSelfCoderGroup.Name
%if childSelfGroupIsInParent && ...
childSelfGroupNameRegisteredInCurrentModel && ...
childAndParentHaveDifferentSelfGroups
%return TLC_TRUE
%endif
%endif
%endif
%return TLC_FALSE
%endfunction
%function SLibGetPathToInstanceFromSelf(aBlock)
%assign path = ""
%assign childSelfCoderGroupIndex = SLibGetChildSelfCoderGroupIndex(aBlock)
%assign blockInterface = GetModelrefInterface(aBlock)
%assign childCoderGroupsRecord = blockInterface.CoderDataGroups.CoderDataGroup
%assign numChildCoderGroups = SIZE(childCoderGroupsRecord, 1)
%if numChildCoderGroups > 1
%assign childSelfCoderGroup = childCoderGroupsRecord[childSelfCoderGroupIndex]
%else
%assign childSelfCoderGroup = childCoderGroupsRecord
%endif
%assign selfVarGroup = ::CompiledModel.VarGroups.VarGroup[SLibGetSelfVarGroupIndex()]
%foreach vgElementId = selfVarGroup.NumVarGroupElements
%assign vgElement = selfVarGroup.VarGroupElements[vgElementId]
%assign idNumElement = IDNUM(vgElement)
%if idNumElement[0] == "RCDG"
%assign coderGroupIndex = idNumElement[1]
%assign coderGroup = ::CompiledModel.CoderDataGroup[coderGroupIndex]
%if coderGroup.Name == childSelfCoderGroup.Name
%assign path = tSimStruct + "->" + LibCGTypeMemberName(selfVarGroup.CGTypeIdx, vgElementId) + "->" + aBlock.Identifier
%break
%endif
%endif
%endforeach
%return path
%endfunction
%function SLibGetFieldPointerFromSelf(eleNameOrIndex,addTypeCast) void
%if !SLibGetUseRTMcgType() || !SLibGetDoesSelfHasCoderDataGroup()
%return ""
%endif
%assign retStr = ""
%assert SLibGetDoesSelfHasCoderDataGroup()
%assign selfVarGroupIdx = SLibGetSelfVarGroupIndex()
%assign elIdx = SLibGetElementIdxFromVarGroup(selfVarGroupIdx, eleNameOrIndex)
%assign ptr = ""
%if elIdx > -1
%if SLibVarGroupIsStruct(selfVarGroupIdx)
%if IsModelRefScalableBuild()
%assign selfVar = IsModelReferenceSimTarget() ? FcnGetSFcnDWorkRTM() : ::CompiledModel.GlobalScope.tRTM
%else
%assign selfVar = tSimStruct
%if SLibSynthesizedRTM()
%<SLibCG_AccessRTM()>
%endif
%endif
%assign deref = IsModelRefScalableBuild() ? "." : "->"
%assign retStr = selfVar + deref
%endif
%assign retStr = retStr + SLibVarGroupElementName(selfVarGroupIdx, elIdx)
%assign typeIdx = SLibVarGroupElementType(selfVarGroupIdx, elIdx)
%if !LibCGTypeIsPointer(typeIdx)
%assign ptr = "*"
%assign retStr = "&("+ retStr +")"
%endif
%if addTypeCast
%assign retStr = "((" + SLibGetTypeNameFromCGType(typeIdx) + ptr + ")" + retStr + ")"
%endif
%endif
%return retStr
%endfunction
%function SLibGetBlockIOPointerFromRTM(addTypeCast)
%if Accelerator
%assign retStr = RTMuGet("ModelBlockIO")
%elseif CodeFormat == "S-Function"
%assign retStr = RTMGet("LocalBlockIO")
%else
%assign retStr = RTMuGet("BlockIO")
%endif
%if addTypeCast
%assign blockIOCast = FcnRewriteCast("(%<::tBlockIOType> *) %<retStr>")
%assign retStr = "(%<blockIOCast>)"
%endif
%return retStr
%endfunction
%function SLibGetBlockIOStruct(addTypeCast) void
%if ::CompiledModel.HasSimStructVars == 1
%return SLibGetBlockIOPointerFromRTM(addTypeCast)
%elseif IsModelRefScalableBuild() && !GenerateClassInterface
%assign baseSystem = ::CompiledModel.System[GetBaseSystemIdx()]
%return FcnSysVarGroupNonreusedName(baseSystem, "BlockIO")
%else
%return ::tBlockIO
%endif
%endfunction
%function LibGetBlockIOStruct() void
%return SLibGetBlockIOStruct(TLC_TRUE)
%endfunction
%function SLibGetConstBlockIOPointerFromRTM() void
%return "((%<::tConstBlockIOType> *) %<RTMGet("ConstBlockIO")>)"
%endfunction
%function SLibGetSelfPointerFromRTM() void
%return tSimStruct
%endfunction
%function SLibGetSelfStruct(addTypeCast) void
%return tSimStruct
%endfunction
%function LibGetSelfStruct() void
%return SLibGetSelfStruct(TLC_TRUE)
%endfunction
%function LibGetConstBlockIOStruct() void
%if isGRTMalloc
%return SLibGetConstBlockIOPointerFromRTM()
%else
%return ::tConstBlockIOStruct
%endif
%endfunction
%function SLibGetExternalInputStructHelper(addTypeCast,isCallSite, cross, typeName, varName) void
%assign retStr = ""
%if isCallSite && ...
(::CompiledModel.HasSimStructVars || ...
((cross || ThisSubsysCross) && MultiInstanceERTCode && !GenerateClassInterface))
%if UsingMalloc || Accelerator || ...
((cross || ThisSubsysCross) && MultiInstanceERTCode && !GenerateClassInterface)
%assign retStr = RTMGet("U")
%elseif CodeFormat == "S-Function"
%assign retStr = RTMGetIdxed("InputPortSignalPtrs", 0)
%else
%assign retStr = ::tInput
%endif
%assert(!WHITE_SPACE(retStr))
%if addTypeCast
%assign retStr = "((%<typeName> *) %<retStr>)"
%endif
%else
%assign retStr = varName
%endif
%return retStr
%endfunction
%function SLibGetExternalInputStructForRecord(extInp) void
%assign coderGroupId = ...
SLibGetCoderGroupIdForDataRecord(extInp)
%if coderGroupId != -1
%assign coderGroup = ::CompiledModel.CoderDataGroup[coderGroupId]
%assign typeName = SLibCoderDataGroupType(coderGroup)
%assign varName = SLibCoderDataGroupInstance(coderGroup)
%return SLibGetExternalInputStructHelper(TLC_TRUE, TLC_FALSE, TLC_FALSE, typeName, varName)
%else
%return LibGetExternalInputStruct()
%endif
%endfunction
%function SLibGetExternalInputStruct(addTypeCast,isCallSite,cross) void
%assign typeName = ::tInputType
%assign varName = ::tInput
%return SLibGetExternalInputStructHelper(addTypeCast,isCallSite,cross, typeName, varName)
%endfunction
%function LibGetExternalInputStruct() void
%return SLibGetExternalInputStruct(TLC_TRUE, TLC_FALSE, TLC_FALSE)
%endfunction
%function SLibGetExternalOutputStructHelper(addTypeCast, isCallSite, cross, typeName, varName) void
%assign retStr = ""
%if isCallSite && ...
(::CompiledModel.HasSimStructVars || ...
((cross || ThisSubsysCross) && MultiInstanceERTCode && !GenerateClassInterface))
%assert(!Accelerator)
%if UsingMalloc || ((cross || ThisSubsysCross) && MultiInstanceERTCode && !GenerateClassInterface)
%assign retStr = RTMGet("Y")
%elseif CodeFormat == "S-Function"
%assign retStr = RTMGetIdxed("OutputPortSignal", 0)
%else
%assign retStr = varName
%endif
%assert(!WHITE_SPACE(retStr))
%if addTypeCast
%assign retStr = "((%<typeName> *) %<retStr>)"
%endif
%else
%assign retStr = varName
%endif
%return retStr
%endfunction
%function SLibGetExternalOutputStructForRecord(extOutp) void
%assign coderGroupId = ...
SLibGetCoderGroupIdForDataRecord(extOutp)
%if coderGroupId != -1
%assign coderGroup = ::CompiledModel.CoderDataGroup[coderGroupId]
%assign typeName = SLibCoderDataGroupType(coderGroup)
%assign varName = SLibCoderDataGroupInstance(coderGroup)
%return SLibGetExternalOutputStructHelper(TLC_TRUE, TLC_FALSE, TLC_FALSE, typeName, varName)
%else
%return LibGetExternalOutputStruct()
%endif
%endfunction
%function SLibGetExternalOutputStruct(addTypeCast,isCallSite,cross) void
%assign typeName = ::tOutputType
%assign varName = ::tOutput
%return SLibGetExternalOutputStructHelper(addTypeCast,isCallSite,cross, typeName, varName)
%endfunction
%function LibGetExternalOutputStruct() void
%return SLibGetExternalOutputStruct(TLC_TRUE, TLC_FALSE, TLC_FALSE)
%endfunction
%function SLibGetContStatesPointerFromRTM(addTypeCast) void
%assign retStr = RTMGet("ContStates")
%if addTypeCast
%assign retStr = "((%<::tContStateType> *) %<retStr>)"
%endif
%return retStr
%endfunction
%function SLibGetContinuousStateStruct(addTypeCast) void
%if ::CompiledModel.HasSimStructVars == 1
%return SLibGetContStatesPointerFromRTM(addTypeCast)
%else
%return ::tContState
%endif
%endfunction
%function LibGetContinuousStateStruct() void
%return SLibGetContinuousStateStruct(TLC_TRUE)
%endfunction
%function SLibGetPeriodicStateIndicesPtrFromRTM(addTypeCast) void
%assign retStr = RTMGet("PeriodicContStateIndices")
%if addTypeCast
%assign retStr = "((%<::tPeriodicStateIndType>*) %<retStr>)"
%endif
%return retStr
%endfunction
%function LibGetPeriodicContStateIndices() Output
%assert (!IsModelReferenceTarget())
%return tPeriodicStateInd
%endfunction
%function SLibGetPeriodicStateRangesPtrFromRTM(addTypeCast) void
%assign retStr = RTMGet("PeriodicContStateRanges")
%if addTypeCast
%assign retStr = "((%<tPeriodicStateRngType>*) %<retStr>)"
%endif
%return retStr
%endfunction
%function LibGetPeriodicContStateRanges() Output
%assert (!IsModelReferenceTarget())
%return tPeriodicStateRng
%endfunction
%function SLibGetContStateDerivativesStructFromRTM() void
%if SLibIsPartitionGrouping()
%assert EXISTS(::GlobalCurrentPID)
%if SLibPartitionNeedContFcnDecl(::GlobalCurrentPID)
%return "((%<::tXdotType> *) %<RTMGet("dX")>)"
%else
%return SLibPartitionGetContStateDerivativeStruct()
%endif
%else
%return "((%<::tXdotType> *) %<RTMGet("dX")>)"
%endif
%endfunction
%function LibGetDotContinuousStateStruct() void
%assign isDeriv = (::BlockFcn == "Derivative")
%assign isForcingFunction = (::BlockFcn == "ForcingFunction")
%if ::CompiledModel.HasSimStructVars == 1 || isDeriv || isForcingFunction
%return SLibGetContStateDerivativesStructFromRTM()
%else
%return ::tXdot
%endif
%endfunction
%function SLibGetContStateDisabledStructFromRTM() void
%return "((%<::tXdisType> *) %<RTMGet("ContStateDisabled")>)"
%endfunction
%function LibGetContinuousStateDisabledStruct() void
%assign isDeriv = (::BlockFcn == "Derivative")
%assign isForcingFunction = (::BlockFcn == "ForcingFunction")
%if ::CompiledModel.HasSimStructVars == 1 || ::isRSimWithSolverModule || isDeriv || isForcingFunction
%return SLibGetContStateDisabledStructFromRTM()
%else
%return ::tXdis
%endif
%endfunction
%function SLibGetContStatesAbsoluteToleranceStructFromRTM() void
%return "((%<::tXAbsTolType> *) %<RTMGet("AbsTolVector")>)"
%endfunction
%function LibGetContinuousStateAbsoluteToleranceStruct() void
%if ::CompiledModel.HasSimStructVars == 1 || ::isRSimWithSolverModule
%return SLibGetContStatesAbsoluteToleranceStructFromRTM()
%else
%return ::tXAbsTol
%endif
%endfunction
%function SLibGetContStatesPerturbMinStructFromRTM() void
%return "((%<::tXPerturbMinType> *) %<RTMGet("JacobianPerturbationBoundsMinVec")>)"
%endfunction
%function LibGetContinuousStatePerturbMinStruct() void
%if ::CompiledModel.HasSimStructVars == 1 || ::isRSimWithSolverModule
%return SLibGetContStatesPerturbMinStructFromRTM()
%else
%return ::tXPerturbMin
%endif
%endfunction
%function SLibGetContStatesPerturbMaxStructFromRTM() void
%return "((%<::tXPerturbMaxType> *) %<RTMGet("JacobianPerturbationBoundsMaxVec")>)"
%endfunction
%function LibGetContinuousStatePerturbMaxStruct() void
%if ::CompiledModel.HasSimStructVars == 1 || ::isRSimWithSolverModule
%return SLibGetContStatesPerturbMaxStructFromRTM()
%else
%return ::tXPerturbMax
%endif
%endfunction
%function LibGetMassMatrixGlobal() Output
%if ::CompiledModel.HasSimStructVars == 1
%return ""
%elseif SLibIsPartitionGrouping() && ...
EXISTS(::GlobalCurrentPID) && ...
TYPE(::GlobalCurrentPID) == "Number" && ...
::GlobalCurrentPID >= 0
%return SLibPartitionGetMassMatricesVarName(::GlobalCurrentPID)
%else
%return ::tMassMatrixGlobal
%endif
%endfunction
%function LibGetMassMatrixGlobalIr() Output
%assert (!IsModelReferenceTarget())
%if Accelerator
%return RTMGet("MassMatrixIr")
%else
%return LibGetMassMatrixGlobal()+".ir"
%endif
%endfunction
%function LibGetMassMatrixGlobalJc() Output
%assert (!IsModelReferenceTarget())
%if Accelerator
%return RTMGet("MassMatrixJc")
%else
%return LibGetMassMatrixGlobal()+".jc"
%endif
%endfunction
%function LibGetMassMatrixGlobalPr() Output
%if IsModelReferenceTarget()
%return RTMGet("MassMatrixBasePr")
%elseif Accelerator
%return RTMGet("MassMatrixPr")
%else
%return LibGetMassMatrixGlobal()+".pr"
%endif
%endfunction
%function SLibGetDWorkPointerFromRTM(addTypeCast) void
%assign retStr = RTMGet("RootDWork")
%if addTypeCast
%assign dworkCast = FcnRewriteCast("(%<::tDWorkType> *) %<retStr>")
%assign retStr = "(%<dworkCast>)"
%endif
%return retStr
%endfunction
%function SLibGetCoderDataGroupPointerFromRTM(group, addTypeCast) void
%assign rootSystem = ::CompiledModel.System[NumSystems-1]
%assign baseSystem = ::CompiledModel.System[GetBaseSystemIdx()]
%assign fieldName = "HasCoderDataGroup" + group.Name + "Arg"
%assign baseSystem.%<fieldName> = TLC_TRUE
%assign varGroupIndex = SLibGetRootVarGroupIdxForCoderGroup(group)
%if SLibAccessViaPointerInSelf(group)
%assign elem = "RCDG" + STRING(group.GroupIndex)
%else
%assign elem = "VG" + STRING(varGroupIndex)
%endif
%if (group.GroupIndex == SLibGetSelfCoderDataGroupIndex())
%assign retStr = ::tSimStruct
%elseif (SLibGetUseRTMcgType())
%assign retStr = SLibGetFieldPointerFromSelf(elem, addTypeCast)
%else
%assign retStr = RTMGet(SLibCoderDataGroupRTMFieldName(group))
%if group.AsStructure == "InSelf"
%assign retStr = "&(%<retStr>)"
%endif
%endif
%if addTypeCast
%assign typeString = SLibCoderDataGroupType(group)
%assign typeCast = FcnRewriteCast("(%<typeString> *) %<retStr>")
%assign retStr = "(%<typeCast>)"
%endif
%return retStr
%endfunction
%function SLibGetDWorkStruct(addTypeCast) void
%if ::CompiledModel.HasSimStructVars == 1
%return SLibGetDWorkPointerFromRTM(addTypeCast)
%elseif IsModelRefScalableBuild() && !GenerateClassInterface
%assign baseSystem = ::CompiledModel.System[GetBaseSystemIdx()]
%return FcnSysVarGroupNonreusedName(baseSystem, "DWork")
%else
%return ::tDWork
%endif
%endfunction
%function LibGetDWorkStruct() void
%return SLibGetDWorkStruct(TLC_TRUE)
%endfunction
%function SLibGetCoderDataGroupStruct(group, addTypeCast) void
%if ::CompiledModel.HasSimStructVars == 1
%return SLibGetCoderDataGroupPointerFromRTM(group,0)
%elseif IsModelRefScalableBuild() && !GenerateClassInterface
%assign baseSystem = ::CompiledModel.System[GetBaseSystemIdx()]
%return FcnSysVarGroupNonreusedName(baseSystem, "CoderDataGroup" + group.Name)
%else
%return SLibCoderDataGroupInstance(group)
%endif
%endfunction
%function LibGetCoderDataGroupStruct(group) void
%return SLibGetCoderDataGroupStruct(group, TLC_TRUE)
%endfunction
%function LibGetContStatesStruct() void
%return LibGetContinuousStateStruct()
%endfunction
%function LibGetContStatesDisabledStruct() void
%return LibGetContinuousStateDisabledStruct()
%endfunction
%function LibGetContStatesAbsoluteToleranceStruct() void
%return LibGetContinuousStateAbsoluteToleranceStruct()
%endfunction
%function LibGetContStatesPerturbMinStruct() void
%return LibGetContinuousStatePerturbMinStruct()
%endfunction
%function LibGetContStatesPerturbMaxStruct() void
%return LibGetContinuousStatePerturbMaxStruct()
%endfunction
%function LibGetContStatesDerivativeStruct() void
%return LibGetDotContinuousStateStruct()
%endfunction
%function SLibGetPreviousZCStructFromRTM(addTypeCast) void
%if CodeFormat == "S-Function"
%assign retStr = RTMuGet("PrevZCSigState")
%else
%assign retStr = RTMGet("PrevZCSigState")
%endif
%if addTypeCast
%assign retStr = "((%<::tPrevZCStateType> *) %<retStr>)"
%endif
%return retStr
%endfunction
%function SLibGetPreviousZCStruct(addTypeCast) void
%if ::CompiledModel.HasSimStructVars == 1
%return SLibGetPreviousZCStructFromRTM(addTypeCast)
%elseif IsModelRefScalableBuild() && !GenerateClassInterface
%assign baseSystem = ::CompiledModel.System[GetBaseSystemIdx()]
%return FcnSysVarGroupNonreusedName(baseSystem, "ZCEvent")
%else
%return ::tPrevZCState
%endif
%endfunction
%function LibGetPreviousZCStruct() void
%return SLibGetPreviousZCStruct(TLC_TRUE)
%endfunction
%function LibGetZCEventStruct() void
%return LibGetPreviousZCStruct()
%endfunction
%function LibGetParameterStruct() void
%return LibGetParametersStruct()
%endfunction
%function SLibGetParamPointerFromRTM(addTypeCast) void
%if Accelerator
%assign retStr = RTMGet("ModelRtp")
%elseif CodeFormat == "S-Function"
%assign retStr = RTMGet("LocalDefaultParam")
%else
%assign retStr = RTMGet("DefaultParam")
%endif
%if addTypeCast
%assign retStr = "((%<::tParametersType> *) %<retStr>)"
%endif
%return retStr
%endfunction
%function (addTypeCast) void
%if ::CompiledModel.HasSimStructVars == 1
%return SLibGetParamPointerFromRTM(addTypeCast)
%elseif IsModelRefScalableBuild() && !GenerateClassInterface
%assign baseSystem = ::CompiledModel.System[GetBaseSystemIdx()]
%return FcnSysVarGroupNonreusedName(baseSystem, "Parameter")
%else
%assign paramStructVarName = ::tParameters
%return paramStructVarName
%endif
%endfunction
%function () void
%return SLibGetParametersStruct(TLC_TRUE)
%endfunction
%function SLibGetZCSignalValueStructFromRTM(addTypeCast) void
%if ::CodeFormat == "S-Function" && !::Accelerator
%assign retStr = RTMGet("NonsampledZCs")
%else
%assign retStr = RTMGet("SolverZcSignalVector")
%endif
%if addTypeCast
%assign retStr = "((%<::tZCSignalValueType> *) %<retStr>)"
%endif
%return retStr
%endfunction
%function SLibGetZCSignalValueStruct(addTypeCast) void
%if ::CompiledModel.HasSimStructVars == 1 || ::isRSimWithSolverModule
%return SLibGetZCSignalValueStructFromRTM(addTypeCast)
%else
%return ::tZCSignalValue
%endif
%endfunction
%function LibGetZCSignalValueStruct() void
%return SLibGetZCSignalValueStruct(TLC_TRUE)
%endfunction
%function LibGetZCSVStruct() void
%return LibGetZCSignalValueStruct()
%endfunction
%endif