      integer function isCorner2v(i,j,n,im,jm,nm)

      implicit none

      integer::i,j,n,im,jm,nm,k
      integer,dimension(6)::i1

      isCorner2v=0

      if(nm.eq.14)then            ! octagon 1
         if(i.eq.0.and.j.eq.0)then
           i1=(/1,2,7,8,9,12/)
           do k=1,6
             if(n.eq.i1(k))then
               isCorner2v=1
             endif
           enddo
         endif
   
         if(i.eq.im.and.j.eq.0)then
           i1=(/1,4,6,7,11,14/)
           do k=1,6
             if(n.eq.i1(k))then
               isCorner2v=2
             endif
           enddo
         endif
   
         if(i.eq.0.and.j.eq.jm)then
           i1=(/2,5,6,9,13,14/)
           do k=1,6
             if(n.eq.i1(k))then
               isCorner2v=3
             endif
           enddo
         endif
   
         if(i.eq.im.and.j.eq.jm)then
           i1=(/4,5,8,11,12,13/)
           do k=1,6
             if(n.eq.i1(k))then
               isCorner2v=4
             endif
           enddo
         endif
       else if(nm.eq.6)then
         if(i.eq.0.and.j.eq.0)then
	   isCorner2v=1
         endif
         if(i.eq.im.and.j.eq.0)then
               isCorner2v=2
         endif
   
         if(i.eq.0.and.j.eq.jm)then
               isCorner2v=3
         endif
   
         if(i.eq.im.and.j.eq.jm)then
               isCorner2v=4
         endif
       endif

      end function isCorner2v
