%%
%%
%%
%%Copyright1994-2019TheMathWorks,Inc.
 
%selectfile NULL_FILE
 
%if EXISTS("_COMMENTLIB_") == 0
%assign _COMMENTLIB_ = 1
 
%function LibCacheBlockComment(block, buf) void
  %if !HaveBlockComment && (!ExprFolding || GenerateComments)
    %addtorecord block BlockComment buf
    %<SETFIELD(block,"HaveBlockComment",1)>
  %endif
%endfunction
 
%function LibBlockParameterForComment(param) void
  %if !ExprFolding || GenerateComments
    %assign size = LibBlockParameterSize(param)
    %assign width = size[0] * size[1]
    %if width == 1
      %return LibBlockParameter(param,"","",0)
    %elseif param.String != ""
      %return param.String
    %elseif param.StringTransformed != ""
      %return param.StringTransformed
    %elseif width < 5
      %assert !LibIsEnumDataType(LibGetRecordDataTypeId(param))
      %return "Computed value %<SLibGetValueFromParamRec(param, TLC_FALSE)>"
    %else
      %return ""
    %endif
  %else
    %return ""
  %endif
%endfunction
 
%%Function:FcnGetBlockDescriptionInFcnBanner=================================
%%Abstract:
%%Addblockdescriptionsingeneratedfunctionbanner.Don'tcheck
%%InsertBlockDesc
%%
%function FcnGetBlockDescriptionInFcnBanner(block) void
  %assign description = GetBlockDescription(block)
  %return description
%endfunction
 
%%Function:FcnGetBlockDescription============================================
%%Abstract:
%%Addblockdescriptionsingeneratedcodeoutsidefunctionbanner.
%%
%function FcnGetBlockDescription(block) void
  %assert(InsertBlockDesc)
  %assign description = GetBlockDescription(block)
  %if !ISEMPTY(description)
    %assign description = "/nBlock description for '%<SLibBlkName(block)>':/n" + ...
      description
  %endif
  %return description
%endfunction
 
%%Function:GetBlockDescription============================================
%%Abstract:
%%Usedtoaddblockdescriptionsingeneratedcode
%%
%function GetBlockDescription(block) void
  %if !ISFIELD(block,"DescriptionWritten")
    %addtorecord block DescriptionWritten 1
  %endif
  %if !WHITE_SPACE(block.Description) && !ISEMPTY(block.Description)
    %assign description = FEVAL("rtwprivate", "wordWrapCommentString", block.Description, 80, 5)
     
    %% add 2 spaces indentation at the beginning of each line of block description
    %assign description = FEVAL("regexprep", description, "/n", "/n ")
    %assign description = FEVAL("deblank", description)
    %assign description = " " + description
  %else
    %assign description = ""
  %endif
  %return description
%endfunction
 
%%Function:FcnGetPolySpaceStartComments============================================
%%Abstract:
%%Addpolyspacestartcommentsinthegeneratedcode.
%%
%function FcnGetPolySpaceStartComments(block) void
  %assert(InsertPolySpaceComments)
  %assign polyspaceStartComments = ""
  %if ISFIELD(block, "PolySpaceStartComment") && (SIZE(block.PolySpaceStartComment,1) > 0)
    %assign polyspaceStartComments = GetPolySpaceStartComments(block)
  %endif
  %return polyspaceStartComments
%endfunction
 
%%Function:GetPolySpaceStartComments============================================
%%Abstract:
%%Usedtoaddpolyspacecommentsinthegeneratedcode
%%
%function GetPolySpaceStartComments(block) void
  %assign retStr = block.PolySpaceStartComment
  %if !WHITE_SPACE(retStr)
    %assign retStr = "*/n* " + retStr
  %else
    %assign retStr = ""
  %endif
 
  %return retStr
%endfunction
 
