Differences From Artifact [d4601e0783]:

To Artifact [4c8b8f966f]:


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.7  2000/10/17 09:53:20  peterg
## Fixed logic rep
##
## Revision 1.6  2000/10/17 08:37:23  peterg
## Included logic rep
##
## Revision 1.5  2000/10/14 09:12:14  peterg







>
>
>
>
>
>
>
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Copyright (C) 2000 by Peter J. Gawthrop

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.2  2000/11/03 00:55:42  geraint
## typo: missed out 'd' in mttedx
## todo: need to accommodate mttsimpar
##
## Revision 1.1  2000/11/02 04:28:39  geraint
## Initial revision
##
## Revision 1.8  2000/10/17 16:35:03  peterg
## No parameter,state or input conversion in txt files
##
## Revision 1.7  2000/10/17 09:53:20  peterg
## Fixed logic rep
##
## Revision 1.6  2000/10/17 08:37:23  peterg
## Included logic rep
##
## Revision 1.5  2000/10/14 09:12:14  peterg
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
eqnargs='mttx,mttu,mttt,mttpar'
inputeqnargs='mttx,mtty,mttt,mttpar'
case $rep in
    cse)
	states=yes;
        inputs=yes;
	parameters=yes;
        output='mttedx,mtte'
        args=$eqnargs
	;;
    csex)
	states=yes;
        inputs=yes;
	parameters=yes;
        output=mttedx







|







66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
eqnargs='mttx,mttu,mttt,mttpar'
inputeqnargs='mttx,mtty,mttt,mttpar'
case $rep in
    cse)
	states=yes;
        inputs=yes;
	parameters=yes;
        output='mttdx,mtte'
        args=$eqnargs
	;;
    csex)
	states=yes;
        inputs=yes;
	parameters=yes;
        output=mttedx
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
        output='mtty'
        args=$eqnargs
	;;
    simpar)
	states=no;
	inputs=no;
	parameters=no;
        output=mttsimpar
	;;
    sm)
	states=no;
	inputs=no;
	parameters=yes;
        output='mtta,mttb,mttc,mttd'
        args=mttpar







|







121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
        output='mtty'
        args=$eqnargs
	;;
    simpar)
	states=no;
	inputs=no;
	parameters=no;
        output='mttsimpar_map'
	;;
    sm)
	states=no;
	inputs=no;
	parameters=yes;
        output='mtta,mttb,mttc,mttd'
        args=mttpar
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
	function=""
	declaration=""
        start=''
        parameters=no
	states=no
	inputs=no
	;;





    *)
	echo Language $language not supported - sorry; exit 1
esac


































































































































































































# Header information
cat<<EOF
$modeline
$function $declaration
$Lc $declaration
$Lc System $system, representation $rep, language $language; $Rc
$Lc File $1_$rep.$language; $Rc
$Lc Generated by MTT on `date`; $Rc
EOF









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

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







>
>
>
>
>




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










>
>
>
>
>
>
>
>







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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
	function=""
	declaration=""
        start=''
        parameters=no
	states=no
	inputs=no
	;;
    oct)
	modeline="// -*-c++-*- Put Emacs into c++-mode";
	Lc='//';
	oct_header=yes;
	;;
    *)
	echo Language $language not supported - sorry; exit 1
esac


