changeset 4044:9678c5526190

[project @ 2002-08-15 16:54:55 by jwe]
author jwe
date Thu, 15 Aug 2002 16:54:56 +0000
parents 6fae69a1796e
children b908aaa4080a
files ChangeLog liboctave/ChangeLog liboctave/DASPK-opts.in liboctave/DASPK.h liboctave/DASRT-opts.in liboctave/DASRT.h liboctave/DASSL-opts.in liboctave/DASSL.h liboctave/LSODE-opts.in liboctave/LSODE.h liboctave/NLEqn-opts.in liboctave/NLEqn.h liboctave/ODESSA-opts.in liboctave/ODESSA.h mk-opts.pl src/ChangeLog src/ov.cc src/ov.h src/parse.y
diffstat 19 files changed, 285 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Aug 15 03:36:27 2002 +0000
+++ b/ChangeLog	Thu Aug 15 16:54:56 2002 +0000
@@ -1,3 +1,11 @@
+2002-08-15  Paul Kienzle <pkienzle@users.sf.net>
+
+	* mk-opts.pl: Add support for INCLUDE = "...".
+
+2002-08-15  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* mk-opts.pl: Handle Array<int> too.
+
 2002-08-10  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* mk-opts.pl (emit_options_function): Emit newline at EOF.
--- a/liboctave/ChangeLog	Thu Aug 15 03:36:27 2002 +0000
+++ b/liboctave/ChangeLog	Thu Aug 15 16:54:56 2002 +0000
@@ -1,3 +1,12 @@
+2002-08-15  Paul Kienzle <pkienzle@users.sf.net>
+
+	* DASPK-opts.in, DASPK.h: Move include to .in file.
+	* DASRT-opts.in, DASRT.h: Likewise.
+        * DASSL-opts.in, DASSL.h: Likewise.
+	* LSODE-opts.in, LSODE.h: Likewise.
+	* NLEqn-opts.in, NLEqn.h: Likewise.
+	* ODESSA-opts.in, ODESSA.h: Likewise.
+
 2002-08-14  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* LSODE.cc (LSODE::error_message): Also return current T on
--- a/liboctave/DASPK-opts.in	Thu Aug 15 03:36:27 2002 +0000
+++ b/liboctave/DASPK-opts.in	Thu Aug 15 16:54:56 2002 +0000
@@ -1,5 +1,7 @@
 CLASS = "DASPK"
 
+INCLUDE = "DAE.h"
+
 OPTION
   NAME = "absolute tolerance"
   TYPE = "Array<double>"
@@ -41,6 +43,89 @@
 END_OPTION
 
 OPTION
+  NAME = "compute consistent initial condition"
+  TYPE = "int"
+  INIT_VALUE = "0"
+  SET_EXPR = "val"
+END_OPTION
+
+OPTION
+  NAME = "enforce inequality constraints"
+  TYPE = "int"
+  INIT_VALUE = "0"
+  SET_EXPR = "val"
+END_OPTION
+
+OPTION
+  NAME = "inequality constraint types"
+  TYPE = "Array<int>"
+  SET_ARG_TYPE = const $TYPE&
+  INIT_BODY
+    $OPTVAR.resize (1);
+    $OPTVAR(0) = 0;
+  END_INIT_BODY
+  SET_CODE
+    void set_$OPT (int val)
+      {
+        $OPTVAR.resize (1);
+        $OPTVAR(0) = (val > 0.0) ? val : 0;
+      }
+
+    void set_$OPT (const $TYPE& val)
+      { $OPTVAR = val; }
+  END_SET_CODE
+END_OPTION
+
+OPTION
+  NAME = "exclude algebraic variables in error test"
+  TYPE = "int"
+  INIT_VALUE = "0"
+  SET_EXPR = "val"
+END_OPTION
+
+OPTION
+  NAME = "initial condition maximum step"
+  TYPE = "double"
+  INIT_VALUE = "-1.0"
+  SET_EXPR = "(val >= 0.0) ? val : -1.0"
+END_OPTION
+
+OPTION
+  NAME = "initial condition maximum jacobian evaluations"
+  TYPE = "int"
+  INIT_VALUE = "-1"
+  SET_EXPR = "(val >= 0) ? val : -1"
+END_OPTION
+
+OPTION
+  NAME = "initial condition maximum newton iterations"
+  TYPE = "int"
+  INIT_VALUE = "-1"
+  SET_EXPR = "(val >= 0) ? val : -1"
+END_OPTION
+
+OPTION
+  NAME = "initial condition minimum linesearch step"
+  TYPE = "double"
+  INIT_VALUE = "-1.0"
+  SET_EXPR = "(val >= 0.0) ? val : 0.0"
+END_OPTION
+
+OPTION
+  NAME = "initial condition omit linesearch"
+  TYPE = "int"
+  INIT_VALUE = "0"
+  SET_EXPR = "val"
+END_OPTION
+
+OPTION
+  NAME = "initial condition swing factor"
+  TYPE = "double"
+  INIT_VALUE = "1.0"
+  SET_EXPR = "(val >= 0.0) ? val : -1.0"
+END_OPTION
+
+OPTION
   NAME = "initial step size"
   TYPE = "double"
   INIT_VALUE = "-1.0"
