/usr/share/octave/packages/odepkg-0.8.5/odepkg_structure_check.m is in octave-odepkg 0.8.5-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | %# Copyright (C) 2006-2012, Thomas Treichl <treichl@users.sourceforge.net>
%# OdePkg - A package for solving ordinary differential equations and more
%#
%# 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.
%#
%# 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.
%#
%# You should have received a copy of the GNU General Public License
%# along with this program; If not, see <http://www.gnu.org/licenses/>.
%# -*- texinfo -*-
%# @deftypefn {Function File} {[@var{newstruct}] =} odepkg_structure_check (@var{oldstruct}, [@var{"solver"}])
%#
%# If this function is called with one input argument of type structure array then check the field names and the field values of the OdePkg structure @var{oldstruct} and return the structure as @var{newstruct} if no error is found. Optionally if this function is called with a second input argument @var{"solver"} of type string taht specifies the name of a valid OdePkg solver then a higher level error detection is performed. The function does not modify any of the field names or field values but terminates with an error if an invalid option or value is found.
%#
%# This function is an OdePkg internal helper function therefore it should never be necessary that this function is called directly by a user. There is only little error detection implemented in this function file to achieve the highest performance.
%#
%# Run examples with the command
%# @example
%# demo odepkg_structure_check
%# @end example
%# @end deftypefn
%#
%# @seealso{odepkg}
function [vret] = odepkg_structure_check (varargin)
%# Check the number of input arguments
if (nargin == 0)
help ('odepkg_structure_check');
error ('OdePkg:InvalidArgument', ...
'Number of input arguments must be greater than zero');
elseif (nargin > 2)
print_usage;
elseif (nargin == 1 && isstruct (varargin{1}))
vret = varargin{1};
vsol = '';
vfld = fieldnames (vret);
vlen = length (vfld);
elseif (nargin == 2 && isstruct (varargin{1}) && ischar (varargin{2}))
vret = varargin{1};
vsol = varargin{2};
vfld = fieldnames (vret);
vlen = length (vfld);
end
for vcntarg = 1:vlen %# Run through the number of given structure field names
switch (vfld{vcntarg})
case 'RelTol'
if (isnumeric (vret.(vfld{vcntarg})) && ...
isreal (vret.(vfld{vcntarg})) && ...
all (vret.(vfld{vcntarg}) > 0)) %# 'all' is a MatLab need
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
switch (vsol)
case {'ode23', 'ode45', 'ode54', 'ode78', ...
'ode23d', 'ode45d', 'ode54d', 'ode78d',}
if (~isscalar (vret.(vfld{vcntarg})) && ...
~isempty (vret.(vfld{vcntarg})))
error ('OdePkg:InvalidParameter', ...
'Value of option "RelTol" must be a scalar');
end
otherwise
end
case 'AbsTol'
if (isnumeric (vret.(vfld{vcntarg})) && ...
isreal (vret.(vfld{vcntarg})) && ...
all (vret.(vfld{vcntarg}) > 0))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'NormControl'
if (strcmp (vret.(vfld{vcntarg}), 'on') || ...
strcmp (vret.(vfld{vcntarg}), 'off'))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'NonNegative'
if (isempty (vret.(vfld{vcntarg})) || ...
(isnumeric (vret.(vfld{vcntarg})) && isvector (vret.(vfld{vcntarg}))))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'OutputFcn'
if (isempty (vret.(vfld{vcntarg})) || ...
isa (vret.(vfld{vcntarg}), 'function_handle'))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'OutputSel'
if (isempty (vret.(vfld{vcntarg})) || ...
(isnumeric (vret.(vfld{vcntarg})) && isvector (vret.(vfld{vcntarg}))) || ...
isscalar (vret.(vfld{vcntarg})))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'OutputSave'
if (isempty (vret.(vfld{vcntarg})) || ...
(isscalar (vret.(vfld{vcntarg})) && ...
mod (vret.(vfld{vcntarg}), 1) == 0 && ...
vret.(vfld{vcntarg}) > 0) || ...
vret.(vfld{vcntarg}) == Inf)
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'Refine'
if (isscalar (vret.(vfld{vcntarg})) && ...
mod (vret.(vfld{vcntarg}), 1) == 0 && ...
vret.(vfld{vcntarg}) >= 0 && ...
vret.(vfld{vcntarg}) <= 5)
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'Stats'
if (strcmp (vret.(vfld{vcntarg}), 'on') || ...
strcmp (vret.(vfld{vcntarg}), 'off'))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'InitialStep'
if (isempty (vret.(vfld{vcntarg})) || ...
(isscalar (vret.(vfld{vcntarg})) && ...
isreal (vret.(vfld{vcntarg}))))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'MaxStep'
if (isempty (vret.(vfld{vcntarg})) || ...
(isscalar (vret.(vfld{vcntarg})) && ...
vret.(vfld{vcntarg}) > 0) )
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'Events'
if (isempty (vret.(vfld{vcntarg})) || ...
isa (vret.(vfld{vcntarg}), 'function_handle'))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'Jacobian'
if (isempty (vret.(vfld{vcntarg})) || ...
isnumeric (vret.(vfld{vcntarg})) || ...
isa (vret.(vfld{vcntarg}), 'function_handle') || ...
iscell (vret.(vfld{vcntarg})))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'JPattern'
if (isempty (vret.(vfld{vcntarg})) || ...
isvector (vret.(vfld{vcntarg})) || ...
isnumeric (vret.(vfld{vcntarg})))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'Vectorized'
if (strcmp (vret.(vfld{vcntarg}), 'on') || ...
strcmp (vret.(vfld{vcntarg}), 'off'))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'Mass'
if (isempty (vret.(vfld{vcntarg})) || ...
isnumeric (vret.(vfld{vcntarg})) || ...
isa (vret.(vfld{vcntarg}), 'function_handle'))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'MStateDependence'
if (strcmp (vret.(vfld{vcntarg}), 'none') || ...
strcmp (vret.(vfld{vcntarg}), 'weak') || ...
strcmp (vret.(vfld{vcntarg}), 'strong'))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'MvPattern'
if (isempty (vret.(vfld{vcntarg})) || ...
isvector (vret.(vfld{vcntarg})) || ...
isnumeric (vret.(vfld{vcntarg})))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'MassSingular'
if (strcmp (vret.(vfld{vcntarg}), 'yes') || ...
strcmp (vret.(vfld{vcntarg}), 'no') || ...
strcmp (vret.(vfld{vcntarg}), 'maybe'))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'InitialSlope'
if (isempty (vret.(vfld{vcntarg})) || ...
isvector (vret.(vfld{vcntarg})))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'MaxOrder'
if (isempty (vret.(vfld{vcntarg})) || ...
(mod (vret.(vfld{vcntarg}), 1) == 0 && ...
vret.(vfld{vcntarg}) > 0 && ...
vret.(vfld{vcntarg}) < 8))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'BDF'
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', ...
vfld{vcntarg});
end
case 'NewtonTol'
if (isnumeric (vret.(vfld{vcntarg})) && ...
isreal (vret.(vfld{vcntarg})) && ...
all (vret.(vfld{vcntarg}) > 0)) %# 'all' is a MatLab need
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
case 'MaxNewtonIterations'
if (isempty (vret.(vfld{vcntarg})) || ...
(mod (vret.(vfld{vcntarg}), 1) == 0 && ...
vret.(vfld{vcntarg}) > 0))
else
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s" or no valid parameter value', ...
vfld{vcntarg});
end
otherwise
error ('OdePkg:InvalidParameter', ...
'Unknown parameter name "%s"', ...
vfld{vcntarg});
end %# switch
end %# for
%# The following line can be uncommented for a even higher level error
%# detection
%# if (vlen ~= 21)
%# vmsg = sprintf ('Number of fields in structure must match 21');
%# error (vmsg);
%# end
%!test A = odeset ('RelTol', 1e-4);
%!test A = odeset ('RelTol', [1e-4, 1e-3]);
%!test A = odeset ('RelTol', []);
%!error A = odeset ('RelTol', '1e-4');
%!test A = odeset ('AbsTol', 1e-4);
%!test A = odeset ('AbsTol', [1e-4, 1e-3]);
%!test A = odeset ('AbsTol', []);
%!error A = odeset ('AbsTol', '1e-4');
%!test A = odeset ('NormControl', 'on');
%!test A = odeset ('NormControl', 'off');
%!error A = odeset ('NormControl', []);
%!error A = odeset ('NormControl', '12');
%!test A = odeset ('NonNegative', 1);
%!test A = odeset ('NonNegative', [1, 2, 3]);
%!test A = odeset ('NonNegative', []);
%!error A = odeset ('NonNegative', '12');
%!test A = odeset ('OutputFcn', @odeprint);
%!test A = odeset ('OutputFcn', @odeplot);
%!test A = odeset ('OutputFcn', []);
%!error A = odeset ('OutputFcn', 'odeprint');
%!test A = odeset ('OutputSel', 1);
%!test A = odeset ('OutputSel', [1, 2, 3]);
%!test A = odeset ('OutputSel', []);
%!error A = odeset ('OutputSel', '12');
%!test A = odeset ('Refine', 3);
%!error A = odeset ('Refine', [1, 2, 3]);
%!error A = odeset ('Refine', []);
%!error A = odeset ('Refine', 6);
%!test A = odeset ('Stats', 'on');
%!test A = odeset ('Stats', 'off');
%!error A = odeset ('Stats', []);
%!error A = odeset ('Stats', '12');
%!test A = odeset ('InitialStep', 3);
%!error A = odeset ('InitialStep', [1, 2, 3]);
%!test A = odeset ('InitialStep', []);
%!test A = odeset ('InitialStep', 6);
%!test A = odeset ('MaxStep', 3);
%!error A = odeset ('MaxStep', [1, 2, 3]);
%!test A = odeset ('MaxStep', []);
%!test A = odeset ('MaxStep', 6);
%!test A = odeset ('Events', @demo);
%!error A = odeset ('Events', 'off');
%!test A = odeset ('Events', []);
%!error A = odeset ('Events', '12');
%!test A = odeset ('Jacobian', @demo);
%!test A = odeset ('Jacobian', [1, 2; 3, 4]);
%!test A = odeset ('Jacobian', []);
%!error A = odeset ('Jacobian', '12');
%!test A = odeset ('JPattern', []);
%!test A = odeset ('JPattern', [1, 2, 4]);
%!test A = odeset ('JPattern', [1, 2; 3, 4]);
%!test A = odeset ('JPattern', 1);
%!test A = odeset ('Vectorized', 'on');
%!test A = odeset ('Vectorized', 'off');
%!error A = odeset ('Vectorized', []);
%!error A = odeset ('Vectorized', '12');
%!test A = odeset ('Mass', @demo);
%!test A = odeset ('Mass', [1, 2; 3, 4]);
%!test A = odeset ('Mass', []);
%!error A = odeset ('Mass', '12');
%!test A = odeset ('MStateDependence', 'none');
%!test A = odeset ('MStateDependence', 'weak');
%!test A = odeset ('MStateDependence', 'strong');
%!error A = odeset ('MStateDependence', [1, 2; 3, 4]);
%!error A = odeset ('MStateDependence', []);
%!error A = odeset ('MStateDependence', '12');
%!test A = odeset ('MvPattern', []);
%!test A = odeset ('MvPattern', [1, 2, 3 ]);
%!test A = odeset ('MvPattern', [1, 2; 3, 4]);
%!test A = odeset ('MvPattern', 1);
%!test A = odeset ('MassSingular', 'yes');
%!test A = odeset ('MassSingular', 'no');
%!test A = odeset ('MassSingular', 'maybe');
%!error A = odeset ('MassSingular', [1, 2; 3, 4]);
%!error A = odeset ('MassSingular', []);
%!error A = odeset ('MassSingular', '12');
%!test A = odeset ('InitialSlope', [1, 2, 3]);
%!test A = odeset ('InitialSlope', 1);
%!test A = odeset ('InitialSlope', []);
%!test A = odeset ('InitialSlope', '12');
%!test A = odeset ('MaxOrder', 3);
%!error A = odeset ('MaxOrder', 3.5);
%!test A = odeset ('MaxOrder', [1, 2; 3, 4]);
%!test A = odeset ('MaxOrder', []);
%!test A = odeset ('BDF', 'on');
%!test A = odeset ('BDF', 'off');
%!test A = odeset ('BDF', []);
%!error A = odeset ('BDF', [1, 2; 3, 4]);
%!test A = odeset ('NewtonTol', []);
%!test A = odeset ('NewtonTol', 1e-3);
%!test A = odeset ('NewtonTol', [1e-3, 1e-3, 1e-3]);
%!error A = odeset ('NewtonTol', 'string');
%!test A = odeset ('MaxNewtonIterations', []);
%!test A = odeset ('MaxNewtonIterations', 2);
%!error A = odeset ('MaxNewtonIterations', 'string');
%!demo
%! # Return the checked OdePkg options structure that is created by
%! # the command odeset.
%!
%! odepkg_structure_check (odeset);
%!
%!demo
%! # Create the OdePkg options structure A with odeset and check it
%! # with odepkg_structure_check. This actually is unnecessary
%! # because odeset automtically calls odepkg_structure_check before
%! # returning.
%!
%! A = odeset (); odepkg_structure_check (A);
%# Local Variables: ***
%# mode: octave ***
%# End: ***
|