diff scripts/ode/odeset.m @ 20581:e368ce72a844

maint: Use Octave coding conventions for ode* functions. Use '!' instead of '~' for logical not. Use '##' only for comments which standalone on a line. Use double quotes instead of single quotes where possible. Wrap long lines to < 80 characters. * ode45.m, odeget.m, odeset.m: Use Octave coding conventions.
author Rik <rik@octave.org>
date Sat, 03 Oct 2015 22:10:45 -0700
parents 25623ef2ff4f
children 45151de7423f
line wrap: on
line diff
--- a/scripts/ode/odeset.m	Sat Oct 03 21:03:16 2015 -0700
+++ b/scripts/ode/odeset.m	Sat Oct 03 22:10:45 2015 -0700
@@ -17,7 +17,6 @@
 ## along with Octave; see the file COPYING.  If not, see
 ## <http://www.gnu.org/licenses/>.
 
-
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {} odeset ()
 ## @deftypefnx {Function File} {@var{odestruct} =} odeset (@var{"field1"}, @var{value1}, @var{"field2"}, @var{value2}, @dots{})
@@ -53,10 +52,9 @@
 function opt = odeset (varargin)
 
   ## Check number and types of all input arguments
-  if ((nargin == 0)
-      && (nargout == 0))
+  if (nargin == 0 && nargout == 0)
     print_options;
-    return
+    return;
   endif
 
   ## Creating a vector of OdePkg possible fields
@@ -81,9 +79,8 @@
   opt.Refine = 0;
   opt.OutputSave = 1;
 
-  if ((nargin == 0)
-      && (nargout == 1))
-    return
+  if (nargin == 0 && nargout == 1)
+    return;
   endif
 
   ode_fields = fieldnames (opt);
@@ -102,14 +99,14 @@
         pos = fuzzy_compare (name, fields);
         if (size (pos, 1) == 0)
           warning ("OdePkg:InvalidArgument",
-                   "no property found with name ''%s''", name);
+                   "no property found with name '%s'", name);
         endif
 
         if (size (pos, 1) == 1)
           if (! strcmp (lower (deblank (name)),
                         lower (deblank (fields(pos,:)))))
             warning ("OdePkg:InvalidArgument", "no exact matching for ",
-                     "''%s''. Assuming you were intending ''%s''",
+                     "'%s'. Assuming you were intending '%s'",
                      name, deblank (fields(pos,:)));
           endif
 
@@ -119,7 +116,7 @@
 
         ## if there are more matching, ask the user to be more precise
         warning ("OdePkg:InvalidArgument",
-                 "no exact matching for ''%s''. %d possible fields were found",
+                 "no exact matching for '%s'. %d possible fields were found",
                  name, size(pos, 1));
         for j = 1:(size (pos, 1))
           fprintf ("%s\n", deblank (fields(pos(j),:)));
@@ -131,8 +128,7 @@
       endwhile
     endfor
 
-    if ((nargin == 2)
-        && (isstruct (varargin{2})))
+    if (nargin == 2 && isstruct (varargin{2}))
       ode_struct_value_check (varargin{2});
 
       optB_fields = fieldnames (varargin{2});
@@ -146,13 +142,14 @@
 
           if (size (pos, 1) == 0)
             warning ("OdePkg:InvalidArgument", ...
-                     "no property found with name ''%s''", name);
+                     "no property found with name '%s'", name);
           endif
 
           if (size(pos, 1) == 1)
-            if (! strcmp (lower (deblank (name)), lower (deblank (fields(pos,:)))))
+            if (! strcmp (lower (deblank (name)), ...
+                          lower (deblank (fields(pos,:)))))
               warning ("OdePkg:InvalidArgument", "no exact matching for ",
-                       "''%s''. Assuming you were intending ''%s''",
+                       "'%s'. Assuming you were intending '%s'",
                         name, deblank (fields(pos,:)));
             endif
             opt.(deblank (fields(pos,:))) = varargin{2}.(optB_fields{i});
@@ -160,7 +157,7 @@
           endif
 
           ## if there are more matching, ask the user to be more precise
-          warning ("OdePkg:InvalidArgument", "no exact matching for ''%s''. ",
+          warning ("OdePkg:InvalidArgument", "no exact matching for '%s'. ",
                    "%d possible fields were found",
                    name, size (pos, 1));
           for j = 1:(size (pos, 1))
@@ -172,7 +169,7 @@
           until (ischar (name))
         endwhile
       endfor
-      return
+      return;
     endif
 
     ## if the second argument is not a struct,
@@ -198,12 +195,12 @@
 
         if (size (pos, 1) == 0)
           error ("OdePkg:InvalidArgument",
-                 "no property found with name ''%s''", name);
+                 "no property found with name '%s'", name);
         endif
 
         if (size (pos, 1) == 1)
           if (! strcmp (lower (deblank (name)), lower (deblank (fields(pos,:)))))
