Merge branch 'prerelease-3.2.1' into devel
[unres.git] / source / unres / src_CSA_DiL / refsys.f
1       subroutine refsys(i2,i3,i4,e1,e2,e3,fail)
2       implicit real*8 (a-h,o-z)
3       include 'DIMENSIONS'
4 c this subroutine calculates unity vectors of a local reference system
5 c defined by atoms (i2), (i3), and (i4). the x axis is the axis from
6 c atom (i3) to atom (i2), and the xy plane is the plane defined by atoms
7 c (i2), (i3), and (i4). z axis is directed according to the sign of the
8 c vector product (i3)-(i2) and (i3)-(i4). sets fail to .true. if atoms
9 c (i2) and (i3) or (i3) and (i4) coincide or atoms (i2), (i3), and (i4)
10 c form a linear fragment. returns vectors e1, e2, and e3.
11       logical fail
12       double precision e1(3),e2(3),e3(3)
13       double precision u(3),z(3)
14 <<<<<<< HEAD
15 =======
16       include 'COMMON.IOUNITS'
17 >>>>>>> prerelease-3.2.1
18       include "COMMON.CHAIN"
19       data coinc /1.0d-13/,align /1.0d-13/
20       fail=.false.
21       s1=0.0d0
22       s2=0.0d0
23       do 1 i=1,3
24       zi=c(i,i2)-c(i,i3)
25       ui=c(i,i4)-c(i,i3)
26       s1=s1+zi*zi
27       s2=s2+ui*ui
28       z(i)=zi
29     1 u(i)=ui
30       s1=sqrt(s1)
31       s2=sqrt(s2)
32       if (s1.gt.coinc) goto 2
33       write (iout,1000) i2,i3,i1
34       fail=.true.
35       return
36     2 if (s2.gt.coinc) goto 4
37       write(iout,1000) i3,i4,i1
38       fail=.true.
39       return
40     4 s1=1.0/s1
41       s2=1.0/s2
42       v1=z(2)*u(3)-z(3)*u(2)
43       v2=z(3)*u(1)-z(1)*u(3)
44       v3=z(1)*u(2)-z(2)*u(1)
45       anorm=sqrt(v1*v1+v2*v2+v3*v3)
46       if (anorm.gt.align) goto 6
47       write (iout,1010) i2,i3,i4,i1
48       fail=.true.
49       return
50     6 anorm=1.0/anorm
51       e3(1)=v1*anorm
52       e3(2)=v2*anorm
53       e3(3)=v3*anorm
54       e1(1)=z(1)*s1
55       e1(2)=z(2)*s1
56       e1(3)=z(3)*s1
57       e2(1)=e1(3)*e3(2)-e1(2)*e3(3)
58       e2(2)=e1(1)*e3(3)-e1(3)*e3(1)
59       e2(3)=e1(2)*e3(1)-e1(1)*e3(2)
60  1000 format (/1x,' * * * error - atoms',i4,' and',i4,' coincide.')
61  1010 format (/1x,' * * * error - atoms',2(i4,2h, ),i4,' form a linear')
62       return
63       end