anchor.diff:          endif
           ! the complement
           f2=1-f1
  -        
  +
           ! note that the final weights are a mixture of the x and y weights
           bilin_weights=(/x1*f2,x0*f2,x3*f1,x2*f1/)
       end function bilin_weights
  -    
  +
       !>------------------------------------------------------------
       !! Find the minimum x
       !! Takes a point (yi,xi) and a set of 4 surrounding points (y[4],x[4]) as input
  -    !! 
  +    !!
       !! Example : xw = minxw(xw,lo%lon,xc,yc,lon)
       !!
  -    !! @param   real    yi  input y location to interpolate to. 
  -    !! @param   real    y   Array of surrounding y-locations to interpolate from. 
  -    !! @param   real    xi  input x location to interpolate to. 
  -    !! @param   real    x   Array of surrounding x-locations to interpolate from. 
  +    !! @param   real    yi  input y location to interpolate to.
  +    !! @param   real    y   Array of surrounding y-locations to interpolate from.
  +    !! @param   real    xi  input x location to interpolate to.
  +    !! @param   real    x   Array of surrounding x-locations to interpolate from.
       !! @retval  real    weights
       !!
  -    !!------------------------------------------------------------     
  +    !!------------------------------------------------------------
       integer function minxw(xw,longrid,xpos,ypos,lon)
           implicit none
           integer, intent(in)::xw,xpos,ypos
           real,intent(in)::longrid(:,:),lon
           real::curdist,dx
           integer::nx
  -        
  +
           nx=size(longrid,1)
           curdist=abs(lon-longrid(xpos,ypos))
           if (xpos<nx) then
  
positive.code:         endif
          ! the weights for the other x are just the complement
          x3=1-x2
          
          ! now compute the y interpolation weights
          ! first find the y locations after performing the x interpolation
          y5=y(0)*x1+y(1)*x0
  
negative.code:         !       yc=ny/2
          xc = lastpos%x
          yc = lastpos%y
  
          x = lo%lon(xc,yc)
          y = lo%lat(xc,yc)
  
          ! steps to take = the difference the between the current point and the input point / dx
          xstep = (lon-x)/dx
          ystep = (lat-y)/dy
  
          ! CASE 1 assume a quasi regular dx/dy and caluate new location
          !  while we need to step by more than one grid cell, iterate
          !  if the grid is highly regular, we will only iterate 1-2x, highly irregular might require more iterations
          !  in the diabolical case, this could fail?
          !  in most cases this succeeds with a few iterations.
          iterations = 0
          do while (((abs(xstep)>1).or.(abs(ystep)>1)).and.iterations<20)
              iterations = iterations+1
  