Overview
Comment:`mtt sys sfun zip` now produces an input block and an interface block for MTT models.
Models can be embedded within larger Simulink models by the 2 ports.
The user must edit 2 code blocks in <sys>_sfun_interface.c before compiling with mex.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 0ae1960649dadca384b98147a5c5625d36ee402270f0ed27e0c8d01a4e54ce2d
User & Date: geraint@users.sourceforge.net on 2002-05-23 17:08:21
Other Links: branch diff | manifest | tags
Context
2002-05-23
17:26:07
Cosmetic tweaks to graphs check-in: 4d5e314d90 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
17:08:21
`mtt sys sfun zip` now produces an input block and an interface block for MTT models.
Models can be embedded within larger Simulink models by the 2 ports.
The user must edit 2 code blocks in <sys>_sfun_interface.c before compiling with mex.
check-in: 0ae1960649 user: geraint@users.sourceforge.net tags: origin/master, trunk
2002-05-22
16:59:59
Multiple ps files generated - view shows all check-in: 8d0ad4c90b user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/mtt from [f52b61c98a] to [559d19bde1].

13
14
15
16
17
18
19




20
21
22
23
24
25
26
# Copyright (C) 2001 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Header$
## $Log$




## Revision 1.349  2002/05/20 10:29:59  gawthrop
## -oct now forces an m target language to be oct
## (if the rep is an the list: "ae input logic numpar simpar state")
##
## Revision 1.348  2002/05/20 08:50:12  geraint
## Cleans _sfun_ae.mexglx.
##







>
>
>
>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Copyright (C) 2001 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Header$
## $Log$
## Revision 1.350  2002/05/21 08:45:36  gawthrop
## DIY reps: no longer skips rep if file exists already.
## Avoids problems in rep.txt when options change
##
## Revision 1.349  2002/05/20 10:29:59  gawthrop
## -oct now forces an m target language to be oct
## (if the rep is an the list: "ae input logic numpar simpar state")
##
## Revision 1.348  2002/05/20 08:50:12  geraint
## Cleans _sfun_ae.mexglx.
##
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
  rm -f *_*_write.r *_simpar.m *_simpar.p
  rm -f *_cseo.oct *_input.oct *_simpar.oct *_smxax.oct
  rm -f *_csex.oct *_numpar.oct *_smxa.oct *_state.oct 
  rm -f *_ode.oct *_odeo.oct
  rm -f *_cseo.mexglx *_input.mexglx *_simpar.mexglx *_smxax.mexglx
  rm -f *_csex.mexglx *_numpar.mexglx *_smxa.mexglx *_state.mexglx 
  rm -f *_ode.mexglx *_odeo.mexglx
  rm -f *_sfun.mexglx *_sfun_ae.mexglx
  rm -f *_cseo.cc *_input.cc *_simpar.cc *_smxax.cc
  rm -f *_csex.cc *_numpar.cc *_smxa.cc *_state.cc 
  rm -f *_ode.cc *_odeo.cc
  rm -f *_logic.m *_logic.cc *_logic.oct
  rm -f *_state.m *_state.cc *_state.oct
  rm -f *_ode2odes.* *.dat2 MTT.core
  rm -f *_modpar.txt *_modpar.r







|







