1 | /* TaylormapPass2.c |
---|
2 | Accelerator Toolbox |
---|
3 | Created on 05/06/2004 |
---|
4 | W. Wan wwan@lbl.gov */ |
---|
5 | |
---|
6 | #include "mex.h" |
---|
7 | #include<stdio.h> |
---|
8 | #include<math.h> |
---|
9 | #include "../atlalib.c" |
---|
10 | #include "elempass.h" |
---|
11 | |
---|
12 | #define PI 3.141592653589793 |
---|
13 | |
---|
14 | void TaylormapPass2(double *r_in, double le, int no, int nv, |
---|
15 | double *x, int nx, double *px, int npx, |
---|
16 | double *y, int ny, double *py, int npy, |
---|
17 | double *delta, int ndelta, double *t, int nt, |
---|
18 | double *T1, double *T2, |
---|
19 | double *R1, double *R2, int num_particles) |
---|
20 | /* |
---|
21 | r_in -- 6-by-N matrix of initial conditions reshaped into |
---|
22 | 1-d array of 6*N elements |
---|
23 | le -- physical length |
---|
24 | no -- order of the Taylor map |
---|
25 | nv -- number of variables in the input |
---|
26 | x -- Taylor map of final x |
---|
27 | nx -- number of monomials in the map x |
---|
28 | px -- Taylor map of final px |
---|
29 | npx -- number of monomials in the map px |
---|
30 | y -- Taylor map of final y |
---|
31 | ny -- number of monomials in the map y |
---|
32 | py -- Taylor map of final py |
---|
33 | npy -- number of monomials in the map py |
---|
34 | delta -- Taylor map of final delta p / p |
---|
35 | ndelta -- number of monomials in the map delta |
---|
36 | t -- Taylor map of final t |
---|
37 | nt -- number of monomials in the map t |
---|
38 | T1 -- 6 x 1 translation at entrance |
---|
39 | T2 -- 6 x 1 translation at exit |
---|
40 | R1 -- 6 x 6 rotation matrix at the entrance |
---|
41 | R2 -- 6 x 6 rotation matrix at the exit |
---|
42 | num_particles -- number of particles |
---|
43 | */ |
---|
44 | #define NUM_COLUMNS 9 |
---|
45 | { |
---|
46 | int c,i,j; |
---|
47 | double *r6; |
---|
48 | double *rtmp; |
---|
49 | double tmp; |
---|
50 | double *product; |
---|
51 | |
---|
52 | rtmp = (double*)mxCalloc(6,sizeof(double)); |
---|
53 | product = (double*)mxCalloc(no*nv,sizeof(double)); |
---|
54 | |
---|
55 | for(c = 0;c<num_particles;c++) { |
---|
56 | r6 = r_in+c*6; |
---|
57 | for(i=0;i<6;i++) { |
---|
58 | rtmp[i] = r6[i]; |
---|
59 | r6[i] = 0; |
---|
60 | } |
---|
61 | |
---|
62 | /* linearized misalignment transformation at the entrance */ |
---|
63 | ATaddvv(rtmp,T1); |
---|
64 | ATmultmv(rtmp,R1); |
---|
65 | |
---|
66 | /* Taylor map */ |
---|
67 | |
---|
68 | for(i=0;i<nv;i++) { |
---|
69 | tmp = 1; |
---|
70 | for(j=0;j<no;j++) { |
---|
71 | tmp *= rtmp[i]; |
---|
72 | product[j+i*no] = tmp; |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | /* x final */ |
---|
77 | for(i=0;i<nx;i++) { |
---|
78 | tmp = x[i+1*nx]; |
---|
79 | for(j=0;j<nv;j++) { |
---|
80 | if ((int)x[i+(j+3)*nx]>0) { |
---|
81 | tmp *= product[(int)x[i+(j+3)*nx]-1+j*no]; |
---|
82 | } |
---|
83 | } |
---|
84 | r6[0] += tmp; |
---|
85 | } |
---|
86 | |
---|
87 | /* px final */ |
---|
88 | for(i=0;i<npx;i++) { |
---|
89 | tmp = px[i+1*npx]; |
---|
90 | for(j=0;j<nv;j++) { |
---|
91 | if ((int)px[i+(j+3)*npx]>0) { |
---|
92 | tmp *= product[(int)px[i+(j+3)*npx]-1+j*no]; |
---|
93 | } |
---|
94 | } |
---|
95 | r6[1] += tmp; |
---|
96 | } |
---|
97 | |
---|
98 | /* y final */ |
---|
99 | for(i=0;i<ny;i++) { |
---|
100 | tmp = y[i+1*ny]; |
---|
101 | for(j=0;j<nv;j++) { |
---|
102 | if ((int)y[i+(j+3)*ny]>0) { |
---|
103 | tmp *= product[(int)y[i+(j+3)*ny]-1+j*no]; |
---|
104 | } |
---|
105 | } |
---|
106 | r6[2] += tmp; |
---|
107 | } |
---|
108 | |
---|
109 | /* py final */ |
---|
110 | for(i=0;i<npy;i++) { |
---|
111 | tmp = py[i+1*npy]; |
---|
112 | for(j=0;j<nv;j++) { |
---|
113 | if ((int)py[i+(j+3)*npy]>0) { |
---|
114 | tmp *= product[(int)py[i+(j+3)*npy]-1+j*no]; |
---|
115 | } |
---|
116 | } |
---|
117 | r6[3] += tmp; |
---|
118 | } |
---|
119 | |
---|
120 | /* delta final */ |
---|
121 | for(i=0;i<ndelta;i++) { |
---|
122 | tmp = delta[i+1*ndelta]; |
---|
123 | for(j=0;j<nv;j++) { |
---|
124 | if ((int)delta[i+(j+3)*ndelta]>0) { |
---|
125 | tmp *= product[(int)delta[i+(j+3)*ndelta]-1+j*no]; |
---|
126 | } |
---|
127 | } |
---|
128 | r6[4] += tmp; |
---|
129 | } |
---|
130 | |
---|
131 | /* t final */ |
---|
132 | for(i=0;i<nt;i++) { |
---|
133 | tmp = t[i+1*nt]; |
---|
134 | for(j=0;j<nv;j++) { |
---|
135 | if ((int)t[i+(j+3)*nt]>0) { |
---|
136 | tmp *= product[(int)t[i+(j+3)*nt]-1+j*no]; |
---|
137 | } |
---|
138 | } |
---|
139 | r6[5] += tmp; |
---|
140 | } |
---|
141 | |
---|
142 | /* linearized misalignment transformation at the exit */ |
---|
143 | ATmultmv(r6,R2); |
---|
144 | ATaddvv(r6,T2); |
---|
145 | } |
---|
146 | mxFree(rtmp); |
---|
147 | mxFree(product); |
---|
148 | } |
---|
149 | |
---|
150 | ExportMode int* passFunction(const mxArray *ElemData,int *FieldNumbers, |
---|
151 | double *r_in, int num_particles, int mode) |
---|
152 | |
---|
153 | #define NUM_FIELDS_2_REMEMBER 19 |
---|
154 | { |
---|
155 | int *returnptr; |
---|
156 | int fnum, *NewFieldNumbers; |
---|
157 | mxArray *tmpmxptr; |
---|
158 | double le; |
---|
159 | int no, nv; |
---|
160 | double *pr1, *pr2, *pt1, *pt2; |
---|
161 | double *x, *px, *y, *py, *t, *delta; |
---|
162 | int nx, npx, ny, npy, nt, ndelta; |
---|
163 | |
---|
164 | switch(mode) { |
---|
165 | case NO_LOCAL_COPY: { /* Get fields by names from MATLAB workspace */ |
---|
166 | tmpmxptr=mxGetField(ElemData,0,"Length"); |
---|
167 | if(tmpmxptr) { |
---|
168 | le = mxGetScalar(tmpmxptr); |
---|
169 | returnptr = NULL; |
---|
170 | } |
---|
171 | else |
---|
172 | mexErrMsgTxt("Required field 'Length' was not found in the element data structure"); |
---|
173 | tmpmxptr=mxGetField(ElemData,0,"Order"); |
---|
174 | if(tmpmxptr) { |
---|
175 | no = (int)mxGetScalar(tmpmxptr); |
---|
176 | returnptr = NULL; |
---|
177 | } |
---|
178 | else |
---|
179 | mexErrMsgTxt("Required field 'Order' was not found in the element data structure"); |
---|
180 | tmpmxptr=mxGetField(ElemData,0,"NumOfVar"); |
---|
181 | if(tmpmxptr) { |
---|
182 | nv = (int)mxGetScalar(tmpmxptr); |
---|
183 | returnptr = NULL; |
---|
184 | } |
---|
185 | else |
---|
186 | mexErrMsgTxt("Required field 'NumOfVar' was not found in the element data structure"); |
---|
187 | tmpmxptr=mxGetField(ElemData,0,"MapX"); |
---|
188 | if(tmpmxptr) { |
---|
189 | x = mxGetPr(tmpmxptr); |
---|
190 | returnptr = NULL; |
---|
191 | } |
---|
192 | else |
---|
193 | mexErrMsgTxt("Required field 'MapX' was not found in the element data structure"); |
---|
194 | tmpmxptr=mxGetField(ElemData,0,"NumOfMonoX"); |
---|
195 | if(tmpmxptr) { |
---|
196 | nx = (int)mxGetScalar(tmpmxptr); |
---|
197 | returnptr = NULL; |
---|
198 | } |
---|
199 | else |
---|
200 | mexErrMsgTxt("Required field 'NumOfMonoX' was not found in the element data structure"); |
---|
201 | tmpmxptr=mxGetField(ElemData,0,"MapPx"); |
---|
202 | if(tmpmxptr) { |
---|
203 | px = mxGetPr(tmpmxptr); |
---|
204 | returnptr = NULL; |
---|
205 | } |
---|
206 | else |
---|
207 | mexErrMsgTxt("Required field 'MapPx' was not found in the element data structure"); |
---|
208 | tmpmxptr=mxGetField(ElemData,0,"NumOfMonoPx"); |
---|
209 | if(tmpmxptr) { |
---|
210 | npx = (int)mxGetScalar(tmpmxptr); |
---|
211 | returnptr = NULL; |
---|
212 | } |
---|
213 | else |
---|
214 | mexErrMsgTxt("Required field 'NumOfMonoPx' was not found in the element data structure"); |
---|
215 | tmpmxptr=mxGetField(ElemData,0,"MapY"); |
---|
216 | if(tmpmxptr) { |
---|
217 | y = mxGetPr(tmpmxptr); |
---|
218 | returnptr = NULL; |
---|
219 | } |
---|
220 | else |
---|
221 | mexErrMsgTxt("Required field 'MapY' was not found in the element data structure"); |
---|
222 | tmpmxptr=mxGetField(ElemData,0,"NumOfMonoY"); |
---|
223 | if(tmpmxptr) { |
---|
224 | ny = (int)mxGetScalar(tmpmxptr); |
---|
225 | returnptr = NULL; |
---|
226 | } |
---|
227 | else |
---|
228 | mexErrMsgTxt("Required field 'NumOfMonoY' was not found in the element data structure"); |
---|
229 | tmpmxptr=mxGetField(ElemData,0,"MapPy"); |
---|
230 | if(tmpmxptr) { |
---|
231 | py = mxGetPr(tmpmxptr); |
---|
232 | returnptr = NULL; |
---|
233 | } |
---|
234 | else |
---|
235 | mexErrMsgTxt("Required field 'MapPy' was not found in the element data structure"); |
---|
236 | tmpmxptr=mxGetField(ElemData,0,"NumOfMonoPy"); |
---|
237 | if(tmpmxptr) { |
---|
238 | npy = (int)mxGetScalar(tmpmxptr); |
---|
239 | returnptr = NULL; |
---|
240 | } |
---|
241 | else |
---|
242 | mexErrMsgTxt("Required field 'NumOfMonoPy' was not found in the element data structure"); |
---|
243 | tmpmxptr=mxGetField(ElemData,0,"MapDelta"); |
---|
244 | if(tmpmxptr) { |
---|
245 | delta = mxGetPr(tmpmxptr); |
---|
246 | returnptr = NULL; |
---|
247 | } |
---|
248 | else |
---|
249 | mexErrMsgTxt("Required field 'MapDelta' was not found in the element data structure"); |
---|
250 | tmpmxptr=mxGetField(ElemData,0,"NumOfMonoDelta"); |
---|
251 | if(tmpmxptr) { |
---|
252 | ndelta = (int)mxGetScalar(tmpmxptr); |
---|
253 | returnptr = NULL; |
---|
254 | } |
---|
255 | else |
---|
256 | mexErrMsgTxt("Required field 'NumOfMonoDelta' was not found in the element data structure"); |
---|
257 | tmpmxptr=mxGetField(ElemData,0,"MapT"); |
---|
258 | if(tmpmxptr) { |
---|
259 | t = mxGetPr(tmpmxptr); |
---|
260 | returnptr = NULL; |
---|
261 | } |
---|
262 | else |
---|
263 | mexErrMsgTxt("Required field 'MapT' was not found in the element data structure"); |
---|
264 | tmpmxptr=mxGetField(ElemData,0,"NumOfMonoT"); |
---|
265 | if(tmpmxptr) { |
---|
266 | nt = (int)mxGetScalar(tmpmxptr); |
---|
267 | returnptr = NULL; |
---|
268 | } |
---|
269 | else |
---|
270 | mexErrMsgTxt("Required field 'NumOfMonoT' was not found in the element data structure"); |
---|
271 | tmpmxptr=mxGetField(ElemData,0,"T1"); |
---|
272 | if(tmpmxptr) { |
---|
273 | pt1 = mxGetPr(tmpmxptr); |
---|
274 | returnptr = NULL; |
---|
275 | } |
---|
276 | else |
---|
277 | mexErrMsgTxt("Required field 'T1' was not found in the element data structure"); |
---|
278 | tmpmxptr=mxGetField(ElemData,0,"T2"); |
---|
279 | if(tmpmxptr) { |
---|
280 | pt2 = mxGetPr(tmpmxptr); |
---|
281 | returnptr = NULL; |
---|
282 | } |
---|
283 | else |
---|
284 | mexErrMsgTxt("Required field 'T2' was not found in the element data structure"); |
---|
285 | tmpmxptr=mxGetField(ElemData,0,"R1"); |
---|
286 | if(tmpmxptr) { |
---|
287 | pr1 = mxGetPr(tmpmxptr); |
---|
288 | returnptr = NULL; |
---|
289 | } |
---|
290 | else |
---|
291 | mexErrMsgTxt("Required field 'R1' was not found in the element data structure"); |
---|
292 | tmpmxptr=mxGetField(ElemData,0,"R2"); |
---|
293 | if(tmpmxptr) { |
---|
294 | pr2 = mxGetPr(tmpmxptr); |
---|
295 | returnptr = NULL; |
---|
296 | } |
---|
297 | else |
---|
298 | mexErrMsgTxt("Required field 'R2' was not found in the element data structure"); |
---|
299 | } |
---|
300 | break; |
---|
301 | case MAKE_LOCAL_COPY: { /* Find field numbers first |
---|
302 | Save a list of field number in an array |
---|
303 | and make returnptr point to that array */ |
---|
304 | NewFieldNumbers = (int*)mxCalloc(NUM_FIELDS_2_REMEMBER,sizeof(int)); |
---|
305 | fnum = mxGetFieldNumber(ElemData,"Length"); |
---|
306 | if(fnum<0) |
---|
307 | mexErrMsgTxt("Required field 'Length' was not found in the element data structure"); |
---|
308 | NewFieldNumbers[0] = fnum; |
---|
309 | fnum = mxGetFieldNumber(ElemData,"Order"); |
---|
310 | if(fnum<0) |
---|
311 | mexErrMsgTxt("Required field 'Order' was not found in the element data structure"); |
---|
312 | NewFieldNumbers[1] = fnum; |
---|
313 | fnum = mxGetFieldNumber(ElemData,"NumOfVar"); |
---|
314 | if(fnum<0) |
---|
315 | mexErrMsgTxt("Required field 'NumOfVar' was not found in the element data structure"); |
---|
316 | NewFieldNumbers[2] = fnum; |
---|
317 | fnum = mxGetFieldNumber(ElemData,"MapX"); |
---|
318 | if(fnum<0) |
---|
319 | mexErrMsgTxt("Required field 'MapX' was not found in the element data structure"); |
---|
320 | NewFieldNumbers[3] = fnum; |
---|
321 | fnum = mxGetFieldNumber(ElemData,"NumOfMonoX"); |
---|
322 | if(fnum<0) |
---|
323 | mexErrMsgTxt("Required field 'NumOfMonoX' was not found in the element data structure"); |
---|
324 | NewFieldNumbers[4] = fnum; |
---|
325 | fnum = mxGetFieldNumber(ElemData,"MapPx"); |
---|
326 | if(fnum<0) |
---|
327 | mexErrMsgTxt("Required field 'MapPx' was not found in the element data structure"); |
---|
328 | NewFieldNumbers[5] = fnum; |
---|
329 | fnum = mxGetFieldNumber(ElemData,"NumOfMonoPx"); |
---|
330 | if(fnum<0) |
---|
331 | mexErrMsgTxt("Required field 'NumOfMonoPx' was not found in the element data structure"); |
---|
332 | NewFieldNumbers[6] = fnum; |
---|
333 | fnum = mxGetFieldNumber(ElemData,"MapY"); |
---|
334 | if(fnum<0) |
---|
335 | mexErrMsgTxt("Required field 'MapY' was not found in the element data structure"); |
---|
336 | NewFieldNumbers[7] = fnum; |
---|
337 | fnum = mxGetFieldNumber(ElemData,"NumOfMonoY"); |
---|
338 | if(fnum<0) |
---|
339 | mexErrMsgTxt("Required field 'NumOfMonoY' was not found in the element data structure"); |
---|
340 | NewFieldNumbers[8] = fnum; |
---|
341 | fnum = mxGetFieldNumber(ElemData,"MapPy"); |
---|
342 | if(fnum<0) |
---|
343 | mexErrMsgTxt("Required field 'MapPy' was not found in the element data structure"); |
---|
344 | NewFieldNumbers[9] = fnum; |
---|
345 | fnum = mxGetFieldNumber(ElemData,"NumOfMonoPy"); |
---|
346 | if(fnum<0) |
---|
347 | mexErrMsgTxt("Required field 'NumOfMonoPy' was not found in the element data structure"); |
---|
348 | NewFieldNumbers[10] = fnum; |
---|
349 | fnum = mxGetFieldNumber(ElemData,"MapDelta"); |
---|
350 | if(fnum<0) |
---|
351 | mexErrMsgTxt("Required field 'MapDelta' was not found in the element data structure"); |
---|
352 | NewFieldNumbers[11] = fnum; |
---|
353 | fnum = mxGetFieldNumber(ElemData,"NumOfMonoDelta"); |
---|
354 | if(fnum<0) |
---|
355 | mexErrMsgTxt("Required field 'NumOfMonoDelta' was not found in the element data structure"); |
---|
356 | NewFieldNumbers[12] = fnum; |
---|
357 | fnum = mxGetFieldNumber(ElemData,"MapT"); |
---|
358 | if(fnum<0) |
---|
359 | mexErrMsgTxt("Required field 'MapT' was not found in the element data structure"); |
---|
360 | NewFieldNumbers[13] = fnum; |
---|
361 | fnum = mxGetFieldNumber(ElemData,"NumOfMonoT"); |
---|
362 | if(fnum<0) |
---|
363 | mexErrMsgTxt("Required field 'NumOfMonoT' was not found in the element data structure"); |
---|
364 | NewFieldNumbers[14] = fnum; |
---|
365 | fnum = mxGetFieldNumber(ElemData,"T1"); |
---|
366 | if(fnum<0) |
---|
367 | mexErrMsgTxt("Required field 'T1' was not found in the element data structure"); |
---|
368 | NewFieldNumbers[15] = fnum; |
---|
369 | fnum = mxGetFieldNumber(ElemData,"T2"); |
---|
370 | if(fnum<0) |
---|
371 | mexErrMsgTxt("Required field 'T2' was not found in the element data structure"); |
---|
372 | NewFieldNumbers[16] = fnum; |
---|
373 | fnum = mxGetFieldNumber(ElemData,"R1"); |
---|
374 | if(fnum<0) |
---|
375 | mexErrMsgTxt("Required field 'R1' was not found in the element data structure"); |
---|
376 | NewFieldNumbers[17] = fnum; |
---|
377 | fnum = mxGetFieldNumber(ElemData,"R2"); |
---|
378 | if(fnum<0) |
---|
379 | mexErrMsgTxt("Required field 'R2' was not found in the element data structure"); |
---|
380 | NewFieldNumbers[18] = fnum; |
---|
381 | |
---|
382 | le = mxGetScalar(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[0])); |
---|
383 | no = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[1])); |
---|
384 | nv = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[2])); |
---|
385 | x = mxGetPr(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[3])); |
---|
386 | nx = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[4])); |
---|
387 | px = mxGetPr(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[5])); |
---|
388 | npx = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[6])); |
---|
389 | y = mxGetPr(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[7])); |
---|
390 | ny = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[8])); |
---|
391 | py = mxGetPr(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[9])); |
---|
392 | npy = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[10])); |
---|
393 | delta = mxGetPr(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[11])); |
---|
394 | ndelta = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[12])); |
---|
395 | t = mxGetPr(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[13])); |
---|
396 | nt = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[14])); |
---|
397 | pt1 = mxGetPr(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[15])); |
---|
398 | pt2 = mxGetPr(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[16])); |
---|
399 | pr1 = mxGetPr(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[17])); |
---|
400 | pr2 = mxGetPr(mxGetFieldByNumber(ElemData,0,NewFieldNumbers[18])); |
---|
401 | |
---|
402 | returnptr = NewFieldNumbers; |
---|
403 | } |
---|
404 | break; |
---|
405 | case USE_LOCAL_COPY: { /* Get fields from MATLAB using field numbers |
---|
406 | The second argument ponter to the array of field |
---|
407 | numbers is previously created with |
---|
408 | QuadLinPass( ..., MAKE_LOCAL_COPY) */ |
---|
409 | le = mxGetScalar(mxGetFieldByNumber(ElemData,0,FieldNumbers[0])); |
---|
410 | no = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,FieldNumbers[1])); |
---|
411 | nv = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,FieldNumbers[2])); |
---|
412 | x = mxGetPr(mxGetFieldByNumber(ElemData,0,FieldNumbers[3])); |
---|
413 | nx = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,FieldNumbers[4])); |
---|
414 | px = mxGetPr(mxGetFieldByNumber(ElemData,0,FieldNumbers[5])); |
---|
415 | npx = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,FieldNumbers[6])); |
---|
416 | y = mxGetPr(mxGetFieldByNumber(ElemData,0,FieldNumbers[7])); |
---|
417 | ny = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,FieldNumbers[8])); |
---|
418 | py = mxGetPr(mxGetFieldByNumber(ElemData,0,FieldNumbers[9])); |
---|
419 | npy = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,FieldNumbers[10])); |
---|
420 | delta = mxGetPr(mxGetFieldByNumber(ElemData,0,FieldNumbers[11])); |
---|
421 | ndelta = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,FieldNumbers[12])); |
---|
422 | t = mxGetPr(mxGetFieldByNumber(ElemData,0,FieldNumbers[13])); |
---|
423 | nt = (int)mxGetScalar(mxGetFieldByNumber(ElemData,0,FieldNumbers[14])); |
---|
424 | pt1 = mxGetPr(mxGetFieldByNumber(ElemData,0,FieldNumbers[15])); |
---|
425 | pt2 = mxGetPr(mxGetFieldByNumber(ElemData,0,FieldNumbers[16])); |
---|
426 | pr1 = mxGetPr(mxGetFieldByNumber(ElemData,0,FieldNumbers[17])); |
---|
427 | pr2 = mxGetPr(mxGetFieldByNumber(ElemData,0,FieldNumbers[18])); |
---|
428 | returnptr = FieldNumbers; |
---|
429 | } |
---|
430 | break; |
---|
431 | default: { |
---|
432 | mexErrMsgTxt("No match for calling mode in function TaylormapPass2\n"); |
---|
433 | } |
---|
434 | } |
---|
435 | TaylormapPass2(r_in, le, no, nv, x, nx, px, npx, y, ny, py, npy, delta, ndelta, t, nt, |
---|
436 | pt1, pt2, pr1, pr2, num_particles); |
---|
437 | return(returnptr); |
---|
438 | } |
---|
439 | |
---|
440 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) |
---|
441 | { |
---|
442 | int m,n; double *r_in; |
---|
443 | mxArray *tmpmxptr; |
---|
444 | double le; |
---|
445 | int no, nv; |
---|
446 | double *pr1, *pr2, *pt1, *pt2; |
---|
447 | double *x, *px, *y, *py, *t, *delta; |
---|
448 | int nx, npx, ny, npy, nt, ndelta; |
---|
449 | |
---|
450 | /* ALLOCATE memory for the output array of the same size as the input */ |
---|
451 | m = mxGetM(prhs[1]); |
---|
452 | n = mxGetN(prhs[1]); |
---|
453 | if(m!=6) |
---|
454 | mexErrMsgTxt("Second argument must be a 6 x N matrix"); |
---|
455 | tmpmxptr=mxGetField(prhs[0],0,"Length"); |
---|
456 | if(tmpmxptr) |
---|
457 | le = mxGetScalar(tmpmxptr); |
---|
458 | else |
---|
459 | mexErrMsgTxt("Required field 'Length' was not found in the element data structure"); |
---|
460 | tmpmxptr=mxGetField(prhs[0],0,"Order"); |
---|
461 | if(tmpmxptr) |
---|
462 | no = (int)mxGetScalar(tmpmxptr); |
---|
463 | else |
---|
464 | mexErrMsgTxt("Required field 'Order' was not found in the element data structure"); |
---|
465 | tmpmxptr=mxGetField(prhs[0],0,"NumOfVariables"); |
---|
466 | if(tmpmxptr) |
---|
467 | nv = (int)mxGetScalar(tmpmxptr); |
---|
468 | else |
---|
469 | mexErrMsgTxt("Required field 'NumOfVariables' was not found in the element data structure"); |
---|
470 | tmpmxptr=mxGetField(prhs[0],0,"MapX"); |
---|
471 | if(tmpmxptr) |
---|
472 | x = mxGetPr(tmpmxptr); |
---|
473 | else |
---|
474 | mexErrMsgTxt("Required field 'MapX' was not found in the element data structure"); |
---|
475 | tmpmxptr=mxGetField(prhs[0],0,"NumOfMonoX"); |
---|
476 | if(tmpmxptr) |
---|
477 | nx = (int)mxGetScalar(tmpmxptr); |
---|
478 | else |
---|
479 | mexErrMsgTxt("Required field 'NumOfMonoX' was not found in the element data structure"); |
---|
480 | tmpmxptr=mxGetField(prhs[0],0,"MapPx"); |
---|
481 | if(tmpmxptr) |
---|
482 | px = mxGetPr(tmpmxptr); |
---|
483 | else |
---|
484 | mexErrMsgTxt("Required field 'MapPx' was not found in the element data structure"); |
---|
485 | tmpmxptr=mxGetField(prhs[0],0,"NumOfMonoPx"); |
---|
486 | if(tmpmxptr) |
---|
487 | npx = (int)mxGetScalar(tmpmxptr); |
---|
488 | else |
---|
489 | mexErrMsgTxt("Required field 'NumOfMonoPx' was not found in the element data structure"); |
---|
490 | tmpmxptr=mxGetField(prhs[0],0,"MapY"); |
---|
491 | if(tmpmxptr) |
---|
492 | y = mxGetPr(tmpmxptr); |
---|
493 | else |
---|
494 | mexErrMsgTxt("Required field 'MapY' was not found in the element data structure"); |
---|
495 | tmpmxptr=mxGetField(prhs[0],0,"NumOfMonoY"); |
---|
496 | if(tmpmxptr) |
---|
497 | ny = (int)mxGetScalar(tmpmxptr); |
---|
498 | else |
---|
499 | mexErrMsgTxt("Required field 'NumOfMonoY' was not found in the element data structure"); |
---|
500 | tmpmxptr=mxGetField(prhs[0],0,"MapPy"); |
---|
501 | if(tmpmxptr) |
---|
502 | py = mxGetPr(tmpmxptr); |
---|
503 | else |
---|
504 | mexErrMsgTxt("Required field 'MapPy' was not found in the element data structure"); |
---|
505 | tmpmxptr=mxGetField(prhs[0],0,"NumOfMonoPy"); |
---|
506 | if(tmpmxptr) |
---|
507 | npy = (int)mxGetScalar(tmpmxptr); |
---|
508 | else |
---|
509 | mexErrMsgTxt("Required field 'NumOfMonoPy' was not found in the element data structure"); |
---|
510 | tmpmxptr=mxGetField(prhs[0],0,"MapDelta"); |
---|
511 | if(tmpmxptr) |
---|
512 | delta = mxGetPr(tmpmxptr); |
---|
513 | else |
---|
514 | mexErrMsgTxt("Required field 'MapDelta' was not found in the element data structure"); |
---|
515 | tmpmxptr=mxGetField(prhs[0],0,"NumOfMonoDelta"); |
---|
516 | if(tmpmxptr) |
---|
517 | ndelta = (int)mxGetScalar(tmpmxptr); |
---|
518 | else |
---|
519 | mexErrMsgTxt("Required field 'NumOfMonoDelta' was not found in the element data structure"); |
---|
520 | tmpmxptr=mxGetField(prhs[0],0,"MapT"); |
---|
521 | if(tmpmxptr) |
---|
522 | t = mxGetPr(tmpmxptr); |
---|
523 | else |
---|
524 | mexErrMsgTxt("Required field 'MapT' was not found in the element data structure"); |
---|
525 | tmpmxptr=mxGetField(prhs[0],0,"NumOfMonoT"); |
---|
526 | if(tmpmxptr) |
---|
527 | nt = (int)mxGetScalar(tmpmxptr); |
---|
528 | else |
---|
529 | mexErrMsgTxt("Required field 'NumOfMonoT' was not found in the element data structure"); |
---|
530 | tmpmxptr=mxGetField(prhs[0],0,"R1"); |
---|
531 | if(tmpmxptr) |
---|
532 | pr1 = mxGetPr(tmpmxptr); |
---|
533 | else |
---|
534 | mexErrMsgTxt("Required field 'R1' was not found in the element data structure"); |
---|
535 | tmpmxptr=mxGetField(prhs[0],0,"R2"); |
---|
536 | if(tmpmxptr) |
---|
537 | pr2 = mxGetPr(tmpmxptr); |
---|
538 | else |
---|
539 | mexErrMsgTxt("Required field 'R2' was not found in the element data structure"); |
---|
540 | tmpmxptr=mxGetField(prhs[0],0,"T1"); |
---|
541 | if(tmpmxptr) |
---|
542 | pt1 = mxGetPr(tmpmxptr); |
---|
543 | else |
---|
544 | mexErrMsgTxt("Required field 'T1' was not found in the element data structure"); |
---|
545 | tmpmxptr=mxGetField(prhs[0],0,"T2"); |
---|
546 | if(tmpmxptr) |
---|
547 | pt2 = mxGetPr(tmpmxptr); |
---|
548 | else |
---|
549 | mexErrMsgTxt("Required field 'T2' was not found in the element data structure"); |
---|
550 | plhs[0] = mxDuplicateArray(prhs[1]); |
---|
551 | r_in = mxGetPr(plhs[0]); |
---|
552 | TaylormapPass2(r_in, le, no, nv, x, nx, px, npx, y, ny, py, npy, delta, ndelta, t, nt, |
---|
553 | pt1, pt2, pr1, pr2, n); |
---|
554 | } |
---|