%%
%%
%%
%%
%%Copyright1994-2017TheMathWorks,Inc.
%%
%%Abstract:
%%Returnstheappropriatevariablestringforagivenaccessto
%%SimStructstructure.
 
%if EXISTS("_FCNIOLIB_") == 0
%assign _FCNIOLIB_ = 1
 
%%
%%(1)GlobalLibraryFunctions(Libfunctions)
%%
 
%%===-----------------------------------------------------------------------===
%%
%%AllaccessestoSimStructvariablesshouldbedonethroughtheseaccessor
%%methods.Thiswillreturnthecorrectversionforthespecifiedtarget.
%%Forexample:GRT-MallocnolongeraccessestheSimStructvariablesthrough
%%alocalvariable,butaccessesthemdirectly.The"HasSimStructVars"
%%variableintheCompiledModelstructureisdefinedifthisdirectaccess
%%isused.
%%
%%===-----------------------------------------------------------------------===
 
%%Function:SLibGetElementIdxFromVarGroup=====================================
%%Abstract:
%%Returnsaelementindexforagivenvargroupandelementsourceorindex
%%
%function SLibGetElementIdxFromVarGroup(aVarGroupIdx, aElementSrcOrIndex) void
  %if TYPE(aElementSrcOrIndex) == "String"
    %assign numElement = SLibVarGroupNumElements(aVarGroupIdx)
    %foreach mIdx = numElement
      %if SLibVarGroupElementSource(aVarGroupIdx, mIdx) == aElementSrcOrIndex
        %return mIdx
      %endif
    %endforeach
    %return -1
  %endif
  %assert TYPE(aElementSrcOrIndex) == "Number"
  %return aElementSrcOrIndex
%endfunction
 
%%Function:SLibGetGlobalInstanceNameForBlocksSelf
%%Abstract:
%%Returnstrueifandonlyifweaccessthechildblockself
%%instancethroughacodergrouppointerinself.Forexample:
%%"self->anotherCoderGroup->childSelfInst1"
%function SLibIsBlockInstanceAccessedViaPointerInSelf(aBlock)
  %assign childSelfCoderGroupIndex = SLibGetChildSelfCoderGroupIndex(aBlock)
  %if childSelfCoderGroupIndex != -1
    %assign blockInterface = GetModelrefInterface(aBlock)
    %assign childCoderGroupsRecord = blockInterface.CoderDataGroups.CoderDataGroup
    %assign numChildCoderGroups = SIZE(childCoderGroupsRecord, 1)
    %if numChildCoderGroups > 1
      %assign childSelfCoderGroup = childCoderGroupsRecord[childSelfCoderGroupIndex]
    %else
      %assign childSelfCoderGroup = childCoderGroupsRecord
    %endif
    %assign groupIndexWithChildSelfNameInCurrentModel = ...
      SLibCoderDataGroupIndex(childSelfCoderGroup.Name)
    %assign childSelfGroupNameRegisteredInCurrentModel = ...
      groupIndexWithChildSelfNameInCurrentModel != -1
    %assign childSelfGroupIsInParent = ...
      ISFIELD(childSelfCoderGroup, "AsStructure") && ...
      childSelfCoderGroup.AsStructure == "InParent"
     
    %if SLibGetDoesSelfHasCoderDataGroup()
      %assign currentModelSelfGroup = ::CompiledModel.CoderDataGroup[SLibGetSelfCoderDataGroupIndex()]
      %assign childAndParentHaveDifferentSelfGroups = ...
        currentModelSelfGroup.Name != childSelfCoderGroup.Name
      %if childSelfGroupIsInParent && ...
        childSelfGroupNameRegisteredInCurrentModel && ...
        childAndParentHaveDifferentSelfGroups
        %return TLC_TRUE
      %endif
    %endif
     
  %endif
 
  %return TLC_FALSE
%endfunction
 
%%Function:SLibGetPathToInstanceFromSelf
%%Abstract:
%%Returnsthepathtochildblock'sselfinstancethrough
%%acodergrouppointer.Forexample:
%%"self->anotherCoderGroup->childSelfInst1"
%function SLibGetPathToInstanceFromSelf(aBlock)
  %assign path = ""
   
  %assign childSelfCoderGroupIndex = SLibGetChildSelfCoderGroupIndex(aBlock)
  %assign blockInterface = GetModelrefInterface(aBlock)
  %assign childCoderGroupsRecord = blockInterface.CoderDataGroups.CoderDataGroup
  %assign numChildCoderGroups = SIZE(childCoderGroupsRecord, 1)
  %if numChildCoderGroups > 1
    %assign childSelfCoderGroup = childCoderGroupsRecord[childSelfCoderGroupIndex]
  %else
    %assign childSelfCoderGroup = childCoderGroupsRecord
  %endif
   
  %assign selfVarGroup = ::CompiledModel.VarGroups.VarGroup[SLibGetSelfVarGroupIndex()]
         
  %foreach vgElementId = selfVarGroup.NumVarGroupElements
    %assign vgElement = selfVarGroup.VarGroupElements[vgElementId]
    %assign idNumElement = IDNUM(vgElement)
    %if idNumElement[0] == "RCDG"
      %assign coderGroupIndex = idNumElement[1]
      %assign coderGroup = ::CompiledModel.CoderDataGroup[coderGroupIndex]
      %if coderGroup.Name == childSelfCoderGroup.Name
        %assign path = tSimStruct + "->" + LibCGTypeMemberName(selfVarGroup.CGTypeIdx, vgElementId) + "->" + aBlock.Identifier
        %break
      %endif
    %endif
  %endforeach
 
  %return path
