@@ -36,6 +36,7 @@ subroutine bmad_parser (lat_file, lat, make_mats6, digested_read_ok, use_line, e
3636use wall3d_mod, dummy3 = > bmad_parser
3737use photon_target_mod, dummy4 = > bmad_parser
3838use ptc_interface_mod, only: set_ptc_com_pointers
39+ use fixer_mod, only: set_active_fixer
3940use random_mod
4041
4142implicit none
@@ -60,8 +61,8 @@ subroutine bmad_parser (lat_file, lat, make_mats6, digested_read_ok, use_line, e
6061integer , allocatable :: seq_indexx(:)
6162
6263integer :: ix_param_ele, ix_mad_beam_ele
63- integer ix_word, i_use, i, j, k, k2, n, ix, ix1, ix2, n_track
64- integer n_ele_use, digested_version, key, loop_counter, n_ic, n_con
64+ integer ix_word, i_use, i, j, k, k2, n, ix, ix1, ix2, n_track, ix_ele_fix
65+ integer n_ele_use, digested_version, key, loop_counter, n_ic, n_con, ix_set
6566integer iseq_tot, iyy, n_ele_max, n_multi, n0, n_ele, ixc, n_slave, n_loc
6667integer ib, ie, ib2, ie2, flip, n_branch, n_forks, i_loop, n_branch_max
6768integer , pointer :: n_max
@@ -95,6 +96,7 @@ subroutine bmad_parser (lat_file, lat, make_mats6, digested_read_ok, use_line, e
9596bp_com = bp_common_struct()
9697allocate (bp_com% lat_file_names(1 )) ! ! To get around an ifort bug in Versions 18+
9798bp_com% parser_name = ' bmad_parser' ! Used for error messages.
99+ bp_com% ix_fixer = 0 ! Used to indicate last fixer set on.
98100debug_line = ' '
99101err = .false.
100102
@@ -1158,6 +1160,22 @@ subroutine bmad_parser (lat_file, lat, make_mats6, digested_read_ok, use_line, e
11581160 return
11591161endif
11601162
1163+ ! Make sure there is only one active fixer
1164+
1165+ do n = 0 , ubound (lat% branch, 1 )
1166+ branch = > lat% branch(n)
1167+ ix_ele_fix = 0
1168+ ix_set = 0
1169+ do i = 0 , branch% n_ele_max
1170+ ele = > branch% ele(i)
1171+ if (ele% key /= beginning_ele$ .and. ele% key /= fixer$) cycle
1172+ if (.not. ele% is_on .or. ele% value(ix_fixer$) < ix_set) cycle
1173+ ix_set = nint (ele% value(ix_fixer$))
1174+ ix_ele_fix = i
1175+ enddo
1176+ call set_active_fixer(branch% ele(ix_ele_fix))
1177+ enddo
1178+
11611179! Bookkeeping...
11621180! Must do this before calling bmad_parser2 since after an expand_lattice command the lattice
11631181! file may contain references to dependent element parameters that are computed in lattice_bookkeeper.
0 commit comments