Index: /codes/icosagcm/trunk/jsrc/base/field.f90
===================================================================
--- /codes/icosagcm/trunk/jsrc/base/field.f90	(revision 1055)
+++ /codes/icosagcm/trunk/jsrc/base/field.f90	(revision 1055)
@@ -0,0 +1,331 @@
+MODULE field_mod
+  USE genmod
+  IMPLICIT NONE
+
+  INTEGER,PARAMETER :: field_T=1
+  INTEGER,PARAMETER :: field_U=2
+  INTEGER,PARAMETER :: field_Z=3
+
+  INTEGER,PARAMETER :: type_integer=1
+  INTEGER,PARAMETER :: type_real=2
+  INTEGER,PARAMETER :: type_logical=3
+
+  {%- set ranks = ( (2,':'), (3,':,:'), (4,':,:,:') ) %}
+  {%- set types = ( ('r','real','REAL(rstd)'), ('i','integer','INTEGER'), ('l','logical','LOGICAL') ) %}
+  
+  TYPE t_field
+     CHARACTER(30)      :: name
+     LOGICAL :: ondevice !< flag if field is allocated on device as well
+     INTEGER :: ndim
+     INTEGER :: field_type
+     INTEGER :: data_type
+     INTEGER :: dim3
+     INTEGER :: dim4
+
+     {%- for tn, tln, tp in types %} {%- for rk, shp in ranks %}     
+     {{tp}}, POINTER, CONTIGUOUS :: {{tn}}val{{rk}}d({{shp}}) => NULL()
+     {%- endfor %} {%- endfor %}
+  END TYPE t_field
+
+  INTERFACE get_val
+     {%- for tn, tln, tp in types %} {%- for rk, shp in ranks %}     
+     MODULE PROCEDURE getval_{{tn}}{{rk}}d
+     {%- endfor %} {%- endfor %}
+  END INTERFACE
+
+  INTERFACE ASSIGNMENT(=)
+     {%- for tn, tln, tp in types %} {%- for rk, shp in ranks %}     
+     MODULE PROCEDURE getval_{{tn}}{{rk}}d
+     {%- endfor %} {%- endfor %}
+  END INTERFACE
+  
+  PRIVATE :: allocate_field_, deallocate_field_
+
+CONTAINS
+
+  !====================================== allocate_field ===================================
+
+  SUBROUTINE allocate_field_glo(field,field_type,data_type,dim1,dim2,name)
+    USE domain_mod
+    TYPE(t_field),POINTER :: field(:)
+    INTEGER,INTENT(IN) :: field_type
+    INTEGER,INTENT(IN) :: data_type
+    INTEGER,OPTIONAL :: dim1,dim2
+    CHARACTER(*), OPTIONAL :: name
+    INTEGER :: ind
+
+    ALLOCATE(field(ndomain_glo))
+    DO ind=1,ndomain_glo
+       CALL allocate_field_(domain_glo(ind), field(ind), field_type, data_type, dim1, dim2, name)
+    ENDDO
+
+  END SUBROUTINE allocate_field_glo
+
+  SUBROUTINE allocate_field(field, field_type, data_type, dim3, dim4, name, ondevice)
+    USE domain_mod
+    USE omp_para
+    TYPE(t_field), POINTER :: field(:)
+    INTEGER, INTENT(IN)    :: field_type
+    INTEGER, INTENT(IN)    :: data_type
+    INTEGER, OPTIONAL      :: dim3,dim4
+    CHARACTER(*), OPTIONAL :: name
+    LOGICAL, INTENT(IN), OPTIONAL :: ondevice
+    INTEGER :: ind
+    !$OMP BARRIER
+    !$OMP MASTER
+    ALLOCATE(field(ndomain))
+    !$OMP END MASTER
+    !$OMP BARRIER
+
+    DO ind=1,ndomain
+       IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
+       CALL allocate_field_(domain(ind), field(ind), field_type, data_type, dim3, dim4, name, ondevice)
+    END DO
+    !$OMP BARRIER
+
+  END SUBROUTINE allocate_field
+
+  SUBROUTINE allocate_fields(nfield,field,field_type,data_type,dim3,dim4,name, ondevice)
+    USE domain_mod
+    USE omp_para
+    INTEGER, INTENT(IN)     :: nfield
+    TYPE(t_field), POINTER  :: field(:,:)
+    INTEGER, INTENT(IN)     :: field_type
+    INTEGER, INTENT(IN)     :: data_type
+    INTEGER, OPTIONAL       :: dim3,dim4
+    CHARACTER(*), OPTIONAL  :: name
+    LOGICAL, INTENT(IN), OPTIONAL :: ondevice
+    INTEGER :: i, ind
+    !$OMP BARRIER
+    !$OMP MASTER
+    ALLOCATE(field(ndomain,nfield))
+    !$OMP END MASTER
+    !$OMP BARRIER
+    DO ind=1,ndomain
+       IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
+       DO i=1,nfield
+          CALL allocate_field_(domain(ind), field(ind,i),field_type, data_type, dim3, dim4, name, ondevice)
+       END DO
+    END DO
+    !$OMP BARRIER
+
+  END SUBROUTINE allocate_fields
+
+  SUBROUTINE allocate_field_(dom, field, field_type, data_type, dim3, dim4, name, ondevice)
+    USE domain_mod
+    USE omp_para
+    TYPE(t_domain)         :: dom
+    TYPE(t_field)          :: field
+    INTEGER, INTENT(IN)    :: field_type
+    INTEGER, INTENT(IN)    :: data_type
+    INTEGER, OPTIONAL      :: dim3,dim4
+    CHARACTER(*), OPTIONAL :: name
+    LOGICAL, INTENT(IN), OPTIONAL :: ondevice
+
+    INTEGER :: ij_size
+
+    IF(PRESENT(name)) THEN
+       field%name = name
+    ELSE
+       field%name = '(undefined)'
+    END IF
+
+    IF (PRESENT(dim4)) THEN
+       field%ndim=4
+       field%dim4=dim4
+       field%dim3=dim3
+    ELSE IF (PRESENT(dim3)) THEN
+       field%ndim=3
+       field%dim3=dim3
+       field%dim4=1
+    ELSE
+       field%ndim=2
+       field%dim3=1
+       field%dim4=1
+    ENDIF
+
+
+    field%data_type=data_type
+    field%field_type=field_type
+
+    IF (field_type==field_T) THEN
+       ij_size=dom%iim*dom%jjm
+    ELSE IF (field_type==field_U) THEN
+       ij_size=3*dom%iim*dom%jjm
+    ELSE IF (field_type==field_Z) THEN
+       ij_size=2*dom%iim*dom%jjm
+    ENDIF
+
+    IF (data_type==type_integer) ALLOCATE(field%ival4d(ij_size, field%dim3, field%dim4))
+    IF (data_type==type_real)    ALLOCATE(field%rval4d(ij_size, field%dim3, field%dim4))
+    IF (data_type==type_logical) ALLOCATE(field%lval4d(ij_size, field%dim3, field%dim4))
+
+    IF (field%ndim==3) THEN
+       IF (data_type==type_integer) field%ival3d => field%ival4d(:,:,1)
+       IF (data_type==type_real)    field%rval3d => field%rval4d(:,:,1)
+       IF (data_type==type_logical) field%lval3d => field%lval4d(:,:,1)
+
+    ELSE IF (field%ndim==2) THEN
+       IF (data_type==type_integer) field%ival2d => field%ival4d(:,1,1)
+       IF (data_type==type_real)    field%rval2d => field%rval4d(:,1,1)
+       IF (data_type==type_logical) field%lval2d => field%lval4d(:,1,1)
+
+    ENDIF
+
+    field%ondevice = .FALSE.
+    IF (PRESENT(ondevice)) THEN
+       IF (ondevice) CALL create_device_field(field)
+    END IF
+
+  END SUBROUTINE allocate_field_
+
+  !==================================== deallocate_field ===================================
+
+  SUBROUTINE deallocate_field_glo(field)
+    USE domain_mod
+    TYPE(t_field),POINTER :: field(:)
+    INTEGER :: ind
+    DO ind=1,ndomain_glo
+       CALL deallocate_field_(field(ind))
+    END DO
+    DEALLOCATE(field)
+  END SUBROUTINE deallocate_field_glo
+
+  SUBROUTINE deallocate_field(field)
+    USE domain_mod
+    USE omp_para
+    TYPE(t_field),POINTER :: field(:)
+    INTEGER :: ind
+    !$OMP BARRIER
+    DO ind=1,ndomain
+       IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
+       CALL deallocate_field_(field(ind))
+    END DO
+    !$OMP BARRIER
+    !$OMP MASTER
+    DEALLOCATE(field)
+    !$OMP END MASTER
+    !$OMP BARRIER
+  END SUBROUTINE deallocate_field
+
+  SUBROUTINE deallocate_fields(field)
+    USE domain_mod
+    USE omp_para
+    TYPE(t_field),POINTER :: field(:,:)
+    INTEGER :: i, ind
+    !$OMP BARRIER
+    DO ind=1,ndomain
+       IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
+       DO i=1,SIZE(field,2)
+          CALL deallocate_field_(field(ind,i))
+       END DO
+    END DO
+    !$OMP BARRIER
+    !$OMP MASTER
+    DEALLOCATE(field)
+    !$OMP END MASTER
+    !$OMP BARRIER
+  END SUBROUTINE deallocate_fields
+
+  SUBROUTINE deallocate_field_(field)
+    USE domain_mod
+    USE omp_para
+    TYPE(t_field) :: field
+    INTEGER :: data_type
+    data_type=field%data_type
+
+    {%- for tn, tln, tp in types %}
+    IF (data_type==type_{{tln}}) THEN
+       IF (field%ondevice) THEN
+          !$acc exit data delete(field%{{tn}}val4d(:,:,:))
+          CONTINUE
+       END IF
+       DEALLOCATE(field%{{tn}}val4d)
+    END IF
+    {%- endfor %}
+
+  END SUBROUTINE deallocate_field_
+
+  !====================================== getval ===================================
+
+  {%- for tn, tln, tp in types %} {%- for rk, shp in ranks %}
+
+  SUBROUTINE getval_{{tn}}{{rk}}d(field_pt,field)
+    {{tp}}, POINTER, INTENT(INOUT) :: field_pt({{shp}})
+    TYPE(t_field),INTENT(IN) :: field
+
+    IF (field%ndim/={{rk}} .OR. field%data_type/=type_{{tln}}) THEN
+       PRINT *, 'getval_{{tn}}{{rk}}d : bad pointer assignment with ' // TRIM(field%name)
+       STOP
+    END IF
+    field_pt=>field%{{tn}}val{{rk}}d
+  END SUBROUTINE getval_{{tn}}{{rk}}d
+
+  {%- endfor %} {%- endfor %}
+
+  !===================== Data transfer between host (CPU) and device (GPU) =========================
+
+  SUBROUTINE update_device_field(field)
+    USE domain_mod
+    USE omp_para
+    TYPE(t_field) :: field(:)
+    INTEGER :: ind
+
+    DO ind=1,ndomain
+       IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
+
+       IF (.NOT. field(ind)%ondevice) CALL create_device_field(field(ind))
+
+       {%- for tn, tln, tp in types %}
+       IF (field(ind)%data_type==type_{{tln}}) THEN
+          !$acc update device(field(ind)%{{tn}}val4d(:,:,:)) async
+          CONTINUE
+       END IF
+       {%- endfor %}
+
+    ENDDO
+    !$OMP BARRIER
+  END SUBROUTINE update_device_field
+
+  SUBROUTINE update_host_field(field)
+    USE domain_mod
+    USE omp_para
+    TYPE(t_field) :: field(:)
+    INTEGER :: ind
+
+    DO ind=1,ndomain
+       IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
+
+       IF (field(ind)%ondevice) THEN
+          
+          {%- for tn, tln, tp in types %}
+          IF (field(ind)%data_type==type_{{tln}}) THEN
+             !$acc update host(field(ind)%{{tn}}val4d(:,:,:)) async
+             CONTINUE
+          END IF
+          {%- endfor %}
+          
+       END IF
+    ENDDO
+    !$acc wait
+    !$OMP BARRIER
+  END SUBROUTINE update_host_field
+
+  SUBROUTINE create_device_field(field)
+    TYPE(t_field) :: field
+
+    IF (field%ondevice) THEN
+       PRINT *, "Field is already on device !"
+       STOP 1
+    END IF
+    
+    {%- for tn, tln, tp in types %}
+    IF (field%data_type==type_{{tln}}) THEN
+       !$acc enter data create(field%{{tn}}val4d(:,:,:)) async
+    END IF
+    {%- endfor %}
+    
+    field%ondevice = .TRUE.
+  END SUBROUTINE create_device_field
+
+END MODULE field_mod
Index: /codes/icosagcm/trunk/jsrc/jinja2
===================================================================
--- /codes/icosagcm/trunk/jsrc/jinja2	(revision 1055)
+++ /codes/icosagcm/trunk/jsrc/jinja2	(revision 1055)
@@ -0,0 +1,9 @@
+#!/bin/env python
+
+from jinja2 import Environment, FileSystemLoader
+from sys import argv
+
+env=Environment(loader=FileSystemLoader('.'))
+tpl=env.get_template(argv[1])
+source = tpl.render()
+print(source)
Index: /codes/icosagcm/trunk/jsrc/parallel/transfert_mpi_collectives.f90
===================================================================
--- /codes/icosagcm/trunk/jsrc/parallel/transfert_mpi_collectives.f90	(revision 1055)
+++ /codes/icosagcm/trunk/jsrc/parallel/transfert_mpi_collectives.f90	(revision 1055)
@@ -0,0 +1,167 @@
+MODULE transfert_mpi_collectives_mod
+  IMPLICIT NONE
+
+  {%- set ranks = ( (1,':'), (2,':,:'), (3,':,:,:'), (4,':,:,:,:') ) %}
+  {%- set types = ( ('i','INTEGER','MPI_INTEGER'),
+  ('r','REAL','MPI_REAL8'), ('l','LOGICAL','MPI_LOGICAL') ) %}
+
+  INTERFACE bcast_mpi
+     MODULE PROCEDURE bcast_mpi_c
+     {%- for tn, tp, mpi in types %}
+     MODULE PROCEDURE bcast_mpi_{{tn}} {%- for rk, junk in ranks %}, bcast_mpi_{{tn}}{{rk}} {%- endfor %}
+     {%- endfor %}
+  END INTERFACE bcast_mpi
+
+CONTAINS
+
+  SUBROUTINE gather_field(field_loc,field_glo)
+    USE field_mod
+    USE domain_mod
+    USE mpi_mod
+    USE mpipara
+    TYPE(t_field),POINTER :: field_loc(:)
+    TYPE(t_field),POINTER :: field_glo(:)
+    INTEGER, ALLOCATABLE :: mpi_req(:)
+    INTEGER, ALLOCATABLE :: status(:,:)
+    INTEGER :: ireq,nreq
+    INTEGER :: ind_glo,ind_loc
+
+    IF (.NOT. using_mpi) THEN
+       DO ind_loc=1,ndomain
+          field_glo(ind_loc)%rval4d=field_loc(ind_loc)%rval4d
+       ENDDO
+
+    ELSE
+       nreq=ndomain
+       IF (mpi_rank==0) nreq=nreq+ndomain_glo
+       ALLOCATE(mpi_req(nreq))
+       ALLOCATE(status(MPI_STATUS_SIZE,nreq))
+
+       ireq=0
+       IF (mpi_rank==0) THEN
+          DO ind_glo=1,ndomain_glo
+             ireq=ireq+1
+             CALL MPI_IRECV(field_glo(ind_glo)%rval4d,size(field_glo(ind_glo)%rval4d) , MPI_REAL8 ,   &
+                  domglo_rank(ind_glo),domglo_loc_ind(ind_glo), comm_icosa, mpi_req(ireq), ierr)
+          ENDDO
+       ENDIF
+
+       DO ind_loc=1,ndomain
+          ireq=ireq+1
+          CALL MPI_ISEND(field_loc(ind_loc)%rval4d,size(field_loc(ind_loc)%rval4d) , MPI_REAL8 ,   &
+               0, ind_loc, comm_icosa, mpi_req(ireq), ierr)
+       ENDDO
+
+       CALL MPI_WAITALL(nreq,mpi_req,status,ierr)
+
+    ENDIF
+
+  END SUBROUTINE gather_field
+
+  SUBROUTINE bcast_field(field_glo)
+    USE field_mod
+    USE domain_mod
+    USE mpi_mod
+    USE mpipara
+    TYPE(t_field),POINTER :: field_glo(:)
+    INTEGER :: ind_glo
+
+    IF (using_mpi) THEN
+       DO ind_glo=1,ndomain_glo
+          CALL MPI_BCAST(field_glo(ind_glo)%rval4d, size(field_glo(ind_glo)%rval4d) , MPI_REAL8, 0, comm_icosa, ierr)
+       ENDDO
+    ENDIF
+
+  END SUBROUTINE bcast_field
+
+  SUBROUTINE scatter_field(field_glo,field_loc)
+    USE field_mod
+    USE domain_mod
+    USE mpi_mod
+    USE mpipara
+    TYPE(t_field),POINTER :: field_glo(:)
+    TYPE(t_field),POINTER :: field_loc(:)
+    INTEGER, ALLOCATABLE :: mpi_req(:)
+    INTEGER, ALLOCATABLE :: status(:,:)
+    INTEGER :: ireq,nreq
+    INTEGER :: ind_glo,ind_loc
+
+    IF (.NOT. using_mpi) THEN
+       DO ind_loc=1,ndomain
+          field_loc(ind_loc)%rval4d=field_glo(ind_loc)%rval4d
+       ENDDO
+
+    ELSE
+       nreq=ndomain
+       IF (mpi_rank==0) nreq=nreq+ndomain_glo
+       ALLOCATE(mpi_req(nreq))
+       ALLOCATE(status(MPI_STATUS_SIZE,nreq))
+
+       ireq=0
+       IF (mpi_rank==0) THEN
+          DO ind_glo=1,ndomain_glo
+             ireq=ireq+1
+             CALL MPI_ISEND(field_glo(ind_glo)%rval4d,size(field_glo(ind_glo)%rval4d) , MPI_REAL8 ,   &
+                  domglo_rank(ind_glo),domglo_loc_ind(ind_glo), comm_icosa, mpi_req(ireq), ierr)
+          ENDDO
+       ENDIF
+       
+       DO ind_loc=1,ndomain
+          ireq=ireq+1
+          CALL MPI_IRECV(field_loc(ind_loc)%rval4d,size(field_loc(ind_loc)%rval4d) , MPI_REAL8 ,   &
+               0, ind_loc, comm_icosa, mpi_req(ireq), ierr)
+       ENDDO
+       
+       CALL MPI_WAITALL(nreq,mpi_req,status,ierr)
+
+    ENDIF
+
+  END SUBROUTINE scatter_field
+
+  !===================  Broadcast routines for strings ==================!
+
+  SUBROUTINE bcast_mpi_cgen(var,nb)
+    USE mpi_mod
+    USE mpipara
+    CHARACTER(LEN=*),INTENT(INOUT) :: Var
+    INTEGER,INTENT(IN) :: nb
+    IF (.NOT. using_mpi) RETURN
+    CALL MPI_BCAST(Var,nb,MPI_CHARACTER,mpi_master,comm_icosa,ierr)
+  END SUBROUTINE bcast_mpi_cgen
+
+  SUBROUTINE bcast_mpi_c(var1)
+    CHARACTER(LEN=*),INTENT(INOUT) :: Var1
+    CALL bcast_mpi_cgen(Var1,len(Var1))
+  END SUBROUTINE bcast_mpi_c
+  
+  {%- for tn, tp, mpi in types %}
+
+  !============= Broadcast routines for {{tp}} scalars and arrays ============!
+
+  SUBROUTINE bcast_mpi_{{tn}}gen(var,nb)
+    USE mpi_mod
+    USE mpipara
+    INTEGER, INTENT(IN) :: nb
+    {{tp}}, DIMENSION(nb), INTENT(INOUT) :: var
+    IF (using_mpi) CALL MPI_BCAST(Var, nb, {{mpi}}, mpi_master, comm_icosa, ierr)
+  END SUBROUTINE bcast_mpi_{{tn}}gen
+
+  SUBROUTINE bcast_mpi_{{tn}}(var)
+    USE mpipara
+    {{tp}}, INTENT(INOUT) :: var
+    {{tp}}                :: var_tmp(1)
+    IF (is_mpi_master) var_tmp(1)=var
+    CALL bcast_mpi_{{tn}}gen(var_tmp,1)
+    var=var_tmp(1)
+  END SUBROUTINE bcast_mpi_{{tn}}
+
+  {%- for rank, shape in ranks %}
+
+  SUBROUTINE bcast_mpi_{{tn}}{{rank}}(var)
+    {{tp}}, INTENT(INOUT) :: var({{shape}})
+    CALL bcast_mpi_{{tn}}gen(var,size(var))
+  END SUBROUTINE bcast_mpi_{{tn}}{{rank}}
+  {%- endfor %}
+  {%- endfor %}
+
+END MODULE transfert_mpi_collectives_mod
Index: /codes/icosagcm/trunk/jsrc/render
===================================================================
--- /codes/icosagcm/trunk/jsrc/render	(revision 1055)
+++ /codes/icosagcm/trunk/jsrc/render	(revision 1055)
@@ -0,0 +1,35 @@
+#!/bin/env bash
+# Usage :
+# 1) render
+# 2) render indent FILE
+# 3) render ascii FILE
+
+function cmd_indent()
+{
+    ACTIONS='(f90-mode) (indent-region (point-min) (point-max) nil) (delete-trailing-whitespace)'
+    emacs -batch $1 --eval "(progn $ACTIONS)" -f save-buffer 2>/dev/null
+}
+
+function cmd_ascii()
+{
+    TMP=$(mktemp)
+    iconv -f utf-8 -t ascii//translit $1 > $TMP || exit
+    cp $TMP $1
+}
+
+function cmd_()
+{
+    TMP=$(mktemp)
+    for x in $(cd jsrc ; find . -name "*.?90") ; do
+	wc jsrc/$x
+	jsrc/jinja2 jsrc/$x > $TMP
+	cmd_indent $TMP
+	cmp -s $TMP src/$x || cp $TMP src/$x
+	wc src/$x
+    done
+    rm -f $TMP
+}
+
+CMD=$1 ; shift
+cmd_$CMD $*
+
Index: /codes/icosagcm/trunk/src/base/field.f90
===================================================================
--- /codes/icosagcm/trunk/src/base/field.f90	(revision 1054)
+++ /codes/icosagcm/trunk/src/base/field.f90	(revision 1055)
@@ -2,5 +2,5 @@
   USE genmod
   IMPLICIT NONE
