      subroutine vecang(p,q,r,s,theta)                                  VECA001
c ----------------------------------------------------------------------VECA002
c     calculate angle between 2 vectors in 3 space                      VECA003
c ----------------------------------------------------------------------VECA004
c     This program module is part of the PhysiSoft X-ray Library        VECA005
c     and may not be sold or reproduced for commercial purposes.        VECA006
c     Although it has been tested carefully, there is no warranty       VECA007
c     regarding accuracy or freedom from side-effects.                  VECA008
c                   (C) 1986-1990 Bernhard Rupp                         VECA009
c ----------------------------------------------------------------------VECA010
                                                                        VECA011
      real * 4 p(3),q(3),r(3),s(3),theta,                               VECA012
     &         qmp(3),smr(3),qmp2,smr2,dp1,denom                        VECA013
                                                                        VECA014
      data deg/57.29577951/                                             VECA015
                                                                        VECA016
c --- get direction -                                                   VECA017
      do 0001 i=1,3                                                     VECA018
         qmp(i)=q(i)-p(i)                                               VECA019
         smr(i)=s(i)-r(i)                                               VECA020
 0001 continue                                                          VECA021
                                                                        VECA022
c --- calculate dot product --                                          VECA023
      dp1 = 0.0                                                         VECA024
      do 0002 i = 1,3                                                   VECA025
         dp1 = dp1 + smr(i)*qmp(i)                                      VECA026
 0002 continue                                                          VECA027
                                                                        VECA028
c --- test for perpendicular                                            VECA029
      if (dp1.eq.0.) then                                               VECA030
         theta = 90.0                                                   VECA031
         return                                                         VECA032
      endif                                                             VECA033
                                                                        VECA034
      qmp2 = qmp(1)*qmp(1)+qmp(2)*qmp(2)+qmp(3)*qmp(3)                  VECA035
      smr2 = smr(1)*smr(1)+smr(2)*smr(2)+smr(3)*smr(3)                  VECA036
                                                                        VECA037
      denom = sqrt(qmp2) * sqrt(smr2)                                   VECA038
                                                                        VECA039
c --- check for parallel                                                VECA040
      if (denom.lt.0.00001) then                                        VECA041
         theta = 0.0                                                    VECA042
         return                                                         VECA043
      endif                                                             VECA044
      arg=dp1/denom                                                     VECA045
      if(arg.gt.1.0) arg=1.0                                            VECA046
      if(arg.lt.-1.0) arg=-1.0                                          VECA047
      theta = acos(arg)*deg                                             VECA048
      return                                                            VECA049
                                                                        VECA050
      end                                                               VECA051
                                                                        VECA052
                                                                        VECA053