%%Function:FcnGetPolySpaceEndComments============================================
%%Abstract:
%%Addpolyspaceendcommentsinthegeneratedcode.
%%
%function FcnGetPolySpaceEndComments(block) void
  %assert(InsertPolySpaceComments)
  %assign polyspaceEndComments = ""
  %if ISFIELD(block, "PolySpaceEndComment") && (SIZE(block.PolySpaceEndComment,1) > 0)
    %assign polyspaceEndComments = GetPolySpaceEndComments(block)
  %endif
  %return polyspaceEndComments
%endfunction
 
%%Function:GetPolySpaceEndComments============================================
%%Abstract:
%%Usedtoaddpolyspaceendcommentsinthegeneratedcode.Returnsempty
%%stringifnoPolySpaceendcommentsarefound
%%
%function GetPolySpaceEndComments(block) void
  %assign retStr = block.PolySpaceEndComment
  %if !WHITE_SPACE(retStr)
    %assign retStr = "* " + retStr
  %else
    %assign retStr = ""
  %endif
 
  %return retStr
%endfunction
 
%%Function:FcnGetBlockRequirements===========================================
%%Abstract:
%%
%%
%function FcnGetBlockRequirements(block) void
  %assert(ReqsInCode)
  %if !ISFIELD(block,"RequirementsWritten")
    %addtorecord block RequirementsWritten 1
  %endif
  %assign reqStr = ""
  %if ISFIELD(block,"Requirements") && (SIZE(block.Requirements,1) > 0)
    %assign reqStr = reqStr + ...
      "*/n* Block requirements for '%<SLibBlkName(block)>':/n" + block.Requirements
  %endif
  %if ISFIELD(block,"InheritedRequirements") && ...
    (SIZE(block.InheritedRequirements,1) > 0)
    %assign reqStr = reqStr + block.InheritedRequirements
  %endif
  %return reqStr
%endfunction
 
%%Function:generateNonExprOutput=============================================
%%Abstract:
%%GeneratetheoutputscodeofablockforspecificTID,accountingforblock
%%description,andexpressionfolding.
%%
%function generateNonExprOutput(block, system, sfuncName, tid, useTid) void
  %assign retBuf = ""
  %assign tmpBuf = ""
  %openfile tmpBuf
  %if useTid
    %if sfuncName != ""
      %<GENERATE_TYPE(block, "OutputsForTID", sfuncName, system, tid)> /
    %else
      %<GENERATE(block, "OutputsForTID", system, tid)> /
    %endif
  %else
    %<GENERATE(block, "Outputs", system)> /
  %endif
   
  %closefile tmpBuf
  %openfile retBuf
  %if !WHITE_SPACE(tmpBuf)
    %assign needsBlockComment = SimulinkBlockComments && NEEDS_COMMENT(tmpBuf)
    %if GenerateComments && block.Type != "Opaque"
      %if !(::CompiledModel.TagTlcBlocks)
        %% Write block start comment
        %<FcnWriteExprComment(block, needsBlockComment, 1)>/
      %else
        %assign blkComment = FcnGetBlockComment(block)
        %if !WHITE_SPACE(blkComment)
          %assign blkComment = "/*/n" + blkComment + "/n*//n"
          %<blkComment>/
        %endif
      %endif
    %endif
    %<tmpBuf>/
    %if GenerateComments && block.Type != "Opaque" && !(::CompiledModel.TagTlcBlocks)
      %% Write block end comment
      %<FcnWriteExprComment(block, needsBlockComment, 0)>/
    %endif
  %endif
   
  %closefile retBuf
  %return retBuf
%endfunction
 
