anchor.diff:        goto 30
       end if
       cheby_maxOrder(ifile)=max(ii,jj,cheby_maxOrder(ifile))
  -    if ( cheby_maxOrder(ifile).gt.cheby_maxOrderFox-1 ) then
  +    if ( cheby_maxOrder(ifile).gt.cheby_maxNterms-1 ) then
         write(lerr,"(2(a,i0))") "CHEBY> ERROR order of map too high: ",cheby_maxOrder(ifile), &
  -                                            " >",cheby_maxOrderFox-1
  -      write(lerr,"(a)")       "CHEBY>       please increase cheby_maxOrderFox parameter"
  +                                            " >",cheby_maxNterms-1
  +      write(lerr,"(a)")       "CHEBY>       please increase cheby_maxNterms parameter"
         goto 30
       end if
   
  
positive.code: !FOX  DYP=ZERO ;
      do NN=0,morder
        do JJ=0,NN
          COEFF=cheby_coeffs(JJ,NN-JJ,icheby(ix))
          MM=JJ+1
          LL=NN-JJ+1
  !FOX    DXP=DXP+(COEFF*TPX(MM))*TY (LL) ;
  !FOX    DYP=DYP+(COEFF*TX (MM))*TPY(LL) ;
        end do
      end do
      ! ref radius in [mm], kick in [mrad]   
  !FOX  DXP=-(DXP*C1E3)/(REFR*C1M3) ;
  !FOX  DYP=-(DYP*C1E3)/(REFR*C1M3) ;
    
      if (lrotate) then
        ! NB: cheby_angle(icheby(ix)) is the rotation angle of the cheby
  !FOX  THETA=ATAN(DYP/DXP)+ANGRAD ;
  !FOX  RR=SQRT(DXP*DXP+DYP*DYP) ;
  !FOX  DXP=RR*COS(THETA) ;
  !FOX  DYP=RR*SIN(THETA) ;
      end if
    
      ! take into account scaling factor, Brho of beam and its relativistic beta,
      !    and magnetic rigidity and relativistic beta of particle being tracked
  !FOX  DXP=(((DXP*CSCAL)/(BRHO*(CLIGHT*BETA0)))*(MTCDA/(ONE+DPDA)))*RV ;
  !FOX  DYP=(((DYP*CSCAL)/(BRHO*(CLIGHT*BETA0)))*(MTCDA/(ONE+DPDA)))*RV ;
        
      ! apply kicks
  !FOX  YY(1)=YY(1)+DXP ;
  !FOX  YY(2)=YY(2)+DYP ;
    end if
      
    if (st_debug) then
      call dapek(XI,hh,XA)
      call dapek(YI,hh,YA)
      call dapek(DXP,hh,DXPA)
      call dapek(DYP,hh,DYPA)
      write(lout,'(2(a,1pe22.15))')'CHEBY> CHEBY_KICK_FOX computed at XA=',XA,' - YA=',YA
      write(lout,'(2(a,1pe22.15))')'CHEBY> CHEBY_KICK_FOX - DXPA=',DXPA,' - DYPA=',DYPA
      write(lout,'(a)')'CHEBY> CHEBY_KICK_FOX closed orbit AFTER cheby lens:'
      call dapri(XX(1),6)
      call dapri(XX(2),6)
  
negative.code:   angrad = (cheby_angle(icheby(ix))/c180e0)*pi
  
    if (st_debug) then
      write(lout,'(3(a,i0))')'CHEBY> CHEBY_KICK_FOX for i= ',i,' - ix= ',ix, ' - icheby(ix)= ',icheby(ix)
      write(lout,'(a)')      'CHEBY> CHEBY_KICK_FOX closed orbit BEFORE cheby map:'
      call dapri(XX(1),6)
      call dapri(XX(2),6)
      call dapri(YY(1),6)
  