%endfunction
 
%%Function:SLibGetFieldPointerFromSelf==========================================
%%Abstract:
%%ReturnsapointertoaRTMVarGroupGeneratedthroughthecgType
%%
%function SLibGetFieldPointerFromSelf(eleNameOrIndex,addTypeCast) void
  %if !SLibGetUseRTMcgType() || !SLibGetDoesSelfHasCoderDataGroup()
    %return ""
  %endif
  %assign retStr = ""
  %% If we are here, we should either have mapped Self (Coder Group) or unmapped Self (RTM)
  %assert SLibGetDoesSelfHasCoderDataGroup()
 
  %assign selfVarGroupIdx = SLibGetSelfVarGroupIndex()
  %assign elIdx = SLibGetElementIdxFromVarGroup(selfVarGroupIdx, eleNameOrIndex)
  %assign ptr = ""
  %if elIdx > -1
    %if SLibVarGroupIsStruct(selfVarGroupIdx)
      %if IsModelRefScalableBuild()
        %assign selfVar = IsModelReferenceSimTarget() ? FcnGetSFcnDWorkRTM() : ::CompiledModel.GlobalScope.tRTM
      %else
        %assign selfVar = tSimStruct
        %if SLibSynthesizedRTM()
          %<SLibCG_AccessRTM()>
        %endif
      %endif
      %assign deref = IsModelRefScalableBuild() ? "." : "->"
      %assign retStr = selfVar + deref
    %endif
    %assign retStr = retStr + SLibVarGroupElementName(selfVarGroupIdx, elIdx)
    %assign typeIdx = SLibVarGroupElementType(selfVarGroupIdx, elIdx)
    %if !LibCGTypeIsPointer(typeIdx)
      %assign ptr = "*"
      %assign retStr = "&("+ retStr +")"
    %endif
    %if addTypeCast
      %assign retStr = "((" + SLibGetTypeNameFromCGType(typeIdx) + ptr + ")" + retStr + ")"
    %endif
  %endif
  %return retStr
%endfunction
 
%%Function:SLibGetBlockIOPointerFromRTM======================================
%%Abstract:
%%ReturnsapointertotheBlockIOstructurefromtheRTM.
%%
%function SLibGetBlockIOPointerFromRTM(addTypeCast)
  %if Accelerator
    %assign retStr = RTMuGet("ModelBlockIO")
  %elseif CodeFormat == "S-Function"
    %assign retStr = RTMGet("LocalBlockIO")
  %else
    %assign retStr = RTMuGet("BlockIO")
  %endif
  %if addTypeCast
    %assign blockIOCast = FcnRewriteCast("(%<::tBlockIOType> *) %<retStr>")
    %assign retStr = "(%<blockIOCast>)"
  %endif
  %return retStr
%endfunction %% SLibGetBlockIOPointerFromRTM
 
%%Function:SLibGetBlockIOStruct==============================================
%%Abstract:
%%ReturnsthevariablefortheblockI/O.Thisfunctionissimilarwith
%%LibGetBlockIOStruct,exceptthisfunctioncancontrolwhetheraddtype
%%cast.
%%
%function SLibGetBlockIOStruct(addTypeCast) void
  %if ::CompiledModel.HasSimStructVars == 1
    %return SLibGetBlockIOPointerFromRTM(addTypeCast)
  %elseif IsModelRefScalableBuild() && !GenerateClassInterface
    %assign baseSystem = ::CompiledModel.System[GetBaseSystemIdx()]
    %return FcnSysVarGroupNonreusedName(baseSystem, "BlockIO")
  %else
    %return ::tBlockIO
  %endif
%endfunction %% SLibGetBlockIOStruct
 
%%Function:LibGetBlockIOStruct==============================================
%%Abstract:
%%ReturnsthevariablefortheblockI/O.
%%
%function LibGetBlockIOStruct() void
  %return SLibGetBlockIOStruct(TLC_TRUE)
%endfunction %% LibGetBlockIOStruct
 
%%Function:SLibGetConstBlockIOPointerFromRTM=================================
%%Abstract:
%%ReturnsapointertotheconstBlockIOstructurefromtheRTM.
%%
%function SLibGetConstBlockIOPointerFromRTM() void
  %return "((%<::tConstBlockIOType> *) %<RTMGet("ConstBlockIO")>)"
%endfunction %% SLibGetConstBlockIOPointerFromRTM
 
