Index: codes/icosagcm/devel/src/base/grid_param.f90
===================================================================
--- codes/icosagcm/devel/src/base/grid_param.f90	(revision 811)
+++ codes/icosagcm/devel/src/base/grid_param.f90	(revision 813)
@@ -2,8 +2,10 @@
   INTEGER  :: iim_glo=40
   INTEGER  :: jjm_glo
-  INTEGER,PARAMETER  :: nb_face=10
-  INTEGER  :: llm=19
+  INTEGER, PARAMETER  :: nb_face=10
+  INTEGER, PARAMETER :: grid_unst=1, grid_ico = 2
+  INTEGER  :: grid_type ! unstructured or icosahedral
+  INTEGER, BIND(C) :: llm=19
   INTEGER  :: nqtot ! number of tracers handled by advection scheme
-  INTEGER  :: nqdyn ! number of dynamical tracers : 1 if dry, more if moist
+  INTEGER, BIND(C) :: nqdyn ! number of dynamical tracers : 1 if dry, more if moist
 
 CONTAINS
Index: codes/icosagcm/devel/src/icosa_init.f90
===================================================================
--- codes/icosagcm/devel/src/icosa_init.f90	(revision 811)
+++ codes/icosagcm/devel/src/icosa_init.f90	(revision 813)
@@ -22,8 +22,10 @@
   USE diagflux_mod
   USE profiling_mod
+  USE init_unstructured_mod, ONLY: init_grid_type
   IMPLICIT NONE
   
     CALL init_profiling
     CALL init_mpipara
+    CALL init_grid_type
     CALL trace_off
     CALL xios_init
@@ -74,5 +76,5 @@
 
   CONTAINS
-  
+ 
     SUBROUTINE check_total_area
     IMPLICIT NONE
Index: codes/icosagcm/devel/src/parallel/domain.f90
===================================================================
--- codes/icosagcm/devel/src/parallel/domain.f90	(revision 811)
+++ codes/icosagcm/devel/src/parallel/domain.f90	(revision 813)
@@ -579,6 +579,5 @@
     CALL assign_domain_omp
 !$OMP END PARALLEL
-        
-    
+            
   END SUBROUTINE  assign_domain      
    
@@ -612,17 +611,22 @@
   END SUBROUTINE assign_domain_omp
     
-
           
   SUBROUTINE compute_domain
-  IMPLICIT NONE
-    CALL init_domain_param
-    CALL create_domain
-    CALL assign_cell
-    CALL compute_boundary
-    CALL set_neighbour_indice
-    CALL assign_domain
-      
+    USE grid_param, ONLY : grid_type, grid_unst, grid_ico
+    IMPLICIT NONE
+    SELECT CASE(grid_type)
+    CASE(grid_unst)
+       ndomain=1
+       ALLOCATE(assigned_domain(1))
+       assigned_domain=.TRUE.
+    CASE DEFAULT
+       CALL init_domain_param
+       CALL create_domain
+       CALL assign_cell
+       CALL compute_boundary
+       CALL set_neighbour_indice
+       CALL assign_domain
+    END SELECT
   END SUBROUTINE compute_domain
           
 END MODULE domain_mod 
-  
Index: codes/icosagcm/devel/src/parallel/mpipara.F90
===================================================================
--- codes/icosagcm/devel/src/parallel/mpipara.F90	(revision 811)
+++ codes/icosagcm/devel/src/parallel/mpipara.F90	(revision 813)
@@ -9,5 +9,5 @@
   LOGICAL,SAVE :: using_mpi
   LOGICAL,SAVE :: is_mpi_root
-  LOGICAL,SAVE :: is_mpi_master
+  LOGICAL,SAVE, BIND(C) :: is_mpi_master=.TRUE.
   INTEGER,SAVE :: mpi_master
   
Index: codes/icosagcm/devel/src/unstructured/data_unstructured.F90
===================================================================
--- codes/icosagcm/devel/src/unstructured/data_unstructured.F90	(revision 811)
+++ codes/icosagcm/devel/src/unstructured/data_unstructured.F90	(revision 813)
@@ -2,6 +2,9 @@
   USE ISO_C_BINDING
   USE OMP_LIB