@@ -48,6 +133,13 @@
 END_OPTION
 
 OPTION
+  NAME = "maximum order"
+  TYPE = "int"
+  INIT_VALUE = "-1"
+  SET_EXPR = "val"
+END_OPTION
+
+OPTION
   NAME = "maximum step size"
   TYPE = "double"
   INIT_VALUE = "-1.0"
@@ -60,3 +152,11 @@
   INIT_VALUE = "0.0"
   SET_EXPR = "(val >= 0.0) ? val : 0.0"
 END_OPTION
+
+OPTION
+  NAME = "print initial condition info"
+  TYPE = "int"
+  INIT_VALUE = "0"
+  SET_EXPR = "val"
+END_OPTION
+
--- a/liboctave/DASPK.h	Thu Aug 15 03:36:27 2002 +0000
+++ b/liboctave/DASPK.h	Thu Aug 15 16:54:56 2002 +0000
@@ -30,8 +30,6 @@
 #include <cfloat>
 #include <cmath>
 
-#include "DAE.h"
-
 #include "DASPK-opts.h"
 
 class
--- a/liboctave/DASRT-opts.in	Thu Aug 15 03:36:27 2002 +0000
+++ b/liboctave/DASRT-opts.in	Thu Aug 15 16:54:56 2002 +0000
@@ -1,5 +1,7 @@
 CLASS = "DASRT"
 
+INCLUDE = "DAERT.h"
+
 OPTION
   NAME = "absolute tolerance"
   TYPE = "Array<double>"
--- a/liboctave/DASRT.h	Thu Aug 15 03:36:27 2002 +0000
+++ b/liboctave/DASRT.h	Thu Aug 15 16:54:56 2002 +0000
@@ -30,8 +30,6 @@
 #include <cfloat>
 #include <cmath>
 
-#include "DAERT.h"
-
 #include "DASRT-opts.h"
 
 class
--- a/liboctave/DASSL-opts.in	Thu Aug 15 03:36:27 2002 +0000
+++ b/liboctave/DASSL-opts.in	Thu Aug 15 16:54:56 2002 +0000
@@ -1,5 +1,7 @@
 CLASS = "DASSL"
 
+INCLUDE = "DAE.h"
+
 OPTION
   NAME = "absolute tolerance"
   TYPE = "Array<double>"
@@ -48,6 +50,13 @@
 END_OPTION
 
 OPTION
+  NAME = "maximum order"
+  TYPE = "int"
+  INIT_VALUE = "-1"
+  SET_EXPR = "val"
+END_OPTION
+
+OPTION
   NAME = "maximum step size"
   TYPE = "double"
   INIT_VALUE = "-1.0"
--- a/liboctave/DASSL.h	Thu Aug 15 03:36:27 2002 +0000
+++ b/liboctave/DASSL.h	Thu Aug 15 16:54:56 2002 +0000
@@ -30,8 +30,6 @@
 #include <cfloat>
 #include <cmath>
 
-#include "DAE.h"
-
 #include "DASSL-opts.h"
 
 class
--- a/liboctave/LSODE-opts.in	Thu Aug 15 03:36:27 2002 +0000
+++ b/liboctave/LSODE-opts.in	Thu Aug 15 16:54:56 2002 +0000
@@ -1,5 +1,7 @@
 CLASS = "LSODE"
 
+INCLUDE = "ODE.h"
+
 OPTION
   NAME = "absolute tolerance"
   TYPE = "Array<double>"
--- a/liboctave/LSODE.h	Thu Aug 15 03:36:27 2002 +0000
+++ b/liboctave/LSODE.h	Thu Aug 15 16:54:56 2002 +0000
@@ -30,8 +30,6 @@
 #include <cfloat>
 #include <cmath>
 
-#include "ODE.h"
-
 #include "LSODE-opts.h"
 
 class
--- a/liboctave/NLEqn-opts.in	Thu Aug 15 03:36:27 2002 +0000
+++ b/liboctave/NLEqn-opts.in	Thu Aug 15 16:54:56 2002 +0000
@@ -2,6 +2,10 @@
 
 FCN_NAME = "fsolve"
 
