Index: UPNODE.f
===================================================================
RCS file: /cvs/cmiss/cm/source/fe23/UPNODE.f,v
retrieving revision 1.451
diff -u -r1.451 UPNODE.f
--- UPNODE.f	17 Jul 2003 05:23:09 -0000	1.451
+++ UPNODE.f	15 Jul 2006 02:30:19 -0000
@@ -1162,24 +1162,58 @@
 C GMH 23/4/96 Loop for subset of nodes
               DO nolist=1,NPLIST(0)
                 np=NPLIST(nolist)
-C               Find all lines that go through the node
+C               Initialise temp memory 
                 DO njj=1,NJ_LOC(NJL_GEOM,0,nr)
                   nj=NJ_LOC(NJL_GEOM,njj,nr)
                   DX(nj)=0.0d0
                 ENDDO !nj
+C               Find all lines that go through the node
+
+
                 NL_COUNT=0
-                DO nl=1,NLT
-                  ni=NPL(1,0,nl)
+                DO nl=1,NLT ! loop over all lines
+                  ni=NPL(1,0,nl) 
                   NP1=NPL(2,1,nl)
                   NP2=NPL(3,1,nl)
-C new PJH 15Sep92
-                  IF((NP1.EQ.np.OR.NP2.EQ.np).AND.
-     '              ni.EQ.NO_DERIV) THEN !update specified derivative
+
+                  IF(((NP1.EQ.np).OR.(NP2.EQ.np))
+     &              .AND.ni.EQ.NO_DERIV) THEN
+
                     NL_COUNT=NL_COUNT+1
                     DO njj=1,NJ_LOC(NJL_GEOM,0,nr)
                       nj=NJ_LOC(NJL_GEOM,njj,nr)
 C!!! NOTE: this will need updating for different versions
-                      DX(nj)=DX(nj)+XP(1,1,nj,NP2)-XP(1,1,nj,NP1)
+                      !DX(nj)=DX(nj)+XP(1,1,nj,NP2)-XP(1,1,nj,NP1)
+
+C Glenn Ramsey 15/7/06 Added version selection so that only the
+C       version relevant to the line is considered instead of
+C       taking the average of all versions as it was previously.
+
+                      ! find the version of each node that is
+                      ! connected to the line
+                      nv1=NVJL(1,nj,nl);
+                      nv2=NVJL(2,nj,nl);
+
+                      ! save the version of the current node, in
+                      ! variable nv, for later use when the XP
+                      ! array is updated
+                      IF(np.EQ.NP1) THEN
+                        nv=nv1
+                      ELSE IF(np.EQ.NP2) THEN
+                        nv=nv2
+                      ENDIF
+
+                      
+                      IF(DOP) THEN
+                        WRITE(OP_STRING,'('' nl='',I3,'' np NP1 NP2='
+     &                  //''',I4,I4,I4,'' nv nv1 nv2='',I3,I3,I3)')
+     &                  nl,np,NP1,NP2,nv,nv1,nv2
+                        CALL WRITES(IODI,OP_STRING,ERROR,*9999)
+                      ENDIF
+
+                      ! update the delta using only the relevant version
+                      DX(nj)=DX(nj)+XP(1,nv2,nj,NP2)-XP(1,nv1,nj,NP1)
+
 C!!!                changed GT to GE here AAY 29Aug1995
                       IF(ITYP10(nr).GT.1.AND.nj.EQ.2.AND.
      '                  (XP(1,1,nj,NP2).GE.3.d0*PI/2.d0).AND.
@@ -1240,24 +1274,36 @@
                   DO njj=1,NJ_LOC(NJL_GEOM,0,nr)
                     nj=NJ_LOC(NJL_GEOM,njj,nr)
 C CS 28/12/2000 adding loop over versions
-                    DO nv=1,NVJP(nj,np)
-                      IF (nv.GE.2) THEN
-                        WRITE(OP_STRING,'('' >>WARNING: Updating'
-     '                  //' higher versions too'')')
-                        CALL WRITES(IOER,OP_STRING,ERROR,*9999)
-                      ENDIF
+C GR 15/7/06 loop no longer needed because we only want to update
+C            the relevant version, stored in nv.
+!                     DO nv=1,NVJP(nj,np)
+!                       IF (nv.GE.2) THEN
+!                         WRITE(OP_STRING,'('' >>WARNING: Updating'
+!      '                  //' higher versions too'')')
+!                         CALL WRITES(IOOP,OP_STRING,ERROR,*9999)
+!                       ENDIF
+!                       XP(nk,nv,nj,np)=DX(nj)
+!                     ENDDO
                       XP(nk,nv,nj,np)=DX(nj)
-                    ENDDO
+C                     If there are no lines attached to this version
+C                     then copy the value from version 1
+!                       IF(nvs.EQ.0) THEN
+!                         XP(nk,nv,nj,np)=XP(nk,1,nj,np)
+!                       ENDIF
                   ENDDO
                 ELSE IF(NJTOT.EQ.1)THEN
-                  DO nv=1,NVJP(nj,np)
-                    IF (nv.GE.2) THEN
-                      WRITE(OP_STRING,'('' >>WARNING: Updating'
-     '                  //' higher versions too'')')
-                      CALL WRITES(IOER,OP_STRING,ERROR,*9999)
-                    ENDIF
-                    XP(nk,1,nj_update,np)=DX(nj_update)
-                  ENDDO
+!                   DO nv=1,NVJP(nj,np)
+!                     IF (nv.GE.2) THEN
+!                       WRITE(OP_STRING,'('' >>WARNING: Updating'
+!      '                  //' higher versions too'')')
+!                       CALL WRITES(IOOP,OP_STRING,ERROR,*9999)
+!                     ENDIF
+!                     XP(nk,1,nj_update,np)=DX(nj_update)
+!                   ENDDO
+                    XP(nk,nv,nj_update,np)=DX(nj_update)
+!                     IF(nvs.EQ.0) THEN
+!                       XP(nk,nv,nj_update,np)=XP(nk,1,nj_update,np)
+!                     ENDIF  
                 ENDIF !NJTOT
 
 C KAT 6Dec00:   We have calculated an average derivative at np.  We don't
