Index: codes/icosagcm/devel/src/diagnostics/diagflux.F90
===================================================================
--- codes/icosagcm/devel/src/diagnostics/diagflux.F90	(revision 602)
+++ codes/icosagcm/devel/src/diagnostics/diagflux.F90	(revision 603)
@@ -54,4 +54,6 @@
        CALL swap_dimensions(ind)
        ZERO2(f_masst)
+       ZERO2(f_ulont)
+       ZERO2(f_thetat)
        ZERO2(f_epot)
        ZERO2(f_ekin)
@@ -59,4 +61,6 @@
        ZERO3(f_qmasst)
        ZERO2(f_massfluxt)
+       ZERO2(f_ulonfluxt)
+       ZERO2(f_thetafluxt)
        ZERO2(f_epotfluxt)
        ZERO2(f_ekinfluxt)
@@ -165,7 +169,5 @@
     ! even if loops are of the _ext variant, we still need halo exchanges before reconstructing fluxes at cell centers
     ! => loop over interior region
-    CALL distrib_level(ij_end-ij_begin+1,ij_omp_begin_ext,ij_omp_end_ext)
-    ij_omp_begin_ext = ij_omp_begin_ext+ij_begin-1
-    ij_omp_end_ext = ij_omp_end_ext+ij_begin-1
+    CALL distrib_level(ij_begin_ext, ij_end_ext, ij_omp_begin_ext,ij_omp_end_ext)
 #include "../kernels/energy_fluxes.k90"
   END SUBROUTINE compute_diagflux_energy
Index: codes/icosagcm/devel/src/diagnostics/observable.f90
===================================================================
--- codes/icosagcm/devel/src/diagnostics/observable.f90	(revision 602)
+++ codes/icosagcm/devel/src/diagnostics/observable.f90	(revision 603)
@@ -1,4 +1,6 @@
 MODULE observable_mod
   USE icosa
+  USE diagflux_mod
+  USE output_field_mod
   IMPLICIT NONE
   PRIVATE
@@ -35,5 +37,4 @@
     USE disvert_mod
     USE wind_mod
-    USE output_field_mod
     USE omp_para
     USE time_mod
@@ -44,5 +45,4 @@
     USE theta2theta_rhodz_mod
     USE omega_mod
-    USE diagflux_mod
     LOGICAL, INTENT(IN) :: init
     INTEGER :: l
@@ -163,21 +163,9 @@
           CALL output_field("massflux_lat",f_buf_ulat)
 
-          CALL transfert_request(f_epotfluxt,req_e1_vect) 
-          CALL flux_centered_lonlat(1./(itau_out*dt) , f_epotfluxt, f_buf_ulon, f_buf_ulat)
-          CALL output_field("epot_t", f_epot)
-          CALL output_field("epotflux_lon",f_buf_ulon)
-          CALL output_field("epotflux_lat",f_buf_ulat)
-
-          CALL transfert_request(f_ekinfluxt,req_e1_vect) 
-          CALL flux_centered_lonlat(1./(itau_out*dt) , f_ekinfluxt, f_buf_ulon, f_buf_ulat)
-          CALL output_field("ekin_t", f_ekin)
-          CALL output_field("ekinflux_lon",f_buf_ulon)
-          CALL output_field("ekinflux_lat",f_buf_ulat)
-
-          CALL transfert_request(f_enthalpyfluxt,req_e1_vect) 
-          CALL flux_centered_lonlat(1./(itau_out*dt) , f_enthalpyfluxt, f_buf_ulon, f_buf_ulat)
-          CALL output_field("enthalpy_t", f_enthalpy)
-          CALL output_field("enthalpyflux_lon",f_buf_ulon)
-          CALL output_field("enthalpyflux_lat",f_buf_ulat)
+          CALL output_energyflux(f_ulont, f_ulonfluxt, "ulon_t", "ulonflux_lon", "ulonflux_lat")
+          CALL output_energyflux(f_thetat, f_thetafluxt, "theta_t", "thetaflux_lon", "thetaflux_lat")
+          CALL output_energyflux(f_epot, f_epotfluxt, "epot_t", "epotflux_lon", "epotflux_lat")
+          CALL output_energyflux(f_ekin, f_ekinfluxt, "ekin_t", "ekinflux_lon", "ekinflux_lat")
+          CALL output_energyflux(f_enthalpy, f_enthalpyfluxt, "enthalpy_t", "enthalpyflux_lon", "enthalpyflux_lat")
 
           CALL qflux_centered_lonlat(1./(itau_out*dt) , f_qfluxt, f_qfluxt_lon, f_qfluxt_lat)
