Index: mttroot/mtt/bin/trans/obs_r2m
==================================================================
--- mttroot/mtt/bin/trans/obs_r2m
+++ mttroot/mtt/bin/trans/obs_r2m
@@ -13,10 +13,15 @@
 echo Creating $1_obs.m
 
 # Remove the old log file
 rm -f obs_r2m.log
 rm -f $1_obs.m?
+rm -f $1_obsa.m
+
+# Is the system affine (look in the _obs.r file
+affine=`grep 'affine :=' $1_obs.r | awk '{print $3}' | sed 's/;//'`
+
 
 # Use reduce to accomplish the transformation
 $SYMBOLIC >obs_r2m.log << EOF
 
 %Read the reduce definitions file
@@ -43,30 +48,23 @@
 PRECISION 16; %Compatible with Matlab
 OFF Nat;
 
 ON NERO;        % Suppress zero elements
 
-mtt_matrix := MTTYY;
-mtt_matrix_n := MTTNY*(MTTGPCNy+1);
-mtt_matrix_m := 1;
-mtt_matrix_name := Y;
+% Matrix output function
 in"$MTTPATH/trans/matlab_matrix.r";
 
-OUT "$1_obs.m1";
-
-write "function Y = $1_obs(x,u)";
-write "%GPC O function in matlab form for system $1;;";
-write "%File $1_obs.m;;";
-write "%Generated by MTT;;";
-
-write "%"; 
+OUT "$1_obs.m2";
+
 write "% Set up the State variables";
 FOR i := 1:MTTNx DO
 BEGIN
   write "mttx", i, " = x(", i, ");";
 END;
 
+IF affine=0 THEN 
+BEGIN
 write "%"; 
 write "% Set up the inputs and input derivatives";
 FOR i := 1:MTTNu DO
   BEGIN
     write "mttu", i, " = u(", i, ",1);";
@@ -74,32 +72,64 @@
     BEGIN
       write "mttu", i,j, " = u(", i, ",", j+1, ");";
     END;
   END;
 
-write "%"; 
-write "% Set up the Y matrix";
-write "Y = zeros(", mtt_matrix_n, ",1);";
-
-
-SHUT "$1_obs.m1";
-
-GENTRANOUT "$1_obs.m3";
-write "%"; 
-write "% Translate the expression for Y";
-matlab_matrix(); 
-GENTRANSHUT "$1_obs.m3";
+%write "%"; 
+%write "% Set up the Y matrix";
+%write "Y = zeros(", mtt_matrix_n, ",1);";
+END;
+
+
+SHUT "$1_obs.m2";
+
+IF affine=1 THEN 
+BEGIN
+  GENTRANOUT "$1_obs.m3";
+  MTT_Matrix := MTTObs_o$ 
+  MTT_Matrix_name := "MTTO_o"$
+  MTT_Matrix_n := (MTTGPCNY+1)*MTTNy$
+  MTT_Matrix_m := 1$
+  matlab_Matrix()$
+  GENTRAN O_o := mtt_matrix;
+
+  MTT_Matrix := MTTObs_h$ 
+  MTT_Matrix_name := "MTTO_h"$
+  MTT_Matrix_n := (MTTGPCNy+1)*MTTNy$
+  MTT_Matrix_m := (MTTGPCNu+1)*MTTNu$
+  matlab_Matrix()$
+  GENTRAN O_h := mtt_matrix;
+
+  GENTRANSHUT "$1_obs.m3";
+END
+ELSE
+BEGIN
+  GENTRANOUT "$1_obs.m3";
+  mtt_matrix := MTTYY$
+  mtt_matrix_n := MTTNY*(MTTGPCNy+1)$
+  mtt_matrix_m := 1$
+  mtt_matrix_name := Y$
+  matlab_matrix(); 
+  GENTRAN YY := mtt_matrix;
+  GENTRANSHUT "$1_obs.m3";
+END;
 
 EOF
 
-# Create the globals
-sympar2global_txt2m $1> $1_obs.m2
+if [ "$affine" = "1" ]; then
+    lang_header $1 obs m x [o_o,o_h] > $1_obs.m1
+else
+    lang_header $1 obs m x,u yy > $1_obs.m1
+fi
 
-# Change name
-echo 'Y = mtt_matrix;' > $1_obs.m4
 # Put together the pieces
+matlab_tidy $1_obs.m3
 cat   $1_obs.m? >$1_obs.m
 
 rm -f $1_obs.m?
+
+
+
+