%%Function:SLibAddToExprCommentList==========================================
%%Description:
%%Addrecordinformationtotheexpressioncommentlist(inawaythat
%%FcnWriteExprCommentwillunderstand).
%%
%function SLibAddToExprCommentList(commInfo, record, srcPort) void
  %assign recName = "%<LibGetRecordIdentifier(record)>___%<srcPort>__"
  %if TYPE(record) == "Scope" && !ISFIELD(commInfo, recName)
    %addtorecord commInfo %<recName> 1
    %switch record.RecordType
      %case "ExternalInput"
    %assign extInp = record
    %assign commInfo.SysIdxList = commInfo.SysIdxList + "U"
    %assign commInfo.BlkIdxList = commInfo.BlkIdxList + extInp
        %assign commInfo.PortIdxList = commInfo.PortIdxList + srcPort
    %break
      %case "Block"
    %assign srcBlk = record
    %assign commInfo.SysIdxList = commInfo.SysIdxList + srcBlk.BlockIdx[0]
    %assign commInfo.BlkIdxList = commInfo.BlkIdxList + srcBlk.BlockIdx[2]
        %assign commInfo.PortIdxList = commInfo.PortIdxList + srcPort
    %break
      %default
    %assign errTxt = "%<record.RecordType> record not handled"
    %<LibReportFatalError(errTxt)>
    %endswitch
  %endif
%endfunction
 
%function SLibBlkType(block) void
  %if block.Type == "S-Function"
    %if block.ParamSettings.FunctionName == "stateflow"
      %if ISFIELD(block, "StateflowChartType")
         %return block.StateflowChartType
      %else
         %return "Stateflow"
      %endif
    %else
      %return "%<block.Type> (%<block.ParamSettings.FunctionName>)"
    %endif
  %elseif block.Type == "SubSystem" && ISFIELD(block, "MaskType") && ...
    block.MaskType == "Stateflow"
      %if ISFIELD(block, "StateflowChartType")
         %return block.StateflowChartType
      %else
         %return "Stateflow"
      %endif
  %else
    %return block.Type
  %endif
%endfunction
 
%function SLibBlkName(block) void
  %return LibGetBlockName(block)
%endfunction
 
%function SLibSSIsInlined(block) void
  %with block
    %assign bType = (Type == "SubSystem")? "Subsystem" : ""
    %assign ss = ...
      ::CompiledModel.System[LibBlockParamSetting(bType, "SystemIdx")]
  %endwith
  %return LibSystemIsInlined(ss)
%endfunction
 
%function writeBlockRequirements(block)
  %return ReqsInCode && !ISFIELD(block,"RequirementsWritten") ...
    && ((ISFIELD(block,"Requirements") && (SIZE(block.Requirements,1)>0)) ...
    || (ISFIELD(block,"InheritedRequirements") && ...
    (SIZE(block.InheritedRequirements,1) > 0)))
%endfunction
 
%function writeBlockDescription(block)
  %return InsertBlockDesc && (SIZE(block.Description,1) > 0) && ...
    !WHITE_SPACE(block.Description) && ...
    !ISFIELD(block,"DescriptionWritten")
%endfunction
 
%function writePolySpaceStartComments(block)
  %return InsertPolySpaceComments && ...
     (SIZE(block.PolySpaceStartComment,1) > 0 && ...
       !WHITE_SPACE(block.PolySpaceStartComment))
%endfunction
 
%function writePolySpaceEndComments(block)
  %return InsertPolySpaceComments && ...
      (SIZE(block.PolySpaceEndComment,1) > 0 && ...
       !WHITE_SPACE(block.PolySpaceEndComment))
%endfunction
 
%function FcnGetBlockComment(block)
  %assign text = ""
  %if HaveBlockComment
    %assign text = "* About '%<SLibBlkName(block)>':/n" + ...
      BlockComment
    %assign text = FEVAL("deblank",text)
  %endif
  %return text
%endfunction
 
%function WriteBlockComments(block, needsBlockComment) void
  %assign text = "/n" + FcnGetBlockComment(block)
  %if writeBlockDescription(block)
    %assign tmpbuf = FEVAL("rtwprivate", "rtw_format_banner", ...
      "insert_comment_prefix", FcnGetBlockDescription(block))
    %assign text = text + "/n" + FEVAL("deblank",tmpbuf)
  %endif
   
  %if writeBlockRequirements(block)
    %assign text = text + "/n" + FcnGetBlockRequirements(block)
  %endif
 
  %if writePolySpaceStartComments(block)
    %assign text = text + "/n" + FcnGetPolySpaceStartComments(block)
  %endif
   
  %if !WHITE_SPACE(text)
    %assign text = text + "/n"
  %endif
 
  %if needsBlockComment
    %return "/n/* %<SLibBlkType(block)>: '%<SLibBlkName(block)>'" ...
      + text + " *//n"
  %else
    %return WHITE_SPACE(text) ? "" : "/n/* " + text + " *//n"
  %endif
       
