anchor.diff:  
       ! Initialize values
       p%on_wall = .false.
  -    p%on_wall_id = 0
  +    p%on_wall_id = no_wall
   
       ! Find whether the photon is on an x-wall
       if(p%v%x > 0._dp) then
          if(p%r%x == geo%w1(p%icell%i1)) then
  -          p%on_wall_id = combine_wall(p%on_wall_id, 1)
  +          p%on_wall_id%w1 = -1
          else if(p%r%x == geo%w1(p%icell%i1 + 1)) then
  -          p%on_wall_id = combine_wall(p%on_wall_id, 1)
  +          p%on_wall_id%w1 = -1
             p%icell%i1 = p%icell%i1 + 1
          end if
       else if(p%v%x < 0._dp) then
          if(p%r%x == geo%w1(p%icell%i1)) then
  -          p%on_wall_id = combine_wall(p%on_wall_id, 2)
  +          p%on_wall_id%w1 = +1
             p%icell%i1 = p%icell%i1 - 1
          else if(p%r%x == geo%w1(p%icell%i1 + 1)) then
  -          p%on_wall_id = combine_wall(p%on_wall_id, 2)
  +          p%on_wall_id%w1 = +1
          end if
       end if
   
       ! Find whether the photon is on a y-wall
       if(p%v%y > 0._dp) then
          if(p%r%y == geo%w2(p%icell%i2)) then
  -          p%on_wall_id = combine_wall(p%on_wall_id, 3)
  +          p%on_wall_id%w2 = -1
          else if(p%r%y == geo%w2(p%icell%i2 + 1)) then
  -          p%on_wall_id = combine_wall(p%on_wall_id, 3)
  +          p%on_wall_id%w2 = -1
             p%icell%i2 = p%icell%i2 + 1
          end if
       else if(p%v%y < 0._dp) then
          if(p%r%y == geo%w2(p%icell%i2)) then
  -          p%on_wall_id = combine_wall(p%on_wall_id, 4)
  +          p%on_wall_id%w2 = +1
             p%icell%i2 = p%icell%i2 - 1
          else if(p%r%y == geo%w2(p%icell%i2 + 1)) then
  -          p%on_wall_id = combine_wall(p%on_wall_id, 4)
  +          p%on_wall_id%w2 = +1
          end if
       end if
   
       ! Find whether the photon is on a z-wall
       if(p%v%z > 0._dp) then
          if(p%r%z == geo%w3(p%icell%i3)) then
  -          p%on_wall_id = combine_wall(p%on_wall_id, 5)
  +          p%on_wall_id%w3 = -1
          else if(p%r%z == geo%w3(p%icell%i3 + 1)) then
  -          p%on_wall_id = combine_wall(p%on_wall_id, 5)
  +          p%on_wall_id%w3 = -1
             p%icell%i3 = p%icell%i3 + 1
          end if
       else if(p%v%z < 0._dp) then
          if(p%r%z == geo%w3(p%icell%i3)) then
  -          p%on_wall_id = combine_wall(p%on_wall_id, 6)
  +          p%on_wall_id%w3 = +1
             p%icell%i3 = p%icell%i3 - 1
          else if(p%r%z == geo%w3(p%icell%i3 + 1)) then
  -          p%on_wall_id = combine_wall(p%on_wall_id, 6)
  -       end if
  -    end if
  -
  -    p%on_wall = p%on_wall_id > 0
  +          p%on_wall_id%w3 = +1
  +       end if
  +    end if
  +
  +    p%on_wall = p%on_wall_id%w1 /= 0 .or. p%on_wall_id%w2 /= 0 .or. p%on_wall_id%w3 /= 0
   
     end subroutine adjust_wall
   
  
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
  
  