anchor.diff:        return
       end if
      
  -    call chr_cast(lnSPlit(2), elens_emin(nelens),iErr)
  -    if ( elens_emin(nelens) < zero ) then
  +    call chr_cast(lnSPlit(2), tmpEmin,iErr)
  +    if ( tmpEmin < zero ) then
         write(lerr,"(a,1pe22.15)") "ELENS> ERROR Negative values of normalised emittance are unacceptable, got: ", &
  -            elens_emin(nelens)
  +            tmpEmin
         iErr = .true.
         return
       end if
  -
  +    if (nelens.gt.0) then
  +      elens_emin(nelens)=tmpEmin
  +      elens_sigdpp(nelens)=-one
  +    end if
  +    
       if (nSplit.ge.3) then
         select case (chr_toLower(trim(lnSplit(3))))
         case('min')
  -        elens_iSet(nelens)=1
  +        tmpSet=1
           if(st_debug) write(lout,"(a)") "ELENS> Applying read normalised emittance with min beta"
         case('max')
  -        elens_iSet(nelens)=2
  +        tmpSet=2
           if(st_debug) write(lout,"(a)") "ELENS> Applying read normalised emittance with max beta"
         case('ave')
  -        elens_iSet(nelens)=3
  +        tmpSet=3
           if(st_debug) write(lout,"(a)") "ELENS> Applying read normalised emittance with average beta"
         case('qve')
  -        elens_iSet(nelens)=4
  +        tmpSet=4
           if(st_debug) write(lout,"(a)") "ELENS> Applying read normalised emittance with quad-average beta"
         case('gve')
  -        elens_iSet(nelens)=5
  +        tmpSet=5
           if(st_debug) write(lout,"(a)") "ELENS> Applying read normalised emittance with geometric average beta"
         case default
           write(lerr,"(a)") "ELENS> ERROR Unidentified third parameter of EMIN line, got: '"//trim(lnSplit(3))//"'"
  
positive.code:   use mod_utils, only : polinterp
    use mod_common, only : bez, kz, e0f, nucm0
    use mod_settings, only : st_debug
  
    integer j, jj, jguess
    real(kind=fPrec) oldVal
  
negative.code:   ! R1/R2 expressed in normalised units (either betatron or dispersion)
    real(kind=fPrec), save      :: elens_emin_def=-one      ! default normalised emittance [m rad]
    real(kind=fPrec), save      :: elens_sigdpp_def=-one    ! default rms of distribution in delta_p / p []
    integer, save               :: elens_iSet_def=0         ! default iSet
    
  
    ! variables to save elens parameters for tracking etc.
    integer, allocatable, save          :: elens_type(:)            ! integer for elens type (nelens)
  