%endfunction
 
%%Function:FcnWriteExprComment===============================================
%%Description:
%%Writeoutacommentlistingalltheblocksfoldedintotheexpression
%%forblock.Also,writetheirblockdescriptionfields.
%%
%function FcnWriteExprComment(block, needsBlockComment, startComment) void
 
  %assign text = ""
 
  %if !SLibBlockIsExpressionCompliant(block)
     
    %if startComment
      %if needsBlockComment || writeBlockDescription(block) || ...
        writeBlockRequirements(block) || writePolySpaceStartComments(block)
       
        %assign text = WriteBlockComments(block, needsBlockComment)
       
      %endif
    %else
      %if writePolySpaceEndComments(block)
        %assign pSpaceEndComment = FcnGetPolySpaceEndComments(block)
        %assign text = "/" + pSpaceEndComment + " *//n"
      %endif
    %endif
     
  %elseif !ExprFolding
     
    %if startComment
      %assign text = WriteBlockComments(block, needsBlockComment)
    %else
      %if writePolySpaceEndComments(block)
        %assign pSpaceEndComment = FcnGetPolySpaceEndComments(block)
          %assign text = "/" + pSpaceEndComment + " *//n"
      %endif
    %endif
 
  %elseif block.Type == "SubSystem" && SLibSSIsInlined(block) && ...
    ISFIELD(block, "MaskType") && block.MaskType == "Stateflow"
    %% do not return any thing
  %else
     
    %if startComment
      %assign endedWithNewline = 0
      %assign multilineComment = 0
      %assign numBlksInExpr = SIZE(block.ExprCommentInfo.BlkIdxList,1)
     
      %if SimulinkBlockComments
        %% describe master block
        %assign text = text + "%<SLibBlkType(block)>: '%<SLibBlkName(block)>'"
       
        %if numBlksInExpr > 0
          %assign text = text + " incorporates:"
          %assign multilineComment = 1
          %assign endedWithNewline = 0
        %endif
       
        %foreach idx = numBlksInExpr
          %assign text = text + "/n"
          %if ISEQUAL(ExprCommentInfo.SysIdxList[idx],"U")
            %% Root inport
            %assign extInp = ExprCommentInfo.BlkIdxList[idx]
            
            %assign text = text + ...
              "* Inport: '%<extInp.BlockName>'"
          %else
            %% Standard block
            %assign origSysIdx = ExprCommentInfo.SysIdxList[idx]
            %assign origBlkIdx = ExprCommentInfo.BlkIdxList[idx]
            %assign origBlk = System[origSysIdx].Block[origBlkIdx]
           
            %if origBlk.Type == "Opaque"
              %assign portIdx = ExprCommentInfo.PortIdxList[idx]
              %assign tmpBuff = GENERATE(origBlk, "BlockOutputComment", portIdx)
              %if !WHITE_SPACE(tmpBuff)
                %assign text = text + tmpBuff
              %endif
            %else
              %assign text = text + ...
                "* %<SLibBlkType(origBlk)>: '%<SLibBlkName(origBlk)>'"
            %endif
          %endif
        %endforeach
      %else
        %assign endedWithNewline = 1
      %endif
     
      %if HaveBlockComment
        %if !endedWithNewline
          %assign text = text + "/n"
        %endif
        %assign text = text + ...
          "*/n" + ...
          "* Regarding '%<SLibBlkName(block)>':/n" + ...
          BlockComment
        %assign endedWithNewline = 1 %% block comment ends with newline
        %assign multilineComment = 1
      %endif
     
      %% incorporated block comments
      %foreach idx = numBlksInExpr
        %if !ISEQUAL(ExprCommentInfo.SysIdxList[idx],"U")
          %assign origSysIdx = ExprCommentInfo.SysIdxList[idx]
          %assign origBlkIdx = ExprCommentInfo.BlkIdxList[idx]
          %assign origBlk = System[origSysIdx].Block[origBlkIdx]
         
          %if origBlk.HaveBlockComment
            %if !endedWithNewline
              %assign text = text + "/n"
            %endif
            %assign text = text + ...
            "*/n" + ...
            "* Regarding '%<SLibBlkName(origBlk)>':/n" + ...
                origBlk.BlockComment
            %assign endedWithNewline = 1 %% block comment ends with newline
            %assign multilineComment = 1
          %endif
        %endif
      %endforeach
     
      %% block descriptions
 
      %if InsertBlockDesc
        %if SIZE(block.Description,1) > 0 && ...
            !ISFIELD(block,"DescriptionWritten")
          %%
          %assign writeDesc = 1
          %if block.Type == "SubSystem"
            %with block
              %assign locSysIdx = LibBlockParamSetting("Subsystem", "SystemIdx")
              %assign writeDesc = System[locSysIdx].DescInCallSite
            %endwith
          %endif
 
          %%
          %if writeDesc
            %if !endedWithNewline
              %assign text = text + "/n"
            %endif
            %assign tmpbuf = FEVAL("rtwprivate", "rtw_format_banner", "insert_comment_prefix", FcnGetBlockDescription(block))
            %assign text = text + tmpbuf
            %assign multilineComment = 1
            %assign endedWithNewline = 1
          %endif
        %endif
       
        %foreach idx = numBlksInExpr
          %if !ISEQUAL(ExprCommentInfo.SysIdxList[idx],"U")
            %assign origSysIdx = ExprCommentInfo.SysIdxList[idx]
            %assign origBlkIdx = ExprCommentInfo.BlkIdxList[idx]
            %assign origBlk = System[origSysIdx].Block[origBlkIdx]
 
            %if origBlk.Type == "Opaque"
              %assign portIdx = ExprCommentInfo.PortIdxList[idx]
              %assign tmpBuff = GENERATE(origBlk,"BlockOutputDescription",portIdx)
              %if !WHITE_SPACE(tmpBuff)
                %if !endedWithNewline
                  %assign text = text + "/n"
                %endif
                %assign text = text + tmpBuff
                %assign multilineComment = 1
                %assign endedWithNewline = 0
              %endif
            %elseif SIZE(origBlk.Description,1) > 0 && ...
                !ISFIELD(origBlk,"DescriptionWritten")
              %%
              %assign writeDesc = 1
              %if origBlk.Type == "SubSystem"
                %with origBlk
                  %assign bType = (Type == "SubSystem") ? "Subsystem" : ""
                  %assign locSysIdx = LibBlockParamSetting(bType, "SystemIdx")
                %endwith
                %assign writeDesc = System[locSysIdx].DescInCallSite
              %endif
              %%
              %if writeDesc
                %if !endedWithNewline
                  %assign text = text + "/n"
                %endif
                %assign tmpbuf = FEVAL("rtwprivate", "rtw_format_banner", "insert_comment_prefix", FcnGetBlockDescription(origBlk))
                %assign text = text + tmpbuf
                %assign multilineComment = 1
                %assign endedWithNewline = 1
              %endif
            %endif
          %endif
        %endforeach
      %endif
 
      %if writeBlockRequirements(block)
        %% Add new line if needed
        %if !endedWithNewline
          %assign text = text + "/n"
        %endif
 
        %% Cat requirements to comment
        %assign text = text + FcnGetBlockRequirements(block)
 
        %assign multilineComment = 1
        %assign endedWithNewline = 0
      %endif
 
      %% requirement in expr-folded blocks
      %if ReqsInCode
        %foreach idx = numBlksInExpr
          %if !ISEQUAL(ExprCommentInfo.SysIdxList[idx],"U")
            %assign origSysIdx = ExprCommentInfo.SysIdxList[idx]
            %assign origBlkIdx = ExprCommentInfo.BlkIdxList[idx]
            %assign origBlk = System[origSysIdx].Block[origBlkIdx]
 
            %if origBlk.Type == "Opaque"
              %assign portIdx = ExprCommentInfo.PortIdxList[idx]
              %assign tmpBuff = GENERATE(origBlk,"BlockOutputRequirements",portIdx)
              %if !WHITE_SPACE(tmpBuff)
                %% Add new line if needed
                %if !endedWithNewline
                  %assign text = text + "/n"
                %endif
                %assign text = text + tmpBuff
                %assign multilineComment = 1
                %assign endedWithNewline = 1
              %endif
            %endif
          %endif
        %endforeach
      %endif
 
      %% Polyspace start comments
      %if writePolySpaceStartComments(block)
        %% Add new line if needed
        %if !endedWithNewline
          %assign text = text + "/n"
        %endif
 
        %% Cat polyspace comments
        %assign text = text + FcnGetPolySpaceStartComments(block)
 
        %assign multilineComment = 1
        %assign endedWithNewline = 0
        %foreach idx = numBlksInExpr
          %assign origSysIdx = ExprCommentInfo.SysIdxList[idx]
          %assign origBlkIdx = ExprCommentInfo.BlkIdxList[idx]
          %assign origBlk = System[origSysIdx].Block[origBlkIdx]
 
          %assign portIdx = ExprCommentInfo.PortIdxList[idx]
          %assign tmpBuff = FcnGetPolySpaceStartComments(origBlk)
          %if !WHITE_SPACE(tmpBuff)
            %% Add new line if needed
            %if !endedWithNewline
              %assign text = text + "/n"
            %endif
            %assign text = text + tmpBuff + "/n"
            %assign multilineComment = 1
            %assign endedWithNewline = 1
          %endif
        %endforeach
      %endif
 
      %% optional newline
      %if multilineComment && !endedWithNewline
        %assign text = text + "/n"
      %endif
 
      %if !ISEMPTY(text)
        %% add open/close comment
        %assign text = "/n/* " + text + " */"
      %endif
    %else
      %assign numBlksInExpr = SIZE(block.ExprCommentInfo.BlkIdxList,1)
 
      %if SimulinkBlockComments
        %% do parent block
        %if writePolySpaceEndComments(block)
          %assign text = FcnGetPolySpaceEndComments(block)
          %if !WHITE_SPACE(text)
            %assign text = "/" + text
          %endif
 
          %% do child blocks
          %foreach idx = numBlksInExpr
            %assign origSysIdx = ExprCommentInfo.SysIdxList[idx]
            %assign origBlkIdx = ExprCommentInfo.BlkIdxList[idx]
            %assign origBlk = System[origSysIdx].Block[origBlkIdx]
 
            %if origBlk.Type == "Opaque"
              %assign tmpBuff = FcnGetPolySpaceEndComments(origBlk)
              %if !WHITE_SPACE(tmpBuff)
                %assign text = text + "/n" + tmpBuff
              %endif
            %endif
          %endforeach
 
          %if !WHITE_SPACE(text)
            %assign text = text + " *//n"
          %endif
        %endif
      %endif
    %endif
  %endif %% ExprFolding
     
  %return text
   
