Index: codes/icosagcm/devel/src/dynamics/compute_caldyn_vert_NH.F90
===================================================================
--- codes/icosagcm/devel/src/dynamics/caldyn_kernels_base.F90	(revision 920)
+++ codes/icosagcm/devel/src/dynamics/compute_caldyn_vert_NH.F90	(revision 928)
@@ -1,7 +1,6 @@
-MODULE caldyn_kernels_base_mod
-  USE icosa
-  USE transfert_mod
+MODULE compute_caldyn_vert_NH_mod
+  USE prec, ONLY : rstd
+  USE grid_param
   USE disvert_mod
-  USE caldyn_vars_mod
   USE omp_para
   USE trace
@@ -10,121 +9,10 @@
   SAVE
 
-  PUBLIC :: compute_caldyn_vert, compute_caldyn_vert_nh
+  PUBLIC :: compute_caldyn_vert_nh_manual, &
+       compute_caldyn_vert_nh_hex
 
 CONTAINS
 
-
-  SUBROUTINE compute_caldyn_vert(u,theta,rhodz,convm, wflux,wwuu, dps,dtheta_rhodz,du)
-    REAL(rstd),INTENT(IN)  :: u(iim*3*jjm,llm)
-    REAL(rstd),INTENT(IN)  :: theta(iim*jjm,llm,nqdyn)
-    REAL(rstd),INTENT(IN)  :: rhodz(iim*jjm,llm)
-    REAL(rstd),INTENT(INOUT)  :: convm(iim*jjm,llm)  ! mass flux convergence
-    REAL(rstd),INTENT(INOUT) :: wflux(iim*jjm,llm+1) ! vertical mass flux (kg/m2/s)
-    REAL(rstd),INTENT(INOUT) :: wwuu(iim*3*jjm,llm+1)
-    REAL(rstd),INTENT(INOUT) :: du(iim*3*jjm,llm)
-    REAL(rstd),INTENT(INOUT) :: dtheta_rhodz(iim*jjm,llm,nqdyn)
-    REAL(rstd),INTENT(OUT) :: dps(iim*jjm)
-
-    ! temporary variable    
-    INTEGER :: i,j,ij,l,iq
-    REAL(rstd) :: p_ik, exner_ik, dF_deta, dFu_deta
-    INTEGER    :: ij_omp_begin, ij_omp_end
-
-    CALL trace_start("compute_caldyn_vert")
-
-!$OMP BARRIER
-
-    CALL distrib_level(ij_begin,ij_end, ij_omp_begin,ij_omp_end)
-
-    IF(dysl_caldyn_vert) THEN
-#define mass_bl(ij,l) bp(l)
-#define dmass_col(ij) dps(ij)
-#include "../kernels_hex/caldyn_wflux.k90"
-#include "../kernels_hex/caldyn_vert.k90"
-#undef mass_bl
-#undef dmass_col
-    ELSE
-
-!!! cumulate mass flux convergence from top to bottom
-    DO  l = llm-1, 1, -1
-       !DIR$ SIMD
-       DO ij=ij_omp_begin,ij_omp_end         
-          convm(ij,l) = convm(ij,l) + convm(ij,l+1)
-       ENDDO
-    ENDDO
-    !  ENDIF
-
-    !$OMP BARRIER
-    ! FLUSH on convm
-    ! compute dmass_col
-    IF (is_omp_first_level) THEN
-       !DIR$ SIMD
-       DO ij=ij_begin,ij_end         
-          ! dps/dt = -int(div flux)dz
-          dps(ij) = convm(ij,1)
-       ENDDO
-    ENDIF
-
-!!! Compute vertical mass flux (l=1,llm+1 done by caldyn_BC)
-    DO l=ll_beginp1,ll_end
-       !    IF (caldyn_conserv==energy) CALL test_message(req_qu) 
-       !DIR$ SIMD
-       DO ij=ij_begin,ij_end         
-          ! w = int(z,ztop,div(flux)dz) + B(eta)dps/dt
-          ! => w>0 for upward transport
-          wflux( ij, l ) = bp(l) * convm( ij, 1 ) - convm( ij, l ) 
-       ENDDO
-    ENDDO
-
-    !--> flush wflux  
-    !$OMP BARRIER
-
-    DO iq=1,nqdyn
-       DO l=ll_begin,ll_endm1
-       !DIR$ SIMD
-          DO ij=ij_begin,ij_end         
-             dtheta_rhodz(ij, l, iq) = dtheta_rhodz(ij, l, iq)  -   0.5 * &
-                  ( wflux(ij,l+1) * (theta(ij,l,iq) + theta(ij,l+1,iq)))
-          END DO
-       END DO
-       DO l=ll_beginp1,ll_end
-          !DIR$ SIMD
-          DO ij=ij_begin,ij_end         
-             dtheta_rhodz(ij, l, iq) = dtheta_rhodz(ij, l, iq)  +   0.5 * &
-                  ( wflux(ij,l) * (theta(ij,l-1,iq) + theta(ij,l,iq) ) )
-          END DO
-       END DO
-    END DO
-
-    ! Compute vertical transport
-    DO l=ll_beginp1,ll_end
-       !DIR$ SIMD
-       DO ij=ij_begin,ij_end         
-          wwuu(ij+u_right,l) = 0.5*( wflux(ij,l) + wflux(ij+t_right,l)) * (u(ij+u_right,l) - u(ij+u_right,l-1))
-          wwuu(ij+u_lup,l) = 0.5* ( wflux(ij,l) + wflux(ij+t_lup,l)) * (u(ij+u_lup,l) - u(ij+u_lup,l-1))
-          wwuu(ij+u_ldown,l) = 0.5*( wflux(ij,l) + wflux(ij+t_ldown,l)) * (u(ij+u_ldown,l) - u(ij+u_ldown,l-1))
-       ENDDO
-    ENDDO
-
-    !--> flush wwuu  
-    !$OMP BARRIER
-
-    ! Add vertical transport to du
-    DO l=ll_begin,ll_end
-       !DIR$ SIMD
-       DO ij=ij_begin,ij_end         
-          du(ij+u_right, l )   = du(ij+u_right,l)  - (wwuu(ij+u_right,l+1)+ wwuu(ij+u_right,l)) / (rhodz(ij,l)+rhodz(ij+t_right,l))
-          du(ij+u_lup, l )     = du(ij+u_lup,l)    - (wwuu(ij+u_lup,l+1)  + wwuu(ij+u_lup,l))   / (rhodz(ij,l)+rhodz(ij+t_lup,l))
-          du(ij+u_ldown, l )   = du(ij+u_ldown,l)  - (wwuu(ij+u_ldown,l+1)+ wwuu(ij+u_ldown,l)) / (rhodz(ij,l)+rhodz(ij+t_ldown,l))
-       ENDDO
-    ENDDO
-
-    END IF ! dysl
-
-    CALL trace_end("compute_caldyn_vert")
-
-  END SUBROUTINE compute_caldyn_vert
-
-  SUBROUTINE compute_caldyn_vert_NH(mass,geopot,W,wflux, W_etadot, du,dPhi,dW)
+  SUBROUTINE compute_caldyn_vert_NH_hex(mass,geopot,W,wflux, W_etadot, du,dPhi,dW)
     REAL(rstd),INTENT(IN) :: mass(iim*jjm,llm)
     REAL(rstd),INTENT(IN) :: geopot(iim*jjm,llm+1)
