Overview
Comment:Fixed some problems with generation of C++ code.

Representations such as ode now appear to have multiple outputs (mttdx,mtty) listed in mtt_header, so the write_cc_header parses the string and only returns the first one.

Vector sizes mttnu, mttnx, etc. now appear in the code of sys_ode.m etc., so they are declared as static int in sys_def.h.

The following now works properly on Ubuntu 12: mtt -cc -i euler -o rc gnuplot view

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 8e2a1aea1b56fd19061cdb95f4ce35a3b66ddbc9e8fc3644a9891497c87f86aa
User & Date: geraint@users.sourceforge.net on 2014-07-13 13:53:52
Other Links: branch diff | manifest | tags
Context
2014-07-14
06:37:07
Avoid continuation \ issues. check-in: 7267367629 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
2014-07-13
13:53:52
Fixed some problems with generation of C++ code.

Representations such as ode now appear to have multiple outputs (mttdx,mtty) listed in mtt_header, so the write_cc_header parses the string and only returns the first one.

Vector sizes mttnu, mttnx, etc. now appear in the code of sys_ode.m etc., so they are declared as static int in sys_def.h.

The following now works properly on Ubuntu 12: mtt -cc -i euler -o rc gnuplot view check-in: 8e2a1aea1b user: geraint@users.sourceforge.net tags: origin/master, trunk

2014-07-12
22:30:45
Declare size of vectors (mttnu,mttnx,etc) which now appear in ode code check-in: f282a62064 user: geraint@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/mtt_header from [af77a75d17] to [342dc555fd].

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.67  2005/11/16 00:43:15  geraint
## rtxi
##
## Revision 1.66  2005/02/17 18:54:23  geraint
## Fixed a bash-sim: replaced let with $(( ))
##
## Revision 1.65  2004/08/29 13:14:29  geraint
## Added rule to make header for sae (sorted algebraic equations).
##
## Revision 1.64  2004/08/29 01:48:46  geraint
262
263
264
265
266
267
268
269

270
271
272
273
274
275
276
265
266
267
268
269
270
271

272
273
274
275
276
277
278
279







-
+







## Make parameter listing representation dependent
##
## Revision 1.3  2000/10/11 08:59:15  peterg
## Added csex rep
##
## Revision 1.2  2000/10/11 08:01:42  peterg
## Added noglobal fudge
##
 ##
## Revision 1.1  2000/10/10 21:02:27  peterg
## Initial revision
##
###############################################################

# Arguments
system=$1
382
383
384
385
386
387
388
389

390
391

392
393
394
395
396
397
398
385
386
387
388
389
390
391

392
393

394
395
396
397
398
399
400
401







-
+

-
+







        output='mttpar'
	zeromatrices='par'
	;;
    ode)
	states=yes;
        inputs=yes;
	parameters=yes;
        output='mttdx'
        output='mttdx,mtty'
        args=$eqnargs
	zeromatrices='dx'
	zeromatrices='dx y'
	;;
    odeo)
	states=yes;
        inputs=yes;
	parameters=yes;
        output='mtty'
        args=$eqnargs
912
913
914
915
916
917
918

919



920
921
922
923
924
925
926
915
916
917
918
919
920
921
922

923
924
925
926
927
928
929
930
931
932







+
-
+
+
+







    done
    echo ${ans}
}


