anchor.diff:    integer, intent(in) :: ix
     integer, intent(in) :: n
     
  -  real(kind=fPrec) xx, yy, rr, frr, dxp, dyp
  +  real(kind=fPrec) xx, yy, rr, dxp, dyp
     real(kind=fPrec) theta, radio, angle_rad
  -  integer          j
  +  integer          jj
     logical          lrotate
   
     ! rotation angle
     lrotate = cheby_angle(icheby(ix)).ne.zero
     angle_rad = (cheby_angle(icheby(ix))/c180e0)*pi
   
  -  do j=1,napx
  +  do jj=1,napx
   
       ! apply offset
  -    xx=xv1(j)-cheby_offset_x(icheby(ix))
  -    yy=xv2(j)-cheby_offset_y(icheby(ix))
  +    xx=xv1(jj)-cheby_offset_x(icheby(ix))
  +    yy=xv2(jj)-cheby_offset_y(icheby(ix))
   
       ! check that particle is within the domain of chebyshev polynomials
       rr=sqrt(xx**2+yy**2)
  
positive.code: 
    ! temp vars
    real(kind=fPrec) :: uu, vv, Tx (0:cheby_maxOrder(iTable)), Ty (0:cheby_maxOrder(iTable)), &
                        kx, ky, Tpx(0:cheby_maxOrder(iTable)), Tpy(0:cheby_maxOrder(iTable)), &
                        fu, fv
    integer          :: nn, jj
  
    ! normalised variables
  
negative.code:       cheby_r1(jj)=tmpFlt
      end if
      if (cheby_r2(jj)>cheby_refR(cheby_itable(jj))) then
        write(lout,"(a)")      "CHEBY> ERROR R2 cannot be larger than domain of Chebyshev polynomials!"
        goto 10 
      end if
      if (cheby_I (jj)<=zero) then
        cheby_I (jj)=cheby_refI(cheby_itable(jj))
      else
        cheby_scalingFact(jj)=cheby_scalingFact(jj)*((cheby_I(jj))/(cheby_refI(cheby_itable(jj))))
      end if
     
      ! checks on maps
      if ( cheby_lMap(jj) ) then
        if (cheby_mapXmax(jj)<cheby_mapXmin(jj)) then
          ! swap
          tmpFlt=cheby_mapXmax(jj)
          cheby_mapXmax(jj)=cheby_mapXmin(jj)
          cheby_mapXmin(jj)=tmpFlt
        end if
        if (cheby_mapXmax(jj)==cheby_mapXmin(jj)) then
          write(lout,"(a)")                     "CHEBY> ERROR X-extremes for map coincide!"
          write(lout,"(a,1pe22.15,a,1pe22.15)") "CHEBY>       xmin [mm]: ",cheby_mapXmin(jj), &
                                                          " - xmax [mm]: ",cheby_mapXmax(jj)
          goto 10 
        end if
        if (cheby_mapNx(jj)<1) then
          write(lout,"(a)")    "CHEBY> ERROR wrong X-stepping for map!"
          write(lout,"(a,i0)") "CHEBY>       must be >0 - got: ",cheby_mapNx(jj)
          goto 10 
        end if
        if (cheby_mapYmax(jj)<cheby_mapYmin(jj)) then
          ! swap
          tmpFlt=cheby_mapYmax(jj)
          cheby_mapYmax(jj)=cheby_mapYmin(jj)
          cheby_mapYmin(jj)=tmpFlt
        end if
        if (cheby_mapYmax(jj)==cheby_mapYmin(jj)) then
          write(lout,"(a)")                     "CHEBY> ERROR Y-extremes for map coincide!"
          write(lout,"(a,1pe22.15,a,1pe22.15)") "CHEBY>       ymin [mm]: ",cheby_mapYmin(jj), &
                                                          " - ymax [mm]: ",cheby_mapYmax(jj)
          goto 10 
        end if
        if (cheby_mapNy(jj)<1) then
          write(lout,"(a)")    "CHEBY> ERROR wrong Y-stepping for map!"
          write(lout,"(a,i0)") "CHEBY>       must be >0 - got: ",cheby_mapNy(jj)
          goto 10 
        end if
      end if
     
      if(st_quiet < 2) then
        write(lout,"(a)") ''
        write(lout,"(a,i0,a)") 'CHEBY> status of chebyshev lens #',jj," - name: '"//trim(bez(kk))//"'"
        write(lout,"(a)")          "CHEBY> - filename         : '"//trim(cheby_filename(cheby_itable(jj)))//"'"
        write(lout,"(a,1pe22.15)") "CHEBY> - R2           [mm]: ",cheby_r2(jj)
        write(lout,"(a,1pe22.15)") "CHEBY> - R1           [mm]: ",cheby_r1(jj)
        write(lout,"(a,1pe22.15)") "CHEBY> - tilt angle  [deg]: ",cheby_angle(jj)
        write(lout,"(a,1pe22.15)") "CHEBY> - hor offset   [mm]: ",cheby_offset_x(jj)
        write(lout,"(a,1pe22.15)") "CHEBY> - ver offset   [mm]: ",cheby_offset_y(jj)
        write(lout,"(a,1pe22.15)") "CHEBY> - lens powering [A]: ",cheby_I(jj)
        write(lout,"(a,1pe22.15)") "CHEBY> - scaling factor []: ",cheby_scalingFact(jj)
        if ( cheby_lMap(jj) ) then
          write(lout,"(a)") 'CHEBY> requested dump of potential map'
          write(lout,"(a,a)")        "CHEBY> - map filename : ",cheby_mapFileName(jj)
          write(lout,"(a,1pe22.15)") "CHEBY> - xmin     [mm]: ",cheby_mapXmin(jj)
          write(lout,"(a,1pe22.15)") "CHEBY> - xmax     [mm]: ",cheby_mapXmax(jj)
          write(lout,"(a,1pe22.15)") "CHEBY> - Nx         []: ",cheby_mapNx  (jj)
          write(lout,"(a,1pe22.15)") "CHEBY> - ymin     [mm]: ",cheby_mapYmin(jj)
          write(lout,"(a,1pe22.15)") "CHEBY> - ymin     [mm]: ",cheby_mapYmax(jj)
          write(lout,"(a,1pe22.15)") "CHEBY> - Ny         []: ",cheby_mapNy  (jj)
          call cheby_potentialMap(jj,kk)
        end if
      end if
    end do
    return
  
  10 continue
     write(lout,"(a,i0,a)") "CHEBY>       concerned lens #", jj," - name: '"//trim(bez(kk))//"'"
     write(lout,"(a,1pe22.15,a,1pe22.15)") "CHEBY>       R2 [mm]: ",cheby_r2(jj), &
             " - reference radius [mm]:",cheby_refR(cheby_itable(jj))
     call prror(-1)
     
  end subroutine cheby_postInput
  
  
  