%%Function:SLibGetSelfPointerFromRTM=================================
%%Abstract:
%%ReturnsapointertothecontextdatastructurefromtheRTM.
%%
%function SLibGetSelfPointerFromRTM() void
  %return tSimStruct
%endfunction %% SLibGetSelfPointerFromRTM
 
%%Function:SLibGetSelfStruct================================================
%%Abstract:
%%ReturnsthevariablefortheDWorkvariable.
%%
%function SLibGetSelfStruct(addTypeCast) void
    %return tSimStruct
%endfunction %% SLibGetDWorkStruct
 
%%Function:LibGetSelfStruct================================================
%%Abstract:
%%ReturnsthevariablefortheDWorkvariable.
%%
%function LibGetSelfStruct() void
  %return SLibGetSelfStruct(TLC_TRUE)
%endfunction %% LibGetDWorkStruct
 
 
%%Function:LibGetConstBlockIOStruct==========================================
%%Abstract:
%%ReturnsthevariablefortheconstblockI/O.
%%
%function LibGetConstBlockIOStruct() void
  %if isGRTMalloc
    %return SLibGetConstBlockIOPointerFromRTM()
  %else
    %return ::tConstBlockIOStruct
  %endif
%endfunction %% LibGetConstBlockIOStruct
 
%%Function:SLibGetExternalInputStructHelper
%%Abstract:
%%HelperforSLibGetExternalInputStructForRecordandSLibGetExternalInputStruct
%function SLibGetExternalInputStructHelper(addTypeCast,isCallSite, cross, typeName, varName) void
  %assign retStr = ""
  %if isCallSite && ...
    (::CompiledModel.HasSimStructVars || ...
    ((cross || ThisSubsysCross) && MultiInstanceERTCode && !GenerateClassInterface))
    %if UsingMalloc || Accelerator || ...
      ((cross || ThisSubsysCross) && MultiInstanceERTCode && !GenerateClassInterface)
      %assign retStr = RTMGet("U")
    %elseif CodeFormat == "S-Function"
      %assign retStr = RTMGetIdxed("InputPortSignalPtrs", 0)
    %else
      %assign retStr = ::tInput
    %endif
    %assert(!WHITE_SPACE(retStr))
    %if addTypeCast
      %assign retStr = "((%<typeName> *) %<retStr>)"
    %endif
  %else
    %assign retStr = varName
  %endif
  %return retStr
%endfunction
 
%%Function:SLibGetExternalInputStructForRecord
%%Abstract:
%%Returnscodergroupstructurenameforrecord,otherwisefallbackstodefaultroutineSLibGetExternalInputStruct
%function SLibGetExternalInputStructForRecord(extInp) void
  %assign coderGroupId = ...
    SLibGetCoderGroupIdForDataRecord(extInp)
  %if coderGroupId != -1
    %assign coderGroup = ::CompiledModel.CoderDataGroup[coderGroupId]
    %assign typeName = SLibCoderDataGroupType(coderGroup)
    %assign varName = SLibCoderDataGroupInstance(coderGroup)
 
    %return SLibGetExternalInputStructHelper(TLC_TRUE, TLC_FALSE, TLC_FALSE, typeName, varName)
  %else
    %% default group
    %return LibGetExternalInputStruct()
  %endif
%endfunction
 
%%Function:SLibGetExternalInputStruct========================================
%%Abstract:
%%Returnsthevariablefortheexternalinputsignal.
%%
%function SLibGetExternalInputStruct(addTypeCast,isCallSite,cross) void
    %assign typeName = ::tInputType
    %assign varName = ::tInput
 
    %return SLibGetExternalInputStructHelper(addTypeCast,isCallSite,cross, typeName, varName)
%endfunction %% SLibGetExternalInputStruct
 
%%Function:LibGetExternalInputStruct========================================
%%Abstract:
%%Returnsthevariablefortheexternalinputsignal.
%%
%function LibGetExternalInputStruct() void
  %return SLibGetExternalInputStruct(TLC_TRUE, TLC_FALSE, TLC_FALSE)
%endfunction %% LibGetExternalInputStruct
 
%%Function:SLibGetExternalOutputStructHelper
%%Abstract:
%%HelperforSLibGetExternalOutputStructForRecordandSLibGetExternalOutputStruct
%function SLibGetExternalOutputStructHelper(addTypeCast, isCallSite, cross, typeName, varName) void
  %assign retStr = ""
 
    %if isCallSite && ...
      (::CompiledModel.HasSimStructVars || ...
      ((cross || ThisSubsysCross) && MultiInstanceERTCode && !GenerateClassInterface))
    %assert(!Accelerator)
    %if UsingMalloc || ((cross || ThisSubsysCross) && MultiInstanceERTCode && !GenerateClassInterface)
      %assign retStr = RTMGet("Y")
    %elseif CodeFormat == "S-Function"
      %assign retStr = RTMGetIdxed("OutputPortSignal", 0)
    %else
      %assign retStr = varName
    %endif
    %assert(!WHITE_SPACE(retStr))
    %if addTypeCast
      %assign retStr = "((%<typeName> *) %<retStr>)"
    %endif
  %else
     %assign retStr = varName
  %endif
  %return retStr
