%if EXISTS("_BLOCKLIB_") == 0
%assign _BLOCKLIB_ = 1
%function LibBlockDiscreteState(ucv, lcv, idx) void
%assign dwIdx = DiscStates[1]
%assign dwRec = ::CompiledModel.DWorks.DWork[dwIdx]
%if PurelyIntegerCode
%assign dTypeId = LibGetDataTypeIdAliasedThruToFromId(LibGetRecordDataTypeId(dwRec))
%if dTypeId == tSS_DOUBLE || dTypeId == tSS_SINGLE
%<SLibCacheIntegerOnlyWarning(Name,"State")>
%endif
%endif
%createrecord optionalArgs {}
%with FcnLoopInfo(ucv, lcv, idx)
%return FcnSimpleGetDWork(dwRec, dwIdx, DiscStates[0], "xd", optionalArgs)
%endwith
%endfunction
%function FcnCsHStructDeclSystemIdx(cs) void
%assign varGroupIdx = cs.VarGroupIdx[0]
%assign varGroup = ::CompiledModel.VarGroups.VarGroup[varGroupIdx]
%return varGroup.SysIdx
%endfunction
%function LibBlockContinuousState(ucv, lcv, idx) void
%assign cs = ::CompiledModel.ContStates.ContState[ContStates[1]]
%if PurelyIntegerCode
%<SLibCacheIntegerOnlyWarning(Name,"State")>
%endif
%return SLibContinuousState(cs, ucv, lcv, idx, ...
SLibGetHStructWithLocalScopeSystemIdx(FcnCsHStructDeclSystemIdx(cs)), CrossNoArgFcnBound)
%endfunction
%function FcnOwnerBlkType(rec) void
%assign grBlockIndex = rec.GrSrc
%assign grSubSys = ::CompiledModel.BlockHierarchyMap.Subsystem[grBlockIndex[0]]
%assign grBlock = grSubSys.Block[grBlockIndex[1]]
%return grBlock.Type
%endfunction
%function SLibContinuousState(cs, ucv, lcv, idx, accSysIdx, cross) void
%if ucv != "" || TYPE(idx) != "Number"
%assign idx = 0
%endif
%assign isMdlRef = FcnOwnerBlkType(cs) == "ModelReference"
%if isMdlRef
%assert(idx == 0)
%endif
%if ucv != "" || lcv == "" || (lcv != "" && cs.Width == 1)
%assign varGroupIdx = cs.VarGroupIdx[0]
%assign memberIdx = cs.VarGroupIdx[6]
%assign vgIdx = SLibVarGroupCGTypeIdx(varGroupIdx)
%assign memberCgTypeIdx = LibCGTypeMemberCGTypeIdx(vgIdx, memberIdx)
%assign width = LibCGTypeWidth(memberCgTypeIdx)
%return SLibCG_VarGroupElement(varGroupIdx, memberIdx, cross, accSysIdx, ...
width, ucv, idx)
%else
%assign sigIndexer = SLibGet1DArrayIndexer(cs.Width, ucv, lcv, idx)
%return "xc%<sigIndexer>"
%endif
%endfunction
%function SLibContinuousStateAddr(cs, mSysIdx) void
%assign thisSys = ::CompiledModel.System[mSysIdx]
%if PurelyIntegerCode
%<SLibCacheIntegerOnlyWarning(Name,"State")>
%endif
%assign varGroupIdx = cs.VarGroupIdx[0]
%assign accessSysIdx = SLibGetHStructWithLocalScopeSystemIdx(::CompiledModel.VarGroups.VarGroup[varGroupIdx].SysIdx)
%if SLibIsMappedSystemInDeploymentDiagram(mSysIdx)
%assign path = SLibCGIRVarGroupPath(varGroupIdx, mSysIdx, thisSys.CrossNoArgFcnBound)
%else
%assign path = SLibCGIRVarGroupPath(varGroupIdx, accessSysIdx, thisSys.CrossNoArgFcnBound)
%endif
%assign base = path + cs.Identifier
%assign isMdlRef = FcnOwnerBlkType(cs) == "ModelReference"
%if isMdlRef
%assign blk = System[cs.SigSrc[0]].Block[cs.SigSrc[2]]
%assign intrf = GetModelrefInterface(blk)
%if intrf.xOptWidth > 1
%assign base = base + "[0]"
%endif
%endif
%if cs.Width == 1 || isMdlRef
%assign base = "&(" + base + ")"
%endif
%return base
%endfunction
%function LibBlockContinuousStateDerivative(ucv, lcv, idx) void
%assign cs = ::CompiledModel.ContStates.ContState[ContStates[1]]
%if PurelyIntegerCode
%<SLibCacheIntegerOnlyWarning(Name,"StateDerivatives")>
%endif
%return SLibContinuousStateDerivative(cs, ucv, lcv, idx)
%endfunction
%function SLibContinuousStateDerivative(cs, ucv, lcv, idx) void
%if ucv != "" || TYPE(idx) != "Number"
%assign idx = 0
%endif
%if ucv != "" || lcv == "" || (lcv != "" && cs.Width == 1)
%assign varGroupIdx = cs.VarGroupIdx[2]
%assign memberIdx = cs.VarGroupIdx[6]
%assign varGroup = ::CompiledModel.VarGroups.VarGroup[varGroupIdx]
%assign sysIdx = varGroup.SysIdx
%assign accSysIdx = SLibGetHStructWithLocalScopeSystemIdx(sysIdx)
%assign cross = CrossNoArgFcnBound
%assign vgIdx = SLibVarGroupCGTypeIdx(varGroupIdx)
%assign memberCgTypeIdx = LibCGTypeMemberCGTypeIdx(vgIdx, memberIdx)
%assign width = LibCGTypeWidth(memberCgTypeIdx)
%return SLibCG_VarGroupElement(varGroupIdx, memberIdx, cross, accSysIdx, ...
width, ucv, idx)
%else
%assign sigIndexer = SLibGet1DArrayIndexer(cs.Width, ucv, lcv, idx)
%return "xdot%<sigIndexer>"
%endif
%endfunction
%function SLibContinuousStateDerivativeAddr(mSysIdx) void
%assign cs = ::CompiledModel.ContStates.ContState[ContStates[1]]
%if PurelyIntegerCode
%<SLibCacheIntegerOnlyWarning(Name,"StateDerivatives")>
%endif
%assign varGroupIdx = cs.VarGroupIdx[2]
%assign accessSysIdx = SLibGetHStructWithLocalScopeSystemIdx(::CompiledModel.VarGroups.VarGroup[varGroupIdx].SysIdx)
%if SLibIsMappedSystemInDeploymentDiagram(mSysIdx)
%assign path = SLibCGIRVarGroupPath(varGroupIdx, mSysIdx, CrossNoArgFcnBound)
%else
%assign path = SLibCGIRVarGroupPath(varGroupIdx, accessSysIdx, CrossNoArgFcnBound)
%endif
%assign base = path + cs.Identifier
%assign isMdlRef = FcnOwnerBlkType(cs) == "ModelReference"
%if isMdlRef
%assign blk = System[cs.SigSrc[0]].Block[cs.SigSrc[2]]
%assign intrf = GetModelrefInterface(blk)
%if intrf.xOptWidth > 1
%assign base = base + "[0]"
%endif
%endif
%if (cs.Width == 1 || isMdlRef)
%assign base = "&(" + base + ")"
%endif
%return base
%endfunction
%function LibBlockContStateDisabled(ucv, lcv, idx) void
%assign cs = ::CompiledModel.ContStates.ContState[ContStates[1]]
%if PurelyIntegerCode
%<SLibCacheIntegerOnlyWarning(Name,"StateDisabled")>
%endif
%return SLibContStateDisabled(cs, ucv, lcv, idx)
%endfunction
%function SLibContStateDisabled(cs, ucv, lcv, idx) void
%if ucv != "" || TYPE(idx) != "Number"
%assign idx = 0
%endif
%if ucv != "" || lcv == "" || (lcv != "" && cs.Width == 1)
%assign varGroupIdx = cs.VarGroupIdx[1]
%assign memberIdx = cs.VarGroupIdx[6]
%assign varGroup = ::CompiledModel.VarGroups.VarGroup[varGroupIdx]
%assign sysIdx = varGroup.SysIdx
%assign accSysIdx = SLibGetHStructWithLocalScopeSystemIdx(sysIdx)
%assign cross = CrossNoArgFcnBound
%assign vgIdx = SLibVarGroupCGTypeIdx(varGroupIdx)
%assign memberCgTypeIdx = LibCGTypeMemberCGTypeIdx(vgIdx, memberIdx)
%assign width = LibCGTypeWidth(memberCgTypeIdx)
%return SLibCG_VarGroupElement(varGroupIdx, memberIdx, cross, accSysIdx, ...
width, ucv, idx)
%else
%assign sigIndexer = SLibGet1DArrayIndexer(cs.Width, ucv, lcv, idx)
%return "xdis%<sigIndexer>"
%endif
%endfunction
%function SLibContStateDisabledAddr(mSysIdx) void
%assign cs = ::CompiledModel.ContStates.ContState[ContStates[1]]
%if PurelyIntegerCode
%<SLibCacheIntegerOnlyWarning(Name,"StateDisabled")>
%endif
%assign varGroupIdx = cs.VarGroupIdx[1]
%assign accessSysIdx = SLibGetHStructWithLocalScopeSystemIdx(::CompiledModel.VarGroups.VarGroup[varGroupIdx].SysIdx)
%if SLibIsMappedSystemInDeploymentDiagram(mSysIdx)
%assign path = SLibCGIRVarGroupPath(varGroupIdx, mSysIdx, CrossNoArgFcnBound)
%else
%assign path = SLibCGIRVarGroupPath(varGroupIdx, accessSysIdx, CrossNoArgFcnBound)
%endif
%assign base = path + cs.Identifier
%assign isMdlRef = FcnOwnerBlkType(cs) == "ModelReference"
%if isMdlRef
%assign blk = System[cs.SigSrc[0]].Block[cs.SigSrc[2]]
%assign intrf = GetModelrefInterface(blk)
%if intrf.xOptWidth > 1
%assign base = base + "[0]"
%endif
%endif
%if (cs.Width == 1 || Type == "ModelReference")
%assign base = "&(" + base + ")"
%endif
%return base
%endfunction
%function LibBlockContStateAbsoluteTolerance(ucv, lcv, idx) void
%assign cs = ::CompiledModel.ContStates.ContState[ContStates[1]]
%if PurelyIntegerCode
%<SLibCacheIntegerOnlyWarning(Name,"StateAbsoluteTolerance")>
%endif
%return SLibContStateAbsoluteTolerance(cs, ucv, lcv, idx)
%endfunction
%function SLibContStateAbsoluteTolerance(cs, ucv, lcv, idx) void
%if ucv != "" || TYPE(idx) != "Number"
%assign idx = 0
%endif
%if ucv != "" || lcv == "" || (lcv != "" && cs.Width == 1)
%assign varGroupIdx = cs.VarGroupIdx[3]
%assign memberIdx = cs.VarGroupIdx[6]
%assign varGroup = ::CompiledModel.VarGroups.VarGroup[varGroupIdx]
%assign sysIdx = varGroup.SysIdx
%assign accSysIdx = SLibGetHStructWithLocalScopeSystemIdx(sysIdx)
%assign cross = CrossNoArgFcnBound
%assign vgIdx = SLibVarGroupCGTypeIdx(varGroupIdx)
%assign memberCgTypeIdx = LibCGTypeMemberCGTypeIdx(vgIdx, memberIdx)
%assign width = LibCGTypeWidth(memberCgTypeIdx)
%return SLibCG_VarGroupElement(varGroupIdx, memberIdx, cross, accSysIdx, ...
width, ucv, idx)
%else
%assign sigIndexer = SLibGet1DArrayIndexer(cs.Width, ucv, lcv, idx)
%return "xAbsTol%<sigIndexer>"
%endif
%endfunction
%function SLibContStateAbsoluteToleranceAddr(mSysIdx) void
%assign cs = ::CompiledModel.ContStates.ContState[ContStates[1]]
%if PurelyIntegerCode
%<SLibCacheIntegerOnlyWarning(Name,"StateAbsoluteTolerance")>
%endif
%assign varGroupIdx = cs.VarGroupIdx[3]
%assign accessSysIdx = SLibGetHStructWithLocalScopeSystemIdx(::CompiledModel.VarGroups.VarGroup[varGroupIdx].SysIdx)
%if SLibIsMappedSystemInDeploymentDiagram(mSysIdx)
%assign path = SLibCGIRVarGroupPath(varGroupIdx, mSysIdx, CrossNoArgFcnBound)
%else
%assign path = SLibCGIRVarGroupPath(varGroupIdx, accessSysIdx, CrossNoArgFcnBound)
%endif
%assign base = path + cs.Identifier
%assign isMdlRef = FcnOwnerBlkType(cs) == "ModelReference"
%if isMdlRef
%assign blk = System[cs.SigSrc[0]].Block[cs.SigSrc[2]]
%assign intrf = GetModelrefInterface(blk)
%if intrf.xOptWidth > 1
%assign base = base + "[0]"
%endif
%endif
%if (cs.Width == 1 || Type == "ModelReference")
%assign base = "&(" + base + ")"
%endif
%return base
%endfunction
%function LibBlockContStatePerturbMin(ucv, lcv, idx) void
%assign cs = ::CompiledModel.ContStates.ContState[ContStates[1]]
%if PurelyIntegerCode
%<SLibCacheIntegerOnlyWarning(Name,"StatePerturbMin")>
%endif
%return SLibContStatePerturbMin(cs, ucv, lcv, idx)
%endfunction
%function SLibContStatePerturbMin(cs, ucv, lcv, idx) void
%if ucv != "" || TYPE(idx) != "Number"
%assign idx = 0
%endif
%if ucv != "" || lcv == "" || (lcv != "" && cs.Width == 1)
%assign varGroupIdx = cs.VarGroupIdx[4]
%assign memberIdx = cs.VarGroupIdx[6]
%assign varGroup = ::CompiledModel.VarGroups.VarGroup[varGroupIdx]
%assign sysIdx = varGroup.SysIdx
%assign accSysIdx = SLibGetHStructWithLocalScopeSystemIdx(sysIdx)
%assign cross = CrossNoArgFcnBound
%assign vgIdx = SLibVarGroupCGTypeIdx(varGroupIdx)
%assign memberCgTypeIdx = LibCGTypeMemberCGTypeIdx(vgIdx, memberIdx)
%assign width = LibCGTypeWidth(memberCgTypeIdx)
%return SLibCG_VarGroupElement(varGroupIdx, memberIdx, cross, accSysIdx, ...
width, ucv, idx)
%else
%assign sigIndexer = SLibGet1DArrayIndexer(cs.Width, ucv, lcv, idx)
%return "xPerturbMin%<sigIndexer>"
%endif
%endfunction
%function SLibContStatePerturbMinAddr(mSysIdx) void
%assign cs = ::CompiledModel.ContStates.ContState[ContStates[1]]
%if PurelyIntegerCode
%<SLibCacheIntegerOnlyWarning(Name,"StatePerturbMin")>
%endif
%assign varGroupIdx = cs.VarGroupIdx[4]
%assign accessSysIdx = SLibGetHStructWithLocalScopeSystemIdx(::CompiledModel.VarGroups.VarGroup[varGroupIdx].SysIdx)
%if SLibIsMappedSystemInDeploymentDiagram(mSysIdx)
%assign path = SLibCGIRVarGroupPath(varGroupIdx, mSysIdx, CrossNoArgFcnBound)
%else
%assign path = SLibCGIRVarGroupPath(varGroupIdx, accessSysIdx, CrossNoArgFcnBound)
%endif
%assign base = path + cs.Identifier
%assign isMdlRef = FcnOwnerBlkType(cs) == "ModelReference"
%if isMdlRef
%assign blk = System[cs.SigSrc[0]].Block[cs.SigSrc[2]]
%assign intrf = GetModelrefInterface(blk)
%if intrf.xOptWidth > 1
%assign base = base + "[0]"
%endif
%endif
%if (cs.Width == 1 || Type == "ModelReference")
%assign base = "&(" + base + ")"
%endif
%return base
%endfunction
%function LibBlockContStatePerturbMax(ucv, lcv, idx) void
%assign cs = ::CompiledModel.ContStates.ContState[ContStates[1]]
%if PurelyIntegerCode
%<SLibCacheIntegerOnlyWarning(Name,"StatePerturbMax")>
%endif
%return SLibContStatePerturbMax(cs, ucv, lcv, idx)
%endfunction
%function SLibContStatePerturbMax(cs, ucv, lcv, idx) void
%if ucv != "" || TYPE(idx) != "Number"
%assign idx = 0
%endif
%if ucv != "" || lcv == "" || (lcv != "" && cs.Width == 1)
%assign varGroupIdx = cs.VarGroupIdx[5]
%assign memberIdx = cs.VarGroupIdx[6]
%assign varGroup = ::CompiledModel.VarGroups.VarGroup[varGroupIdx]
%assign sysIdx = varGroup.SysIdx
%assign accSysIdx = SLibGetHStructWithLocalScopeSystemIdx(sysIdx)
%assign cross = CrossNoArgFcnBound
%assign vgIdx = SLibVarGroupCGTypeIdx(varGroupIdx)
%assign memberCgTypeIdx = LibCGTypeMemberCGTypeIdx(vgIdx, memberIdx)
%assign width = LibCGTypeWidth(memberCgTypeIdx)
%return SLibCG_VarGroupElement(varGroupIdx, memberIdx, cross, accSysIdx, ...
width, ucv, idx)
%else
%assign sigIndexer = SLibGet1DArrayIndexer(cs.Width, ucv, lcv, idx)
%return "xPerturbMax%<sigIndexer>"
%endif
%endfunction
%function SLibContStatePerturbMaxAddr(mSysIdx) void
%assign cs = ::CompiledModel.ContStates.ContState[ContStates[1]]
%if PurelyIntegerCode
%<SLibCacheIntegerOnlyWarning(Name,"StatePerturbMax")>
%endif
%assign varGroupIdx = cs.VarGroupIdx[5]
%assign accessSysIdx = SLibGetHStructWithLocalScopeSystemIdx(::CompiledModel.VarGroups.VarGroup[varGroupIdx].SysIdx)
%if SLibIsMappedSystemInDeploymentDiagram(mSysIdx)
%assign path = SLibCGIRVarGroupPath(varGroupIdx, mSysIdx, CrossNoArgFcnBound)
%else
%assign path = SLibCGIRVarGroupPath(varGroupIdx, accessSysIdx, CrossNoArgFcnBound)
%endif
%assign base = path + cs.Identifier
%assign isMdlRef = FcnOwnerBlkType(cs) == "ModelReference"
%if isMdlRef
%assign blk = System[cs.SigSrc[0]].Block[cs.SigSrc[2]]
%assign intrf = GetModelrefInterface(blk)
%if intrf.xOptWidth > 1
%assign base = base + "[0]"
%endif
%endif
%if (cs.Width == 1 || Type == "ModelReference")
%assign base = "&(" + base + ")"
%endif
%return base
%endfunction
%function SLibBlockMassMatrixPrOffsetInternal(ucv, lcv, idx, dwIdx, dwRec, Pr0) void
%createrecord optionalArgs {}
%with FcnLoopInfo(ucv, lcv, idx)
%return FcnSimpleGetDWork(dwRec, dwIdx, Pr0, "massMatrixPr", optionalArgs)
%endwith
%endfunction
%function SLibBlockMassMatrixPrOffset(ucv, lcv, idx) void
%assign dwIdx = MassMatrixPr[1]
%assign dwRec = ::CompiledModel.DWorks.DWork[dwIdx]
%return SLibBlockMassMatrixPrOffsetInternal(ucv, lcv, idx, dwIdx, dwRec, MassMatrixPr[0])
%endfunction
%function SLibBlockMassMatrixPr() void
%return "&(%<LibGetMassMatrixGlobalPr()>[%<SLibBlockMassMatrixPrOffset("", "", 0)>])"
%endfunction
%function LibBlockRWork(definedrwork, ucv, lcv, idx) void
%if PurelyIntegerCode
%<SLibCacheIntegerOnlyWarning(Name,"WorkVector")>
%endif
%with FcnLoopInfo(ucv, lcv, idx)
%return FcnBlockXWork(definedrwork, RWork, NumRWorkDefines, "r")
%endwith
%endfunction
%function LibBlockIWork(definediwork, ucv, lcv, idx) void
%with FcnLoopInfo(ucv, lcv, idx)
%return FcnBlockXWork(definediwork, IWork, NumIWorkDefines, "i")
%endwith
%endfunction
%function LibBlockPWork(definedpwork, ucv, lcv, idx) void
%with FcnLoopInfo(ucv, lcv, idx)
%return FcnBlockXWork(definedpwork, PWork, NumPWorkDefines, "p")
%endwith
%endfunction
%function FcnBlockXWork(definedxwork, XWork, NumXWorkDefines, XWorkVarNamePrefix) void
%assign dwIdx = XWork[1]
%assign dwRec = ::CompiledModel.DWorks.DWork[dwIdx]
%if (NumXWorkDefines > 0)
%assign rollName = XWorkVarNamePrefix + "w_" + definedxwork.Name
%createrecord optionalArgs ...
{ ...
StartIdx definedxwork.StartIndex; ...
DotName "." + definedxwork.Name ...
}
%return FcnSimpleGetDWork(dwRec, dwIdx, definedxwork.Width, rollName, ...
optionalArgs)
%else
%if Lcv != ""
%setcommandswitch "-v1"
%assign errTxt = "Don't know how to roll " + dwRec.Origin + " for " ...
"%<Type> Block: %<LibGetFormattedBlockPath(block)>"
%exit Simulink Coder Fatal: %<errTxt>
%endif
%if TYPE(definedxwork) == "Scope"
%createrecord optionalArgs { Name definedxwork.Name }
%else
%createrecord optionalArgs {}
%endif
%return FcnNonRollingDWork(dwRec, dwIdx, XWork[0], optionalArgs)
%endif
%endfunction
%function LibBlockMode(ucv, lcv, idx) void
%assign dwIdx = ModeVector[1]
%assign dwRec = ::CompiledModel.DWorks.DWork[dwIdx]
%createrecord optionalArgs {}
%with FcnLoopInfo(ucv, lcv, idx)
%return FcnSimpleGetDWork(dwRec, dwIdx, ModeVector[0], "mode", optionalArgs)
%endwith
%endfunction
%function FcnGetDworkAndRec(DworkIn) void
%assign isRecord = TLC_TRUE
%assign idNum = ["",0]
%assign interface = []
%if TYPE(DworkIn) == "Identifier" || TYPE(DworkIn) == "String"
%assign idNum = IDNUM(DworkIn)
%assign isRecord = TLC_FALSE
%endif
%if isRecord
%assign dwork = DworkIn
%if ISFIELD(dwork, "SigSrc")
%assign dwRec = dwork
%else
%assign dwIdx = dwork.FirstRootIdx
%assign dwRec = ::CompiledModel.DWorks.DWork[dwIdx]
%endif
%else
%if (idNum[0] == "d" || idNum[0] == "D" || idNum[0] == "db")
%assign firstRootIdx = idNum[1]
%else
%assign relIdx = idNum[1]
%assign hStructSysIdx = System[SystemIdx].ReusedParentSystemIdx
%assign interface = System[hStructSysIdx].Interface
%assign firstRootIdx = interface.CanonicalDWorkArgDef[relIdx].FirstSignalSrc
%endif
%createrecord dwork { Name DworkIn; FirstRootIdx %<firstRootIdx>}
%assign dwRec = ::CompiledModel.DWorks.DWork[firstRootIdx]
%endif
%createrecord dworkAndRec { DWork dwork; DWorkRec dwRec ; IsRecord isRecord ; IdNum idNum; Interface interface }
%return dworkAndRec
%endfunction
%function FcnGetDworkContentsOrAddress(access, DworkIn, ucv, lcv, sigIdx) void
%assign dworkAndRec = FcnGetDworkAndRec(DworkIn)
%assign dwork = dworkAndRec.DWork
%assign dwRec = dworkAndRec.DWorkRec
%assign isRecord = dworkAndRec.IsRecord
%assign idNum = dworkAndRec.IdNum
%assign interface = dworkAndRec.Interface
%assign tmpVect = SLibGetReimAndIdx(sigIdx)
%assign reim = tmpVect[0]
%assign idx = tmpVect[1]
%if !SLibDWorkIsComplex(dwRec) && reim == tImagPart
%return ""
%endif
%if PurelyIntegerCode
%assign dTypeId = LibGetDataTypeIdAliasedThruToFromId(SLibGetRecordDataTypeId(dwRec))
%if dTypeId == tSS_DOUBLE || dTypeId == tSS_SINGLE
%<SLibCacheIntegerOnlyWarning(Name,"WorkVector")>
%endif
%endif
%assign width = LibCGTypeWidth(LibGetRecordCGTypeIdx(dwRec))
%assign sigIndexer = SLibGet1DArrayIndexer(width, ucv, lcv, idx)
%assign hasCustomStorage = LibHasCustomStorage(dwRec)
%assign pureSFcnTarget = (CodeFormat == "S-Function" && !Accelerator)
%assign bAddr = ("address" == access)
%if ucv != "" || lcv == "" || (lcv != "" && width == 1)
%if pureSFcnTarget
%with FcnLoopInfo(ucv, lcv, idx)
%assign answer = FcnGetGlobalDWork(dwRec, dwork.FirstRootIdx, width, 0)
%endwith
%else
%if dwRec.StorageClass != "Auto" || SLibIsLegacyStorageClassForDataRecord(dwRec)
%if hasCustomStorage
%if bAddr && !LibCustomDataIsAddressable(dwRec)
%<SLibReportNonAddressableError("Dwork", thisBlock, dwRec)>
%endif
%assign answer = LibCustomData(dwRec,access,sigIndexer,reim)
%return answer
%else
%assign answer = LibGetRecordIdentifier(dwRec) + sigIndexer
%endif
%else
%if EXISTS("BlockIdx") && ...
BlockIdx[0] == dwRec.SigSrc[0] && BlockIdx[2] == dwRec.SigSrc[2]
%assign thisBlock = SLibGetCurrentBlock()
%if "Opaque" != thisBlock.Type
%assign thisDWorkIdx = dwRec.SigSrc[3]
%assert DworkIn.FirstRootIdx == ...
thisBlock.DWork[thisDWorkIdx].FirstRootIdx
%assert DworkIn.Name == thisBlock.DWork[thisDWorkIdx].Name
%assign ident = SLibInvokeTLCInterface(thisBlock, ...
"DWork", thisDWorkIdx, 0, bAddr, lcv, ucv, idx, reim)
%assign tlcIFv2Enable = !ISEMPTY(ident)
%if tlcIFv2Enable
%return ident
%endif
%endif
%endif
%assign cross = CrossNoArgFcnBound
%if isRecord || idNum[0] == "d" || idNum[0] == "D"
%if dwRec.IsLocalScratchDWork == 1
%if dwRec.VarGroupVarIdx > -1
%assign varGroupIdx = ...
::CompiledModel.VarGroups.VarGroupVarIdx[dwRec.VarGroupVarIdx]
%assign answer = SLibCG_GetVarGroupElementPath(varGroupIdx, ...
SLibGetHStructWithLocalScopeSystemIdx(HStructDeclSystemIdx), cross) + sigIndexer
%else
%assign activeFcn = FcnGetActiveFcnForDecl()
%assign declareInFcnScope = "DeclareIn%<activeFcn>FcnScope"
%assign dwRec.%<declareInFcnScope> = 1
%assign answer = LibGetRecordIdentifier(dwRec) + sigIndexer
%endif
%else
%assign answer = SLibCG_GetVarGroupElementPath(dwRec.VarGroupIdx, ...
SLibGetHStructWithLocalScopeSystemIdx(HStructDeclSystemIdx), cross) + sigIndexer
%endif
%else
%assign dworkArgDef = interface.CanonicalDWorkArgDef[idNum[1]]
%assign dworkArgDefId = LibGetRecordIdentifier(dworkArgDef)
%if cross
%<LibAccessGlobalArg(dworkArgDef)>
%assign name = dworkArgDef.GlobalIdentifier
%if width == 1
%assign answer = "(*%<name>)"
%else
%assign answer = name + sigIndexer
%endif
%else
%assert idNum[0] == "dp"
%assign name = LibGetRecordIdentifier(dworkArgDef)
%if width == 1
%assign answer = "(*%<name>)"
%else
%assign answer = name + sigIndexer
%endif
%endif
%assign hStructSysIdx = System[SystemIdx].HStructDeclSystemIdx
%assign interface = System[hStructSysIdx].Interface
%with System[SystemIdx]
%assign tid = FcnGetCurrentAccessTid()
%endwith
%<SLibAccessArgHelper(dworkArgDef,"",tid)>
%endif
%endif
%endif
%else
%assign answer = "dw_%<dwork.Name>%<sigIndexer>"
%endif
%if SLibDWorkIsComplex(dwRec) && reim != ""
%assign answer = answer + ".%<reim>"
%endif
%assign scalarIEP = ((dwRec.StorageClass == "ImportedExternPointer") && ...
(width == 1))
%if bAddr && (!scalarIEP)
%assign answer = "&" + answer
%elseif ((access == "contents") && (scalarIEP) && (!pureSFcnTarget))
%assign answer = "(*%<answer>)"
%endif
%return answer
%endfunction
%function LibBlockDWorkAddr(dwork, ucv, lcv, idx) void
%return FcnGetDworkContentsOrAddress("address", dwork, ucv, lcv, idx)
%endfunction
%function LibBlockDWork(dwork, ucv, lcv, idx) void
%return FcnGetDworkContentsOrAddress("contents", dwork, ucv, lcv, idx)
%endfunction
%function LibBlockDWorkWidth(dwork) void
%assign cgTypeIdx = ISFIELD(dwork, "CGTypeIdx") ? dwork.CGTypeIdx : ...
LibGetRecordCGTypeIdx(::CompiledModel.DWorks.DWork[dwork.FirstRootIdx])
%return LibCGTypeWidth(cgTypeIdx)
%endfunction
%function SLibDWorkWidth(dwRec) void
%return LibCGTypeWidth(LibGetRecordCGTypeIdx(dwRec))
%endfunction
%function LibBlockDWorkStorageClass(dwork) void
%assign dwRec = ::CompiledModel.DWorks.DWork[dwork.FirstRootIdx]
%if SLibIsLegacyStorageClassForDataRecord(dwRec)
%return "Custom"
%else
%return dwRec.StorageClass
%endif
%endfunction
%function LibBlockDWorkStorageTypeQualifier(dwork) void
%assign dwRec = ::CompiledModel.DWorks.DWork[dwork.FirstRootIdx]
%return dwRec.StorageTypeQualifier
%endfunction
%function LibBlockDWorkDataTypeId(dwork) void
%assign dwRec = ::CompiledModel.DWorks.DWork[dwork.FirstRootIdx]
%return SLibGetRecordDataTypeId(dwRec)
%endfunction
%function SLibDWorkDataTypeId(dwRec) void
%return LibCGTypeToSLType(LibGetRecordCGTypeIdx(dwRec))
%endfunction
%function LibBlockDWorkDataTypeName(dwork, reim) void
%assign dwRec = ::CompiledModel.DWorks.DWork[dwork.FirstRootIdx]
%return SLibGetRecordDataTypeName(dwRec, reim)
%endfunction
%function LibBlockDWorkIsComplex(dwork) void
%return LibCGTypeIsComplex(LibGetRecordCGTypeIdx(::CompiledModel.DWorks.DWork[dwork.FirstRootIdx]))
%endfunction
%function SLibDWorkIsComplex(dwRec) void
%return LibCGTypeIsComplex(LibGetRecordCGTypeIdx(dwRec))
%endfunction
%function LibBlockDWorkUsedAsDiscreteState(dwork) void
%assign dwRec = ::CompiledModel.DWorks.DWork[dwork.FirstRootIdx]
%return (dwRec.UsedAs == "DSTATE")
%endfunction
%function LibBlockDWorkName(dwork) void
%return STRING(dwork.Name)
%endfunction
%function SLibGetSystemAndCallSideIndex(rec)
%assign retVal = [-1, -1]
%if ISFIELD(rec,"SysCsIdx")
%return rec.SysCsIdx
%elseif rec.RecordType == "ModelParameter"
%return rec.OwnerSysIdx
%else
%assign varGroup = ::CompiledModel.VarGroups.VarGroup[rec.VarGroupIdx[0]]
%assign retVal[0] = varGroup.SysIdx
%assign retVal[1] = varGroup.InstanceIdx
%return retVal
%endif
%endfunction
%function LibBlockPrevZCSignalState(ucv, lcv, zcsIdx, zcElIdx) void
%assign blkZcRecIdx = BlkZcRec.BlkZcRecIdx
%assign zcs = ::CompiledModel.ZcRec.BlkZcRec[blkZcRecIdx].ZcSignalInfo[zcsIdx]
%return SLibPrevZCSignalState(zcs, ucv, lcv, zcsIdx, zcElIdx)
%endfunction
%function FcnGetZCEventCGVarName(zcsInfo) void
%assign varGroupIdx = zcsInfo.VarGroupIdx[0]
%assign memberIdx = zcsInfo.VarGroupIdx[1]
%return SLibCGVarGroupMemberName(varGroupIdx, memberIdx)
%endfunction
%function FcnGetZCSignalCGVarName(zcsInfo) void
%assign varGroupIdx = zcsInfo.VarGroupIdx[2]
%assign memberIdx = zcsInfo.VarGroupIdx[3]
%return SLibCGVarGroupMemberName(varGroupIdx, memberIdx)
%endfunction
%function FcnGetZCEventCGVarWidth(zcsInfo) void
%assign varGroupIdx = zcsInfo.VarGroupIdx[0]
%assign memberIdx = zcsInfo.VarGroupIdx[1]
%assign cgTypeIdx = SLibCGVarGroupMemberCGTypeIdx(varGroupIdx, memberIdx)
%return LibCGTypeWidth(cgTypeIdx)
%endfunction
%function FcnGetZCSignalCGVarWidth(zcsInfo) void
%assign varGroupIdx = zcsInfo.VarGroupIdx[2]
%assign memberIdx = zcsInfo.VarGroupIdx[3]
%assign cgTypeIdx = SLibCGVarGroupMemberCGTypeIdx(varGroupIdx, memberIdx)
%return LibCGTypeWidth(cgTypeIdx)
%endfunction
%function SLibPrevZCSignalState(zcs, ucv, lcv, zcsIdx, zcElIdx) void
%assign blkZcRecIdx = zcs.BlkZcRecIdx
%assign blkZcRec = ::CompiledModel.ZcRec.BlkZcRec[blkZcRecIdx]
%assign sigIndexer = SLibGet1DArrayIndexer(zcs.Width, ucv, lcv, zcElIdx)
%if ucv != "" || lcv == "" || (lcv != "" && zcs.Width == 1)
%assign idxVec = SLibGetSystemAndCallSideIndex(blkZcRec)
%assign sysIdx = idxVec[0]
%assign varGroupIdx = zcs.VarGroupIdx[0]
%assign zcPath = SLibCGIRVarGroupPath(...
varGroupIdx, NonInlinedParentSystemIdx, System[NonInlinedParentSystemIdx].CrossNoArgFcnBound)
%assign name = FcnGetZCEventCGVarName(zcs)
%return zcPath + name + sigIndexer
%else
%return "pzc%<zcsIdx>" + sigIndexer
%endif
%endfunction
%function LibBlockZCSignalValue(ucv, lcv, zcsIdx, zcElIdx) void
%assign blkZcRecIdx = BlkZcRec[0].BlkZcRecIdx
%assign zcs = ::CompiledModel.ZcRec.BlkZcRec[blkZcRecIdx].ZcSignalInfo[zcsIdx]
%return SLibZCSignalValueState(zcs, ucv, lcv, zcsIdx, zcElIdx)
%endfunction
%function SLibZCSignalValueState(zcs, ucv, lcv, zcsIdx, zcElIdx) void
%assign blkZcRecIdx = zcs.BlkZcRecIdx
%assign blkZcRec = ::CompiledModel.ZcRec.BlkZcRec[blkZcRecIdx]
%assign sigIndexer = SLibGet1DArrayIndexer(zcs.Width, ucv, lcv, zcElIdx)
%if ucv != "" || lcv == "" || (lcv != "" && zcs.Width == 1)
%assign idxVec = SLibGetSystemAndCallSideIndex(blkZcRec)
%assign sysIdx = idxVec[0]
%assign csIdx = idxVec[1]
%assign varGroupIdx = FcnSysVarGroupIndex(System[sysIdx], "ZCSV", csIdx)
%assign cross = System[sysIdx].CrossNoArgFcnBound
%assign zcPath = SLibCGIRVarGroupPath...
(varGroupIdx, HStructDeclSystemIdx, cross)
%assign name = FcnGetZCSignalCGVarName(zcs)
%return zcPath + name + sigIndexer
%else
%return "zcsv%<zcsIdx>" + sigIndexer
%endif
%endfunction
%function SLibZCSignalValueAddr(zcsIdx) void
%assign blkZcRecIdx = BlkZcRec[0].BlkZcRecIdx
%assign blkZcRec = ::CompiledModel.ZcRec.BlkZcRec[blkZcRecIdx]
%assign zcs = blkZcRec.ZcSignalInfo[zcsIdx]
%assign idxVec = SLibGetSystemAndCallSideIndex(blkZcRec)
%assign sysIdx = idxVec[0]
%assign csIdx = idxVec[1]
%assign declSysIdx = HStructDeclSystemIdx
%assign varGroupIdx = zcs.VarGroupIdx[2]
%assign path = SLibCGIRVarGroupPath(...
varGroupIdx, declSysIdx, System[sysIdx].CrossNoArgFcnBound)
%assign base = path + FcnGetZCSignalCGVarName(zcs)
%assign blk = System[sysIdx].Block[blkZcRec.SigSrc[2]]
%if (TYPE(blk.Type) == "Identifier" && blk.Type == "ModelReference")
%assign intrf = GetModelrefInterface(blk)
%if intrf.zcOptWidth > 1
%assign base = base + "[0]"
%endif
%endif
%if ((zcs.Width == 1) || Type == "ModelReference")
%assign base = "&(" + base + ")"
%endif
%return base
%endfunction
%function LibBlockPortSampleTime(portTID)
%if PortBasedSampleTimes != "yes"
%<LibReportFatalError("LibBlockPortSampleTime called for block that does not have port-based sample times")>
%endif
%if TYPE(portTID) != "String"
%<LibReportFatalError("Incorrect portTID argument")>
%endif
%assign portLocAndIdx = IDNUM(portTID)
%if SIZE(portLocAndIdx,1) == 2
%if portLocAndIdx[1] >= 0
%assign port = portLocAndIdx[1]
%if portLocAndIdx[0] == "InputPortIdx" && port < NumDataInputPorts
%if InputPortSampleTimes[port] == rtInf && InputPortOffsetTimes[port] == rtInf
%return "constant"
%else
%return InputPortTIDs[port]
%endif
%elseif portLocAndIdx[0]=="OutputPortIdx" && port < NumDataOutputPorts
%if OutputPortSampleTimes[port] == rtInf && OutputPortOffsetTimes[port] == rtInf
%return "constant"
%else
%return OutputPortTIDs[port]
%endif
%else
%<LibReportFatalError("Incorrect portTID argument")>
%endif
%endif
%else
%<LibReportFatalError("Incorrect portTID argument")>
%endif
%endfunction
%function LibBlockSampleTime(block) void
%assign tid = block.TID
%if TYPE(tid) == "Number"
%return CAST("Real", ::CompiledModel.SampleTime[tid].PeriodAndOffset[0])
%elseif ISEQUAL(tid, "triggered")
%return -1.0
%elseif ISEQUAL(tid, "constant")
%return -2.0
%else
%assign blockName = LibUnmangledPathName(Name)
%setcommandswitch "-v1"
%assign errTxt = "Cannot compute step size for TID=%<tid> in " ...
"%<block.Type> Block: %<LibGetFormattedBlockPath(block)>"
%exit Simulink Coder Fatal: %<errTxt>
%endif
%endfunction
%function LibSetVarNextHitTime(block,tNext) void
%assign tid = block.VarTsTID
%if IsModelReferenceForASimstructBasedTarget()
%assign idx = %<tid>
%else
%assign idx = CAST("Number", ::CompiledModel.SampleTime[tid].PeriodAndOffset[1])
%endif
%return RTMuSetIdxed("VarNextHitTime", "%<idx>", tNext)
%endfunction
%function LibPortBasedSampleTimeBlockIsTriggered(block) void
%assign tid = block.TID
%if LibTriggeredTID(tid)
%return 1
%else
%return 0
%endif
%endfunction
%function FcnGetGlobalDWork(dwRec, dwIdx, width, startIdx) void
%assign index = width == 1 ? ...
"[%<startIdx>]" : ...
SLibGet1DArrayIndexer(width, Ucv, Lcv, startIdx+Idx)
%return SLibGetGlobalDWorkIdentifier(dwRec, dwIdx) + index
%endfunction
%function SLibGetGlobalDWorkIdentifier(dwRec, dwIdx) void
%assign dtype = SLibGetRecordDataTypeName(dwRec, "")
%assign varGrpIdx = dwRec.VarGroupIdx[1]
%assign macro = "ssGetDWork(%<SLibGetSimStruct()>, %<varGrpIdx>)"
%assign retVal = "((%<dtype>*) %<macro>)"
%assign retVal = FcnReplaceCCastWithStaticCastForCPP(retVal)
%return retVal
%endfunction
%function SLibGetNameOfExtModeActiveDWork() void
%return "ExtModeActive"
%endfunction
%function SLibGetNameOfSubsysRanBCDWork() void
%return "SubsysRanBC"
%endfunction
%function FcnNonRollingDWork(dwRec, dwIdx, width, optionalArgs) void
%if !ISFIELD(optionalArgs,"StartIdx")
%addtorecord optionalArgs StartIdx 0
%endif
%if !ISFIELD(optionalArgs,"DotName")
%addtorecord optionalArgs DotName ""
%endif
%if !ISFIELD(optionalArgs,"Name")
%addtorecord optionalArgs Name ""
%endif
%if CodeFormat == "S-Function" && !Accelerator
%return FcnGetGlobalDWork(dwRec, dwIdx, width, optionalArgs.StartIdx)
%else
%if EXISTS("BlockIdx") && ...
BlockIdx[0] == dwRec.SigSrc[0] && BlockIdx[2] == dwRec.SigSrc[2]
%assign thisBlock = SLibGetCurrentBlock()
%if "Opaque" != thisBlock.Type
%assign thisDWorkIdx = dwRec.SigSrc[3]
%if ISEMPTY(optionalArgs.DotName)
%assign ident = SLibInvokeTLCInterface(thisBlock, ...
"DWork", thisDWorkIdx, 0, TLC_FALSE, Ucv, Lcv, Idx, "")
%assign tlcIFv2Enable = !ISEMPTY(ident)
%if tlcIFv2Enable
%return ident
%endif
%else
%assign ident = SLibInvokeTLCInterface(thisBlock, ...
"DWork", thisDWorkIdx, 0, TLC_FALSE, "", "", "", "")
%assign tlcIFv2Enable = !ISEMPTY(ident)
%if tlcIFv2Enable
%return ident + optionalArgs.DotName + ...
SLibGet1DArrayIndexer(width, Ucv, Lcv, Idx)
%endif
%endif
%endif
%endif
%assign idxVec = SLibGetSystemAndCallSideIndex(dwRec)
%assign sysIdx = idxVec[0]
%assign base = SLibCG_GetVarGroupElementPath(dwRec.VarGroupIdx, ...
SLibGetHStructWithLocalScopeSystemIdx(HStructDeclSystemIdx), System[sysIdx].CrossNoArgFcnBound)
%return base + optionalArgs.DotName + ...
SLibGet1DArrayIndexer(width, Ucv, Lcv, Idx)
%endif
%endfunction
%function FcnSimpleGetDWork(dwRec, dwIdx, width, rollName, optionalArgs) void
%if Ucv != "" || Lcv == "" || (Lcv != "" && width == 1)
%return FcnNonRollingDWork(dwRec, dwIdx, width, optionalArgs)
%else
%return rollName + SLibGet1DArrayIndexer(width, Ucv, Lcv, Idx)
%endif
%endfunction
%function FcnLoopInfo(ucv, lcv, idx) void
%if ucv != "" || TYPE(idx) != "Number"
%assign idx = 0
%endif
%createrecord LoopInfo { Ucv ucv; Lcv lcv; Idx idx }
%return LoopInfo
%endfunction
%function LibBlockIsIndexZeroBased(block) void
%assign zeroBased = 0
%with block
%assign zeroBased = (EXISTS(IndexMode) && IndexMode == "Zero-based")
%endwith
%return zeroBased
%endfunction
%function LibBlockIsIndexOneBased(block) void
%assign oneBased = 0
%with block
%assign oneBased = (EXISTS(IndexMode) && IndexMode == "One-based")
%endwith
%return oneBased
%endfunction
%function LibBlockOutputPortIndexMode(block, pidx) void
%assign ret = ""
%with block
%assert (pidx >= 0 && pidx < NumDataOutputPorts)
%if EXISTS(NumIndexOutputPorts)
%foreach n = NumIndexOutputPorts
%assign ip = IndexOutputPort[n]
%if ip.PortIdx == pidx
%assign ret = ip.PortIndexMode
%endif
%endforeach
%endif
%endwith
%return ret
%endfunction
%function LibBlockInputPortIndexMode(block, pidx) void
%assign ret = ""
%with block
%assert (pidx >= 0 && pidx < NumDataInputPorts)
%if EXISTS(NumIndexInputPorts)
%foreach n = NumIndexInputPorts
%assign ip = IndexInputPort[n]
%if ip.PortIdx == pidx
%assign ret = ip.PortIndexMode
%endif
%endforeach
%endif
%endwith
%return ret
%endfunction
%function LibBlockNumInputPorts(block) void
%return block.NumDataInputPorts
%endfunction
%function LibBlockNumOutputPorts(block) void
%return block.NumDataOutputPorts
%endfunction
%endif
%function (dwRec) void
%if dwRec.GrSrc[1] == -1
%if dwRec.HasObject
%if !ISEMPTY(dwRec.OrigIdentifier)
%assign id = dwRec.OrigIdentifier
%else
%assign id = LibGetRecordIdentifier(dwRec)
%endif
%return "Simulink.Signal object '%<id>'"
%else
%return "synthesized block"
%endif
%else
%return "'" + SLibGrBlockCommentName(dwRec.GrSrc) + "'"
%endif
%endfunction
%function SLibBlockFcnRateGrouping(block,locFcnType)
%assign fcnName = locFcnType + "ForTID"
%with block
%assign tid = FcnEffectiveTid(block)
%assign numTIDs = TYPE(tid) == "Vector" ? SIZE(tid,1) : 1
%assign retVal = (numTIDs>1 || SLibNonInlinedModelWideEventTID(tid)) && ...
LibBlockFunctionExists(block, fcnName)
%endwith
%return retVal
%endfunction
%function SLibBlkHasMultirateCode(block)
%with block
%assign blkHasMultirateCode = -1
%assign tmpBufferHasDumpedForTID0 = TLC_FALSE
%if TYPE(TID) == "Vector"
%assign tid01Eq = ISEQUAL(SolverType, "FixedStep") && FixedStepOpts.TID01EQ
%foreach tid = SIZE(TID,1)
%if TYPE(tid) == "Number" && tid > 0
%if tid01Eq && (tid == 1)
%continue
%endif
%assign blkHasMultirateCode = blkHasMultirateCode + 1
%elseif !tmpBufferHasDumpedForTID0
%assign blkHasMultirateCode = blkHasMultirateCode + 1
%assign tmpBufferHasDumpedForTID0 = TLC_TRUE
%endif
%if blkHasMultirateCode == 1
%break
%endif
%endforeach
%endif
%endwith
%return blkHasMultirateCode > 0
%endfunction
%function SLibGetGlobalDWorkAddr(dwIdx, cross) void
%assign sigAddr = ""
%assign dw = ::CompiledModel.DWorks.DWork[dwIdx]
%if ISFIELD(dw, "FirstRootIdx")
%assign dw.FirstRootIdx = dwIdx
%else
%addtorecord dw FirstRootIdx dwIdx
%endif
%assign width = LibGetRecordWidth(dw)
%if ISFIELD(dw,"VarGroupIdx")
%assign varGroupIdx = ::CompiledModel.DWorks.DWork[dwIdx].VarGroupIdx[0]
%assign memberIdx = ::CompiledModel.DWorks.DWork[dwIdx].VarGroupIdx[1]
%return SLibCGIRDWorkGlobalCGVarBaseAddr(varGroupIdx, memberIdx, cross)
%else
%assert dw.StorageClass != "Auto"
%if LibGetRecordIsComplex(dw)
%assign indexExpr = "re0"
%else
%assign indexExpr = "0"
%endif
%if dw.StorageClass == "Custom"
%return SLibCG_CSCDWAddr(dwIdx, width, "", -1, "", indexExpr)
%else
%return SLibCG_VAddr(LibGetRecordIdentifier(dw), ...
dw.StorageClass == "ImportedExternPointer" && (width == 1), width, "", -1, "", indexExpr)
%endif
%endif
%endfunction
%function SLibBlockGetZCSignalIndexFromNSZCIdx(recIdx, NonSampledZCIdx) Output
%assign blkZcRecIdx = BlkZcRec[recIdx].BlkZcRecIdx
%assign blkZcRec = ::CompiledModel.ZcRec.BlkZcRec[blkZcRecIdx]
%assign numZcSignals = blkZcRec.NumZcSignalInfos
%assign numContZc = 0
%foreach i = numZcSignals
%assign zcs = blkZcRec.ZcSignalInfo[i]
%assign zcsType = zcs.ZcSignalType
%if zcsType == "Continuous"
%assign numContZc = numContZc + zcs.Width
%elseif zcsType == "Hybrid"
%foreach j = zcs.Width
%if zcs.IsElementDisc[j] != 1
%assign numContZc = numContZc + 1
%endif
%endforeach
%endif
%if numContZc >= NonSampledZCIdx + 1
%return i
%endif
%endforeach
%endfunction
%function SLibBlockGetZCSignalElIndexFromNSZCIdx( recIdx, NonSampledZCIdx) Output
%assign blkZcRecIdx = BlkZcRec[recIdx].BlkZcRecIdx
%assign blkZcRec = ::CompiledModel.ZcRec.BlkZcRec[blkZcRecIdx]
%assign numZcSignals = blkZcRec.NumZcSignalInfos
%assign numContZc =0
%foreach i = numZcSignals
%assign zcs = blkZcRec.ZcSignalInfo[i]
%assign zcsType = zcs.ZcSignalType
%foreach j = zcs.Width
%if zcsType == "Continuous"
%assign numContZc = numContZc + 1
%elseif zcsType == "Hybrid"
%if zcs.IsElementDisc[j]!= 1
%assign numContZc = numContZc + 1
%endif
%endif
%if numContZc == NonSampledZCIdx + 1
%return j
%endif
%endforeach
%endforeach
%endfunction
%function SLibBlockGetZCSignalIndexFromZCEIdx(recIdx, ZCEIdx) Output
%assign blkZcRecIdx = BlkZcRec[recIdx].BlkZcRecIdx
%assign blkZcRec = ::CompiledModel.ZcRec.BlkZcRec[blkZcRecIdx]
%assign numZcSignals = blkZcRec.NumZcSignalInfos
%assign numZCEvent = 0
%foreach i = numZcSignals
%assign zcs = blkZcRec.ZcSignalInfo[i]
%assign isEvent = zcs.NeedsEvent
%if isEvent == 1
%assign numZCEvent = numZCEvent + zcs.Width
%endif
%if numZCEvent >= ZCEIdx + 1
%return i
%endif
%endforeach
%endfunction
%function SLibBlockGetZCSignalElIndexFromZCEIdx(recIdx, ZCEIdx) Output
%assign blkZcRecIdx = BlkZcRec[recIdx].BlkZcRecIdx
%assign blkZcRec = ::CompiledModel.ZcRec.BlkZcRec[blkZcRecIdx]
%assign numZcSignals = blkZcRec.NumZcSignalInfos
%assign numZCEvent = 0
%foreach i = numZcSignals
%assign zcs = blkZcRec.ZcSignalInfo[i]
%assign isEvent = zcs.NeedsEvent
%if isEvent == 1
%foreach j = zcs.Width
%assign numZCEvent = numZCEvent + 1
%if numZCEvent == ZCEIdx + 1
%return j
%endif
%endforeach
%endif
%endforeach
%endfunction