1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
  rm -f *_*_write.r *_simpar.m *_simpar.p
  rm -f *_cseo.oct *_input.oct *_simpar.oct *_smxax.oct
  rm -f *_csex.oct *_numpar.oct *_smxa.oct *_state.oct 
  rm -f *_ode.oct *_odeo.oct
  rm -f *_cseo.mexglx *_input.mexglx *_simpar.mexglx *_smxax.mexglx
  rm -f *_csex.mexglx *_numpar.mexglx *_smxa.mexglx *_state.mexglx 
  rm -f *_ode.mexglx *_odeo.mexglx
  rm -f *_sfun.mexglx *_sfun_*.mexglx
  rm -f *_cseo.cc *_input.cc *_simpar.cc *_smxax.cc
  rm -f *_csex.cc *_numpar.cc *_smxa.cc *_state.cc 
  rm -f *_ode.cc *_odeo.cc
  rm -f *_logic.m *_logic.cc *_logic.oct
  rm -f *_state.m *_state.cc *_state.oct
  rm -f *_ode2odes.* *.dat2 MTT.core
  rm -f *_modpar.txt *_modpar.r
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
  rm -f $1_*_write.r $1_simpar.m $1_simpar.p
  rm -f $1_cseo.oct $1_input.oct $1_simpar.oct $1_smxax.oct
  rm -f $1_csex.oct $1_numpar.oct $1_smxa.oct $1_state.oct 
  rm -f $1_ode.oct $1_odeo.oct
  rm -f $1_cseo.mexglx $1_input.mexglx $1_simpar.mexglx $1_smxax.mexglx
  rm -f $1_csex.mexglx $1_numpar.mexglx $1_smxa.mexglx $1_state.mexglx 
  rm -f $1_ode.mexglx $1_odeo.mexglx
  rm -f $1_sfun.mexglx $1_sfun_ae.mexglx
  rm -f $1_cseo.cc $1_input.cc $1_simpar.cc $1_smxax.cc
  rm -f $1_csex.cc $1_numpar.cc $1_smxa.cc $1_state.cc 
  rm -f $1_ode.cc $1_odeo.cc
  rm -f $1_logic.m $1_logic.cc $1_logic.oct 
  rm -f $1_state.m $1_state.cc $1_state.oct
  rm -f $1_ode2odes.* $1.dat2
  rm -f $1_modpar.txt $1_modpar.r







|







1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
  rm -f $1_*_write.r $1_simpar.m $1_simpar.p
  rm -f $1_cseo.oct $1_input.oct $1_simpar.oct $1_smxax.oct
  rm -f $1_csex.oct $1_numpar.oct $1_smxa.oct $1_state.oct 
  rm -f $1_ode.oct $1_odeo.oct
  rm -f $1_cseo.mexglx $1_input.mexglx $1_simpar.mexglx $1_smxax.mexglx
  rm -f $1_csex.mexglx $1_numpar.mexglx $1_smxa.mexglx $1_state.mexglx 
  rm -f $1_ode.mexglx $1_odeo.mexglx
  rm -f $1_sfun.mexglx $1_sfun_*.mexglx
  rm -f $1_cseo.cc $1_input.cc $1_simpar.cc $1_smxax.cc
  rm -f $1_csex.cc $1_numpar.cc $1_smxa.cc $1_state.cc 
  rm -f $1_ode.cc $1_odeo.cc
  rm -f $1_logic.m $1_logic.cc $1_logic.oct 
  rm -f $1_state.m $1_state.cc $1_state.oct
  rm -f $1_ode2odes.* $1.dat2
  rm -f $1_modpar.txt $1_modpar.r

Modified mttroot/mtt/lib/rep/sfun_rep/Makefile from [35509f7ef3] to [cc2f9e7025].

1
2
3
4
5
6
7
8
9
10
11
12
#! /usr/bin/make -f

all: $(SYS)_sfun.mexglx

$(SYS)_sfun.mexglx: $(SYS)_sfun.c sfun_debug.h $(SYS)_def.h $(SYS)_sympar.h $(SYS)_numpar.c $(SYS)_ode.c $(SYS)_odeo.c $(SYS)_state.c $(SYS)_sfun_ae.mexglx $(SYS)_sfun_input.mexglx
	echo Creating $@
	mex $(SYS)_sfun.c
	cp *_sfun*mexglx ..

$(SYS)_sfun.c:: ${MTT_REP}/sfun_rep/sfun.c.tmpl
	echo Creating $@
	cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@




|







1
2
3
4
5
6
7
8
9
10
11
12
#! /usr/bin/make -f

all: $(SYS)_sfun.mexglx

$(SYS)_sfun.mexglx: $(SYS)_sfun.c sfun_debug.h $(SYS)_def.h $(SYS)_sympar.h $(SYS)_numpar.c $(SYS)_ode.c $(SYS)_odeo.c $(SYS)_state.c $(SYS)_sfun_ae.mexglx $(SYS)_sfun_input.mexglx $(SYS)_sfun_interface.mexglx
	echo Creating $@
	mex $(SYS)_sfun.c
	cp *_sfun*mexglx ..

$(SYS)_sfun.c:: ${MTT_REP}/sfun_rep/sfun.c.tmpl
	echo Creating $@
	cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@
23
24
25
26
27
28
29










30



31
32
33
34
35
36
37
	echo Creating $@
	mex $(SYS)_sfun_input.c

$(SYS)_sfun_input.c:: ${MTT_REP}/sfun_rep/sfun_input.c.tmpl
	echo Creating $@
	cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@











