1 subroutine refsys(fail)
2 c This subroutine calculates unit vectors of a local reference system
3 c defined by atoms (i2), (i3), and (i4). The x axis is the axis from
4 c atom (i3) to atom (i2), and the xy plane is the plane defined by atoms
5 c (i2), (i3), and (i4). z axis is directed according to the sign of the
6 c vector product (i3)-(i2) and (i3)-(i4). Sets fail to .true. if atoms
7 c (i2) and (i3) or (i3) and (i4) coincide or atoms (i2), (i3), and (i4)
8 c form a linear fragment. Returns vectors e1, e2, and e3.
9 implicit real*8 (a-h,o-z)
12 double precision e1(3),e2(3),e3(3)
13 double precision u(3),z(3)
14 include 'COMMON.IOUNITS'
15 include 'COMMON.CHAIN'
16 double precision coinc/1.0D-13/,align /1.0D-13/
29 if (s1.gt.coinc) goto 2
30 write (iout,1000) i2,i3,i1
35 2 if (s2.gt.coinc) goto 4
36 write(iout,1000) i3,i4,i1
43 v1=z(2)*u(3)-z(3)*u(2)
44 v2=z(3)*u(1)-z(1)*u(3)
45 v3=z(1)*u(2)-z(2)*u(1)
46 anorm=dsqrt(v1*v1+v2*v2+v3*v3)
47 if (anorm.gt.align) goto 6
48 write (iout,1010) i2,i3,i4,i1
60 e2(1)=e1(3)*e3(2)-e1(2)*e3(3)
61 e2(2)=e1(1)*e3(3)-e1(3)*e3(1)
62 e2(3)=e1(2)*e3(1)-e1(1)*e3(2)
63 1000 format (/1x,' * * * Error - atoms',i4,' and',i4,' coincide.',
64 1 'coordinates of atom',i4,' are set to zero.')
65 1010 format (/1x,' * * * Error - atoms',2(i4,2h, ),i4,' form a linear',
66 1 ' fragment. coordinates of atom',i4,' are set to zero.')