Differences From Artifact [6bf6a9a964]:

To Artifact [aeb001e855]:


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.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.
##







>
>
>
>







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

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.46  2002/05/07 13:48:43  geraint
## Improved clarity of code generated for -cc and -oct (except ode2odes).
## Octave DEFUN_DLDs now call (rather than replace) their .cc equivalents.
##
## 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.
##
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
		;;
	    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







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




















>



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







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
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
		;;
	    ColumnVector | Matrix | *)
		printf "  ${arg_type}\t${w}\t= args(${j}).%s ();\n" ${vector_value}
		;;
	esac
    done
}	

map_mex_inputs ()
{
    s=${1:-""}					# comma separated input list
    if [ -z ${s:-""} ];then return; fi
    c=`get_field ${s} 0`			# count of inputs
    i=0
    cat <<EOF
    if (${c} != nrhs)
     {
       std::cerr << "${fun_name} expected " << ${c} << " argument(s): ${s}" << std::endl;
       return;
     }
EOF
    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= mtt_double (prhs [${j}]);\n"
		;;
	    ColumnVector | Matrix | *)
		printf "  ${arg_type}\t${w}\t= mtt_${arg_type} (prhs [${j}]);\n"
		;;
	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
}

write_mex ()
{
    func=${1:-"<insert function name>"}
    args=${2:-""}
    cat <<EOF
#if (CODEGENTARGET == MATLABMEX)
#include "mex.h"

Matrix
mtt_Matrix (const mxArray *m)
{
  const unsigned long int nrows = mxGetM (m);
  const unsigned long int ncols = mxGetN (m);
  Matrix o (nrows, ncols);
  const double *p = mxGetPr (m);
  for (unsigned long int row = 0; row < nrows; row++)
    for (unsigned long int col = 0; col < ncols; col++)
      o (row, col) = p[row + nrows*col];
  return (o);
}

ColumnVector
mtt_ColumnVector (const mxArray *m)
{
  const unsigned long int nrows = mxGetM (m);
  ColumnVector o (nrows);
  const double *p = mxGetPr (m);
  for (unsigned long int row = 0; row < nrows; row++)
    o (row) = p[row];
  return (o);
}

const double
mtt_double (const mxArray *m)
{
  const double *p = mxGetPr (m);
  return (*p);
}

mxArray *
mtt_mxArray (const Matrix &o)
{
  const unsigned long int nrows = o.rows ();
  const unsigned long int ncols = o.columns ();
  mxArray *m;
  m = mxCreateDoubleMatrix (nrows, ncols, mxREAL);
  double *p = mxGetPr (m);
  for (unsigned long int row = 0; row < nrows; row++)
    for (unsigned long int col = 0; col < ncols; col++)
      p [row + nrows*col] = o (row, col);
  return (m);
}

mxArray *
mtt_mxArray (const ColumnVector &o)
{
  const unsigned long int nrows = o.length ();
  mxArray *m;
  m = mxCreateDoubleMatrix (nrows, 1, mxREAL);
  double *p = mxGetPr (m);
  for (unsigned long int row = 0; row < nrows; row++)
    p [row] = o (row);
  return (m);
}

extern "C"
{
  void mexFunction (int nlhs,       mxArray *plhs[],
		  int nrhs, const mxArray *prhs[])
  {
EOF
  map_mex_inputs ${args}
cat <<EOF
  plhs[0] = mtt_mxArray (${func} (${args}));
  }
}
#endif

EOF
}

# Header information
cat<<EOF
$modeline
$function $declaration
$Lc $declaration
$Lc System $system, representation $rep, language $language; $Rc
861
862
863
864
865
866
867
868
869

870
871
872
873
874
875
876
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 ...







|

>







976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
fi

if [ ${language} = "oct" ];then
# standalone
    write_cc_header
    array2constant
    write_cc_footer
# oct and mex code
    write_oct ${system}_${rep} ${args}
    write_mex ${system}_${rep} ${args}
else

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

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

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