66! This will handle open geometry lattices. In this case, dbeta/dpz and dalpha/dpz are are
77! taken to be what is set in the beginning element.
88!
9+ ! Note: If chrom_calc is to be repeatedly called, supplying low_E_lat, high_E_lat, low_E_orb, and/or high_E_orb will save time
10+ ! since memory will not have to be repeatedly allocated.
11+ !
912! Input:
1013! lat -- lat_struct: Lat
1114! delta_e -- real(rp): +/- Delta energy used for the calculation. Notice that the energy difference
@@ -35,7 +38,7 @@ subroutine chrom_calc (lat, delta_e, chrom_a, chrom_b, err_flag, &
3538
3639type (lat_struct), target :: lat
3740type (lat_struct), optional , target :: low_E_lat, high_E_lat
38- type (lat_struct), target :: this_lat
41+ type (lat_struct), target :: temp_lat
3942type (lat_struct), pointer :: lat2
4043type (coord_struct), allocatable , optional , target :: low_E_orb(:), high_E_orb(:)
4144type (coord_struct), optional :: orb0
@@ -53,7 +56,7 @@ subroutine chrom_calc (lat, delta_e, chrom_a, chrom_b, err_flag, &
5356integer nt, nm, stat, ix_br, ie, i0, ix_fix
5457
5558logical , optional , intent (out ) :: err_flag
56- logical err, used_this_lat
59+ logical err
5760
5861character (* ), parameter :: r_name = ' chrom_calc'
5962
@@ -78,14 +81,12 @@ subroutine chrom_calc (lat, delta_e, chrom_a, chrom_b, err_flag, &
7881nt = branch% n_ele_track
7982nm = branch% n_ele_max
8083
81- ! lower energy tune
84+ ! Low energy calc.
8285
8386if (present (low_E_lat)) then
8487 lat2 = > low_E_lat
85- used_this_lat = .false.
8688else
87- lat2 = > this_lat
88- used_this_lat = .true.
89+ lat2 = > temp_lat
8990endif
9091
9192lat2 = lat
@@ -171,20 +172,17 @@ subroutine chrom_calc (lat, delta_e, chrom_a, chrom_b, err_flag, &
171172branch% ele(i0:nm)% y% detap_dpz = branch2% ele(i0:nm)% y% etap
172173branch% ele(i0:nm)% z% detap_dpz = branch2% ele(i0:nm)% z% etap
173174
174- ! higher energy tune
175+ ! Higher energy lattice
175176
176177if (present (high_E_lat)) then
177178 lat2 = > high_E_lat
178- used_this_lat = .false.
179179else
180- lat2 = > this_lat
180+ lat2 = > temp_lat
181181endif
182182
183- if (.not. used_this_lat) then
184- lat2 = lat
185- branch2 = > lat2% branch(ix_br)
186- call set_on_off (rfcavity$, lat2, off$, ix_branch = ix_br)
187- endif
183+ lat2 = lat
184+ branch2 = > lat2% branch(ix_br)
185+ call set_on_off (rfcavity$, lat2, off$, ix_branch = ix_br)
188186
189187if (present (high_E_orb)) then
190188 call reallocate_coord (high_E_orb, branch% n_ele_max)
@@ -268,5 +266,6 @@ subroutine chrom_calc (lat, delta_e, chrom_a, chrom_b, err_flag, &
268266branch% ele(i0:nm)% z% detap_dpz = (branch2% ele(i0:nm)% z% etap - branch% ele(i0:nm)% z% detap_dpz) / dE
269267
270268if (present (err_flag)) err_flag = .false.
269+ if (.not. present (low_E_lat) .or. .not. present (high_E_lat)) call deallocate_lat_pointers(temp_lat)
271270
272271end subroutine
0 commit comments