1 subroutine fitsq(rms,x,y,nn,t,b,non_conv)
2 implicit real*8 (a-h,o-z)
3 include 'COMMON.IOUNITS'
4 c x and y are the vectors of coordinates (dimensioned (3,n)) of the two
5 c structures to be superimposed. nn is 3*n, where n is the number of
6 c points. t and b are respectively the translation vector and the
7 c rotation matrix that transforms the second set of coordinates to the
8 c frame of the first set.
9 c eta = machine-specific variable
11 dimension x(3*nn),y(3*nn),t(3)
12 dimension b(3,3),q(3,3),r(3,3),v(3),xav(3),yav(3),e(3),c(3,3)
15 c small=25.0*rmdcon(3)
18 c the following is a very lenient value for 'small'
31 crc write(iout,*)'x = ',x(nc+i),' y = ',y(nc+i)
32 xav(i)=xav(i)+x(nc+i)/fn
33 20 yav(i)=yav(i)+y(nc+i)/fn
43 rms=rms+(y(3*(n-1)+i)-x(3*(n-1)+i)-t(i))**2
48 c write(iout,*)'xav = ',(xav(j),j=1,3)
49 c write(iout,*)'yav = ',(yav(j),j=1,3)
50 c write(iout,*)'t = ',(t(j),j=1,3)
51 c write(iout,*)'rms=',rms
52 if (rms.lt.small) return
59 rms=rms+((x(nc+i)-xav(i))**2+(y(nc+i)-yav(i))**2)/fn
61 b(j,i)=b(j,i)+(x(nc+i)-xav(i))*(y(nc+j)-yav(j))/fn
64 call sivade(b,q,r,d,non_conv)
68 120 b(j,i)=-q(j,1)*r(i,1)-q(j,2)*r(i,2)-sn3*q(j,3)*r(i,3)
69 call mvvad(b,xav,yav,t)
72 rms=rms+2.0*c(j,i)*b(j,i)
74 if (dabs(rms).gt.small) go to 140
77 140 if (rms.gt.0.0d0) go to 150
78 c write (iout,303) rms
81 c 150 write (iout,302) dsqrt(rms)
84 301 format (5x,'rms deviation negligible')
85 302 format (5x,'rms deviation ',f14.6)
86 303 format (//,5x,'negative ms deviation - ',f14.6)
88 subroutine sivade(x,q,r,dt,non_conv)
89 implicit real*8(a-h,o-z)
90 c computes q,e and r such that q(t)xr = diag(e)
91 dimension x(3,3),q(3,3),r(3,3),e(3)
92 dimension h(3,3),p(3,3),u(3,3),d(3)
102 xnrm=xnrm+x(j,i)*x(j,i)
112 30 if (dabs(x(j,n)).gt.xmax) xmax=dabs(x(j,n))
118 den=a*(a+dabs(h(n,n)))
120 h(n,n)=h(n,n)+dsign(a,h(n,n))
127 60 x(j,i)=x(j,i)-s*h(j,n)
129 if (n.gt.1) go to 110
130 xmax=dmax1(dabs(x(1,2)),dabs(x(1,3)))
133 a=dsqrt(h(2,3)*h(2,3)+h(3,3)*h(3,3))
134 den=a*(a+dabs(h(2,3)))
136 h(2,3)=h(2,3)+sign(a,h(2,3))
143 90 x(i,j)=x(i,j)-s*h(j,3)
148 120 p(j,i)=-d(1)*h(j,1)*h(i,1)
149 130 p(i,i)=1.0+p(i,i)
152 u(j,i)=u(j,i)-d(2)*h(j,2)*h(i,2)
153 140 r(j,i)=r(j,i)-d(3)*h(j,3)*h(i,3)
158 if (nit.gt.10000) then
159 print '(a)','!!!! Over 10000 iterations in SIVADE!!!!!'
163 if (dabs(x(2,3)).gt.small*(dabs(x(2,2))+abs(x(3,3)))) go to 160
166 160 if (dabs(x(1,2)).gt.small*(dabs(x(1,1))+dabs(x(2,2)))) go to 180
168 if (x(2,3).ne.0.0d0) go to 170
172 180 if (nq.eq.3) go to 310
174 if (np.gt.npq) go to 230
178 if (dabs(x(nn,nn)).gt.small*xnrm) go to 220
180 if (x(nn,nn+1).eq.0.0d0) go to 220
182 go to (190,210,220),nn
184 200 call givns(x,q,1,j)
186 210 call givns(x,q,2,3)
188 if (n0.ne.0) go to 150
191 if (nn.gt.1) a=a+x(nn-1,nn)*x(nn-1,nn)
192 b=x(nn+1,nn+1)*x(nn+1,nn+1)+x(nn,nn+1)*x(nn,nn+1)
193 c=x(nn,nn)*x(nn,nn+1)
196 rt=b-xn2/(dd+sign(dsqrt(dd*dd+xn2),dd))
197 y=x(np,np)*x(np,np)-rt
198 z=x(np,np)*x(np,np+1)
200 if (dabs(y).lt.dabs(z)) go to 240
202 c=1.0/dsqrt(1.0d0+t*t)
206 s=1.0/dsqrt(1.0d0+t*t)
216 260 r(j,n+1)=-s*a+c*b
219 if (dabs(y).lt.dabs(z)) go to 270
235 290 q(j,n+1)=-s*a+c*b
236 if (n.ge.nn) go to 300
246 if (nit.gt.10000) then
247 print '(a)','!!!! Over 10000 iterations in SIVADE!!!!!'
252 if (e(i).ge.0.0d0) go to 350
256 350 if (i.eq.1) go to 360
257 if (dabs(e(i)).lt.dabs(e(i-1))) go to 360
258 call switch(i,1,q,r,e)
261 if (n0.ne.0) go to 330
262 if (dabs(e(3)).gt.small*xnrm) go to 370
264 if (dabs(e(2)).gt.small*xnrm) go to 370
266 370 dt=det(q(1,1),q(1,2),q(1,3))*det(r(1,1),r(1,2),r(1,3))
267 * write (1,501) (e(i),i=1,3)
269 501 format (/,5x,'singular values - ',3e15.5)
271 subroutine givns(a,b,m,n)
272 implicit real*8 (a-h,o-z)
273 dimension a(3,3),b(3,3)
274 if (dabs(a(m,n)).lt.dabs(a(n,n))) go to 10
293 subroutine switch(n,m,u,v,d)
294 implicit real*8 (a-h,o-z)
295 dimension u(3,3),v(3,3),d(3)
310 subroutine mvvad(b,xav,yav,t)
311 implicit real*8 (a-h,o-z)
312 dimension b(3,3),xav(3),yav(3),t(3)
313 c dimension a(3,3),b(3),c(3),d(3)
317 c 10 d(j)=d(j)+a(j,i)*b(i)
321 10 t(j)=t(j)+b(j,i)*xav(i)
324 double precision function det (a,b,c)
325 implicit real*8 (a-h,o-z)
326 dimension a(3),b(3),c(3)
327 det=a(1)*(b(2)*c(3)-b(3)*c(2))+a(2)*(b(3)*c(1)-b(1)*c(3))
328 1 +a(3)*(b(1)*c(2)-b(2)*c(1))
331 subroutine mmmul(a,b,c)
332 implicit real*8 (a-h,o-z)
333 dimension a(3,3),b(3,3),c(3,3)
338 10 c(i,j)=c(i,j)+a(i,k)*b(k,j)
341 subroutine matvec(uvec,tmat,pvec,nback)
342 implicit real*8 (a-h,o-z)
343 real*8 tmat(3,3),uvec(3,nback), pvec(3,nback)
349 1 uvec(i,j)=uvec(i,j)+tmat(i,k)*pvec(k,j)