Overview
Comment:lower-case declarations
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 66de85792d53bcb1de107c06d689135c15e58b61cadafee63a404de1ee35075a
User & Date: gawthrop@users.sourceforge.net on 2000-11-09 15:29:35
Other Links: branch diff | manifest | tags
Context
2000-11-09
16:09:46
Declare dummy variables (mtt_s1 etc) check-in: bd23fffb08 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
15:29:35
lower-case declarations check-in: 66de85792d user: gawthrop@users.sourceforge.net tags: origin/master, trunk
10:29:21
open --> mtt_open check-in: 426b9eac45 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/mtt_header from [6b48f7198b] to [7145292f9f].

8
9
10
11
12
13
14



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







+
+
+







# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.10  2000/11/07 17:20:51  peterg
## useful-functions.hh now included locally
##
## Revision 1.9  2000/11/07 16:56:24  peterg
## Version from Geraint
##
## Revision 1.2  2000/11/03 00:55:42  geraint
## typo: missed out 'd' in mttedx
## todo: need to accommodate mttsimpar
##
48
49
50
51
52
53
54

55
56
57
58
59
60
61
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65







+







##
###############################################################

# Arguments
system=$1
rep=$2
language=$3
fun_name=${1}_${2}
#args=$4
#output=$5
#extras=$6

# Find system constants
Nx=`mtt_getsize $system x` # States
Nxx=`mtt_getsize $system xx` # States x States
92
93
94
95
96
97
98

99
100
101
102
103
104

105


106
107
108
109
110
111
112
96
97
98
99
100
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
116
117
118
119







+





-
+

+
+







	;;
    input)
	states=yes;
	inputs=no;
	parameters=yes;
        output=mttu
        args=$inputeqnargs
        declareinputs=yes
	;;
    logic)
	states=no;
	inputs=no;
	parameters=yes;
        output=open
        output=mttopen
        args=$eqnargs
        declareinputs=yes
        declarestates=yes
	;;
    numpar)
	states=no;
	inputs=no;
	parameters=no;
        output='mttpar'
	;;
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
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







+
+
+
+
+
+
+




-
+








+
+
+
+
+
+
+
+
+
+
+
+
+
+






+







    odeo)
	states=yes;
        inputs=yes;
	parameters=yes;
        output='mtty'
        args=$eqnargs
	;;
    ode2odes)
	states=no;
        inputs=no;
	parameters=no;
        output='y,x,t'
        args='x,par,simpar'
	;;
    simpar)
	states=no;
	inputs=no;
	parameters=no;
        output='mttsimpar_map'
        output='mttsimpar'
	;;
    sm)
	states=no;
	inputs=no;
	parameters=yes;
        output='mtta,mttb,mttc,mttd'
        args=mttpar
	;;
    smxa)
	states=no;
        inputs=no;
	parameters=yes;
        output='mtta'
        args=$eqnargs
	;;
    smxax)
	states=no;
        inputs=no;
	parameters=yes;
        output='mttax'
        args=$eqnargs
	;;
    state)
	states=no;
	inputs=no;
	parameters=yes;
        output=mttx
        args=mttpar
        declarestates=yes
	;;
    *)
	echo Representation $rep not supported - sorry; exit 1
esac

## Sort out parentheses
if [ -n "$args" ]; then
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
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







+
+
+













+
+





+
+
+
+





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	Lb='(';
	Rb=')';
	function="function"
	declaration="$Output$1_$rep$Args;"
	noglobals=true; # Fudge to make mtt_m2p work
        start='## BEGIN Code'
        finish='## END Code'
        var_declaration=$Lc
        declarestates=no
        declareinputs=no
	;;
    txt)
	modeline='## -*-octave-*- Put Emacs into octave-mode ##';
	Lc='##';
	Rc='';
	Lb='(';
	Rb=')';
	function=""
	declaration=""
        start=''
        parameters=no
	states=no
	inputs=no
        declarestates=no
        declareinputs=no
	;;
    oct)
	modeline="// -*-c++-*- Put Emacs into c++-mode";
	Lc='//';
	oct_header=yes;
        constant_declaration="const double "
        var_declaration="double "
	minusone="-1"
	map="_map"
	;;
    *)
	echo Language $language not supported - sorry; exit 1
esac

if [ "$rep" = "simpar" ]; then
   output=${output}${map}    # Output is simpar_map in this case
fi

function declare_vars(){
# Grab the names
names=`awk '{if ($1==var_type) print tolower($4)}' var_type=$1 ${system}_struc.txt`

# Comments
cat <<EOF

$Lc  Declarations for $1 names $Rc
EOF
# Declarations
for name in $names; do
    echo '  '$var_declaration $name';'
done
}