-  
+
   INTEGER,PARAMETER :: field_T=1
   INTEGER,PARAMETER :: field_U=2
@@ -10,48 +10,56 @@
   INTEGER,PARAMETER :: type_real=2
   INTEGER,PARAMETER :: type_logical=3
-    
+
   TYPE t_field
-    CHARACTER(30)      :: name
-
-    REAL(rstd),POINTER, CONTIGUOUS :: rval2d(:) => null()
-    REAL(rstd),POINTER, CONTIGUOUS :: rval3d(:,:) => null()
-    REAL(rstd),POINTER, CONTIGUOUS :: rval4d(:,:,:) => null()
-
-    INTEGER,POINTER :: ival2d(:)
-    INTEGER,POINTER :: ival3d(:,:)
-    INTEGER,POINTER :: ival4d(:,:,:)
-    
-    LOGICAL,POINTER :: lval2d(:)
-    LOGICAL,POINTER :: lval3d(:,:)
-    LOGICAL,POINTER :: lval4d(:,:,:)
-
-    INTEGER :: ndim
-    INTEGER :: field_type
-    INTEGER :: data_type 
-    INTEGER :: dim3
-    INTEGER :: dim4
-    
-    LOGICAL :: ondevice !< flag if field is allocated on device as well
-  END TYPE t_field   
+     CHARACTER(30)      :: name
+     LOGICAL :: ondevice !< flag if field is allocated on device as well
+     INTEGER :: ndim
+     INTEGER :: field_type
+     INTEGER :: data_type
+     INTEGER :: dim3
+     INTEGER :: dim4
+     REAL(rstd), POINTER, CONTIGUOUS :: rval2d(:) => NULL()
+     REAL(rstd), POINTER, CONTIGUOUS :: rval3d(:,:) => NULL()
+     REAL(rstd), POINTER, CONTIGUOUS :: rval4d(:,:,:) => NULL()
+     INTEGER, POINTER, CONTIGUOUS :: ival2d(:) => NULL()
+     INTEGER, POINTER, CONTIGUOUS :: ival3d(:,:) => NULL()
+     INTEGER, POINTER, CONTIGUOUS :: ival4d(:,:,:) => NULL()
+     LOGICAL, POINTER, CONTIGUOUS :: lval2d(:) => NULL()
+     LOGICAL, POINTER, CONTIGUOUS :: lval3d(:,:) => NULL()
+     LOGICAL, POINTER, CONTIGUOUS :: lval4d(:,:,:) => NULL()
+  END TYPE t_field
 
   INTERFACE get_val
