1 | /* Tracy-2 |
---|
2 | |
---|
3 | J. Bengtsson, CBP, LBL 1990 - 1994 Pascal version |
---|
4 | SLS, PSI 1995 - 1997 |
---|
5 | M. Boege SLS, PSI 1998 C translation |
---|
6 | L. Nadolski SOLEIL 2002 Link to NAFF, Radia field maps |
---|
7 | J. Bengtsson NSLS-II, BNL 2004 - |
---|
8 | |
---|
9 | */ |
---|
10 | |
---|
11 | #include "tracy_lib.h" |
---|
12 | |
---|
13 | #include "field.cc" |
---|
14 | |
---|
15 | #if ORDER == 1 |
---|
16 | // linear TPSA |
---|
17 | #include "tpsa_lin.cc" |
---|
18 | #include "tpsa_lin_pm.cc" |
---|
19 | #else |
---|
20 | // interface to M. Berz' TPSA |
---|
21 | #include "tpsa_for_pm.cc" |
---|
22 | #endif |
---|
23 | |
---|
24 | #include "mathlib.cc" |
---|
25 | |
---|
26 | #include "ety.cc" |
---|
27 | #include "eigenv.cc" |
---|
28 | |
---|
29 | #include "t2lat.cc" |
---|
30 | #include "t2elem.cc" |
---|
31 | #include "t2cell.cc" |
---|
32 | #include "t2ring.cc" |
---|
33 | |
---|
34 | #include "pascalio.cc" |
---|
35 | |
---|
36 | #include "lsoc.cc" //for COD correction |
---|
37 | #include "prtmfile.cc" |
---|
38 | #include "rdmfile.cc" |
---|
39 | |
---|
40 | #include "fft.cc" |
---|
41 | |
---|
42 | #include "physlib.cc" |
---|
43 | |
---|
44 | #include "naffutils.cc" |
---|
45 | |
---|
46 | #include "modnaff.cc" |
---|
47 | #include "radia2tracy.cc" |
---|
48 | #include "soleillib.cc" |
---|
49 | |
---|
50 | #include "nsls-ii_lib.cc" |
---|
51 | |
---|
52 | /* new added since 2010 at soleil */ |
---|
53 | #include "max4_lib.cc" |
---|
54 | #include "soleilcommon.cc" |
---|
55 | #include "read_script.cc" |
---|
56 | |
---|
57 | // Truncated Power Series Algebra (TPSA) |
---|
58 | const int nv_tps = ss_dim, // no of variables |
---|
59 | nd_tps = 3, // no of degrees of freedom |
---|
60 | ndpt_tps = 5, // index for delta, 0 for 6-D dynamics |
---|
61 | iref_tps = 0; /* file with resonances to be excluded from |
---|
62 | the map normal form: fort.7 */ |
---|
63 | double eps_tps = 1e-25; // floating point truncation |
---|
64 | |
---|
65 | |
---|
66 | // instantiate templates |
---|
67 | |
---|
68 | template class ss_vect<double> ; |
---|
69 | |
---|
70 | template class ss_vect<tps> ; |
---|
71 | |
---|
72 | template void GtoL(ss_vect<double> &, Vector2 &, Vector2 &, const double, |
---|
73 | const double, const double); |
---|
74 | |
---|
75 | template void GtoL(ss_vect<tps> &, Vector2 &, Vector2 &, const double, |
---|
76 | const double, const double); |
---|
77 | |
---|
78 | template void |
---|
79 | LtoG(ss_vect<tps> &, Vector2 &, Vector2 &, double, double, double); |
---|
80 | |
---|
81 | template void LtoG(ss_vect<double> &, Vector2 &, Vector2 &, double, double, |
---|
82 | double); |
---|
83 | |
---|
84 | template void p_rot(double, ss_vect<double> &); |
---|
85 | |
---|
86 | template void p_rot(double, ss_vect<tps> &); |
---|
87 | |
---|
88 | template void get_B2(const double, const double[], const ss_vect<double> &, |
---|
89 | double &, double &); |
---|
90 | |
---|
91 | template void get_B2(const double, const tps[], const ss_vect<tps> &, tps &, |
---|
92 | tps &); |
---|
93 | |
---|
94 | template void radiate(ss_vect<double> &, const double, const double, |
---|
95 | const double[]); |
---|
96 | |
---|
97 | template void radiate(ss_vect<tps> &, const double, const double, const tps[]); |
---|
98 | |
---|
99 | template void Drift(double, ss_vect<double> &); |
---|
100 | |
---|
101 | template void Drift(double, ss_vect<tps> &); |
---|
102 | |
---|
103 | template void bend_fringe(double, ss_vect<double> &); |
---|
104 | |
---|
105 | template void bend_fringe(double, ss_vect<tps> &); |
---|
106 | |
---|
107 | template static void EdgeFocus(double, double, double, ss_vect<double> &); |
---|
108 | |
---|
109 | template static void EdgeFocus(double, double, double, ss_vect<tps> &); |
---|
110 | |
---|
111 | template void quad_fringe(double, ss_vect<double> &); |
---|
112 | |
---|
113 | template void quad_fringe(double, ss_vect<tps> &); |
---|
114 | |
---|
115 | template void Drift_Pass(CellType &, ss_vect<double> &); |
---|
116 | |
---|
117 | template void Drift_Pass(CellType &, ss_vect<tps> &); |
---|
118 | |
---|
119 | template void thin_kick(int, double[], double, double, double, |
---|
120 | ss_vect<double> &); |
---|
121 | |
---|
122 | template void thin_kick(int, double[], double, double, double, ss_vect<tps> &); |
---|
123 | |
---|
124 | template void Mpole_Pass(CellType &, ss_vect<double> &); |
---|
125 | |
---|
126 | template void Mpole_Pass(CellType &, ss_vect<tps> &); |
---|
127 | |
---|
128 | template void Marker_Pass(CellType &, ss_vect<double> &); |
---|
129 | |
---|
130 | template void Marker_Pass(CellType &, ss_vect<tps> &); |
---|
131 | |
---|
132 | template void Cav_Pass(CellType &, ss_vect<double> &); |
---|
133 | |
---|
134 | template void Cav_Pass(CellType &, ss_vect<tps> &); |
---|
135 | |
---|
136 | template void Wiggler_pass_EF(const elemtype &elem, ss_vect<double> &x); |
---|
137 | |
---|
138 | template void Wiggler_pass_EF(const elemtype &elem, ss_vect<tps> &x); |
---|
139 | |
---|
140 | template void Wiggler_pass_EF2(int nstep, double L, double kxV, double kxH, |
---|
141 | double kz, double BoBrhoV, double BoBrhoH, double phi, ss_vect<double> &x); |
---|
142 | |
---|
143 | template void Wiggler_pass_EF2(int nstep, double L, double kxV, double kxH, |
---|
144 | double kz, double BoBrhoV, double BoBrhoH, double phi, ss_vect<tps> &x); |
---|
145 | |
---|
146 | template void Wiggler_pass_EF3(const elemtype &elem, ss_vect<double> &x); |
---|
147 | |
---|
148 | template void Wiggler_pass_EF3(const elemtype &elem, ss_vect<tps> &x); |
---|
149 | |
---|
150 | template void Wiggler_Pass(CellType &, ss_vect<double> &); |
---|
151 | |
---|
152 | template void Wiggler_Pass(CellType &, ss_vect<tps> &); |
---|
153 | |
---|
154 | template void FieldMap_Pass(CellType &, ss_vect<double> &); |
---|
155 | |
---|
156 | template void FieldMap_Pass(CellType &, ss_vect<tps> &); |
---|
157 | |
---|
158 | template void sol_pass(const elemtype &, ss_vect<double> &); |
---|
159 | |
---|
160 | template void sol_pass(const elemtype &, ss_vect<tps> &); |
---|
161 | |
---|
162 | template void Solenoid_Pass(CellType &, ss_vect<double> &); |
---|
163 | |
---|
164 | template void Solenoid_Pass(CellType &, ss_vect<tps> &); |
---|
165 | |
---|
166 | template void LinearInterpolation2(double &, double &, double &, double &, |
---|
167 | CellType &, bool &, int); |
---|
168 | |
---|
169 | template void LinearInterpolation2(tps &, tps &, tps &, tps &, CellType &, |
---|
170 | bool &, int); |
---|
171 | |
---|
172 | template void SplineInterpolation2(double &, double &, double &, double &, |
---|
173 | CellType &, bool &, int); |
---|
174 | |
---|
175 | template void SplineInterpolation2(tps &, tps &, tps &, tps &, CellType &, |
---|
176 | bool &, int); |
---|
177 | |
---|
178 | template void spline(const double[], const double[], int const, double const, |
---|
179 | const double, double[]); |
---|
180 | |
---|
181 | template void spline(const double[], const tps[], int const, double const, |
---|
182 | const double, tps[]); |
---|
183 | |
---|
184 | template void splint(const double[], const double[], const double[], const int, |
---|
185 | const double &, double &); |
---|
186 | |
---|
187 | template void splint(const double[], const double[], const double[], const int, |
---|
188 | const tps &, tps &); |
---|
189 | |
---|
190 | template void splint(const double[], const tps[], const tps[], const int, |
---|
191 | const tps &, tps &); |
---|
192 | |
---|
193 | template void splin2(const double[], const double[], double **, double **, |
---|
194 | const int, const int, const double &, const double &, double &); |
---|
195 | |
---|
196 | template void splin2(const double[], const double[], double **, double **, |
---|
197 | const int, const int, const tps &, const tps &, tps &); |
---|
198 | |
---|
199 | template void Insertion_Pass(CellType &, ss_vect<double> &); |
---|
200 | |
---|
201 | template void Insertion_Pass(CellType &, ss_vect<tps> &); |
---|
202 | |
---|
203 | template void Elem_Pass(const long, ss_vect<double> &); |
---|
204 | |
---|
205 | template void Elem_Pass(const long, ss_vect<tps> &); |
---|
206 | |
---|
207 | template void Cell_Pass(const long, const long, ss_vect<double> &, long &); |
---|
208 | |
---|
209 | template void Cell_Pass(const long, const long, ss_vect<tps> &, long &); |
---|
210 | |
---|
211 | /* Global variable used through the code */ |
---|
212 | globvalrec globval; |
---|
213 | |
---|
214 | statusrec status; |
---|
215 | bool trace, traceID; |
---|
216 | bool cellconcat; |
---|
217 | |
---|
218 | /* Random stuff */ |
---|
219 | long rseed0, rseed; |
---|
220 | double normcut_; |
---|
221 | |
---|
222 | double d_sign(double a, double b) { |
---|
223 | double x; |
---|
224 | |
---|
225 | x = (a >= 0 ? a : -a); |
---|
226 | return (b >= 0 ? x : -x); |
---|
227 | } |
---|
228 | |
---|
229 | int P_eof(FILE *f) { |
---|
230 | register int ch; |
---|
231 | |
---|
232 | if (feof(f)) |
---|
233 | return 1; |
---|
234 | if (f == stdin) |
---|
235 | return 0; /* not safe to look-ahead on the keyboard! */ |
---|
236 | ch = getc(f); |
---|
237 | if (ch == EOF) |
---|
238 | return 1; |
---|
239 | ungetc(ch, f); |
---|
240 | |
---|
241 | return 0; |
---|
242 | } |
---|
243 | |
---|
244 | /* Check if at end of line (or end of entire file). */ |
---|
245 | |
---|
246 | int P_eoln(FILE *f) { |
---|
247 | register int ch; |
---|
248 | |
---|
249 | ch = getc(f); |
---|
250 | if (ch == EOF) |
---|
251 | return 1; |
---|
252 | ungetc(ch, f); |
---|
253 | return (ch == '\n'); |
---|
254 | } |
---|