MODULE layout_mod
  IMPLICIT NONE

  INTEGER,PARAMETER :: field_T=1
  INTEGER,PARAMETER :: field_U=2
  INTEGER,PARAMETER :: field_Z=3
  INTEGER,PARAMETER :: field_type_max=3

  INTEGER,PARAMETER :: order_ij_l_p=1  ! indexing 2D/3D/4D : X(ij) Y(ij,l) Z(ij,l,p)
  INTEGER,PARAMETER :: order_l_ij_p=2  ! indexing 2D/3D/4D : X(ij) Y(l,ij) Z(l,ij,p)

  TYPE t_layout
     LOGICAL :: oriented     ! .TRUE. if sign may need to change when exchanging halos
     INTEGER :: ij_size      ! needed for allocation
     INTEGER :: index_order  ! order of of the indices, e.g. index_ij_l_p
  END type t_layout

  ! allocated and filled during model startup
  TYPE(t_layout), ALLOCATABLE :: &
       layout(:,:), &  ! shape (ndomain,field_type_max),    ; used by allocated_field
       layout_glo(:,:) ! shape (ndomain_glo,field_type_max) ; used by allocated_field_glo
  
CONTAINS

END MODULE layout_mod