@@ -189,4 +177,14 @@
     END IF
   END SUBROUTINE write_output_fields_basic
+
+  SUBROUTINE output_energyflux(f_energy, f_flux, name_energy, name_fluxlon, name_fluxlat)
+    TYPE(t_field), POINTER :: f_energy(:), f_flux(:)
+    CHARACTER(*), INTENT(IN) :: name_energy, name_fluxlon, name_fluxlat
+    CALL transfert_request(f_flux,req_e1_vect)
+    CALL flux_centered_lonlat(1./(itau_out*dt) , f_flux, f_buf_ulon, f_buf_ulat)
+    CALL output_field(name_energy,  f_energy)
+    CALL output_field(name_fluxlon, f_buf_ulon)
+    CALL output_field(name_fluxlat, f_buf_ulat)
+  END SUBROUTINE output_energyflux
   
  !------------------- Conversion from prognostic to observable variables ------------------
Index: codes/icosagcm/devel/src/dynamics/caldyn_kernels_base.F90
===================================================================
--- codes/icosagcm/devel/src/dynamics/caldyn_kernels_base.F90	(revision 602)
+++ codes/icosagcm/devel/src/dynamics/caldyn_kernels_base.F90	(revision 603)
@@ -43,7 +43,5 @@
 !$OMP BARRIER
 
-    CALL distrib_level(ij_end_ext-ij_begin_ext+1,ij_omp_begin_ext,ij_omp_end_ext)
-    ij_omp_begin_ext=ij_omp_begin_ext+ij_begin_ext-1
-    ij_omp_end_ext=ij_omp_end_ext+ij_begin_ext-1
+    CALL distrib_level(ij_begin_ext,ij_end_ext, ij_omp_begin_ext,ij_omp_end_ext)
 
     Rd = kappa*cpp
@@ -190,7 +188,5 @@
     CALL trace_start("compute_caldyn_vert")
 
-    CALL distrib_level(ij_end-ij_begin+1,ij_omp_begin,ij_omp_end)
-    ij_omp_begin=ij_omp_begin+ij_begin-1
-    ij_omp_end=ij_omp_end+ij_begin-1
+    CALL distrib_level(ij_begin,ij_end, ij_omp_begin,ij_omp_end)
 
     !    REAL(rstd) :: wwuu(iim*3*jjm,llm+1) ! tmp var, don't know why but gain 30% on the whole code in opemp
Index: codes/icosagcm/devel/src/dynamics/caldyn_kernels_hevi.F90
===================================================================
--- codes/icosagcm/devel/src/dynamics/caldyn_kernels_hevi.F90	(revision 602)
+++ codes/icosagcm/devel/src/dynamics/caldyn_kernels_hevi.F90	(revision 603)
@@ -122,7 +122,5 @@
     INTEGER    :: iter, ij, l, ij_omp_begin_ext, ij_omp_end_ext
 
-    CALL distrib_level(ij_end_ext-ij_begin_ext+1,ij_omp_begin_ext,ij_omp_end_ext)
-    ij_omp_begin_ext=ij_omp_begin_ext+ij_begin_ext-1
-    ij_omp_end_ext=ij_omp_end_ext+ij_begin_ext-1
+    CALL distrib_level(ij_begin_ext,ij_end_ext, ij_omp_begin_ext,ij_omp_end_ext)
 
     IF(dysl) THEN
