%if EXISTS("_BLKIOLIB_") == 0
%assign _BLKIOLIB_ = 1
%include "blkio_api.tlc"
%include "blkio_internalapi.tlc"
%function PassExtInpByRef(extInp)
%if extInp.RecordType != "ExternalInput" || ...
extInp.StorageClass != "Auto"
%<LibReportFatalError("invalid record type or storage class")>
%endif
%assign dataType = LibGetRecordDataTypeId(extInp)
%assign passByRef = MultiInstanceERTCode && !RootIOStructures && ...
(::BlockFcn == "Registration" || ...
::BlockFcn == "Start" || ...
::BlockFcn == "Initialize" || ...
::BlockFcn == "Enable" || ...
::BlockFcn == "RegistrationAndStart" || ...
SLibDeclareDataAsPointer(dataType)) && ...
!LibGetRecordIsMatrix(extInp)
%return passByRef
%endfunction
%function PassExtOutpByRef(extOutp)
%assign passByRef = MultiInstanceERTCode && !RootIOStructures && ...
!LibGetRecordIsMatrix(extOutp)
%return passByRef
%endfunction
%function LibBlockInputSignal(portIdx, ucv, lcv, sigIdx) void
%if LibBlockInputSignalIsExpr(portIdx)
%assign ip = FcnGetInputPortRecord(portIdx)
%assign srcSys = System[ip.SrcIdx[0]]
%assign srcBlk = srcSys.Block[ip.SrcIdx[1]]
%assign srcPort = ip.SrcIdx[2]
%if lcv != ""
%if ucv != ""
%<LibReportFatalError("invalid indexing into output expression")>
%endif
%assign ucv = lcv
%assign lcv = ""
%endif
%with srcSys
%<FcnAddToExprCommentList(srcBlk, srcPort)>
%assign cast = LibOutputExprCast(srcBlk, srcPort)
%assign retSignal = SLibBlockOutputSignal(srcBlk,srcSys,srcPort,ucv,lcv,sigIdx,"Signal")
%if cast != ""
%assign retSignal = "(%<cast>%<retSignal>)"
%endif
%endwith
%assign srcBlk.ExprCommentSrcIdx.SysIdx = -1
%assign srcBlk.ExprCommentSrcIdx.BlkIdx = -1
%return SLibProcessSafeExpression(srcBlk.Name, retSignal, 1)
%endif
%if (ucv != "" && LibBlockInputSignalSymbolicWidth(portIdx) == "1")
%assign tmpVect = SLibGetReimAndIdx(sigIdx)
%assign reim = tmpVect[0]
%assign sigIdx = "%<reim>0"
%assign ucv = ""
%endif
%assign retSignal = FcnGetInputOrOutputSignal("input",portIdx, ucv, ...
lcv, sigIdx)
%return retSignal
%endfunction
%function (srcBlk, srcPort) void
%if ExprCommentSrcIdx.SysIdx != -1
%assign srcBlk.ExprCommentSrcIdx.SysIdx = ExprCommentSrcIdx.SysIdx
%assign srcBlk.ExprCommentSrcIdx.BlkIdx = ExprCommentSrcIdx.BlkIdx
%else
%assign srcBlk.ExprCommentSrcIdx.SysIdx = BlockIdx[0]
%assign srcBlk.ExprCommentSrcIdx.BlkIdx = BlockIdx[2]
%endif
%assign commSysIdx = srcBlk.ExprCommentSrcIdx.SysIdx
%assign commBlkIdx = srcBlk.ExprCommentSrcIdx.BlkIdx
%assign commInfo = System[commSysIdx].Block[commBlkIdx].ExprCommentInfo
%<SLibAddToExprCommentList(commInfo,srcBlk,srcPort)>
%endfunction
%function LibBlockInputSignalAddr(portIdx, ucv, lcv, sigIdx) void
%if LibBlockInputSignalIsExpr(portIdx)
%assign errTxt = "%<Type> block %<Name> has specified that input " ...
"port %<portIdx> can be an expression, however the block is " ...
"attempting to obtain the address of this input in TLC using " ...
"LibBlockInputSignalAddr. The conflict must be resolved."
%<LibReportFatalError(errTxt)>
%endif
%assign retSignal = FcnGetInputOrOutputSignal("inputAddr",portIdx, ucv, ...
lcv, sigIdx)
%return retSignal
%endfunction
%function LibBlockInputSignalIsMatrix(portIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%return LibGetRecordIsMatrix(ip)
%endfunction
%function LibBlockInputSignalSymbolicWidth(portIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%return LibGetRecordSymbolicWidth(ip)
%endfunction
%function LibBlockInputSignalSymbolicDims(portIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%return LibGetRecordSymbolicDims(ip)
%endfunction
%function LibBlockInputHasSymbolicWidth(portIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%return LibRecordHasSymbolicWidth(ip)
%endfunction
%function SLibNumInputPortRegions(aBlock, aInputPortIdx)
%assign numRegions = 0
%assign ip = aBlock.DataInputPort[aInputPortIdx]
%assign prevSrc = ""
%foreach idx = SIZE(ip.SignalSrc, 1)
%assign currSrc = IDNUM(ip.SignalSrc[idx])[0]
%if currSrc != prevSrc
%assign numRegions = numRegions + 1
%assign prevSrc = currSrc
%endif
%endforeach
%return numRegions
%endfunction
%function SLibBlockSystemToCallForInput(portIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%return ip.SystemToCall
%endfunction
%function LibBlockInputSignalSymbolicDimensions(portIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%return LibCGTypeSymbolicDimensions(LibGetRecordCGTypeIdx(ip))
%endfunction
%function LibBlockInputSignalDataTypeName(portIdx, reim) void
%if Type == "S-Function" && !ParamSettings.AliasDataTypeCompliant
%return LibBlockInputSignalAliasedThruDataTypeName(portIdx, reim)
%else
%assign ip = FcnGetInputPortRecord(portIdx)
%return SLibGetRecordDataTypeName(ip, reim)
%endif
%endfunction
%function LibBlockInputSignalAliasedThruDataTypeName(portIdx, reim) void
%assign ip = FcnGetInputPortRecord(portIdx)
%return LibGetRecordAliasedThruDataTypeName(ip, reim)
%endfunction
%function LibBlockInputSignalUnitId(portIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%return LibGetRecordUnitId(ip)
%endfunction
%function LibBlockInputSignalUnitExpr(portIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%return SLibGetRecordUnitExpr(ip)
%endfunction
%function LibBlockInputSignalASCIIEscapedUnitExpr(portIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%return SLibGetRecordASCIIEscapedUnitExpr(ip)
%endfunction
%function LibBlockInputPortIsContinuousQuantity(portIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%if EXISTS("ip.IsContinuousQuantity")
%if ip.IsContinuousQuantity == "yes"
%return TLC_TRUE
%endif
%endif
%return TLC_FALSE
%endfunction
%function LibBlockInputSignalSampleTime(portIdx) void
%if EXISTS("InputPortSampleTimes")
%assign idx = InputPortSampleTimes[portIdx]
%else
%assign errTxt = "SampleTime is not contained within the specified record"
%<LibBlockReportError([],errTxt)>
%endif
%return idx
%endfunction
%function LibBlockInputSignalOffsetTime(portIdx) void
%if EXISTS("InputPortOffsetTimes")
%assign idx = InputPortOffsetTimes[portIdx]
%else
%assign errTxt = "OffsetTime is not contained within the specified record"
%<LibBlockReportError([],errTxt)>
%endif
%return idx
%endfunction
%function LibBlockInputSignalSampleTimeIndex(portIdx) void
%if EXISTS("InputPortTIDs")
%assign idx = InputPortTIDs[portIdx]
%else
%assign errTxt = "SampleTimeIndex is not contained within the specified record"
%<LibBlockReportError([],errTxt)>
%endif
%return idx
%endfunction
%function LibBlockInputSignalLocalSampleTimeIndex(portIdx) void
%if EXISTS("InputPortLocalTIDs")
%assign idx = InputPortLocalTIDs[portIdx]
%else
%assign errTxt = "LocalSampleTimeIndex is not contained within the specified record"
%<LibBlockReportError([],errTxt)>
%endif
%return idx
%endfunction
%function LibBlockInputSignalBufferDstPort(portIdx)
%assign ip = FcnGetInputPortRecord(portIdx)
%if ip.BufferDstPort < 0
%foreach opIdx = NumDataOutputPorts
%if ip.SignalSrc[0] == DataOutputPort[opIdx].SignalSrc[0]
%return opIdx
%endif
%endforeach
%return -1
%else
%return ip.BufferDstPort
%endif
%endfunction
%function LibBlockInputSignalStorageClass(portIdx, sigIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%assign mapSource = IDNUM(ip.SignalSrc[sigIdx])[0]
%if (mapSource == "L" || mapSource == "b" || mapSource == "B" || ...
mapSource == "I" || mapSource == "C" || mapSource == "G" || ...
mapSource == "x" || mapSource == "X" || mapSource == "F" || ...
mapSource == "Y" || ...
ip.HaveGround == "all")
%return "Auto"
%else
%assign sigRec = SLibGetSourceRecord(ip, sigIdx)
%if (SLibIsLegacyStorageClassForDataRecord(sigRec))
%return "Custom"
%else
%return sigRec.StorageClass
%endif
%endif
%endfunction
%function LibBlockInputSignalStorageTypeQualifier(portIdx, sigIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%assign mapSource = IDNUM(ip.SignalSrc[sigIdx])[0]
%if (mapSource == "L" || mapSource == "b" || mapSource == "B" || ...
mapSource == "I" || mapSource == "G" || mapSource == "x" || ...
mapSource == "X" || mapSource == "F" || mapSource == "Y" || ...
ip.HaveGround == "all")
%return ""
%elseif mapSource == "C"
%assign tmpVec = LibBlockSrcSignalBlock(portIdx, sigIdx)
%assign sysIdx = tmpVec[0]
%assign blkIdx = tmpVec[1]
%assign srcBlock = ::CompiledModel.System[sysIdx].Block[blkIdx]
%if srcBlock.Parameters[0] == 1
%assign mdlParamIdx = ...
FcnGetModelParamIdxFromBlockParam(srcBlock.Parameter[0])
%if mdlParamIdx >= 0
%assign mdlParam = ModelParameters.Parameter[mdlParamIdx]
%return SLibGetModelParameterTypeQualifier(mdlParam)
%else
%return ""
%endif
%else
%return ""
%endif
%else
%assign sigRec = SLibGetSourceRecord(ip, sigIdx)
%return sigRec.StorageTypeQualifier
%endif
%endfunction
%function LibBlockOutputSignal(portIdx, ucv, lcv, sigIdx) void
%if LibBlockOutputSignalIsExpr(portIdx)
%return ""
%endif
%assign retSignal = FcnGetInputOrOutputSignal("output",portIdx, ucv, ...
lcv, sigIdx)
%return retSignal
%endfunction
%function LibBlockOutputSignalAddr(portIdx, ucv, lcv, sigIdx) void
%if LibBlockOutputSignalIsExpr(portIdx)
%return ""
%endif
%assign retSignal = FcnGetInputOrOutputSignal("outputAddr",portIdx, ucv, ...
lcv, sigIdx)
%return retSignal
%endfunction
%function LibBlockOutputSignalWidth(portIdx) void
%assign op = FcnGetOutputPortRecord(portIdx)
%assign opWidth = LibGetRecordWidth(op)
%if opWidth != -1
%return opWidth
%else
%assign sigRec = SLibGetSourceRecord(op, 0)
%if ISEMPTY(sigRec)
%return NumSFcnSysOutputCalls
%else
%return LibGetRecordWidth(sigRec)
%endif
%endif
%endfunction
%function LibBlockOutputSignalIsMatrix(portIdx) void
%assign ip = FcnGetOutputPortRecord(portIdx)
%return LibGetRecordIsMatrix(ip)
%endfunction
%function LibBlockOutputSignalSymbolicWidth(portIdx) void
%assign op = FcnGetOutputPortRecord(portIdx)
%if LibGetRecordIsMatrix(op)
%return LibGetRecordSymbolicWidth(op)
%else
%assign sigRec = SLibGetSourceRecord(op, 0)
%if ISEMPTY(sigRec)
%return NumSFcnSysOutputCalls
%else
%return LibGetRecordSymbolicWidth(sigRec)
%endif
%endif
%endfunction
%function LibBlockOutputHasSymbolicWidth(portIdx) void
%assign ip = FcnGetOutputPortRecord(portIdx)
%return LibRecordHasSymbolicWidth(ip)
%endfunction
%function LibBlockOutputSignalDimensions(portIdx) void
%assign op = FcnGetOutputPortRecord(portIdx)
%assign dims = LibGetRecordDimensions(op)
%if dims[0] != -1
%return dims
%else
%return LibBlockOutputSignalWidth(portIdx)
%endif
%endfunction
%function LibBlockOutputSignalSymbolicDimensions(portIdx) void
%assign op = FcnGetOutputPortRecord(portIdx)
%if LibGetRecordIsMatrix(op)
%return LibGetRecordSymbolicDimensions(op)
%else
%return LibGetRecordSymbolicWidth(op)
%endif
%endfunction
%function LibBlockOutputSignalNumDimensions(portIdx) void
%assign op = FcnGetOutputPortRecord(portIdx)
%assign dims = LibGetRecordDimensions(op)
%if dims[0] != -1
%return SIZE(dims,1)
%else
%return 1
%endif
%endfunction
%function LibBlockOutputSignalIsComplex(portIdx) void
%assign op = FcnGetOutputPortRecord(portIdx)
%return LibGetRecordIsComplex(op)
%endfunction
%function LibBlockOutputSignalDataTypeId(portIdx) void
%assign op = FcnGetOutputPortRecord(portIdx)
%if (IDNUM(op.SignalSrc[0])[0] == "F")
%return tSS_INVALID_DATA_TYPE_ID
%elseif Type == "S-Function" && !ParamSettings.AliasDataTypeCompliant
%return LibGetDataTypeIdAliasedThruToFromId(LibGetRecordDataTypeId(op))
%else
%return LibGetRecordDataTypeId(op)
%endif
%endfunction
%function LibBlockOutputSignalDataTypeName(portIdx, reim) void
%if Type == "S-Function" && !ParamSettings.AliasDataTypeCompliant
%return LibBlockOutputSignalAliasedThruDataTypeName(portIdx, reim)
%else
%assign op = FcnGetOutputPortRecord(portIdx)
%if (IDNUM(op.SignalSrc[0])[0] == "F")
%return ""
%else
%return SLibGetRecordDataTypeName(op, reim)
%endif
%endif
%endfunction
%function LibBlockOutputSignalAliasedThruDataTypeName(portIdx, reim) void
%assign op = FcnGetOutputPortRecord(portIdx)
%if (IDNUM(op.SignalSrc[0])[0] == "F")
%return ""
%else
%return LibGetRecordAliasedThruDataTypeName(op, reim)
%endif
%endfunction
%function LibBlockOutputSignalUnitId(portIdx) void
%assign op = FcnGetOutputPortRecord(portIdx)
%if (IDNUM(op.SignalSrc[0])[0] == "F")
%return 0
%else
%return LibGetRecordUnitId(op)
%endif
%endfunction
%function LibBlockOutputSignalUnitExpr(portIdx) void
%assign op = FcnGetOutputPortRecord(portIdx)
%if (IDNUM(op.SignalSrc[0])[0] == "F")
%return ""
%else
%return SLibGetRecordUnitExpr(op)
%endif
%endfunction
%function LibBlockOutputPortIsContinuousQuantity(portIdx) void
%assign ip = FcnGetOutputPortRecord(portIdx)
%if EXISTS("ip.IsContinuousQuantity")
%if ip.IsContinuousQuantity == "yes"
%return TLC_TRUE
%endif
%endif
%return TLC_FALSE
%endfunction
%function LibBlockAllOutputSignalsAreExpr() void
%if Type == "Opaque"
%return 0
%elseif NumDataOutputPorts >= 1
%foreach opIdx = NumDataOutputPorts
%if !LibBlockOutputSignalIsExpr(opIdx)
%return 0
%endif
%endforeach
%return 1
%else
%return 0
%endif
%endfunction
%function LibBlockSomeOutputSignalIsExpr() void
%foreach opIdx = NumDataOutputPorts
%if LibBlockOutputSignalIsExpr(opIdx)
%return 1
%endif
%endforeach
%return 0
%endfunction
%function LibBlockOutputSignalSampleTime(portIdx) void
%if EXISTS("OutputPortSampleTimes")
%assign idx = OutputPortSampleTimes[portIdx]
%else
%assign errTxt = "SampleTime is not contained within the specified record"
%<LibBlockReportError([],errTxt)>
%endif
%return idx
%endfunction
%function LibBlockOutputSignalOffsetTime(portIdx) void
%if EXISTS("OutputPortOffsetTimes")
%assign idx = OutputPortOffsetTimes[portIdx]
%else
%assign errTxt = "OffsetTime is not contained within the specified record"
%<LibBlockReportError([],errTxt)>
%endif
%return idx
%endfunction
%function LibBlockOutputSignalSampleTimeIndex(portIdx) void
%if EXISTS("OutputPortTIDs")
%assign idx = OutputPortTIDs[portIdx]
%else
%assign errTxt = "SampleTimeIndex is not contained within the specified record"
%<LibBlockReportError([],errTxt)>
%endif
%return idx
%endfunction
%function LibBlockOutputSignalLocalSampleTimeIndex(portIdx) void
%if EXISTS("OutputPortLocalTIDs")
%assign idx = OutputPortLocalTIDs[portIdx]
%else
%assign errTxt = "LocalSampleTimeIndex is not contained within the specified record"
%<LibBlockReportError([],errTxt)>
%endif
%return idx
%endfunction
%function LibBlockOutputSignalBeingMerged(portIdx) void
%if EXISTS("Connections.OutputPortBeingMerged")
%assign connected = (Connections.OutputPortBeingMerged[portIdx] == "yes")
%else
%assign errTxt = "OutputPortBeingMerged is not contained within the specified record"
%<LibBlockReportError([],errTxt)>
%endif
%return connected
%endfunction
%function LibBlockOutputSignalStorageClass(portIdx) void
%assign op = FcnGetOutputPortRecord(portIdx)
%assign mapSource = IDNUM(op.SignalSrc[0])[0]
%if (mapSource == "F")
%return "FcnCall"
%elseif (mapSource != "E" && mapSource != "y")
%return "Auto"
%else
%assign sigRec = SLibGetSourceRecord(op, 0)
%if SLibIsLegacyStorageClassForDataRecord(sigRec)
%return "Custom"
%elseif ISFIELD(sigRec, "StorageClass")
%return sigRec.StorageClass
%else
%assert mapSource != "E"
%return "Auto"
%endif
%endif
%endfunction
%function LibBlockOutputSignalStorageTypeQualifier(portIdx) void
%assign op = FcnGetOutputPortRecord(portIdx)
%assign mapSource = IDNUM(op.SignalSrc[0])[0]
%if (mapSource == "F")
%return "FcnCall"
%elseif (mapSource != "E" && mapSource != "y")
%return ""
%else
%assign sigRec = SLibGetSourceRecord(op, 0)
%if ISFIELD(sigRec, "StorageTypeQualifier")
%return sigRec.StorageTypeQualifier
%else
%assert mapSource != "E"
%return ""
%endif
%endif
%endfunction
%function LibBlockOutputSignalIsInBlockIO(portIdx) void
%assign op = FcnGetOutputPortRecord(portIdx)
%assign mapSource = IDNUM(op.SignalSrc[0])[0]
%if mapSource != "b" && mapSource != "B" && mapSource != "y"
%return 0
%else
%assign sigRec = SLibGetSourceRecord(op, 0)
%if ISFIELD(sigRec, "RequiredInBlockIO")
%return sigRec.RequiredInBlockIO[0]
%else
%return 0
%endif
%endif
%endfunction
%function LibBlockOutputSignalIsValidLValue(portIdx) void
%assign op = FcnGetOutputPortRecord(portIdx)
%assign mapSource = IDNUM(op.SignalSrc[0])[0]
%if (mapSource == "F")
%return 0
%elseif (mapSource == "I")
%assign sigRec = SLibGetSourceRecord(op, 0)
%return (sigRec.DoNotConstify == 1)
%else
%return 1
%endif
%endfunction
%function LibBlockOutputSignalIsGlobal(portIdx) void
%assign op = FcnGetOutputPortRecord(portIdx)
%assign mapSource = IDNUM(op.SignalSrc[0])[0]
%if (mapSource == "L" || mapSource == "C" || mapSource == "F")
%return 0
%else
%assign sigRec = SLibGetSourceRecord(op, 0)
%return !SLibOmitRecord(sigRec)
%endif
%endfunction
%function SLibBlockSystemToCallForOutput(portIdx) void
%assign ip = FcnGetOutputPortRecord(portIdx)
%return ip.SystemToCall
%endfunction
%function FcnCheckHasSrcSignalThing(thing, validThings, funcSuffix, typeOfThing) void
%if ...
thing != validThings[0] && ...
thing != validThings[1] && ...
thing != validThings[2]
%<LibBlockReportError([],"Cannot use " ...
"LibBlockSrcSignalLocation%<funcSuffix> with %<typeOfThing> "...
"/"%<thing>/", only with %<typeOfThing>s %<validThings>")>
%endif
%endfunction
%function FcnCheckHasSrcSignal(loc, funcSuffix) void
%assign validTypes = ["EnablePort", "TriggerPort", "Inport"]
%assign validLocs = ["enableblk", "triggerblk", "inportblk"]
%<FcnCheckHasSrcSignalThing(loc, validLocs, funcSuffix, "location" )>
%<FcnCheckHasSrcSignalThing(Type, validTypes, funcSuffix, "block type")>
%endfunction
%function LibBlockSrcSignalLocation(loc, ucv, lcv, sigIdx)
%<FcnCheckHasSrcSignal(loc, "")>
%return LibBlockInputSignal(loc, ucv, lcv, sigIdx)
%endfunction
%function LibBlockSrcSignalLocationAddr(loc, ucv, lcv, sigIdx)
%<FcnCheckHasSrcSignal(loc, "Addr")>
%return LibBlockInputSignalAddr(loc, ucv, lcv, sigIdx)
%endfunction
%function LibBlockSrcSignalLocationStorageClass(loc, sigIdx)
%<FcnCheckHasSrcSignal(loc, "StorageClass")>
%return LibBlockInputSignalStorageClass(loc, sigIdx)
%endfunction
%function LibBlockSrcSignalLocationStorageTypeQualifier(loc, sigIdx)
%<FcnCheckHasSrcSignal(loc, "StorageTypeQualifier")>
%return LibBlockInputSignalStorageTypeQualifier(loc, sigIdx)
%endfunction
%function LibBlockSrcSignalBlock(portIdx, sigIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%assign sigRec = SLibGetSourceRecord(ip, sigIdx)
%if ISEMPTY(sigRec)
%return "Ground"
%else
%if !ISFIELD(sigRec,"SigSrc") || ISEMPTY(sigRec.SigSrc)
%return 0
%else
%return Vector(2) [%, %]
%endif
%endif
%endfunction
%function SLibExternalOutputIsVirtual(opBlock)
%with opBlock
%assign vR = LibBlockParamSetting("Outport", "VirtualizableRoot")
%endwith
%return vR == "yes"
%endfunction
%function SLibBlockSrcSignalIsGnd(portIdx, sigIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%assign idNum = IDNUM(ip.SignalSrc[sigIdx])
%return (idNum[0] == "G")
%endfunction
%function LibBlockSrcSignalIsDiscrete(portIdx, sigIdx) void
%assign tmpVect = LibBlockSrcSignalBlock(portIdx, sigIdx)
%if TYPE(tmpVect) == "Vector"
%assign sysIdx = tmpVect[0]
%assign blkIdx = tmpVect[1]
%assign srcBlk = ::CompiledModel.System[sysIdx].Block[blkIdx]
%return LibIsDiscrete(srcBlk.TID)
%else
%return 0
%endif
%endfunction
%function LibBlockSrcSignalIsGlobalAndModifiable(portIdx, sigIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%assign mapSource = IDNUM(ip.SignalSrc[sigIdx])[0]
%if (mapSource == "b" || mapSource == "B" || mapSource == "E" || mapSource == "y")
%assign sigRec = SLibGetSourceRecord(ip, sigIdx)
%return !SLibOmitRecord(sigRec)
%endif
%return TLC_FALSE
%endfunction
%function LibBlockSrcSignalIsInvariant(portIdx, sigIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%assign mapSource = IDNUM(ip.SignalSrc[sigIdx])[0]
%return (mapSource == "I" || mapSource == "C")
%endfunction
%function LibBlockDstSignalLocation(loc, ucv, lcv, sigIdx) void
%assign tmpVect = SLibGetReimAndIdx(sigIdx)
%assign reim = tmpVect[0]
%assign idx = tmpVect[1]
%switch loc
%case "outportblk"
%if reim == tImagPart && !LibBlockInputSignalIsComplex(0)
%return ""
%endif
%assign inputWidth = LibBlockInputSignalSymbolicWidth(0)
%assign inputNumDims = LibGetRecordNumDimsFromContainerCgTypeIdx(FcnGetInputPortRecord(0))
%assign sigIndexer = SLibGet1DArrayIndexer(inputWidth, ucv, lcv, idx)
%if (ucv != "") || (lcv == "") || (lcv != "" && inputWidth == "1")
%assign outPortNum = LibBlockParamSetting("Outport", "PortNumber") - 1
%if CodeFormat == "S-Function"
%assign dtype = LibBlockInputSignalDataTypeName(0, "")
%assign ans = "((%<dtype> *)"...
"%<RTMGetIdxed("OutputPortSignal",outPortNum)>)"
%assign ans = ans + "[%<idx>]"
%else
%assign extOut = ExternalOutputs.ExternalOutput[outPortNum]
%if(extOut.Identifier != "")
%assign id = LibGetRecordIdentifier(extOut)
%else
%assign id = Identifier
%endif
%if(SLibDataRecordIsInCoderGroup(extOut))
%assign structName = SLibGetCoderDataGroupStructForRecord(extOut)
%else
%assign structName = SLibGetExternalOutputStruct(TLC_TRUE,TLC_TRUE,TLC_FALSE)
%endif
%assign accessSymb = YQualifier
%if(SLibDataRecordIsInCoderGroup(extOut))
%if( ISFIELD(extOut,"VarGroupIdx") )
%assign varGroupIdx = extOut.VarGroupIdx[0]
%assign varGroup = ::CompiledModel.VarGroups.VarGroup[varGroupIdx]
%if (LibGetVarGroupCategory(varGroupIdx) == "HierarchicalCoderData" && (varGroup.PackageAsStruct != 0) && ...
GenerateClassInterface && SLibAccessViaPointerInSelf(FcnGetCoderGroupForVarGroup(varGroup)))
%assign structName = varGroup.StructureReferenceName
%assign accessSymb = "->"
%endif
%endif
%endif
%if ISEMPTY(structName)
%assign ans = LibGetAddressOfFirstElement("%<id>", ...
inputNumDims) + "%<sigIndexer>"
%else
%assign ans = LibGetAddressOfFirstElement(...
"%<structName>%<accessSymb>%<id>", ...
inputNumDims) + "%<sigIndexer>"
%endif
%if MultiInstanceERTCode && ...
!(RootIOStructures || SLibHasGlobalExternalOutputsWithFPC()) && ...
inputWidth == "1"
%assign ans = "(*%<ans>)"
%endif
%<SLibAccessArgHelper(extOut,"",TID)>
%endif
%else
%assign ans = LibGetAddressOfFirstElement("y0", inputNumDims) + ...
"%<sigIndexer>"
%endif
%if reim != "" && LibBlockInputSignalIsComplex(0)
%assign ans = ans + ".%<reim>"
%endif
%return ans
%default
%assign errTxt = "Invalid location '%<loc>' specified."
%<LibBlockReportError([],errTxt)>
%endswitch
%endfunction
%function LibGetIsInputPortVarDims(portIdx)
%assign portObj = FcnGetInputPortRecord(portIdx)
%return SLibGetArgIsVarDims(portObj)
%endfunction
%function LibGetIsOutputPortVarDims(portIdx)
%assign portObj = FcnGetOutputPortRecord(portIdx)
%return SLibGetArgIsVarDims(portObj)
%endfunction
%function FcnBlockHasVarDimsInput()
%foreach ipIdx = NumDataInputPorts
%if LibGetIsInputPortVarDims(ipIdx)
%return TLC_TRUE
%endif
%endforeach
%return TLC_FALSE
%endfunction
%function FcnBlockHasVarDimsOutput()
%foreach opIdx = NumDataOutputPorts
%if LibGetIsOutputPortVarDims(opIdx)
%return TLC_TRUE
%endif
%endforeach
%return TLC_FALSE
%endfunction
%function FcnBlockNumVarDimsInput()
%assign num = 0
%foreach ipIdx = NumDataInputPorts
%if LibGetIsInputPortVarDims(ipIdx)
%assign num = num + 1
%endif
%endforeach
%return num
%endfunction
%function FcnBlockNumVarDimsOutput()
%assign num = 0
%foreach opIdx = NumDataOutputPorts
%if LibGetIsOutputPortVarDims(opIdx)
%assign num = num + 1
%endif
%endforeach
%return num
%endfunction
%function SLibGetDims(kind, portIdx, dimIdx) void
%return SLibInvokeTLCInterface(SLibGetCurrentBlock(), kind, portIdx, 0, ...
TLC_FALSE, "", "%<dimIdx>", "", "")
%endfunction
%function SLibGetCurrentOutputPortDimensions(portIdx, dimIdx) void
%assign dworkVar = SLibGetDims("OutputDims", portIdx, dimIdx)
%if !ISEMPTY(dworkVar)
%return dworkVar
%endif
%assign portObj = FcnGetOutputPortRecord(portIdx)
%assign the_hstruct = System[System[SystemIdx].HStructDeclSystemIdx]
%assign dimStr = TYPE(dimIdx) == "Number" ? "%<dimIdx>" : dimIdx
%if SLibGetArgUseCanDimSizeDW(portObj)
%assign can_dwork_idx = SLibGetCanDimSizeDWIdxForArg(portObj)
%assign dworkVar = LibGetRecordIdentifier(the_hstruct.Interface.CanonicalDWorkArgDef[can_dwork_idx])
%<SLibAccessArgHelper(the_hstruct.Interface.CanonicalDWorkArgDef[can_dwork_idx],"",...
System[SystemIdx].CurrentTID)>
%assign dworkVar = "%<dworkVar>[%<dimStr>]"
%else
%assert SLibGetArgUseSharedDimSizeDW(portObj)
%assign dworkRec = ::CompiledModel.DWorks.DWork[portObj.DimSizeDWork]
%assign width = LibCGTypeWidth(LibGetRecordCGTypeIdx(dworkRec))
%if dworkRec.StorageClass == "Auto"
%assign dworkVar = SLibCG_DWV(portObj.DimSizeDWork, ...
System[SystemIdx].CrossNoArgFcnBound, the_hstruct.SystemIdx, ...
width, "", -1, dimStr, 0)
%else
%assign dworkVar = SLibCG_V(LibGetRecordIdentifier(dworkRec), TLC_FALSE, width, ...
"", -1, dimStr, 0)
%endif
%endif
%return dworkVar
%endfunction
%function SLibSetCurrentOutputPortDimensions(portIdx, dimIdx, dimSize) Output
%<SLibGetCurrentOutputPortDimensions(portIdx, dimIdx)> = %<dimSize>;
%endfunction
%function SLibGetCurrentInputPortDimensions(portIdx, dimIdx) void
%assign dworkVar = SLibGetDims("InputDims", portIdx, dimIdx)
%if !ISEMPTY(dworkVar)
%return dworkVar
%endif
%assign portObj = FcnGetInputPortRecord(portIdx)
%assign the_hstruct = System[System[SystemIdx].HStructDeclSystemIdx]
%assign dimStr = TYPE(dimIdx) == "Number" ? "%<dimIdx>" : dimIdx
%if SLibGetArgUseCanDimSizeDW(portObj)
%assign can_dwork_idx = SLibGetCanDimSizeDWIdxForArg(DataInputPort[portIdx])
%assign dworkVar = LibGetRecordIdentifier(the_hstruct.Interface.CanonicalDWorkArgDef[can_dwork_idx])
%<SLibAccessArgHelper(the_hstruct.Interface.CanonicalDWorkArgDef[can_dwork_idx],"",...
System[SystemIdx].CurrentTID)>
%assign dworkVar = "%<dworkVar>[%<dimStr>]"
%else
%assert SLibGetArgUseSharedDimSizeDW(portObj)
%assign dworkRec = ::CompiledModel.DWorks.DWork[portObj.DimSizeDWork]
%if ISFIELD(dworkRec, "VarGroupIdx") && ...
LibGetVarGroupCategory(dworkRec.VarGroupIdx[0]) == "ExternalInputSize"
%if CodeFormat == "S-Function"
%assign sigRecAndMapInfo = SLibGetSourceRecordAndMapInfo(...
portObj, 0, TLC_TRUE, TLC_FALSE)
%assign extIn = sigRecAndMapInfo.sigRec
%assign sizeTypeIdx = SLibCGVarGroupMemberCGTypeIdx(...
extIn.SizeVarGroupIdx[0], ...
extIn.SizeVarGroupIdx[1])
%assign sizeTypeWidth = LibCGTypeWidth(sizeTypeIdx)
%return SLibGetInportSize(...
sigRecAndMapInfo.mapIdx, sizeTypeWidth, "", -1, dimStr, 0)
%else
%assign width = LibCGTypeWidth(LibGetRecordCGTypeIdx(dworkRec))
%assign varGroup = ::CompiledModel.VarGroups.VarGroup[dworkRec.VarGroupIdx[0]]
%assign identifier = varGroup.Name + "." + LibGetRecordIdentifier(dworkRec)
%return SLibCG_V(identifier, TLC_FALSE, width, ...
"", -1, dimStr, 0)
%endif
%else
%assign width = LibCGTypeWidth(LibGetRecordCGTypeIdx(dworkRec))
%if dworkRec.StorageClass == "Auto"
%assign dworkVar = SLibCG_DWV(portObj.DimSizeDWork, ...
System[SystemIdx].CrossNoArgFcnBound, the_hstruct.SystemIdx, ...
width, "", -1, dimStr, 0)
%else
%assign dworkVar = SLibCG_V(LibGetRecordIdentifier(dworkRec), TLC_FALSE, width, ...
"", -1, dimStr, 0)
%endif
%endif
%endif
%return dworkVar
%endfunction
%function FcnGetInputPortRecord(portIdx) void
%<LibGetInputPortRecordIsValid(portIdx)>
%if portIdx >= 0 && portIdx < NumDataInputPorts
%assign ip = DataInputPort[portIdx]
%else
%assign errTxt = "The specified port index '%<TYPE(portIdx)>' " ...
"should be a number between 0 and %."
%<LibBlockReportError([],errTxt)>
%endif
%return ip
%endfunction
%function FcnGetOutputPortRecord(portIdx) void
%if portIdx >= 0 && portIdx < NumDataOutputPorts
%assign op = DataOutputPort[portIdx]
%else
%assign errTxt = "The specified port index '%<TYPE(portIdx)>' " ...
"of %<Name> should be a number between 0 and %."
%<LibBlockReportError([],errTxt)>
%endif
%return op
%endfunction
%function SLibGetMapSrcAndMapIdx(port, sigIdx)
%if SIZE(port.SignalSrc, 1) > 1
%assign idNum = IDNUM(port.SignalSrc[sigIdx])
%else
%assign idNum = IDNUM(port.SignalSrc[0])
%endif
%return idNum
%endfunction
%function FcnGetMapSrcAndMapIdx(portIdx, sigIdx) void
%assign ip = FcnGetInputPortRecord(portIdx)
%return SLibGetMapSrcAndMapIdx(ip, sigIdx)
%endfunction
%function FcnReportNonAddressableError(bInput, sigRec) void
%assign block = SLibGetCurrentBlock()
%<SLibReportNonAddressableError(bInput ? "Input" : "Output", block, sigRec)>
%endfunction
%function FcnAddrHandling(bAddr, returnBaseAddr, identi, identiIsPointer, sigSrcWidth, ...
busSelElIdx, sigIndexer, rm)
%assign retVal = ""
%if bAddr
%if returnBaseAddr
%if identiIsPointer
%if (sigSrcWidth > 1) || (!ISEMPTY(busSelElIdx))
%assign retVal = "(*(" + identi + "))" + busSelElIdx
%else
%assign retVal = identi
%endif
%else
%if (sigSrcWidth > 1)
%assign retVal = identi + busSelElIdx
%else
%assign retVal = "&" + identi + busSelElIdx
%endif
%endif
%else
%if identiIsPointer
%assign retVal = "&(*" + identi + ")" + busSelElIdx + sigIndexer
%else
%assign retVal = "&" + identi + busSelElIdx + sigIndexer
%endif
%endif
%else
%if identiIsPointer
%assign retVal = "(*" + identi + ")" + busSelElIdx + sigIndexer + rm
%else
%assign retVal = identi + busSelElIdx + sigIndexer + rm
%endif
%endif
%return retVal
%endfunction
%function FcnGetArrayElementSignalReference(fcn, sigIdx)
%assign numChars = SIZE(sigIdx, 1)
%assign isPureIdx = TLC_TRUE
%foreach charIdx = numChars
%if (sigIdx[charIdx] == "]") && (charIdx < numChars - 2)
%assign isPureIdx = TLC_FALSE
%break
%endif
%endforeach
%if isPureIdx
%assign retVal = fcn + "("
%foreach charIdx = numChars-2
%assign retVal = retVal + sigIdx[charIdx + 1]
%endforeach
%assign retVal = retVal + ")"
%return retVal
%else
%return FcnGetBusArraySignalReference(fcn, sigIdx)
%endif
%endfunction
%function FcnGetBusArraySignalReference(fcn, sigIdx)
%assert((sigIdx[0] == ".") || (sigIdx[0] == "["))
%if (sigIdx[0] == ".")
%return "(%<fcn>())%<sigIdx>"
%else
%assign retref = "(%<fcn>"
%assign numChars = SIZE(sigIdx,1)
%assign endBracketReplaced = 0
%foreach elIdx = numChars
%if (elIdx == 0)
%assign retref = retref + "("
%elseif ((sigIdx[elIdx] == "]") && (endBracketReplaced == 0))
%assign retref = retref + "))"
%assign endBracketReplaced = 1
%else
%assign retref = retref + sigIdx[elIdx]
%endif
%endforeach
%return retref
%endif
%endfunction
%function FcnGetAccessFunctionSignalReference(sigRec, addr, sigIdx) void
%assert sigRec.UseAccessFunctions
%assign mode = sigRec.AccessMode
%if addr
%if mode == "Reference"
%assign fcn = sigRec.GetAccessFunction
%return fcn + "()"
%else
%assign err = "Unable to take address of access method"
%<LibReportFatalError(err)>
%endif
%else
%if mode == "Reference"
%assign fcn = sigRec.GetAccessFunction
%if ISEMPTY(sigIdx)
%return "(*(" + fcn + "()))"
%else
%return fcn + "()" + sigIdx
%endif
%else
%assert mode == "Value"
%assign fcn = sigRec.GetElementAccessFunction
%if ISEMPTY(sigIdx)
%return fcn + "()"
%else
%return FcnGetArrayElementSignalReference(fcn, sigIdx)
%endif
%endif
%endif
%endfunction
%function FcnSetAccessFunctionSignalReference(sigRec, sigIdx, rhs) void
%assert sigRec.UseAccessFunctions
%assign mode = sigRec.AccessMode
%if mode == "Reference"
%assign fcn = sigRec.SetAccessFunction
%if ISEMPTY(sigIdx)
%return "(*(" + fcn + "())) = " + rhs + ";"
%else
%return fcn + "()" + sigIdx + " = " + rhs + ";"
%endif
%else
%assert mode == "Value"
%assign fcn = sigRec.SetElementAccessFunction
%if ISEMPTY(sigIdx)
%return fcn + "(" + rhs + ");"
%else
%assign debracedIdx = ""
%foreach sIdx = SIZE(sigIdx,1) - 2
%assign debracedIdx = debracedIdx + sigIdx[sIdx+1]
%endforeach
%return fcn + "(" + debracedIdx + ", " + rhs + ");"
%endif
%endif
%endfunction
%function FcnCheckForNonAddressableError(aInput, aAddr, aSigRec, aStorageClass) void
%if (aAddr && ...
((ISFIELD(aSigRec, "UseAccessFunctions") && aSigRec.UseAccessFunctions && aSigRec.AccessMode != "Reference") || ...
(aStorageClass == "Custom" && !LibCustomDataIsAddressable(aSigRec))))
%<FcnReportNonAddressableError(aInput, aSigRec)>
%endif
%endfunction
%function FcnGetBasicSignalReference(sigRecAndMapInfo, portWidth, reim, ...
bInput, bAddr, isComplex, isStdContainer, ucv, lcv, cross) void
%assign sigRec = sigRecAndMapInfo.sigRec
%assign mapSource = sigRecAndMapInfo.mapSrc
%assign mapIdx = sigRecAndMapInfo.mapIdx
%assign sigSrcWidth = LibGetRecordWidth(sigRec)
%assign sigOffset = sigRecAndMapInfo.signalOffset
%assign busSelElIdx = sigRecAndMapInfo.busSelElIdx
%assign busSelElCGTypeId = sigRecAndMapInfo.busSelElCGTypeId
%if (!ISEMPTY(busSelElIdx) && busSelElCGTypeId != -1)
%assign sigSrcWidth = LibCGTypeWidth(busSelElCGTypeId)
%endif
%if sigRecAndMapInfo.symbolicSignalOffset > -1
%assign symbolicOffset = "(" + ...
LibCGTypeSymbolicWidth(sigRecAndMapInfo.symbolicSignalOffset) + ")"
%assign sigOffset = 0
%if WHITE_SPACE(ucv)
%assign ucv = symbolicOffset
%else
%assign ucv = ucv + "+" + symbolicOffset
%endif
%endif
%assign returnBaseAddr = (sigOffset == 0 && ucv == "" && lcv == "" && bAddr && portWidth > 1 && sigSrcWidth == portWidth) && !isStdContainer
%if bInput && sigSrcWidth > 1 && portWidth == 1
%assign sigIndexer = SLibGet1DArrayIndexer(sigSrcWidth, ...
"", "", sigOffset)
%assign lcv = ""
%else
%assign sigIndexer = SLibGet1DArrayIndexer(sigSrcWidth, ...
ucv, lcv, sigOffset)
%endif
%if mapSource != "Y"
%assign storageClass = sigRec.StorageClass
%else
%assign storageClass = "Auto"
%endif
%if SLibIsLegacyStorageClassForDataRecord(sigRec)
%assign storageClass = "Custom"
%endif
%if reim != "" && isComplex
%assign rm = ".%<reim>"
%else
%assign rm = ""
%endif
%if !ISEMPTY(sigRecAndMapInfo.identi)
%assign tempVal = FcnAddrHandling(bAddr, returnBaseAddr, sigRecAndMapInfo.identi, ...
sigRecAndMapInfo.isPointer, sigSrcWidth, busSelElIdx, sigIndexer, rm)
%if !ISEMPTY(tempVal)
%return tempVal
%endif
%endif
%assign scalarInputPassedByAddr = TLC_FALSE
%assign scalarOutputPassedByAddr = TLC_FALSE
%switch (mapSource)
%case "C"
%assign sysRef = System[sigRec.SigSrc[0]]
%assign blkRef = sysRef.Block[sigRec.SigSrc[2]]
%assign oPort = sigRec.SigSrc[3]
%if !bInput
%assign sigOffset = 0
%endif
%if GeneratingOutputsCode
%<FcnAddToExprCommentList(blkRef, oPort)>
%assign blkRef.ExprCommentSrcIdx.SysIdx = -1
%assign blkRef.ExprCommentSrcIdx.BlkIdx = -1
%endif
%if !ISEMPTY(busSelElIdx)
%assign sigIndexer = SLibGet1DArrayIndexer(sigSrcWidth, ...
ucv, lcv, sigOffset)
%assign retSignal = SLibBlockOutputSignal(...
blkRef,sysRef,oPort,"","","", bAddr ? "SignalAddr" : "Signal")
%assign identiIsPointer = TLC_FALSE
%assign len = SIZE(retSignal,1)
%foreach idx = len
%if retSignal[idx] == "&"
%assign identiIsPointer = TLC_TRUE
%break
%endif
%endforeach
%assign retSignal = FcnAddrHandling(bAddr, returnBaseAddr, retSignal, ...
identiIsPointer, sigSrcWidth, busSelElIdx, sigIndexer, rm)
%else
%assign sigIdx = "%<reim>%<sigOffset>"
%if sigOffset != 0
%if ucv != ""
%assign ucv = "%<ucv>+%<sigOffset>"
%assign sigIdx = "%<reim>0"
%elseif lcv != ""
%assign lcv = "%<lcv>+%<sigOffset>"
%assign sigIdx = "%<reim>0"
%endif
%endif
%assign retSignal = SLibBlockOutputSignal(blkRef,sysRef,oPort,...
ucv,lcv,sigIdx, bAddr ? "SignalAddr" : "Signal")
%endif
%return retSignal
%case "E"
%if storageClass == "Custom"
%<FcnCheckForNonAddressableError(bInput, bAddr, sigRec, storageClass)>
%return LibCustomData(sigRec, bAddr ? "address" : "contents", ...
busSelElIdx + sigIndexer, reim)
%else
%assign retSignalWithoutIndexer = LibGetRecordIdentifier(sigRec)
%endif
%if reim != "" && isComplex
%if storageClass == "ImportedExtern" || ...
storageClass == "ImportedExternPointer"
%assign errTxt = ...
"Imported complex signals not supported: " + ...
retSignalWithoutIndexer
%<LibBlockReportError([],errTxt)>
%endif
%endif
%assign retSignal = retSignalWithoutIndexer + busSelElIdx + sigIndexer
%if reim != "" && isComplex
%assign retSignal = retSignal + ".%<reim>"
%endif
%break
%case "I"
%if !sigRec.RequiredInConstBlockIO && !GeneratingDeadCode
%assign sigRec.RequiredInConstBlockIO = 1
%assign blkOutsRec = ::CompiledModel.BlockOutputs
%assign blkOutsRec.NumSignalsInConstBlockIO = ...
blkOutsRec.NumSignalsInConstBlockIO + 1
%endif
%assign accessSysIdx = SLibGetHStructWithLocalScopeSystemIdx(SystemIdx)
%assign varGroupIdx = sigRec.VarGroupIdx[0]
%assign varGroup = ::CompiledModel.VarGroups.VarGroup[varGroupIdx]
%assign sysIdx = varGroup.SysIdx
%assign instanceIdx = varGroup.InstanceIdx
%assign retSignalWithoutIndexer = ...
SLibCG_GetVarGroupElementPath(sigRec.VarGroupIdx, accessSysIdx, ...
CrossNoArgFcnBound)
%assign retSignal = retSignalWithoutIndexer + busSelElIdx + sigIndexer
%if reim != "" && isComplex
%assign retSignal = retSignal + ".%<reim>"
%endif
%break
%case "D"
%assign signalName = LibGetDWorkStruct() + DWorkQualifier + LibGetRecordIdentifier(sigRec)
%assign retSignal = signalName + busSelElIdx + sigIndexer
%break
%case "X"
%assign signalName = LibGetContinuousStateStruct() + XQualifier + sigRec.Identifier
%assign retSignal = signalName + busSelElIdx + sigIndexer
%break
%case "U"
%if GeneratingOutputsCode
%if Type != "Opaque"
%assign commSysIdx = ExprCommentSrcIdx.SysIdx
%assign commBlkIdx = ExprCommentSrcIdx.BlkIdx
%if commSysIdx != -1 && commBlkIdx != -1
%assign commInfo = System[commSysIdx].Block[commBlkIdx].ExprCommentInfo
%else
%assign commInfo = ExprCommentInfo
%endif
%else
%assign commInfo = ExprCommentInfo
%endif
%<SLibAddToExprCommentList(commInfo,sigRec,0)>
%endif
%if storageClass != "Auto"
%if CodeFormat == "S-Function"
%assign args = [%<LibGetRecordIdentifier(sigRec)>, storageClass]
%<SLibReportErrorWithIdAndArgs("RTW:tlc:UnsupportStorageInRootU", args)>
%endif
%if storageClass == "Custom"
%<FcnCheckForNonAddressableError(bInput, bAddr, sigRec, storageClass)>
%return LibCustomData(sigRec, bAddr ? "address" : "contents", ...
busSelElIdx + sigIndexer, reim)
%endif
%assign retSignal = "%<LibGetRecordIdentifier(sigRec)>%<busSelElIdx>%<sigIndexer>"
%if reim != ""
%if storageClass == "ImportedExtern" || ...
storageClass == "ImportedExternPointer"
%<SLibReportErrorWithIdAndArgs("RTW:tlc:NoImportedComplex", retSignal)>
%else
%assign retSignal = retSignal + ".%<reim>"
%endif
%endif
%else
%if sigRec.UseAccessFunctions
%<FcnCheckForNonAddressableError(bInput, bAddr, sigRec, storageClass)>
%return FcnGetAccessFunctionSignalReference(sigRec, bAddr, busSelElIdx + sigIndexer)
%endif
%if CodeFormat != "S-Function" || Accelerator
%if SLibFcnProtoCtrlActive() && sigRec.RequiresGlobalAccess == "no"
%assign fcnData = FcnGetFunctionPrototypeRecord()
%assign spec = FcnGetFcnDataForPort(fcnData, "Inport", mapIdx)
%assign identifier = spec.ArgName
%assign scalarInputPassedByAddr = spec.Category == "Pointer" && (sigSrcWidth == 1)
%assign derefNeeded = scalarInputPassedByAddr && !bAddr
%elseif GenerateClassInterface && sigRec.RequiresGlobalAccess == "no"
%assign classConfObj = FcnGetRTWCPPStepPrototypeRecord()
%if !classConfObj.hasGlobalAccessForInport
%assign spec = FcnGetFcnDataForPort(classConfObj, "Inport", mapIdx)
%assign identifier = spec.ArgName
%assign scalarInputPassedByAddr = spec.Category == "Pointer" && (sigSrcWidth == 1)
%assign derefNeeded = scalarInputPassedByAddr && !bAddr
%else
%assign identifier = "%<SLibGetExternalInputStruct(TLC_TRUE,TLC_TRUE,cross)>%<UQualifier>%<LibGetRecordIdentifier(sigRec)>"
%assign derefNeeded = PassExtInpByRef(sigRec)
%endif
%else
%assign identifier = "%<SLibGetExternalInputStruct(TLC_TRUE,TLC_TRUE,cross)>%<UQualifier>%<LibGetRecordIdentifier(sigRec)>"
%assign derefNeeded = PassExtInpByRef(sigRec)
%endif
%if derefNeeded
%assign retSignal = ...
"(*%<identifier>)%<busSelElIdx>%<sigIndexer>"
%else
%assign retSignal = ...
"%<identifier>%<busSelElIdx>%<sigIndexer>"
%endif
%if reim != ""
%assign retSignal = retSignal + ".%<reim>"
%endif
%else
%assign dataType = SLibGetRecordDataTypeName(sigRec, "")
%if ISEMPTY(busSelElIdx) || LibGetRecordWidth(sigRec) > 1
%assign derefOnAnchor = ""
%else
%assign derefOnAnchor = "*"
%endif
%assign extInp = ::CompiledModel.ExternalInputs.ExternalInput[mapIdx]
%if ISFIELD(extInp, "HasVarDims")
%assign anchor = "(%<derefOnAnchor>(const %<dataType>*)"...
"ssGetInputPortSignal(%<SLibGetSimStruct()>, %<mapIdx>))"
%else
%assign anchor = "(%<derefOnAnchor>*((const %<dataType>**)"...
"ssGetInputPortSignalPtrs(%<SLibGetSimStruct()>, %<mapIdx>)))"
%endif
%assign sigIndexer = (ISEMPTY(busSelElIdx) && ISEMPTY(sigIndexer)) ? "[0]" : sigIndexer
%assign retSignal = "%<anchor>%<busSelElIdx>%<sigIndexer>"
%if reim != ""
%assign retSignal = "(%<retSignal>.%<reim>)"
%endif
%endif
%endif
%break
%case "Y"
%if storageClass != "Auto"
%if CodeFormat == "S-Function"
%assign args = [%<LibGetRecordIdentifier(sigRec)>, storageClass]
%<SLibReportErrorWithIdAndArgs("RTW:tlc:UnsupportStorageInRootY", args)>
%endif
%if storageClass == "Custom"
%<FcnCheckForNonAddressableError(bInput, bAddr, sigRec, storageClass)>
%return LibCustomData(sigRec, bAddr ? "address" : "contents", ...
busSelElIdx + sigIndexer, reim)
%endif
%else
%if sigRec.UseAccessFunctions
%<FcnCheckForNonAddressableError(bInput, bAddr, sigRec, storageClass)>
%return FcnGetAccessFunctionSignalReference(sigRec, bAddr, busSelElIdx + sigIndexer)
%endif
%<LibAccessArg(sigRec)>
%if SLibFcnProtoCtrlActive() && sigRec.RequiresGlobalAccess == "no"
%assign fcnData = FcnGetFunctionPrototypeRecord()
%assign spec = FcnGetFcnDataForPort(fcnData, "Outport", mapIdx)
%assign identifier = spec.ArgName
%assign scalarOutputPassedByAddr = spec.Category == "Pointer" && (sigSrcWidth == 1)
%assign derefNeeded = scalarOutputPassedByAddr && !bAddr
%elseif GenerateClassInterface && sigRec.RequiresGlobalAccess == "no"
%assign classConfObj = FcnGetRTWCPPStepPrototypeRecord()
%if !classConfObj.hasGlobalAccessForOutport
%assign spec = FcnGetFcnDataForPort(classConfObj, "Outport", mapIdx)
%assign identifier = spec.ArgName
%assign scalarOutputPassedByAddr = spec.Category == "Pointer" && (sigSrcWidth == 1)
%assign derefNeeded = scalarOutputPassedByAddr && !bAddr
%else
%assign identifier = "%<SLibGetExternalOutputStruct(TLC_TRUE,TLC_TRUE,cross)>%<UQualifier>%<LibGetRecordIdentifier(sigRec)>"
%assign derefNeeded = PassExtOutpByRef(sigRec)
%endif
%else
%assign identifier = "%<SLibGetExternalOutputStruct(TLC_TRUE,TLC_TRUE,cross)>%<UQualifier>%<LibGetRecordIdentifier(sigRec)>"
%assign derefNeeded = PassExtOutpByRef(sigRec)
%endif
%if derefNeeded
%assign retSignal = ...
"(*%<identifier>)%<busSelElIdx>%<sigIndexer>"
%else
%assign retSignal = ...
"%<identifier>%<busSelElIdx>%<sigIndexer>"
%endif
%if reim != ""
%assign retSignal = retSignal + ".%<reim>"
%endif
%endif
%break
%case "G"
%default
%
%endswitch
%assign cast = ""
%if mapSource == "I"
%assign dtypeName = LibGetRecordDataTypeName(sigRec, "")
%assign cast = "(%<dtypeName>*)"
%endif
%if bAddr && !scalarInputPassedByAddr && ...
!scalarOutputPassedByAddr && ...
((storageClass != "ImportedExternPointer") || (sigSrcWidth > 1))
%assign retSignal = cast + "&" + retSignal
%endif
%return retSignal
%endfunction
%function FcnGetGroundSignalValue(dtID, isComplex, reim) void
%if isComplex && reim == ""
%assign retSignal = SLibGetDtGroundName(dtID, isComplex, reim)
%<SLibSetDataTypeComplexGroundReqInMemory(dtID)>
%else
%if LibIsDataTypeMultiWordFixpt(dtID)
%assign retSignal = SLibGetDtGroundName(dtID, isComplex, reim)
%<SLibSetDataTypeGroundReqInMemory(dtID)>
%else
%assign retSignal = SLibGetDtGroundValue(dtID, isComplex, reim, 1)
%if TYPE(retSignal) != "String"
%assign retSignal = SLibGetFormattedValueFromId(dtID, retSignal)
%endif
%endif
%endif
%return retSignal
%endfunction
%function FcnGetGroundSignalAddr(dtID, isComplex, reim) void
%assign retSignal = "&" + SLibGetDtGroundName(dtID, isComplex, "")
%assign dtypeName = ""
%if isComplex
%assign dtypeName = LibGetDataTypeComplexNameFromId(dtID)
%else
%assign dtypeName = LibGetDataTypeNameFromId(dtID)
%endif
%assign cast = "(%<dtypeName>*)"
%assign retSignal = "(%<cast> %<retSignal>)"
%if isComplex
%<SLibSetDataTypeComplexGroundReqInMemory(dtID)>
%else
%<SLibSetDataTypeGroundReqInMemory(dtID)>
%endif
%return retSignal
%endfunction
%function FcnGetGroundSignalReference(sigKind, dtID, isComplex, reim) void
%switch sigKind
%case "input"
%return FcnGetGroundSignalValue(dtID, isComplex, reim)
%case "inputAddr"
%return FcnGetGroundSignalAddr(dtID, isComplex, reim)
%default
%<SLibReportErrorWithIdAndArgs("RTW:tlc:UnexpectedSigKind", sigKind)>
%endswitch
%return ""
%endfunction
%function FcnGetLocalDWorkIdentifier(blkSysIdx, accessSysIdx, sigIdx) void
%assign dwRec = DWorks.DWork[sigIdx]
%if dwRec.StorageClass == "Auto"
%if CodeFormat == "S-Function" && !Accelerator
%assign idxStr = SLibDWorkWidth(dwRec) == 1 ? "[0]" : ""
%return SLibGetGlobalDWorkIdentifier(dwRec, sigIdx) + idxStr
%else
%assign varGroup = ::CompiledModel.VarGroups.VarGroup[dwRec.VarGroupIdx[0]]
%return SLibCG_GetVarGroupElementPath(dwRec.VarGroupIdx, accessSysIdx, ...
System[varGroup.SysIdx].CrossNoArgFcnBound)
%endif
%else
%return ""
%endif
%endfunction
%function FcnGetLocalCStateIdentifier(blkSysIdx, accessSysIdx, sigIdx) void
%assign csRec = ::CompiledModel.ContStates.ContState[sigIdx]
%assign varGroupIdx = csRec.VarGroupIdx[0]
%assign cross = CrossNoArgFcnBound
%assign identiPath = SLibCGIRVarGroupPath(varGroupIdx, accessSysIdx, cross)
%return identiPath + csRec.Identifier
%endfunction
%function FcnGetCanonicalArg(portObj, sigIdx, cross, scalarByAddr) void
%assign sigRecAndMapInfo = ...
SLibGetSourceRecordAndMapInfo(portObj, sigIdx, TLC_TRUE, TLC_FALSE)
%assign bAddr = TLC_FALSE
%assign sigType = "input"
%assign portWidth = LibGetRecordWidth(portObj)
%assign identi = sigRecAndMapInfo.identi
%if portWidth > 1 || (scalarByAddr && portWidth == 1)
%assign sigOffset = sigRecAndMapInfo.signalOffset
%if !ISEMPTY(identi) && sigOffset == 0
%if portWidth > 1
%if ISFIELD(portObj, "SrcIsPointerToArray") && portObj.SrcIsPointerToArray == "yes"
%return "*" + identi
%else
%return identi
%endif
%endif
%endif
%assign bAddr = TLC_TRUE
%assign sigType = "inputAddr"
%endif
%assign signalRec = sigRecAndMapInfo.sigRec
%assign mapSource = sigRecAndMapInfo.mapSrc
%if mapSource=="G" || ISEMPTY(signalRec)
%assign dtID = LibGetRecordDataTypeId(portObj)
%return FcnGetGroundSignalReference(sigType, dtID, TLC_FALSE, "")
%else
%assign retSignal = FcnGetBasicSignalReference(sigRecAndMapInfo, ...
portWidth, "", TLC_TRUE, bAddr, TLC_FALSE, LibGetRecordIsStdContainer(portObj), "", "", cross)
%if ISFIELD(signalRec, "StorageClass") && ...
signalRec.StorageClass == "ImportedExternPointer"
%if LibGetRecordWidth(signalRec) == 1 && ...
!SLibDeclareDataAsPointer(LibGetRecordDataTypeId(signalRec)) && ...
!bAddr
%assign retSignal = "(*%<retSignal>)"
%endif
%endif
%return retSignal
%endif
%endfunction
%function ReAssignLocalBlockOutputTID(localBO) void
%if SLibIsPeriodicRateGrouping()
%if TYPE(CurrentTID) == "Number" && CurrentTID == -1
%elseif !ISEQUAL(localBO.TID, CurrentTID)
%assign temp = []
%foreach i = NumSampleTimes
%assign temp = temp + 0
%endforeach
%if TYPE(localBO.TID) == "Vector"
%foreach i = SIZE(localBO.TID,1)
%assign idx = (localBO.TID[i] > 0) ? localBO.TID[i] : 0
%assign temp[idx] = 1
%endforeach
%elseif TYPE(localBO.TID) == "Number"
%assert localBO.TID >= 0
%assign temp[localBO.TID] = 1
%endif
%if TYPE(CurrentTID) == "Number"
%assign temp[CurrentTID] =1
%elseif TYPE(CurrentTID) == "Vector"
%foreach i = SIZE(CurrentTID,1)
%assign idx = (CurrentTID[i] > 0) ? CurrentTID[i] : 0
%assign temp[idx] = 1
%endforeach
%endif
%assign localBO.TID = []
%foreach i = NumSampleTimes
%if temp[i] == 1
%assign localBO.TID = localBO.TID + i
%endif
%endforeach
%endif
%endif
%endfunction
%function FcnGetActiveFcnForDecl() void
%if ::BlockFcn == "RootUpdate"
%if CombineOutputUpdateFcns == 1
%return "Output"
%else
%return "Update"
%endif
%elseif ::BlockFcn == "OutputUpdate"
%return "Output"
%else
%return ::BlockFcn
%endif
%endfunction
%function SLibCreateDummyPortRecord() void
%createrecord portObj { /
BusSelElIdx [""] /
BusSelElCGTypeId [-1] /
SignalSrc [-1] /
SignalOffset [-1] /
SymbolicSignalOffset -1 /
Width 1 }
%return portObj
%endfunction
%function SLibGetSourceRecordAndMapInfo(portObj, sigIdx, ...
bReturnIdentfier, bTLCInterfaceV2Active) void
%createrecord rec {mapSrc "";mapIdx -1;sigRec [];busSelElIdx "";busSelElCGTypeId -1;signalOffset -1; symbolicSignalOffset -1; identi "";isPointer TLC_FALSE}
%if SIZE(portObj.SignalSrc,1) > 1
%assign lSigIdx = sigIdx
%else
%assign lSigIdx = 0
%endif
%assign sigRecEmpty = TLC_TRUE
%assign idNum = IDNUM(portObj.SignalSrc[lSigIdx])
%assign busSelElIdx = ""
%assign busSelElCGTypeId = -1
%if ISFIELD(portObj,"BusSelElIdx")
%assign busSelElIdx = portObj.BusSelElIdx[lSigIdx]
%assign busSelElCGTypeId = portObj.BusSelElCGTypeId[lSigIdx]
%endif
%switch (idNum[0])
%case "L"
%assign localBO = BlockOutputs.LocalBlockOutput[idNum[1]]
%assign rec.sigRec = localBO
%assign rec.mapSrc = "b"
%assign rec.isPointer = localBO.DeclareAsPointer == "yes"
%assign sigRecEmpty = TLC_FALSE
%if bReturnIdentfier && !bTLCInterfaceV2Active
%if localBO.VarGroupVarIdx > -1
%assign varGroupIdx = ...
::CompiledModel.VarGroups.VarGroupVarIdx[localBO.VarGroupVarIdx]
%assign rec.identi = SLibCG_GetVarGroupElementPath(varGroupIdx, ...
SLibGetHStructWithLocalScopeSystemIdx(SystemIdx), CrossNoArgFcnBound)
%else
%assign activeFcn = FcnGetActiveFcnForDecl()
%assign declareInFcnScope = "DeclareIn%<activeFcn>FcnScope"
%assign localBO.%<declareInFcnScope> = 1
%<ReAssignLocalBlockOutputTID(localBO)>
%assign rec.identi = "%<LibGetRecordIdentifier(localBO)>"
%endif
%endif
%break
%case "b"
%assign globalBO = BlockOutputs.GlobalBlockOutput[idNum[1]]
%assign rec.sigRec = globalBO
%assign rec.mapSrc = "b"
%assign rec.isPointer = globalBO.DeclareAsPointer == "yes"
%assign sigRecEmpty = TLC_FALSE
%if bReturnIdentfier && !bTLCInterfaceV2Active
%assign rec.identi = ...
SLibCG_GetVarGroupElementPath(globalBO.VarGroupIdx, ...
SLibGetHStructWithLocalScopeSystemIdx(SystemIdx), CrossNoArgFcnBound)
%endif
%break
%case "u"
%assign blkSysIdx = System[BlockIdx[1]].ReusedParentSystemIdx
%assign interface = System[blkSysIdx].Interface
%assign canInputArg = interface.CanonicalInputArgDef[idNum[1]]
%assign sys = System[SystemIdx]
%with sys
%assign tid = FcnGetCurrentAccessTid()
%endwith
%if ISFIELD(portObj,"RecordType") && ...
portObj.RecordType == "ControlInputPort"
%assign cross = System[BlockIdx[1]].CrossNoArgFcnBound
%else
%assign cross = CrossNoArgFcnBound
%endif
%if bReturnIdentfier
%if !bTLCInterfaceV2Active
%assert (System[SystemIdx].HStructDeclSystemIdx <= blkSysIdx || ISFIELD(System[SystemIdx],"RTWSystemCodeOptIntf"))
%if !cross
%assign rec.identi = LibGetRecordIdentifier(canInputArg)
%else
%<SLibAccessArgHelper(canInputArg,"Global",tid)>
%assign rec.identi = canInputArg.GlobalIdentifier
%endif
%if canInputArg.DeclareAsPointer == "yes"
%assign rec.identi = "(*%<rec.identi>)"
%endif
%<SLibAccessArgHelper(canInputArg,"",tid)>
%endif
%assign rec.sigRec = canInputArg
%assign rec.mapSrc = "u"
%assign sigRecEmpty = TLC_FALSE
%else
%assign idNum = IDNUM(canInputArg.SignalSrc[0])
%assign mapSource = idNum[0]
%assign mapIndex = idNum[1]
%endif
%break
%case "y"
%assign blkSysIdx = System[BlockIdx[1]].ReusedParentSystemIdx
%assign interface = System[blkSysIdx].Interface
%assign canOutputArg = interface.CanonicalOutputArgDef[idNum[1]]
%assign sys = System[SystemIdx]
%with sys
%assign tid = FcnGetCurrentAccessTid()
%endwith
%if ISFIELD(portObj,"RecordType") && ...
portObj.RecordType == "ControlInputPort"
%assign cross = System[BlockIdx[1]].CrossNoArgFcnBound
%else
%assign cross = CrossNoArgFcnBound
%endif
%if bReturnIdentfier
%if !bTLCInterfaceV2Active
%assert (System[SystemIdx].HStructDeclSystemIdx <= blkSysIdx || ISFIELD(System[SystemIdx],"RTWSystemCodeOptIntf"))
%if !cross
%if LibGetRecordWidth(canOutputArg) == 1 && ...
canOutputArg.DeclareAsPointer == "yes"
%assign rec.identi = "(*" + LibGetRecordIdentifier(canOutputArg) + ")"
%else
%assign rec.identi = LibGetRecordIdentifier(canOutputArg)
%endif
%else
%<SLibAccessArgHelper(canOutputArg,"Global",tid)>
%assign ident = canOutputArg.GlobalIdentifier
%if LibGetRecordWidth(canOutputArg) == 1 && ...
canOutputArg.PassByReturn == "no"
%assign rec.identi = "(*%<ident>)"
%else
%assign rec.identi = "%<ident>"
%endif
%endif
%<SLibAccessArgHelper(canOutputArg,"",tid)>
%endif
%assign rec.sigRec = canOutputArg
%assign rec.mapSrc = "y"
%assign sigRecEmpty = TLC_FALSE
%else
%assign idNum = IDNUM(canOutputArg.SignalSrc[0])
%assign mapSource = idNum[0]
%assign mapIndex = idNum[1]
%endif
%break
%case "d"
%if bReturnIdentfier && !bTLCInterfaceV2Active
%assign blkSysIdx = BlockIdx[0]
%assign accessSysIdx = System[SystemIdx].HStructDeclSystemIdx
%assign rec.identi = ...
FcnGetLocalDWorkIdentifier(blkSysIdx, accessSysIdx, idNum[1])
%endif
%assign mapSource = "D"
%assign mapIndex = idNum[1]
%break
%case "x"
%if bReturnIdentfier && !bTLCInterfaceV2Active
%assign blkSysIdx = BlockIdx[0]
%assign accessSysIdx = System[SystemIdx].HStructDeclSystemIdx
%assign rec.identi = ...
FcnGetLocalCStateIdentifier(blkSysIdx, accessSysIdx, idNum[1])
%endif
%assign mapSource = "X"
%assign mapIndex = idNum[1]
%break
%default
%assign mapSource = idNum[0]
%assign mapIndex = idNum[1]
%endswitch
%assign rec.busSelElIdx = busSelElIdx
%assign rec.busSelElCGTypeId = busSelElCGTypeId
%assign rec.signalOffset = portObj.SignalOffset[lSigIdx]
%if ISFIELD(portObj, "SymbolicSignalOffset")
%assign rec.symbolicSignalOffset = portObj.SymbolicSignalOffset
%endif
%if sigRecEmpty
%if bReturnIdentfier
%assign rec.mapSrc = mapSource
%assign rec.mapIdx = mapIndex
%endif
%switch (mapSource)
%case "C"
%assign rec.sigRec = BlockOutputs.ConstOutputExpr[mapIndex]
%break
%case "L"
%assign rec.sigRec = ...
::CompiledModel.BlockOutputs.LocalBlockOutput[mapIndex]
%break
%case "B"
%assign rec.sigRec = ...
::CompiledModel.BlockOutputs.GlobalBlockOutput[mapIndex]
%break
%case "I"
%assign rec.sigRec = ...
::CompiledModel.BlockOutputs.ConstBlockOutput[mapIndex]
%break
%case "E"
%assign rec.sigRec = ...
::CompiledModel.BlockOutputs.ExternalBlockOutput[mapIndex]
%break
%case "D"
%assign rec.sigRec = ::CompiledModel.DWorks.DWork[mapIndex]
%break
%case "X"
%assign rec.sigRec = ::CompiledModel.ContStates.ContState[mapIndex]
%break
%case "U"
%assign rec.sigRec = ...
::CompiledModel.ExternalInputs.ExternalInput[mapIndex]
%if bReturnIdentfier
%<LibAccessArg(rec.sigRec)>
%endif
%break
%case "Y"
%assign rec.sigRec = ...
::CompiledModel.ExternalOutputs.ExternalOutput[mapIndex]
%break
%case "G"
%assign rec.sigRec = []
%break
%case "F"
%assign rec.sigRec = []
%break
%case "M"
%assign rec.sigRec = []
%break
%default
%error ...
"Wrong map source '%<mapSource>' in SLibGetSourceRecordAndMapInfo."
%endswitch
%endif
%return rec
%endfunction
%function SLibGetSourceRecord(portObj, sigIdx) void
%assign rec = SLibGetSourceRecordAndMapInfo(portObj, sigIdx, ...
TLC_FALSE, TLC_FALSE)
%return rec.sigRec
%endfunction
%function SLibGetSourceMapInfo(portObj, sigIdx) void
%return SLibGetSourceRecordAndMapInfo(portObj, sigIdx, TLC_FALSE, TLC_FALSE)
%endfunction
%function FcnGetInputOrOutputSignal(sigKind, aPortIdx, ucv, lcv, sigIdx) void
%assign portIdx = CAST("Number", aPortIdx)
%assign reim = ""
%if sigKind == "input" || sigKind == "inputAddr"
%assign bInput = TLC_TRUE
%elseif sigKind == "output" || sigKind == "outputAddr"
%assign bInput = TLC_FALSE
%else
%<LibBlockReportError([],"Invalid sigKind")>
%endif
%if sigKind == "input" || sigKind == "output"
%assign bAddr = TLC_FALSE
%else
%assign bAddr = TLC_TRUE
%endif
%if ISEMPTY(sigIdx)
%if ISEMPTY(ucv) && ISEMPTY(lcv)
%setcommandswitch "-v1"
%<LibBlockReportError([],"Invalid sigIdx: '%<sigIdx>' " + ...
"(must be an integer or an integer prefixed with the TLC " + ...
"variable tRealPart or tImagPart)")>
%endif
%assign sigIdx = 0
%endif
%if bInput
%assign portObj = FcnGetInputPortRecord(portIdx)
%assign portType = "BlockInput"
%assign varName = "u"
%else
%assign portObj = FcnGetOutputPortRecord(portIdx)
%assign portType = "BlockOutput"
%assign varName = "y"
%endif
%assign isComplex = LibGetRecordIsComplex(portObj)
%if !bAddr
%if TYPE(sigIdx) == "String"
%assign tmpVect = SLibGetReimAndIdx(sigIdx)
%assign reim = tmpVect[0]
%assign sigIdx = tmpVect[1]
%if reim != "" && !isComplex
%if reim == tImagPart
%return ""
%elseif reim == tRealPart
%assign reim = ""
%else
%<LibBlockReportError([], ...
"Invalid value of Real/Imag sigIdx part: %<reim>")>
%endif
%endif
%endif
%else
%if TYPE(sigIdx) != "Number"
%<LibBlockReportError([], "sigIdx must be an integer index " + ...
"when accessing an input signal address")>
%endif
%endif
%if !bInput && ucv != ""
%assign sigIdx = 0
%endif
%if bInput && SIZE(portObj.SignalSrc,1) > 1
%assign regionIdx = portObj.SignalRegion[sigIdx]
%else
%assign regionIdx = 0
%endif
%if SIZE(portObj.SignalOffset,1) > 1
%assign sigOffset = portObj.SignalOffset[sigIdx]
%else
%assign sigOffset = portObj.SignalOffset[0]
%endif
%if ISFIELD(portObj, "SymbolicSignalOffset") && portObj.SymbolicSignalOffset > -1
%assign symbolicOffset = LibCGTypeSymbolicWidth(portObj.SymbolicSignalOffset)
%assign symbolicOffset = "(" + symbolicOffset + ")"
%if !WHITE_SPACE(ucv)
%assign symbolicOffset = ucv + "+" + symbolicOffset
%endif
%assign ident = SLibInvokeTLCInterface(SLibGetCurrentBlock(), ...
(bInput ? "Input" : "Output"), portIdx, regionIdx, bAddr, ...
lcv, symbolicOffset, 0, reim)
%else
%assign ident = SLibInvokeTLCInterface(SLibGetCurrentBlock(), ...
(bInput ? "Input" : "Output"), portIdx, regionIdx, bAddr, ...
lcv, ucv, sigOffset, reim)
%endif
%assign tlcIFv2Enable = !ISEMPTY(ident)
%assign sigRecAndMapInfo = ...
SLibGetSourceRecordAndMapInfo(portObj, sigIdx, TLC_TRUE, tlcIFv2Enable)
%assign portWidth = LibGetRecordWidth(portObj)
%assign signalRec = sigRecAndMapInfo.sigRec
%assign mapSource = sigRecAndMapInfo.mapSrc
%assign sigOffset = sigRecAndMapInfo.signalOffset
%if !ISEMPTY(signalRec) && ISFIELD(signalRec, "UseAccessFunctions") && signalRec.UseAccessFunctions
%assign tlcIFv2Enable = TLC_FALSE
%endif
%if ucv != "" || lcv == "" || (lcv != "" && portWidth==1) || ...
mapSource=="G" || ISEMPTY(signalRec)
%if mapSource == "F"
%error "This function is called from a function that did not" + ...
"check for function call or action data output port"
%endif
%if !tlcIFv2Enable && (mapSource=="G" || ISEMPTY(signalRec))
%assign dtID = LibGetRecordDataTypeId(portObj)
%return FcnGetGroundSignalReference(sigKind, dtID, isComplex, reim)
%else
%if PurelyIntegerCode
%assign dTypeId = LibGetDataTypeIdAliasedThruToFromId(LibGetRecordDataTypeId(signalRec))
%if dTypeId == tSS_DOUBLE || dTypeId ==tSS_SINGLE
%<SLibCacheIntegerOnlyWarning(Name, portType)>
%endif
%endif
%if tlcIFv2Enable
%if !bInput && bAddr && "I" == mapSource
%assign dtypeName = LibGetRecordDataTypeName(signalRec, "")
%assign cast = "(%<dtypeName>*)"
%return cast + ident
%else
%return ident
%endif
%else
%assign retSignal = FcnGetBasicSignalReference(sigRecAndMapInfo, ...
portWidth, reim, bInput, bAddr, isComplex, LibGetRecordIsStdContainer(portObj), ucv, lcv, TLC_FALSE)
%endif
%endif
%else
%assign sigIndexer = SLibGet1DArrayIndexer(portWidth, ucv, lcv, sigOffset)
%assign returnBaseAddr = (bAddr && ucv == "" && lcv == "" && sigIdx == 0 && portWidth > 1) && ...
!LibGetRecordIsStdContainer(portObj)
%if returnBaseAddr
%assign retSignal = "%<varName>%<portIdx>"
%else
%assign retSignal = "%<varName>%<portIdx>%<sigIndexer>"
%if reim != ""
%assign retSignal = retSignal + ".%<reim>"
%endif
%if bAddr
%assign retSignal = "&" + retSignal
%endif
%endif
%endif
%if !bAddr && ...
ISFIELD(signalRec, "StorageClass") && ...
signalRec.StorageClass == "ImportedExternPointer" && ...
LibGetRecordWidth(signalRec) == 1
%assign retSignal = "(*%<retSignal>)"
%endif
%return retSignal
%endfunction
%function FcnGetIOSignalBaseAddr(sigKind, portIdx) void
%assign reim = ""
%if sigKind == "input"
%assign bInput = TLC_TRUE
%elseif sigKind == "output"
%assign bInput = TLC_FALSE
%else
%<LibBlockReportError([],"Invalid sigKind")>
%endif
%if bInput
%assign portObj = FcnGetInputPortRecord(portIdx)
%assign varName = "u"
%else
%assign portObj = FcnGetOutputPortRecord(portIdx)
%assign varName = "y"
%endif
%assign retSignal = "%<varName>%<portIdx>"
%if LibGetRecordWidth(portObj) == 1
%assign retSignal = "&" + retSignal
%endif
%return retSignal
%endfunction
%function SLibBlockOutputSignal(block,system,portIdx,ucv,lcv,sigIdx,retType) void
%assign returnValue = ""
%assign fcn = "BlockOutputSignal"
%if LibBlockFunctionExists(block,fcn)
%assign prevBlockFcnIdx = ::CurrentBlockFcnIdx
%if -1 < block.OutputBlockFcnIdx
%assign ::CurrentBlockFcnIdx = block.OutputBlockFcnIdx
%endif
%with block
%assign returnValue = GENERATE(block,fcn,system,portIdx,ucv,lcv,sigIdx,retType)
%endwith
%assign ::CurrentBlockFcnIdx = prevBlockFcnIdx
%else
%assign errTxt = "Block specifies that its output signal " ...
"is an expression, however, the block does not provide the " ...
"necessary TLC function: %<fcn>"
%<LibBlockReportError(block, errTxt)>
%endif
%return returnValue
%endfunction
%function SLibGetBlockOutputIdentifierFromRecord(bo, accessSysIdx) void
%assign varGroup = ::CompiledModel.VarGroups.VarGroup[bo.VarGroupIdx[0]]
%return SLibCG_GetVarGroupElementPath(bo.VarGroupIdx, accessSysIdx, ...
System[varGroup.SysIdx].CrossNoArgFcnBound)
%endfunction
%function SLibGetBlockOutputFromRecord(bo,accessSysIdx) void
%assign id = SLibGetBlockOutputIdentifierFromRecord(bo, accessSysIdx)
%if LibGetRecordWidth(bo) > 1
%assign indexer = "[0]"
%else
%assign indexer = ""
%endif
%if LibGetRecordIsComplex(bo)
%assign re = ".%<tRealPart>"
%else
%assign re = ""
%endif
%return "&%<id>%<indexer>%<re>"
%endfunction
%endif