+  USE mpipara, ONLY : is_mpi_master
+  USE grid_param, ONLY : llm, nqdyn
   IMPLICIT NONE
   SAVE
+
 
 #include "unstructured.h90"
@@ -12,5 +15,5 @@
   INDEX,  BIND(C) :: caldyn_thermo=thermo_theta, caldyn_eta=eta_lag, &
        caldyn_vert_variant=caldyn_vert_cons, nb_threads=0, nb_stage=0
-  LOGICAL(C_BOOL), BIND(C) :: hydrostatic=.TRUE., is_mpi_master=.TRUE., debug_on=.FALSE.
+  LOGICAL(C_BOOL), BIND(C) :: hydrostatic=.TRUE., debug_on=.FALSE.
   LOGICAL(C_BOOL), BIND(C, NAME='debug_hevi_solver') :: debug_hevi_solver_=.TRUE.
 
@@ -21,5 +24,5 @@
 #endif
 
-  INDEX, BIND(C) :: llm, nqdyn, edge_num, primal_num, dual_num, &
+  INDEX, BIND(C) :: edge_num, primal_num, dual_num, &
        max_primal_deg, max_dual_deg, max_trisk_deg
   INDEX, ALLOCATABLE :: & ! deg(ij) = nb of vertices = nb of edges of primal/dual cell ij
