anchor.diff:  
       if(p%on_wall) then
   
  -       if(p%on_wall_id > 26 .or. p%on_wall_id < 1) then
  -          call warn("in_correct_cell","invalid on_wall_id")
  -          in_correct_cell = .false.
  -          return
  -       else
  -          in_correct_cell = .true.
  -       end if
  -
  -       select case(p%on_wall_id)
  -       case(1, 7, 9, 11, 13, 19, 21, 23, 25)
  +       in_correct_cell = .true.
  +
  +       if(p%on_wall_id%w1 == -1) then
             frac = (p%r%x - geo%w1(p%icell%i1)) / (geo%w1(p%icell%i1+1) - geo%w1(p%icell%i1))
             in_correct_cell = in_correct_cell .and. abs(frac) < 1.e-3_dp
  -       case(2, 8, 10, 12, 14, 20, 22, 24, 26)
  +       else if(p%on_wall_id%w1 == +1) then
             frac = (p%r%x - geo%w1(p%icell%i1+1)) / (geo%w1(p%icell%i1+1) - geo%w1(p%icell%i1))
             in_correct_cell = in_correct_cell .and. abs(frac) < 1.e-3_dp
  -       case default
  +       else
             in_correct_cell = in_correct_cell .and. icell_actual%i1 == p%icell%i1
  -       end select
  -
  -       select case(p%on_wall_id)
  -       case(3, 7, 8, 15, 17, 19, 20, 23, 24)
  +       end if
  +
  +       if(p%on_wall_id%w2 == -1) then
             frac = (p%r%y - geo%w2(p%icell%i2)) / (geo%w2(p%icell%i2+1) - geo%w2(p%icell%i2))
             in_correct_cell = in_correct_cell .and. abs(frac) < 1.e-3_dp
  -       case(4, 9, 10, 16, 18, 21, 22, 25, 26)
  +       else if(p%on_wall_id%w2 == +1) then
             frac = (p%r%y - geo%w2(p%icell%i2+1)) / (geo%w2(p%icell%i2+1) - geo%w2(p%icell%i2))
             in_correct_cell = in_correct_cell .and. abs(frac) < 1.e-3_dp
  -       case default
  +       else
             in_correct_cell = in_correct_cell .and. icell_actual%i2 == p%icell%i2
  -       end select
  -
  -       select case(p%on_wall_id)
  -       case(5, 11, 12, 15, 16, 19, 20, 21, 22)
  +       end if
  +
  +       if(p%on_wall_id%w3 == -1) then
             frac = (p%r%z - geo%w3(p%icell%i3)) / (geo%w3(p%icell%i3+1) - geo%w3(p%icell%i3))
             in_correct_cell = in_correct_cell .and. abs(frac) < 1.e-3_dp
  -       case(6, 13, 14, 17, 18, 23, 24, 25, 26)
  +       else if(p%on_wall_id%w3 == +1) then
             frac = (p%r%z - geo%w3(p%icell%i3+1)) / (geo%w3(p%icell%i3+1) - geo%w3(p%icell%i3))
             in_correct_cell = in_correct_cell .and. abs(frac) < 1.e-3_dp
  -       case default
  +       else
             in_correct_cell = in_correct_cell .and. icell_actual%i3 == p%icell%i3
  -       end select
  +       end if
   
       else
   
  
positive.code:     i2 = cell%i2
      i3 = cell%i3
      select case(direction)
      case(1, 7, 9, 11, 13, 19, 21, 23, 25)
         i1 = i1 - 1
      case(2, 8, 10, 12, 14, 20, 22, 24, 26)
         i1 = i1 + 1
      end select
      select case(direction)
      case(3, 7, 8, 15, 17, 19, 20, 23, 24)
         i2 = i2 - 1
      case(4, 9, 10, 16, 18, 21, 22, 25, 26)
         i2 = i2 + 1
      end select
      select case(direction)
      case(5, 11, 12, 15, 16, 19, 20, 21, 22)
         i3 = i3 - 1
      case(6, 13, 14, 17, 18, 23, 24, 25, 26)
         i3 = i3 + 1
      end select
      next_cell = new_grid_cell(i1, i2, i3, geo)
    end function next_cell
  
    logical function in_correct_cell(p)
  
  
negative.code: 
    logical :: debug = .false.
  
    real(dp) :: tmin, emin
    type(wall_id) :: imin
  
    public :: escaped
    interface escaped
       module procedure escaped_photon
       module procedure escaped_cell
    end interface escaped
  
    public :: next_cell
    interface next_cell
       module procedure next_cell_int
       module procedure next_cell_wall_id
    end interface next_cell
  
    public :: setup_grid_geometry
    type(grid_geometry_desc),public,target :: geo
  
  contains
  
  