%endfunction
 
%%Function:SLibStateflowSysName=============================================
%%Description:
%%ReturntheSystemIDofStateflowblock
%%
%function SLibStateflowSysName(ssblk) void
  %return "<"+System[ssblk.BlockIdx[0]].SysName+">"
%endfunction
 
%%Function:SLibStateflowComment=============================================
%%Description:
%%ReturncommentsforStateflowobjects.CalledbygeneratedTLCcodefor
%%Stateflowcharts.
%%
%function SLibStateflowComment(ssblk,type,name,ssId) void
  %assign sysname = SLibStateflowSysName(ssblk)
  %if !ISEMPTY(name)
    %assign name = " '%<name>'"
  %endif
  %if ISEMPTY(type) && ISEMPTY(name)
    %assign colon = ""
  %else
    %assign colon = ": "
  %endif
  %assign delim = ":"
  %return type+name+colon+"'"+sysname+delim+"%<ssId>'"
%endfunction
 
%%Function:FcnEmulationHWCommentHelper======================================
%%Description:
%%Returntrueifemulationhardwaresettingofthegivenfieldisdifferent
%%fromthesettinginembeddedhardware.
%%
%function FcnEmulationHWDifferent(field)
  %return ConfigSet.Prod%<field> != ConfigSet.Target%<field>
