      subroutine planar(did,iplan,ibeg,ishell,conang,iclust,idim,averag)PLAN001
c          call planar (did,iplan,ibeg,ishell,conang,iclust,idim,averag)PLAN002
c ----------------------------------------------------------------------PLAN003
c     determines whether shell atoms are in a plane and returns         PLAN004
c     iplan=1 in this case.  Routine is dependent on plane-defining     PLAN005
c     atoms being non-colinear, as implied by shell geometry.           PLAN006
c ----------------------------------------------------------------------PLAN007
c     This program module is part of the PhysiSoft X-ray Library        PLAN008
c     and may not be sold or reproduced for commercial purposes.        PLAN009
c     Although it has been tested carefully, there is no warranty       PLAN010
c     regarding accuracy or freedom from side-effects.                  PLAN011
c          B. Smith Lawrence Livermore National Lab (1990).             PLAN012
c                   (C) PhysiSoft X-ray Library                         PLAN013
c ----------------------------------------------------------------------PLAN014
      dimension did(iclust,idim),v1(3),v2(3),vnrm(3)                    PLAN015
      real d, dist, denom                                               PLAN016
                                                                        PLAN017
      iplan=0                                                           PLAN018
                                                                        PLAN019
c --- conpln is convergence limit whether regarded in plane or not --   PLAN020
      conpln=averag*sin(conang)                                         PLAN021
      if  (conpln.lt.0.01) conpln=0.01                                  PLAN022
                                                                        PLAN023
c --- v1 and v2 are vectors in the plane ---                            PLAN024
c --- vnrm is normal to the plane Ax + By + Cz + d = 0 ---              PLAN025
      do 500 i=1,3                                                      PLAN026
         v1(i)=did(ibeg,i+5)-did(ibeg+1,i+5)                            PLAN027
         v2(i)=did(ibeg,i+5)-did(ibeg+2,i+5)                            PLAN028
 0500 continue                                                          PLAN029
                                                                        PLAN030
c --- find cross product of v1 x v2 ---                                 PLAN031
      vnrm(1)= v1(2)*v2(3)- v1(3)*v2(2)                                 PLAN032
      vnrm(2)= v1(3)*v2(1)- v1(1)*v2(3)                                 PLAN033
      vnrm(3)= v1(1)*v2(2)- v1(2)*v2(1)                                 PLAN034
      d=-(vnrm(1)*did(ibeg,6) +vnrm(2)*did(ibeg,7) +vnrm(3)*did(ibeg,8))PLAN035
      denom=sqrt((vnrm(1))**2+(vnrm(2))**2+(vnrm(3))**2)                PLAN036
                                                                        PLAN037
      if (ishell.gt.3) then                                             PLAN038
c ---     find distance between plane of three atoms and others --      PLAN039
        do 0100 i=ibeg+3,ibeg+ishell-1                                  PLAN040
          dist=abs(vnrm(1)*did(i,6)+vnrm(2)*did(i,7)+vnrm(3)*did(i,8)+d)PLAN041
          dist=dist/denom                                               PLAN042
          if (dist.gt.conpln) then                                      PLAN043
              return                                                    PLAN044
          end if                                                        PLAN045
 0100   continue                                                        PLAN046
      endif                                                             PLAN047
                                                                        PLAN048
c --- check if shell center is on plane ---                             PLAN049
      dist=abs(vnrm(1)*did(1,6)+vnrm(2)*did(1,7)+vnrm(3)*did(1,8)+d)    PLAN050
      dist=dist/denom                                                   PLAN051
      if (dist.gt.conpln) then                                          PLAN052
         return                                                         PLAN053
      endif                                                             PLAN054
                                                                        PLAN055
c --- no pt. to plane distances outside boundaries, therefore ---       PLAN056
      iplan=1                                                           PLAN057
      return                                                            PLAN058
      end                                                               PLAN059
                                                                        PLAN060
                                                                        PLAN061