-    MODULE PROCEDURE getval_r2d,getval_r3d,getval_r4d, &
-                     getval_i2d,getval_i3d,getval_i4d, &
-                     getval_l2d,getval_l3d,getval_l4d
+     MODULE PROCEDURE getval_r2d
+     MODULE PROCEDURE getval_r3d
+     MODULE PROCEDURE getval_r4d
+     MODULE PROCEDURE getval_i2d
+     MODULE PROCEDURE getval_i3d
+     MODULE PROCEDURE getval_i4d
+     MODULE PROCEDURE getval_l2d
+     MODULE PROCEDURE getval_l3d
+     MODULE PROCEDURE getval_l4d
   END INTERFACE
-                   
+
   INTERFACE ASSIGNMENT(=)
-    MODULE PROCEDURE getval_r2d,getval_r3d,getval_r4d, &
-                     getval_i2d,getval_i3d,getval_i4d, &
-                     getval_l2d,getval_l3d,getval_l4d 
+     MODULE PROCEDURE getval_r2d
+     MODULE PROCEDURE getval_r3d
+     MODULE PROCEDURE getval_r4d
+     MODULE PROCEDURE getval_i2d
+     MODULE PROCEDURE getval_i3d
+     MODULE PROCEDURE getval_i4d
+     MODULE PROCEDURE getval_l2d
+     MODULE PROCEDURE getval_l3d
+     MODULE PROCEDURE getval_l4d
   END INTERFACE
 
-  PRIVATE :: allocate_field_
+  PRIVATE :: allocate_field_, deallocate_field_
 
 CONTAINS
 
-  SUBROUTINE allocate_field(field,field_type,data_type,dim1,dim2,name,ondevice)
-  USE domain_mod
-  USE omp_para
+  !====================================== allocate_field ===================================
+
+  SUBROUTINE allocate_field_glo(field,field_type,data_type,dim1,dim2,name)
+    USE domain_mod
     TYPE(t_field),POINTER :: field(:)
     INTEGER,INTENT(IN) :: field_type
@@ -59,182 +67,153 @@
     INTEGER,OPTIONAL :: dim1,dim2
     CHARACTER(*), OPTIONAL :: name
-    LOGICAL, INTENT(IN), OPTIONAL :: ondevice 
-!$OMP BARRIER
-!$OMP MASTER
-    ALLOCATE(field(ndomain))    
-!$OMP END MASTER
-!$OMP BARRIER
-
-    CALL allocate_field_(field,field_type,data_type,dim1,dim2,name,ondevice)
-    
-  END SUBROUTINE allocate_field
-
-  SUBROUTINE allocate_fields(nfield,field,field_type,data_type,dim1,dim2,name, ondevice)
-  USE domain_mod
-  USE omp_para
-    INTEGER,INTENT(IN) :: nfield
-    TYPE(t_field),POINTER :: field(:,:)
-    INTEGER,INTENT(IN) :: field_type
-    INTEGER,INTENT(IN) :: data_type
-    INTEGER,OPTIONAL :: dim1,dim2
+    INTEGER :: ind
+
+    ALLOCATE(field(ndomain_glo))
+    DO ind=1,ndomain_glo
+       CALL allocate_field_(domain_glo(ind), field(ind), field_type, data_type, dim1, dim2, name)
+    ENDDO
+
+  END SUBROUTINE allocate_field_glo
+
+  SUBROUTINE allocate_field(field, field_type, data_type, dim3, dim4, name, ondevice)
+    USE domain_mod
+    USE omp_para
+    TYPE(t_field), POINTER :: field(:)
+    INTEGER, INTENT(IN)    :: field_type
+    INTEGER, INTENT(IN)    :: data_type
+    INTEGER, OPTIONAL      :: dim3,dim4
     CHARACTER(*), OPTIONAL :: name
     LOGICAL, INTENT(IN), OPTIONAL :: ondevice
-    INTEGER :: i
-!$OMP BARRIER
-!$OMP MASTER
+    INTEGER :: ind
+    !$OMP BARRIER
+    !$OMP MASTER
+    ALLOCATE(field(ndomain))
+    !$OMP END MASTER
+    !$OMP BARRIER
+
+    DO ind=1,ndomain
+       IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
+       CALL allocate_field_(domain(ind), field(ind), field_type, data_type, dim3, dim4, name, ondevice)
+    END DO
+    !$OMP BARRIER
+
+  END SUBROUTINE allocate_field
+
+  SUBROUTINE allocate_fields(nfield,field,field_type,data_type,dim3,dim4,name, ondevice)
+    USE domain_mod
+    USE omp_para
+    INTEGER, INTENT(IN)     :: nfield
+    TYPE(t_field), POINTER  :: field(:,:)
+    INTEGER, INTENT(IN)     :: field_type
+    INTEGER, INTENT(IN)     :: data_type
+    INTEGER, OPTIONAL       :: dim3,dim4
+    CHARACTER(*), OPTIONAL  :: name
+    LOGICAL, INTENT(IN), OPTIONAL :: ondevice
+    INTEGER :: i, ind
+    !$OMP BARRIER
+    !$OMP MASTER
     ALLOCATE(field(ndomain,nfield))
-!$OMP END MASTER
-!$OMP BARRIER
-    DO i=1,nfield
-       CALL allocate_field_(field(:,i),field_type,data_type,dim1,dim2,name,ondevice)
+    !$OMP END MASTER
+    !$OMP BARRIER
+    DO ind=1,ndomain
+       IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
+       DO i=1,nfield
+          CALL allocate_field_(domain(ind), field(ind,i),field_type, data_type, dim3, dim4, name, ondevice)
+       END DO
     END DO
+    !$OMP BARRIER
+
   END SUBROUTINE allocate_fields
 
-  SUBROUTINE allocate_field_(field,field_type,data_type,dim3,dim4,name,ondevice)
-  USE domain_mod
-  USE omp_para
-  IMPLICIT NONE
-    TYPE(t_field) :: field(:)
-    INTEGER,INTENT(IN) :: field_type
-    INTEGER,INTENT(IN) :: data_type
-    INTEGER,OPTIONAL :: dim3,dim4
+  SUBROUTINE allocate_field_(dom, field, field_type, data_type, dim3, dim4, name, ondevice)
+    USE domain_mod
+    USE omp_para
+    TYPE(t_domain)         :: dom
+    TYPE(t_field)          :: field
+    INTEGER, INTENT(IN)    :: field_type
+    INTEGER, INTENT(IN)    :: data_type
+    INTEGER, OPTIONAL      :: dim3,dim4
     CHARACTER(*), OPTIONAL :: name
     LOGICAL, INTENT(IN), OPTIONAL :: ondevice
-    INTEGER :: ind
+
     INTEGER :: ij_size
 