$(SYS)_sfun.zip: $(SYS)_sfun.c sfun_debug.h $(SYS)_sfun_ae.c $(SYS)_sfun_input.c $(SYS)_def.h $(SYS)_sympar.h $(SYS)_ae.c $(SYS)_input.c $(SYS)_numpar.c $(SYS)_ode.c $(SYS)_odeo.c $(SYS)_state.c $(SYS).mdl README



	echo Creating $@
	zip $@ $^

$(SYS).mdl: ${MTT_REP}/sfun_rep/mdl.tmpl
	echo Creating $@
	cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@








>
>
>
>
>
>
>
>
>
>
|
>
>
>







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
	echo Creating $@
	mex $(SYS)_sfun_input.c

$(SYS)_sfun_input.c:: ${MTT_REP}/sfun_rep/sfun_input.c.tmpl
	echo Creating $@
	cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@

$(SYS)_sfun_interface.mexglx: $(SYS)_sfun_interface.c sfun_debug.h $(SYS)_def.h $(SYS)_sympar.h $(SYS)_numpar.c
	echo Creating $@
	mex $(SYS)_sfun_interface.c

$(SYS)_sfun_interface.c: ${MTT_REP}/sfun_rep/sfun_interface.c.tmpl $(SYS)_struc.c
	echo Creating $@
	cat ${MTT_REP}/sfun_rep/sfun_interface.c.tmpl	|\
	 sed 's/<mtt_model_name>/$(SYS)/g'		|\
	 ${MTT_REP}/sfun_rep/insert_file.sh > $@

$(SYS)_sfun.zip: $(SYS)_sfun.c sfun_debug.h $(SYS)_sfun_ae.c $(SYS)_sfun_input.c $(SYS)_sfun_interface.c \
	 $(SYS)_def.h $(SYS)_sympar.h \
	 $(SYS)_ae.c $(SYS)_input.c $(SYS)_numpar.c $(SYS)_ode.c $(SYS)_odeo.c $(SYS)_state.c \
	 $(SYS).mdl README
	echo Creating $@
	zip $@ $^

$(SYS).mdl: ${MTT_REP}/sfun_rep/mdl.tmpl
	echo Creating $@
	cat $^ | sed 's/<mtt_model_name>/$(SYS)/g' > $@

58
59
60
61
62
63
64









65
66
67
68
69
70
71
$(SYS)_odeo.c: $(SYS)_odeo.m
	echo Creating $@
	${MTT_CC}/mtt_m2cc.sh $(SYS) odeo c cat

$(SYS)_state.c: $(SYS)_state.m
	echo Creating $@
	${MTT_CC}/mtt_m2cc.sh $(SYS) state c cat










sfun_debug.h:: ${MTT_REP}/sfun_rep/sfun_debug.h
	echo Copying $@
	cp $^ $@

%::
	mtt -q $(OPTS) `echo $* | sed 's/\(.*\)_\(.*\)\.\(.*\)/\1 \2 \3/'`







>
>
>
>
>
>
>
>
>







71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
$(SYS)_odeo.c: $(SYS)_odeo.m
	echo Creating $@
	${MTT_CC}/mtt_m2cc.sh $(SYS) odeo c cat

$(SYS)_state.c: $(SYS)_state.m
	echo Creating $@
	${MTT_CC}/mtt_m2cc.sh $(SYS) state c cat

$(SYS)_struc.c: $(SYS)_struc.txt
	echo Creating $@
	gawk '\
($$1 == "input")  { printf "         double *%s\t= &(mttu[%d]);\t/* input and output */\n", $$4, $$2-1 }\
($$1 == "state")  { printf "   const double *%s\t= &(mttx[%d]);\t/* input */\n", $$4, $$2-1 }\
($$1 == "output") { printf "   const double *%s\t= &(mtty[%d]);\t/* input */\n", $$4, $$2-1 }\
($$1 != "input" && $$1 != "state" && $$1 != "output") { }\
	' $^ > $@

sfun_debug.h:: ${MTT_REP}/sfun_rep/sfun_debug.h
	echo Copying $@
	cp $^ $@

%::
	mtt -q $(OPTS) `echo $* | sed 's/\(.*\)_\(.*\)\.\(.*\)/\1 \2 \3/'`

Modified mttroot/mtt/lib/rep/sfun_rep/README.tmpl from [ae40a63903] to [4bfb771bf0].

1
2
3
4
5
6
7
8
9
10
11
12