%endfunction
 
%%Function:SLibGetExternalOutputStructForRecord
%%Abstract:
%%Returnscodergroupstructurenameforrecord,otherwisefallbackstodefaultroutineSLibGetExternalOutputStruct
%function SLibGetExternalOutputStructForRecord(extOutp) void
  %assign coderGroupId = ...
    SLibGetCoderGroupIdForDataRecord(extOutp)
  %if coderGroupId != -1
    %assign coderGroup = ::CompiledModel.CoderDataGroup[coderGroupId]
    %assign typeName = SLibCoderDataGroupType(coderGroup)
    %assign varName = SLibCoderDataGroupInstance(coderGroup)
     
    %return SLibGetExternalOutputStructHelper(TLC_TRUE, TLC_FALSE, TLC_FALSE, typeName, varName)
  %else
    %% default group
    %return LibGetExternalOutputStruct()
  %endif
%endfunction
 
%%Function:SLibGetExternalOutputStruct=======================================
%%Abstract:
%%Returnsthevariablefortheexternaloutputsignal.
%%
%function SLibGetExternalOutputStruct(addTypeCast,isCallSite,cross) void
    %assign typeName = ::tOutputType
    %assign varName = ::tOutput
     
  %return SLibGetExternalOutputStructHelper(addTypeCast,isCallSite,cross, typeName, varName)
%endfunction %% SLibGetExternalOutputStruct
 
 
%%Function:LibGetExternalOutputStruct=======================================
%%Abstract:
%%Returnsthevariablefortheexternaloutputsignal.
%%
%function LibGetExternalOutputStruct() void
  %return SLibGetExternalOutputStruct(TLC_TRUE, TLC_FALSE, TLC_FALSE)
%endfunction %% LibGetExternalOutputStruct
 
%%Function:SLibGetContStatesPointerFromRTM==================================
%%Abstract:
%%ReturnsapointertothecontinuesstatesstructurefromtheRTM.
%%
%function SLibGetContStatesPointerFromRTM(addTypeCast) void
  %assign retStr = RTMGet("ContStates")
  %if addTypeCast
    %assign retStr = "((%<::tContStateType> *) %<retStr>)"
  %endif
  %return retStr
%endfunction %% SLibGetContStatesPointerFromRTM
 
%%Function:SLibGetContinuousStateStruct======================================
%%Abstract:
%%Returnsthevariableforthecontinuousstatevariable.
%%
%function SLibGetContinuousStateStruct(addTypeCast) void
  %if ::CompiledModel.HasSimStructVars == 1
    %return SLibGetContStatesPointerFromRTM(addTypeCast)
  %else
    %return ::tContState
  %endif
%endfunction %% LibGetContinuousStateStruct
 
 
%%Function:LibGetContinuousStateStruct======================================
%%Abstract:
%%Returnsthevariableforthecontinuousstatevariable.
%%
%function LibGetContinuousStateStruct() void
  %return SLibGetContinuousStateStruct(TLC_TRUE)
%endfunction %% LibGetContinuousStateStruct
 
 
%%Function:LibGetPeriodicStateIndicesPtrFromRTM==================================
%%Abstract:
%%ReturnsapointertotheperiodicstateindicesfromtheRTM.
%%
%function SLibGetPeriodicStateIndicesPtrFromRTM(addTypeCast) void
  %assign retStr = RTMGet("PeriodicContStateIndices")
  %if addTypeCast
    %assign retStr = "((%<::tPeriodicStateIndType>*) %<retStr>)"
  %endif
  %return retStr
%endfunction %% SLibGetPeriodicStateIndicesPtrFromRTM
 
 
%%Function:LibGetPeriodicContStateIndices
%%Abstract:
%%Returnsthevariablefortheindexoftheglobalperiodiccontinuousstate.
%%
%function LibGetPeriodicContStateIndices() Output
  %assert (!IsModelReferenceTarget())
  %return tPeriodicStateInd
%endfunction %% LibGetPeriodicContStateIndices
 
 
%%Function:SLibGetPeriodicStateRangesPtrFromRTM==================================
%%Abstract:
%%ReturnsapointertotheperiodicstaterangesfromtheRTM.
%%
%function SLibGetPeriodicStateRangesPtrFromRTM(addTypeCast) void
  %assign retStr = RTMGet("PeriodicContStateRanges")
  %if addTypeCast
    %assign retStr = "((%<tPeriodicStateRngType>*) %<retStr>)"
  %endif
  %return retStr
%endfunction %% SLibGetPeriodicStateRangesPtrFromRTM
 
 
%%Function:LibGetPeriodicContStateRanges
%%Abstract:
%%Returnsthevariablefortherangeoftheglobalperiodiccontinuousstate.
%%
%function LibGetPeriodicContStateRanges() Output
  %assert (!IsModelReferenceTarget())
  %return tPeriodicStateRng
