source: MML/trunk/at/simulator/element/user/Matrix66Pass.c @ 4

Last change on this file since 4 was 4, checked in by zhangj, 11 years ago

Initial import--MML version from SOLEIL@2013

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