comparison libinterp/corefcn/colloc.cc @ 20918:6f0bd96f93c0

maint: Use new C++ archetype in more files. Place input validation first in files. Move declaration of retval down in function to be closer to point of usage. Eliminate else clause after if () error. Use "return ovl()" where it makes sense. * __dispatch__.cc, __dsearchn__.cc, __ichol__.cc, __lin_interpn__.cc, balance.cc, betainc.cc, bitfcns.cc, bsxfun.cc, cellfun.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, debug.cc, dirfns.cc, dlmread.cc, dot.cc, eig.cc, error.cc, fft.cc, fft2.cc, fftn.cc, file-io.cc, ov-type-conv.h: Use new C++ archetype in more files.
author Rik <rik@octave.org>
date Wed, 16 Dec 2015 15:00:31 -0800
parents f1b2a2dbc0e1
children 48b2ad5ee801
comparison
equal deleted inserted replaced
20917:a7051a169cad 20918:6f0bd96f93c0
41 \n\ 41 \n\
42 Reference: @nospell{J. Villadsen}, @nospell{M. L. Michelsen},\n\ 42 Reference: @nospell{J. Villadsen}, @nospell{M. L. Michelsen},\n\
43 @cite{Solution of Differential Equation Models by Polynomial Approximation}.\n\ 43 @cite{Solution of Differential Equation Models by Polynomial Approximation}.\n\
44 @end deftypefn") 44 @end deftypefn")
45 { 45 {
46 octave_value_list retval;
47
48 int nargin = args.length (); 46 int nargin = args.length ();
49 47
50 if (nargin < 1 || nargin > 3) 48 if (nargin < 1 || nargin > 3)
51 print_usage (); 49 print_usage ();
52 50
53 if (! args(0).is_scalar_type ()) 51 if (! args(0).is_scalar_type ())
54 error ("colloc: N must be a scalar"); 52 error ("colloc: N must be a scalar");
55 53
56 double tmp = args(0).double_value (); 54 double tmp = args(0).double_value ();
57
58 if (xisnan (tmp)) 55 if (xisnan (tmp))
59 error ("colloc: N cannot be NaN"); 56 error ("colloc: N cannot be NaN");
60 57
61 octave_idx_type ncol = NINTbig (tmp); 58 octave_idx_type ncol = NINTbig (tmp);
62 if (ncol < 0) 59 if (ncol < 0)
68 65
69 for (int i = 1; i < nargin; i++) 66 for (int i = 1; i < nargin; i++)
70 { 67 {
71 std::string s = args(i).xstring_value ("colloc: optional arguments must be strings"); 68 std::string s = args(i).xstring_value ("colloc: optional arguments must be strings");
72 69
73 if ((s.length () == 1 && (s[0] == 'R' || s[0] == 'r')) 70 if ((s.length () == 1 && (s[0] == 'R' || s[0] == 'r')) || s == "right")
74 || s == "right") 71 right = 1;
75 {
76 right = 1;
77 }
78 else if ((s.length () == 1 && (s[0] == 'L' || s[0] == 'l')) 72 else if ((s.length () == 1 && (s[0] == 'L' || s[0] == 'l'))
79 || s == "left") 73 || s == "left")
80 { 74 left = 1;
81 left = 1;
82 }
83 else 75 else
84 error ("colloc: string argument must be \"left\" or \"right\""); 76 error ("colloc: string argument must be \"left\" or \"right\"");
85 } 77 }
86 78
87 ntot += left + right; 79 ntot += left + right;
93 ColumnVector r = wts.roots (); 85 ColumnVector r = wts.roots ();
94 Matrix A = wts.first (); 86 Matrix A = wts.first ();
95 Matrix B = wts.second (); 87 Matrix B = wts.second ();
96 ColumnVector q = wts.quad_weights (); 88 ColumnVector q = wts.quad_weights ();
97 89
98 retval = ovl (r, A, B, q); 90 return ovl (r, A, B, q);
91 }
99 92
100 return retval;
101 }