+INCLUDE = "dColVector.h"
+INCLUDE = "NLFunc.h"
+
+
 DOC_STRING
 When called with two arguments, this function allows you set options
 parameters for the function @code{fsolve}.  Given one argument,
--- a/liboctave/NLEqn.h	Thu Aug 15 03:36:27 2002 +0000
+++ b/liboctave/NLEqn.h	Thu Aug 15 16:54:56 2002 +0000
@@ -30,9 +30,6 @@
 #include <cfloat>
 #include <cmath>
 
-#include "dColVector.h"
-#include "NLFunc.h"
-
 #include "NLEqn-opts.h"
 
 class
--- a/liboctave/ODESSA-opts.in	Thu Aug 15 03:36:27 2002 +0000
+++ b/liboctave/ODESSA-opts.in	Thu Aug 15 16:54:56 2002 +0000
@@ -1,5 +1,7 @@
 CLASS = "ODESSA"
 
+INCLUDE = "ODES.h"
+
 OPTION
   NAME = "absolute tolerance"
   TYPE = "Array<double>"
--- a/liboctave/ODESSA.h	Thu Aug 15 03:36:27 2002 +0000
+++ b/liboctave/ODESSA.h	Thu Aug 15 16:54:56 2002 +0000
@@ -30,8 +30,6 @@
 #include <cfloat>
 #include <cmath>
 
-#include "ODES.h"
-
 #include "ODESSA-opts.h"
 
 class
--- a/mk-opts.pl	Thu Aug 15 03:36:27 2002 +0000
+++ b/mk-opts.pl	Thu Aug 15 16:54:56 2002 +0000
@@ -16,6 +16,7 @@
 #
 # CLASS = string
 # FCN_NAME = string
+# INCLUDE = file
 # DOC_STRING doc END_DOC_STRING
 # OPTION
 #   NAME = string
@@ -87,12 +88,20 @@
           die "duplicate FCN_NAME" if ($fcn_name ne "");
           $fcn_name = $1;
         }
+      elsif (/^\s*INCLUDE\s*=\s*"(\S+)"\s*$/)
+        {
+          $include = "${include}#include <$1>\n";
+	}
       elsif (/^\s*DOC_STRING\s*$/)
         {
           die "duplicate DOC_STRING" if ($have_doc_string);
           &parse_doc_string;
           $have_doc_string = 1;
         }
+      else
+        {
+	  die "mk-opts.pl: unknown command: $_\n"
+	}
     }
 }
 
@@ -326,6 +335,8 @@
 #include <cfloat>
 #include <cmath>
 