%endfunction %% LibGetPeriodicContStateRanges
 
 
%%Function:SLibGetContStateDerivativesStructFromRTM=========================
%%Abstract:
%%Returnsapointertothecontinuesstatederivativesstructure
%%fromtheRTM.
%%
%function SLibGetContStateDerivativesStructFromRTM() void
  %if SLibIsPartitionGrouping()
    %assert EXISTS(::GlobalCurrentPID)
    %if SLibPartitionNeedContFcnDecl(::GlobalCurrentPID)
      %return "((%<::tXdotType> *) %<RTMGet("dX")>)"
    %else
      %return SLibPartitionGetContStateDerivativeStruct()
    %endif
  %else
    %return "((%<::tXdotType> *) %<RTMGet("dX")>)"
  %endif
%endfunction %% SLibGetContStateDerivativesStructFromRTM
 
%%Function:LibGetDotContinuousStateStruct===================================
%%Abstract:
%%Returnsthevariableforthedotcontinuousstatevariable.
%%
%function LibGetDotContinuousStateStruct() void
  %assign isDeriv = (::BlockFcn == "Derivative")
  %assign isForcingFunction = (::BlockFcn == "ForcingFunction")
  %if ::CompiledModel.HasSimStructVars == 1 || isDeriv || isForcingFunction
    %return SLibGetContStateDerivativesStructFromRTM()
  %else
    %return ::tXdot
  %endif
%endfunction %% LibGetDotContinuousStateStruct
 
%%Function:SLibGetContStateDisabledsStructFromRTM=========================
%%Abstract:
%%Returnsapointertothecontinuesstatedisabledstructure
%%fromtheRTM.
%%
%function SLibGetContStateDisabledStructFromRTM() void
  %return "((%<::tXdisType> *) %<RTMGet("ContStateDisabled")>)"
%endfunction %% SLibGetContStateDisabledStructFromRTM
 
%%Function:LibGetContinuousStateDisabledStruct==============================
%%Abstract:
%%Returnsthevariableforthecontinuousstatedisabledvariable.
%%
%function LibGetContinuousStateDisabledStruct() void
  %assign isDeriv = (::BlockFcn == "Derivative")
  %assign isForcingFunction = (::BlockFcn == "ForcingFunction")
  %if ::CompiledModel.HasSimStructVars == 1 || ::isRSimWithSolverModule || isDeriv || isForcingFunction
    %return SLibGetContStateDisabledStructFromRTM()
  %else
    %return ::tXdis
  %endif
%endfunction %% LibGetContinuousStateDisabledStruct
 
%%Function:SLibGetContStateAbsoluteToleranceStructFromRTM=================
%%Abstract:
%%Returnsapointertothecontinuousstateabsolutetolerance
%%fromtheRTM.
%%
%function SLibGetContStatesAbsoluteToleranceStructFromRTM() void
  %return "((%<::tXAbsTolType> *) %<RTMGet("AbsTolVector")>)"
%endfunction %% SLibGetContStateAbsoluteToleranceStructFromRTM
 
%%Function:LibGetContinuousStateAbsoluteToleranceStruct==============================
%%Abstract:
%%Returnsthevariableforthecontinuousstateabsolutetolerancevariable.
%%
%function LibGetContinuousStateAbsoluteToleranceStruct() void
  %if ::CompiledModel.HasSimStructVars == 1 || ::isRSimWithSolverModule
    %return SLibGetContStatesAbsoluteToleranceStructFromRTM()
  %else
    %return ::tXAbsTol
  %endif
%endfunction %% LibGetContinuousStateAbsoluteToleranceStruct
 
 
%%Function:SLibGetContStatePerturbMinStructFromRTM=================
%%Abstract:
%%Returnsapointertothecontinuousstateperturbmin
%%fromtheRTM.
%%
%function SLibGetContStatesPerturbMinStructFromRTM() void
  %return "((%<::tXPerturbMinType> *) %<RTMGet("JacobianPerturbationBoundsMinVec")>)"
%endfunction %% SLibGetContStatePerturbMinStructFromRTM
 
%%Function:LibGetContinuousStatePerturbMinStruct==============================
%%Abstract:
%%Returnsthevariableforthecontinuousstateperturbminvariable.
%%
%function LibGetContinuousStatePerturbMinStruct() void
  %if ::CompiledModel.HasSimStructVars == 1 || ::isRSimWithSolverModule
    %return SLibGetContStatesPerturbMinStructFromRTM()
  %else
    %return ::tXPerturbMin
  %endif
%endfunction %% LibGetContinuousStatePerturbMinStruct
 
 
%%Function:SLibGetContStatePerturbMaxStructFromRTM=================
%%Abstract:
%%Returnsapointertothecontinuousstateperturbmax
%%fromtheRTM.
%%
%function SLibGetContStatesPerturbMaxStructFromRTM() void
  %return "((%<::tXPerturbMaxType> *) %<RTMGet("JacobianPerturbationBoundsMaxVec")>)"
%endfunction %% SLibGetContStatePerturbMaxStructFromRTM
 
