<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: S-functions, Bus Signals, and Missing Documentation</title>
	<link>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/</link>
	<description>This blog is about Simulink.</description>
	<pubDate>Sun, 22 Nov 2009 23:19:18 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>By: ksreddy</title>
		<link>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-819</link>
		<dc:creator>ksreddy</dc:creator>
		<pubDate>Tue, 04 Aug 2009 16:42:36 +0000</pubDate>
		<guid>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-819</guid>
		<description>Hi, I am new to MATLAB, As a part of my assignment work I have been asked to integrate a program of 2k lines with simulink.This program has been written in fortran.The code also consists of many functions,just one input and many output variables.
I dont know as to how to call the functions within an s-function. I want to stick to level 1 as that is a little beginners level and easy to understand.
But due to too many outputs I dont know how we can assign it in s-function.
But there is one main function, can that be called in s-function. and what do I assign x and u in level 1 s-function,as input is directly given in through an include file.
So please can you help me out., because I am getting a runtime error forrtl sever(29):file not found although there are no compilation errors.
Hoping for a favourable reply. 
thank you and regards,
ksreddy</description>
		<content:encoded><![CDATA[<p>Hi, I am new to MATLAB, As a part of my assignment work I have been asked to integrate a program of 2k lines with simulink.This program has been written in fortran.The code also consists of many functions,just one input and many output variables.<br />
I dont know as to how to call the functions within an s-function. I want to stick to level 1 as that is a little beginners level and easy to understand.<br />
But due to too many outputs I dont know how we can assign it in s-function.<br />
But there is one main function, can that be called in s-function. and what do I assign x and u in level 1 s-function,as input is directly given in through an include file.<br />
So please can you help me out., because I am getting a runtime error forrtl sever(29):file not found although there are no compilation errors.<br />
Hoping for a favourable reply.<br />
thank you and regards,<br />
ksreddy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wei</title>
		<link>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-799</link>
		<dc:creator>wei</dc:creator>
		<pubDate>Wed, 08 Jul 2009 02:19:40 +0000</pubDate>
		<guid>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-799</guid>
		<description>@Seth(#10), Virtual bus block is very useful for large model. If as object bus can only be non-virtual, then either object, block, or both need be extended to support virtual and non-virtual buses.</description>
		<content:encoded><![CDATA[<p>@Seth(#10), Virtual bus block is very useful for large model. If as object bus can only be non-virtual, then either object, block, or both need be extended to support virtual and non-virtual buses.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pat</title>
		<link>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-798</link>
		<dc:creator>Pat</dc:creator>
		<pubDate>Tue, 07 Jul 2009 08:23:53 +0000</pubDate>
		<guid>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-798</guid>
		<description>@Seth--nice post on Bus
I am having a problem with Bus and embedded Maltab, I need non virtual bus as I a defining interfaces. I have replicated the example of the online Documentation-&#62;Simulink-&#62;Using the embedded Matlab Function Blocks--&#62; Working with structures and Bus signals.

It just does not work and I am wondering what the problem might be, This is an excerpt of message I am getting from Matlab, 


Warning: 'testDescription/Bus Selector2' must be connected to a Bus Creator, Bus
Selector or a bus capable block.
 A possible cause of this error is the use of a bus-capable block (such as Merge or
 Unit Delay) that in this current situation is unable to propagate the bus
 downstream to the block reported in this error. Please see Simulink documentation
 for further information on composite (i.e. bus) signals and their proper usage. 
&#62; In busSelectorddg_cb at 37
  In busSelectorddg_cb at 111

"
As I cant attached my model file, please accept my apology for adding the content of my mdl file here.

/**************************************************/
Model {
  Name			  "testDescription"
  Version		  7.3
  MdlSubVersion		  0
  GraphicalInterface {
    NumRootInports	    0
    NumRootOutports	    0
    ParameterArgumentNames  ""
    ComputedModelVersion    "1.87"
    NumModelReferences	    0
    NumTestPointedSignals   0
  }
  SavedCharacterEncoding  "ibm-5348_P100-1997"
  SaveDefaultBlockParams  on
  ScopeRefreshTime	  0.035000
  OverrideScopeRefreshTime on
  DisableAllScopes	  off
  DataTypeOverride	  "UseLocalSettings"
  MinMaxOverflowLogging	  "UseLocalSettings"
  MinMaxOverflowArchiveMode "Overwrite"
  Created		  "Sat Jul 04 08:00:35 2009"
  Creator		  "Admin"
  UpdateHistory		  "UpdateHistoryNever"
  ModifiedByFormat	  "%"
  LastModifiedBy	  "Admin"
  ModifiedDateFormat	  "%"
  LastModifiedDate	  "Mon Jul 06 22:54:24 2009"
  RTWModifiedTimeStamp	  0
  ModelVersionFormat	  "1.%"
  ConfigurationManager	  "None"
  SampleTimeColors	  on
  SampleTimeAnnotations	  off
  LibraryLinkDisplay	  "none"
  WideLines		  on
  ShowLineDimensions	  on
  ShowPortDataTypes	  on
  ShowLoopsOnError	  on
  IgnoreBidirectionalLines off
  ShowStorageClass	  on
  ShowTestPointIcons	  on
  ShowSignalResolutionIcons on
  ShowViewerIcons	  on
  SortedOrder		  off
  ExecutionContextIcon	  off
  ShowLinearizationAnnotations on
  BlockNameDataTip	  off
  BlockParametersDataTip  off
  BlockDescriptionStringDataTip	off
  ToolBar		  on
  StatusBar		  on
  BrowserShowLibraryLinks off
  BrowserLookUnderMasks	  off
  SimulationMode	  "normal"
  LinearizationMsg	  "none"
  Profile		  off
  ParamWorkspaceSource	  "MATLABWorkspace"
  AccelSystemTargetFile	  "accel.tlc"
  AccelTemplateMakefile	  "accel_default_tmf"
  AccelMakeCommand	  "make_rtw"
  TryForcingSFcnDF	  off
  RecordCoverage	  off
  CovPath		  "/"
  CovSaveName		  "covdata"
  CovMetricSettings	  "dw"
  CovNameIncrementing	  off
  CovHtmlReporting	  on
  covSaveCumulativeToWorkspaceVar on
  CovSaveSingleToWorkspaceVar on
  CovCumulativeVarName	  "covCumulativeData"
  CovCumulativeReport	  off
  CovReportOnPause	  on
  CovModelRefEnable	  "Off"
  CovExternalEMLEnable	  off
  ExtModeBatchMode	  off
  ExtModeEnableFloating	  on
  ExtModeTrigType	  "manual"
  ExtModeTrigMode	  "normal"
  ExtModeTrigPort	  "1"
  ExtModeTrigElement	  "any"
  ExtModeTrigDuration	  1000
  ExtModeTrigDurationFloating "auto"
  ExtModeTrigHoldOff	  0
  ExtModeTrigDelay	  0
  ExtModeTrigDirection	  "rising"
  ExtModeTrigLevel	  0
  ExtModeArchiveMode	  "off"
  ExtModeAutoIncOneShot	  off
  ExtModeIncDirWhenArm	  off
  ExtModeAddSuffixToVar	  off
  ExtModeWriteAllDataToWs off
  ExtModeArmWhenConnect	  on
  ExtModeSkipDownloadWhenConnect off
  ExtModeLogAll		  on
  ExtModeAutoUpdateStatusClock on
  BufferReuse		  off
  ShowModelReferenceBlockVersion off
  ShowModelReferenceBlockIO off
  Array {
    Type		    "Handle"
    Dimension		    1
    Simulink.ConfigSet {
      $ObjectID		      1
      Version		      "1.6.0"
      Array {
	Type			"Handle"
	Dimension		8
	Simulink.SolverCC {
	  $ObjectID		  2
	  Version		  "1.6.0"
	  StartTime		  "0.0"
	  StopTime		  "10.0"
	  AbsTol		  "auto"
	  FixedStep		  "0.1"
	  InitialStep		  "auto"
	  MaxNumMinSteps	  "-1"
	  MaxOrder		  5
	  ZcThreshold		  "auto"
	  ConsecutiveZCsStepRelTol "10*128*eps"
	  MaxConsecutiveZCs	  "1000"
	  ExtrapolationOrder	  4
	  NumberNewtonIterations  1
	  MaxStep		  "auto"
	  MinStep		  "auto"
	  MaxConsecutiveMinStep	  "1"
	  RelTol		  "1e-3"
	  SolverMode		  "Auto"
	  Solver		  "FixedStepDiscrete"
	  SolverName		  "FixedStepDiscrete"
	  ShapePreserveControl	  "DisableAll"
	  ZeroCrossControl	  "UseLocalSettings"
	  ZeroCrossAlgorithm	  "Nonadaptive"
	  AlgebraicLoopSolver	  "TrustRegion"
	  SolverResetMethod	  "Fast"
	  PositivePriorityOrder	  off
	  AutoInsertRateTranBlk	  off
	  SampleTimeConstraint	  "Unconstrained"
	  InsertRTBMode		  "Whenever possible"
	  SignalSizeVariationType "Allow only fixed size"
	}
	Simulink.DataIOCC {
	  $ObjectID		  3
	  Version		  "1.6.0"
	  Decimation		  "1"
	  ExternalInput		  "[t, u]"
	  FinalStateName	  "xFinal"
	  InitialState		  "xInitial"
	  LimitDataPoints	  on
	  MaxDataPoints		  "1000"
	  LoadExternalInput	  off
	  LoadInitialState	  off
	  SaveFinalState	  off
	  SaveCompleteFinalSimState off
	  SaveFormat		  "Array"
	  SaveOutput		  on
	  SaveState		  off
	  SignalLogging		  on
	  InspectSignalLogs	  off
	  SaveTime		  on
	  StateSaveName		  "xout"
	  TimeSaveName		  "tout"
	  OutputSaveName	  "yout"
	  SignalLoggingName	  "logsout"
	  OutputOption		  "RefineOutputTimes"
	  OutputTimes		  "[]"
	  Refine		  "1"
	}
	Simulink.OptimizationCC {
	  $ObjectID		  4
	  Version		  "1.6.0"
	  Array {
	    Type		    "Cell"
	    Dimension		    4
	    Cell		    "ZeroExternalMemoryAtStartup"
	    Cell		    "ZeroInternalMemoryAtStartup"
	    Cell		    "NoFixptDivByZeroProtection"
	    Cell		    "OptimizeModelRefInitCode"
	    PropName		    "DisabledProps"
	  }
	  BlockReduction	  off
	  BooleanDataType	  on
	  ConditionallyExecuteInputs on
	  InlineParams		  off
	  InlineInvariantSignals  on
	  OptimizeBlockIOStorage  off
	  BufferReuse		  off
	  EnhancedBackFolding	  off
	  StrengthReduction	  off
	  EnforceIntegerDowncast  on
	  ExpressionFolding	  off
	  EnableMemcpy		  on
	  MemcpyThreshold	  64
	  PassReuseOutputArgsAs	  "Structure reference"
	  ExpressionDepthLimit	  2147483647
	  FoldNonRolledExpr	  on
	  LocalBlockOutputs	  off
	  RollThreshold		  5
	  SystemCodeInlineAuto	  off
	  StateBitsets		  off
	  DataBitsets		  off
	  UseTempVars		  off
	  ZeroExternalMemoryAtStartup on
	  ZeroInternalMemoryAtStartup on
	  InitFltsAndDblsToZero	  on
	  NoFixptDivByZeroProtection off
	  EfficientFloat2IntCast  off
	  EfficientMapNaN2IntZero on
	  OptimizeModelRefInitCode off
	  LifeSpan		  "inf"
	  BufferReusableBoundary  on
	  SimCompilerOptimization "Off"
	  AccelVerboseBuild	  off
	}
	Simulink.DebuggingCC {
	  $ObjectID		  5
	  Version		  "1.6.0"
	  RTPrefix		  "error"
	  ConsistencyChecking	  "none"
	  ArrayBoundsChecking	  "none"
	  SignalInfNanChecking	  "none"
	  SignalRangeChecking	  "none"
	  ReadBeforeWriteMsg	  "UseLocalSettings"
	  WriteAfterWriteMsg	  "UseLocalSettings"
	  WriteAfterReadMsg	  "UseLocalSettings"
	  AlgebraicLoopMsg	  "warning"
	  ArtificialAlgebraicLoopMsg "warning"
	  SaveWithDisabledLinksMsg "warning"
	  SaveWithParameterizedLinksMsg	"none"
	  CheckSSInitialOutputMsg on
	  UnderspecifiedInitializationDetection	"Classic"
	  MergeDetectMultiDrivingBlocksExec "none"
	  CheckExecutionContextPreStartOutputMsg off
	  CheckExecutionContextRuntimeOutputMsg	off
	  SignalResolutionControl "TryResolveAllWithWarning"
	  BlockPriorityViolationMsg "warning"
	  MinStepSizeMsg	  "warning"
	  TimeAdjustmentMsg	  "none"
	  MaxConsecutiveZCsMsg	  "error"
	  SolverPrmCheckMsg	  "warning"
	  InheritedTsInSrcMsg	  "warning"
	  DiscreteInheritContinuousMsg "warning"
	  MultiTaskDSMMsg	  "warning"
	  MultiTaskCondExecSysMsg "none"
	  MultiTaskRateTransMsg	  "error"
	  SingleTaskRateTransMsg  "none"
	  TasksWithSamePriorityMsg "warning"
	  SigSpecEnsureSampleTimeMsg "warning"
	  CheckMatrixSingularityMsg "none"
	  IntegerOverflowMsg	  "warning"
	  Int32ToFloatConvMsg	  "warning"
	  ParameterDowncastMsg	  "error"
	  ParameterOverflowMsg	  "error"
	  ParameterUnderflowMsg	  "none"
	  ParameterPrecisionLossMsg "warning"
	  ParameterTunabilityLossMsg "warning"
	  UnderSpecifiedDataTypeMsg "none"
	  UnnecessaryDatatypeConvMsg "none"
	  VectorMatrixConversionMsg "none"
	  InvalidFcnCallConnMsg	  "error"
	  FcnCallInpInsideContextMsg "Use local settings"
	  SignalLabelMismatchMsg  "none"
	  UnconnectedInputMsg	  "warning"
	  UnconnectedOutputMsg	  "warning"
	  UnconnectedLineMsg	  "warning"
	  SFcnCompatibilityMsg	  "none"
	  UniqueDataStoreMsg	  "none"
	  BusObjectLabelMismatch  "warning"
	  RootOutportRequireBusObject "warning"
	  AssertControl		  "UseLocalSettings"
	  EnableOverflowDetection off
	  ModelReferenceIOMsg	  "none"
	  ModelReferenceVersionMismatchMessage "none"
	  ModelReferenceIOMismatchMessage "none"
	  ModelReferenceCSMismatchMessage "none"
	  UnknownTsInhSupMsg	  "warning"
	  ModelReferenceDataLoggingMessage "warning"
	  ModelReferenceSymbolNameMessage "warning"
	  ModelReferenceExtraNoncontSigs "error"
	  StateNameClashWarn	  "warning"
	  StrictBusMsg		  "ErrorOnBusTreatedAsVector"
	  LoggingUnavailableSignals "error"
	  BlockIODiagnostic	  "none"
	}
	Simulink.HardwareCC {
	  $ObjectID		  6
	  Version		  "1.6.0"
	  ProdBitPerChar	  8
	  ProdBitPerShort	  16
	  ProdBitPerInt		  32
	  ProdBitPerLong	  32
	  ProdIntDivRoundTo	  "Undefined"
	  ProdEndianess		  "Unspecified"
	  ProdWordSize		  32
	  ProdShiftRightIntArith  on
	  ProdHWDeviceType	  "32-bit Generic"
	  TargetBitPerChar	  8
	  TargetBitPerShort	  16
	  TargetBitPerInt	  32
	  TargetBitPerLong	  32
	  TargetShiftRightIntArith on
	  TargetIntDivRoundTo	  "Undefined"
	  TargetEndianess	  "Unspecified"
	  TargetWordSize	  32
	  TargetTypeEmulationWarnSuppressLevel 0
	  TargetPreprocMaxBitsSint 32
	  TargetPreprocMaxBitsUint 32
	  TargetHWDeviceType	  "Specified"
	  TargetUnknown		  off
	  ProdEqTarget		  on
	}
	Simulink.ModelReferenceCC {
	  $ObjectID		  7
	  Version		  "1.6.0"
	  UpdateModelReferenceTargets "IfOutOfDateOrStructuralChange"
	  CheckModelReferenceTargetMessage "error"
	  ModelReferenceNumInstancesAllowed "Multi"
	  ModelReferencePassRootInputsByReference on
	  ModelReferenceMinAlgLoopOccurrences off
	}
	Simulink.SFSimCC {
	  $ObjectID		  8
	  Version		  "1.6.0"
	  SFSimEnableDebug	  on
	  SFSimOverflowDetection  on
	  SFSimEcho		  on
	  SimBlas		  on
	  SimUseLocalCustomCode	  off
	  SimBuildMode		  "sf_incremental_build"
	}
	Simulink.RTWCC {
	  $BackupClass		  "Simulink.RTWCC"
	  $ObjectID		  9
	  Version		  "1.6.0"
	  Array {
	    Type		    "Cell"
	    Dimension		    1
	    Cell		    "IncludeHyperlinkInReport"
	    PropName		    "DisabledProps"
	  }
	  SystemTargetFile	  "grt.tlc"
	  GenCodeOnly		  off
	  MakeCommand		  "make_rtw"
	  GenerateMakefile	  on
	  TemplateMakefile	  "grt_default_tmf"
	  GenerateReport	  off
	  SaveLog		  off
	  RTWVerbose		  on
	  RetainRTWFile		  off
	  ProfileTLC		  off
	  TLCDebug		  off
	  TLCCoverage		  off
	  TLCAssert		  off
	  ProcessScriptMode	  "Default"
	  ConfigurationMode	  "Optimized"
	  ConfigAtBuild		  off
	  RTWUseLocalCustomCode	  off
	  RTWUseSimCustomCode	  off
	  IncludeHyperlinkInReport off
	  LaunchReport		  off
	  TargetLang		  "C"
	  IncludeBusHierarchyInRTWFileBlockHierarchyMap	off
	  IncludeERTFirstTime	  on
	  GenerateTraceInfo	  off
	  GenerateTraceReport	  off
	  GenerateTraceReportSl	  off
	  GenerateTraceReportSf	  off
	  GenerateTraceReportEml  off
	  GenerateCodeInfo	  off
	  RTWCompilerOptimization "Off"
	  CheckMdlBeforeBuild	  "Off"
	  Array {
	    Type		    "Handle"
	    Dimension		    2
	    Simulink.CodeAppCC {
	      $ObjectID		      10
	      Version		      "1.6.0"
	      Array {
		Type			"Cell"
		Dimension		9
		Cell			"IgnoreCustomStorageClasses"
		Cell			"InsertBlockDesc"
		Cell			"SFDataObjDesc"
		Cell			"SimulinkDataObjDesc"
		Cell			"DefineNamingRule"
		Cell			"SignalNamingRule"
		Cell			"ParamNamingRule"
		Cell			"InlinedPrmAccess"
		Cell			"CustomSymbolStr"
		PropName		"DisabledProps"
	      }
	      ForceParamTrailComments off
	      GenerateComments	      on
	      IgnoreCustomStorageClasses on
	      IgnoreTestpoints	      off
	      IncHierarchyInIds	      off
	      MaxIdLength	      31
	      PreserveName	      off
	      PreserveNameWithParent  off
	      ShowEliminatedStatement off
	      IncAutoGenComments      off
	      SimulinkDataObjDesc     off
	      SFDataObjDesc	      off
	      IncDataTypeInIds	      off
	      MangleLength	      1
	      CustomSymbolStrGlobalVar "$R$N$M"
	      CustomSymbolStrType     "$N$R$M"
	      CustomSymbolStrField    "$N$M"
	      CustomSymbolStrFcn      "$R$N$M$F"
	      CustomSymbolStrBlkIO    "rtb_$N$M"
	      CustomSymbolStrTmpVar   "$N$M"
	      CustomSymbolStrMacro    "$R$N$M"
	      DefineNamingRule	      "None"
	      ParamNamingRule	      "None"
	      SignalNamingRule	      "None"
	      InsertBlockDesc	      off
	      SimulinkBlockComments   on
	      EnableCustomComments    off
	      InlinedPrmAccess	      "Literals"
	      ReqsInCode	      off
	      UseSimReservedNames     off
	    }
	    Simulink.GRTTargetCC {
	      $BackupClass	      "Simulink.TargetCC"
	      $ObjectID		      11
	      Version		      "1.6.0"
	      Array {
		Type			"Cell"
		Dimension		12
		Cell			"IncludeMdlTerminateFcn"
		Cell			"CombineOutputUpdateFcns"
		Cell			"SuppressErrorStatus"
		Cell			"ERTCustomFileBanners"
		Cell			"GenerateSampleERTMain"
		Cell			"MultiInstanceERTCode"
		Cell			"PurelyIntegerCode"
		Cell			"SupportNonFinite"
		Cell			"SupportComplex"
		Cell			"SupportAbsoluteTime"
		Cell			"SupportContinuousTime"
		Cell			"SupportNonInlinedSFcns"
		PropName		"DisabledProps"
	      }
	      TargetFcnLib	      "ansi_tfl_tmw.mat"
	      TargetLibSuffix	      ""
	      TargetPreCompLibLocation ""
	      TargetFunctionLibrary   "ANSI_C"
	      UtilityFuncGeneration   "Auto"
	      ERTMultiwordTypeDef     "System defined"
	      ERTMultiwordLength      256
	      MultiwordLength	      2048
	      GenerateFullHeader      on
	      GenerateSampleERTMain   off
	      GenerateTestInterfaces  off
	      IsPILTarget	      off
	      ModelReferenceCompliant on
	      ParMdlRefBuildCompliant on
	      CompOptLevelCompliant   on
	      IncludeMdlTerminateFcn  on
	      CombineOutputUpdateFcns off
	      SuppressErrorStatus     off
	      ERTFirstTimeCompliant   off
	      IncludeFileDelimiter    "Auto"
	      ERTCustomFileBanners    off
	      SupportAbsoluteTime     on
	      LogVarNameModifier      "rt_"
	      MatFileLogging	      on
	      MultiInstanceERTCode    off
	      SupportNonFinite	      on
	      SupportComplex	      on
	      PurelyIntegerCode	      off
	      SupportContinuousTime   on
	      SupportNonInlinedSFcns  on
	      EnableShiftOperators    on
	      ParenthesesLevel	      "Nominal"
	      PortableWordSizes	      off
	      ModelStepFunctionPrototypeControlCompliant off
	      CPPClassGenCompliant    off
	      AutosarCompliant	      off
	      UseMalloc		      off
	      ExtMode		      off
	      ExtModeStaticAlloc      off
	      ExtModeTesting	      off
	      ExtModeStaticAllocSize  1000000
	      ExtModeTransport	      0
	      ExtModeMexFile	      "ext_comm"
	      ExtModeIntrfLevel	      "Level1"
	      RTWCAPISignals	      off
	      RTWCAPIParams	      off
	      RTWCAPIStates	      off
	      GenerateASAP2	      off
	    }
	    PropName		    "Components"
	  }
	}
	PropName		"Components"
      }
      Name		      "Configuration"
      CurrentDlgPage	      "Optimization"
      ConfigPrmDlgPosition    " [ 200, 85, 1080, 715 ] "
    }
    PropName		    "ConfigurationSets"
  }
  Simulink.ConfigSet {
    $PropName		    "ActiveConfigurationSet"
    $ObjectID		    1
  }
  BlockDefaults {
    ForegroundColor	    "black"
    BackgroundColor	    "white"
    DropShadow		    off
    NamePlacement	    "normal"
    FontName		    "Helvetica"
    FontSize		    10
    FontWeight		    "normal"
    FontAngle		    "normal"
    ShowName		    on
    BlockRotation	    0
    BlockMirror		    off
  }
  AnnotationDefaults {
    HorizontalAlignment	    "center"
    VerticalAlignment	    "middle"
    ForegroundColor	    "black"
    BackgroundColor	    "white"
    DropShadow		    off
    FontName		    "Helvetica"
    FontSize		    10
    FontWeight		    "normal"
    FontAngle		    "normal"
    UseDisplayTextAsClickCallback off
  }
  LineDefaults {
    FontName		    "Helvetica"
    FontSize		    9
    FontWeight		    "normal"
    FontAngle		    "normal"
  }
  BlockParameterDefaults {
    Block {
      BlockType		      BusCreator
      Inputs		      "4"
      DisplayOption	      "none"
      UseBusObject	      off
      BusObject		      "BusObject"
      NonVirtualBus	      off
    }
    Block {
      BlockType		      BusSelector
      OutputAsBus	      off
    }
    Block {
      BlockType		      Constant
      Value		      "1"
      VectorParams1D	      on
      SamplingMode	      "Sample based"
      OutMin		      "[]"
      OutMax		      "[]"
      OutDataTypeMode	      "Inherit from 'Constant value'"
      OutDataType	      "fixdt(1,16,0)"
      ConRadixGroup	      "Use specified scaling"
      OutScaling	      "[]"
      OutDataTypeStr	      "Inherit: Inherit from 'Constant value'"
      LockScale		      off
      SampleTime	      "inf"
      FramePeriod	      "inf"
    }
    Block {
      BlockType		      Demux
      Outputs		      "4"
      DisplayOption	      "none"
      BusSelectionMode	      off
    }
    Block {
      BlockType		      Display
      Format		      "short"
      Decimation	      "10"
      Floating		      off
      SampleTime	      "-1"
    }
    Block {
      BlockType		      Inport
      Port		      "1"
      UseBusObject	      off
      BusObject		      "BusObject"
      BusOutputAsStruct	      off
      PortDimensions	      "-1"
      SampleTime	      "-1"
      OutMin		      "[]"
      OutMax		      "[]"
      DataType		      "auto"
      OutDataType	      "fixdt(1,16,0)"
      OutScaling	      "[]"
      OutDataTypeStr	      "Inherit: auto"
      LockScale		      off
      SignalType	      "auto"
      SamplingMode	      "auto"
      LatchByDelayingOutsideSignal off
      LatchByCopyingInsideSignal off
      Interpolate	      on
      DimensionsMode	      "auto"
    }
    Block {
      BlockType		      Outport
      Port		      "1"
      UseBusObject	      off
      BusObject		      "BusObject"
      BusOutputAsStruct	      off
      PortDimensions	      "-1"
      SampleTime	      "-1"
      OutMin		      "[]"
      OutMax		      "[]"
      DataType		      "auto"
      OutDataType	      "fixdt(1,16,0)"
      OutScaling	      "[]"
      OutDataTypeStr	      "Inherit: auto"
      LockScale		      off
      SignalType	      "auto"
      SamplingMode	      "auto"
      SourceOfInitialOutputValue "Dialog"
      OutputWhenDisabled      "held"
      InitialOutput	      "[]"
      DimensionsMode	      "auto"
    }
    Block {
      BlockType		      "S-Function"
      FunctionName	      "system"
      SFunctionModules	      "''"
      PortCounts	      "[]"
      SFunctionDeploymentMode off
    }
    Block {
      BlockType		      SubSystem
      ShowPortLabels	      "FromPortIcon"
      Permissions	      "ReadWrite"
      PermitHierarchicalResolution "All"
      TreatAsAtomicUnit	      off
      CheckFcnCallInpInsideContextMsg off
      SystemSampleTime	      "-1"
      RTWFcnNameOpts	      "Auto"
      RTWFileNameOpts	      "Auto"
      RTWMemSecFuncInitTerm   "Inherit from model"
      RTWMemSecFuncExecute    "Inherit from model"
      RTWMemSecDataConstants  "Inherit from model"
      RTWMemSecDataInternal   "Inherit from model"
      RTWMemSecDataParameters "Inherit from model"
      SimViewingDevice	      off
      DataTypeOverride	      "UseLocalSettings"
      MinMaxOverflowLogging   "UseLocalSettings"
    }
    Block {
      BlockType		      Terminator
    }
  }
  System {
    Name		    "testDescription"
    Location		    [317, 358, 1148, 746]
    Open		    on
    ModelBrowserVisibility  off
    ModelBrowserWidth	    200
    ScreenColor		    "white"
    PaperOrientation	    "landscape"
    PaperPositionMode	    "auto"
    PaperType		    "A4"
    PaperUnits		    "centimeters"
    TiledPaperMargins	    [1.270000, 1.270000, 1.270000, 1.270000]
    TiledPageScale	    1
    ShowPageBoundaries	    off
    ZoomFactor		    "100"
    ReportName		    "simulink-default.rpt"
    Block {
      BlockType		      BusCreator
      Name		      "Bus\nCreator"
      Ports		      [3, 1]
      Position		      [220, 55, 225, 135]
      ShowName		      off
      Inputs		      "3"
      DisplayOption	      "bar"
      UseBusObject	      on
      BusObject		      "MainBus"
      NonVirtualBus	      on
      Port {
	PortNumber		1
	PropagatedSignals	"ele1, ele2, a1, a2"
	ShowPropagatedSignals	"all"
	RTWStorageClass		"Auto"
	DataLoggingNameMode	"SignalName"
      }
    }
    Block {
      BlockType		      BusCreator
      Name		      "Bus\nCreator1"
      Ports		      [2, 1]
      Position		      [175, 186, 180, 224]
      ShowName		      off
      Inputs		      "2"
      DisplayOption	      "bar"
      UseBusObject	      on
      BusObject		      "SubBus"
      NonVirtualBus	      on
      Port {
	PortNumber		1
	Name			"ele3"
	PropagatedSignals	"a1, a2"
	ShowPropagatedSignals	"on"
	RTWStorageClass		"Auto"
	DataLoggingNameMode	"SignalName"
      }
    }
    Block {
      BlockType		      BusSelector
      Name		      "Bus\nSelector1"
      Ports		      [1, 2]
      Position		      [620, 56, 625, 94]
      ShowName		      off
      OutputSignals	      "signal1,signal2"
      Port {
	PortNumber		1
	Name			""
	RTWStorageClass		"Auto"
	DataLoggingNameMode	"SignalName"
      }
      Port {
	PortNumber		2
	Name			""
	RTWStorageClass		"Auto"
	DataLoggingNameMode	"SignalName"
      }
    }
    Block {
      BlockType		      BusSelector
      Name		      "Bus\nSelector2"
      Ports		      [1, 2]
      Position		      [590, 221, 595, 259]
      ShowName		      off
      OutputSignals	      "signal1,signal2"
      Port {
	PortNumber		1
	Name			""
	RTWStorageClass		"Auto"
	DataLoggingNameMode	"SignalName"
      }
      Port {
	PortNumber		2
	Name			""
	RTWStorageClass		"Auto"
	DataLoggingNameMode	"SignalName"
      }
    }
    Block {
      BlockType		      Constant
      Name		      "Constant"
      Position		      [95, 25, 125, 55]
      Value		      "100"
      OutDataTypeMode	      "double"
      OutDataType	      "sfix(16)"
      OutScaling	      "2^0"
      OutDataTypeStr	      "double"
      Port {
	PortNumber		1
	Name			"ele1"
	RTWStorageClass		"Auto"
	DataLoggingNameMode	"SignalName"
      }
    }
    Block {
      BlockType		      Constant
      Name		      "Constant1"
      Position		      [95, 85, 125, 115]
      Value		      "21"
      OutDataTypeMode	      "single"
      OutDataType	      "sfix(16)"
      OutScaling	      "2^0"
      OutDataTypeStr	      "single"
      Port {
	PortNumber		1
	Name			"ele2"
	RTWStorageClass		"Auto"
	DataLoggingNameMode	"SignalName"
      }
    }
    Block {
      BlockType		      Constant
      Name		      "Constant2"
      Position		      [90, 165, 120, 195]
      Value		      "12"
      OutDataTypeMode	      "double"
      OutDataType	      "sfix(16)"
      OutScaling	      "2^0"
      OutDataTypeStr	      "double"
      Port {
	PortNumber		1
	Name			"a1"
	RTWStorageClass		"Auto"
	DataLoggingNameMode	"SignalName"
      }
    }
    Block {
      BlockType		      Constant
      Name		      "Constant3"
      Position		      [95, 240, 125, 270]
      Value		      "13"
      OutDataTypeMode	      "double"
      OutDataType	      "sfix(16)"
      OutScaling	      "2^0"
      OutDataTypeStr	      "double"
      Port {
	PortNumber		1
	Name			"a2"
	RTWStorageClass		"Auto"
	DataLoggingNameMode	"SignalName"
      }
    }
    Block {
      BlockType		      Display
      Name		      "Display"
      Ports		      [1]
      Position		      [715, 30, 805, 60]
      Decimation	      "1"
      Lockdown		      off
    }
    Block {
      BlockType		      Display
      Name		      "Display1"
      Ports		      [1]
      Position		      [715, 75, 805, 105]
      Decimation	      "1"
      Lockdown		      off
    }
    Block {
      BlockType		      Display
      Name		      "Display2"
      Ports		      [1]
      Position		      [715, 125, 805, 155]
      Decimation	      "1"
      Lockdown		      off
    }
    Block {
      BlockType		      Display
      Name		      "Display3"
      Ports		      [1]
      Position		      [715, 170, 805, 200]
      Decimation	      "1"
      Lockdown		      off
    }
    Block {
      BlockType		      Display
      Name		      "Display4"
      Ports		      [1]
      Position		      [720, 225, 810, 255]
      Decimation	      "1"
      Lockdown		      off
    }
    Block {
      BlockType		      Display
      Name		      "Display5"
      Ports		      [1]
      Position		      [720, 270, 810, 300]
      Decimation	      "1"
      Lockdown		      off
    }
    Block {
      BlockType		      SubSystem
      Name		      "Embedded\nMATLAB Function\n--COMPUTATION UNIT--"
      Ports		      [1, 2]
      Position		      [365, 90, 520, 190]
      PermitHierarchicalResolution "ExplicitOnly"
      MinAlgLoopOccurrences   off
      PropExecContextOutsideSubsystem off
      RTWSystemCode	      "Auto"
      FunctionWithSeparateData off
      Opaque		      off
      RequestExecContextInheritance off
      MaskHideContents	      off
      MaskType		      "Stateflow"
      MaskDescription	      "Embedded MATLAB block"
      MaskDisplay	      "disp('cityBankBranch');"
      MaskSelfModifiable      on
      MaskIconFrame	      on
      MaskIconOpaque	      off
      MaskIconRotate	      "none"
      MaskPortRotate	      "default"
      MaskIconUnits	      "autoscale"
      Port {
	PortNumber		1
	ShowPropagatedSignals	"on"
	RTWStorageClass		"Auto"
	DataLoggingNameMode	"SignalName"
      }
      Port {
	PortNumber		2
	ShowPropagatedSignals	"on"
	RTWStorageClass		"Auto"
	DataLoggingNameMode	"SignalName"
      }
      System {
	Name			"Embedded\nMATLAB Function\n--COMPUTATION UNIT--"
	Location		[257, 457, 812, 717]
	Open			off
	ModelBrowserVisibility	off
	ModelBrowserWidth	200
	ScreenColor		"white"
	PaperOrientation	"landscape"
	PaperPositionMode	"auto"
	PaperType		"A4"
	PaperUnits		"centimeters"
	TiledPaperMargins	[1.270000, 1.270000, 1.270000, 1.270000]
	TiledPageScale		1
	ShowPageBoundaries	off
	ZoomFactor		"100"
	Block {
	  BlockType		  Inport
	  Name			  "inbus"
	  Position		  [20, 101, 40, 119]
	  IconDisplay		  "Port number"
	  OutDataType		  "sfix(16)"
	  OutScaling		  "2^0"
	}
	Block {
	  BlockType		  Demux
	  Name			  " Demux "
	  Ports			  [1, 1]
	  Position		  [270, 180, 320, 220]
	  Outputs		  "1"
	}
	Block {
	  BlockType		  "S-Function"
	  Name			  " SFunction "
	  Tag			  "Stateflow S-Function testDescription 1"
	  Ports			  [1, 3]
	  Position		  [180, 100, 230, 180]
	  FunctionName		  "sf_sfun"
	  PortCounts		  "[1 3]"
	  EnableBusSupport	  on
	  Port {
	    PortNumber		    2
	    Name		    "outbus"
	    RTWStorageClass	    "Auto"
	    DataLoggingNameMode	    "SignalName"
	  }
	  Port {
	    PortNumber		    3
	    Name		    "outbus1"
	    RTWStorageClass	    "Auto"
	    DataLoggingNameMode	    "SignalName"
	  }
	}
	Block {
	  BlockType		  Terminator
	  Name			  " Terminator "
	  Position		  [460, 191, 480, 209]
	}
	Block {
	  BlockType		  Outport
	  Name			  "outbus"
	  Position		  [460, 101, 480, 119]
	  IconDisplay		  "Port number"
	  OutDataType		  "sfix(16)"
	  OutScaling		  "2^0"
	}
	Block {
	  BlockType		  Outport
	  Name			  "outbus1"
	  Position		  [460, 136, 480, 154]
	  Port			  "2"
	  IconDisplay		  "Port number"
	  OutDataType		  "sfix(16)"
	  OutScaling		  "2^0"
	}
	Line {
	  SrcBlock		  " SFunction "
	  SrcPort		  1
	  DstBlock		  " Demux "
	  DstPort		  1
	}
	Line {
	  SrcBlock		  "inbus"
	  SrcPort		  1
	  DstBlock		  " SFunction "
	  DstPort		  1
	}
	Line {
	  Name			  "outbus"
	  Labels		  [0, 0]
	  SrcBlock		  " SFunction "
	  SrcPort		  2
	  DstBlock		  "outbus"
	  DstPort		  1
	}
	Line {
	  Name			  "outbus1"
	  Labels		  [0, 0]
	  SrcBlock		  " SFunction "
	  SrcPort		  3
	  DstBlock		  "outbus1"
	  DstPort		  1
	}
	Line {
	  SrcBlock		  " Demux "
	  SrcPort		  1
	  DstBlock		  " Terminator "
	  DstPort		  1
	}
      }
    }
    Line {
      Name		      "ele1"
      Labels		      [0, 0]
      SrcBlock		      "Constant"
      SrcPort		      1
      Points		      [35, 0; 0, 30]
      DstBlock		      "Bus\nCreator"
      DstPort		      1
    }
    Line {
      Name		      "ele2"
      Labels		      [0, 0]
      SrcBlock		      "Constant1"
      SrcPort		      1
      Points		      [75, 0]
      DstBlock		      "Bus\nCreator"
      DstPort		      2
    }
    Line {
      Name		      "a1"
      Labels		      [0, 0]
      SrcBlock		      "Constant2"
      SrcPort		      1
      Points		      [15, 0; 0, 15]
      DstBlock		      "Bus\nCreator1"
      DstPort		      1
    }
    Line {
      Name		      "a2"
      Labels		      [0, 0]
      SrcBlock		      "Constant3"
      SrcPort		      1
      Points		      [15, 0; 0, -40]
      DstBlock		      "Bus\nCreator1"
      DstPort		      2
    }
    Line {
      Name		      "ele3"
      Labels		      [0, 0]
      SrcBlock		      "Bus\nCreator1"
      SrcPort		      1
      Points		      [10, 0; 0, -85]
      DstBlock		      "Bus\nCreator"
      DstPort		      3
    }
    Line {
      Labels		      [2, 0]
      SrcBlock		      "Bus\nCreator"
      SrcPort		      1
      Points		      [45, 0; 0, 45]
      DstBlock		      "Embedded\nMATLAB Function\n--COMPUTATION UNIT--"
      DstPort		      1
    }
    Line {
      Name		      ""
      Labels		      [3, 0]
      SrcBlock		      "Bus\nSelector2"
      SrcPort		      1
      Points		      [50, 0; 0, 10]
      DstBlock		      "Display4"
      DstPort		      1
    }
    Line {
      Name		      ""
      Labels		      [0, 0]
      SrcBlock		      "Bus\nSelector2"
      SrcPort		      2
      Points		      [50, 0; 0, 35]
      DstBlock		      "Display5"
      DstPort		      1
    }
    Line {
      Labels		      [0, 0]
      SrcBlock		      "Embedded\nMATLAB Function\n--COMPUTATION UNIT--"
      SrcPort		      2
      Points		      [10, 0; 0, 75]
      DstBlock		      "Bus\nSelector2"
      DstPort		      1
    }
    Line {
      Labels		      [0, 0]
      SrcBlock		      "Embedded\nMATLAB Function\n--COMPUTATION UNIT--"
      SrcPort		      1
      Points		      [5, 0; 0, -40]
      DstBlock		      "Bus\nSelector1"
      DstPort		      1
    }
    Annotation {
      Name		      "MainBus"
      Position		      [229, 149]
    }
    Annotation {
      Name		      "SubBus"
      Position		      [181, 237]
    }
  }
}
# Finite State Machines
#
#    Stateflow Version 7.1 (R2009a) dated Jan 28 2009, 05:16:58
#
#


Stateflow {
  machine {
    id			    1
    name		    "testDescription"
    created		    "04-Jul-2009 08:00:42"
    isLibrary		    0
    firstTarget		    10
    sfVersion		    71014000.000008
  }
  chart {
    id			    2
    name		    "Embedded\nMATLAB Function\n--COMPUTATION UNIT--"
    windowPosition	    [311.813 325.875 200.25 189.75]
    viewLimits		    [0 156.75 0 153.75]
    screen		    [1 1 1280 800 1.333333333333333]
    treeNode		    [0 3 0 0]
    firstTransition	    5
    firstJunction	    4
    viewObj		    2
    machine		    1
    ssIdHighWaterMark	    6
    decomposition	    CLUSTER_CHART
    type		    EML_CHART
    firstData		    6
    chartFileNumber	    1
    disableImplicitCasting  1
    eml {
      name		      "cityBankBranch"
    }
  }
  state {
    id			    3
    labelString		    "eML_blk_kernel()"
    position		    [18 64.5 118 66]
    fontSize		    12
    chart		    2
    treeNode		    [2 0 0 0]
    superState		    SUBCHART
    subviewer		    2
    ssIdNumber		    1
    type		    FUNC_STATE
    decomposition	    CLUSTER_STATE
    eml {
      isEML		      1
      script		      "function [outbus, outbus1] = cityBankBranch(inbus)\n%substruct.a1 = inbus.ele3.a1;\n%substruct.a2"
      " = int8([1 2; 3 4]);\n%substruct.a2 = 4;\nsubstruct = struct('a1',inbus.ele3.a1,'a2',4);\nmystruct = struct('ele"
      "1',20.5,'ele2',single(100),'ele3',substruct);\n\noutbus = mystruct;\noutbus.ele3.a2 = 2*(substruct.a2);\n\noutbu"
      "s1 = inbus.ele3;\n\n\n% function s   = cityBankBranch(descriptionFlag)\n% \n%     s.nberOfMethod = 3;\n%     s.m"
      "ethod(1).name = 'deposit';\n%     s.method(2).name = 'withdraw';\n%     s.method(3).name = 'getBalance';\n% \n% "
      "    s.method(1).nberOfOutput = 2;\n%     s.method(1).output(1).name = 'double';\n%     s.method(1).output(2).nam"
      "e = 'int';\n%     s.method(1).nberOfInput = 1;\n%     s.method(1).input(1).name = 'double';\n% \n%     s.method("
      "2).nberOfOutput = 1;\n%     s.method(2).output(1).name = 'int';\n%     s.method(2).nberOfInput = 2;\n%     s.met"
      "hod(2).input(1).name = 'double';\n%     s.method(2).input(2).name = 'double';\n% \n%     s.method(3).nberOfOutpu"
      "t = 1;\n%     s.method(3).output(1).name = 'int';\n%     s.method(3).nberOfInput = 1;\n%     s.method(3).input(1"
      ").name = 'int';\n\n"
      editorLayout	      "100 M4x1[215 17 977 420]"
      fimathForFiConstructors FimathMatlabFactoryDefault
    }
  }
  junction {
    id			    4
    position		    [23.5747 49.5747 7]
    chart		    2
    linkNode		    [2 0 0]
    subviewer		    2
    ssIdNumber		    3
    type		    CONNECTIVE_JUNCTION
  }
  transition {
    id			    5
    labelString		    "{eML_blk_kernel();}"
    labelPosition	    [32.125 19.875 102.544 14.964]
    fontSize		    12
    src {
      intersection	      [0 0 1 0 23.5747 14.625 0 0]
    }
    dst {
      id		      4
      intersection	      [7 0 -1 -1 23.5747 42.5747 0 0]
    }
    midPoint		    [23.5747 24.9468]
    chart		    2
    linkNode		    [2 0 0]
    dataLimits		    [21.175 25.975 14.625 42.575]
    subviewer		    2
    drawStyle		    SMART
    executionOrder	    1
    ssIdNumber		    2
  }
  data {
    id			    6
    ssIdNumber		    4
    name		    "inbus"
    linkNode		    [2 0 7]
    scope		    INPUT_DATA
    machine		    1
    props {
      array {
	size			"-1"
      }
      type {
	method			SF_SIMULINK_OBJECT_TYPE
	busObject		""
	fixpt {
	  scalingMode		  SF_FIXPT_BINARY_POINT
	}
      }
    }
    dataType		    "Bus: "
  }
  data {
    id			    7
    ssIdNumber		    5
    name		    "outbus"
    linkNode		    [2 6 8]
    scope		    OUTPUT_DATA
    machine		    1
    props {
      array {
	size			"-1"
      }
      type {
	method			SF_SIMULINK_OBJECT_TYPE
	expression		"MainBus"
	busObject		""
	fixpt {
	  scalingMode		  SF_FIXPT_BINARY_POINT
	}
      }
      frame		      SF_FRAME_NO
    }
    dataType		    "Bus: "
  }
  data {
    id			    8
    ssIdNumber		    6
    name		    "outbus1"
    linkNode		    [2 7 0]
    scope		    OUTPUT_DATA
    machine		    1
    props {
      array {
	size			"-1"
      }
      type {
	method			SF_SIMULINK_OBJECT_TYPE
	expression		"SubBus"
	busObject		""
	fixpt {
	  scalingMode		  SF_FIXPT_BINARY_POINT
	}
      }
      frame		      SF_FRAME_NO
    }
    dataType		    "Bus: "
  }
  instance {
    id			    9
    name		    "Embedded\nMATLAB Function\n--COMPUTATION UNIT--"
    machine		    1
    chart		    2
  }
  target {
    id			    10
    name		    "sfun"
    codeFlags		    ""
    machine		    1
    linkNode		    [1 0 0]
  }
}

/**************************************************/</description>
		<content:encoded><![CDATA[]]></content:encoded>
	</item>
	<item>
		<title>By: isaiah</title>
		<link>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-796</link>
		<dc:creator>isaiah</dc:creator>
		<pubDate>Mon, 06 Jul 2009 08:05:06 +0000</pubDate>
		<guid>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-796</guid>
		<description>sorry about my previous posting. didnt wrap the code properly. here is the full code well wrapped
&lt;pre&gt;
function msfcn_varpulseizzy(block)
% Level-2 M-file S-function to implement a variable pulse width generator
%   Copyright 1990-2007 The MathWorks, Inc.

% This S-function takes a desired pulse width (in percentage
% of the period of a Pulse Generator block) and sets the PulseWidth
% property in a Pulse Generator block. The result is a variable-width
% pulse signal. The S-function assumes the model contains only one Pulse
% Generator block and modifies the PulseWidth of that block.

setup(block);

%endfunction


function setup(block)

% Register number of ports
 block.NumDialogPrms = 1;
block.NumInputPorts  = 1;
block.NumOutputPorts = 0;

% Setup port properties to be inherited or dynamic
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;

% Override input port properties
block.InputPort(1).DatatypeID  = 0;  % double
block.InputPort(1).Complexity  = 'Real';

% Register sample times
block.SampleTimes = [0 0];

% Register methods
block.RegBlockMethod('PostPropagationSetup', @DoPostPropSetup);
block.RegBlockMethod('InitializeConditions', @InitializeConditions);
block.RegBlockMethod('Start', @Start);
block.RegBlockMethod('Outputs', @Outputs);
block.RegBlockMethod('Update', @Update);
block.RegBlockMethod('Terminate', @Terminate);

%endfunction


function DoPostPropSetup(block)

% Initialize the Dwork vector
block.NumDworks = 2;

% Dwork(1) stores the value of the next pulse width
block.Dwork(1).Name            = 'x1';
block.Dwork(1).Dimensions      = 1;
block.Dwork(1).DatatypeID      = 0;      % double
block.Dwork(1).Complexity      = 'Real'; % real
block.Dwork(1).UsedAsDiscState = true;

% Dwork(2) stores the handle of the Pulse Geneator block
block.Dwork(2).Name            = 'BlockHandle';
block.Dwork(2).Dimensions      = 1;
block.Dwork(2).DatatypeID      = 0;      % double
block.Dwork(2).Complexity      = 'Real'; % real
block.Dwork(2).UsedAsDiscState = false;

%endfunction


function Start(block)

% Populate the Dwork vector
block.Dwork(1).Data = 0;

% Obtain the Pulse Generator block handle
pulseGen = find_system(gcs,'BlockType','DiscretePulseGenerator');
blockH = get_param(pulseGen{1},'Handle');
block.Dwork(2).Data = blockH;

%endfunction


function InitializeConditions(block)

% Set the initial pulse width value
d=50;
set_param(block.Dwork(2).Data, 'PulseWidth', num2str(d));

%endfunction


function Outputs(block)
% Update the pulse width value
if block.InputPort(1).Data&#62;50
    d=d-2;  %reduce dutycycle by 2
else
    d=d+2; %increment dutycycle by 2
end
set_param(block.Dwork(2).Data, 'PulseWidth', num2str(d));


%endfunction


function Update(block)
d=50;
% Store the input value in the Dwork(1)
block.Dwork(1).Data = d;

%endfunction


function Terminate(block)

%endfunction

&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>sorry about my previous posting. didnt wrap the code properly. here is the full code well wrapped</p>
<pre>
function msfcn_varpulseizzy(block)
% Level-2 M-file S-function to implement a variable pulse width generator
%   Copyright 1990-2007 The MathWorks, Inc.

% This S-function takes a desired pulse width (in percentage
% of the period of a Pulse Generator block) and sets the PulseWidth
% property in a Pulse Generator block. The result is a variable-width
% pulse signal. The S-function assumes the model contains only one Pulse
% Generator block and modifies the PulseWidth of that block.

setup(block);

%endfunction

function setup(block)

% Register number of ports
 block.NumDialogPrms = 1;
block.NumInputPorts  = 1;
block.NumOutputPorts = 0;

% Setup port properties to be inherited or dynamic
block.SetPreCompInpPortInfoToDynamic;
block.SetPreCompOutPortInfoToDynamic;

% Override input port properties
block.InputPort(1).DatatypeID  = 0;  % double
block.InputPort(1).Complexity  = 'Real';

% Register sample times
block.SampleTimes = [0 0];

% Register methods
block.RegBlockMethod('PostPropagationSetup', @DoPostPropSetup);
block.RegBlockMethod('InitializeConditions', @InitializeConditions);
block.RegBlockMethod('Start', @Start);
block.RegBlockMethod('Outputs', @Outputs);
block.RegBlockMethod('Update', @Update);
block.RegBlockMethod('Terminate', @Terminate);

%endfunction

function DoPostPropSetup(block)

% Initialize the Dwork vector
block.NumDworks = 2;

% Dwork(1) stores the value of the next pulse width
block.Dwork(1).Name            = 'x1';
block.Dwork(1).Dimensions      = 1;
block.Dwork(1).DatatypeID      = 0;      % double
block.Dwork(1).Complexity      = 'Real'; % real
block.Dwork(1).UsedAsDiscState = true;

% Dwork(2) stores the handle of the Pulse Geneator block
block.Dwork(2).Name            = 'BlockHandle';
block.Dwork(2).Dimensions      = 1;
block.Dwork(2).DatatypeID      = 0;      % double
block.Dwork(2).Complexity      = 'Real'; % real
block.Dwork(2).UsedAsDiscState = false;

%endfunction

function Start(block)

% Populate the Dwork vector
block.Dwork(1).Data = 0;

% Obtain the Pulse Generator block handle
pulseGen = find_system(gcs,'BlockType','DiscretePulseGenerator');
blockH = get_param(pulseGen{1},'Handle');
block.Dwork(2).Data = blockH;

%endfunction

function InitializeConditions(block)

% Set the initial pulse width value
d=50;
set_param(block.Dwork(2).Data, 'PulseWidth', num2str(d));

%endfunction

function Outputs(block)
% Update the pulse width value
if block.InputPort(1).Data&gt;50
    d=d-2;  %reduce dutycycle by 2
else
    d=d+2; %increment dutycycle by 2
end
set_param(block.Dwork(2).Data, 'PulseWidth', num2str(d));

%endfunction

function Update(block)
d=50;
% Store the input value in the Dwork(1)
block.Dwork(1).Data = d;

%endfunction

function Terminate(block)

%endfunction
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: isaiah</title>
		<link>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-795</link>
		<dc:creator>isaiah</dc:creator>
		<pubDate>Mon, 06 Jul 2009 07:53:08 +0000</pubDate>
		<guid>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-795</guid>
		<description>Hi, i tried modifying a level 2 s-funtion. however i keep getting an error.
please help. im new to simulink so i almost have no idea.
i am pasting the code here. please advise on what to...

50
    d=d-2;  %reduce dutycycle by 2
else
    d=d+2; %increment dutycycle by 2
end
set_param(block.Dwork(2).Data, 'PulseWidth', num2str(d));


%endfunction


function Update(block)
d=50;
% Store the input value in the Dwork(1)
block.Dwork(1).Data = d;

%endfunction


function Terminate(block)

%endfunction
&#62;</description>
		<content:encoded><![CDATA[<p>Hi, i tried modifying a level 2 s-funtion. however i keep getting an error.<br />
please help. im new to simulink so i almost have no idea.<br />
i am pasting the code here. please advise on what to&#8230;</p>
<p>50<br />
    d=d-2;  %reduce dutycycle by 2<br />
else<br />
    d=d+2; %increment dutycycle by 2<br />
end<br />
set_param(block.Dwork(2).Data, &#8216;PulseWidth&#8217;, num2str(d));</p>
<p>%endfunction</p>
<p>function Update(block)<br />
d=50;<br />
% Store the input value in the Dwork(1)<br />
block.Dwork(1).Data = d;</p>
<p>%endfunction</p>
<p>function Terminate(block)</p>
<p>%endfunction<br />
&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-791</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 30 Jun 2009 20:57:42 +0000</pubDate>
		<guid>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-791</guid>
		<description>Hi Seth,

Thanks for the feedback. I actually decided to go with the second option since it made more sense for me to have an initialization step and subsequent output steps.

Have you played around with the dynamic port dimensions in the latest prerelease (2009b)? I'm looking at having a bus with elements of varying dimensions, but I haven't found any documentation on the updates to the bus editor. I take it prereleases don't come with documentation?

P.S. Glad y'all spotted the bug!

Thanks,
Jeff</description>
		<content:encoded><![CDATA[<p>Hi Seth,</p>
<p>Thanks for the feedback. I actually decided to go with the second option since it made more sense for me to have an initialization step and subsequent output steps.</p>
<p>Have you played around with the dynamic port dimensions in the latest prerelease (2009b)? I&#8217;m looking at having a bus with elements of varying dimensions, but I haven&#8217;t found any documentation on the updates to the bus editor. I take it prereleases don&#8217;t come with documentation?</p>
<p>P.S. Glad y&#8217;all spotted the bug!</p>
<p>Thanks,<br />
Jeff</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Seth</title>
		<link>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-787</link>
		<dc:creator>Seth</dc:creator>
		<pubDate>Mon, 29 Jun 2009 16:14:45 +0000</pubDate>
		<guid>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-787</guid>
		<description>@Jeff - Regarding your first question about handling a bus with a Level 2 M-file S-function: you are correct, level 2 M-file S-functions do not support bus signals, but there are some other options.
&lt;ul&gt;
&lt;li&gt;Use Embedded MATLAB - As long as you have an structure of arrays (not an array of structures) you should be able to pass the bus out of an Embedded MATLAB block.&lt;/li&gt;
&lt;li&gt;Mask the level 2 M-file s-function in a subsystem with a bus creator at the output.  If there are 100 signals, you can pass them out separately and wire them into the bus.  If the bus is more complicated, you may need to cascade the bus creators.  This would have a high one time cost, but it will give you a nice interface to the system.&lt;/li&gt;
&lt;/ul&gt;

I think the Embedded MATLAB option may be best, though, the Embedded MATLAB language is a subset of what you can do in the M-file S-function.  Embedded MATLAB blocks don't have states the way S-functions do, so you may have to rething your code if you rely on them.

Regarding your second comment about the S-function builder bug, thanks for reporting it.  Technical Support is looking into this.</description>
		<content:encoded><![CDATA[<p>@Jeff - Regarding your first question about handling a bus with a Level 2 M-file S-function: you are correct, level 2 M-file S-functions do not support bus signals, but there are some other options.</p>
<ul>
<li>Use Embedded MATLAB - As long as you have an structure of arrays (not an array of structures) you should be able to pass the bus out of an Embedded MATLAB block.</li>
<li>Mask the level 2 M-file s-function in a subsystem with a bus creator at the output.  If there are 100 signals, you can pass them out separately and wire them into the bus.  If the bus is more complicated, you may need to cascade the bus creators.  This would have a high one time cost, but it will give you a nice interface to the system.</li>
</ul>
<p>I think the Embedded MATLAB option may be best, though, the Embedded MATLAB language is a subset of what you can do in the M-file S-function.  Embedded MATLAB blocks don&#8217;t have states the way S-functions do, so you may have to rething your code if you rely on them.</p>
<p>Regarding your second comment about the S-function builder bug, thanks for reporting it.  Technical Support is looking into this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-781</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 23 Jun 2009 13:41:21 +0000</pubDate>
		<guid>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-781</guid>
		<description>Seth,

Just FYI, I found a bug in the S-Function Builder. If you try to create an S-Function with a bus output and no inputs, the builder messes up while generating the code (inserts an extra comma where the input argument usually is) that causes build errors, rendering the builder GUI useless.

Thanks,
Jeff</description>
		<content:encoded><![CDATA[<p>Seth,</p>
<p>Just FYI, I found a bug in the S-Function Builder. If you try to create an S-Function with a bus output and no inputs, the builder messes up while generating the code (inserts an extra comma where the input argument usually is) that causes build errors, rendering the builder GUI useless.</p>
<p>Thanks,<br />
Jeff</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-778</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Thu, 18 Jun 2009 20:59:33 +0000</pubDate>
		<guid>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-778</guid>
		<description>Hey Seth,

I have a large struct that I need to pass through a simulink model (presumably by bus object). The struct is created in a Level 2 M-file S-Function. Unfortunately it doesn't look like Level 2 M-file S-Functions support bus ports, do you have any recommendations for making this work? The struct is way too complicated to multiplex into a single matrix.

Thanks!</description>
		<content:encoded><![CDATA[<p>Hey Seth,</p>
<p>I have a large struct that I need to pass through a simulink model (presumably by bus object). The struct is created in a Level 2 M-file S-Function. Unfortunately it doesn&#8217;t look like Level 2 M-file S-Functions support bus ports, do you have any recommendations for making this work? The struct is way too complicated to multiplex into a single matrix.</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Seth</title>
		<link>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-776</link>
		<dc:creator>Seth</dc:creator>
		<pubDate>Mon, 15 Jun 2009 20:45:07 +0000</pubDate>
		<guid>http://blogs.mathworks.com/seth/2009/04/17/s-functions-bus-signals-and-missing-documentation/#comment-776</guid>
		<description>@wei - You have asked a difficult question.  S-functions with simple signals (one type and one definition of size) can be dynamically sized, but that was part of the original design for blocks.  Bus signals came later, and the purpose of bus objects is to define an interface. Dimensions and data types are the required parts that define that interface.  At the boundary, the bus is non-virtual and must be fully defined.  I'm not sure I understand your last questions about defining "s-functions bus port by non bus object."  Please clarify if you want more information.

@Gaurav Thaiba - If you are simply looking for a block to output a pulse signal, there are some pulse generators in the Simulink Sources library.  You could also model a PWM signal using &lt;a href="http://www.mathworks.com/products/simelectronics/" rel="nofollow"&gt;SimElectronics&lt;/a&gt; or &lt;a href="http://www.mathworks.com/products/simpower/" rel="nofollow"&gt;SimPowerSystems&lt;/a&gt;.  Search the documentation for PWM.</description>
		<content:encoded><![CDATA[<p>@wei - You have asked a difficult question.  S-functions with simple signals (one type and one definition of size) can be dynamically sized, but that was part of the original design for blocks.  Bus signals came later, and the purpose of bus objects is to define an interface. Dimensions and data types are the required parts that define that interface.  At the boundary, the bus is non-virtual and must be fully defined.  I&#8217;m not sure I understand your last questions about defining &#8220;s-functions bus port by non bus object.&#8221;  Please clarify if you want more information.</p>
<p>@Gaurav Thaiba - If you are simply looking for a block to output a pulse signal, there are some pulse generators in the Simulink Sources library.  You could also model a PWM signal using <a href="http://www.mathworks.com/products/simelectronics/" rel="nofollow">SimElectronics</a> or <a href="http://www.mathworks.com/products/simpower/" rel="nofollow">SimPowerSystems</a>.  Search the documentation for PWM.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