@@ -144,9 +32,28 @@
     CALL trace_start("compute_caldyn_vert_nh")
 
-    IF(dysl) THEN
 !$OMP BARRIER
 #include "../kernels_hex/caldyn_vert_NH.k90"
 !$OMP BARRIER
-    ELSE
+    CALL trace_end("compute_caldyn_vert_nh")
+  END SUBROUTINE compute_caldyn_vert_NH_hex
+
+  SUBROUTINE compute_caldyn_vert_NH_manual(mass,geopot,W,wflux, W_etadot, du,dPhi,dW)
+    REAL(rstd),INTENT(IN) :: mass(iim*jjm,llm)
+    REAL(rstd),INTENT(IN) :: geopot(iim*jjm,llm+1)
+    REAL(rstd),INTENT(IN) :: W(iim*jjm,llm+1)
+    REAL(rstd),INTENT(IN) :: wflux(iim*jjm,llm+1)
+    REAL(rstd),INTENT(INOUT) :: du(iim*3*jjm,llm)
+    REAL(rstd),INTENT(INOUT) :: dPhi(iim*jjm,llm+1)
+    REAL(rstd),INTENT(INOUT) :: dW(iim*jjm,llm+1)
+    REAL(rstd) :: W_etadot(iim*jjm,llm) ! vertical flux of vertical momentum
+    ! local arrays
+    REAL(rstd) :: eta_dot(iim*jjm, llm) ! eta_dot in full layers
+    REAL(rstd) :: wcov(iim*jjm,llm) ! covariant vertical momentum in full layers
+    ! indices and temporary values
+    INTEGER    :: ij, l
+    REAL(rstd) :: wflux_ij, w_ij
+
+    CALL trace_start("compute_caldyn_vert_nh")
+
 #define ETA_DOT(ij) eta_dot(ij,1)
 #define WCOV(ij) wcov(ij,1)
@@ -196,8 +103,7 @@
 #undef WCOV
 
-    END IF ! dysl
     CALL trace_end("compute_caldyn_vert_nh")
 
-  END SUBROUTINE compute_caldyn_vert_NH
+  END SUBROUTINE compute_caldyn_vert_NH_manual
 
-END MODULE caldyn_kernels_base_mod
+END MODULE compute_caldyn_vert_NH_mod