%endfunction
 
%%Function:SLibEmulationHWComment===========================================
%%Description:
%%Returncommentonwhetheremulationhardwareisdifferentfromembedded
%%hardware.
%%
%function SLibEmulationHWComment() void
  %if !ISEMPTY(::EmulationHWComment)
    %return ::EmulationHWComment
  %endif
  %assign str = ""
  %if FcnEmulationHWDifferent("BitPerChar") || ...
    FcnEmulationHWDifferent("BitPerShort") || ...
    FcnEmulationHWDifferent("BitPerInt") || ...
    FcnEmulationHWDifferent("BitPerLong") || ...
    FcnEmulationHWDifferent("WordSize") || ...
    FcnEmulationHWDifferent("Endianess") || ...
    FcnEmulationHWDifferent("IntDivRoundTo") || ...
    FcnEmulationHWDifferent("ShiftRightIntArith")
    %assign str = "Differs from embedded hardware"
    %if FcnEmulationHWDifferent("HWDeviceType")
      %assign str = "/n " + str + " (" + ConfigSet.TargetHWDeviceType + ")"
    %endif
  %else
    %assign str = ""
  %endif
  %assign ::EmulationHWComment = str
  %return str
%endfunction
 
%%Function:SLibGetCallSitesComment===========================================
%%Description:
%%Generatecommentreferringallcallsite.
%%
%function SLibGetCallSitesComment(sysIdx) void
  %assign callSites = ::CompiledModel.System[sysIdx].CallSites
  %assign numCallSites = SIZE(callSites,0)
  %if numCallSites == 0
    %return ""
  %endif
  %assign comment = ""
  %foreach idx = numCallSites
    %assign cs = callSites[idx]
    %assign ssBlk = System[cs[2]].Block[cs[3]]
    %assign comment = comment + "'" + ssBlk.Name + "'"
    %if (numCallSites > 1)
      %if (idx < (numCallSites-1))
        %assign comment = comment + "/n* "
      %else
        %assign comment = comment + "/n"
      %endif
    %endif
  %endforeach
  %return comment
