c     this subroutine checks for canonical labelling of partial graph
c     and computes symmetry number
      subroutine symred(n,m,sym,ier)
      parameter (nvmax=7,nbmax=6,noodmax=nvmax*(nvmax-1)/2)
      implicit integer(b-z)
      dimension m(nvmax,nvmax)
      dimension c(nvmax),occ(nvmax),s(nvmax),vmax(nvmax),smax(nvmax)  
      dimension smp(nvmax,nvmax)
      sym=0
      do 10 i=1,n
      c(i)=0
      occ(i)=0
      s(i)=0
      vmax(i)=-1
      smax(i)=0
      smp(i,1)=i
   10 continue
      iex=0
      vmax(1)=0
      smax(1)=n
      k=1
   40 continue
      ck=c(k)+1
      c(k)=ck
      if (ck.gt.smax(k)) go to 60
      s(k)=smp(ck,k)
      sk=s(k)
      if (sk.gt.n) go to 60
      if (occ(sk).gt.0) go to 40
      occ(sk)=1
      k=k+1
      if (k.gt.n) go to 50
      c(k)=0
      smx=0
      vmk=-1
      k1=k-1
      do 20 j=1,n
      vm1=0
      if (occ(j).gt.0) go to 20
      do 22 l=1,k1
      sl=s(l)
      msj=m(sl,j)
      vm1=ior(vm1,msj)
      vm1=ishft(vm1,1)
   22 continue
      if (vmk.gt.vm1) go to 20
      if (vmk.eq.vm1) go to 24
      vmk=vm1
      smx=1
      smp(1,k)=j
      go to 20
   24 continue
      smx=smx+1
      smp(smx,k)=j
   20 continue
      if (iex.eq.1) go to 26
      if (smp(1,k).ne.k) go to 82
      vmax(k)=vmk
      sym=0
   26 continue
      vmxk=vmax(k)
      if (vmk.gt.vmxk) go to 82
      if (vmk.lt.vmxk) go to 28
      smax(k)=smx
      go to 40
   50 continue
      iex=1
      sym=sym+1
      k=n
      occ(sk)=0
      go to 40
   60 continue
      c(k)=0
   28 continue
      k=k-1
      if (k.eq.0) go to 80
      occ(s(k))=0
      go to 40
   80 ier=0
      return
   82 ier=1
      return
      end

