File: mexfunction1.c

package info (click to toggle)
scilab 2.6-4
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 54,632 kB
  • ctags: 40,267
  • sloc: ansic: 267,851; fortran: 166,549; sh: 10,005; makefile: 4,119; tcl: 1,070; cpp: 233; csh: 143; asm: 135; perl: 130; java: 39
file content (47 lines) | stat: -rw-r--r-- 1,222 bytes parent folder | download
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
#include <stdio.h>
#include "mex.h"

#define STRING "hello world"

void ABcopy __PARAMS((double *a,double *b,int mn));

void mexfunction1(nlhs, plhs, nrhs, prhs)
     int nlhs, nrhs;
     Matrix *plhs[]; Matrix *prhs[];
{
    Matrix *ptrA,*ptrB;
    double *A,*B;
    int m,n,it,strl;
    char *str;
    mexWarnMsgTxt("This function requires 2 inputs");
    if (nrhs!=2) mexErrMsgTxt("This function requires 2 inputs!");
    if (nlhs>3) mexErrMsgTxt("This function requires at most 3 outputs!");
    ptrA = prhs[0];
    if (! mxIsNumeric(prhs[0])) mexErrMsgTxt("First argument must be numeric matrix.");
    if (! mxIsString(prhs[1])) mexErrMsgTxt("Second argument must be a string.");
    m = mxGetM(ptrA);n = mxGetN(ptrA);
    A = mxGetPr(ptrA);
    it=0;
    ptrB = mxCreateFull(n,m,it);
    m = mxGetM(ptrB);n = mxGetN(ptrB);
    B = mxGetPr(ptrB);
    ABcopy(A,B,m*n);
    plhs[0]=prhs[0];
    plhs[1]= ptrB;
    m=mxGetM(prhs[1]);
    strl=mxGetN(prhs[1]);
    str=mxCalloc(m*strl+1,sizeof(char));
    mxGetString(prhs[1],str,m*strl);
    plhs[2]=mxCreateString(str);
}  

void ABcopy(a,b,mn)
     double *a; double *b;
     int mn;
{
  int i;
  for ( i=0 ; i < mn ; i++) 
    {
      b[i] = a[i] + 33.0 +i;
    }
}