diff --git a/bmad/multiparticle/wake_mod.f90 b/bmad/multiparticle/wake_mod.f90 index 391ba8fb8..b1222bdb7 100644 --- a/bmad/multiparticle/wake_mod.f90 +++ b/bmad/multiparticle/wake_mod.f90 @@ -578,12 +578,12 @@ subroutine sr_z_long_wake (ele, bunch, z_ave) p => bunch%particle(i) if (p%state /= alive$) cycle - rz_rel = sr%z_scale * (p%vec(5) - z_ave) / srz%dz + 1 - ix1 = floor(rz_rel) - ix2 = ix1 + 1 + rz_rel = sr%z_scale * (p%vec(5) - z_ave) / srz%dz + n2 + 1 + ix1 = MOD(floor(rz_rel) + n2 - 1, nn) + 1 + ix2 = MOD(ix1, nn) + 1 - r1 = ix2 - rz_rel - r2 = rz_rel - ix1 + r2 = MOD(rz_rel, 1.0_rp) + r1 = 1 - r2 select case (srz%position_dependence) case (none$, x_leading$, y_leading$)