To build a Simulink funtion of the <mtt_model_name> model without using MTT:

mex <mtt_model_name>_sfun.c

The input block can be created with:

mex <mtt_model_name>_sfun_input.c

If numerical solution of algebraic equations is also required:

mex <mtt_model_name>_sfun_ae.c
















>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

To build a Simulink funtion of the <mtt_model_name> model without using MTT:

mex <mtt_model_name>_sfun.c

The input block can be created with:

mex <mtt_model_name>_sfun_input.c

If numerical solution of algebraic equations is also required:

mex <mtt_model_name>_sfun_ae.c

The interface block can be created with

mex <mtt_model_name>_sfun_interface.c

Added mttroot/mtt/lib/rep/sfun_rep/insert_file.sh version [25cb36fec8].









>
>
>
>
1
2
3
4
#! /usr/bin/gawk -f
# script to replace the line: "/* insert filename */" with the contents of file "filename"
($1 != "/*" || $2 != "insert" || $4 != "*/") { print }
($1 == "/*" && $2 == "insert" && $4 == "*/") { cmd = "cat " $3 ; system(cmd) }

Modified mttroot/mtt/lib/rep/sfun_rep/mdl.tmpl from [a18037fb99] to [16ba1b6745].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Model {
  Name			  "generic"
  Version		  4.00
  SampleTimeColors	  off
  LibraryLinkDisplay	  "none"
  WideLines		  off
  ShowLineDimensions	  off
  ShowPortDataTypes	  off
  ShowStorageClass	  off
  ExecutionOrder	  off
  RecordCoverage	  off
  CovPath		  "/"
  CovSaveName		  "covdata"
  CovMetricSettings	  "dw"

|


|

|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
Model {
  Name			  "<mtt_model_name>"
  Version		  4.00
  SampleTimeColors	  off
  LibraryLinkDisplay	  "all"
  WideLines		  off
  ShowLineDimensions	  on
  ShowPortDataTypes	  off
  ShowStorageClass	  off
  ExecutionOrder	  off
  RecordCoverage	  off
  CovPath		  "/"
  CovSaveName		  "covdata"
  CovMetricSettings	  "dw"
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  BrowserLookUnderMasks	  off
  Created		  "Mon May 20 13:21:21 2002"
  Creator		  "geraint"
  UpdateHistory		  "UpdateHistoryNever"
  ModifiedByFormat	  "%<Auto>"
  LastModifiedBy	  "geraint"
  ModifiedDateFormat	  "%<Auto>"
  LastModifiedDate	  "Mon May 20 15:53:00 2002"
  ModelVersionFormat	  "1.%<AutoIncrement:4>"
  ConfigurationManager	  "None"
  SimParamPage		  "Solver"
  StartTime		  "0.0"
  StopTime		  "10.0"
  SolverMode		  "Auto"
  Solver		  "ode45"
  RelTol		  "1e-3"







|
|







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  BrowserLookUnderMasks	  off
  Created		  "Mon May 20 13:21:21 2002"
  Creator		  "geraint"
  UpdateHistory		  "UpdateHistoryNever"
  ModifiedByFormat	  "%<Auto>"
  LastModifiedBy	  "geraint"
  ModifiedDateFormat	  "%<Auto>"
  LastModifiedDate	  "Thu May 23 16:35:42 2002"
  ModelVersionFormat	  "1.%<AutoIncrement:13>"
  ConfigurationManager	  "None"
  SimParamPage		  "Solver"
  StartTime		  "0.0"
  StopTime		  "10.0"
  SolverMode		  "Auto"
  Solver		  "ode45"
  RelTol		  "1e-3"
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170










171
172
173

174
175

176
177
178
179
180
181

182
183





184
185
186
187
188
189
190
191
192
193
194
195
196
197

198
199





























200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233


234


235




236


237
238
239


240
241
242


243


244
245
246
247
248
249
250
251
252
253







254
255
256
257















258

259




260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
  LineDefaults {
    FontName		    "Helvetica"
    FontSize		    9
    FontWeight		    "normal"
    FontAngle		    "normal"
  }
  System {
    Name		    "generic"
    Location		    [40, 379, 681, 493]
    Open		    on
    ModelBrowserVisibility  off
    ModelBrowserWidth	    200
    ScreenColor		    "white"
    PaperOrientation	    "landscape"
    PaperPositionMode	    "auto"
    PaperType		    "usletter"
    PaperUnits		    "inches"
    ZoomFactor		    "100"
    ReportName		    "simulink-default.rpt"
    Block {
      BlockType		      "S-Function"










      Name		      "MTT Model Inputs"
      Ports		      [1, 1]
      Position		      [30, 39, 205, 71]

      BackgroundColor	      "lightBlue"
      DropShadow	      on

      FunctionName	      "<mtt_model_name>_sfun_input"
      PortCounts	      "[]"
      SFunctionModules	      "''"
      Port {
	PortNumber		1
	Name			"MTT  Model Inputs: MTTU"

	TestPoint		off
	LinearAnalysisOutput	off





	LinearAnalysisInput	off
	RTWStorageClass		"Auto"
      }
    }
    Block {
      BlockType		      "S-Function"
      Name		      "MTT Plant Model"
      Ports		      [1, 2]
      Position		      [320, 36, 465, 74]
      BackgroundColor	      "lightBlue"
      DropShadow	      on
      FunctionName	      "<mtt_model_name>_sfun"
      PortCounts	      "[]"
      SFunctionModules	      "''"

      Port {
	PortNumber		1





























	Name			"MTT Model States: MTTX"
	TestPoint		off
	LinearAnalysisOutput	off
	LinearAnalysisInput	off
	RTWStorageClass		"Auto"
      }
      Port {
	PortNumber		2
	Name			"MTT Model Outputs: MTTY"
	TestPoint		off
	LinearAnalysisOutput	off
	LinearAnalysisInput	off
	RTWStorageClass		"Auto"
      }
    }
    Block {
      BlockType		      Scope
      Name		      "Scope"
      Ports		      [1]
      Position		      [595, 49, 625, 81]
      BackgroundColor	      "lightBlue"
      DropShadow	      on
      Floating		      off
      Location		      [604, 136, 1156, 874]
      Open		      on
      NumInputPorts	      "1"
      TickLabels	      "OneTimeTick"
      ZoomMode		      "on"
      List {
	ListType		AxesTitles
	axes1			"%<SignalLabel>"
      }
      List {
	ListType		SelectedSignals


	axes1			""


      }




      Grid		      "on"


      TimeRange		      "auto"
      YMin		      "0"
      YMax		      "1"


      SaveToWorkspace	      off
      SaveName		      "ScopeData"
      DataFormat	      "StructureWithTime"


      LimitDataPoints	      on


      MaxDataPoints	      "5000"
      Decimation	      "1"
      SampleInput	      off
      SampleTime	      "0"
    }
    Line {
      Name		      "MTT  Model Inputs: MTTU"
      Labels		      [0, 0]
      SrcBlock		      "MTT Model Inputs"
      SrcPort		      1







      DstBlock		      "MTT Plant Model"
      DstPort		      1
    }
    Line {















      Name		      "MTT Model States: MTTX"

      Labels		      [2, 0]




      SrcBlock		      "MTT Plant Model"
      SrcPort		      1
      Points		      [0, -30; -455, 0]
      DstBlock		      "MTT Model Inputs"
      DstPort		      1
    }
    Line {
      Name		      "MTT Model Outputs: MTTY"
      Labels		      [-1, 0]
      SrcBlock		      "MTT Plant Model"
      SrcPort		      2
      DstBlock		      "Scope"
      DstPort		      1
    }
  }
}







|
|











|
>
>
>
>
>
>
>
>
>
>
|

|
>

|
>
|
|
|
|
<
|
>
|
|
>
>
>
>
>
|
|
<
<
|
|
|
<
|
|
|
|
|
|
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
|
|
<
<
<
<
<
|
|
|
>
>
|
>
>
|
>
>
>
>
|
>
>
|
|
|
>
>
|
|
|
>
>
|
>
>
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
>
>
>
>
|

<
|



<
<
|
|
|




150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

192
193
194
195
196
197
198
199
200
201
202


203
204
205

206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266

267
268





269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342

343
344
345
346


347
348
349
350
351
352
353
  LineDefaults {
    FontName		    "Helvetica"
    FontSize		    9
    FontWeight		    "normal"
    FontAngle		    "normal"
  }
  System {
    Name		    "<mtt_model_name>"
    Location		    [51, 441, 346, 574]
    Open		    on
    ModelBrowserVisibility  off
    ModelBrowserWidth	    200
    ScreenColor		    "white"
    PaperOrientation	    "landscape"
    PaperPositionMode	    "auto"
    PaperType		    "usletter"
    PaperUnits		    "inches"
    ZoomFactor		    "100"
    ReportName		    "simulink-default.rpt"
    Block {
      BlockType		      Inport
      Name		      "In1"
      Position		      [25, 43, 55, 57]
      Port		      "1"
      LatchInput	      off
      DataType		      "double"
      SignalType	      "real"
      Interpolate	      on
    }
    Block {
      BlockType		      SubSystem
      Name		      "MTT Model\n<mtt_model_name>"
      Ports		      [1, 1]
      Position		      [100, 20, 140, 80]
      ForegroundColor	      "blue"
      BackgroundColor	      "lightBlue"
      ShowPortLabels	      on
      TreatAsAtomicUnit	      off
      RTWSystemCode	      "Auto"
      RTWFcnNameOpts	      "Auto"
      RTWFileNameOpts	      "Auto"
      System {

	Name			"MTT Model\n<mtt_model_name>"
	Location		[45, 448, 1008, 720]
	Open			off
	ModelBrowserVisibility	off
	ModelBrowserWidth	200
	ScreenColor		"white"
	PaperOrientation	"landscape"
	PaperPositionMode	"auto"
	PaperType		"usletter"
	PaperUnits		"inches"
	ZoomFactor		"100"


	Block {
	  BlockType		  Inport
	  Name			  "In1"

	  Position		  [590, 203, 620, 217]
	  Port			  "1"
	  LatchInput		  off
	  DataType		  "double"
	  SignalType		  "real"
	  Interpolate		  on
	}
	Block {
	  BlockType		  "S-Function"
	  Name			  "MTT Model Inputs"
	  Ports			  [1, 1]
	  Position		  [390, 59, 565, 91]
	  BackgroundColor	  "lightBlue"
	  DropShadow		  on
	  FunctionName		  "<mtt_model_name>_sfun_input"
	  PortCounts		  "[]"
	  SFunctionModules	  "''"
	  Port {
	    PortNumber		    1
	    Name		    "MTT  Model Inputs: MTTU"
	    TestPoint		    off
	    LinearAnalysisOutput    off
	    LinearAnalysisInput	    off
	    RTWStorageClass	    "Auto"
	  }
	}
	Block {
	  BlockType		  "S-Function"
	  Name			  "MTT Plant Model"
	  Ports			  [1, 2]
	  Position		  [65, 61, 250, 199]
	  BackgroundColor	  "lightBlue"
	  DropShadow		  on
	  FunctionName		  "<mtt_model_name>_sfun"
	  PortCounts		  "[]"
	  SFunctionModules	  "''"
	  Port {
	    PortNumber		    1
	    Name		    "MTT Model States: MTTX"
	    TestPoint		    off
	    LinearAnalysisOutput    off
	    LinearAnalysisInput	    off
	    RTWStorageClass	    "Auto"
	  }
	  Port {
	    PortNumber		    2
	    Name		    "MTT Model Outputs: MTTY"
	    TestPoint		    off
	    LinearAnalysisOutput    off
	    LinearAnalysisInput	    off
	    RTWStorageClass	    "Auto"
	  }
	}
	Block {
	  BlockType		  "S-Function"
	  Name			  "S-Function"
	  Ports			  [4, 2]
	  Position		  [710, 47, 840, 238]
	  BackgroundColor	  "lightBlue"
	  DropShadow		  on
	  FunctionName		  "<mtt_model_name>_sfun_interface"

	  PortCounts		  "[]"
	  SFunctionModules	  "''"





	}
	Block {
	  BlockType		  Outport
	  Name			  "Out1"
	  Position		  [905, 183, 935, 197]
	  Port			  "1"
	  OutputWhenDisabled	  "held"
	  InitialOutput		  "[]"
	}
	Line {
	  Name			  "MTT Model States: MTTX"
	  Labels		  [2, 0]
	  SrcBlock		  "MTT Plant Model"
	  SrcPort		  1
	  Points		  [0, 0; 105, 0]
	  Branch {
	    Points		    [0, -20]
	    DstBlock		    "MTT Model Inputs"
	    DstPort		    1
	  }
	  Branch {
	    Points		    [0, 25]
	    DstBlock		    "S-Function"
	    DstPort		    2
	  }
	}
	Line {
	  Name			  "MTT Model Outputs: MTTY"
	  Labels		  [1, 0]
	  SrcBlock		  "MTT Plant Model"
	  SrcPort		  2
	  DstBlock		  "S-Function"
	  DstPort		  3
	}
	Line {
	  Name			  "MTT  Model Inputs: MTTU"
	  Labels		  [1, 0]
	  SrcBlock		  "MTT Model Inputs"
	  SrcPort		  1
	  DstBlock		  "S-Function"
	  DstPort		  1
	}
	Line {
	  SrcBlock		  "S-Function"
	  SrcPort		  1
	  Points		  [30, 0; 0, -70; -850, 0; 0, 105]
	  DstBlock		  "MTT Plant Model"
	  DstPort		  1
	}
	Line {
	  SrcBlock		  "In1"
	  SrcPort		  1
	  DstBlock		  "S-Function"
	  DstPort		  4
	}
	Line {
	  SrcBlock		  "S-Function"
	  SrcPort		  2
	  DstBlock		  "Out1"
	  DstPort		  1
	}
      }
    }
    Block {
      BlockType		      Outport
      Name		      "Out1"
      Position		      [185, 43, 215, 57]
      Port		      "1"
      OutputWhenDisabled      "held"
      InitialOutput	      "[]"
    }
    Line {
      SrcBlock		      "MTT Model\n<mtt_model_name>"
      SrcPort		      1

      DstBlock		      "Out1"
      DstPort		      1
    }
    Line {


      SrcBlock		      "In1"
      SrcPort		      1
      DstBlock		      "MTT Model\n<mtt_model_name>"
      DstPort		      1
    }
  }
}

