integer :: i,nstart,maxsi,nsi,maxnit,nit,niter
integer :: it1,it2,it,j
!d print *,' CG Processor',me,' maxgen=',maxgen
integer :: i,nstart,maxsi,nsi,maxnit,nit,niter
integer :: it1,it2,it,j
!d print *,' CG Processor',me,' maxgen=',maxgen
if (nstart.lt.5) then
it1=iabs(itype(2,1))
phi(4)=gen_phi(4,iabs(itype(2,1)),iabs(itype(3,1)))
! write(iout,*)'phi(4)=',rad2deg*phi(4)
if (nstart.lt.3) theta(3)=gen_theta(iabs(itype(2,1)),pi,phi(4))
! write(iout,*)'theta(3)=',rad2deg*theta(3)
if (nstart.lt.5) then
it1=iabs(itype(2,1))
phi(4)=gen_phi(4,iabs(itype(2,1)),iabs(itype(3,1)))
! write(iout,*)'phi(4)=',rad2deg*phi(4)
if (nstart.lt.3) theta(3)=gen_theta(iabs(itype(2,1)),pi,phi(4))
! write(iout,*)'theta(3)=',rad2deg*theta(3)
it1=iabs(itype(i-1,molnum(i-1)))
it2=iabs(itype(i-2,molnum(i-2)))
it=iabs(itype(i,molnum(i)))
it1=iabs(itype(i-1,molnum(i-1)))
it2=iabs(itype(i-2,molnum(i-2)))
it=iabs(itype(i,molnum(i)))
-! print *,'Gen_Rand_Conf: i=',i,' it=',it,' it1=',it1,' it2=',it2,
-! & ' nit=',nit,' niter=',niter,' maxgen=',maxgen
+! print *,'Gen_Rand_Conf: i=',i,' it=',it,' it1=',it1,' it2=',it2,&
+! ' nit=',nit,' niter=',niter,' maxgen=',maxgen
phi(i+1)=gen_phi(i+1,it1,it)
if (back) then
phi(i)=gen_phi(i+1,it2,it1)
! print *,'phi(',i,')=',phi(i)
theta(i-1)=gen_theta(it2,phi(i-1),phi(i))
phi(i+1)=gen_phi(i+1,it1,it)
if (back) then
phi(i)=gen_phi(i+1,it2,it1)
! print *,'phi(',i,')=',phi(i)
theta(i-1)=gen_theta(it2,phi(i-1),phi(i))
call locate_next_res(i-1)
endif
theta(i)=gen_theta(it1,phi(i),phi(i+1))
call locate_next_res(i-1)
endif
theta(i)=gen_theta(it1,phi(i),phi(i+1))
if ((it1.ne.10).and.(it1.ne.ntyp1)) then
nsi=0
fail=.true.
do while (fail.and.nsi.le.maxsi)
call gen_side(it1,theta(i),alph(i-1),omeg(i-1),fail)
if ((it1.ne.10).and.(it1.ne.ntyp1)) then
nsi=0
fail=.true.
do while (fail.and.nsi.le.maxsi)
call gen_side(it1,theta(i),alph(i-1),omeg(i-1),fail)
do k=1,2
thet_pred_mean=thet_pred_mean+athet(k,it,1,1)*y(k) &
+bthet(k,it,1,1)*z(k)
do k=1,2
thet_pred_mean=thet_pred_mean+athet(k,it,1,1)*y(k) &
+bthet(k,it,1,1)*z(k)