anchor.diff:    integer, save :: pencil_distr
   
     real(kind=fPrec), save :: myenom,mynex,mdex,myney,mdey,                    &
  -  &nsig_tcp3,nsig_tcsg3,nsig_tcsm3,nsig_tcla3,                       &
  -  &nsig_tcp7,nsig_tcsg7,nsig_tcsm7,nsig_tcla7,nsig_tclp,nsig_tcli,   &
  -  &nsig_tcth1,nsig_tcth2,nsig_tcth5,nsig_tcth8,                      &
  -  &nsig_tctv1,nsig_tctv2,nsig_tctv5,nsig_tctv8,                      &
  -  &nsig_tcdq,nsig_tcstcdq,nsig_tdi,nsig_tcxrp,nsig_tcryo,            &
   !SEPT2005 add these lines for the slicing procedure
     &smin_slices,smax_slices,recenter1,recenter2,                      &
     &fit1_1,fit1_2,fit1_3,fit1_4,fit1_5,fit1_6,ssf1,                   &
  
positive.code:   character(len=16), save :: castordir
    character(len=80), save :: filename_dis
  
  !  common /grd/ myenom,mynex,mdex,myney,mdey,                        &
  !  &nsig_tcp3,nsig_tcsg3,nsig_tcsm3,nsig_tcla3,                       &
  !  &nsig_tcp7,nsig_tcsg7,nsig_tcsm7,nsig_tcla7,nsig_tclp,nsig_tcli,   &
  !  &nsig_tcth1,nsig_tcth2,nsig_tcth5,nsig_tcth8,                      &
  !  &nsig_tctv1,nsig_tctv2,nsig_tctv5,nsig_tctv8,                      &
  !  &nsig_tcdq,nsig_tcstcdq,nsig_tdi,nsig_tcxrp,nsig_tcryo,            &
  !  &smin_slices,smax_slices,recenter1,recenter2,                      &
  !  &fit1_1,fit1_2,fit1_3,fit1_4,fit1_5,fit1_6,ssf1,                   &
  !  &fit2_1,fit2_2,fit2_3,fit2_4,fit2_5,fit2_6,ssf2,                   &
  !  &emitnx0_dist,emitny0_dist,emitnx0_collgap,emitny0_collgap,        &
  !  &xbeat,xbeatphase,ybeat,ybeatphase,                                &
  !  &c_rmstilt_prim,c_rmstilt_sec,c_systilt_prim,c_systilt_sec,        &
  !  &c_rmsoffset_prim,c_rmsoffset_sec,c_sysoffset_prim,                &
  !  &c_sysoffset_sec,c_rmserror_gap,nr,                                &
  !  &ndr,driftsx,driftsy,pencil_offset,pencil_rmsx,pencil_rmsy,        &
  !  &sigsecut3,sigsecut2,enerror,                                      &
  !  &bunchlength,coll_db,name_sel,                                     &
  !  &castordir,filename_dis,nloop,rnd_seed,c_offsettilt_seed,          &
  !  &ibeam,jobnumber,do_thisdis,n_slices,pencil_distr,                 &
  !  &do_coll,                                                          &
  !  &do_select,do_nominal,dowrite_dist,do_oneside,dowrite_impact,      &
  !  &dowrite_secondary,dowrite_amplitude,radial,systilt_antisymm,      &
  !  &dowritetracks,cern,cdb_doNSig,do_mingap
  !+cd info
    integer, save :: ie, iturn, nabs_total
  !  common  /info/ ie,iturn,nabs_total
  
   !-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  !+cd dbcommon
  
negative.code: !                           bx_dist = tbetax(j) * scale_bx / scale_bx0
  !                           by_dist = tbetay(j) * scale_by / scale_by0
  !                        endif
            if (do_nominal) then
              bx_dist = cdb_cBx(icoll)
              by_dist = cdb_cBy(icoll)
            else
              bx_dist = tbetax(j)
              by_dist = tbetay(j)
            end if
  
            sig_offset = cdb_cOffset(i)/(sqrt(bx_dist**2 * cos_mb(cdb_cRotation(i))**2 + by_dist**2 * sin_mb(cdb_cRotation(i))**2 ))
            write(twisslike_unit,*) bez(myix),tbetax(j),tbetay(j), torbx(j),torby(j), nsig, gap_rms_error(i)
        write(sigmasettings_unit,*) bez(myix), gap_h1, gap_h2, gap_h3, gap_h4, sig_offset, cdb_cOffset(i), nsig, gap_rms_error(i)
  
            if((gap_h1 + sig_offset) .le. mingap) then
              mingap = gap_h1 + sig_offset
              coll_mingap_id = i
              coll_mingap1 = cdb_cNameUC(i)
              coll_mingap2 = cdb_cName(i)
            else if((gap_h2 + sig_offset) .le. mingap) then
              mingap = gap_h2 + sig_offset
              coll_mingap_id = i
              coll_mingap1 = cdb_cNameUC(i)
              coll_mingap2 = cdb_cName(i)
            else if((gap_h3 - sig_offset) .le. mingap) then
              mingap = gap_h3 - sig_offset
              coll_mingap_id = i
              coll_mingap1 = cdb_cNameUC(i)
              coll_mingap2 = cdb_cName(i)
            else if((gap_h4 - sig_offset) .le. mingap) then
              mingap = gap_h4 - sig_offset
              coll_mingap_id = i
              coll_mingap1 = cdb_cNameUC(i)
              coll_mingap2 = cdb_cName(i)
            end if
          end if
        end if
      end do !do i = 1, cdb_nColl
  
    end do !do j=1,iu
  
    write(twisslike_unit,*) coll_mingap_id, coll_mingap1, coll_mingap2,  mingap
  