Index: branches/2011/dev_r2802_NOCL_prjhpg/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90
===================================================================
--- branches/2011/dev_r2802_NOCL_prjhpg/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 3068)
+++ branches/2011/dev_r2802_NOCL_prjhpg/NEMOGCM/NEMO/OPA_SRC/DYN/dynhpg.F90	(revision 3079)
@@ -1150,6 +1150,6 @@
       DO jj = 2, jpjm1     
         DO ji = 2, jpim1  
-          zu(ji,jj,1) = - ( 0.5_wp * fse3uw(ji,jj,1) - sshu_n(ji,jj) * znad)
-          zv(ji,jj,1) = - ( 0.5_wp * fse3vw(ji,jj,1) - sshv_n(ji,jj) * znad)
+          zu(ji,jj,1) = - ( fse3u(ji,jj,1) - sshu_n(ji,jj) * znad)
+          zv(ji,jj,1) = - ( fse3v(ji,jj,1) - sshv_n(ji,jj) * znad)
         END DO
       END DO
@@ -1158,11 +1158,18 @@
         DO jj = 2, jpjm1     
           DO ji = 2, jpim1  
-            zu(ji,jj,jk) = zu(ji,jj,jk-1)- fse3uw(ji,jj,jk)
-            zv(ji,jj,jk) = zv(ji,jj,jk-1)- fse3vw(ji,jj,jk)
+            zu(ji,jj,jk) = zu(ji,jj,jk-1)- fse3u(ji,jj,jk)
+            zv(ji,jj,jk) = zv(ji,jj,jk-1)- fse3v(ji,jj,jk)
           END DO
         END DO
       END DO
                
-      !  Start pressure integration
+      DO jk = 1, jpkm1                                  
+        DO jj = 2, jpjm1     
+          DO ji = 2, jpim1  
+            zu(ji,jj,jk) = zu(ji,jj,jk) + 0.5_wp * fse3u(ji,jj,jk)
+            zv(ji,jj,jk) = zv(ji,jj,jk) + 0.5_wp * fse3v(ji,jj,jk)
+          END DO
+        END DO
+      END DO
 
       DO jk = 1, jpkm1                                  
@@ -1175,5 +1182,6 @@
 
             !!!!!     for u equation
-            IF(-fsde3w(ji+1,jj,mbathy(ji+1,jj)) >= -fsde3w(ji,jj,mbathy(ji,jj))) THEN
+            IF(jk <= mbku(ji,jj)) THEN
+            IF(-fsde3w(ji+1,jj,mbku(ji,jj)) >= -fsde3w(ji,jj,mbku(ji,jj))) THEN
               jis = ji + 1; jid = ji
             ELSE
@@ -1184,27 +1192,19 @@
             jk1 = jk 
             bhitwe = 0
-            IF(jk1 == mbathy(jis,jj)) THEN
-              bhitwe = 1
-            ELSE
-              DO WHILE ( -fsde3w(jis,jj,jk1+1) > zuijk )
-                pwes = pwes + & 
-                     integ2(fsde3w(jis,jj,jk1),fsde3w(jis,jj,jk1+1),&
-                            asp(jis,jj,jk1),bsp(jis,jj,jk1),&
-                            csp(jis,jj,jk1),dsp(jis,jj,jk1))
-                jk1 = jk1 + 1
-                IF(jk1 == mbathy(jis,jj)) THEN
-                  bhitwe = 1
-                  EXIT
-                END IF
-              END DO
-            ENDIF
-            
-            IF(bhitwe /= 1) THEN
+            DO WHILE ( -fsde3w(jis,jj,jk1) > zuijk )
+              IF(jk1 == mbku(ji,jj)) THEN
+                bhitwe = 1
+                EXIT
+              ENDIF
+              deps = min(fsde3w(jis,jj,jk1+1), -zuijk)
               pwes = pwes + & 