Added mttroot/mtt/lib/rep/sfun_rep/sfun_interface.c.tmpl version [aa22fb9cbe].



























































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/* -*-c-*-	Put emacs into c-mode
 * <mtt_model_name>_sfun_interface.c:
 * Matlab S-function to process inputs and outputs of <mtt_model_name>
 */


#define S_FUNCTION_NAME <mtt_model_name>_sfun_interface
#define S_FUNCTION_LEVEL 2

#include <stdio.h>
#include <stdlib.h>
#include "simstruc.h"
#include "sfun_debug.h"
#include "<mtt_model_name>_def.h"

static double *mttu;		/* pointer to inputs */
static double *mttpar;		/* pointer to parameters */
static double *mttx;		/* pointer to states */
static double *mtty;		/* pointer to outputs */
static double  mttt;		/* time */

static double *controller_inputs;
static double *controller_outputs;

static unsigned int i;		/* loop counter */

/* Start EDIT */
/* Edit this block to define the number of controller inputs, outputs and parameters */
const int NumberOfControllerInputs	= 1; /* inputs TO controller */
const int NumberOfControllerOutputs	= 1; /* outputs FROM controller */
/* End EDIT */

static void
<mtt_model_name>_process_inputs (void)
{
  /* insert <mtt_model_name>_struc.c */

  /* Start EDIT */
  /* Edit this block to process the model inputs and outputs */
  
  /* Remove the following line */
  fprintf (stderr, "*** Error: <mtt_model_name>_sfun_interface.c has not been customised!\n"); return;

  /* simple example follows */

  /* Get total of all outputs and input to controller */
  controller_inputs[0] = 0.0;
  for (i = 0; i < MTTNY; i++) {
    controller_inputs[0] += mtty[i];
  }

  /* overwrite first model input with output from controller */
  mttu[0] = controller_outputs[0];

  /* End EDIT */
}


