# HG changeset patch # User Rik # Date 1444071796 25200 # Node ID b7ac1e94266ecc1902f072c09e18846b06e557e5 # Parent 45151de7423f4bfbd14ba9d6f73ad432f5ee28c9 maint: Further clean up of functions in ode/private dir. * AbsRel_Norm.m, fuzzy_compare.m, integrate_adaptive.m, integrate_const.m, integrate_n_steps.m, ode_struct_value_check.m, odepkg_event_handle.m, odepkg_structure_check.m, runge_kutta_45_dorpri.m: Place latest copyright first in file. Use two spaces before beginning single-line comment. Use parentheses around variable to be tested in switch stmt. Use space between function name and opening parenthesis. diff -r 45151de7423f -r b7ac1e94266e scripts/ode/private/AbsRel_Norm.m --- a/scripts/ode/private/AbsRel_Norm.m Mon Oct 05 11:59:18 2015 -0700 +++ b/scripts/ode/private/AbsRel_Norm.m Mon Oct 05 12:03:16 2015 -0700 @@ -1,5 +1,5 @@ +## Copyright (C) 2014, Jacopo Corno ## Copyright (C) 2013, Roberto Porcu' -## Copyright (C) 2014, Jacopo Corno ## ## This file is part of Octave. ## diff -r 45151de7423f -r b7ac1e94266e scripts/ode/private/fuzzy_compare.m --- a/scripts/ode/private/fuzzy_compare.m Mon Oct 05 11:59:18 2015 -0700 +++ b/scripts/ode/private/fuzzy_compare.m Mon Oct 05 12:03:16 2015 -0700 @@ -121,7 +121,7 @@ positions = find (values == minimus); - if (minimus == 0) # exact match + if (minimus == 0) # exact match if (rows (positions) != 1) error ("OdePkg:InvalidArgument", "there are %d strings perfectly matching '%s'", diff -r 45151de7423f -r b7ac1e94266e scripts/ode/private/integrate_adaptive.m --- a/scripts/ode/private/integrate_adaptive.m Mon Oct 05 11:59:18 2015 -0700 +++ b/scripts/ode/private/integrate_adaptive.m Mon Oct 05 12:03:16 2015 -0700 @@ -182,7 +182,7 @@ while ((counter <= k) && (vdirection * z(i) > vdirection * tspan(counter))) ## choose interpolation scheme according to order of the solver - switch order + switch (order) case 1 u_interp = linear_interpolation ([z(i-1) z(i)], [u(:,i-1) u(:,i)], @@ -286,8 +286,8 @@ ## code fragment has moved here. Stop integration if plot function ## returns false if (options.vhaveoutputfunction) - for vcnt = 0:options.Refine # Approximation between told and t - if (options.vhaverefine) # Do interpolation + for vcnt = 0:options.Refine # Approximation between told and t + if (options.vhaverefine) # Do interpolation vapproxtime = (vcnt + 1) / (options.Refine + 2); vapproxvals = (1 - vapproxtime) * vSaveVUForRefine ... + (vapproxtime) * y(:,end); @@ -301,11 +301,11 @@ endif vpltret = feval (options.OutputFcn, vapproxtime, vapproxvals, [], options.vfunarguments{:}); - if (vpltret) # Leave refinement loop + if (vpltret) # Leave refinement loop break; endif endfor - if (vpltret) # Leave main loop + if (vpltret) # Leave main loop solution.vunhandledtermination = false; break; endif @@ -340,8 +340,8 @@ dt = vdirection * min (abs (dt), options.MaxStep); ## Update counters that count the number of iteration cycles - solution.vcntcycles += 1; # Needed for cost statistics - vcntiter += 1; # Needed to find iteration problems + solution.vcntcycles += 1; # Needed for cost statistics + vcntiter += 1; # Needed to find iteration problems ## Stop solving because in the last 1000 steps no successful valid ## value has been found diff -r 45151de7423f -r b7ac1e94266e scripts/ode/private/integrate_const.m --- a/scripts/ode/private/integrate_const.m Mon Oct 05 11:59:18 2015 -0700 +++ b/scripts/ode/private/integrate_const.m Mon Oct 05 12:03:16 2015 -0700 @@ -136,7 +136,7 @@ ## if next tspan value is caught, update counter if ((z(end) == tspan(counter)) || (abs (z(end) - tspan(counter)) / - (max(abs (z(end)), abs(tspan(counter)))) < 8*eps) ) + (max (abs (z(end)), abs (tspan(counter)))) < 8*eps) ) counter++; ## if there is an element in time vector at which the solution is required @@ -150,7 +150,7 @@ if ((counter <= k) && (((z(i) == tspan(counter)) || (abs (z(i) - tspan(counter)) / - (max(abs (z(i)), abs (tspan(counter)))) < 8*eps))) ) + (max (abs (z(i)), abs (tspan(counter)))) < 8*eps))) ) counter++; endif ## else, loop until there are requested values inside this subinterval @@ -232,8 +232,8 @@ endif ## Update counters that count the number of iteration cycles - solution.vcntcycles = solution.vcntcycles + 1; # Needed for cost statistics - vcntiter = vcntiter + 1; # Needed to find iteration problems + solution.vcntcycles = solution.vcntcycles + 1; # Needed for cost statistics + vcntiter = vcntiter + 1; # Needed to find iteration problems ## Stop solving because the last 1000 steps no successful valid ## value has been found diff -r 45151de7423f -r b7ac1e94266e scripts/ode/private/integrate_n_steps.m --- a/scripts/ode/private/integrate_n_steps.m Mon Oct 05 11:59:18 2015 -0700 +++ b/scripts/ode/private/integrate_n_steps.m Mon Oct 05 12:03:16 2015 -0700 @@ -140,8 +140,8 @@ ## Call plot only if a valid result has been found, therefore this code ## fragment has moved here. Stop integration if plot function returns false if (options.vhaveoutputfunction) - for vcnt = 0:options.Refine # Approximation between told and t - if (options.vhaverefine) # Do interpolation + for vcnt = 0:options.Refine # Approximation between told and t + if (options.vhaverefine) # Do interpolation vapproxtime = (vcnt + 1) / (options.Refine + 2); vapproxvals = (1 - vapproxtime) * vSaveVUForRefine ... + (vapproxtime) * y(:,end); @@ -155,11 +155,11 @@ endif vpltret = feval (options.OutputFcn, vapproxtime, vapproxvals, [], options.vfunarguments{:}); - if (vpltret) # Leave refinement loop + if (vpltret) # Leave refinement loop break; endif endfor - if (vpltret) # Leave main loop + if (vpltret) # Leave main loop solution.vunhandledtermination = false; break; endif @@ -181,8 +181,8 @@ endif ## Update counters that count the number of iteration cycles - solution.vcntcycles = solution.vcntcycles + 1; # Needed for cost statistics - vcntiter = vcntiter + 1; # Needed to find iteration problems + solution.vcntcycles = solution.vcntcycles + 1; # Needed for cost statistics + vcntiter = vcntiter + 1; # Needed to find iteration problems ## Stop solving because the last 1000 steps no successful valid ## value has been found diff -r 45151de7423f -r b7ac1e94266e scripts/ode/private/ode_struct_value_check.m --- a/scripts/ode/private/ode_struct_value_check.m Mon Oct 05 11:59:18 2015 -0700 +++ b/scripts/ode/private/ode_struct_value_check.m Mon Oct 05 12:03:16 2015 -0700 @@ -1,5 +1,5 @@ +## Copyright (C) 2013, Roberto Porcu' ## Copyright (C) 2006-2012, Thomas Treichl -## Copyright (C) 2013, Roberto Porcu' ## ## This file is part of Octave. ## @@ -177,7 +177,7 @@ endif case "JConstant" - if (! isempty(arg.(fields{i}))) + if (! isempty (arg.(fields{i}))) if (! strcmp (arg.(fields{i}), "on") && ! strcmp (arg.(fields{i}), "off")) error ("OdePkg:InvalidArgument", diff -r 45151de7423f -r b7ac1e94266e scripts/ode/private/odepkg_event_handle.m --- a/scripts/ode/private/odepkg_event_handle.m Mon Oct 05 11:59:18 2015 -0700 +++ b/scripts/ode/private/odepkg_event_handle.m Mon Oct 05 12:03:16 2015 -0700 @@ -84,7 +84,7 @@ vinpargs = {vevefun, vt, vy}; else vinpargs = {vevefun, vt, vy{1}, vy{2}}; - vy = vy{1}; # Delete cell element 2 + vy = vy{1}; # Delete cell element 2 endif if (nargin > 4) vinpargs = {vinpargs{:}, varargin{:}}; @@ -103,7 +103,7 @@ vinpargs = {vevefun, vt, vy}; else vinpargs = {vevefun, vt, vy{1}, vy{2}}; - vy = vy{1}; # Delete cell element 2 + vy = vy{1}; # Delete cell element 2 endif if (nargin > 4) vinpargs = {vinpargs{:}, varargin{:}}; @@ -115,8 +115,8 @@ ## Check if one or more signs of the event has changed vsignum = (sign (veveold) != sign (veve)); - if (any (vsignum)) # One or more values have changed - vindex = find (vsignum); # Get the index of the changed values + if (any (vsignum)) # One or more values have changed + vindex = find (vsignum); # Get the index of the changed values if (any (vdir(vindex) == 0)) ## Rising or falling (both are possible) @@ -132,8 +132,8 @@ ## Create new output values if a valid index has been found if (! isempty (vindex)) ## Change the persistent result cell array - vretcell{1} = any (vterm(vindex)); # Stop integration or not - vretcell{2}(vevecnt,1) = vindex(1,1); # Take first event found + vretcell{1} = any (vterm(vindex)); # Stop integration or not + vretcell{2}(vevecnt,1) = vindex(1,1); # Take first event found ## Calculate the time stamp when the event function returned 0 and ## calculate new values for the integration results, we do both by ## a linear interpolation diff -r 45151de7423f -r b7ac1e94266e scripts/ode/private/odepkg_structure_check.m --- a/scripts/ode/private/odepkg_structure_check.m Mon Oct 05 11:59:18 2015 -0700 +++ b/scripts/ode/private/odepkg_structure_check.m Mon Oct 05 12:03:16 2015 -0700 @@ -1,19 +1,21 @@ +## Copyright (C) 2013, Roberto Porcu' ## Copyright (C) 2006-2012, Thomas Treichl -## Copyright (C) 2013, Roberto Porcu' -## OdePkg - A package for solving ordinary differential equations and more +## +## This file is part of Octave. ## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. ## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. ## ## You should have received a copy of the GNU General Public License -## along with this program; If not, see . +## along with Octave; see the file COPYING. If not, see +## . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{newstruct} =} odepkg_structure_check (@var{oldstruct}) @@ -52,7 +54,7 @@ error ("OdePkg:InvalidArgument", "Number of input arguments must be greater than zero"); elseif (nargin > 2) - print_usage; + print_usage (); elseif (nargin == 1 && isstruct (varargin{1})) vret = varargin{1}; vsol = ""; @@ -329,7 +331,7 @@ ## new fields added case "Algorithm" - if ( isempty(vret.(vfld{vcntarg})) || ischar(vret.(vfld{vcntarg})) ) + if ( isempty (vret.(vfld{vcntarg})) || ischar (vret.(vfld{vcntarg})) ) else error ("OdePkg:InvalidParameter", 'Unknown parameter name "%s" or no valid parameter value', @@ -337,8 +339,8 @@ endif case "Choice" - if ( isempty(vret.(vfld{vcntarg})) - || (isnumeric(vret.(vfld{vcntarg})) && (vret.(vfld{vcntarg})==1) + if ( isempty (vret.(vfld{vcntarg})) + || (isnumeric (vret.(vfld{vcntarg})) && (vret.(vfld{vcntarg})==1) || vret.(vfld{vcntarg})==2 ) ) else error ("OdePkg:InvalidParameter", @@ -347,8 +349,8 @@ endif case "Eta" - if ( isempty(vret.(vfld{vcntarg})) - || ( isreal(vret.(vfld{vcntarg})) + if ( isempty (vret.(vfld{vcntarg})) + || ( isreal (vret.(vfld{vcntarg})) && vret.(vfld{vcntarg})>=0 && vret.(vfld{vcntarg})<1) ) else error ("OdePkg:InvalidParameter", @@ -357,10 +359,10 @@ endif case "Explicit" - if ( isempty(vret.(vfld{vcntarg})) - || (ischar(vret.(vfld{vcntarg})) - && (strcmp(vret.(vfld{vcntarg}),"yes") - || strcmp(vret.(vfld{vcntarg}),"no"))) ) + if ( isempty (vret.(vfld{vcntarg})) + || (ischar (vret.(vfld{vcntarg})) + && (strcmp (vret.(vfld{vcntarg}),"yes") + || strcmp (vret.(vfld{vcntarg}),"no"))) ) else error ("OdePkg:InvalidParameter", 'Unknown parameter name "%s" or no valid parameter value', @@ -368,7 +370,7 @@ endif case "InexactSolver" - if ( isempty(vret.(vfld{vcntarg})) || ischar(vret.(vfld{vcntarg})) ) + if ( isempty (vret.(vfld{vcntarg})) || ischar (vret.(vfld{vcntarg})) ) else error ("OdePkg:InvalidParameter", 'Unknown parameter name "%s" or no valid parameter value', @@ -376,11 +378,11 @@ endif case "InitialSlope" - if ( isempty(vret.(vfld{vcntarg})) - || ( ischar(vret.(vfld{vcntarg})) - || (isnumeric(vret.(vfld{vcntarg})) - && (isvector(vret.(vfld{vcntarg})) - || isreal(vret.(vfld{vcntarg}))))) ) + if ( isempty (vret.(vfld{vcntarg})) + || ( ischar (vret.(vfld{vcntarg})) + || (isnumeric (vret.(vfld{vcntarg})) + && (isvector (vret.(vfld{vcntarg})) + || isreal (vret.(vfld{vcntarg}))))) ) else error ("OdePkg:InvalidParameter", 'Unknown parameter name "%s" or no valid parameter value', @@ -388,10 +390,10 @@ endif case "JConstant" - if ( isempty(vret.(vfld{vcntarg})) - || (ischar(vret.(vfld{vcntarg})) - && (strcmp(vret.(vfld{vcntarg}),"yes") - || strcmp(vret.(vfld{vcntarg}),"no"))) ) + if ( isempty (vret.(vfld{vcntarg})) + || (ischar (vret.(vfld{vcntarg})) + && (strcmp (vret.(vfld{vcntarg}),"yes") + || strcmp (vret.(vfld{vcntarg}),"no"))) ) else error ("OdePkg:InvalidParameter", 'Unknown parameter name "%s" or no valid parameter value', @@ -399,9 +401,9 @@ endif case "MassConstant" - if ( isempty(vret.(vfld{vcntarg})) - || (strcmp(vret.(vfld{vcntarg}),"on") - || strcmp(vret.(vfld{vcntarg}),"off")) ) + if ( isempty (vret.(vfld{vcntarg})) + || (strcmp (vret.(vfld{vcntarg}),"on") + || strcmp (vret.(vfld{vcntarg}),"off")) ) else error ("OdePkg:InvalidParameter", 'Unknown parameter name "%s" or no valid parameter value', @@ -409,8 +411,8 @@ endif case "PolynomialDegree" - if ( isempty(vret.(vfld{vcntarg})) - || (isnumeric(vret.(vfld{vcntarg})) + if ( isempty (vret.(vfld{vcntarg})) + || (isnumeric (vret.(vfld{vcntarg})) && mod(vret.(vfld{vcntarg}),1)==0 && vret.(vfld{vcntarg})>0) ) else error ("OdePkg:InvalidParameter", @@ -419,8 +421,8 @@ endif case "QuadratureOrder" - if ( isempty(vret.(vfld{vcntarg})) - || (isnumeric(vret.(vfld{vcntarg})) + if ( isempty (vret.(vfld{vcntarg})) + || (isnumeric (vret.(vfld{vcntarg})) && mod(vret.(vfld{vcntarg}),1)==0 && vret.(vfld{vcntarg})>0) ) else error ("OdePkg:InvalidParameter", @@ -429,8 +431,8 @@ endif case "Restart" - if ( isempty(vret.(vfld{vcntarg})) - || (isnumeric(vret.(vfld{vcntarg})) + if ( isempty (vret.(vfld{vcntarg})) + || (isnumeric (vret.(vfld{vcntarg})) && mod(vret.(vfld{vcntarg}),1)==0 && vret.(vfld{vcntarg})>0) ) else error ("OdePkg:InvalidParameter", @@ -439,8 +441,8 @@ endif case "TimeStepNumber" - if ( isempty(vret.(vfld{vcntarg})) - || (isnumeric(vret.(vfld{vcntarg})) + if ( isempty (vret.(vfld{vcntarg})) + || (isnumeric (vret.(vfld{vcntarg})) && mod(vret.(vfld{vcntarg}),1)==0 && vret.(vfld{vcntarg})>0) ) else error ("OdePkg:InvalidParameter", @@ -449,8 +451,8 @@ endif case "TimeStepSize" - if ( isempty(vret.(vfld{vcntarg})) - || ( isreal(vret.(vfld{vcntarg})) && vret.(vfld{vcntarg})!=0) ) + if ( isempty (vret.(vfld{vcntarg})) + || ( isreal (vret.(vfld{vcntarg})) && vret.(vfld{vcntarg})!=0) ) else error ("OdePkg:InvalidParameter", 'Unknown parameter name "%s" or no valid parameter value', @@ -458,10 +460,10 @@ endif case "UseJacobian" - if ( isempty(vret.(vfld{vcntarg})) - || (ischar(vret.(vfld{vcntarg})) - && (strcmp(vret.(vfld{vcntarg}),"yes") - || strcmp(vret.(vfld{vcntarg}),"no"))) ) + if ( isempty (vret.(vfld{vcntarg})) + || (ischar (vret.(vfld{vcntarg})) + && (strcmp (vret.(vfld{vcntarg}),"yes") + || strcmp (vret.(vfld{vcntarg}),"no"))) ) else error ("OdePkg:InvalidParameter", 'Unknown parameter name "%s" or no valid parameter value', diff -r 45151de7423f -r b7ac1e94266e scripts/ode/private/runge_kutta_45_dorpri.m --- a/scripts/ode/private/runge_kutta_45_dorpri.m Mon Oct 05 11:59:18 2015 -0700 +++ b/scripts/ode/private/runge_kutta_45_dorpri.m Mon Oct 05 12:03:16 2015 -0700 @@ -1,5 +1,5 @@ +## Copyright (C) 2015, Carlo de Falco ## Copyright (C) 2013, Roberto Porcu' -## Copyright (C) 2015, Carlo de Falco ## ## This file is part of Octave. ## @@ -80,10 +80,10 @@ aa = dt * a; k = zeros (rows (x), 7); - if (nargin >= 5) # options are passed + if (nargin >= 5) # options are passed args = varargin{1}.vfunarguments; - if (nargin >= 6) # both the options and the k values are passed - k(:,1) = varargin{2}(:,end); # FSAL property + if (nargin >= 6) # both the options and the k values are passed + k(:,1) = varargin{2}(:,end); # FSAL property else k(:,1) = feval (f, t, x, args{:}); endif