-    DO ind=1,ndomain
-      IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
-
-      IF(PRESENT(name)) THEN
-         field(ind)%name = name
-      ELSE
-         field(ind)%name = '(undefined)'
-      END IF
-
-      IF (PRESENT(dim4)) THEN
-        field(ind)%ndim=4 
-        field(ind)%dim4=dim4 
-        field(ind)%dim3=dim3
-      ELSE IF (PRESENT(dim3)) THEN
-        field(ind)%ndim=3
-        field(ind)%dim3=dim3
-        field(ind)%dim4=1
-      ELSE
-        field(ind)%ndim=2
-        field(ind)%dim3=1
-        field(ind)%dim4=1
-      ENDIF
-    
-    
-      field(ind)%data_type=data_type
-      field(ind)%field_type=field_type
-
-      IF (field_type==field_T) THEN 
-         ij_size=domain(ind)%iim*domain(ind)%jjm
-      ELSE IF (field_type==field_U) THEN 
-         ij_size=3*domain(ind)%iim*domain(ind)%jjm
-      ELSE IF (field_type==field_Z) THEN 
-         ij_size=2*domain(ind)%iim*domain(ind)%jjm
-      ENDIF
-     
-      IF (data_type==type_integer) ALLOCATE(field(ind)%ival4d(ij_size, field(ind)%dim3, field(ind)%dim4))
-      IF (data_type==type_real)    ALLOCATE(field(ind)%rval4d(ij_size, field(ind)%dim3, field(ind)%dim4))
-      IF (data_type==type_logical) ALLOCATE(field(ind)%lval4d(ij_size, field(ind)%dim3, field(ind)%dim4))
-
-      IF (field(ind)%ndim==3) THEN
-         IF (data_type==type_integer) field(ind)%ival3d => field(ind)%ival4d(:,:,1)
-         IF (data_type==type_real)    field(ind)%rval3d => field(ind)%rval4d(:,:,1)
-         IF (data_type==type_logical) field(ind)%lval3d => field(ind)%lval4d(:,:,1)
-
-      ELSE IF (field(ind)%ndim==2) THEN
-         IF (data_type==type_integer) field(ind)%ival2d => field(ind)%ival4d(:,1,1)
-         IF (data_type==type_real)    field(ind)%rval2d => field(ind)%rval4d(:,1,1)
-         IF (data_type==type_logical) field(ind)%lval2d => field(ind)%lval4d(:,1,1)
-
-      ENDIF
-
-      field(ind)%ondevice = .FALSE.
-      IF (PRESENT(ondevice)) THEN
-         IF (ondevice) CALL create_device_field(field(ind))
-      END IF
-   
-   ENDDO
-!$OMP BARRIER
-   
- END SUBROUTINE allocate_field_
-
-  SUBROUTINE allocate_field_glo(field,field_type,data_type,dim1,dim2,name)
-  USE domain_mod
-  IMPLICIT NONE
+    IF(PRESENT(name)) THEN
+       field%name = name
+    ELSE
+       field%name = '(undefined)'
+    END IF
+
+    IF (PRESENT(dim4)) THEN
+       field%ndim=4
+       field%dim4=dim4
+       field%dim3=dim3
+    ELSE IF (PRESENT(dim3)) THEN
+       field%ndim=3
+       field%dim3=dim3
+       field%dim4=1
+    ELSE
+       field%ndim=2
+       field%dim3=1
+       field%dim4=1
+    ENDIF
+
+
+    field%data_type=data_type
+    field%field_type=field_type
+
+    IF (field_type==field_T) THEN
+       ij_size=dom%iim*dom%jjm
+    ELSE IF (field_type==field_U) THEN
+       ij_size=3*dom%iim*dom%jjm
+    ELSE IF (field_type==field_Z) THEN
+       ij_size=2*dom%iim*dom%jjm
+    ENDIF
+
+    IF (data_type==type_integer) ALLOCATE(field%ival4d(ij_size, field%dim3, field%dim4))
+    IF (data_type==type_real)    ALLOCATE(field%rval4d(ij_size, field%dim3, field%dim4))
+    IF (data_type==type_logical) ALLOCATE(field%lval4d(ij_size, field%dim3, field%dim4))
+
+    IF (field%ndim==3) THEN
+       IF (data_type==type_integer) field%ival3d => field%ival4d(:,:,1)
+       IF (data_type==type_real)    field%rval3d => field%rval4d(:,:,1)
+       IF (data_type==type_logical) field%lval3d => field%lval4d(:,:,1)
+
+    ELSE IF (field%ndim==2) THEN
+       IF (data_type==type_integer) field%ival2d => field%ival4d(:,1,1)
+       IF (data_type==type_real)    field%rval2d => field%rval4d(:,1,1)
+       IF (data_type==type_logical) field%lval2d => field%lval4d(:,1,1)
+
+    ENDIF
+
+    field%ondevice = .FALSE.
+    IF (PRESENT(ondevice)) THEN
+       IF (ondevice) CALL create_device_field(field)
+    END IF
+
+  END SUBROUTINE allocate_field_
+
+  !==================================== deallocate_field ===================================
+
+  SUBROUTINE deallocate_field_glo(field)
+    USE domain_mod
     TYPE(t_field),POINTER :: field(:)
-    INTEGER,INTENT(IN) :: field_type
-    INTEGER,INTENT(IN) :: data_type
-    INTEGER,OPTIONAL :: dim1,dim2
-    CHARACTER(*), OPTIONAL :: name
-    INTEGER :: ind
-    INTEGER :: ii_size,jj_size
-
-    ALLOCATE(field(ndomain_glo)) 
-
+    INTEGER :: ind
     DO ind=1,ndomain_glo
-  
-      IF (PRESENT(dim2)) THEN
-        field(ind)%ndim=4 
-        field(ind)%dim4=dim2 
-        field(ind)%dim3=dim1 
-      ELSE IF (PRESENT(dim1)) THEN
-        field(ind)%ndim=3
-        field(ind)%dim3=dim1 
-      ELSE
-        field(ind)%ndim=2
-      ENDIF
-    
-      IF(PRESENT(name)) THEN
-         field(ind)%name = name
-      ELSE
-         field(ind)%name = '(undefined)'
-      END IF
-    
-      field(ind)%data_type=data_type
-      field(ind)%field_type=field_type
-    
-      field(ind)%ondevice = .FALSE.
-
-      IF (field_type==field_T) THEN 
-        jj_size=domain_glo(ind)%jjm
-      ELSE IF (field_type==field_U) THEN 
-        jj_size=3*domain_glo(ind)%jjm
-      ELSE IF (field_type==field_Z) THEN 
-        jj_size=2*domain_glo(ind)%jjm
-      ENDIF
-      
-      ii_size=domain_glo(ind)%iim
-        
-      IF (field(ind)%ndim==4) THEN
-        IF (data_type==type_integer) ALLOCATE(field(ind)%ival4d(ii_size*jj_size,dim1,dim2))
-        IF (data_type==type_real)    ALLOCATE(field(ind)%rval4d(ii_size*jj_size,dim1,dim2))
-        IF (data_type==type_logical) ALLOCATE(field(ind)%lval4d(ii_size*jj_size,dim1,dim2))
-      ELSE IF (field(ind)%ndim==3) THEN
-        IF (data_type==type_integer) ALLOCATE(field(ind)%ival3d(ii_size*jj_size,dim1))
-        IF (data_type==type_real)    ALLOCATE(field(ind)%rval3d(ii_size*jj_size,dim1))
-        IF (data_type==type_logical) ALLOCATE(field(ind)%lval3d(ii_size*jj_size,dim1))
-      ELSE IF (field(ind)%ndim==2) THEN
-        IF (data_type==type_integer) ALLOCATE(field(ind)%ival2d(ii_size*jj_size))
-        IF (data_type==type_real)    ALLOCATE(field(ind)%rval2d(ii_size*jj_size))
-        IF (data_type==type_logical) ALLOCATE(field(ind)%lval2d(ii_size*jj_size))
-      ENDIF
-      
-   ENDDO
-  
-  END SUBROUTINE allocate_field_glo
+       CALL deallocate_field_(field(ind))
+    END DO
+    DEALLOCATE(field)
+  END SUBROUTINE deallocate_field_glo
 
   SUBROUTINE deallocate_field(field)
     USE domain_mod
     USE omp_para
-    IMPLICIT NONE
     TYPE(t_field),POINTER :: field(:)
-    !$OMP BARRIER
-    CALL deallocate_field_(field)
+    INTEGER :: ind
+    !$OMP BARRIER
+    DO ind=1,ndomain
+       IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
+       CALL deallocate_field_(field(ind))
+    END DO
     !$OMP BARRIER
     !$OMP MASTER
@@ -243,14 +222,16 @@
     !$OMP BARRIER
   END SUBROUTINE deallocate_field
-  
+
   SUBROUTINE deallocate_fields(field)
     USE domain_mod
     USE omp_para
-    IMPLICIT NONE
     TYPE(t_field),POINTER :: field(:,:)
-    INTEGER :: i
-    !$OMP BARRIER
-    DO i=1,SIZE(field,2)
-       CALL deallocate_field_(field(:,i))
+    INTEGER :: i, ind
+    !$OMP BARRIER
+    DO ind=1,ndomain
+       IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
+       DO i=1,SIZE(field,2)
+          CALL deallocate_field_(field(ind,i))
+       END DO
     END DO
     !$OMP BARRIER
@@ -262,362 +243,193 @@
 
   SUBROUTINE deallocate_field_(field)
-  USE domain_mod
-  USE omp_para
-  IMPLICIT NONE
+    USE domain_mod
+    USE omp_para
+    TYPE(t_field) :: field
+    INTEGER :: data_type
+    data_type=field%data_type
+    IF (data_type==type_real) THEN
+       IF (field%ondevice) THEN
+          !$acc exit data delete(field%rval4d(:,:,:))
+          CONTINUE
+       END IF
+       DEALLOCATE(field%rval4d)
+    END IF
+    IF (data_type==type_integer) THEN
+       IF (field%ondevice) THEN
+          !$acc exit data delete(field%ival4d(:,:,:))
+          CONTINUE
+       END IF
+       DEALLOCATE(field%ival4d)
+    END IF
+    IF (data_type==type_logical) THEN
+       IF (field%ondevice) THEN
+          !$acc exit data delete(field%lval4d(:,:,:))
+          CONTINUE
+       END IF
+       DEALLOCATE(field%lval4d)
+    END IF
+
+  END SUBROUTINE deallocate_field_
+
+  !====================================== getval ===================================
+
+  SUBROUTINE getval_r2d(field_pt,field)
+    REAL(rstd), POINTER, INTENT(INOUT) :: field_pt(:)
+    TYPE(t_field),INTENT(IN) :: field
+
+    IF (field%ndim/=2 .OR. field%data_type/=type_real) THEN
+       PRINT *, 'getval_r2d : bad pointer assignment with ' // TRIM(field%name)
+       STOP
+    END IF
+    field_pt=>field%rval2d
+  END SUBROUTINE getval_r2d
+
+  SUBROUTINE getval_r3d(field_pt,field)
+    REAL(rstd), POINTER, INTENT(INOUT) :: field_pt(:,:)
+    TYPE(t_field),INTENT(IN) :: field
+
+    IF (field%ndim/=3 .OR. field%data_type/=type_real) THEN
+       PRINT *, 'getval_r3d : bad pointer assignment with ' // TRIM(field%name)
+       STOP
+    END IF
+    field_pt=>field%rval3d
+  END SUBROUTINE getval_r3d
+
+  SUBROUTINE getval_r4d(field_pt,field)
+    REAL(rstd), POINTER, INTENT(INOUT) :: field_pt(:,:,:)
+    TYPE(t_field),INTENT(IN) :: field
+
+    IF (field%ndim/=4 .OR. field%data_type/=type_real) THEN
+       PRINT *, 'getval_r4d : bad pointer assignment with ' // TRIM(field%name)
+       STOP
+    END IF
+    field_pt=>field%rval4d
+  END SUBROUTINE getval_r4d
+
+  SUBROUTINE getval_i2d(field_pt,field)
+    INTEGER, POINTER, INTENT(INOUT) :: field_pt(:)
+    TYPE(t_field),INTENT(IN) :: field
+
+    IF (field%ndim/=2 .OR. field%data_type/=type_integer) THEN
+       PRINT *, 'getval_i2d : bad pointer assignment with ' // TRIM(field%name)
+       STOP
+    END IF
+    field_pt=>field%ival2d
+  END SUBROUTINE getval_i2d
+
+  SUBROUTINE getval_i3d(field_pt,field)
+    INTEGER, POINTER, INTENT(INOUT) :: field_pt(:,:)
+    TYPE(t_field),INTENT(IN) :: field
+
+    IF (field%ndim/=3 .OR. field%data_type/=type_integer) THEN
+       PRINT *, 'getval_i3d : bad pointer assignment with ' // TRIM(field%name)
+       STOP
+    END IF
+    field_pt=>field%ival3d
+  END SUBROUTINE getval_i3d
+
+  SUBROUTINE getval_i4d(field_pt,field)
+    INTEGER, POINTER, INTENT(INOUT) :: field_pt(:,:,:)
+    TYPE(t_field),INTENT(IN) :: field
+
+    IF (field%ndim/=4 .OR. field%data_type/=type_integer) THEN
+       PRINT *, 'getval_i4d : bad pointer assignment with ' // TRIM(field%name)
+       STOP
+    END IF
+    field_pt=>field%ival4d
+  END SUBROUTINE getval_i4d
+
+  SUBROUTINE getval_l2d(field_pt,field)
+    LOGICAL, POINTER, INTENT(INOUT) :: field_pt(:)
+    TYPE(t_field),INTENT(IN) :: field
+
+    IF (field%ndim/=2 .OR. field%data_type/=type_logical) THEN
+       PRINT *, 'getval_l2d : bad pointer assignment with ' // TRIM(field%name)
+       STOP
+    END IF
+    field_pt=>field%lval2d
+  END SUBROUTINE getval_l2d
+
+  SUBROUTINE getval_l3d(field_pt,field)
+    LOGICAL, POINTER, INTENT(INOUT) :: field_pt(:,:)
+    TYPE(t_field),INTENT(IN) :: field
+
+    IF (field%ndim/=3 .OR. field%data_type/=type_logical) THEN
+       PRINT *, 'getval_l3d : bad pointer assignment with ' // TRIM(field%name)
+       STOP
+    END IF
+    field_pt=>field%lval3d
+  END SUBROUTINE getval_l3d
+
+  SUBROUTINE getval_l4d(field_pt,field)
+    LOGICAL, POINTER, INTENT(INOUT) :: field_pt(:,:,:)
+    TYPE(t_field),INTENT(IN) :: field
+
+    IF (field%ndim/=4 .OR. field%data_type/=type_logical) THEN
+       PRINT *, 'getval_l4d : bad pointer assignment with ' // TRIM(field%name)
+       STOP
+    END IF
+    field_pt=>field%lval4d
+  END SUBROUTINE getval_l4d
+
+  !===================== Data transfer between host (CPU) and device (GPU) =========================
+
+  SUBROUTINE update_device_field(field)
+    USE domain_mod
+    USE omp_para
     TYPE(t_field) :: field(:)
