16
16
#include "localization.h"
17
17
#include "Scierror.h"
18
18
/*--------------------------------------------------------------------------*/
19
extern void C2F(dxlegf)(double *dnu1, int *nudiff, int *mu1, int *mu2,
20
double *x,int *id, double *pqa, int *ipqa, int *ierror);
19
extern void C2F(dxlegf)(double *dnu1, int *nudiff, int *mu1, int *mu2,
20
double *x, int *id, double *pqa, int *ipqa, int *ierror);
21
21
/*--------------------------------------------------------------------------*/
22
22
static double return_an_inf(void);
23
23
static int verify_cstr(double x[], int nb_elt, int *xmin, int *xmax);
24
24
/*--------------------------------------------------------------------------*/
25
int sci_legendre(char *fname,unsigned long fname_len)
25
int sci_legendre(char *fname, unsigned long fname_len)
28
28
* Interface onto the (Slatec) dxleg.f code.
50
50
double *x = NULL, xx = 0., dnu1 = 0., *pqa = NULL;
51
51
int id = 0, ierror = 0, i = 0, j = 0, nudiff = 0;
55
55
GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &mN, &nN, &lN);
57
if ( ! verify_cstr(stk(lN), mN*nN, &n1, &n2) )
57
if ( ! verify_cstr(stk(lN), mN * nN, &n1, &n2) )
59
Scierror(999,_("%s: Wrong type for first input argument.\n"), fname);
59
Scierror(999, _("%s: Wrong type for first input argument.\n"), fname);
63
63
if ( mN == 1 && nN == 1) N_is_scalar = 1;
65
GetRhsVar(2,MATRIX_OF_DOUBLE_DATATYPE, &mM, &nM, &lM);
66
if ( ! verify_cstr(stk(lM), mM*nM, &m1, &m2) )
65
GetRhsVar(2, MATRIX_OF_DOUBLE_DATATYPE, &mM, &nM, &lM);
66
if ( ! verify_cstr(stk(lM), mM * nM, &m1, &m2) )
68
Scierror(999,_("%s: Wrong type for input argument #%d.\n"), fname,2);
68
Scierror(999, _("%s: Wrong type for input argument #%d.\n"), fname, 2);
74
74
if ( ! M_is_scalar && ! N_is_scalar )
76
Scierror(999,_("%s: Only one of arg1 and arg2 may be a vector.\n"), fname);
76
Scierror(999, _("%s: Only one of arg1 and arg2 may be a vector.\n"), fname);
80
GetRhsCVar(3,MATRIX_OF_DOUBLE_DATATYPE, &it, &mx, &nx, &lx, &lc);
80
GetRhsCVar(3, MATRIX_OF_DOUBLE_DATATYPE, &it, &mx, &nx, &lx, &lc);
83
Scierror(999,_("%s: Wrong type for input argument #%d: Real matrix expected.\n"), fname, 3);
83
Scierror(999, _("%s: Wrong type for input argument #%d: Real matrix expected.\n"), fname, 3);
89
89
for ( i = 0 ; i < mnx ; i++ )
90
90
if ( ! (fabs(x[i]) < 1.0) )
92
Scierror(999,_("%s: Wrong value for input argument #%d: Matrix with elements in (%d,%d) expected.\n"), fname,3,-1,1);
92
Scierror(999, _("%s: Wrong value for input argument #%d: Matrix with elements in (%d,%d) expected.\n"), fname, 3, -1, 1);
98
GetRhsVar(4,STRING_DATATYPE, &ms, &ns, &ls);
99
if ( strcmp(cstk(ls),"norm") == 0)
98
GetRhsVar(4, STRING_DATATYPE, &ms, &ns, &ls);
99
if ( strcmp(cstk(ls), "norm") == 0)
113
113
MNp1 = Max (n2 - n1, m2 - m1) + 1;
115
CreateVar(Rhs+1, MATRIX_OF_DOUBLE_DATATYPE, &MNp1, &mnx, &lpqa); pqa = stk(lpqa);
116
CreateVar(Rhs+2, MATRIX_OF_INTEGER_DATATYPE, &MNp1, &mnx, &lipqa); ipqa = istk(lipqa);
115
CreateVar(Rhs + 1, MATRIX_OF_DOUBLE_DATATYPE, &MNp1, &mnx, &lpqa);
117
CreateVar(Rhs + 2, MATRIX_OF_INTEGER_DATATYPE, &MNp1, &mnx, &lipqa);
118
120
if ( normalised )
132
134
xx = fabs(x[i]); /* dxleg computes only for x in [0,1) */
133
135
F2C(dxlegf) (&dnu1, &nudiff, &m1, &m2, &xx, &id,
134
stk(lpqa+i*MNp1), istk(lipqa+i*MNp1), &ierror);
136
stk(lpqa + i * MNp1), istk(lipqa + i * MNp1), &ierror);
135
137
if ( ierror != 0 )
137
139
if ( ierror == 207 ) /* @TODO what is 207 ? */
139
Scierror(999,_("%s: overflow or underflow of an extended range number\n"), fname);
141
Scierror(999, _("%s: overflow or underflow of an extended range number\n"), fname);
143
Scierror(999,_("%s: error number %d\n"), fname, ierror);
145
Scierror(999, _("%s: error number %d\n"), fname, ierror);
166
168
/* complete the result by odd/even symmetry for negative x */
167
for ( i = 0 ; i < mnx ; i++ )
169
for ( i = 0 ; i < mnx ; i++ )
171
if ( (n1+m1) % 2 == 1 )
173
if ( (n1 + m1) % 2 == 1 )
173
for ( j = 0 ; j < MNp1 ; j+=2 )
175
for ( j = 0 ; j < MNp1 ; j += 2 )
175
pqa[i*MNp1 + j] = -pqa[i*MNp1 + j];
177
pqa[i * MNp1 + j] = -pqa[i * MNp1 + j];
180
for ( j = 1 ; j < MNp1 ; j+=2 )
182
for ( j = 1 ; j < MNp1 ; j += 2 )
182
pqa[i*MNp1 + j] = -pqa[i*MNp1 + j];
184
pqa[i * MNp1 + j] = -pqa[i * MNp1 + j];
223
225
for ( i = 1 ; i < nb_elt ; i++ )
225
if ( x[i] != x[i-1]+1.0 )
227
if ( x[i] != x[i - 1] + 1.0 )
231
233
*xmin = (int) x[0];
232
*xmax = (int) x[nb_elt-1];
234
*xmax = (int) x[nb_elt - 1];
235
237
/*--------------------------------------------------------------------------*/