1 | /* DriftPass.c |
---|
2 | Accelerator Toolbox |
---|
3 | Revision 6/26/00 |
---|
4 | A.Terebilo terebilo@ssrl.slac.stanford.edu |
---|
5 | */ |
---|
6 | |
---|
7 | #include "mex.h" |
---|
8 | #include "elempass.h" |
---|
9 | #include "atlalib.c" |
---|
10 | |
---|
11 | void Matrix66Pass(double *r, double *M, int num_particles) |
---|
12 | |
---|
13 | { int c, c6; |
---|
14 | |
---|
15 | for(c = 0;c<num_particles;c++) |
---|
16 | { c6 = c*6; |
---|
17 | if(!mxIsNaN(r[c6])) |
---|
18 | ATmultmv(r+c*6,M); |
---|
19 | } |
---|
20 | |
---|
21 | } |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | |
---|
26 | ExportMode int* passFunction(const mxArray *ElemData,int *FieldNumbers, |
---|
27 | double *r_in, int num_particles, int mode) |
---|
28 | |
---|
29 | |
---|
30 | #define NUM_FIELDS_2_REMEMBER 1 |
---|
31 | |
---|
32 | { double *M; |
---|
33 | |
---|
34 | int *returnptr; |
---|
35 | int fnum,*NewFieldNumbers; |
---|
36 | |
---|
37 | switch(mode) |
---|
38 | { case NO_LOCAL_COPY: /* Not used in AT1.3 Get fields by names from MATLAB workspace */ |
---|
39 | { |
---|
40 | } break; |
---|
41 | |
---|
42 | case MAKE_LOCAL_COPY: /* Find field numbers first |
---|
43 | Save a list of field number in an array |
---|
44 | and make returnptr point to that array |
---|
45 | */ |
---|
46 | { |
---|
47 | NewFieldNumbers = (int*)mxCalloc(NUM_FIELDS_2_REMEMBER,sizeof(int)); |
---|
48 | fnum = mxGetFieldNumber(ElemData,"M66"); |
---|
49 | if(fnum<0) |
---|
50 | mexErrMsgTxt("Required field 'M66' was not found in the element data structure"); |
---|
51 | else |
---|
52 | { NewFieldNumbers[0] = fnum; |
---|
53 | M = mxGetPr(mxGetFieldByNumber(ElemData,0,fnum)); |
---|
54 | returnptr = NewFieldNumbers; |
---|
55 | } |
---|
56 | } break; |
---|
57 | |
---|
58 | case USE_LOCAL_COPY: /* Get fields from MATLAB using field numbers |
---|
59 | The second argument ponter to the array of field |
---|
60 | numbers is previously created with |
---|
61 | QuadLinPass( ..., MAKE_LOCAL_COPY) |
---|
62 | */ |
---|
63 | |
---|
64 | { M = mxGetPr(mxGetFieldByNumber(ElemData,0,FieldNumbers[0])); |
---|
65 | returnptr = FieldNumbers; |
---|
66 | } break; |
---|
67 | } |
---|
68 | Matrix66Pass(r_in, M, num_particles); |
---|
69 | return(returnptr); |
---|
70 | } |
---|
71 | |
---|
72 | |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) |
---|
81 | { int m,n; |
---|
82 | double *r_in, *M; |
---|
83 | mxArray *tmpmxptr; |
---|
84 | |
---|
85 | if(nrhs) |
---|
86 | { |
---|
87 | /* ALLOCATE memory for the output array of the same size as the input */ |
---|
88 | m = mxGetM(prhs[1]); |
---|
89 | n = mxGetN(prhs[1]); |
---|
90 | if(m!=6) |
---|
91 | mexErrMsgTxt("Second argument must be a 6 x N matrix"); |
---|
92 | |
---|
93 | tmpmxptr=mxGetField(prhs[0],0,"M66"); |
---|
94 | if(tmpmxptr) |
---|
95 | M = mxGetPr(tmpmxptr); |
---|
96 | else |
---|
97 | mexErrMsgTxt("Required field 'Length' was not found in the element data structure"); |
---|
98 | |
---|
99 | |
---|
100 | plhs[0] = mxDuplicateArray(prhs[1]); |
---|
101 | r_in = mxGetPr(plhs[0]); |
---|
102 | |
---|
103 | Matrix66Pass(r_in,M, n); |
---|
104 | } |
---|
105 | else |
---|
106 | { /* return list of required fields */ |
---|
107 | plhs[0] = mxCreateCellMatrix(1,1); |
---|
108 | mxSetCell(plhs[0],0,mxCreateString("M66")); |
---|
109 | if(nlhs>1) /* Required and optional fields */ |
---|
110 | { plhs[1] = mxCreateCellMatrix(0,0); /* No optional fields */ |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | } |
---|