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 | // Intel compiler |
---|
12 | #ifndef __APPLE_CC__ |
---|
13 | #pragma warning (disable:193) |
---|
14 | #pragma warning (disable:981) |
---|
15 | #pragma warning (disable:1572) |
---|
16 | #endif |
---|
17 | // LSN |
---|
18 | |
---|
19 | #define DOF (ss_dim/2) |
---|
20 | |
---|
21 | // defined in math.h |
---|
22 | //#define M_PI 3.14159265358979323846 // pi |
---|
23 | |
---|
24 | #ifndef LONG_MAX |
---|
25 | # define LONG_MAX ((long)(((unsigned long) -1) >> 1)) |
---|
26 | # define LONG_MIN (~LONG_MAX) |
---|
27 | #endif |
---|
28 | |
---|
29 | #define debug false |
---|
30 | |
---|
31 | #define S_SIZE 200 // max size for file name of a lattice file |
---|
32 | |
---|
33 | #define nv_ 6 |
---|
34 | |
---|
35 | #define mnp 400 |
---|
36 | |
---|
37 | // maximum number of LEGO blocks (Cell_nLoc) |
---|
38 | #define Cell_nLocMax 8000 |
---|
39 | |
---|
40 | // maximum number of families for Elem_NFam |
---|
41 | #define Elem_nFamMax 3000 |
---|
42 | |
---|
43 | // maximum number of kids */ |
---|
44 | #define nKidMax 1000 |
---|
45 | |
---|
46 | #define DBNameLen 39 |
---|
47 | |
---|
48 | #define NameLength 150 // maximum length of identifiers |
---|
49 | #define SymbolLength 15 // maximum length of element name |
---|
50 | |
---|
51 | #define blankname " " |
---|
52 | |
---|
53 | #define maxincl 5 |
---|
54 | #define maxfil 10 |
---|
55 | #define bigvectmax 4096 |
---|
56 | |
---|
57 | #define HOMmax 30 |
---|
58 | |
---|
59 | #define maxtransfmat 2000 |
---|
60 | #define maxkicks 5 |
---|
61 | |
---|
62 | |
---|
63 | const double c0 = 2.99792458e8; // speed of light in vacuum |
---|
64 | const double q_e = 1.60217733e-19; // electron charge |
---|
65 | const double m_e = 0.51099906e6; // electron rest mass [eV] |
---|
66 | const double mu_0 = 4.0*M_PI*1e-7; // permittivity of free space |
---|
67 | const double eps_0 = 1.0/(sqr(c0)*mu_0); // permeability of free space |
---|
68 | const double r_e = q_e/(4.0*M_PI*eps_0*m_e); // classical electron radius |
---|
69 | const double h_bar = 6.58211899e-16; // reduced Planck constant [eV] |
---|
70 | |
---|
71 | // const double max_ampl = 10.0; // [m] nsrl-ii |
---|
72 | const double max_ampl = 1.0; // [m] soleil |
---|
73 | |
---|
74 | |
---|
75 | enum pthicktype { thick = 0, thin = 1 }; |
---|
76 | |
---|
77 | enum PartsKind { drift = 0, Wigl = 1, Mpole = 2, Cavity = 3, marker = 4, |
---|
78 | undef = 5, Insertion = 6, FieldMap = 7, |
---|
79 | Spreader = 8, Recombiner = 9, Solenoid = 10 }; |
---|
80 | |
---|
81 | enum { All = 0, Dip = 1, Quad = 2, Sext = 3, Oct = 4, Dec = 5, Dodec = 6 }; |
---|
82 | |
---|
83 | enum { Horizontal = 1, Vertical = 2 }; |
---|
84 | |
---|
85 | enum { Meth_Linear = 0, Meth_First = 1, Meth_Second = 2, Meth_Fourth = 4, |
---|
86 | Meth_genfun = 5 }; |
---|
87 | |
---|
88 | typedef double svdarray[mnp]; |
---|
89 | typedef double svdmat[mnp][mnp]; |
---|
90 | |
---|
91 | typedef char str80[80]; |
---|
92 | |
---|
93 | typedef char alfa_[NameLength]; |
---|
94 | |
---|
95 | typedef long iVector2[2]; |
---|
96 | typedef double Vector2[2]; |
---|
97 | typedef double Vector3[3]; |
---|
98 | |
---|
99 | #define fitvectmax 200 |
---|
100 | typedef long fitvect[fitvectmax]; |
---|
101 | |
---|
102 | typedef char partsName[NameLength]; |
---|
103 | |
---|
104 | typedef char DBNameType[DBNameLen]; |
---|
105 | |
---|
106 | typedef double mpolArray[HOMmax+HOMmax+1]; |
---|
107 | |
---|
108 | |
---|
109 | typedef struct statusrec{ |
---|
110 | bool tuneflag, chromflag, codflag, mapflag, passflag, overflag, chambre; |
---|
111 | int lossplane; /* lost in: horizontal 1 |
---|
112 | vertical 2 |
---|
113 | longitudinal 3 */ |
---|
114 | } statusrec; |
---|
115 | |
---|
116 | |
---|
117 | extern bool stable; |
---|
118 | extern bool ErrFlag; |
---|
119 | extern bool trace, cellconcat, traceID; |
---|
120 | |
---|
121 | extern double Fdrift1, Fkick1, Fdrift2, Fkick2, crad, cfluc; |
---|
122 | |
---|
123 | extern str80 finame, /* input data file */ |
---|
124 | foname, /* output data file */ |
---|
125 | fname; /* temp file name */ |
---|
126 | |
---|
127 | extern FILE *fi, /* lattice input file */ |
---|
128 | *fo, /* lattice output file */ |
---|
129 | *psin[], /* program input file */ |
---|
130 | *psout, /* program output file*/ |
---|
131 | *prr[]; /* prr[1] : input, prr[2] : output */ |
---|
132 | |
---|
133 | extern statusrec status; |
---|
134 | |
---|
135 | |
---|
136 | extern int P_eof(FILE *f); |
---|
137 | |
---|
138 | extern int P_eoln(FILE *f); |
---|
139 | |
---|
140 | extern void GDiag(int n, double C, Matrix &A, Matrix &Ainv, Matrix &R, |
---|
141 | Matrix &M, double &Omega, double &Yalphac); |
---|
142 | extern void NormEigenVec(Matrix &Vr, Matrix &Vi, double *wr, double *wi, |
---|
143 | Matrix &t6a); |
---|
144 | |
---|
145 | extern void EigenVal(double (*Ai)[mnp], long n, double *wr, double *wi); |
---|
146 | |
---|
147 | extern void t2init(void); |
---|
148 | |
---|
149 | /****** for orbit correction *********/ |
---|
150 | extern void prt_gcmat(int bpm, int corr, int plane); |
---|
151 | |
---|
152 | extern void gcmat(int bpm, int corr, int plane); |
---|
153 | |
---|
154 | extern void lsoc(int niter, int bpm, int corr, int plane); |
---|
155 | |
---|
156 | |
---|
157 | /**** same as asctime in C without the \n at the end****/ |
---|
158 | char *asctime2(const struct tm *timeptr); |
---|
159 | struct tm* GetTime(void); |
---|
160 | uint32_t stampstop(uint32_t start); |
---|
161 | uint32_t stampstart(void); |
---|