+${include}
+
 class
 ${class_name}
 {
@@ -430,6 +441,9 @@
 sub emit_opt_handler_fcns
 {
   local ($i);
+  my $header = $INFILE;
+  $header =~ s/[.]\w*$/.h/; # replace .in with .h
+  $header =~ s|^.*/([^/]*)$|$1|; # strip directory part
 
   print "// DO NOT EDIT!\n// Generated automatically from $INFILE.\n\n";
 
@@ -440,9 +454,15 @@
 #include <iomanip>
 #include <iostream>
 
+#include \"$header\"
+
 #include \"defun-dld.h\"
 #include \"pr-output.h\"
 
+#include \"oct-obj.h\"
+#include \"utils.h\"
+#include \"pager.h\"
+
 static ${class_name} ${static_object_name};\n\n";
 
   &emit_struct_decl;
@@ -580,6 +600,24 @@
         {
           print "    os << $static_object_name.$opt[$i] () << \"\\n\";\n";
         }
+      elsif ($type[$i] eq "Array<int>")
+        {
+          print "    Array<int> val = $static_object_name.$opt[$i] ();\n\n";
+          print "    if (val.length () == 1)
+      {
+        os << val(0) << \"\\n\";
+      }
+    else
+      {
+        os << \"\\n\\n\";
+	int len = val.length ();
+	Matrix tmp (len, 1);
+	for (int i = 0; i < len; i++)
+	  tmp(i,0) = val(i);
+        octave_print_internal (os, tmp, false, 2);
+        os << \"\\n\\n\";
+      }\n";
+        }
       elsif ($type[$i] eq "Array<double>")
         {
           print "    Array<double> val = $static_object_name.$opt[$i] ();\n\n";
@@ -641,6 +679,12 @@
           print "      if (! error_state)
         $static_object_name.set_$opt[$i] (tmp);\n";
         }
+      elsif ($type[$i] eq "Array<int>")
+        {
+          print "      Array<int> tmp = val.int_vector_value ();\n\n";
+          print "      if (! error_state)
+        $static_object_name.set_$opt[$i] (tmp);\n";
+        }
       elsif ($type[$i] eq "Array<double>")
         {
           print "      Array<double> tmp = val.vector_value ();\n\n";
@@ -697,6 +741,22 @@
         {
           print "      retval = $static_object_name.$opt[$i] ();\n";
         }
+      elsif ($type[$i] eq "Array<int>")
+        {
+          print "      Array<int> val = $static_object_name.$opt[$i] ();\n\n";
+          print "      if (val.length () == 1)
+        {
+          retval = static_cast<double> (val(0));
+        }
+      else
+        {
+	  int len = val.length ();
+	  ColumnVector tmp (len);
+	  for (int i = 0; i < len; i++)
+	    tmp(i) = val(i);
+          retval = tmp;
+        }\n";
+        }
       elsif ($type[$i] eq "Array<double>")
         {
           print "      Array<double> val = $static_object_name.$opt[$i] ();\n\n";
--- a/src/ChangeLog	Thu Aug 15 03:36:27 2002 +0000
+++ b/src/ChangeLog	Thu Aug 15 16:54:56 2002 +0000
@@ -1,3 +1,9 @@
+2002-08-15  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* parse.y (case_list): Allow it to be empty.
+
+	* ov.cc, ov.h (octave_value::int_vector_value): New function.
+
 2002-08-14  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* Makefile.in (OCTAVE_LIBS): Only include $(LIBKPATHSEA) if not
--- a/src/ov.cc	Thu Aug 15 03:36:27 2002 +0000
+++ b/src/ov.cc	Thu Aug 15 16:54:56 2002 +0000
@@ -907,6 +907,82 @@
   return retval;
 }
 
+Array<int>
+octave_value::int_vector_value (bool force_string_conv, bool require_int,
+				bool force_vector_conversion) const
+{
+  Array<int> retval;
+
+  Matrix m = matrix_value (force_string_conv);
+
+  if (error_state)
+    return retval;
+
+  int nr = m.rows ();
+  int nc = m.columns ();
+
+  if (nr == 1)
+    {
+      retval.resize (nc);
+      for (int i = 0; i < nc; i++)
+	{
+	  double d = m (0, i);
+
+	  if (require_int && D_NINT (d) != d)
+	    {
+	      error ("conversion to integer value failed");
+	      return retval;
+	    }
+
+	  retval (i) = static_cast<int> (d);
+	}
+    }
+  else if (nc == 1)
+    {
+      retval.resize (nr);
+      for (int i = 0; i < nr; i++)
+	{
+	  double d = m (i, 0);
+
+	  if (require_int && D_NINT (d) != d)
+	    {
+	      error ("conversion to integer value failed");
+	      return retval;
+	    }
+
+	  retval (i) = static_cast<int> (d);
+	}
+    }
+  else if (nr > 0 && nc > 0
+	   && (Vdo_fortran_indexing || force_vector_conversion))
+    {
+      retval.resize (nr * nc);
+      int k = 0;
+      for (int j = 0; j < nc; j++)
+	{
+	  for (int i = 0; i < nr; i++)
+	    {
+	      double d = m (i, j);
+
+	      if (require_int && D_NINT (d) != d)
+		{
+		  error ("conversion to integer value failed");
+		  return retval;
+		}
+
+	      retval (k++) = static_cast<int> (d);
+	    }
+	}
+    }
+  else
+    {
+      std::string tn = type_name ();
+      gripe_invalid_conversion (tn.c_str (), "real vector");
+    }
+
+  return retval;
+}
+
 Array<Complex>
 octave_value::complex_vector_value (bool force_string_conv,
 				    bool force_vector_conversion) const
--- a/src/ov.h	Thu Aug 15 03:36:27 2002 +0000
+++ b/src/ov.h	Thu Aug 15 16:54:56 2002 +0000
@@ -483,6 +483,10 @@
   complex_row_vector_value (bool frc_str_conv = false,
 			    bool frc_vec_conv = false) const;
 
+  Array<int> int_vector_value (bool req_int = false,
+			       bool frc_str_conv = false,
+			       bool frc_vec_conv = false) const;
+
   Array<double> vector_value (bool frc_str_conv = false,
 			      bool frc_vec_conv = false) const;
 
--- a/src/parse.y	Thu Aug 15 03:36:27 2002 +0000
+++ b/src/parse.y	Thu Aug 15 16:54:56 2002 +0000
@@ -980,7 +980,9 @@
 		  }
 		;
 
-case_list	: case_list1
+case_list	: // empty
+		  { $$ = new tree_switch_case_list (); }
+		| case_list1
 		  { $$ = $1; }
 		| case_list1 default_case
 		  {