/******************************************************************************
 *                DO NOT EDIT ANYTHING BELOW THIS LINE                        *
 ******************************************************************************/

/* system equations */

static void
<mtt_model_name>_numpar (void)
{
#include "<mtt_model_name>_sympar.h"
#include "<mtt_model_name>_numpar.c"
  PRINT_LEAVE;
}

/* utility procedures */

static double *
array_of_double (size_t n)
{
  void *p = calloc (n, sizeof (double));
  if (! p) {
    fprintf (stderr, "*** Error: failed to allocate memory\n");
  }
  return (double *) p;
}

static void
initialise_arrays (void)
{
  PRINT_ENTER;

  mttpar	= array_of_double (MTTNPAR);
  mttu		= array_of_double (MTTNU + MTTNYZ);
  mttx		= array_of_double (MTTNX);
  mtty		= array_of_double (MTTNY);

  controller_inputs	= array_of_double (NumberOfControllerInputs);
  controller_outputs	= array_of_double (NumberOfControllerOutputs);

  PRINT_LEAVE;
}

static void
update_inputs_from_simulink (SimStruct *S)
{
  PRINT_ENTER;
  for (i = 0; i < MTTNU; i++) {
    mttu[i] = *ssGetInputPortRealSignalPtrs (S, 0)[i];
  }
  for (i = 0; i < MTTNX; i++) {
    mttx[i] = *ssGetInputPortRealSignalPtrs (S, 1)[i];
  }
  for (i = 0; i < MTTNY; i++) {
    mtty[i] = *ssGetInputPortRealSignalPtrs (S, 2)[i];
  }
  for (i = 0; i < NumberOfControllerOutputs; i++) {
    controller_outputs[i] = *ssGetInputPortRealSignalPtrs (S, 3)[i];
  }
  PRINT_LEAVE;
}