Index: codes/icosagcm/devel/src/parallel/omp_para.F90
===================================================================
--- codes/icosagcm/devel/src/parallel/omp_para.F90	(revision 602)
+++ codes/icosagcm/devel/src/parallel/omp_para.F90	(revision 603)
@@ -204,18 +204,18 @@
   END SUBROUTINE init_omp_para
 
-  SUBROUTINE distrib_level(size,lbegin,lend)
-  IMPLICIT NONE
-    INTEGER,INTENT(IN)  :: size  
+  SUBROUTINE distrib_level(ibegin,iend, lbegin,lend)
+  IMPLICIT NONE
+    INTEGER,INTENT(IN)  :: ibegin,iend  
     INTEGER,INTENT(OUT) :: lbegin  
     INTEGER,INTENT(OUT) :: lend  
-    INTEGER :: div,rest
-    
+    INTEGER :: size,div,rest
+    size=iend-ibegin+1
     div=size/omp_level_size
     rest=MOD(size,omp_level_size)
     IF (omp_level_rank<rest) THEN
-      lbegin=(div+1)*omp_level_rank+1
+      lbegin=(div+1)*omp_level_rank + ibegin
       lend=lbegin+div
     ELSE
-      lbegin=(div+1)*rest + (omp_level_rank-rest)*div+1
+      lbegin=(div+1)*rest + (omp_level_rank-rest)*div + ibegin
       lend=lbegin+div-1
     ENDIF
Index: codes/icosagcm/devel/src/parallel/transfert_mpi.f90
===================================================================
--- codes/icosagcm/devel/src/parallel/transfert_mpi.f90	(revision 602)
+++ codes/icosagcm/devel/src/parallel/transfert_mpi.f90	(revision 603)
@@ -1237,5 +1237,5 @@
 
           dim3=size(field(ind)%rval3d,2)
-          CALL distrib_level(dim3,lbegin,lend)
+          CALL distrib_level(1,dim3, lbegin,lend)
 
           rval3d=>field(ind)%rval3d
@@ -1295,5 +1295,5 @@
           IF (.NOT. assigned_domain(ind) ) CYCLE
           dim3=size(field(ind)%rval3d,2)
-          CALL distrib_level(dim3,lbegin,lend)
+          CALL distrib_level(1,dim3, lbegin,lend)
           rval3d=>field(ind)%rval3d
           req=>message%request(ind)
@@ -1349,5 +1349,5 @@
 
           dim3=size(field(ind)%rval4d,2)
-          CALL distrib_level(dim3,lbegin,lend)
+          CALL distrib_level(1,dim3, lbegin,lend)
           dim4=size(field(ind)%rval4d,3)
           rval4d=>field(ind)%rval4d
@@ -1411,5 +1411,5 @@
           
           dim3=size(field(ind)%rval4d,2)
-          CALL distrib_level(dim3,lbegin,lend)
+          CALL distrib_level(1,dim3, lbegin,lend)
           dim4=size(field(ind)%rval4d,3)
           rval4d=>field(ind)%rval4d
@@ -1589,5 +1589,5 @@
               dim3=size(rval3d,2)
     
-              CALL distrib_level(dim3,lbegin,lend)
+              CALL distrib_level(1,dim3, lbegin,lend)
               offset=recv%offset*dim3 + (lbegin-1)*recv%size
               CALL trace_start("copy_from_buffer")
@@ -1637,5 +1637,5 @@
 
               dim3=size(rval4d,2)
-              CALL distrib_level(dim3,lbegin,lend)
+              CALL distrib_level(1,dim3, lbegin,lend)
               dim4=size(rval4d,3)
               CALL trace_start("copy_from_buffer")