# Argument specific stuff
function get_arg_specific_stuff ()
{
    arg_name=${1:-""}
    case ${arg_name} in
	mtta | mtte)
	    arg_type="Matrix"
	    arg_size="(MTTNX,MTTNX)"
	    ;;
	mttb)
	    arg_type="Matrix"
	    arg_size="(MTTNX,MTTNU)"
	    ;;
	mttc)
	    arg_type="Matrix"
	    arg_size="(MTTNY,MTTNX)"
	    ;;
	mttd)
	    arg_type="Matrix"
	    arg_size="(MTTNY,MTTNU)"
	    ;;
	mttax | mttdx | mttedx | mttx | open)
	    arg_type="ColumnVector"
	    arg_size="(MTTNX)"
	    ;;
	mttpar)
	    arg_type="ColumnVector"
	    arg_size="(MTTNPAR)"
	    ;;
	mttsimpar_map)
	    arg_type="Octave_map"
	    arg_size="";
	    ;;
	mttu)
	    arg_type="ColumnVector"
	    arg_size="(MTTNU)"
	    ;;
	mtty)
	    arg_type="ColumnVector"
	    arg_size="(MTTNY)"
	    ;;
	mttt)
	    arg_type="const double"
	    arg_size=""
	    ;;
	nil)
	    arg_type="void *"
	    arg_size="(0x0)"
	    ;;
	*)
	    echo "Argument ${arg} not supported - sorry"; exit 1
    esac
}


function get_field ()
{ # parse comma separated string
    s=${1:-""}					# comma separated string
    i=${2:-0}					# field number in string

    if [ 0 -eq ${i} ]; then			# return number of fields
	echo ${s} |\
	awk -F\, '{ print NF }'
    else					# return ith field
	echo ${s} |\
	awk -F\, -v i=${i} '{ print $i }'
    fi
}


function get_extra_fields ()
{ # return list of words in s2 and not in s1
    s1=${1:-""}					# comma separated list
    s2=${2:-""}					# comma separated list

    c1=$(get_field ${s1} 0)			# count words in s1
    c2=$(get_field ${s2} 0)			# count words in s2
	
    ans=""
	
    i2=0					# s2 word index
    while [ ${i2} -lt ${c2} ]; do
        flag=0					# appearance of word in s1 and s2?
	i2=$((${i2} + 1))
	w2=$(get_field ${s2} ${i2})		# i2 th word in s2
	i1=0					# s1 word index
	while [ ${i1} -lt ${c1} ]; do
	    i1=$((${i1} + 1))
	    w1=$(get_field ${s1} ${i1})		# i1 th word in s1
	    if [ ${w2} = ${w1} ]; then
		flag=1				# w2 occurs in s1
	    fi
        done
	if [ ${flag} -eq 0 ]; then		# w2 is not in s1?
	    if [ -z ${ans} ]; then		#  string is empty?
		ans=${w2}			#   assign w2
	    else
		ans=${ans},${w2}		#   append w2
	    fi
        fi
    done
    echo ${ans}
}


function write_DLD_header ()
{
    cat <<EOF

#include <octave/oct.h>
#include <octave/ov-struct.h>
#include <octave/toplev.h>

#include <MTT/useful-functions.h>
#include "${system}_def.h"
#include "${system}_sympar.h"

DEFUN_DLD (${system}_${rep}, args, ,
"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"
    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")
		printf "  ${arg_type}\t${w}\t= args(${j}).double_value ();\n"
		;;
	    ColumnVector | Matrix | *)
		printf "  ${arg_type}\t${w}\t= args(${j}).vector_value ();\n"
		;;
	esac
    done
    printf "\n"
}	


function declare_DLD_outputs ()
{
    s=${1:-""}					# comma separated output list
    c=$(get_field ${s} 0)			# count of outputs
    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
    i=0
    cat <<EOF

// END Code

EOF
    while [ ${i} -lt ${c} ]; do
	j=${i}
	i=$((${i} + 1))
	w=$(get_field ${s} ${i})
	printf "  retval (${j})\t= octave_value (${w});\n"
    done
    printf "\n  return (retval);\n}\n"
}


# Header information
cat<<EOF
$modeline
$function $declaration
$Lc $declaration
$Lc System $system, representation $rep, language $language; $Rc
$Lc File $1_$rep.$language; $Rc
$Lc Generated by MTT on `date`; $Rc
EOF

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

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

## Horrible fudge to make mtt_m2p work
global ...
mtt_no_globals ;
225
226
227
228
229
230
231
232


$Lc Inputs $Rc
EOF

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










>
>
440
441
442
443
444
445
446
447
448
449
$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 ]