static void
update_simtime_from_simulink (SimStruct *S)
{
  PRINT_ENTER;
  mttt = ssGetT (S);
  PRINT_LEAVE;
}

/* S-function methods */

static void mdlInitializeSizes(SimStruct *S)
{
  PRINT_ENTER;

  ssSetNumSFcnParams(S, 0); 
  if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
    PRINT_LEAVE;
    return;
  }
  
  ssSetNumContStates(S, 0);
  ssSetNumDiscStates(S, 0);
  
  if (!ssSetNumInputPorts(S, 4)) return;
  ssSetInputPortWidth(S, 0, MTTNU);
  ssSetInputPortWidth(S, 1, MTTNX);
  ssSetInputPortWidth(S, 2, MTTNY);
  ssSetInputPortWidth(S, 3, NumberOfControllerOutputs);	/* inputs from controller */
  ssSetInputPortDirectFeedThrough(S, 0, 1);
  ssSetInputPortDirectFeedThrough(S, 1, 1);
  ssSetInputPortDirectFeedThrough(S, 2, 1);
  ssSetInputPortDirectFeedThrough(S, 3, 1);
    
  if (!ssSetNumOutputPorts(S, 2)) return;
  ssSetOutputPortWidth(S, 0, MTTNU); /* altered inputs */
  ssSetOutputPortWidth(S, 1, NumberOfControllerInputs); /* outputs to controller */
    
  ssSetNumSampleTimes(S, 1);
  ssSetNumRWork(S, 0);
  ssSetNumIWork(S, 0);
  ssSetNumPWork(S, 0);
  ssSetNumModes(S, 0);
  ssSetNumNonsampledZCs(S, 0);
  
  ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);
  
  initialise_arrays ();

  PRINT_LEAVE;
}

