subroutine check_for_m5_to_inj_patch(lat, initial_offsets) use bmad use muon_mod implicit none type(lat_struct) lat type (ele_struct) patch_ele type (initial_offsets_struct) initial_offsets integer i,key, sub_key,insert_index ! Check to see if there is a patch element before the start of the injection channel do i=1,lat%branch(0)%n_ele_track if(index(lat%branch(0)%ele(i)%name,'BACKLEG_START')/=0)return if(lat%branch(0)%ele(i)%key == patch$) then print *,' The patch element is ',i,lat%branch(0)%ele(i)%name print '(a,6es12.4)',' initial_offsets before patch =',initial_offsets initial_offsets%x_mean = initial_offsets%x_mean + lat%branch(0)%ele(i)%value(x_offset$) initial_offsets%pxmean = initial_offsets%pxmean + lat%branch(0)%ele(i)%value(x_pitch$) initial_offsets%y_mean = initial_offsets%y_mean + lat%branch(0)%ele(i)%value(y_offset$) initial_offsets%pymean = initial_offsets%pymean + lat%branch(0)%ele(i)%value(y_pitch$) print '(a,6es12.4)',' initial_offsets = after patch',initial_offsets return endif end do ! If there is no patch, then add one here ! insert_index=1 ! key=patch$ ! sub_key = ! call init_ele(patch_ele,key = key, sub_key=sub+key, branch=0) ! call insert_element(lat, patch_ele, insert_index,ix_branch=0) ! patch_ele%name = 'M5_TO_INJ' !end do !print *,'There is a problem in check_for_m5_to_inj_patch' !stop return end