source: TRACY3/trunk/tracy/tracy/src/prtmfile.cc @ 11

Last change on this file since 11 was 11, checked in by zhangj, 11 years ago
  • Property svn:executable set to *
File size: 7.1 KB
Line 
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 To generate a lattice flat file.
11
12 Type codes:
13
14 marker     -1
15 drift   0
16 multipole   1
17 cavity      2
18 thin kick   3
19 wiggler     4
20 kick_map    6
21
22 Integration methods:
23
24 fourth order symplectic integrator   4
25
26 Format:
27
28 name, family no, kid no, element no
29 type code, integration method, no of integration steps
30 vacuum apertures: xmin, xmax, ymin, ymax
31
32 The following lines follows depending on element type.
33
34 type
35
36 1)  drift:      L
37
38 2)  multipole: 
39 a.)  hor., ver. displacement, roll angle (design), roll angle (error);
40 b.)  L, 1/rho, entrance angle, exit angle, totoal magnet gap[m];
41 c.)  number of orders with nonzero field components, design field order
42 d.)  The last lines are the nonzero multipole components,
43 the format is:
44 n, Bn , An
45 where n is the field order, Bn is the upright
46 field component, Bn is the skew field component
47
48 3)  wiggler:    L [m], lambda [m]
49 no of harmonics
50 harm no, kxV [1/m], BoBrhoV [1/m], kxH, BoBrhoH, phi
51 ...
52
53 4)  cavity:     cavity voltage/beam energy [eV], omega/c, beam energy [eV]
54
55 5)  thin kick:  hor., ver. displacement, roll angle (total)
56 no of nonzero multipole coeff.
57 n, b , a
58 n   n
59 ...
60
61 6)   kick_map:   order <file name>
62
63 */
64
65#define snamelen 10
66
67// numerical type codes
68#define marker_   -1
69#define drift_     0
70#define mpole_     1
71#define cavity_    2
72#define thinkick_  3
73#define wiggler_   4
74#define kick_map_  6
75
76/******************************************************************************
77 void prtName(FILE *fp, const int i,
78 const int type, const int method, const int N)
79
80 Purpose:
81 Print out the general imformation of an element to a file
82
83 Input:
84 i                index number in the whole lattice
85 type             predefined integer number for different type of element
86 Type codes:
87 marker         -1
88 drift      0
89 multipole       1
90 cavity          2
91 thin kick       3
92 wiggler         4
93 kick_map        6
94
95 method             integrated method
96 N                  number of integration steps of the element
97
98 Output:
99 Output to the file as the first 3 lines in file "fp":
100
101 L1:      element name, family index, kid index, element index in the whole lattice
102 L2:      type code, integration method,  number of integration steps
103 L3:      vacuum apertures: xmin, xmax, ymin, ymax
104
105 Comments:
106 Called by prtmfile()
107 ******************************************************************************/
108void prtName(FILE *fp, const int i, const int type, const int method,
109    const int N) {
110  fprintf(fp, "%-15s %4ld %4ld %4d\n", Cell[i].Elem.PName, Cell[i].Fnum,
111      Cell[i].Knum, i);
112  fprintf(fp, " %3d %3d %3d\n", type, method, N);
113  fprintf(fp, " %23.16e %23.16e %23.16e %23.16e\n", Cell[i].maxampl[X_][0],
114      Cell[i].maxampl[X_][1], Cell[i].maxampl[Y_][0], Cell[i].maxampl[Y_][1]);
115}
116
117/******************************************************************************
118 void prtHOM(FILE *fp, const int n_design, const mpolArray PB, const int Order)
119
120 Purpose:
121 Print out all field component for multipole to a file
122
123 Input:
124 fp               file name
125 n_design         design order of multipole
126 PB               multipole field components arry, format is: n Bn An
127 Order            maximum order of multipole
128
129 Output:
130 None
131
132 Comments:
133 Called by prtmfile()
134 ******************************************************************************/
135void prtHOM(FILE *fp, const int n_design, const mpolArray PB, const int Order) {
136  int i = 0, nmpole = 0;
137
138  for (i = 1; i <= Order; i++) {
139    if ((PB[HOMmax - i] != 0.0) || (PB[HOMmax + i] != 0.0))
140      nmpole++;
141  }
142
143  fprintf(fp, "  %2d %2d\n", nmpole, n_design);
144
145  for (i = 1; i <= Order; i++) {
146    if ((PB[HOMmax - i] != 0.0) || (PB[HOMmax + i] != 0.0))
147      fprintf(fp, "%3d %23.16e %23.16e\n", i, PB[HOMmax + i], PB[HOMmax - i]);
148  }
149}
150
151/******************************************************************************
152 void prtmfile(const char mfile_dat[])
153
154 Purpose:
155 Print out flatfile;
156 print the lattice parameters in an external file.
157
158 Input:
159 fp           filename
160
161 Output:
162 None
163
164 Comments:
165
166 ******************************************************************************/
167void prtmfile(const char mfile_dat[]) {
168  int i, j;
169  FILE *mfile;
170
171  mfile = file_write(mfile_dat);
172  for (i = 0; i <= globval.Cell_nLoc; i++) {
173    switch (Cell[i].Elem.Pkind) {
174    case drift:
175      prtName(mfile, i, drift_, 0, 0);
176      fprintf(mfile, " %23.16e\n", Cell[i].Elem.PL);
177      break;
178    case Mpole:
179      if (Cell[i].Elem.PL != 0.0) {
180        prtName(mfile, i, mpole_, Cell[i].Elem.M->Pmethod, Cell[i].Elem.M->PN);
181        fprintf(mfile, " %23.16e %23.16e %23.16e %23.16e\n", Cell[i].dS[X_],
182            Cell[i].dS[Y_], Cell[i].Elem.M->PdTpar, Cell[i].Elem.M->PdTsys
183                + Cell[i].Elem.M->PdTrms * Cell[i].Elem.M->PdTrnd);
184        fprintf(mfile, " %23.16e %23.16e %23.16e %23.16e %23.16e  %23.16e %23.16e\n",
185            Cell[i].Elem.PL, Cell[i].Elem.M->Pirho, Cell[i].Elem.M->PTx1,
186            Cell[i].Elem.M->PTx2, Cell[i].Elem.M->PH1,Cell[i].Elem.M->PH2,Cell[i].Elem.M->Pgap);
187        prtHOM(mfile, Cell[i].Elem.M->n_design, Cell[i].Elem.M->PB,
188            Cell[i].Elem.M->Porder);
189      } else {
190        prtName(mfile, i, thinkick_, Cell[i].Elem.M->Pmethod,
191            Cell[i].Elem.M->PN);
192        fprintf(mfile, " %23.16e %23.16e %23.16e\n", Cell[i].dS[X_],
193            Cell[i].dS[Y_], Cell[i].Elem.M->PdTsys + Cell[i].Elem.M->PdTrms
194                * Cell[i].Elem.M->PdTrnd);
195        prtHOM(mfile, Cell[i].Elem.M->n_design, Cell[i].Elem.M->PB,
196            Cell[i].Elem.M->Porder);
197      }
198      break;
199    case Wigl:
200      prtName(mfile, i, wiggler_, Cell[i].Elem.W->Pmethod, Cell[i].Elem.W->PN);
201      fprintf(mfile, " %23.16e %23.16e\n", Cell[i].Elem.PL,
202          Cell[i].Elem.W->lambda);
203      fprintf(mfile, "%2d\n", Cell[i].Elem.W->n_harm);
204      for (j = 0; j < Cell[i].Elem.W->n_harm; j++) {
205        fprintf(mfile, "%2d %23.16e %23.16e %23.16e %23.16e %23.16e\n",
206            Cell[i].Elem.W->harm[j], Cell[i].Elem.W->kxV[j],
207            Cell[i].Elem.W->BoBrhoV[j], Cell[i].Elem.W->kxH[j],
208            Cell[i].Elem.W->BoBrhoH[j], Cell[i].Elem.W->phi[j]);
209      }
210      break;
211    case Cavity:
212      prtName(mfile, i, cavity_, 0, 0);
213      fprintf(mfile, " %23.16e %23.16e %d %23.16e\n", Cell[i].Elem.C->Pvolt
214          / (1e9 * globval.Energy), 2.0 * M_PI * Cell[i].Elem.C->Pfreq / c0,
215          Cell[i].Elem.C->Ph, 1e9 * globval.Energy);
216      break;
217    case marker:
218      prtName(mfile, i, marker_, 0, 0);
219      break;
220    case Insertion:
221      prtName(mfile, i, kick_map_, Cell[i].Elem.ID->Pmethod,
222          Cell[i].Elem.ID->PN);
223      if (Cell[i].Elem.ID->firstorder)
224        fprintf(mfile, " %3.1lf %1d %s\n", Cell[i].Elem.ID->scaling1, 1,
225            Cell[i].Elem.ID->fname1);
226      if (Cell[i].Elem.ID->secondorder)
227        fprintf(mfile, " %3.1lf %1d %s\n", Cell[i].Elem.ID->scaling1, 2,
228            Cell[i].Elem.ID->fname2);
229      break;
230    default:
231      fprintf(mfile, "prtmfile: unknown type\n");
232      break;
233    }
234  }
235  fclose(mfile);
236}
Note: See TracBrowser for help on using the repository browser.