%if EXISTS("::_SFUNCTION_PRIVATE_API_") == 0
%assign ::_SFUNCTION_PRIVATE_API_ = 1
%%
%%Copyright2019TheMathWorks,Inc.
%%
 
%%
%%GlobalVariabletocachetheexistenceofTLCfiles
%%FILE_EXISTScanbeveryslow.Onceitisknownthatafileexists,
%%itismuchquickertolookinthecache.
%%
%assert !EXISTS("::GblInlinedTLCFileAccessed")
%createrecord ::GblInlinedTLCFileAccessed {}
 
%%Function{BlockFunctions}:LibBlockSFunctionFileExists
%%Abstract:
%%LibBlockSFunctionFileExistsdeterminesiftheTLCfileforan
%%S-functionexists.BecauseFILE_EXISTScanbeveryslowespecially
%%overanetwork,theexistenceofthefileiscachedinaglobalvariable.
%%SubsequentcallsforthesameS-Functionwillexecutemuchquicker.
%%
%function LibBlockSFunctionFileExists(sfuncName) void
  %%
  %% check cache to see if file existence has already been checked
  %%
  %if ISFIELD(::GblInlinedTLCFileAccessed, sfuncName)
    %assign fileExists = 1
  %elseif FILE_EXISTS(::GENERATE_FILENAME(sfuncName))
    %assign fileExists = 1
    %<SETFIELD(GblInlinedTLCFileAccessed, sfuncName, 1)>
  %else
    %assign fileExists = 0
  %endif
  %return fileExists
%endfunction %% LibBlockSFunctionFileExists
 
%%Function{BlockFunctions}:LibSFunctionLevel
%%Abstract:
%%DeterminetheS-functionversionlevel{Level1,Level2,RTWLevel2}
%%
%function LibSFunctionLevel() void
  %if EXISTS("ParamSettings.RTWGenerated")
    %return "RTWLevel2"
  %elseif EXISTS("SFcnParamSettings")
    %% For backwards compatibility with R11
    %if EXISTS("SFcnParamSettings.RTWGenerated")
      %return "RTWLevel2"
    %endif
  %elseif ParamSettings.FunctionLevel == 1
    %return "Level1"
  %else
    %return "Level2"
  %endif
%endfunction %% LibSFunctionLevel
 
 
%%Function{BlockFunctions}:SLibSfcnHasBranchFcnCall
%%Abstract:
%%Thisfunctionreturnstrueifasfcnfcn-call
%%generatoremitsbranchedfcn-call.
%%
%function SLibSfcnHasBranchFcnCall(sfcnBlk)
  %if ISFIELD(sfcnBlk, "NumSFcnSysOutputCalls") ...
    && ISFIELD(sfcnBlk, "NumSFcnSysOutputCallDsts")
    %return (sfcnBlk.NumSFcnSysOutputCallDsts > sfcnBlk.NumSFcnSysOutputCalls)
  %endif
  %return TLC_FALSE
%endfunction
 
%endif %% _SFUNCTION_PRIVATE_API_