1 | !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
---|
2 | !-----These subroutines are called from C to manage PTC |
---|
3 | !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
---|
4 | |
---|
5 | subroutine ptc_init(p_in_file) |
---|
6 | |
---|
7 | USE madx_ptc_module |
---|
8 | ! use accel_ptc |
---|
9 | IMPLICIT NONE |
---|
10 | |
---|
11 | character p_in_file*128 |
---|
12 | TYPE(LAYOUT), POINTER :: o_ring |
---|
13 | integer i,j |
---|
14 | real(dp) x(6) |
---|
15 | logical exists |
---|
16 | character*20 file0 |
---|
17 | ! type(mad_universe),target:: orbit_universe |
---|
18 | ! M_U=>orbit_universe |
---|
19 | |
---|
20 | write (*,*) "=============PTC INIT=====START===========" |
---|
21 | ! allocate(m_u) |
---|
22 | ! call set_up_universe(m_u) |
---|
23 | ! allocate(m_t) |
---|
24 | ! call set_up_universe(m_t) |
---|
25 | call ptc_ini_no_append() |
---|
26 | |
---|
27 | !old allocate(m_u) |
---|
28 | !old call set_up_universe(m_u) |
---|
29 | ! call APPEND_EMPTY_LAYOUT(m_u) |
---|
30 | ! call READ_INTO_VIRGIN_LAYOUT(m_u%start,p_in_file,lmax=lmax) |
---|
31 | |
---|
32 | |
---|
33 | N_CAV4_F=3 |
---|
34 | CALL READ_AND_APPEND_VIRGIN_general(m_u,p_in_file,lmax0=lmax) |
---|
35 | ! call READ_INTO_VIRGIN_LAYOUT(m_u%start,p_in_file,lmax=lmax) |
---|
36 | |
---|
37 | |
---|
38 | file0="pre_orbit_set.txt" |
---|
39 | INQUIRE (FILE = file0, EXIST = exists) |
---|
40 | |
---|
41 | if(exists) then |
---|
42 | call read_ptc_command77(file0) |
---|
43 | endif |
---|
44 | o_ring=>m_U%end |
---|
45 | |
---|
46 | call MAKE_NODE_LAYOUT(o_ring) |
---|
47 | if(lmax==zero) then |
---|
48 | write(6,*) " Error lmax = 0 " |
---|
49 | ! pause |
---|
50 | stop 777 |
---|
51 | endif |
---|
52 | |
---|
53 | |
---|
54 | if(lmax>0) then |
---|
55 | CALL ORBIT_MAKE_NODE_LAYOUT(o_ring,my_true) |
---|
56 | else |
---|
57 | lmax=-lmax |
---|
58 | CALL ORBIT_MAKE_NODE_LAYOUT(o_ring,my_false) |
---|
59 | endif |
---|
60 | |
---|
61 | write(6,*) " $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" |
---|
62 | write(6,*) " ORBIT_USE_ORBIT_UNITS ",my_ORBIT_LATTICE%ORBIT_USE_ORBIT_UNITS |
---|
63 | write(6,*) " ORBIT_N_NODE ",my_ORBIT_LATTICE%ORBIT_N_NODE |
---|
64 | write(6,*) " ORBIT_WARNING ",my_ORBIT_LATTICE%ORBIT_WARNING |
---|
65 | write(6,*) " ORBIT_OMEGA ",my_ORBIT_LATTICE%ORBIT_OMEGA |
---|
66 | write(6,*) " ORBIT_HARMONIC ",my_ORBIT_LATTICE%ORBIT_HARMONIC |
---|
67 | write(6,*) " ORBIT_P0C ",my_ORBIT_LATTICE%ORBIT_P0C |
---|
68 | write(6,*) " ORBIT_KINETIC ",my_ORBIT_LATTICE%ORBIT_KINETIC |
---|
69 | write(6,*) " ORBIT_MASS_IN_AMU ",my_ORBIT_LATTICE%ORBIT_MASS_IN_AMU |
---|
70 | write(6,*) " ORBIT_L ",my_ORBIT_LATTICE%ORBIT_L |
---|
71 | write(6,*) " ORBIT_GAMMAT ",my_ORBIT_LATTICE%ORBIT_GAMMAT |
---|
72 | write(6,*) " ORBIT_CHARGE ",my_ORBIT_LATTICE%ORBIT_CHARGE |
---|
73 | write(6,*) " ORBIT_LMAX AND LMAX ",my_ORBIT_LATTICE%ORBIT_LMAX,LMAX |
---|
74 | write(6,*) " $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" |
---|
75 | ! MY_STATE=>my_orbit_lattice%state |
---|
76 | ! MY_ORBIT_STATE=>MY_STATE |
---|
77 | CAVITY_TOTALPATH=0 |
---|
78 | |
---|
79 | return |
---|
80 | end |
---|
81 | |
---|
82 | !=================================================== |
---|
83 | !reads additional ptc commands from file and execute them inside ptc |
---|
84 | !=================================================== |
---|
85 | subroutine ptc_script(p_in_file) |
---|
86 | |
---|
87 | USE orbit_ptc |
---|
88 | USE pointer_lattice |
---|
89 | IMPLICIT NONE |
---|
90 | |
---|
91 | character p_in_file*128 |
---|
92 | |
---|
93 | CALL read_ptc_command(p_in_file) |
---|
94 | |
---|
95 | end subroutine ptc_script |
---|
96 | |
---|
97 | !=================================================== |
---|
98 | !get initial twiss at entrance of the ring |
---|
99 | !=================================================== |
---|
100 | subroutine ptc_get_twiss_init(bx,by,ax,ay,ex,epx) |
---|
101 | |
---|
102 | USE orbit_ptc |
---|
103 | IMPLICIT NONE |
---|
104 | REAL(DP) bx,by,ax,ay,ex,epx |
---|
105 | |
---|
106 | INTEGER i |
---|
107 | REAL(DP) length |
---|
108 | |
---|
109 | call GET_N_NODE(i) |
---|
110 | call GET_info(i,length,bx,by,ax,ay,ex,epx) |
---|
111 | |
---|
112 | return |
---|
113 | end |
---|
114 | |
---|
115 | |
---|
116 | !=================================================== |
---|
117 | !get number of PTC ORBIT nodes, harmonic number, |
---|
118 | ! length of the ring, and gamma transition |
---|
119 | !=================================================== |
---|
120 | subroutine ptc_get_ini_params(nNodes,nHarm,lRing,gammaT) |
---|
121 | |
---|
122 | USE orbit_ptc |
---|
123 | IMPLICIT NONE |
---|
124 | REAL(DP) lRing,gammaT |
---|
125 | INTEGER nNodes,nHarm |
---|
126 | |
---|
127 | call GET_HARMONIC(nHarm) |
---|
128 | call GET_CIRCUMFERENCE(lRing) |
---|
129 | call GET_N_NODE(nNodes) |
---|
130 | call GET_GAMMAT(gammaT) |
---|
131 | |
---|
132 | return |
---|
133 | end |
---|
134 | |
---|
135 | !=================================================== |
---|
136 | !get synchronous particle params mass, charge, and energy |
---|
137 | !=================================================== |
---|
138 | subroutine ptc_get_syncpart(mass,charge,kin_energy) |
---|
139 | |
---|
140 | USE orbit_ptc |
---|
141 | IMPLICIT NONE |
---|
142 | REAL(DP) mass, kin_energy |
---|
143 | ! real(dp) charge |
---|
144 | integer charge |
---|
145 | |
---|
146 | call GET_MASS_AMU(mass) |
---|
147 | |
---|
148 | call GET_kinetic(kin_energy) |
---|
149 | call GET_CHARGE(charge) |
---|
150 | |
---|
151 | return |
---|
152 | end |
---|
153 | |
---|
154 | !=================================================== |
---|
155 | !get twiss and length for a node with index |
---|
156 | !=================================================== |
---|
157 | subroutine ptc_get_twiss_for_node(node_index, node_length, bx,by,ax,ay,ex,epx) |
---|
158 | |
---|
159 | USE orbit_ptc |
---|
160 | IMPLICIT NONE |
---|
161 | REAL(DP) node_length, bx,by,ax,ay,ex,epx |
---|
162 | INTEGER node_index |
---|
163 | |
---|
164 | INTEGER i |
---|
165 | i = node_index + 1 |
---|
166 | call GET_info(i,node_length,bx,by,ax,ay,ex,epx) |
---|
167 | |
---|
168 | return |
---|
169 | end |
---|
170 | |
---|
171 | |
---|
172 | !=================================================== |
---|
173 | !track 6D coordinates through the PTC-ORBIT node |
---|
174 | !=================================================== |
---|
175 | ! subroutine ptc_track_particle(node_index, x,xp,y,yp,phi,dE) |
---|
176 | ! |
---|
177 | ! USE orbit_ptc |
---|
178 | ! IMPLICIT NONE |
---|
179 | ! REAL(DP) x,xp,y,yp,phi,dE |
---|
180 | ! INTEGER node_index |
---|
181 | ! INTEGER i |
---|
182 | ! |
---|
183 | ! i = node_index + 1 |
---|
184 | ! |
---|
185 | ! call PUT_RAY(x,xp,y,yp,phi,dE) |
---|
186 | ! call TRACK_ONE_NODE(i) |
---|
187 | ! call GET_RAY(x,xp,y,yp,phi,dE) |
---|
188 | ! |
---|
189 | ! return |
---|
190 | ! end subroutine orbit_ptc_track_particle |
---|
191 | ! |
---|
192 | !=========================================================== |
---|
193 | ! This subroutine should be called before particle tracking. |
---|
194 | ! It specifies the type of the task that will be performed |
---|
195 | ! in ORBIT before particle tracking for particular node. |
---|
196 | ! i_task = 0 - do not do anything |
---|
197 | ! i_task = 1 - energy of the sync. particle changed |
---|
198 | !=========================================================== |
---|
199 | SUBROUTINE ptc_get_task_type(i_node,i_task) |
---|
200 | |
---|
201 | USE orbit_ptc |
---|
202 | IMPLICIT NONE |
---|
203 | INTEGER i_node,i_task |
---|
204 | INTEGER i_node1 |
---|
205 | |
---|
206 | i_node1 = i_node + 1 |
---|
207 | call GET_task(i_node1,i_task) |
---|
208 | |
---|
209 | END SUBROUTINE ptc_get_task_type |
---|
210 | |
---|
211 | !=================================================== |
---|
212 | !It returns the lowest frequency of the RF cavities |
---|
213 | !This will be used to transform phi to z[m] |
---|
214 | !=================================================== |
---|
215 | SUBROUTINE ptc_get_omega(x) |
---|
216 | |
---|
217 | USE orbit_ptc |
---|
218 | IMPLICIT NONE |
---|
219 | REAL(DP) x |
---|
220 | call GET_omega(x) |
---|
221 | |
---|
222 | END SUBROUTINE ptc_get_omega |
---|
223 | |
---|
224 | !=================================================== |
---|
225 | !It reads the acceleration table into the ptc code |
---|
226 | !=================================================== |
---|
227 | subroutine ptc_read_accel_table(p_in_file) |
---|
228 | |
---|
229 | IMPLICIT NONE |
---|
230 | character p_in_file*128 |
---|
231 | write(6,*) " This is just an ordinary Script now! " |
---|
232 | |
---|
233 | call read_ptc_command77(p_in_file) |
---|
234 | |
---|
235 | END SUBROUTINE ptc_read_accel_table |
---|
236 | |
---|
237 | SUBROUTINE ptc_synchronous_set(i_node) |
---|
238 | IMPLICIT NONE |
---|
239 | integer i_node |
---|
240 | ! write(6,*) " Not needed anymore " |
---|
241 | end SUBROUTINE ptc_synchronous_set |
---|
242 | |
---|
243 | SUBROUTINE ptc_synchronous_after(i_node) |
---|
244 | use pointer_lattice |
---|
245 | IMPLICIT NONE |
---|
246 | integer i_node |
---|
247 | |
---|
248 | if(i_node==-100) then |
---|
249 | write(6,*) " ********************************************************* " |
---|
250 | write(6,*) " " |
---|
251 | write(6,*) " Orbit State is Printed " |
---|
252 | if(accelerate) then |
---|
253 | write(6,*) "Acceleration is turned ON " |
---|
254 | else |
---|
255 | write(6,*) "Acceleration is turned OFF " |
---|
256 | endif |
---|
257 | write(6,*) " " |
---|
258 | call print(my_ORBIT_LATTICE%state,6) |
---|
259 | write(6,*) " ********************************************************* " |
---|
260 | else |
---|
261 | ! write(6,*) " ptc_synchronous_after not needed anymore " |
---|
262 | endif |
---|
263 | end SUBROUTINE ptc_synchronous_after |
---|
264 | |
---|