1!
2!     CalculiX - A 3-dimensional finite element program
3!     Copyright (C) 1998-2021 Guido Dhondt
4!
5!     This program is free software; you can redistribute it and/or
6!     modify it under the terms of the GNU General Public License as
7!     published by the Free Software Foundation(version 2);
8!
9!
10!     This program is distributed in the hope that it will be useful,
11!     but WITHOUT ANY WARRANTY; without even the implied warranty of
12!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13!     GNU General Public License for more details.
14!
15!     You should have received a copy of the GNU General Public License
16!     along with this program; if not, write to the Free Software
17!     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18!
19      subroutine networkneighbor(nelem,node,nelemnei,nodenei,ibranch,
20     &  iponoel,inoel,ipkon,kon)
21!
22!     looks for the neighboring element and neighboring end node of
23!     node "node" of element "nelem". If the neighboring end node
24!     belongs to more than 2 elements ibranch=1, else ibranch=0
25!
26      implicit none
27!
28      integer nelem,node,nelemnei,nodenei,ibranch,index,indexe,
29     &  iponoel(*),inoel(2,*),ipkon(*),kon(*),iel
30!
31      nelemnei=0
32      ibranch=0
33!
34      index=iponoel(node)
35      if(index.eq.0) then
36         write(*,*) '*ERROR in networkneighbor:node',node
37         write(*,*) '       does not belong to network element',nelem
38         call exit(201)
39      endif
40!
41      do
42         iel=inoel(1,index)
43!
44         if(iel.eq.nelem) then
45            index=inoel(2,index)
46            if(index.eq.0) exit
47            cycle
48         endif
49!
50!        neighboring element; check whether a neighboring element
51!        was already found
52!
53         if(nelemnei.ne.0) then
54            ibranch=1
55            exit
56         endif
57!
58         nelemnei=iel
59         indexe=ipkon(iel)
60         if(kon(indexe+1).eq.node) then
61            nodenei=kon(indexe+3)
62         else
63            nodenei=kon(indexe+1)
64         endif
65         index=inoel(2,index)
66         if(index.eq.0) exit
67      enddo
68!
69      return
70      end
71