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

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

Initial import--MML version from SOLEIL@2013

File size: 3.2 KB
Line 
1/* SolenoidPass.c
2   Accelerator Toolbox
3   Revision 7/16/03
4   Christoph Steier, CSteier@lbl.gov
5*/
6
7#include "mex.h"
8#include "elempass.h"
9#include "../atlalib.c"
10#include <stdlib.h>
11#include <math.h>
12
13/******************************************************************************/
14/* PHYSICS SECTION ************************************************************/
15
16void SRotationPass(double *r, double *R, int num_particles)
17{       int c;
18        double *r6;
19        for(c = 0;c<num_particles;c++)
20                {       r6 = r+c*6;     
21                       
22                        ATmultmv(r6,R);
23                                               
24                }               
25}
26
27/********** END PHYSICS SECTION ***********************************************/
28/******************************************************************************/
29
30/********** WINDOWS DLL GATEWAY SECTION ***************************************/
31
32
33ExportMode int* passFunction(const mxArray *ElemData, int *FieldNumbers,
34                                                                double *r_in, int num_particles, int mode)
35
36#define NUM_FIELDS_2_REMEMBER 1
37
38{       double *pr;   
39    mxArray *tmpmxptr;
40        int *returnptr,fnum;
41        int *NewFieldNumbers;
42
43        switch(mode)
44                {       case NO_LOCAL_COPY:     /* Get fields by names from MATLAB workspace  */
45                                {                                               
46                                        tmpmxptr=mxGetField(ElemData,0,"R");
47                                    if(tmpmxptr)
48                        pr = mxGetPr(tmpmxptr);
49                                        else
50                                            mexErrMsgTxt("Required field 'R' was not found in the element data structure"); 
51                               
52                                        returnptr = NULL;
53                               
54                                }       break; 
55                        case MAKE_LOCAL_COPY:   /* Find field numbers first
56                                                                                Save a list of field number in an array
57                                                                                and make returnptr point to that array
58                                                                    */
59                                {                                               
60                                        NewFieldNumbers = (int*)mxCalloc(NUM_FIELDS_2_REMEMBER,sizeof(int));
61                                       
62                                        fnum = mxGetFieldNumber(ElemData,"R");
63                                        if(fnum<0) 
64                                            mexErrMsgTxt("Required field 'R' was not found in the element data structure"); 
65                                        NewFieldNumbers[0] = fnum;                     
66
67                       
68                                        pr = mxGetPr(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[0]));
69
70                                        returnptr = NewFieldNumbers;
71
72                                }       break;
73
74                        case    USE_LOCAL_COPY: /* Get fields from MATLAB using field numbers
75                                                                                The second argument ponter to the array of field
76                                                                                numbers is previously created with
77                                                                                SRotationPass( ..., MAKE_LOCAL_COPY)
78                                                                    */
79                                                                                       
80                                {       pr = mxGetPr(mxGetFieldByNumber(ElemData,0,FieldNumbers[0]));
81
82                                        returnptr = FieldNumbers;
83
84               
85                                }       break;
86                        default:
87                                {       mexErrMsgTxt("No match for calling mode in function SRotationPass\n");
88                                }
89                }
90
91        SRotationPass(r_in,  pr, num_particles);
92        return(returnptr);     
93}
94
95
96/********** END WINDOWS DLL GATEWAY SECTION ***************************************/
97/********** MATLAB GATEWAY  ***************************************/
98
99void mexFunction(       int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
100{       
101        int m, n;
102        double *r_in;   
103        double  *pr; 
104        mxArray *tmpmxptr;
105
106        /* ALLOCATE memory for the output array of the same size as the input */
107        m = mxGetM(prhs[1]);
108        n = mxGetN(prhs[1]);
109        if(m!=6) 
110                {mexErrMsgTxt("Second argument must be a 6 x N matrix");}       
111               
112               
113        tmpmxptr = mxGetField(prhs[0],0,"R");
114        if(tmpmxptr)
115            pr = mxGetPr(tmpmxptr);
116        else
117            mexErrMsgTxt("Required field 'R' was not found in the element data structure"); 
118       
119        plhs[0] = mxDuplicateArray(prhs[1]);
120        r_in = mxGetPr(plhs[0]);
121        SRotationPass(r_in,  pr, n);
122}
123
124
Note: See TracBrowser for help on using the repository browser.