Overview
Comment: | Improved clarity of code generated for -cc and -oct (except ode2odes). Octave DEFUN_DLDs now call (rather than replace) their .cc equivalents. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | origin/master | trunk |
Files: | files | file ages | folders |
SHA3-256: |
06c3b3d188a3eff24b23290e3c67bdca |
User & Date: | geraint@users.sourceforge.net on 2002-05-07 13:48:43 |
Other Links: | branch diff | manifest | tags |
Context
2002-05-07
| ||
16:28:26 | Trying to fix parameter identification problem ... check-in: 93079fee46 user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
13:48:43 |
Improved clarity of code generated for -cc and -oct (except ode2odes). Octave DEFUN_DLDs now call (rather than replace) their .cc equivalents. check-in: 06c3b3d188 user: geraint@users.sourceforge.net tags: origin/master, trunk | |
12:04:49 | Upgraded to return Nx3 matrix of indices check-in: 9ead2455dc user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
Changes
Modified mttroot/mtt/bin/trans/make_ode2odes from [de3807b0bb] to [1c09db5c78].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #! /bin/sh ###################################### ##### Model Transformation Tools ##### ###################################### ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ ## Revision 1.73 2002/05/01 12:24:41 geraint ## Removed unnecessary inclusion of load-save.h. ## ## Revision 1.72 2002/05/01 12:21:29 geraint ## No longer uses save_ascii_data_for_plotting function to write data ## - eliminates dependence on liboctinterp (and libncurses) for .cc. ## | > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #! /bin/sh ###################################### ##### Model Transformation Tools ##### ###################################### ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ ## Revision 1.74 2002/05/01 17:30:56 geraint ## Improved pre-processor directives to better accommodate future alternatives (matlab) ## if necessary. ## ## Revision 1.73 2002/05/01 12:24:41 geraint ## Removed unnecessary inclusion of load-save.h. ## ## Revision 1.72 2002/05/01 12:21:29 geraint ## No longer uses save_ascii_data_for_plotting function to write data ## - eliminates dependence on liboctinterp (and libncurses) for .cc. ## |
︙ | ︙ | |||
451 452 453 454 455 456 457 | #include "mtt_${algebraic_solver}.hh" #include <fstream> #if (CODEGENTARGET == STANDALONE) #include <csignal> | | | | | | | | | | | | 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 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 527 | #include "mtt_${algebraic_solver}.hh" #include <fstream> #if (CODEGENTARGET == STANDALONE) #include <csignal> extern ColumnVector ${sys}_ae ( ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par); extern ColumnVector ${sys}_input ( ColumnVector &x, ColumnVector &y, const double &t, ColumnVector &par); extern ColumnVector ${sys}_logic ( ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par); extern ColumnVector ${sys}_numpar ( void); extern ColumnVector ${sys}_simpar ( void); extern ColumnVector ${sys}_state ( ColumnVector &par); extern ColumnVector ${sys}_${ode} ( ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par); extern ColumnVector ${sys}_${odeo} ( ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par); EOF case "$method" in "implicit") cat <<EOF >> $filename extern ColumnVector Fmtt_implicit ( ColumnVector &x, ColumnVector &dx, Matrix &AA, ColumnVector &AAx, const double &ddt, const int &nx, const ColumnVector &open_switches); extern Matrix ${sys}_smxa ( ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par); extern ColumnVector ${sys}_smxax ( ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par); EOF ;; |
︙ | ︙ | |||
557 558 559 560 561 562 563 | ColumnVector mtt_ae (ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par) { #if (CODEGENTARGET == STANDALONE) | | | 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | ColumnVector mtt_ae (ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par) { #if (CODEGENTARGET == STANDALONE) return ${sys}_ae(x,u,t,par); #elif (CODEGENTARGET == OCTAVEDLD) static octave_value_list args, f; args (0) = octave_value (x); args (1) = octave_value (u); args (2) = octave_value (t); args (3) = octave_value (par); f = feval ("${sys}_ae", args, 1); |
︙ | ︙ | |||
579 580 581 582 583 584 585 | const double &t, ColumnVector &par) { static MTT::${algebraic_solver} ae(MTTNPAR,MTTNU,MTTNX,MTTNY,MTTNYZ); static ColumnVector u (MTTNU); #if (CODEGENTARGET == STANDALONE) | | | 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | const double &t, ColumnVector &par) { static MTT::${algebraic_solver} ae(MTTNPAR,MTTNU,MTTNX,MTTNY,MTTNYZ); static ColumnVector u (MTTNU); #if (CODEGENTARGET == STANDALONE) u = ${sys}_input (x, y, t, par); #elif (CODEGENTARGET == OCTAVEDLD) static octave_value_list args, f; args (0) = octave_value (x); args (1) = octave_value (y); args (2) = octave_value (t); args (3) = octave_value (par); f = feval ("${sys}_input", args, 1); |
︙ | ︙ | |||
606 607 608 609 610 611 612 | inline ColumnVector mtt_logic (ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par) { #if (CODEGENTARGET == STANDALONE) | | | | | | | | 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 | inline ColumnVector mtt_logic (ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par) { #if (CODEGENTARGET == STANDALONE) return ${sys}_logic (x, u, t, par); #elif (CODEGENTARGET == OCTAVEDLD) static octave_value_list args, f; args (0) = octave_value (x); args (1) = octave_value (u); args (2) = octave_value (t); args (3) = octave_value (par); f = feval ("${sys}_logic", args, 1); return f(0).${vector_value} (); #endif // (CODEGENTARGET == STANDALONE) } inline ColumnVector mtt_numpar (void) { #if (CODEGENTARGET == STANDALONE) return ${sys}_numpar (); #elif (CODEGENTARGET == OCTAVEDLD) static octave_value_list args, f; f = feval ("${sys}_numpar", args, 1); return f(0).${vector_value} (); #endif // (CODEGENTARGET == STANDALONE) } inline ColumnVector mtt_simpar (void) { #if (CODEGENTARGET == STANDALONE) return ${sys}_simpar (); #elif (CODEGENTARGET == OCTAVEDLD) static octave_value_list args, f; f = feval ("${sys}_simpar", args, 1); return f(0).${vector_value} (); #endif // (CODEGENTARGET == STANDALONE) } inline ColumnVector mtt_state (ColumnVector &par) { #if (CODEGENTARGET == STANDALONE) return ${sys}_state (par); #elif (CODEGENTARGET == OCTAVEDLD) static octave_value_list args, f; args (0) = octave_value (par); f = feval ("${sys}_state", args, 1); return f(0).${vector_value} (); #endif // (CODEGENTARGET == STANDALONE) } inline ColumnVector mtt_rate (ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par) { #if (CODEGENTARGET == STANDALONE) return ${sys}_${ode} (x, u, t, par); #elif (CODEGENTARGET == OCTAVEDLD) static octave_value_list args, f; args (0) = octave_value (x); args (1) = octave_value (u); args (2) = octave_value (t); args (3) = octave_value (par); f = feval ("${sys}_${ode}", args, 1); return f(0).${vector_value} (); #endif // (CODEGENTARGET == STANDALONE) } inline ColumnVector mtt_output (ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par) { #if (CODEGENTARGET == STANDALONE) return ${sys}_${odeo} (x, u, t, par); #elif (CODEGENTARGET == OCTAVEDLD) static octave_value_list args, f; args (0) = octave_value (x); args (1) = octave_value (u); args (2) = octave_value (t); args (3) = octave_value (par); f = feval ("${sys}_${odeo}", args, 1); |
︙ | ︙ | |||
729 730 731 732 733 734 735 | inline Matrix mtt_smxa (ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par) { #if (CODEGENTARGET == STANDALONE) | | | | 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 | inline Matrix mtt_smxa (ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par) { #if (CODEGENTARGET == STANDALONE) return ${sys}_smxa (x, u, t, par); #elif (CODEGENTARGET == OCTAVEDLD) static octave_value_list args, f; args (0) = octave_value (x); args (1) = octave_value (u); args (2) = octave_value (t); args (3) = octave_value (par); f = feval ("${sys}_smxa", args, 1); return f(0).matrix_value (); #endif // (CODEGENTARGET == STANDALONE) } inline ColumnVector mtt_smxax (ColumnVector &x, ColumnVector &u, const double &t, ColumnVector &par) { #if (CODEGENTARGET == STANDALONE) return ${sys}_smxax (x, u, t, par); #elif (CODEGENTARGET == OCTAVEDLD) static octave_value_list args, f; args (0) = octave_value (x); args (1) = octave_value (u); args (2) = octave_value (t); args (3) = octave_value (par); f = feval ("${sys}_smxax", args, 1); |
︙ | ︙ | |||
795 796 797 798 799 800 801 | f = feval ("mtt_dassl", args, 1); return f(0).${vector_value} (); #endif // (CODEGENTARGET == STANDALONE) } #if (CODEGENTARGET == STANDALONE) ColumnVector | | | 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 | f = feval ("mtt_dassl", args, 1); return f(0).${vector_value} (); #endif // (CODEGENTARGET == STANDALONE) } #if (CODEGENTARGET == STANDALONE) ColumnVector mtt_residual (const ColumnVector &X, const ColumnVector &DX, double t, int &ires) { #elif (CODEGENTARGET == OCTAVEDLD) DEFUN_DLD (mtt_residual, args, , "mtt_residual") { |
︙ | ︙ | |||
832 833 834 835 836 837 838 | static octave_value_list new_args; x = X.extract (0,MTTNX-1); if (MTTNYZ > 0) ui = X.extract (MTTNX,MTTNX+MTTNYZ-1); #if (CODEGENTARGET == STANDALONE) | | | | | | 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 | static octave_value_list new_args; x = X.extract (0,MTTNX-1); if (MTTNYZ > 0) ui = X.extract (MTTNX,MTTNX+MTTNYZ-1); #if (CODEGENTARGET == STANDALONE) par = ${sys}_numpar(); u = ${sys}_input(x,y,t,par); #elif (CODEGENTARGET == OCTAVEDLD) par = feval ("${sys}_numpar", new_args, 1)(0).${vector_value} (); new_args(0) = octave_value (x); new_args(1) = octave_value (u); new_args(2) = octave_value (t); new_args(3) = octave_value (par); u = feval ("${sys}_input", new_args, 1)(0).${vector_value} (); #endif // (CODEGENTARGET == STANDALONE) U.insert (u,0); if (MTTNYZ > 0) U.insert (ui,MTTNU); #if (CODEGENTARGET == STANDALONE) dx = ${sys}_${ode} (x,U,t,par); yz = ${sys}_ae (x,U,t,par); #elif (CODEGENTARGET == OCTAVEDLD) new_args(1) = octave_value (U); dx = feval ("${sys}_${ode}", new_args, 1)(0).${vector_value} (); yz = feval ("${sys}_ae", new_args, 1)(0).${vector_value} (); #endif // (CODEGENTARGET == STANDALONE) for (register int i = 0; i < MTTNX; i++) |
︙ | ︙ |
Modified mttroot/mtt/bin/trans/make_stdin from [d2cafbc640] to [834838dfbf].
︙ | ︙ | |||
96 97 98 99 100 101 102 | str >> c; } str.setf(ios::skipws); c = str.peek (); } } | | | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | str >> c; } str.setf(ios::skipws); c = str.peek (); } } ColumnVector ${Sys}_input ( ColumnVector &mttx, ColumnVector &mtty, const double &mttt, ColumnVector &mttpar ) { #elif (CODEGENTARGET == OCTAVEDLD) |
︙ | ︙ |
Modified mttroot/mtt/bin/trans/mtt_header from [60273694d1] to [6bf6a9a964].
︙ | ︙ | |||
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.44 2002/05/01 17:30:56 geraint ## Improved pre-processor directives to better accommodate future alternatives (matlab) ## if necessary. ## ## Revision 1.43 2002/04/30 23:27:00 geraint ## Replaced octave_map with columnvector in simpar.cc. Not quite as descriptive but ## standardises the interfaces somewhat and reduces the dependency on liboctinterp | > > > | 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.45 2002/05/02 09:30:22 gawthrop ## _ssim.m now returns t as 4th arg ## ## Revision 1.44 2002/05/01 17:30:56 geraint ## Improved pre-processor directives to better accommodate future alternatives (matlab) ## if necessary. ## ## Revision 1.43 2002/04/30 23:27:00 geraint ## Replaced octave_map with columnvector in simpar.cc. Not quite as descriptive but ## standardises the interfaces somewhat and reduces the dependency on liboctinterp |
︙ | ︙ | |||
731 732 733 734 735 736 737 | fi fi done echo ${ans} } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < > > > > > > > > | > > | > > > > > | > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > | | > | | < < < < | | | < < < | 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 | fi fi done echo ${ans} } write_cc_header () { get_arg_specific_stuff ${output} cat <<EOF #include <octave/oct.h> #include "useful-functions.hh" #include "${system}_cr.h" #include "${system}_def.h" #include "${system}_sympar.h" // Code generation directives #define STANDALONE 0 #define OCTAVEDLD 1 #define MATLABMEX 2 #ifndef CODEGENTARGET #define CODEGENTARGET STANDALONE #endif // CODEGENTARGET ${arg_type} ${system}_${rep} ( EOF if [ -z ${args:-""} ]; then printf "\tvoid" else c=`get_field ${args:-""} 0` i=0 while [ ${i} -lt ${c} ]; do i=`expr ${i} + 1` if [ ${i} -lt ${c} ]; then comma="," else comma="" fi w=`get_field ${args} ${i}` get_arg_specific_stuff ${w} printf "\t${arg_type}\t&${w}${comma}\n" done fi get_arg_specific_stuff ${output} cat <<EOF ) { static ${arg_type} ${output} ${arg_init}; EOF } write_cc_footer () { cat <<EOF // BEGIN Code // END Code return ${output}; } EOF } map_oct_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 (\"${fun_name} expected ${c} argument(s): ${s}\");\n\n" while [ ${i} -lt ${c} ]; do j=${i} i=`expr ${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}).%s ();\n" ${vector_value} ;; esac done } write_oct() { func=${1:-"<insert function name>"} args=${2:-""} cat <<EOF #if (CODEGENTARGET == OCTAVEDLD) DEFUN_DLD (${system}_${rep}, args, , "Usage: [$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 retval (0) = ${func} (${args}); return (retval); } #endif // (CODEGENTARGET == OCTAVEDLD) EOF } # 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 "${header_only}" ]; then exit else get_sizes; fi if [ ${language} = "oct" ];then # standalone write_cc_header array2constant write_cc_footer # oct code write_oct ${system}_${rep} ${args} else if [ -n "$noglobals" ]; then cat<<EOF ## Horrible fudge to make mtt_m2p work global ... |
︙ | ︙ |