%%Function:LibGetContinuousStatePerturbMaxStruct==============================
%%Abstract:
%%Returnsthevariableforthecontinuousstateperturbmaxvariable.
%%
%function LibGetContinuousStatePerturbMaxStruct() void
  %if ::CompiledModel.HasSimStructVars == 1 || ::isRSimWithSolverModule
    %return SLibGetContStatesPerturbMaxStructFromRTM()
  %else
    %return ::tXPerturbMax
  %endif
%endfunction %% LibGetContinuousStatePerturbMaxStruct
 
 
%%Function:LibGetMassMatrixGlobal======================================
%%Abstract:
%%ReturnsthevariablefortheglobalMassMatrix.
%%
%function LibGetMassMatrixGlobal() Output
  %if ::CompiledModel.HasSimStructVars == 1
    %return ""
  %elseif SLibIsPartitionGrouping() && ...
    EXISTS(::GlobalCurrentPID) && ...
    TYPE(::GlobalCurrentPID) == "Number" && ...
    ::GlobalCurrentPID >= 0
    %return SLibPartitionGetMassMatricesVarName(::GlobalCurrentPID)
  %else
    %return ::tMassMatrixGlobal
  %endif
%endfunction %% LibGetMassMatrixGlobal
 
 
%%Function:LibGetMassMatrixGlobalIr======================================
%%Abstract:
%%ReturnsthevariablefortheIroftheglobalMassMatrix.
%%
%function LibGetMassMatrixGlobalIr() Output
  %assert (!IsModelReferenceTarget())
  %if Accelerator
    %return RTMGet("MassMatrixIr")
  %else
    %return LibGetMassMatrixGlobal()+".ir"
  %endif
%endfunction %% LibGetMassMatrixGlobalIr
 
%%Function:LibGetMassMatrixGlobalJc======================================
%%Abstract:
%%ReturnsthevariablefortheJcoftheglobalMassMatrix.
%%
%function LibGetMassMatrixGlobalJc() Output
  %assert (!IsModelReferenceTarget())
  %if Accelerator
    %return RTMGet("MassMatrixJc")
  %else
    %return LibGetMassMatrixGlobal()+".jc"
  %endif
%endfunction %% LibGetMassMatrixGlobalJc
 
%%Function:LibGetMassMatrixGlobalPr======================================
%%Abstract:
%%ReturnsthevariablefortheProftheglobalMassMatrix.
%%
%function LibGetMassMatrixGlobalPr() Output
  %if IsModelReferenceTarget()
    %return RTMGet("MassMatrixBasePr")
  %elseif Accelerator
    %return RTMGet("MassMatrixPr")
  %else
    %return LibGetMassMatrixGlobal()+".pr"
  %endif
%endfunction %% LibGetMassMatrixGlobalPr
 
%%Function:SLibGetDWorkPointerFromRTM========================================
%%Abstract:
%%ReturnsapointertotheDWorkstructurefromtheRTM.
%%
%function SLibGetDWorkPointerFromRTM(addTypeCast) void
  %assign retStr = RTMGet("RootDWork")
  %if addTypeCast
    %assign dworkCast = FcnRewriteCast("(%<::tDWorkType> *) %<retStr>")
    %assign retStr = "(%<dworkCast>)"
  %endif
  %return retStr
%endfunction %% SLibGetDWorkPointerFromRTM
 
%%Function:SLibGetCoderDataGroupPointerFromRTM==============================
%%Abstract:
%%ReturnsapointertotheCoderDataGroupstructurefromtheRTM.
%%
%function SLibGetCoderDataGroupPointerFromRTM(group, addTypeCast) void
  %assign rootSystem = ::CompiledModel.System[NumSystems-1]
  %assign baseSystem = ::CompiledModel.System[GetBaseSystemIdx()]
  %assign fieldName = "HasCoderDataGroup" + group.Name + "Arg"
  %assign baseSystem.%<fieldName> = TLC_TRUE
  %assign varGroupIndex = SLibGetRootVarGroupIdxForCoderGroup(group)
 
  %if SLibAccessViaPointerInSelf(group)
    %assign elem = "RCDG" + STRING(group.GroupIndex)
  %else
    %assign elem = "VG" + STRING(varGroupIndex)
  %endif
   
  %if (group.GroupIndex == SLibGetSelfCoderDataGroupIndex())
    %assign retStr = ::tSimStruct
  %elseif (SLibGetUseRTMcgType())
    %assign retStr = SLibGetFieldPointerFromSelf(elem, addTypeCast)
  %else
    %assign retStr = RTMGet(SLibCoderDataGroupRTMFieldName(group))
    %if group.AsStructure == "InSelf"
      %assign retStr = "&(%<retStr>)"
    %endif
  %endif
 
  %if addTypeCast
    %assign typeString = SLibCoderDataGroupType(group)
    %assign typeCast = FcnRewriteCast("(%<typeString> *) %<retStr>")
    %assign retStr = "(%<typeCast>)"
  %endif
 
  %return retStr