-    INTEGER :: data_type
-    INTEGER :: ind
-    DO ind=1,ndomain
-       IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
-
-       data_type=field(ind)%data_type
-
-       IF (data_type==type_integer) THEN
-          IF (field(ind)%ondevice) THEN
-             !$acc exit data delete(field(ind)%ival4d(:,:,:))
+    INTEGER :: ind
+
+    DO ind=1,ndomain
+       IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
+
+       IF (.NOT. field(ind)%ondevice) CALL create_device_field(field(ind))
+       IF (field(ind)%data_type==type_real) THEN
+          !$acc update device(field(ind)%rval4d(:,:,:)) async
+          CONTINUE
+       END IF
+       IF (field(ind)%data_type==type_integer) THEN
+          !$acc update device(field(ind)%ival4d(:,:,:)) async
+          CONTINUE
+       END IF
+       IF (field(ind)%data_type==type_logical) THEN
+          !$acc update device(field(ind)%lval4d(:,:,:)) async
+          CONTINUE
+       END IF
+
+    ENDDO
+    !$OMP BARRIER
+  END SUBROUTINE update_device_field
+
+  SUBROUTINE update_host_field(field)
+    USE domain_mod
+    USE omp_para
+    TYPE(t_field) :: field(:)
+    INTEGER :: ind
+
+    DO ind=1,ndomain
+       IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
+
+       IF (field(ind)%ondevice) THEN
+          IF (field(ind)%data_type==type_real) THEN
+             !$acc update host(field(ind)%rval4d(:,:,:)) async
              CONTINUE
           END IF
-          DEALLOCATE(field(ind)%ival4d)
-       END IF
-
-       IF (data_type==type_real) THEN
-          IF (field(ind)%ondevice) THEN
-             !$acc exit data delete(field(ind)%rval4d(:,:,:))
+          IF (field(ind)%data_type==type_integer) THEN
+             !$acc update host(field(ind)%ival4d(:,:,:)) async
              CONTINUE
           END IF
-          DEALLOCATE(field(ind)%rval4d)
-       END IF
-
-       IF (data_type==type_logical) THEN
-          IF (field(ind)%ondevice) THEN
-             !$acc exit data delete(field(ind)%lval4d(:,:,:))
+          IF (field(ind)%data_type==type_logical) THEN
+             !$acc update host(field(ind)%lval4d(:,:,:)) async
              CONTINUE
           END IF