Index: codes/icosagcm/devel/src/unstructured/init_unstructured.f90
===================================================================
--- codes/icosagcm/devel/src/unstructured/init_unstructured.f90	(revision 813)
+++ codes/icosagcm/devel/src/unstructured/init_unstructured.f90	(revision 813)
@@ -0,0 +1,200 @@
+MODULE init_unstructured_mod
+  USE mpipara, ONLY : is_mpi_master
+  USE grid_param, ONLY : llm, nqdyn
+  USE data_unstructured_mod
+  IMPLICIT NONE
+  SAVE
+  PRIVATE
+
+  ! these buffers are used when reading from the grid file
+  REAL(8), ALLOCATABLE :: Ddata_read1(:),Ddata_read2(:,:),Ddata_read3(:,:,:)
+  INTEGER, ALLOCATABLE :: Idata_read1(:),Idata_read2(:,:),Idata_read3(:,:,:)
+
+  PUBLIC :: init_grid_type
+
+CONTAINS
+
+  SUBROUTINE free_data_read()
+    IF(ALLOCATED(Idata_read1)) DEALLOCATE(Idata_read1) 
+    IF(ALLOCATED(Idata_read2)) DEALLOCATE(Idata_read2) 
+    IF(ALLOCATED(Idata_read3)) DEALLOCATE(Idata_read3) 
+    IF(ALLOCATED(Ddata_read1)) DEALLOCATE(Ddata_read1) 
+    IF(ALLOCATED(Ddata_read2)) DEALLOCATE(Ddata_read2) 
+    IF(ALLOCATED(Ddata_read3)) DEALLOCATE(Ddata_read3) 
+  END SUBROUTINE free_data_read
+
+  SUBROUTINE read_from_gridfile(id_nc, data_type, name)
+    use netcdf_mod
+    CHARACTER(*)    :: data_type, name
+    INTEGER :: id_nc, id_var, status
+    INTEGER :: dim_1, dim_2, dim_3
+    INTEGER :: numDims, dimIDs(3) !max_var_dims
+
+    !-------------------Reading variable-------------------------------
+    status = nf90_inq_varid(id_nc, name,id_var)
+    IF(status /= 0) THEN
+        print *, "Not able to read variable from gridfile :", name
+        STOP "Exit"
+    ENDIF
+    !inquire dimension
+    status = nf90_inquire_variable(id_nc,id_var,dimids=dimIDs,ndims=numDims)
+    status = nf90_inquire_dimension(id_nc, dimIDs(1), len = dim_1)
+    status = nf90_inquire_dimension(id_nc, dimIDs(2), len = dim_2)
+    status = nf90_inquire_dimension(id_nc, dimIDs(3), len = dim_3)
+    SELECT CASE(numDims)
+    CASE(3)
+    print *,"Size of array, ",name,":", dim_1,dim_2,dim_3
+    CASE(2)
+    print *,"Size of array, ",name,":", dim_1,dim_2
+    CASE DEFAULT
+    print *,"Size of array, ",name,":", dim_1
+    END SELECT
+
+    CALL free_data_read
+    SELECT CASE(data_type)
+    CASE('integer')
+       SELECT CASE(numDims)
+       CASE(3)
+          allocate(Idata_read3(dim_1,dim_2,dim_3))
+          status = nf90_get_var(id_nc, id_var,Idata_read3)
+          print *,"First value of array, ",name,":", Idata_read3(1,1,1)
+       CASE(2)
+          allocate(Idata_read2(dim_1,dim_2))
+          status = nf90_get_var(id_nc, id_var,Idata_read2)
+          print *,"First value of array, ",name,":", Idata_read2(1,1)
+       CASE DEFAULT
+          allocate(Idata_read1(dim_1))
+          status = nf90_get_var(id_nc, id_var,Idata_read1)
+          print *,"First value of array, ",name,":", Idata_read1(1)
+       END SELECT
+    CASE DEFAULT
+       SELECT CASE(numDims)
+       CASE(3)
+          allocate(Ddata_read3(dim_1,dim_2,dim_3))
+          status = nf90_get_var(id_nc, id_var,Ddata_read3)
+          print *,"First value of array, ",name,":", Ddata_read3(1,1,1)
+       CASE(2)
+          allocate(Ddata_read2(dim_1,dim_2))
+          status = nf90_get_var(id_nc, id_var,Ddata_read2)
+          print *,"First value of array, ",name,":", Ddata_read2(1,1)
+       CASE DEFAULT
+          allocate(Ddata_read1(dim_1))
+          status = nf90_get_var(id_nc, id_var,Ddata_read1)
+          print *,"First value of array, ",name,":", Ddata_read1(1)
+       END SELECT
+    END SELECT
+    
+    IF(status /= nf90_NoErr) THEN
+        print *, "Error when reading from grid file : ", name
+        STOP "Exit"
+    ENDIF
+
+  END SUBROUTINE read_from_gridfile
+
+
+  SUBROUTINE read_dump_partition
+    use netcdf_mod
+    USE ioipsl
+    USE field_mod
+    IMPLICIT NONE
+
+    !!-------------Declare local variables-------------------
+    CHARACTER(LEN=*),PARAMETER :: f="mesh_information.nc"
+    INTEGER :: id_nc, ierr, status, descriptionLength
+    CHARACTER(LEN= 80) :: description
+
+    print *,"------------------ READING FILE " , f, "----------------------- "
+    !open and read the input file
+    ierr = nf90_open(f, NF90_NOWRITE, id_nc)
+    if (ierr /= nf90_noerr) then
+      print *, trim(nf90_strerror(ierr))
+      stop "Error reading file"
+    end if
+
+    status = nf90_inquire_attribute(id_nc, nf90_global, "description", len =descriptionLength)
+    IF(status /= 0 .or. len(description) < descriptionLength) THEN
+        print *, "Not enough space to put NetCDF attribute values."
+        STOP "Error reading file"
+    ENDIF
+
+    !-------------------Reading global attributes-----------------------
+    status = nf90_get_att(id_nc, nf90_global, "description", description)
+    print *,"Data file description :",description
+
+    !status = nf90_get_att(id_nc, nf90_global, "primal_num", primal_num)
+    !status = nf90_get_att(id_nc, nf90_global, "dual_num", dual_num)
+    !status = nf90_get_att(id_nc, nf90_global, "edge_num", edge_num)
+    !print *,primal_num,dual_num,edge_num
+
+    CALL read_from_gridfile(id_nc, 'integer', 'primal_deg')
+    ALLOCATE(primal_deg, source = Idata_read1)
+    CALL read_from_gridfile(id_nc, 'integer', 'primal_edge')
+    ALLOCATE(primal_edge, source = Idata_read2)
+    CALL read_from_gridfile(id_nc, 'integer', 'primal_ne')
+    ALLOCATE(primal_ne, source = Idata_read2)
+    CALL read_from_gridfile(id_nc, 'integer', 'dual_deg')
+    ALLOCATE(dual_deg, source = Idata_read1)
+    CALL read_from_gridfile(id_nc, 'integer', 'dual_edge')
+    ALLOCATE(dual_edge, source = Idata_read2)
+    CALL read_from_gridfile(id_nc, 'integer', 'dual_ne')
+    ALLOCATE(dual_ne, source = Idata_read2)
+    CALL read_from_gridfile(id_nc, 'integer', 'primal_vertex') 
+    ALLOCATE(primal_vertex, source = Idata_read2)
+    CALL read_from_gridfile(id_nc, 'integer', 'left')
+    ALLOCATE(left, source = Idata_read1)
+    CALL read_from_gridfile(id_nc, 'integer', 'right')
+    ALLOCATE(right, source = Idata_read1)
+    CALL read_from_gridfile(id_nc, 'integer', 'up')
+    ALLOCATE(up, source = Idata_read1)
+    CALL read_from_gridfile(id_nc, 'integer', 'down')
+    ALLOCATE(down, source = Idata_read1)
+    CALL read_from_gridfile(id_nc, 'integer', 'trisk_deg')
+    ALLOCATE(trisk_deg, source = Idata_read1)
+    CALL read_from_gridfile(id_nc, 'integer', 'trisk')
+    ALLOCATE(trisk, source = Idata_read2)
+    CALL read_from_gridfile(id_nc, 'float', 'Ai')
+    ALLOCATE(Ai, source = Ddata_read1)
+    CALL read_from_gridfile(id_nc, 'float', 'Av')
+    ALLOCATE(Av, source = Ddata_read1)
+    CALL read_from_gridfile(id_nc, 'float', 'le_de')
+    ALLOCATE(le_de, source = Ddata_read1)
+    CALL read_from_gridfile(id_nc, 'float', 'Riv2')
+    ALLOCATE(Riv2, source = Ddata_read2)
+    CALL read_from_gridfile(id_nc, 'float', 'wee')
+    ALLOCATE(wee, source = Ddata_read2)
+    CALL read_from_gridfile(id_nc, 'float', 'fv') ! 
+    ALLOCATE(fv, source = Ddata_read1)
+    CALL read_from_gridfile(id_nc, 'integer', 'dual_vertex') 
+    ALLOCATE(dual_vertex, source = Idata_read2)
+
+    CALL free_data_read ! free buffers after reading all data from grid file
+
+    edge_num = SIZE(le_de)
+    primal_num = SIZE(Ai)
+    dual_num = SIZE(Av)
+    max_primal_deg = SIZE(primal_edge,1)
+    max_dual_deg = SIZE(dual_edge,1)
+    max_trisk_deg = SIZE(trisk,1)
+
+  END SUBROUTINE read_dump_partition
+
+  SUBROUTINE init_grid_type
+    USE grid_param, ONLY : grid_type, grid_unst, grid_ico   
+    USE getin_mod, ONLY : getin
+    CHARACTER(len=255) :: grid_type_var
+    grid_type_var='icosahedral'
+    CALL getin("grid_type",grid_type_var)
+    SELECT CASE(grid_type_var)
+    CASE('unstructured')
+       grid_type = grid_unst
+!       is_omp_level_master=.TRUE.
+!       omp_level_size=1
+       CALL read_dump_partition
+       IF (is_mpi_master) PRINT *,'Using unstructured grid type'
+    CASE DEFAULT
+       grid_type = grid_ico
+       IF (is_mpi_master) PRINT *,'Using default grid type'
+    END SELECT  
+  END SUBROUTINE init_grid_type
+
+END MODULE init_unstructured_mod
