-
Notifications
You must be signed in to change notification settings - Fork 17
/
bessel_test.cpp
60 lines (50 loc) · 1.7 KB
/
bessel_test.cpp
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
/*
* Program: bessel_test.cpp
*
* Illustrates calling a C function that uses the GSL numeric library
*
* Computational function that takes a scalar and computes the value
* of the Bessel function J_0(x)
*
*
* This is a MEX-file for MATLAB
*/
#include "mex.h"
#include <iostream>
#include <gsl/gsl_sf_bessel.h>
using namespace std;
// Computational routine.............................................
void bessel_test( double x[] , double y[] ){
y[0] = gsl_sf_bessel_J0 (x[0]);
}
// The gateway function..............................................
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[]){
double *x;
double *y;
size_t mrows;
size_t ncols;
// Get number of rows and coulums of the input matrix...............
mrows = mxGetM(prhs[0]);
ncols = mxGetN(prhs[0]);
// Check for proper number of arguments.............................
if(nrhs!=1) {
mexErrMsgIdAndTxt( "MATLAB:bessel_test:invalidNumInputs",
"One input required.");
} else if(nlhs>1) {
mexErrMsgIdAndTxt( "MATLAB:bessel_test:maxlhs",
"Too many output arguments.");
}
// The input must be a noncomplex scalar double.....................
if( !mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) ||
!(mrows==1 && ncols==1) ) {
mexErrMsgIdAndTxt( "MATLAB:bessel_test:inputNotRealScalarDouble",
"Input must be a noncomplex scalar double.");
}
// Create matrix for the return argument............................
plhs[0] = mxCreateDoubleMatrix((mwSize)mrows, (mwSize)ncols, mxREAL);
// Assign pointers to each input and output.........................
x = mxGetPr(prhs[0]);
y = mxGetPr(plhs[0]);
bessel_test(x,y);
}