%endfunction
 
%%Function:SLibGetRefBlockCommentForDataRec===========================================
%%Description:
%%Generatereferenceblockcommentsfordatarecord
%%
%function SLibGetRefBlockCommentForDataRec(dataRec) void
  %if !ISFIELD(dataRec, "GraphicalRef")
    %return ""
  %endif
   
  %assign numBlocks = SIZE(dataRec.GraphicalRef, 0)
  %if numBlocks == 1
    %assign refBlock = SLibGrBlockCommentName(dataRec.GraphicalRef[0])
    %assign comment = "/* Referenced by: %<refBlock> */"
  %else
    %assign comment = "/* Referenced by:/n"
    %foreach idx = SIZE(dataRec.GraphicalRef, 0)
      %assign refBlock = SLibGrBlockCommentName(dataRec.GraphicalRef[idx])
      %assign comment = comment + "* %<refBlock>/n"
    %endforeach
    %assign comment = comment + "*/"
  %endif
  %return comment
%endfunction
 
%%Function:SLibAddBlockTraceForDeclarationFromDataRec===========================================
%%Description:
%%Addblockorreferenceblocktraceabilitytodeclarations
%%
%function SLibAddBlockTraceForDeclarationFromDataRec(dataRec, decls) void
  %if ISFIELD(dataRec, "GrSrc")
    %assign blockName = SLibGrBlockCommentName(dataRec.GrSrc)
    %if !WHITE_SPACE(blockName) && TLC_FALSE ...
      && ISFIELD(dataRec, "LogicalSrc") %% limit the feature to block IO for now
      %assign idnum = IDNUM(dataRec.LogicalSrc)
      %if idnum[0] == "B" && SIZE(dataRec.GrSrc)[1] > 3
        %assign suffix = "@out:" + STRING(dataRec.GrSrc[2]+1) + "^"
        %assign last = SIZE(blockName)[1] - 1
        %assign isQuoted = blockName[0] == "'" && blockName[last] == "'"
        %assign isParened = blockName[0] == "(" && blockName[last] == ")"
        %if isQuoted || isParened
          %assign blockName = CGMODEL_ACCESS("String.substr", blockName, 0, last)
        %endif
        %assign blockName = blockName + suffix
        %if isQuoted
          %assign blockName = blockName + "'"
        %elseif isParened
          %assign blockName = blockName + ")"
        %endif
      %endif
    %endif
    %if !WHITE_SPACE(blockName)
      %assign blockTraceMarker = SLibAddBlockTrace(blockName)
      %assign decls = "%<SLibTraceBegin(blockTraceMarker)> %<decls> %<SLibTraceEnd(blockTraceMarker)> /* %<blockName> */"
    %endif
  %endif
   
  %if ISFIELD(dataRec, "GraphicalRef")
    %foreach idx = SIZE(dataRec.GraphicalRef, 0)
      %assign refBlock = SLibGrBlockCommentName(dataRec.GraphicalRef[idx])
      %assign refBlockTraceMarker = SLibAddBlockTrace(refBlock)
      %assign decls = "%<SLibTraceBegin(refBlockTraceMarker)> %<decls> %<SLibTraceEnd(refBlockTraceMarker)>"
    %endforeach
    %assign decls = "%<decls> %<SLibGetRefBlockCommentForDataRec(dataRec)>"
  %endif
  %return decls