-          DEALLOCATE(field(ind)%lval4d)
-       END IF
-    END DO
-
-  END SUBROUTINE deallocate_field_
-
-  SUBROUTINE deallocate_field_glo(field)
-  USE domain_mod
-  IMPLICIT NONE
-    TYPE(t_field),POINTER :: field(:)
-    INTEGER :: data_type
-    INTEGER :: ind
-
-    DO ind=1,ndomain_glo
-
-      data_type=field(ind)%data_type
-        
-      IF (field(ind)%ndim==4) THEN
-        IF (data_type==type_integer) DEALLOCATE(field(ind)%ival4d)
-        IF (data_type==type_real)    DEALLOCATE(field(ind)%rval4d)
-        IF (data_type==type_logical) DEALLOCATE(field(ind)%lval4d)
-      ELSE IF (field(ind)%ndim==3) THEN
-        IF (data_type==type_integer) DEALLOCATE(field(ind)%ival3d)
-        IF (data_type==type_real)    DEALLOCATE(field(ind)%rval3d)
-        IF (data_type==type_logical) DEALLOCATE(field(ind)%lval3d)
-      ELSE IF (field(ind)%ndim==2) THEN
-        IF (data_type==type_integer) DEALLOCATE(field(ind)%ival2d)
-        IF (data_type==type_real)    DEALLOCATE(field(ind)%rval2d)
-        IF (data_type==type_logical) DEALLOCATE(field(ind)%lval2d)
-      ENDIF
-      
-   ENDDO
-   DEALLOCATE(field)
-       
-  END SUBROUTINE deallocate_field_glo
-    
-  SUBROUTINE extract_slice(field_in, field_out, l)  
-  USE domain_mod
-  USE omp_para
-  IMPLICIT NONE  
-    TYPE(t_field) :: field_in(:)
-    TYPE(t_field) :: field_out(:)
-    INTEGER,INTENT(IN) :: l
-    
-    INTEGER :: ind
-    INTEGER :: data_type
-
-!$OMP BARRIER
-    DO ind=1,ndomain
-      data_type=field_in(ind)%data_type
-      IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
-      
-      IF (field_in(ind)%ndim==3 .AND. field_out(ind)%ndim==2) THEN  
-        IF (data_type==type_integer)  field_out(ind)%ival2d=field_in(ind)%ival3d(:,l)
-        IF (data_type==type_real)     field_out(ind)%rval2d=field_in(ind)%rval3d(:,l)
-        IF (data_type==type_logical)  field_out(ind)%lval2d=field_in(ind)%lval3d(:,l)
-      ELSE IF  (field_in(ind)%ndim==4 .AND. field_out(ind)%ndim==3) THEN
-        IF (data_type==type_integer)  field_out(ind)%ival3d=field_in(ind)%ival4d(:,:,l)
-        IF (data_type==type_real)     field_out(ind)%rval3d=field_in(ind)%rval4d(:,:,l)
-        IF (data_type==type_logical)  field_out(ind)%lval3d=field_in(ind)%lval4d(:,:,l)
-      ELSE
-        PRINT *, 'extract_slice : cannot extract slice, dimension incompatible'
-        STOP       
-      ENDIF
-   ENDDO 
-!$OMP BARRIER    
-  END  SUBROUTINE extract_slice  
-  
-  
-  SUBROUTINE insert_slice(field_in, field_out, l)  
-  USE domain_mod
-  USE omp_para
-  IMPLICIT NONE  
-    TYPE(t_field) :: field_in(:)
-    TYPE(t_field) :: field_out(:)
-    INTEGER,INTENT(IN) :: l
-    
-    INTEGER :: ind
-    INTEGER :: data_type
-
-!$OMP BARRIER
-    DO ind=1,ndomain
-      data_type=field_in(ind)%data_type
-      IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
-      
-      IF (field_in(ind)%ndim==2 .AND. field_out(ind)%ndim==3) THEN  
-        IF (data_type==type_integer)  field_out(ind)%ival3d(:,l)=field_in(ind)%ival2d(:)
-        IF (data_type==type_real)     field_out(ind)%rval3d(:,l)=field_in(ind)%rval2d(:)
-        IF (data_type==type_logical)  field_out(ind)%lval3d(:,l)=field_in(ind)%lval2d(:)
-      ELSE IF  (field_in(ind)%ndim==4 .AND. field_out(ind)%ndim==3) THEN
-        IF (data_type==type_integer)  field_out(ind)%ival4d(:,:,l)=field_out(ind)%ival3d(:,:)
-        IF (data_type==type_real)     field_out(ind)%rval4d(:,:,l)=field_out(ind)%rval3d(:,:)
-        IF (data_type==type_logical)  field_out(ind)%lval4d(:,:,l)=field_out(ind)%lval3d(:,:)
-      ELSE
-        PRINT *, 'extract_slice : cannot insert slice, dimension incompatible'
-        STOP       
-      ENDIF
-   ENDDO 
-!$OMP BARRIER    
-  
-  END SUBROUTINE insert_slice
-    
-  SUBROUTINE getval_r2d(field_pt,field)
-  IMPLICIT NONE  
-    REAL(rstd),POINTER,INTENT(INOUT) :: field_pt(:)
-    TYPE(t_field),INTENT(IN) :: field
-    
-    IF (field%ndim/=2 .OR. field%data_type/=type_real) THEN
-       PRINT *, 'get_val_r2d : bad pointer assignment with ' // TRIM(field%name) 
-       STOP
-    END IF
-    field_pt=>field%rval2d
-  END SUBROUTINE  getval_r2d
-
-  SUBROUTINE getval_r3d(field_pt,field)
-  IMPLICIT NONE  
-    REAL(rstd),POINTER,INTENT(INOUT) :: field_pt(:,:)
-    TYPE(t_field),INTENT(IN) :: field
-    
-    IF (field%ndim/=3 .OR. field%data_type/=type_real) THEN
-       PRINT *, 'get_val_r3d : bad pointer assignment with ' // TRIM(field%name) 
-       STOP
-!       CALL ABORT
-    END IF
-    field_pt=>field%rval3d
-  END SUBROUTINE  getval_r3d
-
-  SUBROUTINE getval_r4d(field_pt,field)
-  IMPLICIT NONE  
-    REAL(rstd),POINTER,INTENT(INOUT) :: field_pt(:,:,:)
-    TYPE(t_field),INTENT(IN) :: field
-    
-    IF (field%ndim/=4 .OR. field%data_type/=type_real) THEN
-       PRINT *, 'get_val_r4d : bad pointer assignment with ' // TRIM(field%name)
-       STOP
-    END IF
-    field_pt=>field%rval4d
-  END SUBROUTINE  getval_r4d  
-
-  
-  SUBROUTINE getval_i2d(field_pt,field)
-  IMPLICIT NONE  
-    INTEGER,POINTER,INTENT(INOUT) :: field_pt(:)
-    TYPE(t_field),INTENT(IN) :: field
-    
-    IF (field%ndim/=2 .OR. field%data_type/=type_integer) STOP 'get_val_i2d : bad pointer assignment'        
-    field_pt=>field%ival2d
-  END SUBROUTINE  getval_i2d
-
-  SUBROUTINE getval_i3d(field_pt,field)
-  IMPLICIT NONE  
-    INTEGER,POINTER,INTENT(INOUT) :: field_pt(:,:)
-    TYPE(t_field),INTENT(IN) :: field
-    
-    IF (field%ndim/=3 .OR. field%data_type/=type_integer) STOP 'get_val_i3d : bad pointer assignment'        
-    field_pt=>field%ival3d
-  END SUBROUTINE  getval_i3d
-
-  SUBROUTINE getval_i4d(field_pt,field)
-  IMPLICIT NONE  
-    INTEGER,POINTER,INTENT(INOUT) :: field_pt(:,:,:)
-    TYPE(t_field),INTENT(IN) :: field
-    
-    IF (field%ndim/=4 .OR. field%data_type/=type_integer) STOP 'get_val_i4d : bad pointer assignment'        
-    field_pt=>field%ival4d
-  END SUBROUTINE  getval_i4d
-
-  SUBROUTINE getval_l2d(field_pt,field)
-  IMPLICIT NONE  
-    LOGICAL,POINTER,INTENT(INOUT) :: field_pt(:)
-    TYPE(t_field),INTENT(IN) :: field
-    
-    IF (field%ndim/=2 .OR. field%data_type/=type_logical) STOP 'get_val_l2d : bad pointer assignment'        
-    field_pt=>field%lval2d
-  END SUBROUTINE  getval_l2d
-
-  SUBROUTINE getval_l3d(field_pt,field)
-  IMPLICIT NONE  
-    LOGICAL,POINTER,INTENT(INOUT) :: field_pt(:,:)
-    TYPE(t_field),INTENT(IN) :: field
-    
-    IF (field%ndim/=3 .OR. field%data_type/=type_logical) STOP 'get_val_l3d : bad pointer assignment'        
-    field_pt=>field%lval3d
-  END SUBROUTINE  getval_l3d
-
-  SUBROUTINE getval_l4d(field_pt,field)
-  IMPLICIT NONE  
-    LOGICAL,POINTER,INTENT(INOUT) :: field_pt(:,:,:)
-    TYPE(t_field),INTENT(IN) :: field
-    
-    IF (field%ndim/=4 .OR. field%data_type/=type_logical) STOP 'get_val_l4d : bad pointer assignment'        
-    field_pt=>field%lval4d
-  END SUBROUTINE  getval_l4d    
-
-
-  SUBROUTINE update_device_field(field)
-  USE domain_mod
-  USE omp_para
-  IMPLICIT NONE
-    TYPE(t_field) :: field(:)
-    INTEGER :: ind
-
-    DO ind=1,ndomain
-      IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
-
-      IF (.NOT. field(ind)%ondevice) CALL create_device_field(field(ind))
-
-      IF (field(ind)%ndim==4) THEN
-         IF (field(ind)%data_type==type_integer) THEN
-            !$acc update device(field(ind)%ival4d(:,:,:)) async
-            CONTINUE
-         END IF
-
-         IF (field(ind)%data_type==type_real) THEN
-            !$acc update device(field(ind)%rval4d(:,:,:)) async
-            CONTINUE
-         END IF
-
-         IF (field(ind)%data_type==type_logical) THEN
-            !$acc update device(field(ind)%lval4d(:,:,:)) async
-            CONTINUE
-         END IF
-
-      ELSE IF (field(ind)%ndim==3) THEN
-         IF (field(ind)%data_type==type_integer) THEN
-            !$acc update device(field(ind)%ival3d(:,:)) async
-            CONTINUE
-         END IF
-
-         IF (field(ind)%data_type==type_real) THEN
-            !$acc update device(field(ind)%rval3d(:,:)) async
-            CONTINUE
-         END IF
-
-         IF (field(ind)%data_type==type_logical) THEN
-            !$acc update device(field(ind)%lval3d(:,:)) async
-            CONTINUE
-         END IF
-
-      ELSE IF (field(ind)%ndim==2) THEN
-         IF (field(ind)%data_type==type_integer) THEN
-            !$acc update device(field(ind)%ival2d(:)) async
-            CONTINUE
-         END IF
-
-         IF (field(ind)%data_type==type_real) THEN
-            !$acc update device(field(ind)%rval2d(:)) async
-            CONTINUE
-         END IF
-
-         IF (field(ind)%data_type==type_logical) THEN
-            !$acc update device(field(ind)%lval2d(:)) async
-            CONTINUE
-         END IF
-      ENDIF
-   ENDDO
-   !$OMP BARRIER
- END SUBROUTINE update_device_field
- 
-  SUBROUTINE update_host_field(field)
-  USE domain_mod
-  USE omp_para
-  IMPLICIT NONE
-    TYPE(t_field) :: field(:)
-    INTEGER :: ind
-
-    DO ind=1,ndomain
-      IF (.NOT. assigned_domain(ind)  .OR. .NOT. is_omp_level_master) CYCLE
-
-      IF (field(ind)%ondevice) THEN
-
-         IF (field(ind)%ndim==4) THEN
-            IF (field(ind)%data_type==type_integer) THEN
-               !$acc update host(field(ind)%ival4d(:,:,:)) async
-               CONTINUE
-            END IF
-
-            IF (field(ind)%data_type==type_real) THEN
-               !$acc update host(field(ind)%rval4d(:,:,:)) async
-               CONTINUE
-            END IF
-
-            IF (field(ind)%data_type==type_logical) THEN
-               !$acc update host(field(ind)%lval4d(:,:,:)) async
-               CONTINUE
-            END IF
-
-         ELSE IF (field(ind)%ndim==3) THEN
-            IF (field(ind)%data_type==type_integer) THEN
-               !$acc update host(field(ind)%ival3d(:,:)) async
-               CONTINUE
-            END IF
-
-            IF (field(ind)%data_type==type_real) THEN
-               !$acc update host(field(ind)%rval3d(:,:)) async
-               CONTINUE
-            END IF
-
-            IF (field(ind)%data_type==type_logical) THEN
-               !$acc update host(field(ind)%lval3d(:,:)) async
-               CONTINUE
-            END IF
-
-         ELSE IF (field(ind)%ndim==2) THEN
-            IF (field(ind)%data_type==type_integer) THEN
-               !$acc update host(field(ind)%ival2d(:)) async
-               CONTINUE
-            END IF
-
-            IF (field(ind)%data_type==type_real) THEN
-               !$acc update host(field(ind)%rval2d(:)) async
-               CONTINUE
-            END IF
-
-            IF (field(ind)%data_type==type_logical) THEN
-               !$acc update host(field(ind)%lval2d(:)) async
-               CONTINUE
-            END IF
-         ENDIF
-      END IF
-   ENDDO
-   !$acc wait
-   !$OMP BARRIER
- END SUBROUTINE update_host_field
-
- SUBROUTINE create_device_field(field)
+
+       END IF
+    ENDDO
+    !$acc wait
+    !$OMP BARRIER
+  END SUBROUTINE update_host_field
+
+  SUBROUTINE create_device_field(field)
     TYPE(t_field) :: field
 
@@ -626,45 +438,16 @@
        STOP 1
     END IF
-    IF (field%ndim==4) THEN
-       IF (field%data_type==type_integer) THEN
-          !$acc enter data create(field%ival4d(:,:,:)) async
-       END IF
-
-       IF (field%data_type==type_real) THEN
-          !$acc enter data create(field%rval4d(:,:,:)) async
-       END IF
-
-       IF (field%data_type==type_logical) THEN
-          !$acc enter data create(field%lval4d(:,:,:)) async
-       END IF
-
-    ELSE IF (field%ndim==3) THEN
-       IF (field%data_type==type_integer) THEN
-          !$acc enter data create(field%ival3d(:,:)) async
-       END IF
-
-       IF (field%data_type==type_real) THEN
-          !$acc enter data create(field%rval3d(:,:)) async
-       END IF
-
-       IF (field%data_type==type_logical) THEN
-          !$acc enter data create(field%lval3d(:,:)) async
-       END IF
-
-    ELSE IF (field%ndim==2) THEN
-       IF (field%data_type==type_integer) THEN
-          !$acc enter data create(field%ival2d(:)) async
-       END IF
-
-       IF (field%data_type==type_real) THEN
-          !$acc enter data create(field%rval2d(:)) async
-       END IF
-
-       IF (field%data_type==type_logical) THEN
-          !$acc enter data create(field%lval2d(:)) async
-       END IF
-    ENDIF
+    IF (field%data_type==type_real) THEN
+       !$acc enter data create(field%rval4d(:,:,:)) async
+    END IF
+    IF (field%data_type==type_integer) THEN
+       !$acc enter data create(field%ival4d(:,:,:)) async
+    END IF
+    IF (field%data_type==type_logical) THEN
+       !$acc enter data create(field%lval4d(:,:,:)) async
+    END IF
+
     field%ondevice = .TRUE.
   END SUBROUTINE create_device_field
- 
-END MODULE field_mod   
+
+END MODULE field_mod
Index: /codes/icosagcm/trunk/src/parallel/openacc_mod.F90
===================================================================
--- /codes/icosagcm/trunk/src/parallel/openacc_mod.F90	(revision 1054)
+++ /codes/icosagcm/trunk/src/parallel/openacc_mod.F90	(revision 1055)
@@ -31,5 +31,5 @@
     ELSE IF (slurm_local_id_ierr == 0) then
        READ(slurm_local_id_value,*) local_id
-       PRINT *, "setDevice : found env variable SLURM_LOCAL_ID =", local_id 
+       PRINT *, "setDevice : found env variable SLURM_LOCALID =", local_id 
     ELSE
      RETURN
Index: /codes/icosagcm/trunk/src/parallel/transfert_mpi_collectives.f90
===================================================================
--- /codes/icosagcm/trunk/src/parallel/transfert_mpi_collectives.f90	(revision 1054)
+++ /codes/icosagcm/trunk/src/parallel/transfert_mpi_collectives.f90	(revision 1055)
@@ -1,10 +1,10 @@
 MODULE transfert_mpi_collectives_mod
-IMPLICIT NONE
+  IMPLICIT NONE
 
   INTERFACE bcast_mpi
-    MODULE PROCEDURE bcast_mpi_c,                                                     &
-                     bcast_mpi_i,bcast_mpi_i1,bcast_mpi_i2,bcast_mpi_i3,bcast_mpi_i4, &
-                     bcast_mpi_r,bcast_mpi_r1,bcast_mpi_r2,bcast_mpi_r3,bcast_mpi_r4, &
-		     bcast_mpi_l,bcast_mpi_l1,bcast_mpi_l2,bcast_mpi_l3,bcast_mpi_l4
+     MODULE PROCEDURE bcast_mpi_c
+     MODULE PROCEDURE bcast_mpi_i, bcast_mpi_i1, bcast_mpi_i2, bcast_mpi_i3, bcast_mpi_i4
+     MODULE PROCEDURE bcast_mpi_r, bcast_mpi_r1, bcast_mpi_r2, bcast_mpi_r3, bcast_mpi_r4
+     MODULE PROCEDURE bcast_mpi_l, bcast_mpi_l1, bcast_mpi_l2, bcast_mpi_l3, bcast_mpi_l4
   END INTERFACE
 