%endfunction %% SLibGetCoderDataGroupPointerFromRTM
 
%%Function:SLibGetDWorkStruct================================================
%%Abstract:
%%ReturnsthevariablefortheDWorkvariable.
%%
%function SLibGetDWorkStruct(addTypeCast) void
  %if ::CompiledModel.HasSimStructVars == 1
    %return SLibGetDWorkPointerFromRTM(addTypeCast)
  %elseif IsModelRefScalableBuild() && !GenerateClassInterface
    %assign baseSystem = ::CompiledModel.System[GetBaseSystemIdx()]
    %return FcnSysVarGroupNonreusedName(baseSystem, "DWork")
  %else
    %return ::tDWork
  %endif
%endfunction %% SLibGetDWorkStruct
 
%%Function:LibGetDWorkStruct================================================
%%Abstract:
%%ReturnsthevariablefortheDWorkvariable.
%%
%function LibGetDWorkStruct() void
  %return SLibGetDWorkStruct(TLC_TRUE)
%endfunction %% LibGetDWorkStruct
 
%%Function:SLibGetCoderDataGroupStruct================================================
%%Abstract:
%%ReturnsthevariablefortheCoderDataGroupvariable.
%%
%function SLibGetCoderDataGroupStruct(group, addTypeCast) void
  %if ::CompiledModel.HasSimStructVars == 1
    %return SLibGetCoderDataGroupPointerFromRTM(group,0)
  %elseif IsModelRefScalableBuild() && !GenerateClassInterface
    %assign baseSystem = ::CompiledModel.System[GetBaseSystemIdx()]
    %return FcnSysVarGroupNonreusedName(baseSystem, "CoderDataGroup" + group.Name)
  %else
    %return SLibCoderDataGroupInstance(group)
  %endif
%endfunction %% SLibGetCoderDataGroupStruct
 
%%Function:LibGetCoderDataGroupStruct================================================
%%Abstract:
%%ReturnsthevariablefortheCoderDataGroupvariable.
%%
%function LibGetCoderDataGroupStruct(group) void
  %return SLibGetCoderDataGroupStruct(group, TLC_TRUE)
%endfunction %% LibGetCoderDataGroupStruct
 
%%Function:LibGetContStatesStruct==========================================
%%Abstract:
%%ReturnsthevariablefortheContStatesvariable.
%%
%function LibGetContStatesStruct() void
  %return LibGetContinuousStateStruct()
%endfunction %% LibGetContStatesStruct
 
%%Function:LibGetContStatesDisabledStruct==================================
%%Abstract:
%%ReturnsthevariablefortheContStatesDisabledvariable.
%%
%function LibGetContStatesDisabledStruct() void
  %return LibGetContinuousStateDisabledStruct()
%endfunction %% LibGetContStatesDisabledStruct
 
%%Function:LibGetContStatesAbsoluteToleranceStruct=========================
%%Abstract:
%%ReturnsthevariablefortheContStatesAbsoluteTolerancevariable.
%%
%function LibGetContStatesAbsoluteToleranceStruct() void
  %return LibGetContinuousStateAbsoluteToleranceStruct()
%endfunction %% LibGetContStatesAbsoluteToleranceStruct
 
 
%%Function:LibGetContStatesPerturbMinStruct=========================
%%Abstract:
%%ReturnsthevariablefortheContStatesPerturbMinvariable.
%%
%function LibGetContStatesPerturbMinStruct() void
  %return LibGetContinuousStatePerturbMinStruct()
%endfunction %% LibGetContStatesPerturbMinStruct
 
%%Function:LibGetContStatesPerturbMaxStruct=========================
%%Abstract:
%%ReturnsthevariablefortheContStatesPerturbMaxvariable.
%%
%function LibGetContStatesPerturbMaxStruct() void
  %return LibGetContinuousStatePerturbMaxStruct()
%endfunction %% LibGetContStatesPerturbMinStruct
 
%%Function:LibGetContStatesDerivativeStruct================================
%%Abstract:
%%ReturnsthevariablefortheContStatesDerivativevariable.
%%
%function LibGetContStatesDerivativeStruct() void
  %return LibGetDotContinuousStateStruct()
%endfunction %% LibGetContStatesDerivativeStruct
 
 
%%Function:SLibGetPreviousZCStructFromRTM===================================
%%Abstract:
%%ReturnsthevariableforthepreviouszerocrossingsvariablefromRTM.
%%
%function SLibGetPreviousZCStructFromRTM(addTypeCast) void
  %if CodeFormat == "S-Function"
    %assign retStr = RTMuGet("PrevZCSigState")
  %else
    %assign retStr = RTMGet("PrevZCSigState")
  %endif
  %if addTypeCast
    %assign retStr = "((%<::tPrevZCStateType> *) %<retStr>)"
  %endif
  %return retStr
%endfunction %% SLibGetPreviousZCStructFromRTM
 
