Overview
Comment:Parameters in sfun reps are now declared using sympar.h at the top of the
sfun*.c file instead of in individual functions. This causes the optimisation
variables (mtt_tmp*) to be declared correctly without causing conflicts in the
scope of parameter declarations.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: dc3ec712bc3cb820bfd32ab8d5c69511fb74d8aa67ab77adfe6c4ae54abf86d3
User & Date: geraint@users.sourceforge.net on 2002-05-27 14:52:15
Other Links: branch diff | manifest | tags
Context
2002-05-27
15:18:48
Trying to get rid of this! check-in: d73843e4d8 user: geraint@users.sourceforge.net tags: origin/master, trunk
14:52:15
Parameters in sfun reps are now declared using sympar.h at the top of the
sfun*.c file instead of in individual functions. This causes the optimisation
variables (mtt_tmp*) to be declared correctly without causing conflicts in the
scope of parameter declarations.
check-in: dc3ec712bc user: geraint@users.sourceforge.net tags: origin/master, trunk
14:48:34
Inclusion of sympar.h moved to top of file for consistency with other templates.

states and outputs prepended with an underscore to prevent conflicts when
inputs and outputs have the same names. check-in: 373df68651 user: geraint@users.sourceforge.net tags: origin/master, trunk

Changes

Modified mttroot/mtt/bin/trans/mtt_header from [60dbd07829] to [b648dacad1].

8
9
10
11
12
13
14












15
16
17
18
19
20
21
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$












## Revision 1.50  2002/05/15 14:22:25  geraint
## Code for Simulink S-function target written direct to sfun.cc instead of
## calling .mexglx files. This eliminates the sfun dependency on Octave
## ColumnVectors. sys_sfun.cc should build directly on a MS Windows machine
## (can't test this yet).
##
## added sfun.zip target to create source code to export.







>
>
>
>
>
>
>
>
>
>
>
>







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
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.51  2002/05/19 13:01:21  geraint
## Numerical solution of algebraic equations implemented for S-function target.
##
## Equation solving requires the Matlab Optimization Toolbox to be installed.
##
## Code has been changed from C++ to C to allow mex files to be built with LCC,
## the compiler bundled with Matlab.
##
## Parameters are now obtained from numpar.c instead of a dialogue box.
##
## `mtt <sys> sfun zip` creates all necessary files for building the model mex files.
##
## Revision 1.50  2002/05/15 14:22:25  geraint
## Code for Simulink S-function target written direct to sfun.cc instead of
## calling .mexglx files. This eliminates the sfun dependency on Octave
## ColumnVectors. sys_sfun.cc should build directly on a MS Windows machine
## (can't test this yet).
##
## added sfun.zip target to create source code to export.
482
483
484
485
486
487
488

489
490
491
492
493
494
495
	;;
    c)
	modeline="/* -*-c-*- Put Emacs into c-mode */";
	Lc='/*'
	Rc='*/'
	Lb='['
	Rb=']'

	constant_declaration="const double "
	var_declaration="double "
	minusone="-1"
	;;
    *)
	echo Language $language not supported - sorry; exit 1
esac







>







494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
	;;
    c)
	modeline="/* -*-c-*- Put Emacs into c-mode */";
	Lc='/*'
	Rc='*/'
	Lb='['
	Rb=']'
	parameters=no
	constant_declaration="const double "
	var_declaration="double "
	minusone="-1"
	;;
    *)
	echo Language $language not supported - sorry; exit 1
esac

Modified mttroot/mtt/lib/rep/sfun_rep/Makefile from [8d877b3018] to [ef9265af42].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#! /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 $(SYS).mdl
	echo Creating $@
	mex $(SYS)_sfun.c
	cp *_sfun*mexglx $(SYS).mdl ..

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

$(SYS)_sfun_ae.mexglx: $(SYS)_sfun_ae.c $(SYS)_def.h $(SYS)_ae.c
	echo Creating $@
	mex $(SYS)_sfun_ae.c

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














|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#! /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 $(SYS).mdl
	echo Creating $@
	mex $(SYS)_sfun.c
	cp *_sfun*mexglx $(SYS).mdl ..

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

$(SYS)_sfun_ae.mexglx: $(SYS)_sfun_ae.c $(SYS)_def.h $(SYS)_sympar.h $(SYS)_ae.c
	echo Creating $@
	mex $(SYS)_sfun_ae.c

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

76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
	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/'`







|
|









76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
	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/mex_ae.c.tmpl from [946212c79a] to [7b88f2f493].

1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
/* -*-c-*-	Put emacs into c-mode
 * <mtt_model_name>_sfun_ae.c:
 * Matlab mex algebraic equations for <mtt_model_name>
 */

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


/* utility procedures */

double *
array_of_double (size_t n)
{
  void *p = calloc (n, sizeof (double));











>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* -*-c-*-	Put emacs into c-mode
 * <mtt_model_name>_sfun_ae.c:
 * Matlab mex algebraic equations for <mtt_model_name>
 */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <mex.h>
#include "sfun_debug.h"
#include "<mtt_model_name>_def.h"
#include "<mtt_model_name>_sympar.h"

/* utility procedures */

double *
array_of_double (size_t n)
{
  void *p = calloc (n, sizeof (double));

Modified mttroot/mtt/lib/rep/sfun_rep/sfun.c.tmpl from [11a0ec7435] to [129e85ea3e].

8
9
10
11
12
13
14

15
16
17
18
19
20
21

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


static double *mttdx;		/* pointer to rates */
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 *mttyz;		/* pointer to residuals */







>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

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

static double *mttdx;		/* pointer to rates */
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 *mttyz;		/* pointer to residuals */
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "<mtt_model_name>_ae.c"
  PRINT_LEAVE;
}

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

static void
<mtt_model_name>_ode (void)
{







<







32
33
34
35
36
37
38

39
40
41
42
43
44
45
#include "<mtt_model_name>_ae.c"
  PRINT_LEAVE;
}

static void
<mtt_model_name>_numpar (void)
{

#include "<mtt_model_name>_numpar.c"
  PRINT_LEAVE;
}

static void
<mtt_model_name>_ode (void)
{

Modified mttroot/mtt/lib/rep/sfun_rep/sfun_input.c.tmpl from [d7b84bb1c3] to [93bb29059c].

8
9
10
11
12
13
14

15
16
17
18
19
20
21

#include <math.h>
#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 */








>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "simstruc.h"
#include "sfun_debug.h"
#include "<mtt_model_name>_def.h"
#include "<mtt_model_name>_sympar.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 */

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "<mtt_model_name>_input.c"
  PRINT_LEAVE;
}

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 *







<







30
31
32
33
34
35
36

37
38
39
40
41
42
43
#include "<mtt_model_name>_input.c"
  PRINT_LEAVE;
}

static void
<mtt_model_name>_numpar (void)
{

#include "<mtt_model_name>_numpar.c"
  PRINT_LEAVE;
}

/* utility procedures */

static double *


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