@@ -12,9 +12,8 @@
 
   SUBROUTINE gather_field(field_loc,field_glo)
-  USE field_mod
-  USE domain_mod
-  USE mpi_mod
-  USE mpipara
-  IMPLICIT NONE
+    USE field_mod
+    USE domain_mod
+    USE mpi_mod
+    USE mpipara
     TYPE(t_field),POINTER :: field_loc(:)
     TYPE(t_field),POINTER :: field_glo(:)
@@ -25,57 +24,30 @@
 
     IF (.NOT. using_mpi) THEN
-
-      DO ind_loc=1,ndomain
-        IF (field_loc(ind_loc)%ndim==2) field_glo(ind_loc)%rval2d=field_loc(ind_loc)%rval2d
-        IF (field_loc(ind_loc)%ndim==3) field_glo(ind_loc)%rval3d=field_loc(ind_loc)%rval3d
-        IF (field_loc(ind_loc)%ndim==4) field_glo(ind_loc)%rval4d=field_loc(ind_loc)%rval4d
-      ENDDO
+       DO ind_loc=1,ndomain
+          field_glo(ind_loc)%rval4d=field_loc(ind_loc)%rval4d
+       ENDDO
 
     ELSE
-
-      nreq=ndomain
-      IF (mpi_rank==0) nreq=nreq+ndomain_glo
-      ALLOCATE(mpi_req(nreq))
-      ALLOCATE(status(MPI_STATUS_SIZE,nreq))
-
-
-      ireq=0
-      IF (mpi_rank==0) THEN
-        DO ind_glo=1,ndomain_glo
+       nreq=ndomain
+       IF (mpi_rank==0) nreq=nreq+ndomain_glo
+       ALLOCATE(mpi_req(nreq))
+       ALLOCATE(status(MPI_STATUS_SIZE,nreq))
+
+       ireq=0
+       IF (mpi_rank==0) THEN
+          DO ind_glo=1,ndomain_glo
+             ireq=ireq+1
+             CALL MPI_IRECV(field_glo(ind_glo)%rval4d,size(field_glo(ind_glo)%rval4d) , MPI_REAL8 ,   &
+                  domglo_rank(ind_glo),domglo_loc_ind(ind_glo), comm_icosa, mpi_req(ireq), ierr)
+          ENDDO
+       ENDIF
+
+       DO ind_loc=1,ndomain
           ireq=ireq+1
-
-          IF (field_glo(ind_glo)%ndim==2) THEN
-            CALL MPI_IRECV(field_glo(ind_glo)%rval2d,size(field_glo(ind_glo)%rval2d) , MPI_REAL8 ,   &
-                         domglo_rank(ind_glo),domglo_loc_ind(ind_glo), comm_icosa, mpi_req(ireq), ierr)
-
-          ELSE IF (field_glo(ind_glo)%ndim==3) THEN
-            CALL MPI_IRECV(field_glo(ind_glo)%rval3d,size(field_glo(ind_glo)%rval3d) , MPI_REAL8 ,   &
-                         domglo_rank(ind_glo),domglo_loc_ind(ind_glo), comm_icosa, mpi_req(ireq), ierr)
-
-          ELSE IF (field_glo(ind_glo)%ndim==4) THEN
-            CALL MPI_IRECV(field_glo(ind_glo)%rval4d,size(field_glo(ind_glo)%rval4d) , MPI_REAL8 ,   &
-                         domglo_rank(ind_glo),domglo_loc_ind(ind_glo), comm_icosa, mpi_req(ireq), ierr)
-          ENDIF
-
-        ENDDO
-      ENDIF
-
-      DO ind_loc=1,ndomain
-        ireq=ireq+1
-
-        IF (field_loc(ind_loc)%ndim==2) THEN
-          CALL MPI_ISEND(field_loc(ind_loc)%rval2d,size(field_loc(ind_loc)%rval2d) , MPI_REAL8 ,   &
-                         0, ind_loc, comm_icosa, mpi_req(ireq), ierr)
-        ELSE IF (field_loc(ind_loc)%ndim==3) THEN
-          CALL MPI_ISEND(field_loc(ind_loc)%rval3d,size(field_loc(ind_loc)%rval3d) , MPI_REAL8 ,   &
-                         0, ind_loc, comm_icosa, mpi_req(ireq), ierr)
-        ELSE IF (field_loc(ind_loc)%ndim==4) THEN
           CALL MPI_ISEND(field_loc(ind_loc)%rval4d,size(field_loc(ind_loc)%rval4d) , MPI_REAL8 ,   &
-                         0, ind_loc, comm_icosa, mpi_req(ireq), ierr)
-        ENDIF
-
-      ENDDO
-
-      CALL MPI_WAITALL(nreq,mpi_req,status,ierr)
+               0, ind_loc, comm_icosa, mpi_req(ireq), ierr)
+       ENDDO
+
+       CALL MPI_WAITALL(nreq,mpi_req,status,ierr)
 
     ENDIF
@@ -84,39 +56,24 @@
 
   SUBROUTINE bcast_field(field_glo)
-  USE field_mod
-  USE domain_mod
-  USE mpi_mod
-  USE mpipara
-  IMPLICIT NONE
+    USE field_mod
+    USE domain_mod
+    USE mpi_mod
+    USE mpipara
     TYPE(t_field),POINTER :: field_glo(:)
     INTEGER :: ind_glo
 
-    IF (.NOT. using_mpi) THEN
-
-! nothing to do
-
-    ELSE
-
-      DO ind_glo=1,ndomain_glo
-
-          IF (field_glo(ind_glo)%ndim==2) THEN
-            CALL MPI_BCAST(field_glo(ind_glo)%rval2d, size(field_glo(ind_glo)%rval2d) , MPI_REAL8, 0, comm_icosa, ierr)
-          ELSE IF (field_glo(ind_glo)%ndim==3) THEN
-            CALL MPI_BCAST(field_glo(ind_glo)%rval3d, size(field_glo(ind_glo)%rval3d) , MPI_REAL8, 0, comm_icosa, ierr)
-          ELSE IF (field_glo(ind_glo)%ndim==4) THEN
-            CALL MPI_BCAST(field_glo(ind_glo)%rval4d, size(field_glo(ind_glo)%rval4d) , MPI_REAL8, 0, comm_icosa, ierr)
-          ENDIF
-
-        ENDDO
-      ENDIF
+    IF (using_mpi) THEN
+       DO ind_glo=1,ndomain_glo
+          CALL MPI_BCAST(field_glo(ind_glo)%rval4d, size(field_glo(ind_glo)%rval4d) , MPI_REAL8, 0, comm_icosa, ierr)
+       ENDDO
+    ENDIF
 
   END SUBROUTINE bcast_field
 
   SUBROUTINE scatter_field(field_glo,field_loc)
-  USE field_mod
-  USE domain_mod
-  USE mpi_mod
-  USE mpipara
-  IMPLICIT NONE
+    USE field_mod
+    USE domain_mod
+    USE mpi_mod
+    USE mpipara
     TYPE(t_field),POINTER :: field_glo(:)
     TYPE(t_field),POINTER :: field_loc(:)
@@ -127,57 +84,30 @@
 
     IF (.NOT. using_mpi) THEN
-
-      DO ind_loc=1,ndomain
-        IF (field_loc(ind_loc)%ndim==2) field_loc(ind_loc)%rval2d=field_glo(ind_loc)%rval2d
-        IF (field_loc(ind_loc)%ndim==3) field_loc(ind_loc)%rval3d=field_glo(ind_loc)%rval3d
-        IF (field_loc(ind_loc)%ndim==4) field_loc(ind_loc)%rval4d=field_glo(ind_loc)%rval4d
-      ENDDO
+       DO ind_loc=1,ndomain
+          field_loc(ind_loc)%rval4d=field_glo(ind_loc)%rval4d
+       ENDDO
 
     ELSE
-
-      nreq=ndomain
-      IF (mpi_rank==0) nreq=nreq+ndomain_glo
-      ALLOCATE(mpi_req(nreq))
-      ALLOCATE(status(MPI_STATUS_SIZE,nreq))
-
-
-      ireq=0
-      IF (mpi_rank==0) THEN
-        DO ind_glo=1,ndomain_glo
+       nreq=ndomain
+       IF (mpi_rank==0) nreq=nreq+ndomain_glo
+       ALLOCATE(mpi_req(nreq))
+       ALLOCATE(status(MPI_STATUS_SIZE,nreq))
+
+       ireq=0
+       IF (mpi_rank==0) THEN
+          DO ind_glo=1,ndomain_glo
+             ireq=ireq+1
+             CALL MPI_ISEND(field_glo(ind_glo)%rval4d,size(field_glo(ind_glo)%rval4d) , MPI_REAL8 ,   &
+                  domglo_rank(ind_glo),domglo_loc_ind(ind_glo), comm_icosa, mpi_req(ireq), ierr)
+          ENDDO
+       ENDIF
+
+       DO ind_loc=1,ndomain
           ireq=ireq+1
-
-          IF (field_glo(ind_glo)%ndim==2) THEN
-            CALL MPI_ISEND(field_glo(ind_glo)%rval2d,size(field_glo(ind_glo)%rval2d) , MPI_REAL8 ,   &
-                         domglo_rank(ind_glo),domglo_loc_ind(ind_glo), comm_icosa, mpi_req(ireq), ierr)
-
-          ELSE IF (field_glo(ind_glo)%ndim==3) THEN
-            CALL MPI_ISEND(field_glo(ind_glo)%rval3d,size(field_glo(ind_glo)%rval3d) , MPI_REAL8 ,   &
-                         domglo_rank(ind_glo),domglo_loc_ind(ind_glo), comm_icosa, mpi_req(ireq), ierr)
-
-          ELSE IF (field_glo(ind_glo)%ndim==4) THEN
-            CALL MPI_ISEND(field_glo(ind_glo)%rval4d,size(field_glo(ind_glo)%rval4d) , MPI_REAL8 ,   &
-                         domglo_rank(ind_glo),domglo_loc_ind(ind_glo), comm_icosa, mpi_req(ireq), ierr)
-          ENDIF
-
-        ENDDO
-      ENDIF
-
-      DO ind_loc=1,ndomain
-        ireq=ireq+1
-
-        IF (field_loc(ind_loc)%ndim==2) THEN
-          CALL MPI_IRECV(field_loc(ind_loc)%rval2d,size(field_loc(ind_loc)%rval2d) , MPI_REAL8 ,   &
-                         0, ind_loc, comm_icosa, mpi_req(ireq), ierr)
-        ELSE IF (field_loc(ind_loc)%ndim==3) THEN
-          CALL MPI_IRECV(field_loc(ind_loc)%rval3d,size(field_loc(ind_loc)%rval3d) , MPI_REAL8 ,   &
-                         0, ind_loc, comm_icosa, mpi_req(ireq), ierr)
-        ELSE IF (field_loc(ind_loc)%ndim==4) THEN
           CALL MPI_IRECV(field_loc(ind_loc)%rval4d,size(field_loc(ind_loc)%rval4d) , MPI_REAL8 ,   &
-                         0, ind_loc, comm_icosa, mpi_req(ireq), ierr)
-        ENDIF
-
-      ENDDO
-
-      CALL MPI_WAITALL(nreq,mpi_req,status,ierr)
+               0, ind_loc, comm_icosa, mpi_req(ireq), ierr)
+       ENDDO
+
+       CALL MPI_WAITALL(nreq,mpi_req,status,ierr)
 
     ENDIF