%endfunction
%%Function:SLibWriteHeaderFileComments=======================================
%%Description:
%%Inmodel.h,wecanoptionallywriteoutcommentsforthefollowing
%%*anyreducedblocksinthemodel
%%*thesystemhierarchyandhelpwithlinkstoeachsystem
%%*anyrequirements
%function SLibWriteHeaderFileComments() void
  %% =============================================================================
  %% Reduced blocks
  %%
  %openfile rtwReducedBlocksBuffer
  %<LibDeclareReducedBlocks()>/
  %closefile rtwReducedBlocksBuffer
   
  %% ============================================================================
  %% Model hierarchy
  %%
  %openfile rtwSystemHierarchyBuffer
  %if !Accelerator && GenerateComments
    %<LibDeclareSystemHierarchy()>/
  %endif
  %closefile rtwSystemHierarchyBuffer
   
  %% ============================================================================
  %% Requirements
  %%
  %openfile requirementsBuffer
  %if !Accelerator && GenerateComments
    %<LibDeclareSystemRequirements()>/
  %endif
  %closefile requirementsBuffer
   
   
  %<SLibCacheCodeToFile("baseMdl_hdr_doc", rtwReducedBlocksBuffer)>
  %undef rtwReducedBlocksBuffer
  %<SLibCacheCodeToFile("baseMdl_hdr_doc", rtwSystemHierarchyBuffer)>
  %undef rtwSystemHierarchyBuffer
  %<SLibCacheCodeToFile("baseMdl_hdr_doc", requirementsBuffer)>
  %undef requirementsBuffer
%endfunction
 
%endif %% _COMMENTLIB_
 
%%[EOF]commentlib.tlc