-            warning ("OdePkg:InvalidArgument", "no exact matching for ''%s''. ",
+            warning ("OdePkg:InvalidArgument", "no exact matching for '%s'. ",
                      "%d possible fields were found",
                      name, size (pos, 1));
           endif
@@ -212,7 +209,7 @@
         endif
 
         ## if there are more matching, ask the user to be more precise
-        warning ("OdePkg:InvalidArgument", "no exact matching for ''%s''. ",
+        warning ("OdePkg:InvalidArgument", "no exact matching for '%s'. ",
                  "%d possible fields were found",
                  name, size (pos, 1));
         for j = 1:(size (pos, 1))
@@ -227,7 +224,7 @@
 
     ## check if all has been done gives a valid OdePkg struct
     ode_struct_value_check (opt);
-    return
+    return;
   endif
 
   ## first input argument was not a struct
@@ -249,14 +246,14 @@
 
       if (size (pos, 1) == 0)
         error ("OdePkg:InvalidArgument",
-               "invalid property. No property found with name ''%s''", name);
+               "invalid property. No property found with name '%s'", name);
       endif
 
       if (size (pos, 1) == 1)
         if (! strcmp (lower (deblank (name)),
                       lower (deblank (fields(pos,:)))))
           warning ("OdePkg:InvalidArgument", "no exact matching for ",
-                   "''%s''. Assuming you were intending ''%s''",
+                   "'%s'. Assuming you were intending '%s'",
                    name, deblank (fields(pos,:)));
         endif
         opt.(deblank (fields(pos,:))) = varargin{i+1};
@@ -264,7 +261,7 @@
       endif
 
       ## if there are more matching, ask the user to be more precise
-      warning ("OdePkg:InvalidArgument", "no exact matching for ''%s''. ",
+      warning ("OdePkg:InvalidArgument", "no exact matching for '%s'. ",
                "%d possible fields were found",
                name, size (pos, 1));
       for j = 1:(size (pos, 1))
@@ -279,38 +276,39 @@
 
   ## check if all has been done gives a valid OdePkg struct
   ode_struct_value_check (opt);
+
 endfunction
 
 ## function useful to print all the possible options
 function print_options ()
   
-  fprintf ("These following are all possible options.\n",
-           "Default values are put in square brackets.\n\n");
+  printf ("These following are all possible options.\n",
+          "Default values are put in square brackets.\n\n");
   
   disp ("             AbsTol:  scalar or vector, >0, [1.e-6]");
-  disp ("          Algorithm:  string, {[''gmres''], ''pcg'', ''bicgstab''}");
-  disp ("                BDF:  binary, {''on'', [''off'']}");
+  disp ("          Algorithm:  string, {['gmres'], 'pcg', 'bicgstab'}");
+  disp ("                BDF:  binary, {'on', ['off']}");
   disp ("             Choice:  switch, {[1], 2}");
   disp ("                Eta:  scalar, >=0, <1, [0.5]");
   disp ("             Events:  function_handle, []");
-  disp ("           Explicit:  binary, {''yes'', [''no'']}");
-  disp ("      InexactSolver:  string, {''inexact_newton'', ''fsolve'', []}");
+  disp ("           Explicit:  binary, {'yes', ['no']}");
+  disp ("      InexactSolver:  string, {'inexact_newton', 'fsolve', []}");
   disp ("       InitialSlope:  vector, []");
   disp ("        InitialStep:  scalar, >0, []");
   disp ("           Jacobian:  matrix or function_handle, []");
-  disp ("          JConstant:  binary, {''on'', [''off'']}");
+  disp ("          JConstant:  binary, {'on', ['off']}");
   disp ("           JPattern:  sparse matrix, []");
   disp ("               Mass:  matrix or function_handle, []");
-  disp ("       MassConstant:  binary, {''on'', [''off'']}");
-  disp ("       MassSingular:  switch, {''yes'', [''maybe''], ''no''}");
+  disp ("       MassConstant:  binary, {'on', ['off']}");
+  disp ("       MassSingular:  switch, {'yes', ['maybe'], 'no'}");
   disp ("MaxNewtonIterations:  scalar, integer, >0, [1.e3]");
   disp ("           MaxOrder:  switch, {1, 2, 3, 4, [5]}");
   disp ("            MaxStep:  scalar, >0, []");
-  disp ("   MStateDependence:  switch, {''none'', [''weak''], ''strong''}");
+  disp ("   MStateDependence:  switch, {'none', ['weak'], 'strong'}");
   disp ("          MvPattern:  sparse matrix, []");
   disp ("          NewtonTol:  scalar or vector, >0, []");
   disp ("        NonNegative:  vector of integers, []");
-  disp ("        NormControl:  binary, {''on'', [''off'']}");
+  disp ("        NormControl:  binary, {'on', ['off']}");
   disp ("          OutputFcn:  function_handle, []");
   disp ("         OutputSave:  scalar, integer, >0, []");
   disp ("          OutputSel:  scalar or vector, []");
@@ -319,30 +317,14 @@
   disp ("             Refine:  scalar, integer, >0, []");
   disp ("             RelTol:  scalar, >0, [1.e-3]");
   disp ("            Restart:  scalar, integer, >0, [20]");
-  disp ("              Stats:  binary, {''on'', [''off'']}");
+  disp ("              Stats:  binary, {'on', ['off']}");
   disp ("     TimeStepNumber:  scalar, integer, >0, []");
   disp ("       TimeStepSize:  scalar, >0, []");
-  disp ("        UseJacobian:  binary, {''yes'', [''no'']}");
-  disp ("         Vectorized:  binary, {''on'', [''off'']}");
+  disp ("        UseJacobian:  binary, {'yes', ['no']}");
+  disp ("         Vectorized:  binary, {'on', ['off']}");
 
 endfunction
 
-## All tests that are needed to check if a correct resp. valid option
-## has been set are implemented in ode_struct_value_check.m.
-%! ## Turn off output of warning messages for all tests, turn them on
-%! ## again if the last test is called
-%!  warning ('off', 'OdePkg:InvalidArgument');
-%!test odeoptA = odeset ();
-%!test odeoptB = odeset ('AbsTol', 1e-2, 'RelTol', 1e-1);
-%!     if (odeoptB.AbsTol != 1e-2), error; endif
-%!     if (odeoptB.RelTol != 1e-1), error; endif
-%!test odeoptB = odeset ('AbsTol', 1e-2, 'RelTol', 1e-1);
-%!     odeoptC = odeset (odeoptB, 'NormControl', 'on');
-%!test odeoptB = odeset ('AbsTol', 1e-2, 'RelTol', 1e-1);
-%!     odeoptC = odeset (odeoptB, 'NormControl', 'on');
-%!     odeoptD = odeset (odeoptC, odeoptB);
-%!
-%!  warning ('on', 'OdePkg:InvalidArgument');
 
 %!demo
 %! # A new OdePkg options structure with default values is created.
@@ -353,15 +335,29 @@
 %! # A new OdePkg options structure with manually set options 
 %! # "AbsTol" and "RelTol" is created.
 %!
-%! odeoptB = odeset ('AbsTol', 1e-2, 'RelTol', 1e-1);
+%! odeoptB = odeset ("AbsTol", 1e-2, "RelTol", 1e-1);
 %!
 %!demo
 %! # A new OdePkg options structure from odeoptB is created with
 %! # a modified value for option "NormControl".
 %!
-%! odeoptB = odeset ('AbsTol', 1e-2, 'RelTol', 1e-1);
-%! odeoptC = odeset (odeoptB, 'NormControl', 'on');
+%! odeoptB = odeset ("AbsTol", 1e-2, "RelTol", 1e-1);
+%! odeoptC = odeset (odeoptB, "NormControl", "on");
 
-## Local Variables: ***
-## mode: octave ***
-## End: ***
+## All tests that are needed to check if a correct resp. valid option
+## has been set are implemented in ode_struct_value_check.m.
+%! ## Turn off output of warning messages for all tests, turn them on
+%! ## again if the last test is called
+%!  warning ("off", "OdePkg:InvalidArgument");
+%!test odeoptA = odeset ();
+%!test odeoptB = odeset ("AbsTol", 1e-2, "RelTol", 1e-1);
+%!     if (odeoptB.AbsTol != 1e-2), error; endif
+%!     if (odeoptB.RelTol != 1e-1), error; endif
+%!test odeoptB = odeset ("AbsTol", 1e-2, "RelTol", 1e-1);
+%!     odeoptC = odeset (odeoptB, "NormControl", "on");
+%!test odeoptB = odeset ("AbsTol", 1e-2, "RelTol", 1e-1);
+%!     odeoptC = odeset (odeoptB, "NormControl", "on");
+%!     odeoptD = odeset (odeoptC, odeoptB);
+%!
+%!  warning ("on", "OdePkg:InvalidArgument");
+