static void mdlInitializeSampleTimes(SimStruct *S)
{
  PRINT_ENTER;
  ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
  ssSetOffsetTime(S, 0, 0.0);
  PRINT_LEAVE;
}

#define MDL_INITIALIZE_CONDITIONS
static void mdlInitializeConditions(SimStruct *S)
{
  PRINT_ENTER;
  <mtt_model_name>_numpar ();
  PRINT_LEAVE;
}

static void mdlOutputs(SimStruct *S, int_T tid)
{
  PRINT_ENTER;

  update_inputs_from_simulink (S);
  update_simtime_from_simulink (S);

  <mtt_model_name>_process_inputs ();

  UNUSED_ARG(tid); /* not used in single tasking mode */

  for (i = 0; i < MTTNU; i++) {
    ssGetOutputPortRealSignal (S, 0)[i] = mttu[i];
  }
  
  for (i = 0; i < NumberOfControllerInputs; i++) {
    ssGetOutputPortRealSignal (S, 1)[i] = controller_inputs[i];
  }

  PRINT_LEAVE;
}

#define MDL_DERIVATIVES
static void mdlDerivatives(SimStruct *S)
{
  PRINT_ENTER;
  PRINT_LEAVE;
}

static void mdlTerminate(SimStruct *S)
{
  PRINT_ENTER;

  UNUSED_ARG(S);

  free (mttpar);
  free (mttu);
  free (mttx);
  free (mtty);

  free (controller_inputs);
  free (controller_outputs);

  PRINT_LEAVE;
}

#ifdef  MATLAB_MEX_FILE    /* Is this file being compiled as a MEX-file? */
#include "simulink.c"      /* MEX-file interface mechanism */
#else
#include "cg_sfun.h"       /* Code generation registration function */
#endif


MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]