function array2constant() {
# Parameters
if [ "$parameters" = "yes" ]; then
cat <<EOF

$Lc Parameters $Rc
EOF
sympar2par_txt2m ${system} ""  "$constant_declaration" "$minusone"
fi

# States
if [ "$states" = "yes" ]; then
cat <<EOF

$Lc States $Rc
EOF
N=`n2m 1 $Nx`
for i in $N; do
    echo $constant_declaration 'mttx'$i' = mttx('$i$minusone');'
done
fi

if [ "$declarestates" = "yes" ]; then
  declare_vars state
fi

# Inputs
if [ "$inputs" = "yes" ]; then
cat <<EOF

$Lc Inputs $Rc
EOF

N=`n2m 1 $Nu`
for i in $N; do
  echo $constant_declaration 'mttu'$i' = mttu('$i$minusone');'
done
fi

if [ "$declareinputs" = "yes" ]; then
  declare_vars input
fi

}

# Argument specific stuff
function get_arg_specific_stuff ()
{
    arg_name=${1:-""}
    case ${arg_name} in
	mtta | mtte)
210
211
212
213
214
215
216
217

218
219
220
221
222
223
224
312
313
314
315
316
317
318

319
320
321
322
323
324
325
326







-
+







	    arg_type="Matrix"
	    arg_size="(MTTNY,MTTNX)"
	    ;;
	mttd)
	    arg_type="Matrix"
	    arg_size="(MTTNY,MTTNU)"
	    ;;
	mttax | mttdx | mttedx | mttx | open)
	mttax | mttdx | mttedx | mttx | mttopen)
	    arg_type="ColumnVector"
	    arg_size="(MTTNX)"
	    ;;
	mttpar)
	    arg_type="ColumnVector"
	    arg_size="(MTTNPAR)"
	    ;;
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
409
410
411
412
413
414
415
416

417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432

433
434
435
436
437
438
439
440







+
-
+















-
+







#include <octave/toplev.h>

#include "useful-functions.hh"
#include "${system}_def.h"
#include "${system}_sympar.h"

DEFUN_DLD (${system}_${rep}, args, ,
"Usage: [$output] = ${system}_${rep}($args)
"Octave ${rep} representation of system ${system}
Octave ${rep} representation of system ${system}
Generated by MTT on $(date)")
{

  octave_value_list retval;

EOF
}


function map_DLD_inputs ()
{
    s=${1:-""}					# comma separated input list
    if [ -z ${s} ];then return; fi
    c=$(get_field ${s} 0)			# count of inputs
    i=0
    printf "  if (${c} != args.length ()) usage (\"expected ${c} argument(s): ${s}\");\n\n"
    printf "  if (${c} != args.length ()) usage (\"${fun_name} expected ${c} argument(s): ${s}\");\n\n"
    while [ ${i} -lt ${c} ]; do
	j=${i}
	i=$((${i} + 1))
	w=$(get_field ${s} ${i})		# argument name
	get_arg_specific_stuff ${w}
	case ${arg_type} in
	    "const double")
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
456
457
458
459
460
461
462





463
464
465
466
467
468
469







-
-
-
-
-







    i=0
    while [ ${i} -lt ${c} ]; do
	i=$((${i} + 1))
	w=$(get_field ${s} ${i})		# argument name
	get_arg_specific_stuff ${w}
	printf "  ${arg_type}\t${w}\t${arg_size};\n"
    done
    cat <<EOF

// BEGIN Code

EOF
}


function return_DLD_outputs ()
{
    s=${1:-""}					# comma separated output list
    c=$(get_field ${s} 0)			# count of outputs
396
397
398
399
400
401
402






403
404
405
406
407
408
409
410
411
412
413
414



415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525







526

































+
+
+
+
+
+












+
+
+




-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
EOF

if [ ${language} = "oct" ];then
    write_DLD_header
    map_DLD_inputs ${args}
    undeclared=$(get_extra_fields ${args:-"nil"} ${output:-"nil"})
    declare_DLD_outputs ${undeclared}
    array2constant
    cat <<EOF

// BEGIN Code

EOF
    return_DLD_outputs ${output}
else

if [ -n "$noglobals" ]; then
cat<<EOF

## Horrible fudge to make mtt_m2p work
global ...
mtt_no_globals ;
EOF
fi

## Arrays 
array2constant

# Mark start of code
echo
echo $start

# Parameters
if [ "$parameters" = "yes" ]; then
cat <<EOF

$Lc Parameters $Rc
EOF
sympar2par_txt2m $1 
fi
# States
if [ "$states" = "yes" ]; then
cat <<EOF

$Lc States $Rc
EOF
N=`n2m 1 $Nx`
for i in $N; do
    echo '  mttx'$i' = mttx('$i');'
done
fi

# Inputs
if [ "$inputs" = "yes" ]; then
cat <<EOF

$Lc Inputs $Rc
EOF

N=`n2m 1 $Nu`
for i in $N; do
    echo '  mttu'$i' = mttu('$i');'
done
fi

fi


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