@@ -185,228 +115,136 @@
   END SUBROUTINE scatter_field
 
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! Definition des Broadcast --> 4D   !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-!! -- Les chaine de charactï¿œre -- !!
-
-  SUBROUTINE bcast_mpi_c(var1)
-  IMPLICIT NONE
-    CHARACTER(LEN=*),INTENT(INOUT) :: Var1
-
-    CALL bcast_mpi_cgen(Var1,len(Var1))
-
-  END SUBROUTINE bcast_mpi_c
-
-!! -- Les entiers -- !!
-
-  SUBROUTINE bcast_mpi_i(var)
-  USE mpipara
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var
-
-    INTEGER               :: var_tmp(1)
-
-    IF (is_mpi_master) var_tmp(1)=var
-    CALL bcast_mpi_igen(Var_tmp,1)
-    var=var_tmp(1)
-
-  END SUBROUTINE bcast_mpi_i
-
-  SUBROUTINE bcast_mpi_i1(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:)
-
-    CALL bcast_mpi_igen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_i1
-
-  SUBROUTINE bcast_mpi_i2(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:,:)
-
-    CALL bcast_mpi_igen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_i2
-
-  SUBROUTINE bcast_mpi_i3(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:,:,:)
-
-    CALL bcast_mpi_igen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_i3
-
-  SUBROUTINE bcast_mpi_i4(var)
-  IMPLICIT NONE
-    INTEGER,INTENT(INOUT) :: Var(:,:,:,:)
-
-    CALL bcast_mpi_igen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_i4
-
-
-!! -- Les reels -- !!
-
-  SUBROUTINE bcast_mpi_r(var)
-  USE mpipara
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var
-    REAL               :: var_tmp(1)
-
-    IF (is_mpi_master) var_tmp(1)=var
-    CALL bcast_mpi_rgen(Var_tmp,1)
-    var=var_tmp(1)
-
-  END SUBROUTINE bcast_mpi_r
-
-  SUBROUTINE bcast_mpi_r1(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:)
-
-    CALL bcast_mpi_rgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_r1
-
-  SUBROUTINE bcast_mpi_r2(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:,:)
-
-    CALL bcast_mpi_rgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_r2
-
-  SUBROUTINE bcast_mpi_r3(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:,:,:)
-
-    CALL bcast_mpi_rgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_r3
-
-  SUBROUTINE bcast_mpi_r4(var)
-  IMPLICIT NONE
-    REAL,INTENT(INOUT) :: Var(:,:,:,:)
-
-    CALL bcast_mpi_rgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_r4
-
-!! -- Les booleans -- !!
-
-  SUBROUTINE bcast_mpi_l(var)
-  USE mpipara
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var
-    LOGICAL               :: var_tmp(1)
-
-    IF (is_mpi_master) var_tmp(1)=var
-    CALL bcast_mpi_lgen(Var_tmp,1)
-    var=var_tmp(1)
-
-  END SUBROUTINE bcast_mpi_l
-
-  SUBROUTINE bcast_mpi_l1(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:)
-
-    CALL bcast_mpi_lgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_l1
-
-  SUBROUTINE bcast_mpi_l2(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:,:)
-
-    CALL bcast_mpi_lgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_l2
-
-  SUBROUTINE bcast_mpi_l3(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:,:,:)
-
-    CALL bcast_mpi_lgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_l3
-
-  SUBROUTINE bcast_mpi_l4(var)
-  IMPLICIT NONE
-    LOGICAL,INTENT(INOUT) :: Var(:,:,:,:)
-
-    CALL bcast_mpi_lgen(Var,size(Var))
-
-  END SUBROUTINE bcast_mpi_l4
-
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! DEFINITION DES FONCTIONS DE TRANSFERT GENERIQUES !
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+  !===================  Broadcast routines for strings ==================!
 
   SUBROUTINE bcast_mpi_cgen(var,nb)
     USE mpi_mod
     USE mpipara
-    IMPLICIT NONE
-
     CHARACTER(LEN=*),INTENT(INOUT) :: Var
     INTEGER,INTENT(IN) :: nb
-
     IF (.NOT. using_mpi) RETURN
-
     CALL MPI_BCAST(Var,nb,MPI_CHARACTER,mpi_master,comm_icosa,ierr)
-
   END SUBROUTINE bcast_mpi_cgen
 
-
+  SUBROUTINE bcast_mpi_c(var1)
+    CHARACTER(LEN=*),INTENT(INOUT) :: Var1
+    CALL bcast_mpi_cgen(Var1,len(Var1))
+  END SUBROUTINE bcast_mpi_c
+
+  !============= Broadcast routines for INTEGER scalars and arrays ============!
 
   SUBROUTINE bcast_mpi_igen(var,nb)
     USE mpi_mod
     USE mpipara
-    IMPLICIT NONE
-    INTEGER,INTENT(IN) :: nb
-    INTEGER,DIMENSION(nb),INTENT(INOUT) :: Var
-
-    IF (.NOT. using_mpi) RETURN
-
-    CALL MPI_BCAST(Var,nb,MPI_INTEGER,mpi_master,comm_icosa,ierr)
-
+    INTEGER, INTENT(IN) :: nb
+    INTEGER, DIMENSION(nb), INTENT(INOUT) :: var
+    IF (using_mpi) CALL MPI_BCAST(Var, nb, MPI_INTEGER, mpi_master, comm_icosa, ierr)
   END SUBROUTINE bcast_mpi_igen
 
-
-
+  SUBROUTINE bcast_mpi_i(var)
+    USE mpipara
+    INTEGER, INTENT(INOUT) :: var
+    INTEGER                :: var_tmp(1)
+    IF (is_mpi_master) var_tmp(1)=var
+    CALL bcast_mpi_igen(var_tmp,1)
+    var=var_tmp(1)
+  END SUBROUTINE bcast_mpi_i
+
+  SUBROUTINE bcast_mpi_i1(var)
+    INTEGER, INTENT(INOUT) :: var(:)
+    CALL bcast_mpi_igen(var,size(var))
+  END SUBROUTINE bcast_mpi_i1
+
+  SUBROUTINE bcast_mpi_i2(var)
+    INTEGER, INTENT(INOUT) :: var(:,:)
+    CALL bcast_mpi_igen(var,size(var))
+  END SUBROUTINE bcast_mpi_i2
+
+  SUBROUTINE bcast_mpi_i3(var)
+    INTEGER, INTENT(INOUT) :: var(:,:,:)
+    CALL bcast_mpi_igen(var,size(var))
+  END SUBROUTINE bcast_mpi_i3
+
+  SUBROUTINE bcast_mpi_i4(var)
+    INTEGER, INTENT(INOUT) :: var(:,:,:,:)
+    CALL bcast_mpi_igen(var,size(var))
+  END SUBROUTINE bcast_mpi_i4
+
+  !============= Broadcast routines for REAL scalars and arrays ============!
 
   SUBROUTINE bcast_mpi_rgen(var,nb)
     USE mpi_mod
     USE mpipara
-    IMPLICIT NONE
-    INTEGER,INTENT(IN) :: nb
-    REAL,DIMENSION(nb),INTENT(INOUT) :: Var
-
-    IF (.NOT. using_mpi) RETURN
-
-    CALL MPI_BCAST(Var,nb,MPI_REAL8,mpi_master,comm_icosa,ierr)
-
+    INTEGER, INTENT(IN) :: nb
+    REAL, DIMENSION(nb), INTENT(INOUT) :: var
+    IF (using_mpi) CALL MPI_BCAST(Var, nb, MPI_REAL8, mpi_master, comm_icosa, ierr)
   END SUBROUTINE bcast_mpi_rgen
 
-
-
+  SUBROUTINE bcast_mpi_r(var)
+    USE mpipara
+    REAL, INTENT(INOUT) :: var
+    REAL                :: var_tmp(1)
+    IF (is_mpi_master) var_tmp(1)=var
+    CALL bcast_mpi_rgen(var_tmp,1)
+    var=var_tmp(1)
+  END SUBROUTINE bcast_mpi_r
+
+  SUBROUTINE bcast_mpi_r1(var)
+    REAL, INTENT(INOUT) :: var(:)
+    CALL bcast_mpi_rgen(var,size(var))
+  END SUBROUTINE bcast_mpi_r1
+
+  SUBROUTINE bcast_mpi_r2(var)
+    REAL, INTENT(INOUT) :: var(:,:)
+    CALL bcast_mpi_rgen(var,size(var))
+  END SUBROUTINE bcast_mpi_r2
+
+  SUBROUTINE bcast_mpi_r3(var)
+    REAL, INTENT(INOUT) :: var(:,:,:)
+    CALL bcast_mpi_rgen(var,size(var))
+  END SUBROUTINE bcast_mpi_r3
+
+  SUBROUTINE bcast_mpi_r4(var)
+    REAL, INTENT(INOUT) :: var(:,:,:,:)
+    CALL bcast_mpi_rgen(var,size(var))
+  END SUBROUTINE bcast_mpi_r4
+
+  !============= Broadcast routines for LOGICAL scalars and arrays ============!
 
   SUBROUTINE bcast_mpi_lgen(var,nb)
     USE mpi_mod
     USE mpipara
-    IMPLICIT NONE
-    INTEGER,INTENT(IN) :: nb
-    LOGICAL,DIMENSION(nb),INTENT(INOUT) :: Var
-
-    IF (.NOT. using_mpi) RETURN
-
-    CALL MPI_BCAST(Var,nb,MPI_LOGICAL,mpi_master,comm_icosa,ierr)
-
+    INTEGER, INTENT(IN) :: nb
+    LOGICAL, DIMENSION(nb), INTENT(INOUT) :: var
+    IF (using_mpi) CALL MPI_BCAST(Var, nb, MPI_LOGICAL, mpi_master, comm_icosa, ierr)
   END SUBROUTINE bcast_mpi_lgen
 
+  SUBROUTINE bcast_mpi_l(var)
+    USE mpipara
+    LOGICAL, INTENT(INOUT) :: var
+    LOGICAL                :: var_tmp(1)
+    IF (is_mpi_master) var_tmp(1)=var
+    CALL bcast_mpi_lgen(var_tmp,1)
+    var=var_tmp(1)
+  END SUBROUTINE bcast_mpi_l
+
+  SUBROUTINE bcast_mpi_l1(var)
+    LOGICAL, INTENT(INOUT) :: var(:)
+    CALL bcast_mpi_lgen(var,size(var))
+  END SUBROUTINE bcast_mpi_l1
+
+  SUBROUTINE bcast_mpi_l2(var)
+    LOGICAL, INTENT(INOUT) :: var(:,:)
+    CALL bcast_mpi_lgen(var,size(var))
+  END SUBROUTINE bcast_mpi_l2
+
+  SUBROUTINE bcast_mpi_l3(var)
+    LOGICAL, INTENT(INOUT) :: var(:,:,:)
+    CALL bcast_mpi_lgen(var,size(var))
+  END SUBROUTINE bcast_mpi_l3
+
+  SUBROUTINE bcast_mpi_l4(var)
+    LOGICAL, INTENT(INOUT) :: var(:,:,:,:)
+    CALL bcast_mpi_lgen(var,size(var))
+  END SUBROUTINE bcast_mpi_l4
 
 END MODULE transfert_mpi_collectives_mod
-
-
-
-
-