write_cc_header ()
{
    first_output=`get_field ${output:-""} 1`
    get_arg_specific_stuff ${output}
    get_arg_specific_stuff ${first_output}
    # Should multiple vector outputs be returned as a single matrix?
    
    cat <<EOF

#include <octave/oct.h>
#include "useful-functions.hh"
#include "${system}_cr.h"
#include "${system}_def.h"
#include "${system}_sympar.h"
949
950
951
952
953
954
955
956
957
958
959
960
961
962













963
964
965
966



967
968
969
970
971

972
973
974
975
976
977
978
955
956
957
958
959
960
961

962
963
964


965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989

990
991
992
993
994
995
996
997







-



-
-

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




+
+
+




-
+







		comma=""
	    fi
	    w=`get_field ${args} ${i}`
	    get_arg_specific_stuff ${w}
	    printf "\tconst ${arg_type}\t&${w}${comma}\n"
	done
    fi
    get_arg_specific_stuff ${output}
    cat <<EOF
)
{
  static ${arg_type} ${output} ${arg_init};

EOF

    if [ -z ${output:-""} ]; then
	printf "/* write_cc_header: no output specified. */"
    else
	c=`get_field ${output:-""} 0`
	i=0
	while [ ${i} -lt ${c} ]; do
	    i=`expr ${i} + 1`
	    w=`get_field ${output} ${i}`
	    get_arg_specific_stuff ${w}
	    printf "\tstatic ${arg_type}\t${w}${arg_init};\n"
	done
    fi
}

write_cc_footer ()
{
    first_output=`get_field ${output:-""} 1`
    # Should multiple vector outputs be returned as a single matrix?

    cat <<EOF
// BEGIN Code
// END   Code

  return ${output};
  return ${first_output};
}

EOF
}


map_oct_inputs ()
1026
1027
1028
1029
1030
1031
1032

1033
1034
1035
1036
1037
1038
1039
1040

1041
1042
1043
1044
1045
1046
1047
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059

1060
1061
1062
1063
1064
1065
1066
1067







+







-
+







	esac
    done
}	
    

write_oct()
{
    first_output=`get_field ${output:-""} 1`
    func=${1:-"<insert function name>"}
    args=${2:-""}
    cat <<EOF
#if (CODEGENTARGET == OCTAVEDLD)
$oct_rep_include

DEFUN_DLD (${system}_${rep}, args, ,
"Usage: [$output] = ${system}_${rep}($args)\nOctave ${rep} representation of system ${system}\nGenerated by MTT on `date`")
"Usage: [$first_output] = ${system}_${rep}($args)\nOctave ${rep} representation of system ${system}\nGenerated by MTT on `date`")
{
  static octave_value_list retval;

EOF
    map_oct_inputs ${args}
    cat <<EOF

Modified mttroot/mtt/cc/def_m2h.sh from [1106fa706f] to [e00c7a936e].

37
38
39
40
41
42
43



44
45
46
47
48
49
50
51
52



53
54
55
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

55
56
57
58
59
60







+
+
+








-
+
+
+



get_array_size ()
{
vec=$1
gawk -v vec=${vec} '($1 == vec && $2 == "=") { print $3 }' | sed s/\;//
}

 echo "/* ${SYS}_def.h, generated by MTT on `date` */"			>  ${OUT}
 echo ""								>> ${OUT}
 echo "#ifndef HAVE_${SYS}_DEF_H"					>> ${OUT}
 echo "#define HAVE_${SYS}_DEF_H"					>> ${OUT}
 echo ""								>> ${OUT}
 echo "const int MTTNU   = `cat ${IN} | get_array_size nu`;"		>> ${OUT}
 echo "const int MTTNX   = `cat ${IN} | get_array_size nx`;"		>> ${OUT}
 echo "const int MTTNY   = `cat ${IN} | get_array_size ny`;"		>> ${OUT}
 echo "const int MTTNZ   = `cat ${IN} | get_array_size nz`;"		>> ${OUT}
 echo "const int MTTNYZ  = `cat ${IN} | get_array_size nyz`;"		>> ${OUT}
 echo "const int MTTNPAR = `wc -l ${SYM} | gawk '{ print $1 }'`;"      	>> ${OUT}
 echo ""								>> ${OUT}
 echo "int mttnu, mttnx, mttny, mttnyz, mttnz;"				>> ${OUT}
 echo "static int mttnu, mttnx, mttny, mttnyz, mttnz;"		       	>> ${OUT}
 echo ""								>> ${OUT}
 echo "#endif"								>> ${OUT}




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