comparison scripts/ode/private/ode_struct_value_check.m @ 20584:eb9e2d187ed2

maint: Use Octave coding conventions in scripts/ode/private dir. * AbsRel_Norm.m, fuzzy_compare.m, hermite_quartic_interpolation.m, integrate_adaptive.m, integrate_const.m, integrate_n_steps.m, kahan.m, ode_struct_value_check.m, odepkg_event_handle.m, odepkg_structure_check.m, runge_kutta_45_dorpri.m, starting_stepsize.m: Wrap long lines to < 80 chars. Use double quotes rather than single quotes where possible. Use ';' at end of keywords "return;" and "break;" Use '##" for stand-alone comments and '#' for end-of-line comments. Use two spaces after period before starting new sentence. Use '!' instead of '~' for logical negation. Use specific form of end (endif, endfor, etc.). Don't use line continuation marker '...' unless necessary.
author Rik <rik@octave.org>
date Sun, 04 Oct 2015 22:18:54 -0700
parents 25623ef2ff4f
children b7ac1e94266e
comparison
equal deleted inserted replaced
20583:d746695bf494 20584:eb9e2d187ed2
16 ## You should have received a copy of the GNU General Public License 16 ## You should have received a copy of the GNU General Public License
17 ## along with Octave; see the file COPYING. If not, see 17 ## along with Octave; see the file COPYING. If not, see
18 ## <http://www.gnu.org/licenses/>. 18 ## <http://www.gnu.org/licenses/>.
19 19
20 ## -*- texinfo -*- 20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {[@var{}] =} ode_struct_value_check (@var{arg}, [@var{"solver"}]) 21 ## @deftypefn {Function File} {} ode_struct_value_check (@var{arg})
22 ## @deftypefnx {Function File} {} ode_struct_value_check (@var{arg}, @var{"solver"})
22 ## 23 ##
23 ## If this function is called with one input argument of type structure array 24 ## If this function is called with one input argument of type structure array
24 ## then check the field names and the field values of the OdePkg structure 25 ## then check the field names and the field values of the OdePkg structure
25 ## @var{arg}. Optionally if this function is called with a second input 26 ## @var{arg}. Optionally if this function is called with a second input
26 ## argument @var{"solver"} of type string that specifies the name of a valid 27 ## argument @var{"solver"} of type string that specifies the name of a valid
55 endif 56 endif
56 57
57 fields = fieldnames (arg); 58 fields = fieldnames (arg);
58 fields_nb = length (fields); 59 fields_nb = length (fields);
59 60
60 for i = 1:1:fields_nb # Run through the number of given structure field names 61 for i = 1:fields_nb # Run through the number of given structure field names
61 switch (fields{i}) 62 switch (fields{i})
62 63
63 case "AbsTol" 64 case "AbsTol"
64 if (! isempty (arg.(fields{i}))) 65 if (! isempty (arg.(fields{i})))
65 if (! isnumeric (arg.(fields{i})) 66 if (! isnumeric (arg.(fields{i}))
66 || any (arg.(fields{i}) <= 0) 67 || any (arg.(fields{i}) <= 0)
67 || ~isreal (arg.(fields{i}))) 68 || ! isreal (arg.(fields{i})))
68 error ("OdePkg:InvalidArgument", 69 error ("OdePkg:InvalidArgument",
69 "value assigned to field %s is not a valid one", fields{i}); 70 "value assigned to field %s is not a valid one", fields{i});
70 elseif (! isvector (arg.(fields{i}))) 71 elseif (! isvector (arg.(fields{i})))
71 error ("OdePkg:InvalidArgument", 72 error ("OdePkg:InvalidArgument",
72 "value assigned to field %s is not a valid one", fields{i}); 73 "value assigned to field %s is not a valid one", fields{i});
103 "value assigned to field %s is not a valid one", fields{i}); 104 "value assigned to field %s is not a valid one", fields{i});
104 endif 105 endif
105 endif 106 endif
106 107
107 case "Eta" 108 case "Eta"
108 if ( ~isempty (arg.(fields{i})) ) 109 if ( ! isempty (arg.(fields{i})) )
109 if ( ~isreal (arg.(fields{i})) ) 110 if ( ! isreal (arg.(fields{i})) )
110 error ("OdePkg:InvalidArgument", ... 111 error ("OdePkg:InvalidArgument",
111 "value assigned to field %s is not a valid one", fields{i}); 112 "value assigned to field %s is not a valid one", fields{i});
112 elseif ( arg.(fields{i})<0 || arg.(fields{i})>=1 ) 113 elseif ( arg.(fields{i})<0 || arg.(fields{i})>=1 )
113 error ("OdePkg:InvalidArgument", ... 114 error ("OdePkg:InvalidArgument",
114 "value assigned to field %s is not a valid one", fields{i}); 115 "value assigned to field %s is not a valid one", fields{i});
115 endif 116 endif
116 endif 117 endif
117 118
118 case "Events" 119 case "Events"
119 if (! isempty (arg.(fields{i}))) 120 if (! isempty (arg.(fields{i})))
195 endif 196 endif
196 197
197 case "Mass" 198 case "Mass"
198 if (! isempty (arg.(fields{i}))) 199 if (! isempty (arg.(fields{i})))
199 if ((! isnumeric (arg.(fields{i})) 200 if ((! isnumeric (arg.(fields{i}))
200 || ~ismatrix (arg.(fields{i}))) 201 || ! ismatrix (arg.(fields{i})))
201 && ! isa (arg.(fields{i}), "function_handle")) 202 && ! isa (arg.(fields{i}), "function_handle"))
202 error ("OdePkg:InvalidArgument", 203 error ("OdePkg:InvalidArgument",
203 "value assigned to field %s is not a valid one", fields{i}); 204 "value assigned to field %s is not a valid one", fields{i});
204 endif 205 endif
205 endif 206 endif
393 || any (arg.(fields{i}) <= 0)) 394 || any (arg.(fields{i}) <= 0))
394 error ("OdePkg:InvalidArgument", 395 error ("OdePkg:InvalidArgument",
395 "value assigned to field %s is not a valid one", fields{i}); 396 "value assigned to field %s is not a valid one", fields{i});
396 endif 397 endif
397 endif 398 endif
398 switch (solver) 399 if (any (strcmp (solver, {"ode23", "ode23d", "ode45", "ode45d",
399 case {"ode23", "ode23d", "ode45", "ode45d", 400 "ode54", "ode54d", "ode78", "ode78d"})))
400 "ode54", "ode54d", "ode78", "ode78d"} 401 if (! isempty (arg.(fields{i})) && ! isscalar (arg.(fields{i})))
401 if (! isempty (arg.(fields{i}))) 402 error ("OdePkg:InvalidArgument",
402 if (! isscalar (arg.(fields{i}))) 403 "for this type of solver, value assigned to field %s ",
403 error ("OdePkg:InvalidArgument", 404 "is not a valid one", fields{i});
404 "for this type of solver, value assigned to field %s ", 405 endif
405 "is not a valid one", fields{i}); 406 endif
406 endif
407 endif
408 otherwise
409 endswitch
410 407
411 case "Restart" 408 case "Restart"
412 if (! isempty (arg.(fields{i}))) 409 if (! isempty (arg.(fields{i})))
413 if (! isnumeric (arg.(fields{i}))) 410 if (! isnumeric (arg.(fields{i})))
414 error ("OdePkg:InvalidArgument", 411 error ("OdePkg:InvalidArgument",
470 "no fields with name %s in ODE options.", fields{i}); 467 "no fields with name %s in ODE options.", fields{i});
471 endswitch 468 endswitch
472 endfor 469 endfor
473 470
474 endfunction 471 endfunction
472
475 473
476 %!demo 474 %!demo
477 %! # Return the checked OdePkg options structure that is created by 475 %! # Return the checked OdePkg options structure that is created by
478 %! # the command odeset. 476 %! # the command odeset.
479 %! 477 %!
480 %! ode_struct_value_check (odeset); 478 %! ode_struct_value_check (odeset);
481 %! 479 %!
482 %!demo 480 %!demo
483 %! # Create the OdePkg options structure A with odeset and check it 481 %! # Create the OdePkg options structure A with odeset and check it
484 %! # with odepkg_structure_check. This actually is unnecessary 482 %! # with odepkg_structure_check. This actually is unnecessary
485 %! # because odeset automtically calls odepkg_structure_check before 483 %! # because odeset automtically calls odepkg_structure_check before
486 %! # returning. 484 %! # returning.
487 %! 485 %!
488 %! A = odeset (); ode_struct_value_check (A); 486 %! A = odeset (); ode_struct_value_check (A);
489 487
490 ## Local Variables: ***
491 ## mode: octave ***
492 ## End: ***