anchor.diff:          else if(y1<=1.d0) then ! at south end of domain
               if(doperiodic==2) then ! using periodic boundary conditions
                   y1 = dble(imt-1) ! place drifter at the north end of the domain
  +                jb = idint(y1)+1 ! need to update grid index too
               else ! not using periodic boundary conditions
                   y1 = 1.d0
                   flag(ntrac) = 1
  
positive.code:         else if(x1>=imt-1) then ! at east end of domain
              if(doperiodic==1) then ! using periodic boundary conditions
                  x1 = 1.d0 ! place drifter at the west end of the domain
              else ! not using periodic boundary conditions
                  x1 = dble(imt-1)
                  flag(ntrac) = 1
  
negative.code:         ! === end trajectory if outside chosen domain ===
          ! Note that these are combined with checking for drifters having exited the
          ! domain since if using doperiodic in a direction, it cannot exit.
          ! Also note that I don't think drifters can actually have values outside the box [1,imt-1,1,jmt-1]
          if(x1<=1.d0) then ! at west end of domain
              if(doperiodic==1) then ! using periodic boundary conditions
                  x1 = dble(imt-1) ! place drifter at the east end of the domain
                  ib = idint(x1)+1 ! need to update grid index too
              else ! not using periodic boundary conditions
                  x1 = 1.d0
                  flag(ntrac) = 1
  