comparison scripts/ode/odeget.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
comparison
equal deleted inserted replaced
20580:25623ef2ff4f 20581:e368ce72a844
26 ## 26 ##
27 ## If this function is called with two input arguments and the first input 27 ## If this function is called with two input arguments and the first input
28 ## argument @var{ode_opt} is of type structure array and the second input 28 ## argument @var{ode_opt} is of type structure array and the second input
29 ## argument @var{field} is of type string then return the option value 29 ## argument @var{field} is of type string then return the option value
30 ## @var{res} that is specified by the option name @var{field} in the ODE 30 ## @var{res} that is specified by the option name @var{field} in the ODE
31 ## option structure @var{ode_opt}. Optionally if this function is called 31 ## option structure @var{ode_opt}.
32 ## with a third input argument then return the default value @var{default} if 32 ##
33 ## @var{field} is not set in the structure @var{ode_opt}. 33 ## Optionally if this function is called with a third input argument then
34 ## return the default value @var{default} if @var{field} is not set in the
35 ## structure @var{ode_opt}.
34 ## @seealso{odeset} 36 ## @seealso{odeset}
35 ## @end deftypefn 37 ## @end deftypefn
36 38
37 ## Note: 2006-10-22, Thomas Treichl 39 ## Note: 2006-10-22, Thomas Treichl
38 ## We cannot create a function of the form odeget (@var{odestruct}, 40 ## We cannot create a function of the form odeget (@var{odestruct},
109 pos = fuzzy_compare (field, options); 111 pos = fuzzy_compare (field, options);
110 112
111 if (size (pos, 1) == 0) # no matching for the given option 113 if (size (pos, 1) == 0) # no matching for the given option
112 if (nargin == 2) 114 if (nargin == 2)
113 error ("OdePkg:InvalidArgument", 115 error ("OdePkg:InvalidArgument",
114 "invalid property. No property found with name ''%s''.", field); 116 "invalid property. No property found with name '%s'.", field);
115 endif 117 endif
116 warning ("odeget:NoExactMatching", 118 warning ("odeget:NoExactMatching",
117 "no property found with name ''%s''. ", 119 "no property found with name '%s'. ",
118 "Assuming default value.", field); 120 "Assuming default value.", field);
119 res = default; 121 res = default;
120 return 122 return
121 endif 123 endif
122 124
123 if (size (pos, 1) == 1) # one matching 125 if (size (pos, 1) == 1) # one matching
124 if (! strcmp (lower (deblank (field)), 126 if (! strcmp (lower (deblank (field)),
125 lower (deblank (options(pos,:)))) ) 127 lower (deblank (options(pos,:)))) )
126 warning ("OdePkg:InvalidArgument", 128 warning ("OdePkg:InvalidArgument",
127 "no exact matching for ''%s''. ", 129 "no exact matching for '%s'. ",
128 "Assuming you was intending ''%s''.", 130 "Assuming you was intending '%s'.",
129 field, deblank (options(pos,:))); 131 field, deblank (options(pos,:)));
130 endif 132 endif
131 res = ode_opt.(deblank (options(pos,:))); 133 res = ode_opt.(deblank (options(pos,:)));
132 if (isempty (res)) 134 if (isempty (res))
133 res = default; 135 res = default;
136 return 138 return
137 endif 139 endif
138 140
139 ## if there are more matching, ask the user to be more precise 141 ## if there are more matching, ask the user to be more precise
140 warning ("OdePkg:InvalidArgument", ... 142 warning ("OdePkg:InvalidArgument", ...
141 "no exact matching for ''%s''. %d possible fields were found.", 143 "no exact matching for '%s'. %d possible fields were found.",
142 field, size (pos, 1)); 144 field, size (pos, 1));
143 for j = 1:(size (pos, 1)) 145 for j = 1:(size (pos, 1))
144 fprintf ("%s\n", deblank (options(pos(j),:))); 146 fprintf ("%s\n", deblank (options(pos(j),:)));
145 endfor 147 endfor
146 do 148 do
149 until (ischar (field)) 151 until (ischar (field))
150 endwhile 152 endwhile
151 153
152 endfunction 154 endfunction
153 155
154 %! ## Turn off output of warning messages for all tests, turn them on
155 %! ## again if the last test is called
156 %! warning ('off', 'OdePkg:InvalidArgument');
157 %!test assert (odeget (odeset (), 'RelTol'), []);
158 %!test assert (odeget (odeset (), 'RelTol', 10), 10);
159 %!test assert (odeget (odeset (), 'Stats'), []);
160 %!test assert (odeget (odeset (), 'Stats', 'on'), 'on');
161 %!test assert (odeget (odeset (), 'AbsTol', 1.e-6, 'fast'), []);
162 %!test assert (odeget (odeset (), 'AbsTol', 1.e-6, 'fast_not_empty'), 1.e-6);
163 %!test assert (odeget (odeset (), 'AbsTol', 1e-9), 1e-9);
164 %!
165 %! warning ('on', 'OdePkg:InvalidArgument');
166 156
167 %!demo 157 %!demo
168 %! # Return the manually changed value RelTol of the OdePkg options 158 %! # Return the manually changed value RelTol of the OdePkg options
169 %! # strutcure A. If RelTol wouldn't have been changed then an 159 %! # strutcure A. If RelTol wouldn't have been changed then an
170 %! # empty matrix value would have been returned. 160 %! # empty matrix value would have been returned.
171 %! 161 %!
172 %! A = odeset ('RelTol', 1e-1, 'AbsTol', 1e-2); 162 %! A = odeset ("RelTol", 1e-1, "AbsTol", 1e-2);
173 %! odeget (A, 'RelTol', []) 163 %! odeget (A, "RelTol", [])
174 164
175 ## Local Variables: *** 165 %! ## Turn off output of warning messages for all tests, turn them on
176 ## mode: octave *** 166 %! ## again if the last test is called
177 ## End: *** 167 %! warning ("off", "OdePkg:InvalidArgument");
168 %!test assert (odeget (odeset (), "RelTol"), []);
169 %!test assert (odeget (odeset (), "RelTol", 10), 10);
170 %!test assert (odeget (odeset (), "Stats"), []);
171 %!test assert (odeget (odeset (), "Stats", "on"), "on");
172 %!test assert (odeget (odeset (), "AbsTol", 1.e-6, "fast"), []);
173 %!test assert (odeget (odeset (), "AbsTol", 1.e-6, "fast_not_empty"), 1.e-6);
174 %!test assert (odeget (odeset (), "AbsTol", 1e-9), 1e-9);
175 %!
176 %! warning ("on", "OdePkg:InvalidArgument");
177