%%Function:SLibGetPreviousZCStruct===========================================
%%Abstract:
%%Returnsthevariableforthepreviouszerocrossingsvariable.
%%
%function SLibGetPreviousZCStruct(addTypeCast) void
  %if ::CompiledModel.HasSimStructVars == 1
    %return SLibGetPreviousZCStructFromRTM(addTypeCast)
  %elseif IsModelRefScalableBuild() && !GenerateClassInterface
    %assign baseSystem = ::CompiledModel.System[GetBaseSystemIdx()]
    %return FcnSysVarGroupNonreusedName(baseSystem, "ZCEvent")
  %else
    %return ::tPrevZCState
  %endif
%endfunction %% SLibGetPreviousZCStruct
 
%%Function:LibGetPreviousZCStruct===========================================
%%Abstract:
%%Returnsthevariableforthepreviouszerocrossingsvariable.
%%
%function LibGetPreviousZCStruct() void
  %return SLibGetPreviousZCStruct(TLC_TRUE)
%endfunction %% LibGetPreviousZCStruct
 
%%Function:LibGetZCEventStruct===========================================
%%Abstract:
%%Returnsthevariableforthepreviouszerocrossingsvariable.
%%Calledbyopaquelib.tlc:SLibCGIRVarGroupPath().
%%
%function LibGetZCEventStruct() void
  %return LibGetPreviousZCStruct()
%endfunction %% LibGetZCEventStruct
 
%%Function:LibGetParameterStruct===========================================
%%Abstract:
%%Returnsthevariablefortheparametersvariable.
%%
%function LibGetParameterStruct() void
  %return LibGetParametersStruct()
%endfunction
 
%%Function:SLibGetParamPointerFromRTM========================================
%%Abstract:
%%ReturnsapointertotheparameterstructurefromtheRTM.
%%
%function SLibGetParamPointerFromRTM(addTypeCast) void
  %if Accelerator
    %assign retStr = RTMGet("ModelRtp")
  %elseif CodeFormat == "S-Function"
    %assign retStr = RTMGet("LocalDefaultParam")
  %else
    %assign retStr = RTMGet("DefaultParam")
  %endif
  %if addTypeCast
    %assign retStr = "((%<::tParametersType> *) %<retStr>)"
  %endif
  %return retStr
%endfunction %% SLibGetParamPointerFromRTM
 
%%Function:SLibGetParametersStruct===========================================
%%Abstract:
%%Returnsthevariablefortheparametersvariable.
%%
%function SLibGetParametersStruct(addTypeCast) void
  %if ::CompiledModel.HasSimStructVars == 1
    %return SLibGetParamPointerFromRTM(addTypeCast)
  %elseif IsModelRefScalableBuild() && !GenerateClassInterface
    %assign baseSystem = ::CompiledModel.System[GetBaseSystemIdx()]
    %return FcnSysVarGroupNonreusedName(baseSystem, "Parameter")
  %else
    %assign paramStructVarName = ::tParameters
    %return paramStructVarName
  %endif
%endfunction %% SLibGetParametersStruct
 
%%Function:LibGetParametersStruct===========================================
%%Abstract:
%%Returnsthevariablefortheparametersvariable.
%%
%function LibGetParametersStruct() void
  %return SLibGetParametersStruct(TLC_TRUE)
%endfunction %% LibGetParametersStruct
 
 
%%Function:SLibGetZCSignalValueStructFromRTM================================
%%Abstract:
%%Returnsthevariableforthenon-sampledzerocrossingsfromRTM.
%%
%function SLibGetZCSignalValueStructFromRTM(addTypeCast) void
  %if ::CodeFormat == "S-Function" && !::Accelerator
    %assign retStr = RTMGet("NonsampledZCs")
  %else
    %assign retStr = RTMGet("SolverZcSignalVector")
  %endif
  %if addTypeCast
    %assign retStr = "((%<::tZCSignalValueType> *) %<retStr>)"
  %endif
  %return retStr
%endfunction %% SLibGetZCSignalValueStructFromRTM
 
%%Function:SLibGetZCSignalValueStruct========================================
%%Abstract:
%%Returnsthevariableforthenon-sampledzerocrossings.
%%
%function SLibGetZCSignalValueStruct(addTypeCast) void
  %if ::CompiledModel.HasSimStructVars == 1 || ::isRSimWithSolverModule
    %return SLibGetZCSignalValueStructFromRTM(addTypeCast)
  %else
    %return ::tZCSignalValue
  %endif
%endfunction %% SLibGetZCSignalValueStruct
 
%%Function:LibGetZCSignalValueStruct========================================
%%Abstract:
%%Returnsthevariableforthenon-sampledzerocrossings.
%%
%function LibGetZCSignalValueStruct() void
  %return SLibGetZCSignalValueStruct(TLC_TRUE)
%endfunction %% LibGetZCSignalValueStruct
 
%function LibGetZCSVStruct() void
  %return LibGetZCSignalValueStruct()
%endfunction
%%
%%(2)LocalLibraryFunctions(FcnFunctions)
%%
 
 
%%
%%Endoflibrarycode
%%
 
%endif %% _FCNIOLIB_
 
%%[EOF]fcniolib.tlc