c write(iout,*)'phi(4)=',rad2deg*phi(4)
if (nstart.lt.3) theta(3)=gen_theta(itype(2),pi,phi(4))
c write(iout,*)'theta(3)=',rad2deg*theta(3)
c write(iout,*)'phi(4)=',rad2deg*phi(4)
if (nstart.lt.3) theta(3)=gen_theta(itype(2),pi,phi(4))
c write(iout,*)'theta(3)=',rad2deg*theta(3)
c print *,'Gen_Rand_Conf: i=',i,' it=',it,' it1=',it1,' it2=',it2,
c & ' nit=',nit,' niter=',niter,' maxgen=',maxgen
phi(i+1)=gen_phi(i+1,it1,it)
c print *,'Gen_Rand_Conf: i=',i,' it=',it,' it1=',it1,' it2=',it2,
c & ' nit=',nit,' niter=',niter,' maxgen=',maxgen
phi(i+1)=gen_phi(i+1,it1,it)
if (iti.gt.ntyp) return
C Check for SC-SC overlaps.
cd print *,'nnt=',nnt,' nct=',nct
do j=nnt,i-1
if (iti.gt.ntyp) return
C Check for SC-SC overlaps.
cd print *,'nnt=',nnt,' nct=',nct
do j=nnt,i-1
c(j,maxres2+1)=0.5D0*(c(j,i)+c(j,i+1))
enddo
do j=nnt,i-2
c(j,maxres2+1)=0.5D0*(c(j,i)+c(j,i+1))
enddo
do j=nnt,i-2
cd print *,'overlap, p-Sc: i=',i,' j=',j,
cd & ' dist=',dist(nres+j,maxres2+1)
if (dist(nres+j,maxres2+1).lt.4.0D0*redfac) then
cd print *,'overlap, p-Sc: i=',i,' j=',j,
cd & ' dist=',dist(nres+j,maxres2+1)
if (dist(nres+j,maxres2+1).lt.4.0D0*redfac) then
c print *,'>>overlap_sc nnt=',nnt,' nct=',nct
ind=0
do i=iatsc_s,iatsc_e
c print *,'>>overlap_sc nnt=',nnt,' nct=',nct
ind=0
do i=iatsc_s,iatsc_e
do iint=1,nint_gr(i)
do j=istart(i,iint),iend(i,iint)
ind=ind+1
do iint=1,nint_gr(i)
do j=istart(i,iint),iend(i,iint)
ind=ind+1