-                   integ2(fsde3w(jis,jj,jk1),-zuijk,&
+                   integ2(fsde3w(jis,jj,jk1),deps,&
                           asp(jis,jj,jk1),bsp(jis,jj,jk1),&
                           csp(jis,jj,jk1),dsp(jis,jj,jk1))
-            ELSE
-               zuijk = -fsde3w(jis,jj,jk1)
+              jk1 = jk1 + 1
+            END DO
+            
+            IF(bhitwe == 1) THEN
+              zuijk = -fsde3w(jis,jj,jk1)
             ENDIF
 
@@ -1212,26 +1212,18 @@
             jk1 = jk 
             bhitwe = 0
-            IF(jk1 == 1) THEN
-              bhitwe = 1
-            ELSE
-              DO WHILE ( -fsde3w(jid,jj,jk1-1) < zuijk )
-                pwed = pwed + & 
-                     integ2(fsde3w(jid,jj,jk1-1),fsde3w(jid,jj,jk1),&
-                            asp(jid,jj,jk1-1),bsp(jid,jj,jk1-1),&
-                            csp(jid,jj,jk1-1),dsp(jid,jj,jk1-1))
-                jk1 = jk1 - 1
-                IF(jk1 == 1) THEN
-                  bhitwe = 1
-                  EXIT
-                END IF
-              END DO
-            ENDIF
-            
-            IF(bhitwe /= 1) THEN
+            DO WHILE ( -fsde3w(jid,jj,jk1) < zuijk )
+              IF(jk1 == 1) THEN
+                bhitwe = 1
+                EXIT
+              END IF
+              deps = max(fsde3w(jid,jj,jk1-1), -zuijk)
               pwed = pwed + & 
-                   integ2(-zuijk,fsde3w(jid,jj,jk1),&
+                   integ2(deps,fsde3w(jid,jj,jk1),&
                           asp(jid,jj,jk1-1),bsp(jid,jj,jk1-1),&
                           csp(jid,jj,jk1-1),dsp(jid,jj,jk1-1))
-            ELSE
+              jk1 = jk1 - 1
+            END DO
+            
+            IF(bhitwe == 1) THEN
               deps = fsde3w(jid,jj,1) + min(zuijk, sshn(jid,jj)*znad)
               rhdt1 = rhd(jid,jj,1) - interp3(fsde3w(jid,jj,1),asp(jid,jj,1), &
@@ -1241,23 +1233,20 @@
             ENDIF
 
-            IF(jid > jis) THEN
-              pe = pwed; pw = pwes
-            ELSE
-              pe = pwes; pw = pwed
-            ENDIF
 
             dpdx1 = zcoef0 / e1u(ji,jj) * (zhpi(ji+1,jj,jk) - zhpi(ji,jj,jk))
             IF(lk_vvl) THEN
-              dpdx2 = zcoef0 / e1u(ji,jj) * (pw + pe + (sshn(ji+1,jj)-sshn(ji,jj))) 
+              dpdx2 = zcoef0 / e1u(ji,jj) * & 
+                      (REAL(jis-jid, wp) * (pwes + pwed) + (sshn(ji+1,jj)-sshn(ji,jj))) 
              ELSE
-              dpdx2 = zcoef0 / e1u(ji,jj) * (pw + pe) 
+              dpdx2 = zcoef0 / e1u(ji,jj) * REAL(jis-jid, wp) * (pwes + pwed) 
             ENDIF
 
             ua(ji,jj,jk) = ua(ji,jj,jk) + (dpdx1 + dpdx2)*&
                &           umask(ji,jj,jk)*tmask(ji,jj,jk)*tmask(ji+1,jj,jk)
+            ENDIF
   
             !!!!!     for v equation
-
-            IF(-fsde3w(ji,jj+1,mbathy(ji,jj+1)) >= -fsde3w(ji,jj,mbathy(ji,jj))) THEN
+            IF(jk <= mbkv(ji,jj)) THEN
+            IF(-fsde3w(ji,jj+1,mbkv(ji,jj)) >= -fsde3w(ji,jj,mbkv(ji,jj))) THEN
               jjs = jj + 1; jjd = jj
             ELSE
@@ -1268,27 +1257,19 @@
             jk1 = jk 
             bhitns = 0
-            IF(jk1 == mbathy(ji,jjs)) THEN
-              bhitns = 1
-            ELSE
-              DO WHILE ( -fsde3w(ji,jjs,jk1+1) > zvijk )
-                pnss = pnss + & 
-                     integ2(fsde3w(ji,jjs,jk1),fsde3w(ji,jjs,jk1+1),&
-                            asp(ji,jjs,jk1),bsp(ji,jjs,jk1),&
-                            csp(ji,jjs,jk1),dsp(ji,jjs,jk1))
-                jk1 = jk1 + 1
-                IF(jk1 == mbathy(ji,jjs)) THEN
-                  bhitns = 1
-                  EXIT
-                END IF
-              END DO
-            ENDIF
-            
-            IF(bhitns /= 1) THEN
+            DO WHILE ( -fsde3w(ji,jjs,jk1) > zvijk )
+              IF(jk1 == mbkv(ji,jj)) THEN
+                bhitns = 1
+                EXIT
+              ENDIF
+              deps = min(fsde3w(ji,jjs,jk1+1), -zvijk)
               pnss = pnss + & 
-                   integ2(fsde3w(ji,jjs,jk1),-zvijk,&
+                   integ2(fsde3w(ji,jjs,jk1),deps,&
                           asp(ji,jjs,jk1),bsp(ji,jjs,jk1),&
                           csp(ji,jjs,jk1),dsp(ji,jjs,jk1))
-            ELSE
-               zvijk = -fsde3w(ji,jjs,jk1)
+              jk1 = jk1 + 1
+            END DO
+            
+            IF(bhitns == 1) THEN
+              zvijk = -fsde3w(ji,jjs,jk1)
             ENDIF
 
@@ -1296,26 +1277,18 @@
             jk1 = jk 
             bhitns = 0
-            IF(jk1 == 1) THEN
-              bhitns = 1
-            ELSE
-              DO WHILE ( -fsde3w(ji,jjd,jk1-1) < zvijk )
-                pnsd = pnsd + & 
-                     integ2(fsde3w(ji,jjd,jk1-1),fsde3w(ji,jjd,jk1),&
-                            asp(ji,jjd,jk1-1),bsp(ji,jjd,jk1-1),&
-                            csp(ji,jjd,jk1-1),dsp(ji,jjd,jk1-1))
-                jk1 = jk1 - 1
-                IF(jk1 == 1) THEN
-                  bhitns = 1
-                  EXIT
-                END IF
-              END DO
-            ENDIF
-            
-            IF(bhitns /= 1) THEN
+            DO WHILE ( -fsde3w(ji,jjd,jk1) < zvijk )
+              IF(jk1 == 1) THEN
+                bhitns = 1
+                EXIT
+              END IF
+              deps = max(fsde3w(ji,jjd,jk1-1), -zvijk)
               pnsd = pnsd + & 
-                   integ2(-zvijk,fsde3w(ji,jjd,jk1),&
+                   integ2(deps,fsde3w(ji,jjd,jk1),&
                           asp(ji,jjd,jk1-1),bsp(ji,jjd,jk1-1),&
                           csp(ji,jjd,jk1-1),dsp(ji,jjd,jk1-1))
-            ELSE
+              jk1 = jk1 - 1
+            END DO
+            
+            IF(bhitns == 1) THEN
               deps = fsde3w(ji,jjd,1) + min(zvijk, sshn(ji,jjd)*znad)
               rhdt1 = rhd(ji,jjd,1) - interp3(fsde3w(ji,jjd,1),asp(ji,jjd,1), &
@@ -1325,19 +1298,16 @@
             ENDIF
 
-            IF(jjd > jjs) THEN
-              pn = pnsd; ps = pnss
-            ELSE
-              pn = pnss; ps = pnsd
-            ENDIF
 
             dpdy1 = zcoef0 / e2v(ji,jj) * (zhpi(ji,jj+1,jk) - zhpi(ji,jj,jk))
             if(lk_vvl) then
-                dpdy2 = zcoef0 / e2v(ji,jj) * (ps + pn + (sshn(ji,jj+1)-sshn(ji,jj))) 
+                dpdy2 = zcoef0 / e2v(ji,jj) * &
+                        (REAL(jjs-jjd, wp) * (pnss + pnsd) + (sshn(ji,jj+1)-sshn(ji,jj))) 
               else
-                dpdy2 = zcoef0 / e2v(ji,jj) * (ps + pn ) 
+                dpdy2 = zcoef0 / e2v(ji,jj) * REAL(jjs-jjd, wp) * (pnss + pnsd ) 
             end if
 
             va(ji,jj,jk) = va(ji,jj,jk) + (dpdy1 + dpdy2)*&
             &              vmask(ji,jj,jk)*tmask(ji,jj,jk)*tmask(ji,jj+1,jk)
+            ENDIF
 
                     
